nolo-cli 0.1.7 → 0.1.9

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 (247) hide show
  1. package/README.md +107 -5
  2. package/agentRuntimeCommands.ts +464 -0
  3. package/ai/agent/_executeModel.ts +118 -0
  4. package/ai/agent/agentSlice.ts +525 -0
  5. package/ai/agent/appWorkingMemory.ts +126 -0
  6. package/ai/agent/avatarUtils.ts +24 -0
  7. package/ai/agent/buildEditingContext.ts +373 -0
  8. package/ai/agent/buildSystemPrompt.ts +532 -0
  9. package/ai/agent/cleanAgentMessages.ts +140 -0
  10. package/ai/agent/cliChatClient.ts +119 -0
  11. package/ai/agent/cliExecutor.ts +733 -0
  12. package/ai/agent/cliPrompt.ts +10 -0
  13. package/ai/agent/contextCompiler.ts +107 -0
  14. package/ai/agent/contextLayerContract.ts +44 -0
  15. package/ai/agent/createAgentSchema.ts +234 -0
  16. package/ai/agent/executeToolCall.ts +58 -0
  17. package/ai/agent/fetchAgentContexts.ts +42 -0
  18. package/ai/agent/generatePrompt.ts +3 -0
  19. package/ai/agent/getFullChatContextKeys.ts +168 -0
  20. package/ai/agent/hooks/fetchPublicAgents.ts +133 -0
  21. package/ai/agent/hooks/useAgentConfig.ts +61 -0
  22. package/ai/agent/hooks/useAgentDialog.ts +35 -0
  23. package/ai/agent/hooks/useAgentFormValidation.ts +202 -0
  24. package/ai/agent/hooks/usePublicAgents.ts +473 -0
  25. package/ai/agent/machineRunPermissions.ts +95 -0
  26. package/ai/agent/persistMessageWithFixedId.ts +37 -0
  27. package/ai/agent/planSlice.ts +259 -0
  28. package/ai/agent/referenceUtils.ts +229 -0
  29. package/ai/agent/runAgentBackground.ts +238 -0
  30. package/ai/agent/runAgentClientLoop.ts +138 -0
  31. package/ai/agent/runtimeGuidance.ts +97 -0
  32. package/ai/agent/runtimeServerBase.ts +37 -0
  33. package/ai/agent/server/fetchPublicAgents.ts +128 -0
  34. package/ai/agent/startParallelAgentStreams.ts +424 -0
  35. package/ai/agent/startupProtocol.ts +53 -0
  36. package/ai/agent/streamAgentChatTurn.ts +1278 -0
  37. package/ai/agent/streamAgentChatTurnUtils.ts +738 -0
  38. package/ai/agent/types.ts +71 -0
  39. package/ai/agent/utils/imageOutput.ts +33 -0
  40. package/ai/agent/utils/sortUtils.ts +250 -0
  41. package/ai/agent/web/referencePickerUtils.ts +146 -0
  42. package/ai/ai.locale.ts +1075 -0
  43. package/ai/chat/accumulateToolCallChunks.ts +95 -0
  44. package/ai/chat/fetchUtils.native.ts +276 -0
  45. package/ai/chat/fetchUtils.ts +153 -0
  46. package/ai/chat/parseApiError.ts +64 -0
  47. package/ai/chat/parseMultilineSSE.ts +95 -0
  48. package/ai/chat/sendOpenAICompletionsRequest.native.ts +682 -0
  49. package/ai/chat/sendOpenAICompletionsRequest.ts +703 -0
  50. package/ai/chat/sendOpenAIResponseRequest.ts +491 -0
  51. package/ai/chat/shouldUseServerProxy.ts +18 -0
  52. package/ai/chat/sseClient.native.ts +91 -0
  53. package/ai/chat/sseClient.ts +67 -0
  54. package/ai/chat/streamReader.native.ts +31 -0
  55. package/ai/chat/streamReader.ts +62 -0
  56. package/ai/chat/updateTotalUsage.ts +72 -0
  57. package/ai/context/buildReferenceContext.ts +437 -0
  58. package/ai/context/calculateContextUsage.ts +133 -0
  59. package/ai/context/retention.ts +165 -0
  60. package/ai/context/tokenUtils.ts +78 -0
  61. package/ai/index.ts +1 -0
  62. package/ai/llm/calculateGeminiImageTokens.ts +57 -0
  63. package/ai/llm/deepinfra.ts +28 -0
  64. package/ai/llm/fireworks.ts +50 -0
  65. package/ai/llm/generateRequestBody.ts +165 -0
  66. package/ai/llm/getModelContextWindow.ts +84 -0
  67. package/ai/llm/getNoloKey.ts +31 -0
  68. package/ai/llm/getPricing.ts +199 -0
  69. package/ai/llm/hooks/useModelPricing.ts +75 -0
  70. package/ai/llm/imagePricing.ts +40 -0
  71. package/ai/llm/isResponseAPIModel.ts +13 -0
  72. package/ai/llm/mimo.ts +71 -0
  73. package/ai/llm/mistral.ts +22 -0
  74. package/ai/llm/modelAvatar.ts +427 -0
  75. package/ai/llm/models.ts +45 -0
  76. package/ai/llm/openrouterModels.ts +269 -0
  77. package/ai/llm/providers.ts +306 -0
  78. package/ai/llm/reasoningModels.ts +28 -0
  79. package/ai/llm/types.ts +59 -0
  80. package/ai/llm/usageRequestOptions.ts +59 -0
  81. package/ai/memory/capture.ts +148 -0
  82. package/ai/memory/consolidate.ts +104 -0
  83. package/ai/memory/delete.ts +147 -0
  84. package/ai/memory/overlay.ts +84 -0
  85. package/ai/memory/query.ts +38 -0
  86. package/ai/memory/queryShared.ts +160 -0
  87. package/ai/memory/rank.ts +105 -0
  88. package/ai/memory/recentRelationshipRecap.ts +249 -0
  89. package/ai/memory/remember.ts +167 -0
  90. package/ai/memory/runtime.ts +76 -0
  91. package/ai/memory/store.ts +20 -0
  92. package/ai/memory/storeShared.ts +76 -0
  93. package/ai/memory/types.ts +46 -0
  94. package/ai/memory/understanding.ts +349 -0
  95. package/ai/memory/understandingGreeting.ts +264 -0
  96. package/ai/messages/type.ts +20 -0
  97. package/ai/policy/personalizationDialog.ts +333 -0
  98. package/ai/policy/runtimePolicy.ts +440 -0
  99. package/ai/policy/selfUpdateFields.ts +48 -0
  100. package/ai/policy/types.ts +64 -0
  101. package/ai/skills/referenceRuntime.ts +274 -0
  102. package/ai/skills/skillDiagnostics.ts +251 -0
  103. package/ai/skills/skillDocBuilder.ts +139 -0
  104. package/ai/skills/skillDocProtocol.ts +434 -0
  105. package/ai/skills/skillReferenceSummary.ts +63 -0
  106. package/ai/skills/skillSummaryMarker.ts +26 -0
  107. package/ai/token/calculatePrice.ts +544 -0
  108. package/ai/token/db.ts +98 -0
  109. package/ai/token/externalToolCost.ts +330 -0
  110. package/ai/token/hooks/useRecords.ts +65 -0
  111. package/ai/token/missingUsageEstimate.ts +42 -0
  112. package/ai/token/modelUsageQuery.ts +252 -0
  113. package/ai/token/normalizeUsage.ts +84 -0
  114. package/ai/token/openaiImageGenerationUsage.ts +56 -0
  115. package/ai/token/prepareTokenUsageData.ts +88 -0
  116. package/ai/token/query.ts +88 -0
  117. package/ai/token/queryUserTokens.ts +59 -0
  118. package/ai/token/resolveBillingTarget.ts +52 -0
  119. package/ai/token/saveTokenRecord.ts +53 -0
  120. package/ai/token/serverDialogProjection.ts +78 -0
  121. package/ai/token/serverTokenWriter.ts +143 -0
  122. package/ai/token/stats.ts +21 -0
  123. package/ai/token/tokenThunks.ts +24 -0
  124. package/ai/token/types.ts +93 -0
  125. package/ai/tools/agent/agentTools.ts +176 -0
  126. package/ai/tools/agent/agentUpdateShared.ts +311 -0
  127. package/ai/tools/agent/callAgentTool.ts +139 -0
  128. package/ai/tools/agent/createAgentTool.ts +512 -0
  129. package/ai/tools/agent/createDialogTool.ts +69 -0
  130. package/ai/tools/agent/createSkillAgentTool.ts +62 -0
  131. package/ai/tools/agent/parallelBudget.ts +221 -0
  132. package/ai/tools/agent/presets/appBuilderPreset.ts +145 -0
  133. package/ai/tools/agent/runLlmTool.ts +96 -0
  134. package/ai/tools/agent/runStreamingAgentTool.ts +73 -0
  135. package/ai/tools/agent/skillAgentArgs.ts +106 -0
  136. package/ai/tools/agent/skillAgentPreset.ts +89 -0
  137. package/ai/tools/agent/streamParallelAgentsTool.ts +122 -0
  138. package/ai/tools/agent/updateAgentTool.ts +96 -0
  139. package/ai/tools/agent/updateSelfTool.ts +113 -0
  140. package/ai/tools/amazonProductScraperTool.ts +86 -0
  141. package/ai/tools/apifyActorClient.ts +45 -0
  142. package/ai/tools/appEditGuard.ts +372 -0
  143. package/ai/tools/appReadSnapshot.ts +153 -0
  144. package/ai/tools/appTools.ts +1549 -0
  145. package/ai/tools/applyEditTool.ts +256 -0
  146. package/ai/tools/applyLineEditsTool.ts +312 -0
  147. package/ai/tools/browserTools/click.ts +33 -0
  148. package/ai/tools/browserTools/closeSession.ts +29 -0
  149. package/ai/tools/browserTools/common.ts +27 -0
  150. package/ai/tools/browserTools/openSession.ts +48 -0
  151. package/ai/tools/browserTools/readContent.ts +38 -0
  152. package/ai/tools/browserTools/selectOption.ts +46 -0
  153. package/ai/tools/browserTools/typeText.ts +42 -0
  154. package/ai/tools/category/createCategoryTool.ts +66 -0
  155. package/ai/tools/category/queryContentsByCategoryTool.ts +69 -0
  156. package/ai/tools/category/updateContentCategoryTool.ts +75 -0
  157. package/ai/tools/cfBrowserTools.ts +319 -0
  158. package/ai/tools/cfSpeechToTextTool.ts +49 -0
  159. package/ai/tools/checkEnvTool.ts +65 -0
  160. package/ai/tools/cloudflareCrawlTool.ts +289 -0
  161. package/ai/tools/codeSearchTool.ts +111 -0
  162. package/ai/tools/codeTools.ts +101 -0
  163. package/ai/tools/createDocTool.ts +132 -0
  164. package/ai/tools/createPlanTool.ts +999 -0
  165. package/ai/tools/createSkillDocTool.ts +155 -0
  166. package/ai/tools/createWorkflowTool.ts +154 -0
  167. package/ai/tools/deepseekOcrTool.ts +34 -0
  168. package/ai/tools/delayTool.ts +31 -0
  169. package/ai/tools/deleteSpacesTool.ts +325 -0
  170. package/ai/tools/deleteSpacesToolModel.ts +159 -0
  171. package/ai/tools/devReloadUtils.ts +29 -0
  172. package/ai/tools/dialogMessageSearch.ts +137 -0
  173. package/ai/tools/doctorSkillTool.ts +72 -0
  174. package/ai/tools/ecommerceScraperTool.ts +86 -0
  175. package/ai/tools/emailTools.ts +549 -0
  176. package/ai/tools/evalSkillTool.ts +92 -0
  177. package/ai/tools/exaSearchTool.ts +64 -0
  178. package/ai/tools/execBashTool.ts +379 -0
  179. package/ai/tools/executeSqlTool.ts +192 -0
  180. package/ai/tools/fetchWebpageSupport.ts +309 -0
  181. package/ai/tools/fetchWebpageTool.ts +84 -0
  182. package/ai/tools/geminiImagePreviewTool.ts +361 -0
  183. package/ai/tools/generateDocxTool.ts +215 -0
  184. package/ai/tools/googleSearchScraperTool.ts +106 -0
  185. package/ai/tools/importDataTool.ts +133 -0
  186. package/ai/tools/importSkillTool.ts +162 -0
  187. package/ai/tools/index.ts +1858 -0
  188. package/ai/tools/listFilesTool.ts +82 -0
  189. package/ai/tools/listUserSpacesTool.ts +113 -0
  190. package/ai/tools/modelUsageTools.ts +142 -0
  191. package/ai/tools/olmOcrTool.ts +34 -0
  192. package/ai/tools/openaiImageTool.ts +218 -0
  193. package/ai/tools/paddleOcrTool.ts +34 -0
  194. package/ai/tools/prepareTools.ts +23 -0
  195. package/ai/tools/readDocTool.ts +84 -0
  196. package/ai/tools/readFileTool.ts +211 -0
  197. package/ai/tools/readTool.ts +163 -0
  198. package/ai/tools/readXPostTool.ts +233 -0
  199. package/ai/tools/rememberMemoryTool.ts +84 -0
  200. package/ai/tools/remotionVideoTool.ts +151 -0
  201. package/ai/tools/searchDialogMessagesTool.ts +222 -0
  202. package/ai/tools/searchRepoTool.ts +115 -0
  203. package/ai/tools/searchWorkspaceTool.ts +259 -0
  204. package/ai/tools/skillFollowup.ts +86 -0
  205. package/ai/tools/surfWeatherTool.ts +169 -0
  206. package/ai/tools/table/addTableRowTool.ts +217 -0
  207. package/ai/tools/table/createTableTool.ts +315 -0
  208. package/ai/tools/table/rowTools.ts +366 -0
  209. package/ai/tools/table/schemaTools.ts +244 -0
  210. package/ai/tools/table/shareTableTool.ts +148 -0
  211. package/ai/tools/table/toolShared.ts +129 -0
  212. package/ai/tools/toolApiClient.ts +198 -0
  213. package/ai/tools/toolNameAliases.ts +57 -0
  214. package/ai/tools/toolResultError.ts +42 -0
  215. package/ai/tools/toolRunSlice.ts +303 -0
  216. package/ai/tools/toolSchemaCompatibility.ts +53 -0
  217. package/ai/tools/toolVisibility.ts +4 -0
  218. package/ai/tools/types.ts +20 -0
  219. package/ai/tools/uiAskChoiceTool.ts +104 -0
  220. package/ai/tools/updateContentTitleTool.ts +84 -0
  221. package/ai/tools/updateDocTool.ts +105 -0
  222. package/ai/tools/updateUserPreferenceProfileTool.ts +145 -0
  223. package/ai/tools/whisperTool.ts +77 -0
  224. package/ai/tools/writeFileTool.ts +210 -0
  225. package/ai/tools/youtubeScraperTool.ts +116 -0
  226. package/ai/tools/ziweiChartTool.ts +678 -0
  227. package/ai/types.ts +55 -0
  228. package/ai/workflow/workflowExecutor.ts +323 -0
  229. package/ai/workflow/workflowSlice.ts +73 -0
  230. package/ai/workflow/workflowTypes.ts +106 -0
  231. package/client/agentRun.ts +198 -167
  232. package/client/compactDialog.ts +222 -0
  233. package/commandRegistry.ts +14 -0
  234. package/connector-experimental/capabilities.ts +73 -0
  235. package/connector-experimental/codexBinary.ts +41 -0
  236. package/connector-experimental/heartbeatLoop.ts +22 -0
  237. package/connector-experimental/index.ts +5 -0
  238. package/connector-experimental/machineInfo.ts +46 -0
  239. package/connector-experimental/protocol.ts +54 -0
  240. package/connectorWebSocketTarget.ts +29 -0
  241. package/defaultServer.ts +1 -0
  242. package/index.ts +158 -104
  243. package/machineCommands.ts +382 -0
  244. package/package.json +12 -2
  245. package/tui/readlineWorkspace.ts +50 -0
  246. package/tui/session.ts +40 -2
  247. package/updateCommands.ts +70 -5
@@ -0,0 +1,1858 @@
1
+ // 文件路径: ai/tools/index.ts
2
+
3
+ /* ==================================================================
4
+ * 所有 Tool 的统一注册与描述 (最终版:单一事实来源)
5
+ * ==================================================================
6
+ *
7
+ * 如何使用:
8
+ * 1. 为你的工具创建一个新文件 (例如 `myNewTool.ts`)。
9
+ * 2. 在该文件中,导出函数的 schema 和 executor 函数。
10
+ * 3. 在下面的 `toolDefinitions` 数组中,添加一个新的对象来定义你的工具
11
+ * (或在对应分组文件中添加,然后在此汇总)。
12
+ *
13
+ * 此文件会自动生成 toolRegistry, toolExecutors, toolDescriptions,
14
+ * 以及 toolDefinitionsByName。
15
+ *
16
+ * ================================================================== */
17
+
18
+ // ---------- 1. 导入所有工具的 Schema 和 Executor ----------
19
+ // 计划与编排
20
+ import {
21
+ createWorkflowFunctionSchema,
22
+ createWorkflowFunc,
23
+ } from "./createWorkflowTool";
24
+ import { delayFunctionSchema, delayFunc } from "./delayTool";
25
+ import {
26
+ createScheduledTaskFunc,
27
+ createScheduledTaskFunctionSchema,
28
+ notifyUserFunc,
29
+ notifyUserFunctionSchema,
30
+ queryModelUsageFunc,
31
+ queryModelUsageFunctionSchema,
32
+ } from "./modelUsageTools";
33
+
34
+ // Agent 相关工具的 schema(用于 patch enum),具体定义移到 agentTools.ts
35
+ import { createAgentToolFunctionSchema } from "./agent/createAgentTool";
36
+ import { updateAgentToolFunctionSchema } from "./agent/updateAgentTool";
37
+
38
+ // 内容管理
39
+ import { createDocFunctionSchema, createDocFunc } from "./createDocTool";
40
+ import {
41
+ createSkillDocFunctionSchema,
42
+ createSkillDocFunc,
43
+ } from "./createSkillDocTool";
44
+ import { doctorSkillFunctionSchema, doctorSkillFunc } from "./doctorSkillTool";
45
+ import { evalSkillFunctionSchema, evalSkillFunc } from "./evalSkillTool";
46
+ import { importSkillFunctionSchema, importSkillFunc } from "./importSkillTool";
47
+ import {
48
+ readDocFunctionSchema,
49
+ readDocFunc,
50
+ readPageFunctionSchema,
51
+ readPageFunc,
52
+ } from "./readDocTool";
53
+
54
+ // 分类相关工具集中在 ./category 文件夹
55
+ import {
56
+ createCategoryFunctionSchema,
57
+ createCategoryFunc,
58
+ } from "./category/createCategoryTool";
59
+ import {
60
+ updateContentCategoryFunctionSchema,
61
+ updateContentCategoryFunc,
62
+ } from "./category/updateContentCategoryTool";
63
+ import {
64
+ queryContentsByCategoryFunctionSchema,
65
+ queryContentsByCategoryFunc,
66
+ } from "./category/queryContentsByCategoryTool";
67
+
68
+ // 数据操作
69
+ import { importDataFunctionSchema, importDataFunc } from "./importDataTool";
70
+ import { executeSqlFunctionSchema, executeSqlFunc } from "./executeSqlTool";
71
+ import { readFunctionSchema, readFunc } from "./readTool";
72
+ import {
73
+ listUserSpacesFunctionSchema,
74
+ listUserSpacesFunc,
75
+ } from "./listUserSpacesTool";
76
+ import {
77
+ deleteSpacesFunctionSchema,
78
+ deleteSpacesFunc,
79
+ deleteSpacesPreviewFunc,
80
+ } from "./deleteSpacesTool";
81
+ import {
82
+ emailArchiveFunc,
83
+ emailArchiveFunctionSchema,
84
+ emailExtractVerificationFunc,
85
+ emailExtractVerificationFunctionSchema,
86
+ emailProvisionIdentityFunc,
87
+ emailProvisionIdentityFunctionSchema,
88
+ emailReadFunc,
89
+ emailReadFunctionSchema,
90
+ emailSearchFunc,
91
+ emailSearchFunctionSchema,
92
+ emailSendFunc,
93
+ emailSendFunctionSchema,
94
+ emailUpdateTagsFunc,
95
+ emailUpdateTagsFunctionSchema,
96
+ emailWaitForFunc,
97
+ emailWaitForFunctionSchema,
98
+ } from "./emailTools";
99
+ // ✅ 在当前表中新增一行的工具
100
+ import {
101
+ addTableRowFunctionSchema,
102
+ addTableRowFunc,
103
+ } from "./table/addTableRowTool";
104
+ import {
105
+ createTableFunctionSchema,
106
+ createTableFunc,
107
+ } from "./table/createTableTool";
108
+ import {
109
+ shareTableFunctionSchema,
110
+ shareTableFunc,
111
+ } from "./table/shareTableTool";
112
+ import {
113
+ addTableRowsFunctionSchema,
114
+ addTableRowsFunc,
115
+ deleteTableRowFunctionSchema,
116
+ deleteTableRowFunc,
117
+ deleteTableRowsFunctionSchema,
118
+ deleteTableRowsFunc,
119
+ queryTableRowsFunctionSchema,
120
+ queryTableRowsFunc,
121
+ updateTableRowFunctionSchema,
122
+ updateTableRowFunc,
123
+ updateTableRowsFunctionSchema,
124
+ updateTableRowsFunc,
125
+ } from "./table/rowTools";
126
+ import {
127
+ addTableColumnFunctionSchema,
128
+ addTableColumnFunc,
129
+ deleteTableColumnFunctionSchema,
130
+ deleteTableColumnFunc,
131
+ renameTableColumnFunctionSchema,
132
+ renameTableColumnFunc,
133
+ renameTableColumnLabelFunctionSchema,
134
+ renameTableColumnLabelFunc,
135
+ renameTableFunctionSchema,
136
+ renameTableFunc,
137
+ } from "./table/schemaTools";
138
+
139
+ // 网络与智能
140
+ import {
141
+ fetchWebpageFunctionSchema,
142
+ fetchWebpageFunc,
143
+ } from "./fetchWebpageTool";
144
+ import {
145
+ readXPostFunctionSchema,
146
+ readXPostFunc,
147
+ } from "./readXPostTool";
148
+ import {
149
+ surfWeatherFunctionSchema,
150
+ surfWeatherFunc,
151
+ } from "./surfWeatherTool";
152
+
153
+ import {
154
+ browser_closeSession_Schema,
155
+ browser_closeSession_Func,
156
+ } from "./browserTools/closeSession";
157
+ import {
158
+ browser_openSession_Schema,
159
+ browser_openSession_Func,
160
+ } from "./browserTools/openSession";
161
+ import {
162
+ browser_selectOption_Schema,
163
+ browser_selectOption_Func,
164
+ } from "./browserTools/selectOption";
165
+ import {
166
+ browser_click_Schema,
167
+ browser_click_Func,
168
+ } from "./browserTools/click";
169
+ import {
170
+ browser_typeText_Schema,
171
+ browser_typeText_Func,
172
+ } from "./browserTools/typeText";
173
+ import {
174
+ browser_readContent_Schema,
175
+ browser_readContent_Func,
176
+ } from "./browserTools/readContent";
177
+ import {
178
+ exaSearchSchema,
179
+ exaSearchFunc,
180
+ } from "./exaSearchTool";
181
+ import {
182
+ paddleOcrSchema,
183
+ paddleOcrFunc,
184
+ } from "./paddleOcrTool";
185
+ import {
186
+ olmOcrSchema,
187
+ olmOcrFunc,
188
+ } from "./olmOcrTool";
189
+ import {
190
+ whisperTurboSchema,
191
+ whisperTurboFunc,
192
+ whisperV3Schema,
193
+ whisperV3Func,
194
+ } from "./whisperTool";
195
+
196
+
197
+
198
+
199
+ // ✅ generateDocx 工具(前端生成并下载 DOCX)
200
+ import {
201
+ generateDocxFunctionSchema,
202
+ generateDocxFunc,
203
+ } from "./generateDocxTool";
204
+
205
+ // ✅ Google Search Scraper (Apify)
206
+ import {
207
+ googleSearchScraperFunctionSchema,
208
+ googleSearchScraperFunc,
209
+ } from "./googleSearchScraperTool";
210
+
211
+ // ✅ Cloudflare Browser Rendering 爬取工具
212
+ import {
213
+ cloudflareCrawlFunctionSchema,
214
+ cloudflareCrawlFunc,
215
+ cloudflareCrawlStatusFunctionSchema,
216
+ cloudflareCrawlStatusFunc,
217
+ } from "./cloudflareCrawlTool";
218
+
219
+ // ✅ Apify / 抓取相关工具
220
+ import {
221
+ youtubeScraperFunctionSchema,
222
+ youtubeScraperFunc,
223
+ } from "./youtubeScraperTool";
224
+ import {
225
+ ecommerceScraperFunctionSchema,
226
+ ecommerceScraperFunc,
227
+ } from "./ecommerceScraperTool";
228
+ import {
229
+ amazonProductScraperFunctionSchema,
230
+ amazonProductScraperFunc,
231
+ } from "./amazonProductScraperTool";
232
+
233
+ // ✅ 多模态:Gemini 图片(2.5 Flash 文生图 / 3 Pro 编辑)
234
+ import {
235
+ geminiFlashImageFunctionSchema,
236
+ geminiFlashImageFunc,
237
+ geminiProImagePreviewFunctionSchema,
238
+ geminiProImagePreviewFunc,
239
+ } from "./geminiImagePreviewTool";
240
+ import {
241
+ openAIGptImageFunctionSchema,
242
+ openAIGptImageFunc,
243
+ } from "./openaiImageTool";
244
+ import {
245
+ remotionRenderVideoFunctionSchema,
246
+ remotionRenderVideoFunc,
247
+ } from "./remotionVideoTool";
248
+ import { uiAskChoiceFunc, uiAskChoiceFunctionSchema } from "./uiAskChoiceTool";
249
+ import {
250
+ rememberMemoryFunc,
251
+ rememberMemoryFunctionSchema,
252
+ } from "./rememberMemoryTool";
253
+ import { execBashFunctionSchema, execBashFunc, execShellFunctionSchema, execShellFunc } from "./execBashTool";
254
+ import { checkEnvFunctionSchema, checkEnvFunc } from "./checkEnvTool";
255
+
256
+ import { agentToolDefinitions } from "./agent/agentTools";
257
+ import { codeToolDefinitions } from "./codeTools";
258
+ import {
259
+ cfScreenshotFunctionSchema,
260
+ cfScreenshotFunc,
261
+ cfGetMarkdownFunctionSchema,
262
+ cfGetMarkdownFunc,
263
+ cfGeneratePDFFunctionSchema,
264
+ cfGeneratePDFFunc,
265
+ cfExtractJSONFunctionSchema,
266
+ cfExtractJSONFunc,
267
+ } from "./cfBrowserTools";
268
+ import {
269
+ appPreflightFunctionSchema,
270
+ appPreflightFunc,
271
+ appDeployFunctionSchema,
272
+ appDeployFunc,
273
+ appListFunctionSchema,
274
+ appListFunc,
275
+ appDeleteFunctionSchema,
276
+ appDeleteFunc,
277
+ appReadFunctionSchema,
278
+ appReadFunc,
279
+ } from "./appTools";
280
+ import {
281
+ cfSpeechToTextFunctionSchema,
282
+ cfSpeechToTextFunc,
283
+ } from "./cfSpeechToTextTool";
284
+ import {
285
+ updateContentTitleTool,
286
+ updateContentTitleFunc,
287
+ } from "./updateContentTitleTool";
288
+ import {
289
+ searchAllSpacesFunc,
290
+ searchAllSpacesFunctionSchema,
291
+ searchWorkspaceFunctionSchema,
292
+ searchWorkspaceFunc,
293
+ } from "./searchWorkspaceTool";
294
+ import {
295
+ searchDialogMessagesFunc,
296
+ searchDialogMessagesFunctionSchema,
297
+ } from "./searchDialogMessagesTool";
298
+ import {
299
+ updateDocFunctionSchema,
300
+ updateDocFunc,
301
+ } from "./updateDocTool";
302
+ import {
303
+ updateUserPreferenceProfileFunctionSchema,
304
+ updateUserPreferenceProfileFunc,
305
+ } from "./updateUserPreferenceProfileTool";
306
+ import {
307
+ ziweiChartFunctionSchema,
308
+ ziweiChartFunc,
309
+ } from "./ziweiChartTool";
310
+
311
+
312
+ // ---------- 2. 定义工具规范接口 ----------
313
+
314
+ export type ToolBehavior = "orchestrator" | "data" | "action" | "answer";
315
+ export type ToolCapability =
316
+ | "knowledge_capture"
317
+ | "space_context"
318
+ | "self_evolution"
319
+ | "web_access"
320
+ | "browser_automation"
321
+ | "code_edit"
322
+ | "app_deploy"
323
+ | "general";
324
+ export type ToolRiskLevel = "low" | "medium" | "high";
325
+ export type ToolCostLevel = "low" | "medium" | "high";
326
+ export type ToolConsentMode = "auto" | "ask" | "blocked";
327
+
328
+ // 交互模式:
329
+ // - auto: 直接执行
330
+ // - confirm: 需要用户确认后才执行(危险操作)
331
+ // - authorize: 需要用户授权后才执行(权限/敏感资源)
332
+ export type ToolInteraction = "auto" | "confirm" | "authorize";
333
+
334
+ /**
335
+ * 前端分组用:
336
+ * - general: 普通
337
+ * - agent : Agent / 应用相关
338
+ * - content: 内容与页面
339
+ * - media : 多媒体(生成图片 / 生成视频等)
340
+ * - data : 数据操作
341
+ */
342
+ export type ToolUiGroup = "general" | "agent" | "content" | "media" | "data";
343
+
344
+ /**
345
+ * 分组元信息:
346
+ * - id: 分组 ID(与 ToolUiGroup 一致)
347
+ * - label: 默认中文标题(前端可直接用,也可以自己做 i18n 映射)
348
+ * - order: 分组显示顺序(从小到大)
349
+ * - fallbackCategories:
350
+ * 当某个工具没有显式指定 uiGroup 时,可以根据工具的 category 使用兜底分组。
351
+ */
352
+ export interface ToolGroupMeta {
353
+ id: ToolUiGroup;
354
+ label: string;
355
+ order: number;
356
+ fallbackCategories?: string[];
357
+ }
358
+
359
+ /**
360
+ * 单一事实来源:所有分组配置
361
+ * 以后增加 / 修改分组,只需要改这里一处。
362
+ */
363
+ export const TOOL_GROUP_META: ToolGroupMeta[] = [
364
+ {
365
+ id: "general",
366
+ label: "普通",
367
+ order: 0,
368
+ },
369
+ {
370
+ id: "agent",
371
+ label: "Agent / 应用",
372
+ order: 1,
373
+ },
374
+ {
375
+ id: "content",
376
+ label: "内容与页面",
377
+ order: 2,
378
+ fallbackCategories: ["内容管理"],
379
+ },
380
+ {
381
+ id: "media",
382
+ label: "多媒体生成",
383
+ order: 3,
384
+ fallbackCategories: ["多媒体生成"],
385
+ },
386
+ {
387
+ id: "data",
388
+ label: "数据操作",
389
+ order: 4,
390
+ fallbackCategories: ["数据操作"],
391
+ },
392
+ ];
393
+
394
+ export interface ToolDefinition {
395
+ id: string; // 唯一ID (camelCase)
396
+ schema: any; // 提供给 LLM 的函数 Schema
397
+
398
+ executor: (
399
+ args: any,
400
+ thunkApi: any,
401
+ context?: { parentMessageId: string; signal?: AbortSignal; toolRunId?: string }
402
+ ) => Promise<any>;
403
+
404
+ /**
405
+ * ✅ 新增:预览执行(无副作用)
406
+ * - 仅当 interaction 为 confirm/authorize 时会被调用
407
+ * - 用于生成 “待确认/待授权” 阶段的 tool message content(预览输出)
408
+ */
409
+ previewExecutor?: (
410
+ args: any,
411
+ thunkApi: any,
412
+ context?: { parentMessageId: string; signal?: AbortSignal; toolRunId?: string }
413
+ ) => Promise<any>;
414
+
415
+ description: {
416
+ name: string;
417
+ description: string;
418
+ category: string;
419
+ };
420
+
421
+ behavior?: ToolBehavior; // 工具在系统中的角色
422
+ capability?: ToolCapability; // 用户策略与预算主要按 capability 生效
423
+ interaction?: ToolInteraction; // 不写默认 "auto"
424
+ uiGroup?: ToolUiGroup; // 前端展示分组,不写默认 "general"
425
+ riskLevel?: ToolRiskLevel;
426
+ costLevel?: ToolCostLevel;
427
+ defaultConsent?: ToolConsentMode;
428
+
429
+ /**
430
+ * ✅ 新增:是否支持取消(未来 executeToolRun 传 signal 后即可实现)
431
+ * - 现在先作为 UI/能力标记预留,不影响 DB 结构
432
+ */
433
+ cancelable?: boolean;
434
+
435
+ /**
436
+ * ✅ 新增:授权相关元信息预留(未来可扩展,不强制使用)
437
+ * - 现在不实现授权策略,仅留接口,避免未来改 DB/大改代码
438
+ */
439
+ auth?: {
440
+ kind: "domain" | "resource" | "scopes";
441
+ scopeHint?: string; // 给 UI/日志的提示
442
+ };
443
+ }
444
+
445
+ /**
446
+ * 能力分级定义 (Capability Tiers)
447
+ */
448
+ export const TOOL_PACKS = {
449
+ // L1 - 核心:交互 + 记忆读写 + 自我更新,所有 Agent 必有
450
+ CORE: ["ui_ask_choice", "rememberMemory", "read", "searchDialogMessages", "createDoc", "updateDoc", "search_workspace", "search_all_spaces", "updateSelf", "queryModelUsage", "createScheduledTask", "notifyUser"],
451
+ // L2 - 联网搜索:配置了 tools 的 Agent 默认加,纯 QA bot 不加
452
+ LIGHT_WEB: ["exa_search", "read_x_post"],
453
+ // L3 - 深度浏览器:全套复杂网页交互
454
+ FULL_BROWSER: [
455
+ "browser_openSession",
456
+ "browser_closeSession",
457
+ "browser_click",
458
+ "browser_typeText",
459
+ "browser_readContent",
460
+ "browser_selectOption",
461
+ "fetchWebpage",
462
+ ],
463
+ };
464
+
465
+ /* ==================================================================
466
+ * 2.1 toolquery 工具:帮助模型发现可用工具
467
+ * ================================================================== */
468
+
469
+ export const toolQueryFunctionSchema = {
470
+ name: "toolquery",
471
+ description:
472
+ "根据当前任务描述,列出系统中可能有用的工具。适合在不确定可用工具时先调用本函数。",
473
+ parameters: {
474
+ type: "object",
475
+ properties: {
476
+ task: {
477
+ type: "string",
478
+ description: "用户当前的任务或需求描述。",
479
+ },
480
+ top_k: {
481
+ type: "number",
482
+ description: "最多返回多少个候选工具(默认 5)。",
483
+ default: 5,
484
+ },
485
+ },
486
+ required: ["task"],
487
+ },
488
+ };
489
+
490
+ export async function toolQueryFunc(args: any): Promise<{
491
+ rawData: any;
492
+ displayData: string;
493
+ }> {
494
+ const { task, top_k } = args || {};
495
+ const query = String(task || "").trim();
496
+ const topK = typeof top_k === "number" && top_k > 0 && top_k < 50 ? top_k : 5;
497
+
498
+ if (!query) {
499
+ const msg = "toolquery 需要提供 task 描述,比如:'分析数据库相关的工具'。";
500
+ return { rawData: [], displayData: msg };
501
+ }
502
+
503
+ const lowered = query.toLowerCase();
504
+
505
+ const candidates = toolDefinitions
506
+ .filter((tool) => tool.id !== "toolquery")
507
+ .map((tool) => {
508
+ const { description, behavior } = tool;
509
+ const haystack =
510
+ `${description.name} ${description.description} ${description.category} ${behavior || ""}`.toLowerCase();
511
+ const score = haystack.includes(lowered) ? 1 : 0;
512
+ return { tool, score };
513
+ })
514
+ .filter((item) => item.score > 0)
515
+ .slice(0, topK);
516
+
517
+ const rawData = candidates.map(({ tool }) => ({
518
+ name: tool.schema.name,
519
+ id: tool.id,
520
+ description: tool.description.description,
521
+ category: tool.description.category,
522
+ behavior: tool.behavior ?? null,
523
+ }));
524
+
525
+ let displayData: string;
526
+
527
+ if (rawData.length === 0) {
528
+ displayData =
529
+ `根据当前描述暂时没有找到明显匹配的工具。\n` +
530
+ `你可以尝试:\n` +
531
+ `- 换一种更具体的说法描述任务\n` +
532
+ `- 直接选择你认为合适的工具调用`;
533
+ } else {
534
+ displayData =
535
+ `根据你的任务描述,我找到了 ${rawData.length} 个可能有用的工具:\n\n` +
536
+ rawData
537
+ .map((t: any, idx: number) => {
538
+ const behaviorLabel = t.behavior ? `,类型:${t.behavior}` : "";
539
+ return `${idx + 1}. \`${t.name}\`(${t.category}${behaviorLabel})\n - ${t.description}`;
540
+ })
541
+ .join("\n");
542
+ }
543
+
544
+ return { rawData, displayData };
545
+ }
546
+
547
+ /* ==================================================================
548
+ * 3. [核心] 单一事实来源:在此处定义所有工具
549
+ * ================================================================== */
550
+
551
+ // 这里保留“非 Agent / 非代码”的工具定义,
552
+ // Agent 工具在 agentTools.ts,代码相关工具在 codeTools.ts。
553
+ const baseToolDefinitions: ToolDefinition[] = [
554
+ {
555
+ id: "uiAskChoice",
556
+ schema: uiAskChoiceFunctionSchema,
557
+ executor: uiAskChoiceFunc,
558
+ description: {
559
+ name: "ui_ask_choice",
560
+ description:
561
+ "向用户提出一个带多个选项的问题,让界面展示按钮供用户选择。",
562
+ category: "交互 / UI",
563
+ },
564
+ behavior: "answer",
565
+ },
566
+ {
567
+ id: "rememberMemory",
568
+ schema: rememberMemoryFunctionSchema,
569
+ executor: rememberMemoryFunc,
570
+ description: {
571
+ name: "rememberMemory",
572
+ description: "将值得长期保留的用户偏好或空间共识写入一条 episodic memory。",
573
+ category: "记忆 / 长期上下文",
574
+ },
575
+ behavior: "action",
576
+ },
577
+ {
578
+ id: "updateUserPreferenceProfile",
579
+ schema: updateUserPreferenceProfileFunctionSchema,
580
+ executor: updateUserPreferenceProfileFunc,
581
+ description: {
582
+ name: "updateUserPreferenceProfile",
583
+ description: "保存用户的语气、知识沉淀、空间读取等个性化偏好设置。",
584
+ category: "用户设置 / 个性化",
585
+ },
586
+ behavior: "action",
587
+ },
588
+ {
589
+ id: "ziweiChart",
590
+ schema: ziweiChartFunctionSchema,
591
+ executor: ziweiChartFunc,
592
+ description: {
593
+ name: "ziweiChart",
594
+ description: "生成紫微斗数本命盘,并输出可读的十二宫文字盘。",
595
+ category: "命理 / 排盘",
596
+ },
597
+ behavior: "answer",
598
+ capability: "general",
599
+ uiGroup: "general",
600
+ riskLevel: "low",
601
+ costLevel: "low",
602
+ defaultConsent: "auto",
603
+ },
604
+
605
+ // --- 计划与编排(不含 Agent 专用) ---
606
+ {
607
+ id: "createWorkflow",
608
+ schema: createWorkflowFunctionSchema,
609
+ executor: createWorkflowFunc,
610
+ description: {
611
+ name: "createWorkflow",
612
+ description:
613
+ "当执行路径已知时,定义并执行一个多步骤 workflow。引擎自动运行,无需每步调用 LLM,大幅节省 token。",
614
+ category: "计划与编排",
615
+ },
616
+ behavior: "orchestrator",
617
+ },
618
+ {
619
+ id: "toolquery",
620
+ schema: toolQueryFunctionSchema,
621
+ executor: toolQueryFunc,
622
+ description: {
623
+ name: "toolquery",
624
+ description:
625
+ "根据任务描述列出可能有用的工具,帮助你选择合适的工具链。",
626
+ category: "计划与编排",
627
+ },
628
+ behavior: "answer",
629
+ },
630
+ {
631
+ id: "delay",
632
+ schema: delayFunctionSchema,
633
+ executor: delayFunc,
634
+ description: {
635
+ name: "delay",
636
+ description:
637
+ "让计划暂停一小段时间(毫秒),用于节流批量操作(例如连续下载多个文件)。",
638
+ category: "计划与编排",
639
+ },
640
+ behavior: "action",
641
+ },
642
+ {
643
+ id: "queryModelUsage",
644
+ schema: queryModelUsageFunctionSchema,
645
+ executor: queryModelUsageFunc,
646
+ description: {
647
+ name: "queryModelUsage",
648
+ description:
649
+ "查询模型/API 用量与费用,带用户/管理员权限限制,可用于每日用量告警。",
650
+ category: "计费 / 用量",
651
+ },
652
+ behavior: "answer",
653
+ uiGroup: "general",
654
+ capability: "general",
655
+ riskLevel: "low",
656
+ costLevel: "low",
657
+ defaultConsent: "auto",
658
+ },
659
+ {
660
+ id: "createScheduledTask",
661
+ schema: createScheduledTaskFunctionSchema,
662
+ executor: createScheduledTaskFunc,
663
+ description: {
664
+ name: "createScheduledTask",
665
+ description:
666
+ "创建由 agent 执行的 cron 定时任务,可选择创建后立即试运行一次。",
667
+ category: "计划与编排",
668
+ },
669
+ behavior: "action",
670
+ uiGroup: "general",
671
+ capability: "general",
672
+ riskLevel: "medium",
673
+ costLevel: "low",
674
+ defaultConsent: "ask",
675
+ },
676
+ {
677
+ id: "notifyUser",
678
+ schema: notifyUserFunctionSchema,
679
+ executor: notifyUserFunc,
680
+ description: {
681
+ name: "notifyUser",
682
+ description: "发送站内通知给当前用户,用于告警和任务结果提醒。",
683
+ category: "通知",
684
+ },
685
+ behavior: "action",
686
+ uiGroup: "general",
687
+ capability: "general",
688
+ riskLevel: "low",
689
+ costLevel: "low",
690
+ defaultConsent: "auto",
691
+ },
692
+
693
+ // --- 内容管理 ---
694
+ {
695
+ id: "createDoc",
696
+ schema: createDocFunctionSchema,
697
+ executor: createDocFunc,
698
+ description: {
699
+ name: "createDoc",
700
+ description: "在当前空间中创建新页面",
701
+ category: "内容管理",
702
+ },
703
+ behavior: "action",
704
+ uiGroup: "content",
705
+ capability: "knowledge_capture",
706
+ riskLevel: "medium",
707
+ costLevel: "medium",
708
+ defaultConsent: "ask",
709
+ },
710
+ {
711
+ id: "createSkillDoc",
712
+ schema: createSkillDocFunctionSchema,
713
+ executor: createSkillDocFunc,
714
+ description: {
715
+ name: "createSkillDoc",
716
+ description: "创建带 skill-config / eval-config 协议块的本地 skill 文档。",
717
+ category: "内容管理",
718
+ },
719
+ behavior: "action",
720
+ uiGroup: "content",
721
+ capability: "knowledge_capture",
722
+ riskLevel: "medium",
723
+ costLevel: "medium",
724
+ defaultConsent: "ask",
725
+ },
726
+ {
727
+ id: "doctorSkill",
728
+ schema: doctorSkillFunctionSchema,
729
+ executor: doctorSkillFunc,
730
+ description: {
731
+ name: "doctorSkill",
732
+ description: "诊断 skill 文档协议、工具绑定和常见问题。",
733
+ category: "内容管理",
734
+ },
735
+ behavior: "answer",
736
+ uiGroup: "content",
737
+ capability: "knowledge_capture",
738
+ riskLevel: "low",
739
+ costLevel: "low",
740
+ },
741
+ {
742
+ id: "evalSkill",
743
+ schema: evalSkillFunctionSchema,
744
+ executor: evalSkillFunc,
745
+ description: {
746
+ name: "evalSkill",
747
+ description: "根据 eval-config 评估一个 skill 文档是否满足预期。",
748
+ category: "内容管理",
749
+ },
750
+ behavior: "answer",
751
+ uiGroup: "content",
752
+ capability: "knowledge_capture",
753
+ riskLevel: "low",
754
+ costLevel: "low",
755
+ },
756
+ {
757
+ id: "importSkill",
758
+ schema: importSkillFunctionSchema,
759
+ executor: importSkillFunc,
760
+ description: {
761
+ name: "importSkill",
762
+ description: "导入外部 SKILL.md 或 Markdown skill 文档到当前空间。",
763
+ category: "内容管理",
764
+ },
765
+ behavior: "action",
766
+ uiGroup: "content",
767
+ capability: "knowledge_capture",
768
+ riskLevel: "medium",
769
+ costLevel: "medium",
770
+ defaultConsent: "ask",
771
+ },
772
+ {
773
+ id: "readDoc",
774
+ schema: readDocFunctionSchema,
775
+ executor: readDocFunc,
776
+ description: {
777
+ name: "readDoc",
778
+ description: "读取指定文档/页面的内容(Markdown 格式)",
779
+ category: "内容管理",
780
+ },
781
+ behavior: "data",
782
+ uiGroup: "content",
783
+ capability: "space_context",
784
+ riskLevel: "low",
785
+ costLevel: "medium",
786
+ },
787
+ {
788
+ id: "readPage",
789
+ schema: readPageFunctionSchema,
790
+ executor: readPageFunc,
791
+ description: {
792
+ name: "readPage",
793
+ description: "读取指定页面的内容(Markdown 格式,兼容旧名称)",
794
+ category: "内容管理",
795
+ },
796
+ behavior: "data",
797
+ uiGroup: "content",
798
+ capability: "space_context",
799
+ riskLevel: "low",
800
+ costLevel: "medium",
801
+ },
802
+ {
803
+ id: "updateDoc",
804
+ schema: updateDocFunctionSchema,
805
+ executor: updateDocFunc,
806
+ description: {
807
+ name: "updateDoc",
808
+ description: "更新指定页面/文档的内容。支持全量覆盖或在末尾追加内容。",
809
+ category: "内容管理",
810
+ },
811
+ behavior: "action",
812
+ uiGroup: "content",
813
+ capability: "knowledge_capture",
814
+ riskLevel: "medium",
815
+ costLevel: "medium",
816
+ defaultConsent: "ask",
817
+ },
818
+ {
819
+ id: "searchWorkspace",
820
+ schema: searchWorkspaceFunctionSchema,
821
+ executor: searchWorkspaceFunc,
822
+ description: {
823
+ name: "search_workspace",
824
+ description: "在当前空间(Workspace)中搜索页面、表格等内容。",
825
+ category: "内容管理",
826
+ },
827
+ behavior: "data",
828
+ uiGroup: "content",
829
+ capability: "space_context",
830
+ riskLevel: "low",
831
+ costLevel: "low",
832
+ },
833
+ {
834
+ id: "searchAllSpaces",
835
+ schema: searchAllSpacesFunctionSchema,
836
+ executor: searchAllSpacesFunc,
837
+ description: {
838
+ name: "search_all_spaces",
839
+ description: "在你可访问的全部空间中搜索页面、表格等内容,并返回所属空间。",
840
+ category: "内容管理",
841
+ },
842
+ behavior: "data",
843
+ uiGroup: "content",
844
+ capability: "space_context",
845
+ riskLevel: "low",
846
+ costLevel: "medium",
847
+ },
848
+ {
849
+ id: "searchDialogMessages",
850
+ schema: searchDialogMessagesFunctionSchema,
851
+ executor: searchDialogMessagesFunc,
852
+ description: {
853
+ name: "searchDialogMessages",
854
+ description: "在指定对话的原始消息中搜索文本,并返回命中的 messageId、角色、原文片段和邻近上下文。",
855
+ category: "内容管理",
856
+ },
857
+ behavior: "data",
858
+ uiGroup: "content",
859
+ capability: "space_context",
860
+ riskLevel: "low",
861
+ costLevel: "low",
862
+ },
863
+ {
864
+ id: "createCategory",
865
+ schema: createCategoryFunctionSchema,
866
+ executor: createCategoryFunc,
867
+ description: {
868
+ name: "createCategory",
869
+ description: "在当前空间中创建新分类",
870
+ category: "内容管理",
871
+ },
872
+ behavior: "action",
873
+ uiGroup: "content",
874
+ },
875
+ {
876
+ id: "updateContentCategory",
877
+ schema: updateContentCategoryFunctionSchema,
878
+ executor: updateContentCategoryFunc,
879
+ description: {
880
+ name: "updateContentCategory",
881
+ description: "更新内容的分类",
882
+ category: "内容管理",
883
+ },
884
+ behavior: "action",
885
+ uiGroup: "content",
886
+ },
887
+ {
888
+ id: "queryContentsByCategory",
889
+ schema: queryContentsByCategoryFunctionSchema,
890
+ executor: queryContentsByCategoryFunc,
891
+ description: {
892
+ name: "queryContentsByCategory",
893
+ description: "查询分类下的所有内容",
894
+ category: "内容管理",
895
+ },
896
+ behavior: "data",
897
+ uiGroup: "content",
898
+ },
899
+
900
+ // --- 数据操作 ---
901
+ {
902
+ id: "createTable",
903
+ schema: createTableFunctionSchema,
904
+ executor: createTableFunc,
905
+ description: {
906
+ name: "createTable",
907
+ description: "在当前租户下创建一张新的数据表,并定义字段结构。",
908
+ category: "数据操作",
909
+ },
910
+ behavior: "action",
911
+ uiGroup: "data",
912
+ capability: "knowledge_capture",
913
+ riskLevel: "medium",
914
+ costLevel: "medium",
915
+ defaultConsent: "ask",
916
+ },
917
+ {
918
+ id: "shareTable",
919
+ schema: shareTableFunctionSchema,
920
+ executor: shareTableFunc,
921
+ description: {
922
+ name: "shareTable",
923
+ description: "把表发布为可分享链接,可用于社区分享。",
924
+ category: "数据操作",
925
+ },
926
+ behavior: "action",
927
+ uiGroup: "data",
928
+ riskLevel: "medium",
929
+ costLevel: "low",
930
+ defaultConsent: "ask",
931
+ },
932
+ {
933
+ id: "importData",
934
+ schema: importDataFunctionSchema,
935
+ executor: importDataFunc,
936
+ description: {
937
+ name: "importData",
938
+ description: "将用户上传的文件数据导入数据库表",
939
+ category: "数据操作",
940
+ },
941
+ behavior: "data",
942
+ uiGroup: "data",
943
+ capability: "space_context",
944
+ riskLevel: "low",
945
+ costLevel: "medium",
946
+ },
947
+ {
948
+ id: "executeSql",
949
+ schema: executeSqlFunctionSchema,
950
+ executor: executeSqlFunc,
951
+ description: {
952
+ name: "executeSql",
953
+ description: "直接执行 SQL 语句",
954
+ category: "数据操作",
955
+ },
956
+ behavior: "data",
957
+ uiGroup: "data",
958
+ },
959
+ {
960
+ id: "read",
961
+ schema: readFunctionSchema,
962
+ executor: readFunc,
963
+ description: {
964
+ name: "read",
965
+ description:
966
+ "根据指定的 dbKey 从本地/远程数据库读取一条记录,可选择本地优先或等待远程结果。",
967
+ category: "数据操作",
968
+ },
969
+ behavior: "data",
970
+ uiGroup: "data",
971
+ },
972
+ {
973
+ id: "email_provision_identity",
974
+ schema: emailProvisionIdentityFunctionSchema,
975
+ executor: emailProvisionIdentityFunc,
976
+ description: {
977
+ name: "email_provision_identity",
978
+ description: "为 agent 生成并绑定受控域名邮箱身份。",
979
+ category: "数据操作",
980
+ },
981
+ behavior: "action",
982
+ uiGroup: "data",
983
+ riskLevel: "medium",
984
+ costLevel: "low",
985
+ defaultConsent: "ask",
986
+ },
987
+ {
988
+ id: "email_send",
989
+ schema: emailSendFunctionSchema,
990
+ executor: emailSendFunc,
991
+ description: {
992
+ name: "email_send",
993
+ description: "以 agent 已绑定邮箱身份发送邮件。",
994
+ category: "数据操作",
995
+ },
996
+ behavior: "action",
997
+ uiGroup: "data",
998
+ riskLevel: "medium",
999
+ costLevel: "low",
1000
+ defaultConsent: "ask",
1001
+ },
1002
+ {
1003
+ id: "email_wait_for",
1004
+ schema: emailWaitForFunctionSchema,
1005
+ executor: emailWaitForFunc,
1006
+ description: {
1007
+ name: "email_wait_for",
1008
+ description: "等待符合条件的邮件到达。",
1009
+ category: "数据操作",
1010
+ },
1011
+ behavior: "data",
1012
+ uiGroup: "data",
1013
+ riskLevel: "low",
1014
+ costLevel: "low",
1015
+ },
1016
+ {
1017
+ id: "email_extract_verification",
1018
+ schema: emailExtractVerificationFunctionSchema,
1019
+ executor: emailExtractVerificationFunc,
1020
+ description: {
1021
+ name: "email_extract_verification",
1022
+ description: "从邮件中提取验证码和验证链接。",
1023
+ category: "数据操作",
1024
+ },
1025
+ behavior: "data",
1026
+ uiGroup: "data",
1027
+ riskLevel: "low",
1028
+ costLevel: "low",
1029
+ },
1030
+ {
1031
+ id: "email_search",
1032
+ schema: emailSearchFunctionSchema,
1033
+ executor: emailSearchFunc,
1034
+ description: {
1035
+ name: "email_search",
1036
+ description: "查询当前主体可访问的邮件列表。",
1037
+ category: "数据操作",
1038
+ },
1039
+ behavior: "data",
1040
+ uiGroup: "data",
1041
+ riskLevel: "low",
1042
+ costLevel: "low",
1043
+ },
1044
+ {
1045
+ id: "email_read",
1046
+ schema: emailReadFunctionSchema,
1047
+ executor: emailReadFunc,
1048
+ description: {
1049
+ name: "email_read",
1050
+ description: "读取一封邮件的完整内容。",
1051
+ category: "数据操作",
1052
+ },
1053
+ behavior: "data",
1054
+ uiGroup: "data",
1055
+ riskLevel: "low",
1056
+ costLevel: "low",
1057
+ },
1058
+ {
1059
+ id: "email_update_tags",
1060
+ schema: emailUpdateTagsFunctionSchema,
1061
+ executor: emailUpdateTagsFunc,
1062
+ description: {
1063
+ name: "email_update_tags",
1064
+ description: "替换一封邮件的 tags。",
1065
+ category: "数据操作",
1066
+ },
1067
+ behavior: "action",
1068
+ uiGroup: "data",
1069
+ riskLevel: "medium",
1070
+ costLevel: "low",
1071
+ },
1072
+ {
1073
+ id: "email_archive",
1074
+ schema: emailArchiveFunctionSchema,
1075
+ executor: emailArchiveFunc,
1076
+ description: {
1077
+ name: "email_archive",
1078
+ description: "把一封邮件移动到 archive mailbox。",
1079
+ category: "数据操作",
1080
+ },
1081
+ behavior: "action",
1082
+ uiGroup: "data",
1083
+ riskLevel: "medium",
1084
+ costLevel: "low",
1085
+ },
1086
+ {
1087
+ id: "addTableRow",
1088
+ schema: addTableRowFunctionSchema,
1089
+ executor: addTableRowFunc,
1090
+ description: {
1091
+ name: "addTableRow",
1092
+ description:
1093
+ "在当前已打开的表中新增一行数据,通常由 AI 根据分析结果自动填充各列。",
1094
+ category: "数据操作",
1095
+ },
1096
+ behavior: "action",
1097
+ uiGroup: "data",
1098
+ },
1099
+ {
1100
+ id: "queryTableRows",
1101
+ schema: queryTableRowsFunctionSchema,
1102
+ executor: queryTableRowsFunc,
1103
+ description: {
1104
+ name: "queryTableRows",
1105
+ description: "查询指定表中的行,支持过滤、排序和分页。",
1106
+ category: "数据操作",
1107
+ },
1108
+ behavior: "data",
1109
+ uiGroup: "data",
1110
+ },
1111
+ {
1112
+ id: "updateTableRow",
1113
+ schema: updateTableRowFunctionSchema,
1114
+ executor: updateTableRowFunc,
1115
+ description: {
1116
+ name: "updateTableRow",
1117
+ description: "更新表中的单行数据。",
1118
+ category: "数据操作",
1119
+ },
1120
+ behavior: "action",
1121
+ uiGroup: "data",
1122
+ },
1123
+ {
1124
+ id: "deleteTableRow",
1125
+ schema: deleteTableRowFunctionSchema,
1126
+ executor: deleteTableRowFunc,
1127
+ description: {
1128
+ name: "deleteTableRow",
1129
+ description: "删除表中的单行数据。",
1130
+ category: "数据操作",
1131
+ },
1132
+ behavior: "action",
1133
+ uiGroup: "data",
1134
+ },
1135
+ {
1136
+ id: "addTableRows",
1137
+ schema: addTableRowsFunctionSchema,
1138
+ executor: addTableRowsFunc,
1139
+ description: {
1140
+ name: "addTableRows",
1141
+ description: "批量向表中新增多行数据。",
1142
+ category: "数据操作",
1143
+ },
1144
+ behavior: "action",
1145
+ uiGroup: "data",
1146
+ },
1147
+ {
1148
+ id: "updateTableRows",
1149
+ schema: updateTableRowsFunctionSchema,
1150
+ executor: updateTableRowsFunc,
1151
+ description: {
1152
+ name: "updateTableRows",
1153
+ description: "批量更新表中的多行数据。",
1154
+ category: "数据操作",
1155
+ },
1156
+ behavior: "action",
1157
+ uiGroup: "data",
1158
+ },
1159
+ {
1160
+ id: "deleteTableRows",
1161
+ schema: deleteTableRowsFunctionSchema,
1162
+ executor: deleteTableRowsFunc,
1163
+ description: {
1164
+ name: "deleteTableRows",
1165
+ description: "批量删除表中的多行数据。",
1166
+ category: "数据操作",
1167
+ },
1168
+ behavior: "action",
1169
+ uiGroup: "data",
1170
+ },
1171
+ {
1172
+ id: "addTableColumn",
1173
+ schema: addTableColumnFunctionSchema,
1174
+ executor: addTableColumnFunc,
1175
+ description: {
1176
+ name: "addTableColumn",
1177
+ description: "向表中新增字段。",
1178
+ category: "数据操作",
1179
+ },
1180
+ behavior: "action",
1181
+ uiGroup: "data",
1182
+ },
1183
+ {
1184
+ id: "deleteTableColumn",
1185
+ schema: deleteTableColumnFunctionSchema,
1186
+ executor: deleteTableColumnFunc,
1187
+ description: {
1188
+ name: "deleteTableColumn",
1189
+ description: "删除表中的字段,并同步清理现有行数据。",
1190
+ category: "数据操作",
1191
+ },
1192
+ behavior: "action",
1193
+ uiGroup: "data",
1194
+ },
1195
+ {
1196
+ id: "renameTableColumn",
1197
+ schema: renameTableColumnFunctionSchema,
1198
+ executor: renameTableColumnFunc,
1199
+ description: {
1200
+ name: "renameTableColumn",
1201
+ description: "修改表字段的 machine name,并迁移已有行数据。",
1202
+ category: "数据操作",
1203
+ },
1204
+ behavior: "action",
1205
+ uiGroup: "data",
1206
+ },
1207
+ {
1208
+ id: "renameTableColumnLabel",
1209
+ schema: renameTableColumnLabelFunctionSchema,
1210
+ executor: renameTableColumnLabelFunc,
1211
+ description: {
1212
+ name: "renameTableColumnLabel",
1213
+ description: "修改表字段的显示名。",
1214
+ category: "数据操作",
1215
+ },
1216
+ behavior: "action",
1217
+ uiGroup: "data",
1218
+ },
1219
+ {
1220
+ id: "renameTable",
1221
+ schema: renameTableFunctionSchema,
1222
+ executor: renameTableFunc,
1223
+ description: {
1224
+ name: "renameTable",
1225
+ description: "更新表的显示名称。",
1226
+ category: "数据操作",
1227
+ },
1228
+ behavior: "action",
1229
+ uiGroup: "data",
1230
+ },
1231
+ {
1232
+ id: "updateContentTitle",
1233
+ schema: updateContentTitleTool.function,
1234
+ executor: updateContentTitleFunc as any,
1235
+ description: {
1236
+ name: "update_content_title",
1237
+ description: "更新当前空间中某个内容的标题",
1238
+ category: "内容管理",
1239
+ },
1240
+ behavior: "action",
1241
+ uiGroup: "content",
1242
+ },
1243
+ // === Space 导航工具 ===
1244
+ {
1245
+ id: "listUserSpaces",
1246
+ schema: listUserSpacesFunctionSchema,
1247
+ executor: listUserSpacesFunc,
1248
+ description: {
1249
+ name: "listUserSpaces",
1250
+ description:
1251
+ "获取当前用户可访问的所有 Space 列表(概览),只返回 ID 和名称。",
1252
+ category: "数据操作",
1253
+ },
1254
+ behavior: "data",
1255
+ uiGroup: "data",
1256
+ },
1257
+ {
1258
+ id: "deleteSpaces",
1259
+ schema: deleteSpacesFunctionSchema,
1260
+ executor: deleteSpacesFunc,
1261
+ previewExecutor: deleteSpacesPreviewFunc,
1262
+ description: {
1263
+ name: "deleteSpaces",
1264
+ description:
1265
+ "按名称或 ID 删除当前用户拥有的 Space;先列出候选,用户确认后才删除 Space 壳和成员关系。",
1266
+ category: "数据操作",
1267
+ },
1268
+ behavior: "action",
1269
+ uiGroup: "data",
1270
+ capability: "space_context",
1271
+ interaction: "confirm",
1272
+ riskLevel: "high",
1273
+ costLevel: "low",
1274
+ defaultConsent: "ask",
1275
+ },
1276
+
1277
+ // --- 网络与智能 ---
1278
+ {
1279
+ id: "fetchWebpage",
1280
+ schema: fetchWebpageFunctionSchema,
1281
+ executor: fetchWebpageFunc,
1282
+ description: {
1283
+ name: "fetchWebpage",
1284
+ description: "访问网页并获取其内容",
1285
+ category: "网络与智能",
1286
+ },
1287
+ behavior: "data",
1288
+ },
1289
+ {
1290
+ id: "readXPost",
1291
+ schema: readXPostFunctionSchema,
1292
+ executor: readXPostFunc,
1293
+ description: {
1294
+ name: "read_x_post",
1295
+ description:
1296
+ "读取 X/Twitter status 链接的可见帖子正文和结构化数据,适合总结、解释或抽取用户给出的 X 帖子。",
1297
+ category: "网络与智能",
1298
+ },
1299
+ behavior: "data",
1300
+ capability: "web_access",
1301
+ riskLevel: "low",
1302
+ costLevel: "low",
1303
+ defaultConsent: "auto",
1304
+ cancelable: true,
1305
+ },
1306
+
1307
+ {
1308
+ id: "surfWeather",
1309
+ schema: surfWeatherFunctionSchema,
1310
+ executor: surfWeatherFunc,
1311
+ description: {
1312
+ name: "surfWeather",
1313
+ description:
1314
+ "获取指定海岸位置的冲浪天气预报(浪高、涌浪、周期、浪向),判断是否适合冲浪。",
1315
+ category: "网络与智能",
1316
+ },
1317
+ behavior: "data",
1318
+ },
1319
+
1320
+ // === Cloudflare Browser Rendering 爬取工具 ===
1321
+ {
1322
+ id: "cloudflareCrawl",
1323
+ schema: cloudflareCrawlFunctionSchema,
1324
+ executor: cloudflareCrawlFunc,
1325
+ description: {
1326
+ name: "cloudflareCrawl",
1327
+ description:
1328
+ "使用 Cloudflare Browser Rendering 爬取整个网站(支持 JS 渲染),一次调用可获取多页 Markdown 内容,适合站点级内容抓取。",
1329
+ category: "网络与智能",
1330
+ },
1331
+ behavior: "data",
1332
+ },
1333
+ {
1334
+ id: "cloudflareCrawlStatus",
1335
+ schema: cloudflareCrawlStatusFunctionSchema,
1336
+ executor: cloudflareCrawlStatusFunc,
1337
+ description: {
1338
+ name: "cloudflareCrawlStatus",
1339
+ description: "查询 Cloudflare 爬取任务的当前状态和结果(配合 cloudflareCrawl wait=false 使用)。",
1340
+ category: "网络与智能",
1341
+ },
1342
+ behavior: "data",
1343
+ },
1344
+
1345
+ // === Apify 抓取工具 ===
1346
+ {
1347
+ id: "googleSearchScraper",
1348
+ schema: googleSearchScraperFunctionSchema,
1349
+ executor: googleSearchScraperFunc,
1350
+ description: {
1351
+ name: "googleSearchScraper",
1352
+ description: "抓取 Google 搜索结果(SERP),返回自然结果、广告、People Also Ask 等结构化数据。",
1353
+ category: "网络与智能",
1354
+ },
1355
+ behavior: "data",
1356
+ },
1357
+ {
1358
+ id: "youtubeScraper",
1359
+ schema: youtubeScraperFunctionSchema,
1360
+ executor: youtubeScraperFunc,
1361
+ description: {
1362
+ name: "youtubeScraper",
1363
+ description:
1364
+ "使用 Apify YouTube Scraper 抓取指定视频、频道或搜索结果的详细数据(支持字幕)。",
1365
+ category: "网络与智能",
1366
+ },
1367
+ behavior: "data",
1368
+ },
1369
+ {
1370
+ id: "ecommerceScraper",
1371
+ schema: ecommerceScraperFunctionSchema,
1372
+ executor: ecommerceScraperFunc,
1373
+ description: {
1374
+ name: "ecommerceScraper",
1375
+ description:
1376
+ "使用 Apify E-commerce Scraping Tool 抓取电商产品、评论和卖家信息。",
1377
+ category: "网络与智能",
1378
+ },
1379
+ behavior: "data",
1380
+ },
1381
+ {
1382
+ id: "amazonProductScraper",
1383
+ schema: amazonProductScraperFunctionSchema,
1384
+ executor: amazonProductScraperFunc,
1385
+ description: {
1386
+ name: "amazonProductScraper",
1387
+ description:
1388
+ "使用 Apify Amazon Product Scraper 抓取亚马逊商品和类目数据。",
1389
+ category: "网络与智能",
1390
+ },
1391
+ behavior: "data",
1392
+ },
1393
+
1394
+ // 浏览器会话工具
1395
+ {
1396
+ id: "browserCloseSession",
1397
+ schema: browser_closeSession_Schema,
1398
+ executor: browser_closeSession_Func,
1399
+ description: {
1400
+ name: "browser_closeSession",
1401
+ description: "关闭浏览器会话并释放服务器槽位。",
1402
+ category: "网络与智能",
1403
+ },
1404
+ behavior: "action",
1405
+ },
1406
+ {
1407
+ id: "browserOpenSession",
1408
+ schema: browser_openSession_Schema,
1409
+ executor: browser_openSession_Func,
1410
+ description: {
1411
+ name: "browser_openSession",
1412
+ description: "打开一个新的浏览器会话并导航到 URL,返回会话ID",
1413
+ category: "网络与智能",
1414
+ },
1415
+ behavior: "action",
1416
+ },
1417
+ {
1418
+ id: "browserSelectOption",
1419
+ schema: browser_selectOption_Schema,
1420
+ executor: browser_selectOption_Func,
1421
+ description: {
1422
+ name: "browser_selectOption",
1423
+ description: "在浏览器会话中选择一个下拉框选项",
1424
+ category: "网络与智能",
1425
+ },
1426
+ behavior: "action",
1427
+ },
1428
+ {
1429
+ id: "browserClick",
1430
+ schema: browser_click_Schema,
1431
+ executor: browser_click_Func,
1432
+ description: {
1433
+ name: "browser_click",
1434
+ description: "在浏览器会话中点击指定元素 (例如按钮、链接)。",
1435
+ category: "网络与智能",
1436
+ },
1437
+ behavior: "action",
1438
+ },
1439
+ {
1440
+ id: "browserTypeText",
1441
+ schema: browser_typeText_Schema,
1442
+ executor: browser_typeText_Func,
1443
+ description: {
1444
+ name: "browser_typeText",
1445
+ description: "在浏览器会话中向输入框填写文本 (可选回车)。",
1446
+ category: "网络与智能",
1447
+ },
1448
+ behavior: "action",
1449
+ },
1450
+ {
1451
+ id: "browserReadContent",
1452
+ schema: browser_readContent_Schema,
1453
+ executor: browser_readContent_Func,
1454
+ description: {
1455
+ name: "browser_readContent",
1456
+ description: "读取当前浏览器页面或指定元素的可见文本内容。",
1457
+ category: "网络与智能",
1458
+ },
1459
+ behavior: "data",
1460
+ },
1461
+ {
1462
+ id: "exaSearch",
1463
+ schema: exaSearchSchema,
1464
+ executor: exaSearchFunc,
1465
+ description: {
1466
+ name: "exa_search",
1467
+ description: "使用 Exa 神经网络搜索引擎获取高质量、结构化的网络信息(包含正文)。",
1468
+ category: "网络与智能",
1469
+ },
1470
+ behavior: "data",
1471
+ },
1472
+ {
1473
+ id: "paddleOcr",
1474
+ schema: paddleOcrSchema,
1475
+ executor: paddleOcrFunc,
1476
+ description: {
1477
+ name: "paddle_ocr",
1478
+ description: "使用 PaddleOCR-VL-0.9B 进行图片文字识别,支持多语言、表格和公式。",
1479
+ category: "网络与智能",
1480
+ },
1481
+ behavior: "data",
1482
+ },
1483
+ {
1484
+ id: "olmOcr",
1485
+ schema: olmOcrSchema,
1486
+ executor: olmOcrFunc,
1487
+ description: {
1488
+ name: "olm_ocr",
1489
+ description: "使用 olmOCR-2-7B-1025 进行图片文字识别,适合文档、论文等结构化文本的高质量识别。",
1490
+ category: "网络与智能",
1491
+ },
1492
+ behavior: "data",
1493
+ },
1494
+ {
1495
+ id: "whisperTurbo",
1496
+ schema: whisperTurboSchema,
1497
+ executor: whisperTurboFunc,
1498
+ description: {
1499
+ name: "whisper_turbo",
1500
+ description: "使用 whisper-large-v3-turbo 快速转录音频为文字,支持多语言,速度快价格低。",
1501
+ category: "音频与媒体",
1502
+ },
1503
+ behavior: "data",
1504
+ },
1505
+ {
1506
+ id: "whisperV3",
1507
+ schema: whisperV3Schema,
1508
+ executor: whisperV3Func,
1509
+ description: {
1510
+ name: "whisper_v3",
1511
+ description: "使用 whisper-large-v3 高精度转录音频,中文/多语言准确率更高,适合对质量要求严格的场景。",
1512
+ category: "音频与媒体",
1513
+ },
1514
+ behavior: "data",
1515
+ },
1516
+
1517
+ // --- Cloudflare Browser Rendering ---
1518
+
1519
+ {
1520
+ id: "cfScreenshot",
1521
+ schema: cfScreenshotFunctionSchema,
1522
+ executor: cfScreenshotFunc,
1523
+ description: {
1524
+ name: "cfScreenshot",
1525
+ description: "使用 Cloudflare Browser Rendering 对网页或 HTML 截图,支持全页截图和自定义视口。",
1526
+ category: "网络与智能",
1527
+ },
1528
+ behavior: "data",
1529
+ uiGroup: "general",
1530
+ },
1531
+ {
1532
+ id: "cfGetMarkdown",
1533
+ schema: cfGetMarkdownFunctionSchema,
1534
+ executor: cfGetMarkdownFunc,
1535
+ description: {
1536
+ name: "cfGetMarkdown",
1537
+ description: "使用 Cloudflare Browser Rendering 将网页转为 Markdown,支持 JS 渲染,速度快于多页爬取。",
1538
+ category: "网络与智能",
1539
+ },
1540
+ behavior: "data",
1541
+ uiGroup: "general",
1542
+ },
1543
+ {
1544
+ id: "cfGeneratePDF",
1545
+ schema: cfGeneratePDFFunctionSchema,
1546
+ executor: cfGeneratePDFFunc,
1547
+ description: {
1548
+ name: "cfGeneratePDF",
1549
+ description: "使用 Cloudflare Browser Rendering 将网页或 HTML 渲染为 PDF 文件,适合文档导出。",
1550
+ category: "文档生成",
1551
+ },
1552
+ behavior: "action",
1553
+ uiGroup: "general",
1554
+ },
1555
+ {
1556
+ id: "cfExtractJSON",
1557
+ schema: cfExtractJSONFunctionSchema,
1558
+ executor: cfExtractJSONFunc,
1559
+ description: {
1560
+ name: "cfExtractJSON",
1561
+ description: "使用 Cloudflare Browser Rendering + AI 从网页提取结构化 JSON 数据,用自然语言描述需要的字段。",
1562
+ category: "网络与智能",
1563
+ },
1564
+ behavior: "data",
1565
+ uiGroup: "general",
1566
+ },
1567
+ {
1568
+ id: "appPreflight",
1569
+ schema: appPreflightFunctionSchema,
1570
+ executor: appPreflightFunc,
1571
+ description: {
1572
+ name: "appPreflight",
1573
+ description: "在部署前检查应用结构、依赖、图标与常见构建问题。",
1574
+ category: "应用部署",
1575
+ },
1576
+ behavior: "data",
1577
+ uiGroup: "general",
1578
+ },
1579
+ {
1580
+ id: "appDeploy",
1581
+ schema: appDeployFunctionSchema,
1582
+ executor: appDeployFunc,
1583
+ description: {
1584
+ name: "appDeploy",
1585
+ description: "将 JavaScript/TypeScript 代码部署为平台托管的 Web 应用。",
1586
+ category: "应用部署",
1587
+ },
1588
+ behavior: "data",
1589
+ uiGroup: "general",
1590
+ },
1591
+ {
1592
+ id: "appList",
1593
+ schema: appListFunctionSchema,
1594
+ executor: appListFunc,
1595
+ description: {
1596
+ name: "appList",
1597
+ description: "列出当前用户已部署的所有应用,包括名称、appId 和访问 URL。",
1598
+ category: "应用部署",
1599
+ },
1600
+ behavior: "data",
1601
+ uiGroup: "general",
1602
+ },
1603
+ {
1604
+ id: "appDelete",
1605
+ schema: appDeleteFunctionSchema,
1606
+ executor: appDeleteFunc,
1607
+ description: {
1608
+ name: "appDelete",
1609
+ description: "删除一个已部署的应用,删除后 URL 立即失效。",
1610
+ category: "应用部署",
1611
+ },
1612
+ behavior: "data",
1613
+ uiGroup: "general",
1614
+ },
1615
+ {
1616
+ id: "appRead",
1617
+ schema: appReadFunctionSchema,
1618
+ executor: appReadFunc,
1619
+ description: {
1620
+ name: "appRead",
1621
+ description: "读取已部署应用的当前代码,修改应用前必须先调用此工具获取现有代码。",
1622
+ category: "应用部署",
1623
+ },
1624
+ behavior: "data",
1625
+ uiGroup: "general",
1626
+ },
1627
+ {
1628
+ id: "cfSpeechToText",
1629
+ schema: cfSpeechToTextFunctionSchema,
1630
+ executor: cfSpeechToTextFunc,
1631
+ description: {
1632
+ name: "cfSpeechToText",
1633
+ description: "使用 Cloudflare Workers AI (@cf/openai/whisper) 将音频文件转换为文字,支持多语言自动识别。",
1634
+ category: "媒体处理",
1635
+ },
1636
+ behavior: "data",
1637
+ uiGroup: "general",
1638
+ },
1639
+ {
1640
+ id: "execBash",
1641
+ schema: execBashFunctionSchema,
1642
+ executor: execBashFunc,
1643
+ description: {
1644
+ name: "exec_bash",
1645
+ description:
1646
+ "通过后端 diff-server 的 /api/exec-bash 接口执行一条 bash 命令,仅用于本地开发调试。",
1647
+ category: "网络与智能",
1648
+ },
1649
+ behavior: "action",
1650
+ },
1651
+ {
1652
+ id: "execShell",
1653
+ schema: execShellFunctionSchema,
1654
+ executor: execShellFunc,
1655
+ description: {
1656
+ name: "exec_shell",
1657
+ description:
1658
+ "通过后端 shell 执行接口运行跨平台命令:Windows 优先 PowerShell,Linux/macOS 使用 bash,仅用于本地开发调试。",
1659
+ category: "网络与智能",
1660
+ },
1661
+ behavior: "action",
1662
+ },
1663
+ {
1664
+ id: "checkEnv",
1665
+ schema: checkEnvFunctionSchema,
1666
+ executor: checkEnvFunc,
1667
+ description: {
1668
+ name: "checkEnv",
1669
+ description:
1670
+ "执行环境检查(当前默认并支持 build),用于代码变更后的快速生效前验证。",
1671
+ category: "网络与智能",
1672
+ },
1673
+ behavior: "action",
1674
+ uiGroup: "data",
1675
+ },
1676
+
1677
+ // --- 多媒体生成 / 文档生成 ---
1678
+
1679
+ {
1680
+ id: "geminiFlashImage",
1681
+ schema: geminiFlashImageFunctionSchema,
1682
+ executor: geminiFlashImageFunc,
1683
+ description: {
1684
+ name: "geminiFlashImage",
1685
+ description:
1686
+ "使用 Gemini 2.5 Flash 模型,根据文字说明和可选输入图片生成图像,适合文生图和轻量编辑。",
1687
+ category: "多媒体生成",
1688
+ },
1689
+ behavior: "action",
1690
+ uiGroup: "media",
1691
+ },
1692
+ {
1693
+ id: "geminiProImagePreview",
1694
+ schema: geminiProImagePreviewFunctionSchema,
1695
+ executor: geminiProImagePreviewFunc,
1696
+ description: {
1697
+ name: "geminiProImagePreview",
1698
+ description:
1699
+ "使用 Gemini 3 Pro Image Preview 模型,基于一张或多张输入图片进行复杂编辑和多图合成。",
1700
+ category: "多媒体生成",
1701
+ },
1702
+ behavior: "action",
1703
+ uiGroup: "media",
1704
+ },
1705
+ {
1706
+ id: "openAIGptImage",
1707
+ schema: openAIGptImageFunctionSchema,
1708
+ executor: openAIGptImageFunc,
1709
+ description: {
1710
+ name: "openAIGptImage",
1711
+ description:
1712
+ "使用 OpenAI GPT Image 1.5 生成或编辑图片,适合项目页素材、海报、插画和改图。",
1713
+ category: "多媒体生成",
1714
+ },
1715
+ behavior: "action",
1716
+ uiGroup: "media",
1717
+ },
1718
+ {
1719
+ id: "remotionRenderVideo",
1720
+ schema: remotionRenderVideoFunctionSchema,
1721
+ executor: remotionRenderVideoFunc,
1722
+ description: {
1723
+ name: "remotionRenderVideo",
1724
+ description:
1725
+ "使用平台内 Remotion 模板渲染手机传播视频或产品介绍视频,并保存为 MP4。",
1726
+ category: "多媒体生成",
1727
+ },
1728
+ behavior: "action",
1729
+ uiGroup: "media",
1730
+ capability: "general",
1731
+ riskLevel: "medium",
1732
+ costLevel: "medium",
1733
+ defaultConsent: "ask",
1734
+ cancelable: true,
1735
+ },
1736
+ {
1737
+ id: "generateDocx",
1738
+ schema: generateDocxFunctionSchema,
1739
+ executor: generateDocxFunc,
1740
+ description: {
1741
+ name: "generateDocx",
1742
+ description:
1743
+ "在浏览器端根据指定 DOCX 模板 URL 和变量生成文档,并触发下载。",
1744
+ category: "文档生成",
1745
+ },
1746
+ behavior: "action",
1747
+ },
1748
+ ];
1749
+
1750
+ // 汇总所有工具定义:基础工具 + Agent 分组 + 代码分组
1751
+ const toolDefinitions: ToolDefinition[] = [
1752
+ ...baseToolDefinitions,
1753
+ ...agentToolDefinitions,
1754
+ ...codeToolDefinitions,
1755
+ ];
1756
+
1757
+ /* ==================================================================
1758
+ * 3.1 动态为 createAgent / updateAgent 的 tools 字段补 enum
1759
+ * ================================================================== */
1760
+
1761
+ // 所有函数工具的 schema.name 列表
1762
+ const ALL_TOOL_FUNCTION_NAMES: string[] = toolDefinitions
1763
+ .map((tool) => tool.schema?.name)
1764
+ .filter((name): name is string => Boolean(name));
1765
+
1766
+ // Agent 可用的工具名:保留 ui_ask_choice,排除 toolquery 和默认开启的浏览器/搜索工具
1767
+ const AGENT_AVAILABLE_TOOL_NAMES = ALL_TOOL_FUNCTION_NAMES.filter(
1768
+ (name) =>
1769
+ name !== "toolquery" &&
1770
+ !name.startsWith("browser_") &&
1771
+ name !== "exa_search"
1772
+ );
1773
+
1774
+ // 给 createAgent / updateAgent 的 tools 参数 items 动态挂 enum
1775
+ export const patchAgentToolSchemas = () => {
1776
+ try {
1777
+ const createAgentToolsProp =
1778
+ createAgentToolFunctionSchema?.parameters?.properties?.tools;
1779
+ if (createAgentToolsProp?.items && !(createAgentToolsProp.items as any).enum) {
1780
+ (createAgentToolsProp.items as any).enum = AGENT_AVAILABLE_TOOL_NAMES;
1781
+ }
1782
+
1783
+ const updateAgentToolsProp =
1784
+ updateAgentToolFunctionSchema?.parameters?.properties?.tools;
1785
+ if (updateAgentToolsProp?.items && !(updateAgentToolsProp.items as any).enum) {
1786
+ (updateAgentToolsProp.items as any).enum = AGENT_AVAILABLE_TOOL_NAMES;
1787
+ }
1788
+ } catch {
1789
+ // 静默失败即可,不影响其他工具
1790
+ }
1791
+ };
1792
+
1793
+ patchAgentToolSchemas();
1794
+
1795
+ /* ==================================================================
1796
+ * 4. 程序化生成所需的各个对象
1797
+ * ================================================================== */
1798
+
1799
+ export const toolRegistry: Record<string, any> = toolDefinitions.reduce(
1800
+ (acc, tool) => {
1801
+ acc[tool.schema.name] = { type: "function", function: tool.schema };
1802
+ return acc;
1803
+ },
1804
+ {} as Record<string, any>
1805
+ );
1806
+
1807
+ export const toolExecutors: Record<string, ToolDefinition["executor"]> =
1808
+ toolDefinitions.reduce(
1809
+ (acc, tool) => {
1810
+ acc[tool.schema.name] = tool.executor;
1811
+ return acc;
1812
+ },
1813
+ {} as Record<string, ToolDefinition["executor"]>
1814
+ );
1815
+
1816
+ export const toolDescriptions: Record<string, ToolDefinition["description"]> =
1817
+ toolDefinitions.reduce(
1818
+ (acc, tool) => {
1819
+ acc[tool.schema.name] = tool.description;
1820
+ return acc;
1821
+ },
1822
+ {} as Record<string, ToolDefinition["description"]>
1823
+ );
1824
+
1825
+ export const toolDefinitionsByName: Record<string, ToolDefinition> =
1826
+ toolDefinitions.reduce(
1827
+ (acc, tool) => {
1828
+ acc[tool.schema.name] = tool;
1829
+ return acc;
1830
+ },
1831
+ {} as Record<string, ToolDefinition>
1832
+ );
1833
+
1834
+ /* ==================================================================
1835
+ * 5. 工具查找辅助函数
1836
+ * ================================================================== */
1837
+ const normalizeToolName = (name: string): string =>
1838
+ name.replace(/[-_]/g, "").toLowerCase();
1839
+
1840
+ export const findToolExecutor = (
1841
+ rawName: string
1842
+ ): {
1843
+ executor: ToolDefinition["executor"];
1844
+ canonicalName: string;
1845
+ } => {
1846
+ const normalizedRawName = normalizeToolName(rawName);
1847
+ const canonicalName = Object.keys(toolExecutors).find(
1848
+ (key) => normalizeToolName(key) === normalizedRawName
1849
+ );
1850
+
1851
+ if (canonicalName && toolExecutors[canonicalName]) {
1852
+ return {
1853
+ executor: toolExecutors[canonicalName],
1854
+ canonicalName,
1855
+ };
1856
+ }
1857
+ throw new Error(`执行器未找到:未知工具 "${rawName}"`);
1858
+ };