@nocobase/portal-template-default 1.0.3 → 1.0.5
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 +17 -17
- 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,454 +0,0 @@
|
|
|
1
|
-
import { nocobaseClient, type NocoBaseClient } from "@/lib/nocobase/client";
|
|
2
|
-
import type {
|
|
3
|
-
AIChatMessage,
|
|
4
|
-
AIConversation,
|
|
5
|
-
AIEmployee,
|
|
6
|
-
AIModel,
|
|
7
|
-
} from "../providers/types";
|
|
8
|
-
import type {
|
|
9
|
-
AIConversationActiveState,
|
|
10
|
-
AIService,
|
|
11
|
-
CreateAIConversationOptions,
|
|
12
|
-
} from "./types";
|
|
13
|
-
import type { UpdateToolCallDecisionOptions } from "./types";
|
|
14
|
-
import {
|
|
15
|
-
getToolCallState,
|
|
16
|
-
getToolProviderMetadata,
|
|
17
|
-
type NocoBaseToolCall,
|
|
18
|
-
} from "../providers/stream-event-utils";
|
|
19
|
-
|
|
20
|
-
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
21
|
-
!!value && typeof value === "object" && !Array.isArray(value);
|
|
22
|
-
|
|
23
|
-
const parseToolInput = (value: unknown) => {
|
|
24
|
-
if (typeof value !== "string") return value;
|
|
25
|
-
try {
|
|
26
|
-
return JSON.parse(value) as unknown;
|
|
27
|
-
} catch {
|
|
28
|
-
return value;
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const toAttachment = (
|
|
33
|
-
value: unknown,
|
|
34
|
-
index: number,
|
|
35
|
-
resolveUrl: (value: string) => string
|
|
36
|
-
) => {
|
|
37
|
-
if (!isRecord(value)) return undefined;
|
|
38
|
-
const filename = value.filename ?? value.name ?? value.title;
|
|
39
|
-
if (typeof filename !== "string") return undefined;
|
|
40
|
-
return {
|
|
41
|
-
...value,
|
|
42
|
-
uid: String(value.id ?? value.uid ?? `${filename}-${index}`),
|
|
43
|
-
filename,
|
|
44
|
-
status: "done" as const,
|
|
45
|
-
size: typeof value.size === "number" ? value.size : undefined,
|
|
46
|
-
mimetype:
|
|
47
|
-
typeof value.mimetype === "string"
|
|
48
|
-
? value.mimetype
|
|
49
|
-
: typeof value.type === "string"
|
|
50
|
-
? value.type
|
|
51
|
-
: undefined,
|
|
52
|
-
url: typeof value.url === "string" ? resolveUrl(value.url) : undefined,
|
|
53
|
-
preview:
|
|
54
|
-
typeof value.preview === "string" ? resolveUrl(value.preview) : undefined,
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const toHistoryMessage = (
|
|
59
|
-
value: unknown,
|
|
60
|
-
index: number,
|
|
61
|
-
resolveUrl: (value: string) => string
|
|
62
|
-
): AIChatMessage => {
|
|
63
|
-
const message = isRecord(value) ? value : {};
|
|
64
|
-
const content = isRecord(message.content) ? message.content : {};
|
|
65
|
-
const rawServerMessageId = content.messageId ?? message.messageId;
|
|
66
|
-
const serverMessageId =
|
|
67
|
-
typeof rawServerMessageId === "number" ||
|
|
68
|
-
(typeof rawServerMessageId === "string" && /^\d+$/.test(rawServerMessageId))
|
|
69
|
-
? String(rawServerMessageId)
|
|
70
|
-
: undefined;
|
|
71
|
-
const messageId =
|
|
72
|
-
serverMessageId ?? String(message.key ?? `history-${index}`);
|
|
73
|
-
const text =
|
|
74
|
-
typeof content.content === "string"
|
|
75
|
-
? content.content
|
|
76
|
-
: typeof message.content === "string"
|
|
77
|
-
? message.content
|
|
78
|
-
: "";
|
|
79
|
-
const attachments = Array.isArray(content.attachments)
|
|
80
|
-
? content.attachments
|
|
81
|
-
.map((attachment, attachmentIndex) =>
|
|
82
|
-
toAttachment(attachment, attachmentIndex, resolveUrl)
|
|
83
|
-
)
|
|
84
|
-
.filter((attachment) => attachment !== undefined)
|
|
85
|
-
: [];
|
|
86
|
-
const parts: AIChatMessage["parts"] = [];
|
|
87
|
-
const reasoning = isRecord(content.reasoning) ? content.reasoning : undefined;
|
|
88
|
-
if (typeof reasoning?.content === "string" && reasoning.content) {
|
|
89
|
-
parts.push({ type: "reasoning", text: reasoning.content, state: "done" });
|
|
90
|
-
}
|
|
91
|
-
if (text) parts.push({ type: "text", text, state: "done" });
|
|
92
|
-
const toolCalls = Array.isArray(content.tool_calls)
|
|
93
|
-
? content.tool_calls
|
|
94
|
-
: Array.isArray(message.toolCalls)
|
|
95
|
-
? message.toolCalls
|
|
96
|
-
: [];
|
|
97
|
-
for (const rawToolCall of toolCalls) {
|
|
98
|
-
if (!isRecord(rawToolCall)) continue;
|
|
99
|
-
const toolCallId = String(rawToolCall.id ?? `tool-${crypto.randomUUID()}`);
|
|
100
|
-
const toolName = String(rawToolCall.name ?? "tool");
|
|
101
|
-
const toolCall = rawToolCall as NocoBaseToolCall;
|
|
102
|
-
const { failed, completed } = getToolCallState(toolCall);
|
|
103
|
-
const callProviderMetadata = getToolProviderMetadata(toolCall);
|
|
104
|
-
parts.push(
|
|
105
|
-
failed
|
|
106
|
-
? {
|
|
107
|
-
type: "dynamic-tool",
|
|
108
|
-
toolCallId,
|
|
109
|
-
toolName,
|
|
110
|
-
state: "output-error",
|
|
111
|
-
input: parseToolInput(rawToolCall.args ?? {}),
|
|
112
|
-
errorText: String(rawToolCall.content ?? "Tool call failed"),
|
|
113
|
-
callProviderMetadata,
|
|
114
|
-
}
|
|
115
|
-
: completed
|
|
116
|
-
? {
|
|
117
|
-
type: "dynamic-tool",
|
|
118
|
-
toolCallId,
|
|
119
|
-
toolName,
|
|
120
|
-
state: "output-available",
|
|
121
|
-
input: parseToolInput(rawToolCall.args ?? {}),
|
|
122
|
-
output: rawToolCall.content,
|
|
123
|
-
callProviderMetadata,
|
|
124
|
-
}
|
|
125
|
-
: {
|
|
126
|
-
type: "dynamic-tool",
|
|
127
|
-
toolCallId,
|
|
128
|
-
toolName,
|
|
129
|
-
state: "input-available",
|
|
130
|
-
input: parseToolInput(rawToolCall.args ?? {}),
|
|
131
|
-
callProviderMetadata,
|
|
132
|
-
}
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
const subAgentConversations = Array.isArray(content.subAgentConversations)
|
|
136
|
-
? content.subAgentConversations
|
|
137
|
-
: [];
|
|
138
|
-
for (const [
|
|
139
|
-
conversationIndex,
|
|
140
|
-
rawConversation,
|
|
141
|
-
] of subAgentConversations.entries()) {
|
|
142
|
-
if (!isRecord(rawConversation)) continue;
|
|
143
|
-
const rawMessages = Array.isArray(rawConversation.messages)
|
|
144
|
-
? rawConversation.messages
|
|
145
|
-
: [];
|
|
146
|
-
const messages = rawMessages.map((item, messageIndex) =>
|
|
147
|
-
toHistoryMessage(item, messageIndex, resolveUrl)
|
|
148
|
-
);
|
|
149
|
-
const username =
|
|
150
|
-
typeof rawConversation.username === "string"
|
|
151
|
-
? rawConversation.username
|
|
152
|
-
: messages.find((item) => item.metadata?.employeeUsername)?.metadata
|
|
153
|
-
?.employeeUsername ?? "sub-agent";
|
|
154
|
-
const sessionId = String(
|
|
155
|
-
rawConversation.sessionId ??
|
|
156
|
-
`sub-agent-history-${index}-${conversationIndex}`
|
|
157
|
-
);
|
|
158
|
-
parts.push({
|
|
159
|
-
type: "data-subAgent",
|
|
160
|
-
id: sessionId,
|
|
161
|
-
data: {
|
|
162
|
-
sessionId,
|
|
163
|
-
username,
|
|
164
|
-
status:
|
|
165
|
-
rawConversation.status === "completed" ? "completed" : "pending",
|
|
166
|
-
messages,
|
|
167
|
-
},
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
for (const attachment of attachments) {
|
|
171
|
-
if (!attachment.url && !attachment.preview) continue;
|
|
172
|
-
parts.push({
|
|
173
|
-
type: "file",
|
|
174
|
-
mediaType: attachment.mimetype ?? "application/octet-stream",
|
|
175
|
-
filename: attachment.filename,
|
|
176
|
-
url: attachment.url ?? attachment.preview ?? "",
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
const rawRole = String(message.role ?? "assistant");
|
|
180
|
-
const role =
|
|
181
|
-
rawRole === "user" || rawRole === "system" ? rawRole : "assistant";
|
|
182
|
-
return {
|
|
183
|
-
id: messageId,
|
|
184
|
-
role,
|
|
185
|
-
metadata: {
|
|
186
|
-
...(serverMessageId ? { serverMessageId } : {}),
|
|
187
|
-
...(rawRole !== "user" && rawRole !== "system"
|
|
188
|
-
? { employeeUsername: rawRole }
|
|
189
|
-
: {}),
|
|
190
|
-
createdAt:
|
|
191
|
-
typeof message.createdAt === "string" ? message.createdAt : undefined,
|
|
192
|
-
attachments,
|
|
193
|
-
workContext: Array.isArray(content.workContext)
|
|
194
|
-
? content.workContext
|
|
195
|
-
: undefined,
|
|
196
|
-
},
|
|
197
|
-
parts,
|
|
198
|
-
};
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
export class NocoBaseAIService implements AIService {
|
|
202
|
-
constructor(private readonly client: NocoBaseClient = nocobaseClient) {}
|
|
203
|
-
|
|
204
|
-
async listEmployees() {
|
|
205
|
-
const employees = await this.client.action<AIEmployee[]>(
|
|
206
|
-
"aiEmployees",
|
|
207
|
-
"listByUser"
|
|
208
|
-
);
|
|
209
|
-
return employees
|
|
210
|
-
.filter((employee) => employee?.username)
|
|
211
|
-
.map((employee) => ({
|
|
212
|
-
...employee,
|
|
213
|
-
nickname: employee.nickname ?? employee.username,
|
|
214
|
-
description: employee.description ?? employee.bio,
|
|
215
|
-
}));
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
async listModels() {
|
|
219
|
-
const services = await this.client.action<
|
|
220
|
-
Array<{
|
|
221
|
-
llmService: string;
|
|
222
|
-
llmServiceTitle: string;
|
|
223
|
-
enabledModels?: Array<{ label: string; value: string }>;
|
|
224
|
-
supportWebSearch?: boolean;
|
|
225
|
-
isToolConflict?: boolean;
|
|
226
|
-
}>
|
|
227
|
-
>("ai", "listAllEnabledModels");
|
|
228
|
-
return services.flatMap((service) =>
|
|
229
|
-
(service.enabledModels ?? []).map<AIModel>((model) => ({
|
|
230
|
-
value: model.value,
|
|
231
|
-
label: model.label,
|
|
232
|
-
llmService: service.llmService,
|
|
233
|
-
llmServiceTitle: service.llmServiceTitle,
|
|
234
|
-
supportWebSearch: service.supportWebSearch,
|
|
235
|
-
isToolConflict: service.isToolConflict,
|
|
236
|
-
}))
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
async updateEmployeeUserPrompt(username: string, prompt: string) {
|
|
241
|
-
await this.client.action("aiEmployees", "updateUserPrompt", {
|
|
242
|
-
body: { aiEmployee: username, prompt },
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
async listConversations(keyword = "") {
|
|
247
|
-
const normalizedKeyword = keyword.trim();
|
|
248
|
-
const response = await this.client.action<
|
|
249
|
-
{ data?: unknown[]; rows?: unknown[] } | unknown[]
|
|
250
|
-
>("aiConversations", "list", {
|
|
251
|
-
query: {
|
|
252
|
-
sort: "-createdAt",
|
|
253
|
-
appends: "aiEmployee",
|
|
254
|
-
page: 1,
|
|
255
|
-
pageSize: 50,
|
|
256
|
-
filter: normalizedKeyword
|
|
257
|
-
? JSON.stringify({ title: { $includes: normalizedKeyword } })
|
|
258
|
-
: undefined,
|
|
259
|
-
},
|
|
260
|
-
});
|
|
261
|
-
const rows = Array.isArray(response)
|
|
262
|
-
? response
|
|
263
|
-
: response.data ?? response.rows ?? [];
|
|
264
|
-
return rows.flatMap<AIConversation>((value) => {
|
|
265
|
-
if (!isRecord(value) || typeof value.sessionId !== "string") return [];
|
|
266
|
-
const employee = isRecord(value.aiEmployee)
|
|
267
|
-
? value.aiEmployee
|
|
268
|
-
: undefined;
|
|
269
|
-
const options = isRecord(value.options) ? value.options : undefined;
|
|
270
|
-
const modelSettings = isRecord(options?.modelSettings)
|
|
271
|
-
? options.modelSettings
|
|
272
|
-
: undefined;
|
|
273
|
-
return [
|
|
274
|
-
{
|
|
275
|
-
id: value.sessionId,
|
|
276
|
-
title:
|
|
277
|
-
typeof value.title === "string" && value.title
|
|
278
|
-
? value.title
|
|
279
|
-
: "New conversation",
|
|
280
|
-
employeeUsername: String(
|
|
281
|
-
employee?.username ?? value.aiEmployeeUsername ?? ""
|
|
282
|
-
),
|
|
283
|
-
updatedAt:
|
|
284
|
-
typeof value.updatedAt === "string"
|
|
285
|
-
? value.updatedAt
|
|
286
|
-
: new Date().toISOString(),
|
|
287
|
-
unread: value.read === false,
|
|
288
|
-
model:
|
|
289
|
-
typeof modelSettings?.model === "string"
|
|
290
|
-
? {
|
|
291
|
-
llmService:
|
|
292
|
-
typeof modelSettings.llmService === "string"
|
|
293
|
-
? modelSettings.llmService
|
|
294
|
-
: undefined,
|
|
295
|
-
model: modelSettings.model,
|
|
296
|
-
}
|
|
297
|
-
: undefined,
|
|
298
|
-
},
|
|
299
|
-
];
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
async getConversationMessages(
|
|
304
|
-
sessionId: string,
|
|
305
|
-
options: { updateRead?: boolean } = {}
|
|
306
|
-
) {
|
|
307
|
-
const response = await this.client.action<
|
|
308
|
-
{ data?: unknown[]; rows?: unknown[] } | unknown[]
|
|
309
|
-
>("aiConversations", "getMessages", {
|
|
310
|
-
query: {
|
|
311
|
-
sessionId,
|
|
312
|
-
paginate: false,
|
|
313
|
-
updateRead: options.updateRead === true,
|
|
314
|
-
},
|
|
315
|
-
body: {},
|
|
316
|
-
});
|
|
317
|
-
const rows = Array.isArray(response)
|
|
318
|
-
? response
|
|
319
|
-
: response.data ?? response.rows ?? [];
|
|
320
|
-
return [...rows]
|
|
321
|
-
.reverse()
|
|
322
|
-
.filter((value) => {
|
|
323
|
-
if (!isRecord(value)) return true;
|
|
324
|
-
return value.role !== "tool" && value.role !== "system";
|
|
325
|
-
})
|
|
326
|
-
.map((value, index) =>
|
|
327
|
-
toHistoryMessage(value, index, (url) => this.client.resolveUrl(url))
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
async getConversationActiveState(sessionId: string) {
|
|
332
|
-
const response = await this.client.action<{
|
|
333
|
-
llmActiveState?: unknown;
|
|
334
|
-
}>("aiConversations", "get", {
|
|
335
|
-
query: { filter: JSON.stringify({ sessionId }) },
|
|
336
|
-
});
|
|
337
|
-
const state = response?.llmActiveState;
|
|
338
|
-
return state === "idle" || state === "streaming" || state === "invoking"
|
|
339
|
-
? (state as AIConversationActiveState)
|
|
340
|
-
: undefined;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
async updateConversationTitle(sessionId: string, title: string) {
|
|
344
|
-
await this.client.action("aiConversations", "update", {
|
|
345
|
-
method: "PUT",
|
|
346
|
-
query: { filterByTk: sessionId },
|
|
347
|
-
body: { title },
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
async destroyConversation(sessionId: string) {
|
|
352
|
-
await this.client.action("aiConversations", "destroy", {
|
|
353
|
-
method: "DELETE",
|
|
354
|
-
query: { filterByTk: sessionId },
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
async uploadFile(file: File, signal?: AbortSignal) {
|
|
359
|
-
const formData = new FormData();
|
|
360
|
-
formData.append("file", file);
|
|
361
|
-
const response = await this.client.action<Record<string, unknown>>(
|
|
362
|
-
"aiFiles",
|
|
363
|
-
"create",
|
|
364
|
-
{
|
|
365
|
-
body: formData,
|
|
366
|
-
signal,
|
|
367
|
-
unwrap: "deep-data",
|
|
368
|
-
}
|
|
369
|
-
);
|
|
370
|
-
return {
|
|
371
|
-
...response,
|
|
372
|
-
...(typeof response.url === "string"
|
|
373
|
-
? { url: this.client.resolveUrl(response.url) }
|
|
374
|
-
: {}),
|
|
375
|
-
...(typeof response.preview === "string"
|
|
376
|
-
? { preview: this.client.resolveUrl(response.preview) }
|
|
377
|
-
: {}),
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
async createConversation(options: CreateAIConversationOptions) {
|
|
382
|
-
const response = await this.client.action<{ sessionId: string }>(
|
|
383
|
-
"aiConversations",
|
|
384
|
-
"create",
|
|
385
|
-
{
|
|
386
|
-
body: {
|
|
387
|
-
aiEmployee: options.employee,
|
|
388
|
-
systemMessage: options.systemMessage,
|
|
389
|
-
skillSettings: options.skillSettings,
|
|
390
|
-
modelSettings: {
|
|
391
|
-
llmService: options.model.llmService,
|
|
392
|
-
model: options.model.value,
|
|
393
|
-
},
|
|
394
|
-
},
|
|
395
|
-
}
|
|
396
|
-
);
|
|
397
|
-
return response.sessionId;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
sendMessagesStream(body: unknown, signal?: AbortSignal) {
|
|
401
|
-
return this.client.stream("aiConversations:sendMessages", {
|
|
402
|
-
body,
|
|
403
|
-
signal,
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
resendMessagesStream(body: unknown, signal?: AbortSignal) {
|
|
408
|
-
return this.client.stream("aiConversations:resendMessages", {
|
|
409
|
-
body,
|
|
410
|
-
signal,
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
async updateToolCallDecision(options: UpdateToolCallDecisionOptions) {
|
|
415
|
-
const result = await this.client.action<{
|
|
416
|
-
updated: number;
|
|
417
|
-
toolCalls: Array<{
|
|
418
|
-
id: string;
|
|
419
|
-
name: string;
|
|
420
|
-
invokeStatus?: string;
|
|
421
|
-
status?: string;
|
|
422
|
-
auto?: boolean;
|
|
423
|
-
execution?: string;
|
|
424
|
-
willInterrupt?: boolean;
|
|
425
|
-
args?: unknown;
|
|
426
|
-
}>;
|
|
427
|
-
}>("aiConversations", "updateUserDecision", {
|
|
428
|
-
body: options,
|
|
429
|
-
});
|
|
430
|
-
return {
|
|
431
|
-
...result,
|
|
432
|
-
toolCalls: result.toolCalls.map((toolCall) => ({
|
|
433
|
-
...toolCall,
|
|
434
|
-
args: parseToolInput(toolCall.args),
|
|
435
|
-
})),
|
|
436
|
-
};
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
resumeToolCallStream(body: unknown, signal?: AbortSignal) {
|
|
440
|
-
return this.client.stream("aiConversations:resumeToolCall", {
|
|
441
|
-
body,
|
|
442
|
-
signal,
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
resumeConversationStream(sessionId: string, signal?: AbortSignal) {
|
|
447
|
-
return this.client.stream("aiConversations:resumeStream", {
|
|
448
|
-
body: { sessionId },
|
|
449
|
-
signal,
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
export const nocobaseAIService = new NocoBaseAIService();
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AIChatMessage,
|
|
3
|
-
AIConversation,
|
|
4
|
-
AIEmployee,
|
|
5
|
-
AIModel,
|
|
6
|
-
} from "../providers/types";
|
|
7
|
-
|
|
8
|
-
export type CreateAIConversationOptions = {
|
|
9
|
-
employee: AIEmployee;
|
|
10
|
-
model: AIModel;
|
|
11
|
-
systemMessage?: string;
|
|
12
|
-
skillSettings?: {
|
|
13
|
-
skills?: string[];
|
|
14
|
-
tools?: string[];
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export type UpdateToolCallDecisionOptions = {
|
|
19
|
-
sessionId: string;
|
|
20
|
-
messageId: string;
|
|
21
|
-
toolCallId: string;
|
|
22
|
-
userDecision:
|
|
23
|
-
| { type: "approve" }
|
|
24
|
-
| { type: "reject"; message?: string }
|
|
25
|
-
| {
|
|
26
|
-
type: "edit";
|
|
27
|
-
editedAction: { name: string; args: unknown };
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export type UpdatedToolCall = {
|
|
32
|
-
id: string;
|
|
33
|
-
name: string;
|
|
34
|
-
invokeStatus?: string;
|
|
35
|
-
status?: string;
|
|
36
|
-
auto?: boolean;
|
|
37
|
-
execution?: string;
|
|
38
|
-
willInterrupt?: boolean;
|
|
39
|
-
args?: unknown;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export type AIConversationActiveState = "idle" | "streaming" | "invoking";
|
|
43
|
-
|
|
44
|
-
export interface AIService {
|
|
45
|
-
listEmployees(): Promise<AIEmployee[]>;
|
|
46
|
-
listModels(): Promise<AIModel[]>;
|
|
47
|
-
updateEmployeeUserPrompt(username: string, prompt: string): Promise<void>;
|
|
48
|
-
listConversations(keyword?: string): Promise<AIConversation[]>;
|
|
49
|
-
getConversationMessages(
|
|
50
|
-
sessionId: string,
|
|
51
|
-
options?: { updateRead?: boolean }
|
|
52
|
-
): Promise<AIChatMessage[]>;
|
|
53
|
-
getConversationActiveState(
|
|
54
|
-
sessionId: string
|
|
55
|
-
): Promise<AIConversationActiveState | undefined>;
|
|
56
|
-
updateConversationTitle(sessionId: string, title: string): Promise<void>;
|
|
57
|
-
destroyConversation(sessionId: string): Promise<void>;
|
|
58
|
-
uploadFile(
|
|
59
|
-
file: File,
|
|
60
|
-
signal?: AbortSignal
|
|
61
|
-
): Promise<Record<string, unknown>>;
|
|
62
|
-
createConversation(options: CreateAIConversationOptions): Promise<string>;
|
|
63
|
-
sendMessagesStream(
|
|
64
|
-
body: unknown,
|
|
65
|
-
signal?: AbortSignal
|
|
66
|
-
): Promise<ReadableStream<Uint8Array>>;
|
|
67
|
-
resendMessagesStream(
|
|
68
|
-
body: unknown,
|
|
69
|
-
signal?: AbortSignal
|
|
70
|
-
): Promise<ReadableStream<Uint8Array>>;
|
|
71
|
-
updateToolCallDecision(
|
|
72
|
-
options: UpdateToolCallDecisionOptions
|
|
73
|
-
): Promise<{ updated: number; toolCalls: UpdatedToolCall[] }>;
|
|
74
|
-
resumeToolCallStream(
|
|
75
|
-
body: unknown,
|
|
76
|
-
signal?: AbortSignal
|
|
77
|
-
): Promise<ReadableStream<Uint8Array>>;
|
|
78
|
-
resumeConversationStream(
|
|
79
|
-
sessionId: string,
|
|
80
|
-
signal?: AbortSignal
|
|
81
|
-
): Promise<ReadableStream<Uint8Array>>;
|
|
82
|
-
}
|
|
File without changes
|
|
File without changes
|