dotdo 0.0.1 → 0.0.2
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/LICENSE +1 -1
- package/README.md +446 -315
- package/dist/ai/index.js +19 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/ai/template-literals.js +852 -0
- package/dist/ai/template-literals.js.map +1 -0
- package/dist/api/analytics/router.js +601 -0
- package/dist/api/analytics/router.js.map +1 -0
- package/dist/api/index.js +158 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/middleware/auth-federation.js +573 -0
- package/dist/api/middleware/auth-federation.js.map +1 -0
- package/dist/api/middleware/auth.js +544 -0
- package/dist/api/middleware/auth.js.map +1 -0
- package/dist/api/middleware/error-handling.js +176 -0
- package/dist/api/middleware/error-handling.js.map +1 -0
- package/dist/api/middleware/request-id.js +21 -0
- package/dist/api/middleware/request-id.js.map +1 -0
- package/dist/api/pages.js +1180 -0
- package/dist/api/pages.js.map +1 -0
- package/dist/api/routes/api.js +612 -0
- package/dist/api/routes/api.js.map +1 -0
- package/dist/api/routes/browsers.js +471 -0
- package/dist/api/routes/browsers.js.map +1 -0
- package/dist/api/routes/do.js +188 -0
- package/dist/api/routes/do.js.map +1 -0
- package/dist/api/routes/mcp.js +459 -0
- package/dist/api/routes/mcp.js.map +1 -0
- package/dist/api/routes/obs.js +445 -0
- package/dist/api/routes/obs.js.map +1 -0
- package/dist/api/routes/openapi.js +794 -0
- package/dist/api/routes/openapi.js.map +1 -0
- package/dist/api/routes/rpc.js +1103 -0
- package/dist/api/routes/rpc.js.map +1 -0
- package/dist/api/routes/sandboxes.js +389 -0
- package/dist/api/routes/sandboxes.js.map +1 -0
- package/dist/api/test-do.js +38 -0
- package/dist/api/test-do.js.map +1 -0
- package/dist/api/types.js +11 -0
- package/dist/api/types.js.map +1 -0
- package/dist/cli/bin.js +2 -0
- package/dist/cli/main.js +52342 -0
- package/dist/db/actions.js +212 -0
- package/dist/db/actions.js.map +1 -0
- package/dist/db/auth.js +506 -0
- package/dist/db/auth.js.map +1 -0
- package/dist/db/branches.js +65 -0
- package/dist/db/branches.js.map +1 -0
- package/dist/db/clickhouse.js +1074 -0
- package/dist/db/clickhouse.js.map +1 -0
- package/dist/db/dlq.js +39 -0
- package/dist/db/dlq.js.map +1 -0
- package/dist/db/events.js +28 -0
- package/dist/db/events.js.map +1 -0
- package/dist/db/exec.js +64 -0
- package/dist/db/exec.js.map +1 -0
- package/dist/db/files.js +85 -0
- package/dist/db/files.js.map +1 -0
- package/dist/db/flags.js +24 -0
- package/dist/db/flags.js.map +1 -0
- package/dist/db/git.js +116 -0
- package/dist/db/git.js.map +1 -0
- package/dist/db/iceberg/inverted-index.js +862 -0
- package/dist/db/iceberg/inverted-index.js.map +1 -0
- package/dist/db/iceberg/puffin.js +878 -0
- package/dist/db/iceberg/puffin.js.map +1 -0
- package/dist/db/iceberg/search-manifest.js +422 -0
- package/dist/db/iceberg/search-manifest.js.map +1 -0
- package/dist/db/iceberg/types.js +8 -0
- package/dist/db/iceberg/types.js.map +1 -0
- package/dist/db/index.js +121 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/integrations.js +368 -0
- package/dist/db/integrations.js.map +1 -0
- package/dist/db/json-indexes.js +332 -0
- package/dist/db/json-indexes.js.map +1 -0
- package/dist/db/linked-accounts.js +287 -0
- package/dist/db/linked-accounts.js.map +1 -0
- package/dist/db/nouns.js +183 -0
- package/dist/db/nouns.js.map +1 -0
- package/dist/db/objects.js +170 -0
- package/dist/db/objects.js.map +1 -0
- package/dist/db/primitives/dag-scheduler/index.js +869 -0
- package/dist/db/primitives/dag-scheduler/index.js.map +1 -0
- package/dist/db/primitives/exactly-once-context.js +237 -0
- package/dist/db/primitives/exactly-once-context.js.map +1 -0
- package/dist/db/primitives/index.js +62 -0
- package/dist/db/primitives/index.js.map +1 -0
- package/dist/db/primitives/keyed-router.js +145 -0
- package/dist/db/primitives/keyed-router.js.map +1 -0
- package/dist/db/primitives/observability.js +162 -0
- package/dist/db/primitives/observability.js.map +1 -0
- package/dist/db/primitives/schema-evolution.js +643 -0
- package/dist/db/primitives/schema-evolution.js.map +1 -0
- package/dist/db/primitives/stateful-operator/index.js +770 -0
- package/dist/db/primitives/stateful-operator/index.js.map +1 -0
- package/dist/db/primitives/temporal-store.js +306 -0
- package/dist/db/primitives/temporal-store.js.map +1 -0
- package/dist/db/primitives/typed-column-store.js +1229 -0
- package/dist/db/primitives/typed-column-store.js.map +1 -0
- package/dist/db/primitives/utils/duration.js +162 -0
- package/dist/db/primitives/utils/duration.js.map +1 -0
- package/dist/db/primitives/utils/murmur3.js +118 -0
- package/dist/db/primitives/utils/murmur3.js.map +1 -0
- package/dist/db/primitives/watermark-service.js +136 -0
- package/dist/db/primitives/watermark-service.js.map +1 -0
- package/dist/db/primitives/window-manager.js +764 -0
- package/dist/db/primitives/window-manager.js.map +1 -0
- package/dist/db/relationships.js +66 -0
- package/dist/db/relationships.js.map +1 -0
- package/dist/db/schema-minimal.js +61 -0
- package/dist/db/schema-minimal.js.map +1 -0
- package/dist/db/search.js +28 -0
- package/dist/db/search.js.map +1 -0
- package/dist/db/stores.js +1665 -0
- package/dist/db/stores.js.map +1 -0
- package/dist/db/things.js +297 -0
- package/dist/db/things.js.map +1 -0
- package/dist/db/vault.js +171 -0
- package/dist/db/vault.js.map +1 -0
- package/dist/db/verbs.js +102 -0
- package/dist/db/verbs.js.map +1 -0
- package/dist/do/base.js +48 -0
- package/dist/do/base.js.map +1 -0
- package/dist/do/bash.js +35 -0
- package/dist/do/bash.js.map +1 -0
- package/dist/do/fs.js +25 -0
- package/dist/do/fs.js.map +1 -0
- package/dist/do/full.js +61 -0
- package/dist/do/full.js.map +1 -0
- package/dist/do/git.js +28 -0
- package/dist/do/git.js.map +1 -0
- package/dist/do/index.js +52 -0
- package/dist/do/index.js.map +1 -0
- package/dist/do/tiny.js +31 -0
- package/dist/do/tiny.js.map +1 -0
- package/dist/lib/DOAuth.js +261 -0
- package/dist/lib/DOAuth.js.map +1 -0
- package/dist/lib/DODispatcher.js +72 -0
- package/dist/lib/DODispatcher.js.map +1 -0
- package/dist/lib/Modifier.js +189 -0
- package/dist/lib/Modifier.js.map +1 -0
- package/dist/lib/StateStorage.js +403 -0
- package/dist/lib/StateStorage.js.map +1 -0
- package/dist/lib/TypeRegistry.js +122 -0
- package/dist/lib/TypeRegistry.js.map +1 -0
- package/dist/lib/agent/tools/bash.js +336 -0
- package/dist/lib/agent/tools/bash.js.map +1 -0
- package/dist/lib/agent/tools/edit.js +157 -0
- package/dist/lib/agent/tools/edit.js.map +1 -0
- package/dist/lib/agent/tools/glob.js +137 -0
- package/dist/lib/agent/tools/glob.js.map +1 -0
- package/dist/lib/agent/tools/grep.js +315 -0
- package/dist/lib/agent/tools/grep.js.map +1 -0
- package/dist/lib/agent/tools/index.js +71 -0
- package/dist/lib/agent/tools/index.js.map +1 -0
- package/dist/lib/agent/tools/read.js +212 -0
- package/dist/lib/agent/tools/read.js.map +1 -0
- package/dist/lib/agent/tools/types.js +197 -0
- package/dist/lib/agent/tools/types.js.map +1 -0
- package/dist/lib/agent/tools/write.js +159 -0
- package/dist/lib/agent/tools/write.js.map +1 -0
- package/dist/lib/ai/gateway.js +247 -0
- package/dist/lib/ai/gateway.js.map +1 -0
- package/dist/lib/ai/tool-loop-agent.js +591 -0
- package/dist/lib/ai/tool-loop-agent.js.map +1 -0
- package/dist/lib/auto-wiring.js +439 -0
- package/dist/lib/auto-wiring.js.map +1 -0
- package/dist/lib/browse/browserbase.js +163 -0
- package/dist/lib/browse/browserbase.js.map +1 -0
- package/dist/lib/browse/cloudflare.js +144 -0
- package/dist/lib/browse/cloudflare.js.map +1 -0
- package/dist/lib/browse/index.js +62 -0
- package/dist/lib/browse/index.js.map +1 -0
- package/dist/lib/browse/types.js +13 -0
- package/dist/lib/browse/types.js.map +1 -0
- package/dist/lib/cache/index.js +37 -0
- package/dist/lib/cache/index.js.map +1 -0
- package/dist/lib/cache/visibility.js +638 -0
- package/dist/lib/cache/visibility.js.map +1 -0
- package/dist/lib/capabilities.js +268 -0
- package/dist/lib/capabilities.js.map +1 -0
- package/dist/lib/channels/base.js +106 -0
- package/dist/lib/channels/base.js.map +1 -0
- package/dist/lib/channels/discord.js +94 -0
- package/dist/lib/channels/discord.js.map +1 -0
- package/dist/lib/channels/email.js +204 -0
- package/dist/lib/channels/email.js.map +1 -0
- package/dist/lib/channels/index.js +90 -0
- package/dist/lib/channels/index.js.map +1 -0
- package/dist/lib/channels/mdxui-chat.js +95 -0
- package/dist/lib/channels/mdxui-chat.js.map +1 -0
- package/dist/lib/channels/slack-blockkit.js +121 -0
- package/dist/lib/channels/slack-blockkit.js.map +1 -0
- package/dist/lib/channels/types.js +7 -0
- package/dist/lib/channels/types.js.map +1 -0
- package/dist/lib/cloudflare/ai.js +654 -0
- package/dist/lib/cloudflare/ai.js.map +1 -0
- package/dist/lib/cloudflare/index.js +88 -0
- package/dist/lib/cloudflare/index.js.map +1 -0
- package/dist/lib/cloudflare/kv.js +342 -0
- package/dist/lib/cloudflare/kv.js.map +1 -0
- package/dist/lib/cloudflare/queues.js +434 -0
- package/dist/lib/cloudflare/queues.js.map +1 -0
- package/dist/lib/cloudflare/r2.js +604 -0
- package/dist/lib/cloudflare/r2.js.map +1 -0
- package/dist/lib/cloudflare/vectorize.js +494 -0
- package/dist/lib/cloudflare/vectorize.js.map +1 -0
- package/dist/lib/cloudflare/workflows.js +569 -0
- package/dist/lib/cloudflare/workflows.js.map +1 -0
- package/dist/lib/colo/caching.js +196 -0
- package/dist/lib/colo/caching.js.map +1 -0
- package/dist/lib/colo/detection.js +194 -0
- package/dist/lib/colo/detection.js.map +1 -0
- package/dist/lib/colo/external-data.js +219 -0
- package/dist/lib/colo/external-data.js.map +1 -0
- package/dist/lib/colo/globe-data.js +179 -0
- package/dist/lib/colo/globe-data.js.map +1 -0
- package/dist/lib/colo/index.js +16 -0
- package/dist/lib/colo/index.js.map +1 -0
- package/dist/lib/decorators.js +37 -0
- package/dist/lib/decorators.js.map +1 -0
- package/dist/lib/discovery.js +81 -0
- package/dist/lib/discovery.js.map +1 -0
- package/dist/lib/executors/AgenticFunctionExecutor.js +619 -0
- package/dist/lib/executors/AgenticFunctionExecutor.js.map +1 -0
- package/dist/lib/executors/BaseFunctionExecutor.js +328 -0
- package/dist/lib/executors/BaseFunctionExecutor.js.map +1 -0
- package/dist/lib/executors/CascadeExecutor.js +418 -0
- package/dist/lib/executors/CascadeExecutor.js.map +1 -0
- package/dist/lib/executors/CodeFunctionExecutor.js +904 -0
- package/dist/lib/executors/CodeFunctionExecutor.js.map +1 -0
- package/dist/lib/executors/GenerativeFunctionExecutor.js +904 -0
- package/dist/lib/executors/GenerativeFunctionExecutor.js.map +1 -0
- package/dist/lib/executors/HumanFunctionExecutor.js +884 -0
- package/dist/lib/executors/HumanFunctionExecutor.js.map +1 -0
- package/dist/lib/executors/ParallelStepExecutor.js +308 -0
- package/dist/lib/executors/ParallelStepExecutor.js.map +1 -0
- package/dist/lib/executors/types.js +12 -0
- package/dist/lib/executors/types.js.map +1 -0
- package/dist/lib/experiments.js +89 -0
- package/dist/lib/experiments.js.map +1 -0
- package/dist/lib/flags/store.js +262 -0
- package/dist/lib/flags/store.js.map +1 -0
- package/dist/lib/functions/FunctionComposition.js +467 -0
- package/dist/lib/functions/FunctionComposition.js.map +1 -0
- package/dist/lib/functions/FunctionMiddleware.js +457 -0
- package/dist/lib/functions/FunctionMiddleware.js.map +1 -0
- package/dist/lib/functions/FunctionRegistry.js +426 -0
- package/dist/lib/functions/FunctionRegistry.js.map +1 -0
- package/dist/lib/functions/createFunction.js +1048 -0
- package/dist/lib/functions/createFunction.js.map +1 -0
- package/dist/lib/humans/index.js +68 -0
- package/dist/lib/humans/index.js.map +1 -0
- package/dist/lib/humans/templates.js +117 -0
- package/dist/lib/humans/templates.js.map +1 -0
- package/dist/lib/identity.js +98 -0
- package/dist/lib/identity.js.map +1 -0
- package/dist/lib/index.js +9 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/logging/error-logger.js +163 -0
- package/dist/lib/logging/error-logger.js.map +1 -0
- package/dist/lib/logging/index.js +160 -0
- package/dist/lib/logging/index.js.map +1 -0
- package/dist/lib/mixins/bash.js +825 -0
- package/dist/lib/mixins/bash.js.map +1 -0
- package/dist/lib/mixins/fs.js +648 -0
- package/dist/lib/mixins/fs.js.map +1 -0
- package/dist/lib/mixins/git.js +1011 -0
- package/dist/lib/mixins/git.js.map +1 -0
- package/dist/lib/mixins/index.js +29 -0
- package/dist/lib/mixins/index.js.map +1 -0
- package/dist/lib/mixins/npm.js +662 -0
- package/dist/lib/mixins/npm.js.map +1 -0
- package/dist/lib/noun-id.js +278 -0
- package/dist/lib/noun-id.js.map +1 -0
- package/dist/lib/rate-limit/sliding-window.js +148 -0
- package/dist/lib/rate-limit/sliding-window.js.map +1 -0
- package/dist/lib/rate-limit.js +110 -0
- package/dist/lib/rate-limit.js.map +1 -0
- package/dist/lib/rpc/bindings.js +548 -0
- package/dist/lib/rpc/bindings.js.map +1 -0
- package/dist/lib/rpc/index.js +64 -0
- package/dist/lib/rpc/index.js.map +1 -0
- package/dist/lib/safe-stringify.js +223 -0
- package/dist/lib/safe-stringify.js.map +1 -0
- package/dist/lib/sandbox/miniflare-sandbox.js +1007 -0
- package/dist/lib/sandbox/miniflare-sandbox.js.map +1 -0
- package/dist/lib/sqids.js +110 -0
- package/dist/lib/sqids.js.map +1 -0
- package/dist/lib/sql/adapters/index.js +10 -0
- package/dist/lib/sql/adapters/index.js.map +1 -0
- package/dist/lib/sql/adapters/node-sql-parser.js +552 -0
- package/dist/lib/sql/adapters/node-sql-parser.js.map +1 -0
- package/dist/lib/sql/adapters/pgsql-parser.js +1189 -0
- package/dist/lib/sql/adapters/pgsql-parser.js.map +1 -0
- package/dist/lib/sql/index.js +277 -0
- package/dist/lib/sql/index.js.map +1 -0
- package/dist/lib/sql/types.js +56 -0
- package/dist/lib/sql/types.js.map +1 -0
- package/dist/lib/type-classifier.js +126 -0
- package/dist/lib/type-classifier.js.map +1 -0
- package/dist/lib/utils/html.js +47 -0
- package/dist/lib/utils/html.js.map +1 -0
- package/dist/lib/validation.js +48 -0
- package/dist/lib/validation.js.map +1 -0
- package/dist/lib/vault/store.js +411 -0
- package/dist/lib/vault/store.js.map +1 -0
- package/dist/metrics/hunch.js +739 -0
- package/dist/metrics/hunch.js.map +1 -0
- package/dist/objects/API.js +302 -0
- package/dist/objects/API.js.map +1 -0
- package/dist/objects/Agent.js +179 -0
- package/dist/objects/Agent.js.map +1 -0
- package/dist/objects/AgenticFunctionExecutor.js +8 -0
- package/dist/objects/AgenticFunctionExecutor.js.map +1 -0
- package/dist/objects/App.js +83 -0
- package/dist/objects/App.js.map +1 -0
- package/dist/objects/Browser.js +884 -0
- package/dist/objects/Browser.js.map +1 -0
- package/dist/objects/Business.js +107 -0
- package/dist/objects/Business.js.map +1 -0
- package/dist/objects/CLI.js +221 -0
- package/dist/objects/CLI.js.map +1 -0
- package/dist/objects/CodeFunctionExecutor.js +8 -0
- package/dist/objects/CodeFunctionExecutor.js.map +1 -0
- package/dist/objects/Collection.js +161 -0
- package/dist/objects/Collection.js.map +1 -0
- package/dist/objects/DO.js +41 -0
- package/dist/objects/DO.js.map +1 -0
- package/dist/objects/DOBase.js +2309 -0
- package/dist/objects/DOBase.js.map +1 -0
- package/dist/objects/DOFull.js +1676 -0
- package/dist/objects/DOFull.js.map +1 -0
- package/dist/objects/DOTiny.js +207 -0
- package/dist/objects/DOTiny.js.map +1 -0
- package/dist/objects/Directory.js +199 -0
- package/dist/objects/Directory.js.map +1 -0
- package/dist/objects/Entity.js +413 -0
- package/dist/objects/Entity.js.map +1 -0
- package/dist/objects/Function.js +116 -0
- package/dist/objects/Function.js.map +1 -0
- package/dist/objects/Human.js +231 -0
- package/dist/objects/Human.js.map +1 -0
- package/dist/objects/HumanFunctionExecutor.js +8 -0
- package/dist/objects/HumanFunctionExecutor.js.map +1 -0
- package/dist/objects/IcebergMetadataDO.js +938 -0
- package/dist/objects/IcebergMetadataDO.js.map +1 -0
- package/dist/objects/IntegrationsDO.js +1174 -0
- package/dist/objects/IntegrationsDO.js.map +1 -0
- package/dist/objects/ObservabilityBroadcaster.js +149 -0
- package/dist/objects/ObservabilityBroadcaster.js.map +1 -0
- package/dist/objects/Package.js +154 -0
- package/dist/objects/Package.js.map +1 -0
- package/dist/objects/Product.js +193 -0
- package/dist/objects/Product.js.map +1 -0
- package/dist/objects/SDK.js +152 -0
- package/dist/objects/SDK.js.map +1 -0
- package/dist/objects/SaaS.js +235 -0
- package/dist/objects/SaaS.js.map +1 -0
- package/dist/objects/SandboxDO.js +759 -0
- package/dist/objects/SandboxDO.js.map +1 -0
- package/dist/objects/Service.js +337 -0
- package/dist/objects/Service.js.map +1 -0
- package/dist/objects/Site.js +80 -0
- package/dist/objects/Site.js.map +1 -0
- package/dist/objects/Startup.js +479 -0
- package/dist/objects/Startup.js.map +1 -0
- package/dist/objects/ThingsDO.js +170 -0
- package/dist/objects/ThingsDO.js.map +1 -0
- package/dist/objects/VectorShardDO.js +648 -0
- package/dist/objects/VectorShardDO.js.map +1 -0
- package/dist/objects/Worker.js +144 -0
- package/dist/objects/Worker.js.map +1 -0
- package/dist/objects/Workflow.js +196 -0
- package/dist/objects/Workflow.js.map +1 -0
- package/dist/objects/WorkflowFactory.js +313 -0
- package/dist/objects/WorkflowFactory.js.map +1 -0
- package/dist/objects/WorkflowRuntime.js +863 -0
- package/dist/objects/WorkflowRuntime.js.map +1 -0
- package/dist/objects/circuit-breaker-bulkhead.js +178 -0
- package/dist/objects/circuit-breaker-bulkhead.js.map +1 -0
- package/dist/objects/createFunction.js +934 -0
- package/dist/objects/createFunction.js.map +1 -0
- package/dist/objects/index.js +80 -0
- package/dist/objects/index.js.map +1 -0
- package/dist/objects/lifecycle/Branch.js +275 -0
- package/dist/objects/lifecycle/Branch.js.map +1 -0
- package/dist/objects/lifecycle/Clone.js +1499 -0
- package/dist/objects/lifecycle/Clone.js.map +1 -0
- package/dist/objects/lifecycle/Compact.js +237 -0
- package/dist/objects/lifecycle/Compact.js.map +1 -0
- package/dist/objects/lifecycle/Promote.js +476 -0
- package/dist/objects/lifecycle/Promote.js.map +1 -0
- package/dist/objects/lifecycle/Shard.js +560 -0
- package/dist/objects/lifecycle/Shard.js.map +1 -0
- package/dist/objects/lifecycle/index.js +15 -0
- package/dist/objects/lifecycle/index.js.map +1 -0
- package/dist/objects/lifecycle/types.js +33 -0
- package/dist/objects/lifecycle/types.js.map +1 -0
- package/dist/objects/mixins/infrastructure.js +171 -0
- package/dist/objects/mixins/infrastructure.js.map +1 -0
- package/dist/objects/modules/StoresModule.js +153 -0
- package/dist/objects/modules/StoresModule.js.map +1 -0
- package/dist/objects/persistence/checkpoint-manager.js +606 -0
- package/dist/objects/persistence/checkpoint-manager.js.map +1 -0
- package/dist/objects/persistence/index.js +72 -0
- package/dist/objects/persistence/index.js.map +1 -0
- package/dist/objects/persistence/migration-runner.js +562 -0
- package/dist/objects/persistence/migration-runner.js.map +1 -0
- package/dist/objects/persistence/replication-manager.js +501 -0
- package/dist/objects/persistence/replication-manager.js.map +1 -0
- package/dist/objects/persistence/tiered-storage-manager.js +595 -0
- package/dist/objects/persistence/tiered-storage-manager.js.map +1 -0
- package/dist/objects/persistence/types.js +14 -0
- package/dist/objects/persistence/types.js.map +1 -0
- package/dist/objects/persistence/wal-manager.js +653 -0
- package/dist/objects/persistence/wal-manager.js.map +1 -0
- package/dist/objects/presets/index.js +20 -0
- package/dist/objects/presets/index.js.map +1 -0
- package/dist/objects/presets/primitives.js +188 -0
- package/dist/objects/presets/primitives.js.map +1 -0
- package/dist/objects/primitives/alarm-adapter.js +141 -0
- package/dist/objects/primitives/alarm-adapter.js.map +1 -0
- package/dist/objects/primitives/index.js +337 -0
- package/dist/objects/primitives/index.js.map +1 -0
- package/dist/objects/primitives/storage-adapter.js +182 -0
- package/dist/objects/primitives/storage-adapter.js.map +1 -0
- package/dist/objects/primitives/with-primitives.js +102 -0
- package/dist/objects/primitives/with-primitives.js.map +1 -0
- package/dist/objects/services/StoreManager.js +227 -0
- package/dist/objects/services/StoreManager.js.map +1 -0
- package/dist/objects/services/index.js +13 -0
- package/dist/objects/services/index.js.map +1 -0
- package/dist/objects/transport/auth-layer.js +1451 -0
- package/dist/objects/transport/auth-layer.js.map +1 -0
- package/dist/objects/transport/capnweb-target.js +355 -0
- package/dist/objects/transport/capnweb-target.js.map +1 -0
- package/dist/objects/transport/chain.js +441 -0
- package/dist/objects/transport/chain.js.map +1 -0
- package/dist/objects/transport/handler.js +58 -0
- package/dist/objects/transport/handler.js.map +1 -0
- package/dist/objects/transport/index.js +53 -0
- package/dist/objects/transport/index.js.map +1 -0
- package/dist/objects/transport/mcp-server.js +690 -0
- package/dist/objects/transport/mcp-server.js.map +1 -0
- package/dist/objects/transport/rest-autowire.js +1507 -0
- package/dist/objects/transport/rest-autowire.js.map +1 -0
- package/dist/objects/transport/rest-router.js +440 -0
- package/dist/objects/transport/rest-router.js.map +1 -0
- package/dist/objects/transport/rpc-server.js +1536 -0
- package/dist/objects/transport/rpc-server.js.map +1 -0
- package/dist/objects/transport/shared.js +575 -0
- package/dist/objects/transport/shared.js.map +1 -0
- package/dist/objects/transport/sync-engine.js +291 -0
- package/dist/objects/transport/sync-engine.js.map +1 -0
- package/dist/objects/transport/types.js +8 -0
- package/dist/objects/transport/types.js.map +1 -0
- package/dist/primitives/bashx/src/ast/analyze.js +1472 -0
- package/dist/primitives/bashx/src/ast/analyze.js.map +1 -0
- package/dist/primitives/bashx/src/ast/parser.js +1488 -0
- package/dist/primitives/bashx/src/ast/parser.js.map +1 -0
- package/dist/primitives/bashx/src/do/commands/crypto.js +1954 -0
- package/dist/primitives/bashx/src/do/commands/crypto.js.map +1 -0
- package/dist/primitives/bashx/src/do/commands/data-processing.js +1812 -0
- package/dist/primitives/bashx/src/do/commands/data-processing.js.map +1 -0
- package/dist/primitives/bashx/src/do/commands/extended-utils.js +804 -0
- package/dist/primitives/bashx/src/do/commands/extended-utils.js.map +1 -0
- package/dist/primitives/bashx/src/do/commands/math-control.js +1122 -0
- package/dist/primitives/bashx/src/do/commands/math-control.js.map +1 -0
- package/dist/primitives/bashx/src/do/commands/posix-utils.js +1015 -0
- package/dist/primitives/bashx/src/do/commands/posix-utils.js.map +1 -0
- package/dist/primitives/bashx/src/do/commands/system-utils.js +687 -0
- package/dist/primitives/bashx/src/do/commands/system-utils.js.map +1 -0
- package/dist/primitives/bashx/src/do/commands/test-command.js +523 -0
- package/dist/primitives/bashx/src/do/commands/test-command.js.map +1 -0
- package/dist/primitives/bashx/src/do/commands/text-processing.js +1550 -0
- package/dist/primitives/bashx/src/do/commands/text-processing.js.map +1 -0
- package/dist/primitives/bashx/src/do/container-executor.js +429 -0
- package/dist/primitives/bashx/src/do/container-executor.js.map +1 -0
- package/dist/primitives/bashx/src/do/index.js +668 -0
- package/dist/primitives/bashx/src/do/index.js.map +1 -0
- package/dist/primitives/bashx/src/do/tiered-executor.js +2647 -0
- package/dist/primitives/bashx/src/do/tiered-executor.js.map +1 -0
- package/dist/primitives/bashx/src/do/worker.js +352 -0
- package/dist/primitives/bashx/src/do/worker.js.map +1 -0
- package/dist/primitives/bashx/src/types.js +10 -0
- package/dist/primitives/bashx/src/types.js.map +1 -0
- package/dist/primitives/fsx/core/backend.js +480 -0
- package/dist/primitives/fsx/core/backend.js.map +1 -0
- package/dist/primitives/fsx/core/constants.js +140 -0
- package/dist/primitives/fsx/core/constants.js.map +1 -0
- package/dist/primitives/fsx/core/fsx.js +1184 -0
- package/dist/primitives/fsx/core/fsx.js.map +1 -0
- package/dist/primitives/fsx/core/glob/glob.js +438 -0
- package/dist/primitives/fsx/core/glob/glob.js.map +1 -0
- package/dist/primitives/fsx/core/glob/index.js +8 -0
- package/dist/primitives/fsx/core/glob/index.js.map +1 -0
- package/dist/primitives/fsx/core/glob/match.js +392 -0
- package/dist/primitives/fsx/core/glob/match.js.map +1 -0
- package/dist/primitives/fsx/core/types.js +307 -0
- package/dist/primitives/fsx/core/types.js.map +1 -0
- package/dist/sandbox/index.js +258 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/sdk/capnweb-compat.js +42 -0
- package/dist/sdk/capnweb-compat.js.map +1 -0
- package/dist/sdk/client.js +20 -0
- package/dist/sdk/client.js.map +1 -0
- package/dist/sdk/index.js +17 -0
- package/dist/sdk/index.js.map +1 -0
- package/dist/snippets/artifacts-config.js +241 -0
- package/dist/snippets/artifacts-config.js.map +1 -0
- package/dist/snippets/artifacts-ingest.js +832 -0
- package/dist/snippets/artifacts-ingest.js.map +1 -0
- package/dist/snippets/artifacts-serve.js +1035 -0
- package/dist/snippets/artifacts-serve.js.map +1 -0
- package/dist/snippets/artifacts-types.js +161 -0
- package/dist/snippets/artifacts-types.js.map +1 -0
- package/dist/snippets/cache-probe.js +376 -0
- package/dist/snippets/cache-probe.js.map +1 -0
- package/dist/snippets/cache.js +10 -0
- package/dist/snippets/cache.js.map +1 -0
- package/dist/snippets/events.js +469 -0
- package/dist/snippets/events.js.map +1 -0
- package/dist/snippets/index.js +7 -0
- package/dist/snippets/index.js.map +1 -0
- package/dist/snippets/proxy.js +495 -0
- package/dist/snippets/proxy.js.map +1 -0
- package/dist/snippets/search.js +1759 -0
- package/dist/snippets/search.js.map +1 -0
- package/dist/streams/index.js +30 -0
- package/dist/streams/index.js.map +1 -0
- package/dist/streams/observability.js +68 -0
- package/dist/streams/observability.js.map +1 -0
- package/dist/types/AI.js +92 -0
- package/dist/types/AI.js.map +1 -0
- package/dist/types/AIFunction.js +171 -0
- package/dist/types/AIFunction.js.map +1 -0
- package/dist/types/BrowseVerb.js +89 -0
- package/dist/types/BrowseVerb.js.map +1 -0
- package/dist/types/Browser.js +31 -0
- package/dist/types/Browser.js.map +1 -0
- package/dist/types/Chaos.js +15 -0
- package/dist/types/Chaos.js.map +1 -0
- package/dist/types/CloudflareBindings.js +109 -0
- package/dist/types/CloudflareBindings.js.map +1 -0
- package/dist/types/Collection.js +50 -0
- package/dist/types/Collection.js.map +1 -0
- package/dist/types/DO.js +2 -0
- package/dist/types/DO.js.map +1 -0
- package/dist/types/DOLocation.js +63 -0
- package/dist/types/DOLocation.js.map +1 -0
- package/dist/types/EventHandler.js +57 -0
- package/dist/types/EventHandler.js.map +1 -0
- package/dist/types/Experiment.js +33 -0
- package/dist/types/Experiment.js.map +1 -0
- package/dist/types/Flag.js +57 -0
- package/dist/types/Flag.js.map +1 -0
- package/dist/types/Lifecycle.js +13 -0
- package/dist/types/Lifecycle.js.map +1 -0
- package/dist/types/Location.js +169 -0
- package/dist/types/Location.js.map +1 -0
- package/dist/types/Noun.js +66 -0
- package/dist/types/Noun.js.map +1 -0
- package/dist/types/SessionEvent.js +194 -0
- package/dist/types/SessionEvent.js.map +1 -0
- package/dist/types/Thing.js +55 -0
- package/dist/types/Thing.js.map +1 -0
- package/dist/types/ThingDO.js +153 -0
- package/dist/types/ThingDO.js.map +1 -0
- package/dist/types/Things.js +2 -0
- package/dist/types/Things.js.map +1 -0
- package/dist/types/Verb.js +119 -0
- package/dist/types/Verb.js.map +1 -0
- package/dist/types/WorkflowContext.js +70 -0
- package/dist/types/WorkflowContext.js.map +1 -0
- package/dist/types/analytics-api.js +13 -0
- package/dist/types/analytics-api.js.map +1 -0
- package/dist/types/capabilities.js +135 -0
- package/dist/types/capabilities.js.map +1 -0
- package/dist/types/drizzle.js +12 -0
- package/dist/types/drizzle.js.map +1 -0
- package/dist/types/event.js +201 -0
- package/dist/types/event.js.map +1 -0
- package/dist/types/fn.js +12 -0
- package/dist/types/fn.js.map +1 -0
- package/dist/types/iceberg.js +48 -0
- package/dist/types/iceberg.js.map +1 -0
- package/dist/types/ids.js +170 -0
- package/dist/types/ids.js.map +1 -0
- package/dist/types/index.js +41 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/introspect.js +54 -0
- package/dist/types/introspect.js.map +1 -0
- package/dist/types/observability.js +124 -0
- package/dist/types/observability.js.map +1 -0
- package/dist/types/sync-protocol.js +175 -0
- package/dist/types/sync-protocol.js.map +1 -0
- package/dist/types/vector.js +13 -0
- package/dist/types/vector.js.map +1 -0
- package/dist/workflows/ScheduleManager.js +473 -0
- package/dist/workflows/ScheduleManager.js.map +1 -0
- package/dist/workflows/StepDOBridge.js +149 -0
- package/dist/workflows/StepDOBridge.js.map +1 -0
- package/dist/workflows/StepResultStorage.js +232 -0
- package/dist/workflows/StepResultStorage.js.map +1 -0
- package/dist/workflows/WaitForEventManager.js +461 -0
- package/dist/workflows/WaitForEventManager.js.map +1 -0
- package/dist/workflows/analyzer.js +332 -0
- package/dist/workflows/analyzer.js.map +1 -0
- package/dist/workflows/compat/activity-router.js +484 -0
- package/dist/workflows/compat/activity-router.js.map +1 -0
- package/dist/workflows/compat/backends/cloudflare-workflows.js +431 -0
- package/dist/workflows/compat/backends/cloudflare-workflows.js.map +1 -0
- package/dist/workflows/compat/backends/index.js +14 -0
- package/dist/workflows/compat/backends/index.js.map +1 -0
- package/dist/workflows/compat/errors/index.js +375 -0
- package/dist/workflows/compat/errors/index.js.map +1 -0
- package/dist/workflows/compat/index.js +79 -0
- package/dist/workflows/compat/index.js.map +1 -0
- package/dist/workflows/compat/inngest/index.js +989 -0
- package/dist/workflows/compat/inngest/index.js.map +1 -0
- package/dist/workflows/compat/qstash/index.js +1263 -0
- package/dist/workflows/compat/qstash/index.js.map +1 -0
- package/dist/workflows/compat/temporal/activities.js +739 -0
- package/dist/workflows/compat/temporal/activities.js.map +1 -0
- package/dist/workflows/compat/temporal/child-workflows.js +154 -0
- package/dist/workflows/compat/temporal/child-workflows.js.map +1 -0
- package/dist/workflows/compat/temporal/client.js +381 -0
- package/dist/workflows/compat/temporal/client.js.map +1 -0
- package/dist/workflows/compat/temporal/context.js +309 -0
- package/dist/workflows/compat/temporal/context.js.map +1 -0
- package/dist/workflows/compat/temporal/determinism.js +216 -0
- package/dist/workflows/compat/temporal/determinism.js.map +1 -0
- package/dist/workflows/compat/temporal/errors.js +128 -0
- package/dist/workflows/compat/temporal/errors.js.map +1 -0
- package/dist/workflows/compat/temporal/index.js +2464 -0
- package/dist/workflows/compat/temporal/index.js.map +1 -0
- package/dist/workflows/compat/temporal/saga.js +504 -0
- package/dist/workflows/compat/temporal/saga.js.map +1 -0
- package/dist/workflows/compat/temporal/signals.js +364 -0
- package/dist/workflows/compat/temporal/signals.js.map +1 -0
- package/dist/workflows/compat/temporal/storage.js +271 -0
- package/dist/workflows/compat/temporal/storage.js.map +1 -0
- package/dist/workflows/compat/temporal/timers.js +347 -0
- package/dist/workflows/compat/temporal/timers.js.map +1 -0
- package/dist/workflows/compat/temporal/types.js +7 -0
- package/dist/workflows/compat/temporal/types.js.map +1 -0
- package/dist/workflows/compat/temporal/unified-primitives.js +339 -0
- package/dist/workflows/compat/temporal/unified-primitives.js.map +1 -0
- package/dist/workflows/compat/trigger/index.js +468 -0
- package/dist/workflows/compat/trigger/index.js.map +1 -0
- package/dist/workflows/compat/utils/index.js +69 -0
- package/dist/workflows/compat/utils/index.js.map +1 -0
- package/dist/workflows/context/correlation-capability.js +266 -0
- package/dist/workflows/context/correlation-capability.js.map +1 -0
- package/dist/workflows/context/correlation.js +484 -0
- package/dist/workflows/context/correlation.js.map +1 -0
- package/dist/workflows/context/experiment.js +289 -0
- package/dist/workflows/context/experiment.js.map +1 -0
- package/dist/workflows/context/flag.js +244 -0
- package/dist/workflows/context/flag.js.map +1 -0
- package/dist/workflows/context/foundation.js +648 -0
- package/dist/workflows/context/foundation.js.map +1 -0
- package/dist/workflows/context/human-base.js +106 -0
- package/dist/workflows/context/human-base.js.map +1 -0
- package/dist/workflows/context/human.js +368 -0
- package/dist/workflows/context/human.js.map +1 -0
- package/dist/workflows/context/measure.js +354 -0
- package/dist/workflows/context/measure.js.map +1 -0
- package/dist/workflows/context/rate-limit.js +358 -0
- package/dist/workflows/context/rate-limit.js.map +1 -0
- package/dist/workflows/context/user.js +117 -0
- package/dist/workflows/context/user.js.map +1 -0
- package/dist/workflows/context/vault.js +360 -0
- package/dist/workflows/context/vault.js.map +1 -0
- package/dist/workflows/data/entity-events/entity-events.js +489 -0
- package/dist/workflows/data/entity-events/entity-events.js.map +1 -0
- package/dist/workflows/data/experiment/index.js +599 -0
- package/dist/workflows/data/experiment/index.js.map +1 -0
- package/dist/workflows/data/goal/context.js +558 -0
- package/dist/workflows/data/goal/context.js.map +1 -0
- package/dist/workflows/data/goal/index.js +32 -0
- package/dist/workflows/data/goal/index.js.map +1 -0
- package/dist/workflows/data/measure/index.js +840 -0
- package/dist/workflows/data/measure/index.js.map +1 -0
- package/dist/workflows/data/stream/index.js +1215 -0
- package/dist/workflows/data/stream/index.js.map +1 -0
- package/dist/workflows/data/track/context.js +883 -0
- package/dist/workflows/data/track/context.js.map +1 -0
- package/dist/workflows/data/track/index.js +15 -0
- package/dist/workflows/data/track/index.js.map +1 -0
- package/dist/workflows/data/view/context.js +864 -0
- package/dist/workflows/data/view/context.js.map +1 -0
- package/dist/workflows/domain.js +93 -0
- package/dist/workflows/domain.js.map +1 -0
- package/dist/workflows/flag.js +176 -0
- package/dist/workflows/flag.js.map +1 -0
- package/dist/workflows/flags.js +217 -0
- package/dist/workflows/flags.js.map +1 -0
- package/dist/workflows/hash.js +209 -0
- package/dist/workflows/hash.js.map +1 -0
- package/dist/workflows/index.js +50 -0
- package/dist/workflows/index.js.map +1 -0
- package/dist/workflows/on.js +378 -0
- package/dist/workflows/on.js.map +1 -0
- package/dist/workflows/pipeline-promise.js +481 -0
- package/dist/workflows/pipeline-promise.js.map +1 -0
- package/dist/workflows/pipeline-types.js +20 -0
- package/dist/workflows/pipeline-types.js.map +1 -0
- package/dist/workflows/proxy.js +76 -0
- package/dist/workflows/proxy.js.map +1 -0
- package/dist/workflows/runtime.js +310 -0
- package/dist/workflows/runtime.js.map +1 -0
- package/dist/workflows/schedule-builder.js +327 -0
- package/dist/workflows/schedule-builder.js.map +1 -0
- package/dist/workflows/visibility/index.js +148 -0
- package/dist/workflows/visibility/index.js.map +1 -0
- package/dist/workflows/visibility/query-parser.js +150 -0
- package/dist/workflows/visibility/query-parser.js.map +1 -0
- package/dist/workflows/visibility/store.js +223 -0
- package/dist/workflows/visibility/store.js.map +1 -0
- package/dist/workflows/visibility/types.js +30 -0
- package/dist/workflows/visibility/types.js.map +1 -0
- package/dist/workflows/workflow.js +53 -0
- package/dist/workflows/workflow.js.map +1 -0
- package/package.json +279 -46
|
@@ -0,0 +1,884 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HumanFunctionExecutor
|
|
3
|
+
*
|
|
4
|
+
* Execution engine for HumanFunction - a function type that queues tasks for human input.
|
|
5
|
+
* Supports multiple channels (slack, email, in-app), structured forms,
|
|
6
|
+
* timeout handling, escalation, and approval workflows.
|
|
7
|
+
*/
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// ERROR CLASSES
|
|
10
|
+
// ============================================================================
|
|
11
|
+
export class HumanTimeoutError extends Error {
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = 'HumanTimeoutError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export class HumanChannelError extends Error {
|
|
18
|
+
constructor(message) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = 'HumanChannelError';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export class HumanValidationError extends Error {
|
|
24
|
+
fields;
|
|
25
|
+
constructor(message, fields) {
|
|
26
|
+
super(message);
|
|
27
|
+
this.name = 'HumanValidationError';
|
|
28
|
+
this.fields = fields;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export class HumanEscalationError extends Error {
|
|
32
|
+
constructor(message) {
|
|
33
|
+
super(message);
|
|
34
|
+
this.name = 'HumanEscalationError';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export class HumanApprovalRejectedError extends Error {
|
|
38
|
+
constructor(message) {
|
|
39
|
+
super(message);
|
|
40
|
+
this.name = 'HumanApprovalRejectedError';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export class HumanCancelledError extends Error {
|
|
44
|
+
constructor(message) {
|
|
45
|
+
super(message);
|
|
46
|
+
this.name = 'HumanCancelledError';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export class HumanNotificationFailedError extends Error {
|
|
50
|
+
constructor(message) {
|
|
51
|
+
super(message);
|
|
52
|
+
this.name = 'HumanNotificationFailedError';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// ============================================================================
|
|
56
|
+
// UTILITY FUNCTIONS
|
|
57
|
+
// ============================================================================
|
|
58
|
+
function generateTaskId() {
|
|
59
|
+
return `task-${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;
|
|
60
|
+
}
|
|
61
|
+
function interpolatePrompt(prompt, input) {
|
|
62
|
+
return prompt.replace(/\{\{(\w+)\}\}/g, (_, key) => {
|
|
63
|
+
const value = input[key];
|
|
64
|
+
return value !== undefined ? String(value) : `{{${key}}}`;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function sleep(ms) {
|
|
68
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
69
|
+
}
|
|
70
|
+
// ============================================================================
|
|
71
|
+
// HUMAN FUNCTION EXECUTOR
|
|
72
|
+
// ============================================================================
|
|
73
|
+
export class HumanFunctionExecutor {
|
|
74
|
+
state;
|
|
75
|
+
env;
|
|
76
|
+
channels;
|
|
77
|
+
notificationService;
|
|
78
|
+
onEvent;
|
|
79
|
+
constructor(options) {
|
|
80
|
+
this.state = options.state;
|
|
81
|
+
this.env = options.env;
|
|
82
|
+
this.channels = options.channels;
|
|
83
|
+
this.notificationService = options.notificationService;
|
|
84
|
+
this.onEvent = options.onEvent;
|
|
85
|
+
}
|
|
86
|
+
async execute(task) {
|
|
87
|
+
const startTime = Date.now();
|
|
88
|
+
const taskId = generateTaskId();
|
|
89
|
+
const metrics = {
|
|
90
|
+
notificationsSent: 0,
|
|
91
|
+
retries: 0,
|
|
92
|
+
waitTime: 0,
|
|
93
|
+
};
|
|
94
|
+
// Check if already cancelled
|
|
95
|
+
if (task.signal?.aborted) {
|
|
96
|
+
return {
|
|
97
|
+
success: false,
|
|
98
|
+
error: new HumanCancelledError('Task cancelled before execution'),
|
|
99
|
+
taskId,
|
|
100
|
+
duration: 0,
|
|
101
|
+
channel: Array.isArray(task.channel) ? task.channel[0] : task.channel,
|
|
102
|
+
metrics,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
// Validate channel exists before proceeding
|
|
106
|
+
const channelNames = Array.isArray(task.channel) ? task.channel : [task.channel];
|
|
107
|
+
for (const channelName of channelNames) {
|
|
108
|
+
if (!this.channels[channelName]) {
|
|
109
|
+
throw new HumanChannelError(`Unknown channel: ${channelName}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Build context
|
|
113
|
+
const context = this.buildContext(taskId, task);
|
|
114
|
+
// Emit started event
|
|
115
|
+
await this.emit('human.started', { taskId, channel: task.channel });
|
|
116
|
+
try {
|
|
117
|
+
// Handle approval workflows
|
|
118
|
+
if (task.approval) {
|
|
119
|
+
return await this.executeApprovalWorkflow(task, taskId, startTime, metrics, context);
|
|
120
|
+
}
|
|
121
|
+
// Handle multi-channel
|
|
122
|
+
if (Array.isArray(task.channel)) {
|
|
123
|
+
return await this.executeMultiChannel(task, taskId, startTime, metrics, context);
|
|
124
|
+
}
|
|
125
|
+
// Single channel execution
|
|
126
|
+
return await this.executeSingleChannel(task, taskId, startTime, metrics, context);
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
const duration = Date.now() - startTime;
|
|
130
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
131
|
+
await this.emit('human.error', { taskId, error: err.message });
|
|
132
|
+
// Persist error state
|
|
133
|
+
await this.state.storage.put(`task:${taskId}`, {
|
|
134
|
+
status: 'failed',
|
|
135
|
+
error: err.message,
|
|
136
|
+
});
|
|
137
|
+
return {
|
|
138
|
+
success: false,
|
|
139
|
+
error: err instanceof HumanChannelError || err instanceof HumanTimeoutError ||
|
|
140
|
+
err instanceof HumanValidationError || err instanceof HumanCancelledError ||
|
|
141
|
+
err instanceof HumanNotificationFailedError
|
|
142
|
+
? err
|
|
143
|
+
: new HumanChannelError(err.message),
|
|
144
|
+
taskId,
|
|
145
|
+
duration,
|
|
146
|
+
channel: Array.isArray(task.channel) ? task.channel[0] : task.channel,
|
|
147
|
+
metrics,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async executeSingleChannel(task, taskId, startTime, metrics, context, escalationLevel = 0, useFallback = false) {
|
|
152
|
+
let channelName = useFallback && task.fallbackChannel ? task.fallbackChannel : task.channel;
|
|
153
|
+
const channel = this.channels[channelName];
|
|
154
|
+
if (!channel) {
|
|
155
|
+
throw new HumanChannelError(`Unknown channel: ${channelName}`);
|
|
156
|
+
}
|
|
157
|
+
// Resolve prompt
|
|
158
|
+
const message = typeof task.prompt === 'function'
|
|
159
|
+
? task.prompt(task.input)
|
|
160
|
+
: interpolatePrompt(task.prompt, task.input || {});
|
|
161
|
+
// Build notification payload
|
|
162
|
+
let payload = this.buildNotificationPayload(task, message, channelName);
|
|
163
|
+
// Call onSend callback if provided
|
|
164
|
+
if (task.onSend) {
|
|
165
|
+
const modified = task.onSend(payload);
|
|
166
|
+
if (modified) {
|
|
167
|
+
payload = modified;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// Send notification with retries
|
|
171
|
+
let messageId;
|
|
172
|
+
let retries = 0;
|
|
173
|
+
const maxRetries = task.delivery?.maxRetries ?? 1;
|
|
174
|
+
const retryDelay = task.delivery?.retryDelay ?? 1000;
|
|
175
|
+
const backoff = task.delivery?.backoff ?? 'fixed';
|
|
176
|
+
while (true) {
|
|
177
|
+
try {
|
|
178
|
+
const sendResult = await channel.send(payload);
|
|
179
|
+
messageId = sendResult.messageId;
|
|
180
|
+
metrics.notificationsSent = (metrics.notificationsSent || 0) + 1;
|
|
181
|
+
// Store notification info
|
|
182
|
+
await this.state.storage.put(`notification:${taskId}`, {
|
|
183
|
+
messageId,
|
|
184
|
+
channel: channelName,
|
|
185
|
+
});
|
|
186
|
+
await this.emit('human.notification.sent', { channel: channelName, messageId });
|
|
187
|
+
// Confirm delivery if required
|
|
188
|
+
if (task.confirmDelivery && !sendResult.delivered) {
|
|
189
|
+
const status = await this.notificationService.getDeliveryStatus(messageId);
|
|
190
|
+
if (status.status === 'failed') {
|
|
191
|
+
throw new HumanNotificationFailedError(`Delivery failed: ${status.error}`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
retries++;
|
|
198
|
+
metrics.retries = retries;
|
|
199
|
+
if (retries >= maxRetries) {
|
|
200
|
+
// Try fallback channel if available
|
|
201
|
+
if (!useFallback && task.fallbackChannel && this.channels[task.fallbackChannel]) {
|
|
202
|
+
metrics.primaryChannelFailed = true;
|
|
203
|
+
return this.executeSingleChannel(task, taskId, startTime, metrics, context, escalationLevel, true);
|
|
204
|
+
}
|
|
205
|
+
// HumanNotificationFailedError if delivery config specified (retry logic), otherwise HumanChannelError
|
|
206
|
+
if (task.delivery) {
|
|
207
|
+
throw new HumanNotificationFailedError(`Failed to send notification after ${retries} attempts`);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
throw new HumanChannelError(`Failed to send: Channel unavailable`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const delay = backoff === 'exponential' ? retryDelay * Math.pow(2, retries - 1) : retryDelay;
|
|
214
|
+
await sleep(delay);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
// Set up reminder if configured
|
|
218
|
+
let reminderTimeout;
|
|
219
|
+
if (task.reminder) {
|
|
220
|
+
const reminderTime = task.timeout - task.reminder.before;
|
|
221
|
+
if (reminderTime > 0) {
|
|
222
|
+
reminderTimeout = setTimeout(async () => {
|
|
223
|
+
const reminderPayload = { ...payload, message: task.reminder.message };
|
|
224
|
+
await channel.send(reminderPayload);
|
|
225
|
+
}, reminderTime);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
// Set up cancellation listener
|
|
229
|
+
let cancelled = false;
|
|
230
|
+
const abortHandler = () => {
|
|
231
|
+
cancelled = true;
|
|
232
|
+
};
|
|
233
|
+
task.signal?.addEventListener('abort', abortHandler);
|
|
234
|
+
// Wait for response with timeout
|
|
235
|
+
const waitStart = Date.now();
|
|
236
|
+
try {
|
|
237
|
+
const response = await Promise.race([
|
|
238
|
+
channel.waitForResponse({ timeout: task.timeout }),
|
|
239
|
+
new Promise((_, reject) => {
|
|
240
|
+
setTimeout(() => reject(new HumanTimeoutError(`Timeout after ${task.timeout}ms`)), task.timeout);
|
|
241
|
+
}),
|
|
242
|
+
new Promise((_, reject) => {
|
|
243
|
+
if (task.signal) {
|
|
244
|
+
task.signal.addEventListener('abort', () => {
|
|
245
|
+
this.notificationService.cancelPending();
|
|
246
|
+
reject(new HumanCancelledError('Task cancelled'));
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}),
|
|
250
|
+
]);
|
|
251
|
+
if (cancelled) {
|
|
252
|
+
await this.notificationService.cancelPending();
|
|
253
|
+
throw new HumanCancelledError('Task cancelled');
|
|
254
|
+
}
|
|
255
|
+
if (reminderTimeout)
|
|
256
|
+
clearTimeout(reminderTimeout);
|
|
257
|
+
task.signal?.removeEventListener('abort', abortHandler);
|
|
258
|
+
const waitTime = Date.now() - waitStart;
|
|
259
|
+
metrics.waitTime = waitTime;
|
|
260
|
+
await this.emit('human.response.received', { action: response.action, userId: response.userId });
|
|
261
|
+
// Apply onResponse callback
|
|
262
|
+
let processedResponse = response;
|
|
263
|
+
if (task.onResponse) {
|
|
264
|
+
const modified = task.onResponse(response);
|
|
265
|
+
if (modified) {
|
|
266
|
+
processedResponse = modified;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
// Apply transformResponse
|
|
270
|
+
if (task.transformResponse) {
|
|
271
|
+
processedResponse = task.transformResponse(processedResponse);
|
|
272
|
+
}
|
|
273
|
+
// Validate action
|
|
274
|
+
if (task.actions && task.actions.length > 0) {
|
|
275
|
+
const validActions = task.actions.map(a => typeof a === 'string' ? a : a.value);
|
|
276
|
+
if (!validActions.includes(processedResponse.action)) {
|
|
277
|
+
const validationError = new HumanValidationError(`Invalid action: ${processedResponse.action}. Expected one of: ${validActions.join(', ')}`);
|
|
278
|
+
return {
|
|
279
|
+
success: false,
|
|
280
|
+
error: validationError,
|
|
281
|
+
taskId,
|
|
282
|
+
duration: Date.now() - startTime,
|
|
283
|
+
channel: useFallback && task.fallbackChannel ? task.fallbackChannel : channelName,
|
|
284
|
+
metrics,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
// Validate form
|
|
289
|
+
if (task.form) {
|
|
290
|
+
const validationResult = await this.validateForm(task.form, processedResponse.data, task.applyDefaults);
|
|
291
|
+
if (!validationResult.valid) {
|
|
292
|
+
return {
|
|
293
|
+
success: false,
|
|
294
|
+
error: validationResult.error,
|
|
295
|
+
taskId,
|
|
296
|
+
duration: Date.now() - startTime,
|
|
297
|
+
channel: useFallback && task.fallbackChannel ? task.fallbackChannel : channelName,
|
|
298
|
+
metrics,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
if (validationResult.data) {
|
|
302
|
+
processedResponse.data = validationResult.data;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
// Validate with schema
|
|
306
|
+
if (task.responseSchema) {
|
|
307
|
+
const schemaResult = this.validateSchema(task.responseSchema, processedResponse.data);
|
|
308
|
+
if (!schemaResult.valid) {
|
|
309
|
+
return {
|
|
310
|
+
success: false,
|
|
311
|
+
error: new HumanValidationError(schemaResult.error),
|
|
312
|
+
taskId,
|
|
313
|
+
duration: Date.now() - startTime,
|
|
314
|
+
channel: useFallback && task.fallbackChannel ? task.fallbackChannel : channelName,
|
|
315
|
+
metrics,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
// Custom validation
|
|
320
|
+
if (task.validateResponse) {
|
|
321
|
+
// Only pass context if the validator function explicitly accepts 2 args
|
|
322
|
+
const validResult = task.validateResponse.length > 1
|
|
323
|
+
? await task.validateResponse(processedResponse, context)
|
|
324
|
+
: await task.validateResponse(processedResponse);
|
|
325
|
+
if (validResult !== true) {
|
|
326
|
+
const errorMessage = typeof validResult === 'string' ? validResult : 'Validation failed';
|
|
327
|
+
return {
|
|
328
|
+
success: false,
|
|
329
|
+
error: new HumanValidationError(errorMessage),
|
|
330
|
+
taskId,
|
|
331
|
+
duration: Date.now() - startTime,
|
|
332
|
+
channel: useFallback && task.fallbackChannel ? task.fallbackChannel : channelName,
|
|
333
|
+
metrics,
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
// Update message if configured
|
|
338
|
+
if (task.updateOnResponse && channel.updateMessage) {
|
|
339
|
+
await channel.updateMessage(messageId, {
|
|
340
|
+
message: `Request ${processedResponse.action}d by ${processedResponse.userId}`,
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
// Store audit log
|
|
344
|
+
await this.state.storage.put(`audit:${taskId}`, {
|
|
345
|
+
taskId,
|
|
346
|
+
action: processedResponse.action,
|
|
347
|
+
userId: processedResponse.userId,
|
|
348
|
+
comment: processedResponse.data?.comment || processedResponse.data?.reason,
|
|
349
|
+
timestamp: processedResponse.timestamp,
|
|
350
|
+
});
|
|
351
|
+
await this.emit('human.decision', { action: processedResponse.action, userId: processedResponse.userId });
|
|
352
|
+
const duration = Date.now() - startTime;
|
|
353
|
+
await this.emit('human.completed', { success: true, duration });
|
|
354
|
+
return {
|
|
355
|
+
success: true,
|
|
356
|
+
response: processedResponse,
|
|
357
|
+
taskId,
|
|
358
|
+
duration,
|
|
359
|
+
respondedBy: processedResponse.userId,
|
|
360
|
+
respondedAt: processedResponse.timestamp,
|
|
361
|
+
channel: useFallback && task.fallbackChannel ? task.fallbackChannel : channelName,
|
|
362
|
+
escalated: escalationLevel > 0,
|
|
363
|
+
escalationLevel: escalationLevel > 0 ? escalationLevel : undefined,
|
|
364
|
+
metrics,
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
catch (error) {
|
|
368
|
+
if (reminderTimeout)
|
|
369
|
+
clearTimeout(reminderTimeout);
|
|
370
|
+
task.signal?.removeEventListener('abort', abortHandler);
|
|
371
|
+
if (error instanceof HumanCancelledError) {
|
|
372
|
+
return {
|
|
373
|
+
success: false,
|
|
374
|
+
error,
|
|
375
|
+
taskId,
|
|
376
|
+
duration: Date.now() - startTime,
|
|
377
|
+
channel: channelName,
|
|
378
|
+
metrics,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
if (error instanceof HumanTimeoutError) {
|
|
382
|
+
metrics.waitTime = Date.now() - waitStart;
|
|
383
|
+
// Persist timeout state
|
|
384
|
+
await this.state.storage.put(`task:${taskId}`, {
|
|
385
|
+
status: 'timeout',
|
|
386
|
+
notificationSent: true,
|
|
387
|
+
messageId: messageId,
|
|
388
|
+
});
|
|
389
|
+
await this.emit('human.timeout', { taskId, timeout: task.timeout });
|
|
390
|
+
// Handle default on timeout
|
|
391
|
+
if (task.defaultOnTimeout) {
|
|
392
|
+
const defaultResponse = {
|
|
393
|
+
action: task.defaultOnTimeout.action,
|
|
394
|
+
userId: 'system',
|
|
395
|
+
timestamp: new Date(),
|
|
396
|
+
data: { reason: task.defaultOnTimeout.reason },
|
|
397
|
+
isDefault: true,
|
|
398
|
+
};
|
|
399
|
+
return {
|
|
400
|
+
success: true,
|
|
401
|
+
response: defaultResponse,
|
|
402
|
+
taskId,
|
|
403
|
+
duration: Date.now() - startTime,
|
|
404
|
+
channel: channelName,
|
|
405
|
+
metrics,
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
// Handle escalation
|
|
409
|
+
if (task.escalation) {
|
|
410
|
+
await this.emit('human.escalated', {
|
|
411
|
+
fromChannel: channelName,
|
|
412
|
+
toChannel: task.escalation.to,
|
|
413
|
+
level: escalationLevel + 1,
|
|
414
|
+
});
|
|
415
|
+
const escalatedTask = {
|
|
416
|
+
...task,
|
|
417
|
+
channel: task.escalation.to,
|
|
418
|
+
timeout: task.escalation.next?.timeout || task.escalation.timeout,
|
|
419
|
+
channelOptions: {
|
|
420
|
+
...task.channelOptions,
|
|
421
|
+
[task.escalation.to]: task.escalation.channelOptions,
|
|
422
|
+
},
|
|
423
|
+
escalation: task.escalation.next,
|
|
424
|
+
};
|
|
425
|
+
return this.executeSingleChannel(escalatedTask, taskId, startTime, metrics, context, escalationLevel + 1);
|
|
426
|
+
}
|
|
427
|
+
return {
|
|
428
|
+
success: false,
|
|
429
|
+
error,
|
|
430
|
+
taskId,
|
|
431
|
+
duration: Date.now() - startTime,
|
|
432
|
+
channel: channelName,
|
|
433
|
+
escalated: escalationLevel > 0,
|
|
434
|
+
metrics,
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
throw error;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
async executeMultiChannel(task, taskId, startTime, metrics, context) {
|
|
441
|
+
const channels = task.channel;
|
|
442
|
+
// Resolve prompt once
|
|
443
|
+
const message = typeof task.prompt === 'function'
|
|
444
|
+
? task.prompt(task.input)
|
|
445
|
+
: interpolatePrompt(task.prompt, task.input || {});
|
|
446
|
+
// Send to all channels
|
|
447
|
+
const sendPromises = channels.map(async (channelName) => {
|
|
448
|
+
const channel = this.channels[channelName];
|
|
449
|
+
if (!channel) {
|
|
450
|
+
throw new HumanChannelError(`Unknown channel: ${channelName}`);
|
|
451
|
+
}
|
|
452
|
+
const channelOptions = task.channelOptions?.[channelName] || {};
|
|
453
|
+
const payload = this.buildNotificationPayload({ ...task, channelOptions: channelOptions }, message, channelName);
|
|
454
|
+
await channel.send(payload);
|
|
455
|
+
metrics.notificationsSent = (metrics.notificationsSent || 0) + 1;
|
|
456
|
+
});
|
|
457
|
+
await Promise.all(sendPromises);
|
|
458
|
+
// Race for first response
|
|
459
|
+
const responsePromises = channels.map(async (channelName) => {
|
|
460
|
+
const channel = this.channels[channelName];
|
|
461
|
+
const response = await channel.waitForResponse({ timeout: task.timeout });
|
|
462
|
+
return { channelName, response };
|
|
463
|
+
});
|
|
464
|
+
const { channelName: respondingChannel, response } = await Promise.race(responsePromises);
|
|
465
|
+
// Cancel pending notifications
|
|
466
|
+
await this.notificationService.cancelPending();
|
|
467
|
+
const waitTime = Date.now() - startTime;
|
|
468
|
+
metrics.waitTime = waitTime;
|
|
469
|
+
return {
|
|
470
|
+
success: true,
|
|
471
|
+
response,
|
|
472
|
+
taskId,
|
|
473
|
+
duration: Date.now() - startTime,
|
|
474
|
+
respondedBy: response.userId,
|
|
475
|
+
respondedAt: response.timestamp,
|
|
476
|
+
channel: respondingChannel,
|
|
477
|
+
metrics,
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
async executeApprovalWorkflow(task, taskId, startTime, metrics, context) {
|
|
481
|
+
const approval = task.approval;
|
|
482
|
+
const channelName = task.channel;
|
|
483
|
+
const channel = this.channels[channelName];
|
|
484
|
+
if (!channel) {
|
|
485
|
+
throw new HumanChannelError(`Unknown channel: ${channelName}`);
|
|
486
|
+
}
|
|
487
|
+
const message = typeof task.prompt === 'function'
|
|
488
|
+
? task.prompt(task.input)
|
|
489
|
+
: interpolatePrompt(task.prompt, task.input || {});
|
|
490
|
+
if (approval.type === 'sequential') {
|
|
491
|
+
return this.executeSequentialApproval(task, taskId, startTime, metrics, channel, message);
|
|
492
|
+
}
|
|
493
|
+
else if (approval.type === 'parallel') {
|
|
494
|
+
return this.executeParallelApproval(task, taskId, startTime, metrics, channel, message);
|
|
495
|
+
}
|
|
496
|
+
else if (approval.type === 'conditional') {
|
|
497
|
+
return this.executeConditionalApproval(task, taskId, startTime, metrics, channel, message);
|
|
498
|
+
}
|
|
499
|
+
throw new Error(`Unknown approval type: ${approval.type}`);
|
|
500
|
+
}
|
|
501
|
+
async executeSequentialApproval(task, taskId, startTime, metrics, channel, message) {
|
|
502
|
+
const approval = task.approval;
|
|
503
|
+
const levels = approval.levels || [];
|
|
504
|
+
const approvals = [];
|
|
505
|
+
for (const level of levels) {
|
|
506
|
+
const payload = this.buildNotificationPayload(task, message, channel.name);
|
|
507
|
+
payload.mentions = level.users;
|
|
508
|
+
await channel.send(payload);
|
|
509
|
+
metrics.notificationsSent = (metrics.notificationsSent || 0) + 1;
|
|
510
|
+
const response = await channel.waitForResponse({ timeout: task.timeout });
|
|
511
|
+
approvals.push({
|
|
512
|
+
userId: response.userId,
|
|
513
|
+
action: response.action,
|
|
514
|
+
timestamp: response.timestamp,
|
|
515
|
+
});
|
|
516
|
+
if (response.action === 'reject') {
|
|
517
|
+
return {
|
|
518
|
+
success: true,
|
|
519
|
+
response: {
|
|
520
|
+
...response,
|
|
521
|
+
action: 'reject',
|
|
522
|
+
approvals,
|
|
523
|
+
rejectedBy: response.userId,
|
|
524
|
+
rejectionLevel: level.name,
|
|
525
|
+
},
|
|
526
|
+
taskId,
|
|
527
|
+
duration: Date.now() - startTime,
|
|
528
|
+
channel: channel.name,
|
|
529
|
+
metrics,
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return {
|
|
534
|
+
success: true,
|
|
535
|
+
response: {
|
|
536
|
+
action: 'approve',
|
|
537
|
+
userId: approvals[approvals.length - 1]?.userId || '',
|
|
538
|
+
timestamp: new Date(),
|
|
539
|
+
data: {},
|
|
540
|
+
approvals,
|
|
541
|
+
},
|
|
542
|
+
taskId,
|
|
543
|
+
duration: Date.now() - startTime,
|
|
544
|
+
channel: channel.name,
|
|
545
|
+
metrics,
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
async executeParallelApproval(task, taskId, startTime, metrics, channel, message) {
|
|
549
|
+
const approval = task.approval;
|
|
550
|
+
const users = approval.users || [];
|
|
551
|
+
const requiredApprovals = approval.requiredApprovals || users.length;
|
|
552
|
+
const failFast = approval.failFast || false;
|
|
553
|
+
const approvals = [];
|
|
554
|
+
let approvalCount = 0;
|
|
555
|
+
let rejectionCount = 0;
|
|
556
|
+
// Send to all users
|
|
557
|
+
for (const _user of users) {
|
|
558
|
+
const payload = this.buildNotificationPayload(task, message, channel.name);
|
|
559
|
+
await channel.send(payload);
|
|
560
|
+
metrics.notificationsSent = (metrics.notificationsSent || 0) + 1;
|
|
561
|
+
}
|
|
562
|
+
// Collect responses
|
|
563
|
+
for (let i = 0; i < users.length; i++) {
|
|
564
|
+
// Check if we can fast-fail
|
|
565
|
+
if (failFast) {
|
|
566
|
+
const remainingUsers = users.length - i;
|
|
567
|
+
const maxPossibleApprovals = approvalCount + remainingUsers;
|
|
568
|
+
if (maxPossibleApprovals < requiredApprovals) {
|
|
569
|
+
break;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
// Check if we already have enough approvals
|
|
573
|
+
if (approvalCount >= requiredApprovals) {
|
|
574
|
+
break;
|
|
575
|
+
}
|
|
576
|
+
const response = await channel.waitForResponse({ timeout: task.timeout });
|
|
577
|
+
approvals.push({
|
|
578
|
+
userId: response.userId,
|
|
579
|
+
action: response.action,
|
|
580
|
+
timestamp: response.timestamp,
|
|
581
|
+
});
|
|
582
|
+
if (response.action === 'approve') {
|
|
583
|
+
approvalCount++;
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
rejectionCount++;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
const success = approvalCount >= requiredApprovals;
|
|
590
|
+
return {
|
|
591
|
+
success: true,
|
|
592
|
+
response: {
|
|
593
|
+
action: success ? 'approve' : 'reject',
|
|
594
|
+
userId: approvals[approvals.length - 1]?.userId || '',
|
|
595
|
+
timestamp: new Date(),
|
|
596
|
+
data: {},
|
|
597
|
+
approvals,
|
|
598
|
+
approvalCount,
|
|
599
|
+
rejectionCount,
|
|
600
|
+
},
|
|
601
|
+
taskId,
|
|
602
|
+
duration: Date.now() - startTime,
|
|
603
|
+
channel: channel.name,
|
|
604
|
+
metrics,
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
async executeConditionalApproval(task, taskId, startTime, metrics, channel, message) {
|
|
608
|
+
const approval = task.approval;
|
|
609
|
+
const conditions = approval.conditions || [];
|
|
610
|
+
const input = task.input;
|
|
611
|
+
// Find matching condition
|
|
612
|
+
const matchingCondition = conditions.find(c => c.when(input));
|
|
613
|
+
if (!matchingCondition) {
|
|
614
|
+
throw new Error('No matching approval condition found');
|
|
615
|
+
}
|
|
616
|
+
const users = matchingCondition.users;
|
|
617
|
+
const approvals = [];
|
|
618
|
+
if (matchingCondition.sequential) {
|
|
619
|
+
// Sequential approval for matching users
|
|
620
|
+
for (const user of users) {
|
|
621
|
+
const payload = this.buildNotificationPayload(task, message, channel.name);
|
|
622
|
+
payload.mentions = [user];
|
|
623
|
+
await channel.send(payload);
|
|
624
|
+
metrics.notificationsSent = (metrics.notificationsSent || 0) + 1;
|
|
625
|
+
const response = await channel.waitForResponse({ timeout: task.timeout });
|
|
626
|
+
approvals.push({
|
|
627
|
+
userId: response.userId,
|
|
628
|
+
action: response.action,
|
|
629
|
+
timestamp: response.timestamp,
|
|
630
|
+
});
|
|
631
|
+
if (response.action === 'reject') {
|
|
632
|
+
return {
|
|
633
|
+
success: true,
|
|
634
|
+
response: {
|
|
635
|
+
...response,
|
|
636
|
+
action: 'reject',
|
|
637
|
+
approvals,
|
|
638
|
+
},
|
|
639
|
+
taskId,
|
|
640
|
+
duration: Date.now() - startTime,
|
|
641
|
+
channel: channel.name,
|
|
642
|
+
metrics,
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
else {
|
|
648
|
+
// Single approval from any matching user
|
|
649
|
+
const payload = this.buildNotificationPayload(task, message, channel.name);
|
|
650
|
+
payload.mentions = users;
|
|
651
|
+
await channel.send(payload);
|
|
652
|
+
metrics.notificationsSent = (metrics.notificationsSent || 0) + 1;
|
|
653
|
+
const response = await channel.waitForResponse({ timeout: task.timeout });
|
|
654
|
+
approvals.push({
|
|
655
|
+
userId: response.userId,
|
|
656
|
+
action: response.action,
|
|
657
|
+
timestamp: response.timestamp,
|
|
658
|
+
});
|
|
659
|
+
return {
|
|
660
|
+
success: true,
|
|
661
|
+
response: {
|
|
662
|
+
...response,
|
|
663
|
+
approvals,
|
|
664
|
+
},
|
|
665
|
+
taskId,
|
|
666
|
+
duration: Date.now() - startTime,
|
|
667
|
+
channel: channel.name,
|
|
668
|
+
metrics,
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
return {
|
|
672
|
+
success: true,
|
|
673
|
+
response: {
|
|
674
|
+
action: 'approve',
|
|
675
|
+
userId: approvals[approvals.length - 1]?.userId || '',
|
|
676
|
+
timestamp: new Date(),
|
|
677
|
+
data: {},
|
|
678
|
+
approvals,
|
|
679
|
+
},
|
|
680
|
+
taskId,
|
|
681
|
+
duration: Date.now() - startTime,
|
|
682
|
+
channel: channel.name,
|
|
683
|
+
metrics,
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
buildNotificationPayload(task, message, channelName) {
|
|
687
|
+
const channelOptions = task.channelOptions || {};
|
|
688
|
+
const specificOptions = channelOptions[channelName] || channelOptions;
|
|
689
|
+
const payload = {
|
|
690
|
+
message,
|
|
691
|
+
channel: channelName,
|
|
692
|
+
};
|
|
693
|
+
// Add actions
|
|
694
|
+
if (task.actions) {
|
|
695
|
+
payload.actions = task.actions.map(action => {
|
|
696
|
+
if (typeof action === 'string') {
|
|
697
|
+
return { text: action, value: action };
|
|
698
|
+
}
|
|
699
|
+
return { text: action.label, value: action.value, style: action.style };
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
// Add form
|
|
703
|
+
if (task.form) {
|
|
704
|
+
payload.form = task.form;
|
|
705
|
+
}
|
|
706
|
+
// Add channel-specific options
|
|
707
|
+
if (channelName === 'slack' || specificOptions.slackChannel) {
|
|
708
|
+
if (specificOptions.slackChannel) {
|
|
709
|
+
payload.channel = specificOptions.slackChannel;
|
|
710
|
+
}
|
|
711
|
+
if (specificOptions.mentionUsers) {
|
|
712
|
+
payload.mentions = specificOptions.mentionUsers;
|
|
713
|
+
}
|
|
714
|
+
if (specificOptions.channel) {
|
|
715
|
+
payload.channel = specificOptions.channel;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
if (channelName === 'email') {
|
|
719
|
+
if (specificOptions.to) {
|
|
720
|
+
payload.to = specificOptions.to;
|
|
721
|
+
}
|
|
722
|
+
if (specificOptions.subject) {
|
|
723
|
+
payload.subject = specificOptions.subject;
|
|
724
|
+
}
|
|
725
|
+
if (specificOptions.contentType) {
|
|
726
|
+
payload.contentType = specificOptions.contentType;
|
|
727
|
+
}
|
|
728
|
+
if (specificOptions.actionLinkBaseUrl && task.actions) {
|
|
729
|
+
payload.actions = payload.actions?.map(action => ({
|
|
730
|
+
...action,
|
|
731
|
+
url: `${specificOptions.actionLinkBaseUrl}/${action.value}`,
|
|
732
|
+
}));
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
if (channelName === 'in-app') {
|
|
736
|
+
if (specificOptions.userId) {
|
|
737
|
+
payload.userId = specificOptions.userId;
|
|
738
|
+
}
|
|
739
|
+
if (specificOptions.priority) {
|
|
740
|
+
payload.priority = specificOptions.priority;
|
|
741
|
+
}
|
|
742
|
+
if (specificOptions.pushNotification !== undefined) {
|
|
743
|
+
payload.pushNotification = specificOptions.pushNotification;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
return payload;
|
|
747
|
+
}
|
|
748
|
+
async validateForm(form, data, applyDefaults) {
|
|
749
|
+
const errors = [];
|
|
750
|
+
const errorFields = [];
|
|
751
|
+
const processedData = { ...data };
|
|
752
|
+
for (const field of form.fields) {
|
|
753
|
+
let value = data[field.name];
|
|
754
|
+
// Apply defaults if configured
|
|
755
|
+
if (applyDefaults && value === undefined && field.default !== undefined) {
|
|
756
|
+
processedData[field.name] = field.default;
|
|
757
|
+
value = field.default;
|
|
758
|
+
}
|
|
759
|
+
// Required field validation
|
|
760
|
+
if (field.required) {
|
|
761
|
+
if (value === undefined || value === null || value === '') {
|
|
762
|
+
errors.push(`required field ${field.name} is missing or empty`);
|
|
763
|
+
errorFields.push(field.name);
|
|
764
|
+
continue;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
// Skip type validation if no value
|
|
768
|
+
if (value === undefined || value === null) {
|
|
769
|
+
continue;
|
|
770
|
+
}
|
|
771
|
+
// Type validation
|
|
772
|
+
switch (field.type) {
|
|
773
|
+
case 'number':
|
|
774
|
+
if (typeof value !== 'number' || isNaN(value)) {
|
|
775
|
+
errors.push(`Field '${field.name}' must be a number but got type ${typeof value}`);
|
|
776
|
+
errorFields.push(field.name);
|
|
777
|
+
}
|
|
778
|
+
break;
|
|
779
|
+
case 'boolean':
|
|
780
|
+
if (typeof value !== 'boolean') {
|
|
781
|
+
errors.push(`Field '${field.name}' must be a boolean but got type ${typeof value}`);
|
|
782
|
+
errorFields.push(field.name);
|
|
783
|
+
}
|
|
784
|
+
break;
|
|
785
|
+
case 'select':
|
|
786
|
+
if (field.options && !field.options.includes(value)) {
|
|
787
|
+
errors.push(`Field '${field.name}' has invalid option '${value}'. Must be one of: ${field.options.join(', ')}`);
|
|
788
|
+
errorFields.push(field.name);
|
|
789
|
+
}
|
|
790
|
+
break;
|
|
791
|
+
case 'multiselect':
|
|
792
|
+
if (!Array.isArray(value)) {
|
|
793
|
+
errors.push(`Field '${field.name}' must be an array`);
|
|
794
|
+
errorFields.push(field.name);
|
|
795
|
+
}
|
|
796
|
+
else if (field.options) {
|
|
797
|
+
const invalidOptions = value.filter(v => !field.options.includes(v));
|
|
798
|
+
if (invalidOptions.length > 0) {
|
|
799
|
+
errors.push(`Field '${field.name}' has invalid options: ${invalidOptions.join(', ')}`);
|
|
800
|
+
errorFields.push(field.name);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
break;
|
|
804
|
+
}
|
|
805
|
+
// Custom validation
|
|
806
|
+
if (field.validation && !errorFields.includes(field.name)) {
|
|
807
|
+
const result = await field.validation(value);
|
|
808
|
+
if (result !== true) {
|
|
809
|
+
const message = typeof result === 'string' ? result : `Field '${field.name}' failed validation`;
|
|
810
|
+
errors.push(message);
|
|
811
|
+
errorFields.push(field.name);
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
if (errors.length > 0) {
|
|
816
|
+
return {
|
|
817
|
+
valid: false,
|
|
818
|
+
error: new HumanValidationError(errors.join('; '), errorFields),
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
return { valid: true, data: processedData };
|
|
822
|
+
}
|
|
823
|
+
validateSchema(schema, data) {
|
|
824
|
+
const properties = schema.properties;
|
|
825
|
+
const required = schema.required;
|
|
826
|
+
if (!properties) {
|
|
827
|
+
return { valid: true };
|
|
828
|
+
}
|
|
829
|
+
// Check required fields
|
|
830
|
+
if (required) {
|
|
831
|
+
for (const field of required) {
|
|
832
|
+
if (data[field] === undefined) {
|
|
833
|
+
return { valid: false, error: `Required field '${field}' is missing` };
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
// Validate types
|
|
838
|
+
for (const [field, fieldSchema] of Object.entries(properties)) {
|
|
839
|
+
const value = data[field];
|
|
840
|
+
if (value === undefined)
|
|
841
|
+
continue;
|
|
842
|
+
const expectedType = fieldSchema.type;
|
|
843
|
+
const actualType = typeof value;
|
|
844
|
+
if (expectedType && actualType !== expectedType) {
|
|
845
|
+
return { valid: false, error: `Field '${field}' should be ${expectedType} but got ${actualType}` };
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
return { valid: true };
|
|
849
|
+
}
|
|
850
|
+
buildContext(taskId, task) {
|
|
851
|
+
const channelName = Array.isArray(task.channel) ? task.channel[0] : task.channel;
|
|
852
|
+
const channel = this.channels[channelName];
|
|
853
|
+
return {
|
|
854
|
+
taskId,
|
|
855
|
+
invocationId: `inv-${Date.now()}`,
|
|
856
|
+
task,
|
|
857
|
+
channel,
|
|
858
|
+
state: {
|
|
859
|
+
get: async (key) => (await this.state.storage.get(key)),
|
|
860
|
+
set: async (key, value) => {
|
|
861
|
+
await this.state.storage.put(key, value);
|
|
862
|
+
},
|
|
863
|
+
delete: async (key) => this.state.storage.delete(key),
|
|
864
|
+
},
|
|
865
|
+
log: {
|
|
866
|
+
debug: (message, _data) => console.debug(`[${taskId}] ${message}`),
|
|
867
|
+
info: (message, _data) => console.info(`[${taskId}] ${message}`),
|
|
868
|
+
warn: (message, _data) => console.warn(`[${taskId}] ${message}`),
|
|
869
|
+
error: (message, _data) => console.error(`[${taskId}] ${message}`),
|
|
870
|
+
},
|
|
871
|
+
emit: async (event, data) => {
|
|
872
|
+
await this.emit(event, data);
|
|
873
|
+
},
|
|
874
|
+
signal: task.signal || new AbortController().signal,
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
async emit(event, data) {
|
|
878
|
+
if (this.onEvent) {
|
|
879
|
+
await this.onEvent(event, data);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
export default HumanFunctionExecutor;
|
|
884
|
+
//# sourceMappingURL=HumanFunctionExecutor.js.map
|