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
|
@@ -32,6 +32,7 @@ import { SqlDocumentStore } from "./sql/SqlDocumentStore";
|
|
|
32
32
|
import { SqliteInsightSession } from "./sql/SqliteInsightSession";
|
|
33
33
|
import { TransactionScope } from "./sql/TransactionScope";
|
|
34
34
|
import {
|
|
35
|
+
type AfterCommitOptions,
|
|
35
36
|
BASE_COLUMNS,
|
|
36
37
|
type ConcurrentIndexBuild,
|
|
37
38
|
type CreateIndexProps,
|
|
@@ -57,19 +58,23 @@ export {
|
|
|
57
58
|
} from "./sql/RawDocumentTable";
|
|
58
59
|
export { SqlDocumentStore } from "./sql/SqlDocumentStore";
|
|
59
60
|
export type {
|
|
61
|
+
AfterCommitOptions,
|
|
60
62
|
AkanSqlClient,
|
|
61
63
|
AkanSqlStatement,
|
|
62
64
|
DatabaseAdaptor,
|
|
63
65
|
DatabaseConfig,
|
|
64
66
|
DocumentDatabaseOwner,
|
|
65
67
|
DocumentStore,
|
|
68
|
+
DocumentWriteListener,
|
|
66
69
|
InsightSession,
|
|
67
70
|
PostgresDatabaseConfig,
|
|
71
|
+
PrunedIndex,
|
|
68
72
|
SearchConfig,
|
|
69
73
|
SqlDialect,
|
|
70
74
|
SqliteDatabaseConfig,
|
|
71
75
|
SqlResultRows,
|
|
72
76
|
TransferRow,
|
|
77
|
+
UndeclaredIndex,
|
|
73
78
|
UpsertByIdOptions,
|
|
74
79
|
} from "./sql/types";
|
|
75
80
|
export { descriptorHash, stableJson } from "./sql/values";
|
|
@@ -114,17 +119,21 @@ export class SqliteDatabase
|
|
|
114
119
|
#ensures = new PendingStoreEnsures();
|
|
115
120
|
#searchIndex!: SearchIndex;
|
|
116
121
|
|
|
117
|
-
#open:
|
|
122
|
+
#open: TransactionContext | null = null;
|
|
123
|
+
#inMemory = false;
|
|
124
|
+
#committed: Uint8Array | null = null;
|
|
118
125
|
#queue: Promise<void> = Promise.resolve();
|
|
119
126
|
|
|
120
127
|
override async onInit() {
|
|
121
128
|
|
|
122
129
|
await mkdir(path.dirname(path.resolve(this.config.filePath)), { recursive: true });
|
|
123
130
|
this.#db = new Database(this.config.filePath, { strict: true, create: true });
|
|
131
|
+
this.#inMemory = !this.#mainFile();
|
|
124
132
|
this.#client = new BunSqliteClient(
|
|
125
133
|
this.#db,
|
|
126
134
|
() => this.#writeTurn(),
|
|
127
135
|
() => this.#readerOf(),
|
|
136
|
+
!this.#inMemory,
|
|
128
137
|
);
|
|
129
138
|
this.#db.run(`PRAGMA journal_mode = ${this.config.journalMode ?? "WAL"}`);
|
|
130
139
|
this.#db.run(`PRAGMA busy_timeout = ${this.config.busyTimeoutMs ?? 5000}`);
|
|
@@ -158,7 +167,8 @@ export class SqliteDatabase
|
|
|
158
167
|
|
|
159
168
|
#openReader() {
|
|
160
169
|
const file = this.#mainFile();
|
|
161
|
-
if (!file
|
|
170
|
+
if (!file) return null;
|
|
171
|
+
if (this.#db.query("PRAGMA journal_mode").values().at(0)?.at(0) !== "wal") this.#db.run("PRAGMA cache_spill = OFF");
|
|
162
172
|
const reader = new Database(file, { readonly: true, strict: true });
|
|
163
173
|
reader.run(`PRAGMA busy_timeout = ${this.config.busyTimeoutMs ?? 5000}`);
|
|
164
174
|
if (this.config.cacheSize) reader.run(`PRAGMA cache_size = ${this.config.cacheSize}`);
|
|
@@ -183,7 +193,8 @@ export class SqliteDatabase
|
|
|
183
193
|
|
|
184
194
|
async openInsight(): Promise<InsightSession> {
|
|
185
195
|
const file = this.#mainFile();
|
|
186
|
-
|
|
196
|
+
if (file) return SqliteInsightSession.open(file);
|
|
197
|
+
return await SqliteInsightSession.openSnapshot((this.#readerOf() ?? this.#db).serialize());
|
|
187
198
|
}
|
|
188
199
|
|
|
189
200
|
stores() {
|
|
@@ -199,9 +210,11 @@ export class SqliteDatabase
|
|
|
199
210
|
return store;
|
|
200
211
|
}
|
|
201
212
|
|
|
202
|
-
getMeta(key: string) {
|
|
203
|
-
const row =
|
|
204
|
-
|
|
213
|
+
async getMeta(key: string) {
|
|
214
|
+
const row = await this.#client
|
|
215
|
+
.prepare(`SELECT "value" FROM "_akan_meta" WHERE "key" = ?`)
|
|
216
|
+
.get<{ value: string }>(key);
|
|
217
|
+
return row?.value;
|
|
205
218
|
}
|
|
206
219
|
|
|
207
220
|
async setMeta(key: string, value: string) {
|
|
@@ -212,10 +225,10 @@ export class SqliteDatabase
|
|
|
212
225
|
.run(key, value, Date.now());
|
|
213
226
|
}
|
|
214
227
|
|
|
215
|
-
listMeta(prefix: string) {
|
|
216
|
-
return
|
|
217
|
-
.
|
|
218
|
-
.all
|
|
228
|
+
async listMeta(prefix: string) {
|
|
229
|
+
return await this.#client
|
|
230
|
+
.prepare(`SELECT "key", "value" FROM "_akan_meta" WHERE substr("key", 1, ?) = ?`)
|
|
231
|
+
.all<{ key: string; value: string }>(prefix.length, prefix);
|
|
219
232
|
}
|
|
220
233
|
|
|
221
234
|
async deleteMeta(key: string) {
|
|
@@ -232,9 +245,10 @@ export class SqliteDatabase
|
|
|
232
245
|
this.#queue = done;
|
|
233
246
|
await previous;
|
|
234
247
|
const context: TransactionContext = { afterCommit: [] };
|
|
235
|
-
this.#open = { context, done };
|
|
236
248
|
let result: T;
|
|
237
249
|
try {
|
|
250
|
+
this.#keepCommitted();
|
|
251
|
+
this.#open = context;
|
|
238
252
|
result = await this.#transaction.run(context, async () => {
|
|
239
253
|
this.#db.run("BEGIN IMMEDIATE");
|
|
240
254
|
try {
|
|
@@ -249,6 +263,7 @@ export class SqliteDatabase
|
|
|
249
263
|
} finally {
|
|
250
264
|
context.closed = true;
|
|
251
265
|
this.#open = null;
|
|
266
|
+
this.#dropCommitted();
|
|
252
267
|
release();
|
|
253
268
|
}
|
|
254
269
|
await TransactionScope.runAfterCommit(context);
|
|
@@ -256,19 +271,43 @@ export class SqliteDatabase
|
|
|
256
271
|
}
|
|
257
272
|
|
|
258
273
|
#writeTurn() {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
274
|
+
if (!this.#open || this.#transaction.getStore() === this.#open) return null;
|
|
275
|
+
return this.#queue;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
#keepCommitted() {
|
|
279
|
+
if (this.#inMemory) this.#committed = this.#db.serialize();
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
#dropBytes() {
|
|
283
|
+
(this.#committed?.buffer as ArrayBuffer | undefined)?.transfer(0);
|
|
284
|
+
this.#committed = null;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
#dropCommitted() {
|
|
288
|
+
if (!this.#inMemory) return;
|
|
289
|
+
this.#dropBytes();
|
|
290
|
+
this.#reader?.close();
|
|
291
|
+
this.#reader = null;
|
|
262
292
|
}
|
|
263
293
|
|
|
264
294
|
#readerOf() {
|
|
265
|
-
|
|
295
|
+
if (!this.#writeTurn()) return null;
|
|
296
|
+
if (this.#committed) {
|
|
297
|
+
this.#reader = Database.deserialize(this.#committed, { readonly: true, strict: true });
|
|
298
|
+
this.#dropBytes();
|
|
299
|
+
}
|
|
300
|
+
return this.#reader;
|
|
266
301
|
}
|
|
267
302
|
|
|
268
|
-
async afterCommit(fn: () => PromiseOrObject<void
|
|
303
|
+
async afterCommit(fn: () => PromiseOrObject<void>, options: AfterCommitOptions = {}) {
|
|
269
304
|
const active = TransactionScope.live(this.#transaction);
|
|
270
305
|
if (!active) return await fn();
|
|
271
|
-
|
|
306
|
+
TransactionScope.queue(active, fn, options);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
transactionKey(): object | undefined {
|
|
310
|
+
return TransactionScope.live(this.#transaction);
|
|
272
311
|
}
|
|
273
312
|
|
|
274
313
|
checkpoint(mode: "PASSIVE" | "FULL" | "RESTART" | "TRUNCATE" = "TRUNCATE") {
|
|
@@ -509,10 +548,14 @@ export class PostgresDatabase
|
|
|
509
548
|
return result;
|
|
510
549
|
}
|
|
511
550
|
|
|
512
|
-
async afterCommit(fn: () => PromiseOrObject<void
|
|
551
|
+
async afterCommit(fn: () => PromiseOrObject<void>, options: AfterCommitOptions = {}) {
|
|
513
552
|
const active = TransactionScope.live(this.#transaction);
|
|
514
553
|
if (!active) return await fn();
|
|
515
|
-
|
|
554
|
+
TransactionScope.queue(active, fn, options);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
transactionKey(): object | undefined {
|
|
558
|
+
return TransactionScope.live(this.#transaction);
|
|
516
559
|
}
|
|
517
560
|
|
|
518
561
|
async lockSchema<T>(fn: () => Promise<T>): Promise<T> {
|
|
@@ -2,6 +2,11 @@ export interface AgentWireToolCall {
|
|
|
2
2
|
id: string;
|
|
3
3
|
name: string;
|
|
4
4
|
args: Record<string, unknown>;
|
|
5
|
+
/**
|
|
6
|
+
* Set by an adaptor when a finished answer's arguments were not one JSON object, and `args` is then `{}`: why, for
|
|
7
|
+
* the call to be answered with as its error, never run, so the model can write it again.
|
|
8
|
+
*/
|
|
9
|
+
argsError?: string;
|
|
5
10
|
}
|
|
6
11
|
|
|
7
12
|
export interface AgentWireToolResult {
|
|
@@ -53,6 +58,13 @@ export interface AgentWireMessage {
|
|
|
53
58
|
error?: string;
|
|
54
59
|
/** A compaction summary: it arrives with the user's role but is history, not an ask, and a provider frames it so. */
|
|
55
60
|
summary?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* On a summary or tool message `agentService.loop` wrote: whether its run had read a result that taints it.
|
|
63
|
+
* Absent on a summary, nothing judged what it replaced, so a resumed run counts it as tainted.
|
|
64
|
+
*/
|
|
65
|
+
tainted?: boolean;
|
|
66
|
+
/** On a summary `agentService.loop` wrote: the toolkits its run had opened, which the messages it replaced recorded. */
|
|
67
|
+
toolkits?: string[];
|
|
56
68
|
}
|
|
57
69
|
|
|
58
70
|
export interface AgentWireTool {
|
|
@@ -155,7 +167,18 @@ export interface LlmOption {
|
|
|
155
167
|
|
|
156
168
|
export const llmCallSignal = (signal?: AbortSignal): AbortSignal => {
|
|
157
169
|
const timeout = AbortSignal.timeout(120_000);
|
|
158
|
-
|
|
170
|
+
if (!signal) return timeout;
|
|
171
|
+
const call = new AbortController();
|
|
172
|
+
const stop = () =>
|
|
173
|
+
call.abort(
|
|
174
|
+
Object.assign(new DOMException("The caller stopped this model call.", "AbortError"), { cause: signal.reason }),
|
|
175
|
+
);
|
|
176
|
+
if (signal.aborted) stop();
|
|
177
|
+
else {
|
|
178
|
+
signal.addEventListener("abort", stop, { once: true });
|
|
179
|
+
timeout.addEventListener("abort", () => signal.removeEventListener("abort", stop), { once: true });
|
|
180
|
+
}
|
|
181
|
+
return AbortSignal.any([timeout, call.signal]);
|
|
159
182
|
};
|
|
160
183
|
|
|
161
184
|
export const pageContentInstruction =
|
|
@@ -2,14 +2,16 @@ import { FailureCode } from "akanjs/common";
|
|
|
2
2
|
import {
|
|
3
3
|
type AgentWireAttachment,
|
|
4
4
|
type AgentWireMessage,
|
|
5
|
+
type AgentWireTool,
|
|
5
6
|
type LlmAccepts,
|
|
6
7
|
type LlmTurnAnswer,
|
|
7
8
|
type LlmTurnRequest,
|
|
8
9
|
type LlmUsage,
|
|
9
10
|
pageContentInstruction,
|
|
10
11
|
} from "./llm.adaptor";
|
|
12
|
+
import { LlmOverflow } from "./llmOverflow";
|
|
11
13
|
import { LlmSpend } from "./llmSpend";
|
|
12
|
-
import { eachSseData } from "./sseData";
|
|
14
|
+
import { eachSseData, inBandStatus, isStreamCut, parseToolArgs, toolCallOf } from "./sseData";
|
|
13
15
|
|
|
14
16
|
export interface OpenaiToolCall {
|
|
15
17
|
id?: string;
|
|
@@ -25,7 +27,14 @@ export interface OpenaiAnswer {
|
|
|
25
27
|
choices?: { message?: { content?: string | null; tool_calls?: OpenaiToolCall[] }; finish_reason?: string }[];
|
|
26
28
|
usage?: OpenaiUsage | null;
|
|
27
29
|
}
|
|
28
|
-
interface
|
|
30
|
+
interface OpenaiStreamError {
|
|
31
|
+
message?: unknown;
|
|
32
|
+
code?: unknown;
|
|
33
|
+
type?: unknown;
|
|
34
|
+
}
|
|
35
|
+
interface OpenaiStreamChunk extends OpenaiStreamError {
|
|
36
|
+
error?: OpenaiStreamError | string;
|
|
37
|
+
object?: string;
|
|
29
38
|
usage?: OpenaiUsage | null;
|
|
30
39
|
choices?: {
|
|
31
40
|
delta?: {
|
|
@@ -37,6 +46,12 @@ interface OpenaiStreamChunk {
|
|
|
37
46
|
}
|
|
38
47
|
type OpenaiImagePart = { type: "image_url"; image_url: { url: string } };
|
|
39
48
|
type OpenaiContentPart = { type: "text"; text: string } | OpenaiImagePart;
|
|
49
|
+
interface OpenaiStreamedCall {
|
|
50
|
+
index: number;
|
|
51
|
+
id?: string;
|
|
52
|
+
name?: string;
|
|
53
|
+
args: string;
|
|
54
|
+
}
|
|
40
55
|
export interface OpenaiMessage {
|
|
41
56
|
role: "system" | "user" | "assistant" | "tool";
|
|
42
57
|
content: string | OpenaiContentPart[];
|
|
@@ -188,14 +203,24 @@ export class OpenaiDialect {
|
|
|
188
203
|
static async consumeStream(
|
|
189
204
|
body: ReadableStream<Uint8Array>,
|
|
190
205
|
onDelta: (delta: string) => void,
|
|
206
|
+
host = "The model provider",
|
|
207
|
+
tools: AgentWireTool[] = [],
|
|
191
208
|
): Promise<LlmTurnAnswer> {
|
|
192
|
-
const
|
|
209
|
+
const open = new Map<number, OpenaiStreamedCall>();
|
|
210
|
+
const calls: OpenaiStreamedCall[] = [];
|
|
193
211
|
let text = "";
|
|
194
212
|
let finish: string | null = null;
|
|
213
|
+
let done = false;
|
|
214
|
+
let failure: Error | null = null;
|
|
195
215
|
let usage: LlmUsage | undefined;
|
|
196
216
|
const read = eachSseData(body, (payload) => {
|
|
197
|
-
if (payload === "[DONE]")
|
|
217
|
+
if (payload === "[DONE]") {
|
|
218
|
+
done = true;
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
198
221
|
const chunk = JSON.parse(payload) as OpenaiStreamChunk;
|
|
222
|
+
if (chunk.error) failure = OpenaiDialect.#streamFailure(host, chunk.error);
|
|
223
|
+
else if (chunk.object === "error") failure = OpenaiDialect.#streamFailure(host, chunk);
|
|
199
224
|
if (chunk.usage) usage = OpenaiDialect.usageOf(chunk.usage);
|
|
200
225
|
const choice = chunk.choices?.[0];
|
|
201
226
|
if (!choice) return;
|
|
@@ -205,31 +230,55 @@ export class OpenaiDialect {
|
|
|
205
230
|
}
|
|
206
231
|
for (const fragment of choice.delta?.tool_calls ?? []) {
|
|
207
232
|
const index = fragment.index ?? 0;
|
|
208
|
-
|
|
233
|
+
let call = open.get(index);
|
|
234
|
+
|
|
235
|
+
if (!call || (fragment.id && call.id && fragment.id !== call.id)) {
|
|
236
|
+
call = { index, args: "" };
|
|
237
|
+
open.set(index, call);
|
|
238
|
+
calls.push(call);
|
|
239
|
+
}
|
|
209
240
|
if (fragment.id) call.id = fragment.id;
|
|
210
241
|
if (fragment.function?.name) call.name = fragment.function.name;
|
|
211
242
|
if (fragment.function?.arguments) call.args += fragment.function.arguments;
|
|
212
|
-
calls.set(index, call);
|
|
213
243
|
}
|
|
214
244
|
if (choice.finish_reason) finish = choice.finish_reason;
|
|
245
|
+
|
|
246
|
+
if (choice.finish_reason === "error") failure ??= OpenaiDialect.#streamFailure(host, "no reason given");
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
const failed = read.then(() => {
|
|
250
|
+
if (failure) throw failure;
|
|
215
251
|
});
|
|
216
|
-
await
|
|
217
|
-
const streamed = text +
|
|
252
|
+
await failed.catch((error: unknown) => {
|
|
253
|
+
const streamed = text + calls.map(({ args }) => args).join("");
|
|
218
254
|
throw LlmSpend.attach(error, usage ? { usage } : LlmSpend.estimate(undefined, { streamed }));
|
|
219
255
|
});
|
|
220
|
-
const toolCalls = [...calls
|
|
221
|
-
.sort((
|
|
222
|
-
.flatMap(([, call])
|
|
223
|
-
call.id && call.name ? [{ id: call.id, name: call.name, args: OpenaiDialect.parsedArgs(call.args) }] : [],
|
|
224
|
-
);
|
|
256
|
+
const toolCalls = [...calls]
|
|
257
|
+
.sort((a, b) => a.index - b.index)
|
|
258
|
+
.flatMap((call) => (call.id && call.name ? [toolCallOf(call.id, call.name, call.args)] : []));
|
|
225
259
|
return {
|
|
226
260
|
...(text ? { text } : {}),
|
|
227
261
|
...(toolCalls.length ? { toolCalls } : {}),
|
|
228
|
-
stop:
|
|
262
|
+
stop: isStreamCut(
|
|
263
|
+
calls,
|
|
264
|
+
{ ended: finish !== null || done, finished: finish !== null, byModel: OpenaiDialect.#finishedByModel(finish) },
|
|
265
|
+
tools,
|
|
266
|
+
)
|
|
267
|
+
? "length"
|
|
268
|
+
: OpenaiDialect.stopOf(finish, toolCalls.length),
|
|
229
269
|
...(usage ? { usage } : {}),
|
|
230
270
|
};
|
|
231
271
|
}
|
|
232
272
|
|
|
273
|
+
static #streamFailure(host: string, error: OpenaiStreamError | string): Error {
|
|
274
|
+
const { message, code, type } = typeof error === "string" ? { message: error } : error;
|
|
275
|
+
return LlmOverflow.refusal(
|
|
276
|
+
host,
|
|
277
|
+
inBandStatus(code, type),
|
|
278
|
+
typeof message === "string" && message ? message : "no reason given",
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
|
|
233
282
|
static usageOf(usage: OpenaiUsage): LlmUsage {
|
|
234
283
|
return {
|
|
235
284
|
inputTokens: usage.prompt_tokens ?? 0,
|
|
@@ -244,29 +293,29 @@ export class OpenaiDialect {
|
|
|
244
293
|
return finish === "tool_calls" || calls ? "toolUse" : "end";
|
|
245
294
|
}
|
|
246
295
|
|
|
296
|
+
static #finishedByModel(finish: string | null | undefined): boolean {
|
|
297
|
+
return finish === "tool_calls" || finish === "stop";
|
|
298
|
+
}
|
|
299
|
+
|
|
247
300
|
static turnAnswer(answer: OpenaiAnswer): LlmTurnAnswer {
|
|
248
301
|
const choice = answer.choices?.[0];
|
|
249
302
|
const toolCalls = (choice?.message?.tool_calls ?? []).flatMap((call) => {
|
|
250
303
|
if (!call.id || !call.function?.name) return [];
|
|
251
|
-
return [
|
|
304
|
+
return [toolCallOf(call.id, call.function.name, call.function.arguments)];
|
|
252
305
|
});
|
|
306
|
+
const cut =
|
|
307
|
+
!OpenaiDialect.#finishedByModel(choice?.finish_reason) && toolCalls.some((call) => call.argsError !== undefined);
|
|
253
308
|
return {
|
|
254
309
|
...(choice?.message?.content ? { text: choice.message.content } : {}),
|
|
255
310
|
...(toolCalls.length ? { toolCalls } : {}),
|
|
256
|
-
stop: OpenaiDialect.stopOf(choice?.finish_reason, toolCalls.length),
|
|
311
|
+
stop: cut ? "length" : OpenaiDialect.stopOf(choice?.finish_reason, toolCalls.length),
|
|
257
312
|
...(answer.usage ? { usage: OpenaiDialect.usageOf(answer.usage) } : {}),
|
|
258
313
|
};
|
|
259
314
|
}
|
|
260
315
|
|
|
261
316
|
/** The provider sends arguments as a JSON string; an unparsable one becomes an empty call rather than a crash. */
|
|
262
317
|
static parsedArgs(raw: string | undefined): Record<string, unknown> {
|
|
263
|
-
|
|
264
|
-
try {
|
|
265
|
-
const parsed: unknown = JSON.parse(raw);
|
|
266
|
-
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? (parsed as Record<string, unknown>) : {};
|
|
267
|
-
} catch {
|
|
268
|
-
return {};
|
|
269
|
-
}
|
|
318
|
+
return parseToolArgs(raw) ?? {};
|
|
270
319
|
}
|
|
271
320
|
|
|
272
321
|
/** The dialect refuses as `{ error: { message } }`, and that sentence names the limit a long prompt passed. */
|
|
@@ -75,7 +75,7 @@ export class OpenaiLlm
|
|
|
75
75
|
OpenaiDialect.requestBody(model, request, { accepts, stream: true }),
|
|
76
76
|
signal,
|
|
77
77
|
);
|
|
78
|
-
return { ...(await OpenaiDialect.consumeStream(body, onDelta)), model };
|
|
78
|
+
return { ...(await OpenaiDialect.consumeStream(body, onDelta, this.#host, request.tools)), model };
|
|
79
79
|
} catch (error) {
|
|
80
80
|
|
|
81
81
|
if (!signal?.aborted)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type AdaptorCls, adapt } from "../adapt";
|
|
2
|
+
import type { AgentToolsAdaptor } from "./agentTools.adaptor";
|
|
2
3
|
import type { CacheAdaptor } from "./cache.adaptor";
|
|
3
4
|
import type { CompressAdaptor } from "./compress.adaptor";
|
|
4
5
|
import type { DatabaseAdaptor } from "./database.adaptor";
|
|
@@ -18,3 +19,4 @@ export const LoggingAdaptorRole = adapt("loggingAdaptorRole") as AdaptorCls<Logg
|
|
|
18
19
|
export const WebsocketAdaptorRole = adapt("websocketAdaptorRole") as AdaptorCls<WebsocketAdaptor>;
|
|
19
20
|
export const CompressAdaptorRole = adapt("compressAdaptorRole") as AdaptorCls<CompressAdaptor>;
|
|
20
21
|
export const LlmAdaptorRole = adapt("llmAdaptorRole") as AdaptorCls<LlmAdaptor>;
|
|
22
|
+
export const AgentToolsRole = adapt("agentToolsRole") as AdaptorCls<AgentToolsAdaptor>;
|
|
@@ -22,16 +22,33 @@ export class SolidPubSub
|
|
|
22
22
|
const { appName, environment, operationMode } = getEnv();
|
|
23
23
|
return `${appName}-${environment}-${operationMode}-${process.env.AKAN_REPLICA_IDX ?? "0"}-${process.pid}`;
|
|
24
24
|
}),
|
|
25
|
+
|
|
26
|
+
behindGateway: env(() => !!process.env.AKAN_CHILD_SOCKET),
|
|
25
27
|
}))
|
|
26
28
|
implements WebsocketAdaptor
|
|
27
29
|
{
|
|
30
|
+
|
|
31
|
+
static readonly #ackTimeoutMs = 3_000;
|
|
28
32
|
readonly #socketRooms = new Map<string, Set<string>>();
|
|
33
|
+
readonly #acks = new Map<number, () => void>();
|
|
34
|
+
#lastAck = 0;
|
|
29
35
|
#eventHandler: WsRedisEventHandler | null = null;
|
|
30
36
|
#changeHandler: LiveChangeHandler | null = null;
|
|
31
37
|
#liveModels: string[] = [];
|
|
32
38
|
readonly #messageHandler = (message: unknown) => {
|
|
33
39
|
if (!message || typeof message !== "object") return;
|
|
34
|
-
const data = message as {
|
|
40
|
+
const data = message as {
|
|
41
|
+
type?: string;
|
|
42
|
+
roomId?: string;
|
|
43
|
+
data?: unknown;
|
|
44
|
+
origin?: string;
|
|
45
|
+
change?: LiveChange;
|
|
46
|
+
ack?: number;
|
|
47
|
+
};
|
|
48
|
+
if (data.type === "pubsub.subscribed" && data.ack !== undefined) {
|
|
49
|
+
this.#acks.get(data.ack)?.();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
35
52
|
if (data.type === "pubsub.deliver" && data.roomId && data.origin !== this.serverId) {
|
|
36
53
|
this.#eventHandler?.(data.roomId, data.data);
|
|
37
54
|
return;
|
|
@@ -56,6 +73,8 @@ export class SolidPubSub
|
|
|
56
73
|
|
|
57
74
|
override async onDestroy() {
|
|
58
75
|
process.off("message", this.#messageHandler);
|
|
76
|
+
for (const answer of this.#acks.values()) answer();
|
|
77
|
+
this.#acks.clear();
|
|
59
78
|
this.#eventHandler = null;
|
|
60
79
|
this.#changeHandler = null;
|
|
61
80
|
this.#liveModels = [];
|
|
@@ -92,7 +111,21 @@ export class SolidPubSub
|
|
|
92
111
|
const rooms = this.#socketRooms.get(socketId) ?? new Set<string>();
|
|
93
112
|
rooms.add(room);
|
|
94
113
|
this.#socketRooms.set(socketId, rooms);
|
|
95
|
-
|
|
114
|
+
if (!this.behindGateway || !process.send) {
|
|
115
|
+
sendAkanIpc({ type: "pubsub.subscribe", roomId: room, socketId, pid: process.pid });
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const ack = ++this.#lastAck;
|
|
119
|
+
const answered = Promise.withResolvers<void>();
|
|
120
|
+
this.#acks.set(ack, answered.resolve);
|
|
121
|
+
const timer = setTimeout(answered.resolve, SolidPubSub.#ackTimeoutMs);
|
|
122
|
+
sendAkanIpc({ type: "pubsub.subscribe", roomId: room, socketId, pid: process.pid, ack });
|
|
123
|
+
try {
|
|
124
|
+
await answered.promise;
|
|
125
|
+
} finally {
|
|
126
|
+
clearTimeout(timer);
|
|
127
|
+
this.#acks.delete(ack);
|
|
128
|
+
}
|
|
96
129
|
}
|
|
97
130
|
|
|
98
131
|
async leaveRoom(ws: Bun.ServerWebSocket<unknown>, room: string): Promise<void> {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Database, Statement } from "bun:sqlite";
|
|
2
|
-
import { getEnv } from "akanjs/base";
|
|
2
|
+
import { AkanError, getEnv } from "akanjs/base";
|
|
3
3
|
import { adapt } from "../adapt";
|
|
4
4
|
import { type AkanJob, type AkanJobOptions, type AkanWorker, sendAkanIpc } from "../ipcTypes";
|
|
5
5
|
import type { ProcessWorkerOptions, QueueAdaptor } from "./queue.adaptor";
|
|
@@ -231,7 +231,7 @@ export class SolidQueue
|
|
|
231
231
|
for (const row of rows) {
|
|
232
232
|
const payload = JSON.parse(row.payload) as { args: unknown[]; opts?: AkanJobOptions };
|
|
233
233
|
const job = { id: row.id, name: row.name, data: payload.args, attemptsMade: row.attempts, opts: payload.opts };
|
|
234
|
-
await this.#fail(job, new
|
|
234
|
+
await this.#fail(job, new AkanError("jobStalled", message), message, onFailed);
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Database } from "bun:sqlite";
|
|
2
2
|
import { mkdir } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import type
|
|
4
|
+
import { AkanError, type Dayjs } from "akanjs/base";
|
|
5
5
|
import { defaultSqliteFile } from "./sqlitePath";
|
|
6
6
|
|
|
7
7
|
export interface SolidConfig {
|
|
@@ -43,19 +43,22 @@ export const openSolidDatabase = async (config: Required<SolidConfig>) => {
|
|
|
43
43
|
await mkdir(path.dirname(path.resolve(config.filePath)), { recursive: true });
|
|
44
44
|
let lastError: unknown;
|
|
45
45
|
for (let attempt = 0; attempt < 8; attempt++) {
|
|
46
|
+
let db: Database | undefined;
|
|
46
47
|
try {
|
|
47
|
-
|
|
48
|
+
db = new Database(config.filePath, { strict: true, create: true });
|
|
48
49
|
db.run(`PRAGMA busy_timeout = ${config.busyTimeoutMs}`);
|
|
49
50
|
db.run(`PRAGMA journal_mode = ${config.journalMode}`);
|
|
50
51
|
db.run(`PRAGMA synchronous = ${config.synchronous}`);
|
|
51
52
|
return db;
|
|
52
53
|
} catch (error) {
|
|
54
|
+
db?.close();
|
|
53
55
|
lastError = error;
|
|
54
56
|
if (!String(error instanceof Error ? error.message : error).includes("locked")) throw error;
|
|
55
57
|
await wait(50 * (attempt + 1));
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
|
-
|
|
60
|
+
const message = lastError instanceof Error ? lastError.message : String(lastError);
|
|
61
|
+
throw new AkanError("databaseLocked", message, { cause: lastError });
|
|
59
62
|
};
|
|
60
63
|
|
|
61
64
|
export const encodeSolidValue = (value: unknown): { type: SolidValueType; value: string | Buffer } => {
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { type DocumentTouchOptions, sanitizeJson } from "akanjs/document";
|
|
2
|
+
import { DocumentStoreError } from "../../documentStoreError";
|
|
3
|
+
import type { DocumentRowCodec } from "./DocumentRowCodec";
|
|
4
|
+
import type { SqlDocumentStore } from "./SqlDocumentStore";
|
|
5
|
+
import { type StoredRead, StoredRows } from "./StoredRows";
|
|
6
|
+
import { type DocumentRecord, MODIFICATION_STATE, type ModificationState } from "./types";
|
|
7
|
+
|
|
8
|
+
export class DocumentHydrator {
|
|
9
|
+
readonly #store: SqlDocumentStore;
|
|
10
|
+
readonly #codec: DocumentRowCodec;
|
|
11
|
+
readonly #rows: StoredRows;
|
|
12
|
+
#docPrototype: object | null = null;
|
|
13
|
+
|
|
14
|
+
constructor(store: SqlDocumentStore, codec: DocumentRowCodec, rows: StoredRows) {
|
|
15
|
+
this.#store = store;
|
|
16
|
+
this.#codec = codec;
|
|
17
|
+
this.#rows = rows;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
hydrate(data: DocumentRecord, originalData: DocumentRecord = data, { track = true }: { track?: boolean } = {}) {
|
|
21
|
+
const isNew = !originalData.id;
|
|
22
|
+
const hydratedData = isNew ? this.#codec.prepareDocument(data) : data;
|
|
23
|
+
const doc = Object.assign(Object.create(this.#documentPrototype()), hydratedData);
|
|
24
|
+
if (!track) return doc;
|
|
25
|
+
Object.defineProperty(doc, MODIFICATION_STATE, {
|
|
26
|
+
value: {
|
|
27
|
+
isNew,
|
|
28
|
+
|
|
29
|
+
original: JSON.parse(JSON.stringify(sanitizeJson(originalData) ?? {})) as Record<string, unknown>,
|
|
30
|
+
} satisfies ModificationState,
|
|
31
|
+
});
|
|
32
|
+
return doc;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#documentPrototype() {
|
|
36
|
+
if (this.#docPrototype) return this.#docPrototype;
|
|
37
|
+
const store = this.#store;
|
|
38
|
+
const rows = this.#rows;
|
|
39
|
+
this.#docPrototype = Object.create(store.database.doc.prototype, {
|
|
40
|
+
set: {
|
|
41
|
+
value(this: DocumentRecord, patch: DocumentRecord) {
|
|
42
|
+
Object.assign(this, patch);
|
|
43
|
+
return this;
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
save: {
|
|
47
|
+
async value(this: DocumentRecord, { touch }: DocumentTouchOptions = {}) {
|
|
48
|
+
if (!this.id) return store.create(this);
|
|
49
|
+
rows.assertLiveRow(this);
|
|
50
|
+
return store.update(this.id as string, rows.changesOf(this), touch === false ? { touch } : {});
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
refresh: {
|
|
54
|
+
async value(this: DocumentRecord) {
|
|
55
|
+
const fresh = (await store.pickById(this.id as string)) as DocumentRecord & Record<symbol, StoredRead>;
|
|
56
|
+
Object.assign(this, fresh);
|
|
57
|
+
Reflect.deleteProperty(this, StoredRows.readRemoved);
|
|
58
|
+
return rows.withStoredRow(this, fresh[StoredRows.storedRow]);
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
isModified: {
|
|
62
|
+
value(this: DocumentRecord & { [MODIFICATION_STATE]?: ModificationState }, field?: string) {
|
|
63
|
+
const state = this[MODIFICATION_STATE];
|
|
64
|
+
if (!state)
|
|
65
|
+
throw new DocumentStoreError(
|
|
66
|
+
"invalidDocument",
|
|
67
|
+
DocumentHydrator.#untrackedModificationMessage(store.table),
|
|
68
|
+
);
|
|
69
|
+
if (state.isNew) return true;
|
|
70
|
+
if (!field) return JSON.stringify(sanitizeJson(this)) !== JSON.stringify(state.original);
|
|
71
|
+
return JSON.stringify(sanitizeJson(this[field])) !== JSON.stringify(state.original[field]);
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
toJSON: {
|
|
75
|
+
value(this: DocumentRecord) {
|
|
76
|
+
return sanitizeJson(this);
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
toObject: {
|
|
80
|
+
value(this: DocumentRecord) {
|
|
81
|
+
return sanitizeJson(this);
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
}) as object;
|
|
85
|
+
return this.#docPrototype;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static #untrackedModificationMessage(table: string) {
|
|
89
|
+
return (
|
|
90
|
+
`isModified() is unavailable on this ${table} document: it was loaded through a read query, which does not ` +
|
|
91
|
+
`snapshot the row. Call it inside a save hook, or re-load the document through the write path (\`save()\`, ` +
|
|
92
|
+
`\`update()\`) before comparing.`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}
|