feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
125
backend/api/handler/coze/agent_run_service.go
Normal file
125
backend/api/handler/coze/agent_run_service.go
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* 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 coze
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/hertz-contrib/sse"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/conversation/run"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/application/conversation"
|
||||
sseImpl "github.com/coze-dev/coze-studio/backend/infra/impl/sse"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/types/errno"
|
||||
)
|
||||
|
||||
// AgentRun .
|
||||
// @router /api/conversation/chat [POST]
|
||||
func AgentRun(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req run.AgentRunRequest
|
||||
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if checkErr := checkParams(ctx, &req); checkErr != nil {
|
||||
invalidParamRequestResponse(c, checkErr.Error())
|
||||
return
|
||||
}
|
||||
|
||||
sseSender := sseImpl.NewSSESender(sse.NewStream(c))
|
||||
c.SetStatusCode(http.StatusOK)
|
||||
c.Response.Header.Set("X-Accel-Buffering", "no")
|
||||
|
||||
err = conversation.ConversationSVC.Run(ctx, sseSender, &req)
|
||||
if err != nil {
|
||||
errData := run.ErrorData{
|
||||
Code: errno.ErrConversationAgentRunError,
|
||||
Msg: err.Error(),
|
||||
}
|
||||
ed, _ := json.Marshal(errData)
|
||||
_ = sseSender.Send(ctx, &sse.Event{
|
||||
Event: run.RunEventError,
|
||||
Data: ed,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func checkParams(_ context.Context, ar *run.AgentRunRequest) error {
|
||||
if ar.BotID == 0 {
|
||||
return errorx.New(errno.ErrConversationInvalidParamCode, errorx.KV("msg", "bot id is required"))
|
||||
}
|
||||
|
||||
if ar.Scene == nil {
|
||||
return errorx.New(errno.ErrConversationInvalidParamCode, errorx.KV("msg", "scene is required"))
|
||||
}
|
||||
|
||||
if ar.ContentType == nil {
|
||||
ar.ContentType = ptr.Of(run.ContentTypeText)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ChatV3 .
|
||||
// @router /v3/chat [POST]
|
||||
func ChatV3(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req run.ChatV3Request
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
if checkErr := checkParamsV3(ctx, &req); checkErr != nil {
|
||||
invalidParamRequestResponse(c, checkErr.Error())
|
||||
return
|
||||
}
|
||||
|
||||
c.SetStatusCode(http.StatusOK)
|
||||
c.Response.Header.Set("X-Accel-Buffering", "no")
|
||||
sseSender := sseImpl.NewSSESender(sse.NewStream(c))
|
||||
err = conversation.ConversationOpenAPISVC.OpenapiAgentRun(ctx, sseSender, &req)
|
||||
if err != nil {
|
||||
errData := run.ErrorData{
|
||||
Code: errno.ErrConversationAgentRunError,
|
||||
Msg: err.Error(),
|
||||
}
|
||||
ed, _ := json.Marshal(errData)
|
||||
_ = sseSender.Send(ctx, &sse.Event{
|
||||
Event: run.RunEventError,
|
||||
Data: ed,
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func checkParamsV3(_ context.Context, ar *run.ChatV3Request) error {
|
||||
if ar.BotID == 0 {
|
||||
return errorx.New(errno.ErrConversationInvalidParamCode, errorx.KV("msg", "bot id is required"))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
33
backend/api/handler/coze/base.go
Normal file
33
backend/api/handler/coze/base.go
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 coze
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/internal/httputil"
|
||||
)
|
||||
|
||||
func invalidParamRequestResponse(c *app.RequestContext, errMsg string) {
|
||||
httputil.BadRequest(c, errMsg)
|
||||
}
|
||||
|
||||
func internalServerErrorResponse(ctx context.Context, c *app.RequestContext, err error) {
|
||||
httputil.InternalError(ctx, c, err)
|
||||
}
|
||||
59
backend/api/handler/coze/bot_open_api_service.go
Normal file
59
backend/api/handler/coze/bot_open_api_service.go
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by hertz generator.
|
||||
|
||||
package coze
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/application/plugin"
|
||||
|
||||
bot_open_api "github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/bot_open_api"
|
||||
)
|
||||
|
||||
// OauthAuthorizationCode .
|
||||
// @router /api/oauth/authorization_code [GET]
|
||||
func OauthAuthorizationCode(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req bot_open_api.OauthAuthorizationCodeReq
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.Code == "" {
|
||||
invalidParamRequestResponse(c, "code is required")
|
||||
return
|
||||
}
|
||||
if req.State == "" {
|
||||
invalidParamRequestResponse(c, "state is required")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.OauthAuthorizationCode(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
172
backend/api/handler/coze/conversation_service.go
Normal file
172
backend/api/handler/coze/conversation_service.go
Normal file
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by hertz generator.
|
||||
|
||||
package coze
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/conversation/conversation"
|
||||
application "github.com/coze-dev/coze-studio/backend/application/conversation"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
||||
"github.com/coze-dev/coze-studio/backend/types/errno"
|
||||
)
|
||||
|
||||
// ClearConversationHistory .
|
||||
// @router /api/conversation/clear_message [POST]
|
||||
func ClearConversationHistory(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req conversation.ClearConversationHistoryRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if checkErr := checkCCHParams(ctx, &req); checkErr != nil {
|
||||
invalidParamRequestResponse(c, checkErr.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := application.ConversationSVC.ClearHistory(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
func checkCCHParams(_ context.Context, req *conversation.ClearConversationHistoryRequest) error {
|
||||
if req.ConversationID <= 0 {
|
||||
return errorx.New(errno.ErrConversationInvalidParamCode, errorx.KV("msg", "invalid conversation id"))
|
||||
}
|
||||
|
||||
if req.Scene == nil {
|
||||
return errorx.New(errno.ErrConversationInvalidParamCode, errorx.KV("msg", "scene is required"))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearConversationCtx .
|
||||
// @router /api/conversation/create_section [POST]
|
||||
func ClearConversationCtx(ctx context.Context, c *app.RequestContext) {
|
||||
resp := new(conversation.ClearConversationCtxResponse)
|
||||
var err error
|
||||
var req conversation.ClearConversationCtxRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if checkErr := checkCCCParams(ctx, &req); checkErr != nil {
|
||||
invalidParamRequestResponse(c, checkErr.Error())
|
||||
return
|
||||
}
|
||||
|
||||
newSectionID, err := application.ConversationSVC.CreateSection(ctx, req.ConversationID)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
resp.NewSectionID = newSectionID
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
func checkCCCParams(ctx context.Context, req *conversation.ClearConversationCtxRequest) error {
|
||||
if req.ConversationID <= 0 {
|
||||
return errorx.New(errno.ErrConversationInvalidParamCode, errorx.KV("msg", "invalid conversation id"))
|
||||
}
|
||||
|
||||
if req.Scene == nil {
|
||||
return errorx.New(errno.ErrConversationInvalidParamCode, errorx.KV("msg", "scene is required"))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateConversation .
|
||||
// @router /api/conversation/create [POST]
|
||||
func CreateConversation(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req conversation.CreateConversationRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := application.ConversationSVC.CreateConversation(ctx, req.GetBotId(), req.GetConnectorId())
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// ClearConversationApi .
|
||||
// @router /v1/conversations/:conversation_id/clear [POST]
|
||||
func ClearConversationApi(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req conversation.ClearConversationApiRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(conversation.ClearConversationApiResponse)
|
||||
|
||||
sectionID, err := application.ConversationSVC.CreateSection(ctx, req.ConversationID)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
resp.Data = &conversation.Section{
|
||||
ID: sectionID,
|
||||
ConversationID: req.ConversationID,
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// ListConversationsApi .
|
||||
// @router /v1/conversations [GET]
|
||||
func ListConversationsApi(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req conversation.ListConversationsApiRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := application.ConversationSVC.ListConversation(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
72
backend/api/handler/coze/conversation_service_test.go
Normal file
72
backend/api/handler/coze/conversation_service_test.go
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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 coze
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/cloudwego/hertz/pkg/app/server"
|
||||
"github.com/cloudwego/hertz/pkg/common/ut"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/conversation/common"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/conversation/conversation"
|
||||
"github.com/coze-dev/coze-studio/backend/application"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
)
|
||||
|
||||
func TestClearConversationCtx(t *testing.T) {
|
||||
h := server.Default()
|
||||
err := application.Init(context.Background())
|
||||
|
||||
t.Logf("application init err: %v", err)
|
||||
h.POST("/api/conversation/create_section", ClearConversationCtx)
|
||||
|
||||
req := &conversation.ClearConversationCtxRequest{
|
||||
ConversationID: 7496795464885338112,
|
||||
Scene: ptr.Of(common.Scene_Playground),
|
||||
}
|
||||
m, err := sonic.Marshal(req)
|
||||
assert.Nil(t, err)
|
||||
|
||||
w := ut.PerformRequest(h.Engine, "POST", "/api/conversation/create_section", &ut.Body{Body: bytes.NewBuffer(m), Len: len(m)}, ut.Header{Key: "Content-Type", Value: "application/json"})
|
||||
res := w.Result()
|
||||
t.Logf("clear conversation ctx: %s", res.Body())
|
||||
assert.Equal(t, http.StatusInternalServerError, res.StatusCode())
|
||||
}
|
||||
|
||||
func TestClearConversationHistory(t *testing.T) {
|
||||
h := server.Default()
|
||||
err := application.Init(context.Background())
|
||||
t.Logf("application init err: %v", err)
|
||||
h.POST("/api/conversation/clear_message", ClearConversationHistory)
|
||||
req := &conversation.ClearConversationHistoryRequest{
|
||||
ConversationID: 7496795464885338113,
|
||||
Scene: ptr.Of(common.Scene_Playground),
|
||||
BotID: ptr.Of(int64(7366055842027922437)),
|
||||
}
|
||||
m, err := sonic.Marshal(req)
|
||||
assert.Nil(t, err)
|
||||
w := ut.PerformRequest(h.Engine, "POST", "/api/conversation/clear_message", &ut.Body{Body: bytes.NewBuffer(m), Len: len(m)}, ut.Header{Key: "Content-Type", Value: "application/json"})
|
||||
res := w.Result()
|
||||
t.Logf("clear conversation history: %s", res.Body())
|
||||
assert.Equal(t, http.StatusInternalServerError, res.StatusCode())
|
||||
}
|
||||
412
backend/api/handler/coze/database_service.go
Normal file
412
backend/api/handler/coze/database_service.go
Normal file
@@ -0,0 +1,412 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by hertz generator.
|
||||
|
||||
package coze
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/knowledge/document"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/table"
|
||||
"github.com/coze-dev/coze-studio/backend/application/memory"
|
||||
"github.com/coze-dev/coze-studio/backend/application/singleagent"
|
||||
)
|
||||
|
||||
// ListDatabase .
|
||||
// @router /api/memory/database/list [POST]
|
||||
func ListDatabase(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req table.ListDatabaseRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := memory.DatabaseApplicationSVC.ListDatabase(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetDatabaseByID .
|
||||
// @router /api/memory/database/get_by_id [POST]
|
||||
func GetDatabaseByID(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req table.SingleDatabaseRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := memory.DatabaseApplicationSVC.GetDatabaseByID(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// AddDatabase .
|
||||
// @router /api/memory/database/add [POST]
|
||||
func AddDatabase(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req table.AddDatabaseRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := memory.DatabaseApplicationSVC.AddDatabase(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// UpdateDatabase .
|
||||
// @router /api/memory/database/update [POST]
|
||||
func UpdateDatabase(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req table.UpdateDatabaseRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := memory.DatabaseApplicationSVC.UpdateDatabase(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// DeleteDatabase .
|
||||
// @router /api/memory/database/delete [POST]
|
||||
func DeleteDatabase(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req table.DeleteDatabaseRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := memory.DatabaseApplicationSVC.DeleteDatabase(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// BindDatabase .
|
||||
// @router /api/memory/database/bind_to_bot [POST]
|
||||
func BindDatabase(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req table.BindDatabaseToBotRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := singleagent.SingleAgentSVC.BindDatabase(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// UnBindDatabase .
|
||||
// @router /api/memory/database/unbind_to_bot [POST]
|
||||
func UnBindDatabase(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req table.BindDatabaseToBotRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := singleagent.SingleAgentSVC.UnBindDatabase(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// ListDatabaseRecords .
|
||||
// @router /api/memory/database/list_records [POST]
|
||||
func ListDatabaseRecords(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req table.ListDatabaseRecordsRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := memory.DatabaseApplicationSVC.ListDatabaseRecords(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// UpdateDatabaseRecords .
|
||||
// @router /api/memory/database/update_records [POST]
|
||||
func UpdateDatabaseRecords(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req table.UpdateDatabaseRecordsRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := memory.DatabaseApplicationSVC.UpdateDatabaseRecords(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetOnlineDatabaseId .
|
||||
// @router /api/memory/database/get_online_database_id [POST]
|
||||
func GetOnlineDatabaseId(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req table.GetOnlineDatabaseIdRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := memory.DatabaseApplicationSVC.GetOnlineDatabaseId(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// ResetBotTable .
|
||||
// @router /api/memory/database/table/reset [POST]
|
||||
func ResetBotTable(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req table.ResetBotTableRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := memory.DatabaseApplicationSVC.ResetBotTable(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetDatabaseTemplate .
|
||||
// @router /api/memory/database/get_template [POST]
|
||||
func GetDatabaseTemplate(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req table.GetDatabaseTemplateRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := memory.DatabaseApplicationSVC.GetDatabaseTemplate(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetConnectorName .
|
||||
// @router /api/memory/database/get_connector_name [POST]
|
||||
func GetConnectorName(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req table.GetSpaceConnectorListRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := memory.DatabaseApplicationSVC.GetConnectorName(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetBotDatabase .
|
||||
// @router /api/memory/database/table/list_new [POST]
|
||||
func GetBotDatabase(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req table.GetBotTableRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := memory.DatabaseApplicationSVC.GetBotDatabase(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// UpdateDatabaseBotSwitch .
|
||||
// @router /api/memory/database/update_bot_switch [POST]
|
||||
func UpdateDatabaseBotSwitch(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req table.UpdateDatabaseBotSwitchRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := singleagent.SingleAgentSVC.UpdatePromptDisable(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetDatabaseTableSchema .
|
||||
// @router /api/memory/table_schema/get [POST]
|
||||
func GetDatabaseTableSchema(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req table.GetTableSchemaRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var resp *document.GetTableSchemaInfoResponse
|
||||
resp, err = memory.DatabaseApplicationSVC.GetDatabaseTableSchema(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// SubmitDatabaseInsertTask .
|
||||
// @router /api/memory/table_file/submit [POST]
|
||||
func SubmitDatabaseInsertTask(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req table.SubmitDatabaseInsertRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := memory.DatabaseApplicationSVC.SubmitDatabaseInsertTask(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// DatabaseFileProgressData .
|
||||
// @router /api/memory/table_file/get_progress [POST]
|
||||
func DatabaseFileProgressData(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req table.GetDatabaseFileProgressRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := memory.DatabaseApplicationSVC.DatabaseFileProgressData(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// ValidateDatabaseTableSchema .
|
||||
// @router /api/memory/table_schema/validate [POST]
|
||||
func ValidateDatabaseTableSchema(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req table.ValidateTableSchemaRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := memory.DatabaseApplicationSVC.ValidateDatabaseTableSchema(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
463
backend/api/handler/coze/developer_api_service.go
Normal file
463
backend/api/handler/coze/developer_api_service.go
Normal file
@@ -0,0 +1,463 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by hertz generator.
|
||||
|
||||
package coze
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
||||
|
||||
developer_api "github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/developer_api"
|
||||
"github.com/coze-dev/coze-studio/backend/application/base/ctxutil"
|
||||
"github.com/coze-dev/coze-studio/backend/application/modelmgr"
|
||||
"github.com/coze-dev/coze-studio/backend/application/singleagent"
|
||||
application "github.com/coze-dev/coze-studio/backend/application/singleagent"
|
||||
"github.com/coze-dev/coze-studio/backend/application/upload"
|
||||
"github.com/coze-dev/coze-studio/backend/application/user"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/types/errno"
|
||||
)
|
||||
|
||||
// DraftBotCreate .
|
||||
// @router /api/draftbot/create [POST]
|
||||
func DraftBotCreate(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req developer_api.DraftBotCreateRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.SpaceID <= 0 {
|
||||
invalidParamRequestResponse(c, "space id is not set")
|
||||
return
|
||||
}
|
||||
|
||||
if req.Name == "" {
|
||||
invalidParamRequestResponse(c, "name is nil")
|
||||
return
|
||||
}
|
||||
|
||||
if req.IconURI == "" {
|
||||
invalidParamRequestResponse(c, "icon uri is nil")
|
||||
return
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(req.Name) > 50 {
|
||||
invalidParamRequestResponse(c, "name is too long")
|
||||
return
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(req.Description) > 2000 {
|
||||
invalidParamRequestResponse(c, "description is too long")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := application.SingleAgentSVC.CreateSingleAgentDraft(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// DeleteDraftBot .
|
||||
// @router /api/draftbot/delete [POST]
|
||||
func DeleteDraftBot(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req developer_api.DeleteDraftBotRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := application.SingleAgentSVC.DeleteAgentDraft(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// UpdateDraftBotDisplayInfo .
|
||||
// @router /api/draftbot/update_display_info [POST]
|
||||
func UpdateDraftBotDisplayInfo(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req developer_api.UpdateDraftBotDisplayInfoRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := application.SingleAgentSVC.UpdateAgentDraftDisplayInfo(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// DuplicateDraftBot .
|
||||
// @router /api/draftbot/duplicate [POST]
|
||||
func DuplicateDraftBot(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req developer_api.DuplicateDraftBotRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := application.SingleAgentSVC.DuplicateDraftBot(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetDraftBotDisplayInfo .
|
||||
// @router /api/draftbot/get_display_info [POST]
|
||||
func GetDraftBotDisplayInfo(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req developer_api.GetDraftBotDisplayInfoRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := application.SingleAgentSVC.GetAgentDraftDisplayInfo(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// PublishDraftBot .
|
||||
// @router /api/draftbot/publish [POST]
|
||||
func PublishDraftBot(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req developer_api.PublishDraftBotRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if len(req.Connectors) == 0 {
|
||||
invalidParamRequestResponse(c, "connectors is nil")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := application.SingleAgentSVC.PublishAgent(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// ListDraftBotHistory .
|
||||
// @router /api/draftbot/list_draft_history [POST]
|
||||
func ListDraftBotHistory(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req developer_api.ListDraftBotHistoryRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.BotID == 0 {
|
||||
invalidParamRequestResponse(c, "bot id is not set")
|
||||
return
|
||||
}
|
||||
|
||||
if req.PageIndex <= 0 {
|
||||
req.PageIndex = 1
|
||||
}
|
||||
|
||||
if req.PageSize <= 0 {
|
||||
req.PageSize = 30
|
||||
}
|
||||
|
||||
resp, err := application.SingleAgentSVC.ListAgentPublishHistory(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetIcon .
|
||||
// @router /api/developer/get_icon [POST]
|
||||
func GetIcon(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req developer_api.GetIconRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := upload.SVC.GetIcon(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetUploadAuthToken .
|
||||
// @router /api/playground/upload/auth_token [POST]
|
||||
func GetUploadAuthToken(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req developer_api.GetUploadAuthTokenRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := application.SingleAgentSVC.GetUploadAuthToken(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
func createSecret(uid int64, fileType string) string {
|
||||
num := 10
|
||||
input := fmt.Sprintf("upload_%d_Ma*9)fhi_%d_gou_%s_rand_%d", uid, time.Now().Unix(), fileType, rand.Intn(100000))
|
||||
// 做md5,取前20个,// mapIntToBase62 把数字映射到 Base62
|
||||
hash := sha256.Sum256([]byte(fmt.Sprintf("%s", input)))
|
||||
hashString := base64.StdEncoding.EncodeToString(hash[:])
|
||||
if len(hashString) > num {
|
||||
hashString = hashString[:num]
|
||||
}
|
||||
|
||||
result := ""
|
||||
for _, char := range hashString {
|
||||
index := int(char) % 62
|
||||
result += string(baseWord[index])
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// UploadFile .
|
||||
// @router /api/bot/upload_file [POST]
|
||||
func UploadFile(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req developer_api.UploadFileRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(developer_api.UploadFileResponse)
|
||||
fileContent, err := base64.StdEncoding.DecodeString(req.Data)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
userID := ctxutil.GetUIDFromCtx(ctx)
|
||||
if userID == nil {
|
||||
internalServerErrorResponse(ctx, c, errorx.New(errno.ErrUploadPermissionCode, errorx.KV("msg", "session required")))
|
||||
return
|
||||
}
|
||||
secret := createSecret(ptr.From(userID), req.FileHead.FileType)
|
||||
fileName := fmt.Sprintf("%d_%d_%s.%s", ptr.From(userID), time.Now().UnixNano(), secret, req.FileHead.FileType)
|
||||
objectName := fmt.Sprintf("%s/%s", req.FileHead.BizType.String(), fileName)
|
||||
resp, err = upload.SVC.UploadFile(ctx, fileContent, objectName)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
const baseWord = "1Aa2Bb3Cc4Dd5Ee6Ff7Gg8Hh9Ii0JjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"
|
||||
|
||||
// GetOnboarding .
|
||||
// @router /api/playground/get_onboarding [POST]
|
||||
func GetOnboarding(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req developer_api.GetOnboardingRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(developer_api.GetOnboardingResponse)
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// PublishConnectorList .
|
||||
// @router /api/draftbot/publish/connector/list [POST]
|
||||
func PublishConnectorList(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req developer_api.PublishConnectorListRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.BotID == 0 {
|
||||
invalidParamRequestResponse(c, "bot id is not set")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := singleagent.SingleAgentSVC.GetPublishConnectorList(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// CheckDraftBotCommit .
|
||||
// @router /api/draftbot/commit_check [POST]
|
||||
func CheckDraftBotCommit(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req developer_api.CheckDraftBotCommitRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
|
||||
}
|
||||
resp := new(developer_api.CheckDraftBotCommitResponse)
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// UpdateUserProfileCheck .
|
||||
// @router /api/user/update_profile_check [POST]
|
||||
func UpdateUserProfileCheck(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req developer_api.UpdateUserProfileCheckRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := user.UserApplicationSVC.UpdateUserProfileCheck(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetTypeList .
|
||||
// @router /api/bot/get_type_list [POST]
|
||||
func GetTypeList(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req developer_api.GetTypeListRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := modelmgr.ModelmgrApplicationSVC.GetModelList(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// CommonUpload .
|
||||
// @router /api/playground/upload [POST]
|
||||
func CommonUpload(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req developer_api.CommonUploadRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
fullUrl := string(c.Request.URI().FullURI())
|
||||
resp, err := upload.SVC.UploadFileCommon(ctx, &req, fullUrl)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// ApplyUploadAction .
|
||||
// @router /api/playground/apply_upload_action [GET]
|
||||
func ApplyUploadAction(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req developer_api.ApplyUploadActionRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
resp := new(developer_api.ApplyUploadActionResponse)
|
||||
host := c.Request.Host()
|
||||
if ptr.From(req.Action) == "ApplyImageUpload" {
|
||||
resp, err = upload.SVC.ApplyImageUpload(ctx, &req, string(host))
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
} else if ptr.From(req.Action) == "CommitImageUpload" {
|
||||
resp, err = upload.SVC.CommitImageUpload(ctx, &req, string(host))
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
406
backend/api/handler/coze/intelligence_service.go
Normal file
406
backend/api/handler/coze/intelligence_service.go
Normal file
@@ -0,0 +1,406 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by hertz generator.
|
||||
|
||||
package coze
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/intelligence"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/intelligence/common"
|
||||
project "github.com/coze-dev/coze-studio/backend/api/model/project"
|
||||
publish "github.com/coze-dev/coze-studio/backend/api/model/publish"
|
||||
task "github.com/coze-dev/coze-studio/backend/api/model/task"
|
||||
appApplication "github.com/coze-dev/coze-studio/backend/application/app"
|
||||
"github.com/coze-dev/coze-studio/backend/application/search"
|
||||
)
|
||||
|
||||
// GetDraftIntelligenceList .
|
||||
// @router /api/intelligence_api/search/get_draft_intelligence_list [POST]
|
||||
func GetDraftIntelligenceList(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req intelligence.GetDraftIntelligenceListRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := search.SearchSVC.GetDraftIntelligenceList(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetDraftIntelligenceInfo .
|
||||
// @router /api/intelligence_api/search/get_draft_intelligence_info [POST]
|
||||
func GetDraftIntelligenceInfo(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req intelligence.GetDraftIntelligenceInfoRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.IntelligenceID <= 0 {
|
||||
invalidParamRequestResponse(c, "invalid intelligence id")
|
||||
return
|
||||
}
|
||||
if req.IntelligenceType != common.IntelligenceType_Project {
|
||||
invalidParamRequestResponse(c, fmt.Sprintf("invalid intelligence type '%d'", req.IntelligenceType))
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := appApplication.APPApplicationSVC.GetDraftIntelligenceInfo(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetUserRecentlyEditIntelligence .
|
||||
// @router /api/intelligence_api/search/get_recently_edit_intelligence [POST]
|
||||
func GetUserRecentlyEditIntelligence(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req intelligence.GetUserRecentlyEditIntelligenceRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(intelligence.GetUserRecentlyEditIntelligenceResponse)
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// DraftProjectCreate .
|
||||
// @router /api/intelligence_api/draft_project/create [POST]
|
||||
func DraftProjectCreate(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req project.DraftProjectCreateRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.SpaceID <= 0 {
|
||||
invalidParamRequestResponse(c, "invalid space id")
|
||||
return
|
||||
}
|
||||
if req.Name == "" || len(req.Name) > 256 {
|
||||
invalidParamRequestResponse(c, "invalid name")
|
||||
return
|
||||
}
|
||||
if req.IconURI == "" || len(req.IconURI) > 512 {
|
||||
invalidParamRequestResponse(c, "invalid icon uri")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := appApplication.APPApplicationSVC.DraftProjectCreate(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// DraftProjectUpdate .
|
||||
// @router /api/intelligence_api/draft_project/update [POST]
|
||||
func DraftProjectUpdate(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req project.DraftProjectUpdateRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.ProjectID <= 0 {
|
||||
invalidParamRequestResponse(c, "invalid project id")
|
||||
return
|
||||
}
|
||||
if req.Name != nil && (len(*req.Name) == 0 || len(*req.Name) > 256) {
|
||||
invalidParamRequestResponse(c, "invalid name")
|
||||
return
|
||||
}
|
||||
if req.IconURI != nil && (len(*req.IconURI) == 0 || len(*req.IconURI) > 512) {
|
||||
invalidParamRequestResponse(c, "invalid icon uri")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := appApplication.APPApplicationSVC.DraftProjectUpdate(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// DraftProjectDelete .
|
||||
// @router /api/intelligence_api/draft_project/delete [POST]
|
||||
func DraftProjectDelete(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req project.DraftProjectDeleteRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.ProjectID <= 0 {
|
||||
invalidParamRequestResponse(c, "invalid project id")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := appApplication.APPApplicationSVC.DraftProjectDelete(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetProjectPublishedConnector .
|
||||
// @router /api/intelligence_api/publish/get_published_connector [POST]
|
||||
func GetProjectPublishedConnector(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req publish.GetProjectPublishedConnectorRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(publish.GetProjectPublishedConnectorResponse)
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// CheckProjectVersionNumber .
|
||||
// @router /api/intelligence_api/publish/check_version_number [POST]
|
||||
func CheckProjectVersionNumber(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req publish.CheckProjectVersionNumberRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.ProjectID <= 0 {
|
||||
invalidParamRequestResponse(c, "invalid project id")
|
||||
return
|
||||
}
|
||||
if req.VersionNumber == "" {
|
||||
invalidParamRequestResponse(c, "invalid version number")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := appApplication.APPApplicationSVC.CheckProjectVersionNumber(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// PublishProject .
|
||||
// @router /api/intelligence_api/publish/publish_project [POST]
|
||||
func PublishProject(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req publish.PublishProjectRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.ProjectID <= 0 {
|
||||
invalidParamRequestResponse(c, "invalid project id")
|
||||
return
|
||||
}
|
||||
if req.VersionNumber == "" {
|
||||
invalidParamRequestResponse(c, "invalid version number")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := appApplication.APPApplicationSVC.PublishAPP(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetPublishRecordList .
|
||||
// @router /api/intelligence_api/publish/publish_record_list [POST]
|
||||
func GetPublishRecordList(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req publish.GetPublishRecordListRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.ProjectID <= 0 {
|
||||
invalidParamRequestResponse(c, "invalid project id")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := appApplication.APPApplicationSVC.GetPublishRecordList(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// ProjectPublishConnectorList .
|
||||
// @router /api/intelligence_api/publish/connector_list [POST]
|
||||
func ProjectPublishConnectorList(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req publish.PublishConnectorListRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.ProjectID <= 0 {
|
||||
invalidParamRequestResponse(c, "invalid project id")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := appApplication.APPApplicationSVC.ProjectPublishConnectorList(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetPublishRecordDetail .
|
||||
// @router /api/intelligence_api/publish/publish_record_detail [POST]
|
||||
func GetPublishRecordDetail(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req publish.GetPublishRecordDetailRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.ProjectID <= 0 {
|
||||
invalidParamRequestResponse(c, "invalid project id")
|
||||
return
|
||||
}
|
||||
if req.PublishRecordID != nil && *req.PublishRecordID <= 0 {
|
||||
invalidParamRequestResponse(c, "invalid publish record id")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := appApplication.APPApplicationSVC.GetPublishRecordDetail(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// DraftProjectInnerTaskList .
|
||||
// @router /api/intelligence_api/draft_project/inner_task_list [POST]
|
||||
func DraftProjectInnerTaskList(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req task.DraftProjectInnerTaskListRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.ProjectID <= 0 {
|
||||
invalidParamRequestResponse(c, "invalid project id")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := appApplication.APPApplicationSVC.DraftProjectInnerTaskList(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// DraftProjectCopy .
|
||||
// @router /api/intelligence_api/draft_project/copy [POST]
|
||||
func DraftProjectCopy(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req project.DraftProjectCopyRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.ProjectID <= 0 {
|
||||
invalidParamRequestResponse(c, "invalid project id")
|
||||
return
|
||||
}
|
||||
if req.ToSpaceID <= 0 {
|
||||
invalidParamRequestResponse(c, "invalid to space id")
|
||||
return
|
||||
}
|
||||
if req.Name == "" || len(req.Name) > 256 {
|
||||
invalidParamRequestResponse(c, "invalid name")
|
||||
return
|
||||
}
|
||||
if req.IconURI == "" || len(req.IconURI) > 512 {
|
||||
invalidParamRequestResponse(c, "invalid icon uri")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := appApplication.APPApplicationSVC.DraftProjectCopy(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
528
backend/api/handler/coze/knowledge_service.go
Normal file
528
backend/api/handler/coze/knowledge_service.go
Normal file
@@ -0,0 +1,528 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by hertz generator.
|
||||
|
||||
package coze
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
||||
|
||||
dataset "github.com/coze-dev/coze-studio/backend/api/model/flow/dataengine/dataset"
|
||||
application "github.com/coze-dev/coze-studio/backend/application/knowledge"
|
||||
"github.com/coze-dev/coze-studio/backend/application/upload"
|
||||
)
|
||||
|
||||
// CreateDataset .
|
||||
// @router /api/knowledge/create [POST]
|
||||
func CreateDataset(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.CreateDatasetRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
resp := new(dataset.CreateDatasetResponse)
|
||||
resp, err = application.KnowledgeSVC.CreateKnowledge(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// DatasetDetail .
|
||||
// @router /api/knowledge/detail [POST]
|
||||
func DatasetDetail(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.DatasetDetailRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
resp := new(dataset.DatasetDetailResponse)
|
||||
resp, err = application.KnowledgeSVC.DatasetDetail(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// ListDataset .
|
||||
// @router /api/knowledge/list [POST]
|
||||
func ListDataset(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.ListDatasetRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(dataset.ListDatasetResponse)
|
||||
resp, err = application.KnowledgeSVC.ListKnowledge(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// DeleteDataset .
|
||||
// @router /api/knowledge/delete [POST]
|
||||
func DeleteDataset(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.DeleteDatasetRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(dataset.DeleteDatasetResponse)
|
||||
resp, err = application.KnowledgeSVC.DeleteKnowledge(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// UpdateDataset .
|
||||
// @router /api/knowledge/update [POST]
|
||||
func UpdateDataset(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.UpdateDatasetRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(dataset.UpdateDatasetResponse)
|
||||
resp, err = application.KnowledgeSVC.UpdateKnowledge(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// CreateDocument .
|
||||
// @router /api/knowledge/document/create [POST]
|
||||
func CreateDocument(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.CreateDocumentRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(dataset.CreateDocumentResponse)
|
||||
resp, err = application.KnowledgeSVC.CreateDocument(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// ListDocument .
|
||||
// @router /api/knowledge/document/list [POST]
|
||||
func ListDocument(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.ListDocumentRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(dataset.ListDocumentResponse)
|
||||
resp, err = application.KnowledgeSVC.ListDocument(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// DeleteDocument .
|
||||
// @router /api/knowledge/document/delete [POST]
|
||||
func DeleteDocument(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.DeleteDocumentRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(dataset.DeleteDocumentResponse)
|
||||
resp, err = application.KnowledgeSVC.DeleteDocument(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// UpdateDocument .
|
||||
// @router /api/knowledge/document/update [POST]
|
||||
func UpdateDocument(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.UpdateDocumentRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(dataset.UpdateDocumentResponse)
|
||||
resp, err = application.KnowledgeSVC.UpdateDocument(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetDocumentProgress .
|
||||
// @router /api/knowledge/document/progress/get [POST]
|
||||
func GetDocumentProgress(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.GetDocumentProgressRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(dataset.GetDocumentProgressResponse)
|
||||
resp, err = application.KnowledgeSVC.GetDocumentProgress(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// Resegment .
|
||||
// @router /api/knowledge/document/resegment [POST]
|
||||
func Resegment(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.ResegmentRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(dataset.ResegmentResponse)
|
||||
resp, err = application.KnowledgeSVC.Resegment(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// UpdatePhotoCaption .
|
||||
// @router /api/knowledge/photo/caption [POST]
|
||||
func UpdatePhotoCaption(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.UpdatePhotoCaptionRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(dataset.UpdatePhotoCaptionResponse)
|
||||
resp, err = application.KnowledgeSVC.UpdatePhotoCaption(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// ListPhoto .
|
||||
// @router /api/knowledge/photo/list [POST]
|
||||
func ListPhoto(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.ListPhotoRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(dataset.ListPhotoResponse)
|
||||
resp, err = application.KnowledgeSVC.ListPhoto(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// PhotoDetail .
|
||||
// @router /api/knowledge/photo/detail [POST]
|
||||
func PhotoDetail(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.PhotoDetailRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(dataset.PhotoDetailResponse)
|
||||
resp, err = application.KnowledgeSVC.PhotoDetail(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetTableSchema .
|
||||
// @router /api/knowledge/table_schema/get [POST]
|
||||
func GetTableSchema(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.GetTableSchemaRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(dataset.GetTableSchemaResponse)
|
||||
resp, err = application.KnowledgeSVC.GetTableSchema(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// ValidateTableSchema .
|
||||
// @router /api/knowledge/table_schema/validate [POST]
|
||||
func ValidateTableSchema(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.ValidateTableSchemaRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(dataset.ValidateTableSchemaResponse)
|
||||
resp, err = application.KnowledgeSVC.ValidateTableSchema(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// DeleteSlice .
|
||||
// @router /api/knowledge/slice/delete [POST]
|
||||
func DeleteSlice(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.DeleteSliceRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(dataset.DeleteSliceResponse)
|
||||
resp, err = application.KnowledgeSVC.DeleteSlice(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// CreateSlice .
|
||||
// @router /api/knowledge/slice/create [POST]
|
||||
func CreateSlice(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.CreateSliceRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(dataset.CreateSliceResponse)
|
||||
resp, err = application.KnowledgeSVC.CreateSlice(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// UpdateSlice .
|
||||
// @router /api/knowledge/slice/update [POST]
|
||||
func UpdateSlice(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.UpdateSliceRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(dataset.UpdateSliceResponse)
|
||||
resp, err = application.KnowledgeSVC.UpdateSlice(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// ListSlice .
|
||||
// @router /api/knowledge/slice/list [POST]
|
||||
func ListSlice(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.ListSliceRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(dataset.ListSliceResponse)
|
||||
resp, err = application.KnowledgeSVC.ListSlice(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// CreateDocumentReview .
|
||||
// @router /api/knowledge/review/create [POST]
|
||||
func CreateDocumentReview(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.CreateDocumentReviewRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(dataset.CreateDocumentReviewResponse)
|
||||
resp, err = application.KnowledgeSVC.CreateDocumentReview(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// MGetDocumentReview .
|
||||
// @router /api/knowledge/review/mget [POST]
|
||||
func MGetDocumentReview(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.MGetDocumentReviewRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(dataset.MGetDocumentReviewResponse)
|
||||
resp, err = application.KnowledgeSVC.MGetDocumentReview(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// SaveDocumentReview .
|
||||
// @router /api/knowledge/review/save [POST]
|
||||
func SaveDocumentReview(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.SaveDocumentReviewRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(dataset.SaveDocumentReviewResponse)
|
||||
resp, err = application.KnowledgeSVC.SaveDocumentReview(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetIconForDataset .
|
||||
// @router /api/knowledge/icon/get [POST]
|
||||
func GetIconForDataset(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.GetIconRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(dataset.GetIconResponse)
|
||||
resp, err = upload.SVC.GetIconForDataset(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// ExtractPhotoCaption .
|
||||
// @router /api/knowledge/photo/extract_caption [POST]
|
||||
func ExtractPhotoCaption(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req dataset.ExtractPhotoCaptionRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(dataset.ExtractPhotoCaptionResponse)
|
||||
resp, err = application.KnowledgeSVC.ExtractPhotoCaption(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
277
backend/api/handler/coze/memory_service.go
Normal file
277
backend/api/handler/coze/memory_service.go
Normal file
@@ -0,0 +1,277 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by hertz generator.
|
||||
|
||||
package coze
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/knowledge/document"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/kvmemory"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/project_memory"
|
||||
table "github.com/coze-dev/coze-studio/backend/api/model/table"
|
||||
appApplication "github.com/coze-dev/coze-studio/backend/application/app"
|
||||
"github.com/coze-dev/coze-studio/backend/application/knowledge"
|
||||
"github.com/coze-dev/coze-studio/backend/application/memory"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/conv"
|
||||
)
|
||||
|
||||
// GetSysVariableConf .
|
||||
// @router /api/memory/sys_variable_conf [GET]
|
||||
func GetSysVariableConf(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req kvmemory.GetSysVariableConfRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := memory.VariableApplicationSVC.GetSysVariableConf(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetProjectVariableList .
|
||||
// @router /api/memory/project/variable/meta_list [GET]
|
||||
func GetProjectVariableList(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req project_memory.GetProjectVariableListReq
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.ProjectID == "" {
|
||||
invalidParamRequestResponse(c, "project_id is empty")
|
||||
return
|
||||
}
|
||||
|
||||
pID, err := conv.StrToInt64(req.ProjectID)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, "project_id is not int")
|
||||
return
|
||||
}
|
||||
|
||||
pInfo, err := appApplication.APPApplicationSVC.DomainSVC.GetDraftAPP(ctx, pID)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := memory.VariableApplicationSVC.GetProjectVariablesMeta(ctx, pInfo.OwnerID, &req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// UpdateProjectVariable .
|
||||
// @router /api/memory/project/variable/meta_update [POST]
|
||||
func UpdateProjectVariable(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req project_memory.UpdateProjectVariableReq
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.ProjectID == "" {
|
||||
invalidParamRequestResponse(c, "project_id is empty")
|
||||
return
|
||||
}
|
||||
|
||||
key2Var := make(map[string]*project_memory.Variable)
|
||||
for _, v := range req.VariableList {
|
||||
if v.Keyword == "" {
|
||||
invalidParamRequestResponse(c, "variable name is empty")
|
||||
return
|
||||
}
|
||||
|
||||
if key2Var[v.Keyword] != nil {
|
||||
invalidParamRequestResponse(c, "variable keyword is duplicate")
|
||||
return
|
||||
}
|
||||
|
||||
key2Var[v.Keyword] = v
|
||||
}
|
||||
|
||||
resp, err := memory.VariableApplicationSVC.UpdateProjectVariable(ctx, req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// SetKvMemory .
|
||||
// @router /api/memory/variable/upsert [POST]
|
||||
func SetKvMemory(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req kvmemory.SetKvMemoryReq
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.BotID == 0 && req.GetProjectID() == "" {
|
||||
invalidParamRequestResponse(c, "bot_id and project_id are both empty")
|
||||
return
|
||||
}
|
||||
|
||||
if len(req.Data) == 0 {
|
||||
invalidParamRequestResponse(c, "data is empty")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := memory.VariableApplicationSVC.SetVariableInstance(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetMemoryVariableMeta .
|
||||
// @router /api/memory/variable/get_meta [POST]
|
||||
func GetMemoryVariableMeta(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req project_memory.GetMemoryVariableMetaReq
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := memory.VariableApplicationSVC.GetVariableMeta(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// DelProfileMemory .
|
||||
// @router /api/memory/variable/delete [POST]
|
||||
func DelProfileMemory(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req kvmemory.DelProfileMemoryRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.BotID == 0 && req.GetProjectID() == "" {
|
||||
invalidParamRequestResponse(c, "bot_id and project_id are both empty")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := memory.VariableApplicationSVC.DeleteVariableInstance(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetPlayGroundMemory .
|
||||
// @router /api/memory/variable/get [POST]
|
||||
func GetPlayGroundMemory(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req kvmemory.GetProfileMemoryRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.BotID == 0 && req.GetProjectID() == "" {
|
||||
invalidParamRequestResponse(c, "bot_id and project_id are both empty")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := memory.VariableApplicationSVC.GetPlayGroundMemory(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetDocumentTableInfo .
|
||||
// @router /api/memory/doc_table_info [GET]
|
||||
func GetDocumentTableInfo(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req document.GetDocumentTableInfoRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(document.GetDocumentTableInfoResponse)
|
||||
resp, err = knowledge.KnowledgeSVC.GetDocumentTableInfo(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetModeConfig .
|
||||
// @router /api/memory/table_mode_config [GET]
|
||||
func GetModeConfig(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req table.GetModeConfigRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.BotID == 0 {
|
||||
invalidParamRequestResponse(c, "bot_id is zero")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := memory.DatabaseApplicationSVC.GetModeConfig(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
150
backend/api/handler/coze/message_service.go
Normal file
150
backend/api/handler/coze/message_service.go
Normal file
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* 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 coze
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/conversation/message"
|
||||
application "github.com/coze-dev/coze-studio/backend/application/conversation"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
||||
"github.com/coze-dev/coze-studio/backend/types/errno"
|
||||
)
|
||||
|
||||
// GetMessageList .
|
||||
// @router /api/conversation/get_message_list [POST]
|
||||
func GetMessageList(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req message.GetMessageListRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if checkErr := checkMLParams(ctx, &req); checkErr != nil {
|
||||
invalidParamRequestResponse(c, checkErr.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := application.ConversationSVC.GetMessageList(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
func checkMLParams(ctx context.Context, req *message.GetMessageListRequest) error {
|
||||
if req.BotID == "" {
|
||||
return errorx.New(errno.ErrConversationInvalidParamCode, errorx.KV("msg", "agent id is required"))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteMessage .
|
||||
// @router /api/conversation/delete_message [POST]
|
||||
func DeleteMessage(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req message.DeleteMessageRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
if checkErr := checkDMParams(ctx, &req); checkErr != nil {
|
||||
invalidParamRequestResponse(c, checkErr.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := application.ConversationSVC.DeleteMessage(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
func checkDMParams(_ context.Context, req *message.DeleteMessageRequest) error {
|
||||
if req.MessageID <= 0 {
|
||||
return errorx.New(errno.ErrConversationInvalidParamCode, errorx.KV("msg", "message id is invalid"))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// BreakMessage .
|
||||
// @router /api/conversation/break_message [POST]
|
||||
func BreakMessage(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req message.BreakMessageRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if checkErr := checkBMParams(ctx, &req); checkErr != nil {
|
||||
invalidParamRequestResponse(c, checkErr.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := application.ConversationSVC.BreakMessage(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
func checkBMParams(_ context.Context, req *message.BreakMessageRequest) error {
|
||||
if req.AnswerMessageID == nil {
|
||||
return errors.New("answer message id is required")
|
||||
}
|
||||
if *req.AnswerMessageID <= 0 {
|
||||
return errorx.New(errno.ErrConversationInvalidParamCode, errorx.KV("msg", "answer message id is invalid"))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetApiMessageList .
|
||||
// @router /v1/conversation/message/list [POST]
|
||||
func GetApiMessageList(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req message.ListMessageApiRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := application.OpenapiMessageApplicationService.GetApiMessageList(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
57
backend/api/handler/coze/message_service_test.go
Normal file
57
backend/api/handler/coze/message_service_test.go
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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 coze
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/cloudwego/hertz/pkg/app/server"
|
||||
"github.com/cloudwego/hertz/pkg/common/ut"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/conversation/common"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/conversation/message"
|
||||
"github.com/coze-dev/coze-studio/backend/application"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
)
|
||||
|
||||
func TestGetMessageList(t *testing.T) {
|
||||
h := server.Default()
|
||||
err := application.Init(context.Background())
|
||||
|
||||
t.Logf("application init err: %v", err)
|
||||
|
||||
h.POST("/api/conversation/get_message_list", GetMessageList)
|
||||
req := &message.GetMessageListRequest{
|
||||
BotID: "7366055842027922437",
|
||||
Scene: ptr.Of(common.Scene_Playground),
|
||||
ConversationID: "7496795464885338112",
|
||||
Count: 10,
|
||||
Cursor: "1746534530268",
|
||||
}
|
||||
m, err := sonic.Marshal(req)
|
||||
assert.Nil(t, err)
|
||||
w := ut.PerformRequest(h.Engine, "POST", "/api/conversation/get_message_list", &ut.Body{Body: bytes.NewBuffer(m), Len: len(m)}, ut.Header{Key: "Content-Type", Value: "application/json"})
|
||||
res := w.Result()
|
||||
t.Logf("get message list: %s", res.Body())
|
||||
|
||||
assert.Equal(t, http.StatusInternalServerError, w.Code)
|
||||
}
|
||||
169
backend/api/handler/coze/open_apiauth_service.go
Normal file
169
backend/api/handler/coze/open_apiauth_service.go
Normal file
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by hertz generator.
|
||||
|
||||
package coze
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/permission/openapiauth"
|
||||
openapiauthApp "github.com/coze-dev/coze-studio/backend/application/openauth"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/logs"
|
||||
"github.com/coze-dev/coze-studio/backend/types/errno"
|
||||
)
|
||||
|
||||
// GetPersonalAccessTokenAndPermission .
|
||||
// @router /api/permission_api/pat/get_personal_access_token_and_permission [GET]
|
||||
func GetPersonalAccessTokenAndPermission(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req openapiauth.GetPersonalAccessTokenAndPermissionRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.ID == 0 {
|
||||
invalidParamRequestResponse(c, "id is required")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := openapiauthApp.OpenAuthApplication.GetPersonalAccessTokenAndPermission(ctx, &req)
|
||||
if err != nil {
|
||||
logs.CtxErrorf(ctx, "OpenAuthApplicationService.GetPersonalAccessTokenAndPermission failed, err=%v", err)
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// DeletePersonalAccessTokenAndPermission .
|
||||
// @router /api/permission_api/pat/delete_personal_access_token_and_permission [POST]
|
||||
func DeletePersonalAccessTokenAndPermission(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req openapiauth.DeletePersonalAccessTokenAndPermissionRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.ID <= 0 {
|
||||
invalidParamRequestResponse(c, "id is required")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := openapiauthApp.OpenAuthApplication.DeletePersonalAccessTokenAndPermission(ctx, &req)
|
||||
if err != nil {
|
||||
logs.CtxErrorf(ctx, "OpenAuthApplication.DeletePersonalAccessTokenAndPermission failed, err=%v", err)
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// ListPersonalAccessTokens .
|
||||
// @router /api/permission_api/pat/list_personal_access_tokens [GET]
|
||||
func ListPersonalAccessTokens(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req openapiauth.ListPersonalAccessTokensRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.Page == nil || *req.Page <= 0 {
|
||||
req.Page = ptr.Of(int64(1))
|
||||
}
|
||||
if req.Size == nil || *req.Size <= 0 {
|
||||
req.Size = ptr.Of(int64(10))
|
||||
}
|
||||
|
||||
resp, err := openapiauthApp.OpenAuthApplication.ListPersonalAccessTokens(ctx, &req)
|
||||
if err != nil {
|
||||
logs.CtxErrorf(ctx, "OpenAuthApplication.ListPersonalAccessTokens failed, err=%v", err)
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// CreatePersonalAccessTokenAndPermission .
|
||||
// @router /api/permission_api/pat/create_personal_access_token_and_permission [POST]
|
||||
func CreatePersonalAccessTokenAndPermission(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req openapiauth.CreatePersonalAccessTokenAndPermissionRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if err = checkCPATParams(ctx, &req); err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := openapiauthApp.OpenAuthApplication.CreatePersonalAccessToken(ctx, &req)
|
||||
if err != nil {
|
||||
logs.CtxErrorf(ctx, "OpenAuthApplicationService.CreatePersonalAccessToken failed, err=%v", err)
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// checkCPATParams 检查创建个人访问令牌的参数
|
||||
func checkCPATParams(ctx context.Context, req *openapiauth.CreatePersonalAccessTokenAndPermissionRequest) error {
|
||||
|
||||
if req.Name == "" {
|
||||
return errorx.New(errno.ErrPermissionInvalidParamCode, errorx.KV("msg", "name is required"))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdatePersonalAccessTokenAndPermission .
|
||||
// @router /api/permission_api/pat/update_personal_access_token_and_permission [POST]
|
||||
func UpdatePersonalAccessTokenAndPermission(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req openapiauth.UpdatePersonalAccessTokenAndPermissionRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := openapiauthApp.OpenAuthApplication.UpdatePersonalAccessTokenAndPermission(ctx, &req)
|
||||
if err != nil {
|
||||
logs.CtxErrorf(ctx, "OpenAuthApplication.UpdatePersonalAccessTokenAndPermission failed, err=%v", err)
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
220
backend/api/handler/coze/passport_service.go
Normal file
220
backend/api/handler/coze/passport_service.go
Normal file
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by hertz generator.
|
||||
|
||||
package coze
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/protocol"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/passport"
|
||||
"github.com/coze-dev/coze-studio/backend/application/user"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/user/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/hertzutil/domain"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/i18n"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/logs"
|
||||
"github.com/coze-dev/coze-studio/backend/types/consts"
|
||||
)
|
||||
|
||||
// PassportWebEmailRegisterV2Post .
|
||||
// @router /passport/web/email/register/v2/ [POST]
|
||||
func PassportWebEmailRegisterV2Post(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req passport.PassportWebEmailRegisterV2PostRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
locale := string(i18n.GetLocale(ctx))
|
||||
|
||||
resp, sessionKey, err := user.UserApplicationSVC.PassportWebEmailRegisterV2(ctx, locale, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.SetCookie(entity.SessionKey,
|
||||
sessionKey,
|
||||
consts.SessionMaxAgeSecond,
|
||||
"/", domain.GetOriginHost(c),
|
||||
protocol.CookieSameSiteDefaultMode,
|
||||
false, true)
|
||||
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// PassportWebLogoutGet .
|
||||
// @router /passport/web/logout/ [GET]
|
||||
func PassportWebLogoutGet(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req passport.PassportWebLogoutGetRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := user.UserApplicationSVC.PassportWebLogoutGet(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// PassportWebEmailLoginPost .
|
||||
// @router /passport/web/email/login/ [POST]
|
||||
func PassportWebEmailLoginPost(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req passport.PassportWebEmailLoginPostRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, sessionKey, err := user.UserApplicationSVC.PassportWebEmailLoginPost(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
logs.Infof("[PassportWebEmailLoginPost] sessionKey: %s", sessionKey)
|
||||
|
||||
c.SetCookie(entity.SessionKey,
|
||||
sessionKey,
|
||||
consts.SessionMaxAgeSecond,
|
||||
"/", domain.GetOriginHost(c),
|
||||
protocol.CookieSameSiteDefaultMode,
|
||||
false, true)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// PassportWebEmailPasswordResetGet .
|
||||
// @router /passport/web/email/password/reset/ [GET]
|
||||
func PassportWebEmailPasswordResetGet(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req passport.PassportWebEmailPasswordResetGetRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := user.UserApplicationSVC.PassportWebEmailPasswordResetGet(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// PassportAccountInfoV2 .
|
||||
// @router /passport/account/info/v2/ [POST]
|
||||
func PassportAccountInfoV2(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req passport.PassportAccountInfoV2Request
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := user.UserApplicationSVC.PassportAccountInfoV2(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// UserUpdateAvatar .
|
||||
// @router web/user/update/upload_avatar/ [POST]
|
||||
func UserUpdateAvatar(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req passport.UserUpdateAvatarRequest
|
||||
|
||||
// 获取上传的文件
|
||||
file, err := c.FormFile("avatar")
|
||||
if err != nil {
|
||||
logs.CtxErrorf(ctx, "Get Avatar Fail failed, err=%v", err)
|
||||
invalidParamRequestResponse(c, "missing avatar file")
|
||||
return
|
||||
}
|
||||
|
||||
// 检查文件类型
|
||||
if !strings.HasPrefix(file.Header.Get("Content-Type"), "image/") {
|
||||
invalidParamRequestResponse(c, "invalid file type, only image allowed")
|
||||
return
|
||||
}
|
||||
|
||||
// 读取文件内容
|
||||
src, err := file.Open()
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
fileContent, err := io.ReadAll(src)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
req.Avatar = fileContent
|
||||
mimeType := file.Header.Get("Content-Type")
|
||||
|
||||
resp, err := user.UserApplicationSVC.UserUpdateAvatar(ctx, mimeType, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// UserUpdateProfile .
|
||||
// @router api/user/update_profile [POST]
|
||||
func UserUpdateProfile(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req passport.UserUpdateProfileRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := user.UserApplicationSVC.UserUpdateProfile(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
413
backend/api/handler/coze/playground_service.go
Normal file
413
backend/api/handler/coze/playground_service.go
Normal file
@@ -0,0 +1,413 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by hertz generator.
|
||||
|
||||
package coze
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/playground"
|
||||
appApplication "github.com/coze-dev/coze-studio/backend/application/app"
|
||||
"github.com/coze-dev/coze-studio/backend/application/prompt"
|
||||
"github.com/coze-dev/coze-studio/backend/application/shortcutcmd"
|
||||
"github.com/coze-dev/coze-studio/backend/application/singleagent"
|
||||
"github.com/coze-dev/coze-studio/backend/application/upload"
|
||||
"github.com/coze-dev/coze-studio/backend/application/user"
|
||||
)
|
||||
|
||||
// UpdateDraftBotInfoAgw .
|
||||
// @router /api/playground_api/draftbot/update_draft_bot_info [POST]
|
||||
func UpdateDraftBotInfoAgw(ctx context.Context, c *app.RequestContext) {
|
||||
var req playground.UpdateDraftBotInfoAgwRequest
|
||||
err := c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.BotInfo == nil {
|
||||
invalidParamRequestResponse(c, "bot info is nil")
|
||||
return
|
||||
}
|
||||
|
||||
if req.BotInfo.BotId == nil {
|
||||
invalidParamRequestResponse(c, "bot id is nil")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := singleagent.SingleAgentSVC.UpdateSingleAgentDraft(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetDraftBotInfoAgw .
|
||||
// @router /api/playground_api/draftbot/get_draft_bot_info [POST]
|
||||
func GetDraftBotInfoAgw(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req playground.GetDraftBotInfoAgwRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.BotID == 0 {
|
||||
invalidParamRequestResponse(c, "bot id is nil")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := singleagent.SingleAgentSVC.GetAgentBotInfo(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetOfficialPromptResourceList .
|
||||
// @router /api/playground_api/get_official_prompt_list [POST]
|
||||
func GetOfficialPromptResourceList(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req playground.GetOfficialPromptResourceListRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := prompt.PromptSVC.GetOfficialPromptResourceList(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetPromptResourceInfo .
|
||||
// @router /api/playground_api/get_prompt_resource_info [GET]
|
||||
func GetPromptResourceInfo(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req playground.GetPromptResourceInfoRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := prompt.PromptSVC.GetPromptResourceInfo(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// UpsertPromptResource .
|
||||
// @router /api/playground_api/upsert_prompt_resource [POST]
|
||||
func UpsertPromptResource(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req playground.UpsertPromptResourceRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.Prompt == nil {
|
||||
invalidParamRequestResponse(c, "prompt is nil")
|
||||
return
|
||||
}
|
||||
|
||||
if req.Prompt.GetSpaceID() <= 0 {
|
||||
invalidParamRequestResponse(c, "space id is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
if len(req.Prompt.GetName()) <= 0 {
|
||||
invalidParamRequestResponse(c, "name is empty")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := prompt.PromptSVC.UpsertPromptResource(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// DeletePromptResource .
|
||||
// @router /api/playground_api/delete_prompt_resource [POST]
|
||||
func DeletePromptResource(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req playground.DeletePromptResourceRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := prompt.PromptSVC.DeletePromptResource(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetSpaceListV2 .
|
||||
// @router /api/playground_api/space/list [POST]
|
||||
func GetSpaceListV2(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req playground.GetSpaceListV2Request
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := user.UserApplicationSVC.GetSpaceListV2(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetImagexShortUrl .
|
||||
// @router /api/playground_api/get_imagex_url [POST]
|
||||
func GetImagexShortUrl(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req playground.GetImagexShortUrlRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if len(req.Uris) == 0 {
|
||||
invalidParamRequestResponse(c, "uris is empty")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := singleagent.SingleAgentSVC.GetImagexShortUrl(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// MGetUserBasicInfo .
|
||||
// @router /api/playground_api/mget_user_info [POST]
|
||||
func MGetUserBasicInfo(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req playground.MGetUserBasicInfoRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := user.UserApplicationSVC.MGetUserBasicInfo(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetBotPopupInfo .
|
||||
// @router /api/playground_api/operate/get_bot_popup_info [POST]
|
||||
func GetBotPopupInfo(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req playground.GetBotPopupInfoRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if len(req.BotPopupTypes) == 0 {
|
||||
invalidParamRequestResponse(c, "bot popup types is empty")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := singleagent.SingleAgentSVC.GetAgentPopupInfo(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// UpdateBotPopupInfo .
|
||||
// @router /api/playground_api/operate/update_bot_popup_info [POST]
|
||||
func UpdateBotPopupInfo(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req playground.UpdateBotPopupInfoRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := singleagent.SingleAgentSVC.UpdateAgentPopupInfo(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// CreateUpdateShortcutCommand .
|
||||
// @router /api/playground_api/create_update_shortcut_command [POST]
|
||||
func CreateUpdateShortcutCommand(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req playground.CreateUpdateShortcutCommandRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
shortCuts, err := shortcutcmd.ShortcutCmdSVC.Handler(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
resp := new(playground.CreateUpdateShortcutCommandResponse)
|
||||
resp.Shortcuts = shortCuts
|
||||
resp.Code = 0
|
||||
resp.Msg = ""
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// ReportUserBehavior .
|
||||
// @router /api/playground_api/report_user_behavior [POST]
|
||||
func ReportUserBehavior(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req playground.ReportUserBehaviorRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.ResourceID <= 0 {
|
||||
invalidParamRequestResponse(c, "resource id is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(playground.ReportUserBehaviorResponse)
|
||||
|
||||
if req.ResourceType == playground.SpaceResourceType_DraftBot {
|
||||
resp, err = singleagent.SingleAgentSVC.ReportUserBehavior(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
} else if req.ResourceType == playground.SpaceResourceType_Project {
|
||||
resp, err = appApplication.APPApplicationSVC.ReportUserBehavior(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetFileUrls .
|
||||
// @router /api/playground_api/get_file_list [POST]
|
||||
func GetFileUrls(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req playground.GetFileUrlsRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
iconList, err := upload.SVC.GetShortcutIcons(ctx)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
resp := new(playground.GetFileUrlsResponse)
|
||||
resp.FileList = iconList
|
||||
resp.Code = 0
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// UploadFileOpen .
|
||||
// @router /v1/files/upload [POST]
|
||||
func UploadFileOpen(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req playground.UploadFileOpenRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(playground.UploadFileOpenResponse)
|
||||
resp, err = upload.SVC.UploadFileOpen(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetBotOnlineInfo .
|
||||
// @router /v1/bot/get_online_info [GET]
|
||||
func GetBotOnlineInfo(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req playground.GetBotOnlineInfoReq
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := singleagent.SingleAgentSVC.GetAgentOnlineInfo(ctx, &req)
|
||||
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
915
backend/api/handler/coze/plugin_develop_service.go
Normal file
915
backend/api/handler/coze/plugin_develop_service.go
Normal file
@@ -0,0 +1,915 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by hertz generator.
|
||||
|
||||
package coze
|
||||
|
||||
import (
|
||||
"context"
|
||||
"regexp"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/plugin_develop"
|
||||
common "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop_common"
|
||||
"github.com/coze-dev/coze-studio/backend/application/plugin"
|
||||
appworkflow "github.com/coze-dev/coze-studio/backend/application/workflow"
|
||||
)
|
||||
|
||||
// GetPlaygroundPluginList .
|
||||
// @router /api/plugin_api/get_playground_plugin_list [POST]
|
||||
func GetPlaygroundPluginList(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.GetPlaygroundPluginListRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.GetSpaceID() <= 0 {
|
||||
invalidParamRequestResponse(c, "spaceID is invalid")
|
||||
return
|
||||
}
|
||||
if req.GetPage() <= 0 {
|
||||
invalidParamRequestResponse(c, "page is invalid")
|
||||
return
|
||||
}
|
||||
if req.GetSize() >= 30 {
|
||||
invalidParamRequestResponse(c, "size is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
// when there is only one element in the types list, and the element type is workflow, use workflow service
|
||||
// TODO Figure out when there are multiple values for types
|
||||
if len(req.GetPluginTypes()) == 1 && req.GetPluginTypes()[0] == int32(common.PluginType_WORKFLOW) {
|
||||
resp, err := appworkflow.SVC.GetPlaygroundPluginList(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.GetPlaygroundPluginList(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// RegisterPluginMeta .
|
||||
// @router /api/plugin_api/register_plugin_meta [POST]
|
||||
func RegisterPluginMeta(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.RegisterPluginMetaRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.GetName() == "" {
|
||||
invalidParamRequestResponse(c, "plugin name is invalid")
|
||||
return
|
||||
}
|
||||
if req.GetDesc() == "" {
|
||||
invalidParamRequestResponse(c, "plugin desc is invalid")
|
||||
return
|
||||
}
|
||||
if req.URL != nil && (*req.URL == "" || len(*req.URL) > 512) {
|
||||
invalidParamRequestResponse(c, "plugin url is invalid")
|
||||
return
|
||||
}
|
||||
if req.Icon == nil || req.Icon.URI == "" || len(req.Icon.URI) > 512 {
|
||||
invalidParamRequestResponse(c, "plugin icon is invalid")
|
||||
return
|
||||
}
|
||||
if req.AuthType == nil {
|
||||
invalidParamRequestResponse(c, "plugin auth type is invalid")
|
||||
return
|
||||
}
|
||||
if req.SpaceID <= 0 {
|
||||
invalidParamRequestResponse(c, "spaceID is invalid")
|
||||
return
|
||||
}
|
||||
if req.ProjectID != nil {
|
||||
if *req.ProjectID <= 0 {
|
||||
invalidParamRequestResponse(c, "projectID is invalid")
|
||||
return
|
||||
}
|
||||
}
|
||||
if req.GetPluginType() != common.PluginType_PLUGIN {
|
||||
invalidParamRequestResponse(c, "plugin type is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.RegisterPluginMeta(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetPluginAPIs .
|
||||
// @router /api/plugin_api/get_plugin_apis [POST]
|
||||
func GetPluginAPIs(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.GetPluginAPIsRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.PluginID <= 0 {
|
||||
invalidParamRequestResponse(c, "pluginID is invalid")
|
||||
return
|
||||
}
|
||||
if len(req.APIIds) == 0 {
|
||||
if req.Page <= 0 {
|
||||
invalidParamRequestResponse(c, "page is invalid")
|
||||
return
|
||||
}
|
||||
if req.Size >= 30 {
|
||||
invalidParamRequestResponse(c, "size is invalid")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.GetPluginAPIs(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetPluginInfo .
|
||||
// @router /api/plugin_api/get_plugin_info [POST]
|
||||
func GetPluginInfo(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.GetPluginInfoRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.PluginID <= 0 {
|
||||
invalidParamRequestResponse(c, "pluginID is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.GetPluginInfo(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetUpdatedAPIs .
|
||||
// @router /api/plugin_api/get_updated_apis [POST]
|
||||
func GetUpdatedAPIs(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.GetUpdatedAPIsRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.PluginID <= 0 {
|
||||
invalidParamRequestResponse(c, "pluginID is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.GetUpdatedAPIs(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetOAuthStatus .
|
||||
// @router /api/plugin_api/get_oauth_status [POST]
|
||||
func GetOAuthStatus(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.GetOAuthStatusRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.PluginID <= 0 {
|
||||
invalidParamRequestResponse(c, "pluginID is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.GetOAuthStatus(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// CheckAndLockPluginEdit .
|
||||
// @router /api/plugin_api/check_and_lock_plugin_edit [POST]
|
||||
func CheckAndLockPluginEdit(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.CheckAndLockPluginEditRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.PluginID <= 0 {
|
||||
invalidParamRequestResponse(c, "pluginID is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.CheckAndLockPluginEdit(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// UpdatePlugin .
|
||||
// @router /api/plugin_api/update [POST]
|
||||
func UpdatePlugin(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.UpdatePluginRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.PluginID <= 0 {
|
||||
invalidParamRequestResponse(c, "pluginID is invalid")
|
||||
return
|
||||
}
|
||||
if req.AiPlugin == "" {
|
||||
invalidParamRequestResponse(c, "plugin manifest is invalid")
|
||||
return
|
||||
}
|
||||
if req.Openapi == "" {
|
||||
invalidParamRequestResponse(c, "plugin openapi doc is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.UpdatePlugin(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// DeleteAPI .
|
||||
// @router /api/plugin_api/delete_api [POST]
|
||||
func DeleteAPI(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.DeleteAPIRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.PluginID <= 0 {
|
||||
invalidParamRequestResponse(c, "pluginID is invalid")
|
||||
return
|
||||
}
|
||||
if req.APIID <= 0 {
|
||||
invalidParamRequestResponse(c, "apiID is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.DeleteAPI(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// DelPlugin .
|
||||
// @router /api/plugin_api/del_plugin [POST]
|
||||
func DelPlugin(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.DelPluginRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.PluginID <= 0 {
|
||||
invalidParamRequestResponse(c, "pluginID is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.DelPlugin(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// PublishPlugin .
|
||||
// @router /api/plugin_api/publish_plugin [POST]
|
||||
func PublishPlugin(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.PublishPluginRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.PluginID <= 0 {
|
||||
invalidParamRequestResponse(c, "pluginID is invalid")
|
||||
return
|
||||
}
|
||||
if req.VersionName == "" || len(req.VersionName) > 255 {
|
||||
invalidParamRequestResponse(c, "version name is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
match, _ := regexp.MatchString(`^v\d+\.\d+\.\d+$`, req.VersionName)
|
||||
if !match {
|
||||
invalidParamRequestResponse(c, "version name is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
if req.VersionDesc == "" {
|
||||
invalidParamRequestResponse(c, "version desc is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.PublishPlugin(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// UpdatePluginMeta .
|
||||
// @router /api/plugin_api/update_plugin_meta [POST]
|
||||
func UpdatePluginMeta(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.UpdatePluginMetaRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.PluginID <= 0 {
|
||||
invalidParamRequestResponse(c, "pluginID is invalid")
|
||||
return
|
||||
}
|
||||
if req.Name != nil && *req.Name == "" {
|
||||
invalidParamRequestResponse(c, "plugin name is invalid")
|
||||
return
|
||||
}
|
||||
if req.Desc != nil && *req.Desc == "" {
|
||||
invalidParamRequestResponse(c, "plugin desc is invalid")
|
||||
return
|
||||
}
|
||||
if req.URL != nil && (*req.URL == "" || len(*req.URL) > 512) {
|
||||
invalidParamRequestResponse(c, "plugin server url is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.UpdatePluginMeta(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetBotDefaultParams .
|
||||
// @router /api/plugin_api/get_bot_default_params [POST]
|
||||
func GetBotDefaultParams(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.GetBotDefaultParamsRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.SpaceID <= 0 {
|
||||
invalidParamRequestResponse(c, "spaceID is invalid")
|
||||
return
|
||||
}
|
||||
if req.BotID <= 0 {
|
||||
invalidParamRequestResponse(c, "botID is invalid")
|
||||
return
|
||||
}
|
||||
if req.PluginID <= 0 {
|
||||
invalidParamRequestResponse(c, "pluginID is invalid")
|
||||
return
|
||||
}
|
||||
if req.APIName == "" {
|
||||
invalidParamRequestResponse(c, "apiName is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.GetBotDefaultParams(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// UpdateBotDefaultParams .
|
||||
// @router /api/plugin_api/update_bot_default_params [POST]
|
||||
func UpdateBotDefaultParams(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.UpdateBotDefaultParamsRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.SpaceID <= 0 {
|
||||
invalidParamRequestResponse(c, "spaceID is invalid")
|
||||
return
|
||||
}
|
||||
if req.BotID <= 0 {
|
||||
invalidParamRequestResponse(c, "botID is invalid")
|
||||
return
|
||||
}
|
||||
if req.PluginID <= 0 {
|
||||
invalidParamRequestResponse(c, "pluginID is invalid")
|
||||
return
|
||||
}
|
||||
if req.APIName == "" {
|
||||
invalidParamRequestResponse(c, "apiName is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.UpdateBotDefaultParams(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// CreateAPI .
|
||||
// @router /api/plugin_api/create_api [POST]
|
||||
func CreateAPI(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.CreateAPIRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.PluginID <= 0 {
|
||||
invalidParamRequestResponse(c, "pluginID is invalid")
|
||||
return
|
||||
}
|
||||
if req.Name == "" || len(req.Name) > 255 {
|
||||
invalidParamRequestResponse(c, "api name is invalid")
|
||||
return
|
||||
}
|
||||
if req.Desc == "" {
|
||||
invalidParamRequestResponse(c, "api desc is invalid")
|
||||
return
|
||||
}
|
||||
if req.Path != nil && (*req.Path == "" || len(*req.Path) > 512) {
|
||||
invalidParamRequestResponse(c, "api path is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.CreateAPI(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// UpdateAPI .
|
||||
// @router /api/plugin_api/update_api [POST]
|
||||
func UpdateAPI(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.UpdateAPIRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.PluginID <= 0 {
|
||||
invalidParamRequestResponse(c, "pluginID is invalid")
|
||||
return
|
||||
}
|
||||
if req.APIID <= 0 {
|
||||
invalidParamRequestResponse(c, "apiID is invalid")
|
||||
return
|
||||
}
|
||||
if req.Name != nil && (*req.Name == "" || len(*req.Name) > 255) {
|
||||
invalidParamRequestResponse(c, "api name is invalid")
|
||||
return
|
||||
}
|
||||
if req.Desc != nil && (*req.Desc == "" || len(*req.Desc) > 255) {
|
||||
invalidParamRequestResponse(c, "api desc is invalid")
|
||||
return
|
||||
}
|
||||
if req.Path != nil && (*req.Path == "" || len(*req.Path) > 512) {
|
||||
invalidParamRequestResponse(c, "api path is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.UpdateAPI(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetUserAuthority .
|
||||
// @router /api/plugin_api/get_user_authority [POST]
|
||||
func GetUserAuthority(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.GetUserAuthorityRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.PluginID <= 0 {
|
||||
invalidParamRequestResponse(c, "pluginID is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.GetUserAuthority(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// DebugAPI .
|
||||
// @router /api/plugin_api/debug_api [POST]
|
||||
func DebugAPI(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.DebugAPIRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.PluginID <= 0 {
|
||||
invalidParamRequestResponse(c, "pluginID is invalid")
|
||||
return
|
||||
}
|
||||
if req.APIID <= 0 {
|
||||
invalidParamRequestResponse(c, "apiID is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.DebugAPI(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// UnlockPluginEdit .
|
||||
// @router /api/plugin_api/unlock_plugin_edit [POST]
|
||||
func UnlockPluginEdit(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.UnlockPluginEditRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.UnlockPluginEdit(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetPluginNextVersion .
|
||||
// @router /api/plugin_api/get_plugin_next_version [POST]
|
||||
func GetPluginNextVersion(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.GetPluginNextVersionRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.GetPluginNextVersion(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// RegisterPlugin .
|
||||
// @router /api/developer/register [POST]
|
||||
func RegisterPlugin(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.RegisterPluginRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.GetSpaceID() <= 0 {
|
||||
invalidParamRequestResponse(c, "spaceID is invalid")
|
||||
return
|
||||
}
|
||||
if req.ProjectID != nil && *req.ProjectID <= 0 {
|
||||
invalidParamRequestResponse(c, "projectID is invalid")
|
||||
return
|
||||
}
|
||||
if req.AiPlugin == "" {
|
||||
invalidParamRequestResponse(c, "plugin manifest is invalid")
|
||||
return
|
||||
}
|
||||
if req.Openapi == "" {
|
||||
invalidParamRequestResponse(c, "plugin openapi doc is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.RegisterPlugin(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetDevPluginList .
|
||||
// @router /api/plugin_api/get_dev_plugin_list [POST]
|
||||
func GetDevPluginList(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.GetDevPluginListRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.SpaceID <= 0 {
|
||||
invalidParamRequestResponse(c, "spaceID is invalid")
|
||||
return
|
||||
}
|
||||
if req.ProjectID <= 0 {
|
||||
invalidParamRequestResponse(c, "projectID is invalid")
|
||||
return
|
||||
}
|
||||
if req.GetPage() <= 0 {
|
||||
invalidParamRequestResponse(c, "page is invalid")
|
||||
return
|
||||
}
|
||||
if req.GetSize() <= 0 {
|
||||
invalidParamRequestResponse(c, "size is invalid")
|
||||
return
|
||||
}
|
||||
if req.GetSize() > 50 {
|
||||
invalidParamRequestResponse(c, "size is too large")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.GetDevPluginList(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// Convert2OpenAPI .
|
||||
// @router /api/plugin_api/convert_to_openapi [POST]
|
||||
func Convert2OpenAPI(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.Convert2OpenAPIRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.SpaceID <= 0 {
|
||||
invalidParamRequestResponse(c, "spaceID is invalid")
|
||||
return
|
||||
}
|
||||
if req.Data == "" {
|
||||
invalidParamRequestResponse(c, "data is invalid")
|
||||
return
|
||||
}
|
||||
if req.PluginURL != nil && *req.PluginURL == "" {
|
||||
invalidParamRequestResponse(c, "pluginURL is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.Convert2OpenAPI(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetOAuthSchemaAPI .
|
||||
// @router /api/plugin_api/get_oauth_schema [POST]
|
||||
func GetOAuthSchemaAPI(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.GetOAuthSchemaRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.GetOAuthSchema(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetOAuthSchema .
|
||||
// @router /api/plugin/get_oauth_schema [POST]
|
||||
func GetOAuthSchema(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.GetOAuthSchemaRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.GetOAuthSchema(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// BatchCreateAPI .
|
||||
// @router /api/plugin_api/batch_create_api [POST]
|
||||
func BatchCreateAPI(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.BatchCreateAPIRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.SpaceID <= 0 {
|
||||
invalidParamRequestResponse(c, "spaceID is invalid")
|
||||
return
|
||||
}
|
||||
if req.PluginID <= 0 {
|
||||
invalidParamRequestResponse(c, "pluginID is invalid")
|
||||
return
|
||||
}
|
||||
if req.AiPlugin == "" {
|
||||
invalidParamRequestResponse(c, "plugin manifest is invalid")
|
||||
return
|
||||
}
|
||||
if req.Openapi == "" {
|
||||
invalidParamRequestResponse(c, "plugin openapi doc is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.BatchCreateAPI(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// RevokeAuthToken .
|
||||
// @router /api/plugin_api/revoke_auth_token [POST]
|
||||
func RevokeAuthToken(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.RevokeAuthTokenRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.PluginID <= 0 {
|
||||
invalidParamRequestResponse(c, "pluginID is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.RevokeAuthToken(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetQueriedOAuthPluginList .
|
||||
// @router /api/plugin_api/get_queried_oauth_plugins [POST]
|
||||
func GetQueriedOAuthPluginList(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req plugin_develop.GetQueriedOAuthPluginListRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.BotID <= 0 {
|
||||
invalidParamRequestResponse(c, "entityID is required")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.GetQueriedOAuthPluginList(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
269
backend/api/handler/coze/public_product_service.go
Normal file
269
backend/api/handler/coze/public_product_service.go
Normal file
@@ -0,0 +1,269 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by hertz generator.
|
||||
|
||||
package coze
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/workflow"
|
||||
appworkflow "github.com/coze-dev/coze-studio/backend/application/workflow"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/developer_api"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/flow/marketplace/product_common"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/flow/marketplace/product_public_api"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/bot_common"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/playground"
|
||||
appApplication "github.com/coze-dev/coze-studio/backend/application/app"
|
||||
"github.com/coze-dev/coze-studio/backend/application/modelmgr"
|
||||
"github.com/coze-dev/coze-studio/backend/application/plugin"
|
||||
"github.com/coze-dev/coze-studio/backend/application/search"
|
||||
"github.com/coze-dev/coze-studio/backend/application/singleagent"
|
||||
"github.com/coze-dev/coze-studio/backend/application/template"
|
||||
)
|
||||
|
||||
// PublicGetProductList .
|
||||
// @router /api/marketplace/product/list [GET]
|
||||
func PublicGetProductList(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req product_public_api.GetProductListRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var resp *product_public_api.GetProductListResponse
|
||||
switch req.GetEntityType() {
|
||||
case product_common.ProductEntityType_Plugin:
|
||||
resp, err = plugin.PluginApplicationSVC.PublicGetProductList(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
case product_common.ProductEntityType_TemplateCommon:
|
||||
resp, err = template.ApplicationSVC.PublicGetProductList(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// PublicGetProductDetail .
|
||||
// @router /api/marketplace/product/detail [GET]
|
||||
func PublicGetProductDetail(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req product_public_api.GetProductDetailRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.GetProductID() <= 0 {
|
||||
invalidParamRequestResponse(c, "productID is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := plugin.PluginApplicationSVC.PublicGetProductDetail(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// PublicFavoriteProduct .
|
||||
// @router /api/marketplace/product/favorite [POST]
|
||||
func PublicFavoriteProduct(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req product_public_api.FavoriteProductRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.GetEntityID() <= 0 {
|
||||
invalidParamRequestResponse(c, "entityID is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
// check entity id is valid
|
||||
if req.GetEntityType() == product_common.ProductEntityType_Bot {
|
||||
_, err = singleagent.SingleAgentSVC.ValidateAgentDraftAccess(ctx, req.GetEntityID())
|
||||
} else if req.GetEntityType() == product_common.ProductEntityType_Project {
|
||||
_, err = appApplication.APPApplicationSVC.ValidateDraftAPPAccess(ctx, req.GetEntityID())
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := search.SearchSVC.PublicFavoriteProduct(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// PublicGetUserFavoriteListV2 .
|
||||
// @router /api/marketplace/product/favorite/list.v2 [GET]
|
||||
func PublicGetUserFavoriteListV2(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req product_public_api.GetUserFavoriteListV2Request
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.GetPageSize() <= 0 {
|
||||
invalidParamRequestResponse(c, "pageSize is invalid")
|
||||
return
|
||||
}
|
||||
if req.GetEntityType() <= 0 {
|
||||
invalidParamRequestResponse(c, "entityType is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := search.SearchSVC.PublicGetUserFavoriteList(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// PublicDuplicateProduct .
|
||||
// @router /api/marketplace/product/duplicate [POST]
|
||||
func PublicDuplicateProduct(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req product_public_api.DuplicateProductRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(product_public_api.DuplicateProductResponse)
|
||||
resp.Data = new(product_public_api.DuplicateProductData)
|
||||
|
||||
switch req.GetEntityType() {
|
||||
case product_common.ProductEntityType_BotTemplate:
|
||||
modelListResp, err := modelmgr.ModelmgrApplicationSVC.GetModelList(ctx, &developer_api.GetTypeListRequest{})
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
if modelListResp == nil || modelListResp.Data == nil || len(modelListResp.Data.ModelList) == 0 {
|
||||
invalidParamRequestResponse(c, "no model found")
|
||||
return
|
||||
}
|
||||
|
||||
bot, err := singleagent.SingleAgentSVC.DuplicateDraftBot(ctx, &developer_api.DuplicateDraftBotRequest{
|
||||
BotID: req.GetProductID(),
|
||||
SpaceID: req.GetSpaceID(),
|
||||
})
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
botInfo, err := singleagent.SingleAgentSVC.GetAgentBotInfo(ctx, &playground.GetDraftBotInfoAgwRequest{
|
||||
BotID: bot.Data.BotID,
|
||||
})
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
if botInfo.Data == nil || botInfo.Data.BotInfo == nil {
|
||||
invalidParamRequestResponse(c, "no bot info found")
|
||||
return
|
||||
}
|
||||
|
||||
modelInfo := botInfo.GetData().GetBotInfo().GetModelInfo()
|
||||
if modelInfo == nil {
|
||||
invalidParamRequestResponse(c, "no model info found in agent")
|
||||
return
|
||||
}
|
||||
modelInfo.ModelId = &modelListResp.Data.ModelList[0].ModelType
|
||||
|
||||
if req.Name != nil {
|
||||
_, err = singleagent.SingleAgentSVC.UpdateSingleAgentDraft(ctx, &playground.UpdateDraftBotInfoAgwRequest{
|
||||
BotInfo: &bot_common.BotInfoForUpdate{
|
||||
BotId: &bot.Data.BotID,
|
||||
Name: req.Name,
|
||||
ModelInfo: modelInfo,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
resp.Data.NewEntityID = bot.Data.BotID
|
||||
|
||||
case product_common.ProductEntityType_WorkflowTemplateV2:
|
||||
workflowResp, err := appworkflow.SVC.CopyWorkflow(ctx, &workflow.CopyWorkflowRequest{
|
||||
WorkflowID: strconv.FormatInt(req.GetProductID(), 10),
|
||||
SpaceID: strconv.FormatInt(req.GetSpaceID(), 10),
|
||||
})
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
newWorkflowID, err := strconv.ParseInt(workflowResp.Data.WorkflowID, 10, 64)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
resp.Data.NewEntityID = newWorkflowID
|
||||
resp.Data.NewPluginID = &newWorkflowID
|
||||
|
||||
if req.Name != nil {
|
||||
_, err = appworkflow.SVC.UpdateWorkflowMeta(ctx, &workflow.UpdateWorkflowMetaRequest{
|
||||
WorkflowID: workflowResp.Data.WorkflowID,
|
||||
SpaceID: strconv.FormatInt(req.GetSpaceID(), 10),
|
||||
Name: req.Name,
|
||||
})
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
179
backend/api/handler/coze/resource_service.go
Normal file
179
backend/api/handler/coze/resource_service.go
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by hertz generator.
|
||||
|
||||
package coze
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
||||
|
||||
appApplication "github.com/coze-dev/coze-studio/backend/application/app"
|
||||
|
||||
resource "github.com/coze-dev/coze-studio/backend/api/model/resource"
|
||||
"github.com/coze-dev/coze-studio/backend/application/search"
|
||||
)
|
||||
|
||||
// LibraryResourceList .
|
||||
// @router /api/plugin_api/library_resource_list [POST]
|
||||
func LibraryResourceList(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req resource.LibraryResourceListRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.SpaceID <= 0 {
|
||||
invalidParamRequestResponse(c, "space_id is invalid")
|
||||
return
|
||||
}
|
||||
if req.GetSize() > 100 {
|
||||
invalidParamRequestResponse(c, "size is too large")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := search.SearchSVC.LibraryResourceList(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// ProjectResourceList .
|
||||
// @router /api/plugin_api/project_resource_list [POST]
|
||||
func ProjectResourceList(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req resource.ProjectResourceListRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.SpaceID <= 0 {
|
||||
invalidParamRequestResponse(c, "space_id is invalid")
|
||||
return
|
||||
}
|
||||
if req.ProjectID <= 0 {
|
||||
invalidParamRequestResponse(c, "project_id is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := search.SearchSVC.ProjectResourceList(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// ResourceCopyDispatch .
|
||||
// @router /api/plugin_api/resource_copy_dispatch [POST]
|
||||
func ResourceCopyDispatch(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req resource.ResourceCopyDispatchRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.ResID <= 0 {
|
||||
invalidParamRequestResponse(c, "res_id is invalid")
|
||||
return
|
||||
}
|
||||
if req.ResType <= 0 {
|
||||
invalidParamRequestResponse(c, "res_type is invalid")
|
||||
return
|
||||
}
|
||||
if req.GetProjectID() <= 0 {
|
||||
invalidParamRequestResponse(c, "project_id is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := appApplication.APPApplicationSVC.ResourceCopyDispatch(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// ResourceCopyDetail .
|
||||
// @router /api/plugin_api/resource_copy_detail [POST]
|
||||
func ResourceCopyDetail(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req resource.ResourceCopyDetailRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.TaskID == "" {
|
||||
invalidParamRequestResponse(c, "task_id is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := appApplication.APPApplicationSVC.ResourceCopyDetail(ctx, &req)
|
||||
if err != nil {
|
||||
internalServerErrorResponse(ctx, c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// ResourceCopyRetry .
|
||||
// @router /api/plugin_api/resource_copy_retry [POST]
|
||||
func ResourceCopyRetry(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req resource.ResourceCopyRetryRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
invalidParamRequestResponse(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(resource.ResourceCopyRetryResponse)
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// ResourceCopyCancel .
|
||||
// @router /api/plugin_api/resource_copy_cancel [POST]
|
||||
func ResourceCopyCancel(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req resource.ResourceCopyCancelRequest
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
c.String(consts.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp := new(resource.ResourceCopyCancelResponse)
|
||||
|
||||
c.JSON(consts.StatusOK, resp)
|
||||
}
|
||||
1130
backend/api/handler/coze/workflow_service.go
Normal file
1130
backend/api/handler/coze/workflow_service.go
Normal file
File diff suppressed because it is too large
Load Diff
4619
backend/api/handler/coze/workflow_service_test.go
Normal file
4619
backend/api/handler/coze/workflow_service_test.go
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user