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,155 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { Logger, type LogRecord } from "akanjs/common";
|
|
5
|
+
import type { AkanMetricsReport } from "akanjs/service";
|
|
6
|
+
import { RestartSchedule } from "../common/restartSchedule";
|
|
7
|
+
import { ChildOutputReader } from "./logging/childOutputReader";
|
|
8
|
+
|
|
9
|
+
export type RscWorkerStatus = "starting" | "ready" | "restarting" | "stopped";
|
|
10
|
+
export type RscProcess = Bun.Subprocess;
|
|
11
|
+
export type RscWorkerErrorCode = "rscWorkerFailed" | "rscWorkerStopped";
|
|
12
|
+
|
|
13
|
+
interface RscWorkerProcessEvents {
|
|
14
|
+
onMessage: (message: unknown, proc: RscProcess) => void;
|
|
15
|
+
onExit: (proc: RscProcess, code: number | null) => void;
|
|
16
|
+
logRecords: () => ((records: LogRecord[], dropped: number) => void) | null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class RscWorkerProcess {
|
|
20
|
+
readonly ready: Promise<void>;
|
|
21
|
+
proc: RscProcess;
|
|
22
|
+
status: RscWorkerStatus = "starting";
|
|
23
|
+
killed = false;
|
|
24
|
+
booting: RscProcess | null = null;
|
|
25
|
+
reloadsSinceSpawn = 0;
|
|
26
|
+
lastWorkerMetrics: AkanMetricsReport = {};
|
|
27
|
+
readonly restart = new RestartSchedule({ min: 200, max: 30_000 });
|
|
28
|
+
#restartCount = 0;
|
|
29
|
+
#resolveReady!: () => void;
|
|
30
|
+
#rejectReady!: (err: Error) => void;
|
|
31
|
+
#readyResolved = false;
|
|
32
|
+
readonly #logger: Logger;
|
|
33
|
+
readonly #events: RscWorkerProcessEvents;
|
|
34
|
+
|
|
35
|
+
constructor(logger: Logger, events: RscWorkerProcessEvents) {
|
|
36
|
+
this.#logger = logger;
|
|
37
|
+
this.#events = events;
|
|
38
|
+
this.ready = new Promise<void>((resolve, reject) => {
|
|
39
|
+
this.#resolveReady = () => {
|
|
40
|
+
if (this.#readyResolved) return;
|
|
41
|
+
this.#readyResolved = true;
|
|
42
|
+
resolve();
|
|
43
|
+
};
|
|
44
|
+
this.#rejectReady = (err) => {
|
|
45
|
+
if (this.#readyResolved) return;
|
|
46
|
+
this.#readyResolved = true;
|
|
47
|
+
reject(err);
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
this.proc = this.spawn();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get readyResolved() {
|
|
55
|
+
return this.#readyResolved;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get restartCount() {
|
|
59
|
+
return this.#restartCount;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
resolveReady() {
|
|
63
|
+
this.#resolveReady();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
rejectReady(err: Error) {
|
|
67
|
+
this.#rejectReady(err);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
spawn(): RscProcess {
|
|
71
|
+
this.status = "starting";
|
|
72
|
+
this.reloadsSinceSpawn = 0;
|
|
73
|
+
const workerPath = this.#resolveWorkerPath();
|
|
74
|
+
let proc!: RscProcess;
|
|
75
|
+
const earlyMessages: unknown[] = [];
|
|
76
|
+
|
|
77
|
+
const piped = Logger.isNdjson;
|
|
78
|
+
proc = Bun.spawn(["bun", "--conditions", "react-server", workerPath], {
|
|
79
|
+
ipc: (message: unknown) => {
|
|
80
|
+
if (!proc) {
|
|
81
|
+
earlyMessages.push(message);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
this.#events.onMessage(message, proc);
|
|
85
|
+
},
|
|
86
|
+
stdio: ["ignore", piped ? "pipe" : "inherit", piped ? "pipe" : "inherit"],
|
|
87
|
+
serialization: "advanced",
|
|
88
|
+
env: { ...process.env },
|
|
89
|
+
});
|
|
90
|
+
if (piped) this.#readOutput(proc);
|
|
91
|
+
if (earlyMessages.length > 0) {
|
|
92
|
+
setTimeout(() => {
|
|
93
|
+
for (const message of earlyMessages.splice(0)) this.#events.onMessage(message, proc);
|
|
94
|
+
}, 0);
|
|
95
|
+
}
|
|
96
|
+
proc.exited.then((code) => this.#events.onExit(proc, code));
|
|
97
|
+
return proc;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
#readOutput(proc: RscProcess) {
|
|
101
|
+
const replicaIdx = Number(process.env.AKAN_REPLICA_IDX);
|
|
102
|
+
const record = (type: "stdout" | "stderr", text: string) =>
|
|
103
|
+
this.#events.logRecords()?.(
|
|
104
|
+
[
|
|
105
|
+
ChildOutputReader.toRecord({
|
|
106
|
+
type,
|
|
107
|
+
text,
|
|
108
|
+
name: "rsc-worker",
|
|
109
|
+
role: "rsc-worker",
|
|
110
|
+
replicaIdx: Number.isInteger(replicaIdx) ? replicaIdx : null,
|
|
111
|
+
pid: proc.pid,
|
|
112
|
+
}),
|
|
113
|
+
],
|
|
114
|
+
0,
|
|
115
|
+
);
|
|
116
|
+
const reader = new ChildOutputReader({
|
|
117
|
+
onLine: (line) => record("stdout", line),
|
|
118
|
+
onBlock: (lines) => record("stderr", lines.join("")),
|
|
119
|
+
});
|
|
120
|
+
void reader.pipe(proc.stdout instanceof ReadableStream ? proc.stdout : null, "stdout");
|
|
121
|
+
void reader.pipe(proc.stderr instanceof ReadableStream ? proc.stderr : null, "stderr");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
#resolveWorkerPath(): string {
|
|
125
|
+
if (process.env.AKAN_RSC_WORKER_PATH) return path.resolve(process.env.AKAN_RSC_WORKER_PATH);
|
|
126
|
+
|
|
127
|
+
const distWorkerPath = path.join(process.cwd(), "rscWorker.js");
|
|
128
|
+
if (fs.existsSync(distWorkerPath)) return distWorkerPath;
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
return Bun.resolveSync("akanjs/server/rsc-worker", import.meta.dir);
|
|
132
|
+
} catch {
|
|
133
|
+
return fileURLToPath(new URL("./rscWorker.tsx", import.meta.url));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
scheduleRestart(): void {
|
|
138
|
+
this.status = "restarting";
|
|
139
|
+
const delay = this.restart.schedule(() => {
|
|
140
|
+
if (this.killed) return;
|
|
141
|
+
try {
|
|
142
|
+
this.proc = this.spawn();
|
|
143
|
+
} catch (err) {
|
|
144
|
+
this.#logger.error(`[rsc] failed to spawn worker: ${err instanceof Error ? err.message : String(err)}`);
|
|
145
|
+
this.scheduleRestart();
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
this.#restartCount += 1;
|
|
149
|
+
this.#logger.verbose(`[rsc] worker crashed, restarting in ${delay}ms (attempt ${this.restart.attempts})`);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
static isAlive(proc: RscProcess): boolean {
|
|
153
|
+
return proc.exitCode === null && proc.signalCode === null && !proc.killed;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { Logger } from "akanjs/common";
|
|
2
|
+
import type { AkanMetricsReport } from "akanjs/service";
|
|
3
|
+
import { MemoryLimit } from "./memoryLimit";
|
|
4
|
+
import type { RscHostRequests } from "./rscHostRequests";
|
|
5
|
+
import type { RscProcess, RscWorkerProcess } from "./rscWorkerProcess";
|
|
6
|
+
|
|
7
|
+
interface RscRollingRecycle {
|
|
8
|
+
oldProc: RscProcess;
|
|
9
|
+
reason: string;
|
|
10
|
+
reloadsSinceSpawn: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class RscWorkerRecycler {
|
|
14
|
+
static readonly #devMaxReloads = 10;
|
|
15
|
+
static readonly #devMaxRssBytes = 768 * 1024 * 1024;
|
|
16
|
+
rollingRecycle: RscRollingRecycle | null = null;
|
|
17
|
+
#recycleCount = 0;
|
|
18
|
+
#lastRecycleAtMono: number | null = null;
|
|
19
|
+
#lastRecycleReason: string | undefined;
|
|
20
|
+
#recycleTimer: ReturnType<typeof setTimeout> | null = null;
|
|
21
|
+
readonly #worker: RscWorkerProcess;
|
|
22
|
+
readonly #requests: RscHostRequests;
|
|
23
|
+
readonly #logger: Logger;
|
|
24
|
+
|
|
25
|
+
constructor(worker: RscWorkerProcess, requests: RscHostRequests, logger: Logger) {
|
|
26
|
+
this.#worker = worker;
|
|
27
|
+
this.#requests = requests;
|
|
28
|
+
this.#logger = logger;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get recycleCount() {
|
|
32
|
+
return this.#recycleCount;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get lastRecycleReason() {
|
|
36
|
+
return this.#lastRecycleReason;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
restartWhenIdle(reason: string): boolean {
|
|
40
|
+
if (
|
|
41
|
+
this.#worker.killed ||
|
|
42
|
+
this.#worker.status === "stopped" ||
|
|
43
|
+
this.#worker.status === "starting" ||
|
|
44
|
+
this.#worker.status === "restarting"
|
|
45
|
+
) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (this.#requests.pending.size > 0 || this.#requests.calls.size > 0 || this.#requests.queuedSends.length > 0) {
|
|
49
|
+
if (!this.#recycleTimer) {
|
|
50
|
+
const graceMs = MemoryLimit.parsePositiveIntEnv("AKAN_RSC_WORKER_RECYCLE_GRACE_MS") ?? 5_000;
|
|
51
|
+
this.#recycleTimer = setTimeout(() => {
|
|
52
|
+
this.#recycleTimer = null;
|
|
53
|
+
this.restartWhenIdle(reason);
|
|
54
|
+
}, graceMs);
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
this.#lastRecycleReason = reason;
|
|
59
|
+
this.#recycleCount += 1;
|
|
60
|
+
this.#lastRecycleAtMono = performance.now();
|
|
61
|
+
this.#logger.info(`[rsc] rolling recycle worker reason=${reason} oldPid=${this.#worker.proc.pid}`);
|
|
62
|
+
this.#worker.status = "restarting";
|
|
63
|
+
this.rollingRecycle = { oldProc: this.#worker.proc, reason, reloadsSinceSpawn: this.#worker.reloadsSinceSpawn };
|
|
64
|
+
this.#worker.proc = this.#worker.spawn();
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
stop(): void {
|
|
69
|
+
if (this.#recycleTimer) clearTimeout(this.#recycleTimer);
|
|
70
|
+
this.#recycleTimer = null;
|
|
71
|
+
this.rollingRecycle?.oldProc.kill();
|
|
72
|
+
this.rollingRecycle = null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
finishRollingRecycle(): void {
|
|
76
|
+
const recycle = this.rollingRecycle;
|
|
77
|
+
if (!recycle) return;
|
|
78
|
+
this.rollingRecycle = null;
|
|
79
|
+
this.#logger.info(
|
|
80
|
+
`[rsc] rolling recycle ready reason=${recycle.reason} oldPid=${recycle.oldProc.pid} newPid=${this.#worker.proc.pid}`,
|
|
81
|
+
);
|
|
82
|
+
recycle.oldProc.kill();
|
|
83
|
+
this.#worker.lastWorkerMetrics = {};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
shouldRecycleForReloadAccumulation(): boolean {
|
|
87
|
+
const maxReloads = RscWorkerRecycler.#getRscMaxReloads();
|
|
88
|
+
if (!maxReloads || this.#worker.reloadsSinceSpawn < maxReloads) return false;
|
|
89
|
+
|
|
90
|
+
if (this.#lastRecycleAtMono === null) return true;
|
|
91
|
+
const minIntervalMs = MemoryLimit.parsePositiveIntEnv("AKAN_RSC_WORKER_MIN_RECYCLE_INTERVAL_MS") ?? 1_000;
|
|
92
|
+
return performance.now() - this.#lastRecycleAtMono >= minIntervalMs;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
maybeRecycleFromMetrics(metrics: AkanMetricsReport): void {
|
|
96
|
+
if (this.#requests.pending.size > 0 || this.#requests.calls.size > 0) return;
|
|
97
|
+
const maxRssBytes = RscWorkerRecycler.#getRscMaxRssBytes();
|
|
98
|
+
if (maxRssBytes && metrics.rssBytes && metrics.rssBytes >= maxRssBytes) {
|
|
99
|
+
this.restartWhenIdle(`rss>${Math.round(maxRssBytes / 1024 / 1024)}MiB`);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const maxRenderCount = MemoryLimit.parsePositiveIntEnv("AKAN_RSC_WORKER_MAX_RENDER_COUNT");
|
|
103
|
+
if (maxRenderCount && (metrics.rscRenderCount ?? 0) >= maxRenderCount) {
|
|
104
|
+
this.restartWhenIdle(`renderCount>${maxRenderCount}`);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const maxRouteModules = MemoryLimit.parsePositiveIntEnv("AKAN_RSC_WORKER_MAX_ROUTE_MODULES");
|
|
108
|
+
if (maxRouteModules && (metrics.rscLoadedRouteModuleCount ?? 0) >= maxRouteModules) {
|
|
109
|
+
this.restartWhenIdle(`routeModules>${maxRouteModules}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static #getRscMaxReloads(): number | null {
|
|
114
|
+
if (process.env.AKAN_RSC_WORKER_MAX_RELOADS !== undefined)
|
|
115
|
+
return MemoryLimit.parsePositiveIntEnv("AKAN_RSC_WORKER_MAX_RELOADS");
|
|
116
|
+
return process.env.NODE_ENV === "production" ? null : RscWorkerRecycler.#devMaxReloads;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
static #getRscMaxRssBytes(): number | null {
|
|
120
|
+
return MemoryLimit.resolveMaxRssBytes({
|
|
121
|
+
megabytesEnv: "AKAN_RSC_WORKER_MAX_RSS_MB",
|
|
122
|
+
bytesEnv: "AKAN_RSC_WORKER_MAX_RSS",
|
|
123
|
+
limitFraction: 0.55,
|
|
124
|
+
|
|
125
|
+
fallbackBytes: process.env.NODE_ENV === "production" ? null : RscWorkerRecycler.#devMaxRssBytes,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { AkanWebConfig, AkanWebOption } from "akanjs";
|
|
2
|
+
import { AkanError, type BackendEnv, normalizeRoutePrefix } from "akanjs/base";
|
|
3
|
+
import { parseBasePaths } from "akanjs/common";
|
|
4
|
+
import type { AkanLib } from "./akanLib";
|
|
5
|
+
import type { AkanServerOptions, McpServerOption } from "./akanServer";
|
|
6
|
+
import { type McpAuthOption, McpRateLimiter } from "./mcp";
|
|
7
|
+
|
|
8
|
+
export class ServerConfig {
|
|
9
|
+
static requireRoutePrefix(value: string, field: string) {
|
|
10
|
+
const normalized = normalizeRoutePrefix(value);
|
|
11
|
+
if (!normalized)
|
|
12
|
+
throw new AkanError("invalidConfig", `${field} must be a path segment such as "/api"; "${value}" is not one.`);
|
|
13
|
+
return normalized;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static assertPrefixClearsBasePaths(prefix: string) {
|
|
17
|
+
const basePaths = parseBasePaths(process.env.AKAN_PUBLIC_BASE_PATHS);
|
|
18
|
+
const first = prefix.split("/")[1];
|
|
19
|
+
const collision = basePaths.find((basePath) => basePath === first);
|
|
20
|
+
if (!collision) return;
|
|
21
|
+
throw new AkanError(
|
|
22
|
+
"invalidConfig",
|
|
23
|
+
`Route prefix "${prefix}" collides with the "${collision}" basePath; give the API its own.`,
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static splitLibsAndOptions(libsOrOptions: (AkanLib | AkanServerOptions)[]) {
|
|
28
|
+
const last = libsOrOptions.at(-1);
|
|
29
|
+
const options = ServerConfig.isServerOptions(last) ? last : undefined;
|
|
30
|
+
const libs = (options ? libsOrOptions.slice(0, -1) : libsOrOptions) as AkanLib[];
|
|
31
|
+
return { libs, options };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static isServerOptions(value: AkanLib | AkanServerOptions | undefined): value is AkanServerOptions {
|
|
35
|
+
return Boolean(
|
|
36
|
+
value &&
|
|
37
|
+
!("database" in value) &&
|
|
38
|
+
!("service" in value) &&
|
|
39
|
+
!("scalar" in value) &&
|
|
40
|
+
("openapi" in value ||
|
|
41
|
+
"mcp" in value ||
|
|
42
|
+
"modules" in value ||
|
|
43
|
+
"disableModules" in value ||
|
|
44
|
+
"disableLibs" in value),
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static isEdge(env: BackendEnv) {
|
|
49
|
+
return ((env as { operationMode?: string }).operationMode ?? process.env.AKAN_PUBLIC_OPERATION_MODE) === "edge";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static isEnvEnabled(...names: string[]) {
|
|
53
|
+
return names.some((name) => process.env[name] === "true" || process.env[name] === "1");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static narrowWeb(current: AkanWebConfig, web: AkanWebOption | undefined): AkanWebConfig {
|
|
57
|
+
if (web === undefined || web === true) return current;
|
|
58
|
+
if (web === false) return { ssr: false, csr: false };
|
|
59
|
+
return { ssr: current.ssr, csr: web.csr && current.csr };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static isEnvOff(...names: string[]) {
|
|
63
|
+
return names.some((name) => process.env[name] === "false" || process.env[name] === "0");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static mcpAuthFromEnv(): McpAuthOption {
|
|
67
|
+
const authorizationServers = ServerConfig.envList("AKAN_MCP_AUTH_SERVERS");
|
|
68
|
+
const scopes = ServerConfig.envList("AKAN_MCP_SCOPES");
|
|
69
|
+
return {
|
|
70
|
+
...(authorizationServers?.length ? { authorizationServers } : {}),
|
|
71
|
+
...(scopes?.length ? { scopes } : {}),
|
|
72
|
+
...(process.env.AKAN_MCP_RESOURCE ? { resource: process.env.AKAN_MCP_RESOURCE } : {}),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static defined<T extends object>(source: T): Partial<T> {
|
|
77
|
+
return Object.fromEntries(Object.entries(source).filter(([, value]) => value !== undefined)) as Partial<T>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static mcpOptionFromEnv(): Omit<McpServerOption, "enabled" | "readOnly" | "auth"> {
|
|
81
|
+
const allowedOrigins = ServerConfig.envList("AKAN_MCP_ALLOWED_ORIGINS");
|
|
82
|
+
const pageSize = Number(process.env.AKAN_MCP_PAGE_SIZE);
|
|
83
|
+
const promptBudget = Number(process.env.AKAN_MCP_PROMPT_BUDGET);
|
|
84
|
+
return {
|
|
85
|
+
...ServerConfig.mcpPathFromEnv(),
|
|
86
|
+
...(process.env.AKAN_MCP_VERSION ? { version: process.env.AKAN_MCP_VERSION } : {}),
|
|
87
|
+
...(process.env.AKAN_MCP_INSTRUCTIONS ? { instructions: process.env.AKAN_MCP_INSTRUCTIONS } : {}),
|
|
88
|
+
...(allowedOrigins?.length ? { allowedOrigins } : {}),
|
|
89
|
+
...(Number.isInteger(pageSize) && pageSize > 0 ? { pageSize } : {}),
|
|
90
|
+
...(Number.isInteger(promptBudget) && promptBudget > 0 ? { promptBudget } : {}),
|
|
91
|
+
...(process.env.AKAN_MCP_LANGUAGE ? { language: process.env.AKAN_MCP_LANGUAGE } : {}),
|
|
92
|
+
...(ServerConfig.isEnvOff("AKAN_MCP_LEGACY_TEXT") ? { legacyTextBlock: false } : {}),
|
|
93
|
+
...(ServerConfig.isEnvOff("AKAN_MCP_APPS") ? { apps: false } : {}),
|
|
94
|
+
...ServerConfig.mcpModernFromEnv(),
|
|
95
|
+
...ServerConfig.mcpOutputSchemaFromEnv(),
|
|
96
|
+
...McpRateLimiter.fromEnv(),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
static mcpModernFromEnv(): Pick<McpServerOption, "modern"> {
|
|
101
|
+
if (ServerConfig.isEnvEnabled("AKAN_MCP_MODERN")) return { modern: true };
|
|
102
|
+
return ServerConfig.isEnvOff("AKAN_MCP_MODERN") ? { modern: false } : {};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static mcpOutputSchemaFromEnv(): Pick<McpServerOption, "outputSchema"> {
|
|
106
|
+
const value = process.env.AKAN_MCP_OUTPUT_SCHEMA;
|
|
107
|
+
return value === "full" || value === "shallow" || value === "none" ? { outputSchema: value } : {};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
static mcpPathFromEnv() {
|
|
111
|
+
const path = process.env.AKAN_MCP_PATH?.trim();
|
|
112
|
+
if (!path) return {};
|
|
113
|
+
return { path: path.startsWith("/") ? path : `/${path}` };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
static envList(name: string) {
|
|
117
|
+
return process.env[name]
|
|
118
|
+
?.split(",")
|
|
119
|
+
.map((entry) => entry.trim())
|
|
120
|
+
.filter(Boolean);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
static defaultShutdownTimeoutMs() {
|
|
124
|
+
const configured = Number(process.env.AKAN_SHUTDOWN_TIMEOUT_MS);
|
|
125
|
+
if (Number.isFinite(configured) && configured > 0) return configured;
|
|
126
|
+
return process.env.AKAN_COMMAND_TYPE === "start" ? 3_000 : 30_000;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Logger } from "akanjs/common";
|
|
2
|
+
import type { AkanIpcMessage, AkanMetricsReport } from "akanjs/service";
|
|
3
|
+
import type { AkanServer } from "./akanServer";
|
|
4
|
+
import { ProcessMetricsCollector } from "./processMetricsCollector";
|
|
5
|
+
import type { ServerListener } from "./routing/serverListener";
|
|
6
|
+
import type { WebRouter } from "./webRouter";
|
|
7
|
+
|
|
8
|
+
export class ServerMetrics {
|
|
9
|
+
readonly #owner: Pick<AkanServer, "logger" | "serverMode">;
|
|
10
|
+
readonly #logger: Logger;
|
|
11
|
+
readonly #listener: ServerListener;
|
|
12
|
+
readonly #webRouter: () => WebRouter | null;
|
|
13
|
+
#metricsTimer: Timer | null = null;
|
|
14
|
+
#lastMetrics: AkanMetricsReport = {};
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
owner: Pick<AkanServer, "logger" | "serverMode">,
|
|
18
|
+
listener: ServerListener,
|
|
19
|
+
webRouter: () => WebRouter | null,
|
|
20
|
+
) {
|
|
21
|
+
this.#owner = owner;
|
|
22
|
+
this.#logger = owner.logger;
|
|
23
|
+
this.#listener = listener;
|
|
24
|
+
this.#webRouter = webRouter;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get last() {
|
|
28
|
+
return this.#lastMetrics;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
start() {
|
|
32
|
+
this.#metricsTimer ??= ProcessMetricsCollector.startReporting(() => this.#reportMetrics());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
stop() {
|
|
36
|
+
if (this.#metricsTimer) clearInterval(this.#metricsTimer);
|
|
37
|
+
this.#metricsTimer = null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async #reportMetrics() {
|
|
41
|
+
const metrics = await ProcessMetricsCollector.collect({
|
|
42
|
+
role: this.#owner.serverMode,
|
|
43
|
+
pubsubCoalesceCount: this.#listener.coalescedCount,
|
|
44
|
+
...(this.#webRouter()?.getMetrics() ?? {}),
|
|
45
|
+
});
|
|
46
|
+
this.#lastMetrics = metrics;
|
|
47
|
+
process.send?.({ type: "metrics.report", pid: process.pid, metrics } satisfies AkanIpcMessage);
|
|
48
|
+
if (process.env.AKAN_MEMORY_LOG === "1") {
|
|
49
|
+
this.#logger.info(`memory role=${this.#owner.serverMode} ${ProcessMetricsCollector.format(metrics)}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
package/server/sitemap.ts
CHANGED
|
@@ -30,6 +30,7 @@ export function createDefaultSitemapUrls({ origin, basePath, entries, i18n }: De
|
|
|
30
30
|
return paths.map((pathname) => `${normalizedOrigin}${pathname}`);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
/** @deprecated Ignores `basePaths`; use `getSitemapBasePath(pathname, basePaths, headerBasePath) !== undefined`. */
|
|
33
34
|
export function isSitemapPath(pathname: string, basePaths: readonly string[]): boolean {
|
|
34
35
|
return normalizePathname(pathname) === "/sitemap.xml";
|
|
35
36
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
3
|
import { Readable } from "node:stream";
|
|
4
|
-
import { getApiPrefix, getWsPrefix } from "akanjs/base";
|
|
4
|
+
import { AkanError, getApiPrefix, getWsPrefix } from "akanjs/base";
|
|
5
5
|
import { Logger } from "akanjs/common";
|
|
6
6
|
import { type AkanRequestStore, type AkanTheme, createRequestStore, RenderScope, requestStorage } from "akanjs/fetch";
|
|
7
7
|
import type { ReactNode } from "react";
|
|
@@ -20,7 +20,7 @@ import type {
|
|
|
20
20
|
} from "./ssrTypes";
|
|
21
21
|
|
|
22
22
|
const DEFAULT_SSR_CHUNK_REGISTRY_MAX_ENTRIES = 1024;
|
|
23
|
-
const
|
|
23
|
+
const DEFAULT_MAX_PENDING_INLINE_RSC_BYTES = 16 * 1024;
|
|
24
24
|
|
|
25
25
|
interface SsrChunkRegistryEntry<T> {
|
|
26
26
|
keys: Set<string>;
|
|
@@ -330,8 +330,8 @@ export function interleaveRscScriptsWithHtml(
|
|
|
330
330
|
options: {
|
|
331
331
|
bootstrapModuleScripts?: string;
|
|
332
332
|
lateControl?: Promise<SsrLateControl | null>;
|
|
333
|
-
|
|
334
|
-
|
|
333
|
+
maxPendingRscBytes?: number;
|
|
334
|
+
onPendingRscBytes?: (bytes: number) => void;
|
|
335
335
|
onComplete?: () => void;
|
|
336
336
|
onCancel?: (reason?: unknown) => void;
|
|
337
337
|
request?: Request;
|
|
@@ -340,13 +340,14 @@ export function interleaveRscScriptsWithHtml(
|
|
|
340
340
|
): ReadableStream<Uint8Array> {
|
|
341
341
|
const encoder = new TextEncoder();
|
|
342
342
|
const bootstrapDetector = new InlineBootstrapDetector();
|
|
343
|
-
const
|
|
343
|
+
const pendingRscChunks: Uint8Array[] = [];
|
|
344
344
|
const pendingControlScripts: Uint8Array[] = [];
|
|
345
|
-
const explicitMax = options.
|
|
346
|
-
const
|
|
345
|
+
const explicitMax = options.maxPendingRscBytes;
|
|
346
|
+
const maxPendingRscBytes =
|
|
347
347
|
explicitMax !== undefined && Number.isFinite(explicitMax) && explicitMax > 0
|
|
348
348
|
? Math.floor(explicitMax)
|
|
349
|
-
: (parsePositiveInt(process.env.
|
|
349
|
+
: (parsePositiveInt(process.env.AKAN_MAX_PENDING_INLINE_RSC_BYTES) ?? DEFAULT_MAX_PENDING_INLINE_RSC_BYTES);
|
|
350
|
+
const pendingRscBytes = () => pendingRscChunks.reduce((total, chunk) => total + chunk.byteLength, 0);
|
|
350
351
|
const queueDrainResolvers: Array<() => void> = [];
|
|
351
352
|
const scriptAvailableResolvers: Array<() => void> = [];
|
|
352
353
|
let errored = false;
|
|
@@ -381,11 +382,10 @@ export function interleaveRscScriptsWithHtml(
|
|
|
381
382
|
const script = pendingControlScripts.shift();
|
|
382
383
|
if (script) controller.enqueue(script);
|
|
383
384
|
}
|
|
384
|
-
while (!errored &&
|
|
385
|
-
const
|
|
386
|
-
if (
|
|
385
|
+
while (!errored && pendingRscChunks.length > 0) {
|
|
386
|
+
const chunk = pendingRscChunks.shift();
|
|
387
|
+
if (chunk) controller.enqueue(encoder.encode(createInlineRscScript(chunk)));
|
|
387
388
|
}
|
|
388
|
-
options.onPendingRscScriptsSize?.(pendingRscScripts.length);
|
|
389
389
|
while (queueDrainResolvers.length > 0) queueDrainResolvers.shift()?.();
|
|
390
390
|
};
|
|
391
391
|
|
|
@@ -394,9 +394,8 @@ export function interleaveRscScriptsWithHtml(
|
|
|
394
394
|
};
|
|
395
395
|
|
|
396
396
|
const waitForRscQueueDrain = async () => {
|
|
397
|
-
while (!errored &&
|
|
397
|
+
while (!errored && pendingRscBytes() >= maxPendingRscBytes)
|
|
398
398
|
await new Promise<void>((resolve) => queueDrainResolvers.push(resolve));
|
|
399
|
-
}
|
|
400
399
|
};
|
|
401
400
|
|
|
402
401
|
const waitForScriptAvailable = () => new Promise<void>((resolve) => scriptAvailableResolvers.push(resolve));
|
|
@@ -405,12 +404,13 @@ export function interleaveRscScriptsWithHtml(
|
|
|
405
404
|
rscReader = rscClientStream.getReader();
|
|
406
405
|
try {
|
|
407
406
|
for (;;) {
|
|
408
|
-
const { value, done } = await rscReader.read();
|
|
409
|
-
if (done || errored) break;
|
|
410
407
|
await waitForRscQueueDrain();
|
|
411
408
|
if (errored) break;
|
|
412
|
-
|
|
413
|
-
|
|
409
|
+
const { value, done } = await rscReader.read();
|
|
410
|
+
if (done || errored) break;
|
|
411
|
+
|
|
412
|
+
pendingRscChunks.push(value);
|
|
413
|
+
options.onPendingRscBytes?.(pendingRscBytes());
|
|
414
414
|
notifyScriptAvailable();
|
|
415
415
|
}
|
|
416
416
|
} finally {
|
|
@@ -455,7 +455,7 @@ export function interleaveRscScriptsWithHtml(
|
|
|
455
455
|
bootstrapDetector.forceAllow();
|
|
456
456
|
while (
|
|
457
457
|
!errored &&
|
|
458
|
-
(!rscDone || !lateControlDone || pendingControlScripts.length > 0 ||
|
|
458
|
+
(!rscDone || !lateControlDone || pendingControlScripts.length > 0 || pendingRscChunks.length > 0)
|
|
459
459
|
) {
|
|
460
460
|
flushPendingRscScripts();
|
|
461
461
|
if (!rscDone || !lateControlDone) await waitForScriptAvailable();
|
|
@@ -666,7 +666,7 @@ export class SsrFromRscRenderer {
|
|
|
666
666
|
};
|
|
667
667
|
g.__webpack_require__ = (id: string) => {
|
|
668
668
|
const mod = registry.get(id);
|
|
669
|
-
if (!mod) throw new
|
|
669
|
+
if (!mod) throw new AkanError("notInitialized", `[ssrFromRsc] module not loaded yet: ${id}`);
|
|
670
670
|
return mod;
|
|
671
671
|
};
|
|
672
672
|
}
|
package/server/ssrTypes.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AkanRequestStore, AkanTheme } from "akanjs/fetch";
|
|
2
|
+
import type { ClientManifest } from "./artifact";
|
|
2
3
|
import type { ModulePreloadPlan } from "./artifact/modulePreloadPlan";
|
|
3
4
|
|
|
4
5
|
export interface SsrManifestEntry {
|
|
@@ -49,6 +50,14 @@ export interface RscTraceMetadata {
|
|
|
49
50
|
ssrBlocking?: boolean;
|
|
50
51
|
}
|
|
51
52
|
|
|
53
|
+
export interface RscRenderOptions {
|
|
54
|
+
clientManifest?: ClientManifest;
|
|
55
|
+
signal?: AbortSignal;
|
|
56
|
+
clientIp?: string | null;
|
|
57
|
+
/** A Link prefetch through `/__rsc`, never taken from a header a document request could carry. */
|
|
58
|
+
prefetch?: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
52
61
|
export interface SsrFromRscInput {
|
|
53
62
|
request?: Request;
|
|
54
63
|
requestStore?: AkanRequestStore;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { DEFAULT_AKAN_I18N } from "akanjs/common";
|
|
4
|
+
import { type Dictionary, TranslatorState } from "../client/translatorState";
|
|
5
|
+
import type { SsrManifest } from "./ssrTypes";
|
|
6
|
+
import type { BaseBuildArtifact } from "./types";
|
|
7
|
+
|
|
8
|
+
export class WebArtifact {
|
|
9
|
+
static normalize(artifact: BaseBuildArtifact, artifactDir: string): BaseBuildArtifact {
|
|
10
|
+
const normalizedArtifactDir = path.resolve(artifactDir);
|
|
11
|
+
const pagesBundlePath = WebArtifact.#resolveArtifactPath(artifact.pagesBundlePath, normalizedArtifactDir);
|
|
12
|
+
return {
|
|
13
|
+
...artifact,
|
|
14
|
+
cssAssets: artifact.cssAssets ?? {},
|
|
15
|
+
dictAssets: artifact.dictAssets ?? {},
|
|
16
|
+
pagesBundlePath,
|
|
17
|
+
rscRuntimeSsrManifest: artifact.rscRuntimeSsrManifest
|
|
18
|
+
? WebArtifact.#normalizeSsrManifest(artifact.rscRuntimeSsrManifest, normalizedArtifactDir)
|
|
19
|
+
: undefined,
|
|
20
|
+
i18n: artifact.i18n ?? DEFAULT_AKAN_I18N,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static async loadCssBytesByUrl(
|
|
25
|
+
artifact: BaseBuildArtifact,
|
|
26
|
+
artifactDir: string,
|
|
27
|
+
): Promise<Record<string, Uint8Array>> {
|
|
28
|
+
const normalizedArtifactDir = path.resolve(artifactDir);
|
|
29
|
+
return Object.fromEntries(
|
|
30
|
+
await Promise.all(
|
|
31
|
+
Object.values(artifact.cssAssets ?? {}).map(async (asset) => [
|
|
32
|
+
asset.cssUrl,
|
|
33
|
+
await Bun.file(path.join(normalizedArtifactDir, asset.cssRelPath)).bytes(),
|
|
34
|
+
]),
|
|
35
|
+
),
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static async seedDictionaries(artifact: BaseBuildArtifact, artifactDir: string): Promise<void> {
|
|
40
|
+
const normalizedArtifactDir = path.resolve(artifactDir);
|
|
41
|
+
await Promise.all(
|
|
42
|
+
Object.values(artifact.dictAssets ?? {}).map(async (asset) => {
|
|
43
|
+
const { lang, default: dictionary } = (await import(path.join(normalizedArtifactDir, asset.relPath))) as {
|
|
44
|
+
lang: string;
|
|
45
|
+
default: Dictionary;
|
|
46
|
+
};
|
|
47
|
+
TranslatorState.replace(lang, dictionary);
|
|
48
|
+
}),
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static #normalizeSsrManifest(ssrManifest: SsrManifest, artifactDir: string): SsrManifest {
|
|
53
|
+
return {
|
|
54
|
+
...ssrManifest,
|
|
55
|
+
moduleMap: Object.fromEntries(
|
|
56
|
+
Object.entries(ssrManifest.moduleMap).map(([entryUrl, byName]) => [
|
|
57
|
+
entryUrl,
|
|
58
|
+
Object.fromEntries(
|
|
59
|
+
Object.entries(byName).map(([name, entry]) => [
|
|
60
|
+
name,
|
|
61
|
+
{
|
|
62
|
+
...entry,
|
|
63
|
+
id: WebArtifact.#resolveArtifactPath(entry.id, artifactDir),
|
|
64
|
+
chunks: entry.chunks.map((chunk) => WebArtifact.#resolveArtifactPath(chunk, artifactDir)),
|
|
65
|
+
},
|
|
66
|
+
]),
|
|
67
|
+
),
|
|
68
|
+
]),
|
|
69
|
+
),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static #resolveArtifactPath(artifactPath: string, artifactDir: string): string {
|
|
74
|
+
if (!path.isAbsolute(artifactPath)) return path.resolve(artifactDir, artifactPath);
|
|
75
|
+
if (fs.existsSync(artifactPath)) return artifactPath;
|
|
76
|
+
|
|
77
|
+
const marker = `${path.sep}.akan${path.sep}artifact${path.sep}`;
|
|
78
|
+
const markerIndex = artifactPath.lastIndexOf(marker);
|
|
79
|
+
if (markerIndex >= 0) {
|
|
80
|
+
const rel = artifactPath.slice(markerIndex + marker.length);
|
|
81
|
+
return path.resolve(artifactDir, rel);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return path.resolve(artifactDir, "server", path.basename(artifactPath));
|
|
85
|
+
}
|
|
86
|
+
}
|