@nocobase/portal-template-default 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.MD +10 -5
- package/package.json +1 -1
- package/registry/nocobase-ai/components/chat/chat-message.tsx +8 -6
- package/registry/nocobase-ai/components/chat/chat-messages.tsx +8 -3
- package/registry/nocobase-ai/components/chat/markdown-message.tsx +26 -0
- package/registry/nocobase-ai/components/chat/sub-agent-conversation.tsx +3 -3
- package/registry/nocobase-ai/demo/configuration-gate.tsx +83 -35
- package/registry/nocobase-i18n/README.md +23 -32
- package/registry/nocobase-i18n/components/language-switcher.tsx +1 -1
- package/registry/nocobase-i18n/demo/index.tsx +2 -2
- package/registry/nocobase-i18n/demo/prompt-generator.tsx +3 -2
- package/registry/nocobase-i18n/extension.tsx +3 -4
- package/registry/nocobase-i18n/index.ts +4 -3
- package/registry/nocobase-i18n/locales/en-US.ts +2 -52
- package/registry/nocobase-i18n/locales/index.ts +8 -0
- package/registry/nocobase-i18n/locales/zh-CN.ts +2 -52
- package/registry/nocobase-i18n/provider.tsx +18 -6
- package/registry/nocobase-i18n/server-resources.ts +13 -31
- package/registry/nocobase-i18n/tests/i18n-regression.mjs +14 -5
- package/registry/nocobase-route-surfaces/README.md +21 -0
- package/registry/nocobase-route-surfaces/demo/index.tsx +266 -0
- package/{src/extensions/nocobase-acl → registry/nocobase-route-surfaces}/demo/lazy-route.tsx +2 -1
- package/registry/nocobase-route-surfaces/demo/prompt-generator.tsx +90 -0
- package/registry/nocobase-route-surfaces/demo/scenarios.ts +95 -0
- package/registry/nocobase-route-surfaces/extension.tsx +119 -0
- package/registry/nocobase-route-surfaces/index.ts +7 -0
- package/registry/nocobase-route-surfaces/route-dialog.tsx +145 -0
- package/registry/nocobase-route-surfaces/route-drawer.tsx +186 -0
- package/registry/nocobase-route-surfaces/route-page.tsx +29 -0
- package/registry/nocobase-route-surfaces/route-surface-context.ts +13 -0
- package/registry/nocobase-route-surfaces/use-refine-unsaved-changes.tsx +106 -0
- package/registry/nocobase-route-surfaces/use-route-surface-close.ts +15 -0
- package/registry/nocobase-route-surfaces/use-route-surface-state.ts +65 -0
- package/registry.config.json +30 -3
- package/scripts/registry.mjs +0 -2
- package/src/App.tsx +65 -35
- package/src/app/extension.ts +1 -2
- package/src/app/extensions.tsx +0 -14
- package/src/components/app-shell/breadcrumb.tsx +67 -2
- package/src/components/app-shell/sidebar.tsx +2 -2
- package/src/components/resources/views/list-view.tsx +3 -2
- package/src/components/ui/sheet.tsx +22 -21
- package/src/lib/nocobase/client.ts +6 -1
- package/src/locales/en-US.ts +81 -0
- package/src/locales/zh-CN.ts +77 -0
- package/src/pages/users/create.tsx +76 -53
- package/src/pages/users/edit.tsx +87 -56
- package/src/pages/users/index.ts +3 -0
- package/src/pages/users/layout.tsx +15 -0
- package/src/pages/users/list.tsx +19 -21
- package/src/pages/users/role-badges.tsx +43 -0
- package/src/pages/users/role-detail.tsx +272 -0
- package/src/pages/users/role-utils.ts +6 -0
- package/src/pages/users/routes.ts +24 -0
- package/src/pages/users/show.tsx +195 -104
- package/src/pages/users/types.ts +13 -0
- package/src/providers/i18n/index.ts +3 -0
- package/{registry/nocobase-i18n → src/providers/i18n}/runtime.ts +63 -16
- package/src/providers/system-settings/context.ts +26 -0
- package/src/providers/system-settings/index.ts +2 -0
- package/src/providers/system-settings/provider.tsx +94 -0
- package/src/extensions/nocobase-acl/README.md +0 -19
- package/src/extensions/nocobase-acl/components/acl-boundary.tsx +0 -106
- package/src/extensions/nocobase-acl/components/index.ts +0 -3
- package/src/extensions/nocobase-acl/components/role-options.ts +0 -36
- package/src/extensions/nocobase-acl/components/role-switcher.tsx +0 -135
- package/src/extensions/nocobase-acl/demo/boundary-api.tsx +0 -186
- package/src/extensions/nocobase-acl/demo/components.tsx +0 -231
- package/src/extensions/nocobase-acl/demo/index.tsx +0 -505
- package/src/extensions/nocobase-acl/demo/prompt-generator.tsx +0 -134
- package/src/extensions/nocobase-acl/demo/role-switcher-prompt-generator.tsx +0 -198
- package/src/extensions/nocobase-acl/demo/scenario-section.tsx +0 -37
- package/src/extensions/nocobase-acl/extension.tsx +0 -71
- package/src/extensions/nocobase-acl/index.ts +0 -1
- package/src/extensions/nocobase-ai/README.md +0 -70
- package/src/extensions/nocobase-ai/adapters/react-hook-form.ts +0 -20
- package/src/extensions/nocobase-ai/assets/nocobase-ai-chat.svg +0 -50
- package/src/extensions/nocobase-ai/components/ai-root-provider.tsx +0 -32
- package/src/extensions/nocobase-ai/components/chat/ai-employee-avatar.tsx +0 -31
- package/src/extensions/nocobase-ai/components/chat/chat-attachment.tsx +0 -92
- package/src/extensions/nocobase-ai/components/chat/chat-compact.tsx +0 -90
- package/src/extensions/nocobase-ai/components/chat/chat-composer.tsx +0 -429
- package/src/extensions/nocobase-ai/components/chat/chat-empty-state.tsx +0 -51
- package/src/extensions/nocobase-ai/components/chat/chat-header.tsx +0 -88
- package/src/extensions/nocobase-ai/components/chat/chat-history-dialog.tsx +0 -77
- package/src/extensions/nocobase-ai/components/chat/chat-message.tsx +0 -252
- package/src/extensions/nocobase-ai/components/chat/chat-messages.tsx +0 -173
- package/src/extensions/nocobase-ai/components/chat/chat-window.tsx +0 -118
- package/src/extensions/nocobase-ai/components/chat/conversation-list.tsx +0 -343
- package/src/extensions/nocobase-ai/components/chat/markdown-message.tsx +0 -165
- package/src/extensions/nocobase-ai/components/chat/model-select-options.tsx +0 -30
- package/src/extensions/nocobase-ai/components/chat/reasoning-panel.tsx +0 -29
- package/src/extensions/nocobase-ai/components/chat/sub-agent-conversation.tsx +0 -142
- package/src/extensions/nocobase-ai/components/chat/tool-call-card.tsx +0 -316
- package/src/extensions/nocobase-ai/components/chat/user-prompt-editor.tsx +0 -99
- package/src/extensions/nocobase-ai/components/chat/work-context-chip.tsx +0 -114
- package/src/extensions/nocobase-ai/components/index.ts +0 -59
- package/src/extensions/nocobase-ai/components/page-elements/ai-form.tsx +0 -44
- package/src/extensions/nocobase-ai/components/page-elements/page-element-provider.tsx +0 -469
- package/src/extensions/nocobase-ai/components/surfaces/chat-dialog.tsx +0 -31
- package/src/extensions/nocobase-ai/components/surfaces/chat-inline.tsx +0 -18
- package/src/extensions/nocobase-ai/components/surfaces/chat-page.tsx +0 -18
- package/src/extensions/nocobase-ai/components/surfaces/chat-side-panel-layout.tsx +0 -54
- package/src/extensions/nocobase-ai/components/surfaces/chat-side-panel.tsx +0 -74
- package/src/extensions/nocobase-ai/components/surfaces/chat-surface-actions.tsx +0 -54
- package/src/extensions/nocobase-ai/components/tools/builtin-tool-renderers.tsx +0 -31
- package/src/extensions/nocobase-ai/components/tools/business-report-dialog.tsx +0 -364
- package/src/extensions/nocobase-ai/components/tools/business-report-renderer.tsx +0 -122
- package/src/extensions/nocobase-ai/components/tools/business-report-utils.tsx +0 -282
- package/src/extensions/nocobase-ai/components/tools/chart-renderer.tsx +0 -99
- package/src/extensions/nocobase-ai/components/tools/echarts-preview.tsx +0 -59
- package/src/extensions/nocobase-ai/components/tools/echarts-runtime-advanced.ts +0 -18
- package/src/extensions/nocobase-ai/components/tools/echarts-runtime-common.ts +0 -20
- package/src/extensions/nocobase-ai/components/tools/echarts-runtime-components.ts +0 -34
- package/src/extensions/nocobase-ai/components/tools/echarts-runtime-hierarchy.ts +0 -24
- package/src/extensions/nocobase-ai/components/tools/echarts-runtime.ts +0 -138
- package/src/extensions/nocobase-ai/components/tools/sub-agent-renderer.tsx +0 -67
- package/src/extensions/nocobase-ai/components/tools/suggestions-renderer.tsx +0 -59
- package/src/extensions/nocobase-ai/components/tools/tool-renderer-provider.tsx +0 -55
- package/src/extensions/nocobase-ai/components/tools/tool-renderer-utils.ts +0 -18
- package/src/extensions/nocobase-ai/components/tools/workflow-renderer.tsx +0 -108
- package/src/extensions/nocobase-ai/components/triggers/ai-chat-floating-trigger.tsx +0 -73
- package/src/extensions/nocobase-ai/components/triggers/ai-employee-shortcut.tsx +0 -149
- package/src/extensions/nocobase-ai/demo/configuration-gate.tsx +0 -49
- package/src/extensions/nocobase-ai/demo/container-showcase.tsx +0 -210
- package/src/extensions/nocobase-ai/demo/floating.tsx +0 -134
- package/src/extensions/nocobase-ai/demo/index.tsx +0 -346
- package/src/extensions/nocobase-ai/demo/interaction-showcase.tsx +0 -151
- package/src/extensions/nocobase-ai/demo/page-context-prompt-generator.tsx +0 -355
- package/src/extensions/nocobase-ai/demo/page-context.tsx +0 -884
- package/src/extensions/nocobase-ai/demo/page-element-showcase.tsx +0 -197
- package/src/extensions/nocobase-ai/demo/prompt-card.tsx +0 -41
- package/src/extensions/nocobase-ai/demo/prompt-generator.tsx +0 -452
- package/src/extensions/nocobase-ai/demo/shortcut.tsx +0 -1207
- package/src/extensions/nocobase-ai/demo/tool-cards.tsx +0 -530
- package/src/extensions/nocobase-ai/extension.tsx +0 -158
- package/src/extensions/nocobase-ai/global-ai-chat.tsx +0 -213
- package/src/extensions/nocobase-ai/index.ts +0 -3
- package/src/extensions/nocobase-ai/providers/ai-provider.tsx +0 -323
- package/src/extensions/nocobase-ai/providers/avatars.ts +0 -817
- package/src/extensions/nocobase-ai/providers/chat-context.tsx +0 -109
- package/src/extensions/nocobase-ai/providers/chat-controller.ts +0 -84
- package/src/extensions/nocobase-ai/providers/chat-message-utils.ts +0 -198
- package/src/extensions/nocobase-ai/providers/chat-provider.tsx +0 -871
- package/src/extensions/nocobase-ai/providers/chat-reducer.ts +0 -147
- package/src/extensions/nocobase-ai/providers/chat-task-utils.ts +0 -105
- package/src/extensions/nocobase-ai/providers/chat-transport.ts +0 -184
- package/src/extensions/nocobase-ai/providers/form-registry.tsx +0 -271
- package/src/extensions/nocobase-ai/providers/frontend-tool-registry.tsx +0 -231
- package/src/extensions/nocobase-ai/providers/index.ts +0 -61
- package/src/extensions/nocobase-ai/providers/model.ts +0 -32
- package/src/extensions/nocobase-ai/providers/page-context.tsx +0 -136
- package/src/extensions/nocobase-ai/providers/stream-coalescer.ts +0 -60
- package/src/extensions/nocobase-ai/providers/stream-event-utils.ts +0 -82
- package/src/extensions/nocobase-ai/providers/stream-parser.ts +0 -61
- package/src/extensions/nocobase-ai/providers/sub-agent-stream.ts +0 -316
- package/src/extensions/nocobase-ai/providers/types.ts +0 -183
- package/src/extensions/nocobase-ai/providers/ui-message-stream.ts +0 -463
- package/src/extensions/nocobase-ai/providers/use-automatic-tool-approval.ts +0 -94
- package/src/extensions/nocobase-ai/providers/use-chat-attachments.ts +0 -206
- package/src/extensions/nocobase-ai/providers/use-chat-message-actions.ts +0 -554
- package/src/extensions/nocobase-ai/providers/use-chat-runtime.ts +0 -210
- package/src/extensions/nocobase-ai/providers/use-chat-work-context.ts +0 -93
- package/src/extensions/nocobase-ai/providers/use-conversation-catalog.ts +0 -108
- package/src/extensions/nocobase-ai/providers/use-conversation-history.ts +0 -178
- package/src/extensions/nocobase-ai/services/index.ts +0 -7
- package/src/extensions/nocobase-ai/services/nocobase-ai-service.ts +0 -454
- package/src/extensions/nocobase-ai/services/types.ts +0 -82
- /package/{registry/nocobase-i18n → src/providers/i18n}/i18n-provider.ts +0 -0
- /package/{registry/nocobase-i18n → src/providers/i18n}/locale-store.ts +0 -0
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
import type { InferUIMessageChunk } from "ai";
|
|
2
|
-
import type { AIChatMessage, AISubAgentConversation } from "./types";
|
|
3
|
-
import type { NocoBaseStreamEvent } from "./stream-parser";
|
|
4
|
-
import {
|
|
5
|
-
getToolCallState,
|
|
6
|
-
getToolProviderMetadata,
|
|
7
|
-
isRecord,
|
|
8
|
-
parseToolInput,
|
|
9
|
-
toolCallsFromEvent,
|
|
10
|
-
type NocoBaseToolCall,
|
|
11
|
-
} from "./stream-event-utils";
|
|
12
|
-
|
|
13
|
-
type AIChatChunk = InferUIMessageChunk<AIChatMessage>;
|
|
14
|
-
|
|
15
|
-
const createMessage = (username: string): AIChatMessage => ({
|
|
16
|
-
id: `sub-agent-${crypto.randomUUID()}`,
|
|
17
|
-
role: "assistant",
|
|
18
|
-
metadata: {
|
|
19
|
-
createdAt: new Date().toISOString(),
|
|
20
|
-
employeeUsername: username,
|
|
21
|
-
},
|
|
22
|
-
parts: [],
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const updateLastMessage = (
|
|
26
|
-
conversation: AISubAgentConversation,
|
|
27
|
-
updater: (message: AIChatMessage) => AIChatMessage
|
|
28
|
-
) => {
|
|
29
|
-
const messages = conversation.messages.length
|
|
30
|
-
? [...conversation.messages]
|
|
31
|
-
: [createMessage(conversation.username)];
|
|
32
|
-
messages[messages.length - 1] = updater(messages[messages.length - 1]);
|
|
33
|
-
return { ...conversation, messages };
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const appendNarrative = (
|
|
37
|
-
message: AIChatMessage,
|
|
38
|
-
type: "text" | "reasoning",
|
|
39
|
-
delta: string
|
|
40
|
-
): AIChatMessage => {
|
|
41
|
-
const parts = [...message.parts];
|
|
42
|
-
const last = parts.at(-1);
|
|
43
|
-
if (last?.type === type) {
|
|
44
|
-
parts[parts.length - 1] = {
|
|
45
|
-
...last,
|
|
46
|
-
text: `${last.text}${delta}`,
|
|
47
|
-
state: "streaming",
|
|
48
|
-
};
|
|
49
|
-
} else {
|
|
50
|
-
parts.push({ type, text: delta, state: "streaming" });
|
|
51
|
-
}
|
|
52
|
-
return { ...message, parts };
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const toToolPart = (
|
|
56
|
-
toolCall: NocoBaseToolCall
|
|
57
|
-
): AIChatMessage["parts"][number] => {
|
|
58
|
-
const toolCallId = toolCall.id ?? `tool-${crypto.randomUUID()}`;
|
|
59
|
-
const toolName = toolCall.name ?? "tool";
|
|
60
|
-
const input = parseToolInput(toolCall.args ?? toolCall.input ?? {});
|
|
61
|
-
const state = getToolCallState(toolCall);
|
|
62
|
-
const callProviderMetadata = getToolProviderMetadata(toolCall);
|
|
63
|
-
if (state.failed) {
|
|
64
|
-
return {
|
|
65
|
-
type: "dynamic-tool",
|
|
66
|
-
toolCallId,
|
|
67
|
-
toolName,
|
|
68
|
-
state: "output-error",
|
|
69
|
-
input,
|
|
70
|
-
errorText: String(
|
|
71
|
-
toolCall.content ?? toolCall.output ?? "Tool call failed"
|
|
72
|
-
),
|
|
73
|
-
callProviderMetadata,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
if (state.completed) {
|
|
77
|
-
return {
|
|
78
|
-
type: "dynamic-tool",
|
|
79
|
-
toolCallId,
|
|
80
|
-
toolName,
|
|
81
|
-
state: "output-available",
|
|
82
|
-
input,
|
|
83
|
-
output: toolCall.output ?? toolCall.content ?? { status: "completed" },
|
|
84
|
-
callProviderMetadata,
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
type: "dynamic-tool",
|
|
89
|
-
toolCallId,
|
|
90
|
-
toolName,
|
|
91
|
-
state: "input-available",
|
|
92
|
-
input,
|
|
93
|
-
callProviderMetadata,
|
|
94
|
-
};
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const updateToolCalls = (
|
|
98
|
-
message: AIChatMessage,
|
|
99
|
-
toolCalls: NocoBaseToolCall[]
|
|
100
|
-
) => {
|
|
101
|
-
const parts = [...message.parts];
|
|
102
|
-
for (const toolCall of toolCalls) {
|
|
103
|
-
const nextPart = toToolPart(toolCall);
|
|
104
|
-
if (nextPart.type !== "dynamic-tool") continue;
|
|
105
|
-
const index = parts.findIndex(
|
|
106
|
-
(part) =>
|
|
107
|
-
part.type === "dynamic-tool" && part.toolCallId === nextPart.toolCallId
|
|
108
|
-
);
|
|
109
|
-
if (index >= 0) parts[index] = nextPart;
|
|
110
|
-
else parts.push(nextPart);
|
|
111
|
-
}
|
|
112
|
-
return { ...message, parts };
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const finishMessages = (messages: AIChatMessage[]) =>
|
|
116
|
-
messages.map((message) => ({
|
|
117
|
-
...message,
|
|
118
|
-
parts: message.parts.map((part) =>
|
|
119
|
-
part.type === "text" || part.type === "reasoning"
|
|
120
|
-
? { ...part, state: "done" as const }
|
|
121
|
-
: part
|
|
122
|
-
),
|
|
123
|
-
}));
|
|
124
|
-
|
|
125
|
-
export class SubAgentStreamAccumulator {
|
|
126
|
-
private readonly conversations = new Map<string, AISubAgentConversation>();
|
|
127
|
-
private readonly toolStreams = new Map<
|
|
128
|
-
string,
|
|
129
|
-
{
|
|
130
|
-
currentId?: string;
|
|
131
|
-
idsByIndex: Map<number, string>;
|
|
132
|
-
names: Map<string, string>;
|
|
133
|
-
inputs: Map<string, unknown>;
|
|
134
|
-
}
|
|
135
|
-
>();
|
|
136
|
-
|
|
137
|
-
constructor(seedMessage?: AIChatMessage) {
|
|
138
|
-
if (!seedMessage) return;
|
|
139
|
-
const seed = (messages: AIChatMessage[]) => {
|
|
140
|
-
for (const message of messages) {
|
|
141
|
-
for (const part of message.parts) {
|
|
142
|
-
if (part.type !== "data-subAgent") continue;
|
|
143
|
-
this.conversations.set(part.data.sessionId, structuredClone(part.data));
|
|
144
|
-
seed(part.data.messages);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
seed([seedMessage]);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
private getToolStream(sessionId: string) {
|
|
152
|
-
const existing = this.toolStreams.get(sessionId);
|
|
153
|
-
if (existing) return existing;
|
|
154
|
-
const created = {
|
|
155
|
-
currentId: undefined,
|
|
156
|
-
idsByIndex: new Map<number, string>(),
|
|
157
|
-
names: new Map<string, string>(),
|
|
158
|
-
inputs: new Map<string, unknown>(),
|
|
159
|
-
};
|
|
160
|
-
this.toolStreams.set(sessionId, created);
|
|
161
|
-
return created;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
private normalizeToolChunk(
|
|
165
|
-
sessionId: string,
|
|
166
|
-
chunk: NocoBaseToolCall
|
|
167
|
-
): NocoBaseToolCall | undefined {
|
|
168
|
-
const stream = this.getToolStream(sessionId);
|
|
169
|
-
const indexedId =
|
|
170
|
-
typeof chunk.index === "number"
|
|
171
|
-
? stream.idsByIndex.get(chunk.index)
|
|
172
|
-
: undefined;
|
|
173
|
-
const toolCallId = chunk.id ?? indexedId ?? stream.currentId;
|
|
174
|
-
if (!toolCallId) return undefined;
|
|
175
|
-
|
|
176
|
-
stream.currentId = toolCallId;
|
|
177
|
-
if (typeof chunk.index === "number") {
|
|
178
|
-
stream.idsByIndex.set(chunk.index, toolCallId);
|
|
179
|
-
}
|
|
180
|
-
if (chunk.name) stream.names.set(toolCallId, chunk.name);
|
|
181
|
-
|
|
182
|
-
if (typeof chunk.args === "string") {
|
|
183
|
-
const previous = stream.inputs.get(toolCallId);
|
|
184
|
-
stream.inputs.set(
|
|
185
|
-
toolCallId,
|
|
186
|
-
`${typeof previous === "string" ? previous : ""}${chunk.args}`
|
|
187
|
-
);
|
|
188
|
-
} else if (chunk.args !== undefined) {
|
|
189
|
-
stream.inputs.set(toolCallId, chunk.args);
|
|
190
|
-
} else if (chunk.input !== undefined) {
|
|
191
|
-
stream.inputs.set(toolCallId, chunk.input);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return {
|
|
195
|
-
...chunk,
|
|
196
|
-
id: toolCallId,
|
|
197
|
-
name: chunk.name ?? stream.names.get(toolCallId) ?? "tool",
|
|
198
|
-
args: stream.inputs.get(toolCallId),
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
private normalizeToolCall(
|
|
203
|
-
sessionId: string,
|
|
204
|
-
toolCall: NocoBaseToolCall
|
|
205
|
-
): NocoBaseToolCall {
|
|
206
|
-
const stream = this.getToolStream(sessionId);
|
|
207
|
-
const toolCallId =
|
|
208
|
-
toolCall.id ?? stream.currentId ?? `tool-${crypto.randomUUID()}`;
|
|
209
|
-
stream.currentId = toolCallId;
|
|
210
|
-
if (typeof toolCall.index === "number") {
|
|
211
|
-
stream.idsByIndex.set(toolCall.index, toolCallId);
|
|
212
|
-
}
|
|
213
|
-
const toolName = toolCall.name ?? stream.names.get(toolCallId) ?? "tool";
|
|
214
|
-
stream.names.set(toolCallId, toolName);
|
|
215
|
-
const input = toolCall.args ?? toolCall.input;
|
|
216
|
-
if (input !== undefined) stream.inputs.set(toolCallId, input);
|
|
217
|
-
return {
|
|
218
|
-
...toolCall,
|
|
219
|
-
id: toolCallId,
|
|
220
|
-
name: toolName,
|
|
221
|
-
args: input ?? stream.inputs.get(toolCallId),
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
process(event: NocoBaseStreamEvent): AIChatChunk[] {
|
|
226
|
-
if (event.from !== "sub-agent" || !event.sessionId) return [];
|
|
227
|
-
const username = event.username || "sub-agent";
|
|
228
|
-
let conversation = this.conversations.get(event.sessionId) ?? {
|
|
229
|
-
sessionId: event.sessionId,
|
|
230
|
-
username,
|
|
231
|
-
status: "pending" as const,
|
|
232
|
-
messages: [],
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
if (event.type === "new_message") {
|
|
236
|
-
this.getToolStream(event.sessionId).currentId = undefined;
|
|
237
|
-
conversation = {
|
|
238
|
-
...conversation,
|
|
239
|
-
username,
|
|
240
|
-
messages: [...conversation.messages, createMessage(username)],
|
|
241
|
-
};
|
|
242
|
-
} else if (event.type === "content" && typeof event.body === "string") {
|
|
243
|
-
conversation = updateLastMessage(conversation, (message) =>
|
|
244
|
-
appendNarrative(message, "text", event.body as string)
|
|
245
|
-
);
|
|
246
|
-
} else if (event.type === "reasoning" && isRecord(event.body)) {
|
|
247
|
-
const content = event.body.content;
|
|
248
|
-
if (typeof content === "string" && content) {
|
|
249
|
-
conversation = updateLastMessage(conversation, (message) =>
|
|
250
|
-
appendNarrative(message, "reasoning", content)
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
} else if (event.type === "tool_call_chunks") {
|
|
254
|
-
const toolCalls = toolCallsFromEvent(event).flatMap((toolCall) => {
|
|
255
|
-
const normalized = this.normalizeToolChunk(event.sessionId!, toolCall);
|
|
256
|
-
return normalized ? [normalized] : [];
|
|
257
|
-
});
|
|
258
|
-
if (toolCalls.length) {
|
|
259
|
-
conversation = updateLastMessage(conversation, (message) =>
|
|
260
|
-
updateToolCalls(message, toolCalls)
|
|
261
|
-
);
|
|
262
|
-
}
|
|
263
|
-
} else if (event.type === "tool_calls") {
|
|
264
|
-
const toolCalls = toolCallsFromEvent(event).map((toolCall) =>
|
|
265
|
-
this.normalizeToolCall(event.sessionId!, toolCall)
|
|
266
|
-
);
|
|
267
|
-
if (toolCalls.length) {
|
|
268
|
-
conversation = updateLastMessage(conversation, (message) =>
|
|
269
|
-
updateToolCalls(message, toolCalls)
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
} else if (event.type === "tool_call_status" && isRecord(event.body)) {
|
|
273
|
-
const rawToolCall = isRecord(event.body.toolCall)
|
|
274
|
-
? ({
|
|
275
|
-
...event.body.toolCall,
|
|
276
|
-
invokeStatus:
|
|
277
|
-
event.body.invokeStatus ?? event.body.toolCall.invokeStatus,
|
|
278
|
-
status: event.body.status ?? event.body.toolCall.status,
|
|
279
|
-
content: event.body.content ?? event.body.toolCall.content,
|
|
280
|
-
} as NocoBaseToolCall)
|
|
281
|
-
: undefined;
|
|
282
|
-
const toolCall = rawToolCall
|
|
283
|
-
? this.normalizeToolCall(event.sessionId, rawToolCall)
|
|
284
|
-
: undefined;
|
|
285
|
-
if (toolCall) {
|
|
286
|
-
conversation = updateLastMessage(conversation, (message) => {
|
|
287
|
-
const updated = updateToolCalls(message, [toolCall]);
|
|
288
|
-
return toolCall.messageId
|
|
289
|
-
? {
|
|
290
|
-
...updated,
|
|
291
|
-
metadata: {
|
|
292
|
-
...updated.metadata,
|
|
293
|
-
serverMessageId: String(toolCall.messageId),
|
|
294
|
-
},
|
|
295
|
-
}
|
|
296
|
-
: updated;
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
} else if (event.type === "sub_agent_completed") {
|
|
300
|
-
conversation = {
|
|
301
|
-
...conversation,
|
|
302
|
-
status: "completed",
|
|
303
|
-
messages: finishMessages(conversation.messages),
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
this.conversations.set(event.sessionId, conversation);
|
|
308
|
-
return [
|
|
309
|
-
{
|
|
310
|
-
type: "data-subAgent",
|
|
311
|
-
id: event.sessionId,
|
|
312
|
-
data: conversation,
|
|
313
|
-
},
|
|
314
|
-
];
|
|
315
|
-
}
|
|
316
|
-
}
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import type { ChatTransport, UIMessage } from "ai";
|
|
2
|
-
|
|
3
|
-
export const AI_DRAFT_CONVERSATION_ID = "__draft__";
|
|
4
|
-
|
|
5
|
-
export type AIConfigurationStatus = "loading" | "ready" | "error";
|
|
6
|
-
|
|
7
|
-
export type AIEmployee = {
|
|
8
|
-
username: string;
|
|
9
|
-
nickname: string;
|
|
10
|
-
position?: string;
|
|
11
|
-
bio?: string;
|
|
12
|
-
greeting?: string;
|
|
13
|
-
description?: string;
|
|
14
|
-
avatar?: string;
|
|
15
|
-
category?: string;
|
|
16
|
-
deprecated?: boolean;
|
|
17
|
-
builtIn?: boolean;
|
|
18
|
-
userConfig?: {
|
|
19
|
-
prompt?: string;
|
|
20
|
-
};
|
|
21
|
-
modelSettings?: {
|
|
22
|
-
enabled?: boolean;
|
|
23
|
-
llmService?: string;
|
|
24
|
-
model?: string;
|
|
25
|
-
models?: Array<{
|
|
26
|
-
llmService?: string;
|
|
27
|
-
model?: string;
|
|
28
|
-
}>;
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export type AIChatAttachmentStatus = "uploading" | "done" | "error";
|
|
33
|
-
|
|
34
|
-
export type AIChatAttachment = {
|
|
35
|
-
uid: string;
|
|
36
|
-
filename: string;
|
|
37
|
-
status: AIChatAttachmentStatus;
|
|
38
|
-
size?: number;
|
|
39
|
-
mimetype?: string;
|
|
40
|
-
url?: string;
|
|
41
|
-
preview?: string;
|
|
42
|
-
progress?: number;
|
|
43
|
-
error?: string;
|
|
44
|
-
source?: unknown;
|
|
45
|
-
[key: string]: unknown;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export type AIModel = {
|
|
49
|
-
value: string;
|
|
50
|
-
label: string;
|
|
51
|
-
llmService?: string;
|
|
52
|
-
llmServiceTitle?: string;
|
|
53
|
-
supportWebSearch?: boolean;
|
|
54
|
-
isToolConflict?: boolean;
|
|
55
|
-
configured?: boolean;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export type AIConversation = {
|
|
59
|
-
id: string;
|
|
60
|
-
title: string;
|
|
61
|
-
employeeUsername: string;
|
|
62
|
-
updatedAt: string;
|
|
63
|
-
unread?: boolean;
|
|
64
|
-
model?: {
|
|
65
|
-
llmService?: string;
|
|
66
|
-
model: string;
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export type AIWorkContextItem = {
|
|
71
|
-
type: string;
|
|
72
|
-
id?: string;
|
|
73
|
-
title?: string;
|
|
74
|
-
content?: unknown;
|
|
75
|
-
[key: string]: unknown;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export type AIEmployeeTask = {
|
|
79
|
-
title?: string;
|
|
80
|
-
message?: {
|
|
81
|
-
system?: string;
|
|
82
|
-
user?: string;
|
|
83
|
-
workContext?: AIWorkContextItem[];
|
|
84
|
-
};
|
|
85
|
-
autoSend?: boolean;
|
|
86
|
-
skillSettings?: {
|
|
87
|
-
skills?: string[];
|
|
88
|
-
tools?: string[];
|
|
89
|
-
};
|
|
90
|
-
webSearch?: boolean;
|
|
91
|
-
model?: {
|
|
92
|
-
llmService?: string;
|
|
93
|
-
model: string;
|
|
94
|
-
};
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
export type AIEmployeeTasks = Record<string, AIEmployeeTask[]>;
|
|
98
|
-
|
|
99
|
-
export type AIEmployeeTaskTrigger = {
|
|
100
|
-
aiEmployee: string | AIEmployee;
|
|
101
|
-
task?: AIEmployeeTask;
|
|
102
|
-
tasks?: AIEmployeeTask[];
|
|
103
|
-
context?: AIWorkContextItem[];
|
|
104
|
-
auto?: boolean;
|
|
105
|
-
open?: boolean;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
export type AIChatTaskRuntime = {
|
|
109
|
-
systemMessage?: string;
|
|
110
|
-
workContext: AIWorkContextItem[];
|
|
111
|
-
skillSettings?: AIEmployeeTask["skillSettings"];
|
|
112
|
-
webSearch?: boolean;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
export type AIChatMessageMetadata = {
|
|
116
|
-
createdAt?: string;
|
|
117
|
-
employeeUsername?: string;
|
|
118
|
-
toolApprovals?: Record<string, AIToolCallApproval>;
|
|
119
|
-
serverMessageId?: string;
|
|
120
|
-
editingMessageId?: string;
|
|
121
|
-
attachments?: AIChatAttachment[];
|
|
122
|
-
workContext?: AIWorkContextItem[];
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
export type AIToolCallApproval = {
|
|
126
|
-
required: boolean;
|
|
127
|
-
status?: "pending" | "approved" | "rejected";
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
export type AIToolCallDecision = {
|
|
131
|
-
messageId: string;
|
|
132
|
-
toolCallId: string;
|
|
133
|
-
toolName: string;
|
|
134
|
-
decision: "approve" | "reject" | "edit";
|
|
135
|
-
input?: unknown;
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
export type AIToolCallInvocationContext = {
|
|
139
|
-
sessionId: string;
|
|
140
|
-
messageId: string;
|
|
141
|
-
toolCallId: string;
|
|
142
|
-
toolName: string;
|
|
143
|
-
allowedFrontendToolIds?: string[];
|
|
144
|
-
allowedFormIds?: string[];
|
|
145
|
-
automatic?: boolean;
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
export type AIToolInvoker = (
|
|
149
|
-
input: unknown,
|
|
150
|
-
context: AIToolCallInvocationContext
|
|
151
|
-
) => unknown | Promise<unknown>;
|
|
152
|
-
|
|
153
|
-
export type AIToolInvokerMap = Record<string, AIToolInvoker>;
|
|
154
|
-
|
|
155
|
-
export type AISubAgentConversation = {
|
|
156
|
-
sessionId: string;
|
|
157
|
-
username: string;
|
|
158
|
-
status: "pending" | "completed";
|
|
159
|
-
messages: AIChatMessage[];
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
export type AIChatDataParts = {
|
|
163
|
-
subAgent: AISubAgentConversation;
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
export type AIChatMessage = UIMessage<AIChatMessageMetadata, AIChatDataParts>;
|
|
167
|
-
|
|
168
|
-
export type AIChatRequestContext = {
|
|
169
|
-
sessionId?: string;
|
|
170
|
-
employee: AIEmployee;
|
|
171
|
-
model: AIModel;
|
|
172
|
-
task?: AIChatTaskRuntime;
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
export type AITransportFactoryOptions = {
|
|
176
|
-
chatId: string;
|
|
177
|
-
getContext: () => AIChatRequestContext;
|
|
178
|
-
onSessionCreated?: (sessionId: string) => void;
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
export type AITransportFactory = (
|
|
182
|
-
options: AITransportFactoryOptions
|
|
183
|
-
) => ChatTransport<AIChatMessage>;
|