@codespar/cli 0.14.0 → 0.16.0
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/README.md +44 -17
- package/dist/commands/audit-replay.js +267 -0
- package/dist/commands/audit-replay.js.map +1 -0
- package/dist/commands/init.js +28 -0
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/login.js +2 -1
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/mandate-verify.js +75 -27
- package/dist/commands/mandate-verify.js.map +1 -1
- package/dist/config.js +17 -1
- package/dist/config.js.map +1 -1
- package/dist/did.js +262 -41
- package/dist/did.js.map +1 -1
- package/dist/index.js +33 -7
- package/dist/index.js.map +1 -1
- package/dist/surface.js +4 -1
- package/dist/surface.js.map +1 -1
- package/package.json +1 -1
- package/templates/bills-agent/README.md +8 -5
- package/templates/bills-agent/agents/bills-agent/.env.example +3 -3
- package/templates/bills-agent/agents/bills-agent/AGENTS.md +1 -1
- package/templates/bills-agent/agents/bills-agent/CLAUDE.md +1 -1
- package/templates/bills-agent/agents/bills-agent/README.md +62 -22
- package/templates/bills-agent/agents/bills-agent/SYSTEM_PROMPT.md +1 -1
- package/templates/bills-agent/agents/bills-agent/agent.yaml +2 -2
- package/templates/bills-agent/agents/bills-agent/package.json +14 -11
- package/templates/bills-agent/agents/bills-agent/src/kit.ts +193 -0
- package/templates/bills-agent/agents/bills-agent/test/adversarial.test.ts +8 -7
- package/templates/bills-agent/agents/bills-agent/test/check.test.ts +19 -2
- package/templates/bills-agent/agents/bills-agent/test/cli.test.ts +72 -24
- package/templates/bills-agent/agents/bills-agent/test/fixtures/excursao-300.transcript.jsonl +2 -0
- package/templates/bills-agent/agents/bills-agent/test/fixtures/material-400.transcript.jsonl +2 -0
- package/templates/bills-agent/agents/bills-agent/test/inspect.test.ts +124 -0
- package/templates/bills-agent/agents/bills-agent/test/provider.test.ts +25 -0
- package/templates/bills-agent/agents/bills-agent/test/scenarios.test.ts +10 -9
- package/templates/bills-agent/agents/bills-agent/tsconfig.json +0 -1
- package/templates/bills-agent/package.json +5 -2
- package/templates/bills-agent/packages/agent-core/README.md +2 -0
- package/templates/bills-agent/packages/agent-core/package.json +1 -1
- package/templates/bills-agent/packages/agent-core/src/api/charge-rail.ts +27 -6
- package/templates/bills-agent/packages/agent-core/src/api/rail.ts +16 -0
- package/templates/bills-agent/packages/agent-core/src/api/sandbox-payer.ts +20 -7
- package/templates/bills-agent/packages/agent-core/src/approval.ts +16 -2
- package/templates/bills-agent/packages/agent-core/src/bundle.ts +50 -4
- package/templates/bills-agent/packages/agent-core/src/channels.ts +140 -0
- package/templates/bills-agent/packages/agent-core/src/check.ts +90 -8
- package/templates/bills-agent/packages/agent-core/src/clock.ts +42 -0
- package/templates/bills-agent/packages/agent-core/src/engine.ts +119 -18
- package/templates/bills-agent/packages/agent-core/src/hash.ts +13 -0
- package/templates/bills-agent/packages/agent-core/src/index.ts +3 -0
- package/templates/bills-agent/packages/agent-core/src/manifest.ts +1 -1
- package/templates/bills-agent/packages/agent-core/src/rail.ts +16 -2
- package/templates/bills-agent/packages/agent-core/src/receipt-verification.ts +401 -0
- package/templates/bills-agent/packages/agent-core/src/state-machine.ts +3 -1
- package/templates/bills-agent/packages/agent-core/src/stubs/charge-rail.ts +2 -0
- package/templates/bills-agent/packages/agent-core/src/stubs/rail.ts +19 -2
- package/templates/bills-agent/packages/agent-core/src/types.ts +28 -0
- package/templates/bills-agent/packages/agent-core/test/approval.test.ts +36 -2
- package/templates/bills-agent/packages/agent-core/test/bundle.test.ts +85 -0
- package/templates/bills-agent/packages/agent-core/test/clock.test.ts +25 -0
- package/templates/bills-agent/packages/agent-core/test/engine.test.ts +73 -1
- package/templates/bills-agent/packages/agent-core/test/fixtures/staging-receipt-keys.json +18 -0
- package/templates/bills-agent/packages/agent-core/test/fixtures/staging-receipt.json +24 -0
- package/templates/bills-agent/packages/agent-core/test/helpers.ts +1 -1
- package/templates/bills-agent/packages/agent-core/test/manifest.test.ts +2 -2
- package/templates/bills-agent/packages/agent-core/test/receipt-verification.test.ts +316 -0
- package/templates/bills-agent/packages/agent-core/test/receivables.test.ts +51 -0
- package/templates/bills-agent/packages/agent-runtime/README.md +68 -0
- package/templates/bills-agent/packages/agent-runtime/bin.mjs +32 -0
- package/templates/bills-agent/packages/agent-runtime/package.json +23 -0
- package/templates/bills-agent/{agents/bills-agent → packages/agent-runtime}/src/adversarial.ts +36 -44
- package/templates/bills-agent/packages/agent-runtime/src/agent.ts +68 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/contact.ts +13 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/index.ts +72 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/rules.ts +120 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/types.ts +124 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/cloud-api.ts +358 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +206 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/evidence.ts +109 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +225 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +143 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +47 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +113 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +113 -0
- package/templates/bills-agent/packages/agent-runtime/src/cli.ts +98 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/check.ts +15 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/decide.ts +63 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/eval.ts +58 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/inspect.ts +100 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +317 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/poll.ts +144 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/reconcile.ts +42 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/rerun.ts +86 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/resume.ts +43 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +131 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/start.ts +245 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/verify.ts +129 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/webhook.ts +39 -0
- package/templates/bills-agent/packages/agent-runtime/src/default-kit.ts +83 -0
- package/templates/bills-agent/packages/agent-runtime/src/index.ts +12 -0
- package/templates/bills-agent/packages/agent-runtime/src/inspect.ts +797 -0
- package/templates/bills-agent/packages/agent-runtime/src/kit.ts +206 -0
- package/templates/{collections-agent/agents/collections-agent → bills-agent/packages/agent-runtime}/src/poll.ts +22 -11
- package/templates/{collections-agent/agents/collections-agent → bills-agent/packages/agent-runtime}/src/scenarios.ts +50 -34
- package/templates/bills-agent/{agents/bills-agent → packages/agent-runtime}/src/setup.ts +88 -66
- package/templates/bills-agent/packages/agent-runtime/src/terminal.ts +154 -0
- package/templates/{collections-agent/agents/collections-agent/channels/webhook/index.ts → bills-agent/packages/agent-runtime/src/webhook.ts} +1 -1
- package/templates/bills-agent/packages/agent-runtime/test/inspect.test.ts +336 -0
- package/templates/bills-agent/packages/agent-runtime/test/verify-cli.test.ts +127 -0
- package/templates/bills-agent/packages/agent-runtime/test/whatsapp-cloud-api.test.ts +232 -0
- package/templates/bills-agent/packages/agent-runtime/test/whatsapp-emulator.integration.test.ts +204 -0
- package/templates/bills-agent/packages/agent-runtime/test/whatsapp-evidence.test.ts +94 -0
- package/templates/bills-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +174 -0
- package/templates/bills-agent/packages/agent-runtime/test/whatsapp-session.test.ts +135 -0
- package/templates/bills-agent/packages/agent-runtime/tsconfig.json +9 -0
- package/templates/bills-agent/vitest.config.ts +1 -1
- package/templates/collections-agent/README.md +8 -5
- package/templates/collections-agent/agents/collections-agent/.env.example +14 -0
- package/templates/collections-agent/agents/collections-agent/AGENTS.md +6 -4
- package/templates/collections-agent/agents/collections-agent/CLAUDE.md +6 -4
- package/templates/collections-agent/agents/collections-agent/README.md +184 -16
- package/templates/collections-agent/agents/collections-agent/agent.yaml +3 -3
- package/templates/collections-agent/agents/collections-agent/channels/whatsapp/README.md +111 -0
- package/templates/collections-agent/agents/collections-agent/channels/whatsapp/acordo-1042.json +11 -0
- package/templates/collections-agent/agents/collections-agent/channels/whatsapp/acordo-1103.json +11 -0
- package/templates/collections-agent/agents/collections-agent/channels/whatsapp/templates.json +23 -0
- package/templates/collections-agent/agents/collections-agent/package.json +12 -10
- package/templates/collections-agent/agents/collections-agent/runbook.md +52 -1
- package/templates/collections-agent/agents/collections-agent/src/kit.ts +265 -0
- package/templates/collections-agent/agents/collections-agent/test/adversarial.test.ts +9 -8
- package/templates/collections-agent/agents/collections-agent/test/check.test.ts +43 -1
- package/templates/collections-agent/agents/collections-agent/test/cli.test.ts +56 -18
- package/templates/collections-agent/agents/collections-agent/test/fixtures/agreed-1042-awaiting-payer.transcript.jsonl +4 -0
- package/templates/collections-agent/agents/collections-agent/test/scenarios.test.ts +11 -10
- package/templates/collections-agent/agents/collections-agent/test/webhook.test.ts +4 -7
- package/templates/collections-agent/agents/collections-agent/test/whatsapp-poll.test.ts +271 -0
- package/templates/collections-agent/agents/collections-agent/test/whatsapp.test.ts +213 -0
- package/templates/collections-agent/agents/collections-agent/tsconfig.json +0 -1
- package/templates/collections-agent/package.json +3 -1
- package/templates/collections-agent/packages/agent-core/README.md +2 -0
- package/templates/collections-agent/packages/agent-core/package.json +1 -1
- package/templates/collections-agent/packages/agent-core/src/api/charge-rail.ts +27 -6
- package/templates/collections-agent/packages/agent-core/src/api/rail.ts +16 -0
- package/templates/collections-agent/packages/agent-core/src/api/sandbox-payer.ts +20 -7
- package/templates/collections-agent/packages/agent-core/src/approval.ts +16 -2
- package/templates/collections-agent/packages/agent-core/src/bundle.ts +50 -4
- package/templates/collections-agent/packages/agent-core/src/channels.ts +140 -0
- package/templates/collections-agent/packages/agent-core/src/check.ts +90 -8
- package/templates/collections-agent/packages/agent-core/src/clock.ts +42 -0
- package/templates/collections-agent/packages/agent-core/src/engine.ts +119 -18
- package/templates/collections-agent/packages/agent-core/src/hash.ts +13 -0
- package/templates/collections-agent/packages/agent-core/src/index.ts +3 -0
- package/templates/collections-agent/packages/agent-core/src/manifest.ts +1 -1
- package/templates/collections-agent/packages/agent-core/src/rail.ts +16 -2
- package/templates/collections-agent/packages/agent-core/src/receipt-verification.ts +401 -0
- package/templates/collections-agent/packages/agent-core/src/state-machine.ts +3 -1
- package/templates/collections-agent/packages/agent-core/src/stubs/charge-rail.ts +2 -0
- package/templates/collections-agent/packages/agent-core/src/stubs/rail.ts +19 -2
- package/templates/collections-agent/packages/agent-core/src/types.ts +28 -0
- package/templates/collections-agent/packages/agent-core/test/approval.test.ts +36 -2
- package/templates/collections-agent/packages/agent-core/test/bundle.test.ts +85 -0
- package/templates/collections-agent/packages/agent-core/test/clock.test.ts +25 -0
- package/templates/collections-agent/packages/agent-core/test/engine.test.ts +73 -1
- package/templates/collections-agent/packages/agent-core/test/fixtures/staging-receipt-keys.json +18 -0
- package/templates/collections-agent/packages/agent-core/test/fixtures/staging-receipt.json +24 -0
- package/templates/collections-agent/packages/agent-core/test/helpers.ts +1 -1
- package/templates/collections-agent/packages/agent-core/test/manifest.test.ts +2 -2
- package/templates/collections-agent/packages/agent-core/test/receipt-verification.test.ts +316 -0
- package/templates/collections-agent/packages/agent-core/test/receivables.test.ts +51 -0
- package/templates/collections-agent/packages/agent-runtime/README.md +68 -0
- package/templates/collections-agent/packages/agent-runtime/bin.mjs +32 -0
- package/templates/collections-agent/packages/agent-runtime/package.json +23 -0
- package/templates/collections-agent/{agents/collections-agent → packages/agent-runtime}/src/adversarial.ts +29 -50
- package/templates/collections-agent/packages/agent-runtime/src/agent.ts +68 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/contact.ts +13 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/index.ts +72 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/rules.ts +120 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/types.ts +124 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/cloud-api.ts +358 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +206 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/evidence.ts +109 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +225 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +143 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +47 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +113 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +113 -0
- package/templates/collections-agent/packages/agent-runtime/src/cli.ts +98 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/check.ts +15 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/decide.ts +63 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/eval.ts +58 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/inspect.ts +100 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +317 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/poll.ts +144 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/reconcile.ts +42 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/rerun.ts +86 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/resume.ts +43 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +131 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/start.ts +245 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/verify.ts +129 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/webhook.ts +39 -0
- package/templates/collections-agent/packages/agent-runtime/src/default-kit.ts +83 -0
- package/templates/collections-agent/packages/agent-runtime/src/index.ts +12 -0
- package/templates/collections-agent/packages/agent-runtime/src/inspect.ts +797 -0
- package/templates/collections-agent/packages/agent-runtime/src/kit.ts +206 -0
- package/templates/collections-agent/packages/agent-runtime/src/poll.ts +105 -0
- package/templates/{bills-agent/agents/bills-agent → collections-agent/packages/agent-runtime}/src/scenarios.ts +98 -26
- package/templates/collections-agent/packages/agent-runtime/src/setup.ts +229 -0
- package/templates/collections-agent/packages/agent-runtime/src/terminal.ts +154 -0
- package/templates/collections-agent/packages/agent-runtime/src/webhook.ts +131 -0
- package/templates/collections-agent/packages/agent-runtime/test/inspect.test.ts +336 -0
- package/templates/collections-agent/packages/agent-runtime/test/verify-cli.test.ts +127 -0
- package/templates/collections-agent/packages/agent-runtime/test/whatsapp-cloud-api.test.ts +232 -0
- package/templates/collections-agent/packages/agent-runtime/test/whatsapp-emulator.integration.test.ts +204 -0
- package/templates/collections-agent/packages/agent-runtime/test/whatsapp-evidence.test.ts +94 -0
- package/templates/collections-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +174 -0
- package/templates/collections-agent/packages/agent-runtime/test/whatsapp-session.test.ts +135 -0
- package/templates/collections-agent/packages/agent-runtime/tsconfig.json +9 -0
- package/templates/collections-agent/vitest.config.ts +1 -1
- package/templates/hello-agent/LICENSE +21 -0
- package/templates/hello-agent/README.md +23 -0
- package/templates/hello-agent/_gitignore +10 -0
- package/templates/hello-agent/agents/hello-agent/.env.example +5 -0
- package/templates/hello-agent/agents/hello-agent/AGENTS.md +15 -0
- package/templates/hello-agent/agents/hello-agent/CLAUDE.md +15 -0
- package/templates/hello-agent/agents/hello-agent/README.md +33 -0
- package/templates/hello-agent/agents/hello-agent/SYSTEM_PROMPT.md +19 -0
- package/templates/hello-agent/agents/hello-agent/agent.yaml +19 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/beneficiary-swap.json +6 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/beneficiary-swap.transcript.jsonl +2 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/exfiltration.json +6 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/exfiltration.transcript.jsonl +2 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/false-authority.json +6 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/false-authority.transcript.jsonl +2 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/fractioning.json +6 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/fractioning.transcript.jsonl +2 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/model-total.json +6 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/model-total.transcript.jsonl +2 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/prompt-injection.json +6 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/prompt-injection.transcript.jsonl +2 -0
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/webhook-replay.json +6 -0
- package/templates/hello-agent/agents/hello-agent/evals/eval.yaml +7 -0
- package/templates/hello-agent/agents/hello-agent/guardrails.json +8 -0
- package/templates/hello-agent/agents/hello-agent/mandate.example.json +17 -0
- package/templates/hello-agent/agents/hello-agent/package.json +19 -0
- package/templates/hello-agent/agents/hello-agent/runbook.md +10 -0
- package/templates/hello-agent/agents/hello-agent/scenarios/happy-path.json +6 -0
- package/templates/hello-agent/agents/hello-agent/scenarios/happy-path.transcript.jsonl +2 -0
- package/templates/hello-agent/agents/hello-agent/scenarios/prompt-injection.json +6 -0
- package/templates/hello-agent/agents/hello-agent/scenarios/prompt-injection.transcript.jsonl +2 -0
- package/templates/hello-agent/agents/hello-agent/src/bills.ts +23 -0
- package/templates/hello-agent/agents/hello-agent/src/kit.ts +33 -0
- package/templates/hello-agent/agents/hello-agent/tools.json +11 -0
- package/templates/hello-agent/agents/hello-agent/tsconfig.json +9 -0
- package/templates/hello-agent/package.json +30 -0
- package/templates/hello-agent/packages/agent-core/README.md +21 -0
- package/templates/hello-agent/packages/agent-core/package.json +24 -0
- package/templates/hello-agent/packages/agent-core/src/agent.ts +125 -0
- package/templates/hello-agent/packages/agent-core/src/api/charge-rail.ts +175 -0
- package/templates/hello-agent/packages/agent-core/src/api/client.ts +53 -0
- package/templates/hello-agent/packages/agent-core/src/api/mandate-status.ts +58 -0
- package/templates/hello-agent/packages/agent-core/src/api/rail.ts +117 -0
- package/templates/hello-agent/packages/agent-core/src/api/sandbox-payer.ts +58 -0
- package/templates/hello-agent/packages/agent-core/src/approval.ts +123 -0
- package/templates/hello-agent/packages/agent-core/src/bundle.ts +159 -0
- package/templates/hello-agent/packages/agent-core/src/channels.ts +140 -0
- package/templates/hello-agent/packages/agent-core/src/check.ts +253 -0
- package/templates/hello-agent/packages/agent-core/src/clock.ts +42 -0
- package/templates/hello-agent/packages/agent-core/src/engine.ts +885 -0
- package/templates/hello-agent/packages/agent-core/src/escalate.ts +85 -0
- package/templates/hello-agent/packages/agent-core/src/events.ts +40 -0
- package/templates/hello-agent/packages/agent-core/src/guardrails.ts +45 -0
- package/templates/hello-agent/packages/agent-core/src/hash.ts +62 -0
- package/templates/hello-agent/packages/agent-core/src/ids.ts +10 -0
- package/templates/hello-agent/packages/agent-core/src/index.ts +32 -0
- package/templates/hello-agent/packages/agent-core/src/mandate.ts +100 -0
- package/templates/hello-agent/packages/agent-core/src/manifest.ts +76 -0
- package/templates/hello-agent/packages/agent-core/src/providers/anthropic.ts +76 -0
- package/templates/hello-agent/packages/agent-core/src/providers/replay.ts +63 -0
- package/templates/hello-agent/packages/agent-core/src/providers/types.ts +39 -0
- package/templates/hello-agent/packages/agent-core/src/rail.ts +101 -0
- package/templates/hello-agent/packages/agent-core/src/receipt-verification.ts +401 -0
- package/templates/hello-agent/packages/agent-core/src/revocation.ts +30 -0
- package/templates/hello-agent/packages/agent-core/src/secrets.ts +30 -0
- package/templates/hello-agent/packages/agent-core/src/state/store.ts +307 -0
- package/templates/hello-agent/packages/agent-core/src/state-machine.ts +148 -0
- package/templates/hello-agent/packages/agent-core/src/stubs/charge-rail.ts +195 -0
- package/templates/hello-agent/packages/agent-core/src/stubs/mandate-status.ts +57 -0
- package/templates/hello-agent/packages/agent-core/src/stubs/rail.ts +141 -0
- package/templates/hello-agent/packages/agent-core/src/tools.ts +55 -0
- package/templates/hello-agent/packages/agent-core/src/types.ts +134 -0
- package/templates/hello-agent/packages/agent-core/test/approval.test.ts +117 -0
- package/templates/hello-agent/packages/agent-core/test/bundle.test.ts +85 -0
- package/templates/hello-agent/packages/agent-core/test/clock.test.ts +25 -0
- package/templates/hello-agent/packages/agent-core/test/engine.test.ts +596 -0
- package/templates/hello-agent/packages/agent-core/test/escalate.test.ts +42 -0
- package/templates/hello-agent/packages/agent-core/test/fixtures/staging-receipt-keys.json +18 -0
- package/templates/hello-agent/packages/agent-core/test/fixtures/staging-receipt.json +24 -0
- package/templates/hello-agent/packages/agent-core/test/helpers.ts +139 -0
- package/templates/hello-agent/packages/agent-core/test/mandate-status.test.ts +153 -0
- package/templates/hello-agent/packages/agent-core/test/manifest.test.ts +45 -0
- package/templates/hello-agent/packages/agent-core/test/receipt-verification.test.ts +316 -0
- package/templates/hello-agent/packages/agent-core/test/receivables.test.ts +316 -0
- package/templates/hello-agent/packages/agent-core/test/secrets.test.ts +28 -0
- package/templates/hello-agent/packages/agent-core/test/state-machine.test.ts +67 -0
- package/templates/hello-agent/packages/agent-core/test/transitions.type-test.ts +59 -0
- package/templates/hello-agent/packages/agent-core/tsconfig.json +10 -0
- package/templates/hello-agent/packages/agent-runtime/README.md +68 -0
- package/templates/hello-agent/packages/agent-runtime/bin.mjs +32 -0
- package/templates/hello-agent/packages/agent-runtime/package.json +23 -0
- package/templates/hello-agent/packages/agent-runtime/src/adversarial.ts +169 -0
- package/templates/hello-agent/packages/agent-runtime/src/agent.ts +68 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/contact.ts +13 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/index.ts +72 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/rules.ts +120 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/types.ts +124 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/cloud-api.ts +358 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +206 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/evidence.ts +109 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +225 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +143 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +47 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +113 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +113 -0
- package/templates/hello-agent/packages/agent-runtime/src/cli.ts +98 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/check.ts +15 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/decide.ts +63 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/eval.ts +58 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/inspect.ts +100 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +317 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/poll.ts +144 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/reconcile.ts +42 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/rerun.ts +86 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/resume.ts +43 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +131 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/start.ts +245 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/verify.ts +129 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/webhook.ts +39 -0
- package/templates/hello-agent/packages/agent-runtime/src/default-kit.ts +83 -0
- package/templates/hello-agent/packages/agent-runtime/src/index.ts +12 -0
- package/templates/hello-agent/packages/agent-runtime/src/inspect.ts +797 -0
- package/templates/hello-agent/packages/agent-runtime/src/kit.ts +206 -0
- package/templates/hello-agent/packages/agent-runtime/src/poll.ts +105 -0
- package/templates/hello-agent/packages/agent-runtime/src/scenarios.ts +268 -0
- package/templates/hello-agent/packages/agent-runtime/src/setup.ts +229 -0
- package/templates/hello-agent/packages/agent-runtime/src/terminal.ts +154 -0
- package/templates/hello-agent/packages/agent-runtime/src/webhook.ts +131 -0
- package/templates/hello-agent/packages/agent-runtime/test/inspect.test.ts +336 -0
- package/templates/hello-agent/packages/agent-runtime/test/verify-cli.test.ts +127 -0
- package/templates/hello-agent/packages/agent-runtime/test/whatsapp-cloud-api.test.ts +232 -0
- package/templates/hello-agent/packages/agent-runtime/test/whatsapp-emulator.integration.test.ts +204 -0
- package/templates/hello-agent/packages/agent-runtime/test/whatsapp-evidence.test.ts +94 -0
- package/templates/hello-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +174 -0
- package/templates/hello-agent/packages/agent-runtime/test/whatsapp-session.test.ts +135 -0
- package/templates/hello-agent/packages/agent-runtime/tsconfig.json +9 -0
- package/templates/hello-agent/tsconfig.base.json +16 -0
- package/templates/hello-agent/vitest.config.ts +12 -0
- package/templates/kits.lock.json +60 -12
- package/templates/supplier-payments-agent/LICENSE +21 -0
- package/templates/supplier-payments-agent/README.md +23 -0
- package/templates/supplier-payments-agent/_gitignore +10 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/.env.example +7 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/AGENTS.md +21 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/CLAUDE.md +21 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/README.md +118 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/SYSTEM_PROMPT.md +29 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/agent.yaml +26 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/batch-tampering.json +12 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/batch-tampering.transcript.jsonl +3 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/beneficiary-swap-mandate.json +9 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/beneficiary-swap.json +10 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/beneficiary-swap.transcript.jsonl +2 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/exfiltration.json +13 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/exfiltration.transcript.jsonl +3 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/false-authority.json +9 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/false-authority.transcript.jsonl +3 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/fractioning.json +15 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/fractioning.transcript.jsonl +6 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/model-total.json +10 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/model-total.transcript.jsonl +2 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/prompt-injection.json +9 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/prompt-injection.transcript.jsonl +2 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/webhook-replay.json +9 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/eval.yaml +9 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/guardrails.json +15 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/mandate.example.json +70 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/package.json +26 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/runbook.md +19 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/beneficiary-not-allowed.json +14 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/beneficiary-not-allowed.transcript.jsonl +2 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/cap-exceeded.json +12 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/cap-exceeded.transcript.jsonl +2 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/escalated-above-threshold.json +20 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/escalated-above-threshold.transcript.jsonl +7 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/happy-path.json +19 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/happy-path.transcript.jsonl +3 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/mandate-revoked.json +21 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/mandate-revoked.transcript.jsonl +9 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/partial-batch-failure.json +21 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/partial-batch-failure.transcript.jsonl +3 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/prompt-injection.json +12 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/prompt-injection.transcript.jsonl +2 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/src/kit.ts +176 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/src/modules/batch-payout.ts +345 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/src/modules/pix-out.ts +118 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/src/payables.ts +76 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/test/adversarial.test.ts +53 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/test/batch.test.ts +384 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/test/check.test.ts +109 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/test/scenarios.test.ts +81 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/tools.json +53 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/tsconfig.json +9 -0
- package/templates/supplier-payments-agent/package.json +36 -0
- package/templates/supplier-payments-agent/packages/agent-core/README.md +21 -0
- package/templates/supplier-payments-agent/packages/agent-core/package.json +24 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/agent.ts +125 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/api/charge-rail.ts +175 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/api/client.ts +53 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/api/mandate-status.ts +58 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/api/rail.ts +117 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/api/sandbox-payer.ts +58 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/approval.ts +123 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/bundle.ts +159 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/channels.ts +140 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/check.ts +253 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/clock.ts +42 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/engine.ts +885 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/escalate.ts +85 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/events.ts +40 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/guardrails.ts +45 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/hash.ts +62 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/ids.ts +10 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/index.ts +32 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/mandate.ts +100 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/manifest.ts +76 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/providers/anthropic.ts +76 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/providers/replay.ts +63 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/providers/types.ts +39 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/rail.ts +101 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/receipt-verification.ts +401 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/revocation.ts +30 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/secrets.ts +30 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/state/store.ts +307 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/state-machine.ts +148 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/stubs/charge-rail.ts +195 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/stubs/mandate-status.ts +57 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/stubs/rail.ts +141 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/tools.ts +55 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/types.ts +134 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/approval.test.ts +117 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/bundle.test.ts +85 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/clock.test.ts +25 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/engine.test.ts +596 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/escalate.test.ts +42 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/fixtures/staging-receipt-keys.json +18 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/fixtures/staging-receipt.json +24 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/helpers.ts +139 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/mandate-status.test.ts +153 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/manifest.test.ts +45 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/receipt-verification.test.ts +316 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/receivables.test.ts +316 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/secrets.test.ts +28 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/state-machine.test.ts +67 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/transitions.type-test.ts +59 -0
- package/templates/supplier-payments-agent/packages/agent-core/tsconfig.json +10 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/README.md +68 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/bin.mjs +32 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/package.json +23 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/adversarial.ts +169 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/agent.ts +68 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/contact.ts +13 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/index.ts +72 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/rules.ts +120 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/types.ts +124 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/cloud-api.ts +358 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +206 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/evidence.ts +109 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +225 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +143 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +47 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +113 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +113 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/cli.ts +98 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/check.ts +15 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/decide.ts +63 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/eval.ts +58 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/inspect.ts +100 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +317 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/poll.ts +144 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/reconcile.ts +42 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/rerun.ts +86 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/resume.ts +43 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +131 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/start.ts +245 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/verify.ts +129 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/webhook.ts +39 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/default-kit.ts +83 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/index.ts +12 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/inspect.ts +797 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/kit.ts +206 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/poll.ts +105 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/scenarios.ts +268 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/setup.ts +229 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/terminal.ts +154 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/webhook.ts +131 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/inspect.test.ts +336 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/verify-cli.test.ts +127 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/whatsapp-cloud-api.test.ts +232 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/whatsapp-emulator.integration.test.ts +204 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/whatsapp-evidence.test.ts +94 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +174 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/whatsapp-session.test.ts +135 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/tsconfig.json +9 -0
- package/templates/supplier-payments-agent/tsconfig.base.json +16 -0
- package/templates/supplier-payments-agent/vitest.config.ts +12 -0
- package/templates/bills-agent/agents/bills-agent/channels/terminal/index.ts +0 -108
- package/templates/bills-agent/agents/bills-agent/src/commands/approve.ts +0 -9
- package/templates/bills-agent/agents/bills-agent/src/commands/check.ts +0 -13
- package/templates/bills-agent/agents/bills-agent/src/commands/consent.ts +0 -26
- package/templates/bills-agent/agents/bills-agent/src/commands/decide.ts +0 -45
- package/templates/bills-agent/agents/bills-agent/src/commands/deny.ts +0 -7
- package/templates/bills-agent/agents/bills-agent/src/commands/eval.ts +0 -37
- package/templates/bills-agent/agents/bills-agent/src/commands/reconcile.ts +0 -38
- package/templates/bills-agent/agents/bills-agent/src/commands/rerun.ts +0 -65
- package/templates/bills-agent/agents/bills-agent/src/commands/resume.ts +0 -30
- package/templates/bills-agent/agents/bills-agent/src/main.ts +0 -185
- package/templates/collections-agent/agents/collections-agent/channels/terminal/index.ts +0 -178
- package/templates/collections-agent/agents/collections-agent/src/commands/approve.ts +0 -10
- package/templates/collections-agent/agents/collections-agent/src/commands/check.ts +0 -13
- package/templates/collections-agent/agents/collections-agent/src/commands/decide.ts +0 -48
- package/templates/collections-agent/agents/collections-agent/src/commands/deny.ts +0 -7
- package/templates/collections-agent/agents/collections-agent/src/commands/eval.ts +0 -39
- package/templates/collections-agent/agents/collections-agent/src/commands/poll.ts +0 -35
- package/templates/collections-agent/agents/collections-agent/src/commands/reconcile.ts +0 -38
- package/templates/collections-agent/agents/collections-agent/src/commands/rerun.ts +0 -55
- package/templates/collections-agent/agents/collections-agent/src/commands/resume.ts +0 -30
- package/templates/collections-agent/agents/collections-agent/src/commands/webhook.ts +0 -36
- package/templates/collections-agent/agents/collections-agent/src/main.ts +0 -193
- package/templates/collections-agent/agents/collections-agent/src/setup.ts +0 -250
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `codespar-agent poll [--channel terminal|whatsapp] [--wait <seconds>] [--simulate-payer] [--json]`:
|
|
3
|
+
* keeps looking at every receivable still waiting for its payer until it
|
|
4
|
+
* closes or the wait runs out. This is the loop-closer for a run that has no
|
|
5
|
+
* webhook URL; `codespar-agent webhook` is the other. Presents an instrument
|
|
6
|
+
* not yet shown, tells the payer the outcome once, fetches the paid record.
|
|
7
|
+
*
|
|
8
|
+
* `--channel` is on THIS command rather than in a second one, and the reason
|
|
9
|
+
* is that only one thing differs between the two: where the outcome message
|
|
10
|
+
* goes, and which carriers that place allows. The looking, the once-only
|
|
11
|
+
* presentation, the sandbox payer, the receipts and the terminal states are
|
|
12
|
+
* one loop — `pollUntilClosed` — and a second command would have meant a
|
|
13
|
+
* second copy of it, which is exactly how a channel ends up closing a cycle
|
|
14
|
+
* differently from the terminal.
|
|
15
|
+
*/
|
|
16
|
+
import { stderr, stdout } from "node:process";
|
|
17
|
+
import { join } from "node:path";
|
|
18
|
+
import { loadManifest, resolveFixedClock, type ChannelName } from "@codespar/agent-core";
|
|
19
|
+
import type { Agent } from "../agent.js";
|
|
20
|
+
import { setup } from "../setup.js";
|
|
21
|
+
import { announceOutcome, waitForPayer } from "../terminal.js";
|
|
22
|
+
import { pollWhatsApp } from "./poll-whatsapp.js";
|
|
23
|
+
import type { WhatsAppBackendName } from "../channels/whatsapp/open.js";
|
|
24
|
+
|
|
25
|
+
const USAGE = `codespar-agent poll [options]
|
|
26
|
+
--channel terminal|whatsapp where the outcome is told. Default terminal.
|
|
27
|
+
--conversation <name> which channels/whatsapp/<name>.json to come back to (--channel whatsapp)
|
|
28
|
+
--backend simulator|cloud-api default simulator, the local emulator (--channel whatsapp)
|
|
29
|
+
--wait <seconds> how long to keep looking
|
|
30
|
+
--simulate-payer let the sandbox payer act once the receivable is payable
|
|
31
|
+
--payer pays|expires|never what the fixture payer does when it acts (stub rail only)
|
|
32
|
+
--now <ISO 8601> pin the run's clock; env CODESPAR_AGENT_NOW is the same thing
|
|
33
|
+
--json machine output on stdout, everything else on stderr`;
|
|
34
|
+
|
|
35
|
+
interface Args {
|
|
36
|
+
channel: ChannelName;
|
|
37
|
+
conversation?: string;
|
|
38
|
+
backend?: WhatsAppBackendName;
|
|
39
|
+
wait?: number;
|
|
40
|
+
simulatePayer: boolean;
|
|
41
|
+
payer?: "pays" | "expires" | "never";
|
|
42
|
+
now?: string;
|
|
43
|
+
json: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function parsePollArgs(argv: string[]): Args {
|
|
47
|
+
const args: Args = { channel: "terminal", simulatePayer: false, json: false };
|
|
48
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
49
|
+
const a = argv[i]!;
|
|
50
|
+
const next = () => {
|
|
51
|
+
const v = argv[i + 1];
|
|
52
|
+
if (v === undefined) throw new Error(`${a} needs a value`);
|
|
53
|
+
i += 1;
|
|
54
|
+
return v;
|
|
55
|
+
};
|
|
56
|
+
if (a === "--json") args.json = true;
|
|
57
|
+
else if (a === "--simulate-payer") args.simulatePayer = true;
|
|
58
|
+
else if (a === "--wait") {
|
|
59
|
+
const v = Number(next());
|
|
60
|
+
if (!Number.isFinite(v) || v < 0) throw new Error("--wait must be a number of seconds");
|
|
61
|
+
args.wait = v;
|
|
62
|
+
} else if (a === "--channel") {
|
|
63
|
+
const v = next();
|
|
64
|
+
if (v !== "terminal" && v !== "whatsapp") throw new Error("--channel must be terminal or whatsapp");
|
|
65
|
+
args.channel = v;
|
|
66
|
+
} else if (a === "--backend") {
|
|
67
|
+
const v = next();
|
|
68
|
+
if (v !== "simulator" && v !== "cloud-api") throw new Error("--backend must be simulator or cloud-api");
|
|
69
|
+
args.backend = v;
|
|
70
|
+
} else if (a === "--payer") {
|
|
71
|
+
const v = next();
|
|
72
|
+
if (v !== "pays" && v !== "expires" && v !== "never") throw new Error("--payer must be pays, expires or never");
|
|
73
|
+
args.payer = v;
|
|
74
|
+
} else if (a === "--conversation") args.conversation = next();
|
|
75
|
+
else if (a === "--now") args.now = next();
|
|
76
|
+
else throw new Error(`unknown argument ${a}`);
|
|
77
|
+
}
|
|
78
|
+
if (args.channel !== "whatsapp" && (args.backend !== undefined || args.conversation !== undefined)) {
|
|
79
|
+
throw new Error("--backend and --conversation belong to --channel whatsapp");
|
|
80
|
+
}
|
|
81
|
+
return args;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export async function poll(agent: Agent, argv: string[]): Promise<number> {
|
|
85
|
+
const say = (l: string) => stderr.write(l + "\n");
|
|
86
|
+
let args: Args;
|
|
87
|
+
let now: (() => Date) | undefined;
|
|
88
|
+
try {
|
|
89
|
+
args = parsePollArgs(argv);
|
|
90
|
+
now = resolveFixedClock(args.now, process.env);
|
|
91
|
+
} catch (err) {
|
|
92
|
+
say(`${err instanceof Error ? err.message : String(err)}\n${USAGE}`);
|
|
93
|
+
return 2;
|
|
94
|
+
}
|
|
95
|
+
if (args.channel === "whatsapp" && !loadManifest(join(agent.dir, "agent.yaml")).manifest.channels.includes("whatsapp")) {
|
|
96
|
+
say(`${agent.slug} does not declare the whatsapp channel in agent.yaml`);
|
|
97
|
+
return 2;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const s = setup(agent, { say, runId: `run_poll_${Date.now().toString(36)}`, ...(now ? { now } : {}) });
|
|
101
|
+
// The same flag `start` has, and it means more here: a receivable nobody
|
|
102
|
+
// paid reaches its due date BETWEEN two runs, never inside one, so "what
|
|
103
|
+
// happens when it expires" is a question only a poll can be asked.
|
|
104
|
+
if (args.payer) s.payer?.behave(args.payer);
|
|
105
|
+
try {
|
|
106
|
+
if (args.channel === "whatsapp") {
|
|
107
|
+
return await pollWhatsApp({
|
|
108
|
+
agent,
|
|
109
|
+
setup: s,
|
|
110
|
+
conversation: args.conversation,
|
|
111
|
+
backend: args.backend ?? "simulator",
|
|
112
|
+
json: args.json,
|
|
113
|
+
waitSeconds: args.wait,
|
|
114
|
+
simulatePayer: args.simulatePayer,
|
|
115
|
+
...(args.payer ? { payer: args.payer } : {}),
|
|
116
|
+
now: now ?? (() => new Date()),
|
|
117
|
+
say,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
// `behave` only changes the default for receivables the rail has not
|
|
121
|
+
// looked at, and by now it has looked at these; `decideFor` is what
|
|
122
|
+
// rewrites the fate of one that already exists.
|
|
123
|
+
if (args.payer) {
|
|
124
|
+
for (const open of s.engine.list({ state: "executing" })) {
|
|
125
|
+
for (const outcome of open.outcomes) if (outcome.status === "accepted") s.payer?.decideFor?.(outcome.attempt_id, args.payer);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const tell = (l: string) => void (args.json ? stderr : stdout).write(l + "\n");
|
|
129
|
+
const results = [];
|
|
130
|
+
for (const open of s.engine.list({ state: "executing" })) {
|
|
131
|
+
if (open.reason !== "awaiting_settlement") continue;
|
|
132
|
+
const r = await waitForPayer(open.id, { setup: s, approver: { id: s.kit.labels.defaultUser, channel: "terminal" }, say, tell, waitSeconds: args.wait, simulatePayer: args.simulatePayer });
|
|
133
|
+
announceOutcome(r.execution, s, tell);
|
|
134
|
+
if (r.execution.state !== "executing") await s.engine.collectReceipts(r.execution.id);
|
|
135
|
+
results.push({ id: r.execution.id, state: r.execution.state, reason: r.execution.reason ?? null, rounds: r.rounds, seconds: r.seconds, timed_out: r.timed_out });
|
|
136
|
+
say(`${r.execution.id}: ${r.execution.state}${r.execution.reason ? ` (${r.execution.reason})` : ""} after ${r.rounds} look(s), ${r.seconds}s`);
|
|
137
|
+
}
|
|
138
|
+
if (args.json) stdout.write(JSON.stringify({ polled: results }) + "\n");
|
|
139
|
+
else if (!results.length) say("nothing waiting for a payer");
|
|
140
|
+
return results.some((r) => r.timed_out) ? 3 : 0;
|
|
141
|
+
} finally {
|
|
142
|
+
s.close();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `codespar-agent reconcile [--json]`: compares local state with the rail.
|
|
3
|
+
* Names executions without an outcome, attempts the rail never saw, sealed
|
|
4
|
+
* outcomes the rail holds that the bundle does not. Read-only unless an
|
|
5
|
+
* execution is in `executing`, which it closes from what the rail says.
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync } from "node:fs";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { stderr, stdout } from "node:process";
|
|
10
|
+
import type { Agent } from "../agent.js";
|
|
11
|
+
import { runsDir, setup } from "../setup.js";
|
|
12
|
+
|
|
13
|
+
export async function reconcile(agent: Agent, argv: string[]): Promise<number> {
|
|
14
|
+
const json = argv.includes("--json");
|
|
15
|
+
const awaitsPayer = agent.settlement === "await-payer";
|
|
16
|
+
const say = (l: string) => stderr.write(l + "\n");
|
|
17
|
+
const s = setup(agent, { say, runId: `run_reconcile_${Date.now().toString(36)}` });
|
|
18
|
+
try {
|
|
19
|
+
const findings: Array<{ execution_id: string; kind: string; detail: string }> = [];
|
|
20
|
+
for (const e of s.engine.list()) {
|
|
21
|
+
if (e.state === "executing") {
|
|
22
|
+
const closed = await s.engine.reconcile(e.id);
|
|
23
|
+
const kind = closed.state === "executing" ? (awaitsPayer && closed.reason === "awaiting_settlement" ? "awaiting_payer" : "still_uncertain") : "closed_from_rail";
|
|
24
|
+
findings.push({ execution_id: e.id, kind, detail: `executing -> ${closed.state}${awaitsPayer && closed.detail ? ` (${closed.detail})` : ""}` });
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
for (const o of e.outcomes) {
|
|
28
|
+
if (o.receipt_id && !existsSync(join(runsDir(agent), e.run_id, "receipts", `${o.receipt_id}.json`))) {
|
|
29
|
+
findings.push({ execution_id: e.id, kind: s.kit.labels.missingReceiptKind, detail: s.kit.labels.missingReceiptDetail(o.receipt_id, e.run_id) });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const outbox = s.store.getOutbox(e.idempotency_key);
|
|
33
|
+
if (e.state === "settled" && outbox?.status !== "done") findings.push({ execution_id: e.id, kind: "outbox_mismatch", detail: `settled but outbox is ${outbox?.status ?? "absent"}` });
|
|
34
|
+
}
|
|
35
|
+
for (const f of findings) say(`${f.kind} ${f.execution_id}: ${f.detail}`);
|
|
36
|
+
if (json) stdout.write(JSON.stringify({ executions: s.engine.list().length, findings }) + "\n");
|
|
37
|
+
else say(findings.length ? `${findings.length} finding(s)` : "local state and rail agree");
|
|
38
|
+
return 0;
|
|
39
|
+
} finally {
|
|
40
|
+
s.close();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `codespar-agent rerun <run-id> [--json]`: replays a recorded run against
|
|
3
|
+
* the deterministic provider and the stub rail, with no network, in a fresh
|
|
4
|
+
* state, and compares the sequence of states with the original bundle. The
|
|
5
|
+
* model's outputs are the recording; every decision of the core is recomputed.
|
|
6
|
+
*/
|
|
7
|
+
import { mkdtempSync } from "node:fs";
|
|
8
|
+
import { tmpdir } from "node:os";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { stderr, stdout } from "node:process";
|
|
11
|
+
import { ProofBundle, type ApprovalMode, type Execution } from "@codespar/agent-core";
|
|
12
|
+
import type { Agent } from "../agent.js";
|
|
13
|
+
import { runsDir, setup } from "../setup.js";
|
|
14
|
+
import { handleExecution } from "../terminal.js";
|
|
15
|
+
|
|
16
|
+
export async function rerun(agent: Agent, argv: string[]): Promise<number> {
|
|
17
|
+
const json = argv.includes("--json");
|
|
18
|
+
const runId = argv.find((a) => !a.startsWith("--"));
|
|
19
|
+
const say = (l: string) => stderr.write(l + "\n");
|
|
20
|
+
if (!runId) {
|
|
21
|
+
say("usage: npm run rerun <run-id> [--json]");
|
|
22
|
+
return 2;
|
|
23
|
+
}
|
|
24
|
+
const original = ProofBundle.open(runsDir(agent), runId);
|
|
25
|
+
if (!original) {
|
|
26
|
+
say(`no bundle at runs/${runId}`);
|
|
27
|
+
return 1;
|
|
28
|
+
}
|
|
29
|
+
const meta = original.readMeta() ?? {};
|
|
30
|
+
const mode = (meta["mode"] as ApprovalMode | undefined) ?? "human";
|
|
31
|
+
const events = original.readEvents();
|
|
32
|
+
const originalTrail = events.filter((e) => e["type"] === "execution.transition").map((e) => (e["payload"] as { to: string }).to);
|
|
33
|
+
const originalDecisions = events.filter((e) => e["type"] === "approval.created").map((e) => ((e["payload"] as { approver: { type: string } }).approver.type === "person" ? "approve" : "mandate"));
|
|
34
|
+
const userTurns = original.readTranscript().filter((l) => l.kind === "user").map((l) => l["text"] as string);
|
|
35
|
+
const transcriptPath = join(original.dir, "transcript.jsonl");
|
|
36
|
+
const plan = agent.kit.rerunPlan?.(events) ?? {};
|
|
37
|
+
|
|
38
|
+
const s = setup(agent, {
|
|
39
|
+
mode,
|
|
40
|
+
rail: "stub",
|
|
41
|
+
provider: "replay",
|
|
42
|
+
transcript: transcriptPath,
|
|
43
|
+
runId: `${runId}_rerun_${Date.now().toString(36)}`,
|
|
44
|
+
stateDir: mkdtempSync(join(tmpdir(), `${agent.slug}-rerun-`)),
|
|
45
|
+
stubRail: plan.stubRail,
|
|
46
|
+
say,
|
|
47
|
+
});
|
|
48
|
+
try {
|
|
49
|
+
let decisionIndex = 0;
|
|
50
|
+
const runtime = s.makeRuntime();
|
|
51
|
+
const loop = s.makeLoop(runtime, (execution: Execution) => {
|
|
52
|
+
const decision = execution.state === "awaiting_approval" ? (originalDecisions[decisionIndex++] === "approve" ? "approve" : "deny") : "none";
|
|
53
|
+
return handleExecution(execution, {
|
|
54
|
+
setup: s,
|
|
55
|
+
approver: { id: "usr_rerun", channel: "terminal" },
|
|
56
|
+
decision,
|
|
57
|
+
say,
|
|
58
|
+
...(agent.settlement === "await-payer" ? { tell: () => undefined, simulatePayer: plan.simulatePayer ?? false } : {}),
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
for (const text of userTurns) await loop.turn(text);
|
|
62
|
+
const trail = s.store.listEvents({ run_id: s.runId }).filter((e) => e.type === "execution.transition").map((e) => (e.payload as { to: string }).to);
|
|
63
|
+
const outcomesOf = (list: Record<string, unknown>[]) => list.filter((e) => e["type"] === "rail.outcome").map((e) => (e["payload"] as { status: string }).status);
|
|
64
|
+
const originalOutcomes = outcomesOf(events);
|
|
65
|
+
const rerunOutcomes = outcomesOf(s.bundle.readEvents());
|
|
66
|
+
const sameTrail = JSON.stringify(trail) === JSON.stringify(originalTrail);
|
|
67
|
+
const same = agent.kit.rerunComparesOutcomes ? sameTrail && JSON.stringify(rerunOutcomes) === JSON.stringify(originalOutcomes) : sameTrail;
|
|
68
|
+
if (json) {
|
|
69
|
+
stdout.write(
|
|
70
|
+
JSON.stringify({
|
|
71
|
+
run_id: runId,
|
|
72
|
+
rerun_id: s.runId,
|
|
73
|
+
same_states: same,
|
|
74
|
+
original: originalTrail,
|
|
75
|
+
rerun: trail,
|
|
76
|
+
...(agent.kit.rerunComparesOutcomes ? { original_outcomes: originalOutcomes, rerun_outcomes: rerunOutcomes } : {}),
|
|
77
|
+
bundle_dir: s.bundle.dir,
|
|
78
|
+
}) + "\n",
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
say(same ? `rerun ok: ${trail.length} transition(s), same sequence as ${runId}` : `rerun DIFFERS: original ${JSON.stringify(originalTrail)} vs rerun ${JSON.stringify(trail)}`);
|
|
82
|
+
return same ? 0 : 1;
|
|
83
|
+
} finally {
|
|
84
|
+
s.close();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `codespar-agent resume [--json]`: after a crash or a restart. Executions
|
|
3
|
+
* left in `executing` are reconciled against the rail (idempotent on
|
|
4
|
+
* attempt_id), never repeated; stale open ones expire.
|
|
5
|
+
*/
|
|
6
|
+
import { stderr, stdout } from "node:process";
|
|
7
|
+
import type { Execution } from "@codespar/agent-core";
|
|
8
|
+
import type { Agent } from "../agent.js";
|
|
9
|
+
import { setup } from "../setup.js";
|
|
10
|
+
|
|
11
|
+
export async function resume(agent: Agent, argv: string[]): Promise<number> {
|
|
12
|
+
const json = argv.includes("--json");
|
|
13
|
+
const awaitsPayer = agent.settlement === "await-payer";
|
|
14
|
+
const say = (l: string) => stderr.write(l + "\n");
|
|
15
|
+
const s = setup(agent, { say, runId: `run_resume_${Date.now().toString(36)}` });
|
|
16
|
+
try {
|
|
17
|
+
const closed: Execution[] = [];
|
|
18
|
+
// Only resume dispatches, and only what the outbox proves was never sent; everything else is reconciled from the rail.
|
|
19
|
+
for (const stuck of s.engine.list({ state: "executing" })) {
|
|
20
|
+
const e = await s.engine.resumePending(stuck.id);
|
|
21
|
+
closed.push(e);
|
|
22
|
+
say(e.state === "executing" ? s.kit.labels.stillExecuting(e) : `${e.id}: executing -> ${e.state}`);
|
|
23
|
+
}
|
|
24
|
+
const expired = s.engine.expireStale().map((e) => ({ id: e.id, state: e.state }));
|
|
25
|
+
for (const e of expired) say(`${e.id}: -> expired`);
|
|
26
|
+
const open = s.engine.list({ state: ["awaiting_approval", "approved"] }).map((e) => ({ id: e.id, state: e.state }));
|
|
27
|
+
for (const e of open) say(`${e.id}: still ${e.state}; decide it with npm run approve ${e.id} / npm run deny ${e.id}`);
|
|
28
|
+
if (json) {
|
|
29
|
+
const resumed = closed.map((e) => ({
|
|
30
|
+
id: e.id,
|
|
31
|
+
state: e.state,
|
|
32
|
+
...(awaitsPayer ? { reason: e.reason ?? null } : {}),
|
|
33
|
+
detail: e.detail ?? null,
|
|
34
|
+
...(awaitsPayer ? { charge_ids: e.outcomes.map((o) => o.transaction_id ?? null) } : {}),
|
|
35
|
+
receipt_ids: e.outcomes.filter((o) => o.receipt_id).map((o) => o.receipt_id),
|
|
36
|
+
}));
|
|
37
|
+
stdout.write(JSON.stringify({ resumed, expired, open, bundle_dir: s.bundle.dir }) + "\n");
|
|
38
|
+
} else say(closed.length || expired.length ? "resume done" : "nothing to resume");
|
|
39
|
+
return closed.some((e) => e.state === "executing" && (!awaitsPayer || e.reason !== "awaiting_settlement")) ? 3 : 0;
|
|
40
|
+
} finally {
|
|
41
|
+
s.close();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `codespar-agent start --channel whatsapp`: wiring, and only wiring.
|
|
3
|
+
*
|
|
4
|
+
* It picks a backend, binds the conversation, hands the channel the rules the
|
|
5
|
+
* agent's own guardrails declare, and runs the loop — all of that through
|
|
6
|
+
* `channels/whatsapp/open.ts`, which `poll --channel whatsapp` goes through
|
|
7
|
+
* too, so the two commands cannot end up enforcing different rules. The
|
|
8
|
+
* decisions are elsewhere: the rules in `channels/rules.ts`, the session
|
|
9
|
+
* window in `channels/whatsapp/session.ts`, the gates in `terminal.ts`, which
|
|
10
|
+
* this path reuses unchanged so the two channels cannot drift on what may
|
|
11
|
+
* execute.
|
|
12
|
+
*/
|
|
13
|
+
import { stdout } from "node:process";
|
|
14
|
+
import { relative } from "node:path";
|
|
15
|
+
import type { ConversationScript } from "@codespar/agent-core";
|
|
16
|
+
import type { Agent } from "../agent.js";
|
|
17
|
+
import type { Setup } from "../setup.js";
|
|
18
|
+
import { defaultAsk } from "../terminal.js";
|
|
19
|
+
import { converse } from "../channels/whatsapp/run.js";
|
|
20
|
+
import { buildWhatsApp, simulatedCost, type WhatsAppBackendName } from "../channels/whatsapp/open.js";
|
|
21
|
+
import { EmulatorUnreachableError } from "../channels/whatsapp/emulator.js";
|
|
22
|
+
|
|
23
|
+
export type { WhatsAppBackendName };
|
|
24
|
+
|
|
25
|
+
export interface StartWhatsAppOptions {
|
|
26
|
+
agent: Agent;
|
|
27
|
+
setup: Setup;
|
|
28
|
+
script: ConversationScript;
|
|
29
|
+
backend: WhatsAppBackendName;
|
|
30
|
+
/** Replay the conversation's turns; otherwise the person is at the keyboard. */
|
|
31
|
+
scripted: boolean;
|
|
32
|
+
approver: { id: string; channel: string };
|
|
33
|
+
json: boolean;
|
|
34
|
+
startedAt: number;
|
|
35
|
+
say: (line: string) => void;
|
|
36
|
+
decision?: "approve" | "deny" | "none";
|
|
37
|
+
waitSeconds?: number | undefined;
|
|
38
|
+
simulatePayer?: boolean | undefined;
|
|
39
|
+
now?: (() => Date) | undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function startWhatsApp(options: StartWhatsAppOptions): Promise<number> {
|
|
43
|
+
const { agent, setup: s, script, say } = options;
|
|
44
|
+
const now = options.now ?? (() => new Date());
|
|
45
|
+
const conversation = { contact: script.contact, subject: script.subject };
|
|
46
|
+
|
|
47
|
+
// A scripted conversation has nobody at a keyboard, and in `human` mode
|
|
48
|
+
// somebody has to decide. Refused rather than left waiting on a stdin that
|
|
49
|
+
// will never answer: a gate that hangs teaches nothing.
|
|
50
|
+
if (options.scripted && s.mode === "human" && !options.decision) {
|
|
51
|
+
say("--scripted has nobody at the keyboard and approval: human needs a decision: add --approve or --deny, or run --mode mandate");
|
|
52
|
+
return 2;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const built = buildWhatsApp({
|
|
56
|
+
agent,
|
|
57
|
+
setup: s,
|
|
58
|
+
conversation,
|
|
59
|
+
backend: options.backend,
|
|
60
|
+
now,
|
|
61
|
+
say,
|
|
62
|
+
bundle: s.bundle,
|
|
63
|
+
...(options.scripted ? { script } : { ask: defaultAsk }),
|
|
64
|
+
// A run that STARTS a conversation pins the emulator's clock to its own instant.
|
|
65
|
+
...(options.now ? { pinAt: options.now() } : {}),
|
|
66
|
+
});
|
|
67
|
+
if ("refusal" in built) {
|
|
68
|
+
for (const line of built.refusal) say(line);
|
|
69
|
+
return 1;
|
|
70
|
+
}
|
|
71
|
+
const { channel, driver, sessionKey } = built;
|
|
72
|
+
|
|
73
|
+
// The channel is opened here, which is where an emulator that is not
|
|
74
|
+
// running has to be reported: after this the run has already started.
|
|
75
|
+
try {
|
|
76
|
+
await channel.open();
|
|
77
|
+
} catch (err) {
|
|
78
|
+
if (err instanceof EmulatorUnreachableError) {
|
|
79
|
+
say(err.message);
|
|
80
|
+
return 1;
|
|
81
|
+
}
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const result = await converse({
|
|
86
|
+
setup: s,
|
|
87
|
+
channel,
|
|
88
|
+
approver: options.approver,
|
|
89
|
+
say,
|
|
90
|
+
...(options.decision ? { decision: options.decision } : {}),
|
|
91
|
+
...(options.scripted ? {} : { ask: defaultAsk }),
|
|
92
|
+
...(options.waitSeconds !== undefined ? { waitSeconds: options.waitSeconds } : {}),
|
|
93
|
+
...(options.simulatePayer !== undefined ? { simulatePayer: options.simulatePayer } : {}),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// What the emulator is actually for, and the one number this repo cannot
|
|
97
|
+
// compute: what the conversation would have cost under Meta's rules. Read for
|
|
98
|
+
// the console only — never asserted on, because it is their engine's answer
|
|
99
|
+
// and not a contract of ours.
|
|
100
|
+
const cost = await simulatedCost(driver, sessionKey);
|
|
101
|
+
|
|
102
|
+
const log = channel.log();
|
|
103
|
+
const refused = log.filter((l) => l.refused).map((l) => ({ rule: l.refused!.rule, detail: l.refused!.detail }));
|
|
104
|
+
const channelSummary = {
|
|
105
|
+
name: "whatsapp",
|
|
106
|
+
backend: channel.backend,
|
|
107
|
+
conversation: script.name,
|
|
108
|
+
turns: result.turns,
|
|
109
|
+
messages_in: log.filter((l) => l.direction === "in").length,
|
|
110
|
+
messages_out: log.filter((l) => l.direction === "out" && !l.refused).length,
|
|
111
|
+
refused,
|
|
112
|
+
log: relative(process.cwd(), `${s.bundle.dir}/channel.jsonl`),
|
|
113
|
+
...(cost ? { simulated_cost: cost } : {}),
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
if (options.json) {
|
|
117
|
+
const payload = s.kit.oneShotPayload({
|
|
118
|
+
setup: s,
|
|
119
|
+
reply: result.replies[result.replies.length - 1] ?? "",
|
|
120
|
+
toolCalls: result.toolCalls,
|
|
121
|
+
executions: result.executions,
|
|
122
|
+
startedAt: options.startedAt,
|
|
123
|
+
});
|
|
124
|
+
stdout.write(JSON.stringify({ ...payload, channel: channelSummary }) + "\n");
|
|
125
|
+
} else {
|
|
126
|
+
say(`conversa em ${channelSummary.log} — ${channelSummary.messages_in} recebida(s), ${channelSummary.messages_out} enviada(s)${refused.length ? `, ${refused.length} recusada(s)` : ""}`);
|
|
127
|
+
if (cost) say(`custo simulado desta conversa nas regras da Meta: ${cost.total.toFixed(4)} ${cost.currency} (conta do emulador, nao nossa)`);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return result.executions.some((e) => e.state === "executing") ? 3 : 0;
|
|
131
|
+
}
|