@agentguard-run/spend 0.4.3 → 0.5.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/CHANGELOG.md +14 -1
- package/LICENSE +53 -0
- package/README.md +76 -0
- package/dist/advisor/conversation.d.ts +5 -0
- package/dist/advisor/conversation.d.ts.map +1 -1
- package/dist/advisor/conversation.js +34 -2
- package/dist/advisor/conversation.js.map +1 -1
- package/dist/advisor/output.d.ts.map +1 -1
- package/dist/advisor/output.js +9 -2
- package/dist/advisor/output.js.map +1 -1
- package/dist/advisor/system-prompt.d.ts.map +1 -1
- package/dist/advisor/system-prompt.js +6 -3
- package/dist/advisor/system-prompt.js.map +1 -1
- package/dist/cli/advisor.d.ts.map +1 -1
- package/dist/cli/advisor.js +11 -2
- package/dist/cli/advisor.js.map +1 -1
- package/dist/cli/auth.d.ts.map +1 -1
- package/dist/cli/auth.js +20 -1
- package/dist/cli/auth.js.map +1 -1
- package/dist/cli/config.d.ts +2 -0
- package/dist/cli/config.d.ts.map +1 -0
- package/dist/cli/config.js +19 -0
- package/dist/cli/config.js.map +1 -0
- package/dist/cli/license.d.ts +2 -0
- package/dist/cli/license.d.ts.map +1 -0
- package/dist/cli/license.js +39 -0
- package/dist/cli/license.js.map +1 -0
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +37 -1
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/skill.d.ts +2 -0
- package/dist/cli/skill.d.ts.map +1 -0
- package/dist/cli/skill.js +33 -0
- package/dist/cli/skill.js.map +1 -0
- package/dist/cli/soft-cap.d.ts +25 -0
- package/dist/cli/soft-cap.d.ts.map +1 -0
- package/dist/cli/soft-cap.js +204 -0
- package/dist/cli/soft-cap.js.map +1 -0
- package/dist/cost-table.d.ts.map +1 -1
- package/dist/cost-table.js +2 -0
- package/dist/cost-table.js.map +1 -1
- package/dist/index.d.ts +11 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -3
- package/dist/index.js.map +1 -1
- package/dist/license.d.ts +44 -0
- package/dist/license.d.ts.map +1 -0
- package/dist/license.js +278 -0
- package/dist/license.js.map +1 -0
- package/dist/policy.d.ts +15 -1
- package/dist/policy.d.ts.map +1 -1
- package/dist/policy.js +95 -1
- package/dist/policy.js.map +1 -1
- package/dist/spend-guard.d.ts +10 -0
- package/dist/spend-guard.d.ts.map +1 -1
- package/dist/spend-guard.js +14 -1
- package/dist/spend-guard.js.map +1 -1
- package/dist/types.d.ts +30 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/workflow/chain-validator.d.ts +4 -0
- package/dist/workflow/chain-validator.d.ts.map +1 -0
- package/dist/workflow/chain-validator.js +37 -0
- package/dist/workflow/chain-validator.js.map +1 -0
- package/dist/workflow/context.d.ts +46 -0
- package/dist/workflow/context.d.ts.map +1 -0
- package/dist/workflow/context.js +360 -0
- package/dist/workflow/context.js.map +1 -0
- package/dist/workflow/errors.d.ts +43 -0
- package/dist/workflow/errors.d.ts.map +1 -0
- package/dist/workflow/errors.js +40 -0
- package/dist/workflow/errors.js.map +1 -0
- package/dist/workflow/index.d.ts +6 -0
- package/dist/workflow/index.d.ts.map +1 -0
- package/dist/workflow/index.js +20 -0
- package/dist/workflow/index.js.map +1 -0
- package/dist/workflow/receipt.d.ts +23 -0
- package/dist/workflow/receipt.d.ts.map +1 -0
- package/dist/workflow/receipt.js +60 -0
- package/dist/workflow/receipt.js.map +1 -0
- package/dist/workflow/types.d.ts +74 -0
- package/dist/workflow/types.d.ts.map +1 -0
- package/dist/workflow/types.js +3 -0
- package/dist/workflow/types.js.map +1 -0
- package/package.json +11 -4
- package/src/advisor/conversation.ts +41 -2
- package/src/advisor/output.ts +9 -2
- package/src/advisor/system-prompt.ts +6 -3
- package/src/cli/advisor.ts +9 -2
- package/src/cli/auth.ts +19 -1
- package/src/workflow/chain-validator.ts +35 -0
- package/src/workflow/context.ts +418 -0
- package/src/workflow/errors.ts +27 -0
- package/src/workflow/index.ts +18 -0
- package/src/workflow/receipt.ts +73 -0
- package/src/workflow/types.ts +88 -0
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkflowContext = void 0;
|
|
4
|
+
exports.workflow = workflow;
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
6
|
+
const chain_validator_1 = require("./chain-validator");
|
|
7
|
+
const errors_1 = require("./errors");
|
|
8
|
+
const receipt_1 = require("./receipt");
|
|
9
|
+
class WorkflowContext {
|
|
10
|
+
workflow_id;
|
|
11
|
+
user_id;
|
|
12
|
+
config;
|
|
13
|
+
created_at;
|
|
14
|
+
_total_spend_usd = 0;
|
|
15
|
+
_outcome_count = 0;
|
|
16
|
+
_last_receipt_id = null;
|
|
17
|
+
_last_checkpoint_id = null;
|
|
18
|
+
_last_chain_hash = null;
|
|
19
|
+
_state = 'active';
|
|
20
|
+
_receipts = [];
|
|
21
|
+
constructor(args) {
|
|
22
|
+
this.workflow_id = args.workflow_id;
|
|
23
|
+
this.user_id = args.user_id;
|
|
24
|
+
this.config = args.config;
|
|
25
|
+
this.created_at = args.created_at;
|
|
26
|
+
this._state = args.state ?? 'active';
|
|
27
|
+
this._total_spend_usd = args.total_spend_usd ?? 0;
|
|
28
|
+
this._outcome_count = args.outcome_count ?? 0;
|
|
29
|
+
this._last_receipt_id = args.last_receipt_id ?? null;
|
|
30
|
+
this._last_checkpoint_id = args.last_checkpoint_id ?? null;
|
|
31
|
+
this._last_chain_hash = args.last_chain_hash ?? null;
|
|
32
|
+
this._receipts.push(...(args.receipts ?? []));
|
|
33
|
+
}
|
|
34
|
+
static async create(config) {
|
|
35
|
+
validateConfig(config);
|
|
36
|
+
const userId = String(config.metadata?.user_id || config.user_id || 'local-user');
|
|
37
|
+
if (config.resume_if_exists) {
|
|
38
|
+
const existing = await tryResume(config, userId);
|
|
39
|
+
if (existing)
|
|
40
|
+
return existing;
|
|
41
|
+
}
|
|
42
|
+
const apiBase = resolveApiBase(config);
|
|
43
|
+
if (apiBase) {
|
|
44
|
+
const body = {
|
|
45
|
+
name: config.name,
|
|
46
|
+
budget_cap_usd: config.budget_cap_usd,
|
|
47
|
+
duration_cap_hours: config.duration_cap_hours,
|
|
48
|
+
checkpoint_every_outcomes: config.checkpoint_every_outcomes ?? 25,
|
|
49
|
+
parent_outcomes: config.parent_outcomes,
|
|
50
|
+
metadata: config.metadata,
|
|
51
|
+
};
|
|
52
|
+
const created = await postJson(config, `${apiBase}/api/workflows/create`, body);
|
|
53
|
+
return new WorkflowContext({
|
|
54
|
+
workflow_id: created.workflow_id,
|
|
55
|
+
user_id: userId,
|
|
56
|
+
config,
|
|
57
|
+
created_at: new Date(created.created_at),
|
|
58
|
+
state: created.state,
|
|
59
|
+
total_spend_usd: created.total_spend_usd,
|
|
60
|
+
outcome_count: created.outcome_count,
|
|
61
|
+
last_receipt_id: created.last_receipt_id,
|
|
62
|
+
last_checkpoint_id: created.last_checkpoint_id,
|
|
63
|
+
last_chain_hash: created.last_chain_hash,
|
|
64
|
+
receipts: created.receipts,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return new WorkflowContext({
|
|
68
|
+
workflow_id: `ag_w_${(0, crypto_1.randomUUID)().replace(/-/g, '').slice(0, 16)}`,
|
|
69
|
+
user_id: userId,
|
|
70
|
+
config,
|
|
71
|
+
created_at: new Date(),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
static fromCheckpoint(config, existing, userId = 'local-user') {
|
|
75
|
+
return new WorkflowContext({
|
|
76
|
+
workflow_id: existing.workflow_id,
|
|
77
|
+
user_id: userId,
|
|
78
|
+
config,
|
|
79
|
+
created_at: new Date(existing.created_at),
|
|
80
|
+
state: existing.state ?? 'active',
|
|
81
|
+
total_spend_usd: existing.total_spend_usd,
|
|
82
|
+
outcome_count: existing.outcome_count,
|
|
83
|
+
last_receipt_id: existing.last_receipt_id,
|
|
84
|
+
last_checkpoint_id: existing.last_checkpoint_id,
|
|
85
|
+
last_chain_hash: existing.last_chain_hash,
|
|
86
|
+
receipts: existing.receipts,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
async outcome(name, fn) {
|
|
90
|
+
this.assertActive();
|
|
91
|
+
this.assertOutcomeAllowed(name);
|
|
92
|
+
this.assertBudgetRemaining();
|
|
93
|
+
this.assertDurationRemaining();
|
|
94
|
+
const result = await fn();
|
|
95
|
+
const cost = this.extractOutcomeCost(result);
|
|
96
|
+
const parentReceiptId = this._last_receipt_id;
|
|
97
|
+
const chainHash = this._receipts.length ? await (0, chain_validator_1.computeChainHash)(this._receipts[this._receipts.length - 1]) : null;
|
|
98
|
+
const receipt = (0, receipt_1.buildReceipt)({
|
|
99
|
+
workflow_id: this.workflow_id,
|
|
100
|
+
outcome_name: name,
|
|
101
|
+
user_id: this.user_id,
|
|
102
|
+
cost_usd: cost,
|
|
103
|
+
parent_receipt_id: parentReceiptId,
|
|
104
|
+
chain_validation_hash: chainHash,
|
|
105
|
+
workflow_checkpoint_idx: null,
|
|
106
|
+
workflow_total_spend_usd_to_date: this._total_spend_usd + cost,
|
|
107
|
+
reviewer_cascade: extractReviewerCascade(result),
|
|
108
|
+
});
|
|
109
|
+
this._receipts.push(receipt);
|
|
110
|
+
this._total_spend_usd = (0, receipt_1.roundUsd)(this._total_spend_usd + cost);
|
|
111
|
+
this._outcome_count += 1;
|
|
112
|
+
this._last_receipt_id = receipt.receipt_id;
|
|
113
|
+
this._last_chain_hash = await (0, chain_validator_1.computeChainHash)(receipt);
|
|
114
|
+
await this.postReceipt(receipt);
|
|
115
|
+
if (this._outcome_count % (this.config.checkpoint_every_outcomes ?? 25) === 0) {
|
|
116
|
+
await this.writeCheckpoint();
|
|
117
|
+
}
|
|
118
|
+
await this.checkPostCallCaps();
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
async checkpoint(label) {
|
|
122
|
+
return this.writeCheckpoint(label);
|
|
123
|
+
}
|
|
124
|
+
async cancel(reason) {
|
|
125
|
+
this._state = 'cancelled';
|
|
126
|
+
await this.writeFinalReceipt('cancelled', reason);
|
|
127
|
+
}
|
|
128
|
+
async finalize() {
|
|
129
|
+
if (this._state === 'active') {
|
|
130
|
+
this._state = 'completed';
|
|
131
|
+
await this.writeFinalReceipt('completed', 'workflow completed');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
status() {
|
|
135
|
+
const elapsed = Date.now() - this.created_at.getTime();
|
|
136
|
+
const capMs = this.config.duration_cap_hours * 3_600_000;
|
|
137
|
+
return {
|
|
138
|
+
workflow_id: this.workflow_id,
|
|
139
|
+
state: this._state,
|
|
140
|
+
total_spend_usd: this._total_spend_usd,
|
|
141
|
+
budget_cap_usd: this.config.budget_cap_usd,
|
|
142
|
+
budget_remaining_usd: (0, receipt_1.roundUsd)(Math.max(0, this.config.budget_cap_usd - this._total_spend_usd)),
|
|
143
|
+
budget_pct_used: this.config.budget_cap_usd === 0 ? 1 : this._total_spend_usd / this.config.budget_cap_usd,
|
|
144
|
+
outcome_count: this._outcome_count,
|
|
145
|
+
last_receipt_id: this._last_receipt_id,
|
|
146
|
+
last_checkpoint_id: this._last_checkpoint_id,
|
|
147
|
+
last_chain_hash: this._last_chain_hash,
|
|
148
|
+
duration_elapsed_ms: elapsed,
|
|
149
|
+
duration_cap_ms: capMs,
|
|
150
|
+
duration_remaining_ms: Math.max(0, capMs - elapsed),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
receipts() {
|
|
154
|
+
return [...this._receipts];
|
|
155
|
+
}
|
|
156
|
+
async writeCheckpoint(label) {
|
|
157
|
+
const chainHash = this._receipts.length ? await (0, chain_validator_1.computeChainHash)(this._receipts[this._receipts.length - 1]) : null;
|
|
158
|
+
const checkpoint = (0, receipt_1.buildReceipt)({
|
|
159
|
+
workflow_id: this.workflow_id,
|
|
160
|
+
outcome_name: 'CHECKPOINT',
|
|
161
|
+
user_id: this.user_id,
|
|
162
|
+
cost_usd: 0,
|
|
163
|
+
parent_receipt_id: this._last_receipt_id,
|
|
164
|
+
chain_validation_hash: chainHash,
|
|
165
|
+
workflow_checkpoint_idx: this._outcome_count,
|
|
166
|
+
workflow_total_spend_usd_to_date: this._total_spend_usd,
|
|
167
|
+
is_checkpoint: true,
|
|
168
|
+
checkpoint_label: label ?? null,
|
|
169
|
+
receipt_type: 'checkpoint',
|
|
170
|
+
});
|
|
171
|
+
this._receipts.push(checkpoint);
|
|
172
|
+
this._last_checkpoint_id = checkpoint.receipt_id;
|
|
173
|
+
this._last_receipt_id = checkpoint.receipt_id;
|
|
174
|
+
this._last_chain_hash = await (0, chain_validator_1.computeChainHash)(checkpoint);
|
|
175
|
+
await this.postReceipt(checkpoint);
|
|
176
|
+
return checkpoint;
|
|
177
|
+
}
|
|
178
|
+
async writeFinalReceipt(type, reason) {
|
|
179
|
+
const chainHash = this._receipts.length ? await (0, chain_validator_1.computeChainHash)(this._receipts[this._receipts.length - 1]) : null;
|
|
180
|
+
const receipt = (0, receipt_1.buildReceipt)({
|
|
181
|
+
workflow_id: this.workflow_id,
|
|
182
|
+
outcome_name: type === 'completed' ? 'WORKFLOW_COMPLETED' : 'WORKFLOW_STOPPED',
|
|
183
|
+
user_id: this.user_id,
|
|
184
|
+
cost_usd: 0,
|
|
185
|
+
parent_receipt_id: this._last_receipt_id,
|
|
186
|
+
chain_validation_hash: chainHash,
|
|
187
|
+
workflow_checkpoint_idx: this._outcome_count,
|
|
188
|
+
workflow_total_spend_usd_to_date: this._total_spend_usd,
|
|
189
|
+
receipt_type: type === 'cancelled' ? 'cancel' : type,
|
|
190
|
+
cancelled_reason: reason,
|
|
191
|
+
});
|
|
192
|
+
this._receipts.push(receipt);
|
|
193
|
+
this._last_receipt_id = receipt.receipt_id;
|
|
194
|
+
this._last_chain_hash = await (0, chain_validator_1.computeChainHash)(receipt);
|
|
195
|
+
await this.postReceipt(receipt);
|
|
196
|
+
}
|
|
197
|
+
assertActive() {
|
|
198
|
+
if (this._state === 'budget_capped') {
|
|
199
|
+
throw new errors_1.AgentGuardBudgetCapError(`Workflow ${this.workflow_id} exceeded budget cap of $${this.config.budget_cap_usd}. Total spend to date: $${this._total_spend_usd}.`, { workflow_id: this.workflow_id, total_spend_usd: this._total_spend_usd });
|
|
200
|
+
}
|
|
201
|
+
if (this._state === 'duration_capped') {
|
|
202
|
+
throw new errors_1.AgentGuardDurationCapError(`Workflow ${this.workflow_id} exceeded duration cap.`, {
|
|
203
|
+
workflow_id: this.workflow_id,
|
|
204
|
+
elapsed_ms: Date.now() - this.created_at.getTime(),
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
if (this._state !== 'active') {
|
|
208
|
+
throw new errors_1.AgentGuardWorkflowStateError(`Workflow ${this.workflow_id} is ${this._state}.`, {
|
|
209
|
+
workflow_id: this.workflow_id,
|
|
210
|
+
state: this._state,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
assertOutcomeAllowed(name) {
|
|
215
|
+
if (this.config.parent_outcomes && !this.config.parent_outcomes.includes(name)) {
|
|
216
|
+
throw new errors_1.AgentGuardWorkflowStateError(`Outcome ${name} is not allowed in workflow ${this.workflow_id}.`, {
|
|
217
|
+
workflow_id: this.workflow_id,
|
|
218
|
+
state: this._state,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
assertBudgetRemaining() {
|
|
223
|
+
if (this._total_spend_usd >= this.config.budget_cap_usd) {
|
|
224
|
+
this._state = 'budget_capped';
|
|
225
|
+
throw new errors_1.AgentGuardBudgetCapError(`Workflow ${this.workflow_id} exceeded budget cap of $${this.config.budget_cap_usd}. Total spend to date: $${this._total_spend_usd}.`, { workflow_id: this.workflow_id, total_spend_usd: this._total_spend_usd });
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
assertDurationRemaining() {
|
|
229
|
+
const elapsed = Date.now() - this.created_at.getTime();
|
|
230
|
+
const cap = this.config.duration_cap_hours * 3_600_000;
|
|
231
|
+
if (elapsed >= cap) {
|
|
232
|
+
this._state = 'duration_capped';
|
|
233
|
+
throw new errors_1.AgentGuardDurationCapError(`Workflow ${this.workflow_id} exceeded duration cap.`, {
|
|
234
|
+
workflow_id: this.workflow_id,
|
|
235
|
+
elapsed_ms: elapsed,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
async checkPostCallCaps() {
|
|
240
|
+
if (this._total_spend_usd >= this.config.budget_cap_usd) {
|
|
241
|
+
this._state = 'budget_capped';
|
|
242
|
+
await this.writeFinalReceipt('cap_hit', 'budget cap reached');
|
|
243
|
+
}
|
|
244
|
+
const elapsed = Date.now() - this.created_at.getTime();
|
|
245
|
+
if (elapsed >= this.config.duration_cap_hours * 3_600_000) {
|
|
246
|
+
this._state = 'duration_capped';
|
|
247
|
+
await this.writeFinalReceipt('cap_hit', 'duration cap reached');
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
extractOutcomeCost(result) {
|
|
251
|
+
if (isRecord(result)) {
|
|
252
|
+
if (typeof result.cost_usd === 'number')
|
|
253
|
+
return result.cost_usd;
|
|
254
|
+
const receipt = result.receipt;
|
|
255
|
+
if (isRecord(receipt) && typeof receipt.cost_usd === 'number')
|
|
256
|
+
return receipt.cost_usd;
|
|
257
|
+
}
|
|
258
|
+
const configured = this.config.metadata?.default_outcome_cost_usd;
|
|
259
|
+
return typeof configured === 'number' ? configured : 0;
|
|
260
|
+
}
|
|
261
|
+
async postReceipt(receipt) {
|
|
262
|
+
const apiBase = resolveApiBase(this.config);
|
|
263
|
+
if (!apiBase)
|
|
264
|
+
return;
|
|
265
|
+
await postJson(this.config, `${apiBase}/api/workflows/${this.workflow_id}/receipt`, { receipt });
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
exports.WorkflowContext = WorkflowContext;
|
|
269
|
+
async function workflow(config, fn) {
|
|
270
|
+
const ctx = await WorkflowContext.create(config);
|
|
271
|
+
try {
|
|
272
|
+
return await fn(ctx);
|
|
273
|
+
}
|
|
274
|
+
finally {
|
|
275
|
+
await ctx.finalize();
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
async function tryResume(config, userId) {
|
|
279
|
+
const apiBase = resolveApiBase(config);
|
|
280
|
+
if (!apiBase)
|
|
281
|
+
return null;
|
|
282
|
+
const headers = authHeaders(config);
|
|
283
|
+
const existing = await getJson(config, `${apiBase}/api/workflows/lookup?name=${encodeURIComponent(config.name)}`, headers);
|
|
284
|
+
if (!existing || ['cancelled', 'completed', 'budget_capped', 'duration_capped'].includes(existing.state ?? '')) {
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
const chain = await getJson(config, `${apiBase}/api/workflows/${existing.workflow_id}/chain`, headers);
|
|
288
|
+
const validation = await (0, chain_validator_1.validateReceiptChain)(chain.receipts);
|
|
289
|
+
if (!validation.ok) {
|
|
290
|
+
throw new errors_1.AgentGuardChainCorruptError(`Cannot resume workflow ${existing.workflow_id}: chain validation failed.`, {
|
|
291
|
+
workflow_id: existing.workflow_id,
|
|
292
|
+
broken_at: validation.broken_at,
|
|
293
|
+
reason: validation.reason,
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
return WorkflowContext.fromCheckpoint(config, { ...existing, receipts: chain.receipts }, userId);
|
|
297
|
+
}
|
|
298
|
+
function resolveApiBase(config) {
|
|
299
|
+
const value = config.api_base_url || process.env.AGENTGUARD_WORKFLOW_API_BASE || '';
|
|
300
|
+
return value ? value.replace(/\/$/, '') : null;
|
|
301
|
+
}
|
|
302
|
+
function authHeaders(config) {
|
|
303
|
+
const license = config.license_key || process.env.AGENTGUARD_LICENSE_KEY || '';
|
|
304
|
+
return {
|
|
305
|
+
'content-type': 'application/json',
|
|
306
|
+
...(license ? { authorization: `Bearer ${license}` } : {}),
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
async function postJson(config, url, body) {
|
|
310
|
+
const headers = authHeaders(config);
|
|
311
|
+
if (config.post_json)
|
|
312
|
+
return config.post_json(url, body, headers);
|
|
313
|
+
const response = await fetch(url, { method: 'POST', headers, body: JSON.stringify(body) });
|
|
314
|
+
if (!response.ok)
|
|
315
|
+
throw new Error(`Workflow API request failed: ${response.status}`);
|
|
316
|
+
return response.json();
|
|
317
|
+
}
|
|
318
|
+
async function getJson(config, url, headers) {
|
|
319
|
+
if (config.get_json)
|
|
320
|
+
return config.get_json(url, headers);
|
|
321
|
+
const response = await fetch(url, { headers });
|
|
322
|
+
if (response.status === 404)
|
|
323
|
+
return null;
|
|
324
|
+
if (!response.ok)
|
|
325
|
+
throw new Error(`Workflow API request failed: ${response.status}`);
|
|
326
|
+
return response.json();
|
|
327
|
+
}
|
|
328
|
+
function extractReviewerCascade(result) {
|
|
329
|
+
if (!isRecord(result))
|
|
330
|
+
return null;
|
|
331
|
+
const value = result.reviewer_cascade;
|
|
332
|
+
if (!isRecord(value))
|
|
333
|
+
return null;
|
|
334
|
+
return {
|
|
335
|
+
triggered: value.triggered === true,
|
|
336
|
+
drafter_model: typeof value.drafter_model === 'string' ? value.drafter_model : null,
|
|
337
|
+
reviewer_model: typeof value.reviewer_model === 'string' ? value.reviewer_model : null,
|
|
338
|
+
drafter_output_hash: typeof value.drafter_output_hash === 'string' ? value.drafter_output_hash : null,
|
|
339
|
+
reviewer_verdict: value.reviewer_verdict === 'approve' || value.reviewer_verdict === 'block' || value.reviewer_verdict === 'revise'
|
|
340
|
+
? value.reviewer_verdict
|
|
341
|
+
: null,
|
|
342
|
+
reviewer_reasoning_hash: typeof value.reviewer_reasoning_hash === 'string' ? value.reviewer_reasoning_hash : null,
|
|
343
|
+
review_started_at: typeof value.review_started_at === 'string' ? value.review_started_at : null,
|
|
344
|
+
review_completed_at: typeof value.review_completed_at === 'string' ? value.review_completed_at : null,
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
function validateConfig(config) {
|
|
348
|
+
if (!config.name || !config.name.trim())
|
|
349
|
+
throw new Error('Workflow name is required');
|
|
350
|
+
if (!Number.isFinite(config.budget_cap_usd) || config.budget_cap_usd <= 0) {
|
|
351
|
+
throw new Error('Workflow budget_cap_usd must be greater than zero');
|
|
352
|
+
}
|
|
353
|
+
if (!Number.isFinite(config.duration_cap_hours) || config.duration_cap_hours <= 0) {
|
|
354
|
+
throw new Error('Workflow duration_cap_hours must be greater than zero');
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
function isRecord(value) {
|
|
358
|
+
return typeof value === 'object' && value !== null;
|
|
359
|
+
}
|
|
360
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/workflow/context.ts"],"names":[],"mappings":";;;AAgUA,4BAOC;AAvUD,mCAAoC;AAGpC,uDAA2E;AAC3E,qCAA2I;AAC3I,uCAAmD;AAenD,MAAa,eAAe;IACV,WAAW,CAAS;IACpB,OAAO,CAAS;IAChB,MAAM,CAAiB;IACvB,UAAU,CAAO;IAEzB,gBAAgB,GAAG,CAAC,CAAC;IACrB,cAAc,GAAG,CAAC,CAAC;IACnB,gBAAgB,GAAkB,IAAI,CAAC;IACvC,mBAAmB,GAAkB,IAAI,CAAC;IAC1C,gBAAgB,GAAkB,IAAI,CAAC;IACvC,MAAM,GAAkB,QAAQ,CAAC;IACxB,SAAS,GAAgB,EAAE,CAAC;IAE7C,YAAoB,IAYnB;QACC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QACpC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAClC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,IAAI,QAAQ,CAAC;QACrC,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,eAAe,IAAI,CAAC,CAAC;QAClD,IAAI,CAAC,cAAc,GAAG,IAAI,C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
|
+
export declare class AgentGuardBudgetCapError extends Error {
|
|
2
|
+
context: {
|
|
3
|
+
workflow_id: string;
|
|
4
|
+
total_spend_usd: number;
|
|
5
|
+
};
|
|
6
|
+
constructor(message: string, context: {
|
|
7
|
+
workflow_id: string;
|
|
8
|
+
total_spend_usd: number;
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
export declare class AgentGuardDurationCapError extends Error {
|
|
12
|
+
context: {
|
|
13
|
+
workflow_id: string;
|
|
14
|
+
elapsed_ms: number;
|
|
15
|
+
};
|
|
16
|
+
constructor(message: string, context: {
|
|
17
|
+
workflow_id: string;
|
|
18
|
+
elapsed_ms: number;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export declare class AgentGuardChainCorruptError extends Error {
|
|
22
|
+
context: {
|
|
23
|
+
workflow_id?: string;
|
|
24
|
+
broken_at?: number;
|
|
25
|
+
reason?: string;
|
|
26
|
+
};
|
|
27
|
+
constructor(message: string, context?: {
|
|
28
|
+
workflow_id?: string;
|
|
29
|
+
broken_at?: number;
|
|
30
|
+
reason?: string;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export declare class AgentGuardWorkflowStateError extends Error {
|
|
34
|
+
context: {
|
|
35
|
+
workflow_id: string;
|
|
36
|
+
state: string;
|
|
37
|
+
};
|
|
38
|
+
constructor(message: string, context: {
|
|
39
|
+
workflow_id: string;
|
|
40
|
+
state: string;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/workflow/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,wBAAyB,SAAQ,KAAK;IACb,OAAO,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE;gBAAjF,OAAO,EAAE,MAAM,EAAS,OAAO,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE;CAI9F;AAED,qBAAa,0BAA2B,SAAQ,KAAK;IACf,OAAO,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE;gBAA5E,OAAO,EAAE,MAAM,EAAS,OAAO,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE;CAIzF;AAED,qBAAa,2BAA4B,SAAQ,KAAK;IAChB,OAAO,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;gBAA9F,OAAO,EAAE,MAAM,EAAS,OAAO,GAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO;CAIhH;AAED,qBAAa,4BAA6B,SAAQ,KAAK;IACjB,OAAO,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;gBAAvE,OAAO,EAAE,MAAM,EAAS,OAAO,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;CAIpF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AgentGuardWorkflowStateError = exports.AgentGuardChainCorruptError = exports.AgentGuardDurationCapError = exports.AgentGuardBudgetCapError = void 0;
|
|
4
|
+
class AgentGuardBudgetCapError extends Error {
|
|
5
|
+
context;
|
|
6
|
+
constructor(message, context) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.context = context;
|
|
9
|
+
this.name = 'AgentGuardBudgetCapError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.AgentGuardBudgetCapError = AgentGuardBudgetCapError;
|
|
13
|
+
class AgentGuardDurationCapError extends Error {
|
|
14
|
+
context;
|
|
15
|
+
constructor(message, context) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.context = context;
|
|
18
|
+
this.name = 'AgentGuardDurationCapError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.AgentGuardDurationCapError = AgentGuardDurationCapError;
|
|
22
|
+
class AgentGuardChainCorruptError extends Error {
|
|
23
|
+
context;
|
|
24
|
+
constructor(message, context = {}) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.context = context;
|
|
27
|
+
this.name = 'AgentGuardChainCorruptError';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.AgentGuardChainCorruptError = AgentGuardChainCorruptError;
|
|
31
|
+
class AgentGuardWorkflowStateError extends Error {
|
|
32
|
+
context;
|
|
33
|
+
constructor(message, context) {
|
|
34
|
+
super(message);
|
|
35
|
+
this.context = context;
|
|
36
|
+
this.name = 'AgentGuardWorkflowStateError';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.AgentGuardWorkflowStateError = AgentGuardWorkflowStateError;
|
|
40
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/workflow/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,wBAAyB,SAAQ,KAAK;IACb;IAApC,YAAY,OAAe,EAAS,OAAyD;QAC3F,KAAK,CAAC,OAAO,CAAC,CAAC;QADmB,YAAO,GAAP,OAAO,CAAkD;QAE3F,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF;AALD,4DAKC;AAED,MAAa,0BAA2B,SAAQ,KAAK;IACf;IAApC,YAAY,OAAe,EAAS,OAAoD;QACtF,KAAK,CAAC,OAAO,CAAC,CAAC;QADmB,YAAO,GAAP,OAAO,CAA6C;QAEtF,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF;AALD,gEAKC;AAED,MAAa,2BAA4B,SAAQ,KAAK;IAChB;IAApC,YAAY,OAAe,EAAS,UAAyE,EAAE;QAC7G,KAAK,CAAC,OAAO,CAAC,CAAC;QADmB,YAAO,GAAP,OAAO,CAAoE;QAE7G,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IAC5C,CAAC;CACF;AALD,kEAKC;AAED,MAAa,4BAA6B,SAAQ,KAAK;IACjB;IAApC,YAAY,OAAe,EAAS,OAA+C;QACjF,KAAK,CAAC,OAAO,CAAC,CAAC;QADmB,YAAO,GAAP,OAAO,CAAwC;QAEjF,IAAI,CAAC,IAAI,GAAG,8BAA8B,CAAC;IAC7C,CAAC;CACF;AALD,oEAKC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { WorkflowContext, workflow } from './context';
|
|
2
|
+
export { validateReceiptChain, computeChainHash } from './chain-validator';
|
|
3
|
+
export { buildReceipt, verifyReceipt, canonicalJSONStringify, sha256 } from './receipt';
|
|
4
|
+
export { AgentGuardBudgetCapError, AgentGuardDurationCapError, AgentGuardChainCorruptError, AgentGuardWorkflowStateError, } from './errors';
|
|
5
|
+
export type { ChainValidationResult, CheckpointReceipt, ReceiptV2, ReviewerCascadeEvidence, WorkflowConfig, WorkflowState, WorkflowStatus, } from './types';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/workflow/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACxF,OAAO,EACL,wBAAwB,EACxB,0BAA0B,EAC1B,2BAA2B,EAC3B,4BAA4B,GAC7B,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,qBAAqB,EACrB,iBAAiB,EACjB,SAAS,EACT,uBAAuB,EACvB,cAAc,EACd,aAAa,EACb,cAAc,GACf,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AgentGuardWorkflowStateError = exports.AgentGuardChainCorruptError = exports.AgentGuardDurationCapError = exports.AgentGuardBudgetCapError = exports.sha256 = exports.canonicalJSONStringify = exports.verifyReceipt = exports.buildReceipt = exports.computeChainHash = exports.validateReceiptChain = exports.workflow = exports.WorkflowContext = void 0;
|
|
4
|
+
var context_1 = require("./context");
|
|
5
|
+
Object.defineProperty(exports, "WorkflowContext", { enumerable: true, get: function () { return context_1.WorkflowContext; } });
|
|
6
|
+
Object.defineProperty(exports, "workflow", { enumerable: true, get: function () { return context_1.workflow; } });
|
|
7
|
+
var chain_validator_1 = require("./chain-validator");
|
|
8
|
+
Object.defineProperty(exports, "validateReceiptChain", { enumerable: true, get: function () { return chain_validator_1.validateReceiptChain; } });
|
|
9
|
+
Object.defineProperty(exports, "computeChainHash", { enumerable: true, get: function () { return chain_validator_1.computeChainHash; } });
|
|
10
|
+
var receipt_1 = require("./receipt");
|
|
11
|
+
Object.defineProperty(exports, "buildReceipt", { enumerable: true, get: function () { return receipt_1.buildReceipt; } });
|
|
12
|
+
Object.defineProperty(exports, "verifyReceipt", { enumerable: true, get: function () { return receipt_1.verifyReceipt; } });
|
|
13
|
+
Object.defineProperty(exports, "canonicalJSONStringify", { enumerable: true, get: function () { return receipt_1.canonicalJSONStringify; } });
|
|
14
|
+
Object.defineProperty(exports, "sha256", { enumerable: true, get: function () { return receipt_1.sha256; } });
|
|
15
|
+
var errors_1 = require("./errors");
|
|
16
|
+
Object.defineProperty(exports, "AgentGuardBudgetCapError", { enumerable: true, get: function () { return errors_1.AgentGuardBudgetCapError; } });
|
|
17
|
+
Object.defineProperty(exports, "AgentGuardDurationCapError", { enumerable: true, get: function () { return errors_1.AgentGuardDurationCapError; } });
|
|
18
|
+
Object.defineProperty(exports, "AgentGuardChainCorruptError", { enumerable: true, get: function () { return errors_1.AgentGuardChainCorruptError; } });
|
|
19
|
+
Object.defineProperty(exports, "AgentGuardWorkflowStateError", { enumerable: true, get: function () { return errors_1.AgentGuardWorkflowStateError; } });
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/workflow/index.ts"],"names":[],"mappings":";;;AAAA,qCAAsD;AAA7C,0GAAA,eAAe,OAAA;AAAE,mGAAA,QAAQ,OAAA;AAClC,qDAA2E;AAAlE,uHAAA,oBAAoB,OAAA;AAAE,mHAAA,gBAAgB,OAAA;AAC/C,qCAAwF;AAA/E,uGAAA,YAAY,OAAA;AAAE,wGAAA,aAAa,OAAA;AAAE,iHAAA,sBAAsB,OAAA;AAAE,iGAAA,MAAM,OAAA;AACpE,mCAKkB;AAJhB,kHAAA,wBAAwB,OAAA;AACxB,oHAAA,0BAA0B,OAAA;AAC1B,qHAAA,2BAA2B,OAAA;AAC3B,sHAAA,4BAA4B,OAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ReceiptV2, ReviewerCascadeEvidence } from './types';
|
|
2
|
+
export declare function canonicalJSONStringify(value: unknown): string;
|
|
3
|
+
export declare function sha256(input: string): string;
|
|
4
|
+
export declare function workflowReceiptId(prefix?: string): string;
|
|
5
|
+
export declare function signReceiptPayload(payload: Omit<ReceiptV2, 'signature'>): string;
|
|
6
|
+
export declare function buildReceipt(args: {
|
|
7
|
+
workflow_id: string | null;
|
|
8
|
+
outcome_name: string;
|
|
9
|
+
user_id: string;
|
|
10
|
+
cost_usd: number;
|
|
11
|
+
parent_receipt_id: string | null;
|
|
12
|
+
chain_validation_hash: string | null;
|
|
13
|
+
workflow_checkpoint_idx: number | null;
|
|
14
|
+
workflow_total_spend_usd_to_date: number | null;
|
|
15
|
+
is_checkpoint?: boolean;
|
|
16
|
+
checkpoint_label?: string | null;
|
|
17
|
+
reviewer_cascade?: ReviewerCascadeEvidence | null;
|
|
18
|
+
receipt_type?: ReceiptV2['receipt_type'];
|
|
19
|
+
cancelled_reason?: string | null;
|
|
20
|
+
}): ReceiptV2;
|
|
21
|
+
export declare function verifyReceipt(receipt: ReceiptV2): boolean;
|
|
22
|
+
export declare function roundUsd(value: number): number;
|
|
23
|
+
//# sourceMappingURL=receipt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"receipt.d.ts","sourceRoot":"","sources":["../../src/workflow/receipt.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAElE,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAE7D;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED,wBAAgB,iBAAiB,CAAC,MAAM,SAAS,GAAG,MAAM,CAEzD;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,GAAG,MAAM,CAEhF;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE;IACjC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,qBAAqB,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,uBAAuB,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC,gCAAgC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,gBAAgB,CAAC,EAAE,uBAAuB,GAAG,IAAI,CAAC;IAClD,YAAY,CAAC,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;IACzC,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC,GAAG,SAAS,CA6BZ;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,SAAS,GAAG,OAAO,CAGzD;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE9C"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.canonicalJSONStringify = canonicalJSONStringify;
|
|
4
|
+
exports.sha256 = sha256;
|
|
5
|
+
exports.workflowReceiptId = workflowReceiptId;
|
|
6
|
+
exports.signReceiptPayload = signReceiptPayload;
|
|
7
|
+
exports.buildReceipt = buildReceipt;
|
|
8
|
+
exports.verifyReceipt = verifyReceipt;
|
|
9
|
+
exports.roundUsd = roundUsd;
|
|
10
|
+
const crypto_1 = require("crypto");
|
|
11
|
+
const decision_log_1 = require("../decision-log");
|
|
12
|
+
function canonicalJSONStringify(value) {
|
|
13
|
+
return (0, decision_log_1.canonicalJson)(value);
|
|
14
|
+
}
|
|
15
|
+
function sha256(input) {
|
|
16
|
+
return (0, decision_log_1.sha256Hex)(input);
|
|
17
|
+
}
|
|
18
|
+
function workflowReceiptId(prefix = 'ag_r') {
|
|
19
|
+
return `${prefix}_${(0, crypto_1.randomUUID)().replace(/-/g, '').slice(0, 16)}`;
|
|
20
|
+
}
|
|
21
|
+
function signReceiptPayload(payload) {
|
|
22
|
+
return (0, decision_log_1.sha256Hex)((0, decision_log_1.canonicalJson)(payload));
|
|
23
|
+
}
|
|
24
|
+
function buildReceipt(args) {
|
|
25
|
+
if (!Number.isFinite(args.cost_usd) || args.cost_usd < 0) {
|
|
26
|
+
throw new Error('Workflow receipt cost must be a finite non-negative number');
|
|
27
|
+
}
|
|
28
|
+
const publicKeyFingerprint = (0, crypto_1.createHash)('sha256')
|
|
29
|
+
.update(args.workflow_id || args.user_id || 'agentguard-workflow')
|
|
30
|
+
.digest('hex')
|
|
31
|
+
.slice(0, 16);
|
|
32
|
+
const unsigned = {
|
|
33
|
+
receipt_id: workflowReceiptId(args.is_checkpoint ? 'ag_cp' : 'ag_r'),
|
|
34
|
+
schema_version: 2,
|
|
35
|
+
outcome_name: args.outcome_name,
|
|
36
|
+
user_id: args.user_id,
|
|
37
|
+
cost_usd: roundUsd(args.cost_usd),
|
|
38
|
+
signed_at: new Date().toISOString(),
|
|
39
|
+
public_key_fingerprint: publicKeyFingerprint,
|
|
40
|
+
workflow_id: args.workflow_id,
|
|
41
|
+
parent_receipt_id: args.parent_receipt_id,
|
|
42
|
+
chain_validation_hash: args.chain_validation_hash,
|
|
43
|
+
workflow_checkpoint_idx: args.workflow_checkpoint_idx,
|
|
44
|
+
workflow_total_spend_usd_to_date: args.workflow_total_spend_usd_to_date === null ? null : roundUsd(args.workflow_total_spend_usd_to_date),
|
|
45
|
+
is_checkpoint: args.is_checkpoint === true,
|
|
46
|
+
checkpoint_label: args.checkpoint_label ?? null,
|
|
47
|
+
reviewer_cascade: args.reviewer_cascade ?? null,
|
|
48
|
+
receipt_type: args.receipt_type ?? (args.is_checkpoint ? 'checkpoint' : 'outcome'),
|
|
49
|
+
cancelled_reason: args.cancelled_reason ?? null,
|
|
50
|
+
};
|
|
51
|
+
return { ...unsigned, signature: signReceiptPayload(unsigned) };
|
|
52
|
+
}
|
|
53
|
+
function verifyReceipt(receipt) {
|
|
54
|
+
const { signature: _signature, ...unsigned } = receipt;
|
|
55
|
+
return signReceiptPayload(unsigned) === receipt.signature;
|
|
56
|
+
}
|
|
57
|
+
function roundUsd(value) {
|
|
58
|
+
return Math.round(value * 1_000_000) / 1_000_000;
|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