akanjs 3.3.0-rc.2 → 3.3.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 (433) hide show
  1. package/ARCHITECTURE.md +3 -2
  2. package/CHANGELOG.md +391 -23
  3. package/CONTRIBUTING.md +2 -2
  4. package/README.ko.md +40 -296
  5. package/README.md +41 -297
  6. package/client/appOpenedTab.ts +12 -0
  7. package/client/clientRuntime.ts +3 -10
  8. package/client/cn.ts +4 -4
  9. package/client/cookie.ts +15 -6
  10. package/client/csrTypes.ts +17 -0
  11. package/client/device.ts +43 -3
  12. package/client/frameConfig.ts +27 -6
  13. package/client/index.ts +12 -6
  14. package/client/keyboardRide.ts +124 -0
  15. package/client/router.ts +6 -3
  16. package/client/rscNavigation.ts +0 -7
  17. package/client/scriptPolicy.ts +14 -0
  18. package/common/CodeTranscript.ts +4 -2
  19. package/common/Logger.ts +4 -1
  20. package/common/TraceContext.ts +97 -0
  21. package/common/TrustedProxy.ts +10 -0
  22. package/common/codeAgentProfile.ts +1 -1
  23. package/common/codeAgentWire.ts +7 -2
  24. package/common/index.ts +1 -0
  25. package/common/inlineToken.ts +26 -0
  26. package/common/logContext.ts +1 -0
  27. package/common/sessionTokenContract.ts +7 -0
  28. package/constant/index.ts +0 -1
  29. package/constant/types.ts +0 -2
  30. package/document/documentSchema.ts +0 -3
  31. package/document/filterMeta.ts +3 -16
  32. package/fetch/client/fetchClient.ts +8 -17
  33. package/fetch/client/httpClient.ts +22 -12
  34. package/fetch/client/wsClient.ts +10 -6
  35. package/fetch/requestStorage.ts +30 -0
  36. package/index.ts +8 -0
  37. package/package.json +263 -57
  38. package/server/SSR_MEMORY_DIAGNOSIS.md +88 -1
  39. package/server/admissionQueue.ts +107 -0
  40. package/server/akanApp.ts +39 -14
  41. package/server/akanAppHeaders.ts +20 -6
  42. package/server/akanOption.ts +28 -0
  43. package/server/akanServer.ts +13 -1
  44. package/server/assetHeaders.ts +8 -3
  45. package/server/cachePolicy.ts +2 -1
  46. package/server/clientErrorReport.ts +191 -0
  47. package/server/clientReportId.ts +54 -0
  48. package/server/console.ts +5 -12
  49. package/server/devtools/README.md +15 -3
  50. package/server/devtools/devtoolsAccess.ts +119 -0
  51. package/server/devtools/devtoolsRouter.ts +30 -26
  52. package/server/devtools/devtoolsUnlockPage.ts +38 -0
  53. package/server/devtools/signalSerializer.ts +18 -1
  54. package/server/devtools/studio/studioDocument.tsx +3 -1
  55. package/server/devtools/studio/studioRoute.ts +4 -1
  56. package/server/devtools/types.ts +6 -0
  57. package/server/flightSanitizeRecorded.fixture.json +36 -34
  58. package/server/forwardedError.ts +43 -0
  59. package/server/gateway/gatewayChildren.ts +3 -0
  60. package/server/gateway/gatewayConfig.ts +5 -0
  61. package/server/gateway/gatewayHttpProxy.ts +10 -2
  62. package/server/gateway/gatewayStatus.ts +21 -1
  63. package/server/gateway/gatewayStatusPage.ts +18 -11
  64. package/server/headSplice.ts +73 -0
  65. package/server/hmr/clientReport.ts +9 -9
  66. package/server/hmr/csrDevShell.ts +7 -4
  67. package/server/htmlResultCache.ts +81 -14
  68. package/server/imageOptimizer.ts +44 -12
  69. package/server/index.ts +2 -4
  70. package/server/lifecycle/secretEnv.ts +98 -0
  71. package/server/lifecycle/shutdownManager.ts +6 -0
  72. package/server/logging/logForwarder.ts +2 -2
  73. package/server/logging/logQuery.ts +9 -1
  74. package/server/mcp/McpDispatcher.ts +13 -10
  75. package/server/metrics/metricAggregate.ts +27 -0
  76. package/server/metrics/metricExposition.ts +92 -0
  77. package/server/metrics/metricMerge.ts +81 -0
  78. package/server/metrics/metricRegistry.ts +271 -0
  79. package/server/metrics/pubsubGauges.ts +20 -0
  80. package/server/metrics/requestMetrics.ts +110 -0
  81. package/server/metrics/runtimeFamilies.ts +61 -0
  82. package/server/metrics/slowStatementLog.ts +63 -0
  83. package/server/metrics/statementMetrics.ts +259 -0
  84. package/server/metrics/statementPlanCheck.ts +141 -0
  85. package/server/metrics/statementReport.ts +105 -0
  86. package/server/migration/migrationRunner.ts +13 -10
  87. package/server/oauth/OAuthErrors.ts +5 -1
  88. package/server/ops/statusAccess.ts +23 -3
  89. package/server/otlp/otlpBatcher.ts +221 -0
  90. package/server/otlp/otlpConfig.ts +185 -0
  91. package/server/otlp/otlpEncode.ts +114 -0
  92. package/server/otlp/otlpExporter.ts +98 -0
  93. package/server/otlp/otlpSampler.ts +50 -0
  94. package/server/pageFailure.ts +33 -0
  95. package/server/processMetricsCollector.ts +1 -0
  96. package/server/renderBusyResponse.ts +97 -0
  97. package/server/reportText.ts +27 -0
  98. package/server/resolver/databaseModelInstance.ts +21 -19
  99. package/server/resolver/httpEndpointHandler.ts +43 -0
  100. package/server/resolver/jobTrace.ts +18 -0
  101. package/server/resolver/modelFacade.ts +24 -18
  102. package/server/resolver/modelLoaders.ts +10 -3
  103. package/server/resolver/signal.resolver.ts +28 -31
  104. package/server/resolver/timedQuery.ts +8 -4
  105. package/server/routeCacheQuery.ts +58 -0
  106. package/server/routeCacheTally.ts +65 -0
  107. package/server/routeElementComposer.tsx +16 -0
  108. package/server/routeTreeBuilder.ts +6 -0
  109. package/server/routing/apiRouter.ts +34 -11
  110. package/server/routing/appWsData.ts +4 -0
  111. package/server/routing/builtinRoutes.ts +4 -1
  112. package/server/routing/devRoutes.ts +50 -0
  113. package/server/routing/devSurfacePolicy.ts +40 -0
  114. package/server/routing/devSurfaces.ts +101 -0
  115. package/server/routing/hostAllowlist.ts +2 -0
  116. package/server/routing/roomReplay.ts +4 -0
  117. package/server/routing/serverListener.ts +13 -0
  118. package/server/routing/soloAppRoutes.ts +14 -1
  119. package/server/rscClient.tsx +6 -1
  120. package/server/rscClientChunks.ts +8 -1
  121. package/server/rscClientErrorSender.ts +77 -0
  122. package/server/rscClientErrors.ts +26 -0
  123. package/server/rscFirstRenderMemory.ts +49 -0
  124. package/server/rscFlightRenderer.ts +21 -4
  125. package/server/rscFlightStream.ts +2 -2
  126. package/server/rscHostRenderStream.ts +5 -3
  127. package/server/rscHostRequests.ts +17 -3
  128. package/server/rscRenderAdmission.ts +130 -0
  129. package/server/rscRenderControl.ts +2 -1
  130. package/server/rscRenderHandler.ts +112 -31
  131. package/server/rscRenderLevels.ts +40 -0
  132. package/server/rscRenderRefusal.ts +23 -0
  133. package/server/rscRenderStats.ts +3 -0
  134. package/server/rscResultCaches.ts +20 -2
  135. package/server/rscWorker.tsx +25 -5
  136. package/server/rscWorkerCache.ts +2 -0
  137. package/server/rscWorkerHost.ts +35 -4
  138. package/server/rscWorkerProcess.ts +12 -0
  139. package/server/rscWorkerRecycler.ts +3 -3
  140. package/server/scriptPolicy.ts +128 -0
  141. package/server/serverConfig.ts +11 -0
  142. package/server/serverMetrics.ts +34 -1
  143. package/server/sitemap.ts +0 -5
  144. package/server/ssrFromRscRenderer.tsx +32 -204
  145. package/server/ssrInlineScripts.ts +195 -0
  146. package/server/ssrTypes.ts +15 -2
  147. package/server/systemPageDocument.tsx +6 -2
  148. package/server/systemPages.tsx +9 -4
  149. package/server/webCsrSurface.ts +55 -21
  150. package/server/webDocumentRoute.ts +47 -21
  151. package/server/webRouteContext.ts +25 -8
  152. package/server/webRouter.ts +15 -12
  153. package/server/webRscRoute.ts +18 -14
  154. package/service/agent.service.ts +34 -8
  155. package/service/agentLoop/agentLoop.ts +35 -24
  156. package/service/agentLoop/agentLoopTypes.ts +16 -7
  157. package/service/agentLoop/loopCompaction.ts +1 -1
  158. package/service/agentLoop/loopContext.ts +33 -0
  159. package/service/agentLoop/loopToolkits.ts +17 -8
  160. package/service/index.ts +0 -1
  161. package/service/ipcTypes.ts +56 -0
  162. package/service/mentionToken.ts +44 -0
  163. package/service/predefinedAdaptor/anthropicLlm.ts +18 -17
  164. package/service/predefinedAdaptor/database.adaptor.ts +43 -9
  165. package/service/predefinedAdaptor/directoryNotWritableError.ts +30 -0
  166. package/service/predefinedAdaptor/index.ts +1 -0
  167. package/service/predefinedAdaptor/llm.adaptor.ts +9 -3
  168. package/service/predefinedAdaptor/llmContext.ts +26 -0
  169. package/service/predefinedAdaptor/llmFence.ts +55 -0
  170. package/service/predefinedAdaptor/openaiDialect.ts +45 -18
  171. package/service/predefinedAdaptor/solidSqlite.ts +2 -0
  172. package/service/predefinedAdaptor/sql/driver/bunSqlite.ts +49 -11
  173. package/service/predefinedAdaptor/sql/driver/postgres.ts +47 -10
  174. package/service/predefinedAdaptor/sql/statementFingerprint.ts +117 -0
  175. package/service/predefinedAdaptor/sql/statementPlans.ts +71 -0
  176. package/service/predefinedAdaptor/sql/statementProbe.ts +110 -0
  177. package/service/predefinedAdaptor/sql/statementScrub.ts +149 -0
  178. package/service/predefinedAdaptor/storage.adaptor.ts +5 -0
  179. package/service/predefinedAdaptor/websocket.adaptor.ts +6 -0
  180. package/signal/CrossSiteGuard.ts +5 -0
  181. package/signal/SignalFailure.ts +24 -2
  182. package/signal/browserError.ts +24 -0
  183. package/signal/errorReporting.ts +168 -0
  184. package/signal/httpPeer.ts +9 -0
  185. package/signal/index.ts +2 -3
  186. package/signal/openapi/openapi.ts +4 -0
  187. package/signal/requestTrace.ts +124 -0
  188. package/signal/signalContext.ts +15 -22
  189. package/signal/spanExport.ts +137 -0
  190. package/signal/trace.ts +168 -37
  191. package/store/agent/AgentBridge.ts +6 -2
  192. package/store/agent/AgentContext.ts +81 -14
  193. package/store/agent/AgentInline.ts +72 -0
  194. package/store/agent/StoreSurfaceSource.ts +2 -1
  195. package/store/baseSt.ts +0 -6
  196. package/store/index.ts +1 -3
  197. package/store/stateBuilder.ts +1 -6
  198. package/types/client/appOpenedTab.d.ts +1 -0
  199. package/types/client/clientRuntime.d.ts +4 -2
  200. package/types/client/cn.d.ts +0 -4
  201. package/types/client/cookie.d.ts +4 -3
  202. package/types/client/csrTypes.d.ts +20 -0
  203. package/types/client/device.d.ts +8 -0
  204. package/types/client/frameConfig.d.ts +1 -3
  205. package/types/client/index.d.ts +7 -7
  206. package/types/client/keyboardRide.d.ts +16 -0
  207. package/types/client/rscNavigation.d.ts +0 -10
  208. package/types/client/scriptPolicy.d.ts +4 -0
  209. package/types/common/CodeTranscript.d.ts +1 -0
  210. package/types/common/Logger.d.ts +2 -0
  211. package/types/common/TraceContext.d.ts +28 -0
  212. package/types/common/TrustedProxy.d.ts +1 -0
  213. package/types/common/codeAgentWire.d.ts +10 -2
  214. package/types/common/index.d.ts +1 -0
  215. package/types/common/inlineToken.d.ts +5 -0
  216. package/types/common/logContext.d.ts +1 -0
  217. package/types/common/sessionTokenContract.d.ts +6 -0
  218. package/types/constant/index.d.ts +1 -1
  219. package/types/constant/types.d.ts +0 -2
  220. package/types/document/documentSchema.d.ts +0 -2
  221. package/types/document/filterMeta.d.ts +0 -13
  222. package/types/fetch/client/fetchClient.d.ts +1 -4
  223. package/types/fetch/client/httpClient.d.ts +2 -5
  224. package/types/fetch/client/wsClient.d.ts +3 -3
  225. package/types/fetch/requestStorage.d.ts +9 -0
  226. package/types/index.d.ts +12 -0
  227. package/types/server/admissionQueue.d.ts +26 -0
  228. package/types/server/akanAppHeaders.d.ts +3 -1
  229. package/types/server/akanOption.d.ts +16 -1
  230. package/types/server/assetHeaders.d.ts +5 -3
  231. package/types/server/cachePolicy.d.ts +2 -0
  232. package/types/server/clientErrorReport.d.ts +27 -0
  233. package/types/server/clientReportId.d.ts +9 -0
  234. package/types/server/console.d.ts +0 -7
  235. package/types/server/devtools/devtoolsAccess.d.ts +12 -0
  236. package/types/server/devtools/devtoolsRouter.d.ts +0 -1
  237. package/types/server/devtools/devtoolsUnlockPage.d.ts +11 -0
  238. package/types/server/devtools/signalSerializer.d.ts +3 -1
  239. package/types/server/devtools/studio/studioDocument.d.ts +1 -0
  240. package/types/server/devtools/types.d.ts +5 -0
  241. package/types/server/forwardedError.d.ts +13 -0
  242. package/types/server/gateway/gatewayChildren.d.ts +2 -0
  243. package/types/server/gateway/gatewayConfig.d.ts +1 -0
  244. package/types/server/gateway/gatewayHttpProxy.d.ts +1 -0
  245. package/types/server/gateway/gatewayStatus.d.ts +2 -0
  246. package/types/server/headSplice.d.ts +11 -0
  247. package/types/server/hmr/clientReport.d.ts +2 -0
  248. package/types/server/hmr/csrDevShell.d.ts +3 -1
  249. package/types/server/htmlResultCache.d.ts +13 -3
  250. package/types/server/index.d.ts +4 -3
  251. package/types/server/lifecycle/secretEnv.d.ts +23 -0
  252. package/types/server/logging/logForwarder.d.ts +1 -0
  253. package/types/server/logging/logStdoutWriter.d.ts +1 -0
  254. package/types/server/logging/rotatingLogWriter.d.ts +1 -1
  255. package/types/server/metrics/metricAggregate.d.ts +6 -0
  256. package/types/server/metrics/metricExposition.d.ts +8 -0
  257. package/types/server/metrics/metricMerge.d.ts +9 -0
  258. package/types/server/metrics/metricRegistry.d.ts +76 -0
  259. package/types/server/metrics/pubsubGauges.d.ts +5 -0
  260. package/types/server/metrics/requestMetrics.d.ts +22 -0
  261. package/types/server/metrics/runtimeFamilies.d.ts +9 -0
  262. package/types/server/metrics/slowStatementLog.d.ts +18 -0
  263. package/types/server/metrics/statementMetrics.d.ts +45 -0
  264. package/types/server/metrics/statementPlanCheck.d.ts +16 -0
  265. package/types/server/metrics/statementReport.d.ts +28 -0
  266. package/types/server/ops/statusAccess.d.ts +7 -1
  267. package/types/server/otlp/otlpBatcher.d.ts +18 -0
  268. package/types/server/otlp/otlpConfig.d.ts +25 -0
  269. package/types/server/otlp/otlpEncode.d.ts +13 -0
  270. package/types/server/otlp/otlpExporter.d.ts +18 -0
  271. package/types/server/otlp/otlpSampler.d.ts +10 -0
  272. package/types/server/pageFailure.d.ts +14 -0
  273. package/types/server/renderBusyResponse.d.ts +9 -0
  274. package/types/server/reportText.d.ts +4 -0
  275. package/types/server/resolver/httpEndpointHandler.d.ts +14 -0
  276. package/types/server/resolver/jobTrace.d.ts +5 -0
  277. package/types/server/resolver/modelLoaders.d.ts +3 -0
  278. package/types/server/resolver/timedQuery.d.ts +2 -1
  279. package/types/server/routeCacheQuery.d.ts +11 -0
  280. package/types/server/routeCacheTally.d.ts +23 -0
  281. package/types/server/routeElementComposer.d.ts +2 -0
  282. package/types/server/routing/appWsData.d.ts +3 -0
  283. package/types/server/routing/devRoutes.d.ts +9 -0
  284. package/types/server/routing/devSurfacePolicy.d.ts +12 -0
  285. package/types/server/routing/devSurfaces.d.ts +18 -0
  286. package/types/server/routing/hostAllowlist.d.ts +1 -0
  287. package/types/server/routing/roomReplay.d.ts +1 -0
  288. package/types/server/routing/serverListener.d.ts +2 -0
  289. package/types/server/routing/soloAppRoutes.d.ts +3 -1
  290. package/types/server/rscClient.d.ts +1 -0
  291. package/types/server/rscClientChunks.d.ts +3 -1
  292. package/types/server/rscClientErrorSender.d.ts +8 -0
  293. package/types/server/rscClientErrors.d.ts +3 -0
  294. package/types/server/rscFirstRenderMemory.d.ts +16 -0
  295. package/types/server/rscFlightStream.d.ts +1 -1
  296. package/types/server/rscHostRenderStream.d.ts +2 -1
  297. package/types/server/rscRenderAdmission.d.ts +14 -0
  298. package/types/server/rscRenderControl.d.ts +2 -1
  299. package/types/server/rscRenderHandler.d.ts +5 -2
  300. package/types/server/rscRenderLevels.d.ts +8 -0
  301. package/types/server/rscRenderRefusal.d.ts +9 -0
  302. package/types/server/rscRenderStats.d.ts +2 -0
  303. package/types/server/rscResultCaches.d.ts +8 -1
  304. package/types/server/rscWorkerCache.d.ts +2 -0
  305. package/types/server/rscWorkerHost.d.ts +2 -1
  306. package/types/server/rscWorkerProcess.d.ts +1 -0
  307. package/types/server/rscWorkerRecycler.d.ts +1 -1
  308. package/types/server/scriptPolicy.d.ts +31 -0
  309. package/types/server/serverConfig.d.ts +1 -0
  310. package/types/server/serverMetrics.d.ts +4 -1
  311. package/types/server/sitemap.d.ts +0 -2
  312. package/types/server/ssrFromRscRenderer.d.ts +2 -6
  313. package/types/server/ssrInlineScripts.d.ts +39 -0
  314. package/types/server/ssrTypes.d.ts +14 -2
  315. package/types/server/systemPageDocument.d.ts +3 -1
  316. package/types/server/systemPages.d.ts +2 -1
  317. package/types/server/webRouteContext.d.ts +7 -4
  318. package/types/server/webRouter.d.ts +2 -1
  319. package/types/service/agent.service.d.ts +3 -0
  320. package/types/service/agentLoop/agentLoopTypes.d.ts +16 -7
  321. package/types/service/agentLoop/loopContext.d.ts +13 -0
  322. package/types/service/agentLoop/loopToolkits.d.ts +1 -0
  323. package/types/service/index.d.ts +0 -1
  324. package/types/service/ipcTypes.d.ts +60 -0
  325. package/types/service/mentionToken.d.ts +13 -0
  326. package/types/service/predefinedAdaptor/anthropicLlm.d.ts +3 -3
  327. package/types/service/predefinedAdaptor/database.adaptor.d.ts +2 -0
  328. package/types/service/predefinedAdaptor/directoryNotWritableError.d.ts +6 -0
  329. package/types/service/predefinedAdaptor/index.d.ts +1 -0
  330. package/types/service/predefinedAdaptor/llm.adaptor.d.ts +9 -3
  331. package/types/service/predefinedAdaptor/llmContext.d.ts +11 -0
  332. package/types/service/predefinedAdaptor/llmFence.d.ts +15 -0
  333. package/types/service/predefinedAdaptor/openaiDialect.d.ts +3 -3
  334. package/types/service/predefinedAdaptor/sql/driver/bunSqlite.d.ts +3 -1
  335. package/types/service/predefinedAdaptor/sql/driver/postgres.d.ts +3 -1
  336. package/types/service/predefinedAdaptor/sql/statementFingerprint.d.ts +21 -0
  337. package/types/service/predefinedAdaptor/sql/statementPlans.d.ts +17 -0
  338. package/types/service/predefinedAdaptor/sql/statementProbe.d.ts +37 -0
  339. package/types/service/predefinedAdaptor/sql/statementScrub.d.ts +5 -0
  340. package/types/service/predefinedAdaptor/storage.adaptor.d.ts +1 -0
  341. package/types/service/predefinedAdaptor/websocket.adaptor.d.ts +3 -0
  342. package/types/signal/CrossSiteGuard.d.ts +1 -0
  343. package/types/signal/SignalFailure.d.ts +2 -0
  344. package/types/signal/browserError.d.ts +17 -0
  345. package/types/signal/errorReporting.d.ts +27 -0
  346. package/types/signal/httpPeer.d.ts +5 -0
  347. package/types/signal/index.d.ts +3 -1
  348. package/types/signal/requestTrace.d.ts +33 -0
  349. package/types/signal/signalContext.d.ts +2 -1
  350. package/types/signal/spanExport.d.ts +47 -0
  351. package/types/signal/trace.d.ts +33 -12
  352. package/types/store/agent/AgentBridge.d.ts +1 -0
  353. package/types/store/agent/AgentContext.d.ts +6 -2
  354. package/types/store/agent/AgentInline.d.ts +16 -0
  355. package/types/store/baseSt.d.ts +0 -2
  356. package/types/store/index.d.ts +2 -2
  357. package/types/store/stateBuilder.d.ts +0 -4
  358. package/types/ui/Link/Action.d.ts +2 -1
  359. package/types/ui/Reference/origin.d.ts +0 -2
  360. package/types/ui/System/Common.d.ts +1 -1
  361. package/types/vendor/@akanjs/native/packages/cli/src/lib/project.d.ts +5 -0
  362. package/types/vendor/@akanjs/native/packages/core/src/boot.d.ts +5 -0
  363. package/types/vendor/@akanjs/native/plugins/external-view/src/index.d.ts +20 -8
  364. package/types/vendor/@akanjs/native/plugins/keyboard/src/index.d.ts +3 -2
  365. package/types/vendor/use-agentic/ToolRunner.d.ts +2 -1
  366. package/types/vendor/use-agentic/types.d.ts +8 -0
  367. package/types/webkit/CsrStack.d.ts +2 -1
  368. package/types/webkit/csrPageReadiness.d.ts +18 -0
  369. package/types/webkit/csrSlide.d.ts +30 -0
  370. package/types/webkit/index.d.ts +1 -1
  371. package/types/webkit/nativeNavigation.d.ts +2 -2
  372. package/types/webkit/nativeSplash.d.ts +6 -0
  373. package/types/webkit/openSurfaces.d.ts +13 -0
  374. package/types/webkit/useCsrKeyboard.d.ts +2 -1
  375. package/types/webkit/useCsrNavigation.d.ts +1 -1
  376. package/types/webkit/useEscapeKey.d.ts +7 -2
  377. package/types/webkit/useFrameRuntime.d.ts +6 -2
  378. package/types/webkit/usePageLocation.d.ts +3 -1
  379. package/types/webkit/useVisualViewportFrame.d.ts +2 -0
  380. package/ui/Dialog/Modal.tsx +16 -2
  381. package/ui/KeyboardAvoiding.tsx +2 -1
  382. package/ui/Layout/FrameSlotPortal.tsx +10 -3
  383. package/ui/Link/Action.tsx +2 -1
  384. package/ui/Reference/origin.ts +0 -10
  385. package/ui/System/CSR.tsx +33 -13
  386. package/ui/System/Common.tsx +8 -2
  387. package/ui/System/SSR.tsx +7 -4
  388. package/ui/Tooltip.tsx +1 -1
  389. package/ui/styles.css +14 -0
  390. package/vendor/@akanjs/native/CHANGELOG.md +20 -52
  391. package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeActivity.kt +27 -14
  392. package/vendor/@akanjs/native/native/desktop/Cargo.lock +1 -0
  393. package/vendor/@akanjs/native/native/desktop/Cargo.toml +2 -0
  394. package/vendor/@akanjs/native/native/desktop/src/acl.rs +27 -7
  395. package/vendor/@akanjs/native/native/desktop/src/external.rs +240 -29
  396. package/vendor/@akanjs/native/native/desktop/src/lib.rs +3 -3
  397. package/vendor/@akanjs/native/native/desktop/src/navigation.rs +4 -0
  398. package/vendor/@akanjs/native/native/ios/Sources/AkanNativeViewController.swift +21 -2
  399. package/vendor/@akanjs/native/packages/cli/src/lib/acl.ts +10 -2
  400. package/vendor/@akanjs/native/packages/cli/src/lib/project.ts +11 -1
  401. package/vendor/@akanjs/native/packages/core/src/boot.ts +6 -0
  402. package/vendor/@akanjs/native/plugins/external-view/native-plugin.json +26 -0
  403. package/vendor/@akanjs/native/plugins/external-view/src/desktop.ts +9 -1
  404. package/vendor/@akanjs/native/plugins/external-view/src/index.ts +20 -8
  405. package/vendor/@akanjs/native/plugins/keyboard/src/index.ts +3 -2
  406. package/vendor/use-agentic/AgentSession.ts +1 -1
  407. package/vendor/use-agentic/CHANGELOG.md +9 -59
  408. package/vendor/use-agentic/Compaction.ts +1 -1
  409. package/vendor/use-agentic/ToolRunner.ts +12 -0
  410. package/vendor/use-agentic/WIRE.md +8 -2
  411. package/vendor/use-agentic/types.ts +8 -0
  412. package/webkit/CsrStack.ts +17 -9
  413. package/webkit/McpAppAgent.ts +3 -1
  414. package/webkit/RenderLayer.tsx +22 -13
  415. package/webkit/bootCsr.tsx +19 -1
  416. package/webkit/csrPageReadiness.ts +43 -0
  417. package/webkit/csrSlide.ts +130 -0
  418. package/webkit/index.ts +1 -1
  419. package/webkit/nativeNavigation.ts +12 -3
  420. package/webkit/nativeSplash.ts +30 -0
  421. package/webkit/openSurfaces.ts +54 -0
  422. package/webkit/useCsrKeyboard.ts +33 -1
  423. package/webkit/useCsrNavigation.ts +69 -21
  424. package/webkit/useCsrTransitions.ts +130 -29
  425. package/webkit/useCsrValues.ts +17 -5
  426. package/webkit/useEscapeKey.tsx +10 -23
  427. package/webkit/useFrameRuntime.ts +55 -6
  428. package/webkit/usePageLocation.ts +8 -2
  429. package/webkit/useVisualViewportFrame.tsx +24 -0
  430. package/client/locale.ts +0 -5
  431. package/service/serviceRegistry.ts +0 -27
  432. package/types/client/locale.d.ts +0 -6
  433. package/types/service/serviceRegistry.d.ts +0 -10
package/README.md CHANGED
@@ -6,11 +6,9 @@
6
6
 
7
7
  **The TypeScript framework, agents included.** Powered by Bun.
8
8
 
9
- **Build a screen — agents can use it. Build a server — any AI can run it.**
10
-
11
- No tool schemas, no MCP server to write, no second permission model. The app you build for people is already the
12
- one AI can use, on the model you choose. One line of business code runs through every layer, ships to six platforms,
13
- and reaches everyone who uses it — people and agents.
9
+ Akan.js is a full-stack TypeScript framework. One field declaration runs through the schema, service, API, client
10
+ state and UI, and the same code ships as a web app, iOS and Android apps, and desktop apps. Every guarded endpoint is
11
+ also an MCP tool and every control on screen an in-page agent tool, behind the guards people pass.
14
12
 
15
13
  ## Quick Start
16
14
 
@@ -61,307 +59,53 @@ Node and npm, or URLs given by a spec, a coding agent needs these, and nothing h
61
59
  - **Exact URLs:** pages live under `/<locale>/…`. To serve the default locale at the bare path (`/books/OL45804W`),
62
60
  set `i18n: { defaultLocale: "en", locales: ["en"], localePrefix: "as-needed" }` in `akan.config.ts`; `<Link>`
63
61
  follows.
64
- - **A host with only Node and npm:** run the creator through npx, which writes nothing global:
65
- `npx -y bun@1.4.4 x create-akan-workspace@latest . --app <app> --dir <folder> --sample false`. That Bun is not on
66
- `PATH` afterwards, so the creator lists `bun` in the workspace's `dependencies` and writes the scripts below; run
67
- any other command as `npx akan …`.
68
- - **Build and run without Docker** through these package scripts; `npm run build`, then `PORT=3000 npm start`:
69
-
70
- ```json
71
- "build": "akan build <app>",
72
- "start": "cd dist/apps/<app> && bun main.js"
73
- ```
74
-
75
- A fresh clone builds as is: the env files stay gitignored and `akan` writes the ones it lacks, so commit none. The
76
- build carries the env it needs, and a variable set at start overrides it.
62
+ - **A host with only Node and npm:** `npx -y bun@1.4.4 x create-akan-workspace@latest . --app <app> --dir <folder> --sample false`,
63
+ then `npm run build` and `PORT=3000 npm start`. The
64
+ [`create-akan-workspace` README](https://www.npmjs.com/package/create-akan-workspace#with-only-node-and-npm) has the
65
+ scripts it writes and what a fresh clone needs.
77
66
  - **Build for where it runs.** A variable set in the shell, or in a `.env.local` Bun loads, outranks the workspace `.env`
78
67
  (an empty one counts as unset, and the build names each one it took), and `--env` outranks both for `AKAN_PUBLIC_ENV`. A new workspace's `.env` says `local`, which suits your own machine or a test runner, but the
79
68
  server runs without endpoint rate limits and on local defaults. For a host others can reach, run
80
69
  `akan build <app> --env main` with `AKAN_PUBLIC_REPO_NAME` and `AKAN_PUBLIC_SERVE_DOMAIN` (the domain it serves) set
81
70
  in the shell or the workspace `.env`.
82
71
 
83
- ## All Of It Is One Line
84
-
85
- ```ts
86
- export class ProductInput extends via((field) => ({
87
- name: field(String),
88
- })) {}
89
- ```
90
-
91
- **1 line × 8 layers × 6 platforms × people & agents.**
92
-
93
- - **1 line.** Adding a field is one declaration: a name and a type.
94
- - **× 8 layers.** That line runs through the schema, query, service, API, fetch, client type, state and UI prop. In a
95
- usual stack those are eight places to change by hand, and missing one breaks a type or fails at runtime. Here they
96
- change together.
97
- - **× 6 platforms.** The same code ships as SEO-ready web, iOS and Android apps, and macOS, Windows and Linux desktop
98
- apps, with native-level screen transitions rather than a wrapped website.
99
- - **× people & agents.** Every guarded endpoint becomes an MCP tool and every control on screen an in-page agent
100
- tool, behind the same guards people pass.
101
-
102
- ## The Screen You Build Is The Agent's Interface
103
-
104
- ```tsx
105
- export const Order = () => {
106
- const { l } = usePage();
107
- const icecreamOrderForm = st.use.icecreamOrderForm();
108
- const order = st.tool("createIcecreamOrder", { confirm: true })
109
- .desc("Place the order in the form.")
110
- .exec(() => st.do.createIcecreamOrder());
111
- return (
112
- <>
113
- <Field.MultiToggleSelect
114
- label={l("icecreamOrder.toppings")}
115
- items={cnst.Topping}
116
- value={icecreamOrderForm.toppings}
117
- onChange={st.do.setToppingsOnIcecreamOrder}
118
- />
119
- <Button onClick={order}>{l("icecreamOrder.createIcecreamOrder")}</Button>
120
- </>
121
- );
122
- };
123
- ```
124
-
125
- - **Write the screen you were going to write.** A field handed its setter publishes it. A button's handler becomes a
126
- tool with one `st.tool` line — the same function the button calls.
127
- - **An agent sees tools, not pixels.** Every control you wired is published under its own name, with the arguments it
128
- takes. What isn't on the screen isn't on the list.
129
- - **It works the screen in the user's own tab**, with their session, exactly like a click.
130
- - **What matters waits for a yes.** A tool declared with `confirm` stops on an approval card.
131
-
132
- Setup is one `<Agent.Chat />` in a layout and your model's key in `option.ts`. OpenAI-compatible hosts and Anthropic
133
- both work.
134
-
135
- ## Your Server Is Already An MCP Server
136
-
137
- ```ts
138
- serveIcecreamOrder: mutation(cnst.IcecreamOrder, {
139
- guards: [Admin],
140
- })
141
- .param("icecreamOrderId", ID)
142
- .exec(async function (icecreamOrderId) {
143
- return await this.icecreamOrderService.serve(icecreamOrderId);
144
- }),
145
- refundIcecreamOrder: mutation(cnst.IcecreamOrder, {
146
- guards: [Every, Person],
147
- })
148
- .param("icecreamOrderId", ID)
149
- .with(Self)
150
- .exec(async function (icecreamOrderId, self) {
151
- return await this.icecreamOrderService.refund(icecreamOrderId, self.id);
152
- }),
153
- ```
154
-
155
- - **Point any MCP client at your app.** `POST /mcp` is on by default. Every endpoint whose guards admit the caller is
156
- a tool, described by the dictionary you already write.
157
- - **Sign-in and consent happen on your app.** OAuth 2.1 ships with `libs/shared`. The AI gets a token for one user —
158
- exactly their rights, revocable at any time.
159
- - **It can't do what it shouldn't.** `refundIcecreamOrder` is guarded by `Person`, so it never reaches the shelf. To
160
- the AI it looks exactly like a tool that doesn't exist.
161
- - **Pages become prompts.** `page().prompt(name, description)` publishes a screen as an MCP prompt: its fetches run
162
- under the caller's token and the agent receives the data, with no second implementation to keep in sync.
163
-
164
- ## One Rule, Three Kinds Of Users
165
-
166
- You write a guard once per endpoint. It decides for a person on the screen, for the agent in their tab, and for an AI
167
- calling over MCP.
168
-
169
- - **Refusals give nothing away.** A tool an agent may not use answers exactly like one that doesn't exist.
170
- - **Rate-limited per caller.** MCP calls are capped at 120 a minute and 8 at once for each caller.
171
- - **Secrets stay home.** Hidden and secret fields are stripped before anything reaches a model.
172
- - **Connections end when you say.** Revoke a connection and its next call is refused. The chat relay keeps no
173
- session and no transcript.
174
-
175
- ## Agents Build It, Too
176
-
177
- AI coding turns to spaghetti past a certain size: the faster an agent writes, the more file paths, names, structures
178
- and declaration styles drift apart. Akan stops this at the source with strict rules.
179
-
180
- - **Config hell ends.** Everything is configured in `akan.config.ts`, and an empty one still runs.
181
- - **Strict rules, unified style.** File paths, names, structures and declarations stay consistent, and lint enforces
182
- them, so code reads like one person wrote it.
183
- - **Rules agents can't route around.** Every workspace ships a generated `AGENTS.md`, bundled guidelines, a
184
- plan-then-apply workflow MCP, and `akan code`, a terminal coding agent that works through them.
185
- - **Fixed blocks.** Upload, login, admin, chat, boards and alerts are ready-made blocks, so agents produce
186
- consistent code on top of them.
187
-
188
- ## The Domain Module
189
-
190
- Code is organized around business domains such as `user`, `product`, `ticket` or `project`, not by technical layer
191
- first.
192
-
193
- ```text
194
- lib/product/
195
- ├── product.constant.ts # model, scalar, enum, schema definition
196
- ├── product.dictionary.ts # i18n labels, descriptions, errors
197
- ├── product.signal.ts # typed endpoint contract, guards
198
- ├── product.document.ts # persistence and document queries
199
- ├── product.service.ts # business logic
200
- ├── product.store.ts # domain state and actions
201
- ├── Product.Template.tsx # form UI
202
- ├── Product.Unit.tsx # list item UI
203
- ├── Product.View.tsx # detail UI
204
- └── Product.Zone.tsx # page section UI
205
- ```
206
-
207
- ```mermaid
208
- flowchart LR
209
- ConstantDictionarySignal["constant + dictionary + signal"] --> DocumentService["document + service"]
210
- ConstantDictionarySignal --> StoreComponents["store + UI components"]
211
- DocumentService --> ServerRuntime["server runtime + MCP"]
212
- StoreComponents --> ClientRuntime["client runtime + in-page agent"]
213
- ServerRuntime --> DeployArtifacts["deploy artifacts"]
214
- ClientRuntime --> DeployArtifacts
215
- ```
216
-
217
- ## Faster Than v2
218
-
219
- v3 adds agents, MCP and a new UI system, and it is still faster than v2 on every number we measured.
220
-
221
- | Metric | v2 | v3 | Change |
222
- | --- | --- | --- | --- |
223
- | Requests per second | 112K | 123K | +10% |
224
- | Response time (p99) | 1.30 ms | 1.04 ms | −20% |
225
- | Startup time | 204 ms | 102 ms | −50% |
226
- | Memory at rest | 84 MB | 57 MB | −32% |
227
- | Memory under load | 105 MB | 85 MB | −19% |
72
+ ## Your First App
228
73
 
229
- - Client build output: 26MB → 8.1MB (605 chunks down to 258).
230
- - Hydrating 1,000 rows on the client: 3.5ms → 0.9ms.
231
- - A 50-row list query: −33% time, with 85% fewer allocations.
74
+ - **A screen** is a file under `apps/<app>/page/`: `<route>.tsx` or `_index.tsx`, `_layout.tsx` around it, `[id]/`
75
+ for a segment. It exports one `page()` chain from `akanjs/client`. [Routing](https://akanjs.com/docs/core/routing)
76
+ - **A stored model** is a module under `lib/<model>/`, made by `akan create-module <model> <app>`. A service with no
77
+ stored model, such as an outside API, goes under `lib/_<service>/` with `akan create-service <service> <app>`.
78
+ [File rules](https://akanjs.com/docs/core/file-rule)
79
+ - **The rules** a coding agent follows are in the workspace: `AGENTS.md`, `.claude/rules/akan/`, and the skills in
80
+ `.claude/skills/` and `.agents/skills/`. `akan guideline show <name>` prints any bundled guideline.
81
+ - **`akan.config.ts`** may stay empty. It grows only for routes, domains, locales, database modes or native apps.
82
+ [Configuration](https://akanjs.com/docs/core/config)
232
83
 
233
- Measured on an Apple M4 Pro MacBook Pro with production builds and 50 concurrent users. The harness and raw data live
234
- in [`benchmarks/api-benchmark`](https://github.com/akan-team/akanjs/tree/main/benchmarks/api-benchmark).
235
-
236
- ## From Build To A Live URL
237
-
238
- [Akan Cloud](https://cloud.akanjs.com) is the deploy platform built for Akan apps.
239
-
240
- ```bash
241
- akan login # sign in to Akan Cloud from your machine
242
- akan tunnel <app> # share the app you are running on a public URL
243
- akan build <app> # build the production artifact Akan Cloud runs
244
- ```
245
-
246
- ## Docs For You And Your Agent
247
-
248
- - Read the docs at [akanjs.com/docs](https://akanjs.com/docs). Every docs page carries the in-page agent, so you can
249
- ask it about a topic and it opens the page.
250
- - Connect Claude Code or Cursor to `https://akanjs.com/mcp`, and your AI reads the docs (`listDocPages`,
251
- `searchDocPages`, `readDocPage`) while it writes your code.
252
- - [`llms.txt`](https://akanjs.com/llms.txt) indexes the docs for any model.
253
-
254
- ## One Package, Many Boundaries
255
-
256
- Akan is published as a single npm package, `akanjs`. The root import is intentionally small; subpath imports keep
257
- server-only, client-only, UI and tooling surfaces apart.
258
-
259
- ```ts
260
- import { Int, dayjs } from "akanjs/base";
261
- import { via } from "akanjs/constant";
262
- import { endpoint } from "akanjs/signal";
263
- import { Button, Layout } from "akanjs/ui";
264
- import { page } from "akanjs/client";
265
- import { AkanApp } from "akanjs/server/akanApp";
266
- ```
267
-
268
- ```css
269
- @import "akanjs/ui/styles.css";
270
- ```
271
-
272
- | Subpath | Purpose |
273
- | --- | --- |
274
- | `akanjs/base` | Core primitives, scalars (`Int`, `Float`, `ID`, `Binary`, `enumOf`), `dayjs`, environment helpers. |
275
- | `akanjs/common` | Shared cross-runtime helpers. |
276
- | `akanjs/constant` | Model declarations, schema shaping, serialization, defaults, and the `via` builder. |
277
- | `akanjs/dictionary` | Locale, translation, and dictionary helpers for labels, descriptions and errors. |
278
- | `akanjs/document` | Database documents, filters, query builders, full-text search, and persistence utilities. |
279
- | `akanjs/signal` | Endpoints, slices, guards, middleware, and typed signal contracts. |
280
- | `akanjs/service` | Services, adaptors, dependency injection, and the business logic runtime. |
281
- | `akanjs/fetch` | Typed fetch, HTTP and WebSocket clients. |
282
- | `akanjs/store` | Domain state, actions, and the in-page agent's `st.tool` / `st.use` surface. |
283
- | `akanjs/ui` | React components, recipes, and `_overrides.tsx` slots: layout, form, modal, table, loading, agent chat. |
284
- | `akanjs/client` | The route chain (`page()`, `layout()`), routing, cookies, storage, locale, and `cn`. |
285
- | `akanjs/client/native` | The native bridge and builtin plugins for iOS, Android and desktop apps. |
286
- | `akanjs/webkit` | Browser-side helpers such as `lazy` and SEO pages. |
287
- | `akanjs/server` | Server runtime, SSR/RSC, MCP, logging, and server types. `akanjs/server/akanApp` is the entrypoint. |
288
- | `akanjs/native/desktop` | Desktop parts of native plugins. |
289
- | `akanjs/test` | Test helpers and sample generation. |
290
-
291
- Tooling ships as separate packages: `@akanjs/cli` (the `akan` command), `@akanjs/devkit` (build runners, code
292
- generation, lint rules) and `create-akan-workspace`.
293
-
294
- ## CLI Overview
84
+ ## Build And Run
295
85
 
296
86
  ```bash
297
- akan create-workspace
298
- akan create-application <app>
299
- akan create-module
300
- akan start <app> --open # or several: akan start a,b
301
- akan build <app>
302
- akan build-ios <app> # also build-android, build-desktop
303
- akan lint <app>
304
- akan typecheck <app>
305
- akan test <app>
306
- akan logs <app>
307
- akan code
308
- akan update
87
+ akan start <app> # dev server, http://localhost:8282
88
+ akan verify <app> # sync, lint, typecheck, build and SSR check
89
+ akan build <app> # production build in dist/apps/<app>
90
+ cd dist/apps/<app> && PORT=3000 bun main.js
309
91
  ```
310
92
 
311
- - **Workspace**: create workspaces, lint, sync, and run `akan doctor`.
312
- - **Application**: start, build, typecheck, test, and package web, mobile and desktop apps.
313
- - **Library**: create, install, sync, push, and pull shared libraries.
314
- - **Module and scalar**: generate domain modules, models, views, units, templates, and stores.
315
- - **Agents**: `akan code`, `akan mcp`, `akan mcp-install`, `akan workflow`, `akan guideline`.
316
- - **Cloud and release**: `akan login`, `akan tunnel`, deployment assets, and package updates.
317
-
318
- ## Application Configuration
319
-
320
- `akan.config.ts` is the single place for app-level configuration. It can stay empty, then grow only when the app
321
- needs routes, domains, base paths, database modes, or native app settings.
322
-
323
- ```ts
324
- import type { AppConfig } from "akanjs";
325
-
326
- const config: AppConfig = {
327
- routes: [
328
- { domains: { main: ["example.com", "www.example.com"] }, basePath: "web" },
329
- { domains: {}, basePath: "app" },
330
- ],
331
- database: { modes: ["single", "cluster"] },
332
- native: {
333
- basePath: "app",
334
- appName: "Example",
335
- appId: "com.example.app",
336
- version: "1.0.0",
337
- buildNum: 1,
338
- },
339
- };
340
-
341
- export default config;
342
- ```
343
-
344
- ## Contributor Notes
345
-
346
- This repository is a Bun-first monorepo. Framework code lives under `pkgs/akanjs`, tooling under `pkgs/@akanjs`,
347
- applications under `apps`, shared libraries under `libs`, and deployment assets under `infra`. `apps/akan` is
348
- [akanjs.com](https://akanjs.com) itself.
349
-
350
- Inside this repository, `bun run akan` builds the CLI from source and runs it:
351
-
352
- ```bash
353
- bun run akan start <app>
354
- bun run akan lint <app>
355
- bun run akan typecheck <app>
356
- bun run akan test <app-or-lib-or-pkg>
357
- ```
358
-
359
- `AGENTS.md` is the guide for coding agents and contributors alike. When editing framework code, prefer established
360
- subpaths and keep the root `akanjs` entrypoint small. The package boundary is part of the runtime design.
361
-
362
- ## Open Source Notes
363
-
364
- - License: MIT. See [`pkgs/akanjs/LICENSE`](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/LICENSE).
365
- - Repository: [akan-team/akanjs](https://github.com/akan-team/akanjs).
366
- - Contribution guide: [`pkgs/akanjs/CONTRIBUTING.md`](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/CONTRIBUTING.md).
367
- - Code of conduct: [`pkgs/akanjs/CODE_OF_CONDUCT.md`](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/CODE_OF_CONDUCT.md).
93
+ [Akan Cloud](https://cloud.akanjs.com) runs Akan apps: `akan login` signs in, and `akan tunnel <app>` shares the app
94
+ you are running on a public URL.
95
+
96
+ ## Learn More
97
+
98
+ - [akanjs.com](https://akanjs.com): what one line of code reaches, the screen as an agent's interface, and your server
99
+ as an MCP server.
100
+ - [Docs](https://akanjs.com/docs), the [CLI reference](https://akanjs.com/references/cli/overview), and
101
+ [`llms.txt`](https://akanjs.com/llms.txt). Connect a coding agent to `https://akanjs.com/mcp` to read the docs while
102
+ it writes code.
103
+ - [MCP](https://akanjs.com/cheatsheet/interface/mcp) and the [in-page agent](https://akanjs.com/cheatsheet/interface/agent-chat):
104
+ guards, refusals, rate limits and model setup.
105
+ - [v3 performance](https://akanjs.com/blog/v3release#v3-performance): the numbers against v2 and how they were measured.
106
+ - `akanjs` is one npm package. Its subpaths (`akanjs/base`, `akanjs/client`, `akanjs/signal`, `akanjs/ui`, …) keep
107
+ server-only, client-only, UI and tooling code apart, and the [package reference](https://akanjs.com/references/akanjs/base)
108
+ covers them; the tooling ships as `@akanjs/cli` and `@akanjs/devkit`.
109
+ - Contributing: [`CONTRIBUTING.md`](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/CONTRIBUTING.md) and
110
+ the [code of conduct](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/CODE_OF_CONDUCT.md). License: MIT
111
+ ([`LICENSE`](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/LICENSE)).
@@ -0,0 +1,12 @@
1
+ import { Href } from "./href";
2
+ import { isNativeShell } from "./nativeHost";
3
+
4
+ export const closeAppOpenedTab = (): boolean => {
5
+ const win = globalThis.window;
6
+ if (!win || isNativeShell() || win.history?.length !== 1 || typeof win.close !== "function") return false;
7
+
8
+ const referrer = globalThis.document?.referrer ?? "";
9
+ if (!win.opener && (!referrer || Href.leavesOrigin(referrer, win.location.href))) return false;
10
+ win.close();
11
+ return win.closed === true;
12
+ };
@@ -38,6 +38,8 @@ type RuntimeErr = {
38
38
 
39
39
  type RuntimeWs = {
40
40
  connected: boolean;
41
+ state?: "connecting" | "open" | "closed" | "gaveUp";
42
+ connect?: (option?: { fresh?: boolean }) => void;
41
43
  on: (event: string, handler: (...args: unknown[]) => void) => void;
42
44
  off: (event: string, handler: (...args: unknown[]) => void) => void;
43
45
  };
@@ -80,13 +82,6 @@ globalWithRuntime[CLIENT_RUNTIME_KEY] = state;
80
82
  const missingRuntimeError = () =>
81
83
  new Error("Akan client runtime is not registered. Import the generated app client first.");
82
84
 
83
- const applyRuntimeErrorConstructor = (runtime: ClientRuntime) => {
84
- const instance = (runtime.fetch as RuntimeFetch | undefined)?.instance as
85
- | { setErrorConstructor?: (Err: unknown) => void }
86
- | undefined;
87
- if (typeof instance?.setErrorConstructor === "function") instance.setErrorConstructor(runtime.Err);
88
- };
89
-
90
85
  export const registerClientRuntime = <Runtime>(
91
86
  runtime: Runtime,
92
87
  { scope = "app" }: { scope?: RuntimeScope } = {},
@@ -94,12 +89,10 @@ export const registerClientRuntime = <Runtime>(
94
89
  if (state.scope === "app" && scope === "lib") return runtime;
95
90
  state.runtime = runtime as ClientRuntime;
96
91
  state.scope = scope;
97
- applyRuntimeErrorConstructor(state.runtime);
98
92
  return runtime;
99
93
  };
100
94
 
101
- /** @internal */
102
- export const getClientRuntime = () => {
95
+ const getClientRuntime = () => {
103
96
  if (!state.runtime) throw missingRuntimeError();
104
97
  return state.runtime;
105
98
  };
package/client/cn.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { type ClassNameValue, extendTailwindMerge } from "tailwind-merge";
2
2
 
3
- /** @internal Registered with tailwind-merge so `cn("bg-primary", "bg-open")` resolves to `"bg-open"` instead of keeping both. */
4
- export const colorTokens = [
3
+ /** Registered with tailwind-merge so `cn("bg-primary", "bg-open")` resolves to `"bg-open"` instead of keeping both. */
4
+ const colorTokens = [
5
5
  "background",
6
6
  "foreground",
7
7
  "primary",
@@ -33,8 +33,8 @@ export const colorTokens = [
33
33
  "ring",
34
34
  ];
35
35
 
36
- /** @internal `--radius-box` / `--radius-field`; unregistered, `cn("rounded-field", "rounded-full")` would keep both. */
37
- export const radiusTokens = ["box", "field"];
36
+ /** `--radius-box` / `--radius-field`; unregistered, `cn("rounded-field", "rounded-full")` would keep both. */
37
+ const radiusTokens = ["box", "field"];
38
38
 
39
39
  const twMerge = extendTailwindMerge({
40
40
  extend: {
package/client/cookie.ts CHANGED
@@ -153,25 +153,34 @@ export interface GetOption {
153
153
  unauthorize: string;
154
154
  }
155
155
  interface SetAuthOption {
156
- jwt: string;
156
+ jwt?: string | null;
157
157
  }
158
158
  const announceAuth = () => {
159
159
  if (typeof window !== "undefined") window.dispatchEvent(new Event("akan:auth"));
160
160
  };
161
+
162
+ const reopenSocket = () => {
163
+ const { ws } = fetch;
164
+ if (ws?.state === "open" || ws?.state === "connecting") ws.connect?.({ fresh: true });
165
+ };
161
166
  /** Sets the active auth token on fetch, then keeps it where the next launch finds it: client storage on a CSR client,
162
- * the session cookie elsewhere unless the server already holds it there (`SessionCookie.issue`). */
163
- export const setAuth = ({ jwt }: SetAuthOption) => {
164
- fetch.setJwt(jwt);
167
+ * the session cookie elsewhere unless the server already holds it there (`SessionCookie.issue`). An answer with no
168
+ * token beside a session the server holds is a cookie-only session: fetch sends no token and the socket reconnects. */
169
+ export const setAuth = ({ jwt }: SetAuthOption = {}) => {
170
+ const token = jwt ?? "";
171
+ const cookieOnly = !token && serverHoldsSession();
172
+ fetch.setJwt(cookieOnly ? null : token);
165
173
 
166
- if (isCsrClient()) void secretStorage.setItem(storedAuthTokenKey(), jwt);
174
+ if (isCsrClient()) void secretStorage.setItem(storedAuthTokenKey(), token);
167
175
  else {
168
176
 
169
177
  void secretStorage.removeItem(storedAuthTokenKey());
170
- if (!serverHoldsSession()) setCookie(authTokenKey(), jwt);
178
+ if (!serverHoldsSession()) setCookie(authTokenKey(), token);
171
179
  }
172
180
 
173
181
  for (const key of retiredAuthTokenKeys()) removeCookie(key);
174
182
  void secretStorage.removeItem(legacyAuthTokenKey);
183
+ if (cookieOnly) reopenSocket();
175
184
  announceAuth();
176
185
  };
177
186
 
@@ -19,6 +19,8 @@ export type PageSafeAreaConfig =
19
19
  bottom?: boolean;
20
20
  android?: "auto" | "edge-to-edge" | "none";
21
21
  };
22
+ /** The sides whose chrome the page runs under instead of below. */
23
+ export type PageOverlayConfig = boolean | "top" | "bottom";
22
24
  /** `"stream"` flushes the shell (`Loading` included) then streams; a redirect in suspended content becomes a client one.
23
25
  * `"block"` buffers the whole document, so an error in slow content can still render a clean error page. */
24
26
  export type SsrRenderMode = "stream" | "block";
@@ -34,6 +36,12 @@ export interface PageConfig {
34
36
  topInset?: number | boolean | ResponsiveInset;
35
37
  /** Bottom chrome reservation in px, or px per breakpoint. Use true for the default 48px reservation. */
36
38
  bottomInset?: number | boolean | ResponsiveInset;
39
+ /**
40
+ * Lays the page under its top or bottom chrome (safe area and inset) instead of below it, so a translucent bar has
41
+ * content scrolling beneath it. The page pads its own scrollers by `--akan-overlay-top` / `--akan-overlay-bottom`,
42
+ * and an overlaid side's safe area defaults to transparent.
43
+ */
44
+ overlay?: PageOverlayConfig;
37
45
  gesture?: boolean;
38
46
  cache?: boolean;
39
47
  /** Initial full-document SSR strategy. Defaults to `"stream"`. */
@@ -47,6 +55,10 @@ export interface PageConfig {
47
55
  /** `false` answers a `Link` prefetch of the page (on a layout, of every page under it) without rendering it, for a
48
56
  * render with a side effect such as counting a view; the click renders it as usual. */
49
57
  prefetch?: boolean;
58
+ /** `false` keys the page in the RSC and HTML result caches on its query exactly as requested (on a layout, every
59
+ * page under it), for a page whose output follows parameter order or a tracking parameter it reads without declaring
60
+ * it with `.search()`. By default the key sorts the query and leaves out `AKAN_ROUTE_CACHE_TRACKING_PARAMS`. */
61
+ canonicalQuery?: boolean;
50
62
  topSafeAreaColor?: string;
51
63
  bottomSafeAreaColor?: string;
52
64
  /** Keeps the route (on a `_layout`, its whole directory) out of `akan build` while `akan start` serves it. Write a
@@ -64,6 +76,7 @@ export interface CsrState {
64
76
  responsiveInset?: { top: ResponsiveInset; bottom: ResponsiveInset };
65
77
  /** Web only: the sides whose safe area `env(safe-area-inset-*)` measures, since a browser tells script nothing. */
66
78
  safeAreaEnv?: { top: boolean; bottom: boolean };
79
+ overlay?: { top: boolean; bottom: boolean };
67
80
  gesture: boolean;
68
81
  cache: boolean;
69
82
  ssr: SsrRenderMode;
@@ -153,6 +166,8 @@ export interface RouteRender {
153
166
  getLayoutManifest?: () => PromiseOrObject<WebAppManifest | undefined>;
154
167
  /** The `page()` chain behind a page render, when it was declared as one — what a page prompt is read off. */
155
168
  getRouteDefinition?: () => PromiseOrObject<RouteDefinition | undefined>;
169
+ /** The query names the level reads; `undefined` for a legacy module, which receives every one. */
170
+ getSearchNames?: () => PromiseOrObject<string[] | undefined>;
156
171
  }
157
172
  export interface RouteViewport {
158
173
  /** `viewport-fit=cover`: the page runs under the notch and home indicator, and `env(safe-area-inset-*)` measures them. */
@@ -437,6 +452,8 @@ export interface KeyboardFrameState {
437
452
  source?: "native" | "visualViewport" | "fallback";
438
453
  animationDuration?: number;
439
454
  animationEasing?: string;
455
+ /** The page's content ends at the keyboard, as UIKit's keyboard layout guide does: an iOS shell no longer pans. */
456
+ avoidsContent?: boolean;
440
457
  }
441
458
  export interface FrameContentViewportState {
442
459
  top: number;
package/client/device.ts CHANGED
@@ -1,16 +1,30 @@
1
1
  "use client";
2
+ import { parseAkanI18nEnv } from "akanjs/common";
2
3
  import type { RefObject } from "react";
3
4
  import { csrLocation } from "./csrLocation";
4
5
  import { readCssSafeAreaInsets } from "./frameConfig";
5
6
  import type { DeviceInfo } from "./native";
6
7
 
7
8
  type NativeModule = typeof import("./native");
9
+ type KeyboardRideClass = typeof import("./keyboardRide").KeyboardRide;
8
10
  type NativeControls = Pick<NativeModule, "haptics" | "keyboard">;
9
11
  type ProcessEnvLike = { env?: Record<string, string | undefined> };
10
12
  type DebugPayload = Record<string, unknown>;
11
13
 
12
14
  const globalWithProcess = globalThis as typeof globalThis & { process?: ProcessEnvLike };
13
15
 
16
+ /** Whether the shell left the keyboard to the page; an older shell still pans to the field, so the page must not. */
17
+ export const isPageKeyboardAvoidance = () =>
18
+ (globalThis as { __AKAN_NATIVE__?: { keyboardAvoidance?: string } }).__AKAN_NATIVE__?.keyboardAvoidance === "page";
19
+
20
+ export const IOS_KEYBOARD_ANIMATION_EASING = "cubic-bezier(0.38, 0.7, 0.125, 1)";
21
+
22
+ export const ANDROID_KEYBOARD_ANIMATION_EASING = "cubic-bezier(0.2, 0, 0, 1)";
23
+ export const nativeKeyboardEasing = () =>
24
+ (globalThis as { __AKAN_NATIVE__?: { platform?: string } }).__AKAN_NATIVE__?.platform === "android"
25
+ ? ANDROID_KEYBOARD_ANIMATION_EASING
26
+ : IOS_KEYBOARD_ANIMATION_EASING;
27
+
14
28
  const debugSessionId = crypto.getRandomValues(new Uint32Array(1))[0].toString(36);
15
29
  let debugSeq = 0;
16
30
 
@@ -92,6 +106,12 @@ const langInPath = (pathname: string, supportLanguages: string[] | readonly stri
92
106
  return supportLanguages.find((language) => language === predefinedLangPath);
93
107
  };
94
108
 
109
+ const supportedLang = (code: string, supportLanguages: string[] | readonly string[]) => {
110
+ if (supportLanguages.length === 0 || supportLanguages.includes(code)) return code;
111
+ const { defaultLocale } = parseAkanI18nEnv();
112
+ return supportLanguages.includes(defaultLocale) ? defaultLocale : (supportLanguages[0] ?? code);
113
+ };
114
+
95
115
  const createWebDevice = ({
96
116
  lang,
97
117
  supportLanguages,
@@ -101,7 +121,7 @@ const createWebDevice = ({
101
121
  }) => {
102
122
  const pathname = typeof window === "undefined" ? "" : csrLocation.pathname;
103
123
  return new Device({
104
- lang: lang ?? langInPath(pathname, supportLanguages) ?? getBrowserLanguage(),
124
+ lang: lang ?? langInPath(pathname, supportLanguages) ?? supportedLang(getBrowserLanguage(), supportLanguages),
105
125
  info: webDeviceInfo,
106
126
  topSafeArea: 0,
107
127
  bottomSafeArea: 0,
@@ -133,7 +153,8 @@ export class Device {
133
153
 
134
154
  const { top: topSafeArea, bottom: bottomSafeArea } = readCssSafeAreaInsets();
135
155
  Device.instance = new Device({
136
- lang: lang ?? langInPath(window.location.pathname, supportLanguages) ?? languageCode,
156
+ lang:
157
+ lang ?? langInPath(window.location.pathname, supportLanguages) ?? supportedLang(languageCode, supportLanguages),
137
158
  info,
138
159
  topSafeArea,
139
160
  bottomSafeArea,
@@ -151,6 +172,9 @@ export class Device {
151
172
  topSafeArea: number;
152
173
  bottomSafeArea: number;
153
174
  isMobile = isMobileDevice();
175
+ keyboardAnimationMs = 0;
176
+ keyboardHeight = 0;
177
+ #keyboardSubscribers = new Set<(height: number) => void>();
154
178
  #native: NativeControls | null;
155
179
  #stopKeyboardListeners: (() => void)[] = [];
156
180
  #pageContentRef: RefObject<HTMLDivElement | null> | null = null;
@@ -168,24 +192,40 @@ export class Device {
168
192
  async hideKeyboard() {
169
193
  await this.#native?.keyboard.hide();
170
194
  }
195
+
196
+ static #keyboardRide: KeyboardRideClass | null = null;
171
197
  listenKeyboardChanged(onKeyboardChanged: (height: number) => void) {
172
198
  const keyboard = this.#native?.keyboard;
173
199
  if (!keyboard) return;
200
+ if (isPageKeyboardAvoidance())
201
+ void import("./keyboardRide").then(({ KeyboardRide }) => {
202
+ Device.#keyboardRide = KeyboardRide;
203
+ });
174
204
  let currentHeight = 0;
175
205
  const emitKeyboardHeight = (event: string, height: number) => {
176
206
  debugFrame("keyboard.event", { event, height, previousHeight: currentHeight });
177
207
  if (currentHeight === height) return;
178
208
  currentHeight = height;
209
+ this.keyboardHeight = height;
179
210
  onKeyboardChanged(height);
211
+ for (const subscriber of this.#keyboardSubscribers) subscriber(height);
180
212
  };
181
213
  this.#stopKeyboardListeners.push(
182
214
  ...(["willShow", "didShow", "willHide", "didHide"] as const).map((event) =>
183
- keyboard.listen(event, ({ height }) => {
215
+ keyboard.listen(event, ({ height, duration }) => {
216
+ if (duration > 0) this.keyboardAnimationMs = duration;
217
+ Device.#keyboardRide?.move(height, this.keyboardAnimationMs);
184
218
  emitKeyboardHeight(event, height);
185
219
  }),
186
220
  ),
187
221
  );
188
222
  }
223
+ subscribeKeyboard(onKeyboardChanged: (height: number) => void) {
224
+ this.#keyboardSubscribers.add(onKeyboardChanged);
225
+ return () => {
226
+ this.#keyboardSubscribers.delete(onKeyboardChanged);
227
+ };
228
+ }
189
229
  unlistenKeyboardChanged() {
190
230
  for (const stop of this.#stopKeyboardListeners.splice(0)) stop();
191
231
  }