akanjs 3.2.0-rc.9 → 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 -680
- 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 +121 -204
- package/server/rscClientCache.ts +165 -0
- package/server/rscClientChunks.ts +126 -8
- package/server/rscClientFetch.ts +3 -1
- 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 +5 -1
- 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/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/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
|
@@ -38,7 +38,12 @@ final class AkanNativeViewController: UIViewController, WKNavigationDelegate, WK
|
|
|
38
38
|
required init?(coder: NSCoder) { fatalError("not used") }
|
|
39
39
|
|
|
40
40
|
// S1: the status bar follows the page's light/dark appearance (UIViewControllerBasedStatusBarAppearance).
|
|
41
|
-
override var preferredStatusBarStyle: UIStatusBarStyle { .default }
|
|
41
|
+
override var preferredStatusBarStyle: UIStatusBarStyle { statusBarStyle ?? .default }
|
|
42
|
+
|
|
43
|
+
/// appearance.setThemeColor: icons that read on the color the page paints under the bar; nil follows the appearance.
|
|
44
|
+
var statusBarStyle: UIStatusBarStyle? {
|
|
45
|
+
didSet { if statusBarStyle != oldValue { setNeedsStatusBarAppearanceUpdate() } }
|
|
46
|
+
}
|
|
42
47
|
|
|
43
48
|
/// screen-orientation plugin: the orientations the page locked to (already intersected with
|
|
44
49
|
/// Info.plist, or UIKit throws); nil = the app's default set.
|
|
@@ -7,7 +7,7 @@ import { pluginBindings } from "./codegen.ts";
|
|
|
7
7
|
import { CliError } from "./log.ts";
|
|
8
8
|
import { mergePlist } from "./nativeconfig.ts";
|
|
9
9
|
import type { PlistValue } from "./plist.ts";
|
|
10
|
-
import type { AndroidManifest, IosManifest, NativeSubset, ResolvedPlugin } from "./project.ts";
|
|
10
|
+
import type { AndroidManifest, DesktopManifest, IosManifest, NativeSubset, ResolvedPlugin } from "./project.ts";
|
|
11
11
|
|
|
12
12
|
export type NativePlatform = "macos" | "windows" | "linux" | "ios" | "android";
|
|
13
13
|
|
|
@@ -16,7 +16,8 @@ export function pluginDecls(plugins: ResolvedPlugin[], platform: NativePlatform)
|
|
|
16
16
|
const decls: Record<string, PluginDecl> = {};
|
|
17
17
|
for (const { manifest } of plugins) {
|
|
18
18
|
|
|
19
|
-
const
|
|
19
|
+
const mobile = platform === "ios" || platform === "android";
|
|
20
|
+
const entry = mobile ? manifest[platform] : manifest.desktop;
|
|
20
21
|
if (entry === undefined || entry === null) continue;
|
|
21
22
|
if (entry === "web") {
|
|
22
23
|
if (manifest.web) decls[manifest.id] = "web";
|
|
@@ -25,8 +26,9 @@ export function pluginDecls(plugins: ResolvedPlugin[], platform: NativePlatform)
|
|
|
25
26
|
const subset: NativeSubset = typeof entry === "string" ? {} : entry;
|
|
26
27
|
const events = subset.events ?? manifest.events;
|
|
27
28
|
const coalesce = (manifest.coalesce ?? []).filter((e) => events.includes(e));
|
|
29
|
+
const lacks = mobile ? [] : ((subset as DesktopManifest).unsupported?.[platform] ?? []);
|
|
28
30
|
decls[manifest.id] = {
|
|
29
|
-
methods: subset.methods ?? manifest.methods,
|
|
31
|
+
methods: (subset.methods ?? manifest.methods).filter((m) => !lacks.includes(m)),
|
|
30
32
|
events,
|
|
31
33
|
...(subset.web && manifest.web ? { web: true as const } : {}),
|
|
32
34
|
...(coalesce.length ? { coalesce } : {}),
|
|
@@ -406,9 +406,14 @@ export interface AndroidManifest extends NativeSubset {
|
|
|
406
406
|
minSdk?: number;
|
|
407
407
|
}
|
|
408
408
|
|
|
409
|
+
export const DESKTOP_OSES = ["macos", "windows", "linux"] as const;
|
|
410
|
+
export type DesktopOs = (typeof DESKTOP_OSES)[number];
|
|
411
|
+
|
|
409
412
|
/** Desktop Bun module that implements only some methods (the rest are UNSUPPORTED, or web with `web: true`). */
|
|
410
413
|
export interface DesktopManifest extends NativeSubset {
|
|
411
414
|
module: string;
|
|
415
|
+
/** The methods one desktop OS lacks: left out of that OS's declaration, so `isSupported()` is false there only. */
|
|
416
|
+
unsupported?: Partial<Record<DesktopOs, string[]>>;
|
|
412
417
|
}
|
|
413
418
|
|
|
414
419
|
export interface PluginManifest {
|
|
@@ -536,6 +541,25 @@ export function resolvePlugins(appDir: string, specs: string[], resolveFrom = ap
|
|
|
536
541
|
}
|
|
537
542
|
if (!Array.isArray(manifest.methods) || !Array.isArray(manifest.events ?? []))
|
|
538
543
|
throw new CliError(`plugin ${spec}: methods and events must be arrays`);
|
|
544
|
+
const desktop = typeof manifest.desktop === "object" && manifest.desktop ? manifest.desktop : undefined;
|
|
545
|
+
if (desktop?.unsupported !== undefined) {
|
|
546
|
+
const declared = desktop.methods ?? manifest.methods;
|
|
547
|
+
const lists = desktop.unsupported as Record<string, unknown> | null;
|
|
548
|
+
const valid =
|
|
549
|
+
!!lists &&
|
|
550
|
+
typeof lists === "object" &&
|
|
551
|
+
!Array.isArray(lists) &&
|
|
552
|
+
Object.entries(lists).every(
|
|
553
|
+
([os, names]) =>
|
|
554
|
+
(DESKTOP_OSES as readonly string[]).includes(os) &&
|
|
555
|
+
Array.isArray(names) &&
|
|
556
|
+
names.every((name) => typeof name === "string" && declared.includes(name)),
|
|
557
|
+
);
|
|
558
|
+
if (!valid)
|
|
559
|
+
throw new CliError(
|
|
560
|
+
`plugin ${spec}: desktop.unsupported must map macos, windows or linux to methods of its desktop entry`,
|
|
561
|
+
);
|
|
562
|
+
}
|
|
539
563
|
manifest.events ??= [];
|
|
540
564
|
|
|
541
565
|
for (const [kind, names] of [
|
|
@@ -608,7 +632,7 @@ const MANIFEST_KEYS: Record<string, readonly string[]> = {
|
|
|
608
632
|
"maven",
|
|
609
633
|
"minSdk",
|
|
610
634
|
],
|
|
611
|
-
desktop: ["methods", "events", "web", "module"],
|
|
635
|
+
desktop: ["methods", "events", "web", "module", "unsupported"],
|
|
612
636
|
macos: ["infoPlist"],
|
|
613
637
|
};
|
|
614
638
|
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
|
+
import { appLauncher } from "./relaunch.ts";
|
|
6
7
|
|
|
7
8
|
type Env = Record<string, string | undefined>;
|
|
8
9
|
type Runner = (argv: string[]) => Promise<{ code: number; stdout: string }>;
|
|
@@ -158,8 +159,7 @@ export async function registerDeepLinks(
|
|
|
158
159
|
const platform = options.platform ?? process.platform;
|
|
159
160
|
if (!schemes.length || (platform !== "win32" && platform !== "linux")) return;
|
|
160
161
|
const env = options.env ?? process.env;
|
|
161
|
-
|
|
162
|
-
const exe = options.exe ?? (env.APPIMAGE || process.execPath);
|
|
162
|
+
const exe = options.exe ?? appLauncher(env);
|
|
163
163
|
const runner = options.run ?? run;
|
|
164
164
|
if (platform === "win32") await registerWindows(app, exe, schemes, runner);
|
|
165
165
|
else await registerLinux(app, exe, schemes, { env, home: options.home ?? homedir(), runner, icon: options.icon });
|
|
@@ -14,7 +14,7 @@ import { cstr, FRAME_EVENT, FRAME_HEADER, FRAME_IPC, openNative, resolvePaths }
|
|
|
14
14
|
import { createLifecycle } from "./lifecycle.ts";
|
|
15
15
|
import { appDataDir, appLocalDataDir, reservedDirs, serverDataDir } from "./paths.ts";
|
|
16
16
|
import { type DesktopPlugin, useShellOpenLimit } from "./plugin.ts";
|
|
17
|
-
import { nextRelaunchDelay, relaunchAfterExit } from "./relaunch.ts";
|
|
17
|
+
import { appLauncher, nextRelaunchDelay, relaunchAfterExit } from "./relaunch.ts";
|
|
18
18
|
import { createSecretStore } from "./secretStore.ts";
|
|
19
19
|
import {
|
|
20
20
|
createDesktopServer,
|
|
@@ -350,7 +350,7 @@ export function startHost(plugins: DesktopPlugin[]): void {
|
|
|
350
350
|
void lifecycle.quit(1);
|
|
351
351
|
return;
|
|
352
352
|
}
|
|
353
|
-
relaunchAfterExit(
|
|
353
|
+
relaunchAfterExit(appLauncher(), [], { delayMs })
|
|
354
354
|
.then(() => lifecycle.quit(0))
|
|
355
355
|
.catch((error: unknown) => console.error("[akan-native] cannot relaunch the app", error));
|
|
356
356
|
};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
4
|
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
6
|
-
import { dirname } from "node:path";
|
|
6
|
+
import { dirname, resolve } from "node:path";
|
|
7
7
|
|
|
8
8
|
export interface RelaunchOptions {
|
|
9
9
|
/** How long the helper waits after this process exited before it starts the app. */
|
|
@@ -48,6 +48,12 @@ export function recoveryCommand(script: string): string | null {
|
|
|
48
48
|
return command.length <= 260 ? command : null;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
export const appLauncher = (env: NodeJS.ProcessEnv = process.env, exe = process.execPath): string =>
|
|
52
|
+
env.APPIMAGE && env.APPDIR && exe.startsWith(`${resolve(env.APPDIR)}/`) ? env.APPIMAGE : exe;
|
|
53
|
+
|
|
54
|
+
const NOT_INHERITED = new Set(["AKAN_NATIVE_QUIT_ON_STDIN", "APPDIR", "APPIMAGE", "ARGV0", "OWD"]);
|
|
55
|
+
const inheritedEnv = () => Object.fromEntries(Object.entries(process.env).filter(([key]) => !NOT_INHERITED.has(key)));
|
|
56
|
+
|
|
51
57
|
let started: Promise<void> | null = null;
|
|
52
58
|
|
|
53
59
|
/**
|
|
@@ -82,8 +88,7 @@ function startHelper(
|
|
|
82
88
|
recover: RelaunchOptions["recover"],
|
|
83
89
|
start: boolean,
|
|
84
90
|
): Promise<void> {
|
|
85
|
-
|
|
86
|
-
const { AKAN_NATIVE_QUIT_ON_STDIN: _cli, ...inherited } = process.env;
|
|
91
|
+
const inherited = inheritedEnv();
|
|
87
92
|
const delay = (delayMs / 1000).toFixed(3);
|
|
88
93
|
if (process.platform !== "win32") {
|
|
89
94
|
const done: [string, string][] = [];
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
linkClaimed,
|
|
9
9
|
type QuitReason,
|
|
10
10
|
} from "../../../packages/desktop/src/plugin.ts";
|
|
11
|
-
import { relaunchAfterExit } from "../../../packages/desktop/src/relaunch.ts";
|
|
11
|
+
import { appLauncher, relaunchAfterExit } from "../../../packages/desktop/src/relaunch.ts";
|
|
12
12
|
import type { AppApi, AppEvents } from "./index.ts";
|
|
13
13
|
|
|
14
14
|
const quitVeto = createPageVeto<{ reason: QuitReason }>();
|
|
@@ -47,7 +47,7 @@ export default defineDesktopPlugin<AppApi, AppEvents>({
|
|
|
47
47
|
setTimeout(() => ctx.quit(0), 50);
|
|
48
48
|
},
|
|
49
49
|
relaunch: async (_args, ctx) => {
|
|
50
|
-
await relaunchAfterExit(
|
|
50
|
+
await relaunchAfterExit(appLauncher());
|
|
51
51
|
setTimeout(() => ctx.quit(0), 50);
|
|
52
52
|
},
|
|
53
53
|
answerBeforeQuit: (args, ctx) => quitVeto.answer(args, ctx.window),
|
|
@@ -3,6 +3,7 @@ package com.akanjs.plugins.appearance
|
|
|
3
3
|
import android.app.UiModeManager
|
|
4
4
|
import android.content.Context
|
|
5
5
|
import android.content.res.Configuration
|
|
6
|
+
import android.graphics.Color
|
|
6
7
|
import android.os.Build
|
|
7
8
|
import android.os.Handler
|
|
8
9
|
import android.os.Looper
|
|
@@ -26,6 +27,7 @@ import com.akanjs.runtime.AkanNativeVoidReply
|
|
|
26
27
|
* - mode: the fixed setting, or the configuration's night bit when following the system.
|
|
27
28
|
* - change: onConfigurationChanged, plus a check shortly after set(), since a setting that keeps
|
|
28
29
|
* the drawn scheme (system dark, set dark) changes no configuration. Duplicates are filtered.
|
|
30
|
+
* - setThemeColor: the shell's status bar icons, until the page's document ends.
|
|
29
31
|
* - Below API 31 there is no per-app night mode: the setting goes to AkanNativeCompat.storeNightMode, the
|
|
30
32
|
* shell applies it as an override configuration when the activity starts, and set() recreates the
|
|
31
33
|
* activity when the drawn scheme changes, so the page reloads there.
|
|
@@ -77,6 +79,16 @@ class AppearancePlugin(private val context: AkanNativePluginContext) : Appearanc
|
|
|
77
79
|
if (next != drawn) main.post { activity.recreate() }
|
|
78
80
|
}
|
|
79
81
|
|
|
82
|
+
override fun setThemeColor(args: AppearanceSetThemeColorArgs, reply: AkanNativeVoidReply) {
|
|
83
|
+
val hex = args.color
|
|
84
|
+
if (hex != null && !HEX.matches(hex)) return reply.reject(AkanNativeErrorCode.INVALID_ARGS, "color must be #rrggbb (got $hex)")
|
|
85
|
+
context.setThemeColor(hex?.let(Color::parseColor))
|
|
86
|
+
reply.resolve()
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The next page starts from the background color, whether or not it names a theme color. */
|
|
90
|
+
override fun documentEnded(document: String) = context.setThemeColor(null)
|
|
91
|
+
|
|
80
92
|
private fun isNight(config: Configuration) = (config.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
|
|
81
93
|
|
|
82
94
|
private object Api31 {
|
|
@@ -129,5 +141,6 @@ class AppearancePlugin(private val context: AkanNativePluginContext) : Appearanc
|
|
|
129
141
|
private companion object {
|
|
130
142
|
const val KEY = "setting"
|
|
131
143
|
const val SETTLE_MS = 500L
|
|
144
|
+
val HEX = Regex("#[0-9a-fA-F]{6}")
|
|
132
145
|
}
|
|
133
146
|
}
|
|
@@ -10,6 +10,7 @@ import UIKit
|
|
|
10
10
|
/// - change: a trait registration on the web view sees both system switches and set(). iOS flips
|
|
11
11
|
/// the style of a backgrounded app twice to snapshot both appearances, so changes are only
|
|
12
12
|
/// reported while not in the background, and checked again on the way back to the foreground.
|
|
13
|
+
/// - setThemeColor: the view controller's status bar style, until the page's document ends.
|
|
13
14
|
/// Arguments arrive decoded and checked by the generated AppearancePluginSpec (PL-10).
|
|
14
15
|
final class AppearancePlugin: AppearancePluginSpec {
|
|
15
16
|
static let id = "appearance"
|
|
@@ -47,6 +48,32 @@ final class AppearancePlugin: AppearancePluginSpec {
|
|
|
47
48
|
report()
|
|
48
49
|
}
|
|
49
50
|
|
|
51
|
+
func setThemeColor(_ args: AppearanceSetThemeColorArgs, _ reply: AkanNativeReply<Void>) {
|
|
52
|
+
var style: UIStatusBarStyle?
|
|
53
|
+
if let color = args.color {
|
|
54
|
+
guard let light = Self.isLight(hex: color) else { return reply.reject(.invalidArgs, "color must be #rrggbb (got \(color))") }
|
|
55
|
+
style = light ? .darkContent : .lightContent
|
|
56
|
+
}
|
|
57
|
+
(context.viewController as? AkanNativeViewController)?.statusBarStyle = style
|
|
58
|
+
reply.resolve()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/// The next page starts from the appearance, whether or not it names a theme color.
|
|
62
|
+
func documentEnded(_ document: String) {
|
|
63
|
+
(context.viewController as? AkanNativeViewController)?.statusBarStyle = nil
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//? Android's Color.luminance (sRGB relative luminance) over 0.5, so both shells pick the same icons for one color.
|
|
67
|
+
static func isLight(hex: String) -> Bool? {
|
|
68
|
+
let digits = hex.dropFirst()
|
|
69
|
+
guard hex.first == "#", digits.count == 6, digits.allSatisfy(\.isHexDigit), let rgb = UInt32(digits, radix: 16) else { return nil }
|
|
70
|
+
let linear = { (byte: UInt32) -> Double in
|
|
71
|
+
let c = Double(byte & 0xff) / 255
|
|
72
|
+
return c <= 0.04045 ? c / 12.92 : pow((c + 0.055) / 1.055, 2.4)
|
|
73
|
+
}
|
|
74
|
+
return 0.2126 * linear(rgb >> 16) + 0.7152 * linear(rgb >> 8) + 0.0722 * linear(rgb) > 0.5
|
|
75
|
+
}
|
|
76
|
+
|
|
50
77
|
func startListening(_ event: String) {
|
|
51
78
|
guard event == "change", registration == nil, let webView = context.webView else { return }
|
|
52
79
|
last = state()
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "appearance",
|
|
3
3
|
"apiVersion": 1,
|
|
4
|
-
"methods": ["get", "set"],
|
|
4
|
+
"methods": ["get", "set", "setThemeColor"],
|
|
5
5
|
"events": ["change"],
|
|
6
6
|
"codegen": true,
|
|
7
7
|
"web": "./src/web.ts",
|
|
8
|
-
"desktop": "./src/desktop.ts",
|
|
8
|
+
"desktop": { "module": "./src/desktop.ts", "methods": ["get", "set"] },
|
|
9
9
|
"ios": {
|
|
10
10
|
"sources": ["ios/*.swift"],
|
|
11
11
|
"class": "AppearancePlugin",
|
|
@@ -26,6 +26,13 @@ export interface AppearanceApi {
|
|
|
26
26
|
* available on the web (UNSUPPORTED): a page cannot change `prefers-color-scheme`.
|
|
27
27
|
*/
|
|
28
28
|
set(args: { mode: AppearanceSetting }): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* iOS and Android: the color the page paints under the status bar, as `#rrggbb`. The bar's icons turn dark on a light
|
|
31
|
+
* color and light on a dark one; null hands them back to the shell (the appearance on iOS, the app's background color
|
|
32
|
+
* on Android). The page keeps drawing under the bar, so the bar gets no background of its own, and the setting ends
|
|
33
|
+
* with the page's document. Not available on the web or the desktop (UNSUPPORTED).
|
|
34
|
+
*/
|
|
35
|
+
setThemeColor(args: { color: string | null }): Promise<void>;
|
|
29
36
|
}
|
|
30
37
|
|
|
31
38
|
export interface AppearanceEvents {
|
|
@@ -34,7 +41,7 @@ export interface AppearanceEvents {
|
|
|
34
41
|
}
|
|
35
42
|
|
|
36
43
|
export const appearance = definePlugin<AppearanceApi, AppearanceEvents>("appearance", {
|
|
37
|
-
methods: ["get", "set"],
|
|
44
|
+
methods: ["get", "set", "setThemeColor"],
|
|
38
45
|
events: ["change"],
|
|
39
46
|
web,
|
|
40
47
|
});
|
|
@@ -5,6 +5,7 @@ import { homedir } from "node:os";
|
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { AkanNativeError } from "../../../packages/core/src/index.ts";
|
|
7
7
|
import { type DesktopContext, defineDesktopPlugin } from "../../../packages/desktop/src/plugin.ts";
|
|
8
|
+
import { appLauncher } from "../../../packages/desktop/src/relaunch.ts";
|
|
8
9
|
import type { AutostartApi, AutostartState, AutostartStatus } from "./index.ts";
|
|
9
10
|
|
|
10
11
|
export interface ShellError {
|
|
@@ -111,7 +112,7 @@ export function entryStatus(text: string | null): AutostartStatus {
|
|
|
111
112
|
/** `executable`: the file the entry starts; an AppImage's mount point changes at every start, $APPIMAGE does not. */
|
|
112
113
|
export function linuxAutostart(
|
|
113
114
|
dir: () => string = () => autostartDir(),
|
|
114
|
-
executable: () => string = () =>
|
|
115
|
+
executable: () => string = () => appLauncher(),
|
|
115
116
|
) {
|
|
116
117
|
const file = (ctx: DesktopContext) => join(dir(), `${ctx.app.id}.desktop`);
|
|
117
118
|
const read = (ctx: DesktopContext) => (existsSync(file(ctx)) ? readFileSync(file(ctx), "utf8") : null);
|
|
@@ -17,7 +17,10 @@
|
|
|
17
17
|
],
|
|
18
18
|
"events": ["load", "loadFailed", "gone", "consoleMessage"],
|
|
19
19
|
"web": null,
|
|
20
|
-
"desktop":
|
|
20
|
+
"desktop": {
|
|
21
|
+
"module": "./src/desktop.ts",
|
|
22
|
+
"unsupported": { "macos": ["sendKey", "setMuted", "capture"] }
|
|
23
|
+
},
|
|
21
24
|
"ios": null,
|
|
22
25
|
"android": null
|
|
23
26
|
}
|
|
@@ -10,8 +10,10 @@ import { definePlugin, type FileRef } from "../../../packages/core/src/index.ts"
|
|
|
10
10
|
* permissions and links another program would open (`mailto:`, a custom scheme) are refused. Listing the plugin in
|
|
11
11
|
* `native.plugins` is what lets an app open one.
|
|
12
12
|
*
|
|
13
|
-
* Windows has every method.
|
|
14
|
-
*
|
|
13
|
+
* Windows has every method. Linux has every method and sends no `consoleMessage`; there the visible view shown last
|
|
14
|
+
* also holds the keyboard focus inside its window, so the user's own keys reach it, until a click on the page takes the
|
|
15
|
+
* focus or the view is hidden or closed. macOS (14 or later, for its separate profile) has all but `sendKey`,
|
|
16
|
+
* `setMuted` and `capture`, and sends no `loadFailed` or `consoleMessage`. iOS and Android: UNSUPPORTED.
|
|
15
17
|
*/
|
|
16
18
|
export type ExternalViewBounds = "fill" | { x: number; y: number; width: number; height: number };
|
|
17
19
|
|
|
@@ -30,7 +32,7 @@ export interface ExternalViewOpenOptions {
|
|
|
30
32
|
* with `evaluate`. It may not declare `__akanTopOnly`, and an empty one registers nothing.
|
|
31
33
|
*/
|
|
32
34
|
initScript?: string;
|
|
33
|
-
/**
|
|
35
|
+
/** macOS refuses `true` as UNSUPPORTED. */
|
|
34
36
|
muted?: boolean;
|
|
35
37
|
/** Media plays with sound without a gesture first (default true): nobody taps a signage screen. */
|
|
36
38
|
autoplay?: boolean;
|
|
@@ -53,7 +55,7 @@ export interface ExternalViewApi {
|
|
|
53
55
|
/**
|
|
54
56
|
* Opens the view, or brings an open one with this id to these options (a page that mounts again finds it). Another
|
|
55
57
|
* `initScript` builds the view again and loads its page anew, as does another `console` on Windows and another
|
|
56
|
-
* `autoplay` on macOS; Windows refuses another `autoplay` as UNSUPPORTED, before anything is built.
|
|
58
|
+
* `autoplay` on macOS and Linux; Windows refuses another `autoplay` as UNSUPPORTED, before anything is built.
|
|
57
59
|
*/
|
|
58
60
|
open(args: ExternalViewOpenOptions): Promise<ExternalViewState>;
|
|
59
61
|
/** Rejects NOT_ALLOWED for a URL on none of its `allowOrigins`. */
|
|
@@ -65,18 +67,23 @@ export interface ExternalViewApi {
|
|
|
65
67
|
setBounds(args: { id: string; bounds: ExternalViewBounds }): Promise<void>;
|
|
66
68
|
/**
|
|
67
69
|
* The script's completion value as JSON has it (a Date as its ISO string, a lone surrogate as U+FFFD), and `null`
|
|
68
|
-
* for undefined, NaN, a cycle or an exception: catch it in the script. macOS
|
|
69
|
-
* nesting too. A promise is not awaited. CANCELLED: a close or a rebuild of the view cut the call off. TIMEOUT: no
|
|
70
|
+
* for undefined, NaN, a cycle or an exception: catch it in the script. macOS and Linux answer `null` past 128 levels
|
|
71
|
+
* of nesting too. A promise is not awaited. CANCELLED: a close or a rebuild of the view cut the call off. TIMEOUT: no
|
|
70
72
|
* answer within 30 s, as from a page busy in a loop; `sendKey` and `capture` time out the same way.
|
|
71
73
|
*/
|
|
72
74
|
evaluate(args: { id: string; script: string }): Promise<{ value: unknown }>;
|
|
73
|
-
/**
|
|
75
|
+
/**
|
|
76
|
+
* A trusted key press (`{ key: "z", code: "KeyZ" }`), whether or not the view has the focus. Not on macOS; on Linux
|
|
77
|
+
* UNSUPPORTED while the view's window is hidden. On Linux a Tab past the page's last element takes the page's focus
|
|
78
|
+
* out of it, as in a browser, but the keyboard stays with the view or the app's page, whichever had it; `Dead` is
|
|
79
|
+
* INVALID_ARGS there, since GTK's input method would compose it with the next key into one character.
|
|
80
|
+
*/
|
|
74
81
|
sendKey(args: { id: string; key: string; code: string }): Promise<void>;
|
|
75
|
-
/** The view's own sound only; the system volume is the volume plugin's.
|
|
82
|
+
/** The view's own sound only; the system volume is the volume plugin's. Not on macOS. */
|
|
76
83
|
setMuted(args: { id: string; muted: boolean }): Promise<void>;
|
|
77
84
|
/** Clears the view's cookies, storage and cache; the app's own stay. */
|
|
78
85
|
clearData(args: { id: string }): Promise<void>;
|
|
79
|
-
/** A PNG of the view's content (not the screen), kept until its next capture or the next launch.
|
|
86
|
+
/** A PNG of the view's content (not the screen), kept until its next capture or the next launch. Not on macOS. */
|
|
80
87
|
capture(args: { id: string }): Promise<FileRef & { width?: number; height?: number }>;
|
|
81
88
|
}
|
|
82
89
|
|
|
@@ -85,13 +92,15 @@ export interface ExternalViewEvents {
|
|
|
85
92
|
/**
|
|
86
93
|
* A navigation that failed. `errorCode`: `http<status>` for a server's 4xx or 5xx page, else WebView2's own
|
|
87
94
|
* (`hostNameNotResolved`, `cannotConnect`, `timeout`, `certificate`, `disconnected`, …; a refused connection is
|
|
88
|
-
* `unknown`).
|
|
95
|
+
* `unknown`). Linux names the same failures by those names (a refused connection is `cannotConnect`) and any other
|
|
96
|
+
* `unknown`. Not on macOS.
|
|
89
97
|
*/
|
|
90
98
|
loadFailed: { id: string; url: string; errorCode: string };
|
|
91
99
|
/**
|
|
92
|
-
* Its web process ended (`reason`: `crashed`, `unresponsive` or `browserExited` on Windows, `terminated` on macOS
|
|
93
|
-
* the view loads its page again by itself, sooner the first times, and an end
|
|
94
|
-
* again. `rebuildFailed`: after its browser exited the view could not be built
|
|
100
|
+
* Its web process ended (`reason`: `crashed`, `unresponsive` or `browserExited` on Windows, `terminated` on macOS,
|
|
101
|
+
* `crashed`, `killed` or `oom` on Linux); the view loads its page again by itself, sooner the first times, and an end
|
|
102
|
+
* while that waits is not reported again. `rebuildFailed`: after its browser exited the view could not be built
|
|
103
|
+
* again, and is closed; open it again.
|
|
95
104
|
*/
|
|
96
105
|
gone: { id: string; reason: string; restarts: number };
|
|
97
106
|
/** `dropped`: messages left out before this one, past the rate cap. Windows only. */
|
|
@@ -59,8 +59,10 @@ export function tokenSid(query: (info: Uint8Array) => boolean = queryTokenUser):
|
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
61
|
* sun_path is 104 bytes on macOS, so the name is a short hash, not the app id. Windows pipe names
|
|
62
|
-
* are one namespace for the whole PC, so the user is part of the hash there
|
|
63
|
-
*
|
|
62
|
+
* are one namespace for the whole PC, so the user is part of the hash there. The hash is no secret:
|
|
63
|
+
* another account can work the name out and create the pipe first. The pipe's default security only
|
|
64
|
+
* keeps others from writing to a pipe this account created, so a launch reads who owns the pipe
|
|
65
|
+
* before it sends (claimPipe).
|
|
64
66
|
*/
|
|
65
67
|
export function socketPath(
|
|
66
68
|
appId: string,
|
|
@@ -81,6 +83,79 @@ export function socketPath(
|
|
|
81
83
|
/** A named pipe disappears with its server: there is no file to protect or clean up. */
|
|
82
84
|
const isPipe = (path: string) => path.startsWith("\\\\.\\pipe\\");
|
|
83
85
|
|
|
86
|
+
const GENERIC_READ = 0x80000000;
|
|
87
|
+
const OPEN_EXISTING = 3;
|
|
88
|
+
|
|
89
|
+
const SECURITY_SQOS_PRESENT = 0x00100000;
|
|
90
|
+
const OWNER_SECURITY_INFORMATION = 1;
|
|
91
|
+
const SE_SELF_RELATIVE = 0x8000;
|
|
92
|
+
const INVALID_HANDLE_VALUE = -1n;
|
|
93
|
+
|
|
94
|
+
const ADMINISTRATORS = "S-1-5-32-544";
|
|
95
|
+
|
|
96
|
+
export interface PipeCalls {
|
|
97
|
+
open(name: Uint8Array): bigint;
|
|
98
|
+
security(handle: bigint, descriptor: Uint8Array): boolean;
|
|
99
|
+
close(handle: bigint): void;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface HeldPipe {
|
|
103
|
+
owner: string | null;
|
|
104
|
+
close(): void;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let win32: PipeCalls | null = null;
|
|
108
|
+
|
|
109
|
+
const win32PipeCalls = (): PipeCalls => {
|
|
110
|
+
if (win32) return win32;
|
|
111
|
+
const kernel = dlopen("kernel32.dll", {
|
|
112
|
+
CreateFileW: {
|
|
113
|
+
args: [FFIType.ptr, FFIType.u32, FFIType.u32, FFIType.ptr, FFIType.u32, FFIType.u32, FFIType.i64],
|
|
114
|
+
returns: FFIType.i64,
|
|
115
|
+
},
|
|
116
|
+
CloseHandle: { args: [FFIType.i64], returns: FFIType.i32 },
|
|
117
|
+
}).symbols;
|
|
118
|
+
const advapi = dlopen("advapi32.dll", {
|
|
119
|
+
GetKernelObjectSecurity: {
|
|
120
|
+
args: [FFIType.i64, FFIType.u32, FFIType.ptr, FFIType.u32, FFIType.ptr],
|
|
121
|
+
returns: FFIType.i32,
|
|
122
|
+
},
|
|
123
|
+
}).symbols;
|
|
124
|
+
win32 = {
|
|
125
|
+
|
|
126
|
+
open: (name) => kernel.CreateFileW(name, GENERIC_READ, 0, null, OPEN_EXISTING, SECURITY_SQOS_PRESENT, 0),
|
|
127
|
+
security: (handle, descriptor) =>
|
|
128
|
+
advapi.GetKernelObjectSecurity(
|
|
129
|
+
handle,
|
|
130
|
+
OWNER_SECURITY_INFORMATION,
|
|
131
|
+
descriptor,
|
|
132
|
+
descriptor.length,
|
|
133
|
+
new Uint32Array(1),
|
|
134
|
+
) !== 0,
|
|
135
|
+
close: (handle) => void kernel.CloseHandle(handle),
|
|
136
|
+
};
|
|
137
|
+
return win32;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export function heldPipe(path: string, calls?: PipeCalls): HeldPipe | null {
|
|
141
|
+
try {
|
|
142
|
+
const pipe = calls ?? win32PipeCalls();
|
|
143
|
+
const handle = pipe.open(Buffer.from(`${path}\0`, "utf16le"));
|
|
144
|
+
if (handle === INVALID_HANDLE_VALUE) return null;
|
|
145
|
+
const descriptor = new Uint8Array(new ArrayBuffer(256));
|
|
146
|
+
let owner: string | null = null;
|
|
147
|
+
if (pipe.security(handle, descriptor)) {
|
|
148
|
+
|
|
149
|
+
const view = new DataView(descriptor.buffer);
|
|
150
|
+
const at = view.getUint32(4, true);
|
|
151
|
+
if (view.getUint16(2, true) & SE_SELF_RELATIVE && at >= 20) owner = sidText(descriptor.subarray(at));
|
|
152
|
+
}
|
|
153
|
+
return { owner, close: () => pipe.close(handle) };
|
|
154
|
+
} catch {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
84
159
|
export function encodeMessage(message: SecondInstance): string {
|
|
85
160
|
return `${JSON.stringify({ format: FORMAT, args: message.args, cwd: message.cwd })}\n`;
|
|
86
161
|
}
|
|
@@ -214,35 +289,49 @@ export async function claim(
|
|
|
214
289
|
onMessage: (m: SecondInstance) => void,
|
|
215
290
|
timeoutMs = 1500,
|
|
216
291
|
): Promise<Claim> {
|
|
217
|
-
|
|
218
|
-
|
|
292
|
+
return isPipe(path)
|
|
293
|
+
? claimPipe(path, message, onMessage, timeoutMs)
|
|
294
|
+
: claimLocked(path, message, onMessage, timeoutMs);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export async function claimPipe(
|
|
298
|
+
path: string,
|
|
299
|
+
message: SecondInstance,
|
|
300
|
+
onMessage: (m: SecondInstance) => void,
|
|
301
|
+
timeoutMs: number,
|
|
302
|
+
hold: (path: string) => HeldPipe | null = heldPipe,
|
|
303
|
+
account: () => string | null = tokenSid,
|
|
304
|
+
): Promise<Claim> {
|
|
305
|
+
const deadline = Date.now() + timeoutMs;
|
|
306
|
+
for (;;) {
|
|
219
307
|
try {
|
|
220
308
|
const server = await listen(path, onMessage);
|
|
221
|
-
|
|
222
|
-
if (!isPipe(path)) chmodSync(path, 0o600);
|
|
223
|
-
} catch {}
|
|
224
|
-
return {
|
|
225
|
-
kind: "primary",
|
|
226
|
-
close() {
|
|
227
|
-
server.close();
|
|
228
|
-
if (!isPipe(path)) rmSync(path, { force: true });
|
|
229
|
-
},
|
|
230
|
-
};
|
|
309
|
+
return { kind: "primary", close: () => void server.close() };
|
|
231
310
|
} catch (error) {
|
|
232
311
|
if (errno(error) !== "EADDRINUSE") return { kind: "failed", error: error as Error };
|
|
233
312
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
313
|
+
const held = hold(path);
|
|
314
|
+
if (held) {
|
|
315
|
+
try {
|
|
316
|
+
if (held.owner === null || (held.owner !== account() && held.owner !== ADMINISTRATORS)) {
|
|
317
|
+
const owner = held.owner ?? "an owner that cannot be read";
|
|
318
|
+
return { kind: "failed", error: new Error(`${path} belongs to another account (${owner})`) };
|
|
319
|
+
}
|
|
320
|
+
const heard = await send(path, message, timeoutMs);
|
|
321
|
+
if (!heard) console.warn("[akan-native] single-instance: the running instance did not answer; exiting anyway");
|
|
322
|
+
return { kind: "forwarded" };
|
|
323
|
+
} catch (error) {
|
|
324
|
+
if (errno(error) !== "ENOENT") return { kind: "failed", error: error as Error };
|
|
325
|
+
} finally {
|
|
326
|
+
held.close();
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (Date.now() >= deadline) {
|
|
331
|
+
return { kind: "failed", error: new Error(`${path} is taken and cannot be opened to see whose it is`) };
|
|
243
332
|
}
|
|
333
|
+
await Bun.sleep(20);
|
|
244
334
|
}
|
|
245
|
-
return { kind: "failed", error: new Error(`could not claim ${path}`) };
|
|
246
335
|
}
|
|
247
336
|
|
|
248
337
|
/** The lock and socket need a folder of this user's alone: another user's could block the app or read its arguments. */
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AgenticSurface } from "./AgenticSurface";
|
|
2
|
+
import { ToolRunner, type ToolRunnerHost } from "./ToolRunner";
|
|
3
|
+
import type { PublishedTool, SurfaceView, ToolCallRequest, ToolCallResult } from "./types";
|
|
4
|
+
|
|
5
|
+
/** `readOnly` is always `false`: a screen tool declares no such flag, so a server loop counts every one as a write. */
|
|
6
|
+
export interface AgentClientToolDefinition extends PublishedTool {
|
|
7
|
+
readOnly: false;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A screen's tools lent to an agent loop that runs on the server: `list()` is what that loop takes as its client
|
|
12
|
+
* tools, and `run(call)` answers a call it parked. A call goes through the same `ToolRunner` as the in-page chat, so a
|
|
13
|
+
* `confirm` still asks through `host.approve` (refused without one), a card needs `host.card`, and the answer is
|
|
14
|
+
* clipped and fenced as the chat's would be.
|
|
15
|
+
*/
|
|
16
|
+
export class AgentClientTools {
|
|
17
|
+
readonly #surface: SurfaceView;
|
|
18
|
+
readonly #runner: ToolRunner;
|
|
19
|
+
|
|
20
|
+
constructor(surface: SurfaceView = AgenticSurface.shared, host: ToolRunnerHost = {}) {
|
|
21
|
+
this.#surface = surface;
|
|
22
|
+
this.#runner = new ToolRunner(surface, host);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
list(): AgentClientToolDefinition[] {
|
|
26
|
+
return this.#surface.snapshot().tools.map((tool) => ({ ...tool, readOnly: false }));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Never throws: a tool no longer on the screen, a refusal and a failure all come back as the result's `error`. */
|
|
30
|
+
async run(call: ToolCallRequest, signal: AbortSignal = new AbortController().signal): Promise<ToolCallResult> {
|
|
31
|
+
return await this.#runner.run(call, signal);
|
|
32
|
+
}
|
|
33
|
+
}
|