Skip to content

Commit 9a57e94

Browse files
authored
4.8.10 test (#2601)
* perf: workflow children run params * feat: workflow userId * fix: ui size * perf: Markdown whitespace and ai images split * fix: openai sdk ts
1 parent 761e35c commit 9a57e94

File tree

43 files changed

+319
-289
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+319
-289
lines changed

packages/global/core/chat/adapt.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,23 @@ export const GPTMessages2Chats = (
151151
obj === ChatRoleEnum.System &&
152152
item.role === ChatCompletionRequestMessageRoleEnum.System
153153
) {
154-
value.push({
155-
type: ChatItemValueTypeEnum.text,
156-
text: {
157-
content: item.content
158-
}
159-
});
154+
if (Array.isArray(item.content)) {
155+
item.content.forEach((item) => [
156+
value.push({
157+
type: ChatItemValueTypeEnum.text,
158+
text: {
159+
content: item.text
160+
}
161+
})
162+
]);
163+
} else {
164+
value.push({
165+
type: ChatItemValueTypeEnum.text,
166+
text: {
167+
content: item.content
168+
}
169+
});
170+
}
160171
} else if (
161172
obj === ChatRoleEnum.Human &&
162173
item.role === ChatCompletionRequestMessageRoleEnum.User

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,15 @@ export type ChatDispatchProps = {
2626
res?: NextApiResponse;
2727
requestOrigin?: string;
2828
mode: 'test' | 'chat' | 'debug';
29-
teamId: string; // App teamId
30-
tmbId: string; // App tmbId
3129
user: UserModelSchema;
32-
app: AppDetailType | AppSchema;
30+
31+
runningAppInfo: {
32+
id: string; // May be the id of the system plug-in (cannot be used directly to look up the table)
33+
teamId: string;
34+
tmbId: string; // App tmbId
35+
};
36+
uid: string; // Who run this workflow
37+
3338
chatId?: string;
3439
responseChatItemId?: string;
3540
histories: ChatItemType[];
@@ -50,10 +55,12 @@ export type ModuleDispatchProps<T> = ChatDispatchProps & {
5055
};
5156

5257
export type SystemVariablesType = {
58+
userId: string;
5359
appId: string;
5460
chatId?: string;
5561
responseChatItemId?: string;
5662
histories: ChatItemType[];
63+
cTime: string;
5764
};
5865

5966
/* node props */
@@ -69,7 +76,7 @@ export type RuntimeNodeItemType = {
6976
inputs: FlowNodeInputItemType[];
7077
outputs: FlowNodeOutputItemType[];
7178

72-
pluginId?: string;
79+
pluginId?: string; // workflow id / plugin id
7380
};
7481

7582
export type PluginRuntimeType = {

packages/global/core/workflow/template/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { RunAppModule } from './system/abandoned/runApp/index';
1717
import { PluginInputModule } from './system/pluginInput';
1818
import { PluginOutputModule } from './system/pluginOutput';
1919
import { RunPluginModule } from './system/runPlugin';
20-
import { RunAppPluginModule } from './system/runAppPlugin';
20+
import { RunAppNode } from './system/runApp';
2121
import { AiQueryExtension } from './system/queryExtension';
2222

2323
import type { FlowNodeTemplateType } from '../type/node';
@@ -73,6 +73,6 @@ export const moduleTemplatesFlat: FlowNodeTemplateType[] = [
7373
),
7474
EmptyNode,
7575
RunPluginModule,
76-
RunAppPluginModule,
76+
RunAppNode,
7777
RunAppModule
7878
];

packages/global/core/workflow/template/system/runAppPlugin.ts renamed to packages/global/core/workflow/template/system/runApp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { FlowNodeTypeEnum } from '../../node/constant';
33
import { FlowNodeTemplateType } from '../../type/node';
44
import { getHandleConfig } from '../utils';
55

6-
export const RunAppPluginModule: FlowNodeTemplateType = {
6+
export const RunAppNode: FlowNodeTemplateType = {
77
id: FlowNodeTypeEnum.appModule,
88
templateType: FlowNodeTemplateTypeEnum.other,
99
flowNodeType: FlowNodeTypeEnum.appModule,

packages/global/core/workflow/utils.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -326,27 +326,6 @@ export const updatePluginInputByVariables = (
326326
);
327327
};
328328

329-
/* Remove pluginInput variables from global variables
330-
(completions api: Plugin input get value from global variables)
331-
*/
332-
export const removePluginInputVariables = (
333-
variables: Record<string, any>,
334-
nodes: RuntimeNodeItemType[]
335-
) => {
336-
const pluginInputNode = nodes.find((node) => node.flowNodeType === FlowNodeTypeEnum.pluginInput);
337-
338-
if (!pluginInputNode) return variables;
339-
return Object.keys(variables).reduce(
340-
(acc, key) => {
341-
if (!pluginInputNode.inputs.find((input) => input.key === key)) {
342-
acc[key] = variables[key];
343-
}
344-
return acc;
345-
},
346-
{} as Record<string, any>
347-
);
348-
};
349-
350329
// replace {{$xx.xx$}} variables for text
351330
export function replaceEditorVariable({
352331
text,

packages/global/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"jschardet": "3.1.1",
1212
"nanoid": "^4.0.1",
1313
"next": "14.2.5",
14-
"openai": "4.53.0",
14+
"openai": "4.57.0",
1515
"openapi-types": "^12.1.3",
1616
"timezones-list": "^3.0.2"
1717
},

packages/service/core/chat/utils.ts

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -121,46 +121,22 @@ export const loadRequestMessages = async ({
121121
const imageRegex =
122122
/(https?:\/\/[^\s/$.?#].[^\s]*\.(?:png|jpe?g|gif|webp|bmp|tiff?|svg|ico|heic|avif))/i;
123123

124-
const result: { type: 'text' | 'image'; value: string }[] = [];
125-
let lastIndex = 0;
126-
let match;
127-
128-
// 使用正则表达式查找所有匹配项
129-
while ((match = imageRegex.exec(input.slice(lastIndex))) !== null) {
130-
const textBefore = input.slice(lastIndex, lastIndex + match.index);
131-
132-
// 如果图片URL前有文本,添加文本部分
133-
if (textBefore) {
134-
result.push({ type: 'text', value: textBefore });
135-
}
136-
137-
// 添加图片URL
138-
result.push({ type: 'image', value: match[0] });
139-
140-
lastIndex += match.index + match[0].length;
141-
}
142-
143-
// 添加剩余的文本(如果有的话)
144-
if (lastIndex < input.length) {
145-
result.push({ type: 'text', value: input.slice(lastIndex) });
146-
}
147-
148-
return result
149-
.map((item) => {
150-
if (item.type === 'text') {
151-
return { type: 'text', text: item.value };
152-
}
153-
if (item.type === 'image') {
154-
return {
155-
type: 'image_url',
156-
image_url: {
157-
url: item.value
158-
}
159-
};
124+
const result: ChatCompletionContentPart[] = [];
125+
126+
// 提取所有HTTPS图片URL并添加到result开头
127+
const httpsImages = input.match(imageRegex) || [];
128+
httpsImages.forEach((url) => {
129+
result.push({
130+
type: 'image_url',
131+
image_url: {
132+
url: url
160133
}
161-
return { type: 'text', text: item.value };
162-
})
163-
.filter(Boolean) as ChatCompletionContentPart[];
134+
});
135+
});
136+
137+
// 添加原始input作为文本
138+
result.push({ type: 'text', text: input });
139+
return result;
164140
}
165141
// Load image
166142
const parseUserContent = async (content: string | ChatCompletionContentPart[]) => {

packages/service/core/workflow/dispatch/abandoned/runApp.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type Response = DispatchNodeResultType<{
3131

3232
export const dispatchAppRequest = async (props: Props): Promise<Response> => {
3333
const {
34-
app: workflowApp,
34+
runningAppInfo,
3535
workflowStreamResponse,
3636
histories,
3737
query,
@@ -45,7 +45,7 @@ export const dispatchAppRequest = async (props: Props): Promise<Response> => {
4545
// 检查该工作流的tmb是否有调用该app的权限(不是校验对话的人,是否有权限)
4646
const { app: appData } = await authAppByTmbId({
4747
appId: app.id,
48-
tmbId: workflowApp.tmbId,
48+
tmbId: runningAppInfo.tmbId,
4949
per: ReadPermissionVal
5050
});
5151

@@ -61,7 +61,11 @@ export const dispatchAppRequest = async (props: Props): Promise<Response> => {
6161

6262
const { flowResponses, flowUsages, assistantResponses } = await dispatchWorkFlow({
6363
...props,
64-
app: appData,
64+
runningAppInfo: {
65+
id: String(appData._id),
66+
teamId: String(appData.teamId),
67+
tmbId: String(appData.tmbId)
68+
},
6569
runtimeNodes: storeNodes2RuntimeNodes(
6670
appData.modules,
6771
getWorkflowEntryNodeIds(appData.modules)

packages/service/core/workflow/dispatch/dataset/search.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export async function dispatchDatasetSearch(
3737
props: DatasetSearchProps
3838
): Promise<DatasetSearchResponse> {
3939
const {
40-
teamId,
40+
runningAppInfo: { teamId },
4141
histories,
4242
node,
4343
params: {

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
import { NodeOutputKeyEnum } from '@fastgpt/global/core/workflow/constants';
77
import type {
88
ChatDispatchProps,
9-
ModuleDispatchProps
9+
ModuleDispatchProps,
10+
SystemVariablesType
1011
} from '@fastgpt/global/core/workflow/runtime/type';
1112
import type { RuntimeNodeItemType } from '@fastgpt/global/core/workflow/runtime/type.d';
1213
import type {
@@ -554,13 +555,15 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons
554555
/* get system variable */
555556
export function getSystemVariable({
556557
user,
557-
app,
558+
runningAppInfo,
558559
chatId,
559560
responseChatItemId,
560-
histories = []
561-
}: Props) {
561+
histories = [],
562+
uid
563+
}: Props): SystemVariablesType {
562564
return {
563-
appId: String(app._id),
565+
userId: uid,
566+
appId: String(runningAppInfo.id),
564567
chatId,
565568
responseChatItemId,
566569
histories,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type UserSelectResponse = DispatchNodeResultType<{
2929
export const dispatchUserSelect = async (props: Props): Promise<UserSelectResponse> => {
3030
const {
3131
workflowStreamResponse,
32-
app: { _id: appId },
32+
runningAppInfo: { id: appId },
3333
chatId,
3434
node: { nodeId, isEntry },
3535
params: { description, userSelectOptions },

packages/service/core/workflow/dispatch/plugin/run.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { authPluginByTmbId } from '../../../../support/permission/app/auth';
1313
import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
1414
import { computedPluginUsage } from '../../../app/plugin/utils';
1515
import { filterSystemVariables } from '../utils';
16+
import { getPluginRunUserQuery } from '../../utils';
1617

1718
type RunPluginProps = ModuleDispatchProps<{
1819
[key: string]: any;
@@ -22,9 +23,8 @@ type RunPluginResponse = DispatchNodeResultType<{}>;
2223
export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPluginResponse> => {
2324
const {
2425
node: { pluginId },
25-
app: workflowApp,
26+
runningAppInfo,
2627
mode,
27-
teamId,
2828
params: data // Plugin input
2929
} = props;
3030

@@ -33,9 +33,9 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi
3333
}
3434

3535
// auth plugin
36-
await authPluginByTmbId({
36+
const pluginData = await authPluginByTmbId({
3737
appId: pluginId,
38-
tmbId: workflowApp.tmbId,
38+
tmbId: runningAppInfo.tmbId,
3939
per: ReadPermissionVal
4040
});
4141

@@ -61,14 +61,21 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi
6161
showStatus: false
6262
};
6363
});
64+
const runtimeVariables = {
65+
...filterSystemVariables(props.variables),
66+
appId: String(plugin.id)
67+
};
6468

6569
const { flowResponses, flowUsages, assistantResponses } = await dispatchWorkFlow({
6670
...props,
67-
68-
variables: {
69-
...filterSystemVariables(props.variables),
70-
appId: String(plugin.id)
71+
runningAppInfo: {
72+
id: String(plugin.id),
73+
teamId: plugin.teamId || '',
74+
tmbId: pluginData?.tmbId || ''
7175
},
76+
variables: runtimeVariables,
77+
query: getPluginRunUserQuery(plugin.nodes, runtimeVariables).value,
78+
chatConfig: {},
7279
runtimeNodes,
7380
runtimeEdges: initWorkflowEdgeStatus(plugin.edges)
7481
});
@@ -90,7 +97,7 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi
9097
totalPoints: usagePoints,
9198
pluginOutput: output?.pluginOutput,
9299
pluginDetail:
93-
mode === 'test' && plugin.teamId === teamId
100+
mode === 'test' && plugin.teamId === runningAppInfo.teamId
94101
? flowResponses.filter((item) => {
95102
const filterArr = [FlowNodeTypeEnum.pluginOutput];
96103
return !filterArr.includes(item.moduleType as any);

0 commit comments

Comments
 (0)