nolo-cli 0.1.39 → 0.1.41

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