akanjs 3.2.0-rc.8 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +41 -38
- package/CHANGELOG.md +0 -679
- package/CONTRIBUTING.md +3 -0
- package/base/base.ts +2 -1
- package/client/clientRuntime.ts +1 -0
- package/client/cn.ts +2 -2
- package/client/csrTypes.ts +2 -0
- package/client/frameConfig.ts +1 -0
- package/client/index.ts +249 -26
- package/client/locale.ts +1 -0
- package/client/makePageProto.tsx +12 -85
- package/client/nativeThemeColor.ts +51 -0
- package/client/route/PageDefinition.ts +11 -3
- package/client/route/RouteDefinition.ts +24 -7
- package/client/route/RouteGuards.ts +2 -1
- package/client/route/RouteHead.ts +4 -1
- package/client/route/routeArgs.ts +8 -0
- package/client/router.ts +17 -2
- package/client/rscNavigation.ts +1 -0
- package/client/viewportMeta.ts +86 -6
- package/common/CodeTranscript.ts +1 -1
- package/common/Logger.ts +4 -2
- package/common/PipelinePlanSchema.ts +2 -2
- package/common/clientAddress.ts +14 -0
- package/common/err.ts +122 -0
- package/common/eventStream.ts +71 -19
- package/common/facetBarrel.ts +38 -0
- package/common/index.ts +7 -0
- package/common/isGuardRefusal.ts +14 -0
- package/common/loggedFailure.ts +11 -0
- package/common/mcpExposure.ts +17 -4
- package/common/pipelinePlan.ts +1 -1
- package/common/routeConvention.ts +3 -1
- package/common/types.ts +18 -1
- package/constant/constantRegistry.ts +4 -8
- package/constant/crystalize.ts +1 -2
- package/constant/getDefault.ts +1 -1
- package/constant/immerify.ts +1 -1
- package/constant/index.ts +78 -21
- package/constant/purify.ts +4 -9
- package/constant/serialize.ts +4 -2
- package/constant/types.ts +1 -0
- package/constant/via.ts +1 -2
- package/dictionary/agent.dictionary.ts +12 -0
- package/dictionary/base.dictionary.ts +11 -0
- package/dictionary/locale.ts +1 -1
- package/dictionary/trans.ts +14 -97
- package/document/dataLoader.ts +39 -19
- package/document/databaseRegistry.ts +2 -1
- package/document/documentSchema.ts +1 -0
- package/document/filterMeta.ts +4 -1
- package/document/into.ts +2 -1
- package/document/loaderInfo.ts +2 -1
- package/document/noDocumentError.ts +4 -1
- package/document/queryEvaluator.ts +1 -1
- package/document/types.ts +1 -1
- package/fetch/client/fetchClient.ts +83 -269
- package/fetch/client/fetchClientTypes.ts +49 -0
- package/fetch/client/httpClient.ts +3 -2
- package/fetch/client/remoteError.ts +4 -20
- package/fetch/client/requestScope.ts +41 -0
- package/fetch/client/signalCatalog.ts +131 -0
- package/fetch/client/wsClient.ts +82 -6
- package/fetch/requestStorage.ts +1 -0
- package/package.json +1 -1
- package/server/agentHooks.ts +16 -0
- package/server/akanApp.ts +110 -1272
- package/server/akanOption.ts +30 -3
- package/server/akanServer.ts +179 -674
- package/server/artifact/builderRpc.ts +14 -6
- package/server/artifact/routeSeedIndexStore.ts +4 -2
- package/server/assetHeaders.ts +6 -0
- package/server/console.ts +6 -4
- package/server/decorators.ts +2 -2
- package/server/di/diLifecycle.ts +24 -35
- package/server/di/predefinedAdaptor.ts +24 -1
- package/server/di/resolveHierarchy.ts +19 -6
- package/server/di/stageFailedError.ts +10 -0
- package/server/di/utils.ts +8 -3
- package/server/ed25519Key.ts +31 -15
- package/server/flightRowReader.ts +106 -20
- package/server/gateway/childSupervisor.ts +328 -0
- package/server/gateway/devHostChannel.ts +47 -0
- package/server/gateway/gatewayChildren.ts +161 -0
- package/server/gateway/gatewayConfig.ts +182 -0
- package/server/gateway/gatewayHttpProxy.ts +231 -0
- package/server/gateway/gatewayLogging.ts +111 -0
- package/server/gateway/gatewayRooms.ts +141 -0
- package/server/gateway/gatewayStatus.ts +122 -0
- package/server/gateway/gatewayStatusPage.ts +54 -0
- package/server/gateway/gatewayWebSocketRelay.ts +149 -0
- package/server/gateway/listeningPort.ts +13 -0
- package/server/hmr/devHmrController.ts +10 -1
- package/server/htmlResultCache.ts +234 -0
- package/server/imageOptimizer.ts +4 -1
- package/server/index.ts +281 -17
- package/server/lifecycle/parentChannel.ts +79 -0
- package/server/lifecycle/shutdownManager.ts +6 -3
- package/server/lifecycle/startGuard.ts +90 -0
- package/server/logging/hubFileSink.ts +1 -0
- package/server/logging/logControlSocket.ts +42 -3
- package/server/logging/logHub.ts +0 -0
- package/server/logging/logStdoutWriter.ts +3 -1
- package/server/logging/logStreamRoute.ts +28 -11
- package/server/logging/serverLogging.ts +74 -0
- package/server/machine/machineToken.ts +10 -3
- package/server/mcp/AgentTools.ts +149 -0
- package/server/mcp/AgentToolsAccount.ts +26 -0
- package/server/mcp/McpApps.ts +32 -2
- package/server/mcp/McpDispatcher.ts +44 -30
- package/server/mcp/McpPages.ts +34 -12
- package/server/mcp/McpRateLimiter.ts +14 -0
- package/server/mcp/McpRouter.ts +4 -2
- package/server/mcp/McpUiSession.ts +2 -1
- package/server/mcp/index.ts +1 -0
- package/server/migration/migrationCommand.ts +31 -2
- package/server/migration/migrationRunner.ts +36 -1
- package/server/nativeFile.ts +39 -12
- package/server/nativeSecret.ts +12 -3
- package/server/oauth/OAuthClientIdMetadata.ts +2 -2
- package/server/ops/migrateJobs.ts +2 -2
- package/server/ops/opsCommand.ts +1 -1
- package/server/ops/opsRoute.ts +5 -1
- package/server/ops/opsToken.ts +3 -1
- package/server/remote/RemoteFetch.ts +161 -0
- package/server/remote/RemoteMcp.ts +242 -0
- package/server/remote/RemoteOAuth.ts +270 -0
- package/server/remote/RemoteSource.ts +214 -0
- package/server/remote/index.ts +17 -0
- package/server/remote/remoteError.ts +19 -0
- package/server/resolver/CascadeRunner.ts +20 -8
- package/server/resolver/database.resolver.ts +10 -417
- package/server/resolver/databaseModelInstance.ts +209 -0
- package/server/resolver/invalidSignal.ts +7 -0
- package/server/resolver/livePause.ts +34 -0
- package/server/resolver/modelFacade.ts +136 -0
- package/server/resolver/modelLoaders.ts +84 -0
- package/server/resolver/modelSchema.ts +52 -0
- package/server/resolver/roomAdmission.ts +68 -0
- package/server/resolver/signal.resolver.ts +45 -111
- package/server/resolver/sliceCrud.ts +63 -0
- package/server/resolver/timedQuery.ts +16 -0
- package/server/resolver/websocketOf.ts +2 -1
- package/server/routeElementComposer.tsx +45 -6
- package/server/routeTreeBuilder.ts +23 -9
- package/server/routing/apiRouter.ts +53 -28
- package/server/routing/builtinRoutes.ts +194 -0
- package/server/routing/localRooms.ts +34 -0
- package/server/routing/roomReplay.ts +2 -2
- package/server/routing/serverLimits.ts +4 -1
- package/server/routing/serverListener.ts +194 -0
- package/server/rscClient.tsx +122 -195
- package/server/rscClientCache.ts +165 -0
- package/server/rscClientChunks.ts +126 -8
- package/server/rscClientFetch.ts +9 -2
- package/server/rscClientPatch.ts +78 -15
- package/server/rscDocumentHead.tsx +177 -0
- package/server/rscFlightRenderer.ts +83 -0
- package/server/rscFlightStream.ts +259 -0
- package/server/rscHostReloads.ts +238 -0
- package/server/rscHostRenderStream.ts +297 -0
- package/server/rscHostRequests.ts +158 -0
- package/server/rscHttp.ts +18 -6
- package/server/rscNavigationState.ts +24 -1
- package/server/rscPagePrompts.ts +65 -14
- package/server/rscPrefetchCache.ts +31 -17
- package/server/rscRenderControl.ts +33 -0
- package/server/rscRenderFallbacks.ts +299 -0
- package/server/rscRenderHandler.ts +439 -0
- package/server/rscRenderStats.ts +49 -0
- package/server/rscResultCaches.ts +74 -0
- package/server/rscRouteDocument.tsx +316 -0
- package/server/rscSegmentOutletReference.ts +5 -1
- package/server/rscStaticApp.tsx +73 -0
- package/server/rscWorker.tsx +112 -1341
- package/server/rscWorkerHost.ts +175 -803
- package/server/rscWorkerProcess.ts +155 -0
- package/server/rscWorkerRecycler.ts +128 -0
- package/server/serverConfig.ts +128 -0
- package/server/serverMetrics.ts +52 -0
- package/server/sitemap.ts +1 -0
- package/server/ssrFromRscRenderer.tsx +20 -20
- package/server/ssrStaticApp.tsx +243 -0
- package/server/webArtifact.ts +86 -0
- package/server/webAssetRoutes.ts +84 -0
- package/server/webCsrSurface.ts +172 -0
- package/server/webDocumentRoute.ts +180 -0
- package/server/webRouteContext.ts +232 -0
- package/server/webRouter.ts +129 -1165
- package/server/webRscRoute.ts +155 -0
- package/server/webSiteFiles.ts +139 -0
- package/server/webStaticApp.ts +62 -0
- package/server/wellKnownRoutes.ts +73 -0
- package/service/agent.service.ts +14 -2
- package/service/agentAccounts.ts +19 -0
- package/service/agentLoop/agentLoop.ts +550 -0
- package/service/agentLoop/agentLoopTypes.ts +220 -0
- package/service/agentLoop/deltaStream.ts +40 -0
- package/service/agentLoop/loopAnswer.ts +67 -0
- package/service/agentLoop/loopAsk.ts +44 -0
- package/service/agentLoop/loopCompaction.ts +146 -0
- package/service/agentLoop/loopRemotes.ts +181 -0
- package/service/agentLoop/loopRequest.ts +120 -0
- package/service/agentLoop/loopStored.ts +24 -0
- package/service/agentLoop/loopToolOutput.ts +54 -0
- package/service/agentLoop/loopToolkits.ts +155 -0
- package/service/agentLoop/loopTranscript.ts +138 -0
- package/{signal → service}/agentMeter.ts +2 -1
- package/{signal → service}/agentRelayPolicy.ts +43 -8
- package/service/endpointCacheKeys.ts +14 -2
- package/service/index.ts +6 -0
- package/service/injectInfo.ts +2 -1
- package/service/ipcTypes.ts +8 -2
- package/service/liveRoomLimit.ts +68 -0
- package/service/liveRoomLimitError.ts +16 -0
- package/service/liveSyncHub.ts +24 -2
- package/service/predefinedAdaptor/agentTools.adaptor.ts +34 -0
- package/service/predefinedAdaptor/anthropicLlm.ts +33 -14
- package/service/predefinedAdaptor/compress.adaptor.ts +2 -2
- package/service/predefinedAdaptor/database.adaptor.ts +62 -19
- package/service/predefinedAdaptor/index.ts +1 -0
- package/service/predefinedAdaptor/llm.adaptor.ts +24 -1
- package/service/predefinedAdaptor/openaiDialect.ts +72 -23
- package/service/predefinedAdaptor/openaiLlm.ts +1 -1
- package/service/predefinedAdaptor/role.adaptor.ts +2 -0
- package/service/predefinedAdaptor/solidPubsub.adaptor.ts +35 -2
- package/service/predefinedAdaptor/solidQueue.adaptor.ts +2 -2
- package/service/predefinedAdaptor/solidSqlite.ts +6 -3
- package/service/predefinedAdaptor/sql/DocumentHydrator.ts +95 -0
- package/service/predefinedAdaptor/sql/DocumentRowCodec.ts +192 -0
- package/service/predefinedAdaptor/sql/DocumentWriter.ts +298 -0
- package/service/predefinedAdaptor/sql/QueryScope.ts +70 -0
- package/service/predefinedAdaptor/sql/QueryWriter.ts +200 -0
- package/service/predefinedAdaptor/sql/SqlDocumentStore.ts +127 -1069
- package/service/predefinedAdaptor/sql/SqlTableSchema.ts +357 -0
- package/service/predefinedAdaptor/sql/StoredRows.ts +95 -0
- package/service/predefinedAdaptor/sql/TransactionScope.ts +14 -7
- package/service/predefinedAdaptor/sql/dialect/postgres.ts +1 -1
- package/service/predefinedAdaptor/sql/dialect/sqlite.ts +1 -1
- package/service/predefinedAdaptor/sql/driver/bunSqlite.ts +20 -9
- package/service/predefinedAdaptor/sql/driver/postgres.ts +1 -1
- package/service/predefinedAdaptor/sql/types.ts +28 -4
- package/service/predefinedAdaptor/sseData.ts +88 -0
- package/service/predefinedAdaptor/storage.adaptor.ts +2 -1
- package/service/predefinedAdaptor/websocket.adaptor.ts +74 -44
- package/service/serviceRegistry.ts +1 -0
- package/signal/SignalFailure.ts +35 -0
- package/signal/agent.signal.ts +15 -9
- package/signal/agentTurnStream.ts +23 -9
- package/signal/byIdRead.ts +18 -0
- package/signal/carriedClientIps.ts +1 -0
- package/signal/endpointCache.ts +61 -6
- package/signal/endpointErrorContract.ts +1 -1
- package/signal/endpointRateLimit.ts +84 -3
- package/signal/index.ts +322 -32
- package/signal/mcp/McpDocument.ts +8 -1
- package/signal/mcp/mcpProtocol.ts +6 -1
- package/signal/mcp/pagePrompt.ts +15 -0
- package/signal/middleware.ts +10 -3
- package/signal/openapi/openapi.ts +10 -1
- package/signal/resolveFieldContext.ts +34 -0
- package/signal/serializer/fetch.serializer.ts +22 -15
- package/signal/signalContext.ts +15 -42
- package/signal/slice.ts +22 -19
- package/signal/trace.ts +44 -5
- package/signal/types.ts +46 -8
- package/store/action.ts +32 -1057
- package/store/actionErrorMessage.ts +20 -0
- package/store/actionOption.ts +22 -0
- package/store/baseSt.ts +1 -0
- package/store/formFieldSetters.ts +229 -0
- package/store/index.ts +125 -17
- package/store/modelActionContext.ts +65 -0
- package/store/modelOpenActions.ts +158 -0
- package/store/modelWriteActions.ts +240 -0
- package/store/modelWriteGuard.ts +3 -12
- package/store/openSeq.ts +34 -0
- package/store/sliceListActions.ts +370 -0
- package/store/sliceLiveActions.ts +140 -0
- package/store/stateBuilder.ts +2 -0
- package/store/storeInstance.ts +4 -18
- package/store/storeRegistry.ts +1 -1
- package/test/conformance.ts +25 -5
- package/types/base/base.d.ts +2 -1
- package/types/client/clientRuntime.d.ts +1 -0
- package/types/client/cn.d.ts +2 -2
- package/types/client/csrTypes.d.ts +2 -0
- package/types/client/frameConfig.d.ts +1 -0
- package/types/client/index.d.ts +25 -26
- package/types/client/locale.d.ts +1 -0
- package/types/client/makePageProto.d.ts +5 -13
- package/types/client/nativeThemeColor.d.ts +6 -0
- package/types/client/route/PageDefinition.d.ts +5 -2
- package/types/client/route/RouteDefinition.d.ts +2 -2
- package/types/client/route/routeArgs.d.ts +7 -0
- package/types/client/router.d.ts +3 -1
- package/types/client/rscNavigation.d.ts +1 -0
- package/types/client/viewportMeta.d.ts +5 -2
- package/types/common/CodeTranscript.d.ts +1 -1
- package/types/common/clientAddress.d.ts +5 -0
- package/types/common/err.d.ts +48 -0
- package/types/common/eventStream.d.ts +5 -1
- package/types/common/facetBarrel.d.ts +4 -0
- package/types/common/index.d.ts +6 -3
- package/types/common/isGuardRefusal.d.ts +3 -0
- package/types/common/loggedFailure.d.ts +2 -0
- package/types/common/mcpExposure.d.ts +9 -2
- package/types/common/routeConvention.d.ts +2 -0
- package/types/common/types.d.ts +18 -1
- package/types/constant/constantRegistry.d.ts +3 -1
- package/types/constant/crystalize.d.ts +1 -1
- package/types/constant/getDefault.d.ts +1 -1
- package/types/constant/immerify.d.ts +1 -1
- package/types/constant/index.d.ts +21 -21
- package/types/constant/purify.d.ts +2 -1
- package/types/constant/serialize.d.ts +1 -1
- package/types/constant/types.d.ts +1 -0
- package/types/dictionary/agent.dictionary.d.ts +1 -1
- package/types/dictionary/base.dictionary.d.ts +1 -1
- package/types/dictionary/dictionary.d.ts +9 -9
- package/types/dictionary/locale.d.ts +1 -1
- package/types/dictionary/trans.d.ts +3 -26
- package/types/document/dataLoader.d.ts +5 -0
- package/types/document/databaseRegistry.d.ts +2 -1
- package/types/document/documentSchema.d.ts +1 -0
- package/types/document/filterMeta.d.ts +4 -1
- package/types/document/into.d.ts +1 -1
- package/types/document/loaderInfo.d.ts +2 -1
- package/types/document/noDocumentError.d.ts +8 -1
- package/types/document/queryEvaluator.d.ts +1 -1
- package/types/document/types.d.ts +1 -1
- package/types/fetch/client/fetchClient.d.ts +6 -36
- package/types/fetch/client/fetchClientTypes.d.ts +40 -0
- package/types/fetch/client/httpClient.d.ts +2 -0
- package/types/fetch/client/remoteError.d.ts +0 -4
- package/types/fetch/client/requestScope.d.ts +11 -0
- package/types/fetch/client/signalCatalog.d.ts +25 -0
- package/types/fetch/client/wsClient.d.ts +2 -0
- package/types/fetch/requestStorage.d.ts +1 -0
- package/types/server/agentHooks.d.ts +4 -0
- package/types/server/akanApp.d.ts +2 -20
- package/types/server/akanOption.d.ts +16 -2
- package/types/server/akanServer.d.ts +2 -2
- package/types/server/assetHeaders.d.ts +1 -0
- package/types/server/console.d.ts +4 -3
- package/types/server/di/predefinedAdaptor.d.ts +1 -0
- package/types/server/di/stageFailedError.d.ts +5 -0
- package/types/server/ed25519Key.d.ts +1 -0
- package/types/server/flightRowReader.d.ts +8 -2
- package/types/server/gateway/childSupervisor.d.ts +35 -0
- package/types/server/gateway/devHostChannel.d.ts +14 -0
- package/types/server/gateway/gatewayChildren.d.ts +50 -0
- package/types/server/gateway/gatewayConfig.d.ts +82 -0
- package/types/server/gateway/gatewayHttpProxy.d.ts +22 -0
- package/types/server/gateway/gatewayLogging.d.ts +16 -0
- package/types/server/gateway/gatewayRooms.d.ts +25 -0
- package/types/server/gateway/gatewayStatus.d.ts +63 -0
- package/types/server/gateway/gatewayStatusPage.d.ts +9 -0
- package/types/server/gateway/gatewayWebSocketRelay.d.ts +17 -0
- package/types/server/gateway/listeningPort.d.ts +5 -0
- package/types/server/htmlResultCache.d.ts +51 -0
- package/types/server/index.d.ts +19 -17
- package/types/server/lifecycle/parentChannel.d.ts +13 -0
- package/types/server/lifecycle/startGuard.d.ts +10 -0
- package/types/server/logging/logHub.d.ts +5 -1
- package/types/server/logging/logStreamRoute.d.ts +2 -0
- package/types/server/logging/rotatingLogWriter.d.ts +1 -1
- package/types/server/logging/serverLogging.d.ts +12 -0
- package/types/server/mcp/AgentTools.d.ts +31 -0
- package/types/server/mcp/AgentToolsAccount.d.ts +7 -0
- package/types/server/mcp/McpApps.d.ts +6 -2
- package/types/server/mcp/McpDispatcher.d.ts +10 -1
- package/types/server/mcp/McpPages.d.ts +2 -1
- package/types/server/mcp/McpRateLimiter.d.ts +3 -0
- package/types/server/mcp/index.d.ts +1 -0
- package/types/server/migration/migrationCommand.d.ts +1 -1
- package/types/server/migration/migrationRunner.d.ts +9 -1
- package/types/server/remote/RemoteFetch.d.ts +42 -0
- package/types/server/remote/RemoteMcp.d.ts +52 -0
- package/types/server/remote/RemoteOAuth.d.ts +58 -0
- package/types/server/remote/RemoteSource.d.ts +51 -0
- package/types/server/remote/index.d.ts +5 -0
- package/types/server/remote/remoteError.d.ts +12 -0
- package/types/server/remote.d.ts +1 -0
- package/types/server/resolver/CascadeRunner.d.ts +2 -2
- package/types/server/resolver/database.resolver.d.ts +2 -2
- package/types/server/resolver/databaseModelInstance.d.ts +4 -0
- package/types/server/resolver/invalidSignal.d.ts +2 -0
- package/types/server/resolver/livePause.d.ts +5 -0
- package/types/server/resolver/modelFacade.d.ts +5 -0
- package/types/server/resolver/modelLoaders.d.ts +15 -0
- package/types/server/resolver/modelSchema.d.ts +6 -0
- package/types/server/resolver/roomAdmission.d.ts +7 -0
- package/types/server/resolver/signal.resolver.d.ts +1 -1
- package/types/server/resolver/sliceCrud.d.ts +8 -0
- package/types/server/resolver/timedQuery.d.ts +8 -0
- package/types/server/routeElementComposer.d.ts +21 -5
- package/types/server/routing/builtinRoutes.d.ts +24 -0
- package/types/server/routing/localRooms.d.ts +14 -0
- package/types/server/routing/roomReplay.d.ts +2 -2
- package/types/server/routing/serverListener.d.ts +31 -0
- package/types/server/rscClientCache.d.ts +34 -0
- package/types/server/rscClientChunks.d.ts +3 -1
- package/types/server/rscClientFetch.d.ts +1 -1
- package/types/server/rscClientPatch.d.ts +12 -1
- package/types/server/rscDocumentHead.d.ts +33 -0
- package/types/server/rscFlightRenderer.d.ts +14 -0
- package/types/server/rscFlightStream.d.ts +53 -0
- package/types/server/rscHostReloads.d.ts +54 -0
- package/types/server/rscHostRenderStream.d.ts +53 -0
- package/types/server/rscHostRequests.d.ts +29 -0
- package/types/server/rscHttp.d.ts +4 -2
- package/types/server/rscNavigationState.d.ts +5 -1
- package/types/server/rscPagePrompts.d.ts +13 -0
- package/types/server/rscPrefetchCache.d.ts +7 -6
- package/types/server/rscRenderControl.d.ts +12 -0
- package/types/server/rscRenderFallbacks.d.ts +41 -0
- package/types/server/rscRenderHandler.d.ts +29 -0
- package/types/server/rscRenderStats.d.ts +32 -0
- package/types/server/rscResultCaches.d.ts +18 -0
- package/types/server/rscRouteDocument.d.ts +52 -0
- package/types/server/rscStaticApp.d.ts +28 -0
- package/types/server/rscWorker.d.ts +1 -3
- package/types/server/rscWorkerHost.d.ts +10 -70
- package/types/server/rscWorkerProcess.d.ts +31 -0
- package/types/server/rscWorkerRecycler.d.ts +22 -0
- package/types/server/serverConfig.d.ts +30 -0
- package/types/server/serverMetrics.d.ts +11 -0
- package/types/server/sitemap.d.ts +1 -0
- package/types/server/ssrFromRscRenderer.d.ts +2 -2
- package/types/server/ssrStaticApp.d.ts +20 -0
- package/types/server/webArtifact.d.ts +7 -0
- package/types/server/webAssetRoutes.d.ts +11 -0
- package/types/server/webCsrSurface.d.ts +18 -0
- package/types/server/webDocumentRoute.d.ts +19 -0
- package/types/server/webRouteContext.d.ts +45 -0
- package/types/server/webRouter.d.ts +3 -28
- package/types/server/webRscRoute.d.ts +24 -0
- package/types/server/webSiteFiles.d.ts +12 -0
- package/types/server/webStaticApp.d.ts +8 -0
- package/types/server/wellKnownRoutes.d.ts +5 -0
- package/types/service/agent.service.d.ts +3 -0
- package/types/service/agentAccounts.d.ts +8 -0
- package/types/service/agentLoop/agentLoop.d.ts +33 -0
- package/types/service/agentLoop/agentLoopTypes.d.ts +235 -0
- package/types/service/agentLoop/deltaStream.d.ts +3 -0
- package/types/service/agentLoop/loopAnswer.d.ts +13 -0
- package/types/service/agentLoop/loopAsk.d.ts +12 -0
- package/types/service/agentLoop/loopCompaction.d.ts +12 -0
- package/types/service/agentLoop/loopRemotes.d.ts +40 -0
- package/types/service/agentLoop/loopRequest.d.ts +9 -0
- package/types/service/agentLoop/loopStored.d.ts +6 -0
- package/types/service/agentLoop/loopToolOutput.d.ts +8 -0
- package/types/service/agentLoop/loopToolkits.d.ts +17 -0
- package/types/service/agentLoop/loopTranscript.d.ts +13 -0
- package/types/{signal → service}/agentMeter.d.ts +1 -1
- package/types/{signal → service}/agentRelayPolicy.d.ts +18 -3
- package/types/service/index.d.ts +6 -0
- package/types/service/injectInfo.d.ts +2 -1
- package/types/service/ipcTypes.d.ts +10 -0
- package/types/service/liveRoomLimit.d.ts +26 -0
- package/types/service/liveRoomLimitError.d.ts +9 -0
- package/types/service/predefinedAdaptor/agentTools.adaptor.d.ts +31 -0
- package/types/service/predefinedAdaptor/anthropicLlm.d.ts +2 -2
- package/types/service/predefinedAdaptor/database.adaptor.d.ts +9 -7
- package/types/service/predefinedAdaptor/index.d.ts +1 -0
- package/types/service/predefinedAdaptor/llm.adaptor.d.ts +12 -0
- package/types/service/predefinedAdaptor/openaiDialect.d.ts +3 -2
- package/types/service/predefinedAdaptor/role.adaptor.d.ts +2 -0
- package/types/service/predefinedAdaptor/solidPubsub.adaptor.d.ts +3 -0
- package/types/service/predefinedAdaptor/solidSqlite.d.ts +1 -1
- package/types/service/predefinedAdaptor/sql/DocumentHydrator.d.ts +11 -0
- package/types/service/predefinedAdaptor/sql/DocumentRowCodec.d.ts +26 -0
- package/types/service/predefinedAdaptor/sql/DocumentWriter.d.ts +25 -0
- package/types/service/predefinedAdaptor/sql/QueryScope.d.ts +16 -0
- package/types/service/predefinedAdaptor/sql/QueryWriter.d.ts +20 -0
- package/types/service/predefinedAdaptor/sql/SqlDocumentStore.d.ts +5 -28
- package/types/service/predefinedAdaptor/sql/SqlTableSchema.d.ts +22 -0
- package/types/service/predefinedAdaptor/sql/StoredRows.d.ts +27 -0
- package/types/service/predefinedAdaptor/sql/TransactionScope.d.ts +3 -1
- package/types/service/predefinedAdaptor/sql/driver/bunSqlite.d.ts +3 -15
- package/types/service/predefinedAdaptor/sql/driver/postgres.d.ts +0 -8
- package/types/service/predefinedAdaptor/sql/types.d.ts +27 -4
- package/types/service/predefinedAdaptor/sseData.d.ts +13 -0
- package/types/service/predefinedAdaptor/websocket.adaptor.d.ts +7 -3
- package/types/service/serviceRegistry.d.ts +1 -0
- package/types/signal/SignalFailure.d.ts +4 -0
- package/types/signal/agentTurnStream.d.ts +3 -0
- package/types/signal/byIdRead.d.ts +7 -0
- package/types/signal/carriedClientIps.d.ts +4 -0
- package/types/signal/endpointRateLimit.d.ts +12 -0
- package/types/signal/index.d.ts +32 -32
- package/types/signal/mcp/McpDocument.d.ts +2 -0
- package/types/signal/mcp/mcpProtocol.d.ts +5 -0
- package/types/signal/mcp/pagePrompt.d.ts +13 -0
- package/types/signal/resolveFieldContext.d.ts +15 -0
- package/types/signal/serializer/fetch.serializer.d.ts +3 -1
- package/types/signal/signalContext.d.ts +2 -14
- package/types/signal/slice.d.ts +15 -13
- package/types/signal/trace.d.ts +12 -1
- package/types/signal/types.d.ts +38 -7
- package/types/store/action.d.ts +4 -27
- package/types/store/actionErrorMessage.d.ts +1 -0
- package/types/store/actionOption.d.ts +24 -0
- package/types/store/baseSt.d.ts +1 -0
- package/types/store/formFieldSetters.d.ts +80 -0
- package/types/store/index.d.ts +17 -16
- package/types/store/modelActionContext.d.ts +189 -0
- package/types/store/modelOpenActions.d.ts +12 -0
- package/types/store/modelWriteActions.d.ts +16 -0
- package/types/store/modelWriteGuard.d.ts +2 -5
- package/types/store/openSeq.d.ts +17 -0
- package/types/store/sliceListActions.d.ts +295 -0
- package/types/store/sliceLiveActions.d.ts +6 -0
- package/types/store/stateBuilder.d.ts +2 -0
- package/types/test/conformance.d.ts +3 -1
- package/types/ui/Agent/Chat.d.ts +5 -2
- package/types/ui/Agent/ChatHeader.d.ts +13 -0
- package/types/ui/Agent/ChatPendingCards.d.ts +23 -0
- package/types/ui/Agent/ToolRow.d.ts +13 -0
- package/types/ui/Field/Choice.d.ts +2 -1
- package/types/ui/Field/index.d.ts +1 -1
- package/types/ui/Reference/origin.d.ts +1 -0
- package/types/ui/UiOverride/UiOverride.d.ts +2 -0
- package/types/ui/index.d.ts +2 -1
- package/types/ui/overlayLayer.d.ts +8 -2
- package/types/ui/recipe/badgeRecipe.d.ts +3 -3
- package/types/ui/recipe/buttonRecipe.d.ts +3 -3
- package/types/ui/recipe/inputRecipe.d.ts +1 -1
- package/types/vendor/@akanjs/native/packages/cli/src/lib/project.d.ts +4 -0
- package/types/vendor/@akanjs/native/packages/desktop/src/relaunch.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/appearance/src/index.d.ts +9 -0
- package/types/vendor/@akanjs/native/plugins/external-view/src/index.d.ts +22 -13
- package/types/vendor/@akanjs/native/plugins/single-instance/src/socket.d.ts +15 -2
- package/types/vendor/use-agentic/AgentClientTools.d.ts +19 -0
- package/types/vendor/use-agentic/Compaction.d.ts +3 -1
- package/types/vendor/use-agentic/SessionQuestion.d.ts +26 -0
- package/types/vendor/use-agentic/Transcript.d.ts +1 -1
- package/types/vendor/use-agentic/failureCode.d.ts +4 -0
- package/types/vendor/use-agentic/index.d.ts +1 -0
- package/types/vendor/use-agentic/types.d.ts +12 -3
- package/types/webkit/CsrGuards.d.ts +3 -0
- package/types/webkit/McpAppHost.d.ts +24 -0
- package/types/webkit/RouteLevelBoundary.d.ts +17 -0
- package/types/webkit/csrRefresh.d.ts +13 -0
- package/types/webkit/index.d.ts +3 -0
- package/types/webkit/needsBrowser.d.ts +5 -0
- package/types/webkit/useCamera.d.ts +1 -1
- package/types/webkit/useCsrKeyboard.d.ts +19 -0
- package/types/webkit/useCsrLocationState.d.ts +21 -0
- package/types/webkit/useCsrNavigation.d.ts +25 -0
- package/types/webkit/useCsrRefs.d.ts +33 -0
- package/types/webkit/useCsrRenderTrace.d.ts +13 -0
- package/types/webkit/useCsrStackLifecycle.d.ts +12 -0
- package/types/webkit/useCsrTransitions.d.ts +2 -0
- package/types/webkit/useGeoLocation.d.ts +1 -1
- package/types/webkit/useHistory.d.ts +2 -3
- package/types/webkit/useResolvedFrame.d.ts +38 -0
- package/types/webkit/useSyncNavigation.d.ts +22 -0
- package/ui/Agent/Bubble.tsx +4 -118
- package/ui/Agent/Chat.tsx +402 -235
- package/ui/Agent/ChatHeader.tsx +59 -0
- package/ui/Agent/ChatPendingCards.tsx +49 -0
- package/ui/Agent/ToolRow.tsx +117 -0
- package/ui/Agent/fetchRunner.ts +8 -1
- package/ui/BottomSheet.tsx +1 -1
- package/ui/Data/Item.tsx +2 -2
- package/ui/Data/ListContainer.tsx +348 -181
- package/ui/Data/useViewModal.ts +10 -4
- package/ui/Dialog/LegacyModal.tsx +1 -1
- package/ui/Dialog/Modal.tsx +1 -1
- package/ui/Field/Choice.tsx +3 -1
- package/ui/Load/StreamBoundary.tsx +1 -6
- package/ui/Load/View.tsx +2 -1
- package/ui/Model/EditModal.tsx +2 -1
- package/ui/Popconfirm.tsx +1 -1
- package/ui/Reference/origin.ts +1 -0
- package/ui/Select.tsx +43 -51
- package/ui/Signal/RestApi.tsx +3 -2
- package/ui/System/Client.tsx +4 -1
- package/ui/UiOverride/UiOverride.tsx +2 -0
- package/ui/index.ts +5 -0
- package/ui/overlayLayer.ts +25 -2
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeActivity.kt +31 -13
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativePlugin.kt +4 -0
- package/vendor/@akanjs/native/native/desktop/Cargo.lock +1 -0
- package/vendor/@akanjs/native/native/desktop/Cargo.toml +2 -0
- package/vendor/@akanjs/native/native/desktop/src/external.rs +240 -114
- package/vendor/@akanjs/native/native/desktop/src/json.rs +14 -1
- package/vendor/@akanjs/native/native/desktop/src/lib.rs +12 -4
- package/vendor/@akanjs/native/native/desktop/src/linux/external.rs +696 -0
- package/vendor/@akanjs/native/native/desktop/src/linux/mod.rs +1 -0
- package/vendor/@akanjs/native/native/ios/Sources/AkanNativeViewController.swift +6 -1
- package/vendor/@akanjs/native/packages/cli/src/lib/native-plugins.ts +5 -3
- package/vendor/@akanjs/native/packages/cli/src/lib/project.ts +25 -1
- package/vendor/@akanjs/native/packages/desktop/src/deeplinks.ts +2 -2
- package/vendor/@akanjs/native/packages/desktop/src/host.ts +2 -2
- package/vendor/@akanjs/native/packages/desktop/src/relaunch.ts +8 -3
- package/vendor/@akanjs/native/plugins/app/src/desktop.ts +2 -2
- package/vendor/@akanjs/native/plugins/appearance/android/AppearancePlugin.kt +13 -0
- package/vendor/@akanjs/native/plugins/appearance/ios/AppearancePlugin.swift +27 -0
- package/vendor/@akanjs/native/plugins/appearance/native-plugin.json +2 -2
- package/vendor/@akanjs/native/plugins/appearance/src/index.ts +8 -1
- package/vendor/@akanjs/native/plugins/autostart/src/desktop.ts +2 -1
- package/vendor/@akanjs/native/plugins/external-view/native-plugin.json +4 -1
- package/vendor/@akanjs/native/plugins/external-view/src/index.ts +22 -13
- package/vendor/@akanjs/native/plugins/single-instance/src/socket.ts +113 -24
- package/vendor/use-agentic/AgentClientTools.ts +33 -0
- package/vendor/use-agentic/AgentSession.ts +35 -73
- package/vendor/use-agentic/CHANGELOG.md +0 -43
- package/vendor/use-agentic/Compaction.ts +12 -2
- package/vendor/use-agentic/SessionQuestion.ts +99 -0
- package/vendor/use-agentic/ToolRunner.ts +3 -15
- package/vendor/use-agentic/Transcript.ts +8 -5
- package/vendor/use-agentic/WIRE.md +28 -9
- package/vendor/use-agentic/failureCode.ts +44 -0
- package/vendor/use-agentic/httpRunner.ts +22 -8
- package/vendor/use-agentic/index.ts +1 -0
- package/vendor/use-agentic/types.ts +13 -1
- package/webkit/CsrGuards.ts +11 -2
- package/webkit/McpAppFetchBridge.ts +3 -1
- package/webkit/McpAppHost.ts +122 -0
- package/webkit/RenderLayer.tsx +48 -14
- package/webkit/RouteLevelBoundary.tsx +37 -0
- package/webkit/csrRefresh.ts +33 -0
- package/webkit/index.ts +3 -0
- package/webkit/lazy.tsx +5 -1
- package/webkit/needsBrowser.ts +10 -0
- package/webkit/useCamera.tsx +18 -7
- package/webkit/useCsrKeyboard.ts +155 -0
- package/webkit/useCsrLocationState.ts +58 -0
- package/webkit/useCsrNavigation.ts +302 -0
- package/webkit/useCsrRefs.ts +52 -0
- package/webkit/useCsrRenderTrace.ts +68 -0
- package/webkit/useCsrStackLifecycle.ts +120 -0
- package/webkit/useCsrTransitions.ts +552 -0
- package/webkit/useCsrValues.ts +73 -1235
- package/webkit/useGeoLocation.tsx +1 -3
- package/webkit/useHistory.ts +2 -2
- package/webkit/useLocation.ts +3 -2
- package/webkit/useResolvedFrame.ts +116 -0
- package/webkit/useSyncNavigation.ts +109 -0
- package/vendor/@akanjs/native/CHANGELOG.md +0 -21
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
type ImageResultValue,
|
|
7
7
|
PrimitiveRegistry,
|
|
8
8
|
} from "akanjs/base";
|
|
9
|
-
import {
|
|
9
|
+
import { interpolateTranslation, isGuardRefusal, Logger, MCP_FAILURE_META, type McpFailure } from "akanjs/common";
|
|
10
10
|
import { agentRead, ConstantRegistry, mask } from "akanjs/constant";
|
|
11
11
|
import { DictionaryLookup } from "akanjs/dictionary";
|
|
12
12
|
import { NoDocumentError } from "akanjs/document";
|
|
@@ -36,6 +36,8 @@ interface McpDispatcherProps {
|
|
|
36
36
|
legacyTextBlock?: boolean;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
export type McpAnswer = { value: unknown } | { images: ImageResultValue[] } | { error: string; code: string };
|
|
40
|
+
|
|
39
41
|
export class McpDispatcher {
|
|
40
42
|
static readonly logger = new Logger("McpDispatcher");
|
|
41
43
|
|
|
@@ -76,21 +78,40 @@ export class McpDispatcher {
|
|
|
76
78
|
};
|
|
77
79
|
} catch (error) {
|
|
78
80
|
const status = McpDispatcher.#statusOf(error);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
|
|
82
|
+
const refusal = (status === 401 || status === 403) && isGuardRefusal(error);
|
|
83
|
+
if (refusal && !req.headers.get("authorization")) throw new McpAuthRequiredError();
|
|
84
|
+
const failure = McpDispatcher.#failure(this.#message(error, status, exposed.refName), {
|
|
85
|
+
code: SignalFailure.codeOf(error, status),
|
|
86
|
+
statusCode: status || 500,
|
|
87
|
+
});
|
|
85
88
|
const restorable = forView ? McpDispatcher.#restorable(error, status) : null;
|
|
86
89
|
return restorable ? { ...failure, _meta: { ...failure._meta, [MCP_APP_META.error]: restorable } } : failure;
|
|
87
90
|
}
|
|
88
91
|
}
|
|
89
92
|
|
|
93
|
+
async answer(exposed: McpExposedEndpoint, args: Record<string, unknown>, req: Request): Promise<McpAnswer> {
|
|
94
|
+
const found = this.#index().get(exposed.key);
|
|
95
|
+
const crashed = McpDispatcher.#crashed.code;
|
|
96
|
+
if (!found) return { error: `Tool "${exposed.key}" is declared but not mounted on this server.`, code: crashed };
|
|
97
|
+
try {
|
|
98
|
+
const wire = await this.#exec(exposed.key, found, args, req);
|
|
99
|
+
if (exposed.endpoint.returns.refName !== ImageResult.refName)
|
|
100
|
+
return { value: McpDispatcher.#readable(exposed, wire) };
|
|
101
|
+
if (wire === null || wire === undefined) return { value: null };
|
|
102
|
+
const images = McpDispatcher.#images(exposed, wire);
|
|
103
|
+
return images ? { images } : { error: "The server failed to complete this request.", code: crashed };
|
|
104
|
+
} catch (error) {
|
|
105
|
+
const status = McpDispatcher.#statusOf(error);
|
|
106
|
+
return { error: this.#message(error, status, exposed.refName), code: SignalFailure.codeOf(error, status) };
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
90
110
|
static #restorable(error: unknown, status: number | undefined) {
|
|
91
111
|
if (!status || status >= 500) return null;
|
|
92
|
-
if (
|
|
93
|
-
|
|
112
|
+
if (isGuardRefusal(error)) return { statusCode: status };
|
|
113
|
+
if (isExceptionLike(error)) return error.toJSON();
|
|
114
|
+
return AkanError.is(error) && !(error instanceof McpArgumentError) ? SignalFailure.generalized(error) : null;
|
|
94
115
|
}
|
|
95
116
|
|
|
96
117
|
async filterForAccount<T extends { name: string }>(items: T[], req: Request): Promise<T[]> {
|
|
@@ -171,10 +192,10 @@ export class McpDispatcher {
|
|
|
171
192
|
if (error instanceof NoDocumentError) return `No ${refName} found for the arguments given.`;
|
|
172
193
|
if (status && status < 500) {
|
|
173
194
|
|
|
174
|
-
if (status === 401 || status === 403) return "You are not permitted to perform this action.";
|
|
175
|
-
|
|
176
195
|
if (AkanError.is(error) && !error.forwarded && !(error instanceof McpArgumentError))
|
|
177
196
|
return `${AkanError.reasonOf(status)}: ${error.code}`;
|
|
197
|
+
|
|
198
|
+
if (status === 401 || status === 403) return "You are not permitted to perform this action.";
|
|
178
199
|
const raw = error instanceof Error ? error.message : String(error);
|
|
179
200
|
|
|
180
201
|
this.#lookup ??= new DictionaryLookup(this.#props.language);
|
|
@@ -188,17 +209,6 @@ export class McpDispatcher {
|
|
|
188
209
|
return "The server failed to complete this request.";
|
|
189
210
|
}
|
|
190
211
|
|
|
191
|
-
static #codeOf(error: unknown, status: number | undefined): McpFailure {
|
|
192
|
-
if (!status) return McpDispatcher.#crashed;
|
|
193
|
-
const byStatus = { code: AkanError.codeOfStatus(status), statusCode: status };
|
|
194
|
-
if (status === 401 || status === 403) return byStatus;
|
|
195
|
-
const wire = isExceptionLike(error) ? (error.toJSON() as { error?: unknown; code?: unknown }) : {};
|
|
196
|
-
if (FailureCode.isKey(wire.error)) return { code: wire.error, statusCode: status };
|
|
197
|
-
if (AkanError.is(error) && FailureCode.isToken(error.code)) return { code: error.code, statusCode: status };
|
|
198
|
-
if (status < 500 && FailureCode.isToken(wire.code)) return { code: wire.code, statusCode: status };
|
|
199
|
-
return byStatus;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
212
|
static #statusOf(error: unknown): number | undefined {
|
|
203
213
|
if (isExceptionLike(error)) return error.statusCode;
|
|
204
214
|
if (AkanError.is(error)) return SignalFailure.generalized(error).statusCode;
|
|
@@ -235,21 +245,25 @@ export class McpDispatcher {
|
|
|
235
245
|
|
|
236
246
|
static #imageResult(exposed: McpExposedEndpoint, value: unknown): McpToolResult {
|
|
237
247
|
if (value === null || value === undefined) return { content: [{ type: "text", text: "null" }], isError: false };
|
|
238
|
-
const images = (exposed
|
|
248
|
+
const images = McpDispatcher.#images(exposed, value);
|
|
249
|
+
if (!images) return McpDispatcher.#failure("The server failed to complete this request.");
|
|
239
250
|
if (!images.length) return { content: [{ type: "text", text: "[]" }], isError: false };
|
|
240
|
-
|
|
241
|
-
McpDispatcher.logger.error(
|
|
242
|
-
`MCP refused the "${exposed.key}" image result: an ImageResult needs \`data\` in padded base64 without a \`data:\` prefix and a \`mimeType\` of ${ImageResult.mimeTypes.join(", ")}.`,
|
|
243
|
-
);
|
|
244
|
-
return McpDispatcher.#failure("The server failed to complete this request.");
|
|
245
|
-
}
|
|
246
|
-
const content = (images as ImageResultValue[]).flatMap(({ data, mimeType, caption }) => [
|
|
251
|
+
const content = images.flatMap(({ data, mimeType, caption }) => [
|
|
247
252
|
...(caption ? [{ type: "text" as const, text: caption }] : []),
|
|
248
253
|
{ type: "image" as const, data, mimeType },
|
|
249
254
|
]);
|
|
250
255
|
return { content, isError: false };
|
|
251
256
|
}
|
|
252
257
|
|
|
258
|
+
static #images(exposed: McpExposedEndpoint, value: unknown): ImageResultValue[] | null {
|
|
259
|
+
const images = (exposed.endpoint.returns.arrDepth ? [value].flat(Number.POSITIVE_INFINITY) : [value]) as unknown[];
|
|
260
|
+
if (images.every((image) => ImageResult.validate(image as ImageResultValue))) return images as ImageResultValue[];
|
|
261
|
+
McpDispatcher.logger.error(
|
|
262
|
+
`MCP refused the "${exposed.key}" image result: an ImageResult needs \`data\` in padded base64 without a \`data:\` prefix and a \`mimeType\` of ${ImageResult.mimeTypes.join(", ")}.`,
|
|
263
|
+
);
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
|
|
253
267
|
static #failure(message: string, failure = McpDispatcher.#crashed): McpToolResult {
|
|
254
268
|
return { content: [{ type: "text", text: message }], isError: true, _meta: { [MCP_FAILURE_META]: failure } };
|
|
255
269
|
}
|
package/server/mcp/McpPages.ts
CHANGED
|
@@ -9,7 +9,14 @@ import {
|
|
|
9
9
|
} from "../../signal/mcp";
|
|
10
10
|
import type { PromptMessage } from "../../signal/mcp/Msg";
|
|
11
11
|
import type { McpPrompt } from "../../signal/mcp/mcpProtocol";
|
|
12
|
-
import type {
|
|
12
|
+
import type {
|
|
13
|
+
PagePromptEntry,
|
|
14
|
+
PagePromptRefusal,
|
|
15
|
+
PagePromptRender,
|
|
16
|
+
PagePromptRun,
|
|
17
|
+
PagePromptRunInput,
|
|
18
|
+
PagePromptSource,
|
|
19
|
+
} from "../../signal/mcp/pagePrompt";
|
|
13
20
|
import { McpApps } from "./McpApps";
|
|
14
21
|
import { McpAuthRequiredError, type McpDispatcher } from "./McpDispatcher";
|
|
15
22
|
import type { McpUiSession } from "./McpUiSession";
|
|
@@ -37,7 +44,7 @@ interface McpPageCall {
|
|
|
37
44
|
export type McpPageRun =
|
|
38
45
|
| { badArguments: true }
|
|
39
46
|
| { refusal: string; failure: McpFailure }
|
|
40
|
-
| { run: Extract<PagePromptRun, { ok: true }> | null; messages: PromptMessage[] };
|
|
47
|
+
| { run: Extract<PagePromptRun, { ok: true }> | null; messages: PromptMessage[]; html?: string | null };
|
|
41
48
|
|
|
42
49
|
export class McpPages {
|
|
43
50
|
static readonly listWaitMs = 1_000;
|
|
@@ -105,7 +112,8 @@ export class McpPages {
|
|
|
105
112
|
args: Record<string, unknown> | null,
|
|
106
113
|
): Promise<{ badArguments: true } | { result: object }> {
|
|
107
114
|
const apps = this.#props.apps;
|
|
108
|
-
const
|
|
115
|
+
const origin = this.#props.publicOrigin(call.req);
|
|
116
|
+
const page = await this.run(call, document, entry, args, apps?.drawsHtml(entry, call.params) ? origin : null);
|
|
109
117
|
if ("badArguments" in page) return page;
|
|
110
118
|
if ("refusal" in page)
|
|
111
119
|
return {
|
|
@@ -116,9 +124,8 @@ export class McpPages {
|
|
|
116
124
|
},
|
|
117
125
|
};
|
|
118
126
|
if (!page.run || !apps) return { result: { content: page.messages.map((message) => message.content) } };
|
|
119
|
-
const origin = this.#props.publicOrigin(call.req);
|
|
120
127
|
const forView = call.ui ? { account: McpApps.accountOf(call.req) } : null;
|
|
121
|
-
return { result: apps.resultOf(entry, page.run, page.messages, origin, forView) };
|
|
128
|
+
return { result: apps.resultOf(entry, page.run, page.messages, origin, forView, page.html ?? null) };
|
|
122
129
|
}
|
|
123
130
|
|
|
124
131
|
async run(
|
|
@@ -126,6 +133,7 @@ export class McpPages {
|
|
|
126
133
|
document: McpDocument,
|
|
127
134
|
entry: PagePromptEntry,
|
|
128
135
|
args: Record<string, unknown> | null,
|
|
136
|
+
htmlOrigin: string | null = null,
|
|
129
137
|
): Promise<McpPageRun> {
|
|
130
138
|
const source = this.#props.source;
|
|
131
139
|
const { name } = entry;
|
|
@@ -147,12 +155,16 @@ export class McpPages {
|
|
|
147
155
|
.filter((arg) => arg.required && strings[arg.name] === undefined)
|
|
148
156
|
.map((arg) => arg.name);
|
|
149
157
|
if (missing.length) return { run: null, messages: composer.missing(entry, missing) };
|
|
150
|
-
const run = await
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
158
|
+
const { run, html } = await this.#render(
|
|
159
|
+
source,
|
|
160
|
+
{
|
|
161
|
+
name,
|
|
162
|
+
arguments: strings,
|
|
163
|
+
headers: McpPages.#forwardedHeaders(call.req),
|
|
164
|
+
language: this.#props.language,
|
|
165
|
+
},
|
|
166
|
+
htmlOrigin,
|
|
167
|
+
);
|
|
156
168
|
if (!run.ok) {
|
|
157
169
|
|
|
158
170
|
const gated = run.reason === "redirect" || run.reason === "forbidden";
|
|
@@ -168,7 +180,17 @@ export class McpPages {
|
|
|
168
180
|
: MCP_SCREEN_REFUSAL.failed;
|
|
169
181
|
return { refusal: message, failure: McpPages.#failureOf(gated ? "forbidden" : run.reason) };
|
|
170
182
|
}
|
|
171
|
-
return { run, messages: await composer.compose(entry, run) };
|
|
183
|
+
return { run, messages: await composer.compose(entry, run), html };
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async #render(source: PagePromptSource, input: PagePromptRunInput, origin: string | null): Promise<PagePromptRender> {
|
|
187
|
+
if (origin === null || !source.render) return { run: await source.run(input), html: null };
|
|
188
|
+
try {
|
|
189
|
+
return await source.render({ ...input, origin });
|
|
190
|
+
} catch (error) {
|
|
191
|
+
const message = `static app "${input.name}" sent no HTML: ${error instanceof Error ? error.message : error}`;
|
|
192
|
+
return { run: { ok: false, reason: "error", message }, html: null };
|
|
193
|
+
}
|
|
172
194
|
}
|
|
173
195
|
|
|
174
196
|
static #failureOf(reason: PagePromptRefusal): McpFailure {
|
|
@@ -37,6 +37,20 @@ export class McpRateLimiter {
|
|
|
37
37
|
this.#limiter = new RateLimiter(shared, { topic: "mcpRate" });
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
static fromEnv(): { rateLimit?: McpRateLimitOption | false } {
|
|
41
|
+
const raw = process.env.AKAN_MCP_RATE_LIMIT?.trim().toLowerCase();
|
|
42
|
+
if (raw === "off" || raw === "false" || raw === "0") return { rateLimit: false };
|
|
43
|
+
const option: McpRateLimitOption = {};
|
|
44
|
+
if (raw) {
|
|
45
|
+
const [calls, seconds] = raw.split("/").map((part) => Number(part));
|
|
46
|
+
if (Number.isInteger(calls) && calls > 0) option.calls = calls;
|
|
47
|
+
if (Number.isInteger(seconds) && seconds > 0) option.windowMs = seconds * 1000;
|
|
48
|
+
}
|
|
49
|
+
const concurrent = Number(process.env.AKAN_MCP_CONCURRENT);
|
|
50
|
+
if (Number.isInteger(concurrent) && concurrent >= 0) option.concurrent = concurrent;
|
|
51
|
+
return Object.keys(option).length ? { rateLimit: option } : {};
|
|
52
|
+
}
|
|
53
|
+
|
|
40
54
|
async acquire(key: string, now = Date.now()): Promise<McpRateLimitVerdict> {
|
|
41
55
|
const held = this.#inFlight.get(key) ?? 0;
|
|
42
56
|
if (this.concurrent && held >= this.concurrent) return { ok: false, reason: "concurrent", retryAfterMs: 1_000 };
|
package/server/mcp/McpRouter.ts
CHANGED
|
@@ -112,7 +112,9 @@ export class McpRouter {
|
|
|
112
112
|
this.#dispatcher = new McpDispatcher({ ...props, legacyTextBlock, language: props.language ?? defaultLanguage });
|
|
113
113
|
this.#auth = new McpAuth({ ...props.auth, path: props.path ?? "/mcp" });
|
|
114
114
|
this.#apps =
|
|
115
|
-
props.apps && props.pagePrompts
|
|
115
|
+
props.apps && props.pagePrompts
|
|
116
|
+
? new McpApps(props.appShell ?? null, { readOnly: props.readOnly, staticHtml: !!props.pagePrompts.render })
|
|
117
|
+
: null;
|
|
116
118
|
const cache = props.registry.adaptor.get(CacheAdaptorRole) as (McpSharedCounter & McpUiSessionStore) | undefined;
|
|
117
119
|
this.#pages = new McpPages({
|
|
118
120
|
source: props.pagePrompts,
|
|
@@ -409,7 +411,7 @@ export class McpRouter {
|
|
|
409
411
|
};
|
|
410
412
|
const body = (await (await this.#dispatch(call)).json()) as McpJsonRpcResponse;
|
|
411
413
|
const result = body.result as Record<string, unknown> | undefined;
|
|
412
|
-
if (!result) throw new
|
|
414
|
+
if (!result) throw new AkanError("listFailed", `MCP ${method} failed: ${body.error?.message ?? "no result"}`);
|
|
413
415
|
items.push(...((result[key] as unknown[] | undefined) ?? []));
|
|
414
416
|
cursor = typeof result.nextCursor === "string" ? result.nextCursor : undefined;
|
|
415
417
|
} while (cursor);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
|
2
|
+
import { AkanError } from "akanjs/base";
|
|
2
3
|
import { Logger } from "akanjs/common";
|
|
3
4
|
import type { CacheAdaptor } from "akanjs/service";
|
|
4
5
|
|
|
@@ -61,7 +62,7 @@ export class McpUiSession {
|
|
|
61
62
|
if (!store) return McpUiSession.#processKey;
|
|
62
63
|
await store.setIfAbsent(McpUiSession.#topic, "key", randomBytes(32).toString("base64url"));
|
|
63
64
|
const key = await store.get<string>(McpUiSession.#topic, "key");
|
|
64
|
-
if (typeof key !== "string" || !key) throw new
|
|
65
|
+
if (typeof key !== "string" || !key) throw new AkanError("invalidKey", "the signing key it stored is gone");
|
|
65
66
|
return key;
|
|
66
67
|
}
|
|
67
68
|
}
|
package/server/mcp/index.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { parseArgs } from "node:util";
|
|
2
|
+
import type { UndeclaredIndex } from "akanjs/service";
|
|
2
3
|
import { MigrationError, type MigrationErrorCode } from "./migrationError";
|
|
3
4
|
import type { MigrationListItem, MigrationRunner } from "./migrationRunner";
|
|
4
5
|
|
|
5
|
-
export const migrationActions = ["list", "plan", "apply", "verify", "rollback"] as const;
|
|
6
|
+
export const migrationActions = ["list", "plan", "apply", "verify", "rollback", "indexes", "prune-indexes"] as const;
|
|
6
7
|
export type MigrationAction = (typeof migrationActions)[number];
|
|
7
8
|
const migrationOptions = ["param", "expect", "actor", "items"] as const;
|
|
8
9
|
type MigrationOption = (typeof migrationOptions)[number];
|
|
@@ -35,7 +36,10 @@ export class MigrationCommand {
|
|
|
35
36
|
apply: ["param", "expect", "actor"],
|
|
36
37
|
verify: ["param", "actor"],
|
|
37
38
|
rollback: ["actor"],
|
|
39
|
+
indexes: [],
|
|
40
|
+
"prune-indexes": ["actor"],
|
|
38
41
|
};
|
|
42
|
+
static readonly #untargeted = new Set<MigrationAction>(["list", "indexes", "prune-indexes"]);
|
|
39
43
|
|
|
40
44
|
static usageOf(invokedAs = "ops migrate") {
|
|
41
45
|
return [
|
|
@@ -45,6 +49,8 @@ export class MigrationCommand {
|
|
|
45
49
|
` ${invokedAs} apply <id> [--param <name>=<value>]... [--expect <planHash>] [--actor <id>] [--json]`,
|
|
46
50
|
` ${invokedAs} verify <id> [--param <name>=<value>]... [--actor <id>] [--json]`,
|
|
47
51
|
` ${invokedAs} rollback <applyRunId|id> [--actor <id>] [--json]`,
|
|
52
|
+
` ${invokedAs} indexes [--json]`,
|
|
53
|
+
` ${invokedAs} prune-indexes [--actor <id>] [--json]`,
|
|
48
54
|
].join("\n");
|
|
49
55
|
}
|
|
50
56
|
|
|
@@ -59,7 +65,7 @@ export class MigrationCommand {
|
|
|
59
65
|
if (!migrationActions.includes(name as MigrationAction))
|
|
60
66
|
throw new MigrationError("usage", `Unknown action "${name}"\n${usage}`);
|
|
61
67
|
const action = name as MigrationAction;
|
|
62
|
-
if (action
|
|
68
|
+
if (MigrationCommand.#untargeted.has(action) ? target : !target)
|
|
63
69
|
throw new MigrationError("usage", `${action} ${target ? "takes no id" : "needs an id"}\n${usage}`);
|
|
64
70
|
if (extra.length) throw new MigrationError("usage", `Unexpected arguments: ${extra.join(" ")}`);
|
|
65
71
|
const refused = migrationOptions.find(
|
|
@@ -85,6 +91,19 @@ export class MigrationCommand {
|
|
|
85
91
|
if (action === "list") return { ok: true, action, migrations: await runner.list() };
|
|
86
92
|
if (action === "plan") return { ok: true, action, ...(await runner.plan(target, params, { actor, items })) };
|
|
87
93
|
if (action === "rollback") return { ok: true, action, ...(await runner.rollback(target, { actor })) };
|
|
94
|
+
if (action === "indexes") return { ok: true, action, indexes: await runner.undeclaredIndexes() };
|
|
95
|
+
if (action === "prune-indexes") {
|
|
96
|
+
const { dropped, failed } = await runner.pruneIndexes({ actor });
|
|
97
|
+
if (!failed.length) return { ok: true, action, dropped, failed };
|
|
98
|
+
return {
|
|
99
|
+
ok: false,
|
|
100
|
+
action,
|
|
101
|
+
code: "failed",
|
|
102
|
+
error: `${failed.length} of the indexes could not be dropped`,
|
|
103
|
+
dropped,
|
|
104
|
+
failed,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
88
107
|
const result =
|
|
89
108
|
action === "apply"
|
|
90
109
|
? await runner.apply(target, params, { expect, actor })
|
|
@@ -128,6 +147,8 @@ export class MigrationCommand {
|
|
|
128
147
|
if (json) return JSON.stringify(result);
|
|
129
148
|
if (result.ok && result.action === "list")
|
|
130
149
|
return MigrationCommand.#renderList(result.migrations as MigrationListItem[]);
|
|
150
|
+
if (result.ok && result.action === "indexes")
|
|
151
|
+
return MigrationCommand.#renderIndexes(result.indexes as UndeclaredIndex[]);
|
|
131
152
|
return JSON.stringify(result, null, 2);
|
|
132
153
|
}
|
|
133
154
|
|
|
@@ -146,6 +167,14 @@ export class MigrationCommand {
|
|
|
146
167
|
.join("\n");
|
|
147
168
|
}
|
|
148
169
|
|
|
170
|
+
static #renderIndexes(indexes: UndeclaredIndex[]) {
|
|
171
|
+
if (!indexes.length) return "This release declares every index an earlier one built";
|
|
172
|
+
return [
|
|
173
|
+
"Kept for an earlier release; drop them with prune-indexes once no instance runs one:",
|
|
174
|
+
...indexes.map(({ table, name, unique }) => `${unique ? "unique" : " "} ${table} ${name}`),
|
|
175
|
+
].join("\n");
|
|
176
|
+
}
|
|
177
|
+
|
|
149
178
|
static #parseArgs(argv: string[], usage: string) {
|
|
150
179
|
try {
|
|
151
180
|
return parseArgs({
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { Logger } from "akanjs/common";
|
|
2
2
|
import { createDocumentId, sanitizeJson } from "akanjs/document";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
type DatabaseAdaptor,
|
|
5
|
+
descriptorHash,
|
|
6
|
+
type PrunedIndex,
|
|
7
|
+
type SqlDocumentStore,
|
|
8
|
+
stableJson,
|
|
9
|
+
type UndeclaredIndex,
|
|
10
|
+
} from "akanjs/service";
|
|
4
11
|
import { MigrationChangeLog } from "./migrationChangeLog";
|
|
5
12
|
import { MigrationChanges, type MigrationSkip } from "./migrationChanges";
|
|
6
13
|
import { MigrationContext, type MigrationGet } from "./migrationContext";
|
|
@@ -79,6 +86,11 @@ export interface MigrationRollbackResult {
|
|
|
79
86
|
runs: MigrationRollbackRun[];
|
|
80
87
|
}
|
|
81
88
|
|
|
89
|
+
export interface MigrationPruneResult {
|
|
90
|
+
dropped: UndeclaredIndex[];
|
|
91
|
+
failed: PrunedIndex[];
|
|
92
|
+
}
|
|
93
|
+
|
|
82
94
|
export class MigrationRunner {
|
|
83
95
|
static readonly defaultItemNum = 100;
|
|
84
96
|
readonly #entries: MigrationEntry[];
|
|
@@ -129,6 +141,29 @@ export class MigrationRunner {
|
|
|
129
141
|
);
|
|
130
142
|
}
|
|
131
143
|
|
|
144
|
+
async undeclaredIndexes(): Promise<UndeclaredIndex[]> {
|
|
145
|
+
const indexes: UndeclaredIndex[] = [];
|
|
146
|
+
for (const store of this.#stores()) indexes.push(...(await store.undeclaredIndexes()));
|
|
147
|
+
return indexes;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async pruneIndexes({ actor = null }: { actor?: string | null } = {}): Promise<MigrationPruneResult> {
|
|
151
|
+
const pruned: PrunedIndex[] = [];
|
|
152
|
+
for (const store of this.#stores()) pruned.push(...(await store.pruneUndeclaredIndexes()));
|
|
153
|
+
const failed = pruned.filter(({ error }) => error !== undefined);
|
|
154
|
+
const dropped = pruned.filter(({ error }) => error === undefined);
|
|
155
|
+
this.#logger.info(
|
|
156
|
+
`prune-indexes${actor ? ` for ${actor}` : ""}: ${dropped.length} dropped, ${failed.length} failed to drop`,
|
|
157
|
+
);
|
|
158
|
+
return { dropped, failed };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
#stores(): SqlDocumentStore[] {
|
|
162
|
+
const stores = this.#database.stores?.();
|
|
163
|
+
if (!stores) throw new MigrationError("failed", "This database adaptor keeps no model stores to read indexes from");
|
|
164
|
+
return stores;
|
|
165
|
+
}
|
|
166
|
+
|
|
132
167
|
async plan(
|
|
133
168
|
id: string,
|
|
134
169
|
raw: Record<string, string> = {},
|
package/server/nativeFile.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { createHmac, timingSafeEqual } from "node:crypto";
|
|
|
2
2
|
import { lstatSync, readFileSync, realpathSync } from "node:fs";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import { getEnv } from "akanjs/base";
|
|
5
|
+
import { AkanError, getEnv } from "akanjs/base";
|
|
6
|
+
import { Logger } from "akanjs/common";
|
|
6
7
|
import type { AkanIpcMessage } from "akanjs/service";
|
|
7
8
|
|
|
8
9
|
export type NativeFileMode = "read" | "write" | "folder";
|
|
@@ -13,12 +14,13 @@ export class NativeFile {
|
|
|
13
14
|
static timeoutMs = 5_000;
|
|
14
15
|
static operationMode: () => string = () => getEnv().operationMode;
|
|
15
16
|
static readonly #waiting = new Map<string, (answer: Resolved) => void>();
|
|
17
|
+
static readonly #logger = new Logger("NativeFile");
|
|
16
18
|
static #listener: ((message: unknown) => void) | null = null;
|
|
17
19
|
|
|
18
20
|
/** The path behind `grant`, which the user must have given for `mode`. */
|
|
19
21
|
static async resolve(grant: string, mode: NativeFileMode): Promise<string> {
|
|
20
22
|
const found = grant.startsWith("dev:") ? NativeFile.#devGrant(grant) : await NativeFile.#ask(grant);
|
|
21
|
-
if (found.mode !== mode) throw
|
|
23
|
+
if (found.mode !== mode) throw NativeFile.#refused(`The file was granted to ${found.mode}, not to ${mode}.`);
|
|
22
24
|
return found.path;
|
|
23
25
|
}
|
|
24
26
|
|
|
@@ -35,19 +37,29 @@ export class NativeFile {
|
|
|
35
37
|
static #assertInside(folder: string, target: string, relative: string) {
|
|
36
38
|
const inside = path.relative(folder, target);
|
|
37
39
|
if (inside === ".." || inside.startsWith(`..${path.sep}`) || path.isAbsolute(inside))
|
|
38
|
-
throw
|
|
40
|
+
throw NativeFile.#refused(`${relative} is outside the folder the user granted.`);
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
static #realPath(target: string): string {
|
|
42
44
|
const rest: string[] = [];
|
|
45
|
+
let missing: unknown;
|
|
43
46
|
for (let current = target; ; current = path.dirname(current)) {
|
|
47
|
+
let real: string;
|
|
44
48
|
try {
|
|
45
|
-
|
|
49
|
+
real = realpathSync.native(current);
|
|
46
50
|
} catch (error) {
|
|
47
|
-
|
|
48
|
-
if (
|
|
51
|
+
|
|
52
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT" || path.dirname(current) === current)
|
|
53
|
+
throw NativeFile.#refused(`${target} cannot be followed.`, error);
|
|
54
|
+
if (NativeFile.#exists(current)) throw NativeFile.#refused(`${target} is a link to nothing.`);
|
|
49
55
|
rest.unshift(path.basename(current));
|
|
56
|
+
missing = error;
|
|
57
|
+
continue;
|
|
50
58
|
}
|
|
59
|
+
|
|
60
|
+
if (rest.length > 0 && !lstatSync(real).isDirectory())
|
|
61
|
+
throw NativeFile.#refused(`${target} cannot be followed.`, missing);
|
|
62
|
+
return path.join(real, ...rest);
|
|
51
63
|
}
|
|
52
64
|
}
|
|
53
65
|
|
|
@@ -62,19 +74,26 @@ export class NativeFile {
|
|
|
62
74
|
|
|
63
75
|
static #ask(grant: string): Promise<{ path: string; mode: NativeFileMode }> {
|
|
64
76
|
const send = process.send?.bind(process);
|
|
65
|
-
if (!send)
|
|
77
|
+
if (!send)
|
|
78
|
+
return Promise.reject(
|
|
79
|
+
new AkanError("desktopAppRequired", "A file grant resolves only inside the desktop app that gave it."),
|
|
80
|
+
);
|
|
66
81
|
NativeFile.#listen();
|
|
67
82
|
const id = crypto.randomUUID();
|
|
68
83
|
return new Promise((resolve, reject) => {
|
|
69
84
|
const timer = setTimeout(() => {
|
|
70
85
|
NativeFile.#waiting.delete(id);
|
|
71
|
-
reject(
|
|
86
|
+
reject(
|
|
87
|
+
new AkanError("fileGrantUnavailable", "The desktop app did not answer for the file grant.", {
|
|
88
|
+
statusCode: 503,
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
72
91
|
}, NativeFile.timeoutMs);
|
|
73
92
|
NativeFile.#waiting.set(id, (answer) => {
|
|
74
93
|
clearTimeout(timer);
|
|
75
94
|
NativeFile.#waiting.delete(id);
|
|
76
95
|
if (answer.path && answer.mode) resolve({ path: answer.path, mode: answer.mode });
|
|
77
|
-
else reject(
|
|
96
|
+
else reject(NativeFile.#refused(answer.error ?? "The desktop app refused the file grant."));
|
|
78
97
|
});
|
|
79
98
|
send({ type: "file.resolve", id, grant } satisfies AkanIpcMessage);
|
|
80
99
|
});
|
|
@@ -92,16 +111,24 @@ export class NativeFile {
|
|
|
92
111
|
static #devGrant(grant: string): { path: string; mode: NativeFileMode } {
|
|
93
112
|
|
|
94
113
|
if (NativeFile.operationMode() !== "local")
|
|
95
|
-
throw
|
|
114
|
+
throw NativeFile.#refused("A dev build's file grant resolves only on akan start, in operationMode local.");
|
|
96
115
|
const [, mode, encoded = "", signature = ""] = grant.split(":");
|
|
97
|
-
if (mode !== "read" && mode !== "write" && mode !== "folder")
|
|
116
|
+
if (mode !== "read" && mode !== "write" && mode !== "folder") {
|
|
117
|
+
NativeFile.#logger.warn("File grant refused: The file grant is malformed.");
|
|
118
|
+
throw new AkanError("invalidFileGrant", "The file grant is malformed.", { statusCode: 400 });
|
|
119
|
+
}
|
|
98
120
|
const key = readFileSync(
|
|
99
121
|
process.env.AKAN_NATIVE_DEV_GRANT_KEY || path.join(homedir(), ".akan", "native", "dev-file-grant.key"),
|
|
100
122
|
);
|
|
101
123
|
const expected = createHmac("sha256", key).update(`${mode}:${encoded}`).digest();
|
|
102
124
|
const given = Buffer.from(signature, "base64url");
|
|
103
125
|
if (given.length !== expected.length || !timingSafeEqual(given, expected))
|
|
104
|
-
throw
|
|
126
|
+
throw NativeFile.#refused("The file grant was not signed by this computer's dev build.");
|
|
105
127
|
return { path: Buffer.from(encoded, "base64url").toString(), mode };
|
|
106
128
|
}
|
|
129
|
+
|
|
130
|
+
static #refused(message: string, cause?: unknown) {
|
|
131
|
+
NativeFile.#logger.warn(`File grant refused: ${message}`);
|
|
132
|
+
return new AkanError("fileGrantRefused", message, { statusCode: 403, cause });
|
|
133
|
+
}
|
|
107
134
|
}
|
package/server/nativeSecret.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AkanError } from "akanjs/base";
|
|
1
2
|
import type { AkanIpcMessage } from "akanjs/service";
|
|
2
3
|
import { SelfExec } from "./selfExec";
|
|
3
4
|
|
|
@@ -33,7 +34,8 @@ export class NativeSecret {
|
|
|
33
34
|
const send = NativeSecret.available ? process.send?.bind(process) : undefined;
|
|
34
35
|
if (!send)
|
|
35
36
|
return Promise.reject(
|
|
36
|
-
new
|
|
37
|
+
new AkanError(
|
|
38
|
+
"desktopAppRequired",
|
|
37
39
|
"Secrets are kept only by the desktop app that carries this server; elsewhere use the env or secrets.",
|
|
38
40
|
),
|
|
39
41
|
);
|
|
@@ -42,13 +44,20 @@ export class NativeSecret {
|
|
|
42
44
|
return new Promise((resolve, reject) => {
|
|
43
45
|
const timer = setTimeout(() => {
|
|
44
46
|
NativeSecret.#waiting.delete(id);
|
|
45
|
-
reject(
|
|
47
|
+
reject(
|
|
48
|
+
new AkanError("secretStoreUnavailable", `The desktop app did not answer for the secret "${request.key}".`, {
|
|
49
|
+
statusCode: 503,
|
|
50
|
+
}),
|
|
51
|
+
);
|
|
46
52
|
}, NativeSecret.timeoutMs);
|
|
47
53
|
NativeSecret.#waiting.set(id, (answer) => {
|
|
48
54
|
clearTimeout(timer);
|
|
49
55
|
NativeSecret.#waiting.delete(id);
|
|
50
56
|
if (answer.error === undefined) resolve(answer);
|
|
51
|
-
else
|
|
57
|
+
else
|
|
58
|
+
reject(
|
|
59
|
+
new AkanError("secretRefused", `The desktop app refused the secret "${request.key}": ${answer.error}`),
|
|
60
|
+
);
|
|
52
61
|
});
|
|
53
62
|
send({ type: "secret.request", id, ...request } satisfies AkanIpcMessage);
|
|
54
63
|
});
|
|
@@ -124,8 +124,8 @@ export class OAuthClientIdMetadata {
|
|
|
124
124
|
static readonly #lookup: OAuthAddressLookup = async (hostname) =>
|
|
125
125
|
await Promise.race([
|
|
126
126
|
lookup(hostname, { all: true }),
|
|
127
|
-
new Promise<
|
|
128
|
-
setTimeout(() =>
|
|
127
|
+
new Promise<{ address: string }[]>((resolve) =>
|
|
128
|
+
setTimeout(() => resolve([]), OAuthClientIdMetadata.timeoutMs).unref(),
|
|
129
129
|
),
|
|
130
130
|
]);
|
|
131
131
|
|
|
@@ -54,7 +54,7 @@ export class MigrateJobs {
|
|
|
54
54
|
return `id must match ${MigrateJobs.idPattern.source}`;
|
|
55
55
|
if (typeof action !== "string" || !migrationActions.includes(action as MigrationAction))
|
|
56
56
|
return `action must be one of ${migrationActions.join(", ")}`;
|
|
57
|
-
if ((action === "apply" || action === "rollback") && !actor)
|
|
57
|
+
if ((action === "apply" || action === "rollback" || action === "prune-indexes") && !actor)
|
|
58
58
|
return `${action} needs the token's sub, the person it runs for`;
|
|
59
59
|
if (target !== undefined && (typeof target !== "string" || !MigrateJobs.targetPattern.test(target)))
|
|
60
60
|
return `target must match ${MigrateJobs.targetPattern.source}`;
|
|
@@ -72,7 +72,7 @@ export class MigrateJobs {
|
|
|
72
72
|
...entries.map(([name, value]) => `--param=${name}=${value as string}`),
|
|
73
73
|
...(expect ? [`--expect=${expect}`] : []),
|
|
74
74
|
...(items === undefined ? [] : [`--items=${items}`]),
|
|
75
|
-
...(actor && action !== "list" ? [`--actor=${actor}`] : []),
|
|
75
|
+
...(actor && action !== "list" && action !== "indexes" ? [`--actor=${actor}`] : []),
|
|
76
76
|
"--json",
|
|
77
77
|
];
|
|
78
78
|
return { id, action: action as MigrationAction, argv };
|
package/server/ops/opsCommand.ts
CHANGED
|
@@ -20,7 +20,7 @@ export class OpsCommand {
|
|
|
20
20
|
"Usage:",
|
|
21
21
|
" bun main.js ops snapshot [--id <id>] [--out <dir>] [--include-solid] [--db <file>] [--solid-db <file>] [--allow-plaintext] [--json]",
|
|
22
22
|
" bun main.js ops restore <manifest.json> [--identity <file>] [--db <file>] [--solid-db <file>] [--allow-plaintext] [--force]",
|
|
23
|
-
" bun main.js ops migrate [list|plan|apply|verify|rollback] [<id>] [--param <name>=<value>]... [--expect <planHash>] [--items <n>] [--actor <id>] [--json]",
|
|
23
|
+
" bun main.js ops migrate [list|plan|apply|verify|rollback|indexes|prune-indexes] [<id>] [--param <name>=<value>]... [--expect <planHash>] [--items <n>] [--actor <id>] [--json]",
|
|
24
24
|
].join("\n");
|
|
25
25
|
|
|
26
26
|
static async run(argv: string[], host?: OpsHost): Promise<number> {
|
package/server/ops/opsRoute.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AkanError } from "akanjs/base";
|
|
1
2
|
import { Logger } from "akanjs/common";
|
|
2
3
|
import { getEnv } from "../../base/baseEnv";
|
|
3
4
|
import { Ed25519Key } from "../ed25519Key";
|
|
@@ -68,7 +69,10 @@ export class OpsRoute {
|
|
|
68
69
|
|
|
69
70
|
const machineKey = OpsRoute.#machinePublicKey();
|
|
70
71
|
if (machineKey && Ed25519Key.rawPublic(machineKey) === Ed25519Key.rawPublic(key))
|
|
71
|
-
throw new
|
|
72
|
+
throw new AkanError(
|
|
73
|
+
"invalidConfig",
|
|
74
|
+
"AKAN_OPS_PUBLIC_KEY is also the machine token key; give the ops channel a key of its own",
|
|
75
|
+
);
|
|
72
76
|
verifier = new OpsTokenVerifier(key, OpsTokenVerifier.audienceOf(appName, environment));
|
|
73
77
|
} catch (error) {
|
|
74
78
|
|