Compare commits
10 Commits
263a75b1c0
...
f39e03fde2
| Author | SHA1 | Date |
|---|---|---|
|
|
f39e03fde2 | |
|
|
2ffd7a8221 | |
|
|
042f2299f0 | |
|
|
d70101c979 | |
|
|
bbc615a18e | |
|
|
afb48a6c40 | |
|
|
16bd3b5628 | |
|
|
aae865dafb | |
|
|
77e1931494 | |
|
|
5562800958 |
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"title": "Coze用户注册功能故障诊断系统",
|
||||
"features": [
|
||||
"系统健康检查",
|
||||
"前端表单诊断",
|
||||
"后端接口测试",
|
||||
"数据库连接验证",
|
||||
"用户验证逻辑检测",
|
||||
"实时日志监控",
|
||||
"问题修复指导"
|
||||
],
|
||||
"tech": {
|
||||
"Web": { "arch": "react", "component": null },
|
||||
"Backend": "Go语言,集成现有coze-studio后端架构",
|
||||
"Database": "MySQL连接诊断工具",
|
||||
"Infrastructure": "Docker容器化部署,Minio对象存储"
|
||||
},
|
||||
"design": "Material Design风格的诊断仪表板,采用深蓝色主色调,卡片式布局展示系统状态和诊断结果,包含实时日志监控和问题修复指导界面",
|
||||
"plan": {
|
||||
"开发系统健康检查模块,检测前端、后端、数据库、Minio等核心服务状态": "doing",
|
||||
"构建前端注册表单诊断功能,验证表单验证逻辑和数据提交流程": "holding",
|
||||
"实现后端注册接口测试工具,检查API响应、参数处理和错误返回": "holding",
|
||||
"开发数据库连接和用户表诊断功能,验证数据写入和查询权限": "holding",
|
||||
"构建用户验证逻辑检测模块,测试邮箱验证、密码加密等业务流程": "holding",
|
||||
"创建诊断结果展示界面,提供问题定位和修复建议": "holding",
|
||||
"集成实时日志监控和错误追踪功能": "holding"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
# Coze用户注册功能故障诊断系统
|
||||
|
||||
## Core Features
|
||||
|
||||
- 系统健康检查
|
||||
|
||||
- 前端表单诊断
|
||||
|
||||
- 后端接口测试
|
||||
|
||||
- 数据库连接验证
|
||||
|
||||
- 用户验证逻辑检测
|
||||
|
||||
- 实时日志监控
|
||||
|
||||
- 问题修复指导
|
||||
|
||||
## Tech Stack
|
||||
|
||||
{
|
||||
"Web": {
|
||||
"arch": "react",
|
||||
"component": null
|
||||
},
|
||||
"Backend": "Go语言,集成现有coze-studio后端架构",
|
||||
"Database": "MySQL连接诊断工具",
|
||||
"Infrastructure": "Docker容器化部署,Minio对象存储"
|
||||
}
|
||||
|
||||
## Design
|
||||
|
||||
Material Design风格的诊断仪表板,采用深蓝色主色调,卡片式布局展示系统状态和诊断结果,包含实时日志监控和问题修复指导界面
|
||||
|
||||
## Plan
|
||||
|
||||
Note:
|
||||
|
||||
- [ ] is holding
|
||||
- [/] is doing
|
||||
- [X] is done
|
||||
|
||||
---
|
||||
|
||||
[/] 开发系统健康检查模块,检测前端、后端、数据库、Minio等核心服务状态
|
||||
|
||||
[ ] 构建前端注册表单诊断功能,验证表单验证逻辑和数据提交流程
|
||||
|
||||
[ ] 实现后端注册接口测试工具,检查API响应、参数处理和错误返回
|
||||
|
||||
[ ] 开发数据库连接和用户表诊断功能,验证数据写入和查询权限
|
||||
|
||||
[ ] 构建用户验证逻辑检测模块,测试邮箱验证、密码加密等业务流程
|
||||
|
||||
[ ] 创建诊断结果展示界面,提供问题定位和修复建议
|
||||
|
||||
[ ] 集成实时日志监控和错误追踪功能
|
||||
|
|
@ -27,6 +27,8 @@ WORKDIR /app
|
|||
# bind-tools for nslookup etc., file for debugging file types
|
||||
RUN apk add --no-cache pax-utils python3 python3-dev bind-tools file deno curl
|
||||
|
||||
RUN deno run -A jsr:@eyurtsev/pyodide-sandbox -c "print('Hello, World')"
|
||||
|
||||
# Install Python build dependencies, create venv, install packages, then remove build deps
|
||||
RUN apk add --no-cache --virtual .python-build-deps build-base py3-pip git && \
|
||||
python3 -m venv --copies --upgrade-deps /app/.venv && \
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import (
|
|||
"github.com/hertz-contrib/sse"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/conversation/run"
|
||||
|
||||
|
|
@ -123,3 +124,23 @@ func checkParamsV3(_ context.Context, ar *run.ChatV3Request) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CancelChatApi .
|
||||
// @router /v3/chat/cancel [POST]
|
||||
func CancelChatApi(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req run.CancelChatApiRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := conversation.ConversationOpenAPISVC.CancelRun(ctx, &req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
openapiauthApp "github.com/coze-dev/coze-studio/backend/application/openauth"
|
||||
"github.com/coze-dev/coze-studio/backend/application/plugin"
|
||||
"github.com/coze-dev/coze-studio/backend/application/singleagent"
|
||||
"github.com/coze-dev/coze-studio/backend/application/upload"
|
||||
|
|
@ -73,7 +74,7 @@ func UploadFileOpen(ctx context.Context, c *app.RequestContext) {
|
|||
var req bot_open_api.UploadFileOpenRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -83,6 +84,7 @@ func UploadFileOpen(ctx context.Context, c *app.RequestContext) {
|
|||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
|
|
@ -93,7 +95,7 @@ func GetBotOnlineInfo(ctx context.Context, c *app.RequestContext) {
|
|||
var req bot_open_api.GetBotOnlineInfoReq
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -105,3 +107,43 @@ func GetBotOnlineInfo(ctx context.Context, c *app.RequestContext) {
|
|||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// ImpersonateCozeUser .
|
||||
// @router /api/permission_api/coze_web_app/impersonate_coze_user [POST]
|
||||
func ImpersonateCozeUser(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req bot_open_api.ImpersonateCozeUserRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := openapiauthApp.OpenAuthApplication.ImpersonateCozeUserAccessToken(ctx, &req)
|
||||
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// OpenGetBotInfo .
|
||||
// @router /v1/bots/:bot_id [GET]
|
||||
func OpenGetBotInfo(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req bot_open_api.OpenGetBotInfoRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := singleagent.SingleAgentSVC.OpenGetBotInfo(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,3 +170,42 @@ func ListConversationsApi(ctx context.Context, c *app.RequestContext) {
|
|||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// UpdateConversationApi .
|
||||
// @router /v1/conversations/:conversation_id [PUT]
|
||||
func UpdateConversationApi(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req conversation.UpdateConversationApiRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := application.ConversationSVC.UpdateConversation(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// DeleteConversationApi .
|
||||
// @router /v1/conversations/:conversation_id [DELETE]
|
||||
func DeleteConversationApi(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req conversation.DeleteConversationApiRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
resp, err := application.ConversationSVC.DeleteConversation(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -404,3 +404,23 @@ func DraftProjectCopy(ctx context.Context, c *app.RequestContext) {
|
|||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetOnlineAppData .
|
||||
// @router /v1/apps/:app_id [GET]
|
||||
func GetOnlineAppData(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req project.GetOnlineAppDataRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := appApplication.APPApplicationSVC.GetOnlineAppData(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ func GetApiMessageList(ctx context.Context, c *app.RequestContext) {
|
|||
return
|
||||
}
|
||||
|
||||
resp, err := application.OpenapiMessageApplicationService.GetApiMessageList(ctx, &req)
|
||||
resp, err := application.OpenapiMessageSVC.GetApiMessageList(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by hertz generator.
|
||||
|
||||
package coze
|
||||
|
|
@ -21,7 +37,7 @@ func CommonUpload(ctx context.Context, c *app.RequestContext) {
|
|||
var req upload.CommonUploadRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
fullUrl := string(c.Request.URI().FullURI())
|
||||
|
|
@ -41,7 +57,7 @@ func ApplyUploadAction(ctx context.Context, c *app.RequestContext) {
|
|||
var req upload.ApplyUploadActionRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
resp := new(upload.ApplyUploadActionResponse)
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/cloudwego/eino/schema"
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
|
|
@ -555,7 +557,11 @@ func CreateProjectConversationDef(ctx context.Context, c *app.RequestContext) {
|
|||
return
|
||||
}
|
||||
|
||||
resp := new(workflow.CreateProjectConversationDefResponse)
|
||||
resp, err := appworkflow.SVC.CreateApplicationConversationDef(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
|
@ -570,8 +576,11 @@ func UpdateProjectConversationDef(ctx context.Context, c *app.RequestContext) {
|
|||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(workflow.UpdateProjectConversationDefResponse)
|
||||
resp, err := appworkflow.SVC.UpdateApplicationConversationDef(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
|
@ -587,7 +596,11 @@ func DeleteProjectConversationDef(ctx context.Context, c *app.RequestContext) {
|
|||
return
|
||||
}
|
||||
|
||||
resp := new(workflow.DeleteProjectConversationDefResponse)
|
||||
resp, err := appworkflow.SVC.DeleteApplicationConversationDef(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
|
@ -603,7 +616,11 @@ func ListProjectConversationDef(ctx context.Context, c *app.RequestContext) {
|
|||
return
|
||||
}
|
||||
|
||||
resp := new(workflow.ListProjectConversationResponse)
|
||||
resp, err := appworkflow.SVC.ListApplicationConversationDef(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
|
@ -723,7 +740,11 @@ func GetChatFlowRole(ctx context.Context, c *app.RequestContext) {
|
|||
return
|
||||
}
|
||||
|
||||
resp := new(workflow.GetChatFlowRoleResponse)
|
||||
resp, err := appworkflow.SVC.GetChatFlowRole(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
|
@ -738,8 +759,11 @@ func CreateChatFlowRole(ctx context.Context, c *app.RequestContext) {
|
|||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(workflow.CreateChatFlowRoleResponse)
|
||||
resp, err := appworkflow.SVC.CreateChatFlowRole(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
|
@ -755,7 +779,11 @@ func DeleteChatFlowRole(ctx context.Context, c *app.RequestContext) {
|
|||
return
|
||||
}
|
||||
|
||||
resp := new(workflow.DeleteChatFlowRoleResponse)
|
||||
resp, err := appworkflow.SVC.DeleteChatFlowRole(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
|
@ -1061,6 +1089,11 @@ func OpenAPIGetWorkflowRunHistory(ctx context.Context, c *app.RequestContext) {
|
|||
// @router /v1/workflows/chat [POST]
|
||||
func OpenAPIChatFlowRun(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
if err = preprocessWorkflowRequestBody(ctx, c); err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var req workflow.ChatFlowRunRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
|
|
@ -1068,27 +1101,107 @@ func OpenAPIChatFlowRun(ctx context.Context, c *app.RequestContext) {
|
|||
return
|
||||
}
|
||||
|
||||
resp := new(workflow.ChatFlowRunResponse)
|
||||
w := sse.NewWriter(c)
|
||||
c.SetContentType("text/event-stream; charset=utf-8")
|
||||
c.Response.Header.Set("Cache-Control", "no-cache")
|
||||
c.Response.Header.Set("Connection", "keep-alive")
|
||||
c.Response.Header.Set("Access-Control-Allow-Origin", "*")
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
sr, err := appworkflow.SVC.OpenAPIChatFlowRun(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
sendChatFlowStreamRunSSE(ctx, w, sr)
|
||||
|
||||
}
|
||||
|
||||
func sendChatFlowStreamRunSSE(ctx context.Context, w *sse.Writer, sr *schema.StreamReader[[]*workflow.ChatFlowRunResponse]) {
|
||||
defer func() {
|
||||
_ = w.Close()
|
||||
sr.Close()
|
||||
}()
|
||||
seq := int64(1)
|
||||
for {
|
||||
respList, err := sr.Recv()
|
||||
|
||||
if err != nil {
|
||||
if errors.Is(err, io.EOF) {
|
||||
// finish
|
||||
break
|
||||
}
|
||||
|
||||
event := &sse.Event{
|
||||
Type: "error",
|
||||
Data: []byte(err.Error()),
|
||||
}
|
||||
|
||||
if err = w.Write(event); err != nil {
|
||||
logs.CtxErrorf(ctx, "publish stream event failed, err:%v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
for _, resp := range respList {
|
||||
event := &sse.Event{
|
||||
ID: strconv.FormatInt(seq, 10),
|
||||
Type: resp.Event,
|
||||
Data: []byte(resp.Data),
|
||||
}
|
||||
|
||||
if err = w.Write(event); err != nil {
|
||||
logs.CtxErrorf(ctx, "publish stream event failed, err:%v", err)
|
||||
return
|
||||
}
|
||||
seq++
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// OpenAPIGetWorkflowInfo .
|
||||
// @router /v1/workflows/:workflow_id [GET]
|
||||
func OpenAPIGetWorkflowInfo(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
|
||||
if err = processOpenAPIGetWorkflowInfoRequest(ctx, c); err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var req workflow.OpenAPIGetWorkflowInfoRequest
|
||||
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(workflow.OpenAPIGetWorkflowInfoResponse)
|
||||
resp, err := appworkflow.SVC.OpenAPIGetWorkflowInfo(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
func processOpenAPIGetWorkflowInfoRequest(_ context.Context, c *app.RequestContext) error {
|
||||
queryString := c.Request.QueryString()
|
||||
|
||||
values, err := url.ParseQuery(string(queryString))
|
||||
if err != nil {
|
||||
return fmt.Errorf("parse query parameter failed, err:%v", err)
|
||||
}
|
||||
isDebug := values.Get("is_debug")
|
||||
if len(isDebug) == 0 {
|
||||
values.Set("is_debug", "false")
|
||||
}
|
||||
c.Request.SetQueryString(values.Encode())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetHistorySchema .
|
||||
// @router /api/workflow_api/history_schema [POST]
|
||||
func GetHistorySchema(ctx context.Context, c *app.RequestContext) {
|
||||
|
|
@ -1128,3 +1241,22 @@ func GetExampleWorkFlowList(ctx context.Context, c *app.RequestContext) {
|
|||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// OpenAPICreateConversation .
|
||||
// @router /v1/workflow/conversation/create [POST]
|
||||
func OpenAPICreateConversation(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req workflow.CreateConversationRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
resp, err := appworkflow.SVC.OpenAPICreateConversation(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"net/http"
|
||||
"os"
|
||||
"reflect"
|
||||
|
|
@ -42,6 +43,7 @@ import (
|
|||
"github.com/cloudwego/hertz/pkg/common/ut"
|
||||
"github.com/cloudwego/hertz/pkg/protocol"
|
||||
"github.com/cloudwego/hertz/pkg/protocol/sse"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/config"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/mock/gomock"
|
||||
|
|
@ -250,7 +252,10 @@ func newWfTestRunner(t *testing.T) *wfTestRunner {
|
|||
|
||||
mockTos := storageMock.NewMockStorage(ctrl)
|
||||
mockTos.EXPECT().GetObjectUrl(gomock.Any(), gomock.Any(), gomock.Any()).Return("", nil).AnyTimes()
|
||||
workflowRepo := service.NewWorkflowRepository(mockIDGen, db, redisClient, mockTos, cpStore, utChatModel)
|
||||
|
||||
workflowRepo, _ := service.NewWorkflowRepository(mockIDGen, db, redisClient, mockTos, cpStore, utChatModel, &config.WorkflowConfig{
|
||||
NodeOfCodeConfig: &config.NodeOfCodeConfig{},
|
||||
})
|
||||
mockey.Mock(appworkflow.GetWorkflowDomainSVC).Return(service.NewWorkflowService(workflowRepo)).Build()
|
||||
mockey.Mock(workflow2.GetRepository).Return(workflowRepo).Build()
|
||||
publishPatcher := mockey.Mock(appworkflow.PublishWorkflowResource).Return(nil).Build()
|
||||
|
|
@ -1815,212 +1820,212 @@ func TestUpdateWorkflowMeta(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
//func TestSimpleInvokableToolWithReturnVariables(t *testing.T) {
|
||||
// mockey.PatchConvey("simple invokable tool with return variables", t, func() {
|
||||
// r := newWfTestRunner(t)
|
||||
// defer r.closeFn()
|
||||
//
|
||||
// toolID := r.load("function_call/tool_workflow_1.json", withID(7492075279843737651), withPublish("v0.0.1"))
|
||||
//
|
||||
// chatModel := &testutil.UTChatModel{
|
||||
// InvokeResultProvider: func(index int, in []*schema.Message) (*schema.Message, error) {
|
||||
// if index == 0 {
|
||||
// return &schema.Message{
|
||||
// Role: schema.Assistant,
|
||||
// ToolCalls: []schema.ToolCall{
|
||||
// {
|
||||
// ID: "1",
|
||||
// Function: schema.FunctionCall{
|
||||
// Name: "ts_test_wf_test_wf",
|
||||
// Arguments: "{}",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// ResponseMeta: &schema.ResponseMeta{
|
||||
// Usage: &schema.TokenUsage{
|
||||
// PromptTokens: 10,
|
||||
// CompletionTokens: 11,
|
||||
// TotalTokens: 21,
|
||||
// },
|
||||
// },
|
||||
// }, nil
|
||||
// } else if index == 1 {
|
||||
// return &schema.Message{
|
||||
// Role: schema.Assistant,
|
||||
// Content: "final_answer",
|
||||
// ResponseMeta: &schema.ResponseMeta{
|
||||
// Usage: &schema.TokenUsage{
|
||||
// PromptTokens: 5,
|
||||
// CompletionTokens: 6,
|
||||
// TotalTokens: 11,
|
||||
// },
|
||||
// },
|
||||
// }, nil
|
||||
// } else {
|
||||
// return nil, fmt.Errorf("unexpected index: %d", index)
|
||||
// }
|
||||
// },
|
||||
// }
|
||||
// r.modelManage.EXPECT().GetModel(gomock.Any(), gomock.Any()).Return(chatModel, nil, nil).AnyTimes()
|
||||
//
|
||||
// id := r.load("function_call/llm_with_workflow_as_tool.json")
|
||||
// defer func() {
|
||||
// post[workflow.DeleteWorkflowResponse](r, &workflow.DeleteWorkflowRequest{
|
||||
// WorkflowID: id,
|
||||
// })
|
||||
// }()
|
||||
//
|
||||
// exeID := r.testRun(id, map[string]string{
|
||||
// "input": "this is the user input",
|
||||
// })
|
||||
//
|
||||
// e := r.getProcess(id, exeID)
|
||||
// e.assertSuccess()
|
||||
// assert.Equal(t, map[string]any{
|
||||
// "output": "final_answer",
|
||||
// }, mustUnmarshalToMap(t, e.output))
|
||||
// e.tokenEqual(15, 17)
|
||||
//
|
||||
// mockey.PatchConvey("check behavior if stream run", func() {
|
||||
// chatModel.Reset()
|
||||
//
|
||||
// defer r.runServer()()
|
||||
//
|
||||
// r.publish(id, "v0.0.1", true)
|
||||
//
|
||||
// sseReader := r.openapiStream(id, map[string]any{
|
||||
// "input": "hello",
|
||||
// })
|
||||
// err := sseReader.ForEach(t.Context(), func(e *sse.Event) error {
|
||||
// t.Logf("sse id: %s, type: %s, data: %s", e.ID, e.Type, string(e.Data))
|
||||
// return nil
|
||||
// })
|
||||
// assert.NoError(t, err)
|
||||
//
|
||||
// // check workflow references are correct
|
||||
// refs := post[workflow.GetWorkflowReferencesResponse](r, &workflow.GetWorkflowReferencesRequest{
|
||||
// WorkflowID: toolID,
|
||||
// })
|
||||
// assert.Equal(t, 1, len(refs.Data.WorkflowList))
|
||||
// assert.Equal(t, id, refs.Data.WorkflowList[0].WorkflowID)
|
||||
// })
|
||||
// })
|
||||
//}
|
||||
func TestSimpleInvokableToolWithReturnVariables(t *testing.T) {
|
||||
mockey.PatchConvey("simple invokable tool with return variables", t, func() {
|
||||
r := newWfTestRunner(t)
|
||||
defer r.closeFn()
|
||||
|
||||
//func TestReturnDirectlyStreamableTool(t *testing.T) {
|
||||
// mockey.PatchConvey("return directly streamable tool", t, func() {
|
||||
// r := newWfTestRunner(t)
|
||||
// defer r.closeFn()
|
||||
//
|
||||
// outerModel := &testutil.UTChatModel{
|
||||
// StreamResultProvider: func(index int, in []*schema.Message) (*schema.StreamReader[*schema.Message], error) {
|
||||
// if index == 0 {
|
||||
// return schema.StreamReaderFromArray([]*schema.Message{
|
||||
// {
|
||||
// Role: schema.Assistant,
|
||||
// ToolCalls: []schema.ToolCall{
|
||||
// {
|
||||
// ID: "1",
|
||||
// Function: schema.FunctionCall{
|
||||
// Name: "ts_test_wf_test_wf",
|
||||
// Arguments: `{"input": "input for inner model"}`,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// ResponseMeta: &schema.ResponseMeta{
|
||||
// Usage: &schema.TokenUsage{
|
||||
// PromptTokens: 10,
|
||||
// CompletionTokens: 11,
|
||||
// TotalTokens: 21,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// }), nil
|
||||
// } else {
|
||||
// return nil, fmt.Errorf("unexpected index: %d", index)
|
||||
// }
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// innerModel := &testutil.UTChatModel{
|
||||
// StreamResultProvider: func(index int, in []*schema.Message) (*schema.StreamReader[*schema.Message], error) {
|
||||
// if index == 0 {
|
||||
// return schema.StreamReaderFromArray([]*schema.Message{
|
||||
// {
|
||||
// Role: schema.Assistant,
|
||||
// Content: "I ",
|
||||
// ResponseMeta: &schema.ResponseMeta{
|
||||
// Usage: &schema.TokenUsage{
|
||||
// PromptTokens: 5,
|
||||
// CompletionTokens: 6,
|
||||
// TotalTokens: 11,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Role: schema.Assistant,
|
||||
// Content: "don't know",
|
||||
// ResponseMeta: &schema.ResponseMeta{
|
||||
// Usage: &schema.TokenUsage{
|
||||
// CompletionTokens: 8,
|
||||
// TotalTokens: 8,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Role: schema.Assistant,
|
||||
// Content: ".",
|
||||
// ResponseMeta: &schema.ResponseMeta{
|
||||
// Usage: &schema.TokenUsage{
|
||||
// CompletionTokens: 2,
|
||||
// TotalTokens: 2,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// }), nil
|
||||
// } else {
|
||||
// return nil, fmt.Errorf("unexpected index: %d", index)
|
||||
// }
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// r.modelManage.EXPECT().GetModel(gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, params *model.LLMParams) (model2.BaseChatModel, *modelmgr.Model, error) {
|
||||
// if params.ModelType == 1706077826 {
|
||||
// innerModel.ModelType = strconv.FormatInt(params.ModelType, 10)
|
||||
// return innerModel, nil, nil
|
||||
// } else {
|
||||
// outerModel.ModelType = strconv.FormatInt(params.ModelType, 10)
|
||||
// return outerModel, nil, nil
|
||||
// }
|
||||
// }).AnyTimes()
|
||||
//
|
||||
// r.load("function_call/tool_workflow_2.json", withID(7492615435881709608), withPublish("v0.0.1"))
|
||||
// id := r.load("function_call/llm_workflow_stream_tool.json")
|
||||
//
|
||||
// exeID := r.testRun(id, map[string]string{
|
||||
// "input": "this is the user input",
|
||||
// })
|
||||
// e := r.getProcess(id, exeID)
|
||||
// e.assertSuccess()
|
||||
// assert.Equal(t, "this is the streaming output I don't know.", e.output)
|
||||
// e.tokenEqual(15, 27)
|
||||
//
|
||||
// mockey.PatchConvey("check behavior if stream run", func() {
|
||||
// outerModel.Reset()
|
||||
// innerModel.Reset()
|
||||
// defer r.runServer()()
|
||||
// r.publish(id, "v0.0.1", true)
|
||||
// sseReader := r.openapiStream(id, map[string]any{
|
||||
// "input": "hello",
|
||||
// })
|
||||
// err := sseReader.ForEach(t.Context(), func(e *sse.Event) error {
|
||||
// t.Logf("sse id: %s, type: %s, data: %s", e.ID, e.Type, string(e.Data))
|
||||
// return nil
|
||||
// })
|
||||
// assert.NoError(t, err)
|
||||
// })
|
||||
// })
|
||||
//}
|
||||
toolID := r.load("function_call/tool_workflow_1.json", withID(7492075279843737651), withPublish("v0.0.1"))
|
||||
|
||||
chatModel := &testutil.UTChatModel{
|
||||
InvokeResultProvider: func(index int, in []*schema.Message) (*schema.Message, error) {
|
||||
if index == 0 {
|
||||
return &schema.Message{
|
||||
Role: schema.Assistant,
|
||||
ToolCalls: []schema.ToolCall{
|
||||
{
|
||||
ID: "1",
|
||||
Function: schema.FunctionCall{
|
||||
Name: "ts_test_wf_test_wf",
|
||||
Arguments: "{}",
|
||||
},
|
||||
},
|
||||
},
|
||||
ResponseMeta: &schema.ResponseMeta{
|
||||
Usage: &schema.TokenUsage{
|
||||
PromptTokens: 10,
|
||||
CompletionTokens: 11,
|
||||
TotalTokens: 21,
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
} else if index == 1 {
|
||||
return &schema.Message{
|
||||
Role: schema.Assistant,
|
||||
Content: "final_answer",
|
||||
ResponseMeta: &schema.ResponseMeta{
|
||||
Usage: &schema.TokenUsage{
|
||||
PromptTokens: 5,
|
||||
CompletionTokens: 6,
|
||||
TotalTokens: 11,
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
} else {
|
||||
return nil, fmt.Errorf("unexpected index: %d", index)
|
||||
}
|
||||
},
|
||||
}
|
||||
r.modelManage.EXPECT().GetModel(gomock.Any(), gomock.Any()).Return(chatModel, nil, nil).AnyTimes()
|
||||
|
||||
id := r.load("function_call/llm_with_workflow_as_tool.json")
|
||||
defer func() {
|
||||
post[workflow.DeleteWorkflowResponse](r, &workflow.DeleteWorkflowRequest{
|
||||
WorkflowID: id,
|
||||
})
|
||||
}()
|
||||
|
||||
exeID := r.testRun(id, map[string]string{
|
||||
"input": "this is the user input",
|
||||
})
|
||||
|
||||
e := r.getProcess(id, exeID)
|
||||
e.assertSuccess()
|
||||
assert.Equal(t, map[string]any{
|
||||
"output": "final_answer",
|
||||
}, mustUnmarshalToMap(t, e.output))
|
||||
e.tokenEqual(15, 17)
|
||||
|
||||
mockey.PatchConvey("check behavior if stream run", func() {
|
||||
chatModel.Reset()
|
||||
|
||||
defer r.runServer()()
|
||||
|
||||
r.publish(id, "v0.0.1", true)
|
||||
|
||||
sseReader := r.openapiStream(id, map[string]any{
|
||||
"input": "hello",
|
||||
})
|
||||
err := sseReader.ForEach(t.Context(), func(e *sse.Event) error {
|
||||
t.Logf("sse id: %s, type: %s, data: %s", e.ID, e.Type, string(e.Data))
|
||||
return nil
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
// check workflow references are correct
|
||||
refs := post[workflow.GetWorkflowReferencesResponse](r, &workflow.GetWorkflowReferencesRequest{
|
||||
WorkflowID: toolID,
|
||||
})
|
||||
assert.Equal(t, 1, len(refs.Data.WorkflowList))
|
||||
assert.Equal(t, id, refs.Data.WorkflowList[0].WorkflowID)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestReturnDirectlyStreamableTool(t *testing.T) {
|
||||
mockey.PatchConvey("return directly streamable tool", t, func() {
|
||||
r := newWfTestRunner(t)
|
||||
defer r.closeFn()
|
||||
|
||||
outerModel := &testutil.UTChatModel{
|
||||
StreamResultProvider: func(index int, in []*schema.Message) (*schema.StreamReader[*schema.Message], error) {
|
||||
if index == 0 {
|
||||
return schema.StreamReaderFromArray([]*schema.Message{
|
||||
{
|
||||
Role: schema.Assistant,
|
||||
ToolCalls: []schema.ToolCall{
|
||||
{
|
||||
ID: "1",
|
||||
Function: schema.FunctionCall{
|
||||
Name: "ts_test_wf_test_wf",
|
||||
Arguments: `{"input": "input for inner model"}`,
|
||||
},
|
||||
},
|
||||
},
|
||||
ResponseMeta: &schema.ResponseMeta{
|
||||
Usage: &schema.TokenUsage{
|
||||
PromptTokens: 10,
|
||||
CompletionTokens: 11,
|
||||
TotalTokens: 21,
|
||||
},
|
||||
},
|
||||
},
|
||||
}), nil
|
||||
} else {
|
||||
return nil, fmt.Errorf("unexpected index: %d", index)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
innerModel := &testutil.UTChatModel{
|
||||
StreamResultProvider: func(index int, in []*schema.Message) (*schema.StreamReader[*schema.Message], error) {
|
||||
if index == 0 {
|
||||
return schema.StreamReaderFromArray([]*schema.Message{
|
||||
{
|
||||
Role: schema.Assistant,
|
||||
Content: "I ",
|
||||
ResponseMeta: &schema.ResponseMeta{
|
||||
Usage: &schema.TokenUsage{
|
||||
PromptTokens: 5,
|
||||
CompletionTokens: 6,
|
||||
TotalTokens: 11,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Role: schema.Assistant,
|
||||
Content: "don't know",
|
||||
ResponseMeta: &schema.ResponseMeta{
|
||||
Usage: &schema.TokenUsage{
|
||||
CompletionTokens: 8,
|
||||
TotalTokens: 8,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Role: schema.Assistant,
|
||||
Content: ".",
|
||||
ResponseMeta: &schema.ResponseMeta{
|
||||
Usage: &schema.TokenUsage{
|
||||
CompletionTokens: 2,
|
||||
TotalTokens: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
}), nil
|
||||
} else {
|
||||
return nil, fmt.Errorf("unexpected index: %d", index)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
r.modelManage.EXPECT().GetModel(gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, params *model.LLMParams) (model2.BaseChatModel, *modelmgr.Model, error) {
|
||||
if params.ModelType == 1706077826 {
|
||||
innerModel.ModelType = strconv.FormatInt(params.ModelType, 10)
|
||||
return innerModel, nil, nil
|
||||
} else {
|
||||
outerModel.ModelType = strconv.FormatInt(params.ModelType, 10)
|
||||
return outerModel, nil, nil
|
||||
}
|
||||
}).AnyTimes()
|
||||
|
||||
r.load("function_call/tool_workflow_2.json", withID(7492615435881709608), withPublish("v0.0.1"))
|
||||
id := r.load("function_call/llm_workflow_stream_tool.json")
|
||||
|
||||
exeID := r.testRun(id, map[string]string{
|
||||
"input": "this is the user input",
|
||||
})
|
||||
e := r.getProcess(id, exeID)
|
||||
e.assertSuccess()
|
||||
assert.Equal(t, "this is the streaming output I don't know.", e.output)
|
||||
e.tokenEqual(15, 27)
|
||||
|
||||
mockey.PatchConvey("check behavior if stream run", func() {
|
||||
outerModel.Reset()
|
||||
innerModel.Reset()
|
||||
defer r.runServer()()
|
||||
r.publish(id, "v0.0.1", true)
|
||||
sseReader := r.openapiStream(id, map[string]any{
|
||||
"input": "hello",
|
||||
})
|
||||
err := sseReader.ForEach(t.Context(), func(e *sse.Event) error {
|
||||
t.Logf("sse id: %s, type: %s, data: %s", e.ID, e.Type, string(e.Data))
|
||||
return nil
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestSimpleInterruptibleTool(t *testing.T) {
|
||||
mockey.PatchConvey("test simple interruptible tool", t, func() {
|
||||
|
|
@ -2082,233 +2087,231 @@ func TestSimpleInterruptibleTool(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
//func TestStreamableToolWithMultipleInterrupts(t *testing.T) {
|
||||
// mockey.PatchConvey("return directly streamable tool with multiple interrupts", t, func() {
|
||||
// r := newWfTestRunner(t)
|
||||
// defer r.closeFn()
|
||||
//
|
||||
// outerModel := &testutil.UTChatModel{
|
||||
// StreamResultProvider: func(index int, in []*schema.Message) (*schema.StreamReader[*schema.Message], error) {
|
||||
// if index == 0 {
|
||||
// return schema.StreamReaderFromArray([]*schema.Message{
|
||||
// {
|
||||
// Role: schema.Assistant,
|
||||
// ToolCalls: []schema.ToolCall{
|
||||
// {
|
||||
// ID: "1",
|
||||
// Function: schema.FunctionCall{
|
||||
// Name: "ts_test_wf_test_wf",
|
||||
// Arguments: `{"input": "what's your name and age"}`,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// ResponseMeta: &schema.ResponseMeta{
|
||||
// Usage: &schema.TokenUsage{
|
||||
// PromptTokens: 6,
|
||||
// CompletionTokens: 7,
|
||||
// TotalTokens: 13,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// }), nil
|
||||
// } else if index == 1 {
|
||||
// return schema.StreamReaderFromArray([]*schema.Message{
|
||||
// {
|
||||
// Role: schema.Assistant,
|
||||
// Content: "I now know your ",
|
||||
// ResponseMeta: &schema.ResponseMeta{
|
||||
// Usage: &schema.TokenUsage{
|
||||
// PromptTokens: 5,
|
||||
// CompletionTokens: 8,
|
||||
// TotalTokens: 13,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Role: schema.Assistant,
|
||||
// Content: "name is Eino and age is 1.",
|
||||
// ResponseMeta: &schema.ResponseMeta{
|
||||
// Usage: &schema.TokenUsage{
|
||||
// CompletionTokens: 10,
|
||||
// TotalTokens: 17,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// }), nil
|
||||
// } else {
|
||||
// return nil, fmt.Errorf("unexpected index: %d", index)
|
||||
// }
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// innerModel := &testutil.UTChatModel{
|
||||
// InvokeResultProvider: func(index int, in []*schema.Message) (*schema.Message, error) {
|
||||
// if index == 0 {
|
||||
// return &schema.Message{
|
||||
// Role: schema.Assistant,
|
||||
// Content: `{"question": "what's your age?"}`,
|
||||
// ResponseMeta: &schema.ResponseMeta{
|
||||
// Usage: &schema.TokenUsage{
|
||||
// PromptTokens: 6,
|
||||
// CompletionTokens: 7,
|
||||
// TotalTokens: 13,
|
||||
// },
|
||||
// },
|
||||
// }, nil
|
||||
// } else if index == 1 {
|
||||
// return &schema.Message{
|
||||
// Role: schema.Assistant,
|
||||
// Content: `{"fields": {"name": "eino", "age": 1}}`,
|
||||
// ResponseMeta: &schema.ResponseMeta{
|
||||
// Usage: &schema.TokenUsage{
|
||||
// PromptTokens: 8,
|
||||
// CompletionTokens: 10,
|
||||
// TotalTokens: 18,
|
||||
// },
|
||||
// },
|
||||
// }, nil
|
||||
// } else {
|
||||
// return nil, fmt.Errorf("unexpected index: %d", index)
|
||||
// }
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// r.modelManage.EXPECT().GetModel(gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, params *model.LLMParams) (model2.BaseChatModel, *modelmgr.Model, error) {
|
||||
// if params.ModelType == 1706077827 {
|
||||
// outerModel.ModelType = strconv.FormatInt(params.ModelType, 10)
|
||||
// return outerModel, nil, nil
|
||||
// } else {
|
||||
// innerModel.ModelType = strconv.FormatInt(params.ModelType, 10)
|
||||
// return innerModel, nil, nil
|
||||
// }
|
||||
// }).AnyTimes()
|
||||
//
|
||||
// r.load("function_call/tool_workflow_3.json", withID(7492615435881709611), withPublish("v0.0.1"))
|
||||
// id := r.load("function_call/llm_workflow_stream_tool_1.json")
|
||||
//
|
||||
// exeID := r.testRun(id, map[string]string{
|
||||
// "input": "this is the user input",
|
||||
// })
|
||||
//
|
||||
// e := r.getProcess(id, exeID)
|
||||
// assert.NotNil(t, e.event)
|
||||
// e.tokenEqual(0, 0)
|
||||
//
|
||||
// r.testResume(id, exeID, e.event.ID, "my name is eino")
|
||||
// e2 := r.getProcess(id, exeID, withPreviousEventID(e.event.ID))
|
||||
// assert.NotNil(t, e2.event)
|
||||
// e2.tokenEqual(0, 0)
|
||||
//
|
||||
// r.testResume(id, exeID, e2.event.ID, "1 year old")
|
||||
// e3 := r.getProcess(id, exeID, withPreviousEventID(e2.event.ID))
|
||||
// e3.assertSuccess()
|
||||
// assert.Equal(t, "the name is eino, age is 1", e3.output)
|
||||
// e3.tokenEqual(20, 24)
|
||||
// })
|
||||
//}
|
||||
func TestStreamableToolWithMultipleInterrupts(t *testing.T) {
|
||||
mockey.PatchConvey("return directly streamable tool with multiple interrupts", t, func() {
|
||||
r := newWfTestRunner(t)
|
||||
defer r.closeFn()
|
||||
|
||||
//func TestNodeWithBatchEnabled(t *testing.T) {
|
||||
// mockey.PatchConvey("test node with batch enabled", t, func() {
|
||||
// r := newWfTestRunner(t)
|
||||
// defer r.closeFn()
|
||||
//
|
||||
// r.load("batch/sub_workflow_as_batch.json", withID(7469707607914217512), withPublish("v0.0.1"))
|
||||
//
|
||||
// chatModel := &testutil.UTChatModel{
|
||||
// InvokeResultProvider: func(index int, in []*schema.Message) (*schema.Message, error) {
|
||||
// if index == 0 {
|
||||
// return &schema.Message{
|
||||
// Role: schema.Assistant,
|
||||
// Content: "answer。for index 0",
|
||||
// ResponseMeta: &schema.ResponseMeta{
|
||||
// Usage: &schema.TokenUsage{
|
||||
// PromptTokens: 5,
|
||||
// CompletionTokens: 6,
|
||||
// TotalTokens: 11,
|
||||
// },
|
||||
// },
|
||||
// }, nil
|
||||
// } else if index == 1 {
|
||||
// return &schema.Message{
|
||||
// Role: schema.Assistant,
|
||||
// Content: "answer,for index 1",
|
||||
// ResponseMeta: &schema.ResponseMeta{
|
||||
// Usage: &schema.TokenUsage{
|
||||
// PromptTokens: 5,
|
||||
// CompletionTokens: 6,
|
||||
// TotalTokens: 11,
|
||||
// },
|
||||
// },
|
||||
// }, nil
|
||||
// } else {
|
||||
// return nil, fmt.Errorf("unexpected index: %d", index)
|
||||
// }
|
||||
// },
|
||||
// }
|
||||
// r.modelManage.EXPECT().GetModel(gomock.Any(), gomock.Any()).Return(chatModel, nil, nil).AnyTimes()
|
||||
//
|
||||
// id := r.load("batch/node_batches.json")
|
||||
//
|
||||
// exeID := r.testRun(id, map[string]string{
|
||||
// "input": `["first input", "second input"]`,
|
||||
// })
|
||||
// e := r.getProcess(id, exeID)
|
||||
// e.assertSuccess()
|
||||
// assert.Equal(t, map[string]any{
|
||||
// "output": []any{
|
||||
// map[string]any{
|
||||
// "output": []any{
|
||||
// "answer",
|
||||
// "for index 0",
|
||||
// },
|
||||
// "input": "answer。for index 0",
|
||||
// },
|
||||
// map[string]any{
|
||||
// "output": []any{
|
||||
// "answer",
|
||||
// "for index 1",
|
||||
// },
|
||||
// "input": "answer,for index 1",
|
||||
// },
|
||||
// },
|
||||
// }, mustUnmarshalToMap(t, e.output))
|
||||
// e.tokenEqual(10, 12)
|
||||
//
|
||||
// // verify this workflow has previously succeeded a test run
|
||||
// result := r.getNodeExeHistory(id, "", "100001", ptr.Of(workflow.NodeHistoryScene_TestRunInput))
|
||||
// assert.True(t, len(result.Output) > 0)
|
||||
//
|
||||
// // verify querying this node's result for a particular test run
|
||||
// result = r.getNodeExeHistory(id, exeID, "178876", nil)
|
||||
// assert.True(t, len(result.Output) > 0)
|
||||
//
|
||||
// mockey.PatchConvey("test node debug with batch mode", func() {
|
||||
// exeID = r.nodeDebug(id, "178876", withNDBatch(map[string]string{"item1": `[{"output":"output_1"},{"output":"output_2"}]`}))
|
||||
// e = r.getProcess(id, exeID)
|
||||
// e.assertSuccess()
|
||||
// assert.Equal(t, map[string]any{
|
||||
// "outputList": []any{
|
||||
// map[string]any{
|
||||
// "input": "output_1",
|
||||
// "output": []any{"output_1"},
|
||||
// },
|
||||
// map[string]any{
|
||||
// "input": "output_2",
|
||||
// "output": []any{"output_2"},
|
||||
// },
|
||||
// },
|
||||
// }, mustUnmarshalToMap(t, e.output))
|
||||
//
|
||||
// // verify querying this node's result for this node debug run
|
||||
// result := r.getNodeExeHistory(id, exeID, "178876", nil)
|
||||
// assert.Equal(t, mustUnmarshalToMap(t, e.output), mustUnmarshalToMap(t, result.Output))
|
||||
//
|
||||
// // verify querying this node's has succeeded any node debug run
|
||||
// result = r.getNodeExeHistory(id, "", "178876", ptr.Of(workflow.NodeHistoryScene_TestRunInput))
|
||||
// assert.Equal(t, mustUnmarshalToMap(t, e.output), mustUnmarshalToMap(t, result.Output))
|
||||
// })
|
||||
// })
|
||||
//}
|
||||
outerModel := &testutil.UTChatModel{
|
||||
StreamResultProvider: func(index int, in []*schema.Message) (*schema.StreamReader[*schema.Message], error) {
|
||||
if index == 0 {
|
||||
return schema.StreamReaderFromArray([]*schema.Message{
|
||||
{
|
||||
Role: schema.Assistant,
|
||||
ToolCalls: []schema.ToolCall{
|
||||
{
|
||||
ID: "1",
|
||||
Function: schema.FunctionCall{
|
||||
Name: "ts_test_wf_test_wf",
|
||||
Arguments: `{"input": "what's your name and age"}`,
|
||||
},
|
||||
},
|
||||
},
|
||||
ResponseMeta: &schema.ResponseMeta{
|
||||
Usage: &schema.TokenUsage{
|
||||
PromptTokens: 6,
|
||||
CompletionTokens: 7,
|
||||
TotalTokens: 13,
|
||||
},
|
||||
},
|
||||
},
|
||||
}), nil
|
||||
} else if index == 1 {
|
||||
return schema.StreamReaderFromArray([]*schema.Message{
|
||||
{
|
||||
Role: schema.Assistant,
|
||||
Content: "I now know your ",
|
||||
ResponseMeta: &schema.ResponseMeta{
|
||||
Usage: &schema.TokenUsage{
|
||||
PromptTokens: 5,
|
||||
CompletionTokens: 8,
|
||||
TotalTokens: 13,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Role: schema.Assistant,
|
||||
Content: "name is Eino and age is 1.",
|
||||
ResponseMeta: &schema.ResponseMeta{
|
||||
Usage: &schema.TokenUsage{
|
||||
CompletionTokens: 10,
|
||||
TotalTokens: 17,
|
||||
},
|
||||
},
|
||||
},
|
||||
}), nil
|
||||
} else {
|
||||
return nil, fmt.Errorf("unexpected index: %d", index)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
innerModel := &testutil.UTChatModel{
|
||||
InvokeResultProvider: func(index int, in []*schema.Message) (*schema.Message, error) {
|
||||
if index == 0 {
|
||||
return &schema.Message{
|
||||
Role: schema.Assistant,
|
||||
Content: `{"question": "what's your age?"}`,
|
||||
ResponseMeta: &schema.ResponseMeta{
|
||||
Usage: &schema.TokenUsage{
|
||||
PromptTokens: 6,
|
||||
CompletionTokens: 7,
|
||||
TotalTokens: 13,
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
} else if index == 1 {
|
||||
return &schema.Message{
|
||||
Role: schema.Assistant,
|
||||
Content: `{"fields": {"name": "eino", "age": 1}}`,
|
||||
ResponseMeta: &schema.ResponseMeta{
|
||||
Usage: &schema.TokenUsage{
|
||||
PromptTokens: 8,
|
||||
CompletionTokens: 10,
|
||||
TotalTokens: 18,
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
} else {
|
||||
return nil, fmt.Errorf("unexpected index: %d", index)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
r.modelManage.EXPECT().GetModel(gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, params *model.LLMParams) (model2.BaseChatModel, *modelmgr.Model, error) {
|
||||
if params.ModelType == 1706077827 {
|
||||
outerModel.ModelType = strconv.FormatInt(params.ModelType, 10)
|
||||
return outerModel, nil, nil
|
||||
} else {
|
||||
innerModel.ModelType = strconv.FormatInt(params.ModelType, 10)
|
||||
return innerModel, nil, nil
|
||||
}
|
||||
}).AnyTimes()
|
||||
|
||||
r.load("function_call/tool_workflow_3.json", withID(7492615435881709611), withPublish("v0.0.1"))
|
||||
id := r.load("function_call/llm_workflow_stream_tool_1.json")
|
||||
|
||||
exeID := r.testRun(id, map[string]string{
|
||||
"input": "this is the user input",
|
||||
})
|
||||
|
||||
e := r.getProcess(id, exeID)
|
||||
assert.NotNil(t, e.event)
|
||||
e.tokenEqual(0, 0)
|
||||
|
||||
r.testResume(id, exeID, e.event.ID, "my name is eino")
|
||||
e2 := r.getProcess(id, exeID, withPreviousEventID(e.event.ID))
|
||||
assert.NotNil(t, e2.event)
|
||||
e2.tokenEqual(0, 0)
|
||||
|
||||
r.testResume(id, exeID, e2.event.ID, "1 year old")
|
||||
e3 := r.getProcess(id, exeID, withPreviousEventID(e2.event.ID))
|
||||
e3.assertSuccess()
|
||||
assert.Equal(t, "the name is eino, age is 1", e3.output)
|
||||
e3.tokenEqual(20, 24)
|
||||
})
|
||||
}
|
||||
|
||||
func TestNodeWithBatchEnabled(t *testing.T) {
|
||||
mockey.PatchConvey("test node with batch enabled", t, func() {
|
||||
r := newWfTestRunner(t)
|
||||
defer r.closeFn()
|
||||
|
||||
r.load("batch/sub_workflow_as_batch.json", withID(7469707607914217512), withPublish("v0.0.1"))
|
||||
|
||||
chatModel := &testutil.UTChatModel{
|
||||
InvokeResultProvider: func(index int, in []*schema.Message) (*schema.Message, error) {
|
||||
if index == 0 {
|
||||
return &schema.Message{
|
||||
Role: schema.Assistant,
|
||||
Content: "answer。for index 0",
|
||||
ResponseMeta: &schema.ResponseMeta{
|
||||
Usage: &schema.TokenUsage{
|
||||
PromptTokens: 5,
|
||||
CompletionTokens: 6,
|
||||
TotalTokens: 11,
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
} else if index == 1 {
|
||||
return &schema.Message{
|
||||
Role: schema.Assistant,
|
||||
Content: "answer,for index 1",
|
||||
ResponseMeta: &schema.ResponseMeta{
|
||||
Usage: &schema.TokenUsage{
|
||||
PromptTokens: 5,
|
||||
CompletionTokens: 6,
|
||||
TotalTokens: 11,
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
} else {
|
||||
return nil, fmt.Errorf("unexpected index: %d", index)
|
||||
}
|
||||
},
|
||||
}
|
||||
r.modelManage.EXPECT().GetModel(gomock.Any(), gomock.Any()).Return(chatModel, nil, nil).AnyTimes()
|
||||
|
||||
id := r.load("batch/node_batches.json")
|
||||
|
||||
exeID := r.testRun(id, map[string]string{
|
||||
"input": `["first input", "second input"]`,
|
||||
})
|
||||
e := r.getProcess(id, exeID)
|
||||
e.assertSuccess()
|
||||
outputMap := mustUnmarshalToMap(t, e.output)
|
||||
assert.Contains(t, outputMap["output"], map[string]any{
|
||||
"output": []any{
|
||||
"answer",
|
||||
"for index 0",
|
||||
},
|
||||
"input": "answer。for index 0",
|
||||
})
|
||||
assert.Contains(t, outputMap["output"], map[string]any{
|
||||
"output": []any{
|
||||
"answer",
|
||||
"for index 1",
|
||||
},
|
||||
"input": "answer,for index 1",
|
||||
})
|
||||
assert.Equal(t, 2, len(outputMap["output"].([]any)))
|
||||
e.tokenEqual(10, 12)
|
||||
|
||||
// verify this workflow has previously succeeded a test run
|
||||
result := r.getNodeExeHistory(id, "", "100001", ptr.Of(workflow.NodeHistoryScene_TestRunInput))
|
||||
assert.True(t, len(result.Output) > 0)
|
||||
|
||||
// verify querying this node's result for a particular test run
|
||||
result = r.getNodeExeHistory(id, exeID, "178876", nil)
|
||||
assert.True(t, len(result.Output) > 0)
|
||||
|
||||
mockey.PatchConvey("test node debug with batch mode", func() {
|
||||
exeID = r.nodeDebug(id, "178876", withNDBatch(map[string]string{"item1": `[{"output":"output_1"},{"output":"output_2"}]`}))
|
||||
e = r.getProcess(id, exeID)
|
||||
e.assertSuccess()
|
||||
assert.Equal(t, map[string]any{
|
||||
"outputList": []any{
|
||||
map[string]any{
|
||||
"input": "output_1",
|
||||
"output": []any{"output_1"},
|
||||
},
|
||||
map[string]any{
|
||||
"input": "output_2",
|
||||
"output": []any{"output_2"},
|
||||
},
|
||||
},
|
||||
}, mustUnmarshalToMap(t, e.output))
|
||||
|
||||
// verify querying this node's result for this node debug run
|
||||
result := r.getNodeExeHistory(id, exeID, "178876", nil)
|
||||
assert.Equal(t, mustUnmarshalToMap(t, e.output), mustUnmarshalToMap(t, result.Output))
|
||||
|
||||
// verify querying this node's has succeeded any node debug run
|
||||
result = r.getNodeExeHistory(id, "", "178876", ptr.Of(workflow.NodeHistoryScene_TestRunInput))
|
||||
assert.Equal(t, mustUnmarshalToMap(t, e.output), mustUnmarshalToMap(t, result.Output))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestStartNodeDefaultValues(t *testing.T) {
|
||||
mockey.PatchConvey("default values", t, func() {
|
||||
|
|
@ -4102,13 +4105,13 @@ func TestCopyWorkflowAppToLibrary(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
validateSubWorkflowIDs(subworkflowCanvas.Nodes)
|
||||
case entity.NodeTypeLLM:
|
||||
if node.Data.Inputs.FCParam != nil && node.Data.Inputs.FCParam.WorkflowFCParam != nil {
|
||||
if node.Data.Inputs.LLM != nil && node.Data.Inputs.FCParam != nil && node.Data.Inputs.FCParam.WorkflowFCParam != nil {
|
||||
for _, w := range node.Data.Inputs.FCParam.WorkflowFCParam.WorkflowList {
|
||||
assert.True(t, copiedIDMap[w.WorkflowID])
|
||||
}
|
||||
}
|
||||
|
||||
if node.Data.Inputs.FCParam != nil && node.Data.Inputs.FCParam.PluginFCParam != nil {
|
||||
if node.Data.Inputs.LLM != nil && node.Data.Inputs.FCParam != nil && node.Data.Inputs.FCParam.PluginFCParam != nil {
|
||||
for _, p := range node.Data.Inputs.FCParam.PluginFCParam.PluginList {
|
||||
if p.PluginVersion == "0" {
|
||||
assert.Equal(t, "100100", p.PluginID)
|
||||
|
|
@ -4116,7 +4119,7 @@ func TestCopyWorkflowAppToLibrary(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
if node.Data.Inputs.FCParam != nil && node.Data.Inputs.FCParam.KnowledgeFCParam != nil {
|
||||
if node.Data.Inputs.LLM != nil && node.Data.Inputs.FCParam != nil && node.Data.Inputs.FCParam.KnowledgeFCParam != nil {
|
||||
for _, k := range node.Data.Inputs.FCParam.KnowledgeFCParam.KnowledgeList {
|
||||
assert.Equal(t, "100100", k.ID)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,20 +38,28 @@ import (
|
|||
const HeaderAuthorizationKey = "Authorization"
|
||||
|
||||
var needAuthPath = map[string]bool{
|
||||
"/v3/chat": true,
|
||||
"/v1/conversations": true,
|
||||
"/v1/conversation/create": true,
|
||||
"/v1/conversation/message/list": true,
|
||||
"/v1/files/upload": true,
|
||||
"/v1/workflow/run": true,
|
||||
"/v1/workflow/stream_run": true,
|
||||
"/v1/workflow/stream_resume": true,
|
||||
"/v1/workflow/get_run_history": true,
|
||||
"/v1/bot/get_online_info": true,
|
||||
"/v3/chat": true,
|
||||
"/v1/conversations": true,
|
||||
"/v1/conversation/create": true,
|
||||
"/v1/conversation/message/list": true,
|
||||
"/v1/files/upload": true,
|
||||
"/v1/workflow/run": true,
|
||||
"/v1/workflow/stream_run": true,
|
||||
"/v1/workflow/stream_resume": true,
|
||||
"/v1/workflow/get_run_history": true,
|
||||
"/v1/bot/get_online_info": true,
|
||||
"/v1/workflows/chat": true,
|
||||
"/v1/workflow/conversation/create": true,
|
||||
"/v3/chat/cancel": true,
|
||||
}
|
||||
|
||||
var needAuthFunc = map[string]bool{
|
||||
"^/v1/conversations/[0-9]+/clear$": true, // v1/conversations/:conversation_id/clear
|
||||
"^/v1/bots/[0-9]+$": true,
|
||||
"^/v1/conversations/[0-9]+$": true,
|
||||
|
||||
"^/v1/workflows/[0-9]+$": true,
|
||||
"^/v1/apps/[0-9]+$": true,
|
||||
}
|
||||
|
||||
func parseBearerAuthToken(authHeader string) string {
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by thriftgo (0.4.1). DO NOT EDIT.
|
||||
|
||||
package common
|
||||
|
|
@ -6,9 +22,26 @@ import (
|
|||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
|
||||
"github.com/apache/thrift/lib/go/thrift"
|
||||
)
|
||||
|
||||
const (
|
||||
VariableTypeKVVariable = "KVVariable"
|
||||
|
||||
VariableTypeListVariable = "ListVariable"
|
||||
|
||||
VariableChannelCustom = "custom"
|
||||
|
||||
VariableChannelSystem = "system"
|
||||
|
||||
VariableChannelLocation = "location"
|
||||
|
||||
VariableChannelFeishu = "feishu"
|
||||
|
||||
VariableChannelAPP = "app"
|
||||
)
|
||||
|
||||
/****************************** audit **********************************/
|
||||
type AuditStatus int64
|
||||
|
||||
|
|
@ -314,6 +347,10 @@ func (p *SpaceStatus) Value() (driver.Value, error) {
|
|||
return int64(*p), nil
|
||||
}
|
||||
|
||||
type VariableType = string
|
||||
|
||||
type VariableChannel = string
|
||||
|
||||
type UserLabel struct {
|
||||
LabelID string `thrift:"label_id,1" form:"label_id" json:"label_id" query:"label_id"`
|
||||
LabelName string `thrift:"label_name,2" form:"label_name" json:"label_name" query:"label_name"`
|
||||
|
|
@ -2275,3 +2312,412 @@ func (p *Space) String() string {
|
|||
return fmt.Sprintf("Space(%+v)", *p)
|
||||
|
||||
}
|
||||
|
||||
type Variable struct {
|
||||
Keyword string `thrift:"keyword,1" form:"keyword" json:"keyword" query:"keyword"`
|
||||
DefaultValue string `thrift:"default_value,2" form:"default_value" json:"default_value" query:"default_value"`
|
||||
VariableType VariableType `thrift:"variable_type,3" form:"variable_type" json:"variable_type" query:"variable_type"`
|
||||
Channel VariableChannel `thrift:"channel,4" form:"channel" json:"channel" query:"channel"`
|
||||
Description string `thrift:"description,5" form:"description" json:"description" query:"description"`
|
||||
Enable bool `thrift:"enable,6" form:"enable" json:"enable" query:"enable"`
|
||||
PromptEnable bool `thrift:"prompt_enable,7" form:"prompt_enable" json:"prompt_enable" query:"prompt_enable"`
|
||||
}
|
||||
|
||||
func NewVariable() *Variable {
|
||||
return &Variable{}
|
||||
}
|
||||
|
||||
func (p *Variable) InitDefault() {
|
||||
}
|
||||
|
||||
func (p *Variable) GetKeyword() (v string) {
|
||||
return p.Keyword
|
||||
}
|
||||
|
||||
func (p *Variable) GetDefaultValue() (v string) {
|
||||
return p.DefaultValue
|
||||
}
|
||||
|
||||
func (p *Variable) GetVariableType() (v VariableType) {
|
||||
return p.VariableType
|
||||
}
|
||||
|
||||
func (p *Variable) GetChannel() (v VariableChannel) {
|
||||
return p.Channel
|
||||
}
|
||||
|
||||
func (p *Variable) GetDescription() (v string) {
|
||||
return p.Description
|
||||
}
|
||||
|
||||
func (p *Variable) GetEnable() (v bool) {
|
||||
return p.Enable
|
||||
}
|
||||
|
||||
func (p *Variable) GetPromptEnable() (v bool) {
|
||||
return p.PromptEnable
|
||||
}
|
||||
|
||||
var fieldIDToName_Variable = map[int16]string{
|
||||
1: "keyword",
|
||||
2: "default_value",
|
||||
3: "variable_type",
|
||||
4: "channel",
|
||||
5: "description",
|
||||
6: "enable",
|
||||
7: "prompt_enable",
|
||||
}
|
||||
|
||||
func (p *Variable) Read(iprot thrift.TProtocol) (err error) {
|
||||
var fieldTypeId thrift.TType
|
||||
var fieldId int16
|
||||
|
||||
if _, err = iprot.ReadStructBegin(); err != nil {
|
||||
goto ReadStructBeginError
|
||||
}
|
||||
|
||||
for {
|
||||
_, fieldTypeId, fieldId, err = iprot.ReadFieldBegin()
|
||||
if err != nil {
|
||||
goto ReadFieldBeginError
|
||||
}
|
||||
if fieldTypeId == thrift.STOP {
|
||||
break
|
||||
}
|
||||
|
||||
switch fieldId {
|
||||
case 1:
|
||||
if fieldTypeId == thrift.STRING {
|
||||
if err = p.ReadField1(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 2:
|
||||
if fieldTypeId == thrift.STRING {
|
||||
if err = p.ReadField2(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 3:
|
||||
if fieldTypeId == thrift.STRING {
|
||||
if err = p.ReadField3(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 4:
|
||||
if fieldTypeId == thrift.STRING {
|
||||
if err = p.ReadField4(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 5:
|
||||
if fieldTypeId == thrift.STRING {
|
||||
if err = p.ReadField5(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 6:
|
||||
if fieldTypeId == thrift.BOOL {
|
||||
if err = p.ReadField6(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 7:
|
||||
if fieldTypeId == thrift.BOOL {
|
||||
if err = p.ReadField7(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
default:
|
||||
if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadFieldEnd(); err != nil {
|
||||
goto ReadFieldEndError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadStructEnd(); err != nil {
|
||||
goto ReadStructEndError
|
||||
}
|
||||
|
||||
return nil
|
||||
ReadStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err)
|
||||
ReadFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err)
|
||||
ReadFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_Variable[fieldId]), err)
|
||||
SkipFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err)
|
||||
|
||||
ReadFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err)
|
||||
ReadStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *Variable) ReadField1(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field string
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = v
|
||||
}
|
||||
p.Keyword = _field
|
||||
return nil
|
||||
}
|
||||
func (p *Variable) ReadField2(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field string
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = v
|
||||
}
|
||||
p.DefaultValue = _field
|
||||
return nil
|
||||
}
|
||||
func (p *Variable) ReadField3(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field VariableType
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = v
|
||||
}
|
||||
p.VariableType = _field
|
||||
return nil
|
||||
}
|
||||
func (p *Variable) ReadField4(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field VariableChannel
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = v
|
||||
}
|
||||
p.Channel = _field
|
||||
return nil
|
||||
}
|
||||
func (p *Variable) ReadField5(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field string
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = v
|
||||
}
|
||||
p.Description = _field
|
||||
return nil
|
||||
}
|
||||
func (p *Variable) ReadField6(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field bool
|
||||
if v, err := iprot.ReadBool(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = v
|
||||
}
|
||||
p.Enable = _field
|
||||
return nil
|
||||
}
|
||||
func (p *Variable) ReadField7(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field bool
|
||||
if v, err := iprot.ReadBool(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = v
|
||||
}
|
||||
p.PromptEnable = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Variable) Write(oprot thrift.TProtocol) (err error) {
|
||||
var fieldId int16
|
||||
if err = oprot.WriteStructBegin("Variable"); err != nil {
|
||||
goto WriteStructBeginError
|
||||
}
|
||||
if p != nil {
|
||||
if err = p.writeField1(oprot); err != nil {
|
||||
fieldId = 1
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField2(oprot); err != nil {
|
||||
fieldId = 2
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField3(oprot); err != nil {
|
||||
fieldId = 3
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField4(oprot); err != nil {
|
||||
fieldId = 4
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField5(oprot); err != nil {
|
||||
fieldId = 5
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField6(oprot); err != nil {
|
||||
fieldId = 6
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField7(oprot); err != nil {
|
||||
fieldId = 7
|
||||
goto WriteFieldError
|
||||
}
|
||||
}
|
||||
if err = oprot.WriteFieldStop(); err != nil {
|
||||
goto WriteFieldStopError
|
||||
}
|
||||
if err = oprot.WriteStructEnd(); err != nil {
|
||||
goto WriteStructEndError
|
||||
}
|
||||
return nil
|
||||
WriteStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
|
||||
WriteFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err)
|
||||
WriteFieldStopError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err)
|
||||
WriteStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *Variable) writeField1(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("keyword", thrift.STRING, 1); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteString(p.Keyword); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err)
|
||||
}
|
||||
func (p *Variable) writeField2(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("default_value", thrift.STRING, 2); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteString(p.DefaultValue); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err)
|
||||
}
|
||||
func (p *Variable) writeField3(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("variable_type", thrift.STRING, 3); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteString(p.VariableType); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 3 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 3 end error: ", p), err)
|
||||
}
|
||||
func (p *Variable) writeField4(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("channel", thrift.STRING, 4); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteString(p.Channel); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 4 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 4 end error: ", p), err)
|
||||
}
|
||||
func (p *Variable) writeField5(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("description", thrift.STRING, 5); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteString(p.Description); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 5 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 5 end error: ", p), err)
|
||||
}
|
||||
func (p *Variable) writeField6(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("enable", thrift.BOOL, 6); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteBool(p.Enable); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 6 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 6 end error: ", p), err)
|
||||
}
|
||||
func (p *Variable) writeField7(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("prompt_enable", thrift.BOOL, 7); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteBool(p.PromptEnable); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 7 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 7 end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *Variable) String() string {
|
||||
if p == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("Variable(%+v)", *p)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package intelligence
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/apache/thrift/lib/go/thrift"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/app/intelligence/project"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/app/intelligence/publish"
|
||||
|
|
@ -55,6 +56,8 @@ type IntelligenceService interface {
|
|||
GetPublishRecordList(ctx context.Context, request *publish.GetPublishRecordListRequest) (r *publish.GetPublishRecordListResponse, err error)
|
||||
|
||||
GetPublishRecordDetail(ctx context.Context, request *publish.GetPublishRecordDetailRequest) (r *publish.GetPublishRecordDetailResponse, err error)
|
||||
// OpenAPI
|
||||
GetOnlineAppData(ctx context.Context, request *project.GetOnlineAppDataRequest) (r *project.GetOnlineAppDataResponse, err error)
|
||||
}
|
||||
|
||||
type IntelligenceServiceClient struct {
|
||||
|
|
@ -209,6 +212,15 @@ func (p *IntelligenceServiceClient) GetPublishRecordDetail(ctx context.Context,
|
|||
}
|
||||
return _result.GetSuccess(), nil
|
||||
}
|
||||
func (p *IntelligenceServiceClient) GetOnlineAppData(ctx context.Context, request *project.GetOnlineAppDataRequest) (r *project.GetOnlineAppDataResponse, err error) {
|
||||
var _args IntelligenceServiceGetOnlineAppDataArgs
|
||||
_args.Request = request
|
||||
var _result IntelligenceServiceGetOnlineAppDataResult
|
||||
if err = p.Client_().Call(ctx, "GetOnlineAppData", &_args, &_result); err != nil {
|
||||
return
|
||||
}
|
||||
return _result.GetSuccess(), nil
|
||||
}
|
||||
|
||||
type IntelligenceServiceProcessor struct {
|
||||
processorMap map[string]thrift.TProcessorFunction
|
||||
|
|
@ -244,6 +256,7 @@ func NewIntelligenceServiceProcessor(handler IntelligenceService) *IntelligenceS
|
|||
self.AddToProcessorMap("PublishProject", &intelligenceServiceProcessorPublishProject{handler: handler})
|
||||
self.AddToProcessorMap("GetPublishRecordList", &intelligenceServiceProcessorGetPublishRecordList{handler: handler})
|
||||
self.AddToProcessorMap("GetPublishRecordDetail", &intelligenceServiceProcessorGetPublishRecordDetail{handler: handler})
|
||||
self.AddToProcessorMap("GetOnlineAppData", &intelligenceServiceProcessorGetOnlineAppData{handler: handler})
|
||||
return self
|
||||
}
|
||||
func (p *IntelligenceServiceProcessor) Process(ctx context.Context, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
|
||||
|
|
@ -936,6 +949,54 @@ func (p *intelligenceServiceProcessorGetPublishRecordDetail) Process(ctx context
|
|||
return true, err
|
||||
}
|
||||
|
||||
type intelligenceServiceProcessorGetOnlineAppData struct {
|
||||
handler IntelligenceService
|
||||
}
|
||||
|
||||
func (p *intelligenceServiceProcessorGetOnlineAppData) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
|
||||
args := IntelligenceServiceGetOnlineAppDataArgs{}
|
||||
if err = args.Read(iprot); err != nil {
|
||||
iprot.ReadMessageEnd()
|
||||
x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error())
|
||||
oprot.WriteMessageBegin("GetOnlineAppData", thrift.EXCEPTION, seqId)
|
||||
x.Write(oprot)
|
||||
oprot.WriteMessageEnd()
|
||||
oprot.Flush(ctx)
|
||||
return false, err
|
||||
}
|
||||
|
||||
iprot.ReadMessageEnd()
|
||||
var err2 error
|
||||
result := IntelligenceServiceGetOnlineAppDataResult{}
|
||||
var retval *project.GetOnlineAppDataResponse
|
||||
if retval, err2 = p.handler.GetOnlineAppData(ctx, args.Request); err2 != nil {
|
||||
x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing GetOnlineAppData: "+err2.Error())
|
||||
oprot.WriteMessageBegin("GetOnlineAppData", thrift.EXCEPTION, seqId)
|
||||
x.Write(oprot)
|
||||
oprot.WriteMessageEnd()
|
||||
oprot.Flush(ctx)
|
||||
return true, err2
|
||||
} else {
|
||||
result.Success = retval
|
||||
}
|
||||
if err2 = oprot.WriteMessageBegin("GetOnlineAppData", thrift.REPLY, seqId); err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
if err2 = result.Write(oprot); err == nil && err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
if err2 = oprot.Flush(ctx); err == nil && err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return true, err
|
||||
}
|
||||
|
||||
type IntelligenceServiceDraftProjectCreateArgs struct {
|
||||
Request *project.DraftProjectCreateRequest `thrift:"request,1"`
|
||||
}
|
||||
|
|
@ -5023,3 +5084,295 @@ func (p *IntelligenceServiceGetPublishRecordDetailResult) String() string {
|
|||
return fmt.Sprintf("IntelligenceServiceGetPublishRecordDetailResult(%+v)", *p)
|
||||
|
||||
}
|
||||
|
||||
type IntelligenceServiceGetOnlineAppDataArgs struct {
|
||||
Request *project.GetOnlineAppDataRequest `thrift:"request,1"`
|
||||
}
|
||||
|
||||
func NewIntelligenceServiceGetOnlineAppDataArgs() *IntelligenceServiceGetOnlineAppDataArgs {
|
||||
return &IntelligenceServiceGetOnlineAppDataArgs{}
|
||||
}
|
||||
|
||||
func (p *IntelligenceServiceGetOnlineAppDataArgs) InitDefault() {
|
||||
}
|
||||
|
||||
var IntelligenceServiceGetOnlineAppDataArgs_Request_DEFAULT *project.GetOnlineAppDataRequest
|
||||
|
||||
func (p *IntelligenceServiceGetOnlineAppDataArgs) GetRequest() (v *project.GetOnlineAppDataRequest) {
|
||||
if !p.IsSetRequest() {
|
||||
return IntelligenceServiceGetOnlineAppDataArgs_Request_DEFAULT
|
||||
}
|
||||
return p.Request
|
||||
}
|
||||
|
||||
var fieldIDToName_IntelligenceServiceGetOnlineAppDataArgs = map[int16]string{
|
||||
1: "request",
|
||||
}
|
||||
|
||||
func (p *IntelligenceServiceGetOnlineAppDataArgs) IsSetRequest() bool {
|
||||
return p.Request != nil
|
||||
}
|
||||
|
||||
func (p *IntelligenceServiceGetOnlineAppDataArgs) Read(iprot thrift.TProtocol) (err error) {
|
||||
var fieldTypeId thrift.TType
|
||||
var fieldId int16
|
||||
|
||||
if _, err = iprot.ReadStructBegin(); err != nil {
|
||||
goto ReadStructBeginError
|
||||
}
|
||||
|
||||
for {
|
||||
_, fieldTypeId, fieldId, err = iprot.ReadFieldBegin()
|
||||
if err != nil {
|
||||
goto ReadFieldBeginError
|
||||
}
|
||||
if fieldTypeId == thrift.STOP {
|
||||
break
|
||||
}
|
||||
|
||||
switch fieldId {
|
||||
case 1:
|
||||
if fieldTypeId == thrift.STRUCT {
|
||||
if err = p.ReadField1(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
default:
|
||||
if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadFieldEnd(); err != nil {
|
||||
goto ReadFieldEndError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadStructEnd(); err != nil {
|
||||
goto ReadStructEndError
|
||||
}
|
||||
|
||||
return nil
|
||||
ReadStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err)
|
||||
ReadFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err)
|
||||
ReadFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_IntelligenceServiceGetOnlineAppDataArgs[fieldId]), err)
|
||||
SkipFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err)
|
||||
|
||||
ReadFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err)
|
||||
ReadStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *IntelligenceServiceGetOnlineAppDataArgs) ReadField1(iprot thrift.TProtocol) error {
|
||||
_field := project.NewGetOnlineAppDataRequest()
|
||||
if err := _field.Read(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
p.Request = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *IntelligenceServiceGetOnlineAppDataArgs) Write(oprot thrift.TProtocol) (err error) {
|
||||
var fieldId int16
|
||||
if err = oprot.WriteStructBegin("GetOnlineAppData_args"); err != nil {
|
||||
goto WriteStructBeginError
|
||||
}
|
||||
if p != nil {
|
||||
if err = p.writeField1(oprot); err != nil {
|
||||
fieldId = 1
|
||||
goto WriteFieldError
|
||||
}
|
||||
}
|
||||
if err = oprot.WriteFieldStop(); err != nil {
|
||||
goto WriteFieldStopError
|
||||
}
|
||||
if err = oprot.WriteStructEnd(); err != nil {
|
||||
goto WriteStructEndError
|
||||
}
|
||||
return nil
|
||||
WriteStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
|
||||
WriteFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err)
|
||||
WriteFieldStopError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err)
|
||||
WriteStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *IntelligenceServiceGetOnlineAppDataArgs) writeField1(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("request", thrift.STRUCT, 1); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := p.Request.Write(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *IntelligenceServiceGetOnlineAppDataArgs) String() string {
|
||||
if p == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("IntelligenceServiceGetOnlineAppDataArgs(%+v)", *p)
|
||||
|
||||
}
|
||||
|
||||
type IntelligenceServiceGetOnlineAppDataResult struct {
|
||||
Success *project.GetOnlineAppDataResponse `thrift:"success,0,optional"`
|
||||
}
|
||||
|
||||
func NewIntelligenceServiceGetOnlineAppDataResult() *IntelligenceServiceGetOnlineAppDataResult {
|
||||
return &IntelligenceServiceGetOnlineAppDataResult{}
|
||||
}
|
||||
|
||||
func (p *IntelligenceServiceGetOnlineAppDataResult) InitDefault() {
|
||||
}
|
||||
|
||||
var IntelligenceServiceGetOnlineAppDataResult_Success_DEFAULT *project.GetOnlineAppDataResponse
|
||||
|
||||
func (p *IntelligenceServiceGetOnlineAppDataResult) GetSuccess() (v *project.GetOnlineAppDataResponse) {
|
||||
if !p.IsSetSuccess() {
|
||||
return IntelligenceServiceGetOnlineAppDataResult_Success_DEFAULT
|
||||
}
|
||||
return p.Success
|
||||
}
|
||||
|
||||
var fieldIDToName_IntelligenceServiceGetOnlineAppDataResult = map[int16]string{
|
||||
0: "success",
|
||||
}
|
||||
|
||||
func (p *IntelligenceServiceGetOnlineAppDataResult) IsSetSuccess() bool {
|
||||
return p.Success != nil
|
||||
}
|
||||
|
||||
func (p *IntelligenceServiceGetOnlineAppDataResult) Read(iprot thrift.TProtocol) (err error) {
|
||||
var fieldTypeId thrift.TType
|
||||
var fieldId int16
|
||||
|
||||
if _, err = iprot.ReadStructBegin(); err != nil {
|
||||
goto ReadStructBeginError
|
||||
}
|
||||
|
||||
for {
|
||||
_, fieldTypeId, fieldId, err = iprot.ReadFieldBegin()
|
||||
if err != nil {
|
||||
goto ReadFieldBeginError
|
||||
}
|
||||
if fieldTypeId == thrift.STOP {
|
||||
break
|
||||
}
|
||||
|
||||
switch fieldId {
|
||||
case 0:
|
||||
if fieldTypeId == thrift.STRUCT {
|
||||
if err = p.ReadField0(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
default:
|
||||
if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadFieldEnd(); err != nil {
|
||||
goto ReadFieldEndError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadStructEnd(); err != nil {
|
||||
goto ReadStructEndError
|
||||
}
|
||||
|
||||
return nil
|
||||
ReadStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err)
|
||||
ReadFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err)
|
||||
ReadFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_IntelligenceServiceGetOnlineAppDataResult[fieldId]), err)
|
||||
SkipFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err)
|
||||
|
||||
ReadFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err)
|
||||
ReadStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *IntelligenceServiceGetOnlineAppDataResult) ReadField0(iprot thrift.TProtocol) error {
|
||||
_field := project.NewGetOnlineAppDataResponse()
|
||||
if err := _field.Read(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
p.Success = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *IntelligenceServiceGetOnlineAppDataResult) Write(oprot thrift.TProtocol) (err error) {
|
||||
var fieldId int16
|
||||
if err = oprot.WriteStructBegin("GetOnlineAppData_result"); err != nil {
|
||||
goto WriteStructBeginError
|
||||
}
|
||||
if p != nil {
|
||||
if err = p.writeField0(oprot); err != nil {
|
||||
fieldId = 0
|
||||
goto WriteFieldError
|
||||
}
|
||||
}
|
||||
if err = oprot.WriteFieldStop(); err != nil {
|
||||
goto WriteFieldStopError
|
||||
}
|
||||
if err = oprot.WriteStructEnd(); err != nil {
|
||||
goto WriteStructEndError
|
||||
}
|
||||
return nil
|
||||
WriteStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
|
||||
WriteFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err)
|
||||
WriteFieldStopError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err)
|
||||
WriteStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *IntelligenceServiceGetOnlineAppDataResult) writeField0(oprot thrift.TProtocol) (err error) {
|
||||
if p.IsSetSuccess() {
|
||||
if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := p.Success.Write(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *IntelligenceServiceGetOnlineAppDataResult) String() string {
|
||||
if p == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("IntelligenceServiceGetOnlineAppDataResult(%+v)", *p)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,26 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by thriftgo (0.4.1). DO NOT EDIT.
|
||||
|
||||
package project
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/apache/thrift/lib/go/thrift"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/app/intelligence/common"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/base"
|
||||
|
|
@ -3278,3 +3295,954 @@ func (p *DraftProjectCopyResponseData) String() string {
|
|||
return fmt.Sprintf("DraftProjectCopyResponseData(%+v)", *p)
|
||||
|
||||
}
|
||||
|
||||
type GetOnlineAppDataRequest struct {
|
||||
AppID *int64 `thrift:"app_id,1,optional" json:"app_id,string,omitempty" path:"app_id"`
|
||||
ConnectorID *int64 `thrift:"connector_id,2,optional" form:"connector_id" json:"connector_id,string,omitempty" query:"connector_id"`
|
||||
Base *base.Base `thrift:"Base,255,optional" form:"Base" json:"Base,omitempty" query:"Base"`
|
||||
}
|
||||
|
||||
func NewGetOnlineAppDataRequest() *GetOnlineAppDataRequest {
|
||||
return &GetOnlineAppDataRequest{}
|
||||
}
|
||||
|
||||
func (p *GetOnlineAppDataRequest) InitDefault() {
|
||||
}
|
||||
|
||||
var GetOnlineAppDataRequest_AppID_DEFAULT int64
|
||||
|
||||
func (p *GetOnlineAppDataRequest) GetAppID() (v int64) {
|
||||
if !p.IsSetAppID() {
|
||||
return GetOnlineAppDataRequest_AppID_DEFAULT
|
||||
}
|
||||
return *p.AppID
|
||||
}
|
||||
|
||||
var GetOnlineAppDataRequest_ConnectorID_DEFAULT int64
|
||||
|
||||
func (p *GetOnlineAppDataRequest) GetConnectorID() (v int64) {
|
||||
if !p.IsSetConnectorID() {
|
||||
return GetOnlineAppDataRequest_ConnectorID_DEFAULT
|
||||
}
|
||||
return *p.ConnectorID
|
||||
}
|
||||
|
||||
var GetOnlineAppDataRequest_Base_DEFAULT *base.Base
|
||||
|
||||
func (p *GetOnlineAppDataRequest) GetBase() (v *base.Base) {
|
||||
if !p.IsSetBase() {
|
||||
return GetOnlineAppDataRequest_Base_DEFAULT
|
||||
}
|
||||
return p.Base
|
||||
}
|
||||
|
||||
var fieldIDToName_GetOnlineAppDataRequest = map[int16]string{
|
||||
1: "app_id",
|
||||
2: "connector_id",
|
||||
255: "Base",
|
||||
}
|
||||
|
||||
func (p *GetOnlineAppDataRequest) IsSetAppID() bool {
|
||||
return p.AppID != nil
|
||||
}
|
||||
|
||||
func (p *GetOnlineAppDataRequest) IsSetConnectorID() bool {
|
||||
return p.ConnectorID != nil
|
||||
}
|
||||
|
||||
func (p *GetOnlineAppDataRequest) IsSetBase() bool {
|
||||
return p.Base != nil
|
||||
}
|
||||
|
||||
func (p *GetOnlineAppDataRequest) Read(iprot thrift.TProtocol) (err error) {
|
||||
var fieldTypeId thrift.TType
|
||||
var fieldId int16
|
||||
|
||||
if _, err = iprot.ReadStructBegin(); err != nil {
|
||||
goto ReadStructBeginError
|
||||
}
|
||||
|
||||
for {
|
||||
_, fieldTypeId, fieldId, err = iprot.ReadFieldBegin()
|
||||
if err != nil {
|
||||
goto ReadFieldBeginError
|
||||
}
|
||||
if fieldTypeId == thrift.STOP {
|
||||
break
|
||||
}
|
||||
|
||||
switch fieldId {
|
||||
case 1:
|
||||
if fieldTypeId == thrift.I64 {
|
||||
if err = p.ReadField1(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 2:
|
||||
if fieldTypeId == thrift.I64 {
|
||||
if err = p.ReadField2(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 255:
|
||||
if fieldTypeId == thrift.STRUCT {
|
||||
if err = p.ReadField255(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
default:
|
||||
if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadFieldEnd(); err != nil {
|
||||
goto ReadFieldEndError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadStructEnd(); err != nil {
|
||||
goto ReadStructEndError
|
||||
}
|
||||
|
||||
return nil
|
||||
ReadStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err)
|
||||
ReadFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err)
|
||||
ReadFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_GetOnlineAppDataRequest[fieldId]), err)
|
||||
SkipFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err)
|
||||
|
||||
ReadFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err)
|
||||
ReadStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *GetOnlineAppDataRequest) ReadField1(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field *int64
|
||||
if v, err := iprot.ReadI64(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = &v
|
||||
}
|
||||
p.AppID = _field
|
||||
return nil
|
||||
}
|
||||
func (p *GetOnlineAppDataRequest) ReadField2(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field *int64
|
||||
if v, err := iprot.ReadI64(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = &v
|
||||
}
|
||||
p.ConnectorID = _field
|
||||
return nil
|
||||
}
|
||||
func (p *GetOnlineAppDataRequest) ReadField255(iprot thrift.TProtocol) error {
|
||||
_field := base.NewBase()
|
||||
if err := _field.Read(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
p.Base = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *GetOnlineAppDataRequest) Write(oprot thrift.TProtocol) (err error) {
|
||||
var fieldId int16
|
||||
if err = oprot.WriteStructBegin("GetOnlineAppDataRequest"); err != nil {
|
||||
goto WriteStructBeginError
|
||||
}
|
||||
if p != nil {
|
||||
if err = p.writeField1(oprot); err != nil {
|
||||
fieldId = 1
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField2(oprot); err != nil {
|
||||
fieldId = 2
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField255(oprot); err != nil {
|
||||
fieldId = 255
|
||||
goto WriteFieldError
|
||||
}
|
||||
}
|
||||
if err = oprot.WriteFieldStop(); err != nil {
|
||||
goto WriteFieldStopError
|
||||
}
|
||||
if err = oprot.WriteStructEnd(); err != nil {
|
||||
goto WriteStructEndError
|
||||
}
|
||||
return nil
|
||||
WriteStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
|
||||
WriteFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err)
|
||||
WriteFieldStopError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err)
|
||||
WriteStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *GetOnlineAppDataRequest) writeField1(oprot thrift.TProtocol) (err error) {
|
||||
if p.IsSetAppID() {
|
||||
if err = oprot.WriteFieldBegin("app_id", thrift.I64, 1); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteI64(*p.AppID); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err)
|
||||
}
|
||||
func (p *GetOnlineAppDataRequest) writeField2(oprot thrift.TProtocol) (err error) {
|
||||
if p.IsSetConnectorID() {
|
||||
if err = oprot.WriteFieldBegin("connector_id", thrift.I64, 2); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteI64(*p.ConnectorID); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err)
|
||||
}
|
||||
func (p *GetOnlineAppDataRequest) writeField255(oprot thrift.TProtocol) (err error) {
|
||||
if p.IsSetBase() {
|
||||
if err = oprot.WriteFieldBegin("Base", thrift.STRUCT, 255); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := p.Base.Write(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 255 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 255 end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *GetOnlineAppDataRequest) String() string {
|
||||
if p == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("GetOnlineAppDataRequest(%+v)", *p)
|
||||
|
||||
}
|
||||
|
||||
type AppData struct {
|
||||
AppID string `thrift:"app_id,1" form:"app_id" json:"app_id" query:"app_id"`
|
||||
Version string `thrift:"version,2" form:"version" json:"version" query:"version"`
|
||||
Name string `thrift:"name,3" form:"name" json:"name" query:"name"`
|
||||
Description string `thrift:"description,4" form:"description" json:"description" query:"description"`
|
||||
IconURL string `thrift:"icon_url,5" form:"icon_url" json:"icon_url" query:"icon_url"`
|
||||
Variables []*common.Variable `thrift:"variables,6" form:"variables" json:"variables" query:"variables"`
|
||||
}
|
||||
|
||||
func NewAppData() *AppData {
|
||||
return &AppData{}
|
||||
}
|
||||
|
||||
func (p *AppData) InitDefault() {
|
||||
}
|
||||
|
||||
func (p *AppData) GetAppID() (v string) {
|
||||
return p.AppID
|
||||
}
|
||||
|
||||
func (p *AppData) GetVersion() (v string) {
|
||||
return p.Version
|
||||
}
|
||||
|
||||
func (p *AppData) GetName() (v string) {
|
||||
return p.Name
|
||||
}
|
||||
|
||||
func (p *AppData) GetDescription() (v string) {
|
||||
return p.Description
|
||||
}
|
||||
|
||||
func (p *AppData) GetIconURL() (v string) {
|
||||
return p.IconURL
|
||||
}
|
||||
|
||||
func (p *AppData) GetVariables() (v []*common.Variable) {
|
||||
return p.Variables
|
||||
}
|
||||
|
||||
var fieldIDToName_AppData = map[int16]string{
|
||||
1: "app_id",
|
||||
2: "version",
|
||||
3: "name",
|
||||
4: "description",
|
||||
5: "icon_url",
|
||||
6: "variables",
|
||||
}
|
||||
|
||||
func (p *AppData) Read(iprot thrift.TProtocol) (err error) {
|
||||
var fieldTypeId thrift.TType
|
||||
var fieldId int16
|
||||
|
||||
if _, err = iprot.ReadStructBegin(); err != nil {
|
||||
goto ReadStructBeginError
|
||||
}
|
||||
|
||||
for {
|
||||
_, fieldTypeId, fieldId, err = iprot.ReadFieldBegin()
|
||||
if err != nil {
|
||||
goto ReadFieldBeginError
|
||||
}
|
||||
if fieldTypeId == thrift.STOP {
|
||||
break
|
||||
}
|
||||
|
||||
switch fieldId {
|
||||
case 1:
|
||||
if fieldTypeId == thrift.STRING {
|
||||
if err = p.ReadField1(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 2:
|
||||
if fieldTypeId == thrift.STRING {
|
||||
if err = p.ReadField2(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 3:
|
||||
if fieldTypeId == thrift.STRING {
|
||||
if err = p.ReadField3(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 4:
|
||||
if fieldTypeId == thrift.STRING {
|
||||
if err = p.ReadField4(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 5:
|
||||
if fieldTypeId == thrift.STRING {
|
||||
if err = p.ReadField5(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 6:
|
||||
if fieldTypeId == thrift.LIST {
|
||||
if err = p.ReadField6(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
default:
|
||||
if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadFieldEnd(); err != nil {
|
||||
goto ReadFieldEndError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadStructEnd(); err != nil {
|
||||
goto ReadStructEndError
|
||||
}
|
||||
|
||||
return nil
|
||||
ReadStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err)
|
||||
ReadFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err)
|
||||
ReadFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_AppData[fieldId]), err)
|
||||
SkipFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err)
|
||||
|
||||
ReadFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err)
|
||||
ReadStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *AppData) ReadField1(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field string
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = v
|
||||
}
|
||||
p.AppID = _field
|
||||
return nil
|
||||
}
|
||||
func (p *AppData) ReadField2(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field string
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = v
|
||||
}
|
||||
p.Version = _field
|
||||
return nil
|
||||
}
|
||||
func (p *AppData) ReadField3(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field string
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = v
|
||||
}
|
||||
p.Name = _field
|
||||
return nil
|
||||
}
|
||||
func (p *AppData) ReadField4(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field string
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = v
|
||||
}
|
||||
p.Description = _field
|
||||
return nil
|
||||
}
|
||||
func (p *AppData) ReadField5(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field string
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = v
|
||||
}
|
||||
p.IconURL = _field
|
||||
return nil
|
||||
}
|
||||
func (p *AppData) ReadField6(iprot thrift.TProtocol) error {
|
||||
_, size, err := iprot.ReadListBegin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_field := make([]*common.Variable, 0, size)
|
||||
values := make([]common.Variable, size)
|
||||
for i := 0; i < size; i++ {
|
||||
_elem := &values[i]
|
||||
_elem.InitDefault()
|
||||
|
||||
if err := _elem.Read(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_field = append(_field, _elem)
|
||||
}
|
||||
if err := iprot.ReadListEnd(); err != nil {
|
||||
return err
|
||||
}
|
||||
p.Variables = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *AppData) Write(oprot thrift.TProtocol) (err error) {
|
||||
var fieldId int16
|
||||
if err = oprot.WriteStructBegin("AppData"); err != nil {
|
||||
goto WriteStructBeginError
|
||||
}
|
||||
if p != nil {
|
||||
if err = p.writeField1(oprot); err != nil {
|
||||
fieldId = 1
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField2(oprot); err != nil {
|
||||
fieldId = 2
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField3(oprot); err != nil {
|
||||
fieldId = 3
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField4(oprot); err != nil {
|
||||
fieldId = 4
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField5(oprot); err != nil {
|
||||
fieldId = 5
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField6(oprot); err != nil {
|
||||
fieldId = 6
|
||||
goto WriteFieldError
|
||||
}
|
||||
}
|
||||
if err = oprot.WriteFieldStop(); err != nil {
|
||||
goto WriteFieldStopError
|
||||
}
|
||||
if err = oprot.WriteStructEnd(); err != nil {
|
||||
goto WriteStructEndError
|
||||
}
|
||||
return nil
|
||||
WriteStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
|
||||
WriteFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err)
|
||||
WriteFieldStopError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err)
|
||||
WriteStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *AppData) writeField1(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("app_id", thrift.STRING, 1); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteString(p.AppID); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err)
|
||||
}
|
||||
func (p *AppData) writeField2(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("version", thrift.STRING, 2); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteString(p.Version); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err)
|
||||
}
|
||||
func (p *AppData) writeField3(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("name", thrift.STRING, 3); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteString(p.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 3 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 3 end error: ", p), err)
|
||||
}
|
||||
func (p *AppData) writeField4(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("description", thrift.STRING, 4); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteString(p.Description); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 4 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 4 end error: ", p), err)
|
||||
}
|
||||
func (p *AppData) writeField5(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("icon_url", thrift.STRING, 5); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteString(p.IconURL); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 5 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 5 end error: ", p), err)
|
||||
}
|
||||
func (p *AppData) writeField6(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("variables", thrift.LIST, 6); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteListBegin(thrift.STRUCT, len(p.Variables)); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, v := range p.Variables {
|
||||
if err := v.Write(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := oprot.WriteListEnd(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 6 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 6 end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *AppData) String() string {
|
||||
if p == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("AppData(%+v)", *p)
|
||||
|
||||
}
|
||||
|
||||
type GetOnlineAppDataResponse struct {
|
||||
Code *int32 `thrift:"Code,1,optional" form:"code" json:"code,omitempty"`
|
||||
Message *string `thrift:"Message,2,optional" form:"message" json:"message,omitempty"`
|
||||
Data *AppData `thrift:"Data,3" form:"data" json:"data"`
|
||||
BaseResp *base.BaseResp `thrift:"BaseResp,255" form:"BaseResp" json:"BaseResp" query:"BaseResp"`
|
||||
}
|
||||
|
||||
func NewGetOnlineAppDataResponse() *GetOnlineAppDataResponse {
|
||||
return &GetOnlineAppDataResponse{}
|
||||
}
|
||||
|
||||
func (p *GetOnlineAppDataResponse) InitDefault() {
|
||||
}
|
||||
|
||||
var GetOnlineAppDataResponse_Code_DEFAULT int32
|
||||
|
||||
func (p *GetOnlineAppDataResponse) GetCode() (v int32) {
|
||||
if !p.IsSetCode() {
|
||||
return GetOnlineAppDataResponse_Code_DEFAULT
|
||||
}
|
||||
return *p.Code
|
||||
}
|
||||
|
||||
var GetOnlineAppDataResponse_Message_DEFAULT string
|
||||
|
||||
func (p *GetOnlineAppDataResponse) GetMessage() (v string) {
|
||||
if !p.IsSetMessage() {
|
||||
return GetOnlineAppDataResponse_Message_DEFAULT
|
||||
}
|
||||
return *p.Message
|
||||
}
|
||||
|
||||
var GetOnlineAppDataResponse_Data_DEFAULT *AppData
|
||||
|
||||
func (p *GetOnlineAppDataResponse) GetData() (v *AppData) {
|
||||
if !p.IsSetData() {
|
||||
return GetOnlineAppDataResponse_Data_DEFAULT
|
||||
}
|
||||
return p.Data
|
||||
}
|
||||
|
||||
var GetOnlineAppDataResponse_BaseResp_DEFAULT *base.BaseResp
|
||||
|
||||
func (p *GetOnlineAppDataResponse) GetBaseResp() (v *base.BaseResp) {
|
||||
if !p.IsSetBaseResp() {
|
||||
return GetOnlineAppDataResponse_BaseResp_DEFAULT
|
||||
}
|
||||
return p.BaseResp
|
||||
}
|
||||
|
||||
var fieldIDToName_GetOnlineAppDataResponse = map[int16]string{
|
||||
1: "Code",
|
||||
2: "Message",
|
||||
3: "Data",
|
||||
255: "BaseResp",
|
||||
}
|
||||
|
||||
func (p *GetOnlineAppDataResponse) IsSetCode() bool {
|
||||
return p.Code != nil
|
||||
}
|
||||
|
||||
func (p *GetOnlineAppDataResponse) IsSetMessage() bool {
|
||||
return p.Message != nil
|
||||
}
|
||||
|
||||
func (p *GetOnlineAppDataResponse) IsSetData() bool {
|
||||
return p.Data != nil
|
||||
}
|
||||
|
||||
func (p *GetOnlineAppDataResponse) IsSetBaseResp() bool {
|
||||
return p.BaseResp != nil
|
||||
}
|
||||
|
||||
func (p *GetOnlineAppDataResponse) Read(iprot thrift.TProtocol) (err error) {
|
||||
var fieldTypeId thrift.TType
|
||||
var fieldId int16
|
||||
|
||||
if _, err = iprot.ReadStructBegin(); err != nil {
|
||||
goto ReadStructBeginError
|
||||
}
|
||||
|
||||
for {
|
||||
_, fieldTypeId, fieldId, err = iprot.ReadFieldBegin()
|
||||
if err != nil {
|
||||
goto ReadFieldBeginError
|
||||
}
|
||||
if fieldTypeId == thrift.STOP {
|
||||
break
|
||||
}
|
||||
|
||||
switch fieldId {
|
||||
case 1:
|
||||
if fieldTypeId == thrift.I32 {
|
||||
if err = p.ReadField1(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 2:
|
||||
if fieldTypeId == thrift.STRING {
|
||||
if err = p.ReadField2(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 3:
|
||||
if fieldTypeId == thrift.STRUCT {
|
||||
if err = p.ReadField3(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 255:
|
||||
if fieldTypeId == thrift.STRUCT {
|
||||
if err = p.ReadField255(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
default:
|
||||
if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadFieldEnd(); err != nil {
|
||||
goto ReadFieldEndError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadStructEnd(); err != nil {
|
||||
goto ReadStructEndError
|
||||
}
|
||||
|
||||
return nil
|
||||
ReadStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err)
|
||||
ReadFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err)
|
||||
ReadFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_GetOnlineAppDataResponse[fieldId]), err)
|
||||
SkipFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err)
|
||||
|
||||
ReadFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err)
|
||||
ReadStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *GetOnlineAppDataResponse) ReadField1(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field *int32
|
||||
if v, err := iprot.ReadI32(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = &v
|
||||
}
|
||||
p.Code = _field
|
||||
return nil
|
||||
}
|
||||
func (p *GetOnlineAppDataResponse) ReadField2(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field *string
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = &v
|
||||
}
|
||||
p.Message = _field
|
||||
return nil
|
||||
}
|
||||
func (p *GetOnlineAppDataResponse) ReadField3(iprot thrift.TProtocol) error {
|
||||
_field := NewAppData()
|
||||
if err := _field.Read(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
p.Data = _field
|
||||
return nil
|
||||
}
|
||||
func (p *GetOnlineAppDataResponse) ReadField255(iprot thrift.TProtocol) error {
|
||||
_field := base.NewBaseResp()
|
||||
if err := _field.Read(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
p.BaseResp = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *GetOnlineAppDataResponse) Write(oprot thrift.TProtocol) (err error) {
|
||||
var fieldId int16
|
||||
if err = oprot.WriteStructBegin("GetOnlineAppDataResponse"); err != nil {
|
||||
goto WriteStructBeginError
|
||||
}
|
||||
if p != nil {
|
||||
if err = p.writeField1(oprot); err != nil {
|
||||
fieldId = 1
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField2(oprot); err != nil {
|
||||
fieldId = 2
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField3(oprot); err != nil {
|
||||
fieldId = 3
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField255(oprot); err != nil {
|
||||
fieldId = 255
|
||||
goto WriteFieldError
|
||||
}
|
||||
}
|
||||
if err = oprot.WriteFieldStop(); err != nil {
|
||||
goto WriteFieldStopError
|
||||
}
|
||||
if err = oprot.WriteStructEnd(); err != nil {
|
||||
goto WriteStructEndError
|
||||
}
|
||||
return nil
|
||||
WriteStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
|
||||
WriteFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err)
|
||||
WriteFieldStopError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err)
|
||||
WriteStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *GetOnlineAppDataResponse) writeField1(oprot thrift.TProtocol) (err error) {
|
||||
if p.IsSetCode() {
|
||||
if err = oprot.WriteFieldBegin("Code", thrift.I32, 1); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteI32(*p.Code); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err)
|
||||
}
|
||||
func (p *GetOnlineAppDataResponse) writeField2(oprot thrift.TProtocol) (err error) {
|
||||
if p.IsSetMessage() {
|
||||
if err = oprot.WriteFieldBegin("Message", thrift.STRING, 2); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteString(*p.Message); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err)
|
||||
}
|
||||
func (p *GetOnlineAppDataResponse) writeField3(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("Data", thrift.STRUCT, 3); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := p.Data.Write(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 3 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 3 end error: ", p), err)
|
||||
}
|
||||
func (p *GetOnlineAppDataResponse) writeField255(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("BaseResp", thrift.STRUCT, 255); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := p.BaseResp.Write(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 255 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 255 end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *GetOnlineAppDataResponse) String() string {
|
||||
if p == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("GetOnlineAppDataResponse(%+v)", *p)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by thriftgo (0.4.1). DO NOT EDIT.
|
||||
|
||||
package agentrun
|
||||
|
|
@ -5,6 +21,7 @@ package agentrun
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/apache/thrift/lib/go/thrift"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/conversation/run"
|
||||
)
|
||||
|
|
@ -13,6 +30,8 @@ type AgentRunService interface {
|
|||
AgentRun(ctx context.Context, request *run.AgentRunRequest) (r *run.AgentRunResponse, err error)
|
||||
|
||||
ChatV3(ctx context.Context, request *run.ChatV3Request) (r *run.ChatV3Response, err error)
|
||||
|
||||
CancelChatApi(ctx context.Context, request *run.CancelChatApiRequest) (r *run.CancelChatApiResponse, err error)
|
||||
}
|
||||
|
||||
type AgentRunServiceClient struct {
|
||||
|
|
@ -59,6 +78,15 @@ func (p *AgentRunServiceClient) ChatV3(ctx context.Context, request *run.ChatV3R
|
|||
}
|
||||
return _result.GetSuccess(), nil
|
||||
}
|
||||
func (p *AgentRunServiceClient) CancelChatApi(ctx context.Context, request *run.CancelChatApiRequest) (r *run.CancelChatApiResponse, err error) {
|
||||
var _args AgentRunServiceCancelChatApiArgs
|
||||
_args.Request = request
|
||||
var _result AgentRunServiceCancelChatApiResult
|
||||
if err = p.Client_().Call(ctx, "CancelChatApi", &_args, &_result); err != nil {
|
||||
return
|
||||
}
|
||||
return _result.GetSuccess(), nil
|
||||
}
|
||||
|
||||
type AgentRunServiceProcessor struct {
|
||||
processorMap map[string]thrift.TProcessorFunction
|
||||
|
|
@ -82,6 +110,7 @@ func NewAgentRunServiceProcessor(handler AgentRunService) *AgentRunServiceProces
|
|||
self := &AgentRunServiceProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)}
|
||||
self.AddToProcessorMap("AgentRun", &agentRunServiceProcessorAgentRun{handler: handler})
|
||||
self.AddToProcessorMap("ChatV3", &agentRunServiceProcessorChatV3{handler: handler})
|
||||
self.AddToProcessorMap("CancelChatApi", &agentRunServiceProcessorCancelChatApi{handler: handler})
|
||||
return self
|
||||
}
|
||||
func (p *AgentRunServiceProcessor) Process(ctx context.Context, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
|
||||
|
|
@ -198,6 +227,54 @@ func (p *agentRunServiceProcessorChatV3) Process(ctx context.Context, seqId int3
|
|||
return true, err
|
||||
}
|
||||
|
||||
type agentRunServiceProcessorCancelChatApi struct {
|
||||
handler AgentRunService
|
||||
}
|
||||
|
||||
func (p *agentRunServiceProcessorCancelChatApi) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
|
||||
args := AgentRunServiceCancelChatApiArgs{}
|
||||
if err = args.Read(iprot); err != nil {
|
||||
iprot.ReadMessageEnd()
|
||||
x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error())
|
||||
oprot.WriteMessageBegin("CancelChatApi", thrift.EXCEPTION, seqId)
|
||||
x.Write(oprot)
|
||||
oprot.WriteMessageEnd()
|
||||
oprot.Flush(ctx)
|
||||
return false, err
|
||||
}
|
||||
|
||||
iprot.ReadMessageEnd()
|
||||
var err2 error
|
||||
result := AgentRunServiceCancelChatApiResult{}
|
||||
var retval *run.CancelChatApiResponse
|
||||
if retval, err2 = p.handler.CancelChatApi(ctx, args.Request); err2 != nil {
|
||||
x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing CancelChatApi: "+err2.Error())
|
||||
oprot.WriteMessageBegin("CancelChatApi", thrift.EXCEPTION, seqId)
|
||||
x.Write(oprot)
|
||||
oprot.WriteMessageEnd()
|
||||
oprot.Flush(ctx)
|
||||
return true, err2
|
||||
} else {
|
||||
result.Success = retval
|
||||
}
|
||||
if err2 = oprot.WriteMessageBegin("CancelChatApi", thrift.REPLY, seqId); err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
if err2 = result.Write(oprot); err == nil && err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
if err2 = oprot.Flush(ctx); err == nil && err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return true, err
|
||||
}
|
||||
|
||||
type AgentRunServiceAgentRunArgs struct {
|
||||
Request *run.AgentRunRequest `thrift:"request,1"`
|
||||
}
|
||||
|
|
@ -781,3 +858,295 @@ func (p *AgentRunServiceChatV3Result) String() string {
|
|||
return fmt.Sprintf("AgentRunServiceChatV3Result(%+v)", *p)
|
||||
|
||||
}
|
||||
|
||||
type AgentRunServiceCancelChatApiArgs struct {
|
||||
Request *run.CancelChatApiRequest `thrift:"request,1"`
|
||||
}
|
||||
|
||||
func NewAgentRunServiceCancelChatApiArgs() *AgentRunServiceCancelChatApiArgs {
|
||||
return &AgentRunServiceCancelChatApiArgs{}
|
||||
}
|
||||
|
||||
func (p *AgentRunServiceCancelChatApiArgs) InitDefault() {
|
||||
}
|
||||
|
||||
var AgentRunServiceCancelChatApiArgs_Request_DEFAULT *run.CancelChatApiRequest
|
||||
|
||||
func (p *AgentRunServiceCancelChatApiArgs) GetRequest() (v *run.CancelChatApiRequest) {
|
||||
if !p.IsSetRequest() {
|
||||
return AgentRunServiceCancelChatApiArgs_Request_DEFAULT
|
||||
}
|
||||
return p.Request
|
||||
}
|
||||
|
||||
var fieldIDToName_AgentRunServiceCancelChatApiArgs = map[int16]string{
|
||||
1: "request",
|
||||
}
|
||||
|
||||
func (p *AgentRunServiceCancelChatApiArgs) IsSetRequest() bool {
|
||||
return p.Request != nil
|
||||
}
|
||||
|
||||
func (p *AgentRunServiceCancelChatApiArgs) Read(iprot thrift.TProtocol) (err error) {
|
||||
var fieldTypeId thrift.TType
|
||||
var fieldId int16
|
||||
|
||||
if _, err = iprot.ReadStructBegin(); err != nil {
|
||||
goto ReadStructBeginError
|
||||
}
|
||||
|
||||
for {
|
||||
_, fieldTypeId, fieldId, err = iprot.ReadFieldBegin()
|
||||
if err != nil {
|
||||
goto ReadFieldBeginError
|
||||
}
|
||||
if fieldTypeId == thrift.STOP {
|
||||
break
|
||||
}
|
||||
|
||||
switch fieldId {
|
||||
case 1:
|
||||
if fieldTypeId == thrift.STRUCT {
|
||||
if err = p.ReadField1(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
default:
|
||||
if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadFieldEnd(); err != nil {
|
||||
goto ReadFieldEndError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadStructEnd(); err != nil {
|
||||
goto ReadStructEndError
|
||||
}
|
||||
|
||||
return nil
|
||||
ReadStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err)
|
||||
ReadFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err)
|
||||
ReadFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_AgentRunServiceCancelChatApiArgs[fieldId]), err)
|
||||
SkipFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err)
|
||||
|
||||
ReadFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err)
|
||||
ReadStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *AgentRunServiceCancelChatApiArgs) ReadField1(iprot thrift.TProtocol) error {
|
||||
_field := run.NewCancelChatApiRequest()
|
||||
if err := _field.Read(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
p.Request = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *AgentRunServiceCancelChatApiArgs) Write(oprot thrift.TProtocol) (err error) {
|
||||
var fieldId int16
|
||||
if err = oprot.WriteStructBegin("CancelChatApi_args"); err != nil {
|
||||
goto WriteStructBeginError
|
||||
}
|
||||
if p != nil {
|
||||
if err = p.writeField1(oprot); err != nil {
|
||||
fieldId = 1
|
||||
goto WriteFieldError
|
||||
}
|
||||
}
|
||||
if err = oprot.WriteFieldStop(); err != nil {
|
||||
goto WriteFieldStopError
|
||||
}
|
||||
if err = oprot.WriteStructEnd(); err != nil {
|
||||
goto WriteStructEndError
|
||||
}
|
||||
return nil
|
||||
WriteStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
|
||||
WriteFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err)
|
||||
WriteFieldStopError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err)
|
||||
WriteStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *AgentRunServiceCancelChatApiArgs) writeField1(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("request", thrift.STRUCT, 1); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := p.Request.Write(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *AgentRunServiceCancelChatApiArgs) String() string {
|
||||
if p == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("AgentRunServiceCancelChatApiArgs(%+v)", *p)
|
||||
|
||||
}
|
||||
|
||||
type AgentRunServiceCancelChatApiResult struct {
|
||||
Success *run.CancelChatApiResponse `thrift:"success,0,optional"`
|
||||
}
|
||||
|
||||
func NewAgentRunServiceCancelChatApiResult() *AgentRunServiceCancelChatApiResult {
|
||||
return &AgentRunServiceCancelChatApiResult{}
|
||||
}
|
||||
|
||||
func (p *AgentRunServiceCancelChatApiResult) InitDefault() {
|
||||
}
|
||||
|
||||
var AgentRunServiceCancelChatApiResult_Success_DEFAULT *run.CancelChatApiResponse
|
||||
|
||||
func (p *AgentRunServiceCancelChatApiResult) GetSuccess() (v *run.CancelChatApiResponse) {
|
||||
if !p.IsSetSuccess() {
|
||||
return AgentRunServiceCancelChatApiResult_Success_DEFAULT
|
||||
}
|
||||
return p.Success
|
||||
}
|
||||
|
||||
var fieldIDToName_AgentRunServiceCancelChatApiResult = map[int16]string{
|
||||
0: "success",
|
||||
}
|
||||
|
||||
func (p *AgentRunServiceCancelChatApiResult) IsSetSuccess() bool {
|
||||
return p.Success != nil
|
||||
}
|
||||
|
||||
func (p *AgentRunServiceCancelChatApiResult) Read(iprot thrift.TProtocol) (err error) {
|
||||
var fieldTypeId thrift.TType
|
||||
var fieldId int16
|
||||
|
||||
if _, err = iprot.ReadStructBegin(); err != nil {
|
||||
goto ReadStructBeginError
|
||||
}
|
||||
|
||||
for {
|
||||
_, fieldTypeId, fieldId, err = iprot.ReadFieldBegin()
|
||||
if err != nil {
|
||||
goto ReadFieldBeginError
|
||||
}
|
||||
if fieldTypeId == thrift.STOP {
|
||||
break
|
||||
}
|
||||
|
||||
switch fieldId {
|
||||
case 0:
|
||||
if fieldTypeId == thrift.STRUCT {
|
||||
if err = p.ReadField0(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
default:
|
||||
if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadFieldEnd(); err != nil {
|
||||
goto ReadFieldEndError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadStructEnd(); err != nil {
|
||||
goto ReadStructEndError
|
||||
}
|
||||
|
||||
return nil
|
||||
ReadStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err)
|
||||
ReadFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err)
|
||||
ReadFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_AgentRunServiceCancelChatApiResult[fieldId]), err)
|
||||
SkipFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err)
|
||||
|
||||
ReadFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err)
|
||||
ReadStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *AgentRunServiceCancelChatApiResult) ReadField0(iprot thrift.TProtocol) error {
|
||||
_field := run.NewCancelChatApiResponse()
|
||||
if err := _field.Read(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
p.Success = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *AgentRunServiceCancelChatApiResult) Write(oprot thrift.TProtocol) (err error) {
|
||||
var fieldId int16
|
||||
if err = oprot.WriteStructBegin("CancelChatApi_result"); err != nil {
|
||||
goto WriteStructBeginError
|
||||
}
|
||||
if p != nil {
|
||||
if err = p.writeField0(oprot); err != nil {
|
||||
fieldId = 0
|
||||
goto WriteFieldError
|
||||
}
|
||||
}
|
||||
if err = oprot.WriteFieldStop(); err != nil {
|
||||
goto WriteFieldStopError
|
||||
}
|
||||
if err = oprot.WriteStructEnd(); err != nil {
|
||||
goto WriteStructEndError
|
||||
}
|
||||
return nil
|
||||
WriteStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
|
||||
WriteFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err)
|
||||
WriteFieldStopError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err)
|
||||
WriteStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *AgentRunServiceCancelChatApiResult) writeField0(oprot thrift.TProtocol) (err error) {
|
||||
if p.IsSetSuccess() {
|
||||
if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := p.Success.Write(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *AgentRunServiceCancelChatApiResult) String() string {
|
||||
if p == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("AgentRunServiceCancelChatApiResult(%+v)", *p)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by thriftgo (0.4.1). DO NOT EDIT.
|
||||
|
||||
package common
|
||||
|
|
@ -26,6 +42,8 @@ const (
|
|||
Scene_GenerateAgentInfo Scene = 8
|
||||
//openapi
|
||||
Scene_SceneOpenApi Scene = 9
|
||||
// workflow
|
||||
Scene_SceneWorkflow Scene = 50
|
||||
)
|
||||
|
||||
func (p Scene) String() string {
|
||||
|
|
@ -50,6 +68,8 @@ func (p Scene) String() string {
|
|||
return "GenerateAgentInfo"
|
||||
case Scene_SceneOpenApi:
|
||||
return "SceneOpenApi"
|
||||
case Scene_SceneWorkflow:
|
||||
return "SceneWorkflow"
|
||||
}
|
||||
return "<UNSET>"
|
||||
}
|
||||
|
|
@ -76,6 +96,8 @@ func SceneFromString(s string) (Scene, error) {
|
|||
return Scene_GenerateAgentInfo, nil
|
||||
case "SceneOpenApi":
|
||||
return Scene_SceneOpenApi, nil
|
||||
case "SceneWorkflow":
|
||||
return Scene_SceneWorkflow, nil
|
||||
}
|
||||
return Scene(0), fmt.Errorf("not a valid Scene string")
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by thriftgo (0.4.1). DO NOT EDIT.
|
||||
|
||||
package conversation
|
||||
|
|
@ -5,6 +21,7 @@ package conversation
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/apache/thrift/lib/go/thrift"
|
||||
)
|
||||
|
||||
|
|
@ -18,6 +35,10 @@ type ConversationService interface {
|
|||
ClearConversationApi(ctx context.Context, req *ClearConversationApiRequest) (r *ClearConversationApiResponse, err error)
|
||||
|
||||
ListConversationsApi(ctx context.Context, request *ListConversationsApiRequest) (r *ListConversationsApiResponse, err error)
|
||||
|
||||
UpdateConversationApi(ctx context.Context, request *UpdateConversationApiRequest) (r *UpdateConversationApiResponse, err error)
|
||||
|
||||
DeleteConversationApi(ctx context.Context, req *DeleteConversationApiRequest) (r *DeleteConversationApiResponse, err error)
|
||||
}
|
||||
|
||||
type ConversationServiceClient struct {
|
||||
|
|
@ -91,6 +112,24 @@ func (p *ConversationServiceClient) ListConversationsApi(ctx context.Context, re
|
|||
}
|
||||
return _result.GetSuccess(), nil
|
||||
}
|
||||
func (p *ConversationServiceClient) UpdateConversationApi(ctx context.Context, request *UpdateConversationApiRequest) (r *UpdateConversationApiResponse, err error) {
|
||||
var _args ConversationServiceUpdateConversationApiArgs
|
||||
_args.Request = request
|
||||
var _result ConversationServiceUpdateConversationApiResult
|
||||
if err = p.Client_().Call(ctx, "UpdateConversationApi", &_args, &_result); err != nil {
|
||||
return
|
||||
}
|
||||
return _result.GetSuccess(), nil
|
||||
}
|
||||
func (p *ConversationServiceClient) DeleteConversationApi(ctx context.Context, req *DeleteConversationApiRequest) (r *DeleteConversationApiResponse, err error) {
|
||||
var _args ConversationServiceDeleteConversationApiArgs
|
||||
_args.Req = req
|
||||
var _result ConversationServiceDeleteConversationApiResult
|
||||
if err = p.Client_().Call(ctx, "DeleteConversationApi", &_args, &_result); err != nil {
|
||||
return
|
||||
}
|
||||
return _result.GetSuccess(), nil
|
||||
}
|
||||
|
||||
type ConversationServiceProcessor struct {
|
||||
processorMap map[string]thrift.TProcessorFunction
|
||||
|
|
@ -117,6 +156,8 @@ func NewConversationServiceProcessor(handler ConversationService) *ConversationS
|
|||
self.AddToProcessorMap("CreateConversation", &conversationServiceProcessorCreateConversation{handler: handler})
|
||||
self.AddToProcessorMap("ClearConversationApi", &conversationServiceProcessorClearConversationApi{handler: handler})
|
||||
self.AddToProcessorMap("ListConversationsApi", &conversationServiceProcessorListConversationsApi{handler: handler})
|
||||
self.AddToProcessorMap("UpdateConversationApi", &conversationServiceProcessorUpdateConversationApi{handler: handler})
|
||||
self.AddToProcessorMap("DeleteConversationApi", &conversationServiceProcessorDeleteConversationApi{handler: handler})
|
||||
return self
|
||||
}
|
||||
func (p *ConversationServiceProcessor) Process(ctx context.Context, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
|
||||
|
|
@ -377,6 +418,102 @@ func (p *conversationServiceProcessorListConversationsApi) Process(ctx context.C
|
|||
return true, err
|
||||
}
|
||||
|
||||
type conversationServiceProcessorUpdateConversationApi struct {
|
||||
handler ConversationService
|
||||
}
|
||||
|
||||
func (p *conversationServiceProcessorUpdateConversationApi) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
|
||||
args := ConversationServiceUpdateConversationApiArgs{}
|
||||
if err = args.Read(iprot); err != nil {
|
||||
iprot.ReadMessageEnd()
|
||||
x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error())
|
||||
oprot.WriteMessageBegin("UpdateConversationApi", thrift.EXCEPTION, seqId)
|
||||
x.Write(oprot)
|
||||
oprot.WriteMessageEnd()
|
||||
oprot.Flush(ctx)
|
||||
return false, err
|
||||
}
|
||||
|
||||
iprot.ReadMessageEnd()
|
||||
var err2 error
|
||||
result := ConversationServiceUpdateConversationApiResult{}
|
||||
var retval *UpdateConversationApiResponse
|
||||
if retval, err2 = p.handler.UpdateConversationApi(ctx, args.Request); err2 != nil {
|
||||
x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing UpdateConversationApi: "+err2.Error())
|
||||
oprot.WriteMessageBegin("UpdateConversationApi", thrift.EXCEPTION, seqId)
|
||||
x.Write(oprot)
|
||||
oprot.WriteMessageEnd()
|
||||
oprot.Flush(ctx)
|
||||
return true, err2
|
||||
} else {
|
||||
result.Success = retval
|
||||
}
|
||||
if err2 = oprot.WriteMessageBegin("UpdateConversationApi", thrift.REPLY, seqId); err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
if err2 = result.Write(oprot); err == nil && err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
if err2 = oprot.Flush(ctx); err == nil && err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return true, err
|
||||
}
|
||||
|
||||
type conversationServiceProcessorDeleteConversationApi struct {
|
||||
handler ConversationService
|
||||
}
|
||||
|
||||
func (p *conversationServiceProcessorDeleteConversationApi) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
|
||||
args := ConversationServiceDeleteConversationApiArgs{}
|
||||
if err = args.Read(iprot); err != nil {
|
||||
iprot.ReadMessageEnd()
|
||||
x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error())
|
||||
oprot.WriteMessageBegin("DeleteConversationApi", thrift.EXCEPTION, seqId)
|
||||
x.Write(oprot)
|
||||
oprot.WriteMessageEnd()
|
||||
oprot.Flush(ctx)
|
||||
return false, err
|
||||
}
|
||||
|
||||
iprot.ReadMessageEnd()
|
||||
var err2 error
|
||||
result := ConversationServiceDeleteConversationApiResult{}
|
||||
var retval *DeleteConversationApiResponse
|
||||
if retval, err2 = p.handler.DeleteConversationApi(ctx, args.Req); err2 != nil {
|
||||
x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing DeleteConversationApi: "+err2.Error())
|
||||
oprot.WriteMessageBegin("DeleteConversationApi", thrift.EXCEPTION, seqId)
|
||||
x.Write(oprot)
|
||||
oprot.WriteMessageEnd()
|
||||
oprot.Flush(ctx)
|
||||
return true, err2
|
||||
} else {
|
||||
result.Success = retval
|
||||
}
|
||||
if err2 = oprot.WriteMessageBegin("DeleteConversationApi", thrift.REPLY, seqId); err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
if err2 = result.Write(oprot); err == nil && err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
if err2 = oprot.Flush(ctx); err == nil && err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return true, err
|
||||
}
|
||||
|
||||
type ConversationServiceClearConversationCtxArgs struct {
|
||||
Request *ClearConversationCtxRequest `thrift:"request,1"`
|
||||
}
|
||||
|
|
@ -1836,3 +1973,587 @@ func (p *ConversationServiceListConversationsApiResult) String() string {
|
|||
return fmt.Sprintf("ConversationServiceListConversationsApiResult(%+v)", *p)
|
||||
|
||||
}
|
||||
|
||||
type ConversationServiceUpdateConversationApiArgs struct {
|
||||
Request *UpdateConversationApiRequest `thrift:"request,1"`
|
||||
}
|
||||
|
||||
func NewConversationServiceUpdateConversationApiArgs() *ConversationServiceUpdateConversationApiArgs {
|
||||
return &ConversationServiceUpdateConversationApiArgs{}
|
||||
}
|
||||
|
||||
func (p *ConversationServiceUpdateConversationApiArgs) InitDefault() {
|
||||
}
|
||||
|
||||
var ConversationServiceUpdateConversationApiArgs_Request_DEFAULT *UpdateConversationApiRequest
|
||||
|
||||
func (p *ConversationServiceUpdateConversationApiArgs) GetRequest() (v *UpdateConversationApiRequest) {
|
||||
if !p.IsSetRequest() {
|
||||
return ConversationServiceUpdateConversationApiArgs_Request_DEFAULT
|
||||
}
|
||||
return p.Request
|
||||
}
|
||||
|
||||
var fieldIDToName_ConversationServiceUpdateConversationApiArgs = map[int16]string{
|
||||
1: "request",
|
||||
}
|
||||
|
||||
func (p *ConversationServiceUpdateConversationApiArgs) IsSetRequest() bool {
|
||||
return p.Request != nil
|
||||
}
|
||||
|
||||
func (p *ConversationServiceUpdateConversationApiArgs) Read(iprot thrift.TProtocol) (err error) {
|
||||
var fieldTypeId thrift.TType
|
||||
var fieldId int16
|
||||
|
||||
if _, err = iprot.ReadStructBegin(); err != nil {
|
||||
goto ReadStructBeginError
|
||||
}
|
||||
|
||||
for {
|
||||
_, fieldTypeId, fieldId, err = iprot.ReadFieldBegin()
|
||||
if err != nil {
|
||||
goto ReadFieldBeginError
|
||||
}
|
||||
if fieldTypeId == thrift.STOP {
|
||||
break
|
||||
}
|
||||
|
||||
switch fieldId {
|
||||
case 1:
|
||||
if fieldTypeId == thrift.STRUCT {
|
||||
if err = p.ReadField1(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
default:
|
||||
if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadFieldEnd(); err != nil {
|
||||
goto ReadFieldEndError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadStructEnd(); err != nil {
|
||||
goto ReadStructEndError
|
||||
}
|
||||
|
||||
return nil
|
||||
ReadStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err)
|
||||
ReadFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err)
|
||||
ReadFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_ConversationServiceUpdateConversationApiArgs[fieldId]), err)
|
||||
SkipFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err)
|
||||
|
||||
ReadFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err)
|
||||
ReadStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *ConversationServiceUpdateConversationApiArgs) ReadField1(iprot thrift.TProtocol) error {
|
||||
_field := NewUpdateConversationApiRequest()
|
||||
if err := _field.Read(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
p.Request = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *ConversationServiceUpdateConversationApiArgs) Write(oprot thrift.TProtocol) (err error) {
|
||||
var fieldId int16
|
||||
if err = oprot.WriteStructBegin("UpdateConversationApi_args"); err != nil {
|
||||
goto WriteStructBeginError
|
||||
}
|
||||
if p != nil {
|
||||
if err = p.writeField1(oprot); err != nil {
|
||||
fieldId = 1
|
||||
goto WriteFieldError
|
||||
}
|
||||
}
|
||||
if err = oprot.WriteFieldStop(); err != nil {
|
||||
goto WriteFieldStopError
|
||||
}
|
||||
if err = oprot.WriteStructEnd(); err != nil {
|
||||
goto WriteStructEndError
|
||||
}
|
||||
return nil
|
||||
WriteStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
|
||||
WriteFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err)
|
||||
WriteFieldStopError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err)
|
||||
WriteStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *ConversationServiceUpdateConversationApiArgs) writeField1(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("request", thrift.STRUCT, 1); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := p.Request.Write(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *ConversationServiceUpdateConversationApiArgs) String() string {
|
||||
if p == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("ConversationServiceUpdateConversationApiArgs(%+v)", *p)
|
||||
|
||||
}
|
||||
|
||||
type ConversationServiceUpdateConversationApiResult struct {
|
||||
Success *UpdateConversationApiResponse `thrift:"success,0,optional"`
|
||||
}
|
||||
|
||||
func NewConversationServiceUpdateConversationApiResult() *ConversationServiceUpdateConversationApiResult {
|
||||
return &ConversationServiceUpdateConversationApiResult{}
|
||||
}
|
||||
|
||||
func (p *ConversationServiceUpdateConversationApiResult) InitDefault() {
|
||||
}
|
||||
|
||||
var ConversationServiceUpdateConversationApiResult_Success_DEFAULT *UpdateConversationApiResponse
|
||||
|
||||
func (p *ConversationServiceUpdateConversationApiResult) GetSuccess() (v *UpdateConversationApiResponse) {
|
||||
if !p.IsSetSuccess() {
|
||||
return ConversationServiceUpdateConversationApiResult_Success_DEFAULT
|
||||
}
|
||||
return p.Success
|
||||
}
|
||||
|
||||
var fieldIDToName_ConversationServiceUpdateConversationApiResult = map[int16]string{
|
||||
0: "success",
|
||||
}
|
||||
|
||||
func (p *ConversationServiceUpdateConversationApiResult) IsSetSuccess() bool {
|
||||
return p.Success != nil
|
||||
}
|
||||
|
||||
func (p *ConversationServiceUpdateConversationApiResult) Read(iprot thrift.TProtocol) (err error) {
|
||||
var fieldTypeId thrift.TType
|
||||
var fieldId int16
|
||||
|
||||
if _, err = iprot.ReadStructBegin(); err != nil {
|
||||
goto ReadStructBeginError
|
||||
}
|
||||
|
||||
for {
|
||||
_, fieldTypeId, fieldId, err = iprot.ReadFieldBegin()
|
||||
if err != nil {
|
||||
goto ReadFieldBeginError
|
||||
}
|
||||
if fieldTypeId == thrift.STOP {
|
||||
break
|
||||
}
|
||||
|
||||
switch fieldId {
|
||||
case 0:
|
||||
if fieldTypeId == thrift.STRUCT {
|
||||
if err = p.ReadField0(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
default:
|
||||
if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadFieldEnd(); err != nil {
|
||||
goto ReadFieldEndError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadStructEnd(); err != nil {
|
||||
goto ReadStructEndError
|
||||
}
|
||||
|
||||
return nil
|
||||
ReadStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err)
|
||||
ReadFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err)
|
||||
ReadFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_ConversationServiceUpdateConversationApiResult[fieldId]), err)
|
||||
SkipFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err)
|
||||
|
||||
ReadFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err)
|
||||
ReadStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *ConversationServiceUpdateConversationApiResult) ReadField0(iprot thrift.TProtocol) error {
|
||||
_field := NewUpdateConversationApiResponse()
|
||||
if err := _field.Read(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
p.Success = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *ConversationServiceUpdateConversationApiResult) Write(oprot thrift.TProtocol) (err error) {
|
||||
var fieldId int16
|
||||
if err = oprot.WriteStructBegin("UpdateConversationApi_result"); err != nil {
|
||||
goto WriteStructBeginError
|
||||
}
|
||||
if p != nil {
|
||||
if err = p.writeField0(oprot); err != nil {
|
||||
fieldId = 0
|
||||
goto WriteFieldError
|
||||
}
|
||||
}
|
||||
if err = oprot.WriteFieldStop(); err != nil {
|
||||
goto WriteFieldStopError
|
||||
}
|
||||
if err = oprot.WriteStructEnd(); err != nil {
|
||||
goto WriteStructEndError
|
||||
}
|
||||
return nil
|
||||
WriteStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
|
||||
WriteFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err)
|
||||
WriteFieldStopError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err)
|
||||
WriteStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *ConversationServiceUpdateConversationApiResult) writeField0(oprot thrift.TProtocol) (err error) {
|
||||
if p.IsSetSuccess() {
|
||||
if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := p.Success.Write(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *ConversationServiceUpdateConversationApiResult) String() string {
|
||||
if p == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("ConversationServiceUpdateConversationApiResult(%+v)", *p)
|
||||
|
||||
}
|
||||
|
||||
type ConversationServiceDeleteConversationApiArgs struct {
|
||||
Req *DeleteConversationApiRequest `thrift:"req,1"`
|
||||
}
|
||||
|
||||
func NewConversationServiceDeleteConversationApiArgs() *ConversationServiceDeleteConversationApiArgs {
|
||||
return &ConversationServiceDeleteConversationApiArgs{}
|
||||
}
|
||||
|
||||
func (p *ConversationServiceDeleteConversationApiArgs) InitDefault() {
|
||||
}
|
||||
|
||||
var ConversationServiceDeleteConversationApiArgs_Req_DEFAULT *DeleteConversationApiRequest
|
||||
|
||||
func (p *ConversationServiceDeleteConversationApiArgs) GetReq() (v *DeleteConversationApiRequest) {
|
||||
if !p.IsSetReq() {
|
||||
return ConversationServiceDeleteConversationApiArgs_Req_DEFAULT
|
||||
}
|
||||
return p.Req
|
||||
}
|
||||
|
||||
var fieldIDToName_ConversationServiceDeleteConversationApiArgs = map[int16]string{
|
||||
1: "req",
|
||||
}
|
||||
|
||||
func (p *ConversationServiceDeleteConversationApiArgs) IsSetReq() bool {
|
||||
return p.Req != nil
|
||||
}
|
||||
|
||||
func (p *ConversationServiceDeleteConversationApiArgs) Read(iprot thrift.TProtocol) (err error) {
|
||||
var fieldTypeId thrift.TType
|
||||
var fieldId int16
|
||||
|
||||
if _, err = iprot.ReadStructBegin(); err != nil {
|
||||
goto ReadStructBeginError
|
||||
}
|
||||
|
||||
for {
|
||||
_, fieldTypeId, fieldId, err = iprot.ReadFieldBegin()
|
||||
if err != nil {
|
||||
goto ReadFieldBeginError
|
||||
}
|
||||
if fieldTypeId == thrift.STOP {
|
||||
break
|
||||
}
|
||||
|
||||
switch fieldId {
|
||||
case 1:
|
||||
if fieldTypeId == thrift.STRUCT {
|
||||
if err = p.ReadField1(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
default:
|
||||
if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadFieldEnd(); err != nil {
|
||||
goto ReadFieldEndError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadStructEnd(); err != nil {
|
||||
goto ReadStructEndError
|
||||
}
|
||||
|
||||
return nil
|
||||
ReadStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err)
|
||||
ReadFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err)
|
||||
ReadFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_ConversationServiceDeleteConversationApiArgs[fieldId]), err)
|
||||
SkipFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err)
|
||||
|
||||
ReadFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err)
|
||||
ReadStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *ConversationServiceDeleteConversationApiArgs) ReadField1(iprot thrift.TProtocol) error {
|
||||
_field := NewDeleteConversationApiRequest()
|
||||
if err := _field.Read(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
p.Req = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *ConversationServiceDeleteConversationApiArgs) Write(oprot thrift.TProtocol) (err error) {
|
||||
var fieldId int16
|
||||
if err = oprot.WriteStructBegin("DeleteConversationApi_args"); err != nil {
|
||||
goto WriteStructBeginError
|
||||
}
|
||||
if p != nil {
|
||||
if err = p.writeField1(oprot); err != nil {
|
||||
fieldId = 1
|
||||
goto WriteFieldError
|
||||
}
|
||||
}
|
||||
if err = oprot.WriteFieldStop(); err != nil {
|
||||
goto WriteFieldStopError
|
||||
}
|
||||
if err = oprot.WriteStructEnd(); err != nil {
|
||||
goto WriteStructEndError
|
||||
}
|
||||
return nil
|
||||
WriteStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
|
||||
WriteFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err)
|
||||
WriteFieldStopError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err)
|
||||
WriteStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *ConversationServiceDeleteConversationApiArgs) writeField1(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("req", thrift.STRUCT, 1); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := p.Req.Write(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *ConversationServiceDeleteConversationApiArgs) String() string {
|
||||
if p == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("ConversationServiceDeleteConversationApiArgs(%+v)", *p)
|
||||
|
||||
}
|
||||
|
||||
type ConversationServiceDeleteConversationApiResult struct {
|
||||
Success *DeleteConversationApiResponse `thrift:"success,0,optional"`
|
||||
}
|
||||
|
||||
func NewConversationServiceDeleteConversationApiResult() *ConversationServiceDeleteConversationApiResult {
|
||||
return &ConversationServiceDeleteConversationApiResult{}
|
||||
}
|
||||
|
||||
func (p *ConversationServiceDeleteConversationApiResult) InitDefault() {
|
||||
}
|
||||
|
||||
var ConversationServiceDeleteConversationApiResult_Success_DEFAULT *DeleteConversationApiResponse
|
||||
|
||||
func (p *ConversationServiceDeleteConversationApiResult) GetSuccess() (v *DeleteConversationApiResponse) {
|
||||
if !p.IsSetSuccess() {
|
||||
return ConversationServiceDeleteConversationApiResult_Success_DEFAULT
|
||||
}
|
||||
return p.Success
|
||||
}
|
||||
|
||||
var fieldIDToName_ConversationServiceDeleteConversationApiResult = map[int16]string{
|
||||
0: "success",
|
||||
}
|
||||
|
||||
func (p *ConversationServiceDeleteConversationApiResult) IsSetSuccess() bool {
|
||||
return p.Success != nil
|
||||
}
|
||||
|
||||
func (p *ConversationServiceDeleteConversationApiResult) Read(iprot thrift.TProtocol) (err error) {
|
||||
var fieldTypeId thrift.TType
|
||||
var fieldId int16
|
||||
|
||||
if _, err = iprot.ReadStructBegin(); err != nil {
|
||||
goto ReadStructBeginError
|
||||
}
|
||||
|
||||
for {
|
||||
_, fieldTypeId, fieldId, err = iprot.ReadFieldBegin()
|
||||
if err != nil {
|
||||
goto ReadFieldBeginError
|
||||
}
|
||||
if fieldTypeId == thrift.STOP {
|
||||
break
|
||||
}
|
||||
|
||||
switch fieldId {
|
||||
case 0:
|
||||
if fieldTypeId == thrift.STRUCT {
|
||||
if err = p.ReadField0(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
default:
|
||||
if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadFieldEnd(); err != nil {
|
||||
goto ReadFieldEndError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadStructEnd(); err != nil {
|
||||
goto ReadStructEndError
|
||||
}
|
||||
|
||||
return nil
|
||||
ReadStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err)
|
||||
ReadFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err)
|
||||
ReadFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_ConversationServiceDeleteConversationApiResult[fieldId]), err)
|
||||
SkipFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err)
|
||||
|
||||
ReadFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err)
|
||||
ReadStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *ConversationServiceDeleteConversationApiResult) ReadField0(iprot thrift.TProtocol) error {
|
||||
_field := NewDeleteConversationApiResponse()
|
||||
if err := _field.Read(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
p.Success = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *ConversationServiceDeleteConversationApiResult) Write(oprot thrift.TProtocol) (err error) {
|
||||
var fieldId int16
|
||||
if err = oprot.WriteStructBegin("DeleteConversationApi_result"); err != nil {
|
||||
goto WriteStructBeginError
|
||||
}
|
||||
if p != nil {
|
||||
if err = p.writeField0(oprot); err != nil {
|
||||
fieldId = 0
|
||||
goto WriteFieldError
|
||||
}
|
||||
}
|
||||
if err = oprot.WriteFieldStop(); err != nil {
|
||||
goto WriteFieldStopError
|
||||
}
|
||||
if err = oprot.WriteStructEnd(); err != nil {
|
||||
goto WriteStructEndError
|
||||
}
|
||||
return nil
|
||||
WriteStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
|
||||
WriteFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err)
|
||||
WriteFieldStopError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err)
|
||||
WriteStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *ConversationServiceDeleteConversationApiResult) writeField0(oprot thrift.TProtocol) (err error) {
|
||||
if p.IsSetSuccess() {
|
||||
if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := p.Success.Write(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *ConversationServiceDeleteConversationApiResult) String() string {
|
||||
if p == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("ConversationServiceDeleteConversationApiResult(%+v)", *p)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by thriftgo (0.4.1). DO NOT EDIT.
|
||||
|
||||
package message
|
||||
|
|
@ -6,6 +22,7 @@ import (
|
|||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
|
||||
"github.com/apache/thrift/lib/go/thrift"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/base"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/conversation/common"
|
||||
|
|
@ -7567,6 +7584,8 @@ type ListMessageApiResponse struct {
|
|||
FirstID *int64 `thrift:"first_id,3,optional" form:"first_id" json:"first_id,string,omitempty"`
|
||||
// The id of the last piece of data.
|
||||
LastID *int64 `thrift:"last_id,4,optional" form:"last_id" json:"last_id,string,omitempty"`
|
||||
Code int64 `thrift:"code,253" form:"code" json:"code" query:"code"`
|
||||
Msg string `thrift:"msg,254" form:"msg" json:"msg" query:"msg"`
|
||||
}
|
||||
|
||||
func NewListMessageApiResponse() *ListMessageApiResponse {
|
||||
|
|
@ -7612,11 +7631,21 @@ func (p *ListMessageApiResponse) GetLastID() (v int64) {
|
|||
return *p.LastID
|
||||
}
|
||||
|
||||
func (p *ListMessageApiResponse) GetCode() (v int64) {
|
||||
return p.Code
|
||||
}
|
||||
|
||||
func (p *ListMessageApiResponse) GetMsg() (v string) {
|
||||
return p.Msg
|
||||
}
|
||||
|
||||
var fieldIDToName_ListMessageApiResponse = map[int16]string{
|
||||
1: "messages",
|
||||
2: "has_more",
|
||||
3: "first_id",
|
||||
4: "last_id",
|
||||
1: "messages",
|
||||
2: "has_more",
|
||||
3: "first_id",
|
||||
4: "last_id",
|
||||
253: "code",
|
||||
254: "msg",
|
||||
}
|
||||
|
||||
func (p *ListMessageApiResponse) IsSetMessages() bool {
|
||||
|
|
@ -7685,6 +7714,22 @@ func (p *ListMessageApiResponse) Read(iprot thrift.TProtocol) (err error) {
|
|||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 253:
|
||||
if fieldTypeId == thrift.I64 {
|
||||
if err = p.ReadField253(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 254:
|
||||
if fieldTypeId == thrift.STRING {
|
||||
if err = p.ReadField254(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
default:
|
||||
if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
|
|
@ -7770,6 +7815,28 @@ func (p *ListMessageApiResponse) ReadField4(iprot thrift.TProtocol) error {
|
|||
p.LastID = _field
|
||||
return nil
|
||||
}
|
||||
func (p *ListMessageApiResponse) ReadField253(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field int64
|
||||
if v, err := iprot.ReadI64(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = v
|
||||
}
|
||||
p.Code = _field
|
||||
return nil
|
||||
}
|
||||
func (p *ListMessageApiResponse) ReadField254(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field string
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = v
|
||||
}
|
||||
p.Msg = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *ListMessageApiResponse) Write(oprot thrift.TProtocol) (err error) {
|
||||
var fieldId int16
|
||||
|
|
@ -7793,6 +7860,14 @@ func (p *ListMessageApiResponse) Write(oprot thrift.TProtocol) (err error) {
|
|||
fieldId = 4
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField253(oprot); err != nil {
|
||||
fieldId = 253
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField254(oprot); err != nil {
|
||||
fieldId = 254
|
||||
goto WriteFieldError
|
||||
}
|
||||
}
|
||||
if err = oprot.WriteFieldStop(); err != nil {
|
||||
goto WriteFieldStopError
|
||||
|
|
@ -7891,6 +7966,38 @@ WriteFieldBeginError:
|
|||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 4 end error: ", p), err)
|
||||
}
|
||||
func (p *ListMessageApiResponse) writeField253(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("code", thrift.I64, 253); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteI64(p.Code); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 253 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 253 end error: ", p), err)
|
||||
}
|
||||
func (p *ListMessageApiResponse) writeField254(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("msg", thrift.STRING, 254); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteString(p.Msg); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 254 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 254 end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *ListMessageApiResponse) String() string {
|
||||
if p == nil {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by thriftgo (0.4.1). DO NOT EDIT.
|
||||
|
||||
package run
|
||||
|
|
@ -6,7 +22,9 @@ import (
|
|||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
|
||||
"github.com/apache/thrift/lib/go/thrift"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/base"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/conversation/common"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/conversation/message"
|
||||
)
|
||||
|
|
@ -1875,6 +1893,7 @@ type AdditionalContent struct {
|
|||
Type string `thrift:"type,1,required" form:"type,required" json:"type,required" query:"type,required"`
|
||||
Text *string `thrift:"text,2,optional" form:"text" json:"text,omitempty" query:"text"`
|
||||
FileURL *string `thrift:"file_url,3,optional" form:"file_url" json:"file_url,omitempty" query:"file_url"`
|
||||
FileID *int64 `thrift:"file_id,4,optional" form:"file_id" json:"file_id,string,omitempty" query:"file_id"`
|
||||
}
|
||||
|
||||
func NewAdditionalContent() *AdditionalContent {
|
||||
|
|
@ -1906,10 +1925,20 @@ func (p *AdditionalContent) GetFileURL() (v string) {
|
|||
return *p.FileURL
|
||||
}
|
||||
|
||||
var AdditionalContent_FileID_DEFAULT int64
|
||||
|
||||
func (p *AdditionalContent) GetFileID() (v int64) {
|
||||
if !p.IsSetFileID() {
|
||||
return AdditionalContent_FileID_DEFAULT
|
||||
}
|
||||
return *p.FileID
|
||||
}
|
||||
|
||||
var fieldIDToName_AdditionalContent = map[int16]string{
|
||||
1: "type",
|
||||
2: "text",
|
||||
3: "file_url",
|
||||
4: "file_id",
|
||||
}
|
||||
|
||||
func (p *AdditionalContent) IsSetText() bool {
|
||||
|
|
@ -1920,6 +1949,10 @@ func (p *AdditionalContent) IsSetFileURL() bool {
|
|||
return p.FileURL != nil
|
||||
}
|
||||
|
||||
func (p *AdditionalContent) IsSetFileID() bool {
|
||||
return p.FileID != nil
|
||||
}
|
||||
|
||||
func (p *AdditionalContent) Read(iprot thrift.TProtocol) (err error) {
|
||||
var fieldTypeId thrift.TType
|
||||
var fieldId int16
|
||||
|
|
@ -1964,6 +1997,14 @@ func (p *AdditionalContent) Read(iprot thrift.TProtocol) (err error) {
|
|||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 4:
|
||||
if fieldTypeId == thrift.I64 {
|
||||
if err = p.ReadField4(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
default:
|
||||
if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
|
|
@ -2032,6 +2073,17 @@ func (p *AdditionalContent) ReadField3(iprot thrift.TProtocol) error {
|
|||
p.FileURL = _field
|
||||
return nil
|
||||
}
|
||||
func (p *AdditionalContent) ReadField4(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field *int64
|
||||
if v, err := iprot.ReadI64(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = &v
|
||||
}
|
||||
p.FileID = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *AdditionalContent) Write(oprot thrift.TProtocol) (err error) {
|
||||
var fieldId int16
|
||||
|
|
@ -2051,6 +2103,10 @@ func (p *AdditionalContent) Write(oprot thrift.TProtocol) (err error) {
|
|||
fieldId = 3
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField4(oprot); err != nil {
|
||||
fieldId = 4
|
||||
goto WriteFieldError
|
||||
}
|
||||
}
|
||||
if err = oprot.WriteFieldStop(); err != nil {
|
||||
goto WriteFieldStopError
|
||||
|
|
@ -2121,6 +2177,24 @@ WriteFieldBeginError:
|
|||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 3 end error: ", p), err)
|
||||
}
|
||||
func (p *AdditionalContent) writeField4(oprot thrift.TProtocol) (err error) {
|
||||
if p.IsSetFileID() {
|
||||
if err = oprot.WriteFieldBegin("file_id", thrift.I64, 4); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteI64(*p.FileID); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 4 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 4 end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *AdditionalContent) String() string {
|
||||
if p == nil {
|
||||
|
|
@ -9459,3 +9533,449 @@ func (p *ChatV3Response) String() string {
|
|||
return fmt.Sprintf("ChatV3Response(%+v)", *p)
|
||||
|
||||
}
|
||||
|
||||
type CancelChatApiRequest struct {
|
||||
ChatID int64 `thrift:"ChatID,1,required" form:"chat_id,required" json:"chat_id,string,required"`
|
||||
ConversationID int64 `thrift:"ConversationID,2,required" form:"conversation_id,required" json:"conversation_id,string,required"`
|
||||
Base *base.Base `thrift:"Base,255" form:"Base" json:"Base" query:"Base"`
|
||||
}
|
||||
|
||||
func NewCancelChatApiRequest() *CancelChatApiRequest {
|
||||
return &CancelChatApiRequest{}
|
||||
}
|
||||
|
||||
func (p *CancelChatApiRequest) InitDefault() {
|
||||
}
|
||||
|
||||
func (p *CancelChatApiRequest) GetChatID() (v int64) {
|
||||
return p.ChatID
|
||||
}
|
||||
|
||||
func (p *CancelChatApiRequest) GetConversationID() (v int64) {
|
||||
return p.ConversationID
|
||||
}
|
||||
|
||||
var CancelChatApiRequest_Base_DEFAULT *base.Base
|
||||
|
||||
func (p *CancelChatApiRequest) GetBase() (v *base.Base) {
|
||||
if !p.IsSetBase() {
|
||||
return CancelChatApiRequest_Base_DEFAULT
|
||||
}
|
||||
return p.Base
|
||||
}
|
||||
|
||||
var fieldIDToName_CancelChatApiRequest = map[int16]string{
|
||||
1: "ChatID",
|
||||
2: "ConversationID",
|
||||
255: "Base",
|
||||
}
|
||||
|
||||
func (p *CancelChatApiRequest) IsSetBase() bool {
|
||||
return p.Base != nil
|
||||
}
|
||||
|
||||
func (p *CancelChatApiRequest) Read(iprot thrift.TProtocol) (err error) {
|
||||
var fieldTypeId thrift.TType
|
||||
var fieldId int16
|
||||
var issetChatID bool = false
|
||||
var issetConversationID bool = false
|
||||
|
||||
if _, err = iprot.ReadStructBegin(); err != nil {
|
||||
goto ReadStructBeginError
|
||||
}
|
||||
|
||||
for {
|
||||
_, fieldTypeId, fieldId, err = iprot.ReadFieldBegin()
|
||||
if err != nil {
|
||||
goto ReadFieldBeginError
|
||||
}
|
||||
if fieldTypeId == thrift.STOP {
|
||||
break
|
||||
}
|
||||
|
||||
switch fieldId {
|
||||
case 1:
|
||||
if fieldTypeId == thrift.I64 {
|
||||
if err = p.ReadField1(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
issetChatID = true
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 2:
|
||||
if fieldTypeId == thrift.I64 {
|
||||
if err = p.ReadField2(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
issetConversationID = true
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 255:
|
||||
if fieldTypeId == thrift.STRUCT {
|
||||
if err = p.ReadField255(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
default:
|
||||
if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadFieldEnd(); err != nil {
|
||||
goto ReadFieldEndError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadStructEnd(); err != nil {
|
||||
goto ReadStructEndError
|
||||
}
|
||||
|
||||
if !issetChatID {
|
||||
fieldId = 1
|
||||
goto RequiredFieldNotSetError
|
||||
}
|
||||
|
||||
if !issetConversationID {
|
||||
fieldId = 2
|
||||
goto RequiredFieldNotSetError
|
||||
}
|
||||
return nil
|
||||
ReadStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err)
|
||||
ReadFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err)
|
||||
ReadFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_CancelChatApiRequest[fieldId]), err)
|
||||
SkipFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err)
|
||||
|
||||
ReadFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err)
|
||||
ReadStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
|
||||
RequiredFieldNotSetError:
|
||||
return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_CancelChatApiRequest[fieldId]))
|
||||
}
|
||||
|
||||
func (p *CancelChatApiRequest) ReadField1(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field int64
|
||||
if v, err := iprot.ReadI64(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = v
|
||||
}
|
||||
p.ChatID = _field
|
||||
return nil
|
||||
}
|
||||
func (p *CancelChatApiRequest) ReadField2(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field int64
|
||||
if v, err := iprot.ReadI64(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = v
|
||||
}
|
||||
p.ConversationID = _field
|
||||
return nil
|
||||
}
|
||||
func (p *CancelChatApiRequest) ReadField255(iprot thrift.TProtocol) error {
|
||||
_field := base.NewBase()
|
||||
if err := _field.Read(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
p.Base = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *CancelChatApiRequest) Write(oprot thrift.TProtocol) (err error) {
|
||||
var fieldId int16
|
||||
if err = oprot.WriteStructBegin("CancelChatApiRequest"); err != nil {
|
||||
goto WriteStructBeginError
|
||||
}
|
||||
if p != nil {
|
||||
if err = p.writeField1(oprot); err != nil {
|
||||
fieldId = 1
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField2(oprot); err != nil {
|
||||
fieldId = 2
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField255(oprot); err != nil {
|
||||
fieldId = 255
|
||||
goto WriteFieldError
|
||||
}
|
||||
}
|
||||
if err = oprot.WriteFieldStop(); err != nil {
|
||||
goto WriteFieldStopError
|
||||
}
|
||||
if err = oprot.WriteStructEnd(); err != nil {
|
||||
goto WriteStructEndError
|
||||
}
|
||||
return nil
|
||||
WriteStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
|
||||
WriteFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err)
|
||||
WriteFieldStopError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err)
|
||||
WriteStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *CancelChatApiRequest) writeField1(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("ChatID", thrift.I64, 1); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteI64(p.ChatID); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err)
|
||||
}
|
||||
func (p *CancelChatApiRequest) writeField2(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("ConversationID", thrift.I64, 2); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteI64(p.ConversationID); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err)
|
||||
}
|
||||
func (p *CancelChatApiRequest) writeField255(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("Base", thrift.STRUCT, 255); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := p.Base.Write(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 255 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 255 end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *CancelChatApiRequest) String() string {
|
||||
if p == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("CancelChatApiRequest(%+v)", *p)
|
||||
|
||||
}
|
||||
|
||||
type CancelChatApiResponse struct {
|
||||
ChatV3ChatDetail *ChatV3ChatDetail `thrift:"ChatV3ChatDetail,1" form:"ChatV3ChatDetail" json:"ChatV3ChatDetail" query:"ChatV3ChatDetail"`
|
||||
BaseResp *base.BaseResp `thrift:"BaseResp,255" form:"BaseResp" json:"BaseResp" query:"BaseResp"`
|
||||
}
|
||||
|
||||
func NewCancelChatApiResponse() *CancelChatApiResponse {
|
||||
return &CancelChatApiResponse{}
|
||||
}
|
||||
|
||||
func (p *CancelChatApiResponse) InitDefault() {
|
||||
}
|
||||
|
||||
var CancelChatApiResponse_ChatV3ChatDetail_DEFAULT *ChatV3ChatDetail
|
||||
|
||||
func (p *CancelChatApiResponse) GetChatV3ChatDetail() (v *ChatV3ChatDetail) {
|
||||
if !p.IsSetChatV3ChatDetail() {
|
||||
return CancelChatApiResponse_ChatV3ChatDetail_DEFAULT
|
||||
}
|
||||
return p.ChatV3ChatDetail
|
||||
}
|
||||
|
||||
var CancelChatApiResponse_BaseResp_DEFAULT *base.BaseResp
|
||||
|
||||
func (p *CancelChatApiResponse) GetBaseResp() (v *base.BaseResp) {
|
||||
if !p.IsSetBaseResp() {
|
||||
return CancelChatApiResponse_BaseResp_DEFAULT
|
||||
}
|
||||
return p.BaseResp
|
||||
}
|
||||
|
||||
var fieldIDToName_CancelChatApiResponse = map[int16]string{
|
||||
1: "ChatV3ChatDetail",
|
||||
255: "BaseResp",
|
||||
}
|
||||
|
||||
func (p *CancelChatApiResponse) IsSetChatV3ChatDetail() bool {
|
||||
return p.ChatV3ChatDetail != nil
|
||||
}
|
||||
|
||||
func (p *CancelChatApiResponse) IsSetBaseResp() bool {
|
||||
return p.BaseResp != nil
|
||||
}
|
||||
|
||||
func (p *CancelChatApiResponse) Read(iprot thrift.TProtocol) (err error) {
|
||||
var fieldTypeId thrift.TType
|
||||
var fieldId int16
|
||||
|
||||
if _, err = iprot.ReadStructBegin(); err != nil {
|
||||
goto ReadStructBeginError
|
||||
}
|
||||
|
||||
for {
|
||||
_, fieldTypeId, fieldId, err = iprot.ReadFieldBegin()
|
||||
if err != nil {
|
||||
goto ReadFieldBeginError
|
||||
}
|
||||
if fieldTypeId == thrift.STOP {
|
||||
break
|
||||
}
|
||||
|
||||
switch fieldId {
|
||||
case 1:
|
||||
if fieldTypeId == thrift.STRUCT {
|
||||
if err = p.ReadField1(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 255:
|
||||
if fieldTypeId == thrift.STRUCT {
|
||||
if err = p.ReadField255(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
default:
|
||||
if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadFieldEnd(); err != nil {
|
||||
goto ReadFieldEndError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadStructEnd(); err != nil {
|
||||
goto ReadStructEndError
|
||||
}
|
||||
|
||||
return nil
|
||||
ReadStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err)
|
||||
ReadFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err)
|
||||
ReadFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_CancelChatApiResponse[fieldId]), err)
|
||||
SkipFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err)
|
||||
|
||||
ReadFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err)
|
||||
ReadStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *CancelChatApiResponse) ReadField1(iprot thrift.TProtocol) error {
|
||||
_field := NewChatV3ChatDetail()
|
||||
if err := _field.Read(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
p.ChatV3ChatDetail = _field
|
||||
return nil
|
||||
}
|
||||
func (p *CancelChatApiResponse) ReadField255(iprot thrift.TProtocol) error {
|
||||
_field := base.NewBaseResp()
|
||||
if err := _field.Read(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
p.BaseResp = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *CancelChatApiResponse) Write(oprot thrift.TProtocol) (err error) {
|
||||
var fieldId int16
|
||||
if err = oprot.WriteStructBegin("CancelChatApiResponse"); err != nil {
|
||||
goto WriteStructBeginError
|
||||
}
|
||||
if p != nil {
|
||||
if err = p.writeField1(oprot); err != nil {
|
||||
fieldId = 1
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField255(oprot); err != nil {
|
||||
fieldId = 255
|
||||
goto WriteFieldError
|
||||
}
|
||||
}
|
||||
if err = oprot.WriteFieldStop(); err != nil {
|
||||
goto WriteFieldStopError
|
||||
}
|
||||
if err = oprot.WriteStructEnd(); err != nil {
|
||||
goto WriteStructEndError
|
||||
}
|
||||
return nil
|
||||
WriteStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
|
||||
WriteFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err)
|
||||
WriteFieldStopError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err)
|
||||
WriteStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *CancelChatApiResponse) writeField1(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("ChatV3ChatDetail", thrift.STRUCT, 1); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := p.ChatV3ChatDetail.Write(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err)
|
||||
}
|
||||
func (p *CancelChatApiResponse) writeField255(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("BaseResp", thrift.STRUCT, 255); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := p.BaseResp.Write(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 255 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 255 end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *CancelChatApiResponse) String() string {
|
||||
if p == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("CancelChatApiResponse(%+v)", *p)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,3 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by thriftgo (0.4.1). DO NOT EDIT.
|
||||
|
||||
package coze
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ const (
|
|||
|
||||
type Conversation struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
SectionID int64 `json:"section_id"`
|
||||
AgentID int64 `json:"agent_id"`
|
||||
ConnectorID int64 `json:"connector_id"`
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ type LLMParams struct {
|
|||
EnableChatHistory bool `json:"enableChatHistory"`
|
||||
SystemPrompt string `json:"systemPrompt"`
|
||||
ResponseFormat ResponseFormat `json:"responseFormat"`
|
||||
ChatHistoryRound int64 `json:"chatHistoryRound"`
|
||||
}
|
||||
|
||||
type ResponseFormat int64
|
||||
|
|
|
|||
|
|
@ -26,14 +26,6 @@ import (
|
|||
crossworkflow "github.com/coze-dev/coze-studio/backend/crossdomain/contract/workflow"
|
||||
)
|
||||
|
||||
type AgentRuntime struct {
|
||||
AgentVersion string
|
||||
IsDraft bool
|
||||
SpaceID int64
|
||||
ConnectorID int64
|
||||
PreRetrieveTools []*agentrun.Tool
|
||||
}
|
||||
|
||||
type EventType string
|
||||
|
||||
const (
|
||||
|
|
@ -84,6 +76,8 @@ type SingleAgent struct {
|
|||
JumpConfig *bot_common.JumpConfig
|
||||
BackgroundImageInfoList []*bot_common.BackgroundImageInfo
|
||||
Database []*bot_common.Database
|
||||
BotMode bot_common.BotMode
|
||||
LayoutInfo *bot_common.LayoutInfo
|
||||
ShortcutCommand []string
|
||||
}
|
||||
|
||||
|
|
@ -106,6 +100,8 @@ type InterruptInfo struct {
|
|||
ToolCallID string
|
||||
InterruptType InterruptEventType
|
||||
InterruptID string
|
||||
|
||||
ChatflowInterrupt *crossworkflow.StateMessage
|
||||
}
|
||||
|
||||
type ExecuteRequest struct {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,13 @@
|
|||
|
||||
package workflow
|
||||
|
||||
import (
|
||||
"github.com/cloudwego/eino/schema"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/workflow"
|
||||
crossmessage "github.com/coze-dev/coze-studio/backend/crossdomain/contract/message"
|
||||
)
|
||||
|
||||
type Locator uint8
|
||||
|
||||
const (
|
||||
|
|
@ -25,21 +32,30 @@ const (
|
|||
)
|
||||
|
||||
type ExecuteConfig struct {
|
||||
ID int64
|
||||
From Locator
|
||||
Version string
|
||||
CommitID string
|
||||
Operator int64
|
||||
Mode ExecuteMode
|
||||
AppID *int64
|
||||
AgentID *int64
|
||||
ConnectorID int64
|
||||
ConnectorUID string
|
||||
TaskType TaskType
|
||||
SyncPattern SyncPattern
|
||||
InputFailFast bool // whether to fail fast if input conversion has warnings
|
||||
BizType BizType
|
||||
Cancellable bool
|
||||
ID int64
|
||||
From Locator
|
||||
Version string
|
||||
CommitID string
|
||||
Operator int64
|
||||
Mode ExecuteMode
|
||||
AppID *int64
|
||||
AgentID *int64
|
||||
ConnectorID int64
|
||||
ConnectorUID string
|
||||
TaskType TaskType
|
||||
SyncPattern SyncPattern
|
||||
InputFailFast bool // whether to fail fast if input conversion has warnings
|
||||
BizType BizType
|
||||
Cancellable bool
|
||||
WorkflowMode WorkflowMode
|
||||
RoundID *int64 // if workflow is chat flow, conversation round id is required
|
||||
InitRoundID *int64 // if workflow is chat flow, init conversation round id is required
|
||||
ConversationID *int64 // if workflow is chat flow, conversation id is required
|
||||
UserMessage *schema.Message
|
||||
ConversationHistory []*crossmessage.WfMessage
|
||||
ConversationHistorySchemaMessages []*schema.Message
|
||||
SectionID *int64
|
||||
MaxHistoryRounds *int32
|
||||
}
|
||||
|
||||
type ExecuteMode string
|
||||
|
|
@ -50,6 +66,8 @@ const (
|
|||
ExecuteModeNodeDebug ExecuteMode = "node_debug"
|
||||
)
|
||||
|
||||
type WorkflowMode = workflow.WorkflowMode
|
||||
|
||||
type TaskType string
|
||||
|
||||
const (
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by thriftgo (0.4.1). DO NOT EDIT.
|
||||
|
||||
package playground
|
||||
|
|
@ -7,6 +23,7 @@ import (
|
|||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
|
||||
"github.com/apache/thrift/lib/go/thrift"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/app/bot_common"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/base"
|
||||
|
|
@ -15881,329 +15898,6 @@ func (p *GetFileUrlsResponse) String() string {
|
|||
|
||||
}
|
||||
|
||||
type File struct {
|
||||
// File URI
|
||||
URI string `thrift:"URI,1" form:"uri" json:"uri"`
|
||||
// file bytes
|
||||
Bytes int64 `thrift:"Bytes,2" form:"bytes" json:"bytes"`
|
||||
// Upload timestamp in s
|
||||
CreatedAt int64 `thrift:"CreatedAt,3" form:"CreatedAt" json:"CreatedAt" query:"CreatedAt"`
|
||||
// file name
|
||||
FileName string `thrift:"FileName,4" form:"file_name" json:"file_name"`
|
||||
URL string `thrift:"URL,5" form:"url" json:"url"`
|
||||
}
|
||||
|
||||
func NewFile() *File {
|
||||
return &File{}
|
||||
}
|
||||
|
||||
func (p *File) InitDefault() {
|
||||
}
|
||||
|
||||
func (p *File) GetURI() (v string) {
|
||||
return p.URI
|
||||
}
|
||||
|
||||
func (p *File) GetBytes() (v int64) {
|
||||
return p.Bytes
|
||||
}
|
||||
|
||||
func (p *File) GetCreatedAt() (v int64) {
|
||||
return p.CreatedAt
|
||||
}
|
||||
|
||||
func (p *File) GetFileName() (v string) {
|
||||
return p.FileName
|
||||
}
|
||||
|
||||
func (p *File) GetURL() (v string) {
|
||||
return p.URL
|
||||
}
|
||||
|
||||
var fieldIDToName_File = map[int16]string{
|
||||
1: "URI",
|
||||
2: "Bytes",
|
||||
3: "CreatedAt",
|
||||
4: "FileName",
|
||||
5: "URL",
|
||||
}
|
||||
|
||||
func (p *File) Read(iprot thrift.TProtocol) (err error) {
|
||||
var fieldTypeId thrift.TType
|
||||
var fieldId int16
|
||||
|
||||
if _, err = iprot.ReadStructBegin(); err != nil {
|
||||
goto ReadStructBeginError
|
||||
}
|
||||
|
||||
for {
|
||||
_, fieldTypeId, fieldId, err = iprot.ReadFieldBegin()
|
||||
if err != nil {
|
||||
goto ReadFieldBeginError
|
||||
}
|
||||
if fieldTypeId == thrift.STOP {
|
||||
break
|
||||
}
|
||||
|
||||
switch fieldId {
|
||||
case 1:
|
||||
if fieldTypeId == thrift.STRING {
|
||||
if err = p.ReadField1(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 2:
|
||||
if fieldTypeId == thrift.I64 {
|
||||
if err = p.ReadField2(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 3:
|
||||
if fieldTypeId == thrift.I64 {
|
||||
if err = p.ReadField3(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 4:
|
||||
if fieldTypeId == thrift.STRING {
|
||||
if err = p.ReadField4(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 5:
|
||||
if fieldTypeId == thrift.STRING {
|
||||
if err = p.ReadField5(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
default:
|
||||
if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadFieldEnd(); err != nil {
|
||||
goto ReadFieldEndError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadStructEnd(); err != nil {
|
||||
goto ReadStructEndError
|
||||
}
|
||||
|
||||
return nil
|
||||
ReadStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err)
|
||||
ReadFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err)
|
||||
ReadFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_File[fieldId]), err)
|
||||
SkipFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err)
|
||||
|
||||
ReadFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err)
|
||||
ReadStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *File) ReadField1(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field string
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = v
|
||||
}
|
||||
p.URI = _field
|
||||
return nil
|
||||
}
|
||||
func (p *File) ReadField2(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field int64
|
||||
if v, err := iprot.ReadI64(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = v
|
||||
}
|
||||
p.Bytes = _field
|
||||
return nil
|
||||
}
|
||||
func (p *File) ReadField3(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field int64
|
||||
if v, err := iprot.ReadI64(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = v
|
||||
}
|
||||
p.CreatedAt = _field
|
||||
return nil
|
||||
}
|
||||
func (p *File) ReadField4(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field string
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = v
|
||||
}
|
||||
p.FileName = _field
|
||||
return nil
|
||||
}
|
||||
func (p *File) ReadField5(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field string
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = v
|
||||
}
|
||||
p.URL = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *File) Write(oprot thrift.TProtocol) (err error) {
|
||||
var fieldId int16
|
||||
if err = oprot.WriteStructBegin("File"); err != nil {
|
||||
goto WriteStructBeginError
|
||||
}
|
||||
if p != nil {
|
||||
if err = p.writeField1(oprot); err != nil {
|
||||
fieldId = 1
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField2(oprot); err != nil {
|
||||
fieldId = 2
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField3(oprot); err != nil {
|
||||
fieldId = 3
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField4(oprot); err != nil {
|
||||
fieldId = 4
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField5(oprot); err != nil {
|
||||
fieldId = 5
|
||||
goto WriteFieldError
|
||||
}
|
||||
}
|
||||
if err = oprot.WriteFieldStop(); err != nil {
|
||||
goto WriteFieldStopError
|
||||
}
|
||||
if err = oprot.WriteStructEnd(); err != nil {
|
||||
goto WriteStructEndError
|
||||
}
|
||||
return nil
|
||||
WriteStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
|
||||
WriteFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err)
|
||||
WriteFieldStopError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err)
|
||||
WriteStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *File) writeField1(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("URI", thrift.STRING, 1); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteString(p.URI); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err)
|
||||
}
|
||||
func (p *File) writeField2(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("Bytes", thrift.I64, 2); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteI64(p.Bytes); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err)
|
||||
}
|
||||
func (p *File) writeField3(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("CreatedAt", thrift.I64, 3); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteI64(p.CreatedAt); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 3 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 3 end error: ", p), err)
|
||||
}
|
||||
func (p *File) writeField4(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("FileName", thrift.STRING, 4); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteString(p.FileName); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 4 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 4 end error: ", p), err)
|
||||
}
|
||||
func (p *File) writeField5(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("URL", thrift.STRING, 5); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteString(p.URL); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 5 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 5 end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *File) String() string {
|
||||
if p == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("File(%+v)", *p)
|
||||
|
||||
}
|
||||
|
||||
type PlaygroundService interface {
|
||||
UpdateDraftBotInfoAgw(ctx context.Context, request *UpdateDraftBotInfoAgwRequest) (r *UpdateDraftBotInfoAgwResponse, err error)
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by thriftgo (0.4.1). DO NOT EDIT.
|
||||
|
||||
package workflow
|
||||
|
|
@ -5,6 +21,7 @@ package workflow
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/apache/thrift/lib/go/thrift"
|
||||
)
|
||||
|
||||
|
|
@ -106,6 +123,8 @@ type WorkflowService interface {
|
|||
OpenAPIChatFlowRun(ctx context.Context, request *ChatFlowRunRequest) (r *ChatFlowRunResponse, err error)
|
||||
|
||||
OpenAPIGetWorkflowInfo(ctx context.Context, request *OpenAPIGetWorkflowInfoRequest) (r *OpenAPIGetWorkflowInfoResponse, err error)
|
||||
|
||||
OpenAPICreateConversation(ctx context.Context, request *CreateConversationRequest) (r *CreateConversationResponse, err error)
|
||||
}
|
||||
|
||||
type WorkflowServiceClient struct {
|
||||
|
|
@ -566,6 +585,15 @@ func (p *WorkflowServiceClient) OpenAPIGetWorkflowInfo(ctx context.Context, requ
|
|||
}
|
||||
return _result.GetSuccess(), nil
|
||||
}
|
||||
func (p *WorkflowServiceClient) OpenAPICreateConversation(ctx context.Context, request *CreateConversationRequest) (r *CreateConversationResponse, err error) {
|
||||
var _args WorkflowServiceOpenAPICreateConversationArgs
|
||||
_args.Request = request
|
||||
var _result WorkflowServiceOpenAPICreateConversationResult
|
||||
if err = p.Client_().Call(ctx, "OpenAPICreateConversation", &_args, &_result); err != nil {
|
||||
return
|
||||
}
|
||||
return _result.GetSuccess(), nil
|
||||
}
|
||||
|
||||
type WorkflowServiceProcessor struct {
|
||||
processorMap map[string]thrift.TProcessorFunction
|
||||
|
|
@ -635,6 +663,7 @@ func NewWorkflowServiceProcessor(handler WorkflowService) *WorkflowServiceProces
|
|||
self.AddToProcessorMap("OpenAPIGetWorkflowRunHistory", &workflowServiceProcessorOpenAPIGetWorkflowRunHistory{handler: handler})
|
||||
self.AddToProcessorMap("OpenAPIChatFlowRun", &workflowServiceProcessorOpenAPIChatFlowRun{handler: handler})
|
||||
self.AddToProcessorMap("OpenAPIGetWorkflowInfo", &workflowServiceProcessorOpenAPIGetWorkflowInfo{handler: handler})
|
||||
self.AddToProcessorMap("OpenAPICreateConversation", &workflowServiceProcessorOpenAPICreateConversation{handler: handler})
|
||||
return self
|
||||
}
|
||||
func (p *WorkflowServiceProcessor) Process(ctx context.Context, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
|
||||
|
|
@ -2959,6 +2988,54 @@ func (p *workflowServiceProcessorOpenAPIGetWorkflowInfo) Process(ctx context.Con
|
|||
return true, err
|
||||
}
|
||||
|
||||
type workflowServiceProcessorOpenAPICreateConversation struct {
|
||||
handler WorkflowService
|
||||
}
|
||||
|
||||
func (p *workflowServiceProcessorOpenAPICreateConversation) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
|
||||
args := WorkflowServiceOpenAPICreateConversationArgs{}
|
||||
if err = args.Read(iprot); err != nil {
|
||||
iprot.ReadMessageEnd()
|
||||
x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error())
|
||||
oprot.WriteMessageBegin("OpenAPICreateConversation", thrift.EXCEPTION, seqId)
|
||||
x.Write(oprot)
|
||||
oprot.WriteMessageEnd()
|
||||
oprot.Flush(ctx)
|
||||
return false, err
|
||||
}
|
||||
|
||||
iprot.ReadMessageEnd()
|
||||
var err2 error
|
||||
result := WorkflowServiceOpenAPICreateConversationResult{}
|
||||
var retval *CreateConversationResponse
|
||||
if retval, err2 = p.handler.OpenAPICreateConversation(ctx, args.Request); err2 != nil {
|
||||
x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing OpenAPICreateConversation: "+err2.Error())
|
||||
oprot.WriteMessageBegin("OpenAPICreateConversation", thrift.EXCEPTION, seqId)
|
||||
x.Write(oprot)
|
||||
oprot.WriteMessageEnd()
|
||||
oprot.Flush(ctx)
|
||||
return true, err2
|
||||
} else {
|
||||
result.Success = retval
|
||||
}
|
||||
if err2 = oprot.WriteMessageBegin("OpenAPICreateConversation", thrift.REPLY, seqId); err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
if err2 = result.Write(oprot); err == nil && err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
if err2 = oprot.Flush(ctx); err == nil && err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return true, err
|
||||
}
|
||||
|
||||
type WorkflowServiceCreateWorkflowArgs struct {
|
||||
Request *CreateWorkflowRequest `thrift:"request,1"`
|
||||
}
|
||||
|
|
@ -16974,3 +17051,295 @@ func (p *WorkflowServiceOpenAPIGetWorkflowInfoResult) String() string {
|
|||
return fmt.Sprintf("WorkflowServiceOpenAPIGetWorkflowInfoResult(%+v)", *p)
|
||||
|
||||
}
|
||||
|
||||
type WorkflowServiceOpenAPICreateConversationArgs struct {
|
||||
Request *CreateConversationRequest `thrift:"request,1"`
|
||||
}
|
||||
|
||||
func NewWorkflowServiceOpenAPICreateConversationArgs() *WorkflowServiceOpenAPICreateConversationArgs {
|
||||
return &WorkflowServiceOpenAPICreateConversationArgs{}
|
||||
}
|
||||
|
||||
func (p *WorkflowServiceOpenAPICreateConversationArgs) InitDefault() {
|
||||
}
|
||||
|
||||
var WorkflowServiceOpenAPICreateConversationArgs_Request_DEFAULT *CreateConversationRequest
|
||||
|
||||
func (p *WorkflowServiceOpenAPICreateConversationArgs) GetRequest() (v *CreateConversationRequest) {
|
||||
if !p.IsSetRequest() {
|
||||
return WorkflowServiceOpenAPICreateConversationArgs_Request_DEFAULT
|
||||
}
|
||||
return p.Request
|
||||
}
|
||||
|
||||
var fieldIDToName_WorkflowServiceOpenAPICreateConversationArgs = map[int16]string{
|
||||
1: "request",
|
||||
}
|
||||
|
||||
func (p *WorkflowServiceOpenAPICreateConversationArgs) IsSetRequest() bool {
|
||||
return p.Request != nil
|
||||
}
|
||||
|
||||
func (p *WorkflowServiceOpenAPICreateConversationArgs) Read(iprot thrift.TProtocol) (err error) {
|
||||
var fieldTypeId thrift.TType
|
||||
var fieldId int16
|
||||
|
||||
if _, err = iprot.ReadStructBegin(); err != nil {
|
||||
goto ReadStructBeginError
|
||||
}
|
||||
|
||||
for {
|
||||
_, fieldTypeId, fieldId, err = iprot.ReadFieldBegin()
|
||||
if err != nil {
|
||||
goto ReadFieldBeginError
|
||||
}
|
||||
if fieldTypeId == thrift.STOP {
|
||||
break
|
||||
}
|
||||
|
||||
switch fieldId {
|
||||
case 1:
|
||||
if fieldTypeId == thrift.STRUCT {
|
||||
if err = p.ReadField1(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
default:
|
||||
if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadFieldEnd(); err != nil {
|
||||
goto ReadFieldEndError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadStructEnd(); err != nil {
|
||||
goto ReadStructEndError
|
||||
}
|
||||
|
||||
return nil
|
||||
ReadStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err)
|
||||
ReadFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err)
|
||||
ReadFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_WorkflowServiceOpenAPICreateConversationArgs[fieldId]), err)
|
||||
SkipFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err)
|
||||
|
||||
ReadFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err)
|
||||
ReadStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *WorkflowServiceOpenAPICreateConversationArgs) ReadField1(iprot thrift.TProtocol) error {
|
||||
_field := NewCreateConversationRequest()
|
||||
if err := _field.Read(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
p.Request = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *WorkflowServiceOpenAPICreateConversationArgs) Write(oprot thrift.TProtocol) (err error) {
|
||||
var fieldId int16
|
||||
if err = oprot.WriteStructBegin("OpenAPICreateConversation_args"); err != nil {
|
||||
goto WriteStructBeginError
|
||||
}
|
||||
if p != nil {
|
||||
if err = p.writeField1(oprot); err != nil {
|
||||
fieldId = 1
|
||||
goto WriteFieldError
|
||||
}
|
||||
}
|
||||
if err = oprot.WriteFieldStop(); err != nil {
|
||||
goto WriteFieldStopError
|
||||
}
|
||||
if err = oprot.WriteStructEnd(); err != nil {
|
||||
goto WriteStructEndError
|
||||
}
|
||||
return nil
|
||||
WriteStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
|
||||
WriteFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err)
|
||||
WriteFieldStopError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err)
|
||||
WriteStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *WorkflowServiceOpenAPICreateConversationArgs) writeField1(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("request", thrift.STRUCT, 1); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := p.Request.Write(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *WorkflowServiceOpenAPICreateConversationArgs) String() string {
|
||||
if p == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("WorkflowServiceOpenAPICreateConversationArgs(%+v)", *p)
|
||||
|
||||
}
|
||||
|
||||
type WorkflowServiceOpenAPICreateConversationResult struct {
|
||||
Success *CreateConversationResponse `thrift:"success,0,optional"`
|
||||
}
|
||||
|
||||
func NewWorkflowServiceOpenAPICreateConversationResult() *WorkflowServiceOpenAPICreateConversationResult {
|
||||
return &WorkflowServiceOpenAPICreateConversationResult{}
|
||||
}
|
||||
|
||||
func (p *WorkflowServiceOpenAPICreateConversationResult) InitDefault() {
|
||||
}
|
||||
|
||||
var WorkflowServiceOpenAPICreateConversationResult_Success_DEFAULT *CreateConversationResponse
|
||||
|
||||
func (p *WorkflowServiceOpenAPICreateConversationResult) GetSuccess() (v *CreateConversationResponse) {
|
||||
if !p.IsSetSuccess() {
|
||||
return WorkflowServiceOpenAPICreateConversationResult_Success_DEFAULT
|
||||
}
|
||||
return p.Success
|
||||
}
|
||||
|
||||
var fieldIDToName_WorkflowServiceOpenAPICreateConversationResult = map[int16]string{
|
||||
0: "success",
|
||||
}
|
||||
|
||||
func (p *WorkflowServiceOpenAPICreateConversationResult) IsSetSuccess() bool {
|
||||
return p.Success != nil
|
||||
}
|
||||
|
||||
func (p *WorkflowServiceOpenAPICreateConversationResult) Read(iprot thrift.TProtocol) (err error) {
|
||||
var fieldTypeId thrift.TType
|
||||
var fieldId int16
|
||||
|
||||
if _, err = iprot.ReadStructBegin(); err != nil {
|
||||
goto ReadStructBeginError
|
||||
}
|
||||
|
||||
for {
|
||||
_, fieldTypeId, fieldId, err = iprot.ReadFieldBegin()
|
||||
if err != nil {
|
||||
goto ReadFieldBeginError
|
||||
}
|
||||
if fieldTypeId == thrift.STOP {
|
||||
break
|
||||
}
|
||||
|
||||
switch fieldId {
|
||||
case 0:
|
||||
if fieldTypeId == thrift.STRUCT {
|
||||
if err = p.ReadField0(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
default:
|
||||
if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadFieldEnd(); err != nil {
|
||||
goto ReadFieldEndError
|
||||
}
|
||||
}
|
||||
if err = iprot.ReadStructEnd(); err != nil {
|
||||
goto ReadStructEndError
|
||||
}
|
||||
|
||||
return nil
|
||||
ReadStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err)
|
||||
ReadFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err)
|
||||
ReadFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_WorkflowServiceOpenAPICreateConversationResult[fieldId]), err)
|
||||
SkipFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err)
|
||||
|
||||
ReadFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err)
|
||||
ReadStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *WorkflowServiceOpenAPICreateConversationResult) ReadField0(iprot thrift.TProtocol) error {
|
||||
_field := NewCreateConversationResponse()
|
||||
if err := _field.Read(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
p.Success = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *WorkflowServiceOpenAPICreateConversationResult) Write(oprot thrift.TProtocol) (err error) {
|
||||
var fieldId int16
|
||||
if err = oprot.WriteStructBegin("OpenAPICreateConversation_result"); err != nil {
|
||||
goto WriteStructBeginError
|
||||
}
|
||||
if p != nil {
|
||||
if err = p.writeField0(oprot); err != nil {
|
||||
fieldId = 0
|
||||
goto WriteFieldError
|
||||
}
|
||||
}
|
||||
if err = oprot.WriteFieldStop(); err != nil {
|
||||
goto WriteFieldStopError
|
||||
}
|
||||
if err = oprot.WriteStructEnd(); err != nil {
|
||||
goto WriteStructEndError
|
||||
}
|
||||
return nil
|
||||
WriteStructBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
|
||||
WriteFieldError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err)
|
||||
WriteFieldStopError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err)
|
||||
WriteStructEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *WorkflowServiceOpenAPICreateConversationResult) writeField0(oprot thrift.TProtocol) (err error) {
|
||||
if p.IsSetSuccess() {
|
||||
if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := p.Success.Write(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *WorkflowServiceOpenAPICreateConversationResult) String() string {
|
||||
if p == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("WorkflowServiceOpenAPICreateConversationResult(%+v)", *p)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by hertz generator. DO NOT EDIT.
|
||||
|
||||
package coze
|
||||
|
|
@ -250,6 +266,10 @@ func Register(r *server.Hertz) {
|
|||
}
|
||||
{
|
||||
_permission_api := _api.Group("/permission_api", _permission_apiMw()...)
|
||||
{
|
||||
_coze_web_app := _permission_api.Group("/coze_web_app", _coze_web_appMw()...)
|
||||
_coze_web_app.POST("/impersonate_coze_user", append(_impersonatecozeuserMw(), coze.ImpersonateCozeUser)...)
|
||||
}
|
||||
{
|
||||
_pat := _permission_api.Group("/pat", _patMw()...)
|
||||
_pat.POST("/create_personal_access_token_and_permission", append(_createpersonalaccesstokenandpermissionMw(), coze.CreatePersonalAccessTokenAndPermission)...)
|
||||
|
|
@ -409,10 +429,21 @@ func Register(r *server.Hertz) {
|
|||
{
|
||||
_v1 := root.Group("/v1", _v1Mw()...)
|
||||
_v1.GET("/conversations", append(_listconversationsapiMw(), coze.ListConversationsApi)...)
|
||||
_conversations := _v1.Group("/conversations", _conversationsMw()...)
|
||||
_conversations.DELETE("/:conversation_id", append(_deleteconversationapiMw(), coze.DeleteConversationApi)...)
|
||||
_conversations.PUT("/:conversation_id", append(_updateconversationapiMw(), coze.UpdateConversationApi)...)
|
||||
{
|
||||
_apps := _v1.Group("/apps", _appsMw()...)
|
||||
_apps.GET("/:app_id", append(_getonlineappdataMw(), coze.GetOnlineAppData)...)
|
||||
}
|
||||
{
|
||||
_bot0 := _v1.Group("/bot", _bot0Mw()...)
|
||||
_bot0.GET("/get_online_info", append(_getbotonlineinfoMw(), coze.GetBotOnlineInfo)...)
|
||||
}
|
||||
{
|
||||
_bots := _v1.Group("/bots", _botsMw()...)
|
||||
_bots.GET("/:bot_id", append(_opengetbotinfoMw(), coze.OpenGetBotInfo)...)
|
||||
}
|
||||
{
|
||||
_conversation0 := _v1.Group("/conversation", _conversation0Mw()...)
|
||||
_conversation0.POST("/create", append(_createconversationMw(), coze.CreateConversation)...)
|
||||
|
|
@ -422,9 +453,9 @@ func Register(r *server.Hertz) {
|
|||
}
|
||||
}
|
||||
{
|
||||
_conversations := _v1.Group("/conversations", _conversationsMw()...)
|
||||
_conversations0 := _v1.Group("/conversations", _conversations0Mw()...)
|
||||
{
|
||||
_conversation_id := _conversations.Group("/:conversation_id", _conversation_idMw()...)
|
||||
_conversation_id := _conversations0.Group("/:conversation_id", _conversation_idMw()...)
|
||||
_conversation_id.POST("/clear", append(_clearconversationapiMw(), coze.ClearConversationApi)...)
|
||||
}
|
||||
}
|
||||
|
|
@ -438,6 +469,10 @@ func Register(r *server.Hertz) {
|
|||
_workflow.POST("/run", append(_openapirunflowMw(), coze.OpenAPIRunFlow)...)
|
||||
_workflow.POST("/stream_resume", append(_openapistreamresumeflowMw(), coze.OpenAPIStreamResumeFlow)...)
|
||||
_workflow.POST("/stream_run", append(_openapistreamrunflowMw(), coze.OpenAPIStreamRunFlow)...)
|
||||
{
|
||||
_conversation1 := _workflow.Group("/conversation", _conversation1Mw()...)
|
||||
_conversation1.POST("/create", append(_openapicreateconversationMw(), coze.OpenAPICreateConversation)...)
|
||||
}
|
||||
}
|
||||
{
|
||||
_workflows := _v1.Group("/workflows", _workflowsMw()...)
|
||||
|
|
@ -448,5 +483,7 @@ func Register(r *server.Hertz) {
|
|||
{
|
||||
_v3 := root.Group("/v3", _v3Mw()...)
|
||||
_v3.POST("/chat", append(_chatv3Mw(), coze.ChatV3)...)
|
||||
_chat := _v3.Group("/chat", _chatMw()...)
|
||||
_chat.POST("/cancel", append(_cancelchatapiMw(), coze.CancelChatApi)...)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1505,3 +1505,68 @@ func _upload1Mw() []app.HandlerFunc {
|
|||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _conversation1Mw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _openapicreateconversationMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _coze_web_appMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _impersonatecozeuserMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _botsMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _opengetbotinfoMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _deleteconversationapiMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _updateconversationapiMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _conversations0Mw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _chatMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _cancelchatapiMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _appsMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _getonlineappdataMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ import (
|
|||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/conv"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ternary"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/logs"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/safego"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/taskgroup"
|
||||
|
|
@ -303,6 +304,11 @@ func (a *APPApplicationService) getAPPPublishConnectorList(ctx context.Context,
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case consts.WebSDKConnectorID:
|
||||
info, err = a.packChatSDKConnectorInfo(ctx, c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
logs.CtxWarnf(ctx, "unsupported connector id '%v'", c.ID)
|
||||
continue
|
||||
|
|
@ -338,6 +344,22 @@ func (a *APPApplicationService) packAPIConnectorInfo(ctx context.Context, c *con
|
|||
return info, nil
|
||||
}
|
||||
|
||||
func (a *APPApplicationService) packChatSDKConnectorInfo(ctx context.Context, c *connectorModel.Connector) (*publishAPI.PublishConnectorInfo, error) {
|
||||
|
||||
info := &publishAPI.PublishConnectorInfo{
|
||||
ID: c.ID,
|
||||
BindType: publishAPI.ConnectorBindType_WebSDKBind,
|
||||
ConnectorClassification: publishAPI.ConnectorClassification_APIOrSDK,
|
||||
BindInfo: map[string]string{},
|
||||
Name: c.Name,
|
||||
IconURL: c.URL,
|
||||
Description: c.Desc,
|
||||
AllowPublish: true,
|
||||
}
|
||||
|
||||
return info, nil
|
||||
}
|
||||
|
||||
func (a *APPApplicationService) getLatestPublishRecord(ctx context.Context, appID int64) (info *publishAPI.LastPublishInfo, err error) {
|
||||
record, exist, err := a.DomainSVC.GetAPPPublishRecord(ctx, &service.GetAPPPublishRecordRequest{
|
||||
APPID: appID,
|
||||
|
|
@ -1089,6 +1111,91 @@ func (a *APPApplicationService) DraftProjectCopy(ctx context.Context, req *proje
|
|||
return resp, nil
|
||||
}
|
||||
|
||||
func (a *APPApplicationService) GetOnlineAppData(ctx context.Context, req *projectAPI.GetOnlineAppDataRequest) (resp *projectAPI.GetOnlineAppDataResponse, err error) {
|
||||
uid := ctxutil.GetApiAuthFromCtx(ctx).UserID
|
||||
record, exist, err := a.DomainSVC.GetAPPPublishRecord(ctx, &service.GetAPPPublishRecordRequest{
|
||||
APPID: req.GetAppID(),
|
||||
Oldest: false,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !exist {
|
||||
return nil, errorx.Wrapf(err, "GetOnlineAppDataRequest failed, app id=%d, connector id=%v", req.GetAppID(), req.GetConnectorID())
|
||||
}
|
||||
|
||||
if record.APP.OwnerID != uid {
|
||||
return nil, errorx.New(errno.ErrAppPermissionCode, errorx.KV(errno.APPMsgKey, fmt.Sprintf("user %d does not have access to app %d", uid, req.GetAppID())))
|
||||
|
||||
}
|
||||
|
||||
valid := false
|
||||
for _, v := range record.ConnectorPublishRecords {
|
||||
if v.ConnectorID == req.GetConnectorID() {
|
||||
valid = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !valid {
|
||||
return nil, errorx.Wrapf(err, "GetOnlineAppDataRequest failed, invalid connector id, app id=%d, connector id=%v", req.GetAppID(), req.GetConnectorID())
|
||||
}
|
||||
|
||||
app := record.APP
|
||||
|
||||
iconURL, err := a.oss.GetObjectUrl(ctx, app.GetIconURI())
|
||||
if err != nil {
|
||||
logs.CtxWarnf(ctx, "get icon url failed with '%s', err=%v", app.GetIconURI(), err)
|
||||
}
|
||||
|
||||
varMeta, err := a.variablesSVC.GetProjectVariablesMeta(ctx, strconv.FormatInt(app.ID, 10), "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
vars := make([]*common.Variable, 0, len(varMeta.Variables))
|
||||
for _, v := range varMeta.Variables {
|
||||
vars = append(vars, &common.Variable{
|
||||
Keyword: v.Keyword,
|
||||
DefaultValue: v.DefaultValue,
|
||||
Description: v.Description,
|
||||
Enable: v.Enable,
|
||||
VariableType: ternary.IFElse(v.VariableType == project_memory.VariableType_KVVariable, common.VariableTypeKVVariable, common.VariableTypeListVariable),
|
||||
Channel: func() common.VariableChannel {
|
||||
switch v.Channel {
|
||||
case project_memory.VariableChannel_APP:
|
||||
return common.VariableChannelAPP
|
||||
case project_memory.VariableChannel_System:
|
||||
return common.VariableChannelSystem
|
||||
case project_memory.VariableChannel_Custom:
|
||||
return common.VariableChannelCustom
|
||||
case project_memory.VariableChannel_Feishu:
|
||||
return common.VariableChannelFeishu
|
||||
case project_memory.VariableChannel_Location:
|
||||
return common.VariableChannelLocation
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
|
||||
}(),
|
||||
})
|
||||
}
|
||||
|
||||
response := &projectAPI.GetOnlineAppDataResponse{
|
||||
Data: &projectAPI.AppData{
|
||||
AppID: strconv.FormatInt(record.APP.ID, 10),
|
||||
Name: *app.Name,
|
||||
Description: *app.Desc,
|
||||
Version: *app.Version,
|
||||
IconURL: iconURL,
|
||||
Variables: vars,
|
||||
},
|
||||
}
|
||||
|
||||
return response, nil
|
||||
|
||||
}
|
||||
|
||||
func (a *APPApplicationService) duplicateDraftAPP(ctx context.Context, userID int64, req *projectAPI.DraftProjectCopyRequest) (newAppID int64, err error) {
|
||||
newAppID, err = a.DomainSVC.CreateDraftAPP(ctx, &service.CreateDraftAPPRequest{
|
||||
SpaceID: req.ToSpaceID,
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ import (
|
|||
crossmessage "github.com/coze-dev/coze-studio/backend/crossdomain/contract/message"
|
||||
crossmodelmgr "github.com/coze-dev/coze-studio/backend/crossdomain/contract/modelmgr"
|
||||
crossplugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin"
|
||||
crossupload "github.com/coze-dev/coze-studio/backend/crossdomain/contract/upload"
|
||||
crossuser "github.com/coze-dev/coze-studio/backend/crossdomain/contract/user"
|
||||
crossvariables "github.com/coze-dev/coze-studio/backend/crossdomain/contract/variables"
|
||||
crossworkflow "github.com/coze-dev/coze-studio/backend/crossdomain/contract/workflow"
|
||||
|
|
@ -64,6 +65,7 @@ import (
|
|||
pluginImpl "github.com/coze-dev/coze-studio/backend/crossdomain/impl/plugin"
|
||||
searchImpl "github.com/coze-dev/coze-studio/backend/crossdomain/impl/search"
|
||||
singleagentImpl "github.com/coze-dev/coze-studio/backend/crossdomain/impl/singleagent"
|
||||
uploadImpl "github.com/coze-dev/coze-studio/backend/crossdomain/impl/upload"
|
||||
variablesImpl "github.com/coze-dev/coze-studio/backend/crossdomain/impl/variables"
|
||||
workflowImpl "github.com/coze-dev/coze-studio/backend/crossdomain/impl/workflow"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/eventbus"
|
||||
|
|
@ -86,6 +88,7 @@ type basicServices struct {
|
|||
promptSVC *prompt.PromptApplicationService
|
||||
templateSVC *template.ApplicationService
|
||||
openAuthSVC *openauth.OpenAuthApplicationService
|
||||
uploadSVC *upload.UploadService
|
||||
}
|
||||
|
||||
type primaryServices struct {
|
||||
|
|
@ -139,11 +142,12 @@ func Init(ctx context.Context) (err error) {
|
|||
crossconversation.SetDefaultSVC(conversationImpl.InitDomainService(complexServices.conversationSVC.ConversationDomainSVC))
|
||||
crossmessage.SetDefaultSVC(messageImpl.InitDomainService(complexServices.conversationSVC.MessageDomainSVC))
|
||||
crossagentrun.SetDefaultSVC(agentrunImpl.InitDomainService(complexServices.conversationSVC.AgentRunDomainSVC))
|
||||
crossagent.SetDefaultSVC(singleagentImpl.InitDomainService(complexServices.singleAgentSVC.DomainSVC, infra.ImageXClient))
|
||||
crossagent.SetDefaultSVC(singleagentImpl.InitDomainService(complexServices.singleAgentSVC.DomainSVC))
|
||||
crossuser.SetDefaultSVC(crossuserImpl.InitDomainService(basicServices.userSVC.DomainSVC))
|
||||
crossdatacopy.SetDefaultSVC(dataCopyImpl.InitDomainService(basicServices.infra))
|
||||
crosssearch.SetDefaultSVC(searchImpl.InitDomainService(complexServices.searchSVC.DomainSVC))
|
||||
crossmodelmgr.SetDefaultSVC(modelmgrImpl.InitDomainService(infra.ModelMgr, nil))
|
||||
crossupload.SetDefaultSVC(uploadImpl.InitDomainService(basicServices.uploadSVC.UploadSVC))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -159,7 +163,7 @@ func initEventBus(infra *appinfra.AppDependencies) *eventbusImpl {
|
|||
|
||||
// initBasicServices init basic services that only depends on infra.
|
||||
func initBasicServices(ctx context.Context, infra *appinfra.AppDependencies, e *eventbusImpl) (*basicServices, error) {
|
||||
upload.InitService(infra.TOSClient, infra.CacheCli)
|
||||
uploadSVC := upload.InitService(&upload.UploadComponents{Cache: infra.CacheCli, Oss: infra.TOSClient, DB: infra.DB, Idgen: infra.IDGenSVC})
|
||||
openAuthSVC := openauth.InitService(infra.DB, infra.IDGenSVC)
|
||||
promptSVC := prompt.InitService(infra.DB, infra.IDGenSVC, e.resourceEventBus)
|
||||
modelMgrSVC := modelmgr.InitService(infra.ModelMgr, infra.TOSClient)
|
||||
|
|
@ -180,6 +184,7 @@ func initBasicServices(ctx context.Context, infra *appinfra.AppDependencies, e *
|
|||
promptSVC: promptSVC,
|
||||
templateSVC: templateSVC,
|
||||
openAuthSVC: openAuthSVC,
|
||||
uploadSVC: uploadSVC,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import (
|
|||
conversationService "github.com/coze-dev/coze-studio/backend/domain/conversation/conversation/service"
|
||||
message "github.com/coze-dev/coze-studio/backend/domain/conversation/message/service"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/shortcutcmd/service"
|
||||
uploadService "github.com/coze-dev/coze-studio/backend/domain/upload/service"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/slices"
|
||||
|
|
@ -48,6 +49,7 @@ var ConversationSVC = new(ConversationApplicationService)
|
|||
|
||||
type OpenapiAgentRunApplication struct {
|
||||
ShortcutDomainSVC service.ShortcutCmd
|
||||
UploaodDomainSVC uploadService.UploadService
|
||||
}
|
||||
|
||||
var ConversationOpenAPISVC = new(OpenapiAgentRunApplication)
|
||||
|
|
@ -177,6 +179,7 @@ func (c *ConversationApplicationService) ListConversation(ctx context.Context, r
|
|||
LastSectionID: &conv.SectionID,
|
||||
ConnectorID: &conv.ConnectorID,
|
||||
CreatedAt: conv.CreatedAt / 1000,
|
||||
Name: ptr.Of(conv.Name),
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -186,3 +189,70 @@ func (c *ConversationApplicationService) ListConversation(ctx context.Context, r
|
|||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *ConversationApplicationService) DeleteConversation(ctx context.Context, req *conversation.DeleteConversationApiRequest) (*conversation.DeleteConversationApiResponse, error) {
|
||||
resp := new(conversation.DeleteConversationApiResponse)
|
||||
convID := req.GetConversationID()
|
||||
|
||||
apiKeyInfo := ctxutil.GetApiAuthFromCtx(ctx)
|
||||
userID := apiKeyInfo.UserID
|
||||
|
||||
if userID == 0 {
|
||||
return resp, errorx.New(errno.ErrConversationPermissionCode, errorx.KV("msg", "permission check failed"))
|
||||
}
|
||||
|
||||
conversationDO, err := c.ConversationDomainSVC.GetByID(ctx, convID)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
if conversationDO == nil {
|
||||
return resp, errorx.New(errno.ErrConversationNotFound)
|
||||
}
|
||||
if conversationDO.CreatorID != userID {
|
||||
return resp, errorx.New(errno.ErrConversationNotFound, errorx.KV("msg", "user not match"))
|
||||
}
|
||||
err = c.ConversationDomainSVC.Delete(ctx, convID)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *ConversationApplicationService) UpdateConversation(ctx context.Context, req *conversation.UpdateConversationApiRequest) (*conversation.UpdateConversationApiResponse, error) {
|
||||
resp := new(conversation.UpdateConversationApiResponse)
|
||||
convID := req.GetConversationID()
|
||||
|
||||
apiKeyInfo := ctxutil.GetApiAuthFromCtx(ctx)
|
||||
userID := apiKeyInfo.UserID
|
||||
|
||||
if userID == 0 {
|
||||
return resp, errorx.New(errno.ErrConversationPermissionCode, errorx.KV("msg", "permission check failed"))
|
||||
}
|
||||
|
||||
conversationDO, err := c.ConversationDomainSVC.GetByID(ctx, convID)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
if conversationDO == nil {
|
||||
return resp, errorx.New(errno.ErrConversationNotFound)
|
||||
}
|
||||
if conversationDO.CreatorID != userID {
|
||||
return resp, errorx.New(errno.ErrConversationPermissionCode, errorx.KV("msg", "user not match"))
|
||||
}
|
||||
|
||||
updateResult, err := c.ConversationDomainSVC.Update(ctx, &entity.UpdateMeta{
|
||||
ID: convID,
|
||||
Name: req.GetName(),
|
||||
})
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
resp.ConversationData = &conversation.ConversationData{
|
||||
Id: updateResult.ID,
|
||||
LastSectionID: &updateResult.SectionID,
|
||||
ConnectorID: &updateResult.ConnectorID,
|
||||
CreatedAt: updateResult.CreatedAt / 1000,
|
||||
Name: ptr.Of(updateResult.Name),
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import (
|
|||
message "github.com/coze-dev/coze-studio/backend/domain/conversation/message/service"
|
||||
shortcutRepo "github.com/coze-dev/coze-studio/backend/domain/shortcutcmd/repository"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/shortcutcmd/service"
|
||||
uploadService "github.com/coze-dev/coze-studio/backend/domain/upload/service"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/imagex"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/storage"
|
||||
|
|
@ -56,6 +57,7 @@ func InitService(s *ServiceComponents) *ConversationApplicationService {
|
|||
|
||||
arDomainComponents := &agentrun.Components{
|
||||
RunRecordRepo: repository.NewRunRecordRepo(s.DB, s.IDGen),
|
||||
ImagexSVC: s.ImageX,
|
||||
}
|
||||
|
||||
agentRunDomainSVC := agentrun.NewService(arDomainComponents)
|
||||
|
|
@ -71,6 +73,9 @@ func InitService(s *ServiceComponents) *ConversationApplicationService {
|
|||
ConversationSVC.ShortcutDomainSVC = shortcutCmdDomainSVC
|
||||
|
||||
ConversationOpenAPISVC.ShortcutDomainSVC = shortcutCmdDomainSVC
|
||||
uploadSVC := uploadService.NewUploadSVC(s.DB, s.IDGen, s.TosClient)
|
||||
ConversationOpenAPISVC.UploaodDomainSVC = uploadSVC
|
||||
OpenapiMessageSVC.UploaodDomainSVC = uploadSVC
|
||||
|
||||
return ConversationSVC
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,9 @@ import (
|
|||
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/entity"
|
||||
convEntity "github.com/coze-dev/coze-studio/backend/domain/conversation/conversation/entity"
|
||||
cmdEntity "github.com/coze-dev/coze-studio/backend/domain/shortcutcmd/entity"
|
||||
uploadService "github.com/coze-dev/coze-studio/backend/domain/upload/service"
|
||||
sseImpl "github.com/coze-dev/coze-studio/backend/infra/impl/sse"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/conv"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/logs"
|
||||
|
|
@ -237,11 +239,26 @@ func (a *OpenapiAgentRunApplication) buildMultiContent(ctx context.Context, ar *
|
|||
Text: ptr.From(one.Text),
|
||||
})
|
||||
case message.InputTypeImage, message.InputTypeFile:
|
||||
|
||||
var fileUrl, fileURI string
|
||||
if one.GetFileURL() != "" {
|
||||
fileUrl = one.GetFileURL()
|
||||
} else if one.GetFileID() != 0 {
|
||||
fileInfo, err := a.UploaodDomainSVC.GetFile(ctx, &uploadService.GetFileRequest{
|
||||
ID: one.GetFileID(),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, contentType, err
|
||||
}
|
||||
fileUrl = fileInfo.File.Url
|
||||
fileURI = fileInfo.File.TosURI
|
||||
}
|
||||
multiContents = append(multiContents, &message.InputMetaData{
|
||||
Type: message.InputType(one.Type),
|
||||
FileData: []*message.FileData{
|
||||
{
|
||||
Url: one.GetFileURL(),
|
||||
Url: fileUrl,
|
||||
URI: fileURI,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
|
@ -328,3 +345,62 @@ func buildARSM2ApiChatMessage(chunk *entity.AgentRunResponse) []byte {
|
|||
mCM, _ := json.Marshal(chunkMessage)
|
||||
return mCM
|
||||
}
|
||||
|
||||
func (a *OpenapiAgentRunApplication) CancelRun(ctx context.Context, req *run.CancelChatApiRequest) (*run.CancelChatApiResponse, error) {
|
||||
resp := new(run.CancelChatApiResponse)
|
||||
|
||||
apiKeyInfo := ctxutil.GetApiAuthFromCtx(ctx)
|
||||
userID := apiKeyInfo.UserID
|
||||
|
||||
runRecord, err := ConversationSVC.AgentRunDomainSVC.GetByID(ctx, req.ChatID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if runRecord == nil {
|
||||
return nil, errorx.New(errno.ErrRecordNotFound)
|
||||
}
|
||||
|
||||
conversationData, err := ConversationSVC.ConversationDomainSVC.GetByID(ctx, req.ConversationID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if userID != conversationData.CreatorID {
|
||||
return nil, errorx.New(errno.ErrConversationPermissionCode, errorx.KV("msg", "user not match"))
|
||||
}
|
||||
|
||||
if runRecord.Status != entity.RunStatusInProgress && runRecord.Status != entity.RunStatusCreated {
|
||||
return nil, errorx.New(errno.ErrInProgressCanNotCancel)
|
||||
}
|
||||
|
||||
runMeta, err := ConversationSVC.AgentRunDomainSVC.Cancel(ctx, &entity.CancelRunMeta{
|
||||
RunID: req.ChatID,
|
||||
ConversationID: req.ConversationID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if runMeta == nil {
|
||||
return nil, errorx.New(errno.ErrConversationAgentRunError)
|
||||
}
|
||||
|
||||
resp.ChatV3ChatDetail = &run.ChatV3ChatDetail{
|
||||
ID: runMeta.ID,
|
||||
ConversationID: runMeta.ConversationID,
|
||||
BotID: runMeta.AgentID,
|
||||
Status: string(runMeta.Status),
|
||||
SectionID: ptr.Of(runMeta.SectionID),
|
||||
CreatedAt: ptr.Of(int32(runMeta.CreatedAt / 1000)),
|
||||
CompletedAt: ptr.Of(int32(runMeta.CompletedAt / 1000)),
|
||||
FailedAt: ptr.Of(int32(runMeta.FailedAt / 1000)),
|
||||
}
|
||||
if runMeta.Usage != nil {
|
||||
resp.ChatV3ChatDetail.Usage = &run.Usage{
|
||||
TokenCount: ptr.Of(int32(runMeta.Usage.LlmTotalTokens)),
|
||||
InputTokens: ptr.Of(int32(runMeta.Usage.LlmPromptTokens)),
|
||||
OutputTokens: ptr.Of(int32(runMeta.Usage.LlmCompletionTokens)),
|
||||
}
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,23 +18,28 @@ package conversation
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/conversation/message"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/conversation/run"
|
||||
apiMessage "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/message"
|
||||
message3 "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/message"
|
||||
"github.com/coze-dev/coze-studio/backend/application/base/ctxutil"
|
||||
convEntity "github.com/coze-dev/coze-studio/backend/domain/conversation/conversation/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/message/entity"
|
||||
uploadService "github.com/coze-dev/coze-studio/backend/domain/upload/service"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/slices"
|
||||
"github.com/coze-dev/coze-studio/backend/types/errno"
|
||||
)
|
||||
|
||||
type OpenapiMessageApplication struct{}
|
||||
type OpenapiMessageApplication struct {
|
||||
UploaodDomainSVC uploadService.UploadService
|
||||
}
|
||||
|
||||
var OpenapiMessageApplicationService = new(OpenapiMessageApplication)
|
||||
var OpenapiMessageSVC = new(OpenapiMessageApplication)
|
||||
|
||||
func (m *OpenapiMessageApplication) GetApiMessageList(ctx context.Context, mr *message.ListMessageApiRequest) (*message.ListMessageApiResponse, error) {
|
||||
// Get Conversation ID by agent id & userID & scene
|
||||
|
|
@ -61,13 +66,21 @@ func (m *OpenapiMessageApplication) GetApiMessageList(ctx context.Context, mr *m
|
|||
ConversationID: currentConversation.ID,
|
||||
AgentID: currentConversation.AgentID,
|
||||
Limit: int(ptr.From(mr.Limit)),
|
||||
|
||||
MessageType: []*message3.MessageType{
|
||||
ptr.Of(message3.MessageTypeQuestion),
|
||||
ptr.Of(message3.MessageTypeAnswer),
|
||||
},
|
||||
}
|
||||
if mr.ChatID != nil {
|
||||
msgListMeta.RunID = []*int64{mr.ChatID}
|
||||
}
|
||||
|
||||
if mr.BeforeID != nil {
|
||||
msgListMeta.Direction = entity.ScrollPageDirectionPrev
|
||||
msgListMeta.Direction = entity.ScrollPageDirectionNext
|
||||
msgListMeta.Cursor = *mr.BeforeID
|
||||
} else {
|
||||
msgListMeta.Direction = entity.ScrollPageDirectionNext
|
||||
msgListMeta.Direction = entity.ScrollPageDirectionPrev
|
||||
msgListMeta.Cursor = ptr.From(mr.AfterID)
|
||||
}
|
||||
if mr.Order == nil {
|
||||
|
|
@ -76,20 +89,14 @@ func (m *OpenapiMessageApplication) GetApiMessageList(ctx context.Context, mr *m
|
|||
msgListMeta.OrderBy = mr.Order
|
||||
}
|
||||
|
||||
mListMessages, err := ConversationSVC.MessageDomainSVC.List(ctx, msgListMeta)
|
||||
mListMessages, err := ConversationSVC.MessageDomainSVC.ListWithoutPair(ctx, msgListMeta)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// get agent id
|
||||
var agentIDs []int64
|
||||
for _, mOne := range mListMessages.Messages {
|
||||
agentIDs = append(agentIDs, mOne.AgentID)
|
||||
}
|
||||
|
||||
resp := m.buildMessageListResponse(ctx, mListMessages, currentConversation)
|
||||
|
||||
return resp, err
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func getConversation(ctx context.Context, conversationID int64) (*convEntity.Conversation, error) {
|
||||
|
|
@ -106,21 +113,22 @@ func (m *OpenapiMessageApplication) buildMessageListResponse(ctx context.Context
|
|||
content := dm.Content
|
||||
|
||||
msg := &message.OpenMessageApi{
|
||||
ID: dm.ID,
|
||||
ConversationID: dm.ConversationID,
|
||||
BotID: dm.AgentID,
|
||||
Role: string(dm.Role),
|
||||
Type: string(dm.MessageType),
|
||||
Content: content,
|
||||
ContentType: string(dm.ContentType),
|
||||
SectionID: strconv.FormatInt(dm.SectionID, 10),
|
||||
CreatedAt: dm.CreatedAt / 1000,
|
||||
UpdatedAt: dm.UpdatedAt / 1000,
|
||||
ChatID: dm.RunID,
|
||||
MetaData: dm.Ext,
|
||||
ID: dm.ID,
|
||||
ConversationID: dm.ConversationID,
|
||||
BotID: dm.AgentID,
|
||||
Role: string(dm.Role),
|
||||
Type: string(dm.MessageType),
|
||||
Content: content,
|
||||
ContentType: string(dm.ContentType),
|
||||
SectionID: strconv.FormatInt(dm.SectionID, 10),
|
||||
CreatedAt: dm.CreatedAt / 1000,
|
||||
UpdatedAt: dm.UpdatedAt / 1000,
|
||||
ChatID: dm.RunID,
|
||||
MetaData: dm.Ext,
|
||||
ReasoningContent: ptr.Of(dm.ReasoningContent),
|
||||
}
|
||||
if dm.ContentType == message3.ContentTypeMix && dm.DisplayContent != "" {
|
||||
msg.Content = dm.DisplayContent
|
||||
msg.Content = m.parseDisplayContent(ctx, dm)
|
||||
msg.ContentType = run.ContentTypeMixApi
|
||||
}
|
||||
return msg
|
||||
|
|
@ -135,3 +143,38 @@ func (m *OpenapiMessageApplication) buildMessageListResponse(ctx context.Context
|
|||
|
||||
return resp
|
||||
}
|
||||
|
||||
func (m *OpenapiMessageApplication) parseDisplayContent(ctx context.Context, dm *entity.Message) string {
|
||||
|
||||
var inputs []*run.AdditionalContent
|
||||
err := json.Unmarshal([]byte(dm.DisplayContent), &inputs)
|
||||
|
||||
if err != nil {
|
||||
return dm.DisplayContent
|
||||
}
|
||||
for k, one := range inputs {
|
||||
if one == nil {
|
||||
continue
|
||||
}
|
||||
switch apiMessage.InputType(one.Type) {
|
||||
case apiMessage.InputTypeText:
|
||||
continue
|
||||
case apiMessage.InputTypeImage, apiMessage.InputTypeFile:
|
||||
if one.GetFileID() != 0 {
|
||||
fileInfo, err := m.UploaodDomainSVC.GetFile(ctx, &uploadService.GetFileRequest{
|
||||
ID: one.GetFileID(),
|
||||
})
|
||||
if err == nil {
|
||||
inputs[k].FileURL = ptr.Of(fileInfo.File.Url)
|
||||
}
|
||||
}
|
||||
default:
|
||||
continue
|
||||
}
|
||||
}
|
||||
content, err := json.Marshal(inputs)
|
||||
if err == nil {
|
||||
dm.DisplayContent = string(content)
|
||||
}
|
||||
return dm.DisplayContent
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import (
|
|||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/app/bot_open_api"
|
||||
openapimodel "github.com/coze-dev/coze-studio/backend/api/model/permission/openapiauth"
|
||||
"github.com/coze-dev/coze-studio/backend/application/base/ctxutil"
|
||||
openapi "github.com/coze-dev/coze-studio/backend/domain/openauth/openapiauth"
|
||||
|
|
@ -80,6 +81,7 @@ func (s *OpenAuthApplicationService) CreatePersonalAccessToken(ctx context.Conte
|
|||
Name: req.Name,
|
||||
Expire: req.ExpireAt,
|
||||
UserID: *userID,
|
||||
AkType: entity.AkTypeCustomer,
|
||||
}
|
||||
|
||||
if req.DurationDay == "customize" {
|
||||
|
|
@ -111,6 +113,32 @@ func (s *OpenAuthApplicationService) CreatePersonalAccessToken(ctx context.Conte
|
|||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *OpenAuthApplicationService) ImpersonateCozeUserAccessToken(ctx context.Context, req *bot_open_api.ImpersonateCozeUserRequest) (*bot_open_api.ImpersonateCozeUserResponse, error) {
|
||||
resp := new(bot_open_api.ImpersonateCozeUserResponse)
|
||||
userID := ctxutil.GetUIDFromCtx(ctx)
|
||||
|
||||
expiredSecond := time.Now().Add(time.Duration(time.Second * 60 * 15)).Unix()
|
||||
|
||||
appReq := &entity.CreateApiKey{
|
||||
UserID: *userID,
|
||||
AkType: entity.AkTypeTemporary,
|
||||
Expire: expiredSecond,
|
||||
Name: "temporary access token",
|
||||
}
|
||||
|
||||
apiKeyResp, err := openapiAuthDomainSVC.Create(ctx, appReq)
|
||||
if err != nil {
|
||||
logs.CtxErrorf(ctx, "OpenAuthApplicationService.CreatePersonalAccessToken failed, err=%v", err)
|
||||
return resp, errors.New("CreatePersonalAccessToken failed")
|
||||
}
|
||||
resp.Data = &bot_open_api.ImpersonateCozeUserResponseData{
|
||||
AccessToken: apiKeyResp.ApiKey,
|
||||
ExpiresIn: expiredSecond,
|
||||
TokenType: "Bearer",
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *OpenAuthApplicationService) ListPersonalAccessTokens(ctx context.Context, req *openapimodel.ListPersonalAccessTokensRequest) (*openapimodel.ListPersonalAccessTokensResponse, error) {
|
||||
|
||||
resp := new(openapimodel.ListPersonalAccessTokensResponse)
|
||||
|
|
|
|||
|
|
@ -23,10 +23,12 @@ import (
|
|||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/database"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/data/database/table"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/resource/common"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/workflow"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/knowledge/service"
|
||||
dbservice "github.com/coze-dev/coze-studio/backend/domain/memory/database/service"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ternary"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/logs"
|
||||
)
|
||||
|
||||
|
|
@ -157,8 +159,39 @@ func (w *workflowPacker) GetDataInfo(ctx context.Context) (*dataInfo, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (w *workflowPacker) GetActions(ctx context.Context) []*common.ResourceAction {
|
||||
actions := []*common.ResourceAction{
|
||||
{
|
||||
Key: common.ActionKey_Edit,
|
||||
Enable: true,
|
||||
},
|
||||
{
|
||||
Key: common.ActionKey_Delete,
|
||||
Enable: true,
|
||||
},
|
||||
{
|
||||
Key: common.ActionKey_Copy,
|
||||
Enable: true,
|
||||
},
|
||||
}
|
||||
meta, err := w.appContext.WorkflowDomainSVC.Get(ctx, &vo.GetPolicy{
|
||||
ID: w.resID,
|
||||
MetaOnly: true,
|
||||
})
|
||||
if err != nil {
|
||||
logs.CtxWarnf(ctx, "get policy failed with '%s', err=%v", w.resID, err)
|
||||
return actions
|
||||
}
|
||||
key := ternary.IFElse(meta.Mode == workflow.WorkflowMode_Workflow, common.ActionKey_SwitchToChatflow, common.ActionKey_SwitchToFuncflow)
|
||||
action := &common.ResourceAction{
|
||||
Key: key,
|
||||
Enable: true,
|
||||
}
|
||||
return append(actions, action)
|
||||
}
|
||||
|
||||
func (w *workflowPacker) GetProjectDefaultActions(ctx context.Context) []*common.ProjectResourceAction {
|
||||
return []*common.ProjectResourceAction{
|
||||
actions := []*common.ProjectResourceAction{
|
||||
{
|
||||
Key: common.ProjectResourceActionKey_Rename,
|
||||
Enable: true,
|
||||
|
|
@ -184,6 +217,21 @@ func (w *workflowPacker) GetProjectDefaultActions(ctx context.Context) []*common
|
|||
Enable: true,
|
||||
},
|
||||
}
|
||||
meta, err := w.appContext.WorkflowDomainSVC.Get(ctx, &vo.GetPolicy{
|
||||
ID: w.resID,
|
||||
MetaOnly: true,
|
||||
})
|
||||
if err != nil {
|
||||
logs.CtxWarnf(ctx, "get policy failed with '%s', err=%v", w.resID, err)
|
||||
return actions
|
||||
}
|
||||
key := ternary.IFElse(meta.Mode == workflow.WorkflowMode_Workflow, common.ProjectResourceActionKey_SwitchToChatflow, common.ProjectResourceActionKey_SwitchToFuncflow)
|
||||
action := &common.ProjectResourceAction{
|
||||
Enable: true,
|
||||
Key: key,
|
||||
}
|
||||
|
||||
return append(actions, action)
|
||||
}
|
||||
|
||||
type knowledgePacker struct {
|
||||
|
|
|
|||
|
|
@ -370,6 +370,12 @@ func (s *SingleAgentApplicationService) applyAgentUpdates(target *entity.SingleA
|
|||
}
|
||||
target.Database = patch.DatabaseList
|
||||
}
|
||||
if patch.BotMode != nil {
|
||||
target.BotMode = ptr.From(patch.BotMode)
|
||||
}
|
||||
if patch.LayoutInfo != nil {
|
||||
target.LayoutInfo = patch.LayoutInfo
|
||||
}
|
||||
|
||||
return target, nil
|
||||
}
|
||||
|
|
@ -419,11 +425,12 @@ func (s *SingleAgentApplicationService) singleAgentDraftDo2Vo(ctx context.Contex
|
|||
TaskInfo: &bot_common.TaskInfo{},
|
||||
CreateTime: do.CreatedAt / 1000,
|
||||
UpdateTime: do.UpdatedAt / 1000,
|
||||
BotMode: bot_common.BotMode_SingleMode,
|
||||
BotMode: do.BotMode,
|
||||
BackgroundImageInfoList: do.BackgroundImageInfoList,
|
||||
Status: bot_common.BotStatus_Using,
|
||||
DatabaseList: do.Database,
|
||||
ShortcutSort: do.ShortcutCommand,
|
||||
LayoutInfo: do.LayoutInfo,
|
||||
}
|
||||
|
||||
if do.VariablesMetaID != nil {
|
||||
|
|
@ -647,16 +654,24 @@ func (s *SingleAgentApplicationService) GetAgentOnlineInfo(ctx context.Context,
|
|||
if connectorID == 0 {
|
||||
connectorID = ctxutil.GetApiAuthFromCtx(ctx).ConnectorID
|
||||
}
|
||||
agentInfo, err := s.DomainSVC.ObtainAgentByIdentity(ctx, &entity.AgentIdentity{
|
||||
AgentID: req.BotID,
|
||||
|
||||
return s.getAgentInfo(ctx, req.BotID, connectorID, uid, req.Version)
|
||||
}
|
||||
|
||||
func (s *SingleAgentApplicationService) getAgentInfo(ctx context.Context, botID int64, connectorID int64, uid int64, version *string) (*bot_common.OpenAPIBotInfo, error) {
|
||||
ae := &entity.AgentIdentity{
|
||||
AgentID: botID,
|
||||
ConnectorID: connectorID,
|
||||
Version: ptr.From(req.Version),
|
||||
})
|
||||
}
|
||||
if version != nil {
|
||||
ae.Version = ptr.From(version)
|
||||
}
|
||||
agentInfo, err := s.DomainSVC.ObtainAgentByIdentity(ctx, ae)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if agentInfo == nil {
|
||||
logs.CtxErrorf(ctx, "agent(%d) is not exist", req.BotID)
|
||||
logs.CtxErrorf(ctx, "agent(%d) is not exist", botID)
|
||||
return nil, errorx.New(errno.ErrAgentPermissionCode, errorx.KV("msg", "agent not exist"))
|
||||
}
|
||||
if agentInfo.CreatorID != uid {
|
||||
|
|
@ -731,3 +746,21 @@ func (s *SingleAgentApplicationService) GetAgentOnlineInfo(ctx context.Context,
|
|||
}
|
||||
return combineInfo, nil
|
||||
}
|
||||
|
||||
func (s *SingleAgentApplicationService) OpenGetBotInfo(ctx context.Context, req *bot_open_api.OpenGetBotInfoRequest) (*bot_open_api.OpenGetBotInfoResponse, error) {
|
||||
resp := new(bot_open_api.OpenGetBotInfoResponse)
|
||||
|
||||
uid := ctxutil.MustGetUIDFromApiAuthCtx(ctx)
|
||||
|
||||
connectorID := ptr.From(req.ConnectorID)
|
||||
|
||||
if connectorID == 0 {
|
||||
connectorID = ctxutil.GetApiAuthFromCtx(ctx).ConnectorID
|
||||
}
|
||||
agentInfo, err := s.getAgentInfo(ctx, req.BotID, connectorID, uid, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.Data = agentInfo
|
||||
return resp, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import (
|
|||
|
||||
_ "golang.org/x/image/tiff"
|
||||
_ "golang.org/x/image/webp"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
|
|
@ -50,7 +51,9 @@ import (
|
|||
"github.com/coze-dev/coze-studio/backend/api/model/playground"
|
||||
"github.com/coze-dev/coze-studio/backend/application/base/ctxutil"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/upload/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/upload/service"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/cache"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/storage"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/conv"
|
||||
|
|
@ -61,16 +64,26 @@ import (
|
|||
"github.com/coze-dev/coze-studio/backend/types/errno"
|
||||
)
|
||||
|
||||
func InitService(oss storage.Storage, cache cache.Cmdable) {
|
||||
SVC.cache = cache
|
||||
SVC.oss = oss
|
||||
func InitService(components *UploadComponents) *UploadService {
|
||||
SVC.cache = components.Cache
|
||||
SVC.oss = components.Oss
|
||||
SVC.UploadSVC = service.NewUploadSVC(components.DB, components.Idgen, components.Oss)
|
||||
return SVC
|
||||
}
|
||||
|
||||
type UploadComponents struct {
|
||||
Oss storage.Storage
|
||||
Cache cache.Cmdable
|
||||
DB *gorm.DB
|
||||
Idgen idgen.IDGenerator
|
||||
}
|
||||
|
||||
var SVC = &UploadService{}
|
||||
|
||||
type UploadService struct {
|
||||
oss storage.Storage
|
||||
cache cache.Cmdable
|
||||
oss storage.Storage
|
||||
cache cache.Cmdable
|
||||
UploadSVC service.UploadService
|
||||
}
|
||||
|
||||
const (
|
||||
|
|
@ -427,6 +440,23 @@ func (u *UploadService) UploadFileOpen(ctx context.Context, req *bot_open_api.Up
|
|||
}
|
||||
resp.File.CreatedAt = time.Now().Unix()
|
||||
resp.File.URL = url
|
||||
fileEntity := entity.File{
|
||||
Name: fileHeader.Filename,
|
||||
FileSize: fileHeader.Size,
|
||||
TosURI: objName,
|
||||
Status: entity.FileStatusValid,
|
||||
CreatorID: strconv.FormatInt(uid, 10),
|
||||
Source: entity.FileSourceAPI,
|
||||
CozeAccountID: uid,
|
||||
ContentType: fileHeader.Header.Get("Content-Type"),
|
||||
CreatedAt: time.Now().UnixMilli(),
|
||||
UpdatedAt: time.Now().UnixMilli(),
|
||||
}
|
||||
domainResp, err := u.UploadSVC.UploadFile(ctx, &service.UploadFileRequest{File: &fileEntity})
|
||||
if err != nil {
|
||||
return &resp, err
|
||||
}
|
||||
resp.File.ID = strconv.FormatInt(domainResp.File.ID, 10)
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -18,19 +18,24 @@ package workflow
|
|||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
"os"
|
||||
|
||||
"github.com/cloudwego/eino/callbacks"
|
||||
"github.com/cloudwego/eino/compose"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/crossdomain/impl/code"
|
||||
|
||||
knowledge "github.com/coze-dev/coze-studio/backend/domain/knowledge/service"
|
||||
dbservice "github.com/coze-dev/coze-studio/backend/domain/memory/database/service"
|
||||
variables "github.com/coze-dev/coze-studio/backend/domain/memory/variables/service"
|
||||
plugin "github.com/coze-dev/coze-studio/backend/domain/plugin/service"
|
||||
search "github.com/coze-dev/coze-studio/backend/domain/search/service"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/config"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/service"
|
||||
workflowservice "github.com/coze-dev/coze-studio/backend/domain/workflow/service"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/cache"
|
||||
|
|
@ -57,17 +62,44 @@ type ServiceComponents struct {
|
|||
WorkflowBuildInChatModel chatmodel.BaseChatModel
|
||||
}
|
||||
|
||||
func InitService(ctx context.Context, components *ServiceComponents) (*ApplicationService, error) {
|
||||
func initWorkflowConfig() (workflow.WorkflowConfig, error) {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
configBs, err := os.ReadFile(filepath.Join(wd, "resources/conf/workflow/config.yaml"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var cfg *config.WorkflowConfig
|
||||
err = yaml.Unmarshal(configBs, &cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func InitService(_ context.Context, components *ServiceComponents) (*ApplicationService, error) {
|
||||
service.RegisterAllNodeAdaptors()
|
||||
|
||||
workflowRepo := service.NewWorkflowRepository(components.IDGen, components.DB, components.Cache,
|
||||
components.Tos, components.CPStore, components.WorkflowBuildInChatModel)
|
||||
cfg, err := initWorkflowConfig()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
workflowRepo, err := service.NewWorkflowRepository(components.IDGen, components.DB, components.Cache,
|
||||
components.Tos, components.CPStore, components.WorkflowBuildInChatModel, cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
workflow.SetRepository(workflowRepo)
|
||||
|
||||
workflowDomainSVC := service.NewWorkflowService(workflowRepo)
|
||||
|
||||
code.SetCodeRunner(components.CodeRunner)
|
||||
callbacks.AppendGlobalHandlers(workflowservice.GetTokenCallbackHandler())
|
||||
|
||||
setEventBus(components.DomainNotifier)
|
||||
|
||||
SVC.DomainSVC = workflowDomainSVC
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@ import (
|
|||
crossuser "github.com/coze-dev/coze-studio/backend/crossdomain/contract/user"
|
||||
search "github.com/coze-dev/coze-studio/backend/domain/search/entity"
|
||||
domainWorkflow "github.com/coze-dev/coze-studio/backend/domain/workflow"
|
||||
workflowDomain "github.com/coze-dev/coze-studio/backend/domain/workflow"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
|
|
@ -70,7 +69,7 @@ import (
|
|||
)
|
||||
|
||||
type ApplicationService struct {
|
||||
DomainSVC workflowDomain.Service
|
||||
DomainSVC domainWorkflow.Service
|
||||
ImageX imagex.ImageX // we set Imagex here, because Imagex is used as a proxy to get auth token, there is no actual correlation with the workflow domain.
|
||||
TosClient storage.Storage
|
||||
IDGenerator idgen.IDGenerator
|
||||
|
|
@ -169,6 +168,21 @@ func (w *ApplicationService) CreateWorkflow(ctx context.Context, req *workflow.C
|
|||
if err := checkUserSpace(ctx, uID, spaceID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var createConversation bool
|
||||
if req.ProjectID != nil && req.IsSetFlowMode() && req.GetFlowMode() == workflow.WorkflowMode_ChatFlow && req.IsSetCreateConversation() && req.GetCreateConversation() {
|
||||
createConversation = true
|
||||
_, err := GetWorkflowDomainSVC().CreateDraftConversationTemplate(ctx, &vo.CreateConversationTemplateMeta{
|
||||
AppID: mustParseInt64(req.GetProjectID()),
|
||||
UserID: uID,
|
||||
SpaceID: spaceID,
|
||||
Name: req.Name,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
wf := &vo.MetaCreate{
|
||||
CreatorID: uID,
|
||||
SpaceID: spaceID,
|
||||
|
|
@ -180,6 +194,14 @@ func (w *ApplicationService) CreateWorkflow(ctx context.Context, req *workflow.C
|
|||
Mode: ternary.IFElse(req.IsSetFlowMode(), req.GetFlowMode(), workflow.WorkflowMode_Workflow),
|
||||
InitCanvasSchema: vo.GetDefaultInitCanvasJsonSchema(i18n.GetLocale(ctx)),
|
||||
}
|
||||
if req.IsSetFlowMode() && req.GetFlowMode() == workflow.WorkflowMode_ChatFlow {
|
||||
conversationName := req.Name
|
||||
if !req.IsSetProjectID() || mustParseInt64(req.GetProjectID()) == 0 || !createConversation {
|
||||
conversationName = "Default"
|
||||
}
|
||||
|
||||
wf.InitCanvasSchema = vo.GetDefaultInitCanvasJsonSchemaChat(i18n.GetLocale(ctx), conversationName)
|
||||
}
|
||||
|
||||
id, err := GetWorkflowDomainSVC().Create(ctx, wf)
|
||||
if err != nil {
|
||||
|
|
@ -249,10 +271,12 @@ func (w *ApplicationService) UpdateWorkflowMeta(ctx context.Context, req *workfl
|
|||
}
|
||||
|
||||
workflowID := mustParseInt64(req.GetWorkflowID())
|
||||
err = GetWorkflowDomainSVC().UpdateMeta(ctx, workflowID, &vo.MetaUpdate{
|
||||
Name: req.Name,
|
||||
Desc: req.Desc,
|
||||
IconURI: req.IconURI,
|
||||
|
||||
err = GetWorkflowDomainSVC().UpdateMeta(ctx, mustParseInt64(req.GetWorkflowID()), &vo.MetaUpdate{
|
||||
Name: req.Name,
|
||||
Desc: req.Desc,
|
||||
IconURI: req.IconURI,
|
||||
WorkflowMode: req.FlowMode,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -2106,6 +2130,10 @@ func (w *ApplicationService) ListWorkflow(ctx context.Context, req *workflow.Get
|
|||
option.IDs = ids
|
||||
}
|
||||
|
||||
if req.IsSetFlowMode() && req.GetFlowMode() != workflow.WorkflowMode_All {
|
||||
option.Mode = ptr.Of(workflowModel.WorkflowMode(req.GetFlowMode()))
|
||||
}
|
||||
|
||||
spaceID, err := strconv.ParseInt(req.GetSpaceID(), 10, 64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("space id is invalid, parse to int64 failed, err: %w", err)
|
||||
|
|
@ -2157,6 +2185,13 @@ func (w *ApplicationService) ListWorkflow(ctx context.Context, req *workflow.Get
|
|||
},
|
||||
}
|
||||
|
||||
if len(req.Checker) > 0 && status == workflow.WorkFlowListStatus_HadPublished {
|
||||
ww.CheckResult, err = GetWorkflowDomainSVC().WorkflowSchemaCheck(ctx, w, req.Checker)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if qType == workflowModel.FromDraft {
|
||||
ww.UpdateTime = w.DraftMeta.Timestamp.Unix()
|
||||
} else if qType == workflowModel.FromLatestVersion || qType == workflowModel.FromSpecificVersion {
|
||||
|
|
@ -3736,3 +3771,419 @@ func checkUserSpace(ctx context.Context, uid int64, spaceID int64) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *ApplicationService) populateChatFlowRoleFields(role *workflow.ChatFlowRole, targetRole interface{}) error {
|
||||
var avatarUri, audioStr, bgStr, obStr, srStr, uiStr string
|
||||
var err error
|
||||
|
||||
if role.Avatar != nil {
|
||||
avatarUri = role.Avatar.ImageUri
|
||||
|
||||
}
|
||||
if role.AudioConfig != nil {
|
||||
audioStr, err = sonic.MarshalString(*role.AudioConfig)
|
||||
if err != nil {
|
||||
return vo.WrapError(errno.ErrSerializationDeserializationFail, err)
|
||||
}
|
||||
}
|
||||
if role.BackgroundImageInfo != nil {
|
||||
bgStr, err = sonic.MarshalString(*role.BackgroundImageInfo)
|
||||
if err != nil {
|
||||
return vo.WrapError(errno.ErrSerializationDeserializationFail, err)
|
||||
}
|
||||
}
|
||||
if role.OnboardingInfo != nil {
|
||||
obStr, err = sonic.MarshalString(*role.OnboardingInfo)
|
||||
if err != nil {
|
||||
return vo.WrapError(errno.ErrSerializationDeserializationFail, err)
|
||||
}
|
||||
}
|
||||
if role.SuggestReplyInfo != nil {
|
||||
srStr, err = sonic.MarshalString(*role.SuggestReplyInfo)
|
||||
if err != nil {
|
||||
return vo.WrapError(errno.ErrSerializationDeserializationFail, err)
|
||||
}
|
||||
}
|
||||
if role.UserInputConfig != nil {
|
||||
uiStr, err = sonic.MarshalString(*role.UserInputConfig)
|
||||
if err != nil {
|
||||
return vo.WrapError(errno.ErrSerializationDeserializationFail, err)
|
||||
}
|
||||
}
|
||||
|
||||
switch r := targetRole.(type) {
|
||||
case *vo.ChatFlowRoleCreate:
|
||||
if role.Name != nil {
|
||||
r.Name = *role.Name
|
||||
}
|
||||
if role.Description != nil {
|
||||
r.Description = *role.Description
|
||||
}
|
||||
if avatarUri != "" {
|
||||
r.AvatarUri = avatarUri
|
||||
}
|
||||
if audioStr != "" {
|
||||
r.AudioConfig = audioStr
|
||||
}
|
||||
if bgStr != "" {
|
||||
r.BackgroundImageInfo = bgStr
|
||||
}
|
||||
if obStr != "" {
|
||||
r.OnboardingInfo = obStr
|
||||
}
|
||||
if srStr != "" {
|
||||
r.SuggestReplyInfo = srStr
|
||||
}
|
||||
if uiStr != "" {
|
||||
r.UserInputConfig = uiStr
|
||||
}
|
||||
case *vo.ChatFlowRoleUpdate:
|
||||
r.Name = role.Name
|
||||
r.Description = role.Description
|
||||
if avatarUri != "" {
|
||||
r.AvatarUri = ptr.Of(avatarUri)
|
||||
}
|
||||
if audioStr != "" {
|
||||
r.AudioConfig = ptr.Of(audioStr)
|
||||
}
|
||||
if bgStr != "" {
|
||||
r.BackgroundImageInfo = ptr.Of(bgStr)
|
||||
}
|
||||
if obStr != "" {
|
||||
r.OnboardingInfo = ptr.Of(obStr)
|
||||
}
|
||||
if srStr != "" {
|
||||
r.SuggestReplyInfo = ptr.Of(srStr)
|
||||
}
|
||||
if uiStr != "" {
|
||||
r.UserInputConfig = ptr.Of(uiStr)
|
||||
}
|
||||
default:
|
||||
return vo.WrapError(errno.ErrInvalidParameter, fmt.Errorf("invalid type for targetRole: %T", targetRole))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func IsChatFlow(wf *entity.Workflow) bool {
|
||||
if wf == nil || wf.ID == 0 {
|
||||
return false
|
||||
}
|
||||
return wf.Meta.Mode == workflow.WorkflowMode_ChatFlow
|
||||
}
|
||||
|
||||
func (w *ApplicationService) CreateChatFlowRole(ctx context.Context, req *workflow.CreateChatFlowRoleRequest) (
|
||||
_ *workflow.CreateChatFlowRoleResponse, err error) {
|
||||
defer func() {
|
||||
if panicErr := recover(); panicErr != nil {
|
||||
err = safego.NewPanicErr(panicErr, debug.Stack())
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
err = vo.WrapIfNeeded(errno.ErrChatFlowRoleOperationFail, err, errorx.KV("cause", vo.UnwrapRootErr(err).Error()))
|
||||
}
|
||||
}()
|
||||
|
||||
uID := ctxutil.MustGetUIDFromCtx(ctx)
|
||||
wf, err := GetWorkflowDomainSVC().Get(ctx, &vo.GetPolicy{
|
||||
ID: mustParseInt64(req.GetChatFlowRole().GetWorkflowID()),
|
||||
MetaOnly: true,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = checkUserSpace(ctx, uID, wf.Meta.SpaceID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
role := req.GetChatFlowRole()
|
||||
|
||||
if !IsChatFlow(wf) {
|
||||
logs.CtxWarnf(ctx, "CreateChatFlowRole not chat flow, workflowID: %d", wf.ID)
|
||||
return nil, vo.WrapError(errno.ErrChatFlowRoleOperationFail, fmt.Errorf("workflow %d is not a chat flow", wf.ID))
|
||||
}
|
||||
|
||||
oldRole, err := GetWorkflowDomainSVC().GetChatFlowRole(ctx, mustParseInt64(role.WorkflowID), "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var roleID int64
|
||||
if oldRole != nil {
|
||||
role.ID = strconv.FormatInt(oldRole.ID, 10)
|
||||
roleID = oldRole.ID
|
||||
}
|
||||
|
||||
if role.GetID() == "" || role.GetID() == "0" {
|
||||
chatFlowRole := &vo.ChatFlowRoleCreate{
|
||||
WorkflowID: mustParseInt64(role.WorkflowID),
|
||||
CreatorID: uID,
|
||||
}
|
||||
if err = w.populateChatFlowRoleFields(role, chatFlowRole); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
roleID, err = GetWorkflowDomainSVC().CreateChatFlowRole(ctx, chatFlowRole)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
} else {
|
||||
chatFlowRole := &vo.ChatFlowRoleUpdate{
|
||||
WorkflowID: mustParseInt64(role.WorkflowID),
|
||||
}
|
||||
|
||||
if err = w.populateChatFlowRoleFields(role, chatFlowRole); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = GetWorkflowDomainSVC().UpdateChatFlowRole(ctx, chatFlowRole.WorkflowID, chatFlowRole)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &workflow.CreateChatFlowRoleResponse{
|
||||
ID: strconv.FormatInt(roleID, 10),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (w *ApplicationService) DeleteChatFlowRole(ctx context.Context, req *workflow.DeleteChatFlowRoleRequest) (
|
||||
_ *workflow.DeleteChatFlowRoleResponse, err error) {
|
||||
defer func() {
|
||||
if panicErr := recover(); panicErr != nil {
|
||||
err = safego.NewPanicErr(panicErr, debug.Stack())
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
err = vo.WrapIfNeeded(errno.ErrChatFlowRoleOperationFail, err, errorx.KV("cause", vo.UnwrapRootErr(err).Error()))
|
||||
}
|
||||
}()
|
||||
|
||||
uID := ctxutil.MustGetUIDFromCtx(ctx)
|
||||
wf, err := GetWorkflowDomainSVC().Get(ctx, &vo.GetPolicy{
|
||||
ID: mustParseInt64(req.GetWorkflowID()),
|
||||
MetaOnly: true,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = checkUserSpace(ctx, uID, wf.Meta.SpaceID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = GetWorkflowDomainSVC().DeleteChatFlowRole(ctx, mustParseInt64(req.ID), mustParseInt64(req.WorkflowID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &workflow.DeleteChatFlowRoleResponse{}, nil
|
||||
}
|
||||
|
||||
func (w *ApplicationService) GetChatFlowRole(ctx context.Context, req *workflow.GetChatFlowRoleRequest) (
|
||||
_ *workflow.GetChatFlowRoleResponse, err error) {
|
||||
defer func() {
|
||||
if panicErr := recover(); panicErr != nil {
|
||||
err = safego.NewPanicErr(panicErr, debug.Stack())
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
err = vo.WrapIfNeeded(errno.ErrChatFlowRoleOperationFail, err, errorx.KV("cause", vo.UnwrapRootErr(err).Error()))
|
||||
}
|
||||
}()
|
||||
|
||||
uID := ctxutil.MustGetUIDFromCtx(ctx)
|
||||
wf, err := GetWorkflowDomainSVC().Get(ctx, &vo.GetPolicy{
|
||||
ID: mustParseInt64(req.GetWorkflowID()),
|
||||
MetaOnly: true,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = checkUserSpace(ctx, uID, wf.Meta.SpaceID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !IsChatFlow(wf) {
|
||||
logs.CtxWarnf(ctx, "GetChatFlowRole not chat flow, workflowID: %d", wf.ID)
|
||||
return nil, vo.WrapError(errno.ErrChatFlowRoleOperationFail, fmt.Errorf("workflow %d is not a chat flow", wf.ID))
|
||||
}
|
||||
|
||||
var version string
|
||||
if wf.Meta.AppID != nil {
|
||||
if vl, err := GetWorkflowDomainSVC().GetWorkflowVersionsByConnector(ctx, mustParseInt64(req.GetConnectorID()), wf.ID, 1); err != nil {
|
||||
return nil, err
|
||||
} else if len(vl) > 0 {
|
||||
version = vl[0]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
role, err := GetWorkflowDomainSVC().GetChatFlowRole(ctx, mustParseInt64(req.WorkflowID), version)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if role == nil {
|
||||
logs.CtxWarnf(ctx, "GetChatFlowRole role nil, workflowID: %d", wf.ID)
|
||||
// Return nil for the error to align with the production behavior,
|
||||
// where the GET API may be called before the CREATE API during chatflow creation.
|
||||
return &workflow.GetChatFlowRoleResponse{}, nil
|
||||
}
|
||||
|
||||
wfRole, err := w.convertChatFlowRole(ctx, role)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get chat flow role config, internal data processing error: %+v", err)
|
||||
}
|
||||
|
||||
return &workflow.GetChatFlowRoleResponse{
|
||||
Role: wfRole,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (w *ApplicationService) convertChatFlowRole(ctx context.Context, role *entity.ChatFlowRole) (*workflow.ChatFlowRole, error) {
|
||||
var err error
|
||||
res := &workflow.ChatFlowRole{
|
||||
ID: strconv.FormatInt(role.ID, 10),
|
||||
WorkflowID: strconv.FormatInt(role.WorkflowID, 10),
|
||||
Name: ptr.Of(role.Name),
|
||||
Description: ptr.Of(role.Description),
|
||||
}
|
||||
|
||||
if role.AvatarUri != "" {
|
||||
url, err := w.ImageX.GetResourceURL(ctx, role.AvatarUri)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res.Avatar = &workflow.AvatarConfig{
|
||||
ImageUri: role.AvatarUri,
|
||||
ImageUrl: url.URL,
|
||||
}
|
||||
}
|
||||
|
||||
if role.AudioConfig != "" {
|
||||
err = sonic.UnmarshalString(role.AudioConfig, &res.AudioConfig)
|
||||
if err != nil {
|
||||
logs.CtxErrorf(ctx, "GetChatFlowRole AudioConfig UnmarshalString err: %+v", err)
|
||||
return nil, vo.WrapError(errno.ErrSerializationDeserializationFail, err)
|
||||
}
|
||||
}
|
||||
|
||||
if role.OnboardingInfo != "" {
|
||||
err = sonic.UnmarshalString(role.OnboardingInfo, &res.OnboardingInfo)
|
||||
if err != nil {
|
||||
logs.CtxErrorf(ctx, "GetChatFlowRole OnboardingInfo UnmarshalString err: %+v", err)
|
||||
return nil, vo.WrapError(errno.ErrSerializationDeserializationFail, err)
|
||||
}
|
||||
}
|
||||
|
||||
if role.SuggestReplyInfo != "" {
|
||||
err = sonic.UnmarshalString(role.SuggestReplyInfo, &res.SuggestReplyInfo)
|
||||
if err != nil {
|
||||
logs.CtxErrorf(ctx, "GetChatFlowRole SuggestReplyInfo UnmarshalString err: %+v", err)
|
||||
return nil, vo.WrapError(errno.ErrSerializationDeserializationFail, err)
|
||||
}
|
||||
}
|
||||
|
||||
if role.UserInputConfig != "" {
|
||||
err = sonic.UnmarshalString(role.UserInputConfig, &res.UserInputConfig)
|
||||
if err != nil {
|
||||
logs.CtxErrorf(ctx, "GetChatFlowRole UserInputConfig UnmarshalString err: %+v", err)
|
||||
return nil, vo.WrapError(errno.ErrSerializationDeserializationFail, err)
|
||||
}
|
||||
}
|
||||
|
||||
if role.BackgroundImageInfo != "" {
|
||||
res.BackgroundImageInfo = &workflow.BackgroundImageInfo{}
|
||||
err = sonic.UnmarshalString(role.BackgroundImageInfo, res.BackgroundImageInfo)
|
||||
if err != nil {
|
||||
logs.CtxErrorf(ctx, "GetChatFlowRole BackgroundImageInfo UnmarshalString err: %+v", err)
|
||||
return nil, vo.WrapError(errno.ErrSerializationDeserializationFail, err)
|
||||
}
|
||||
if res.BackgroundImageInfo != nil {
|
||||
if res.BackgroundImageInfo.WebBackgroundImage != nil && res.BackgroundImageInfo.WebBackgroundImage.OriginImageUri != nil {
|
||||
url, err := w.ImageX.GetResourceURL(ctx, res.BackgroundImageInfo.WebBackgroundImage.GetOriginImageUri())
|
||||
if err != nil {
|
||||
logs.CtxErrorf(ctx, "get url by uri err, err:%s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
res.BackgroundImageInfo.WebBackgroundImage.ImageUrl = &url.URL
|
||||
}
|
||||
|
||||
if res.BackgroundImageInfo.MobileBackgroundImage != nil && res.BackgroundImageInfo.MobileBackgroundImage.OriginImageUri != nil {
|
||||
url, err := w.ImageX.GetResourceURL(ctx, res.BackgroundImageInfo.MobileBackgroundImage.GetOriginImageUri())
|
||||
if err != nil {
|
||||
logs.CtxErrorf(ctx, "get url by uri err, err:%s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
res.BackgroundImageInfo.MobileBackgroundImage.ImageUrl = &url.URL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (w *ApplicationService) OpenAPIGetWorkflowInfo(ctx context.Context, req *workflow.OpenAPIGetWorkflowInfoRequest) (
|
||||
_ *workflow.OpenAPIGetWorkflowInfoResponse, err error) {
|
||||
defer func() {
|
||||
if panicErr := recover(); panicErr != nil {
|
||||
err = safego.NewPanicErr(panicErr, debug.Stack())
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
err = vo.WrapIfNeeded(errno.ErrChatFlowRoleOperationFail, err, errorx.KV("cause", vo.UnwrapRootErr(err).Error()))
|
||||
}
|
||||
}()
|
||||
|
||||
uID := ctxutil.GetApiAuthFromCtx(ctx).UserID
|
||||
wf, err := GetWorkflowDomainSVC().Get(ctx, &vo.GetPolicy{
|
||||
ID: mustParseInt64(req.GetWorkflowID()),
|
||||
MetaOnly: true,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = checkUserSpace(ctx, uID, wf.Meta.SpaceID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !IsChatFlow(wf) {
|
||||
logs.CtxWarnf(ctx, "GetChatFlowRole not chat flow, workflowID: %d", wf.ID)
|
||||
return nil, vo.WrapError(errno.ErrChatFlowRoleOperationFail, fmt.Errorf("workflow %d is not a chat flow", wf.ID))
|
||||
}
|
||||
|
||||
var version string
|
||||
if wf.Meta.AppID != nil {
|
||||
if vl, err := GetWorkflowDomainSVC().GetWorkflowVersionsByConnector(ctx, mustParseInt64(req.GetConnectorID()), wf.ID, 1); err != nil {
|
||||
return nil, err
|
||||
} else if len(vl) > 0 {
|
||||
version = vl[0]
|
||||
}
|
||||
}
|
||||
|
||||
role, err := GetWorkflowDomainSVC().GetChatFlowRole(ctx, mustParseInt64(req.WorkflowID), version)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if role == nil {
|
||||
logs.CtxWarnf(ctx, "GetChatFlowRole role nil, workflowID: %d", wf.ID)
|
||||
// Return nil for the error to align with the production behavior,
|
||||
// where the GET API may be called before the CREATE API during chatflow creation.
|
||||
return &workflow.OpenAPIGetWorkflowInfoResponse{}, nil
|
||||
}
|
||||
|
||||
wfRole, err := w.convertChatFlowRole(ctx, role)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get chat flow role config, internal data processing error: %+v", err)
|
||||
}
|
||||
|
||||
return &workflow.OpenAPIGetWorkflowInfoResponse{
|
||||
WorkflowInfo: &workflow.WorkflowInfo{
|
||||
Role: wfRole,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
NodeOfCodeConfig:
|
||||
SupportThirdPartModules:
|
||||
- httpx
|
||||
- numpy
|
||||
|
|
@ -21,17 +21,31 @@ import (
|
|||
|
||||
"github.com/cloudwego/eino/schema"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/message"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/agentrun"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/singleagent"
|
||||
)
|
||||
|
||||
// Requests and responses must not reference domain entities and can only use models under api/model/crossdomain.
|
||||
type SingleAgent interface {
|
||||
StreamExecute(ctx context.Context, historyMsg []*message.Message, query *message.Message,
|
||||
agentRuntime *singleagent.AgentRuntime) (*schema.StreamReader[*singleagent.AgentEvent], error)
|
||||
StreamExecute(ctx context.Context,
|
||||
agentRuntime *AgentRuntime) (*schema.StreamReader[*singleagent.AgentEvent], error)
|
||||
ObtainAgentByIdentity(ctx context.Context, identity *singleagent.AgentIdentity) (*singleagent.SingleAgent, error)
|
||||
}
|
||||
|
||||
type AgentRuntime struct {
|
||||
AgentVersion string
|
||||
UserID string
|
||||
AgentID int64
|
||||
IsDraft bool
|
||||
SpaceID int64
|
||||
ConnectorID int64
|
||||
PreRetrieveTools []*agentrun.Tool
|
||||
|
||||
HistoryMsg []*schema.Message
|
||||
Input *schema.Message
|
||||
ResumeInfo *ResumeInfo
|
||||
}
|
||||
|
||||
type ResumeInfo = singleagent.InterruptInfo
|
||||
|
||||
type AgentEvent = singleagent.AgentEvent
|
||||
|
|
|
|||
|
|
@ -18,10 +18,14 @@ package crossagentrun
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/entity"
|
||||
)
|
||||
|
||||
type AgentRun interface {
|
||||
Delete(ctx context.Context, runID []int64) error
|
||||
List(ctx context.Context, ListMeta *entity.ListRunRecordMeta) ([]*entity.RunRecordMeta, error)
|
||||
Create(ctx context.Context, runRecord *entity.AgentRunMeta) (*entity.RunRecordMeta, error)
|
||||
}
|
||||
|
||||
var defaultSVC AgentRun
|
||||
|
|
|
|||
|
|
@ -20,10 +20,15 @@ import (
|
|||
"context"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/conversation"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/conversation/entity"
|
||||
)
|
||||
|
||||
//go:generate mockgen -destination conversationmock/conversation_mock.go --package conversationmock -source conversation.go
|
||||
type Conversation interface {
|
||||
GetCurrentConversation(ctx context.Context, req *conversation.GetCurrent) (*conversation.Conversation, error)
|
||||
CreateConversation(ctx context.Context, req *entity.CreateMeta) (*entity.Conversation, error)
|
||||
ClearConversationHistory(ctx context.Context, req *ClearConversationHistoryReq) (*entity.NewConversationCtxResponse, error)
|
||||
GetByID(ctx context.Context, id int64) (*entity.Conversation, error)
|
||||
}
|
||||
|
||||
var defaultSVC Conversation
|
||||
|
|
@ -35,3 +40,7 @@ func DefaultSVC() Conversation {
|
|||
func SetDefaultSVC(c Conversation) {
|
||||
defaultSVC = c
|
||||
}
|
||||
|
||||
type ClearConversationHistoryReq struct {
|
||||
ConversationID int64
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: conversation.go
|
||||
//
|
||||
// Generated by this command:
|
||||
//
|
||||
// mockgen -destination conversationmock/conversation_mock.go --package conversationmock -source conversation.go
|
||||
//
|
||||
|
||||
// Package conversationmock is a generated GoMock package.
|
||||
package conversationmock
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
conversation "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/conversation"
|
||||
conversation0 "github.com/coze-dev/coze-studio/backend/crossdomain/contract/conversation"
|
||||
entity "github.com/coze-dev/coze-studio/backend/domain/conversation/conversation/entity"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
// MockConversation is a mock of Conversation interface.
|
||||
type MockConversation struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockConversationMockRecorder
|
||||
isgomock struct{}
|
||||
}
|
||||
|
||||
// MockConversationMockRecorder is the mock recorder for MockConversation.
|
||||
type MockConversationMockRecorder struct {
|
||||
mock *MockConversation
|
||||
}
|
||||
|
||||
// NewMockConversation creates a new mock instance.
|
||||
func NewMockConversation(ctrl *gomock.Controller) *MockConversation {
|
||||
mock := &MockConversation{ctrl: ctrl}
|
||||
mock.recorder = &MockConversationMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockConversation) EXPECT() *MockConversationMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// ClearConversationHistory mocks base method.
|
||||
func (m *MockConversation) ClearConversationHistory(ctx context.Context, req *conversation0.ClearConversationHistoryReq) (*entity.NewConversationCtxResponse, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ClearConversationHistory", ctx, req)
|
||||
ret0, _ := ret[0].(*entity.NewConversationCtxResponse)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// ClearConversationHistory indicates an expected call of ClearConversationHistory.
|
||||
func (mr *MockConversationMockRecorder) ClearConversationHistory(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ClearConversationHistory", reflect.TypeOf((*MockConversation)(nil).ClearConversationHistory), ctx, req)
|
||||
}
|
||||
|
||||
// CreateConversation mocks base method.
|
||||
func (m *MockConversation) CreateConversation(ctx context.Context, req *entity.CreateMeta) (*entity.Conversation, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "CreateConversation", ctx, req)
|
||||
ret0, _ := ret[0].(*entity.Conversation)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// CreateConversation indicates an expected call of CreateConversation.
|
||||
func (mr *MockConversationMockRecorder) CreateConversation(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateConversation", reflect.TypeOf((*MockConversation)(nil).CreateConversation), ctx, req)
|
||||
}
|
||||
|
||||
// GetByID mocks base method.
|
||||
func (m *MockConversation) GetByID(ctx context.Context, id int64) (*entity.Conversation, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetByID", ctx, id)
|
||||
ret0, _ := ret[0].(*entity.Conversation)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetByID indicates an expected call of GetByID.
|
||||
func (mr *MockConversationMockRecorder) GetByID(ctx, id any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetByID", reflect.TypeOf((*MockConversation)(nil).GetByID), ctx, id)
|
||||
}
|
||||
|
||||
// GetCurrentConversation mocks base method.
|
||||
func (m *MockConversation) GetCurrentConversation(ctx context.Context, req *conversation.GetCurrent) (*conversation.Conversation, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetCurrentConversation", ctx, req)
|
||||
ret0, _ := ret[0].(*conversation.Conversation)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetCurrentConversation indicates an expected call of GetCurrentConversation.
|
||||
func (mr *MockConversationMockRecorder) GetCurrentConversation(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCurrentConversation", reflect.TypeOf((*MockConversation)(nil).GetCurrentConversation), ctx, req)
|
||||
}
|
||||
|
|
@ -19,14 +19,24 @@ package message
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cloudwego/eino/schema"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/message"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/message/entity"
|
||||
)
|
||||
|
||||
//go:generate mockgen -destination messagemock/message_mock.go --package messagemock -source message.go
|
||||
type Message interface {
|
||||
GetByRunIDs(ctx context.Context, conversationID int64, runIDs []int64) ([]*message.Message, error)
|
||||
PreCreate(ctx context.Context, msg *message.Message) (*message.Message, error)
|
||||
Create(ctx context.Context, msg *message.Message) (*message.Message, error)
|
||||
List(ctx context.Context, meta *entity.ListMeta) (*entity.ListResult, error)
|
||||
ListWithoutPair(ctx context.Context, req *entity.ListMeta) (*entity.ListResult, error)
|
||||
Edit(ctx context.Context, msg *message.Message) (*message.Message, error)
|
||||
Delete(ctx context.Context, req *entity.DeleteMeta) error
|
||||
GetMessageByID(ctx context.Context, id int64) (*entity.Message, error)
|
||||
MessageList(ctx context.Context, req *MessageListRequest) (*MessageListResponse, error)
|
||||
GetLatestRunIDs(ctx context.Context, req *GetLatestRunIDsRequest) ([]int64, error)
|
||||
GetMessagesByRunIDs(ctx context.Context, req *GetMessagesByRunIDsRequest) (*GetMessagesByRunIDsResponse, error)
|
||||
}
|
||||
|
||||
var defaultSVC Message
|
||||
|
|
@ -40,3 +50,55 @@ func DefaultSVC() Message {
|
|||
func SetDefaultSVC(c Message) {
|
||||
defaultSVC = c
|
||||
}
|
||||
|
||||
type MessageListRequest struct {
|
||||
ConversationID int64
|
||||
Limit int64
|
||||
BeforeID *string
|
||||
AfterID *string
|
||||
UserID int64
|
||||
AppID int64
|
||||
OrderBy *string
|
||||
}
|
||||
|
||||
type MessageListResponse struct {
|
||||
Messages []*WfMessage
|
||||
FirstID string
|
||||
LastID string
|
||||
HasMore bool
|
||||
}
|
||||
|
||||
type Content struct {
|
||||
Type message.InputType `json:"type"`
|
||||
Text *string `json:"text,omitempty"`
|
||||
Uri *string `json:"uri,omitempty"`
|
||||
Url *string `json:"url,omitempty"`
|
||||
}
|
||||
|
||||
type WfMessage struct {
|
||||
ID int64
|
||||
Role schema.RoleType `json:"role"` // user or assistant
|
||||
MultiContent []*Content `json:"multi_content"`
|
||||
Text *string `json:"text,omitempty"`
|
||||
ContentType string `json:"content_type"`
|
||||
SectionID int64 `json:"section_id"`
|
||||
}
|
||||
|
||||
type GetLatestRunIDsRequest struct {
|
||||
ConversationID int64
|
||||
UserID int64
|
||||
AppID int64
|
||||
Rounds int64
|
||||
SectionID int64
|
||||
InitRunID *int64
|
||||
}
|
||||
|
||||
type GetMessagesByRunIDsRequest struct {
|
||||
ConversationID int64
|
||||
RunIDs []int64
|
||||
}
|
||||
|
||||
type GetMessagesByRunIDsResponse struct {
|
||||
Messages []*WfMessage
|
||||
SchemaMessages []*schema.Message
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,224 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: message.go
|
||||
//
|
||||
// Generated by this command:
|
||||
//
|
||||
// mockgen -destination messagemock/message_mock.go --package messagemock -source message.go
|
||||
//
|
||||
|
||||
// Package messagemock is a generated GoMock package.
|
||||
package messagemock
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
message "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/message"
|
||||
message0 "github.com/coze-dev/coze-studio/backend/crossdomain/contract/message"
|
||||
entity "github.com/coze-dev/coze-studio/backend/domain/conversation/message/entity"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
// MockMessage is a mock of Message interface.
|
||||
type MockMessage struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockMessageMockRecorder
|
||||
isgomock struct{}
|
||||
}
|
||||
|
||||
// MockMessageMockRecorder is the mock recorder for MockMessage.
|
||||
type MockMessageMockRecorder struct {
|
||||
mock *MockMessage
|
||||
}
|
||||
|
||||
// NewMockMessage creates a new mock instance.
|
||||
func NewMockMessage(ctrl *gomock.Controller) *MockMessage {
|
||||
mock := &MockMessage{ctrl: ctrl}
|
||||
mock.recorder = &MockMessageMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockMessage) EXPECT() *MockMessageMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// Create mocks base method.
|
||||
func (m *MockMessage) Create(ctx context.Context, msg *message.Message) (*message.Message, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Create", ctx, msg)
|
||||
ret0, _ := ret[0].(*message.Message)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// Create indicates an expected call of Create.
|
||||
func (mr *MockMessageMockRecorder) Create(ctx, msg any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockMessage)(nil).Create), ctx, msg)
|
||||
}
|
||||
|
||||
// Delete mocks base method.
|
||||
func (m *MockMessage) Delete(ctx context.Context, req *entity.DeleteMeta) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Delete", ctx, req)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Delete indicates an expected call of Delete.
|
||||
func (mr *MockMessageMockRecorder) Delete(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockMessage)(nil).Delete), ctx, req)
|
||||
}
|
||||
|
||||
// Edit mocks base method.
|
||||
func (m *MockMessage) Edit(ctx context.Context, msg *message.Message) (*message.Message, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Edit", ctx, msg)
|
||||
ret0, _ := ret[0].(*message.Message)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// Edit indicates an expected call of Edit.
|
||||
func (mr *MockMessageMockRecorder) Edit(ctx, msg any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Edit", reflect.TypeOf((*MockMessage)(nil).Edit), ctx, msg)
|
||||
}
|
||||
|
||||
// GetByRunIDs mocks base method.
|
||||
func (m *MockMessage) GetByRunIDs(ctx context.Context, conversationID int64, runIDs []int64) ([]*message.Message, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetByRunIDs", ctx, conversationID, runIDs)
|
||||
ret0, _ := ret[0].([]*message.Message)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetByRunIDs indicates an expected call of GetByRunIDs.
|
||||
func (mr *MockMessageMockRecorder) GetByRunIDs(ctx, conversationID, runIDs any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetByRunIDs", reflect.TypeOf((*MockMessage)(nil).GetByRunIDs), ctx, conversationID, runIDs)
|
||||
}
|
||||
|
||||
// GetLatestRunIDs mocks base method.
|
||||
func (m *MockMessage) GetLatestRunIDs(ctx context.Context, req *message0.GetLatestRunIDsRequest) ([]int64, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetLatestRunIDs", ctx, req)
|
||||
ret0, _ := ret[0].([]int64)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetLatestRunIDs indicates an expected call of GetLatestRunIDs.
|
||||
func (mr *MockMessageMockRecorder) GetLatestRunIDs(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLatestRunIDs", reflect.TypeOf((*MockMessage)(nil).GetLatestRunIDs), ctx, req)
|
||||
}
|
||||
|
||||
// GetMessageByID mocks base method.
|
||||
func (m *MockMessage) GetMessageByID(ctx context.Context, id int64) (*entity.Message, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetMessageByID", ctx, id)
|
||||
ret0, _ := ret[0].(*entity.Message)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetMessageByID indicates an expected call of GetMessageByID.
|
||||
func (mr *MockMessageMockRecorder) GetMessageByID(ctx, id any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMessageByID", reflect.TypeOf((*MockMessage)(nil).GetMessageByID), ctx, id)
|
||||
}
|
||||
|
||||
// GetMessagesByRunIDs mocks base method.
|
||||
func (m *MockMessage) GetMessagesByRunIDs(ctx context.Context, req *message0.GetMessagesByRunIDsRequest) (*message0.GetMessagesByRunIDsResponse, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetMessagesByRunIDs", ctx, req)
|
||||
ret0, _ := ret[0].(*message0.GetMessagesByRunIDsResponse)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetMessagesByRunIDs indicates an expected call of GetMessagesByRunIDs.
|
||||
func (mr *MockMessageMockRecorder) GetMessagesByRunIDs(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMessagesByRunIDs", reflect.TypeOf((*MockMessage)(nil).GetMessagesByRunIDs), ctx, req)
|
||||
}
|
||||
|
||||
// List mocks base method.
|
||||
func (m *MockMessage) List(ctx context.Context, meta *entity.ListMeta) (*entity.ListResult, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "List", ctx, meta)
|
||||
ret0, _ := ret[0].(*entity.ListResult)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// List indicates an expected call of List.
|
||||
func (mr *MockMessageMockRecorder) List(ctx, meta any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockMessage)(nil).List), ctx, meta)
|
||||
}
|
||||
|
||||
// ListWithoutPair mocks base method.
|
||||
func (m *MockMessage) ListWithoutPair(ctx context.Context, req *entity.ListMeta) (*entity.ListResult, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ListWithoutPair", ctx, req)
|
||||
ret0, _ := ret[0].(*entity.ListResult)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// ListWithoutPair indicates an expected call of ListWithoutPair.
|
||||
func (mr *MockMessageMockRecorder) ListWithoutPair(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListWithoutPair", reflect.TypeOf((*MockMessage)(nil).ListWithoutPair), ctx, req)
|
||||
}
|
||||
|
||||
// MessageList mocks base method.
|
||||
func (m *MockMessage) MessageList(ctx context.Context, req *message0.MessageListRequest) (*message0.MessageListResponse, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "MessageList", ctx, req)
|
||||
ret0, _ := ret[0].(*message0.MessageListResponse)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// MessageList indicates an expected call of MessageList.
|
||||
func (mr *MockMessageMockRecorder) MessageList(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MessageList", reflect.TypeOf((*MockMessage)(nil).MessageList), ctx, req)
|
||||
}
|
||||
|
||||
// PreCreate mocks base method.
|
||||
func (m *MockMessage) PreCreate(ctx context.Context, msg *message.Message) (*message.Message, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "PreCreate", ctx, msg)
|
||||
ret0, _ := ret[0].(*message.Message)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// PreCreate indicates an expected call of PreCreate.
|
||||
func (mr *MockMessageMockRecorder) PreCreate(ctx, msg any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PreCreate", reflect.TypeOf((*MockMessage)(nil).PreCreate), ctx, msg)
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package crossupload
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/domain/upload/service"
|
||||
)
|
||||
|
||||
var defaultSVC Uploader
|
||||
|
||||
type Uploader interface {
|
||||
GetFile(ctx context.Context, req *service.GetFileRequest) (resp *service.GetFileResponse, err error)
|
||||
}
|
||||
|
||||
func SetDefaultSVC(s Uploader) {
|
||||
defaultSVC = s
|
||||
}
|
||||
|
||||
func DefaultSVC() Uploader {
|
||||
return defaultSVC
|
||||
}
|
||||
|
|
@ -38,19 +38,47 @@ type Workflow interface {
|
|||
allInterruptEvents map[string]*workflowEntity.ToolInterruptEvent) einoCompose.Option
|
||||
ReleaseApplicationWorkflows(ctx context.Context, appID int64, config *ReleaseWorkflowConfig) ([]*vo.ValidateIssue, error)
|
||||
GetWorkflowIDsByAppID(ctx context.Context, appID int64) ([]int64, error)
|
||||
|
||||
SyncExecuteWorkflow(ctx context.Context, config workflowModel.ExecuteConfig, input map[string]any) (*workflowEntity.WorkflowExecution, vo.TerminatePlan, error)
|
||||
StreamExecute(ctx context.Context, config workflowModel.ExecuteConfig, input map[string]any) (*schema.StreamReader[*workflowEntity.Message], error)
|
||||
WithExecuteConfig(cfg workflowModel.ExecuteConfig) einoCompose.Option
|
||||
WithMessagePipe() (compose.Option, *schema.StreamReader[*entity.Message])
|
||||
WithMessagePipe() (compose.Option, *schema.StreamReader[*entity.Message], func())
|
||||
StreamResume(ctx context.Context, req *entity.ResumeRequest, config workflowModel.ExecuteConfig) (*schema.StreamReader[*entity.Message], error)
|
||||
InitApplicationDefaultConversationTemplate(ctx context.Context, spaceID int64, appID int64, userID int64) error
|
||||
}
|
||||
|
||||
type ExecuteConfig = workflowModel.ExecuteConfig
|
||||
type ExecuteMode = workflowModel.ExecuteMode
|
||||
type NodeType = entity.NodeType
|
||||
|
||||
type WorkflowMessage = entity.Message
|
||||
type WorkflowMessage = workflowEntity.Message
|
||||
|
||||
type StateMessage = workflowEntity.StateMessage
|
||||
|
||||
type NodeType = entity.NodeType
|
||||
type MessageType = entity.MessageType
|
||||
type InterruptEvent = workflowEntity.InterruptEvent
|
||||
type EventType = workflowEntity.InterruptEventType
|
||||
type ResumeRequest = entity.ResumeRequest
|
||||
type WorkflowExecuteStatus = entity.WorkflowExecuteStatus
|
||||
|
||||
const (
|
||||
WorkflowRunning = WorkflowExecuteStatus(entity.WorkflowRunning)
|
||||
WorkflowSuccess = WorkflowExecuteStatus(entity.WorkflowSuccess)
|
||||
WorkflowFailed = WorkflowExecuteStatus(entity.WorkflowFailed)
|
||||
WorkflowCancel = WorkflowExecuteStatus(entity.WorkflowCancel)
|
||||
WorkflowInterrupted = WorkflowExecuteStatus(entity.WorkflowInterrupted)
|
||||
)
|
||||
|
||||
const (
|
||||
Answer MessageType = "answer"
|
||||
FunctionCall MessageType = "function_call"
|
||||
ToolResponse MessageType = "tool_response"
|
||||
)
|
||||
|
||||
const (
|
||||
NodeTypeOutputEmitter NodeType = "OutputEmitter"
|
||||
NodeTypeInputReceiver NodeType = "InputReceiver"
|
||||
NodeTypeQuestion NodeType = "QuestionAnswer"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -61,6 +89,14 @@ const (
|
|||
|
||||
type TaskType = workflowModel.TaskType
|
||||
|
||||
type SyncPattern = workflowModel.SyncPattern
|
||||
|
||||
const (
|
||||
SyncPatternSync SyncPattern = "sync"
|
||||
SyncPatternAsync SyncPattern = "async"
|
||||
SyncPatternStream SyncPattern = "stream"
|
||||
)
|
||||
|
||||
const (
|
||||
TaskTypeForeground TaskType = "foreground"
|
||||
TaskTypeBackground TaskType = "background"
|
||||
|
|
@ -73,6 +109,14 @@ const (
|
|||
BizTypeWorkflow BizType = "workflow"
|
||||
)
|
||||
|
||||
type Locator = workflowModel.Locator
|
||||
|
||||
const (
|
||||
FromDraft Locator = iota
|
||||
FromSpecificVersion
|
||||
FromLatestVersion
|
||||
)
|
||||
|
||||
type ReleaseWorkflowConfig = vo.ReleaseWorkflowConfig
|
||||
|
||||
type ToolInterruptEvent = workflowEntity.ToolInterruptEvent
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import (
|
|||
"context"
|
||||
|
||||
crossagentrun "github.com/coze-dev/coze-studio/backend/crossdomain/contract/agentrun"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/entity"
|
||||
agentrun "github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/service"
|
||||
)
|
||||
|
||||
|
|
@ -44,3 +45,11 @@ func InitDomainService(c agentrun.Run) crossagentrun.AgentRun {
|
|||
func (c *impl) Delete(ctx context.Context, runID []int64) error {
|
||||
return c.DomainSVC.Delete(ctx, runID)
|
||||
}
|
||||
|
||||
func (c *impl) List(ctx context.Context, meta *entity.ListRunRecordMeta) ([]*entity.RunRecordMeta, error) {
|
||||
return c.DomainSVC.List(ctx, meta)
|
||||
}
|
||||
|
||||
func (c *impl) Create(ctx context.Context, meta *entity.AgentRunMeta) (*entity.RunRecordMeta, error) {
|
||||
return c.DomainSVC.Create(ctx, meta)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import (
|
|||
|
||||
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/conversation"
|
||||
crossconversation "github.com/coze-dev/coze-studio/backend/crossdomain/contract/conversation"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/conversation/entity"
|
||||
conversation "github.com/coze-dev/coze-studio/backend/domain/conversation/conversation/service"
|
||||
)
|
||||
|
||||
|
|
@ -37,6 +38,20 @@ func InitDomainService(c conversation.Conversation) crossconversation.Conversati
|
|||
return defaultSVC
|
||||
}
|
||||
|
||||
func (s *impl) CreateConversation(ctx context.Context, req *entity.CreateMeta) (*entity.Conversation, error) {
|
||||
return s.DomainSVC.Create(ctx, req)
|
||||
}
|
||||
|
||||
func (s *impl) ClearConversationHistory(ctx context.Context, req *crossconversation.ClearConversationHistoryReq) (*entity.NewConversationCtxResponse, error) {
|
||||
return s.DomainSVC.NewConversationCtx(ctx, &entity.NewConversationCtxRequest{
|
||||
ID: req.ConversationID,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *impl) GetCurrentConversation(ctx context.Context, req *model.GetCurrent) (*model.Conversation, error) {
|
||||
return s.DomainSVC.GetCurrentConversation(ctx, req)
|
||||
}
|
||||
|
||||
func (s *impl) GetByID(ctx context.Context, id int64) (*entity.Conversation, error) {
|
||||
return s.DomainSVC.GetByID(ctx, id)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,9 +18,19 @@ package message
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/cloudwego/eino/schema"
|
||||
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/message"
|
||||
crossagentrun "github.com/coze-dev/coze-studio/backend/crossdomain/contract/agentrun"
|
||||
crossmessage "github.com/coze-dev/coze-studio/backend/crossdomain/contract/message"
|
||||
agententity "github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/message/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/sonic"
|
||||
|
||||
message "github.com/coze-dev/coze-studio/backend/domain/conversation/message/service"
|
||||
)
|
||||
|
||||
|
|
@ -38,6 +48,96 @@ func InitDomainService(c message.Message) crossmessage.Message {
|
|||
return defaultSVC
|
||||
}
|
||||
|
||||
func (c *impl) MessageList(ctx context.Context, req *crossmessage.MessageListRequest) (*crossmessage.MessageListResponse, error) {
|
||||
lm := &entity.ListMeta{
|
||||
ConversationID: req.ConversationID,
|
||||
Limit: int(req.Limit), // Since the value of limit is checked inside the node, the type cast here is safe
|
||||
UserID: strconv.FormatInt(req.UserID, 10),
|
||||
AgentID: req.AppID,
|
||||
OrderBy: req.OrderBy,
|
||||
}
|
||||
if req.BeforeID != nil {
|
||||
lm.Cursor, _ = strconv.ParseInt(*req.BeforeID, 10, 64)
|
||||
lm.Direction = entity.ScrollPageDirectionNext
|
||||
}
|
||||
if req.AfterID != nil {
|
||||
lm.Cursor, _ = strconv.ParseInt(*req.AfterID, 10, 64)
|
||||
lm.Direction = entity.ScrollPageDirectionPrev
|
||||
}
|
||||
lm.MessageType = []*model.MessageType{ptr.Of(model.MessageTypeQuestion), ptr.Of(model.MessageTypeAnswer)}
|
||||
|
||||
lr, err := c.DomainSVC.ListWithoutPair(ctx, lm)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response := &crossmessage.MessageListResponse{
|
||||
HasMore: lr.HasMore,
|
||||
}
|
||||
|
||||
if lr.PrevCursor > 0 {
|
||||
response.FirstID = strconv.FormatInt(lr.PrevCursor, 10)
|
||||
}
|
||||
if lr.NextCursor > 0 {
|
||||
response.LastID = strconv.FormatInt(lr.NextCursor, 10)
|
||||
}
|
||||
if len(lr.Messages) == 0 {
|
||||
return response, nil
|
||||
}
|
||||
messages, _, err := convertToConvAndSchemaMessage(ctx, lr.Messages)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response.Messages = messages
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *impl) GetLatestRunIDs(ctx context.Context, req *crossmessage.GetLatestRunIDsRequest) ([]int64, error) {
|
||||
listMeta := &agententity.ListRunRecordMeta{
|
||||
ConversationID: req.ConversationID,
|
||||
AgentID: req.AppID,
|
||||
Limit: int32(req.Rounds),
|
||||
SectionID: req.SectionID,
|
||||
}
|
||||
|
||||
if req.InitRunID != nil {
|
||||
listMeta.BeforeID = *req.InitRunID
|
||||
}
|
||||
|
||||
runRecords, err := crossagentrun.DefaultSVC().List(ctx, listMeta)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
runIDs := make([]int64, 0, len(runRecords))
|
||||
for _, record := range runRecords {
|
||||
runIDs = append(runIDs, record.ID)
|
||||
}
|
||||
return runIDs, nil
|
||||
}
|
||||
|
||||
func (c *impl) GetMessagesByRunIDs(ctx context.Context, req *crossmessage.GetMessagesByRunIDsRequest) (*crossmessage.GetMessagesByRunIDsResponse, error) {
|
||||
responseMessages, err := c.DomainSVC.GetByRunIDs(ctx, req.ConversationID, req.RunIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// only returns messages of type user/assistant/system role type
|
||||
messages := make([]*model.Message, 0, len(responseMessages))
|
||||
for _, m := range responseMessages {
|
||||
if m.Role == schema.User || m.Role == schema.System || m.Role == schema.Assistant {
|
||||
messages = append(messages, m)
|
||||
}
|
||||
}
|
||||
|
||||
convMessages, scMessages, err := convertToConvAndSchemaMessage(ctx, messages)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &crossmessage.GetMessagesByRunIDsResponse{
|
||||
Messages: convMessages,
|
||||
SchemaMessages: scMessages,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *impl) GetByRunIDs(ctx context.Context, conversationID int64, runIDs []int64) ([]*model.Message, error) {
|
||||
return c.DomainSVC.GetByRunIDs(ctx, conversationID, runIDs)
|
||||
}
|
||||
|
|
@ -53,3 +153,115 @@ func (c *impl) Edit(ctx context.Context, msg *model.Message) (*model.Message, er
|
|||
func (c *impl) PreCreate(ctx context.Context, msg *model.Message) (*model.Message, error) {
|
||||
return c.DomainSVC.PreCreate(ctx, msg)
|
||||
}
|
||||
|
||||
func (c *impl) List(ctx context.Context, lm *entity.ListMeta) (*entity.ListResult, error) {
|
||||
return c.DomainSVC.List(ctx, lm)
|
||||
}
|
||||
|
||||
func (c *impl) Delete(ctx context.Context, req *entity.DeleteMeta) error {
|
||||
return c.DomainSVC.Delete(ctx, req)
|
||||
}
|
||||
|
||||
func (c *impl) GetMessageByID(ctx context.Context, id int64) (*entity.Message, error) {
|
||||
return c.DomainSVC.GetByID(ctx, id)
|
||||
}
|
||||
|
||||
func (c *impl) ListWithoutPair(ctx context.Context, req *entity.ListMeta) (*entity.ListResult, error) {
|
||||
return c.DomainSVC.ListWithoutPair(ctx, req)
|
||||
}
|
||||
|
||||
func convertToConvAndSchemaMessage(ctx context.Context, msgs []*entity.Message) ([]*crossmessage.WfMessage, []*schema.Message, error) {
|
||||
messages := make([]*schema.Message, 0)
|
||||
convMessages := make([]*crossmessage.WfMessage, 0)
|
||||
for _, m := range msgs {
|
||||
msg := &schema.Message{}
|
||||
err := sonic.UnmarshalString(m.ModelContent, msg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
msg.Role = m.Role
|
||||
|
||||
covMsg := &crossmessage.WfMessage{
|
||||
ID: m.ID,
|
||||
Role: m.Role,
|
||||
ContentType: string(m.ContentType),
|
||||
SectionID: m.SectionID,
|
||||
}
|
||||
|
||||
if len(msg.MultiContent) == 0 {
|
||||
covMsg.Text = ptr.Of(msg.Content)
|
||||
} else {
|
||||
covMsg.MultiContent = make([]*crossmessage.Content, 0, len(msg.MultiContent))
|
||||
for _, part := range msg.MultiContent {
|
||||
switch part.Type {
|
||||
case schema.ChatMessagePartTypeText:
|
||||
covMsg.MultiContent = append(covMsg.MultiContent, &crossmessage.Content{
|
||||
Type: model.InputTypeText,
|
||||
Text: ptr.Of(part.Text),
|
||||
})
|
||||
|
||||
case schema.ChatMessagePartTypeImageURL:
|
||||
if part.ImageURL != nil {
|
||||
part.ImageURL.URL, err = workflow.GetRepository().GetObjectUrl(ctx, part.ImageURL.URI)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
covMsg.MultiContent = append(covMsg.MultiContent, &crossmessage.Content{
|
||||
Uri: ptr.Of(part.ImageURL.URI),
|
||||
Type: model.InputTypeImage,
|
||||
Url: ptr.Of(part.ImageURL.URL),
|
||||
})
|
||||
}
|
||||
|
||||
case schema.ChatMessagePartTypeFileURL:
|
||||
|
||||
if part.FileURL != nil {
|
||||
part.FileURL.URL, err = workflow.GetRepository().GetObjectUrl(ctx, part.FileURL.URI)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
covMsg.MultiContent = append(covMsg.MultiContent, &crossmessage.Content{
|
||||
Uri: ptr.Of(part.FileURL.URI),
|
||||
Type: model.InputTypeFile,
|
||||
Url: ptr.Of(part.FileURL.URL),
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
case schema.ChatMessagePartTypeAudioURL:
|
||||
if part.AudioURL != nil {
|
||||
part.AudioURL.URL, err = workflow.GetRepository().GetObjectUrl(ctx, part.AudioURL.URI)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
covMsg.MultiContent = append(covMsg.MultiContent, &crossmessage.Content{
|
||||
Uri: ptr.Of(part.AudioURL.URI),
|
||||
Type: model.InputTypeAudio,
|
||||
Url: ptr.Of(part.AudioURL.URL),
|
||||
})
|
||||
|
||||
}
|
||||
case schema.ChatMessagePartTypeVideoURL:
|
||||
if part.VideoURL != nil {
|
||||
part.VideoURL.URL, err = workflow.GetRepository().GetObjectUrl(ctx, part.VideoURL.URI)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
covMsg.MultiContent = append(covMsg.MultiContent, &crossmessage.Content{
|
||||
Uri: ptr.Of(part.VideoURL.URI),
|
||||
Type: model.InputTypeVideo,
|
||||
Url: ptr.Of(part.VideoURL.URL),
|
||||
})
|
||||
}
|
||||
default:
|
||||
return nil, nil, fmt.Errorf("unknown part type: %s", part.Type)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
messages = append(messages, msg)
|
||||
convMessages = append(convMessages, covMsg)
|
||||
}
|
||||
return convMessages, messages, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,362 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package message
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/cloudwego/eino/schema"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/message"
|
||||
crossmessage "github.com/coze-dev/coze-studio/backend/crossdomain/contract/message"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/message/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/storage"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/sonic"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type mockWorkflowRepo struct {
|
||||
workflow.Repository
|
||||
}
|
||||
|
||||
func (m *mockWorkflowRepo) GetObjectUrl(ctx context.Context, uri string, opts ...storage.GetOptFn) (string, error) {
|
||||
return uri, nil
|
||||
}
|
||||
|
||||
func Test_convertToConvAndSchemaMessage(t *testing.T) {
|
||||
workflow.SetRepository(&mockWorkflowRepo{})
|
||||
|
||||
sm1, err := sonic.MarshalString(&schema.Message{Content: "hello"})
|
||||
require.NoError(t, err)
|
||||
|
||||
sm2, err := sonic.MarshalString(&schema.Message{MultiContent: []schema.ChatMessagePart{{Type: schema.ChatMessagePartTypeFileURL, FileURL: &schema.ChatMessageFileURL{URI: "f_uri_1"}}}})
|
||||
require.NoError(t, err)
|
||||
|
||||
sm3, err := sonic.MarshalString(&schema.Message{MultiContent: []schema.ChatMessagePart{{Type: schema.ChatMessagePartTypeText, Text: "hello"}, {Type: schema.ChatMessagePartTypeFileURL, FileURL: &schema.ChatMessageFileURL{URI: "f_uri_2"}}}})
|
||||
require.NoError(t, err)
|
||||
|
||||
sm4, err := sonic.MarshalString(&schema.Message{MultiContent: []schema.ChatMessagePart{{Type: schema.ChatMessagePartTypeFileURL, FileURL: &schema.ChatMessageFileURL{URI: "f_uri_3"}}, {Type: schema.ChatMessagePartTypeFileURL, FileURL: &schema.ChatMessageFileURL{URI: "f_uri_4"}}}})
|
||||
require.NoError(t, err)
|
||||
|
||||
sm5, err := sonic.MarshalString(&schema.Message{Content: ""})
|
||||
require.NoError(t, err)
|
||||
|
||||
sm6, err := sonic.MarshalString(&schema.Message{MultiContent: []schema.ChatMessagePart{{Type: schema.ChatMessagePartTypeImageURL, ImageURL: &schema.ChatMessageImageURL{URI: "image_uri_5"}}}})
|
||||
require.NoError(t, err)
|
||||
|
||||
sm7, err := sonic.MarshalString(&schema.Message{MultiContent: []schema.ChatMessagePart{{Type: schema.ChatMessagePartTypeImageURL, ImageURL: &schema.ChatMessageImageURL{URI: "file_id_6"}}, {Type: schema.ChatMessagePartTypeImageURL, ImageURL: &schema.ChatMessageImageURL{URI: "file_id_7"}}}})
|
||||
require.NoError(t, err)
|
||||
|
||||
sm8, err := sonic.MarshalString(&schema.Message{MultiContent: []schema.ChatMessagePart{{Type: schema.ChatMessagePartTypeText, Text: "hello"}, {Type: schema.ChatMessagePartTypeImageURL, ImageURL: &schema.ChatMessageImageURL{URI: "file_id_8"}}, {Type: schema.ChatMessagePartTypeFileURL, FileURL: &schema.ChatMessageFileURL{URI: "file_id_9"}}}})
|
||||
require.NoError(t, err)
|
||||
|
||||
type args struct {
|
||||
msgs []*entity.Message
|
||||
}
|
||||
type want struct {
|
||||
convMsgs []*crossmessage.WfMessage
|
||||
schemaMsgs []*schema.Message
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want want
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "pure text",
|
||||
args: args{
|
||||
msgs: []*entity.Message{
|
||||
{
|
||||
ID: 1,
|
||||
Role: schema.User,
|
||||
ContentType: "text",
|
||||
ModelContent: sm1,
|
||||
},
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
convMsgs: []*crossmessage.WfMessage{
|
||||
{
|
||||
ID: 1,
|
||||
Role: schema.User,
|
||||
ContentType: "text",
|
||||
Text: ptr.Of("hello"),
|
||||
},
|
||||
},
|
||||
schemaMsgs: []*schema.Message{
|
||||
{
|
||||
Role: schema.User,
|
||||
Content: "hello",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "pure file",
|
||||
args: args{
|
||||
msgs: []*entity.Message{
|
||||
{
|
||||
ID: 2,
|
||||
Role: schema.User,
|
||||
ContentType: "file",
|
||||
ModelContent: sm2,
|
||||
},
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
convMsgs: []*crossmessage.WfMessage{
|
||||
{
|
||||
ID: 2,
|
||||
Role: schema.User,
|
||||
ContentType: "file",
|
||||
MultiContent: []*crossmessage.Content{
|
||||
{Type: message.InputTypeFile, Uri: ptr.Of("f_uri_1"), Url: ptr.Of("f_uri_1")},
|
||||
},
|
||||
},
|
||||
},
|
||||
schemaMsgs: []*schema.Message{
|
||||
{
|
||||
Role: schema.User,
|
||||
MultiContent: []schema.ChatMessagePart{
|
||||
{Type: schema.ChatMessagePartTypeFileURL, FileURL: &schema.ChatMessageFileURL{URI: "f_uri_1", URL: "f_uri_1"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "text and file",
|
||||
args: args{
|
||||
msgs: []*entity.Message{
|
||||
{
|
||||
ID: 3,
|
||||
Role: schema.User,
|
||||
ContentType: "text_file",
|
||||
ModelContent: sm3,
|
||||
},
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
convMsgs: []*crossmessage.WfMessage{
|
||||
{
|
||||
ID: 3,
|
||||
Role: schema.User,
|
||||
ContentType: "text_file",
|
||||
MultiContent: []*crossmessage.Content{
|
||||
{Type: message.InputTypeText, Text: ptr.Of("hello")},
|
||||
{Type: message.InputTypeFile, Uri: ptr.Of("f_uri_2"), Url: ptr.Of("f_uri_2")},
|
||||
},
|
||||
},
|
||||
},
|
||||
schemaMsgs: []*schema.Message{
|
||||
{
|
||||
Role: schema.User,
|
||||
MultiContent: []schema.ChatMessagePart{
|
||||
{Type: schema.ChatMessagePartTypeText, Text: "hello"},
|
||||
{Type: schema.ChatMessagePartTypeFileURL, FileURL: &schema.ChatMessageFileURL{URI: "f_uri_2", URL: "f_uri_2"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "multiple files",
|
||||
args: args{
|
||||
msgs: []*entity.Message{
|
||||
{
|
||||
ID: 4,
|
||||
Role: schema.User,
|
||||
ContentType: "file",
|
||||
ModelContent: sm4,
|
||||
},
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
convMsgs: []*crossmessage.WfMessage{
|
||||
{
|
||||
ID: 4,
|
||||
Role: schema.User,
|
||||
ContentType: "file",
|
||||
MultiContent: []*crossmessage.Content{
|
||||
{Type: message.InputTypeFile, Uri: ptr.Of("f_uri_3"), Url: ptr.Of("f_uri_3")},
|
||||
{Type: message.InputTypeFile, Uri: ptr.Of("f_uri_4"), Url: ptr.Of("f_uri_4")},
|
||||
},
|
||||
},
|
||||
},
|
||||
schemaMsgs: []*schema.Message{
|
||||
{
|
||||
Role: schema.User,
|
||||
MultiContent: []schema.ChatMessagePart{
|
||||
{Type: schema.ChatMessagePartTypeFileURL, FileURL: &schema.ChatMessageFileURL{URI: "f_uri_3", URL: "f_uri_3"}},
|
||||
{Type: schema.ChatMessagePartTypeFileURL, FileURL: &schema.ChatMessageFileURL{URI: "f_uri_4", URL: "f_uri_4"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty text",
|
||||
args: args{
|
||||
msgs: []*entity.Message{
|
||||
{
|
||||
ID: 5,
|
||||
Role: schema.User,
|
||||
ContentType: "text",
|
||||
ModelContent: sm5,
|
||||
},
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
convMsgs: []*crossmessage.WfMessage{
|
||||
{
|
||||
ID: 5,
|
||||
Role: schema.User,
|
||||
ContentType: "text",
|
||||
Text: ptr.Of(""),
|
||||
},
|
||||
},
|
||||
schemaMsgs: []*schema.Message{
|
||||
{
|
||||
Role: schema.User,
|
||||
Content: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "pure image",
|
||||
args: args{
|
||||
msgs: []*entity.Message{
|
||||
{
|
||||
ID: 6,
|
||||
Role: schema.User,
|
||||
ContentType: "image",
|
||||
ModelContent: sm6,
|
||||
},
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
convMsgs: []*crossmessage.WfMessage{
|
||||
{
|
||||
ID: 6,
|
||||
Role: schema.User,
|
||||
ContentType: "image",
|
||||
MultiContent: []*crossmessage.Content{
|
||||
{Type: message.InputTypeImage, Uri: ptr.Of("image_uri_5"), Url: ptr.Of("image_uri_5")},
|
||||
},
|
||||
},
|
||||
},
|
||||
schemaMsgs: []*schema.Message{
|
||||
{
|
||||
Role: schema.User,
|
||||
MultiContent: []schema.ChatMessagePart{
|
||||
{Type: schema.ChatMessagePartTypeImageURL, ImageURL: &schema.ChatMessageImageURL{URI: "image_uri_5", URL: "image_uri_5"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "multiple images",
|
||||
args: args{
|
||||
msgs: []*entity.Message{
|
||||
{
|
||||
ID: 7,
|
||||
Role: schema.User,
|
||||
ContentType: "image",
|
||||
ModelContent: sm7,
|
||||
},
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
convMsgs: []*crossmessage.WfMessage{
|
||||
{
|
||||
ID: 7,
|
||||
Role: schema.User,
|
||||
ContentType: "image",
|
||||
MultiContent: []*crossmessage.Content{
|
||||
{Type: message.InputTypeImage, Uri: ptr.Of("file_id_6"), Url: ptr.Of("file_id_6")},
|
||||
{Type: message.InputTypeImage, Uri: ptr.Of("file_id_7"), Url: ptr.Of("file_id_7")},
|
||||
},
|
||||
},
|
||||
},
|
||||
schemaMsgs: []*schema.Message{
|
||||
{
|
||||
Role: schema.User,
|
||||
MultiContent: []schema.ChatMessagePart{
|
||||
{Type: schema.ChatMessagePartTypeImageURL, ImageURL: &schema.ChatMessageImageURL{URI: "file_id_6", URL: "file_id_6"}},
|
||||
{Type: schema.ChatMessagePartTypeImageURL, ImageURL: &schema.ChatMessageImageURL{URI: "file_id_7", URL: "file_id_7"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "mixed content",
|
||||
args: args{
|
||||
msgs: []*entity.Message{
|
||||
{
|
||||
ID: 8,
|
||||
Role: schema.User,
|
||||
ContentType: "mix",
|
||||
ModelContent: sm8,
|
||||
},
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
convMsgs: []*crossmessage.WfMessage{
|
||||
{
|
||||
ID: 8,
|
||||
Role: schema.User,
|
||||
ContentType: "mix",
|
||||
MultiContent: []*crossmessage.Content{
|
||||
{Type: message.InputTypeText, Text: ptr.Of("hello")},
|
||||
{Type: message.InputTypeImage, Uri: ptr.Of("file_id_8"), Url: ptr.Of("file_id_8")},
|
||||
{Type: message.InputTypeFile, Uri: ptr.Of("file_id_9"), Url: ptr.Of("file_id_9")},
|
||||
},
|
||||
},
|
||||
},
|
||||
schemaMsgs: []*schema.Message{
|
||||
{
|
||||
Role: schema.User,
|
||||
MultiContent: []schema.ChatMessagePart{
|
||||
{Type: schema.ChatMessagePartTypeText, Text: "hello"},
|
||||
{Type: schema.ChatMessagePartTypeImageURL, ImageURL: &schema.ChatMessageImageURL{URI: "file_id_8", URL: "file_id_8"}},
|
||||
{Type: schema.ChatMessagePartTypeFileURL, FileURL: &schema.ChatMessageFileURL{URI: "file_id_9", URL: "file_id_9"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
convMsgs, schemaMsgs, err := convertToConvAndSchemaMessage(context.Background(), tt.args.msgs)
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err)
|
||||
return
|
||||
}
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tt.want.convMsgs, convMsgs)
|
||||
assert.Equal(t, tt.want.schemaMsgs, schemaMsgs)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -18,17 +18,13 @@ package agent
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/cloudwego/eino/schema"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/agentrun"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/message"
|
||||
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/singleagent"
|
||||
crossagent "github.com/coze-dev/coze-studio/backend/crossdomain/contract/agent"
|
||||
singleagent "github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/service"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/message/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/imagex"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/conv"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/slices"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/logs"
|
||||
|
|
@ -38,49 +34,34 @@ var defaultSVC crossagent.SingleAgent
|
|||
|
||||
type impl struct {
|
||||
DomainSVC singleagent.SingleAgent
|
||||
ImagexSVC imagex.ImageX
|
||||
}
|
||||
|
||||
func InitDomainService(c singleagent.SingleAgent, imagexClient imagex.ImageX) crossagent.SingleAgent {
|
||||
func InitDomainService(c singleagent.SingleAgent) crossagent.SingleAgent {
|
||||
defaultSVC = &impl{
|
||||
DomainSVC: c,
|
||||
ImagexSVC: imagexClient,
|
||||
}
|
||||
|
||||
return defaultSVC
|
||||
}
|
||||
|
||||
func (c *impl) StreamExecute(ctx context.Context, historyMsg []*message.Message,
|
||||
query *message.Message, agentRuntime *model.AgentRuntime,
|
||||
func (c *impl) StreamExecute(ctx context.Context, agentRuntime *crossagent.AgentRuntime,
|
||||
) (*schema.StreamReader[*model.AgentEvent], error) {
|
||||
|
||||
historyMsg = c.historyPairs(historyMsg)
|
||||
|
||||
singleAgentStreamExecReq := c.buildSingleAgentStreamExecuteReq(ctx, historyMsg, query, agentRuntime)
|
||||
singleAgentStreamExecReq := c.buildSingleAgentStreamExecuteReq(ctx, agentRuntime)
|
||||
|
||||
streamEvent, err := c.DomainSVC.StreamExecute(ctx, singleAgentStreamExecReq)
|
||||
logs.CtxInfof(ctx, "agent StreamExecute req:%v, streamEvent:%v, err:%v", conv.DebugJsonToStr(singleAgentStreamExecReq), streamEvent, err)
|
||||
return streamEvent, err
|
||||
}
|
||||
|
||||
func (c *impl) buildSingleAgentStreamExecuteReq(ctx context.Context, historyMsg []*message.Message,
|
||||
input *message.Message, agentRuntime *model.AgentRuntime,
|
||||
func (c *impl) buildSingleAgentStreamExecuteReq(ctx context.Context, agentRuntime *crossagent.AgentRuntime,
|
||||
) *model.ExecuteRequest {
|
||||
identity := c.buildIdentity(input, agentRuntime)
|
||||
inputBuild := c.buildSchemaMessage(ctx, []*message.Message{input})
|
||||
var inputSM *schema.Message
|
||||
if len(inputBuild) > 0 {
|
||||
inputSM = inputBuild[0]
|
||||
}
|
||||
history := c.buildSchemaMessage(ctx, historyMsg)
|
||||
|
||||
resumeInfo := c.checkResumeInfo(ctx, historyMsg)
|
||||
|
||||
return &model.ExecuteRequest{
|
||||
Identity: identity,
|
||||
Input: inputSM,
|
||||
History: history,
|
||||
UserID: input.UserID,
|
||||
Identity: c.buildIdentity(agentRuntime),
|
||||
Input: agentRuntime.Input,
|
||||
History: agentRuntime.HistoryMsg,
|
||||
UserID: agentRuntime.UserID,
|
||||
PreCallTools: slices.Transform(agentRuntime.PreRetrieveTools, func(tool *agentrun.Tool) *agentrun.ToolsRetriever {
|
||||
return &agentrun.ToolsRetriever{
|
||||
PluginID: tool.PluginID,
|
||||
|
|
@ -98,141 +79,19 @@ func (c *impl) buildSingleAgentStreamExecuteReq(ctx context.Context, historyMsg
|
|||
}(tool.Type),
|
||||
}
|
||||
}),
|
||||
|
||||
ResumeInfo: resumeInfo,
|
||||
ResumeInfo: agentRuntime.ResumeInfo,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *impl) historyPairs(historyMsg []*message.Message) []*message.Message {
|
||||
|
||||
fcMsgPairs := make(map[int64][]*message.Message)
|
||||
for _, one := range historyMsg {
|
||||
if one.MessageType != message.MessageTypeFunctionCall && one.MessageType != message.MessageTypeToolResponse {
|
||||
continue
|
||||
}
|
||||
if _, ok := fcMsgPairs[one.RunID]; !ok {
|
||||
fcMsgPairs[one.RunID] = []*message.Message{one}
|
||||
} else {
|
||||
fcMsgPairs[one.RunID] = append(fcMsgPairs[one.RunID], one)
|
||||
}
|
||||
}
|
||||
|
||||
var historyAfterPairs []*message.Message
|
||||
for _, value := range historyMsg {
|
||||
if value.MessageType == message.MessageTypeFunctionCall {
|
||||
if len(fcMsgPairs[value.RunID])%2 == 0 {
|
||||
historyAfterPairs = append(historyAfterPairs, value)
|
||||
}
|
||||
} else {
|
||||
historyAfterPairs = append(historyAfterPairs, value)
|
||||
}
|
||||
}
|
||||
return historyAfterPairs
|
||||
|
||||
}
|
||||
func (c *impl) checkResumeInfo(_ context.Context, historyMsg []*message.Message) *crossagent.ResumeInfo {
|
||||
|
||||
var resumeInfo *crossagent.ResumeInfo
|
||||
for i := len(historyMsg) - 1; i >= 0; i-- {
|
||||
if historyMsg[i].MessageType == message.MessageTypeQuestion {
|
||||
break
|
||||
}
|
||||
if historyMsg[i].MessageType == message.MessageTypeVerbose {
|
||||
if historyMsg[i].Ext[string(entity.ExtKeyResumeInfo)] != "" {
|
||||
err := json.Unmarshal([]byte(historyMsg[i].Ext[string(entity.ExtKeyResumeInfo)]), &resumeInfo)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resumeInfo
|
||||
}
|
||||
|
||||
func (c *impl) buildSchemaMessage(ctx context.Context, msgs []*message.Message) []*schema.Message {
|
||||
schemaMessage := make([]*schema.Message, 0, len(msgs))
|
||||
|
||||
for _, msgOne := range msgs {
|
||||
if msgOne.ModelContent == "" {
|
||||
continue
|
||||
}
|
||||
if msgOne.MessageType == message.MessageTypeVerbose || msgOne.MessageType == message.MessageTypeFlowUp {
|
||||
continue
|
||||
}
|
||||
var sm *schema.Message
|
||||
err := json.Unmarshal([]byte(msgOne.ModelContent), &sm)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if len(sm.ReasoningContent) > 0 {
|
||||
sm.ReasoningContent = ""
|
||||
}
|
||||
|
||||
schemaMessage = append(schemaMessage, c.parseMessageURI(ctx, sm))
|
||||
}
|
||||
|
||||
return schemaMessage
|
||||
}
|
||||
|
||||
func (c *impl) parseMessageURI(ctx context.Context, mcMsg *schema.Message) *schema.Message {
|
||||
if mcMsg.MultiContent == nil {
|
||||
return mcMsg
|
||||
}
|
||||
for k, one := range mcMsg.MultiContent {
|
||||
switch one.Type {
|
||||
case schema.ChatMessagePartTypeImageURL:
|
||||
|
||||
if one.ImageURL.URI != "" {
|
||||
url, err := c.ImagexSVC.GetResourceURL(ctx, one.ImageURL.URI)
|
||||
if err == nil {
|
||||
mcMsg.MultiContent[k].ImageURL.URL = url.URL
|
||||
}
|
||||
}
|
||||
case schema.ChatMessagePartTypeFileURL:
|
||||
if one.FileURL.URI != "" {
|
||||
url, err := c.ImagexSVC.GetResourceURL(ctx, one.FileURL.URI)
|
||||
if err == nil {
|
||||
mcMsg.MultiContent[k].FileURL.URL = url.URL
|
||||
}
|
||||
}
|
||||
case schema.ChatMessagePartTypeAudioURL:
|
||||
if one.AudioURL.URI != "" {
|
||||
url, err := c.ImagexSVC.GetResourceURL(ctx, one.AudioURL.URI)
|
||||
if err == nil {
|
||||
mcMsg.MultiContent[k].AudioURL.URL = url.URL
|
||||
}
|
||||
}
|
||||
case schema.ChatMessagePartTypeVideoURL:
|
||||
if one.VideoURL.URI != "" {
|
||||
url, err := c.ImagexSVC.GetResourceURL(ctx, one.VideoURL.URI)
|
||||
if err == nil {
|
||||
mcMsg.MultiContent[k].VideoURL.URL = url.URL
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return mcMsg
|
||||
}
|
||||
|
||||
func (c *impl) buildIdentity(input *message.Message, agentRuntime *model.AgentRuntime) *model.AgentIdentity {
|
||||
func (c *impl) buildIdentity(agentRuntime *crossagent.AgentRuntime) *model.AgentIdentity {
|
||||
return &model.AgentIdentity{
|
||||
AgentID: input.AgentID,
|
||||
AgentID: agentRuntime.AgentID,
|
||||
Version: agentRuntime.AgentVersion,
|
||||
IsDraft: agentRuntime.IsDraft,
|
||||
ConnectorID: agentRuntime.ConnectorID,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *impl) GetSingleAgent(ctx context.Context, agentID int64, version string) (agent *model.SingleAgent, err error) {
|
||||
agentInfo, err := c.DomainSVC.GetSingleAgent(ctx, agentID, version)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return agentInfo.SingleAgent, nil
|
||||
}
|
||||
|
||||
func (c *impl) ObtainAgentByIdentity(ctx context.Context, identity *model.AgentIdentity) (*model.SingleAgent, error) {
|
||||
agentInfo, err := c.DomainSVC.ObtainAgentByIdentity(ctx, identity)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package upload
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
crossupload "github.com/coze-dev/coze-studio/backend/crossdomain/contract/upload"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/upload/service"
|
||||
)
|
||||
|
||||
var defaultSVC crossupload.Uploader
|
||||
|
||||
type impl struct {
|
||||
DomainSVC service.UploadService
|
||||
}
|
||||
|
||||
func InitDomainService(c service.UploadService) crossupload.Uploader {
|
||||
defaultSVC = &impl{
|
||||
DomainSVC: c,
|
||||
}
|
||||
|
||||
return defaultSVC
|
||||
}
|
||||
|
||||
func (c *impl) GetFile(ctx context.Context, req *service.GetFileRequest) (resp *service.GetFileResponse, err error) {
|
||||
return c.DomainSVC.GetFile(ctx, req)
|
||||
}
|
||||
|
|
@ -18,7 +18,6 @@ package workflow
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cloudwego/eino/compose"
|
||||
einoCompose "github.com/cloudwego/eino/compose"
|
||||
"github.com/cloudwego/eino/schema"
|
||||
|
|
@ -66,7 +65,18 @@ func (i *impl) WithExecuteConfig(cfg workflowModel.ExecuteConfig) einoCompose.Op
|
|||
return i.DomainSVC.WithExecuteConfig(cfg)
|
||||
}
|
||||
|
||||
func (i *impl) WithMessagePipe() (compose.Option, *schema.StreamReader[*entity.Message]) {
|
||||
func (i *impl) StreamResume(ctx context.Context, req *entity.ResumeRequest, config workflowModel.ExecuteConfig) (*schema.StreamReader[*entity.Message], error) {
|
||||
return i.DomainSVC.StreamResume(ctx, req, config)
|
||||
}
|
||||
func (i *impl) StreamExecute(ctx context.Context, config workflowModel.ExecuteConfig, input map[string]any) (*schema.StreamReader[*workflowEntity.Message], error) {
|
||||
return i.DomainSVC.StreamExecute(ctx, config, input)
|
||||
}
|
||||
|
||||
func (i *impl) InitApplicationDefaultConversationTemplate(ctx context.Context, spaceID int64, appID int64, userID int64) error {
|
||||
return i.DomainSVC.InitApplicationDefaultConversationTemplate(ctx, spaceID, appID, userID)
|
||||
}
|
||||
|
||||
func (i *impl) WithMessagePipe() (compose.Option, *schema.StreamReader[*entity.Message], func()) {
|
||||
return i.DomainSVC.WithMessagePipe()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ func (r *AgentRunner) StreamExecute(ctx context.Context, req *AgentRequest) (
|
|||
var composeOpts []compose.Option
|
||||
var pipeMsgOpt compose.Option
|
||||
var workflowMsgSr *schema.StreamReader[*crossworkflow.WorkflowMessage]
|
||||
var workflowMsgCloser func()
|
||||
if r.containWfTool {
|
||||
cfReq := crossworkflow.ExecuteConfig{
|
||||
AgentID: &req.Identity.AgentID,
|
||||
|
|
@ -88,7 +89,7 @@ func (r *AgentRunner) StreamExecute(ctx context.Context, req *AgentRequest) (
|
|||
}
|
||||
wfConfig := crossworkflow.DefaultSVC().WithExecuteConfig(cfReq)
|
||||
composeOpts = append(composeOpts, wfConfig)
|
||||
pipeMsgOpt, workflowMsgSr = crossworkflow.DefaultSVC().WithMessagePipe()
|
||||
pipeMsgOpt, workflowMsgSr, workflowMsgCloser = crossworkflow.DefaultSVC().WithMessagePipe()
|
||||
composeOpts = append(composeOpts, pipeMsgOpt)
|
||||
}
|
||||
|
||||
|
|
@ -120,6 +121,9 @@ func (r *AgentRunner) StreamExecute(ctx context.Context, req *AgentRequest) (
|
|||
|
||||
sw.Send(nil, errors.New("internal server error"))
|
||||
}
|
||||
if workflowMsgCloser != nil {
|
||||
workflowMsgCloser()
|
||||
}
|
||||
sw.Close()
|
||||
}()
|
||||
_, _ = r.runner.Stream(ctx, req, composeOpts...)
|
||||
|
|
@ -136,6 +140,7 @@ func (r *AgentRunner) processWfMidAnswerStream(_ context.Context, sw *schema.Str
|
|||
if swT != nil {
|
||||
swT.Close()
|
||||
}
|
||||
wfStream.Close()
|
||||
}()
|
||||
for {
|
||||
msg, err := wfStream.Recv()
|
||||
|
|
|
|||
|
|
@ -50,7 +50,9 @@ type SingleAgentDraft struct {
|
|||
JumpConfig *bot_common.JumpConfig `gorm:"column:jump_config;comment:Jump Configuration;serializer:json" json:"jump_config"` // Jump Configuration
|
||||
BackgroundImageInfoList []*bot_common.BackgroundImageInfo `gorm:"column:background_image_info_list;comment:Background image;serializer:json" json:"background_image_info_list"` // Background image
|
||||
DatabaseConfig []*bot_common.Database `gorm:"column:database_config;comment:Agent Database Base Configuration;serializer:json" json:"database_config"` // Agent Database Base Configuration
|
||||
BotMode int32 `gorm:"column:bot_mode;not null;comment:mod,0:single mode 2:chatflow mode" json:"bot_mode"` // mod,0:single mode 2:chatflow mode
|
||||
ShortcutCommand []string `gorm:"column:shortcut_command;comment:shortcut command;serializer:json" json:"shortcut_command"` // shortcut command
|
||||
LayoutInfo *bot_common.LayoutInfo `gorm:"column:layout_info;comment:chatflow layout info;serializer:json" json:"layout_info"` // chatflow layout info
|
||||
}
|
||||
|
||||
// TableName SingleAgentDraft's table name
|
||||
|
|
|
|||
|
|
@ -52,7 +52,9 @@ type SingleAgentVersion struct {
|
|||
Version string `gorm:"column:version;not null;comment:Agent Version" json:"version"` // Agent Version
|
||||
BackgroundImageInfoList []*bot_common.BackgroundImageInfo `gorm:"column:background_image_info_list;comment:Background image;serializer:json" json:"background_image_info_list"` // Background image
|
||||
DatabaseConfig []*bot_common.Database `gorm:"column:database_config;comment:Agent Database Base Configuration;serializer:json" json:"database_config"` // Agent Database Base Configuration
|
||||
BotMode int32 `gorm:"column:bot_mode;not null;comment:mod,0:single mode 2:chatflow mode" json:"bot_mode"` // mod,0:single mode 2:chatflow mode
|
||||
ShortcutCommand []string `gorm:"column:shortcut_command;comment:shortcut command;serializer:json" json:"shortcut_command"` // shortcut command
|
||||
LayoutInfo *bot_common.LayoutInfo `gorm:"column:layout_info;comment:chatflow layout info;serializer:json" json:"layout_info"` // chatflow layout info
|
||||
}
|
||||
|
||||
// TableName SingleAgentVersion's table name
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
|
@ -48,7 +64,9 @@ func newSingleAgentDraft(db *gorm.DB, opts ...gen.DOOption) singleAgentDraft {
|
|||
_singleAgentDraft.JumpConfig = field.NewField(tableName, "jump_config")
|
||||
_singleAgentDraft.BackgroundImageInfoList = field.NewField(tableName, "background_image_info_list")
|
||||
_singleAgentDraft.DatabaseConfig = field.NewField(tableName, "database_config")
|
||||
_singleAgentDraft.BotMode = field.NewInt32(tableName, "bot_mode")
|
||||
_singleAgentDraft.ShortcutCommand = field.NewField(tableName, "shortcut_command")
|
||||
_singleAgentDraft.LayoutInfo = field.NewField(tableName, "layout_info")
|
||||
|
||||
_singleAgentDraft.fillFieldMap()
|
||||
|
||||
|
|
@ -81,7 +99,9 @@ type singleAgentDraft struct {
|
|||
JumpConfig field.Field // Jump Configuration
|
||||
BackgroundImageInfoList field.Field // Background image
|
||||
DatabaseConfig field.Field // Agent Database Base Configuration
|
||||
BotMode field.Int32 // mod,0:single mode 2:chatflow mode
|
||||
ShortcutCommand field.Field // shortcut command
|
||||
LayoutInfo field.Field // chatflow layout info
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
|
@ -119,7 +139,9 @@ func (s *singleAgentDraft) updateTableName(table string) *singleAgentDraft {
|
|||
s.JumpConfig = field.NewField(table, "jump_config")
|
||||
s.BackgroundImageInfoList = field.NewField(table, "background_image_info_list")
|
||||
s.DatabaseConfig = field.NewField(table, "database_config")
|
||||
s.BotMode = field.NewInt32(table, "bot_mode")
|
||||
s.ShortcutCommand = field.NewField(table, "shortcut_command")
|
||||
s.LayoutInfo = field.NewField(table, "layout_info")
|
||||
|
||||
s.fillFieldMap()
|
||||
|
||||
|
|
@ -136,7 +158,7 @@ func (s *singleAgentDraft) GetFieldByName(fieldName string) (field.OrderExpr, bo
|
|||
}
|
||||
|
||||
func (s *singleAgentDraft) fillFieldMap() {
|
||||
s.fieldMap = make(map[string]field.Expr, 22)
|
||||
s.fieldMap = make(map[string]field.Expr, 24)
|
||||
s.fieldMap["id"] = s.ID
|
||||
s.fieldMap["agent_id"] = s.AgentID
|
||||
s.fieldMap["creator_id"] = s.CreatorID
|
||||
|
|
@ -158,7 +180,9 @@ func (s *singleAgentDraft) fillFieldMap() {
|
|||
s.fieldMap["jump_config"] = s.JumpConfig
|
||||
s.fieldMap["background_image_info_list"] = s.BackgroundImageInfoList
|
||||
s.fieldMap["database_config"] = s.DatabaseConfig
|
||||
s.fieldMap["bot_mode"] = s.BotMode
|
||||
s.fieldMap["shortcut_command"] = s.ShortcutCommand
|
||||
s.fieldMap["layout_info"] = s.LayoutInfo
|
||||
}
|
||||
|
||||
func (s singleAgentDraft) clone(db *gorm.DB) singleAgentDraft {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
|
@ -50,7 +66,9 @@ func newSingleAgentVersion(db *gorm.DB, opts ...gen.DOOption) singleAgentVersion
|
|||
_singleAgentVersion.Version = field.NewString(tableName, "version")
|
||||
_singleAgentVersion.BackgroundImageInfoList = field.NewField(tableName, "background_image_info_list")
|
||||
_singleAgentVersion.DatabaseConfig = field.NewField(tableName, "database_config")
|
||||
_singleAgentVersion.BotMode = field.NewInt32(tableName, "bot_mode")
|
||||
_singleAgentVersion.ShortcutCommand = field.NewField(tableName, "shortcut_command")
|
||||
_singleAgentVersion.LayoutInfo = field.NewField(tableName, "layout_info")
|
||||
|
||||
_singleAgentVersion.fillFieldMap()
|
||||
|
||||
|
|
@ -85,7 +103,9 @@ type singleAgentVersion struct {
|
|||
Version field.String // Agent Version
|
||||
BackgroundImageInfoList field.Field // Background image
|
||||
DatabaseConfig field.Field // Agent Database Base Configuration
|
||||
BotMode field.Int32 // mod,0:single mode 2:chatflow mode
|
||||
ShortcutCommand field.Field // shortcut command
|
||||
LayoutInfo field.Field // chatflow layout info
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
|
@ -125,7 +145,9 @@ func (s *singleAgentVersion) updateTableName(table string) *singleAgentVersion {
|
|||
s.Version = field.NewString(table, "version")
|
||||
s.BackgroundImageInfoList = field.NewField(table, "background_image_info_list")
|
||||
s.DatabaseConfig = field.NewField(table, "database_config")
|
||||
s.BotMode = field.NewInt32(table, "bot_mode")
|
||||
s.ShortcutCommand = field.NewField(table, "shortcut_command")
|
||||
s.LayoutInfo = field.NewField(table, "layout_info")
|
||||
|
||||
s.fillFieldMap()
|
||||
|
||||
|
|
@ -142,7 +164,7 @@ func (s *singleAgentVersion) GetFieldByName(fieldName string) (field.OrderExpr,
|
|||
}
|
||||
|
||||
func (s *singleAgentVersion) fillFieldMap() {
|
||||
s.fieldMap = make(map[string]field.Expr, 24)
|
||||
s.fieldMap = make(map[string]field.Expr, 26)
|
||||
s.fieldMap["id"] = s.ID
|
||||
s.fieldMap["agent_id"] = s.AgentID
|
||||
s.fieldMap["creator_id"] = s.CreatorID
|
||||
|
|
@ -166,7 +188,9 @@ func (s *singleAgentVersion) fillFieldMap() {
|
|||
s.fieldMap["version"] = s.Version
|
||||
s.fieldMap["background_image_info_list"] = s.BackgroundImageInfoList
|
||||
s.fieldMap["database_config"] = s.DatabaseConfig
|
||||
s.fieldMap["bot_mode"] = s.BotMode
|
||||
s.fieldMap["shortcut_command"] = s.ShortcutCommand
|
||||
s.fieldMap["layout_info"] = s.LayoutInfo
|
||||
}
|
||||
|
||||
func (s singleAgentVersion) clone(db *gorm.DB) singleAgentVersion {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,9 @@ import (
|
|||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/app/bot_common"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/singleagent"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/internal/dal/model"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/internal/dal/query"
|
||||
|
|
@ -118,7 +120,7 @@ func (sa *SingleAgentDraftDAO) Update(ctx context.Context, agentInfo *entity.Sin
|
|||
po := sa.singleAgentDraftDo2Po(agentInfo)
|
||||
singleAgentDAOModel := sa.dbQuery.SingleAgentDraft
|
||||
|
||||
_, err = singleAgentDAOModel.Where(singleAgentDAOModel.AgentID.Eq(agentInfo.AgentID)).Updates(po)
|
||||
err = singleAgentDAOModel.Where(singleAgentDAOModel.AgentID.Eq(agentInfo.AgentID)).Save(po)
|
||||
if err != nil {
|
||||
return errorx.WrapByCode(err, errno.ErrAgentUpdateCode)
|
||||
}
|
||||
|
|
@ -156,6 +158,8 @@ func (sa *SingleAgentDraftDAO) singleAgentDraftPo2Do(po *model.SingleAgentDraft)
|
|||
BackgroundImageInfoList: po.BackgroundImageInfoList,
|
||||
Database: po.DatabaseConfig,
|
||||
ShortcutCommand: po.ShortcutCommand,
|
||||
BotMode: bot_common.BotMode(po.BotMode),
|
||||
LayoutInfo: po.LayoutInfo,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -183,5 +187,7 @@ func (sa *SingleAgentDraftDAO) singleAgentDraftDo2Po(do *entity.SingleAgent) *mo
|
|||
BackgroundImageInfoList: do.BackgroundImageInfoList,
|
||||
DatabaseConfig: do.Database,
|
||||
ShortcutCommand: do.ShortcutCommand,
|
||||
BotMode: int32(do.BotMode),
|
||||
LayoutInfo: do.LayoutInfo,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@ type SingleAgentDraftRepo interface {
|
|||
Delete(ctx context.Context, spaceID, agentID int64) (err error)
|
||||
Update(ctx context.Context, agentInfo *entity.SingleAgent) (err error)
|
||||
Save(ctx context.Context, agentInfo *entity.SingleAgent) (err error)
|
||||
|
||||
GetDisplayInfo(ctx context.Context, userID, agentID int64) (*entity.AgentDraftDisplayInfo, error)
|
||||
UpdateDisplayInfo(ctx context.Context, userID int64, e *entity.AgentDraftDisplayInfo) error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import (
|
|||
)
|
||||
|
||||
var ConnectorIDWhiteList = []int64{
|
||||
consts.WebSDKConnectorID,
|
||||
consts.APIConnectorID,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ func (a *appServiceImpl) publishByConnectors(ctx context.Context, recordID int64
|
|||
for cid := range req.ConnectorPublishConfigs {
|
||||
connectorIDs = append(connectorIDs, cid)
|
||||
}
|
||||
failedResources, err := a.packResources(ctx, req.APPID, req.Version, connectorIDs)
|
||||
failedResources, err := a.packResources(ctx, req.APPID, req.Version, connectorIDs, req.ConnectorPublishConfigs)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
@ -92,7 +92,7 @@ func (a *appServiceImpl) publishByConnectors(ctx context.Context, recordID int64
|
|||
|
||||
for cid := range req.ConnectorPublishConfigs {
|
||||
switch cid {
|
||||
case commonConsts.APIConnectorID:
|
||||
case commonConsts.APIConnectorID, commonConsts.WebSDKConnectorID:
|
||||
updateSuccessErr := a.APPRepo.UpdateConnectorPublishStatus(ctx, recordID, entity.ConnectorPublishStatusOfSuccess)
|
||||
if updateSuccessErr == nil {
|
||||
continue
|
||||
|
|
@ -172,7 +172,8 @@ func (a *appServiceImpl) createPublishVersion(ctx context.Context, req *PublishA
|
|||
return recordID, nil
|
||||
}
|
||||
|
||||
func (a *appServiceImpl) packResources(ctx context.Context, appID int64, version string, connectorIDs []int64) (failedResources []*entity.PackResourceFailedInfo, err error) {
|
||||
func (a *appServiceImpl) packResources(ctx context.Context, appID int64, version string, connectorIDs []int64, pConfig map[int64]entity.PublishConfig) (failedResources []*entity.PackResourceFailedInfo, err error) {
|
||||
|
||||
failedPlugins, allDraftPlugins, err := a.packPlugins(ctx, appID, version)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -25,10 +25,13 @@ import (
|
|||
connectorModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/connector"
|
||||
databaseModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/database"
|
||||
knowledgeModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/knowledge"
|
||||
|
||||
crossconnector "github.com/coze-dev/coze-studio/backend/crossdomain/contract/connector"
|
||||
crossdatabase "github.com/coze-dev/coze-studio/backend/crossdomain/contract/database"
|
||||
crossknowledge "github.com/coze-dev/coze-studio/backend/crossdomain/contract/knowledge"
|
||||
crossplugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin"
|
||||
crossworkflow "github.com/coze-dev/coze-studio/backend/crossdomain/contract/workflow"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/domain/app/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/app/repository"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
|
|
@ -67,6 +70,11 @@ func (a *appServiceImpl) CreateDraftAPP(ctx context.Context, req *CreateDraftAPP
|
|||
return 0, errorx.Wrapf(err, "CreateDraftAPP failed, spaceID=%d", req.SpaceID)
|
||||
}
|
||||
|
||||
err = crossworkflow.DefaultSVC().InitApplicationDefaultConversationTemplate(ctx, req.SpaceID, appID, req.OwnerID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return appID, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ func NewService(tos storage.Storage) Connector {
|
|||
|
||||
var i18n2ConnectorDesc = map[i18n.Locale]map[int64]string{
|
||||
i18n.LocaleEN: {
|
||||
consts.WebSDKConnectorID: "Deploy the bot as a Web SDK",
|
||||
consts.WebSDKConnectorID: "Deploy your project to the Chat SDK. This publishing method is supported only for projects that have created a conversation flow, please refer to [Installation Guidelines](coze://web-sdk-guide) for installation methods.",
|
||||
consts.APIConnectorID: "Supports OAuth 2.0 and personal access tokens",
|
||||
consts.CozeConnectorID: "Coze",
|
||||
},
|
||||
|
|
@ -54,7 +54,7 @@ func (c *connectorImpl) AllConnectorInfo(ctx context.Context) []*entity.Connecto
|
|||
ID: consts.WebSDKConnectorID,
|
||||
Name: "Chat SDK",
|
||||
URI: "default_icon/connector-chat-sdk.jpg",
|
||||
Desc: "将Bot部署为Web SDK",
|
||||
Desc: "将项目部署到Chat SDK。仅创建过对话流的项目支持该发布方式,安装方式请查看[安装指引](coze://web-sdk-guide)",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ type RunRecordMeta struct {
|
|||
ChatRequest *string `json:"chat_message"`
|
||||
CompletedAt int64 `json:"completed_at"`
|
||||
FailedAt int64 `json:"failed_at"`
|
||||
CreatorID int64 `json:"creator_id"`
|
||||
}
|
||||
|
||||
type ChunkRunItem = RunRecordMeta
|
||||
|
|
@ -158,3 +159,18 @@ type ModelAnswerEvent struct {
|
|||
Message *schema.Message
|
||||
Err error
|
||||
}
|
||||
|
||||
type ListRunRecordMeta struct {
|
||||
ConversationID int64 `json:"conversation_id"`
|
||||
AgentID int64 `json:"agent_id"`
|
||||
SectionID int64 `json:"section_id"`
|
||||
Limit int32 `json:"limit"`
|
||||
OrderBy string `json:"order_by"` //desc asc
|
||||
BeforeID int64 `json:"before_id"`
|
||||
AfterID int64 `json:"after_id"`
|
||||
}
|
||||
|
||||
type CancelRunMeta struct {
|
||||
ConversationID int64 `json:"conversation_id"`
|
||||
RunID int64 `json:"run_id"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/singleagent"
|
||||
crossagent "github.com/coze-dev/coze-studio/backend/crossdomain/contract/agent"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
)
|
||||
|
||||
func getAgentHistoryRounds(agentInfo *singleagent.SingleAgent) int32 {
|
||||
var conversationTurns int32 = entity.ConversationTurnsDefault
|
||||
if agentInfo != nil && agentInfo.ModelInfo != nil && agentInfo.ModelInfo.ShortMemoryPolicy != nil && ptr.From(agentInfo.ModelInfo.ShortMemoryPolicy.HistoryRound) > 0 {
|
||||
conversationTurns = ptr.From(agentInfo.ModelInfo.ShortMemoryPolicy.HistoryRound)
|
||||
}
|
||||
return conversationTurns
|
||||
}
|
||||
|
||||
func getAgentInfo(ctx context.Context, agentID int64, isDraft bool) (*singleagent.SingleAgent, error) {
|
||||
agentInfo, err := crossagent.DefaultSVC().ObtainAgentByIdentity(ctx, &singleagent.AgentIdentity{
|
||||
AgentID: agentID,
|
||||
IsDraft: isDraft,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return agentInfo, nil
|
||||
}
|
||||
|
|
@ -0,0 +1,216 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package internal
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/cloudwego/eino/schema"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/agentrun"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/message"
|
||||
crossworkflow "github.com/coze-dev/coze-studio/backend/crossdomain/contract/workflow"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/entity"
|
||||
msgEntity "github.com/coze-dev/coze-studio/backend/domain/conversation/message/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/imagex"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/logs"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/safego"
|
||||
"github.com/coze-dev/coze-studio/backend/types/errno"
|
||||
)
|
||||
|
||||
func (art *AgentRuntime) ChatflowRun(ctx context.Context, imagex imagex.ImageX) (err error) {
|
||||
|
||||
mh := &MesssageEventHanlder{
|
||||
sw: art.SW,
|
||||
messageEvent: art.MessageEvent,
|
||||
}
|
||||
resumeInfo := parseResumeInfo(ctx, art.GetHistory())
|
||||
wfID, _ := strconv.ParseInt(art.GetAgentInfo().LayoutInfo.WorkflowId, 10, 64)
|
||||
|
||||
if wfID == 0 {
|
||||
mh.handlerErr(ctx, errorx.New(errno.ErrAgentRunWorkflowNotFound))
|
||||
return
|
||||
}
|
||||
var wfStreamer *schema.StreamReader[*crossworkflow.WorkflowMessage]
|
||||
|
||||
executeConfig := crossworkflow.ExecuteConfig{
|
||||
ID: wfID,
|
||||
ConnectorID: art.GetRunMeta().ConnectorID,
|
||||
ConnectorUID: art.GetRunMeta().UserID,
|
||||
AgentID: ptr.Of(art.GetRunMeta().AgentID),
|
||||
Mode: crossworkflow.ExecuteModeRelease,
|
||||
BizType: crossworkflow.BizTypeAgent,
|
||||
SyncPattern: crossworkflow.SyncPatternStream,
|
||||
From: crossworkflow.FromLatestVersion,
|
||||
}
|
||||
|
||||
if resumeInfo != nil {
|
||||
wfStreamer, err = crossworkflow.DefaultSVC().StreamResume(ctx, &crossworkflow.ResumeRequest{
|
||||
ResumeData: concatWfInput(art),
|
||||
EventID: resumeInfo.ChatflowInterrupt.InterruptEvent.ID,
|
||||
ExecuteID: resumeInfo.ChatflowInterrupt.ExecuteID,
|
||||
}, executeConfig)
|
||||
} else {
|
||||
executeConfig.ConversationID = &art.GetRunMeta().ConversationID
|
||||
executeConfig.SectionID = &art.GetRunMeta().SectionID
|
||||
executeConfig.InitRoundID = &art.RunRecord.ID
|
||||
executeConfig.RoundID = &art.RunRecord.ID
|
||||
executeConfig.UserMessage = transMessageToSchemaMessage(ctx, []*msgEntity.Message{art.GetInput()}, imagex)[0]
|
||||
executeConfig.MaxHistoryRounds = ptr.Of(getAgentHistoryRounds(art.GetAgentInfo()))
|
||||
wfStreamer, err = crossworkflow.DefaultSVC().StreamExecute(ctx, executeConfig, map[string]any{
|
||||
"USER_INPUT": concatWfInput(art),
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
safego.Go(ctx, func() {
|
||||
defer wg.Done()
|
||||
art.pullWfStream(ctx, wfStreamer, mh)
|
||||
})
|
||||
wg.Wait()
|
||||
return err
|
||||
}
|
||||
|
||||
func concatWfInput(rtDependence *AgentRuntime) string {
|
||||
var input string
|
||||
for _, content := range rtDependence.RunMeta.Content {
|
||||
if content.Type == message.InputTypeText {
|
||||
input = content.Text + "," + input
|
||||
} else {
|
||||
for _, file := range content.FileData {
|
||||
input += file.Url + ","
|
||||
}
|
||||
}
|
||||
}
|
||||
return strings.Trim(input, ",")
|
||||
}
|
||||
|
||||
func (art *AgentRuntime) pullWfStream(ctx context.Context, events *schema.StreamReader[*crossworkflow.WorkflowMessage], mh *MesssageEventHanlder) {
|
||||
|
||||
fullAnswerContent := bytes.NewBuffer([]byte{})
|
||||
var usage *msgEntity.UsageExt
|
||||
|
||||
preAnswerMsg, cErr := preCreateAnswer(ctx, art)
|
||||
|
||||
if cErr != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var preMsgIsFinish = false
|
||||
var lastAnswerMsg *entity.ChunkMessageItem
|
||||
|
||||
for {
|
||||
st, re := events.Recv()
|
||||
if re != nil {
|
||||
if errors.Is(re, io.EOF) {
|
||||
|
||||
if lastAnswerMsg != nil && usage != nil {
|
||||
art.SetUsage(&agentrun.Usage{
|
||||
LlmPromptTokens: usage.InputTokens,
|
||||
LlmCompletionTokens: usage.OutputTokens,
|
||||
LlmTotalTokens: usage.TotalCount,
|
||||
})
|
||||
_ = mh.handlerWfUsage(ctx, lastAnswerMsg, usage)
|
||||
}
|
||||
|
||||
finishErr := mh.handlerFinalAnswerFinish(ctx, art)
|
||||
if finishErr != nil {
|
||||
logs.CtxErrorf(ctx, "handlerFinalAnswerFinish error: %v", finishErr)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
logs.CtxErrorf(ctx, "pullWfStream Recv error: %v", re)
|
||||
mh.handlerErr(ctx, re)
|
||||
return
|
||||
}
|
||||
if st == nil {
|
||||
continue
|
||||
}
|
||||
if st.StateMessage != nil {
|
||||
if st.StateMessage.Status == crossworkflow.WorkflowFailed {
|
||||
mh.handlerErr(ctx, st.StateMessage.LastError)
|
||||
continue
|
||||
}
|
||||
if st.StateMessage.Usage != nil {
|
||||
usage = &msgEntity.UsageExt{
|
||||
InputTokens: st.StateMessage.Usage.InputTokens,
|
||||
OutputTokens: st.StateMessage.Usage.OutputTokens,
|
||||
TotalCount: st.StateMessage.Usage.InputTokens + st.StateMessage.Usage.OutputTokens,
|
||||
}
|
||||
}
|
||||
|
||||
if st.StateMessage.InterruptEvent != nil { // interrupt
|
||||
mh.handlerWfInterruptMsg(ctx, st.StateMessage, art)
|
||||
continue
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if st.DataMessage == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
switch st.DataMessage.Type {
|
||||
case crossworkflow.Answer:
|
||||
|
||||
// input node & question node skip
|
||||
if st.DataMessage != nil && (st.DataMessage.NodeType == crossworkflow.NodeTypeInputReceiver || st.DataMessage.NodeType == crossworkflow.NodeTypeQuestion) {
|
||||
break
|
||||
}
|
||||
|
||||
if preMsgIsFinish {
|
||||
preAnswerMsg, cErr = preCreateAnswer(ctx, art)
|
||||
if cErr != nil {
|
||||
return
|
||||
}
|
||||
preMsgIsFinish = false
|
||||
}
|
||||
if st.DataMessage.Content != "" {
|
||||
fullAnswerContent.WriteString(st.DataMessage.Content)
|
||||
}
|
||||
|
||||
sendAnswerMsg := buildSendMsg(ctx, preAnswerMsg, false, art)
|
||||
sendAnswerMsg.Content = st.DataMessage.Content
|
||||
|
||||
mh.messageEvent.SendMsgEvent(entity.RunEventMessageDelta, sendAnswerMsg, mh.sw)
|
||||
|
||||
if st.DataMessage.Last {
|
||||
preMsgIsFinish = true
|
||||
sendAnswerMsg := buildSendMsg(ctx, preAnswerMsg, false, art)
|
||||
sendAnswerMsg.Content = fullAnswerContent.String()
|
||||
fullAnswerContent.Reset()
|
||||
hfErr := mh.handlerAnswer(ctx, sendAnswerMsg, usage, art, preAnswerMsg)
|
||||
if hfErr != nil {
|
||||
return
|
||||
}
|
||||
lastAnswerMsg = sendAnswerMsg
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -19,6 +19,8 @@ package dal
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
|
@ -27,6 +29,7 @@ import (
|
|||
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/internal/dal/model"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/internal/dal/query"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/slices"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/logs"
|
||||
)
|
||||
|
||||
|
|
@ -59,8 +62,12 @@ func (dao *RunRecordDAO) Create(ctx context.Context, runMeta *entity.AgentRunMet
|
|||
return dao.buildPo2Do(createPO), nil
|
||||
}
|
||||
|
||||
func (dao *RunRecordDAO) GetByID(ctx context.Context, id int64) (*model.RunRecord, error) {
|
||||
return dao.query.RunRecord.WithContext(ctx).Where(dao.query.RunRecord.ID.Eq(id)).First()
|
||||
func (dao *RunRecordDAO) GetByID(ctx context.Context, id int64) (*entity.RunRecordMeta, error) {
|
||||
po, err := dao.query.RunRecord.WithContext(ctx).Where(dao.query.RunRecord.ID.Eq(id)).First()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dao.buildPo2Do(po), nil
|
||||
}
|
||||
|
||||
func (dao *RunRecordDAO) UpdateByID(ctx context.Context, id int64, updateMeta *entity.UpdateMeta) error {
|
||||
|
|
@ -106,20 +113,40 @@ func (dao *RunRecordDAO) Delete(ctx context.Context, id []int64) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (dao *RunRecordDAO) List(ctx context.Context, conversationID int64, sectionID int64, limit int32) ([]*model.RunRecord, error) {
|
||||
logs.CtxInfof(ctx, "list run record req:%v, sectionID:%v, limit:%v", conversationID, sectionID, limit)
|
||||
func (dao *RunRecordDAO) List(ctx context.Context, meta *entity.ListRunRecordMeta) ([]*entity.RunRecordMeta, error) {
|
||||
logs.CtxInfof(ctx, "list run record req:%v, sectionID:%v, limit:%v", meta.ConversationID, meta.SectionID, meta.Limit)
|
||||
m := dao.query.RunRecord
|
||||
do := m.WithContext(ctx).Where(m.ConversationID.Eq(conversationID)).Debug().Where(m.Status.NotIn(string(entity.RunStatusDeleted)))
|
||||
|
||||
if sectionID > 0 {
|
||||
do = do.Where(m.SectionID.Eq(sectionID))
|
||||
do := m.WithContext(ctx).Where(m.ConversationID.Eq(meta.ConversationID)).Debug().Where(m.Status.NotIn(string(entity.RunStatusDeleted)))
|
||||
if meta.BeforeID > 0 {
|
||||
runRecord, err := m.Where(m.ID.Eq(meta.BeforeID)).First()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
do = do.Where(m.CreatedAt.Lt(runRecord.CreatedAt))
|
||||
}
|
||||
if limit > 0 {
|
||||
do = do.Limit(int(limit))
|
||||
if meta.AfterID > 0 {
|
||||
runRecord, err := m.Where(m.ID.Eq(meta.AfterID)).First()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
do = do.Where(m.CreatedAt.Gt(runRecord.CreatedAt))
|
||||
}
|
||||
if meta.SectionID > 0 {
|
||||
do = do.Where(m.SectionID.Eq(meta.SectionID))
|
||||
}
|
||||
if meta.Limit > 0 {
|
||||
do = do.Limit(int(meta.Limit))
|
||||
}
|
||||
if strings.ToLower(meta.OrderBy) == "asc" {
|
||||
do = do.Order(m.CreatedAt.Asc())
|
||||
} else {
|
||||
do = do.Order(m.CreatedAt.Desc())
|
||||
}
|
||||
|
||||
runRecords, err := do.Order(m.CreatedAt.Desc()).Find()
|
||||
return runRecords, err
|
||||
runRecords, err := do.Find()
|
||||
return slices.Transform(runRecords, func(item *model.RunRecord) *entity.RunRecordMeta {
|
||||
return dao.buildPo2Do(item)
|
||||
}), err
|
||||
}
|
||||
|
||||
func (dao *RunRecordDAO) buildCreatePO(ctx context.Context, runMeta *entity.AgentRunMeta) (*model.RunRecord, error) {
|
||||
|
|
@ -135,7 +162,10 @@ func (dao *RunRecordDAO) buildCreatePO(ctx context.Context, runMeta *entity.Agen
|
|||
}
|
||||
|
||||
timeNow := time.Now().UnixMilli()
|
||||
|
||||
creatorID, err := strconv.ParseInt(runMeta.UserID, 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &model.RunRecord{
|
||||
ID: runID,
|
||||
ConversationID: runMeta.ConversationID,
|
||||
|
|
@ -145,6 +175,7 @@ func (dao *RunRecordDAO) buildCreatePO(ctx context.Context, runMeta *entity.Agen
|
|||
ChatRequest: string(reqOrigin),
|
||||
UserID: runMeta.UserID,
|
||||
CreatedAt: timeNow,
|
||||
CreatorID: creatorID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
@ -161,7 +192,21 @@ func (dao *RunRecordDAO) buildPo2Do(po *model.RunRecord) *entity.RunRecordMeta {
|
|||
CompletedAt: po.CompletedAt,
|
||||
FailedAt: po.FailedAt,
|
||||
Usage: po.Usage,
|
||||
CreatorID: po.CreatorID,
|
||||
}
|
||||
|
||||
return runMeta
|
||||
}
|
||||
|
||||
func (dao *RunRecordDAO) Cancel(ctx context.Context, meta *entity.CancelRunMeta) (*entity.RunRecordMeta, error) {
|
||||
|
||||
m := dao.query.RunRecord
|
||||
_, err := m.WithContext(ctx).Where(m.ID.Eq(meta.RunID)).UpdateColumns(map[string]interface{}{
|
||||
"updated_at": time.Now().UnixMilli(),
|
||||
"status": entity.RunEventCancelled,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dao.GetByID(ctx, meta.RunID)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package internal
|
||||
|
||||
import (
|
||||
"github.com/cloudwego/eino/schema"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/entity"
|
||||
)
|
||||
|
||||
type Event struct {
|
||||
}
|
||||
|
||||
func NewEvent() *Event {
|
||||
return &Event{}
|
||||
}
|
||||
|
||||
func (e *Event) buildMessageEvent(runEvent entity.RunEvent, chunkMsgItem *entity.ChunkMessageItem) *entity.AgentRunResponse {
|
||||
return &entity.AgentRunResponse{
|
||||
Event: runEvent,
|
||||
ChunkMessageItem: chunkMsgItem,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Event) buildRunEvent(runEvent entity.RunEvent, chunkRunItem *entity.ChunkRunItem) *entity.AgentRunResponse {
|
||||
return &entity.AgentRunResponse{
|
||||
Event: runEvent,
|
||||
ChunkRunItem: chunkRunItem,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Event) buildErrEvent(runEvent entity.RunEvent, err *entity.RunError) *entity.AgentRunResponse {
|
||||
return &entity.AgentRunResponse{
|
||||
Event: runEvent,
|
||||
Error: err,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Event) buildStreamDoneEvent() *entity.AgentRunResponse {
|
||||
|
||||
return &entity.AgentRunResponse{
|
||||
Event: entity.RunEventStreamDone,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Event) SendRunEvent(runEvent entity.RunEvent, runItem *entity.ChunkRunItem, sw *schema.StreamWriter[*entity.AgentRunResponse]) {
|
||||
resp := e.buildRunEvent(runEvent, runItem)
|
||||
sw.Send(resp, nil)
|
||||
}
|
||||
|
||||
func (e *Event) SendMsgEvent(runEvent entity.RunEvent, messageItem *entity.ChunkMessageItem, sw *schema.StreamWriter[*entity.AgentRunResponse]) {
|
||||
resp := e.buildMessageEvent(runEvent, messageItem)
|
||||
sw.Send(resp, nil)
|
||||
}
|
||||
|
||||
func (e *Event) SendErrEvent(runEvent entity.RunEvent, sw *schema.StreamWriter[*entity.AgentRunResponse], err *entity.RunError) {
|
||||
resp := e.buildErrEvent(runEvent, err)
|
||||
sw.Send(resp, nil)
|
||||
}
|
||||
|
||||
func (e *Event) SendStreamDoneEvent(sw *schema.StreamWriter[*entity.AgentRunResponse]) {
|
||||
resp := e.buildStreamDoneEvent()
|
||||
sw.Send(resp, nil)
|
||||
}
|
||||
|
|
@ -0,0 +1,512 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/cloudwego/eino/schema"
|
||||
|
||||
messageModel "github.com/coze-dev/coze-studio/backend/api/model/conversation/message"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/message"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/singleagent"
|
||||
crossagent "github.com/coze-dev/coze-studio/backend/crossdomain/contract/agent"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/imagex"
|
||||
|
||||
crossmessage "github.com/coze-dev/coze-studio/backend/crossdomain/contract/message"
|
||||
crossworkflow "github.com/coze-dev/coze-studio/backend/crossdomain/contract/workflow"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/entity"
|
||||
msgEntity "github.com/coze-dev/coze-studio/backend/domain/conversation/message/entity"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/types/errno"
|
||||
)
|
||||
|
||||
func buildSendMsg(_ context.Context, msg *msgEntity.Message, isFinish bool, rtDependence *AgentRuntime) *entity.ChunkMessageItem {
|
||||
|
||||
copyMap := make(map[string]string)
|
||||
for k, v := range msg.Ext {
|
||||
copyMap[k] = v
|
||||
}
|
||||
|
||||
return &entity.ChunkMessageItem{
|
||||
ID: msg.ID,
|
||||
ConversationID: msg.ConversationID,
|
||||
SectionID: msg.SectionID,
|
||||
AgentID: msg.AgentID,
|
||||
Content: msg.Content,
|
||||
Role: entity.RoleTypeAssistant,
|
||||
ContentType: msg.ContentType,
|
||||
MessageType: msg.MessageType,
|
||||
ReplyID: rtDependence.GetQuestionMsgID(),
|
||||
Type: msg.MessageType,
|
||||
CreatedAt: msg.CreatedAt,
|
||||
UpdatedAt: msg.UpdatedAt,
|
||||
RunID: rtDependence.GetRunRecord().ID,
|
||||
Ext: copyMap,
|
||||
IsFinish: isFinish,
|
||||
ReasoningContent: ptr.Of(msg.ReasoningContent),
|
||||
}
|
||||
}
|
||||
|
||||
func buildKnowledge(_ context.Context, chunk *entity.AgentRespEvent) *msgEntity.VerboseInfo {
|
||||
var recallDatas []msgEntity.RecallDataInfo
|
||||
for _, kOne := range chunk.Knowledge {
|
||||
recallDatas = append(recallDatas, msgEntity.RecallDataInfo{
|
||||
Slice: kOne.Content,
|
||||
Meta: msgEntity.MetaInfo{
|
||||
Dataset: msgEntity.DatasetInfo{
|
||||
ID: kOne.MetaData["dataset_id"].(string),
|
||||
Name: kOne.MetaData["dataset_name"].(string),
|
||||
},
|
||||
Document: msgEntity.DocumentInfo{
|
||||
ID: kOne.MetaData["document_id"].(string),
|
||||
Name: kOne.MetaData["document_name"].(string),
|
||||
},
|
||||
},
|
||||
Score: kOne.Score(),
|
||||
})
|
||||
}
|
||||
|
||||
verboseData := &msgEntity.VerboseData{
|
||||
Chunks: recallDatas,
|
||||
OriReq: "",
|
||||
StatusCode: 0,
|
||||
}
|
||||
data, err := json.Marshal(verboseData)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
knowledgeInfo := &msgEntity.VerboseInfo{
|
||||
MessageType: string(entity.MessageSubTypeKnowledgeCall),
|
||||
Data: string(data),
|
||||
}
|
||||
return knowledgeInfo
|
||||
}
|
||||
|
||||
func buildBotStateExt(arm *entity.AgentRunMeta) *msgEntity.BotStateExt {
|
||||
agentID := strconv.FormatInt(arm.AgentID, 10)
|
||||
botStateExt := &msgEntity.BotStateExt{
|
||||
AgentID: agentID,
|
||||
AgentName: arm.Name,
|
||||
Awaiting: agentID,
|
||||
BotID: agentID,
|
||||
}
|
||||
|
||||
return botStateExt
|
||||
}
|
||||
|
||||
type irMsg struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
ContentType string `json:"content_type"`
|
||||
Content any `json:"content"` // either optionContent or string
|
||||
ID string `json:"id,omitempty"`
|
||||
}
|
||||
|
||||
func parseInterruptData(_ context.Context, interruptData *singleagent.InterruptInfo) (string, message.ContentType, error) {
|
||||
|
||||
defaultContentType := message.ContentTypeText
|
||||
switch interruptData.InterruptType {
|
||||
case singleagent.InterruptEventType_OauthPlugin:
|
||||
data := interruptData.AllToolInterruptData[interruptData.ToolCallID].ToolNeedOAuth.Message
|
||||
return data, defaultContentType, nil
|
||||
case singleagent.InterruptEventType_Question:
|
||||
data := interruptData.AllWfInterruptData[interruptData.ToolCallID].InterruptData
|
||||
return processQuestionInterruptData(data)
|
||||
case singleagent.InterruptEventType_InputNode:
|
||||
data := interruptData.AllWfInterruptData[interruptData.ToolCallID].InterruptData
|
||||
return processInputNodeInterruptData(data)
|
||||
case singleagent.InterruptEventType_WorkflowLLM:
|
||||
toolInterruptEvent := interruptData.AllWfInterruptData[interruptData.ToolCallID].ToolInterruptEvent
|
||||
data := toolInterruptEvent.InterruptData
|
||||
if singleagent.InterruptEventType(toolInterruptEvent.EventType) == singleagent.InterruptEventType_InputNode {
|
||||
return processInputNodeInterruptData(data)
|
||||
}
|
||||
if singleagent.InterruptEventType(toolInterruptEvent.EventType) == singleagent.InterruptEventType_Question {
|
||||
return processQuestionInterruptData(data)
|
||||
}
|
||||
return "", defaultContentType, errorx.New(errno.ErrUnknowInterruptType)
|
||||
|
||||
}
|
||||
return "", defaultContentType, errorx.New(errno.ErrUnknowInterruptType)
|
||||
}
|
||||
|
||||
func processQuestionInterruptData(data string) (string, message.ContentType, error) {
|
||||
defaultContentType := message.ContentTypeText
|
||||
var iData map[string][]*irMsg
|
||||
err := json.Unmarshal([]byte(data), &iData)
|
||||
if err != nil {
|
||||
return "", defaultContentType, err
|
||||
}
|
||||
if len(iData["messages"]) == 0 {
|
||||
return "", defaultContentType, errorx.New(errno.ErrInterruptDataEmpty)
|
||||
}
|
||||
interruptMsg := iData["messages"][0]
|
||||
|
||||
if interruptMsg.ContentType == "text" {
|
||||
return interruptMsg.Content.(string), defaultContentType, nil
|
||||
} else if interruptMsg.ContentType == "option" || interruptMsg.ContentType == "form_schema" {
|
||||
iMarshalData, err := json.Marshal(interruptMsg)
|
||||
if err != nil {
|
||||
return "", defaultContentType, err
|
||||
}
|
||||
return string(iMarshalData), message.ContentTypeCard, nil
|
||||
}
|
||||
return "", defaultContentType, errorx.New(errno.ErrUnknowInterruptType)
|
||||
}
|
||||
|
||||
func processInputNodeInterruptData(data string) (string, message.ContentType, error) {
|
||||
return data, message.ContentTypeCard, nil
|
||||
}
|
||||
|
||||
func handlerUsage(meta *schema.ResponseMeta) *msgEntity.UsageExt {
|
||||
if meta == nil || meta.Usage == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &msgEntity.UsageExt{
|
||||
TotalCount: int64(meta.Usage.TotalTokens),
|
||||
InputTokens: int64(meta.Usage.PromptTokens),
|
||||
OutputTokens: int64(meta.Usage.CompletionTokens),
|
||||
}
|
||||
}
|
||||
|
||||
func preCreateAnswer(ctx context.Context, rtDependence *AgentRuntime) (*msgEntity.Message, error) {
|
||||
arm := rtDependence.RunMeta
|
||||
msgMeta := &msgEntity.Message{
|
||||
ConversationID: arm.ConversationID,
|
||||
RunID: rtDependence.RunRecord.ID,
|
||||
AgentID: arm.AgentID,
|
||||
SectionID: arm.SectionID,
|
||||
UserID: arm.UserID,
|
||||
Role: schema.Assistant,
|
||||
MessageType: message.MessageTypeAnswer,
|
||||
ContentType: message.ContentTypeText,
|
||||
Ext: arm.Ext,
|
||||
}
|
||||
|
||||
if arm.Ext == nil {
|
||||
msgMeta.Ext = map[string]string{}
|
||||
}
|
||||
|
||||
botStateExt := buildBotStateExt(arm)
|
||||
bseString, err := json.Marshal(botStateExt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, ok := msgMeta.Ext[string(msgEntity.MessageExtKeyBotState)]; !ok {
|
||||
msgMeta.Ext[string(msgEntity.MessageExtKeyBotState)] = string(bseString)
|
||||
}
|
||||
|
||||
msgMeta.Ext = arm.Ext
|
||||
return crossmessage.DefaultSVC().PreCreate(ctx, msgMeta)
|
||||
}
|
||||
|
||||
func buildAgentMessage2Create(ctx context.Context, chunk *entity.AgentRespEvent, messageType message.MessageType, rtDependence *AgentRuntime) *message.Message {
|
||||
arm := rtDependence.GetRunMeta()
|
||||
msg := &msgEntity.Message{
|
||||
ConversationID: arm.ConversationID,
|
||||
RunID: rtDependence.RunRecord.ID,
|
||||
AgentID: arm.AgentID,
|
||||
SectionID: arm.SectionID,
|
||||
UserID: arm.UserID,
|
||||
MessageType: messageType,
|
||||
}
|
||||
buildExt := map[string]string{}
|
||||
|
||||
timeCost := fmt.Sprintf("%.1f", float64(time.Since(rtDependence.GetStartTime()).Milliseconds())/1000.00)
|
||||
|
||||
switch messageType {
|
||||
case message.MessageTypeQuestion:
|
||||
msg.Role = schema.User
|
||||
msg.ContentType = arm.ContentType
|
||||
for _, content := range arm.Content {
|
||||
if content.Type == message.InputTypeText {
|
||||
msg.Content = content.Text
|
||||
break
|
||||
}
|
||||
}
|
||||
msg.MultiContent = arm.Content
|
||||
buildExt = arm.Ext
|
||||
|
||||
msg.DisplayContent = arm.DisplayContent
|
||||
case message.MessageTypeAnswer, message.MessageTypeToolAsAnswer:
|
||||
msg.Role = schema.Assistant
|
||||
msg.ContentType = message.ContentTypeText
|
||||
|
||||
case message.MessageTypeToolResponse:
|
||||
msg.Role = schema.Assistant
|
||||
msg.ContentType = message.ContentTypeText
|
||||
msg.Content = chunk.ToolsMessage[0].Content
|
||||
|
||||
buildExt[string(msgEntity.MessageExtKeyTimeCost)] = timeCost
|
||||
modelContent := chunk.ToolsMessage[0]
|
||||
mc, err := json.Marshal(modelContent)
|
||||
if err == nil {
|
||||
msg.ModelContent = string(mc)
|
||||
}
|
||||
|
||||
case message.MessageTypeKnowledge:
|
||||
msg.Role = schema.Assistant
|
||||
msg.ContentType = message.ContentTypeText
|
||||
|
||||
knowledgeContent := buildKnowledge(ctx, chunk)
|
||||
if knowledgeContent != nil {
|
||||
knInfo, err := json.Marshal(knowledgeContent)
|
||||
if err == nil {
|
||||
msg.Content = string(knInfo)
|
||||
}
|
||||
}
|
||||
|
||||
buildExt[string(msgEntity.MessageExtKeyTimeCost)] = timeCost
|
||||
|
||||
modelContent := chunk.Knowledge
|
||||
mc, err := json.Marshal(modelContent)
|
||||
if err == nil {
|
||||
msg.ModelContent = string(mc)
|
||||
}
|
||||
|
||||
case message.MessageTypeFunctionCall:
|
||||
msg.Role = schema.Assistant
|
||||
msg.ContentType = message.ContentTypeText
|
||||
|
||||
if len(chunk.FuncCall.ToolCalls) > 0 {
|
||||
toolCall := chunk.FuncCall.ToolCalls[0]
|
||||
toolCalling, err := json.Marshal(toolCall)
|
||||
if err == nil {
|
||||
msg.Content = string(toolCalling)
|
||||
}
|
||||
buildExt[string(msgEntity.MessageExtKeyPlugin)] = toolCall.Function.Name
|
||||
buildExt[string(msgEntity.MessageExtKeyToolName)] = toolCall.Function.Name
|
||||
buildExt[string(msgEntity.MessageExtKeyTimeCost)] = timeCost
|
||||
|
||||
modelContent := chunk.FuncCall
|
||||
mc, err := json.Marshal(modelContent)
|
||||
if err == nil {
|
||||
msg.ModelContent = string(mc)
|
||||
}
|
||||
}
|
||||
case message.MessageTypeFlowUp:
|
||||
msg.Role = schema.Assistant
|
||||
msg.ContentType = message.ContentTypeText
|
||||
msg.Content = chunk.Suggest.Content
|
||||
|
||||
case message.MessageTypeVerbose:
|
||||
msg.Role = schema.Assistant
|
||||
msg.ContentType = message.ContentTypeText
|
||||
|
||||
d := &entity.Data{
|
||||
FinishReason: 0,
|
||||
FinData: "",
|
||||
}
|
||||
dByte, _ := json.Marshal(d)
|
||||
afc := &entity.AnswerFinshContent{
|
||||
MsgType: entity.MessageSubTypeGenerateFinish,
|
||||
Data: string(dByte),
|
||||
}
|
||||
afcMarshal, _ := json.Marshal(afc)
|
||||
msg.Content = string(afcMarshal)
|
||||
case message.MessageTypeInterrupt:
|
||||
msg.Role = schema.Assistant
|
||||
msg.MessageType = message.MessageTypeVerbose
|
||||
msg.ContentType = message.ContentTypeText
|
||||
|
||||
afc := &entity.AnswerFinshContent{
|
||||
MsgType: entity.MessageSubTypeInterrupt,
|
||||
Data: "",
|
||||
}
|
||||
afcMarshal, _ := json.Marshal(afc)
|
||||
msg.Content = string(afcMarshal)
|
||||
|
||||
// Add ext to save to context_message
|
||||
interruptByte, err := json.Marshal(chunk.Interrupt)
|
||||
if err == nil {
|
||||
buildExt[string(msgEntity.ExtKeyResumeInfo)] = string(interruptByte)
|
||||
}
|
||||
buildExt[string(msgEntity.ExtKeyToolCallsIDs)] = chunk.Interrupt.ToolCallID
|
||||
rc := &messageModel.RequiredAction{
|
||||
Type: "submit_tool_outputs",
|
||||
SubmitToolOutputs: &messageModel.SubmitToolOutputs{},
|
||||
}
|
||||
msg.RequiredAction = rc
|
||||
rcExtByte, err := json.Marshal(rc)
|
||||
if err == nil {
|
||||
buildExt[string(msgEntity.ExtKeyRequiresAction)] = string(rcExtByte)
|
||||
}
|
||||
}
|
||||
|
||||
if messageType != message.MessageTypeQuestion {
|
||||
botStateExt := buildBotStateExt(arm)
|
||||
bseString, err := json.Marshal(botStateExt)
|
||||
if err == nil {
|
||||
buildExt[string(msgEntity.MessageExtKeyBotState)] = string(bseString)
|
||||
}
|
||||
}
|
||||
msg.Ext = buildExt
|
||||
return msg
|
||||
}
|
||||
|
||||
func handlerWfInterruptEvent(_ context.Context, interruptEventData *crossworkflow.InterruptEvent) (string, message.ContentType, error) {
|
||||
defaultContentType := message.ContentTypeText
|
||||
switch singleagent.InterruptEventType(interruptEventData.EventType) {
|
||||
case singleagent.InterruptEventType_OauthPlugin:
|
||||
|
||||
case singleagent.InterruptEventType_Question:
|
||||
data := interruptEventData.InterruptData
|
||||
return processQuestionInterruptData(data)
|
||||
case singleagent.InterruptEventType_InputNode:
|
||||
data := interruptEventData.InterruptData
|
||||
return processInputNodeInterruptData(data)
|
||||
case singleagent.InterruptEventType_WorkflowLLM:
|
||||
data := interruptEventData.ToolInterruptEvent.InterruptData
|
||||
if singleagent.InterruptEventType(interruptEventData.EventType) == singleagent.InterruptEventType_InputNode {
|
||||
return processInputNodeInterruptData(data)
|
||||
}
|
||||
if singleagent.InterruptEventType(interruptEventData.EventType) == singleagent.InterruptEventType_Question {
|
||||
return processQuestionInterruptData(data)
|
||||
}
|
||||
return "", defaultContentType, errorx.New(errno.ErrUnknowInterruptType)
|
||||
}
|
||||
return "", defaultContentType, errorx.New(errno.ErrUnknowInterruptType)
|
||||
}
|
||||
|
||||
func historyPairs(historyMsg []*message.Message) []*message.Message {
|
||||
|
||||
fcMsgPairs := make(map[int64][]*message.Message)
|
||||
for _, one := range historyMsg {
|
||||
if one.MessageType != message.MessageTypeFunctionCall && one.MessageType != message.MessageTypeToolResponse {
|
||||
continue
|
||||
}
|
||||
if _, ok := fcMsgPairs[one.RunID]; !ok {
|
||||
fcMsgPairs[one.RunID] = []*message.Message{one}
|
||||
} else {
|
||||
fcMsgPairs[one.RunID] = append(fcMsgPairs[one.RunID], one)
|
||||
}
|
||||
}
|
||||
|
||||
var historyAfterPairs []*message.Message
|
||||
for _, value := range historyMsg {
|
||||
if value.MessageType == message.MessageTypeFunctionCall {
|
||||
if len(fcMsgPairs[value.RunID])%2 == 0 {
|
||||
historyAfterPairs = append(historyAfterPairs, value)
|
||||
}
|
||||
} else {
|
||||
historyAfterPairs = append(historyAfterPairs, value)
|
||||
}
|
||||
}
|
||||
return historyAfterPairs
|
||||
|
||||
}
|
||||
|
||||
func transMessageToSchemaMessage(ctx context.Context, msgs []*message.Message, imagexClient imagex.ImageX) []*schema.Message {
|
||||
schemaMessage := make([]*schema.Message, 0, len(msgs))
|
||||
|
||||
for _, msgOne := range msgs {
|
||||
if msgOne.ModelContent == "" {
|
||||
continue
|
||||
}
|
||||
if msgOne.MessageType == message.MessageTypeVerbose || msgOne.MessageType == message.MessageTypeFlowUp {
|
||||
continue
|
||||
}
|
||||
var sm *schema.Message
|
||||
err := json.Unmarshal([]byte(msgOne.ModelContent), &sm)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if len(sm.ReasoningContent) > 0 {
|
||||
sm.ReasoningContent = ""
|
||||
}
|
||||
schemaMessage = append(schemaMessage, parseMessageURI(ctx, sm, imagexClient))
|
||||
}
|
||||
|
||||
return schemaMessage
|
||||
}
|
||||
|
||||
func parseMessageURI(ctx context.Context, mcMsg *schema.Message, imagexClient imagex.ImageX) *schema.Message {
|
||||
if mcMsg.MultiContent == nil {
|
||||
return mcMsg
|
||||
}
|
||||
for k, one := range mcMsg.MultiContent {
|
||||
switch one.Type {
|
||||
case schema.ChatMessagePartTypeImageURL:
|
||||
|
||||
if one.ImageURL.URI != "" {
|
||||
url, err := imagexClient.GetResourceURL(ctx, one.ImageURL.URI)
|
||||
if err == nil {
|
||||
mcMsg.MultiContent[k].ImageURL.URL = url.URL
|
||||
}
|
||||
}
|
||||
case schema.ChatMessagePartTypeFileURL:
|
||||
if one.FileURL.URI != "" {
|
||||
url, err := imagexClient.GetResourceURL(ctx, one.FileURL.URI)
|
||||
if err == nil {
|
||||
mcMsg.MultiContent[k].FileURL.URL = url.URL
|
||||
}
|
||||
}
|
||||
case schema.ChatMessagePartTypeAudioURL:
|
||||
if one.AudioURL.URI != "" {
|
||||
url, err := imagexClient.GetResourceURL(ctx, one.AudioURL.URI)
|
||||
if err == nil {
|
||||
mcMsg.MultiContent[k].AudioURL.URL = url.URL
|
||||
}
|
||||
}
|
||||
case schema.ChatMessagePartTypeVideoURL:
|
||||
if one.VideoURL.URI != "" {
|
||||
url, err := imagexClient.GetResourceURL(ctx, one.VideoURL.URI)
|
||||
if err == nil {
|
||||
mcMsg.MultiContent[k].VideoURL.URL = url.URL
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return mcMsg
|
||||
}
|
||||
|
||||
func parseResumeInfo(_ context.Context, historyMsg []*message.Message) *crossagent.ResumeInfo {
|
||||
|
||||
var resumeInfo *crossagent.ResumeInfo
|
||||
for i := len(historyMsg) - 1; i >= 0; i-- {
|
||||
if historyMsg[i].MessageType == message.MessageTypeQuestion {
|
||||
break
|
||||
}
|
||||
if historyMsg[i].MessageType == message.MessageTypeVerbose {
|
||||
if historyMsg[i].Ext[string(msgEntity.ExtKeyResumeInfo)] != "" {
|
||||
err := json.Unmarshal([]byte(historyMsg[i].Ext[string(msgEntity.ExtKeyResumeInfo)]), &resumeInfo)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return resumeInfo
|
||||
}
|
||||
|
||||
func buildSendRunRecord(_ context.Context, runRecord *entity.RunRecordMeta, runStatus entity.RunStatus) *entity.ChunkRunItem {
|
||||
return &entity.ChunkRunItem{
|
||||
ID: runRecord.ID,
|
||||
ConversationID: runRecord.ConversationID,
|
||||
AgentID: runRecord.AgentID,
|
||||
SectionID: runRecord.SectionID,
|
||||
Status: runStatus,
|
||||
CreatedAt: runRecord.CreatedAt,
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,428 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cloudwego/eino/schema"
|
||||
"github.com/mohae/deepcopy"
|
||||
|
||||
crossmessage "github.com/coze-dev/coze-studio/backend/crossdomain/contract/message"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/agentrun"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/message"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/singleagent"
|
||||
crossworkflow "github.com/coze-dev/coze-studio/backend/crossdomain/contract/workflow"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/entity"
|
||||
msgEntity "github.com/coze-dev/coze-studio/backend/domain/conversation/message/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/types/consts"
|
||||
"github.com/coze-dev/coze-studio/backend/types/errno"
|
||||
)
|
||||
|
||||
type Event struct {
|
||||
}
|
||||
|
||||
func NewMessageEvent() *Event {
|
||||
return &Event{}
|
||||
}
|
||||
|
||||
func (e *Event) buildMessageEvent(runEvent entity.RunEvent, chunkMsgItem *entity.ChunkMessageItem) *entity.AgentRunResponse {
|
||||
return &entity.AgentRunResponse{
|
||||
Event: runEvent,
|
||||
ChunkMessageItem: chunkMsgItem,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Event) buildRunEvent(runEvent entity.RunEvent, chunkRunItem *entity.ChunkRunItem) *entity.AgentRunResponse {
|
||||
return &entity.AgentRunResponse{
|
||||
Event: runEvent,
|
||||
ChunkRunItem: chunkRunItem,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Event) buildErrEvent(runEvent entity.RunEvent, err *entity.RunError) *entity.AgentRunResponse {
|
||||
return &entity.AgentRunResponse{
|
||||
Event: runEvent,
|
||||
Error: err,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Event) buildStreamDoneEvent() *entity.AgentRunResponse {
|
||||
|
||||
return &entity.AgentRunResponse{
|
||||
Event: entity.RunEventStreamDone,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Event) SendRunEvent(runEvent entity.RunEvent, runItem *entity.ChunkRunItem, sw *schema.StreamWriter[*entity.AgentRunResponse]) {
|
||||
resp := e.buildRunEvent(runEvent, runItem)
|
||||
sw.Send(resp, nil)
|
||||
}
|
||||
|
||||
func (e *Event) SendMsgEvent(runEvent entity.RunEvent, messageItem *entity.ChunkMessageItem, sw *schema.StreamWriter[*entity.AgentRunResponse]) {
|
||||
resp := e.buildMessageEvent(runEvent, messageItem)
|
||||
sw.Send(resp, nil)
|
||||
}
|
||||
|
||||
func (e *Event) SendErrEvent(runEvent entity.RunEvent, sw *schema.StreamWriter[*entity.AgentRunResponse], err *entity.RunError) {
|
||||
resp := e.buildErrEvent(runEvent, err)
|
||||
sw.Send(resp, nil)
|
||||
}
|
||||
|
||||
func (e *Event) SendStreamDoneEvent(sw *schema.StreamWriter[*entity.AgentRunResponse]) {
|
||||
resp := e.buildStreamDoneEvent()
|
||||
sw.Send(resp, nil)
|
||||
}
|
||||
|
||||
type MesssageEventHanlder struct {
|
||||
messageEvent *Event
|
||||
sw *schema.StreamWriter[*entity.AgentRunResponse]
|
||||
}
|
||||
|
||||
func (mh *MesssageEventHanlder) handlerErr(_ context.Context, err error) {
|
||||
|
||||
var errMsg string
|
||||
var statusErr errorx.StatusError
|
||||
if errors.As(err, &statusErr) {
|
||||
errMsg = statusErr.Msg()
|
||||
} else {
|
||||
if strings.ToLower(os.Getenv(consts.RunMode)) != "debug" {
|
||||
errMsg = "Internal Server Error"
|
||||
} else {
|
||||
errMsg = errorx.ErrorWithoutStack(err)
|
||||
}
|
||||
}
|
||||
|
||||
mh.messageEvent.SendErrEvent(entity.RunEventError, mh.sw, &entity.RunError{
|
||||
Code: errno.ErrAgentRun,
|
||||
Msg: errMsg,
|
||||
})
|
||||
}
|
||||
|
||||
func (mh *MesssageEventHanlder) handlerAckMessage(_ context.Context, input *msgEntity.Message) error {
|
||||
sendMsg := &entity.ChunkMessageItem{
|
||||
ID: input.ID,
|
||||
ConversationID: input.ConversationID,
|
||||
SectionID: input.SectionID,
|
||||
AgentID: input.AgentID,
|
||||
Role: entity.RoleType(input.Role),
|
||||
MessageType: message.MessageTypeAck,
|
||||
ReplyID: input.ID,
|
||||
Content: input.Content,
|
||||
ContentType: message.ContentTypeText,
|
||||
IsFinish: true,
|
||||
}
|
||||
|
||||
mh.messageEvent.SendMsgEvent(entity.RunEventAck, sendMsg, mh.sw)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mh *MesssageEventHanlder) handlerFunctionCall(ctx context.Context, chunk *entity.AgentRespEvent, rtDependence *AgentRuntime) error {
|
||||
cm := buildAgentMessage2Create(ctx, chunk, message.MessageTypeFunctionCall, rtDependence)
|
||||
|
||||
cmData, err := crossmessage.DefaultSVC().Create(ctx, cm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sendMsg := buildSendMsg(ctx, cmData, true, rtDependence)
|
||||
|
||||
mh.messageEvent.SendMsgEvent(entity.RunEventMessageCompleted, sendMsg, mh.sw)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mh *MesssageEventHanlder) handlerTooResponse(ctx context.Context, chunk *entity.AgentRespEvent, rtDependence *AgentRuntime, preToolResponseMsg *msgEntity.Message, toolResponseMsgContent string) error {
|
||||
|
||||
cm := buildAgentMessage2Create(ctx, chunk, message.MessageTypeToolResponse, rtDependence)
|
||||
|
||||
var cmData *message.Message
|
||||
var err error
|
||||
|
||||
if preToolResponseMsg != nil {
|
||||
cm.ID = preToolResponseMsg.ID
|
||||
cm.CreatedAt = preToolResponseMsg.CreatedAt
|
||||
cm.UpdatedAt = preToolResponseMsg.UpdatedAt
|
||||
if len(toolResponseMsgContent) > 0 {
|
||||
cm.Content = toolResponseMsgContent + "\n" + cm.Content
|
||||
}
|
||||
}
|
||||
|
||||
cmData, err = crossmessage.DefaultSVC().Create(ctx, cm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sendMsg := buildSendMsg(ctx, cmData, true, rtDependence)
|
||||
|
||||
mh.messageEvent.SendMsgEvent(entity.RunEventMessageCompleted, sendMsg, mh.sw)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mh *MesssageEventHanlder) handlerSuggest(ctx context.Context, chunk *entity.AgentRespEvent, rtDependence *AgentRuntime) error {
|
||||
cm := buildAgentMessage2Create(ctx, chunk, message.MessageTypeFlowUp, rtDependence)
|
||||
|
||||
cmData, err := crossmessage.DefaultSVC().Create(ctx, cm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sendMsg := buildSendMsg(ctx, cmData, true, rtDependence)
|
||||
|
||||
mh.messageEvent.SendMsgEvent(entity.RunEventMessageCompleted, sendMsg, mh.sw)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mh *MesssageEventHanlder) handlerKnowledge(ctx context.Context, chunk *entity.AgentRespEvent, rtDependence *AgentRuntime) error {
|
||||
cm := buildAgentMessage2Create(ctx, chunk, message.MessageTypeKnowledge, rtDependence)
|
||||
cmData, err := crossmessage.DefaultSVC().Create(ctx, cm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sendMsg := buildSendMsg(ctx, cmData, true, rtDependence)
|
||||
|
||||
mh.messageEvent.SendMsgEvent(entity.RunEventMessageCompleted, sendMsg, mh.sw)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mh *MesssageEventHanlder) handlerAnswer(ctx context.Context, msg *entity.ChunkMessageItem, usage *msgEntity.UsageExt, rtDependence *AgentRuntime, preAnswerMsg *msgEntity.Message) error {
|
||||
|
||||
if len(msg.Content) == 0 && len(ptr.From(msg.ReasoningContent)) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
msg.IsFinish = true
|
||||
|
||||
if msg.Ext == nil {
|
||||
msg.Ext = map[string]string{}
|
||||
}
|
||||
if usage != nil {
|
||||
msg.Ext[string(msgEntity.MessageExtKeyToken)] = strconv.FormatInt(usage.TotalCount, 10)
|
||||
msg.Ext[string(msgEntity.MessageExtKeyInputTokens)] = strconv.FormatInt(usage.InputTokens, 10)
|
||||
msg.Ext[string(msgEntity.MessageExtKeyOutputTokens)] = strconv.FormatInt(usage.OutputTokens, 10)
|
||||
|
||||
rtDependence.Usage = &agentrun.Usage{
|
||||
LlmPromptTokens: usage.InputTokens,
|
||||
LlmCompletionTokens: usage.OutputTokens,
|
||||
LlmTotalTokens: usage.TotalCount,
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok := msg.Ext[string(msgEntity.MessageExtKeyTimeCost)]; !ok {
|
||||
msg.Ext[string(msgEntity.MessageExtKeyTimeCost)] = fmt.Sprintf("%.1f", float64(time.Since(rtDependence.GetStartTime()).Milliseconds())/1000.00)
|
||||
}
|
||||
|
||||
buildModelContent := &schema.Message{
|
||||
Role: schema.Assistant,
|
||||
Content: msg.Content,
|
||||
}
|
||||
|
||||
mc, err := json.Marshal(buildModelContent)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
preAnswerMsg.Content = msg.Content
|
||||
preAnswerMsg.ReasoningContent = ptr.From(msg.ReasoningContent)
|
||||
preAnswerMsg.Ext = msg.Ext
|
||||
preAnswerMsg.ContentType = msg.ContentType
|
||||
preAnswerMsg.ModelContent = string(mc)
|
||||
preAnswerMsg.CreatedAt = 0
|
||||
preAnswerMsg.UpdatedAt = 0
|
||||
|
||||
_, err = crossmessage.DefaultSVC().Create(ctx, preAnswerMsg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mh.messageEvent.SendMsgEvent(entity.RunEventMessageCompleted, msg, mh.sw)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mh *MesssageEventHanlder) handlerFinalAnswerFinish(ctx context.Context, rtDependence *AgentRuntime) error {
|
||||
cm := buildAgentMessage2Create(ctx, nil, message.MessageTypeVerbose, rtDependence)
|
||||
cmData, err := crossmessage.DefaultSVC().Create(ctx, cm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sendMsg := buildSendMsg(ctx, cmData, true, rtDependence)
|
||||
|
||||
mh.messageEvent.SendMsgEvent(entity.RunEventMessageCompleted, sendMsg, mh.sw)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mh *MesssageEventHanlder) handlerInterruptVerbose(ctx context.Context, chunk *entity.AgentRespEvent, rtDependence *AgentRuntime) error {
|
||||
cm := buildAgentMessage2Create(ctx, chunk, message.MessageTypeInterrupt, rtDependence)
|
||||
cmData, err := crossmessage.DefaultSVC().Create(ctx, cm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sendMsg := buildSendMsg(ctx, cmData, true, rtDependence)
|
||||
|
||||
mh.messageEvent.SendMsgEvent(entity.RunEventMessageCompleted, sendMsg, mh.sw)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mh *MesssageEventHanlder) handlerWfUsage(ctx context.Context, msg *entity.ChunkMessageItem, usage *msgEntity.UsageExt) error {
|
||||
|
||||
if msg.Ext == nil {
|
||||
msg.Ext = map[string]string{}
|
||||
}
|
||||
if usage != nil {
|
||||
msg.Ext[string(msgEntity.MessageExtKeyToken)] = strconv.FormatInt(usage.TotalCount, 10)
|
||||
msg.Ext[string(msgEntity.MessageExtKeyInputTokens)] = strconv.FormatInt(usage.InputTokens, 10)
|
||||
msg.Ext[string(msgEntity.MessageExtKeyOutputTokens)] = strconv.FormatInt(usage.OutputTokens, 10)
|
||||
}
|
||||
|
||||
_, err := crossmessage.DefaultSVC().Edit(ctx, &msgEntity.Message{
|
||||
ID: msg.ID,
|
||||
Ext: msg.Ext,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mh.messageEvent.SendMsgEvent(entity.RunEventMessageCompleted, msg, mh.sw)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mh *MesssageEventHanlder) handlerInterrupt(ctx context.Context, chunk *entity.AgentRespEvent, rtDependence *AgentRuntime, firstAnswerMsg *msgEntity.Message, reasoningContent string) error {
|
||||
interruptData, cType, err := parseInterruptData(ctx, chunk.Interrupt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
preMsg, err := preCreateAnswer(ctx, rtDependence)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
deltaAnswer := &entity.ChunkMessageItem{
|
||||
ID: preMsg.ID,
|
||||
ConversationID: preMsg.ConversationID,
|
||||
SectionID: preMsg.SectionID,
|
||||
RunID: preMsg.RunID,
|
||||
AgentID: preMsg.AgentID,
|
||||
Role: entity.RoleType(preMsg.Role),
|
||||
Content: interruptData,
|
||||
MessageType: preMsg.MessageType,
|
||||
ContentType: cType,
|
||||
ReplyID: preMsg.RunID,
|
||||
Ext: preMsg.Ext,
|
||||
IsFinish: false,
|
||||
}
|
||||
|
||||
mh.messageEvent.SendMsgEvent(entity.RunEventMessageDelta, deltaAnswer, mh.sw)
|
||||
finalAnswer := deepcopy.Copy(deltaAnswer).(*entity.ChunkMessageItem)
|
||||
if len(reasoningContent) > 0 && firstAnswerMsg == nil {
|
||||
finalAnswer.ReasoningContent = ptr.Of(reasoningContent)
|
||||
}
|
||||
usage := func() *msgEntity.UsageExt {
|
||||
if rtDependence.GetUsage() != nil {
|
||||
return &msgEntity.UsageExt{
|
||||
TotalCount: rtDependence.GetUsage().LlmTotalTokens,
|
||||
InputTokens: rtDependence.GetUsage().LlmPromptTokens,
|
||||
OutputTokens: rtDependence.GetUsage().LlmCompletionTokens,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
err = mh.handlerAnswer(ctx, finalAnswer, usage(), rtDependence, preMsg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = mh.handlerInterruptVerbose(ctx, chunk, rtDependence)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mh *MesssageEventHanlder) handlerWfInterruptMsg(ctx context.Context, stateMsg *crossworkflow.StateMessage, rtDependence *AgentRuntime) {
|
||||
interruptData, cType, err := handlerWfInterruptEvent(ctx, stateMsg.InterruptEvent)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
preMsg, err := preCreateAnswer(ctx, rtDependence)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
deltaAnswer := &entity.ChunkMessageItem{
|
||||
ID: preMsg.ID,
|
||||
ConversationID: preMsg.ConversationID,
|
||||
SectionID: preMsg.SectionID,
|
||||
RunID: preMsg.RunID,
|
||||
AgentID: preMsg.AgentID,
|
||||
Role: entity.RoleType(preMsg.Role),
|
||||
Content: interruptData,
|
||||
MessageType: preMsg.MessageType,
|
||||
ContentType: cType,
|
||||
ReplyID: preMsg.RunID,
|
||||
Ext: preMsg.Ext,
|
||||
IsFinish: false,
|
||||
}
|
||||
|
||||
mh.messageEvent.SendMsgEvent(entity.RunEventMessageDelta, deltaAnswer, mh.sw)
|
||||
finalAnswer := deepcopy.Copy(deltaAnswer).(*entity.ChunkMessageItem)
|
||||
|
||||
err = mh.handlerAnswer(ctx, finalAnswer, nil, rtDependence, preMsg)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = mh.handlerInterruptVerbose(ctx, &entity.AgentRespEvent{
|
||||
EventType: message.MessageTypeInterrupt,
|
||||
Interrupt: &singleagent.InterruptInfo{
|
||||
|
||||
InterruptType: singleagent.InterruptEventType(stateMsg.InterruptEvent.EventType),
|
||||
InterruptID: strconv.FormatInt(stateMsg.InterruptEvent.ID, 10),
|
||||
ChatflowInterrupt: stateMsg,
|
||||
},
|
||||
}, rtDependence)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (mh *MesssageEventHanlder) HandlerInput(ctx context.Context, rtDependence *AgentRuntime) (*msgEntity.Message, error) {
|
||||
msgMeta := buildAgentMessage2Create(ctx, nil, message.MessageTypeQuestion, rtDependence)
|
||||
|
||||
cm, err := crossmessage.DefaultSVC().Create(ctx, msgMeta)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ackErr := mh.handlerAckMessage(ctx, cm)
|
||||
if ackErr != nil {
|
||||
return msgMeta, ackErr
|
||||
}
|
||||
return cm, nil
|
||||
}
|
||||
|
|
@ -0,0 +1,214 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/cloudwego/eino/schema"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/app/bot_common"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/agentrun"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/singleagent"
|
||||
crossmessage "github.com/coze-dev/coze-studio/backend/crossdomain/contract/message"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/repository"
|
||||
msgEntity "github.com/coze-dev/coze-studio/backend/domain/conversation/message/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/imagex"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/logs"
|
||||
"github.com/coze-dev/coze-studio/backend/types/errno"
|
||||
)
|
||||
|
||||
type AgentRuntime struct {
|
||||
RunRecord *entity.RunRecordMeta
|
||||
AgentInfo *singleagent.SingleAgent
|
||||
QuestionMsgID int64
|
||||
RunMeta *entity.AgentRunMeta
|
||||
StartTime time.Time
|
||||
Input *msgEntity.Message
|
||||
HistoryMsg []*msgEntity.Message
|
||||
Usage *agentrun.Usage
|
||||
SW *schema.StreamWriter[*entity.AgentRunResponse]
|
||||
|
||||
RunProcess *RunProcess
|
||||
RunRecordRepo repository.RunRecordRepo
|
||||
ImagexClient imagex.ImageX
|
||||
MessageEvent *Event
|
||||
}
|
||||
|
||||
func (rd *AgentRuntime) SetRunRecord(runRecord *entity.RunRecordMeta) {
|
||||
rd.RunRecord = runRecord
|
||||
}
|
||||
|
||||
func (rd *AgentRuntime) GetRunRecord() *entity.RunRecordMeta {
|
||||
return rd.RunRecord
|
||||
}
|
||||
|
||||
func (rd *AgentRuntime) SetUsage(usage *agentrun.Usage) {
|
||||
rd.Usage = usage
|
||||
}
|
||||
func (rd *AgentRuntime) GetUsage() *agentrun.Usage {
|
||||
return rd.Usage
|
||||
}
|
||||
|
||||
func (rd *AgentRuntime) SetRunMeta(arm *entity.AgentRunMeta) {
|
||||
rd.RunMeta = arm
|
||||
}
|
||||
func (rd *AgentRuntime) GetRunMeta() *entity.AgentRunMeta {
|
||||
return rd.RunMeta
|
||||
}
|
||||
func (rd *AgentRuntime) SetAgentInfo(agentInfo *singleagent.SingleAgent) {
|
||||
rd.AgentInfo = agentInfo
|
||||
}
|
||||
func (rd *AgentRuntime) GetAgentInfo() *singleagent.SingleAgent {
|
||||
return rd.AgentInfo
|
||||
}
|
||||
func (rd *AgentRuntime) SetQuestionMsgID(msgID int64) {
|
||||
rd.QuestionMsgID = msgID
|
||||
}
|
||||
func (rd *AgentRuntime) GetQuestionMsgID() int64 {
|
||||
return rd.QuestionMsgID
|
||||
}
|
||||
func (rd *AgentRuntime) SetStartTime(t time.Time) {
|
||||
rd.StartTime = t
|
||||
}
|
||||
func (rd *AgentRuntime) GetStartTime() time.Time {
|
||||
return rd.StartTime
|
||||
}
|
||||
func (rd *AgentRuntime) SetInput(input *msgEntity.Message) {
|
||||
rd.Input = input
|
||||
}
|
||||
func (rd *AgentRuntime) GetInput() *msgEntity.Message {
|
||||
return rd.Input
|
||||
}
|
||||
|
||||
func (rd *AgentRuntime) SetHistoryMsg(histroyMsg []*msgEntity.Message) {
|
||||
rd.HistoryMsg = histroyMsg
|
||||
}
|
||||
|
||||
func (rd *AgentRuntime) GetHistory() []*msgEntity.Message {
|
||||
return rd.HistoryMsg
|
||||
}
|
||||
|
||||
func (art *AgentRuntime) Run(ctx context.Context) (err error) {
|
||||
|
||||
agentInfo, err := getAgentInfo(ctx, art.GetRunMeta().AgentID, art.GetRunMeta().IsDraft)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
art.SetAgentInfo(agentInfo)
|
||||
|
||||
history, err := art.getHistory(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
runRecord, err := art.createRunRecord(ctx)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
art.SetRunRecord(runRecord)
|
||||
art.SetHistoryMsg(history)
|
||||
|
||||
defer func() {
|
||||
srRecord := buildSendRunRecord(ctx, runRecord, entity.RunStatusCompleted)
|
||||
if err != nil {
|
||||
srRecord.Error = &entity.RunError{
|
||||
Code: errno.ErrConversationAgentRunError,
|
||||
Msg: err.Error(),
|
||||
}
|
||||
art.RunProcess.StepToFailed(ctx, srRecord, art.SW)
|
||||
return
|
||||
}
|
||||
art.RunProcess.StepToComplete(ctx, srRecord, art.SW, art.GetUsage())
|
||||
}()
|
||||
mh := &MesssageEventHanlder{
|
||||
messageEvent: art.MessageEvent,
|
||||
sw: art.SW,
|
||||
}
|
||||
input, err := mh.HandlerInput(ctx, art)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
art.SetInput(input)
|
||||
|
||||
art.SetQuestionMsgID(input.ID)
|
||||
|
||||
if art.GetAgentInfo().BotMode == bot_common.BotMode_WorkflowMode {
|
||||
err = art.ChatflowRun(ctx, art.ImagexClient)
|
||||
} else {
|
||||
err = art.AgentStreamExecute(ctx, art.ImagexClient)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (art *AgentRuntime) getHistory(ctx context.Context) ([]*msgEntity.Message, error) {
|
||||
|
||||
conversationTurns := getAgentHistoryRounds(art.GetAgentInfo())
|
||||
|
||||
runRecordList, err := art.RunRecordRepo.List(ctx, &entity.ListRunRecordMeta{
|
||||
ConversationID: art.GetRunMeta().ConversationID,
|
||||
SectionID: art.GetRunMeta().SectionID,
|
||||
Limit: conversationTurns,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(runRecordList) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
runIDS := concactRunID(runRecordList)
|
||||
history, err := crossmessage.DefaultSVC().GetByRunIDs(ctx, art.GetRunMeta().ConversationID, runIDS)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return history, nil
|
||||
}
|
||||
|
||||
func concactRunID(rr []*entity.RunRecordMeta) []int64 {
|
||||
ids := make([]int64, 0, len(rr))
|
||||
for _, c := range rr {
|
||||
ids = append(ids, c.ID)
|
||||
}
|
||||
|
||||
return ids
|
||||
}
|
||||
|
||||
func (art *AgentRuntime) createRunRecord(ctx context.Context) (*entity.RunRecordMeta, error) {
|
||||
runPoData, err := art.RunRecordRepo.Create(ctx, art.GetRunMeta())
|
||||
if err != nil {
|
||||
logs.CtxErrorf(ctx, "RunRecordRepo.Create error: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
srRecord := buildSendRunRecord(ctx, runPoData, entity.RunStatusCreated)
|
||||
|
||||
art.RunProcess.StepToCreate(ctx, srRecord, art.SW)
|
||||
|
||||
err = art.RunProcess.StepToInProgress(ctx, srRecord, art.SW)
|
||||
if err != nil {
|
||||
logs.CtxErrorf(ctx, "runProcess.StepToInProgress error: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
return runPoData, nil
|
||||
}
|
||||
|
|
@ -30,8 +30,8 @@ import (
|
|||
)
|
||||
|
||||
type RunProcess struct {
|
||||
event *Event
|
||||
|
||||
event *Event
|
||||
SW *schema.StreamWriter[*entity.AgentRunResponse]
|
||||
RunRecordRepo repository.RunRecordRepo
|
||||
}
|
||||
|
||||
|
|
@ -115,7 +115,6 @@ func (r *RunProcess) StepToFailed(ctx context.Context, srRecord *entity.ChunkRun
|
|||
Code: srRecord.Error.Code,
|
||||
Msg: srRecord.Error.Msg,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (r *RunProcess) StepToDone(sw *schema.StreamWriter[*entity.AgentRunResponse]) {
|
||||
|
|
@ -0,0 +1,450 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package internal
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"sync"
|
||||
|
||||
"github.com/cloudwego/eino/schema"
|
||||
"github.com/mohae/deepcopy"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/agentrun"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/message"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/singleagent"
|
||||
crossagent "github.com/coze-dev/coze-studio/backend/crossdomain/contract/agent"
|
||||
crossmessage "github.com/coze-dev/coze-studio/backend/crossdomain/contract/message"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/entity"
|
||||
msgEntity "github.com/coze-dev/coze-studio/backend/domain/conversation/message/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/imagex"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/logs"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/safego"
|
||||
"github.com/coze-dev/coze-studio/backend/types/errno"
|
||||
)
|
||||
|
||||
func (art *AgentRuntime) AgentStreamExecute(ctx context.Context, imagex imagex.ImageX) (err error) {
|
||||
mainChan := make(chan *entity.AgentRespEvent, 100)
|
||||
|
||||
ar := &crossagent.AgentRuntime{
|
||||
AgentVersion: art.GetRunMeta().Version,
|
||||
SpaceID: art.GetRunMeta().SpaceID,
|
||||
AgentID: art.GetRunMeta().AgentID,
|
||||
IsDraft: art.GetRunMeta().IsDraft,
|
||||
UserID: art.GetRunMeta().UserID,
|
||||
ConnectorID: art.GetRunMeta().ConnectorID,
|
||||
PreRetrieveTools: art.GetRunMeta().PreRetrieveTools,
|
||||
Input: transMessageToSchemaMessage(ctx, []*msgEntity.Message{art.GetInput()}, imagex)[0],
|
||||
HistoryMsg: transMessageToSchemaMessage(ctx, historyPairs(art.GetHistory()), imagex),
|
||||
ResumeInfo: parseResumeInfo(ctx, art.GetHistory()),
|
||||
}
|
||||
|
||||
streamer, err := crossagent.DefaultSVC().StreamExecute(ctx, ar)
|
||||
if err != nil {
|
||||
return errors.New(errorx.ErrorWithoutStack(err))
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
safego.Go(ctx, func() {
|
||||
defer wg.Done()
|
||||
art.pull(ctx, mainChan, streamer)
|
||||
})
|
||||
|
||||
safego.Go(ctx, func() {
|
||||
defer wg.Done()
|
||||
art.push(ctx, mainChan)
|
||||
})
|
||||
|
||||
wg.Wait()
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (art *AgentRuntime) push(ctx context.Context, mainChan chan *entity.AgentRespEvent) {
|
||||
|
||||
mh := &MesssageEventHanlder{
|
||||
sw: art.SW,
|
||||
messageEvent: art.MessageEvent,
|
||||
}
|
||||
|
||||
var err error
|
||||
defer func() {
|
||||
if err != nil {
|
||||
logs.CtxErrorf(ctx, "run.push error: %v", err)
|
||||
mh.handlerErr(ctx, err)
|
||||
}
|
||||
}()
|
||||
|
||||
reasoningContent := bytes.NewBuffer([]byte{})
|
||||
|
||||
var firstAnswerMsg *msgEntity.Message
|
||||
var reasoningMsg *msgEntity.Message
|
||||
isSendFinishAnswer := false
|
||||
var preToolResponseMsg *msgEntity.Message
|
||||
toolResponseMsgContent := bytes.NewBuffer([]byte{})
|
||||
for {
|
||||
chunk, ok := <-mainChan
|
||||
if !ok || chunk == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if chunk.Err != nil {
|
||||
if errors.Is(chunk.Err, io.EOF) {
|
||||
if !isSendFinishAnswer {
|
||||
isSendFinishAnswer = true
|
||||
if firstAnswerMsg != nil && len(reasoningContent.String()) > 0 {
|
||||
art.saveReasoningContent(ctx, firstAnswerMsg, reasoningContent.String())
|
||||
reasoningContent.Reset()
|
||||
}
|
||||
|
||||
finishErr := mh.handlerFinalAnswerFinish(ctx, art)
|
||||
if finishErr != nil {
|
||||
err = finishErr
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
mh.handlerErr(ctx, chunk.Err)
|
||||
return
|
||||
}
|
||||
|
||||
switch chunk.EventType {
|
||||
case message.MessageTypeFunctionCall:
|
||||
if chunk.FuncCall != nil && chunk.FuncCall.ResponseMeta != nil {
|
||||
if usage := handlerUsage(chunk.FuncCall.ResponseMeta); usage != nil {
|
||||
art.SetUsage(&agentrun.Usage{
|
||||
LlmPromptTokens: usage.InputTokens,
|
||||
LlmCompletionTokens: usage.OutputTokens,
|
||||
LlmTotalTokens: usage.TotalCount,
|
||||
})
|
||||
}
|
||||
}
|
||||
err = mh.handlerFunctionCall(ctx, chunk, art)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if preToolResponseMsg == nil {
|
||||
var cErr error
|
||||
preToolResponseMsg, cErr = preCreateAnswer(ctx, art)
|
||||
if cErr != nil {
|
||||
err = cErr
|
||||
return
|
||||
}
|
||||
}
|
||||
case message.MessageTypeToolResponse:
|
||||
err = mh.handlerTooResponse(ctx, chunk, art, preToolResponseMsg, toolResponseMsgContent.String())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
preToolResponseMsg = nil // reset
|
||||
case message.MessageTypeKnowledge:
|
||||
err = mh.handlerKnowledge(ctx, chunk, art)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
case message.MessageTypeToolMidAnswer:
|
||||
fullMidAnswerContent := bytes.NewBuffer([]byte{})
|
||||
var usage *msgEntity.UsageExt
|
||||
toolMidAnswerMsg, cErr := preCreateAnswer(ctx, art)
|
||||
|
||||
if cErr != nil {
|
||||
err = cErr
|
||||
return
|
||||
}
|
||||
|
||||
var preMsgIsFinish = false
|
||||
for {
|
||||
streamMsg, receErr := chunk.ToolMidAnswer.Recv()
|
||||
if receErr != nil {
|
||||
if errors.Is(receErr, io.EOF) {
|
||||
break
|
||||
}
|
||||
err = receErr
|
||||
return
|
||||
}
|
||||
if preMsgIsFinish {
|
||||
toolMidAnswerMsg, cErr = preCreateAnswer(ctx, art)
|
||||
if cErr != nil {
|
||||
err = cErr
|
||||
return
|
||||
}
|
||||
preMsgIsFinish = false
|
||||
}
|
||||
if streamMsg == nil {
|
||||
continue
|
||||
}
|
||||
if firstAnswerMsg == nil && len(streamMsg.Content) > 0 {
|
||||
if reasoningMsg != nil {
|
||||
toolMidAnswerMsg = deepcopy.Copy(reasoningMsg).(*msgEntity.Message)
|
||||
}
|
||||
firstAnswerMsg = deepcopy.Copy(toolMidAnswerMsg).(*msgEntity.Message)
|
||||
}
|
||||
|
||||
if streamMsg.Extra != nil {
|
||||
if val, ok := streamMsg.Extra["workflow_node_name"]; ok && val != nil {
|
||||
toolMidAnswerMsg.Ext["message_title"] = val.(string)
|
||||
}
|
||||
}
|
||||
|
||||
sendMidAnswerMsg := buildSendMsg(ctx, toolMidAnswerMsg, false, art)
|
||||
sendMidAnswerMsg.Content = streamMsg.Content
|
||||
toolResponseMsgContent.WriteString(streamMsg.Content)
|
||||
fullMidAnswerContent.WriteString(streamMsg.Content)
|
||||
|
||||
art.MessageEvent.SendMsgEvent(entity.RunEventMessageDelta, sendMidAnswerMsg, art.SW)
|
||||
|
||||
if streamMsg != nil && streamMsg.ResponseMeta != nil {
|
||||
usage = handlerUsage(streamMsg.ResponseMeta)
|
||||
}
|
||||
|
||||
if streamMsg.Extra["is_finish"] == true {
|
||||
preMsgIsFinish = true
|
||||
sendMidAnswerMsg := buildSendMsg(ctx, toolMidAnswerMsg, false, art)
|
||||
sendMidAnswerMsg.Content = fullMidAnswerContent.String()
|
||||
fullMidAnswerContent.Reset()
|
||||
hfErr := mh.handlerAnswer(ctx, sendMidAnswerMsg, usage, art, toolMidAnswerMsg)
|
||||
if hfErr != nil {
|
||||
err = hfErr
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case message.MessageTypeToolAsAnswer:
|
||||
var usage *msgEntity.UsageExt
|
||||
fullContent := bytes.NewBuffer([]byte{})
|
||||
toolAsAnswerMsg, cErr := preCreateAnswer(ctx, art)
|
||||
if cErr != nil {
|
||||
err = cErr
|
||||
return
|
||||
}
|
||||
if firstAnswerMsg == nil {
|
||||
firstAnswerMsg = toolAsAnswerMsg
|
||||
}
|
||||
|
||||
for {
|
||||
streamMsg, receErr := chunk.ToolAsAnswer.Recv()
|
||||
if receErr != nil {
|
||||
if errors.Is(receErr, io.EOF) {
|
||||
|
||||
answer := buildSendMsg(ctx, toolAsAnswerMsg, false, art)
|
||||
answer.Content = fullContent.String()
|
||||
hfErr := mh.handlerAnswer(ctx, answer, usage, art, toolAsAnswerMsg)
|
||||
if hfErr != nil {
|
||||
err = hfErr
|
||||
return
|
||||
}
|
||||
break
|
||||
}
|
||||
err = receErr
|
||||
return
|
||||
}
|
||||
|
||||
if streamMsg != nil && streamMsg.ResponseMeta != nil {
|
||||
usage = handlerUsage(streamMsg.ResponseMeta)
|
||||
}
|
||||
sendMsg := buildSendMsg(ctx, toolAsAnswerMsg, false, art)
|
||||
fullContent.WriteString(streamMsg.Content)
|
||||
sendMsg.Content = streamMsg.Content
|
||||
art.MessageEvent.SendMsgEvent(entity.RunEventMessageDelta, sendMsg, art.SW)
|
||||
}
|
||||
|
||||
case message.MessageTypeAnswer:
|
||||
fullContent := bytes.NewBuffer([]byte{})
|
||||
var usage *msgEntity.UsageExt
|
||||
var isToolCalls = false
|
||||
var modelAnswerMsg *msgEntity.Message
|
||||
for {
|
||||
streamMsg, receErr := chunk.ModelAnswer.Recv()
|
||||
if receErr != nil {
|
||||
if errors.Is(receErr, io.EOF) {
|
||||
|
||||
if isToolCalls {
|
||||
break
|
||||
}
|
||||
if modelAnswerMsg == nil {
|
||||
break
|
||||
}
|
||||
answer := buildSendMsg(ctx, modelAnswerMsg, false, art)
|
||||
answer.Content = fullContent.String()
|
||||
hfErr := mh.handlerAnswer(ctx, answer, usage, art, modelAnswerMsg)
|
||||
if hfErr != nil {
|
||||
err = hfErr
|
||||
return
|
||||
}
|
||||
break
|
||||
}
|
||||
err = receErr
|
||||
return
|
||||
}
|
||||
|
||||
if streamMsg != nil && len(streamMsg.ToolCalls) > 0 {
|
||||
isToolCalls = true
|
||||
}
|
||||
|
||||
if streamMsg != nil && streamMsg.ResponseMeta != nil {
|
||||
usage = handlerUsage(streamMsg.ResponseMeta)
|
||||
}
|
||||
|
||||
if streamMsg != nil && len(streamMsg.ReasoningContent) == 0 && len(streamMsg.Content) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
if len(streamMsg.ReasoningContent) > 0 {
|
||||
if reasoningMsg == nil {
|
||||
reasoningMsg, err = preCreateAnswer(ctx, art)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
sendReasoningMsg := buildSendMsg(ctx, reasoningMsg, false, art)
|
||||
reasoningContent.WriteString(streamMsg.ReasoningContent)
|
||||
sendReasoningMsg.ReasoningContent = ptr.Of(streamMsg.ReasoningContent)
|
||||
art.MessageEvent.SendMsgEvent(entity.RunEventMessageDelta, sendReasoningMsg, art.SW)
|
||||
}
|
||||
if len(streamMsg.Content) > 0 {
|
||||
|
||||
if modelAnswerMsg == nil {
|
||||
modelAnswerMsg, err = preCreateAnswer(ctx, art)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if firstAnswerMsg == nil {
|
||||
if reasoningMsg != nil {
|
||||
modelAnswerMsg.ID = reasoningMsg.ID
|
||||
}
|
||||
firstAnswerMsg = modelAnswerMsg
|
||||
}
|
||||
}
|
||||
|
||||
sendAnswerMsg := buildSendMsg(ctx, modelAnswerMsg, false, art)
|
||||
fullContent.WriteString(streamMsg.Content)
|
||||
sendAnswerMsg.Content = streamMsg.Content
|
||||
art.MessageEvent.SendMsgEvent(entity.RunEventMessageDelta, sendAnswerMsg, art.SW)
|
||||
}
|
||||
}
|
||||
|
||||
case message.MessageTypeFlowUp:
|
||||
if isSendFinishAnswer {
|
||||
|
||||
if firstAnswerMsg != nil && len(reasoningContent.String()) > 0 {
|
||||
art.saveReasoningContent(ctx, firstAnswerMsg, reasoningContent.String())
|
||||
}
|
||||
|
||||
isSendFinishAnswer = true
|
||||
finishErr := mh.handlerFinalAnswerFinish(ctx, art)
|
||||
if finishErr != nil {
|
||||
err = finishErr
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err = mh.handlerSuggest(ctx, chunk, art)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
case message.MessageTypeInterrupt:
|
||||
err = mh.handlerInterrupt(ctx, chunk, art, firstAnswerMsg, reasoningContent.String())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (art *AgentRuntime) pull(_ context.Context, mainChan chan *entity.AgentRespEvent, events *schema.StreamReader[*crossagent.AgentEvent]) {
|
||||
defer func() {
|
||||
close(mainChan)
|
||||
}()
|
||||
|
||||
for {
|
||||
rm, re := events.Recv()
|
||||
if re != nil {
|
||||
errChunk := &entity.AgentRespEvent{
|
||||
Err: re,
|
||||
}
|
||||
mainChan <- errChunk
|
||||
return
|
||||
}
|
||||
|
||||
eventType, tErr := transformEventMap(rm.EventType)
|
||||
|
||||
if tErr != nil {
|
||||
errChunk := &entity.AgentRespEvent{
|
||||
Err: tErr,
|
||||
}
|
||||
mainChan <- errChunk
|
||||
return
|
||||
}
|
||||
|
||||
respChunk := &entity.AgentRespEvent{
|
||||
EventType: eventType,
|
||||
ModelAnswer: rm.ChatModelAnswer,
|
||||
ToolsMessage: rm.ToolsMessage,
|
||||
FuncCall: rm.FuncCall,
|
||||
Knowledge: rm.Knowledge,
|
||||
Suggest: rm.Suggest,
|
||||
Interrupt: rm.Interrupt,
|
||||
|
||||
ToolMidAnswer: rm.ToolMidAnswer,
|
||||
ToolAsAnswer: rm.ToolAsChatModelAnswer,
|
||||
}
|
||||
|
||||
mainChan <- respChunk
|
||||
}
|
||||
}
|
||||
|
||||
func transformEventMap(eventType singleagent.EventType) (message.MessageType, error) {
|
||||
var eType message.MessageType
|
||||
switch eventType {
|
||||
case singleagent.EventTypeOfFuncCall:
|
||||
return message.MessageTypeFunctionCall, nil
|
||||
case singleagent.EventTypeOfKnowledge:
|
||||
return message.MessageTypeKnowledge, nil
|
||||
case singleagent.EventTypeOfToolsMessage:
|
||||
return message.MessageTypeToolResponse, nil
|
||||
case singleagent.EventTypeOfChatModelAnswer:
|
||||
return message.MessageTypeAnswer, nil
|
||||
case singleagent.EventTypeOfToolsAsChatModelStream:
|
||||
return message.MessageTypeToolAsAnswer, nil
|
||||
case singleagent.EventTypeOfToolMidAnswer:
|
||||
return message.MessageTypeToolMidAnswer, nil
|
||||
case singleagent.EventTypeOfSuggest:
|
||||
return message.MessageTypeFlowUp, nil
|
||||
case singleagent.EventTypeOfInterrupt:
|
||||
return message.MessageTypeInterrupt, nil
|
||||
}
|
||||
return eType, errorx.New(errno.ErrReplyUnknowEventType)
|
||||
}
|
||||
|
||||
func (art *AgentRuntime) saveReasoningContent(ctx context.Context, firstAnswerMsg *msgEntity.Message, reasoningContent string) {
|
||||
_, err := crossmessage.DefaultSVC().Edit(ctx, &message.Message{
|
||||
ID: firstAnswerMsg.ID,
|
||||
ReasoningContent: reasoningContent,
|
||||
})
|
||||
if err != nil {
|
||||
logs.CtxInfof(ctx, "save reasoning content failed, err: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -23,7 +23,6 @@ import (
|
|||
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/internal/dal"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/internal/dal/model"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
)
|
||||
|
||||
|
|
@ -34,8 +33,9 @@ func NewRunRecordRepo(db *gorm.DB, idGen idgen.IDGenerator) RunRecordRepo {
|
|||
|
||||
type RunRecordRepo interface {
|
||||
Create(ctx context.Context, runMeta *entity.AgentRunMeta) (*entity.RunRecordMeta, error)
|
||||
GetByID(ctx context.Context, id int64) (*entity.RunRecord, error)
|
||||
GetByID(ctx context.Context, id int64) (*entity.RunRecordMeta, error)
|
||||
Cancel(ctx context.Context, req *entity.CancelRunMeta) (*entity.RunRecordMeta, error)
|
||||
Delete(ctx context.Context, id []int64) error
|
||||
UpdateByID(ctx context.Context, id int64, update *entity.UpdateMeta) error
|
||||
List(ctx context.Context, conversationID int64, sectionID int64, limit int32) ([]*model.RunRecord, error)
|
||||
List(ctx context.Context, meta *entity.ListRunRecordMeta) ([]*entity.RunRecordMeta, error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ import (
|
|||
|
||||
type Run interface {
|
||||
AgentRun(ctx context.Context, req *entity.AgentRunMeta) (*schema.StreamReader[*entity.AgentRunResponse], error)
|
||||
|
||||
Delete(ctx context.Context, runID []int64) error
|
||||
Create(ctx context.Context, runRecord *entity.AgentRunMeta) (*entity.RunRecordMeta, error)
|
||||
List(ctx context.Context, ListMeta *entity.ListRunRecordMeta) ([]*entity.RunRecordMeta, error)
|
||||
GetByID(ctx context.Context, runID int64) (*entity.RunRecordMeta, error)
|
||||
Cancel(ctx context.Context, req *entity.CancelRunMeta) (*entity.RunRecordMeta, error)
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -17,7 +17,18 @@
|
|||
package agentrun
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/mock/gomock"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/internal/dal/model"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/repository"
|
||||
mock "github.com/coze-dev/coze-studio/backend/internal/mock/infra/contract/idgen"
|
||||
"github.com/coze-dev/coze-studio/backend/internal/mock/infra/contract/orm"
|
||||
)
|
||||
|
||||
func TestAgentRun(t *testing.T) {
|
||||
|
|
@ -97,3 +108,158 @@ func TestAgentRun(t *testing.T) {
|
|||
// assert.NoError(t, err)
|
||||
|
||||
}
|
||||
|
||||
func TestRunImpl_List(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
mockDBGen := orm.NewMockDB()
|
||||
mockDBGen.AddTable(&model.RunRecord{}).AddRows(
|
||||
&model.RunRecord{
|
||||
ID: 1,
|
||||
ConversationID: 123,
|
||||
AgentID: 456,
|
||||
SectionID: 789,
|
||||
UserID: "123456",
|
||||
CreatedAt: time.Now().Unix(),
|
||||
},
|
||||
&model.RunRecord{
|
||||
ID: 2,
|
||||
ConversationID: 123,
|
||||
AgentID: 456,
|
||||
SectionID: 789,
|
||||
UserID: "123456",
|
||||
CreatedAt: time.Now().Unix() + 1,
|
||||
}, &model.RunRecord{
|
||||
ID: 3,
|
||||
ConversationID: 123,
|
||||
AgentID: 456,
|
||||
SectionID: 789,
|
||||
UserID: "123456",
|
||||
CreatedAt: time.Now().Unix() + 2,
|
||||
}, &model.RunRecord{
|
||||
ID: 4,
|
||||
ConversationID: 123,
|
||||
AgentID: 456,
|
||||
SectionID: 789,
|
||||
UserID: "123456",
|
||||
CreatedAt: time.Now().Unix() + 3,
|
||||
}, &model.RunRecord{
|
||||
ID: 5,
|
||||
ConversationID: 123,
|
||||
AgentID: 456,
|
||||
SectionID: 789,
|
||||
UserID: "123456",
|
||||
CreatedAt: time.Now().Unix() + 4,
|
||||
},
|
||||
&model.RunRecord{
|
||||
ID: 6,
|
||||
ConversationID: 123,
|
||||
AgentID: 456,
|
||||
SectionID: 789,
|
||||
UserID: "123456",
|
||||
CreatedAt: time.Now().Unix() + 5,
|
||||
}, &model.RunRecord{
|
||||
ID: 7,
|
||||
ConversationID: 123,
|
||||
AgentID: 456,
|
||||
SectionID: 789,
|
||||
UserID: "123456",
|
||||
CreatedAt: time.Now().Unix() + 6,
|
||||
}, &model.RunRecord{
|
||||
ID: 8,
|
||||
ConversationID: 123,
|
||||
AgentID: 456,
|
||||
SectionID: 789,
|
||||
UserID: "123456",
|
||||
CreatedAt: time.Now().Unix() + 7,
|
||||
}, &model.RunRecord{
|
||||
ID: 9,
|
||||
ConversationID: 123,
|
||||
AgentID: 456,
|
||||
SectionID: 789,
|
||||
UserID: "123456",
|
||||
CreatedAt: time.Now().Unix() + 8,
|
||||
},
|
||||
)
|
||||
mockDB, err := mockDBGen.DB()
|
||||
assert.NoError(t, err)
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
mockIDGen := mock.NewMockIDGenerator(ctrl)
|
||||
|
||||
runRecordRepo := repository.NewRunRecordRepo(mockDB, mockIDGen)
|
||||
|
||||
service := &runImpl{
|
||||
Components: Components{
|
||||
RunRecordRepo: runRecordRepo,
|
||||
},
|
||||
}
|
||||
|
||||
t.Run("list success", func(t *testing.T) {
|
||||
|
||||
meta := &entity.ListRunRecordMeta{
|
||||
ConversationID: 123,
|
||||
AgentID: 456,
|
||||
SectionID: 789,
|
||||
Limit: 10,
|
||||
OrderBy: "desc",
|
||||
}
|
||||
|
||||
result, err := service.List(ctx, meta)
|
||||
// check result
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, result, 9)
|
||||
assert.Equal(t, int64(123), result[0].ConversationID)
|
||||
assert.Equal(t, int64(456), result[0].AgentID)
|
||||
})
|
||||
|
||||
t.Run("empty list", func(t *testing.T) {
|
||||
meta := &entity.ListRunRecordMeta{
|
||||
ConversationID: 999, //
|
||||
Limit: 10,
|
||||
OrderBy: "desc",
|
||||
}
|
||||
|
||||
// check result
|
||||
result, err := service.List(ctx, meta)
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, result)
|
||||
})
|
||||
|
||||
t.Run("search with before id", func(t *testing.T) {
|
||||
|
||||
meta := &entity.ListRunRecordMeta{
|
||||
ConversationID: 123,
|
||||
SectionID: 789,
|
||||
AgentID: 456,
|
||||
BeforeID: 5,
|
||||
Limit: 3,
|
||||
OrderBy: "desc",
|
||||
}
|
||||
|
||||
result, err := service.List(ctx, meta)
|
||||
|
||||
// check result
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, result, 3)
|
||||
assert.Equal(t, int64(4), result[0].ID)
|
||||
})
|
||||
t.Run("search with after id and limit", func(t *testing.T) {
|
||||
|
||||
meta := &entity.ListRunRecordMeta{
|
||||
ConversationID: 123,
|
||||
SectionID: 789,
|
||||
AgentID: 456,
|
||||
AfterID: 5,
|
||||
Limit: 3,
|
||||
OrderBy: "desc",
|
||||
}
|
||||
|
||||
result, err := service.List(ctx, meta)
|
||||
|
||||
// check result
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, result, 3)
|
||||
assert.Equal(t, int64(9), result[0].ID)
|
||||
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import (
|
|||
type Conversation = conversation.Conversation
|
||||
|
||||
type CreateMeta struct {
|
||||
Name string `json:"name"`
|
||||
AgentID int64 `json:"agent_id"`
|
||||
UserID int64 `json:"user_id"`
|
||||
ConnectorID int64 `json:"connector_id"`
|
||||
|
|
@ -50,3 +51,8 @@ type ListMeta struct {
|
|||
Limit int `json:"limit"`
|
||||
Page int `json:"page"`
|
||||
}
|
||||
|
||||
type UpdateMeta struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,6 +107,20 @@ func (dao *ConversationDAO) Delete(ctx context.Context, id int64) (int64, error)
|
|||
return updateRes.RowsAffected, err
|
||||
}
|
||||
|
||||
func (dao *ConversationDAO) Update(ctx context.Context, req *entity.UpdateMeta) (*entity.Conversation, error) {
|
||||
updateColumn := make(map[string]interface{})
|
||||
updateColumn[dao.query.Conversation.UpdatedAt.ColumnName().String()] = time.Now().UnixMilli()
|
||||
if len(req.Name) > 0 {
|
||||
updateColumn[dao.query.Conversation.Name.ColumnName().String()] = req.Name
|
||||
}
|
||||
|
||||
_, err := dao.query.Conversation.WithContext(ctx).Where(dao.query.Conversation.ID.Eq(req.ID)).UpdateColumns(updateColumn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dao.GetByID(ctx, req.ID)
|
||||
}
|
||||
|
||||
func (dao *ConversationDAO) Get(ctx context.Context, userID int64, agentID int64, scene int32, connectorID int64) (*entity.Conversation, error) {
|
||||
po, err := dao.query.Conversation.WithContext(ctx).Debug().
|
||||
Where(dao.query.Conversation.CreatorID.Eq(userID)).
|
||||
|
|
@ -133,13 +147,15 @@ func (dao *ConversationDAO) List(ctx context.Context, userID int64, agentID int6
|
|||
do = do.Where(dao.query.Conversation.CreatorID.Eq(userID)).
|
||||
Where(dao.query.Conversation.AgentID.Eq(agentID)).
|
||||
Where(dao.query.Conversation.Scene.Eq(scene)).
|
||||
Where(dao.query.Conversation.ConnectorID.Eq(connectorID))
|
||||
Where(dao.query.Conversation.ConnectorID.Eq(connectorID)).
|
||||
Where(dao.query.Conversation.Status.Eq(int32(conversation.ConversationStatusNormal)))
|
||||
|
||||
do = do.Offset((page - 1) * limit)
|
||||
|
||||
if limit > 0 {
|
||||
do = do.Limit(int(limit) + 1)
|
||||
}
|
||||
do = do.Order(dao.query.Conversation.CreatedAt.Desc())
|
||||
|
||||
poList, err := do.Find()
|
||||
|
||||
|
|
@ -173,6 +189,7 @@ func (dao *ConversationDAO) conversationDO2PO(ctx context.Context, conversation
|
|||
Ext: conversation.Ext,
|
||||
CreatedAt: time.Now().UnixMilli(),
|
||||
UpdatedAt: time.Now().UnixMilli(),
|
||||
Name: conversation.Name,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -188,6 +205,7 @@ func (dao *ConversationDAO) conversationPO2DO(ctx context.Context, c *model.Conv
|
|||
Ext: c.Ext,
|
||||
CreatedAt: c.CreatedAt,
|
||||
UpdatedAt: c.UpdatedAt,
|
||||
Name: c.Name,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -204,6 +222,7 @@ func (dao *ConversationDAO) conversationBatchPO2DO(ctx context.Context, conversa
|
|||
Ext: c.Ext,
|
||||
CreatedAt: c.CreatedAt,
|
||||
UpdatedAt: c.UpdatedAt,
|
||||
Name: c.Name,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
|
@ -9,6 +25,7 @@ const TableNameConversation = "conversation"
|
|||
// Conversation conversation info record
|
||||
type Conversation struct {
|
||||
ID int64 `gorm:"column:id;primaryKey;autoIncrement:true;comment:id" json:"id"` // id
|
||||
Name string `gorm:"column:name;not null;comment:conversation name" json:"name"` // conversation name
|
||||
ConnectorID int64 `gorm:"column:connector_id;not null;comment:Publish Connector ID" json:"connector_id"` // Publish Connector ID
|
||||
AgentID int64 `gorm:"column:agent_id;not null;comment:agent_id" json:"agent_id"` // agent_id
|
||||
Scene int32 `gorm:"column:scene;not null;comment:conversation scene" json:"scene"` // conversation scene
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
|
@ -28,6 +44,7 @@ func newConversation(db *gorm.DB, opts ...gen.DOOption) conversation {
|
|||
tableName := _conversation.conversationDo.TableName()
|
||||
_conversation.ALL = field.NewAsterisk(tableName)
|
||||
_conversation.ID = field.NewInt64(tableName, "id")
|
||||
_conversation.Name = field.NewString(tableName, "name")
|
||||
_conversation.ConnectorID = field.NewInt64(tableName, "connector_id")
|
||||
_conversation.AgentID = field.NewInt64(tableName, "agent_id")
|
||||
_conversation.Scene = field.NewInt32(tableName, "scene")
|
||||
|
|
@ -49,6 +66,7 @@ type conversation struct {
|
|||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // id
|
||||
Name field.String // conversation name
|
||||
ConnectorID field.Int64 // Publish Connector ID
|
||||
AgentID field.Int64 // agent_id
|
||||
Scene field.Int32 // conversation scene
|
||||
|
|
@ -75,6 +93,7 @@ func (c conversation) As(alias string) *conversation {
|
|||
func (c *conversation) updateTableName(table string) *conversation {
|
||||
c.ALL = field.NewAsterisk(table)
|
||||
c.ID = field.NewInt64(table, "id")
|
||||
c.Name = field.NewString(table, "name")
|
||||
c.ConnectorID = field.NewInt64(table, "connector_id")
|
||||
c.AgentID = field.NewInt64(table, "agent_id")
|
||||
c.Scene = field.NewInt32(table, "scene")
|
||||
|
|
@ -100,8 +119,9 @@ func (c *conversation) GetFieldByName(fieldName string) (field.OrderExpr, bool)
|
|||
}
|
||||
|
||||
func (c *conversation) fillFieldMap() {
|
||||
c.fieldMap = make(map[string]field.Expr, 10)
|
||||
c.fieldMap = make(map[string]field.Expr, 11)
|
||||
c.fieldMap["id"] = c.ID
|
||||
c.fieldMap["name"] = c.Name
|
||||
c.fieldMap["connector_id"] = c.ConnectorID
|
||||
c.fieldMap["agent_id"] = c.AgentID
|
||||
c.fieldMap["scene"] = c.Scene
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ type ConversationRepo interface {
|
|||
GetByID(ctx context.Context, id int64) (*entity.Conversation, error)
|
||||
UpdateSection(ctx context.Context, id int64) (int64, error)
|
||||
Get(ctx context.Context, userID int64, agentID int64, scene int32, connectorID int64) (*entity.Conversation, error)
|
||||
Update(ctx context.Context, req *entity.UpdateMeta) (*entity.Conversation, error)
|
||||
Delete(ctx context.Context, id int64) (int64, error)
|
||||
List(ctx context.Context, userID int64, agentID int64, connectorID int64, scene int32, limit int, page int) ([]*entity.Conversation, bool, error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,4 +29,5 @@ type Conversation interface {
|
|||
GetCurrentConversation(ctx context.Context, req *entity.GetCurrent) (*entity.Conversation, error)
|
||||
Delete(ctx context.Context, id int64) error
|
||||
List(ctx context.Context, req *entity.ListMeta) ([]*entity.Conversation, bool, error)
|
||||
Update(ctx context.Context, req *entity.UpdateMeta) (*entity.Conversation, error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,6 +101,11 @@ func (c *conversationImpl) Delete(ctx context.Context, id int64) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *conversationImpl) Update(ctx context.Context, req *entity.UpdateMeta) (*entity.Conversation, error) {
|
||||
// get conversation
|
||||
return c.ConversationRepo.Update(ctx, req)
|
||||
}
|
||||
|
||||
func (c *conversationImpl) List(ctx context.Context, req *entity.ListMeta) ([]*entity.Conversation, bool, error) {
|
||||
conversationList, hasMore, err := c.ConversationRepo.List(ctx, req.UserID, req.AgentID, req.ConnectorID, int32(req.Scene), req.Limit, req.Page)
|
||||
|
||||
|
|
|
|||
|
|
@ -16,19 +16,22 @@
|
|||
|
||||
package entity
|
||||
|
||||
import "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/message"
|
||||
import (
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/message"
|
||||
)
|
||||
|
||||
type Message = message.Message
|
||||
|
||||
type ListMeta struct {
|
||||
ConversationID int64 `json:"conversation_id"`
|
||||
RunID []*int64 `json:"run_id"`
|
||||
UserID string `json:"user_id"`
|
||||
AgentID int64 `json:"agent_id"`
|
||||
OrderBy *string `json:"order_by"`
|
||||
Limit int `json:"limit"`
|
||||
Cursor int64 `json:"cursor"` // message id
|
||||
Direction ScrollPageDirection `json:"direction"` // "prev" "Next"
|
||||
ConversationID int64 `json:"conversation_id"`
|
||||
RunID []*int64 `json:"run_id"`
|
||||
UserID string `json:"user_id"`
|
||||
AgentID int64 `json:"agent_id"`
|
||||
OrderBy *string `json:"order_by"`
|
||||
Limit int `json:"limit"`
|
||||
Cursor int64 `json:"cursor"` // message id
|
||||
Direction ScrollPageDirection `json:"direction"` // "prev" "Next"
|
||||
MessageType []*message.MessageType `json:"message_type"`
|
||||
}
|
||||
|
||||
type ListResult struct {
|
||||
|
|
@ -45,8 +48,9 @@ type GetByRunIDsRequest struct {
|
|||
}
|
||||
|
||||
type DeleteMeta struct {
|
||||
MessageIDs []int64 `json:"message_ids"`
|
||||
RunIDs []int64 `json:"run_ids"`
|
||||
ConversationID *int64 `json:"conversation_id"`
|
||||
MessageIDs []int64 `json:"message_ids"`
|
||||
RunIDs []int64 `json:"run_ids"`
|
||||
}
|
||||
|
||||
type BrokenMeta struct {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import (
|
|||
"github.com/coze-dev/coze-studio/backend/domain/conversation/message/internal/dal/query"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/slices"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/sonic"
|
||||
"github.com/coze-dev/coze-studio/backend/types/errno"
|
||||
|
|
@ -71,27 +72,41 @@ func (dao *MessageDAO) Create(ctx context.Context, msg *entity.Message) (*entity
|
|||
return dao.messagePO2DO(poData), nil
|
||||
}
|
||||
|
||||
func (dao *MessageDAO) List(ctx context.Context, conversationID int64, limit int, cursor int64, direction entity.ScrollPageDirection, messageType *message.MessageType) ([]*entity.Message, bool, error) {
|
||||
func (dao *MessageDAO) List(ctx context.Context, listMeta *entity.ListMeta) ([]*entity.Message, bool, error) {
|
||||
m := dao.query.Message
|
||||
do := m.WithContext(ctx).Debug().Where(m.ConversationID.Eq(conversationID)).Where(m.Status.Eq(int32(entity.MessageStatusAvailable)))
|
||||
do := m.WithContext(ctx).Debug().Where(m.ConversationID.Eq(listMeta.ConversationID)).Where(m.Status.Eq(int32(entity.MessageStatusAvailable)))
|
||||
|
||||
if messageType != nil {
|
||||
do = do.Where(m.MessageType.Eq(string(*messageType)))
|
||||
if len(listMeta.RunID) > 0 {
|
||||
do = do.Where(m.RunID.In(slices.Transform(listMeta.RunID, func(t *int64) int64 {
|
||||
return *t
|
||||
})...))
|
||||
}
|
||||
if len(listMeta.MessageType) > 0 {
|
||||
do = do.Where(m.MessageType.In(slices.Transform(listMeta.MessageType, func(t *message.MessageType) string {
|
||||
return string(*t)
|
||||
})...))
|
||||
}
|
||||
|
||||
if limit > 0 {
|
||||
do = do.Limit(int(limit) + 1)
|
||||
if listMeta.Limit > 0 {
|
||||
do = do.Limit(int(listMeta.Limit) + 1)
|
||||
}
|
||||
|
||||
if cursor > 0 {
|
||||
if direction == entity.ScrollPageDirectionPrev {
|
||||
do = do.Where(m.CreatedAt.Lt(cursor))
|
||||
} else {
|
||||
do = do.Where(m.CreatedAt.Gt(cursor))
|
||||
if listMeta.Cursor > 0 {
|
||||
msg, err := m.Where(m.ID.Eq(listMeta.Cursor)).First()
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
if listMeta.Direction == entity.ScrollPageDirectionPrev {
|
||||
do = do.Where(m.CreatedAt.Lt(msg.CreatedAt))
|
||||
do = do.Order(m.CreatedAt.Desc())
|
||||
} else {
|
||||
do = do.Where(m.CreatedAt.Gt(msg.CreatedAt))
|
||||
do = do.Order(m.CreatedAt.Asc())
|
||||
}
|
||||
} else {
|
||||
do = do.Order(m.CreatedAt.Desc())
|
||||
}
|
||||
|
||||
do = do.Order(m.CreatedAt.Desc())
|
||||
messageList, err := do.Find()
|
||||
|
||||
var hasMore bool
|
||||
|
|
@ -103,9 +118,9 @@ func (dao *MessageDAO) List(ctx context.Context, conversationID int64, limit int
|
|||
return nil, false, err
|
||||
}
|
||||
|
||||
if len(messageList) > limit {
|
||||
if len(messageList) > int(listMeta.Limit) {
|
||||
hasMore = true
|
||||
messageList = messageList[:limit]
|
||||
messageList = messageList[:int(listMeta.Limit)]
|
||||
}
|
||||
|
||||
return dao.batchMessagePO2DO(messageList), hasMore, nil
|
||||
|
|
@ -113,7 +128,8 @@ func (dao *MessageDAO) List(ctx context.Context, conversationID int64, limit int
|
|||
|
||||
func (dao *MessageDAO) GetByRunIDs(ctx context.Context, runIDs []int64, orderBy string) ([]*entity.Message, error) {
|
||||
m := dao.query.Message
|
||||
do := m.WithContext(ctx).Debug().Where(m.RunID.In(runIDs...))
|
||||
do := m.WithContext(ctx).Debug().Where(m.RunID.In(runIDs...)).Where(m.Status.Eq(int32(entity.MessageStatusAvailable)))
|
||||
|
||||
if orderBy == "DESC" {
|
||||
do = do.Order(m.CreatedAt.Desc())
|
||||
} else {
|
||||
|
|
@ -133,19 +149,37 @@ func (dao *MessageDAO) GetByRunIDs(ctx context.Context, runIDs []int64, orderBy
|
|||
|
||||
func (dao *MessageDAO) Edit(ctx context.Context, msgID int64, msg *message.Message) (int64, error) {
|
||||
m := dao.query.Message
|
||||
columns := dao.buildEditColumns(msg)
|
||||
|
||||
originMsg, err := dao.GetByID(ctx, msgID)
|
||||
if originMsg == nil {
|
||||
return 0, errorx.New(errno.ErrRecordNotFound)
|
||||
}
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
columns := dao.buildEditColumns(msg, originMsg)
|
||||
do, err := m.WithContext(ctx).Where(m.ID.Eq(msgID)).UpdateColumns(columns)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if do.RowsAffected == 0 {
|
||||
return 0, errorx.New(errno.ErrRecordNotFound)
|
||||
}
|
||||
|
||||
return do.RowsAffected, nil
|
||||
}
|
||||
|
||||
func (dao *MessageDAO) buildEditColumns(msg *message.Message) map[string]interface{} {
|
||||
func (dao *MessageDAO) buildEditColumns(msg *message.Message, originMsg *entity.Message) map[string]interface{} {
|
||||
columns := make(map[string]interface{})
|
||||
table := dao.query.Message
|
||||
if msg.Content != "" {
|
||||
msg.Role = originMsg.Role
|
||||
columns[table.Content.ColumnName().String()] = msg.Content
|
||||
modelContent, err := dao.buildModelContent(msg)
|
||||
if err == nil {
|
||||
columns[table.ModelContent.ColumnName().String()] = modelContent
|
||||
}
|
||||
}
|
||||
if msg.MessageType != "" {
|
||||
columns[table.MessageType.ColumnName().String()] = msg.MessageType
|
||||
|
|
@ -170,6 +204,11 @@ func (dao *MessageDAO) buildEditColumns(msg *message.Message) map[string]interfa
|
|||
|
||||
columns[table.UpdatedAt.ColumnName().String()] = time.Now().UnixMilli()
|
||||
if msg.Ext != nil {
|
||||
if originMsg.Ext != nil {
|
||||
for k, v := range originMsg.Ext {
|
||||
msg.Ext[k] = v
|
||||
}
|
||||
}
|
||||
ext, err := sonic.MarshalString(msg.Ext)
|
||||
if err == nil {
|
||||
columns[table.Ext.ColumnName().String()] = ext
|
||||
|
|
@ -192,8 +231,8 @@ func (dao *MessageDAO) GetByID(ctx context.Context, msgID int64) (*entity.Messag
|
|||
return dao.messagePO2DO(po), nil
|
||||
}
|
||||
|
||||
func (dao *MessageDAO) Delete(ctx context.Context, msgIDs []int64, runIDs []int64) error {
|
||||
if len(msgIDs) == 0 && len(runIDs) == 0 {
|
||||
func (dao *MessageDAO) Delete(ctx context.Context, delMeta *entity.DeleteMeta) error {
|
||||
if len(delMeta.MessageIDs) == 0 && len(delMeta.RunIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -202,11 +241,14 @@ func (dao *MessageDAO) Delete(ctx context.Context, msgIDs []int64, runIDs []int6
|
|||
m := dao.query.Message
|
||||
do := m.WithContext(ctx)
|
||||
|
||||
if len(runIDs) > 0 {
|
||||
do = do.Where(m.RunID.In(runIDs...))
|
||||
if len(delMeta.RunIDs) > 0 {
|
||||
do = do.Where(m.RunID.In(delMeta.RunIDs...))
|
||||
}
|
||||
if len(msgIDs) > 0 {
|
||||
do = do.Where(m.ID.In(msgIDs...))
|
||||
if len(delMeta.MessageIDs) > 0 {
|
||||
do = do.Where(m.ID.In(delMeta.MessageIDs...))
|
||||
}
|
||||
if delMeta.ConversationID != nil && ptr.From(delMeta.ConversationID) > 0 {
|
||||
do = do.Where(m.ConversationID.Eq(*delMeta.ConversationID))
|
||||
}
|
||||
_, err := do.UpdateColumns(&updateColumns)
|
||||
return err
|
||||
|
|
@ -284,6 +326,9 @@ func (dao *MessageDAO) buildModelContent(msgDO *entity.Message) (string, error)
|
|||
var multiContent []schema.ChatMessagePart
|
||||
for _, contentData := range msgDO.MultiContent {
|
||||
if contentData.Type == message.InputTypeText {
|
||||
if len(msgDO.Content) == 0 && len(contentData.Text) > 0 {
|
||||
msgDO.Content = contentData.Text
|
||||
}
|
||||
continue
|
||||
}
|
||||
one := schema.ChatMessagePart{}
|
||||
|
|
|
|||
|
|
@ -34,10 +34,9 @@ func NewMessageRepo(db *gorm.DB, idGen idgen.IDGenerator) MessageRepo {
|
|||
type MessageRepo interface {
|
||||
PreCreate(ctx context.Context, msg *entity.Message) (*entity.Message, error)
|
||||
Create(ctx context.Context, msg *entity.Message) (*entity.Message, error)
|
||||
List(ctx context.Context, conversationID int64, limit int, cursor int64,
|
||||
direction entity.ScrollPageDirection, messageType *message.MessageType) ([]*entity.Message, bool, error)
|
||||
List(ctx context.Context, listMeta *entity.ListMeta) ([]*entity.Message, bool, error)
|
||||
GetByRunIDs(ctx context.Context, runIDs []int64, orderBy string) ([]*entity.Message, error)
|
||||
Edit(ctx context.Context, msgID int64, message *message.Message) (int64, error)
|
||||
GetByID(ctx context.Context, msgID int64) (*entity.Message, error)
|
||||
Delete(ctx context.Context, msgIDs []int64, runIDs []int64) error
|
||||
Delete(ctx context.Context, delMeta *entity.DeleteMeta) error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import (
|
|||
|
||||
type Message interface {
|
||||
List(ctx context.Context, req *entity.ListMeta) (*entity.ListResult, error)
|
||||
ListWithoutPair(ctx context.Context, req *entity.ListMeta) (*entity.ListResult, error)
|
||||
PreCreate(ctx context.Context, req *entity.Message) (*entity.Message, error)
|
||||
Create(ctx context.Context, req *entity.Message) (*entity.Message, error)
|
||||
GetByRunIDs(ctx context.Context, conversationID int64, runIDs []int64) ([]*entity.Message, error)
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package message
|
|||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/message"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/message/entity"
|
||||
|
|
@ -51,9 +52,9 @@ func (m *messageImpl) Create(ctx context.Context, msg *entity.Message) (*entity.
|
|||
|
||||
func (m *messageImpl) List(ctx context.Context, req *entity.ListMeta) (*entity.ListResult, error) {
|
||||
resp := &entity.ListResult{}
|
||||
|
||||
req.MessageType = []*message.MessageType{ptr.Of(message.MessageTypeQuestion)}
|
||||
// get message with query
|
||||
messageList, hasMore, err := m.MessageRepo.List(ctx, req.ConversationID, req.Limit, req.Cursor, req.Direction, ptr.Of(message.MessageTypeQuestion))
|
||||
messageList, hasMore, err := m.MessageRepo.List(ctx, req)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
|
|
@ -62,8 +63,11 @@ func (m *messageImpl) List(ctx context.Context, req *entity.ListMeta) (*entity.L
|
|||
resp.HasMore = hasMore
|
||||
|
||||
if len(messageList) > 0 {
|
||||
resp.PrevCursor = messageList[len(messageList)-1].CreatedAt
|
||||
resp.NextCursor = messageList[0].CreatedAt
|
||||
sort.Slice(messageList, func(i, j int) bool {
|
||||
return messageList[i].CreatedAt > messageList[j].CreatedAt
|
||||
})
|
||||
resp.PrevCursor = messageList[len(messageList)-1].ID
|
||||
resp.NextCursor = messageList[0].ID
|
||||
|
||||
var runIDs []int64
|
||||
for _, m := range messageList {
|
||||
|
|
@ -82,6 +86,23 @@ func (m *messageImpl) List(ctx context.Context, req *entity.ListMeta) (*entity.L
|
|||
return resp, nil
|
||||
}
|
||||
|
||||
func (m *messageImpl) ListWithoutPair(ctx context.Context, req *entity.ListMeta) (*entity.ListResult, error) {
|
||||
resp := &entity.ListResult{}
|
||||
messageList, hasMore, err := m.MessageRepo.List(ctx, req)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
resp.Direction = req.Direction
|
||||
resp.HasMore = hasMore
|
||||
resp.Messages = messageList
|
||||
if len(messageList) > 0 {
|
||||
resp.PrevCursor = messageList[0].ID
|
||||
resp.NextCursor = messageList[len(messageList)-1].ID
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (m *messageImpl) GetByRunIDs(ctx context.Context, conversationID int64, runIDs []int64) ([]*entity.Message, error) {
|
||||
return m.MessageRepo.GetByRunIDs(ctx, runIDs, "ASC")
|
||||
}
|
||||
|
|
@ -96,7 +117,7 @@ func (m *messageImpl) Edit(ctx context.Context, req *entity.Message) (*entity.Me
|
|||
}
|
||||
|
||||
func (m *messageImpl) Delete(ctx context.Context, req *entity.DeleteMeta) error {
|
||||
return m.MessageRepo.Delete(ctx, req.MessageIDs, req.RunIDs)
|
||||
return m.MessageRepo.Delete(ctx, req)
|
||||
}
|
||||
|
||||
func (m *messageImpl) GetByID(ctx context.Context, id int64) (*entity.Message, error) {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package message
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -145,20 +146,26 @@ func TestCreateMessage(t *testing.T) {
|
|||
func TestEditMessage(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
mockDBGen := orm.NewMockDB()
|
||||
|
||||
extData := map[string]string{
|
||||
"test": "test",
|
||||
}
|
||||
ext, _ := json.Marshal(extData)
|
||||
mockDBGen.AddTable(&model.Message{}).
|
||||
AddRows(
|
||||
&model.Message{
|
||||
ID: 1,
|
||||
ConversationID: 1,
|
||||
UserID: "1",
|
||||
Role: string(schema.User),
|
||||
RunID: 123,
|
||||
},
|
||||
&model.Message{
|
||||
ID: 2,
|
||||
ConversationID: 1,
|
||||
UserID: "1",
|
||||
Role: string(schema.User),
|
||||
RunID: 124,
|
||||
Ext: string(ext),
|
||||
},
|
||||
)
|
||||
|
||||
|
|
@ -177,7 +184,7 @@ func TestEditMessage(t *testing.T) {
|
|||
Url: "https://xxxxx.xxxx/file",
|
||||
Name: "test_file",
|
||||
}
|
||||
content := []*message.InputMetaData{
|
||||
_ = []*message.InputMetaData{
|
||||
{
|
||||
Type: message.InputTypeText,
|
||||
Text: "解析图片中的内容",
|
||||
|
|
@ -197,56 +204,293 @@ func TestEditMessage(t *testing.T) {
|
|||
}
|
||||
|
||||
resp, err := NewService(components).Edit(ctx, &entity.Message{
|
||||
ID: 2,
|
||||
Content: "test edit message",
|
||||
MultiContent: content,
|
||||
ID: 2,
|
||||
Content: "test edit message",
|
||||
Ext: map[string]string{"newext": "true"},
|
||||
|
||||
// MultiContent: content,
|
||||
})
|
||||
_ = resp
|
||||
|
||||
msOne, err := NewService(components).GetByRunIDs(ctx, 1, []int64{124})
|
||||
msg, err := NewService(components).GetByID(ctx, 2)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, int64(124), msOne[0].RunID)
|
||||
assert.Equal(t, int64(2), msg.ID)
|
||||
assert.Equal(t, "test edit message", msg.Content)
|
||||
var modelContent *schema.Message
|
||||
err = json.Unmarshal([]byte(msg.ModelContent), &modelContent)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "test edit message", modelContent.Content)
|
||||
|
||||
assert.Equal(t, "true", msg.Ext["newext"])
|
||||
}
|
||||
|
||||
func TestGetByRunIDs(t *testing.T) {
|
||||
//func TestGetByRunIDs(t *testing.T) {
|
||||
// ctx := context.Background()
|
||||
//
|
||||
// mockDBGen := orm.NewMockDB()
|
||||
//
|
||||
// mockDBGen.AddTable(&model.Message{}).
|
||||
// AddRows(
|
||||
// &model.Message{
|
||||
// ID: 1,
|
||||
// ConversationID: 1,
|
||||
// UserID: "1",
|
||||
// RunID: 123,
|
||||
// Content: "test content123",
|
||||
// },
|
||||
// &model.Message{
|
||||
// ID: 2,
|
||||
// ConversationID: 1,
|
||||
// UserID: "1",
|
||||
// Content: "test content124",
|
||||
// RunID: 124,
|
||||
// },
|
||||
// &model.Message{
|
||||
// ID: 3,
|
||||
// ConversationID: 1,
|
||||
// UserID: "1",
|
||||
// Content: "test content124",
|
||||
// RunID: 124,
|
||||
// },
|
||||
// )
|
||||
// mockDB, err := mockDBGen.DB()
|
||||
// assert.NoError(t, err)
|
||||
// components := &Components{
|
||||
// MessageRepo: repository.NewMessageRepo(mockDB, nil),
|
||||
// }
|
||||
//
|
||||
// resp, err := NewService(components).GetByRunIDs(ctx, 1, []int64{124})
|
||||
//
|
||||
// assert.NoError(t, err)
|
||||
//
|
||||
// assert.Len(t, resp, 2)
|
||||
//}
|
||||
|
||||
func TestListWithoutPair(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
t.Run("success_with_messages", func(t *testing.T) {
|
||||
mockDBGen := orm.NewMockDB()
|
||||
|
||||
mockDBGen := orm.NewMockDB()
|
||||
mockDBGen.AddTable(&model.Message{}).
|
||||
AddRows(
|
||||
&model.Message{
|
||||
ID: 1,
|
||||
ConversationID: 100,
|
||||
UserID: "user123",
|
||||
RunID: 200,
|
||||
Content: "Hello",
|
||||
MessageType: string(message.MessageTypeAnswer),
|
||||
Status: 1, // MessageStatusAvailable
|
||||
CreatedAt: time.Now().UnixMilli(),
|
||||
},
|
||||
&model.Message{
|
||||
ID: 2,
|
||||
ConversationID: 100,
|
||||
UserID: "user123",
|
||||
RunID: 201,
|
||||
Content: "World",
|
||||
MessageType: string(message.MessageTypeAnswer),
|
||||
Status: 1, // MessageStatusAvailable
|
||||
CreatedAt: time.Now().UnixMilli(),
|
||||
},
|
||||
)
|
||||
|
||||
mockDBGen.AddTable(&model.Message{}).
|
||||
AddRows(
|
||||
&model.Message{
|
||||
ID: 1,
|
||||
ConversationID: 1,
|
||||
UserID: "1",
|
||||
RunID: 123,
|
||||
Content: "test content123",
|
||||
},
|
||||
&model.Message{
|
||||
ID: 2,
|
||||
ConversationID: 1,
|
||||
UserID: "1",
|
||||
Content: "test content124",
|
||||
RunID: 124,
|
||||
},
|
||||
&model.Message{
|
||||
ID: 3,
|
||||
ConversationID: 1,
|
||||
UserID: "1",
|
||||
Content: "test content124",
|
||||
RunID: 124,
|
||||
},
|
||||
)
|
||||
mockDB, err := mockDBGen.DB()
|
||||
assert.NoError(t, err)
|
||||
components := &Components{
|
||||
MessageRepo: repository.NewMessageRepo(mockDB, nil),
|
||||
}
|
||||
mockDB, err := mockDBGen.DB()
|
||||
assert.NoError(t, err)
|
||||
|
||||
resp, err := NewService(components).GetByRunIDs(ctx, 1, []int64{124})
|
||||
components := &Components{
|
||||
MessageRepo: repository.NewMessageRepo(mockDB, nil),
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
req := &entity.ListMeta{
|
||||
ConversationID: 100,
|
||||
UserID: "user123",
|
||||
Limit: 10,
|
||||
Direction: entity.ScrollPageDirectionNext,
|
||||
}
|
||||
|
||||
assert.Len(t, resp, 2)
|
||||
resp, err := NewService(components).ListWithoutPair(ctx, req)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, resp)
|
||||
assert.Equal(t, entity.ScrollPageDirectionNext, resp.Direction)
|
||||
assert.False(t, resp.HasMore)
|
||||
assert.Len(t, resp.Messages, 2)
|
||||
assert.Equal(t, "Hello", resp.Messages[0].Content)
|
||||
assert.Equal(t, "World", resp.Messages[1].Content)
|
||||
})
|
||||
|
||||
t.Run("empty_result", func(t *testing.T) {
|
||||
mockDBGen := orm.NewMockDB()
|
||||
mockDBGen.AddTable(&model.Message{})
|
||||
|
||||
mockDB, err := mockDBGen.DB()
|
||||
assert.NoError(t, err)
|
||||
|
||||
components := &Components{
|
||||
MessageRepo: repository.NewMessageRepo(mockDB, nil),
|
||||
}
|
||||
|
||||
req := &entity.ListMeta{
|
||||
ConversationID: 999,
|
||||
UserID: "user123",
|
||||
Limit: 10,
|
||||
Direction: entity.ScrollPageDirectionNext,
|
||||
}
|
||||
|
||||
resp, err := NewService(components).ListWithoutPair(ctx, req)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, resp)
|
||||
assert.Equal(t, entity.ScrollPageDirectionNext, resp.Direction)
|
||||
assert.False(t, resp.HasMore)
|
||||
assert.Len(t, resp.Messages, 0)
|
||||
})
|
||||
|
||||
t.Run("pagination_has_more", func(t *testing.T) {
|
||||
mockDBGen := orm.NewMockDB()
|
||||
|
||||
mockDBGen.AddTable(&model.Message{}).
|
||||
AddRows(
|
||||
&model.Message{
|
||||
ID: 1,
|
||||
ConversationID: 100,
|
||||
UserID: "user123",
|
||||
RunID: 200,
|
||||
Content: "Message 1",
|
||||
MessageType: string(message.MessageTypeAnswer),
|
||||
Status: 1,
|
||||
CreatedAt: time.Now().UnixMilli() - 3000,
|
||||
},
|
||||
&model.Message{
|
||||
ID: 2,
|
||||
ConversationID: 100,
|
||||
UserID: "user123",
|
||||
RunID: 201,
|
||||
Content: "Message 2",
|
||||
MessageType: string(message.MessageTypeAnswer),
|
||||
Status: 1,
|
||||
CreatedAt: time.Now().UnixMilli() - 2000,
|
||||
},
|
||||
&model.Message{
|
||||
ID: 3,
|
||||
ConversationID: 100,
|
||||
UserID: "user123",
|
||||
RunID: 202,
|
||||
Content: "Message 3",
|
||||
MessageType: string(message.MessageTypeAnswer),
|
||||
Status: 1,
|
||||
CreatedAt: time.Now().UnixMilli() - 1000,
|
||||
},
|
||||
)
|
||||
|
||||
mockDB, err := mockDBGen.DB()
|
||||
assert.NoError(t, err)
|
||||
|
||||
components := &Components{
|
||||
MessageRepo: repository.NewMessageRepo(mockDB, nil),
|
||||
}
|
||||
|
||||
req := &entity.ListMeta{
|
||||
ConversationID: 100,
|
||||
UserID: "user123",
|
||||
Limit: 2,
|
||||
Direction: entity.ScrollPageDirectionNext,
|
||||
}
|
||||
|
||||
resp, err := NewService(components).ListWithoutPair(ctx, req)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, resp)
|
||||
assert.Equal(t, entity.ScrollPageDirectionNext, resp.Direction)
|
||||
assert.True(t, resp.HasMore)
|
||||
assert.Len(t, resp.Messages, 2)
|
||||
})
|
||||
|
||||
t.Run("direction_prev", func(t *testing.T) {
|
||||
mockDBGen := orm.NewMockDB()
|
||||
|
||||
mockDBGen.AddTable(&model.Message{}).
|
||||
AddRows(
|
||||
&model.Message{
|
||||
ID: 1,
|
||||
ConversationID: 100,
|
||||
UserID: "user123",
|
||||
RunID: 200,
|
||||
Content: "Test message",
|
||||
MessageType: string(message.MessageTypeAnswer),
|
||||
Status: 1,
|
||||
CreatedAt: time.Now().UnixMilli(),
|
||||
},
|
||||
)
|
||||
|
||||
mockDB, err := mockDBGen.DB()
|
||||
assert.NoError(t, err)
|
||||
|
||||
components := &Components{
|
||||
MessageRepo: repository.NewMessageRepo(mockDB, nil),
|
||||
}
|
||||
|
||||
req := &entity.ListMeta{
|
||||
ConversationID: 100,
|
||||
UserID: "user123",
|
||||
Limit: 10,
|
||||
Direction: entity.ScrollPageDirectionPrev,
|
||||
}
|
||||
|
||||
resp, err := NewService(components).ListWithoutPair(ctx, req)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, resp)
|
||||
assert.Equal(t, entity.ScrollPageDirectionPrev, resp.Direction)
|
||||
assert.False(t, resp.HasMore)
|
||||
assert.Len(t, resp.Messages, 1)
|
||||
})
|
||||
|
||||
t.Run("with_message_type_filter", func(t *testing.T) {
|
||||
mockDBGen := orm.NewMockDB()
|
||||
|
||||
mockDBGen.AddTable(&model.Message{}).
|
||||
AddRows(
|
||||
&model.Message{
|
||||
ID: 1,
|
||||
ConversationID: 100,
|
||||
UserID: "user123",
|
||||
RunID: 200,
|
||||
Content: "Answer message",
|
||||
MessageType: string(message.MessageTypeAnswer),
|
||||
Status: 1,
|
||||
CreatedAt: time.Now().UnixMilli(),
|
||||
},
|
||||
&model.Message{
|
||||
ID: 2,
|
||||
ConversationID: 100,
|
||||
UserID: "user123",
|
||||
RunID: 201,
|
||||
Content: "Question message",
|
||||
MessageType: string(message.MessageTypeQuestion),
|
||||
Status: 1,
|
||||
CreatedAt: time.Now().UnixMilli(),
|
||||
},
|
||||
)
|
||||
|
||||
mockDB, err := mockDBGen.DB()
|
||||
assert.NoError(t, err)
|
||||
|
||||
components := &Components{
|
||||
MessageRepo: repository.NewMessageRepo(mockDB, nil),
|
||||
}
|
||||
|
||||
req := &entity.ListMeta{
|
||||
ConversationID: 100,
|
||||
UserID: "user123",
|
||||
Limit: 10,
|
||||
Direction: entity.ScrollPageDirectionNext,
|
||||
MessageType: []*message.MessageType{&[]message.MessageType{message.MessageTypeAnswer}[0]},
|
||||
}
|
||||
|
||||
resp, err := NewService(components).ListWithoutPair(ctx, req)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, resp)
|
||||
assert.Len(t, resp.Messages, 1)
|
||||
assert.Equal(t, "Answer message", resp.Messages[0].Content)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ type CreateApiKey struct {
|
|||
Name string `json:"name"`
|
||||
Expire int64 `json:"expire"`
|
||||
UserID int64 `json:"user_id"`
|
||||
AkType AkType `json:"ak_type"`
|
||||
}
|
||||
|
||||
type DeleteApiKey struct {
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue