akanjs 3.2.0-rc.9 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +41 -38
- package/CHANGELOG.md +0 -680
- package/CONTRIBUTING.md +3 -0
- package/base/base.ts +2 -1
- package/client/clientRuntime.ts +1 -0
- package/client/cn.ts +2 -2
- package/client/csrTypes.ts +2 -0
- package/client/frameConfig.ts +1 -0
- package/client/index.ts +249 -26
- package/client/locale.ts +1 -0
- package/client/makePageProto.tsx +12 -85
- package/client/nativeThemeColor.ts +51 -0
- package/client/route/PageDefinition.ts +11 -3
- package/client/route/RouteDefinition.ts +24 -7
- package/client/route/RouteGuards.ts +2 -1
- package/client/route/RouteHead.ts +4 -1
- package/client/route/routeArgs.ts +8 -0
- package/client/router.ts +17 -2
- package/client/rscNavigation.ts +1 -0
- package/client/viewportMeta.ts +86 -6
- package/common/CodeTranscript.ts +1 -1
- package/common/Logger.ts +4 -2
- package/common/PipelinePlanSchema.ts +2 -2
- package/common/clientAddress.ts +14 -0
- package/common/err.ts +122 -0
- package/common/eventStream.ts +71 -19
- package/common/facetBarrel.ts +38 -0
- package/common/index.ts +7 -0
- package/common/isGuardRefusal.ts +14 -0
- package/common/loggedFailure.ts +11 -0
- package/common/mcpExposure.ts +17 -4
- package/common/pipelinePlan.ts +1 -1
- 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 +12 -0
- package/dictionary/base.dictionary.ts +11 -0
- package/dictionary/locale.ts +1 -1
- package/dictionary/trans.ts +14 -97
- package/document/dataLoader.ts +39 -19
- 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 +83 -269
- package/fetch/client/fetchClientTypes.ts +49 -0
- package/fetch/client/httpClient.ts +3 -2
- package/fetch/client/remoteError.ts +4 -20
- package/fetch/client/requestScope.ts +41 -0
- package/fetch/client/signalCatalog.ts +131 -0
- package/fetch/client/wsClient.ts +82 -6
- package/fetch/requestStorage.ts +1 -0
- package/package.json +1 -1
- package/server/agentHooks.ts +16 -0
- package/server/akanApp.ts +110 -1272
- package/server/akanOption.ts +30 -3
- package/server/akanServer.ts +179 -674
- package/server/artifact/builderRpc.ts +14 -6
- 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/di/diLifecycle.ts +24 -35
- package/server/di/predefinedAdaptor.ts +24 -1
- package/server/di/resolveHierarchy.ts +19 -6
- package/server/di/stageFailedError.ts +10 -0
- package/server/di/utils.ts +8 -3
- package/server/ed25519Key.ts +31 -15
- package/server/flightRowReader.ts +106 -20
- package/server/gateway/childSupervisor.ts +328 -0
- package/server/gateway/devHostChannel.ts +47 -0
- package/server/gateway/gatewayChildren.ts +161 -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 +122 -0
- package/server/gateway/gatewayStatusPage.ts +54 -0
- package/server/gateway/gatewayWebSocketRelay.ts +149 -0
- package/server/gateway/listeningPort.ts +13 -0
- package/server/hmr/devHmrController.ts +10 -1
- package/server/htmlResultCache.ts +234 -0
- package/server/imageOptimizer.ts +4 -1
- package/server/index.ts +281 -17
- package/server/lifecycle/parentChannel.ts +79 -0
- package/server/lifecycle/shutdownManager.ts +6 -3
- package/server/lifecycle/startGuard.ts +90 -0
- package/server/logging/hubFileSink.ts +1 -0
- package/server/logging/logControlSocket.ts +42 -3
- package/server/logging/logHub.ts +0 -0
- package/server/logging/logStdoutWriter.ts +3 -1
- package/server/logging/logStreamRoute.ts +28 -11
- 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/McpApps.ts +32 -2
- package/server/mcp/McpDispatcher.ts +44 -30
- package/server/mcp/McpPages.ts +34 -12
- package/server/mcp/McpRateLimiter.ts +14 -0
- package/server/mcp/McpRouter.ts +4 -2
- package/server/mcp/McpUiSession.ts +2 -1
- package/server/mcp/index.ts +1 -0
- package/server/migration/migrationCommand.ts +31 -2
- package/server/migration/migrationRunner.ts +36 -1
- package/server/nativeFile.ts +39 -12
- package/server/nativeSecret.ts +12 -3
- package/server/oauth/OAuthClientIdMetadata.ts +2 -2
- package/server/ops/migrateJobs.ts +2 -2
- package/server/ops/opsCommand.ts +1 -1
- package/server/ops/opsRoute.ts +5 -1
- package/server/ops/opsToken.ts +3 -1
- package/server/remote/RemoteFetch.ts +161 -0
- package/server/remote/RemoteMcp.ts +242 -0
- package/server/remote/RemoteOAuth.ts +270 -0
- package/server/remote/RemoteSource.ts +214 -0
- package/server/remote/index.ts +17 -0
- package/server/remote/remoteError.ts +19 -0
- package/server/resolver/CascadeRunner.ts +20 -8
- package/server/resolver/database.resolver.ts +10 -417
- package/server/resolver/databaseModelInstance.ts +209 -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 +84 -0
- package/server/resolver/modelSchema.ts +52 -0
- package/server/resolver/roomAdmission.ts +68 -0
- package/server/resolver/signal.resolver.ts +45 -111
- package/server/resolver/sliceCrud.ts +63 -0
- package/server/resolver/timedQuery.ts +16 -0
- package/server/resolver/websocketOf.ts +2 -1
- package/server/routeElementComposer.tsx +45 -6
- package/server/routeTreeBuilder.ts +23 -9
- package/server/routing/apiRouter.ts +53 -28
- 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 +121 -204
- package/server/rscClientCache.ts +165 -0
- package/server/rscClientChunks.ts +126 -8
- package/server/rscClientFetch.ts +3 -1
- package/server/rscClientPatch.ts +78 -15
- package/server/rscDocumentHead.tsx +177 -0
- package/server/rscFlightRenderer.ts +83 -0
- package/server/rscFlightStream.ts +259 -0
- 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/rscNavigationState.ts +24 -1
- package/server/rscPagePrompts.ts +65 -14
- package/server/rscPrefetchCache.ts +5 -1
- package/server/rscRenderControl.ts +33 -0
- package/server/rscRenderFallbacks.ts +299 -0
- package/server/rscRenderHandler.ts +439 -0
- package/server/rscRenderStats.ts +49 -0
- package/server/rscResultCaches.ts +74 -0
- package/server/rscRouteDocument.tsx +316 -0
- package/server/rscSegmentOutletReference.ts +5 -1
- package/server/rscStaticApp.tsx +73 -0
- package/server/rscWorker.tsx +112 -1341
- package/server/rscWorkerHost.ts +175 -803
- 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/ssrStaticApp.tsx +243 -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 +129 -1165
- package/server/webRscRoute.ts +155 -0
- package/server/webSiteFiles.ts +139 -0
- package/server/webStaticApp.ts +62 -0
- package/server/wellKnownRoutes.ts +73 -0
- package/service/agent.service.ts +14 -2
- package/service/agentAccounts.ts +19 -0
- package/service/agentLoop/agentLoop.ts +550 -0
- package/service/agentLoop/agentLoopTypes.ts +220 -0
- package/service/agentLoop/deltaStream.ts +40 -0
- package/service/agentLoop/loopAnswer.ts +67 -0
- package/service/agentLoop/loopAsk.ts +44 -0
- package/service/agentLoop/loopCompaction.ts +146 -0
- package/service/agentLoop/loopRemotes.ts +181 -0
- package/service/agentLoop/loopRequest.ts +120 -0
- package/service/agentLoop/loopStored.ts +24 -0
- package/service/agentLoop/loopToolOutput.ts +54 -0
- package/service/agentLoop/loopToolkits.ts +155 -0
- package/service/agentLoop/loopTranscript.ts +138 -0
- package/{signal → service}/agentMeter.ts +2 -1
- package/{signal → service}/agentRelayPolicy.ts +43 -8
- package/service/endpointCacheKeys.ts +14 -2
- package/service/index.ts +6 -0
- package/service/injectInfo.ts +2 -1
- package/service/ipcTypes.ts +8 -2
- package/service/liveRoomLimit.ts +68 -0
- package/service/liveRoomLimitError.ts +16 -0
- package/service/liveSyncHub.ts +24 -2
- package/service/predefinedAdaptor/agentTools.adaptor.ts +34 -0
- package/service/predefinedAdaptor/anthropicLlm.ts +33 -14
- package/service/predefinedAdaptor/compress.adaptor.ts +2 -2
- package/service/predefinedAdaptor/database.adaptor.ts +62 -19
- package/service/predefinedAdaptor/index.ts +1 -0
- package/service/predefinedAdaptor/llm.adaptor.ts +24 -1
- package/service/predefinedAdaptor/openaiDialect.ts +72 -23
- package/service/predefinedAdaptor/openaiLlm.ts +1 -1
- package/service/predefinedAdaptor/role.adaptor.ts +2 -0
- package/service/predefinedAdaptor/solidPubsub.adaptor.ts +35 -2
- package/service/predefinedAdaptor/solidQueue.adaptor.ts +2 -2
- package/service/predefinedAdaptor/solidSqlite.ts +6 -3
- package/service/predefinedAdaptor/sql/DocumentHydrator.ts +95 -0
- package/service/predefinedAdaptor/sql/DocumentRowCodec.ts +192 -0
- package/service/predefinedAdaptor/sql/DocumentWriter.ts +298 -0
- package/service/predefinedAdaptor/sql/QueryScope.ts +70 -0
- package/service/predefinedAdaptor/sql/QueryWriter.ts +200 -0
- package/service/predefinedAdaptor/sql/SqlDocumentStore.ts +127 -1069
- package/service/predefinedAdaptor/sql/SqlTableSchema.ts +357 -0
- package/service/predefinedAdaptor/sql/StoredRows.ts +95 -0
- package/service/predefinedAdaptor/sql/TransactionScope.ts +14 -7
- package/service/predefinedAdaptor/sql/dialect/postgres.ts +1 -1
- package/service/predefinedAdaptor/sql/dialect/sqlite.ts +1 -1
- package/service/predefinedAdaptor/sql/driver/bunSqlite.ts +20 -9
- package/service/predefinedAdaptor/sql/driver/postgres.ts +1 -1
- package/service/predefinedAdaptor/sql/types.ts +28 -4
- package/service/predefinedAdaptor/sseData.ts +88 -0
- package/service/predefinedAdaptor/storage.adaptor.ts +2 -1
- package/service/predefinedAdaptor/websocket.adaptor.ts +74 -44
- package/service/serviceRegistry.ts +1 -0
- package/signal/SignalFailure.ts +35 -0
- package/signal/agent.signal.ts +15 -9
- package/signal/agentTurnStream.ts +23 -9
- package/signal/byIdRead.ts +18 -0
- package/signal/carriedClientIps.ts +1 -0
- package/signal/endpointCache.ts +61 -6
- package/signal/endpointErrorContract.ts +1 -1
- package/signal/endpointRateLimit.ts +84 -3
- package/signal/index.ts +322 -32
- package/signal/mcp/McpDocument.ts +8 -1
- package/signal/mcp/mcpProtocol.ts +6 -1
- package/signal/mcp/pagePrompt.ts +15 -0
- package/signal/middleware.ts +10 -3
- package/signal/openapi/openapi.ts +10 -1
- package/signal/resolveFieldContext.ts +34 -0
- package/signal/serializer/fetch.serializer.ts +22 -15
- package/signal/signalContext.ts +15 -42
- package/signal/slice.ts +22 -19
- package/signal/trace.ts +44 -5
- package/signal/types.ts +46 -8
- package/store/action.ts +32 -1057
- package/store/actionErrorMessage.ts +20 -0
- package/store/actionOption.ts +22 -0
- package/store/baseSt.ts +1 -0
- package/store/formFieldSetters.ts +229 -0
- package/store/index.ts +125 -17
- package/store/modelActionContext.ts +65 -0
- package/store/modelOpenActions.ts +158 -0
- package/store/modelWriteActions.ts +240 -0
- package/store/modelWriteGuard.ts +3 -12
- package/store/openSeq.ts +34 -0
- package/store/sliceListActions.ts +370 -0
- package/store/sliceLiveActions.ts +140 -0
- package/store/stateBuilder.ts +2 -0
- package/store/storeInstance.ts +4 -18
- package/store/storeRegistry.ts +1 -1
- package/test/conformance.ts +25 -5
- 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 +2 -0
- 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 +5 -13
- package/types/client/nativeThemeColor.d.ts +6 -0
- package/types/client/route/PageDefinition.d.ts +5 -2
- package/types/client/route/RouteDefinition.d.ts +2 -2
- package/types/client/route/routeArgs.d.ts +7 -0
- package/types/client/router.d.ts +3 -1
- package/types/client/rscNavigation.d.ts +1 -0
- package/types/client/viewportMeta.d.ts +5 -2
- package/types/common/CodeTranscript.d.ts +1 -1
- package/types/common/clientAddress.d.ts +5 -0
- package/types/common/err.d.ts +48 -0
- package/types/common/eventStream.d.ts +5 -1
- package/types/common/facetBarrel.d.ts +4 -0
- package/types/common/index.d.ts +6 -3
- package/types/common/isGuardRefusal.d.ts +3 -0
- package/types/common/loggedFailure.d.ts +2 -0
- package/types/common/mcpExposure.d.ts +9 -2
- 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/dataLoader.d.ts +5 -0
- 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/httpClient.d.ts +2 -0
- package/types/fetch/client/remoteError.d.ts +0 -4
- package/types/fetch/client/requestScope.d.ts +11 -0
- package/types/fetch/client/signalCatalog.d.ts +25 -0
- package/types/fetch/client/wsClient.d.ts +2 -0
- package/types/fetch/requestStorage.d.ts +1 -0
- package/types/server/agentHooks.d.ts +4 -0
- package/types/server/akanApp.d.ts +2 -20
- package/types/server/akanOption.d.ts +16 -2
- package/types/server/akanServer.d.ts +2 -2
- package/types/server/assetHeaders.d.ts +1 -0
- package/types/server/console.d.ts +4 -3
- package/types/server/di/predefinedAdaptor.d.ts +1 -0
- package/types/server/di/stageFailedError.d.ts +5 -0
- package/types/server/ed25519Key.d.ts +1 -0
- package/types/server/flightRowReader.d.ts +8 -2
- package/types/server/gateway/childSupervisor.d.ts +35 -0
- package/types/server/gateway/devHostChannel.d.ts +14 -0
- package/types/server/gateway/gatewayChildren.d.ts +50 -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 +63 -0
- package/types/server/gateway/gatewayStatusPage.d.ts +9 -0
- package/types/server/gateway/gatewayWebSocketRelay.d.ts +17 -0
- package/types/server/gateway/listeningPort.d.ts +5 -0
- package/types/server/htmlResultCache.d.ts +51 -0
- package/types/server/index.d.ts +19 -17
- package/types/server/lifecycle/parentChannel.d.ts +13 -0
- package/types/server/lifecycle/startGuard.d.ts +10 -0
- package/types/server/logging/logHub.d.ts +5 -1
- package/types/server/logging/logStreamRoute.d.ts +2 -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/McpApps.d.ts +6 -2
- 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/migration/migrationCommand.d.ts +1 -1
- package/types/server/migration/migrationRunner.d.ts +9 -1
- package/types/server/remote/RemoteFetch.d.ts +42 -0
- package/types/server/remote/RemoteMcp.d.ts +52 -0
- package/types/server/remote/RemoteOAuth.d.ts +58 -0
- package/types/server/remote/RemoteSource.d.ts +51 -0
- package/types/server/remote/index.d.ts +5 -0
- package/types/server/remote/remoteError.d.ts +12 -0
- package/types/server/remote.d.ts +1 -0
- package/types/server/resolver/CascadeRunner.d.ts +2 -2
- 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 +15 -0
- package/types/server/resolver/modelSchema.d.ts +6 -0
- package/types/server/resolver/roomAdmission.d.ts +7 -0
- package/types/server/resolver/signal.resolver.d.ts +1 -1
- package/types/server/resolver/sliceCrud.d.ts +8 -0
- package/types/server/resolver/timedQuery.d.ts +8 -0
- package/types/server/routeElementComposer.d.ts +21 -5
- 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/rscClientCache.d.ts +34 -0
- package/types/server/rscClientChunks.d.ts +3 -1
- package/types/server/rscClientPatch.d.ts +12 -1
- package/types/server/rscDocumentHead.d.ts +33 -0
- package/types/server/rscFlightRenderer.d.ts +14 -0
- package/types/server/rscFlightStream.d.ts +53 -0
- 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/rscNavigationState.d.ts +5 -1
- package/types/server/rscPagePrompts.d.ts +13 -0
- 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/rscResultCaches.d.ts +18 -0
- package/types/server/rscRouteDocument.d.ts +52 -0
- package/types/server/rscStaticApp.d.ts +28 -0
- package/types/server/rscWorker.d.ts +1 -3
- package/types/server/rscWorkerHost.d.ts +10 -70
- 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/ssrStaticApp.d.ts +20 -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 +3 -28
- package/types/server/webRscRoute.d.ts +24 -0
- package/types/server/webSiteFiles.d.ts +12 -0
- package/types/server/webStaticApp.d.ts +8 -0
- package/types/server/wellKnownRoutes.d.ts +5 -0
- package/types/service/agent.service.d.ts +3 -0
- package/types/service/agentAccounts.d.ts +8 -0
- package/types/service/agentLoop/agentLoop.d.ts +33 -0
- package/types/service/agentLoop/agentLoopTypes.d.ts +235 -0
- package/types/service/agentLoop/deltaStream.d.ts +3 -0
- package/types/service/agentLoop/loopAnswer.d.ts +13 -0
- package/types/service/agentLoop/loopAsk.d.ts +12 -0
- package/types/service/agentLoop/loopCompaction.d.ts +12 -0
- package/types/service/agentLoop/loopRemotes.d.ts +40 -0
- package/types/service/agentLoop/loopRequest.d.ts +9 -0
- package/types/service/agentLoop/loopStored.d.ts +6 -0
- package/types/service/agentLoop/loopToolOutput.d.ts +8 -0
- package/types/service/agentLoop/loopToolkits.d.ts +17 -0
- package/types/service/agentLoop/loopTranscript.d.ts +13 -0
- package/types/{signal → service}/agentMeter.d.ts +1 -1
- package/types/{signal → service}/agentRelayPolicy.d.ts +18 -3
- package/types/service/index.d.ts +6 -0
- package/types/service/injectInfo.d.ts +2 -1
- package/types/service/ipcTypes.d.ts +10 -0
- package/types/service/liveRoomLimit.d.ts +26 -0
- package/types/service/liveRoomLimitError.d.ts +9 -0
- package/types/service/predefinedAdaptor/agentTools.adaptor.d.ts +31 -0
- package/types/service/predefinedAdaptor/anthropicLlm.d.ts +2 -2
- package/types/service/predefinedAdaptor/database.adaptor.d.ts +9 -7
- package/types/service/predefinedAdaptor/index.d.ts +1 -0
- package/types/service/predefinedAdaptor/llm.adaptor.d.ts +12 -0
- package/types/service/predefinedAdaptor/openaiDialect.d.ts +3 -2
- 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 +25 -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 +5 -28
- package/types/service/predefinedAdaptor/sql/SqlTableSchema.d.ts +22 -0
- package/types/service/predefinedAdaptor/sql/StoredRows.d.ts +27 -0
- package/types/service/predefinedAdaptor/sql/TransactionScope.d.ts +3 -1
- package/types/service/predefinedAdaptor/sql/driver/bunSqlite.d.ts +3 -15
- package/types/service/predefinedAdaptor/sql/driver/postgres.d.ts +0 -8
- package/types/service/predefinedAdaptor/sql/types.d.ts +27 -4
- package/types/service/predefinedAdaptor/sseData.d.ts +13 -0
- package/types/service/predefinedAdaptor/websocket.adaptor.d.ts +7 -3
- package/types/service/serviceRegistry.d.ts +1 -0
- package/types/signal/SignalFailure.d.ts +4 -0
- package/types/signal/agentTurnStream.d.ts +3 -0
- package/types/signal/byIdRead.d.ts +7 -0
- package/types/signal/carriedClientIps.d.ts +4 -0
- package/types/signal/endpointRateLimit.d.ts +12 -0
- package/types/signal/index.d.ts +32 -32
- package/types/signal/mcp/McpDocument.d.ts +2 -0
- package/types/signal/mcp/mcpProtocol.d.ts +5 -0
- package/types/signal/mcp/pagePrompt.d.ts +13 -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 +2 -14
- package/types/signal/slice.d.ts +15 -13
- package/types/signal/trace.d.ts +12 -1
- package/types/signal/types.d.ts +38 -7
- package/types/store/action.d.ts +4 -27
- package/types/store/actionErrorMessage.d.ts +1 -0
- package/types/store/actionOption.d.ts +24 -0
- package/types/store/baseSt.d.ts +1 -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/modelOpenActions.d.ts +12 -0
- package/types/store/modelWriteActions.d.ts +16 -0
- package/types/store/modelWriteGuard.d.ts +2 -5
- package/types/store/openSeq.d.ts +17 -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/test/conformance.d.ts +3 -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/Agent/ToolRow.d.ts +13 -0
- package/types/ui/Field/Choice.d.ts +2 -1
- package/types/ui/Field/index.d.ts +1 -1
- package/types/ui/Reference/origin.d.ts +1 -0
- package/types/ui/UiOverride/UiOverride.d.ts +2 -0
- package/types/ui/index.d.ts +2 -1
- package/types/ui/overlayLayer.d.ts +8 -2
- 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 +22 -13
- package/types/vendor/@akanjs/native/plugins/single-instance/src/socket.d.ts +15 -2
- package/types/vendor/use-agentic/AgentClientTools.d.ts +19 -0
- package/types/vendor/use-agentic/Compaction.d.ts +3 -1
- package/types/vendor/use-agentic/SessionQuestion.d.ts +26 -0
- package/types/vendor/use-agentic/Transcript.d.ts +1 -1
- 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 +12 -3
- package/types/webkit/CsrGuards.d.ts +3 -0
- package/types/webkit/McpAppHost.d.ts +24 -0
- package/types/webkit/RouteLevelBoundary.d.ts +17 -0
- package/types/webkit/csrRefresh.d.ts +13 -0
- package/types/webkit/index.d.ts +3 -0
- package/types/webkit/needsBrowser.d.ts +5 -0
- package/types/webkit/useCamera.d.ts +1 -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/useGeoLocation.d.ts +1 -1
- package/types/webkit/useHistory.d.ts +2 -3
- package/types/webkit/useResolvedFrame.d.ts +38 -0
- package/types/webkit/useSyncNavigation.d.ts +22 -0
- package/ui/Agent/Bubble.tsx +4 -118
- package/ui/Agent/Chat.tsx +402 -235
- package/ui/Agent/ChatHeader.tsx +59 -0
- package/ui/Agent/ChatPendingCards.tsx +49 -0
- package/ui/Agent/ToolRow.tsx +117 -0
- package/ui/Agent/fetchRunner.ts +8 -1
- package/ui/BottomSheet.tsx +1 -1
- 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/Load/StreamBoundary.tsx +1 -6
- package/ui/Load/View.tsx +2 -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 +4 -1
- package/ui/UiOverride/UiOverride.tsx +2 -0
- package/ui/index.ts +5 -0
- package/ui/overlayLayer.ts +25 -2
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeActivity.kt +31 -13
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativePlugin.kt +4 -0
- package/vendor/@akanjs/native/native/desktop/Cargo.lock +1 -0
- package/vendor/@akanjs/native/native/desktop/Cargo.toml +2 -0
- package/vendor/@akanjs/native/native/desktop/src/external.rs +240 -114
- package/vendor/@akanjs/native/native/desktop/src/json.rs +14 -1
- package/vendor/@akanjs/native/native/desktop/src/lib.rs +12 -4
- package/vendor/@akanjs/native/native/desktop/src/linux/external.rs +696 -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 +22 -13
- package/vendor/@akanjs/native/plugins/single-instance/src/socket.ts +113 -24
- package/vendor/use-agentic/AgentClientTools.ts +33 -0
- package/vendor/use-agentic/AgentSession.ts +35 -73
- package/vendor/use-agentic/CHANGELOG.md +0 -43
- package/vendor/use-agentic/Compaction.ts +12 -2
- package/vendor/use-agentic/SessionQuestion.ts +99 -0
- package/vendor/use-agentic/ToolRunner.ts +3 -15
- package/vendor/use-agentic/Transcript.ts +8 -5
- package/vendor/use-agentic/WIRE.md +28 -9
- package/vendor/use-agentic/failureCode.ts +44 -0
- package/vendor/use-agentic/httpRunner.ts +22 -8
- package/vendor/use-agentic/index.ts +1 -0
- package/vendor/use-agentic/types.ts +13 -1
- package/webkit/CsrGuards.ts +11 -2
- package/webkit/McpAppFetchBridge.ts +3 -1
- package/webkit/McpAppHost.ts +122 -0
- package/webkit/RenderLayer.tsx +48 -14
- package/webkit/RouteLevelBoundary.tsx +37 -0
- package/webkit/csrRefresh.ts +33 -0
- package/webkit/index.ts +3 -0
- package/webkit/lazy.tsx +5 -1
- package/webkit/needsBrowser.ts +10 -0
- package/webkit/useCamera.tsx +18 -7
- 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 +73 -1235
- package/webkit/useGeoLocation.tsx +1 -3
- package/webkit/useHistory.ts +2 -2
- package/webkit/useLocation.ts +3 -2
- package/webkit/useResolvedFrame.ts +116 -0
- package/webkit/useSyncNavigation.ts +109 -0
- package/vendor/@akanjs/native/CHANGELOG.md +0 -21
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { PrefetchPriority } from "../client/rscNavigation";
|
|
2
|
+
import { isAuthTokenKey } from "../common/authCookie";
|
|
3
|
+
import { CookieJar } from "../common/cookieJar";
|
|
4
|
+
import { StaleReads } from "../fetch/staleReads";
|
|
5
|
+
import { type AkanRouterStateV1, isAkanRscPartialCommitEnabled } from "./routeState";
|
|
6
|
+
import { fetchRscPrefetchResponse } from "./rscClientFetch";
|
|
7
|
+
import type { RscPatchedResult } from "./rscClientPatch";
|
|
8
|
+
import {
|
|
9
|
+
type AkanSegmentCacheNode,
|
|
10
|
+
createRscPatchNavigationCacheNode,
|
|
11
|
+
forgetRscPatchesOfLostBases,
|
|
12
|
+
type RscNavigationCacheNode,
|
|
13
|
+
type RscPatchNavigationCacheNode,
|
|
14
|
+
rememberRscCacheEntry,
|
|
15
|
+
rememberRscCacheNode,
|
|
16
|
+
resolveCachedRscPatchNavigation,
|
|
17
|
+
} from "./rscNavigationState";
|
|
18
|
+
import { RscPrefetchCache } from "./rscPrefetchCache";
|
|
19
|
+
|
|
20
|
+
export const normalizeHref = (href: string): string => new URL(href, window.location.origin).href;
|
|
21
|
+
export const withoutHash = (href: string | undefined) => href?.split("#", 1)[0];
|
|
22
|
+
export const pageKeyOf = (href: string) => withoutHash(href) ?? href;
|
|
23
|
+
|
|
24
|
+
const readAuthCookies = () =>
|
|
25
|
+
CookieJar.parse(document.cookie)
|
|
26
|
+
.entries()
|
|
27
|
+
.filter(({ name }) => isAuthTokenKey(name))
|
|
28
|
+
.map(({ name, value }) => `${name}=${value}`)
|
|
29
|
+
.sort((a, b) => a.localeCompare(b))
|
|
30
|
+
.join("; ");
|
|
31
|
+
|
|
32
|
+
const isConstrainedNetwork = () => {
|
|
33
|
+
const connection = (navigator as Navigator & { connection?: { saveData?: boolean; effectiveType?: string } })
|
|
34
|
+
.connection;
|
|
35
|
+
return connection?.saveData === true || /2g$/.test(connection?.effectiveType ?? "");
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
interface RscClientScreen<T> {
|
|
39
|
+
routerState: () => AkanRouterStateV1 | null;
|
|
40
|
+
tree: () => AkanSegmentCacheNode<T> | null;
|
|
41
|
+
base: () => RscNavigationCacheNode<T> | null;
|
|
42
|
+
navId: () => number;
|
|
43
|
+
pendingTarget: () => string | undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export class RscClientCache<T extends object> {
|
|
47
|
+
static readonly maxEntries = 32;
|
|
48
|
+
readonly pages = new Map<string, RscNavigationCacheNode<T>>();
|
|
49
|
+
readonly prefetches: RscPrefetchCache<RscNavigationCacheNode<T> | null>;
|
|
50
|
+
#patches = new Map<string, RscPatchNavigationCacheNode<T>>();
|
|
51
|
+
#failed = new WeakSet<T>();
|
|
52
|
+
#account = readAuthCookies();
|
|
53
|
+
#screen: RscClientScreen<T>;
|
|
54
|
+
|
|
55
|
+
constructor(screen: RscClientScreen<T>) {
|
|
56
|
+
this.#screen = screen;
|
|
57
|
+
this.prefetches = new RscPrefetchCache({
|
|
58
|
+
fetchResponse: (href, signal) => fetchRscPrefetchResponse(href, signal, screen.routerState()),
|
|
59
|
+
baseOf: () => this.#prefetchBase(),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
StaleReads.subscribe(() => this.prefetches.clear());
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
clear(): void {
|
|
66
|
+
this.pages.clear();
|
|
67
|
+
this.#patches.clear();
|
|
68
|
+
this.prefetches.clear();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
forgetAnotherAccount(): boolean {
|
|
72
|
+
const account = readAuthCookies();
|
|
73
|
+
if (account === this.#account) return false;
|
|
74
|
+
this.#account = account;
|
|
75
|
+
this.clear();
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
noteFailedRender(thenable: T): void {
|
|
80
|
+
this.#failed.add(thenable);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
pageOf(target: string): RscNavigationCacheNode<T> | undefined {
|
|
84
|
+
const key = pageKeyOf(target);
|
|
85
|
+
const exact = this.pages.get(target);
|
|
86
|
+
if (exact && !this.#failed.has(exact.thenable)) return exact;
|
|
87
|
+
return [...this.pages.values()].findLast(
|
|
88
|
+
(node) => pageKeyOf(node.href) === key && !this.#failed.has(node.thenable),
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
replayedPageOf(target: string): RscNavigationCacheNode<T> | undefined {
|
|
93
|
+
const node = this.pageOf(target);
|
|
94
|
+
if (node) rememberRscCacheNode(this.pages, node, RscClientCache.maxEntries);
|
|
95
|
+
return node;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
replayPatch(target: string, navId: number, commit: (patch: RscPatchedResult<T>) => boolean): boolean {
|
|
99
|
+
const key = pageKeyOf(target);
|
|
100
|
+
const cachedPatch = this.#patchOf(key);
|
|
101
|
+
if (!cachedPatch) return false;
|
|
102
|
+
const patchResult = this.#patchReplayOf(cachedPatch, navId);
|
|
103
|
+
if (patchResult.status === "patched") {
|
|
104
|
+
const { tree, patchedNode, outletKey, headSnapshot } = patchResult;
|
|
105
|
+
if (commit({ type: "patched", tree, patchedNode, patch: cachedPatch.patch, outletKey, headSnapshot })) {
|
|
106
|
+
rememberRscCacheEntry(this.#patches, key, cachedPatch, RscClientCache.maxEntries);
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
this.#patches.delete(key);
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
rememberPatch(href: string, { patch, patchedNode, outletKey, headSnapshot }: RscPatchedResult<T>): void {
|
|
115
|
+
const base = this.#screen.base();
|
|
116
|
+
const node = createRscPatchNavigationCacheNode({ href, patch, patchedNode, outletKey, headSnapshot, base });
|
|
117
|
+
if (node) rememberRscCacheEntry(this.#patches, pageKeyOf(href), node, RscClientCache.maxEntries);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
forgetPatch(target: string): void {
|
|
121
|
+
this.#patches.delete(pageKeyOf(target));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
forgetPatchesOfLostBases(base: RscNavigationCacheNode<T>): void {
|
|
125
|
+
forgetRscPatchesOfLostBases(this.#patches, this.pages, base);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
takePrefetch(target: string, signal: AbortSignal) {
|
|
129
|
+
return this.prefetches.take(pageKeyOf(target), this.#account, signal, this.#prefetchBase());
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
prefetch(href: string, priority?: PrefetchPriority): () => void {
|
|
133
|
+
const none = () => undefined;
|
|
134
|
+
if (isConstrainedNetwork()) return none;
|
|
135
|
+
const target = normalizeHref(href);
|
|
136
|
+
const key = pageKeyOf(target);
|
|
137
|
+
if (new URL(target).origin !== window.location.origin || this.#screen.pendingTarget() === key) return none;
|
|
138
|
+
|
|
139
|
+
const account = readAuthCookies();
|
|
140
|
+
const cachedPatch = this.#patchOf(key);
|
|
141
|
+
const replayable = this.pageOf(target) || (!!cachedPatch && this.#patchReplayOf(cachedPatch).status === "patched");
|
|
142
|
+
if (account === this.#account && replayable) return none;
|
|
143
|
+
return this.prefetches.request(key, account, priority, this.#prefetchBase());
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
#patchOf(key: string): RscPatchNavigationCacheNode<T> | undefined {
|
|
147
|
+
const node = this.#patches.get(key);
|
|
148
|
+
return node && !this.#failed.has(node.thenable) ? node : undefined;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
#prefetchBase(): RscNavigationCacheNode<T> | null {
|
|
152
|
+
return isAkanRscPartialCommitEnabled() ? this.#screen.base() : null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
#patchReplayOf(node: RscPatchNavigationCacheNode<T>, navId?: number) {
|
|
156
|
+
return resolveCachedRscPatchNavigation({
|
|
157
|
+
currentTree: this.#screen.tree(),
|
|
158
|
+
currentBase: this.#screen.base(),
|
|
159
|
+
node,
|
|
160
|
+
partialCommitEnabled: isAkanRscPartialCommitEnabled(),
|
|
161
|
+
navId,
|
|
162
|
+
getCurrentNavId: this.#screen.navId,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { FlightLineRowHandler } from "./flightRowReader";
|
|
2
2
|
|
|
3
3
|
export interface ChunkNavigation {
|
|
4
4
|
navId: number;
|
|
@@ -11,13 +11,10 @@ const quotedString = /"([^"\\]*)"/g;
|
|
|
11
11
|
const maxScriptRowBytes = 1024;
|
|
12
12
|
const rowDecoder = new TextDecoder();
|
|
13
13
|
|
|
14
|
-
export function
|
|
15
|
-
stream: ReadableStream<Uint8Array>,
|
|
16
|
-
navigation: ChunkNavigation,
|
|
17
|
-
): ReadableStream<Uint8Array> {
|
|
14
|
+
export function chunkRecorderOf(navigation: ChunkNavigation): FlightLineRowHandler {
|
|
18
15
|
|
|
19
16
|
const scriptRows = new Map<string, string>();
|
|
20
|
-
return
|
|
17
|
+
return (row, tag) => {
|
|
21
18
|
if (tag !== "I" && (tag !== "" || row.byteLength > maxScriptRowBytes)) return row;
|
|
22
19
|
const text = rowDecoder.decode(row);
|
|
23
20
|
const colon = text.indexOf(":");
|
|
@@ -31,7 +28,7 @@ export function recordChunksOf(
|
|
|
31
28
|
if (chunkId.endsWith(".js")) chunkNavigations.set(chunkId, navigation);
|
|
32
29
|
}
|
|
33
30
|
return row;
|
|
34
|
-
}
|
|
31
|
+
};
|
|
35
32
|
}
|
|
36
33
|
|
|
37
34
|
export const navigationOfChunk = (chunkId: string): ChunkNavigation | undefined => chunkNavigations.get(chunkId);
|
|
@@ -49,6 +46,119 @@ export const noteChunkLoadFailure = (error: unknown): void => {
|
|
|
49
46
|
export const lazyLinkFailureKeyOf = (error: unknown): string | null =>
|
|
50
47
|
error instanceof Error && isLinkFailure(error) && !chunkLoadFailures.has(error) ? `import() ${error.message}` : null;
|
|
51
48
|
|
|
49
|
+
const namedFetchFailure =
|
|
50
|
+
/^(?:Failed to fetch dynamically imported module|error loading dynamically imported module): \S+$/;
|
|
51
|
+
const unnamedFetchFailure = "Importing a module script failed.";
|
|
52
|
+
const ownClientUrlOf = (href: string): URL | null => {
|
|
53
|
+
try {
|
|
54
|
+
const url = new URL(href);
|
|
55
|
+
return url.origin === window.location.origin && url.pathname.startsWith("/_akan/client/") ? url : null;
|
|
56
|
+
} catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const maxFallbackProbes = 4;
|
|
62
|
+
|
|
63
|
+
const maxUnansweredProbes = 3;
|
|
64
|
+
const failedChunkFetches = new Map<string, number>();
|
|
65
|
+
const noteFailedChunkFetches = (entries: PerformanceEntryList): void => {
|
|
66
|
+
for (const entry of entries as PerformanceResourceTiming[]) {
|
|
67
|
+
const answeredAsFailed =
|
|
68
|
+
entry.responseStatus === undefined
|
|
69
|
+
? entry.responseStart > 0
|
|
70
|
+
: !(entry.responseStatus >= 200 && entry.responseStatus < 300);
|
|
71
|
+
const failed = entry.decodedBodySize === 0 && entry.initiatorType !== "fetch" && answeredAsFailed;
|
|
72
|
+
const url = failed ? ownClientUrlOf(entry.name) : null;
|
|
73
|
+
|
|
74
|
+
if (!url?.pathname.endsWith(".js")) continue;
|
|
75
|
+
failedChunkFetches.delete(url.href);
|
|
76
|
+
failedChunkFetches.set(url.href, 0);
|
|
77
|
+
}
|
|
78
|
+
for (const url of failedChunkFetches.keys())
|
|
79
|
+
if (failedChunkFetches.size > maxFallbackProbes) failedChunkFetches.delete(url);
|
|
80
|
+
};
|
|
81
|
+
const chunkFetchObserver = (() => {
|
|
82
|
+
try {
|
|
83
|
+
const observer = new PerformanceObserver((list) => noteFailedChunkFetches(list.getEntries()));
|
|
84
|
+
observer.observe({ type: "resource", buffered: true });
|
|
85
|
+
return observer;
|
|
86
|
+
} catch {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
})();
|
|
90
|
+
const fallbackChunksFor = (named: string | null): string[] => {
|
|
91
|
+
noteFailedChunkFetches(chunkFetchObserver?.takeRecords() ?? []);
|
|
92
|
+
return [...failedChunkFetches.keys()].filter((url) => url !== named);
|
|
93
|
+
};
|
|
94
|
+
const settleFailedChunkFetch = (url: string, status: number | null): void => {
|
|
95
|
+
const unanswered = failedChunkFetches.get(url);
|
|
96
|
+
if (unanswered === undefined || status === 404) return;
|
|
97
|
+
if ((status !== null && status < 400) || unanswered + 1 >= maxUnansweredProbes) failedChunkFetches.delete(url);
|
|
98
|
+
else failedChunkFetches.set(url, unanswered + 1);
|
|
99
|
+
};
|
|
100
|
+
const probesOut = new Map<string, Promise<boolean>>();
|
|
101
|
+
const probeDeadlineMs = 10_000;
|
|
102
|
+
const isGone = (url: string): Promise<boolean> => {
|
|
103
|
+
const out = probesOut.get(url);
|
|
104
|
+
if (out) return out;
|
|
105
|
+
|
|
106
|
+
const deadline = new AbortController();
|
|
107
|
+
setTimeout(() => deadline.abort(), probeDeadlineMs);
|
|
108
|
+
const gone = fetch(url, { method: "HEAD", cache: "no-store", signal: deadline.signal })
|
|
109
|
+
.then(
|
|
110
|
+
({ status }) => status,
|
|
111
|
+
() => null,
|
|
112
|
+
)
|
|
113
|
+
.then((status) => {
|
|
114
|
+
probesOut.delete(url);
|
|
115
|
+
settleFailedChunkFetch(url, status);
|
|
116
|
+
return status === 404;
|
|
117
|
+
});
|
|
118
|
+
probesOut.set(url, gone);
|
|
119
|
+
return gone;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const unclaimedGoneKey = (urls: string[], keyOf: (url: string) => string): Promise<string | undefined> =>
|
|
123
|
+
new Promise((resolve) => {
|
|
124
|
+
let unsettled = urls.length;
|
|
125
|
+
if (!unsettled) resolve(undefined);
|
|
126
|
+
for (const url of urls)
|
|
127
|
+
void isGone(url).then((gone) => {
|
|
128
|
+
unsettled -= 1;
|
|
129
|
+
if (gone && !isChunkReloadClaimed(keyOf(url))) resolve(keyOf(url));
|
|
130
|
+
else if (!unsettled) resolve(undefined);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const reloadedPathname = window.location.pathname;
|
|
135
|
+
const onReloadedPath = () =>
|
|
136
|
+
window.location.pathname === reloadedPathname &&
|
|
137
|
+
(performance.getEntriesByType("navigation")[0] as PerformanceNavigationTiming | undefined)?.type === "reload";
|
|
138
|
+
|
|
139
|
+
const unloadEvents = ["beforeunload", "pagehide"] as const;
|
|
140
|
+
|
|
141
|
+
export const ifLazyChunkGone = (error: unknown, then: (key: string) => void): void => {
|
|
142
|
+
if (!(error instanceof TypeError) || chunkLoadFailures.has(error) || !navigator.onLine) return;
|
|
143
|
+
const { message } = error;
|
|
144
|
+
const named = namedFetchFailure.test(message)
|
|
145
|
+
? (ownClientUrlOf(message.slice(message.lastIndexOf(" ") + 1))?.href ?? null)
|
|
146
|
+
: null;
|
|
147
|
+
if ((!named && message !== unnamedFetchFailure) || onReloadedPath()) return;
|
|
148
|
+
let unloading = false;
|
|
149
|
+
const unload = () => {
|
|
150
|
+
unloading = true;
|
|
151
|
+
};
|
|
152
|
+
for (const type of unloadEvents) window.addEventListener(type, unload);
|
|
153
|
+
void (async () => {
|
|
154
|
+
const key =
|
|
155
|
+
(await unclaimedGoneKey(named ? [named] : [], () => `import() ${message}`)) ??
|
|
156
|
+
(await unclaimedGoneKey(fallbackChunksFor(named), (gone) => `import() ${message} ${gone}`));
|
|
157
|
+
for (const type of unloadEvents) window.removeEventListener(type, unload);
|
|
158
|
+
if (key && !unloading) then(key);
|
|
159
|
+
})();
|
|
160
|
+
};
|
|
161
|
+
|
|
52
162
|
const reportGlobalError = (error: unknown): void => {
|
|
53
163
|
if (typeof reportError === "function") {
|
|
54
164
|
reportError(error);
|
|
@@ -71,9 +181,17 @@ export const reportingRootErrors = (onError: (error: unknown) => void) => ({
|
|
|
71
181
|
});
|
|
72
182
|
|
|
73
183
|
const chunkReloadsKey = "akan.rsc.chunkReloads";
|
|
184
|
+
const claimedChunkReloads = (): string[] => JSON.parse(sessionStorage.getItem(chunkReloadsKey) ?? "[]") as string[];
|
|
185
|
+
const isChunkReloadClaimed = (chunkId: string): boolean => {
|
|
186
|
+
try {
|
|
187
|
+
return claimedChunkReloads().includes(chunkId);
|
|
188
|
+
} catch {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
74
192
|
export function claimChunkReload(chunkId: string): boolean {
|
|
75
193
|
try {
|
|
76
|
-
const reloaded =
|
|
194
|
+
const reloaded = claimedChunkReloads();
|
|
77
195
|
if (reloaded.includes(chunkId)) return false;
|
|
78
196
|
sessionStorage.setItem(chunkReloadsKey, JSON.stringify([...reloaded, chunkId].slice(-32)));
|
|
79
197
|
return true;
|
package/server/rscClientFetch.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AkanError } from "../base/akanError";
|
|
1
2
|
import {
|
|
2
3
|
AKAN_RSC_IMPORT_MAP_HEADER,
|
|
3
4
|
AKAN_RSC_NOT_FOUND_HEADER,
|
|
@@ -98,7 +99,8 @@ export async function fetchRscNavigationResponse(
|
|
|
98
99
|
}
|
|
99
100
|
if (response.headers.get("X-Akan-Rsc-Partial") === "patch") {
|
|
100
101
|
const patch = readAkanRscPatchMetadataResponseHeaders(response.headers);
|
|
101
|
-
if (options.sendRouterState === false)
|
|
102
|
+
if (options.sendRouterState === false)
|
|
103
|
+
throw new AkanError("invalidRscResponse", "[rscClient] RSC full fallback returned a patch response");
|
|
102
104
|
if (!patch) {
|
|
103
105
|
await response.body?.cancel();
|
|
104
106
|
return fetchRscNavigationResponse(href, {
|
package/server/rscClientPatch.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type ReactNode, startTransition } from "react";
|
|
2
|
+
import { AkanError } from "../base/akanError";
|
|
3
|
+
import { type FlightLineRowHandler, type FlightRowPass, flightRowPassOf } from "./flightRowReader";
|
|
2
4
|
import { type AkanHeadSnapshotV1, type AkanRscPatchMetadata, readAkanRouterStateResponseHeader } from "./routeState";
|
|
5
|
+
import {
|
|
6
|
+
commitPreparedAkanHeadSnapshotPatch,
|
|
7
|
+
prepareAkanHeadSnapshotPatch,
|
|
8
|
+
rollbackPreparedAkanHeadSnapshotPatch,
|
|
9
|
+
} from "./rscHeadPatch";
|
|
3
10
|
import { getRscPayloadStream } from "./rscHttp";
|
|
4
11
|
import {
|
|
5
12
|
type AkanSegmentCacheNode,
|
|
@@ -7,26 +14,37 @@ import {
|
|
|
7
14
|
type AkanSegmentPatchResult,
|
|
8
15
|
applyAkanSegmentCachePatch,
|
|
9
16
|
} from "./rscNavigationState";
|
|
10
|
-
import { hasAkanSegmentOutlet } from "./rscSegmentOutlet";
|
|
17
|
+
import { commitAkanSegmentOutletPatch, hasAkanSegmentOutlet, resetAkanSegmentOutletPatches } from "./rscSegmentOutlet";
|
|
11
18
|
|
|
12
19
|
const RSC_PATCH_REDIRECT_ROW_RE = /^[0-9a-z]+:E\{[^\n]*"digest":"AKAN_REDIRECT(?:;[^"]*)?"[^\n]*\}\n?$/;
|
|
13
|
-
|
|
20
|
+
|
|
21
|
+
const RSC_PATCH_ERROR_ROW_RE = /^[0-9a-z]+:E\{(?![^\n]*"digest":"")[^\n]*\}\n?$/;
|
|
22
|
+
const patchesWithControlRows = new WeakSet<PromiseLike<unknown>>();
|
|
23
|
+
const lateControlHandlers = new WeakMap<PromiseLike<unknown>, () => void>();
|
|
24
|
+
|
|
25
|
+
export interface RscPatchedResult<T> {
|
|
26
|
+
type: "patched";
|
|
27
|
+
tree: AkanSegmentCacheNode<T>;
|
|
28
|
+
patchedNode: AkanSegmentCacheNode<T>;
|
|
29
|
+
patch: AkanRscPatchMetadata;
|
|
30
|
+
outletKey: string;
|
|
31
|
+
headSnapshot: AkanHeadSnapshotV1;
|
|
32
|
+
}
|
|
14
33
|
|
|
15
34
|
interface ValidateRscSegmentPatchInput<T extends PromiseLike<unknown>> {
|
|
16
35
|
href: string;
|
|
17
36
|
response: Response;
|
|
18
37
|
patch: AkanRscPatchMetadata;
|
|
19
38
|
currentTree: AkanSegmentCacheNode<T> | null;
|
|
20
|
-
createThenable: (
|
|
39
|
+
createThenable: (rows: FlightRowPass) => T;
|
|
21
40
|
navId?: number;
|
|
22
41
|
getCurrentNavId?: () => number;
|
|
23
42
|
getHeadSnapshotPatchFailureReason?: (snapshot: AkanHeadSnapshotV1) => AkanSegmentPatchFailureReason | null;
|
|
24
43
|
}
|
|
25
44
|
|
|
26
|
-
function
|
|
27
|
-
stream: ReadableStream<Uint8Array>,
|
|
45
|
+
function patchControlRowGuard(
|
|
28
46
|
onControl: (reason: Extract<AkanSegmentPatchFailureReason, "redirect-in-patch" | "error-in-patch">) => void,
|
|
29
|
-
):
|
|
47
|
+
): FlightLineRowHandler {
|
|
30
48
|
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
31
49
|
|
|
32
50
|
const inspectRow = (row: Uint8Array): void => {
|
|
@@ -38,10 +56,10 @@ function guardRscPatchControlRows(
|
|
|
38
56
|
}
|
|
39
57
|
};
|
|
40
58
|
|
|
41
|
-
return
|
|
59
|
+
return (row, tag) => {
|
|
42
60
|
if (tag === "E") inspectRow(row);
|
|
43
61
|
return row;
|
|
44
|
-
}
|
|
62
|
+
};
|
|
45
63
|
}
|
|
46
64
|
|
|
47
65
|
export async function validateRscPatchAndRequestFullFallback<T extends PromiseLike<unknown>>(
|
|
@@ -61,17 +79,26 @@ export async function validateRscSegmentPatch<T extends PromiseLike<unknown>>({
|
|
|
61
79
|
}: ValidateRscSegmentPatchInput<T>): Promise<AkanSegmentPatchResult<T>> {
|
|
62
80
|
const patchStream = getRscPayloadStream(response);
|
|
63
81
|
let patchControlReason: Extract<AkanSegmentPatchFailureReason, "redirect-in-patch" | "error-in-patch"> | undefined;
|
|
64
|
-
const
|
|
65
|
-
?
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
82
|
+
const patchThenable = patchStream
|
|
83
|
+
? createThenable(
|
|
84
|
+
flightRowPassOf(
|
|
85
|
+
patchStream,
|
|
86
|
+
patchControlRowGuard((reason) => {
|
|
87
|
+
patchControlReason ??= reason;
|
|
88
|
+
if (!patchThenable) return;
|
|
89
|
+
patchesWithControlRows.add(patchThenable);
|
|
90
|
+
lateControlHandlers.get(patchThenable)?.();
|
|
91
|
+
}),
|
|
92
|
+
),
|
|
93
|
+
)
|
|
94
|
+
: undefined;
|
|
70
95
|
let decodeFailed = !patchThenable;
|
|
71
96
|
|
|
72
97
|
if (patchThenable) {
|
|
73
98
|
try {
|
|
74
99
|
await patchThenable;
|
|
100
|
+
|
|
101
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
75
102
|
} catch {
|
|
76
103
|
decodeFailed = true;
|
|
77
104
|
}
|
|
@@ -110,3 +137,39 @@ export async function validateRscPatchForGuardedCommit<T extends PromiseLike<unk
|
|
|
110
137
|
if (!hasAkanSegmentOutlet(patchResult.outletKey)) return { status: "rejected", reason: "outlet-missing" };
|
|
111
138
|
return { ...patchResult, headSnapshot: input.patch.headSnapshot };
|
|
112
139
|
}
|
|
140
|
+
|
|
141
|
+
export function commitRscPatch<T extends PromiseLike<ReactNode>>(
|
|
142
|
+
target: string,
|
|
143
|
+
patch: RscPatchedResult<T>,
|
|
144
|
+
onCommitted: () => void,
|
|
145
|
+
onLateControl: () => void,
|
|
146
|
+
): boolean {
|
|
147
|
+
const patchThenable = patch.patchedNode.thenable;
|
|
148
|
+
if (!patchThenable)
|
|
149
|
+
throw new AkanError("invalidRscResponse", "[rscClient] validated RSC patch is missing a thenable");
|
|
150
|
+
if (patchesWithControlRows.has(patchThenable)) return false;
|
|
151
|
+
const preparedHeadPatch = prepareAkanHeadSnapshotPatch(patch.headSnapshot, target);
|
|
152
|
+
if (!preparedHeadPatch) return false;
|
|
153
|
+
|
|
154
|
+
let outletCommitted = false;
|
|
155
|
+
let headApplied = false;
|
|
156
|
+
startTransition(() => {
|
|
157
|
+
try {
|
|
158
|
+
headApplied = commitPreparedAkanHeadSnapshotPatch(preparedHeadPatch);
|
|
159
|
+
if (!headApplied) return;
|
|
160
|
+
outletCommitted = commitAkanSegmentOutletPatch(patch.outletKey, patchThenable);
|
|
161
|
+
if (!outletCommitted) {
|
|
162
|
+
rollbackPreparedAkanHeadSnapshotPatch(preparedHeadPatch);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
onCommitted();
|
|
166
|
+
lateControlHandlers.set(patchThenable, onLateControl);
|
|
167
|
+
} catch {
|
|
168
|
+
if (headApplied) rollbackPreparedAkanHeadSnapshotPatch(preparedHeadPatch);
|
|
169
|
+
if (outletCommitted) resetAkanSegmentOutletPatches();
|
|
170
|
+
headApplied = false;
|
|
171
|
+
outletCommitted = false;
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
return outletCommitted && headApplied;
|
|
175
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import type { AkanHeadSnapshotNode, ResolvedHead, RouteRender, RouteViewport } from "akanjs/client";
|
|
2
|
+
import { type AkanI18nConfig, getBasePathFromPathname, LocalePath } from "akanjs/common";
|
|
3
|
+
import { untrackedRequest } from "akanjs/fetch";
|
|
4
|
+
import type { ReactNode } from "react";
|
|
5
|
+
import { RouteHead } from "../client/route/RouteHead";
|
|
6
|
+
import { ViewportMeta } from "../client/viewportMeta";
|
|
7
|
+
import { webManifestHref } from "../client/webManifest";
|
|
8
|
+
import type { RouteHeadSnapshots } from "./rscPatchPlanner";
|
|
9
|
+
import { AkanRouteHeadReference } from "./rscSegmentOutletReference";
|
|
10
|
+
|
|
11
|
+
interface RscDocumentHeadProps {
|
|
12
|
+
i18n: () => AkanI18nConfig;
|
|
13
|
+
basePaths: () => string[];
|
|
14
|
+
cssAssets: () => Record<string, { cssUrl: string; cssRelPath: string }>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class RscDocumentHead {
|
|
18
|
+
readonly #props: RscDocumentHeadProps;
|
|
19
|
+
|
|
20
|
+
constructor(props: RscDocumentHeadProps) {
|
|
21
|
+
this.#props = props;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get #i18n(): AkanI18nConfig {
|
|
25
|
+
return this.#props.i18n();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get #basePaths(): string[] {
|
|
29
|
+
return this.#props.basePaths();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get #cssAssets(): Record<string, { cssUrl: string; cssRelPath: string }> {
|
|
33
|
+
return this.#props.cssAssets();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static async firstRootValue<T>(
|
|
37
|
+
renderRootLayouts: RouteRender[],
|
|
38
|
+
read: (render: RouteRender) => T | Promise<T | undefined> | undefined,
|
|
39
|
+
): Promise<T | undefined> {
|
|
40
|
+
const values = await Promise.all(renderRootLayouts.map(read));
|
|
41
|
+
return values.find((value) => value !== undefined);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
renderViewport(viewport: RouteViewport | undefined): ReactNode {
|
|
45
|
+
return <meta key="viewport" name="viewport" content={ViewportMeta.content(viewport)} />;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async renderManifestLink(url: URL, renderRootLayouts: RouteRender[]): Promise<ReactNode> {
|
|
49
|
+
const manifest = await RscDocumentHead.firstRootValue(renderRootLayouts, (render) => render.getLayoutManifest?.());
|
|
50
|
+
if (manifest === undefined) return null;
|
|
51
|
+
|
|
52
|
+
const basePath = getBasePathFromPathname(url.pathname, { basePaths: this.#basePaths, i18n: this.#i18n });
|
|
53
|
+
return <link key="manifest" rel="manifest" href={webManifestHref(basePath)} />;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
renderHeadTags(
|
|
57
|
+
url: URL,
|
|
58
|
+
{
|
|
59
|
+
manifestLink,
|
|
60
|
+
routeHead,
|
|
61
|
+
snapshots,
|
|
62
|
+
noindex = false,
|
|
63
|
+
tags = null,
|
|
64
|
+
themeColors = [],
|
|
65
|
+
}: {
|
|
66
|
+
manifestLink: ReactNode;
|
|
67
|
+
routeHead: ResolvedHead;
|
|
68
|
+
themeColors?: AkanHeadSnapshotNode[];
|
|
69
|
+
snapshots?: RouteHeadSnapshots;
|
|
70
|
+
noindex?: boolean;
|
|
71
|
+
tags?: ReactNode[] | null;
|
|
72
|
+
},
|
|
73
|
+
): ReactNode {
|
|
74
|
+
if (snapshots) {
|
|
75
|
+
const ownsManifest = [...snapshots.layouts.nodes, ...snapshots.page.nodes].some(
|
|
76
|
+
(node) => RouteHead.keyOf(node.tag, node.attrs ?? {}) === "link:manifest",
|
|
77
|
+
);
|
|
78
|
+
return (
|
|
79
|
+
<>
|
|
80
|
+
{ownsManifest ? null : manifestLink}
|
|
81
|
+
<AkanRouteHeadReference
|
|
82
|
+
layouts={{
|
|
83
|
+
...snapshots.layouts,
|
|
84
|
+
nodes: RouteHead.mergeSnapshots([themeColors, snapshots.layouts.nodes]).nodes,
|
|
85
|
+
}}
|
|
86
|
+
page={snapshots.page}
|
|
87
|
+
/>
|
|
88
|
+
</>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
const head = routeHead.node ?? this.renderDefaultHead();
|
|
92
|
+
return (
|
|
93
|
+
<>
|
|
94
|
+
{RouteHead.mergeNodes([
|
|
95
|
+
themeColors.map((node, idx) => <meta key={`theme-color:${idx}`} {...node.attrs} />),
|
|
96
|
+
manifestLink,
|
|
97
|
+
head,
|
|
98
|
+
noindex ? RouteHead.noindexOver(head) : null,
|
|
99
|
+
tags,
|
|
100
|
+
])}
|
|
101
|
+
{this.#renderLocaleAlternates(url)}
|
|
102
|
+
</>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
renderDefaultHead(): ReactNode {
|
|
107
|
+
return <title key="title">{process.env.AKAN_PUBLIC_APP_NAME ?? "Akan App"}</title>;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
getBasePath(url: URL): string | null {
|
|
111
|
+
return getBasePathFromPathname(url.pathname, {
|
|
112
|
+
basePaths: this.#basePaths,
|
|
113
|
+
i18n: this.#i18n,
|
|
114
|
+
headerBasePath: untrackedRequest()?.headers.get("x-base-path"),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
getLocaleAlternateLanguages(url: URL): Record<string, string> {
|
|
119
|
+
const languages: Record<string, string> = {};
|
|
120
|
+
const publicUrl = RscDocumentHead.#getPublicRequestUrl(url);
|
|
121
|
+
for (const lang of this.#i18n.locales) {
|
|
122
|
+
const alternateUrl = new URL(publicUrl);
|
|
123
|
+
alternateUrl.pathname = RscDocumentHead.#replaceLocalePathSegment(publicUrl.pathname, lang, this.#i18n);
|
|
124
|
+
languages[lang] = alternateUrl.href;
|
|
125
|
+
}
|
|
126
|
+
const xDefaultUrl = new URL(publicUrl);
|
|
127
|
+
xDefaultUrl.pathname = "/";
|
|
128
|
+
xDefaultUrl.search = "";
|
|
129
|
+
xDefaultUrl.hash = "";
|
|
130
|
+
languages["x-default"] = xDefaultUrl.href;
|
|
131
|
+
return languages;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
#renderLocaleAlternates(url: URL): ReactNode {
|
|
135
|
+
return Object.entries(this.getLocaleAlternateLanguages(url)).map(([lang, href]) => (
|
|
136
|
+
<link key={`alternate:${lang}`} rel="alternate" hrefLang={lang} href={href} />
|
|
137
|
+
));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
renderStylesheet(pathname: string): ReactNode {
|
|
141
|
+
const cssUrl = this.getStylesheetHref(pathname);
|
|
142
|
+
if (!cssUrl) return null;
|
|
143
|
+
return <link key="stylesheet" rel="stylesheet" href={cssUrl} precedence="default" data-akan-css="active" />;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
getStylesheetHref(pathname: string): string | null {
|
|
147
|
+
const basePath = getBasePathFromPathname(pathname, {
|
|
148
|
+
basePaths: Object.keys(this.#cssAssets),
|
|
149
|
+
i18n: this.#i18n,
|
|
150
|
+
headerBasePath: untrackedRequest()?.headers.get("x-base-path"),
|
|
151
|
+
});
|
|
152
|
+
return this.#cssAssets[basePath ?? ""]?.cssUrl ?? null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
static #getPublicRequestUrl(url: URL): URL {
|
|
156
|
+
const publicUrl = new URL(url);
|
|
157
|
+
const req = untrackedRequest();
|
|
158
|
+
const headers = req?.headers;
|
|
159
|
+
const host = headers?.get("x-forwarded-host")?.split(",")[0]?.trim() ?? headers?.get("host");
|
|
160
|
+
const proto = headers?.get("x-forwarded-proto")?.split(",")[0]?.trim();
|
|
161
|
+
if (host) publicUrl.host = host;
|
|
162
|
+
if (host && !host.includes(":")) publicUrl.port = "";
|
|
163
|
+
if (proto) publicUrl.protocol = proto.endsWith(":") ? proto : `${proto}:`;
|
|
164
|
+
|
|
165
|
+
const basePath = headers?.get("x-base-path");
|
|
166
|
+
const parts = publicUrl.pathname.split("/").filter(Boolean);
|
|
167
|
+
if (basePath && parts[1] === basePath) {
|
|
168
|
+
publicUrl.pathname = `/${[parts[0], ...parts.slice(2)].filter(Boolean).join("/")}`;
|
|
169
|
+
}
|
|
170
|
+
return publicUrl;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
static #replaceLocalePathSegment(pathname: string, lang: string, i18n: AkanI18nConfig): string {
|
|
174
|
+
const parts = pathname.split("/").filter(Boolean);
|
|
175
|
+
return LocalePath.join(lang, `/${parts.slice(1).join("/")}`, i18n);
|
|
176
|
+
}
|
|
177
|
+
}
|