fix: replace hardcoded DebugURLTpl in Workflow with a configurable value (#2388)

This commit is contained in:
Ryo
2025-10-25 13:49:11 +08:00
committed by GitHub
parent 7adc079622
commit 2369deb1aa
7 changed files with 76 additions and 1187 deletions

File diff suppressed because it is too large Load Diff

View File

@ -31,6 +31,7 @@ import (
"github.com/coze-dev/coze-studio/backend/api/model/workflow"
"github.com/coze-dev/coze-studio/backend/application/base/ctxutil"
"github.com/coze-dev/coze-studio/backend/bizpkg/debugutil"
crossagentrun "github.com/coze-dev/coze-studio/backend/crossdomain/agentrun"
crossconversation "github.com/coze-dev/coze-studio/backend/crossdomain/conversation"
crossmessage "github.com/coze-dev/coze-studio/backend/crossdomain/message"
@ -831,7 +832,7 @@ func (w *ApplicationService) convertToChatFlowRunResponseList(ctx context.Contex
}
doneData, err := sonic.MarshalString(map[string]interface{}{
"debug_url": fmt.Sprintf(workflowModel.DebugURLTpl, executeID, spaceID, workflowID),
"debug_url": debugutil.GetWorkflowDebugURL(ctx, workflowID, spaceID, executeID),
})
if err != nil {
return nil, err
@ -976,7 +977,7 @@ func (w *ApplicationService) convertToChatFlowRunResponseList(ctx context.Contex
})
doneData, _ := sonic.MarshalString(map[string]interface{}{
"debug_url": fmt.Sprintf(workflowModel.DebugURLTpl, executeID, spaceID, workflowID),
"debug_url": debugutil.GetWorkflowDebugURL(ctx, workflowID, spaceID, executeID),
})
responses = append(responses, &workflow.ChatFlowRunResponse{

View File

@ -42,6 +42,7 @@ import (
appmemory "github.com/coze-dev/coze-studio/backend/application/memory"
appplugin "github.com/coze-dev/coze-studio/backend/application/plugin"
"github.com/coze-dev/coze-studio/backend/application/user"
"github.com/coze-dev/coze-studio/backend/bizpkg/debugutil"
crossknowledge "github.com/coze-dev/coze-studio/backend/crossdomain/knowledge"
model "github.com/coze-dev/coze-studio/backend/crossdomain/knowledge/model"
pluginConsts "github.com/coze-dev/coze-studio/backend/crossdomain/plugin/consts"
@ -1394,6 +1395,7 @@ func convertStreamRunEvent(workflowID int64) func(msg *entity.Message) (res *wor
}
}()
ctx := context.Background()
if msg.StateMessage != nil {
// stream run will skip all messages from workflow tools
if executeID > 0 && executeID != msg.StateMessage.ExecuteID {
@ -1405,7 +1407,7 @@ func convertStreamRunEvent(workflowID int64) func(msg *entity.Message) (res *wor
return &workflow.OpenAPIStreamRunFlowResponse{
ID: strconv.Itoa(messageID),
Event: string(DoneEvent),
DebugUrl: ptr.Of(fmt.Sprintf(workflowModel.DebugURLTpl, executeID, spaceID, workflowID)),
DebugUrl: ptr.Of(debugutil.GetWorkflowDebugURL(ctx, workflowID, spaceID, executeID)),
}, nil
case entity.WorkflowFailed, entity.WorkflowCancel:
var wfe vo.WorkflowError
@ -1415,7 +1417,7 @@ func convertStreamRunEvent(workflowID int64) func(msg *entity.Message) (res *wor
return &workflow.OpenAPIStreamRunFlowResponse{
ID: strconv.Itoa(messageID),
Event: string(ErrEvent),
DebugUrl: ptr.Of(fmt.Sprintf(workflowModel.DebugURLTpl, executeID, spaceID, workflowID)),
DebugUrl: ptr.Of(debugutil.GetWorkflowDebugURL(ctx, workflowID, spaceID, executeID)),
ErrorCode: ptr.Of(int64(wfe.Code())),
ErrorMessage: ptr.Of(wfe.Msg()),
}, nil
@ -1424,7 +1426,7 @@ func convertStreamRunEvent(workflowID int64) func(msg *entity.Message) (res *wor
return &workflow.OpenAPIStreamRunFlowResponse{
ID: strconv.Itoa(messageID),
Event: string(InterruptEvent),
DebugUrl: ptr.Of(fmt.Sprintf(workflowModel.DebugURLTpl, executeID, spaceID, workflowID)),
DebugUrl: ptr.Of(debugutil.GetWorkflowDebugURL(ctx, workflowID, spaceID, executeID)),
InterruptData: &workflow.Interrupt{
EventID: fmt.Sprintf("%d/%d", executeID, msg.InterruptEvent.ID),
Type: workflow.InterruptType(msg.InterruptEvent.EventType),
@ -1436,7 +1438,7 @@ func convertStreamRunEvent(workflowID int64) func(msg *entity.Message) (res *wor
return &workflow.OpenAPIStreamRunFlowResponse{
ID: strconv.Itoa(messageID),
Event: string(InterruptEvent),
DebugUrl: ptr.Of(fmt.Sprintf(workflowModel.DebugURLTpl, executeID, spaceID, workflowID)),
DebugUrl: ptr.Of(debugutil.GetWorkflowDebugURL(ctx, workflowID, spaceID, executeID)),
InterruptData: &workflow.Interrupt{
EventID: fmt.Sprintf("%d/%d", executeID, msg.InterruptEvent.ID),
Type: workflow.InterruptType(msg.InterruptEvent.ToolInterruptEvent.EventType),
@ -1729,7 +1731,7 @@ func (w *ApplicationService) OpenAPIRun(ctx context.Context, req *workflow.OpenA
return &workflow.OpenAPIRunFlowResponse{
ExecuteID: ptr.Of(strconv.FormatInt(exeID, 10)),
DebugUrl: ptr.Of(fmt.Sprintf(workflowModel.DebugURLTpl, exeID, meta.SpaceID, meta.ID)),
DebugUrl: ptr.Of(debugutil.GetWorkflowDebugURL(ctx, meta.ID, meta.SpaceID, exeID)),
}, nil
}
@ -1765,7 +1767,7 @@ func (w *ApplicationService) OpenAPIRun(ctx context.Context, req *workflow.OpenA
return &workflow.OpenAPIRunFlowResponse{
Data: data,
ExecuteID: ptr.Of(strconv.FormatInt(wfExe.ID, 10)),
DebugUrl: ptr.Of(fmt.Sprintf(workflowModel.DebugURLTpl, wfExe.ID, wfExe.SpaceID, meta.ID)),
DebugUrl: ptr.Of(debugutil.GetWorkflowDebugURL(ctx, meta.ID, wfExe.SpaceID, wfExe.ID)),
Token: ptr.Of(wfExe.TokenInfo.InputTokens + wfExe.TokenInfo.OutputTokens),
Cost: ptr.Of("0.00000"),
}, nil
@ -1826,7 +1828,7 @@ func (w *ApplicationService) OpenAPIGetWorkflowRunHistory(ctx context.Context, r
LogID: ptr.Of(exe.LogID),
CreateTime: ptr.Of(exe.CreatedAt.Unix()),
UpdateTime: updateTime,
DebugUrl: ptr.Of(fmt.Sprintf(workflowModel.DebugURLTpl, exe.ID, exe.SpaceID, exe.WorkflowID)),
DebugUrl: ptr.Of(debugutil.GetWorkflowDebugURL(ctx, exe.WorkflowID, exe.SpaceID, exe.ID)),
Input: exe.Input,
Output: exe.Output,
Token: ptr.Of(exe.TokenInfo.InputTokens + exe.TokenInfo.OutputTokens),

View File

@ -106,7 +106,7 @@ func (c *BaseConfig) GetServerHost(ctx context.Context) (string, error) {
host := cfg.ServerHost
if host == "" {
return "", errors.New("server host is empty")
return "http://127.0.0.1:8888", nil
}
if strings.HasPrefix(host, "http://") || strings.HasPrefix(host, "https://") {

View File

@ -0,0 +1,58 @@
/*
* 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 debugutil
import (
"context"
"fmt"
"net/url"
"strconv"
"github.com/coze-dev/coze-studio/backend/bizpkg/config"
"github.com/coze-dev/coze-studio/backend/pkg/logs"
)
func GetWorkflowDebugURL(ctx context.Context, workflowID, spaceID, executeID int64) string {
defaultURL := fmt.Sprintf("http://127.0.0.1:8888/work_flow?execute_id=%d&space_id=%d&workflow_id=%d&execute_mode=2", executeID, spaceID, workflowID)
serverHost, err := config.Base().GetServerHost(ctx)
if err != nil {
logs.CtxErrorf(ctx, "[GetWorkflowDebugURL] get base config failed, use default debug url instead, err: %v", err)
return defaultURL
}
workFlowURL, err := url.JoinPath(serverHost, "work_flow")
if err != nil {
logs.CtxErrorf(ctx, "[GetWorkflowDebugURL] join path failed, use default debug url instead, err: %v", err)
return defaultURL
}
u, err := url.Parse(workFlowURL)
if err != nil {
logs.CtxErrorf(ctx, "[GetWorkflowDebugURL] parse workflow url failed, use default debug url instead, err: %v", err)
return defaultURL
}
q := u.Query()
q.Set("execute_id", strconv.FormatInt(executeID, 10))
q.Set("space_id", strconv.FormatInt(spaceID, 10))
q.Set("workflow_id", strconv.FormatInt(workflowID, 10))
q.Set("execute_mode", "2")
u.RawQuery = q.Encode()
return u.String()
}

View File

@ -84,8 +84,6 @@ const (
SyncPatternStream SyncPattern = "stream"
)
var DebugURLTpl = "http://127.0.0.1:3000/work_flow?execute_id=%d&space_id=%d&workflow_id=%d&execute_mode=2"
type BizType string
const (

View File

@ -17,13 +17,14 @@
package vo
import (
"context"
"errors"
"fmt"
"github.com/cloudwego/eino/compose"
"github.com/cloudwego/eino/schema"
workflowModel "github.com/coze-dev/coze-studio/backend/crossdomain/workflow/model"
"github.com/coze-dev/coze-studio/backend/bizpkg/debugutil"
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
"github.com/coze-dev/coze-studio/backend/pkg/sonic"
"github.com/coze-dev/coze-studio/backend/types/errno"
@ -99,7 +100,7 @@ type wfErr struct {
func (w *wfErr) DebugURL() string {
if w.StatusError.Extra() == nil {
return fmt.Sprintf(workflowModel.DebugURLTpl, w.exeID, w.spaceID, w.workflowID)
return debugutil.GetWorkflowDebugURL(context.Background(), w.workflowID, w.spaceID, w.exeID)
}
debugURL, ok := w.StatusError.Extra()["debug_url"]
@ -107,7 +108,7 @@ func (w *wfErr) DebugURL() string {
return debugURL
}
return fmt.Sprintf(workflowModel.DebugURLTpl, w.exeID, w.spaceID, w.workflowID)
return debugutil.GetWorkflowDebugURL(context.Background(), w.workflowID, w.spaceID, w.exeID)
}
func (w *wfErr) Level() ErrorLevel {
@ -176,7 +177,7 @@ func WrapError(code int, err error, opts ...errorx.Option) WorkflowError {
}
func WrapWithDebug(code int, err error, exeID, spaceID, workflowID int64, opts ...errorx.Option) WorkflowError {
debugURL := fmt.Sprintf(workflowModel.DebugURLTpl, exeID, spaceID, workflowID)
debugURL := debugutil.GetWorkflowDebugURL(context.Background(), workflowID, spaceID, exeID)
opts = append(opts, errorx.Extra("debug_url", debugURL))
return WrapError(code, err, opts...)
}