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,170 @@
|
|
|
1
|
+
import type { 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, theme?: string): ReactNode {
|
|
45
|
+
return (
|
|
46
|
+
<>
|
|
47
|
+
<meta key="viewport" name="viewport" content={ViewportMeta.content(viewport)} />
|
|
48
|
+
{ViewportMeta.themeColors(viewport, theme).map(({ content, media }) => (
|
|
49
|
+
<meta key={`theme-color:${media ?? ""}`} name="theme-color" content={content} media={media} />
|
|
50
|
+
))}
|
|
51
|
+
</>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async renderManifestLink(url: URL, renderRootLayouts: RouteRender[]): Promise<ReactNode> {
|
|
56
|
+
const manifest = await RscDocumentHead.firstRootValue(renderRootLayouts, (render) => render.getLayoutManifest?.());
|
|
57
|
+
if (manifest === undefined) return null;
|
|
58
|
+
|
|
59
|
+
const basePath = getBasePathFromPathname(url.pathname, { basePaths: this.#basePaths, i18n: this.#i18n });
|
|
60
|
+
return <link key="manifest" rel="manifest" href={webManifestHref(basePath)} />;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
renderHeadTags(
|
|
64
|
+
url: URL,
|
|
65
|
+
{
|
|
66
|
+
manifestLink,
|
|
67
|
+
routeHead,
|
|
68
|
+
snapshots,
|
|
69
|
+
noindex = false,
|
|
70
|
+
tags = null,
|
|
71
|
+
}: {
|
|
72
|
+
manifestLink: ReactNode;
|
|
73
|
+
routeHead: ResolvedHead;
|
|
74
|
+
snapshots?: RouteHeadSnapshots;
|
|
75
|
+
noindex?: boolean;
|
|
76
|
+
tags?: ReactNode[] | null;
|
|
77
|
+
},
|
|
78
|
+
): ReactNode {
|
|
79
|
+
if (snapshots) {
|
|
80
|
+
const ownsManifest = [...snapshots.layouts.nodes, ...snapshots.page.nodes].some(
|
|
81
|
+
(node) => RouteHead.keyOf(node.tag, node.attrs ?? {}) === "link:manifest",
|
|
82
|
+
);
|
|
83
|
+
return (
|
|
84
|
+
<>
|
|
85
|
+
{ownsManifest ? null : manifestLink}
|
|
86
|
+
<AkanRouteHeadReference layouts={snapshots.layouts} page={snapshots.page} />
|
|
87
|
+
</>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
const head = routeHead.node ?? this.renderDefaultHead();
|
|
91
|
+
return (
|
|
92
|
+
<>
|
|
93
|
+
{RouteHead.mergeNodes([manifestLink, head, noindex ? RouteHead.noindexOver(head) : null, tags])}
|
|
94
|
+
{this.#renderLocaleAlternates(url)}
|
|
95
|
+
</>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
renderDefaultHead(): ReactNode {
|
|
100
|
+
return <title key="title">{process.env.AKAN_PUBLIC_APP_NAME ?? "Akan App"}</title>;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
getBasePath(url: URL): string | null {
|
|
104
|
+
return getBasePathFromPathname(url.pathname, {
|
|
105
|
+
basePaths: this.#basePaths,
|
|
106
|
+
i18n: this.#i18n,
|
|
107
|
+
headerBasePath: untrackedRequest()?.headers.get("x-base-path"),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
getLocaleAlternateLanguages(url: URL): Record<string, string> {
|
|
112
|
+
const languages: Record<string, string> = {};
|
|
113
|
+
const publicUrl = RscDocumentHead.#getPublicRequestUrl(url);
|
|
114
|
+
for (const lang of this.#i18n.locales) {
|
|
115
|
+
const alternateUrl = new URL(publicUrl);
|
|
116
|
+
alternateUrl.pathname = RscDocumentHead.#replaceLocalePathSegment(publicUrl.pathname, lang, this.#i18n);
|
|
117
|
+
languages[lang] = alternateUrl.href;
|
|
118
|
+
}
|
|
119
|
+
const xDefaultUrl = new URL(publicUrl);
|
|
120
|
+
xDefaultUrl.pathname = "/";
|
|
121
|
+
xDefaultUrl.search = "";
|
|
122
|
+
xDefaultUrl.hash = "";
|
|
123
|
+
languages["x-default"] = xDefaultUrl.href;
|
|
124
|
+
return languages;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
#renderLocaleAlternates(url: URL): ReactNode {
|
|
128
|
+
return Object.entries(this.getLocaleAlternateLanguages(url)).map(([lang, href]) => (
|
|
129
|
+
<link key={`alternate:${lang}`} rel="alternate" hrefLang={lang} href={href} />
|
|
130
|
+
));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
renderStylesheet(pathname: string): ReactNode {
|
|
134
|
+
const cssUrl = this.getStylesheetHref(pathname);
|
|
135
|
+
if (!cssUrl) return null;
|
|
136
|
+
return <link key="stylesheet" rel="stylesheet" href={cssUrl} precedence="default" data-akan-css="active" />;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
getStylesheetHref(pathname: string): string | null {
|
|
140
|
+
const basePath = getBasePathFromPathname(pathname, {
|
|
141
|
+
basePaths: Object.keys(this.#cssAssets),
|
|
142
|
+
i18n: this.#i18n,
|
|
143
|
+
headerBasePath: untrackedRequest()?.headers.get("x-base-path"),
|
|
144
|
+
});
|
|
145
|
+
return this.#cssAssets[basePath ?? ""]?.cssUrl ?? null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
static #getPublicRequestUrl(url: URL): URL {
|
|
149
|
+
const publicUrl = new URL(url);
|
|
150
|
+
const req = untrackedRequest();
|
|
151
|
+
const headers = req?.headers;
|
|
152
|
+
const host = headers?.get("x-forwarded-host")?.split(",")[0]?.trim() ?? headers?.get("host");
|
|
153
|
+
const proto = headers?.get("x-forwarded-proto")?.split(",")[0]?.trim();
|
|
154
|
+
if (host) publicUrl.host = host;
|
|
155
|
+
if (host && !host.includes(":")) publicUrl.port = "";
|
|
156
|
+
if (proto) publicUrl.protocol = proto.endsWith(":") ? proto : `${proto}:`;
|
|
157
|
+
|
|
158
|
+
const basePath = headers?.get("x-base-path");
|
|
159
|
+
const parts = publicUrl.pathname.split("/").filter(Boolean);
|
|
160
|
+
if (basePath && parts[1] === basePath) {
|
|
161
|
+
publicUrl.pathname = `/${[parts[0], ...parts.slice(2)].filter(Boolean).join("/")}`;
|
|
162
|
+
}
|
|
163
|
+
return publicUrl;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
static #replaceLocalePathSegment(pathname: string, lang: string, i18n: AkanI18nConfig): string {
|
|
167
|
+
const parts = pathname.split("/").filter(Boolean);
|
|
168
|
+
return LocalePath.join(lang, `/${parts.slice(1).join("/")}`, i18n);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { Logger } from "akanjs/common";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import type { ClientManifest } from "./artifact";
|
|
4
|
+
import { type FlightRenderOptions, type FlightRenderResult, RscFlightStream } from "./rscFlightStream";
|
|
5
|
+
|
|
6
|
+
export class RscFlightRenderer {
|
|
7
|
+
readonly #logger: Logger;
|
|
8
|
+
readonly #send: (message: unknown) => void;
|
|
9
|
+
readonly #activeRenderReaders = new Map<string, ReadableStreamDefaultReader<Uint8Array>>();
|
|
10
|
+
readonly #inFlightRenders = new Map<string, { cancelled: boolean }>();
|
|
11
|
+
|
|
12
|
+
constructor(logger: Logger, send: (message: unknown) => void) {
|
|
13
|
+
this.#logger = logger;
|
|
14
|
+
this.#send = send;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
renderFlightElement(
|
|
18
|
+
element: ReactNode,
|
|
19
|
+
clientManifest: ClientManifest,
|
|
20
|
+
options: FlightRenderOptions = {},
|
|
21
|
+
): Promise<FlightRenderResult> {
|
|
22
|
+
const stream = new RscFlightStream(
|
|
23
|
+
{
|
|
24
|
+
logger: this.#logger,
|
|
25
|
+
send: this.#send,
|
|
26
|
+
isCancelled: (requestId) => this.isCancelled(requestId),
|
|
27
|
+
track: (requestId, reader) => this.#activeRenderReaders.set(requestId, reader),
|
|
28
|
+
untrack: (requestId) => this.#activeRenderReaders.delete(requestId),
|
|
29
|
+
reportRenderError: (error, pathname) => this.#reportRenderError(error, pathname),
|
|
30
|
+
},
|
|
31
|
+
options,
|
|
32
|
+
);
|
|
33
|
+
return stream.render(element, clientManifest);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get inFlightCount(): number {
|
|
37
|
+
return this.#inFlightRenders.size;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
begin(requestId: string): void {
|
|
41
|
+
this.#inFlightRenders.set(requestId, { cancelled: false });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
isCancelled(requestId: string): boolean {
|
|
45
|
+
return !!this.#inFlightRenders.get(requestId)?.cancelled;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
handleCancel(requestId: string): void {
|
|
49
|
+
const render = this.#inFlightRenders.get(requestId);
|
|
50
|
+
if (!render) return;
|
|
51
|
+
render.cancelled = true;
|
|
52
|
+
const reader = this.#activeRenderReaders.get(requestId);
|
|
53
|
+
if (!reader) return;
|
|
54
|
+
void reader.cancel().catch(() => {
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
release(requestId: string): void {
|
|
59
|
+
this.#activeRenderReaders.delete(requestId);
|
|
60
|
+
this.#inFlightRenders.delete(requestId);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
#reportRenderError(error: unknown, pathname?: string): string {
|
|
64
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
65
|
+
const description = error instanceof Error ? (error.stack ?? message) : message;
|
|
66
|
+
const opaque = process.env.NODE_ENV === "production";
|
|
67
|
+
const digest = opaque ? crypto.randomUUID().slice(0, 8) : message || "AKAN_RENDER_ERROR";
|
|
68
|
+
const scope = `${pathname ? ` path=${pathname}` : ""}${opaque ? ` digest=${digest}` : ""}`;
|
|
69
|
+
if (RscFlightRenderer.#isExpectedRequestAbort(error))
|
|
70
|
+
this.#logger.debug(`[rsc] render aborted${scope}: ${description}`);
|
|
71
|
+
else this.#logger.error(`[rsc] render failed${scope}: ${description}`);
|
|
72
|
+
return digest;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static #isExpectedRequestAbort(error: unknown): boolean {
|
|
76
|
+
if (!(error instanceof Error)) return false;
|
|
77
|
+
return (
|
|
78
|
+
error.name === "AbortError" ||
|
|
79
|
+
error.message === "Connection closed." ||
|
|
80
|
+
error.message.includes("The connection was closed")
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import type { RedirectStatus } from "akanjs/client";
|
|
2
|
+
import type { Logger } from "akanjs/common";
|
|
3
|
+
import { type AkanTheme, getRequestTheme } from "akanjs/fetch";
|
|
4
|
+
import type { ReactNode } from "react";
|
|
5
|
+
import { renderToReadableStream } from "react-server-dom-webpack/server.node";
|
|
6
|
+
import { getCurrentTrace } from "../signal/trace";
|
|
7
|
+
import type { ClientManifest } from "./artifact";
|
|
8
|
+
import type { RouteCacheRenderState } from "./cachePolicy";
|
|
9
|
+
import { RouteElementComposer } from "./routeElementComposer";
|
|
10
|
+
import type { RouteShellGate } from "./routeShellGate";
|
|
11
|
+
import { concatBytes, encodeAkanRedirectDigest } from "./rscHttp";
|
|
12
|
+
import { isAkanNotFoundError, isAkanRedirectError } from "./rscRenderControl";
|
|
13
|
+
import type { RscTraceMetadata } from "./ssrTypes";
|
|
14
|
+
|
|
15
|
+
export type RenderControl =
|
|
16
|
+
| { type: "redirect"; location: string; method: "replace" | "push"; status: RedirectStatus }
|
|
17
|
+
| { type: "not-found" }
|
|
18
|
+
| { type: "error"; error: unknown };
|
|
19
|
+
|
|
20
|
+
export interface FlightRenderResult {
|
|
21
|
+
chunks: Uint8Array[];
|
|
22
|
+
bytes: number;
|
|
23
|
+
chunksCount: number;
|
|
24
|
+
control: RenderControl | null;
|
|
25
|
+
lateControlSent: boolean;
|
|
26
|
+
cancelled: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface FlightRenderOptions {
|
|
30
|
+
requestId?: string;
|
|
31
|
+
collectChunks?: boolean;
|
|
32
|
+
status?: number;
|
|
33
|
+
trace?: RscTraceMetadata;
|
|
34
|
+
/** Raised by a render that answered `router.notFound()` in place, which React never reports as an error. */
|
|
35
|
+
notFoundProbe?: { hit: boolean };
|
|
36
|
+
gate?: RouteShellGate;
|
|
37
|
+
onComplete?: (
|
|
38
|
+
result: Omit<FlightRenderResult, "cancelled">,
|
|
39
|
+
) => Promise<RouteCacheRenderState> | RouteCacheRenderState;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface RscFlightStreamProps {
|
|
43
|
+
logger: Logger;
|
|
44
|
+
send: (message: unknown) => void;
|
|
45
|
+
isCancelled: (requestId: string) => boolean;
|
|
46
|
+
track: (requestId: string, reader: ReadableStreamDefaultReader<Uint8Array>) => void;
|
|
47
|
+
untrack: (requestId: string) => void;
|
|
48
|
+
reportRenderError: (error: unknown, pathname?: string) => string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export class RscFlightStream {
|
|
52
|
+
readonly #props: RscFlightStreamProps;
|
|
53
|
+
readonly #options: FlightRenderOptions;
|
|
54
|
+
readonly #controlRef: { current: RenderControl | null } = { current: null };
|
|
55
|
+
|
|
56
|
+
#isCancelling: boolean = false;
|
|
57
|
+
#bytes = 0;
|
|
58
|
+
#chunksCount = 0;
|
|
59
|
+
#sentMeta: boolean = false;
|
|
60
|
+
#sentChunk: boolean = false;
|
|
61
|
+
#lateControlSent: boolean = false;
|
|
62
|
+
readonly #chunks: Uint8Array[] = [];
|
|
63
|
+
|
|
64
|
+
#holding: RouteShellGate | null = null;
|
|
65
|
+
#held: Uint8Array | null = null;
|
|
66
|
+
#reportedTheme: AkanTheme | undefined;
|
|
67
|
+
|
|
68
|
+
constructor(props: RscFlightStreamProps, options: FlightRenderOptions) {
|
|
69
|
+
this.#props = props;
|
|
70
|
+
this.#options = options;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async render(element: ReactNode, clientManifest: ClientManifest): Promise<FlightRenderResult> {
|
|
74
|
+
const options = this.#options;
|
|
75
|
+
const stream = await renderToReadableStream(element, clientManifest, {
|
|
76
|
+
onError: (error) => this.#onError(error),
|
|
77
|
+
});
|
|
78
|
+
const reader = stream.getReader();
|
|
79
|
+
if (options.requestId) this.#props.track(options.requestId, reader);
|
|
80
|
+
this.#holding = options.gate?.holding ? options.gate : null;
|
|
81
|
+
try {
|
|
82
|
+
let pendingRead: ReturnType<typeof reader.read> | null = null;
|
|
83
|
+
for (;;) {
|
|
84
|
+
if (options.requestId && this.#props.isCancelled(options.requestId))
|
|
85
|
+
return await this.#cancelWith(reader, null, true);
|
|
86
|
+
pendingRead ??= reader.read();
|
|
87
|
+
const holding = this.#holding;
|
|
88
|
+
if (holding && (await Promise.race([pendingRead.then(() => false), holding.opened.then(() => true)]))) {
|
|
89
|
+
this.#readProbe();
|
|
90
|
+
if (this.#controlRef.current?.type === "error")
|
|
91
|
+
return await this.#cancelWith(reader, this.#controlRef.current, false);
|
|
92
|
+
this.#releaseHeld();
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const { value, done } = await pendingRead;
|
|
96
|
+
pendingRead = null;
|
|
97
|
+
if (options.requestId && this.#props.isCancelled(options.requestId))
|
|
98
|
+
return await this.#cancelWith(reader, null, true);
|
|
99
|
+
this.#readProbe();
|
|
100
|
+
if (
|
|
101
|
+
this.#controlRef.current &&
|
|
102
|
+
!this.#sentChunk &&
|
|
103
|
+
(!this.#holding || this.#controlRef.current.type === "error")
|
|
104
|
+
)
|
|
105
|
+
return await this.#cancelWith(reader, this.#controlRef.current, false);
|
|
106
|
+
if (this.#controlRef.current && this.#sentChunk) this.#sendLateControl();
|
|
107
|
+
if (done) break;
|
|
108
|
+
|
|
109
|
+
if (this.#chunksCount === 0 && options.requestId) {
|
|
110
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
111
|
+
this.#readProbe();
|
|
112
|
+
if (this.#controlRef.current) return await this.#cancelWith(reader, this.#controlRef.current, false);
|
|
113
|
+
}
|
|
114
|
+
const chunk = value instanceof Uint8Array ? value : new Uint8Array(value as ArrayBufferLike);
|
|
115
|
+
this.#bytes += chunk.byteLength;
|
|
116
|
+
this.#chunksCount += 1;
|
|
117
|
+
if (this.#holding) this.#held = this.#held ? concatBytes(this.#held, chunk) : chunk;
|
|
118
|
+
else this.#emit(chunk);
|
|
119
|
+
}
|
|
120
|
+
} catch (error) {
|
|
121
|
+
if (options.requestId && this.#props.isCancelled(options.requestId)) {
|
|
122
|
+
return this.#resultOf(null, true);
|
|
123
|
+
}
|
|
124
|
+
throw error;
|
|
125
|
+
} finally {
|
|
126
|
+
if (options.requestId) this.#props.untrack(options.requestId);
|
|
127
|
+
reader.releaseLock();
|
|
128
|
+
}
|
|
129
|
+
this.#readProbe();
|
|
130
|
+
if (this.#holding && this.#controlRef.current?.type !== "error") this.#releaseHeld();
|
|
131
|
+
if (this.#controlRef.current && this.#sentChunk) this.#sendLateControl();
|
|
132
|
+
if (this.#controlRef.current && !this.#sentChunk) return this.#resultOf(this.#controlRef.current, false);
|
|
133
|
+
if (options.requestId) {
|
|
134
|
+
this.#sendMeta();
|
|
135
|
+
const cacheState = (await options.onComplete?.({
|
|
136
|
+
chunks: this.#chunks,
|
|
137
|
+
bytes: this.#bytes,
|
|
138
|
+
chunksCount: this.#chunksCount,
|
|
139
|
+
control: this.#controlRef.current,
|
|
140
|
+
lateControlSent: this.#lateControlSent,
|
|
141
|
+
})) ?? { cacheable: false, reason: "uncacheable-render" };
|
|
142
|
+
this.#props.send({ type: "cache-state", requestId: options.requestId, state: cacheState });
|
|
143
|
+
this.#props.send({ type: "end", requestId: options.requestId });
|
|
144
|
+
}
|
|
145
|
+
return this.#resultOf(this.#lateControlSent ? this.#controlRef.current : null, false);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
#onError(error: unknown): string | undefined {
|
|
149
|
+
const options = this.#options;
|
|
150
|
+
if (this.#isCancelling || (options.requestId && this.#props.isCancelled(options.requestId))) return;
|
|
151
|
+
if (isAkanRedirectError(error)) {
|
|
152
|
+
const { location, method, status } = error;
|
|
153
|
+
this.#controlRef.current = { type: "redirect", location, method, status };
|
|
154
|
+
return encodeAkanRedirectDigest({ location, method, status });
|
|
155
|
+
}
|
|
156
|
+
if (isAkanNotFoundError(error)) {
|
|
157
|
+
this.#controlRef.current = { type: "not-found" };
|
|
158
|
+
return error.digest;
|
|
159
|
+
}
|
|
160
|
+
if (!RouteElementComposer.streamed(error)) this.#controlRef.current = { type: "error", error };
|
|
161
|
+
return this.#props.reportRenderError(error, options.trace?.pathname);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
#resultOf(control: RenderControl | null, cancelled: boolean): FlightRenderResult {
|
|
165
|
+
return {
|
|
166
|
+
chunks: this.#chunks,
|
|
167
|
+
bytes: this.#bytes,
|
|
168
|
+
chunksCount: this.#chunksCount,
|
|
169
|
+
control,
|
|
170
|
+
lateControlSent: this.#lateControlSent,
|
|
171
|
+
cancelled,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
#sendMeta(): void {
|
|
176
|
+
const options = this.#options;
|
|
177
|
+
if (!options.requestId || this.#sentMeta) return;
|
|
178
|
+
this.#sentMeta = true;
|
|
179
|
+
if (options.status !== undefined) {
|
|
180
|
+
const trace = getCurrentTrace();
|
|
181
|
+
if (trace) trace.status = options.status;
|
|
182
|
+
}
|
|
183
|
+
this.#reportedTheme = getRequestTheme();
|
|
184
|
+
this.#props.send({
|
|
185
|
+
type: "meta",
|
|
186
|
+
requestId: options.requestId,
|
|
187
|
+
theme: this.#reportedTheme,
|
|
188
|
+
status: options.status,
|
|
189
|
+
trace: options.trace,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
#sendLateTheme(): void {
|
|
194
|
+
const options = this.#options;
|
|
195
|
+
const theme = getRequestTheme();
|
|
196
|
+
if (!options.requestId || !this.#sentMeta || theme === this.#reportedTheme) return;
|
|
197
|
+
this.#reportedTheme = theme;
|
|
198
|
+
this.#props.send({ type: "theme", requestId: options.requestId, theme });
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
async #cancelWith(
|
|
202
|
+
reader: ReadableStreamDefaultReader<Uint8Array>,
|
|
203
|
+
control: RenderControl | null,
|
|
204
|
+
cancelled: boolean,
|
|
205
|
+
): Promise<FlightRenderResult> {
|
|
206
|
+
this.#isCancelling = true;
|
|
207
|
+
await reader.cancel();
|
|
208
|
+
return this.#resultOf(control, cancelled);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
#readProbe(): void {
|
|
212
|
+
if (!this.#controlRef.current && this.#options.notFoundProbe?.hit) this.#controlRef.current = { type: "not-found" };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
#emit(chunk: Uint8Array): void {
|
|
216
|
+
const options = this.#options;
|
|
217
|
+
if (options.collectChunks) this.#chunks.push(chunk);
|
|
218
|
+
if (!options.requestId) return;
|
|
219
|
+
this.#sendMeta();
|
|
220
|
+
this.#sendLateTheme();
|
|
221
|
+
this.#props.send({ type: "chunk", requestId: options.requestId, data: chunk });
|
|
222
|
+
this.#sentChunk = true;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
#releaseHeld(): void {
|
|
226
|
+
this.#holding = null;
|
|
227
|
+
if (!this.#held) return;
|
|
228
|
+
if (this.#controlRef.current) {
|
|
229
|
+
this.#sendMeta();
|
|
230
|
+
this.#sendLateControl();
|
|
231
|
+
}
|
|
232
|
+
this.#emit(this.#held);
|
|
233
|
+
this.#held = null;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
#sendLateControl(): void {
|
|
237
|
+
const options = this.#options;
|
|
238
|
+
const control = this.#controlRef.current;
|
|
239
|
+
if (!options.requestId || this.#lateControlSent || !control || control.type === "error") return;
|
|
240
|
+
this.#lateControlSent = true;
|
|
241
|
+
if (control.type === "redirect") {
|
|
242
|
+
this.#props.send({
|
|
243
|
+
type: "late-redirect",
|
|
244
|
+
requestId: options.requestId,
|
|
245
|
+
location: control.location,
|
|
246
|
+
method: control.method,
|
|
247
|
+
status: control.status,
|
|
248
|
+
});
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (!options.notFoundProbe?.hit)
|
|
252
|
+
this.#props.logger.warn(
|
|
253
|
+
`render[${options.requestId}] not-found raised below a route render after the stream started; that subtree renders nothing — call router.notFound() from the page or layout body`,
|
|
254
|
+
);
|
|
255
|
+
this.#props.send({ type: "late-not-found", requestId: options.requestId });
|
|
256
|
+
}
|
|
257
|
+
}
|
package/server/rscHeadPatch.ts
CHANGED
|
@@ -1,31 +1,17 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { hasRscRouteHead, type RscRoutePatch, readRscRoutePatch, writeRscRoutePatch } from "../client/rscRoutePatch";
|
|
2
|
+
import type { AkanHeadSnapshotV1 } from "./routeState";
|
|
2
3
|
import type { AkanSegmentPatchFailureReason } from "./rscNavigationState";
|
|
3
4
|
|
|
4
|
-
const AKAN_ROUTE_HEAD_SELECTOR = '[data-akan-head="route"]';
|
|
5
|
-
|
|
6
5
|
export interface PreparedAkanHeadSnapshotPatch {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function createHeadElement(node: AkanHeadSnapshotNode, index: number): HTMLElement {
|
|
12
|
-
const element = document.createElement(node.tag);
|
|
13
|
-
element.setAttribute("data-akan-head", "route");
|
|
14
|
-
element.setAttribute("data-akan-head-key", `${node.tag}:${index}`);
|
|
15
|
-
for (const [key, value] of Object.entries(node.attrs ?? {})) {
|
|
16
|
-
element.setAttribute(key, value);
|
|
17
|
-
}
|
|
18
|
-
if (node.tag === "title") element.textContent = node.text ?? "";
|
|
19
|
-
return element;
|
|
6
|
+
previous: RscRoutePatch | null;
|
|
7
|
+
next: RscRoutePatch;
|
|
20
8
|
}
|
|
21
9
|
|
|
22
10
|
export function getAkanHeadSnapshotPatchFailureReason(
|
|
23
11
|
snapshot: AkanHeadSnapshotV1,
|
|
24
12
|
): Extract<AkanSegmentPatchFailureReason, "head-missing" | "head-invalid"> | null {
|
|
25
|
-
if (typeof document === "undefined" || !document.head) return "head-invalid";
|
|
26
|
-
const existing = document.head.querySelector(AKAN_ROUTE_HEAD_SELECTOR);
|
|
27
|
-
if (!existing) return "head-missing";
|
|
28
13
|
if (!Array.isArray(snapshot.nodes)) return "head-invalid";
|
|
14
|
+
if (!hasRscRouteHead()) return "head-missing";
|
|
29
15
|
return null;
|
|
30
16
|
}
|
|
31
17
|
|
|
@@ -33,50 +19,25 @@ export function canApplyAkanHeadSnapshotPatch(snapshot: AkanHeadSnapshotV1): boo
|
|
|
33
19
|
return getAkanHeadSnapshotPatchFailureReason(snapshot) === null;
|
|
34
20
|
}
|
|
35
21
|
|
|
36
|
-
export function prepareAkanHeadSnapshotPatch(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
existing,
|
|
43
|
-
replacement: snapshot.nodes.map((node, index) => createHeadElement(node, index)),
|
|
44
|
-
};
|
|
45
|
-
} catch {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
22
|
+
export function prepareAkanHeadSnapshotPatch(
|
|
23
|
+
snapshot: AkanHeadSnapshotV1,
|
|
24
|
+
href: string,
|
|
25
|
+
): PreparedAkanHeadSnapshotPatch | null {
|
|
26
|
+
if (getAkanHeadSnapshotPatchFailureReason(snapshot)) return null;
|
|
27
|
+
return { previous: readRscRoutePatch(), next: { href, head: snapshot } };
|
|
48
28
|
}
|
|
49
29
|
|
|
50
30
|
export function commitPreparedAkanHeadSnapshotPatch(prepared: PreparedAkanHeadSnapshotPatch): boolean {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const anchor = inHead[0];
|
|
55
|
-
if (!anchor) return false;
|
|
56
|
-
const fragment = document.createDocumentFragment();
|
|
57
|
-
for (const node of prepared.replacement) fragment.appendChild(node);
|
|
58
|
-
document.head.insertBefore(fragment, anchor);
|
|
59
|
-
for (const node of inHead) node.remove();
|
|
60
|
-
return true;
|
|
61
|
-
} catch {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
31
|
+
if (!hasRscRouteHead()) return false;
|
|
32
|
+
writeRscRoutePatch(prepared.next);
|
|
33
|
+
return true;
|
|
64
34
|
}
|
|
65
35
|
|
|
66
36
|
export function rollbackPreparedAkanHeadSnapshotPatch(prepared: PreparedAkanHeadSnapshotPatch): void {
|
|
67
|
-
|
|
68
|
-
const anchor = prepared.replacement.find((node) => node.parentNode === document.head) ?? null;
|
|
69
|
-
if (anchor) {
|
|
70
|
-
const fragment = document.createDocumentFragment();
|
|
71
|
-
for (const node of prepared.existing) if (!node.parentNode) fragment.appendChild(node);
|
|
72
|
-
document.head.insertBefore(fragment, anchor);
|
|
73
|
-
}
|
|
74
|
-
for (const node of prepared.replacement) if (node.parentNode === document.head) node.remove();
|
|
75
|
-
} catch {
|
|
76
|
-
}
|
|
37
|
+
writeRscRoutePatch(prepared.previous);
|
|
77
38
|
}
|
|
78
39
|
|
|
79
|
-
export function applyAkanHeadSnapshotPatch(snapshot: AkanHeadSnapshotV1): boolean {
|
|
80
|
-
const prepared = prepareAkanHeadSnapshotPatch(snapshot);
|
|
40
|
+
export function applyAkanHeadSnapshotPatch(snapshot: AkanHeadSnapshotV1, href: string): boolean {
|
|
41
|
+
const prepared = prepareAkanHeadSnapshotPatch(snapshot, href);
|
|
81
42
|
return prepared ? commitPreparedAkanHeadSnapshotPatch(prepared) : false;
|
|
82
43
|
}
|