@agentguard-run/spend 0.2.2 → 0.3.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.
Files changed (80) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/LICENSE +1 -1
  3. package/README.es-419.md +28 -102
  4. package/README.md +50 -124
  5. package/README.pt-BR.md +28 -102
  6. package/dist/bindings/anthropic.d.ts +11 -0
  7. package/dist/bindings/anthropic.d.ts.map +1 -0
  8. package/dist/bindings/anthropic.js +116 -0
  9. package/dist/bindings/anthropic.js.map +1 -0
  10. package/dist/bindings/bedrock.d.ts +11 -0
  11. package/dist/bindings/bedrock.d.ts.map +1 -0
  12. package/dist/bindings/bedrock.js +177 -0
  13. package/dist/bindings/bedrock.js.map +1 -0
  14. package/dist/cli/auth.d.ts +7 -0
  15. package/dist/cli/auth.d.ts.map +1 -0
  16. package/dist/cli/auth.js +189 -0
  17. package/dist/cli/auth.js.map +1 -0
  18. package/dist/cli/colors.d.ts +8 -3
  19. package/dist/cli/colors.d.ts.map +1 -1
  20. package/dist/cli/colors.js +93 -4
  21. package/dist/cli/colors.js.map +1 -1
  22. package/dist/cli/demo.d.ts.map +1 -1
  23. package/dist/cli/demo.js +23 -2
  24. package/dist/cli/demo.js.map +1 -1
  25. package/dist/cli/main.d.ts +0 -6
  26. package/dist/cli/main.d.ts.map +1 -1
  27. package/dist/cli/main.js +36 -16
  28. package/dist/cli/main.js.map +1 -1
  29. package/dist/cli/models.d.ts +18 -0
  30. package/dist/cli/models.d.ts.map +1 -0
  31. package/dist/cli/models.js +277 -0
  32. package/dist/cli/models.js.map +1 -0
  33. package/dist/cli/tips.d.ts +21 -0
  34. package/dist/cli/tips.d.ts.map +1 -0
  35. package/dist/cli/tips.js +191 -0
  36. package/dist/cli/tips.js.map +1 -0
  37. package/dist/cli/wizard.d.ts +27 -0
  38. package/dist/cli/wizard.d.ts.map +1 -0
  39. package/dist/cli/wizard.js +182 -0
  40. package/dist/cli/wizard.js.map +1 -0
  41. package/dist/cost-table.d.ts +11 -36
  42. package/dist/cost-table.d.ts.map +1 -1
  43. package/dist/cost-table.js +114 -45
  44. package/dist/cost-table.js.map +1 -1
  45. package/dist/index.d.ts +6 -3
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +17 -2
  48. package/dist/index.js.map +1 -1
  49. package/dist/openrouter-catalog.d.ts +56 -0
  50. package/dist/openrouter-catalog.d.ts.map +1 -0
  51. package/dist/openrouter-catalog.js +183 -0
  52. package/dist/openrouter-catalog.js.map +1 -0
  53. package/dist/spend-guard.d.ts +38 -55
  54. package/dist/spend-guard.d.ts.map +1 -1
  55. package/dist/spend-guard.js +268 -83
  56. package/dist/spend-guard.js.map +1 -1
  57. package/dist/telemetry.d.ts.map +1 -1
  58. package/dist/telemetry.js +52 -21
  59. package/dist/telemetry.js.map +1 -1
  60. package/dist/templates/index.d.ts +17 -0
  61. package/dist/templates/index.d.ts.map +1 -0
  62. package/dist/templates/index.js +100 -0
  63. package/dist/templates/index.js.map +1 -0
  64. package/dist/types.d.ts +18 -3
  65. package/dist/types.d.ts.map +1 -1
  66. package/package.json +32 -4
  67. package/src/bindings/anthropic.ts +142 -0
  68. package/src/bindings/bedrock.ts +200 -0
  69. package/src/cli/auth.ts +145 -0
  70. package/src/cli/models.ts +236 -0
  71. package/src/cli/tips.ts +161 -0
  72. package/src/cli/wizard.ts +160 -0
  73. package/src/openrouter-catalog.ts +180 -0
  74. package/src/templates/agent-support.yaml +30 -0
  75. package/src/templates/chargeback-evidence.yaml +30 -0
  76. package/src/templates/code-scan.yaml +30 -0
  77. package/src/templates/index.ts +109 -0
  78. package/src/templates/payment-approval.yaml +30 -0
  79. package/src/templates/risk-review.yaml +30 -0
  80. package/tests/fixtures/openrouter-catalog.json +1 -0
@@ -0,0 +1,109 @@
1
+ import type { CapabilityTier, SpendPolicy } from '../types';
2
+
3
+ export interface TaskTemplate {
4
+ id: string;
5
+ slug: string;
6
+ label: string;
7
+ requiredCapability: CapabilityTier;
8
+ primaryModel: string;
9
+ fallbackModel: string;
10
+ allowedModels: string[];
11
+ caps: SpendPolicy['caps'];
12
+ systemInstructions: string;
13
+ }
14
+
15
+ export const TASK_TEMPLATES: Record<string, TaskTemplate> = {
16
+ 'risk-review': {
17
+ id: 'risk-review-v1',
18
+ slug: 'risk-review',
19
+ label: 'Risk review agent',
20
+ requiredCapability: 'read_only',
21
+ primaryModel: 'openai/gpt-4o-mini',
22
+ fallbackModel: 'anthropic/claude-haiku-4-5',
23
+ allowedModels: ['openai/gpt-4o-mini', 'anthropic/claude-haiku-4-5'],
24
+ caps: [
25
+ { amountCents: 50, window: 'per_call', action: 'downgrade', downgradeTo: 'anthropic/claude-haiku-4-5', reason: 'Per-call budget reached, routing to fallback model' },
26
+ { amountCents: 2500, window: 'per_day', action: 'block', reason: 'Daily budget reached' },
27
+ ],
28
+ systemInstructions: 'Classify transaction, vendor, and account risk. Return concise findings with evidence pointers only.',
29
+ },
30
+ 'payment-approval': {
31
+ id: 'payment-approval-v1',
32
+ slug: 'payment-approval',
33
+ label: 'Payment approval agent',
34
+ requiredCapability: 'payment_initiate',
35
+ primaryModel: 'anthropic/claude-sonnet-4-6',
36
+ fallbackModel: 'openai/gpt-5-mini',
37
+ allowedModels: ['anthropic/claude-sonnet-4-6', 'openai/gpt-5-mini'],
38
+ caps: [
39
+ { amountCents: 500, window: 'per_call', action: 'downgrade', downgradeTo: 'openai/gpt-5-mini', reason: 'Per-call budget reached, routing to fallback model' },
40
+ { amountCents: 20000, window: 'per_day', action: 'block', reason: 'Daily budget reached' },
41
+ ],
42
+ systemInstructions: 'Review payment intent and policy evidence. Recommend approve, hold, or escalate. Never execute funds movement.',
43
+ },
44
+ 'chargeback-evidence': {
45
+ id: 'chargeback-evidence-v1',
46
+ slug: 'chargeback-evidence',
47
+ label: 'Chargeback evidence agent',
48
+ requiredCapability: 'read_only',
49
+ primaryModel: 'openai/gpt-5-mini',
50
+ fallbackModel: 'openai/gpt-4o-mini',
51
+ allowedModels: ['openai/gpt-5-mini', 'openai/gpt-4o-mini'],
52
+ caps: [
53
+ { amountCents: 100, window: 'per_call', action: 'downgrade', downgradeTo: 'openai/gpt-4o-mini', reason: 'Per-call budget reached, routing to fallback model' },
54
+ { amountCents: 5000, window: 'per_day', action: 'block', reason: 'Daily budget reached' },
55
+ ],
56
+ systemInstructions: 'Assemble claim evidence from provided records. Cite source IDs and keep disputed facts separate from verified records.',
57
+ },
58
+ 'agent-support': {
59
+ id: 'agent-support-v1',
60
+ slug: 'agent-support',
61
+ label: 'Agent support workflow',
62
+ requiredCapability: 'data_write',
63
+ primaryModel: 'openai/gpt-4o-mini',
64
+ fallbackModel: 'google/gemini-3-flash-preview',
65
+ allowedModels: ['openai/gpt-4o-mini', 'google/gemini-3-flash-preview'],
66
+ caps: [
67
+ { amountCents: 25, window: 'per_call', action: 'downgrade', downgradeTo: 'google/gemini-3-flash-preview', reason: 'Per-call budget reached, routing to fallback model' },
68
+ { amountCents: 10000, window: 'per_day', action: 'block', reason: 'Daily budget reached' },
69
+ ],
70
+ systemInstructions: 'Draft support replies and update allowed fields only after policy checks. Escalate billing, payment, and identity changes.',
71
+ },
72
+ 'code-scan': {
73
+ id: 'code-scan-v1',
74
+ slug: 'code-scan',
75
+ label: 'Code scan agent',
76
+ requiredCapability: 'read_only',
77
+ primaryModel: 'google/gemini-3-flash-preview',
78
+ fallbackModel: 'openai/gpt-4o-mini',
79
+ allowedModels: ['google/gemini-3-flash-preview', 'openai/gpt-4o-mini'],
80
+ caps: [
81
+ { amountCents: 10, window: 'per_call', action: 'downgrade', downgradeTo: 'openai/gpt-4o-mini', reason: 'Per-call budget reached, routing to fallback model' },
82
+ { amountCents: 3000, window: 'per_day', action: 'block', reason: 'Daily budget reached' },
83
+ ],
84
+ systemInstructions: 'Scan code for spend, audit, and integration risks. Return findings with file paths and minimal fix guidance.',
85
+ },
86
+ };
87
+
88
+ export function listTaskTemplates(): TaskTemplate[] {
89
+ return Object.values(TASK_TEMPLATES);
90
+ }
91
+
92
+ export function getTaskTemplate(slug: string): TaskTemplate | null {
93
+ return TASK_TEMPLATES[slug] ?? null;
94
+ }
95
+
96
+ export function policyFromTemplate(slug: string, tenantId = 'my-tenant'): SpendPolicy | null {
97
+ const template = getTaskTemplate(slug);
98
+ if (!template) return null;
99
+ return {
100
+ id: template.id,
101
+ name: template.label,
102
+ scope: { tenantId },
103
+ caps: template.caps.map((cap) => ({ ...cap })),
104
+ mode: 'enforce',
105
+ requiredCapability: template.requiredCapability,
106
+ version: 1,
107
+ effectiveFrom: new Date().toISOString(),
108
+ };
109
+ }
@@ -0,0 +1,30 @@
1
+ # AgentGuard Spend task template: payment-approval
2
+ # Local-only policy file. Prompts, completions, API keys, and signing keys stay in the customer runtime.
3
+ id: payment-approval-v1
4
+ name: Payment approval agent
5
+ version: 1
6
+ effectiveFrom: "2026-05-27T00:00:00.000Z"
7
+ mode: enforce
8
+ requiredCapability: payment_initiate
9
+ scope:
10
+ tenantId: my-tenant
11
+ models:
12
+ primary: anthropic/claude-sonnet-4-6
13
+ fallback: openai/gpt-5-mini
14
+ allowed:
15
+ - anthropic/claude-sonnet-4-6
16
+ - openai/gpt-5-mini
17
+ caps:
18
+ # WHY: 500 cents per call bounds one agent action while keeping normal work flowing.
19
+ - amountCents: 500
20
+ window: per_call
21
+ action: downgrade
22
+ downgradeTo: openai/gpt-5-mini
23
+ reason: "Per-call budget reached, routing to fallback model"
24
+ # WHY: Daily cap catches loops and unexpected traffic before monthly budgets drift.
25
+ - amountCents: 20000
26
+ window: per_day
27
+ action: block
28
+ reason: "Daily budget reached"
29
+ systemInstructions: |
30
+ Review payment intent and policy evidence. Recommend approve, hold, or escalate. Never execute funds movement.
@@ -0,0 +1,30 @@
1
+ # AgentGuard Spend task template: risk-review
2
+ # Local-only policy file. Prompts, completions, API keys, and signing keys stay in the customer runtime.
3
+ id: risk-review-v1
4
+ name: Risk review agent
5
+ version: 1
6
+ effectiveFrom: "2026-05-27T00:00:00.000Z"
7
+ mode: enforce
8
+ requiredCapability: read_only
9
+ scope:
10
+ tenantId: my-tenant
11
+ models:
12
+ primary: openai/gpt-4o-mini
13
+ fallback: anthropic/claude-haiku-4-5
14
+ allowed:
15
+ - openai/gpt-4o-mini
16
+ - anthropic/claude-haiku-4-5
17
+ caps:
18
+ # WHY: 50 cents per call bounds one agent action while keeping normal work flowing.
19
+ - amountCents: 50
20
+ window: per_call
21
+ action: downgrade
22
+ downgradeTo: anthropic/claude-haiku-4-5
23
+ reason: "Per-call budget reached, routing to fallback model"
24
+ # WHY: Daily cap catches loops and unexpected traffic before monthly budgets drift.
25
+ - amountCents: 2500
26
+ window: per_day
27
+ action: block
28
+ reason: "Daily budget reached"
29
+ systemInstructions: |
30
+ Classify transaction, vendor, and account risk. Return concise findings with evidence pointers only.