@relayflows/sdk 2.0.9 → 2.0.11
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/dist/adapters/base.d.ts +46 -0
- package/dist/adapters/base.d.ts.map +1 -0
- package/dist/adapters/base.js +15 -0
- package/dist/adapters/base.js.map +1 -0
- package/dist/adapters/claude.d.ts +5 -0
- package/dist/adapters/claude.d.ts.map +1 -0
- package/dist/adapters/claude.js +44 -0
- package/dist/adapters/claude.js.map +1 -0
- package/dist/adapters/codex.d.ts +5 -0
- package/dist/adapters/codex.d.ts.map +1 -0
- package/dist/adapters/codex.js +45 -0
- package/dist/adapters/codex.js.map +1 -0
- package/dist/adapters/index.d.ts +14 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +29 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/wrapper.d.ts +12 -0
- package/dist/adapters/wrapper.d.ts.map +1 -0
- package/dist/adapters/wrapper.js +31 -0
- package/dist/adapters/wrapper.js.map +1 -0
- package/dist/agent-relay-receipt.d.ts +24 -0
- package/dist/agent-relay-receipt.d.ts.map +1 -0
- package/dist/agent-relay-receipt.js +66 -0
- package/dist/agent-relay-receipt.js.map +1 -0
- package/dist/agent-relay-state.d.ts +18 -0
- package/dist/agent-relay-state.d.ts.map +1 -0
- package/dist/agent-relay-state.js +58 -0
- package/dist/agent-relay-state.js.map +1 -0
- package/dist/agent-relay-transport.d.ts +31 -0
- package/dist/agent-relay-transport.d.ts.map +1 -0
- package/dist/agent-relay-transport.js +199 -0
- package/dist/agent-relay-transport.js.map +1 -0
- package/dist/authored-budget.d.ts +13 -0
- package/dist/authored-budget.d.ts.map +1 -0
- package/dist/authored-budget.js +78 -0
- package/dist/authored-budget.js.map +1 -0
- package/dist/authored-flow-error.d.ts +2 -21
- package/dist/authored-flow-error.d.ts.map +1 -1
- package/dist/authored-flow-error.js +1 -12
- package/dist/authored-flow-error.js.map +1 -1
- package/dist/authored-flow-executor.d.ts +13 -7
- package/dist/authored-flow-executor.d.ts.map +1 -1
- package/dist/authored-flow-executor.js +116 -235
- package/dist/authored-flow-executor.js.map +1 -1
- package/dist/authored-flow-loader.d.ts +10 -1
- package/dist/authored-flow-loader.d.ts.map +1 -1
- package/dist/authored-flow-loader.js +56 -3
- package/dist/authored-flow-loader.js.map +1 -1
- package/dist/authored-flow-operation.d.ts +9 -1
- package/dist/authored-flow-operation.d.ts.map +1 -1
- package/dist/authored-flow-operation.js +35 -4
- package/dist/authored-flow-operation.js.map +1 -1
- package/dist/authored-helper-effect.d.ts +12 -0
- package/dist/authored-helper-effect.d.ts.map +1 -0
- package/dist/authored-helper-effect.js +144 -0
- package/dist/authored-helper-effect.js.map +1 -0
- package/dist/authored-mcp.d.ts +17 -0
- package/dist/authored-mcp.d.ts.map +1 -0
- package/dist/authored-mcp.js +171 -0
- package/dist/authored-mcp.js.map +1 -0
- package/dist/authored-memory.d.ts +7 -0
- package/dist/authored-memory.d.ts.map +1 -0
- package/dist/authored-memory.js +60 -0
- package/dist/authored-memory.js.map +1 -0
- package/dist/authored-plugin-effect.d.ts +16 -0
- package/dist/authored-plugin-effect.d.ts.map +1 -0
- package/dist/authored-plugin-effect.js +163 -0
- package/dist/authored-plugin-effect.js.map +1 -0
- package/dist/authored-step-output.d.ts +23 -0
- package/dist/authored-step-output.d.ts.map +1 -0
- package/dist/authored-step-output.js +67 -0
- package/dist/authored-step-output.js.map +1 -0
- package/dist/authored-worker-step.d.ts +15 -0
- package/dist/authored-worker-step.d.ts.map +1 -0
- package/dist/authored-worker-step.js +136 -0
- package/dist/authored-worker-step.js.map +1 -0
- package/dist/budget-preflight.d.ts +5 -0
- package/dist/budget-preflight.d.ts.map +1 -0
- package/dist/budget-preflight.js +33 -0
- package/dist/budget-preflight.js.map +1 -0
- package/dist/budget.d.ts +14 -0
- package/dist/budget.d.ts.map +1 -0
- package/dist/budget.js +52 -0
- package/dist/budget.js.map +1 -0
- package/dist/bundle-transport.d.ts +18 -0
- package/dist/bundle-transport.d.ts.map +1 -0
- package/dist/bundle-transport.js +111 -0
- package/dist/bundle-transport.js.map +1 -0
- package/dist/bundle-typescript.d.ts +8 -0
- package/dist/bundle-typescript.d.ts.map +1 -0
- package/dist/bundle-typescript.js +108 -0
- package/dist/bundle-typescript.js.map +1 -0
- package/dist/bundle.d.ts +25 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +199 -0
- package/dist/bundle.js.map +1 -0
- package/dist/child-stop.d.ts +59 -0
- package/dist/child-stop.d.ts.map +1 -0
- package/dist/child-stop.js +94 -0
- package/dist/child-stop.js.map +1 -0
- package/dist/cli/add.d.ts +6 -0
- package/dist/cli/add.d.ts.map +1 -0
- package/dist/cli/add.js +47 -0
- package/dist/cli/add.js.map +1 -0
- package/dist/cli/build.d.ts +13 -0
- package/dist/cli/build.d.ts.map +1 -0
- package/dist/cli/build.js +224 -0
- package/dist/cli/build.js.map +1 -0
- package/dist/cli/bundle-preflight.d.ts +5 -0
- package/dist/cli/bundle-preflight.d.ts.map +1 -0
- package/dist/cli/bundle-preflight.js +28 -0
- package/dist/cli/bundle-preflight.js.map +1 -0
- package/dist/cli/check-helper-body.d.ts +4 -0
- package/dist/cli/check-helper-body.d.ts.map +1 -0
- package/dist/cli/check-helper-body.js +15 -0
- package/dist/cli/check-helper-body.js.map +1 -0
- package/dist/cli/check-triggers.d.ts +14 -0
- package/dist/cli/check-triggers.d.ts.map +1 -0
- package/dist/cli/check-triggers.js +37 -0
- package/dist/cli/check-triggers.js.map +1 -0
- package/dist/cli/check-typescript.d.ts +20 -0
- package/dist/cli/check-typescript.d.ts.map +1 -0
- package/dist/cli/check-typescript.js +54 -0
- package/dist/cli/check-typescript.js.map +1 -0
- package/dist/cli/check.d.ts +36 -3
- package/dist/cli/check.d.ts.map +1 -1
- package/dist/cli/check.js +122 -11
- package/dist/cli/check.js.map +1 -1
- package/dist/cli/cloud-run.d.ts +8 -0
- package/dist/cli/cloud-run.d.ts.map +1 -0
- package/dist/cli/cloud-run.js +50 -0
- package/dist/cli/cloud-run.js.map +1 -0
- package/dist/cli/deploy.d.ts +9 -0
- package/dist/cli/deploy.d.ts.map +1 -0
- package/dist/cli/deploy.js +58 -0
- package/dist/cli/deploy.js.map +1 -0
- package/dist/cli/deterministic-failure.d.ts +5 -0
- package/dist/cli/deterministic-failure.d.ts.map +1 -0
- package/dist/cli/deterministic-failure.js +66 -0
- package/dist/cli/deterministic-failure.js.map +1 -0
- package/dist/cli/direct-run.d.ts.map +1 -1
- package/dist/cli/direct-run.js +83 -18
- package/dist/cli/direct-run.js.map +1 -1
- package/dist/cli/hn-monitor.d.ts.map +1 -1
- package/dist/cli/hn-monitor.js +2 -1
- package/dist/cli/hn-monitor.js.map +1 -1
- package/dist/cli/replay.d.ts +12 -0
- package/dist/cli/replay.d.ts.map +1 -0
- package/dist/cli/replay.js +82 -0
- package/dist/cli/replay.js.map +1 -0
- package/dist/cli/reuse.d.ts +8 -0
- package/dist/cli/reuse.d.ts.map +1 -0
- package/dist/cli/reuse.js +25 -0
- package/dist/cli/reuse.js.map +1 -0
- package/dist/cli/run-digest.d.ts +4 -0
- package/dist/cli/run-digest.d.ts.map +1 -0
- package/dist/cli/run-digest.js +24 -0
- package/dist/cli/run-digest.js.map +1 -0
- package/dist/cli/run.d.ts +16 -5
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +99 -17
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/serve-webhook.d.ts +40 -0
- package/dist/cli/serve-webhook.d.ts.map +1 -0
- package/dist/cli/serve-webhook.js +233 -0
- package/dist/cli/serve-webhook.js.map +1 -0
- package/dist/cli/tick-runner.d.ts.map +1 -1
- package/dist/cli/tick-runner.js +2 -1
- package/dist/cli/tick-runner.js.map +1 -1
- package/dist/cli-adapter.d.ts +8 -14
- package/dist/cli-adapter.d.ts.map +1 -1
- package/dist/cli-adapter.js +19 -64
- package/dist/cli-adapter.js.map +1 -1
- package/dist/cli-watch.d.ts +13 -0
- package/dist/cli-watch.d.ts.map +1 -0
- package/dist/cli-watch.js +185 -0
- package/dist/cli-watch.js.map +1 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +387 -14
- package/dist/cli.js.map +1 -1
- package/dist/cloud-http.d.ts +22 -0
- package/dist/cloud-http.d.ts.map +1 -0
- package/dist/cloud-http.js +84 -0
- package/dist/cloud-http.js.map +1 -0
- package/dist/cloud-run.d.ts +38 -0
- package/dist/cloud-run.d.ts.map +1 -0
- package/dist/cloud-run.js +112 -0
- package/dist/cloud-run.js.map +1 -0
- package/dist/compile.d.ts +21 -3
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +97 -23
- package/dist/compile.js.map +1 -1
- package/dist/create-flow.d.ts +17 -0
- package/dist/create-flow.d.ts.map +1 -0
- package/dist/create-flow.js +72 -0
- package/dist/create-flow.js.map +1 -0
- package/dist/daemon-connection.d.ts +14 -0
- package/dist/daemon-connection.d.ts.map +1 -1
- package/dist/daemon-connection.js +33 -1
- package/dist/daemon-connection.js.map +1 -1
- package/dist/demo-hn-monitor.js +2 -1
- package/dist/demo-hn-monitor.js.map +1 -1
- package/dist/effect-channel.d.ts +30 -0
- package/dist/effect-channel.d.ts.map +1 -0
- package/dist/effect-channel.js +71 -0
- package/dist/effect-channel.js.map +1 -0
- package/dist/failure-kinds.d.ts +14 -3
- package/dist/failure-kinds.d.ts.map +1 -1
- package/dist/failure-kinds.js +27 -0
- package/dist/failure-kinds.js.map +1 -1
- package/dist/gate-contract.d.ts.map +1 -1
- package/dist/gate-contract.js +9 -0
- package/dist/gate-contract.js.map +1 -1
- package/dist/helper-preflight.d.ts +18 -0
- package/dist/helper-preflight.d.ts.map +1 -0
- package/dist/helper-preflight.js +32 -0
- package/dist/helper-preflight.js.map +1 -0
- package/dist/helper-storage.d.ts +5 -0
- package/dist/helper-storage.d.ts.map +1 -0
- package/dist/helper-storage.js +31 -0
- package/dist/helper-storage.js.map +1 -0
- package/dist/helper-writeback.d.ts +12 -0
- package/dist/helper-writeback.d.ts.map +1 -0
- package/dist/helper-writeback.js +95 -0
- package/dist/helper-writeback.js.map +1 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/input-binding.d.ts +4 -0
- package/dist/input-binding.d.ts.map +1 -0
- package/dist/input-binding.js +78 -0
- package/dist/input-binding.js.map +1 -0
- package/dist/journal-client.d.ts +12 -4
- package/dist/journal-client.d.ts.map +1 -1
- package/dist/journal-client.js +17 -6
- package/dist/journal-client.js.map +1 -1
- package/dist/journal-offset.d.ts +3 -0
- package/dist/journal-offset.d.ts.map +1 -0
- package/dist/journal-offset.js +69 -0
- package/dist/journal-offset.js.map +1 -0
- package/dist/journal-reader.d.ts +30 -0
- package/dist/journal-reader.d.ts.map +1 -0
- package/dist/journal-reader.js +156 -0
- package/dist/journal-reader.js.map +1 -0
- package/dist/json-schema.d.ts +2 -0
- package/dist/json-schema.d.ts.map +1 -1
- package/dist/json-schema.js +38 -22
- package/dist/json-schema.js.map +1 -1
- package/dist/llm-worker.d.ts +16 -0
- package/dist/llm-worker.d.ts.map +1 -0
- package/dist/llm-worker.js +79 -0
- package/dist/llm-worker.js.map +1 -0
- package/dist/local-agent.d.ts +8 -0
- package/dist/local-agent.d.ts.map +1 -0
- package/dist/local-agent.js +25 -0
- package/dist/local-agent.js.map +1 -0
- package/dist/mcp-client.d.ts +15 -0
- package/dist/mcp-client.d.ts.map +1 -0
- package/dist/mcp-client.js +104 -0
- package/dist/mcp-client.js.map +1 -0
- package/dist/mcp-config.d.ts +4 -0
- package/dist/mcp-config.d.ts.map +1 -0
- package/dist/mcp-config.js +61 -0
- package/dist/mcp-config.js.map +1 -0
- package/dist/mcp-stdio.d.ts +24 -0
- package/dist/mcp-stdio.d.ts.map +1 -0
- package/dist/mcp-stdio.js +89 -0
- package/dist/mcp-stdio.js.map +1 -0
- package/dist/model-pricing.d.ts +22 -0
- package/dist/model-pricing.d.ts.map +1 -0
- package/dist/model-pricing.js +30 -0
- package/dist/model-pricing.js.map +1 -0
- package/dist/mount-registry.d.ts +9 -0
- package/dist/mount-registry.d.ts.map +1 -0
- package/dist/mount-registry.js +47 -0
- package/dist/mount-registry.js.map +1 -0
- package/dist/named-gate-lowering.d.ts +9 -0
- package/dist/named-gate-lowering.d.ts.map +1 -0
- package/dist/named-gate-lowering.js +152 -0
- package/dist/named-gate-lowering.js.map +1 -0
- package/dist/named-gates.d.ts +10 -0
- package/dist/named-gates.d.ts.map +1 -0
- package/dist/named-gates.js +69 -0
- package/dist/named-gates.js.map +1 -0
- package/dist/observer-link.d.ts +129 -0
- package/dist/observer-link.d.ts.map +1 -0
- package/dist/observer-link.js +274 -0
- package/dist/observer-link.js.map +1 -0
- package/dist/plugin-loader.d.ts +13 -0
- package/dist/plugin-loader.d.ts.map +1 -0
- package/dist/plugin-loader.js +110 -0
- package/dist/plugin-loader.js.map +1 -0
- package/dist/plugin-manifest.d.ts +27 -0
- package/dist/plugin-manifest.d.ts.map +1 -0
- package/dist/plugin-manifest.js +89 -0
- package/dist/plugin-manifest.js.map +1 -0
- package/dist/preflight.d.ts +26 -2
- package/dist/preflight.d.ts.map +1 -1
- package/dist/preflight.js +175 -1
- package/dist/preflight.js.map +1 -1
- package/dist/progress.d.ts +14 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +39 -0
- package/dist/progress.js.map +1 -0
- package/dist/protocol.d.ts +11 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/pty-sidechannel.d.ts +14 -0
- package/dist/pty-sidechannel.d.ts.map +1 -0
- package/dist/pty-sidechannel.js +103 -0
- package/dist/pty-sidechannel.js.map +1 -0
- package/dist/scope-compiler.d.ts +52 -0
- package/dist/scope-compiler.d.ts.map +1 -0
- package/dist/scope-compiler.js +62 -0
- package/dist/scope-compiler.js.map +1 -0
- package/dist/slack-preflight.d.ts +6 -0
- package/dist/slack-preflight.d.ts.map +1 -0
- package/dist/slack-preflight.js +28 -0
- package/dist/slack-preflight.js.map +1 -0
- package/dist/slack-writeback.d.ts +40 -0
- package/dist/slack-writeback.d.ts.map +1 -0
- package/dist/slack-writeback.js +60 -0
- package/dist/slack-writeback.js.map +1 -0
- package/dist/spec.d.ts +134 -4
- package/dist/spec.d.ts.map +1 -1
- package/dist/spec.js.map +1 -1
- package/dist/step-dependencies.d.ts.map +1 -1
- package/dist/step-dependencies.js +2 -1
- package/dist/step-dependencies.js.map +1 -1
- package/dist/step-fields.d.ts +4 -4
- package/dist/step-fields.d.ts.map +1 -1
- package/dist/step-fields.js +5 -2
- package/dist/step-fields.js.map +1 -1
- package/dist/trigger-executor.d.ts +7 -0
- package/dist/trigger-executor.d.ts.map +1 -0
- package/dist/trigger-executor.js +35 -0
- package/dist/trigger-executor.js.map +1 -0
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +53 -6
- package/dist/validate.js.map +1 -1
- package/dist/webhook-rate-limit.d.ts +29 -0
- package/dist/webhook-rate-limit.d.ts.map +1 -0
- package/dist/webhook-rate-limit.js +38 -0
- package/dist/webhook-rate-limit.js.map +1 -0
- package/dist/webhook-signature.d.ts +22 -0
- package/dist/webhook-signature.d.ts.map +1 -0
- package/dist/webhook-signature.js +53 -0
- package/dist/webhook-signature.js.map +1 -0
- package/dist/worker-cli.d.ts +16 -1
- package/dist/worker-cli.d.ts.map +1 -1
- package/dist/worker-cli.js +129 -12
- package/dist/worker-cli.js.map +1 -1
- package/dist/worker-input.d.ts +4 -0
- package/dist/worker-input.d.ts.map +1 -0
- package/dist/worker-input.js +14 -0
- package/dist/worker-input.js.map +1 -0
- package/dist/worker-lease.d.ts +5 -0
- package/dist/worker-lease.d.ts.map +1 -0
- package/dist/worker-lease.js +80 -0
- package/dist/worker-lease.js.map +1 -0
- package/dist/worker-spend.d.ts +19 -0
- package/dist/worker-spend.d.ts.map +1 -0
- package/dist/worker-spend.js +22 -0
- package/dist/worker-spend.js.map +1 -0
- package/dist/worker-usage.d.ts +7 -0
- package/dist/worker-usage.d.ts.map +1 -0
- package/dist/worker-usage.js +54 -0
- package/dist/worker-usage.js.map +1 -0
- package/dist/worker.d.ts +2 -0
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +29 -9
- package/dist/worker.js.map +1 -1
- package/dist/wrapper-session.d.ts +1 -1
- package/dist/wrapper-session.d.ts.map +1 -1
- package/dist/wrapper-session.js +56 -19
- package/dist/wrapper-session.js.map +1 -1
- package/dist/yaml-helper-effect.d.ts +8 -0
- package/dist/yaml-helper-effect.d.ts.map +1 -0
- package/dist/yaml-helper-effect.js +79 -0
- package/dist/yaml-helper-effect.js.map +1 -0
- package/dist/yaml-helpers.d.ts +18 -0
- package/dist/yaml-helpers.d.ts.map +1 -0
- package/dist/yaml-helpers.js +116 -0
- package/dist/yaml-helpers.js.map +1 -0
- package/package.json +19 -2
- package/src/adapters/base.ts +53 -0
- package/src/adapters/claude.ts +55 -0
- package/src/adapters/codex.ts +56 -0
- package/src/adapters/index.ts +36 -0
- package/src/adapters/wrapper.ts +42 -0
- package/src/agent-relay-receipt.ts +120 -0
- package/src/agent-relay-state.ts +73 -0
- package/src/agent-relay-transport.ts +273 -0
- package/src/authored-budget.ts +69 -0
- package/src/authored-flow-error.ts +10 -10
- package/src/authored-flow-executor.ts +171 -347
- package/src/authored-flow-loader.ts +60 -3
- package/src/authored-flow-operation.ts +38 -5
- package/src/authored-helper-effect.ts +143 -0
- package/src/authored-mcp.ts +166 -0
- package/src/authored-memory.ts +55 -0
- package/src/authored-plugin-effect.ts +152 -0
- package/src/authored-step-output.ts +107 -0
- package/src/authored-worker-step.ts +181 -0
- package/src/budget-preflight.ts +31 -0
- package/src/budget.ts +49 -0
- package/src/bundle-transport.ts +79 -0
- package/src/bundle-typescript.ts +98 -0
- package/src/bundle.ts +182 -0
- package/src/child-stop.ts +138 -0
- package/src/cli/add.ts +45 -0
- package/src/cli/build.ts +214 -0
- package/src/cli/bundle-preflight.ts +28 -0
- package/src/cli/check-helper-body.ts +14 -0
- package/src/cli/check-triggers.ts +41 -0
- package/src/cli/check-typescript.ts +63 -0
- package/src/cli/check.ts +132 -14
- package/src/cli/cloud-run.ts +47 -0
- package/src/cli/deploy.ts +52 -0
- package/src/cli/deterministic-failure.ts +69 -0
- package/src/cli/direct-run.ts +79 -18
- package/src/cli/hn-monitor.ts +2 -1
- package/src/cli/replay.ts +81 -0
- package/src/cli/reuse.ts +23 -0
- package/src/cli/run-digest.ts +24 -0
- package/src/cli/run.ts +104 -21
- package/src/cli/serve-webhook.ts +246 -0
- package/src/cli/tick-runner.ts +2 -1
- package/src/cli-adapter.ts +31 -74
- package/src/cli-watch.ts +174 -0
- package/src/cli.ts +396 -17
- package/src/cloud-http.ts +100 -0
- package/src/cloud-run.ts +137 -0
- package/src/compile.ts +102 -23
- package/src/create-flow.ts +82 -0
- package/src/daemon-connection.ts +32 -1
- package/src/demo-hn-monitor.ts +2 -1
- package/src/effect-channel.ts +97 -0
- package/src/failure-kinds.ts +38 -0
- package/src/gate-contract.ts +7 -0
- package/src/helper-preflight.ts +34 -0
- package/src/helper-storage.ts +23 -0
- package/src/helper-writeback.ts +83 -0
- package/src/index.ts +26 -0
- package/src/input-binding.ts +76 -0
- package/src/journal-client.ts +20 -7
- package/src/journal-offset.ts +60 -0
- package/src/journal-reader.ts +165 -0
- package/src/json-schema.ts +34 -18
- package/src/llm-worker.ts +82 -0
- package/src/local-agent.ts +30 -0
- package/src/mcp-client.ts +97 -0
- package/src/mcp-config.ts +42 -0
- package/src/mcp-stdio.ts +84 -0
- package/src/model-pricing.ts +32 -0
- package/src/mount-registry.ts +44 -0
- package/src/named-gate-lowering.ts +147 -0
- package/src/named-gates.ts +76 -0
- package/src/observer-link.ts +368 -0
- package/src/plugin-loader.ts +88 -0
- package/src/plugin-manifest.ts +76 -0
- package/src/preflight.ts +178 -4
- package/src/progress.ts +51 -0
- package/src/protocol.ts +12 -0
- package/src/pty-sidechannel.ts +92 -0
- package/src/scope-compiler.ts +105 -0
- package/src/slack-preflight.ts +25 -0
- package/src/slack-writeback.ts +63 -0
- package/src/spec.ts +112 -4
- package/src/step-dependencies.ts +3 -1
- package/src/step-fields.ts +5 -2
- package/src/trigger-executor.ts +34 -0
- package/src/validate.ts +47 -6
- package/src/webhook-rate-limit.ts +69 -0
- package/src/webhook-signature.ts +74 -0
- package/src/worker-cli.ts +150 -11
- package/src/worker-input.ts +15 -0
- package/src/worker-lease.ts +85 -0
- package/src/worker-spend.ts +23 -0
- package/src/worker-usage.ts +48 -0
- package/src/worker.ts +34 -10
- package/src/wrapper-session.ts +50 -15
- package/src/yaml-helper-effect.ts +78 -0
- package/src/yaml-helpers.ts +131 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { compileSpec, toKernelSpec } from './compile.js';
|
|
3
|
+
import { invokePlugin, type LoadedPlugin } from './plugin-loader.js';
|
|
4
|
+
import type { PluginVerb } from './plugin-manifest.js';
|
|
5
|
+
import type { AuthoredBudget } from './authored-budget.js';
|
|
6
|
+
import { SPEC_SCHEMA_VERSION } from './spec.js';
|
|
7
|
+
import type { JournalClient } from './journal-client.js';
|
|
8
|
+
import type { StepDispatchEvent } from './protocol.js';
|
|
9
|
+
import { AuthoredFlowExecutionError } from './authored-flow-error.js';
|
|
10
|
+
import type { AuthoredFlowJournalStep } from './authored-flow-executor.js';
|
|
11
|
+
import { readCompletedStepOutput } from './authored-step-output.js';
|
|
12
|
+
import { withWorkerLease } from './worker-lease.js';
|
|
13
|
+
|
|
14
|
+
export class PluginStepError extends AuthoredFlowExecutionError {
|
|
15
|
+
constructor(readonly diagnostic: string, runId: string) {
|
|
16
|
+
super('step_failed', diagnostic, 'worker_error', runId);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Helpers lower to an existing agent effect, never a fourth kernel primitive.
|
|
21
|
+
* The Plugin receipt lives in step.completed.output: { type, input, output, ... }.
|
|
22
|
+
* A private stream routes the step to this short-lived SDK worker exclusively.
|
|
23
|
+
*/
|
|
24
|
+
export async function runPluginEffect(
|
|
25
|
+
journal: JournalClient, flowName: string, id: string, plugin: LoadedPlugin, verb: PluginVerb,
|
|
26
|
+
args: unknown, journalSteps: AuthoredFlowJournalStep[], budget: AuthoredBudget,
|
|
27
|
+
): Promise<unknown> {
|
|
28
|
+
const server = verb.namespace;
|
|
29
|
+
const tool = verb.method;
|
|
30
|
+
const idempotencyKey = `plugin:${server}:${tool}:${createHash('sha256').update(JSON.stringify(args)).digest('hex')}`;
|
|
31
|
+
const surfacePath = `/plugins/${pathPart(server)}/${pathPart(tool)}`;
|
|
32
|
+
const stream = `plugin-worker-${randomUUID()}`;
|
|
33
|
+
const instruction = JSON.stringify({ type: 'effect', server, tool, input: args });
|
|
34
|
+
const peer = journal.createPeer();
|
|
35
|
+
let diagnostic: string | undefined;
|
|
36
|
+
let settled!: () => void;
|
|
37
|
+
let failed!: (error: unknown) => void;
|
|
38
|
+
const completed = new Promise<void>((resolve, reject) => { settled = resolve; failed = reject; });
|
|
39
|
+
void completed.catch(() => undefined);
|
|
40
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
41
|
+
let work: Promise<void> | undefined;
|
|
42
|
+
let dispatchExpired = false;
|
|
43
|
+
const dispatch = (event: StepDispatchEvent): void => {
|
|
44
|
+
if (dispatchExpired) return;
|
|
45
|
+
const dispatched = event.spec as { instruction?: string; surfaces?: { streams?: { stream: string }[] } };
|
|
46
|
+
if (event.step_id !== id || event.step_type !== 'agent' || work !== undefined
|
|
47
|
+
|| dispatched?.instruction !== instruction
|
|
48
|
+
|| !dispatched.surfaces?.streams?.some(pin => pin.stream === stream)) {
|
|
49
|
+
failed(new Error('Plugin worker received an unexpected dispatch'));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
clearTimeout(timer);
|
|
53
|
+
timer = undefined;
|
|
54
|
+
work = execute(event);
|
|
55
|
+
void work.then(settled, failed);
|
|
56
|
+
};
|
|
57
|
+
async function execute(event: StepDispatchEvent): Promise<void> {
|
|
58
|
+
const receipt = { type: 'effect' as const, plugin: plugin.manifest.name, version: plugin.manifest.version,
|
|
59
|
+
namespace: server, method: tool, input: args, idempotencyKey: event.idempotency_key };
|
|
60
|
+
let output: unknown;
|
|
61
|
+
let confirmed = false;
|
|
62
|
+
try {
|
|
63
|
+
// Renew the worker lease while the Plugin tool is in flight. Without this,
|
|
64
|
+
// a tool that runs longer than the initial lease loses ownership and
|
|
65
|
+
// the write-back path fails — see worker-lease.ts for the renewal contract.
|
|
66
|
+
confirmed = await withWorkerLease(peer, event, async () => {
|
|
67
|
+
return peer.performEffect({
|
|
68
|
+
runId: event.run_id, stepId: id, attempt: event.attempt, idempotencyKey: event.idempotency_key,
|
|
69
|
+
surfacePath, revisionBefore: 'pending', revisionAfter: idempotencyKey,
|
|
70
|
+
}, async () => {
|
|
71
|
+
try { output = await invokePlugin(plugin, verb, args, event.idempotency_key); }
|
|
72
|
+
catch { diagnostic = 'plugin_execution_failed'; throw new PluginExecutionFailure(); }
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
// A confirmed election without its receipt is an interrupted writeback,
|
|
76
|
+
// not a successful result we may invent or a call we may safely repeat.
|
|
77
|
+
if (!confirmed) throw new Error('plugin_result_unavailable');
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (error instanceof PluginExecutionFailure) diagnostic = 'plugin_execution_failed';
|
|
80
|
+
else if (error instanceof Error && error.message === 'plugin_result_unavailable') diagnostic = error.message;
|
|
81
|
+
else throw error; // Journal failures remain fail-closed, never provider errors.
|
|
82
|
+
}
|
|
83
|
+
await peer.stepComplete(event.run_id, id, event.attempt, event.idempotency_key,
|
|
84
|
+
diagnostic === undefined ? 'success' : 'worker_error', {
|
|
85
|
+
output: { ...receipt, output: output ?? null, ...(diagnostic ? { diagnostic } : {}) },
|
|
86
|
+
started_pins: event.pins, end_pins: event.pins,
|
|
87
|
+
...(diagnostic ? { trajectory_tail: { ...receipt, diagnostic } } : {}),
|
|
88
|
+
effects: confirmed ? [{ surface_path: surfacePath, idempotency_key: event.idempotency_key }] : [],
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
let childRunId: string | undefined;
|
|
92
|
+
async function cancelChildRun(): Promise<void> {
|
|
93
|
+
const runId = childRunId;
|
|
94
|
+
childRunId = undefined;
|
|
95
|
+
if (runId !== undefined) {
|
|
96
|
+
try { await journal.runCancel(runId); } catch { /* fail-open on cleanup */ }
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const deadlineError = new Error('Plugin worker dispatch deadline exceeded');
|
|
100
|
+
let finishDeadline!: () => void;
|
|
101
|
+
const deadline = new Promise<void>((resolve, reject) => {
|
|
102
|
+
finishDeadline = resolve;
|
|
103
|
+
// One deadline covers connection, initialization, run creation and dispatch.
|
|
104
|
+
timer = setTimeout(() => {
|
|
105
|
+
dispatchExpired = true;
|
|
106
|
+
failed(deadlineError);
|
|
107
|
+
reject(deadlineError);
|
|
108
|
+
}, 30_000);
|
|
109
|
+
});
|
|
110
|
+
try {
|
|
111
|
+
await Promise.race([peer.connect(), deadline]);
|
|
112
|
+
await Promise.race([peer.hello('flows-plugin'), deadline]);
|
|
113
|
+
peer.on('step.dispatch', dispatch);
|
|
114
|
+
await Promise.race([peer.workerAttach(stream, ['agent'], { workspace: [], streams: [{ stream, read_offset: 0 }] }, 1), deadline]);
|
|
115
|
+
const spec = toKernelSpec(compileSpec({ version: SPEC_SCHEMA_VERSION, name: `${flowName}/${id}`,
|
|
116
|
+
steps: [{ id, type: 'agent', instruction,
|
|
117
|
+
surfaces: { streams: [{ stream }], external: [surfacePath] }, maxIterations: 1 }],
|
|
118
|
+
}));
|
|
119
|
+
return await Promise.race([budget.execute(journal, spec, async outcome => {
|
|
120
|
+
childRunId = outcome.run_id;
|
|
121
|
+
// run.start may answer after the deadline and the outer cleanup.
|
|
122
|
+
if (dispatchExpired) await cancelChildRun();
|
|
123
|
+
await completed;
|
|
124
|
+
if (diagnostic !== undefined) {
|
|
125
|
+
try { await readCompletedStepOutput(journal, outcome.run_id, id, journalSteps); }
|
|
126
|
+
catch (error) {
|
|
127
|
+
if (!(error instanceof AuthoredFlowExecutionError) || error.code !== 'step_failed') throw error;
|
|
128
|
+
throw new PluginStepError(diagnostic, outcome.run_id);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const receipt = await readCompletedStepOutput(journal, outcome.run_id, id, journalSteps) as { output: unknown };
|
|
132
|
+
return receipt.output;
|
|
133
|
+
}), deadline]);
|
|
134
|
+
} finally {
|
|
135
|
+
clearTimeout(timer);
|
|
136
|
+
finishDeadline();
|
|
137
|
+
peer.off('step.dispatch', dispatch);
|
|
138
|
+
// If the dispatch deadline fired we started a child run that will never
|
|
139
|
+
// be worked -- cancel it so its journal doesn't stay indeterminate.
|
|
140
|
+
// Best-effort: the parent flow already surfaced the deadline via the
|
|
141
|
+
// rejected `completed` promise, so a cancel error here must not mask it.
|
|
142
|
+
if (dispatchExpired) await cancelChildRun();
|
|
143
|
+
peer.close();
|
|
144
|
+
await work?.catch(() => undefined);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function pathPart(value: string): string {
|
|
149
|
+
return encodeURIComponent(value).replaceAll('.', '%2E');
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
class PluginExecutionFailure extends Error {}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { COMPLETION_REASONS, RUN_COMPLETION_REASONS } from '@relayflows/surface';
|
|
2
|
+
import { AuthoredFlowExecutionError } from './authored-flow-error.js';
|
|
3
|
+
import type { JournalClient } from './journal-client.js';
|
|
4
|
+
import type { CompletionReason as ProtocolCompletionReason, RunCompletionReason as ProtocolRunCompletionReason, RunOutcome } from './protocol.js';
|
|
5
|
+
import type { AuthoredFlowJournalStep } from './authored-flow-executor.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Shared by every `f.*` verb that lowers to one kernel step run in isolation:
|
|
9
|
+
* find its `step.completed` entry, record it, and refuse anything but a
|
|
10
|
+
* clean success before handing the raw `output` back for verb-specific
|
|
11
|
+
* extraction (a plain string for `f.run`, an `AgentResult` for `f.agent`).
|
|
12
|
+
*
|
|
13
|
+
* Callers are responsible for having already established that the RUN
|
|
14
|
+
* reached a terminal, successful state before calling this — `f.run`'s
|
|
15
|
+
* caller relies on `runStart`'s own immediate response (the kernel drives a
|
|
16
|
+
* deterministic step to completion inline, no race); `f.agent`'s caller
|
|
17
|
+
* relies on `classifyOutcome` (cli/run.ts) having already polled to a true
|
|
18
|
+
* terminal state. Given that, a single read from the start of this run's
|
|
19
|
+
* (small, single-step) journal is enough — no polling here, and no run
|
|
20
|
+
* outcome ever needs re-checking.
|
|
21
|
+
*/
|
|
22
|
+
export async function readCompletedStepOutput(
|
|
23
|
+
journal: JournalClient,
|
|
24
|
+
runId: string,
|
|
25
|
+
stepId: string,
|
|
26
|
+
journalSteps: AuthoredFlowJournalStep[],
|
|
27
|
+
): Promise<unknown> {
|
|
28
|
+
const entries = (await journal.journalRead(runId, 1)).entries;
|
|
29
|
+
const completed = entries.find((entry) => isStepCompleted(entry, stepId));
|
|
30
|
+
if (!isStepCompleted(completed, stepId)) {
|
|
31
|
+
throw protocolViolation(runId, `journal has no step.completed for "${stepId}"`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const reason = completed.payload.completionReason;
|
|
35
|
+
journalSteps.push(Object.freeze({ id: stepId, runId, completionReason: reason }));
|
|
36
|
+
if (reason !== 'success') {
|
|
37
|
+
throw new AuthoredFlowExecutionError(
|
|
38
|
+
'step_failed',
|
|
39
|
+
`journal step "${stepId}" completed with ${reason}`,
|
|
40
|
+
reason,
|
|
41
|
+
runId,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return completed.payload.output;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function readSuccessfulOutput(
|
|
48
|
+
journal: JournalClient,
|
|
49
|
+
outcome: RunOutcome,
|
|
50
|
+
stepId: string,
|
|
51
|
+
journalSteps: AuthoredFlowJournalStep[],
|
|
52
|
+
): Promise<string> {
|
|
53
|
+
const output = await readCompletedStepOutput(journal, outcome.run_id, stepId, journalSteps).catch(error => {
|
|
54
|
+
if (error instanceof AuthoredFlowExecutionError
|
|
55
|
+
&& (error.completionReason === 'timeout' || error.completionReason === 'lease_expired')) {
|
|
56
|
+
throw new AuthoredFlowExecutionError('lease_exceeded',
|
|
57
|
+
`f.run step "${stepId}" exceeded its command timeout.`, error.completionReason, error.runId);
|
|
58
|
+
}
|
|
59
|
+
throw error;
|
|
60
|
+
});
|
|
61
|
+
if (!isRecord(output) || typeof output['stdout_tail'] !== 'string') {
|
|
62
|
+
throw protocolViolation(outcome.run_id, `step "${stepId}" has no string stdout_tail`);
|
|
63
|
+
}
|
|
64
|
+
return output['stdout_tail'];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface StepCompletedEntry {
|
|
68
|
+
entry_type: 'step.completed';
|
|
69
|
+
step_id: string;
|
|
70
|
+
payload: {
|
|
71
|
+
completionReason: ProtocolCompletionReason;
|
|
72
|
+
output: unknown;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function isStepCompleted(value: unknown, stepId: string): value is StepCompletedEntry {
|
|
77
|
+
if (!isRecord(value) || value['entry_type'] !== 'step.completed' || value['step_id'] !== stepId) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
const payload = value['payload'];
|
|
81
|
+
return isRecord(payload)
|
|
82
|
+
&& isSurfaceCompletionReason(payload['completionReason'])
|
|
83
|
+
&& 'output' in payload;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function isSurfaceCompletionReason(value: unknown): value is ProtocolCompletionReason {
|
|
87
|
+
return typeof value === 'string'
|
|
88
|
+
&& (COMPLETION_REASONS as readonly string[]).includes(value);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function isSurfaceRunCompletionReason(value: unknown): value is ProtocolRunCompletionReason {
|
|
92
|
+
return typeof value === 'string'
|
|
93
|
+
&& (RUN_COMPLETION_REASONS as readonly string[]).includes(value);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
97
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function protocolViolation(runId: string, detail: string): AuthoredFlowExecutionError {
|
|
101
|
+
return new AuthoredFlowExecutionError(
|
|
102
|
+
'journal_protocol_violation',
|
|
103
|
+
detail,
|
|
104
|
+
undefined,
|
|
105
|
+
runId,
|
|
106
|
+
);
|
|
107
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import type { AuthoredBudget } from './authored-budget.js';
|
|
2
|
+
import { parseBudget } from './budget.js';
|
|
3
|
+
import type { AgentOptions, AgentResult, LlmOptions, NamedGate } from '@relayflows/surface';
|
|
4
|
+
import { compileSpec, toKernelSpec } from './compile.js';
|
|
5
|
+
import { checkAuthoredFlow } from './cli/check.js';
|
|
6
|
+
import { classifyOutcome, type RunLifecycleOptions } from './cli/run.js';
|
|
7
|
+
import type { PreflightDiagnostic } from './preflight.js';
|
|
8
|
+
import { AuthoredFlowExecutionError } from './authored-flow-error.js';
|
|
9
|
+
import type { JournalClient } from './journal-client.js';
|
|
10
|
+
import { SPEC_SCHEMA_VERSION, type FlowSpec, type StepSpec } from './spec.js';
|
|
11
|
+
import { isSurfaceCompletionReason, readCompletedStepOutput, readSuccessfulOutput } from './authored-step-output.js';
|
|
12
|
+
import type { AuthoredFlowJournalStep } from './authored-flow-executor.js';
|
|
13
|
+
import { snapshotJsonValue } from './json-value.js';
|
|
14
|
+
|
|
15
|
+
const WORKSPACE_PERMISSION_ANNOTATION = /:\s*(readonly|readwrite)\s*$/i;
|
|
16
|
+
|
|
17
|
+
/** Agent and LLM calls share the exact declarative preflight and lease wait. */
|
|
18
|
+
export function authoredWorkerRunner(
|
|
19
|
+
definition: { name: string }, journal: JournalClient, flowPath: string,
|
|
20
|
+
journalSteps: AuthoredFlowJournalStep[], waitOptions: RunLifecycleOptions,
|
|
21
|
+
localAgentStream?: string, budget?: AuthoredBudget, headerBudget?: unknown,
|
|
22
|
+
) {
|
|
23
|
+
async function run(step: StepSpec): Promise<unknown> {
|
|
24
|
+
const id = step.id;
|
|
25
|
+
const authoring: FlowSpec = { version: SPEC_SCHEMA_VERSION, name: `${definition.name}/${id}`, steps: [step], ...(headerBudget === undefined ? {} : { budget: parseBudget(headerBudget) }) };
|
|
26
|
+
// The kernel never resolves a `cli` on its own — every declarative
|
|
27
|
+
// `flows run`/`flows check` binds it first via this exact function
|
|
28
|
+
// (cli/check.ts), searching for the nearest flows.json from `flowPath`
|
|
29
|
+
// and real-probing auth/model readiness. An authored agent step gets
|
|
30
|
+
// nothing for free just because it was declared in TS instead of YAML.
|
|
31
|
+
const { report, flow: resolved } = checkAuthoredFlow(authoring, flowPath);
|
|
32
|
+
if (!report.ok || resolved === undefined) {
|
|
33
|
+
const refusal = report.diagnostics.find(
|
|
34
|
+
(diagnostic): diagnostic is PreflightDiagnostic & { severity: 'refusal' } =>
|
|
35
|
+
diagnostic.severity === 'refusal',
|
|
36
|
+
);
|
|
37
|
+
throw new AuthoredFlowExecutionError(
|
|
38
|
+
refusal?.kind === 'budget_missing_price' || refusal?.kind === 'budget_syntax_invalid' ? refusal.kind
|
|
39
|
+
: step.type === 'llm' ? 'llm_cli_unresolved' : 'agent_cli_unresolved',
|
|
40
|
+
refusal?.message
|
|
41
|
+
?? `flow "${definition.name}" step "${id}": no CLI could be resolved for f.${step.type} `
|
|
42
|
+
+ `(searched for flows.json from "${flowPath}")`,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
const spec = toKernelSpec(resolved);
|
|
46
|
+
const consume = async (outcome: import('./protocol.js').RunOutcome) => {
|
|
47
|
+
// Reuse the declarative CLI's own wait/classification (cli/run.ts) rather
|
|
48
|
+
// than a hand-rolled poll: `step.completed` and the run's own terminal
|
|
49
|
+
// state are appended as two SEPARATE actions (kernel/relayflowd-core/src/machine.rs
|
|
50
|
+
// completion_actions vs complete_run_actions), so a naive read right
|
|
51
|
+
// after runStart can race a real, valid completion — and a genuinely
|
|
52
|
+
// long-running agent has no reason to be bounded by anything other than
|
|
53
|
+
// its own worker's lease, which classifyOutcome already follows
|
|
54
|
+
// (renewing as the lease renews, per docs/SURFACE.md §5's WAITING
|
|
55
|
+
// [worker_lease] contract), never an unrelated fixed deadline.
|
|
56
|
+
const execution = await classifyOutcome(journal, 'run', outcome, report, '', waitOptions);
|
|
57
|
+
if (execution.exitCode === 3) {
|
|
58
|
+
const parked = execution.report.parkedStep;
|
|
59
|
+
throw new AuthoredFlowExecutionError(
|
|
60
|
+
step.type === 'llm' ? 'llm_parked' : 'agent_parked',
|
|
61
|
+
execution.report.diagnostics.at(-1)?.message
|
|
62
|
+
?? `flow "${definition.name}" step "${id}" parked`
|
|
63
|
+
+ (parked !== undefined ? ` (${parked.type})` : '')
|
|
64
|
+
+ ': no worker is attached to run it.',
|
|
65
|
+
undefined,
|
|
66
|
+
outcome.run_id,
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
if (execution.exitCode !== 0) {
|
|
70
|
+
const reason = execution.report.completionReason;
|
|
71
|
+
throw new AuthoredFlowExecutionError(
|
|
72
|
+
'step_failed',
|
|
73
|
+
execution.report.diagnostics.at(-1)?.message
|
|
74
|
+
?? `flow "${definition.name}" step "${id}" did not complete successfully `
|
|
75
|
+
+ `(status: ${execution.report.status ?? 'unknown'})`,
|
|
76
|
+
isSurfaceCompletionReason(reason) ? reason : undefined,
|
|
77
|
+
outcome.run_id,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
return readCompletedStepOutput(journal, outcome.run_id, id, journalSteps);
|
|
81
|
+
};
|
|
82
|
+
return budget === undefined ? consume(await journal.runStart(spec)) : budget.execute(journal, spec, consume);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
async agent(id: string, options: AgentOptions, verification?: NamedGate): Promise<AgentResult> {
|
|
87
|
+
if (options.workspace !== undefined && localAgentStream !== undefined) {
|
|
88
|
+
throw new AuthoredFlowExecutionError('unsupported_workspace_permission',
|
|
89
|
+
'The local agent worker accepts stream-only steps. Remove workspace or attach a worker that holds its revision pins.');
|
|
90
|
+
}
|
|
91
|
+
if (options.workspace !== undefined && WORKSPACE_PERMISSION_ANNOTATION.test(options.workspace)) {
|
|
92
|
+
throw new AuthoredFlowExecutionError(
|
|
93
|
+
'unsupported_workspace_permission',
|
|
94
|
+
`flow "${definition.name}" step "${id}": workspace "${options.workspace}" declares a `
|
|
95
|
+
+ 'permission annotation ("...: readonly" / "...: readwrite"), but nothing enforces it — '
|
|
96
|
+
+ 'no parser anywhere in this package turns that annotation into a real restriction '
|
|
97
|
+
+ '(kernel/DAEMON-LIFECYCLE.md\'s permission model is untouched by f.agent). '
|
|
98
|
+
+ 'Silently accepting and ignoring it would let a flow believe a restriction is in effect '
|
|
99
|
+
+ "when it is not. Declare a bare surface name (no trailing \": readonly\"/\": readwrite\") "
|
|
100
|
+
+ 'if you do not need enforcement, or use the declarative spec\'s `permissions` field, which is real.',
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
if (options.cli !== undefined && typeof options.cli !== 'string') {
|
|
104
|
+
throw new AuthoredFlowExecutionError(
|
|
105
|
+
'agent_cli_unresolved',
|
|
106
|
+
`f.agent options.cli must be a string when set (got ${typeof options.cli}).`,
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
if (options.model !== undefined && typeof options.model !== 'string') {
|
|
110
|
+
throw new AuthoredFlowExecutionError(
|
|
111
|
+
'agent_cli_unresolved',
|
|
112
|
+
`f.agent options.model must be a string when set (got ${typeof options.model}).`,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
if (options.cwd !== undefined && typeof options.cwd !== 'string') {
|
|
116
|
+
throw new AuthoredFlowExecutionError(
|
|
117
|
+
'agent_cli_unresolved',
|
|
118
|
+
`f.agent options.cwd must be a string when set (got ${typeof options.cwd}).`,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
if (options.transport !== undefined && options.transport !== 'direct' && options.transport !== 'relay') {
|
|
122
|
+
throw new AuthoredFlowExecutionError(
|
|
123
|
+
'agent_cli_unresolved',
|
|
124
|
+
`f.agent options.transport must be 'direct' or 'relay' (got ${JSON.stringify(options.transport)}).`,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
const output = await run({
|
|
128
|
+
id, type: 'agent', instruction: options.task,
|
|
129
|
+
...(localAgentStream === undefined ? {} : { surfaces: { streams: [{ stream: localAgentStream }] } }),
|
|
130
|
+
...(options.workspace === undefined ? {} : { surfaces: { workspace: [{ surface: options.workspace }] } }),
|
|
131
|
+
...(options.cli === undefined ? {} : { cli: options.cli }),
|
|
132
|
+
...(options.model === undefined ? {} : { model: options.model }),
|
|
133
|
+
...(options.cwd === undefined ? {} : { cwd: options.cwd }),
|
|
134
|
+
...(options.transport === undefined ? {} : { transport: options.transport }),
|
|
135
|
+
...(verification === undefined ? {} : { verification }),
|
|
136
|
+
});
|
|
137
|
+
if (typeof output !== 'object' || output === null || Array.isArray(output)) {
|
|
138
|
+
throw new AuthoredFlowExecutionError('journal_protocol_violation', `step "${id}" produced a non-object output`);
|
|
139
|
+
}
|
|
140
|
+
const stdout = 'stdout_tail' in output ? output.stdout_tail : undefined;
|
|
141
|
+
return { summary: typeof stdout === 'string' ? stdout : JSON.stringify(output), artifacts: [] };
|
|
142
|
+
},
|
|
143
|
+
async llm(id: string, prompt: string, options?: LlmOptions, verification?: NamedGate): Promise<unknown> {
|
|
144
|
+
if (options !== undefined && (typeof options !== 'object' || options === null || options.output === undefined)) {
|
|
145
|
+
throw new AuthoredFlowExecutionError('llm_cli_unresolved', 'f.llm(prompt, options) requires an output JSON Schema.');
|
|
146
|
+
}
|
|
147
|
+
const snapshot = options === undefined ? undefined : snapshotJsonValue(options, 'f.llm options');
|
|
148
|
+
if (snapshot !== undefined && (typeof snapshot !== 'object' || snapshot === null || Array.isArray(snapshot)
|
|
149
|
+
|| Object.keys(snapshot).some(key => !['output', 'cli', 'model'].includes(key)))) {
|
|
150
|
+
throw new AuthoredFlowExecutionError('llm_cli_unresolved', 'f.llm options accepts only output, cli, and model.');
|
|
151
|
+
}
|
|
152
|
+
const output = await run({
|
|
153
|
+
id, type: 'llm', prompt, ...snapshot as unknown as LlmOptions,
|
|
154
|
+
...(verification === undefined ? {} : { verification }),
|
|
155
|
+
});
|
|
156
|
+
if (options === undefined && typeof output !== 'string') {
|
|
157
|
+
throw new AuthoredFlowExecutionError('journal_protocol_violation', `text step "${id}" produced a non-string output`);
|
|
158
|
+
}
|
|
159
|
+
return output;
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Deterministic commands execute inline under their per-invocation lease. */
|
|
165
|
+
export function authoredDeterministicRunner(
|
|
166
|
+
name: string, journal: JournalClient, journalSteps: AuthoredFlowJournalStep[], budget: AuthoredBudget,
|
|
167
|
+
) {
|
|
168
|
+
return async (id: string, command: string, terminal = false, leaseMs?: number, verification?: NamedGate): Promise<string> => {
|
|
169
|
+
const spec = toKernelSpec(compileSpec({
|
|
170
|
+
version: SPEC_SCHEMA_VERSION,
|
|
171
|
+
name: `${name}/${id}`,
|
|
172
|
+
steps: [{
|
|
173
|
+
id, type: 'deterministic', command,
|
|
174
|
+
...(leaseMs === undefined ? {} : { lease_ms: leaseMs }),
|
|
175
|
+
...(verification === undefined ? {} : { verification }),
|
|
176
|
+
}],
|
|
177
|
+
}));
|
|
178
|
+
if (terminal) return readSuccessfulOutput(journal, await journal.runStart(spec), id, journalSteps);
|
|
179
|
+
return budget.execute(journal, spec, outcome => readSuccessfulOutput(journal, outcome, id, journalSteps));
|
|
180
|
+
};
|
|
181
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CompiledFlowSpec } from './compile.js';
|
|
2
|
+
import type { PreflightRefusal } from './preflight.js';
|
|
3
|
+
import { MODEL_PRICING } from './model-pricing.js';
|
|
4
|
+
|
|
5
|
+
/** Legacy explicit envelopes keep their worker-supplied pricing contract. */
|
|
6
|
+
export function budgetDiagnostics(flow: CompiledFlowSpec): PreflightRefusal[] {
|
|
7
|
+
if (flow.budget?.pricing !== 'frozen') return [];
|
|
8
|
+
const diagnostics: PreflightRefusal[] = [];
|
|
9
|
+
const declared = [
|
|
10
|
+
...Object.entries(flow.agents ?? {}).map(([agent, d]) => ({ agent, model: d.model })),
|
|
11
|
+
...flow.steps.flatMap(s => s.type !== 'deterministic' && s.model !== undefined
|
|
12
|
+
? [{ stepId: s.id, model: s.model }] : []),
|
|
13
|
+
];
|
|
14
|
+
for (const step of flow.steps) {
|
|
15
|
+
if (step.type === 'deterministic' || flow.budget.maxDollars === undefined) continue;
|
|
16
|
+
const model = step.model ?? (step.type === 'agent' && step.agent !== undefined
|
|
17
|
+
? flow.agents?.[step.agent]?.model : undefined);
|
|
18
|
+
if (model === undefined) diagnostics.push({
|
|
19
|
+
severity: 'refusal', kind: 'budget_missing_price', stepId: step.id,
|
|
20
|
+
message: `Step "${step.id}" needs a declared, priced model for its dollar budget.`,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
for (const declaration of declared) {
|
|
24
|
+
if (Object.hasOwn(MODEL_PRICING, declaration.model)) continue;
|
|
25
|
+
diagnostics.push({
|
|
26
|
+
severity: 'refusal', kind: 'budget_missing_price', ...declaration,
|
|
27
|
+
message: `Model "${declaration.model}" has no frozen price for budget accounting.`,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return diagnostics;
|
|
31
|
+
}
|
package/src/budget.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { BudgetSpec, KernelBudgetSpec } from './spec.js';
|
|
2
|
+
|
|
3
|
+
export type HeaderBudget = string | { tokens?: number; dollars?: number; wallclock?: string };
|
|
4
|
+
|
|
5
|
+
export class BudgetSyntaxError extends Error {
|
|
6
|
+
constructor() { super('budget_syntax_invalid: expected $<amount>/run, $<amount>/day, or { tokens, dollars, wallclock }'); }
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Normalize surface sugar; existing explicit envelopes remain supported. */
|
|
10
|
+
export function parseBudget(value: unknown): BudgetSpec {
|
|
11
|
+
if (typeof value === 'string') {
|
|
12
|
+
const match = /^\$(\d+(?:\.\d{1,6})?)\/(run|day)$/.exec(value);
|
|
13
|
+
if (!match) throw new BudgetSyntaxError();
|
|
14
|
+
return { pricing: 'frozen', maxDollars: match[1]!, ...(match[2] === 'day' ? { window: 'day' as const } : {}) };
|
|
15
|
+
}
|
|
16
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) throw new BudgetSyntaxError();
|
|
17
|
+
const b = value as Record<string, unknown>;
|
|
18
|
+
const legacy = ['maxTokensIn', 'maxTokensOut', 'maxTokens', 'maxDollars', 'maxWallclockMs', 'window', 'pricing'];
|
|
19
|
+
if (Object.keys(b).some(k => legacy.includes(k))) {
|
|
20
|
+
if (Object.keys(b).some(k => !legacy.includes(k))) throw new BudgetSyntaxError();
|
|
21
|
+
return b as BudgetSpec;
|
|
22
|
+
}
|
|
23
|
+
if (Object.keys(b).some(k => !['tokens', 'dollars', 'wallclock'].includes(k))) throw new BudgetSyntaxError();
|
|
24
|
+
if (b.tokens !== undefined && (!Number.isSafeInteger(b.tokens) || (b.tokens as number) < 0)) throw new BudgetSyntaxError();
|
|
25
|
+
if (b.dollars !== undefined && (typeof b.dollars !== 'number' || !Number.isFinite(b.dollars) || b.dollars < 0 || !/^\d+(?:\.\d{1,6})?$/.test(String(b.dollars)))) throw new BudgetSyntaxError();
|
|
26
|
+
let ms: number | undefined;
|
|
27
|
+
if (b.wallclock !== undefined) {
|
|
28
|
+
const match = typeof b.wallclock === 'string' && /^(\d+)(ms|s|m|h|d)$/.exec(b.wallclock);
|
|
29
|
+
if (!match) throw new BudgetSyntaxError();
|
|
30
|
+
ms = Number(match[1]) * ({ms:1,s:1000,m:60000,h:3600000,d:86400000}[match[2]!]!);
|
|
31
|
+
if (!Number.isSafeInteger(ms)) throw new BudgetSyntaxError();
|
|
32
|
+
}
|
|
33
|
+
return { pricing: 'frozen', ...(b.tokens === undefined ? {} : {maxTokens: b.tokens as number}),
|
|
34
|
+
...(b.dollars === undefined ? {} : {maxDollars: String(b.dollars)}),
|
|
35
|
+
...(ms === undefined ? {} : {maxWallclockMs: ms}) };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Lower a normalized envelope to the existing kernel protocol. */
|
|
39
|
+
export function toKernelBudget(budget: BudgetSpec): KernelBudgetSpec {
|
|
40
|
+
return {
|
|
41
|
+
...(budget.pricing !== undefined ? { pricing: budget.pricing } : {}),
|
|
42
|
+
...(budget.maxTokens !== undefined ? { max_tokens: budget.maxTokens } : {}),
|
|
43
|
+
...(budget.maxWallclockMs !== undefined ? { max_wallclock_ms: budget.maxWallclockMs } : {}),
|
|
44
|
+
...(budget.window !== undefined ? { window: budget.window } : {}),
|
|
45
|
+
...(budget.maxTokensIn !== undefined ? { max_tokens_in: budget.maxTokensIn } : {}),
|
|
46
|
+
...(budget.maxTokensOut !== undefined ? { max_tokens_out: budget.maxTokensOut } : {}),
|
|
47
|
+
...(budget.maxDollars !== undefined ? { max_dollars: budget.maxDollars } : {}),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { constants } from 'node:fs';
|
|
2
|
+
import { access, cp, lstat, mkdir, mkdtemp, rename, rm } from 'node:fs/promises';
|
|
3
|
+
import { dirname, isAbsolute, join } from 'node:path';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { verifyBundle } from './bundle.js';
|
|
7
|
+
|
|
8
|
+
export type BundleFailureKind = 'bucket_unconfigured' | 'bucket_unreachable'
|
|
9
|
+
| 'bundle_missing_locally' | 'bundle_signature_invalid' | 'bundle_unsupported' | 'deploy_partial';
|
|
10
|
+
export class BundleFailure extends Error {
|
|
11
|
+
constructor(readonly kind: BundleFailureKind, message: string) { super(message); }
|
|
12
|
+
}
|
|
13
|
+
export interface DigestReference { name: string; digest: string }
|
|
14
|
+
export function parseDigestReference(value: string): DigestReference | undefined {
|
|
15
|
+
// Match the safe single-component name grammar used by sealBundle.
|
|
16
|
+
const match = /^([A-Za-z0-9][A-Za-z0-9._-]*)@sha256:([0-9a-f]{64})$/.exec(value);
|
|
17
|
+
return match ? { name: match[1]!, digest: match[2]! } : undefined;
|
|
18
|
+
}
|
|
19
|
+
export function bucketDirectory(uri: string, ref: DigestReference): string {
|
|
20
|
+
try {
|
|
21
|
+
const url = new URL(uri);
|
|
22
|
+
if (url.protocol !== 'file:' || url.search || url.hash) throw new Error('expected file:// URI');
|
|
23
|
+
const path = fileURLToPath(url);
|
|
24
|
+
if (!isAbsolute(path)) throw new Error('expected absolute bucket path');
|
|
25
|
+
return join(path, ref.name, 'sha256', ref.digest);
|
|
26
|
+
} catch {
|
|
27
|
+
throw new BundleFailure('bucket_unreachable', 'This slice requires an absolute file:// bucket URI.');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export async function exists(path: string): Promise<boolean> {
|
|
31
|
+
try { await lstat(path); return true; }
|
|
32
|
+
catch (error) { if ((error as NodeJS.ErrnoException).code === 'ENOENT') return false; throw error; }
|
|
33
|
+
}
|
|
34
|
+
export async function verifyDigest(directory: string, digest: string): Promise<void> {
|
|
35
|
+
try { await verifyBundle(directory, digest); }
|
|
36
|
+
catch (error) { throw new BundleFailure('bundle_signature_invalid', String(error)); }
|
|
37
|
+
}
|
|
38
|
+
/** Publish only a complete, verified directory. Concurrent identical writers converge. */
|
|
39
|
+
export async function copyBundle(source: string, target: string, digest: string): Promise<boolean> {
|
|
40
|
+
if (await exists(target)) { await verifyDigest(target, digest); return false; }
|
|
41
|
+
await mkdir(dirname(target), { recursive: true });
|
|
42
|
+
const staging = await mkdtemp(join(dirname(target), '.bundle-'));
|
|
43
|
+
try {
|
|
44
|
+
await cp(source, staging, { recursive: true, dereference: false, verbatimSymlinks: true });
|
|
45
|
+
await verifyDigest(staging, digest);
|
|
46
|
+
try { await rename(staging, target); }
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (!['EEXIST', 'ENOTEMPTY'].includes((error as NodeJS.ErrnoException).code ?? '')) throw error;
|
|
49
|
+
await verifyDigest(target, digest);
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
} finally { await rm(staging, { recursive: true, force: true }); }
|
|
54
|
+
}
|
|
55
|
+
export async function writableBucket(target: string): Promise<void> {
|
|
56
|
+
try {
|
|
57
|
+
await mkdir(dirname(target), { recursive: true });
|
|
58
|
+
await access(dirname(target), constants.W_OK);
|
|
59
|
+
const probe = await mkdtemp(join(dirname(target), '.probe-'));
|
|
60
|
+
await rm(probe, { recursive: true });
|
|
61
|
+
} catch (error) { throw new BundleFailure('bucket_unreachable', String(error)); }
|
|
62
|
+
}
|
|
63
|
+
export async function fetchBundle(ref: DigestReference, bucket: string): Promise<string> {
|
|
64
|
+
const cacheRoot = process.env['XDG_CACHE_HOME'];
|
|
65
|
+
const cache = join(cacheRoot && isAbsolute(cacheRoot) ? cacheRoot : join(homedir(), '.cache'),
|
|
66
|
+
'flows', 'bundles', ref.digest);
|
|
67
|
+
// Verify every hit; a corrupt cache never executes or silently falls back.
|
|
68
|
+
if (await exists(cache)) { await verifyDigest(cache, ref.digest); return cache; }
|
|
69
|
+
const source = bucketDirectory(bucket, ref);
|
|
70
|
+
try {
|
|
71
|
+
if (!await exists(source)) throw new BundleFailure('bucket_unreachable', `Bundle is absent at ${bucket}.`);
|
|
72
|
+
await verifyDigest(source, ref.digest);
|
|
73
|
+
await copyBundle(source, cache, ref.digest);
|
|
74
|
+
return cache;
|
|
75
|
+
} catch (error) {
|
|
76
|
+
if (error instanceof BundleFailure) throw error;
|
|
77
|
+
throw new BundleFailure('bucket_unreachable', String(error));
|
|
78
|
+
}
|
|
79
|
+
}
|