nolo-cli 0.1.40 → 0.1.42

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 (482) hide show
  1. package/README.md +27 -12
  2. package/agent-runtime/agentThread.ts +222 -0
  3. package/agent-runtime/agentThreadAdmission.ts +74 -0
  4. package/agent-runtime/dialogWritePlan.ts +42 -0
  5. package/agent-runtime/hostAdapter.ts +1 -0
  6. package/agent-runtime/hybridRecordStore.ts +5 -3
  7. package/agent-runtime/index.ts +43 -0
  8. package/agent-runtime/localLoop.ts +31 -2
  9. package/agent-runtime/localToolPolicy.ts +1 -0
  10. package/agent-runtime/localWorkspaceTools.ts +1258 -78
  11. package/agent-runtime/noloWorkspaceTools.ts +20 -1
  12. package/agent-runtime/runtimeToolPolicy.ts +1 -5
  13. package/agent-runtime/runtimeToolSurface.ts +1 -0
  14. package/agentAliases.ts +29 -9
  15. package/agentInternalCommandEntries.ts +11 -3
  16. package/agentMachineCommands.ts +1 -0
  17. package/agentRecordCommands.ts +2 -2
  18. package/agentRecordHelpers.ts +59 -6
  19. package/agentRunCommand.ts +84 -19
  20. package/ai/agent/_executeModel.ts +146 -0
  21. package/ai/agent/agentSlice.ts +556 -1
  22. package/ai/agent/appWorkingMemory.ts +126 -0
  23. package/ai/agent/buildEditingContext.ts +378 -0
  24. package/ai/agent/buildSystemPrompt.ts +599 -0
  25. package/ai/agent/canvasEditingContext.ts +49 -0
  26. package/ai/agent/cleanAgentMessages.ts +140 -0
  27. package/ai/agent/cliChatClient.ts +153 -0
  28. package/ai/agent/cliExecutor.ts +264 -46
  29. package/ai/agent/contextCompiler.ts +107 -0
  30. package/ai/agent/contextLayerContract.ts +44 -0
  31. package/ai/agent/createAgentSchema.ts +272 -0
  32. package/ai/agent/currentTimeContext.ts +65 -0
  33. package/ai/agent/executeToolCall.ts +58 -0
  34. package/ai/agent/fetchAgentContexts.ts +42 -0
  35. package/ai/agent/generatePrompt.ts +3 -0
  36. package/ai/agent/getFullChatContextKeys.ts +168 -0
  37. package/ai/agent/guidedCreation/capabilities.ts +84 -0
  38. package/ai/agent/guidedCreation/types.ts +38 -0
  39. package/ai/agent/isLiveAudioOnlyAgent.ts +26 -0
  40. package/ai/agent/liveAudioModel.ts +2 -0
  41. package/ai/agent/pageBuilderHandoffRules.ts +75 -0
  42. package/ai/agent/persistMessageWithFixedId.ts +37 -0
  43. package/ai/agent/planSlice.ts +259 -0
  44. package/ai/agent/referenceUtils.ts +229 -0
  45. package/ai/agent/runAgentBackground.ts +310 -0
  46. package/ai/agent/runAgentClientLoop.ts +164 -0
  47. package/ai/agent/runtimeGuidance.ts +116 -0
  48. package/ai/agent/serverOrigin.ts +7 -0
  49. package/ai/agent/startParallelAgentStreams.ts +424 -0
  50. package/ai/agent/startupProtocol.ts +53 -0
  51. package/ai/agent/streamAgentChatTurn.ts +2135 -0
  52. package/ai/agent/streamAgentChatTurnUtils.ts +923 -0
  53. package/ai/agent/toolFailureGuard.ts +99 -0
  54. package/ai/agent/types.ts +73 -0
  55. package/ai/agent/utils/imageOutput.ts +37 -0
  56. package/ai/agent/utils/publicImageAgentMode.ts +26 -0
  57. package/ai/ai.locale.ts +1165 -0
  58. package/ai/chat/accumulateToolCallChunks.ts +126 -0
  59. package/ai/chat/fetchUtils.ts +143 -0
  60. package/ai/chat/inlineImageUrlsForCustomProvider.ts +122 -0
  61. package/ai/chat/parseApiError.ts +67 -0
  62. package/ai/chat/parseMultilineSSE.ts +95 -0
  63. package/ai/chat/sendOpenAICompletionsRequest.ts +921 -0
  64. package/ai/chat/sendOpenAIResponseRequest.ts +720 -0
  65. package/ai/chat/serverProxyRetry.ts +102 -0
  66. package/ai/chat/shouldUseServerProxy.ts +18 -0
  67. package/ai/chat/streamRetry.ts +46 -0
  68. package/ai/chat/updateTotalUsage.ts +89 -0
  69. package/ai/context/buildReferenceContext.ts +437 -0
  70. package/ai/context/retention.ts +165 -0
  71. package/ai/context/tokenUtils.ts +78 -0
  72. package/ai/llm/agentCapabilities.ts +74 -0
  73. package/ai/llm/deepinfra.ts +79 -0
  74. package/ai/llm/fireworks.ts +68 -0
  75. package/ai/llm/generateRequestBody.ts +165 -0
  76. package/ai/llm/getModelContextWindow.ts +93 -0
  77. package/ai/llm/getPricing.ts +252 -0
  78. package/ai/llm/imagePricing.ts +66 -0
  79. package/ai/llm/isResponseAPIModel.ts +13 -0
  80. package/ai/llm/kimi.ts +22 -0
  81. package/ai/llm/mimo.ts +99 -0
  82. package/ai/llm/mistral.ts +21 -0
  83. package/ai/llm/models.ts +45 -0
  84. package/ai/llm/openrouterModels.ts +31 -0
  85. package/ai/llm/providers.ts +313 -0
  86. package/ai/llm/reasoningModels.ts +27 -0
  87. package/ai/llm/types.ts +82 -0
  88. package/ai/llm/usageRequestOptions.ts +59 -0
  89. package/ai/memory/policy.ts +49 -0
  90. package/ai/memory/queryShared.ts +167 -0
  91. package/ai/memory/recentRelationshipRecap.ts +251 -0
  92. package/ai/memory/remember.ts +111 -0
  93. package/ai/memory/scope.ts +74 -0
  94. package/ai/memory/store.ts +20 -0
  95. package/ai/memory/storeShared.ts +76 -0
  96. package/ai/memory/types.ts +52 -0
  97. package/ai/memory/understanding.ts +341 -0
  98. package/ai/memory/understandingGreeting.ts +264 -0
  99. package/ai/policy/personalizationDialog.ts +333 -0
  100. package/ai/policy/runtimePolicy.ts +526 -0
  101. package/ai/policy/selfUpdateFields.ts +48 -0
  102. package/ai/policy/types.ts +64 -0
  103. package/ai/skills/referenceRuntime.ts +274 -0
  104. package/ai/skills/skillDiagnostics.ts +251 -0
  105. package/ai/skills/skillDocBuilder.ts +139 -0
  106. package/ai/skills/skillSummaryMarker.ts +26 -0
  107. package/ai/token/calculatePrice.ts +576 -0
  108. package/ai/token/missingUsageEstimate.ts +42 -0
  109. package/ai/token/normalizeUsage.ts +124 -0
  110. package/ai/token/openaiImageGenerationUsage.ts +56 -0
  111. package/ai/token/prepareTokenUsageData.ts +93 -0
  112. package/ai/token/resolveBillingTarget.ts +52 -0
  113. package/ai/token/saveTokenRecord.ts +53 -0
  114. package/ai/token/types.ts +103 -0
  115. package/ai/tools/agent/agentTools.ts +214 -0
  116. package/ai/tools/agent/agentUpdateShared.ts +311 -0
  117. package/ai/tools/agent/callAgentTool.ts +139 -0
  118. package/ai/tools/agent/createAgentTool.ts +512 -0
  119. package/ai/tools/agent/createDialogTool.ts +69 -0
  120. package/ai/tools/agent/createSkillAgentTool.ts +62 -0
  121. package/ai/tools/agent/parallelBudget.ts +221 -0
  122. package/ai/tools/agent/prepareAgentDraftTool.ts +159 -0
  123. package/ai/tools/agent/presets/appBuilderPreset.ts +154 -0
  124. package/ai/tools/agent/runLlmTool.ts +96 -0
  125. package/ai/tools/agent/runStreamingAgentTool.ts +73 -0
  126. package/ai/tools/agent/skillAgentArgs.ts +106 -0
  127. package/ai/tools/agent/startAgentDialogTool.ts +54 -0
  128. package/ai/tools/agent/streamParallelAgentsTool.ts +123 -0
  129. package/ai/tools/agent/updateAgentTool.ts +96 -0
  130. package/ai/tools/agent/updateSelfTool.ts +113 -0
  131. package/ai/tools/amazonProductScraperTool.ts +86 -0
  132. package/ai/tools/apifyActorClient.ts +45 -0
  133. package/ai/tools/appEditGuard.ts +372 -0
  134. package/ai/tools/appReadSnapshot.ts +153 -0
  135. package/ai/tools/appTools.ts +1549 -0
  136. package/ai/tools/applyEditTool.ts +259 -0
  137. package/ai/tools/applyLineEditsTool.ts +315 -0
  138. package/ai/tools/browserTools/click.ts +33 -0
  139. package/ai/tools/browserTools/closeSession.ts +29 -0
  140. package/ai/tools/browserTools/common.ts +27 -0
  141. package/ai/tools/browserTools/openSession.ts +48 -0
  142. package/ai/tools/browserTools/readContent.ts +38 -0
  143. package/ai/tools/browserTools/selectOption.ts +46 -0
  144. package/ai/tools/browserTools/typeText.ts +42 -0
  145. package/ai/tools/category/createCategoryTool.ts +66 -0
  146. package/ai/tools/category/queryContentsByCategoryTool.ts +69 -0
  147. package/ai/tools/category/updateContentCategoryTool.ts +75 -0
  148. package/ai/tools/cfBrowserTools.ts +319 -0
  149. package/ai/tools/cfSpeechToTextTool.ts +49 -0
  150. package/ai/tools/checkEnvTool.ts +102 -0
  151. package/ai/tools/cloudflareCrawlTool.ts +289 -0
  152. package/ai/tools/codeSearchTool.ts +123 -0
  153. package/ai/tools/codeTools.ts +101 -0
  154. package/ai/tools/convertMarxistsBookTool.ts +103 -0
  155. package/ai/tools/createDocTool.ts +132 -0
  156. package/ai/tools/createSkillDocTool.ts +155 -0
  157. package/ai/tools/createWorkflowTool.ts +154 -0
  158. package/ai/tools/delayTool.ts +31 -0
  159. package/ai/tools/deleteSpacesTool.ts +325 -0
  160. package/ai/tools/deleteSpacesToolModel.ts +159 -0
  161. package/ai/tools/devReloadUtils.ts +29 -0
  162. package/ai/tools/dialogMessageSearch.ts +137 -0
  163. package/ai/tools/doctorSkillTool.ts +72 -0
  164. package/ai/tools/ecommerceScraperTool.ts +86 -0
  165. package/ai/tools/emailTools.ts +549 -0
  166. package/ai/tools/evalSkillTool.ts +92 -0
  167. package/ai/tools/exaSearchTool.ts +63 -0
  168. package/ai/tools/execShellTool.ts +266 -0
  169. package/ai/tools/executeSqlTool.ts +192 -0
  170. package/ai/tools/fetchWebpageSupport.ts +333 -0
  171. package/ai/tools/fetchWebpageTool.ts +97 -0
  172. package/ai/tools/geminiImagePreviewTool.ts +386 -0
  173. package/ai/tools/generateDocxTool.ts +215 -0
  174. package/ai/tools/googleSearchScraperTool.ts +106 -0
  175. package/ai/tools/importDataTool.ts +133 -0
  176. package/ai/tools/importSkillTool.ts +162 -0
  177. package/ai/tools/index.ts +2290 -0
  178. package/ai/tools/jdProductScraperTool.ts +821 -0
  179. package/ai/tools/listUserSpacesTool.ts +113 -0
  180. package/ai/tools/localFilesTool.ts +276 -0
  181. package/ai/tools/marxistsOfflineBook.ts +253 -0
  182. package/ai/tools/modelUsageTools.ts +206 -0
  183. package/ai/tools/noloWorkspaceReadTools.ts +467 -0
  184. package/ai/tools/olmOcrTool.ts +33 -0
  185. package/ai/tools/openaiImageTool.ts +267 -0
  186. package/ai/tools/prepareTools.ts +193 -0
  187. package/ai/tools/readDocTool.ts +88 -0
  188. package/ai/tools/readFileTool.ts +214 -0
  189. package/ai/tools/readTool.ts +194 -0
  190. package/ai/tools/readXPostTool.ts +229 -0
  191. package/ai/tools/readXhsProfileTool.ts +638 -0
  192. package/ai/tools/rememberMemoryTool.ts +84 -0
  193. package/ai/tools/remotionVideoTool.ts +151 -0
  194. package/ai/tools/searchDialogMessagesTool.ts +222 -0
  195. package/ai/tools/searchWorkspaceTool.ts +259 -0
  196. package/ai/tools/skillFollowup.ts +86 -0
  197. package/ai/tools/surfWeatherTool.ts +169 -0
  198. package/ai/tools/table/addTableRowTool.ts +217 -0
  199. package/ai/tools/table/createTableTool.ts +326 -0
  200. package/ai/tools/table/rowTools.ts +386 -0
  201. package/ai/tools/table/schemaTools.ts +244 -0
  202. package/ai/tools/table/shareTableTool.ts +148 -0
  203. package/ai/tools/table/toolShared.ts +129 -0
  204. package/ai/tools/taobaoTmallProductScraperTool.ts +49 -0
  205. package/ai/tools/toolApiClient.ts +279 -0
  206. package/ai/tools/toolPacks.ts +19 -0
  207. package/ai/tools/toolResultError.ts +42 -0
  208. package/ai/tools/toolRunSlice.ts +303 -0
  209. package/ai/tools/toolSchemaCompatibility.ts +53 -0
  210. package/ai/tools/uiAskChoiceTool.ts +104 -0
  211. package/ai/tools/updateContentTitleTool.ts +84 -0
  212. package/ai/tools/updateDocTool.ts +105 -0
  213. package/ai/tools/updateUserPreferenceProfileTool.ts +153 -0
  214. package/ai/tools/wereadGatewayTool.ts +152 -0
  215. package/ai/tools/whisperTool.ts +76 -0
  216. package/ai/tools/writeFileTool.ts +213 -0
  217. package/ai/tools/youtubeScraperTool.ts +116 -0
  218. package/ai/tools/ziweiChartTool.ts +678 -0
  219. package/ai/types.ts +58 -0
  220. package/ai/workflow/workflowExecutor.ts +323 -0
  221. package/ai/workflow/workflowSlice.ts +73 -0
  222. package/ai/workflow/workflowTypes.ts +106 -0
  223. package/app/actions/syncAppRecord.ts +73 -0
  224. package/app/constants/animationSets.ts +21 -0
  225. package/app/constants/appEditor.ts +99 -0
  226. package/app/favorite/deletedFavoriteProjection.ts +31 -0
  227. package/app/favorite/favoriteSlice.ts +690 -0
  228. package/app/favorite/type.ts +43 -0
  229. package/app/hooks/deleteDbKey.ts +254 -0
  230. package/app/i18n/client.ts +13 -0
  231. package/app/i18n/i18n.base.ts +14 -0
  232. package/app/i18n/i18n.config.ts +77 -0
  233. package/app/i18n/index.ts +15 -0
  234. package/app/i18n/mapLanguage.ts +11 -0
  235. package/app/i18n/translations/appBuilder.locale.ts +453 -0
  236. package/app/i18n/translations/error.locale.ts +246 -0
  237. package/app/i18n/translations/interface.locale.ts +2206 -0
  238. package/app/i18n/translations/pricing.locale.ts +397 -0
  239. package/app/i18n/translations/privacy.locale.ts +168 -0
  240. package/app/i18n/translations/seo.locale.ts +129 -0
  241. package/app/i18n/translations/terms.locale.ts +124 -0
  242. package/app/i18n/types.ts +6 -0
  243. package/app/notifications/model.ts +77 -0
  244. package/app/notifications/notificationSlice.ts +141 -0
  245. package/app/reducer.ts +36 -0
  246. package/app/settings/dbActionThunks.ts +34 -0
  247. package/app/settings/defaultSpacePreference.ts +87 -0
  248. package/app/settings/settingSlice.tsx +1212 -0
  249. package/app/settings/settingsRecord.ts +8 -0
  250. package/app/stateViews/runtime.ts +90 -0
  251. package/app/store.ts +55 -0
  252. package/app/theme/colors.ts +280 -0
  253. package/app/theme/fontPreference.ts +77 -0
  254. package/app/theme/theme.config.ts +120 -0
  255. package/app/theme/themeModeBootstrap.ts +123 -0
  256. package/app/types/appSummary.ts +118 -0
  257. package/app/types.ts +358 -0
  258. package/app/utils/appKeys.ts +55 -0
  259. package/app/utils/async.ts +28 -0
  260. package/app/utils/desktopAgentRuntimeTurnClient.ts +75 -0
  261. package/app/utils/env.ts +17 -0
  262. package/app/utils/fileUtils.ts +229 -0
  263. package/app/utils/imageUtils.ts +274 -0
  264. package/app/utils/myContentItems.ts +289 -0
  265. package/app/utils/retryAfter.ts +36 -0
  266. package/app/utils/retryFetch.ts +61 -0
  267. package/app/utils/toast.ts +3 -0
  268. package/auth/action/signUpAction.ts +227 -0
  269. package/auth/adminPermissions.ts +78 -0
  270. package/auth/authSlice.ts +531 -0
  271. package/auth/client/loginRequest.ts +14 -0
  272. package/auth/resetAuthScopedClientState.ts +27 -0
  273. package/auth/routes.ts +183 -0
  274. package/auth/token.ts +63 -0
  275. package/auth/types.ts +40 -0
  276. package/chat/chat.locale.ts +817 -0
  277. package/chat/dialog/actions/addCybotAction.ts +52 -0
  278. package/chat/dialog/actions/addReferenceKeysAction.ts +62 -0
  279. package/chat/dialog/actions/builtinDialogLlm.ts +35 -0
  280. package/chat/dialog/actions/cleanupCliSession.ts +40 -0
  281. package/chat/dialog/actions/createDialogAction.ts +379 -0
  282. package/chat/dialog/actions/createScheduledTaskAction.ts +78 -0
  283. package/chat/dialog/actions/handleSendMessageAction.ts +202 -0
  284. package/chat/dialog/actions/handleSendMessageResolver.ts +27 -0
  285. package/chat/dialog/actions/removeCybotAction.ts +6 -0
  286. package/chat/dialog/actions/removeDialogAgentAction.ts +44 -0
  287. package/chat/dialog/actions/replacePrimaryCybotAction.ts +6 -0
  288. package/chat/dialog/actions/setPrimaryDialogAgentAction.ts +52 -0
  289. package/chat/dialog/actions/updateDialogSummaryAction.ts +430 -0
  290. package/chat/dialog/actions/updateDialogTitleAction.ts +151 -0
  291. package/chat/dialog/actions/updateDialogTitlePolicy.ts +30 -0
  292. package/chat/dialog/actions/updateTokensAction.ts +233 -0
  293. package/chat/dialog/dialogAgents.ts +72 -0
  294. package/chat/dialog/dialogAttachmentCleanup.ts +135 -0
  295. package/chat/dialog/dialogSlice.ts +985 -0
  296. package/chat/dialog/dialogTitle.ts +81 -0
  297. package/chat/dialog/dialogTokenStats.ts +12 -0
  298. package/chat/dialog/dialogUrl.ts +6 -0
  299. package/chat/dialog/goal.ts +108 -0
  300. package/chat/dialog/objectAssistantRegistry.ts +286 -0
  301. package/chat/dialog/schedule.ts +17 -0
  302. package/chat/messages/activityCompletion.ts +97 -0
  303. package/chat/messages/fetchAndCacheMessages.ts +119 -0
  304. package/chat/messages/fetchConvMsgs.ts +51 -0
  305. package/chat/messages/fileUrl.ts +13 -0
  306. package/chat/messages/imagePayloadPersistence.ts +22 -0
  307. package/chat/messages/messageAgent.ts +8 -0
  308. package/chat/messages/messageContent.ts +203 -0
  309. package/chat/messages/messageContract.ts +88 -0
  310. package/chat/messages/messageSlice.ts +1386 -0
  311. package/chat/messages/toolThunks.ts +646 -0
  312. package/chat/messages/types.ts +8 -1
  313. package/chat/messages/web/toolDisplayName.ts +686 -0
  314. package/cli/agentAliases.ts +29 -9
  315. package/cli/agentInternalCommandEntries.ts +11 -3
  316. package/cli/agentMachineCommands.ts +1 -0
  317. package/cli/agentRecordCommands.ts +2 -2
  318. package/cli/agentRecordHelpers.ts +59 -6
  319. package/cli/agentRunCommand.ts +84 -19
  320. package/cli/client/agentRun.ts +92 -261
  321. package/cli/client/localRuntimeAdapter.ts +292 -50
  322. package/cli/commandRegistry.ts +7 -4
  323. package/cli/dialogAttachmentCleanup.ts +151 -0
  324. package/cli/dialogCommands.ts +163 -61
  325. package/cli/dialogInternalCommandEntries.ts +1 -1
  326. package/cli/docCreateCommands.ts +345 -0
  327. package/cli/docInternalCommandEntries.ts +11 -0
  328. package/cli/docPageHelpers.ts +80 -0
  329. package/cli/docSkillHelpers.ts +67 -0
  330. package/cli/docSpaceHelpers.ts +46 -0
  331. package/cli/internalCommandEntries.ts +4 -0
  332. package/cli/machineCommands.ts +18 -34
  333. package/cli/memoryCommands.ts +253 -0
  334. package/cli/memoryInternalCommandEntries.ts +9 -0
  335. package/cli/qoderUsageProbe.ts +252 -0
  336. package/cli/scriptCommandEntries.ts +0 -3
  337. package/cli/secretScan.ts +31 -0
  338. package/cli/tableCommands.ts +248 -13
  339. package/cli/workflowInternalCommandEntries.ts +2 -3
  340. package/client/agentRun.test.ts +119 -83
  341. package/client/agentRun.ts +92 -261
  342. package/client/localRuntimeAdapter.test.ts +894 -32
  343. package/client/localRuntimeAdapter.ts +292 -50
  344. package/commandRegistry.ts +7 -4
  345. package/connector-experimental/capabilities.ts +10 -9
  346. package/core/builtinAgents.ts +209 -0
  347. package/core/config.ts +15 -0
  348. package/core/crypto.ts +51 -0
  349. package/core/generateKeyPairFromSeedV1.ts +15 -0
  350. package/core/generateMainKey.ts +22 -0
  351. package/core/init.ts +41 -0
  352. package/core/localOrigins.ts +8 -0
  353. package/core/password.ts +13 -0
  354. package/core/prefix.ts +23 -0
  355. package/create/editor/transforms/fromMarkdown/index.ts +260 -0
  356. package/create/editor/transforms/fromMarkdown/inline.ts +285 -0
  357. package/create/editor/transforms/fromMarkdown/table.ts +130 -0
  358. package/create/editor/transforms/markdownToSlate.ts +24 -0
  359. package/create/editor/transforms/slateToRenderMarkdown.ts +218 -0
  360. package/create/editor/transforms/slateToSimplifiedMarkdown.ts +224 -0
  361. package/create/editor/transforms/slateToText.ts +33 -0
  362. package/create/editor/utils/slateUtils.ts +233 -0
  363. package/create/space/addSpaceAction.ts +193 -0
  364. package/create/space/category/categoryActions.ts +427 -0
  365. package/create/space/changeSpaceAction.ts +36 -0
  366. package/create/space/constants.ts +8 -0
  367. package/create/space/content/addContentAction.ts +116 -0
  368. package/create/space/content/contentThunks.ts +90 -0
  369. package/create/space/content/deleteContentFromSpaceAction.ts +187 -0
  370. package/create/space/content/deleteMultipleContentAction.ts +112 -0
  371. package/create/space/content/moveContentAction.ts +285 -0
  372. package/create/space/content/updateContentCategoryAction.ts +154 -0
  373. package/create/space/content/updateContentTitleAction.ts +151 -0
  374. package/create/space/content/uploadAndAddFileToSpaceAction.ts +98 -0
  375. package/create/space/contentKeyUtils.ts +117 -0
  376. package/create/space/deleteSpaceAction.ts +276 -0
  377. package/create/space/fetchSpaceAction.ts +70 -0
  378. package/create/space/fetchSpaceSidebarStateAction.ts +26 -0
  379. package/create/space/loadDefaultSpaceAction.ts +57 -0
  380. package/create/space/member/addMemberAction.ts +79 -0
  381. package/create/space/member/fetchUserSpaceMembershipsAction.ts +386 -0
  382. package/create/space/member/memberThunks.ts +47 -0
  383. package/create/space/member/removeMemberAction.ts +67 -0
  384. package/create/space/resolvePreferredSpaceId.ts +113 -0
  385. package/create/space/sidebarVisibleTypes.ts +260 -0
  386. package/create/space/space.locale.ts +1087 -0
  387. package/create/space/spaceAccess.ts +182 -0
  388. package/create/space/spaceCollapsedState.ts +54 -0
  389. package/create/space/spaceKeys.ts +65 -0
  390. package/create/space/spaceSlice.ts +328 -0
  391. package/create/space/spaceThunks.ts +410 -0
  392. package/create/space/types.ts +27 -0
  393. package/create/space/updateSpaceAction.ts +107 -0
  394. package/create/space/utils/permissions.ts +47 -0
  395. package/create/types.ts +21 -0
  396. package/database/actions/agentReadResolution.ts +33 -0
  397. package/database/actions/common.ts +243 -0
  398. package/database/actions/deleteFile.ts +40 -0
  399. package/database/actions/fileContent.ts +125 -0
  400. package/database/actions/patch.ts +155 -0
  401. package/database/actions/read.ts +358 -0
  402. package/database/actions/readAndWait.ts +260 -0
  403. package/database/actions/readRequestManager.ts +120 -0
  404. package/database/actions/readResolution.ts +125 -0
  405. package/database/actions/remove.ts +94 -0
  406. package/database/actions/replication.ts +477 -0
  407. package/database/actions/upload.ts +186 -0
  408. package/database/actions/upsert.ts +56 -0
  409. package/database/actions/write.ts +146 -0
  410. package/database/authority/ownerKey.ts +80 -0
  411. package/database/authority/recordAuthority.ts +67 -0
  412. package/database/authority/userAuthorityRegistry.ts +54 -0
  413. package/database/client/fetchUserData.ts +61 -0
  414. package/database/dbActionThunks.ts +1 -0
  415. package/database/dbSlice.ts +149 -0
  416. package/database/fileRing.ts +51 -0
  417. package/database/fileStorage.ts +232 -0
  418. package/database/fileUrl.ts +34 -0
  419. package/database/keys.ts +767 -0
  420. package/database/queryPrefixes.ts +14 -0
  421. package/database/requests.ts +443 -0
  422. package/database/runtimeServerContext.ts +54 -0
  423. package/database/tenantPlacement.ts +57 -0
  424. package/database/userPreferenceRegister.ts +131 -0
  425. package/database/utils/ulid.ts +1 -0
  426. package/dialogAttachmentCleanup.ts +151 -0
  427. package/dialogCommands.ts +163 -61
  428. package/dialogInternalCommandEntries.ts +1 -1
  429. package/docCreateCommands.ts +345 -0
  430. package/docInternalCommandEntries.ts +11 -0
  431. package/docPageHelpers.ts +80 -0
  432. package/docSkillHelpers.ts +67 -0
  433. package/docSpaceHelpers.ts +46 -0
  434. package/integrations/anthropic/anthropicModels.ts +47 -0
  435. package/integrations/deepseek/models.ts +37 -0
  436. package/integrations/google/models.ts +341 -0
  437. package/integrations/openai/chatCompletionStreamMode.ts +10 -0
  438. package/integrations/openai/filterAndCleanMessages.ts +284 -0
  439. package/integrations/openai/flexTier.ts +102 -0
  440. package/integrations/openai/generateOpenAIRequestBody.ts +271 -0
  441. package/integrations/openai/generateResponseRequestBody.ts +77 -0
  442. package/integrations/openai/models.ts +271 -0
  443. package/integrations/openai/providerBodyCompatibility.ts +23 -0
  444. package/integrations/openai/responsesHelpers.ts +297 -0
  445. package/integrations/x-reader/types.ts +109 -0
  446. package/integrations/xai/models.ts +13 -0
  447. package/integrations/xhs-reader/redaction.ts +68 -0
  448. package/integrations/xhs-reader/types.ts +277 -0
  449. package/integrations/xhs-reader/url.ts +80 -0
  450. package/internalCommandEntries.ts +4 -0
  451. package/machineCommands.ts +18 -34
  452. package/memoryCommands.ts +253 -0
  453. package/memoryInternalCommandEntries.ts +9 -0
  454. package/package.json +454 -9
  455. package/qoderUsageProbe.ts +252 -0
  456. package/render/contentIcon/types.ts +167 -0
  457. package/render/page/createPageAction.ts +183 -0
  458. package/render/page/docSlice.ts +495 -0
  459. package/render/page/types.ts +19 -0
  460. package/render/table/createTableAction.ts +274 -0
  461. package/render/table/deleteTableAction.ts +193 -0
  462. package/render/table/fetchAndCacheTableRows.ts +174 -0
  463. package/render/table/tableSlice.ts +1167 -0
  464. package/render/table/toolValueUtils.ts +363 -0
  465. package/render/table/types.ts +262 -0
  466. package/render/table/utils/tableSerialization.ts +50 -0
  467. package/scriptCommandEntries.ts +0 -3
  468. package/secretScan.ts +31 -0
  469. package/server/handlers/agentRun/types.ts +105 -0
  470. package/share/action.ts +225 -0
  471. package/share/helpers.ts +302 -0
  472. package/share/keys.ts +243 -0
  473. package/share/publicSharePolicy.ts +27 -0
  474. package/share/shareSlice.ts +53 -0
  475. package/share/types.ts +100 -0
  476. package/tableCommands.ts +248 -13
  477. package/workflowInternalCommandEntries.ts +2 -3
  478. package/ai/tools/agent/taskRunTool.ts +0 -112
  479. package/cli/client/taskRunPrompt.ts +0 -27
  480. package/cli/taskRunCommand.ts +0 -265
  481. package/client/taskRunPrompt.ts +0 -27
  482. package/taskRunCommand.ts +0 -265
@@ -0,0 +1,2290 @@
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 { canonicalizeToolName } from "./toolNameAliases";
26
+ import {
27
+ completeDialogGoalFunc,
28
+ completeDialogGoalFunctionSchema,
29
+ createDialogGoalFunc,
30
+ createDialogGoalFunctionSchema,
31
+ createScheduledTaskFunc,
32
+ createScheduledTaskFunctionSchema,
33
+ getDialogGoalFunc,
34
+ getDialogGoalFunctionSchema,
35
+ notifyUserFunc,
36
+ notifyUserFunctionSchema,
37
+ queryModelUsageFunc,
38
+ queryModelUsageFunctionSchema,
39
+ } from "./modelUsageTools";
40
+
41
+ // Agent 相关工具的 schema(用于 patch enum),具体定义移到 agentTools.ts
42
+ import { createAgentToolFunctionSchema } from "./agent/createAgentTool";
43
+ import { updateAgentToolFunctionSchema } from "./agent/updateAgentTool";
44
+
45
+ // 内容管理
46
+ import { createDocFunctionSchema, createDocFunc } from "./createDocTool";
47
+ import {
48
+ createSkillDocFunctionSchema,
49
+ createSkillDocFunc,
50
+ } from "./createSkillDocTool";
51
+ import { doctorSkillFunctionSchema, doctorSkillFunc } from "./doctorSkillTool";
52
+ import { evalSkillFunctionSchema, evalSkillFunc } from "./evalSkillTool";
53
+ import { importSkillFunctionSchema, importSkillFunc } from "./importSkillTool";
54
+ import {
55
+ readDocFunctionSchema,
56
+ readDocFunc,
57
+ readPageFunctionSchema,
58
+ readPageFunc,
59
+ } from "./readDocTool";
60
+
61
+ // 分类相关工具集中在 ./category 文件夹
62
+ import {
63
+ createCategoryFunctionSchema,
64
+ createCategoryFunc,
65
+ } from "./category/createCategoryTool";
66
+ import {
67
+ updateContentCategoryFunctionSchema,
68
+ updateContentCategoryFunc,
69
+ } from "./category/updateContentCategoryTool";
70
+ import {
71
+ queryContentsByCategoryFunctionSchema,
72
+ queryContentsByCategoryFunc,
73
+ } from "./category/queryContentsByCategoryTool";
74
+
75
+ // 数据操作
76
+ import { importDataFunctionSchema, importDataFunc } from "./importDataTool";
77
+ import { executeSqlFunctionSchema, executeSqlFunc } from "./executeSqlTool";
78
+ import { readFunctionSchema, readFunc } from "./readTool";
79
+ import {
80
+ listUserSpacesFunctionSchema,
81
+ listUserSpacesFunc,
82
+ } from "./listUserSpacesTool";
83
+ import {
84
+ cliDoctorFunc,
85
+ cliDoctorFunctionSchema,
86
+ cliWhoamiFunc,
87
+ cliWhoamiFunctionSchema,
88
+ listAgentsFunc,
89
+ listAgentsFunctionSchema,
90
+ listDialogsFunc,
91
+ listDialogsFunctionSchema,
92
+ listSpacesFunc,
93
+ listSpacesFunctionSchema,
94
+ readAgentFunc,
95
+ readAgentFunctionSchema,
96
+ readDialogFunc,
97
+ readDialogFunctionSchema,
98
+ readSkillDocFunc,
99
+ readSkillDocFunctionSchema,
100
+ readSpaceFunc,
101
+ readSpaceFunctionSchema,
102
+ } from "./noloWorkspaceReadTools";
103
+ import {
104
+ deleteSpacesFunctionSchema,
105
+ deleteSpacesFunc,
106
+ deleteSpacesPreviewFunc,
107
+ } from "./deleteSpacesTool";
108
+ import {
109
+ executeApprovedLocalFileChangesFunc,
110
+ executeApprovedLocalFileChangesFunctionSchema,
111
+ listLocalRootsFunc,
112
+ listLocalRootsFunctionSchema,
113
+ listLocalFilesFunc,
114
+ listLocalFilesFunctionSchema,
115
+ proposeLocalFileChangesFunc,
116
+ proposeLocalFileChangesFunctionSchema,
117
+ proposeLocalFileChangesPreviewFunc,
118
+ readLocalFileFunc,
119
+ readLocalFileFunctionSchema,
120
+ requestLocalFolderAccessFunc,
121
+ requestLocalFolderAccessFunctionSchema,
122
+ undoLocalFileChangeBatchFunc,
123
+ undoLocalFileChangeBatchFunctionSchema,
124
+ } from "./localFilesTool";
125
+ import {
126
+ emailArchiveFunc,
127
+ emailArchiveFunctionSchema,
128
+ emailExtractVerificationFunc,
129
+ emailExtractVerificationFunctionSchema,
130
+ emailProvisionIdentityFunc,
131
+ emailProvisionIdentityFunctionSchema,
132
+ emailReadFunc,
133
+ emailReadFunctionSchema,
134
+ emailSearchFunc,
135
+ emailSearchFunctionSchema,
136
+ emailSendFunc,
137
+ emailSendFunctionSchema,
138
+ emailUpdateTagsFunc,
139
+ emailUpdateTagsFunctionSchema,
140
+ emailWaitForFunc,
141
+ emailWaitForFunctionSchema,
142
+ } from "./emailTools";
143
+ // ✅ 在当前表中新增一行的工具
144
+ import {
145
+ addTableRowFunctionSchema,
146
+ addTableRowFunc,
147
+ } from "./table/addTableRowTool";
148
+ import {
149
+ createTableFunctionSchema,
150
+ createTableFunc,
151
+ } from "./table/createTableTool";
152
+ import {
153
+ shareTableFunctionSchema,
154
+ shareTableFunc,
155
+ } from "./table/shareTableTool";
156
+ import {
157
+ addTableRowsFunctionSchema,
158
+ addTableRowsFunc,
159
+ deleteTableRowFunctionSchema,
160
+ deleteTableRowFunc,
161
+ deleteTableRowsFunctionSchema,
162
+ deleteTableRowsFunc,
163
+ queryTableRowsFunctionSchema,
164
+ queryTableRowsFunc,
165
+ updateTableRowFunctionSchema,
166
+ updateTableRowFunc,
167
+ updateTableRowsFunctionSchema,
168
+ updateTableRowsFunc,
169
+ } from "./table/rowTools";
170
+ import {
171
+ addTableColumnFunctionSchema,
172
+ addTableColumnFunc,
173
+ deleteTableColumnFunctionSchema,
174
+ deleteTableColumnFunc,
175
+ renameTableColumnFunctionSchema,
176
+ renameTableColumnFunc,
177
+ renameTableColumnLabelFunctionSchema,
178
+ renameTableColumnLabelFunc,
179
+ renameTableFunctionSchema,
180
+ renameTableFunc,
181
+ } from "./table/schemaTools";
182
+
183
+ // 网络与智能
184
+ import {
185
+ fetchWebpageFunctionSchema,
186
+ fetchWebpageFunc,
187
+ } from "./fetchWebpageTool";
188
+ import {
189
+ convertMarxistsBookToOfflineHtmlFunctionSchema,
190
+ convertMarxistsBookToOfflineHtmlFunc,
191
+ } from "./convertMarxistsBookTool";
192
+ import {
193
+ readXPostFunctionSchema,
194
+ readXPostFunc,
195
+ } from "./readXPostTool";
196
+ import {
197
+ readXhsProfileFunctionSchema,
198
+ readXhsProfileFunc,
199
+ } from "./readXhsProfileTool";
200
+ export { TOOL_PACKS } from "./toolPacks";
201
+ import { TOOL_PACKS } from "./toolPacks";
202
+ import {
203
+ surfWeatherFunctionSchema,
204
+ surfWeatherFunc,
205
+ } from "./surfWeatherTool";
206
+ import {
207
+ wereadGatewayFunctionSchema,
208
+ wereadGatewayFunc,
209
+ } from "./wereadGatewayTool";
210
+
211
+ import {
212
+ browser_closeSession_Schema,
213
+ browser_closeSession_Func,
214
+ } from "./browserTools/closeSession";
215
+ import {
216
+ browser_openSession_Schema,
217
+ browser_openSession_Func,
218
+ } from "./browserTools/openSession";
219
+ import {
220
+ browser_selectOption_Schema,
221
+ browser_selectOption_Func,
222
+ } from "./browserTools/selectOption";
223
+ import {
224
+ browser_click_Schema,
225
+ browser_click_Func,
226
+ } from "./browserTools/click";
227
+ import {
228
+ browser_typeText_Schema,
229
+ browser_typeText_Func,
230
+ } from "./browserTools/typeText";
231
+ import {
232
+ browser_readContent_Schema,
233
+ browser_readContent_Func,
234
+ } from "./browserTools/readContent";
235
+ import {
236
+ exaSearchSchema,
237
+ exaSearchFunc,
238
+ } from "./exaSearchTool";
239
+ import {
240
+ olmOcrSchema,
241
+ olmOcrFunc,
242
+ } from "./olmOcrTool";
243
+ import {
244
+ whisperTurboSchema,
245
+ whisperTurboFunc,
246
+ whisperV3Schema,
247
+ whisperV3Func,
248
+ } from "./whisperTool";
249
+
250
+
251
+
252
+
253
+ // ✅ generateDocx 工具(前端生成并下载 DOCX)
254
+ import {
255
+ generateDocxFunctionSchema,
256
+ generateDocxFunc,
257
+ } from "./generateDocxTool";
258
+
259
+ // ✅ Google Search Scraper (Apify)
260
+ import {
261
+ googleSearchScraperFunctionSchema,
262
+ googleSearchScraperFunc,
263
+ } from "./googleSearchScraperTool";
264
+
265
+ // ✅ Cloudflare Browser Rendering 爬取工具
266
+ import {
267
+ cloudflareCrawlFunctionSchema,
268
+ cloudflareCrawlFunc,
269
+ cloudflareCrawlStatusFunctionSchema,
270
+ cloudflareCrawlStatusFunc,
271
+ } from "./cloudflareCrawlTool";
272
+
273
+ // ✅ Apify / 抓取相关工具
274
+ import {
275
+ youtubeScraperFunctionSchema,
276
+ youtubeScraperFunc,
277
+ } from "./youtubeScraperTool";
278
+ import {
279
+ ecommerceScraperFunctionSchema,
280
+ ecommerceScraperFunc,
281
+ } from "./ecommerceScraperTool";
282
+ import {
283
+ amazonProductScraperFunctionSchema,
284
+ amazonProductScraperFunc,
285
+ } from "./amazonProductScraperTool";
286
+ import {
287
+ taobaoTmallProductScraperFunctionSchema,
288
+ taobaoTmallProductScraperFunc,
289
+ } from "./taobaoTmallProductScraperTool";
290
+ import {
291
+ jdProductScraperFunctionSchema,
292
+ jdProductScraperFunc,
293
+ } from "./jdProductScraperTool";
294
+
295
+ // ✅ 多模态:Gemini 图片(2.5 Flash 文生图 / 3 Pro 编辑)
296
+ import {
297
+ geminiFlashImageFunctionSchema,
298
+ geminiFlashImageFunc,
299
+ geminiProImagePreviewFunctionSchema,
300
+ geminiProImagePreviewFunc,
301
+ } from "./geminiImagePreviewTool";
302
+ import {
303
+ openAIGptImageEditFunctionSchema,
304
+ openAIGptImageEditFunc,
305
+ openAIGptImageFunctionSchema,
306
+ openAIGptImageGenerateFunctionSchema,
307
+ openAIGptImageGenerateFunc,
308
+ openAIGptImageFunc,
309
+ } from "./openaiImageTool";
310
+ import {
311
+ remotionRenderVideoFunctionSchema,
312
+ remotionRenderVideoFunc,
313
+ } from "./remotionVideoTool";
314
+ import { uiAskChoiceFunc, uiAskChoiceFunctionSchema } from "./uiAskChoiceTool";
315
+ import {
316
+ rememberMemoryFunc,
317
+ rememberMemoryFunctionSchema,
318
+ } from "./rememberMemoryTool";
319
+ import { execShellFunctionSchema, execShellFunc } from "./execShellTool";
320
+ import { checkEnvFunctionSchema, checkEnvFunc } from "./checkEnvTool";
321
+
322
+ import { agentToolDefinitions } from "./agent/agentTools";
323
+ import { codeToolDefinitions } from "./codeTools";
324
+ import {
325
+ cfScreenshotFunctionSchema,
326
+ cfScreenshotFunc,
327
+ cfGetMarkdownFunctionSchema,
328
+ cfGetMarkdownFunc,
329
+ cfGeneratePDFFunctionSchema,
330
+ cfGeneratePDFFunc,
331
+ cfExtractJSONFunctionSchema,
332
+ cfExtractJSONFunc,
333
+ } from "./cfBrowserTools";
334
+ import {
335
+ appPreflightFunctionSchema,
336
+ appPreflightFunc,
337
+ appDeployFunctionSchema,
338
+ appDeployFunc,
339
+ appListFunctionSchema,
340
+ appListFunc,
341
+ appDeleteFunctionSchema,
342
+ appDeleteFunc,
343
+ appReadFunctionSchema,
344
+ appReadFunc,
345
+ } from "./appTools";
346
+ import {
347
+ cfSpeechToTextFunctionSchema,
348
+ cfSpeechToTextFunc,
349
+ } from "./cfSpeechToTextTool";
350
+ import {
351
+ updateContentTitleTool,
352
+ updateContentTitleFunc,
353
+ } from "./updateContentTitleTool";
354
+ import {
355
+ searchAllSpacesFunc,
356
+ searchAllSpacesFunctionSchema,
357
+ searchWorkspaceFunctionSchema,
358
+ searchWorkspaceFunc,
359
+ } from "./searchWorkspaceTool";
360
+ import {
361
+ searchDialogMessagesFunc,
362
+ searchDialogMessagesFunctionSchema,
363
+ } from "./searchDialogMessagesTool";
364
+ import {
365
+ updateDocFunctionSchema,
366
+ updateDocFunc,
367
+ } from "./updateDocTool";
368
+ import {
369
+ updateUserPreferenceProfileFunctionSchema,
370
+ updateUserPreferenceProfileFunc,
371
+ } from "./updateUserPreferenceProfileTool";
372
+ import {
373
+ ziweiChartFunctionSchema,
374
+ ziweiChartFunc,
375
+ } from "./ziweiChartTool";
376
+
377
+
378
+ // ---------- 2. 定义工具规范接口 ----------
379
+
380
+ export type ToolBehavior = "orchestrator" | "data" | "action" | "answer";
381
+ export type ToolCapability =
382
+ | "knowledge_capture"
383
+ | "space_context"
384
+ | "self_evolution"
385
+ | "web_access"
386
+ | "browser_automation"
387
+ | "code_edit"
388
+ | "app_deploy"
389
+ | "general";
390
+ export type ToolRiskLevel = "low" | "medium" | "high";
391
+ export type ToolCostLevel = "low" | "medium" | "high";
392
+ export type ToolConsentMode = "auto" | "ask" | "blocked";
393
+
394
+ // 交互模式:
395
+ // - auto: 直接执行
396
+ // - confirm: 需要用户确认后才执行(危险操作)
397
+ // - authorize: 需要用户授权后才执行(权限/敏感资源)
398
+ export type ToolInteraction = "auto" | "confirm" | "authorize";
399
+
400
+ /**
401
+ * 前端分组用:
402
+ * - general: 普通
403
+ * - agent : Agent / 应用相关
404
+ * - content: 内容与页面
405
+ * - media : 多媒体(生成图片 / 生成视频等)
406
+ * - data : 数据操作
407
+ */
408
+ export type ToolUiGroup = "general" | "agent" | "content" | "media" | "data";
409
+
410
+ /**
411
+ * 分组元信息:
412
+ * - id: 分组 ID(与 ToolUiGroup 一致)
413
+ * - label: 默认中文标题(前端可直接用,也可以自己做 i18n 映射)
414
+ * - order: 分组显示顺序(从小到大)
415
+ * - fallbackCategories:
416
+ * 当某个工具没有显式指定 uiGroup 时,可以根据工具的 category 使用兜底分组。
417
+ */
418
+ export interface ToolGroupMeta {
419
+ id: ToolUiGroup;
420
+ label: string;
421
+ order: number;
422
+ fallbackCategories?: string[];
423
+ }
424
+
425
+ /**
426
+ * 单一事实来源:所有分组配置
427
+ * 以后增加 / 修改分组,只需要改这里一处。
428
+ */
429
+ export const TOOL_GROUP_META: ToolGroupMeta[] = [
430
+ {
431
+ id: "general",
432
+ label: "普通",
433
+ order: 0,
434
+ },
435
+ {
436
+ id: "agent",
437
+ label: "Agent / 应用",
438
+ order: 1,
439
+ },
440
+ {
441
+ id: "content",
442
+ label: "内容与页面",
443
+ order: 2,
444
+ fallbackCategories: ["内容管理"],
445
+ },
446
+ {
447
+ id: "media",
448
+ label: "多媒体生成",
449
+ order: 3,
450
+ fallbackCategories: ["多媒体生成"],
451
+ },
452
+ {
453
+ id: "data",
454
+ label: "数据操作",
455
+ order: 4,
456
+ fallbackCategories: ["数据操作"],
457
+ },
458
+ ];
459
+
460
+ export interface ToolDefinition {
461
+ id: string; // 唯一ID (camelCase)
462
+ schema: any; // 提供给 LLM 的函数 Schema
463
+
464
+ executor: (
465
+ args: any,
466
+ thunkApi: any,
467
+ context?: { parentMessageId: string; signal?: AbortSignal; toolRunId?: string }
468
+ ) => Promise<any>;
469
+
470
+ /**
471
+ * ✅ 新增:预览执行(无副作用)
472
+ * - 仅当 interaction 为 confirm/authorize 时会被调用
473
+ * - 用于生成 “待确认/待授权” 阶段的 tool message content(预览输出)
474
+ */
475
+ previewExecutor?: (
476
+ args: any,
477
+ thunkApi: any,
478
+ context?: { parentMessageId: string; signal?: AbortSignal; toolRunId?: string }
479
+ ) => Promise<any>;
480
+
481
+ description: {
482
+ name: string;
483
+ description: string;
484
+ category: string;
485
+ };
486
+
487
+ behavior?: ToolBehavior; // 工具在系统中的角色
488
+ capability?: ToolCapability; // 用户策略与预算主要按 capability 生效
489
+ interaction?: ToolInteraction; // 不写默认 "auto"
490
+ uiGroup?: ToolUiGroup; // 前端展示分组,不写默认 "general"
491
+ riskLevel?: ToolRiskLevel;
492
+ costLevel?: ToolCostLevel;
493
+ defaultConsent?: ToolConsentMode;
494
+
495
+ /**
496
+ * ✅ 新增:是否支持取消(未来 executeToolRun 传 signal 后即可实现)
497
+ * - 现在先作为 UI/能力标记预留,不影响 DB 结构
498
+ */
499
+ cancelable?: boolean;
500
+
501
+ /**
502
+ * ✅ 新增:授权相关元信息预留(未来可扩展,不强制使用)
503
+ * - 现在不实现授权策略,仅留接口,避免未来改 DB/大改代码
504
+ */
505
+ auth?: {
506
+ kind: "domain" | "resource" | "scopes";
507
+ scopeHint?: string; // 给 UI/日志的提示
508
+ };
509
+ }
510
+
511
+ /* ==================================================================
512
+ * 2.1 toolquery 工具:帮助模型发现可用工具
513
+ * ================================================================== */
514
+
515
+ export const toolQueryFunctionSchema = {
516
+ name: "toolquery",
517
+ description:
518
+ "根据当前任务描述,列出系统中可能有用的工具。适合在不确定可用工具时先调用本函数。",
519
+ parameters: {
520
+ type: "object",
521
+ properties: {
522
+ task: {
523
+ type: "string",
524
+ description: "用户当前的任务或需求描述。",
525
+ },
526
+ top_k: {
527
+ type: "number",
528
+ description: "最多返回多少个候选工具(默认 5)。",
529
+ default: 5,
530
+ },
531
+ },
532
+ required: ["task"],
533
+ },
534
+ };
535
+
536
+ export async function toolQueryFunc(args: any): Promise<{
537
+ rawData: any;
538
+ displayData: string;
539
+ }> {
540
+ const { task, top_k } = args || {};
541
+ const query = String(task || "").trim();
542
+ const topK = typeof top_k === "number" && top_k > 0 && top_k < 50 ? top_k : 5;
543
+
544
+ if (!query) {
545
+ const msg = "toolquery 需要提供 task 描述,比如:'分析数据库相关的工具'。";
546
+ return { rawData: [], displayData: msg };
547
+ }
548
+
549
+ const lowered = query.toLowerCase();
550
+
551
+ const candidates = toolDefinitions
552
+ .filter((tool) => tool.id !== "toolquery")
553
+ .map((tool) => {
554
+ const { description, behavior } = tool;
555
+ const haystack =
556
+ `${description.name} ${description.description} ${description.category} ${behavior || ""}`.toLowerCase();
557
+ const score = haystack.includes(lowered) ? 1 : 0;
558
+ return { tool, score };
559
+ })
560
+ .filter((item) => item.score > 0)
561
+ .slice(0, topK);
562
+
563
+ const rawData = candidates.map(({ tool }) => ({
564
+ name: tool.schema.name,
565
+ id: tool.id,
566
+ description: tool.description.description,
567
+ category: tool.description.category,
568
+ behavior: tool.behavior ?? null,
569
+ }));
570
+
571
+ let displayData: string;
572
+
573
+ if (rawData.length === 0) {
574
+ displayData =
575
+ `根据当前描述暂时没有找到明显匹配的工具。\n` +
576
+ `你可以尝试:\n` +
577
+ `- 换一种更具体的说法描述任务\n` +
578
+ `- 直接选择你认为合适的工具调用`;
579
+ } else {
580
+ displayData =
581
+ `根据你的任务描述,我找到了 ${rawData.length} 个可能有用的工具:\n\n` +
582
+ rawData
583
+ .map((t: any, idx: number) => {
584
+ const behaviorLabel = t.behavior ? `,类型:${t.behavior}` : "";
585
+ return `${idx + 1}. \`${t.name}\`(${t.category}${behaviorLabel})\n - ${t.description}`;
586
+ })
587
+ .join("\n");
588
+ }
589
+
590
+ return { rawData, displayData };
591
+ }
592
+
593
+ /* ==================================================================
594
+ * 3. [核心] 单一事实来源:在此处定义所有工具
595
+ * ================================================================== */
596
+
597
+ // 这里保留“非 Agent / 非代码”的工具定义,
598
+ // Agent 工具在 agentTools.ts,代码相关工具在 codeTools.ts。
599
+ const baseToolDefinitions: ToolDefinition[] = [
600
+ {
601
+ id: "uiAskChoice",
602
+ schema: uiAskChoiceFunctionSchema,
603
+ executor: uiAskChoiceFunc,
604
+ description: {
605
+ name: "ui_ask_choice",
606
+ description:
607
+ "向用户提出一个带多个选项的问题,让界面展示按钮供用户选择。",
608
+ category: "交互 / UI",
609
+ },
610
+ behavior: "answer",
611
+ },
612
+ {
613
+ id: "rememberMemory",
614
+ schema: rememberMemoryFunctionSchema,
615
+ executor: rememberMemoryFunc,
616
+ description: {
617
+ name: "rememberMemory",
618
+ description: "将值得长期保留的用户偏好或空间共识写入一条 episodic memory。",
619
+ category: "记忆 / 长期上下文",
620
+ },
621
+ behavior: "action",
622
+ },
623
+ {
624
+ id: "updateUserPreferenceProfile",
625
+ schema: updateUserPreferenceProfileFunctionSchema,
626
+ executor: updateUserPreferenceProfileFunc,
627
+ description: {
628
+ name: "updateUserPreferenceProfile",
629
+ description: "保存用户的语气、知识沉淀、空间读取等个性化偏好设置。",
630
+ category: "用户设置 / 个性化",
631
+ },
632
+ behavior: "action",
633
+ },
634
+ {
635
+ id: "ziweiChart",
636
+ schema: ziweiChartFunctionSchema,
637
+ executor: ziweiChartFunc,
638
+ description: {
639
+ name: "ziweiChart",
640
+ description: "生成紫微斗数本命盘,并输出可读的十二宫文字盘。",
641
+ category: "命理 / 排盘",
642
+ },
643
+ behavior: "answer",
644
+ capability: "general",
645
+ uiGroup: "general",
646
+ riskLevel: "low",
647
+ costLevel: "low",
648
+ defaultConsent: "auto",
649
+ },
650
+
651
+ // --- 计划与编排(不含 Agent 专用) ---
652
+ {
653
+ id: "createWorkflow",
654
+ schema: createWorkflowFunctionSchema,
655
+ executor: createWorkflowFunc,
656
+ description: {
657
+ name: "createWorkflow",
658
+ description:
659
+ "当执行路径已知时,定义并执行一个多步骤 workflow。引擎自动运行,无需每步调用 LLM,大幅节省 token。",
660
+ category: "计划与编排",
661
+ },
662
+ behavior: "orchestrator",
663
+ },
664
+ {
665
+ id: "toolquery",
666
+ schema: toolQueryFunctionSchema,
667
+ executor: toolQueryFunc,
668
+ description: {
669
+ name: "toolquery",
670
+ description:
671
+ "根据任务描述列出可能有用的工具,帮助你选择合适的工具链。",
672
+ category: "计划与编排",
673
+ },
674
+ behavior: "answer",
675
+ },
676
+ {
677
+ id: "delay",
678
+ schema: delayFunctionSchema,
679
+ executor: delayFunc,
680
+ description: {
681
+ name: "delay",
682
+ description:
683
+ "让计划暂停一小段时间(毫秒),用于节流批量操作(例如连续下载多个文件)。",
684
+ category: "计划与编排",
685
+ },
686
+ behavior: "action",
687
+ },
688
+ {
689
+ id: "queryModelUsage",
690
+ schema: queryModelUsageFunctionSchema,
691
+ executor: queryModelUsageFunc,
692
+ description: {
693
+ name: "queryModelUsage",
694
+ description:
695
+ "查询模型/API 用量与费用,带用户/管理员权限限制,可用于每日用量告警。",
696
+ category: "计费 / 用量",
697
+ },
698
+ behavior: "answer",
699
+ uiGroup: "general",
700
+ capability: "general",
701
+ riskLevel: "low",
702
+ costLevel: "low",
703
+ defaultConsent: "auto",
704
+ },
705
+ {
706
+ id: "createDialogGoal",
707
+ schema: createDialogGoalFunctionSchema,
708
+ executor: createDialogGoalFunc,
709
+ description: {
710
+ name: "createDialogGoal",
711
+ description: "为当前对话创建或替换一个目标,并可选设置 token 预算。",
712
+ category: "计划与编排",
713
+ },
714
+ behavior: "action",
715
+ uiGroup: "general",
716
+ capability: "general",
717
+ riskLevel: "low",
718
+ costLevel: "low",
719
+ defaultConsent: "auto",
720
+ },
721
+ {
722
+ id: "getDialogGoal",
723
+ schema: getDialogGoalFunctionSchema,
724
+ executor: getDialogGoalFunc,
725
+ description: {
726
+ name: "getDialogGoal",
727
+ description: "读取当前对话目标、完成状态和 token 预算报告。",
728
+ category: "计划与编排",
729
+ },
730
+ behavior: "answer",
731
+ uiGroup: "general",
732
+ capability: "general",
733
+ riskLevel: "low",
734
+ costLevel: "low",
735
+ defaultConsent: "auto",
736
+ },
737
+ {
738
+ id: "completeDialogGoal",
739
+ schema: completeDialogGoalFunctionSchema,
740
+ executor: completeDialogGoalFunc,
741
+ description: {
742
+ name: "completeDialogGoal",
743
+ description: "将当前对话目标标记为完成并持久化。",
744
+ category: "计划与编排",
745
+ },
746
+ behavior: "action",
747
+ uiGroup: "general",
748
+ capability: "general",
749
+ riskLevel: "low",
750
+ costLevel: "low",
751
+ defaultConsent: "auto",
752
+ },
753
+ {
754
+ id: "createScheduledTask",
755
+ schema: createScheduledTaskFunctionSchema,
756
+ executor: createScheduledTaskFunc,
757
+ description: {
758
+ name: "createScheduledTask",
759
+ description:
760
+ "创建由 agent 执行的 cron 定时任务,可选择创建后立即试运行一次。",
761
+ category: "计划与编排",
762
+ },
763
+ behavior: "action",
764
+ uiGroup: "general",
765
+ capability: "general",
766
+ riskLevel: "medium",
767
+ costLevel: "low",
768
+ defaultConsent: "ask",
769
+ },
770
+ {
771
+ id: "notifyUser",
772
+ schema: notifyUserFunctionSchema,
773
+ executor: notifyUserFunc,
774
+ description: {
775
+ name: "notifyUser",
776
+ description: "发送站内通知给当前用户,用于告警和任务结果提醒。",
777
+ category: "通知",
778
+ },
779
+ behavior: "action",
780
+ uiGroup: "general",
781
+ capability: "general",
782
+ riskLevel: "low",
783
+ costLevel: "low",
784
+ defaultConsent: "auto",
785
+ },
786
+
787
+ // --- 内容管理 ---
788
+ {
789
+ id: "createDoc",
790
+ schema: createDocFunctionSchema,
791
+ executor: createDocFunc,
792
+ description: {
793
+ name: "createDoc",
794
+ description: "在当前空间中创建新页面",
795
+ category: "内容管理",
796
+ },
797
+ behavior: "action",
798
+ uiGroup: "content",
799
+ capability: "knowledge_capture",
800
+ riskLevel: "medium",
801
+ costLevel: "medium",
802
+ defaultConsent: "ask",
803
+ },
804
+ {
805
+ id: "createSkillDoc",
806
+ schema: createSkillDocFunctionSchema,
807
+ executor: createSkillDocFunc,
808
+ description: {
809
+ name: "createSkillDoc",
810
+ description: "创建带 skill-config / eval-config 协议块的本地 skill 文档。",
811
+ category: "内容管理",
812
+ },
813
+ behavior: "action",
814
+ uiGroup: "content",
815
+ capability: "knowledge_capture",
816
+ riskLevel: "medium",
817
+ costLevel: "medium",
818
+ defaultConsent: "ask",
819
+ },
820
+ {
821
+ id: "doctorSkill",
822
+ schema: doctorSkillFunctionSchema,
823
+ executor: doctorSkillFunc,
824
+ description: {
825
+ name: "doctorSkill",
826
+ description: "诊断 skill 文档协议、工具绑定和常见问题。",
827
+ category: "内容管理",
828
+ },
829
+ behavior: "answer",
830
+ uiGroup: "content",
831
+ capability: "knowledge_capture",
832
+ riskLevel: "low",
833
+ costLevel: "low",
834
+ },
835
+ {
836
+ id: "evalSkill",
837
+ schema: evalSkillFunctionSchema,
838
+ executor: evalSkillFunc,
839
+ description: {
840
+ name: "evalSkill",
841
+ description: "根据 eval-config 评估一个 skill 文档是否满足预期。",
842
+ category: "内容管理",
843
+ },
844
+ behavior: "answer",
845
+ uiGroup: "content",
846
+ capability: "knowledge_capture",
847
+ riskLevel: "low",
848
+ costLevel: "low",
849
+ },
850
+ {
851
+ id: "importSkill",
852
+ schema: importSkillFunctionSchema,
853
+ executor: importSkillFunc,
854
+ description: {
855
+ name: "importSkill",
856
+ description: "导入外部 SKILL.md 或 Markdown skill 文档到当前空间。",
857
+ category: "内容管理",
858
+ },
859
+ behavior: "action",
860
+ uiGroup: "content",
861
+ capability: "knowledge_capture",
862
+ riskLevel: "medium",
863
+ costLevel: "medium",
864
+ defaultConsent: "ask",
865
+ },
866
+ {
867
+ id: "wereadGateway",
868
+ schema: wereadGatewayFunctionSchema,
869
+ executor: wereadGatewayFunc,
870
+ description: {
871
+ name: "wereadGateway",
872
+ description: "调用微信读书接口,支持书架、搜索、阅读统计、笔记划线、书评和推荐。",
873
+ category: "网络",
874
+ },
875
+ behavior: "data",
876
+ uiGroup: "external",
877
+ capability: "web_search",
878
+ riskLevel: "low",
879
+ costLevel: "low",
880
+ },
881
+ {
882
+ id: "readDoc",
883
+ schema: readDocFunctionSchema,
884
+ executor: readDocFunc,
885
+ description: {
886
+ name: "readDoc",
887
+ description: "读取指定文档/页面的内容(Markdown 格式)",
888
+ category: "内容管理",
889
+ },
890
+ behavior: "data",
891
+ uiGroup: "content",
892
+ capability: "space_context",
893
+ riskLevel: "low",
894
+ costLevel: "medium",
895
+ },
896
+ {
897
+ id: "readSkillDoc",
898
+ schema: readSkillDocFunctionSchema,
899
+ executor: readSkillDocFunc,
900
+ description: {
901
+ name: "readSkillDoc",
902
+ description: "Read a Nolo skill doc/page.",
903
+ category: "Nolo workspace",
904
+ },
905
+ behavior: "data",
906
+ uiGroup: "content",
907
+ capability: "space_context",
908
+ riskLevel: "low",
909
+ costLevel: "medium",
910
+ },
911
+ {
912
+ id: "readPage",
913
+ schema: readPageFunctionSchema,
914
+ executor: readPageFunc,
915
+ description: {
916
+ name: "readPage",
917
+ description: "读取指定页面的内容(Markdown 格式,兼容旧名称)",
918
+ category: "内容管理",
919
+ },
920
+ behavior: "data",
921
+ uiGroup: "content",
922
+ capability: "space_context",
923
+ riskLevel: "low",
924
+ costLevel: "medium",
925
+ },
926
+ {
927
+ id: "updateDoc",
928
+ schema: updateDocFunctionSchema,
929
+ executor: updateDocFunc,
930
+ description: {
931
+ name: "updateDoc",
932
+ description: "更新指定页面/文档的内容。支持全量覆盖或在末尾追加内容。",
933
+ category: "内容管理",
934
+ },
935
+ behavior: "action",
936
+ uiGroup: "content",
937
+ capability: "knowledge_capture",
938
+ riskLevel: "medium",
939
+ costLevel: "medium",
940
+ defaultConsent: "ask",
941
+ },
942
+ {
943
+ id: "searchWorkspace",
944
+ schema: searchWorkspaceFunctionSchema,
945
+ executor: searchWorkspaceFunc,
946
+ description: {
947
+ name: "search_workspace",
948
+ description: "在当前空间(Workspace)中搜索页面、表格等内容。",
949
+ category: "内容管理",
950
+ },
951
+ behavior: "data",
952
+ uiGroup: "content",
953
+ capability: "space_context",
954
+ riskLevel: "low",
955
+ costLevel: "low",
956
+ },
957
+ {
958
+ id: "searchAllSpaces",
959
+ schema: searchAllSpacesFunctionSchema,
960
+ executor: searchAllSpacesFunc,
961
+ description: {
962
+ name: "search_all_spaces",
963
+ description: "在你可访问的全部空间中搜索页面、表格等内容,并返回所属空间。",
964
+ category: "内容管理",
965
+ },
966
+ behavior: "data",
967
+ uiGroup: "content",
968
+ capability: "space_context",
969
+ riskLevel: "low",
970
+ costLevel: "medium",
971
+ },
972
+ {
973
+ id: "searchDialogMessages",
974
+ schema: searchDialogMessagesFunctionSchema,
975
+ executor: searchDialogMessagesFunc,
976
+ description: {
977
+ name: "searchDialogMessages",
978
+ description: "在指定对话的原始消息中搜索文本,并返回命中的 messageId、角色、原文片段和邻近上下文。",
979
+ category: "内容管理",
980
+ },
981
+ behavior: "data",
982
+ uiGroup: "content",
983
+ capability: "space_context",
984
+ riskLevel: "low",
985
+ costLevel: "low",
986
+ },
987
+ {
988
+ id: "createCategory",
989
+ schema: createCategoryFunctionSchema,
990
+ executor: createCategoryFunc,
991
+ description: {
992
+ name: "createCategory",
993
+ description: "在当前空间中创建新分类",
994
+ category: "内容管理",
995
+ },
996
+ behavior: "action",
997
+ uiGroup: "content",
998
+ },
999
+ {
1000
+ id: "updateContentCategory",
1001
+ schema: updateContentCategoryFunctionSchema,
1002
+ executor: updateContentCategoryFunc,
1003
+ description: {
1004
+ name: "updateContentCategory",
1005
+ description: "更新内容的分类",
1006
+ category: "内容管理",
1007
+ },
1008
+ behavior: "action",
1009
+ uiGroup: "content",
1010
+ },
1011
+ {
1012
+ id: "queryContentsByCategory",
1013
+ schema: queryContentsByCategoryFunctionSchema,
1014
+ executor: queryContentsByCategoryFunc,
1015
+ description: {
1016
+ name: "queryContentsByCategory",
1017
+ description: "查询分类下的所有内容",
1018
+ category: "内容管理",
1019
+ },
1020
+ behavior: "data",
1021
+ uiGroup: "content",
1022
+ },
1023
+
1024
+ // --- 数据操作 ---
1025
+ {
1026
+ id: "createTable",
1027
+ schema: createTableFunctionSchema,
1028
+ executor: createTableFunc,
1029
+ description: {
1030
+ name: "createTable",
1031
+ description: "在当前租户下创建一张新的数据表,并定义字段结构。",
1032
+ category: "数据操作",
1033
+ },
1034
+ behavior: "action",
1035
+ uiGroup: "data",
1036
+ capability: "knowledge_capture",
1037
+ riskLevel: "medium",
1038
+ costLevel: "medium",
1039
+ defaultConsent: "ask",
1040
+ },
1041
+ {
1042
+ id: "shareTable",
1043
+ schema: shareTableFunctionSchema,
1044
+ executor: shareTableFunc,
1045
+ description: {
1046
+ name: "shareTable",
1047
+ description: "把表发布为可分享链接,可用于社区分享。",
1048
+ category: "数据操作",
1049
+ },
1050
+ behavior: "action",
1051
+ uiGroup: "data",
1052
+ riskLevel: "medium",
1053
+ costLevel: "low",
1054
+ defaultConsent: "ask",
1055
+ },
1056
+ {
1057
+ id: "importData",
1058
+ schema: importDataFunctionSchema,
1059
+ executor: importDataFunc,
1060
+ description: {
1061
+ name: "importData",
1062
+ description: "将用户上传的文件数据导入数据库表",
1063
+ category: "数据操作",
1064
+ },
1065
+ behavior: "data",
1066
+ uiGroup: "data",
1067
+ capability: "space_context",
1068
+ riskLevel: "low",
1069
+ costLevel: "medium",
1070
+ },
1071
+ {
1072
+ id: "executeSql",
1073
+ schema: executeSqlFunctionSchema,
1074
+ executor: executeSqlFunc,
1075
+ description: {
1076
+ name: "executeSql",
1077
+ description: "直接执行 SQL 语句",
1078
+ category: "数据操作",
1079
+ },
1080
+ behavior: "data",
1081
+ uiGroup: "data",
1082
+ },
1083
+ {
1084
+ id: "read",
1085
+ schema: readFunctionSchema,
1086
+ executor: readFunc,
1087
+ description: {
1088
+ name: "read",
1089
+ description:
1090
+ "根据指定的 dbKey 从本地/远程数据库读取一条记录,可选择本地优先或等待远程结果。",
1091
+ category: "数据操作",
1092
+ },
1093
+ behavior: "data",
1094
+ uiGroup: "data",
1095
+ },
1096
+ {
1097
+ id: "email_provision_identity",
1098
+ schema: emailProvisionIdentityFunctionSchema,
1099
+ executor: emailProvisionIdentityFunc,
1100
+ description: {
1101
+ name: "email_provision_identity",
1102
+ description: "为 agent 生成并绑定受控域名邮箱身份。",
1103
+ category: "数据操作",
1104
+ },
1105
+ behavior: "action",
1106
+ uiGroup: "data",
1107
+ riskLevel: "medium",
1108
+ costLevel: "low",
1109
+ defaultConsent: "ask",
1110
+ },
1111
+ {
1112
+ id: "email_send",
1113
+ schema: emailSendFunctionSchema,
1114
+ executor: emailSendFunc,
1115
+ description: {
1116
+ name: "email_send",
1117
+ description: "以 agent 已绑定邮箱身份发送邮件。",
1118
+ category: "数据操作",
1119
+ },
1120
+ behavior: "action",
1121
+ uiGroup: "data",
1122
+ riskLevel: "medium",
1123
+ costLevel: "low",
1124
+ defaultConsent: "ask",
1125
+ },
1126
+ {
1127
+ id: "email_wait_for",
1128
+ schema: emailWaitForFunctionSchema,
1129
+ executor: emailWaitForFunc,
1130
+ description: {
1131
+ name: "email_wait_for",
1132
+ description: "等待符合条件的邮件到达。",
1133
+ category: "数据操作",
1134
+ },
1135
+ behavior: "data",
1136
+ uiGroup: "data",
1137
+ riskLevel: "low",
1138
+ costLevel: "low",
1139
+ },
1140
+ {
1141
+ id: "email_extract_verification",
1142
+ schema: emailExtractVerificationFunctionSchema,
1143
+ executor: emailExtractVerificationFunc,
1144
+ description: {
1145
+ name: "email_extract_verification",
1146
+ description: "从邮件中提取验证码和验证链接。",
1147
+ category: "数据操作",
1148
+ },
1149
+ behavior: "data",
1150
+ uiGroup: "data",
1151
+ riskLevel: "low",
1152
+ costLevel: "low",
1153
+ },
1154
+ {
1155
+ id: "email_search",
1156
+ schema: emailSearchFunctionSchema,
1157
+ executor: emailSearchFunc,
1158
+ description: {
1159
+ name: "email_search",
1160
+ description: "查询当前主体可访问的邮件列表。",
1161
+ category: "数据操作",
1162
+ },
1163
+ behavior: "data",
1164
+ uiGroup: "data",
1165
+ riskLevel: "low",
1166
+ costLevel: "low",
1167
+ },
1168
+ {
1169
+ id: "email_read",
1170
+ schema: emailReadFunctionSchema,
1171
+ executor: emailReadFunc,
1172
+ description: {
1173
+ name: "email_read",
1174
+ description: "读取一封邮件的完整内容。",
1175
+ category: "数据操作",
1176
+ },
1177
+ behavior: "data",
1178
+ uiGroup: "data",
1179
+ riskLevel: "low",
1180
+ costLevel: "low",
1181
+ },
1182
+ {
1183
+ id: "email_update_tags",
1184
+ schema: emailUpdateTagsFunctionSchema,
1185
+ executor: emailUpdateTagsFunc,
1186
+ description: {
1187
+ name: "email_update_tags",
1188
+ description: "替换一封邮件的 tags。",
1189
+ category: "数据操作",
1190
+ },
1191
+ behavior: "action",
1192
+ uiGroup: "data",
1193
+ riskLevel: "medium",
1194
+ costLevel: "low",
1195
+ },
1196
+ {
1197
+ id: "email_archive",
1198
+ schema: emailArchiveFunctionSchema,
1199
+ executor: emailArchiveFunc,
1200
+ description: {
1201
+ name: "email_archive",
1202
+ description: "把一封邮件移动到 archive mailbox。",
1203
+ category: "数据操作",
1204
+ },
1205
+ behavior: "action",
1206
+ uiGroup: "data",
1207
+ riskLevel: "medium",
1208
+ costLevel: "low",
1209
+ },
1210
+ {
1211
+ id: "addTableRow",
1212
+ schema: addTableRowFunctionSchema,
1213
+ executor: addTableRowFunc,
1214
+ description: {
1215
+ name: "addTableRow",
1216
+ description:
1217
+ "在当前已打开的表中新增一行数据,通常由 AI 根据分析结果自动填充各列。",
1218
+ category: "数据操作",
1219
+ },
1220
+ behavior: "action",
1221
+ uiGroup: "data",
1222
+ },
1223
+ {
1224
+ id: "queryTableRows",
1225
+ schema: queryTableRowsFunctionSchema,
1226
+ executor: queryTableRowsFunc,
1227
+ description: {
1228
+ name: "queryTableRows",
1229
+ description: "查询指定表中的行,支持过滤、排序和分页。",
1230
+ category: "数据操作",
1231
+ },
1232
+ behavior: "data",
1233
+ uiGroup: "data",
1234
+ },
1235
+ {
1236
+ id: "updateTableRow",
1237
+ schema: updateTableRowFunctionSchema,
1238
+ executor: updateTableRowFunc,
1239
+ description: {
1240
+ name: "updateTableRow",
1241
+ description: "更新表中的单行数据。",
1242
+ category: "数据操作",
1243
+ },
1244
+ behavior: "action",
1245
+ uiGroup: "data",
1246
+ },
1247
+ {
1248
+ id: "deleteTableRow",
1249
+ schema: deleteTableRowFunctionSchema,
1250
+ executor: deleteTableRowFunc,
1251
+ description: {
1252
+ name: "deleteTableRow",
1253
+ description: "删除表中的单行数据。",
1254
+ category: "数据操作",
1255
+ },
1256
+ behavior: "action",
1257
+ uiGroup: "data",
1258
+ },
1259
+ {
1260
+ id: "addTableRows",
1261
+ schema: addTableRowsFunctionSchema,
1262
+ executor: addTableRowsFunc,
1263
+ description: {
1264
+ name: "addTableRows",
1265
+ description: "批量向表中新增多行数据。",
1266
+ category: "数据操作",
1267
+ },
1268
+ behavior: "action",
1269
+ uiGroup: "data",
1270
+ },
1271
+ {
1272
+ id: "updateTableRows",
1273
+ schema: updateTableRowsFunctionSchema,
1274
+ executor: updateTableRowsFunc,
1275
+ description: {
1276
+ name: "updateTableRows",
1277
+ description: "批量更新表中的多行数据。",
1278
+ category: "数据操作",
1279
+ },
1280
+ behavior: "action",
1281
+ uiGroup: "data",
1282
+ },
1283
+ {
1284
+ id: "deleteTableRows",
1285
+ schema: deleteTableRowsFunctionSchema,
1286
+ executor: deleteTableRowsFunc,
1287
+ description: {
1288
+ name: "deleteTableRows",
1289
+ description: "批量删除表中的多行数据。",
1290
+ category: "数据操作",
1291
+ },
1292
+ behavior: "action",
1293
+ uiGroup: "data",
1294
+ },
1295
+ {
1296
+ id: "addTableColumn",
1297
+ schema: addTableColumnFunctionSchema,
1298
+ executor: addTableColumnFunc,
1299
+ description: {
1300
+ name: "addTableColumn",
1301
+ description: "向表中新增字段。",
1302
+ category: "数据操作",
1303
+ },
1304
+ behavior: "action",
1305
+ uiGroup: "data",
1306
+ },
1307
+ {
1308
+ id: "deleteTableColumn",
1309
+ schema: deleteTableColumnFunctionSchema,
1310
+ executor: deleteTableColumnFunc,
1311
+ description: {
1312
+ name: "deleteTableColumn",
1313
+ description: "删除表中的字段,并同步清理现有行数据。",
1314
+ category: "数据操作",
1315
+ },
1316
+ behavior: "action",
1317
+ uiGroup: "data",
1318
+ },
1319
+ {
1320
+ id: "renameTableColumn",
1321
+ schema: renameTableColumnFunctionSchema,
1322
+ executor: renameTableColumnFunc,
1323
+ description: {
1324
+ name: "renameTableColumn",
1325
+ description: "修改表字段的 machine name,并迁移已有行数据。",
1326
+ category: "数据操作",
1327
+ },
1328
+ behavior: "action",
1329
+ uiGroup: "data",
1330
+ },
1331
+ {
1332
+ id: "renameTableColumnLabel",
1333
+ schema: renameTableColumnLabelFunctionSchema,
1334
+ executor: renameTableColumnLabelFunc,
1335
+ description: {
1336
+ name: "renameTableColumnLabel",
1337
+ description: "修改表字段的显示名。",
1338
+ category: "数据操作",
1339
+ },
1340
+ behavior: "action",
1341
+ uiGroup: "data",
1342
+ },
1343
+ {
1344
+ id: "renameTable",
1345
+ schema: renameTableFunctionSchema,
1346
+ executor: renameTableFunc,
1347
+ description: {
1348
+ name: "renameTable",
1349
+ description: "更新表的显示名称。",
1350
+ category: "数据操作",
1351
+ },
1352
+ behavior: "action",
1353
+ uiGroup: "data",
1354
+ },
1355
+ {
1356
+ id: "updateContentTitle",
1357
+ schema: updateContentTitleTool.function,
1358
+ executor: updateContentTitleFunc as any,
1359
+ description: {
1360
+ name: "update_content_title",
1361
+ description: "更新当前空间中某个内容的标题",
1362
+ category: "内容管理",
1363
+ },
1364
+ behavior: "action",
1365
+ uiGroup: "content",
1366
+ },
1367
+ // === Space 导航工具 ===
1368
+ {
1369
+ id: "listUserSpaces",
1370
+ schema: listUserSpacesFunctionSchema,
1371
+ executor: listUserSpacesFunc,
1372
+ description: {
1373
+ name: "listUserSpaces",
1374
+ description:
1375
+ "获取当前用户可访问的所有 Space 列表(概览),只返回 ID 和名称。",
1376
+ category: "数据操作",
1377
+ },
1378
+ behavior: "data",
1379
+ uiGroup: "data",
1380
+ },
1381
+ {
1382
+ id: "listDialogs",
1383
+ schema: listDialogsFunctionSchema,
1384
+ executor: listDialogsFunc,
1385
+ description: {
1386
+ name: "listDialogs",
1387
+ description: "List the current user's Nolo dialogs.",
1388
+ category: "Nolo workspace",
1389
+ },
1390
+ behavior: "data",
1391
+ uiGroup: "content",
1392
+ capability: "space_context",
1393
+ riskLevel: "low",
1394
+ costLevel: "low",
1395
+ },
1396
+ {
1397
+ id: "readDialog",
1398
+ schema: readDialogFunctionSchema,
1399
+ executor: readDialogFunc,
1400
+ description: {
1401
+ name: "readDialog",
1402
+ description: "Read a Nolo dialog and recent messages.",
1403
+ category: "Nolo workspace",
1404
+ },
1405
+ behavior: "data",
1406
+ uiGroup: "content",
1407
+ capability: "space_context",
1408
+ riskLevel: "low",
1409
+ costLevel: "medium",
1410
+ },
1411
+ {
1412
+ id: "listAgents",
1413
+ schema: listAgentsFunctionSchema,
1414
+ executor: listAgentsFunc,
1415
+ description: {
1416
+ name: "listAgents",
1417
+ description: "List the current user's Nolo agents.",
1418
+ category: "Nolo workspace",
1419
+ },
1420
+ behavior: "data",
1421
+ uiGroup: "content",
1422
+ capability: "space_context",
1423
+ riskLevel: "low",
1424
+ costLevel: "low",
1425
+ },
1426
+ {
1427
+ id: "readAgent",
1428
+ schema: readAgentFunctionSchema,
1429
+ executor: readAgentFunc,
1430
+ description: {
1431
+ name: "readAgent",
1432
+ description: "Read a Nolo agent config.",
1433
+ category: "Nolo workspace",
1434
+ },
1435
+ behavior: "data",
1436
+ uiGroup: "content",
1437
+ capability: "space_context",
1438
+ riskLevel: "low",
1439
+ costLevel: "low",
1440
+ },
1441
+ {
1442
+ id: "listSpaces",
1443
+ schema: listSpacesFunctionSchema,
1444
+ executor: listSpacesFunc,
1445
+ description: {
1446
+ name: "listSpaces",
1447
+ description: "List joined Nolo spaces.",
1448
+ category: "Nolo workspace",
1449
+ },
1450
+ behavior: "data",
1451
+ uiGroup: "content",
1452
+ capability: "space_context",
1453
+ riskLevel: "low",
1454
+ costLevel: "low",
1455
+ },
1456
+ {
1457
+ id: "readSpace",
1458
+ schema: readSpaceFunctionSchema,
1459
+ executor: readSpaceFunc,
1460
+ description: {
1461
+ name: "readSpace",
1462
+ description: "Read a Nolo space and its contents.",
1463
+ category: "Nolo workspace",
1464
+ },
1465
+ behavior: "data",
1466
+ uiGroup: "content",
1467
+ capability: "space_context",
1468
+ riskLevel: "low",
1469
+ costLevel: "medium",
1470
+ },
1471
+ {
1472
+ id: "cliWhoami",
1473
+ schema: cliWhoamiFunctionSchema,
1474
+ executor: cliWhoamiFunc,
1475
+ description: {
1476
+ name: "cliWhoami",
1477
+ description: "Show current Nolo runtime identity.",
1478
+ category: "Nolo workspace",
1479
+ },
1480
+ behavior: "data",
1481
+ uiGroup: "content",
1482
+ capability: "space_context",
1483
+ riskLevel: "low",
1484
+ costLevel: "low",
1485
+ },
1486
+ {
1487
+ id: "cliDoctor",
1488
+ schema: cliDoctorFunctionSchema,
1489
+ executor: cliDoctorFunc,
1490
+ description: {
1491
+ name: "cliDoctor",
1492
+ description: "Show current Nolo runtime diagnostics.",
1493
+ category: "Nolo workspace",
1494
+ },
1495
+ behavior: "data",
1496
+ uiGroup: "content",
1497
+ capability: "space_context",
1498
+ riskLevel: "low",
1499
+ costLevel: "low",
1500
+ },
1501
+ {
1502
+ id: "deleteSpaces",
1503
+ schema: deleteSpacesFunctionSchema,
1504
+ executor: deleteSpacesFunc,
1505
+ previewExecutor: deleteSpacesPreviewFunc,
1506
+ description: {
1507
+ name: "deleteSpaces",
1508
+ description:
1509
+ "按名称或 ID 删除当前用户拥有的 Space;先列出候选,用户确认后才删除 Space 壳和成员关系。",
1510
+ category: "数据操作",
1511
+ },
1512
+ behavior: "action",
1513
+ uiGroup: "data",
1514
+ capability: "space_context",
1515
+ interaction: "confirm",
1516
+ riskLevel: "high",
1517
+ costLevel: "low",
1518
+ defaultConsent: "ask",
1519
+ },
1520
+ {
1521
+ id: "listLocalRoots",
1522
+ schema: listLocalRootsFunctionSchema,
1523
+ executor: listLocalRootsFunc,
1524
+ description: {
1525
+ name: "listLocalRoots",
1526
+ description: "列出当前桌面客户端里已经授权的本地文件夹 roots。",
1527
+ category: "本地文件",
1528
+ },
1529
+ behavior: "data",
1530
+ uiGroup: "data",
1531
+ capability: "general",
1532
+ riskLevel: "low",
1533
+ costLevel: "low",
1534
+ defaultConsent: "ask",
1535
+ },
1536
+ {
1537
+ id: "requestLocalFolderAccess",
1538
+ schema: requestLocalFolderAccessFunctionSchema,
1539
+ executor: requestLocalFolderAccessFunc,
1540
+ description: {
1541
+ name: "requestLocalFolderAccess",
1542
+ description: "为桌面客户端请求授权一个本地文件夹,并返回可复用的 rootId。",
1543
+ category: "本地文件",
1544
+ },
1545
+ behavior: "action",
1546
+ uiGroup: "data",
1547
+ capability: "general",
1548
+ interaction: "confirm",
1549
+ riskLevel: "medium",
1550
+ costLevel: "low",
1551
+ defaultConsent: "ask",
1552
+ },
1553
+ {
1554
+ id: "listLocalFiles",
1555
+ schema: listLocalFilesFunctionSchema,
1556
+ executor: listLocalFilesFunc,
1557
+ description: {
1558
+ name: "listLocalFiles",
1559
+ description: "列出 Windows 桌面客户端中用户已授权本地文件夹内的文件和目录。",
1560
+ category: "本地文件",
1561
+ },
1562
+ behavior: "data",
1563
+ uiGroup: "data",
1564
+ capability: "general",
1565
+ riskLevel: "low",
1566
+ costLevel: "low",
1567
+ defaultConsent: "ask",
1568
+ },
1569
+ {
1570
+ id: "readLocalFile",
1571
+ schema: readLocalFileFunctionSchema,
1572
+ executor: readLocalFileFunc,
1573
+ description: {
1574
+ name: "readLocalFile",
1575
+ description: "读取 Windows 桌面客户端中用户已授权本地文件夹内的文本文件。",
1576
+ category: "本地文件",
1577
+ },
1578
+ behavior: "data",
1579
+ uiGroup: "data",
1580
+ capability: "general",
1581
+ riskLevel: "medium",
1582
+ costLevel: "low",
1583
+ defaultConsent: "ask",
1584
+ },
1585
+ {
1586
+ id: "proposeLocalFileChanges",
1587
+ schema: proposeLocalFileChangesFunctionSchema,
1588
+ executor: proposeLocalFileChangesFunc,
1589
+ previewExecutor: proposeLocalFileChangesPreviewFunc,
1590
+ description: {
1591
+ name: "proposeLocalFileChanges",
1592
+ description: "为用户已授权的本地文件夹创建待确认整理计划,不会直接修改本地文件。",
1593
+ category: "本地文件",
1594
+ },
1595
+ behavior: "action",
1596
+ uiGroup: "data",
1597
+ capability: "general",
1598
+ interaction: "confirm",
1599
+ riskLevel: "high",
1600
+ costLevel: "low",
1601
+ defaultConsent: "ask",
1602
+ },
1603
+ {
1604
+ id: "executeApprovedLocalFileChanges",
1605
+ schema: executeApprovedLocalFileChangesFunctionSchema,
1606
+ executor: executeApprovedLocalFileChangesFunc,
1607
+ description: {
1608
+ name: "executeApprovedLocalFileChanges",
1609
+ description: "执行用户已经确认的本地文件整理计划。",
1610
+ category: "本地文件",
1611
+ },
1612
+ behavior: "action",
1613
+ uiGroup: "data",
1614
+ capability: "general",
1615
+ interaction: "confirm",
1616
+ riskLevel: "high",
1617
+ costLevel: "low",
1618
+ defaultConsent: "ask",
1619
+ },
1620
+ {
1621
+ id: "undoLocalFileChangeBatch",
1622
+ schema: undoLocalFileChangeBatchFunctionSchema,
1623
+ executor: undoLocalFileChangeBatchFunc,
1624
+ description: {
1625
+ name: "undoLocalFileChangeBatch",
1626
+ description: "撤销一个本地文件整理批次中可撤销的移动或重命名操作。",
1627
+ category: "本地文件",
1628
+ },
1629
+ behavior: "action",
1630
+ uiGroup: "data",
1631
+ capability: "general",
1632
+ interaction: "confirm",
1633
+ riskLevel: "medium",
1634
+ costLevel: "low",
1635
+ defaultConsent: "ask",
1636
+ },
1637
+
1638
+ // --- 网络与智能 ---
1639
+ {
1640
+ id: "fetchWebpage",
1641
+ schema: fetchWebpageFunctionSchema,
1642
+ executor: fetchWebpageFunc,
1643
+ description: {
1644
+ name: "fetchWebpage",
1645
+ description: "访问网页并获取其内容",
1646
+ category: "网络与智能",
1647
+ },
1648
+ behavior: "data",
1649
+ },
1650
+ {
1651
+ id: "convertMarxistsBookToOfflineHtml",
1652
+ schema: convertMarxistsBookToOfflineHtmlFunctionSchema,
1653
+ executor: convertMarxistsBookToOfflineHtmlFunc,
1654
+ description: {
1655
+ name: "convertMarxistsBookToOfflineHtml",
1656
+ description:
1657
+ "将 Marxists.org 中文旧式书籍页面转换成保留原 CSS、背景和排版的离线单 HTML。",
1658
+ category: "网络与智能",
1659
+ },
1660
+ behavior: "data",
1661
+ capability: "web_access",
1662
+ riskLevel: "low",
1663
+ costLevel: "medium",
1664
+ defaultConsent: "auto",
1665
+ cancelable: true,
1666
+ },
1667
+ {
1668
+ id: "readXPost",
1669
+ schema: readXPostFunctionSchema,
1670
+ executor: readXPostFunc,
1671
+ description: {
1672
+ name: "read_x_post",
1673
+ description:
1674
+ "读取 X/Twitter status 链接的可见帖子正文和结构化数据,适合总结、解释或抽取用户给出的 X 帖子。",
1675
+ category: "网络与智能",
1676
+ },
1677
+ behavior: "data",
1678
+ capability: "web_access",
1679
+ riskLevel: "low",
1680
+ costLevel: "low",
1681
+ defaultConsent: "auto",
1682
+ cancelable: true,
1683
+ },
1684
+ {
1685
+ id: "readXhsProfile",
1686
+ schema: readXhsProfileFunctionSchema,
1687
+ executor: readXhsProfileFunc,
1688
+ description: {
1689
+ name: "read_xhs_profile",
1690
+ description:
1691
+ "读取小红书用户主页的公开信息:用户资料、笔记列表、笔记详情指标和评论摘要。适合分析小红书账号内容和互动数据。",
1692
+ category: "网络与智能",
1693
+ },
1694
+ behavior: "data",
1695
+ capability: "web_access",
1696
+ riskLevel: "low",
1697
+ costLevel: "low",
1698
+ defaultConsent: "auto",
1699
+ cancelable: true,
1700
+ },
1701
+
1702
+ {
1703
+ id: "surfWeather",
1704
+ schema: surfWeatherFunctionSchema,
1705
+ executor: surfWeatherFunc,
1706
+ description: {
1707
+ name: "surfWeather",
1708
+ description:
1709
+ "获取指定海岸位置的冲浪天气预报(浪高、涌浪、周期、浪向),判断是否适合冲浪。",
1710
+ category: "网络与智能",
1711
+ },
1712
+ behavior: "data",
1713
+ },
1714
+
1715
+ // === Cloudflare Browser Rendering 爬取工具 ===
1716
+ {
1717
+ id: "cloudflareCrawl",
1718
+ schema: cloudflareCrawlFunctionSchema,
1719
+ executor: cloudflareCrawlFunc,
1720
+ description: {
1721
+ name: "cloudflareCrawl",
1722
+ description:
1723
+ "使用 Cloudflare Browser Rendering 爬取整个网站(支持 JS 渲染),一次调用可获取多页 Markdown 内容,适合站点级内容抓取。",
1724
+ category: "网络与智能",
1725
+ },
1726
+ behavior: "data",
1727
+ },
1728
+ {
1729
+ id: "cloudflareCrawlStatus",
1730
+ schema: cloudflareCrawlStatusFunctionSchema,
1731
+ executor: cloudflareCrawlStatusFunc,
1732
+ description: {
1733
+ name: "cloudflareCrawlStatus",
1734
+ description: "查询 Cloudflare 爬取任务的当前状态和结果(配合 cloudflareCrawl wait=false 使用)。",
1735
+ category: "网络与智能",
1736
+ },
1737
+ behavior: "data",
1738
+ },
1739
+
1740
+ // === Apify 抓取工具 ===
1741
+ {
1742
+ id: "googleSearchScraper",
1743
+ schema: googleSearchScraperFunctionSchema,
1744
+ executor: googleSearchScraperFunc,
1745
+ description: {
1746
+ name: "googleSearchScraper",
1747
+ description: "抓取 Google 搜索结果(SERP),返回自然结果、广告、People Also Ask 等结构化数据。",
1748
+ category: "网络与智能",
1749
+ },
1750
+ behavior: "data",
1751
+ },
1752
+ {
1753
+ id: "youtubeScraper",
1754
+ schema: youtubeScraperFunctionSchema,
1755
+ executor: youtubeScraperFunc,
1756
+ description: {
1757
+ name: "youtubeScraper",
1758
+ description:
1759
+ "使用 Apify YouTube Scraper 抓取指定视频、频道或搜索结果的详细数据(支持字幕)。",
1760
+ category: "网络与智能",
1761
+ },
1762
+ behavior: "data",
1763
+ },
1764
+ {
1765
+ id: "ecommerceScraper",
1766
+ schema: ecommerceScraperFunctionSchema,
1767
+ executor: ecommerceScraperFunc,
1768
+ description: {
1769
+ name: "ecommerceScraper",
1770
+ description:
1771
+ "使用 Apify E-commerce Scraping Tool 抓取电商产品、评论和卖家信息。",
1772
+ category: "网络与智能",
1773
+ },
1774
+ behavior: "data",
1775
+ },
1776
+ {
1777
+ id: "taobaoTmallProductScraper",
1778
+ schema: taobaoTmallProductScraperFunctionSchema,
1779
+ executor: taobaoTmallProductScraperFunc,
1780
+ description: {
1781
+ name: "taobaoTmallProductScraper",
1782
+ description:
1783
+ "使用 Apify Taobao/Tmall Product Scraper 抓取淘宝/天猫商品真实详情、SKU、价格、库存和规格参数。",
1784
+ category: "网络与智能",
1785
+ },
1786
+ behavior: "data",
1787
+ capability: "web_access",
1788
+ riskLevel: "low",
1789
+ costLevel: "low",
1790
+ defaultConsent: "auto",
1791
+ cancelable: true,
1792
+ },
1793
+ {
1794
+ id: "jdProductScraper",
1795
+ schema: jdProductScraperFunctionSchema,
1796
+ executor: jdProductScraperFunc,
1797
+ description: {
1798
+ name: "jdProductScraper",
1799
+ description:
1800
+ "抓取京东商品页内嵌真实商品参数,返回标题、品牌、型号、店铺、尺寸重量、价格、图片、变体和库存状态。",
1801
+ category: "网络与智能",
1802
+ },
1803
+ behavior: "data",
1804
+ capability: "web_access",
1805
+ riskLevel: "low",
1806
+ costLevel: "low",
1807
+ defaultConsent: "auto",
1808
+ cancelable: true,
1809
+ },
1810
+ {
1811
+ id: "amazonProductScraper",
1812
+ schema: amazonProductScraperFunctionSchema,
1813
+ executor: amazonProductScraperFunc,
1814
+ description: {
1815
+ name: "amazonProductScraper",
1816
+ description:
1817
+ "使用 Apify Amazon Product Scraper 抓取亚马逊商品和类目数据。",
1818
+ category: "网络与智能",
1819
+ },
1820
+ behavior: "data",
1821
+ },
1822
+
1823
+ // 浏览器会话工具
1824
+ {
1825
+ id: "browserCloseSession",
1826
+ schema: browser_closeSession_Schema,
1827
+ executor: browser_closeSession_Func,
1828
+ description: {
1829
+ name: "browser_closeSession",
1830
+ description: "关闭浏览器会话并释放服务器槽位。",
1831
+ category: "网络与智能",
1832
+ },
1833
+ behavior: "action",
1834
+ },
1835
+ {
1836
+ id: "browserOpenSession",
1837
+ schema: browser_openSession_Schema,
1838
+ executor: browser_openSession_Func,
1839
+ description: {
1840
+ name: "browser_openSession",
1841
+ description: "打开一个新的浏览器会话并导航到 URL,返回会话ID",
1842
+ category: "网络与智能",
1843
+ },
1844
+ behavior: "action",
1845
+ },
1846
+ {
1847
+ id: "browserSelectOption",
1848
+ schema: browser_selectOption_Schema,
1849
+ executor: browser_selectOption_Func,
1850
+ description: {
1851
+ name: "browser_selectOption",
1852
+ description: "在浏览器会话中选择一个下拉框选项",
1853
+ category: "网络与智能",
1854
+ },
1855
+ behavior: "action",
1856
+ },
1857
+ {
1858
+ id: "browserClick",
1859
+ schema: browser_click_Schema,
1860
+ executor: browser_click_Func,
1861
+ description: {
1862
+ name: "browser_click",
1863
+ description: "在浏览器会话中点击指定元素 (例如按钮、链接)。",
1864
+ category: "网络与智能",
1865
+ },
1866
+ behavior: "action",
1867
+ },
1868
+ {
1869
+ id: "browserTypeText",
1870
+ schema: browser_typeText_Schema,
1871
+ executor: browser_typeText_Func,
1872
+ description: {
1873
+ name: "browser_typeText",
1874
+ description: "在浏览器会话中向输入框填写文本 (可选回车)。",
1875
+ category: "网络与智能",
1876
+ },
1877
+ behavior: "action",
1878
+ },
1879
+ {
1880
+ id: "browserReadContent",
1881
+ schema: browser_readContent_Schema,
1882
+ executor: browser_readContent_Func,
1883
+ description: {
1884
+ name: "browser_readContent",
1885
+ description: "读取当前浏览器页面或指定元素的可见文本内容。",
1886
+ category: "网络与智能",
1887
+ },
1888
+ behavior: "data",
1889
+ },
1890
+ {
1891
+ id: "exaSearch",
1892
+ schema: exaSearchSchema,
1893
+ executor: exaSearchFunc,
1894
+ description: {
1895
+ name: "exa_search",
1896
+ description: "使用 Exa 神经网络搜索引擎获取高质量、结构化的网络信息(包含正文)。",
1897
+ category: "网络与智能",
1898
+ },
1899
+ behavior: "data",
1900
+ },
1901
+ {
1902
+ id: "olmOcr",
1903
+ schema: olmOcrSchema,
1904
+ executor: olmOcrFunc,
1905
+ description: {
1906
+ name: "olm_ocr",
1907
+ description: "使用 olmOCR-2-7B-1025 进行图片文字识别,适合文档、论文等结构化文本的高质量识别。",
1908
+ category: "网络与智能",
1909
+ },
1910
+ behavior: "data",
1911
+ },
1912
+ {
1913
+ id: "whisperTurbo",
1914
+ schema: whisperTurboSchema,
1915
+ executor: whisperTurboFunc,
1916
+ description: {
1917
+ name: "whisper_turbo",
1918
+ description: "使用 whisper-large-v3-turbo 快速转录音频为文字,支持多语言,速度快价格低。",
1919
+ category: "音频与媒体",
1920
+ },
1921
+ behavior: "data",
1922
+ },
1923
+ {
1924
+ id: "whisperV3",
1925
+ schema: whisperV3Schema,
1926
+ executor: whisperV3Func,
1927
+ description: {
1928
+ name: "whisper_v3",
1929
+ description: "使用 whisper-large-v3 高精度转录音频,中文/多语言准确率更高,适合对质量要求严格的场景。",
1930
+ category: "音频与媒体",
1931
+ },
1932
+ behavior: "data",
1933
+ },
1934
+
1935
+ // --- Cloudflare Browser Rendering ---
1936
+
1937
+ {
1938
+ id: "cfScreenshot",
1939
+ schema: cfScreenshotFunctionSchema,
1940
+ executor: cfScreenshotFunc,
1941
+ description: {
1942
+ name: "cfScreenshot",
1943
+ description: "使用 Cloudflare Browser Rendering 对网页或 HTML 截图,支持全页截图和自定义视口。",
1944
+ category: "网络与智能",
1945
+ },
1946
+ behavior: "data",
1947
+ uiGroup: "general",
1948
+ },
1949
+ {
1950
+ id: "cfGetMarkdown",
1951
+ schema: cfGetMarkdownFunctionSchema,
1952
+ executor: cfGetMarkdownFunc,
1953
+ description: {
1954
+ name: "cfGetMarkdown",
1955
+ description: "使用 Cloudflare Browser Rendering 将网页转为 Markdown,支持 JS 渲染,速度快于多页爬取。",
1956
+ category: "网络与智能",
1957
+ },
1958
+ behavior: "data",
1959
+ uiGroup: "general",
1960
+ },
1961
+ {
1962
+ id: "cfGeneratePDF",
1963
+ schema: cfGeneratePDFFunctionSchema,
1964
+ executor: cfGeneratePDFFunc,
1965
+ description: {
1966
+ name: "cfGeneratePDF",
1967
+ description: "使用 Cloudflare Browser Rendering 将网页或 HTML 渲染为 PDF 文件,适合文档导出。",
1968
+ category: "文档生成",
1969
+ },
1970
+ behavior: "action",
1971
+ uiGroup: "general",
1972
+ },
1973
+ {
1974
+ id: "cfExtractJSON",
1975
+ schema: cfExtractJSONFunctionSchema,
1976
+ executor: cfExtractJSONFunc,
1977
+ description: {
1978
+ name: "cfExtractJSON",
1979
+ description: "使用 Cloudflare Browser Rendering + AI 从网页提取结构化 JSON 数据,用自然语言描述需要的字段。",
1980
+ category: "网络与智能",
1981
+ },
1982
+ behavior: "data",
1983
+ uiGroup: "general",
1984
+ },
1985
+ {
1986
+ id: "appPreflight",
1987
+ schema: appPreflightFunctionSchema,
1988
+ executor: appPreflightFunc,
1989
+ description: {
1990
+ name: "appPreflight",
1991
+ description: "在部署前检查应用结构、依赖、图标与常见构建问题。",
1992
+ category: "应用部署",
1993
+ },
1994
+ behavior: "data",
1995
+ uiGroup: "general",
1996
+ },
1997
+ {
1998
+ id: "appDeploy",
1999
+ schema: appDeployFunctionSchema,
2000
+ executor: appDeployFunc,
2001
+ description: {
2002
+ name: "appDeploy",
2003
+ description: "将 JavaScript/TypeScript 代码部署为平台托管的 Web 应用。",
2004
+ category: "应用部署",
2005
+ },
2006
+ behavior: "data",
2007
+ uiGroup: "general",
2008
+ },
2009
+ {
2010
+ id: "appList",
2011
+ schema: appListFunctionSchema,
2012
+ executor: appListFunc,
2013
+ description: {
2014
+ name: "appList",
2015
+ description: "列出当前用户已部署的所有应用,包括名称、appId 和访问 URL。",
2016
+ category: "应用部署",
2017
+ },
2018
+ behavior: "data",
2019
+ uiGroup: "general",
2020
+ },
2021
+ {
2022
+ id: "appDelete",
2023
+ schema: appDeleteFunctionSchema,
2024
+ executor: appDeleteFunc,
2025
+ description: {
2026
+ name: "appDelete",
2027
+ description: "删除一个已部署的应用,删除后 URL 立即失效。",
2028
+ category: "应用部署",
2029
+ },
2030
+ behavior: "data",
2031
+ uiGroup: "general",
2032
+ },
2033
+ {
2034
+ id: "appRead",
2035
+ schema: appReadFunctionSchema,
2036
+ executor: appReadFunc,
2037
+ description: {
2038
+ name: "appRead",
2039
+ description: "读取已部署应用的当前代码,修改应用前必须先调用此工具获取现有代码。",
2040
+ category: "应用部署",
2041
+ },
2042
+ behavior: "data",
2043
+ uiGroup: "general",
2044
+ },
2045
+ {
2046
+ id: "cfSpeechToText",
2047
+ schema: cfSpeechToTextFunctionSchema,
2048
+ executor: cfSpeechToTextFunc,
2049
+ description: {
2050
+ name: "cfSpeechToText",
2051
+ description: "使用 Cloudflare Workers AI (@cf/openai/whisper) 将音频文件转换为文字,支持多语言自动识别。",
2052
+ category: "媒体处理",
2053
+ },
2054
+ behavior: "data",
2055
+ uiGroup: "general",
2056
+ },
2057
+ {
2058
+ id: "execShell",
2059
+ schema: execShellFunctionSchema,
2060
+ executor: execShellFunc,
2061
+ description: {
2062
+ name: "exec_shell",
2063
+ description:
2064
+ "通过后端 shell 执行接口运行跨平台命令:Windows 优先 PowerShell,Linux/macOS 使用 bash,仅用于本地开发调试。",
2065
+ category: "网络与智能",
2066
+ },
2067
+ behavior: "action",
2068
+ },
2069
+ {
2070
+ id: "checkEnv",
2071
+ schema: checkEnvFunctionSchema,
2072
+ executor: checkEnvFunc,
2073
+ description: {
2074
+ name: "checkEnv",
2075
+ description:
2076
+ "执行环境检查(当前默认并支持 build),用于代码变更后的快速生效前验证。",
2077
+ category: "网络与智能",
2078
+ },
2079
+ behavior: "action",
2080
+ uiGroup: "data",
2081
+ },
2082
+
2083
+ // --- 多媒体生成 / 文档生成 ---
2084
+
2085
+ {
2086
+ id: "geminiFlashImage",
2087
+ schema: geminiFlashImageFunctionSchema,
2088
+ executor: geminiFlashImageFunc,
2089
+ description: {
2090
+ name: "geminiFlashImage",
2091
+ description:
2092
+ "使用 Gemini 2.5 Flash 模型,根据文字说明和可选输入图片生成图像,适合文生图和轻量编辑。",
2093
+ category: "多媒体生成",
2094
+ },
2095
+ behavior: "action",
2096
+ uiGroup: "media",
2097
+ },
2098
+ {
2099
+ id: "geminiProImagePreview",
2100
+ schema: geminiProImagePreviewFunctionSchema,
2101
+ executor: geminiProImagePreviewFunc,
2102
+ description: {
2103
+ name: "geminiProImagePreview",
2104
+ description:
2105
+ "使用 Gemini 3 Pro Image Preview 模型,基于一张或多张输入图片进行复杂编辑和多图合成。",
2106
+ category: "多媒体生成",
2107
+ },
2108
+ behavior: "action",
2109
+ uiGroup: "media",
2110
+ },
2111
+ {
2112
+ id: "openAIGptImageGenerate",
2113
+ schema: openAIGptImageGenerateFunctionSchema,
2114
+ executor: openAIGptImageGenerateFunc,
2115
+ description: {
2116
+ name: "openAIGptImageGenerate",
2117
+ description:
2118
+ "使用 OpenAI GPT Image 2 生成新图片,适合文本出图与基于参考图的单次新图生成。",
2119
+ category: "多媒体生成",
2120
+ },
2121
+ behavior: "action",
2122
+ uiGroup: "media",
2123
+ },
2124
+ {
2125
+ id: "openAIGptImageEdit",
2126
+ schema: openAIGptImageEditFunctionSchema,
2127
+ executor: openAIGptImageEditFunc,
2128
+ description: {
2129
+ name: "openAIGptImageEdit",
2130
+ description:
2131
+ "使用 OpenAI GPT Image 2 编辑现有图片,适合多图参考、局部修改与连续改图。",
2132
+ category: "多媒体生成",
2133
+ },
2134
+ behavior: "action",
2135
+ uiGroup: "media",
2136
+ },
2137
+ {
2138
+ id: "openAIGptImage",
2139
+ schema: openAIGptImageFunctionSchema,
2140
+ executor: openAIGptImageFunc,
2141
+ description: {
2142
+ name: "openAIGptImage",
2143
+ description:
2144
+ "使用 OpenAI GPT Image 1.5 生成或编辑图片,适合项目页素材、海报、插画和改图。",
2145
+ category: "多媒体生成",
2146
+ },
2147
+ behavior: "action",
2148
+ uiGroup: "media",
2149
+ },
2150
+ {
2151
+ id: "remotionRenderVideo",
2152
+ schema: remotionRenderVideoFunctionSchema,
2153
+ executor: remotionRenderVideoFunc,
2154
+ description: {
2155
+ name: "remotionRenderVideo",
2156
+ description:
2157
+ "使用平台内 Remotion 模板渲染手机传播视频或产品介绍视频,并保存为 MP4。",
2158
+ category: "多媒体生成",
2159
+ },
2160
+ behavior: "action",
2161
+ uiGroup: "media",
2162
+ capability: "general",
2163
+ riskLevel: "medium",
2164
+ costLevel: "medium",
2165
+ defaultConsent: "ask",
2166
+ cancelable: true,
2167
+ },
2168
+ {
2169
+ id: "generateDocx",
2170
+ schema: generateDocxFunctionSchema,
2171
+ executor: generateDocxFunc,
2172
+ description: {
2173
+ name: "generateDocx",
2174
+ description:
2175
+ "在浏览器端根据指定 DOCX 模板 URL 和变量生成文档,并触发下载。",
2176
+ category: "文档生成",
2177
+ },
2178
+ behavior: "action",
2179
+ },
2180
+ ];
2181
+
2182
+ // 汇总所有工具定义:基础工具 + Agent 分组 + 代码分组
2183
+ const toolDefinitions: ToolDefinition[] = [
2184
+ ...baseToolDefinitions,
2185
+ ...agentToolDefinitions,
2186
+ ...codeToolDefinitions,
2187
+ ];
2188
+
2189
+ /* ==================================================================
2190
+ * 3.1 动态为 createAgent / updateAgent 的 tools 字段补 enum
2191
+ * ================================================================== */
2192
+
2193
+ // 所有函数工具的 schema.name 列表
2194
+ const ALL_TOOL_FUNCTION_NAMES: string[] = toolDefinitions
2195
+ .map((tool) => tool.schema?.name)
2196
+ .filter((name): name is string => Boolean(name));
2197
+
2198
+ // Agent 可用的工具名:保留 ui_ask_choice,排除 toolquery 和默认开启的浏览器/搜索工具
2199
+ const AGENT_AVAILABLE_TOOL_NAMES = ALL_TOOL_FUNCTION_NAMES.filter(
2200
+ (name) =>
2201
+ name !== "toolquery" &&
2202
+ !name.startsWith("browser_") &&
2203
+ name !== "exa_search"
2204
+ );
2205
+
2206
+ // 给 createAgent / updateAgent 的 tools 参数 items 动态挂 enum
2207
+ export const patchAgentToolSchemas = () => {
2208
+ try {
2209
+ const createAgentToolsProp =
2210
+ createAgentToolFunctionSchema?.parameters?.properties?.tools;
2211
+ if (createAgentToolsProp?.items && !(createAgentToolsProp.items as any).enum) {
2212
+ (createAgentToolsProp.items as any).enum = AGENT_AVAILABLE_TOOL_NAMES;
2213
+ }
2214
+
2215
+ const updateAgentToolsProp =
2216
+ updateAgentToolFunctionSchema?.parameters?.properties?.tools;
2217
+ if (updateAgentToolsProp?.items && !(updateAgentToolsProp.items as any).enum) {
2218
+ (updateAgentToolsProp.items as any).enum = AGENT_AVAILABLE_TOOL_NAMES;
2219
+ }
2220
+ } catch {
2221
+ // 静默失败即可,不影响其他工具
2222
+ }
2223
+ };
2224
+
2225
+ patchAgentToolSchemas();
2226
+
2227
+ /* ==================================================================
2228
+ * 4. 程序化生成所需的各个对象
2229
+ * ================================================================== */
2230
+
2231
+ export const toolRegistry: Record<string, any> = toolDefinitions.reduce(
2232
+ (acc, tool) => {
2233
+ acc[tool.schema.name] = { type: "function", function: tool.schema };
2234
+ return acc;
2235
+ },
2236
+ {} as Record<string, any>
2237
+ );
2238
+
2239
+ export const toolExecutors: Record<string, ToolDefinition["executor"]> =
2240
+ toolDefinitions.reduce(
2241
+ (acc, tool) => {
2242
+ acc[tool.schema.name] = tool.executor;
2243
+ return acc;
2244
+ },
2245
+ {} as Record<string, ToolDefinition["executor"]>
2246
+ );
2247
+
2248
+ export const toolDescriptions: Record<string, ToolDefinition["description"]> =
2249
+ toolDefinitions.reduce(
2250
+ (acc, tool) => {
2251
+ acc[tool.schema.name] = tool.description;
2252
+ return acc;
2253
+ },
2254
+ {} as Record<string, ToolDefinition["description"]>
2255
+ );
2256
+
2257
+ export const toolDefinitionsByName: Record<string, ToolDefinition> =
2258
+ toolDefinitions.reduce(
2259
+ (acc, tool) => {
2260
+ acc[tool.schema.name] = tool;
2261
+ return acc;
2262
+ },
2263
+ {} as Record<string, ToolDefinition>
2264
+ );
2265
+
2266
+ /* ==================================================================
2267
+ * 5. 工具查找辅助函数
2268
+ * ================================================================== */
2269
+ const normalizeToolName = (name: string): string =>
2270
+ name.replace(/[-_]/g, "").toLowerCase();
2271
+
2272
+ export const findToolExecutor = (
2273
+ rawName: string
2274
+ ): {
2275
+ executor: ToolDefinition["executor"];
2276
+ canonicalName: string;
2277
+ } => {
2278
+ const normalizedRawName = normalizeToolName(canonicalizeToolName(rawName));
2279
+ const canonicalName = Object.keys(toolExecutors).find(
2280
+ (key) => normalizeToolName(key) === normalizedRawName
2281
+ );
2282
+
2283
+ if (canonicalName && toolExecutors[canonicalName]) {
2284
+ return {
2285
+ executor: toolExecutors[canonicalName],
2286
+ canonicalName,
2287
+ };
2288
+ }
2289
+ throw new Error(`执行器未找到:未知工具 "${rawName}"`);
2290
+ };