@paybond/kit 0.11.10 → 0.12.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 (128) hide show
  1. package/README.md +2 -2
  2. package/completion-presets/catalog.json +374 -3
  3. package/completion-presets/catalog.sha256 +1 -1
  4. package/dist/agent/facade.js +13 -0
  5. package/dist/agent/guarded-agent.d.ts +1 -1
  6. package/dist/agent/guarded-agent.js +19 -0
  7. package/dist/agent/index.d.ts +2 -1
  8. package/dist/agent/index.js +1 -0
  9. package/dist/agent/instrument.d.ts +6 -0
  10. package/dist/agent/instrument.js +6 -0
  11. package/dist/agent/interceptor.d.ts +9 -0
  12. package/dist/agent/interceptor.js +177 -1
  13. package/dist/agent/receipt-client.d.ts +49 -0
  14. package/dist/agent/receipt-client.js +45 -0
  15. package/dist/agent/registry.js +1 -0
  16. package/dist/agent/run.d.ts +2 -0
  17. package/dist/agent/run.js +52 -0
  18. package/dist/agent/types.d.ts +70 -0
  19. package/dist/agent-receipt-external-attestations.d.ts +29 -0
  20. package/dist/agent-receipt-external-attestations.js +124 -0
  21. package/dist/agent-receipt.d.ts +134 -0
  22. package/dist/agent-receipt.js +580 -0
  23. package/dist/agent-recognition.d.ts +25 -0
  24. package/dist/agent-recognition.js +36 -0
  25. package/dist/audit/exports.d.ts +72 -0
  26. package/dist/audit/exports.js +185 -0
  27. package/dist/audit/index.d.ts +3 -0
  28. package/dist/audit/index.js +3 -0
  29. package/dist/audit/verify.d.ts +8 -0
  30. package/dist/audit/verify.js +113 -0
  31. package/dist/audit/wire.d.ts +54 -0
  32. package/dist/audit/wire.js +80 -0
  33. package/dist/cli/agent/demo-loaders.d.ts +2 -0
  34. package/dist/cli/agent/demo-loaders.js +24 -0
  35. package/dist/cli/agent/production-evidence.d.ts +11 -0
  36. package/dist/cli/agent/production-evidence.js +17 -0
  37. package/dist/cli/audit-export.d.ts +2 -7
  38. package/dist/cli/audit-export.js +2 -120
  39. package/dist/cli/command-spec.js +43 -10
  40. package/dist/cli/commands/agent.d.ts +3 -0
  41. package/dist/cli/commands/agent.js +143 -1
  42. package/dist/cli/commands/discovery.js +39 -36
  43. package/dist/cli/commands/workflows.js +116 -18
  44. package/dist/cli/help.d.ts +1 -1
  45. package/dist/cli/help.js +12 -8
  46. package/dist/cli/intents-harbor-mutation.d.ts +18 -0
  47. package/dist/cli/intents-harbor-mutation.js +33 -0
  48. package/dist/cli/paybond.d.ts +9 -0
  49. package/dist/cli/paybond.js +23 -0
  50. package/dist/cli/redact.js +3 -0
  51. package/dist/cloudflare-agents/config.d.ts +24 -0
  52. package/dist/cloudflare-agents/config.js +23 -0
  53. package/dist/cloudflare-agents/index.d.ts +3 -0
  54. package/dist/cloudflare-agents/index.js +3 -0
  55. package/dist/cloudflare-agents/peer.d.ts +9 -0
  56. package/dist/cloudflare-agents/peer.js +20 -0
  57. package/dist/cloudflare-agents/sandbox-demo.d.ts +36 -0
  58. package/dist/cloudflare-agents/sandbox-demo.js +89 -0
  59. package/dist/completion-catalog-digest.d.ts +1 -1
  60. package/dist/completion-catalog-digest.js +1 -1
  61. package/dist/completion-init.js +8 -3
  62. package/dist/dev/offline-gateway.d.ts +2 -1
  63. package/dist/dev/offline-gateway.js +34 -3
  64. package/dist/dev/x402-fund-mock.d.ts +28 -0
  65. package/dist/dev/x402-fund-mock.js +124 -0
  66. package/dist/index.d.ts +125 -9
  67. package/dist/index.js +264 -17
  68. package/dist/init.js +113 -2
  69. package/dist/mastra/config.d.ts +30 -0
  70. package/dist/mastra/config.js +58 -0
  71. package/dist/mastra/index.d.ts +2 -0
  72. package/dist/mastra/index.js +2 -0
  73. package/dist/mastra/peer.d.ts +11 -0
  74. package/dist/mastra/peer.js +24 -0
  75. package/dist/mastra/sandbox-demo.d.ts +36 -0
  76. package/dist/mastra/sandbox-demo.js +87 -0
  77. package/dist/mcp/index.d.ts +1 -0
  78. package/dist/mcp/index.js +1 -0
  79. package/dist/mcp/sandbox-demo.d.ts +38 -0
  80. package/dist/mcp/sandbox-demo.js +112 -0
  81. package/dist/mcp-receipt-resource.d.ts +10 -0
  82. package/dist/mcp-receipt-resource.js +32 -0
  83. package/dist/mcp-server.d.ts +6 -0
  84. package/dist/mcp-server.js +124 -1
  85. package/dist/mpp-commercial.d.ts +19 -0
  86. package/dist/mpp-commercial.js +34 -0
  87. package/dist/mpp-funding.d.ts +71 -0
  88. package/dist/mpp-funding.js +192 -0
  89. package/dist/payment-transport.d.ts +30 -0
  90. package/dist/payment-transport.js +56 -0
  91. package/dist/policy/init.js +2 -0
  92. package/dist/policy/intent-spec.js +2 -0
  93. package/dist/principal-intent.d.ts +1 -1
  94. package/dist/principal-intent.js +4 -1
  95. package/dist/project-init.js +8 -0
  96. package/dist/template-init.d.ts +2 -2
  97. package/dist/template-init.js +6 -2
  98. package/dist/x402-funding.d.ts +52 -0
  99. package/dist/x402-funding.js +124 -0
  100. package/package.json +20 -2
  101. package/templates/manifest.json +28 -9
  102. package/templates/openai-shopping-agent/package-lock.json +16 -8
  103. package/templates/openai-shopping-agent/package.json +1 -1
  104. package/templates/paybond-aws-operator/package-lock.json +13 -5
  105. package/templates/paybond-aws-operator/package.json +1 -1
  106. package/templates/paybond-claude-agents-demo/package-lock.json +16 -8
  107. package/templates/paybond-claude-agents-demo/package.json +1 -1
  108. package/templates/paybond-invoice-agent/requirements.txt +1 -1
  109. package/templates/paybond-mastra-travel-agent/.env.example +3 -0
  110. package/templates/paybond-mastra-travel-agent/.github/workflows/smoke.yml +20 -0
  111. package/templates/paybond-mastra-travel-agent/LICENSE +201 -0
  112. package/templates/paybond-mastra-travel-agent/README.md +29 -0
  113. package/templates/paybond-mastra-travel-agent/package-lock.json +3377 -0
  114. package/templates/paybond-mastra-travel-agent/package.json +22 -0
  115. package/templates/paybond-mastra-travel-agent/paybond.policy.yaml +22 -0
  116. package/templates/paybond-mastra-travel-agent/src/index.ts +22 -0
  117. package/templates/paybond-mastra-travel-agent/src/paybond.config.ts +51 -0
  118. package/templates/paybond-mastra-travel-agent/tsconfig.json +13 -0
  119. package/templates/paybond-mcp-coding-agent/package-lock.json +13 -5
  120. package/templates/paybond-mcp-coding-agent/package.json +1 -1
  121. package/templates/paybond-openai-agents-demo/package-lock.json +16 -8
  122. package/templates/paybond-openai-agents-demo/package.json +1 -1
  123. package/templates/paybond-procurement-agent/package-lock.json +13 -5
  124. package/templates/paybond-procurement-agent/package.json +1 -1
  125. package/templates/paybond-travel-agent/package-lock.json +16 -8
  126. package/templates/paybond-travel-agent/package.json +1 -1
  127. package/templates/paybond-vercel-shopping-agent/package-lock.json +13 -5
  128. package/templates/paybond-vercel-shopping-agent/package.json +1 -1
@@ -2,6 +2,8 @@ import { evictExpiredAuthorizationCache, takeValidCachedAuthorization, } from ".
2
2
  import { buildAutoEvidencePayload } from "./evidence.js";
3
3
  import { signHarborEvidenceSubmitRecognitionProof } from "../agent-recognition.js";
4
4
  import { signPayeeEvidenceBinding } from "../payee-evidence.js";
5
+ import { AGENT_RECEIPT_KIND_V1, AGENT_RECEIPT_SCHEMA_VERSION, AGENT_RECEIPT_SCOPE_ACTION, AGENT_RECEIPT_SIGNING_ALGORITHM_ED25519, AGENT_RECEIPT_VERSION_V1, actionReceiptId, agentReceiptMessageDigestSha256Hex, valueDigestSha256Hex, } from "../agent-receipt.js";
6
+ import { resolveExternalAttestations, } from "../agent-receipt-external-attestations.js";
5
7
  import { PaybondAutoEvidenceSubmitError, PaybondUnregisteredSideEffectingToolError, } from "./types.js";
6
8
  export { PaybondAutoEvidenceSubmitError, PaybondEvidenceSubmitError } from "./types.js";
7
9
  function nowRfc3339Seconds() {
@@ -27,6 +29,8 @@ function mapSandboxEvidenceResult(result) {
27
29
  intentId: result.intent_id,
28
30
  predicatePassed: result.predicate_passed ?? undefined,
29
31
  sandboxLifecycleStatus: result.sandbox_lifecycle_status,
32
+ payloadDigestSha256Hex: result.payload_digest?.trim().toLowerCase() || undefined,
33
+ artifactsDigestSha256Hex: result.artifacts_digest?.trim().toLowerCase() || undefined,
30
34
  };
31
35
  }
32
36
  function isSpendApprovalRequiredError(err) {
@@ -227,11 +231,14 @@ export class PaybondToolInterceptor {
227
231
  });
228
232
  const evidencePolicyDigest = cached?.policyDigest ?? pinnedDigest;
229
233
  let auth;
234
+ let authorizedAtMs;
230
235
  if (cached) {
231
236
  auth = cached.auth;
237
+ authorizedAtMs = cached.cachedAtMs;
232
238
  }
233
239
  else {
234
240
  auth = await this.binding.guard.assertSpendAuthorized(resolved.authInput);
241
+ authorizedAtMs = Date.now();
235
242
  this.emitTrace({
236
243
  type: "spend_authorized",
237
244
  runId: this.binding.runId,
@@ -266,6 +273,12 @@ export class PaybondToolInterceptor {
266
273
  });
267
274
  }
268
275
  const evidenceId = evidenceIdempotencyKey(this.binding.intentId, toolCallId);
276
+ const externalAttestations = this.resolveToolExternalAttestations(resolved.entry, toolResult, {
277
+ toolName,
278
+ toolCallId,
279
+ operation: resolved.operation,
280
+ arguments: input.arguments,
281
+ });
269
282
  const evidence = await this.submitAutoEvidence({
270
283
  entry: resolved.entry,
271
284
  toolName,
@@ -287,8 +300,27 @@ export class PaybondToolInterceptor {
287
300
  evidencePreset: resolved.entry.evidencePreset,
288
301
  sandboxLifecycleStatus: evidence.sandboxLifecycleStatus,
289
302
  predicatePassed: evidence.predicatePassed,
303
+ externalAttestations,
290
304
  recordedAt: traceTimestamp(),
291
305
  });
306
+ const receiptDraft = this.buildReceiptDraft({
307
+ toolName: resolved.toolName,
308
+ toolCallId: resolved.toolCallId,
309
+ operation: resolved.operation,
310
+ arguments: input.arguments,
311
+ agentSubject: resolved.authInput.agentSubject,
312
+ requestedSpendCents: resolved.requestedSpendCents,
313
+ currency: resolved.authInput.currency,
314
+ vendorId: resolved.authInput.vendorId,
315
+ entry: resolved.entry,
316
+ auth,
317
+ authorizedAtMs,
318
+ policyDigest: evidencePolicyDigest,
319
+ executeStartedAt,
320
+ toolResult,
321
+ evidence,
322
+ externalAttestations,
323
+ });
292
324
  return {
293
325
  toolResult,
294
326
  authorization: {
@@ -298,6 +330,7 @@ export class PaybondToolInterceptor {
298
330
  policyDigest: evidencePolicyDigest,
299
331
  },
300
332
  evidence,
333
+ receiptDraft,
301
334
  };
302
335
  }
303
336
  catch (err) {
@@ -344,6 +377,7 @@ export class PaybondToolInterceptor {
344
377
  : Math.min(requestedSpendCents, sandboxSpend);
345
378
  }
346
379
  requestedSpendCents ??= 0;
380
+ const agentContext = this.binding.agentContext;
347
381
  return {
348
382
  toolName,
349
383
  toolCallId,
@@ -359,9 +393,12 @@ export class PaybondToolInterceptor {
359
393
  taskId: input.taskId,
360
394
  workflowId: input.workflowId,
361
395
  currency: input.currency,
362
- agentSubject: input.agentSubject,
396
+ agentSubject: input.agentSubject ?? agentContext?.operatorDid,
363
397
  approvalToken: input.approvalToken,
364
398
  idempotencyKey: input.idempotencyKey,
399
+ modelFamily: agentContext?.modelFamily,
400
+ configHashHex: agentContext?.configHashHex,
401
+ promptHashHex: agentContext?.promptHashHex,
365
402
  },
366
403
  };
367
404
  }
@@ -432,11 +469,19 @@ export class PaybondToolInterceptor {
432
469
  : typeof resultRecord.predicatePassed === "boolean"
433
470
  ? resultRecord.predicatePassed
434
471
  : undefined;
472
+ const payloadDigestSha256Hex = typeof resultRecord.payload_digest === "string"
473
+ ? resultRecord.payload_digest.trim().toLowerCase() || undefined
474
+ : undefined;
475
+ const artifactsDigestSha256Hex = typeof resultRecord.artifacts_digest === "string"
476
+ ? resultRecord.artifacts_digest.trim().toLowerCase() || undefined
477
+ : undefined;
435
478
  return {
436
479
  submitted: true,
437
480
  intentId: this.binding.intentId,
438
481
  intentState,
439
482
  predicatePassed,
483
+ payloadDigestSha256Hex,
484
+ artifactsDigestSha256Hex,
440
485
  };
441
486
  }
442
487
  catch (err) {
@@ -446,4 +491,135 @@ export class PaybondToolInterceptor {
446
491
  throw new PaybondAutoEvidenceSubmitError(options.toolResult, err);
447
492
  }
448
493
  }
494
+ /**
495
+ * Composes an unsigned Agent Receipt Standard draft (Phase 1) after a successful
496
+ * authorize → execute → evidence cycle. Never signed or persisted here; Phase 2 covers
497
+ * compose/sign/persist. Best-effort: returns `undefined` instead of throwing whenever
498
+ * required receipt fields (agent context, principal/operator DID, policy template, pinned
499
+ * policy digest, or a Harbor decision id) are unavailable on this binding or call.
500
+ */
501
+ buildReceiptDraft(options) {
502
+ try {
503
+ const agentContext = this.binding.agentContext;
504
+ if (!agentContext?.operatorDid || !agentContext.principalDid || !agentContext.policyTemplateId) {
505
+ return undefined;
506
+ }
507
+ if (!agentContext.configHashHex || !agentContext.promptHashHex) {
508
+ return undefined;
509
+ }
510
+ if (!options.auth.decisionId || !options.policyDigest) {
511
+ return undefined;
512
+ }
513
+ const actorSubject = options.agentSubject ?? agentContext.operatorDid;
514
+ const bareDigest = options.policyDigest.startsWith("sha256:")
515
+ ? options.policyDigest.slice("sha256:".length)
516
+ : options.policyDigest;
517
+ const completedAtMs = Date.now();
518
+ const argumentsDigest = valueDigestSha256Hex(options.arguments);
519
+ let resultDigest;
520
+ try {
521
+ resultDigest = valueDigestSha256Hex(options.toolResult);
522
+ }
523
+ catch {
524
+ resultDigest = undefined;
525
+ }
526
+ const harborState = options.evidence.intentState ?? options.evidence.sandboxLifecycleStatus ?? "evidence_submitted";
527
+ let merchant;
528
+ let evidenceBlock;
529
+ const payeeDid = this.binding.productionEvidence?.payeeDid;
530
+ if (payeeDid && options.evidence.payloadDigestSha256Hex) {
531
+ merchant = {
532
+ payee_did: payeeDid,
533
+ vendor_id: options.vendorId,
534
+ };
535
+ evidenceBlock = {
536
+ completion_preset_id: options.entry.evidencePreset,
537
+ payload_digest_sha256_hex: options.evidence.payloadDigestSha256Hex,
538
+ artifacts_digest_sha256_hex: options.evidence.artifactsDigestSha256Hex,
539
+ predicate_passed: options.evidence.predicatePassed ?? false,
540
+ payee_did: payeeDid,
541
+ };
542
+ }
543
+ const draft = {
544
+ schema_version: AGENT_RECEIPT_SCHEMA_VERSION,
545
+ kind: AGENT_RECEIPT_KIND_V1,
546
+ receipt_version: AGENT_RECEIPT_VERSION_V1,
547
+ scope: AGENT_RECEIPT_SCOPE_ACTION,
548
+ receipt_id: actionReceiptId(this.binding.intentId, options.toolCallId),
549
+ issued_at: new Date(completedAtMs).toISOString(),
550
+ tenant_id: this.binding.tenantId,
551
+ authorization: {
552
+ principal_did: agentContext.principalDid,
553
+ actor_subject: actorSubject,
554
+ agent: {
555
+ operator_did: agentContext.operatorDid,
556
+ model_family: agentContext.modelFamily,
557
+ model_instance_id: agentContext.modelInstanceId,
558
+ config_hash_sha256_hex: agentContext.configHashHex,
559
+ prompt_hash_sha256_hex: agentContext.promptHashHex,
560
+ },
561
+ decision_id: options.auth.decisionId,
562
+ audit_id: options.auth.auditId,
563
+ policy: {
564
+ template_id: agentContext.policyTemplateId,
565
+ content_digest_sha256_hex: bareDigest,
566
+ },
567
+ authorized_at: new Date(options.authorizedAtMs).toISOString(),
568
+ requested_spend_cents: options.requestedSpendCents,
569
+ currency: options.currency ?? "usd",
570
+ },
571
+ execution: {
572
+ run_id: this.binding.runId,
573
+ tool_call_id: options.toolCallId,
574
+ tool_name: options.toolName,
575
+ operation: options.operation,
576
+ arguments_digest_sha256_hex: argumentsDigest,
577
+ result_digest_sha256_hex: resultDigest,
578
+ outcome: "executed",
579
+ started_at: new Date(options.executeStartedAt).toISOString(),
580
+ completed_at: new Date(completedAtMs).toISOString(),
581
+ duration_ms: completedAtMs - options.executeStartedAt,
582
+ },
583
+ merchant,
584
+ evidence: evidenceBlock,
585
+ outcome: {
586
+ harbor_state: harborState,
587
+ spend_reservation_outcome: "consumed",
588
+ predicate_passed: options.evidence.predicatePassed ?? undefined,
589
+ },
590
+ references: {
591
+ intent_id: this.binding.intentId,
592
+ settlement_receipt_id: null,
593
+ },
594
+ external_attestations: options.externalAttestations ?? [],
595
+ signing_algorithm: AGENT_RECEIPT_SIGNING_ALGORITHM_ED25519,
596
+ message_digest_sha256_hex: "",
597
+ signing_public_key_ed25519_hex: "",
598
+ ed25519_signature_hex: "",
599
+ };
600
+ draft.message_digest_sha256_hex = agentReceiptMessageDigestSha256Hex(draft);
601
+ return draft;
602
+ }
603
+ catch {
604
+ // Draft composition is always best-effort; never fails tool execution (Phase 1).
605
+ return undefined;
606
+ }
607
+ }
608
+ resolveToolExternalAttestations(entry, toolResult, ctx) {
609
+ const mapper = entry.externalAttestationMapper;
610
+ if (!mapper) {
611
+ return [];
612
+ }
613
+ try {
614
+ const mapped = mapper(toolResult, ctx);
615
+ if (!mapped) {
616
+ return [];
617
+ }
618
+ const inputs = Array.isArray(mapped) ? mapped : [mapped];
619
+ return resolveExternalAttestations(inputs);
620
+ }
621
+ catch {
622
+ return [];
623
+ }
624
+ }
449
625
  }
@@ -0,0 +1,49 @@
1
+ import { type AgentReceiptV1 } from "../agent-receipt.js";
2
+ import type { PaybondAgentInput, PaybondAgentResult } from "./facade.js";
3
+ export type VerifyAgentReceiptV1Result = {
4
+ valid: boolean;
5
+ kind: string;
6
+ receipt_id: string;
7
+ tenant_id: string;
8
+ receipt: AgentReceiptV1;
9
+ };
10
+ type AgentReceiptProtocolClient = {
11
+ getAgentReceiptV1ByID(receiptId: string): Promise<AgentReceiptV1>;
12
+ getAgentReceiptV1ByIntentToolCall(init: {
13
+ intentId: string;
14
+ toolCallId: string;
15
+ }): Promise<AgentReceiptV1>;
16
+ verifyAgentReceiptV1(receipt: AgentReceiptV1 | Record<string, unknown>): Promise<VerifyAgentReceiptV1Result>;
17
+ };
18
+ export type GetAgentReceiptInput = {
19
+ receiptId: string;
20
+ intentId?: never;
21
+ toolCallId?: never;
22
+ } | {
23
+ intentId: string;
24
+ toolCallId: string;
25
+ receiptId?: never;
26
+ };
27
+ export type PaybondAgentCallable = ((input: PaybondAgentInput) => Promise<PaybondAgentResult>) & {
28
+ getReceipt(input: GetAgentReceiptInput): Promise<AgentReceiptV1>;
29
+ verifyReceipt(receipt: AgentReceiptV1, options?: {
30
+ offline?: boolean;
31
+ }): Promise<VerifyAgentReceiptV1Result | AgentReceiptV1>;
32
+ };
33
+ /** Tenant-bound agent quickstart plus receipt fetch/verify helpers. */
34
+ export declare class PaybondAgentFacade {
35
+ private readonly protocol;
36
+ private readonly invokeAgent?;
37
+ constructor(protocol: AgentReceiptProtocolClient, invokeAgent?: ((input: PaybondAgentInput) => Promise<PaybondAgentResult>) | undefined);
38
+ /** Fetch a signed `paybond.agent_receipt_v1` by receipt id or intent/tool-call lookup. */
39
+ getReceipt(input: GetAgentReceiptInput): Promise<AgentReceiptV1>;
40
+ /** Verify a signed agent receipt via Gateway or locally with {@link verifyAgentReceiptV1}. */
41
+ verifyReceipt(receipt: AgentReceiptV1, options?: {
42
+ offline?: boolean;
43
+ }): Promise<VerifyAgentReceiptV1Result | AgentReceiptV1>;
44
+ /** Opinionated quickstart: resolve policy presets and wire framework tools. */
45
+ call(input: PaybondAgentInput): Promise<PaybondAgentResult>;
46
+ }
47
+ /** Callable `paybond.agent({...})` surface with receipt helpers attached. */
48
+ export declare function createPaybondAgentCallable(protocol: AgentReceiptProtocolClient, invokeAgent: (input: PaybondAgentInput) => Promise<PaybondAgentResult>): PaybondAgentCallable;
49
+ export {};
@@ -0,0 +1,45 @@
1
+ import { verifyAgentReceiptV1, } from "../agent-receipt.js";
2
+ /** Tenant-bound agent quickstart plus receipt fetch/verify helpers. */
3
+ export class PaybondAgentFacade {
4
+ protocol;
5
+ invokeAgent;
6
+ constructor(protocol, invokeAgent) {
7
+ this.protocol = protocol;
8
+ this.invokeAgent = invokeAgent;
9
+ }
10
+ /** Fetch a signed `paybond.agent_receipt_v1` by receipt id or intent/tool-call lookup. */
11
+ async getReceipt(input) {
12
+ if ("receiptId" in input && input.receiptId?.trim()) {
13
+ return this.protocol.getAgentReceiptV1ByID(input.receiptId.trim());
14
+ }
15
+ if (input.intentId?.trim() && input.toolCallId?.trim()) {
16
+ return this.protocol.getAgentReceiptV1ByIntentToolCall({
17
+ intentId: input.intentId.trim(),
18
+ toolCallId: input.toolCallId.trim(),
19
+ });
20
+ }
21
+ throw new Error("getReceipt requires receiptId or intentId + toolCallId");
22
+ }
23
+ /** Verify a signed agent receipt via Gateway or locally with {@link verifyAgentReceiptV1}. */
24
+ async verifyReceipt(receipt, options) {
25
+ if (options?.offline) {
26
+ return verifyAgentReceiptV1(receipt);
27
+ }
28
+ return this.protocol.verifyAgentReceiptV1(receipt);
29
+ }
30
+ /** Opinionated quickstart: resolve policy presets and wire framework tools. */
31
+ async call(input) {
32
+ if (!this.invokeAgent) {
33
+ throw new Error("paybond.agent() requires a hosted Paybond session");
34
+ }
35
+ return this.invokeAgent(input);
36
+ }
37
+ }
38
+ /** Callable `paybond.agent({...})` surface with receipt helpers attached. */
39
+ export function createPaybondAgentCallable(protocol, invokeAgent) {
40
+ const facade = new PaybondAgentFacade(protocol, invokeAgent);
41
+ const callable = ((input) => facade.call(input));
42
+ callable.getReceipt = facade.getReceipt.bind(facade);
43
+ callable.verifyReceipt = facade.verifyReceipt.bind(facade);
44
+ return callable;
45
+ }
@@ -32,6 +32,7 @@ function normalizeSideEffecting(sideEffecting) {
32
32
  spendCents: policy.spendCents,
33
33
  evidencePreset,
34
34
  evidenceMapper: policy.evidenceMapper,
35
+ externalAttestationMapper: policy.externalAttestationMapper,
35
36
  });
36
37
  }
37
38
  return entries;
@@ -16,6 +16,8 @@ type SandboxGuardrailEvidenceResult = {
16
16
  intent_id: string;
17
17
  sandbox_lifecycle_status: string;
18
18
  predicate_passed?: boolean | null;
19
+ payload_digest?: string;
20
+ artifacts_digest?: string;
19
21
  };
20
22
  export type PaybondSubmitProductionEvidenceInput = {
21
23
  intentId: string;
package/dist/agent/run.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { PaybondToolInterceptor } from "./interceptor.js";
2
2
  import { PaybondAgentRunBindError, } from "./types.js";
3
+ import { configHashSha256Hex, promptHashSha256Hex } from "../agent-receipt.js";
3
4
  import { reloadPolicyOnRun, } from "../policy/reload.js";
4
5
  import { PaybondPolicyReloadController } from "../policy/watcher.js";
5
6
  import { resolveDevTraceSink } from "../dev/trace-buffer.js";
@@ -45,6 +46,55 @@ function normalizeProductionEvidence(raw, sandbox) {
45
46
  agentRecognitionSigningSeed: raw.agentRecognitionSigningSeed,
46
47
  };
47
48
  }
49
+ /** Strips the leading `sha256:` scheme from a policy snapshot digest, if present. */
50
+ function bareDigestHex(digest) {
51
+ if (!digest) {
52
+ return undefined;
53
+ }
54
+ const trimmed = digest.trim();
55
+ return trimmed.startsWith("sha256:") ? trimmed.slice("sha256:".length) : trimmed;
56
+ }
57
+ /**
58
+ * Resolves optional Agent Receipt Standard agent context at bind time: auto-computes
59
+ * `config_hash_hex` from {@link PaybondRunAgentContextInput.configHashMaterials} (per spec,
60
+ * `sha256(JCS({ system_prompt, tools_manifest, policy_snapshot_id }))`) and `prompt_hash_hex`
61
+ * from {@link PaybondRunAgentContextInput.normalizedUserPrompt} when precomputed hashes are not
62
+ * supplied directly. Raw prompt text is hashed here and discarded; only the digest is retained.
63
+ */
64
+ function resolveAgentContext(input, snapshot) {
65
+ if (!input) {
66
+ return undefined;
67
+ }
68
+ const modelFamily = input.modelFamily.trim();
69
+ if (!modelFamily) {
70
+ throw new PaybondAgentRunBindError("agentContext.modelFamily must be non-empty");
71
+ }
72
+ let configHashHex = input.configHashHex?.trim().toLowerCase();
73
+ if (!configHashHex && input.configHashMaterials) {
74
+ const policySnapshotId = input.configHashMaterials.policySnapshotId?.trim() || bareDigestHex(snapshot?.digest);
75
+ if (!policySnapshotId) {
76
+ throw new PaybondAgentRunBindError("agentContext.configHashMaterials.policySnapshotId is required when no policySnapshot is bound");
77
+ }
78
+ configHashHex = configHashSha256Hex({
79
+ system_prompt: input.configHashMaterials.systemPrompt,
80
+ tools_manifest: input.configHashMaterials.toolsManifest,
81
+ policy_snapshot_id: policySnapshotId,
82
+ });
83
+ }
84
+ let promptHashHex = input.promptHashHex?.trim().toLowerCase();
85
+ if (!promptHashHex && input.normalizedUserPrompt !== undefined) {
86
+ promptHashHex = promptHashSha256Hex(input.normalizedUserPrompt);
87
+ }
88
+ return {
89
+ modelFamily,
90
+ modelInstanceId: input.modelInstanceId?.trim() || undefined,
91
+ configHashHex,
92
+ promptHashHex,
93
+ principalDid: input.principalDid?.trim() || undefined,
94
+ operatorDid: input.operatorDid?.trim() || undefined,
95
+ policyTemplateId: input.policyTemplateId?.trim() || undefined,
96
+ };
97
+ }
48
98
  function assertExclusiveBindMode(input) {
49
99
  const hasBootstrap = input.bootstrap !== undefined;
50
100
  const hasAttach = input.attach !== undefined;
@@ -268,6 +318,7 @@ export class PaybondAgentRun {
268
318
  const registry = snapshot?.registry ?? input.registry;
269
319
  registry.validateForBind(allowedTools);
270
320
  const guard = paybond.spendGuard(intentId, capabilityToken);
321
+ const agentContext = resolveAgentContext(input.agentContext, snapshot);
271
322
  const binding = {
272
323
  runId,
273
324
  tenantId,
@@ -280,6 +331,7 @@ export class PaybondAgentRun {
280
331
  productionEvidence,
281
332
  policySnapshot: snapshot,
282
333
  onTrace: input.traceSink ?? input.onTrace ?? resolveDevTraceSink(),
334
+ agentContext,
283
335
  };
284
336
  const policyFilePath = input.policyFile?.trim();
285
337
  const run = new PaybondAgentRun(binding, paybond, snapshot, policyFilePath);
@@ -1,3 +1,4 @@
1
+ import type { AgentReceiptExternalAttestationV1 } from "../agent-receipt.js";
1
2
  /** Context passed to evidence mappers after a successful side-effecting tool call. */
2
3
  export type PaybondToolCallContext = {
3
4
  toolName: string;
@@ -9,6 +10,8 @@ export type PaybondToolCallContext = {
9
10
  export type PaybondSpendResolver<TArgs = unknown> = (args: TArgs) => number | undefined;
10
11
  /** Customize auto-evidence payload extraction from a tool result. */
11
12
  export type PaybondEvidenceMapper<TResult = unknown> = (result: TResult, ctx: PaybondToolCallContext) => Record<string, unknown>;
13
+ /** Optional partner attestation material for Agent Receipt `external_attestations`. */
14
+ export type PaybondExternalAttestationMapper<TResult = unknown> = (result: TResult, ctx: PaybondToolCallContext) => PaybondExternalAttestationInput | PaybondExternalAttestationInput[] | undefined;
12
15
  /** Policy for one registered side-effecting tool. */
13
16
  export type PaybondSideEffectingToolPolicy<TArgs = unknown, TResult = unknown> = {
14
17
  /** Harbor `allowed_tools` operation; defaults to the registry key (tool name). */
@@ -17,6 +20,7 @@ export type PaybondSideEffectingToolPolicy<TArgs = unknown, TResult = unknown> =
17
20
  /** Required completion catalog preset id for auto-evidence. */
18
21
  evidencePreset: string;
19
22
  evidenceMapper?: PaybondEvidenceMapper<TResult>;
23
+ externalAttestationMapper?: PaybondExternalAttestationMapper<TResult>;
20
24
  };
21
25
  export type PaybondToolRegistryConfig = {
22
26
  sideEffecting?: Record<string, PaybondSideEffectingToolPolicy>;
@@ -29,6 +33,7 @@ export type PaybondSideEffectingToolEntry = {
29
33
  spendCents?: number | PaybondSpendResolver;
30
34
  evidencePreset: string;
31
35
  evidenceMapper?: PaybondEvidenceMapper;
36
+ externalAttestationMapper?: PaybondExternalAttestationMapper;
32
37
  };
33
38
  export type PaybondToolResolution = {
34
39
  kind: "passthrough";
@@ -50,6 +55,8 @@ export declare class PaybondToolRegistryValidationError extends Error {
50
55
  import type { PaybondToolRegistry } from "./registry.js";
51
56
  import type { PaybondPolicySnapshot } from "../policy/snapshot.js";
52
57
  import type { PaybondPolicyReloadBindConfig } from "../policy/reload.js";
58
+ import type { AgentReceiptV1 } from "../agent-receipt.js";
59
+ import type { PaybondExternalAttestationInput } from "../agent-receipt-external-attestations.js";
53
60
  /** Spend authorization input forwarded to the run-bound guard. */
54
61
  export type PaybondRunGuardAuthInput = {
55
62
  operation: string;
@@ -63,6 +70,54 @@ export type PaybondRunGuardAuthInput = {
63
70
  agentSubject?: string;
64
71
  approvalToken?: string;
65
72
  idempotencyKey?: string;
73
+ /** Agent Receipt Standard context forwarded to Gateway `/verify` for audit correlation. */
74
+ modelFamily?: string;
75
+ configHashHex?: string;
76
+ promptHashHex?: string;
77
+ };
78
+ /**
79
+ * Materials to auto-compute `config_hash_hex` as `sha256(JCS({ system_prompt, tools_manifest,
80
+ * policy_snapshot_id }))` per the Agent Receipt Standard spec. `policySnapshotId` defaults to
81
+ * the bound policy snapshot digest (without the `sha256:` prefix) when omitted.
82
+ */
83
+ export type PaybondRunConfigHashMaterials = {
84
+ systemPrompt: string;
85
+ toolsManifest: unknown;
86
+ policySnapshotId?: string;
87
+ };
88
+ /**
89
+ * Optional agent identity/config context for {@link PaybondAgentRun.bind}. Threaded onto every
90
+ * spend verify call and used to compose the unsigned Agent Receipt Standard draft returned from
91
+ * {@link PaybondToolInterceptor.wrapExecute}. Raw prompts are hashed locally and never retained
92
+ * or transmitted; only `promptHashHex` is kept on the resolved binding.
93
+ */
94
+ export type PaybondRunAgentContextInput = {
95
+ modelFamily: string;
96
+ modelInstanceId?: string;
97
+ /** Precomputed sha256 hex digest; mutually exclusive with {@link configHashMaterials}. */
98
+ configHashHex?: string;
99
+ /** Auto-computed into `configHashHex` at bind time when `configHashHex` is omitted. */
100
+ configHashMaterials?: PaybondRunConfigHashMaterials;
101
+ /** Precomputed sha256 hex digest; mutually exclusive with {@link normalizedUserPrompt}. */
102
+ promptHashHex?: string;
103
+ /** Hashed locally at bind time into `promptHashHex`; never stored or transmitted raw. */
104
+ normalizedUserPrompt?: string;
105
+ /** Agent receipt `authorization.principal_did`; omitted from receipt drafts when unset. */
106
+ principalDid?: string;
107
+ /** Agent receipt `authorization.agent.operator_did`; omitted from receipt drafts when unset. */
108
+ operatorDid?: string;
109
+ /** Agent receipt `authorization.policy.template_id`; omitted from receipt drafts when unset. */
110
+ policyTemplateId?: string;
111
+ };
112
+ /** Resolved agent context stored on the run binding after bind-time hash computation. */
113
+ export type PaybondRunAgentContext = {
114
+ modelFamily: string;
115
+ modelInstanceId?: string;
116
+ configHashHex?: string;
117
+ promptHashHex?: string;
118
+ principalDid?: string;
119
+ operatorDid?: string;
120
+ policyTemplateId?: string;
66
121
  };
67
122
  /** Spend authorization result from Harbor verify. */
68
123
  export type PaybondRunGuardAuthResult = {
@@ -116,6 +171,10 @@ export type PaybondInterceptEvidenceResult = {
116
171
  predicatePassed?: boolean | null;
117
172
  sandboxLifecycleStatus?: string;
118
173
  intentState?: string;
174
+ /** sha256 hex digest of the submitted evidence payload, when returned by Harbor. */
175
+ payloadDigestSha256Hex?: string;
176
+ /** sha256 hex digest of submitted evidence artifacts, when returned by Harbor. */
177
+ artifactsDigestSha256Hex?: string;
119
178
  };
120
179
  export type PaybondInterceptWrapExecuteResult<TResult> = {
121
180
  toolResult: TResult;
@@ -126,6 +185,12 @@ export type PaybondInterceptWrapExecuteResult<TResult> = {
126
185
  policyDigest?: string;
127
186
  };
128
187
  evidence?: PaybondInterceptEvidenceResult;
188
+ /**
189
+ * Unsigned Agent Receipt Standard draft (Phase 1: composed locally, never signed or persisted).
190
+ * Omitted when required context (agentContext hashes, principal/operator DID, policy template,
191
+ * decision id) is unavailable — receipt composition is always best-effort and never throws.
192
+ */
193
+ receiptDraft?: AgentReceiptV1;
129
194
  };
130
195
  export type PaybondInterceptWrapExecuteInput<TResult> = {
131
196
  toolName: string;
@@ -241,6 +306,7 @@ export type PaybondTraceEvidenceSubmittedEvent = {
241
306
  evidencePreset?: string;
242
307
  sandboxLifecycleStatus?: string;
243
308
  predicatePassed?: boolean | null;
309
+ externalAttestations?: AgentReceiptExternalAttestationV1[];
244
310
  recordedAt: string;
245
311
  };
246
312
  export type PaybondTraceSpendFinalizedEvent = {
@@ -275,6 +341,8 @@ export type PaybondRunBinding = {
275
341
  policySnapshot?: PaybondPolicySnapshot;
276
342
  /** Optional trace sink for dev observability (see {@link PaybondAgentRunBindInput.traceSink}). */
277
343
  onTrace?: PaybondTraceSink;
344
+ /** Resolved Agent Receipt Standard context, when bound with {@link PaybondAgentRunBindInput.agentContext}. */
345
+ agentContext?: PaybondRunAgentContext;
278
346
  };
279
347
  export type PaybondAgentRunBindInput = {
280
348
  bootstrap?: PaybondRunBindingSandboxBootstrapInput;
@@ -295,6 +363,8 @@ export type PaybondAgentRunBindInput = {
295
363
  traceSink?: PaybondTraceSink;
296
364
  /** @deprecated Use {@link PaybondAgentRunBindInput.traceSink}. */
297
365
  onTrace?: PaybondTraceSink;
366
+ /** Optional Agent Receipt Standard agent identity/config context (see {@link PaybondRunAgentContextInput}). */
367
+ agentContext?: PaybondRunAgentContextInput;
298
368
  };
299
369
  export declare class PaybondAgentRunBindError extends Error {
300
370
  constructor(message: string);
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Maps partner attestation artifacts into Agent Receipt `external_attestations` entries.
3
+ *
4
+ * Partner digests are SHA-256 of canonical JSON (signature fields stripped for SEP-2828).
5
+ * These entries are never canonical inside Paybond; they provide interop hooks only.
6
+ */
7
+ import type { AgentReceiptExternalAttestationV1 } from "./agent-receipt.js";
8
+ export declare const AGENT_RECEIPT_EXTERNAL_SOURCE_SEP2828 = "sep2828_mcp";
9
+ export declare const AGENT_RECEIPT_EXTERNAL_SOURCE_X402 = "x402";
10
+ /** SHA-256 hex digest of canonical JSON bytes. */
11
+ export declare function partnerRecordDigestSha256Hex(record: Record<string, unknown>): string;
12
+ /**
13
+ * Converts verified SEP-2828 decision/outcome records into external attestation entries.
14
+ */
15
+ export declare function sep2828RecordsToExternalAttestations(decisionInput: Record<string, unknown>, outcomeInput: Record<string, unknown>): AgentReceiptExternalAttestationV1[];
16
+ /**
17
+ * Converts a verified x402 signed delivery receipt into one external attestation entry.
18
+ */
19
+ export declare function x402ReceiptToExternalAttestations(receiptInput: Record<string, unknown>): AgentReceiptExternalAttestationV1[];
20
+ export type PaybondExternalAttestationInput = {
21
+ kind: "sep2828";
22
+ decision: Record<string, unknown>;
23
+ outcome: Record<string, unknown>;
24
+ } | {
25
+ kind: "x402";
26
+ receipt: Record<string, unknown>;
27
+ } | AgentReceiptExternalAttestationV1;
28
+ /** Resolves pre-built or partner-native attestation inputs into normalized receipt entries. */
29
+ export declare function resolveExternalAttestations(inputs: readonly PaybondExternalAttestationInput[]): AgentReceiptExternalAttestationV1[];