akanjs 3.1.0-rc.8 → 3.1.0

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 (323) hide show
  1. package/CHANGELOG.md +547 -0
  2. package/README.ko.md +2 -2
  3. package/README.md +2 -2
  4. package/client/cookie.ts +5 -0
  5. package/client/csrLocation.ts +17 -72
  6. package/client/csrTypes.ts +19 -4
  7. package/client/href.ts +8 -0
  8. package/client/makePageProto.tsx +3 -2
  9. package/client/route/PageDefinition.ts +103 -10
  10. package/client/route/RouteDefinition.ts +44 -3
  11. package/client/route/RouteGuards.ts +64 -0
  12. package/client/route/index.ts +1 -0
  13. package/client/route/resolveRouteModule.ts +8 -0
  14. package/client/route/routeArgs.ts +9 -0
  15. package/client/router.ts +51 -2
  16. package/client/translator.ts +16 -0
  17. package/client/viewportMeta.ts +23 -8
  18. package/common/Logger.ts +6 -4
  19. package/common/authCookie.ts +13 -0
  20. package/common/authToken.ts +1 -12
  21. package/common/codeAgentWire.ts +8 -1
  22. package/common/index.ts +2 -8
  23. package/common/routeConvention.ts +2 -0
  24. package/constant/inputParser.ts +1 -1
  25. package/dictionary/base.dictionary.ts +11 -0
  26. package/document/database.ts +3 -0
  27. package/document/documentQuery.ts +21 -0
  28. package/document/into.ts +2 -0
  29. package/document/liveRowScope.ts +4 -8
  30. package/document/noDocumentError.ts +6 -1
  31. package/document/queryEvaluator.ts +5 -8
  32. package/fetch/appScope.ts +54 -0
  33. package/fetch/client/fetchClient.ts +46 -29
  34. package/fetch/client/httpClient.ts +38 -10
  35. package/fetch/client/sliceInitHandle.ts +2 -3
  36. package/fetch/client/wsClient.ts +3 -1
  37. package/fetch/fetchType/endpointFetch.type.ts +11 -9
  38. package/fetch/index.ts +1 -0
  39. package/index.ts +2 -0
  40. package/package.json +32 -22
  41. package/server/akanApp.ts +12 -3
  42. package/server/akanServer.ts +10 -5
  43. package/server/index.ts +1 -0
  44. package/server/mcp/McpApps.ts +44 -50
  45. package/server/mcp/McpDispatcher.ts +3 -3
  46. package/server/mcp/McpPages.ts +93 -19
  47. package/server/mcp/McpRouter.ts +14 -11
  48. package/server/memoryLimit.ts +4 -0
  49. package/server/migration/docPath.ts +121 -0
  50. package/server/migration/index.ts +15 -0
  51. package/server/migration/migrationChangeLog.ts +86 -0
  52. package/server/migration/migrationChanges.ts +70 -0
  53. package/server/migration/migrationCommand.ts +179 -0
  54. package/server/migration/migrationContext.ts +53 -0
  55. package/server/migration/migrationDefinition.ts +87 -0
  56. package/server/migration/migrationError.ts +45 -0
  57. package/server/migration/migrationLedger.ts +172 -0
  58. package/server/migration/migrationLock.ts +103 -0
  59. package/server/migration/migrationParams.ts +122 -0
  60. package/server/migration/migrationPulse.ts +39 -0
  61. package/server/migration/migrationRunner.ts +525 -0
  62. package/server/migration/migrationScope.ts +93 -0
  63. package/server/migration/migrationTable.ts +258 -0
  64. package/server/migration/migrations.ts +57 -0
  65. package/server/ops/migrateJobs.ts +145 -0
  66. package/server/ops/opsCommand.ts +30 -1
  67. package/server/ops/opsRoute.ts +39 -7
  68. package/server/ops/opsToken.ts +7 -2
  69. package/server/resolver/CascadeRunner.ts +15 -2
  70. package/server/resolver/database.resolver.ts +4 -0
  71. package/server/resolver/service.resolver.ts +3 -0
  72. package/server/resolver/signal.resolver.ts +41 -31
  73. package/server/routeElementComposer.tsx +33 -6
  74. package/server/routeState.ts +1 -0
  75. package/server/routeTreeBuilder.ts +5 -0
  76. package/server/rscClient.tsx +67 -22
  77. package/server/rscClientFetch.ts +8 -3
  78. package/server/rscNavigationState.ts +2 -2
  79. package/server/rscPagePrompts.ts +66 -16
  80. package/server/rscScrollRestoration.ts +21 -8
  81. package/server/rscWorker.tsx +79 -32
  82. package/server/rscWorkerHost.ts +12 -1
  83. package/server/tunnel/TunnelAgent.ts +2 -1
  84. package/server/webRouter.ts +33 -27
  85. package/service/agent.service.ts +21 -1
  86. package/service/endpointCacheKeys.ts +35 -0
  87. package/service/index.ts +1 -0
  88. package/service/liveSyncHub.ts +2 -1
  89. package/service/predefinedAdaptor/anthropicLlm.ts +37 -17
  90. package/service/predefinedAdaptor/database.adaptor.ts +98 -25
  91. package/service/predefinedAdaptor/documentTransfer.ts +50 -0
  92. package/service/predefinedAdaptor/endpointCacheControl.adaptor.ts +19 -0
  93. package/service/predefinedAdaptor/index.ts +1 -0
  94. package/service/predefinedAdaptor/llm.adaptor.ts +7 -0
  95. package/service/predefinedAdaptor/openaiDialect.ts +53 -17
  96. package/service/predefinedAdaptor/openaiLlm.ts +1 -1
  97. package/service/predefinedAdaptor/solidQueue.adaptor.ts +30 -9
  98. package/service/predefinedAdaptor/sql/MigrationTables.ts +90 -0
  99. package/service/predefinedAdaptor/sql/QueryCompiler.ts +16 -14
  100. package/service/predefinedAdaptor/sql/RawDocumentTable.ts +200 -0
  101. package/service/predefinedAdaptor/sql/SqlDocumentStore.ts +218 -44
  102. package/service/predefinedAdaptor/sql/SqliteInsightSession.ts +4 -1
  103. package/service/predefinedAdaptor/sql/dialect/postgres.ts +13 -3
  104. package/service/predefinedAdaptor/sql/dialect/sqlite.ts +13 -2
  105. package/service/predefinedAdaptor/sql/driver/bunSqlite.ts +4 -5
  106. package/service/predefinedAdaptor/sql/types.ts +22 -1
  107. package/service/predefinedAdaptor/sql/values.ts +19 -0
  108. package/service/predefinedAdaptor/storage.adaptor.ts +19 -0
  109. package/service/serviceModule.ts +3 -0
  110. package/service/types.ts +1 -0
  111. package/signal/TaggedJson.ts +26 -4
  112. package/signal/endpointCache.ts +16 -6
  113. package/signal/exception.ts +4 -1
  114. package/signal/mcp/mcpProtocol.ts +7 -0
  115. package/signal/mcp/pagePrompt.ts +18 -1
  116. package/signal/signalContext.ts +7 -10
  117. package/store/action.ts +181 -73
  118. package/store/agent/ScreenImage.ts +166 -0
  119. package/store/agent/StoreSurfaceSource.ts +41 -2
  120. package/store/agent/index.ts +2 -1
  121. package/store/databaseStateNames.ts +1 -0
  122. package/store/formUploadOf.ts +41 -0
  123. package/store/index.ts +1 -0
  124. package/store/liveInsert.ts +5 -1
  125. package/store/sliceKeys.ts +1 -0
  126. package/store/state.ts +15 -3
  127. package/store/stateBuilder.ts +7 -1
  128. package/store/storeInstance.ts +22 -4
  129. package/types/client/csrLocation.d.ts +3 -7
  130. package/types/client/csrTypes.d.ts +22 -3
  131. package/types/client/href.d.ts +3 -0
  132. package/types/client/route/PageDefinition.d.ts +21 -4
  133. package/types/client/route/RouteDefinition.d.ts +4 -0
  134. package/types/client/route/RouteGuards.d.ts +15 -0
  135. package/types/client/route/index.d.ts +1 -0
  136. package/types/client/route/resolveRouteModule.d.ts +2 -0
  137. package/types/client/route/routeArgs.d.ts +5 -0
  138. package/types/client/route/routeBuilders.d.ts +1 -1
  139. package/types/client/router.d.ts +9 -1
  140. package/types/client/translator.d.ts +2 -0
  141. package/types/common/authCookie.d.ts +5 -0
  142. package/types/common/authToken.d.ts +0 -5
  143. package/types/common/codeAgentWire.d.ts +7 -0
  144. package/types/common/index.d.ts +2 -1
  145. package/types/dictionary/base.dictionary.d.ts +1 -1
  146. package/types/dictionary/dictionary.d.ts +8 -8
  147. package/types/document/database.d.ts +3 -0
  148. package/types/document/documentQuery.d.ts +1 -0
  149. package/types/document/into.d.ts +2 -0
  150. package/types/document/noDocumentError.d.ts +6 -1
  151. package/types/fetch/appScope.d.ts +18 -0
  152. package/types/fetch/client/fetchClient.d.ts +1 -1
  153. package/types/fetch/fetchType/endpointFetch.type.d.ts +1 -1
  154. package/types/fetch/index.d.ts +1 -0
  155. package/types/index.d.ts +5 -0
  156. package/types/server/akanServer.d.ts +10 -5
  157. package/types/server/index.d.ts +1 -0
  158. package/types/server/mcp/McpApps.d.ts +14 -8
  159. package/types/server/mcp/McpPages.d.ts +6 -3
  160. package/types/server/migration/docPath.d.ts +20 -0
  161. package/types/server/migration/index.d.ts +15 -0
  162. package/types/server/migration/migrationChangeLog.d.ts +27 -0
  163. package/types/server/migration/migrationChanges.d.ts +27 -0
  164. package/types/server/migration/migrationCommand.d.ts +33 -0
  165. package/types/server/migration/migrationContext.d.ts +28 -0
  166. package/types/server/migration/migrationDefinition.d.ts +42 -0
  167. package/types/server/migration/migrationError.d.ts +15 -0
  168. package/types/server/migration/migrationLedger.d.ts +51 -0
  169. package/types/server/migration/migrationLock.d.ts +34 -0
  170. package/types/server/migration/migrationParams.d.ts +41 -0
  171. package/types/server/migration/migrationPulse.d.ts +15 -0
  172. package/types/server/migration/migrationRunner.d.ts +93 -0
  173. package/types/server/migration/migrationScope.d.ts +42 -0
  174. package/types/server/migration/migrationTable.d.ts +52 -0
  175. package/types/server/migration/migrations.d.ts +12 -0
  176. package/types/server/migration.d.ts +1 -0
  177. package/types/server/ops/migrateJobs.d.ts +36 -0
  178. package/types/server/ops/opsCommand.d.ts +10 -1
  179. package/types/server/ops/opsRoute.d.ts +4 -1
  180. package/types/server/ops/opsToken.d.ts +3 -0
  181. package/types/server/routeElementComposer.d.ts +10 -1
  182. package/types/server/routeState.d.ts +1 -0
  183. package/types/server/rscClientFetch.d.ts +2 -0
  184. package/types/server/rscNavigationState.d.ts +1 -1
  185. package/types/server/rscPagePrompts.d.ts +3 -1
  186. package/types/server/rscScrollRestoration.d.ts +2 -0
  187. package/types/server/rscWorkerHost.d.ts +2 -1
  188. package/types/server/webRouter.d.ts +3 -0
  189. package/types/service/agent.service.d.ts +2 -0
  190. package/types/service/endpointCacheKeys.d.ts +8 -0
  191. package/types/service/index.d.ts +1 -0
  192. package/types/service/predefinedAdaptor/anthropicLlm.d.ts +9 -4
  193. package/types/service/predefinedAdaptor/database.adaptor.d.ts +21 -2
  194. package/types/service/predefinedAdaptor/documentTransfer.d.ts +1 -0
  195. package/types/service/predefinedAdaptor/endpointCacheControl.adaptor.d.ts +9 -0
  196. package/types/service/predefinedAdaptor/index.d.ts +1 -0
  197. package/types/service/predefinedAdaptor/llm.adaptor.d.ts +7 -0
  198. package/types/service/predefinedAdaptor/openaiDialect.d.ts +20 -5
  199. package/types/service/predefinedAdaptor/solidQueue.adaptor.d.ts +1 -0
  200. package/types/service/predefinedAdaptor/sql/MigrationTables.d.ts +17 -0
  201. package/types/service/predefinedAdaptor/sql/QueryCompiler.d.ts +0 -1
  202. package/types/service/predefinedAdaptor/sql/RawDocumentTable.d.ts +38 -0
  203. package/types/service/predefinedAdaptor/sql/SqlDocumentStore.d.ts +1 -0
  204. package/types/service/predefinedAdaptor/sql/dialect/postgres.d.ts +2 -1
  205. package/types/service/predefinedAdaptor/sql/dialect/sqlite.d.ts +3 -1
  206. package/types/service/predefinedAdaptor/sql/driver/bunSqlite.d.ts +2 -2
  207. package/types/service/predefinedAdaptor/sql/types.d.ts +26 -0
  208. package/types/service/predefinedAdaptor/sql/values.d.ts +1 -0
  209. package/types/service/predefinedAdaptor/storage.adaptor.d.ts +8 -0
  210. package/types/service/types.d.ts +1 -0
  211. package/types/signal/exception.d.ts +4 -1
  212. package/types/signal/mcp/mcpProtocol.d.ts +6 -0
  213. package/types/signal/mcp/pagePrompt.d.ts +16 -0
  214. package/types/signal/signalContext.d.ts +0 -2
  215. package/types/store/action.d.ts +2 -0
  216. package/types/store/agent/ScreenImage.d.ts +27 -0
  217. package/types/store/agent/StoreSurfaceSource.d.ts +1 -1
  218. package/types/store/agent/index.d.ts +2 -1
  219. package/types/store/databaseStateNames.d.ts +1 -0
  220. package/types/store/formUploadOf.d.ts +9 -0
  221. package/types/store/index.d.ts +1 -0
  222. package/types/store/liveInsert.d.ts +3 -1
  223. package/types/store/sliceKeys.d.ts +1 -0
  224. package/types/store/state.d.ts +10 -4
  225. package/types/store/stateBuilder.d.ts +1 -0
  226. package/types/ui/Agent/Composer.d.ts +2 -0
  227. package/types/ui/Agent/Menu.d.ts +2 -0
  228. package/types/ui/CsrImage.d.ts +2 -0
  229. package/types/ui/Image.d.ts +3 -1
  230. package/types/ui/Layout/FrameSlotPortal.d.ts +1 -1
  231. package/types/ui/Load/sliceClaim.d.ts +28 -0
  232. package/types/ui/Model/Edit.d.ts +3 -2
  233. package/types/ui/Model/editSeed.d.ts +4 -0
  234. package/types/ui/System/App.d.ts +17 -0
  235. package/types/ui/System/index.d.ts +2 -0
  236. package/types/ui/recipe/badgeRecipe.d.ts +2 -2
  237. package/types/ui/recipe/buttonRecipe.d.ts +2 -2
  238. package/types/ui/sliceNamesOf.d.ts +2 -0
  239. package/types/vendor/@akanjs/native/packages/cli/src/lib/compat.d.ts +6 -0
  240. package/types/vendor/@akanjs/native/packages/cli/src/lib/toolchains.d.ts +2 -2
  241. package/types/vendor/use-agentic/Compaction.d.ts +3 -1
  242. package/types/vendor/use-agentic/Reference.d.ts +7 -2
  243. package/types/vendor/use-agentic/ToolOutput.d.ts +6 -1
  244. package/types/vendor/use-agentic/ToolReturn.d.ts +18 -0
  245. package/types/vendor/use-agentic/Transcript.d.ts +7 -0
  246. package/types/vendor/use-agentic/index.d.ts +1 -0
  247. package/types/vendor/use-agentic/types.d.ts +6 -0
  248. package/types/webkit/CsrGuards.d.ts +25 -0
  249. package/types/webkit/CsrRouteTable.d.ts +6 -0
  250. package/types/webkit/CsrStack.d.ts +7 -0
  251. package/types/webkit/McpAppBoot.d.ts +32 -0
  252. package/types/webkit/McpAppBridge.d.ts +10 -1
  253. package/types/webkit/McpAppFetchBridge.d.ts +3 -1
  254. package/types/webkit/McpAppView.d.ts +4 -1
  255. package/types/webkit/PageNotFound.d.ts +5 -0
  256. package/types/webkit/RenderLayer.d.ts +1 -3
  257. package/types/webkit/index.d.ts +1 -0
  258. package/types/webkit/useDebounce.d.ts +1 -1
  259. package/ui/Agent/Chat.tsx +1 -0
  260. package/ui/Agent/Composer.tsx +2 -0
  261. package/ui/Agent/Menu.tsx +5 -1
  262. package/ui/Agent/agentSessionOf.ts +15 -8
  263. package/ui/Agent/mentionDraft.ts +2 -3
  264. package/ui/Agent/useReferenceMenu.ts +1 -0
  265. package/ui/Agent/useSlashMenu.ts +1 -0
  266. package/ui/CsrImage.tsx +3 -1
  267. package/ui/Dialog/LegacyModal.tsx +7 -5
  268. package/ui/Dialog/Modal.tsx +7 -4
  269. package/ui/Field/Collection.tsx +2 -1
  270. package/ui/Image.tsx +4 -4
  271. package/ui/Layout/BottomInset.tsx +2 -11
  272. package/ui/Layout/FrameSlotPortal.tsx +1 -3
  273. package/ui/Layout/Navbar.tsx +7 -22
  274. package/ui/Layout/TopInset.tsx +3 -4
  275. package/ui/Load/Units.tsx +34 -12
  276. package/ui/Load/sliceClaim.ts +164 -0
  277. package/ui/Model/Edit.tsx +22 -3
  278. package/ui/Model/EditModal.tsx +22 -6
  279. package/ui/Model/LoadStore.tsx +1 -1
  280. package/ui/Model/NewWrapper_Client.tsx +1 -1
  281. package/ui/Model/ViewEditModal.tsx +9 -3
  282. package/ui/Model/editSeed.ts +28 -0
  283. package/ui/System/App.tsx +43 -0
  284. package/ui/System/CSR.tsx +1 -10
  285. package/ui/System/Client.tsx +3 -0
  286. package/ui/System/index.tsx +3 -0
  287. package/ui/Tab/Provider.tsx +6 -8
  288. package/ui/styles.css +10 -0
  289. package/vendor/@akanjs/native/native/ios/Sources/AkanNativeBridge.swift +3 -2
  290. package/vendor/@akanjs/native/packages/cli/src/lib/compat.ts +6 -2
  291. package/vendor/@akanjs/native/packages/cli/src/lib/native-plugins.ts +1 -1
  292. package/vendor/@akanjs/native/packages/cli/src/lib/toolchains.ts +1 -1
  293. package/vendor/@akanjs/native/packages/cli/src/lib/updates.ts +3 -3
  294. package/vendor/@akanjs/native/plugins/sqlite/src/desktop.ts +10 -5
  295. package/vendor/@akanjs/native/plugins/updates/src/desktop.ts +45 -15
  296. package/vendor/use-agentic/CHANGELOG.md +31 -0
  297. package/vendor/use-agentic/Compaction.ts +38 -7
  298. package/vendor/use-agentic/Reference.ts +14 -10
  299. package/vendor/use-agentic/ToolOutput.ts +25 -3
  300. package/vendor/use-agentic/ToolReturn.ts +32 -0
  301. package/vendor/use-agentic/ToolRunner.ts +15 -13
  302. package/vendor/use-agentic/Transcript.ts +38 -2
  303. package/vendor/use-agentic/WIRE.md +20 -0
  304. package/vendor/use-agentic/index.ts +1 -0
  305. package/vendor/use-agentic/types.ts +6 -0
  306. package/webkit/CsrGuards.ts +112 -0
  307. package/webkit/CsrRouteTable.ts +71 -16
  308. package/webkit/CsrStack.ts +47 -1
  309. package/webkit/McpAppAgent.ts +14 -2
  310. package/webkit/McpAppBoot.tsx +129 -0
  311. package/webkit/McpAppBridge.ts +30 -6
  312. package/webkit/McpAppFetchBridge.ts +8 -2
  313. package/webkit/McpAppView.ts +39 -28
  314. package/webkit/PageNotFound.tsx +24 -0
  315. package/webkit/RenderLayer.tsx +106 -30
  316. package/webkit/bootCsr.tsx +4 -43
  317. package/webkit/index.ts +1 -0
  318. package/webkit/useCsrValues.ts +66 -6
  319. package/webkit/useDebounce.ts +23 -14
  320. package/webkit/useEscapeKey.tsx +1 -1
  321. package/webkit/useLocation.ts +21 -19
  322. package/types/webkit/EmbeddedLayout.d.ts +0 -10
  323. package/webkit/EmbeddedLayout.tsx +0 -82
@@ -20,6 +20,7 @@ import type {
20
20
  ServiceSignal,
21
21
  } from "akanjs/signal";
22
22
  import { agentTurnConstant } from "../agentTurn";
23
+ import { AppScope } from "../appScope";
23
24
  import type { ClientSignal, FetchClientType, FetchSignalInput, MergeAllFetchTypes, SliceMeta } from "../fetchType";
24
25
  import {
25
26
  claimRequestQuery,
@@ -30,7 +31,7 @@ import {
30
31
  import type { GetSliceMetaObjFromDatabaseSignals } from "../types";
31
32
  import { FetchHandle } from "./fetchHandle";
32
33
  import { HttpClient } from "./httpClient";
33
- import type { ErrorConstructor, RestoredError } from "./remoteError";
34
+ import { type ErrorConstructor, type RestoredError, restoreRemoteError } from "./remoteError";
34
35
  import { SliceInitHandle } from "./sliceInitHandle";
35
36
  import { expandQueryArgs, normalizeQueryArgs } from "./sliceQueryArgs";
36
37
  import { WsClient, type WsClientOptions } from "./wsClient";
@@ -440,8 +441,8 @@ export class FetchClient {
440
441
  const payload = claim.owned ? response : FetchClient.#deepCopy(response);
441
442
  return parseReturn(payload, { crystalize: option?.crystalize ?? true });
442
443
  };
443
- case "mutation":
444
- return async (...argData: unknown[]) => {
444
+ case "mutation": {
445
+ const send = async (...argData: unknown[]) => {
445
446
  const { option, argMap, url } = requestOf(argData);
446
447
  const bridge = this.#bridgeOf(option?.origin);
447
448
  if (bridge)
@@ -458,6 +459,12 @@ export class FetchClient {
458
459
  });
459
460
  return parseReturn(response, { crystalize: option?.crystalize ?? true });
460
461
  };
462
+
463
+ return (...argData: unknown[]) => {
464
+ this.#refuseInApp(key);
465
+ return send(...argData);
466
+ };
467
+ }
461
468
  default:
462
469
  throw new Error(`Unsupported endpoint type: ${endpoint.type}`);
463
470
  }
@@ -476,6 +483,7 @@ export class FetchClient {
476
483
  const parseReturn = this.#makeReturnParser(endpoint.returns);
477
484
  const wrappedListeners = new WeakMap<(data: unknown) => void, (data: unknown) => void>();
478
485
  return (...argData: unknown[]) => {
486
+ this.#refuseInApp(key);
479
487
 
480
488
  if (FetchClient.bridged) return () => undefined;
481
489
  const args = argData.slice(0, roomArgLength);
@@ -507,6 +515,7 @@ export class FetchClient {
507
515
  const msgArgLength = msgArgs.length;
508
516
  const serializerMap = this.#makeArgSerializer(endpoint.args);
509
517
  return (...argData: unknown[]) => {
518
+ this.#refuseInApp(key);
510
519
  if (FetchClient.bridged) return;
511
520
  const args = argData.slice(0, msgArgLength);
512
521
  const fetchPolicy = argData[msgArgLength] as FetchPolicy | undefined;
@@ -536,6 +545,12 @@ export class FetchClient {
536
545
  }
537
546
  }
538
547
 
548
+ #refuseInApp(endpoint: string) {
549
+ const app = AppScope.current();
550
+ if (app)
551
+ throw restoreRemoteError({ error: "base.error.mutationInApp", data: { app, endpoint } }, 400, this.ErrorCls);
552
+ }
553
+
539
554
  #bridgeOf(origin?: string) {
540
555
  return origin || this.#foreign ? null : FetchClient.bridge;
541
556
  }
@@ -707,32 +722,34 @@ export class FetchClient {
707
722
  );
708
723
  }
709
724
 
710
- this.#setHandlerFactory(
711
- names.addModelFiles,
712
- () =>
713
- (async (fileList: FileList | File[], parentId?: string, option?: FetchPolicy) => {
714
-
715
- if (this.#bridgeOf())
716
- throw new Error("File upload is unavailable in an MCP App view: its host relays tool calls, not files.");
717
- const cap = resolveFileUploadCapability(this.serializedSignal);
718
- const endpoint = cap ? this.serializedSignal[cap.refName]?.endpoint[cap.endpointKey] : undefined;
719
- if (!cap || !endpoint)
720
- throw new Error(
721
- "File upload is not configured. Mark an upload mutation with { fileUpload: true } (e.g. shared FileEndpoint.addFiles).",
722
- );
723
- const { fields, buildMetas } = fileUploadContract;
724
- const formData = new FormData();
725
- for (let i = 0; i < fileList.length; i++) formData.append(fields.files, fileList[i]);
726
- formData.append(fields.metas, JSON.stringify(buildMetas(fileList)));
727
- formData.append(fields.type, refName);
728
- if (parentId) formData.append(fields.parentId, parentId);
729
- const url = FetchClient.makeHttpUrl(cap.endpointKey, endpoint, cap.prefix, new Map());
730
- return await this.http.post(url, formData, {
731
- headers: this.#makeRequestHeaders(option),
732
- baseUrl: this.#baseUrlOf(endpoint),
733
- });
734
- }) as FetchHandler,
735
- );
725
+ this.#setHandlerFactory(names.addModelFiles, () => {
726
+ const upload = async (fileList: FileList | File[], parentId?: string, option?: FetchPolicy) => {
727
+
728
+ if (this.#bridgeOf())
729
+ throw new Error("File upload is unavailable in an MCP App view: its host relays tool calls, not files.");
730
+ const cap = resolveFileUploadCapability(this.serializedSignal);
731
+ const endpoint = cap ? this.serializedSignal[cap.refName]?.endpoint[cap.endpointKey] : undefined;
732
+ if (!cap || !endpoint)
733
+ throw new Error(
734
+ "File upload is not configured. Mark an upload mutation with { fileUpload: true } (e.g. shared FileEndpoint.addFiles).",
735
+ );
736
+ const { fields, buildMetas } = fileUploadContract;
737
+ const formData = new FormData();
738
+ for (let i = 0; i < fileList.length; i++) formData.append(fields.files, fileList[i]);
739
+ formData.append(fields.metas, JSON.stringify(buildMetas(fileList)));
740
+ formData.append(fields.type, refName);
741
+ if (parentId) formData.append(fields.parentId, parentId);
742
+ const url = FetchClient.makeHttpUrl(cap.endpointKey, endpoint, cap.prefix, new Map());
743
+ return await this.http.post(url, formData, {
744
+ headers: this.#makeRequestHeaders(option),
745
+ baseUrl: this.#baseUrlOf(endpoint),
746
+ });
747
+ };
748
+ return ((fileList: FileList | File[], parentId?: string, option?: FetchPolicy) => {
749
+ this.#refuseInApp(names.addModelFiles);
750
+ return upload(fileList, parentId, option);
751
+ }) as FetchHandler;
752
+ });
736
753
  }
737
754
 
738
755
  #makeModelObjFn(refName: string, callerKey: string) {
@@ -1,6 +1,11 @@
1
- import { Backoff, isRecord, type RetryPolicy } from "akanjs/common";
1
+ import { Backoff, isRecord, Logger, type RetryPolicy } from "akanjs/common";
2
2
  import type { HttpMutationMethod, SerializedArg } from "akanjs/signal";
3
- import { type ErrorConstructor, type RestoredError, restoreRemoteError } from "./remoteError";
3
+ import {
4
+ type ErrorConstructor,
5
+ type ErrorResponsePayload,
6
+ type RestoredError,
7
+ restoreRemoteError,
8
+ } from "./remoteError";
4
9
 
5
10
  export interface HttpClientOptions {
6
11
  headers?: Record<string, string>;
@@ -42,6 +47,7 @@ const transportDetailLimit = 200;
42
47
  const DEFAULT_TIMEOUT_MS = 30_000;
43
48
 
44
49
  export class HttpClient {
50
+ static readonly #logger = new Logger("HttpClient");
45
51
  readonly baseUrl: string;
46
52
  #headers: Record<string, string>;
47
53
  #timeout?: number | false;
@@ -166,11 +172,11 @@ export class HttpClient {
166
172
 
167
173
  async #requestOnce<Returns>(url: string, init: RequestInit, deadline: number): Promise<Returns> {
168
174
  const res = await this.#fetch(url, this.#withDeadline(init, deadline));
169
- const body = await this.#readBody(res);
175
+ const body = await this.#readBody(url, res);
170
176
  if (res.ok) return body as Returns;
171
177
 
172
178
  if (res.status in transportErrorKeyMap && !HttpClient.#namesErrorKey(body))
173
- throw this.#transportError(res, JSON.stringify(body));
179
+ throw this.#transportError(url, res, JSON.stringify(body));
174
180
  throw this.#restoreError(body, res.status);
175
181
  }
176
182
 
@@ -197,21 +203,21 @@ export class HttpClient {
197
203
  if (error instanceof Error && error.name === "TimeoutError")
198
204
  throw this.#restoreError({ error: transportErrorKeyMap[408], data: { status: 408 } }, 408);
199
205
  if (error instanceof Error && error.name === "AbortError") throw error;
200
- throw this.#restoreError({ error: serverUnreachableKey, details: String(error) }, 503);
206
+ throw this.#transportFailure(url, { error: serverUnreachableKey, details: String(error) }, 503);
201
207
  }
202
208
  }
203
209
 
204
- async #readBody(res: Response) {
210
+ async #readBody(url: string, res: Response) {
205
211
  if (jsonContentType.test(res.headers.get("content-type") ?? "")) {
206
212
  try {
207
213
  return (await res.json()) as unknown;
208
214
  } catch (error) {
209
- throw this.#transportError(res, String(error));
215
+ throw this.#transportError(url, res, String(error));
210
216
  }
211
217
  }
212
218
  const raw = await res.text();
213
219
  const parsed = HttpClient.#parseJson(raw);
214
- if (parsed === undefined) throw this.#transportError(res, raw);
220
+ if (parsed === undefined) throw this.#transportError(url, res, raw);
215
221
  return parsed;
216
222
  }
217
223
 
@@ -223,11 +229,33 @@ export class HttpClient {
223
229
  }
224
230
  }
225
231
 
226
- #transportError(res: Response, detail: string): RestoredError {
232
+ #transportError(url: string, res: Response, detail: string): RestoredError {
227
233
  const { status } = res;
228
234
  const error = transportErrorKeyMap[status as keyof typeof transportErrorKeyMap] ?? unexpectedResponseKey;
229
235
  const data = status === 429 ? { status, seconds: HttpClient.#retryAfterSeconds(res) } : { status };
230
- return this.#restoreError({ error, data, details: detail.slice(0, transportDetailLimit) }, status);
236
+ return this.#transportFailure(url, { error, data, details: detail.slice(0, transportDetailLimit) }, status);
237
+ }
238
+
239
+ #transportFailure(url: string, body: ErrorResponsePayload, status: number): RestoredError {
240
+ if (typeof window === "undefined")
241
+ HttpClient.#logger.warn(`${body.error} from ${HttpClient.#originAndPath(url)}: ${JSON.stringify(body.details)}`);
242
+ const error = this.#restoreError(body, status);
243
+ const toJSON = error.toJSON?.bind(error);
244
+ if (toJSON)
245
+ error.toJSON = () => {
246
+ const { details: _local, ...wire } = toJSON();
247
+ return wire;
248
+ };
249
+ return error;
250
+ }
251
+
252
+ static #originAndPath(url: string) {
253
+ try {
254
+ const { origin, pathname } = new URL(url);
255
+ return `${origin}${pathname}`;
256
+ } catch {
257
+ return url.split("?")[0];
258
+ }
231
259
  }
232
260
 
233
261
  static #retryAfterSeconds(res: Response): number {
@@ -63,9 +63,8 @@ export class SliceInitHandle {
63
63
 
64
64
  #serverInitOf(modelObjList: BaseObject[], modelObjInsight: BaseInsight | null) {
65
65
  const { refName, capRefName, sliceName, argLength, queryArgs, page, limit, sort } = this.#input;
66
- const lastPage = modelObjInsight?.count
67
- ? Math.max(Math.floor((modelObjInsight.count - 1) / (limit || 20)) + 1, 1)
68
- : 1;
66
+ const lastPage =
67
+ modelObjInsight?.count && limit > 0 ? Math.max(Math.floor((modelObjInsight.count - 1) / limit) + 1, 1) : 1;
69
68
  this.#serverInit ??= {
70
69
  refName,
71
70
  sliceName,
@@ -302,7 +302,9 @@ export class WsClient {
302
302
  if (Date.now() - this.#lastInboundAt > websocketHeartbeatContract.silenceMs) {
303
303
  this.logger.warn(`WebSocket is silent, reconnecting`);
304
304
  this.#stopHeartbeat();
305
- ws.close();
305
+
306
+ if ("terminate" in ws) (ws as unknown as Bun.WebSocket).terminate();
307
+ else ws.close();
306
308
  return;
307
309
  }
308
310
  ws.send(JSON.stringify(websocketHeartbeatContract.makeRequest()));
@@ -14,15 +14,17 @@ import type {
14
14
  SliceCls,
15
15
  } from "akanjs/signal";
16
16
 
17
- type ExtendedEndpointReturn<ClientReturns, Full, Light, Insight> = ClientReturns extends (infer R)[]
18
- ? ExtendedEndpointReturn<R, Full, Light, Insight>[]
19
- : Full extends ClientReturns
20
- ? Full
21
- : Light extends ClientReturns
22
- ? Light
23
- : Insight extends ClientReturns
24
- ? Insight
25
- : ClientReturns;
17
+ type ExtendedEndpointReturn<ClientReturns, Full, Light, Insight> = unknown extends ClientReturns
18
+ ? ClientReturns
19
+ : ClientReturns extends (infer R)[]
20
+ ? ExtendedEndpointReturn<R, Full, Light, Insight>[]
21
+ : Full extends ClientReturns
22
+ ? Full
23
+ : Light extends ClientReturns
24
+ ? Light
25
+ : Insight extends ClientReturns
26
+ ? Insight
27
+ : ClientReturns;
26
28
 
27
29
  type EndpointClientReturns<E, SlceCls extends SliceCls | never> = [SlceCls] extends [never]
28
30
  ? EndpInfoClientReturns<E>
package/fetch/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./agentTurn";
2
+ export * from "./appScope";
2
3
  export * from "./client";
3
4
  export * from "./fetchType";
4
5
  export * from "./requestStorage";
package/index.ts CHANGED
@@ -601,6 +601,8 @@ export interface AppInfo {
601
601
  readonly service: Map<string, Set<string>>;
602
602
  readonly scalar: Map<string, Set<string>>;
603
603
  readonly file: FileConventionScanSets;
604
+ /** `script/migration/*.ts` by id, each with its source's sha256. */
605
+ readonly migrations: readonly { id: string; checksum: string }[];
604
606
  getLibs(): string[];
605
607
  getLibInfos(): Map<string, LibInfo>;
606
608
  getDatabaseModules(): string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "3.1.0-rc.8",
3
+ "version": "3.1.0",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -225,34 +225,44 @@
225
225
  "types": "./types/server/hmr/runtimeMetadataFile.d.ts",
226
226
  "import": "./server/hmr/runtimeMetadataFile.ts",
227
227
  "default": "./server/hmr/runtimeMetadataFile.ts"
228
+ },
229
+ "./server/migration/migrationCommand": {
230
+ "types": "./types/server/migration/migrationCommand.d.ts",
231
+ "import": "./server/migration/migrationCommand.ts",
232
+ "default": "./server/migration/migrationCommand.ts"
233
+ },
234
+ "./server/migration/migrationError": {
235
+ "types": "./types/server/migration/migrationError.d.ts",
236
+ "import": "./server/migration/migrationError.ts",
237
+ "default": "./server/migration/migrationError.ts"
228
238
  }
229
239
  },
230
240
  "dependencies": {
231
- "@lexical/plain-text": "^0.51.0",
241
+ "@lexical/plain-text": "^0.52.0",
232
242
  "@noble/ciphers": "^2.4.0",
233
- "dayjs": "^1.11.20",
234
- "immer": "^11.1.8",
235
- "lexical": "^0.51.0",
236
- "tailwind-merge": "^3.3.1",
237
- "tailwind-variants": "^3.3.0"
243
+ "dayjs": "^1.11.23",
244
+ "immer": "^11.1.21",
245
+ "lexical": "^0.52.0",
246
+ "tailwind-merge": "^3.7.0",
247
+ "tailwind-variants": "^3.3.1"
238
248
  },
239
249
  "peerDependencies": {
240
- "@happy-dom/global-registrator": "^20.11.2",
241
- "@playwright/test": "^1.60.0",
242
- "@react-spring/web": "^10.1.0",
250
+ "@happy-dom/global-registrator": "^21.0.3",
251
+ "@playwright/test": "^1.64.1",
252
+ "@react-spring/web": "^10.1.2",
243
253
  "@use-gesture/react": "^10.3.1",
244
- "bullmq": "^5.76.10",
254
+ "bullmq": "^5.81.5",
245
255
  "chance": "^1.1.13",
246
- "firebase": "^12.13.0",
247
- "happy-dom": "^20.11.2",
248
- "ioredis": "^5.10.1",
256
+ "firebase": "^13.0.0",
257
+ "happy-dom": "^21.0.3",
258
+ "ioredis": "^5.11.1",
249
259
  "postgres": "^3.4.9",
250
- "protobufjs": "^8.4.0",
251
- "react": "19.3.0",
252
- "react-dom": "19.3.0",
253
- "react-icons": "^5.6.0",
260
+ "protobufjs": "^8.8.1",
261
+ "react": "19.3.1",
262
+ "react-dom": "19.3.1",
263
+ "react-icons": "^5.7.0",
254
264
  "react-refresh": "^0.19.0",
255
- "react-server-dom-webpack": "^19.3.0",
265
+ "react-server-dom-webpack": "19.3.1",
256
266
  "react-spring": "^10.0.4",
257
267
  "scheduler": "^0.28.0",
258
268
  "tailwind-scrollbar": "^4.0.2",
@@ -321,14 +331,14 @@
321
331
  }
322
332
  },
323
333
  "devDependencies": {
324
- "@biomejs/biome": "2.5.12",
325
- "@types/bun": "^1.4.2"
334
+ "@biomejs/biome": "2.5.14",
335
+ "@types/bun": "^1.4.4"
326
336
  },
327
337
  "bun": {
328
338
  "platform": "bun"
329
339
  },
330
340
  "engines": {
331
- "bun": ">=1.4.0"
341
+ "bun": ">=1.4.4"
332
342
  },
333
343
  "main": "./index.ts"
334
344
  }
package/server/akanApp.ts CHANGED
@@ -19,6 +19,7 @@ import { LogHub } from "./logging/logHub";
19
19
  import { LogStreamRoute } from "./logging/logStreamRoute";
20
20
  import { RotatingLogWriter } from "./logging/rotatingLogWriter";
21
21
  import { AppInfo } from "./ops/appInfo";
22
+ import type { OpsHost } from "./ops/opsCommand";
22
23
  import type { OpsRoute } from "./ops/opsRoute";
23
24
  import { ProcessMetricsCollector } from "./processMetricsCollector";
24
25
  import { HostAllowlist } from "./routing/hostAllowlist";
@@ -108,7 +109,7 @@ export class AkanApp {
108
109
  readonly #devHosted = process.env.AKAN_COMMAND_TYPE === "start";
109
110
  readonly #healthTimeoutMs = AkanApp.#parseHealthTimeoutMs();
110
111
  readonly #upstreamWaitMs = AkanApp.#parseUpstreamWaitMs();
111
- /** Child stderr is bundler/runtime noise the gateway cannot act on; it still reaches the rotating log file. */
112
+ /** Child stderr is mostly bundler/runtime noise, kept to the log file; with none it may be a crash's only trace. */
112
113
  readonly #printChildStderr = process.env.AKAN_CHILD_STDERR === "1";
113
114
  readonly #serverPath: string;
114
115
  readonly #artifactDir: string;
@@ -238,7 +239,9 @@ export class AkanApp {
238
239
  async start() {
239
240
  if (process.argv[2] === "ops") {
240
241
  const { OpsCommand } = await import("./ops/opsCommand");
241
- process.exit(await OpsCommand.run(process.argv.slice(3)));
242
+ process.exit(
243
+ await OpsCommand.run(process.argv.slice(3), { importServer: async () => await this.#importServer() }),
244
+ );
242
245
  }
243
246
  if (this.#solo) return await this.#startSolo();
244
247
  if (SelfExec.carried)
@@ -274,6 +277,12 @@ export class AkanApp {
274
277
  });
275
278
  }
276
279
 
280
+ async #importServer() {
281
+ Object.assign(process.env, this.#childEnv(0, this.#getRole(0)), { AKAN_COMMAND_TYPE: "script" });
282
+ resetEnvCache();
283
+ return (await import(this.#serverPath)) as Awaited<ReturnType<OpsHost["importServer"]>>;
284
+ }
285
+
277
286
  async #startSolo() {
278
287
  const role = this.#getRole(0);
279
288
 
@@ -1328,7 +1337,7 @@ export class AkanApp {
1328
1337
  return;
1329
1338
  }
1330
1339
  const prefixedLine = `[child:${idx} ${role}] [${type}] ${line}`;
1331
- if (type === "stdout" || this.#printChildStderr) process[type].write(prefixedLine);
1340
+ if (type === "stdout" || this.#printChildStderr || !this.#logWriter) process[type].write(prefixedLine);
1332
1341
  this.#logWriter?.write(`${idx}-${role}`, AkanApp.#stripAnsi(prefixedLine));
1333
1342
  }
1334
1343
 
@@ -66,7 +66,10 @@ export interface AkanServerProps extends AkanLibProps {
66
66
 
67
67
  export interface AkanServerOptions {
68
68
  openapi?: boolean;
69
- /** `/mcp` is mounted by default; `false` takes it off, and the object form carries the rest of its settings. */
69
+ /**
70
+ * `/mcp` is mounted by default, on an edge server only when asked for here or by `AKAN_MCP=true`; `false` takes it
71
+ * off, and the object form carries the rest of its settings.
72
+ */
70
73
  mcp?: boolean | McpServerOption;
71
74
  /** Boot only these modules and what they reach; omitted or empty mounts every enabled module. */
72
75
  modules?: string[];
@@ -107,13 +110,15 @@ export interface McpServerOption {
107
110
  /** Characters a page prompt may attach before its lists are cut; 60,000 by default. `AKAN_MCP_PROMPT_BUDGET`. */
108
111
  promptBudget?: number;
109
112
  /**
110
- * MCP Apps: a `.prompt()` page is a tool as well, whose result a host speaking the extension renders from the CSR
111
- * shell; an endpoint kept off the shelf by `mcp: false` stays callable by that view. `true` by default. `AKAN_MCP_APPS`.
113
+ * MCP Apps: each `.app()` is a read-only tool whose result a host speaking the extension draws with that app's own
114
+ * view, and a `.prompt()` page a text tool; an endpoint kept off the shelf by `mcp: false` stays callable by a view.
115
+ * `false` publishes no page tools. `true` by default. `AKAN_MCP_APPS`.
112
116
  */
113
117
  apps?: boolean;
114
118
  /**
115
- * Speak the modern `2026-07-28` revision (`server/discover`) beside the legacy ones. On unless MCP Apps renders views,
116
- * since claude.ai renders a view only for a server it reached through `initialize`. `AKAN_MCP_MODERN`.
119
+ * Speak the modern `2026-07-28` revision (`server/discover`) beside the legacy ones. On unless the build serves views
120
+ * and a page declares `.app()`, since claude.ai renders a view only for a server it reached through `initialize`.
121
+ * `AKAN_MCP_MODERN`.
117
122
  */
118
123
  modern?: boolean;
119
124
  }
package/server/index.ts CHANGED
@@ -8,6 +8,7 @@ export * from "./decorators";
8
8
  export * from "./devtools";
9
9
  export type { ChangeBatch, ChangeKind } from "./hmr/wsHub";
10
10
  export * from "./machine";
11
+ export * from "./migration";
11
12
  export * from "./nativeFile";
12
13
  export * from "./oauth";
13
14
  export * from "./processMetricsCollector";
@@ -14,23 +14,29 @@ import {
14
14
  import type { PagePromptEntry, PagePromptRecord, PagePromptRun } from "../../signal/mcp/pagePrompt";
15
15
  import { McpAppShell } from "./McpAppShell";
16
16
 
17
- /** The CSR shell a view boots from: one single-file HTML per basePath, read from the build that serves the web. */
17
+ /** The single-file view each `.app()` boots from, read from the build that serves the web. */
18
18
  export interface McpAppShellSource {
19
- readonly basePaths: readonly string[];
20
- /** `""` is the app without a basePath; `null` when this build has no single-file shell for it. */
21
- read(basePath: string): Promise<string | null>;
19
+ /** `null` when this build has no view for the app. */
20
+ read(app: string): Promise<string | null>;
21
+ }
22
+
23
+ interface McpAppsOption {
24
+ /** Every write the view sends is refused before it leaves, as the deployment lists no write to relay it to. */
25
+ readOnly?: boolean;
22
26
  }
23
27
 
24
28
  export class McpApps {
25
29
  static readonly scheme = "ui://";
26
-
27
- static readonly rootSegment = "app";
28
30
  static readonly #tokenClaims = new Set(["iss", "aud", "exp", "nbf", "iat", "jti", "client_id", "scope"]);
31
+
32
+ static readonly #appUri = /^ui:\/\/([^/]+)\/apps\/([A-Za-z0-9_-]{1,64})$/;
29
33
 
30
34
  readonly #shell: McpAppShellSource | null;
35
+ readonly #readOnly: boolean;
31
36
 
32
- constructor(shell: McpAppShellSource | null) {
37
+ constructor(shell: McpAppShellSource | null, { readOnly = false }: McpAppsOption = {}) {
33
38
  this.#shell = shell;
39
+ this.#readOnly = readOnly;
34
40
  }
35
41
 
36
42
  get rendersUi() {
@@ -53,18 +59,19 @@ export class McpApps {
53
59
  ]),
54
60
  );
55
61
  const required = entry.arguments.filter((arg) => arg.required).map((arg) => arg.name);
62
+ const inputSchema = {
63
+ type: "object" as const,
64
+ properties,
65
+ ...(required.length ? { required } : {}),
66
+ additionalProperties: false,
67
+ };
68
+ const tool = { name: entry.name, description: entry.description, inputSchema };
69
+
70
+ if (entry.kind === "prompt") return { ...tool, annotations: { readOnlyHint: false, openWorldHint: false } };
56
71
  return {
57
- name: entry.name,
58
- description: entry.description,
59
- inputSchema: {
60
- type: "object",
61
- properties,
62
- ...(required.length ? { required } : {}),
63
- additionalProperties: false,
64
- },
65
-
66
- annotations: { readOnlyHint: false, openWorldHint: false },
67
- ...(this.#shell ? { _meta: this.#toolMetaOf(this.uriOf(this.#basePathOf(entry.pattern))) } : {}),
72
+ ...tool,
73
+ annotations: { readOnlyHint: true, openWorldHint: false },
74
+ ...(this.#shell ? { _meta: this.#toolMetaOf(this.uriOf(entry.name)) } : {}),
68
75
  };
69
76
  }
70
77
 
@@ -74,30 +81,30 @@ export class McpApps {
74
81
 
75
82
  resourcesOf(entries: PagePromptEntry[]): McpResource[] {
76
83
  if (!this.#shell) return [];
77
- const { appName } = getEnv();
78
- const basePaths = [...new Set(entries.map((entry) => this.#basePathOf(entry.pattern)))];
79
- return basePaths.map((basePath) => ({
80
- uri: this.uriOf(basePath),
81
- name: basePath || appName,
82
- description: `The ${basePath || appName} screens, rendered in place of a tool result.`,
83
- mimeType: MCP_UI_MIME_TYPE,
84
- }));
84
+ return entries
85
+ .filter((entry) => entry.kind === "app")
86
+ .map((entry) => ({
87
+ uri: this.uriOf(entry.name),
88
+ name: entry.name,
89
+ description: entry.description,
90
+ mimeType: MCP_UI_MIME_TYPE,
91
+ }));
85
92
  }
86
93
 
87
- uriOf(basePath: string) {
88
- const root = `${McpApps.scheme}${getEnv().appName.toLowerCase()}/${McpApps.rootSegment}`;
89
- return basePath ? `${root}/${basePath}` : root;
94
+ uriOf(app: string) {
95
+ return `${McpApps.scheme}${getEnv().appName.toLowerCase()}/apps/${app}`;
90
96
  }
91
97
 
92
98
  async read(uri: string, origin: string): Promise<McpResourceContents | null> {
93
- const shell = this.#shell;
94
- const basePath = shell ? this.#basePathOfUri(uri) : null;
95
- if (!shell || basePath === null) return null;
96
- const html = await shell.read(basePath);
99
+ const match = McpApps.#appUri.exec(uri);
100
+ const app = match?.[1]?.toLowerCase() === getEnv().appName.toLowerCase() ? match[2] : undefined;
101
+ if (!this.#shell || !app) return null;
102
+ const html = await this.#shell.read(app);
97
103
  return html ? McpAppShell.contentsOf(uri, html, origin) : null;
98
104
  }
99
105
 
100
106
  resultOf(
107
+ entry: PagePromptEntry,
101
108
  run: Extract<PagePromptRun, { ok: true }>,
102
109
  messages: PromptMessage[],
103
110
  webOrigin: string,
@@ -107,14 +114,15 @@ export class McpApps {
107
114
  const href = `${url.pathname}${url.search}`;
108
115
  const content: PromptContent[] = [
109
116
  ...messages.map((message) => message.content),
110
- { type: "text", text: `Open this screen in a browser: ${webOrigin}${href}` },
117
+ { type: "text", text: `Open the full screen: ${webOrigin}${href}` },
111
118
  ];
112
- if (!this.#shell || !forView) return { content, isError: false };
119
+ if (entry.kind === "prompt" || !this.#shell || !forView) return { content, isError: false };
113
120
  const _meta = {
114
121
  [MCP_APP_META.snapshot]: McpApps.#snapshotOf(run.records),
115
122
  [MCP_APP_META.account]: forView.account,
123
+ ...(this.#readOnly ? { [MCP_APP_META.readOnly]: true } : {}),
116
124
  };
117
- return { content, structuredContent: { href }, _meta, isError: false };
125
+ return { content, structuredContent: { href, ...run.route }, _meta, isError: false };
118
126
  }
119
127
 
120
128
  static accountOf(req: Request): Record<string, unknown> | null {
@@ -128,20 +136,6 @@ export class McpApps {
128
136
  }
129
137
  }
130
138
 
131
- #basePathOf(pattern: string) {
132
- const [, , segment] = pattern.split("/");
133
- return segment && this.#shell?.basePaths.includes(segment) ? segment : "";
134
- }
135
-
136
- #basePathOfUri(uri: string) {
137
- const match = /^ui:\/\/([^/]+)\/([^?#]*)$/i.exec(uri);
138
- if (!match || match[1]?.toLowerCase() !== getEnv().appName.toLowerCase()) return null;
139
- const [root, basePath, ...rest] = (match[2] ?? "").split("/");
140
- if (root !== McpApps.rootSegment || rest.length) return null;
141
- if (!basePath) return "";
142
- return this.#shell?.basePaths.includes(basePath) ? basePath : null;
143
- }
144
-
145
139
  static #snapshotOf(records: PagePromptRecord[]): McpAppSnapshotRecord[] {
146
140
  return records.flatMap(({ key, args, value }) => (value === undefined ? [] : [{ key, args, value }]));
147
141
  }
@@ -72,7 +72,8 @@ export class McpDispatcher {
72
72
  }
73
73
 
74
74
  static #restorable(error: unknown, status: number | undefined) {
75
- if (!status || status >= 500 || status === 401 || status === 403 || error instanceof NoDocumentError) return null;
75
+ if (!status || status >= 500) return null;
76
+ if (status === 401 || status === 403) return { statusCode: status };
76
77
  return isExceptionLike(error) ? error.toJSON() : null;
77
78
  }
78
79
 
@@ -169,8 +170,7 @@ export class McpDispatcher {
169
170
  }
170
171
 
171
172
  static #statusOf(error: unknown): number | undefined {
172
- if (isExceptionLike(error) || error instanceof McpArgumentError || error instanceof NoDocumentError)
173
- return error.statusCode;
173
+ if (isExceptionLike(error) || error instanceof McpArgumentError) return error.statusCode;
174
174
  return undefined;
175
175
  }
176
176