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
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import type { PromiseOrObject } from "akanjs/base";
|
|
2
|
+
import type { AgentTool } from "../predefinedAdaptor/agentTools.adaptor";
|
|
3
|
+
import type {
|
|
4
|
+
AgentWireContext,
|
|
5
|
+
AgentWireMessage,
|
|
6
|
+
AgentWireToolCall,
|
|
7
|
+
AgentWireToolResult,
|
|
8
|
+
LlmUsage,
|
|
9
|
+
} from "../predefinedAdaptor/llm.adaptor";
|
|
10
|
+
|
|
11
|
+
export type AgentLoopApproval = "allow" | "defer" | { deny: string };
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* `tainted`: a result `untrusted` marked, with no `untrusted` any result a tool returned, a client tool's answer or a
|
|
15
|
+
* remote's result was read, or a remote was opened, earlier in this run or in the messages it resumed from. `client`:
|
|
16
|
+
* the call is to a tool of `clientTools`, whose name may be that of an endpoint this run does not list. `remote`: the
|
|
17
|
+
* call goes to that entry of `remotes`, not to this server.
|
|
18
|
+
*/
|
|
19
|
+
export type AgentLoopApprove = (
|
|
20
|
+
call: AgentWireToolCall,
|
|
21
|
+
state: { tainted: boolean; tool: AgentTool; client?: true; remote?: string },
|
|
22
|
+
) => PromiseOrObject<AgentLoopApproval>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* What answers a parked call: a page's `run(call)` result, the member's reply, or their refusal to connect a remote,
|
|
26
|
+
* of which only the fact is taken: its `error` text is not stored. Its `name` is the call's, never sent.
|
|
27
|
+
*/
|
|
28
|
+
export type AgentLoopCallAnswer = Omit<AgentWireToolResult, "name">;
|
|
29
|
+
|
|
30
|
+
/** Where a remote's result can be drawn for the person: its screen on that server. Never sent to the model. */
|
|
31
|
+
export interface AgentLoopView {
|
|
32
|
+
remote: string;
|
|
33
|
+
/** The remote's own name for the tool, without the `<remote>.` prefix, and the arguments it was called with. */
|
|
34
|
+
tool: string;
|
|
35
|
+
args: Record<string, unknown>;
|
|
36
|
+
/** The screen's path and query on the remote's web origin; like `resourceUri`, dropped past 2,048 characters. */
|
|
37
|
+
href?: string;
|
|
38
|
+
/** The remote can draw this result as script-less HTML (`page().app(…, { static: true })`). */
|
|
39
|
+
static?: boolean;
|
|
40
|
+
/** The MCP Apps view (`ui://…`) that draws this result. */
|
|
41
|
+
resourceUri?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface AgentLoopRemoteResult extends Omit<AgentWireToolResult, "id" | "name"> {
|
|
45
|
+
view?: Omit<AgentLoopView, "remote" | "tool" | "args">;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Another server's tools, called as the run's account over a connection that account granted. `list` answers `null`
|
|
50
|
+
* when there is no live connection. `call` takes the tool's name as `list` gave it; a failure comes back as the
|
|
51
|
+
* result's `error`, with `code` "remoteDisconnected" once the connection is gone. Of what `call` returns, the run
|
|
52
|
+
* keeps `result`, `error`, `code`, `changes`, `attachments` and `view`, each bounded as the parts of an `answer` are.
|
|
53
|
+
*/
|
|
54
|
+
export interface AgentLoopRemote {
|
|
55
|
+
/** `[a-z][A-Za-z0-9]{0,15}`: names its toolkit and prefixes its tools as `<name>.<tool>`. */
|
|
56
|
+
name: string;
|
|
57
|
+
/** The one line the model reads, in `openToolkit`'s own description, to decide whether to open it. */
|
|
58
|
+
description: string;
|
|
59
|
+
list(): Promise<AgentTool[] | null>;
|
|
60
|
+
call(tool: string, args: Record<string, unknown>): Promise<AgentLoopRemoteResult>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** `description` is the one line the model reads, in `openToolkit`'s own description, to decide whether to open it. */
|
|
64
|
+
export interface AgentLoopToolkit {
|
|
65
|
+
description: string;
|
|
66
|
+
tools: readonly string[];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface AgentLoopBudget {
|
|
70
|
+
/** Input and output tokens summed over this run's model calls, compactions included. */
|
|
71
|
+
tokens?: number;
|
|
72
|
+
toolCalls?: number;
|
|
73
|
+
/**
|
|
74
|
+
* Like `signal`, also ends a run stuck in a tool or in `approve`. `callAs` cannot cancel a call: the run stops waiting
|
|
75
|
+
* and answers it with an error saying it may still finish, so a resume does not run it again, and the endpoint runs
|
|
76
|
+
* on unreported.
|
|
77
|
+
*/
|
|
78
|
+
wallMs?: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* `awaiting`: `approve` deferred a call, or a remote needs connecting, and a resume with the messages `onMessage`
|
|
83
|
+
* stored runs it again; or a client tool or `askUser` was called, and a resume with those messages and its `answer`
|
|
84
|
+
* runs on from it.
|
|
85
|
+
*/
|
|
86
|
+
export type AgentLoopStop =
|
|
87
|
+
| "end"
|
|
88
|
+
| "maxRounds"
|
|
89
|
+
| "budget"
|
|
90
|
+
| "aborted"
|
|
91
|
+
| "length"
|
|
92
|
+
| "quota"
|
|
93
|
+
| "unauthorized"
|
|
94
|
+
| "awaiting";
|
|
95
|
+
|
|
96
|
+
export interface AgentLoopOptions {
|
|
97
|
+
/** Tool names; the run sees only those `AgentToolsRole` lists to the account: `/mcp`'s, plus `mcp: "agent"` ones. */
|
|
98
|
+
allow: readonly string[];
|
|
99
|
+
/**
|
|
100
|
+
* The transcript so far, ending in a user message for a new ask or in unanswered calls for a resumed run: your own
|
|
101
|
+
* user messages and what `onMessage` handed over. Never take them from a request: a tool message a client wrote
|
|
102
|
+
* reads exactly like one this run stored. What a client answers goes in `answer`.
|
|
103
|
+
*/
|
|
104
|
+
messages: AgentWireMessage[];
|
|
105
|
+
/** With no `preamble` either, a short neutral prompt stands in, as each adaptor's own fallback is about a screen. */
|
|
106
|
+
instructions?: string;
|
|
107
|
+
/** Prepended to `instructions`; there is none by default, as the in-page preamble is about a screen. */
|
|
108
|
+
preamble?: string;
|
|
109
|
+
context?: AgentWireContext[];
|
|
110
|
+
model?: string;
|
|
111
|
+
maxRounds?: number;
|
|
112
|
+
budget?: AgentLoopBudget;
|
|
113
|
+
/**
|
|
114
|
+
* Named groups of `allow` the model adds with `openToolkit({ name })`, a tool this run lists beside them; a tool in no
|
|
115
|
+
* toolkit is listed every round. An opened toolkit's tools are listed from the next round on, `allow` still capping
|
|
116
|
+
* them, and stay open across a resume and a compaction. `openToolkit` is never asked about and counts as no tool call.
|
|
117
|
+
*/
|
|
118
|
+
toolkits?: Record<string, AgentLoopToolkit>;
|
|
119
|
+
/**
|
|
120
|
+
* Other servers, each a toolkit the model opens with `openToolkit({ name })`; none is listed or contacted before.
|
|
121
|
+
* Opening one the account has no live connection to ends the run as `awaiting` with `connect` naming it: connect
|
|
122
|
+
* and resume with the stored messages, or with `answer: { id, error }` for that call when the person declines,
|
|
123
|
+
* for which the run stores a sentence of its own, not the `error` sent.
|
|
124
|
+
* Security: what a remote lists and returns is another party's text, so opening one taints the run, and a call's
|
|
125
|
+
* arguments leave for that server, so a request with `remotes` and no `approve` is refused. `approve` hears a tool
|
|
126
|
+
* the remote does not call read-only as a `needsConfirm` one. A `clientTools` entry named `<remote>.…` is dropped.
|
|
127
|
+
* A run keeps at most four remotes open, answering the open of a fifth with an error, and its rounds meet the
|
|
128
|
+
* relay's size caps (`AgentRelayPolicy.defaultLimits`), as with `clientTools`.
|
|
129
|
+
*/
|
|
130
|
+
remotes?: readonly AgentLoopRemote[];
|
|
131
|
+
/**
|
|
132
|
+
* The tools of a screen a connected browser has open (`AgentClientTools.list()` in `akanjs/ui`): client input,
|
|
133
|
+
* listed beside the endpoint tools and never run here. `approve` is still asked, and sees each as a write whatever
|
|
134
|
+
* `readOnly` it was sent with. An allowed call ends the run as `awaiting` with `client: true`; resume with the
|
|
135
|
+
* browser's result as `answer`, or `{ id, error }` when no page answers. A name an endpoint tool or `openToolkit`
|
|
136
|
+
* holds is dropped. Past 128 tools, 200,000 characters of definitions or 64 levels of nesting the run ends with
|
|
137
|
+
* `agent.error.clientToolsRefused`, and its rounds meet the relay's size caps (`AgentRelayPolicy.defaultLimits`).
|
|
138
|
+
*/
|
|
139
|
+
clientTools?: AgentTool[];
|
|
140
|
+
/**
|
|
141
|
+
* Lists `askUser({ question, choices?, multiple? })`, the in-page chat's own tool. A call ends the run as `awaiting`
|
|
142
|
+
* with `question: true`; resume with the person's reply as `answer: { id, result }`, or `{ id, error }` when they
|
|
143
|
+
* dismiss it. It never reaches `approve`, counts as no tool call, and `untrusted` never sees its answer. A call with
|
|
144
|
+
* no question is answered with an error instead. A `clientTools` entry by that name is dropped.
|
|
145
|
+
*/
|
|
146
|
+
ask?: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Answers the call the last run parked on with `client` or `question`: the first call of the last batch that
|
|
149
|
+
* nothing answered, and only when it is a client tool's or `askUser`'s. The run names the result after that call,
|
|
150
|
+
* hands it to `onMessage` and runs on. An endpoint tool's call is answered only by running it, so an `answer` that
|
|
151
|
+
* names any other call ends the run with `agent.error.answerRefused` before anything runs; resume without it. Its
|
|
152
|
+
* `result`, `error` and `changes` as one value are clipped as a tool's result is, `code` is kept only when it is a
|
|
153
|
+
* failure code, and of its `attachments` the first four carrying `data` or `text` are kept, never a `url`. Pass it
|
|
154
|
+
* only after an `awaiting` event with `client` or `question` named that call: `approve` is not asked about an
|
|
155
|
+
* answered call, as nothing runs here, so one given for a call `approve` deferred, or for one a run died before
|
|
156
|
+
* parking on, is stored as it stands. A call parked with `connect` takes only the person's refusal, `{ id, error }`:
|
|
157
|
+
* the run stores a sentence of its own naming the remote, coded `remoteDeclined`, and none of the `error` text, so
|
|
158
|
+
* it taints neither that run nor a later resume. With a `result`, or for an `openToolkit` call that names no
|
|
159
|
+
* remote, it is refused the same way, as a connected remote is opened by resuming without `answer`. The stored
|
|
160
|
+
* messages do not say why a run stopped at an open, so a refusal is taken for any first unanswered `openToolkit`
|
|
161
|
+
* call naming a remote, one in a batch `approve` deferred included: all it does is keep that open from running.
|
|
162
|
+
*/
|
|
163
|
+
answer?: AgentLoopCallAnswer;
|
|
164
|
+
/**
|
|
165
|
+
* Summarizes all but the last `keep` messages (6), a batch's results counting as one, once the transcript is
|
|
166
|
+
* estimated at `at` tokens, and also when a round's call fails as `agent.error.contextOverflow`, which is then asked
|
|
167
|
+
* again once. A refusal whose data carries `limit` and `requested`, in any one unit, lowers `at` for the rest of the
|
|
168
|
+
* run to where the request would fit.
|
|
169
|
+
*/
|
|
170
|
+
compact?: { at: number; keep?: number };
|
|
171
|
+
/**
|
|
172
|
+
* Asked before every call, and required with `remotes`; without it a `needsConfirm` tool is refused, and so is any
|
|
173
|
+
* write once tainted.
|
|
174
|
+
*/
|
|
175
|
+
approve?: AgentLoopApprove;
|
|
176
|
+
/**
|
|
177
|
+
* Says which endpoint results carry text someone else wrote. Left out, every result of a call that ran taints the
|
|
178
|
+
* run, an error included, so with no `approve` only the batch written before any result may write; `() => false`
|
|
179
|
+
* trusts them all. A client tool's answer always taints and is never shown to it, as a page may name a tool after
|
|
180
|
+
* an endpoint, and so do the open of a remote and any call into one, refused or not. `askUser`'s answer, the open
|
|
181
|
+
* of a toolkit of `toolkits` and any other call the run refused never taint. Sees a result whole, before the
|
|
182
|
+
* 20,000-character clip. A resume re-applies it to stored, clipped results, or with none counts every stored
|
|
183
|
+
* result, a refusal included, and also reads the `tainted` mark on stored messages, so store each message
|
|
184
|
+
* `onMessage` hands over whole. A stored result whose call names no endpoint the resumed run lists, a page's tool,
|
|
185
|
+
* a remote's, the open of a remote or a tool the run no longer has, taints without it; the run's own
|
|
186
|
+
* `Unknown tool: <name>.`, and its own sentence for a connection the person refused, taint nothing. Keep `ask`,
|
|
187
|
+
* `toolkits` and `remotes` the same for the life of a transcript: a stored `askUser` or `openToolkit` answer is the
|
|
188
|
+
* run's own only under the options it was given with, and one whose name the page lends taints.
|
|
189
|
+
*/
|
|
190
|
+
untrusted?: (result: AgentWireToolResult) => boolean;
|
|
191
|
+
meta?: Record<string, string>;
|
|
192
|
+
signal?: AbortSignal;
|
|
193
|
+
/**
|
|
194
|
+
* Awaited for each message the run appends, before it acts on it; a retried run may hand one over twice. A batch's
|
|
195
|
+
* results arrive one tool message a call, as each call finishes: a run that dies mid-batch has stored those.
|
|
196
|
+
*/
|
|
197
|
+
onMessage?: (message: AgentWireMessage) => PromiseOrObject<void>;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* `account` is a snapshot the server resolved; `principal` is a server-stored id `option.setAgentAccountResolver`
|
|
202
|
+
* resolves at the start and before every round, so a revoked one stops the run. Either one missing or falsy ends the
|
|
203
|
+
* run as `unauthorized`: there is no anonymous run.
|
|
204
|
+
*/
|
|
205
|
+
export type AgentLoopRequest = AgentLoopOptions &
|
|
206
|
+
({ account: unknown; principal?: undefined } | { principal: string; account?: undefined });
|
|
207
|
+
|
|
208
|
+
export type AgentLoopEvent =
|
|
209
|
+
| { type: "text"; delta: string; round: number }
|
|
210
|
+
| { type: "toolCall"; call: AgentWireToolCall; round: number }
|
|
211
|
+
| { type: "toolResult"; result: AgentWireToolResult; round: number; view?: AgentLoopView }
|
|
212
|
+
| { type: "usage"; usage: LlmUsage; model?: string; round: number }
|
|
213
|
+
/**
|
|
214
|
+
* The first `replaced` messages of the transcript as it stands, `onMessage`'s included, are now `summary`. Store it
|
|
215
|
+
* whole: its `tainted` carries the run's taint across a resume.
|
|
216
|
+
*/
|
|
217
|
+
| { type: "compacted"; replaced: number; summary: AgentWireMessage }
|
|
218
|
+
| { type: "awaiting"; call: AgentWireToolCall; client?: true; question?: true; connect?: string }
|
|
219
|
+
| { type: "done"; stop: AgentLoopStop; rounds: number }
|
|
220
|
+
| { type: "error"; message: string; error: unknown };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
type Settled<T> = { ok: true; value: T } | { ok: false; error: unknown };
|
|
2
|
+
|
|
3
|
+
export class DeltaStream {
|
|
4
|
+
static async *of<T, E>(
|
|
5
|
+
run: (onDelta?: (delta: string) => void) => Promise<T>,
|
|
6
|
+
toEvent: ((delta: string) => E) | null,
|
|
7
|
+
): AsyncGenerator<E, T> {
|
|
8
|
+
if (!toEvent) return await run();
|
|
9
|
+
const deltas: string[] = [];
|
|
10
|
+
const state: { settled: Settled<T> | null; wake: () => void } = { settled: null, wake: () => undefined };
|
|
11
|
+
void run((delta) => {
|
|
12
|
+
deltas.push(delta);
|
|
13
|
+
state.wake();
|
|
14
|
+
}).then(
|
|
15
|
+
(value) => {
|
|
16
|
+
state.settled = { ok: true, value };
|
|
17
|
+
state.wake();
|
|
18
|
+
},
|
|
19
|
+
(error: unknown) => {
|
|
20
|
+
state.settled = { ok: false, error };
|
|
21
|
+
state.wake();
|
|
22
|
+
},
|
|
23
|
+
);
|
|
24
|
+
for (;;) {
|
|
25
|
+
const delta = deltas.shift();
|
|
26
|
+
if (delta !== undefined) {
|
|
27
|
+
yield toEvent(delta);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const { settled } = state;
|
|
31
|
+
if (settled) {
|
|
32
|
+
if (settled.ok) return settled.value;
|
|
33
|
+
throw settled.error;
|
|
34
|
+
}
|
|
35
|
+
await new Promise<void>((resolve) => {
|
|
36
|
+
state.wake = resolve;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { FailureCode } from "akanjs/common";
|
|
2
|
+
import { Err } from "akanjs/dictionary";
|
|
3
|
+
import type {
|
|
4
|
+
AgentWireAttachment,
|
|
5
|
+
AgentWireMessage,
|
|
6
|
+
AgentWireToolCall,
|
|
7
|
+
AgentWireToolResult,
|
|
8
|
+
} from "../predefinedAdaptor/llm.adaptor";
|
|
9
|
+
import type { AgentLoopCallAnswer } from "./agentLoopTypes";
|
|
10
|
+
import { LoopToolOutput } from "./loopToolOutput";
|
|
11
|
+
import { LoopTranscript } from "./loopTranscript";
|
|
12
|
+
|
|
13
|
+
export type LoopPark = "answer" | { refusal: string; code: string };
|
|
14
|
+
|
|
15
|
+
export class LoopAnswer {
|
|
16
|
+
|
|
17
|
+
static readonly maxFiles = 4;
|
|
18
|
+
static readonly maxLabelChars = 255;
|
|
19
|
+
|
|
20
|
+
static resultOf(
|
|
21
|
+
answer: AgentLoopCallAnswer,
|
|
22
|
+
messages: readonly AgentWireMessage[],
|
|
23
|
+
parks: (call: AgentWireToolCall) => LoopPark | null,
|
|
24
|
+
): AgentWireToolResult {
|
|
25
|
+
const sent = (answer as Partial<AgentLoopCallAnswer> | null) ?? {};
|
|
26
|
+
const { id, result, error } = sent;
|
|
27
|
+
if (typeof id !== "string" || !id) throw new Err("base.error.invalidArgument", { name: "answer" });
|
|
28
|
+
const [parked] = LoopTranscript.pending(messages);
|
|
29
|
+
const park = parked?.id === id ? parks(parked) : null;
|
|
30
|
+
if (!parked || !park) throw new Err("agent.error.answerRefused", { id });
|
|
31
|
+
if (park === "answer") return LoopAnswer.bounded(parked, sent);
|
|
32
|
+
if (result !== undefined || typeof error !== "string" || !error) throw new Err("agent.error.answerRefused", { id });
|
|
33
|
+
return { id: parked.id, name: parked.name, error: park.refusal, code: park.code };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static bounded({ id, name }: Pick<AgentWireToolCall, "id" | "name">, sent: unknown): AgentWireToolResult {
|
|
37
|
+
const { result, changes, error, code, attachments } = (sent ?? {}) as Partial<AgentWireToolResult>;
|
|
38
|
+
return {
|
|
39
|
+
id,
|
|
40
|
+
name,
|
|
41
|
+
...(result !== undefined ? { result } : {}),
|
|
42
|
+
...(Array.isArray(changes) ? { changes: LoopAnswer.#changes(changes) } : {}),
|
|
43
|
+
...(typeof error === "string" && error ? { error } : {}),
|
|
44
|
+
...(FailureCode.is(code) ? { code } : {}),
|
|
45
|
+
...(Array.isArray(attachments) ? { attachments: LoopAnswer.#files(attachments) } : {}),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static #changes(changes: unknown[]): unknown[] {
|
|
50
|
+
const whole = LoopToolOutput.within(changes);
|
|
51
|
+
return whole === changes ? changes : [whole];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static #files(attachments: unknown[]): AgentWireAttachment[] {
|
|
55
|
+
const files = attachments.flatMap((attachment): AgentWireAttachment[] => {
|
|
56
|
+
const { name, mimeType, data, text } = (attachment ?? {}) as Partial<AgentWireAttachment>;
|
|
57
|
+
if (!LoopAnswer.#isLabel(name) || !LoopAnswer.#isLabel(mimeType)) return [];
|
|
58
|
+
if (typeof data === "string" && data) return [{ name, mimeType, data }];
|
|
59
|
+
return typeof text === "string" && text ? [{ name, mimeType, text }] : [];
|
|
60
|
+
});
|
|
61
|
+
return files.slice(0, LoopAnswer.maxFiles);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static #isLabel(value: unknown): value is string {
|
|
65
|
+
return typeof value === "string" && value.length <= LoopAnswer.maxLabelChars;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { AgentTool } from "../predefinedAdaptor/agentTools.adaptor";
|
|
2
|
+
import type { AgentWireToolCall, AgentWireToolResult } from "../predefinedAdaptor/llm.adaptor";
|
|
3
|
+
|
|
4
|
+
export class LoopAsk {
|
|
5
|
+
static readonly toolName = "askUser";
|
|
6
|
+
|
|
7
|
+
static readonly tool: AgentTool = {
|
|
8
|
+
name: LoopAsk.toolName,
|
|
9
|
+
description:
|
|
10
|
+
"Ask the user to decide something that is theirs to decide — an ambiguous request, a missing value, a choice between paths. Use it instead of guessing. Pass `choices` to offer options, or omit them for a free-text answer; the user may answer off-list either way. Returns what they chose or wrote, and errors if they dismiss it.",
|
|
11
|
+
parameters: {
|
|
12
|
+
type: "object",
|
|
13
|
+
properties: {
|
|
14
|
+
question: { type: "string", description: "What to ask, in one sentence." },
|
|
15
|
+
choices: { type: "array", items: { type: "string" }, description: "The options to offer, as short labels." },
|
|
16
|
+
multiple: { type: "boolean", description: "Let the user pick several choices. Ignored without choices." },
|
|
17
|
+
},
|
|
18
|
+
required: ["question"],
|
|
19
|
+
additionalProperties: false,
|
|
20
|
+
},
|
|
21
|
+
readOnly: true,
|
|
22
|
+
needsConfirm: false,
|
|
23
|
+
};
|
|
24
|
+
static readonly noQuestion = "askUser needs a question to ask.";
|
|
25
|
+
|
|
26
|
+
readonly #on: boolean;
|
|
27
|
+
|
|
28
|
+
constructor(on: boolean | undefined) {
|
|
29
|
+
this.#on = on === true;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
isMeta(name: string): boolean {
|
|
33
|
+
return this.#on && name === LoopAsk.toolName;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
listed(): AgentTool[] {
|
|
37
|
+
return this.#on ? [LoopAsk.tool] : [];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static refusalOf({ id, name, args }: AgentWireToolCall): AgentWireToolResult | null {
|
|
41
|
+
const question = typeof args.question === "string" ? args.question.trim() : "";
|
|
42
|
+
return question ? null : { id, name, error: LoopAsk.noQuestion };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { AgentWireAttachment, AgentWireMessage, LlmTurnRequest } from "../predefinedAdaptor/llm.adaptor";
|
|
2
|
+
import { LoopTranscript } from "./loopTranscript";
|
|
3
|
+
|
|
4
|
+
export class LoopCompaction {
|
|
5
|
+
static readonly keep = 6;
|
|
6
|
+
|
|
7
|
+
static readonly imageTokens = 1_600;
|
|
8
|
+
|
|
9
|
+
static readonly instruction =
|
|
10
|
+
"Summarize the conversation below so you can carry it on with the summary in place of the messages themselves. " +
|
|
11
|
+
"If it opens with a previous summary, carry forward everything in it that still matters: nothing else remembers " +
|
|
12
|
+
"what came before it. " +
|
|
13
|
+
"Keep what the user is trying to do, the decisions taken, the facts and tool results that still matter, and " +
|
|
14
|
+
"anything left unfinished. Drop pleasantries and anything already superseded. Write compact notes, not prose, " +
|
|
15
|
+
"and write nothing but the summary itself.";
|
|
16
|
+
|
|
17
|
+
static tokensOf(messages: readonly AgentWireMessage[]): number {
|
|
18
|
+
let chars = 0;
|
|
19
|
+
for (const message of LoopTranscript.seen(messages)) chars += LoopCompaction.#charsOf(message);
|
|
20
|
+
return Math.ceil(chars / 4);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static frameTokensOf({ messages: _messages, ...frame }: LlmTurnRequest): number {
|
|
24
|
+
return Math.ceil(JSON.stringify(frame).length / 4);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static #charsOf(message: AgentWireMessage): number {
|
|
28
|
+
const own = LoopCompaction.#blanked(message.attachments);
|
|
29
|
+
let images = own.images;
|
|
30
|
+
const toolResults = message.toolResults?.map((result) => {
|
|
31
|
+
const blanked = LoopCompaction.#blanked(result.attachments);
|
|
32
|
+
images += blanked.images;
|
|
33
|
+
return blanked.images ? { ...result, attachments: blanked.attachments } : result;
|
|
34
|
+
});
|
|
35
|
+
if (!images) return JSON.stringify(message).length;
|
|
36
|
+
return (
|
|
37
|
+
JSON.stringify({ ...message, attachments: own.attachments, toolResults }).length +
|
|
38
|
+
images * LoopCompaction.imageTokens * 4
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static #blanked(attachments: AgentWireAttachment[] | undefined) {
|
|
43
|
+
const images = attachments?.filter(LoopCompaction.#isInlinedImage).length ?? 0;
|
|
44
|
+
if (!images) return { attachments, images };
|
|
45
|
+
return {
|
|
46
|
+
attachments: attachments?.map((attachment) =>
|
|
47
|
+
LoopCompaction.#isInlinedImage(attachment) ? { ...attachment, data: "" } : attachment,
|
|
48
|
+
),
|
|
49
|
+
images,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static #isInlinedImage(attachment: AgentWireAttachment): boolean {
|
|
54
|
+
return !!attachment.data && typeof attachment.mimeType === "string" && attachment.mimeType.startsWith("image/");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static cutAt(messages: readonly AgentWireMessage[], keep: number): number {
|
|
58
|
+
if (!messages.length) return -1;
|
|
59
|
+
if (keep <= 0) return messages.length;
|
|
60
|
+
const target = LoopCompaction.#keptFrom(messages, keep);
|
|
61
|
+
if (target <= 0) return -1;
|
|
62
|
+
let boundary = -1;
|
|
63
|
+
for (let at = target; at < messages.length; at += 1) {
|
|
64
|
+
if (messages[at]?.role === "user") return at;
|
|
65
|
+
if (boundary < 0 && messages[at]?.role !== "tool") boundary = at;
|
|
66
|
+
}
|
|
67
|
+
if (boundary >= 0) return boundary;
|
|
68
|
+
for (let at = target - 1; at > 0; at -= 1) if (messages[at]?.role !== "tool") return at;
|
|
69
|
+
return -1;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static #keptFrom(messages: readonly AgentWireMessage[], keep: number): number {
|
|
73
|
+
let at = messages.length;
|
|
74
|
+
for (let kept = 0; at > 0 && kept < keep; at -= 1)
|
|
75
|
+
if (messages[at - 1]?.role !== "tool" || messages[at - 2]?.role !== "tool") kept += 1;
|
|
76
|
+
return at;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static digest(messages: readonly AgentWireMessage[], budget = 12_000): string {
|
|
80
|
+
const previous = messages
|
|
81
|
+
.filter((message) => message.summary)
|
|
82
|
+
.map((message) => `previous summary:\n${message.text ?? ""}`);
|
|
83
|
+
const lines = messages.filter((message) => !message.summary).map((message) => LoopCompaction.#line(message));
|
|
84
|
+
return [...previous, LoopCompaction.#fit(lines, budget)].filter(Boolean).join("\n");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
static #fit(lines: readonly string[], budget: number): string {
|
|
88
|
+
if (lines.reduce((sum, line) => sum + line.length + 1, 0) <= budget) return lines.join("\n");
|
|
89
|
+
const head: string[] = [];
|
|
90
|
+
const tail: string[] = [];
|
|
91
|
+
let used = 0;
|
|
92
|
+
let low = 0;
|
|
93
|
+
let high = lines.length - 1;
|
|
94
|
+
let fromHead = true;
|
|
95
|
+
while (low <= high) {
|
|
96
|
+
const line = lines[fromHead ? low : high] ?? "";
|
|
97
|
+
if (used + line.length + 1 > budget) break;
|
|
98
|
+
used += line.length + 1;
|
|
99
|
+
if (fromHead) {
|
|
100
|
+
head.push(line);
|
|
101
|
+
low += 1;
|
|
102
|
+
} else {
|
|
103
|
+
tail.unshift(line);
|
|
104
|
+
high -= 1;
|
|
105
|
+
}
|
|
106
|
+
fromHead = !fromHead;
|
|
107
|
+
}
|
|
108
|
+
return [...head, `[... ${high - low + 1} messages omitted ...]`, ...tail].join("\n");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
static message(summary: string, tainted?: boolean, toolkits: string[] = []): AgentWireMessage {
|
|
112
|
+
return {
|
|
113
|
+
role: "user",
|
|
114
|
+
text: summary,
|
|
115
|
+
summary: true,
|
|
116
|
+
...(tainted === undefined ? {} : { tainted }),
|
|
117
|
+
...(toolkits.length ? { toolkits } : {}),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
static #line(message: AgentWireMessage): string {
|
|
122
|
+
const parts: string[] = [];
|
|
123
|
+
if (message.text) parts.push(LoopCompaction.#clip(message.text, 1200));
|
|
124
|
+
for (const attachment of message.attachments ?? [])
|
|
125
|
+
parts.push(`[attached ${attachment.name}, content not carried into this summary]`);
|
|
126
|
+
for (const reference of message.references ?? [])
|
|
127
|
+
parts.push(
|
|
128
|
+
`[referenced ${reference.refName}/${reference.refId}${reference.path ? `#${reference.path}` : ""}` +
|
|
129
|
+
` (${reference.label}), value not carried into this summary]`,
|
|
130
|
+
);
|
|
131
|
+
for (const call of message.toolCalls ?? [])
|
|
132
|
+
parts.push(`[called ${call.name} ${LoopCompaction.#clip(JSON.stringify(call.args), 200)}]`);
|
|
133
|
+
for (const result of message.toolResults ?? []) {
|
|
134
|
+
const body = result.error ?? JSON.stringify(result.result ?? null);
|
|
135
|
+
parts.push(`[${result.error ? "failed" : "result"} ${result.name}: ${LoopCompaction.#clip(body, 400)}]`);
|
|
136
|
+
for (const attachment of result.attachments ?? [])
|
|
137
|
+
parts.push(`[${result.name} returned ${attachment.name}, content not carried into this summary]`);
|
|
138
|
+
}
|
|
139
|
+
if (message.error) parts.push(`[turn failed: ${message.error}]`);
|
|
140
|
+
return `${message.role}: ${parts.join(" ")}`.trimEnd();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
static #clip(text: string, max: number): string {
|
|
144
|
+
return text.length <= max ? text : `${text.slice(0, max)}...`;
|
|
145
|
+
}
|
|
146
|
+
}
|