akanjs 3.2.0-rc.8 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +41 -38
- package/CHANGELOG.md +0 -679
- package/CONTRIBUTING.md +3 -0
- package/base/base.ts +2 -1
- package/client/clientRuntime.ts +1 -0
- package/client/cn.ts +2 -2
- package/client/csrTypes.ts +2 -0
- package/client/frameConfig.ts +1 -0
- package/client/index.ts +249 -26
- package/client/locale.ts +1 -0
- package/client/makePageProto.tsx +12 -85
- package/client/nativeThemeColor.ts +51 -0
- package/client/route/PageDefinition.ts +11 -3
- package/client/route/RouteDefinition.ts +24 -7
- package/client/route/RouteGuards.ts +2 -1
- package/client/route/RouteHead.ts +4 -1
- package/client/route/routeArgs.ts +8 -0
- package/client/router.ts +17 -2
- package/client/rscNavigation.ts +1 -0
- package/client/viewportMeta.ts +86 -6
- package/common/CodeTranscript.ts +1 -1
- package/common/Logger.ts +4 -2
- package/common/PipelinePlanSchema.ts +2 -2
- package/common/clientAddress.ts +14 -0
- package/common/err.ts +122 -0
- package/common/eventStream.ts +71 -19
- package/common/facetBarrel.ts +38 -0
- package/common/index.ts +7 -0
- package/common/isGuardRefusal.ts +14 -0
- package/common/loggedFailure.ts +11 -0
- package/common/mcpExposure.ts +17 -4
- package/common/pipelinePlan.ts +1 -1
- package/common/routeConvention.ts +3 -1
- package/common/types.ts +18 -1
- package/constant/constantRegistry.ts +4 -8
- package/constant/crystalize.ts +1 -2
- package/constant/getDefault.ts +1 -1
- package/constant/immerify.ts +1 -1
- package/constant/index.ts +78 -21
- package/constant/purify.ts +4 -9
- package/constant/serialize.ts +4 -2
- package/constant/types.ts +1 -0
- package/constant/via.ts +1 -2
- package/dictionary/agent.dictionary.ts +12 -0
- package/dictionary/base.dictionary.ts +11 -0
- package/dictionary/locale.ts +1 -1
- package/dictionary/trans.ts +14 -97
- package/document/dataLoader.ts +39 -19
- package/document/databaseRegistry.ts +2 -1
- package/document/documentSchema.ts +1 -0
- package/document/filterMeta.ts +4 -1
- package/document/into.ts +2 -1
- package/document/loaderInfo.ts +2 -1
- package/document/noDocumentError.ts +4 -1
- package/document/queryEvaluator.ts +1 -1
- package/document/types.ts +1 -1
- package/fetch/client/fetchClient.ts +83 -269
- package/fetch/client/fetchClientTypes.ts +49 -0
- package/fetch/client/httpClient.ts +3 -2
- package/fetch/client/remoteError.ts +4 -20
- package/fetch/client/requestScope.ts +41 -0
- package/fetch/client/signalCatalog.ts +131 -0
- package/fetch/client/wsClient.ts +82 -6
- package/fetch/requestStorage.ts +1 -0
- package/package.json +1 -1
- package/server/agentHooks.ts +16 -0
- package/server/akanApp.ts +110 -1272
- package/server/akanOption.ts +30 -3
- package/server/akanServer.ts +179 -674
- package/server/artifact/builderRpc.ts +14 -6
- package/server/artifact/routeSeedIndexStore.ts +4 -2
- package/server/assetHeaders.ts +6 -0
- package/server/console.ts +6 -4
- package/server/decorators.ts +2 -2
- package/server/di/diLifecycle.ts +24 -35
- package/server/di/predefinedAdaptor.ts +24 -1
- package/server/di/resolveHierarchy.ts +19 -6
- package/server/di/stageFailedError.ts +10 -0
- package/server/di/utils.ts +8 -3
- package/server/ed25519Key.ts +31 -15
- package/server/flightRowReader.ts +106 -20
- package/server/gateway/childSupervisor.ts +328 -0
- package/server/gateway/devHostChannel.ts +47 -0
- package/server/gateway/gatewayChildren.ts +161 -0
- package/server/gateway/gatewayConfig.ts +182 -0
- package/server/gateway/gatewayHttpProxy.ts +231 -0
- package/server/gateway/gatewayLogging.ts +111 -0
- package/server/gateway/gatewayRooms.ts +141 -0
- package/server/gateway/gatewayStatus.ts +122 -0
- package/server/gateway/gatewayStatusPage.ts +54 -0
- package/server/gateway/gatewayWebSocketRelay.ts +149 -0
- package/server/gateway/listeningPort.ts +13 -0
- package/server/hmr/devHmrController.ts +10 -1
- package/server/htmlResultCache.ts +234 -0
- package/server/imageOptimizer.ts +4 -1
- package/server/index.ts +281 -17
- package/server/lifecycle/parentChannel.ts +79 -0
- package/server/lifecycle/shutdownManager.ts +6 -3
- package/server/lifecycle/startGuard.ts +90 -0
- package/server/logging/hubFileSink.ts +1 -0
- package/server/logging/logControlSocket.ts +42 -3
- package/server/logging/logHub.ts +0 -0
- package/server/logging/logStdoutWriter.ts +3 -1
- package/server/logging/logStreamRoute.ts +28 -11
- package/server/logging/serverLogging.ts +74 -0
- package/server/machine/machineToken.ts +10 -3
- package/server/mcp/AgentTools.ts +149 -0
- package/server/mcp/AgentToolsAccount.ts +26 -0
- package/server/mcp/McpApps.ts +32 -2
- package/server/mcp/McpDispatcher.ts +44 -30
- package/server/mcp/McpPages.ts +34 -12
- package/server/mcp/McpRateLimiter.ts +14 -0
- package/server/mcp/McpRouter.ts +4 -2
- package/server/mcp/McpUiSession.ts +2 -1
- package/server/mcp/index.ts +1 -0
- package/server/migration/migrationCommand.ts +31 -2
- package/server/migration/migrationRunner.ts +36 -1
- package/server/nativeFile.ts +39 -12
- package/server/nativeSecret.ts +12 -3
- package/server/oauth/OAuthClientIdMetadata.ts +2 -2
- package/server/ops/migrateJobs.ts +2 -2
- package/server/ops/opsCommand.ts +1 -1
- package/server/ops/opsRoute.ts +5 -1
- package/server/ops/opsToken.ts +3 -1
- package/server/remote/RemoteFetch.ts +161 -0
- package/server/remote/RemoteMcp.ts +242 -0
- package/server/remote/RemoteOAuth.ts +270 -0
- package/server/remote/RemoteSource.ts +214 -0
- package/server/remote/index.ts +17 -0
- package/server/remote/remoteError.ts +19 -0
- package/server/resolver/CascadeRunner.ts +20 -8
- package/server/resolver/database.resolver.ts +10 -417
- package/server/resolver/databaseModelInstance.ts +209 -0
- package/server/resolver/invalidSignal.ts +7 -0
- package/server/resolver/livePause.ts +34 -0
- package/server/resolver/modelFacade.ts +136 -0
- package/server/resolver/modelLoaders.ts +84 -0
- package/server/resolver/modelSchema.ts +52 -0
- package/server/resolver/roomAdmission.ts +68 -0
- package/server/resolver/signal.resolver.ts +45 -111
- package/server/resolver/sliceCrud.ts +63 -0
- package/server/resolver/timedQuery.ts +16 -0
- package/server/resolver/websocketOf.ts +2 -1
- package/server/routeElementComposer.tsx +45 -6
- package/server/routeTreeBuilder.ts +23 -9
- package/server/routing/apiRouter.ts +53 -28
- package/server/routing/builtinRoutes.ts +194 -0
- package/server/routing/localRooms.ts +34 -0
- package/server/routing/roomReplay.ts +2 -2
- package/server/routing/serverLimits.ts +4 -1
- package/server/routing/serverListener.ts +194 -0
- package/server/rscClient.tsx +122 -195
- package/server/rscClientCache.ts +165 -0
- package/server/rscClientChunks.ts +126 -8
- package/server/rscClientFetch.ts +9 -2
- package/server/rscClientPatch.ts +78 -15
- package/server/rscDocumentHead.tsx +177 -0
- package/server/rscFlightRenderer.ts +83 -0
- package/server/rscFlightStream.ts +259 -0
- package/server/rscHostReloads.ts +238 -0
- package/server/rscHostRenderStream.ts +297 -0
- package/server/rscHostRequests.ts +158 -0
- package/server/rscHttp.ts +18 -6
- package/server/rscNavigationState.ts +24 -1
- package/server/rscPagePrompts.ts +65 -14
- package/server/rscPrefetchCache.ts +31 -17
- package/server/rscRenderControl.ts +33 -0
- package/server/rscRenderFallbacks.ts +299 -0
- package/server/rscRenderHandler.ts +439 -0
- package/server/rscRenderStats.ts +49 -0
- package/server/rscResultCaches.ts +74 -0
- package/server/rscRouteDocument.tsx +316 -0
- package/server/rscSegmentOutletReference.ts +5 -1
- package/server/rscStaticApp.tsx +73 -0
- package/server/rscWorker.tsx +112 -1341
- package/server/rscWorkerHost.ts +175 -803
- package/server/rscWorkerProcess.ts +155 -0
- package/server/rscWorkerRecycler.ts +128 -0
- package/server/serverConfig.ts +128 -0
- package/server/serverMetrics.ts +52 -0
- package/server/sitemap.ts +1 -0
- package/server/ssrFromRscRenderer.tsx +20 -20
- package/server/ssrStaticApp.tsx +243 -0
- package/server/webArtifact.ts +86 -0
- package/server/webAssetRoutes.ts +84 -0
- package/server/webCsrSurface.ts +172 -0
- package/server/webDocumentRoute.ts +180 -0
- package/server/webRouteContext.ts +232 -0
- package/server/webRouter.ts +129 -1165
- package/server/webRscRoute.ts +155 -0
- package/server/webSiteFiles.ts +139 -0
- package/server/webStaticApp.ts +62 -0
- package/server/wellKnownRoutes.ts +73 -0
- package/service/agent.service.ts +14 -2
- package/service/agentAccounts.ts +19 -0
- package/service/agentLoop/agentLoop.ts +550 -0
- package/service/agentLoop/agentLoopTypes.ts +220 -0
- package/service/agentLoop/deltaStream.ts +40 -0
- package/service/agentLoop/loopAnswer.ts +67 -0
- package/service/agentLoop/loopAsk.ts +44 -0
- package/service/agentLoop/loopCompaction.ts +146 -0
- package/service/agentLoop/loopRemotes.ts +181 -0
- package/service/agentLoop/loopRequest.ts +120 -0
- package/service/agentLoop/loopStored.ts +24 -0
- package/service/agentLoop/loopToolOutput.ts +54 -0
- package/service/agentLoop/loopToolkits.ts +155 -0
- package/service/agentLoop/loopTranscript.ts +138 -0
- package/{signal → service}/agentMeter.ts +2 -1
- package/{signal → service}/agentRelayPolicy.ts +43 -8
- package/service/endpointCacheKeys.ts +14 -2
- package/service/index.ts +6 -0
- package/service/injectInfo.ts +2 -1
- package/service/ipcTypes.ts +8 -2
- package/service/liveRoomLimit.ts +68 -0
- package/service/liveRoomLimitError.ts +16 -0
- package/service/liveSyncHub.ts +24 -2
- package/service/predefinedAdaptor/agentTools.adaptor.ts +34 -0
- package/service/predefinedAdaptor/anthropicLlm.ts +33 -14
- package/service/predefinedAdaptor/compress.adaptor.ts +2 -2
- package/service/predefinedAdaptor/database.adaptor.ts +62 -19
- package/service/predefinedAdaptor/index.ts +1 -0
- package/service/predefinedAdaptor/llm.adaptor.ts +24 -1
- package/service/predefinedAdaptor/openaiDialect.ts +72 -23
- package/service/predefinedAdaptor/openaiLlm.ts +1 -1
- package/service/predefinedAdaptor/role.adaptor.ts +2 -0
- package/service/predefinedAdaptor/solidPubsub.adaptor.ts +35 -2
- package/service/predefinedAdaptor/solidQueue.adaptor.ts +2 -2
- package/service/predefinedAdaptor/solidSqlite.ts +6 -3
- package/service/predefinedAdaptor/sql/DocumentHydrator.ts +95 -0
- package/service/predefinedAdaptor/sql/DocumentRowCodec.ts +192 -0
- package/service/predefinedAdaptor/sql/DocumentWriter.ts +298 -0
- package/service/predefinedAdaptor/sql/QueryScope.ts +70 -0
- package/service/predefinedAdaptor/sql/QueryWriter.ts +200 -0
- package/service/predefinedAdaptor/sql/SqlDocumentStore.ts +127 -1069
- package/service/predefinedAdaptor/sql/SqlTableSchema.ts +357 -0
- package/service/predefinedAdaptor/sql/StoredRows.ts +95 -0
- package/service/predefinedAdaptor/sql/TransactionScope.ts +14 -7
- package/service/predefinedAdaptor/sql/dialect/postgres.ts +1 -1
- package/service/predefinedAdaptor/sql/dialect/sqlite.ts +1 -1
- package/service/predefinedAdaptor/sql/driver/bunSqlite.ts +20 -9
- package/service/predefinedAdaptor/sql/driver/postgres.ts +1 -1
- package/service/predefinedAdaptor/sql/types.ts +28 -4
- package/service/predefinedAdaptor/sseData.ts +88 -0
- package/service/predefinedAdaptor/storage.adaptor.ts +2 -1
- package/service/predefinedAdaptor/websocket.adaptor.ts +74 -44
- package/service/serviceRegistry.ts +1 -0
- package/signal/SignalFailure.ts +35 -0
- package/signal/agent.signal.ts +15 -9
- package/signal/agentTurnStream.ts +23 -9
- package/signal/byIdRead.ts +18 -0
- package/signal/carriedClientIps.ts +1 -0
- package/signal/endpointCache.ts +61 -6
- package/signal/endpointErrorContract.ts +1 -1
- package/signal/endpointRateLimit.ts +84 -3
- package/signal/index.ts +322 -32
- package/signal/mcp/McpDocument.ts +8 -1
- package/signal/mcp/mcpProtocol.ts +6 -1
- package/signal/mcp/pagePrompt.ts +15 -0
- package/signal/middleware.ts +10 -3
- package/signal/openapi/openapi.ts +10 -1
- package/signal/resolveFieldContext.ts +34 -0
- package/signal/serializer/fetch.serializer.ts +22 -15
- package/signal/signalContext.ts +15 -42
- package/signal/slice.ts +22 -19
- package/signal/trace.ts +44 -5
- package/signal/types.ts +46 -8
- package/store/action.ts +32 -1057
- package/store/actionErrorMessage.ts +20 -0
- package/store/actionOption.ts +22 -0
- package/store/baseSt.ts +1 -0
- package/store/formFieldSetters.ts +229 -0
- package/store/index.ts +125 -17
- package/store/modelActionContext.ts +65 -0
- package/store/modelOpenActions.ts +158 -0
- package/store/modelWriteActions.ts +240 -0
- package/store/modelWriteGuard.ts +3 -12
- package/store/openSeq.ts +34 -0
- package/store/sliceListActions.ts +370 -0
- package/store/sliceLiveActions.ts +140 -0
- package/store/stateBuilder.ts +2 -0
- package/store/storeInstance.ts +4 -18
- package/store/storeRegistry.ts +1 -1
- package/test/conformance.ts +25 -5
- package/types/base/base.d.ts +2 -1
- package/types/client/clientRuntime.d.ts +1 -0
- package/types/client/cn.d.ts +2 -2
- package/types/client/csrTypes.d.ts +2 -0
- package/types/client/frameConfig.d.ts +1 -0
- package/types/client/index.d.ts +25 -26
- package/types/client/locale.d.ts +1 -0
- package/types/client/makePageProto.d.ts +5 -13
- package/types/client/nativeThemeColor.d.ts +6 -0
- package/types/client/route/PageDefinition.d.ts +5 -2
- package/types/client/route/RouteDefinition.d.ts +2 -2
- package/types/client/route/routeArgs.d.ts +7 -0
- package/types/client/router.d.ts +3 -1
- package/types/client/rscNavigation.d.ts +1 -0
- package/types/client/viewportMeta.d.ts +5 -2
- package/types/common/CodeTranscript.d.ts +1 -1
- package/types/common/clientAddress.d.ts +5 -0
- package/types/common/err.d.ts +48 -0
- package/types/common/eventStream.d.ts +5 -1
- package/types/common/facetBarrel.d.ts +4 -0
- package/types/common/index.d.ts +6 -3
- package/types/common/isGuardRefusal.d.ts +3 -0
- package/types/common/loggedFailure.d.ts +2 -0
- package/types/common/mcpExposure.d.ts +9 -2
- package/types/common/routeConvention.d.ts +2 -0
- package/types/common/types.d.ts +18 -1
- package/types/constant/constantRegistry.d.ts +3 -1
- package/types/constant/crystalize.d.ts +1 -1
- package/types/constant/getDefault.d.ts +1 -1
- package/types/constant/immerify.d.ts +1 -1
- package/types/constant/index.d.ts +21 -21
- package/types/constant/purify.d.ts +2 -1
- package/types/constant/serialize.d.ts +1 -1
- package/types/constant/types.d.ts +1 -0
- package/types/dictionary/agent.dictionary.d.ts +1 -1
- package/types/dictionary/base.dictionary.d.ts +1 -1
- package/types/dictionary/dictionary.d.ts +9 -9
- package/types/dictionary/locale.d.ts +1 -1
- package/types/dictionary/trans.d.ts +3 -26
- package/types/document/dataLoader.d.ts +5 -0
- package/types/document/databaseRegistry.d.ts +2 -1
- package/types/document/documentSchema.d.ts +1 -0
- package/types/document/filterMeta.d.ts +4 -1
- package/types/document/into.d.ts +1 -1
- package/types/document/loaderInfo.d.ts +2 -1
- package/types/document/noDocumentError.d.ts +8 -1
- package/types/document/queryEvaluator.d.ts +1 -1
- package/types/document/types.d.ts +1 -1
- package/types/fetch/client/fetchClient.d.ts +6 -36
- package/types/fetch/client/fetchClientTypes.d.ts +40 -0
- package/types/fetch/client/httpClient.d.ts +2 -0
- package/types/fetch/client/remoteError.d.ts +0 -4
- package/types/fetch/client/requestScope.d.ts +11 -0
- package/types/fetch/client/signalCatalog.d.ts +25 -0
- package/types/fetch/client/wsClient.d.ts +2 -0
- package/types/fetch/requestStorage.d.ts +1 -0
- package/types/server/agentHooks.d.ts +4 -0
- package/types/server/akanApp.d.ts +2 -20
- package/types/server/akanOption.d.ts +16 -2
- package/types/server/akanServer.d.ts +2 -2
- package/types/server/assetHeaders.d.ts +1 -0
- package/types/server/console.d.ts +4 -3
- package/types/server/di/predefinedAdaptor.d.ts +1 -0
- package/types/server/di/stageFailedError.d.ts +5 -0
- package/types/server/ed25519Key.d.ts +1 -0
- package/types/server/flightRowReader.d.ts +8 -2
- package/types/server/gateway/childSupervisor.d.ts +35 -0
- package/types/server/gateway/devHostChannel.d.ts +14 -0
- package/types/server/gateway/gatewayChildren.d.ts +50 -0
- package/types/server/gateway/gatewayConfig.d.ts +82 -0
- package/types/server/gateway/gatewayHttpProxy.d.ts +22 -0
- package/types/server/gateway/gatewayLogging.d.ts +16 -0
- package/types/server/gateway/gatewayRooms.d.ts +25 -0
- package/types/server/gateway/gatewayStatus.d.ts +63 -0
- package/types/server/gateway/gatewayStatusPage.d.ts +9 -0
- package/types/server/gateway/gatewayWebSocketRelay.d.ts +17 -0
- package/types/server/gateway/listeningPort.d.ts +5 -0
- package/types/server/htmlResultCache.d.ts +51 -0
- package/types/server/index.d.ts +19 -17
- package/types/server/lifecycle/parentChannel.d.ts +13 -0
- package/types/server/lifecycle/startGuard.d.ts +10 -0
- package/types/server/logging/logHub.d.ts +5 -1
- package/types/server/logging/logStreamRoute.d.ts +2 -0
- package/types/server/logging/rotatingLogWriter.d.ts +1 -1
- package/types/server/logging/serverLogging.d.ts +12 -0
- package/types/server/mcp/AgentTools.d.ts +31 -0
- package/types/server/mcp/AgentToolsAccount.d.ts +7 -0
- package/types/server/mcp/McpApps.d.ts +6 -2
- package/types/server/mcp/McpDispatcher.d.ts +10 -1
- package/types/server/mcp/McpPages.d.ts +2 -1
- package/types/server/mcp/McpRateLimiter.d.ts +3 -0
- package/types/server/mcp/index.d.ts +1 -0
- package/types/server/migration/migrationCommand.d.ts +1 -1
- package/types/server/migration/migrationRunner.d.ts +9 -1
- package/types/server/remote/RemoteFetch.d.ts +42 -0
- package/types/server/remote/RemoteMcp.d.ts +52 -0
- package/types/server/remote/RemoteOAuth.d.ts +58 -0
- package/types/server/remote/RemoteSource.d.ts +51 -0
- package/types/server/remote/index.d.ts +5 -0
- package/types/server/remote/remoteError.d.ts +12 -0
- package/types/server/remote.d.ts +1 -0
- package/types/server/resolver/CascadeRunner.d.ts +2 -2
- package/types/server/resolver/database.resolver.d.ts +2 -2
- package/types/server/resolver/databaseModelInstance.d.ts +4 -0
- package/types/server/resolver/invalidSignal.d.ts +2 -0
- package/types/server/resolver/livePause.d.ts +5 -0
- package/types/server/resolver/modelFacade.d.ts +5 -0
- package/types/server/resolver/modelLoaders.d.ts +15 -0
- package/types/server/resolver/modelSchema.d.ts +6 -0
- package/types/server/resolver/roomAdmission.d.ts +7 -0
- package/types/server/resolver/signal.resolver.d.ts +1 -1
- package/types/server/resolver/sliceCrud.d.ts +8 -0
- package/types/server/resolver/timedQuery.d.ts +8 -0
- package/types/server/routeElementComposer.d.ts +21 -5
- package/types/server/routing/builtinRoutes.d.ts +24 -0
- package/types/server/routing/localRooms.d.ts +14 -0
- package/types/server/routing/roomReplay.d.ts +2 -2
- package/types/server/routing/serverListener.d.ts +31 -0
- package/types/server/rscClientCache.d.ts +34 -0
- package/types/server/rscClientChunks.d.ts +3 -1
- package/types/server/rscClientFetch.d.ts +1 -1
- package/types/server/rscClientPatch.d.ts +12 -1
- package/types/server/rscDocumentHead.d.ts +33 -0
- package/types/server/rscFlightRenderer.d.ts +14 -0
- package/types/server/rscFlightStream.d.ts +53 -0
- package/types/server/rscHostReloads.d.ts +54 -0
- package/types/server/rscHostRenderStream.d.ts +53 -0
- package/types/server/rscHostRequests.d.ts +29 -0
- package/types/server/rscHttp.d.ts +4 -2
- package/types/server/rscNavigationState.d.ts +5 -1
- package/types/server/rscPagePrompts.d.ts +13 -0
- package/types/server/rscPrefetchCache.d.ts +7 -6
- package/types/server/rscRenderControl.d.ts +12 -0
- package/types/server/rscRenderFallbacks.d.ts +41 -0
- package/types/server/rscRenderHandler.d.ts +29 -0
- package/types/server/rscRenderStats.d.ts +32 -0
- package/types/server/rscResultCaches.d.ts +18 -0
- package/types/server/rscRouteDocument.d.ts +52 -0
- package/types/server/rscStaticApp.d.ts +28 -0
- package/types/server/rscWorker.d.ts +1 -3
- package/types/server/rscWorkerHost.d.ts +10 -70
- package/types/server/rscWorkerProcess.d.ts +31 -0
- package/types/server/rscWorkerRecycler.d.ts +22 -0
- package/types/server/serverConfig.d.ts +30 -0
- package/types/server/serverMetrics.d.ts +11 -0
- package/types/server/sitemap.d.ts +1 -0
- package/types/server/ssrFromRscRenderer.d.ts +2 -2
- package/types/server/ssrStaticApp.d.ts +20 -0
- package/types/server/webArtifact.d.ts +7 -0
- package/types/server/webAssetRoutes.d.ts +11 -0
- package/types/server/webCsrSurface.d.ts +18 -0
- package/types/server/webDocumentRoute.d.ts +19 -0
- package/types/server/webRouteContext.d.ts +45 -0
- package/types/server/webRouter.d.ts +3 -28
- package/types/server/webRscRoute.d.ts +24 -0
- package/types/server/webSiteFiles.d.ts +12 -0
- package/types/server/webStaticApp.d.ts +8 -0
- package/types/server/wellKnownRoutes.d.ts +5 -0
- package/types/service/agent.service.d.ts +3 -0
- package/types/service/agentAccounts.d.ts +8 -0
- package/types/service/agentLoop/agentLoop.d.ts +33 -0
- package/types/service/agentLoop/agentLoopTypes.d.ts +235 -0
- package/types/service/agentLoop/deltaStream.d.ts +3 -0
- package/types/service/agentLoop/loopAnswer.d.ts +13 -0
- package/types/service/agentLoop/loopAsk.d.ts +12 -0
- package/types/service/agentLoop/loopCompaction.d.ts +12 -0
- package/types/service/agentLoop/loopRemotes.d.ts +40 -0
- package/types/service/agentLoop/loopRequest.d.ts +9 -0
- package/types/service/agentLoop/loopStored.d.ts +6 -0
- package/types/service/agentLoop/loopToolOutput.d.ts +8 -0
- package/types/service/agentLoop/loopToolkits.d.ts +17 -0
- package/types/service/agentLoop/loopTranscript.d.ts +13 -0
- package/types/{signal → service}/agentMeter.d.ts +1 -1
- package/types/{signal → service}/agentRelayPolicy.d.ts +18 -3
- package/types/service/index.d.ts +6 -0
- package/types/service/injectInfo.d.ts +2 -1
- package/types/service/ipcTypes.d.ts +10 -0
- package/types/service/liveRoomLimit.d.ts +26 -0
- package/types/service/liveRoomLimitError.d.ts +9 -0
- package/types/service/predefinedAdaptor/agentTools.adaptor.d.ts +31 -0
- package/types/service/predefinedAdaptor/anthropicLlm.d.ts +2 -2
- package/types/service/predefinedAdaptor/database.adaptor.d.ts +9 -7
- package/types/service/predefinedAdaptor/index.d.ts +1 -0
- package/types/service/predefinedAdaptor/llm.adaptor.d.ts +12 -0
- package/types/service/predefinedAdaptor/openaiDialect.d.ts +3 -2
- package/types/service/predefinedAdaptor/role.adaptor.d.ts +2 -0
- package/types/service/predefinedAdaptor/solidPubsub.adaptor.d.ts +3 -0
- package/types/service/predefinedAdaptor/solidSqlite.d.ts +1 -1
- package/types/service/predefinedAdaptor/sql/DocumentHydrator.d.ts +11 -0
- package/types/service/predefinedAdaptor/sql/DocumentRowCodec.d.ts +26 -0
- package/types/service/predefinedAdaptor/sql/DocumentWriter.d.ts +25 -0
- package/types/service/predefinedAdaptor/sql/QueryScope.d.ts +16 -0
- package/types/service/predefinedAdaptor/sql/QueryWriter.d.ts +20 -0
- package/types/service/predefinedAdaptor/sql/SqlDocumentStore.d.ts +5 -28
- package/types/service/predefinedAdaptor/sql/SqlTableSchema.d.ts +22 -0
- package/types/service/predefinedAdaptor/sql/StoredRows.d.ts +27 -0
- package/types/service/predefinedAdaptor/sql/TransactionScope.d.ts +3 -1
- package/types/service/predefinedAdaptor/sql/driver/bunSqlite.d.ts +3 -15
- package/types/service/predefinedAdaptor/sql/driver/postgres.d.ts +0 -8
- package/types/service/predefinedAdaptor/sql/types.d.ts +27 -4
- package/types/service/predefinedAdaptor/sseData.d.ts +13 -0
- package/types/service/predefinedAdaptor/websocket.adaptor.d.ts +7 -3
- package/types/service/serviceRegistry.d.ts +1 -0
- package/types/signal/SignalFailure.d.ts +4 -0
- package/types/signal/agentTurnStream.d.ts +3 -0
- package/types/signal/byIdRead.d.ts +7 -0
- package/types/signal/carriedClientIps.d.ts +4 -0
- package/types/signal/endpointRateLimit.d.ts +12 -0
- package/types/signal/index.d.ts +32 -32
- package/types/signal/mcp/McpDocument.d.ts +2 -0
- package/types/signal/mcp/mcpProtocol.d.ts +5 -0
- package/types/signal/mcp/pagePrompt.d.ts +13 -0
- package/types/signal/resolveFieldContext.d.ts +15 -0
- package/types/signal/serializer/fetch.serializer.d.ts +3 -1
- package/types/signal/signalContext.d.ts +2 -14
- package/types/signal/slice.d.ts +15 -13
- package/types/signal/trace.d.ts +12 -1
- package/types/signal/types.d.ts +38 -7
- package/types/store/action.d.ts +4 -27
- package/types/store/actionErrorMessage.d.ts +1 -0
- package/types/store/actionOption.d.ts +24 -0
- package/types/store/baseSt.d.ts +1 -0
- package/types/store/formFieldSetters.d.ts +80 -0
- package/types/store/index.d.ts +17 -16
- package/types/store/modelActionContext.d.ts +189 -0
- package/types/store/modelOpenActions.d.ts +12 -0
- package/types/store/modelWriteActions.d.ts +16 -0
- package/types/store/modelWriteGuard.d.ts +2 -5
- package/types/store/openSeq.d.ts +17 -0
- package/types/store/sliceListActions.d.ts +295 -0
- package/types/store/sliceLiveActions.d.ts +6 -0
- package/types/store/stateBuilder.d.ts +2 -0
- package/types/test/conformance.d.ts +3 -1
- package/types/ui/Agent/Chat.d.ts +5 -2
- package/types/ui/Agent/ChatHeader.d.ts +13 -0
- package/types/ui/Agent/ChatPendingCards.d.ts +23 -0
- package/types/ui/Agent/ToolRow.d.ts +13 -0
- package/types/ui/Field/Choice.d.ts +2 -1
- package/types/ui/Field/index.d.ts +1 -1
- package/types/ui/Reference/origin.d.ts +1 -0
- package/types/ui/UiOverride/UiOverride.d.ts +2 -0
- package/types/ui/index.d.ts +2 -1
- package/types/ui/overlayLayer.d.ts +8 -2
- package/types/ui/recipe/badgeRecipe.d.ts +3 -3
- package/types/ui/recipe/buttonRecipe.d.ts +3 -3
- package/types/ui/recipe/inputRecipe.d.ts +1 -1
- package/types/vendor/@akanjs/native/packages/cli/src/lib/project.d.ts +4 -0
- package/types/vendor/@akanjs/native/packages/desktop/src/relaunch.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/appearance/src/index.d.ts +9 -0
- package/types/vendor/@akanjs/native/plugins/external-view/src/index.d.ts +22 -13
- package/types/vendor/@akanjs/native/plugins/single-instance/src/socket.d.ts +15 -2
- package/types/vendor/use-agentic/AgentClientTools.d.ts +19 -0
- package/types/vendor/use-agentic/Compaction.d.ts +3 -1
- package/types/vendor/use-agentic/SessionQuestion.d.ts +26 -0
- package/types/vendor/use-agentic/Transcript.d.ts +1 -1
- package/types/vendor/use-agentic/failureCode.d.ts +4 -0
- package/types/vendor/use-agentic/index.d.ts +1 -0
- package/types/vendor/use-agentic/types.d.ts +12 -3
- package/types/webkit/CsrGuards.d.ts +3 -0
- package/types/webkit/McpAppHost.d.ts +24 -0
- package/types/webkit/RouteLevelBoundary.d.ts +17 -0
- package/types/webkit/csrRefresh.d.ts +13 -0
- package/types/webkit/index.d.ts +3 -0
- package/types/webkit/needsBrowser.d.ts +5 -0
- package/types/webkit/useCamera.d.ts +1 -1
- package/types/webkit/useCsrKeyboard.d.ts +19 -0
- package/types/webkit/useCsrLocationState.d.ts +21 -0
- package/types/webkit/useCsrNavigation.d.ts +25 -0
- package/types/webkit/useCsrRefs.d.ts +33 -0
- package/types/webkit/useCsrRenderTrace.d.ts +13 -0
- package/types/webkit/useCsrStackLifecycle.d.ts +12 -0
- package/types/webkit/useCsrTransitions.d.ts +2 -0
- package/types/webkit/useGeoLocation.d.ts +1 -1
- package/types/webkit/useHistory.d.ts +2 -3
- package/types/webkit/useResolvedFrame.d.ts +38 -0
- package/types/webkit/useSyncNavigation.d.ts +22 -0
- package/ui/Agent/Bubble.tsx +4 -118
- package/ui/Agent/Chat.tsx +402 -235
- package/ui/Agent/ChatHeader.tsx +59 -0
- package/ui/Agent/ChatPendingCards.tsx +49 -0
- package/ui/Agent/ToolRow.tsx +117 -0
- package/ui/Agent/fetchRunner.ts +8 -1
- package/ui/BottomSheet.tsx +1 -1
- package/ui/Data/Item.tsx +2 -2
- package/ui/Data/ListContainer.tsx +348 -181
- package/ui/Data/useViewModal.ts +10 -4
- package/ui/Dialog/LegacyModal.tsx +1 -1
- package/ui/Dialog/Modal.tsx +1 -1
- package/ui/Field/Choice.tsx +3 -1
- package/ui/Load/StreamBoundary.tsx +1 -6
- package/ui/Load/View.tsx +2 -1
- package/ui/Model/EditModal.tsx +2 -1
- package/ui/Popconfirm.tsx +1 -1
- package/ui/Reference/origin.ts +1 -0
- package/ui/Select.tsx +43 -51
- package/ui/Signal/RestApi.tsx +3 -2
- package/ui/System/Client.tsx +4 -1
- package/ui/UiOverride/UiOverride.tsx +2 -0
- package/ui/index.ts +5 -0
- package/ui/overlayLayer.ts +25 -2
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeActivity.kt +31 -13
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativePlugin.kt +4 -0
- package/vendor/@akanjs/native/native/desktop/Cargo.lock +1 -0
- package/vendor/@akanjs/native/native/desktop/Cargo.toml +2 -0
- package/vendor/@akanjs/native/native/desktop/src/external.rs +240 -114
- package/vendor/@akanjs/native/native/desktop/src/json.rs +14 -1
- package/vendor/@akanjs/native/native/desktop/src/lib.rs +12 -4
- package/vendor/@akanjs/native/native/desktop/src/linux/external.rs +696 -0
- package/vendor/@akanjs/native/native/desktop/src/linux/mod.rs +1 -0
- package/vendor/@akanjs/native/native/ios/Sources/AkanNativeViewController.swift +6 -1
- package/vendor/@akanjs/native/packages/cli/src/lib/native-plugins.ts +5 -3
- package/vendor/@akanjs/native/packages/cli/src/lib/project.ts +25 -1
- package/vendor/@akanjs/native/packages/desktop/src/deeplinks.ts +2 -2
- package/vendor/@akanjs/native/packages/desktop/src/host.ts +2 -2
- package/vendor/@akanjs/native/packages/desktop/src/relaunch.ts +8 -3
- package/vendor/@akanjs/native/plugins/app/src/desktop.ts +2 -2
- package/vendor/@akanjs/native/plugins/appearance/android/AppearancePlugin.kt +13 -0
- package/vendor/@akanjs/native/plugins/appearance/ios/AppearancePlugin.swift +27 -0
- package/vendor/@akanjs/native/plugins/appearance/native-plugin.json +2 -2
- package/vendor/@akanjs/native/plugins/appearance/src/index.ts +8 -1
- package/vendor/@akanjs/native/plugins/autostart/src/desktop.ts +2 -1
- package/vendor/@akanjs/native/plugins/external-view/native-plugin.json +4 -1
- package/vendor/@akanjs/native/plugins/external-view/src/index.ts +22 -13
- package/vendor/@akanjs/native/plugins/single-instance/src/socket.ts +113 -24
- package/vendor/use-agentic/AgentClientTools.ts +33 -0
- package/vendor/use-agentic/AgentSession.ts +35 -73
- package/vendor/use-agentic/CHANGELOG.md +0 -43
- package/vendor/use-agentic/Compaction.ts +12 -2
- package/vendor/use-agentic/SessionQuestion.ts +99 -0
- package/vendor/use-agentic/ToolRunner.ts +3 -15
- package/vendor/use-agentic/Transcript.ts +8 -5
- package/vendor/use-agentic/WIRE.md +28 -9
- package/vendor/use-agentic/failureCode.ts +44 -0
- package/vendor/use-agentic/httpRunner.ts +22 -8
- package/vendor/use-agentic/index.ts +1 -0
- package/vendor/use-agentic/types.ts +13 -1
- package/webkit/CsrGuards.ts +11 -2
- package/webkit/McpAppFetchBridge.ts +3 -1
- package/webkit/McpAppHost.ts +122 -0
- package/webkit/RenderLayer.tsx +48 -14
- package/webkit/RouteLevelBoundary.tsx +37 -0
- package/webkit/csrRefresh.ts +33 -0
- package/webkit/index.ts +3 -0
- package/webkit/lazy.tsx +5 -1
- package/webkit/needsBrowser.ts +10 -0
- package/webkit/useCamera.tsx +18 -7
- package/webkit/useCsrKeyboard.ts +155 -0
- package/webkit/useCsrLocationState.ts +58 -0
- package/webkit/useCsrNavigation.ts +302 -0
- package/webkit/useCsrRefs.ts +52 -0
- package/webkit/useCsrRenderTrace.ts +68 -0
- package/webkit/useCsrStackLifecycle.ts +120 -0
- package/webkit/useCsrTransitions.ts +552 -0
- package/webkit/useCsrValues.ts +73 -1235
- package/webkit/useGeoLocation.tsx +1 -3
- package/webkit/useHistory.ts +2 -2
- package/webkit/useLocation.ts +3 -2
- package/webkit/useResolvedFrame.ts +116 -0
- package/webkit/useSyncNavigation.ts +109 -0
- package/vendor/@akanjs/native/CHANGELOG.md +0 -21
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AgentProgressReport } from "./AgentProgress";
|
|
2
2
|
import { Compaction, type CompactOptions } from "./Compaction";
|
|
3
3
|
import { Reference } from "./Reference";
|
|
4
|
+
import { SessionQuestion } from "./SessionQuestion";
|
|
4
5
|
import { ToolOutput } from "./ToolOutput";
|
|
5
6
|
import { type ToolApprovalRequest, type ToolCardAnswer, type ToolCardRequest, ToolRunner } from "./ToolRunner";
|
|
6
7
|
import { Transcript } from "./Transcript";
|
|
@@ -10,6 +11,7 @@ import type {
|
|
|
10
11
|
ContextBlock,
|
|
11
12
|
MessageReference,
|
|
12
13
|
PublishedTool,
|
|
14
|
+
RunnerEvent,
|
|
13
15
|
RunnerRequest,
|
|
14
16
|
SurfaceView,
|
|
15
17
|
ToolActivity,
|
|
@@ -17,6 +19,7 @@ import type {
|
|
|
17
19
|
ToolCallResult,
|
|
18
20
|
ToolCard,
|
|
19
21
|
TurnLimits,
|
|
22
|
+
TurnOverflow,
|
|
20
23
|
TurnStop,
|
|
21
24
|
TurnUsage,
|
|
22
25
|
} from "./types";
|
|
@@ -168,7 +171,7 @@ export class AgentSession {
|
|
|
168
171
|
#messages: ChatMessage[] = [];
|
|
169
172
|
#running = false;
|
|
170
173
|
#pending: PendingApproval | null = null;
|
|
171
|
-
#
|
|
174
|
+
readonly #questions = new SessionQuestion(() => this.#notify());
|
|
172
175
|
#card: PendingCard | null = null;
|
|
173
176
|
#staged: MessageReference[] = [];
|
|
174
177
|
#inserts: MessageReference[] = [];
|
|
@@ -215,13 +218,13 @@ export class AgentSession {
|
|
|
215
218
|
},
|
|
216
219
|
fallback: async (call, signal) =>
|
|
217
220
|
call.name === AgentSession.askUserTool.name
|
|
218
|
-
? await this.#ask(call, signal)
|
|
221
|
+
? await this.#questions.ask(call, signal)
|
|
219
222
|
: { id: call.id, name: call.name, error: this.#unknown(call.name) },
|
|
220
223
|
});
|
|
221
224
|
this.#history = options.history;
|
|
222
225
|
this.#onCompact = options.onCompact;
|
|
223
226
|
const restored = AgentSession.#restored(options.history);
|
|
224
|
-
if (Array.isArray(restored)) this.#
|
|
227
|
+
if (Array.isArray(restored)) this.#reopen(restored);
|
|
225
228
|
else {
|
|
226
229
|
this.#restoring = true;
|
|
227
230
|
void this.#hydrate(restored);
|
|
@@ -262,7 +265,7 @@ export class AgentSession {
|
|
|
262
265
|
}
|
|
263
266
|
|
|
264
267
|
get pendingQuestion(): PendingQuestion | null {
|
|
265
|
-
return this.#
|
|
268
|
+
return this.#questions.pending;
|
|
266
269
|
}
|
|
267
270
|
|
|
268
271
|
get pendingCard(): PendingCard | null {
|
|
@@ -400,6 +403,7 @@ export class AgentSession {
|
|
|
400
403
|
/** A user's text, or prewritten messages — how a host injects a prompt's result as the user's turn. */
|
|
401
404
|
send = async (input: string | ChatMessage[]) => {
|
|
402
405
|
if (this.#running) throw new Error("A turn is already running.");
|
|
406
|
+
this.#questions.clear();
|
|
403
407
|
this.#running = true;
|
|
404
408
|
const run = this.#turn(input);
|
|
405
409
|
this.#active = run;
|
|
@@ -429,15 +433,15 @@ export class AgentSession {
|
|
|
429
433
|
budget = turn + maxTurns;
|
|
430
434
|
}
|
|
431
435
|
await this.#autoCompact(controller.signal);
|
|
432
|
-
const { toolCalls, stop,
|
|
436
|
+
const { toolCalls, stop, failure } = await this.#assistantTurn(controller.signal);
|
|
433
437
|
|
|
434
438
|
if (controller.signal.aborted) {
|
|
435
439
|
this.#unanswered(toolCalls);
|
|
436
440
|
return;
|
|
437
441
|
}
|
|
438
|
-
if (
|
|
439
|
-
if (recovered || !(await this.#recover(overflow, controller.signal))) {
|
|
440
|
-
if (!controller.signal.aborted) this.#fail(
|
|
442
|
+
if (failure) {
|
|
443
|
+
if (!failure.overflow || recovered || !(await this.#recover(failure.overflow, controller.signal))) {
|
|
444
|
+
if (!controller.signal.aborted) this.#fail(failure.message, failure.code);
|
|
441
445
|
return;
|
|
442
446
|
}
|
|
443
447
|
recovered = true;
|
|
@@ -469,7 +473,7 @@ export class AgentSession {
|
|
|
469
473
|
this.#controller = null;
|
|
470
474
|
this.#active = null;
|
|
471
475
|
this.#pending = null;
|
|
472
|
-
this.#
|
|
476
|
+
this.#questions.clear();
|
|
473
477
|
this.#card = null;
|
|
474
478
|
this.#progress = null;
|
|
475
479
|
|
|
@@ -496,6 +500,7 @@ export class AgentSession {
|
|
|
496
500
|
await this.#active;
|
|
497
501
|
}
|
|
498
502
|
this.#messages = [];
|
|
503
|
+
this.#questions.clear();
|
|
499
504
|
this.#staged = [];
|
|
500
505
|
this.#inserts = [];
|
|
501
506
|
this.#tools.forgetUntrusted();
|
|
@@ -575,6 +580,7 @@ export class AgentSession {
|
|
|
575
580
|
if (this.#running) return false;
|
|
576
581
|
const controller = new AbortController();
|
|
577
582
|
this.#controller = controller;
|
|
583
|
+
this.#questions.clear();
|
|
578
584
|
this.#running = true;
|
|
579
585
|
|
|
580
586
|
this.#notify();
|
|
@@ -664,7 +670,7 @@ export class AgentSession {
|
|
|
664
670
|
const guard = Compaction.thresholdOf(this.#limits, buffer);
|
|
665
671
|
const measure = () => ({
|
|
666
672
|
transcript: Compaction.tokensOf(this.#messages),
|
|
667
|
-
prompt: Compaction.promptTokensOf(this.#messages, () =>
|
|
673
|
+
prompt: Compaction.promptTokensOf(this.#messages, () => Compaction.frameTokensOf(this.#frame())),
|
|
668
674
|
});
|
|
669
675
|
const before = measure();
|
|
670
676
|
const floor = this.#compactFloor;
|
|
@@ -690,8 +696,9 @@ export class AgentSession {
|
|
|
690
696
|
* refused again after its own summary is not one another summary will fit — and never where the host turned
|
|
691
697
|
* automatic compaction off, since that host keeps the window itself.
|
|
692
698
|
*/
|
|
693
|
-
async #recover(overflow:
|
|
694
|
-
|
|
699
|
+
async #recover(overflow: TurnOverflow, signal: AbortSignal): Promise<boolean> {
|
|
700
|
+
const window = Compaction.windowOf(overflow, this.#messages, this.#overhead);
|
|
701
|
+
if (window) this.#limits = { ...this.#limits, window };
|
|
695
702
|
const { at, keep } = this.#compactOptions;
|
|
696
703
|
if (!at) return false;
|
|
697
704
|
const draft = this.#messages[this.#messages.length - 1];
|
|
@@ -726,10 +733,6 @@ export class AgentSession {
|
|
|
726
733
|
};
|
|
727
734
|
}
|
|
728
735
|
|
|
729
|
-
static #tokensOfFrame(frame: Omit<RunnerRequest, "messages" | "signal">): number {
|
|
730
|
-
return Math.ceil(JSON.stringify(frame).length / 4);
|
|
731
|
-
}
|
|
732
|
-
|
|
733
736
|
/** No tools and no screen context: this turn summarizes the conversation, and must not act on it. */
|
|
734
737
|
async #summarize(digest: string, signal: AbortSignal): Promise<string> {
|
|
735
738
|
const custom = this.#options.compact?.summarize;
|
|
@@ -750,9 +753,9 @@ export class AgentSession {
|
|
|
750
753
|
|
|
751
754
|
async #assistantTurn(
|
|
752
755
|
signal: AbortSignal,
|
|
753
|
-
): Promise<{ toolCalls: ToolCallRequest[]; stop: TurnStop;
|
|
756
|
+
): Promise<{ toolCalls: ToolCallRequest[]; stop: TurnStop; failure?: Extract<RunnerEvent, { type: "error" }> }> {
|
|
754
757
|
const frame = this.#frame();
|
|
755
|
-
this.#overhead =
|
|
758
|
+
this.#overhead = Compaction.frameTokensOf(frame);
|
|
756
759
|
this.#listed = frame.tools.map((tool) => tool.name);
|
|
757
760
|
const request: RunnerRequest = { messages: Transcript.wire(this.#messages), ...frame, signal };
|
|
758
761
|
this.#append({ role: "assistant" });
|
|
@@ -770,9 +773,7 @@ export class AgentSession {
|
|
|
770
773
|
stop = event.stop;
|
|
771
774
|
usage = event.usage;
|
|
772
775
|
if (event.limits) this.#limits = { ...this.#limits, ...event.limits };
|
|
773
|
-
} else
|
|
774
|
-
return { toolCalls: [], stop: "end", overflow: { message: event.message, limit: event.overflow.limit } };
|
|
775
|
-
else throw new Error(event.message);
|
|
776
|
+
} else return { toolCalls: [], stop: "end", failure: event };
|
|
776
777
|
}
|
|
777
778
|
if (toolCalls.length || usage)
|
|
778
779
|
this.#patchLast({ ...(toolCalls.length ? { toolCalls } : {}), ...(usage ? { usage } : {}) });
|
|
@@ -783,7 +784,8 @@ export class AgentSession {
|
|
|
783
784
|
async #askToContinue(turns: number, signal: AbortSignal): Promise<string | null> {
|
|
784
785
|
const ask = this.#options.continueAsk?.();
|
|
785
786
|
if (!ask) return null;
|
|
786
|
-
const
|
|
787
|
+
const asked = { question: ask.question, choices: [ask.keep], multiple: false };
|
|
788
|
+
const settled = await this.#questions.wait(`continue-${turns}`, asked, signal);
|
|
787
789
|
if ("error" in settled) return null;
|
|
788
790
|
return Array.isArray(settled.result) ? settled.result.join(", ") : settled.result;
|
|
789
791
|
}
|
|
@@ -802,52 +804,6 @@ export class AgentSession {
|
|
|
802
804
|
: `Unknown tool: ${name}. Call only a tool listed to you, by its exact name — never a guessed one. Listed now: ${now.join(", ")}.`;
|
|
803
805
|
}
|
|
804
806
|
|
|
805
|
-
/** No surface call and so no diff to report: the only thing this changes is what the model knows. */
|
|
806
|
-
async #ask(call: ToolCallRequest, signal: AbortSignal): Promise<ToolCallResult> {
|
|
807
|
-
const base = { id: call.id, name: call.name };
|
|
808
|
-
const question = typeof call.args.question === "string" ? call.args.question.trim() : "";
|
|
809
|
-
if (!question) return { ...base, error: "askUser needs a question to ask." };
|
|
810
|
-
|
|
811
|
-
const choices = [
|
|
812
|
-
...new Set(
|
|
813
|
-
(Array.isArray(call.args.choices) ? call.args.choices : [])
|
|
814
|
-
.filter((choice): choice is string => typeof choice === "string")
|
|
815
|
-
.map((choice) => choice.trim())
|
|
816
|
-
.filter(Boolean),
|
|
817
|
-
),
|
|
818
|
-
];
|
|
819
|
-
const multiple = call.args.multiple === true && choices.length > 1;
|
|
820
|
-
return { ...base, ...(await this.#awaitAnswer(call.id, question, choices, multiple, signal)) };
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
#awaitAnswer(
|
|
824
|
-
callId: string,
|
|
825
|
-
question: string,
|
|
826
|
-
choices: string[],
|
|
827
|
-
multiple: boolean,
|
|
828
|
-
signal: AbortSignal,
|
|
829
|
-
): Promise<{ result: string | string[] } | { error: string }> {
|
|
830
|
-
return new Promise((resolve) => {
|
|
831
|
-
const settle = (value: { result: string | string[] } | { error: string }) => {
|
|
832
|
-
this.#question = null;
|
|
833
|
-
signal.removeEventListener("abort", onAbort);
|
|
834
|
-
this.#notify();
|
|
835
|
-
resolve(value);
|
|
836
|
-
};
|
|
837
|
-
const onAbort = () => settle({ error: "The user aborted the turn." });
|
|
838
|
-
signal.addEventListener("abort", onAbort);
|
|
839
|
-
this.#question = {
|
|
840
|
-
callId,
|
|
841
|
-
question,
|
|
842
|
-
choices,
|
|
843
|
-
multiple,
|
|
844
|
-
answer: (value) => settle({ result: value }),
|
|
845
|
-
dismiss: (reason) => settle({ error: reason ?? "The user dismissed the question without answering it." }),
|
|
846
|
-
};
|
|
847
|
-
this.#notify();
|
|
848
|
-
});
|
|
849
|
-
}
|
|
850
|
-
|
|
851
807
|
#awaitCard(request: ToolCardRequest, signal: AbortSignal): Promise<ToolCardAnswer> {
|
|
852
808
|
return new Promise((resolve) => {
|
|
853
809
|
const settle = (answer: ToolCardAnswer) => {
|
|
@@ -907,10 +863,11 @@ export class AgentSession {
|
|
|
907
863
|
}
|
|
908
864
|
|
|
909
865
|
/** Recorded on the open assistant draft when there is one, so a failed turn reads as that turn failing. */
|
|
910
|
-
#fail(message: string) {
|
|
866
|
+
#fail(message: string, code?: string) {
|
|
867
|
+
const failed = { error: message, ...(code ? { errorCode: code } : {}) };
|
|
911
868
|
const last = this.#messages[this.#messages.length - 1];
|
|
912
|
-
if (last?.role === "assistant" && !last.error) this.#patchLast(
|
|
913
|
-
else this.#append({ role: "assistant",
|
|
869
|
+
if (last?.role === "assistant" && !last.error) this.#patchLast(failed);
|
|
870
|
+
else this.#append({ role: "assistant", ...failed });
|
|
914
871
|
}
|
|
915
872
|
|
|
916
873
|
#append(message: ChatMessage) {
|
|
@@ -965,7 +922,7 @@ export class AgentSession {
|
|
|
965
922
|
|
|
966
923
|
static #settled(messages: ChatMessage[] | null): ChatMessage[] {
|
|
967
924
|
|
|
968
|
-
return Array.isArray(messages) ? Transcript.sanitize(messages) : [];
|
|
925
|
+
return Array.isArray(messages) ? Transcript.sanitize(messages, SessionQuestion.openCall(messages)?.id) : [];
|
|
969
926
|
}
|
|
970
927
|
|
|
971
928
|
/**
|
|
@@ -989,8 +946,13 @@ export class AgentSession {
|
|
|
989
946
|
* which would save the transcript it has just loaded.
|
|
990
947
|
*/
|
|
991
948
|
#restore(restored: ChatMessage[]) {
|
|
992
|
-
if (this.#version === 0 && restored.length) this.#
|
|
949
|
+
if (this.#version === 0 && restored.length) this.#reopen(restored);
|
|
993
950
|
this.#version += 1;
|
|
994
951
|
for (const listener of this.#listeners) listener();
|
|
995
952
|
}
|
|
953
|
+
|
|
954
|
+
#reopen(restored: ChatMessage[]) {
|
|
955
|
+
this.#messages = restored;
|
|
956
|
+
this.#questions.reopen(restored, (result) => void this.send([{ role: "tool", toolResults: [result] }]));
|
|
957
|
+
}
|
|
996
958
|
}
|
|
@@ -1,48 +1,5 @@
|
|
|
1
1
|
# use-agentic
|
|
2
2
|
|
|
3
|
-
## 0.3.1
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- e3de9ef: Tighter defaults for the web client and the in-page agent. Every changed default below names the option that restores the old behaviour.
|
|
8
|
-
|
|
9
|
-
- **Write tools confirm by default.** An `st.tool` whose name starts with `remove`, `delete`, `create`, `update`, `upsert`, `submit`, `save`, `send` or `export` now shows the approval card unless it declares `confirm`. Before, only `remove*` did. This covers `submit<Model>` in `Model.EditModal` and `exportCsvOf<Model>` / `exportJsonOf<Model>` in `Data.ListContainer`. Opt out per tool with `{ confirm: false }`, which also drops the tool's confirm mark in the dock and the screen actions and its MCP `destructiveHint`, or app-wide with `AgentConfirm.set({ byName: (name) => name.startsWith("remove") })`.
|
|
10
|
-
- **A change right after a page read asks once.** A tool can declare `taint: "source"` (its result carries text the user did not write) or `taint: "exempt"` (it only moves the view). `readScreen`, `readState` and `viewImage` are sources, and `navigate`, `goBack` and the framework's view-only tools are exempt: tabs, dialogs, dropdowns, the side menu, the screen navigator, a list's view, sort, page size and page, and opening or closing a detail view. After a source call, the next call that changes something shows the approval card, even with `confirm: false`. A read (`settle: false`) and a card tool do not count as changes. The user's approval lifts the ask until the next source call. `st.tool(name, { taint })`, `useAgentTool(name, { taint })` and `ToolEntry.taint` declare it. Turn it off app-wide with `AgentConfirm.set({ afterScreenRead: false })`, or with `AgentSession` / `ToolRunner` `askAfterUntrusted: false`.
|
|
11
|
-
- **Page text reaches the model fenced as data.** A `taint: "source"` result or error is wrapped in a `<page-content …>` block. The block has a fresh boundary per call and a note that its contents are data, not instructions. The agent's system prompt, and the default prompt of the Anthropic and OpenAI-compatible adaptors, say the same.
|
|
12
|
-
- **`readScreen` withholds more.** It never reads the value of an input with `autocomplete` `one-time-code`, `current-password`, `new-password` or a card field (`cc-number`, `cc-csc`, `cc-exp*`). It also withholds any element marked `data-agent-private`. A private control prints only its kind and name, and a private region prints `[private: label]`, even when asked for by name. A private region is never a `highlight` or section target. Mark content `data-agent-private` to keep it from the agent.
|
|
13
|
-
- **The agent transcript belongs to one account.** A stored transcript, including one under an app-chosen `persist.key`, now records which account wrote it. It is neither restored nor overwritten while another account is signed in, and other accounts' transcripts under the app's default keys are removed. Default keys now include the account (`akan.agent.<app>.<account>[.<zone>]`), so transcripts stored before this change are removed, not restored; a `persist.key` of the app's own is kept, even one under `akan.agent.<app>`, unless it holds such a transcript. `Agent.Chat` and `Agent.Zone` reset a conversation they own when the signed-in account changes in this tab, or in another tab once this one is focused again. A session the app provides (`AgentProvider`, `SessionContext` or `Agent.Zone`'s `session`) is left to the app, and a `SessionHistory` passed as `persist` or attached with `Agent.History` keeps what it stored. `AgentSession.reset({ keepHistory: true })` empties a transcript without clearing its history.
|
|
14
|
-
- **The session token stays on the app's origin.** A `FetchClient` sends the token set with `setJwt` only to its own origin, over HTTP and WebSocket. `fetch.clone({ origin })` for another origin starts without it. Pass `clone({ origin, jwt })` to send one on purpose, over HTTP and WebSocket. A per-call `{ token }` covers that HTTP call only: the socket a call opens for its `FetchPolicy.origin` carries no token.
|
|
15
|
-
- **SSR web pages keep no token in `localStorage`.** `setAuth` on an SSR web page removes the stored copy, so the session cookie is the only place the token is stored. CSR and native clients still keep it in `secretStorage`. A web CSR boot with nothing stored now adopts the session cookie of an SSR page on the same origin.
|
|
16
|
-
- **Server-held sessions.** New `SessionCookie` (`akanjs/fetch`): `SessionCookie.issue(jwt, { maxAge })` returns the `Set-Cookie` values for an HttpOnly session cookie and a readable claims cookie beside it, and `SessionCookie.expire()` returns the sign-out values. While the claims cookie is present, the page never writes the session cookie itself, and `getAccount()` and form drafts read the account from the claims (`getSessionClaims()`). Nothing changes until a server sends these cookies.
|
|
17
|
-
- **`pathChange` goes only to known parents in production.** `router.postPathChange` posts to a same-origin parent frame, or to origins the app names with `router.setFrameParentOrigins([...])`. Local mode still posts to any parent. `router.setFrameParentOrigins("*")` restores the old target.
|
|
18
|
-
- **`l.rich` escapes its params.** Param values are HTML-escaped before interpolation, and a param named `br` no longer replaces the line break. Put markup in the dictionary text, not in a param.
|
|
19
|
-
- **Links in agent markdown.** `isSafeHref` drops tabs, newlines and leading control characters and spaces before it reads the scheme, as a browser does, so a disguised `javascript:` link is refused.
|
|
20
|
-
- **CSV export keeps formulas as text.** A text cell that starts with `=`, `+`, `-`, `@`, a tab or a carriage return gets a leading `'`. Numbers are written unchanged.
|
|
21
|
-
|
|
22
|
-
- 3b7247e: A failed tool call now names a code a client or a model can branch on, beside the text it already sent, which is unchanged. No upgrade step is needed: `AgentWireToolResult` and `use-agentic`'s `ToolCallResult` only gain an optional `code`, and `akanjs/common` adds `MCP_FAILURE_META`, `McpFailure` and `FailureCode`.
|
|
23
|
-
|
|
24
|
-
Every code is a bounded token, a dictionary key (`<module>.error.<key>`) or one camelCase identifier, never prose, so no text can pass for one.
|
|
25
|
-
|
|
26
|
-
- **An app's `/mcp`:**
|
|
27
|
-
- A tool error carries `_meta["akanjs/failure"]: { code, statusCode }`, beside the server's own `_meta` for a 2026-07-28 client. The code is the one an HTTP caller gets:
|
|
28
|
-
- a domain `Err` by its dictionary key, such as `base.error.documentNotFound`;
|
|
29
|
-
- an `AkanError` by its code, such as `invalidArgument` for an argument the call got wrong;
|
|
30
|
-
- a 401 or 403 by its status alone (`unauthorized`, `forbidden`);
|
|
31
|
-
- a 5xx by a dictionary key or this server's own `AkanError` code, else by its status (`internalError`, `serviceUnavailable`), never by a code a duck-typed error put in its body.
|
|
32
|
-
- A JSON-RPC error carries `data.code`, which tells apart what `-32602` covers:
|
|
33
|
-
- `unknownTool`, `unknownPrompt` (an unlisted page prompt included) and `unknownResource`;
|
|
34
|
-
- `invalidArgument` for bad arguments or a missing tool name, prompt name or resource uri;
|
|
35
|
-
- a refused screen's `forbidden` or `notFound`.
|
|
36
|
-
A rate-limited call names `tooManyRequests` and the catch-all names `internalError`.
|
|
37
|
-
- An MCP Apps view's call that fails without a domain `Err` restores as an error with that status and code, where it used to be a plain `Error`. A tool the view itself serves to the host names its code in the same `_meta` entry, without a `statusCode`.
|
|
38
|
-
- **`akan mcp`:** a tool error carries the same `_meta["akanjs/failure"]`, with one of these codes:
|
|
39
|
-
- `unknownTool` for a name no mode lists;
|
|
40
|
-
- `toolUnavailable` for a tool outside the server's mode;
|
|
41
|
-
- `invalidArgument` for a missing argument, an unknown guideline name, or a workflow path outside `.akan/workflows/`;
|
|
42
|
-
- `toolFailed` for anything else, with `statusCode` 500. A coded `AkanError` keeps its own code.
|
|
43
|
-
- **The code agent:** an MCP server's tool result keeps the code it named, from `_meta["akanjs/failure"]` or a JSON-RPC error's `data.code`, in the call's `details`.
|
|
44
|
-
- **The in-page agent:** a `toolResults` entry whose tool threw carries `code` beside `error` (see `use-agentic`'s WIRE.md): a dictionary `Err`'s key, else the thrown error's own `code`. A `taint: "source"` tool's result carries none, since its code would travel outside the page-content fence. The bundled Anthropic and OpenAI adaptors send `code` to the model inside the tool result, beside `error`.
|
|
45
|
-
|
|
46
3
|
## 0.3.0
|
|
47
4
|
|
|
48
5
|
### Minor Changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Transcript } from "./Transcript";
|
|
2
|
-
import type { ChatMessage, MessageAttachment, ToolCallResult, TurnLimits } from "./types";
|
|
2
|
+
import type { ChatMessage, MessageAttachment, RunnerRequest, ToolCallResult, TurnLimits, TurnOverflow } from "./types";
|
|
3
3
|
|
|
4
4
|
export interface CompactOptions {
|
|
5
5
|
/**
|
|
@@ -70,6 +70,10 @@ export class Compaction {
|
|
|
70
70
|
return Math.ceil(chars / 4) + images * Compaction.imageTokens;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
static frameTokensOf(frame: Omit<RunnerRequest, "messages" | "signal">): number {
|
|
74
|
+
return Math.ceil(JSON.stringify(frame).length / 4);
|
|
75
|
+
}
|
|
76
|
+
|
|
73
77
|
/**
|
|
74
78
|
* What the next request is estimated to cost, prompt and all: the provider's own count for the last turn that
|
|
75
79
|
* reported one, plus four characters a token for what the transcript gained since. The provider's number is the
|
|
@@ -85,6 +89,11 @@ export class Compaction {
|
|
|
85
89
|
return Compaction.tokensOf(messages) + overhead();
|
|
86
90
|
}
|
|
87
91
|
|
|
92
|
+
static windowOf({ limit, requested }: TurnOverflow, messages: readonly ChatMessage[], overhead: number) {
|
|
93
|
+
if (!limit || !requested || requested <= limit) return limit;
|
|
94
|
+
return Math.floor((Compaction.promptTokensOf(messages, () => overhead) * limit) / requested);
|
|
95
|
+
}
|
|
96
|
+
|
|
88
97
|
/**
|
|
89
98
|
* The prompt size past which a turn compacts first, or `Infinity` while the window is unknown. The answer shares
|
|
90
99
|
* the window with the prompt, so its ceiling is held back along with `buffer`.
|
|
@@ -95,7 +104,8 @@ export class Compaction {
|
|
|
95
104
|
}
|
|
96
105
|
|
|
97
106
|
static #charsOf(message: ChatMessage): number {
|
|
98
|
-
const posted =
|
|
107
|
+
const posted =
|
|
108
|
+
message.usage || message.errorCode ? { ...message, usage: undefined, errorCode: undefined } : message;
|
|
99
109
|
const own = Compaction.#blanked(message.attachments);
|
|
100
110
|
let images = own.images;
|
|
101
111
|
const toolResults = message.toolResults?.map((result) => {
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { PendingQuestion } from "./AgentSession";
|
|
2
|
+
import { Transcript } from "./Transcript";
|
|
3
|
+
import type { ChatMessage, ToolCallRequest, ToolCallResult } from "./types";
|
|
4
|
+
|
|
5
|
+
type Settled = { result: string | string[] } | { error: string };
|
|
6
|
+
type Asked = Pick<PendingQuestion, "question" | "choices" | "multiple">;
|
|
7
|
+
|
|
8
|
+
export class SessionQuestion {
|
|
9
|
+
static readonly toolName = "askUser";
|
|
10
|
+
static readonly dismissed = "The user dismissed the question without answering it.";
|
|
11
|
+
|
|
12
|
+
readonly #changed: () => void;
|
|
13
|
+
#pending: PendingQuestion | null = null;
|
|
14
|
+
|
|
15
|
+
constructor(changed: () => void) {
|
|
16
|
+
this.#changed = changed;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
get pending(): PendingQuestion | null {
|
|
20
|
+
return this.#pending;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
clear() {
|
|
24
|
+
this.#pending = null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** No surface call and so no diff to report: the only thing this changes is what the model knows. */
|
|
28
|
+
async ask(call: ToolCallRequest, signal: AbortSignal): Promise<ToolCallResult> {
|
|
29
|
+
const base = { id: call.id, name: call.name };
|
|
30
|
+
const asked = SessionQuestion.#asked(call);
|
|
31
|
+
if (!asked) return { ...base, error: "askUser needs a question to ask." };
|
|
32
|
+
return { ...base, ...(await this.wait(call.id, asked, signal)) };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
wait(callId: string, asked: Asked, signal: AbortSignal): Promise<Settled> {
|
|
36
|
+
return new Promise((resolve) => {
|
|
37
|
+
const settle = (value: Settled) => {
|
|
38
|
+
this.#pending = null;
|
|
39
|
+
signal.removeEventListener("abort", onAbort);
|
|
40
|
+
this.#changed();
|
|
41
|
+
resolve(value);
|
|
42
|
+
};
|
|
43
|
+
const onAbort = () => settle({ error: "The user aborted the turn." });
|
|
44
|
+
signal.addEventListener("abort", onAbort);
|
|
45
|
+
this.#pending = {
|
|
46
|
+
callId,
|
|
47
|
+
...asked,
|
|
48
|
+
answer: (value) => settle({ result: value }),
|
|
49
|
+
dismiss: (reason) => settle({ error: reason ?? SessionQuestion.dismissed }),
|
|
50
|
+
};
|
|
51
|
+
this.#changed();
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Puts back a question a restored transcript ends on, which a run asked while no chat was open; settling it hands
|
|
57
|
+
* the result to `resume` once, and a turn that starts first takes it down, leaving the call to the wire's closing.
|
|
58
|
+
*/
|
|
59
|
+
reopen(messages: readonly ChatMessage[], resume: (result: ToolCallResult) => void) {
|
|
60
|
+
const call = SessionQuestion.openCall(messages);
|
|
61
|
+
const asked = call ? SessionQuestion.#asked(call) : null;
|
|
62
|
+
if (!call || !asked) return;
|
|
63
|
+
const settle = (value: Settled) => {
|
|
64
|
+
if (this.#pending !== question) return;
|
|
65
|
+
this.#pending = null;
|
|
66
|
+
resume({ id: call.id, name: call.name, ...value });
|
|
67
|
+
};
|
|
68
|
+
const question: PendingQuestion = {
|
|
69
|
+
callId: call.id,
|
|
70
|
+
...asked,
|
|
71
|
+
answer: (value) => settle({ result: value }),
|
|
72
|
+
dismiss: (reason) => settle({ error: reason ?? SessionQuestion.dismissed }),
|
|
73
|
+
};
|
|
74
|
+
this.#pending = question;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static openCall(messages: readonly ChatMessage[]): ToolCallRequest | null {
|
|
78
|
+
const last = messages.findLast((message) => message.role !== "tool" && Transcript.carries(message));
|
|
79
|
+
if (last?.role !== "assistant") return null;
|
|
80
|
+
const answered = new Set(messages.flatMap((message) => (message.toolResults ?? []).map((result) => result.id)));
|
|
81
|
+
const call = last.toolCalls?.find((one) => !answered.has(one.id));
|
|
82
|
+
return call?.name === SessionQuestion.toolName && SessionQuestion.#asked(call) ? call : null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static #asked({ args }: ToolCallRequest): Asked | null {
|
|
86
|
+
const question = typeof args.question === "string" ? args.question.trim() : "";
|
|
87
|
+
if (!question) return null;
|
|
88
|
+
|
|
89
|
+
const choices = [
|
|
90
|
+
...new Set(
|
|
91
|
+
(Array.isArray(args.choices) ? args.choices : [])
|
|
92
|
+
.filter((choice): choice is string => typeof choice === "string")
|
|
93
|
+
.map((choice) => choice.trim())
|
|
94
|
+
.filter(Boolean),
|
|
95
|
+
),
|
|
96
|
+
];
|
|
97
|
+
return { question, choices, multiple: args.multiple === true && choices.length > 1 };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AgentAbort } from "./AgentAbort";
|
|
2
2
|
import { AgentProgress, type AgentProgressReport } from "./AgentProgress";
|
|
3
|
+
import { failureCodeOf, isFailureCode } from "./failureCode";
|
|
3
4
|
import { ToolOutput } from "./ToolOutput";
|
|
4
5
|
import { ToolReturn } from "./ToolReturn";
|
|
5
6
|
import type {
|
|
@@ -107,8 +108,6 @@ export class ToolRunner {
|
|
|
107
108
|
* the user is not work, and holding the lock across it would let one agent's unanswered card freeze the other's.
|
|
108
109
|
*/
|
|
109
110
|
static #queue: Promise<void> = Promise.resolve();
|
|
110
|
-
static readonly #errKey = /^[A-Za-z][\w$-]{0,63}\.error\.[\w$.-]{1,120}$/;
|
|
111
|
-
static readonly #token = /^[a-z][A-Za-z0-9]{0,63}$/;
|
|
112
111
|
|
|
113
112
|
readonly #surface: SurfaceView;
|
|
114
113
|
readonly #host: ToolRunnerHost;
|
|
@@ -127,7 +126,7 @@ export class ToolRunner {
|
|
|
127
126
|
const source = this.#surface.tool(call.name)?.taint === "source";
|
|
128
127
|
|
|
129
128
|
const { code, ...answered } = ToolOutput.clipped(await this.#answer(call, signal));
|
|
130
|
-
if (!source) return
|
|
129
|
+
if (!source) return isFailureCode(code) ? { ...answered, code } : answered;
|
|
131
130
|
this.#untrusted = true;
|
|
132
131
|
|
|
133
132
|
return ToolRunner.#framed(answered);
|
|
@@ -230,7 +229,7 @@ export class ToolRunner {
|
|
|
230
229
|
return ToolRunner.#answered(base, returned, this.#surface.diffSince(before));
|
|
231
230
|
} catch (error) {
|
|
232
231
|
failed = error instanceof Error ? error.message : String(error);
|
|
233
|
-
const code =
|
|
232
|
+
const code = failureCodeOf(error);
|
|
234
233
|
return { ...base, error: failed, ...(code ? { code } : {}) };
|
|
235
234
|
} finally {
|
|
236
235
|
this.#host.progress?.({ callId: call.id, report: null });
|
|
@@ -244,17 +243,6 @@ export class ToolRunner {
|
|
|
244
243
|
}
|
|
245
244
|
}
|
|
246
245
|
|
|
247
|
-
static #codeOf(error: unknown): string | undefined {
|
|
248
|
-
if (typeof error !== "object" || error === null) return undefined;
|
|
249
|
-
const { code, error: key } = error as { code?: unknown; error?: unknown };
|
|
250
|
-
if (typeof key === "string" && ToolRunner.#errKey.test(key)) return key;
|
|
251
|
-
return typeof code === "string" && ToolRunner.#token.test(code) ? code : undefined;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
static #isCode(code: unknown): code is string {
|
|
255
|
-
return typeof code === "string" && (ToolRunner.#errKey.test(code) || ToolRunner.#token.test(code));
|
|
256
|
-
}
|
|
257
|
-
|
|
258
246
|
/**
|
|
259
247
|
* A consent covers the action the user read. Another registration of that declaration — one per row of a list — is
|
|
260
248
|
* the same action; anything else the screen put under the name since may not run in its place, asked or not.
|
|
@@ -15,9 +15,7 @@ export class Transcript {
|
|
|
15
15
|
|
|
16
16
|
/** What one turn posts: no host-only message, no unanswered call, no result answering a call nobody sees. */
|
|
17
17
|
static wire(messages: readonly ChatMessage[]): ChatMessage[] {
|
|
18
|
-
return Transcript.sanitize(
|
|
19
|
-
Transcript.seen(messages.filter((message) => !message.local)).map(Transcript.unmeasured),
|
|
20
|
-
);
|
|
18
|
+
return Transcript.sanitize(Transcript.seen(messages.filter((message) => !message.local)).map(Transcript.#sent));
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
/**
|
|
@@ -54,12 +52,17 @@ export class Transcript {
|
|
|
54
52
|
return { ...result, attachments };
|
|
55
53
|
}
|
|
56
54
|
|
|
55
|
+
static #sent(message: ChatMessage): ChatMessage {
|
|
56
|
+
const unmeasured = Transcript.unmeasured(message);
|
|
57
|
+
return unmeasured.errorCode ? { ...unmeasured, errorCode: undefined } : unmeasured;
|
|
58
|
+
}
|
|
59
|
+
|
|
57
60
|
/** A message without the provider's count for its turn — what the wire carries and what a compaction keeps. */
|
|
58
61
|
static unmeasured(message: ChatMessage): ChatMessage {
|
|
59
62
|
return message.usage ? { ...message, usage: undefined } : message;
|
|
60
63
|
}
|
|
61
64
|
|
|
62
|
-
static sanitize(messages: readonly ChatMessage[]): ChatMessage[] {
|
|
65
|
+
static sanitize(messages: readonly ChatMessage[], openCallId?: string): ChatMessage[] {
|
|
63
66
|
const answered = new Set(messages.flatMap((message) => (message.toolResults ?? []).map((result) => result.id)));
|
|
64
67
|
const called = new Set<string>();
|
|
65
68
|
const kept: ChatMessage[] = [];
|
|
@@ -73,7 +76,7 @@ export class Transcript {
|
|
|
73
76
|
kept.push(message);
|
|
74
77
|
const calls = message.toolCalls ?? [];
|
|
75
78
|
for (const call of calls) called.add(call.id);
|
|
76
|
-
const unanswered = calls.filter((call) => !answered.has(call.id));
|
|
79
|
+
const unanswered = calls.filter((call) => !answered.has(call.id) && call.id !== openCallId);
|
|
77
80
|
|
|
78
81
|
if (unanswered.length)
|
|
79
82
|
kept.push({
|
|
@@ -110,14 +110,33 @@ outgrows the window, measured by the provider's own count rather than by a chara
|
|
|
110
110
|
falls back to its transcript ceiling alone.
|
|
111
111
|
|
|
112
112
|
Any non-2xx status is surfaced to the session as one error event and ends the turn; a string `message` or
|
|
113
|
-
`error` field in a JSON body becomes that event's message verbatim,
|
|
114
|
-
message that is a code rather than a sentence may be accompanied by a flat `data`
|
|
115
|
-
the values whoever resolves the code interpolates into its text; a host that does
|
|
116
|
-
message as it stands.
|
|
113
|
+
`error` field in a JSON body becomes that event's message verbatim, else the message is
|
|
114
|
+
`Agent turn failed: <status>`. A message that is a code rather than a sentence may be accompanied by a flat `data`
|
|
115
|
+
object of strings and numbers — the values whoever resolves the code interpolates into its text; a host that does
|
|
116
|
+
not know the code shows the message as it stands.
|
|
117
|
+
|
|
118
|
+
The event also carries `code`, read from a JSON body whether or not it has a message: the dictionary key
|
|
119
|
+
(`<module>.error.<key>`) in the body's `error`, `message` or `code`, else its `code` when that is one camelCase
|
|
120
|
+
token, else the status's name (`unauthorized`, `forbidden`, `tooManyRequests`, `internalError`, or `http<status>`
|
|
121
|
+
for a status with no name). A 401 or 403 takes no dictionary key: it is its `code` token, else its status's name. A
|
|
122
|
+
body's `code` shaped otherwise, such as a proxy's `ECONNRESET`, is dropped rather than passed on, and a body that is
|
|
123
|
+
not JSON, such as a proxy's HTML page, leaves the status's name. A 5xx is no exception: its token is taken too, and
|
|
124
|
+
on the akan server it comes from the failed error's own JSON when that carries one, which can be a third-party
|
|
125
|
+
library's rather than the server's own. The bound is what keeps prose out of it.
|
|
126
|
+
|
|
127
|
+
A server names a failure inside the stream by this same rule, applied to the body it would have answered with, so a
|
|
128
|
+
host sees one code whether the failure came before or after the stream opened. The akan server does, with two
|
|
129
|
+
exceptions. In detailed mode (development, or `AKAN_ERROR_DETAIL=1`) a generalized JSON answer's `error` is the raw
|
|
130
|
+
message, which reads as a key over JSON when it is one. And an app's own forwarded `AkanError` 401 or 403 whose
|
|
131
|
+
JSON carries a code is named by that code over JSON but by its status in the stream; none of the framework's own
|
|
132
|
+
errors is such a refusal. The code is what a host branches on, since the message may reach it already translated.
|
|
133
|
+
The session keeps it on the failed assistant message as `errorCode`, which is never sent back.
|
|
117
134
|
|
|
118
135
|
**A refusal because the prompt no longer fits the window carries `"overflow": { "limit": 128000 }`** (`limit` only
|
|
119
|
-
when the
|
|
120
|
-
|
|
136
|
+
when the refusal named it). With `requested` beside it, both are in the refusal's own unit — a byte cap included —
|
|
137
|
+
and the session scales its own estimate of the refused prompt by their ratio; `limit` alone is a window in tokens. It
|
|
138
|
+
is the one refusal a session can answer by itself: it summarizes the transcript and asks again, once, and remembers
|
|
139
|
+
the window for the rest of the conversation. Flag nothing else with it — a rate
|
|
121
140
|
limit flagged as overflow compacts a conversation that fit.
|
|
122
141
|
|
|
123
142
|
## Streaming
|
|
@@ -125,6 +144,6 @@ limit flagged as overflow compacts a conversation that fit.
|
|
|
125
144
|
The same endpoint may answer `text/event-stream` instead when the request's `accept` names it: one `RunnerEvent`
|
|
126
145
|
(`types.ts`) JSON object per SSE `data:` line, ending with the `done` event. A failure after the stream opened
|
|
127
146
|
travels as one `error` event — the status line is already gone by then. `usage` and `limits` ride the `done` event
|
|
128
|
-
and `overflow` the `error` event, in the same shapes as above
|
|
129
|
-
`accept: text/event-stream, application/json` and branches on the response's content type, so a
|
|
130
|
-
streams keeps answering the single JSON object above unchanged.
|
|
147
|
+
and `overflow` and `code` the `error` event, in the same shapes and bounds as above, `code` named by the rule above.
|
|
148
|
+
`httpRunner` sends `accept: text/event-stream, application/json` and branches on the response's content type, so a
|
|
149
|
+
server that never streams keeps answering the single JSON object above unchanged.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
const errKey = /^[A-Za-z][\w$-]{0,63}\.error\.[\w$.-]{1,120}$/;
|
|
4
|
+
const token = /^[a-z][A-Za-z0-9]{0,63}$/;
|
|
5
|
+
|
|
6
|
+
export const isFailureCode = (value: unknown): value is string =>
|
|
7
|
+
typeof value === "string" && (errKey.test(value) || token.test(value));
|
|
8
|
+
|
|
9
|
+
const statusCodes: { readonly [status: number]: string } = {
|
|
10
|
+
400: "badRequest",
|
|
11
|
+
401: "unauthorized",
|
|
12
|
+
403: "forbidden",
|
|
13
|
+
404: "notFound",
|
|
14
|
+
409: "conflict",
|
|
15
|
+
413: "payloadTooLarge",
|
|
16
|
+
415: "unsupportedMediaType",
|
|
17
|
+
429: "tooManyRequests",
|
|
18
|
+
500: "internalError",
|
|
19
|
+
502: "badGateway",
|
|
20
|
+
503: "serviceUnavailable",
|
|
21
|
+
504: "gatewayTimeout",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const codeOfStatus = (status: number): string => statusCodes[status] ?? `http${status}`;
|
|
25
|
+
|
|
26
|
+
const isKey = (value: unknown): value is string => typeof value === "string" && errKey.test(value);
|
|
27
|
+
|
|
28
|
+
export const codeOfAnswer = (status: number, body: unknown): string => {
|
|
29
|
+
const fields = (typeof body === "object" && body !== null ? body : {}) as {
|
|
30
|
+
code?: unknown;
|
|
31
|
+
error?: unknown;
|
|
32
|
+
message?: unknown;
|
|
33
|
+
};
|
|
34
|
+
const kept = typeof fields.code === "string" && token.test(fields.code) ? fields.code : undefined;
|
|
35
|
+
if (status === 401 || status === 403) return kept ?? codeOfStatus(status);
|
|
36
|
+
return [fields.error, fields.message, fields.code].find(isKey) ?? kept ?? codeOfStatus(status);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const failureCodeOf = (value: unknown): string | undefined => {
|
|
40
|
+
if (typeof value !== "object" || value === null) return undefined;
|
|
41
|
+
const { code, error } = value as { code?: unknown; error?: unknown };
|
|
42
|
+
if (typeof error === "string" && errKey.test(error)) return error;
|
|
43
|
+
return typeof code === "string" && token.test(code) ? code : undefined;
|
|
44
|
+
};
|