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,852 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template Literal API for AI Functions
|
|
3
|
+
*
|
|
4
|
+
* Provides tagged template literal functions for convenient AI operations:
|
|
5
|
+
* - ai`prompt` - general AI completion
|
|
6
|
+
* - write`text` - text generation with structured output
|
|
7
|
+
* - summarize`text` - summarization
|
|
8
|
+
* - list`items` - list generation
|
|
9
|
+
* - extract`data` - data extraction
|
|
10
|
+
*
|
|
11
|
+
* All functions integrate with the AI Gateway and return typed PipelinePromises.
|
|
12
|
+
*/
|
|
13
|
+
import { AIGatewayClient } from '../lib/ai/gateway';
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// PipelinePromise Implementation
|
|
16
|
+
// ============================================================================
|
|
17
|
+
/**
|
|
18
|
+
* Creates a PipelinePromise from a regular Promise
|
|
19
|
+
*/
|
|
20
|
+
function createPipelinePromise(promise) {
|
|
21
|
+
const pipelinePromise = promise;
|
|
22
|
+
// Add get method for property access
|
|
23
|
+
pipelinePromise.get = (key) => {
|
|
24
|
+
return createPipelinePromise(promise.then((value) => value[key]));
|
|
25
|
+
};
|
|
26
|
+
// Add map method for transformation
|
|
27
|
+
pipelinePromise.map = (fn) => {
|
|
28
|
+
return createPipelinePromise(promise.then(fn));
|
|
29
|
+
};
|
|
30
|
+
// Override catch to return PipelinePromise
|
|
31
|
+
const originalCatch = pipelinePromise.catch.bind(pipelinePromise);
|
|
32
|
+
pipelinePromise.catch = (fn) => {
|
|
33
|
+
return createPipelinePromise(originalCatch(fn));
|
|
34
|
+
};
|
|
35
|
+
return pipelinePromise;
|
|
36
|
+
}
|
|
37
|
+
// ============================================================================
|
|
38
|
+
// Global Configuration
|
|
39
|
+
// ============================================================================
|
|
40
|
+
let globalConfig = {
|
|
41
|
+
provider: 'anthropic',
|
|
42
|
+
model: 'claude-sonnet-4-20250514',
|
|
43
|
+
temperature: 0.7,
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Configure default settings for template literal functions
|
|
47
|
+
*/
|
|
48
|
+
export function configure(config) {
|
|
49
|
+
globalConfig = { ...globalConfig, ...config };
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get current configuration
|
|
53
|
+
*/
|
|
54
|
+
export function getConfig() {
|
|
55
|
+
return { ...globalConfig };
|
|
56
|
+
}
|
|
57
|
+
// ============================================================================
|
|
58
|
+
// Helper Functions
|
|
59
|
+
// ============================================================================
|
|
60
|
+
/**
|
|
61
|
+
* Interpolate template literal strings and values
|
|
62
|
+
*/
|
|
63
|
+
function interpolate(strings, values) {
|
|
64
|
+
return strings.reduce((result, str, i) => {
|
|
65
|
+
const value = i < values.length ? String(values[i] ?? '') : '';
|
|
66
|
+
return result + str + value;
|
|
67
|
+
}, '');
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Create AI client from configuration
|
|
71
|
+
*/
|
|
72
|
+
function createClient(config) {
|
|
73
|
+
const aiConfig = {
|
|
74
|
+
provider: config.provider ?? globalConfig.provider ?? 'anthropic',
|
|
75
|
+
model: config.model ?? globalConfig.model ?? 'claude-sonnet-4-20250514',
|
|
76
|
+
gateway: config.gateway ?? globalConfig.gateway,
|
|
77
|
+
temperature: config.temperature ?? globalConfig.temperature,
|
|
78
|
+
maxTokens: config.maxTokens ?? globalConfig.maxTokens,
|
|
79
|
+
};
|
|
80
|
+
const env = config.env ?? globalConfig.env ?? {};
|
|
81
|
+
return new AIGatewayClient(aiConfig, env);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Execute AI chat and return response
|
|
85
|
+
*/
|
|
86
|
+
async function executeChat(prompt, options = {}) {
|
|
87
|
+
const client = createClient(options);
|
|
88
|
+
const messages = [];
|
|
89
|
+
if (options.systemPrompt) {
|
|
90
|
+
messages.push({ role: 'system', content: options.systemPrompt });
|
|
91
|
+
}
|
|
92
|
+
messages.push({ role: 'user', content: prompt });
|
|
93
|
+
const response = await client.chat(messages);
|
|
94
|
+
return response.content;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Parse JSON from AI response, handling code blocks
|
|
98
|
+
*/
|
|
99
|
+
function parseJSON(text) {
|
|
100
|
+
// Try direct parse
|
|
101
|
+
try {
|
|
102
|
+
return JSON.parse(text);
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
// Continue
|
|
106
|
+
}
|
|
107
|
+
// Try extracting from markdown code blocks
|
|
108
|
+
const codeBlockMatch = text.match(/```(?:json)?\s*([\s\S]*?)```/);
|
|
109
|
+
if (codeBlockMatch) {
|
|
110
|
+
try {
|
|
111
|
+
return JSON.parse(codeBlockMatch[1].trim());
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
// Continue
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// Try extracting JSON object/array from text
|
|
118
|
+
const jsonMatch = text.match(/(\{[\s\S]*\}|\[[\s\S]*\])/);
|
|
119
|
+
if (jsonMatch) {
|
|
120
|
+
try {
|
|
121
|
+
return JSON.parse(jsonMatch[1]);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
// Continue
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
throw new Error('Failed to parse JSON from AI response');
|
|
128
|
+
}
|
|
129
|
+
// ============================================================================
|
|
130
|
+
// Template Literal Functions
|
|
131
|
+
// ============================================================================
|
|
132
|
+
/**
|
|
133
|
+
* ai`prompt` - General AI completion
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* const response = await ai`What is the capital of France?`
|
|
137
|
+
* // => "The capital of France is Paris."
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* const response = await ai`Explain ${topic} in simple terms`
|
|
141
|
+
* // => "..." (explanation of the topic)
|
|
142
|
+
*/
|
|
143
|
+
export function ai(strings, ...values) {
|
|
144
|
+
const prompt = interpolate(strings, values);
|
|
145
|
+
return createPipelinePromise(executeChat(prompt));
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Create a configured ai function with custom options
|
|
149
|
+
*/
|
|
150
|
+
ai.configure = (options) => {
|
|
151
|
+
return (strings, ...values) => {
|
|
152
|
+
const prompt = interpolate(strings, values);
|
|
153
|
+
return createPipelinePromise(executeChat(prompt, options));
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* write`prompt` - Text generation with structured output
|
|
158
|
+
*
|
|
159
|
+
* Returns an object with destructurable properties like title, body, summary.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* const { title, body } = await write`Write a blog post about ${topic}`
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* const result = await write`Create an email about ${subject}`
|
|
166
|
+
* console.log(result.title) // Email subject
|
|
167
|
+
* console.log(result.body) // Email body
|
|
168
|
+
*/
|
|
169
|
+
export function write(strings, ...values) {
|
|
170
|
+
const prompt = interpolate(strings, values);
|
|
171
|
+
const systemPrompt = `You are a writing assistant. Generate structured content with clear sections.
|
|
172
|
+
Always respond with a JSON object containing relevant fields like:
|
|
173
|
+
- title: A concise title or headline
|
|
174
|
+
- body: The main content
|
|
175
|
+
- summary: A brief summary (if applicable)
|
|
176
|
+
- content: Alternative field for the main content
|
|
177
|
+
|
|
178
|
+
Respond ONLY with valid JSON, no additional text.`;
|
|
179
|
+
const executePromise = async () => {
|
|
180
|
+
const response = await executeChat(prompt, { systemPrompt });
|
|
181
|
+
return parseJSON(response);
|
|
182
|
+
};
|
|
183
|
+
return createPipelinePromise(executePromise());
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Create a configured write function with custom options
|
|
187
|
+
*/
|
|
188
|
+
write.configure = (options) => {
|
|
189
|
+
return (strings, ...values) => {
|
|
190
|
+
const prompt = interpolate(strings, values);
|
|
191
|
+
const systemPrompt = options.systemPrompt ?? `You are a writing assistant. Generate structured content with clear sections.
|
|
192
|
+
Always respond with a JSON object containing relevant fields like:
|
|
193
|
+
- title: A concise title or headline
|
|
194
|
+
- body: The main content
|
|
195
|
+
- summary: A brief summary (if applicable)
|
|
196
|
+
- content: Alternative field for the main content
|
|
197
|
+
|
|
198
|
+
Respond ONLY with valid JSON, no additional text.`;
|
|
199
|
+
const executePromise = async () => {
|
|
200
|
+
const response = await executeChat(prompt, { ...options, systemPrompt });
|
|
201
|
+
return parseJSON(response);
|
|
202
|
+
};
|
|
203
|
+
return createPipelinePromise(executePromise());
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* summarize`text` - Summarization
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* const summary = await summarize`${longArticle}`
|
|
211
|
+
* // => "This article discusses..."
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* const summary = await summarize`Summarize the key points: ${document}`
|
|
215
|
+
*/
|
|
216
|
+
export function summarize(strings, ...values) {
|
|
217
|
+
const text = interpolate(strings, values);
|
|
218
|
+
const systemPrompt = `You are a summarization assistant. Provide concise, accurate summaries.
|
|
219
|
+
Focus on the key points and main ideas. Keep summaries clear and informative.
|
|
220
|
+
Respond with only the summary text, no additional formatting or preamble.`;
|
|
221
|
+
const prompt = `Summarize the following:\n\n${text}`;
|
|
222
|
+
return createPipelinePromise(executeChat(prompt, { systemPrompt }));
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Create a configured summarize function with custom options
|
|
226
|
+
*/
|
|
227
|
+
summarize.configure = (options) => {
|
|
228
|
+
return (strings, ...values) => {
|
|
229
|
+
const text = interpolate(strings, values);
|
|
230
|
+
const lengthInstruction = options.length === 'short'
|
|
231
|
+
? 'Keep the summary to 1-2 sentences.'
|
|
232
|
+
: options.length === 'long'
|
|
233
|
+
? 'Provide a detailed summary covering all key points.'
|
|
234
|
+
: 'Provide a moderate-length summary.';
|
|
235
|
+
const systemPrompt = options.systemPrompt ?? `You are a summarization assistant. Provide concise, accurate summaries.
|
|
236
|
+
Focus on the key points and main ideas. ${lengthInstruction}
|
|
237
|
+
Respond with only the summary text, no additional formatting or preamble.`;
|
|
238
|
+
const prompt = `Summarize the following:\n\n${text}`;
|
|
239
|
+
return createPipelinePromise(executeChat(prompt, { ...options, systemPrompt }));
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
/**
|
|
243
|
+
* list`prompt` - List generation
|
|
244
|
+
*
|
|
245
|
+
* Returns an array of strings extracted from the AI response.
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* const items = await list`List 5 programming languages for web development`
|
|
249
|
+
* // => ["JavaScript", "TypeScript", "Python", "Ruby", "Go"]
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* const steps = await list`Steps to ${task}`
|
|
253
|
+
*/
|
|
254
|
+
export function list(strings, ...values) {
|
|
255
|
+
const prompt = interpolate(strings, values);
|
|
256
|
+
const systemPrompt = `You are a list generation assistant. Generate lists as JSON arrays.
|
|
257
|
+
Always respond with a JSON array of strings, no additional text.
|
|
258
|
+
Example: ["item 1", "item 2", "item 3"]`;
|
|
259
|
+
const executePromise = async () => {
|
|
260
|
+
const response = await executeChat(prompt, { systemPrompt });
|
|
261
|
+
return parseJSON(response);
|
|
262
|
+
};
|
|
263
|
+
return createPipelinePromise(executePromise());
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Create a configured list function with custom options
|
|
267
|
+
*/
|
|
268
|
+
list.configure = (options) => {
|
|
269
|
+
return (strings, ...values) => {
|
|
270
|
+
const prompt = interpolate(strings, values);
|
|
271
|
+
const countInstruction = options.count
|
|
272
|
+
? `Generate exactly ${options.count} items.`
|
|
273
|
+
: '';
|
|
274
|
+
const systemPrompt = options.systemPrompt ?? `You are a list generation assistant. Generate lists as JSON arrays.
|
|
275
|
+
${countInstruction}
|
|
276
|
+
Always respond with a JSON array of strings, no additional text.
|
|
277
|
+
Example: ["item 1", "item 2", "item 3"]`;
|
|
278
|
+
const executePromise = async () => {
|
|
279
|
+
const response = await executeChat(prompt, { ...options, systemPrompt });
|
|
280
|
+
return parseJSON(response);
|
|
281
|
+
};
|
|
282
|
+
return createPipelinePromise(executePromise());
|
|
283
|
+
};
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* extract`data` - Data extraction
|
|
287
|
+
*
|
|
288
|
+
* Extracts structured entities from text.
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* const { entities } = await extract`Extract all company names from: ${article}`
|
|
292
|
+
* // => { entities: ["Apple", "Google", "Microsoft"], raw: "..." }
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* const data = await extract`Extract dates and locations from: ${text}`
|
|
296
|
+
*/
|
|
297
|
+
export function extract(strings, ...values) {
|
|
298
|
+
const prompt = interpolate(strings, values);
|
|
299
|
+
const systemPrompt = `You are a data extraction assistant. Extract structured data from text.
|
|
300
|
+
Respond with a JSON object containing:
|
|
301
|
+
- entities: An array of extracted items (each can be an object with relevant properties)
|
|
302
|
+
- raw: The original text that was analyzed
|
|
303
|
+
|
|
304
|
+
Example response:
|
|
305
|
+
{
|
|
306
|
+
"entities": [{"name": "John", "type": "person"}, {"name": "Acme Corp", "type": "company"}],
|
|
307
|
+
"raw": "original text here"
|
|
308
|
+
}`;
|
|
309
|
+
const executePromise = async () => {
|
|
310
|
+
const response = await executeChat(prompt, { systemPrompt });
|
|
311
|
+
return parseJSON(response);
|
|
312
|
+
};
|
|
313
|
+
return createPipelinePromise(executePromise());
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Create a configured extract function with custom options and schema
|
|
317
|
+
*/
|
|
318
|
+
extract.configure = (options) => {
|
|
319
|
+
return (strings, ...values) => {
|
|
320
|
+
const prompt = interpolate(strings, values);
|
|
321
|
+
const entityInstruction = options.entityType
|
|
322
|
+
? `Focus on extracting ${options.entityType} entities.`
|
|
323
|
+
: '';
|
|
324
|
+
const schemaInstruction = options.schema
|
|
325
|
+
? `Each entity should match this structure: ${JSON.stringify(options.schema)}`
|
|
326
|
+
: '';
|
|
327
|
+
const systemPrompt = options.systemPrompt ?? `You are a data extraction assistant. Extract structured data from text.
|
|
328
|
+
${entityInstruction}
|
|
329
|
+
${schemaInstruction}
|
|
330
|
+
Respond with a JSON object containing:
|
|
331
|
+
- entities: An array of extracted items
|
|
332
|
+
- raw: The original text that was analyzed`;
|
|
333
|
+
const executePromise = async () => {
|
|
334
|
+
const response = await executeChat(prompt, { ...options, systemPrompt });
|
|
335
|
+
return parseJSON(response);
|
|
336
|
+
};
|
|
337
|
+
return createPipelinePromise(executePromise());
|
|
338
|
+
};
|
|
339
|
+
};
|
|
340
|
+
// ============================================================================
|
|
341
|
+
// Classification Functions
|
|
342
|
+
// ============================================================================
|
|
343
|
+
/**
|
|
344
|
+
* Parse boolean from AI response
|
|
345
|
+
* Handles various formats: true/false, yes/no, JSON objects, and natural language
|
|
346
|
+
*/
|
|
347
|
+
function parseBoolean(text) {
|
|
348
|
+
const normalized = text.toLowerCase().trim();
|
|
349
|
+
// Direct boolean values
|
|
350
|
+
if (normalized === 'true' || normalized === 'yes') {
|
|
351
|
+
return true;
|
|
352
|
+
}
|
|
353
|
+
if (normalized === 'false' || normalized === 'no') {
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
// Try to parse as JSON
|
|
357
|
+
try {
|
|
358
|
+
const parsed = JSON.parse(text);
|
|
359
|
+
if (typeof parsed === 'boolean') {
|
|
360
|
+
return parsed;
|
|
361
|
+
}
|
|
362
|
+
// Look for common result fields
|
|
363
|
+
if (typeof parsed === 'object' && parsed !== null) {
|
|
364
|
+
if ('result' in parsed && typeof parsed.result === 'boolean') {
|
|
365
|
+
return parsed.result;
|
|
366
|
+
}
|
|
367
|
+
if ('value' in parsed && typeof parsed.value === 'boolean') {
|
|
368
|
+
return parsed.value;
|
|
369
|
+
}
|
|
370
|
+
if ('answer' in parsed && typeof parsed.answer === 'boolean') {
|
|
371
|
+
return parsed.answer;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
catch {
|
|
376
|
+
// Not JSON, continue with text analysis
|
|
377
|
+
}
|
|
378
|
+
// Check for affirmative indicators at the start
|
|
379
|
+
if (normalized.startsWith('yes') || normalized.startsWith('true')) {
|
|
380
|
+
return true;
|
|
381
|
+
}
|
|
382
|
+
if (normalized.startsWith('no') || normalized.startsWith('false')) {
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
385
|
+
// Default to false for unclear responses
|
|
386
|
+
return false;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Find matching option in AI response
|
|
390
|
+
* Uses case-insensitive matching and returns first match found
|
|
391
|
+
*/
|
|
392
|
+
function findOption(response, options) {
|
|
393
|
+
const normalizedResponse = response.toLowerCase();
|
|
394
|
+
// Try to parse as JSON first
|
|
395
|
+
try {
|
|
396
|
+
const parsed = JSON.parse(response);
|
|
397
|
+
if (typeof parsed === 'object' && parsed !== null) {
|
|
398
|
+
// Look for common selection fields
|
|
399
|
+
const value = parsed.choice ?? parsed.selection ?? parsed.option ?? parsed.result ?? parsed.answer;
|
|
400
|
+
if (value !== undefined) {
|
|
401
|
+
const valueStr = String(value).toLowerCase();
|
|
402
|
+
for (const option of options) {
|
|
403
|
+
if (String(option).toLowerCase() === valueStr) {
|
|
404
|
+
return option;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
// Direct value
|
|
411
|
+
const valueStr = String(parsed).toLowerCase();
|
|
412
|
+
for (const option of options) {
|
|
413
|
+
if (String(option).toLowerCase() === valueStr) {
|
|
414
|
+
return option;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
catch {
|
|
420
|
+
// Not JSON, continue with text analysis
|
|
421
|
+
}
|
|
422
|
+
// Search for options in the response text (in order of definition)
|
|
423
|
+
for (const option of options) {
|
|
424
|
+
const optionStr = String(option).toLowerCase();
|
|
425
|
+
if (normalizedResponse.includes(optionStr)) {
|
|
426
|
+
return option;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
// Default to first option if no match found
|
|
430
|
+
return options[0];
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* is`prompt` - Binary classification
|
|
434
|
+
*
|
|
435
|
+
* Returns a boolean based on AI classification of the prompt.
|
|
436
|
+
*
|
|
437
|
+
* @example
|
|
438
|
+
* const isSpam = await is`Is this message spam? ${message}`
|
|
439
|
+
* // => true or false
|
|
440
|
+
*
|
|
441
|
+
* @example
|
|
442
|
+
* const isValid = await is`Is this email address valid? ${email}`
|
|
443
|
+
*/
|
|
444
|
+
export function is(strings, ...values) {
|
|
445
|
+
const prompt = interpolate(strings, values);
|
|
446
|
+
const systemPrompt = `You are a binary classifier. Analyze the question and respond with only "true" or "false".
|
|
447
|
+
Do not include any other text, explanation, or formatting.
|
|
448
|
+
If you are uncertain, respond with "false".`;
|
|
449
|
+
const executePromise = async () => {
|
|
450
|
+
const response = await executeChat(prompt, { systemPrompt });
|
|
451
|
+
return parseBoolean(response);
|
|
452
|
+
};
|
|
453
|
+
return createPipelinePromise(executePromise());
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Create a configured is function with custom options
|
|
457
|
+
*/
|
|
458
|
+
is.configure = (options) => {
|
|
459
|
+
return (strings, ...values) => {
|
|
460
|
+
const prompt = interpolate(strings, values);
|
|
461
|
+
const systemPrompt = options.systemPrompt ?? `You are a binary classifier. Analyze the question and respond with only "true" or "false".
|
|
462
|
+
Do not include any other text, explanation, or formatting.
|
|
463
|
+
If you are uncertain, respond with "false".`;
|
|
464
|
+
const executePromise = async () => {
|
|
465
|
+
const response = await executeChat(prompt, { ...options, systemPrompt });
|
|
466
|
+
return parseBoolean(response);
|
|
467
|
+
};
|
|
468
|
+
return createPipelinePromise(executePromise());
|
|
469
|
+
};
|
|
470
|
+
};
|
|
471
|
+
/**
|
|
472
|
+
* decide(options) - Multi-option classification
|
|
473
|
+
*
|
|
474
|
+
* Returns a curried function that classifies into one of the provided options.
|
|
475
|
+
*
|
|
476
|
+
* @example
|
|
477
|
+
* const sentiment = await decide(['positive', 'negative', 'neutral'])`What is the sentiment? ${text}`
|
|
478
|
+
* // => 'positive' | 'negative' | 'neutral'
|
|
479
|
+
*
|
|
480
|
+
* @example
|
|
481
|
+
* const category = await decide(['bug', 'feature', 'task'])`Classify: ${issueText}`
|
|
482
|
+
*/
|
|
483
|
+
export function decide(options) {
|
|
484
|
+
return (strings, ...values) => {
|
|
485
|
+
const prompt = interpolate(strings, values);
|
|
486
|
+
const optionsList = options.map((o) => `"${o}"`).join(', ');
|
|
487
|
+
const systemPrompt = `You are a classifier. Classify the input into exactly one of these options: ${optionsList}
|
|
488
|
+
Respond with only the selected option, no other text.
|
|
489
|
+
If uncertain, choose the option that best matches.`;
|
|
490
|
+
const executePromise = async () => {
|
|
491
|
+
const response = await executeChat(prompt, { systemPrompt });
|
|
492
|
+
return findOption(response, options);
|
|
493
|
+
};
|
|
494
|
+
return createPipelinePromise(executePromise());
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Create a configured decide function with custom options
|
|
499
|
+
*/
|
|
500
|
+
decide.configure = (options) => {
|
|
501
|
+
return (decideOptions) => {
|
|
502
|
+
return (strings, ...values) => {
|
|
503
|
+
const prompt = interpolate(strings, values);
|
|
504
|
+
const optionsList = decideOptions.map((o) => `"${o}"`).join(', ');
|
|
505
|
+
const systemPrompt = options.systemPrompt ?? `You are a classifier. Classify the input into exactly one of these options: ${optionsList}
|
|
506
|
+
Respond with only the selected option, no other text.
|
|
507
|
+
If uncertain, choose the option that best matches.`;
|
|
508
|
+
const executePromise = async () => {
|
|
509
|
+
const response = await executeChat(prompt, { ...options, systemPrompt });
|
|
510
|
+
return findOption(response, decideOptions);
|
|
511
|
+
};
|
|
512
|
+
return createPipelinePromise(executePromise());
|
|
513
|
+
};
|
|
514
|
+
};
|
|
515
|
+
};
|
|
516
|
+
// Default human task executor (mock for now, real impl uses HumanFunctionExecutor)
|
|
517
|
+
let humanTaskExecutor = null;
|
|
518
|
+
/**
|
|
519
|
+
* Set the human task executor (for integration with HumanFunctionExecutor)
|
|
520
|
+
*/
|
|
521
|
+
export function setHumanTaskExecutor(executor) {
|
|
522
|
+
humanTaskExecutor = executor;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Get the human task executor
|
|
526
|
+
*/
|
|
527
|
+
export function getHumanTaskExecutor() {
|
|
528
|
+
return humanTaskExecutor;
|
|
529
|
+
}
|
|
530
|
+
// ============================================================================
|
|
531
|
+
// Human-in-Loop Template Literal Functions
|
|
532
|
+
// ============================================================================
|
|
533
|
+
/**
|
|
534
|
+
* ask`prompt` - Prompts human for free-form input
|
|
535
|
+
*
|
|
536
|
+
* Pauses workflow execution until a human responds with text input.
|
|
537
|
+
* Integrates with HumanFunctionExecutor for task queuing and notification.
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* const answer = await ask`What priority should this bug have? ${bugReport}`
|
|
541
|
+
* // => "High - this is blocking the release"
|
|
542
|
+
*
|
|
543
|
+
* @example
|
|
544
|
+
* const feedback = await ask`Any additional notes for ${customer.name}'s order?`
|
|
545
|
+
* // => "Rush order - ship overnight"
|
|
546
|
+
*/
|
|
547
|
+
export function ask(strings, ...values) {
|
|
548
|
+
const prompt = interpolate(strings, values);
|
|
549
|
+
const executePromise = async () => {
|
|
550
|
+
if (!humanTaskExecutor) {
|
|
551
|
+
// Fallback: Use AI to simulate human response for testing/development
|
|
552
|
+
const systemPrompt = `You are simulating a human response to a question.
|
|
553
|
+
Respond naturally as if you were a human being asked this question.
|
|
554
|
+
Keep your response concise and relevant.`;
|
|
555
|
+
return executeChat(prompt, { systemPrompt });
|
|
556
|
+
}
|
|
557
|
+
const result = await humanTaskExecutor.execute({
|
|
558
|
+
prompt,
|
|
559
|
+
channel: 'in-app',
|
|
560
|
+
timeout: 86400000, // 24 hours default
|
|
561
|
+
});
|
|
562
|
+
if (!result.success || !result.response) {
|
|
563
|
+
throw new Error(result.error?.message || 'No response received');
|
|
564
|
+
}
|
|
565
|
+
// Return the text response from the human
|
|
566
|
+
return result.response.data?.text ||
|
|
567
|
+
result.response.data?.answer ||
|
|
568
|
+
result.response.data?.response ||
|
|
569
|
+
String(result.response.data || '');
|
|
570
|
+
};
|
|
571
|
+
return createPipelinePromise(executePromise());
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Create a configured ask function with custom options
|
|
575
|
+
*/
|
|
576
|
+
ask.configure = (options) => {
|
|
577
|
+
return (strings, ...values) => {
|
|
578
|
+
const prompt = interpolate(strings, values);
|
|
579
|
+
const executePromise = async () => {
|
|
580
|
+
if (!humanTaskExecutor) {
|
|
581
|
+
// Fallback to AI simulation
|
|
582
|
+
const systemPrompt = `You are simulating a human response to a question.
|
|
583
|
+
Respond naturally as if you were a human being asked this question.
|
|
584
|
+
Keep your response concise and relevant.`;
|
|
585
|
+
return executeChat(prompt, { systemPrompt });
|
|
586
|
+
}
|
|
587
|
+
const result = await humanTaskExecutor.execute({
|
|
588
|
+
prompt,
|
|
589
|
+
channel: options.channel || 'in-app',
|
|
590
|
+
timeout: options.timeout || 86400000,
|
|
591
|
+
channelOptions: {
|
|
592
|
+
priority: options.priority,
|
|
593
|
+
mentionUsers: options.assignees,
|
|
594
|
+
},
|
|
595
|
+
});
|
|
596
|
+
if (!result.success || !result.response) {
|
|
597
|
+
throw new Error(result.error?.message || 'No response received');
|
|
598
|
+
}
|
|
599
|
+
return result.response.data?.text ||
|
|
600
|
+
result.response.data?.answer ||
|
|
601
|
+
result.response.data?.response ||
|
|
602
|
+
String(result.response.data || '');
|
|
603
|
+
};
|
|
604
|
+
return createPipelinePromise(executePromise());
|
|
605
|
+
};
|
|
606
|
+
};
|
|
607
|
+
/**
|
|
608
|
+
* approve`prompt` - Requests human approval (binary yes/no)
|
|
609
|
+
*
|
|
610
|
+
* Pauses workflow execution until a human approves or rejects.
|
|
611
|
+
* Returns true for approval, false for rejection.
|
|
612
|
+
*
|
|
613
|
+
* @example
|
|
614
|
+
* const approved = await approve`Approve expense $${amount} for ${description}?`
|
|
615
|
+
* if (!approved) throw new Error('Expense rejected')
|
|
616
|
+
*
|
|
617
|
+
* @example
|
|
618
|
+
* const canProceed = await approve`Deploy ${service} to production?`
|
|
619
|
+
*/
|
|
620
|
+
export function approve(strings, ...values) {
|
|
621
|
+
const prompt = interpolate(strings, values);
|
|
622
|
+
const executePromise = async () => {
|
|
623
|
+
if (!humanTaskExecutor) {
|
|
624
|
+
// Fallback: Use AI to simulate approval decision
|
|
625
|
+
const systemPrompt = `You are simulating a human approval decision.
|
|
626
|
+
Based on the request, respond with ONLY "true" or "false".
|
|
627
|
+
Consider if the request seems reasonable, appropriate, and within normal parameters.
|
|
628
|
+
Respond with a single word: true or false`;
|
|
629
|
+
const response = await executeChat(prompt, { systemPrompt });
|
|
630
|
+
const normalized = response.trim().toLowerCase();
|
|
631
|
+
return normalized === 'true' || normalized === 'yes' || normalized === 'approved';
|
|
632
|
+
}
|
|
633
|
+
const result = await humanTaskExecutor.execute({
|
|
634
|
+
prompt,
|
|
635
|
+
channel: 'in-app',
|
|
636
|
+
timeout: 86400000,
|
|
637
|
+
actions: [
|
|
638
|
+
{ text: 'Approve', value: 'approve', style: 'primary' },
|
|
639
|
+
{ text: 'Reject', value: 'reject', style: 'danger' },
|
|
640
|
+
],
|
|
641
|
+
});
|
|
642
|
+
if (!result.success || !result.response) {
|
|
643
|
+
throw new Error(result.error?.message || 'No response received');
|
|
644
|
+
}
|
|
645
|
+
return result.response.action === 'approve';
|
|
646
|
+
};
|
|
647
|
+
return createPipelinePromise(executePromise());
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Create a configured approve function with custom options
|
|
651
|
+
*/
|
|
652
|
+
approve.configure = (options) => {
|
|
653
|
+
return (strings, ...values) => {
|
|
654
|
+
const prompt = interpolate(strings, values);
|
|
655
|
+
const executePromise = async () => {
|
|
656
|
+
if (!humanTaskExecutor) {
|
|
657
|
+
// Fallback to AI simulation
|
|
658
|
+
const systemPrompt = `You are simulating a human approval decision.
|
|
659
|
+
Based on the request, respond with ONLY "true" or "false".
|
|
660
|
+
Consider if the request seems reasonable, appropriate, and within normal parameters.`;
|
|
661
|
+
const response = await executeChat(prompt, { systemPrompt });
|
|
662
|
+
const normalized = response.trim().toLowerCase();
|
|
663
|
+
return normalized === 'true' || normalized === 'yes' || normalized === 'approved';
|
|
664
|
+
}
|
|
665
|
+
// Build actions from options or use defaults
|
|
666
|
+
const actions = options.actions
|
|
667
|
+
? (typeof options.actions[0] === 'string'
|
|
668
|
+
? options.actions.map(a => ({ text: a, value: a.toLowerCase() }))
|
|
669
|
+
: options.actions.map(a => ({
|
|
670
|
+
text: a.label,
|
|
671
|
+
value: a.value,
|
|
672
|
+
style: a.style,
|
|
673
|
+
})))
|
|
674
|
+
: [
|
|
675
|
+
{ text: 'Approve', value: 'approve', style: 'primary' },
|
|
676
|
+
{ text: 'Reject', value: 'reject', style: 'danger' },
|
|
677
|
+
];
|
|
678
|
+
const result = await humanTaskExecutor.execute({
|
|
679
|
+
prompt,
|
|
680
|
+
channel: options.channel || 'in-app',
|
|
681
|
+
timeout: options.timeout || 86400000,
|
|
682
|
+
actions,
|
|
683
|
+
channelOptions: {
|
|
684
|
+
priority: options.priority,
|
|
685
|
+
mentionUsers: options.assignees,
|
|
686
|
+
},
|
|
687
|
+
});
|
|
688
|
+
if (!result.success || !result.response) {
|
|
689
|
+
throw new Error(result.error?.message || 'No response received');
|
|
690
|
+
}
|
|
691
|
+
return result.response.action === 'approve';
|
|
692
|
+
};
|
|
693
|
+
return createPipelinePromise(executePromise());
|
|
694
|
+
};
|
|
695
|
+
};
|
|
696
|
+
/**
|
|
697
|
+
* review`prompt` - Requests human review with feedback
|
|
698
|
+
*
|
|
699
|
+
* Pauses workflow execution until a human reviews content and provides feedback.
|
|
700
|
+
* Returns an object with approval status and detailed feedback.
|
|
701
|
+
*
|
|
702
|
+
* @example
|
|
703
|
+
* const { approved, feedback } = await review`Review PR #${prNumber}: ${diff}`
|
|
704
|
+
* if (!approved) {
|
|
705
|
+
* await requestChanges(feedback)
|
|
706
|
+
* }
|
|
707
|
+
*
|
|
708
|
+
* @example
|
|
709
|
+
* const result = await review`Evaluate the quality of ${document.title}`
|
|
710
|
+
* console.log(result.feedback) // Detailed review comments
|
|
711
|
+
*/
|
|
712
|
+
export function review(strings, ...values) {
|
|
713
|
+
const prompt = interpolate(strings, values);
|
|
714
|
+
const executePromise = async () => {
|
|
715
|
+
if (!humanTaskExecutor) {
|
|
716
|
+
// Fallback: Use AI to simulate review
|
|
717
|
+
const systemPrompt = `You are simulating a human reviewer.
|
|
718
|
+
Provide a JSON response with the following structure:
|
|
719
|
+
{
|
|
720
|
+
"approved": boolean,
|
|
721
|
+
"feedback": "detailed feedback text"
|
|
722
|
+
}
|
|
723
|
+
Be thorough in your review and provide actionable feedback.
|
|
724
|
+
Respond ONLY with valid JSON.`;
|
|
725
|
+
const response = await executeChat(prompt, { systemPrompt });
|
|
726
|
+
try {
|
|
727
|
+
return parseJSON(response);
|
|
728
|
+
}
|
|
729
|
+
catch {
|
|
730
|
+
// If JSON parsing fails, try to extract meaningful response
|
|
731
|
+
const isApproved = response.toLowerCase().includes('approve') &&
|
|
732
|
+
!response.toLowerCase().includes('not approve') &&
|
|
733
|
+
!response.toLowerCase().includes("don't approve");
|
|
734
|
+
return {
|
|
735
|
+
approved: isApproved,
|
|
736
|
+
feedback: response,
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
const result = await humanTaskExecutor.execute({
|
|
741
|
+
prompt,
|
|
742
|
+
channel: 'in-app',
|
|
743
|
+
timeout: 86400000,
|
|
744
|
+
actions: [
|
|
745
|
+
{ text: 'Approve', value: 'approve', style: 'primary' },
|
|
746
|
+
{ text: 'Request Changes', value: 'request_changes', style: 'danger' },
|
|
747
|
+
],
|
|
748
|
+
});
|
|
749
|
+
if (!result.success || !result.response) {
|
|
750
|
+
throw new Error(result.error?.message || 'No response received');
|
|
751
|
+
}
|
|
752
|
+
return {
|
|
753
|
+
approved: result.response.action === 'approve',
|
|
754
|
+
feedback: result.response.data?.feedback ||
|
|
755
|
+
result.response.data?.comment ||
|
|
756
|
+
result.response.data?.notes ||
|
|
757
|
+
'',
|
|
758
|
+
reviewer: result.response.userId,
|
|
759
|
+
timestamp: result.response.timestamp,
|
|
760
|
+
};
|
|
761
|
+
};
|
|
762
|
+
return createPipelinePromise(executePromise());
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Create a configured review function with custom options
|
|
766
|
+
*/
|
|
767
|
+
review.configure = (options) => {
|
|
768
|
+
return (strings, ...values) => {
|
|
769
|
+
const prompt = interpolate(strings, values);
|
|
770
|
+
const executePromise = async () => {
|
|
771
|
+
if (!humanTaskExecutor) {
|
|
772
|
+
// Fallback to AI simulation
|
|
773
|
+
const systemPrompt = `You are simulating a human reviewer.
|
|
774
|
+
Provide a JSON response with the following structure:
|
|
775
|
+
{
|
|
776
|
+
"approved": boolean,
|
|
777
|
+
"feedback": "detailed feedback text"
|
|
778
|
+
}
|
|
779
|
+
Be thorough in your review and provide actionable feedback.
|
|
780
|
+
Respond ONLY with valid JSON.`;
|
|
781
|
+
const response = await executeChat(prompt, { systemPrompt });
|
|
782
|
+
try {
|
|
783
|
+
return parseJSON(response);
|
|
784
|
+
}
|
|
785
|
+
catch {
|
|
786
|
+
const isApproved = response.toLowerCase().includes('approve') &&
|
|
787
|
+
!response.toLowerCase().includes('not approve');
|
|
788
|
+
return {
|
|
789
|
+
approved: isApproved,
|
|
790
|
+
feedback: response,
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
// Build actions from options or use defaults
|
|
795
|
+
const actions = options.actions
|
|
796
|
+
? (typeof options.actions[0] === 'string'
|
|
797
|
+
? options.actions.map(a => ({ text: a, value: a.toLowerCase().replace(/\s+/g, '_') }))
|
|
798
|
+
: options.actions.map(a => ({
|
|
799
|
+
text: a.label,
|
|
800
|
+
value: a.value,
|
|
801
|
+
style: a.style,
|
|
802
|
+
})))
|
|
803
|
+
: [
|
|
804
|
+
{ text: 'Approve', value: 'approve', style: 'primary' },
|
|
805
|
+
{ text: 'Request Changes', value: 'request_changes', style: 'danger' },
|
|
806
|
+
];
|
|
807
|
+
const result = await humanTaskExecutor.execute({
|
|
808
|
+
prompt,
|
|
809
|
+
channel: options.channel || 'in-app',
|
|
810
|
+
timeout: options.timeout || 86400000,
|
|
811
|
+
actions,
|
|
812
|
+
channelOptions: {
|
|
813
|
+
priority: options.priority,
|
|
814
|
+
mentionUsers: options.assignees,
|
|
815
|
+
},
|
|
816
|
+
});
|
|
817
|
+
if (!result.success || !result.response) {
|
|
818
|
+
throw new Error(result.error?.message || 'No response received');
|
|
819
|
+
}
|
|
820
|
+
return {
|
|
821
|
+
approved: result.response.action === 'approve',
|
|
822
|
+
feedback: result.response.data?.feedback ||
|
|
823
|
+
result.response.data?.comment ||
|
|
824
|
+
result.response.data?.notes ||
|
|
825
|
+
'',
|
|
826
|
+
reviewer: result.response.userId,
|
|
827
|
+
timestamp: result.response.timestamp,
|
|
828
|
+
};
|
|
829
|
+
};
|
|
830
|
+
return createPipelinePromise(executePromise());
|
|
831
|
+
};
|
|
832
|
+
};
|
|
833
|
+
// ============================================================================
|
|
834
|
+
// Exports
|
|
835
|
+
// ============================================================================
|
|
836
|
+
export default {
|
|
837
|
+
ai,
|
|
838
|
+
write,
|
|
839
|
+
summarize,
|
|
840
|
+
list,
|
|
841
|
+
extract,
|
|
842
|
+
is,
|
|
843
|
+
decide,
|
|
844
|
+
ask,
|
|
845
|
+
approve,
|
|
846
|
+
review,
|
|
847
|
+
configure,
|
|
848
|
+
getConfig,
|
|
849
|
+
setHumanTaskExecutor,
|
|
850
|
+
getHumanTaskExecutor,
|
|
851
|
+
};
|
|
852
|
+
//# sourceMappingURL=template-literals.js.map
|