@codespar/cli 0.18.1 → 0.21.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 +1 -1
- package/dist/commands/login.js +52 -12
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/payables.js +220 -0
- package/dist/commands/payables.js.map +1 -0
- package/dist/index.js +77 -1
- package/dist/index.js.map +1 -1
- package/dist/surface.js +31 -13
- package/dist/surface.js.map +1 -1
- package/package.json +2 -2
- package/templates/bills-agent/README.md +2 -2
- package/templates/bills-agent/agents/bills-agent/.env.example +2 -2
- package/templates/bills-agent/agents/bills-agent/README.md +25 -18
- package/templates/bills-agent/agents/bills-agent/SYSTEM_PROMPT.md +13 -3
- package/templates/bills-agent/agents/bills-agent/agent.yaml +2 -1
- package/templates/bills-agent/agents/bills-agent/evals/adversarial/exfiltration.transcript.jsonl +1 -1
- package/templates/bills-agent/agents/bills-agent/evals/adversarial/false-authority.transcript.jsonl +1 -1
- package/templates/bills-agent/agents/bills-agent/evals/adversarial/prompt-injection.transcript.jsonl +1 -1
- package/templates/bills-agent/agents/bills-agent/mandate.example.json +1 -1
- package/templates/bills-agent/agents/bills-agent/runbook.md +1 -1
- package/templates/bills-agent/agents/bills-agent/scenarios/beneficiary-not-allowed.transcript.jsonl +1 -1
- package/templates/bills-agent/agents/bills-agent/scenarios/cap-exceeded.transcript.jsonl +1 -1
- package/templates/bills-agent/agents/bills-agent/scenarios/escalated-above-threshold.transcript.jsonl +4 -4
- package/templates/bills-agent/agents/bills-agent/scenarios/happy-path.transcript.jsonl +1 -1
- package/templates/bills-agent/agents/bills-agent/scenarios/mandate-revoked.json +1 -1
- package/templates/bills-agent/agents/bills-agent/scenarios/mandate-revoked.transcript.jsonl +4 -4
- package/templates/bills-agent/agents/bills-agent/scenarios/prompt-injection.transcript.jsonl +1 -1
- package/templates/bills-agent/agents/bills-agent/src/bills.ts +1 -1
- package/templates/bills-agent/agents/bills-agent/src/kit.ts +15 -28
- package/templates/bills-agent/agents/bills-agent/src/modules/embedded-consent.ts +42 -15
- package/templates/bills-agent/agents/bills-agent/src/modules/pix-out.ts +21 -3
- package/templates/bills-agent/agents/bills-agent/src/strings.ts +68 -0
- package/templates/bills-agent/agents/bills-agent/test/cli.test.ts +130 -2
- package/templates/bills-agent/agents/bills-agent/test/consent-money.test.ts +25 -0
- package/templates/bills-agent/agents/bills-agent/test/dates-and-approval.test.ts +98 -0
- package/templates/bills-agent/agents/bills-agent/test/eval-runs.test.ts +81 -0
- package/templates/bills-agent/agents/bills-agent/test/fixtures/excursao-300.transcript.jsonl +2 -2
- package/templates/bills-agent/agents/bills-agent/test/fixtures/material-400.transcript.jsonl +1 -1
- package/templates/bills-agent/agents/bills-agent/test/locale.test.ts +161 -0
- package/templates/bills-agent/agents/bills-agent/test/mandate-state.test.ts +108 -0
- package/templates/bills-agent/agents/bills-agent/test/refused-before-draft.test.ts +81 -0
- package/templates/bills-agent/agents/bills-agent/test/replay.test.ts +76 -0
- package/templates/bills-agent/agents/bills-agent/test/reply-and-outcome.test.ts +84 -0
- package/templates/bills-agent/agents/bills-agent/test/reply-language.test.ts +95 -0
- package/templates/bills-agent/agents/bills-agent/test/rerun-and-missing-transcript.test.ts +120 -0
- package/templates/bills-agent/agents/bills-agent/test/rerun-world-events.test.ts +55 -0
- package/templates/bills-agent/agents/bills-agent/tools.json +1 -1
- package/templates/bills-agent/packages/agent-core/README.md +21 -2
- package/templates/bills-agent/packages/agent-core/package.json +1 -1
- package/templates/bills-agent/packages/agent-core/src/agent.ts +33 -6
- package/templates/bills-agent/packages/agent-core/src/api/charge-rail.ts +15 -1
- package/templates/bills-agent/packages/agent-core/src/api/rail.ts +11 -5
- package/templates/bills-agent/packages/agent-core/src/api/sandbox-payer.ts +36 -0
- package/templates/bills-agent/packages/agent-core/src/bundle.ts +2 -0
- package/templates/bills-agent/packages/agent-core/src/channels.ts +18 -8
- package/templates/bills-agent/packages/agent-core/src/check.ts +25 -3
- package/templates/bills-agent/packages/agent-core/src/engine.ts +90 -9
- package/templates/bills-agent/packages/agent-core/src/escalate.ts +10 -0
- package/templates/bills-agent/packages/agent-core/src/index.ts +3 -0
- package/templates/bills-agent/packages/agent-core/src/language.ts +52 -0
- package/templates/bills-agent/packages/agent-core/src/locale.ts +88 -0
- package/templates/bills-agent/packages/agent-core/src/manifest.ts +4 -1
- package/templates/bills-agent/packages/agent-core/src/rail.ts +29 -1
- package/templates/bills-agent/packages/agent-core/src/receipt-verification.ts +30 -2
- package/templates/bills-agent/packages/agent-core/src/secrets.ts +53 -8
- package/templates/bills-agent/packages/agent-core/src/state-machine.ts +14 -0
- package/templates/bills-agent/packages/agent-core/src/strings.ts +175 -0
- package/templates/bills-agent/packages/agent-core/src/stubs/charge-rail.ts +15 -2
- package/templates/bills-agent/packages/agent-core/src/stubs/rail.ts +7 -4
- package/templates/bills-agent/packages/agent-core/src/types.ts +15 -2
- package/templates/bills-agent/packages/agent-core/test/actor-on-the-wire.test.ts +144 -0
- package/templates/bills-agent/packages/agent-core/test/attempt-replay.test.ts +2 -2
- package/templates/bills-agent/packages/agent-core/test/engine.test.ts +23 -0
- package/templates/bills-agent/packages/agent-core/test/helpers.ts +1 -1
- package/templates/bills-agent/packages/agent-core/test/language.test.ts +40 -0
- package/templates/bills-agent/packages/agent-core/test/locale.test.ts +137 -0
- package/templates/bills-agent/packages/agent-core/test/mandate-status.test.ts +2 -2
- package/templates/bills-agent/packages/agent-core/test/manifest.test.ts +2 -2
- package/templates/bills-agent/packages/agent-core/test/rail-errors.test.ts +74 -0
- package/templates/bills-agent/packages/agent-core/test/receipt-read-verification.test.ts +32 -0
- package/templates/bills-agent/packages/agent-core/test/receivables.test.ts +49 -0
- package/templates/bills-agent/packages/agent-core/test/recorded-turns.ts +29 -0
- package/templates/bills-agent/packages/agent-core/test/secrets.test.ts +40 -1
- package/templates/bills-agent/packages/agent-runtime/README.md +31 -4
- package/templates/bills-agent/packages/agent-runtime/src/channels/rules.ts +4 -2
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +11 -5
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +43 -21
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +3 -0
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +8 -12
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +8 -4
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +12 -9
- package/templates/bills-agent/packages/agent-runtime/src/cli.ts +30 -4
- package/templates/bills-agent/packages/agent-runtime/src/commands/check.ts +18 -2
- package/templates/bills-agent/packages/agent-runtime/src/commands/decide.ts +13 -4
- package/templates/bills-agent/packages/agent-runtime/src/commands/eval.ts +7 -2
- package/templates/bills-agent/packages/agent-runtime/src/commands/inspect.ts +11 -13
- package/templates/bills-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +32 -24
- package/templates/bills-agent/packages/agent-runtime/src/commands/poll.ts +12 -5
- package/templates/bills-agent/packages/agent-runtime/src/commands/rerun.ts +83 -10
- package/templates/bills-agent/packages/agent-runtime/src/commands/resume.ts +2 -1
- package/templates/bills-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +10 -5
- package/templates/bills-agent/packages/agent-runtime/src/commands/start.ts +48 -17
- package/templates/bills-agent/packages/agent-runtime/src/commands/verify.ts +37 -12
- package/templates/bills-agent/packages/agent-runtime/src/commands/webhook.ts +11 -3
- package/templates/bills-agent/packages/agent-runtime/src/default-kit.ts +52 -22
- package/templates/bills-agent/packages/agent-runtime/src/env.ts +64 -0
- package/templates/bills-agent/packages/agent-runtime/src/index.ts +2 -0
- package/templates/bills-agent/packages/agent-runtime/src/inspect.ts +81 -10
- package/templates/bills-agent/packages/agent-runtime/src/kit.ts +34 -12
- package/templates/bills-agent/packages/agent-runtime/src/outcome.ts +118 -0
- package/templates/bills-agent/packages/agent-runtime/src/poll.ts +7 -7
- package/templates/bills-agent/packages/agent-runtime/src/runs.ts +51 -0
- package/templates/bills-agent/packages/agent-runtime/src/scenarios.ts +55 -8
- package/templates/bills-agent/packages/agent-runtime/src/setup.ts +75 -5
- package/templates/bills-agent/packages/agent-runtime/src/terminal.ts +71 -33
- package/templates/bills-agent/packages/agent-runtime/test/env-names.test.ts +56 -0
- package/templates/bills-agent/packages/agent-runtime/test/inspect-mandate-status.test.ts +80 -0
- package/templates/bills-agent/packages/agent-runtime/test/inspect.test.ts +63 -2
- package/templates/bills-agent/packages/agent-runtime/test/outcome.test.ts +72 -0
- package/templates/bills-agent/packages/agent-runtime/test/poll-payer.test.ts +64 -0
- package/templates/bills-agent/packages/agent-runtime/test/rerun-not-replayed.test.ts +46 -0
- package/templates/bills-agent/packages/agent-runtime/test/transition-line.test.ts +29 -0
- package/templates/bills-agent/packages/agent-runtime/test/verify-cli.test.ts +99 -6
- package/templates/bills-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +8 -0
- package/templates/bills-agent/packages/agent-runtime/test/whatsapp-session.test.ts +77 -0
- package/templates/bills-agent/packages/agent-runtime/test/whatsapp-status-replies.test.ts +27 -1
- package/templates/checkout-agent/README.md +2 -2
- package/templates/checkout-agent/agents/checkout-agent/.env.example +6 -4
- package/templates/checkout-agent/agents/checkout-agent/README.md +16 -8
- package/templates/checkout-agent/agents/checkout-agent/SYSTEM_PROMPT.md +17 -7
- package/templates/checkout-agent/agents/checkout-agent/agent.yaml +4 -3
- package/templates/checkout-agent/agents/checkout-agent/channels/whatsapp/README.md +2 -2
- package/templates/checkout-agent/agents/checkout-agent/channels/whatsapp/templates.json +48 -4
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/beneficiary-swap-human.json +1 -1
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/beneficiary-swap.json +1 -1
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/beneficiary-swap.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/coupon-unknown.json +1 -1
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/exfiltration.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/fractioning.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/payment-claimed.json +1 -1
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/payment-claimed.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/price-injected.json +1 -1
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/prompt-injection.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/quantity-swapped.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/package.json +1 -1
- package/templates/checkout-agent/agents/checkout-agent/runbook.md +4 -4
- package/templates/checkout-agent/agents/checkout-agent/scenarios/beneficiary-not-allowed.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/scenarios/cart-recomposed.transcript.jsonl +2 -2
- package/templates/checkout-agent/agents/checkout-agent/scenarios/cart-replaced.json +2 -2
- package/templates/checkout-agent/agents/checkout-agent/scenarios/cart-replaced.transcript.jsonl +2 -2
- package/templates/checkout-agent/agents/checkout-agent/scenarios/charge-expired.json +1 -1
- package/templates/checkout-agent/agents/checkout-agent/scenarios/charge-expired.transcript.jsonl +2 -2
- package/templates/checkout-agent/agents/checkout-agent/scenarios/coupon-unknown.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/scenarios/escalated-above-threshold.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/scenarios/happy-path.transcript.jsonl +2 -2
- package/templates/checkout-agent/agents/checkout-agent/scenarios/item-unavailable.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/scenarios/mandate-revoked.transcript.jsonl +3 -3
- package/templates/checkout-agent/agents/checkout-agent/scenarios/payment-claimed.json +1 -1
- package/templates/checkout-agent/agents/checkout-agent/scenarios/payment-claimed.transcript.jsonl +2 -2
- package/templates/checkout-agent/agents/checkout-agent/scenarios/price-injected.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/scenarios/prompt-injection.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/src/catalog.ts +7 -7
- package/templates/checkout-agent/agents/checkout-agent/src/kit.ts +47 -43
- package/templates/checkout-agent/agents/checkout-agent/src/modules/bolepix-receivables.ts +20 -12
- package/templates/checkout-agent/agents/checkout-agent/src/modules/nfse-invoice.ts +4 -4
- package/templates/checkout-agent/agents/checkout-agent/src/modules/storefront-cart.ts +9 -6
- package/templates/checkout-agent/agents/checkout-agent/src/pricing.ts +44 -41
- package/templates/checkout-agent/agents/checkout-agent/src/strings.ts +179 -0
- package/templates/checkout-agent/agents/checkout-agent/test/check.test.ts +4 -1
- package/templates/checkout-agent/agents/checkout-agent/test/fixtures/order-marina.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/test/fixtures/ordered-marina-awaiting-payer.transcript.jsonl +2 -2
- package/templates/checkout-agent/agents/checkout-agent/test/fixtures/tap-falar-agora-marina.transcript.jsonl +1 -1
- package/templates/checkout-agent/agents/checkout-agent/test/payable-instrument.test.ts +58 -0
- package/templates/checkout-agent/agents/checkout-agent/test/pricing.test.ts +2 -2
- package/templates/checkout-agent/agents/checkout-agent/test/rerun-unpaid.test.ts +47 -0
- package/templates/checkout-agent/agents/checkout-agent/test/scenario-reach-and-seconds.test.ts +55 -0
- package/templates/checkout-agent/agents/checkout-agent/test/whatsapp.test.ts +26 -10
- package/templates/checkout-agent/agents/checkout-agent/tools.json +1 -1
- package/templates/checkout-agent/packages/agent-core/README.md +21 -2
- package/templates/checkout-agent/packages/agent-core/package.json +1 -1
- package/templates/checkout-agent/packages/agent-core/src/agent.ts +33 -6
- package/templates/checkout-agent/packages/agent-core/src/api/charge-rail.ts +15 -1
- package/templates/checkout-agent/packages/agent-core/src/api/rail.ts +11 -5
- package/templates/checkout-agent/packages/agent-core/src/api/sandbox-payer.ts +36 -0
- package/templates/checkout-agent/packages/agent-core/src/bundle.ts +2 -0
- package/templates/checkout-agent/packages/agent-core/src/channels.ts +18 -8
- package/templates/checkout-agent/packages/agent-core/src/check.ts +25 -3
- package/templates/checkout-agent/packages/agent-core/src/engine.ts +90 -9
- package/templates/checkout-agent/packages/agent-core/src/escalate.ts +10 -0
- package/templates/checkout-agent/packages/agent-core/src/index.ts +3 -0
- package/templates/checkout-agent/packages/agent-core/src/language.ts +52 -0
- package/templates/checkout-agent/packages/agent-core/src/locale.ts +88 -0
- package/templates/checkout-agent/packages/agent-core/src/manifest.ts +4 -1
- package/templates/checkout-agent/packages/agent-core/src/rail.ts +29 -1
- package/templates/checkout-agent/packages/agent-core/src/receipt-verification.ts +30 -2
- package/templates/checkout-agent/packages/agent-core/src/secrets.ts +53 -8
- package/templates/checkout-agent/packages/agent-core/src/state-machine.ts +14 -0
- package/templates/checkout-agent/packages/agent-core/src/strings.ts +175 -0
- package/templates/checkout-agent/packages/agent-core/src/stubs/charge-rail.ts +15 -2
- package/templates/checkout-agent/packages/agent-core/src/stubs/rail.ts +7 -4
- package/templates/checkout-agent/packages/agent-core/src/types.ts +15 -2
- package/templates/checkout-agent/packages/agent-core/test/actor-on-the-wire.test.ts +144 -0
- package/templates/checkout-agent/packages/agent-core/test/attempt-replay.test.ts +2 -2
- package/templates/checkout-agent/packages/agent-core/test/engine.test.ts +23 -0
- package/templates/checkout-agent/packages/agent-core/test/helpers.ts +1 -1
- package/templates/checkout-agent/packages/agent-core/test/language.test.ts +40 -0
- package/templates/checkout-agent/packages/agent-core/test/locale.test.ts +137 -0
- package/templates/checkout-agent/packages/agent-core/test/mandate-status.test.ts +2 -2
- package/templates/checkout-agent/packages/agent-core/test/manifest.test.ts +2 -2
- package/templates/checkout-agent/packages/agent-core/test/rail-errors.test.ts +74 -0
- package/templates/checkout-agent/packages/agent-core/test/receipt-read-verification.test.ts +32 -0
- package/templates/checkout-agent/packages/agent-core/test/receivables.test.ts +49 -0
- package/templates/checkout-agent/packages/agent-core/test/recorded-turns.ts +29 -0
- package/templates/checkout-agent/packages/agent-core/test/secrets.test.ts +40 -1
- package/templates/checkout-agent/packages/agent-runtime/README.md +31 -4
- package/templates/checkout-agent/packages/agent-runtime/src/channels/rules.ts +4 -2
- package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +11 -5
- package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +43 -21
- package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +3 -0
- package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +8 -12
- package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +8 -4
- package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +12 -9
- package/templates/checkout-agent/packages/agent-runtime/src/cli.ts +30 -4
- package/templates/checkout-agent/packages/agent-runtime/src/commands/check.ts +18 -2
- package/templates/checkout-agent/packages/agent-runtime/src/commands/decide.ts +13 -4
- package/templates/checkout-agent/packages/agent-runtime/src/commands/eval.ts +7 -2
- package/templates/checkout-agent/packages/agent-runtime/src/commands/inspect.ts +11 -13
- package/templates/checkout-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +32 -24
- package/templates/checkout-agent/packages/agent-runtime/src/commands/poll.ts +12 -5
- package/templates/checkout-agent/packages/agent-runtime/src/commands/rerun.ts +83 -10
- package/templates/checkout-agent/packages/agent-runtime/src/commands/resume.ts +2 -1
- package/templates/checkout-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +10 -5
- package/templates/checkout-agent/packages/agent-runtime/src/commands/start.ts +48 -17
- package/templates/checkout-agent/packages/agent-runtime/src/commands/verify.ts +37 -12
- package/templates/checkout-agent/packages/agent-runtime/src/commands/webhook.ts +11 -3
- package/templates/checkout-agent/packages/agent-runtime/src/default-kit.ts +52 -22
- package/templates/checkout-agent/packages/agent-runtime/src/env.ts +64 -0
- package/templates/checkout-agent/packages/agent-runtime/src/index.ts +2 -0
- package/templates/checkout-agent/packages/agent-runtime/src/inspect.ts +81 -10
- package/templates/checkout-agent/packages/agent-runtime/src/kit.ts +34 -12
- package/templates/checkout-agent/packages/agent-runtime/src/outcome.ts +118 -0
- package/templates/checkout-agent/packages/agent-runtime/src/poll.ts +7 -7
- package/templates/checkout-agent/packages/agent-runtime/src/runs.ts +51 -0
- package/templates/checkout-agent/packages/agent-runtime/src/scenarios.ts +55 -8
- package/templates/checkout-agent/packages/agent-runtime/src/setup.ts +75 -5
- package/templates/checkout-agent/packages/agent-runtime/src/terminal.ts +71 -33
- package/templates/checkout-agent/packages/agent-runtime/test/env-names.test.ts +56 -0
- package/templates/checkout-agent/packages/agent-runtime/test/inspect-mandate-status.test.ts +80 -0
- package/templates/checkout-agent/packages/agent-runtime/test/inspect.test.ts +63 -2
- package/templates/checkout-agent/packages/agent-runtime/test/outcome.test.ts +72 -0
- package/templates/checkout-agent/packages/agent-runtime/test/poll-payer.test.ts +64 -0
- package/templates/checkout-agent/packages/agent-runtime/test/rerun-not-replayed.test.ts +46 -0
- package/templates/checkout-agent/packages/agent-runtime/test/transition-line.test.ts +29 -0
- package/templates/checkout-agent/packages/agent-runtime/test/verify-cli.test.ts +99 -6
- package/templates/checkout-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +8 -0
- package/templates/checkout-agent/packages/agent-runtime/test/whatsapp-session.test.ts +77 -0
- package/templates/checkout-agent/packages/agent-runtime/test/whatsapp-status-replies.test.ts +27 -1
- package/templates/collections-agent/README.md +2 -2
- package/templates/collections-agent/agents/collections-agent/.env.example +6 -3
- package/templates/collections-agent/agents/collections-agent/README.md +14 -9
- package/templates/collections-agent/agents/collections-agent/SYSTEM_PROMPT.md +16 -5
- package/templates/collections-agent/agents/collections-agent/agent.yaml +4 -3
- package/templates/collections-agent/agents/collections-agent/channels/whatsapp/README.md +21 -4
- package/templates/collections-agent/agents/collections-agent/channels/whatsapp/templates.json +49 -5
- package/templates/collections-agent/agents/collections-agent/mandate.example.json +1 -1
- package/templates/collections-agent/agents/collections-agent/runbook.md +3 -3
- package/templates/collections-agent/agents/collections-agent/src/agreements.ts +1 -1
- package/templates/collections-agent/agents/collections-agent/src/envelope.ts +15 -13
- package/templates/collections-agent/agents/collections-agent/src/kit.ts +38 -35
- package/templates/collections-agent/agents/collections-agent/src/modules/bolepix-receivables.ts +16 -8
- package/templates/collections-agent/agents/collections-agent/src/strings.ts +91 -0
- package/templates/collections-agent/agents/collections-agent/test/ambiguous-charge.test.ts +2 -2
- package/templates/collections-agent/agents/collections-agent/test/check.test.ts +4 -1
- package/templates/collections-agent/agents/collections-agent/test/cli.test.ts +1 -1
- package/templates/collections-agent/agents/collections-agent/test/envelope.test.ts +2 -2
- package/templates/collections-agent/agents/collections-agent/test/fixtures/accept-1103.transcript.jsonl +1 -1
- package/templates/collections-agent/agents/collections-agent/test/fixtures/tap-emitir-nova-1042.transcript.jsonl +1 -1
- package/templates/collections-agent/agents/collections-agent/test/payable-instrument.test.ts +56 -0
- package/templates/collections-agent/agents/collections-agent/test/rerun-clock.test.ts +54 -0
- package/templates/collections-agent/agents/collections-agent/test/whatsapp-poll.test.ts +69 -2
- package/templates/collections-agent/agents/collections-agent/test/whatsapp-status-replies.test.ts +16 -3
- package/templates/collections-agent/agents/collections-agent/test/whatsapp.test.ts +16 -4
- package/templates/collections-agent/agents/collections-agent/tools.json +2 -2
- package/templates/collections-agent/packages/agent-core/README.md +21 -2
- package/templates/collections-agent/packages/agent-core/package.json +1 -1
- package/templates/collections-agent/packages/agent-core/src/agent.ts +33 -6
- package/templates/collections-agent/packages/agent-core/src/api/charge-rail.ts +15 -1
- package/templates/collections-agent/packages/agent-core/src/api/rail.ts +11 -5
- package/templates/collections-agent/packages/agent-core/src/api/sandbox-payer.ts +36 -0
- package/templates/collections-agent/packages/agent-core/src/bundle.ts +2 -0
- package/templates/collections-agent/packages/agent-core/src/channels.ts +18 -8
- package/templates/collections-agent/packages/agent-core/src/check.ts +25 -3
- package/templates/collections-agent/packages/agent-core/src/engine.ts +90 -9
- package/templates/collections-agent/packages/agent-core/src/escalate.ts +10 -0
- package/templates/collections-agent/packages/agent-core/src/index.ts +3 -0
- package/templates/collections-agent/packages/agent-core/src/language.ts +52 -0
- package/templates/collections-agent/packages/agent-core/src/locale.ts +88 -0
- package/templates/collections-agent/packages/agent-core/src/manifest.ts +4 -1
- package/templates/collections-agent/packages/agent-core/src/rail.ts +29 -1
- package/templates/collections-agent/packages/agent-core/src/receipt-verification.ts +30 -2
- package/templates/collections-agent/packages/agent-core/src/secrets.ts +53 -8
- package/templates/collections-agent/packages/agent-core/src/state-machine.ts +14 -0
- package/templates/collections-agent/packages/agent-core/src/strings.ts +175 -0
- package/templates/collections-agent/packages/agent-core/src/stubs/charge-rail.ts +15 -2
- package/templates/collections-agent/packages/agent-core/src/stubs/rail.ts +7 -4
- package/templates/collections-agent/packages/agent-core/src/types.ts +15 -2
- package/templates/collections-agent/packages/agent-core/test/actor-on-the-wire.test.ts +144 -0
- package/templates/collections-agent/packages/agent-core/test/attempt-replay.test.ts +2 -2
- package/templates/collections-agent/packages/agent-core/test/engine.test.ts +23 -0
- package/templates/collections-agent/packages/agent-core/test/helpers.ts +1 -1
- package/templates/collections-agent/packages/agent-core/test/language.test.ts +40 -0
- package/templates/collections-agent/packages/agent-core/test/locale.test.ts +137 -0
- package/templates/collections-agent/packages/agent-core/test/mandate-status.test.ts +2 -2
- package/templates/collections-agent/packages/agent-core/test/manifest.test.ts +2 -2
- package/templates/collections-agent/packages/agent-core/test/rail-errors.test.ts +74 -0
- package/templates/collections-agent/packages/agent-core/test/receipt-read-verification.test.ts +32 -0
- package/templates/collections-agent/packages/agent-core/test/receivables.test.ts +49 -0
- package/templates/collections-agent/packages/agent-core/test/recorded-turns.ts +29 -0
- package/templates/collections-agent/packages/agent-core/test/secrets.test.ts +40 -1
- package/templates/collections-agent/packages/agent-runtime/README.md +31 -4
- package/templates/collections-agent/packages/agent-runtime/src/channels/rules.ts +4 -2
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +11 -5
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +43 -21
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +3 -0
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +8 -12
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +8 -4
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +12 -9
- package/templates/collections-agent/packages/agent-runtime/src/cli.ts +30 -4
- package/templates/collections-agent/packages/agent-runtime/src/commands/check.ts +18 -2
- package/templates/collections-agent/packages/agent-runtime/src/commands/decide.ts +13 -4
- package/templates/collections-agent/packages/agent-runtime/src/commands/eval.ts +7 -2
- package/templates/collections-agent/packages/agent-runtime/src/commands/inspect.ts +11 -13
- package/templates/collections-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +32 -24
- package/templates/collections-agent/packages/agent-runtime/src/commands/poll.ts +12 -5
- package/templates/collections-agent/packages/agent-runtime/src/commands/rerun.ts +83 -10
- package/templates/collections-agent/packages/agent-runtime/src/commands/resume.ts +2 -1
- package/templates/collections-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +10 -5
- package/templates/collections-agent/packages/agent-runtime/src/commands/start.ts +48 -17
- package/templates/collections-agent/packages/agent-runtime/src/commands/verify.ts +37 -12
- package/templates/collections-agent/packages/agent-runtime/src/commands/webhook.ts +11 -3
- package/templates/collections-agent/packages/agent-runtime/src/default-kit.ts +52 -22
- package/templates/collections-agent/packages/agent-runtime/src/env.ts +64 -0
- package/templates/collections-agent/packages/agent-runtime/src/index.ts +2 -0
- package/templates/collections-agent/packages/agent-runtime/src/inspect.ts +81 -10
- package/templates/collections-agent/packages/agent-runtime/src/kit.ts +34 -12
- package/templates/collections-agent/packages/agent-runtime/src/outcome.ts +118 -0
- package/templates/collections-agent/packages/agent-runtime/src/poll.ts +7 -7
- package/templates/collections-agent/packages/agent-runtime/src/runs.ts +51 -0
- package/templates/collections-agent/packages/agent-runtime/src/scenarios.ts +55 -8
- package/templates/collections-agent/packages/agent-runtime/src/setup.ts +75 -5
- package/templates/collections-agent/packages/agent-runtime/src/terminal.ts +71 -33
- package/templates/collections-agent/packages/agent-runtime/test/env-names.test.ts +56 -0
- package/templates/collections-agent/packages/agent-runtime/test/inspect-mandate-status.test.ts +80 -0
- package/templates/collections-agent/packages/agent-runtime/test/inspect.test.ts +63 -2
- package/templates/collections-agent/packages/agent-runtime/test/outcome.test.ts +72 -0
- package/templates/collections-agent/packages/agent-runtime/test/poll-payer.test.ts +64 -0
- package/templates/collections-agent/packages/agent-runtime/test/rerun-not-replayed.test.ts +46 -0
- package/templates/collections-agent/packages/agent-runtime/test/transition-line.test.ts +29 -0
- package/templates/collections-agent/packages/agent-runtime/test/verify-cli.test.ts +99 -6
- package/templates/collections-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +8 -0
- package/templates/collections-agent/packages/agent-runtime/test/whatsapp-session.test.ts +77 -0
- package/templates/collections-agent/packages/agent-runtime/test/whatsapp-status-replies.test.ts +27 -1
- package/templates/hello-agent/README.md +2 -2
- package/templates/hello-agent/agents/hello-agent/README.md +6 -0
- package/templates/hello-agent/agents/hello-agent/SYSTEM_PROMPT.md +27 -13
- package/templates/hello-agent/agents/hello-agent/agent.yaml +2 -1
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/exfiltration.transcript.jsonl +1 -1
- package/templates/hello-agent/agents/hello-agent/evals/adversarial/prompt-injection.transcript.jsonl +1 -1
- package/templates/hello-agent/agents/hello-agent/mandate.example.json +1 -1
- package/templates/hello-agent/agents/hello-agent/scenarios/happy-path.json +1 -1
- package/templates/hello-agent/agents/hello-agent/scenarios/happy-path.transcript.jsonl +1 -1
- package/templates/hello-agent/agents/hello-agent/scenarios/prompt-injection.json +1 -1
- package/templates/hello-agent/agents/hello-agent/scenarios/prompt-injection.transcript.jsonl +1 -1
- package/templates/hello-agent/agents/hello-agent/src/bills.ts +9 -5
- package/templates/hello-agent/agents/hello-agent/src/kit.ts +4 -1
- package/templates/hello-agent/agents/hello-agent/tools.json +1 -1
- package/templates/hello-agent/packages/agent-core/README.md +21 -2
- package/templates/hello-agent/packages/agent-core/package.json +1 -1
- package/templates/hello-agent/packages/agent-core/src/agent.ts +33 -6
- package/templates/hello-agent/packages/agent-core/src/api/charge-rail.ts +15 -1
- package/templates/hello-agent/packages/agent-core/src/api/rail.ts +11 -5
- package/templates/hello-agent/packages/agent-core/src/api/sandbox-payer.ts +36 -0
- package/templates/hello-agent/packages/agent-core/src/bundle.ts +2 -0
- package/templates/hello-agent/packages/agent-core/src/channels.ts +18 -8
- package/templates/hello-agent/packages/agent-core/src/check.ts +25 -3
- package/templates/hello-agent/packages/agent-core/src/engine.ts +90 -9
- package/templates/hello-agent/packages/agent-core/src/escalate.ts +10 -0
- package/templates/hello-agent/packages/agent-core/src/index.ts +3 -0
- package/templates/hello-agent/packages/agent-core/src/language.ts +52 -0
- package/templates/hello-agent/packages/agent-core/src/locale.ts +88 -0
- package/templates/hello-agent/packages/agent-core/src/manifest.ts +4 -1
- package/templates/hello-agent/packages/agent-core/src/rail.ts +29 -1
- package/templates/hello-agent/packages/agent-core/src/receipt-verification.ts +30 -2
- package/templates/hello-agent/packages/agent-core/src/secrets.ts +53 -8
- package/templates/hello-agent/packages/agent-core/src/state-machine.ts +14 -0
- package/templates/hello-agent/packages/agent-core/src/strings.ts +175 -0
- package/templates/hello-agent/packages/agent-core/src/stubs/charge-rail.ts +15 -2
- package/templates/hello-agent/packages/agent-core/src/stubs/rail.ts +7 -4
- package/templates/hello-agent/packages/agent-core/src/types.ts +15 -2
- package/templates/hello-agent/packages/agent-core/test/actor-on-the-wire.test.ts +144 -0
- package/templates/hello-agent/packages/agent-core/test/attempt-replay.test.ts +2 -2
- package/templates/hello-agent/packages/agent-core/test/engine.test.ts +23 -0
- package/templates/hello-agent/packages/agent-core/test/helpers.ts +1 -1
- package/templates/hello-agent/packages/agent-core/test/language.test.ts +40 -0
- package/templates/hello-agent/packages/agent-core/test/locale.test.ts +137 -0
- package/templates/hello-agent/packages/agent-core/test/mandate-status.test.ts +2 -2
- package/templates/hello-agent/packages/agent-core/test/manifest.test.ts +2 -2
- package/templates/hello-agent/packages/agent-core/test/rail-errors.test.ts +74 -0
- package/templates/hello-agent/packages/agent-core/test/receipt-read-verification.test.ts +32 -0
- package/templates/hello-agent/packages/agent-core/test/receivables.test.ts +49 -0
- package/templates/hello-agent/packages/agent-core/test/recorded-turns.ts +29 -0
- package/templates/hello-agent/packages/agent-core/test/secrets.test.ts +40 -1
- package/templates/hello-agent/packages/agent-runtime/README.md +31 -4
- package/templates/hello-agent/packages/agent-runtime/src/channels/rules.ts +4 -2
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +11 -5
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +43 -21
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +3 -0
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +8 -12
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +8 -4
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +12 -9
- package/templates/hello-agent/packages/agent-runtime/src/cli.ts +30 -4
- package/templates/hello-agent/packages/agent-runtime/src/commands/check.ts +18 -2
- package/templates/hello-agent/packages/agent-runtime/src/commands/decide.ts +13 -4
- package/templates/hello-agent/packages/agent-runtime/src/commands/eval.ts +7 -2
- package/templates/hello-agent/packages/agent-runtime/src/commands/inspect.ts +11 -13
- package/templates/hello-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +32 -24
- package/templates/hello-agent/packages/agent-runtime/src/commands/poll.ts +12 -5
- package/templates/hello-agent/packages/agent-runtime/src/commands/rerun.ts +83 -10
- package/templates/hello-agent/packages/agent-runtime/src/commands/resume.ts +2 -1
- package/templates/hello-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +10 -5
- package/templates/hello-agent/packages/agent-runtime/src/commands/start.ts +48 -17
- package/templates/hello-agent/packages/agent-runtime/src/commands/verify.ts +37 -12
- package/templates/hello-agent/packages/agent-runtime/src/commands/webhook.ts +11 -3
- package/templates/hello-agent/packages/agent-runtime/src/default-kit.ts +52 -22
- package/templates/hello-agent/packages/agent-runtime/src/env.ts +64 -0
- package/templates/hello-agent/packages/agent-runtime/src/index.ts +2 -0
- package/templates/hello-agent/packages/agent-runtime/src/inspect.ts +81 -10
- package/templates/hello-agent/packages/agent-runtime/src/kit.ts +34 -12
- package/templates/hello-agent/packages/agent-runtime/src/outcome.ts +118 -0
- package/templates/hello-agent/packages/agent-runtime/src/poll.ts +7 -7
- package/templates/hello-agent/packages/agent-runtime/src/runs.ts +51 -0
- package/templates/hello-agent/packages/agent-runtime/src/scenarios.ts +55 -8
- package/templates/hello-agent/packages/agent-runtime/src/setup.ts +75 -5
- package/templates/hello-agent/packages/agent-runtime/src/terminal.ts +71 -33
- package/templates/hello-agent/packages/agent-runtime/test/env-names.test.ts +56 -0
- package/templates/hello-agent/packages/agent-runtime/test/inspect-mandate-status.test.ts +80 -0
- package/templates/hello-agent/packages/agent-runtime/test/inspect.test.ts +63 -2
- package/templates/hello-agent/packages/agent-runtime/test/outcome.test.ts +72 -0
- package/templates/hello-agent/packages/agent-runtime/test/poll-payer.test.ts +64 -0
- package/templates/hello-agent/packages/agent-runtime/test/rerun-not-replayed.test.ts +46 -0
- package/templates/hello-agent/packages/agent-runtime/test/transition-line.test.ts +29 -0
- package/templates/hello-agent/packages/agent-runtime/test/verify-cli.test.ts +99 -6
- package/templates/hello-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +8 -0
- package/templates/hello-agent/packages/agent-runtime/test/whatsapp-session.test.ts +77 -0
- package/templates/hello-agent/packages/agent-runtime/test/whatsapp-status-replies.test.ts +27 -1
- package/templates/kits.lock.json +12 -12
- package/templates/supplier-payments-agent/README.md +2 -2
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/.env.example +2 -2
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/README.md +12 -7
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/SYSTEM_PROMPT.md +14 -3
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/agent.yaml +2 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/exfiltration.transcript.jsonl +1 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/false-authority.transcript.jsonl +1 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/evals/adversarial/prompt-injection.transcript.jsonl +1 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/mandate.example.json +3 -3
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/beneficiary-not-allowed.transcript.jsonl +1 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/cap-exceeded.transcript.jsonl +1 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/escalated-above-threshold.transcript.jsonl +5 -5
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/happy-path.transcript.jsonl +1 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/mandate-revoked.transcript.jsonl +5 -5
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/partial-batch-failure.json +1 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/partial-batch-failure.transcript.jsonl +1 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/scenarios/prompt-injection.transcript.jsonl +1 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/src/kit.ts +37 -26
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/src/modules/batch-payout.ts +41 -14
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/src/modules/pix-out.ts +12 -3
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/src/payables.ts +8 -8
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/test/batch.test.ts +75 -10
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/test/locale.test.ts +101 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/test/run-outcome.test.ts +127 -0
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/tools.json +1 -1
- package/templates/supplier-payments-agent/packages/agent-core/README.md +21 -2
- package/templates/supplier-payments-agent/packages/agent-core/package.json +1 -1
- package/templates/supplier-payments-agent/packages/agent-core/src/agent.ts +33 -6
- package/templates/supplier-payments-agent/packages/agent-core/src/api/charge-rail.ts +15 -1
- package/templates/supplier-payments-agent/packages/agent-core/src/api/rail.ts +11 -5
- package/templates/supplier-payments-agent/packages/agent-core/src/api/sandbox-payer.ts +36 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/bundle.ts +2 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/channels.ts +18 -8
- package/templates/supplier-payments-agent/packages/agent-core/src/check.ts +25 -3
- package/templates/supplier-payments-agent/packages/agent-core/src/engine.ts +90 -9
- package/templates/supplier-payments-agent/packages/agent-core/src/escalate.ts +10 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/index.ts +3 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/language.ts +52 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/locale.ts +88 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/manifest.ts +4 -1
- package/templates/supplier-payments-agent/packages/agent-core/src/rail.ts +29 -1
- package/templates/supplier-payments-agent/packages/agent-core/src/receipt-verification.ts +30 -2
- package/templates/supplier-payments-agent/packages/agent-core/src/secrets.ts +53 -8
- package/templates/supplier-payments-agent/packages/agent-core/src/state-machine.ts +14 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/strings.ts +175 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/stubs/charge-rail.ts +15 -2
- package/templates/supplier-payments-agent/packages/agent-core/src/stubs/rail.ts +7 -4
- package/templates/supplier-payments-agent/packages/agent-core/src/types.ts +15 -2
- package/templates/supplier-payments-agent/packages/agent-core/test/actor-on-the-wire.test.ts +144 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/attempt-replay.test.ts +2 -2
- package/templates/supplier-payments-agent/packages/agent-core/test/engine.test.ts +23 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/helpers.ts +1 -1
- package/templates/supplier-payments-agent/packages/agent-core/test/language.test.ts +40 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/locale.test.ts +137 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/mandate-status.test.ts +2 -2
- package/templates/supplier-payments-agent/packages/agent-core/test/manifest.test.ts +2 -2
- package/templates/supplier-payments-agent/packages/agent-core/test/rail-errors.test.ts +74 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/receipt-read-verification.test.ts +32 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/receivables.test.ts +49 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/recorded-turns.ts +29 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/secrets.test.ts +40 -1
- package/templates/supplier-payments-agent/packages/agent-runtime/README.md +31 -4
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/rules.ts +4 -2
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +11 -5
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +43 -21
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +3 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +8 -12
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +8 -4
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +12 -9
- package/templates/supplier-payments-agent/packages/agent-runtime/src/cli.ts +30 -4
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/check.ts +18 -2
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/decide.ts +13 -4
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/eval.ts +7 -2
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/inspect.ts +11 -13
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +32 -24
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/poll.ts +12 -5
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/rerun.ts +83 -10
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/resume.ts +2 -1
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +10 -5
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/start.ts +48 -17
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/verify.ts +37 -12
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/webhook.ts +11 -3
- package/templates/supplier-payments-agent/packages/agent-runtime/src/default-kit.ts +52 -22
- package/templates/supplier-payments-agent/packages/agent-runtime/src/env.ts +64 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/index.ts +2 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/inspect.ts +81 -10
- package/templates/supplier-payments-agent/packages/agent-runtime/src/kit.ts +34 -12
- package/templates/supplier-payments-agent/packages/agent-runtime/src/outcome.ts +118 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/poll.ts +7 -7
- package/templates/supplier-payments-agent/packages/agent-runtime/src/runs.ts +51 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/scenarios.ts +55 -8
- package/templates/supplier-payments-agent/packages/agent-runtime/src/setup.ts +75 -5
- package/templates/supplier-payments-agent/packages/agent-runtime/src/terminal.ts +71 -33
- package/templates/supplier-payments-agent/packages/agent-runtime/test/env-names.test.ts +56 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/inspect-mandate-status.test.ts +80 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/inspect.test.ts +63 -2
- package/templates/supplier-payments-agent/packages/agent-runtime/test/outcome.test.ts +72 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/poll-payer.test.ts +64 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/rerun-not-replayed.test.ts +46 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/transition-line.test.ts +29 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/verify-cli.test.ts +99 -6
- package/templates/supplier-payments-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +8 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/whatsapp-session.test.ts +77 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/whatsapp-status-replies.test.ts +27 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Every turn a person types in a recorded scenario or WhatsApp conversation
|
|
6
|
+
* under `root/agents`: all Portuguese. `root` is this repository, with every
|
|
7
|
+
* agent, or a scaffold made by `codespar init --template`, with one.
|
|
8
|
+
*/
|
|
9
|
+
export function recordedTurns(root: string): string[] {
|
|
10
|
+
const out: string[] = [];
|
|
11
|
+
for (const agent of readdirSync(join(root, "agents"))) {
|
|
12
|
+
for (const dir of ["scenarios", join("channels", "whatsapp")]) {
|
|
13
|
+
let files: string[] = [];
|
|
14
|
+
try {
|
|
15
|
+
files = readdirSync(join(root, "agents", agent, dir)).filter((f) => f.endsWith(".json") && f !== "templates.json");
|
|
16
|
+
} catch {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
for (const f of files) {
|
|
20
|
+
const doc = JSON.parse(readFileSync(join(root, "agents", agent, dir, f), "utf8")) as { turns?: Array<{ input?: string; text?: string }> };
|
|
21
|
+
for (const t of doc.turns ?? []) {
|
|
22
|
+
const text = t.input ?? t.text;
|
|
23
|
+
if (typeof text === "string") out.push(text);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import { createCodeSparClient } from "../src/api/client.js";
|
|
3
|
-
import { assertTestKey, isTestKey, NotATestKeyError, redactKey } from "../src/secrets.js";
|
|
3
|
+
import { assertTestKey, CODESPAR_KEY_PLACEHOLDER, isTestKey, NotATestKeyError, redactKey, testKeyMessage, testKeyProblem } from "../src/secrets.js";
|
|
4
4
|
|
|
5
5
|
// Built at runtime so the secret scan (which refuses key-shaped literals) stays honest about this file.
|
|
6
6
|
const TEST = ["csk", "test", "0123456789abcdef"].join("_");
|
|
@@ -21,6 +21,45 @@ describe("sandbox by construction", () => {
|
|
|
21
21
|
expect(createCodeSparClient({ apiKey: TEST })).toBeDefined();
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
+
it("tells the three mistakes apart (#50): no key, the placeholder, a key that is not a test key", () => {
|
|
25
|
+
for (const missing of [undefined, "", " "]) expect(testKeyProblem(missing)).toBe("missing");
|
|
26
|
+
expect(testKeyProblem(CODESPAR_KEY_PLACEHOLDER)).toBe("placeholder");
|
|
27
|
+
expect(testKeyProblem(LIVE)).toBe("not_test");
|
|
28
|
+
expect(testKeyProblem("csk_test_")).toBe("not_test");
|
|
29
|
+
expect(testKeyProblem(TEST)).toBeUndefined();
|
|
30
|
+
expect(isTestKey(CODESPAR_KEY_PLACEHOLDER)).toBe(false);
|
|
31
|
+
for (const [key, problem] of [[undefined, "missing"], [CODESPAR_KEY_PLACEHOLDER, "placeholder"], [LIVE, "not_test"]] as const) {
|
|
32
|
+
try {
|
|
33
|
+
assertTestKey(key);
|
|
34
|
+
throw new Error("accepted");
|
|
35
|
+
} catch (err) {
|
|
36
|
+
expect(err).toBeInstanceOf(NotATestKeyError);
|
|
37
|
+
expect((err as NotATestKeyError).problem).toBe(problem);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("gives each its own remediation, naming the file the agent reads", () => {
|
|
43
|
+
const file = "agents/bills-agent/.env";
|
|
44
|
+
const missing = testKeyMessage("missing", file);
|
|
45
|
+
const placeholder = testKeyMessage("placeholder", file);
|
|
46
|
+
const live = testKeyMessage("not_test", file);
|
|
47
|
+
expect(missing).toContain("CODESPAR_API_KEY is not set");
|
|
48
|
+
expect(missing).toContain(`copy ${file}.example to ${file}`);
|
|
49
|
+
expect(missing).not.toContain("live");
|
|
50
|
+
expect(placeholder).toContain(`still the placeholder from .env.example (${CODESPAR_KEY_PLACEHOLDER})`);
|
|
51
|
+
expect(placeholder).toContain(file);
|
|
52
|
+
expect(placeholder).not.toContain("live");
|
|
53
|
+
expect(live).toContain("a live key is refused");
|
|
54
|
+
expect(new Set([missing, placeholder, live]).size).toBe(3);
|
|
55
|
+
expect(new NotATestKeyError("missing", file).message).toBe(missing);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("refuses to build a client on the placeholder too, before any network", () => {
|
|
59
|
+
expect(() => createCodeSparClient({ apiKey: CODESPAR_KEY_PLACEHOLDER })).toThrow(/placeholder/);
|
|
60
|
+
expect(() => createCodeSparClient({ apiKey: undefined })).toThrow(/is not set/);
|
|
61
|
+
});
|
|
62
|
+
|
|
24
63
|
it("redacts keys for logs", () => {
|
|
25
64
|
expect(redactKey(TEST)).toBe("csk_test_…cdef");
|
|
26
65
|
expect(redactKey(TEST)).not.toContain("0123456789");
|
|
@@ -33,11 +33,33 @@ nothing else.
|
|
|
33
33
|
`--conversation`, `--scripted`), `consent`, `approve`, `deny`, `resume`,
|
|
34
34
|
`rerun`, `reconcile`, `inspect` (`--json`, `--html <file>`), `poll`
|
|
35
35
|
(`--channel`, `--conversation`, `--backend`, `--wait`, `--simulate-payer`,
|
|
36
|
-
`--payer`, `--now`, `--json`), `webhook`, `check`, `eval
|
|
36
|
+
`--payer`, `--now`, `--json`), `webhook`, `check`, `eval`, `verify`
|
|
37
|
+
(`--from-api`, `--json`, `--keys`/`--url`, `--approval`), which needs no
|
|
38
|
+
agent directory.
|
|
39
|
+
- What a report says about a settlement the API replayed: the terminal line
|
|
40
|
+
"já estava pago", `replayed` on the executions of a paying agent's one-shot
|
|
41
|
+
`--json`, and "replayed, not paid by this run" in `inspect`. The first two
|
|
42
|
+
read agent-core's `isReplayedSettlement`; `inspect` reads the same mark from
|
|
43
|
+
the bundle's rail answers (`docs/OPEN_QUESTIONS.md` §39c).
|
|
44
|
+
- What `verify` prints: the verdict, the chain it recomputed, the approval it
|
|
45
|
+
matched and, off a body that bound, `sandbox` and `money_moved` as the chain
|
|
46
|
+
sealed them. Nothing else of the API's read, which still carries
|
|
47
|
+
`mandate.sig` (§47).
|
|
37
48
|
- Setup: the manifest, the guardrails, the tools file, the system prompt, the
|
|
38
49
|
local state, the signer, the proof bundle, the provider (Anthropic with a
|
|
39
50
|
real key, replay without one), and the pinned clock (`--now`,
|
|
40
|
-
`CODESPAR_AGENT_NOW`).
|
|
51
|
+
`CODESPAR_AGENT_NOW`), which also pins the `today` the list tools return.
|
|
52
|
+
- The locale of what the code prints (#64). `setup` resolves it once per run:
|
|
53
|
+
`--locale`, else `locale:` in `agent.yaml`, else `pt-BR`, and records it in
|
|
54
|
+
the bundle's `run.json`. The terminal's own lines come from agent-core's
|
|
55
|
+
`CORE_STRINGS` and the kit's from `kit.strings`, both in that locale; the
|
|
56
|
+
parsers do not change with it (`parseApproval`, `parseBatchGesture` read both
|
|
57
|
+
languages whatever is shown). A command that tells an outcome later (`poll`,
|
|
58
|
+
`webhook`, `approve`) tells the counterparty in the locale of the run that
|
|
59
|
+
proposed it, and `poll --channel whatsapp` sends the template copy in the
|
|
60
|
+
conversation's recorded language and refuses a `--locale` that disagrees.
|
|
61
|
+
The model's reply language is a different thing, read per turn from what
|
|
62
|
+
the person types.
|
|
41
63
|
- The section 9 adversarial runner and the section 12 scenario runner.
|
|
42
64
|
- The `csk_test_` guard and the `.env.example` placeholder rule.
|
|
43
65
|
|
|
@@ -57,11 +79,16 @@ export const agent = defineAgent(import.meta.url, {
|
|
|
57
79
|
```
|
|
58
80
|
|
|
59
81
|
`AgentKit` (in `src/kit.ts`) is the whole seam: the rail adapter
|
|
60
|
-
(`buildRail`), the tool handlers, the `policyExtension`, the console
|
|
61
|
-
|
|
82
|
+
(`buildRail`), the tool handlers, the `policyExtension`, the console words
|
|
83
|
+
(`strings`, one entry per locale, and `labels`, which holds what must not vary
|
|
84
|
+
by locale: who approves and the record kinds), what a one-shot prints as JSON, and — for an agent whose money comes IN — the
|
|
62
85
|
sandbox payer and the one message per outcome. An agent that declares none of
|
|
63
86
|
it gets `defaultKit`: the stub rail, the example mandate, no tools.
|
|
64
87
|
|
|
88
|
+
`npm run check` fails when a key of `kit.strings` or of `CORE_STRINGS` is
|
|
89
|
+
missing from one locale (`strings_incomplete`), so an English run never prints
|
|
90
|
+
`undefined` where a Portuguese one prints a word.
|
|
91
|
+
|
|
65
92
|
`defineAgent(import.meta.url, kit)` finds the nearest `agent.yaml` above the
|
|
66
93
|
module, which is what makes every path (`scenarios/`, `evals/`, `.codespar/`,
|
|
67
94
|
`runs/`) and every test-only environment variable (`BILLS_STATE_DIR`,
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* Every rule can only REFUSE. None of them rewrites a message: a message
|
|
25
25
|
* that is edited on the way out is not the message the transcript shows.
|
|
26
26
|
*/
|
|
27
|
-
import { isOutsideHours, localClock } from "@codespar/agent-core";
|
|
27
|
+
import { CORE_STRINGS, isOutsideHours, localClock, type Locale } from "@codespar/agent-core";
|
|
28
28
|
import type { Conversation, OutboundBody } from "./types.js";
|
|
29
29
|
|
|
30
30
|
export interface ChannelRefusal {
|
|
@@ -44,6 +44,8 @@ export interface RuleContext {
|
|
|
44
44
|
now: () => Date;
|
|
45
45
|
/** Agreement aliases this agent knows, so "names another agreement" is decidable. */
|
|
46
46
|
knownSubjects?: readonly string[] | undefined;
|
|
47
|
+
/** The language of the refusal details. It never changes what is refused. Default pt-BR. */
|
|
48
|
+
locale?: Locale | undefined;
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
/** `123.456.789-00`, `12345678900`, `12.345.678/0001-95`, `12345678000195`. */
|
|
@@ -90,7 +92,7 @@ export function checkOutbound(to: string, body: OutboundBody, ctx: RuleContext):
|
|
|
90
92
|
if (isOutsideHours(`${close}-${open}`, ctx.now(), ctx.hours.timezone)) {
|
|
91
93
|
return {
|
|
92
94
|
rule: "collection_hours",
|
|
93
|
-
detail:
|
|
95
|
+
detail: CORE_STRINGS[ctx.locale ?? "pt-BR"].outsideCollectionHours(ctx.hours.window, ctx.hours.timezone, localClock(ctx.now(), ctx.hours.timezone)),
|
|
94
96
|
};
|
|
95
97
|
}
|
|
96
98
|
}
|
package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* fetches `@dyvit/whatsapp-simulator-cli` at a pinned version and runs it;
|
|
26
26
|
* `npm run whatsapp:emulator` is the command.
|
|
27
27
|
*/
|
|
28
|
-
import type
|
|
28
|
+
import { CORE_STRINGS, type ConversationScript, type Locale } from "@codespar/agent-core";
|
|
29
29
|
import type { ChannelBackend, InboundMessage, OutboundBody, SentMessage, StatusUpdate } from "../types.js";
|
|
30
30
|
import { WhatsAppCloudApi, type CloudApiOptions } from "./cloud-api.js";
|
|
31
31
|
|
|
@@ -129,6 +129,8 @@ export interface EmulatorBackendOptions extends CloudApiOptions {
|
|
|
129
129
|
ask?: ((question: string) => Promise<string>) | undefined;
|
|
130
130
|
/** Where the console draws the conversation as it goes. */
|
|
131
131
|
render: (line: string) => void;
|
|
132
|
+
/** The language of the console lines above. Default pt-BR. */
|
|
133
|
+
locale?: Locale | undefined;
|
|
132
134
|
}
|
|
133
135
|
|
|
134
136
|
/**
|
|
@@ -147,7 +149,7 @@ export class WhatsAppEmulator implements ChannelBackend {
|
|
|
147
149
|
private closed = false;
|
|
148
150
|
|
|
149
151
|
constructor(private readonly options: EmulatorBackendOptions) {
|
|
150
|
-
const { driver: _driver, script: _script, pinAt: _pinAt, ask: _ask, render: _render, ...api } = options;
|
|
152
|
+
const { driver: _driver, script: _script, pinAt: _pinAt, ask: _ask, render: _render, locale: _locale, ...api } = options;
|
|
151
153
|
this.api = new WhatsAppCloudApi(api);
|
|
152
154
|
}
|
|
153
155
|
|
|
@@ -156,7 +158,7 @@ export class WhatsAppEmulator implements ChannelBackend {
|
|
|
156
158
|
await this.options.driver.health();
|
|
157
159
|
if (this.options.pinAt) await this.options.driver.pin(this.options.pinAt);
|
|
158
160
|
this.options.render("");
|
|
159
|
-
this.options.render(
|
|
161
|
+
this.options.render(this.text.waEmulatorOpen);
|
|
160
162
|
}
|
|
161
163
|
|
|
162
164
|
async next(): Promise<InboundMessage | undefined> {
|
|
@@ -193,7 +195,7 @@ export class WhatsAppEmulator implements ChannelBackend {
|
|
|
193
195
|
if (!this.options.ask) return undefined;
|
|
194
196
|
let answer: string;
|
|
195
197
|
try {
|
|
196
|
-
answer = await this.options.ask(
|
|
198
|
+
answer = await this.options.ask(this.text.waYou);
|
|
197
199
|
} catch {
|
|
198
200
|
return undefined;
|
|
199
201
|
}
|
|
@@ -207,10 +209,14 @@ export class WhatsAppEmulator implements ChannelBackend {
|
|
|
207
209
|
return this.api.deliver(to, body);
|
|
208
210
|
}
|
|
209
211
|
|
|
212
|
+
private get text() {
|
|
213
|
+
return CORE_STRINGS[this.options.locale ?? "pt-BR"];
|
|
214
|
+
}
|
|
215
|
+
|
|
210
216
|
async close(): Promise<void> {
|
|
211
217
|
if (this.closed) return;
|
|
212
218
|
this.closed = true;
|
|
213
219
|
await this.api.close();
|
|
214
|
-
this.options.render(
|
|
220
|
+
this.options.render(this.text.waEmulatorClosed);
|
|
215
221
|
}
|
|
216
222
|
}
|
|
@@ -13,12 +13,22 @@
|
|
|
13
13
|
* caller and have no path to this object at all — not a check, a shape: there
|
|
14
14
|
* is no method here that an operator line could be handed to.
|
|
15
15
|
*/
|
|
16
|
-
import { declaredReplies, type ProofBundle, type QuickReply, type WhatsAppTemplate } from "@codespar/agent-core";
|
|
16
|
+
import { CORE_STRINGS, WHATSAPP_LANGUAGE, declaredReplies, type CoreStrings, type Locale, type ProofBundle, type QuickReply, type WhatsAppTemplate } from "@codespar/agent-core";
|
|
17
17
|
import { checkOutbound, type HoursRule, type RuleContext } from "../rules.js";
|
|
18
18
|
import type { Channel, ChannelBackend, ChannelLogLine, Conversation, DeliveryState, InboundMessage, OutboundBody, SentMessage, StatusUpdate } from "../types.js";
|
|
19
19
|
import { maskContact } from "../contact.js";
|
|
20
20
|
import { SessionWindow, type SessionState } from "./session.js";
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* How far along a message a status puts it. Status webhooks are not ordered:
|
|
24
|
+
* the emulator dispatches a send's own `sent` and `delivered` while a status
|
|
25
|
+
* posted meanwhile goes out between them, and Meta does not promise order
|
|
26
|
+
* either. A `delivered` that lands after a `failed` must not un-fail the
|
|
27
|
+
* message (#63), so `failed` ranks above everything, and a late `sent` does
|
|
28
|
+
* not rewind a `read`.
|
|
29
|
+
*/
|
|
30
|
+
const PROGRESS: Record<DeliveryState, number> = { queued: 0, sent: 1, delivered: 2, read: 3, failed: 4 };
|
|
31
|
+
|
|
22
32
|
export interface WhatsAppChannelOptions {
|
|
23
33
|
backend: ChannelBackend;
|
|
24
34
|
conversation: Conversation;
|
|
@@ -52,6 +62,12 @@ export interface WhatsAppChannelOptions {
|
|
|
52
62
|
onDeliveryFailed?: ((line: ChannelLogLine) => void) | undefined;
|
|
53
63
|
/** Lines an earlier run wrote for this conversation, so a status about a message it sent can be tied back to what that message was. */
|
|
54
64
|
priorLines?: ReadonlyArray<ChannelLogLine> | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* The conversation's locale. It picks the language of every template this
|
|
67
|
+
* channel sends and of the quick replies it reads a tap by, and the words of
|
|
68
|
+
* the operator's lines. Fixed for the conversation. Default pt-BR.
|
|
69
|
+
*/
|
|
70
|
+
locale?: Locale | undefined;
|
|
55
71
|
}
|
|
56
72
|
|
|
57
73
|
export class WhatsAppChannel implements Channel {
|
|
@@ -61,7 +77,7 @@ export class WhatsAppChannel implements Channel {
|
|
|
61
77
|
private readonly lines: ChannelLogLine[] = [];
|
|
62
78
|
private lastInbound: InboundMessage | undefined;
|
|
63
79
|
private readonly replies: Map<string, QuickReply>;
|
|
64
|
-
/** The
|
|
80
|
+
/** The furthest state the provider reported per message id (`PROGRESS`), this process. */
|
|
65
81
|
private readonly delivery = new Map<string, DeliveryState>();
|
|
66
82
|
/**
|
|
67
83
|
* Failures reported for a message not yet in the log. A provider can post
|
|
@@ -71,10 +87,16 @@ export class WhatsAppChannel implements Channel {
|
|
|
71
87
|
*/
|
|
72
88
|
private readonly earlyFailures = new Map<string, ChannelLogLine>();
|
|
73
89
|
|
|
90
|
+
/** Meta's language code for this conversation: the one every template send carries. */
|
|
91
|
+
readonly language: string;
|
|
92
|
+
private readonly text: CoreStrings;
|
|
93
|
+
|
|
74
94
|
constructor(private readonly options: WhatsAppChannelOptions) {
|
|
75
95
|
this.conversation = options.conversation;
|
|
96
|
+
this.language = WHATSAPP_LANGUAGE[options.locale ?? "pt-BR"];
|
|
97
|
+
this.text = CORE_STRINGS[options.locale ?? "pt-BR"];
|
|
76
98
|
this.session = new SessionWindow(options.templates ?? [], options.session);
|
|
77
|
-
this.replies = declaredReplies(options.templates ?? []);
|
|
99
|
+
this.replies = declaredReplies(options.templates ?? [], this.language);
|
|
78
100
|
}
|
|
79
101
|
|
|
80
102
|
get backend(): string {
|
|
@@ -111,9 +133,9 @@ export class WhatsAppChannel implements Channel {
|
|
|
111
133
|
return (this.options.templates ?? []).find((t) => t.fallback)?.name;
|
|
112
134
|
}
|
|
113
135
|
|
|
114
|
-
/**
|
|
136
|
+
/** The copy of a template declared in this conversation's language, for a caller about to send it. */
|
|
115
137
|
declaredTemplate(name: string): WhatsAppTemplate | undefined {
|
|
116
|
-
return this.session.declared(name);
|
|
138
|
+
return this.session.declared(name, this.language);
|
|
117
139
|
}
|
|
118
140
|
|
|
119
141
|
async open(): Promise<void> {
|
|
@@ -160,7 +182,7 @@ export class WhatsAppChannel implements Channel {
|
|
|
160
182
|
: undefined;
|
|
161
183
|
if (refusal) {
|
|
162
184
|
this.record({ ...base, kind: "reply", reply: tapped, refused: refusal });
|
|
163
|
-
this.options.say?.(
|
|
185
|
+
this.options.say?.(this.text.waTapIgnored(refusal.rule, refusal.detail));
|
|
164
186
|
continue;
|
|
165
187
|
}
|
|
166
188
|
this.record({ ...base, kind: "reply", reply: tapped, text: declared!.intent });
|
|
@@ -182,7 +204,8 @@ export class WhatsAppChannel implements Channel {
|
|
|
182
204
|
*/
|
|
183
205
|
private observeStatus(status: StatusUpdate): void {
|
|
184
206
|
const sent = [...(this.options.priorLines ?? []), ...this.lines].find((l) => l.direction === "out" && l.message_id === status.message_id);
|
|
185
|
-
this.delivery.
|
|
207
|
+
const known = this.delivery.get(status.message_id);
|
|
208
|
+
if (known === undefined || PROGRESS[status.status] > PROGRESS[known]) this.delivery.set(status.message_id, status.status);
|
|
186
209
|
const line: ChannelLogLine = {
|
|
187
210
|
at: this.options.now().toISOString(),
|
|
188
211
|
direction: "status",
|
|
@@ -206,13 +229,11 @@ export class WhatsAppChannel implements Channel {
|
|
|
206
229
|
private reportFailure(line: ChannelLogLine): void {
|
|
207
230
|
const status = { message_id: line.message_id, errors: line.errors ?? [] };
|
|
208
231
|
const codes = status.errors.map((e) => `${e.code ?? "?"}${e.details ? ` ${e.details}` : ""}`).join("; ") || "no error given";
|
|
209
|
-
this.options.say?.(
|
|
210
|
-
` [operador] ENTREGA FALHOU da mensagem ${status.message_id} (${codes})${line.about ? ` — era o aviso de ${line.about.execution_id} (${line.about.state}): a pessoa NAO foi avisada` : ""}`,
|
|
211
|
-
);
|
|
232
|
+
this.options.say?.(this.text.waDeliveryFailed(status.message_id, codes, line.about ? `${line.about.execution_id} (${line.about.state})` : undefined));
|
|
212
233
|
this.options.onDeliveryFailed?.(line);
|
|
213
234
|
}
|
|
214
235
|
|
|
215
|
-
/** The
|
|
236
|
+
/** The furthest status the provider reported for a message this process saw a status for; a `failed` stays `failed`. */
|
|
216
237
|
deliveryOf(messageId: string): DeliveryState | undefined {
|
|
217
238
|
return this.delivery.get(messageId);
|
|
218
239
|
}
|
|
@@ -234,6 +255,7 @@ export class WhatsAppChannel implements Channel {
|
|
|
234
255
|
hours: this.options.hours,
|
|
235
256
|
now: this.options.now,
|
|
236
257
|
knownSubjects: this.options.knownSubjects,
|
|
258
|
+
locale: this.options.locale,
|
|
237
259
|
};
|
|
238
260
|
|
|
239
261
|
// The house rules first: a message the law refuses is not a message the provider should ever see.
|
|
@@ -241,15 +263,15 @@ export class WhatsAppChannel implements Channel {
|
|
|
241
263
|
if (refusal) {
|
|
242
264
|
const sent: SentMessage = { id: "", state: "failed", refused: refusal };
|
|
243
265
|
this.logOutbound(body, sent);
|
|
244
|
-
this.options.say?.(
|
|
266
|
+
this.options.say?.(this.text.waRefused(refusal.rule, refusal.detail));
|
|
245
267
|
return sent;
|
|
246
268
|
}
|
|
247
269
|
|
|
248
270
|
// A template carries the quick replies its declaration offers, and only those.
|
|
249
|
-
const buttons = body.kind === "template" ? this.session.declared(body.template)?.buttons : undefined;
|
|
271
|
+
const buttons = body.kind === "template" ? this.session.declared(body.template, body.language)?.buttons : undefined;
|
|
250
272
|
const outgoing: OutboundBody = body.kind === "template" && buttons?.length ? { ...body, buttons: buttons.map((b) => ({ id: b.id, title: b.title })) } : body;
|
|
251
273
|
const sent = await this.options.backend.deliver(to, outgoing);
|
|
252
|
-
if (sent.refused) this.options.say?.(
|
|
274
|
+
if (sent.refused) this.options.say?.(this.text.waRefusedByBackend(sent.refused.rule, sent.refused.detail));
|
|
253
275
|
if (sent.refused?.rule === "session_window_closed") this.session.observeProviderShut();
|
|
254
276
|
this.logOutbound(outgoing, sent);
|
|
255
277
|
return sent;
|
|
@@ -310,24 +332,24 @@ export class WhatsAppChannel implements Channel {
|
|
|
310
332
|
private record(line: ChannelLogLine): void {
|
|
311
333
|
this.lines.push(line);
|
|
312
334
|
this.options.bundle?.channel({ ...line, channel: "whatsapp", backend: this.backend });
|
|
313
|
-
this.options.render?.(` │ ${draw(line)}`);
|
|
335
|
+
this.options.render?.(` │ ${draw(line, this.text)}`);
|
|
314
336
|
}
|
|
315
337
|
}
|
|
316
338
|
|
|
317
339
|
/** One console line for one message. The refusals are visible: a message nobody got is part of the conversation's story. */
|
|
318
|
-
function draw(line: ChannelLogLine): string {
|
|
340
|
+
function draw(line: ChannelLogLine, text: CoreStrings): string {
|
|
319
341
|
if (line.direction === "status") return `(status ${line.message_id}: ${line.state}${line.errors?.length ? ` ${line.errors.map((e) => e.code).join(",")}` : ""})`;
|
|
320
|
-
if (line.kind === "reply") return `${line.contact}:
|
|
321
|
-
const who = line.direction === "in" ? `${line.contact}:` :
|
|
342
|
+
if (line.kind === "reply") return `${line.contact}: ${text.waTap(line.reply?.title ?? "?")}${line.refused ? text.waTapIgnoredMark(line.refused.rule) : ` -> ${line.text ?? ""}`}`;
|
|
343
|
+
const who = line.direction === "in" ? `${line.contact}:` : text.waShop;
|
|
322
344
|
const what =
|
|
323
345
|
line.kind === "instrument"
|
|
324
|
-
?
|
|
346
|
+
? `${text.waCopyPaste} ${line.text ?? ""}`
|
|
325
347
|
: line.kind === "media"
|
|
326
|
-
?
|
|
348
|
+
? text.waQrImage
|
|
327
349
|
: line.kind === "template"
|
|
328
350
|
? line.text ?? "[template]"
|
|
329
351
|
: line.text ?? "";
|
|
330
|
-
return line.refused ? `${who}
|
|
352
|
+
return line.refused ? `${who} ${text.waNotSent(line.refused.rule)} ${what}` : `${who} ${what}`;
|
|
331
353
|
}
|
|
332
354
|
|
|
333
355
|
function textOf(body: OutboundBody): string | undefined {
|
|
@@ -144,6 +144,7 @@ export function buildWhatsApp(options: OpenWhatsAppOptions): OpenedWhatsApp | {
|
|
|
144
144
|
driver,
|
|
145
145
|
say,
|
|
146
146
|
render: options.render ?? say,
|
|
147
|
+
locale: s.locale,
|
|
147
148
|
...(options.script ? { script: options.script } : {}),
|
|
148
149
|
...(options.ask ? { ask: options.ask } : {}),
|
|
149
150
|
...(options.pinAt ? { pinAt: options.pinAt } : {}),
|
|
@@ -166,6 +167,8 @@ export function buildWhatsApp(options: OpenWhatsAppOptions): OpenedWhatsApp | {
|
|
|
166
167
|
...(options.session ? { session: options.session } : {}),
|
|
167
168
|
...(options.priorLines ? { priorLines: options.priorLines } : {}),
|
|
168
169
|
onDeliveryFailed: (line) => recordDeliveryFailure(s, line),
|
|
170
|
+
// The run's locale, which for a poll is the conversation's recorded one: the templates go out in its language.
|
|
171
|
+
locale: s.locale,
|
|
169
172
|
});
|
|
170
173
|
|
|
171
174
|
return { channel, ...(driver ? { driver } : {}), ...(sessionKey ? { sessionKey } : {}) };
|
|
@@ -11,21 +11,22 @@
|
|
|
11
11
|
* its OWN message underneath, because a code inside a picture cannot be
|
|
12
12
|
* copied and a code inside a paragraph cannot be tapped.
|
|
13
13
|
*/
|
|
14
|
-
import type
|
|
14
|
+
import { CORE_STRINGS, formatDay, type ChargeInstrument, type Execution, type Locale } from "@codespar/agent-core";
|
|
15
15
|
import type { OutboundBody } from "../types.js";
|
|
16
16
|
|
|
17
|
-
export function instrumentBodies(execution: Execution, instalment: number, chargeId: string, instrument: ChargeInstrument, currency: string): OutboundBody[] {
|
|
18
|
-
const
|
|
17
|
+
export function instrumentBodies(execution: Execution, instalment: number, chargeId: string, instrument: ChargeInstrument, currency: string, locale: Locale = "pt-BR"): OutboundBody[] {
|
|
18
|
+
const text = CORE_STRINGS[locale];
|
|
19
|
+
const money = new Intl.NumberFormat(locale === "en" ? "en-US" : "pt-BR", { style: "currency", currency });
|
|
19
20
|
const item = execution.items[instalment - 1];
|
|
20
21
|
const count = execution.items.length;
|
|
21
22
|
const bodies: OutboundBody[] = [
|
|
22
23
|
{
|
|
23
24
|
kind: "text",
|
|
24
25
|
text: [
|
|
25
|
-
count > 1 ?
|
|
26
|
+
count > 1 ? text.instalmentOf(instalment, count) : "",
|
|
26
27
|
item ? money.format(item.amount / 100) : "",
|
|
27
|
-
instrument.due_date ?
|
|
28
|
-
|
|
28
|
+
instrument.due_date ? text.dueOn(formatDay(instrument.due_date, locale)) : "",
|
|
29
|
+
text.chargeRef(chargeId),
|
|
29
30
|
].join(""),
|
|
30
31
|
},
|
|
31
32
|
];
|
|
@@ -34,14 +35,9 @@ export function instrumentBodies(execution: Execution, instalment: number, charg
|
|
|
34
35
|
bodies.push({ kind: "instrument", instrument: "pix_copy_paste", value: instrument.pix_copy_paste });
|
|
35
36
|
}
|
|
36
37
|
if (instrument.boleto_bank_line) {
|
|
37
|
-
bodies.push({ kind: "text", text:
|
|
38
|
+
bodies.push({ kind: "text", text: text.boletoLine });
|
|
38
39
|
bodies.push({ kind: "instrument", instrument: "boleto_bank_line", value: instrument.boleto_bank_line });
|
|
39
40
|
}
|
|
40
41
|
return bodies;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
/** `2026-09-30` -> `30/09/2026`. */
|
|
44
|
-
export function formatDate(iso: string): string {
|
|
45
|
-
const [y, m, d] = iso.split("-");
|
|
46
|
-
return `${d}/${m}/${y}`;
|
|
47
|
-
}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* a code inside a picture cannot be copied and a code inside a paragraph
|
|
16
16
|
* cannot be tapped.
|
|
17
17
|
*/
|
|
18
|
-
import type { ChargeInstrument, Execution } from "@codespar/agent-core";
|
|
18
|
+
import type { ChargeInstrument, Execution, NotRunLine } from "@codespar/agent-core";
|
|
19
19
|
import { handleExecution, type TerminalOptions } from "../../terminal.js";
|
|
20
20
|
import type { Setup } from "../../setup.js";
|
|
21
21
|
import type { OutboundBody } from "../types.js";
|
|
@@ -42,6 +42,8 @@ export interface ConverseResult {
|
|
|
42
42
|
replies: string[];
|
|
43
43
|
toolCalls: Array<{ name: string; refused: boolean }>;
|
|
44
44
|
executions: Execution[];
|
|
45
|
+
/** Lines a tool did not run, across every turn: the run's count needs them. */
|
|
46
|
+
notRun: NotRunLine[];
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
/** Keeps outbound messages in the order the run produced them, across await points. */
|
|
@@ -67,10 +69,11 @@ export async function converse(options: ConverseOptions): Promise<ConverseResult
|
|
|
67
69
|
let toldOutcome = false;
|
|
68
70
|
const replies: string[] = [];
|
|
69
71
|
const toolCalls: Array<{ name: string; refused: boolean }> = [];
|
|
72
|
+
const notRun: NotRunLine[] = [];
|
|
70
73
|
let turns = 0;
|
|
71
74
|
|
|
72
75
|
const presentInstrument = (execution: Execution, instalment: number, chargeId: string, instrument: ChargeInstrument): Promise<void> => {
|
|
73
|
-
for (const body of instrumentBodies(execution, instalment, chargeId, instrument, s.mandate.currency)) outbox.push(body);
|
|
76
|
+
for (const body of instrumentBodies(execution, instalment, chargeId, instrument, s.mandate.currency, s.locale)) outbox.push(body);
|
|
74
77
|
// Awaited by the poll: the person has the code in hand before the next look, not after the cycle closed.
|
|
75
78
|
return outbox.drain();
|
|
76
79
|
};
|
|
@@ -95,7 +98,7 @@ export async function converse(options: ConverseOptions): Promise<ConverseResult
|
|
|
95
98
|
const runtime = s.makeRuntime();
|
|
96
99
|
const loop = s.makeLoop(runtime, (execution) => handleExecution(execution, terminalOptions));
|
|
97
100
|
|
|
98
|
-
say(
|
|
101
|
+
say(s.coreStrings.waBanner(s.manifest.manifest.name, s.manifest.manifest.version, channel.backend, s.mode, s.railKind, s.strings.mandateWord, s.mandate.id));
|
|
99
102
|
|
|
100
103
|
try {
|
|
101
104
|
for (;;) {
|
|
@@ -104,6 +107,7 @@ export async function converse(options: ConverseOptions): Promise<ConverseResult
|
|
|
104
107
|
turns += 1;
|
|
105
108
|
const result = await loop.turn(message.text);
|
|
106
109
|
toolCalls.push(...result.tool_calls);
|
|
110
|
+
notRun.push(...result.not_run);
|
|
107
111
|
// Whatever the execution put in the conversation goes first: the QR before the sentence that explains it.
|
|
108
112
|
await outbox.drain();
|
|
109
113
|
if (result.reply.trim()) await channel.say(result.reply);
|
|
@@ -116,5 +120,5 @@ export async function converse(options: ConverseOptions): Promise<ConverseResult
|
|
|
116
120
|
await channel.close();
|
|
117
121
|
}
|
|
118
122
|
|
|
119
|
-
return { turns, replies, toolCalls, executions: s.engine.list().filter((e) => e.run_id === s.runId) };
|
|
123
|
+
return { turns, replies, toolCalls, executions: s.engine.list().filter((e) => e.run_id === s.runId), notRun };
|
|
120
124
|
}
|
|
@@ -31,13 +31,15 @@ export interface SessionState {
|
|
|
31
31
|
export type TemplateRefusal = { rule: string; detail: string } | undefined;
|
|
32
32
|
|
|
33
33
|
export class SessionWindow {
|
|
34
|
-
|
|
34
|
+
/** Every declared copy, by name: one per language, since Meta approves a template per (name, language). */
|
|
35
|
+
private readonly templates: Map<string, WhatsAppTemplate[]>;
|
|
35
36
|
private lastInboundAt: number | undefined;
|
|
36
37
|
/** The provider said the window is shut (131047) after ours read it open. Holds until the person writes again. */
|
|
37
38
|
private shutByProvider = false;
|
|
38
39
|
|
|
39
40
|
constructor(templates: readonly WhatsAppTemplate[], initial?: SessionState) {
|
|
40
|
-
this.templates = new Map(
|
|
41
|
+
this.templates = new Map();
|
|
42
|
+
for (const t of templates) this.templates.set(t.name, [...(this.templates.get(t.name) ?? []), t]);
|
|
41
43
|
this.lastInboundAt = initial?.lastInboundAt;
|
|
42
44
|
}
|
|
43
45
|
|
|
@@ -67,9 +69,9 @@ export class SessionWindow {
|
|
|
67
69
|
return this.remainingSeconds(now) > 0;
|
|
68
70
|
}
|
|
69
71
|
|
|
70
|
-
/** The
|
|
71
|
-
declared(name: string): WhatsAppTemplate | undefined {
|
|
72
|
-
return this.templates.get(name);
|
|
72
|
+
/** The copy declared in `language`, for a caller that has to build a send. `undefined` when the name or that language was never declared. */
|
|
73
|
+
declared(name: string, language: string): WhatsAppTemplate | undefined {
|
|
74
|
+
return this.templates.get(name)?.find((t) => t.language === language);
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
/**
|
|
@@ -80,17 +82,18 @@ export class SessionWindow {
|
|
|
80
82
|
* delivers nothing, so each is refused here instead.
|
|
81
83
|
*/
|
|
82
84
|
refuse(body: { template: string; language: string; variables: readonly string[] }): TemplateRefusal {
|
|
83
|
-
const
|
|
84
|
-
if (!
|
|
85
|
+
const copies = this.templates.get(body.template);
|
|
86
|
+
if (!copies) {
|
|
85
87
|
return {
|
|
86
88
|
rule: "template_unknown",
|
|
87
89
|
detail: `the agent declares no template named ${body.template}; Meta only delivers templates it approved, and this one was never registered here`,
|
|
88
90
|
};
|
|
89
91
|
}
|
|
90
|
-
|
|
92
|
+
const declared = copies.find((t) => t.language === body.language);
|
|
93
|
+
if (!declared) {
|
|
91
94
|
return {
|
|
92
95
|
rule: "template_language_unknown",
|
|
93
|
-
detail: `${body.template} is declared in ${
|
|
96
|
+
detail: `${body.template} is declared in ${copies.map((t) => t.language).join(", ")}, not ${body.language}; a template approved in one language does not exist in another`,
|
|
94
97
|
};
|
|
95
98
|
}
|
|
96
99
|
const expected = templateArity(declared.body);
|
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { stderr } from "node:process";
|
|
7
7
|
import { loadAgent, type Agent } from "./agent.js";
|
|
8
|
-
import {
|
|
8
|
+
import { NotATestKeyError } from "@codespar/agent-core";
|
|
9
|
+
import { readAgentEnv } from "./env.js";
|
|
10
|
+
import { envFileOf, localeFlag, resolveRailKind } from "./setup.js";
|
|
11
|
+
import { loadManifest, resolveLocale } from "@codespar/agent-core";
|
|
12
|
+
import { join } from "node:path";
|
|
9
13
|
import { check } from "./commands/check.js";
|
|
10
14
|
import { decide } from "./commands/decide.js";
|
|
11
15
|
import { runEval } from "./commands/eval.js";
|
|
@@ -42,8 +46,23 @@ export async function main(argv: string[] = process.argv.slice(2)): Promise<numb
|
|
|
42
46
|
}
|
|
43
47
|
if (AGENTLESS.includes(command)) return verify(rest);
|
|
44
48
|
const agent = await loadAgent(dir);
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
// The CLI's names for the deployment and the project are aliases of the kit's. Two that disagree stop a command that talks to the API; on the stub rail neither is read, and the run goes on.
|
|
50
|
+
const disagreement = readAgentEnv(agent.dir);
|
|
51
|
+
const railFlag = rest.includes("--rail") ? rest[rest.indexOf("--rail") + 1] : undefined;
|
|
52
|
+
if (disagreement && resolveRailKind(process.env, railFlag === "api" || railFlag === "stub" ? railFlag : undefined) === "api") {
|
|
53
|
+
stderr.write(disagreement.message + "\n");
|
|
54
|
+
return 1;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
return await run(agent, command, rest);
|
|
58
|
+
} catch (err) {
|
|
59
|
+
// A key refusal is the first thing a newcomer meets (#50): one sentence naming the file this agent reads, never a stack trace.
|
|
60
|
+
if (err instanceof NotATestKeyError) {
|
|
61
|
+
stderr.write(new NotATestKeyError(err.problem, envFileOf(agent.dir)).message + "\n");
|
|
62
|
+
return 1;
|
|
63
|
+
}
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
47
66
|
}
|
|
48
67
|
|
|
49
68
|
async function run(agent: Agent, command: string, argv: string[]): Promise<number> {
|
|
@@ -56,7 +75,14 @@ async function run(agent: Agent, command: string, argv: string[]): Promise<numbe
|
|
|
56
75
|
stderr.write(`${agent.slug}: this agent has no consent step (its policy is its own file, not a signed mandate)\n`);
|
|
57
76
|
return 2;
|
|
58
77
|
}
|
|
59
|
-
|
|
78
|
+
let locale;
|
|
79
|
+
try {
|
|
80
|
+
locale = resolveLocale(localeFlag(argv), loadManifest(join(agent.dir, "agent.yaml")).manifest);
|
|
81
|
+
} catch (err) {
|
|
82
|
+
stderr.write(`${err instanceof Error ? err.message : String(err)}\n`);
|
|
83
|
+
return 2;
|
|
84
|
+
}
|
|
85
|
+
return agent.kit.consent({ agentDir: agent.dir, argv, locale, say: (l) => void stderr.write(l + "\n") });
|
|
60
86
|
}
|
|
61
87
|
case "approve":
|
|
62
88
|
return decide(agent, "approve", argv);
|