@nocobase/plugin-ai 2.1.0-alpha.13 → 2.1.0-alpha.14

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.
Files changed (75) hide show
  1. package/dist/ai/ai-employees/atlas/index.d.ts +10 -0
  2. package/dist/ai/ai-employees/atlas/index.js +56 -0
  3. package/dist/ai/ai-employees/atlas/prompt.md +84 -0
  4. package/dist/ai/ai-employees/vera.js +1 -1
  5. package/dist/ai/tools/chartGenerator.js +1 -0
  6. package/dist/ai/tools/getSkill.js +1 -1
  7. package/dist/ai/tools/sub-agents/dispatch-sub-agent-task.d.ts +10 -0
  8. package/dist/ai/tools/sub-agents/dispatch-sub-agent-task.js +108 -0
  9. package/dist/ai/tools/sub-agents/get-ai-employee.d.ts +10 -0
  10. package/dist/ai/tools/sub-agents/get-ai-employee.js +67 -0
  11. package/dist/ai/tools/sub-agents/list-ai-employees.d.ts +10 -0
  12. package/dist/ai/tools/sub-agents/list-ai-employees.js +64 -0
  13. package/dist/ai/tools/sub-agents/shared.d.ts +33 -0
  14. package/dist/ai/tools/sub-agents/shared.js +169 -0
  15. package/dist/ai/tools/suggestions.js +2 -2
  16. package/dist/client/7237366e104efa7a.js +10 -0
  17. package/dist/client/748fbb87c1013c6e.js +10 -0
  18. package/dist/client/ai-employees/built-in/utils.d.ts +1 -0
  19. package/dist/client/ai-employees/chatbox/AIEmployeeSwitch.d.ts +0 -1
  20. package/dist/client/ai-employees/chatbox/hooks/useChatBoxActions.d.ts +5 -3
  21. package/dist/client/ai-employees/chatbox/roles.d.ts +1 -0
  22. package/dist/client/ai-employees/chatbox/stores/chat-messages.d.ts +8 -0
  23. package/dist/client/ai-employees/chatbox/utils.d.ts +15 -1
  24. package/dist/client/ai-employees/sub-agents/tools/index.d.ts +10 -0
  25. package/dist/client/ai-employees/sub-agents/ui/SubAgentDispatchCard.d.ts +21 -0
  26. package/dist/client/ai-employees/types.d.ts +19 -0
  27. package/dist/client/index.js +7 -7
  28. package/dist/externalVersion.js +16 -15
  29. package/dist/locale/en-US.json +10 -1
  30. package/dist/locale/zh-CN.json +10 -1
  31. package/dist/node_modules/fast-glob/package.json +1 -1
  32. package/dist/node_modules/flexsearch/package.json +1 -1
  33. package/dist/node_modules/fs-extra/package.json +1 -1
  34. package/dist/node_modules/nodejs-snowflake/package.json +1 -1
  35. package/dist/node_modules/openai/package.json +1 -1
  36. package/dist/node_modules/zod/package.json +1 -1
  37. package/dist/server/ai-employees/ai-conversations.d.ts +64 -0
  38. package/dist/server/ai-employees/ai-conversations.js +285 -0
  39. package/dist/server/ai-employees/ai-employee.d.ts +85 -9
  40. package/dist/server/ai-employees/ai-employee.js +264 -149
  41. package/dist/server/ai-employees/middleware/conversation.d.ts +2 -0
  42. package/dist/server/ai-employees/middleware/conversation.js +38 -5
  43. package/dist/server/ai-employees/middleware/tools.js +37 -10
  44. package/dist/server/ai-employees/prompts.d.ts +9 -1
  45. package/dist/server/ai-employees/prompts.js +24 -2
  46. package/dist/server/ai-employees/sub-agents/dispatcher.d.ts +36 -0
  47. package/dist/server/ai-employees/sub-agents/dispatcher.js +225 -0
  48. package/dist/server/ai-employees/sub-agents/index.d.ts +9 -0
  49. package/dist/server/ai-employees/sub-agents/index.js +36 -0
  50. package/dist/server/collections/ai-conversations.js +6 -0
  51. package/dist/server/llm-providers/anthropic.d.ts +1 -0
  52. package/dist/server/llm-providers/anthropic.js +2 -1
  53. package/dist/server/llm-providers/dashscope.d.ts +3 -0
  54. package/dist/server/llm-providers/dashscope.js +16 -2
  55. package/dist/server/llm-providers/deepseek.d.ts +1 -0
  56. package/dist/server/llm-providers/deepseek.js +5 -2
  57. package/dist/server/llm-providers/google-genai.d.ts +1 -0
  58. package/dist/server/llm-providers/google-genai.js +2 -1
  59. package/dist/server/llm-providers/kimi/provider.d.ts +1 -0
  60. package/dist/server/llm-providers/openai/responses.d.ts +1 -0
  61. package/dist/server/llm-providers/openai/responses.js +2 -1
  62. package/dist/server/llm-providers/provider.d.ts +1 -10
  63. package/dist/server/llm-providers/provider.js +3 -34
  64. package/dist/server/migrations/20260319000000-add-ai-conversations-from.d.ts +14 -0
  65. package/dist/server/migrations/20260319000000-add-ai-conversations-from.js +63 -0
  66. package/dist/server/plugin.d.ts +4 -0
  67. package/dist/server/plugin.js +4 -0
  68. package/dist/server/resource/aiConversations.d.ts +3 -3
  69. package/dist/server/resource/aiConversations.js +125 -159
  70. package/dist/server/types/ai-chat-conversation.type.d.ts +8 -2
  71. package/dist/server/types/ai-message.type.d.ts +7 -0
  72. package/dist/server/utils.d.ts +3 -0
  73. package/dist/server/utils.js +25 -1
  74. package/package.json +4 -2
  75. package/dist/client/27539a4356faebb1.js +0 -10
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ declare const _default: import("@nocobase/ai").AIEmployeeOptions;
10
+ export default _default;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var atlas_exports = {};
28
+ __export(atlas_exports, {
29
+ default: () => atlas_default
30
+ });
31
+ module.exports = __toCommonJS(atlas_exports);
32
+ var import_ai = require("@nocobase/ai");
33
+ var atlas_default = (0, import_ai.defineAIEmployee)({
34
+ sort: 0,
35
+ username: "atlas",
36
+ description: "Team leader of AI employee for request analysis and sub-agent orchestration",
37
+ avatar: "nocobase-044-male",
38
+ nickname: "Atlas",
39
+ position: "Team leader",
40
+ bio: "I analyze each request, identify the right specialist, and coordinate the best AI employee to complete the task efficiently.",
41
+ greeting: "Hi, I'm Atlas. Tell me what you need, and I'll route it to the right AI specialist and coordinate the result.",
42
+ tools: [
43
+ {
44
+ name: "dispatch-sub-agent-task",
45
+ autoCall: true
46
+ },
47
+ {
48
+ name: "list-ai-employees",
49
+ autoCall: true
50
+ },
51
+ {
52
+ name: "get-ai-employee",
53
+ autoCall: true
54
+ }
55
+ ]
56
+ });
@@ -0,0 +1,84 @@
1
+ You are Atlas, the main AI employee and orchestration lead for the NocoBase AI team.
2
+
3
+ Your primary job is not to solve every problem yourself. Your job is to:
4
+ 1. Understand the user's real intent
5
+ 2. Select the best specialist AI employee
6
+ 3. Coordinate the task through sub-agents
7
+ 4. Use the available routing tools to delegate efficiently
8
+ 5. Return a concise, high-quality final answer to the user
9
+
10
+ You have three core tools for orchestration:
11
+ - \`list-ai-employees\`
12
+ - \`get-ai-employee\`
13
+ - \`dispatch-sub-agent-task\`
14
+
15
+ **Mandatory default behavior**
16
+ - Treat delegation as the default for nearly every substantive user request
17
+ - Prefer using \`dispatch-sub-agent-task\` to have the most suitable AI employee answer the user
18
+ - If a \`<sub_agents>\` section is present in the system prompt, treat it as the current source of truth for available specialists
19
+ - Do not call \`list-ai-employees\` when \`<sub_agents>\` already gives enough information to choose a specialist
20
+ - Use \`list-ai-employees\` only when you genuinely need discovery because the current specialist roster is missing, ambiguous, insufficient, or likely outdated
21
+ - Use \`get-ai-employee\` when you need the full profile of a candidate before dispatching
22
+ - Do not wait for the user to tell you to delegate
23
+ - Do not give up simply because you cannot solve the task yourself
24
+ - If the request is not a trivial greeting, a pure clarification turn, or a simple meta question about your own role, attempt delegation first
25
+ - When a task seems difficult, specialized, domain-specific, or tool-dependent, delegation is required unless no suitable employee exists
26
+
27
+ **Language**
28
+ - Reply in {{$nLang}} whenever possible
29
+ - Match the user's language and tone
30
+
31
+ **Core behavior**
32
+ - Treat every new request as a routing and coordination problem first
33
+ - Prefer delegating specialized work to the most suitable sub-agent instead of answering directly yourself
34
+ - Your default execution path is to identify the right employee and then use \`dispatch-sub-agent-task\`
35
+ - Use direct handling only for simple meta-level guidance, clarification, or when no specialist is appropriate
36
+ - Preserve the user's original goal when delegating
37
+
38
+ **Required execution order**
39
+ 1. Analyze the user's goal
40
+ 2. Identify the best specialist AI employee for the request
41
+ 3. Read \`<sub_agents>\` first if it is present and use it as your routing roster
42
+ 4. Use \`list-ai-employees\` only if you still need discovery beyond what \`<sub_agents>\` already provides
43
+ 5. Use \`get-ai-employee\` if you need the full profile of a candidate before deciding
44
+ 6. Use \`dispatch-sub-agent-task\` to assign one concrete, focused task to the selected employee
45
+ 7. Summarize the result back to the user
46
+
47
+ You should skip discovery or profile inspection only when the correct specialist is already clear from the request or existing conversation context.
48
+
49
+ **Delegation policy**
50
+ - Choose the employee whose role is closest to the user's main outcome
51
+ - Inspect available AI employees from \`<sub_agents>\` before considering discovery tools
52
+ - Do not re-list employees merely to confirm information already provided in \`<sub_agents>\`
53
+ - Read the full profile of a candidate employee when needed before dispatching
54
+ - Delegate one focused task at a time
55
+ - If a request requires multiple specialist steps, break it into a clear sequence and coordinate them one by one
56
+ - Preserve the user's original intent when forwarding the task
57
+ - Forward the task in the user's language when appropriate and keep the instruction concrete
58
+
59
+ **Decision rules**
60
+ - If the user's request is ambiguous, ask a short clarifying question before dispatching
61
+ - If one specialist clearly fits, dispatch immediately
62
+ - If more than one specialist could fit, choose the one whose role is closest to the user's main outcome
63
+ - If no current specialist can solve the task well, explain the limitation clearly and provide the best high-level help you can without pretending specialist execution happened
64
+
65
+ **Anti-failure rule**
66
+ - Never stop at "I can't do that" or equivalent before checking whether another AI employee can do it
67
+ - If you are personally unable to answer, that is a signal to delegate, not a reason to quit
68
+ - Only conclude that the team cannot complete the task after checking the available roster and finding no suitable employee
69
+
70
+ **Response style**
71
+ - Be concise, calm, and execution-oriented
72
+ - Do not expose internal routing deliberation unless it helps the user
73
+ - Summarize delegated results into one coherent final answer
74
+ - When useful, briefly state which specialist handled the task and why
75
+
76
+ **Quality bar**
77
+ - Do not invent capabilities that a sub-agent does not have
78
+ - Do not claim delegation unless you actually delegated
79
+ - Keep the final output focused on the user's requested outcome, not on the coordination process
80
+
81
+ **Tool usage notes**
82
+ - \`list-ai-employees\` returns lightweight profiles for discovery only; it is not a mandatory first step when \`<sub_agents>\` already provides the roster
83
+ - \`get-ai-employee\` returns the full employee profile; if the employee has no custom \`about\`, the response may use \`defaultPrompt\`
84
+ - \`dispatch-sub-agent-task\` starts a sub-agent conversation and returns both the sub-session ID and the final answer
@@ -46,7 +46,7 @@ Provide accurate, timely, and well-sourced answers to user questions by searchin
46
46
  // --- CORE OPERATING PROCESS (The "How") ---
47
47
  You have a default, step-by-step process for handling every user request.
48
48
  1. **Deconstruct & Plan:** First, analyze the user's question to identify the core entities, keywords, and the specific information needed. Formulate multiple, precise search queries to cover different angles of the topic.
49
- 2. **Search & Aggregate:** Execute the search queries using the provided internet search tool. You must gather information from at least 3-5 different, high-quality sources to build a comprehensive and balanced view.
49
+ 2. **Search & Aggregate:** Execute the search queries on public internet. You must gather information from at least 3-5 different, high-quality sources to build a comprehensive and balanced view.
50
50
  3. **Synthesize & Verify:** Critically evaluate the search results. Cross-reference key facts between different sources. Prioritize information from reputable news outlets, official documentation, academic papers, and established expert organizations. Discard or explicitly flag unsubstantiated or clearly outdated claims.
51
51
  4. **Structure & Report:** **Based on your findings, structure your response according to the following priorities:**
52
52
  * **Priority 1: Direct Answer.** Your primary goal is to directly answer the user's question. Synthesize the verified findings into a clear, concise summary. It is mandatory that every sentence containing a factual claim MUST end with a citation marker in the format \`\`.
@@ -44,6 +44,7 @@ var import_zod = require("zod");
44
44
  var import_package = __toESM(require("../../../package.json"));
45
45
  var chartGenerator_default = (0, import_ai.defineTools)({
46
46
  scope: "GENERAL",
47
+ defaultPermission: "ALLOW",
47
48
  introduction: {
48
49
  title: `{{t("Chart generator", { ns: "${import_package.default.name}" })}}`,
49
50
  about: `{{t("Generates ECharts options (JSON) based on user input or data context.", { ns: "${import_package.default.name}" })}}`
@@ -56,7 +56,7 @@ var getSkill_default = (0, import_ai.defineTools)({
56
56
  skillName: import_zod.z.string().describe("Name of skill to load")
57
57
  })
58
58
  },
59
- invoke: async (ctx, args, id) => {
59
+ invoke: async (ctx, args) => {
60
60
  const target = await ctx.app.aiManager.skillsManager.getSkills(args.skillName);
61
61
  if (!target) {
62
62
  return {
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ declare const _default: import("@nocobase/ai").ToolsOptions;
10
+ export default _default;
@@ -0,0 +1,108 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var dispatch_sub_agent_task_exports = {};
38
+ __export(dispatch_sub_agent_task_exports, {
39
+ default: () => dispatch_sub_agent_task_default
40
+ });
41
+ module.exports = __toCommonJS(dispatch_sub_agent_task_exports);
42
+ var import_ai = require("@nocobase/ai");
43
+ var import_zod = require("zod");
44
+ var import_shared = require("./shared");
45
+ var import_package = __toESM(require("../../../../package.json"));
46
+ var dispatch_sub_agent_task_default = (0, import_ai.defineTools)({
47
+ scope: "SPECIFIED",
48
+ defaultPermission: "ALLOW",
49
+ introduction: {
50
+ title: `{{t("AI employee task dispatching", { ns: "${import_package.default.name}" })}}`,
51
+ about: `{{t("Awaken and assign specific tasks to ai employees", { ns: "${import_package.default.name}" })}}`
52
+ },
53
+ definition: {
54
+ name: "dispatch-sub-agent-task",
55
+ description: "Dispatch a question to a target AI employee and return the sub-session result.",
56
+ schema: import_zod.z.object({
57
+ username: import_zod.z.string().describe("The username of the target AI employee."),
58
+ question: import_zod.z.string().describe("The question or task that should be executed by the target AI employee.")
59
+ })
60
+ },
61
+ async invoke(ctx, { username, question }, { toolCallId, writer }) {
62
+ var _a, _b, _c, _d, _e, _f, _g, _h;
63
+ const sessionId = (_c = (_b = (_a = ctx.action) == null ? void 0 : _a.params) == null ? void 0 : _b.values) == null ? void 0 : _c.sessionId;
64
+ const userId = (_e = (_d = ctx.auth) == null ? void 0 : _d.user) == null ? void 0 : _e.id;
65
+ if (!userId) {
66
+ throw new Error("User not authenticated");
67
+ }
68
+ const plugin = (0, import_shared.getAIPlugin)(ctx);
69
+ const employee = await (0, import_shared.getAccessibleAIEmployee)(ctx, username);
70
+ if (!employee) {
71
+ throw new Error(`AI employee "${username}" not found`);
72
+ }
73
+ let subSessionId;
74
+ const skillSettings = await (0, import_shared.getSkillSettingsFromMain)(ctx);
75
+ const existedConversation = await plugin.aiConversationsManager.resolveSubAgentConversation(sessionId, toolCallId);
76
+ if (existedConversation) {
77
+ subSessionId = existedConversation.sessionId;
78
+ } else {
79
+ const newConversation = await plugin.aiConversationsManager.create({
80
+ userId,
81
+ aiEmployee: {
82
+ username: employee.get("username")
83
+ },
84
+ title: question.slice(0, 30),
85
+ from: "sub-agent",
86
+ options: {
87
+ skillSettings
88
+ }
89
+ });
90
+ subSessionId = newConversation.sessionId;
91
+ }
92
+ await (0, import_shared.updateMessageMetadata)(ctx, toolCallId, subSessionId, "pending");
93
+ const answer = await plugin.subAgentsDispatcher.run({
94
+ ctx,
95
+ sessionId: subSessionId,
96
+ employee,
97
+ model: ((_h = (_g = (_f = ctx.action) == null ? void 0 : _f.params) == null ? void 0 : _g.values) == null ? void 0 : _h.model) ?? employee.get("modelSettings"),
98
+ question,
99
+ skillSettings,
100
+ writer
101
+ });
102
+ await (0, import_shared.updateMessageMetadata)(ctx, toolCallId, subSessionId, "completed");
103
+ return {
104
+ sessionId: subSessionId,
105
+ answer
106
+ };
107
+ }
108
+ });
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ declare const _default: import("@nocobase/ai").ToolsOptions;
10
+ export default _default;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var get_ai_employee_exports = {};
38
+ __export(get_ai_employee_exports, {
39
+ default: () => get_ai_employee_default
40
+ });
41
+ module.exports = __toCommonJS(get_ai_employee_exports);
42
+ var import_ai = require("@nocobase/ai");
43
+ var import_zod = require("zod");
44
+ var import_shared = require("./shared");
45
+ var import_package = __toESM(require("../../../../package.json"));
46
+ var get_ai_employee_default = (0, import_ai.defineTools)({
47
+ scope: "SPECIFIED",
48
+ defaultPermission: "ALLOW",
49
+ introduction: {
50
+ title: `{{t("Get AI employee", { ns: "${import_package.default.name}" })}}`,
51
+ about: `{{t("Get the detailed definition of AI employee", { ns: "${import_package.default.name}" })}}`
52
+ },
53
+ definition: {
54
+ name: "get-ai-employee",
55
+ description: "Get the detailed profile of one accessible AI employee by username.",
56
+ schema: import_zod.z.object({
57
+ username: import_zod.z.string().describe("The username of the AI employee.")
58
+ })
59
+ },
60
+ async invoke(ctx, args) {
61
+ const employee = await (0, import_shared.getAccessibleAIEmployee)(ctx, args.username);
62
+ if (!employee) {
63
+ throw new Error(`AI employee "${args.username}" not found`);
64
+ }
65
+ return (0, import_shared.serializeEmployeeDetail)(ctx, employee);
66
+ }
67
+ });
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ declare const _default: import("@nocobase/ai").ToolsOptions;
10
+ export default _default;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var list_ai_employees_exports = {};
38
+ __export(list_ai_employees_exports, {
39
+ default: () => list_ai_employees_default
40
+ });
41
+ module.exports = __toCommonJS(list_ai_employees_exports);
42
+ var import_ai = require("@nocobase/ai");
43
+ var import_zod = require("zod");
44
+ var import_shared = require("./shared");
45
+ var import_package = __toESM(require("../../../../package.json"));
46
+ var list_ai_employees_default = (0, import_ai.defineTools)({
47
+ scope: "SPECIFIED",
48
+ defaultPermission: "ALLOW",
49
+ introduction: {
50
+ title: `{{t("List AI employee", { ns: "${import_package.default.name}" })}}`,
51
+ about: `{{t("Get the list of available AI employees", { ns: "${import_package.default.name}" })}}`
52
+ },
53
+ definition: {
54
+ name: "list-ai-employees",
55
+ description: "List accessible AI employees with their basic profile and skill settings.",
56
+ schema: import_zod.z.object({}).describe("No input is required.")
57
+ },
58
+ async invoke(ctx) {
59
+ const employees = await (0, import_shared.listAccessibleAIEmployees)(ctx);
60
+ return {
61
+ aiEmployees: employees.map((employee) => (0, import_shared.serializeEmployeeSummary)(ctx, employee))
62
+ };
63
+ }
64
+ });
@@ -0,0 +1,33 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import type { Context } from '@nocobase/actions';
10
+ import type { Model } from '@nocobase/database';
11
+ import type PluginAIServer from '../../../server/plugin';
12
+ export declare const getAIPlugin: (ctx: Context) => PluginAIServer;
13
+ export declare function listAccessibleAIEmployees(ctx: Context): Promise<Model[]>;
14
+ export declare function getAccessibleAIEmployee(ctx: Context, username: string): Promise<Model | null>;
15
+ export declare function serializeEmployeeSummary(ctx: Context, employee: Model): {
16
+ username: string;
17
+ nickname: string;
18
+ position: string;
19
+ bio: string;
20
+ greeting: string;
21
+ skillSettings: any;
22
+ };
23
+ export declare function serializeEmployeeDetail(ctx: Context, employee: Model): {
24
+ about: any;
25
+ username: string;
26
+ nickname: string;
27
+ position: string;
28
+ bio: string;
29
+ greeting: string;
30
+ skillSettings: any;
31
+ };
32
+ export declare const getSkillSettingsFromMain: (ctx: Context) => Promise<any>;
33
+ export declare const updateMessageMetadata: (ctx: Context, toolCallId: string, subSessionId: string, status: 'pending' | 'completed') => Promise<void>;
@@ -0,0 +1,169 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var shared_exports = {};
28
+ __export(shared_exports, {
29
+ getAIPlugin: () => getAIPlugin,
30
+ getAccessibleAIEmployee: () => getAccessibleAIEmployee,
31
+ getSkillSettingsFromMain: () => getSkillSettingsFromMain,
32
+ listAccessibleAIEmployees: () => listAccessibleAIEmployees,
33
+ serializeEmployeeDetail: () => serializeEmployeeDetail,
34
+ serializeEmployeeSummary: () => serializeEmployeeSummary,
35
+ updateMessageMetadata: () => updateMessageMetadata
36
+ });
37
+ module.exports = __toCommonJS(shared_exports);
38
+ const getAIPlugin = (ctx) => ctx.app.pm.get("ai");
39
+ async function listAccessibleAIEmployees(ctx) {
40
+ const filter = await buildAccessibleEmployeeFilter(ctx);
41
+ return ctx.db.getRepository("aiEmployees").find({
42
+ filter,
43
+ sort: ["sort", "username"]
44
+ });
45
+ }
46
+ async function getAccessibleAIEmployee(ctx, username) {
47
+ const filter = await buildAccessibleEmployeeFilter(ctx);
48
+ return ctx.db.getRepository("aiEmployees").findOne({
49
+ filter: {
50
+ ...filter,
51
+ username
52
+ }
53
+ });
54
+ }
55
+ function localizeBuiltInInfo(ctx, employee) {
56
+ const plugin = getAIPlugin(ctx);
57
+ plugin.builtInManager.setupBuiltInInfo(ctx, employee);
58
+ }
59
+ function serializeEmployeeSummary(ctx, employee) {
60
+ localizeBuiltInInfo(ctx, employee);
61
+ return {
62
+ username: employee.get("username"),
63
+ nickname: employee.get("nickname"),
64
+ position: employee.get("position"),
65
+ bio: employee.get("bio"),
66
+ greeting: employee.get("greeting"),
67
+ skillSettings: employee.get("skillSettings")
68
+ };
69
+ }
70
+ function serializeEmployeeDetail(ctx, employee) {
71
+ localizeBuiltInInfo(ctx, employee);
72
+ const about = employee.get("about") || employee.get("defaultPrompt") || "";
73
+ return {
74
+ ...serializeEmployeeSummary(ctx, employee),
75
+ about
76
+ };
77
+ }
78
+ async function buildAccessibleEmployeeFilter(ctx) {
79
+ var _a;
80
+ const filter = {
81
+ enabled: true
82
+ };
83
+ if ((_a = ctx.state.currentRoles) == null ? void 0 : _a.includes("root")) {
84
+ return filter;
85
+ }
86
+ const roleMappings = await ctx.db.getRepository("rolesAiEmployees").find({
87
+ filter: {
88
+ roleName: ctx.state.currentRoles
89
+ }
90
+ });
91
+ const usernames = roleMappings.map((item) => item.aiEmployee);
92
+ filter.username = usernames.length ? usernames : "__NO_ACCESSIBLE_AI_EMPLOYEE__";
93
+ return filter;
94
+ }
95
+ const getSkillSettingsFromMain = async (ctx) => {
96
+ var _a, _b, _c, _d, _e, _f;
97
+ const sessionId = (_c = (_b = (_a = ctx.action) == null ? void 0 : _a.params) == null ? void 0 : _b.values) == null ? void 0 : _c.sessionId;
98
+ if (!sessionId) {
99
+ return null;
100
+ }
101
+ const aiConversation = await ctx.db.getRepository("aiConversations").findOne({
102
+ filter: {
103
+ sessionId,
104
+ userId: (_e = (_d = ctx.auth) == null ? void 0 : _d.user) == null ? void 0 : _e.id
105
+ }
106
+ });
107
+ return (_f = aiConversation == null ? void 0 : aiConversation.options) == null ? void 0 : _f.skillSettings;
108
+ };
109
+ const updateMessageMetadata = async (ctx, toolCallId, subSessionId, status) => {
110
+ var _a, _b, _c;
111
+ const sessionId = (_c = (_b = (_a = ctx.action) == null ? void 0 : _a.params) == null ? void 0 : _b.values) == null ? void 0 : _c.sessionId;
112
+ if (!sessionId) {
113
+ return;
114
+ }
115
+ const aiToolMessage = await ctx.db.getRepository("aiToolMessages").findOne({
116
+ filter: {
117
+ sessionId,
118
+ toolCallId
119
+ }
120
+ });
121
+ if (!aiToolMessage) {
122
+ return;
123
+ }
124
+ const aiMessage = await ctx.db.getRepository("aiMessages").findOne({
125
+ filter: {
126
+ sessionId,
127
+ messageId: aiToolMessage.messageId
128
+ }
129
+ });
130
+ if (!aiMessage) {
131
+ return;
132
+ }
133
+ const metadata = aiMessage.metadata ?? {};
134
+ if (!metadata.subAgentConversations) {
135
+ metadata.subAgentConversations = [];
136
+ }
137
+ const subAgentConversations = metadata.subAgentConversations;
138
+ const existingConversation = subAgentConversations.find((item) => item.sessionId === subSessionId);
139
+ if (existingConversation) {
140
+ existingConversation.toolCallId = toolCallId;
141
+ existingConversation.status = status;
142
+ } else {
143
+ subAgentConversations.push({
144
+ sessionId: subSessionId,
145
+ toolCallId,
146
+ status
147
+ });
148
+ }
149
+ metadata.subAgentConversations = subAgentConversations;
150
+ await ctx.db.getRepository("aiMessages").update({
151
+ values: {
152
+ metadata
153
+ },
154
+ filter: {
155
+ sessionId,
156
+ messageId: aiMessage.messageId
157
+ }
158
+ });
159
+ };
160
+ // Annotate the CommonJS export names for ESM import in node:
161
+ 0 && (module.exports = {
162
+ getAIPlugin,
163
+ getAccessibleAIEmployee,
164
+ getSkillSettingsFromMain,
165
+ listAccessibleAIEmployees,
166
+ serializeEmployeeDetail,
167
+ serializeEmployeeSummary,
168
+ updateMessageMetadata
169
+ });