@402flow/sdk 0.1.0-alpha.3 → 0.1.0-alpha.30

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.
@@ -0,0 +1,487 @@
1
+ /**
2
+ * AgentHarness provides a small in-memory orchestration layer on top of
3
+ * AgentPayClient for hosts that prefer preparedId-based handoffs over holding
4
+ * full prepared request objects.
5
+ *
6
+ * The intended host-facing flow is:
7
+ *
8
+ * 1. prepare a candidate request and receive a preparedId plus the preparation summary
9
+ * 2. execute later by preparedId once nextAction is execute
10
+ * 3. read back the stored execution result by preparedId
11
+ *
12
+ * This is useful for tool-driven hosts such as OpenAI tools, MCP servers,
13
+ * Claude tools, LangGraph nodes, or custom orchestrators where passing a small
14
+ * opaque id between turns is easier than preserving the full prepared object.
15
+ *
16
+ * This file implements only a convenience layer. The core SDK contract remains
17
+ * AgentPayClient with preparePaidRequest() and executePreparedRequest().
18
+ *
19
+ * Important behavior:
20
+ * - State is kept only in memory inside this process.
21
+ * - Prepared requests expire after a TTL.
22
+ * - A newer active preparation for the same method + origin + pathname supersedes
23
+ * the older one.
24
+ * - Execution is rejected locally unless the stored preparation is still active,
25
+ * kind === 'ready', and nextAction === 'execute'.
26
+ */
27
+ import { randomUUID } from 'node:crypto';
28
+ /** Typed error used internally to convert local state failures into stable results. */
29
+ export class AgentHarnessError extends Error {
30
+ code;
31
+ preparedId;
32
+ constructor(code, message, preparedId) {
33
+ super(message);
34
+ this.name = 'AgentHarnessError';
35
+ this.code = code;
36
+ this.preparedId = preparedId;
37
+ Object.setPrototypeOf(this, new.target.prototype);
38
+ }
39
+ }
40
+ const defaultPreparedTtlMs = 5 * 60 * 1000;
41
+ // Preparations supersede by stable execution target, not by full query/body, so a
42
+ // newer attempt for the same endpoint path invalidates older active ones.
43
+ function createSupersessionKey(binding) {
44
+ const url = new URL(binding.url);
45
+ return `${binding.method}:${url.origin}${url.pathname}`;
46
+ }
47
+ function deepFreeze(value) {
48
+ if (value === null || typeof value !== 'object' || Object.isFrozen(value)) {
49
+ return value;
50
+ }
51
+ if (Array.isArray(value)) {
52
+ for (const entry of value) {
53
+ deepFreeze(entry);
54
+ }
55
+ }
56
+ else {
57
+ for (const entry of Object.values(value)) {
58
+ deepFreeze(entry);
59
+ }
60
+ }
61
+ return Object.freeze(value);
62
+ }
63
+ // All records exposed back to callers are cloned and frozen so host code cannot
64
+ // mutate the harness' in-memory state by retaining object references.
65
+ function cloneValue(value) {
66
+ return structuredClone(value);
67
+ }
68
+ function createFrozenClone(value) {
69
+ return deepFreeze(cloneValue(value));
70
+ }
71
+ function normalizeHeaders(headers) {
72
+ const normalizedHeaders = {};
73
+ if (!headers) {
74
+ return normalizedHeaders;
75
+ }
76
+ const headerMap = new Headers(headers);
77
+ headerMap.forEach((value, key) => {
78
+ normalizedHeaders[key] = value;
79
+ });
80
+ return normalizedHeaders;
81
+ }
82
+ function buildExecutionBinding(prepared) {
83
+ // Capture the exact prepared execution payload once so later execute calls do
84
+ // not depend on the host resending or reconstructing it correctly.
85
+ return createFrozenClone({
86
+ method: prepared.request.method,
87
+ url: prepared.request.url,
88
+ headers: normalizeHeaders(prepared.request.headers),
89
+ ...(prepared.request.body !== undefined ? { body: prepared.request.body } : {}),
90
+ ...(prepared.request.bodyHash !== undefined
91
+ ? { bodyHash: prepared.request.bodyHash }
92
+ : {}),
93
+ ...(prepared.kind === 'ready'
94
+ ? {
95
+ challenge: {
96
+ protocol: prepared.challenge.protocol,
97
+ headers: normalizeHeaders(prepared.challenge.headers),
98
+ ...(prepared.challenge.body !== undefined
99
+ ? { body: cloneValue(prepared.challenge.body) }
100
+ : {}),
101
+ },
102
+ }
103
+ : {}),
104
+ merchantOrigin: new URL(prepared.request.url).origin,
105
+ });
106
+ }
107
+ const knownNetworkLabels = {
108
+ 'eip155:84532': 'Base Sepolia',
109
+ 'base-sepolia': 'Base Sepolia',
110
+ 'eip155:8453': 'Base',
111
+ base: 'Base',
112
+ 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1': 'Solana Devnet',
113
+ 'solana-devnet': 'Solana Devnet',
114
+ 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp': 'Solana',
115
+ 'solana-mainnet': 'Solana',
116
+ };
117
+ const knownAssetMetadata = {
118
+ '0x036cbd53842c5426634e7929541ec2318f3dcf7e': {
119
+ name: 'USDC',
120
+ precision: 6,
121
+ },
122
+ '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913': {
123
+ name: 'USDC',
124
+ precision: 6,
125
+ },
126
+ '4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU': {
127
+ name: 'USDC',
128
+ precision: 6,
129
+ },
130
+ EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v: {
131
+ name: 'USDC',
132
+ precision: 6,
133
+ },
134
+ };
135
+ function normalizeAssetLookupKey(asset) {
136
+ return asset.startsWith('0x') ? asset.toLowerCase() : asset;
137
+ }
138
+ function formatMinorAmount(amountMinor, precision) {
139
+ const normalizedMinor = amountMinor.replace(/^0+(?=\d)/, '') || '0';
140
+ if (precision === 0) {
141
+ return normalizedMinor;
142
+ }
143
+ const paddedMinor = normalizedMinor.padStart(precision + 1, '0');
144
+ const wholePart = paddedMinor.slice(0, -precision) || '0';
145
+ const fractionalPart = paddedMinor.slice(-precision);
146
+ return `${wholePart}.${fractionalPart}`;
147
+ }
148
+ function getChallengeAssetName(challengeDetails) {
149
+ const extra = challengeDetails?.accepts[0]?.extra;
150
+ if (!extra || typeof extra !== 'object') {
151
+ return undefined;
152
+ }
153
+ const name = extra.name;
154
+ return typeof name === 'string' && name.length > 0 ? name : undefined;
155
+ }
156
+ function getChallengePrecision(challengeDetails) {
157
+ const extra = challengeDetails?.accepts[0]?.extra;
158
+ if (!extra || typeof extra !== 'object') {
159
+ return undefined;
160
+ }
161
+ const precision = extra.precision;
162
+ return typeof precision === 'number' && Number.isInteger(precision) ? precision : undefined;
163
+ }
164
+ function getAmountTypeLabel(amountType) {
165
+ if (amountType === 'exact') {
166
+ return 'exact';
167
+ }
168
+ if (amountType === 'max') {
169
+ return 'up to';
170
+ }
171
+ return undefined;
172
+ }
173
+ function buildCostSummary(prepared) {
174
+ if (prepared.kind === 'passthrough') {
175
+ return 'No payment required.';
176
+ }
177
+ const paymentRequirement = prepared.paymentRequirement;
178
+ if (!paymentRequirement) {
179
+ return undefined;
180
+ }
181
+ const knownAsset = paymentRequirement.asset
182
+ ? knownAssetMetadata[normalizeAssetLookupKey(paymentRequirement.asset)]
183
+ : undefined;
184
+ const resolvedPrecision = paymentRequirement.precision
185
+ ?? getChallengePrecision(prepared.challengeDetails)
186
+ ?? knownAsset?.precision;
187
+ const amount = paymentRequirement.amount
188
+ ?? (paymentRequirement.amountMinor !== undefined && resolvedPrecision !== undefined
189
+ ? formatMinorAmount(paymentRequirement.amountMinor, resolvedPrecision)
190
+ : undefined);
191
+ const assetName = getChallengeAssetName(prepared.challengeDetails)
192
+ ?? (paymentRequirement.asset
193
+ ? knownAsset?.name
194
+ ?? paymentRequirement.asset
195
+ : undefined);
196
+ const networkLabel = paymentRequirement.network
197
+ ? knownNetworkLabels[paymentRequirement.network] ?? paymentRequirement.network
198
+ : undefined;
199
+ const amountTypeLabel = getAmountTypeLabel(paymentRequirement.amountType);
200
+ if (!amount || !assetName || !networkLabel || !amountTypeLabel) {
201
+ return undefined;
202
+ }
203
+ return `Costs ${amount} ${assetName} on ${networkLabel} (${amountTypeLabel}).`;
204
+ }
205
+ function summarizePreparedRecord(record) {
206
+ const costSummary = buildCostSummary(record.prepared);
207
+ return cloneValue({
208
+ preparedId: record.preparedId,
209
+ state: 'active',
210
+ kind: record.prepared.kind,
211
+ protocol: record.prepared.protocol,
212
+ ...(costSummary ? { costSummary } : {}),
213
+ ...(record.prepared.kind === 'ready' && record.prepared.challengeDetails
214
+ ? { challengeDetails: record.prepared.challengeDetails }
215
+ : {}),
216
+ ...(record.prepared.kind === 'ready' && record.prepared.paymentRequirement
217
+ ? { paymentRequirement: record.prepared.paymentRequirement }
218
+ : {}),
219
+ hints: record.prepared.hints,
220
+ ...(record.prepared.probe ? { probe: record.prepared.probe } : {}),
221
+ validationIssues: record.prepared.validationIssues,
222
+ nextAction: record.prepared.nextAction,
223
+ expiresAt: record.expiresAt,
224
+ });
225
+ }
226
+ async function summarizeMerchantResponse(response) {
227
+ const headers = {};
228
+ response.headers.forEach((value, key) => {
229
+ headers[key] = value;
230
+ });
231
+ return {
232
+ status: response.status,
233
+ headers,
234
+ body: await response.clone().text(),
235
+ };
236
+ }
237
+ async function summarizeExecutionOutcome(preparedId, outcome) {
238
+ return {
239
+ preparedId,
240
+ harnessDisposition: 'executed',
241
+ sdkOutcomeKind: outcome.kind,
242
+ status: outcome.response.status,
243
+ merchantResponse: await summarizeMerchantResponse(outcome.response),
244
+ ...('receiptId' in outcome && outcome.receiptId
245
+ ? { receiptId: outcome.receiptId }
246
+ : {}),
247
+ ...('paidRequestId' in outcome && outcome.paidRequestId
248
+ ? { paidRequestId: outcome.paidRequestId }
249
+ : {}),
250
+ ...('paymentAttemptId' in outcome && outcome.paymentAttemptId
251
+ ? { paymentAttemptId: outcome.paymentAttemptId }
252
+ : {}),
253
+ ...('reason' in outcome && typeof outcome.reason === 'string'
254
+ ? { reason: outcome.reason }
255
+ : {}),
256
+ ...('policyReviewEventId' in outcome && outcome.policyReviewEventId
257
+ ? { policyReviewEventId: outcome.policyReviewEventId }
258
+ : {}),
259
+ };
260
+ }
261
+ function isFetchPaidFailureResponse(value) {
262
+ if (typeof value !== 'object' || value === null) {
263
+ return false;
264
+ }
265
+ const candidate = value;
266
+ return (typeof candidate.kind === 'string' &&
267
+ typeof candidate.protocol === 'string' &&
268
+ candidate.response instanceof Response &&
269
+ typeof candidate.reason === 'string' &&
270
+ typeof candidate.decision === 'object' &&
271
+ candidate.decision !== null);
272
+ }
273
+ function isFetchPaidErrorLike(error) {
274
+ if (!(error instanceof Error) || error.name !== 'FetchPaidError') {
275
+ return false;
276
+ }
277
+ const candidate = error;
278
+ return isFetchPaidFailureResponse(candidate.details);
279
+ }
280
+ /**
281
+ * Optional in-memory preparedId wrapper over AgentPayClient.
282
+ */
283
+ export class AgentHarness {
284
+ client;
285
+ preparedTtlMs;
286
+ now;
287
+ createPreparedId;
288
+ preparedRecords = new Map();
289
+ constructor(options) {
290
+ this.client = options.client;
291
+ this.preparedTtlMs = options.preparedTtlMs ?? defaultPreparedTtlMs;
292
+ this.now = options.now ?? (() => new Date());
293
+ this.createPreparedId = options.createPreparedId ?? (() => randomUUID());
294
+ }
295
+ /**
296
+ * Prepare a candidate request through the core SDK and store the immutable
297
+ * prepared result behind a generated preparedId for later execution.
298
+ */
299
+ async preparePaidRequest(input) {
300
+ // Prepare against the SDK, then store the exact prepared request behind a
301
+ // deterministic id so later tool calls do not need to resend the full payload.
302
+ const prepared = await this.client.preparePaidRequest(input.url, {
303
+ ...(input.method ? { method: input.method } : {}),
304
+ ...(input.headers ? { headers: input.headers } : {}),
305
+ ...(input.body !== undefined ? { body: input.body } : {}),
306
+ }, {
307
+ ...(input.externalMetadata
308
+ ? { externalMetadata: input.externalMetadata }
309
+ : {}),
310
+ });
311
+ const createdAt = this.now();
312
+ const preparedId = this.createPreparedId();
313
+ const record = {
314
+ preparedId,
315
+ state: 'active',
316
+ createdAt: createdAt.toISOString(),
317
+ expiresAt: new Date(createdAt.getTime() + this.preparedTtlMs).toISOString(),
318
+ prepared: createFrozenClone(prepared),
319
+ executionBinding: buildExecutionBinding(prepared),
320
+ };
321
+ this.supersedeActiveRecords(record);
322
+ this.preparedRecords.set(preparedId, record);
323
+ return summarizePreparedRecord(record);
324
+ }
325
+ /**
326
+ * Execute a previously stored ready preparation. Local state failures are
327
+ * converted into deterministic rejected results rather than thrown to the host.
328
+ */
329
+ async executePreparedRequest(input) {
330
+ try {
331
+ // Execution is only allowed for active, ready preparations. All rejected
332
+ // local states are converted into stored deterministic results.
333
+ const record = this.getRecordForExecution(input.preparedId);
334
+ const executionPromise = record.executionPromise ??
335
+ this.createExecutionPromise(record, input.executionContext);
336
+ const outcome = await executionPromise;
337
+ return cloneValue(outcome);
338
+ }
339
+ catch (error) {
340
+ if (!(error instanceof AgentHarnessError)) {
341
+ throw error;
342
+ }
343
+ return this.handleExecutionRejection(input.preparedId, error);
344
+ }
345
+ }
346
+ /**
347
+ * Return the stored in-memory outcome for a preparedId without re-running any
348
+ * merchant or control-plane call.
349
+ */
350
+ getExecutionResult(preparedId) {
351
+ // This lookup lets an agent fetch the stored in-memory outcome later without
352
+ // re-running execution or depending on host-specific tool memory.
353
+ const record = this.getKnownRecord(preparedId);
354
+ this.refreshRecordState(record);
355
+ return cloneValue({
356
+ preparedId: record.preparedId,
357
+ state: record.state,
358
+ ...(record.supersededByPreparedId
359
+ ? { supersededByPreparedId: record.supersededByPreparedId }
360
+ : {}),
361
+ ...(record.executionResult
362
+ ? { executionResult: record.executionResult }
363
+ : {}),
364
+ });
365
+ }
366
+ /**
367
+ * Return the full stored record for debugging, tests, or host inspection.
368
+ */
369
+ getPreparedRecord(preparedId) {
370
+ const record = this.getKnownRecord(preparedId);
371
+ this.refreshRecordState(record);
372
+ return cloneValue({
373
+ preparedId: record.preparedId,
374
+ state: record.state,
375
+ createdAt: record.createdAt,
376
+ expiresAt: record.expiresAt,
377
+ ...(record.supersededByPreparedId
378
+ ? { supersededByPreparedId: record.supersededByPreparedId }
379
+ : {}),
380
+ prepared: record.prepared,
381
+ executionBinding: record.executionBinding,
382
+ ...(record.executionResult
383
+ ? { executionResult: record.executionResult }
384
+ : {}),
385
+ });
386
+ }
387
+ async runExecution(record, executionContext) {
388
+ try {
389
+ const response = await this.client.executePreparedRequest(record.prepared, executionContext);
390
+ return summarizeExecutionOutcome(record.preparedId, response);
391
+ }
392
+ catch (error) {
393
+ if (!isFetchPaidErrorLike(error)) {
394
+ throw error;
395
+ }
396
+ return summarizeExecutionOutcome(record.preparedId, error.details);
397
+ }
398
+ }
399
+ createExecutionPromise(record, executionContext) {
400
+ const executionPromise = this.runExecution(record, executionContext)
401
+ .then((outcome) => {
402
+ record.state = 'consumed';
403
+ record.executionResult = createFrozenClone(outcome);
404
+ return record.executionResult;
405
+ })
406
+ .finally(() => {
407
+ delete record.executionPromise;
408
+ });
409
+ record.executionPromise = executionPromise;
410
+ return executionPromise;
411
+ }
412
+ // Rejection results are stored so later lookups remain deterministic even when
413
+ // execution never reached the core SDK or merchant.
414
+ handleExecutionRejection(preparedId, error) {
415
+ const rejectedResult = {
416
+ preparedId,
417
+ harnessDisposition: 'rejected',
418
+ rejectionCode: error.code,
419
+ message: error.message,
420
+ };
421
+ const record = preparedId ? this.preparedRecords.get(preparedId) : undefined;
422
+ if (record &&
423
+ error.code !== 'prepared_request_consumed' &&
424
+ !record.executionResult) {
425
+ record.executionResult = createFrozenClone(rejectedResult);
426
+ }
427
+ return rejectedResult;
428
+ }
429
+ getRecordForExecution(preparedId) {
430
+ const record = this.getKnownRecord(preparedId);
431
+ this.refreshRecordState(record);
432
+ if (record.state === 'expired') {
433
+ throw new AgentHarnessError('expired_prepared_id', `Prepared request ${preparedId} has expired.`, preparedId);
434
+ }
435
+ if (record.state === 'superseded') {
436
+ throw new AgentHarnessError('prepared_request_superseded', record.supersededByPreparedId
437
+ ? `Prepared request ${preparedId} was superseded by ${record.supersededByPreparedId}.`
438
+ : `Prepared request ${preparedId} was superseded by a newer preparation.`, preparedId);
439
+ }
440
+ if (record.state === 'consumed') {
441
+ throw new AgentHarnessError('prepared_request_consumed', `Prepared request ${preparedId} has already been consumed.`, preparedId);
442
+ }
443
+ if (record.prepared.kind !== 'ready') {
444
+ throw new AgentHarnessError('prepared_request_not_ready', `Prepared request ${preparedId} is not executable because it is ${record.prepared.kind}.`, preparedId);
445
+ }
446
+ if (record.prepared.nextAction !== 'execute') {
447
+ throw new AgentHarnessError('prepared_request_not_executable', `Prepared request ${preparedId} requires ${record.prepared.nextAction} before execution.`, preparedId);
448
+ }
449
+ return record;
450
+ }
451
+ getKnownRecord(preparedId) {
452
+ if (preparedId.trim().length === 0) {
453
+ throw new AgentHarnessError('missing_prepared_id', 'A preparedId is required.');
454
+ }
455
+ const record = this.preparedRecords.get(preparedId);
456
+ if (!record) {
457
+ throw new AgentHarnessError('unknown_prepared_id', `Prepared request ${preparedId} is unknown.`, preparedId);
458
+ }
459
+ return record;
460
+ }
461
+ // Expiry is checked lazily on access so the harness does not need timers or a
462
+ // background cleanup loop.
463
+ refreshRecordState(record) {
464
+ if (record.state !== 'active') {
465
+ return;
466
+ }
467
+ if (this.now().getTime() >= new Date(record.expiresAt).getTime()) {
468
+ record.state = 'expired';
469
+ }
470
+ }
471
+ supersedeActiveRecords(nextRecord) {
472
+ // Only one active preparation should survive for the same method + origin +
473
+ // pathname. Older active preparations become stale as soon as a newer one is stored.
474
+ const nextKey = createSupersessionKey(nextRecord.executionBinding);
475
+ for (const record of this.preparedRecords.values()) {
476
+ if (record.state !== 'active') {
477
+ continue;
478
+ }
479
+ if (createSupersessionKey(record.executionBinding) !== nextKey) {
480
+ continue;
481
+ }
482
+ record.state = 'superseded';
483
+ record.supersededByPreparedId = nextRecord.preparedId;
484
+ }
485
+ }
486
+ }
487
+ //# sourceMappingURL=agent-harness.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-harness.js","sourceRoot":"","sources":["../src/agent-harness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAqCzC,uFAAuF;AACvF,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACjC,IAAI,CAA4B;IAChC,UAAU,CAAqB;IAExC,YACE,IAA+B,EAC/B,OAAe,EACf,UAAmB;QAEnB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,MAAM,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,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,EAAE,CAAC;YACnD,IAAI,MAAM,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC9B,SAAS;YACX,CAAC;YAED,IAAI,qBAAqB,CAAC,MAAM,CAAC,gBAAgB,CAAC,KAAK,OAAO,EAAE,CAAC;gBAC/D,SAAS;YACX,CAAC;YAED,MAAM,CAAC,KAAK,GAAG,YAAY,CAAC;YAC5B,MAAM,CAAC,sBAAsB,GAAG,UAAU,CAAC,UAAU,CAAC;QACxD,CAAC;IACH,CAAC;CACF"}
@@ -1,5 +1,17 @@
1
- import { getX402PaymentRequired, type ParsedChallenge } from './challenge-types.js';
2
- export declare function detectChallengeFromResponse(response: Response): Promise<ParsedChallenge | undefined>;
3
- export declare function parseX402PaymentResponseFromHeaders(headers: Headers | Record<string, string>): import("./challenge-types.js").X402PaymentResponse | undefined;
4
- export declare function parseX402PaymentResponseHeader(headerValue: string | null): import("./challenge-types.js").X402PaymentResponse | undefined;
5
- export { getX402PaymentRequired, type ParsedChallenge };
1
+ /**
2
+ * Detects whether an unpaid merchant response is actually a payable challenge and,
3
+ * if so, which paid-request protocol it speaks.
4
+ */
5
+ import type { PaidRequestProtocol } from './contracts.js';
6
+ /** Minimal challenge shape the rest of the SDK needs in order to proceed. */
7
+ export type DetectedChallenge = {
8
+ protocol: PaidRequestProtocol;
9
+ headers: Record<string, string>;
10
+ body?: unknown;
11
+ };
12
+ /**
13
+ * Inspect a merchant response for x402/l402 challenge evidence in either headers
14
+ * or a JSON body. The SDK prefers header evidence first because that is the most
15
+ * direct live protocol signal.
16
+ */
17
+ export declare function detectChallengeFromResponse(response: Response): Promise<DetectedChallenge | undefined>;