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,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
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import type { FlightLineRowHandler } from "./flightRowReader";
|
|
2
|
+
|
|
3
|
+
export interface ChunkNavigation {
|
|
4
|
+
navId: number;
|
|
5
|
+
href: string;
|
|
6
|
+
replace: () => boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const chunkNavigations = new Map<string, ChunkNavigation>();
|
|
10
|
+
const quotedString = /"([^"\\]*)"/g;
|
|
11
|
+
const maxScriptRowBytes = 1024;
|
|
12
|
+
const rowDecoder = new TextDecoder();
|
|
13
|
+
|
|
14
|
+
export function chunkRecorderOf(navigation: ChunkNavigation): FlightLineRowHandler {
|
|
15
|
+
|
|
16
|
+
const scriptRows = new Map<string, string>();
|
|
17
|
+
return (row, tag) => {
|
|
18
|
+
if (tag !== "I" && (tag !== "" || row.byteLength > maxScriptRowBytes)) return row;
|
|
19
|
+
const text = rowDecoder.decode(row);
|
|
20
|
+
const colon = text.indexOf(":");
|
|
21
|
+
const value = text.slice(colon + 1 + tag.length).trimEnd();
|
|
22
|
+
if (tag === "") {
|
|
23
|
+
if (value.startsWith('"') && value.endsWith('.js"')) scriptRows.set(text.slice(0, colon), value.slice(1, -1));
|
|
24
|
+
return row;
|
|
25
|
+
}
|
|
26
|
+
for (const [, named] of value.matchAll(quotedString)) {
|
|
27
|
+
const chunkId = (named.startsWith("$") ? scriptRows.get(named.slice(1)) : undefined) ?? named;
|
|
28
|
+
if (chunkId.endsWith(".js")) chunkNavigations.set(chunkId, navigation);
|
|
29
|
+
}
|
|
30
|
+
return row;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const navigationOfChunk = (chunkId: string): ChunkNavigation | undefined => chunkNavigations.get(chunkId);
|
|
35
|
+
|
|
36
|
+
const linkFailure =
|
|
37
|
+
/does not provide an export named|doesn't provide an export named|import not found|Importing binding name|Failed to resolve module specifier|was a bare specifier|does not resolve to a valid URL/;
|
|
38
|
+
export const isLinkFailure = (error: unknown): boolean =>
|
|
39
|
+
(error instanceof SyntaxError || error instanceof TypeError) && linkFailure.test(error.message);
|
|
40
|
+
|
|
41
|
+
const chunkLoadFailures = new WeakSet<object>();
|
|
42
|
+
export const noteChunkLoadFailure = (error: unknown): void => {
|
|
43
|
+
if (typeof error === "object" && error !== null) chunkLoadFailures.add(error);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const lazyLinkFailureKeyOf = (error: unknown): string | null =>
|
|
47
|
+
error instanceof Error && isLinkFailure(error) && !chunkLoadFailures.has(error) ? `import() ${error.message}` : null;
|
|
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
|
+
|
|
162
|
+
const reportGlobalError = (error: unknown): void => {
|
|
163
|
+
if (typeof reportError === "function") {
|
|
164
|
+
reportError(error);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
168
|
+
if (window.dispatchEvent(new ErrorEvent("error", { bubbles: true, cancelable: true, message, error })))
|
|
169
|
+
console.error(error);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export const reportingRootErrors = (onError: (error: unknown) => void) => ({
|
|
173
|
+
onCaughtError: (error: unknown) => {
|
|
174
|
+
console.error(error);
|
|
175
|
+
onError(error);
|
|
176
|
+
},
|
|
177
|
+
onUncaughtError: (error: unknown) => {
|
|
178
|
+
reportGlobalError(error);
|
|
179
|
+
onError(error);
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
|
|
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
|
+
};
|
|
192
|
+
export function claimChunkReload(chunkId: string): boolean {
|
|
193
|
+
try {
|
|
194
|
+
const reloaded = claimedChunkReloads();
|
|
195
|
+
if (reloaded.includes(chunkId)) return false;
|
|
196
|
+
sessionStorage.setItem(chunkReloadsKey, JSON.stringify([...reloaded, chunkId].slice(-32)));
|
|
197
|
+
return true;
|
|
198
|
+
} catch {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export const isBuildBundle = (): boolean => {
|
|
204
|
+
try {
|
|
205
|
+
return process.env.AKAN_BUNDLE_COMMAND === "build";
|
|
206
|
+
} catch {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
};
|
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,
|
|
@@ -5,6 +6,7 @@ import {
|
|
|
5
6
|
type AkanRouterStateV1,
|
|
6
7
|
type AkanRscPatchMetadata,
|
|
7
8
|
appendAkanRouterStateRequestHeaders,
|
|
9
|
+
isAkanRscPartialCommitEnabled,
|
|
8
10
|
readAkanRscPatchMetadataResponseHeaders,
|
|
9
11
|
} from "./routeState";
|
|
10
12
|
|
|
@@ -21,6 +23,9 @@ const rscEndpointOf = (href: string, buildId?: number) => {
|
|
|
21
23
|
return endpoint;
|
|
22
24
|
};
|
|
23
25
|
|
|
26
|
+
const sentRouterStateOf = (state: AkanRouterStateV1 | null) =>
|
|
27
|
+
state?.headKey && !isAkanRscPartialCommitEnabled() ? { ...state, headKey: undefined } : state;
|
|
28
|
+
|
|
24
29
|
const rscRequestHeaders = () => {
|
|
25
30
|
const headers = new Headers({ Accept: "text/x-component", "Cache-Control": "no-cache" });
|
|
26
31
|
const importMapKey = (globalThis as { __AKAN_IMPORT_MAP_KEY__?: string }).__AKAN_IMPORT_MAP_KEY__;
|
|
@@ -41,9 +46,14 @@ const fetchKeepingHeaders = async (endpoint: URL, init: RequestInit, signal: Abo
|
|
|
41
46
|
return response;
|
|
42
47
|
};
|
|
43
48
|
|
|
44
|
-
export const fetchRscPrefetchResponse = (
|
|
49
|
+
export const fetchRscPrefetchResponse = (
|
|
50
|
+
href: string,
|
|
51
|
+
signal: AbortSignal,
|
|
52
|
+
currentRouterState: AkanRouterStateV1 | null = null,
|
|
53
|
+
) => {
|
|
45
54
|
const headers = rscRequestHeaders();
|
|
46
55
|
headers.set(AKAN_RSC_PREFETCH_HEADER, "1");
|
|
56
|
+
if (isAkanRscPartialCommitEnabled()) appendAkanRouterStateRequestHeaders(headers, currentRouterState);
|
|
47
57
|
return fetchKeepingHeaders(rscEndpointOf(href), { headers, credentials: "same-origin", cache: "no-store" }, signal);
|
|
48
58
|
};
|
|
49
59
|
|
|
@@ -62,7 +72,8 @@ export async function fetchRscNavigationResponse(
|
|
|
62
72
|
): Promise<RscClientFetchResponseResult> {
|
|
63
73
|
const shouldApplyNavigation = options.shouldApplyNavigation ?? (() => true);
|
|
64
74
|
const headers = rscRequestHeaders();
|
|
65
|
-
if (options.sendRouterState !== false)
|
|
75
|
+
if (options.sendRouterState !== false)
|
|
76
|
+
appendAkanRouterStateRequestHeaders(headers, sentRouterStateOf(options.currentRouterState));
|
|
66
77
|
const response =
|
|
67
78
|
options.prefetched ??
|
|
68
79
|
(await fetchKeepingHeaders(
|
|
@@ -88,7 +99,8 @@ export async function fetchRscNavigationResponse(
|
|
|
88
99
|
}
|
|
89
100
|
if (response.headers.get("X-Akan-Rsc-Partial") === "patch") {
|
|
90
101
|
const patch = readAkanRscPatchMetadataResponseHeaders(response.headers);
|
|
91
|
-
if (options.sendRouterState === false)
|
|
102
|
+
if (options.sendRouterState === false)
|
|
103
|
+
throw new AkanError("invalidRscResponse", "[rscClient] RSC full fallback returned a patch response");
|
|
92
104
|
if (!patch) {
|
|
93
105
|
await response.body?.cancel();
|
|
94
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
|
+
}
|