@nocobase/plugin-ai 2.1.0-beta.30 → 2.1.0-beta.32

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 (94) hide show
  1. package/client-v2.d.ts +1 -0
  2. package/client-v2.js +1 -0
  3. package/dist/ai/docs/nocobase/ai/index.md +1 -1
  4. package/dist/ai/docs/nocobase/ai-employees/built-in/atlas.md +24 -0
  5. package/dist/ai/docs/nocobase/ai-employees/built-in/dara.md +22 -0
  6. package/dist/ai/docs/nocobase/ai-employees/built-in/dex.md +32 -0
  7. package/dist/ai/docs/nocobase/ai-employees/built-in/ellis.md +22 -0
  8. package/dist/ai/docs/nocobase/ai-employees/built-in/index.md +25 -0
  9. package/dist/ai/docs/nocobase/ai-employees/built-in/lexi.md +26 -0
  10. package/dist/ai/docs/nocobase/ai-employees/built-in/lina.md +142 -0
  11. package/dist/ai/docs/nocobase/ai-employees/built-in/nathan.md +36 -0
  12. package/dist/ai/docs/nocobase/ai-employees/built-in/vera.md +22 -0
  13. package/dist/ai/docs/nocobase/ai-employees/built-in/viz.md +25 -0
  14. package/dist/ai/docs/nocobase/ai-employees/features/built-in-employee.md +1 -29
  15. package/dist/ai/docs/nocobase/ai-employees/features/collaborate.md +17 -7
  16. package/dist/ai/docs/nocobase/ai-employees/features/enable-ai-employee.md +4 -4
  17. package/dist/ai/docs/nocobase/ai-employees/features/model-settings.md +87 -0
  18. package/dist/ai/docs/nocobase/ai-employees/index.md +1 -1
  19. package/dist/ai/docs/nocobase/ai-employees/scenarios/localization-hy-mt.md +241 -0
  20. package/dist/ai/docs/nocobase/ai-employees/workflow/nodes/employee/configuration.md +1 -1
  21. package/dist/ai/docs/nocobase/interface-builder/actions/types/js-action.md +1 -1
  22. package/dist/ai/docs/nocobase/interface-builder/actions/types/js-item.md +1 -1
  23. package/dist/ai/docs/nocobase/interface-builder/blocks/other-blocks/js-block.md +1 -1
  24. package/dist/ai/docs/nocobase/interface-builder/fields/specific/js-column.md +1 -1
  25. package/dist/ai/docs/nocobase/interface-builder/fields/specific/js-field.md +1 -1
  26. package/dist/ai/docs/nocobase/interface-builder/fields/specific/js-item.md +1 -1
  27. package/dist/ai/docs/nocobase/security/guide.md +13 -1
  28. package/dist/ai/docs/nocobase/system-management/localization/index.md +25 -1
  29. package/dist/client/462.1708385b148779cd.js +10 -0
  30. package/dist/client/{559.39872901b9053629.js → 559.585f80c3bcea0bed.js} +1 -1
  31. package/dist/client/646.b0ed728921b007d4.js +10 -0
  32. package/dist/client/{927.ac9ee9a8c1cb4f1d.js → 927.d95c74ebb8fd51c9.js} +1 -1
  33. package/dist/client/ai-employees/admin/ModelSettings.d.ts +10 -0
  34. package/dist/client/ai-employees/admin/hooks.d.ts +1 -1
  35. package/dist/client/ai-employees/avatars.d.ts +9 -783
  36. package/dist/client/ai-employees/chatbox/model.d.ts +6 -3
  37. package/dist/client/ai-employees/types.d.ts +23 -0
  38. package/dist/client/features/vector-database-provider.d.ts +1 -1
  39. package/dist/client/index.js +4 -4
  40. package/dist/client/llm-services/component/EnabledModelsSelect.d.ts +1 -14
  41. package/dist/client-v2/ai-employees/AIEmployeeShortcut.d.ts +21 -0
  42. package/dist/client-v2/ai-employees/ProfileCard.d.ts +17 -0
  43. package/dist/client-v2/ai-employees/avatars.d.ts +783 -0
  44. package/dist/client-v2/ai-employees/types.d.ts +20 -0
  45. package/dist/client-v2/index.d.ts +17 -0
  46. package/dist/client-v2/index.js +10 -0
  47. package/dist/client-v2/llm-services/model-label.d.ts +22 -0
  48. package/dist/collections/ai-employees.d.ts +2 -1
  49. package/dist/collections/ai-employees.js +1 -1
  50. package/dist/externalVersion.js +17 -17
  51. package/dist/locale/en-US.json +15 -1
  52. package/dist/locale/zh-CN.json +15 -1
  53. package/dist/node_modules/@langchain/xai/package.json +1 -1
  54. package/dist/node_modules/fs-extra/package.json +1 -1
  55. package/dist/node_modules/jsonrepair/package.json +1 -1
  56. package/dist/node_modules/just-bash/package.json +1 -1
  57. package/dist/node_modules/nodejs-snowflake/package.json +1 -1
  58. package/dist/node_modules/openai/package.json +1 -1
  59. package/dist/node_modules/zod/package.json +1 -1
  60. package/dist/server/ai-employees/ai-conversations.d.ts +1 -0
  61. package/dist/server/ai-employees/ai-conversations.js +4 -1
  62. package/dist/server/ai-employees/ai-employee.d.ts +15 -1
  63. package/dist/server/ai-employees/ai-employee.js +140 -9
  64. package/dist/server/ai-employees/ai-employees-manager.d.ts +4 -0
  65. package/dist/server/ai-employees/ai-employees-manager.js +41 -0
  66. package/dist/server/ai-employees/ai-knowledge-base.js +7 -7
  67. package/dist/server/ai-employees/middleware/conversation.d.ts +1 -0
  68. package/dist/server/ai-employees/middleware/conversation.js +4 -2
  69. package/dist/server/ai-employees/sub-agents/dispatcher.js +2 -4
  70. package/dist/server/ai-employees/utils.d.ts +6 -3
  71. package/dist/server/ai-employees/utils.js +7 -1
  72. package/dist/server/features/knowledge-base.d.ts +3 -2
  73. package/dist/server/index.d.ts +2 -0
  74. package/dist/server/index.js +3 -0
  75. package/dist/server/llm-providers/common/reasoning.d.ts +2 -0
  76. package/dist/server/llm-providers/common/reasoning.js +15 -2
  77. package/dist/server/llm-providers/dashscope.d.ts +2 -1
  78. package/dist/server/llm-providers/dashscope.js +39 -0
  79. package/dist/server/llm-providers/deepseek.js +2 -0
  80. package/dist/server/llm-providers/provider.d.ts +15 -1
  81. package/dist/server/llm-providers/provider.js +21 -2
  82. package/dist/server/manager/ai-chat-conversation.js +3 -4
  83. package/dist/server/manager/ai-manager.d.ts +17 -0
  84. package/dist/server/manager/ai-manager.js +65 -0
  85. package/dist/server/migrations/20260407170416-ai-employee-knowledge-base-add-key.d.ts +14 -0
  86. package/dist/server/migrations/20260407170416-ai-employee-knowledge-base-add-key.js +61 -0
  87. package/dist/server/resource/ai.js +1 -41
  88. package/dist/server/resource/aiConversations.js +12 -8
  89. package/dist/server/resource/aiEmployees.js +32 -1
  90. package/dist/server/types/knowledge-base.type.d.ts +3 -2
  91. package/dist/server/workflow/nodes/employee/index.js +4 -2
  92. package/package.json +2 -2
  93. package/dist/client/343.6f36d97dd122c5b6.js +0 -10
  94. package/dist/client/646.5860101cb28c8272.js +0 -10
@@ -0,0 +1,241 @@
1
+ ---
2
+ pkg: '@nocobase/plugin-ai'
3
+ title: 'Use Lina and local HY-MT to translate localization entries'
4
+ description: 'Deploy the HY-MT1.5 GGUF translation model with llama-server and configure it for Lina to batch translate NocoBase localization entries.'
5
+ keywords: 'Lina,localization,HY-MT,GGUF,llama-server,OpenAI compatible,AI translation,NocoBase'
6
+ ---
7
+
8
+ # Use Lina and local HY-MT1.5-1.8B to translate localization entries
9
+
10
+ This guide describes a localization translation practice: deploy a translation-specific small model locally, expose it as an OpenAI-compatible service, and configure it for Lina to translate localization entries in batches.
11
+
12
+ This approach is suitable for translating many system entries, plugin text, menus, collection titles, and field labels. Compared with online models, local models are not affected by external API RPM, TPM, or concurrency limits, and concurrency can be tuned according to machine and model capability.
13
+
14
+ ## Overview
15
+
16
+ This guide uses:
17
+
18
+ - Model: `tencent/HY-MT1.5-1.8B-GGUF`
19
+ - Inference service: `llama-server`
20
+ - Integration: OpenAI-compatible API
21
+ - AI Employee: Lina
22
+ - Entry point: Localization Management page
23
+
24
+ :::info{title=Note}
25
+ HY-MT1.5-1.8B is a translation-specific small model. It is more suitable for short entries, UI text, and batch translation. General chat models are not recommended as the first choice for localization tasks.
26
+ :::
27
+
28
+ ## Prerequisites
29
+
30
+ Before starting, prepare:
31
+
32
+ - The **Localization Management** plugin is enabled.
33
+ - Target language is enabled.
34
+ - Localization entries have been synchronized.
35
+ - The local machine or server can run [`llama-server`](https://github.com/ggml-org/llama.cpp).
36
+ - The NocoBase service can access the HTTP address of `llama-server`.
37
+
38
+ ## Deploy HY-MT GGUF
39
+
40
+ ### Install llama.cpp
41
+
42
+ On macOS, you can install it with Homebrew:
43
+
44
+ ```bash
45
+ brew install llama.cpp
46
+ ```
47
+
48
+ You can also use a prebuilt llama.cpp binary or build it from source. The final requirement is that `llama-server` is available.
49
+
50
+ ### Start an OpenAI-compatible service
51
+
52
+ Start the service with the GGUF model from Hugging Face:
53
+
54
+ ```bash
55
+ llama-server \
56
+ -hf tencent/HY-MT1.5-1.8B-GGUF:Q4_K_M \
57
+ --host 0.0.0.0 \
58
+ --port 8000 \
59
+ -c 2048 \
60
+ -np 4
61
+ ```
62
+
63
+ | Parameter | Description |
64
+ | --- | --- |
65
+ | `-hf` | Load the model from Hugging Face. |
66
+ | `--host` | Listening address. Use `127.0.0.1` for local testing or `0.0.0.0` for container or remote access. |
67
+ | `--port` | HTTP service port. |
68
+ | `-c` | Context length. Localization entries are usually short, so `2048` is usually enough. |
69
+ | `-np` | Number of parallel slots. Adjust according to machine performance. |
70
+
71
+ :::info{title=Tip}
72
+ If server resources are limited, start with `-np 1` or `-np 2`, then increase gradually after verifying stability.
73
+ :::
74
+
75
+ ## Test the Model Service
76
+
77
+ After `llama-server` starts, check service health:
78
+
79
+ ```bash
80
+ curl http://127.0.0.1:8000/health
81
+ ```
82
+
83
+ Then test translation through the OpenAI-compatible API:
84
+
85
+ ```bash
86
+ curl http://127.0.0.1:8000/v1/chat/completions \
87
+ -H "Content-Type: application/json" \
88
+ -d '{
89
+ "model": "tencent/HY-MT1.5-1.8B-GGUF:Q4_K_M",
90
+ "messages": [
91
+ {
92
+ "role": "user",
93
+ "content": "Translate the following text into Chinese. Output only the translated result without any additional explanation:\n\nSave"
94
+ }
95
+ ]
96
+ }'
97
+ ```
98
+
99
+ If you start from a local model file, change `model` to the actual model name returned or configured by the service.
100
+
101
+ :::warning{title=Note}
102
+ If a request does not respond for a long time, the model may be too slow, concurrency may be too high, or context may be too large. Lower `-np` and NocoBase translation concurrency first, then observe response time.
103
+ :::
104
+
105
+ ## Configure an LLM Service in NocoBase
106
+
107
+ Go to `System Settings -> AI Employees -> LLM service` and add an LLM service.
108
+
109
+ Example configuration:
110
+
111
+ | Setting | Example |
112
+ | --- | --- |
113
+ | Provider | OpenAI (completions) |
114
+ | Title | HY-MT Local |
115
+ | Base URL | `http://127.0.0.1:8000/v1` |
116
+ | API Key | If llama-server has no authentication, use a placeholder such as `dummy`. |
117
+ | Enabled Models | Select `tencent/HY-MT1.5-1.8B-GGUF:Q4_K_M`, or enter the actual model name. |
118
+
119
+ After configuration, use `Test flight` to verify the model.
120
+
121
+ :::info{title=Tip}
122
+ If NocoBase runs in Docker, `127.0.0.1` points to the container itself and may not access the host service. Use the host IP, container network address, or `host.docker.internal`.
123
+ :::
124
+
125
+ ## Configure Lina's Dedicated Model
126
+
127
+ Go to `System Settings -> AI Employees -> AI employees`, open Lina, and switch to `Model settings`.
128
+
129
+ 1. Enable `Enable dedicated model configuration`.
130
+ 2. Select the HY-MT local model in `Models`.
131
+ 3. Save the configuration.
132
+
133
+ After this, Lina uses this model for localization translation tasks, preventing users or tasks from switching to general chat models.
134
+
135
+ For details, see [Configure AI Employee Models](/ai-employees/features/model-settings).
136
+
137
+ ## Configure Translation Concurrency
138
+
139
+ Localization translation task concurrency is controlled by `AI_LOCALIZATION_CONCURRENCY`:
140
+
141
+ ```bash
142
+ AI_LOCALIZATION_CONCURRENCY=10
143
+ ```
144
+
145
+ Rules:
146
+
147
+ - Default: `10`
148
+ - Minimum: `1`
149
+ - Maximum: `20`
150
+ - Values outside the range use the default
151
+
152
+ The best concurrency depends on CPU, GPU, memory, model quantization, and `llama-server -np`. If the default concurrency causes issues:
153
+
154
+ 1. Start with `AI_LOCALIZATION_CONCURRENCY=1` and verify single-entry translation.
155
+ 2. Set both `llama-server -np` and `AI_LOCALIZATION_CONCURRENCY` to `2` or `4`.
156
+ 3. Observe response time, CPU/GPU usage, and task progress.
157
+ 4. Increase concurrency gradually only if stable.
158
+
159
+ :::warning{title=Note}
160
+ Do not set concurrency too high at the beginning. If concurrency exceeds actual model capacity, tasks may become slower due to queuing, timeout, or service stalls.
161
+ :::
162
+
163
+ ## Execute Localization Translation
164
+
165
+ Go to `System Management -> Localization Management`.
166
+
167
+ 1. Switch to the target language.
168
+ 2. Click `Synchronize` to ensure entries are synchronized.
169
+ 3. Click Lina's avatar.
170
+ 4. Choose a task scope:
171
+ - `Incremental translation`: translate entries without translations.
172
+ - `Selected translation`: translate selected entries in the table.
173
+ - `Full translation`: translate all entries in the current language.
174
+ 5. Check entry count, provider, and model in the confirmation dialog.
175
+ 6. Confirm to create the async task.
176
+ 7. Wait for completion, review translations, and publish.
177
+
178
+ Start with `Selected translation` for a few entries to verify output style and speed before running incremental or full translation.
179
+
180
+ ## How Lina Builds Translation Requests
181
+
182
+ Lina builds requests from entries and reference translations. For short entries, existing references are used to improve consistency:
183
+
184
+ - Built-in entries prefer Chinese translations as references.
185
+ - Non-built-in entries prefer the system default language as references.
186
+ - If an English reference exists, English is used as source text.
187
+ - Translation results are written to the target language but are not published automatically.
188
+
189
+ Prompt semantics are similar to:
190
+
191
+ ```text
192
+ Refer to the following translation:
193
+ {source_term} is translated as {target_term}
194
+
195
+ Translate the following text into {target_language}. Output only the translated result without any additional explanation:
196
+
197
+ {source_text}
198
+ ```
199
+
200
+ ## Troubleshooting
201
+
202
+ ### No progress after creating a task
203
+
204
+ Check whether `llama-server` received requests. View service logs or call `/v1/chat/completions` with `curl`.
205
+
206
+ If the model receives requests but does not return, reduce:
207
+
208
+ - `AI_LOCALIZATION_CONCURRENCY`
209
+ - `llama-server -np`
210
+ - `llama-server -c`
211
+
212
+ ### The model returns explanations instead of translations
213
+
214
+ Local translation models are usually more stable than general chat models. If explanations still appear, test the same prompt with `curl` first to verify the model's output style.
215
+
216
+ You can also translate shorter entries first or reduce sampling parameters such as temperature.
217
+
218
+ ### NocoBase cannot connect to the model service
219
+
220
+ Check:
221
+
222
+ - Whether Base URL includes `/v1`.
223
+ - Whether the NocoBase runtime environment can access the address.
224
+ - Whether firewall or container networking blocks the port.
225
+ - Whether `llama-server` is still running.
226
+
227
+ ## Review Before Publishing
228
+
229
+ After AI translation finishes, review before publishing:
230
+
231
+ - Filter by module and check short entries such as menus, buttons, field names, and statuses.
232
+ - Check variables, placeholders, HTML tags, and formatting symbols.
233
+ - Check key business terminology consistency.
234
+ - If built-in entry translations are overwritten, resynchronize in Localization Management and select `Reset system built-in entry translations` to restore defaults. To contribute default translations for the system and official plugins, see [Translation Contribution](/get-started/translations).
235
+ - Publish in a test environment first, then sync to production.
236
+
237
+ ## References
238
+
239
+ - [tencent/HY-MT1.5-1.8B-GGUF](https://huggingface.co/tencent/HY-MT1.5-1.8B-GGUF)
240
+ - [llama-server documentation](https://www.mintlify.com/ggml-org/llama.cpp/inference/server)
241
+ - [Lina: Localization Engineer](/ai-employees/built-in/lina)
@@ -18,7 +18,7 @@ You can refer to the following documents:
18
18
 
19
19
  - [Workflow](/workflow)
20
20
  - [Configure LLM Service](/ai-employees/features/llm-service)
21
- - [Built-in AI Employees](/ai-employees/features/built-in-employee)
21
+ - [Built-in AI Employees](/ai-employees/built-in/)
22
22
  - [New AI Employee](/ai-employees/features/new-ai-employees)
23
23
 
24
24
  ### Task
@@ -35,7 +35,7 @@ JS Action is used to execute JavaScript when a button is clicked, allowing for c
35
35
  ![jsaction-toolbars-20251029](https://static-docs.nocobase.com/jsaction-toolbars-20251029.png)
36
36
 
37
37
 
38
- - You can use AI employees to generate/modify scripts: [AI Employee · Nathan: Frontend Engineer](/ai-employees/features/built-in-employee)
38
+ - You can use AI employees to generate/modify scripts: [AI Employee · Nathan: Frontend Engineer](/ai-employees/built-in/)
39
39
 
40
40
  ## Common Usage (Simplified Examples)
41
41
 
@@ -47,7 +47,7 @@ The JS Item runtime injects common capabilities that you can use directly in the
47
47
 
48
48
  ![](https://static-docs.nocobase.com/JS-Item-03-27-2026_03_35_PM.png)
49
49
 
50
- - You can use AI employees to generate / modify scripts: [AI Employee · Nathan: Frontend Engineer](/ai-employees/features/built-in-employee)
50
+ - You can use AI employees to generate / modify scripts: [AI Employee · Nathan: Frontend Engineer](/ai-employees/built-in/)
51
51
 
52
52
  ## Common Usage (Simplified Examples)
53
53
 
@@ -38,7 +38,7 @@ The JS Block's script editor supports syntax highlighting, error hints, and buil
38
38
 
39
39
  Additionally, you can directly summon the AI employee "Frontend Engineer · Nathan" from the top-right corner of the editor. Nathan can help you write or modify scripts based on the current context. You can then "Apply to editor" with one click and run the code to see the effect. For details, see:
40
40
 
41
- - [AI Employee · Nathan: Frontend Engineer](/ai-employees/features/built-in-employee)
41
+ - [AI Employee · Nathan: Frontend Engineer](/ai-employees/built-in/)
42
42
 
43
43
  ## Runtime Environment and Security
44
44
 
@@ -37,7 +37,7 @@ The script editor for JS Column supports syntax highlighting, error hints, and b
37
37
 
38
38
  You can also use an AI Employee to generate code:
39
39
 
40
- - [AI Employee · Nathan: Frontend Engineer](/ai-employees/features/built-in-employee)
40
+ - [AI Employee · Nathan: Frontend Engineer](/ai-employees/built-in/)
41
41
 
42
42
  ## Common Usage
43
43
 
@@ -58,7 +58,7 @@ The JS Field script editor supports syntax highlighting, error hints, and built-
58
58
 
59
59
  You can also generate code with the AI Employee:
60
60
 
61
- - [AI Employee · Nathan: Frontend Engineer](/ai-employees/features/built-in-employee)
61
+ - [AI Employee · Nathan: Frontend Engineer](/ai-employees/built-in/)
62
62
 
63
63
  ## Common Usage
64
64
 
@@ -32,7 +32,7 @@ JS Item is used for "custom items" (not bound to a field) in a form. You can use
32
32
  ![jsitem-toolbars-20251029](https://static-docs.nocobase.com/jsitem-toolbars-20251029.png)
33
33
 
34
34
 
35
- - Can be used with AI Employee to generate/modify scripts: [AI Employee · Nathan: Frontend Engineer](/ai-employees/features/built-in-employee)
35
+ - Can be used with AI Employee to generate/modify scripts: [AI Employee · Nathan: Frontend Engineer](/ai-employees/built-in/)
36
36
 
37
37
  ## Common Usage (Simplified Examples)
38
38
 
@@ -213,6 +213,18 @@ If you need to store sensitive files, it is recommended to use a cloud storage s
213
213
 
214
214
  ![](https://static-docs.nocobase.com/202501031623549.png)
215
215
 
216
+ For local storage or other public storage that can be accessed directly through same-origin application URLs, you should also pay extra attention to the risks introduced by active content files. Files such as `html`, `xhtml`, and `svg` may be parsed and executed directly by the browser. If an attacker can upload such a file and trick a user into opening it, the attacker may use your trusted application domain to host a malicious page or script.
217
+
218
+ In most cases, we recommend that administrators:
219
+
220
+ - Prefer private storage, signed URLs, or a separate file domain, so that user-uploaded files are not served directly from the same origin as the main application.
221
+ - Enforce a strict MIME type allowlist for uploads and only allow the file types that are actually required by the business.
222
+ - Be cautious about allowing active content types such as `text/html`, `application/xhtml+xml`, and `image/svg+xml`. Even if the system tries to return these files as downloads, this should not be considered a complete replacement for upload restrictions and origin isolation.
223
+ - Apply consistent security settings to reverse proxies, CDNs, object storage, and any other static file delivery layer, so dangerous files are not returned inline by bypassing application-layer protections.
224
+ - Do not use local/public storage to host untrusted web content. If you really need this capability, use an isolated domain and separately evaluate CSP, download behavior, and access control.
225
+
226
+ If an administrator explicitly allows dangerous file types to be uploaded, they should assess the resulting phishing, same-origin script execution, and sensitive information leakage risks on their own, and ensure that the Web Server, gateway, CDN, and storage services in the deployment chain enforce consistent restrictions.
227
+
216
228
 
217
229
  ### Application Backup
218
230
 
@@ -293,4 +305,4 @@ NocoBase provides multiple log types to help users understand the system's runni
293
305
  - Request log: API request logs, including accessed URLs, HTTP methods, request parameters, response times, and status codes.
294
306
  - System log: Records application running events, including service startup, configuration changes, error messages, and key operations.
295
307
  - SQL log: Records database operation statements and their execution times, covering operations such as query, update, insert, and delete.
296
- - Workflow log: Execution log of the workflow, including execution time, running information, and error information.
308
+ - Workflow log: Execution log of the workflow, including execution time, running information, and error information.
@@ -4,6 +4,8 @@
4
4
 
5
5
  The Localization Management plugin is used to manage and implement NocoBase's localization resources. It can translate system menus, collections, fields, and all plugins to adapt to the language and culture of specific regions.
6
6
 
7
+ If you want to contribute default translations for the system and official plugins to NocoBase, see [Translation Contribution](/get-started/translations).
8
+
7
9
  ## Installation
8
10
 
9
11
  This plugin is built-in and requires no additional installation.
@@ -36,6 +38,8 @@ After synchronization, the system will list all translatable entries for the cur
36
38
  Different modules may have the same original text entries, which need to be translated separately.
37
39
  :::
38
40
 
41
+ If translations for system or plugin built-in entries are manually changed or overwritten by AI translation, select `Reset system built-in entry translations` during synchronization. After synchronization, the system will overwrite existing built-in entry translations for the current language with translations from the built-in language pack to restore the defaults.
42
+
39
43
  ### Automatically Create Translation Entries
40
44
 
41
45
  When editing a page, custom text within each block will automatically generate the corresponding i18n entry and simultaneously create the translation for the current language.
@@ -54,6 +58,26 @@ When defining text in code, you need to manually specify the ns (namespace), for
54
58
 
55
59
  <img src="https://static-docs.nocobase.com/202404202142836.png"/>
56
60
 
61
+ ### Using AI Translation
62
+
63
+ Localization Management supports translating entries through the AI Employee Lina. After enabling AI Employees and configuring a model service, you can use AI translation on the Localization Management page to batch generate translations for the current language.
64
+
65
+ ![](https://static-docs.nocobase.com/202605121152196.png)
66
+
67
+ Supported translation scopes:
68
+
69
+ - **Full translation**: translate all eligible entries in the current language.
70
+ - **Incremental translation**: only translate entries that do not have translations yet.
71
+ - **Selected translation**: select entries in the table and translate only the selected content.
72
+
73
+ AI translation creates a background task. You can view progress while the task runs. After completion, translations are written to the corresponding language and should still be reviewed and corrected according to the actual context.
74
+
75
+ For the complete guide, see [AI Employee - Lina](/ai-employees/built-in/lina).
76
+
77
+ :::warning{title=Note}
78
+ AI-generated translations may have semantic deviations, inconsistent terminology, or insufficient context understanding. Before publishing, manually review important pages, business terminology, and user-facing copy.
79
+ :::
80
+
57
81
  ### Publishing Translations
58
82
 
59
83
  After completing the translation, you need to click the "Publish" button to make the changes take effect.
@@ -76,4 +100,4 @@ Synchronize the entries.
76
100
 
77
101
  Translate and publish.
78
102
 
79
- <img src="https://static-docs.nocobase.com/202404202143135.png"/>
103
+ <img src="https://static-docs.nocobase.com/202404202143135.png"/>
@@ -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
+
10
+ "use strict";(self.webpackChunk_nocobase_plugin_ai=self.webpackChunk_nocobase_plugin_ai||[]).push([["462"],{8349:function(e,t,n){n.r(t),n.d(t,{Employees:function(){return eB}});var r=n(9155),o=n.n(r),l=n(2059),a=n(3342),i=n(3079),c=n(5230),u=n(4450),s=n(3059),m=n.n(s),p=n(5477);function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function d(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var l=[],a=!0,i=!1;try{for(o=o.call(e);!(a=(n=o.next()).done)&&(l.push(n.value),!t||l.length!==t);a=!0);}catch(e){i=!0,r=e}finally{try{a||null==o.return||o.return()}finally{if(i)throw r}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return f(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return f(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function y(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}function v(){var e=y(["\n border-color: "," !important;\n "]);return v=function(){return e},e}function b(){var e=y(["\n cursor: pointer;\n &:hover {\n border-color: "," !important;\n }\n "]);return b=function(){return e},e}function g(){var e=y(["\n border: 2px solid "," !important;\n "]);return g=function(){return e},e}function h(){var e=y(["\n cursor: pointer;\n &:hover {\n border: 2px solid "," !important;\n }\n "]);return h=function(){return e},e}var S=function(e){var t=e.srcs,n=e.size,r=void 0===n?"large":n,i=e.selectable,c=e.highlightItem,u=e.onClick,s=(0,a.useToken)().token,f=(0,a.useUploadStyles)(),y=(f.wrapSSR,f.hashId,f.componentCls);return null==t||t.map(function(e,t){var n=d(e,2),r=n[0],l=n[1];return o().createElement("div",{key:t,className:"".concat(y,"-list-picture-card-container ").concat(y,"-list-item-container")},o().createElement("div",{onClick:function(){return u&&u(l)},className:m()("".concat(y,"-list-item"),"".concat(y,"-list-item-done"),"".concat(y,"-list-item-list-type-picture-card"),c===l?(0,p.css)(v(),s.colorPrimary):"",i?(0,p.css)(b(),s.colorPrimary):"")},o().createElement("div",{className:"".concat(y,"-list-item-info")},o().createElement("span",{key:"thumbnail",className:"".concat(y,"-list-item-thumbnail")},o().createElement("img",{src:r,className:"".concat(y,"-list-item-image")})))))}),o().createElement(l.List,{grid:{gutter:16,column:10},itemLayout:"horizontal",dataSource:t,renderItem:function(e){var t=d(e,2),n=t[0],a=t[1];return o().createElement(l.List.Item,null,o().createElement(l.Avatar,{size:"small"===r?45:80,className:m()(c===a?(0,p.css)(g(),s.colorPrimary):"",i?(0,p.css)(h(),s.colorPrimary):""),src:n,onClick:function(){return u&&u(a)}}))}})},E=function(e){var t=e.disabled,n=(0,c.useField)(),l=Object.keys(u.B)[0],a=d(o().useState(l),2),i=a[0],s=a[1];(0,r.useEffect)(function(){n.value||n.setInitialValue(l)},[n]),(0,r.useEffect)(function(){n.value&&s(n.value)},[n.value]);var m=(0,r.useMemo)(function(){return Object.keys(u.B).map(function(e){return{seed:e,uri:(0,u.H)(e)}})},[]);return o().createElement(o().Fragment,null,o().createElement("div",{style:{marginBottom:"16px"}},o().createElement(S,{srcs:i?[[(0,u.H)(i),i]]:[]})),!0!==t?o().createElement(S,{srcs:m.map(function(e){return[e.uri,e.seed]}),size:"small",selectable:!0,highlightItem:i,onClick:function(e){return n.value=e}}):o().createElement(o().Fragment,null))},x=function(e){var t=e.edit,n=(0,i.kj)(),r=(0,a.useCollectionRecordData)(),l=null==r?void 0:r.builtIn;return o().createElement(a.SchemaComponent,{scope:{t:n},components:{AvatarSelect:E},schema:{type:"void",properties:{username:{type:"string",title:'{{t("Username")}}',"x-decorator":"FormItem","x-component":"Input",required:!0,"x-disabled":t},nickname:{type:"string",title:'{{t("Nickname")}}',"x-disabled":l,"x-decorator":"FormItem","x-component":"Input",required:!0},position:{type:"string",title:'{{t("Position")}}',"x-disabled":l,"x-decorator":"FormItem","x-component":"Input",description:n("Position description"),"x-component-props":{placeholder:n("Position placeholder")}},avatar:{type:"string",title:'{{t("Avatar")}}',"x-decorator":"FormItem","x-component":"AvatarSelect","x-component-props":{disabled:l}},bio:{type:"string",title:'{{t("Bio")}}',"x-disabled":l,"x-decorator":"FormItem","x-component":"Input.TextArea","x-component-props":{placeholder:n("Bio placeholder")}},greeting:{type:"string",title:'{{t("Greeting message")}}',"x-disabled":l,"x-decorator":"FormItem","x-component":"Input.TextArea","x-component-props":{placeholder:n("Greeting message placeholder")}}}}})};function A(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function k(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}function w(){var e=k(["\n background-color: #fafafa;\n border: 1px solid #d9d9d9;\n border-radius: 6px;\n padding: 8px 12px;\n min-height: 330px;\n max-height: 500px;\n overflow-y: auto;\n "]);return w=function(){return e},e}function C(){var e=k(["\n margin: 0 !important;\n white-space: pre-wrap;\n word-break: break-word;\n "]);return C=function(){return e},e}function I(){var e=k(["\n width: 100%;\n "]);return I=function(){return e},e}function j(){var e=k(["\n width: 100%;\n "]);return j=function(){return e},e}var O=l.Typography.Paragraph,P=function(){var e=(0,i.kj)(),t=(0,a.useCurrentUserVariable)({maxDepth:3,noDisabled:!0}).currentUserSettings,n=(0,a.useCurrentRoleVariable)({noDisabled:!0}).currentRoleSettings,r=(0,a.useDatetimeVariable)({noDisabled:!0}).datetimeSettings;return[t,n,{key:"$nLang",value:"$nLang",label:e("Current language")},r]},T=function(){var e=(0,i.kj)();return o().createElement(l.Alert,{style:{marginBottom:16},message:e("Role setting description"),type:"info"})},z=function(){var e,t,n=(0,i.kj)(),u=(0,a.useCollectionRecordData)(),s=(0,c.useForm)(),m=P(),f=(null==u?void 0:u.about)?"custom":"system",d=function(e){if(Array.isArray(e))return e}(e=(0,r.useState)(f))||function(e){var t,n,r=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var o=[],l=!0,a=!1;try{for(r=r.call(e);!(l=(t=r.next()).done)&&(o.push(t.value),2!==o.length);l=!0);}catch(e){a=!0,n=e}finally{try{l||null==r.return||r.return()}finally{if(a)throw n}}return o}}(e)||function(e){if(e){if("string"==typeof e)return A(e,2);var t=Object.prototype.toString.call(e).slice(8,-1);if("Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t)return Array.from(t);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return A(e,2)}}(e)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(),y=d[0],v=d[1];(0,r.useEffect)(function(){s.setValuesIn("_aboutMode",y)},[s,y]);var b=(null==u?void 0:u.defaultPrompt)||"",g=function(e){v(e)};return o().createElement(l.Space,{direction:"vertical",style:{width:"100%"}},o().createElement(l.Radio.Group,{value:y,onChange:function(e){return g(e.target.value)}},o().createElement(l.Radio,{value:"system"},n("System default")),o().createElement(l.Radio,{value:"custom"},n("Custom"))),"system"===y?o().createElement("div",{className:(0,p.css)(w())},o().createElement(O,{copyable:!0,className:(0,p.css)(C())},b)):o().createElement(a.Variable.RawTextArea,{value:null!=(t=s.values.about)?t:"",onChange:function(e){s.setValuesIn("about",e.target.value)},scope:m,placeholder:n("Role setting placeholder"),autoSize:{minRows:15},className:(0,p.css)(I())}))},F=function(){var e,t=(0,i.kj)(),n=(0,c.useForm)(),r=P();return o().createElement(a.Variable.RawTextArea,{value:null!=(e=n.values.about)?e:"",onChange:function(e){n.setValuesIn("about",e.target.value)},scope:r,placeholder:t("Role setting placeholder"),autoSize:{minRows:15},className:(0,p.css)(j())})},M=function(){var e=(0,a.useCollectionRecordData)();return(null==e?void 0:e.builtIn)?o().createElement(z,null):o().createElement(F,null)},B=function(){var e=(0,i.kj)();return o().createElement(a.SchemaComponent,{scope:{t:e},components:{Description:T,AboutField:M},schema:{type:"void",properties:{desc:{type:"void","x-component":"Description"},aboutWrap:{type:"void","x-component":"div",properties:{about:{type:"string",title:'{{t("Role setting")}}',"x-decorator":"FormItem","x-component":"AboutField"}}}}}})},R=n(7694),D=n(475);function L(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var K=function(e){return e.llmService&&e.model?"".concat(e.llmService,":").concat(e.model):void 0},V=function(e){var t,n=function(e){if(Array.isArray(e))return e}(t=e.split(":"))||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(t)||function(e){if(e){if("string"==typeof e)return L(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);if("Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t)return Array.from(t);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return L(e,void 0)}}(t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}();return{llmService:n[0],model:n.slice(1).join(":")}},N=function(e){var t=e.serviceTitle,n=e.modelLabel;return"".concat(t," / ").concat(n)},U=(0,R.observer)(function(){var e=(0,i.kj)(),t=(0,c.useForm)(),n=(0,D.l)(),a=n.services,u=n.loading,s=(0,r.useMemo)(function(){return t.values.modelSettings||{}},[t.values.modelSettings]),m=!!s.enabled,p=(0,r.useMemo)(function(){var e=Array.isArray(s.models)?s.models:[];if(e.length)return e.map(K).filter(Boolean);var t=K(s);return t?[t]:[]},[s]),f=(0,r.useMemo)(function(){return a.map(function(e){return{label:e.llmServiceTitle,options:e.enabledModels.map(function(t){return{label:N({serviceTitle:e.llmServiceTitle,modelLabel:t.label}),value:"".concat(e.llmService,":").concat(t.value)}})}})},[a]),d=(0,r.useMemo)(function(){var e=new Map;return f.forEach(function(t){t.options.forEach(function(t){e.set(t.value,t.label)})}),e},[f]),y=(0,r.useCallback)(function(e){t.setValuesIn("modelSettings",function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}({},s,e))},[t,s]);return(0,r.useEffect)(function(){if(m&&!p.length&&f.length){var e,t,n,r=null==(n=f[0])||null==(t=n.options)||null==(e=t[0])?void 0:e.value;r&&y({models:[V(r)]})}},[m,f,p.length,y]),o().createElement("div",null,o().createElement(l.Alert,{type:"info",showIcon:!0,message:e("Restrict this AI employee to the selected models."),style:{marginBottom:16}}),o().createElement(l.Form,{layout:"vertical"},o().createElement(l.Form.Item,{label:o().createElement(l.Typography.Text,{strong:!0},e("Enable dedicated model configuration"))},o().createElement(l.Switch,{checked:m,onChange:function(e){return y({enabled:e})}})),o().createElement(l.Form.Item,{label:o().createElement(l.Typography.Text,{strong:!0},e("Models"))},o().createElement(l.Select,{allowClear:!0,disabled:!m,mode:"multiple",showSearch:!0,value:p,placeholder:e("Select models"),options:f,onChange:function(e){(null==e?void 0:e.length)?y({llmService:void 0,model:void 0,models:e.map(V)}):y({llmService:void 0,model:void 0,models:[]})},tagRender:function(e){var t=e.closable,n=e.onClose,r=e.value;return o().createElement(l.Tag,{closable:t,onClose:n,style:{marginInlineEnd:4}},d.get(String(r))||e.label)},loading:u,notFoundContent:u?o().createElement(l.Spin,{size:"small"}):null,optionFilterProp:"label"}))))}),W={name:"aiEmployees",fields:[{name:"username",type:"string",primaryKey:!0},{name:"nickname",type:"string",interface:"input"},{name:"position",type:"string",interface:"input"},{name:"avatar",type:"string",interface:"image"},{name:"bio",type:"text",interface:"textarea"},{name:"about",type:"text",interface:"textarea"},{name:"defaultPrompt",type:"text",interface:"textarea"},{name:"greeting",type:"text",interface:"textarea"},{name:"chatSettings",type:"jsonb"},{name:"skillSettings",type:"jsonb"},{name:"modelSettings",type:"jsonb"},{name:"dataSourceSettings",type:"jsonb"},{name:"enableKnowledgeBase",type:"boolean",allowNull:!1,defaultValue:!1},{name:"knowledgeBasePrompt",type:"text"},{name:"knowledgeBase",type:"jsonb"},{name:"enabled",type:"boolean",interface:"switch",allowNull:!1,defaultValue:!0},{name:"builtIn",type:"boolean",allowNull:!1,defaultValue:!1},{name:"category",type:"string",allowNull:!1,defaultValue:"business"},{name:"deprecated",type:"boolean",allowNull:!1,defaultValue:!1}]},$=n(7330);function G(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var q=function(e){var t=e.skills,n=(0,i.kj)(),r=(0,a.useToken)().token,u=t.filter(function(e){return"GENERAL"===e.scope});return o().createElement(l.Collapse,{ghost:!0,size:"small",defaultActiveKey:[],items:[{key:"general-skills",label:o().createElement("div",null,o().createElement("div",{style:{fontWeight:r.fontWeightStrong,fontSize:r.fontSizeSM}},n("General skills")),o().createElement("div",{style:{color:r.colorTextSecondary,fontSize:r.fontSizeSM}},n("Shared by all AI employees."))),children:o().createElement(l.List,{itemLayout:"vertical",size:"small",dataSource:u,renderItem:function(e){var t,a,i;return o().createElement(l.List.Item,{key:e.name},o().createElement("div",{style:{fontSize:r.fontSizeSM}},c.Schema.compile(null!=(t=null==e?void 0:e.title)?t:e.name,{t:n})),o().createElement("div",{style:{color:r.colorTextSecondary,fontSize:r.fontSizeSM}},c.Schema.compile(null!=(a=null!=(i=null==e?void 0:e.about)?i:e.description)?a:"",{t:n})))}})}]})},_=function(e){var t=e.selectedSkills,n=e.skills,r=(0,i.kj)(),u=(0,a.useToken)().token,s=new Map(n.map(function(e){return[e.name,e]})),m=t.map(function(e){return s.get(e)});return o().createElement(l.Collapse,{ghost:!0,size:"small",items:[{key:"specific-skills",label:o().createElement("div",null,o().createElement("div",{style:{fontWeight:u.fontWeightStrong,fontSize:u.fontSizeSM}},r("Employee-specific skills")),o().createElement("div",{style:{color:u.colorTextSecondary,fontSize:u.fontSizeSM}},r("Only available to this AI employee."))),children:o().createElement(l.List,{itemLayout:"vertical",size:"small",dataSource:m,renderItem:function(e){var t,n,a;return o().createElement(l.List.Item,{key:e.name},o().createElement("div",{style:{fontSize:u.fontSizeSM}},c.Schema.compile(null!=(t=null==e?void 0:e.title)?t:e.name,{t:r})),o().createElement("div",{style:{color:u.colorTextSecondary,fontSize:u.fontSizeSM}},c.Schema.compile(null!=(n=null!=(a=null==e?void 0:e.about)?a:e.description)?n:"",{t:r})))}})}],defaultActiveKey:["specific-skills"]})},H=(0,R.observer)(function(){var e,t=(0,c.useField)(),n=(0,$.M)(),i=n.aiSkillsLoading,u=n.aiSkills,s=(0,a.useCollectionRecordData)(),m=null==s?void 0:s.builtIn,p=null!=(e=t.value)?e:[];(0,r.useEffect)(function(){n.getAISkills()},[n]);var f=function(e){if(Array.isArray(e))return G(e)}(p)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(p)||function(e){if(e){if("string"==typeof e)return G(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);if("Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t)return Array.from(t);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return G(e,void 0)}}(p)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(),d=new Map(u.map(function(e){return[e.name,e]})),y=f.filter(function(e){var t=d.get(e);return t&&"SPECIFIED"===t.scope});return o().createElement(o().Fragment,null,!i&&o().createElement(l.Space,{direction:"vertical",size:"large",style:{width:"100%"}},o().createElement(q,{skills:u}),m&&y.length>0&&o().createElement(_,{selectedSkills:y,skills:u})))}),X=function(){return o().createElement(a.SchemaComponent,{components:{Skills:H},schema:{type:"void",properties:{skillSettings:{type:"object",properties:{skills:{type:"array","x-component":"Skills","x-decorator":"FormItem"}}}}}})},Y=n(166),J=n(9452);function Q(e,t,n,r,o,l,a){try{var i=e[l](a),c=i.value}catch(e){n(e);return}i.done?t(c):Promise.resolve(c).then(r,o)}function Z(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var l=e.apply(t,n);function a(e){Q(l,r,o,a,i,"next",e)}function i(e){Q(l,r,o,a,i,"throw",e)}a(void 0)})}}function ee(e,t){var n,r,o,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(a,"next",{value:c(0)}),i(a,"throw",{value:c(1)}),i(a,"return",{value:c(2)}),"function"==typeof Symbol&&i(a,Symbol.iterator,{value:function(){return this}}),a;function c(i){return function(c){var u=[i,c];if(n)throw TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(l=0)),l;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return l.label++,{value:u[1],done:!1};case 5:l.label++,r=u[1],u=[0];continue;case 7:u=l.ops.pop(),l.trys.pop();continue;default:if(!(o=(o=l.trys).length>0&&o[o.length-1])&&(6===u[0]||2===u[0])){l=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){l.label=u[1];break}if(6===u[0]&&l.label<o[1]){l.label=o[1],o=u;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(u);break}o[2]&&l.ops.pop(),l.trys.pop();continue}u=t.call(e,l)}catch(e){u=[6,e],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var et=function(){var e=(0,i.kj)();return{form:(0,r.useMemo)(function(){return(0,J.createForm)({initialValues:{username:"".concat((0,Y.uid)()),enabled:!0,enableKnowledgeBase:!1,knowledgeBase:{knowledgeBaseKeys:[],topK:3,score:"0.6"},knowledgeBasePrompt:e("knowledge Base Prompt default")}})},[e])}},en=function(){var e=(0,a.useCollectionRecordData)();return{form:(0,r.useMemo)(function(){return(0,J.createForm)({initialValues:e})},[e])}},er=function(){var e=(0,a.useActionContext)().setVisible,t=(0,c.useForm)();return{type:"default",onClick:function(){e(!1),t.reset()}}},eo=function(){var e=(0,a.useActionContext)().setVisible,t=l.App.useApp().message,n=(0,c.useForm)(),r=(0,a.useAPIClient)(),o=(0,a.useDataBlockRequest)().refresh,u=(0,$.M)(),s=(0,i.kj)();return{type:"primary",onClick:function(){return Z(function(){var l;return ee(this,function(a){switch(a.label){case 0:return l=n.values,[4,n.submit()];case 1:return a.sent(),[4,r.resource("aiEmployees").create({values:l})];case 2:return a.sent(),o(),t.success(s("Saved successfully")),e(!1),n.reset(),[4,u.refreshAIEmployees()];case 3:return a.sent(),[2]}})})()}}},el=function(){var e=(0,a.useActionContext)().setVisible,t=l.App.useApp().message,n=(0,c.useForm)(),r=(0,a.useDataBlockResource)(),o=(0,a.useDataBlockRequest)().refresh,u=(0,$.M)(),s=(0,a.useCollection)().getFilterTargetKey(),m=(0,i.kj)();return{type:"primary",onClick:function(){return Z(function(){var l;return ee(this,function(a){switch(a.label){case 0:return"system"===(l=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}({},n.values))._aboutMode&&(l.about=null),delete l._aboutMode,delete l.enabled,[4,n.submit()];case 1:return a.sent(),[4,r.update({values:l,filterByTk:l[s]})];case 2:return a.sent(),o(),t.success(m("Saved successfully")),e(!1),n.reset(),[4,u.refreshAIEmployees()];case 3:return a.sent(),[2]}})})()}}},ea=function(){var e=(0,i.kj)(),t=(0,a.useCollectionRecordData)(),n=(0,a.useDestroyActionProps)().onClick,r=null==t?void 0:t.builtIn,o=l.App.useApp().message,c="root"===(0,a.useAPIClient)().auth.role;return{onClick:function(t,l){return Z(function(){return ee(this,function(a){switch(a.label){case 0:if(r&&!c)return o.warning(e("Cannot delete built-in ai employees")),[2];return[4,n(t,l)];case 1:return a.sent(),[2]}})})()}}};function ei(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var ec=l.Card.Meta,eu=(0,r.createContext)(null),es=function(){var e=(0,r.useContext)(eu).aiEmployee;return{form:(0,r.useMemo)(function(){return(0,J.createForm)({initialValues:e})},[e])}},em=function(e){var t=e.aiEmployee,n=(0,a.useToken)().token,r=(0,a.useActionContext)().setVisible;return o().createElement(l.Card,{variant:"borderless",hoverable:!0,onClick:function(){return r(!0)}},o().createElement(ec,{avatar:t.avatar?o().createElement(l.Avatar,{size:40,src:(0,u.H)(t.avatar)}):null,title:t.nickname,description:o().createElement(o().Fragment,null,t.position&&o().createElement(l.Tag,{style:{marginBottom:n.marginXS}},t.position),o().createElement(l.Typography.Paragraph,{style:{height:n.fontSize*n.lineHeight*3},ellipsis:{rows:3},type:"secondary"},t.bio))}))},ep=function(){var e,t=function(e){if(Array.isArray(e))return e}(e=o().useState(!1))||function(e){var t,n,r=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var o=[],l=!0,a=!1;try{for(r=r.call(e);!(l=(t=r.next()).done)&&(o.push(t.value),2!==o.length);l=!0);}catch(e){a=!0,n=e}finally{try{l||null==r.return||r.return()}finally{if(a)throw n}}return o}}(e)||function(e){if(e){if("string"==typeof e)return ei(e,2);var t=Object.prototype.toString.call(e).slice(8,-1);if("Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t)return Array.from(t);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return ei(e,2)}}(e)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(),n=t[0],r=t[1],i=(0,a.useAPIClient)(),c=(0,a.useRequest)(function(){return i.resource("aiEmployees").getTemplates().then(function(e){var t;return null==e||null==(t=e.data)?void 0:t.data})}),u=c.data;return c.loading?o().createElement(l.Spin,null):u&&u.length?o().createElement(l.Row,{gutter:[16,16]},u.map(function(e){return o().createElement(a.ActionContextProvider,{key:e.username,value:{visible:n,setVisible:r}},o().createElement(l.Col,{span:12},o().createElement(em,{aiEmployee:e})),o().createElement(eu.Provider,{value:{aiEmployee:e}},o().createElement(a.SchemaComponent,{scope:{useCancelActionProps:er,useCreateActionProps:eo,useTemplateFormProps:es},schema:{type:"void",name:(0,Y.uid)(),"x-component":"Action.Drawer",title:'{{t("New AI employee")}}',"x-decorator":"FormV2","x-use-decorator-props":"useTemplateFormProps",properties:{form:{type:"void","x-component":"AIEmployeeForm"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{close:{title:"Cancel","x-component":"Action","x-component-props":{type:"default"},"x-use-component-props":"useCancelActionProps"},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary"},"x-use-component-props":"useCreateActionProps"}}}}}})))})):o().createElement(l.Empty,{image:l.Empty.PRESENTED_IMAGE_SIMPLE})},ef=n(418),ed=function(){return(0,i.kj)(),o().createElement(a.SchemaComponent,{components:{Switch:ef.Switch},schema:{type:"void",properties:{enableKnowledgeBase:{type:"boolean",title:'{{t("Enable Knowledge Base")}}',"x-decorator":"FormItem","x-component":"Switch"},knowledgeBasePrompt:{type:"string",title:'{{t("Knowledge Base Prompt")}}',required:!0,"x-decorator":"FormItem","x-component":"Input.TextArea","x-component-props":{autoSize:{minRows:5}},"x-reactions":[{dependencies:["enableKnowledgeBase"],fulfill:{state:{disabled:"{{$deps[0] === false}}"}}}]},knowledgeBase:{type:"object",properties:{knowledgeBaseKeys:{type:"array",title:'{{t("Knowledge Base")}}',required:!0,"x-decorator":"FormItem","x-component":"RemoteSelect","x-component-props":{mode:"multiple",manual:!1,fieldNames:{label:"name",value:"key"},service:{resource:"aiKnowledgeBase",action:"list",params:{fields:["key","name"],filter:{enabled:!0}}}},"x-reactions":[{dependencies:["enableKnowledgeBase"],fulfill:{state:{disabled:"{{$deps[0] === false}}"}}}]},topK:{type:"number",title:'{{t("Top K")}}',required:!0,"x-decorator":"FormItem","x-component":"InputNumber","x-component-props":{min:1,max:100},"x-reactions":[{dependencies:["enableKnowledgeBase"],fulfill:{state:{disabled:"{{$deps[0] === false}}"}}}]},score:{type:"number",title:'{{t("Score")}}',required:!0,"x-decorator":"FormItem","x-component":"InputNumber","x-component-props":{min:0,max:1,step:.1},"x-reactions":[{dependencies:["enableKnowledgeBase"],fulfill:{state:{disabled:"{{$deps[0] === false}}"}}}]}}}}}})},ey=n(7375);function ev(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function eb(e,t,n,r,o,l,a){try{var i=e[l](a),c=i.value}catch(e){n(e);return}i.done?t(c):Promise.resolve(c).then(r,o)}var eg=function(){var e,t=(0,c.useField)(),n=(0,a.useCollectionRecordData)(),u=(0,a.useDataBlockResource)(),s=(0,a.useDataBlockRequest)().refresh,m=(0,$.M)(),p=l.App.useApp().message,f=(0,i.kj)(),d=function(e){if(Array.isArray(e))return e}(e=(0,r.useState)(!1))||function(e){var t,n,r=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var o=[],l=!0,a=!1;try{for(r=r.call(e);!(l=(t=r.next()).done)&&(o.push(t.value),2!==o.length);l=!0);}catch(e){a=!0,n=e}finally{try{l||null==r.return||r.return()}finally{if(a)throw n}}return o}}(e)||function(e){if(e){if("string"==typeof e)return ev(e,2);var t=Object.prototype.toString.call(e).slice(8,-1);if("Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t)return Array.from(t);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return ev(e,2)}}(e)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(),y=d[0],v=d[1];return o().createElement(l.Switch,{checked:t.value,onChange:function(e){var t;return(t=function(){return function(e,t){var n,r,o,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(a,"next",{value:c(0)}),i(a,"throw",{value:c(1)}),i(a,"return",{value:c(2)}),"function"==typeof Symbol&&i(a,Symbol.iterator,{value:function(){return this}}),a;function c(i){return function(c){var u=[i,c];if(n)throw TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(l=0)),l;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return l.label++,{value:u[1],done:!1};case 5:l.label++,r=u[1],u=[0];continue;case 7:u=l.ops.pop(),l.trys.pop();continue;default:if(!(o=(o=l.trys).length>0&&o[o.length-1])&&(6===u[0]||2===u[0])){l=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){l.label=u[1];break}if(6===u[0]&&l.label<o[1]){l.label=o[1],o=u;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(u);break}o[2]&&l.ops.pop(),l.trys.pop();continue}u=t.call(e,l)}catch(e){u=[6,e],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}(this,function(t){switch(t.label){case 0:v(!0),t.label=1;case 1:return t.trys.push([1,4,5,6]),[4,u.update({filterByTk:n.username,values:{enabled:e}})];case 2:return t.sent(),p.success(f("Saved successfully")),s(),[4,m.refreshAIEmployees()];case 3:return t.sent(),[3,6];case 4:return t.sent(),p.error(f("Failed to update")),[3,6];case 5:return v(!1),[7];case 6:return[2]}})},function(){var e=this,n=arguments;return new Promise(function(r,o){var l=t.apply(e,n);function a(e){eb(l,r,o,a,i,"next",e)}function i(e){eb(l,r,o,a,i,"throw",e)}a(void 0)})})()},loading:y,size:"small"})};function eh(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function eS(e){return function(e){if(Array.isArray(e))return eh(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||eE(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function eE(e,t){if(e){if("string"==typeof e)return eh(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return eh(e,t)}}var ex=function(e){var t,n=e.name,r=e.title,u=e.description,s=e.isRoot,m=(0,i.kj)(),p=(0,a.useToken)().token,f=null==(t=(0,c.useField)().value)?void 0:t.find(function(e){return e.name===n});return o().createElement("div",{style:{minWidth:"150px",maxWidth:"300px"}},o().createElement("div",{style:{display:"flex",justifyContent:"space-between"}},o().createElement("div",null,c.Schema.compile(r,{t:m})),!s&&o().createElement("div",null,o().createElement(l.Switch,{size:"small",value:f,disabled:f}))),o().createElement("div",{style:{color:p.colorTextSecondary,fontSize:p.fontSizeSM}},c.Schema.compile(u,{t:m})))},eA=(0,R.observer)(function(){var e,t,n=(0,i.kj)(),u=(0,a.useToken)().token,s=(0,c.useField)(),m=(0,$.M)(),p=m.aiToolsLoading,f=m.aiTools,d=(0,a.useCollectionRecordData)(),y=null==d?void 0:d.builtIn;(0,r.useEffect)(function(){m.getAITools()},[m]);var v=function(e){console.log(e);var t=eS(s.value||[]);t.some(function(t){return t.name===e})||t.push({name:e,autoCall:!1}),console.log(s.value),console.log(t),s.value=t,console.log(s.value)},b=eS(null!=(t=s.value)?t:[]),g=new Set(b.map(function(e){return e.name})),h=(null==f?void 0:f.filter(function(e){return"CUSTOM"===e.scope&&!g.has(e.definition.name)}).map(function(e){var t,n,r={key:e.definition.name},l={title:null!=(t=e.introduction.title)?t:"",description:null!=(n=e.introduction.about)?n:"",name:e.definition.name,isRoot:!0};return r.label=o().createElement(ex,l),r.onClick=function(){return v(e.definition.name)},r}))||[],S=new Map(f.map(function(e){return[e.definition.name,e]})),E=f.filter(function(e){return"GENERAL"===e.scope&&"loader"===e.from}),x=b.filter(function(e){var t=S.get(e.name);return t&&"GENERAL"!==t.scope&&"CUSTOM"!==t.scope}),A=b.filter(function(e){var t=S.get(e.name);return t&&"CUSTOM"===t.scope}),k=[{label:n("Ask"),value:"ASK"},{label:n("Allow"),value:"ALLOW"}],w=function(e,t){return"CUSTOM"===e.scope?(null==t?void 0:t.autoCall)?"ALLOW":"ASK":"ALLOW"===e.defaultPermission?"ALLOW":"ASK"},C=function(e){if(Array.isArray(e))return e}(e=(0,r.useState)(y&&0===A.length?[]:["custom-tools"]))||function(e){var t,n,r=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var o=[],l=!0,a=!1;try{for(r=r.call(e);!(l=(t=r.next()).done)&&(o.push(t.value),2!==o.length);l=!0);}catch(e){a=!0,n=e}finally{try{l||null==r.return||r.return()}finally{if(a)throw n}}return o}}(e)||eE(e,2)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(),I=C[0],j=C[1],O=(0,r.useRef)(A.length);return(0,r.useEffect)(function(){var e=0===O.current;y&&0===A.length?j([]):e&&A.length>0&&j(["custom-tools"]),O.current=A.length},[A.length,y]),o().createElement(o().Fragment,null,!p&&o().createElement(l.Space,{direction:"vertical",size:"large",style:{width:"100%"}},o().createElement("div",null,o().createElement(l.Collapse,{ghost:!0,size:"small",defaultActiveKey:[],items:[{key:"general-tools",label:o().createElement("div",null,o().createElement("div",{style:{fontWeight:u.fontWeightStrong,fontSize:u.fontSizeSM}},n("General tools")),o().createElement("div",{style:{color:u.colorTextSecondary,fontSize:u.fontSizeSM}},n("Shared by all AI employees."))),children:o().createElement(l.List,{itemLayout:"vertical",size:"small",dataSource:E,renderItem:function(e){return o().createElement(l.List.Item,{key:e.definition.name,extra:o().createElement(l.Flex,{vertical:!0,justify:"end"},o().createElement("div",{style:{fontSize:u.fontSizeSM,color:u.colorTextSecondary}},n("Permission"),o().createElement(l.Segmented,{style:{marginLeft:"8px"},size:"small",options:k,value:w(e),disabled:!0})))},o().createElement("div",{style:{fontSize:u.fontSizeSM}},c.Schema.compile(e.introduction.title,{t:n})),o().createElement("div",{style:{color:u.colorTextSecondary,fontSize:u.fontSizeSM}},c.Schema.compile(e.introduction.about,{t:n})))}})}]})),y&&x.length>0&&o().createElement("div",null,o().createElement(l.Collapse,{ghost:!0,size:"small",items:[{key:"specific-tools",label:o().createElement("div",null,o().createElement("div",{style:{fontWeight:u.fontWeightStrong,fontSize:u.fontSizeSM}},n("Employee-specific tools")),o().createElement("div",{style:{color:u.colorTextSecondary,fontSize:u.fontSizeSM}},n("Only available to this AI employee."))),children:o().createElement(l.List,{itemLayout:"vertical",size:"small",dataSource:x,renderItem:function(e){var t=S.get(e.name);return t?o().createElement(l.List.Item,{key:t.definition.name,extra:o().createElement(l.Flex,{vertical:!0,justify:"end"},o().createElement("div",{style:{fontSize:u.fontSizeSM,color:u.colorTextSecondary}},n("Permission"),o().createElement(l.Segmented,{style:{marginLeft:"8px"},size:"small",options:k,value:w(t,e),disabled:!0})))},o().createElement("div",{style:{fontSize:u.fontSizeSM}},c.Schema.compile(t.introduction.title,{t:n})),o().createElement("div",{style:{color:u.colorTextSecondary,fontSize:u.fontSizeSM}},c.Schema.compile(t.introduction.about,{t:n}))):null}})}],defaultActiveKey:["specific-tools"]})),o().createElement("div",null,o().createElement(l.Collapse,{ghost:!0,size:"small",activeKey:I,onChange:function(e){j(Array.isArray(e)?e:[e].filter(Boolean))},items:[{key:"custom-tools",label:o().createElement("div",null,o().createElement("div",{style:{fontWeight:u.fontWeightStrong,fontSize:u.fontSizeSM}},n("Custom tools")),o().createElement("div",{style:{color:u.colorTextSecondary,fontSize:u.fontSizeSM}},n("Created by workflow. You can add/remove and set default permissions."))),extra:o().createElement("div",{onClick:function(e){e.stopPropagation()},onKeyDown:function(e){e.stopPropagation()}},o().createElement(l.Dropdown,{menu:{items:h},placement:"bottomRight",disabled:0===h.length},o().createElement(l.Button,{type:"primary",icon:o().createElement(ey.PlusOutlined,null)},n("Add tool")))),children:o().createElement(l.List,{itemLayout:"vertical",bordered:!0,dataSource:A,renderItem:function(e){var t=S.get(e.name);return t?o().createElement(l.List.Item,{key:t.definition.name,extra:o().createElement(l.Flex,{vertical:!0,justify:"end"},o().createElement(l.Space,null,o().createElement("div",{style:{fontSize:u.fontSizeSM}},n("Permission"),o().createElement(l.Segmented,{style:{marginLeft:"8px",marginRight:"8px"},size:"small",options:k,value:w(t,e),onChange:function(t){var n=(s.value||[]).map(function(n){var r,o;return n.name===e.name?(r=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}({},n),o=o={autoCall:"ALLOW"===t},Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(o)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(o)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(o,e))}),r):n});s.value=n}})),o().createElement(l.Button,{icon:o().createElement(ey.DeleteOutlined,null),variant:"link",color:"default",onClick:function(){var e=eS(s.value||[]),n=e.findIndex(function(e){return e.name===t.definition.name});-1!==n&&(e.splice(n,1),s.value=e)}})))},o().createElement("div",null,c.Schema.compile(t.introduction.title,{t:n})),o().createElement("div",{style:{color:u.colorTextSecondary,fontSize:u.fontSizeSM}},c.Schema.compile(t.introduction.about,{t:n}))):null}})}]}))))}),ek=function(){return o().createElement(a.SchemaComponent,{components:{Tools:eA},schema:{type:"void",properties:{skillSettings:{type:"object",properties:{tools:{type:"array","x-component":"Tools","x-decorator":"FormItem"}}}}}})};function ew(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function eC(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}function eI(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function ej(e){return function(e){if(Array.isArray(e))return ew(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||eO(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function eO(e,t){if(e){if("string"==typeof e)return ew(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return ew(e,t)}}var eP=function(e){var t,n,u,s=e.edit,m=(0,i.kj)(),p=(0,a.useAPIClient)(),f=(0,c.useForm)(),d=function(e){if(Array.isArray(e))return e}(t=(0,r.useState)(!1))||function(e){var t,n,r=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var o=[],l=!0,a=!1;try{for(r=r.call(e);!(l=(t=r.next()).done)&&(o.push(t.value),2!==o.length);l=!0);}catch(e){a=!0,n=e}finally{try{l||null==r.return||r.return()}finally{if(a)throw n}}return o}}(t)||eO(t,2)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(),y=d[0],v=d[1],b=null!=(n=null==(u=f.values)?void 0:u.chatSettings)?n:{},g=!1!==b.enableSkills,h=!1!==b.enableTools;return(0,r.useEffect)(function(){p.resource("aiSettings").isKnowledgeBaseEnabled().then(function(e){var t;v(null==e||null==(t=e.data)?void 0:t.data.enabled)}).catch(function(e){return console.error("api fail aiSettings.isKnowledgeBaseEnabled",e)})},[p]),o().createElement(l.Tabs,{items:[{key:"profile",label:m("Profile"),children:o().createElement(x,{edit:s}),forceRender:!0},{key:"roleSetting",label:m("Role setting"),children:o().createElement(B,null),forceRender:!0},{key:"modelSettings",label:m("Model settings"),children:o().createElement(U,null),forceRender:!0}].concat(ej(g?[{key:"skills",label:m("Skills"),children:o().createElement(X,null)}]:[]),ej(h?[{key:"tools",label:m("Tools"),children:o().createElement(ek,null)}]:[]),ej(y?[{key:"knowledgeBase",label:m("KnowledgeBase"),children:o().createElement(ed,null)}]:[]))})},eT=function(e){var t=(0,c.useField)();return t.value?o().createElement(l.Avatar,eI(eC({shape:"square",size:"large"},e),{src:(0,u.H)(t.value)})):null},ez=function(e){var t=(0,c.useField)();return t.value?t.value&&o().createElement(ey.CheckOutlined,{style:{color:"#52c41a"}}):null},eF=function(){var e,t,n,r=(0,i.kj)(),c=(0,a.useTableBlockContext)().service,u=(null==c||null==(n=c.params)||null==(t=n[0])||null==(e=t.filter)?void 0:e.category)||"business",s=[{label:r("Business"),value:"business"},{label:r("Developer"),value:"developer"}];return o().createElement(l.Radio.Group,{value:u,optionType:"button",options:s,onChange:function(e){var t,n,r;e.target.value!==u&&(null==c||c.run(eI(eC({},null==c||null==(t=c.params)?void 0:t[0]),{page:1,filter:eI(eC({},null==c||null==(r=c.params)||null==(n=r[0])?void 0:n.filter),{category:e.target.value})})))}})},eM=function(){var e=(0,i.kj)(),t=(0,c.useField)(),n=(0,a.useRecord)(),r=(null==n?void 0:n.missingKnowledgeBaseKeys)||[];return t.value?r.length?o().createElement(l.Space,{size:4},o().createElement("span",null,t.value),o().createElement(l.Tooltip,{title:e("Missing knowledge base configuration for keys: {{keys}}. Create knowledge bases with the same keys to enable this employee normally.",{keys:r.join(", ")})},o().createElement(ey.ExclamationCircleOutlined,{style:{color:"#faad14",cursor:"help"}}))):o().createElement("span",null,t.value):null},eB=function(){var e=(0,i.kj)();return o().createElement(a.ExtendCollectionsProvider,{collections:[W]},o().createElement(a.SchemaComponent,{components:{AIEmployeeForm:eP,Avatar:eT,Templates:ep,Enabled:ez,EnableSwitch:eg,CategoryFilter:eF,Username:eM},scope:{t:e,useCreateFormProps:et,useEditFormProps:en,useCancelActionProps:er,useCreateActionProps:eo,useEditActionProps:el,useDeleteActionProps:ea},schema:{type:"void",name:"ai-employees",properties:{block:{type:"void","x-component":"CardItem","x-component-props":{heightMode:"fullHeight"},"x-decorator":"TableBlockProvider","x-decorator-props":{collection:"aiEmployees",action:"list",params:{filter:{category:"business"}},rowKey:"username",dragSort:!0,dragSortBy:"sort"},properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:20}},properties:{categoryFilter:{type:"void","x-align":"left","x-component":"CategoryFilter"},refresh:{title:"{{t('Refresh')}}","x-component":"Action","x-use-component-props":"useRefreshActionProps","x-component-props":{icon:"ReloadOutlined"}},add:{type:"void",title:"{{t('New AI employee')}}","x-align":"right","x-component":"Action","x-component-props":{type:"primary",icon:"PlusOutlined"},properties:{drawer:{type:"void","x-component":"Action.Drawer",title:'{{t("New AI employee")}}',"x-decorator":"FormV2","x-use-decorator-props":"useCreateFormProps",properties:{form:{type:"void","x-component":"AIEmployeeForm"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{close:{title:"Cancel","x-component":"Action","x-component-props":{type:"default"},"x-use-component-props":"useCancelActionProps"},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary"},"x-use-component-props":"useCreateActionProps"}}}}}}}}},table:{type:"array","x-component":"TableV2","x-use-component-props":"useTableBlockProps","x-component-props":{rowKey:"username",rowSelection:{type:"checkbox"}},properties:{column0:{type:"void",title:e("Avatar"),"x-component":"TableV2.Column",properties:{avatar:{type:"string","x-component":"Avatar","x-component-props":{shape:"circle"}}}},column1:{type:"void",title:e("Username"),"x-component":"TableV2.Column",properties:{username:{type:"string","x-component":"Username","x-pattern":"readPretty"}}},column2:{type:"void",title:e("Nickname"),"x-component":"TableV2.Column",properties:{nickname:{type:"string","x-component":"Input","x-pattern":"readPretty"}}},column3:{type:"void",title:e("Position"),"x-component":"TableV2.Column",properties:{position:{type:"string","x-component":"Input","x-pattern":"readPretty"}}},column4:{type:"void",title:e("Enabled"),"x-component":"TableV2.Column",properties:{enabled:{type:"boolean","x-component":"EnableSwitch"}}},column6:{type:"void",title:'{{t("Actions")}}',"x-decorator":"TableV2.Column.ActionBar","x-component":"TableV2.Column",properties:{actions:{type:"void","x-component":"Space","x-component-props":{split:"|"},properties:{edit:{type:"void",title:'{{t("Edit") }}',"x-action":"update","x-component":"Action.Link","x-component-props":{openMode:"drawer"},properties:{drawer:{type:"void",title:e("Edit AI employee"),"x-component":"Action.Drawer","x-decorator":"FormV2","x-use-decorator-props":"useEditFormProps",properties:{form:{type:"void","x-component":"AIEmployeeForm","x-component-props":{edit:!0}},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{close:{title:e("Cancel"),"x-component":"Action","x-use-component-props":"useCancelActionProps"},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-use-component-props":"useEditActionProps"}}}}}}},destroy:{type:"void",title:'{{ t("Delete") }}',"x-action":"destroy","x-component":"Action.Link","x-use-component-props":"useDeleteActionProps","x-component-props":{confirm:{title:"{{t('Delete AI employee')}}",content:"{{t('Are you sure you want to delete this AI employee?')}}"}}}}}}}}}}}}}}))}}}]);