Compare commits
7 Commits
feat/addit
...
fix/workfl
| Author | SHA1 | Date | |
|---|---|---|---|
| ffb553fbae | |||
| 67d28dd7d5 | |||
| dd35c98338 | |||
| edf47b96dd | |||
| 009f310cc0 | |||
| 4987e3d8d5 | |||
| 2635f06afb |
@ -78,3 +78,23 @@ func ApplyUploadAction(ctx context.Context, c *app.RequestContext) {
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// RecordFileInfo .
|
||||
// @router /api/common/record_file_info [POST]
|
||||
func RecordFileInfo(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req upload.RecordFileInfoRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := uploadSVC.SVC.RecordFileInfo(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
@ -2454,7 +2454,7 @@ func TestStartNodeDefaultValues(t *testing.T) {
|
||||
result, _ := r.openapiSyncRun(idStr, input)
|
||||
assert.Equal(t, result, map[string]any{
|
||||
"ts": "2025-07-09 21:43:34",
|
||||
"files": "http://imagex.fanlv.fun/tos-cn-i-1heqlfnr21/e81acc11277f421390770618e24e01ce.jpeg~tplv-1heqlfnr21-image.image?x-wf-file_name=20250317-154742.jpeg",
|
||||
"files": "http://imagex.fanlv.fun/tos-cn-i-1heqlfnr21/e81acc11277f421390770618e24e01ce.jpeg~tplv-1heqlfnr21-image.image",
|
||||
"str": "str",
|
||||
"object": map[string]any{
|
||||
"a": "1",
|
||||
@ -2478,7 +2478,7 @@ func TestStartNodeDefaultValues(t *testing.T) {
|
||||
result, _ := r.openapiSyncRun(idStr, input)
|
||||
assert.Equal(t, result, map[string]any{
|
||||
"ts": "2025-07-09 21:43:34",
|
||||
"files": "http://imagex.fanlv.fun/tos-cn-i-1heqlfnr21/e81acc11277f421390770618e24e01ce.jpeg~tplv-1heqlfnr21-image.image?x-wf-file_name=20250317-154742.jpeg",
|
||||
"files": "http://imagex.fanlv.fun/tos-cn-i-1heqlfnr21/e81acc11277f421390770618e24e01ce.jpeg~tplv-1heqlfnr21-image.image",
|
||||
"str": "str",
|
||||
"object": map[string]any{
|
||||
"a": "1",
|
||||
@ -2503,7 +2503,7 @@ func TestStartNodeDefaultValues(t *testing.T) {
|
||||
result, _ := r.openapiSyncRun(idStr, input)
|
||||
assert.Equal(t, result, map[string]any{
|
||||
"ts": "2025-07-09 21:43:34",
|
||||
"files": "http://imagex.fanlv.fun/tos-cn-i-1heqlfnr21/e81acc11277f421390770618e24e01ce.jpeg~tplv-1heqlfnr21-image.image?x-wf-file_name=20250317-154742.jpeg",
|
||||
"files": "http://imagex.fanlv.fun/tos-cn-i-1heqlfnr21/e81acc11277f421390770618e24e01ce.jpeg~tplv-1heqlfnr21-image.image",
|
||||
"str": "value",
|
||||
"object": map[string]any{
|
||||
"a": "1",
|
||||
|
||||
@ -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 upload
|
||||
@ -6,6 +22,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/apache/thrift/lib/go/thrift"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/base"
|
||||
)
|
||||
|
||||
type CommonUploadRequest struct {
|
||||
@ -4592,10 +4609,575 @@ func (p *ApplyUploadActionResponse) String() string {
|
||||
|
||||
}
|
||||
|
||||
type RecordFileInfoRequest struct {
|
||||
FileURI string `thrift:"FileURI,1,required" form:"FileURI,required" json:"FileURI,required" query:"FileURI,required"`
|
||||
FileName string `thrift:"FileName,2,required" form:"FileName,required" json:"FileName,required" query:"FileName,required"`
|
||||
FileSize *string `thrift:"FileSize,3,optional" form:"FileSize" json:"FileSize,omitempty" query:"FileSize"`
|
||||
FileExtension *string `thrift:"FileExtension,4,optional" form:"FileExtension" json:"FileExtension,omitempty" query:"FileExtension"`
|
||||
}
|
||||
|
||||
func NewRecordFileInfoRequest() *RecordFileInfoRequest {
|
||||
return &RecordFileInfoRequest{}
|
||||
}
|
||||
|
||||
func (p *RecordFileInfoRequest) InitDefault() {
|
||||
}
|
||||
|
||||
func (p *RecordFileInfoRequest) GetFileURI() (v string) {
|
||||
return p.FileURI
|
||||
}
|
||||
|
||||
func (p *RecordFileInfoRequest) GetFileName() (v string) {
|
||||
return p.FileName
|
||||
}
|
||||
|
||||
var RecordFileInfoRequest_FileSize_DEFAULT string
|
||||
|
||||
func (p *RecordFileInfoRequest) GetFileSize() (v string) {
|
||||
if !p.IsSetFileSize() {
|
||||
return RecordFileInfoRequest_FileSize_DEFAULT
|
||||
}
|
||||
return *p.FileSize
|
||||
}
|
||||
|
||||
var RecordFileInfoRequest_FileExtension_DEFAULT string
|
||||
|
||||
func (p *RecordFileInfoRequest) GetFileExtension() (v string) {
|
||||
if !p.IsSetFileExtension() {
|
||||
return RecordFileInfoRequest_FileExtension_DEFAULT
|
||||
}
|
||||
return *p.FileExtension
|
||||
}
|
||||
|
||||
var fieldIDToName_RecordFileInfoRequest = map[int16]string{
|
||||
1: "FileURI",
|
||||
2: "FileName",
|
||||
3: "FileSize",
|
||||
4: "FileExtension",
|
||||
}
|
||||
|
||||
func (p *RecordFileInfoRequest) IsSetFileSize() bool {
|
||||
return p.FileSize != nil
|
||||
}
|
||||
|
||||
func (p *RecordFileInfoRequest) IsSetFileExtension() bool {
|
||||
return p.FileExtension != nil
|
||||
}
|
||||
|
||||
func (p *RecordFileInfoRequest) Read(iprot thrift.TProtocol) (err error) {
|
||||
var fieldTypeId thrift.TType
|
||||
var fieldId int16
|
||||
var issetFileURI bool = false
|
||||
var issetFileName 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.STRING {
|
||||
if err = p.ReadField1(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
issetFileURI = true
|
||||
} 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
|
||||
}
|
||||
issetFileName = true
|
||||
} 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
|
||||
}
|
||||
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 !issetFileURI {
|
||||
fieldId = 1
|
||||
goto RequiredFieldNotSetError
|
||||
}
|
||||
|
||||
if !issetFileName {
|
||||
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_RecordFileInfoRequest[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_RecordFileInfoRequest[fieldId]))
|
||||
}
|
||||
|
||||
func (p *RecordFileInfoRequest) ReadField1(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field string
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = v
|
||||
}
|
||||
p.FileURI = _field
|
||||
return nil
|
||||
}
|
||||
func (p *RecordFileInfoRequest) ReadField2(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 *RecordFileInfoRequest) ReadField3(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field *string
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = &v
|
||||
}
|
||||
p.FileSize = _field
|
||||
return nil
|
||||
}
|
||||
func (p *RecordFileInfoRequest) ReadField4(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field *string
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = &v
|
||||
}
|
||||
p.FileExtension = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *RecordFileInfoRequest) Write(oprot thrift.TProtocol) (err error) {
|
||||
var fieldId int16
|
||||
if err = oprot.WriteStructBegin("RecordFileInfoRequest"); 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 = 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 *RecordFileInfoRequest) writeField1(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("FileURI", thrift.STRING, 1); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteString(p.FileURI); 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 *RecordFileInfoRequest) writeField2(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("FileName", thrift.STRING, 2); 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 2 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err)
|
||||
}
|
||||
func (p *RecordFileInfoRequest) writeField3(oprot thrift.TProtocol) (err error) {
|
||||
if p.IsSetFileSize() {
|
||||
if err = oprot.WriteFieldBegin("FileSize", thrift.STRING, 3); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteString(*p.FileSize); 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 *RecordFileInfoRequest) writeField4(oprot thrift.TProtocol) (err error) {
|
||||
if p.IsSetFileExtension() {
|
||||
if err = oprot.WriteFieldBegin("FileExtension", thrift.STRING, 4); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteString(*p.FileExtension); 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 *RecordFileInfoRequest) String() string {
|
||||
if p == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("RecordFileInfoRequest(%+v)", *p)
|
||||
|
||||
}
|
||||
|
||||
type RecordFileInfoResponse struct {
|
||||
Code int64 `thrift:"code,253,required" form:"code,required" json:"code,required" query:"code,required"`
|
||||
Msg string `thrift:"msg,254,required" form:"msg,required" json:"msg,required" query:"msg,required"`
|
||||
BaseResp *base.BaseResp `thrift:"BaseResp,255,optional" form:"-" json:"-" query:"-"`
|
||||
}
|
||||
|
||||
func NewRecordFileInfoResponse() *RecordFileInfoResponse {
|
||||
return &RecordFileInfoResponse{}
|
||||
}
|
||||
|
||||
func (p *RecordFileInfoResponse) InitDefault() {
|
||||
}
|
||||
|
||||
func (p *RecordFileInfoResponse) GetCode() (v int64) {
|
||||
return p.Code
|
||||
}
|
||||
|
||||
func (p *RecordFileInfoResponse) GetMsg() (v string) {
|
||||
return p.Msg
|
||||
}
|
||||
|
||||
var RecordFileInfoResponse_BaseResp_DEFAULT *base.BaseResp
|
||||
|
||||
func (p *RecordFileInfoResponse) GetBaseResp() (v *base.BaseResp) {
|
||||
if !p.IsSetBaseResp() {
|
||||
return RecordFileInfoResponse_BaseResp_DEFAULT
|
||||
}
|
||||
return p.BaseResp
|
||||
}
|
||||
|
||||
var fieldIDToName_RecordFileInfoResponse = map[int16]string{
|
||||
253: "code",
|
||||
254: "msg",
|
||||
255: "BaseResp",
|
||||
}
|
||||
|
||||
func (p *RecordFileInfoResponse) IsSetBaseResp() bool {
|
||||
return p.BaseResp != nil
|
||||
}
|
||||
|
||||
func (p *RecordFileInfoResponse) Read(iprot thrift.TProtocol) (err error) {
|
||||
var fieldTypeId thrift.TType
|
||||
var fieldId int16
|
||||
var issetCode bool = false
|
||||
var issetMsg 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 253:
|
||||
if fieldTypeId == thrift.I64 {
|
||||
if err = p.ReadField253(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
issetCode = true
|
||||
} 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
|
||||
}
|
||||
issetMsg = 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 !issetCode {
|
||||
fieldId = 253
|
||||
goto RequiredFieldNotSetError
|
||||
}
|
||||
|
||||
if !issetMsg {
|
||||
fieldId = 254
|
||||
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_RecordFileInfoResponse[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_RecordFileInfoResponse[fieldId]))
|
||||
}
|
||||
|
||||
func (p *RecordFileInfoResponse) 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 *RecordFileInfoResponse) 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 *RecordFileInfoResponse) ReadField255(iprot thrift.TProtocol) error {
|
||||
_field := base.NewBaseResp()
|
||||
if err := _field.Read(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
p.BaseResp = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *RecordFileInfoResponse) Write(oprot thrift.TProtocol) (err error) {
|
||||
var fieldId int16
|
||||
if err = oprot.WriteStructBegin("RecordFileInfoResponse"); err != nil {
|
||||
goto WriteStructBeginError
|
||||
}
|
||||
if p != nil {
|
||||
if err = p.writeField253(oprot); err != nil {
|
||||
fieldId = 253
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField254(oprot); err != nil {
|
||||
fieldId = 254
|
||||
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 *RecordFileInfoResponse) 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 *RecordFileInfoResponse) 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 *RecordFileInfoResponse) writeField255(oprot thrift.TProtocol) (err error) {
|
||||
if p.IsSetBaseResp() {
|
||||
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 *RecordFileInfoResponse) String() string {
|
||||
if p == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("RecordFileInfoResponse(%+v)", *p)
|
||||
|
||||
}
|
||||
|
||||
type UploadService interface {
|
||||
CommonUpload(ctx context.Context, request *CommonUploadRequest) (r *CommonUploadResponse, err error)
|
||||
|
||||
ApplyUploadAction(ctx context.Context, request *ApplyUploadActionRequest) (r *ApplyUploadActionResponse, err error)
|
||||
|
||||
RecordFileInfo(ctx context.Context, request *RecordFileInfoRequest) (r *RecordFileInfoResponse, err error)
|
||||
}
|
||||
|
||||
type UploadServiceClient struct {
|
||||
@ -4642,6 +5224,15 @@ func (p *UploadServiceClient) ApplyUploadAction(ctx context.Context, request *Ap
|
||||
}
|
||||
return _result.GetSuccess(), nil
|
||||
}
|
||||
func (p *UploadServiceClient) RecordFileInfo(ctx context.Context, request *RecordFileInfoRequest) (r *RecordFileInfoResponse, err error) {
|
||||
var _args UploadServiceRecordFileInfoArgs
|
||||
_args.Request = request
|
||||
var _result UploadServiceRecordFileInfoResult
|
||||
if err = p.Client_().Call(ctx, "RecordFileInfo", &_args, &_result); err != nil {
|
||||
return
|
||||
}
|
||||
return _result.GetSuccess(), nil
|
||||
}
|
||||
|
||||
type UploadServiceProcessor struct {
|
||||
processorMap map[string]thrift.TProcessorFunction
|
||||
@ -4665,6 +5256,7 @@ func NewUploadServiceProcessor(handler UploadService) *UploadServiceProcessor {
|
||||
self := &UploadServiceProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)}
|
||||
self.AddToProcessorMap("CommonUpload", &uploadServiceProcessorCommonUpload{handler: handler})
|
||||
self.AddToProcessorMap("ApplyUploadAction", &uploadServiceProcessorApplyUploadAction{handler: handler})
|
||||
self.AddToProcessorMap("RecordFileInfo", &uploadServiceProcessorRecordFileInfo{handler: handler})
|
||||
return self
|
||||
}
|
||||
func (p *UploadServiceProcessor) Process(ctx context.Context, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
|
||||
@ -4781,6 +5373,54 @@ func (p *uploadServiceProcessorApplyUploadAction) Process(ctx context.Context, s
|
||||
return true, err
|
||||
}
|
||||
|
||||
type uploadServiceProcessorRecordFileInfo struct {
|
||||
handler UploadService
|
||||
}
|
||||
|
||||
func (p *uploadServiceProcessorRecordFileInfo) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
|
||||
args := UploadServiceRecordFileInfoArgs{}
|
||||
if err = args.Read(iprot); err != nil {
|
||||
iprot.ReadMessageEnd()
|
||||
x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error())
|
||||
oprot.WriteMessageBegin("RecordFileInfo", thrift.EXCEPTION, seqId)
|
||||
x.Write(oprot)
|
||||
oprot.WriteMessageEnd()
|
||||
oprot.Flush(ctx)
|
||||
return false, err
|
||||
}
|
||||
|
||||
iprot.ReadMessageEnd()
|
||||
var err2 error
|
||||
result := UploadServiceRecordFileInfoResult{}
|
||||
var retval *RecordFileInfoResponse
|
||||
if retval, err2 = p.handler.RecordFileInfo(ctx, args.Request); err2 != nil {
|
||||
x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing RecordFileInfo: "+err2.Error())
|
||||
oprot.WriteMessageBegin("RecordFileInfo", thrift.EXCEPTION, seqId)
|
||||
x.Write(oprot)
|
||||
oprot.WriteMessageEnd()
|
||||
oprot.Flush(ctx)
|
||||
return true, err2
|
||||
} else {
|
||||
result.Success = retval
|
||||
}
|
||||
if err2 = oprot.WriteMessageBegin("RecordFileInfo", 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 UploadServiceCommonUploadArgs struct {
|
||||
Request *CommonUploadRequest `thrift:"request,1"`
|
||||
}
|
||||
@ -5364,3 +6004,295 @@ func (p *UploadServiceApplyUploadActionResult) String() string {
|
||||
return fmt.Sprintf("UploadServiceApplyUploadActionResult(%+v)", *p)
|
||||
|
||||
}
|
||||
|
||||
type UploadServiceRecordFileInfoArgs struct {
|
||||
Request *RecordFileInfoRequest `thrift:"request,1"`
|
||||
}
|
||||
|
||||
func NewUploadServiceRecordFileInfoArgs() *UploadServiceRecordFileInfoArgs {
|
||||
return &UploadServiceRecordFileInfoArgs{}
|
||||
}
|
||||
|
||||
func (p *UploadServiceRecordFileInfoArgs) InitDefault() {
|
||||
}
|
||||
|
||||
var UploadServiceRecordFileInfoArgs_Request_DEFAULT *RecordFileInfoRequest
|
||||
|
||||
func (p *UploadServiceRecordFileInfoArgs) GetRequest() (v *RecordFileInfoRequest) {
|
||||
if !p.IsSetRequest() {
|
||||
return UploadServiceRecordFileInfoArgs_Request_DEFAULT
|
||||
}
|
||||
return p.Request
|
||||
}
|
||||
|
||||
var fieldIDToName_UploadServiceRecordFileInfoArgs = map[int16]string{
|
||||
1: "request",
|
||||
}
|
||||
|
||||
func (p *UploadServiceRecordFileInfoArgs) IsSetRequest() bool {
|
||||
return p.Request != nil
|
||||
}
|
||||
|
||||
func (p *UploadServiceRecordFileInfoArgs) 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_UploadServiceRecordFileInfoArgs[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 *UploadServiceRecordFileInfoArgs) ReadField1(iprot thrift.TProtocol) error {
|
||||
_field := NewRecordFileInfoRequest()
|
||||
if err := _field.Read(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
p.Request = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *UploadServiceRecordFileInfoArgs) Write(oprot thrift.TProtocol) (err error) {
|
||||
var fieldId int16
|
||||
if err = oprot.WriteStructBegin("RecordFileInfo_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 *UploadServiceRecordFileInfoArgs) 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 *UploadServiceRecordFileInfoArgs) String() string {
|
||||
if p == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("UploadServiceRecordFileInfoArgs(%+v)", *p)
|
||||
|
||||
}
|
||||
|
||||
type UploadServiceRecordFileInfoResult struct {
|
||||
Success *RecordFileInfoResponse `thrift:"success,0,optional"`
|
||||
}
|
||||
|
||||
func NewUploadServiceRecordFileInfoResult() *UploadServiceRecordFileInfoResult {
|
||||
return &UploadServiceRecordFileInfoResult{}
|
||||
}
|
||||
|
||||
func (p *UploadServiceRecordFileInfoResult) InitDefault() {
|
||||
}
|
||||
|
||||
var UploadServiceRecordFileInfoResult_Success_DEFAULT *RecordFileInfoResponse
|
||||
|
||||
func (p *UploadServiceRecordFileInfoResult) GetSuccess() (v *RecordFileInfoResponse) {
|
||||
if !p.IsSetSuccess() {
|
||||
return UploadServiceRecordFileInfoResult_Success_DEFAULT
|
||||
}
|
||||
return p.Success
|
||||
}
|
||||
|
||||
var fieldIDToName_UploadServiceRecordFileInfoResult = map[int16]string{
|
||||
0: "success",
|
||||
}
|
||||
|
||||
func (p *UploadServiceRecordFileInfoResult) IsSetSuccess() bool {
|
||||
return p.Success != nil
|
||||
}
|
||||
|
||||
func (p *UploadServiceRecordFileInfoResult) 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_UploadServiceRecordFileInfoResult[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 *UploadServiceRecordFileInfoResult) ReadField0(iprot thrift.TProtocol) error {
|
||||
_field := NewRecordFileInfoResponse()
|
||||
if err := _field.Read(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
p.Success = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *UploadServiceRecordFileInfoResult) Write(oprot thrift.TProtocol) (err error) {
|
||||
var fieldId int16
|
||||
if err = oprot.WriteStructBegin("RecordFileInfo_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 *UploadServiceRecordFileInfoResult) 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 *UploadServiceRecordFileInfoResult) String() string {
|
||||
if p == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("UploadServiceRecordFileInfoResult(%+v)", *p)
|
||||
|
||||
}
|
||||
|
||||
@ -42,6 +42,7 @@ func Register(r *server.Hertz) {
|
||||
}
|
||||
{
|
||||
_common := _api.Group("/common", _commonMw()...)
|
||||
_common.POST("/record_file_info", append(_recordfileinfoMw(), coze.RecordFileInfo)...)
|
||||
{
|
||||
_upload := _common.Group("/upload", _uploadMw()...)
|
||||
_upload.GET("/apply_upload_action", append(_applyuploadactionMw(), coze.ApplyUploadAction)...)
|
||||
|
||||
@ -1570,3 +1570,8 @@ func _getonlineappdataMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _recordfileinfoMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -435,17 +435,13 @@ func getVectorStore(ctx context.Context) (searchstore.Manager, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Second*5)
|
||||
defer cancel()
|
||||
|
||||
var (
|
||||
milvusAddr = os.Getenv("MILVUS_ADDR")
|
||||
user = os.Getenv("MILVUS_USER")
|
||||
password = os.Getenv("MILVUS_PASSWORD")
|
||||
milvusToken = os.Getenv("MILVUS_TOKEN")
|
||||
)
|
||||
milvusAddr := os.Getenv("MILVUS_ADDR")
|
||||
user := os.Getenv("MILVUS_USER")
|
||||
password := os.Getenv("MILVUS_PASSWORD")
|
||||
mc, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
|
||||
Address: milvusAddr,
|
||||
Username: user,
|
||||
Password: password,
|
||||
APIKey: milvusToken,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("init milvus client failed, err=%w", err)
|
||||
|
||||
@ -21,7 +21,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"slices"
|
||||
"strconv"
|
||||
|
||||
"github.com/cloudwego/eino/schema"
|
||||
@ -103,7 +102,7 @@ func (a *OpenapiAgentRunApplication) checkConversation(ctx context.Context, ar *
|
||||
return nil, err
|
||||
}
|
||||
if conData == nil {
|
||||
return nil, errorx.New(errno.ErrConversationNotFound)
|
||||
return nil, errors.New("conversation data is nil")
|
||||
}
|
||||
conversationData = conData
|
||||
|
||||
@ -111,7 +110,7 @@ func (a *OpenapiAgentRunApplication) checkConversation(ctx context.Context, ar *
|
||||
}
|
||||
|
||||
if conversationData.CreatorID != userID {
|
||||
return nil, errorx.New(errno.ErrConversationPermissionCode, errorx.KV("msg","user not match"))
|
||||
return nil, errors.New("conversation data not match")
|
||||
}
|
||||
|
||||
return conversationData, nil
|
||||
@ -139,31 +138,26 @@ func (a *OpenapiAgentRunApplication) buildAgentRunRequest(ctx context.Context, a
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
multiAdditionalMessages, err := a.parseAdditionalMessages(ctx, ar)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
filterMultiAdditionalMessages, multiContent, contentType, err := a.parseQueryContent(ctx, multiAdditionalMessages)
|
||||
multiContent, contentType, err := a.buildMultiContent(ctx, ar)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
displayContent := a.buildDisplayContent(ctx, ar)
|
||||
arm := &entity.AgentRunMeta{
|
||||
ConversationID: ptr.From(ar.ConversationID),
|
||||
AgentID: ar.BotID,
|
||||
Content: multiContent,
|
||||
DisplayContent: displayContent,
|
||||
SpaceID: spaceID,
|
||||
UserID: ar.User,
|
||||
SectionID: conversationData.SectionID,
|
||||
PreRetrieveTools: shortcutCMDData,
|
||||
IsDraft: false,
|
||||
ConnectorID: connectorID,
|
||||
ContentType: contentType,
|
||||
Ext: ar.ExtraParams,
|
||||
CustomVariables: ar.CustomVariables,
|
||||
CozeUID: conversationData.CreatorID,
|
||||
AdditionalMessages: filterMultiAdditionalMessages,
|
||||
ConversationID: ptr.From(ar.ConversationID),
|
||||
AgentID: ar.BotID,
|
||||
Content: multiContent,
|
||||
DisplayContent: displayContent,
|
||||
SpaceID: spaceID,
|
||||
UserID: ar.User,
|
||||
SectionID: conversationData.SectionID,
|
||||
PreRetrieveTools: shortcutCMDData,
|
||||
IsDraft: false,
|
||||
ConnectorID: connectorID,
|
||||
ContentType: contentType,
|
||||
Ext: ar.ExtraParams,
|
||||
CustomVariables: ar.CustomVariables,
|
||||
CozeUID: conversationData.CreatorID,
|
||||
}
|
||||
return arm, nil
|
||||
}
|
||||
@ -206,68 +200,29 @@ func (a *OpenapiAgentRunApplication) buildDisplayContent(_ context.Context, ar *
|
||||
return ""
|
||||
}
|
||||
|
||||
func (a *OpenapiAgentRunApplication) parseQueryContent(ctx context.Context, multiAdditionalMessages []*entity.AdditionalMessage) ([]*entity.AdditionalMessage, []*message.InputMetaData, message.ContentType, error) {
|
||||
|
||||
var multiContent []*message.InputMetaData
|
||||
var contentType message.ContentType
|
||||
var filterMultiAdditionalMessages []*entity.AdditionalMessage
|
||||
filterMultiAdditionalMessages = multiAdditionalMessages
|
||||
|
||||
if len(multiAdditionalMessages) > 0 {
|
||||
lastMessage := multiAdditionalMessages[len(multiAdditionalMessages)-1]
|
||||
if lastMessage != nil && lastMessage.Role == schema.User {
|
||||
multiContent = lastMessage.Content
|
||||
contentType = lastMessage.ContentType
|
||||
filterMultiAdditionalMessages = multiAdditionalMessages[:len(multiAdditionalMessages)-1]
|
||||
}
|
||||
}
|
||||
|
||||
return filterMultiAdditionalMessages, multiContent, contentType, nil
|
||||
}
|
||||
|
||||
func (a *OpenapiAgentRunApplication) parseAdditionalMessages(ctx context.Context, ar *run.ChatV3Request) ([]*entity.AdditionalMessage, error) {
|
||||
|
||||
additionalMessages := make([]*entity.AdditionalMessage, 0, len(ar.AdditionalMessages))
|
||||
func (a *OpenapiAgentRunApplication) buildMultiContent(ctx context.Context, ar *run.ChatV3Request) ([]*message.InputMetaData, message.ContentType, error) {
|
||||
var multiContents []*message.InputMetaData
|
||||
contentType := message.ContentTypeText
|
||||
|
||||
for _, item := range ar.AdditionalMessages {
|
||||
if item == nil {
|
||||
continue
|
||||
}
|
||||
if item.Role != string(schema.User) && item.Role != string(schema.Assistant) {
|
||||
return nil, errors.New("additional message role only support user and assistant")
|
||||
if item.Role != string(schema.User) {
|
||||
return nil, contentType, errors.New("role not match")
|
||||
}
|
||||
if item.Type != nil && !slices.Contains([]message.MessageType{message.MessageTypeQuestion, message.MessageTypeAnswer}, message.MessageType(*item.Type)) {
|
||||
return nil, errors.New("additional message type only support question and answer now")
|
||||
}
|
||||
|
||||
addOne := entity.AdditionalMessage{
|
||||
Role: schema.RoleType(item.Role),
|
||||
}
|
||||
if item.Type != nil {
|
||||
addOne.Type = message.MessageType(*item.Type)
|
||||
} else {
|
||||
addOne.Type = message.MessageTypeQuestion
|
||||
}
|
||||
|
||||
if item.ContentType == run.ContentTypeText {
|
||||
if item.Content == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
addOne.ContentType = message.ContentTypeText
|
||||
addOne.Content = []*message.InputMetaData{{
|
||||
multiContents = append(multiContents, &message.InputMetaData{
|
||||
Type: message.InputTypeText,
|
||||
Text: item.Content,
|
||||
}}
|
||||
})
|
||||
}
|
||||
|
||||
if item.ContentType == run.ContentTypeMixApi {
|
||||
|
||||
if ptr.From(item.Type) == string(message.MessageTypeAnswer) {
|
||||
return nil, errors.New(" answer messages only support text content")
|
||||
}
|
||||
|
||||
addOne.ContentType = message.ContentTypeMix
|
||||
contentType = message.ContentTypeMix
|
||||
var inputs []*run.AdditionalContent
|
||||
err := json.Unmarshal([]byte(item.Content), &inputs)
|
||||
|
||||
@ -281,8 +236,7 @@ func (a *OpenapiAgentRunApplication) parseAdditionalMessages(ctx context.Context
|
||||
}
|
||||
switch message.InputType(one.Type) {
|
||||
case message.InputTypeText:
|
||||
|
||||
addOne.Content = append(addOne.Content, &message.InputMetaData{
|
||||
multiContents = append(multiContents, &message.InputMetaData{
|
||||
Type: message.InputTypeText,
|
||||
Text: ptr.From(one.Text),
|
||||
})
|
||||
@ -296,12 +250,12 @@ func (a *OpenapiAgentRunApplication) parseAdditionalMessages(ctx context.Context
|
||||
ID: one.GetFileID(),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, contentType, err
|
||||
}
|
||||
fileUrl = fileInfo.File.Url
|
||||
fileURI = fileInfo.File.TosURI
|
||||
}
|
||||
addOne.Content = append(addOne.Content, &message.InputMetaData{
|
||||
multiContents = append(multiContents, &message.InputMetaData{
|
||||
Type: message.InputType(one.Type),
|
||||
FileData: []*message.FileData{
|
||||
{
|
||||
@ -315,10 +269,10 @@ func (a *OpenapiAgentRunApplication) parseAdditionalMessages(ctx context.Context
|
||||
}
|
||||
}
|
||||
}
|
||||
additionalMessages = append(additionalMessages, &addOne)
|
||||
|
||||
}
|
||||
|
||||
return additionalMessages, nil
|
||||
return multiContents, contentType, nil
|
||||
}
|
||||
|
||||
func (a *OpenapiAgentRunApplication) pullStream(ctx context.Context, sseSender *sseImpl.SSenderImpl, streamer *schema.StreamReader[*entity.AgentRunResponse]) {
|
||||
|
||||
@ -1,903 +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 conversation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/mock/gomock"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/conversation/common"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/conversation/run"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/singleagent"
|
||||
saEntity "github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/entity"
|
||||
convEntity "github.com/coze-dev/coze-studio/backend/domain/conversation/conversation/entity"
|
||||
openapiEntity "github.com/coze-dev/coze-studio/backend/domain/openauth/openapiauth/entity"
|
||||
cmdEntity "github.com/coze-dev/coze-studio/backend/domain/shortcutcmd/entity"
|
||||
uploadEntity "github.com/coze-dev/coze-studio/backend/domain/upload/entity"
|
||||
uploadService "github.com/coze-dev/coze-studio/backend/domain/upload/service"
|
||||
sseImpl "github.com/coze-dev/coze-studio/backend/infra/impl/sse"
|
||||
mockSingleAgent "github.com/coze-dev/coze-studio/backend/internal/mock/domain/agent/singleagent"
|
||||
mockAgentRun "github.com/coze-dev/coze-studio/backend/internal/mock/domain/conversation/agentrun"
|
||||
mockConversation "github.com/coze-dev/coze-studio/backend/internal/mock/domain/conversation/conversation"
|
||||
mockShortcut "github.com/coze-dev/coze-studio/backend/internal/mock/domain/shortcutcmd"
|
||||
mockUpload "github.com/coze-dev/coze-studio/backend/internal/mock/domain/upload"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/ctxcache"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/types/consts"
|
||||
)
|
||||
|
||||
func setupMocks(t *testing.T) (*OpenapiAgentRunApplication, *mockShortcut.MockShortcutCmd, *mockUpload.MockUploadService, *mockAgentRun.MockRun, *mockConversation.MockConversation, *mockSingleAgent.MockSingleAgent, *gomock.Controller) {
|
||||
ctrl := gomock.NewController(t)
|
||||
|
||||
mockShortcutSvc := mockShortcut.NewMockShortcutCmd(ctrl)
|
||||
mockUploadSvc := mockUpload.NewMockUploadService(ctrl)
|
||||
mockAgentRunSvc := mockAgentRun.NewMockRun(ctrl)
|
||||
mockConversationSvc := mockConversation.NewMockConversation(ctrl)
|
||||
mockSingleAgentSvc := mockSingleAgent.NewMockSingleAgent(ctrl)
|
||||
|
||||
app := &OpenapiAgentRunApplication{
|
||||
ShortcutDomainSVC: mockShortcutSvc,
|
||||
UploaodDomainSVC: mockUploadSvc,
|
||||
}
|
||||
|
||||
// Setup ConversationSVC mocks
|
||||
originalConversationSVC := ConversationSVC
|
||||
ConversationSVC = &ConversationApplicationService{
|
||||
AgentRunDomainSVC: mockAgentRunSvc,
|
||||
ConversationDomainSVC: mockConversationSvc,
|
||||
appContext: &ServiceComponents{
|
||||
SingleAgentDomainSVC: mockSingleAgentSvc,
|
||||
},
|
||||
}
|
||||
|
||||
t.Cleanup(func() {
|
||||
ConversationSVC = originalConversationSVC
|
||||
ctrl.Finish()
|
||||
})
|
||||
|
||||
return app, mockShortcutSvc, mockUploadSvc, mockAgentRunSvc, mockConversationSvc, mockSingleAgentSvc, ctrl
|
||||
}
|
||||
|
||||
func createTestContext() context.Context {
|
||||
ctx := context.Background()
|
||||
ctx = ctxcache.Init(ctx)
|
||||
apiKey := &openapiEntity.ApiKey{
|
||||
UserID: 12345,
|
||||
ConnectorID: consts.CozeConnectorID,
|
||||
}
|
||||
ctxcache.Store(ctx, consts.OpenapiAuthKeyInCtx, apiKey)
|
||||
return ctx
|
||||
}
|
||||
|
||||
func createTestRequest() *run.ChatV3Request {
|
||||
return &run.ChatV3Request{
|
||||
BotID: 67890,
|
||||
ConversationID: ptr.Of(int64(11111)),
|
||||
User: "test-user",
|
||||
AdditionalMessages: []*run.EnterMessage{
|
||||
{
|
||||
Role: "user",
|
||||
Content: "Hello, world!",
|
||||
ContentType: run.ContentTypeText,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func createTestRequestWithMultipleMessages() *run.ChatV3Request {
|
||||
return &run.ChatV3Request{
|
||||
BotID: 67890,
|
||||
ConversationID: ptr.Of(int64(11111)),
|
||||
User: "test-user",
|
||||
AdditionalMessages: []*run.EnterMessage{
|
||||
{
|
||||
Role: "user",
|
||||
Content: "Hello, I need help with something.",
|
||||
ContentType: run.ContentTypeText,
|
||||
},
|
||||
{
|
||||
Role: "assistant",
|
||||
Content: "Sure, I'd be happy to help! What do you need assistance with?",
|
||||
ContentType: run.ContentTypeText,
|
||||
},
|
||||
{
|
||||
Role: "user",
|
||||
Content: `{"type": "image", "url": "https://example.com/image.jpg"}`,
|
||||
ContentType: run.ContentTypeImage,
|
||||
},
|
||||
{
|
||||
Role: "user",
|
||||
Content: `{"type": "file", "name": "document.pdf", "url": "https://example.com/doc.pdf"}`,
|
||||
ContentType: run.ContentTypeFile,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func createTestRequestWithAssistantOnly() *run.ChatV3Request {
|
||||
return &run.ChatV3Request{
|
||||
BotID: 67890,
|
||||
ConversationID: ptr.Of(int64(11111)),
|
||||
User: "test-user",
|
||||
AdditionalMessages: []*run.EnterMessage{
|
||||
{
|
||||
Role: "assistant",
|
||||
Content: "I'm here to help you with any questions you might have.",
|
||||
ContentType: run.ContentTypeText, // assistant role only supports text content type
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenapiAgentRun_Success(t *testing.T) {
|
||||
app, _, _, mockAgentRun, mockConversation, mockSingleAgent, _ := setupMocks(t)
|
||||
ctx := createTestContext()
|
||||
req := createTestRequest()
|
||||
|
||||
// Mock agent check
|
||||
mockAgent := &saEntity.SingleAgent{
|
||||
SingleAgent: &singleagent.SingleAgent{
|
||||
AgentID: 67890,
|
||||
SpaceID: 54321,
|
||||
},
|
||||
}
|
||||
mockSingleAgent.EXPECT().ObtainAgentByIdentity(ctx, gomock.Any()).Return(mockAgent, nil)
|
||||
|
||||
// Mock conversation check
|
||||
mockConv := &convEntity.Conversation{
|
||||
ID: 11111,
|
||||
CreatorID: 12345,
|
||||
SectionID: 98765,
|
||||
}
|
||||
mockConversation.EXPECT().GetByID(ctx, int64(11111)).Return(mockConv, nil)
|
||||
|
||||
// Mock agent run failure to avoid pullStream complexity
|
||||
mockAgentRun.EXPECT().AgentRun(ctx, gomock.Any()).Return(nil, errors.New("mock stream error"))
|
||||
|
||||
err := app.OpenapiAgentRun(ctx, &sseImpl.SSenderImpl{}, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "mock stream error")
|
||||
}
|
||||
|
||||
func TestOpenapiAgentRun_CheckAgentError(t *testing.T) {
|
||||
app, _, _, _, _, mockSingleAgent, _ := setupMocks(t)
|
||||
ctx := createTestContext()
|
||||
req := createTestRequest()
|
||||
|
||||
// Mock agent check failure
|
||||
mockSingleAgent.EXPECT().ObtainAgentByIdentity(ctx, gomock.Any()).Return(nil, errors.New("agent not found"))
|
||||
|
||||
err := app.OpenapiAgentRun(ctx, &sseImpl.SSenderImpl{}, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "agent not found")
|
||||
}
|
||||
|
||||
func TestOpenapiAgentRun_AgentNotExists(t *testing.T) {
|
||||
app, _, _, _, _, mockSingleAgent, _ := setupMocks(t)
|
||||
ctx := createTestContext()
|
||||
req := createTestRequest()
|
||||
|
||||
// Mock agent check returns nil (agent not exists)
|
||||
mockSingleAgent.EXPECT().ObtainAgentByIdentity(ctx, gomock.Any()).Return(nil, nil)
|
||||
|
||||
err := app.OpenapiAgentRun(ctx, &sseImpl.SSenderImpl{}, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestOpenapiAgentRun_CheckConversationError(t *testing.T) {
|
||||
app, _, _, _, mockConversation, mockSingleAgent, _ := setupMocks(t)
|
||||
ctx := createTestContext()
|
||||
req := createTestRequest()
|
||||
|
||||
// Mock agent check success
|
||||
mockAgent := &saEntity.SingleAgent{
|
||||
SingleAgent: &singleagent.SingleAgent{
|
||||
AgentID: 67890,
|
||||
SpaceID: 54321,
|
||||
},
|
||||
}
|
||||
mockSingleAgent.EXPECT().ObtainAgentByIdentity(ctx, gomock.Any()).Return(mockAgent, nil)
|
||||
|
||||
// Mock conversation check failure
|
||||
mockConversation.EXPECT().GetByID(ctx, int64(11111)).Return(nil, errors.New("conversation not found"))
|
||||
|
||||
err := app.OpenapiAgentRun(ctx, &sseImpl.SSenderImpl{}, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "conversation not found")
|
||||
}
|
||||
|
||||
func TestOpenapiAgentRun_ConversationPermissionError(t *testing.T) {
|
||||
app, _, _, _, mockConversation, mockSingleAgent, _ := setupMocks(t)
|
||||
ctx := createTestContext()
|
||||
req := createTestRequest()
|
||||
|
||||
// Mock agent check success
|
||||
mockAgent := &saEntity.SingleAgent{
|
||||
SingleAgent: &singleagent.SingleAgent{
|
||||
AgentID: 67890,
|
||||
SpaceID: 54321,
|
||||
},
|
||||
}
|
||||
mockSingleAgent.EXPECT().ObtainAgentByIdentity(ctx, gomock.Any()).Return(mockAgent, nil)
|
||||
|
||||
// Mock conversation with different creator
|
||||
mockConv := &convEntity.Conversation{
|
||||
ID: 11111,
|
||||
CreatorID: 99999, // Different from user ID (12345)
|
||||
SectionID: 98765,
|
||||
}
|
||||
mockConversation.EXPECT().GetByID(ctx, int64(11111)).Return(mockConv, nil)
|
||||
|
||||
err := app.OpenapiAgentRun(ctx, &sseImpl.SSenderImpl{}, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestOpenapiAgentRun_CreateNewConversation(t *testing.T) {
|
||||
app, _, _, mockAgentRun, mockConversation, mockSingleAgent, _ := setupMocks(t)
|
||||
ctx := createTestContext()
|
||||
req := createTestRequest()
|
||||
req.ConversationID = ptr.Of(int64(0)) // No conversation ID
|
||||
|
||||
// Mock agent check success
|
||||
mockAgent := &saEntity.SingleAgent{
|
||||
SingleAgent: &singleagent.SingleAgent{
|
||||
AgentID: 67890,
|
||||
SpaceID: 54321,
|
||||
},
|
||||
}
|
||||
mockSingleAgent.EXPECT().ObtainAgentByIdentity(ctx, gomock.Any()).Return(mockAgent, nil)
|
||||
|
||||
// Mock create new conversation
|
||||
mockConv := &convEntity.Conversation{
|
||||
ID: 22222,
|
||||
CreatorID: 12345,
|
||||
SectionID: 98765,
|
||||
}
|
||||
mockConversation.EXPECT().Create(ctx, gomock.Any()).DoAndReturn(func(ctx context.Context, meta *convEntity.CreateMeta) (*convEntity.Conversation, error) {
|
||||
assert.Equal(t, int64(67890), meta.AgentID)
|
||||
assert.Equal(t, int64(12345), meta.UserID)
|
||||
assert.Equal(t, common.Scene_SceneOpenApi, meta.Scene)
|
||||
return mockConv, nil
|
||||
})
|
||||
|
||||
// Mock agent run failure to avoid pullStream complexity
|
||||
mockAgentRun.EXPECT().AgentRun(ctx, gomock.Any()).Return(nil, errors.New("mock stream error"))
|
||||
|
||||
err := app.OpenapiAgentRun(ctx, &sseImpl.SSenderImpl{}, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, int64(22222), *req.ConversationID) // Should be updated
|
||||
}
|
||||
|
||||
func TestOpenapiAgentRun_AgentRunError(t *testing.T) {
|
||||
app, _, _, mockAgentRun, mockConversation, mockSingleAgent, _ := setupMocks(t)
|
||||
ctx := createTestContext()
|
||||
req := createTestRequest()
|
||||
|
||||
// Mock agent check success
|
||||
mockAgent := &saEntity.SingleAgent{
|
||||
SingleAgent: &singleagent.SingleAgent{
|
||||
AgentID: 67890,
|
||||
SpaceID: 54321,
|
||||
},
|
||||
}
|
||||
mockSingleAgent.EXPECT().ObtainAgentByIdentity(ctx, gomock.Any()).Return(mockAgent, nil)
|
||||
|
||||
// Mock conversation check success
|
||||
mockConv := &convEntity.Conversation{
|
||||
ID: 11111,
|
||||
CreatorID: 12345,
|
||||
SectionID: 98765,
|
||||
}
|
||||
mockConversation.EXPECT().GetByID(ctx, int64(11111)).Return(mockConv, nil)
|
||||
|
||||
// Mock agent run failure
|
||||
mockAgentRun.EXPECT().AgentRun(ctx, gomock.Any()).Return(nil, errors.New("agent run failed"))
|
||||
|
||||
err := app.OpenapiAgentRun(ctx, &sseImpl.SSenderImpl{}, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "agent run failed")
|
||||
}
|
||||
|
||||
func TestOpenapiAgentRun_WithShortcutCommand(t *testing.T) {
|
||||
app, mockShortcut, _, mockAgentRun, mockConversation, mockSingleAgent, _ := setupMocks(t)
|
||||
ctx := createTestContext()
|
||||
req := createTestRequest()
|
||||
req.ShortcutCommand = &run.ShortcutCommandDetail{
|
||||
CommandID: 123,
|
||||
Parameters: map[string]string{"param1": "value1"},
|
||||
}
|
||||
|
||||
// Mock agent check success
|
||||
mockAgent := &saEntity.SingleAgent{
|
||||
SingleAgent: &singleagent.SingleAgent{
|
||||
AgentID: 67890,
|
||||
SpaceID: 54321,
|
||||
},
|
||||
}
|
||||
mockSingleAgent.EXPECT().ObtainAgentByIdentity(ctx, gomock.Any()).Return(mockAgent, nil)
|
||||
|
||||
// Mock conversation check success
|
||||
mockConv := &convEntity.Conversation{
|
||||
ID: 11111,
|
||||
CreatorID: 12345,
|
||||
SectionID: 98765,
|
||||
}
|
||||
mockConversation.EXPECT().GetByID(ctx, int64(11111)).Return(mockConv, nil)
|
||||
|
||||
// Mock shortcut command
|
||||
mockCmd := &cmdEntity.ShortcutCmd{
|
||||
ID: 123,
|
||||
PluginID: 456,
|
||||
PluginToolName: "test-tool",
|
||||
PluginToolID: 789,
|
||||
ToolType: 1,
|
||||
}
|
||||
mockShortcut.EXPECT().GetByCmdID(ctx, int64(123), int32(0)).Return(mockCmd, nil)
|
||||
|
||||
// Mock agent run failure to avoid pullStream complexity
|
||||
mockAgentRun.EXPECT().AgentRun(ctx, gomock.Any()).Return(nil, errors.New("mock stream error"))
|
||||
|
||||
err := app.OpenapiAgentRun(ctx, &sseImpl.SSenderImpl{}, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestOpenapiAgentRun_WithMultipleMessages(t *testing.T) {
|
||||
app, _, _, mockAgentRun, mockConversation, mockSingleAgent, _ := setupMocks(t)
|
||||
ctx := createTestContext()
|
||||
req := createTestRequestWithMultipleMessages()
|
||||
|
||||
// Mock agent check success
|
||||
mockAgent := &saEntity.SingleAgent{
|
||||
SingleAgent: &singleagent.SingleAgent{
|
||||
AgentID: 67890,
|
||||
SpaceID: 54321,
|
||||
},
|
||||
}
|
||||
mockSingleAgent.EXPECT().ObtainAgentByIdentity(ctx, gomock.Any()).Return(mockAgent, nil)
|
||||
|
||||
// Mock conversation check success
|
||||
mockConv := &convEntity.Conversation{
|
||||
ID: 11111,
|
||||
CreatorID: 12345,
|
||||
SectionID: 98765,
|
||||
}
|
||||
mockConversation.EXPECT().GetByID(ctx, int64(11111)).Return(mockConv, nil)
|
||||
|
||||
// Mock agent run failure to avoid pullStream complexity
|
||||
mockAgentRun.EXPECT().AgentRun(ctx, gomock.Any()).Return(nil, errors.New("mock stream error"))
|
||||
|
||||
err := app.OpenapiAgentRun(ctx, &sseImpl.SSenderImpl{}, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "mock stream error")
|
||||
|
||||
// Verify that the request contains multiple messages with different roles and content types
|
||||
assert.Len(t, req.AdditionalMessages, 4)
|
||||
assert.Equal(t, "user", req.AdditionalMessages[0].Role)
|
||||
assert.Equal(t, run.ContentTypeText, req.AdditionalMessages[0].ContentType)
|
||||
assert.Equal(t, "assistant", req.AdditionalMessages[1].Role)
|
||||
assert.Equal(t, run.ContentTypeText, req.AdditionalMessages[1].ContentType)
|
||||
assert.Equal(t, "user", req.AdditionalMessages[2].Role)
|
||||
assert.Equal(t, run.ContentTypeImage, req.AdditionalMessages[2].ContentType)
|
||||
assert.Equal(t, "user", req.AdditionalMessages[3].Role)
|
||||
assert.Equal(t, run.ContentTypeFile, req.AdditionalMessages[3].ContentType)
|
||||
}
|
||||
|
||||
func TestOpenapiAgentRun_WithAssistantMessage(t *testing.T) {
|
||||
app, _, _, mockAgentRun, mockConversation, mockSingleAgent, _ := setupMocks(t)
|
||||
ctx := createTestContext()
|
||||
req := createTestRequestWithAssistantOnly()
|
||||
|
||||
// Mock agent check success
|
||||
mockAgent := &saEntity.SingleAgent{
|
||||
SingleAgent: &singleagent.SingleAgent{
|
||||
AgentID: 67890,
|
||||
SpaceID: 54321,
|
||||
},
|
||||
}
|
||||
mockSingleAgent.EXPECT().ObtainAgentByIdentity(ctx, gomock.Any()).Return(mockAgent, nil)
|
||||
|
||||
// Mock conversation check success
|
||||
mockConv := &convEntity.Conversation{
|
||||
ID: 11111,
|
||||
CreatorID: 12345,
|
||||
SectionID: 98765,
|
||||
}
|
||||
mockConversation.EXPECT().GetByID(ctx, int64(11111)).Return(mockConv, nil)
|
||||
|
||||
// Mock agent run failure to avoid pullStream complexity
|
||||
mockAgentRun.EXPECT().AgentRun(ctx, gomock.Any()).Return(nil, errors.New("mock stream error"))
|
||||
|
||||
err := app.OpenapiAgentRun(ctx, &sseImpl.SSenderImpl{}, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "mock stream error")
|
||||
|
||||
// Verify that the assistant message only supports text content type
|
||||
assert.Len(t, req.AdditionalMessages, 1)
|
||||
assert.Equal(t, "assistant", req.AdditionalMessages[0].Role)
|
||||
assert.Equal(t, run.ContentTypeText, req.AdditionalMessages[0].ContentType)
|
||||
}
|
||||
|
||||
func TestOpenapiAgentRun_WithMixedContentTypes(t *testing.T) {
|
||||
app, _, _, mockAgentRun, mockConversation, mockSingleAgent, _ := setupMocks(t)
|
||||
ctx := createTestContext()
|
||||
|
||||
// Create request with various content types for user role
|
||||
req := &run.ChatV3Request{
|
||||
BotID: 67890,
|
||||
ConversationID: ptr.Of(int64(11111)),
|
||||
User: "test-user",
|
||||
AdditionalMessages: []*run.EnterMessage{
|
||||
{
|
||||
Role: "user",
|
||||
Content: "Here's a text message",
|
||||
ContentType: run.ContentTypeText,
|
||||
},
|
||||
{
|
||||
Role: "user",
|
||||
Content: `{"type": "audio", "url": "https://example.com/audio.mp3"}`,
|
||||
ContentType: run.ContentTypeAudio,
|
||||
},
|
||||
{
|
||||
Role: "user",
|
||||
Content: `{"type": "video", "url": "https://example.com/video.mp4"}`,
|
||||
ContentType: run.ContentTypeVideo,
|
||||
},
|
||||
{
|
||||
Role: "assistant",
|
||||
Content: "I can only respond with text content.",
|
||||
ContentType: run.ContentTypeText, // assistant must use text
|
||||
},
|
||||
{
|
||||
Role: "user",
|
||||
Content: `{"type": "link", "url": "https://example.com"}`,
|
||||
ContentType: run.ContentTypeLink,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Mock agent check success
|
||||
mockAgent := &saEntity.SingleAgent{
|
||||
SingleAgent: &singleagent.SingleAgent{
|
||||
AgentID: 67890,
|
||||
SpaceID: 54321,
|
||||
},
|
||||
}
|
||||
mockSingleAgent.EXPECT().ObtainAgentByIdentity(ctx, gomock.Any()).Return(mockAgent, nil)
|
||||
|
||||
// Mock conversation check success
|
||||
mockConv := &convEntity.Conversation{
|
||||
ID: 11111,
|
||||
CreatorID: 12345,
|
||||
SectionID: 98765,
|
||||
}
|
||||
mockConversation.EXPECT().GetByID(ctx, int64(11111)).Return(mockConv, nil)
|
||||
|
||||
// Mock agent run failure to avoid pullStream complexity
|
||||
mockAgentRun.EXPECT().AgentRun(ctx, gomock.Any()).Return(nil, errors.New("mock stream error"))
|
||||
|
||||
err := app.OpenapiAgentRun(ctx, &sseImpl.SSenderImpl{}, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "mock stream error")
|
||||
|
||||
// Verify various content types are preserved
|
||||
assert.Len(t, req.AdditionalMessages, 5)
|
||||
|
||||
// Check user messages with different content types
|
||||
assert.Equal(t, "user", req.AdditionalMessages[0].Role)
|
||||
assert.Equal(t, run.ContentTypeText, req.AdditionalMessages[0].ContentType)
|
||||
|
||||
assert.Equal(t, "user", req.AdditionalMessages[1].Role)
|
||||
assert.Equal(t, run.ContentTypeAudio, req.AdditionalMessages[1].ContentType)
|
||||
|
||||
assert.Equal(t, "user", req.AdditionalMessages[2].Role)
|
||||
assert.Equal(t, run.ContentTypeVideo, req.AdditionalMessages[2].ContentType)
|
||||
|
||||
// Check assistant message (must be text)
|
||||
assert.Equal(t, "assistant", req.AdditionalMessages[3].Role)
|
||||
assert.Equal(t, run.ContentTypeText, req.AdditionalMessages[3].ContentType)
|
||||
|
||||
assert.Equal(t, "user", req.AdditionalMessages[4].Role)
|
||||
assert.Equal(t, run.ContentTypeLink, req.AdditionalMessages[4].ContentType)
|
||||
}
|
||||
|
||||
func TestOpenapiAgentRun_ParseAdditionalMessages_InvalidRole(t *testing.T) {
|
||||
app, _, _, _, mockConversation, mockSingleAgent, _ := setupMocks(t)
|
||||
ctx := createTestContext()
|
||||
|
||||
// Create request with invalid role
|
||||
req := &run.ChatV3Request{
|
||||
BotID: 67890,
|
||||
ConversationID: ptr.Of(int64(11111)),
|
||||
User: "test-user",
|
||||
AdditionalMessages: []*run.EnterMessage{
|
||||
{
|
||||
Role: "system", // Invalid role
|
||||
Content: "System message",
|
||||
ContentType: run.ContentTypeText,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Mock agent check success
|
||||
mockAgent := &saEntity.SingleAgent{
|
||||
SingleAgent: &singleagent.SingleAgent{
|
||||
AgentID: 67890,
|
||||
SpaceID: 54321,
|
||||
},
|
||||
}
|
||||
mockSingleAgent.EXPECT().ObtainAgentByIdentity(ctx, gomock.Any()).Return(mockAgent, nil)
|
||||
|
||||
// Mock conversation check success to reach parseAdditionalMessages
|
||||
mockConv := &convEntity.Conversation{
|
||||
ID: 11111,
|
||||
CreatorID: 12345,
|
||||
SectionID: 98765,
|
||||
}
|
||||
mockConversation.EXPECT().GetByID(ctx, int64(11111)).Return(mockConv, nil)
|
||||
|
||||
err := app.OpenapiAgentRun(ctx, &sseImpl.SSenderImpl{}, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "additional message role only support user and assistant")
|
||||
}
|
||||
|
||||
|
||||
|
||||
func TestOpenapiAgentRun_ParseAdditionalMessages_InvalidType(t *testing.T) {
|
||||
app, _, _, _, mockConversation, mockSingleAgent, _ := setupMocks(t)
|
||||
ctx := createTestContext()
|
||||
|
||||
// Create request with invalid message type
|
||||
invalidType := "invalid_type"
|
||||
req := &run.ChatV3Request{
|
||||
BotID: 67890,
|
||||
ConversationID: ptr.Of(int64(11111)),
|
||||
User: "test-user",
|
||||
AdditionalMessages: []*run.EnterMessage{
|
||||
{
|
||||
Role: "user",
|
||||
Content: "Test message",
|
||||
ContentType: run.ContentTypeText,
|
||||
Type: &invalidType, // Invalid type
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Mock agent check success
|
||||
mockAgent := &saEntity.SingleAgent{
|
||||
SingleAgent: &singleagent.SingleAgent{
|
||||
AgentID: 67890,
|
||||
SpaceID: 54321,
|
||||
},
|
||||
}
|
||||
mockSingleAgent.EXPECT().ObtainAgentByIdentity(ctx, gomock.Any()).Return(mockAgent, nil)
|
||||
|
||||
// Mock conversation check success to reach parseAdditionalMessages
|
||||
mockConv := &convEntity.Conversation{
|
||||
ID: 11111,
|
||||
CreatorID: 12345,
|
||||
SectionID: 98765,
|
||||
}
|
||||
mockConversation.EXPECT().GetByID(ctx, int64(11111)).Return(mockConv, nil)
|
||||
|
||||
err := app.OpenapiAgentRun(ctx, &sseImpl.SSenderImpl{}, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "additional message type only support question and answer now")
|
||||
}
|
||||
|
||||
func TestOpenapiAgentRun_ParseAdditionalMessages_AnswerWithNonTextContent(t *testing.T) {
|
||||
app, _, _, _, mockConversation, mockSingleAgent, _ := setupMocks(t)
|
||||
ctx := createTestContext()
|
||||
|
||||
// Create request with answer type but non-text content
|
||||
answerType := "answer"
|
||||
req := &run.ChatV3Request{
|
||||
BotID: 67890,
|
||||
ConversationID: ptr.Of(int64(11111)),
|
||||
User: "test-user",
|
||||
AdditionalMessages: []*run.EnterMessage{
|
||||
{
|
||||
Role: "assistant",
|
||||
Content: `[{"type": "image", "file_url": "https://example.com/image.jpg"}]`,
|
||||
ContentType: run.ContentTypeMixApi, // object_string
|
||||
Type: &answerType,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Mock agent check success
|
||||
mockAgent := &saEntity.SingleAgent{
|
||||
SingleAgent: &singleagent.SingleAgent{
|
||||
AgentID: 67890,
|
||||
SpaceID: 54321,
|
||||
},
|
||||
}
|
||||
mockSingleAgent.EXPECT().ObtainAgentByIdentity(ctx, gomock.Any()).Return(mockAgent, nil)
|
||||
|
||||
// Mock conversation check success to reach parseAdditionalMessages
|
||||
mockConv := &convEntity.Conversation{
|
||||
ID: 11111,
|
||||
CreatorID: 12345,
|
||||
SectionID: 98765,
|
||||
}
|
||||
mockConversation.EXPECT().GetByID(ctx, int64(11111)).Return(mockConv, nil)
|
||||
|
||||
err := app.OpenapiAgentRun(ctx, &sseImpl.SSenderImpl{}, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "answer messages only support text content")
|
||||
}
|
||||
|
||||
func TestOpenapiAgentRun_ParseAdditionalMessages_MixApiWithFileURL(t *testing.T) {
|
||||
app, _, _, mockAgentRun, mockConversation, mockSingleAgent, _ := setupMocks(t)
|
||||
ctx := createTestContext()
|
||||
|
||||
// Create request with object_string content type and file URL
|
||||
req := &run.ChatV3Request{
|
||||
BotID: 67890,
|
||||
ConversationID: ptr.Of(int64(11111)),
|
||||
User: "test-user",
|
||||
AdditionalMessages: []*run.EnterMessage{
|
||||
{
|
||||
Role: "user",
|
||||
Content: `[{"type": "text", "text": "Here's an image:"}, {"type": "image", "file_url": "https://example.com/image.jpg"}]`,
|
||||
ContentType: run.ContentTypeMixApi,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Mock agent check success
|
||||
mockAgent := &saEntity.SingleAgent{
|
||||
SingleAgent: &singleagent.SingleAgent{
|
||||
AgentID: 67890,
|
||||
SpaceID: 54321,
|
||||
},
|
||||
}
|
||||
mockSingleAgent.EXPECT().ObtainAgentByIdentity(ctx, gomock.Any()).Return(mockAgent, nil)
|
||||
|
||||
// Mock conversation check success
|
||||
mockConv := &convEntity.Conversation{
|
||||
ID: 11111,
|
||||
CreatorID: 12345,
|
||||
SectionID: 98765,
|
||||
}
|
||||
mockConversation.EXPECT().GetByID(ctx, int64(11111)).Return(mockConv, nil)
|
||||
|
||||
// Mock agent run failure to avoid pullStream complexity
|
||||
mockAgentRun.EXPECT().AgentRun(ctx, gomock.Any()).Return(nil, errors.New("mock stream error"))
|
||||
|
||||
err := app.OpenapiAgentRun(ctx, &sseImpl.SSenderImpl{}, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "mock stream error")
|
||||
}
|
||||
|
||||
func TestOpenapiAgentRun_ParseAdditionalMessages_MixApiWithFileID(t *testing.T) {
|
||||
app, _, mockUpload, mockAgentRun, mockConversation, mockSingleAgent, _ := setupMocks(t)
|
||||
ctx := createTestContext()
|
||||
|
||||
// Create request with object_string content type and file ID
|
||||
req := &run.ChatV3Request{
|
||||
BotID: 67890,
|
||||
ConversationID: ptr.Of(int64(11111)),
|
||||
User: "test-user",
|
||||
AdditionalMessages: []*run.EnterMessage{
|
||||
{
|
||||
Role: "user",
|
||||
Content: `[{"type": "file", "file_id": "12345"}]`,
|
||||
ContentType: run.ContentTypeMixApi,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Mock agent check success
|
||||
mockAgent := &saEntity.SingleAgent{
|
||||
SingleAgent: &singleagent.SingleAgent{
|
||||
AgentID: 67890,
|
||||
SpaceID: 54321,
|
||||
},
|
||||
}
|
||||
mockSingleAgent.EXPECT().ObtainAgentByIdentity(ctx, gomock.Any()).Return(mockAgent, nil)
|
||||
|
||||
// Mock conversation check success
|
||||
mockConv := &convEntity.Conversation{
|
||||
ID: 11111,
|
||||
CreatorID: 12345,
|
||||
SectionID: 98765,
|
||||
}
|
||||
mockConversation.EXPECT().GetByID(ctx, int64(11111)).Return(mockConv, nil)
|
||||
|
||||
// Mock upload service to return file info
|
||||
mockUpload.EXPECT().GetFile(ctx, gomock.Any()).DoAndReturn(func(ctx context.Context, req *uploadService.GetFileRequest) (*uploadService.GetFileResponse, error) {
|
||||
assert.Equal(t, int64(12345), req.ID)
|
||||
return &uploadService.GetFileResponse{
|
||||
File: &uploadEntity.File{
|
||||
Url: "https://example.com/file.pdf",
|
||||
TosURI: "tos://bucket/file.pdf",
|
||||
},
|
||||
}, nil
|
||||
})
|
||||
|
||||
// Mock agent run failure to avoid pullStream complexity
|
||||
mockAgentRun.EXPECT().AgentRun(ctx, gomock.Any()).Return(nil, errors.New("mock stream error"))
|
||||
|
||||
err := app.OpenapiAgentRun(ctx, &sseImpl.SSenderImpl{}, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "mock stream error")
|
||||
}
|
||||
|
||||
func TestOpenapiAgentRun_ParseAdditionalMessages_FileIDError(t *testing.T) {
|
||||
app, _, mockUpload, _, mockConversation, mockSingleAgent, _ := setupMocks(t)
|
||||
ctx := createTestContext()
|
||||
|
||||
// Create request with object_string content type and file ID that will fail
|
||||
req := &run.ChatV3Request{
|
||||
BotID: 67890,
|
||||
ConversationID: ptr.Of(int64(11111)),
|
||||
User: "test-user",
|
||||
AdditionalMessages: []*run.EnterMessage{
|
||||
{
|
||||
Role: "user",
|
||||
Content: `[{"type": "file", "file_id": "99999"}]`,
|
||||
ContentType: run.ContentTypeMixApi,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Mock agent check success
|
||||
mockAgent := &saEntity.SingleAgent{
|
||||
SingleAgent: &singleagent.SingleAgent{
|
||||
AgentID: 67890,
|
||||
SpaceID: 54321,
|
||||
},
|
||||
}
|
||||
mockSingleAgent.EXPECT().ObtainAgentByIdentity(ctx, gomock.Any()).Return(mockAgent, nil)
|
||||
|
||||
// Mock conversation check success
|
||||
mockConv := &convEntity.Conversation{
|
||||
ID: 11111,
|
||||
CreatorID: 12345,
|
||||
SectionID: 98765,
|
||||
}
|
||||
mockConversation.EXPECT().GetByID(ctx, int64(11111)).Return(mockConv, nil)
|
||||
|
||||
// Mock upload service to return error
|
||||
mockUpload.EXPECT().GetFile(ctx, gomock.Any()).Return(nil, errors.New("file not found"))
|
||||
|
||||
err := app.OpenapiAgentRun(ctx, &sseImpl.SSenderImpl{}, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "file not found")
|
||||
}
|
||||
|
||||
func TestOpenapiAgentRun_ParseAdditionalMessages_EmptyContent(t *testing.T) {
|
||||
app, _, _, mockAgentRun, mockConversation, mockSingleAgent, _ := setupMocks(t)
|
||||
ctx := createTestContext()
|
||||
|
||||
// Create request with empty text content (should be skipped)
|
||||
req := &run.ChatV3Request{
|
||||
BotID: 67890,
|
||||
ConversationID: ptr.Of(int64(11111)),
|
||||
User: "test-user",
|
||||
AdditionalMessages: []*run.EnterMessage{
|
||||
{
|
||||
Role: "user",
|
||||
Content: "", // Empty content
|
||||
ContentType: run.ContentTypeText,
|
||||
},
|
||||
{
|
||||
Role: "user",
|
||||
Content: "Valid content",
|
||||
ContentType: run.ContentTypeText,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Mock agent check success
|
||||
mockAgent := &saEntity.SingleAgent{
|
||||
SingleAgent: &singleagent.SingleAgent{
|
||||
AgentID: 67890,
|
||||
SpaceID: 54321,
|
||||
},
|
||||
}
|
||||
mockSingleAgent.EXPECT().ObtainAgentByIdentity(ctx, gomock.Any()).Return(mockAgent, nil)
|
||||
|
||||
// Mock conversation check success
|
||||
mockConv := &convEntity.Conversation{
|
||||
ID: 11111,
|
||||
CreatorID: 12345,
|
||||
SectionID: 98765,
|
||||
}
|
||||
mockConversation.EXPECT().GetByID(ctx, int64(11111)).Return(mockConv, nil)
|
||||
|
||||
// Mock agent run failure to avoid pullStream complexity
|
||||
mockAgentRun.EXPECT().AgentRun(ctx, gomock.Any()).Return(nil, errors.New("mock stream error"))
|
||||
|
||||
err := app.OpenapiAgentRun(ctx, &sseImpl.SSenderImpl{}, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "mock stream error")
|
||||
|
||||
// Verify that only the non-empty message is included
|
||||
assert.Len(t, req.AdditionalMessages, 2) // Original request still has 2 messages
|
||||
}
|
||||
|
||||
func TestOpenapiAgentRun_ParseAdditionalMessages_NilMessage(t *testing.T) {
|
||||
app, _, _, mockAgentRun, mockConversation, mockSingleAgent, _ := setupMocks(t)
|
||||
ctx := createTestContext()
|
||||
|
||||
// Create request with empty content message (should be skipped)
|
||||
req := &run.ChatV3Request{
|
||||
BotID: 67890,
|
||||
ConversationID: ptr.Of(int64(11111)),
|
||||
User: "test-user",
|
||||
AdditionalMessages: []*run.EnterMessage{
|
||||
{
|
||||
Role: "user",
|
||||
Content: "", // Empty content message
|
||||
ContentType: run.ContentTypeText,
|
||||
},
|
||||
{
|
||||
Role: "user",
|
||||
Content: "Valid content",
|
||||
ContentType: run.ContentTypeText,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Mock agent check success
|
||||
mockAgent := &saEntity.SingleAgent{
|
||||
SingleAgent: &singleagent.SingleAgent{
|
||||
AgentID: 67890,
|
||||
SpaceID: 54321,
|
||||
},
|
||||
}
|
||||
mockSingleAgent.EXPECT().ObtainAgentByIdentity(ctx, gomock.Any()).Return(mockAgent, nil)
|
||||
|
||||
// Mock conversation check success
|
||||
mockConv := &convEntity.Conversation{
|
||||
ID: 11111,
|
||||
CreatorID: 12345,
|
||||
SectionID: 98765,
|
||||
}
|
||||
mockConversation.EXPECT().GetByID(ctx, int64(11111)).Return(mockConv, nil)
|
||||
|
||||
// Mock agent run failure to avoid pullStream complexity
|
||||
mockAgentRun.EXPECT().AgentRun(ctx, gomock.Any()).Return(nil, errors.New("mock stream error"))
|
||||
|
||||
err := app.OpenapiAgentRun(ctx, &sseImpl.SSenderImpl{}, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "mock stream error")
|
||||
}
|
||||
@ -22,6 +22,7 @@ import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"hash/crc32"
|
||||
"image"
|
||||
_ "image/gif"
|
||||
@ -279,6 +280,7 @@ func stringToMap(input string) map[string]string {
|
||||
return result
|
||||
}
|
||||
func (u *UploadService) UploadFileCommon(ctx context.Context, req *upload.CommonUploadRequest, fullPath string) (*upload.CommonUploadResponse, error) {
|
||||
var err error
|
||||
resp := upload.NewCommonUploadResponse()
|
||||
re := regexp.MustCompile(consts.UploadURI + `/([^?]+)`)
|
||||
match := re.FindStringSubmatch(fullPath)
|
||||
@ -321,13 +323,13 @@ func (u *UploadService) UploadFileCommon(ctx context.Context, req *upload.Common
|
||||
resp.Payload = &upload.Payload{Key: uuid.NewString()}
|
||||
return resp, nil
|
||||
}
|
||||
var err error
|
||||
|
||||
opts := make([]storage.PutOptFn, 0, 2)
|
||||
contentType := getContentType(objKey)
|
||||
if len(contentType) != 0 {
|
||||
err = u.oss.PutObject(ctx, objKey, req.ByteData, storage.WithContentType(contentType))
|
||||
} else {
|
||||
err = u.oss.PutObject(ctx, objKey, req.ByteData)
|
||||
opts = append(opts, storage.WithContentType(contentType))
|
||||
}
|
||||
err = u.oss.PutObject(ctx, objKey, req.ByteData, opts...)
|
||||
if err != nil {
|
||||
return resp, errorx.New(errno.ErrUploadSystemErrorCode, errorx.KV("msg", err.Error()))
|
||||
}
|
||||
@ -738,3 +740,16 @@ func (u *UploadService) CommitImageUpload(ctx context.Context, req *upload.Apply
|
||||
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (u *UploadService) RecordFileInfo(ctx context.Context, req *upload.RecordFileInfoRequest) (*upload.RecordFileInfoResponse, error) {
|
||||
err := u.oss.PutObjectTagging(ctx, req.GetFileURI(), map[string]string{
|
||||
"filename": req.GetFileName(),
|
||||
"file_ext": req.GetFileExtension(),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &upload.RecordFileInfoResponse{}, nil
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -764,6 +765,87 @@ func (w *ApplicationService) GetProcess(ctx context.Context, req *workflow.GetWo
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func collectFileFields(ctx context.Context, workflowID int64) (map[string]bool, error) {
|
||||
wf, err := GetWorkflowDomainSVC().Get(ctx, &vo.GetPolicy{
|
||||
ID: workflowID,
|
||||
QType: workflowModel.FromDraft,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
canvas := &vo.Canvas{}
|
||||
err = sonic.UnmarshalString(wf.Canvas, canvas)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var startNode *vo.Node
|
||||
for _, n := range canvas.Nodes {
|
||||
if n.ID == "100001" {
|
||||
startNode = n
|
||||
break
|
||||
}
|
||||
}
|
||||
if startNode == nil {
|
||||
return nil, fmt.Errorf("workflow invalid, not found start node")
|
||||
}
|
||||
fileFields := make(map[string]bool)
|
||||
for _, v := range startNode.Data.Outputs {
|
||||
v, err := vo.ParseVariable(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if v.AssistType >= vo.AssistTypeDefault && v.AssistType <= vo.AssistTypeVoice {
|
||||
fileFields[v.Name] = true
|
||||
}
|
||||
}
|
||||
return fileFields, nil
|
||||
}
|
||||
|
||||
func (w *ApplicationService) adaptorInputFileFields(ctx context.Context, workflowID int64, input string) (string, error) {
|
||||
fileFields, err := collectFileFields(ctx, workflowID)
|
||||
inputMap := make(map[string]any)
|
||||
err = sonic.UnmarshalString(input, &inputMap)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
appendQueryFileName := func(v string) (string, error) {
|
||||
u, err := url.Parse(v)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
filename := u.Query().Get("x-wf-file_name")
|
||||
if len(filename) > 0 {
|
||||
return u.String(), nil
|
||||
}
|
||||
fileURI := strings.TrimPrefix(u.Path, "/opencoze")
|
||||
tagging, err := w.TosClient.GetObjectTagging(ctx, fileURI)
|
||||
if err != nil {
|
||||
logs.CtxWarnf(ctx, fmt.Sprintf("GetObjectTagging failed: %v", err))
|
||||
return input, nil
|
||||
}
|
||||
if fName, ok := tagging["filename"]; ok {
|
||||
query := u.Query()
|
||||
query.Set("x-wf-file_name", fName)
|
||||
u.RawQuery = query.Encode()
|
||||
}
|
||||
return u.String(), nil
|
||||
|
||||
}
|
||||
for k, v := range inputMap {
|
||||
if fileFields[k] {
|
||||
v, err = appendQueryFileName(v.(string))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
inputMap[k] = v
|
||||
}
|
||||
}
|
||||
input, _ = sonic.MarshalString(inputMap)
|
||||
return input, nil
|
||||
|
||||
}
|
||||
|
||||
func (w *ApplicationService) GetNodeExecuteHistory(ctx context.Context, req *workflow.GetNodeExecuteHistoryRequest) (
|
||||
_ *workflow.GetNodeExecuteHistoryResponse, err error,
|
||||
) {
|
||||
@ -807,6 +889,11 @@ func (w *ApplicationService) GetNodeExecuteHistory(ctx context.Context, req *wor
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result.Input, err = w.adaptorInputFileFields(ctx, mustParseInt64(req.GetWorkflowID()), result.Input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &workflow.GetNodeExecuteHistoryResponse{
|
||||
Data: result,
|
||||
}, nil
|
||||
@ -1322,10 +1409,10 @@ func mergeBatchModeNodes(parent, inner *workflow.NodeResult) *workflow.NodeResul
|
||||
type StreamRunEventType string
|
||||
|
||||
const (
|
||||
DoneEvent StreamRunEventType = "Done"
|
||||
MessageEvent StreamRunEventType = "Message"
|
||||
ErrEvent StreamRunEventType = "Error"
|
||||
InterruptEvent StreamRunEventType = "Interrupt"
|
||||
DoneEvent StreamRunEventType = "done"
|
||||
MessageEvent StreamRunEventType = "message"
|
||||
ErrEvent StreamRunEventType = "error"
|
||||
InterruptEvent StreamRunEventType = "interrupt"
|
||||
)
|
||||
|
||||
func convertStreamRunEvent(workflowID int64) func(msg *entity.Message) (res *workflow.OpenAPIStreamRunFlowResponse, err error) {
|
||||
|
||||
@ -30,7 +30,6 @@ 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)
|
||||
BatchCreate(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)
|
||||
|
||||
@ -59,21 +59,6 @@ func (m *MockMessage) EXPECT() *MockMessageMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// BatchCreate mocks base method.
|
||||
func (m *MockMessage) BatchCreate(ctx context.Context, msg []*message.Message) ([]*message.Message, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "BatchCreate", ctx, msg)
|
||||
ret0, _ := ret[0].([]*message.Message)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// BatchCreate indicates an expected call of BatchCreate.
|
||||
func (mr *MockMessageMockRecorder) BatchCreate(ctx, msg any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BatchCreate", reflect.TypeOf((*MockMessage)(nil).BatchCreate), ctx, msg)
|
||||
}
|
||||
|
||||
// Create mocks base method.
|
||||
func (m *MockMessage) Create(ctx context.Context, msg *message.Message) (*message.Message, error) {
|
||||
m.ctrl.T.Helper()
|
||||
|
||||
@ -24,8 +24,10 @@ import (
|
||||
|
||||
var defaultSVC Uploader
|
||||
|
||||
//go:generate mockgen -destination uploadmock/upload_mock.go --package uploadmock -source upload.go
|
||||
type Uploader interface {
|
||||
GetFile(ctx context.Context, req *service.GetFileRequest) (resp *service.GetFileResponse, err error)
|
||||
GetFileTagging(ctx context.Context, req *service.GetFileTaggingRequest) (resp *service.GetFileTaggingResponse, err error)
|
||||
}
|
||||
|
||||
func SetDefaultSVC(s Uploader) {
|
||||
|
||||
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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: upload.go
|
||||
//
|
||||
// Generated by this command:
|
||||
//
|
||||
// mockgen -destination uploadmock/upload_mock.go --package uploadmock -source upload.go
|
||||
//
|
||||
|
||||
// Package uploadmock is a generated GoMock package.
|
||||
package uploadmock
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
service "github.com/coze-dev/coze-studio/backend/domain/upload/service"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
// MockUploader is a mock of Uploader interface.
|
||||
type MockUploader struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockUploaderMockRecorder
|
||||
isgomock struct{}
|
||||
}
|
||||
|
||||
// MockUploaderMockRecorder is the mock recorder for MockUploader.
|
||||
type MockUploaderMockRecorder struct {
|
||||
mock *MockUploader
|
||||
}
|
||||
|
||||
// NewMockUploader creates a new mock instance.
|
||||
func NewMockUploader(ctrl *gomock.Controller) *MockUploader {
|
||||
mock := &MockUploader{ctrl: ctrl}
|
||||
mock.recorder = &MockUploaderMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockUploader) EXPECT() *MockUploaderMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// GetFile mocks base method.
|
||||
func (m *MockUploader) GetFile(ctx context.Context, req *service.GetFileRequest) (*service.GetFileResponse, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetFile", ctx, req)
|
||||
ret0, _ := ret[0].(*service.GetFileResponse)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetFile indicates an expected call of GetFile.
|
||||
func (mr *MockUploaderMockRecorder) GetFile(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFile", reflect.TypeOf((*MockUploader)(nil).GetFile), ctx, req)
|
||||
}
|
||||
|
||||
// GetFileTagging mocks base method.
|
||||
func (m *MockUploader) GetFileTagging(ctx context.Context, req *service.GetFileTaggingRequest) (*service.GetFileTaggingResponse, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetFileTagging", ctx, req)
|
||||
ret0, _ := ret[0].(*service.GetFileTaggingResponse)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetFileTagging indicates an expected call of GetFileTagging.
|
||||
func (mr *MockUploaderMockRecorder) GetFileTagging(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFileTagging", reflect.TypeOf((*MockUploader)(nil).GetFileTagging), ctx, req)
|
||||
}
|
||||
@ -170,9 +170,6 @@ func (c *impl) GetMessageByID(ctx context.Context, id int64) (*entity.Message, e
|
||||
func (c *impl) ListWithoutPair(ctx context.Context, req *entity.ListMeta) (*entity.ListResult, error) {
|
||||
return c.DomainSVC.ListWithoutPair(ctx, req)
|
||||
}
|
||||
func (c *impl) BatchCreate(ctx context.Context, msgs []*entity.Message) ([]*entity.Message, error) {
|
||||
return c.DomainSVC.BatchCreate(ctx, msgs)
|
||||
}
|
||||
|
||||
func convertToConvAndSchemaMessage(ctx context.Context, msgs []*entity.Message) ([]*crossmessage.WfMessage, []*schema.Message, error) {
|
||||
messages := make([]*schema.Message, 0)
|
||||
|
||||
@ -40,3 +40,6 @@ func InitDomainService(c service.UploadService) crossupload.Uploader {
|
||||
func (c *impl) GetFile(ctx context.Context, req *service.GetFileRequest) (resp *service.GetFileResponse, err error) {
|
||||
return c.DomainSVC.GetFile(ctx, req)
|
||||
}
|
||||
func (c *impl) GetFileTagging(ctx context.Context, req *service.GetFileTaggingRequest) (resp *service.GetFileTaggingResponse, err error) {
|
||||
return c.DomainSVC.GetFileTagging(ctx, req)
|
||||
}
|
||||
|
||||
@ -25,7 +25,6 @@ import (
|
||||
"github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/entity"
|
||||
)
|
||||
|
||||
//go:generate mockgen -destination ../../../../internal/mock/domain/agent/singleagent/single_agent_mock.go --package singleagent -source single_agent.go
|
||||
type SingleAgent interface {
|
||||
// draft agent
|
||||
CreateSingleAgentDraft(ctx context.Context, creatorID int64, draft *entity.SingleAgent) (agentID int64, err error)
|
||||
|
||||
@ -106,34 +106,24 @@ type MetaInfo struct {
|
||||
}
|
||||
|
||||
type AgentRunMeta struct {
|
||||
ConversationID int64 `json:"conversation_id"`
|
||||
ConnectorID int64 `json:"connector_id"`
|
||||
SpaceID int64 `json:"space_id"`
|
||||
Scene common.Scene `json:"scene"`
|
||||
SectionID int64 `json:"section_id"`
|
||||
Name string `json:"name"`
|
||||
UserID string `json:"user_id"`
|
||||
CozeUID int64 `json:"coze_uid"`
|
||||
AgentID int64 `json:"agent_id"`
|
||||
ContentType message.ContentType `json:"content_type"`
|
||||
Content []*message.InputMetaData `json:"content"`
|
||||
PreRetrieveTools []*Tool `json:"tools"`
|
||||
IsDraft bool `json:"is_draft"`
|
||||
CustomerConfig *CustomerConfig `json:"customer_config"`
|
||||
DisplayContent string `json:"display_content"`
|
||||
CustomVariables map[string]string `json:"custom_variables"`
|
||||
Version string `json:"version"`
|
||||
Ext map[string]string `json:"ext"`
|
||||
AdditionalMessages []*AdditionalMessage `json:"additional_messages"`
|
||||
}
|
||||
|
||||
type AdditionalMessage struct {
|
||||
Role schema.RoleType `json:"role"`
|
||||
Type message.MessageType `json:"type"`
|
||||
Content []*message.InputMetaData `json:"content"`
|
||||
ContentType message.ContentType `json:"content_type"`
|
||||
Name *string `json:"name"`
|
||||
Meta map[string]string `json:"meta"`
|
||||
ConversationID int64 `json:"conversation_id"`
|
||||
ConnectorID int64 `json:"connector_id"`
|
||||
SpaceID int64 `json:"space_id"`
|
||||
Scene common.Scene `json:"scene"`
|
||||
SectionID int64 `json:"section_id"`
|
||||
Name string `json:"name"`
|
||||
UserID string `json:"user_id"`
|
||||
CozeUID int64 `json:"coze_uid"`
|
||||
AgentID int64 `json:"agent_id"`
|
||||
ContentType message.ContentType `json:"content_type"`
|
||||
Content []*message.InputMetaData `json:"content"`
|
||||
PreRetrieveTools []*Tool `json:"tools"`
|
||||
IsDraft bool `json:"is_draft"`
|
||||
CustomerConfig *CustomerConfig `json:"customer_config"`
|
||||
DisplayContent string `json:"display_content"`
|
||||
CustomVariables map[string]string `json:"custom_variables"`
|
||||
Version string `json:"version"`
|
||||
Ext map[string]string `json:"ext"`
|
||||
}
|
||||
|
||||
type UpdateMeta struct {
|
||||
|
||||
@ -41,7 +41,7 @@ import (
|
||||
|
||||
func (art *AgentRuntime) ChatflowRun(ctx context.Context, imagex imagex.ImageX) (err error) {
|
||||
|
||||
mh := &MessageEventHandler{
|
||||
mh := &MesssageEventHanlder{
|
||||
sw: art.SW,
|
||||
messageEvent: art.MessageEvent,
|
||||
}
|
||||
@ -110,7 +110,7 @@ func concatWfInput(rtDependence *AgentRuntime) string {
|
||||
return strings.Trim(input, ",")
|
||||
}
|
||||
|
||||
func (art *AgentRuntime) pullWfStream(ctx context.Context, events *schema.StreamReader[*crossworkflow.WorkflowMessage], mh *MessageEventHandler) {
|
||||
func (art *AgentRuntime) pullWfStream(ctx context.Context, events *schema.StreamReader[*crossworkflow.WorkflowMessage], mh *MesssageEventHanlder) {
|
||||
|
||||
fullAnswerContent := bytes.NewBuffer([]byte{})
|
||||
var usage *msgEntity.UsageExt
|
||||
|
||||
@ -221,51 +221,6 @@ func preCreateAnswer(ctx context.Context, rtDependence *AgentRuntime) (*msgEntit
|
||||
return crossmessage.DefaultSVC().PreCreate(ctx, msgMeta)
|
||||
}
|
||||
|
||||
func buildAdditionalMessage2Create(ctx context.Context, runRecord *entity.RunRecordMeta, additionalMessage *entity.AdditionalMessage, userID string) *message.Message {
|
||||
|
||||
msg := &msgEntity.Message{
|
||||
ConversationID: runRecord.ConversationID,
|
||||
RunID: runRecord.ID,
|
||||
AgentID: runRecord.AgentID,
|
||||
SectionID: runRecord.SectionID,
|
||||
UserID: userID,
|
||||
MessageType: additionalMessage.Type,
|
||||
}
|
||||
|
||||
switch additionalMessage.Type {
|
||||
case message.MessageTypeQuestion:
|
||||
msg.Role = schema.User
|
||||
msg.ContentType = additionalMessage.ContentType
|
||||
for _, content := range additionalMessage.Content {
|
||||
if content.Type == message.InputTypeText {
|
||||
msg.Content = content.Text
|
||||
break
|
||||
}
|
||||
}
|
||||
msg.MultiContent = additionalMessage.Content
|
||||
|
||||
case message.MessageTypeAnswer:
|
||||
msg.Role = schema.Assistant
|
||||
msg.ContentType = message.ContentTypeText
|
||||
for _, content := range additionalMessage.Content {
|
||||
if content.Type == message.InputTypeText {
|
||||
msg.Content = content.Text
|
||||
break
|
||||
}
|
||||
}
|
||||
modelContent := &schema.Message{
|
||||
Role: schema.Assistant,
|
||||
Content: msg.Content,
|
||||
}
|
||||
|
||||
jsonContent, err := json.Marshal(modelContent)
|
||||
if err == nil {
|
||||
msg.ModelContent = string(jsonContent)
|
||||
}
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
||||
func buildAgentMessage2Create(ctx context.Context, chunk *entity.AgentRespEvent, messageType message.MessageType, rtDependence *AgentRuntime) *message.Message {
|
||||
arm := rtDependence.GetRunMeta()
|
||||
msg := &msgEntity.Message{
|
||||
|
||||
@ -98,12 +98,12 @@ func (e *Event) SendStreamDoneEvent(sw *schema.StreamWriter[*entity.AgentRunResp
|
||||
sw.Send(resp, nil)
|
||||
}
|
||||
|
||||
type MessageEventHandler struct {
|
||||
type MesssageEventHanlder struct {
|
||||
messageEvent *Event
|
||||
sw *schema.StreamWriter[*entity.AgentRunResponse]
|
||||
}
|
||||
|
||||
func (mh *MessageEventHandler) handlerErr(_ context.Context, err error) {
|
||||
func (mh *MesssageEventHanlder) handlerErr(_ context.Context, err error) {
|
||||
|
||||
var errMsg string
|
||||
var statusErr errorx.StatusError
|
||||
@ -123,7 +123,7 @@ func (mh *MessageEventHandler) handlerErr(_ context.Context, err error) {
|
||||
})
|
||||
}
|
||||
|
||||
func (mh *MessageEventHandler) handlerAckMessage(_ context.Context, input *msgEntity.Message) error {
|
||||
func (mh *MesssageEventHanlder) handlerAckMessage(_ context.Context, input *msgEntity.Message) error {
|
||||
sendMsg := &entity.ChunkMessageItem{
|
||||
ID: input.ID,
|
||||
ConversationID: input.ConversationID,
|
||||
@ -142,7 +142,7 @@ func (mh *MessageEventHandler) handlerAckMessage(_ context.Context, input *msgEn
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mh *MessageEventHandler) handlerFunctionCall(ctx context.Context, chunk *entity.AgentRespEvent, rtDependence *AgentRuntime) error {
|
||||
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)
|
||||
@ -156,7 +156,7 @@ func (mh *MessageEventHandler) handlerFunctionCall(ctx context.Context, chunk *e
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mh *MessageEventHandler) handlerTooResponse(ctx context.Context, chunk *entity.AgentRespEvent, rtDependence *AgentRuntime, preToolResponseMsg *msgEntity.Message, toolResponseMsgContent string) error {
|
||||
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)
|
||||
|
||||
@ -184,7 +184,7 @@ func (mh *MessageEventHandler) handlerTooResponse(ctx context.Context, chunk *en
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mh *MessageEventHandler) handlerSuggest(ctx context.Context, chunk *entity.AgentRespEvent, rtDependence *AgentRuntime) error {
|
||||
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)
|
||||
@ -199,7 +199,7 @@ func (mh *MessageEventHandler) handlerSuggest(ctx context.Context, chunk *entity
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mh *MessageEventHandler) handlerKnowledge(ctx context.Context, chunk *entity.AgentRespEvent, rtDependence *AgentRuntime) error {
|
||||
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 {
|
||||
@ -212,7 +212,7 @@ func (mh *MessageEventHandler) handlerKnowledge(ctx context.Context, chunk *enti
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mh *MessageEventHandler) handlerAnswer(ctx context.Context, msg *entity.ChunkMessageItem, usage *msgEntity.UsageExt, rtDependence *AgentRuntime, preAnswerMsg *msgEntity.Message) error {
|
||||
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
|
||||
@ -265,7 +265,7 @@ func (mh *MessageEventHandler) handlerAnswer(ctx context.Context, msg *entity.Ch
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mh *MessageEventHandler) handlerFinalAnswerFinish(ctx context.Context, rtDependence *AgentRuntime) error {
|
||||
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 {
|
||||
@ -278,7 +278,7 @@ func (mh *MessageEventHandler) handlerFinalAnswerFinish(ctx context.Context, rtD
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mh *MessageEventHandler) handlerInterruptVerbose(ctx context.Context, chunk *entity.AgentRespEvent, rtDependence *AgentRuntime) error {
|
||||
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 {
|
||||
@ -291,7 +291,7 @@ func (mh *MessageEventHandler) handlerInterruptVerbose(ctx context.Context, chun
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mh *MessageEventHandler) handlerWfUsage(ctx context.Context, msg *entity.ChunkMessageItem, usage *msgEntity.UsageExt) error {
|
||||
func (mh *MesssageEventHanlder) handlerWfUsage(ctx context.Context, msg *entity.ChunkMessageItem, usage *msgEntity.UsageExt) error {
|
||||
|
||||
if msg.Ext == nil {
|
||||
msg.Ext = map[string]string{}
|
||||
@ -314,7 +314,7 @@ func (mh *MessageEventHandler) handlerWfUsage(ctx context.Context, msg *entity.C
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mh *MessageEventHandler) handlerInterrupt(ctx context.Context, chunk *entity.AgentRespEvent, rtDependence *AgentRuntime, firstAnswerMsg *msgEntity.Message, reasoningContent string) error {
|
||||
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
|
||||
@ -366,7 +366,7 @@ func (mh *MessageEventHandler) handlerInterrupt(ctx context.Context, chunk *enti
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mh *MessageEventHandler) handlerWfInterruptMsg(ctx context.Context, stateMsg *crossworkflow.StateMessage, rtDependence *AgentRuntime) {
|
||||
func (mh *MesssageEventHanlder) handlerWfInterruptMsg(ctx context.Context, stateMsg *crossworkflow.StateMessage, rtDependence *AgentRuntime) {
|
||||
interruptData, cType, err := handlerWfInterruptEvent(ctx, stateMsg.InterruptEvent)
|
||||
if err != nil {
|
||||
return
|
||||
@ -412,7 +412,7 @@ func (mh *MessageEventHandler) handlerWfInterruptMsg(ctx context.Context, stateM
|
||||
}
|
||||
}
|
||||
|
||||
func (mh *MessageEventHandler) HandlerInput(ctx context.Context, rtDependence *AgentRuntime) (*msgEntity.Message, error) {
|
||||
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)
|
||||
@ -426,21 +426,3 @@ func (mh *MessageEventHandler) HandlerInput(ctx context.Context, rtDependence *A
|
||||
}
|
||||
return cm, nil
|
||||
}
|
||||
|
||||
func (mh *MessageEventHandler) ParseAdditionalMessages(ctx context.Context, rtDependence *AgentRuntime, runRecord *entity.RunRecordMeta) error {
|
||||
|
||||
if len(rtDependence.GetRunMeta().AdditionalMessages) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
additionalMessages := make([]*message.Message, 0, len(rtDependence.GetRunMeta().AdditionalMessages))
|
||||
|
||||
for _, msg := range rtDependence.GetRunMeta().AdditionalMessages {
|
||||
cm := buildAdditionalMessage2Create(ctx, runRecord, msg, rtDependence.GetRunMeta().UserID)
|
||||
additionalMessages = append(additionalMessages, cm)
|
||||
}
|
||||
|
||||
_, err := crossmessage.DefaultSVC().BatchCreate(ctx, additionalMessages)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@ -107,11 +107,6 @@ func (rd *AgentRuntime) GetHistory() []*msgEntity.Message {
|
||||
|
||||
func (art *AgentRuntime) Run(ctx context.Context) (err error) {
|
||||
|
||||
mh := &MessageEventHandler{
|
||||
messageEvent: art.MessageEvent,
|
||||
sw: art.SW,
|
||||
}
|
||||
|
||||
agentInfo, err := getAgentInfo(ctx, art.GetRunMeta().AgentID, art.GetRunMeta().IsDraft, art.GetRunMeta().ConnectorID)
|
||||
if err != nil {
|
||||
return
|
||||
@ -119,18 +114,6 @@ func (art *AgentRuntime) Run(ctx context.Context) (err error) {
|
||||
|
||||
art.SetAgentInfo(agentInfo)
|
||||
|
||||
if len(art.GetRunMeta().AdditionalMessages) > 0 {
|
||||
var additionalRunRecord *entity.RunRecordMeta
|
||||
additionalRunRecord, err = art.RunRecordRepo.Create(ctx, art.GetRunMeta())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = mh.ParseAdditionalMessages(ctx, art, additionalRunRecord)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
history, err := art.getHistory(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
@ -157,7 +140,10 @@ func (art *AgentRuntime) Run(ctx context.Context) (err error) {
|
||||
}
|
||||
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
|
||||
|
||||
@ -80,7 +80,7 @@ func (art *AgentRuntime) AgentStreamExecute(ctx context.Context, imagex imagex.I
|
||||
|
||||
func (art *AgentRuntime) push(ctx context.Context, mainChan chan *entity.AgentRespEvent) {
|
||||
|
||||
mh := &MessageEventHandler{
|
||||
mh := &MesssageEventHanlder{
|
||||
sw: art.SW,
|
||||
messageEvent: art.MessageEvent,
|
||||
}
|
||||
|
||||
@ -24,7 +24,6 @@ import (
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/entity"
|
||||
)
|
||||
|
||||
//go:generate mockgen -destination ../../../../internal/mock/domain/conversation/agentrun/agent_run_mock.go --package agentrun -source agent_run.go
|
||||
type Run interface {
|
||||
AgentRun(ctx context.Context, req *entity.AgentRunMeta) (*schema.StreamReader[*entity.AgentRunResponse], error)
|
||||
Delete(ctx context.Context, runID []int64) error
|
||||
|
||||
@ -22,7 +22,6 @@ import (
|
||||
"github.com/coze-dev/coze-studio/backend/domain/conversation/conversation/entity"
|
||||
)
|
||||
|
||||
//go:generate mockgen -destination ../../../../internal/mock/domain/conversation/conversation/conversation_mock.go --package conversation -source conversation.go
|
||||
type Conversation interface {
|
||||
Create(ctx context.Context, req *entity.CreateMeta) (*entity.Conversation, error)
|
||||
GetByID(ctx context.Context, id int64) (*entity.Conversation, error)
|
||||
|
||||
@ -72,25 +72,6 @@ func (dao *MessageDAO) Create(ctx context.Context, msg *entity.Message) (*entity
|
||||
return dao.messagePO2DO(poData), nil
|
||||
}
|
||||
|
||||
func (dao *MessageDAO) BatchCreate(ctx context.Context, msg []*entity.Message) ([]*entity.Message, error) {
|
||||
poList := make([]*model.Message, 0, len(msg))
|
||||
for _, m := range msg {
|
||||
po, err := dao.messageDO2PO(ctx, m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
poList = append(poList, po)
|
||||
}
|
||||
|
||||
do := dao.query.Message.WithContext(ctx).Debug()
|
||||
cErr := do.CreateInBatches(poList, len(poList))
|
||||
if cErr != nil {
|
||||
return nil, cErr
|
||||
}
|
||||
|
||||
return dao.batchMessagePO2DO(poList), nil
|
||||
}
|
||||
|
||||
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(listMeta.ConversationID)).Where(m.Status.Eq(int32(entity.MessageStatusAvailable)))
|
||||
|
||||
@ -34,7 +34,6 @@ 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)
|
||||
BatchCreate(ctx context.Context, msg []*entity.Message) ([]*entity.Message, 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)
|
||||
|
||||
@ -27,7 +27,6 @@ type Message interface {
|
||||
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)
|
||||
BatchCreate(ctx context.Context, req []*entity.Message) ([]*entity.Message, error)
|
||||
GetByRunIDs(ctx context.Context, conversationID int64, runIDs []int64) ([]*entity.Message, error)
|
||||
GetByID(ctx context.Context, id int64) (*entity.Message, error)
|
||||
Edit(ctx context.Context, req *entity.Message) (*entity.Message, error)
|
||||
|
||||
@ -124,10 +124,6 @@ func (m *messageImpl) GetByID(ctx context.Context, id int64) (*entity.Message, e
|
||||
return m.MessageRepo.GetByID(ctx, id)
|
||||
}
|
||||
|
||||
func (m *messageImpl) BatchCreate(ctx context.Context, req []*entity.Message) ([]*entity.Message, error) {
|
||||
return m.MessageRepo.BatchCreate(ctx, req)
|
||||
}
|
||||
|
||||
func (m *messageImpl) Broken(ctx context.Context, req *entity.BrokenMeta) error {
|
||||
|
||||
_, err := m.MessageRepo.Edit(ctx, req.ID, &message.Message{
|
||||
|
||||
@ -494,55 +494,3 @@ func TestListWithoutPair(t *testing.T) {
|
||||
assert.Equal(t, "Answer message", resp.Messages[0].Content)
|
||||
})
|
||||
}
|
||||
|
||||
func TestBatchCreate(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
mockDBGen := orm.NewMockDB()
|
||||
mockDBGen.AddTable(&model.Message{})
|
||||
mockDB, err := mockDBGen.DB()
|
||||
assert.NoError(t, err)
|
||||
|
||||
components := &Components{
|
||||
MessageRepo: repository.NewMessageRepo(mockDB, nil),
|
||||
}
|
||||
|
||||
|
||||
t.Run("success_single_message", func(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
// 准备测试数据
|
||||
inputMsgs := []*entity.Message{
|
||||
{
|
||||
ID: 1,
|
||||
ConversationID: 100,
|
||||
RunID: 200,
|
||||
AgentID: 300,
|
||||
UserID: "user123",
|
||||
Content: "Hello World",
|
||||
Role: schema.User,
|
||||
ContentType: message.ContentTypeText,
|
||||
MessageType: message.MessageTypeQuestion,
|
||||
Status: message.MessageStatusAvailable,
|
||||
},
|
||||
{
|
||||
ID: 2,
|
||||
ConversationID: 100,
|
||||
RunID: 200,
|
||||
AgentID: 300,
|
||||
UserID: "user123",
|
||||
Content: "Hello World",
|
||||
Role: schema.Assistant,
|
||||
ContentType: message.ContentTypeText,
|
||||
MessageType: message.MessageTypeQuestion,
|
||||
Status: message.MessageStatusAvailable,
|
||||
},
|
||||
}
|
||||
|
||||
result, err := NewService(components).BatchCreate(ctx, inputMsgs)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, result, 2)
|
||||
assert.Equal(t, inputMsgs[1].ID, result[1].ID)
|
||||
})
|
||||
}
|
||||
|
||||
@ -1208,13 +1208,45 @@ func (d databaseService) executeSelectSQL(ctx context.Context, req *ExecuteSQLRe
|
||||
}
|
||||
selectReq.Fields = fields
|
||||
}
|
||||
|
||||
complexCond, err := generateComplexCond(ctx, req, tableInfo.RwMode, fieldNameToPhysical)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
var (
|
||||
finallyComplexCond *rdb.ComplexCondition
|
||||
complexCond *rdb.ComplexCondition
|
||||
)
|
||||
var err error
|
||||
if req.Condition != nil {
|
||||
complexCond, err = convertCondition(ctx, req.Condition, fieldNameToPhysical, req.SQLParams)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("convert condition failed: %v", err)
|
||||
}
|
||||
}
|
||||
if complexCond != nil {
|
||||
selectReq.Where = complexCond
|
||||
|
||||
// add rw mode
|
||||
var extraCondition *rdb.ComplexCondition
|
||||
if tableInfo.RwMode == table.BotTableRWMode_LimitedReadWrite && req.UserID != "" {
|
||||
cond := &rdb.Condition{
|
||||
Field: database.DefaultUidColName,
|
||||
Operator: entity3.OperatorEqual,
|
||||
Value: req.UserID,
|
||||
}
|
||||
extraCondition = &rdb.ComplexCondition{
|
||||
Conditions: []*rdb.Condition{cond},
|
||||
}
|
||||
}
|
||||
|
||||
if extraCondition != nil {
|
||||
finallyComplexCond = &rdb.ComplexCondition{
|
||||
NestedConditions: []*rdb.ComplexCondition{
|
||||
complexCond,
|
||||
extraCondition,
|
||||
},
|
||||
Operator: entity3.AND,
|
||||
}
|
||||
} else {
|
||||
finallyComplexCond = complexCond
|
||||
}
|
||||
|
||||
if finallyComplexCond != nil {
|
||||
selectReq.Where = finallyComplexCond
|
||||
}
|
||||
|
||||
if len(req.OrderByList) > 0 {
|
||||
@ -1354,16 +1386,48 @@ func (d databaseService) executeUpdateSQL(ctx context.Context, req *ExecuteSQLRe
|
||||
}
|
||||
}
|
||||
|
||||
req.SQLParams = req.SQLParams[index:]
|
||||
complexCond, err := generateComplexCond(ctx, req, tableInfo.RwMode, fieldNameToPhysical)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
condParams := req.SQLParams[index:]
|
||||
var (
|
||||
finallyComplexCond *rdb.ComplexCondition
|
||||
complexCond *rdb.ComplexCondition
|
||||
)
|
||||
var err error
|
||||
if req.Condition != nil {
|
||||
complexCond, err = convertCondition(ctx, req.Condition, fieldNameToPhysical, condParams)
|
||||
if err != nil {
|
||||
return -1, fmt.Errorf("convert condition failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// add rw mode
|
||||
var extraCondition *rdb.ComplexCondition
|
||||
if tableInfo.RwMode == table.BotTableRWMode_LimitedReadWrite && req.UserID != "" {
|
||||
cond := &rdb.Condition{
|
||||
Field: database.DefaultUidColName,
|
||||
Operator: entity3.OperatorEqual,
|
||||
Value: req.UserID,
|
||||
}
|
||||
extraCondition = &rdb.ComplexCondition{
|
||||
Conditions: []*rdb.Condition{cond},
|
||||
}
|
||||
}
|
||||
|
||||
if extraCondition != nil {
|
||||
finallyComplexCond = &rdb.ComplexCondition{
|
||||
NestedConditions: []*rdb.ComplexCondition{
|
||||
complexCond,
|
||||
extraCondition,
|
||||
},
|
||||
Operator: entity3.AND,
|
||||
}
|
||||
} else {
|
||||
finallyComplexCond = complexCond
|
||||
}
|
||||
|
||||
updateResp, err := d.rdb.UpdateData(ctx, &rdb.UpdateDataRequest{
|
||||
TableName: physicalTableName,
|
||||
Data: updateData,
|
||||
Where: complexCond,
|
||||
Where: finallyComplexCond,
|
||||
Limit: int64PtrToIntPtr(req.Limit),
|
||||
})
|
||||
if err != nil {
|
||||
@ -1378,14 +1442,46 @@ func (d databaseService) executeDeleteSQL(ctx context.Context, req *ExecuteSQLRe
|
||||
return -1, fmt.Errorf("missing delete condition")
|
||||
}
|
||||
|
||||
complexCond, err := generateComplexCond(ctx, req, tableInfo.RwMode, fieldNameToPhysical)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
var (
|
||||
finallyComplexCond *rdb.ComplexCondition
|
||||
complexCond *rdb.ComplexCondition
|
||||
)
|
||||
var err error
|
||||
if req.Condition != nil {
|
||||
complexCond, err = convertCondition(ctx, req.Condition, fieldNameToPhysical, req.SQLParams)
|
||||
if err != nil {
|
||||
return -1, fmt.Errorf("convert condition failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// add rw mode
|
||||
var extraCondition *rdb.ComplexCondition
|
||||
if tableInfo.RwMode == table.BotTableRWMode_LimitedReadWrite && req.UserID != "" {
|
||||
cond := &rdb.Condition{
|
||||
Field: database.DefaultUidColName,
|
||||
Operator: entity3.OperatorEqual,
|
||||
Value: req.UserID,
|
||||
}
|
||||
extraCondition = &rdb.ComplexCondition{
|
||||
Conditions: []*rdb.Condition{cond},
|
||||
}
|
||||
}
|
||||
|
||||
if extraCondition != nil {
|
||||
finallyComplexCond = &rdb.ComplexCondition{
|
||||
NestedConditions: []*rdb.ComplexCondition{
|
||||
complexCond,
|
||||
extraCondition,
|
||||
},
|
||||
Operator: entity3.AND,
|
||||
}
|
||||
} else {
|
||||
finallyComplexCond = complexCond
|
||||
}
|
||||
|
||||
deleteResp, err := d.rdb.DeleteData(ctx, &rdb.DeleteDataRequest{
|
||||
TableName: physicalTableName,
|
||||
Where: complexCond,
|
||||
Where: finallyComplexCond,
|
||||
Limit: int64PtrToIntPtr(req.Limit),
|
||||
})
|
||||
if err != nil {
|
||||
@ -1482,6 +1578,13 @@ func convertCondition(ctx context.Context, cond *database.ComplexCondition, fiel
|
||||
}
|
||||
result.Conditions = conditions
|
||||
}
|
||||
// if cond.NestedConditions != nil {
|
||||
// nested, err := convertCondition(cond.NestedConditions, fieldMap, params)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// result.NestedConditions = []*rdb.ComplexCondition{nested}
|
||||
// }
|
||||
|
||||
return result, nil
|
||||
}
|
||||
@ -2141,50 +2244,3 @@ func (d databaseService) GetAllDatabaseByAppID(ctx context.Context, req *GetAllD
|
||||
Databases: onlineDBs,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func generateComplexCond(ctx context.Context, req *ExecuteSQLRequest, mode table.BotTableRWMode, fieldNameToPhysical map[string]string) (*rdb.ComplexCondition, error) {
|
||||
var (
|
||||
err error
|
||||
complexCond *rdb.ComplexCondition
|
||||
extraCondition *rdb.ComplexCondition
|
||||
)
|
||||
if req.Condition != nil {
|
||||
complexCond, err = convertCondition(ctx, req.Condition, fieldNameToPhysical, req.SQLParams)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("convert condition failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if mode == table.BotTableRWMode_LimitedReadWrite && req.UserID != "" {
|
||||
cond := &rdb.Condition{
|
||||
Field: database.DefaultUidColName,
|
||||
Operator: entity3.OperatorEqual,
|
||||
Value: req.UserID,
|
||||
}
|
||||
extraCondition = &rdb.ComplexCondition{
|
||||
Conditions: []*rdb.Condition{cond},
|
||||
}
|
||||
}
|
||||
|
||||
if complexCond != nil && extraCondition != nil {
|
||||
return &rdb.ComplexCondition{
|
||||
NestedConditions: []*rdb.ComplexCondition{
|
||||
complexCond,
|
||||
extraCondition,
|
||||
},
|
||||
Operator: entity3.AND,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
if complexCond != nil {
|
||||
return complexCond, nil
|
||||
}
|
||||
|
||||
if extraCondition != nil {
|
||||
return extraCondition, nil
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
|
||||
}
|
||||
|
||||
@ -634,52 +634,6 @@ func TestExecuteSQLWithOperations(t *testing.T) {
|
||||
assert.NotNil(t, selectINResp)
|
||||
assert.True(t, len(selectINResp.Records) == 2)
|
||||
|
||||
executeSelectWithOrOperationReq := &ExecuteSQLRequest{
|
||||
DatabaseID: resp.Database.ID,
|
||||
TableType: table.TableType_OnlineTable,
|
||||
OperateType: database.OperateType_Select,
|
||||
SelectFieldList: selectFields,
|
||||
Limit: &limit,
|
||||
UserID: "1001",
|
||||
SpaceID: 1,
|
||||
OrderByList: []database.OrderBy{
|
||||
{
|
||||
Field: "id_custom",
|
||||
Direction: table.SortDirection_Desc,
|
||||
},
|
||||
},
|
||||
SQLParams: []*database.SQLParamVal{
|
||||
{
|
||||
Value: ptr.Of("Alice"),
|
||||
},
|
||||
{
|
||||
Value: ptr.Of("100"),
|
||||
},
|
||||
},
|
||||
Condition: &database.ComplexCondition{
|
||||
Conditions: []*database.Condition{
|
||||
{
|
||||
Left: "name",
|
||||
Operation: database.Operation_EQUAL,
|
||||
Right: "?",
|
||||
},
|
||||
{
|
||||
Left: "score",
|
||||
Operation: database.Operation_EQUAL,
|
||||
Right: "?",
|
||||
},
|
||||
},
|
||||
Logic: database.Logic_Or,
|
||||
},
|
||||
}
|
||||
|
||||
selectWithOrOperationResp, err := dbService.ExecuteSQL(context.Background(), executeSelectWithOrOperationReq)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, selectWithOrOperationResp)
|
||||
assert.Equal(t, string(selectWithOrOperationResp.Records[0]["name"].([]uint8)), "Alice")
|
||||
assert.True(t, len(selectWithOrOperationResp.Records) == 1)
|
||||
|
||||
updateRows := []*database.UpsertRow{
|
||||
{
|
||||
Records: []*database.Record{
|
||||
|
||||
@ -22,7 +22,6 @@ import (
|
||||
"github.com/coze-dev/coze-studio/backend/domain/shortcutcmd/entity"
|
||||
)
|
||||
|
||||
//go:generate mockgen -destination ../../../internal/mock/domain/shortcutcmd/shortcut_cmd_mock.go --package shortcutcmd -source shortcut_cmd.go
|
||||
type ShortcutCmd interface {
|
||||
ListCMD(ctx context.Context, lm *entity.ListMeta) ([]*entity.ShortcutCmd, error)
|
||||
CreateCMD(ctx context.Context, shortcut *entity.ShortcutCmd) (*entity.ShortcutCmd, error)
|
||||
|
||||
@ -22,12 +22,12 @@ import (
|
||||
"github.com/coze-dev/coze-studio/backend/domain/upload/entity"
|
||||
)
|
||||
|
||||
//go:generate mockgen -destination ../../../internal/mock/domain/upload/upload_service_mock.go --package upload -source interface.go
|
||||
type UploadService interface {
|
||||
UploadFile(ctx context.Context, req *UploadFileRequest) (resp *UploadFileResponse, err error)
|
||||
UploadFiles(ctx context.Context, req *UploadFilesRequest) (resp *UploadFilesResponse, err error)
|
||||
GetFiles(ctx context.Context, req *GetFilesRequest) (resp *GetFilesResponse, err error)
|
||||
GetFile(ctx context.Context, req *GetFileRequest) (resp *GetFileResponse, err error)
|
||||
GetFileTagging(ctx context.Context, req *GetFileTaggingRequest) (resp *GetFileTaggingResponse, err error)
|
||||
}
|
||||
|
||||
type UploadFileRequest struct {
|
||||
@ -59,3 +59,10 @@ type GetFileRequest struct {
|
||||
type GetFileResponse struct {
|
||||
File *entity.File `json:"file"`
|
||||
}
|
||||
|
||||
type GetFileTaggingRequest struct {
|
||||
FileURI string `json:"file_uri"`
|
||||
}
|
||||
type GetFileTaggingResponse struct {
|
||||
Tagging map[string]string `json:"tagging"`
|
||||
}
|
||||
|
||||
@ -95,3 +95,14 @@ func (u *uploadSVC) GetFile(ctx context.Context, req *GetFileRequest) (resp *Get
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (u *uploadSVC) GetFileTagging(ctx context.Context, req *GetFileTaggingRequest) (resp *GetFileTaggingResponse, err error) {
|
||||
tagging, err := u.oss.GetObjectTagging(ctx, req.FileURI)
|
||||
if err != nil {
|
||||
return nil, errorx.WrapByCode(err, errno.ErrUploadSystemErrorCode)
|
||||
}
|
||||
return &GetFileTaggingResponse{
|
||||
Tagging: tagging,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
@ -45,7 +45,10 @@ import (
|
||||
mockmodel "github.com/coze-dev/coze-studio/backend/crossdomain/contract/modelmgr/modelmock"
|
||||
crossplugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin"
|
||||
"github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/pluginmock"
|
||||
crossupload "github.com/coze-dev/coze-studio/backend/crossdomain/contract/upload"
|
||||
"github.com/coze-dev/coze-studio/backend/crossdomain/contract/upload/uploadmock"
|
||||
"github.com/coze-dev/coze-studio/backend/crossdomain/impl/code"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/upload/service"
|
||||
userentity "github.com/coze-dev/coze-studio/backend/domain/user/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
|
||||
@ -709,7 +712,14 @@ func TestKnowledgeDeleter(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
mockUpload := uploadmock.NewMockUploader(ctrl)
|
||||
mockUpload.EXPECT().GetFileTagging(gomock.Any(), gomock.Any()).Return(&service.GetFileTaggingResponse{
|
||||
Tagging: map[string]string{
|
||||
"filename": "1706.03762v7.pdf",
|
||||
"file_ext": ".pdf",
|
||||
},
|
||||
}, nil)
|
||||
crossupload.SetDefaultSVC(mockUpload)
|
||||
mockKnowledgeOperator := knowledgemock.NewMockKnowledge(ctrl)
|
||||
crossknowledge.SetDefaultSVC(mockKnowledgeOperator)
|
||||
|
||||
|
||||
@ -368,7 +368,23 @@ func (w *Workflow) getInnerWorkflow(ctx context.Context, cNode *schema.Composite
|
||||
continue
|
||||
}
|
||||
|
||||
addFieldMappingsWithDeduplication(carryOvers, fromNodeKey, fieldMappings)
|
||||
if _, ok := carryOvers[fromNodeKey]; !ok {
|
||||
carryOvers[fromNodeKey] = make([]*compose.FieldMapping, 0)
|
||||
}
|
||||
|
||||
for _, fm := range fieldMappings {
|
||||
duplicate := false
|
||||
for _, existing := range carryOvers[fromNodeKey] {
|
||||
if fm.Equals(existing) {
|
||||
duplicate = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !duplicate {
|
||||
carryOvers[fromNodeKey] = append(carryOvers[fromNodeKey], fieldMappings...)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -866,29 +882,3 @@ func (w *Workflow) resolveDependenciesAsParent(n vo.NodeKey, sourceWithPaths []*
|
||||
variableInfos: variableInfos,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// addFieldMappingsWithDeduplication adds field mappings to carryOvers while avoiding duplicates
|
||||
func addFieldMappingsWithDeduplication(
|
||||
carryOvers map[vo.NodeKey][]*compose.FieldMapping,
|
||||
fromNodeKey vo.NodeKey,
|
||||
fieldMappings []*compose.FieldMapping,
|
||||
) {
|
||||
if _, ok := carryOvers[fromNodeKey]; !ok {
|
||||
carryOvers[fromNodeKey] = make([]*compose.FieldMapping, 0)
|
||||
}
|
||||
|
||||
for i := range fieldMappings {
|
||||
fm := fieldMappings[i]
|
||||
duplicate := false
|
||||
for _, existing := range carryOvers[fromNodeKey] {
|
||||
if fm.Equals(existing) {
|
||||
duplicate = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !duplicate {
|
||||
carryOvers[fromNodeKey] = append(carryOvers[fromNodeKey], fm)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,174 +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 compose
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cloudwego/eino/compose"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
|
||||
)
|
||||
|
||||
func TestAddFieldMappingsWithDeduplication(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
initialCarryOvers map[vo.NodeKey][]*compose.FieldMapping
|
||||
fromNodeKey vo.NodeKey
|
||||
fieldMappings []*compose.FieldMapping
|
||||
expectedCount int
|
||||
description string
|
||||
}{
|
||||
{
|
||||
name: "empty_carry_overs",
|
||||
initialCarryOvers: make(map[vo.NodeKey][]*compose.FieldMapping),
|
||||
fromNodeKey: "node1",
|
||||
fieldMappings: []*compose.FieldMapping{
|
||||
compose.MapFieldPaths(compose.FieldPath{"input1"}, compose.FieldPath{"output1"}),
|
||||
compose.MapFieldPaths(compose.FieldPath{"input2"}, compose.FieldPath{"output2"}),
|
||||
},
|
||||
expectedCount: 2,
|
||||
description: "should add all mappings when carryOvers is empty",
|
||||
},
|
||||
{
|
||||
name: "no_duplicates",
|
||||
initialCarryOvers: map[vo.NodeKey][]*compose.FieldMapping{
|
||||
"node1": {
|
||||
compose.MapFieldPaths(compose.FieldPath{"input1"}, compose.FieldPath{"output1"}),
|
||||
},
|
||||
},
|
||||
fromNodeKey: "node1",
|
||||
fieldMappings: []*compose.FieldMapping{
|
||||
compose.MapFieldPaths(compose.FieldPath{"input2"}, compose.FieldPath{"output2"}),
|
||||
compose.MapFieldPaths(compose.FieldPath{"input3"}, compose.FieldPath{"output3"}),
|
||||
},
|
||||
expectedCount: 3,
|
||||
description: "should add new mappings when no duplicates exist",
|
||||
},
|
||||
{
|
||||
name: "with_duplicates",
|
||||
initialCarryOvers: map[vo.NodeKey][]*compose.FieldMapping{
|
||||
"node1": {
|
||||
compose.MapFieldPaths(compose.FieldPath{"input1"}, compose.FieldPath{"output1"}),
|
||||
compose.MapFieldPaths(compose.FieldPath{"input2"}, compose.FieldPath{"output2"}),
|
||||
},
|
||||
},
|
||||
fromNodeKey: "node1",
|
||||
fieldMappings: []*compose.FieldMapping{
|
||||
compose.MapFieldPaths(compose.FieldPath{"input1"}, compose.FieldPath{"output1"}), // duplicate
|
||||
compose.MapFieldPaths(compose.FieldPath{"input3"}, compose.FieldPath{"output3"}), // new
|
||||
compose.MapFieldPaths(compose.FieldPath{"input2"}, compose.FieldPath{"output2"}), // duplicate
|
||||
},
|
||||
expectedCount: 3,
|
||||
description: "should skip duplicates and only add new mappings",
|
||||
},
|
||||
{
|
||||
name: "all_duplicates",
|
||||
initialCarryOvers: map[vo.NodeKey][]*compose.FieldMapping{
|
||||
"node1": {
|
||||
compose.MapFieldPaths(compose.FieldPath{"input1"}, compose.FieldPath{"output1"}),
|
||||
compose.MapFieldPaths(compose.FieldPath{"input2"}, compose.FieldPath{"output2"}),
|
||||
},
|
||||
},
|
||||
fromNodeKey: "node1",
|
||||
fieldMappings: []*compose.FieldMapping{
|
||||
compose.MapFieldPaths(compose.FieldPath{"input1"}, compose.FieldPath{"output1"}),
|
||||
compose.MapFieldPaths(compose.FieldPath{"input2"}, compose.FieldPath{"output2"}),
|
||||
},
|
||||
expectedCount: 2,
|
||||
description: "should not add any mappings when all are duplicates",
|
||||
},
|
||||
{
|
||||
name: "new_node_key",
|
||||
initialCarryOvers: map[vo.NodeKey][]*compose.FieldMapping{
|
||||
"node1": {
|
||||
compose.MapFieldPaths(compose.FieldPath{"input1"}, compose.FieldPath{"output1"}),
|
||||
},
|
||||
},
|
||||
fromNodeKey: "node2",
|
||||
fieldMappings: []*compose.FieldMapping{
|
||||
compose.MapFieldPaths(compose.FieldPath{"input1"}, compose.FieldPath{"output1"}),
|
||||
compose.MapFieldPaths(compose.FieldPath{"input2"}, compose.FieldPath{"output2"}),
|
||||
},
|
||||
expectedCount: 2,
|
||||
description: "should add all mappings for new node key",
|
||||
},
|
||||
{
|
||||
name: "empty_field_mappings",
|
||||
initialCarryOvers: map[vo.NodeKey][]*compose.FieldMapping{
|
||||
"node1": {
|
||||
compose.MapFieldPaths(compose.FieldPath{"input1"}, compose.FieldPath{"output1"}),
|
||||
},
|
||||
},
|
||||
fromNodeKey: "node1",
|
||||
fieldMappings: []*compose.FieldMapping{},
|
||||
expectedCount: 1,
|
||||
description: "should not change carryOvers when fieldMappings is empty",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Make a copy of initial carryOvers to avoid modifying the test data
|
||||
carryOvers := make(map[vo.NodeKey][]*compose.FieldMapping)
|
||||
for k, v := range tt.initialCarryOvers {
|
||||
carryOvers[k] = make([]*compose.FieldMapping, len(v))
|
||||
copy(carryOvers[k], v)
|
||||
}
|
||||
|
||||
// Call the function under test
|
||||
addFieldMappingsWithDeduplication(carryOvers, tt.fromNodeKey, tt.fieldMappings)
|
||||
|
||||
// Verify the result
|
||||
actualCount := len(carryOvers[tt.fromNodeKey])
|
||||
assert.Equal(t, tt.expectedCount, actualCount, tt.description)
|
||||
|
||||
// Verify no duplicates exist in the result
|
||||
mappings := carryOvers[tt.fromNodeKey]
|
||||
for i := 0; i < len(mappings); i++ {
|
||||
for j := i + 1; j < len(mappings); j++ {
|
||||
assert.False(t, mappings[i].Equals(mappings[j]),
|
||||
"found duplicate mappings at indices %d and %d", i, j)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddFieldMappingsWithDeduplication_NilSafety(t *testing.T) {
|
||||
t.Run("nil_field_mappings", func(t *testing.T) {
|
||||
carryOvers := make(map[vo.NodeKey][]*compose.FieldMapping)
|
||||
fromNodeKey := vo.NodeKey("node1")
|
||||
|
||||
// Should not panic with nil fieldMappings
|
||||
assert.NotPanics(t, func() {
|
||||
addFieldMappingsWithDeduplication(carryOvers, fromNodeKey, nil)
|
||||
})
|
||||
|
||||
// Should initialize empty slice for the node
|
||||
assert.NotNil(t, carryOvers[fromNodeKey])
|
||||
assert.Equal(t, 0, len(carryOvers[fromNodeKey]))
|
||||
})
|
||||
|
||||
t.Run("nil_carry_overs", func(t *testing.T) {
|
||||
// Should panic with nil carryOvers - this is expected behavior
|
||||
assert.Panics(t, func() {
|
||||
addFieldMappingsWithDeduplication(nil, "node1", []*compose.FieldMapping{})
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -20,6 +20,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -166,10 +167,24 @@ func convert(ctx context.Context, in any, path string, t *vo.TypeInfo, options *
|
||||
if in == nil { // nil is valid for ALL types
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
switch t.Type {
|
||||
case vo.DataTypeString, vo.DataTypeFile, vo.DataTypeTime:
|
||||
case vo.DataTypeString, vo.DataTypeTime:
|
||||
return convertToString(ctx, in, path, options)
|
||||
case vo.DataTypeFile:
|
||||
ret, warns, err := convertToString(ctx, in, path, options)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if warns != nil {
|
||||
return ret, warns, nil
|
||||
}
|
||||
|
||||
fileURL, err := adaptorFileURL(ret.(string))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return fileURL, nil, nil
|
||||
|
||||
case vo.DataTypeInteger:
|
||||
return convertToInt64(ctx, in, path, options)
|
||||
case vo.DataTypeNumber:
|
||||
@ -215,7 +230,16 @@ func convertToString(_ context.Context, in any, path string, options *convertOpt
|
||||
return nil, newWarnings(path, vo.DataTypeString, fmt.Errorf("unsupported type to convert to string: %T", in)), nil
|
||||
}
|
||||
}
|
||||
|
||||
func adaptorFileURL(in string) (string, error) {
|
||||
u, err := url.Parse(in)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
query := u.Query()
|
||||
query.Del("x-wf-file_name")
|
||||
u.RawQuery = query.Encode()
|
||||
return u.String(), nil
|
||||
}
|
||||
func convertToInt64(_ context.Context, in any, path string, options *convertOptions) (any, *ConversionWarnings, error) {
|
||||
switch in.(type) {
|
||||
case int64:
|
||||
|
||||
@ -20,6 +20,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@ -28,12 +29,15 @@ import (
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/knowledge"
|
||||
crossknowledge "github.com/coze-dev/coze-studio/backend/crossdomain/contract/knowledge"
|
||||
crossupload "github.com/coze-dev/coze-studio/backend/crossdomain/contract/upload"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/upload/service"
|
||||
"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/domain/workflow/internal/canvas/convert"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/nodes"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/schema"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/document/parser"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/logs"
|
||||
)
|
||||
|
||||
type IndexerConfig struct {
|
||||
@ -125,7 +129,7 @@ func (k *Indexer) Invoke(ctx context.Context, input map[string]any) (map[string]
|
||||
return nil, errors.New("knowledge is required")
|
||||
}
|
||||
|
||||
fileName, ext, err := parseToFileNameAndFileExtension(fileURL)
|
||||
fileName, ext, err := parseToFileNameAndFileExtension(ctx, fileURL)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -153,23 +157,52 @@ func (k *Indexer) Invoke(ctx context.Context, input map[string]any) (map[string]
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func parseToFileNameAndFileExtension(fileURL string) (string, parser.FileExtension, error) {
|
||||
|
||||
func parseToFileNameAndFileExtension(ctx context.Context, fileURL string) (string, parser.FileExtension, error) {
|
||||
u, err := url.Parse(fileURL)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
uris := make([]string, 0)
|
||||
ap := false
|
||||
for _, path := range strings.Split(u.Path, "/") {
|
||||
if path == "tos-cn-i-v4nquku3lp" {
|
||||
ap = true
|
||||
}
|
||||
if ap {
|
||||
uris = append(uris, path)
|
||||
}
|
||||
}
|
||||
fileURI := strings.Join(uris, "/")
|
||||
response, err := crossupload.DefaultSVC().GetFileTagging(context.Background(), &service.GetFileTaggingRequest{
|
||||
FileURI: fileURI,
|
||||
})
|
||||
|
||||
fileName := u.Query().Get("x-wf-file_name")
|
||||
if len(fileName) == 0 {
|
||||
return "", "", errors.New("file name is required")
|
||||
if err != nil {
|
||||
logs.CtxWarnf(ctx, "GetFileTagging failed for uri %s", fileURI)
|
||||
fileExt := strings.ToLower(strings.TrimPrefix(filepath.Ext(fileURI), "."))
|
||||
ext, support := parser.ValidateFileExtension(fileExt)
|
||||
if !support {
|
||||
return "", "", fmt.Errorf("unsupported file type: %s", fileExt)
|
||||
}
|
||||
return fileURI, ext, nil
|
||||
}
|
||||
|
||||
fileExt := strings.ToLower(strings.TrimPrefix(filepath.Ext(fileName), "."))
|
||||
filename, ok := response.Tagging["filename"]
|
||||
if !ok {
|
||||
return "", "", fmt.Errorf("failed to get file tagging filename")
|
||||
}
|
||||
|
||||
ext, support := parser.ValidateFileExtension(fileExt)
|
||||
fileExt, ok := response.Tagging["file_ext"]
|
||||
if !ok {
|
||||
logs.CtxWarnf(ctx, "failed to get file tagging file ext")
|
||||
fileExt = strings.TrimPrefix(filepath.Ext(fileURI), ".")
|
||||
}
|
||||
if len(fileExt) == 0 {
|
||||
fileExt = strings.TrimPrefix(filepath.Ext(fileURI), ".")
|
||||
}
|
||||
ext, support := parser.ValidateFileExtension(strings.TrimPrefix(fileExt, "."))
|
||||
if !support {
|
||||
return "", "", fmt.Errorf("unsupported file type: %s", fileExt)
|
||||
}
|
||||
return fileName, ext, nil
|
||||
return filename, ext, nil
|
||||
}
|
||||
|
||||
@ -79,8 +79,8 @@ require (
|
||||
gorm.io/driver/mysql v1.5.7
|
||||
gorm.io/driver/sqlite v1.4.3
|
||||
gorm.io/gen v0.3.26
|
||||
gorm.io/gorm v1.25.11
|
||||
gorm.io/plugin/dbresolver v1.5.2
|
||||
gorm.io/gorm v1.30.0
|
||||
gorm.io/plugin/dbresolver v1.6.0
|
||||
)
|
||||
|
||||
require (
|
||||
@ -289,6 +289,5 @@ require (
|
||||
github.com/bahlo/generic-list-go v0.2.0 // indirect
|
||||
github.com/buger/jsonparser v1.1.1 // indirect
|
||||
github.com/eino-contrib/jsonschema v1.0.0 // indirect
|
||||
github.com/stretchr/objx v0.5.2 // indirect
|
||||
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
|
||||
)
|
||||
|
||||
@ -1674,7 +1674,6 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gorm.io/datatypes v1.1.1-0.20230130040222-c43177d3cf8c h1:jWdr7cHgl8c/ua5vYbR2WhSp+NQmzhsj0xoY3foTzW8=
|
||||
gorm.io/datatypes v1.1.1-0.20230130040222-c43177d3cf8c/go.mod h1:SH2K9R+2RMjuX1CkCONrPwoe9JzVv2hkQvEu4bXGojE=
|
||||
gorm.io/driver/mysql v1.5.6/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM=
|
||||
gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo=
|
||||
gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM=
|
||||
gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314=
|
||||
@ -1690,12 +1689,12 @@ gorm.io/gorm v1.21.15/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=
|
||||
gorm.io/gorm v1.22.2/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=
|
||||
gorm.io/gorm v1.24.0/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA=
|
||||
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
|
||||
gorm.io/gorm v1.25.11 h1:/Wfyg1B/je1hnDx3sMkX+gAlxrlZpn6X0BXRlwXlvHg=
|
||||
gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
|
||||
gorm.io/gorm v1.30.0 h1:qbT5aPv1UH8gI99OsRlvDToLxW5zR7FzS9acZDOZcgs=
|
||||
gorm.io/gorm v1.30.0/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE=
|
||||
gorm.io/hints v1.1.0 h1:Lp4z3rxREufSdxn4qmkK3TLDltrM10FLTHiuqwDPvXw=
|
||||
gorm.io/hints v1.1.0/go.mod h1:lKQ0JjySsPBj3uslFzY3JhYDtqEwzm+G1hv8rWujB6Y=
|
||||
gorm.io/plugin/dbresolver v1.5.2 h1:Iut7lW4TXNoVs++I+ra3zxjSxTRj4ocIeFEVp4lLhII=
|
||||
gorm.io/plugin/dbresolver v1.5.2/go.mod h1:jPh59GOQbO7v7v28ZKZPd45tr+u3vyT+8tHdfdfOWcU=
|
||||
gorm.io/plugin/dbresolver v1.6.0 h1:XvKDeOtTn1EIX6s4SrKpEH82q0gXVemhYjbYZFGFVcw=
|
||||
gorm.io/plugin/dbresolver v1.6.0/go.mod h1:tctw63jdrOezFR9HmrKnPkmig3m5Edem9fdxk9bQSzM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
|
||||
@ -30,6 +30,10 @@ type Storage interface {
|
||||
PutObjectWithReader(ctx context.Context, objectKey string, content io.Reader, opts ...PutOptFn) error
|
||||
// GetObject returns the object with the specified key.
|
||||
GetObject(ctx context.Context, objectKey string) ([]byte, error)
|
||||
// GetObjectTagging returns object tagging
|
||||
GetObjectTagging(ctx context.Context, objectKey string) (map[string]string, error)
|
||||
// PutObjectTagging update the tag of the object in full
|
||||
PutObjectTagging(ctx context.Context, objectKey string, ts map[string]string) error
|
||||
// DeleteObject deletes the object with the specified key.
|
||||
DeleteObject(ctx context.Context, objectKey string) error
|
||||
// GetObjectUrl returns a presigned URL for the object.
|
||||
|
||||
@ -21,12 +21,12 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/parsex"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/elastic/go-elasticsearch/v7"
|
||||
"github.com/elastic/go-elasticsearch/v7/esapi"
|
||||
"github.com/elastic/go-elasticsearch/v7/esutil"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/es"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/conv"
|
||||
@ -39,14 +39,12 @@ type es7Client struct {
|
||||
}
|
||||
|
||||
func newES7() (Client, error) {
|
||||
addresses, err := parsex.ParseClusterEndpoints(os.Getenv("ES_ADDR"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
esAddr := os.Getenv("ES_ADDR")
|
||||
esUsername := os.Getenv("ES_USERNAME")
|
||||
esPassword := os.Getenv("ES_PASSWORD")
|
||||
|
||||
esClient, err := elasticsearch.NewClient(elasticsearch.Config{
|
||||
Addresses: addresses,
|
||||
Addresses: []string{esAddr},
|
||||
Username: esUsername,
|
||||
Password: esPassword,
|
||||
})
|
||||
@ -122,10 +120,6 @@ func (c *es7Client) CreateIndex(ctx context.Context, index string, properties ma
|
||||
"mappings": map[string]any{
|
||||
"properties": properties,
|
||||
},
|
||||
"settings": map[string]any{
|
||||
"number_of_shards": parsex.GetEnvDefaultIntSetting("ES_NUMBER_OF_SHARDS", "1"),
|
||||
"number_of_replicas": parsex.GetEnvDefaultIntSetting("ES_NUMBER_OF_REPLICAS", "1"),
|
||||
},
|
||||
}
|
||||
|
||||
body, err := json.Marshal(mapping)
|
||||
|
||||
@ -19,7 +19,8 @@ package es
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/parsex"
|
||||
"os"
|
||||
|
||||
"github.com/elastic/go-elasticsearch/v8"
|
||||
"github.com/elastic/go-elasticsearch/v8/esutil"
|
||||
"github.com/elastic/go-elasticsearch/v8/typedapi/core/search"
|
||||
@ -30,7 +31,6 @@ import (
|
||||
"github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/operator"
|
||||
"github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/sortorder"
|
||||
"github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/textquerytype"
|
||||
"os"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/es"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/conv"
|
||||
@ -51,14 +51,11 @@ type es8BulkIndexer struct {
|
||||
type es8Types struct{}
|
||||
|
||||
func newES8() (Client, error) {
|
||||
addresses, err := parsex.ParseClusterEndpoints(os.Getenv("ES_ADDR"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
esAddr := os.Getenv("ES_ADDR")
|
||||
esUsername := os.Getenv("ES_USERNAME")
|
||||
esPassword := os.Getenv("ES_PASSWORD")
|
||||
esClient, err := elasticsearch.NewTypedClient(elasticsearch.Config{
|
||||
Addresses: addresses,
|
||||
Addresses: []string{esAddr},
|
||||
Username: esUsername,
|
||||
Password: esPassword,
|
||||
})
|
||||
@ -242,10 +239,6 @@ func (c *es8Client) CreateIndex(ctx context.Context, index string, properties ma
|
||||
Mappings: &types.TypeMapping{
|
||||
Properties: propertiesMap,
|
||||
},
|
||||
Settings: &types.IndexSettings{
|
||||
NumberOfShards: parsex.GetEnvDefaultIntSetting("ES_NUMBER_OF_SHARDS", "1"),
|
||||
NumberOfReplicas: parsex.GetEnvDefaultIntSetting("ES_NUMBER_OF_REPLICAS", "1"),
|
||||
},
|
||||
}).Do(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -18,8 +18,9 @@ package es
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/es"
|
||||
"os"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/es"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@ -937,9 +937,9 @@ func (m *mysqlService) buildWhereClause(condition *rdb.ComplexCondition) (string
|
||||
return m.buildNestedConditions(condition)
|
||||
} else if len(condition.Conditions) > 0 {
|
||||
whereClauseString, values, err := m.buildWhereCondition(condition)
|
||||
return " WHERE " + whereClauseString, values, err
|
||||
return "WHERE " + whereClauseString, values, err
|
||||
} else {
|
||||
return "", nil, fmt.Errorf("empty condition: no nested or direct conditions found")
|
||||
return "", nil, fmt.Errorf("condddd")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -19,7 +19,9 @@ package minio
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
|
||||
"io"
|
||||
"math/rand"
|
||||
"net/url"
|
||||
@ -27,6 +29,7 @@ import (
|
||||
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"github.com/minio/minio-go/v7/pkg/tags"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/storage"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/impl/storage/internal/fileutil"
|
||||
@ -183,8 +186,12 @@ func (m *minioClient) PutObjectWithReader(ctx context.Context, objectKey string,
|
||||
minioOpts.Expires = *option.Expires
|
||||
}
|
||||
|
||||
tagging := make(map[string]string, len(option.Tagging))
|
||||
for k, v := range option.Tagging {
|
||||
tagging[k] = base64.StdEncoding.EncodeToString([]byte(v))
|
||||
}
|
||||
if option.Tagging != nil {
|
||||
minioOpts.UserTags = option.Tagging
|
||||
minioOpts.UserTags = tagging
|
||||
}
|
||||
|
||||
_, err := m.client.PutObject(ctx, m.bucketName, objectKey,
|
||||
@ -293,12 +300,20 @@ func (m *minioClient) ListAllObjects(ctx context.Context, prefix string, opts ..
|
||||
return nil, object.Err
|
||||
}
|
||||
|
||||
tagging := make(map[string]string, len(object.UserTags))
|
||||
for k, v := range object.UserTags {
|
||||
valBs, err := base64.StdEncoding.DecodeString(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tagging[k] = string(valBs)
|
||||
}
|
||||
files = append(files, &storage.FileInfo{
|
||||
Key: object.Key,
|
||||
LastModified: object.LastModified,
|
||||
ETag: object.ETag,
|
||||
Size: object.Size,
|
||||
Tagging: object.UserTags,
|
||||
Tagging: tagging,
|
||||
})
|
||||
|
||||
logs.CtxDebugf(ctx, "key = %s, lastModified = %s, eTag = %s, size = %d, tagging = %v",
|
||||
@ -331,12 +346,11 @@ func (m *minioClient) HeadObject(ctx context.Context, objectKey string, opts ...
|
||||
}
|
||||
|
||||
if option.WithTagging {
|
||||
tags, err := m.client.GetObjectTagging(ctx, m.bucketName, objectKey, minio.GetObjectTaggingOptions{})
|
||||
objTags, err := m.GetObjectTagging(ctx, objectKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
f.Tagging = tags.ToMap()
|
||||
f.Tagging = objTags
|
||||
}
|
||||
|
||||
if option.WithURL {
|
||||
@ -348,3 +362,33 @@ func (m *minioClient) HeadObject(ctx context.Context, objectKey string, opts ...
|
||||
|
||||
return f, nil
|
||||
}
|
||||
|
||||
func (m *minioClient) GetObjectTagging(ctx context.Context, objectKey string) (map[string]string, error) {
|
||||
response, err := m.client.GetObjectTagging(ctx, m.bucketName, objectKey, minio.GetObjectTaggingOptions{})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("GetObjectTagging failed: %v", err)
|
||||
}
|
||||
rst := make(map[string]string)
|
||||
for k, v := range response.ToMap() {
|
||||
valBs, err := base64.StdEncoding.DecodeString(v)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("QueryUnescape failed: %v", err)
|
||||
}
|
||||
rst[k] = string(valBs)
|
||||
}
|
||||
|
||||
return rst, nil
|
||||
}
|
||||
func (m *minioClient) PutObjectTagging(ctx context.Context, objectKey string, ts map[string]string) error {
|
||||
saveTags := make(map[string]string)
|
||||
for k, v := range ts {
|
||||
saveTags[k] = base64.StdEncoding.EncodeToString([]byte(v))
|
||||
}
|
||||
t, err := tags.NewTags(saveTags, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return m.client.PutObjectTagging(ctx, m.bucketName, objectKey, t, minio.PutObjectTaggingOptions{})
|
||||
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"io"
|
||||
"time"
|
||||
|
||||
@ -29,6 +30,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go-v2/credentials"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3/types"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/slices"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/storage"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/impl/storage/internal/fileutil"
|
||||
@ -151,7 +153,6 @@ func (t *s3Client) PutObject(ctx context.Context, objectKey string, content []by
|
||||
func (t *s3Client) PutObjectWithReader(ctx context.Context, objectKey string, content io.Reader, opts ...storage.PutOptFn) error {
|
||||
client := t.client
|
||||
bucket := t.bucketName
|
||||
|
||||
option := storage.PutOption{}
|
||||
for _, opt := range opts {
|
||||
opt(&option)
|
||||
@ -440,3 +441,38 @@ func tagsToMap(tags []types.Tag) map[string]string {
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func (t *s3Client) GetObjectTagging(ctx context.Context, objectKey string) (map[string]string, error) {
|
||||
response, err := t.client.GetObjectTagging(ctx, &s3.GetObjectTaggingInput{
|
||||
Bucket: aws.String(t.bucketName),
|
||||
Key: aws.String(objectKey),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return slices.ToMap(response.TagSet, func(e types.Tag) (string, string) {
|
||||
return *e.Key, *e.Value
|
||||
}), err
|
||||
}
|
||||
|
||||
func (t *s3Client) PutObjectTagging(ctx context.Context, objectKey string, ts map[string]string) error {
|
||||
tags := make([]types.Tag, 0, len(ts))
|
||||
for k, v := range ts {
|
||||
tags = append(tags, types.Tag{
|
||||
Key: aws.String(k),
|
||||
Value: aws.String(v),
|
||||
})
|
||||
}
|
||||
_, err := t.client.PutObjectTagging(ctx, &s3.PutObjectTaggingInput{
|
||||
Bucket: aws.String(t.bucketName),
|
||||
Key: aws.String(objectKey),
|
||||
Tagging: &types.Tagging{
|
||||
TagSet: tags,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
@ -25,6 +25,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/slices"
|
||||
"github.com/volcengine/ve-tos-golang-sdk/v2/tos"
|
||||
"github.com/volcengine/ve-tos-golang-sdk/v2/tos/enum"
|
||||
|
||||
@ -441,3 +442,36 @@ func tagsToMap(tags []tos.Tag) map[string]string {
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (t *tosClient) GetObjectTagging(ctx context.Context, objectKey string) (map[string]string, error) {
|
||||
response, err := t.client.GetObjectTagging(ctx, &tos.GetObjectTaggingInput{
|
||||
Bucket: t.bucketName,
|
||||
Key: objectKey,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return slices.ToMap(response.TagSet.Tags, func(e tos.Tag) (string, string) {
|
||||
return e.Key, e.Value
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (t *tosClient) PutObjectTagging(ctx context.Context, objectKey string, ts map[string]string) error {
|
||||
tags := make([]tos.Tag, 0, len(ts))
|
||||
for k, v := range ts {
|
||||
tags = append(tags, tos.Tag{Key: k, Value: v})
|
||||
}
|
||||
_, err := t.client.PutObjectTagging(ctx, &tos.PutObjectTaggingInput{
|
||||
Bucket: t.bucketName,
|
||||
Key: objectKey,
|
||||
TagSet: tos.TagSet{
|
||||
Tags: tags,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
@ -1,355 +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.
|
||||
*/
|
||||
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: domain/agent/singleagent/service/single_agent.go
|
||||
//
|
||||
// Generated by this command:
|
||||
//
|
||||
// mockgen -destination internal/mock/domain/agent/singleagent/single_agent_mock.go --package mock -source domain/agent/singleagent/service/single_agent.go
|
||||
//
|
||||
|
||||
// Package mock is a generated GoMock package.
|
||||
package mock
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
schema "github.com/cloudwego/eino/schema"
|
||||
playground "github.com/coze-dev/coze-studio/backend/api/model/playground"
|
||||
entity "github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/entity"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
// MockSingleAgent is a mock of SingleAgent interface.
|
||||
type MockSingleAgent struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockSingleAgentMockRecorder
|
||||
isgomock struct{}
|
||||
}
|
||||
|
||||
// MockSingleAgentMockRecorder is the mock recorder for MockSingleAgent.
|
||||
type MockSingleAgentMockRecorder struct {
|
||||
mock *MockSingleAgent
|
||||
}
|
||||
|
||||
// NewMockSingleAgent creates a new mock instance.
|
||||
func NewMockSingleAgent(ctrl *gomock.Controller) *MockSingleAgent {
|
||||
mock := &MockSingleAgent{ctrl: ctrl}
|
||||
mock.recorder = &MockSingleAgentMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockSingleAgent) EXPECT() *MockSingleAgentMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// CreateSingleAgent mocks base method.
|
||||
func (m *MockSingleAgent) CreateSingleAgent(ctx context.Context, connectorID int64, version string, e *entity.SingleAgent) (int64, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "CreateSingleAgent", ctx, connectorID, version, e)
|
||||
ret0, _ := ret[0].(int64)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// CreateSingleAgent indicates an expected call of CreateSingleAgent.
|
||||
func (mr *MockSingleAgentMockRecorder) CreateSingleAgent(ctx, connectorID, version, e any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateSingleAgent", reflect.TypeOf((*MockSingleAgent)(nil).CreateSingleAgent), ctx, connectorID, version, e)
|
||||
}
|
||||
|
||||
// CreateSingleAgentDraft mocks base method.
|
||||
func (m *MockSingleAgent) CreateSingleAgentDraft(ctx context.Context, creatorID int64, draft *entity.SingleAgent) (int64, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "CreateSingleAgentDraft", ctx, creatorID, draft)
|
||||
ret0, _ := ret[0].(int64)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// CreateSingleAgentDraft indicates an expected call of CreateSingleAgentDraft.
|
||||
func (mr *MockSingleAgentMockRecorder) CreateSingleAgentDraft(ctx, creatorID, draft any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateSingleAgentDraft", reflect.TypeOf((*MockSingleAgent)(nil).CreateSingleAgentDraft), ctx, creatorID, draft)
|
||||
}
|
||||
|
||||
// CreateSingleAgentDraftWithID mocks base method.
|
||||
func (m *MockSingleAgent) CreateSingleAgentDraftWithID(ctx context.Context, creatorID, agentID int64, draft *entity.SingleAgent) (int64, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "CreateSingleAgentDraftWithID", ctx, creatorID, agentID, draft)
|
||||
ret0, _ := ret[0].(int64)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// CreateSingleAgentDraftWithID indicates an expected call of CreateSingleAgentDraftWithID.
|
||||
func (mr *MockSingleAgentMockRecorder) CreateSingleAgentDraftWithID(ctx, creatorID, agentID, draft any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateSingleAgentDraftWithID", reflect.TypeOf((*MockSingleAgent)(nil).CreateSingleAgentDraftWithID), ctx, creatorID, agentID, draft)
|
||||
}
|
||||
|
||||
// DeleteAgentDraft mocks base method.
|
||||
func (m *MockSingleAgent) DeleteAgentDraft(ctx context.Context, spaceID, agentID int64) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "DeleteAgentDraft", ctx, spaceID, agentID)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// DeleteAgentDraft indicates an expected call of DeleteAgentDraft.
|
||||
func (mr *MockSingleAgentMockRecorder) DeleteAgentDraft(ctx, spaceID, agentID any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteAgentDraft", reflect.TypeOf((*MockSingleAgent)(nil).DeleteAgentDraft), ctx, spaceID, agentID)
|
||||
}
|
||||
|
||||
// DuplicateInMemory mocks base method.
|
||||
func (m *MockSingleAgent) DuplicateInMemory(ctx context.Context, req *entity.DuplicateInfo) (*entity.SingleAgent, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "DuplicateInMemory", ctx, req)
|
||||
ret0, _ := ret[0].(*entity.SingleAgent)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// DuplicateInMemory indicates an expected call of DuplicateInMemory.
|
||||
func (mr *MockSingleAgentMockRecorder) DuplicateInMemory(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DuplicateInMemory", reflect.TypeOf((*MockSingleAgent)(nil).DuplicateInMemory), ctx, req)
|
||||
}
|
||||
|
||||
// GetAgentDraftDisplayInfo mocks base method.
|
||||
func (m *MockSingleAgent) GetAgentDraftDisplayInfo(ctx context.Context, userID, agentID int64) (*entity.AgentDraftDisplayInfo, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetAgentDraftDisplayInfo", ctx, userID, agentID)
|
||||
ret0, _ := ret[0].(*entity.AgentDraftDisplayInfo)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetAgentDraftDisplayInfo indicates an expected call of GetAgentDraftDisplayInfo.
|
||||
func (mr *MockSingleAgentMockRecorder) GetAgentDraftDisplayInfo(ctx, userID, agentID any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAgentDraftDisplayInfo", reflect.TypeOf((*MockSingleAgent)(nil).GetAgentDraftDisplayInfo), ctx, userID, agentID)
|
||||
}
|
||||
|
||||
// GetAgentPopupCount mocks base method.
|
||||
func (m *MockSingleAgent) GetAgentPopupCount(ctx context.Context, uid, agentID int64, agentPopupType playground.BotPopupType) (int64, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetAgentPopupCount", ctx, uid, agentID, agentPopupType)
|
||||
ret0, _ := ret[0].(int64)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetAgentPopupCount indicates an expected call of GetAgentPopupCount.
|
||||
func (mr *MockSingleAgentMockRecorder) GetAgentPopupCount(ctx, uid, agentID, agentPopupType any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAgentPopupCount", reflect.TypeOf((*MockSingleAgent)(nil).GetAgentPopupCount), ctx, uid, agentID, agentPopupType)
|
||||
}
|
||||
|
||||
// GetPublishConnectorList mocks base method.
|
||||
func (m *MockSingleAgent) GetPublishConnectorList(ctx context.Context, agentID int64) (*entity.PublishConnectorData, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetPublishConnectorList", ctx, agentID)
|
||||
ret0, _ := ret[0].(*entity.PublishConnectorData)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetPublishConnectorList indicates an expected call of GetPublishConnectorList.
|
||||
func (mr *MockSingleAgentMockRecorder) GetPublishConnectorList(ctx, agentID any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPublishConnectorList", reflect.TypeOf((*MockSingleAgent)(nil).GetPublishConnectorList), ctx, agentID)
|
||||
}
|
||||
|
||||
// GetPublishedInfo mocks base method.
|
||||
func (m *MockSingleAgent) GetPublishedInfo(ctx context.Context, agentID int64) (*entity.PublishInfo, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetPublishedInfo", ctx, agentID)
|
||||
ret0, _ := ret[0].(*entity.PublishInfo)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetPublishedInfo indicates an expected call of GetPublishedInfo.
|
||||
func (mr *MockSingleAgentMockRecorder) GetPublishedInfo(ctx, agentID any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPublishedInfo", reflect.TypeOf((*MockSingleAgent)(nil).GetPublishedInfo), ctx, agentID)
|
||||
}
|
||||
|
||||
// GetPublishedTime mocks base method.
|
||||
func (m *MockSingleAgent) GetPublishedTime(ctx context.Context, agentID int64) (int64, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetPublishedTime", ctx, agentID)
|
||||
ret0, _ := ret[0].(int64)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetPublishedTime indicates an expected call of GetPublishedTime.
|
||||
func (mr *MockSingleAgentMockRecorder) GetPublishedTime(ctx, agentID any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPublishedTime", reflect.TypeOf((*MockSingleAgent)(nil).GetPublishedTime), ctx, agentID)
|
||||
}
|
||||
|
||||
// GetSingleAgent mocks base method.
|
||||
func (m *MockSingleAgent) GetSingleAgent(ctx context.Context, agentID int64, version string) (*entity.SingleAgent, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetSingleAgent", ctx, agentID, version)
|
||||
ret0, _ := ret[0].(*entity.SingleAgent)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetSingleAgent indicates an expected call of GetSingleAgent.
|
||||
func (mr *MockSingleAgentMockRecorder) GetSingleAgent(ctx, agentID, version any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSingleAgent", reflect.TypeOf((*MockSingleAgent)(nil).GetSingleAgent), ctx, agentID, version)
|
||||
}
|
||||
|
||||
// GetSingleAgentDraft mocks base method.
|
||||
func (m *MockSingleAgent) GetSingleAgentDraft(ctx context.Context, agentID int64) (*entity.SingleAgent, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetSingleAgentDraft", ctx, agentID)
|
||||
ret0, _ := ret[0].(*entity.SingleAgent)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetSingleAgentDraft indicates an expected call of GetSingleAgentDraft.
|
||||
func (mr *MockSingleAgentMockRecorder) GetSingleAgentDraft(ctx, agentID any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSingleAgentDraft", reflect.TypeOf((*MockSingleAgent)(nil).GetSingleAgentDraft), ctx, agentID)
|
||||
}
|
||||
|
||||
// IncrAgentPopupCount mocks base method.
|
||||
func (m *MockSingleAgent) IncrAgentPopupCount(ctx context.Context, uid, agentID int64, agentPopupType playground.BotPopupType) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "IncrAgentPopupCount", ctx, uid, agentID, agentPopupType)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// IncrAgentPopupCount indicates an expected call of IncrAgentPopupCount.
|
||||
func (mr *MockSingleAgentMockRecorder) IncrAgentPopupCount(ctx, uid, agentID, agentPopupType any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IncrAgentPopupCount", reflect.TypeOf((*MockSingleAgent)(nil).IncrAgentPopupCount), ctx, uid, agentID, agentPopupType)
|
||||
}
|
||||
|
||||
// ListAgentPublishHistory mocks base method.
|
||||
func (m *MockSingleAgent) ListAgentPublishHistory(ctx context.Context, agentID int64, pageIndex, pageSize int32, connectorID *int64) ([]*entity.SingleAgentPublish, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ListAgentPublishHistory", ctx, agentID, pageIndex, pageSize, connectorID)
|
||||
ret0, _ := ret[0].([]*entity.SingleAgentPublish)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// ListAgentPublishHistory indicates an expected call of ListAgentPublishHistory.
|
||||
func (mr *MockSingleAgentMockRecorder) ListAgentPublishHistory(ctx, agentID, pageIndex, pageSize, connectorID any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListAgentPublishHistory", reflect.TypeOf((*MockSingleAgent)(nil).ListAgentPublishHistory), ctx, agentID, pageIndex, pageSize, connectorID)
|
||||
}
|
||||
|
||||
// MGetSingleAgentDraft mocks base method.
|
||||
func (m *MockSingleAgent) MGetSingleAgentDraft(ctx context.Context, agentIDs []int64) ([]*entity.SingleAgent, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "MGetSingleAgentDraft", ctx, agentIDs)
|
||||
ret0, _ := ret[0].([]*entity.SingleAgent)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// MGetSingleAgentDraft indicates an expected call of MGetSingleAgentDraft.
|
||||
func (mr *MockSingleAgentMockRecorder) MGetSingleAgentDraft(ctx, agentIDs any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MGetSingleAgentDraft", reflect.TypeOf((*MockSingleAgent)(nil).MGetSingleAgentDraft), ctx, agentIDs)
|
||||
}
|
||||
|
||||
// ObtainAgentByIdentity mocks base method.
|
||||
func (m *MockSingleAgent) ObtainAgentByIdentity(ctx context.Context, identity *entity.AgentIdentity) (*entity.SingleAgent, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ObtainAgentByIdentity", ctx, identity)
|
||||
ret0, _ := ret[0].(*entity.SingleAgent)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// ObtainAgentByIdentity indicates an expected call of ObtainAgentByIdentity.
|
||||
func (mr *MockSingleAgentMockRecorder) ObtainAgentByIdentity(ctx, identity any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ObtainAgentByIdentity", reflect.TypeOf((*MockSingleAgent)(nil).ObtainAgentByIdentity), ctx, identity)
|
||||
}
|
||||
|
||||
// SavePublishRecord mocks base method.
|
||||
func (m *MockSingleAgent) SavePublishRecord(ctx context.Context, p *entity.SingleAgentPublish, e *entity.SingleAgent) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SavePublishRecord", ctx, p, e)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SavePublishRecord indicates an expected call of SavePublishRecord.
|
||||
func (mr *MockSingleAgentMockRecorder) SavePublishRecord(ctx, p, e any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SavePublishRecord", reflect.TypeOf((*MockSingleAgent)(nil).SavePublishRecord), ctx, p, e)
|
||||
}
|
||||
|
||||
// StreamExecute mocks base method.
|
||||
func (m *MockSingleAgent) StreamExecute(ctx context.Context, req *entity.ExecuteRequest) (*schema.StreamReader[*entity.AgentEvent], error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "StreamExecute", ctx, req)
|
||||
ret0, _ := ret[0].(*schema.StreamReader[*entity.AgentEvent])
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// StreamExecute indicates an expected call of StreamExecute.
|
||||
func (mr *MockSingleAgentMockRecorder) StreamExecute(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StreamExecute", reflect.TypeOf((*MockSingleAgent)(nil).StreamExecute), ctx, req)
|
||||
}
|
||||
|
||||
// UpdateAgentDraftDisplayInfo mocks base method.
|
||||
func (m *MockSingleAgent) UpdateAgentDraftDisplayInfo(ctx context.Context, userID int64, e *entity.AgentDraftDisplayInfo) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "UpdateAgentDraftDisplayInfo", ctx, userID, e)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// UpdateAgentDraftDisplayInfo indicates an expected call of UpdateAgentDraftDisplayInfo.
|
||||
func (mr *MockSingleAgentMockRecorder) UpdateAgentDraftDisplayInfo(ctx, userID, e any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateAgentDraftDisplayInfo", reflect.TypeOf((*MockSingleAgent)(nil).UpdateAgentDraftDisplayInfo), ctx, userID, e)
|
||||
}
|
||||
|
||||
// UpdateSingleAgentDraft mocks base method.
|
||||
func (m *MockSingleAgent) UpdateSingleAgentDraft(ctx context.Context, agentInfo *entity.SingleAgent) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "UpdateSingleAgentDraft", ctx, agentInfo)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// UpdateSingleAgentDraft indicates an expected call of UpdateSingleAgentDraft.
|
||||
func (mr *MockSingleAgentMockRecorder) UpdateSingleAgentDraft(ctx, agentInfo any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateSingleAgentDraft", reflect.TypeOf((*MockSingleAgent)(nil).UpdateSingleAgentDraft), ctx, agentInfo)
|
||||
}
|
||||
@ -1,148 +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.
|
||||
*/
|
||||
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: domain/conversation/agentrun/service/agent_run.go
|
||||
//
|
||||
// Generated by this command:
|
||||
//
|
||||
// mockgen -destination internal/mock/domain/conversation/agentrun/agent_run_mock.go --package mock_agentrun -source domain/conversation/agentrun/service/agent_run.go
|
||||
//
|
||||
|
||||
// Package mock_agentrun is a generated GoMock package.
|
||||
package mock_agentrun
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
schema "github.com/cloudwego/eino/schema"
|
||||
entity "github.com/coze-dev/coze-studio/backend/domain/conversation/agentrun/entity"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
// MockRun is a mock of Run interface.
|
||||
type MockRun struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockRunMockRecorder
|
||||
isgomock struct{}
|
||||
}
|
||||
|
||||
// MockRunMockRecorder is the mock recorder for MockRun.
|
||||
type MockRunMockRecorder struct {
|
||||
mock *MockRun
|
||||
}
|
||||
|
||||
// NewMockRun creates a new mock instance.
|
||||
func NewMockRun(ctrl *gomock.Controller) *MockRun {
|
||||
mock := &MockRun{ctrl: ctrl}
|
||||
mock.recorder = &MockRunMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockRun) EXPECT() *MockRunMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// AgentRun mocks base method.
|
||||
func (m *MockRun) AgentRun(ctx context.Context, req *entity.AgentRunMeta) (*schema.StreamReader[*entity.AgentRunResponse], error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "AgentRun", ctx, req)
|
||||
ret0, _ := ret[0].(*schema.StreamReader[*entity.AgentRunResponse])
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// AgentRun indicates an expected call of AgentRun.
|
||||
func (mr *MockRunMockRecorder) AgentRun(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AgentRun", reflect.TypeOf((*MockRun)(nil).AgentRun), ctx, req)
|
||||
}
|
||||
|
||||
// Cancel mocks base method.
|
||||
func (m *MockRun) Cancel(ctx context.Context, req *entity.CancelRunMeta) (*entity.RunRecordMeta, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Cancel", ctx, req)
|
||||
ret0, _ := ret[0].(*entity.RunRecordMeta)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// Cancel indicates an expected call of Cancel.
|
||||
func (mr *MockRunMockRecorder) Cancel(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Cancel", reflect.TypeOf((*MockRun)(nil).Cancel), ctx, req)
|
||||
}
|
||||
|
||||
// Create mocks base method.
|
||||
func (m *MockRun) Create(ctx context.Context, runRecord *entity.AgentRunMeta) (*entity.RunRecordMeta, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Create", ctx, runRecord)
|
||||
ret0, _ := ret[0].(*entity.RunRecordMeta)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// Create indicates an expected call of Create.
|
||||
func (mr *MockRunMockRecorder) Create(ctx, runRecord any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockRun)(nil).Create), ctx, runRecord)
|
||||
}
|
||||
|
||||
// Delete mocks base method.
|
||||
func (m *MockRun) Delete(ctx context.Context, runID []int64) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Delete", ctx, runID)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Delete indicates an expected call of Delete.
|
||||
func (mr *MockRunMockRecorder) Delete(ctx, runID any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockRun)(nil).Delete), ctx, runID)
|
||||
}
|
||||
|
||||
// GetByID mocks base method.
|
||||
func (m *MockRun) GetByID(ctx context.Context, runID int64) (*entity.RunRecordMeta, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetByID", ctx, runID)
|
||||
ret0, _ := ret[0].(*entity.RunRecordMeta)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetByID indicates an expected call of GetByID.
|
||||
func (mr *MockRunMockRecorder) GetByID(ctx, runID any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetByID", reflect.TypeOf((*MockRun)(nil).GetByID), ctx, runID)
|
||||
}
|
||||
|
||||
// List mocks base method.
|
||||
func (m *MockRun) List(ctx context.Context, ListMeta *entity.ListRunRecordMeta) ([]*entity.RunRecordMeta, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "List", ctx, ListMeta)
|
||||
ret0, _ := ret[0].([]*entity.RunRecordMeta)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// List indicates an expected call of List.
|
||||
func (mr *MockRunMockRecorder) List(ctx, ListMeta any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockRun)(nil).List), ctx, ListMeta)
|
||||
}
|
||||
@ -1,163 +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.
|
||||
*/
|
||||
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: domain/conversation/conversation/service/conversation.go
|
||||
//
|
||||
// Generated by this command:
|
||||
//
|
||||
// mockgen -destination internal/mock/domain/conversation/conversation/conversation_mock.go --package mock_conversation -source domain/conversation/conversation/service/conversation.go
|
||||
//
|
||||
|
||||
// Package mock_conversation is a generated GoMock package.
|
||||
package mock_conversation
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// Create mocks base method.
|
||||
func (m *MockConversation) Create(ctx context.Context, req *entity.CreateMeta) (*entity.Conversation, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Create", ctx, req)
|
||||
ret0, _ := ret[0].(*entity.Conversation)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// Create indicates an expected call of Create.
|
||||
func (mr *MockConversationMockRecorder) Create(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockConversation)(nil).Create), ctx, req)
|
||||
}
|
||||
|
||||
// Delete mocks base method.
|
||||
func (m *MockConversation) Delete(ctx context.Context, id int64) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Delete", ctx, id)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Delete indicates an expected call of Delete.
|
||||
func (mr *MockConversationMockRecorder) Delete(ctx, id any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockConversation)(nil).Delete), ctx, id)
|
||||
}
|
||||
|
||||
// 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 *entity.GetCurrent) (*entity.Conversation, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetCurrentConversation", ctx, req)
|
||||
ret0, _ := ret[0].(*entity.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)
|
||||
}
|
||||
|
||||
// List mocks base method.
|
||||
func (m *MockConversation) List(ctx context.Context, req *entity.ListMeta) ([]*entity.Conversation, bool, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "List", ctx, req)
|
||||
ret0, _ := ret[0].([]*entity.Conversation)
|
||||
ret1, _ := ret[1].(bool)
|
||||
ret2, _ := ret[2].(error)
|
||||
return ret0, ret1, ret2
|
||||
}
|
||||
|
||||
// List indicates an expected call of List.
|
||||
func (mr *MockConversationMockRecorder) List(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockConversation)(nil).List), ctx, req)
|
||||
}
|
||||
|
||||
// NewConversationCtx mocks base method.
|
||||
func (m *MockConversation) NewConversationCtx(ctx context.Context, req *entity.NewConversationCtxRequest) (*entity.NewConversationCtxResponse, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "NewConversationCtx", ctx, req)
|
||||
ret0, _ := ret[0].(*entity.NewConversationCtxResponse)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// NewConversationCtx indicates an expected call of NewConversationCtx.
|
||||
func (mr *MockConversationMockRecorder) NewConversationCtx(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewConversationCtx", reflect.TypeOf((*MockConversation)(nil).NewConversationCtx), ctx, req)
|
||||
}
|
||||
|
||||
// Update mocks base method.
|
||||
func (m *MockConversation) Update(ctx context.Context, req *entity.UpdateMeta) (*entity.Conversation, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Update", ctx, req)
|
||||
ret0, _ := ret[0].(*entity.Conversation)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// Update indicates an expected call of Update.
|
||||
func (mr *MockConversationMockRecorder) Update(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockConversation)(nil).Update), ctx, req)
|
||||
}
|
||||
@ -1,132 +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.
|
||||
*/
|
||||
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: domain/shortcutcmd/service/shortcut_cmd.go
|
||||
//
|
||||
// Generated by this command:
|
||||
//
|
||||
// mockgen -destination internal/mock/domain/shortcutcmd/shortcut_cmd_mock.go --package mock_shortcutcmd -source domain/shortcutcmd/service/shortcut_cmd.go
|
||||
//
|
||||
|
||||
// Package mock_shortcutcmd is a generated GoMock package.
|
||||
package mock_shortcutcmd
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
entity "github.com/coze-dev/coze-studio/backend/domain/shortcutcmd/entity"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
// MockShortcutCmd is a mock of ShortcutCmd interface.
|
||||
type MockShortcutCmd struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockShortcutCmdMockRecorder
|
||||
isgomock struct{}
|
||||
}
|
||||
|
||||
// MockShortcutCmdMockRecorder is the mock recorder for MockShortcutCmd.
|
||||
type MockShortcutCmdMockRecorder struct {
|
||||
mock *MockShortcutCmd
|
||||
}
|
||||
|
||||
// NewMockShortcutCmd creates a new mock instance.
|
||||
func NewMockShortcutCmd(ctrl *gomock.Controller) *MockShortcutCmd {
|
||||
mock := &MockShortcutCmd{ctrl: ctrl}
|
||||
mock.recorder = &MockShortcutCmdMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockShortcutCmd) EXPECT() *MockShortcutCmdMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// CreateCMD mocks base method.
|
||||
func (m *MockShortcutCmd) CreateCMD(ctx context.Context, shortcut *entity.ShortcutCmd) (*entity.ShortcutCmd, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "CreateCMD", ctx, shortcut)
|
||||
ret0, _ := ret[0].(*entity.ShortcutCmd)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// CreateCMD indicates an expected call of CreateCMD.
|
||||
func (mr *MockShortcutCmdMockRecorder) CreateCMD(ctx, shortcut any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateCMD", reflect.TypeOf((*MockShortcutCmd)(nil).CreateCMD), ctx, shortcut)
|
||||
}
|
||||
|
||||
// GetByCmdID mocks base method.
|
||||
func (m *MockShortcutCmd) GetByCmdID(ctx context.Context, cmdID int64, isOnline int32) (*entity.ShortcutCmd, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetByCmdID", ctx, cmdID, isOnline)
|
||||
ret0, _ := ret[0].(*entity.ShortcutCmd)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetByCmdID indicates an expected call of GetByCmdID.
|
||||
func (mr *MockShortcutCmdMockRecorder) GetByCmdID(ctx, cmdID, isOnline any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetByCmdID", reflect.TypeOf((*MockShortcutCmd)(nil).GetByCmdID), ctx, cmdID, isOnline)
|
||||
}
|
||||
|
||||
// ListCMD mocks base method.
|
||||
func (m *MockShortcutCmd) ListCMD(ctx context.Context, lm *entity.ListMeta) ([]*entity.ShortcutCmd, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ListCMD", ctx, lm)
|
||||
ret0, _ := ret[0].([]*entity.ShortcutCmd)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// ListCMD indicates an expected call of ListCMD.
|
||||
func (mr *MockShortcutCmdMockRecorder) ListCMD(ctx, lm any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListCMD", reflect.TypeOf((*MockShortcutCmd)(nil).ListCMD), ctx, lm)
|
||||
}
|
||||
|
||||
// PublishCMDs mocks base method.
|
||||
func (m *MockShortcutCmd) PublishCMDs(ctx context.Context, objID int64, cmdIDs []int64) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "PublishCMDs", ctx, objID, cmdIDs)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// PublishCMDs indicates an expected call of PublishCMDs.
|
||||
func (mr *MockShortcutCmdMockRecorder) PublishCMDs(ctx, objID, cmdIDs any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PublishCMDs", reflect.TypeOf((*MockShortcutCmd)(nil).PublishCMDs), ctx, objID, cmdIDs)
|
||||
}
|
||||
|
||||
// UpdateCMD mocks base method.
|
||||
func (m *MockShortcutCmd) UpdateCMD(ctx context.Context, shortcut *entity.ShortcutCmd) (*entity.ShortcutCmd, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "UpdateCMD", ctx, shortcut)
|
||||
ret0, _ := ret[0].(*entity.ShortcutCmd)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// UpdateCMD indicates an expected call of UpdateCMD.
|
||||
func (mr *MockShortcutCmdMockRecorder) UpdateCMD(ctx, shortcut any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateCMD", reflect.TypeOf((*MockShortcutCmd)(nil).UpdateCMD), ctx, shortcut)
|
||||
}
|
||||
@ -1,118 +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.
|
||||
*/
|
||||
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: domain/upload/service/interface.go
|
||||
//
|
||||
// Generated by this command:
|
||||
//
|
||||
// mockgen -destination internal/mock/domain/upload/upload_service_mock.go --package mock_upload -source domain/upload/service/interface.go UploadService
|
||||
//
|
||||
|
||||
// Package mock_upload is a generated GoMock package.
|
||||
package mock_upload
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
service "github.com/coze-dev/coze-studio/backend/domain/upload/service"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
// MockUploadService is a mock of UploadService interface.
|
||||
type MockUploadService struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockUploadServiceMockRecorder
|
||||
isgomock struct{}
|
||||
}
|
||||
|
||||
// MockUploadServiceMockRecorder is the mock recorder for MockUploadService.
|
||||
type MockUploadServiceMockRecorder struct {
|
||||
mock *MockUploadService
|
||||
}
|
||||
|
||||
// NewMockUploadService creates a new mock instance.
|
||||
func NewMockUploadService(ctrl *gomock.Controller) *MockUploadService {
|
||||
mock := &MockUploadService{ctrl: ctrl}
|
||||
mock.recorder = &MockUploadServiceMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockUploadService) EXPECT() *MockUploadServiceMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// GetFile mocks base method.
|
||||
func (m *MockUploadService) GetFile(ctx context.Context, req *service.GetFileRequest) (*service.GetFileResponse, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetFile", ctx, req)
|
||||
ret0, _ := ret[0].(*service.GetFileResponse)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetFile indicates an expected call of GetFile.
|
||||
func (mr *MockUploadServiceMockRecorder) GetFile(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFile", reflect.TypeOf((*MockUploadService)(nil).GetFile), ctx, req)
|
||||
}
|
||||
|
||||
// GetFiles mocks base method.
|
||||
func (m *MockUploadService) GetFiles(ctx context.Context, req *service.GetFilesRequest) (*service.GetFilesResponse, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetFiles", ctx, req)
|
||||
ret0, _ := ret[0].(*service.GetFilesResponse)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetFiles indicates an expected call of GetFiles.
|
||||
func (mr *MockUploadServiceMockRecorder) GetFiles(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFiles", reflect.TypeOf((*MockUploadService)(nil).GetFiles), ctx, req)
|
||||
}
|
||||
|
||||
// UploadFile mocks base method.
|
||||
func (m *MockUploadService) UploadFile(ctx context.Context, req *service.UploadFileRequest) (*service.UploadFileResponse, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "UploadFile", ctx, req)
|
||||
ret0, _ := ret[0].(*service.UploadFileResponse)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// UploadFile indicates an expected call of UploadFile.
|
||||
func (mr *MockUploadServiceMockRecorder) UploadFile(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UploadFile", reflect.TypeOf((*MockUploadService)(nil).UploadFile), ctx, req)
|
||||
}
|
||||
|
||||
// UploadFiles mocks base method.
|
||||
func (m *MockUploadService) UploadFiles(ctx context.Context, req *service.UploadFilesRequest) (*service.UploadFilesResponse, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "UploadFiles", ctx, req)
|
||||
ret0, _ := ret[0].(*service.UploadFilesResponse)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// UploadFiles indicates an expected call of UploadFiles.
|
||||
func (mr *MockUploadServiceMockRecorder) UploadFiles(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UploadFiles", reflect.TypeOf((*MockUploadService)(nil).UploadFiles), ctx, req)
|
||||
}
|
||||
@ -71,6 +71,21 @@ func (mr *MockStorageMockRecorder) GetObject(ctx, objectKey any) *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetObject", reflect.TypeOf((*MockStorage)(nil).GetObject), ctx, objectKey)
|
||||
}
|
||||
|
||||
// GetObjectTagging mocks base method.
|
||||
func (m *MockStorage) GetObjectTagging(ctx context.Context, objectKey string) (map[string]string, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetObjectTagging", ctx, objectKey)
|
||||
ret0, _ := ret[0].(map[string]string)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetObjectTagging indicates an expected call of GetObjectTagging.
|
||||
func (mr *MockStorageMockRecorder) GetObjectTagging(ctx, objectKey any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetObjectTagging", reflect.TypeOf((*MockStorage)(nil).GetObjectTagging), ctx, objectKey)
|
||||
}
|
||||
|
||||
// GetObjectUrl mocks base method.
|
||||
func (m *MockStorage) GetObjectUrl(ctx context.Context, objectKey string, opts ...storage.GetOptFn) (string, error) {
|
||||
m.ctrl.T.Helper()
|
||||
@ -170,6 +185,20 @@ func (mr *MockStorageMockRecorder) PutObject(ctx, objectKey, content any, opts .
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutObject", reflect.TypeOf((*MockStorage)(nil).PutObject), varargs...)
|
||||
}
|
||||
|
||||
// PutObjectTagging mocks base method.
|
||||
func (m *MockStorage) PutObjectTagging(ctx context.Context, objectKey string, ts map[string]string) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "PutObjectTagging", ctx, objectKey, ts)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// PutObjectTagging indicates an expected call of PutObjectTagging.
|
||||
func (mr *MockStorageMockRecorder) PutObjectTagging(ctx, objectKey, ts any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutObjectTagging", reflect.TypeOf((*MockStorage)(nil).PutObjectTagging), ctx, objectKey, ts)
|
||||
}
|
||||
|
||||
// PutObjectWithReader mocks base method.
|
||||
func (m *MockStorage) PutObjectWithReader(ctx context.Context, objectKey string, content io.Reader, opts ...storage.PutOptFn) error {
|
||||
m.ctrl.T.Helper()
|
||||
|
||||
@ -1,66 +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 parsex
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/logs"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ParseClusterEndpoints 解析 ES /kafka 地址,多个地址用逗号分隔
|
||||
func ParseClusterEndpoints(address string) ([]string, error) {
|
||||
if strings.TrimSpace(address) == "" {
|
||||
return nil, fmt.Errorf("endpoints environment variable is required")
|
||||
}
|
||||
|
||||
endpoints := strings.Split(address, ",")
|
||||
var validEndpoints []string
|
||||
uniqueEndpoints := make(map[string]bool, len(endpoints))
|
||||
|
||||
for _, endpoint := range endpoints {
|
||||
trimmed := strings.TrimSpace(endpoint)
|
||||
if trimmed == "" {
|
||||
continue
|
||||
}
|
||||
if !uniqueEndpoints[trimmed] {
|
||||
uniqueEndpoints[trimmed] = true
|
||||
validEndpoints = append(validEndpoints, trimmed)
|
||||
}
|
||||
}
|
||||
|
||||
if len(validEndpoints) == 0 {
|
||||
return nil, fmt.Errorf("no valid endpoints found in: %s", address)
|
||||
}
|
||||
|
||||
return validEndpoints, nil
|
||||
}
|
||||
|
||||
// GetEnvDefaultIntSetting 获取环境变量的值,如果不存在或无效则返回默认值
|
||||
func GetEnvDefaultIntSetting(envVar, defaultValue string) string {
|
||||
value := os.Getenv(envVar)
|
||||
if value == "" {
|
||||
return defaultValue
|
||||
}
|
||||
if num, err := strconv.Atoi(value); err != nil || num <= 0 {
|
||||
logs.Warnf("Invalid %s value: %s, using default: %s", envVar, value, defaultValue)
|
||||
return defaultValue
|
||||
}
|
||||
return value
|
||||
}
|
||||
3
common/config/subspaces/default/pnpm-lock.yaml
generated
3
common/config/subspaces/default/pnpm-lock.yaml
generated
@ -22340,6 +22340,9 @@ importers:
|
||||
'@coze-project-ide/framework':
|
||||
specifier: workspace:*
|
||||
version: link:../../project-ide/framework
|
||||
'@coze-studio/api-schema':
|
||||
specifier: workspace:*
|
||||
version: link:../../arch/api-schema
|
||||
'@coze-studio/bot-detail-store':
|
||||
specifier: workspace:*
|
||||
version: link:../../studio/stores/bot-detail
|
||||
|
||||
@ -75,8 +75,6 @@ export ES_ADDR="http://127.0.0.1:9200"
|
||||
export ES_VERSION="v8"
|
||||
export ES_USERNAME=""
|
||||
export ES_PASSWORD=""
|
||||
export ES_NUMBER_OF_SHARDS = "1"
|
||||
export ES_NUMBER_OF_REPLICAS = "1"
|
||||
|
||||
|
||||
export COZE_MQ_TYPE="nsq" # nsq / kafka / rmq
|
||||
@ -91,9 +89,6 @@ export RMQ_SECRET_KEY=""
|
||||
export VECTOR_STORE_TYPE="milvus"
|
||||
# milvus vector store
|
||||
export MILVUS_ADDR="127.0.0.1:19530"
|
||||
export MILVUS_USER=""
|
||||
export MILVUS_PASSWORD=""
|
||||
export MILVUS_TOKEN=""
|
||||
# vikingdb vector store for Volcengine
|
||||
export VIKING_DB_HOST=""
|
||||
export VIKING_DB_REGION=""
|
||||
|
||||
@ -71,8 +71,6 @@ export ES_ADDR="http://elasticsearch:9200"
|
||||
export ES_VERSION="v8"
|
||||
export ES_USERNAME=""
|
||||
export ES_PASSWORD=""
|
||||
export ES_NUMBER_OF_SHARDS = "1"
|
||||
export ES_NUMBER_OF_REPLICAS = "1"
|
||||
|
||||
|
||||
export COZE_MQ_TYPE="nsq" # nsq / kafka / rmq
|
||||
@ -89,7 +87,6 @@ export VECTOR_STORE_TYPE="milvus"
|
||||
export MILVUS_ADDR="milvus:19530"
|
||||
export MILVUS_USER=""
|
||||
export MILVUS_PASSWORD=""
|
||||
export MILVUS_TOKEN=""
|
||||
# vikingdb vector store for Volcengine
|
||||
export VIKING_DB_HOST=""
|
||||
export VIKING_DB_REGION=""
|
||||
|
||||
@ -24,6 +24,7 @@ const config = [
|
||||
entries: {
|
||||
passport: './idl/passport/passport.thrift', // Entry service name and path
|
||||
explore: './idl/marketplace/public_api.thrift',
|
||||
upload: './idl/upload/upload.thrift',
|
||||
},
|
||||
commonCodePath: path.resolve(__dirname, './src/api/config.ts'), // custom profile
|
||||
output: './src', // Product location
|
||||
|
||||
@ -8,7 +8,8 @@
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./passport": "./src/idl/passport/passport.ts",
|
||||
"./marketplace": "./src/idl/marketplace/public_api.ts"
|
||||
"./marketplace": "./src/idl/marketplace/public_api.ts",
|
||||
"./upload": "./src/idl/upload/upload.ts"
|
||||
},
|
||||
"main": "src/index.ts",
|
||||
"typesVersions": {
|
||||
@ -18,6 +19,9 @@
|
||||
],
|
||||
"marketplace": [
|
||||
"./src/idl/marketplace/public_api.ts"
|
||||
],
|
||||
"upload": [
|
||||
"./src/idl/upload/upload.ts"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
1156
frontend/packages/arch/api-schema/src/idl/app/bot_common.ts
Normal file
1156
frontend/packages/arch/api-schema/src/idl/app/bot_common.ts
Normal file
File diff suppressed because it is too large
Load Diff
157
frontend/packages/arch/api-schema/src/idl/upload/upload.ts
Normal file
157
frontend/packages/arch/api-schema/src/idl/upload/upload.ts
Normal file
@ -0,0 +1,157 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import * as bot_common from './../app/bot_common';
|
||||
export { bot_common };
|
||||
import * as base from './../base';
|
||||
export { base };
|
||||
import { createAPI } from './../../api/config';
|
||||
export interface CommonUploadRequest {
|
||||
ByteData?: Blob,
|
||||
uploadID?: string,
|
||||
partNumber?: string,
|
||||
}
|
||||
export interface Error {
|
||||
code: number,
|
||||
error: string,
|
||||
error_code: number,
|
||||
message: string,
|
||||
}
|
||||
export interface Payload {
|
||||
hash: string,
|
||||
key: string,
|
||||
uploadID: string,
|
||||
}
|
||||
export interface CommonUploadResponse {
|
||||
Version: string,
|
||||
success: number,
|
||||
error: Error,
|
||||
payload: Payload,
|
||||
}
|
||||
export interface ApplyUploadActionRequest {
|
||||
Action?: string,
|
||||
Version?: string,
|
||||
ServiceId?: string,
|
||||
FileExtension?: string,
|
||||
FileSize?: string,
|
||||
s?: string,
|
||||
ByteData?: Blob,
|
||||
}
|
||||
export interface ResponseMetadata {
|
||||
RequestId: string,
|
||||
Action: string,
|
||||
Version: string,
|
||||
Service: string,
|
||||
Region: string,
|
||||
}
|
||||
export interface StoreInfo {
|
||||
StoreUri: string,
|
||||
Auth: string,
|
||||
UploadID: string,
|
||||
}
|
||||
export interface UploadAddress {
|
||||
StoreInfos: StoreInfo[],
|
||||
UploadHosts: string[],
|
||||
UploadHeader?: {
|
||||
[key: string | number]: string
|
||||
},
|
||||
SessionKey: string,
|
||||
Cloud: string,
|
||||
}
|
||||
export interface UploadNode {
|
||||
StoreInfos: StoreInfo[],
|
||||
UploadHost: string,
|
||||
UploadHeader?: {
|
||||
[key: string | number]: string
|
||||
},
|
||||
SessionKey: string,
|
||||
}
|
||||
export interface InnerUploadAddress {
|
||||
UploadNodes: UploadNode[]
|
||||
}
|
||||
export interface UploadResult {
|
||||
Uri: string,
|
||||
UriStatus: number,
|
||||
}
|
||||
export interface PluginResult {
|
||||
FileName: string,
|
||||
SourceUri: string,
|
||||
ImageUri: string,
|
||||
ImageWidth: number,
|
||||
ImageHeight: number,
|
||||
ImageMd5: string,
|
||||
ImageFormat: string,
|
||||
ImageSize: number,
|
||||
FrameCnt: number,
|
||||
}
|
||||
export interface ApplyUploadActionResult {
|
||||
UploadAddress?: UploadAddress,
|
||||
FallbackUploadAddress?: UploadAddress,
|
||||
InnerUploadAddress?: InnerUploadAddress,
|
||||
RequestId?: string,
|
||||
SDKParam?: string,
|
||||
Results?: UploadResult[],
|
||||
PluginResult?: PluginResult[],
|
||||
}
|
||||
export interface ApplyUploadActionResponse {
|
||||
ResponseMetadata: ResponseMetadata,
|
||||
Result: ApplyUploadActionResult,
|
||||
}
|
||||
export interface RecordFileInfoRequest {
|
||||
FileURI: string,
|
||||
FileName: string,
|
||||
FileSize?: string,
|
||||
FileExtension?: string,
|
||||
}
|
||||
export interface RecordFileInfoResponse {}
|
||||
export const CommonUpload = /*#__PURE__*/createAPI<CommonUploadRequest, CommonUploadResponse>({
|
||||
"url": "/api/common/upload/*tos_uri",
|
||||
"method": "POST",
|
||||
"name": "CommonUpload",
|
||||
"reqType": "CommonUploadRequest",
|
||||
"reqMapping": {
|
||||
"raw_body": [],
|
||||
"query": ["uploadID", "partNumber"]
|
||||
},
|
||||
"resType": "CommonUploadResponse",
|
||||
"schemaRoot": "api://schemas/idl_upload_upload",
|
||||
"service": "upload"
|
||||
});
|
||||
export const ApplyUploadAction = /*#__PURE__*/createAPI<ApplyUploadActionRequest, ApplyUploadActionResponse>({
|
||||
"url": "/api/common/upload/apply_upload_action",
|
||||
"method": "POST",
|
||||
"name": "ApplyUploadAction",
|
||||
"reqType": "ApplyUploadActionRequest",
|
||||
"reqMapping": {
|
||||
"query": ["Action", "Version", "ServiceId", "FileExtension", "FileSize", "s"],
|
||||
"raw_body": []
|
||||
},
|
||||
"resType": "ApplyUploadActionResponse",
|
||||
"schemaRoot": "api://schemas/idl_upload_upload",
|
||||
"service": "upload"
|
||||
});
|
||||
export const RecordFileInfo = /*#__PURE__*/createAPI<RecordFileInfoRequest, RecordFileInfoResponse>({
|
||||
"url": "/api/common/record_file_info",
|
||||
"method": "POST",
|
||||
"name": "RecordFileInfo",
|
||||
"reqType": "RecordFileInfoRequest",
|
||||
"reqMapping": {
|
||||
"body": ["FileURI", "FileName", "FileSize", "FileExtension"]
|
||||
},
|
||||
"resType": "RecordFileInfoResponse",
|
||||
"schemaRoot": "api://schemas/idl_upload_upload",
|
||||
"service": "upload"
|
||||
});
|
||||
@ -16,3 +16,4 @@
|
||||
|
||||
export * as passport from './idl/passport/passport';
|
||||
export * as explore from './idl/marketplace/public_api';
|
||||
export * as upload from './idl/upload/upload';
|
||||
|
||||
@ -92,6 +92,7 @@
|
||||
"@coze-foundation/layout": "workspace:*",
|
||||
"@coze-foundation/local-storage": "workspace:*",
|
||||
"@coze-project-ide/framework": "workspace:*",
|
||||
"@coze-studio/api-schema": "workspace:*",
|
||||
"@coze-studio/bot-detail-store": "workspace:*",
|
||||
"@coze-studio/components": "workspace:*",
|
||||
"@coze-studio/open-chat": "workspace:*",
|
||||
|
||||
@ -20,10 +20,11 @@ import { useState } from 'react';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { workflowApi } from '@coze-workflow/base/api';
|
||||
import { type ViewVariableType } from '@coze-workflow/base';
|
||||
import { upload as uploadAPI } from '@coze-studio/api-schema';
|
||||
import { I18n } from '@coze-arch/i18n';
|
||||
import { Toast } from '@coze-arch/coze-design';
|
||||
import { upLoadFile } from '@coze-arch/bot-utils';
|
||||
import { CustomError } from '@coze-arch/bot-error';
|
||||
import { Toast } from '@coze-arch/coze-design';
|
||||
|
||||
import { validate } from './validate';
|
||||
import { FileItemStatus, type FileItem } from './types';
|
||||
@ -101,7 +102,10 @@ export const useUpload = (props?: UploadConfig) => {
|
||||
|
||||
// Upload complete, clear timeout timer
|
||||
clearTimeout(progressTimer);
|
||||
|
||||
await uploadAPI.RecordFileInfo({
|
||||
FileURI: uri,
|
||||
FileName: file.name,
|
||||
});
|
||||
// Add uri and get the url.
|
||||
const { url } = await workflowApi.SignImageURL(
|
||||
{
|
||||
@ -134,7 +138,8 @@ export const useUpload = (props?: UploadConfig) => {
|
||||
const validateFile = async (file: FileItem): Promise<string | undefined> => {
|
||||
const validateMsg = await validate(file, {
|
||||
customValidate,
|
||||
maxSize: maxSize ?? fileType === 'image' ? MAX_IMAGE_SIZE : MAX_FILE_SIZE,
|
||||
maxSize:
|
||||
(maxSize ?? fileType === 'image') ? MAX_IMAGE_SIZE : MAX_FILE_SIZE,
|
||||
accept,
|
||||
});
|
||||
if (validateMsg) {
|
||||
|
||||
@ -53,6 +53,9 @@
|
||||
{
|
||||
"path": "../../agent-ide/space-bot/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/api-schema/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/bot-api/tsconfig.build.json"
|
||||
},
|
||||
|
||||
@ -88,7 +88,22 @@ struct ApplyUploadActionResponse {
|
||||
1: required ResponseMetadata ResponseMetadata,
|
||||
2: required ApplyUploadActionResult Result
|
||||
}
|
||||
struct RecordFileInfoRequest {
|
||||
1: required string FileURI
|
||||
2: required string FileName
|
||||
3: optional string FileSize
|
||||
4: optional string FileExtension
|
||||
}
|
||||
|
||||
struct RecordFileInfoResponse {
|
||||
253: required i64 code,
|
||||
254: required string msg,
|
||||
255: optional base.BaseResp BaseResp (api.none="true")
|
||||
}
|
||||
|
||||
|
||||
service UploadService {
|
||||
CommonUploadResponse CommonUpload(1: CommonUploadRequest request)(api.post = '/api/common/upload/*tos_uri', api.category="upload", api.gen_path="upload")
|
||||
ApplyUploadActionResponse ApplyUploadAction(1: ApplyUploadActionRequest request)(api.get='/api/common/upload/apply_upload_action', api.post='/api/common/upload/apply_upload_action', api.category="common", api.gen_path="common")
|
||||
RecordFileInfoResponse RecordFileInfo(1: RecordFileInfoRequest request)( api.post='/api/common/record_file_info', api.category="common", api.gen_path="common")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user