@nocobase/plugin-ai 2.2.0-alpha.11 → 2.2.0-alpha.12

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 (120) hide show
  1. package/dist/ai/docs/nocobase/ai-employees/block/ai-chat-box.md +133 -0
  2. package/dist/ai/docs/nocobase/ai-employees/knowledge-base/knowledge-base/documents.md +1 -1
  3. package/dist/ai/docs/nocobase/ai-employees/knowledge-base/knowledge-base/index.md +11 -7
  4. package/dist/ai/docs/nocobase/ai-employees/knowledge-base/knowledge-base/settings.md +12 -8
  5. package/dist/ai/docs/nocobase/ai-employees/knowledge-base/vector-database.md +3 -3
  6. package/dist/ai/docs/nocobase/ai-employees/workflow/nodes/knowledge/create-document.md +1 -1
  7. package/dist/ai/docs/nocobase/ops-management/migration-manager/built-in-tables.md +1 -2
  8. package/dist/ai/docs/nocobase/runjs/context/ai.md +194 -4
  9. package/dist/ai/tools/getSkill.js +1 -1
  10. package/dist/client/244.8631eb5cf3f05e21.js +10 -0
  11. package/dist/client/681.6ffbc9329b9ac242.js +10 -0
  12. package/dist/client/index.d.ts +1 -3
  13. package/dist/client/index.js +8 -8
  14. package/dist/client-v2/244.c428e645ecb94414.js +10 -0
  15. package/dist/client-v2/420.b2aedb1ff71fca0e.js +10 -0
  16. package/dist/client-v2/681.6890caa389564ff7.js +10 -0
  17. package/dist/client-v2/ai-employees/AIEmployeeShortcut.d.ts +2 -0
  18. package/dist/client-v2/ai-employees/AddContextButton.d.ts +2 -0
  19. package/dist/client-v2/ai-employees/chatbox/components/AIEmployeeSwitcher.d.ts +1 -0
  20. package/dist/client-v2/ai-employees/chatbox/components/ChatBoxUnreadBadge.d.ts +17 -0
  21. package/dist/client-v2/ai-employees/chatbox/components/Conversations.d.ts +9 -1
  22. package/dist/client-v2/ai-employees/chatbox/components/MessageRenderers.d.ts +1 -1
  23. package/dist/client-v2/ai-employees/chatbox/components/Messages.d.ts +5 -1
  24. package/dist/client-v2/ai-employees/chatbox/components/ModelSwitcher.d.ts +4 -0
  25. package/dist/client-v2/ai-employees/chatbox/components/Sender.d.ts +33 -1
  26. package/dist/client-v2/ai-employees/chatbox/components/index.d.ts +1 -0
  27. package/dist/client-v2/ai-employees/chatbox/hooks/useChat.d.ts +8 -5
  28. package/dist/client-v2/ai-employees/chatbox/hooks/useChatBoxActions.d.ts +3 -2
  29. package/dist/client-v2/ai-employees/chatbox/hooks/useChatBoxEffect.d.ts +2 -1
  30. package/dist/client-v2/ai-employees/chatbox/hooks/useChatConversationActions.d.ts +3 -2
  31. package/dist/client-v2/ai-employees/chatbox/hooks/useChatMessageActions.d.ts +4 -2
  32. package/dist/client-v2/ai-employees/chatbox/hooks/useToolCallActions.d.ts +3 -1
  33. package/dist/client-v2/ai-employees/chatbox/hooks/useUploadFiles.d.ts +13 -3
  34. package/dist/client-v2/ai-employees/chatbox/hooks/useWorkflowTasks.d.ts +3 -2
  35. package/dist/client-v2/ai-employees/chatbox/index.d.ts +17 -0
  36. package/dist/client-v2/ai-employees/chatbox/roles.d.ts +2 -153
  37. package/dist/client-v2/ai-employees/chatbox/stores/chat-box.d.ts +46 -31
  38. package/dist/client-v2/ai-employees/chatbox/stores/chat-conversations.d.ts +7 -7
  39. package/dist/client-v2/ai-employees/chatbox/stores/chat-messages.d.ts +23 -18
  40. package/dist/client-v2/ai-employees/chatbox/stores/chat-sender.d.ts +43 -0
  41. package/dist/client-v2/ai-employees/chatbox/stores/chat-tool-call.d.ts +6 -5
  42. package/dist/client-v2/ai-employees/chatbox/stores/chat-tools.d.ts +11 -5
  43. package/dist/client-v2/ai-employees/chatbox/stores/mounted-chat-boxes.d.ts +20 -0
  44. package/dist/client-v2/ai-employees/chatbox/stores/runtime.d.ts +43 -0
  45. package/dist/client-v2/ai-employees/chatbox/stores/workflow-tasks.d.ts +22 -10
  46. package/dist/client-v2/ai-employees/chatbox/upload.d.ts +19 -0
  47. package/dist/client-v2/ai-employees/chatbox/utils.d.ts +28 -4
  48. package/dist/client-v2/ai-employees/tools/SuggestionsOptionsCard.d.ts +1 -1
  49. package/dist/client-v2/ai-employees/tools/WorkflowTaskOutputCard.d.ts +1 -1
  50. package/dist/client-v2/ai-employees/types.d.ts +27 -0
  51. package/dist/client-v2/block/ai-chat-box/AIChatBoxBlockModel.d.ts +21 -0
  52. package/dist/client-v2/block/ai-chat-box/AIChatBoxCoreModel.d.ts +13 -0
  53. package/dist/client-v2/block/ai-chat-box/components/AIChatBoxCoreView.d.ts +10 -0
  54. package/dist/client-v2/block/ai-chat-box/components/AIChatBoxView.d.ts +12 -0
  55. package/dist/client-v2/block/ai-chat-box/index.d.ts +14 -0
  56. package/dist/client-v2/block/ai-chat-box/settings.d.ts +12 -0
  57. package/dist/client-v2/block/ai-chat-box/sub-models.d.ts +26 -0
  58. package/dist/client-v2/block/ai-chat-box/types.d.ts +38 -0
  59. package/dist/client-v2/block/ai-chat-box/utils.d.ts +26 -0
  60. package/dist/client-v2/index.d.ts +3 -5
  61. package/dist/client-v2/index.js +3 -3
  62. package/dist/client-v2/llm-services/model-select.d.ts +33 -0
  63. package/dist/client-v2/llm-services/utils.d.ts +1 -0
  64. package/dist/client-v2/manager/ai-manager.d.ts +8 -3
  65. package/dist/client-v2/models/ai-employees/AIEmployeeActionModel.d.ts +4 -1
  66. package/dist/client-v2/models/ai-employees/AIEmployeeShortcutModel.d.ts +5 -0
  67. package/dist/client-v2/pages/EmployeesPage.d.ts +1 -0
  68. package/dist/client-v2/runjs/registerAIEmployeeRunJSFacade.d.ts +1 -0
  69. package/dist/common/ai-employee-validation.d.ts +15 -0
  70. package/dist/common/ai-employee-validation.js +61 -0
  71. package/dist/common/error-codes.d.ts +13 -0
  72. package/dist/common/error-codes.js +48 -0
  73. package/dist/common/llm-service-models.d.ts +16 -0
  74. package/dist/common/llm-service-models.js +84 -0
  75. package/dist/externalVersion.js +15 -15
  76. package/dist/locale/en-US.json +62 -0
  77. package/dist/locale/zh-CN.json +62 -0
  78. package/dist/node_modules/@langchain/mistralai/package.json +1 -1
  79. package/dist/node_modules/@langchain/xai/package.json +1 -1
  80. package/dist/node_modules/fs-extra/package.json +1 -1
  81. package/dist/node_modules/jsonrepair/package.json +1 -1
  82. package/dist/node_modules/just-bash/package.json +1 -1
  83. package/dist/node_modules/nodejs-snowflake/package.json +1 -1
  84. package/dist/node_modules/openai/package.json +1 -1
  85. package/dist/node_modules/zod/package.json +1 -1
  86. package/dist/server/ai-employees/ai-conversations.d.ts +2 -1
  87. package/dist/server/ai-employees/ai-conversations.js +2 -0
  88. package/dist/server/ai-employees/ai-employee.d.ts +1 -0
  89. package/dist/server/ai-employees/ai-employee.js +6 -0
  90. package/dist/server/ai-employees/middleware/conversation.js +9 -2
  91. package/dist/server/collections/ai-conversations.js +5 -0
  92. package/dist/server/document-loader/constants.js +0 -1
  93. package/dist/server/plugin.d.ts +1 -0
  94. package/dist/server/plugin.js +25 -0
  95. package/dist/server/resource/aiConversations.js +6 -2
  96. package/dist/server/resource/aiEmployees.d.ts +2 -0
  97. package/dist/server/resource/aiEmployees.js +62 -0
  98. package/dist/server/resource/aiWorkflowTasks.js +9 -1
  99. package/dist/server/resource/llmServices.d.ts +11 -0
  100. package/dist/server/resource/llmServices.js +85 -0
  101. package/dist/server/types/knowledge-base.type.d.ts +6 -2
  102. package/dist/swagger/common.d.ts +143 -0
  103. package/dist/swagger/common.js +144 -0
  104. package/dist/swagger/employees.d.ts +301 -0
  105. package/dist/swagger/employees.js +131 -0
  106. package/dist/swagger/index.d.ts +1588 -0
  107. package/dist/swagger/index.js +62 -0
  108. package/dist/swagger/llm.d.ts +555 -0
  109. package/dist/swagger/llm.js +247 -0
  110. package/dist/swagger/schemas.d.ts +736 -0
  111. package/dist/swagger/schemas.js +381 -0
  112. package/package.json +2 -2
  113. package/dist/ai/docs/nocobase/ai-employees/knowledge-base/vector-store.md +0 -24
  114. package/dist/client/372.49163fac65cef81c.js +0 -10
  115. package/dist/client/681.399948c18d753667.js +0 -10
  116. package/dist/client-v2/372.387161cdeb106987.js +0 -10
  117. package/dist/client-v2/406.341be51205c674e0.js +0 -10
  118. package/dist/client-v2/681.082f4f1c7b841983.js +0 -10
  119. package/dist/client-v2/ai-employees/chatbox/stores/create-selectors.d.ts +0 -46
  120. package/dist/client-v2/ai-employees/chatbox/utils/normalizeTriggerTaskOptions.d.ts +0 -19
@@ -0,0 +1,133 @@
1
+ ---
2
+ pkg: '@nocobase/plugin-ai'
3
+ title: 'AI Chat box block'
4
+ description: 'User guide for NocoBase administrators and page builders covering how to add an AI Chat box block, configure conversation capabilities, set Work context, manage conversations, and add Actions.'
5
+ keywords: 'AI Chat box,AI Employee,page block,Work context,Scope,Actions,NocoBase'
6
+ ---
7
+
8
+ # AI Chat box block
9
+
10
+ In NocoBase, **AI Chat box** is an AI conversation block that can be added directly to a page. You can place it on a business page to provide a fixed AI assistant entry point for that page.
11
+
12
+ Each AI Chat box block has its own current conversation and input state. Page builders can also restrict the available AI employees, models, file uploads, web search, and work context to suit the current business scenario.
13
+
14
+ :::tip Before you start
15
+
16
+ First [configure an LLM service](../features/llm-service.md) and [enable at least one AI employee](../features/enable-ai-employee.md).
17
+
18
+ :::
19
+
20
+ ## Add an AI Chat box block
21
+
22
+ 1. Open the page you want to configure.
23
+ 2. Click `UI Editor` in the upper-right corner to enter page editing mode.
24
+ 3. Click `Add block`.
25
+ 4. Under `Other blocks`, select `AI chat box`.
26
+
27
+ ![Select AI chat box from the Add block menu](https://static-docs.nocobase.com/ai-employees/block/ai-chat-box/2026-07-22/add-ai-chat-box-block-3.png)
28
+
29
+ ## Understand the block structure
30
+
31
+ ![AI Chat box block](https://static-docs.nocobase.com/ai-employees/block/ai-chat-box/2026-07-22/ai-chat-box-overview-2.png)
32
+
33
+ An AI Chat box contains three areas from top to bottom:
34
+
35
+ - **Top action area** — conversation list, Actions, custom actions, and new conversation buttons; a messages button also appears when the messages area is hidden
36
+ - **Messages area** — displays messages in the current draft or conversation
37
+ - **Sender area** — input box, context selection, file upload, web search, AI employee selection, model selection, send button, and disclaimer
38
+
39
+ ### Add display content inside the block body
40
+
41
+ In page editing mode, click `Add block` inside the AI Chat box to add any of the following blocks above the chat area:
42
+
43
+ - JS block
44
+ - Iframe
45
+ - Markdown
46
+
47
+ These blocks are useful for displaying instructions, external pages, or supporting information. The internal Add block menu only provides these three block types and does not allow another AI Chat box to be nested inside it.
48
+
49
+ ## Configure the AI Chat box
50
+
51
+ Move the pointer over the block and open its settings menu. Click `Edit chat box` to configure the conversation scope, default message, Work context, AI employees, and models.
52
+
53
+ ![Edit chat box settings dialog](https://static-docs.nocobase.com/ai-employees/block/ai-chat-box/2026-07-22/edit-chat-box-settings-2.png)
54
+
55
+ ### Edit chat box settings
56
+
57
+ | Setting | Description |
58
+ | --- | --- |
59
+ | `Scope` | Controls which AI Chat boxes share a conversation list. A new block uses its own block UID by default to keep conversations separate. |
60
+ | `Background` | Adds a system prompt after the AI employee definition to provide the role, objective, or response requirements for the current page. |
61
+ | `Default user message` | Prefills a default user message in the sender when a new conversation starts. |
62
+ | `Work context` | Selects page blocks to place in a new draft by default. |
63
+ | `AI employees` | Restricts the business AI employees that can be selected in this block. Leave it empty to allow all available business AI employees. |
64
+ | `Models` | Restricts the models that can be selected in this block. Leave it empty to allow all available models. |
65
+
66
+ ### Other block settings
67
+
68
+ | Setting | Description |
69
+ | --- | --- |
70
+ | `Show messages` | Controls whether the messages area is displayed directly in the block. When disabled, use the messages button at the top to open the right-side panel. |
71
+ | `Sender placeholder` | Changes the placeholder shown in the sender. |
72
+ | `Enable add context` | Shows or hides the context selection entry in the sender. |
73
+ | `Enable upload files` | Shows or hides the file upload entry. When disabled, pasting a file does not start an upload. |
74
+ | `Enable web search` | Shows or hides the web search switch. Disabling it also turns off web search for the current draft. |
75
+ | `Enable employee select` | Shows or hides the AI employee selector. |
76
+ | `Enable model select` | Shows or hides the model selector. |
77
+ | `Show disclaimer` | Shows or hides the AI disclaimer below the sender. |
78
+
79
+ ## Configure Work context
80
+
81
+ In `Work context` under `Edit chat box`, click the add context button, select `Pick block`, and then select the page block you want to provide to the AI. After saving, the selected block becomes the default work context for new conversations and can be removed from the sender before sending.
82
+
83
+ ## Hide the messages area and use the right-side panel
84
+
85
+ After disabling `Show messages`, the block body only keeps the sender area. A messages button appears at the top; click it to open the messages panel from the right.
86
+
87
+ ![Right-side messages panel with the messages area hidden](https://static-docs.nocobase.com/ai-employees/block/ai-chat-box/2026-07-22/messages-side-panel-2.png)
88
+
89
+ When the panel is open, the rest of the block is covered by an overlay. Click the overlay or click the messages button again to close the panel.
90
+
91
+ This layout works well when the AI Chat box is used as a lightweight input entry on a page: keep only the sender visible and open the panel when you need to review messages.
92
+
93
+ ## Manage conversation history
94
+
95
+ Click the conversation list button in the upper-left corner of the block to view conversation history under the current Scope.
96
+
97
+ Keep these rules in mind:
98
+
99
+ - Multiple AI Chat boxes with the same Scope can see the same conversation list
100
+ - Each block still has its own current conversation, sender draft, AI employee, model, attachments, and context state
101
+ - The global floating chatbox does not filter by block Scope, so it does not hide conversations with a Scope
102
+ - After clearing Scope, the block no longer filters the conversation list by Scope and displays both conversations without a Scope and conversations using other Scopes
103
+
104
+ Normally, keeping the Scope generated for a new block is enough to separate the history of each page assistant. Only configure the same Scope when multiple blocks need to share the same conversation list.
105
+
106
+ ## Add Actions
107
+
108
+ In page editing mode, click `Actions` at the top of the block to add either of the following actions:
109
+
110
+ - JS Action
111
+ - AI employee
112
+
113
+ After adding an AI employee, you can configure shortcut tasks for that employee.
114
+
115
+ The `Chat box uid` setting in a shortcut task specifies which AI Chat box runs the task. An AI employee added directly inside an AI Chat box points to the current block UID by default.
116
+
117
+ If the specified AI Chat box is not mounted, NocoBase reports that the target block cannot be found and does not fall back to the global floating chatbox. See [AI employee shortcut tasks](../features/task.md) for detailed configuration.
118
+
119
+ ## Configure a page-specific assistant
120
+
121
+ The following steps create a lightweight AI assistant for a page:
122
+
123
+ 1. Add an AI Chat box block and move it to the appropriate position on the page.
124
+ 2. Enter a page-specific Background under `Edit chat box`.
125
+ 3. Select one or more Work contexts.
126
+ 4. Restrict the available employees and models under `AI employees` and `Models`.
127
+ 5. Exit editing mode, enter a question, and send it.
128
+
129
+ ## Notes
130
+
131
+ - The AI Chat box block and the global floating chatbox in the lower-right corner are separate entry points; their current conversations and input states are not synchronized automatically
132
+ - Only JS block, Iframe, and Markdown can be added from `Add block` inside an AI Chat box
133
+ - Changing Scope affects the conversation list query and does not copy the conversation or draft currently open in another block
@@ -17,7 +17,7 @@ After opening the knowledge base detail page, click Documents in the left sideba
17
17
 
18
18
  Click Upload in the upper-right corner to upload files. After upload, documents automatically enter segment generation and vectorization. Status first shows Pending, then changes to Success after processing. If processing fails, it shows Error, and an error icon appears next to the filename.
19
19
 
20
- Supported document types include: `txt`, `md`, `json`, `csv`, `xls`, `xlsx`, `pdf`, `doc`, `docx`, `ppt`, and `pptx`.
20
+ Supported document types include: `txt`, `md`, `json`, `csv`, `xls`, `xlsx`, `pdf`, `doc`, `docx`, and `pptx`.
21
21
 
22
22
  :::tip PDF documents
23
23
 
@@ -13,7 +13,7 @@ A knowledge base is the foundation of RAG retrieval. You can add product manuals
13
13
 
14
14
  For most scenarios, a Local knowledge base is enough. Only consider Readonly or External knowledge bases when documents and vector data are already maintained by an external system.
15
15
 
16
- ![](https://static-docs.nocobase.com/20260617003643.png)
16
+ ![](https://static-docs.nocobase.com/20260728222403.png)
17
17
 
18
18
  ## Open knowledge base management
19
19
 
@@ -23,15 +23,15 @@ Click a knowledge base card to open its detail page:
23
23
 
24
24
  - Documents is used to upload documents, run vectorization, and open segment management
25
25
  - Hit tests is used to test which segments can be matched by a query
26
- - Settings is used to adjust basic information, vector store, and default segmentation parameters
26
+ - Settings is used to adjust basic information, vector configuration, and default segmentation parameters
27
27
 
28
- ![](https://static-docs.nocobase.com/20260617004104.png)
28
+ ![](https://static-docs.nocobase.com/20260728222406.png)
29
29
 
30
30
  ## Create a knowledge base
31
31
 
32
32
  Click Add new in the upper-right corner to create a knowledge base. The menu shows three types: Local, Readonly, and External.
33
33
 
34
- ![](https://static-docs.nocobase.com/20260617003505.png)
34
+ ![](https://static-docs.nocobase.com/20260728222404.png)
35
35
 
36
36
  The three knowledge base types have different capability boundaries:
37
37
 
@@ -45,19 +45,23 @@ Local knowledge bases are recommended by default. Only consider Readonly or Exte
45
45
 
46
46
  A Local knowledge base usually needs the following information:
47
47
 
48
- ![](https://static-docs.nocobase.com/20260617003603.png)
48
+ ![](https://static-docs.nocobase.com/20260728222405.png)
49
49
 
50
50
  - Key: unique identifier of the knowledge base. It cannot be changed after creation
51
51
  - Name: knowledge base name
52
52
  - File storage: where original documents and segment files are stored
53
- - Vector store: vector store used to generate and retrieve vectors
53
+ - Vector database: select a configured vector database. See [Vector database](../vector-database)
54
+ - LLM service: select a configured LLM service that supports embedding models. See [LLM service management](../../features/llm-service)
55
+ - Embedding model: select or enter the embedding model used to generate and retrieve vectors; available models update when the LLM service changes
54
56
  - Description: knowledge base description
55
57
  - Split document, Chunk size, and Chunk overlap: default segmentation parameters used after document upload
56
58
  - Enabled: whether the knowledge base is enabled
57
59
 
60
+ A Readonly knowledge base does not require File storage or default segmentation parameters, but it still requires Vector database, LLM service, and Embedding model.
61
+
58
62
  :::tip Prerequisites
59
63
 
60
- Before creating a Local knowledge base, prepare two dependencies: file storage for original documents and segment files, see [File storage](../../../file-manager/storage/); and vector storage for generating and retrieving vectors, see [Vector database](../vector-database) and [Vector store](../vector-store).
64
+ Before creating a Local knowledge base, prepare file storage, a vector database, and an LLM service that supports embedding models. File storage holds original documents and segment files; see [File storage](../../../file-manager/storage/index.md). Configure the vector database as described in [Vector database](../vector-database), and configure the LLM service as described in [LLM service management](../../features/llm-service).
61
65
 
62
66
  :::
63
67
 
@@ -1,17 +1,17 @@
1
1
  ---
2
2
  pkg: "@nocobase/plugin-ai-knowledge-base"
3
3
  title: "Settings"
4
- description: "Modify basic information, vector store, and default segmentation settings on the Settings page of a knowledge base, and understand the relation between knowledge-base-level and document-level segmentation settings."
5
- keywords: "knowledge base settings,segmentation settings,Chunk size,Chunk overlap,vector store,NocoBase"
4
+ description: "Modify basic information, vector database, LLM service, embedding model, and default segmentation settings on the Settings page of a knowledge base."
5
+ keywords: "knowledge base settings,vector database,LLM service,embedding model,segmentation settings,NocoBase"
6
6
  ---
7
7
 
8
8
  # Settings
9
9
 
10
10
  ## Open the Settings page
11
11
 
12
- After opening the knowledge base detail page, click Settings in the left sidebar. This page modifies basic information, file storage, vector store, and default segmentation settings of the current knowledge base.
12
+ After opening the knowledge base detail page, click Settings in the left sidebar. This page modifies basic information, file storage, vector database, LLM service, embedding model, and default segmentation settings of the current knowledge base.
13
13
 
14
- ![](https://static-docs.nocobase.com/20260617005832.png)
14
+ ![](https://static-docs.nocobase.com/20260728222407.png)
15
15
 
16
16
  ## Basic information
17
17
 
@@ -22,17 +22,21 @@ Local knowledge base settings include:
22
22
  | Key | Unique identifier of the knowledge base. It cannot be changed after creation |
23
23
  | Name | Knowledge base name |
24
24
  | File storage | Where documents and segment files are stored. It cannot be changed after creation |
25
- | Vector store | Vector store used by the current knowledge base |
25
+ | Vector database | Vector database used by the current knowledge base |
26
+ | LLM service | LLM service used to generate embeddings |
27
+ | Embedding model | Embedding model used to generate and retrieve vectors |
26
28
  | Description | Knowledge base description |
27
29
  | Enabled | Whether the current knowledge base is enabled |
28
30
 
29
- :::tip Vector store changes
31
+ :::tip Vector configuration changes
30
32
 
31
- After you modify Vector store, NocoBase asks for confirmation when saving. After the vector store changes, existing documents must be vectorized again before vector data can be written to the new vector store. Choose Save and vectorize to save the settings and vectorize immediately, or choose Save only to save the settings and later run Vectorization manually on the Documents page.
33
+ After you modify Vector database, LLM service, or Embedding model, NocoBase asks for confirmation when saving. After the vector configuration changes, existing documents must be vectorized again. Choose Save and vectorize to save the settings and vectorize immediately, or choose Save only to save the settings and later run Vectorization manually on the Documents page.
34
+
35
+ If the vector database connection settings change, the Documents page also prompts you to run vectorization again.
32
36
 
33
37
  :::
34
38
 
35
- ![](https://static-docs.nocobase.com/20260617005951.png)
39
+ ![](https://static-docs.nocobase.com/20260728222408.png)
36
40
 
37
41
  ## Default segmentation parameters
38
42
 
@@ -10,10 +10,10 @@ Currently, the AI Knowledge Base plugin only has built-in support for PGVector,
10
10
 
11
11
  ## Vector Database Management
12
12
 
13
- Go to the AI Agent plugin configuration page, click the `Vector store` tab, and select `Vector database` to enter the vector database management page.
13
+ Go to the AI employees plugin configuration page and click the top-level `Vector database` tab to open the vector database management page.
14
14
 
15
15
 
16
- ![20251022233704](https://static-docs.nocobase.com/20251022233704.png)
16
+ ![20260728222401](https://static-docs.nocobase.com/20260728222401.png)
17
17
 
18
18
 
19
19
  Click the `Add new` button in the upper right corner to add a new `PGVector` vector database connection:
@@ -29,4 +29,4 @@ Click the `Add new` button in the upper right corner to add a new `PGVector` vec
29
29
  After entering all the necessary information, click the `Test` button to test if the vector database service is available, and click the `Submit` button to save the connection information.
30
30
 
31
31
 
32
- ![20251022234644](https://static-docs.nocobase.com/20251022234644.png)
32
+ ![20260728222402](https://static-docs.nocobase.com/20260728222402.png)
@@ -30,7 +30,7 @@ Where:
30
30
 
31
31
  The example uses the `Answers` / `Questions` collections and target knowledge base described in [Overview](./). Before configuring the workflow, confirm that:
32
32
 
33
- - A Local knowledge base has been created, with file storage and vector store configured. See [Knowledge base overview](../../../knowledge-base/knowledge-base) and [Vector store](../../../knowledge-base/vector-store)
33
+ - A Local knowledge base has been created, with file storage, vector database, LLM service, and embedding model configured. See [Knowledge base overview](../../../knowledge-base/knowledge-base/index.md) and [Vector database](../../../knowledge-base/vector-database)
34
34
  - The `Answers.questions` relation field is ready. To review the collection structure, return to [Overview](./)
35
35
  - The workflow uses asynchronous execution. See [Workflow](../../../../workflow) for the basics
36
36
 
@@ -336,9 +336,8 @@ The “Data type” column comes from built-in classification. System base data
336
336
  | Table | Description | Data type | Default migration strategy | Version control | Backup/restore |
337
337
  | --- | --- | --- | --- | --- | --- |
338
338
  | `aiKnowledgeBaseDocs` | Document chunks and index metadata stored in knowledge bases | Business runtime data | Schema-only | Not included | Backed up |
339
- | `aiKnowledgeBase` | Knowledge-base type, external ID, and base information | Business runtime data | Schema-only | Not included | Backed up |
339
+ | `aiKnowledgeBase` | Knowledge-base type, external ID, vector database, LLM service, embedding model, and base information | Business runtime data | Schema-only | Not included | Backed up |
340
340
  | `aiVectorDatabases` | Vector database service and connection configuration | Business runtime data | Schema-only | Not included | Backed up |
341
- | `aiVectorStoreConfig` | Relationship between vector database connections and embedding models | Business runtime data | Schema-only | Not included | Backed up |
342
341
 
343
342
  ### Environment variables
344
343
 
@@ -1,23 +1,51 @@
1
1
  ---
2
2
  title: "ctx.ai"
3
- description: "Use ctx.ai in RunJS to trigger AI employee tasks, either with inline task content or with tasks configured on an AI employee action."
4
- keywords: "ctx.ai,AI employee,triggerTask,triggerModelTask,RunJS,NocoBase"
3
+ description: "Use ctx.ai in RunJS to trigger AI employee tasks in the global conversation or a specified AI Chat Box, either with inline task content or with tasks configured on an AI employee action."
4
+ keywords: "ctx.ai,AI employee,uploadFile,attachments,triggerTask,triggerModelTask,onResponseLoadingChange,chatBoxUid,AI Chat Box,RunJS,NocoBase"
5
5
  ---
6
6
 
7
7
  # ctx.ai
8
8
 
9
9
  Use `ctx.ai` in RunJS to trigger **AI employee tasks**. It works well in JSBlock, JSAction, and other interactions where a button, form, or business flow needs to hand work to a specific AI employee.
10
10
 
11
- `ctx.ai` only triggers tasks. It does not return the execution result of the AI employee task. After the call, the task enters the AI employee conversation flow, and the result is handled by the AI employee session.
11
+ `ctx.ai` uploads AI task attachments and triggers tasks. File uploads can be awaited, but task triggering does not return the execution result of the AI employee task. After the call, the task enters the AI employee conversation flow, and the result is handled by the AI employee session.
12
12
 
13
13
  :::warning Note
14
14
 
15
- `ctx.ai` is provided by the AI plugin. If the AI plugin is not enabled, or the current RunJS environment has not loaded the corresponding client capability, `ctx.ai` may not exist. You can check `ctx.ai?.triggerTask` or `ctx.ai?.triggerModelTask` before calling it.
15
+ `ctx.ai` is provided by the AI plugin. If the AI plugin is not enabled, or the current RunJS environment has not loaded the corresponding client capability, `ctx.ai` may not exist. You can check `ctx.ai?.uploadFile`, `ctx.ai?.triggerTask`, or `ctx.ai?.triggerModelTask` before calling it.
16
16
 
17
17
  :::
18
18
 
19
19
  ## Methods
20
20
 
21
+ ### ctx.ai.uploadFile()
22
+
23
+ Upload one file and return an attachment object that can be passed directly to an AI employee task.
24
+
25
+ ```ts
26
+ const attachment = await ctx.ai.uploadFile(file, options);
27
+ ```
28
+
29
+ | Parameter | Type | Description |
30
+ |------|------|------|
31
+ | `file` | `File` | Browser file object to upload. |
32
+ | `options.onProgress` | `(percent: number) => void` | Upload progress callback. `percent` ranges from `0` to `100`. |
33
+ | `options.signal` | `AbortSignal` | Signal used to cancel the upload. |
34
+
35
+ The upload uses the file storage configured by the AI plugin and creates a record in `aiFiles`. The returned object includes fields such as `id`, `filename`, `url`, and `source`:
36
+
37
+ ```ts
38
+ const attachment = await ctx.ai.uploadFile(file, {
39
+ onProgress(percent) {
40
+ console.log('upload progress', percent);
41
+ },
42
+ });
43
+
44
+ // attachment can be placed directly in message.attachments
45
+ ```
46
+
47
+ The Promise is rejected when the upload fails. Removing an attachment from the local UI does not delete the record already created in `aiFiles`, matching the behavior of the default AI chat window.
48
+
21
49
  ### ctx.ai.triggerTask()
22
50
 
23
51
  Trigger an AI employee task directly.
@@ -30,8 +58,10 @@ ctx.ai.triggerTask(options: TriggerTaskOptions): void
30
58
  |------|------|------|
31
59
  | `aiEmployee` | `string \| AIEmployee` | AI employee. When a string is passed, NocoBase matches `AIEmployee.username` exactly, and the AI employee must be accessible to the current user. |
32
60
  | `tasks` | `Task[]` | Tasks to trigger. |
61
+ | `chatBoxUid` | `string` | FlowModel uid of the AI Chat Box block that should receive the task. |
33
62
  | `open` | `boolean` | Whether to open the AI employee conversation panel. |
34
63
  | `auto` | `boolean` | Whether to use the auto-trigger semantics of an AI employee action. |
64
+ | `onResponseLoadingChange` | `(loading: boolean) => void` | Model response loading callback. It only runs when this task is sent automatically. |
35
65
 
36
66
  Common `Task` fields:
37
67
 
@@ -40,12 +70,160 @@ Common `Task` fields:
40
70
  | `title` | `string` | Task title. |
41
71
  | `message.system` | `string` | System message, used to constrain the AI employee's role and output requirements. |
42
72
  | `message.user` | `string` | User message, which is the main instruction for this task. |
73
+ | `message.attachments` | `Attachment[]` | Attachments used by the task, usually returned by `ctx.ai.uploadFile()`. |
43
74
  | `message.workContext` | `ContextItem[]` | Page block context used by the task. |
44
75
  | `autoSend` | `boolean` | Whether to send the task message automatically. |
45
76
  | `webSearch` | `boolean` | Whether Web search is allowed for this task. |
46
77
  | `model` | `{ llmService: string; model: string } \| null` | Model used by this task. |
47
78
  | `skillSettings` | `SkillSettings` | Skills and tools available to this task. |
48
79
 
80
+ ### Track the Response Loading State
81
+
82
+ Pass `onResponseLoadingChange` in the top-level options to track the model response loading state for this task. The callback receives `true` when NocoBase starts waiting for the model response, and `false` when the response completes, is canceled, or fails. If the React component has declared `setResponseLoading` with `useState`, you can write:
83
+
84
+ ```tsx
85
+ ctx.ai.triggerTask({
86
+ aiEmployee: 'nathan',
87
+ open: true,
88
+ tasks: [
89
+ {
90
+ title: ctx.t('Review current page'),
91
+ message: {
92
+ user: 'Review the current page and summarize the main risks.',
93
+ },
94
+ autoSend: true,
95
+ },
96
+ ],
97
+ onResponseLoadingChange(loading) {
98
+ setResponseLoading(loading);
99
+ },
100
+ });
101
+ ```
102
+
103
+ `onResponseLoadingChange` only tracks the model response started directly by this `triggerTask()` call. With `autoSend: false`, the task is placed in the chat draft and the callback does not run. If the user sends the draft later, that manual send does not reuse this callback.
104
+
105
+ In a React component inside a JS block, this state update rerenders the component while it remains mounted.
106
+
107
+ ### Target an AI Chat Box
108
+
109
+ Set `chatBoxUid` on the top-level `triggerTask()` options to trigger the task in a mounted AI Chat Box block instead of the global AI employee dialog.
110
+
111
+ ```ts
112
+ ctx.ai.triggerTask({
113
+ aiEmployee: 'nathan',
114
+ chatBoxUid: 'AI_CHAT_BOX_BLOCK_UID',
115
+ open: true,
116
+ tasks: [
117
+ {
118
+ title: ctx.t('Review current page'),
119
+ message: {
120
+ user: 'Review the current page and summarize the main risks.',
121
+ },
122
+ },
123
+ ],
124
+ });
125
+ ```
126
+
127
+ The uid must belong to the outer AI Chat Box block currently mounted on the page. Do not put this routing value inside `tasks`. If the target block cannot be found, NocoBase reports an error and does not fall back to the global dialog. When `chatBoxUid` is omitted, the task uses the global AI employee dialog.
128
+
129
+ ### Upload and Send Attachments in JSBlock
130
+
131
+ The following example renders file upload, task instructions, and a send button in JSBlock. Uploaded files are passed to the AI employee through `message.attachments`:
132
+
133
+ ```tsx
134
+ if (!ctx.ai?.uploadFile || !ctx.ai?.triggerTask) {
135
+ ctx.message.error(ctx.t('AI employee task API is not available.'));
136
+ return;
137
+ }
138
+
139
+ const { React } = ctx.libs;
140
+ const { useState } = React;
141
+ const { Button, Card, Input, Space, Upload } = ctx.libs.antd;
142
+ const { InboxOutlined, SendOutlined } = ctx.libs.antdIcons;
143
+
144
+ const AttachmentTask = () => {
145
+ const [prompt, setPrompt] = useState('');
146
+ const [fileList, setFileList] = useState([]);
147
+
148
+ const uploadAttachment = async ({ file, onError, onProgress, onSuccess }) => {
149
+ try {
150
+ const attachment = await ctx.ai.uploadFile(file, {
151
+ onProgress(percent) {
152
+ onProgress?.({ percent });
153
+ },
154
+ });
155
+ onSuccess?.(attachment);
156
+ } catch (error) {
157
+ onError?.(error instanceof Error ? error : new Error(ctx.t('File upload failed')));
158
+ }
159
+ };
160
+
161
+ const sendTask = () => {
162
+ const attachments = fileList
163
+ .filter((file) => file.status === 'done' && file.response)
164
+ .map((file) => file.response);
165
+
166
+ if (!prompt.trim()) {
167
+ ctx.message.warning(ctx.t('Enter task instructions'));
168
+ return;
169
+ }
170
+
171
+ ctx.ai.triggerTask({
172
+ aiEmployee: 'viz',
173
+ open: true,
174
+ tasks: [
175
+ {
176
+ title: ctx.t('Analyze uploaded files'),
177
+ message: {
178
+ user: prompt.trim(),
179
+ attachments,
180
+ },
181
+ autoSend: true,
182
+ },
183
+ ],
184
+ });
185
+ setPrompt('');
186
+ setFileList([]);
187
+ };
188
+
189
+ const uploading = fileList.some((file) => file.status === 'uploading');
190
+
191
+ return (
192
+ <Card title={ctx.t('AI file analysis')}>
193
+ <Space direction="vertical" size="middle" style={{ width: '100%' }}>
194
+ <Upload.Dragger
195
+ multiple
196
+ fileList={fileList}
197
+ customRequest={uploadAttachment}
198
+ onChange={({ fileList: nextFileList }) => setFileList(nextFileList)}
199
+ >
200
+ <p className="ant-upload-drag-icon"><InboxOutlined /></p>
201
+ <p>{ctx.t('Click or drag files here to upload')}</p>
202
+ </Upload.Dragger>
203
+ <Input.TextArea
204
+ value={prompt}
205
+ onChange={(event) => setPrompt(event.target.value)}
206
+ placeholder={ctx.t('Describe the task for the AI employee')}
207
+ autoSize={{ minRows: 3, maxRows: 8 }}
208
+ />
209
+ <Button
210
+ type="primary"
211
+ icon={<SendOutlined />}
212
+ disabled={uploading || !prompt.trim()}
213
+ onClick={sendTask}
214
+ >
215
+ {ctx.t('Send to AI')}
216
+ </Button>
217
+ </Space>
218
+ </Card>
219
+ );
220
+ };
221
+
222
+ ctx.render(<AttachmentTask />);
223
+ ```
224
+
225
+ With `autoSend: false`, the attachments and task instructions are placed in the AI chat draft instead of being sent immediately.
226
+
49
227
  ### Add Page Block Context
50
228
 
51
229
  `message.workContext` currently passes page blocks. Put the FlowModel uid of the target page block into it:
@@ -163,9 +341,15 @@ ctx.ai.triggerModelTask(uid: string, taskIndex: number, options?: TriggerModelTa
163
341
  | `taskIndex` | `number` | Task index, starting from `0`. |
164
342
  | `options.open` | `boolean` | Whether to open the AI employee conversation panel. |
165
343
  | `options.auto` | `boolean` | Whether to use the auto-trigger semantics of an AI employee action. |
344
+ | `options.attachments` | `Attachment[]` | Attachments dynamically appended to the configured task. |
345
+ | `options.onResponseLoadingChange` | `(loading: boolean) => void` | Model response loading callback. It only runs when the configured task is sent automatically. |
166
346
 
167
347
  This method reads the AI employee and task configuration from the target model. It is useful when the task has already been configured on an AI employee action on the page, and RunJS only needs to trigger it.
168
348
 
349
+ The public `triggerModelTask()` options do not accept `chatBoxUid`. To target an AI Chat Box, configure `chatBoxUid` on the preset task of the AI employee action. `triggerModelTask()` continues to reuse that preset value.
350
+
351
+ `options.onResponseLoadingChange` behaves the same as the option on `triggerTask()`. Whether it runs depends on the configured task's `autoSend` value. It does not run when that task uses `autoSend: false`.
352
+
169
353
  ```ts
170
354
  if (!ctx.ai?.triggerModelTask) {
171
355
  ctx.message.error(ctx.t('AI employee task API is not available.'));
@@ -176,6 +360,7 @@ const weeklyReviewActionUid = 'AI_EMPLOYEE_ACTION_MODEL_UID';
176
360
 
177
361
  ctx.ai.triggerModelTask(weeklyReviewActionUid, 0, {
178
362
  open: true,
363
+ attachments,
179
364
  });
180
365
 
181
366
  ctx.message.success(ctx.t('Configured AI employee task triggered.'));
@@ -195,9 +380,14 @@ If the target model does not exist, has no AI employee configured, or the specif
195
380
  ## Notes
196
381
 
197
382
  - `triggerTask()` and `triggerModelTask()` are fire-and-forget. They do not return the execution result of the AI employee task.
383
+ - `uploadFile()` returns a Promise. Wait for the upload to finish before triggering a task that uses the attachment.
198
384
  - `aiEmployee` strings only match `AIEmployee.username` exactly. They do not match nicknames, job titles, or translated names.
199
385
  - `triggerModelTask()` uses a `0`-based `taskIndex`.
200
386
  - `triggerModelTask()` reads task configuration from the target AI employee action model. If the task needs work context, configure `message.workContext` on that task.
387
+ - Top-level `triggerTask().chatBoxUid` must reference an AI Chat Box block currently mounted on the page.
388
+ - `triggerModelTask()` keeps using `chatBoxUid` configured on its preset task.
389
+ - Dynamic `triggerModelTask()` attachments are appended to the preset task's existing `message.attachments` without changing the saved task configuration.
390
+ - `onResponseLoadingChange` only tracks a model response automatically sent by the current call. It does not track a message the user sends manually later.
201
391
 
202
392
  ## Related
203
393
 
@@ -43,7 +43,7 @@ var import_ai = require("@nocobase/ai");
43
43
  var import_zod = require("zod");
44
44
  var import_package = __toESM(require("../../../package.json"));
45
45
  var getSkill_default = (0, import_ai.defineTools)({
46
- scope: "GENERAL",
46
+ scope: "SPECIFIED",
47
47
  defaultPermission: "ALLOW",
48
48
  introduction: {
49
49
  title: `{{t("Load specific SKILLS", { ns: "${import_package.default.name}" })}}`,