nolo-cli 0.1.13 → 0.1.14

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