nolo-cli 0.1.45 → 0.1.47

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 (615) hide show
  1. package/README.md +272 -118
  2. package/index.js +73946 -0
  3. package/package.json +10 -635
  4. package/LICENSE +0 -21
  5. package/agent-runtime/agentConfigOptions.ts +0 -12
  6. package/agent-runtime/agentRecordConfig.ts +0 -101
  7. package/agent-runtime/agentRecordKeys.ts +0 -14
  8. package/agent-runtime/agentThread.ts +0 -222
  9. package/agent-runtime/agentThreadAdmission.ts +0 -74
  10. package/agent-runtime/dialogMessageRecord.ts +0 -16
  11. package/agent-runtime/dialogWritePlan.ts +0 -211
  12. package/agent-runtime/hostAdapter.ts +0 -81
  13. package/agent-runtime/hybridRecordStore.ts +0 -170
  14. package/agent-runtime/index.ts +0 -184
  15. package/agent-runtime/localDialogRead.ts +0 -23
  16. package/agent-runtime/localLoop.ts +0 -334
  17. package/agent-runtime/localToolPolicy.ts +0 -179
  18. package/agent-runtime/localWorkspaceTools.ts +0 -2310
  19. package/agent-runtime/noloWorkspaceTools.ts +0 -390
  20. package/agent-runtime/openAiCompatibleProvider.ts +0 -74
  21. package/agent-runtime/openAiCompatibleProviderConfig.ts +0 -27
  22. package/agent-runtime/platformChatProvider.ts +0 -229
  23. package/agent-runtime/providerResolution.ts +0 -302
  24. package/agent-runtime/runtimeDecision.ts +0 -70
  25. package/agent-runtime/runtimeFacts.ts +0 -40
  26. package/agent-runtime/runtimeToolPolicy.ts +0 -191
  27. package/agent-runtime/runtimeToolSurface.ts +0 -199
  28. package/agent-runtime/shellCommandPolicy.ts +0 -120
  29. package/agent-runtime/types.ts +0 -137
  30. package/agentAliases.ts +0 -40
  31. package/agentCommandSupport.ts +0 -81
  32. package/agentInternalCommandEntries.ts +0 -44
  33. package/agentListCommands.ts +0 -185
  34. package/agentListHelpers.ts +0 -242
  35. package/agentMachineCommands.ts +0 -426
  36. package/agentNameResolver.ts +0 -164
  37. package/agentPullCommand.ts +0 -142
  38. package/agentRecordCommands.ts +0 -224
  39. package/agentRecordHelpers.ts +0 -592
  40. package/agentRunCommand.ts +0 -568
  41. package/agentRuntimeCommands.ts +0 -7
  42. package/agentRuntimeLocal.ts +0 -45
  43. package/ai/agent/_executeModel.ts +0 -146
  44. package/ai/agent/agentSlice.ts +0 -557
  45. package/ai/agent/appWorkingMemory.ts +0 -126
  46. package/ai/agent/buildEditingContext.ts +0 -378
  47. package/ai/agent/buildSystemPrompt.ts +0 -599
  48. package/ai/agent/canvasEditingContext.ts +0 -49
  49. package/ai/agent/cleanAgentMessages.ts +0 -140
  50. package/ai/agent/cliChatClient.ts +0 -153
  51. package/ai/agent/cliExecutor.ts +0 -1465
  52. package/ai/agent/cliPrompt.ts +0 -10
  53. package/ai/agent/contextCompiler.ts +0 -107
  54. package/ai/agent/contextLayerContract.ts +0 -44
  55. package/ai/agent/createAgentSchema.ts +0 -272
  56. package/ai/agent/currentTimeContext.ts +0 -65
  57. package/ai/agent/executeToolCall.ts +0 -58
  58. package/ai/agent/fetchAgentContexts.ts +0 -42
  59. package/ai/agent/generatePrompt.ts +0 -3
  60. package/ai/agent/getFullChatContextKeys.ts +0 -168
  61. package/ai/agent/guidedCreation/capabilities.ts +0 -84
  62. package/ai/agent/guidedCreation/types.ts +0 -38
  63. package/ai/agent/isLiveAudioOnlyAgent.ts +0 -26
  64. package/ai/agent/liveAudioModel.ts +0 -2
  65. package/ai/agent/machineRunPermissions.ts +0 -113
  66. package/ai/agent/pageBuilderHandoffRules.ts +0 -75
  67. package/ai/agent/persistMessageWithFixedId.ts +0 -37
  68. package/ai/agent/planSlice.ts +0 -259
  69. package/ai/agent/referenceUtils.ts +0 -229
  70. package/ai/agent/runAgentBackground.ts +0 -310
  71. package/ai/agent/runAgentClientLoop.ts +0 -164
  72. package/ai/agent/runtimeGuidance.ts +0 -116
  73. package/ai/agent/serverOrigin.ts +0 -7
  74. package/ai/agent/startParallelAgentStreams.ts +0 -424
  75. package/ai/agent/startupProtocol.ts +0 -53
  76. package/ai/agent/streamAgentChatTurn.ts +0 -2135
  77. package/ai/agent/streamAgentChatTurnUtils.ts +0 -923
  78. package/ai/agent/toolFailureGuard.ts +0 -99
  79. package/ai/agent/types.ts +0 -73
  80. package/ai/agent/utils/imageOutput.ts +0 -37
  81. package/ai/agent/utils/publicImageAgentMode.ts +0 -26
  82. package/ai/agent.ts +0 -2
  83. package/ai/ai.locale.ts +0 -1165
  84. package/ai/chat/accumulateToolCallChunks.ts +0 -126
  85. package/ai/chat/fetchUtils.ts +0 -143
  86. package/ai/chat/inlineImageUrlsForCustomProvider.ts +0 -122
  87. package/ai/chat/parseApiError.ts +0 -67
  88. package/ai/chat/parseMultilineSSE.ts +0 -95
  89. package/ai/chat/sendOpenAICompletionsRequest.ts +0 -921
  90. package/ai/chat/sendOpenAIResponseRequest.ts +0 -720
  91. package/ai/chat/serverProxyRetry.ts +0 -102
  92. package/ai/chat/shouldUseServerProxy.ts +0 -18
  93. package/ai/chat/streamRetry.ts +0 -46
  94. package/ai/chat/updateTotalUsage.ts +0 -89
  95. package/ai/context/buildReferenceContext.ts +0 -437
  96. package/ai/context/retention.ts +0 -165
  97. package/ai/context/tokenUtils.ts +0 -78
  98. package/ai/index.ts +0 -1
  99. package/ai/llm/agentCapabilities.ts +0 -74
  100. package/ai/llm/deepinfra.ts +0 -79
  101. package/ai/llm/fireworks.ts +0 -68
  102. package/ai/llm/generateRequestBody.ts +0 -165
  103. package/ai/llm/getModelContextWindow.ts +0 -93
  104. package/ai/llm/getPricing.ts +0 -252
  105. package/ai/llm/imagePricing.ts +0 -66
  106. package/ai/llm/isResponseAPIModel.ts +0 -13
  107. package/ai/llm/kimi.ts +0 -22
  108. package/ai/llm/mimo.ts +0 -99
  109. package/ai/llm/mistral.ts +0 -21
  110. package/ai/llm/models.ts +0 -45
  111. package/ai/llm/openrouterModels.ts +0 -31
  112. package/ai/llm/providers.ts +0 -313
  113. package/ai/llm/reasoningModels.ts +0 -27
  114. package/ai/llm/types.ts +0 -82
  115. package/ai/llm/usageRequestOptions.ts +0 -59
  116. package/ai/memory/policy.ts +0 -49
  117. package/ai/memory/queryShared.ts +0 -167
  118. package/ai/memory/recentRelationshipRecap.ts +0 -251
  119. package/ai/memory/remember.ts +0 -111
  120. package/ai/memory/scope.ts +0 -74
  121. package/ai/memory/store.ts +0 -20
  122. package/ai/memory/storeShared.ts +0 -76
  123. package/ai/memory/types.ts +0 -52
  124. package/ai/memory/understanding.ts +0 -341
  125. package/ai/memory/understandingGreeting.ts +0 -264
  126. package/ai/policy/personalizationDialog.ts +0 -333
  127. package/ai/policy/runtimePolicy.ts +0 -526
  128. package/ai/policy/selfUpdateFields.ts +0 -48
  129. package/ai/policy/types.ts +0 -64
  130. package/ai/skills/referenceRuntime.ts +0 -274
  131. package/ai/skills/skillDiagnostics.ts +0 -251
  132. package/ai/skills/skillDocBuilder.ts +0 -139
  133. package/ai/skills/skillDocProtocol.ts +0 -526
  134. package/ai/skills/skillSummaryMarker.ts +0 -26
  135. package/ai/token/calculatePrice.ts +0 -576
  136. package/ai/token/missingUsageEstimate.ts +0 -42
  137. package/ai/token/normalizeUsage.ts +0 -124
  138. package/ai/token/openaiImageGenerationUsage.ts +0 -56
  139. package/ai/token/prepareTokenUsageData.ts +0 -93
  140. package/ai/token/resolveBillingTarget.ts +0 -52
  141. package/ai/token/saveTokenRecord.ts +0 -53
  142. package/ai/token/types.ts +0 -103
  143. package/ai/tools/agent/agentTools.ts +0 -214
  144. package/ai/tools/agent/agentUpdateShared.ts +0 -311
  145. package/ai/tools/agent/callAgentTool.ts +0 -139
  146. package/ai/tools/agent/createAgentTool.ts +0 -512
  147. package/ai/tools/agent/createDialogTool.ts +0 -69
  148. package/ai/tools/agent/createSkillAgentTool.ts +0 -62
  149. package/ai/tools/agent/parallelBudget.ts +0 -221
  150. package/ai/tools/agent/prepareAgentDraftTool.ts +0 -159
  151. package/ai/tools/agent/presets/appBuilderPreset.ts +0 -154
  152. package/ai/tools/agent/runLlmTool.ts +0 -96
  153. package/ai/tools/agent/runStreamingAgentTool.ts +0 -73
  154. package/ai/tools/agent/skillAgentArgs.ts +0 -106
  155. package/ai/tools/agent/startAgentDialogTool.ts +0 -54
  156. package/ai/tools/agent/streamParallelAgentsTool.ts +0 -123
  157. package/ai/tools/agent/updateAgentTool.ts +0 -96
  158. package/ai/tools/agent/updateSelfTool.ts +0 -113
  159. package/ai/tools/amazonProductScraperTool.ts +0 -86
  160. package/ai/tools/apifyActorClient.ts +0 -45
  161. package/ai/tools/appEditGuard.ts +0 -372
  162. package/ai/tools/appReadSnapshot.ts +0 -153
  163. package/ai/tools/appTools.ts +0 -1549
  164. package/ai/tools/applyEditTool.ts +0 -259
  165. package/ai/tools/applyLineEditsTool.ts +0 -315
  166. package/ai/tools/browserTools/click.ts +0 -33
  167. package/ai/tools/browserTools/closeSession.ts +0 -29
  168. package/ai/tools/browserTools/common.ts +0 -27
  169. package/ai/tools/browserTools/openSession.ts +0 -48
  170. package/ai/tools/browserTools/readContent.ts +0 -38
  171. package/ai/tools/browserTools/selectOption.ts +0 -46
  172. package/ai/tools/browserTools/typeText.ts +0 -42
  173. package/ai/tools/category/createCategoryTool.ts +0 -66
  174. package/ai/tools/category/queryContentsByCategoryTool.ts +0 -69
  175. package/ai/tools/category/updateContentCategoryTool.ts +0 -75
  176. package/ai/tools/cfBrowserTools.ts +0 -319
  177. package/ai/tools/cfSpeechToTextTool.ts +0 -49
  178. package/ai/tools/checkEnvTool.ts +0 -102
  179. package/ai/tools/cloudflareCrawlTool.ts +0 -289
  180. package/ai/tools/codeSearchTool.ts +0 -123
  181. package/ai/tools/codeTools.ts +0 -101
  182. package/ai/tools/convertMarxistsBookTool.ts +0 -103
  183. package/ai/tools/createDocTool.ts +0 -132
  184. package/ai/tools/createSkillDocTool.ts +0 -155
  185. package/ai/tools/createWorkflowTool.ts +0 -154
  186. package/ai/tools/delayTool.ts +0 -31
  187. package/ai/tools/deleteSpacesTool.ts +0 -325
  188. package/ai/tools/deleteSpacesToolModel.ts +0 -159
  189. package/ai/tools/devReloadUtils.ts +0 -29
  190. package/ai/tools/dialogMessageSearch.ts +0 -137
  191. package/ai/tools/doctorSkillTool.ts +0 -72
  192. package/ai/tools/ecommerceScraperTool.ts +0 -86
  193. package/ai/tools/emailTools.ts +0 -549
  194. package/ai/tools/evalSkillTool.ts +0 -92
  195. package/ai/tools/exaSearchTool.ts +0 -63
  196. package/ai/tools/execShellTool.ts +0 -266
  197. package/ai/tools/executeSqlTool.ts +0 -192
  198. package/ai/tools/fetchWebpageSupport.ts +0 -333
  199. package/ai/tools/fetchWebpageTool.ts +0 -97
  200. package/ai/tools/geminiImagePreviewTool.ts +0 -386
  201. package/ai/tools/generateDocxTool.ts +0 -215
  202. package/ai/tools/googleSearchScraperTool.ts +0 -106
  203. package/ai/tools/importDataTool.ts +0 -133
  204. package/ai/tools/importSkillTool.ts +0 -162
  205. package/ai/tools/index.ts +0 -2290
  206. package/ai/tools/jdProductScraperTool.ts +0 -821
  207. package/ai/tools/listUserSpacesTool.ts +0 -113
  208. package/ai/tools/localFilesTool.ts +0 -276
  209. package/ai/tools/marxistsOfflineBook.ts +0 -253
  210. package/ai/tools/modelUsageTools.ts +0 -206
  211. package/ai/tools/noloWorkspaceReadTools.ts +0 -467
  212. package/ai/tools/olmOcrTool.ts +0 -33
  213. package/ai/tools/openaiImageTool.ts +0 -267
  214. package/ai/tools/prepareTools.ts +0 -193
  215. package/ai/tools/readDocTool.ts +0 -88
  216. package/ai/tools/readFileTool.ts +0 -214
  217. package/ai/tools/readTool.ts +0 -194
  218. package/ai/tools/readXPostTool.ts +0 -229
  219. package/ai/tools/readXhsProfileTool.ts +0 -638
  220. package/ai/tools/rememberMemoryTool.ts +0 -84
  221. package/ai/tools/remotionVideoTool.ts +0 -151
  222. package/ai/tools/searchDialogMessagesTool.ts +0 -222
  223. package/ai/tools/searchWorkspaceTool.ts +0 -259
  224. package/ai/tools/skillFollowup.ts +0 -86
  225. package/ai/tools/surfWeatherTool.ts +0 -169
  226. package/ai/tools/table/addTableRowTool.ts +0 -217
  227. package/ai/tools/table/createTableTool.ts +0 -326
  228. package/ai/tools/table/rowTools.ts +0 -386
  229. package/ai/tools/table/schemaTools.ts +0 -244
  230. package/ai/tools/table/shareTableTool.ts +0 -148
  231. package/ai/tools/table/toolShared.ts +0 -129
  232. package/ai/tools/taobaoTmallProductScraperTool.ts +0 -49
  233. package/ai/tools/toolApiClient.ts +0 -279
  234. package/ai/tools/toolNameAliases.ts +0 -70
  235. package/ai/tools/toolPacks.ts +0 -19
  236. package/ai/tools/toolResultError.ts +0 -42
  237. package/ai/tools/toolRunSlice.ts +0 -303
  238. package/ai/tools/toolSchemaCompatibility.ts +0 -53
  239. package/ai/tools/uiAskChoiceTool.ts +0 -104
  240. package/ai/tools/updateContentTitleTool.ts +0 -84
  241. package/ai/tools/updateDocTool.ts +0 -105
  242. package/ai/tools/updateUserPreferenceProfileTool.ts +0 -153
  243. package/ai/tools/wereadGatewayTool.ts +0 -152
  244. package/ai/tools/whisperTool.ts +0 -76
  245. package/ai/tools/writeFileTool.ts +0 -213
  246. package/ai/tools/youtubeScraperTool.ts +0 -116
  247. package/ai/tools/ziweiChartTool.ts +0 -678
  248. package/ai/types.ts +0 -58
  249. package/ai/workflow/workflowExecutor.ts +0 -323
  250. package/ai/workflow/workflowSlice.ts +0 -73
  251. package/ai/workflow/workflowTypes.ts +0 -106
  252. package/app/actions/syncAppRecord.ts +0 -73
  253. package/app/constants/animationSets.ts +0 -21
  254. package/app/constants/appEditor.ts +0 -99
  255. package/app/favorite/deletedFavoriteProjection.ts +0 -31
  256. package/app/favorite/favoriteSlice.ts +0 -690
  257. package/app/favorite/type.ts +0 -43
  258. package/app/hooks/deleteDbKey.ts +0 -254
  259. package/app/i18n/client.ts +0 -13
  260. package/app/i18n/i18n.base.ts +0 -14
  261. package/app/i18n/i18n.config.ts +0 -77
  262. package/app/i18n/index.ts +0 -15
  263. package/app/i18n/mapLanguage.ts +0 -11
  264. package/app/i18n/translations/appBuilder.locale.ts +0 -453
  265. package/app/i18n/translations/error.locale.ts +0 -246
  266. package/app/i18n/translations/interface.locale.ts +0 -2206
  267. package/app/i18n/translations/pricing.locale.ts +0 -397
  268. package/app/i18n/translations/privacy.locale.ts +0 -168
  269. package/app/i18n/translations/seo.locale.ts +0 -129
  270. package/app/i18n/translations/terms.locale.ts +0 -124
  271. package/app/i18n/types.ts +0 -6
  272. package/app/notifications/model.ts +0 -77
  273. package/app/notifications/notificationSlice.ts +0 -141
  274. package/app/reducer.ts +0 -36
  275. package/app/settings/dbActionThunks.ts +0 -34
  276. package/app/settings/defaultSpacePreference.ts +0 -87
  277. package/app/settings/settingSlice.tsx +0 -1212
  278. package/app/settings/settingsRecord.ts +0 -8
  279. package/app/stateViews/runtime.ts +0 -90
  280. package/app/store.ts +0 -55
  281. package/app/theme/colors.ts +0 -280
  282. package/app/theme/fontPreference.ts +0 -77
  283. package/app/theme/theme.config.ts +0 -120
  284. package/app/theme/themeModeBootstrap.ts +0 -123
  285. package/app/types/appSummary.ts +0 -118
  286. package/app/types.ts +0 -358
  287. package/app/utils/appKeys.ts +0 -55
  288. package/app/utils/async.ts +0 -28
  289. package/app/utils/desktopAgentRuntimeTurnClient.ts +0 -75
  290. package/app/utils/env.ts +0 -17
  291. package/app/utils/fileUtils.ts +0 -229
  292. package/app/utils/imageUtils.ts +0 -274
  293. package/app/utils/myContentItems.ts +0 -317
  294. package/app/utils/retryAfter.ts +0 -36
  295. package/app/utils/retryFetch.ts +0 -61
  296. package/app/utils/toast.ts +0 -3
  297. package/auth/action/signUpAction.ts +0 -227
  298. package/auth/adminPermissions.ts +0 -78
  299. package/auth/authSlice.ts +0 -531
  300. package/auth/client/loginRequest.ts +0 -14
  301. package/auth/resetAuthScopedClientState.ts +0 -27
  302. package/auth/routes.ts +0 -183
  303. package/auth/token.ts +0 -63
  304. package/auth/types.ts +0 -40
  305. package/authCommands.ts +0 -230
  306. package/chat/chat.locale.ts +0 -817
  307. package/chat/dialog/actions/addCybotAction.ts +0 -52
  308. package/chat/dialog/actions/addReferenceKeysAction.ts +0 -62
  309. package/chat/dialog/actions/builtinDialogLlm.ts +0 -35
  310. package/chat/dialog/actions/cleanupCliSession.ts +0 -40
  311. package/chat/dialog/actions/createDialogAction.ts +0 -379
  312. package/chat/dialog/actions/createScheduledTaskAction.ts +0 -78
  313. package/chat/dialog/actions/handleSendMessageAction.ts +0 -202
  314. package/chat/dialog/actions/handleSendMessageResolver.ts +0 -27
  315. package/chat/dialog/actions/removeCybotAction.ts +0 -6
  316. package/chat/dialog/actions/removeDialogAgentAction.ts +0 -44
  317. package/chat/dialog/actions/replacePrimaryCybotAction.ts +0 -6
  318. package/chat/dialog/actions/setPrimaryDialogAgentAction.ts +0 -52
  319. package/chat/dialog/actions/updateDialogSummaryAction.ts +0 -430
  320. package/chat/dialog/actions/updateDialogTitleAction.ts +0 -151
  321. package/chat/dialog/actions/updateDialogTitlePolicy.ts +0 -30
  322. package/chat/dialog/actions/updateTokensAction.ts +0 -233
  323. package/chat/dialog/dialogAgents.ts +0 -72
  324. package/chat/dialog/dialogAttachmentCleanup.ts +0 -135
  325. package/chat/dialog/dialogSlice.ts +0 -985
  326. package/chat/dialog/dialogTitle.ts +0 -81
  327. package/chat/dialog/dialogTokenStats.ts +0 -12
  328. package/chat/dialog/dialogUrl.ts +0 -6
  329. package/chat/dialog/goal.ts +0 -108
  330. package/chat/dialog/objectAssistantRegistry.ts +0 -286
  331. package/chat/dialog/schedule.ts +0 -17
  332. package/chat/messages/activityCompletion.ts +0 -97
  333. package/chat/messages/fetchAndCacheMessages.ts +0 -119
  334. package/chat/messages/fetchConvMsgs.ts +0 -51
  335. package/chat/messages/fetchMessages.ts +0 -84
  336. package/chat/messages/fileUrl.ts +0 -13
  337. package/chat/messages/imagePayloadPersistence.ts +0 -22
  338. package/chat/messages/messageAgent.ts +0 -8
  339. package/chat/messages/messageContent.ts +0 -203
  340. package/chat/messages/messageContract.ts +0 -88
  341. package/chat/messages/messageSlice.ts +0 -1386
  342. package/chat/messages/toolThunks.ts +0 -646
  343. package/chat/messages/types.ts +0 -192
  344. package/chat/messages/web/toolDisplayName.ts +0 -686
  345. package/cli/agentAliases.ts +0 -40
  346. package/cli/agentCommandSupport.ts +0 -81
  347. package/cli/agentInternalCommandEntries.ts +0 -44
  348. package/cli/agentListCommands.ts +0 -185
  349. package/cli/agentListHelpers.ts +0 -242
  350. package/cli/agentMachineCommands.ts +0 -426
  351. package/cli/agentNameResolver.ts +0 -164
  352. package/cli/agentPullCommand.ts +0 -142
  353. package/cli/agentRecordCommands.ts +0 -224
  354. package/cli/agentRecordHelpers.ts +0 -592
  355. package/cli/agentRunCommand.ts +0 -568
  356. package/cli/agentRuntimeLocal.ts +0 -45
  357. package/cli/authCommands.ts +0 -230
  358. package/cli/cliCommandAdapters.ts +0 -28
  359. package/cli/cliCommandDispatch.ts +0 -66
  360. package/cli/cliCommandFactories.ts +0 -66
  361. package/cli/cliCommandTypes.ts +0 -49
  362. package/cli/cliEnvHelpers.ts +0 -116
  363. package/cli/cliSpaceHelpers.ts +0 -39
  364. package/cli/client/agentConfigResolver.ts +0 -1
  365. package/cli/client/agentRun.ts +0 -735
  366. package/cli/client/compactDialog.ts +0 -222
  367. package/cli/client/hybridRecordStore.ts +0 -52
  368. package/cli/client/localAgentRecords.ts +0 -7
  369. package/cli/client/localDialogRecords.ts +0 -30
  370. package/cli/client/localProviderResolver.ts +0 -1
  371. package/cli/client/localRuntimeAdapter.ts +0 -1098
  372. package/cli/client/localToolPolicy.ts +0 -8
  373. package/cli/client/profileConfig.ts +0 -101
  374. package/cli/client/streamingOutput.ts +0 -38
  375. package/cli/commandRegistry.ts +0 -98
  376. package/cli/connectorRunArtifact.ts +0 -120
  377. package/cli/connectorWebSocketTarget.ts +0 -112
  378. package/cli/defaultServer.ts +0 -1
  379. package/cli/dialogAttachmentCleanup.ts +0 -151
  380. package/cli/dialogCommands.ts +0 -1120
  381. package/cli/dialogInternalCommandEntries.ts +0 -17
  382. package/cli/docCreateCommands.ts +0 -345
  383. package/cli/docInternalCommandEntries.ts +0 -11
  384. package/cli/docPageHelpers.ts +0 -80
  385. package/cli/docSkillHelpers.ts +0 -67
  386. package/cli/docSpaceHelpers.ts +0 -46
  387. package/cli/globalRecordOperations.ts +0 -258
  388. package/cli/internalCommandEntries.ts +0 -18
  389. package/cli/localRuntimeAuthority.ts +0 -182
  390. package/cli/localRuntimeDb.ts +0 -26
  391. package/cli/machineCommands.ts +0 -312
  392. package/cli/machineDaemonCommands.ts +0 -185
  393. package/cli/machineHeartbeatCommands.ts +0 -30
  394. package/cli/machineStatusCommands.ts +0 -95
  395. package/cli/machineWatchCommands.ts +0 -41
  396. package/cli/machineWsPromptMaterialization.ts +0 -89
  397. package/cli/machineWsRunDispatch.ts +0 -695
  398. package/cli/machineWsSession.ts +0 -213
  399. package/cli/memoryCommands.ts +0 -253
  400. package/cli/memoryInternalCommandEntries.ts +0 -9
  401. package/cli/offlineMarxistsAgentCommand.ts +0 -315
  402. package/cli/qoderUsageProbe.ts +0 -252
  403. package/cli/runtimeDoctorCommands.ts +0 -174
  404. package/cli/runtimeModeArgs.ts +0 -33
  405. package/cli/scriptCommandEntries.ts +0 -66
  406. package/cli/secretScan.ts +0 -31
  407. package/cli/systemInternalCommandEntries.ts +0 -65
  408. package/cli/tableCommands.ts +0 -453
  409. package/cli/tui/readlineWorkspace.ts +0 -210
  410. package/cli/tui/session.ts +0 -554
  411. package/cli/updateCommands.ts +0 -134
  412. package/cli/workflowInternalCommandEntries.ts +0 -10
  413. package/cliCommandAdapters.ts +0 -28
  414. package/cliCommandDispatch.ts +0 -66
  415. package/cliCommandFactories.ts +0 -66
  416. package/cliCommandTypes.ts +0 -49
  417. package/cliEnvHelpers.ts +0 -116
  418. package/cliSpaceHelpers.ts +0 -39
  419. package/client/agentConfigResolver.test.ts +0 -69
  420. package/client/agentConfigResolver.ts +0 -1
  421. package/client/agentRun.test.ts +0 -1346
  422. package/client/agentRun.ts +0 -735
  423. package/client/compactDialog.test.ts +0 -238
  424. package/client/compactDialog.ts +0 -222
  425. package/client/hybridRecordStore.test.ts +0 -157
  426. package/client/hybridRecordStore.ts +0 -52
  427. package/client/localAgentRecords.test.ts +0 -27
  428. package/client/localAgentRecords.ts +0 -7
  429. package/client/localDialogRecords.test.ts +0 -124
  430. package/client/localDialogRecords.ts +0 -30
  431. package/client/localProviderResolver.test.ts +0 -102
  432. package/client/localProviderResolver.ts +0 -1
  433. package/client/localRuntimeAdapter.test.ts +0 -2809
  434. package/client/localRuntimeAdapter.ts +0 -1098
  435. package/client/localRuntimeDryRun.test.ts +0 -135
  436. package/client/localToolPolicy.test.ts +0 -48
  437. package/client/localToolPolicy.ts +0 -8
  438. package/client/profileConfig.test.ts +0 -106
  439. package/client/profileConfig.ts +0 -101
  440. package/client/streamingOutput.test.ts +0 -22
  441. package/client/streamingOutput.ts +0 -38
  442. package/commandRegistry.ts +0 -98
  443. package/connector-experimental/capabilities.ts +0 -75
  444. package/connector-experimental/codexBinary.ts +0 -41
  445. package/connector-experimental/heartbeatLoop.ts +0 -22
  446. package/connector-experimental/machineInfo.ts +0 -46
  447. package/connector-experimental/protocol.ts +0 -54
  448. package/connectorRunArtifact.ts +0 -120
  449. package/connectorWebSocketTarget.ts +0 -112
  450. package/core/builtinAgents.ts +0 -209
  451. package/core/config.ts +0 -15
  452. package/core/crypto.ts +0 -51
  453. package/core/generateKeyPairFromSeedV1.ts +0 -15
  454. package/core/generateMainKey.ts +0 -22
  455. package/core/init.ts +0 -41
  456. package/core/localOrigins.ts +0 -8
  457. package/core/password.ts +0 -13
  458. package/core/prefix.ts +0 -23
  459. package/create/editor/transforms/fromMarkdown/index.ts +0 -260
  460. package/create/editor/transforms/fromMarkdown/inline.ts +0 -285
  461. package/create/editor/transforms/fromMarkdown/table.ts +0 -130
  462. package/create/editor/transforms/markdownToSlate.ts +0 -24
  463. package/create/editor/transforms/slateToRenderMarkdown.ts +0 -218
  464. package/create/editor/transforms/slateToSimplifiedMarkdown.ts +0 -224
  465. package/create/editor/transforms/slateToText.ts +0 -33
  466. package/create/editor/utils/slateUtils.ts +0 -233
  467. package/create/space/addSpaceAction.ts +0 -193
  468. package/create/space/category/categoryActions.ts +0 -427
  469. package/create/space/changeSpaceAction.ts +0 -36
  470. package/create/space/constants.ts +0 -8
  471. package/create/space/content/addContentAction.ts +0 -116
  472. package/create/space/content/contentThunks.ts +0 -90
  473. package/create/space/content/deleteContentFromSpaceAction.ts +0 -187
  474. package/create/space/content/deleteMultipleContentAction.ts +0 -112
  475. package/create/space/content/moveContentAction.ts +0 -285
  476. package/create/space/content/updateContentCategoryAction.ts +0 -154
  477. package/create/space/content/updateContentTitleAction.ts +0 -151
  478. package/create/space/content/uploadAndAddFileToSpaceAction.ts +0 -98
  479. package/create/space/contentKeyUtils.ts +0 -117
  480. package/create/space/deleteSpaceAction.ts +0 -276
  481. package/create/space/fetchSpaceAction.ts +0 -70
  482. package/create/space/fetchSpaceSidebarStateAction.ts +0 -26
  483. package/create/space/loadDefaultSpaceAction.ts +0 -57
  484. package/create/space/member/addMemberAction.ts +0 -79
  485. package/create/space/member/fetchUserSpaceMembershipsAction.ts +0 -386
  486. package/create/space/member/memberThunks.ts +0 -47
  487. package/create/space/member/removeMemberAction.ts +0 -67
  488. package/create/space/resolvePreferredSpaceId.ts +0 -113
  489. package/create/space/sidebarVisibleTypes.ts +0 -260
  490. package/create/space/space.locale.ts +0 -1087
  491. package/create/space/spaceAccess.ts +0 -182
  492. package/create/space/spaceCollapsedState.ts +0 -54
  493. package/create/space/spaceKeys.ts +0 -65
  494. package/create/space/spaceSlice.ts +0 -328
  495. package/create/space/spaceThunks.ts +0 -410
  496. package/create/space/types.ts +0 -27
  497. package/create/space/updateSpaceAction.ts +0 -107
  498. package/create/space/utils/permissions.ts +0 -47
  499. package/create/types.ts +0 -21
  500. package/database/actions/agentReadResolution.ts +0 -33
  501. package/database/actions/common.ts +0 -243
  502. package/database/actions/deleteFile.ts +0 -40
  503. package/database/actions/fileContent.ts +0 -125
  504. package/database/actions/patch.ts +0 -155
  505. package/database/actions/read.ts +0 -358
  506. package/database/actions/readAndWait.ts +0 -260
  507. package/database/actions/readRequestManager.ts +0 -120
  508. package/database/actions/readResolution.ts +0 -125
  509. package/database/actions/remove.ts +0 -94
  510. package/database/actions/replication.ts +0 -477
  511. package/database/actions/upload.ts +0 -186
  512. package/database/actions/upsert.ts +0 -56
  513. package/database/actions/write.ts +0 -146
  514. package/database/authority/ownerKey.ts +0 -80
  515. package/database/authority/recordAuthority.ts +0 -67
  516. package/database/authority/userAuthorityRegistry.ts +0 -54
  517. package/database/client/fetchUserData.ts +0 -61
  518. package/database/config.ts +0 -40
  519. package/database/dbActionThunks.ts +0 -1
  520. package/database/dbSlice.ts +0 -149
  521. package/database/fileRing.ts +0 -51
  522. package/database/fileStorage.ts +0 -232
  523. package/database/fileUrl.ts +0 -34
  524. package/database/keys.ts +0 -767
  525. package/database/queryPrefixes.ts +0 -14
  526. package/database/requests.ts +0 -443
  527. package/database/runtimeServerContext.ts +0 -54
  528. package/database/server/authorityStoreTypes.ts +0 -31
  529. package/database/server/cliAuthorityBrokerClient.ts +0 -227
  530. package/database/server/cliAuthorityBrokerServer.ts +0 -283
  531. package/database/server/cliAuthorityBrokerTypes.ts +0 -43
  532. package/database/server/cliAuthorityStoreDriver.ts +0 -98
  533. package/database/server/db.ts +0 -99
  534. package/database/server/dbPath.ts +0 -20
  535. package/database/server/ensureDbOpen.ts +0 -12
  536. package/database/server/legacyServerDb.ts +0 -58
  537. package/database/server/levelAuthorityStore.ts +0 -114
  538. package/database/server/memoryAuthorityStore.ts +0 -133
  539. package/database/server/serverStoreFactory.ts +0 -118
  540. package/database/tenantPlacement.ts +0 -57
  541. package/database/tombstones.ts +0 -52
  542. package/database/userDataMerge.ts +0 -95
  543. package/database/userPreferenceRegister.ts +0 -131
  544. package/database/utils/ulid.ts +0 -1
  545. package/defaultServer.ts +0 -1
  546. package/dialogAttachmentCleanup.ts +0 -151
  547. package/dialogCommands.ts +0 -1120
  548. package/dialogInternalCommandEntries.ts +0 -17
  549. package/docCreateCommands.ts +0 -345
  550. package/docInternalCommandEntries.ts +0 -11
  551. package/docPageHelpers.ts +0 -80
  552. package/docSkillHelpers.ts +0 -67
  553. package/docSpaceHelpers.ts +0 -46
  554. package/globalRecordOperations.ts +0 -258
  555. package/index.ts +0 -78
  556. package/integrations/anthropic/anthropicModels.ts +0 -47
  557. package/integrations/deepseek/models.ts +0 -37
  558. package/integrations/google/models.ts +0 -341
  559. package/integrations/openai/chatCompletionStreamMode.ts +0 -10
  560. package/integrations/openai/filterAndCleanMessages.ts +0 -284
  561. package/integrations/openai/flexTier.ts +0 -102
  562. package/integrations/openai/generateOpenAIRequestBody.ts +0 -271
  563. package/integrations/openai/generateResponseRequestBody.ts +0 -77
  564. package/integrations/openai/models.ts +0 -271
  565. package/integrations/openai/providerBodyCompatibility.ts +0 -23
  566. package/integrations/openai/responsesHelpers.ts +0 -297
  567. package/integrations/x-reader/types.ts +0 -109
  568. package/integrations/xai/models.ts +0 -13
  569. package/integrations/xhs-reader/redaction.ts +0 -68
  570. package/integrations/xhs-reader/types.ts +0 -277
  571. package/integrations/xhs-reader/url.ts +0 -80
  572. package/internalCommandEntries.ts +0 -18
  573. package/localRuntimeAuthority.ts +0 -182
  574. package/localRuntimeDb.ts +0 -26
  575. package/machineCommands.ts +0 -312
  576. package/machineDaemonCommands.ts +0 -185
  577. package/machineHeartbeatCommands.ts +0 -30
  578. package/machineStatusCommands.ts +0 -95
  579. package/machineWatchCommands.ts +0 -41
  580. package/machineWsPromptMaterialization.ts +0 -89
  581. package/machineWsRunDispatch.ts +0 -695
  582. package/machineWsSession.ts +0 -213
  583. package/memoryCommands.ts +0 -253
  584. package/memoryInternalCommandEntries.ts +0 -9
  585. package/offlineMarxistsAgentCommand.ts +0 -315
  586. package/qoderUsageProbe.ts +0 -252
  587. package/render/contentIcon/types.ts +0 -167
  588. package/render/page/createPageAction.ts +0 -183
  589. package/render/page/docSlice.ts +0 -495
  590. package/render/page/types.ts +0 -19
  591. package/render/table/activityColumns.ts +0 -6
  592. package/render/table/createTableAction.ts +0 -274
  593. package/render/table/deleteTableAction.ts +0 -193
  594. package/render/table/fetchAndCacheTableRows.ts +0 -174
  595. package/render/table/tableSlice.ts +0 -1167
  596. package/render/table/toolValueUtils.ts +0 -363
  597. package/render/table/types.ts +0 -262
  598. package/render/table/utils/tableSerialization.ts +0 -50
  599. package/runtimeDoctorCommands.ts +0 -174
  600. package/runtimeModeArgs.ts +0 -33
  601. package/scriptCommandEntries.ts +0 -66
  602. package/secretScan.ts +0 -31
  603. package/server/handlers/agentRun/types.ts +0 -105
  604. package/share/action.ts +0 -225
  605. package/share/helpers.ts +0 -302
  606. package/share/keys.ts +0 -243
  607. package/share/publicSharePolicy.ts +0 -27
  608. package/share/shareSlice.ts +0 -53
  609. package/share/types.ts +0 -100
  610. package/systemInternalCommandEntries.ts +0 -65
  611. package/tableCommands.ts +0 -453
  612. package/tui/readlineWorkspace.ts +0 -210
  613. package/tui/session.ts +0 -554
  614. package/updateCommands.ts +0 -134
  615. package/workflowInternalCommandEntries.ts +0 -10
@@ -1,2809 +0,0 @@
1
- import { describe, expect, test } from "bun:test";
2
- import { mkdtempSync, readFileSync, rmSync } from "node:fs";
3
- import { join } from "node:path";
4
- import { tmpdir } from "node:os";
5
-
6
- import { runLocalAgentTurn } from "../agent-runtime/localLoop";
7
- import { LOCAL_CODEX_AGENT_KEY, LOCAL_QODER_AGENT_KEY } from "../agentAliases";
8
- import { createCliLocalRuntimeAdapter } from "./localRuntimeAdapter";
9
-
10
- const TEST_CUSTOM_AGENT_KEY = "agent-user-1-custom-runtime";
11
-
12
- describe("CLI local runtime adapter", () => {
13
- const DEFAULT_LOCAL_CODING_TOOL_NAMES = [
14
- "listFiles",
15
- "readFile",
16
- "writeFile",
17
- "editFile",
18
- "globFiles",
19
- "searchFiles",
20
- "execShell",
21
- ];
22
- const LEGACY_WRITE_LOCAL_CODING_TOOL_NAMES = [
23
- "listFiles",
24
- "readFile",
25
- "writeFile",
26
- "editFile",
27
- "globFiles",
28
- "searchFiles",
29
- "execShell",
30
- ];
31
- const SHELL_LOCAL_CODING_TOOL_NAMES = [
32
- ...DEFAULT_LOCAL_CODING_TOOL_NAMES,
33
- ];
34
- const DEFAULT_PRIVATE_NOLO_WORKSPACE_TOOL_NAMES = [
35
- "listDialogs",
36
- "readDialog",
37
- "listAgents",
38
- "readAgent",
39
- "listSpaces",
40
- "readSpace",
41
- "readDoc",
42
- "readSkillDoc",
43
- "listTables",
44
- "queryTableRows",
45
- "cliWhoami",
46
- "cliDoctor",
47
- ];
48
- const DEFAULT_PRIVATE_LOCAL_TOOL_NAMES = [
49
- ...DEFAULT_LOCAL_CODING_TOOL_NAMES,
50
- ...DEFAULT_PRIVATE_NOLO_WORKSPACE_TOOL_NAMES,
51
- ];
52
-
53
- function toolNamesFromRequest(request: any) {
54
- return request?.body?.tools?.map((tool: any) => tool.function.name) ?? [];
55
- }
56
-
57
- function publicSchemaKeys(schema: any) {
58
- return Object.keys(schema.parameters.properties).filter((key) => key !== "_activity");
59
- }
60
-
61
- test("loads stored local CLI agent records before falling back to built-ins", async () => {
62
- const adapter = createCliLocalRuntimeAdapter({
63
- env: {
64
- NOLO_LOCAL_USER_ID: "0e95801d90",
65
- },
66
- db: {
67
- get: async (key) => {
68
- if (key !== LOCAL_CODEX_AGENT_KEY) throw new Error(`not found: ${key}`);
69
- return {
70
- dbKey: LOCAL_CODEX_AGENT_KEY,
71
- id: "01LOCALCODEXCLI000000NEW",
72
- name: "User Edited Local Codex",
73
- prompt: "User-owned local Codex prompt.",
74
- apiSource: "cli",
75
- provider: "cli",
76
- cliProvider: "codex",
77
- model: "gpt-5.4",
78
- };
79
- },
80
- put: async () => {},
81
- batch: async () => {},
82
- iterator: () => (async function* () {})(),
83
- },
84
- fetchImpl: async () => new Response("not found", { status: 404 }),
85
- } as any);
86
-
87
- await expect(adapter.loadAgentConfig(LOCAL_CODEX_AGENT_KEY)).resolves.toMatchObject({
88
- key: LOCAL_CODEX_AGENT_KEY,
89
- name: "User Edited Local Codex",
90
- prompt: "User-owned local Codex prompt.",
91
- apiSource: "cli",
92
- provider: "cli",
93
- cliProvider: "codex",
94
- model: "gpt-5.4",
95
- });
96
- });
97
-
98
- test("falls back to built-in local Codex and Qoder CLI agents without machine binding", async () => {
99
- const adapter = createCliLocalRuntimeAdapter({
100
- env: {
101
- NOLO_LOCAL_USER_ID: "user-1",
102
- },
103
- db: {
104
- get: async (key) => {
105
- throw new Error(`not found: ${key}`);
106
- },
107
- put: async () => {},
108
- batch: async () => {},
109
- iterator: () => (async function* () {})(),
110
- },
111
- fetchImpl: async () => new Response("not found", { status: 404 }),
112
- } as any);
113
-
114
- const codex = await adapter.loadAgentConfig(LOCAL_CODEX_AGENT_KEY);
115
- const qoder = await adapter.loadAgentConfig(LOCAL_QODER_AGENT_KEY);
116
-
117
- expect(codex).toMatchObject({
118
- key: LOCAL_CODEX_AGENT_KEY,
119
- name: "Local Codex",
120
- apiSource: "cli",
121
- provider: "cli",
122
- cliProvider: "codex",
123
- });
124
- expect(qoder).toMatchObject({
125
- key: LOCAL_QODER_AGENT_KEY,
126
- name: "Local Qoder",
127
- apiSource: "cli",
128
- provider: "cli",
129
- cliProvider: "qoder",
130
- model: "Qwen3.7-Max",
131
- });
132
- expect((codex as any)?.runtimeBinding).toBeUndefined();
133
- expect((qoder as any)?.runtimeBinding).toBeUndefined();
134
- expect((codex as any)?.rawRecord?.runtimeBinding).toBeUndefined();
135
- expect((qoder as any)?.rawRecord?.runtimeBinding).toBeUndefined();
136
- });
137
-
138
- test("runs cli-provider agents through the local CLI executor instead of OpenAI-compatible direct mode", async () => {
139
- const cliExecutions: Array<{ provider: string; prompt: string; options: any }> = [];
140
- const adapter = createCliLocalRuntimeAdapter({
141
- env: {
142
- NOLO_LOCAL_USER_ID: "user-1",
143
- OPENAI_API_KEY: "sk-should-not-be-used",
144
- },
145
- db: {
146
- get: async (key) => {
147
- if (key !== "agent-user-1-frontend") throw new Error(`not found: ${key}`);
148
- return {
149
- dbKey: "agent-user-1-frontend",
150
- id: "frontend",
151
- name: "Frontend",
152
- prompt: "You are the frontend implementer.",
153
- apiSource: "cli",
154
- cliProvider: "agy",
155
- model: "gemini-3.1-pro",
156
- };
157
- },
158
- put: async () => {},
159
- batch: async () => {},
160
- iterator: () => (async function* () {})(),
161
- },
162
- cwd: "/repo/worktree",
163
- now: () => 1710000000000,
164
- createId: () => "01CLI",
165
- fetchImpl: async () => {
166
- throw new Error("OpenAI-compatible fetch should not be used for cli providers");
167
- },
168
- executeCli: async (provider, prompt, options) => {
169
- cliExecutions.push({ provider, prompt, options });
170
- return { text: "cli ok", raw: "cli ok", elapsed: 1 };
171
- },
172
- } as any);
173
-
174
- const result = await runLocalAgentTurn({
175
- adapter,
176
- agentRef: "frontend",
177
- input: "add tooltip",
178
- });
179
-
180
- expect(result).toMatchObject({
181
- content: "cli ok",
182
- model: "gemini-3.1-pro",
183
- });
184
- expect(cliExecutions).toHaveLength(1);
185
- expect(cliExecutions[0]).toMatchObject({
186
- provider: "agy",
187
- options: {
188
- model: "gemini-3.1-pro",
189
- cwd: "/repo/worktree",
190
- yolo: true,
191
- },
192
- });
193
- expect(cliExecutions[0].prompt).toContain("You are the frontend implementer.");
194
- expect(cliExecutions[0].prompt).toContain("add tooltip");
195
- });
196
-
197
- test("fails cli-provider local runs clearly when the requested local CLI is unavailable", async () => {
198
- const adapter = createCliLocalRuntimeAdapter({
199
- env: {
200
- NOLO_LOCAL_USER_ID: "user-1",
201
- OPENAI_API_KEY: "sk-should-not-be-used",
202
- },
203
- db: {
204
- get: async (key) => {
205
- if (key !== "agent-user-1-frontend") throw new Error(`not found: ${key}`);
206
- return {
207
- dbKey: "agent-user-1-frontend",
208
- id: "frontend",
209
- name: "Frontend",
210
- prompt: "You are the frontend implementer.",
211
- apiSource: "cli",
212
- cliProvider: "agy",
213
- };
214
- },
215
- put: async () => {},
216
- batch: async () => {},
217
- iterator: () => (async function* () {})(),
218
- },
219
- fetchImpl: async () => {
220
- throw new Error("OpenAI-compatible fetch should not be used for cli providers");
221
- },
222
- executeCli: async () => {
223
- throw new Error("agy: command not found");
224
- },
225
- } as any);
226
-
227
- await expect(runLocalAgentTurn({
228
- adapter,
229
- agentRef: "frontend",
230
- input: "add tooltip",
231
- })).rejects.toThrow("Local CLI provider \"agy\" is unavailable");
232
- });
233
-
234
- test("passes cli-provider image inputs to the CLI executor instead of rejecting", async () => {
235
- let cliCalledWith: any = null;
236
- const adapter = createCliLocalRuntimeAdapter({
237
- env: {
238
- NOLO_LOCAL_USER_ID: "user-1",
239
- },
240
- db: {
241
- get: async (key) => {
242
- if (key !== "agent-user-1-frontend") throw new Error(`not found: ${key}`);
243
- return {
244
- dbKey: "agent-user-1-frontend",
245
- id: "frontend",
246
- name: "Frontend",
247
- prompt: "You are the frontend implementer.",
248
- apiSource: "cli",
249
- cliProvider: "agy",
250
- };
251
- },
252
- put: async () => {},
253
- batch: async () => {},
254
- iterator: () => (async function* () {})(),
255
- },
256
- executeCli: async (provider, prompt, options) => {
257
- cliCalledWith = { provider, prompt, options };
258
- return { text: "image handled", raw: "", elapsed: 1 };
259
- },
260
- } as any);
261
-
262
- const result = await runLocalAgentTurn({
263
- adapter,
264
- agentRef: "frontend",
265
- input: [
266
- { type: "text", text: "look at this screenshot" },
267
- { type: "image_url", image_url: { url: "https://example.com/screen.png" } },
268
- ],
269
- });
270
-
271
- expect(result.content).toBe("image handled");
272
- expect(cliCalledWith).not.toBeNull();
273
- expect(cliCalledWith.provider).toBe("agy");
274
- expect(cliCalledWith.prompt).toContain("look at this screenshot");
275
- expect(cliCalledWith.options.imageInputs).toEqual([
276
- { source: "https://example.com/screen.png" },
277
- ]);
278
- });
279
-
280
- test("loads agent/history from LevelDB and saves dialog/message records back to LevelDB", async () => {
281
- const requests: Array<{ url: string; body: any; auth: string | null }> = [];
282
- const store = new Map<string, any>([
283
- ["agent-user-1-frontend", {
284
- dbKey: "agent-user-1-frontend",
285
- id: "frontend",
286
- name: "Frontend",
287
- prompt: "Fix UI",
288
- model: "gpt-4.1-mini",
289
- provider: "openai-compatible",
290
- }],
291
- ["dialog-user-1-dialog-existing", {
292
- dbKey: "dialog-user-1-dialog-existing",
293
- id: "dialog-existing",
294
- type: "dialog",
295
- userId: "user-1",
296
- }],
297
- ["dialog-dialog-existing-msg-001", {
298
- dbKey: "dialog-dialog-existing-msg-001",
299
- id: "msg-001",
300
- dialogId: "dialog-existing",
301
- role: "assistant",
302
- content: "previous answer",
303
- }],
304
- ]);
305
- const batchOps: any[] = [];
306
- const adapter = createCliLocalRuntimeAdapter({
307
- env: {
308
- NOLO_LOCAL_USER_ID: "user-1",
309
- OPENAI_API_KEY: "sk-local",
310
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
311
- },
312
- db: {
313
- get: async (key) => {
314
- if (!store.has(key)) throw new Error(`not found: ${key}`);
315
- return store.get(key);
316
- },
317
- put: async (key, value) => {
318
- store.set(key, value);
319
- },
320
- batch: async (ops) => {
321
- batchOps.push(...ops);
322
- for (const op of ops) {
323
- if (op.type === "put") store.set(op.key, op.value);
324
- }
325
- },
326
- iterator: ({ gte, lte }) => (async function* () {
327
- for (const entry of [...store.entries()].sort(([a], [b]) => a.localeCompare(b))) {
328
- if (entry[0] >= gte && entry[0] <= lte) yield entry;
329
- }
330
- })(),
331
- },
332
- now: () => 1710000000000,
333
- createId: () => "01LOCAL",
334
- fetchImpl: async (url, init) => {
335
- requests.push({
336
- url: String(url),
337
- body: JSON.parse(String(init?.body)),
338
- auth: new Headers(init?.headers).get("Authorization"),
339
- });
340
- return Response.json({
341
- choices: [{ message: { content: "local adapter ok" } }],
342
- usage: { prompt_tokens: 4, completion_tokens: 3 },
343
- });
344
- },
345
- });
346
-
347
- const result = await runLocalAgentTurn({
348
- adapter,
349
- agentRef: "frontend",
350
- input: "make it cleaner",
351
- continueDialogId: "dialog-existing",
352
- });
353
-
354
- expect(result).toMatchObject({
355
- content: "local adapter ok",
356
- model: "gpt-4.1-mini",
357
- dialogId: "dialog-existing",
358
- });
359
- expect(requests[0]).toMatchObject({
360
- url: "http://127.0.0.1:11434/v1/chat/completions",
361
- auth: "Bearer sk-local",
362
- body: {
363
- model: "gpt-4.1-mini",
364
- messages: [
365
- { role: "system", content: "Fix UI" },
366
- { role: "assistant", content: "previous answer" },
367
- { role: "user", content: "make it cleaner" },
368
- ],
369
- stream: false,
370
- },
371
- });
372
- expect(toolNamesFromRequest(requests[0])).toEqual(DEFAULT_PRIVATE_LOCAL_TOOL_NAMES);
373
- expect(batchOps.map((op) => op.key)).toEqual([
374
- "dialog-user-1-dialog-existing",
375
- "dialog-dialog-existing-msg-1710000000000-001",
376
- "dialog-dialog-existing-msg-1710000000000-002",
377
- ]);
378
- expect(store.get("dialog-user-1-dialog-existing")).toMatchObject({
379
- id: "dialog-existing",
380
- dbKey: "dialog-user-1-dialog-existing",
381
- type: "dialog",
382
- primaryAgentKey: "agent-user-1-frontend",
383
- status: "done",
384
- });
385
- expect(store.get("dialog-dialog-existing-msg-1710000000000-001")).toMatchObject({
386
- dialogId: "dialog-existing",
387
- role: "user",
388
- content: "make it cleaner",
389
- });
390
- expect(store.get("dialog-dialog-existing-msg-1710000000000-002")).toMatchObject({
391
- dialogId: "dialog-existing",
392
- role: "assistant",
393
- content: "local adapter ok",
394
- });
395
- });
396
-
397
- test("loads a missing explicit agent key through the hybrid store remote cache", async () => {
398
- const memory = new Map<string, any>();
399
- const requests: string[] = [];
400
- const adapter = createCliLocalRuntimeAdapter({
401
- env: {
402
- NOLO_LOCAL_USER_ID: "user-1",
403
- NOLO_SERVER: "https://us.nolo.chat",
404
- AUTH_TOKEN: "token-1",
405
- OPENAI_API_KEY: "sk-local",
406
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
407
- },
408
- db: {
409
- get: async (key) => {
410
- if (!memory.has(key)) throw new Error(`not found: ${key}`);
411
- return memory.get(key);
412
- },
413
- put: async (key, value) => {
414
- memory.set(key, value);
415
- },
416
- batch: async (ops) => {
417
- for (const op of ops) {
418
- if (op.type === "put") memory.set(op.key, op.value);
419
- }
420
- },
421
- iterator: () => (async function* () {})(),
422
- },
423
- createId: () => "01REMOTE",
424
- fetchImpl: async (url, init) => {
425
- requests.push(String(url));
426
- if (String(url).includes("/api/v1/db/read/")) {
427
- expect(new Headers(init?.headers).get("Authorization")).toBe("Bearer token-1");
428
- return Response.json({
429
- data: {
430
- dbKey: "agent-user-1-remote",
431
- name: "Remote cached",
432
- prompt: "Remote prompt",
433
- model: "gpt-4.1-mini",
434
- },
435
- });
436
- }
437
- return Response.json({
438
- choices: [{ message: { content: "remote cache ok" } }],
439
- });
440
- },
441
- });
442
-
443
- const result = await runLocalAgentTurn({
444
- adapter,
445
- agentRef: "agent-user-1-remote",
446
- input: "hello",
447
- });
448
-
449
- expect(result.content).toBe("remote cache ok");
450
- expect(requests[0]).toBe("https://us.nolo.chat/api/v1/db/read/agent-user-1-remote");
451
- expect(memory.get("agent-user-1-remote")).toMatchObject({
452
- name: "Remote cached",
453
- serverOrigin: "https://us.nolo.chat",
454
- });
455
- });
456
-
457
- test("keeps local runtime runnable when the configured local server is down but a cluster server can provide agent config", async () => {
458
- const memory = new Map<string, any>();
459
- const requests: string[] = [];
460
- const adapter = createCliLocalRuntimeAdapter({
461
- env: {
462
- NOLO_LOCAL_USER_ID: "user-1",
463
- NOLO_SERVER: "http://127.0.0.1:38123",
464
- AUTH_TOKEN: "token-1",
465
- OPENAI_API_KEY: "sk-local",
466
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
467
- },
468
- db: {
469
- get: async (key) => {
470
- if (!memory.has(key)) throw new Error(`not found: ${key}`);
471
- return memory.get(key);
472
- },
473
- put: async (key, value) => {
474
- memory.set(key, value);
475
- },
476
- batch: async (ops) => {
477
- for (const op of ops) {
478
- if (op.type === "put") memory.set(op.key, op.value);
479
- }
480
- },
481
- iterator: () => (async function* () {})(),
482
- },
483
- createId: () => "01CLUSTER",
484
- fetchImpl: async (url, init) => {
485
- const target = String(url);
486
- requests.push(target);
487
- if (target === "http://127.0.0.1:38123/api/v1/db/read/agent-user-1-cluster") {
488
- throw new Error("ConnectionRefused");
489
- }
490
- if (target === "https://nolo.chat/api/v1/db/read/agent-user-1-cluster") {
491
- expect(new Headers(init?.headers).get("Authorization")).toBe("Bearer token-1");
492
- return Response.json({
493
- data: {
494
- dbKey: "agent-user-1-cluster",
495
- name: "Cluster cached",
496
- prompt: "Use cached config",
497
- model: "gpt-4.1-mini",
498
- },
499
- });
500
- }
501
- if (target === "http://127.0.0.1:11434/v1/chat/completions") {
502
- return Response.json({
503
- choices: [{ message: { content: "cluster cache ok" } }],
504
- });
505
- }
506
- return new Response(null, { status: 404 });
507
- },
508
- });
509
-
510
- const result = await runLocalAgentTurn({
511
- adapter,
512
- agentRef: "agent-user-1-cluster",
513
- input: "hello",
514
- });
515
-
516
- expect(result.content).toBe("cluster cache ok");
517
- expect(requests).toEqual([
518
- "http://127.0.0.1:38123/api/v1/db/read/agent-user-1-cluster",
519
- "https://nolo.chat/api/v1/db/read/agent-user-1-cluster",
520
- "http://127.0.0.1:11434/v1/chat/completions",
521
- ]);
522
- expect(memory.get("agent-user-1-cluster")).toMatchObject({
523
- name: "Cluster cached",
524
- serverOrigin: "https://nolo.chat",
525
- });
526
- });
527
-
528
- test("uses agent-owned custom credentials for local OpenAI-compatible requests", async () => {
529
- const requests: Array<{ url: string; auth: string | null; apiKeyHeader: string | null; body: any }> = [];
530
- const store = new Map<string, any>([
531
- ["agent-user-1-custom", {
532
- dbKey: "agent-user-1-custom",
533
- id: "custom",
534
- prompt: "Use custom provider.",
535
- model: "custom-coder",
536
- provider: "custom-openai-compatible",
537
- apiSource: "custom",
538
- customProviderUrl: "https://provider.example/v1/chat/completions",
539
- apiKey: "sk-agent-custom",
540
- apiKeyHeader: "api-key",
541
- temperature: 0.2,
542
- max_tokens: 4096,
543
- reasoning_effort: "medium",
544
- }],
545
- ]);
546
- const adapter = createCliLocalRuntimeAdapter({
547
- env: {
548
- NOLO_LOCAL_USER_ID: "user-1",
549
- OPENAI_API_KEY: "sk-custom",
550
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
551
- },
552
- db: {
553
- get: async (key) => {
554
- if (!store.has(key)) throw new Error(`not found: ${key}`);
555
- return store.get(key);
556
- },
557
- put: async (key, value) => {
558
- store.set(key, value);
559
- },
560
- batch: async (ops) => {
561
- for (const op of ops) {
562
- if (op.type === "put") store.set(op.key, op.value);
563
- }
564
- },
565
- iterator: () => (async function* () {})(),
566
- },
567
- fetchImpl: async (url, init) => {
568
- requests.push({
569
- url: String(url),
570
- auth: new Headers(init?.headers).get("Authorization"),
571
- apiKeyHeader: new Headers(init?.headers).get("api-key"),
572
- body: JSON.parse(String(init?.body)),
573
- });
574
- return Response.json({
575
- choices: [{ message: { content: "custom ok" } }],
576
- });
577
- },
578
- });
579
-
580
- const result = await runLocalAgentTurn({
581
- adapter,
582
- agentRef: "custom",
583
- input: "hello",
584
- });
585
-
586
- expect(result.content).toBe("custom ok");
587
- expect(result.provider).toBe("custom-openai-compatible");
588
- expect(requests[0]).toMatchObject({
589
- url: "https://provider.example/v1/chat/completions",
590
- auth: null,
591
- apiKeyHeader: "sk-agent-custom",
592
- body: {
593
- model: "custom-coder",
594
- messages: [
595
- { role: "system", content: "Use custom provider." },
596
- { role: "user", content: "hello" },
597
- ],
598
- stream: false,
599
- temperature: 0.2,
600
- max_tokens: 4096,
601
- reasoning_effort: "medium",
602
- },
603
- });
604
- expect(toolNamesFromRequest(requests[0])).toEqual(DEFAULT_PRIVATE_LOCAL_TOOL_NAMES);
605
- });
606
-
607
- test("aborts stalled custom provider requests when timeoutMs is provided", async () => {
608
- const store = new Map<string, any>([
609
- ["agent-user-1-mimo", {
610
- dbKey: "agent-user-1-mimo",
611
- id: "mimo",
612
- prompt: "Use monthly mimo.",
613
- model: "mimo-v2.5-pro",
614
- provider: "custom",
615
- apiSource: "custom",
616
- customProviderUrl: "https://token-plan-cn.xiaomimimo.com/v1",
617
- apiKey: "mimo-monthly-key",
618
- }],
619
- ]);
620
- const adapter = createCliLocalRuntimeAdapter({
621
- env: {
622
- NOLO_LOCAL_USER_ID: "user-1",
623
- },
624
- store: {
625
- read: async (key) => store.get(key) ?? null,
626
- put: async (key, value) => {
627
- store.set(key, value);
628
- },
629
- batch: async (ops) => {
630
- for (const op of ops) {
631
- if (op.type === "put") store.set(op.key, op.value);
632
- }
633
- },
634
- iterator: () => (async function* () {})(),
635
- },
636
- fetchImpl: async (_url, init) => {
637
- if (init?.signal?.aborted) {
638
- throw init.signal.reason ?? new Error("aborted");
639
- }
640
- await new Promise((_, reject) => {
641
- init?.signal?.addEventListener("abort", () => reject(init.signal?.reason ?? new Error("aborted")));
642
- });
643
- throw new Error("unreachable");
644
- },
645
- });
646
-
647
- await expect(runLocalAgentTurn({
648
- adapter,
649
- agentRef: "mimo",
650
- input: "hello",
651
- timeoutMs: 10,
652
- })).rejects.toThrow(/timed out|aborted/i);
653
- });
654
-
655
- test("uses loopback transport for localhost custom providers when the default fetch path cannot connect", async () => {
656
- const store = new Map<string, any>([
657
- ["agent-user-1-localhost", {
658
- dbKey: "agent-user-1-localhost",
659
- id: "localhost",
660
- prompt: "Use localhost provider.",
661
- model: "Qwen3.6-27B-MTP-Q3_K_M.gguf",
662
- provider: "custom-openai-compatible",
663
- apiSource: "custom",
664
- customProviderUrl: "http://127.0.0.1:8080/v1/chat/completions",
665
- }],
666
- ]);
667
- const loopbackRequests: Array<{ url: string; body: any }> = [];
668
- const adapter = createCliLocalRuntimeAdapter({
669
- env: {
670
- NOLO_LOCAL_USER_ID: "user-1",
671
- },
672
- db: {
673
- get: async (key) => {
674
- if (!store.has(key)) throw new Error(`not found: ${key}`);
675
- return store.get(key);
676
- },
677
- put: async (key, value) => {
678
- store.set(key, value);
679
- },
680
- batch: async (ops) => {
681
- for (const op of ops) {
682
- if (op.type === "put") store.set(op.key, op.value);
683
- }
684
- },
685
- iterator: () => (async function* () {})(),
686
- },
687
- fetchImpl: async () => {
688
- throw new TypeError("Unable to connect. Is the computer able to access the url?");
689
- },
690
- loopbackRequest: async (url, init) => {
691
- loopbackRequests.push({
692
- url: String(url),
693
- body: JSON.parse(String(init?.body)),
694
- });
695
- return Response.json({
696
- choices: [{ message: { content: "loopback ok" } }],
697
- });
698
- },
699
- });
700
-
701
- const result = await runLocalAgentTurn({
702
- adapter,
703
- agentRef: "localhost",
704
- input: "hello",
705
- });
706
-
707
- expect(result.content).toBe("loopback ok");
708
- expect(loopbackRequests).toHaveLength(1);
709
- expect(loopbackRequests[0]).toMatchObject({
710
- url: "http://127.0.0.1:8080/v1/chat/completions",
711
- body: {
712
- model: "Qwen3.6-27B-MTP-Q3_K_M.gguf",
713
- messages: [
714
- { role: "system", content: "Use localhost provider." },
715
- { role: "user", content: "hello" },
716
- ],
717
- stream: false,
718
- },
719
- });
720
- expect(toolNamesFromRequest(loopbackRequests[0])).toEqual(DEFAULT_PRIVATE_LOCAL_TOOL_NAMES);
721
- });
722
-
723
- test("uses the Nolo chat proxy when local provider keys are absent", async () => {
724
- const requests: Array<{ url: string; auth: string | null; body: any }> = [];
725
- const store = new Map<string, any>([
726
- ["agent-user-1-frontend", {
727
- dbKey: "agent-user-1-frontend",
728
- id: "frontend",
729
- prompt: "Fix UI.",
730
- model: "accounts/fireworks/models/kimi-k2p6",
731
- provider: "fireworks",
732
- tools: ["writeFile"],
733
- }],
734
- ]);
735
- const adapter = createCliLocalRuntimeAdapter({
736
- env: {
737
- NOLO_LOCAL_USER_ID: "user-1",
738
- NOLO_SERVER: "https://us.nolo.chat",
739
- AUTH_TOKEN: "token-1",
740
- },
741
- db: {
742
- get: async (key) => {
743
- if (!store.has(key)) throw new Error(`not found: ${key}`);
744
- return store.get(key);
745
- },
746
- put: async (key, value) => {
747
- store.set(key, value);
748
- },
749
- batch: async (ops) => {
750
- for (const op of ops) {
751
- if (op.type === "put") store.set(op.key, op.value);
752
- }
753
- },
754
- iterator: () => (async function* () {})(),
755
- },
756
- fetchImpl: async (url, init) => {
757
- requests.push({
758
- url: String(url),
759
- auth: new Headers(init?.headers).get("Authorization"),
760
- body: JSON.parse(String(init?.body)),
761
- });
762
- return Response.json({
763
- choices: [{ message: { content: "platform ok" } }],
764
- usage: { prompt_tokens: 7, completion_tokens: 2 },
765
- });
766
- },
767
- });
768
-
769
- const result = await runLocalAgentTurn({
770
- adapter,
771
- agentRef: "frontend",
772
- input: "make notifications cleaner",
773
- });
774
-
775
- expect(result.content).toBe("platform ok");
776
- expect(result.provider).toBe("fireworks");
777
- expect(requests[0]).toMatchObject({
778
- url: "https://us.nolo.chat/api/v1/chat",
779
- auth: "Bearer token-1",
780
- body: {
781
- model: "accounts/fireworks/models/kimi-k2p6",
782
- messages: [
783
- { role: "system", content: "Fix UI." },
784
- { role: "user", content: "make notifications cleaner" },
785
- ],
786
- stream: false,
787
- tool_choice: "auto",
788
- url: "https://api.fireworks.ai/inference/v1/chat/completions",
789
- provider: "fireworks",
790
- agentKey: "agent-user-1-frontend",
791
- },
792
- });
793
- expect(toolNamesFromRequest(requests[0])).toEqual([
794
- ...LEGACY_WRITE_LOCAL_CODING_TOOL_NAMES,
795
- ...DEFAULT_PRIVATE_NOLO_WORKSPACE_TOOL_NAMES,
796
- ]);
797
- });
798
-
799
- test("uses the Nolo chat proxy for platform agents even when direct provider env exists", async () => {
800
- const requests: Array<{ url: string; auth: string | null; body: any }> = [];
801
- const store = new Map<string, any>([
802
- ["agent-user-1-frontend", {
803
- dbKey: "agent-user-1-frontend",
804
- id: "frontend",
805
- prompt: "Fix UI.",
806
- model: "accounts/fireworks/models/kimi-k2p6",
807
- provider: "fireworks",
808
- apiSource: "platform",
809
- useServerProxy: true,
810
- tools: ["readFile"],
811
- }],
812
- ]);
813
- const adapter = createCliLocalRuntimeAdapter({
814
- env: {
815
- NOLO_LOCAL_USER_ID: "user-1",
816
- NOLO_SERVER: "https://us.nolo.chat",
817
- AUTH_TOKEN: "token-1",
818
- OPENAI_API_KEY: "sk-direct",
819
- },
820
- db: {
821
- get: async (key) => {
822
- if (!store.has(key)) throw new Error(`not found: ${key}`);
823
- return store.get(key);
824
- },
825
- put: async (key, value) => {
826
- store.set(key, value);
827
- },
828
- batch: async (ops) => {
829
- for (const op of ops) {
830
- if (op.type === "put") store.set(op.key, op.value);
831
- }
832
- },
833
- iterator: () => (async function* () {})(),
834
- },
835
- fetchImpl: async (url, init) => {
836
- requests.push({
837
- url: String(url),
838
- auth: new Headers(init?.headers).get("Authorization"),
839
- body: JSON.parse(String(init?.body)),
840
- });
841
- return Response.json({
842
- choices: [{ message: { content: "platform ok" } }],
843
- });
844
- },
845
- });
846
-
847
- const result = await runLocalAgentTurn({
848
- adapter,
849
- agentRef: "frontend",
850
- input: "inspect",
851
- });
852
-
853
- expect(result.content).toBe("platform ok");
854
- expect(requests[0]).toMatchObject({
855
- url: "https://us.nolo.chat/api/v1/chat",
856
- auth: "Bearer token-1",
857
- body: {
858
- provider: "fireworks",
859
- apiSource: "platform",
860
- agentKey: "agent-user-1-frontend",
861
- },
862
- });
863
- });
864
-
865
- test("retries transient certificate failures from the platform chat proxy", async () => {
866
- let attempts = 0;
867
- const store = new Map<string, any>([
868
- ["agent-user-1-frontend", {
869
- dbKey: "agent-user-1-frontend",
870
- id: "frontend",
871
- prompt: "Fix UI.",
872
- model: "accounts/fireworks/models/kimi-k2p6",
873
- provider: "fireworks",
874
- apiSource: "platform",
875
- useServerProxy: true,
876
- }],
877
- ]);
878
- const adapter = createCliLocalRuntimeAdapter({
879
- env: {
880
- NOLO_LOCAL_USER_ID: "user-1",
881
- NOLO_SERVER: "https://us.nolo.chat",
882
- AUTH_TOKEN: "token-1",
883
- },
884
- db: {
885
- get: async (key) => {
886
- if (!store.has(key)) throw new Error(`not found: ${key}`);
887
- return store.get(key);
888
- },
889
- put: async (key, value) => {
890
- store.set(key, value);
891
- },
892
- batch: async (ops) => {
893
- for (const op of ops) {
894
- if (op.type === "put") store.set(op.key, op.value);
895
- }
896
- },
897
- iterator: () => (async function* () {})(),
898
- },
899
- fetchImpl: async () => {
900
- attempts += 1;
901
- if (attempts <= 2) {
902
- throw new Error("unknown certificate verification error");
903
- }
904
- return Response.json({
905
- choices: [{ message: { content: "platform retry ok" } }],
906
- });
907
- },
908
- sleep: async () => {},
909
- });
910
-
911
- const result = await runLocalAgentTurn({
912
- adapter,
913
- agentRef: "frontend",
914
- input: "inspect",
915
- });
916
-
917
- expect(result.content).toBe("platform retry ok");
918
- expect(attempts).toBe(3);
919
- });
920
-
921
- test("keeps retrying repeated transient certificate failures with backoff hooks", async () => {
922
- let attempts = 0;
923
- const retryDelays: number[] = [];
924
- const store = new Map<string, any>([
925
- ["agent-user-1-frontend", {
926
- dbKey: "agent-user-1-frontend",
927
- id: "frontend",
928
- prompt: "Fix UI.",
929
- model: "accounts/fireworks/models/kimi-k2p6",
930
- provider: "fireworks",
931
- apiSource: "platform",
932
- useServerProxy: true,
933
- }],
934
- ]);
935
- const adapter = createCliLocalRuntimeAdapter({
936
- env: {
937
- NOLO_LOCAL_USER_ID: "user-1",
938
- NOLO_SERVER: "https://us.nolo.chat",
939
- AUTH_TOKEN: "token-1",
940
- },
941
- db: {
942
- get: async (key) => {
943
- if (!store.has(key)) throw new Error(`not found: ${key}`);
944
- return store.get(key);
945
- },
946
- put: async (key, value) => {
947
- store.set(key, value);
948
- },
949
- batch: async (ops) => {
950
- for (const op of ops) {
951
- if (op.type === "put") store.set(op.key, op.value);
952
- }
953
- },
954
- iterator: () => (async function* () {})(),
955
- },
956
- fetchImpl: async () => {
957
- attempts += 1;
958
- if (attempts <= 5) {
959
- throw new Error("unknown certificate verification error");
960
- }
961
- return Response.json({
962
- choices: [{ message: { content: "platform longer retry ok" } }],
963
- });
964
- },
965
- sleep: async (ms) => {
966
- retryDelays.push(ms);
967
- },
968
- });
969
-
970
- const result = await runLocalAgentTurn({
971
- adapter,
972
- agentRef: "frontend",
973
- input: "inspect",
974
- });
975
-
976
- expect(result.content).toBe("platform longer retry ok");
977
- expect(attempts).toBe(6);
978
- expect(retryDelays.length).toBeGreaterThanOrEqual(3);
979
- expect(retryDelays[0]).toBeGreaterThan(0);
980
- });
981
-
982
- test("saves local tool call trace and shell metadata into the local dialog", async () => {
983
- const store = new Map<string, any>([
984
- ["agent-user-1-shell", {
985
- dbKey: "agent-user-1-shell",
986
- id: "shell",
987
- prompt: "Use shell.",
988
- model: "gpt-4.1-mini",
989
- }],
990
- ]);
991
- const adapter = createCliLocalRuntimeAdapter({
992
- env: {
993
- NOLO_LOCAL_USER_ID: "user-1",
994
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
995
- },
996
- db: {
997
- get: async (key) => {
998
- if (!store.has(key)) throw new Error(`not found: ${key}`);
999
- return store.get(key);
1000
- },
1001
- put: async (key, value) => {
1002
- store.set(key, value);
1003
- },
1004
- batch: async (ops) => {
1005
- for (const op of ops) {
1006
- if (op.type === "put") store.set(op.key, op.value);
1007
- }
1008
- },
1009
- iterator: () => (async function* () {})(),
1010
- },
1011
- cwd: import.meta.dir,
1012
- now: () => 1710000000000,
1013
- createId: () => "01TRACE",
1014
- localToolExecutors: {
1015
- execShell: async () => ({
1016
- content: "stdout:\ntrace-ok\n\nexitCode: 0",
1017
- metadata: { exitCode: 0, timedOut: false },
1018
- }),
1019
- },
1020
- fetchImpl: async (_url, init) => {
1021
- const body = JSON.parse(String(init?.body));
1022
- const hasToolResult = body.messages.some((message: any) => message.role === "tool");
1023
- if (!hasToolResult) {
1024
- return Response.json({
1025
- choices: [{
1026
- message: {
1027
- content: "",
1028
- tool_calls: [{
1029
- id: "call-shell",
1030
- type: "function",
1031
- function: {
1032
- name: "execShell",
1033
- arguments: JSON.stringify({
1034
- cmd: process.platform === "win32"
1035
- ? "Write-Output trace-ok"
1036
- : "printf trace-ok",
1037
- }),
1038
- },
1039
- }],
1040
- },
1041
- }],
1042
- });
1043
- }
1044
- return Response.json({
1045
- choices: [{ message: { content: "done" } }],
1046
- });
1047
- },
1048
- });
1049
-
1050
- const result = await runLocalAgentTurn({
1051
- adapter,
1052
- agentRef: "shell",
1053
- input: "inspect",
1054
- });
1055
-
1056
- expect(result.dialogId).toBe("01TRACE");
1057
- expect(store.get("dialog-user-1-01TRACE")).toMatchObject({
1058
- toolCallCount: 1,
1059
- localRuntime: expect.objectContaining({
1060
- host: "cli",
1061
- worktreePath: import.meta.dir,
1062
- }),
1063
- });
1064
- const messages = [...store.entries()]
1065
- .filter(([key]) => key.startsWith("dialog-01TRACE-msg-"))
1066
- .sort(([a], [b]) => a.localeCompare(b))
1067
- .map(([, value]) => value);
1068
- expect(messages.map((message) => message.role)).toEqual([
1069
- "user",
1070
- "assistant",
1071
- "tool",
1072
- "assistant",
1073
- ]);
1074
- expect(messages[1]).toMatchObject({
1075
- tool_calls: [{
1076
- id: "call-shell",
1077
- function: { name: "execShell" },
1078
- }],
1079
- });
1080
- expect(messages[2]).toMatchObject({
1081
- role: "tool",
1082
- toolCallId: "call-shell",
1083
- metadata: { exitCode: 0 },
1084
- });
1085
- expect(messages[2].content).toContain("trace-ok");
1086
- expect(messages[3]).toMatchObject({
1087
- role: "assistant",
1088
- content: "done",
1089
- });
1090
- });
1091
-
1092
- test("returns tool budget errors to the local loop", async () => {
1093
- const store = new Map<string, any>([
1094
- ["agent-user-1-reader", {
1095
- dbKey: "agent-user-1-reader",
1096
- id: "reader",
1097
- prompt: "Read narrowly",
1098
- model: "gpt-4.1-mini",
1099
- provider: "openai-compatible",
1100
- tools: ["readFile"],
1101
- }],
1102
- ]);
1103
- let requestCount = 0;
1104
- const adapter = createCliLocalRuntimeAdapter({
1105
- env: {
1106
- NOLO_LOCAL_USER_ID: "user-1",
1107
- NOLO_LOCAL_OPENAI_BASE_URL: "https://llm.example/v1",
1108
- NOLO_LOCAL_OPENAI_API_KEY: "sk-test",
1109
- NOLO_LOCAL_TOOL_BUDGETS: "readFile=1",
1110
- },
1111
- store: {
1112
- read: async (key) => {
1113
- if (!store.has(key)) throw new Error(`not found: ${key}`);
1114
- return store.get(key);
1115
- },
1116
- put: async (key, value) => {
1117
- store.set(key, value);
1118
- },
1119
- batch: async (ops) => {
1120
- for (const op of ops) {
1121
- if (op.type === "put") store.set(op.key, op.value);
1122
- }
1123
- },
1124
- iterator: () => (async function* () {})(),
1125
- },
1126
- cwd: import.meta.dir,
1127
- now: () => 1710000000000,
1128
- createId: () => "01BUDGET",
1129
- localToolExecutors: {
1130
- readFile: async () => ({ content: "file content" }),
1131
- },
1132
- fetchImpl: async (_url, init) => {
1133
- requestCount += 1;
1134
- const body = JSON.parse(String(init?.body));
1135
- const toolMessages = body.messages.filter((message: any) => message.role === "tool");
1136
- if (toolMessages.some((message: any) => String(message.content).includes("exceeded local tool budget"))) {
1137
- return Response.json({ choices: [{ message: { content: "budget handled" } }] });
1138
- }
1139
- return Response.json({
1140
- choices: [{
1141
- message: {
1142
- content: "",
1143
- tool_calls: [{
1144
- id: `call-read-${requestCount}`,
1145
- type: "function",
1146
- function: {
1147
- name: "readFile",
1148
- arguments: JSON.stringify({ path: "file.ts" }),
1149
- },
1150
- }],
1151
- },
1152
- }],
1153
- });
1154
- },
1155
- });
1156
-
1157
- const result = await runLocalAgentTurn({
1158
- adapter,
1159
- agentRef: "agent-user-1-reader",
1160
- input: "inspect",
1161
- });
1162
-
1163
- expect(result.content).toBe("budget handled");
1164
- const messages = [...store.values()];
1165
- expect(messages.some((message) => String(message.content).includes("exceeded local tool budget 1"))).toBe(true);
1166
- });
1167
-
1168
- test("continues a local dialog instead of creating a new one", async () => {
1169
- const store = new Map<string, any>([
1170
- ["agent-user-1-frontend", {
1171
- dbKey: "agent-user-1-frontend",
1172
- id: "frontend",
1173
- prompt: "Fix UI",
1174
- model: "gpt-4.1-mini",
1175
- }],
1176
- ["dialog-user-1-dialog-existing", {
1177
- dbKey: "dialog-user-1-dialog-existing",
1178
- id: "dialog-existing",
1179
- type: "dialog",
1180
- userId: "user-1",
1181
- title: "Existing dialog",
1182
- }],
1183
- ["dialog-dialog-existing-msg-001", {
1184
- dbKey: "dialog-dialog-existing-msg-001",
1185
- id: "msg-001",
1186
- dialogId: "dialog-existing",
1187
- role: "assistant",
1188
- content: "previous answer",
1189
- }],
1190
- ]);
1191
- const adapter = createCliLocalRuntimeAdapter({
1192
- env: {
1193
- NOLO_LOCAL_USER_ID: "user-1",
1194
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1195
- },
1196
- db: {
1197
- get: async (key) => {
1198
- if (!store.has(key)) throw new Error(`not found: ${key}`);
1199
- return store.get(key);
1200
- },
1201
- put: async (key, value) => {
1202
- store.set(key, value);
1203
- },
1204
- batch: async (ops) => {
1205
- for (const op of ops) {
1206
- if (op.type === "put") store.set(op.key, op.value);
1207
- }
1208
- },
1209
- iterator: ({ gte, lte }) => (async function* () {
1210
- for (const entry of [...store.entries()].sort(([a], [b]) => a.localeCompare(b))) {
1211
- if (entry[0] >= gte && entry[0] <= lte) yield entry;
1212
- }
1213
- })(),
1214
- },
1215
- now: () => 1710000000000,
1216
- createId: () => "SHOULDNOTUSE",
1217
- fetchImpl: async (_url, init) => {
1218
- const body = JSON.parse(String(init?.body));
1219
- expect(body.messages).toContainEqual({
1220
- role: "assistant",
1221
- content: "previous answer",
1222
- });
1223
- return Response.json({
1224
- choices: [{ message: { content: "continued" } }],
1225
- });
1226
- },
1227
- });
1228
-
1229
- const result = await runLocalAgentTurn({
1230
- adapter,
1231
- agentRef: "frontend",
1232
- input: "continue",
1233
- continueDialogId: "dialog-existing",
1234
- });
1235
-
1236
- expect(result.dialogId).toBe("dialog-existing");
1237
- expect(store.has("dialog-user-1-SHOULDNOTUSE")).toBe(false);
1238
- expect(store.get("dialog-user-1-dialog-existing")).toMatchObject({
1239
- id: "dialog-existing",
1240
- title: "Existing dialog",
1241
- status: "done",
1242
- });
1243
- expect([...store.keys()].filter((key) => key.startsWith("dialog-dialog-existing-msg-"))).toContain(
1244
- "dialog-dialog-existing-msg-1710000000000-001"
1245
- );
1246
- });
1247
-
1248
- test("passes image_url message parts through to OpenAI-compatible providers", async () => {
1249
- const requests: Array<{ body: any }> = [];
1250
- const adapter = createCliLocalRuntimeAdapter({
1251
- env: {
1252
- OPENAI_API_KEY: "sk-local",
1253
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1254
- },
1255
- db: {
1256
- get: async () => ({
1257
- dbKey: "agent-local-vision",
1258
- prompt: "Describe images.",
1259
- model: "gpt-4.1-mini",
1260
- }),
1261
- put: async () => {},
1262
- batch: async () => {},
1263
- iterator: () => (async function* () {})(),
1264
- },
1265
- fetchImpl: async (_url, init) => {
1266
- requests.push({ body: JSON.parse(String(init?.body)) });
1267
- return Response.json({
1268
- choices: [{ message: { content: "image ok" } }],
1269
- });
1270
- },
1271
- });
1272
-
1273
- await runLocalAgentTurn({
1274
- adapter,
1275
- agentRef: "vision",
1276
- input: [
1277
- { type: "text", text: "describe this" },
1278
- { type: "image_url", image_url: { url: "https://example.com/a.png" } },
1279
- ],
1280
- });
1281
-
1282
- expect(requests[0]?.body.messages.at(-1)).toEqual({
1283
- role: "user",
1284
- content: [
1285
- { type: "text", text: "describe this" },
1286
- { type: "image_url", image_url: { url: "https://example.com/a.png" } },
1287
- ],
1288
- });
1289
- });
1290
-
1291
- test("allows registered execShell by default", async () => {
1292
- const adapter = createCliLocalRuntimeAdapter({
1293
- env: {},
1294
- localToolExecutors: {
1295
- execShell: async (call) => ({ content: `shell:${call.arguments}` }),
1296
- },
1297
- fetchImpl: async () => Response.json({}),
1298
- });
1299
-
1300
- const result = await adapter.executeTool({
1301
- id: "call-1",
1302
- name: "execShell",
1303
- arguments: "{\"cmd\":\"pwd\"}",
1304
- });
1305
-
1306
- expect(result.content).toContain("\"cmd\":\"pwd\"");
1307
- });
1308
-
1309
- test("executes explicitly allowed registered local tools declared by the agent", async () => {
1310
- const store = new Map<string, any>([
1311
- ["agent-user-1-reader", {
1312
- dbKey: "agent-user-1-reader",
1313
- id: "reader",
1314
- prompt: "Read files.",
1315
- toolNames: ["readFile"],
1316
- }],
1317
- ]);
1318
- const adapter = createCliLocalRuntimeAdapter({
1319
- env: {
1320
- NOLO_LOCAL_USER_ID: "user-1",
1321
- NOLO_LOCAL_ALLOWED_TOOLS: "readFile",
1322
- },
1323
- db: {
1324
- get: async (key) => {
1325
- if (!store.has(key)) throw new Error(`not found: ${key}`);
1326
- return store.get(key);
1327
- },
1328
- put: async () => {},
1329
- batch: async () => {},
1330
- iterator: () => (async function* () {})(),
1331
- },
1332
- localToolExecutors: {
1333
- readFile: async (call) => ({ content: `read:${call.arguments}` }),
1334
- },
1335
- fetchImpl: async () => Response.json({}),
1336
- });
1337
-
1338
- await adapter.loadAgentConfig("reader");
1339
- const result = await adapter.executeTool({
1340
- id: "call-1",
1341
- name: "readFile",
1342
- arguments: "{\"path\":\"README.md\"}",
1343
- });
1344
-
1345
- expect(result.content).toContain("README.md");
1346
- });
1347
-
1348
- test("advertises execShell to OpenAI-compatible providers by default", async () => {
1349
- const requests: Array<{ body: any }> = [];
1350
- const adapter = createCliLocalRuntimeAdapter({
1351
- env: {
1352
- OPENAI_API_KEY: "sk-local",
1353
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1354
- },
1355
- db: {
1356
- get: async () => ({
1357
- dbKey: "agent-local-shell",
1358
- prompt: "Use shell.",
1359
- model: "gpt-4.1-mini",
1360
- }),
1361
- put: async () => {},
1362
- batch: async () => {},
1363
- iterator: () => (async function* () {})(),
1364
- },
1365
- fetchImpl: async (_url, init) => {
1366
- requests.push({ body: JSON.parse(String(init?.body)) });
1367
- return Response.json({
1368
- choices: [{ message: { content: "done" } }],
1369
- });
1370
- },
1371
- });
1372
-
1373
- await runLocalAgentTurn({
1374
- adapter,
1375
- agentRef: "shell",
1376
- input: "pwd",
1377
- });
1378
-
1379
- expect(toolNamesFromRequest(requests[0])).toEqual([
1380
- ...SHELL_LOCAL_CODING_TOOL_NAMES,
1381
- ...DEFAULT_PRIVATE_NOLO_WORKSPACE_TOOL_NAMES,
1382
- ]);
1383
- });
1384
-
1385
- test("keeps generic custom agent tools to the supported local and server surfaces", async () => {
1386
- const requests: Array<{ body: any }> = [];
1387
- const adapter = createCliLocalRuntimeAdapter({
1388
- env: {
1389
- OPENAI_API_KEY: "sk-local",
1390
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1391
- },
1392
- db: {
1393
- get: async () => ({
1394
- dbKey: TEST_CUSTOM_AGENT_KEY,
1395
- prompt: "Use local coding tools.",
1396
- model: "mimo-v2.5-pro",
1397
- provider: "custom",
1398
- tools: [
1399
- "read",
1400
- "searchDialogMessages",
1401
- "searchFiles",
1402
- "codeSearch",
1403
- "listFiles",
1404
- "readFile",
1405
- "writeFile",
1406
- "editFile",
1407
- "searchFiles",
1408
- "legacyLocalAlias",
1409
- "applyPatch",
1410
- "execShell",
1411
- "checkEnv",
1412
- "queryTableRows",
1413
- ],
1414
- }),
1415
- put: async () => {},
1416
- batch: async () => {},
1417
- iterator: () => (async function* () {})(),
1418
- },
1419
- fetchImpl: async (_url, init) => {
1420
- requests.push({ body: JSON.parse(String(init?.body)) });
1421
- return Response.json({
1422
- choices: [{ message: { content: "done" } }],
1423
- });
1424
- },
1425
- });
1426
-
1427
- await runLocalAgentTurn({
1428
- adapter,
1429
- agentRef: TEST_CUSTOM_AGENT_KEY,
1430
- input: "inspect cwd",
1431
- });
1432
-
1433
- expect(toolNamesFromRequest(requests[0])).toEqual([
1434
- ...SHELL_LOCAL_CODING_TOOL_NAMES,
1435
- "queryTableRows",
1436
- ]);
1437
- });
1438
-
1439
- test("can expose only declared local workspace tools for tool ablations", async () => {
1440
- const requests: Array<{ body: any }> = [];
1441
- const adapter = createCliLocalRuntimeAdapter({
1442
- env: {
1443
- OPENAI_API_KEY: "sk-local",
1444
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1445
- NOLO_LOCAL_WORKSPACE_TOOLSET: "declared-only",
1446
- },
1447
- db: {
1448
- get: async () => ({
1449
- dbKey: TEST_CUSTOM_AGENT_KEY,
1450
- prompt: "Use exactly the declared local tools.",
1451
- model: "mimo-v2.5-pro",
1452
- provider: "custom",
1453
- tools: ["listFiles", "readFile", "execShell"],
1454
- }),
1455
- put: async () => {},
1456
- batch: async () => {},
1457
- iterator: () => (async function* () {})(),
1458
- },
1459
- fetchImpl: async (_url, init) => {
1460
- requests.push({ body: JSON.parse(String(init?.body)) });
1461
- return Response.json({
1462
- choices: [{ message: { content: "done" } }],
1463
- });
1464
- },
1465
- });
1466
-
1467
- await runLocalAgentTurn({
1468
- adapter,
1469
- agentRef: TEST_CUSTOM_AGENT_KEY,
1470
- input: "inspect cwd",
1471
- });
1472
-
1473
- expect(toolNamesFromRequest(requests[0])).toEqual(["listFiles", "readFile", "execShell"]);
1474
- });
1475
-
1476
- test("defaults local workspace tools to strategy descriptions and rich parameters", async () => {
1477
- const requests: Array<{ body: any }> = [];
1478
- const adapter = createCliLocalRuntimeAdapter({
1479
- env: {
1480
- OPENAI_API_KEY: "sk-local",
1481
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1482
- NOLO_LOCAL_WORKSPACE_TOOLSET: "declared-only",
1483
- },
1484
- db: {
1485
- get: async () => ({
1486
- dbKey: TEST_CUSTOM_AGENT_KEY,
1487
- prompt: "Use local coding tools.",
1488
- model: "mimo-v2.5-pro",
1489
- provider: "custom",
1490
- tools: ["listFiles", "readFile", "globFiles", "searchFiles"],
1491
- }),
1492
- put: async () => {},
1493
- batch: async () => {},
1494
- iterator: () => (async function* () {})(),
1495
- },
1496
- fetchImpl: async (_url, init) => {
1497
- requests.push({ body: JSON.parse(String(init?.body)) });
1498
- return Response.json({
1499
- choices: [{ message: { content: "done" } }],
1500
- });
1501
- },
1502
- });
1503
-
1504
- await runLocalAgentTurn({
1505
- adapter,
1506
- agentRef: TEST_CUSTOM_AGENT_KEY,
1507
- input: "inspect cwd",
1508
- });
1509
-
1510
- const tools = new Map(
1511
- requests[0]?.body.tools.map((tool: any) => [tool.function.name, tool.function]),
1512
- );
1513
- const listFiles = tools.get("listFiles") as any;
1514
- const readFile = tools.get("readFile") as any;
1515
- const globFiles = tools.get("globFiles") as any;
1516
- const searchFiles = tools.get("searchFiles") as any;
1517
-
1518
- expect(listFiles.description).toContain("not for path-pattern discovery across the repo");
1519
- expect(publicSchemaKeys(listFiles)).toEqual([
1520
- "path",
1521
- "maxDepth",
1522
- "maxResults",
1523
- "entryType",
1524
- ]);
1525
- expect(readFile.description).toContain("Use line ranges");
1526
- expect(publicSchemaKeys(readFile)).toEqual([
1527
- "path",
1528
- "startLine",
1529
- "endLine",
1530
- "maxLines",
1531
- "tailLines",
1532
- ]);
1533
- expect(globFiles.description).toContain("any file discovery task");
1534
- expect(publicSchemaKeys(globFiles)).toEqual([
1535
- "pattern",
1536
- "path",
1537
- "exclude",
1538
- "includeIgnored",
1539
- "maxResults",
1540
- ]);
1541
- expect(searchFiles.description).toContain("using ripgrep when available");
1542
- expect(publicSchemaKeys(searchFiles)).toEqual([
1543
- "query",
1544
- "path",
1545
- "exclude",
1546
- "includeIgnored",
1547
- "maxResults",
1548
- "literal",
1549
- "caseSensitive",
1550
- "contextLines",
1551
- ]);
1552
- });
1553
-
1554
- test("can vary globFiles schema through local runtime env", async () => {
1555
- const requests: Array<{ body: any }> = [];
1556
- const adapter = createCliLocalRuntimeAdapter({
1557
- env: {
1558
- OPENAI_API_KEY: "sk-local",
1559
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1560
- NOLO_GLOBFILES_DESCRIPTION_VARIANT: "antiShell",
1561
- NOLO_GLOBFILES_PARAMETER_VARIANT: "rich",
1562
- },
1563
- db: {
1564
- get: async () => ({
1565
- dbKey: TEST_CUSTOM_AGENT_KEY,
1566
- prompt: "Use local coding tools.",
1567
- model: "mimo-v2.5-pro",
1568
- provider: "custom",
1569
- tools: ["globFiles"],
1570
- }),
1571
- put: async () => {},
1572
- batch: async () => {},
1573
- iterator: () => (async function* () {})(),
1574
- },
1575
- fetchImpl: async (_url, init) => {
1576
- requests.push({ body: JSON.parse(String(init?.body)) });
1577
- return Response.json({
1578
- choices: [{ message: { content: "done" } }],
1579
- });
1580
- },
1581
- });
1582
-
1583
- await runLocalAgentTurn({
1584
- adapter,
1585
- agentRef: TEST_CUSTOM_AGENT_KEY,
1586
- input: "find tests",
1587
- });
1588
-
1589
- const globFiles = requests[0]?.body.tools.find((tool: any) => tool.function.name === "globFiles")?.function;
1590
- expect(globFiles.description).toContain("Do not use execShell or listFiles for path discovery");
1591
- expect(publicSchemaKeys(globFiles)).toEqual([
1592
- "pattern",
1593
- "path",
1594
- "exclude",
1595
- "includeIgnored",
1596
- "maxResults",
1597
- ]);
1598
- });
1599
-
1600
- test("can vary listFiles schema through local runtime env", async () => {
1601
- const requests: Array<{ body: any }> = [];
1602
- const adapter = createCliLocalRuntimeAdapter({
1603
- env: {
1604
- OPENAI_API_KEY: "sk-local",
1605
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1606
- NOLO_LISTFILES_DESCRIPTION_VARIANT: "antiShell",
1607
- NOLO_LISTFILES_PARAMETER_VARIANT: "rich",
1608
- },
1609
- db: {
1610
- get: async () => ({
1611
- dbKey: TEST_CUSTOM_AGENT_KEY,
1612
- prompt: "Use local coding tools.",
1613
- model: "mimo-v2.5-pro",
1614
- provider: "custom",
1615
- tools: ["listFiles"],
1616
- }),
1617
- put: async () => {},
1618
- batch: async () => {},
1619
- iterator: () => (async function* () {})(),
1620
- },
1621
- fetchImpl: async (_url, init) => {
1622
- requests.push({ body: JSON.parse(String(init?.body)) });
1623
- return Response.json({
1624
- choices: [{ message: { content: "done" } }],
1625
- });
1626
- },
1627
- });
1628
-
1629
- await runLocalAgentTurn({
1630
- adapter,
1631
- agentRef: TEST_CUSTOM_AGENT_KEY,
1632
- input: "list directories",
1633
- });
1634
-
1635
- const listFiles = requests[0]?.body.tools.find((tool: any) => tool.function.name === "listFiles")?.function;
1636
- expect(listFiles.description).toContain("Do not use execShell with ls/find/tree");
1637
- expect(publicSchemaKeys(listFiles)).toEqual([
1638
- "path",
1639
- "maxDepth",
1640
- "maxResults",
1641
- "entryType",
1642
- ]);
1643
- });
1644
-
1645
- test("can vary readFile schema through local runtime env", async () => {
1646
- const requests: Array<{ body: any }> = [];
1647
- const adapter = createCliLocalRuntimeAdapter({
1648
- env: {
1649
- OPENAI_API_KEY: "sk-local",
1650
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1651
- NOLO_READFILE_DESCRIPTION_VARIANT: "strategy",
1652
- NOLO_READFILE_PARAMETER_VARIANT: "rich",
1653
- },
1654
- db: {
1655
- get: async () => ({
1656
- dbKey: TEST_CUSTOM_AGENT_KEY,
1657
- prompt: "Use local coding tools.",
1658
- model: "mimo-v2.5-pro",
1659
- provider: "custom",
1660
- tools: ["readFile"],
1661
- }),
1662
- put: async () => {},
1663
- batch: async () => {},
1664
- iterator: () => (async function* () {})(),
1665
- },
1666
- fetchImpl: async (_url, init) => {
1667
- requests.push({ body: JSON.parse(String(init?.body)) });
1668
- return Response.json({
1669
- choices: [{ message: { content: "done" } }],
1670
- });
1671
- },
1672
- });
1673
-
1674
- await runLocalAgentTurn({
1675
- adapter,
1676
- agentRef: TEST_CUSTOM_AGENT_KEY,
1677
- input: "read a file range",
1678
- });
1679
-
1680
- const readFile = requests[0]?.body.tools.find((tool: any) => tool.function.name === "readFile")?.function;
1681
- expect(readFile.description).toContain("Use line ranges");
1682
- expect(readFile.parameters.properties.maxLines.description).toContain("each readFile preview consumes one budget slot");
1683
- expect(publicSchemaKeys(readFile)).toEqual([
1684
- "path",
1685
- "startLine",
1686
- "endLine",
1687
- "maxLines",
1688
- "tailLines",
1689
- ]);
1690
- });
1691
-
1692
- test("can vary searchFiles schema through local runtime env", async () => {
1693
- const requests: Array<{ body: any }> = [];
1694
- const adapter = createCliLocalRuntimeAdapter({
1695
- env: {
1696
- OPENAI_API_KEY: "sk-local",
1697
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1698
- NOLO_SEARCHFILES_DESCRIPTION_VARIANT: "antiShell",
1699
- NOLO_SEARCHFILES_PARAMETER_VARIANT: "rich",
1700
- },
1701
- db: {
1702
- get: async () => ({
1703
- dbKey: TEST_CUSTOM_AGENT_KEY,
1704
- prompt: "Use local coding tools.",
1705
- model: "mimo-v2.5-pro",
1706
- provider: "custom",
1707
- tools: ["searchFiles"],
1708
- }),
1709
- put: async () => {},
1710
- batch: async () => {},
1711
- iterator: () => (async function* () {})(),
1712
- },
1713
- fetchImpl: async (_url, init) => {
1714
- requests.push({ body: JSON.parse(String(init?.body)) });
1715
- return Response.json({
1716
- choices: [{ message: { content: "done" } }],
1717
- });
1718
- },
1719
- });
1720
-
1721
- await runLocalAgentTurn({
1722
- adapter,
1723
- agentRef: TEST_CUSTOM_AGENT_KEY,
1724
- input: "find TODO",
1725
- });
1726
-
1727
- const searchFiles = requests[0]?.body.tools.find((tool: any) => tool.function.name === "searchFiles")?.function;
1728
- expect(searchFiles.description).toContain("Do not use execShell for content search");
1729
- expect(publicSchemaKeys(searchFiles)).toEqual([
1730
- "query",
1731
- "path",
1732
- "exclude",
1733
- "includeIgnored",
1734
- "maxResults",
1735
- "literal",
1736
- "caseSensitive",
1737
- "contextLines",
1738
- ]);
1739
- });
1740
-
1741
- test("allows default semantic workspace tools without legacy agent tool declarations", async () => {
1742
- const workspaceRoot = mkdtempSync(join(tmpdir(), "nolo-cli-runtime-"));
1743
- try {
1744
- await Bun.write(join(workspaceRoot, "README.md"), "local ok\n");
1745
- const adapter = createCliLocalRuntimeAdapter({
1746
- env: {},
1747
- cwd: workspaceRoot,
1748
- db: {
1749
- get: async () => ({
1750
- dbKey: "agent-local-default-tools",
1751
- prompt: "Use local workspace tools.",
1752
- model: "gpt-4.1-mini",
1753
- }),
1754
- put: async () => {},
1755
- batch: async () => {},
1756
- iterator: () => (async function* () {})(),
1757
- },
1758
- fetchImpl: async () => Response.json({}),
1759
- });
1760
-
1761
- await adapter.loadAgentConfig("default-tools");
1762
- await expect(adapter.executeTool({
1763
- id: "call-read",
1764
- name: "readFile",
1765
- arguments: JSON.stringify({ path: "README.md" }),
1766
- })).resolves.toMatchObject({
1767
- content: "local ok\n",
1768
- });
1769
- } finally {
1770
- rmSync(workspaceRoot, { recursive: true, force: true });
1771
- }
1772
- });
1773
-
1774
- test("exposes declared server table write tools in local runtime requests", async () => {
1775
- const requests: Array<{ body: any }> = [];
1776
- const adapter = createCliLocalRuntimeAdapter({
1777
- env: {
1778
- OPENAI_API_KEY: "sk-local",
1779
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1780
- },
1781
- db: {
1782
- get: async () => ({
1783
- dbKey: "agent-local-table",
1784
- prompt: "Use table tools.",
1785
- model: "gpt-4.1-mini",
1786
- toolNames: ["createTable", "addTableRow", "addTableRows"],
1787
- }),
1788
- put: async () => {},
1789
- batch: async () => {},
1790
- iterator: () => (async function* () {})(),
1791
- },
1792
- fetchImpl: async (_url, init) => {
1793
- requests.push({ body: JSON.parse(String(init?.body)) });
1794
- return Response.json({
1795
- choices: [{ message: { content: "done" } }],
1796
- });
1797
- },
1798
- });
1799
-
1800
- await runLocalAgentTurn({
1801
- adapter,
1802
- agentRef: "table",
1803
- input: "采集并写入 table",
1804
- });
1805
-
1806
- const toolNames = toolNamesFromRequest(requests[0]);
1807
- expect(toolNames).toContain("createTable");
1808
- expect(toolNames).toContain("addTableRow");
1809
- expect(toolNames).toContain("addTableRows");
1810
- });
1811
-
1812
- test("executes declared createTable through the server table bridge when capture is explicit", async () => {
1813
- const requests: Array<{ url: string; auth: string | null; body: any }> = [];
1814
- const adapter = createCliLocalRuntimeAdapter({
1815
- env: {
1816
- NOLO_SERVER: "https://us.nolo.chat",
1817
- AUTH_TOKEN: "token-1",
1818
- },
1819
- db: {
1820
- get: async () => ({
1821
- dbKey: "agent-local-table-write",
1822
- toolNames: ["createTable"],
1823
- }),
1824
- put: async () => {},
1825
- batch: async () => {},
1826
- iterator: () => (async function* () {})(),
1827
- },
1828
- fetchImpl: async (url, init) => {
1829
- requests.push({
1830
- url: String(url),
1831
- auth: new Headers(init?.headers).get("authorization"),
1832
- body: JSON.parse(String(init?.body)),
1833
- });
1834
- return Response.json({
1835
- ok: true,
1836
- tenantId: "user-1",
1837
- tableId: "table-1",
1838
- });
1839
- },
1840
- });
1841
-
1842
- await adapter.loadAgentConfig("table-write");
1843
- const result = await adapter.executeTool({
1844
- id: "call-create-table",
1845
- name: "createTable",
1846
- userInput: "采集这个用户并写入 table",
1847
- arguments: JSON.stringify({
1848
- title: "XHS profile",
1849
- purpose: "agent_eval_workbench",
1850
- columns: [{ name: "nickname" }],
1851
- }),
1852
- });
1853
-
1854
- expect(requests).toEqual([
1855
- {
1856
- url: "https://us.nolo.chat/api/table/create",
1857
- auth: "Bearer token-1",
1858
- body: {
1859
- title: "XHS profile",
1860
- purpose: "agent_eval_workbench",
1861
- columns: [{ name: "nickname" }],
1862
- },
1863
- },
1864
- ]);
1865
- expect(result.content).toContain("\"tableId\":\"table-1\"");
1866
- expect(result.metadata).toMatchObject({
1867
- serverPlatformTool: true,
1868
- tableWrite: true,
1869
- });
1870
- });
1871
-
1872
- test("blocks local table writes when the current user request is not explicit capture", async () => {
1873
- const adapter = createCliLocalRuntimeAdapter({
1874
- env: {
1875
- NOLO_SERVER: "https://us.nolo.chat",
1876
- AUTH_TOKEN: "token-1",
1877
- },
1878
- db: {
1879
- get: async () => ({
1880
- dbKey: "agent-local-table-blocked",
1881
- toolNames: ["createTable"],
1882
- }),
1883
- put: async () => {},
1884
- batch: async () => {},
1885
- iterator: () => (async function* () {})(),
1886
- },
1887
- fetchImpl: async () => {
1888
- throw new Error("blocked createTable must not reach the server");
1889
- },
1890
- });
1891
-
1892
- await adapter.loadAgentConfig("table-blocked");
1893
- const result = await adapter.executeTool({
1894
- id: "call-create-table-blocked",
1895
- name: "createTable",
1896
- userInput: "总结这个用户画像",
1897
- arguments: JSON.stringify({
1898
- title: "XHS profile",
1899
- columns: [{ name: "nickname" }],
1900
- }),
1901
- });
1902
-
1903
- const parsed = JSON.parse(result.content);
1904
- expect(parsed.error).toBe("knowledge_capture_requires_confirmation");
1905
- expect(result.metadata).toMatchObject({
1906
- serverPlatformTool: true,
1907
- tableWriteBlocked: true,
1908
- });
1909
- });
1910
-
1911
- test("adds typed CLI workspace tools to the default nolo local agent request", async () => {
1912
- const requests: Array<{ body: any }> = [];
1913
- const adapter = createCliLocalRuntimeAdapter({
1914
- env: {
1915
- OPENAI_API_KEY: "sk-local",
1916
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
1917
- },
1918
- db: {
1919
- get: async () => ({
1920
- dbKey: "agent-pub-01NOLOAPPBLD000000019KCKT0",
1921
- id: "01NOLOAPPBLD000000019KCKT0",
1922
- name: "nolo",
1923
- prompt: "Route through typed tools.",
1924
- model: "gpt-4.1-mini",
1925
- tools: ["fetchWebpage"],
1926
- }),
1927
- put: async () => {},
1928
- batch: async () => {},
1929
- iterator: () => (async function* () {})(),
1930
- },
1931
- fetchImpl: async (_url, init) => {
1932
- requests.push({ body: JSON.parse(String(init?.body)) });
1933
- return Response.json({
1934
- choices: [{ message: { content: "done" } }],
1935
- });
1936
- },
1937
- });
1938
-
1939
- await runLocalAgentTurn({
1940
- adapter,
1941
- agentRef: "agent-pub-01NOLOAPPBLD000000019KCKT0",
1942
- input: "帮我总结最近 10 个对话",
1943
- });
1944
-
1945
- const toolNames = toolNamesFromRequest(requests[0]);
1946
- expect(toolNames).toContain("listDialogs");
1947
- expect(toolNames).toContain("readDialog");
1948
- expect(toolNames).toContain("listAgents");
1949
- expect(toolNames).toContain("readSpace");
1950
- expect(toolNames).toContain("queryTableRows");
1951
- });
1952
-
1953
- test("executes typed CLI workspace tools through whitelisted nolo commands", async () => {
1954
- const spawnCalls: Array<{ cmd: string[]; env: NodeJS.ProcessEnv }> = [];
1955
- const originalSpawn = Bun.spawn;
1956
- Bun.spawn = ((options: { cmd: string[]; env: NodeJS.ProcessEnv }) => {
1957
- spawnCalls.push(options);
1958
- return {
1959
- stdout: new ReadableStream({
1960
- start(controller) {
1961
- controller.enqueue(new TextEncoder().encode("dialog output\n"));
1962
- controller.close();
1963
- },
1964
- }),
1965
- stderr: new ReadableStream({
1966
- start(controller) {
1967
- controller.close();
1968
- },
1969
- }),
1970
- exited: Promise.resolve(0),
1971
- };
1972
- }) as unknown as typeof Bun.spawn;
1973
-
1974
- try {
1975
- const adapter = createCliLocalRuntimeAdapter({
1976
- env: {
1977
- NOLO_LOCAL_USER_ID: "user-1",
1978
- AUTH_TOKEN: "token-1",
1979
- },
1980
- db: {
1981
- get: async () => ({
1982
- dbKey: "agent-pub-01NOLOAPPBLD000000019KCKT0",
1983
- id: "01NOLOAPPBLD000000019KCKT0",
1984
- }),
1985
- put: async () => {},
1986
- batch: async () => {},
1987
- iterator: () => (async function* () {})(),
1988
- },
1989
- fetchImpl: async () => Response.json({}),
1990
- });
1991
-
1992
- await adapter.loadAgentConfig("agent-pub-01NOLOAPPBLD000000019KCKT0");
1993
- const result = await adapter.executeTool({
1994
- id: "call-list-dialogs",
1995
- name: "listDialogs",
1996
- arguments: JSON.stringify({ limit: 3 }),
1997
- });
1998
-
1999
- expect(result.content).toBe("dialog output\n");
2000
- expect(result.metadata).toMatchObject({
2001
- cliWorkspaceTool: true,
2002
- exitCode: 0,
2003
- });
2004
- expect(spawnCalls[0]?.cmd.at(-5)?.endsWith("index.ts")).toBe(true);
2005
- expect(spawnCalls[0]?.cmd.slice(-4)).toEqual([
2006
- "dialog",
2007
- "list",
2008
- "--limit",
2009
- "3",
2010
- ]);
2011
- } finally {
2012
- Bun.spawn = originalSpawn;
2013
- }
2014
- });
2015
-
2016
- test("runs execShell locally by default", async () => {
2017
- const adapter = createCliLocalRuntimeAdapter({
2018
- env: {},
2019
- db: {
2020
- get: async () => ({
2021
- dbKey: "agent-local-shell",
2022
- toolNames: ["execShell"],
2023
- }),
2024
- put: async () => {},
2025
- batch: async () => {},
2026
- iterator: () => (async function* () {})(),
2027
- },
2028
- cwd: import.meta.dir,
2029
- localToolExecutors: {
2030
- execShell: async () => ({
2031
- content: import.meta.dir,
2032
- metadata: { exitCode: 0, timedOut: false },
2033
- }),
2034
- },
2035
- fetchImpl: async () => Response.json({}),
2036
- });
2037
-
2038
- await adapter.loadAgentConfig("shell");
2039
- const result = await adapter.executeTool({
2040
- id: "call-1",
2041
- name: "execShell",
2042
- arguments: "{\"cmd\":\"pwd\"}",
2043
- });
2044
-
2045
- expect(result.content).toContain(import.meta.dir);
2046
- expect(result.metadata).toMatchObject({ exitCode: 0 });
2047
- });
2048
-
2049
- test("applies runtime policy shell settings to local executors without adding a timeout", async () => {
2050
- const requests: Array<{ body: any }> = [];
2051
- const adapter = createCliLocalRuntimeAdapter({
2052
- env: {
2053
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
2054
- },
2055
- db: {
2056
- get: async () => ({
2057
- dbKey: "agent-local-shell-limits",
2058
- prompt: "Use shell when needed.",
2059
- model: "qwen-coder",
2060
- runtimeToolPolicy: {
2061
- version: 1,
2062
- runtimeTools: ["execShell"],
2063
- shell: { enabled: true, mode: "worktree", maxOutputBytes: 120 },
2064
- },
2065
- }),
2066
- put: async () => {},
2067
- batch: async () => {},
2068
- iterator: () => (async function* () {})(),
2069
- },
2070
- cwd: import.meta.dir,
2071
- fetchImpl: async (_url, init) => {
2072
- requests.push({ body: JSON.parse(String(init?.body)) });
2073
- if (requests.length === 1) {
2074
- return Response.json({
2075
- choices: [{
2076
- message: {
2077
- content: "",
2078
- tool_calls: [{
2079
- id: "call-1",
2080
- type: "function",
2081
- function: {
2082
- name: "execShell",
2083
- arguments: JSON.stringify({
2084
- cmd: process.platform === "win32"
2085
- ? "'abcdefghijklmnopqrstuvwxyz0123456789'"
2086
- : "node -e 'console.log(\"x\".repeat(50))'",
2087
- }),
2088
- },
2089
- }],
2090
- },
2091
- }],
2092
- });
2093
- }
2094
- return Response.json({
2095
- choices: [{ message: { content: "limits applied" } }],
2096
- });
2097
- },
2098
- });
2099
-
2100
- const result = await runLocalAgentTurn({
2101
- adapter,
2102
- agentRef: "shell-limits",
2103
- input: "run output limit check",
2104
- });
2105
-
2106
- expect(result.content).toBe("limits applied");
2107
- const toolResult = requests[1]?.body.messages.at(-1)?.content ?? "";
2108
- expect(toolResult).toContain("exitCode: 0");
2109
- expect(toolResult).not.toContain("command timed out");
2110
- });
2111
-
2112
- test("accepts execShell aliases from the local model", async () => {
2113
- const requests: Array<{ body: any }> = [];
2114
- const adapter = createCliLocalRuntimeAdapter({
2115
- env: {
2116
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
2117
- },
2118
- db: {
2119
- get: async () => ({
2120
- dbKey: "agent-local-shell-alias",
2121
- prompt: "Use shell when needed.",
2122
- model: "qwen-coder",
2123
- toolNames: ["execShell"],
2124
- }),
2125
- put: async () => {},
2126
- batch: async () => {},
2127
- iterator: () => (async function* () {})(),
2128
- },
2129
- cwd: import.meta.dir,
2130
- localToolExecutors: {
2131
- execShell: async () => ({
2132
- content: import.meta.dir,
2133
- metadata: { exitCode: 0, timedOut: false },
2134
- }),
2135
- },
2136
- fetchImpl: async (_url, init) => {
2137
- requests.push({ body: JSON.parse(String(init?.body)) });
2138
- if (requests.length === 1) {
2139
- return Response.json({
2140
- choices: [{
2141
- message: {
2142
- content: "",
2143
- tool_calls: [{
2144
- id: "call-1",
2145
- type: "function",
2146
- function: { name: "runCommand", arguments: "{\"cmd\":\"pwd\"}" },
2147
- }],
2148
- },
2149
- }],
2150
- });
2151
- }
2152
- return Response.json({
2153
- choices: [{ message: { content: "alias ok" } }],
2154
- });
2155
- },
2156
- });
2157
-
2158
- const result = await runLocalAgentTurn({
2159
- adapter,
2160
- agentRef: "shell",
2161
- input: "print cwd",
2162
- });
2163
-
2164
- expect(result.content).toBe("alias ok");
2165
- expect(requests[1]?.body.messages.at(-1)?.content).toContain(import.meta.dir);
2166
- });
2167
-
2168
- test("blocks destructive local execShell calls unless the user explicitly asked to delete", async () => {
2169
- let executorCalls = 0;
2170
- const adapter = createCliLocalRuntimeAdapter({
2171
- env: {
2172
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
2173
- },
2174
- db: {
2175
- get: async () => ({
2176
- dbKey: "agent-local-shell-guard",
2177
- prompt: "Use shell when useful.",
2178
- model: "qwen-coder",
2179
- toolNames: ["execShell"],
2180
- }),
2181
- put: async () => {},
2182
- batch: async () => {},
2183
- iterator: () => (async function* () {})(),
2184
- },
2185
- cwd: import.meta.dir,
2186
- localToolExecutors: {
2187
- execShell: async () => {
2188
- executorCalls += 1;
2189
- return {
2190
- content: "should not run",
2191
- };
2192
- },
2193
- },
2194
- fetchImpl: async (_url, init) => {
2195
- const body = JSON.parse(String(init?.body));
2196
- const lastToolMessage = [...body.messages]
2197
- .reverse()
2198
- .find((message: any) => message.role === "tool");
2199
- if (lastToolMessage) {
2200
- expect(String(lastToolMessage.content)).toContain(
2201
- "destructive_action_requires_confirmation",
2202
- );
2203
- return Response.json({
2204
- choices: [{ message: { content: "guard ok" } }],
2205
- });
2206
- }
2207
- return Response.json({
2208
- choices: [{
2209
- message: {
2210
- content: "",
2211
- tool_calls: [{
2212
- id: "call-1",
2213
- type: "function",
2214
- function: {
2215
- name: "execShell",
2216
- arguments: "{\"cmd\":\"rm -rf ./tmp\"}",
2217
- },
2218
- }],
2219
- },
2220
- }],
2221
- });
2222
- },
2223
- });
2224
-
2225
- const result = await runLocalAgentTurn({
2226
- adapter,
2227
- agentRef: "shell",
2228
- input: "inspect cwd but don't delete files",
2229
- });
2230
-
2231
- expect(result.content).toBe("guard ok");
2232
- expect(executorCalls).toBe(0);
2233
- });
2234
-
2235
- test("exposes runtime policy tools to the local model even when toolNames omits them", async () => {
2236
- const requests: Array<{ body: any }> = [];
2237
- const adapter = createCliLocalRuntimeAdapter({
2238
- env: {
2239
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
2240
- },
2241
- db: {
2242
- get: async () => ({
2243
- dbKey: "agent-local-policy-shell",
2244
- prompt: "Use shell when needed.",
2245
- model: "qwen-coder",
2246
- runtimeToolPolicy: {
2247
- version: 1,
2248
- runtimeTools: ["execShell"],
2249
- },
2250
- }),
2251
- put: async () => {},
2252
- batch: async () => {},
2253
- iterator: () => (async function* () {})(),
2254
- },
2255
- cwd: import.meta.dir,
2256
- localToolExecutors: {
2257
- execShell: async () => ({
2258
- content: import.meta.dir,
2259
- metadata: { exitCode: 0, timedOut: false },
2260
- }),
2261
- },
2262
- fetchImpl: async (_url, init) => {
2263
- requests.push({ body: JSON.parse(String(init?.body)) });
2264
- if (requests.length === 1) {
2265
- return Response.json({
2266
- choices: [{
2267
- message: {
2268
- content: "",
2269
- tool_calls: [{
2270
- id: "call-1",
2271
- type: "function",
2272
- function: { name: "execShell", arguments: "{\"cmd\":\"pwd\"}" },
2273
- }],
2274
- },
2275
- }],
2276
- });
2277
- }
2278
- return Response.json({
2279
- choices: [{ message: { content: "policy shell ok" } }],
2280
- });
2281
- },
2282
- });
2283
-
2284
- const result = await runLocalAgentTurn({
2285
- adapter,
2286
- agentRef: "shell",
2287
- input: "print cwd",
2288
- });
2289
-
2290
- expect(result.content).toBe("policy shell ok");
2291
- expect(toolNamesFromRequest(requests[0])).toContain("execShell");
2292
- expect(requests[1]?.body.messages.at(-1)?.content).toContain(import.meta.dir);
2293
- });
2294
-
2295
- test("treats runtime policy visual tools as declared local tools", async () => {
2296
- const adapter = createCliLocalRuntimeAdapter({
2297
- env: {
2298
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
2299
- },
2300
- db: {
2301
- get: async () => ({
2302
- dbKey: "agent-local-visual",
2303
- prompt: "Inspect the page.",
2304
- model: "qwen-coder",
2305
- runtimeToolPolicy: {
2306
- version: 1,
2307
- runtimeTools: ["captureVisualState"],
2308
- },
2309
- }),
2310
- put: async () => {},
2311
- batch: async () => {},
2312
- iterator: () => (async function* () {})(),
2313
- },
2314
- cwd: import.meta.dir,
2315
- localToolExecutors: {
2316
- captureVisualState: async () => ({
2317
- content: "{\"status\":\"ok\"}",
2318
- }),
2319
- },
2320
- fetchImpl: async (_url, init) => {
2321
- expect(toolNamesFromRequest({ body: JSON.parse(String(init?.body)) })).toContain("captureVisualState");
2322
- return Response.json({
2323
- choices: [{ message: { content: "visual ok" } }],
2324
- });
2325
- },
2326
- });
2327
-
2328
- await adapter.loadAgentConfig("visual");
2329
- await expect(adapter.executeTool({
2330
- id: "call-visual",
2331
- name: "captureVisualState",
2332
- arguments: JSON.stringify({ waitSelector: "body" }),
2333
- })).resolves.toMatchObject({
2334
- content: "{\"status\":\"ok\"}",
2335
- });
2336
- });
2337
-
2338
- test("exposes read_xhs_profile to OpenAI-compatible providers when the agent declares it", async () => {
2339
- const requests: Array<{ body: any }> = [];
2340
- const adapter = createCliLocalRuntimeAdapter({
2341
- env: {
2342
- OPENAI_API_KEY: "sk-local",
2343
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
2344
- },
2345
- db: {
2346
- get: async () => ({
2347
- dbKey: "agent-local-xhs",
2348
- prompt: "Read XHS profile.",
2349
- model: "gpt-4.1-mini",
2350
- toolNames: ["read_xhs_profile"],
2351
- }),
2352
- put: async () => {},
2353
- batch: async () => {},
2354
- iterator: () => (async function* () {})(),
2355
- },
2356
- fetchImpl: async (_url, init) => {
2357
- requests.push({ body: JSON.parse(String(init?.body)) });
2358
- return Response.json({
2359
- choices: [{ message: { content: "done" } }],
2360
- });
2361
- },
2362
- });
2363
-
2364
- await runLocalAgentTurn({
2365
- adapter,
2366
- agentRef: "xhs",
2367
- input: "读取小红书用户主页",
2368
- });
2369
-
2370
- expect(toolNamesFromRequest(requests[0])).toContain("read_xhs_profile");
2371
- });
2372
-
2373
- test("exposes read_x_post to OpenAI-compatible providers when the agent declares it", async () => {
2374
- const requests: Array<{ body: any }> = [];
2375
- const adapter = createCliLocalRuntimeAdapter({
2376
- env: {
2377
- OPENAI_API_KEY: "sk-local",
2378
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
2379
- },
2380
- db: {
2381
- get: async () => ({
2382
- dbKey: "agent-local-x-post",
2383
- prompt: "Read X posts.",
2384
- model: "gpt-4.1-mini",
2385
- toolNames: ["read_x_post"],
2386
- }),
2387
- put: async () => {},
2388
- batch: async () => {},
2389
- iterator: () => (async function* () {})(),
2390
- },
2391
- fetchImpl: async (_url, init) => {
2392
- requests.push({ body: JSON.parse(String(init?.body)) });
2393
- return Response.json({
2394
- choices: [{ message: { content: "done" } }],
2395
- });
2396
- },
2397
- });
2398
-
2399
- await runLocalAgentTurn({
2400
- adapter,
2401
- agentRef: "x-post",
2402
- input: "读取 X 帖子",
2403
- });
2404
-
2405
- expect(toolNamesFromRequest(requests[0])).toContain("read_x_post");
2406
- });
2407
-
2408
- test("adds read_x_post to local web-capable agent tool surface", async () => {
2409
- const requests: Array<{ body: any }> = [];
2410
- const adapter = createCliLocalRuntimeAdapter({
2411
- env: {
2412
- OPENAI_API_KEY: "sk-local",
2413
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
2414
- },
2415
- db: {
2416
- get: async () => ({
2417
- dbKey: "agent-local-web-reader",
2418
- prompt: "Read web pages.",
2419
- model: "gpt-4.1-mini",
2420
- toolNames: ["fetchWebpage"],
2421
- }),
2422
- put: async () => {},
2423
- batch: async () => {},
2424
- iterator: () => (async function* () {})(),
2425
- },
2426
- fetchImpl: async (_url, init) => {
2427
- requests.push({ body: JSON.parse(String(init?.body)) });
2428
- return Response.json({
2429
- choices: [{ message: { content: "done" } }],
2430
- });
2431
- },
2432
- });
2433
-
2434
- await runLocalAgentTurn({
2435
- adapter,
2436
- agentRef: "web-reader",
2437
- input: "读取 X 帖子",
2438
- });
2439
-
2440
- expect(toolNamesFromRequest(requests[0])).toContain("read_x_post");
2441
- });
2442
-
2443
- test("does not expose read_xhs_profile when the agent does not declare it", async () => {
2444
- const requests: Array<{ body: any }> = [];
2445
- const adapter = createCliLocalRuntimeAdapter({
2446
- env: {
2447
- OPENAI_API_KEY: "sk-local",
2448
- NOLO_LOCAL_OPENAI_BASE_URL: "http://127.0.0.1:11434/v1",
2449
- },
2450
- db: {
2451
- get: async () => ({
2452
- dbKey: "agent-local-no-xhs",
2453
- prompt: "Be helpful.",
2454
- model: "gpt-4.1-mini",
2455
- }),
2456
- put: async () => {},
2457
- batch: async () => {},
2458
- iterator: () => (async function* () {})(),
2459
- },
2460
- fetchImpl: async (_url, init) => {
2461
- requests.push({ body: JSON.parse(String(init?.body)) });
2462
- return Response.json({
2463
- choices: [{ message: { content: "done" } }],
2464
- });
2465
- },
2466
- });
2467
-
2468
- await runLocalAgentTurn({
2469
- adapter,
2470
- agentRef: "no-xhs",
2471
- input: "hello",
2472
- });
2473
-
2474
- expect(toolNamesFromRequest(requests[0])).not.toContain("read_xhs_profile");
2475
- });
2476
-
2477
- test("executes read_xhs_profile locally through the desktop bridge", async () => {
2478
- const xhsCalls: Array<{ args: any }> = [];
2479
- const adapter = createCliLocalRuntimeAdapter({
2480
- env: {
2481
- NOLO_LOCAL_USER_ID: "user-1",
2482
- },
2483
- db: {
2484
- get: async () => ({
2485
- dbKey: "agent-user-1-xhs",
2486
- id: "xhs-agent",
2487
- prompt: "Read XHS.",
2488
- toolNames: ["read_xhs_profile"],
2489
- }),
2490
- put: async () => {},
2491
- batch: async () => {},
2492
- iterator: () => (async function* () {})(),
2493
- },
2494
- localToolExecutors: {
2495
- read_xhs_profile: async (call) => {
2496
- const parsed = JSON.parse(call.arguments || "{}");
2497
- xhsCalls.push({ args: parsed });
2498
- return {
2499
- content: JSON.stringify({
2500
- ok: true,
2501
- data: {
2502
- profile: { nickname: "test-soul", redId: "12345" },
2503
- notes: [],
2504
- noteDetails: [],
2505
- analysis: {
2506
- totalNotes: 0,
2507
- commentBuckets: [],
2508
- },
2509
- },
2510
- }),
2511
- metadata: { xhsLocalBridge: true },
2512
- };
2513
- },
2514
- },
2515
- fetchImpl: async () => Response.json({}),
2516
- });
2517
-
2518
- await adapter.loadAgentConfig("xhs-agent");
2519
- const result = await adapter.executeTool({
2520
- id: "call-xhs-1",
2521
- name: "read_xhs_profile",
2522
- arguments: JSON.stringify({
2523
- url: "https://www.xiaohongshu.com/user/profile/5d2be8720000000010007556",
2524
- maxScrollPages: 3,
2525
- }),
2526
- });
2527
-
2528
- expect(xhsCalls).toHaveLength(1);
2529
- expect(xhsCalls[0].args.url).toBe(
2530
- "https://www.xiaohongshu.com/user/profile/5d2be8720000000010007556"
2531
- );
2532
- expect(xhsCalls[0].args.maxScrollPages).toBe(3);
2533
- expect(result.metadata).toMatchObject({ xhsLocalBridge: true });
2534
- const parsed = JSON.parse(result.content);
2535
- expect(parsed.ok).toBe(true);
2536
- expect(parsed.data.profile.nickname).toBe("test-soul");
2537
- });
2538
-
2539
- test("default read_x_post executor calls the local bridge reader", async () => {
2540
- const readerCalls: Array<{ args: any }> = [];
2541
- const adapter = createCliLocalRuntimeAdapter({
2542
- env: {
2543
- NOLO_LOCAL_USER_ID: "user-1",
2544
- },
2545
- db: {
2546
- get: async () => ({
2547
- dbKey: "agent-user-1-x-post-default",
2548
- id: "x-post-default",
2549
- prompt: "Read X posts.",
2550
- toolNames: ["read_x_post"],
2551
- }),
2552
- put: async () => {},
2553
- batch: async () => {},
2554
- iterator: () => (async function* () {})(),
2555
- },
2556
- readXPost: async (args) => {
2557
- readerCalls.push({ args });
2558
- return {
2559
- rawData: {
2560
- ok: true,
2561
- backend: "desktop_local_browser",
2562
- fetchedAt: "2026-06-08T00:00:00.000Z",
2563
- data: {
2564
- id: "2063842222307704944",
2565
- url: "https://x.com/BohuTANG/status/2063842222307704944",
2566
- text: "mock x post",
2567
- author: {
2568
- handle: "BohuTANG",
2569
- displayName: "Bohu",
2570
- },
2571
- },
2572
- } as any,
2573
- displayData: "已读取 X 帖子:@BohuTANG",
2574
- };
2575
- },
2576
- fetchImpl: async () => Response.json({}),
2577
- });
2578
-
2579
- await adapter.loadAgentConfig("x-post-default");
2580
- const result = await adapter.executeTool({
2581
- id: "call-x-post-default",
2582
- name: "read_x_post",
2583
- arguments: JSON.stringify({
2584
- url: "https://x.com/BohuTANG/status/2063842222307704944",
2585
- keepOpen: true,
2586
- }),
2587
- });
2588
-
2589
- expect(readerCalls).toHaveLength(1);
2590
- expect(readerCalls[0].args).toMatchObject({
2591
- url: "https://x.com/BohuTANG/status/2063842222307704944",
2592
- keepOpen: true,
2593
- });
2594
- expect(result.metadata).toMatchObject({ xPostLocalBridge: true });
2595
- const parsed = JSON.parse(result.content);
2596
- expect(parsed.ok).toBe(true);
2597
- expect(parsed.data.text).toBe("mock x post");
2598
- });
2599
-
2600
- test("default read_xhs_profile executor calls the local bridge reader", async () => {
2601
- const readerCalls: Array<{ args: any; thunkApi: any }> = [];
2602
- const adapter = createCliLocalRuntimeAdapter({
2603
- env: {
2604
- NOLO_LOCAL_USER_ID: "user-1",
2605
- },
2606
- db: {
2607
- get: async () => ({
2608
- dbKey: "agent-user-1-xhs-default",
2609
- id: "xhs-default",
2610
- prompt: "Read XHS.",
2611
- toolNames: ["read_xhs_profile"],
2612
- }),
2613
- put: async () => {},
2614
- batch: async () => {},
2615
- iterator: () => (async function* () {})(),
2616
- },
2617
- readXhsProfile: async (args, thunkApi) => {
2618
- readerCalls.push({ args, thunkApi });
2619
- return {
2620
- rawData: {
2621
- ok: true,
2622
- data: {
2623
- profile: { nickname: "default-bridge", redId: "67890" },
2624
- notes: [],
2625
- noteDetails: [],
2626
- commentsByNote: {},
2627
- analysis: {
2628
- totalNotes: 0,
2629
- averageLikes: 0,
2630
- averageComments: 0,
2631
- averageCollects: 0,
2632
- averageShares: 0,
2633
- commentBuckets: [],
2634
- themes: [],
2635
- },
2636
- },
2637
- fetchedAt: "2026-06-03T00:00:00.000Z",
2638
- } as any,
2639
- displayData: "小红书用户: default-bridge",
2640
- };
2641
- },
2642
- fetchImpl: async () => Response.json({}),
2643
- });
2644
-
2645
- await adapter.loadAgentConfig("xhs-default");
2646
- const result = await adapter.executeTool({
2647
- id: "call-xhs-default",
2648
- name: "read_xhs_profile",
2649
- arguments: JSON.stringify({
2650
- url: "https://www.xiaohongshu.com/user/profile/5d2be8720000000010007556",
2651
- includeComments: true,
2652
- maxCommentPagesPerNote: 1,
2653
- }),
2654
- });
2655
-
2656
- expect(readerCalls).toHaveLength(1);
2657
- expect(readerCalls[0].args).toMatchObject({
2658
- url: "https://www.xiaohongshu.com/user/profile/5d2be8720000000010007556",
2659
- includeComments: true,
2660
- maxCommentPagesPerNote: 1,
2661
- });
2662
- expect(readerCalls[0].args.profileDir).toBeUndefined();
2663
- expect(readerCalls[0].thunkApi).toBeUndefined();
2664
- expect(result.metadata).toMatchObject({
2665
- xhsLocalBridge: true,
2666
- displayData: "小红书用户: default-bridge",
2667
- });
2668
- expect(JSON.parse(result.content).data.profile.nickname).toBe("default-bridge");
2669
- });
2670
-
2671
- test("default read_xhs_profile executor ignores explicit XHS profile env", async () => {
2672
- const readerCalls: Array<{ args: any }> = [];
2673
- const adapter = createCliLocalRuntimeAdapter({
2674
- env: {
2675
- NOLO_LOCAL_USER_ID: "user-1",
2676
- NOLO_XHS_READER_PROFILE_DIR: "/tmp/custom-xhs-profile",
2677
- },
2678
- db: {
2679
- get: async () => ({
2680
- dbKey: "agent-user-1-xhs-env",
2681
- id: "xhs-env",
2682
- prompt: "Read XHS.",
2683
- toolNames: ["read_xhs_profile"],
2684
- }),
2685
- put: async () => {},
2686
- batch: async () => {},
2687
- iterator: () => (async function* () {})(),
2688
- },
2689
- readXhsProfile: async (args) => {
2690
- readerCalls.push({ args });
2691
- return {
2692
- rawData: {
2693
- ok: true,
2694
- data: {
2695
- profile: { nickname: "env-bridge" },
2696
- notes: [],
2697
- noteDetails: [],
2698
- commentsByNote: {},
2699
- analysis: { totalNotes: 0, commentBuckets: [] },
2700
- },
2701
- fetchedAt: "2026-06-03T00:00:00.000Z",
2702
- } as any,
2703
- displayData: "小红书用户: env-bridge",
2704
- };
2705
- },
2706
- fetchImpl: async () => Response.json({}),
2707
- });
2708
-
2709
- await adapter.loadAgentConfig("xhs-env");
2710
- await adapter.executeTool({
2711
- id: "call-xhs-env",
2712
- name: "read_xhs_profile",
2713
- arguments: JSON.stringify({
2714
- url: "https://www.xiaohongshu.com/user/profile/5d2be8720000000010007556",
2715
- }),
2716
- });
2717
-
2718
- expect(readerCalls).toHaveLength(1);
2719
- expect(readerCalls[0].args.profileDir).toBeUndefined();
2720
- });
2721
-
2722
- test("read_xhs_profile executor does not falsely succeed when bridge is unavailable", async () => {
2723
- const adapter = createCliLocalRuntimeAdapter({
2724
- env: {
2725
- NOLO_LOCAL_USER_ID: "user-1",
2726
- },
2727
- db: {
2728
- get: async () => ({
2729
- dbKey: "agent-user-1-xhs-fail",
2730
- id: "xhs-fail",
2731
- prompt: "Read XHS.",
2732
- toolNames: ["read_xhs_profile"],
2733
- }),
2734
- put: async () => {},
2735
- batch: async () => {},
2736
- iterator: () => (async function* () {})(),
2737
- },
2738
- localToolExecutors: {
2739
- read_xhs_profile: async () => ({
2740
- content: JSON.stringify({
2741
- ok: false,
2742
- code: "network_error",
2743
- message: "read_xhs_profile needs Playwright but it is not installed.",
2744
- }),
2745
- metadata: { xhsLocalBridge: true, bridgeError: true },
2746
- }),
2747
- },
2748
- fetchImpl: async () => Response.json({}),
2749
- });
2750
-
2751
- await adapter.loadAgentConfig("xhs-fail");
2752
- const result = await adapter.executeTool({
2753
- id: "call-xhs-fail",
2754
- name: "read_xhs_profile",
2755
- arguments: JSON.stringify({
2756
- url: "https://www.xiaohongshu.com/user/profile/5d2be8720000000010007556",
2757
- }),
2758
- });
2759
-
2760
- const parsed = JSON.parse(result.content);
2761
- expect(parsed.ok).toBe(false);
2762
- expect(parsed.code).toBe("network_error");
2763
- expect(result.metadata).toMatchObject({ bridgeError: true });
2764
- });
2765
-
2766
- test("runs allowed workspace file tools through default local executors", async () => {
2767
- const workspaceRoot = mkdtempSync(join(tmpdir(), "nolo-cli-runtime-"));
2768
- try {
2769
- const store = new Map<string, any>([
2770
- ["agent-user-1-writer", {
2771
- dbKey: "agent-user-1-writer",
2772
- id: "writer",
2773
- toolNames: ["writeFile"],
2774
- }],
2775
- ]);
2776
- const adapter = createCliLocalRuntimeAdapter({
2777
- env: {
2778
- NOLO_LOCAL_USER_ID: "user-1",
2779
- },
2780
- db: {
2781
- get: async (key) => {
2782
- if (!store.has(key)) throw new Error(`not found: ${key}`);
2783
- return store.get(key);
2784
- },
2785
- put: async () => {},
2786
- batch: async () => {},
2787
- iterator: () => (async function* () {})(),
2788
- },
2789
- cwd: workspaceRoot,
2790
- fetchImpl: async () => Response.json({}),
2791
- });
2792
-
2793
- await adapter.loadAgentConfig("writer");
2794
- const result = await adapter.executeTool({
2795
- id: "call-1",
2796
- name: "writeFile",
2797
- arguments: JSON.stringify({
2798
- path: "src/app.ts",
2799
- content: "export const cliValue = 1;\n",
2800
- }),
2801
- });
2802
-
2803
- expect(result.content).toBe(`wrote ${join("src", "app.ts")}`);
2804
- expect(readFileSync(join(workspaceRoot, "src/app.ts"), "utf8")).toBe("export const cliValue = 1;\n");
2805
- } finally {
2806
- rmSync(workspaceRoot, { recursive: true, force: true });
2807
- }
2808
- });
2809
- });