akanjs 3.2.0-rc.2 → 3.2.0-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +42 -41
- package/CHANGELOG.md +593 -3
- package/CONTRIBUTING.md +26 -0
- package/base/base.ts +2 -1
- package/client/clientRuntime.ts +1 -0
- package/client/cn.ts +2 -2
- package/client/csrTypes.ts +15 -1
- package/client/frameConfig.ts +5 -2
- package/client/index.ts +249 -26
- package/client/locale.ts +1 -0
- package/client/makePageProto.tsx +33 -82
- package/client/nativeThemeColor.ts +51 -0
- package/client/route/RouteDefinition.ts +24 -7
- package/client/route/RouteGuards.ts +2 -1
- package/client/route/RouteHead.ts +11 -2
- package/client/route/routeArgs.ts +7 -0
- package/client/router.ts +25 -6
- package/client/rscNavigation.ts +3 -3
- package/client/rscRoutePatch.ts +42 -0
- package/client/viewportMeta.ts +34 -4
- package/common/CodeTranscript.ts +1 -1
- package/common/PipelinePlanSchema.ts +2 -2
- package/common/akanGraph.ts +1 -1
- package/common/err.ts +122 -0
- package/common/facetBarrel.ts +38 -0
- package/common/failureCode.ts +18 -0
- package/common/index.ts +9 -0
- package/common/isGuardRefusal.ts +14 -0
- package/common/mcpExposure.ts +17 -4
- package/common/mcpFailure.ts +9 -0
- package/common/pipelinePlan.ts +1 -1
- package/common/restartSchedule.ts +55 -0
- package/common/routeConvention.ts +3 -1
- package/common/types.ts +18 -1
- package/constant/constantRegistry.ts +4 -8
- package/constant/crystalize.ts +1 -2
- package/constant/getDefault.ts +1 -1
- package/constant/immerify.ts +1 -1
- package/constant/index.ts +78 -21
- package/constant/purify.ts +4 -9
- package/constant/serialize.ts +4 -2
- package/constant/types.ts +1 -0
- package/constant/via.ts +1 -2
- package/dictionary/agent.dictionary.ts +4 -0
- package/dictionary/base.dictionary.ts +1 -0
- package/dictionary/locale.ts +1 -1
- package/dictionary/trans.ts +14 -97
- package/document/databaseRegistry.ts +2 -1
- package/document/documentSchema.ts +1 -0
- package/document/filterMeta.ts +4 -1
- package/document/into.ts +2 -1
- package/document/loaderInfo.ts +2 -1
- package/document/noDocumentError.ts +4 -1
- package/document/queryEvaluator.ts +1 -1
- package/document/types.ts +1 -1
- package/fetch/client/fetchClient.ts +87 -270
- package/fetch/client/fetchClientTypes.ts +49 -0
- package/fetch/client/fetchHandle.ts +11 -1
- package/fetch/client/httpClient.ts +14 -2
- package/fetch/client/inflightQueries.ts +17 -0
- package/fetch/client/remoteError.ts +4 -20
- package/fetch/client/requestScope.ts +32 -0
- package/fetch/client/signalCatalog.ts +131 -0
- package/fetch/client/wsClient.ts +11 -0
- package/fetch/index.ts +1 -0
- package/fetch/staleReads.ts +27 -0
- package/fetch/streamedRead.ts +23 -0
- package/package.json +1 -1
- package/server/agentHooks.ts +16 -0
- package/server/akanApp.ts +107 -1272
- package/server/akanOption.ts +17 -4
- package/server/akanServer.ts +167 -675
- package/server/artifact/builderRpc.ts +33 -10
- package/server/artifact/ipcTypes.ts +9 -3
- package/server/artifact/routeSeedIndexStore.ts +4 -2
- package/server/assetHeaders.ts +6 -0
- package/server/console.ts +6 -4
- package/server/decorators.ts +2 -2
- package/server/devtools/README.md +4 -3
- package/server/devtools/devtoolsRouter.ts +9 -5
- package/server/devtools/studio/studioRoute.ts +18 -11
- package/server/di/diLifecycle.ts +24 -35
- package/server/di/predefinedAdaptor.ts +24 -1
- package/server/di/resolveHierarchy.ts +19 -6
- package/server/di/utils.ts +7 -3
- package/server/ed25519Key.ts +31 -15
- package/server/flightRowReader.ts +95 -18
- package/server/gateway/childSupervisor.ts +326 -0
- package/server/gateway/devHostChannel.ts +47 -0
- package/server/gateway/gatewayChildren.ts +135 -0
- package/server/gateway/gatewayConfig.ts +182 -0
- package/server/gateway/gatewayHttpProxy.ts +231 -0
- package/server/gateway/gatewayLogging.ts +111 -0
- package/server/gateway/gatewayRooms.ts +141 -0
- package/server/gateway/gatewayStatus.ts +116 -0
- package/server/gateway/gatewayStatusPage.ts +54 -0
- package/server/gateway/gatewayWebSocketRelay.ts +149 -0
- package/server/head.tsx +4 -19
- package/server/hmr/devHmrController.ts +10 -1
- package/server/htmlResultCache.ts +234 -0
- package/server/imageOptimizer.ts +4 -1
- package/server/index.ts +257 -17
- package/server/lifecycle/parentChannel.ts +78 -0
- package/server/lifecycle/shutdownManager.ts +6 -3
- package/server/lifecycle/startGuard.ts +90 -0
- package/server/logging/logControlSocket.ts +42 -3
- package/server/logging/serverLogging.ts +74 -0
- package/server/machine/machineToken.ts +10 -3
- package/server/mcp/AgentTools.ts +149 -0
- package/server/mcp/AgentToolsAccount.ts +26 -0
- package/server/mcp/McpDispatcher.ts +48 -19
- package/server/mcp/McpPages.ts +21 -6
- package/server/mcp/McpRateLimiter.ts +14 -0
- package/server/mcp/McpRouter.ts +52 -23
- package/server/mcp/McpUiSession.ts +2 -1
- package/server/mcp/index.ts +1 -0
- package/server/nativeFile.ts +30 -11
- package/server/nativeSecret.ts +12 -3
- package/server/oauth/OAuthClientIdMetadata.ts +2 -2
- package/server/ops/opsRoute.ts +5 -1
- package/server/ops/opsToken.ts +3 -1
- package/server/resolver/CascadeRunner.ts +10 -4
- package/server/resolver/database.resolver.ts +10 -417
- package/server/resolver/databaseModelInstance.ts +200 -0
- package/server/resolver/invalidSignal.ts +7 -0
- package/server/resolver/livePause.ts +34 -0
- package/server/resolver/modelFacade.ts +136 -0
- package/server/resolver/modelLoaders.ts +52 -0
- package/server/resolver/modelSchema.ts +52 -0
- package/server/resolver/signal.resolver.ts +92 -116
- package/server/resolver/timedQuery.ts +16 -0
- package/server/resolver/websocketOf.ts +23 -0
- package/server/routeElementComposer.tsx +131 -9
- package/server/routeState.ts +5 -1
- package/server/routeTreeBuilder.ts +22 -9
- package/server/routing/apiRouter.ts +44 -25
- package/server/routing/builtinRoutes.ts +194 -0
- package/server/routing/localRooms.ts +34 -0
- package/server/routing/roomReplay.ts +2 -2
- package/server/routing/serverLimits.ts +4 -1
- package/server/routing/serverListener.ts +194 -0
- package/server/rscClient.tsx +210 -227
- package/server/rscClientCache.ts +165 -0
- package/server/rscClientChunks.ts +209 -0
- package/server/rscClientFetch.ts +15 -3
- package/server/rscClientPatch.ts +78 -15
- package/server/rscDocumentHead.tsx +170 -0
- package/server/rscFlightRenderer.ts +83 -0
- package/server/rscFlightStream.ts +257 -0
- package/server/rscHeadPatch.ts +17 -56
- package/server/rscHostReloads.ts +238 -0
- package/server/rscHostRenderStream.ts +297 -0
- package/server/rscHostRequests.ts +158 -0
- package/server/rscHttp.ts +18 -6
- package/server/rscInlineStream.ts +34 -0
- package/server/rscNavigationState.ts +21 -1
- package/server/rscPagePrompts.ts +11 -5
- package/server/rscParkedRedirect.ts +23 -0
- package/server/rscPatchPlanner.ts +220 -0
- package/server/rscPrefetchCache.ts +68 -32
- package/server/rscRenderControl.ts +33 -0
- package/server/rscRenderFallbacks.ts +297 -0
- package/server/rscRenderHandler.ts +439 -0
- package/server/rscRenderStats.ts +49 -0
- package/server/rscResponse.ts +78 -0
- package/server/rscResultCaches.ts +74 -0
- package/server/rscRouteDocument.tsx +299 -0
- package/server/rscSegmentOutlet.tsx +24 -5
- package/server/rscSegmentOutletReference.ts +14 -12
- package/server/rscWorker.tsx +86 -1392
- package/server/rscWorkerCache.ts +56 -0
- package/server/rscWorkerHost.ts +145 -811
- package/server/rscWorkerProcess.ts +155 -0
- package/server/rscWorkerRecycler.ts +128 -0
- package/server/serverConfig.ts +128 -0
- package/server/serverMetrics.ts +52 -0
- package/server/sitemap.ts +1 -0
- package/server/ssrFromRscRenderer.tsx +20 -20
- package/server/ssrTypes.ts +9 -0
- package/server/webArtifact.ts +86 -0
- package/server/webAssetRoutes.ts +84 -0
- package/server/webCsrSurface.ts +172 -0
- package/server/webDocumentRoute.ts +180 -0
- package/server/webRouteContext.ts +232 -0
- package/server/webRouter.ts +126 -1242
- package/server/webRscRoute.ts +155 -0
- package/server/webSiteFiles.ts +139 -0
- package/server/wellKnownRoutes.ts +73 -0
- package/service/agent.service.ts +59 -5
- package/service/agentAccounts.ts +19 -0
- package/service/agentLoop/agentLoop.ts +387 -0
- package/service/agentLoop/agentLoopTypes.ts +112 -0
- package/service/agentLoop/deltaStream.ts +40 -0
- package/service/agentLoop/loopCompaction.ts +135 -0
- package/service/agentLoop/loopRequest.ts +62 -0
- package/service/agentLoop/loopToolOutput.ts +54 -0
- package/service/agentLoop/loopToolkits.ts +107 -0
- package/service/agentLoop/loopTranscript.ts +102 -0
- package/{signal → service}/agentMeter.ts +83 -15
- package/{signal → service}/agentRelayPolicy.ts +30 -7
- package/service/documentStoreError.ts +16 -0
- package/service/index.ts +7 -0
- package/service/injectError.ts +5 -0
- package/service/injectInfo.ts +30 -18
- package/service/insightQueryError.ts +19 -0
- package/service/ipcTypes.ts +3 -1
- package/service/liveSyncHub.ts +5 -2
- package/service/predefinedAdaptor/agentTools.adaptor.ts +34 -0
- package/service/predefinedAdaptor/anthropicLlm.ts +52 -21
- package/service/predefinedAdaptor/cache.adaptor.ts +3 -2
- package/service/predefinedAdaptor/compress.adaptor.ts +7 -3
- package/service/predefinedAdaptor/database.adaptor.ts +3 -1
- package/service/predefinedAdaptor/documentTransfer.ts +2 -1
- package/service/predefinedAdaptor/index.ts +2 -0
- package/service/predefinedAdaptor/insightQuery.ts +35 -11
- package/service/predefinedAdaptor/llm.adaptor.ts +22 -2
- package/service/predefinedAdaptor/llmSpend.ts +80 -0
- package/service/predefinedAdaptor/openaiDialect.ts +52 -17
- package/service/predefinedAdaptor/openaiLlm.ts +17 -9
- package/service/predefinedAdaptor/role.adaptor.ts +2 -0
- package/service/predefinedAdaptor/searchIndex.ts +5 -1
- package/service/predefinedAdaptor/solidPubsub.adaptor.ts +35 -2
- package/service/predefinedAdaptor/solidQueue.adaptor.ts +2 -2
- package/service/predefinedAdaptor/solidSqlite.ts +3 -2
- package/service/predefinedAdaptor/sql/DocumentHydrator.ts +95 -0
- package/service/predefinedAdaptor/sql/DocumentRowCodec.ts +192 -0
- package/service/predefinedAdaptor/sql/DocumentWriter.ts +292 -0
- package/service/predefinedAdaptor/sql/PostgresInsightSession.ts +15 -5
- package/service/predefinedAdaptor/sql/QueryCompiler.ts +29 -13
- package/service/predefinedAdaptor/sql/QueryScope.ts +70 -0
- package/service/predefinedAdaptor/sql/QueryWriter.ts +200 -0
- package/service/predefinedAdaptor/sql/RawDocumentTable.ts +20 -8
- package/service/predefinedAdaptor/sql/SqlDocumentStore.ts +83 -1124
- package/service/predefinedAdaptor/sql/SqlTableSchema.ts +319 -0
- package/service/predefinedAdaptor/sql/SqliteInsightSession.ts +2 -1
- package/service/predefinedAdaptor/sql/StoredRows.ts +95 -0
- package/service/predefinedAdaptor/sql/UpdateCompiler.ts +6 -2
- package/service/predefinedAdaptor/sql/driver/bunSqlite.ts +3 -3
- package/service/predefinedAdaptor/sql/driver/postgres.ts +1 -1
- package/service/predefinedAdaptor/sql/fieldValues.ts +74 -0
- package/service/predefinedAdaptor/sql/search/fts5.ts +4 -1
- package/service/predefinedAdaptor/sql/search/postgres.ts +6 -2
- package/service/predefinedAdaptor/sql/values.ts +8 -4
- package/service/predefinedAdaptor/sseData.ts +14 -0
- package/service/predefinedAdaptor/storage.adaptor.ts +9 -4
- package/service/predefinedAdaptor/websocket.adaptor.ts +199 -43
- package/service/serve.ts +3 -2
- package/service/serviceModule.ts +2 -2
- package/service/serviceRegistry.ts +1 -0
- package/signal/SignalFailure.ts +30 -1
- package/signal/agent.signal.ts +30 -9
- package/signal/agentTurnStream.ts +12 -8
- package/signal/byIdRead.ts +18 -0
- package/signal/carriedClientIps.ts +1 -0
- package/signal/endpointErrorContract.ts +20 -2
- package/signal/endpointInfo.ts +6 -5
- package/signal/exception.ts +1 -0
- package/signal/index.ts +314 -30
- package/signal/internalInfo.ts +6 -4
- package/signal/mcp/McpDocument.ts +8 -1
- package/signal/mcp/Msg.ts +23 -10
- package/signal/mcp/index.ts +1 -0
- package/signal/mcp/promptError.ts +9 -0
- package/signal/middleware.ts +12 -3
- package/signal/openapi/openapi.ts +10 -1
- package/signal/resolveFieldContext.ts +34 -0
- package/signal/serializer/fetch.serializer.ts +23 -15
- package/signal/signalContext.ts +24 -57
- package/signal/signalContractError.ts +10 -0
- package/signal/signalDeclarationError.ts +13 -0
- package/signal/signalRegistry.ts +3 -1
- package/signal/slice.ts +24 -20
- package/signal/sliceInfo.ts +12 -9
- package/signal/trace.ts +3 -0
- package/signal/types.ts +35 -6
- package/store/action.ts +44 -1086
- package/store/actionErrorKey.ts +9 -0
- package/store/actionOption.ts +22 -0
- package/store/baseSt.ts +1 -0
- package/store/draftFlush.ts +5 -0
- package/store/draftStore.ts +2 -0
- package/store/formDrafts.ts +115 -0
- package/store/formFieldSetters.ts +229 -0
- package/store/index.ts +125 -17
- package/store/modelActionContext.ts +65 -0
- package/store/modelListPatch.ts +53 -0
- package/store/modelOpenActions.ts +158 -0
- package/store/modelWriteActions.ts +240 -0
- package/store/modelWriteGuard.ts +82 -0
- package/store/openSeq.ts +34 -0
- package/store/rootStore.ts +2 -0
- package/store/sliceListActions.ts +370 -0
- package/store/sliceLiveActions.ts +130 -0
- package/store/stateBuilder.ts +2 -0
- package/store/storeInstance.ts +9 -10
- package/store/uploadPoll.ts +52 -0
- package/store/withSelector.ts +6 -4
- package/types/base/base.d.ts +2 -1
- package/types/client/clientRuntime.d.ts +1 -0
- package/types/client/cn.d.ts +2 -2
- package/types/client/csrTypes.d.ts +15 -1
- package/types/client/frameConfig.d.ts +1 -0
- package/types/client/index.d.ts +25 -26
- package/types/client/locale.d.ts +1 -0
- package/types/client/makePageProto.d.ts +28 -26091
- package/types/client/nativeThemeColor.d.ts +6 -0
- package/types/client/route/RouteDefinition.d.ts +2 -2
- package/types/client/route/RouteHead.d.ts +5 -1
- package/types/client/route/routeArgs.d.ts +6 -0
- package/types/client/router.d.ts +6 -3
- package/types/client/rscNavigation.d.ts +3 -2
- package/types/client/rscRoutePatch.d.ts +22 -0
- package/types/client/viewportMeta.d.ts +3 -1
- package/types/common/CodeTranscript.d.ts +1 -1
- package/types/common/akanGraph.d.ts +1 -1
- package/types/common/err.d.ts +48 -0
- package/types/common/facetBarrel.d.ts +4 -0
- package/types/common/failureCode.d.ts +6 -0
- package/types/common/index.d.ts +8 -2
- package/types/common/isGuardRefusal.d.ts +3 -0
- package/types/common/mcpExposure.d.ts +9 -2
- package/types/common/mcpFailure.d.ts +6 -0
- package/types/common/restartSchedule.d.ts +16 -0
- package/types/common/routeConvention.d.ts +2 -0
- package/types/common/types.d.ts +18 -1
- package/types/constant/constantRegistry.d.ts +3 -1
- package/types/constant/crystalize.d.ts +1 -1
- package/types/constant/getDefault.d.ts +1 -1
- package/types/constant/immerify.d.ts +1 -1
- package/types/constant/index.d.ts +21 -21
- package/types/constant/purify.d.ts +2 -1
- package/types/constant/serialize.d.ts +1 -1
- package/types/constant/types.d.ts +1 -0
- package/types/dictionary/agent.dictionary.d.ts +1 -1
- package/types/dictionary/base.dictionary.d.ts +1 -1
- package/types/dictionary/dictionary.d.ts +9 -9
- package/types/dictionary/locale.d.ts +1 -1
- package/types/dictionary/trans.d.ts +3 -26
- package/types/document/databaseRegistry.d.ts +2 -1
- package/types/document/documentSchema.d.ts +1 -0
- package/types/document/filterMeta.d.ts +4 -1
- package/types/document/into.d.ts +1 -1
- package/types/document/loaderInfo.d.ts +2 -1
- package/types/document/noDocumentError.d.ts +8 -1
- package/types/document/queryEvaluator.d.ts +1 -1
- package/types/document/types.d.ts +1 -1
- package/types/fetch/client/fetchClient.d.ts +6 -36
- package/types/fetch/client/fetchClientTypes.d.ts +40 -0
- package/types/fetch/client/fetchHandle.d.ts +1 -0
- package/types/fetch/client/httpClient.d.ts +2 -0
- package/types/fetch/client/inflightQueries.d.ts +2 -0
- package/types/fetch/client/remoteError.d.ts +0 -4
- package/types/fetch/client/requestScope.d.ts +6 -0
- package/types/fetch/client/signalCatalog.d.ts +25 -0
- package/types/fetch/client/wsClient.d.ts +1 -0
- package/types/fetch/index.d.ts +1 -0
- package/types/fetch/staleReads.d.ts +8 -0
- package/types/fetch/streamedRead.d.ts +8 -0
- package/types/server/agentHooks.d.ts +4 -0
- package/types/server/akanApp.d.ts +2 -20
- package/types/server/akanOption.d.ts +9 -3
- package/types/server/akanServer.d.ts +1 -1
- package/types/server/artifact/builderRpc.d.ts +8 -0
- package/types/server/artifact/ipcTypes.d.ts +8 -0
- package/types/server/assetHeaders.d.ts +1 -0
- package/types/server/console.d.ts +4 -3
- package/types/server/devtools/devtoolsRouter.d.ts +4 -1
- package/types/server/devtools/studio/studioRoute.d.ts +2 -1
- package/types/server/di/predefinedAdaptor.d.ts +1 -0
- package/types/server/ed25519Key.d.ts +1 -0
- package/types/server/flightRowReader.d.ts +3 -1
- package/types/server/gateway/childSupervisor.d.ts +33 -0
- package/types/server/gateway/devHostChannel.d.ts +14 -0
- package/types/server/gateway/gatewayChildren.d.ts +47 -0
- package/types/server/gateway/gatewayConfig.d.ts +82 -0
- package/types/server/gateway/gatewayHttpProxy.d.ts +22 -0
- package/types/server/gateway/gatewayLogging.d.ts +16 -0
- package/types/server/gateway/gatewayRooms.d.ts +25 -0
- package/types/server/gateway/gatewayStatus.d.ts +62 -0
- package/types/server/gateway/gatewayStatusPage.d.ts +9 -0
- package/types/server/gateway/gatewayWebSocketRelay.d.ts +17 -0
- package/types/server/head.d.ts +2 -2
- package/types/server/htmlResultCache.d.ts +51 -0
- package/types/server/index.d.ts +17 -17
- package/types/server/lifecycle/parentChannel.d.ts +13 -0
- package/types/server/lifecycle/startGuard.d.ts +10 -0
- package/types/server/logging/rotatingLogWriter.d.ts +1 -1
- package/types/server/logging/serverLogging.d.ts +12 -0
- package/types/server/mcp/AgentTools.d.ts +31 -0
- package/types/server/mcp/AgentToolsAccount.d.ts +7 -0
- package/types/server/mcp/McpDispatcher.d.ts +10 -1
- package/types/server/mcp/McpPages.d.ts +2 -1
- package/types/server/mcp/McpRateLimiter.d.ts +3 -0
- package/types/server/mcp/index.d.ts +1 -0
- package/types/server/resolver/database.resolver.d.ts +2 -2
- package/types/server/resolver/databaseModelInstance.d.ts +4 -0
- package/types/server/resolver/invalidSignal.d.ts +2 -0
- package/types/server/resolver/livePause.d.ts +5 -0
- package/types/server/resolver/modelFacade.d.ts +5 -0
- package/types/server/resolver/modelLoaders.d.ts +9 -0
- package/types/server/resolver/modelSchema.d.ts +6 -0
- package/types/server/resolver/signal.resolver.d.ts +2 -2
- package/types/server/resolver/timedQuery.d.ts +8 -0
- package/types/server/resolver/websocketOf.d.ts +2 -0
- package/types/server/routeElementComposer.d.ts +45 -6
- package/types/server/routeState.d.ts +2 -0
- package/types/server/routing/builtinRoutes.d.ts +24 -0
- package/types/server/routing/localRooms.d.ts +14 -0
- package/types/server/routing/roomReplay.d.ts +2 -2
- package/types/server/routing/serverListener.d.ts +31 -0
- package/types/server/rscClient.d.ts +1 -5
- package/types/server/rscClientCache.d.ts +34 -0
- package/types/server/rscClientChunks.d.ts +18 -0
- package/types/server/rscClientFetch.d.ts +1 -1
- package/types/server/rscClientPatch.d.ts +12 -1
- package/types/server/rscDocumentHead.d.ts +32 -0
- package/types/server/rscFlightRenderer.d.ts +14 -0
- package/types/server/rscFlightStream.d.ts +52 -0
- package/types/server/rscHeadPatch.d.ts +5 -4
- package/types/server/rscHostReloads.d.ts +54 -0
- package/types/server/rscHostRenderStream.d.ts +53 -0
- package/types/server/rscHostRequests.d.ts +29 -0
- package/types/server/rscHttp.d.ts +4 -2
- package/types/server/rscInlineStream.d.ts +9 -0
- package/types/server/rscNavigationState.d.ts +8 -3
- package/types/server/rscParkedRedirect.d.ts +12 -0
- package/types/server/rscPatchPlanner.d.ts +49 -0
- package/types/server/rscPrefetchCache.d.ts +8 -7
- package/types/server/rscRenderControl.d.ts +12 -0
- package/types/server/rscRenderFallbacks.d.ts +41 -0
- package/types/server/rscRenderHandler.d.ts +29 -0
- package/types/server/rscRenderStats.d.ts +32 -0
- package/types/server/rscResponse.d.ts +9 -0
- package/types/server/rscResultCaches.d.ts +18 -0
- package/types/server/rscRouteDocument.d.ts +52 -0
- package/types/server/rscSegmentOutlet.d.ts +5 -0
- package/types/server/rscSegmentOutletReference.d.ts +2 -1
- package/types/server/rscWorker.d.ts +1 -3
- package/types/server/rscWorkerCache.d.ts +33 -1
- package/types/server/rscWorkerHost.d.ts +9 -76
- package/types/server/rscWorkerProcess.d.ts +31 -0
- package/types/server/rscWorkerRecycler.d.ts +22 -0
- package/types/server/serverConfig.d.ts +30 -0
- package/types/server/serverMetrics.d.ts +11 -0
- package/types/server/sitemap.d.ts +1 -0
- package/types/server/ssrFromRscRenderer.d.ts +2 -2
- package/types/server/ssrTypes.d.ts +8 -0
- package/types/server/webArtifact.d.ts +7 -0
- package/types/server/webAssetRoutes.d.ts +11 -0
- package/types/server/webCsrSurface.d.ts +18 -0
- package/types/server/webDocumentRoute.d.ts +19 -0
- package/types/server/webRouteContext.d.ts +45 -0
- package/types/server/webRouter.d.ts +4 -35
- package/types/server/webRscRoute.d.ts +24 -0
- package/types/server/webSiteFiles.d.ts +12 -0
- package/types/server/wellKnownRoutes.d.ts +5 -0
- package/types/service/agent.service.d.ts +13 -4
- package/types/service/agentAccounts.d.ts +8 -0
- package/types/service/agentLoop/agentLoop.d.ts +31 -0
- package/types/service/agentLoop/agentLoopTypes.d.ts +126 -0
- package/types/service/agentLoop/deltaStream.d.ts +3 -0
- package/types/service/agentLoop/loopCompaction.d.ts +11 -0
- package/types/service/agentLoop/loopRequest.d.ts +6 -0
- package/types/service/agentLoop/loopToolOutput.d.ts +7 -0
- package/types/service/agentLoop/loopToolkits.d.ts +14 -0
- package/types/service/agentLoop/loopTranscript.d.ts +12 -0
- package/types/service/agentMeter.d.ts +50 -0
- package/types/service/agentRelayPolicy.d.ts +45 -0
- package/types/service/documentStoreError.d.ts +7 -0
- package/types/service/index.d.ts +7 -0
- package/types/service/injectError.d.ts +4 -0
- package/types/service/injectInfo.d.ts +2 -1
- package/types/service/insightQueryError.d.ts +9 -0
- package/types/service/ipcTypes.d.ts +6 -0
- package/types/service/predefinedAdaptor/agentTools.adaptor.d.ts +31 -0
- package/types/service/predefinedAdaptor/anthropicLlm.d.ts +2 -2
- package/types/service/predefinedAdaptor/index.d.ts +2 -0
- package/types/service/predefinedAdaptor/llm.adaptor.d.ts +18 -2
- package/types/service/predefinedAdaptor/llmSpend.d.ts +22 -0
- package/types/service/predefinedAdaptor/openaiDialect.d.ts +2 -1
- package/types/service/predefinedAdaptor/openaiLlm.d.ts +1 -1
- package/types/service/predefinedAdaptor/role.adaptor.d.ts +2 -0
- package/types/service/predefinedAdaptor/solidPubsub.adaptor.d.ts +3 -0
- package/types/service/predefinedAdaptor/solidSqlite.d.ts +1 -1
- package/types/service/predefinedAdaptor/sql/DocumentHydrator.d.ts +11 -0
- package/types/service/predefinedAdaptor/sql/DocumentRowCodec.d.ts +26 -0
- package/types/service/predefinedAdaptor/sql/DocumentWriter.d.ts +24 -0
- package/types/service/predefinedAdaptor/sql/QueryScope.d.ts +16 -0
- package/types/service/predefinedAdaptor/sql/QueryWriter.d.ts +20 -0
- package/types/service/predefinedAdaptor/sql/SqlDocumentStore.d.ts +1 -32
- package/types/service/predefinedAdaptor/sql/SqlTableSchema.d.ts +20 -0
- package/types/service/predefinedAdaptor/sql/StoredRows.d.ts +27 -0
- package/types/service/predefinedAdaptor/sql/driver/bunSqlite.d.ts +1 -14
- package/types/service/predefinedAdaptor/sql/driver/postgres.d.ts +0 -8
- package/types/service/predefinedAdaptor/sql/fieldValues.d.ts +5 -0
- package/types/service/predefinedAdaptor/sseData.d.ts +5 -0
- package/types/service/predefinedAdaptor/websocket.adaptor.d.ts +14 -5
- package/types/service/serviceModule.d.ts +1 -1
- package/types/service/serviceRegistry.d.ts +1 -0
- package/types/signal/SignalFailure.d.ts +2 -0
- package/types/signal/agentTurnStream.d.ts +2 -1
- package/types/signal/byIdRead.d.ts +7 -0
- package/types/signal/carriedClientIps.d.ts +4 -0
- package/types/signal/endpointErrorContract.d.ts +3 -0
- package/types/signal/exception.d.ts +1 -0
- package/types/signal/index.d.ts +32 -30
- package/types/signal/mcp/McpDocument.d.ts +2 -0
- package/types/signal/mcp/index.d.ts +1 -0
- package/types/signal/mcp/promptError.d.ts +5 -0
- package/types/signal/resolveFieldContext.d.ts +15 -0
- package/types/signal/serializer/fetch.serializer.d.ts +3 -1
- package/types/signal/signalContext.d.ts +1 -13
- package/types/signal/signalContractError.d.ts +4 -0
- package/types/signal/signalDeclarationError.d.ts +4 -0
- package/types/signal/slice.d.ts +15 -13
- package/types/signal/trace.d.ts +3 -0
- package/types/signal/types.d.ts +33 -6
- package/types/store/action.d.ts +8 -27
- package/types/store/actionErrorKey.d.ts +1 -0
- package/types/store/actionOption.d.ts +24 -0
- package/types/store/baseSt.d.ts +2 -295
- package/types/store/draftFlush.d.ts +4 -0
- package/types/store/formDrafts.d.ts +21 -0
- package/types/store/formFieldSetters.d.ts +80 -0
- package/types/store/index.d.ts +17 -16
- package/types/store/modelActionContext.d.ts +189 -0
- package/types/store/modelListPatch.d.ts +34 -0
- package/types/store/modelOpenActions.d.ts +12 -0
- package/types/store/modelWriteActions.d.ts +16 -0
- package/types/store/modelWriteGuard.d.ts +42 -0
- package/types/store/openSeq.d.ts +17 -0
- package/types/store/rootStore.d.ts +6 -0
- package/types/store/sliceListActions.d.ts +295 -0
- package/types/store/sliceLiveActions.d.ts +6 -0
- package/types/store/stateBuilder.d.ts +2 -0
- package/types/store/uploadPoll.d.ts +16 -0
- package/types/store/withSelector.d.ts +1 -1
- package/types/ui/Agent/Chat.d.ts +5 -2
- package/types/ui/Agent/ChatHeader.d.ts +13 -0
- package/types/ui/Agent/ChatPendingCards.d.ts +23 -0
- package/types/ui/Field/Choice.d.ts +2 -1
- package/types/ui/Field/index.d.ts +1 -1
- package/types/ui/Link/inputModality.d.ts +5 -0
- package/types/ui/Link/viewportPrefetch.d.ts +4 -0
- package/types/ui/Load/Edit_Client.d.ts +2 -0
- package/types/ui/Load/Pagination.d.ts +4 -1
- package/types/ui/Load/Stream.d.ts +7 -1
- package/types/ui/Load/StreamBoundary.d.ts +20 -0
- package/types/ui/Load/Units.d.ts +2 -0
- package/types/ui/Load/View.d.ts +2 -0
- package/types/ui/Reference/origin.d.ts +1 -0
- package/types/ui/index.d.ts +1 -1
- package/types/ui/overlayLayer.d.ts +6 -1
- package/types/ui/recipe/badgeRecipe.d.ts +3 -3
- package/types/ui/recipe/buttonRecipe.d.ts +3 -3
- package/types/ui/recipe/inputRecipe.d.ts +1 -1
- package/types/vendor/@akanjs/native/packages/cli/src/lib/project.d.ts +4 -0
- package/types/vendor/@akanjs/native/packages/desktop/src/relaunch.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/appearance/src/index.d.ts +9 -0
- package/types/vendor/@akanjs/native/plugins/external-view/src/index.d.ts +18 -11
- package/types/vendor/use-agentic/AgentClientTools.d.ts +19 -0
- package/types/vendor/use-agentic/failureCode.d.ts +4 -0
- package/types/vendor/use-agentic/index.d.ts +1 -0
- package/types/vendor/use-agentic/types.d.ts +11 -0
- package/types/webkit/CsrGuards.d.ts +2 -0
- package/types/webkit/RouteLevelBoundary.d.ts +17 -0
- package/types/webkit/nativeCore.d.ts +1 -0
- package/types/webkit/nativePurchase.d.ts +2 -1
- package/types/webkit/useCsrKeyboard.d.ts +19 -0
- package/types/webkit/useCsrLocationState.d.ts +21 -0
- package/types/webkit/useCsrNavigation.d.ts +25 -0
- package/types/webkit/useCsrRefs.d.ts +33 -0
- package/types/webkit/useCsrRenderTrace.d.ts +13 -0
- package/types/webkit/useCsrStackLifecycle.d.ts +12 -0
- package/types/webkit/useCsrTransitions.d.ts +2 -0
- package/types/webkit/useFrameRuntime.d.ts +1 -0
- package/types/webkit/useGeoLocation.d.ts +1 -1
- package/types/webkit/useHistory.d.ts +2 -3
- package/types/webkit/usePurchase.d.ts +1 -1
- package/types/webkit/useResolvedFrame.d.ts +38 -0
- package/types/webkit/useSyncNavigation.d.ts +22 -0
- package/types/webkit/useTransitionStore.d.ts +1 -0
- package/ui/Agent/Chat.tsx +392 -235
- package/ui/Agent/ChatHeader.tsx +59 -0
- package/ui/Agent/ChatPendingCards.tsx +49 -0
- package/ui/Agent/fetchRunner.ts +8 -1
- package/ui/BottomSheet.tsx +1 -1
- package/ui/Button.tsx +1 -0
- package/ui/Data/Item.tsx +2 -2
- package/ui/Data/ListContainer.tsx +348 -181
- package/ui/Data/useViewModal.ts +10 -4
- package/ui/Dialog/LegacyModal.tsx +1 -1
- package/ui/Dialog/Modal.tsx +1 -1
- package/ui/Field/Choice.tsx +3 -1
- package/ui/Link/inputModality.ts +21 -0
- package/ui/Link/prefetchIntent.ts +7 -25
- package/ui/Link/viewportPrefetch.ts +30 -0
- package/ui/Load/Edit_Client.tsx +7 -1
- package/ui/Load/Pagination.tsx +10 -2
- package/ui/Load/Stream.tsx +24 -4
- package/ui/Load/StreamBoundary.tsx +65 -0
- package/ui/Load/Units.tsx +3 -0
- package/ui/Load/View.tsx +5 -1
- package/ui/Model/EditModal.tsx +2 -1
- package/ui/Popconfirm.tsx +1 -1
- package/ui/Reference/origin.ts +1 -0
- package/ui/Select.tsx +43 -51
- package/ui/Signal/RestApi.tsx +3 -2
- package/ui/System/Client.tsx +32 -8
- package/ui/index.ts +4 -0
- package/ui/overlayLayer.ts +22 -1
- package/vendor/@akanjs/native/CHANGELOG.md +7 -1
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeActivity.kt +27 -12
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativePlugin.kt +4 -0
- package/vendor/@akanjs/native/native/desktop/src/external.rs +213 -111
- package/vendor/@akanjs/native/native/desktop/src/lib.rs +12 -4
- package/vendor/@akanjs/native/native/desktop/src/linux/external.rs +509 -0
- package/vendor/@akanjs/native/native/desktop/src/linux/mod.rs +1 -0
- package/vendor/@akanjs/native/native/ios/Sources/AkanNativeViewController.swift +6 -1
- package/vendor/@akanjs/native/packages/cli/src/lib/native-plugins.ts +5 -3
- package/vendor/@akanjs/native/packages/cli/src/lib/project.ts +25 -1
- package/vendor/@akanjs/native/packages/desktop/src/deeplinks.ts +2 -2
- package/vendor/@akanjs/native/packages/desktop/src/host.ts +2 -2
- package/vendor/@akanjs/native/packages/desktop/src/relaunch.ts +8 -3
- package/vendor/@akanjs/native/plugins/app/src/desktop.ts +2 -2
- package/vendor/@akanjs/native/plugins/appearance/android/AppearancePlugin.kt +13 -0
- package/vendor/@akanjs/native/plugins/appearance/ios/AppearancePlugin.swift +27 -0
- package/vendor/@akanjs/native/plugins/appearance/native-plugin.json +2 -2
- package/vendor/@akanjs/native/plugins/appearance/src/index.ts +8 -1
- package/vendor/@akanjs/native/plugins/autostart/src/desktop.ts +2 -1
- package/vendor/@akanjs/native/plugins/external-view/native-plugin.json +4 -1
- package/vendor/@akanjs/native/plugins/external-view/src/index.ts +18 -11
- package/vendor/use-agentic/AgentClientTools.ts +33 -0
- package/vendor/use-agentic/AgentSession.ts +11 -11
- package/vendor/use-agentic/CHANGELOG.md +46 -1
- package/vendor/use-agentic/Compaction.ts +2 -1
- package/vendor/use-agentic/ToolRunner.ts +6 -3
- package/vendor/use-agentic/Transcript.ts +6 -3
- package/vendor/use-agentic/WIRE.md +29 -7
- package/vendor/use-agentic/failureCode.ts +44 -0
- package/vendor/use-agentic/httpRunner.ts +15 -4
- package/vendor/use-agentic/index.ts +1 -0
- package/vendor/use-agentic/types.ts +11 -0
- package/webkit/CsrGuards.ts +7 -2
- package/webkit/McpAppAgent.ts +8 -3
- package/webkit/McpAppFetchBridge.ts +11 -5
- package/webkit/RouteLevelBoundary.tsx +37 -0
- package/webkit/nativeCore.ts +1 -0
- package/webkit/nativePurchase.ts +6 -3
- package/webkit/useCamera.tsx +22 -21
- package/webkit/useCsrKeyboard.ts +155 -0
- package/webkit/useCsrLocationState.ts +58 -0
- package/webkit/useCsrNavigation.ts +302 -0
- package/webkit/useCsrRefs.ts +52 -0
- package/webkit/useCsrRenderTrace.ts +68 -0
- package/webkit/useCsrStackLifecycle.ts +120 -0
- package/webkit/useCsrTransitions.ts +552 -0
- package/webkit/useCsrValues.ts +69 -1234
- package/webkit/useGeoLocation.tsx +4 -1
- package/webkit/useHistory.ts +2 -2
- package/webkit/useLocation.ts +3 -2
- package/webkit/usePurchase.tsx +4 -2
- package/webkit/useResolvedFrame.ts +116 -0
- package/webkit/useSyncNavigation.ts +109 -0
- package/webkit/useTransitionStore.ts +13 -0
- package/types/signal/agentMeter.d.ts +0 -27
- package/types/signal/agentRelayPolicy.d.ts +0 -25
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { assetHeaders, missingAssetResponse } from "./assetHeaders";
|
|
2
|
+
import type { ImageOptimizer } from "./imageOptimizer";
|
|
3
|
+
import { resolveStaticPath } from "./staticPath";
|
|
4
|
+
import type { HttpRoutes } from "./types";
|
|
5
|
+
import { WebRouteContext } from "./webRouteContext";
|
|
6
|
+
|
|
7
|
+
interface WebAssetRoutesOptions {
|
|
8
|
+
artifactDir: string;
|
|
9
|
+
imageOptimizer: ImageOptimizer;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class WebAssetRoutes {
|
|
13
|
+
static build(context: WebRouteContext, { artifactDir, imageOptimizer }: WebAssetRoutesOptions): HttpRoutes {
|
|
14
|
+
const clientServePrefix = `/_akan/client`;
|
|
15
|
+
const clientOutputDir = `${artifactDir}/client`;
|
|
16
|
+
const dictServePrefix = "/_akan/dict";
|
|
17
|
+
const dictOutputDir = `${artifactDir}/dict`;
|
|
18
|
+
const stylesServePrefix = "/_akan/styles";
|
|
19
|
+
const stylesOutputDir = `${artifactDir}/styles`;
|
|
20
|
+
const fontsServePrefix = "/_akan/fonts";
|
|
21
|
+
const fontsOutputDir = `${artifactDir}/fonts`;
|
|
22
|
+
const { stats, prodMode } = context;
|
|
23
|
+
return {
|
|
24
|
+
[`${clientServePrefix}/*`]: async (req) => {
|
|
25
|
+
stats.staticAsset += 1;
|
|
26
|
+
const url = new URL(req.url);
|
|
27
|
+
const filePath = resolveStaticPath(clientOutputDir, url.pathname.slice(clientServePrefix.length + 1));
|
|
28
|
+
if (!filePath) return missingAssetResponse();
|
|
29
|
+
return WebRouteContext.fileResponse(req, filePath, {
|
|
30
|
+
contentType: Bun.file(filePath).type || "application/javascript",
|
|
31
|
+
cacheControl: prodMode ? "public, max-age=31536000, immutable" : "no-store",
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
[`${stylesServePrefix}/*`]: (req) => {
|
|
35
|
+
stats.staticAsset += 1;
|
|
36
|
+
const url = new URL(req.url);
|
|
37
|
+
if (prodMode) {
|
|
38
|
+
const filePath = resolveStaticPath(stylesOutputDir, url.pathname.slice(`${stylesServePrefix}/`.length));
|
|
39
|
+
if (filePath) {
|
|
40
|
+
return WebRouteContext.fileResponse(req, filePath, {
|
|
41
|
+
contentType: "text/css; charset=utf-8",
|
|
42
|
+
cacheControl: "public, max-age=31536000, immutable",
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const cssBytes = context.renderState.cssBytesByUrl[url.pathname];
|
|
47
|
+
if (!cssBytes) return new Response("Not Found", { status: 404 });
|
|
48
|
+
const headers = assetHeaders({
|
|
49
|
+
contentType: "text/css; charset=utf-8",
|
|
50
|
+
cacheControl: "no-store",
|
|
51
|
+
});
|
|
52
|
+
return new Response(
|
|
53
|
+
cssBytes.buffer.slice(cssBytes.byteOffset, cssBytes.byteOffset + cssBytes.byteLength) as ArrayBuffer,
|
|
54
|
+
{ headers },
|
|
55
|
+
);
|
|
56
|
+
},
|
|
57
|
+
[`${fontsServePrefix}/*`]: (req) => {
|
|
58
|
+
stats.staticAsset += 1;
|
|
59
|
+
const url = new URL(req.url);
|
|
60
|
+
const filePath = resolveStaticPath(fontsOutputDir, url.pathname.slice(`${fontsServePrefix}/`.length));
|
|
61
|
+
if (!filePath) return new Response("Not Found", { status: 404 });
|
|
62
|
+
return WebRouteContext.fileResponse(req, filePath, {
|
|
63
|
+
contentType: Bun.file(filePath).type || "font/woff2",
|
|
64
|
+
cacheControl: prodMode ? "public, max-age=31536000, immutable" : "no-store",
|
|
65
|
+
anyOrigin: true,
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
[`${dictServePrefix}/*`]: (req) => {
|
|
69
|
+
stats.staticAsset += 1;
|
|
70
|
+
const url = new URL(req.url);
|
|
71
|
+
const filePath = resolveStaticPath(dictOutputDir, url.pathname.slice(`${dictServePrefix}/`.length));
|
|
72
|
+
if (!filePath) return new Response("Not Found", { status: 404 });
|
|
73
|
+
return WebRouteContext.fileResponse(req, filePath, {
|
|
74
|
+
contentType: "text/javascript; charset=utf-8",
|
|
75
|
+
cacheControl: prodMode ? "public, max-age=31536000, immutable" : "no-store",
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
"/_akan/image": (req) => {
|
|
79
|
+
stats.image += 1;
|
|
80
|
+
return imageOptimizer.handle(req);
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { getBasePathFromPathname } from "akanjs/common";
|
|
4
|
+
import type { BuilderRpc } from "./artifact";
|
|
5
|
+
import { HMR_CLIENT_SCRIPT } from "./hmr/clientScript";
|
|
6
|
+
import { CSR_DEV_ROUTE_PREFIX } from "./hmr/csrDevManifest";
|
|
7
|
+
import type { CsrDevShell } from "./hmr/csrDevShell";
|
|
8
|
+
import { resolveStaticPath } from "./staticPath";
|
|
9
|
+
import type { BaseBuildArtifact, HttpRoutes } from "./types";
|
|
10
|
+
import { WebRouteContext } from "./webRouteContext";
|
|
11
|
+
|
|
12
|
+
interface WebCsrSurfaceOptions {
|
|
13
|
+
devShell: CsrDevShell | null;
|
|
14
|
+
builderRpc: () => BuilderRpc | null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class WebCsrSurface {
|
|
18
|
+
readonly #context: WebRouteContext;
|
|
19
|
+
readonly devShell: CsrDevShell | null;
|
|
20
|
+
readonly #builderRpc: () => BuilderRpc | null;
|
|
21
|
+
#armed = false;
|
|
22
|
+
readonly #builds = new Map<string, Promise<unknown>>();
|
|
23
|
+
|
|
24
|
+
constructor(context: WebRouteContext, { devShell, builderRpc }: WebCsrSurfaceOptions) {
|
|
25
|
+
this.#context = context;
|
|
26
|
+
this.devShell = devShell;
|
|
27
|
+
this.#builderRpc = builderRpc;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
routes(csrOutputDir: string): HttpRoutes {
|
|
31
|
+
const { stats } = this.#context;
|
|
32
|
+
return {
|
|
33
|
+
"/__csr": async (req) => {
|
|
34
|
+
stats.csr += 1;
|
|
35
|
+
if (this.devShell) return await this.#serveDevShell(req, "/", this.devShell);
|
|
36
|
+
const csrHtml = await this.#resolveCsrHtml(csrOutputDir, "/");
|
|
37
|
+
const csrFile = csrHtml ? Bun.file(csrHtml) : null;
|
|
38
|
+
const htmlText =
|
|
39
|
+
csrFile && (await csrFile.exists())
|
|
40
|
+
? await csrFile.text()
|
|
41
|
+
: `<!doctype html>
|
|
42
|
+
<html lang="en">
|
|
43
|
+
<head>
|
|
44
|
+
<meta charset="utf-8" />
|
|
45
|
+
<title>Minimal</title>
|
|
46
|
+
<base href="/" />
|
|
47
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
48
|
+
</head>
|
|
49
|
+
<body>
|
|
50
|
+
<div id="root"></div>
|
|
51
|
+
<script type="module" src="/csr.js"></script>
|
|
52
|
+
</body>
|
|
53
|
+
</html>`;
|
|
54
|
+
return new Response(this.#withCsrHmr(htmlText), { headers: this.#context.htmlResponseHeaders(200, req) });
|
|
55
|
+
},
|
|
56
|
+
...(this.devShell
|
|
57
|
+
? {
|
|
58
|
+
[`${CSR_DEV_ROUTE_PREFIX}*`]: async (req: Request) => {
|
|
59
|
+
stats.staticAsset += 1;
|
|
60
|
+
return (await this.devShell?.serve(req)) ?? new Response("Not Found", { status: 404 });
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
: {}),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async answer(req: Request, url: URL, csrOutputDir: string): Promise<Response | null> {
|
|
68
|
+
const { stats, prodMode } = this.#context;
|
|
69
|
+
const isCsr = url.searchParams.get("csr") === "true";
|
|
70
|
+
if (isCsr) {
|
|
71
|
+
stats.csr += 1;
|
|
72
|
+
if (this.devShell) return await this.#serveDevShell(req, url.pathname, this.devShell);
|
|
73
|
+
const csrHtml = await this.#resolveCsrHtml(csrOutputDir, url.pathname);
|
|
74
|
+
if (!csrHtml) return this.#unavailableResponse(url.pathname);
|
|
75
|
+
const html = await Bun.file(csrHtml).text();
|
|
76
|
+
return new Response(this.#withCsrHmr(html), { headers: this.#context.htmlResponseHeaders(200, req) });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const csrAssetPath = path.extname(url.pathname) ? resolveStaticPath(csrOutputDir, url.pathname) : null;
|
|
80
|
+
if (csrAssetPath && (await Bun.file(csrAssetPath).exists())) {
|
|
81
|
+
stats.staticAsset += 1;
|
|
82
|
+
return WebRouteContext.fileResponse(req, csrAssetPath, {
|
|
83
|
+
contentType: Bun.file(csrAssetPath).type || "application/octet-stream",
|
|
84
|
+
cacheControl: prodMode ? "public, max-age=31536000, immutable" : undefined,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
#withCsrHmr(html: string): string {
|
|
91
|
+
if (this.#context.prodMode) return html;
|
|
92
|
+
const csrGeneration = this.#context.renderState.csrGeneration ?? null;
|
|
93
|
+
const flags = `self.__AKAN_HMR_CLIENT__="csr";self.__AKAN_CSR_GENERATION__=${csrGeneration};`;
|
|
94
|
+
return WebCsrSurface.#injectBeforeBodyEnd(html, `<script>${flags}${HMR_CLIENT_SCRIPT}</script>`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async #serveDevShell(req: Request, pathname: string, shell: CsrDevShell): Promise<Response> {
|
|
98
|
+
await this.armArtifact(pathname);
|
|
99
|
+
const { artifact } = this.#context;
|
|
100
|
+
const basePath = getBasePathFromPathname(pathname, { basePaths: artifact.basePaths, i18n: artifact.i18n }) ?? "";
|
|
101
|
+
const html = await shell.render({
|
|
102
|
+
basePath,
|
|
103
|
+
lang: "en",
|
|
104
|
+
title: process.env.AKAN_PUBLIC_APP_NAME ?? "akan",
|
|
105
|
+
cssHref: this.#context.stylesheetHref(req, pathname),
|
|
106
|
+
});
|
|
107
|
+
if (!html) return this.#unavailableResponse(pathname);
|
|
108
|
+
return new Response(this.#withCsrHmr(html), { headers: this.#context.htmlResponseHeaders(200, req) });
|
|
109
|
+
}
|
|
110
|
+
async #resolveCsrHtml(csrOutputDir: string, pathname: string): Promise<string | null> {
|
|
111
|
+
const resolved = WebCsrSurface.#resolveCsrHtmlPath(csrOutputDir, pathname, this.#context.artifact);
|
|
112
|
+
if (resolved) return resolved;
|
|
113
|
+
await this.armArtifact(pathname);
|
|
114
|
+
return WebCsrSurface.#resolveCsrHtmlPath(csrOutputDir, pathname, this.#context.artifact);
|
|
115
|
+
}
|
|
116
|
+
armArtifact(reason: string): Promise<unknown> {
|
|
117
|
+
const rpc = this.#builderRpc();
|
|
118
|
+
|
|
119
|
+
if (this.#armed || !rpc) return Promise.resolve();
|
|
120
|
+
return this.#singleFlight("csr", () =>
|
|
121
|
+
rpc
|
|
122
|
+
.buildCsr(reason)
|
|
123
|
+
.then(() => {
|
|
124
|
+
this.#armed = true;
|
|
125
|
+
this.#context.logger.info(`[csr] dev CSR artifact built on demand (${reason})`);
|
|
126
|
+
})
|
|
127
|
+
.catch((err: unknown) => {
|
|
128
|
+
this.#context.logger.error(
|
|
129
|
+
`[csr] on-demand build failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
130
|
+
);
|
|
131
|
+
}),
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async buildMcpAppViews(): Promise<void> {
|
|
136
|
+
const rpc = this.#builderRpc();
|
|
137
|
+
if (!rpc) return;
|
|
138
|
+
await this.#singleFlight("mcpShell", () =>
|
|
139
|
+
rpc.buildCsr("mcp app view", { shell: true }).catch((err: unknown) => {
|
|
140
|
+
this.#context.logger.error(`[mcp] view build failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
141
|
+
}),
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
#singleFlight(kind: string, run: () => Promise<unknown>): Promise<unknown> {
|
|
145
|
+
const pending = this.#builds.get(kind) ?? run().finally(() => this.#builds.delete(kind));
|
|
146
|
+
this.#builds.set(kind, pending);
|
|
147
|
+
return pending;
|
|
148
|
+
}
|
|
149
|
+
#unavailableResponse(pathname: string): Response {
|
|
150
|
+
if (this.#context.prodMode) return new Response("Not Found", { status: 404 });
|
|
151
|
+
const message = `No CSR artifact for ${pathname}. Dev CSR is built on demand; check the dev server log for a csr-build failure and verify the basePath in the URL.`;
|
|
152
|
+
this.#context.logger.warn(`[csr] ${message}`);
|
|
153
|
+
return new Response(message, { status: 404, headers: { "Content-Type": "text/plain; charset=utf-8" } });
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
static #injectBeforeBodyEnd(html: string, snippet: string): string {
|
|
157
|
+
const matches = [...html.matchAll(/<\/body\s*>/gi)];
|
|
158
|
+
const last = matches.at(-1);
|
|
159
|
+
if (!last || last.index === undefined) return `${html}\n${snippet}`;
|
|
160
|
+
return `${html.slice(0, last.index)}${snippet}\n${html.slice(last.index)}`;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
static #resolveCsrHtmlPath(csrOutputDir: string, pathname: string, artifact: BaseBuildArtifact): string | null {
|
|
164
|
+
const basePath = getBasePathFromPathname(pathname, {
|
|
165
|
+
basePaths: artifact.basePaths,
|
|
166
|
+
i18n: artifact.i18n,
|
|
167
|
+
});
|
|
168
|
+
const filename = basePath ? `${basePath}.html` : "index.html";
|
|
169
|
+
const filePath = resolveStaticPath(csrOutputDir, filename);
|
|
170
|
+
return filePath && fs.existsSync(filePath) ? filePath : null;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { type AkanRequestStore, createRequestStore } from "akanjs/fetch";
|
|
2
|
+
import { SignalContext } from "../signal/signalContext";
|
|
3
|
+
import type { MergedManifest, ModulePreloadPlan } from "./artifact";
|
|
4
|
+
import { encodedBodyResponse } from "./contentEncoding";
|
|
5
|
+
import { isCrawlerUserAgent } from "./crawler";
|
|
6
|
+
import { HMR_CLIENT_SCRIPT } from "./hmr/clientScript";
|
|
7
|
+
import type { CsrDevShell } from "./hmr/csrDevShell";
|
|
8
|
+
import { SsrDevShim } from "./hmr/ssrDevShim";
|
|
9
|
+
import type { HtmlResultCache } from "./htmlResultCache";
|
|
10
|
+
import type { RscRedirectStatus, RscRenderResult, RscWorker } from "./rscWorkerHost";
|
|
11
|
+
import { SessionRefresh } from "./sessionRefresh";
|
|
12
|
+
import { SsrFromRscRenderer } from "./ssrFromRscRenderer";
|
|
13
|
+
import { WebRouteContext } from "./webRouteContext";
|
|
14
|
+
|
|
15
|
+
type RscStreamResult = Extract<RscRenderResult, { type: "stream" }>;
|
|
16
|
+
|
|
17
|
+
interface WebDocumentRouteOptions {
|
|
18
|
+
rsc: RscWorker;
|
|
19
|
+
importMapKey: string;
|
|
20
|
+
ssrDevShell: CsrDevShell | null;
|
|
21
|
+
htmlCache: HtmlResultCache;
|
|
22
|
+
modulePreloadPlan?: ModulePreloadPlan;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface HtmlRenderInput {
|
|
26
|
+
rscResult: RscStreamResult;
|
|
27
|
+
manifest: MergedManifest;
|
|
28
|
+
isCrawler: boolean;
|
|
29
|
+
hostRequestStore: AkanRequestStore;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function createDocumentRedirectResponse(location: string, requestUrl: URL, status: RscRedirectStatus): Response {
|
|
33
|
+
const target = new URL(location, requestUrl.origin);
|
|
34
|
+
const sameOrigin = target.origin === requestUrl.origin && !target.pathname.startsWith("//");
|
|
35
|
+
const href = sameOrigin ? `${target.pathname}${target.search}${target.hash}` : target.href;
|
|
36
|
+
return new Response(null, { status, headers: { Location: href, "Cache-Control": "no-store" } });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function cancelStreamForHeadResponse(stream: ReadableStream<Uint8Array>, message: string): void {
|
|
40
|
+
void stream.cancel(new DOMException(message, "AbortError")).catch(() => {
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class WebDocumentRoute {
|
|
45
|
+
readonly #context: WebRouteContext;
|
|
46
|
+
readonly #rsc: RscWorker;
|
|
47
|
+
readonly #importMapKey: string;
|
|
48
|
+
readonly #ssrDevShell: CsrDevShell | null;
|
|
49
|
+
readonly #htmlCache: HtmlResultCache;
|
|
50
|
+
readonly #modulePreloadPlan?: ModulePreloadPlan;
|
|
51
|
+
|
|
52
|
+
constructor(context: WebRouteContext, options: WebDocumentRouteOptions) {
|
|
53
|
+
this.#context = context;
|
|
54
|
+
this.#rsc = options.rsc;
|
|
55
|
+
this.#importMapKey = options.importMapKey;
|
|
56
|
+
this.#ssrDevShell = options.ssrDevShell;
|
|
57
|
+
this.#htmlCache = options.htmlCache;
|
|
58
|
+
this.#modulePreloadPlan = options.modulePreloadPlan;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async render(req: Request, url: URL): Promise<Response> {
|
|
62
|
+
let answer: Response | "not-found";
|
|
63
|
+
try {
|
|
64
|
+
answer = await this.#render(req, url);
|
|
65
|
+
} catch (err) {
|
|
66
|
+
return this.#context.errorPageResponse(req, url.pathname, err);
|
|
67
|
+
}
|
|
68
|
+
return answer === "not-found" ? this.#context.notFoundPageResponse(req, url) : answer;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async #render(req: Request, url: URL): Promise<Response | "not-found"> {
|
|
72
|
+
const context = this.#context;
|
|
73
|
+
context.stats.fullSsr += 1;
|
|
74
|
+
await SessionRefresh.apply(req);
|
|
75
|
+
const manifest = await context.ensureRoute(url);
|
|
76
|
+
const isCrawler = isCrawlerUserAgent(req.headers.get("user-agent"));
|
|
77
|
+
const htmlCacheDecision = this.#htmlCache.entryFor(req, url, isCrawler);
|
|
78
|
+
const htmlCacheEntry = htmlCacheDecision.entry;
|
|
79
|
+
const cachedHtml = htmlCacheEntry ? this.#htmlCache.get(htmlCacheEntry.key) : null;
|
|
80
|
+
if (cachedHtml) {
|
|
81
|
+
const cachedHeaders = context.htmlResponseHeaders(200, req);
|
|
82
|
+
cachedHeaders.set("X-Akan-Cache", "HIT");
|
|
83
|
+
return encodedBodyResponse(req, cachedHtml, { headers: cachedHeaders });
|
|
84
|
+
}
|
|
85
|
+
const rscResult = await this.#rsc.renderWithMeta(req, {
|
|
86
|
+
clientManifest: manifest.clientManifest,
|
|
87
|
+
signal: req.signal,
|
|
88
|
+
clientIp: SignalContext.clientIpOf(req),
|
|
89
|
+
});
|
|
90
|
+
if (rscResult.type === "redirect") return createDocumentRedirectResponse(rscResult.location, url, rscResult.status);
|
|
91
|
+
if (rscResult.type === "not-found") return "not-found";
|
|
92
|
+
const hostRequestStore = createRequestStore(req);
|
|
93
|
+
const htmlStream = await this.#renderHtml(req, url, { rscResult, manifest, isCrawler, hostRequestStore });
|
|
94
|
+
|
|
95
|
+
const lateControl = await Promise.race([rscResult.lateControl, Promise.resolve(null)]);
|
|
96
|
+
if (lateControl?.type === "redirect") {
|
|
97
|
+
cancelStreamForHeadResponse(htmlStream, "redirected before the response started");
|
|
98
|
+
return createDocumentRedirectResponse(lateControl.location, url, lateControl.status);
|
|
99
|
+
}
|
|
100
|
+
const responseStatus = lateControl?.type === "not-found" ? 404 : (rscResult.status ?? 200);
|
|
101
|
+
const responseHeaders = context.htmlResponseHeaders(responseStatus, req);
|
|
102
|
+
if (req.method === "HEAD") {
|
|
103
|
+
const headers = new Headers(responseHeaders);
|
|
104
|
+
if (htmlCacheEntry && responseStatus === 200) headers.set("X-Akan-Cache", "MISS");
|
|
105
|
+
else if (htmlCacheDecision.reason) {
|
|
106
|
+
headers.set("X-Akan-Cache", "BYPASS");
|
|
107
|
+
headers.set("X-Akan-Cache-Reason", htmlCacheDecision.reason);
|
|
108
|
+
}
|
|
109
|
+
cancelStreamForHeadResponse(htmlStream, "HEAD response does not consume body");
|
|
110
|
+
return new Response(null, { status: responseStatus, headers });
|
|
111
|
+
}
|
|
112
|
+
if (htmlCacheEntry && responseStatus === 200) {
|
|
113
|
+
const headers = new Headers(responseHeaders);
|
|
114
|
+
headers.set("X-Akan-Cache", "MISS");
|
|
115
|
+
const body = this.#htmlCache.storeWhileStreaming(htmlStream, {
|
|
116
|
+
entry: htmlCacheEntry,
|
|
117
|
+
pathname: url.pathname,
|
|
118
|
+
lateControl: rscResult.lateControl,
|
|
119
|
+
cacheState: rscResult.cacheState,
|
|
120
|
+
hostRequestStore,
|
|
121
|
+
logger: context.logger,
|
|
122
|
+
});
|
|
123
|
+
return new Response(body, {
|
|
124
|
+
status: responseStatus,
|
|
125
|
+
headers,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
const headers = new Headers(responseHeaders);
|
|
129
|
+
if (htmlCacheDecision.reason) {
|
|
130
|
+
headers.set("X-Akan-Cache", "BYPASS");
|
|
131
|
+
headers.set("X-Akan-Cache-Reason", htmlCacheDecision.reason);
|
|
132
|
+
}
|
|
133
|
+
return new Response(htmlStream, {
|
|
134
|
+
status: responseStatus,
|
|
135
|
+
headers,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async #renderHtml(req: Request, url: URL, input: HtmlRenderInput): Promise<ReadableStream<Uint8Array>> {
|
|
140
|
+
const { rscResult, manifest, isCrawler, hostRequestStore } = input;
|
|
141
|
+
const { artifact, prodMode } = this.#context;
|
|
142
|
+
|
|
143
|
+
const cookieTheme = WebRouteContext.cookieValue(req, "theme");
|
|
144
|
+
const dictionaryUrl = this.#context.dictionaryUrlOf(req.headers, url.pathname);
|
|
145
|
+
const extraBootstrapInline = [
|
|
146
|
+
rscResult.trace?.routeState
|
|
147
|
+
? `self.__AKAN_RSC_INITIAL_STATE__=${JSON.stringify(rscResult.trace.routeState)};`
|
|
148
|
+
: "",
|
|
149
|
+
dictionaryUrl ? `self.__AKAN_DICT_URL__=${JSON.stringify(dictionaryUrl)};` : "",
|
|
150
|
+
`self.__AKAN_IMPORT_MAP_KEY__=${JSON.stringify(this.#importMapKey)};`,
|
|
151
|
+
this.#ssrDevShell
|
|
152
|
+
? SsrDevShim.script(await this.#ssrDevShell.readManifest(), Object.keys(artifact.vendorMap))
|
|
153
|
+
: "",
|
|
154
|
+
!prodMode ? HMR_CLIENT_SCRIPT : "",
|
|
155
|
+
]
|
|
156
|
+
.filter(Boolean)
|
|
157
|
+
.join("\n");
|
|
158
|
+
return await new SsrFromRscRenderer().render({
|
|
159
|
+
request: req,
|
|
160
|
+
requestStore: hostRequestStore,
|
|
161
|
+
rscStream: rscResult.stream,
|
|
162
|
+
ssrManifest: manifest.ssrManifest,
|
|
163
|
+
bootstrapModules: [artifact.rscClientUrl],
|
|
164
|
+
modulePreloads: dictionaryUrl ? [dictionaryUrl] : undefined,
|
|
165
|
+
modulePreloadPlan: this.#modulePreloadPlan,
|
|
166
|
+
extraBootstrapInline: extraBootstrapInline || undefined,
|
|
167
|
+
importmap: artifact.vendorMap,
|
|
168
|
+
|
|
169
|
+
get theme() {
|
|
170
|
+
return cookieTheme ?? rscResult.theme ?? "system";
|
|
171
|
+
},
|
|
172
|
+
lateControl: rscResult.lateControl,
|
|
173
|
+
waitForAllReady: rscResult.trace?.ssrBlocking ?? false,
|
|
174
|
+
inlineBoundaries: isCrawler,
|
|
175
|
+
onCancel: (reason: unknown) => {
|
|
176
|
+
rscResult.cancel(reason);
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { CookieJar, getBasePathFromPathname, Logger, parseAkanI18nEnv, RequestLocale } from "akanjs/common";
|
|
3
|
+
import { type MergedManifest, type RouteClientCache, type RouteSeedIndex, RouteSeedIndexStore } from "./artifact";
|
|
4
|
+
import {
|
|
5
|
+
type AssetHeaderOptions,
|
|
6
|
+
applySecurityHeaders,
|
|
7
|
+
assetHeaders,
|
|
8
|
+
missingAssetResponse,
|
|
9
|
+
strictTransportSecurity,
|
|
10
|
+
} from "./assetHeaders";
|
|
11
|
+
import { getClientFacingOrigin, resolveHtmlCacheControl } from "./cachePolicy";
|
|
12
|
+
import { encodedFileResponse, isCompressibleContentType, matchesIfNoneMatch, varyOnEncoding } from "./contentEncoding";
|
|
13
|
+
import { HMR_CLIENT_SCRIPT } from "./hmr/clientScript";
|
|
14
|
+
import type { HmrWsHub } from "./hmr/wsHub";
|
|
15
|
+
import { normalizeHost } from "./proxy/hostBasePathWebProxy";
|
|
16
|
+
import { getPathnameLocale } from "./systemPageDocument";
|
|
17
|
+
import { createSystemPageResponse, getSystemPageHomeHref } from "./systemPages";
|
|
18
|
+
import type { BaseBuildArtifact, RenderState } from "./types";
|
|
19
|
+
|
|
20
|
+
const CLIENT_CLOSED_REQUEST_STATUS = 499;
|
|
21
|
+
|
|
22
|
+
export interface WebRequestStats {
|
|
23
|
+
fullSsr: number;
|
|
24
|
+
rscNavigation: number;
|
|
25
|
+
rscPrefetch: number;
|
|
26
|
+
staticAsset: number;
|
|
27
|
+
csr: number;
|
|
28
|
+
image: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface WebRouteContextOptions {
|
|
32
|
+
artifact: BaseBuildArtifact;
|
|
33
|
+
prodMode: boolean;
|
|
34
|
+
renderState: RenderState;
|
|
35
|
+
subRoutes: Record<string, string[]>;
|
|
36
|
+
seedIndex: RouteSeedIndex;
|
|
37
|
+
routeCache: RouteClientCache;
|
|
38
|
+
hub: () => HmrWsHub | null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class WebRouteContext {
|
|
42
|
+
readonly logger = new Logger("WebRouter");
|
|
43
|
+
readonly stats: WebRequestStats = { fullSsr: 0, rscNavigation: 0, rscPrefetch: 0, staticAsset: 0, csr: 0, image: 0 };
|
|
44
|
+
readonly artifact: BaseBuildArtifact;
|
|
45
|
+
readonly prodMode: boolean;
|
|
46
|
+
readonly renderState: RenderState;
|
|
47
|
+
readonly subRoutes: Record<string, string[]>;
|
|
48
|
+
readonly seedIndex: RouteSeedIndex;
|
|
49
|
+
readonly routeCache: RouteClientCache;
|
|
50
|
+
readonly #hub: () => HmrWsHub | null;
|
|
51
|
+
#runtimeManifest: { revision: number; manifest: MergedManifest } | null = null;
|
|
52
|
+
|
|
53
|
+
constructor({ artifact, prodMode, renderState, subRoutes, seedIndex, routeCache, hub }: WebRouteContextOptions) {
|
|
54
|
+
this.artifact = artifact;
|
|
55
|
+
this.prodMode = prodMode;
|
|
56
|
+
this.renderState = renderState;
|
|
57
|
+
this.subRoutes = subRoutes;
|
|
58
|
+
this.seedIndex = seedIndex;
|
|
59
|
+
this.routeCache = routeCache;
|
|
60
|
+
this.#hub = hub;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
requestBasePath(req: Request): string | null {
|
|
64
|
+
const headerBasePath = req.headers.get("x-base-path");
|
|
65
|
+
if (headerBasePath && this.artifact.basePaths.includes(headerBasePath)) return headerBasePath;
|
|
66
|
+
return WebRouteContext.#basePathForRequestHost(req, this.subRoutes);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static #basePathForRequestHost(req: Request, subRoutes: Record<string, string[]>): string | null {
|
|
70
|
+
const host = normalizeHost(req.headers.get("x-forwarded-host")?.split(",")[0]?.trim() ?? req.headers.get("host"));
|
|
71
|
+
if (!host) return null;
|
|
72
|
+
for (const [basePath, domains] of Object.entries(subRoutes)) {
|
|
73
|
+
if (domains.some((domain) => normalizeHost(domain) === host)) return basePath;
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async ensureRoute(url: URL) {
|
|
79
|
+
const started = Date.now();
|
|
80
|
+
const matched =
|
|
81
|
+
RouteSeedIndexStore.match(url.pathname, this.seedIndex.entries) ??
|
|
82
|
+
RouteSeedIndexStore.matchPrefix(url.pathname, this.seedIndex.entries);
|
|
83
|
+
if (matched) await this.routeCache.ensure(matched.entry.routeId, matched.entry.seeds);
|
|
84
|
+
this.logger.verbose(
|
|
85
|
+
`[route-cache] ensure pathname=${url.pathname} routeId=${matched?.entry.routeId ?? "(none)"} in ${Date.now() - started}ms`,
|
|
86
|
+
);
|
|
87
|
+
return this.#mergeRuntimeManifest();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
#mergeRuntimeManifest(): MergedManifest {
|
|
91
|
+
const revision = this.routeCache.revision;
|
|
92
|
+
if (this.#runtimeManifest?.revision === revision) return this.#runtimeManifest.manifest;
|
|
93
|
+
const snapshot = this.routeCache.snapshot();
|
|
94
|
+
const manifest: MergedManifest = {
|
|
95
|
+
...snapshot,
|
|
96
|
+
clientManifest: Object.assign({}, this.artifact.rscRuntimeClientManifest, snapshot.clientManifest),
|
|
97
|
+
ssrManifest: {
|
|
98
|
+
moduleLoading: null,
|
|
99
|
+
moduleMap: Object.assign({}, this.artifact.rscRuntimeSsrManifest?.moduleMap, snapshot.ssrManifest.moduleMap),
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
this.#runtimeManifest = { revision, manifest };
|
|
103
|
+
return manifest;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
dictionaryUrlOf(headers: Headers, pathname: string): string | undefined {
|
|
107
|
+
const i18n = parseAkanI18nEnv();
|
|
108
|
+
const { locale } = RequestLocale.resolve(
|
|
109
|
+
{ localeHeader: headers.get("x-locale"), pathHeader: headers.get("x-path"), pathname },
|
|
110
|
+
i18n,
|
|
111
|
+
);
|
|
112
|
+
const assets = this.artifact.dictAssets ?? {};
|
|
113
|
+
return (assets[locale] ?? assets[i18n.defaultLocale])?.url;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
htmlResponseHeaders(status: number, req: Request): Headers {
|
|
117
|
+
const headers = new Headers({ "Content-Type": "text/html; charset=utf-8" });
|
|
118
|
+
if (status >= 400 || !this.prodMode) headers.set("Cache-Control", "no-store");
|
|
119
|
+
else {
|
|
120
|
+
const cacheControl = resolveHtmlCacheControl(req);
|
|
121
|
+
if (cacheControl) headers.set("Cache-Control", cacheControl);
|
|
122
|
+
}
|
|
123
|
+
const hsts = this.prodMode ? strictTransportSecurity() : null;
|
|
124
|
+
if (hsts && getClientFacingOrigin(req).startsWith("https:")) headers.set("Strict-Transport-Security", hsts);
|
|
125
|
+
return applySecurityHeaders(headers, { html: true });
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
stylesheetHref(req: Request, pathname: string): string | null {
|
|
129
|
+
const basePath = getBasePathFromPathname(pathname, {
|
|
130
|
+
basePaths: Object.keys(this.renderState.cssAssets),
|
|
131
|
+
i18n: this.artifact.i18n,
|
|
132
|
+
headerBasePath: this.requestBasePath(req),
|
|
133
|
+
});
|
|
134
|
+
return this.renderState.cssAssets[basePath ?? ""]?.cssUrl ?? null;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
#systemPageHomeHref(req: Request, pathname: string): string {
|
|
138
|
+
return getSystemPageHomeHref({
|
|
139
|
+
pathname,
|
|
140
|
+
i18n: this.artifact.i18n,
|
|
141
|
+
basePaths: this.artifact.basePaths,
|
|
142
|
+
headerBasePath: this.requestBasePath(req),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
notFoundPageResponse(req: Request, url: URL): Promise<Response> {
|
|
147
|
+
return createSystemPageResponse({
|
|
148
|
+
kind: "not-found",
|
|
149
|
+
method: req.method,
|
|
150
|
+
pathname: url.pathname,
|
|
151
|
+
lang: getPathnameLocale(url.pathname, this.artifact.i18n),
|
|
152
|
+
homeHref: this.#systemPageHomeHref(req, url.pathname),
|
|
153
|
+
stylesheetHref: this.stylesheetHref(req, url.pathname),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
errorPageResponse(req: Request, scope: string, err: unknown): Promise<Response> {
|
|
158
|
+
if (WebRouteContext.#isExpectedRequestAbort(err)) return Promise.resolve(WebRouteContext.#clientClosedResponse());
|
|
159
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
160
|
+
this.logger.error(`[SSR] render failed scope=${scope}: ${message}`);
|
|
161
|
+
this.#hub()?.broadcast({ type: "error", message });
|
|
162
|
+
return createSystemPageResponse({
|
|
163
|
+
kind: "error",
|
|
164
|
+
method: req.method,
|
|
165
|
+
pathname: scope,
|
|
166
|
+
lang: getPathnameLocale(new URL(req.url).pathname, this.artifact.i18n),
|
|
167
|
+
homeHref: this.#systemPageHomeHref(req, new URL(req.url).pathname),
|
|
168
|
+
stylesheetHref: this.stylesheetHref(req, new URL(req.url).pathname),
|
|
169
|
+
showDetails: !this.prodMode,
|
|
170
|
+
error: err,
|
|
171
|
+
...(this.prodMode ? {} : { script: `self.__AKAN_HMR_SYSTEM_PAGE__=true;${HMR_CLIENT_SCRIPT}` }),
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
rscErrorResponse(scope: string, err: unknown): Response {
|
|
176
|
+
if (WebRouteContext.#isExpectedRequestAbort(err)) return WebRouteContext.#clientClosedResponse();
|
|
177
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
178
|
+
this.logger.error(`[SSR] render failed scope=${scope}: ${message}`);
|
|
179
|
+
this.#hub()?.broadcast({ type: "error", message });
|
|
180
|
+
return new Response("Internal Server Error", {
|
|
181
|
+
status: 500,
|
|
182
|
+
headers: { "Content-Type": "text/plain; charset=utf-8", "Cache-Control": "no-store" },
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
static cookieValue(req: Request, name: string): string | undefined {
|
|
187
|
+
return CookieJar.parse(req.headers.get("cookie")).read(name).value;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
static #clientClosedResponse(): Response {
|
|
191
|
+
return new Response(null, {
|
|
192
|
+
status: CLIENT_CLOSED_REQUEST_STATUS,
|
|
193
|
+
headers: { "Cache-Control": "no-store" },
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
static #isExpectedRequestAbort(error: unknown): boolean {
|
|
198
|
+
if (!(error instanceof Error)) return false;
|
|
199
|
+
return (
|
|
200
|
+
error.name === "AbortError" ||
|
|
201
|
+
error.message === "The connection was closed." ||
|
|
202
|
+
error.message === "Connection closed." ||
|
|
203
|
+
error.message.includes("The connection was closed")
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
static async fileResponse(req: Request, filePath: string, options: AssetHeaderOptions): Promise<Response> {
|
|
208
|
+
const headers = assetHeaders(options);
|
|
209
|
+
const file = Bun.file(filePath);
|
|
210
|
+
if (!(await file.exists())) return missingAssetResponse();
|
|
211
|
+
const stat = fs.statSync(filePath);
|
|
212
|
+
const lastModifiedMs = Math.floor(stat.mtimeMs / 1000) * 1000;
|
|
213
|
+
const etag = `W/"${stat.size.toString(16)}-${lastModifiedMs.toString(16)}"`;
|
|
214
|
+
headers.set("ETag", etag);
|
|
215
|
+
headers.set("Last-Modified", new Date(lastModifiedMs).toUTCString());
|
|
216
|
+
if (isCompressibleContentType(options.contentType)) varyOnEncoding(headers);
|
|
217
|
+
if (WebRouteContext.#isNotModified(req, etag, lastModifiedMs)) return new Response(null, { status: 304, headers });
|
|
218
|
+
|
|
219
|
+
return await encodedFileResponse(req, filePath, options.contentType, headers);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
static #isNotModified(req: Request, etag: string, lastModifiedMs: number): boolean {
|
|
223
|
+
if (req.method !== "GET" && req.method !== "HEAD") return false;
|
|
224
|
+
const ifNoneMatch = req.headers.get("if-none-match");
|
|
225
|
+
if (ifNoneMatch) return matchesIfNoneMatch(ifNoneMatch, etag);
|
|
226
|
+
|
|
227
|
+
const ifModifiedSince = req.headers.get("if-modified-since");
|
|
228
|
+
if (!ifModifiedSince) return false;
|
|
229
|
+
const sinceMs = Date.parse(ifModifiedSince);
|
|
230
|
+
return Number.isFinite(sinceMs) && sinceMs >= lastModifiedMs;
|
|
231
|
+
}
|
|
232
|
+
}
|