akanjs 3.1.0-rc.2 → 3.1.0-rc.21
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/base/baseEnv.ts +5 -2
- package/client/device.ts +1 -1
- package/client/frameConfig.ts +2 -2
- package/client/href.ts +35 -0
- package/client/index.ts +1 -0
- package/client/makePageProto.tsx +3 -2
- package/client/router.ts +6 -4
- package/client/rscNavigation.ts +1 -1
- package/client/transitionTypes.ts +0 -4
- package/client/translator.ts +16 -0
- package/client/types.ts +3 -2
- package/client/viewportMeta.ts +23 -8
- package/client/webManifest.ts +5 -3
- package/common/TrustedProxy.ts +14 -0
- package/common/codeAgentWire.ts +8 -1
- package/common/index.ts +1 -0
- package/common/interpolateTranslation.ts +17 -3
- package/common/isEmail.ts +1 -1
- package/common/localeConfig.ts +10 -4
- package/common/markdownSpans.ts +1 -1
- package/common/restClient.ts +3 -1
- package/common/routeConvention.ts +4 -4
- package/common/trimSlashes.ts +11 -0
- package/common/types.ts +1 -1
- package/constant/fieldInfo.ts +2 -2
- package/constant/fieldPlan.ts +80 -0
- package/constant/index.ts +3 -0
- package/constant/inputParser.ts +148 -0
- package/constant/invalidInputError.ts +13 -0
- package/constant/serialize.ts +36 -20
- package/constant/types.ts +1 -1
- package/constant/via.ts +2 -0
- package/dictionary/base.dictionary.ts +4 -0
- package/dictionary/trans.ts +8 -0
- package/document/database.ts +3 -6
- package/document/documentSchema.ts +1 -1
- package/document/noDocumentError.ts +6 -1
- package/fetch/client/fetchClient.ts +2 -1
- package/fetch/client/sliceInitHandle.ts +2 -3
- package/fetch/fetchType/appliedReturn.type.ts +3 -1
- package/fetch/types.ts +4 -2
- package/index.ts +2 -0
- package/package.json +31 -21
- package/server/akanApp.ts +15 -3
- package/server/akanServer.ts +34 -14
- package/server/artifact/routeClientCache.ts +4 -5
- package/server/artifact/routeSeedIndexStore.ts +3 -20
- package/server/artifact/routeSeedMatcher.ts +70 -0
- package/server/console.ts +1 -1
- package/server/di/diLifecycle.ts +16 -7
- package/server/imageOptimizer.ts +1 -1
- package/server/index.ts +1 -0
- package/server/machine/machineAccount.ts +28 -3
- package/server/machine/machineToken.ts +27 -3
- package/server/mcp/McpDispatcher.ts +2 -3
- package/server/mcp/McpExecutionContext.ts +9 -3
- package/server/migration/docPath.ts +121 -0
- package/server/migration/index.ts +15 -0
- package/server/migration/migrationChangeLog.ts +86 -0
- package/server/migration/migrationChanges.ts +70 -0
- package/server/migration/migrationCommand.ts +179 -0
- package/server/migration/migrationContext.ts +53 -0
- package/server/migration/migrationDefinition.ts +87 -0
- package/server/migration/migrationError.ts +45 -0
- package/server/migration/migrationLedger.ts +172 -0
- package/server/migration/migrationLock.ts +103 -0
- package/server/migration/migrationParams.ts +122 -0
- package/server/migration/migrationPulse.ts +39 -0
- package/server/migration/migrationRunner.ts +525 -0
- package/server/migration/migrationScope.ts +93 -0
- package/server/migration/migrationTable.ts +258 -0
- package/server/migration/migrations.ts +57 -0
- package/server/ops/opsCommand.ts +30 -1
- package/server/resolver/CascadeRunner.ts +15 -2
- package/server/resolver/signal.resolver.ts +35 -55
- package/server/routeState.ts +0 -6
- package/server/rscClient.tsx +22 -37
- package/server/rscNavigationState.ts +3 -5
- package/server/rscScrollRestoration.ts +116 -0
- package/server/rscWorker.tsx +12 -19
- package/server/sitemap.ts +4 -4
- package/server/tunnel/TunnelAgent.ts +9 -1
- package/server/webRouter.ts +17 -2
- package/service/agent.service.ts +21 -1
- package/service/endpointCacheKeys.ts +35 -0
- package/service/index.ts +1 -0
- package/service/injectInfo.ts +2 -2
- package/service/predefinedAdaptor/anthropicLlm.ts +37 -17
- package/service/predefinedAdaptor/database.adaptor.ts +15 -0
- package/service/predefinedAdaptor/documentTransfer.ts +50 -0
- package/service/predefinedAdaptor/endpointCacheControl.adaptor.ts +19 -0
- package/service/predefinedAdaptor/index.ts +1 -0
- package/service/predefinedAdaptor/llm.adaptor.ts +7 -0
- package/service/predefinedAdaptor/openaiDialect.ts +53 -17
- package/service/predefinedAdaptor/openaiLlm.ts +1 -1
- package/service/predefinedAdaptor/sql/MigrationTables.ts +90 -0
- package/service/predefinedAdaptor/sql/RawDocumentTable.ts +200 -0
- package/service/predefinedAdaptor/sql/SqlDocumentStore.ts +6 -2
- package/service/predefinedAdaptor/sql/SqliteInsightSession.ts +4 -1
- package/service/predefinedAdaptor/sql/dialect/postgres.ts +0 -1
- package/service/predefinedAdaptor/sql/dialect/sqlite.ts +0 -1
- package/service/predefinedAdaptor/sql/types.ts +3 -1
- package/service/predefinedAdaptor/storage.adaptor.ts +19 -0
- package/signal/endpointCache.ts +23 -7
- package/signal/endpointErrorContract.ts +37 -0
- package/signal/endpointIdempotency.ts +5 -3
- package/signal/endpointInfo.ts +4 -1
- package/signal/endpointRateLimit.ts +6 -2
- package/signal/exception.ts +4 -1
- package/signal/index.ts +1 -0
- package/signal/mcp/McpDocument.ts +16 -1
- package/signal/mcp/McpUriTemplate.ts +1 -1
- package/signal/middlewareChain.ts +105 -0
- package/signal/openapi/openapi.ts +46 -2
- package/signal/serializer/fetch.serializer.ts +1 -0
- package/signal/signalContext.ts +110 -82
- package/signal/slice.ts +2 -2
- package/signal/trace.ts +8 -2
- package/signal/types.ts +13 -0
- package/store/action.ts +102 -42
- package/store/agent/ScreenImage.ts +166 -0
- package/store/agent/ScreenReader.ts +2 -1
- package/store/agent/StoreSurfaceSource.ts +41 -2
- package/store/agent/index.ts +2 -1
- package/store/databaseStateNames.ts +1 -0
- package/store/formUploadOf.ts +41 -0
- package/store/index.ts +1 -0
- package/store/liveInsert.ts +2 -2
- package/store/state.ts +9 -1
- package/store/stateBuilder.ts +8 -2
- package/store/storeInstance.ts +12 -3
- package/store/withSelector.ts +2 -2
- package/types/client/href.d.ts +11 -0
- package/types/client/index.d.ts +1 -0
- package/types/client/rscNavigation.d.ts +1 -1
- package/types/client/transitionTypes.d.ts +0 -2
- package/types/client/translator.d.ts +2 -0
- package/types/common/codeAgentWire.d.ts +7 -0
- package/types/common/index.d.ts +1 -0
- package/types/common/trimSlashes.d.ts +2 -0
- package/types/common/types.d.ts +1 -1
- package/types/constant/fieldInfo.d.ts +2 -2
- package/types/constant/fieldPlan.d.ts +33 -0
- package/types/constant/index.d.ts +3 -0
- package/types/constant/inputParser.d.ts +11 -0
- package/types/constant/invalidInputError.d.ts +8 -0
- package/types/constant/types.d.ts +1 -1
- package/types/dictionary/base.dictionary.d.ts +1 -1
- package/types/dictionary/dictionary.d.ts +3 -3
- package/types/dictionary/trans.d.ts +3 -0
- package/types/document/database.d.ts +2 -3
- package/types/document/documentSchema.d.ts +1 -1
- package/types/document/noDocumentError.d.ts +6 -1
- package/types/fetch/fetchType/appliedReturn.type.d.ts +3 -1
- package/types/fetch/types.d.ts +2 -2
- package/types/index.d.ts +5 -0
- package/types/server/akanServer.d.ts +1 -1
- package/types/server/artifact/routeSeedMatcher.d.ts +8 -0
- package/types/server/di/diLifecycle.d.ts +1 -0
- package/types/server/index.d.ts +1 -0
- package/types/server/machine/machineAccount.d.ts +1 -0
- package/types/server/machine/machineToken.d.ts +9 -0
- package/types/server/migration/docPath.d.ts +20 -0
- package/types/server/migration/index.d.ts +15 -0
- package/types/server/migration/migrationChangeLog.d.ts +27 -0
- package/types/server/migration/migrationChanges.d.ts +27 -0
- package/types/server/migration/migrationCommand.d.ts +33 -0
- package/types/server/migration/migrationContext.d.ts +28 -0
- package/types/server/migration/migrationDefinition.d.ts +42 -0
- package/types/server/migration/migrationError.d.ts +15 -0
- package/types/server/migration/migrationLedger.d.ts +51 -0
- package/types/server/migration/migrationLock.d.ts +34 -0
- package/types/server/migration/migrationParams.d.ts +41 -0
- package/types/server/migration/migrationPulse.d.ts +15 -0
- package/types/server/migration/migrationRunner.d.ts +93 -0
- package/types/server/migration/migrationScope.d.ts +42 -0
- package/types/server/migration/migrationTable.d.ts +52 -0
- package/types/server/migration/migrations.d.ts +12 -0
- package/types/server/migration.d.ts +1 -0
- package/types/server/ops/opsCommand.d.ts +10 -1
- package/types/server/routeState.d.ts +1 -4
- package/types/server/rscNavigationState.d.ts +2 -3
- package/types/server/rscScrollRestoration.d.ts +14 -0
- package/types/server/sitemap.d.ts +1 -1
- package/types/service/agent.service.d.ts +2 -0
- package/types/service/endpointCacheKeys.d.ts +8 -0
- package/types/service/index.d.ts +1 -0
- package/types/service/injectInfo.d.ts +2 -2
- package/types/service/predefinedAdaptor/anthropicLlm.d.ts +9 -4
- package/types/service/predefinedAdaptor/database.adaptor.d.ts +8 -1
- package/types/service/predefinedAdaptor/documentTransfer.d.ts +1 -0
- package/types/service/predefinedAdaptor/endpointCacheControl.adaptor.d.ts +9 -0
- package/types/service/predefinedAdaptor/index.d.ts +1 -0
- package/types/service/predefinedAdaptor/llm.adaptor.d.ts +7 -0
- package/types/service/predefinedAdaptor/openaiDialect.d.ts +20 -5
- package/types/service/predefinedAdaptor/sql/MigrationTables.d.ts +17 -0
- package/types/service/predefinedAdaptor/sql/RawDocumentTable.d.ts +38 -0
- package/types/service/predefinedAdaptor/sql/types.d.ts +1 -0
- package/types/service/predefinedAdaptor/storage.adaptor.d.ts +8 -0
- package/types/signal/endpointCache.d.ts +2 -0
- package/types/signal/endpointErrorContract.d.ts +10 -0
- package/types/signal/endpointIdempotency.d.ts +1 -0
- package/types/signal/endpointRateLimit.d.ts +1 -1
- package/types/signal/exception.d.ts +4 -1
- package/types/signal/index.d.ts +1 -0
- package/types/signal/middlewareChain.d.ts +11 -0
- package/types/signal/signalContext.d.ts +2 -6
- package/types/signal/slice.d.ts +1 -1
- package/types/signal/trace.d.ts +1 -1
- package/types/signal/types.d.ts +12 -0
- package/types/store/action.d.ts +2 -0
- package/types/store/agent/ScreenImage.d.ts +27 -0
- package/types/store/agent/StoreSurfaceSource.d.ts +1 -1
- package/types/store/agent/index.d.ts +2 -1
- package/types/store/databaseStateNames.d.ts +1 -0
- package/types/store/formUploadOf.d.ts +9 -0
- package/types/store/index.d.ts +1 -0
- package/types/store/state.d.ts +7 -1
- package/types/store/stateBuilder.d.ts +2 -1
- package/types/store/storeInstance.d.ts +2 -2
- package/types/store/withSelector.d.ts +1 -1
- package/types/ui/Agent/Composer.d.ts +2 -0
- package/types/ui/Agent/Menu.d.ts +2 -0
- package/types/ui/CsrImage.d.ts +2 -0
- package/types/ui/Data/CardList.d.ts +1 -1
- package/types/ui/Data/Dashboard.d.ts +1 -1
- package/types/ui/Data/Insight.d.ts +1 -1
- package/types/ui/Data/Item.d.ts +2 -2
- package/types/ui/Data/ListContainer.d.ts +1 -1
- package/types/ui/Data/Pagination.d.ts +1 -1
- package/types/ui/Data/TableList.d.ts +1 -1
- package/types/ui/Field/Relation.d.ts +13 -10
- package/types/ui/Field/index.d.ts +4 -4
- package/types/ui/Field/useRelationOptions.d.ts +3 -1
- package/types/ui/Field/useRelationWindow.d.ts +14 -0
- package/types/ui/Image.d.ts +3 -1
- package/types/ui/Load/View.d.ts +1 -1
- package/types/ui/Pagination.d.ts +1 -1
- package/types/ui/Signal/Arg.d.ts +1 -1
- package/types/ui/System/CSR.d.ts +1 -1
- package/types/ui/System/Client.d.ts +1 -1
- package/types/ui/System/SSR.d.ts +1 -1
- package/types/vendor/@akanjs/native/packages/core/src/plugin.d.ts +3 -3
- package/types/vendor/@akanjs/native/packages/desktop/src/page-veto.d.ts +1 -1
- package/types/vendor/@akanjs/native/packages/desktop/src/plugin.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/auth-session/src/desktop.d.ts +2 -2
- package/types/vendor/@akanjs/native/plugins/auth-session/src/index.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/autostart/src/desktop.d.ts +2 -2
- package/types/vendor/@akanjs/native/plugins/autostart/src/index.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/badge/src/desktop.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/badge/src/index.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/badge/src/web.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/biometric/src/index.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/camera/src/desktop.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/camera/src/index.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/camera/src/web.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/clipboard/src/desktop.d.ts +2 -2
- package/types/vendor/@akanjs/native/plugins/clipboard/src/index.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/clipboard/src/web.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/contacts/src/index.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/device/src/desktop.d.ts +2 -2
- package/types/vendor/@akanjs/native/plugins/device/src/index.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/device/src/web.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/dialog/src/desktop.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/dialog/src/index.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/dialog/src/web.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/dock/src/desktop.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/dock/src/index.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/file-picker/src/desktop.d.ts +2 -2
- package/types/vendor/@akanjs/native/plugins/file-picker/src/web.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/filesystem/src/desktop.d.ts +2 -2
- package/types/vendor/@akanjs/native/plugins/filesystem/src/web.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/haptics/src/index.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/haptics/src/web.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/http/src/desktop.d.ts +2 -2
- package/types/vendor/@akanjs/native/plugins/http/src/web.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/keep-awake/src/desktop.d.ts +2 -2
- package/types/vendor/@akanjs/native/plugins/keep-awake/src/index.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/keep-awake/src/web.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/opener/src/desktop.d.ts +2 -2
- package/types/vendor/@akanjs/native/plugins/opener/src/index.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/opener/src/web.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/preferences/src/desktop.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/preferences/src/index.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/preferences/src/web.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/secure-storage/src/desktop.d.ts +2 -2
- package/types/vendor/@akanjs/native/plugins/secure-storage/src/index.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/share/src/index.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/share/src/web.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/single-instance/src/desktop.d.ts +2 -2
- package/types/vendor/@akanjs/native/plugins/splash-screen/src/index.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/splash-screen/src/web.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/sqlite/src/desktop.d.ts +2 -2
- package/types/vendor/@akanjs/native/plugins/toast/src/index.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/toast/src/web.d.ts +1 -1
- package/types/vendor/@akanjs/native/plugins/window/src/index.d.ts +2 -2
- package/types/vendor/@akanjs/native/plugins/window-state/src/desktop.d.ts +2 -2
- package/types/vendor/@akanjs/native/plugins/window-state/src/index.d.ts +1 -1
- package/types/vendor/use-agentic/Compaction.d.ts +3 -1
- package/types/vendor/use-agentic/Reference.d.ts +9 -1
- package/types/vendor/use-agentic/ToolOutput.d.ts +6 -1
- package/types/vendor/use-agentic/ToolReturn.d.ts +18 -0
- package/types/vendor/use-agentic/Transcript.d.ts +7 -0
- package/types/vendor/use-agentic/index.d.ts +1 -0
- package/types/vendor/use-agentic/types.d.ts +6 -0
- package/types/webkit/useDebounce.d.ts +1 -1
- package/ui/Agent/Chat.tsx +1 -0
- package/ui/Agent/Composer.tsx +2 -0
- package/ui/Agent/Menu.tsx +5 -1
- package/ui/Agent/agentSessionOf.ts +15 -8
- package/ui/Agent/mentionDraft.ts +2 -3
- package/ui/Agent/useReferenceMenu.ts +1 -0
- package/ui/Agent/useSlashMenu.ts +1 -0
- package/ui/Clipboard.tsx +1 -0
- package/ui/CsrImage.tsx +3 -1
- package/ui/Data/CardList.tsx +1 -1
- package/ui/Data/Dashboard.tsx +1 -1
- package/ui/Data/Insight.tsx +1 -1
- package/ui/Data/Item.tsx +5 -2
- package/ui/Data/ListContainer.tsx +2 -2
- package/ui/Data/Pagination.tsx +1 -1
- package/ui/Data/TableList.tsx +1 -1
- package/ui/DraggableList.tsx +1 -0
- package/ui/Field/Collection.tsx +4 -0
- package/ui/Field/Relation.tsx +33 -14
- package/ui/Field/useRelationOptions.ts +33 -5
- package/ui/Field/useRelationWindow.ts +50 -0
- package/ui/Image.tsx +4 -4
- package/ui/Input.tsx +1 -0
- package/ui/Layout/Sider.tsx +1 -1
- package/ui/Link/Anchor.tsx +7 -5
- package/ui/Load/Units.tsx +17 -7
- package/ui/Load/View.tsx +2 -2
- package/ui/Model/Edit.tsx +1 -1
- package/ui/Model/EditModal.tsx +11 -5
- package/ui/Model/New.tsx +1 -1
- package/ui/Model/SureToRemove.tsx +1 -0
- package/ui/Model/ViewEditModal.tsx +17 -5
- package/ui/Model/ViewModal.tsx +2 -2
- package/ui/ObjectId.tsx +5 -1
- package/ui/Pagination.tsx +1 -1
- package/ui/Signal/Arg.tsx +1 -3
- package/ui/Signal/Doc.tsx +5 -1
- package/ui/System/CSR.tsx +1 -1
- package/ui/System/Client.tsx +1 -1
- package/ui/System/Reconnect.tsx +1 -1
- package/ui/System/SSR.tsx +3 -36
- package/ui/ToggleSelect.tsx +2 -0
- package/ui/styles.css +10 -103
- package/vendor/@akanjs/native/native/ios/Sources/AkanNativeBridge.swift +3 -2
- package/vendor/@akanjs/native/packages/cli/src/lib/addons.ts +4 -1
- package/vendor/@akanjs/native/packages/cli/src/lib/apk.ts +2 -2
- package/vendor/@akanjs/native/packages/cli/src/lib/codegen.ts +1 -1
- package/vendor/@akanjs/native/packages/cli/src/lib/csp.ts +4 -3
- package/vendor/@akanjs/native/packages/cli/src/lib/googleservices.ts +7 -1
- package/vendor/@akanjs/native/packages/cli/src/lib/hmr.ts +8 -5
- package/vendor/@akanjs/native/packages/cli/src/lib/html.ts +18 -3
- package/vendor/@akanjs/native/packages/cli/src/lib/manifestmerge.ts +1 -1
- package/vendor/@akanjs/native/packages/cli/src/lib/plist.ts +2 -4
- package/vendor/@akanjs/native/packages/cli/src/lib/toolchains.ts +1 -1
- package/vendor/@akanjs/native/packages/cli/src/lib/updates.ts +10 -4
- package/vendor/@akanjs/native/packages/cli/src/lib/xml.ts +4 -3
- package/vendor/@akanjs/native/packages/cli/src/platforms/android.ts +3 -3
- package/vendor/@akanjs/native/packages/core/src/kernel.ts +3 -3
- package/vendor/@akanjs/native/packages/core/src/live.ts +1 -0
- package/vendor/@akanjs/native/packages/core/src/plugin.ts +5 -3
- package/vendor/@akanjs/native/packages/desktop/src/host.ts +13 -5
- package/vendor/@akanjs/native/packages/desktop/src/lifecycle.ts +1 -0
- package/vendor/@akanjs/native/packages/desktop/src/page-veto.ts +1 -1
- package/vendor/@akanjs/native/packages/desktop/src/plugin.ts +4 -1
- package/vendor/@akanjs/native/plugins/camera/src/web.ts +3 -3
- package/vendor/@akanjs/native/plugins/file-picker/src/index.ts +4 -1
- package/vendor/@akanjs/native/plugins/local-notifications/src/web.ts +1 -1
- package/vendor/@akanjs/native/plugins/secure-storage/src/desktop.ts +1 -1
- package/vendor/@akanjs/native/plugins/share/src/options.ts +1 -1
- package/vendor/@akanjs/native/plugins/single-instance/src/desktop.ts +3 -2
- package/vendor/@akanjs/native/plugins/updates/src/desktop.ts +4 -1
- package/vendor/@akanjs/native/plugins/window/src/index.ts +2 -2
- package/vendor/use-agentic/Compaction.ts +38 -7
- package/vendor/use-agentic/Reference.ts +16 -9
- package/vendor/use-agentic/ToolOutput.ts +25 -3
- package/vendor/use-agentic/ToolReturn.ts +32 -0
- package/vendor/use-agentic/ToolRunner.ts +15 -13
- package/vendor/use-agentic/Transcript.ts +38 -2
- package/vendor/use-agentic/WIRE.md +20 -0
- package/vendor/use-agentic/index.ts +1 -0
- package/vendor/use-agentic/types.ts +6 -0
- package/webkit/McpAppAgent.ts +12 -2
- package/webkit/RenderLayer.tsx +23 -4
- package/webkit/useDebounce.ts +23 -14
- package/client/viewTransition.ts +0 -10
- package/types/client/viewTransition.d.ts +0 -3
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { BackendEnv, PromiseOrObject } from "akanjs/base";
|
|
2
|
+
|
|
3
|
+
import type { EndpointInfo } from "./endpointInfo";
|
|
4
|
+
import type { MiddlewareCls } from "./middleware";
|
|
5
|
+
import type { SignalContext } from "./signalContext";
|
|
6
|
+
|
|
7
|
+
type MiddlewareHandler = (context: SignalContext, next: () => Promise<unknown>) => PromiseOrObject<unknown>;
|
|
8
|
+
type ChainRun = (context: SignalContext, core: () => Promise<unknown>) => Promise<unknown>;
|
|
9
|
+
|
|
10
|
+
export class MiddlewareChain {
|
|
11
|
+
|
|
12
|
+
static readonly #handlers = new WeakMap<MiddlewareCls, WeakMap<object, Promise<MiddlewareHandler>>>();
|
|
13
|
+
|
|
14
|
+
static readonly #byEndpoint = new WeakMap<EndpointInfo, MiddlewareChain[]>();
|
|
15
|
+
static readonly #byGlobal = new WeakMap<Map<string, MiddlewareCls>, Map<string, MiddlewareChain[]>>();
|
|
16
|
+
|
|
17
|
+
/** An endpoint's whole chain with `endpointInfo`; with `null`, the global middlewares less those named in `skip`. */
|
|
18
|
+
static of(
|
|
19
|
+
global: Map<string, MiddlewareCls>,
|
|
20
|
+
env: BackendEnv,
|
|
21
|
+
endpointInfo: EndpointInfo | null,
|
|
22
|
+
skip: readonly string[] = [],
|
|
23
|
+
): MiddlewareChain {
|
|
24
|
+
const chains = endpointInfo
|
|
25
|
+
? MiddlewareChain.#endpointChains(endpointInfo)
|
|
26
|
+
: MiddlewareChain.#globalChains(global, skip);
|
|
27
|
+
for (const chain of chains) if (chain.#serves(global, env)) return chain;
|
|
28
|
+
const classes = [
|
|
29
|
+
...[...global.entries()].filter(([name]) => !skip.includes(name)).map(([, cls]) => cls),
|
|
30
|
+
...(endpointInfo?.signalOption.middlewares ?? []),
|
|
31
|
+
];
|
|
32
|
+
const chain = new MiddlewareChain(classes, global, env);
|
|
33
|
+
chains.push(chain);
|
|
34
|
+
return chain;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static #endpointChains(endpointInfo: EndpointInfo): MiddlewareChain[] {
|
|
38
|
+
const chains = MiddlewareChain.#byEndpoint.get(endpointInfo) ?? [];
|
|
39
|
+
if (!chains.length) MiddlewareChain.#byEndpoint.set(endpointInfo, chains);
|
|
40
|
+
return chains;
|
|
41
|
+
}
|
|
42
|
+
static #globalChains(global: Map<string, MiddlewareCls>, skip: readonly string[]): MiddlewareChain[] {
|
|
43
|
+
const bySkip = MiddlewareChain.#byGlobal.get(global) ?? new Map<string, MiddlewareChain[]>();
|
|
44
|
+
if (!bySkip.size) MiddlewareChain.#byGlobal.set(global, bySkip);
|
|
45
|
+
const skipKey = skip.join(",");
|
|
46
|
+
const chains = bySkip.get(skipKey) ?? [];
|
|
47
|
+
if (!chains.length) bySkip.set(skipKey, chains);
|
|
48
|
+
return chains;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
readonly #classes: MiddlewareCls[];
|
|
52
|
+
readonly #global: Map<string, MiddlewareCls>;
|
|
53
|
+
readonly #globalSize: number;
|
|
54
|
+
readonly #env: BackendEnv;
|
|
55
|
+
#run: ChainRun | null = null;
|
|
56
|
+
#composing: Promise<ChainRun> | null = null;
|
|
57
|
+
constructor(classes: MiddlewareCls[], global: Map<string, MiddlewareCls>, env: BackendEnv) {
|
|
58
|
+
this.#classes = classes;
|
|
59
|
+
this.#global = global;
|
|
60
|
+
this.#globalSize = global.size;
|
|
61
|
+
this.#env = env;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
#serves(global: Map<string, MiddlewareCls>, env: BackendEnv) {
|
|
65
|
+
return this.#global === global && this.#env === env && this.#globalSize === global.size;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
run(context: SignalContext, core: () => Promise<unknown>): Promise<unknown> {
|
|
69
|
+
if (this.#run) return this.#run(context, core);
|
|
70
|
+
return this.#compose().then((run) => run(context, core));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
#compose(): Promise<ChainRun> {
|
|
74
|
+
this.#composing ??= Promise.all(this.#classes.map((cls) => MiddlewareChain.#handlerOf(cls, this.#env))).then(
|
|
75
|
+
(handlers) => {
|
|
76
|
+
this.#run = handlers.reduceRight<ChainRun>(
|
|
77
|
+
(next, handler) => async (context, core) => await handler(context, () => next(context, core)),
|
|
78
|
+
(_context, core) => core(),
|
|
79
|
+
);
|
|
80
|
+
return this.#run;
|
|
81
|
+
},
|
|
82
|
+
(error: unknown) => {
|
|
83
|
+
this.#composing = null;
|
|
84
|
+
throw error;
|
|
85
|
+
},
|
|
86
|
+
);
|
|
87
|
+
return this.#composing;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static #handlerOf(MiddlewareCls: MiddlewareCls, env: BackendEnv): Promise<MiddlewareHandler> {
|
|
91
|
+
const byEnv = MiddlewareChain.#handlers.get(MiddlewareCls) ?? new WeakMap<object, Promise<MiddlewareHandler>>();
|
|
92
|
+
MiddlewareChain.#handlers.set(MiddlewareCls, byEnv);
|
|
93
|
+
const cached = byEnv.get(env);
|
|
94
|
+
if (cached) return cached;
|
|
95
|
+
|
|
96
|
+
const handler = Promise.resolve(new MiddlewareCls().use(env) as PromiseOrObject<MiddlewareHandler>).catch(
|
|
97
|
+
(error: unknown) => {
|
|
98
|
+
byEnv.delete(env);
|
|
99
|
+
throw error;
|
|
100
|
+
},
|
|
101
|
+
);
|
|
102
|
+
byEnv.set(env, handler);
|
|
103
|
+
return handler;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FetchClient } from "akanjs/fetch";
|
|
2
2
|
import { type JsonSchema, JsonSchemaBuilder } from "../schema";
|
|
3
|
-
import type { SerializedArg, SerializedEndpoint, SerializedSignal } from "../types";
|
|
3
|
+
import type { EndpointErrors, SerializedArg, SerializedEndpoint, SerializedSignal } from "../types";
|
|
4
4
|
|
|
5
5
|
type OpenApiParameter = Record<string, unknown>;
|
|
6
6
|
type OpenApiOperation = Record<string, unknown>;
|
|
@@ -38,6 +38,19 @@ const httpMethods = {
|
|
|
38
38
|
|
|
39
39
|
const schema = new JsonSchemaBuilder();
|
|
40
40
|
|
|
41
|
+
const akanErrorSchema: JsonSchema = {
|
|
42
|
+
type: "object",
|
|
43
|
+
properties: {
|
|
44
|
+
error: { type: "string", description: "The dictionary error key, <module>.error.<key>." },
|
|
45
|
+
statusCode: { type: "integer" },
|
|
46
|
+
data: { type: "object", additionalProperties: true, description: "The values the message interpolates." },
|
|
47
|
+
details: {},
|
|
48
|
+
path: { type: "string" },
|
|
49
|
+
timestamp: { type: "string", format: "date-time" },
|
|
50
|
+
},
|
|
51
|
+
required: ["error", "statusCode"],
|
|
52
|
+
};
|
|
53
|
+
|
|
41
54
|
export const createOpenApiDocument = (
|
|
42
55
|
serializedSignal: Record<string, SerializedSignal>,
|
|
43
56
|
options: OpenApiDocumentOptions = {},
|
|
@@ -45,6 +58,7 @@ export const createOpenApiDocument = (
|
|
|
45
58
|
const paths: Record<string, OpenApiPathItem> = {};
|
|
46
59
|
const excludeSignals = new Set(options.excludeSignals ?? ["base"]);
|
|
47
60
|
let hasProtectedOperation = false;
|
|
61
|
+
let declaresErrors = false;
|
|
48
62
|
|
|
49
63
|
for (const [refName, signal] of Object.entries(serializedSignal)) {
|
|
50
64
|
if (excludeSignals.has(refName)) continue;
|
|
@@ -57,6 +71,7 @@ export const createOpenApiDocument = (
|
|
|
57
71
|
if (!options.includeNonStandardPaths && isNonStandardOpenApiPath(path)) continue;
|
|
58
72
|
const operation = createOperation(refName, endpointKey, endpoint, options);
|
|
59
73
|
if (operation.security) hasProtectedOperation = true;
|
|
74
|
+
if (endpoint.errors) declaresErrors = true;
|
|
60
75
|
paths[path] ??= {};
|
|
61
76
|
paths[path][method] = operation;
|
|
62
77
|
}
|
|
@@ -72,7 +87,10 @@ export const createOpenApiDocument = (
|
|
|
72
87
|
...(options.servers?.length ? { servers: options.servers } : {}),
|
|
73
88
|
paths,
|
|
74
89
|
components: {
|
|
75
|
-
schemas:
|
|
90
|
+
schemas: {
|
|
91
|
+
...schema.referencedSchemas(paths, schema.allModelSchemas()),
|
|
92
|
+
...(declaresErrors ? { AkanError: akanErrorSchema } : {}),
|
|
93
|
+
},
|
|
76
94
|
...(hasProtectedOperation
|
|
77
95
|
? {
|
|
78
96
|
securitySchemes: {
|
|
@@ -124,6 +142,7 @@ const createOperation = (
|
|
|
124
142
|
description: "Successful response",
|
|
125
143
|
content: createResponseContent(endpoint),
|
|
126
144
|
},
|
|
145
|
+
...createErrorResponses(endpoint, options),
|
|
127
146
|
default: {
|
|
128
147
|
description: "Error response",
|
|
129
148
|
},
|
|
@@ -134,6 +153,31 @@ const createOperation = (
|
|
|
134
153
|
};
|
|
135
154
|
};
|
|
136
155
|
|
|
156
|
+
const createErrorResponses = (endpoint: SerializedEndpoint, options: OpenApiDocumentOptions) =>
|
|
157
|
+
Object.fromEntries(
|
|
158
|
+
(Object.entries(endpoint.errors ?? {}) as [string, EndpointErrors[number]][]).map(([status, keys]) => [
|
|
159
|
+
status,
|
|
160
|
+
{
|
|
161
|
+
description: keys
|
|
162
|
+
.map((key) => {
|
|
163
|
+
const message = options.resolveDescription?.(key);
|
|
164
|
+
return message ? `${key}: ${message}` : key;
|
|
165
|
+
})
|
|
166
|
+
.join("\n"),
|
|
167
|
+
content: {
|
|
168
|
+
"application/json": {
|
|
169
|
+
schema: {
|
|
170
|
+
allOf: [
|
|
171
|
+
{ $ref: "#/components/schemas/AkanError" },
|
|
172
|
+
{ type: "object", properties: { error: { type: "string", enum: [...keys] } } },
|
|
173
|
+
],
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
]),
|
|
179
|
+
);
|
|
180
|
+
|
|
137
181
|
const createParameter = (
|
|
138
182
|
refName: string,
|
|
139
183
|
endpointKey: string,
|
|
@@ -74,6 +74,7 @@ export class FetchSerializer {
|
|
|
74
74
|
...(endpointInfo.signalOption.method ? { method: endpointInfo.signalOption.method } : {}),
|
|
75
75
|
...(endpointInfo.signalOption.fileUpload ? { fileUpload: true } : {}),
|
|
76
76
|
...(endpointInfo.signalOption.timeout ? { timeout: endpointInfo.signalOption.timeout } : {}),
|
|
77
|
+
...(endpointInfo.signalOption.errors ? { errors: endpointInfo.signalOption.errors } : {}),
|
|
77
78
|
...(guards?.length ? { guards } : {}),
|
|
78
79
|
...(endpointInfo.signalOption.mcp === false ? { mcp: false as const } : {}),
|
|
79
80
|
...(refusesAgents(endpointInfo.signalOption.guards) ? { agents: false as const } : {}),
|
package/signal/signalContext.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
type BackendEnv,
|
|
4
4
|
Binary,
|
|
5
5
|
type Cls,
|
|
6
|
-
FIELD_META,
|
|
6
|
+
type FIELD_META,
|
|
7
7
|
ID,
|
|
8
8
|
INTERNAL_META,
|
|
9
9
|
PrimitiveRegistry,
|
|
@@ -15,7 +15,9 @@ import {
|
|
|
15
15
|
type ConstantCls,
|
|
16
16
|
type ConstantFieldTypeInput,
|
|
17
17
|
ConstantRegistry,
|
|
18
|
-
|
|
18
|
+
FieldPlan,
|
|
19
|
+
InputParser,
|
|
20
|
+
InvalidInputError,
|
|
19
21
|
serialize,
|
|
20
22
|
} from "akanjs/constant";
|
|
21
23
|
import { Err } from "akanjs/dictionary";
|
|
@@ -23,11 +25,13 @@ import type { Adaptor, AdaptorCls, DatabaseService, InjectRegistry, LiveRegistry
|
|
|
23
25
|
import type { Internal, InternalCls, InternalInfo, MiddlewareCls } from ".";
|
|
24
26
|
import { CrossSiteGuard } from "./CrossSiteGuard";
|
|
25
27
|
import { EndpointCache } from "./endpointCache";
|
|
28
|
+
import { EndpointErrorContract } from "./endpointErrorContract";
|
|
26
29
|
import { EndpointIdempotency } from "./endpointIdempotency";
|
|
27
30
|
import type { ArgInfo, EndpointInfo, EndpointType } from "./endpointInfo";
|
|
28
31
|
import { EndpointRateLimit } from "./endpointRateLimit";
|
|
29
|
-
import { Exception, isExceptionLike } from "./exception";
|
|
32
|
+
import { Exception, type ExceptionLike, isExceptionLike } from "./exception";
|
|
30
33
|
import { type GuardCls, type GuardScope, guardOf } from "./guard";
|
|
34
|
+
import { MiddlewareChain } from "./middlewareChain";
|
|
31
35
|
import { SignalFailure } from "./SignalFailure";
|
|
32
36
|
import { getCurrentTrace, runTraced, SignalTrace, type TraceOrigin, traceSpan } from "./trace";
|
|
33
37
|
|
|
@@ -38,8 +42,22 @@ export type HttpPeerResolver = (req: Request) => { address: string; port: number
|
|
|
38
42
|
|
|
39
43
|
const httpEndpointTypes = new Set<EndpointType>(["query", "mutation"]);
|
|
40
44
|
|
|
41
|
-
const deserializeArg = (arg: ArgInfo, value: unknown) =>
|
|
42
|
-
|
|
45
|
+
const deserializeArg = (arg: ArgInfo, value: unknown) => {
|
|
46
|
+
try {
|
|
47
|
+
return InputParser.parse(arg.argRef, arg.arrDepth, value, {
|
|
48
|
+
key: arg.name,
|
|
49
|
+
nullable: arg.option?.nullable,
|
|
50
|
+
enum: arg.enum,
|
|
51
|
+
});
|
|
52
|
+
} catch (error) {
|
|
53
|
+
|
|
54
|
+
if (isExceptionLike(error)) throw error;
|
|
55
|
+
if (!(error instanceof InvalidInputError))
|
|
56
|
+
throw new Err.BadRequest("base.error.invalidArgument", { name: arg.name });
|
|
57
|
+
if (error.reason === "missing") throw new Err.BadRequest("base.error.requiredArgument", { name: error.path });
|
|
58
|
+
throw new Err.BadRequest("base.error.invalidArgument", { name: error.path, expected: error.expected });
|
|
59
|
+
}
|
|
60
|
+
};
|
|
43
61
|
|
|
44
62
|
interface WebSocketRequest {
|
|
45
63
|
ws: Bun.ServerWebSocket<unknown>;
|
|
@@ -47,7 +65,6 @@ interface WebSocketRequest {
|
|
|
47
65
|
eventType: WebSocketEventType;
|
|
48
66
|
}
|
|
49
67
|
type RuntimeRecord = Record<string, unknown>;
|
|
50
|
-
type MiddlewareHandler = (context: SignalContext, next: () => Promise<unknown>) => PromiseOrObject<unknown>;
|
|
51
68
|
/** Request-scoped: the outermost `resolveReturn` starts one and every recursion threads it down. */
|
|
52
69
|
type ResolveCache = Map<ConstantFieldTypeInput, Map<string, Promise<unknown>>>;
|
|
53
70
|
|
|
@@ -133,10 +150,11 @@ export class SignalContext<
|
|
|
133
150
|
CrossSiteGuard.assertOrigin(httpCtx.req, httpCtx.url, this.key);
|
|
134
151
|
}
|
|
135
152
|
|
|
136
|
-
|
|
137
|
-
|
|
153
|
+
const admitting = this.#isLeavingRoom() ? undefined : EndpointRateLimit.admit(this, "ip");
|
|
154
|
+
if (admitting) await admitting;
|
|
155
|
+
const start = this.#spanned ? performance.now() : 0;
|
|
138
156
|
this.#rawArgs = await this.ctx.readArgs(this.endpointInfo);
|
|
139
|
-
this.trace?.recordSpan("argRead", performance.now() - start);
|
|
157
|
+
if (this.#spanned) this.trace?.recordSpan("argRead", performance.now() - start);
|
|
140
158
|
return this;
|
|
141
159
|
}
|
|
142
160
|
/** Parsed on first read, so a guard or middleware that reads one still gets it; a parser runs at most once per call. */
|
|
@@ -150,9 +168,9 @@ export class SignalContext<
|
|
|
150
168
|
#parseArgs(): unknown[] {
|
|
151
169
|
const raw = this.#rawArgs;
|
|
152
170
|
if (!raw) return [];
|
|
153
|
-
const start = this
|
|
171
|
+
const start = this.#spanned ? performance.now() : 0;
|
|
154
172
|
const args = this.endpointInfo.args.map((arg, idx) => this.ctx.parseArg(arg, raw[idx]));
|
|
155
|
-
this.trace?.recordSpan("argParse", performance.now() - start);
|
|
173
|
+
if (this.#spanned) this.trace?.recordSpan("argParse", performance.now() - start);
|
|
156
174
|
return args;
|
|
157
175
|
}
|
|
158
176
|
#isLeavingRoom() {
|
|
@@ -231,61 +249,42 @@ export class SignalContext<
|
|
|
231
249
|
coreExec: () => Promise<unknown>,
|
|
232
250
|
{ endpointMiddlewares = true, skip = [] as string[] }: { endpointMiddlewares?: boolean; skip?: string[] } = {},
|
|
233
251
|
): () => Promise<unknown> {
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const MiddlewareCls = middlewares[i];
|
|
242
|
-
if (!MiddlewareCls) continue;
|
|
243
|
-
const currentNext = next;
|
|
244
|
-
next = async () =>
|
|
245
|
-
await (await SignalContext.#getMiddlewareHandler(MiddlewareCls, this.getEnv()))(this, currentNext);
|
|
246
|
-
}
|
|
247
|
-
return next;
|
|
252
|
+
const chain = MiddlewareChain.of(
|
|
253
|
+
this.#middleware,
|
|
254
|
+
this.getEnv(),
|
|
255
|
+
endpointMiddlewares ? this.endpointInfo : null,
|
|
256
|
+
skip,
|
|
257
|
+
);
|
|
258
|
+
return () => chain.run(this, coreExec);
|
|
248
259
|
}
|
|
249
260
|
static #httpPeer: HttpPeerResolver | null = null;
|
|
250
261
|
/** Registered by the listening `Bun.serve`, the only thing that can answer `requestIP`; unused behind the gateway. */
|
|
251
262
|
static setHttpPeerResolver(resolve: HttpPeerResolver | null) {
|
|
252
263
|
SignalContext.#httpPeer = resolve;
|
|
253
264
|
}
|
|
254
|
-
|
|
255
|
-
static #middlewareHandlers = new WeakMap<MiddlewareCls, WeakMap<object, Promise<MiddlewareHandler>>>();
|
|
256
|
-
static #getMiddlewareHandler(MiddlewareCls: MiddlewareCls, env: BackendEnv): Promise<MiddlewareHandler> {
|
|
257
|
-
const byEnv =
|
|
258
|
-
SignalContext.#middlewareHandlers.get(MiddlewareCls) ?? new WeakMap<object, Promise<MiddlewareHandler>>();
|
|
259
|
-
SignalContext.#middlewareHandlers.set(MiddlewareCls, byEnv);
|
|
260
|
-
const cached = byEnv.get(env);
|
|
261
|
-
if (cached) return cached;
|
|
262
|
-
|
|
263
|
-
const handler = Promise.resolve(new MiddlewareCls().use(env) as PromiseOrObject<MiddlewareHandler>).catch(
|
|
264
|
-
(error: unknown) => {
|
|
265
|
-
byEnv.delete(env);
|
|
266
|
-
throw error;
|
|
267
|
-
},
|
|
268
|
-
);
|
|
269
|
-
byEnv.set(env, handler);
|
|
270
|
-
return handler;
|
|
271
|
-
}
|
|
272
265
|
async exec() {
|
|
273
266
|
if (!this.trace || getCurrentTrace() === this.trace) return await this.#exec();
|
|
274
267
|
return await runTraced(this.trace, async () => await this.#exec());
|
|
275
268
|
}
|
|
269
|
+
|
|
270
|
+
get #spanned() {
|
|
271
|
+
return this.trace?.mode === "full";
|
|
272
|
+
}
|
|
276
273
|
async #exec() {
|
|
277
274
|
if (!this.endpointInfo.execFn) throw new Exception.Error("Exec function is not set");
|
|
278
275
|
const coreExec = async () => {
|
|
279
276
|
if (!this.endpointInfo.execFn) throw new Exception.Error("Exec function is not set");
|
|
280
|
-
|
|
277
|
+
const admitting = EndpointRateLimit.admit(this, "account");
|
|
278
|
+
if (admitting) await admitting;
|
|
279
|
+
if (this.#spanned) await traceSpan("guards", () => this.#checkGuards("account"));
|
|
280
|
+
else await this.#checkGuards("account");
|
|
281
281
|
if (this.trace) {
|
|
282
|
-
await traceSpan("guards", () => this.#checkGuards("account"));
|
|
283
282
|
const account = this.get<{ id?: unknown }>("account");
|
|
284
283
|
if (typeof account?.id === "string") this.trace.setAttr("userId", account.id);
|
|
285
|
-
}
|
|
284
|
+
}
|
|
286
285
|
|
|
287
286
|
this.#args ??= this.#parseArgs();
|
|
288
|
-
if (this
|
|
287
|
+
if (this.#spanned) await traceSpan("resourceGuards", () => this.#checkGuards("resource"));
|
|
289
288
|
else await this.#checkGuards("resource");
|
|
290
289
|
if (this.endpointInfo.internalArgs.length > 0) {
|
|
291
290
|
this.internalArgs = await Promise.all(
|
|
@@ -298,23 +297,21 @@ export class SignalContext<
|
|
|
298
297
|
);
|
|
299
298
|
}
|
|
300
299
|
const handle = async () => await this.endpointInfo.execFn?.call(this.adaptor, ...this.args, ...this.internalArgs);
|
|
301
|
-
const traced = this
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
},
|
|
309
|
-
);
|
|
300
|
+
const traced = this.#spanned ? () => traceSpan("handler", handle) : handle;
|
|
301
|
+
const run = EndpointCache.declares(this.endpointInfo) ? () => EndpointCache.through(this, traced) : traced;
|
|
302
|
+
if (!EndpointIdempotency.applies(this)) return await run();
|
|
303
|
+
return await EndpointIdempotency.through(this, run, async (result) => {
|
|
304
|
+
const resolved = await this.#resolve(result);
|
|
305
|
+
return await traceSpan("serialize", async () => HttpExecutionContext.wireOf(resolved, this.endpointInfo));
|
|
306
|
+
});
|
|
310
307
|
};
|
|
311
308
|
const next = this.#withMiddleware(coreExec);
|
|
312
|
-
const result = this
|
|
309
|
+
const result = this.#spanned ? await traceSpan("execChain", () => next()) : await next();
|
|
313
310
|
|
|
314
311
|
if (this.endpointInfo.type === "pubsub") return result;
|
|
315
312
|
if (result instanceof Response) return result;
|
|
316
313
|
const resolved = await this.#resolve(result);
|
|
317
|
-
if (!this
|
|
314
|
+
if (!this.#spanned) return this.ctx.makeResponse(resolved, this.endpointInfo);
|
|
318
315
|
return await traceSpan("serialize", async () => this.ctx.makeResponse(resolved, this.endpointInfo));
|
|
319
316
|
}
|
|
320
317
|
async #resolve(result: unknown) {
|
|
@@ -325,7 +322,7 @@ export class SignalContext<
|
|
|
325
322
|
registry: this.#registry,
|
|
326
323
|
live: this.#live,
|
|
327
324
|
};
|
|
328
|
-
const resolved = this
|
|
325
|
+
const resolved = this.#spanned
|
|
329
326
|
? await traceSpan("resolveReturn", () => SignalContext.resolveReturn(result, resolveOption))
|
|
330
327
|
: await SignalContext.resolveReturn(result, resolveOption);
|
|
331
328
|
return this.#settle(resolved);
|
|
@@ -362,13 +359,14 @@ export class SignalContext<
|
|
|
362
359
|
key: string,
|
|
363
360
|
origin: TraceOrigin,
|
|
364
361
|
fn: () => Promise<T>,
|
|
365
|
-
{ trace = true }: { trace?: boolean } = {},
|
|
366
362
|
): Promise<T> {
|
|
367
|
-
return await runTraced(
|
|
363
|
+
return await runTraced(SignalTrace.create(key, endpointInfo.type, origin), async () => {
|
|
368
364
|
try {
|
|
369
365
|
return await fn();
|
|
370
366
|
} catch (error) {
|
|
371
|
-
if (
|
|
367
|
+
if (isExceptionLike(error))
|
|
368
|
+
EndpointErrorContract.checkThrown(endpoint, endpointInfo, key, SignalContext.#wireKey(error));
|
|
369
|
+
else {
|
|
372
370
|
const message = error instanceof Error ? error.message : String(error);
|
|
373
371
|
const stack = error instanceof Error ? error.stack : undefined;
|
|
374
372
|
endpoint.logger.error(`Error ${endpointInfo.type}-${key}:\n${stack ?? message}`);
|
|
@@ -383,10 +381,9 @@ export class SignalContext<
|
|
|
383
381
|
endpointInfo: EndpointInfo,
|
|
384
382
|
key: string,
|
|
385
383
|
fn: () => Promise<Response | undefined>,
|
|
386
|
-
options: { trace?: boolean } = {},
|
|
387
384
|
): Promise<Response | undefined> {
|
|
388
385
|
try {
|
|
389
|
-
return await SignalContext.run(endpoint, endpointInfo, key, "http", fn
|
|
386
|
+
return await SignalContext.run(endpoint, endpointInfo, key, "http", fn);
|
|
390
387
|
} catch (error) {
|
|
391
388
|
if (endpointInfo.type === "message" || endpointInfo.type === "pubsub") throw error;
|
|
392
389
|
if (isExceptionLike(error)) {
|
|
@@ -402,6 +399,11 @@ export class SignalContext<
|
|
|
402
399
|
return SignalFailure.response(error, { path: endpointInfo.getPath(key) });
|
|
403
400
|
}
|
|
404
401
|
}
|
|
402
|
+
|
|
403
|
+
static #wireKey(error: ExceptionLike): string {
|
|
404
|
+
const wire = (error.toJSON() as { error?: unknown }).error;
|
|
405
|
+
return typeof wire === "string" ? wire : (error as unknown as Error).message;
|
|
406
|
+
}
|
|
405
407
|
static #exceptionHeaders(error: { statusCode: number }): Record<string, string> {
|
|
406
408
|
const seconds = (error as { data?: { seconds?: unknown } }).data?.seconds;
|
|
407
409
|
if (error.statusCode !== 429 || typeof seconds !== "number") return { "Content-Type": "application/json" };
|
|
@@ -430,6 +432,8 @@ export class SignalContext<
|
|
|
430
432
|
): Promise<unknown> {
|
|
431
433
|
if (value === null || value === undefined) return value;
|
|
432
434
|
if (PrimitiveRegistry.has(returnRef as Cls)) return value;
|
|
435
|
+
const plan = FieldPlan.of(returnRef as ConstantCls);
|
|
436
|
+
if (!plan.resolvesAsync) return SignalContext.#resolveSync(value, plan, arrDepth);
|
|
433
437
|
else if (arrDepth)
|
|
434
438
|
return await Promise.all(
|
|
435
439
|
(value as unknown[]).map((v) =>
|
|
@@ -454,10 +458,14 @@ export class SignalContext<
|
|
|
454
458
|
resolvedValue[key] = v;
|
|
455
459
|
}),
|
|
456
460
|
);
|
|
457
|
-
for (const
|
|
461
|
+
for (const { key, field, kind } of plan.entries) {
|
|
462
|
+
if (kind === "masked") continue;
|
|
463
|
+
if (kind === "value") {
|
|
464
|
+
resolvedValue[key] = valueRecord[key];
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
458
467
|
const fieldPath = path ? `${path}.${key}` : key;
|
|
459
|
-
if (
|
|
460
|
-
else if (field.fieldType === "resolve")
|
|
468
|
+
if (kind === "computed")
|
|
461
469
|
assign(
|
|
462
470
|
key,
|
|
463
471
|
SignalContext.#resolveComputed(key, valueRecord, {
|
|
@@ -470,21 +478,24 @@ export class SignalContext<
|
|
|
470
478
|
path: fieldPath,
|
|
471
479
|
}),
|
|
472
480
|
);
|
|
473
|
-
else if (
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
key,
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
481
|
+
else if (kind === "scalar") {
|
|
482
|
+
const scalarPlan = FieldPlan.of(field.modelRef as unknown as ConstantCls);
|
|
483
|
+
if (!scalarPlan.resolvesAsync)
|
|
484
|
+
resolvedValue[key] = SignalContext.#resolveSync(valueRecord[key], scalarPlan, field.arrDepth);
|
|
485
|
+
else
|
|
486
|
+
assign(
|
|
487
|
+
key,
|
|
488
|
+
SignalContext.resolveReturn(valueRecord[key], {
|
|
489
|
+
signalContext,
|
|
490
|
+
returnRef: field.modelRef,
|
|
491
|
+
arrDepth: field.arrDepth,
|
|
492
|
+
registry,
|
|
493
|
+
live,
|
|
494
|
+
cache,
|
|
495
|
+
path: fieldPath,
|
|
496
|
+
}),
|
|
497
|
+
);
|
|
498
|
+
} else
|
|
488
499
|
assign(
|
|
489
500
|
key,
|
|
490
501
|
SignalContext.#resolveRelation(valueRecord[key], {
|
|
@@ -502,6 +513,23 @@ export class SignalContext<
|
|
|
502
513
|
if (pending.length) await Promise.all(pending);
|
|
503
514
|
return resolvedValue;
|
|
504
515
|
}
|
|
516
|
+
|
|
517
|
+
static #resolveSync(value: unknown, plan: FieldPlan, arrDepth: number): unknown {
|
|
518
|
+
if (value === null || value === undefined) return value;
|
|
519
|
+
if (arrDepth) return (value as unknown[]).map((item) => SignalContext.#resolveSync(item, plan, arrDepth - 1));
|
|
520
|
+
const valueRecord = value as RuntimeRecord;
|
|
521
|
+
const resolvedValue = {} as RuntimeRecord;
|
|
522
|
+
for (const { key, field, kind } of plan.entries) {
|
|
523
|
+
if (kind === "value") resolvedValue[key] = valueRecord[key];
|
|
524
|
+
else if (kind === "scalar")
|
|
525
|
+
resolvedValue[key] = SignalContext.#resolveSync(
|
|
526
|
+
valueRecord[key],
|
|
527
|
+
FieldPlan.of(field.modelRef as unknown as ConstantCls),
|
|
528
|
+
field.arrDepth,
|
|
529
|
+
);
|
|
530
|
+
}
|
|
531
|
+
return resolvedValue;
|
|
532
|
+
}
|
|
505
533
|
static async #resolveComputed(
|
|
506
534
|
key: string,
|
|
507
535
|
valueRecord: RuntimeRecord,
|
package/signal/slice.ts
CHANGED
|
@@ -119,7 +119,7 @@ type RootSliceInfoObj<
|
|
|
119
119
|
_Filter extends FilterInstance,
|
|
120
120
|
_QueryKey extends string,
|
|
121
121
|
> = {
|
|
122
|
-
|
|
122
|
+
"": SliceInfo<
|
|
123
123
|
SrvRefName<SrvModule>,
|
|
124
124
|
_Input,
|
|
125
125
|
_Full,
|
|
@@ -206,7 +206,7 @@ export function slice<
|
|
|
206
206
|
...libSlices.map((libSlice) => libSlice[SLICE_META]),
|
|
207
207
|
{
|
|
208
208
|
|
|
209
|
-
|
|
209
|
+
"": init({ guards: rootGuards, ...(mcpOption?.root === false ? { mcp: false } : {}) })
|
|
210
210
|
.search<"queryKey", string>("queryKey", String)
|
|
211
211
|
.search<"args", unknown[]>("args", Any)
|
|
212
212
|
.exec((queryKey, args) => {
|
package/signal/trace.ts
CHANGED
|
@@ -94,7 +94,6 @@ export class SignalTrace {
|
|
|
94
94
|
static #activeFlights = 0;
|
|
95
95
|
static #flightMaxTraces: number | null = null;
|
|
96
96
|
|
|
97
|
-
readonly traceId: string;
|
|
98
97
|
readonly endpointKey: string;
|
|
99
98
|
readonly endpointType: string;
|
|
100
99
|
readonly origin: TraceOrigin;
|
|
@@ -116,6 +115,8 @@ export class SignalTrace {
|
|
|
116
115
|
#flightRing: FlightEntry[] | null = null;
|
|
117
116
|
#flightEvicted = 0;
|
|
118
117
|
#finalized = false;
|
|
118
|
+
readonly #startedAtEpoch: number;
|
|
119
|
+
#traceId: string | null = null;
|
|
119
120
|
|
|
120
121
|
constructor(
|
|
121
122
|
endpointKey: string,
|
|
@@ -127,7 +128,12 @@ export class SignalTrace {
|
|
|
127
128
|
this.mode = mode;
|
|
128
129
|
this.origin = origin;
|
|
129
130
|
this.startedAt = performance.now();
|
|
130
|
-
this
|
|
131
|
+
this.#startedAtEpoch = Date.now();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
get traceId(): string {
|
|
135
|
+
this.#traceId ??= `${this.#startedAtEpoch.toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
136
|
+
return this.#traceId;
|
|
131
137
|
}
|
|
132
138
|
|
|
133
139
|
/** `null` when both modes are off. */
|
package/signal/types.ts
CHANGED
|
@@ -76,6 +76,13 @@ export interface LiveEndpointOption {
|
|
|
76
76
|
pauseOn: string[];
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/** A dictionary error key, `<module>.error.<key>`: what an `Err` carries and the wire's `error` field names. */
|
|
80
|
+
export type EndpointErrorKey = `${string}.error.${string}`;
|
|
81
|
+
/** The errors an endpoint answers with on purpose, by HTTP status: `{ 409: ["ticket.error.locked"] }`. */
|
|
82
|
+
export interface EndpointErrors {
|
|
83
|
+
readonly [status: number]: readonly EndpointErrorKey[];
|
|
84
|
+
}
|
|
85
|
+
|
|
79
86
|
export interface SignalOption<Response = any, Nullable extends boolean = false, _Key = keyof UnCls<Response>>
|
|
80
87
|
extends InitOption,
|
|
81
88
|
TimerOption {
|
|
@@ -114,6 +121,11 @@ export interface SignalOption<Response = any, Nullable extends boolean = false,
|
|
|
114
121
|
fileUpload?: boolean;
|
|
115
122
|
/** `false` keeps it out of the MCP catalogue (default `true`); curation, not authorization — HTTP still serves it. */
|
|
116
123
|
mcp?: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* The errors this endpoint throws on purpose, by status. Published as OpenAPI responses and in the MCP tool's
|
|
126
|
+
* description; outside production, throwing a key this leaves out is warned about once.
|
|
127
|
+
*/
|
|
128
|
+
errors?: EndpointErrors;
|
|
117
129
|
/**
|
|
118
130
|
* A slow subscriber of a `pubsub(Binary)`: `"coalesce"` (default) keeps only the newest frame per room, `"queue"`
|
|
119
131
|
* delivers every frame and grows the send buffer with the slowest subscriber.
|
|
@@ -172,6 +184,7 @@ export interface SerializedEndpoint extends SerializedSignalOption {
|
|
|
172
184
|
returns: SerializedReturns;
|
|
173
185
|
/** Milliseconds; the client sizes its request budget from it. */
|
|
174
186
|
timeout?: number;
|
|
187
|
+
errors?: EndpointErrors;
|
|
175
188
|
}
|
|
176
189
|
export interface SerializedFilter {
|
|
177
190
|
filter: { [key: string]: SerializedArg[] };
|