Skip to content

Commit 0ed99d8

Browse files
c121914yusd0ric4
andauthored
Check debug (#4384)
* feat : Added support for interactive nodes in the debugging interface (#4339) * feat: add VSCode launch configuration and enhance debug API handler * feat: refactor debug API handler to streamline workflow processing and enhance interactive chat features * feat: enhance debug API handler with structured input forms and improved query handling * feat: enhance debug API handler to support optional query and histories parameters * feat: simplify query and histories initialization in debug API handler * feat: add realmode parameter to workflow dispatch and update interactive handling * feat: add optional query parameter to PostWorkflowDebugProps and remove realmode from ModuleDispatchProps * feat: add history parameter to PostWorkflowDebugProps and update related components * feat: remove realmode * feat: simplify handler parameter destructuring in debug.ts * feat: remove unused interactive prop from WholeResponseContent component * feat: refactor onNextNodeDebug to use parameter object for better readability * feat: Merge selections and next actions to remove unused state management * feat: 添加 NodeDebugResponse 组件以增强调试功能 * feat: Simplify the import statements in InteractiveComponents.tsx * feat: Update the handler function to use default parameters to simplify the code * feat: Add optional workflowInteractiveResponse field to PostWorkflowDebugResponse type * feat: Add the workflowInteractiveResponse field in the debugging handler to enhance response capabilities * feat: Added workflowInteractiveResponse field in FlowNodeItemType to enhance responsiveness * feat: Refactor NodeDebugResponse to utilize workflowInteractiveResponse for improved interactivity * feat: Extend UserSelectInteractive and UserInputInteractive types to inherit from InteractiveBasicType * feat: Refactor NodeDebugResponse to streamline interactive handling and improve code clarity * feat: 重构交互式调试逻辑,创建共用 Hook 以简化用户选择和输入处理 * fix: type error * feat: 重构 AIResponseBox 组件,简化用户交互逻辑并引入共用表单组件 * feat: 清理 AIResponseBox 和表单组件代码,移除冗余注释和未使用的导入 * fix: type error * feat: 重构 AIResponseBox 组件,简化类型定义并优化代码结构 * refactor: 将 FormItem 接口更改为类型定义,优化代码结构 * refactor: 将 NodeDebugResponseProps 接口更改为类型定义,优化代码结构 * refactor: 移除不必要的入口节点检查,简化调试处理逻辑 * feat: 移动调试交互组件位置 * refactor: 将 InteractiveBasicType 中的属性设为可选,简化数据结构 * refactor: 优化类型定义 * refactor: 移除未使用的 ChatItemType 和 UserChatItemValueItemType 导入 * refactor: 将接口定义更改为类型别名,简化代码结构 * refactor: 更新类型定义,使用类型别名简化代码结构 * refactor: 使用类型导入简化代码结构,重构 AIResponseBox 组件 * refactor: 提取描述框和表单项标签组件,简化代码结构 * refactor: 移除多余的空行 * refactor: 移除多余的空行和注释 * refactor: 移除多余的空行,简化 AIResponseBox 组件代码 * refactor: 重构组件,移动 FormComponents 到 InteractiveComponents,简化代码结构 * refactor: 移除多余的空行,简化 NodeDebugResponse 组件代码 * refactor: 更新导入语句,使用 type 关键字优化类型导入 * refactor: 在 tsconfig.json 中启用 verbatimModuleSyntax 选项 * Revert "refactor: 在 tsconfig.json 中启用 verbatimModuleSyntax 选项" This reverts commit 2b335a9. * revert: rendertool * refactor: Remove unused imports and functions to simplify code * perf: debug interactive --------- Co-authored-by: Theresa <[email protected]>
1 parent 2d3ae7f commit 0ed99d8

File tree

16 files changed

+788
-499
lines changed

16 files changed

+788
-499
lines changed

.vscode/launch.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Next.js: debug server-side",
6+
"type": "node-terminal",
7+
"request": "launch",
8+
"command": "pnpm run dev",
9+
"cwd": "${workspaceFolder}/projects/app"
10+
},
11+
{
12+
"name": "Next.js: debug client-side",
13+
"type": "chrome",
14+
"request": "launch",
15+
"url": "http://localhost:3000"
16+
},
17+
{
18+
"name": "Next.js: debug client-side (Edge)",
19+
"type": "msedge",
20+
"request": "launch",
21+
"url": "http://localhost:3000"
22+
},
23+
{
24+
"name": "Next.js: debug full stack",
25+
"type": "node-terminal",
26+
"request": "launch",
27+
"command": "pnpm run dev",
28+
"cwd": "${workspaceFolder}/projects/app",
29+
"skipFiles": ["<node_internals>/**"],
30+
"serverReadyAction": {
31+
"action": "debugWithEdge",
32+
"killOnServerStop": true,
33+
"pattern": "- Local:.+(https?://.+)",
34+
"uriFormat": "%s",
35+
"webRoot": "${workspaceFolder}/projects/app"
36+
}
37+
}
38+
]
39+
}

packages/global/core/workflow/runtime/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { FlowNodeOutputItemType, ReferenceValueType } from '../type/io';
1010
import { ChatItemType, NodeOutputItemType } from '../../../core/chat/type';
1111
import { ChatItemValueTypeEnum, ChatRoleEnum } from '../../../core/chat/constants';
1212
import { replaceVariable, valToStr } from '../../../common/string/tools';
13-
import { ChatCompletionChunk } from 'openai/resources';
1413

1514
export const getMaxHistoryLimitFromNodes = (nodes: StoreNodeItemType[]): number => {
1615
let limit = 10;

packages/global/core/workflow/template/system/interactive/type.d.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,36 @@ import { FlowNodeInputTypeEnum } from 'core/workflow/node/constant';
55
import { WorkflowIOValueTypeEnum } from 'core/workflow/constants';
66
import type { ChatCompletionMessageParam } from '../../../../ai/type';
77

8+
type InteractiveBasicType = {
9+
entryNodeIds: string[];
10+
memoryEdges: RuntimeEdgeItemType[];
11+
nodeOutputs: NodeOutputItemType[];
12+
13+
toolParams?: {
14+
entryNodeIds: string[]; // 记录工具中,交互节点的 Id,而不是起始工作流的入口
15+
memoryMessages: ChatCompletionMessageParam[]; // 这轮工具中,产生的新的 messages
16+
toolCallId: string; // 记录对应 tool 的id,用于后续交互节点可以替换掉 tool 的 response
17+
};
18+
};
19+
20+
type InteractiveNodeType = {
21+
entryNodeIds?: string[];
22+
memoryEdges?: RuntimeEdgeItemType[];
23+
nodeOutputs?: NodeOutputItemType[];
24+
};
25+
826
export type UserSelectOptionItemType = {
927
key: string;
1028
value: string;
1129
};
30+
type UserSelectInteractive = InteractiveNodeType & {
31+
type: 'userSelect';
32+
params: {
33+
description: string;
34+
userSelectOptions: UserSelectOptionItemType[];
35+
userSelectedVal?: string;
36+
};
37+
};
1238

1339
export type UserInputFormItemType = {
1440
type: FlowNodeInputTypeEnum;
@@ -28,36 +54,13 @@ export type UserInputFormItemType = {
2854
// select
2955
list?: { label: string; value: string }[];
3056
};
31-
32-
type InteractiveBasicType = {
33-
entryNodeIds: string[];
34-
memoryEdges: RuntimeEdgeItemType[];
35-
nodeOutputs: NodeOutputItemType[];
36-
37-
toolParams?: {
38-
entryNodeIds: string[]; // 记录工具中,交互节点的 Id,而不是起始工作流的入口
39-
memoryMessages: ChatCompletionMessageParam[]; // 这轮工具中,产生的新的 messages
40-
toolCallId: string; // 记录对应 tool 的id,用于后续交互节点可以替换掉 tool 的 response
41-
};
42-
};
43-
44-
type UserSelectInteractive = {
45-
type: 'userSelect';
46-
params: {
47-
description: string;
48-
userSelectOptions: UserSelectOptionItemType[];
49-
userSelectedVal?: string;
50-
};
51-
};
52-
53-
type UserInputInteractive = {
57+
type UserInputInteractive = InteractiveNodeType & {
5458
type: 'userInput';
5559
params: {
5660
description: string;
5761
inputForm: UserInputFormItemType[];
5862
submitted?: boolean;
5963
};
6064
};
61-
6265
export type InteractiveNodeResponseType = UserSelectInteractive | UserInputInteractive;
6366
export type WorkflowInteractiveResponseType = InteractiveBasicType & InteractiveNodeResponseType;

packages/global/core/workflow/type/node.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { NextApiResponse } from 'next';
2323
import { AppDetailType, AppSchema } from '../../app/type';
2424
import { ParentIdType } from 'common/parentFolder/type';
2525
import { AppTypeEnum } from 'core/app/constants';
26+
import { WorkflowInteractiveResponseType } from '../template/system/interactive/type';
2627

2728
export type FlowNodeCommonType = {
2829
parentNodeId?: string;
@@ -120,6 +121,7 @@ export type FlowNodeItemType = FlowNodeTemplateType & {
120121
showResult?: boolean; // show and hide result modal
121122
response?: ChatHistoryItemResType;
122123
isExpired?: boolean;
124+
workflowInteractiveResponse?: WorkflowInteractiveResponseType;
123125
};
124126
isFolded?: boolean;
125127
};

packages/service/core/workflow/dispatch/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ import {
4444
textAdaptGptResponse,
4545
replaceEditorVariable
4646
} from '@fastgpt/global/core/workflow/runtime/utils';
47-
import { ChatNodeUsageType } from '@fastgpt/global/support/wallet/bill/type';
47+
import type { ChatNodeUsageType } from '@fastgpt/global/support/wallet/bill/type';
4848
import { dispatchRunTools } from './agent/runTool/index';
4949
import { ChatItemValueTypeEnum } from '@fastgpt/global/core/chat/constants';
50-
import { DispatchFlowResponse } from './type';
50+
import type { DispatchFlowResponse } from './type';
5151
import { dispatchStopToolCall } from './agent/runTool/stopTool';
5252
import { dispatchLafRequest } from './tools/runLaf';
5353
import { dispatchIfElse } from './tools/runIfElse';
54-
import { RuntimeEdgeItemType } from '@fastgpt/global/core/workflow/type/edge';
54+
import type { RuntimeEdgeItemType } from '@fastgpt/global/core/workflow/type/edge';
5555
import { getReferenceVariableValue } from '@fastgpt/global/core/workflow/runtime/utils';
5656
import { dispatchSystemConfig } from './init/systemConfig';
5757
import { dispatchUpdateVariable } from './tools/runUpdateVar';
@@ -62,7 +62,7 @@ import { dispatchTextEditor } from './tools/textEditor';
6262
import { dispatchCustomFeedback } from './tools/customFeedback';
6363
import { dispatchReadFiles } from './tools/readFiles';
6464
import { dispatchUserSelect } from './interactive/userSelect';
65-
import {
65+
import type {
6666
WorkflowInteractiveResponseType,
6767
InteractiveNodeResponseType
6868
} from '@fastgpt/global/core/workflow/template/system/interactive/type';
@@ -451,6 +451,11 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons
451451
const interactiveResponse = nodeRunResult.result?.[DispatchNodeResponseKeyEnum.interactive];
452452
if (interactiveResponse) {
453453
pushStore(nodeRunResult.node, nodeRunResult.result);
454+
455+
if (props.mode === 'debug') {
456+
debugNextStepRunNodes = debugNextStepRunNodes.concat([nodeRunResult.node]);
457+
}
458+
454459
nodeInteractiveResponse = {
455460
entryNodeIds: [nodeRunResult.node.nodeId],
456461
interactiveResponse

packages/service/core/workflow/dispatch/interactive/formInput.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { chatValue2RuntimePrompt } from '@fastgpt/global/core/chat/adapt';
22
import { NodeInputKeyEnum, NodeOutputKeyEnum } from '@fastgpt/global/core/workflow/constants';
33
import { DispatchNodeResponseKeyEnum } from '@fastgpt/global/core/workflow/runtime/constants';
4-
import {
4+
import type {
55
DispatchNodeResultType,
66
ModuleDispatchProps
77
} from '@fastgpt/global/core/workflow/runtime/type';
8-
import {
8+
import type {
99
UserInputFormItemType,
1010
UserInputInteractive
1111
} from '@fastgpt/global/core/workflow/template/system/interactive/type';
@@ -32,7 +32,6 @@ export const dispatchFormInput = async (props: Props): Promise<FormInputResponse
3232
query
3333
} = props;
3434
const { isEntry } = node;
35-
3635
const interactive = getLastInteractiveValue(histories);
3736

3837
// Interactive node is not the entry node, return interactive result

packages/service/core/workflow/dispatch/interactive/userSelect.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DispatchNodeResponseKeyEnum } from '@fastgpt/global/core/workflow/runtime/constants';
2-
import {
2+
import type {
33
DispatchNodeResultType,
44
ModuleDispatchProps
55
} from '@fastgpt/global/core/workflow/runtime/type';
@@ -30,7 +30,6 @@ export const dispatchUserSelect = async (props: Props): Promise<UserSelectRespon
3030
query
3131
} = props;
3232
const { nodeId, isEntry } = node;
33-
3433
const interactive = getLastInteractiveValue(histories);
3534

3635
// Interactive node is not the entry node, return interactive result

packages/service/core/workflow/dispatch/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export const getHistories = (history?: ChatItemType[] | number, histories: ChatI
106106
/* value type format */
107107
export const valueTypeFormat = (value: any, type?: WorkflowIOValueTypeEnum) => {
108108
if (value === undefined) return;
109-
if (!type) return value;
109+
if (!type || type === WorkflowIOValueTypeEnum.any) return value;
110110

111111
if (type === 'string') {
112112
if (typeof value !== 'object') return String(value);
@@ -118,7 +118,7 @@ export const valueTypeFormat = (value: any, type?: WorkflowIOValueTypeEnum) => {
118118
return Boolean(value);
119119
}
120120
try {
121-
if (WorkflowIOValueTypeEnum.arrayString && typeof value === 'string') {
121+
if (type === WorkflowIOValueTypeEnum.arrayString && typeof value === 'string') {
122122
return [value];
123123
}
124124
if (

0 commit comments

Comments
 (0)