@relayflows/sdk 2.0.9 → 2.0.10
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-transport.d.ts +84 -0
- package/dist/agent-relay-transport.d.ts.map +1 -0
- package/dist/agent-relay-transport.js +134 -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 +13 -1
- package/dist/worker-cli.d.ts.map +1 -1
- package/dist/worker-cli.js +133 -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 +22 -8
- 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-transport.ts +187 -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 +156 -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 +27 -9
- 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,136 @@
|
|
|
1
|
+
import { parseBudget } from './budget.js';
|
|
2
|
+
import { compileSpec, toKernelSpec } from './compile.js';
|
|
3
|
+
import { checkAuthoredFlow } from './cli/check.js';
|
|
4
|
+
import { classifyOutcome } from './cli/run.js';
|
|
5
|
+
import { AuthoredFlowExecutionError } from './authored-flow-error.js';
|
|
6
|
+
import { SPEC_SCHEMA_VERSION } from './spec.js';
|
|
7
|
+
import { isSurfaceCompletionReason, readCompletedStepOutput, readSuccessfulOutput } from './authored-step-output.js';
|
|
8
|
+
import { snapshotJsonValue } from './json-value.js';
|
|
9
|
+
const WORKSPACE_PERMISSION_ANNOTATION = /:\s*(readonly|readwrite)\s*$/i;
|
|
10
|
+
/** Agent and LLM calls share the exact declarative preflight and lease wait. */
|
|
11
|
+
export function authoredWorkerRunner(definition, journal, flowPath, journalSteps, waitOptions, localAgentStream, budget, headerBudget) {
|
|
12
|
+
async function run(step) {
|
|
13
|
+
const id = step.id;
|
|
14
|
+
const authoring = { version: SPEC_SCHEMA_VERSION, name: `${definition.name}/${id}`, steps: [step], ...(headerBudget === undefined ? {} : { budget: parseBudget(headerBudget) }) };
|
|
15
|
+
// The kernel never resolves a `cli` on its own — every declarative
|
|
16
|
+
// `flows run`/`flows check` binds it first via this exact function
|
|
17
|
+
// (cli/check.ts), searching for the nearest flows.json from `flowPath`
|
|
18
|
+
// and real-probing auth/model readiness. An authored agent step gets
|
|
19
|
+
// nothing for free just because it was declared in TS instead of YAML.
|
|
20
|
+
const { report, flow: resolved } = checkAuthoredFlow(authoring, flowPath);
|
|
21
|
+
if (!report.ok || resolved === undefined) {
|
|
22
|
+
const refusal = report.diagnostics.find((diagnostic) => diagnostic.severity === 'refusal');
|
|
23
|
+
throw new AuthoredFlowExecutionError(refusal?.kind === 'budget_missing_price' || refusal?.kind === 'budget_syntax_invalid' ? refusal.kind
|
|
24
|
+
: step.type === 'llm' ? 'llm_cli_unresolved' : 'agent_cli_unresolved', refusal?.message
|
|
25
|
+
?? `flow "${definition.name}" step "${id}": no CLI could be resolved for f.${step.type} `
|
|
26
|
+
+ `(searched for flows.json from "${flowPath}")`);
|
|
27
|
+
}
|
|
28
|
+
const spec = toKernelSpec(resolved);
|
|
29
|
+
const consume = async (outcome) => {
|
|
30
|
+
// Reuse the declarative CLI's own wait/classification (cli/run.ts) rather
|
|
31
|
+
// than a hand-rolled poll: `step.completed` and the run's own terminal
|
|
32
|
+
// state are appended as two SEPARATE actions (kernel/relayflowd-core/src/machine.rs
|
|
33
|
+
// completion_actions vs complete_run_actions), so a naive read right
|
|
34
|
+
// after runStart can race a real, valid completion — and a genuinely
|
|
35
|
+
// long-running agent has no reason to be bounded by anything other than
|
|
36
|
+
// its own worker's lease, which classifyOutcome already follows
|
|
37
|
+
// (renewing as the lease renews, per docs/SURFACE.md §5's WAITING
|
|
38
|
+
// [worker_lease] contract), never an unrelated fixed deadline.
|
|
39
|
+
const execution = await classifyOutcome(journal, 'run', outcome, report, '', waitOptions);
|
|
40
|
+
if (execution.exitCode === 3) {
|
|
41
|
+
const parked = execution.report.parkedStep;
|
|
42
|
+
throw new AuthoredFlowExecutionError(step.type === 'llm' ? 'llm_parked' : 'agent_parked', execution.report.diagnostics.at(-1)?.message
|
|
43
|
+
?? `flow "${definition.name}" step "${id}" parked`
|
|
44
|
+
+ (parked !== undefined ? ` (${parked.type})` : '')
|
|
45
|
+
+ ': no worker is attached to run it.', undefined, outcome.run_id);
|
|
46
|
+
}
|
|
47
|
+
if (execution.exitCode !== 0) {
|
|
48
|
+
const reason = execution.report.completionReason;
|
|
49
|
+
throw new AuthoredFlowExecutionError('step_failed', execution.report.diagnostics.at(-1)?.message
|
|
50
|
+
?? `flow "${definition.name}" step "${id}" did not complete successfully `
|
|
51
|
+
+ `(status: ${execution.report.status ?? 'unknown'})`, isSurfaceCompletionReason(reason) ? reason : undefined, outcome.run_id);
|
|
52
|
+
}
|
|
53
|
+
return readCompletedStepOutput(journal, outcome.run_id, id, journalSteps);
|
|
54
|
+
};
|
|
55
|
+
return budget === undefined ? consume(await journal.runStart(spec)) : budget.execute(journal, spec, consume);
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
async agent(id, options, verification) {
|
|
59
|
+
if (options.workspace !== undefined && localAgentStream !== undefined) {
|
|
60
|
+
throw new AuthoredFlowExecutionError('unsupported_workspace_permission', 'The local agent worker accepts stream-only steps. Remove workspace or attach a worker that holds its revision pins.');
|
|
61
|
+
}
|
|
62
|
+
if (options.workspace !== undefined && WORKSPACE_PERMISSION_ANNOTATION.test(options.workspace)) {
|
|
63
|
+
throw new AuthoredFlowExecutionError('unsupported_workspace_permission', `flow "${definition.name}" step "${id}": workspace "${options.workspace}" declares a `
|
|
64
|
+
+ 'permission annotation ("...: readonly" / "...: readwrite"), but nothing enforces it — '
|
|
65
|
+
+ 'no parser anywhere in this package turns that annotation into a real restriction '
|
|
66
|
+
+ '(kernel/DAEMON-LIFECYCLE.md\'s permission model is untouched by f.agent). '
|
|
67
|
+
+ 'Silently accepting and ignoring it would let a flow believe a restriction is in effect '
|
|
68
|
+
+ "when it is not. Declare a bare surface name (no trailing \": readonly\"/\": readwrite\") "
|
|
69
|
+
+ 'if you do not need enforcement, or use the declarative spec\'s `permissions` field, which is real.');
|
|
70
|
+
}
|
|
71
|
+
if (options.cli !== undefined && typeof options.cli !== 'string') {
|
|
72
|
+
throw new AuthoredFlowExecutionError('agent_cli_unresolved', `f.agent options.cli must be a string when set (got ${typeof options.cli}).`);
|
|
73
|
+
}
|
|
74
|
+
if (options.model !== undefined && typeof options.model !== 'string') {
|
|
75
|
+
throw new AuthoredFlowExecutionError('agent_cli_unresolved', `f.agent options.model must be a string when set (got ${typeof options.model}).`);
|
|
76
|
+
}
|
|
77
|
+
if (options.cwd !== undefined && typeof options.cwd !== 'string') {
|
|
78
|
+
throw new AuthoredFlowExecutionError('agent_cli_unresolved', `f.agent options.cwd must be a string when set (got ${typeof options.cwd}).`);
|
|
79
|
+
}
|
|
80
|
+
if (options.transport !== undefined && options.transport !== 'direct' && options.transport !== 'relay') {
|
|
81
|
+
throw new AuthoredFlowExecutionError('agent_cli_unresolved', `f.agent options.transport must be 'direct' or 'relay' (got ${JSON.stringify(options.transport)}).`);
|
|
82
|
+
}
|
|
83
|
+
const output = await run({
|
|
84
|
+
id, type: 'agent', instruction: options.task,
|
|
85
|
+
...(localAgentStream === undefined ? {} : { surfaces: { streams: [{ stream: localAgentStream }] } }),
|
|
86
|
+
...(options.workspace === undefined ? {} : { surfaces: { workspace: [{ surface: options.workspace }] } }),
|
|
87
|
+
...(options.cli === undefined ? {} : { cli: options.cli }),
|
|
88
|
+
...(options.model === undefined ? {} : { model: options.model }),
|
|
89
|
+
...(options.cwd === undefined ? {} : { cwd: options.cwd }),
|
|
90
|
+
...(options.transport === undefined ? {} : { transport: options.transport }),
|
|
91
|
+
...(verification === undefined ? {} : { verification }),
|
|
92
|
+
});
|
|
93
|
+
if (typeof output !== 'object' || output === null || Array.isArray(output)) {
|
|
94
|
+
throw new AuthoredFlowExecutionError('journal_protocol_violation', `step "${id}" produced a non-object output`);
|
|
95
|
+
}
|
|
96
|
+
const stdout = 'stdout_tail' in output ? output.stdout_tail : undefined;
|
|
97
|
+
return { summary: typeof stdout === 'string' ? stdout : JSON.stringify(output), artifacts: [] };
|
|
98
|
+
},
|
|
99
|
+
async llm(id, prompt, options, verification) {
|
|
100
|
+
if (options !== undefined && (typeof options !== 'object' || options === null || options.output === undefined)) {
|
|
101
|
+
throw new AuthoredFlowExecutionError('llm_cli_unresolved', 'f.llm(prompt, options) requires an output JSON Schema.');
|
|
102
|
+
}
|
|
103
|
+
const snapshot = options === undefined ? undefined : snapshotJsonValue(options, 'f.llm options');
|
|
104
|
+
if (snapshot !== undefined && (typeof snapshot !== 'object' || snapshot === null || Array.isArray(snapshot)
|
|
105
|
+
|| Object.keys(snapshot).some(key => !['output', 'cli', 'model'].includes(key)))) {
|
|
106
|
+
throw new AuthoredFlowExecutionError('llm_cli_unresolved', 'f.llm options accepts only output, cli, and model.');
|
|
107
|
+
}
|
|
108
|
+
const output = await run({
|
|
109
|
+
id, type: 'llm', prompt, ...snapshot,
|
|
110
|
+
...(verification === undefined ? {} : { verification }),
|
|
111
|
+
});
|
|
112
|
+
if (options === undefined && typeof output !== 'string') {
|
|
113
|
+
throw new AuthoredFlowExecutionError('journal_protocol_violation', `text step "${id}" produced a non-string output`);
|
|
114
|
+
}
|
|
115
|
+
return output;
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/** Deterministic commands execute inline under their per-invocation lease. */
|
|
120
|
+
export function authoredDeterministicRunner(name, journal, journalSteps, budget) {
|
|
121
|
+
return async (id, command, terminal = false, leaseMs, verification) => {
|
|
122
|
+
const spec = toKernelSpec(compileSpec({
|
|
123
|
+
version: SPEC_SCHEMA_VERSION,
|
|
124
|
+
name: `${name}/${id}`,
|
|
125
|
+
steps: [{
|
|
126
|
+
id, type: 'deterministic', command,
|
|
127
|
+
...(leaseMs === undefined ? {} : { lease_ms: leaseMs }),
|
|
128
|
+
...(verification === undefined ? {} : { verification }),
|
|
129
|
+
}],
|
|
130
|
+
}));
|
|
131
|
+
if (terminal)
|
|
132
|
+
return readSuccessfulOutput(journal, await journal.runStart(spec), id, journalSteps);
|
|
133
|
+
return budget.execute(journal, spec, outcome => readSuccessfulOutput(journal, outcome, id, journalSteps));
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=authored-worker-step.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authored-worker-step.js","sourceRoot":"","sources":["../src/authored-worker-step.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,C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,MAAM,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,YAAY,CAAC,CAAC;QACnG,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,YAAY,CAAC,CAAC,CAAC;IAC5G,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CompiledFlowSpec } from './compile.js';
|
|
2
|
+
import type { PreflightRefusal } from './preflight.js';
|
|
3
|
+
/** Legacy explicit envelopes keep their worker-supplied pricing contract. */
|
|
4
|
+
export declare function budgetDiagnostics(flow: CompiledFlowSpec): PreflightRefusal[];
|
|
5
|
+
//# sourceMappingURL=budget-preflight.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"budget-preflight.d.ts","sourceRoot":"","sources":["../src/budget-preflight.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGvD,6EAA6E;AAC7E,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,GAAG,gBAAgB,EAAE,CAyB5E"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { MODEL_PRICING } from './model-pricing.js';
|
|
2
|
+
/** Legacy explicit envelopes keep their worker-supplied pricing contract. */
|
|
3
|
+
export function budgetDiagnostics(flow) {
|
|
4
|
+
if (flow.budget?.pricing !== 'frozen')
|
|
5
|
+
return [];
|
|
6
|
+
const diagnostics = [];
|
|
7
|
+
const declared = [
|
|
8
|
+
...Object.entries(flow.agents ?? {}).map(([agent, d]) => ({ agent, model: d.model })),
|
|
9
|
+
...flow.steps.flatMap(s => s.type !== 'deterministic' && s.model !== undefined
|
|
10
|
+
? [{ stepId: s.id, model: s.model }] : []),
|
|
11
|
+
];
|
|
12
|
+
for (const step of flow.steps) {
|
|
13
|
+
if (step.type === 'deterministic' || flow.budget.maxDollars === undefined)
|
|
14
|
+
continue;
|
|
15
|
+
const model = step.model ?? (step.type === 'agent' && step.agent !== undefined
|
|
16
|
+
? flow.agents?.[step.agent]?.model : undefined);
|
|
17
|
+
if (model === undefined)
|
|
18
|
+
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))
|
|
25
|
+
continue;
|
|
26
|
+
diagnostics.push({
|
|
27
|
+
severity: 'refusal', kind: 'budget_missing_price', ...declaration,
|
|
28
|
+
message: `Model "${declaration.model}" has no frozen price for budget accounting.`,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return diagnostics;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=budget-preflight.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"budget-preflight.js","sourceRoot":"","sources":["../src/budget-preflight.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,6EAA6E;AAC7E,MAAM,UAAU,iBAAiB,CAAC,IAAsB;IACtD,IAAI,IAAI,CAAC,MAAM,EAAE,OAAO,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IACjD,MAAM,WAAW,GAAuB,EAAE,CAAC;IAC3C,MAAM,QAAQ,GAAG;QACf,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,C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K,8CAA8C;SACnF,CAAC,CAAC;IACL,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
package/dist/budget.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BudgetSpec, KernelBudgetSpec } from './spec.js';
|
|
2
|
+
export type HeaderBudget = string | {
|
|
3
|
+
tokens?: number;
|
|
4
|
+
dollars?: number;
|
|
5
|
+
wallclock?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class BudgetSyntaxError extends Error {
|
|
8
|
+
constructor();
|
|
9
|
+
}
|
|
10
|
+
/** Normalize surface sugar; existing explicit envelopes remain supported. */
|
|
11
|
+
export declare function parseBudget(value: unknown): BudgetSpec;
|
|
12
|
+
/** Lower a normalized envelope to the existing kernel protocol. */
|
|
13
|
+
export declare function toKernelBudget(budget: BudgetSpec): KernelBudgetSpec;
|
|
14
|
+
//# sourceMappingURL=budget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"budget.d.ts","sourceRoot":"","sources":["../src/budget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE9D,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9F,qBAAa,iBAAkB,SAAQ,KAAK;;CAE3C;AAED,6EAA6E;AAC7E,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CA0BtD;AAED,mEAAmE;AACnE,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,gBAAgB,CAUnE"}
|
package/dist/budget.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export class BudgetSyntaxError extends Error {
|
|
2
|
+
constructor() { super('budget_syntax_invalid: expected $<amount>/run, $<amount>/day, or { tokens, dollars, wallclock }'); }
|
|
3
|
+
}
|
|
4
|
+
/** Normalize surface sugar; existing explicit envelopes remain supported. */
|
|
5
|
+
export function parseBudget(value) {
|
|
6
|
+
if (typeof value === 'string') {
|
|
7
|
+
const match = /^\$(\d+(?:\.\d{1,6})?)\/(run|day)$/.exec(value);
|
|
8
|
+
if (!match)
|
|
9
|
+
throw new BudgetSyntaxError();
|
|
10
|
+
return { pricing: 'frozen', maxDollars: match[1], ...(match[2] === 'day' ? { window: 'day' } : {}) };
|
|
11
|
+
}
|
|
12
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
13
|
+
throw new BudgetSyntaxError();
|
|
14
|
+
const b = value;
|
|
15
|
+
const legacy = ['maxTokensIn', 'maxTokensOut', 'maxTokens', 'maxDollars', 'maxWallclockMs', 'window', 'pricing'];
|
|
16
|
+
if (Object.keys(b).some(k => legacy.includes(k))) {
|
|
17
|
+
if (Object.keys(b).some(k => !legacy.includes(k)))
|
|
18
|
+
throw new BudgetSyntaxError();
|
|
19
|
+
return b;
|
|
20
|
+
}
|
|
21
|
+
if (Object.keys(b).some(k => !['tokens', 'dollars', 'wallclock'].includes(k)))
|
|
22
|
+
throw new BudgetSyntaxError();
|
|
23
|
+
if (b.tokens !== undefined && (!Number.isSafeInteger(b.tokens) || b.tokens < 0))
|
|
24
|
+
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))))
|
|
26
|
+
throw new BudgetSyntaxError();
|
|
27
|
+
let ms;
|
|
28
|
+
if (b.wallclock !== undefined) {
|
|
29
|
+
const match = typeof b.wallclock === 'string' && /^(\d+)(ms|s|m|h|d)$/.exec(b.wallclock);
|
|
30
|
+
if (!match)
|
|
31
|
+
throw new BudgetSyntaxError();
|
|
32
|
+
ms = Number(match[1]) * ({ ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 }[match[2]]);
|
|
33
|
+
if (!Number.isSafeInteger(ms))
|
|
34
|
+
throw new BudgetSyntaxError();
|
|
35
|
+
}
|
|
36
|
+
return { pricing: 'frozen', ...(b.tokens === undefined ? {} : { maxTokens: b.tokens }),
|
|
37
|
+
...(b.dollars === undefined ? {} : { maxDollars: String(b.dollars) }),
|
|
38
|
+
...(ms === undefined ? {} : { maxWallclockMs: ms }) };
|
|
39
|
+
}
|
|
40
|
+
/** Lower a normalized envelope to the existing kernel protocol. */
|
|
41
|
+
export function toKernelBudget(budget) {
|
|
42
|
+
return {
|
|
43
|
+
...(budget.pricing !== undefined ? { pricing: budget.pricing } : {}),
|
|
44
|
+
...(budget.maxTokens !== undefined ? { max_tokens: budget.maxTokens } : {}),
|
|
45
|
+
...(budget.maxWallclockMs !== undefined ? { max_wallclock_ms: budget.maxWallclockMs } : {}),
|
|
46
|
+
...(budget.window !== undefined ? { window: budget.window } : {}),
|
|
47
|
+
...(budget.maxTokensIn !== undefined ? { max_tokens_in: budget.maxTokensIn } : {}),
|
|
48
|
+
...(budget.maxTokensOut !== undefined ? { max_tokens_out: budget.maxTokensOut } : {}),
|
|
49
|
+
...(budget.maxDollars !== undefined ? { max_dollars: budget.maxDollars } : {}),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=budget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"budget.js","sourceRoot":"","sources":["../src/budget.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,gBAAgB,KAAK,CAAC,iGAAiG,CAAC,CAAC,CAAC,CAAC;CAC5H;AAED,6EAA6E;AAC7E,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,oCAAoC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/D,IAAI,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AU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC/E,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type BundleFailureKind = 'bucket_unconfigured' | 'bucket_unreachable' | 'bundle_missing_locally' | 'bundle_signature_invalid' | 'bundle_unsupported' | 'deploy_partial';
|
|
2
|
+
export declare class BundleFailure extends Error {
|
|
3
|
+
readonly kind: BundleFailureKind;
|
|
4
|
+
constructor(kind: BundleFailureKind, message: string);
|
|
5
|
+
}
|
|
6
|
+
export interface DigestReference {
|
|
7
|
+
name: string;
|
|
8
|
+
digest: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function parseDigestReference(value: string): DigestReference | undefined;
|
|
11
|
+
export declare function bucketDirectory(uri: string, ref: DigestReference): string;
|
|
12
|
+
export declare function exists(path: string): Promise<boolean>;
|
|
13
|
+
export declare function verifyDigest(directory: string, digest: string): Promise<void>;
|
|
14
|
+
/** Publish only a complete, verified directory. Concurrent identical writers converge. */
|
|
15
|
+
export declare function copyBundle(source: string, target: string, digest: string): Promise<boolean>;
|
|
16
|
+
export declare function writableBucket(target: string): Promise<void>;
|
|
17
|
+
export declare function fetchBundle(ref: DigestReference, bucket: string): Promise<string>;
|
|
18
|
+
//# sourceMappingURL=bundle-transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle-transport.d.ts","sourceRoot":"","sources":["../src/bundle-transport.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,iBAAiB,GAAG,qBAAqB,GAAG,oBAAoB,GACxE,wBAAwB,GAAG,0BAA0B,GAAG,oBAAoB,GAAG,gBAAgB,CAAC;AACpG,qBAAa,aAAc,SAAQ,KAAK;IAC1B,QAAQ,CAAC,IAAI,EAAE,iBAAiB;gBAAvB,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM;CAC9D;AACD,MAAM,WAAW,eAAe;IAAG,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE;AACjE,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAI/E;AACD,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,eAAe,GAAG,MAAM,CAUzE;AACD,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAG3D;AACD,wBAAsB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGnF;AACD,0FAA0F;AAC1F,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAejG;AACD,wBAAsB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAOlE;AACD,wBAAsB,WAAW,CAAC,GAAG,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAgBvF"}
|
|
@@ -0,0 +1,111 @@
|
|
|
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
|
+
export class BundleFailure extends Error {
|
|
8
|
+
kind;
|
|
9
|
+
constructor(kind, message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.kind = kind;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function parseDigestReference(value) {
|
|
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, ref) {
|
|
20
|
+
try {
|
|
21
|
+
const url = new URL(uri);
|
|
22
|
+
if (url.protocol !== 'file:' || url.search || url.hash)
|
|
23
|
+
throw new Error('expected file:// URI');
|
|
24
|
+
const path = fileURLToPath(url);
|
|
25
|
+
if (!isAbsolute(path))
|
|
26
|
+
throw new Error('expected absolute bucket path');
|
|
27
|
+
return join(path, ref.name, 'sha256', ref.digest);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
throw new BundleFailure('bucket_unreachable', 'This slice requires an absolute file:// bucket URI.');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export async function exists(path) {
|
|
34
|
+
try {
|
|
35
|
+
await lstat(path);
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (error.code === 'ENOENT')
|
|
40
|
+
return false;
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export async function verifyDigest(directory, digest) {
|
|
45
|
+
try {
|
|
46
|
+
await verifyBundle(directory, digest);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
throw new BundleFailure('bundle_signature_invalid', String(error));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** Publish only a complete, verified directory. Concurrent identical writers converge. */
|
|
53
|
+
export async function copyBundle(source, target, digest) {
|
|
54
|
+
if (await exists(target)) {
|
|
55
|
+
await verifyDigest(target, digest);
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
await mkdir(dirname(target), { recursive: true });
|
|
59
|
+
const staging = await mkdtemp(join(dirname(target), '.bundle-'));
|
|
60
|
+
try {
|
|
61
|
+
await cp(source, staging, { recursive: true, dereference: false, verbatimSymlinks: true });
|
|
62
|
+
await verifyDigest(staging, digest);
|
|
63
|
+
try {
|
|
64
|
+
await rename(staging, target);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
if (!['EEXIST', 'ENOTEMPTY'].includes(error.code ?? ''))
|
|
68
|
+
throw error;
|
|
69
|
+
await verifyDigest(target, digest);
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
await rm(staging, { recursive: true, force: true });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export async function writableBucket(target) {
|
|
79
|
+
try {
|
|
80
|
+
await mkdir(dirname(target), { recursive: true });
|
|
81
|
+
await access(dirname(target), constants.W_OK);
|
|
82
|
+
const probe = await mkdtemp(join(dirname(target), '.probe-'));
|
|
83
|
+
await rm(probe, { recursive: true });
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
throw new BundleFailure('bucket_unreachable', String(error));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export async function fetchBundle(ref, bucket) {
|
|
90
|
+
const cacheRoot = process.env['XDG_CACHE_HOME'];
|
|
91
|
+
const cache = join(cacheRoot && isAbsolute(cacheRoot) ? cacheRoot : join(homedir(), '.cache'), 'flows', 'bundles', ref.digest);
|
|
92
|
+
// Verify every hit; a corrupt cache never executes or silently falls back.
|
|
93
|
+
if (await exists(cache)) {
|
|
94
|
+
await verifyDigest(cache, ref.digest);
|
|
95
|
+
return cache;
|
|
96
|
+
}
|
|
97
|
+
const source = bucketDirectory(bucket, ref);
|
|
98
|
+
try {
|
|
99
|
+
if (!await exists(source))
|
|
100
|
+
throw new BundleFailure('bucket_unreachable', `Bundle is absent at ${bucket}.`);
|
|
101
|
+
await verifyDigest(source, ref.digest);
|
|
102
|
+
await copyBundle(source, cache, ref.digest);
|
|
103
|
+
return cache;
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
if (error instanceof BundleFailure)
|
|
107
|
+
throw error;
|
|
108
|
+
throw new BundleFailure('bucket_unreachable', String(error));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=bundle-transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle-transport.js","sourceRoot":"","sources":["../src/bundle-transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C,MAAM,OAAO,aAAc,SAAQ,KAAK;IACjB;IAArB,YAAqB,IAAuB,EAAE,OAAe;QAAI,KAAK,CAAC,OAAO,CAAC,CAAC;QAA3D,SAAI,GAAJ,IAAI,CAAmB;IAAqC,CAAC;CACnF;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,mEAAmE;IACnE,MAAM,KAAK,GAAG,sDAAsD,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACjF,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAE,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACpE,CAAC;AACD,MAAM,UAAU,eAAe,CAAC,GAAW,EAAE,GAAoB;IAC/D,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QACzB,IAAI,GAAG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C;IACf,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,aAAa;YAAE,MAAM,KAAK,CAAC;QAChD,MAAM,IAAI,aAAa,CAAC,oBAAoB,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { BundleFile } from './bundle.js';
|
|
2
|
+
export declare function buildTypescript(input: string): Promise<{
|
|
3
|
+
spec: import("./compile.js").CompiledFlowSpec;
|
|
4
|
+
authored: boolean;
|
|
5
|
+
compiler: string;
|
|
6
|
+
files: BundleFile[];
|
|
7
|
+
}>;
|
|
8
|
+
//# sourceMappingURL=bundle-typescript.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle-typescript.d.ts","sourceRoot":"","sources":["../src/bundle-typescript.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAc9C,wBAAsB,eAAe,CAAC,KAAK,EAAE,MAAM;;;;;GA6ClD"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
import { pathToFileURL } from 'node:url';
|
|
6
|
+
import { canonicalize } from './canonical.js';
|
|
7
|
+
import { compileSpec } from './compile.js';
|
|
8
|
+
/** Bun is an explicit build dependency, never an implicit install. */
|
|
9
|
+
function bun(args, cwd) {
|
|
10
|
+
const result = spawnSync('bun', ['--no-env-file', ...args], {
|
|
11
|
+
cwd, encoding: 'utf8', timeout: 120_000, maxBuffer: 16 * 1024 * 1024,
|
|
12
|
+
env: { PATH: process.env['PATH'], NODE_ENV: 'production', TZ: 'UTC' },
|
|
13
|
+
});
|
|
14
|
+
if (result.error || result.status !== 0) {
|
|
15
|
+
throw new Error(`TypeScript build requires Bun: ${result.error?.message ?? result.stderr}`);
|
|
16
|
+
}
|
|
17
|
+
return result.stdout.trim();
|
|
18
|
+
}
|
|
19
|
+
export async function buildTypescript(input) {
|
|
20
|
+
const directory = dirname(input);
|
|
21
|
+
const lockPath = await findLock(directory);
|
|
22
|
+
const lock = JSON.parse(await readFile(lockPath, 'utf8'));
|
|
23
|
+
if (![2, 3].includes(lock.lockfileVersion) || !lock.packages) {
|
|
24
|
+
throw new Error('package-lock.json: expected npm lockfile version 2 or 3 with pinned packages');
|
|
25
|
+
}
|
|
26
|
+
await checkInstalledVersions(dirname(lockPath), lock.packages);
|
|
27
|
+
const compiler = `bun@${bun(['--version'], directory)}`;
|
|
28
|
+
const staging = await mkdtemp(join(tmpdir(), 'flows-ts-'));
|
|
29
|
+
try {
|
|
30
|
+
// Evaluate module declarations, never the authored body. Resolve the runtime
|
|
31
|
+
// beside the input, keeping flow()'s WeakMap identity in the same module.
|
|
32
|
+
const probe = `
|
|
33
|
+
import { createRequire } from 'node:module';
|
|
34
|
+
import { pathToFileURL } from 'node:url';
|
|
35
|
+
const module = await import(${JSON.stringify(pathToFileURL(input).href)});
|
|
36
|
+
let spec = module.default;
|
|
37
|
+
let authored = false;
|
|
38
|
+
if (!spec || !Array.isArray(spec.steps)) {
|
|
39
|
+
const require = createRequire(${JSON.stringify(pathToFileURL(input).href)});
|
|
40
|
+
const { getFlowDefinition } = await import(pathToFileURL(require.resolve('@relayflows/surface/runtime')).href);
|
|
41
|
+
const definition = getFlowDefinition(spec);
|
|
42
|
+
if (Object.keys(definition.header).length) throw new Error('unsupported authored flow header');
|
|
43
|
+
if (!module.spec) throw new Error('authored flow() requires an exported spec declaration for build-time preflight; the body is not executed during build');
|
|
44
|
+
spec = module.spec;
|
|
45
|
+
if (spec.name !== definition.name) throw new Error('exported spec name must match flow() name');
|
|
46
|
+
authored = true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
process.stdout.write(JSON.stringify({ spec, authored }));
|
|
50
|
+
`;
|
|
51
|
+
const probePath = join(staging, 'inspect.ts');
|
|
52
|
+
await writeFile(probePath, probe);
|
|
53
|
+
const inspected = JSON.parse(bun([probePath], directory));
|
|
54
|
+
const spec = compileSpec(inspected.spec);
|
|
55
|
+
const executable = join(staging, 'flow');
|
|
56
|
+
bun(['build', '--compile', '--env=disable', '--no-compile-autoload-dotenv',
|
|
57
|
+
'--no-compile-autoload-bunfig', '--outfile', executable, input], directory);
|
|
58
|
+
const files = [
|
|
59
|
+
{ path: 'flow', data: await readFile(executable) },
|
|
60
|
+
{ path: 'lockfile.json', data: canonicalize(lock) },
|
|
61
|
+
];
|
|
62
|
+
return { spec, authored: inspected.authored === true, compiler, files };
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
await rm(staging, { recursive: true, force: true });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** Do not label a stale node_modules tree with a newer lockfile's pins. */
|
|
69
|
+
async function checkInstalledVersions(root, packages) {
|
|
70
|
+
for (const [path, entry] of Object.entries(packages)) {
|
|
71
|
+
if (path === '')
|
|
72
|
+
continue;
|
|
73
|
+
if (path.startsWith('/') || path.includes('\\') || path.split('/').includes('..')
|
|
74
|
+
|| (entry.resolved !== undefined && /^(?:file:|\/|[A-Za-z]:)/.test(entry.resolved))) {
|
|
75
|
+
throw new Error(`package-lock.json: ${path} must use portable, pinned dependency locations`);
|
|
76
|
+
}
|
|
77
|
+
if (entry.link)
|
|
78
|
+
continue; // Workspace source is captured by the compiler.
|
|
79
|
+
let installed;
|
|
80
|
+
try {
|
|
81
|
+
installed = JSON.parse(await readFile(join(root, path, 'package.json'), 'utf8'));
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
if (error.code === 'ENOENT' && (entry.optional || entry.dev))
|
|
85
|
+
continue;
|
|
86
|
+
throw new Error(`package-lock.json: ${path} is missing; run npm ci before building`);
|
|
87
|
+
}
|
|
88
|
+
if (typeof entry.version !== 'string' || installed.version !== entry.version) {
|
|
89
|
+
throw new Error(`package-lock.json: ${path} does not match its pinned version; run npm ci before building`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async function findLock(start) {
|
|
94
|
+
for (let directory = start;; directory = dirname(directory)) {
|
|
95
|
+
const candidate = join(directory, 'package-lock.json');
|
|
96
|
+
try {
|
|
97
|
+
await readFile(candidate);
|
|
98
|
+
return candidate;
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
if (error.code !== 'ENOENT')
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
if (dirname(directory) === directory)
|
|
105
|
+
throw new Error('package-lock.json: no workspace lockfile found for TS flow');
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=bundle-typescript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle-typescript.js","sourceRoot":"","sources":["../src/bundle-typescript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG3C,sEAAsE;AACtE,SAAS,GAAG,CAAC,IAAc,EAAE,GAAW;IACtC,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,EAAE,CAAC,eAAe,EAAE,GAAG,IAAI,CAAC,EAAE;QAC1D,GAAG,EAAE,QAAQ,EAAE,MAAM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;IACH,CAAC;AACH,CAAC;AACD,KAAK,UAAU,QAAQ,CAAC,KAAa;IACnC,KAAK,IAAI,SAAS,GAAG,KAAK,GAAI,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QAC7D,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;QACvD,IAAI,CAAC;YAAC,MAAM,QAAQ,CAAC,SAAS,CAAC,CAAC;YAAC,OAAO,SAAS,CAAC;QAAC,CAAC;QACpD,OAAO,KAAK,EAAE,CAAC;YAAC,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;gBAAE,MAAM,KAAK,CAAC;QAAC,CAAC;QACtF,IAAI,OAAO,CAAC,SAAS,CAAC,KAAK,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;IACtH,CAAC;AACH,CAAC"}
|
package/dist/bundle.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface BundleEntry {
|
|
2
|
+
path: string;
|
|
3
|
+
sha256: string;
|
|
4
|
+
bytes: number;
|
|
5
|
+
}
|
|
6
|
+
export interface BundleFile {
|
|
7
|
+
path: string;
|
|
8
|
+
data: Uint8Array | string;
|
|
9
|
+
executable?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface BundleOptions {
|
|
12
|
+
name: string;
|
|
13
|
+
out: string;
|
|
14
|
+
repo: string;
|
|
15
|
+
files: BundleFile[];
|
|
16
|
+
env?: NodeJS.ProcessEnv;
|
|
17
|
+
warn(message: string): void;
|
|
18
|
+
}
|
|
19
|
+
export declare function sha256(data: Uint8Array | string): string;
|
|
20
|
+
/** Manifest and identity are envelopes, excluded to avoid circular hashing. */
|
|
21
|
+
export declare function sealBundle(options: BundleOptions): Promise<string>;
|
|
22
|
+
/** Verify an untrusted directory without following symlinks or manifest traversal.
|
|
23
|
+
* Bucket/cache readers supply the requested digest; local builds bind it to the directory name. */
|
|
24
|
+
export declare function verifyBundle(directory: string, expectedDigest?: string): Promise<string>;
|
|
25
|
+
//# sourceMappingURL=bundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,WAAW;IAAG,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE;AAC5E,MAAM,WAAW,UAAU;IAAG,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE;AAC7F,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,CAExD;AAQD,+EAA+E;AAC/E,wBAAsB,UAAU,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CA2CxE;AA4CD;mGACmG;AACnG,wBAAsB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAsD9F"}
|