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,44 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
const errKey = /^[A-Za-z][\w$-]{0,63}\.error\.[\w$.-]{1,120}$/;
|
|
4
|
+
const token = /^[a-z][A-Za-z0-9]{0,63}$/;
|
|
5
|
+
|
|
6
|
+
export const isFailureCode = (value: unknown): value is string =>
|
|
7
|
+
typeof value === "string" && (errKey.test(value) || token.test(value));
|
|
8
|
+
|
|
9
|
+
const statusCodes: { readonly [status: number]: string } = {
|
|
10
|
+
400: "badRequest",
|
|
11
|
+
401: "unauthorized",
|
|
12
|
+
403: "forbidden",
|
|
13
|
+
404: "notFound",
|
|
14
|
+
409: "conflict",
|
|
15
|
+
413: "payloadTooLarge",
|
|
16
|
+
415: "unsupportedMediaType",
|
|
17
|
+
429: "tooManyRequests",
|
|
18
|
+
500: "internalError",
|
|
19
|
+
502: "badGateway",
|
|
20
|
+
503: "serviceUnavailable",
|
|
21
|
+
504: "gatewayTimeout",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const codeOfStatus = (status: number): string => statusCodes[status] ?? `http${status}`;
|
|
25
|
+
|
|
26
|
+
const isKey = (value: unknown): value is string => typeof value === "string" && errKey.test(value);
|
|
27
|
+
|
|
28
|
+
export const codeOfAnswer = (status: number, body: unknown): string => {
|
|
29
|
+
const fields = (typeof body === "object" && body !== null ? body : {}) as {
|
|
30
|
+
code?: unknown;
|
|
31
|
+
error?: unknown;
|
|
32
|
+
message?: unknown;
|
|
33
|
+
};
|
|
34
|
+
const kept = typeof fields.code === "string" && token.test(fields.code) ? fields.code : undefined;
|
|
35
|
+
if (status === 401 || status === 403) return kept ?? codeOfStatus(status);
|
|
36
|
+
return [fields.error, fields.message, fields.code].find(isKey) ?? kept ?? codeOfStatus(status);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const failureCodeOf = (value: unknown): string | undefined => {
|
|
40
|
+
if (typeof value !== "object" || value === null) return undefined;
|
|
41
|
+
const { code, error } = value as { code?: unknown; error?: unknown };
|
|
42
|
+
if (typeof error === "string" && errKey.test(error)) return error;
|
|
43
|
+
return typeof code === "string" && token.test(code) ? code : undefined;
|
|
44
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { codeOfAnswer, codeOfStatus, isFailureCode } from "./failureCode";
|
|
1
2
|
import type { AgentRunner, RunnerEvent, ToolCallRequest, TurnLimits, TurnUsage } from "./types";
|
|
2
3
|
|
|
3
4
|
export interface HttpRunnerOptions {
|
|
@@ -25,7 +26,10 @@ const parseFrame = (frame: string): RunnerEvent | null => {
|
|
|
25
26
|
.join("\n");
|
|
26
27
|
if (!data) return null;
|
|
27
28
|
const event = JSON.parse(data) as RunnerEvent;
|
|
28
|
-
|
|
29
|
+
if (!eventTypes.has((event as { type?: string }).type ?? "")) return null;
|
|
30
|
+
if (event.type !== "error" || event.code === undefined || isFailureCode(event.code)) return event;
|
|
31
|
+
const { code: _unbounded, ...bounded } = event;
|
|
32
|
+
return bounded;
|
|
29
33
|
};
|
|
30
34
|
|
|
31
35
|
/**
|
|
@@ -88,14 +92,21 @@ const overflowOf = (value: unknown): { limit?: number } | undefined => {
|
|
|
88
92
|
* The status stands in only when the body says nothing.
|
|
89
93
|
*/
|
|
90
94
|
const turnError = async (response: Response): Promise<RunnerEvent> => {
|
|
91
|
-
const
|
|
95
|
+
const byStatus = codeOfStatus(response.status);
|
|
96
|
+
const fallback = { type: "error", message: `Agent turn failed: ${response.status}`, code: byStatus } as const;
|
|
92
97
|
try {
|
|
93
98
|
const body = (await response.json()) as { message?: unknown; error?: unknown; data?: unknown; overflow?: unknown };
|
|
94
99
|
const message = typeof body.message === "string" ? body.message : typeof body.error === "string" ? body.error : "";
|
|
95
|
-
if (!message) return fallback;
|
|
100
|
+
if (!message) return { ...fallback, code: codeOfAnswer(response.status, body) };
|
|
96
101
|
const data = interpolations(body.data);
|
|
97
102
|
const overflow = overflowOf(body.overflow);
|
|
98
|
-
return {
|
|
103
|
+
return {
|
|
104
|
+
type: "error",
|
|
105
|
+
message,
|
|
106
|
+
code: codeOfAnswer(response.status, body),
|
|
107
|
+
...(data ? { data } : {}),
|
|
108
|
+
...(overflow ? { overflow } : {}),
|
|
109
|
+
};
|
|
99
110
|
} catch {
|
|
100
111
|
return fallback;
|
|
101
112
|
}
|
|
@@ -169,6 +169,11 @@ export interface ToolCallResult {
|
|
|
169
169
|
/** What the call changed on the surface — the whole report for a tool that returns nothing. */
|
|
170
170
|
changes?: ResourceDiff[];
|
|
171
171
|
error?: string;
|
|
172
|
+
/**
|
|
173
|
+
* The failure's code, when what the tool threw named one, so the model can branch on it rather than on `error`.
|
|
174
|
+
* Never on a `taint: "source"` tool's result, whose text is fenced as page content.
|
|
175
|
+
*/
|
|
176
|
+
code?: string;
|
|
172
177
|
/**
|
|
173
178
|
* Files the call handed the model — a picture it looked at — in the shape a user's attachment takes. A `result`
|
|
174
179
|
* cannot carry one: it reaches the model as JSON text, so a URL is read as letters and base64 as a wall of them.
|
|
@@ -270,6 +275,8 @@ export interface ChatMessage {
|
|
|
270
275
|
toolResults?: ToolCallResult[];
|
|
271
276
|
/** A failed or capped turn, recorded in the transcript rather than thrown past it. */
|
|
272
277
|
error?: string;
|
|
278
|
+
/** The code the runner named that failure by, for a host to branch on where `error` is text. Never sent. */
|
|
279
|
+
errorCode?: string;
|
|
273
280
|
/**
|
|
274
281
|
* Host-rendered and never sent: a command's own output belongs in the transcript the user reads but not in the
|
|
275
282
|
* history the model reads, which would take it for something it had said itself.
|
|
@@ -305,10 +312,14 @@ export type RunnerEvent =
|
|
|
305
312
|
*
|
|
306
313
|
* `overflow` marks the provider refusing a prompt too long for its window — the one refusal a session can undo
|
|
307
314
|
* on its own, by compacting and asking again. `limit` is the window when the refusal named it.
|
|
315
|
+
*
|
|
316
|
+
* `code` names the failure for a host to branch on, since `message` may reach it already translated: a
|
|
317
|
+
* dictionary key (`<module>.error.<key>`) or a camelCase token, never prose.
|
|
308
318
|
*/
|
|
309
319
|
| {
|
|
310
320
|
type: "error";
|
|
311
321
|
message: string;
|
|
322
|
+
code?: string;
|
|
312
323
|
data?: Record<string, string | number>;
|
|
313
324
|
overflow?: { limit?: number };
|
|
314
325
|
};
|
package/webkit/CsrGuards.ts
CHANGED
|
@@ -5,6 +5,8 @@ interface GuardedLocation {
|
|
|
5
5
|
pathRoute: PathRoute;
|
|
6
6
|
params: Record<string, string>;
|
|
7
7
|
searchParams: Record<string, string | string[]>;
|
|
8
|
+
pathname?: string;
|
|
9
|
+
search?: string;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
/**
|
|
@@ -88,12 +90,15 @@ export class CsrGuards {
|
|
|
88
90
|
CsrGuards.#released.delete(key);
|
|
89
91
|
}
|
|
90
92
|
|
|
91
|
-
static async #run({ pathRoute, params, searchParams }: GuardedLocation): Promise<boolean> {
|
|
93
|
+
static async #run({ pathRoute, params, searchParams, pathname, search }: GuardedLocation): Promise<boolean> {
|
|
92
94
|
const navigations = router.navigationCount();
|
|
95
|
+
|
|
96
|
+
const path =
|
|
97
|
+
pathname === undefined ? undefined : `${router.routeOf(pathname, params.lang)}${search ? `?${search}` : ""}`;
|
|
93
98
|
for (const render of CsrGuards.#rendersOf(pathRoute)) {
|
|
94
99
|
if (!render?.guard) continue;
|
|
95
100
|
try {
|
|
96
|
-
await render.guard({ params, searchParams });
|
|
101
|
+
await render.guard({ params, searchParams, path });
|
|
97
102
|
} catch (error) {
|
|
98
103
|
if (router.navigationCount() !== navigations) return false;
|
|
99
104
|
const refusal = RouteGuards.refusalOf(error);
|
package/webkit/McpAppAgent.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { ImageResult } from "akanjs/base";
|
|
3
3
|
import { csrLocation } from "akanjs/client";
|
|
4
|
-
import { Logger } from "akanjs/common";
|
|
4
|
+
import { Logger, MCP_FAILURE_META } from "akanjs/common";
|
|
5
5
|
import { AgentConfirm, StoreRegistry } from "akanjs/store";
|
|
6
6
|
import { AgentContext, AgentVisual, ensureStoreSurface, ScreenSettle } from "akanjs/store/agent";
|
|
7
7
|
import {
|
|
@@ -150,8 +150,13 @@ export class McpAppAgent {
|
|
|
150
150
|
return JSON.stringify(tools);
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
static #resultOf({ result, changes, error, attachments = [] }: ToolCallResult): McpToolResult {
|
|
154
|
-
if (error !== undefined)
|
|
153
|
+
static #resultOf({ result, changes, error, code, attachments = [] }: ToolCallResult): McpToolResult {
|
|
154
|
+
if (error !== undefined)
|
|
155
|
+
return {
|
|
156
|
+
content: [{ type: "text", text: error }],
|
|
157
|
+
isError: true,
|
|
158
|
+
...(code === undefined ? {} : { _meta: { [MCP_FAILURE_META]: { code } } }),
|
|
159
|
+
};
|
|
155
160
|
const text = changes?.length
|
|
156
161
|
? JSON.stringify({ ...(result !== undefined ? { result } : {}), changes })
|
|
157
162
|
: result === undefined
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { AbortSignals } from "akanjs/common";
|
|
2
|
+
import { AbortSignals, MCP_FAILURE_META, type McpFailure } from "akanjs/common";
|
|
3
3
|
import {
|
|
4
4
|
type ErrorResponsePayload,
|
|
5
5
|
type FetchBridge,
|
|
@@ -64,10 +64,16 @@ export class McpAppFetchBridge implements FetchBridge {
|
|
|
64
64
|
|
|
65
65
|
static #valueOf({ key, returns }: FetchBridgeCall, result: Partial<McpToolResult>) {
|
|
66
66
|
const text = result.content?.find((block) => block.type === "text")?.text ?? "";
|
|
67
|
-
const
|
|
68
|
-
if (result.isError &&
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
const restorable = result._meta?.[MCP_APP_META.error] as Partial<ErrorResponsePayload> | undefined;
|
|
68
|
+
if (result.isError && restorable?.error) throw restoreRemoteError(restorable, restorable.statusCode ?? 400);
|
|
69
|
+
const failure = result._meta?.[MCP_FAILURE_META] as Partial<McpFailure> | undefined;
|
|
70
|
+
const statusCode = restorable?.statusCode ?? failure?.statusCode;
|
|
71
|
+
const error = text || `${key} failed`;
|
|
72
|
+
|
|
73
|
+
const code = restorable ? undefined : failure?.code;
|
|
74
|
+
if (result.isError && statusCode)
|
|
75
|
+
throw restoreRemoteError({ error, statusCode, ...(code ? { code } : {}) }, statusCode);
|
|
76
|
+
if (result.isError) throw new Error(error);
|
|
71
77
|
if (result._meta && MCP_APP_META.value in result._meta) return result._meta[MCP_APP_META.value];
|
|
72
78
|
const structured = result.structuredContent as Record<string, unknown> | undefined;
|
|
73
79
|
if (structured !== undefined) return returns.arrDepth ? structured.items : structured;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { isRouteControl, router } from "akanjs/client";
|
|
3
|
+
import { Component, type ReactNode } from "react";
|
|
4
|
+
import { RenderFailure } from "./RenderFailure";
|
|
5
|
+
|
|
6
|
+
interface RouteLevelBoundaryProps {
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
interface RouteLevelBoundaryState {
|
|
10
|
+
children?: ReactNode;
|
|
11
|
+
failure: { error: unknown } | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class RouteLevelBoundary extends Component<RouteLevelBoundaryProps, RouteLevelBoundaryState> {
|
|
15
|
+
override state: RouteLevelBoundaryState = { children: this.props.children, failure: null };
|
|
16
|
+
|
|
17
|
+
static getDerivedStateFromError(error: unknown): Partial<RouteLevelBoundaryState> {
|
|
18
|
+
return { failure: { error } };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static getDerivedStateFromProps(
|
|
22
|
+
props: RouteLevelBoundaryProps,
|
|
23
|
+
state: RouteLevelBoundaryState,
|
|
24
|
+
): Partial<RouteLevelBoundaryState> | null {
|
|
25
|
+
return props.children === state.children ? null : { children: props.children, failure: null };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
override render() {
|
|
29
|
+
const { failure } = this.state;
|
|
30
|
+
if (!failure) return this.props.children;
|
|
31
|
+
if (typeof (failure.error as { digest?: unknown } | null)?.digest !== "string") throw failure.error;
|
|
32
|
+
if (isRouteControl(failure.error)) return null;
|
|
33
|
+
return <RenderFailure error={failure.error} onRetry={retry} />;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const retry = () => router.refresh();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AkanNativeError, fileBlob, releaseFile } from "../vendor/@akanjs/native/packages/core/src/index.ts";
|
package/webkit/nativePurchase.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import type { IapTransaction } from "akanjs/client/native";
|
|
3
|
+
|
|
4
|
+
export const loadIap = () => import("akanjs/client/native/iap");
|
|
5
|
+
const appInfo = async () => await (await import("akanjs/client/native/app")).app.getInfo();
|
|
3
6
|
|
|
4
7
|
export type PurchaseProductType = "consumable" | "nonConsumable" | "subscription";
|
|
5
8
|
|
|
@@ -48,7 +51,7 @@ export class NativePurchase {
|
|
|
48
51
|
if (verification.jws)
|
|
49
52
|
return {
|
|
50
53
|
platform: "apple",
|
|
51
|
-
packageName: (await
|
|
54
|
+
packageName: (await appInfo()).id,
|
|
52
55
|
productId,
|
|
53
56
|
receipt: verification.jws,
|
|
54
57
|
transactionId: id,
|
|
@@ -56,7 +59,7 @@ export class NativePurchase {
|
|
|
56
59
|
if (verification.purchaseToken)
|
|
57
60
|
return {
|
|
58
61
|
platform: "google",
|
|
59
|
-
packageName: verification.packageName ?? (await
|
|
62
|
+
packageName: verification.packageName ?? (await appInfo()).id,
|
|
60
63
|
productId,
|
|
61
64
|
receipt: verification.purchaseToken,
|
|
62
65
|
transactionId: verification.orderId ?? id,
|
package/webkit/useCamera.tsx
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Binary } from "akanjs/base";
|
|
3
|
-
import { Translator } from "akanjs/client";
|
|
4
|
-
import {
|
|
5
|
-
AkanNativeError,
|
|
6
|
-
dialog,
|
|
7
|
-
fileBlob,
|
|
8
|
-
isNativeApp,
|
|
9
|
-
loadCamera,
|
|
10
|
-
opener,
|
|
11
|
-
type Photo,
|
|
12
|
-
releaseFile,
|
|
13
|
-
} from "akanjs/client/native";
|
|
3
|
+
import { isNativeApp, Translator } from "akanjs/client";
|
|
4
|
+
import type { Photo } from "akanjs/client/native";
|
|
14
5
|
import { parseAkanI18nEnv } from "akanjs/common";
|
|
15
6
|
import { useEffect, useState } from "react";
|
|
16
7
|
|
|
@@ -27,7 +18,16 @@ export interface CameraPromptLabels {
|
|
|
27
18
|
const promptLabel = (key: string, override?: string) =>
|
|
28
19
|
override ?? Translator.translateByLocale(Translator.getActiveLocale() ?? parseAkanI18nEnv().defaultLocale, key);
|
|
29
20
|
|
|
30
|
-
const
|
|
21
|
+
const loadCamera = () => import("akanjs/client/native/camera");
|
|
22
|
+
const loadCore = () => import("./nativeCore");
|
|
23
|
+
const openSettings = async () => await (await import("akanjs/client/native/opener")).opener.openSettings();
|
|
24
|
+
type NativeCore = Awaited<ReturnType<typeof loadCore>>;
|
|
25
|
+
const loadForPhotos = async () => {
|
|
26
|
+
const [{ camera }, core] = await Promise.all([loadCamera(), loadCore()]);
|
|
27
|
+
return { camera, core };
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const toDataUrl = async ({ fileBlob, releaseFile }: NativeCore, photo: Photo) => {
|
|
31
31
|
try {
|
|
32
32
|
const bytes = new Uint8Array(await (await fileBlob(photo)).arrayBuffer());
|
|
33
33
|
return { dataUrl: `data:${photo.mime};base64,${Binary.toBase64(bytes)}` };
|
|
@@ -40,12 +40,12 @@ const toDataUrl = async (photo: Photo) => {
|
|
|
40
40
|
export const useCamera = ({ promptLabels = {} }: { promptLabels?: CameraPromptLabels } = {}) => {
|
|
41
41
|
const [permissions, setPermissions] = useState<{ camera: PermissionState }>({ camera: "prompt" });
|
|
42
42
|
|
|
43
|
-
const openSettingsWhenDenied = async (error: unknown) => {
|
|
43
|
+
const openSettingsWhenDenied = async ({ AkanNativeError }: NativeCore, error: unknown) => {
|
|
44
44
|
const code = AkanNativeError.from(error).code;
|
|
45
45
|
if (code === "CANCELLED") return;
|
|
46
46
|
if (code !== "PERMISSION_DENIED") throw error;
|
|
47
47
|
setPermissions({ camera: "denied" });
|
|
48
|
-
await
|
|
48
|
+
await openSettings();
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
const checkPermission = async () => {
|
|
@@ -53,11 +53,12 @@ export const useCamera = ({ promptLabels = {} }: { promptLabels?: CameraPromptLa
|
|
|
53
53
|
const { camera } = await loadCamera();
|
|
54
54
|
const { camera: state } = await camera.requestPermission();
|
|
55
55
|
setPermissions({ camera: state });
|
|
56
|
-
if (state === "denied") await
|
|
56
|
+
if (state === "denied") await openSettings();
|
|
57
57
|
return state;
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
const chooseSource = async (): Promise<"camera" | "library" | null> => {
|
|
61
|
+
const { dialog } = await import("akanjs/client/native/dialog");
|
|
61
62
|
const { index } = await dialog.actionSheet({
|
|
62
63
|
title: promptLabel("base.cameraPromptHeader", promptLabels.header),
|
|
63
64
|
options: [
|
|
@@ -72,21 +73,21 @@ export const useCamera = ({ promptLabels = {} }: { promptLabels?: CameraPromptLa
|
|
|
72
73
|
const getPhoto = async (src: "prompt" | "camera" | "photos" = "prompt") => {
|
|
73
74
|
const source = !isNativeApp() || src === "photos" ? "library" : src === "camera" ? "camera" : await chooseSource();
|
|
74
75
|
if (!source) return;
|
|
75
|
-
const { camera } = await
|
|
76
|
+
const { camera, core } = await loadForPhotos();
|
|
76
77
|
try {
|
|
77
|
-
return await toDataUrl(await camera.takePhoto({ source }));
|
|
78
|
+
return await toDataUrl(core, await camera.takePhoto({ source }));
|
|
78
79
|
} catch (error) {
|
|
79
|
-
await openSettingsWhenDenied(error);
|
|
80
|
+
await openSettingsWhenDenied(core, error);
|
|
80
81
|
}
|
|
81
82
|
};
|
|
82
83
|
|
|
83
84
|
const pickImage = async ({ limit }: { limit?: number } = {}) => {
|
|
84
|
-
const { camera } = await
|
|
85
|
+
const { camera, core } = await loadForPhotos();
|
|
85
86
|
try {
|
|
86
87
|
const { photos } = await camera.pickImages(limit ? { limit } : {});
|
|
87
|
-
return await Promise.all(photos.map(toDataUrl));
|
|
88
|
+
return await Promise.all(photos.map((photo) => toDataUrl(core, photo)));
|
|
88
89
|
} catch (error) {
|
|
89
|
-
await openSettingsWhenDenied(error);
|
|
90
|
+
await openSettingsWhenDenied(core, error);
|
|
90
91
|
}
|
|
91
92
|
};
|
|
92
93
|
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { debugFrame } from "akanjs/client";
|
|
3
|
+
import { useEffect, useLayoutEffect, useMemo, useRef } from "react";
|
|
4
|
+
import type { CsrLocationState } from "./useCsrLocationState";
|
|
5
|
+
import type { CsrRefs } from "./useCsrRefs";
|
|
6
|
+
import {
|
|
7
|
+
getFramePlatformProfile,
|
|
8
|
+
hasBottomAnchoredKeyboardSlot,
|
|
9
|
+
hasKeyboardStickySlot,
|
|
10
|
+
resolveKeyboardAccessoryHeight,
|
|
11
|
+
resolveKeyboardLayout,
|
|
12
|
+
useFrameRuntimeResync,
|
|
13
|
+
type useFrameSlots,
|
|
14
|
+
type useFrameViewport,
|
|
15
|
+
useKeyboardFrame,
|
|
16
|
+
} from "./useFrameRuntime";
|
|
17
|
+
import type { ResolvedFrame } from "./useResolvedFrame";
|
|
18
|
+
|
|
19
|
+
export const useCsrKeyboard = ({
|
|
20
|
+
viewport,
|
|
21
|
+
updateViewport,
|
|
22
|
+
frameSlots,
|
|
23
|
+
phase,
|
|
24
|
+
resolvedLocation,
|
|
25
|
+
pageContentRef,
|
|
26
|
+
}: {
|
|
27
|
+
viewport: ReturnType<typeof useFrameViewport>["viewport"];
|
|
28
|
+
updateViewport: ReturnType<typeof useFrameViewport>["updateViewport"];
|
|
29
|
+
frameSlots: ReturnType<typeof useFrameSlots>["frameSlots"];
|
|
30
|
+
phase: CsrLocationState["phase"];
|
|
31
|
+
resolvedLocation: ResolvedFrame["resolvedLocation"];
|
|
32
|
+
pageContentRef: CsrRefs["pageContentRef"];
|
|
33
|
+
}) => {
|
|
34
|
+
const platformProfile = getFramePlatformProfile();
|
|
35
|
+
const accessoryHeight = resolveKeyboardAccessoryHeight(resolvedLocation.pathRoute.path, frameSlots);
|
|
36
|
+
const shouldAnchorContentBottom = hasBottomAnchoredKeyboardSlot(resolvedLocation.pathRoute.path, frameSlots);
|
|
37
|
+
const keyboardFrame = useKeyboardFrame({
|
|
38
|
+
bottomSafeArea: resolvedLocation.pathRoute.pageState.bottomSafeArea,
|
|
39
|
+
sticky: hasKeyboardStickySlot(resolvedLocation.pathRoute.path, frameSlots),
|
|
40
|
+
viewport,
|
|
41
|
+
platformProfile,
|
|
42
|
+
freeze: phase === "transitioning",
|
|
43
|
+
});
|
|
44
|
+
const keyboardLayout = useMemo(
|
|
45
|
+
() =>
|
|
46
|
+
resolveKeyboardLayout({
|
|
47
|
+
viewport,
|
|
48
|
+
keyboard: keyboardFrame,
|
|
49
|
+
accessoryHeight,
|
|
50
|
+
bottomSafeArea: resolvedLocation.pathRoute.pageState.bottomSafeArea,
|
|
51
|
+
}),
|
|
52
|
+
[viewport, keyboardFrame, accessoryHeight, resolvedLocation.pathRoute.pageState.bottomSafeArea],
|
|
53
|
+
);
|
|
54
|
+
const contentBottomAnchorRef = useRef<{
|
|
55
|
+
path: string;
|
|
56
|
+
contentViewportHeight: number;
|
|
57
|
+
bottomDistance: number;
|
|
58
|
+
} | null>(null);
|
|
59
|
+
const contentBottomAnchorRafRef = useRef<number | null>(null);
|
|
60
|
+
useLayoutEffect(() => {
|
|
61
|
+
const element = pageContentRef.current;
|
|
62
|
+
const path = resolvedLocation.pathRoute.path;
|
|
63
|
+
if (!element || !shouldAnchorContentBottom || !keyboardFrame.sticky) {
|
|
64
|
+
contentBottomAnchorRef.current = null;
|
|
65
|
+
if (contentBottomAnchorRafRef.current !== null) {
|
|
66
|
+
cancelAnimationFrame(contentBottomAnchorRafRef.current);
|
|
67
|
+
contentBottomAnchorRafRef.current = null;
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const previous = contentBottomAnchorRef.current;
|
|
73
|
+
const currentBottomDistance = Math.max(0, element.scrollHeight - element.scrollTop - element.clientHeight);
|
|
74
|
+
if (!previous || previous.path !== path) {
|
|
75
|
+
contentBottomAnchorRef.current = {
|
|
76
|
+
path,
|
|
77
|
+
contentViewportHeight: keyboardLayout.contentViewport.height,
|
|
78
|
+
bottomDistance: currentBottomDistance,
|
|
79
|
+
};
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const shouldRestoreBottom = previous.contentViewportHeight !== keyboardLayout.contentViewport.height;
|
|
84
|
+
const bottomDistance = previous.bottomDistance;
|
|
85
|
+
if (shouldRestoreBottom) {
|
|
86
|
+
const nextScrollTop = Math.max(0, element.scrollHeight - element.clientHeight - bottomDistance);
|
|
87
|
+
if (Math.abs(element.scrollTop - nextScrollTop) > 1) {
|
|
88
|
+
debugFrame("keyboard.contentAnchor", {
|
|
89
|
+
path,
|
|
90
|
+
from: element.scrollTop,
|
|
91
|
+
to: nextScrollTop,
|
|
92
|
+
bottomDistance,
|
|
93
|
+
contentViewportHeight: keyboardLayout.contentViewport.height,
|
|
94
|
+
});
|
|
95
|
+
element.scrollTop = nextScrollTop;
|
|
96
|
+
}
|
|
97
|
+
const startedAt = performance.now();
|
|
98
|
+
const duration = (keyboardFrame.animationDuration ?? 0) + 50;
|
|
99
|
+
const keepBottomAnchored = () => {
|
|
100
|
+
const scrollTop = Math.max(0, element.scrollHeight - element.clientHeight - bottomDistance);
|
|
101
|
+
if (Math.abs(element.scrollTop - scrollTop) > 1) element.scrollTop = scrollTop;
|
|
102
|
+
if (performance.now() - startedAt < duration) {
|
|
103
|
+
contentBottomAnchorRafRef.current = requestAnimationFrame(keepBottomAnchored);
|
|
104
|
+
} else {
|
|
105
|
+
contentBottomAnchorRafRef.current = null;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
if (contentBottomAnchorRafRef.current !== null) cancelAnimationFrame(contentBottomAnchorRafRef.current);
|
|
109
|
+
contentBottomAnchorRafRef.current = requestAnimationFrame(keepBottomAnchored);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
contentBottomAnchorRef.current = {
|
|
113
|
+
path,
|
|
114
|
+
contentViewportHeight: keyboardLayout.contentViewport.height,
|
|
115
|
+
bottomDistance: Math.max(0, element.scrollHeight - element.scrollTop - element.clientHeight),
|
|
116
|
+
};
|
|
117
|
+
return () => {
|
|
118
|
+
if (contentBottomAnchorRafRef.current !== null) {
|
|
119
|
+
cancelAnimationFrame(contentBottomAnchorRafRef.current);
|
|
120
|
+
contentBottomAnchorRafRef.current = null;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}, [
|
|
124
|
+
pageContentRef,
|
|
125
|
+
resolvedLocation.pathRoute.path,
|
|
126
|
+
shouldAnchorContentBottom,
|
|
127
|
+
keyboardFrame.sticky,
|
|
128
|
+
keyboardFrame.animationDuration,
|
|
129
|
+
keyboardLayout.contentViewport.height,
|
|
130
|
+
]);
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
const element = pageContentRef.current;
|
|
133
|
+
const path = resolvedLocation.pathRoute.path;
|
|
134
|
+
if (!element || !shouldAnchorContentBottom || !keyboardFrame.sticky) return;
|
|
135
|
+
const updateBottomDistance = () => {
|
|
136
|
+
contentBottomAnchorRef.current = {
|
|
137
|
+
path,
|
|
138
|
+
contentViewportHeight: keyboardLayout.contentViewport.height,
|
|
139
|
+
bottomDistance: Math.max(0, element.scrollHeight - element.scrollTop - element.clientHeight),
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
element.addEventListener("scroll", updateBottomDistance, { passive: true });
|
|
143
|
+
return () => element.removeEventListener("scroll", updateBottomDistance);
|
|
144
|
+
}, [
|
|
145
|
+
pageContentRef,
|
|
146
|
+
resolvedLocation.pathRoute.path,
|
|
147
|
+
shouldAnchorContentBottom,
|
|
148
|
+
keyboardFrame.sticky,
|
|
149
|
+
keyboardLayout.contentViewport.height,
|
|
150
|
+
]);
|
|
151
|
+
useFrameRuntimeResync({ updateViewport });
|
|
152
|
+
return { platformProfile, accessoryHeight, shouldAnchorContentBottom, keyboardFrame, keyboardLayout };
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export type CsrKeyboard = ReturnType<typeof useCsrKeyboard>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { csrLocation, getAuthToken, type LocationState, type RouteGuide } from "akanjs/client";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { CsrStack } from "./CsrStack";
|
|
5
|
+
import { useHistory } from "./useHistory";
|
|
6
|
+
import { useLocation } from "./useLocation";
|
|
7
|
+
|
|
8
|
+
export const useCsrLocationState = (rootRouteGuide: RouteGuide) => {
|
|
9
|
+
const { getLocation } = useLocation({ rootRouteGuide });
|
|
10
|
+
const [initialStack] = useState(() => {
|
|
11
|
+
const current = getLocation(csrLocation.href);
|
|
12
|
+
return CsrStack.restore(current, getLocation) ?? { locations: [current], idx: 0 };
|
|
13
|
+
});
|
|
14
|
+
const {
|
|
15
|
+
history,
|
|
16
|
+
setHistoryForward,
|
|
17
|
+
setHistoryBack,
|
|
18
|
+
setHistoryJump,
|
|
19
|
+
getNextLocation,
|
|
20
|
+
getCurrentLocation,
|
|
21
|
+
getPrevLocation,
|
|
22
|
+
getScrollTop,
|
|
23
|
+
} = useHistory(initialStack.locations, initialStack);
|
|
24
|
+
history.current.account ??= { token: getAuthToken() ?? null, generation: 0 };
|
|
25
|
+
const [isBackgrounded, setIsBackgrounded] = useState(() => document.visibilityState === "hidden");
|
|
26
|
+
const [locationState, setLocationState] = useState<LocationState>({
|
|
27
|
+
location: getCurrentLocation(),
|
|
28
|
+
prevLocation: getPrevLocation(),
|
|
29
|
+
pendingLocation: null,
|
|
30
|
+
navigationIntent: null,
|
|
31
|
+
phase: "idle",
|
|
32
|
+
});
|
|
33
|
+
const { location, prevLocation } = locationState;
|
|
34
|
+
const pendingLocation = locationState.pendingLocation ?? null;
|
|
35
|
+
const navigationIntent = locationState.navigationIntent ?? null;
|
|
36
|
+
const phase = locationState.phase ?? "idle";
|
|
37
|
+
return {
|
|
38
|
+
getLocation,
|
|
39
|
+
history,
|
|
40
|
+
setHistoryForward,
|
|
41
|
+
setHistoryBack,
|
|
42
|
+
setHistoryJump,
|
|
43
|
+
getNextLocation,
|
|
44
|
+
getCurrentLocation,
|
|
45
|
+
getPrevLocation,
|
|
46
|
+
getScrollTop,
|
|
47
|
+
isBackgrounded,
|
|
48
|
+
setIsBackgrounded,
|
|
49
|
+
setLocationState,
|
|
50
|
+
location,
|
|
51
|
+
prevLocation,
|
|
52
|
+
pendingLocation,
|
|
53
|
+
navigationIntent,
|
|
54
|
+
phase,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type CsrLocationState = ReturnType<typeof useCsrLocationState>;
|