akanjs 3.2.0-rc.2 → 3.2.0-rc.21

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 (667) hide show
  1. package/ARCHITECTURE.md +42 -41
  2. package/CHANGELOG.md +593 -3
  3. package/CONTRIBUTING.md +26 -0
  4. package/base/base.ts +2 -1
  5. package/client/clientRuntime.ts +1 -0
  6. package/client/cn.ts +2 -2
  7. package/client/csrTypes.ts +15 -1
  8. package/client/frameConfig.ts +5 -2
  9. package/client/index.ts +249 -26
  10. package/client/locale.ts +1 -0
  11. package/client/makePageProto.tsx +33 -82
  12. package/client/nativeThemeColor.ts +51 -0
  13. package/client/route/RouteDefinition.ts +24 -7
  14. package/client/route/RouteGuards.ts +2 -1
  15. package/client/route/RouteHead.ts +11 -2
  16. package/client/route/routeArgs.ts +7 -0
  17. package/client/router.ts +25 -6
  18. package/client/rscNavigation.ts +3 -3
  19. package/client/rscRoutePatch.ts +42 -0
  20. package/client/viewportMeta.ts +34 -4
  21. package/common/CodeTranscript.ts +1 -1
  22. package/common/PipelinePlanSchema.ts +2 -2
  23. package/common/akanGraph.ts +1 -1
  24. package/common/err.ts +122 -0
  25. package/common/facetBarrel.ts +38 -0
  26. package/common/failureCode.ts +18 -0
  27. package/common/index.ts +9 -0
  28. package/common/isGuardRefusal.ts +14 -0
  29. package/common/mcpExposure.ts +17 -4
  30. package/common/mcpFailure.ts +9 -0
  31. package/common/pipelinePlan.ts +1 -1
  32. package/common/restartSchedule.ts +55 -0
  33. package/common/routeConvention.ts +3 -1
  34. package/common/types.ts +18 -1
  35. package/constant/constantRegistry.ts +4 -8
  36. package/constant/crystalize.ts +1 -2
  37. package/constant/getDefault.ts +1 -1
  38. package/constant/immerify.ts +1 -1
  39. package/constant/index.ts +78 -21
  40. package/constant/purify.ts +4 -9
  41. package/constant/serialize.ts +4 -2
  42. package/constant/types.ts +1 -0
  43. package/constant/via.ts +1 -2
  44. package/dictionary/agent.dictionary.ts +4 -0
  45. package/dictionary/base.dictionary.ts +1 -0
  46. package/dictionary/locale.ts +1 -1
  47. package/dictionary/trans.ts +14 -97
  48. package/document/databaseRegistry.ts +2 -1
  49. package/document/documentSchema.ts +1 -0
  50. package/document/filterMeta.ts +4 -1
  51. package/document/into.ts +2 -1
  52. package/document/loaderInfo.ts +2 -1
  53. package/document/noDocumentError.ts +4 -1
  54. package/document/queryEvaluator.ts +1 -1
  55. package/document/types.ts +1 -1
  56. package/fetch/client/fetchClient.ts +87 -270
  57. package/fetch/client/fetchClientTypes.ts +49 -0
  58. package/fetch/client/fetchHandle.ts +11 -1
  59. package/fetch/client/httpClient.ts +14 -2
  60. package/fetch/client/inflightQueries.ts +17 -0
  61. package/fetch/client/remoteError.ts +4 -20
  62. package/fetch/client/requestScope.ts +32 -0
  63. package/fetch/client/signalCatalog.ts +131 -0
  64. package/fetch/client/wsClient.ts +11 -0
  65. package/fetch/index.ts +1 -0
  66. package/fetch/staleReads.ts +27 -0
  67. package/fetch/streamedRead.ts +23 -0
  68. package/package.json +1 -1
  69. package/server/agentHooks.ts +16 -0
  70. package/server/akanApp.ts +107 -1272
  71. package/server/akanOption.ts +17 -4
  72. package/server/akanServer.ts +167 -675
  73. package/server/artifact/builderRpc.ts +33 -10
  74. package/server/artifact/ipcTypes.ts +9 -3
  75. package/server/artifact/routeSeedIndexStore.ts +4 -2
  76. package/server/assetHeaders.ts +6 -0
  77. package/server/console.ts +6 -4
  78. package/server/decorators.ts +2 -2
  79. package/server/devtools/README.md +4 -3
  80. package/server/devtools/devtoolsRouter.ts +9 -5
  81. package/server/devtools/studio/studioRoute.ts +18 -11
  82. package/server/di/diLifecycle.ts +24 -35
  83. package/server/di/predefinedAdaptor.ts +24 -1
  84. package/server/di/resolveHierarchy.ts +19 -6
  85. package/server/di/utils.ts +7 -3
  86. package/server/ed25519Key.ts +31 -15
  87. package/server/flightRowReader.ts +95 -18
  88. package/server/gateway/childSupervisor.ts +326 -0
  89. package/server/gateway/devHostChannel.ts +47 -0
  90. package/server/gateway/gatewayChildren.ts +135 -0
  91. package/server/gateway/gatewayConfig.ts +182 -0
  92. package/server/gateway/gatewayHttpProxy.ts +231 -0
  93. package/server/gateway/gatewayLogging.ts +111 -0
  94. package/server/gateway/gatewayRooms.ts +141 -0
  95. package/server/gateway/gatewayStatus.ts +116 -0
  96. package/server/gateway/gatewayStatusPage.ts +54 -0
  97. package/server/gateway/gatewayWebSocketRelay.ts +149 -0
  98. package/server/head.tsx +4 -19
  99. package/server/hmr/devHmrController.ts +10 -1
  100. package/server/htmlResultCache.ts +234 -0
  101. package/server/imageOptimizer.ts +4 -1
  102. package/server/index.ts +257 -17
  103. package/server/lifecycle/parentChannel.ts +78 -0
  104. package/server/lifecycle/shutdownManager.ts +6 -3
  105. package/server/lifecycle/startGuard.ts +90 -0
  106. package/server/logging/logControlSocket.ts +42 -3
  107. package/server/logging/serverLogging.ts +74 -0
  108. package/server/machine/machineToken.ts +10 -3
  109. package/server/mcp/AgentTools.ts +149 -0
  110. package/server/mcp/AgentToolsAccount.ts +26 -0
  111. package/server/mcp/McpDispatcher.ts +48 -19
  112. package/server/mcp/McpPages.ts +21 -6
  113. package/server/mcp/McpRateLimiter.ts +14 -0
  114. package/server/mcp/McpRouter.ts +52 -23
  115. package/server/mcp/McpUiSession.ts +2 -1
  116. package/server/mcp/index.ts +1 -0
  117. package/server/nativeFile.ts +30 -11
  118. package/server/nativeSecret.ts +12 -3
  119. package/server/oauth/OAuthClientIdMetadata.ts +2 -2
  120. package/server/ops/opsRoute.ts +5 -1
  121. package/server/ops/opsToken.ts +3 -1
  122. package/server/resolver/CascadeRunner.ts +10 -4
  123. package/server/resolver/database.resolver.ts +10 -417
  124. package/server/resolver/databaseModelInstance.ts +200 -0
  125. package/server/resolver/invalidSignal.ts +7 -0
  126. package/server/resolver/livePause.ts +34 -0
  127. package/server/resolver/modelFacade.ts +136 -0
  128. package/server/resolver/modelLoaders.ts +52 -0
  129. package/server/resolver/modelSchema.ts +52 -0
  130. package/server/resolver/signal.resolver.ts +92 -116
  131. package/server/resolver/timedQuery.ts +16 -0
  132. package/server/resolver/websocketOf.ts +23 -0
  133. package/server/routeElementComposer.tsx +131 -9
  134. package/server/routeState.ts +5 -1
  135. package/server/routeTreeBuilder.ts +22 -9
  136. package/server/routing/apiRouter.ts +44 -25
  137. package/server/routing/builtinRoutes.ts +194 -0
  138. package/server/routing/localRooms.ts +34 -0
  139. package/server/routing/roomReplay.ts +2 -2
  140. package/server/routing/serverLimits.ts +4 -1
  141. package/server/routing/serverListener.ts +194 -0
  142. package/server/rscClient.tsx +210 -227
  143. package/server/rscClientCache.ts +165 -0
  144. package/server/rscClientChunks.ts +209 -0
  145. package/server/rscClientFetch.ts +15 -3
  146. package/server/rscClientPatch.ts +78 -15
  147. package/server/rscDocumentHead.tsx +170 -0
  148. package/server/rscFlightRenderer.ts +83 -0
  149. package/server/rscFlightStream.ts +257 -0
  150. package/server/rscHeadPatch.ts +17 -56
  151. package/server/rscHostReloads.ts +238 -0
  152. package/server/rscHostRenderStream.ts +297 -0
  153. package/server/rscHostRequests.ts +158 -0
  154. package/server/rscHttp.ts +18 -6
  155. package/server/rscInlineStream.ts +34 -0
  156. package/server/rscNavigationState.ts +21 -1
  157. package/server/rscPagePrompts.ts +11 -5
  158. package/server/rscParkedRedirect.ts +23 -0
  159. package/server/rscPatchPlanner.ts +220 -0
  160. package/server/rscPrefetchCache.ts +68 -32
  161. package/server/rscRenderControl.ts +33 -0
  162. package/server/rscRenderFallbacks.ts +297 -0
  163. package/server/rscRenderHandler.ts +439 -0
  164. package/server/rscRenderStats.ts +49 -0
  165. package/server/rscResponse.ts +78 -0
  166. package/server/rscResultCaches.ts +74 -0
  167. package/server/rscRouteDocument.tsx +299 -0
  168. package/server/rscSegmentOutlet.tsx +24 -5
  169. package/server/rscSegmentOutletReference.ts +14 -12
  170. package/server/rscWorker.tsx +86 -1392
  171. package/server/rscWorkerCache.ts +56 -0
  172. package/server/rscWorkerHost.ts +145 -811
  173. package/server/rscWorkerProcess.ts +155 -0
  174. package/server/rscWorkerRecycler.ts +128 -0
  175. package/server/serverConfig.ts +128 -0
  176. package/server/serverMetrics.ts +52 -0
  177. package/server/sitemap.ts +1 -0
  178. package/server/ssrFromRscRenderer.tsx +20 -20
  179. package/server/ssrTypes.ts +9 -0
  180. package/server/webArtifact.ts +86 -0
  181. package/server/webAssetRoutes.ts +84 -0
  182. package/server/webCsrSurface.ts +172 -0
  183. package/server/webDocumentRoute.ts +180 -0
  184. package/server/webRouteContext.ts +232 -0
  185. package/server/webRouter.ts +126 -1242
  186. package/server/webRscRoute.ts +155 -0
  187. package/server/webSiteFiles.ts +139 -0
  188. package/server/wellKnownRoutes.ts +73 -0
  189. package/service/agent.service.ts +59 -5
  190. package/service/agentAccounts.ts +19 -0
  191. package/service/agentLoop/agentLoop.ts +387 -0
  192. package/service/agentLoop/agentLoopTypes.ts +112 -0
  193. package/service/agentLoop/deltaStream.ts +40 -0
  194. package/service/agentLoop/loopCompaction.ts +135 -0
  195. package/service/agentLoop/loopRequest.ts +62 -0
  196. package/service/agentLoop/loopToolOutput.ts +54 -0
  197. package/service/agentLoop/loopToolkits.ts +107 -0
  198. package/service/agentLoop/loopTranscript.ts +102 -0
  199. package/{signal → service}/agentMeter.ts +83 -15
  200. package/{signal → service}/agentRelayPolicy.ts +30 -7
  201. package/service/documentStoreError.ts +16 -0
  202. package/service/index.ts +7 -0
  203. package/service/injectError.ts +5 -0
  204. package/service/injectInfo.ts +30 -18
  205. package/service/insightQueryError.ts +19 -0
  206. package/service/ipcTypes.ts +3 -1
  207. package/service/liveSyncHub.ts +5 -2
  208. package/service/predefinedAdaptor/agentTools.adaptor.ts +34 -0
  209. package/service/predefinedAdaptor/anthropicLlm.ts +52 -21
  210. package/service/predefinedAdaptor/cache.adaptor.ts +3 -2
  211. package/service/predefinedAdaptor/compress.adaptor.ts +7 -3
  212. package/service/predefinedAdaptor/database.adaptor.ts +3 -1
  213. package/service/predefinedAdaptor/documentTransfer.ts +2 -1
  214. package/service/predefinedAdaptor/index.ts +2 -0
  215. package/service/predefinedAdaptor/insightQuery.ts +35 -11
  216. package/service/predefinedAdaptor/llm.adaptor.ts +22 -2
  217. package/service/predefinedAdaptor/llmSpend.ts +80 -0
  218. package/service/predefinedAdaptor/openaiDialect.ts +52 -17
  219. package/service/predefinedAdaptor/openaiLlm.ts +17 -9
  220. package/service/predefinedAdaptor/role.adaptor.ts +2 -0
  221. package/service/predefinedAdaptor/searchIndex.ts +5 -1
  222. package/service/predefinedAdaptor/solidPubsub.adaptor.ts +35 -2
  223. package/service/predefinedAdaptor/solidQueue.adaptor.ts +2 -2
  224. package/service/predefinedAdaptor/solidSqlite.ts +3 -2
  225. package/service/predefinedAdaptor/sql/DocumentHydrator.ts +95 -0
  226. package/service/predefinedAdaptor/sql/DocumentRowCodec.ts +192 -0
  227. package/service/predefinedAdaptor/sql/DocumentWriter.ts +292 -0
  228. package/service/predefinedAdaptor/sql/PostgresInsightSession.ts +15 -5
  229. package/service/predefinedAdaptor/sql/QueryCompiler.ts +29 -13
  230. package/service/predefinedAdaptor/sql/QueryScope.ts +70 -0
  231. package/service/predefinedAdaptor/sql/QueryWriter.ts +200 -0
  232. package/service/predefinedAdaptor/sql/RawDocumentTable.ts +20 -8
  233. package/service/predefinedAdaptor/sql/SqlDocumentStore.ts +83 -1124
  234. package/service/predefinedAdaptor/sql/SqlTableSchema.ts +319 -0
  235. package/service/predefinedAdaptor/sql/SqliteInsightSession.ts +2 -1
  236. package/service/predefinedAdaptor/sql/StoredRows.ts +95 -0
  237. package/service/predefinedAdaptor/sql/UpdateCompiler.ts +6 -2
  238. package/service/predefinedAdaptor/sql/driver/bunSqlite.ts +3 -3
  239. package/service/predefinedAdaptor/sql/driver/postgres.ts +1 -1
  240. package/service/predefinedAdaptor/sql/fieldValues.ts +74 -0
  241. package/service/predefinedAdaptor/sql/search/fts5.ts +4 -1
  242. package/service/predefinedAdaptor/sql/search/postgres.ts +6 -2
  243. package/service/predefinedAdaptor/sql/values.ts +8 -4
  244. package/service/predefinedAdaptor/sseData.ts +14 -0
  245. package/service/predefinedAdaptor/storage.adaptor.ts +9 -4
  246. package/service/predefinedAdaptor/websocket.adaptor.ts +199 -43
  247. package/service/serve.ts +3 -2
  248. package/service/serviceModule.ts +2 -2
  249. package/service/serviceRegistry.ts +1 -0
  250. package/signal/SignalFailure.ts +30 -1
  251. package/signal/agent.signal.ts +30 -9
  252. package/signal/agentTurnStream.ts +12 -8
  253. package/signal/byIdRead.ts +18 -0
  254. package/signal/carriedClientIps.ts +1 -0
  255. package/signal/endpointErrorContract.ts +20 -2
  256. package/signal/endpointInfo.ts +6 -5
  257. package/signal/exception.ts +1 -0
  258. package/signal/index.ts +314 -30
  259. package/signal/internalInfo.ts +6 -4
  260. package/signal/mcp/McpDocument.ts +8 -1
  261. package/signal/mcp/Msg.ts +23 -10
  262. package/signal/mcp/index.ts +1 -0
  263. package/signal/mcp/promptError.ts +9 -0
  264. package/signal/middleware.ts +12 -3
  265. package/signal/openapi/openapi.ts +10 -1
  266. package/signal/resolveFieldContext.ts +34 -0
  267. package/signal/serializer/fetch.serializer.ts +23 -15
  268. package/signal/signalContext.ts +24 -57
  269. package/signal/signalContractError.ts +10 -0
  270. package/signal/signalDeclarationError.ts +13 -0
  271. package/signal/signalRegistry.ts +3 -1
  272. package/signal/slice.ts +24 -20
  273. package/signal/sliceInfo.ts +12 -9
  274. package/signal/trace.ts +3 -0
  275. package/signal/types.ts +35 -6
  276. package/store/action.ts +44 -1086
  277. package/store/actionErrorKey.ts +9 -0
  278. package/store/actionOption.ts +22 -0
  279. package/store/baseSt.ts +1 -0
  280. package/store/draftFlush.ts +5 -0
  281. package/store/draftStore.ts +2 -0
  282. package/store/formDrafts.ts +115 -0
  283. package/store/formFieldSetters.ts +229 -0
  284. package/store/index.ts +125 -17
  285. package/store/modelActionContext.ts +65 -0
  286. package/store/modelListPatch.ts +53 -0
  287. package/store/modelOpenActions.ts +158 -0
  288. package/store/modelWriteActions.ts +240 -0
  289. package/store/modelWriteGuard.ts +82 -0
  290. package/store/openSeq.ts +34 -0
  291. package/store/rootStore.ts +2 -0
  292. package/store/sliceListActions.ts +370 -0
  293. package/store/sliceLiveActions.ts +130 -0
  294. package/store/stateBuilder.ts +2 -0
  295. package/store/storeInstance.ts +9 -10
  296. package/store/uploadPoll.ts +52 -0
  297. package/store/withSelector.ts +6 -4
  298. package/types/base/base.d.ts +2 -1
  299. package/types/client/clientRuntime.d.ts +1 -0
  300. package/types/client/cn.d.ts +2 -2
  301. package/types/client/csrTypes.d.ts +15 -1
  302. package/types/client/frameConfig.d.ts +1 -0
  303. package/types/client/index.d.ts +25 -26
  304. package/types/client/locale.d.ts +1 -0
  305. package/types/client/makePageProto.d.ts +28 -26091
  306. package/types/client/nativeThemeColor.d.ts +6 -0
  307. package/types/client/route/RouteDefinition.d.ts +2 -2
  308. package/types/client/route/RouteHead.d.ts +5 -1
  309. package/types/client/route/routeArgs.d.ts +6 -0
  310. package/types/client/router.d.ts +6 -3
  311. package/types/client/rscNavigation.d.ts +3 -2
  312. package/types/client/rscRoutePatch.d.ts +22 -0
  313. package/types/client/viewportMeta.d.ts +3 -1
  314. package/types/common/CodeTranscript.d.ts +1 -1
  315. package/types/common/akanGraph.d.ts +1 -1
  316. package/types/common/err.d.ts +48 -0
  317. package/types/common/facetBarrel.d.ts +4 -0
  318. package/types/common/failureCode.d.ts +6 -0
  319. package/types/common/index.d.ts +8 -2
  320. package/types/common/isGuardRefusal.d.ts +3 -0
  321. package/types/common/mcpExposure.d.ts +9 -2
  322. package/types/common/mcpFailure.d.ts +6 -0
  323. package/types/common/restartSchedule.d.ts +16 -0
  324. package/types/common/routeConvention.d.ts +2 -0
  325. package/types/common/types.d.ts +18 -1
  326. package/types/constant/constantRegistry.d.ts +3 -1
  327. package/types/constant/crystalize.d.ts +1 -1
  328. package/types/constant/getDefault.d.ts +1 -1
  329. package/types/constant/immerify.d.ts +1 -1
  330. package/types/constant/index.d.ts +21 -21
  331. package/types/constant/purify.d.ts +2 -1
  332. package/types/constant/serialize.d.ts +1 -1
  333. package/types/constant/types.d.ts +1 -0
  334. package/types/dictionary/agent.dictionary.d.ts +1 -1
  335. package/types/dictionary/base.dictionary.d.ts +1 -1
  336. package/types/dictionary/dictionary.d.ts +9 -9
  337. package/types/dictionary/locale.d.ts +1 -1
  338. package/types/dictionary/trans.d.ts +3 -26
  339. package/types/document/databaseRegistry.d.ts +2 -1
  340. package/types/document/documentSchema.d.ts +1 -0
  341. package/types/document/filterMeta.d.ts +4 -1
  342. package/types/document/into.d.ts +1 -1
  343. package/types/document/loaderInfo.d.ts +2 -1
  344. package/types/document/noDocumentError.d.ts +8 -1
  345. package/types/document/queryEvaluator.d.ts +1 -1
  346. package/types/document/types.d.ts +1 -1
  347. package/types/fetch/client/fetchClient.d.ts +6 -36
  348. package/types/fetch/client/fetchClientTypes.d.ts +40 -0
  349. package/types/fetch/client/fetchHandle.d.ts +1 -0
  350. package/types/fetch/client/httpClient.d.ts +2 -0
  351. package/types/fetch/client/inflightQueries.d.ts +2 -0
  352. package/types/fetch/client/remoteError.d.ts +0 -4
  353. package/types/fetch/client/requestScope.d.ts +6 -0
  354. package/types/fetch/client/signalCatalog.d.ts +25 -0
  355. package/types/fetch/client/wsClient.d.ts +1 -0
  356. package/types/fetch/index.d.ts +1 -0
  357. package/types/fetch/staleReads.d.ts +8 -0
  358. package/types/fetch/streamedRead.d.ts +8 -0
  359. package/types/server/agentHooks.d.ts +4 -0
  360. package/types/server/akanApp.d.ts +2 -20
  361. package/types/server/akanOption.d.ts +9 -3
  362. package/types/server/akanServer.d.ts +1 -1
  363. package/types/server/artifact/builderRpc.d.ts +8 -0
  364. package/types/server/artifact/ipcTypes.d.ts +8 -0
  365. package/types/server/assetHeaders.d.ts +1 -0
  366. package/types/server/console.d.ts +4 -3
  367. package/types/server/devtools/devtoolsRouter.d.ts +4 -1
  368. package/types/server/devtools/studio/studioRoute.d.ts +2 -1
  369. package/types/server/di/predefinedAdaptor.d.ts +1 -0
  370. package/types/server/ed25519Key.d.ts +1 -0
  371. package/types/server/flightRowReader.d.ts +3 -1
  372. package/types/server/gateway/childSupervisor.d.ts +33 -0
  373. package/types/server/gateway/devHostChannel.d.ts +14 -0
  374. package/types/server/gateway/gatewayChildren.d.ts +47 -0
  375. package/types/server/gateway/gatewayConfig.d.ts +82 -0
  376. package/types/server/gateway/gatewayHttpProxy.d.ts +22 -0
  377. package/types/server/gateway/gatewayLogging.d.ts +16 -0
  378. package/types/server/gateway/gatewayRooms.d.ts +25 -0
  379. package/types/server/gateway/gatewayStatus.d.ts +62 -0
  380. package/types/server/gateway/gatewayStatusPage.d.ts +9 -0
  381. package/types/server/gateway/gatewayWebSocketRelay.d.ts +17 -0
  382. package/types/server/head.d.ts +2 -2
  383. package/types/server/htmlResultCache.d.ts +51 -0
  384. package/types/server/index.d.ts +17 -17
  385. package/types/server/lifecycle/parentChannel.d.ts +13 -0
  386. package/types/server/lifecycle/startGuard.d.ts +10 -0
  387. package/types/server/logging/rotatingLogWriter.d.ts +1 -1
  388. package/types/server/logging/serverLogging.d.ts +12 -0
  389. package/types/server/mcp/AgentTools.d.ts +31 -0
  390. package/types/server/mcp/AgentToolsAccount.d.ts +7 -0
  391. package/types/server/mcp/McpDispatcher.d.ts +10 -1
  392. package/types/server/mcp/McpPages.d.ts +2 -1
  393. package/types/server/mcp/McpRateLimiter.d.ts +3 -0
  394. package/types/server/mcp/index.d.ts +1 -0
  395. package/types/server/resolver/database.resolver.d.ts +2 -2
  396. package/types/server/resolver/databaseModelInstance.d.ts +4 -0
  397. package/types/server/resolver/invalidSignal.d.ts +2 -0
  398. package/types/server/resolver/livePause.d.ts +5 -0
  399. package/types/server/resolver/modelFacade.d.ts +5 -0
  400. package/types/server/resolver/modelLoaders.d.ts +9 -0
  401. package/types/server/resolver/modelSchema.d.ts +6 -0
  402. package/types/server/resolver/signal.resolver.d.ts +2 -2
  403. package/types/server/resolver/timedQuery.d.ts +8 -0
  404. package/types/server/resolver/websocketOf.d.ts +2 -0
  405. package/types/server/routeElementComposer.d.ts +45 -6
  406. package/types/server/routeState.d.ts +2 -0
  407. package/types/server/routing/builtinRoutes.d.ts +24 -0
  408. package/types/server/routing/localRooms.d.ts +14 -0
  409. package/types/server/routing/roomReplay.d.ts +2 -2
  410. package/types/server/routing/serverListener.d.ts +31 -0
  411. package/types/server/rscClient.d.ts +1 -5
  412. package/types/server/rscClientCache.d.ts +34 -0
  413. package/types/server/rscClientChunks.d.ts +18 -0
  414. package/types/server/rscClientFetch.d.ts +1 -1
  415. package/types/server/rscClientPatch.d.ts +12 -1
  416. package/types/server/rscDocumentHead.d.ts +32 -0
  417. package/types/server/rscFlightRenderer.d.ts +14 -0
  418. package/types/server/rscFlightStream.d.ts +52 -0
  419. package/types/server/rscHeadPatch.d.ts +5 -4
  420. package/types/server/rscHostReloads.d.ts +54 -0
  421. package/types/server/rscHostRenderStream.d.ts +53 -0
  422. package/types/server/rscHostRequests.d.ts +29 -0
  423. package/types/server/rscHttp.d.ts +4 -2
  424. package/types/server/rscInlineStream.d.ts +9 -0
  425. package/types/server/rscNavigationState.d.ts +8 -3
  426. package/types/server/rscParkedRedirect.d.ts +12 -0
  427. package/types/server/rscPatchPlanner.d.ts +49 -0
  428. package/types/server/rscPrefetchCache.d.ts +8 -7
  429. package/types/server/rscRenderControl.d.ts +12 -0
  430. package/types/server/rscRenderFallbacks.d.ts +41 -0
  431. package/types/server/rscRenderHandler.d.ts +29 -0
  432. package/types/server/rscRenderStats.d.ts +32 -0
  433. package/types/server/rscResponse.d.ts +9 -0
  434. package/types/server/rscResultCaches.d.ts +18 -0
  435. package/types/server/rscRouteDocument.d.ts +52 -0
  436. package/types/server/rscSegmentOutlet.d.ts +5 -0
  437. package/types/server/rscSegmentOutletReference.d.ts +2 -1
  438. package/types/server/rscWorker.d.ts +1 -3
  439. package/types/server/rscWorkerCache.d.ts +33 -1
  440. package/types/server/rscWorkerHost.d.ts +9 -76
  441. package/types/server/rscWorkerProcess.d.ts +31 -0
  442. package/types/server/rscWorkerRecycler.d.ts +22 -0
  443. package/types/server/serverConfig.d.ts +30 -0
  444. package/types/server/serverMetrics.d.ts +11 -0
  445. package/types/server/sitemap.d.ts +1 -0
  446. package/types/server/ssrFromRscRenderer.d.ts +2 -2
  447. package/types/server/ssrTypes.d.ts +8 -0
  448. package/types/server/webArtifact.d.ts +7 -0
  449. package/types/server/webAssetRoutes.d.ts +11 -0
  450. package/types/server/webCsrSurface.d.ts +18 -0
  451. package/types/server/webDocumentRoute.d.ts +19 -0
  452. package/types/server/webRouteContext.d.ts +45 -0
  453. package/types/server/webRouter.d.ts +4 -35
  454. package/types/server/webRscRoute.d.ts +24 -0
  455. package/types/server/webSiteFiles.d.ts +12 -0
  456. package/types/server/wellKnownRoutes.d.ts +5 -0
  457. package/types/service/agent.service.d.ts +13 -4
  458. package/types/service/agentAccounts.d.ts +8 -0
  459. package/types/service/agentLoop/agentLoop.d.ts +31 -0
  460. package/types/service/agentLoop/agentLoopTypes.d.ts +126 -0
  461. package/types/service/agentLoop/deltaStream.d.ts +3 -0
  462. package/types/service/agentLoop/loopCompaction.d.ts +11 -0
  463. package/types/service/agentLoop/loopRequest.d.ts +6 -0
  464. package/types/service/agentLoop/loopToolOutput.d.ts +7 -0
  465. package/types/service/agentLoop/loopToolkits.d.ts +14 -0
  466. package/types/service/agentLoop/loopTranscript.d.ts +12 -0
  467. package/types/service/agentMeter.d.ts +50 -0
  468. package/types/service/agentRelayPolicy.d.ts +45 -0
  469. package/types/service/documentStoreError.d.ts +7 -0
  470. package/types/service/index.d.ts +7 -0
  471. package/types/service/injectError.d.ts +4 -0
  472. package/types/service/injectInfo.d.ts +2 -1
  473. package/types/service/insightQueryError.d.ts +9 -0
  474. package/types/service/ipcTypes.d.ts +6 -0
  475. package/types/service/predefinedAdaptor/agentTools.adaptor.d.ts +31 -0
  476. package/types/service/predefinedAdaptor/anthropicLlm.d.ts +2 -2
  477. package/types/service/predefinedAdaptor/index.d.ts +2 -0
  478. package/types/service/predefinedAdaptor/llm.adaptor.d.ts +18 -2
  479. package/types/service/predefinedAdaptor/llmSpend.d.ts +22 -0
  480. package/types/service/predefinedAdaptor/openaiDialect.d.ts +2 -1
  481. package/types/service/predefinedAdaptor/openaiLlm.d.ts +1 -1
  482. package/types/service/predefinedAdaptor/role.adaptor.d.ts +2 -0
  483. package/types/service/predefinedAdaptor/solidPubsub.adaptor.d.ts +3 -0
  484. package/types/service/predefinedAdaptor/solidSqlite.d.ts +1 -1
  485. package/types/service/predefinedAdaptor/sql/DocumentHydrator.d.ts +11 -0
  486. package/types/service/predefinedAdaptor/sql/DocumentRowCodec.d.ts +26 -0
  487. package/types/service/predefinedAdaptor/sql/DocumentWriter.d.ts +24 -0
  488. package/types/service/predefinedAdaptor/sql/QueryScope.d.ts +16 -0
  489. package/types/service/predefinedAdaptor/sql/QueryWriter.d.ts +20 -0
  490. package/types/service/predefinedAdaptor/sql/SqlDocumentStore.d.ts +1 -32
  491. package/types/service/predefinedAdaptor/sql/SqlTableSchema.d.ts +20 -0
  492. package/types/service/predefinedAdaptor/sql/StoredRows.d.ts +27 -0
  493. package/types/service/predefinedAdaptor/sql/driver/bunSqlite.d.ts +1 -14
  494. package/types/service/predefinedAdaptor/sql/driver/postgres.d.ts +0 -8
  495. package/types/service/predefinedAdaptor/sql/fieldValues.d.ts +5 -0
  496. package/types/service/predefinedAdaptor/sseData.d.ts +5 -0
  497. package/types/service/predefinedAdaptor/websocket.adaptor.d.ts +14 -5
  498. package/types/service/serviceModule.d.ts +1 -1
  499. package/types/service/serviceRegistry.d.ts +1 -0
  500. package/types/signal/SignalFailure.d.ts +2 -0
  501. package/types/signal/agentTurnStream.d.ts +2 -1
  502. package/types/signal/byIdRead.d.ts +7 -0
  503. package/types/signal/carriedClientIps.d.ts +4 -0
  504. package/types/signal/endpointErrorContract.d.ts +3 -0
  505. package/types/signal/exception.d.ts +1 -0
  506. package/types/signal/index.d.ts +32 -30
  507. package/types/signal/mcp/McpDocument.d.ts +2 -0
  508. package/types/signal/mcp/index.d.ts +1 -0
  509. package/types/signal/mcp/promptError.d.ts +5 -0
  510. package/types/signal/resolveFieldContext.d.ts +15 -0
  511. package/types/signal/serializer/fetch.serializer.d.ts +3 -1
  512. package/types/signal/signalContext.d.ts +1 -13
  513. package/types/signal/signalContractError.d.ts +4 -0
  514. package/types/signal/signalDeclarationError.d.ts +4 -0
  515. package/types/signal/slice.d.ts +15 -13
  516. package/types/signal/trace.d.ts +3 -0
  517. package/types/signal/types.d.ts +33 -6
  518. package/types/store/action.d.ts +8 -27
  519. package/types/store/actionErrorKey.d.ts +1 -0
  520. package/types/store/actionOption.d.ts +24 -0
  521. package/types/store/baseSt.d.ts +2 -295
  522. package/types/store/draftFlush.d.ts +4 -0
  523. package/types/store/formDrafts.d.ts +21 -0
  524. package/types/store/formFieldSetters.d.ts +80 -0
  525. package/types/store/index.d.ts +17 -16
  526. package/types/store/modelActionContext.d.ts +189 -0
  527. package/types/store/modelListPatch.d.ts +34 -0
  528. package/types/store/modelOpenActions.d.ts +12 -0
  529. package/types/store/modelWriteActions.d.ts +16 -0
  530. package/types/store/modelWriteGuard.d.ts +42 -0
  531. package/types/store/openSeq.d.ts +17 -0
  532. package/types/store/rootStore.d.ts +6 -0
  533. package/types/store/sliceListActions.d.ts +295 -0
  534. package/types/store/sliceLiveActions.d.ts +6 -0
  535. package/types/store/stateBuilder.d.ts +2 -0
  536. package/types/store/uploadPoll.d.ts +16 -0
  537. package/types/store/withSelector.d.ts +1 -1
  538. package/types/ui/Agent/Chat.d.ts +5 -2
  539. package/types/ui/Agent/ChatHeader.d.ts +13 -0
  540. package/types/ui/Agent/ChatPendingCards.d.ts +23 -0
  541. package/types/ui/Field/Choice.d.ts +2 -1
  542. package/types/ui/Field/index.d.ts +1 -1
  543. package/types/ui/Link/inputModality.d.ts +5 -0
  544. package/types/ui/Link/viewportPrefetch.d.ts +4 -0
  545. package/types/ui/Load/Edit_Client.d.ts +2 -0
  546. package/types/ui/Load/Pagination.d.ts +4 -1
  547. package/types/ui/Load/Stream.d.ts +7 -1
  548. package/types/ui/Load/StreamBoundary.d.ts +20 -0
  549. package/types/ui/Load/Units.d.ts +2 -0
  550. package/types/ui/Load/View.d.ts +2 -0
  551. package/types/ui/Reference/origin.d.ts +1 -0
  552. package/types/ui/index.d.ts +1 -1
  553. package/types/ui/overlayLayer.d.ts +6 -1
  554. package/types/ui/recipe/badgeRecipe.d.ts +3 -3
  555. package/types/ui/recipe/buttonRecipe.d.ts +3 -3
  556. package/types/ui/recipe/inputRecipe.d.ts +1 -1
  557. package/types/vendor/@akanjs/native/packages/cli/src/lib/project.d.ts +4 -0
  558. package/types/vendor/@akanjs/native/packages/desktop/src/relaunch.d.ts +1 -0
  559. package/types/vendor/@akanjs/native/plugins/appearance/src/index.d.ts +9 -0
  560. package/types/vendor/@akanjs/native/plugins/external-view/src/index.d.ts +18 -11
  561. package/types/vendor/use-agentic/AgentClientTools.d.ts +19 -0
  562. package/types/vendor/use-agentic/failureCode.d.ts +4 -0
  563. package/types/vendor/use-agentic/index.d.ts +1 -0
  564. package/types/vendor/use-agentic/types.d.ts +11 -0
  565. package/types/webkit/CsrGuards.d.ts +2 -0
  566. package/types/webkit/RouteLevelBoundary.d.ts +17 -0
  567. package/types/webkit/nativeCore.d.ts +1 -0
  568. package/types/webkit/nativePurchase.d.ts +2 -1
  569. package/types/webkit/useCsrKeyboard.d.ts +19 -0
  570. package/types/webkit/useCsrLocationState.d.ts +21 -0
  571. package/types/webkit/useCsrNavigation.d.ts +25 -0
  572. package/types/webkit/useCsrRefs.d.ts +33 -0
  573. package/types/webkit/useCsrRenderTrace.d.ts +13 -0
  574. package/types/webkit/useCsrStackLifecycle.d.ts +12 -0
  575. package/types/webkit/useCsrTransitions.d.ts +2 -0
  576. package/types/webkit/useFrameRuntime.d.ts +1 -0
  577. package/types/webkit/useGeoLocation.d.ts +1 -1
  578. package/types/webkit/useHistory.d.ts +2 -3
  579. package/types/webkit/usePurchase.d.ts +1 -1
  580. package/types/webkit/useResolvedFrame.d.ts +38 -0
  581. package/types/webkit/useSyncNavigation.d.ts +22 -0
  582. package/types/webkit/useTransitionStore.d.ts +1 -0
  583. package/ui/Agent/Chat.tsx +392 -235
  584. package/ui/Agent/ChatHeader.tsx +59 -0
  585. package/ui/Agent/ChatPendingCards.tsx +49 -0
  586. package/ui/Agent/fetchRunner.ts +8 -1
  587. package/ui/BottomSheet.tsx +1 -1
  588. package/ui/Button.tsx +1 -0
  589. package/ui/Data/Item.tsx +2 -2
  590. package/ui/Data/ListContainer.tsx +348 -181
  591. package/ui/Data/useViewModal.ts +10 -4
  592. package/ui/Dialog/LegacyModal.tsx +1 -1
  593. package/ui/Dialog/Modal.tsx +1 -1
  594. package/ui/Field/Choice.tsx +3 -1
  595. package/ui/Link/inputModality.ts +21 -0
  596. package/ui/Link/prefetchIntent.ts +7 -25
  597. package/ui/Link/viewportPrefetch.ts +30 -0
  598. package/ui/Load/Edit_Client.tsx +7 -1
  599. package/ui/Load/Pagination.tsx +10 -2
  600. package/ui/Load/Stream.tsx +24 -4
  601. package/ui/Load/StreamBoundary.tsx +65 -0
  602. package/ui/Load/Units.tsx +3 -0
  603. package/ui/Load/View.tsx +5 -1
  604. package/ui/Model/EditModal.tsx +2 -1
  605. package/ui/Popconfirm.tsx +1 -1
  606. package/ui/Reference/origin.ts +1 -0
  607. package/ui/Select.tsx +43 -51
  608. package/ui/Signal/RestApi.tsx +3 -2
  609. package/ui/System/Client.tsx +32 -8
  610. package/ui/index.ts +4 -0
  611. package/ui/overlayLayer.ts +22 -1
  612. package/vendor/@akanjs/native/CHANGELOG.md +7 -1
  613. package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeActivity.kt +27 -12
  614. package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativePlugin.kt +4 -0
  615. package/vendor/@akanjs/native/native/desktop/src/external.rs +213 -111
  616. package/vendor/@akanjs/native/native/desktop/src/lib.rs +12 -4
  617. package/vendor/@akanjs/native/native/desktop/src/linux/external.rs +509 -0
  618. package/vendor/@akanjs/native/native/desktop/src/linux/mod.rs +1 -0
  619. package/vendor/@akanjs/native/native/ios/Sources/AkanNativeViewController.swift +6 -1
  620. package/vendor/@akanjs/native/packages/cli/src/lib/native-plugins.ts +5 -3
  621. package/vendor/@akanjs/native/packages/cli/src/lib/project.ts +25 -1
  622. package/vendor/@akanjs/native/packages/desktop/src/deeplinks.ts +2 -2
  623. package/vendor/@akanjs/native/packages/desktop/src/host.ts +2 -2
  624. package/vendor/@akanjs/native/packages/desktop/src/relaunch.ts +8 -3
  625. package/vendor/@akanjs/native/plugins/app/src/desktop.ts +2 -2
  626. package/vendor/@akanjs/native/plugins/appearance/android/AppearancePlugin.kt +13 -0
  627. package/vendor/@akanjs/native/plugins/appearance/ios/AppearancePlugin.swift +27 -0
  628. package/vendor/@akanjs/native/plugins/appearance/native-plugin.json +2 -2
  629. package/vendor/@akanjs/native/plugins/appearance/src/index.ts +8 -1
  630. package/vendor/@akanjs/native/plugins/autostart/src/desktop.ts +2 -1
  631. package/vendor/@akanjs/native/plugins/external-view/native-plugin.json +4 -1
  632. package/vendor/@akanjs/native/plugins/external-view/src/index.ts +18 -11
  633. package/vendor/use-agentic/AgentClientTools.ts +33 -0
  634. package/vendor/use-agentic/AgentSession.ts +11 -11
  635. package/vendor/use-agentic/CHANGELOG.md +46 -1
  636. package/vendor/use-agentic/Compaction.ts +2 -1
  637. package/vendor/use-agentic/ToolRunner.ts +6 -3
  638. package/vendor/use-agentic/Transcript.ts +6 -3
  639. package/vendor/use-agentic/WIRE.md +29 -7
  640. package/vendor/use-agentic/failureCode.ts +44 -0
  641. package/vendor/use-agentic/httpRunner.ts +15 -4
  642. package/vendor/use-agentic/index.ts +1 -0
  643. package/vendor/use-agentic/types.ts +11 -0
  644. package/webkit/CsrGuards.ts +7 -2
  645. package/webkit/McpAppAgent.ts +8 -3
  646. package/webkit/McpAppFetchBridge.ts +11 -5
  647. package/webkit/RouteLevelBoundary.tsx +37 -0
  648. package/webkit/nativeCore.ts +1 -0
  649. package/webkit/nativePurchase.ts +6 -3
  650. package/webkit/useCamera.tsx +22 -21
  651. package/webkit/useCsrKeyboard.ts +155 -0
  652. package/webkit/useCsrLocationState.ts +58 -0
  653. package/webkit/useCsrNavigation.ts +302 -0
  654. package/webkit/useCsrRefs.ts +52 -0
  655. package/webkit/useCsrRenderTrace.ts +68 -0
  656. package/webkit/useCsrStackLifecycle.ts +120 -0
  657. package/webkit/useCsrTransitions.ts +552 -0
  658. package/webkit/useCsrValues.ts +69 -1234
  659. package/webkit/useGeoLocation.tsx +4 -1
  660. package/webkit/useHistory.ts +2 -2
  661. package/webkit/useLocation.ts +3 -2
  662. package/webkit/usePurchase.tsx +4 -2
  663. package/webkit/useResolvedFrame.ts +116 -0
  664. package/webkit/useSyncNavigation.ts +109 -0
  665. package/webkit/useTransitionStore.ts +13 -0
  666. package/types/signal/agentMeter.d.ts +0 -27
  667. package/types/signal/agentRelayPolicy.d.ts +0 -25
@@ -3,6 +3,7 @@
3
3
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
4
  import { homedir } from "node:os";
5
5
  import { dirname, join } from "node:path";
6
+ import { appLauncher } from "./relaunch.ts";
6
7
 
7
8
  type Env = Record<string, string | undefined>;
8
9
  type Runner = (argv: string[]) => Promise<{ code: number; stdout: string }>;
@@ -158,8 +159,7 @@ export async function registerDeepLinks(
158
159
  const platform = options.platform ?? process.platform;
159
160
  if (!schemes.length || (platform !== "win32" && platform !== "linux")) return;
160
161
  const env = options.env ?? process.env;
161
-
162
- const exe = options.exe ?? (env.APPIMAGE || process.execPath);
162
+ const exe = options.exe ?? appLauncher(env);
163
163
  const runner = options.run ?? run;
164
164
  if (platform === "win32") await registerWindows(app, exe, schemes, runner);
165
165
  else await registerLinux(app, exe, schemes, { env, home: options.home ?? homedir(), runner, icon: options.icon });
@@ -14,7 +14,7 @@ import { cstr, FRAME_EVENT, FRAME_HEADER, FRAME_IPC, openNative, resolvePaths }
14
14
  import { createLifecycle } from "./lifecycle.ts";
15
15
  import { appDataDir, appLocalDataDir, reservedDirs, serverDataDir } from "./paths.ts";
16
16
  import { type DesktopPlugin, useShellOpenLimit } from "./plugin.ts";
17
- import { nextRelaunchDelay, relaunchAfterExit } from "./relaunch.ts";
17
+ import { appLauncher, nextRelaunchDelay, relaunchAfterExit } from "./relaunch.ts";
18
18
  import { createSecretStore } from "./secretStore.ts";
19
19
  import {
20
20
  createDesktopServer,
@@ -350,7 +350,7 @@ export function startHost(plugins: DesktopPlugin[]): void {
350
350
  void lifecycle.quit(1);
351
351
  return;
352
352
  }
353
- relaunchAfterExit(process.execPath, [], { delayMs })
353
+ relaunchAfterExit(appLauncher(), [], { delayMs })
354
354
  .then(() => lifecycle.quit(0))
355
355
  .catch((error: unknown) => console.error("[akan-native] cannot relaunch the app", error));
356
356
  };
@@ -3,7 +3,7 @@
3
3
  import { spawn } from "node:child_process";
4
4
  import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
5
5
  import { tmpdir } from "node:os";
6
- import { dirname } from "node:path";
6
+ import { dirname, resolve } from "node:path";
7
7
 
8
8
  export interface RelaunchOptions {
9
9
  /** How long the helper waits after this process exited before it starts the app. */
@@ -48,6 +48,12 @@ export function recoveryCommand(script: string): string | null {
48
48
  return command.length <= 260 ? command : null;
49
49
  }
50
50
 
51
+ export const appLauncher = (env: NodeJS.ProcessEnv = process.env, exe = process.execPath): string =>
52
+ env.APPIMAGE && env.APPDIR && exe.startsWith(`${resolve(env.APPDIR)}/`) ? env.APPIMAGE : exe;
53
+
54
+ const NOT_INHERITED = new Set(["AKAN_NATIVE_QUIT_ON_STDIN", "APPDIR", "APPIMAGE", "ARGV0", "OWD"]);
55
+ const inheritedEnv = () => Object.fromEntries(Object.entries(process.env).filter(([key]) => !NOT_INHERITED.has(key)));
56
+
51
57
  let started: Promise<void> | null = null;
52
58
 
53
59
  /**
@@ -82,8 +88,7 @@ function startHelper(
82
88
  recover: RelaunchOptions["recover"],
83
89
  start: boolean,
84
90
  ): Promise<void> {
85
-
86
- const { AKAN_NATIVE_QUIT_ON_STDIN: _cli, ...inherited } = process.env;
91
+ const inherited = inheritedEnv();
87
92
  const delay = (delayMs / 1000).toFixed(3);
88
93
  if (process.platform !== "win32") {
89
94
  const done: [string, string][] = [];
@@ -8,7 +8,7 @@ import {
8
8
  linkClaimed,
9
9
  type QuitReason,
10
10
  } from "../../../packages/desktop/src/plugin.ts";
11
- import { relaunchAfterExit } from "../../../packages/desktop/src/relaunch.ts";
11
+ import { appLauncher, relaunchAfterExit } from "../../../packages/desktop/src/relaunch.ts";
12
12
  import type { AppApi, AppEvents } from "./index.ts";
13
13
 
14
14
  const quitVeto = createPageVeto<{ reason: QuitReason }>();
@@ -47,7 +47,7 @@ export default defineDesktopPlugin<AppApi, AppEvents>({
47
47
  setTimeout(() => ctx.quit(0), 50);
48
48
  },
49
49
  relaunch: async (_args, ctx) => {
50
- await relaunchAfterExit(process.execPath);
50
+ await relaunchAfterExit(appLauncher());
51
51
  setTimeout(() => ctx.quit(0), 50);
52
52
  },
53
53
  answerBeforeQuit: (args, ctx) => quitVeto.answer(args, ctx.window),
@@ -3,6 +3,7 @@ package com.akanjs.plugins.appearance
3
3
  import android.app.UiModeManager
4
4
  import android.content.Context
5
5
  import android.content.res.Configuration
6
+ import android.graphics.Color
6
7
  import android.os.Build
7
8
  import android.os.Handler
8
9
  import android.os.Looper
@@ -26,6 +27,7 @@ import com.akanjs.runtime.AkanNativeVoidReply
26
27
  * - mode: the fixed setting, or the configuration's night bit when following the system.
27
28
  * - change: onConfigurationChanged, plus a check shortly after set(), since a setting that keeps
28
29
  * the drawn scheme (system dark, set dark) changes no configuration. Duplicates are filtered.
30
+ * - setThemeColor: the shell's status bar icons, until the page's document ends.
29
31
  * - Below API 31 there is no per-app night mode: the setting goes to AkanNativeCompat.storeNightMode, the
30
32
  * shell applies it as an override configuration when the activity starts, and set() recreates the
31
33
  * activity when the drawn scheme changes, so the page reloads there.
@@ -77,6 +79,16 @@ class AppearancePlugin(private val context: AkanNativePluginContext) : Appearanc
77
79
  if (next != drawn) main.post { activity.recreate() }
78
80
  }
79
81
 
82
+ override fun setThemeColor(args: AppearanceSetThemeColorArgs, reply: AkanNativeVoidReply) {
83
+ val hex = args.color
84
+ if (hex != null && !HEX.matches(hex)) return reply.reject(AkanNativeErrorCode.INVALID_ARGS, "color must be #rrggbb (got $hex)")
85
+ context.setThemeColor(hex?.let(Color::parseColor))
86
+ reply.resolve()
87
+ }
88
+
89
+ /** The next page starts from the background color, whether or not it names a theme color. */
90
+ override fun documentEnded(document: String) = context.setThemeColor(null)
91
+
80
92
  private fun isNight(config: Configuration) = (config.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
81
93
 
82
94
  private object Api31 {
@@ -129,5 +141,6 @@ class AppearancePlugin(private val context: AkanNativePluginContext) : Appearanc
129
141
  private companion object {
130
142
  const val KEY = "setting"
131
143
  const val SETTLE_MS = 500L
144
+ val HEX = Regex("#[0-9a-fA-F]{6}")
132
145
  }
133
146
  }
@@ -10,6 +10,7 @@ import UIKit
10
10
  /// - change: a trait registration on the web view sees both system switches and set(). iOS flips
11
11
  /// the style of a backgrounded app twice to snapshot both appearances, so changes are only
12
12
  /// reported while not in the background, and checked again on the way back to the foreground.
13
+ /// - setThemeColor: the view controller's status bar style, until the page's document ends.
13
14
  /// Arguments arrive decoded and checked by the generated AppearancePluginSpec (PL-10).
14
15
  final class AppearancePlugin: AppearancePluginSpec {
15
16
  static let id = "appearance"
@@ -47,6 +48,32 @@ final class AppearancePlugin: AppearancePluginSpec {
47
48
  report()
48
49
  }
49
50
 
51
+ func setThemeColor(_ args: AppearanceSetThemeColorArgs, _ reply: AkanNativeReply<Void>) {
52
+ var style: UIStatusBarStyle?
53
+ if let color = args.color {
54
+ guard let light = Self.isLight(hex: color) else { return reply.reject(.invalidArgs, "color must be #rrggbb (got \(color))") }
55
+ style = light ? .darkContent : .lightContent
56
+ }
57
+ (context.viewController as? AkanNativeViewController)?.statusBarStyle = style
58
+ reply.resolve()
59
+ }
60
+
61
+ /// The next page starts from the appearance, whether or not it names a theme color.
62
+ func documentEnded(_ document: String) {
63
+ (context.viewController as? AkanNativeViewController)?.statusBarStyle = nil
64
+ }
65
+
66
+ //? Android's Color.luminance (sRGB relative luminance) over 0.5, so both shells pick the same icons for one color.
67
+ static func isLight(hex: String) -> Bool? {
68
+ let digits = hex.dropFirst()
69
+ guard hex.first == "#", digits.count == 6, digits.allSatisfy(\.isHexDigit), let rgb = UInt32(digits, radix: 16) else { return nil }
70
+ let linear = { (byte: UInt32) -> Double in
71
+ let c = Double(byte & 0xff) / 255
72
+ return c <= 0.04045 ? c / 12.92 : pow((c + 0.055) / 1.055, 2.4)
73
+ }
74
+ return 0.2126 * linear(rgb >> 16) + 0.7152 * linear(rgb >> 8) + 0.0722 * linear(rgb) > 0.5
75
+ }
76
+
50
77
  func startListening(_ event: String) {
51
78
  guard event == "change", registration == nil, let webView = context.webView else { return }
52
79
  last = state()
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "id": "appearance",
3
3
  "apiVersion": 1,
4
- "methods": ["get", "set"],
4
+ "methods": ["get", "set", "setThemeColor"],
5
5
  "events": ["change"],
6
6
  "codegen": true,
7
7
  "web": "./src/web.ts",
8
- "desktop": "./src/desktop.ts",
8
+ "desktop": { "module": "./src/desktop.ts", "methods": ["get", "set"] },
9
9
  "ios": {
10
10
  "sources": ["ios/*.swift"],
11
11
  "class": "AppearancePlugin",
@@ -26,6 +26,13 @@ export interface AppearanceApi {
26
26
  * available on the web (UNSUPPORTED): a page cannot change `prefers-color-scheme`.
27
27
  */
28
28
  set(args: { mode: AppearanceSetting }): Promise<void>;
29
+ /**
30
+ * iOS and Android: the color the page paints under the status bar, as `#rrggbb`. The bar's icons turn dark on a light
31
+ * color and light on a dark one; null hands them back to the shell (the appearance on iOS, the app's background color
32
+ * on Android). The page keeps drawing under the bar, so the bar gets no background of its own, and the setting ends
33
+ * with the page's document. Not available on the web or the desktop (UNSUPPORTED).
34
+ */
35
+ setThemeColor(args: { color: string | null }): Promise<void>;
29
36
  }
30
37
 
31
38
  export interface AppearanceEvents {
@@ -34,7 +41,7 @@ export interface AppearanceEvents {
34
41
  }
35
42
 
36
43
  export const appearance = definePlugin<AppearanceApi, AppearanceEvents>("appearance", {
37
- methods: ["get", "set"],
44
+ methods: ["get", "set", "setThemeColor"],
38
45
  events: ["change"],
39
46
  web,
40
47
  });
@@ -5,6 +5,7 @@ import { homedir } from "node:os";
5
5
  import { join } from "node:path";
6
6
  import { AkanNativeError } from "../../../packages/core/src/index.ts";
7
7
  import { type DesktopContext, defineDesktopPlugin } from "../../../packages/desktop/src/plugin.ts";
8
+ import { appLauncher } from "../../../packages/desktop/src/relaunch.ts";
8
9
  import type { AutostartApi, AutostartState, AutostartStatus } from "./index.ts";
9
10
 
10
11
  export interface ShellError {
@@ -111,7 +112,7 @@ export function entryStatus(text: string | null): AutostartStatus {
111
112
  /** `executable`: the file the entry starts; an AppImage's mount point changes at every start, $APPIMAGE does not. */
112
113
  export function linuxAutostart(
113
114
  dir: () => string = () => autostartDir(),
114
- executable: () => string = () => process.env.APPIMAGE || process.execPath,
115
+ executable: () => string = () => appLauncher(),
115
116
  ) {
116
117
  const file = (ctx: DesktopContext) => join(dir(), `${ctx.app.id}.desktop`);
117
118
  const read = (ctx: DesktopContext) => (existsSync(file(ctx)) ? readFileSync(file(ctx), "utf8") : null);
@@ -17,7 +17,10 @@
17
17
  ],
18
18
  "events": ["load", "loadFailed", "gone", "consoleMessage"],
19
19
  "web": null,
20
- "desktop": "./src/desktop.ts",
20
+ "desktop": {
21
+ "module": "./src/desktop.ts",
22
+ "unsupported": { "macos": ["sendKey", "setMuted", "capture"] }
23
+ },
21
24
  "ios": null,
22
25
  "android": null
23
26
  }
@@ -10,8 +10,10 @@ import { definePlugin, type FileRef } from "../../../packages/core/src/index.ts"
10
10
  * permissions and links another program would open (`mailto:`, a custom scheme) are refused. Listing the plugin in
11
11
  * `native.plugins` is what lets an app open one.
12
12
  *
13
- * Windows has every method. macOS (14 or later, for its separate profile) has all but `sendKey`, `setMuted` and
14
- * `capture`, and sends no `loadFailed` or `consoleMessage`. Linux, iOS and Android: UNSUPPORTED.
13
+ * Windows has every method. Linux has every method and sends no `consoleMessage`; there the visible view shown last
14
+ * also holds the keyboard focus inside its window, so the user's own keys reach it, until a click on the page takes the
15
+ * focus or the view is hidden or closed. macOS (14 or later, for its separate profile) has all but `sendKey`,
16
+ * `setMuted` and `capture`, and sends no `loadFailed` or `consoleMessage`. iOS and Android: UNSUPPORTED.
15
17
  */
16
18
  export type ExternalViewBounds = "fill" | { x: number; y: number; width: number; height: number };
17
19
 
@@ -30,7 +32,7 @@ export interface ExternalViewOpenOptions {
30
32
  * with `evaluate`. It may not declare `__akanTopOnly`, and an empty one registers nothing.
31
33
  */
32
34
  initScript?: string;
33
- /** Windows only: macOS refuses `true` as UNSUPPORTED. */
35
+ /** macOS refuses `true` as UNSUPPORTED. */
34
36
  muted?: boolean;
35
37
  /** Media plays with sound without a gesture first (default true): nobody taps a signage screen. */
36
38
  autoplay?: boolean;
@@ -53,7 +55,7 @@ export interface ExternalViewApi {
53
55
  /**
54
56
  * Opens the view, or brings an open one with this id to these options (a page that mounts again finds it). Another
55
57
  * `initScript` builds the view again and loads its page anew, as does another `console` on Windows and another
56
- * `autoplay` on macOS; Windows refuses another `autoplay` as UNSUPPORTED, before anything is built.
58
+ * `autoplay` on macOS and Linux; Windows refuses another `autoplay` as UNSUPPORTED, before anything is built.
57
59
  */
58
60
  open(args: ExternalViewOpenOptions): Promise<ExternalViewState>;
59
61
  /** Rejects NOT_ALLOWED for a URL on none of its `allowOrigins`. */
@@ -70,13 +72,16 @@ export interface ExternalViewApi {
70
72
  * answer within 30 s, as from a page busy in a loop; `sendKey` and `capture` time out the same way.
71
73
  */
72
74
  evaluate(args: { id: string; script: string }): Promise<{ value: unknown }>;
73
- /** A trusted key press (`{ key: "z", code: "KeyZ" }`), whether or not the view has the focus. Windows only. */
75
+ /**
76
+ * A trusted key press (`{ key: "z", code: "KeyZ" }`), whether or not the view has the focus. Not on macOS; on Linux
77
+ * UNSUPPORTED while the view's window is hidden.
78
+ */
74
79
  sendKey(args: { id: string; key: string; code: string }): Promise<void>;
75
- /** The view's own sound only; the system volume is the volume plugin's. Windows only. */
80
+ /** The view's own sound only; the system volume is the volume plugin's. Not on macOS. */
76
81
  setMuted(args: { id: string; muted: boolean }): Promise<void>;
77
82
  /** Clears the view's cookies, storage and cache; the app's own stay. */
78
83
  clearData(args: { id: string }): Promise<void>;
79
- /** A PNG of the view's content (not the screen), kept until its next capture or the next launch. Windows only. */
84
+ /** A PNG of the view's content (not the screen), kept until its next capture or the next launch. Not on macOS. */
80
85
  capture(args: { id: string }): Promise<FileRef & { width?: number; height?: number }>;
81
86
  }
82
87
 
@@ -85,13 +90,15 @@ export interface ExternalViewEvents {
85
90
  /**
86
91
  * A navigation that failed. `errorCode`: `http<status>` for a server's 4xx or 5xx page, else WebView2's own
87
92
  * (`hostNameNotResolved`, `cannotConnect`, `timeout`, `certificate`, `disconnected`, …; a refused connection is
88
- * `unknown`). Windows only.
93
+ * `unknown`). Linux names the same failures by those names (a refused connection is `cannotConnect`) and any other
94
+ * `unknown`. Not on macOS.
89
95
  */
90
96
  loadFailed: { id: string; url: string; errorCode: string };
91
97
  /**
92
- * Its web process ended (`reason`: `crashed`, `unresponsive` or `browserExited` on Windows, `terminated` on macOS);
93
- * the view loads its page again by itself, sooner the first times, and an end while that waits is not reported
94
- * again. `rebuildFailed`: after its browser exited the view could not be built again, and is closed; open it again.
98
+ * Its web process ended (`reason`: `crashed`, `unresponsive` or `browserExited` on Windows, `terminated` on macOS,
99
+ * `crashed`, `killed` or `oom` on Linux); the view loads its page again by itself, sooner the first times, and an end
100
+ * while that waits is not reported again. `rebuildFailed`: after its browser exited the view could not be built
101
+ * again, and is closed; open it again.
95
102
  */
96
103
  gone: { id: string; reason: string; restarts: number };
97
104
  /** `dropped`: messages left out before this one, past the rate cap. Windows only. */
@@ -0,0 +1,33 @@
1
+ import { AgenticSurface } from "./AgenticSurface";
2
+ import { ToolRunner, type ToolRunnerHost } from "./ToolRunner";
3
+ import type { PublishedTool, SurfaceView, ToolCallRequest, ToolCallResult } from "./types";
4
+
5
+ /** `readOnly` is always `false`: a screen tool declares no such flag, so a server loop counts every one as a write. */
6
+ export interface AgentClientToolDefinition extends PublishedTool {
7
+ readOnly: false;
8
+ }
9
+
10
+ /**
11
+ * A screen's tools lent to an agent loop that runs on the server: `list()` is what that loop takes as its client
12
+ * tools, and `run(call)` answers a call it parked. A call goes through the same `ToolRunner` as the in-page chat, so a
13
+ * `confirm` still asks through `host.approve` (refused without one), a card needs `host.card`, and the answer is
14
+ * clipped and fenced as the chat's would be.
15
+ */
16
+ export class AgentClientTools {
17
+ readonly #surface: SurfaceView;
18
+ readonly #runner: ToolRunner;
19
+
20
+ constructor(surface: SurfaceView = AgenticSurface.shared, host: ToolRunnerHost = {}) {
21
+ this.#surface = surface;
22
+ this.#runner = new ToolRunner(surface, host);
23
+ }
24
+
25
+ list(): AgentClientToolDefinition[] {
26
+ return this.#surface.snapshot().tools.map((tool) => ({ ...tool, readOnly: false }));
27
+ }
28
+
29
+ /** Never throws: a tool no longer on the screen, a refusal and a failure all come back as the result's `error`. */
30
+ async run(call: ToolCallRequest, signal: AbortSignal = new AbortController().signal): Promise<ToolCallResult> {
31
+ return await this.#runner.run(call, signal);
32
+ }
33
+ }
@@ -10,6 +10,7 @@ import type {
10
10
  ContextBlock,
11
11
  MessageReference,
12
12
  PublishedTool,
13
+ RunnerEvent,
13
14
  RunnerRequest,
14
15
  SurfaceView,
15
16
  ToolActivity,
@@ -429,15 +430,15 @@ export class AgentSession {
429
430
  budget = turn + maxTurns;
430
431
  }
431
432
  await this.#autoCompact(controller.signal);
432
- const { toolCalls, stop, overflow } = await this.#assistantTurn(controller.signal);
433
+ const { toolCalls, stop, failure } = await this.#assistantTurn(controller.signal);
433
434
 
434
435
  if (controller.signal.aborted) {
435
436
  this.#unanswered(toolCalls);
436
437
  return;
437
438
  }
438
- if (overflow) {
439
- if (recovered || !(await this.#recover(overflow, controller.signal))) {
440
- if (!controller.signal.aborted) this.#fail(overflow.message);
439
+ if (failure) {
440
+ if (!failure.overflow || recovered || !(await this.#recover(failure.overflow, controller.signal))) {
441
+ if (!controller.signal.aborted) this.#fail(failure.message, failure.code);
441
442
  return;
442
443
  }
443
444
  recovered = true;
@@ -750,7 +751,7 @@ export class AgentSession {
750
751
 
751
752
  async #assistantTurn(
752
753
  signal: AbortSignal,
753
- ): Promise<{ toolCalls: ToolCallRequest[]; stop: TurnStop; overflow?: { message: string; limit?: number } }> {
754
+ ): Promise<{ toolCalls: ToolCallRequest[]; stop: TurnStop; failure?: Extract<RunnerEvent, { type: "error" }> }> {
754
755
  const frame = this.#frame();
755
756
  this.#overhead = AgentSession.#tokensOfFrame(frame);
756
757
  this.#listed = frame.tools.map((tool) => tool.name);
@@ -770,9 +771,7 @@ export class AgentSession {
770
771
  stop = event.stop;
771
772
  usage = event.usage;
772
773
  if (event.limits) this.#limits = { ...this.#limits, ...event.limits };
773
- } else if (event.overflow)
774
- return { toolCalls: [], stop: "end", overflow: { message: event.message, limit: event.overflow.limit } };
775
- else throw new Error(event.message);
774
+ } else return { toolCalls: [], stop: "end", failure: event };
776
775
  }
777
776
  if (toolCalls.length || usage)
778
777
  this.#patchLast({ ...(toolCalls.length ? { toolCalls } : {}), ...(usage ? { usage } : {}) });
@@ -907,10 +906,11 @@ export class AgentSession {
907
906
  }
908
907
 
909
908
  /** Recorded on the open assistant draft when there is one, so a failed turn reads as that turn failing. */
910
- #fail(message: string) {
909
+ #fail(message: string, code?: string) {
910
+ const failed = { error: message, ...(code ? { errorCode: code } : {}) };
911
911
  const last = this.#messages[this.#messages.length - 1];
912
- if (last?.role === "assistant" && !last.error) this.#patchLast({ error: message });
913
- else this.#append({ role: "assistant", error: message });
912
+ if (last?.role === "assistant" && !last.error) this.#patchLast(failed);
913
+ else this.#append({ role: "assistant", ...failed });
914
914
  }
915
915
 
916
916
  #append(message: ChatMessage) {
@@ -1,9 +1,30 @@
1
1
  # use-agentic
2
2
 
3
- ## 0.3.1
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - dcddea0: `agentService.loop` can now call the tools of a screen the member has open, without running them on the server. The run parks each such call, the way an approval parks one, until the page answers it.
8
+
9
+ - **Server.** `clientTools` takes the definitions the open page sent over the app's own transport. They are listed beside the endpoint tools.
10
+ - They are client input. Each definition is rebuilt from `name`, `description`, `parameters`, `readOnly` and `needsConfirm`. A name an endpoint tool holds is dropped, in a closed toolkit too, and so is `openToolkit`.
11
+ - `approve` is still asked about each call. With no approver, a definition that is not `readOnly` counts as a write, and a `needsConfirm` one is refused.
12
+ - An allowed call ends the run as `awaiting`, with `client: true` on the event. Calls written before it in the same batch have already run; calls written after it wait for the resume.
13
+ - The run never waits on a socket. The app delivers the call to the page, appends the page's result to the stored messages (or its own error when no page answers), and resumes. A resume without that result parks the call again. A resume without `clientTools` answers it as an unknown tool.
14
+ - **Browser.** `AgentClientTools` is new in `use-agentic` and re-exported from `akanjs/ui`, along with the `ToolRunnerHost` and `ToolApprovalRequest` types.
15
+ - `new AgentClientTools(surface?, host?).list()` gives the open screen's tools in the shape `clientTools` takes, each with `readOnly: false`.
16
+ - `run(call)` answers a parked call through the same `ToolRunner` as the in-page chat. A `confirm` still asks through `host.approve` and is refused without one, a card tool needs `host.card`, and the answer is clipped and fenced as the chat's would be.
17
+
18
+ Both are new and optional, so no upgrade step is needed.
4
19
 
5
20
  ### Patch Changes
6
21
 
22
+ - 8c70603: A failed agent turn now names a code a host can branch on, beside the message it already sent, which is unchanged. No upgrade step is needed: the fields are new.
23
+
24
+ - The relay's `error` event and `AgentTurnStream.failure` carry `code`, named the way a failed MCP tool call is: by the body the relay would have answered with before its stream opened, so a failure, a 5xx included, reads the same code either side of it. That is the dictionary key in the body, else its code token, else the status's name. The token is an `AkanError`'s own code when its JSON carries it, as a generalized answer always does, or the code a third-party error's own JSON carries. A 401 or 403 takes no key, and a guard's is named by its status alone. `SignalFailure.codeOf(error, status)` holds that rule, and a failed MCP tool call is now named through it too.
25
+ - `use-agentic`'s `RunnerEvent` error gains an optional `code`. `httpRunner` reads it from a stream's error event and keeps it only when it is a dictionary key or one camelCase token. A failure answered before the stream opens is named by its JSON body's bounded code, whether or not the body carries a message, else by its status. A 401 or 403 takes no dictionary key there either, so a refusal or a 5xx reads the code a streamed `error` event names for it. WIRE.md states that rule, and the two cases where the akan server still names a failure differently.
26
+ - The in-page chat keeps the key as `code` after translating the message. The session records it on the failed assistant message as `ChatMessage.errorCode`, which a host reads and the transcript never sends back.
27
+
7
28
  - e3de9ef: Tighter defaults for the web client and the in-page agent. Every changed default below names the option that restores the old behaviour.
8
29
 
9
30
  - **Write tools confirm by default.** An `st.tool` whose name starts with `remove`, `delete`, `create`, `update`, `upsert`, `submit`, `save`, `send` or `export` now shows the approval card unless it declares `confirm`. Before, only `remove*` did. This covers `submit<Model>` in `Model.EditModal` and `exportCsvOf<Model>` / `exportJsonOf<Model>` in `Data.ListContainer`. Opt out per tool with `{ confirm: false }`, which also drops the tool's confirm mark in the dock and the screen actions and its MCP `destructiveHint`, or app-wide with `AgentConfirm.set({ byName: (name) => name.startsWith("remove") })`.
@@ -19,6 +40,30 @@
19
40
  - **Links in agent markdown.** `isSafeHref` drops tabs, newlines and leading control characters and spaces before it reads the scheme, as a browser does, so a disguised `javascript:` link is refused.
20
41
  - **CSV export keeps formulas as text.** A text cell that starts with `=`, `+`, `-`, `@`, a tab or a carriage return gets a leading `'`. Numbers are written unchanged.
21
42
 
43
+ - 3b7247e: A failed tool call now names a code a client or a model can branch on, beside the text it already sent, which is unchanged. No upgrade step is needed: `AgentWireToolResult` and `use-agentic`'s `ToolCallResult` only gain an optional `code`, and `akanjs/common` adds `MCP_FAILURE_META`, `McpFailure` and `FailureCode`.
44
+
45
+ Every code is a bounded token, a dictionary key (`<module>.error.<key>`) or one camelCase identifier, never prose, so no text can pass for one.
46
+
47
+ - **An app's `/mcp`:**
48
+ - A tool error carries `_meta["akanjs/failure"]: { code, statusCode }`, beside the server's own `_meta` for a 2026-07-28 client. The code is the one an HTTP caller gets:
49
+ - a domain `Err` by its dictionary key, such as `base.error.documentNotFound`;
50
+ - an `AkanError` by its code, such as `invalidArgument` for an argument the call got wrong;
51
+ - a guard's 401 or 403 by its status alone (`unauthorized`, `forbidden`);
52
+ - a 5xx by the dictionary key or code token its HTTP answer carries, else by its status (`internalError`, `serviceUnavailable`). Its text is redacted but its code is not, and the code comes from the error's own JSON when that carries one, which can be a third-party library's.
53
+ - A JSON-RPC error carries `data.code`, which tells apart what `-32602` covers:
54
+ - `unknownTool`, `unknownPrompt` (an unlisted page prompt included) and `unknownResource`;
55
+ - `invalidArgument` for bad arguments or a missing tool name, prompt name or resource uri;
56
+ - a refused screen's `forbidden` or `notFound`.
57
+ A rate-limited call names `tooManyRequests` and the catch-all names `internalError`.
58
+ - An MCP Apps view's call that fails without a domain `Err` restores as an error with that status and code, where it used to be a plain `Error`. A tool the view itself serves to the host names its code in the same `_meta` entry, without a `statusCode`.
59
+ - **`akan mcp`:** a tool error carries the same `_meta["akanjs/failure"]`, with one of these codes:
60
+ - `unknownTool` for a name no mode lists;
61
+ - `toolUnavailable` for a tool outside the server's mode;
62
+ - `invalidArgument` for a missing argument, an unknown guideline name, or a workflow path outside `.akan/workflows/`;
63
+ - `toolFailed` for anything else, with `statusCode` 500. A coded `AkanError` keeps its own code.
64
+ - **The code agent:** an MCP server's tool result keeps the code it named, from `_meta["akanjs/failure"]` or a JSON-RPC error's `data.code`, in the call's `details`.
65
+ - **The in-page agent:** a `toolResults` entry whose tool threw carries `code` beside `error` (see `use-agentic`'s WIRE.md): a dictionary `Err`'s key, else the thrown error's own `code`. A `taint: "source"` tool's result carries none, since its code would travel outside the page-content fence. The bundled Anthropic and OpenAI adaptors send `code` to the model inside the tool result, beside `error`.
66
+
22
67
  ## 0.3.0
23
68
 
24
69
  ### Minor Changes
@@ -95,7 +95,8 @@ export class Compaction {
95
95
  }
96
96
 
97
97
  static #charsOf(message: ChatMessage): number {
98
- const posted = message.usage ? { ...message, usage: undefined } : message;
98
+ const posted =
99
+ message.usage || message.errorCode ? { ...message, usage: undefined, errorCode: undefined } : message;
99
100
  const own = Compaction.#blanked(message.attachments);
100
101
  let images = own.images;
101
102
  const toolResults = message.toolResults?.map((result) => {
@@ -1,5 +1,6 @@
1
1
  import { AgentAbort } from "./AgentAbort";
2
2
  import { AgentProgress, type AgentProgressReport } from "./AgentProgress";
3
+ import { failureCodeOf, isFailureCode } from "./failureCode";
3
4
  import { ToolOutput } from "./ToolOutput";
4
5
  import { ToolReturn } from "./ToolReturn";
5
6
  import type {
@@ -124,9 +125,10 @@ export class ToolRunner {
124
125
  async run(call: ToolCallRequest, signal: AbortSignal): Promise<ToolCallResult> {
125
126
  const source = this.#surface.tool(call.name)?.taint === "source";
126
127
 
127
- const answered = ToolOutput.clipped(await this.#answer(call, signal));
128
- if (!source) return answered;
128
+ const { code, ...answered } = ToolOutput.clipped(await this.#answer(call, signal));
129
+ if (!source) return isFailureCode(code) ? { ...answered, code } : answered;
129
130
  this.#untrusted = true;
131
+
130
132
  return ToolRunner.#framed(answered);
131
133
  }
132
134
 
@@ -227,7 +229,8 @@ export class ToolRunner {
227
229
  return ToolRunner.#answered(base, returned, this.#surface.diffSince(before));
228
230
  } catch (error) {
229
231
  failed = error instanceof Error ? error.message : String(error);
230
- return { ...base, error: failed };
232
+ const code = failureCodeOf(error);
233
+ return { ...base, error: failed, ...(code ? { code } : {}) };
231
234
  } finally {
232
235
  this.#host.progress?.({ callId: call.id, report: null });
233
236
  this.#host.activity?.({
@@ -15,9 +15,7 @@ export class Transcript {
15
15
 
16
16
  /** What one turn posts: no host-only message, no unanswered call, no result answering a call nobody sees. */
17
17
  static wire(messages: readonly ChatMessage[]): ChatMessage[] {
18
- return Transcript.sanitize(
19
- Transcript.seen(messages.filter((message) => !message.local)).map(Transcript.unmeasured),
20
- );
18
+ return Transcript.sanitize(Transcript.seen(messages.filter((message) => !message.local)).map(Transcript.#sent));
21
19
  }
22
20
 
23
21
  /**
@@ -54,6 +52,11 @@ export class Transcript {
54
52
  return { ...result, attachments };
55
53
  }
56
54
 
55
+ static #sent(message: ChatMessage): ChatMessage {
56
+ const unmeasured = Transcript.unmeasured(message);
57
+ return unmeasured.errorCode ? { ...unmeasured, errorCode: undefined } : unmeasured;
58
+ }
59
+
57
60
  /** A message without the provider's count for its turn — what the wire carries and what a compaction keeps. */
58
61
  static unmeasured(message: ChatMessage): ChatMessage {
59
62
  return message.usage ? { ...message, usage: undefined } : message;
@@ -35,6 +35,11 @@ tools, and the loop stay in the client; the server serves exactly one stateless
35
35
  the request carries.** The client holds that invariant (`Transcript.sanitize`) because provider dialects refuse
36
36
  a transcript that breaks it; a backend can map calls to results by id without checking for holes. A call the
37
37
  client stopped before running arrives answered with an `error`, not missing.
38
+ - A `toolResults` entry whose call threw may carry `code` beside `error`: a dictionary `Err`'s key
39
+ (`<module>.error.<key>`), else the thrown error's own `code` (an `AkanError`'s). It is a bounded token, never
40
+ prose, and never on a `taint: "source"` tool's result. **Send it to the model with `error`**, so the model can tell
41
+ a refusal it can fix from one it cannot by more than the wording. A client that sends no `code` sends what it
42
+ always did.
38
43
  - A message may carry `error` — a turn that failed, recorded where every other failure is recorded. No provider
39
44
  format has a field for it, so **fold it into the text you send**: an assistant turn that reaches the model
40
45
  saying nothing is one the model repeats.
@@ -105,10 +110,27 @@ outgrows the window, measured by the provider's own count rather than by a chara
105
110
  falls back to its transcript ceiling alone.
106
111
 
107
112
  Any non-2xx status is surfaced to the session as one error event and ends the turn; a string `message` or
108
- `error` field in a JSON body becomes that event's message verbatim, and any other body is not interpreted. A
109
- message that is a code rather than a sentence may be accompanied by a flat `data` object of strings and numbers —
110
- the values whoever resolves the code interpolates into its text; a host that does not know the code shows the
111
- message as it stands.
113
+ `error` field in a JSON body becomes that event's message verbatim, else the message is
114
+ `Agent turn failed: <status>`. A message that is a code rather than a sentence may be accompanied by a flat `data`
115
+ object of strings and numbers — the values whoever resolves the code interpolates into its text; a host that does
116
+ not know the code shows the message as it stands.
117
+
118
+ The event also carries `code`, read from a JSON body whether or not it has a message: the dictionary key
119
+ (`<module>.error.<key>`) in the body's `error`, `message` or `code`, else its `code` when that is one camelCase
120
+ token, else the status's name (`unauthorized`, `forbidden`, `tooManyRequests`, `internalError`, or `http<status>`
121
+ for a status with no name). A 401 or 403 takes no dictionary key: it is its `code` token, else its status's name. A
122
+ body's `code` shaped otherwise, such as a proxy's `ECONNRESET`, is dropped rather than passed on, and a body that is
123
+ not JSON, such as a proxy's HTML page, leaves the status's name. A 5xx is no exception: its token is taken too, and
124
+ on the akan server it comes from the failed error's own JSON when that carries one, which can be a third-party
125
+ library's rather than the server's own. The bound is what keeps prose out of it.
126
+
127
+ A server names a failure inside the stream by this same rule, applied to the body it would have answered with, so a
128
+ host sees one code whether the failure came before or after the stream opened. The akan server does, with two
129
+ exceptions. In detailed mode (development, or `AKAN_ERROR_DETAIL=1`) a generalized JSON answer's `error` is the raw
130
+ message, which reads as a key over JSON when it is one. And an app's own forwarded `AkanError` 401 or 403 whose
131
+ JSON carries a code is named by that code over JSON but by its status in the stream; none of the framework's own
132
+ errors is such a refusal. The code is what a host branches on, since the message may reach it already translated.
133
+ The session keeps it on the failed assistant message as `errorCode`, which is never sent back.
112
134
 
113
135
  **A refusal because the prompt no longer fits the window carries `"overflow": { "limit": 128000 }`** (`limit` only
114
136
  when the provider named it). It is the one refusal a session can answer by itself: it summarizes the transcript and
@@ -120,6 +142,6 @@ limit flagged as overflow compacts a conversation that fit.
120
142
  The same endpoint may answer `text/event-stream` instead when the request's `accept` names it: one `RunnerEvent`
121
143
  (`types.ts`) JSON object per SSE `data:` line, ending with the `done` event. A failure after the stream opened
122
144
  travels as one `error` event — the status line is already gone by then. `usage` and `limits` ride the `done` event
123
- and `overflow` the `error` event, in the same shapes as above. `httpRunner` sends
124
- `accept: text/event-stream, application/json` and branches on the response's content type, so a server that never
125
- streams keeps answering the single JSON object above unchanged.
145
+ and `overflow` and `code` the `error` event, in the same shapes and bounds as above, `code` named by the rule above.
146
+ `httpRunner` sends `accept: text/event-stream, application/json` and branches on the response's content type, so a
147
+ server that never streams keeps answering the single JSON object above unchanged.