@nevermined-io/payments 1.12.0 → 1.14.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 (98) hide show
  1. package/README.md +33 -0
  2. package/dist/a2a/clientRegistry.d.ts +10 -1
  3. package/dist/a2a/clientRegistry.d.ts.map +1 -1
  4. package/dist/a2a/clientRegistry.js +13 -4
  5. package/dist/a2a/clientRegistry.js.map +1 -1
  6. package/dist/a2a/paymentsClient.d.ts +60 -3
  7. package/dist/a2a/paymentsClient.d.ts.map +1 -1
  8. package/dist/a2a/paymentsClient.js +129 -8
  9. package/dist/a2a/paymentsClient.js.map +1 -1
  10. package/dist/a2a/paymentsRequestHandler.d.ts +5 -1
  11. package/dist/a2a/paymentsRequestHandler.d.ts.map +1 -1
  12. package/dist/a2a/paymentsRequestHandler.js +156 -13
  13. package/dist/a2a/paymentsRequestHandler.js.map +1 -1
  14. package/dist/a2a/types.d.ts +30 -0
  15. package/dist/a2a/types.d.ts.map +1 -1
  16. package/dist/a2a/types.js.map +1 -1
  17. package/dist/api/agents-api.d.ts +4 -3
  18. package/dist/api/agents-api.d.ts.map +1 -1
  19. package/dist/api/agents-api.js +7 -4
  20. package/dist/api/agents-api.js.map +1 -1
  21. package/dist/api/base-payments.d.ts +7 -2
  22. package/dist/api/base-payments.d.ts.map +1 -1
  23. package/dist/api/base-payments.js +15 -8
  24. package/dist/api/base-payments.js.map +1 -1
  25. package/dist/api/nvm-api.d.ts +5 -5
  26. package/dist/api/observability-api/types.d.ts +34 -6
  27. package/dist/api/observability-api/types.d.ts.map +1 -1
  28. package/dist/api/observability-api/types.js.map +1 -1
  29. package/dist/api/plans-api.d.ts +15 -12
  30. package/dist/api/plans-api.d.ts.map +1 -1
  31. package/dist/api/plans-api.js +17 -14
  32. package/dist/api/plans-api.js.map +1 -1
  33. package/dist/api/query-api.d.ts +1 -1
  34. package/dist/common/types.d.ts +175 -18
  35. package/dist/common/types.d.ts.map +1 -1
  36. package/dist/common/types.js.map +1 -1
  37. package/dist/index.d.ts +2 -1
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +1 -0
  40. package/dist/index.js.map +1 -1
  41. package/dist/mcp/core/paywall.d.ts.map +1 -1
  42. package/dist/mcp/core/paywall.js +69 -8
  43. package/dist/mcp/core/paywall.js.map +1 -1
  44. package/dist/mcp/http/index.d.ts +1 -1
  45. package/dist/mcp/http/index.d.ts.map +1 -1
  46. package/dist/mcp/http/index.js +1 -1
  47. package/dist/mcp/http/index.js.map +1 -1
  48. package/dist/mcp/http/oauth-metadata.d.ts +32 -0
  49. package/dist/mcp/http/oauth-metadata.d.ts.map +1 -1
  50. package/dist/mcp/http/oauth-metadata.js +329 -34
  51. package/dist/mcp/http/oauth-metadata.js.map +1 -1
  52. package/dist/mcp/index.d.ts +4 -4
  53. package/dist/mcp/index.d.ts.map +1 -1
  54. package/dist/mcp/index.js +5 -5
  55. package/dist/mcp/index.js.map +1 -1
  56. package/dist/mcp/types/http.types.d.ts +38 -3
  57. package/dist/mcp/types/http.types.d.ts.map +1 -1
  58. package/dist/mcp/types/http.types.js.map +1 -1
  59. package/dist/mcp/types/paywall.types.d.ts +19 -3
  60. package/dist/mcp/types/paywall.types.d.ts.map +1 -1
  61. package/dist/mcp/types/paywall.types.js.map +1 -1
  62. package/dist/mpp/fetch.d.ts +8 -3
  63. package/dist/mpp/fetch.d.ts.map +1 -1
  64. package/dist/mpp/fetch.js +6 -0
  65. package/dist/mpp/fetch.js.map +1 -1
  66. package/dist/mpp/mpp-api.d.ts +11 -5
  67. package/dist/mpp/mpp-api.d.ts.map +1 -1
  68. package/dist/mpp/mpp-api.js +10 -3
  69. package/dist/mpp/mpp-api.js.map +1 -1
  70. package/dist/payments.d.ts.map +1 -1
  71. package/dist/x402/delegation-api.d.ts +5 -17
  72. package/dist/x402/delegation-api.d.ts.map +1 -1
  73. package/dist/x402/delegation-api.js +2 -2
  74. package/dist/x402/delegation-api.js.map +1 -1
  75. package/dist/x402/express/middleware.d.ts.map +1 -1
  76. package/dist/x402/express/middleware.js +98 -1
  77. package/dist/x402/express/middleware.js.map +1 -1
  78. package/dist/x402/facilitator-api.d.ts +90 -7
  79. package/dist/x402/facilitator-api.d.ts.map +1 -1
  80. package/dist/x402/facilitator-api.js +64 -3
  81. package/dist/x402/facilitator-api.js.map +1 -1
  82. package/dist/x402/index.d.ts +3 -2
  83. package/dist/x402/index.d.ts.map +1 -1
  84. package/dist/x402/index.js +1 -0
  85. package/dist/x402/index.js.map +1 -1
  86. package/dist/x402/token-request.d.ts +8 -0
  87. package/dist/x402/token-request.d.ts.map +1 -1
  88. package/dist/x402/token-request.js +101 -1
  89. package/dist/x402/token-request.js.map +1 -1
  90. package/dist/x402/token-version.d.ts +97 -0
  91. package/dist/x402/token-version.d.ts.map +1 -0
  92. package/dist/x402/token-version.js +127 -0
  93. package/dist/x402/token-version.js.map +1 -0
  94. package/dist/x402/token.d.ts +33 -2
  95. package/dist/x402/token.d.ts.map +1 -1
  96. package/dist/x402/token.js +47 -2
  97. package/dist/x402/token.js.map +1 -1
  98. package/package.json +22 -13
@@ -1 +1 @@
1
- {"version":3,"file":"paymentsRequestHandler.js","sourceRoot":"","sources":["../../src/a2a/paymentsRequestHandler.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,QAAQ,EAER,qBAAqB,EAErB,mBAAmB,EACnB,aAAa,GACd,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAAqB,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAErE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EACL,oBAAoB,GAGrB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAU5C,MAAM,cAAc,GAAgB,CAAC,W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B,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;oBACnE,IAAI,WAAW,EAAE,CAAC;wBAChB,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,WAAW,CAAA;wBAC/C,IAAI,WAAW,IAAI,UAAU,EAAE,CAAC;4BAC9B,8DAA8D;4BAC9D,MAAM,IAAI,CAAC,sBAAsB,CAAC,aAAa,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,CAAC,CAAA;wBACnF,CAAC;oBACH,CAAC;gBACH,CAAC;gBAED,wDAAwD;gBACxD,IAAI,KAAK,CAAC,IAAI,KAAK,eAAe,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,EAAE,EAAE,CAAC;oBACjE,MAAM,KAAK,CAAA;gBACb,CAAC;qBAAM,IAAI,KAAK,CAAC,IAAI,KAAK,iBAAiB,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,EAAE,EAAE,CAAC;oBAC1E,MAAM,KAAK,CAAA;gBACb,CAAC;qBAAM,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,IAAI,KAAK,CAAC,EAAE,KAAK,MAAM,CAAC,EAAE,EAAE,CAAC;oBAC3D,MAAM,KAAK,CAAA;gBACb,CAAC;YACH,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,UAAU,CAAC,IAAI,EAAE,CAAA;QACnB,CAAC;IACH,CAAC;CACF","sourcesContent":["import type {\n AgentCard,\n Message,\n MessageSendParams,\n PushNotificationConfig,\n Task,\n TaskArtifactUpdateEvent,\n TaskIdParams,\n TaskState,\n TaskStatusUpdateEvent,\n} from '@a2a-js/sdk'\nimport type { ExecutionEventBusManager, TaskStore } from '@a2a-js/sdk/server'\nimport {\n A2AError,\n AgentExecutor,\n DefaultRequestHandler,\n ExecutionEventBus,\n ExecutionEventQueue,\n ResultManager,\n} from '@a2a-js/sdk/server'\nimport { v4 as uuidv4 } from 'uuid'\nimport { PaymentsError } from '../common/payments.error.js'\nimport { StartAgentRequest, isValidScheme } from '../common/types.js'\nimport { Payments } from '../payments.js'\nimport { decodeAccessToken } from '../utils.js'\nimport {\n buildPaymentRequired,\n type SettlePermissionsResult,\n type X402PaymentRequired,\n} from '../x402/facilitator-api.js'\nimport { x402A2AUtils } from './x402-a2a.js'\nimport type {\n A2AAuthResult,\n A2AStreamEvent,\n AgentRequestContext,\n HttpRequestContext,\n PaymentRedemptionConfig,\n PaymentsRequestContext,\n} from './types.js'\n\nconst terminalStates: TaskState[] = ['completed', 'failed', 'canceled', 'rejected']\n\n/**\n * Options for configuring the PaymentsRequestHandler\n */\nexport interface PaymentsRequestHandlerOptions {\n /** Whether to execute tasks asynchronously */\n asyncExecution?: boolean\n /** Default batch mode for all requests (can be overridden per-request) */\n defaultBatch?: boolean\n /** Default margin percentage for all requests (can be overridden per-request) */\n defaultMarginPercent?: number\n}\n\n/**\n * PaymentsRequestHandler extends DefaultRequestHandler to add payments validation and burning.\n * It validates credits before executing a task and burns credits after successful execution.\n * It also sends push notifications when a task reaches a terminal state.\n * @param options - Handler options, including asyncExecution, defaultBatch, and defaultMarginPercent\n */\nexport class PaymentsRequestHandler extends DefaultRequestHandler {\n private paymentsService: Payments\n private httpContextByTaskId: Map<string, HttpRequestContext> = new Map()\n private httpContextByMessageId: Map<string, HttpRequestContext> = new Map()\n private asyncExecution: boolean\n private defaultBatch: boolean\n private defaultMarginPercent?: number\n\n /**\n * Store HTTP context temporarily by messageId (used in middleware when taskId is not yet available).\n * @param messageId - The messageId from the incoming message\n * @param ctx - The HTTP context (bearerToken, url, method)\n */\n public setHttpRequestContextForMessage(messageId: string, ctx: HttpRequestContext) {\n this.httpContextByMessageId.set(messageId, ctx)\n }\n\n /**\n * Store HTTP context by taskId (used in middleware when taskId is available).\n * @param taskId - The taskId of the task\n * @param ctx - The HTTP context (bearerToken, url, method)\n */\n public setHttpRequestContextForTask(taskId: string, ctx: HttpRequestContext) {\n this.httpContextByTaskId.set(taskId, ctx)\n }\n\n /**\n * @param agentCard - The agent card\n * @param taskStore - The task store\n * @param agentExecutor - The business logic executor\n * @param paymentsService - The payments service for validation and burning\n * @param eventBusManager - The event bus manager (optional)\n * @param options - Handler options (asyncExecution, defaultBatch, defaultMarginPercent)\n */\n constructor(\n agentCard: AgentCard,\n taskStore: TaskStore,\n agentExecutor: AgentExecutor,\n paymentsService: any,\n eventBusManager?: ExecutionEventBusManager,\n options?: PaymentsRequestHandlerOptions,\n ) {\n super(agentCard, taskStore, agentExecutor, eventBusManager)\n this.paymentsService = paymentsService\n this.asyncExecution = options?.asyncExecution ?? false\n this.defaultBatch = options?.defaultBatch ?? false\n this.defaultMarginPercent = options?.defaultMarginPercent\n }\n\n /**\n * Retrieve the HTTP context for a given taskId.\n * @param taskId - The taskId of the task\n * @returns The HTTP context (bearerToken, url, method) or undefined\n */\n private getHttpRequestContextForTask(taskId: string): HttpRequestContext | undefined {\n return this.httpContextByTaskId.get(taskId)\n }\n\n /**\n * Retrieve the HTTP context for a given messageId.\n * @param messageId - The messageId of the message\n * @returns The HTTP context (bearerToken, url, method) or undefined\n */\n private getHttpRequestContextForMessage(messageId: string): HttpRequestContext | undefined {\n return this.httpContextByMessageId.get(messageId)\n }\n\n /**\n * Deletes the HTTP context associated with a taskId.\n * @param taskId - The taskId to delete context for\n */\n public deleteHttpRequestContextForTask(taskId: string): void {\n this.httpContextByTaskId.delete(taskId)\n }\n\n /**\n * Get the handler options (defaultBatch, defaultMarginPercent).\n * Used by middleware to determine default redemption behavior.\n * @returns The handler options\n */\n public getHandlerOptions(): PaymentsRequestHandlerOptions {\n return {\n asyncExecution: this.asyncExecution,\n defaultBatch: this.defaultBatch,\n defaultMarginPercent: this.defaultMarginPercent,\n }\n }\n\n /**\n * Validates a request using the x402 payments service.\n * This method is used by the middleware to validate credits before processing requests.\n *\n * @param bearerToken - The bearer token for authentication\n * @param endpoint - Optional endpoint URL being requested\n * @param httpVerb - Optional HTTP method being used\n * @returns Promise resolving to the validation result\n */\n public async validateRequest(\n bearerToken: string,\n endpoint?: string,\n httpVerb?: string,\n ): Promise<any> {\n let planId: string | undefined\n const agentCard = await this.getAgentCard()\n const paymentExtension = agentCard.capabilities?.extensions?.find(\n (ext: any) => ext.uri === 'urn:nevermined:payment',\n )\n if (paymentExtension) {\n planId = paymentExtension.params?.planId as string\n }\n\n const decodedAccessToken = decodeAccessToken(bearerToken)\n\n if (!decodedAccessToken) {\n throw PaymentsError.unauthorized('Invalid access token.')\n }\n\n if (!planId) {\n throw PaymentsError.unauthorized('Plan ID not found in agent card.')\n }\n\n // Extract subscriberAddress from token (payload.authorization.from per x402 spec)\n const subscriberAddress = decodedAccessToken.payload?.authorization?.from\n\n if (!subscriberAddress) {\n throw PaymentsError.unauthorized(\n 'Cannot determine subscriberAddress from token (expected payload.authorization.from)',\n )\n }\n\n const agentId = paymentExtension?.params?.agentId as string | undefined\n const scheme = isValidScheme(decodedAccessToken.accepted?.scheme)\n ? decodedAccessToken.accepted.scheme\n : 'nvm:erc4337'\n\n const paymentRequired: X402PaymentRequired = buildPaymentRequired(planId, {\n endpoint: endpoint || '',\n agentId,\n httpVerb,\n scheme,\n environment: this.paymentsService.getEnvironmentName(),\n })\n\n const result = await this.paymentsService.facilitator.verifyPermissions({\n paymentRequired,\n x402AccessToken: bearerToken,\n maxAmount: 1n,\n })\n if (!result.isValid) {\n throw PaymentsError.unauthorized('Permission verification failed.')\n }\n return {\n success: true,\n planId,\n subscriberAddress,\n balance: { isSubscriber: true },\n }\n }\n\n /**\n * Gets redemption configuration for a task based on AgentCard and handler defaults.\n * The configuration is determined by the server, not by client metadata.\n *\n * @returns The redemption configuration\n */\n private async getRedemptionConfig(): Promise<PaymentRedemptionConfig> {\n const agentCard = await this.getAgentCard()\n const paymentExtension = agentCard.capabilities?.extensions?.find(\n (ext: any) => ext.uri === 'urn:nevermined:payment',\n )\n\n const agentConfig =\n (paymentExtension?.params?.redemptionConfig as PaymentRedemptionConfig) || {}\n\n return {\n useBatch: agentConfig.useBatch ?? this.defaultBatch ?? false,\n useMargin: agentConfig.useMargin ?? false,\n marginPercent: agentConfig.marginPercent ?? this.defaultMarginPercent,\n }\n }\n\n /**\n * Determines the appropriate redemption method based on server configuration.\n *\n * @param bearerToken - The bearer token for authentication\n * @param creditsUsed - The number of credits to burn\n * @param httpContext - Optional HTTP context with endpoint and method information\n * @returns Promise resolving to the redemption result\n */\n private async executeRedemption(\n bearerToken: string,\n creditsUsed: bigint | number,\n httpContext?: HttpRequestContext,\n ): Promise<any> {\n const decodedAccessToken = decodeAccessToken(bearerToken)\n if (!decodedAccessToken) {\n throw PaymentsError.unauthorized('Invalid access token.')\n }\n\n let planId: string | undefined\n let agentId: string | undefined\n const agentCard = await this.getAgentCard()\n const paymentExtension = agentCard.capabilities?.extensions?.find(\n (ext: any) => ext.uri === 'urn:nevermined:payment',\n )\n if (paymentExtension) {\n planId = paymentExtension.params?.planId as string | undefined\n agentId = paymentExtension.params?.agentId as string | undefined\n }\n\n if (!planId) {\n throw PaymentsError.unauthorized('Plan ID not found in agent card.')\n }\n\n const scheme = isValidScheme(decodedAccessToken.accepted?.scheme)\n ? decodedAccessToken.accepted.scheme\n : 'nvm:erc4337'\n\n // Build paymentRequired using the helper\n const paymentRequired = buildPaymentRequired(planId, {\n endpoint: httpContext?.urlRequested,\n agentId,\n httpVerb: httpContext?.httpMethodRequested,\n scheme,\n environment: this.paymentsService.getEnvironmentName(),\n })\n\n return await this.paymentsService.facilitator.settlePermissions({\n paymentRequired,\n x402AccessToken: bearerToken,\n maxAmount: BigInt(creditsUsed),\n })\n }\n\n /**\n * Creates PaymentsRequestContext from message parameters.\n * This method handles HTTP context retrieval, validation, and context creation.\n * @param params - Message send parameters\n * @param isStreaming - Whether this is for streaming (affects createRequestContext call)\n * @returns Object containing PaymentsRequestContext and related data\n */\n private async createPaymentsRequestContext(\n params: MessageSendParams,\n isStreaming = false,\n ): Promise<{\n paymentsRequestContext: PaymentsRequestContext\n taskId: string\n httpContext: HttpRequestContext\n bearerToken: string\n validation: StartAgentRequest\n requestContext: any\n finalMessageForAgent: Message\n eventBus: ExecutionEventBus\n eventQueue: ExecutionEventQueue\n resultManager: ResultManager\n }> {\n // Validate required parameters before any processing\n const missingParam = !params.message\n ? 'message'\n : !params.message.messageId\n ? 'message.messageId'\n : null\n if (missingParam) {\n throw A2AError.invalidParams(`${missingParam} is required.`)\n }\n\n // 1. Get HTTP context for the task or message\n let taskId = params.message.taskId\n let httpContext: HttpRequestContext | undefined\n if (taskId) {\n httpContext = this.getHttpRequestContextForTask(taskId)\n } else {\n const messageId = params.message.messageId\n httpContext = this.getHttpRequestContextForMessage(messageId)\n }\n\n if (!httpContext) {\n throw A2AError.internalError('HTTP context not found for task or message.')\n }\n\n // 2. Extract bearer token and validate presence of required fields.\n // This path only runs for an *authorized* context (a token was supplied), so\n // both bearerToken and validation must be present — assert the invariant\n // explicitly instead of carrying an `undefined as any`.\n const { bearerToken, validation } = httpContext\n if (!bearerToken) {\n throw PaymentsError.unauthorized('Missing bearer token for payment validation.')\n }\n if (!validation) {\n throw PaymentsError.unauthorized('Missing validation context for payment.')\n }\n\n // 3. Validate credits before executing the task\n const agentCard = await this.getAgentCard()\n const agentId = agentCard.capabilities?.extensions?.find(\n (ext) => ext.uri === 'urn:nevermined:payment',\n )?.params?.agentId\n if (!agentId) {\n throw A2AError.internalError('Agent ID not found in payment extension.')\n }\n\n // 4. Generate taskId if not present and migrate HTTP context\n const incomingMessage = params.message\n if (!taskId) {\n taskId = uuidv4()\n this.migrateHttpRequestContextFromMessageToTask(params.message.messageId, taskId)\n }\n\n // 5. Instantiate ResultManager and eventBus\n const resultManager = new ResultManager(this.getTaskStore())\n resultManager.setContext(incomingMessage)\n const requestContext = await this.callCreateRequestContext(incomingMessage, taskId, isStreaming)\n const finalMessageForAgent = requestContext.userMessage\n const eventBus = this.getEventBusManager().createOrGetByTaskId(taskId)\n const eventQueue = new ExecutionEventQueue(eventBus)\n\n // 6. Create PaymentsRequestContext\n const authResult: A2AAuthResult = {\n requestId: validation.agentRequestId,\n token: bearerToken,\n agentId: validation.agentId,\n agentRequest: validation,\n }\n\n const agentRequestContext: AgentRequestContext = {\n authResult,\n httpContext,\n paymentsService: this.paymentsService,\n }\n\n // 7. Create extended request context with agent request data\n const paymentsRequestContext: PaymentsRequestContext = {\n ...requestContext,\n payments: agentRequestContext,\n }\n\n return {\n paymentsRequestContext,\n taskId,\n httpContext,\n bearerToken,\n validation,\n requestContext,\n finalMessageForAgent,\n eventBus,\n eventQueue,\n resultManager,\n }\n }\n\n /**\n * x402 v2 A2A transport: if the request is payment-gated and arrived with no\n * token (the middleware stored a `paymentRequired` on the HTTP context), build\n * and return the spec-shaped `input-required` task carrying the\n * X402PaymentRequired object under `x402.payment.required` — WITHOUT executing\n * the agent. Returns `undefined` when a token was present (normal flow).\n *\n * @param params - The incoming message send parameters\n * @returns The `input-required` Task to return to the client, or `undefined`\n */\n private async buildPaymentRequiredTaskIfNeeded(\n params: MessageSendParams,\n ): Promise<Task | undefined> {\n const message = params.message\n if (!message) {\n return undefined\n }\n const incomingTaskId = message.taskId\n const httpContext = incomingTaskId\n ? this.getHttpRequestContextForTask(incomingTaskId)\n : this.getHttpRequestContextForMessage(message.messageId)\n\n if (!httpContext?.paymentRequired) {\n return undefined\n }\n\n // Correlate the input-required task with the incoming taskId when present so\n // the client's follow-up payment payload (same taskId) maps back to it.\n const taskId = incomingTaskId || uuidv4()\n const contextId = message.contextId || uuidv4()\n const task: Task = {\n kind: 'task',\n id: taskId,\n contextId,\n status: { state: 'submitted', timestamp: new Date().toISOString() },\n history: [message],\n }\n const paymentRequiredTask = x402A2AUtils.createPaymentRequiredTask(\n task,\n httpContext.paymentRequired,\n )\n\n // Persist the input-required task so the client's follow-up (same taskId)\n // can correlate to it (otherwise the SDK's _createRequestContext raises\n // \"Task not found\"). The follow-up carries the in-band payload, so the\n // middleware overwrites this taskId's HTTP context with the authorized one.\n await this.getTaskStore().save(paymentRequiredTask)\n if (!incomingTaskId) {\n this.deleteHttpRequestContextForMessage(message.messageId)\n }\n return paymentRequiredTask\n }\n\n /**\n * Stamp x402 settlement state onto the final task's metadata, in band, per the\n * x402 v2 A2A transport. Only applied when the token arrived in band (so the\n * legacy `payment-signature` header path is unchanged). On success the task\n * carries `x402.payment.status: payment-completed` + `x402.payment.receipts`;\n * on failure `payment-failed` + `x402.payment.error` + receipts.\n *\n * @param task - The current task (mutated in place)\n * @param httpContext - The request's HTTP context\n * @param settlement - The settlement result, or undefined when none ran\n */\n private recordInBandSettlement(\n task: Task | undefined,\n httpContext: HttpRequestContext | undefined,\n settlement?: SettlePermissionsResult,\n settlementDeferred = false,\n ): void {\n if (!task || !httpContext?.inBand) {\n return\n }\n if (settlement && settlement.success === false) {\n x402A2AUtils.recordPaymentFailure(\n task,\n settlement.errorReason || 'SETTLEMENT_FAILED',\n settlement,\n )\n } else if (settlement) {\n x402A2AUtils.recordPaymentSuccess(task, settlement)\n } else if (settlementDeferred) {\n // No in-band settlement result because redemption is BATCHED: the payload was\n // verified but on-chain settlement is deferred out-of-band (this handler never\n // confirms it). Mark payment-verified + the deferred marker, NOT\n // payment-completed — so the client knows it will be charged out-of-band\n // rather than reading a completed task as \"nothing owed\".\n x402A2AUtils.recordPaymentDeferred(task)\n } else {\n // Defensive default: verified, but no settlement result AND not batch-deferred\n // (e.g. a settle that returned nothing). Record a bare verify.\n x402A2AUtils.recordPaymentVerified(task)\n }\n }\n\n /**\n * Processes streaming events with finalization (credits burning and push notifications).\n * Similar to processEventsWithFinalization but yields events for streaming.\n * @param taskId - The task ID\n * @param resultManager - The result manager\n * @param eventQueue - The event queue\n * @param bearerToken - The bearer token\n * @param validation - The validation result\n * @returns Async generator yielding processed events\n */\n protected async *processStreamingEventsWithFinalization(\n taskId: string,\n resultManager: ResultManager,\n eventQueue: ExecutionEventQueue,\n bearerToken: string,\n requestHttpContext?: HttpRequestContext,\n ): AsyncGenerator<A2AStreamEvent, void, undefined> {\n try {\n for await (const event of eventQueue.events()) {\n await resultManager.processEvent(event)\n yield event\n\n if (\n event.kind === 'status-update' &&\n event.final &&\n event?.metadata?.creditsUsed !== undefined &&\n event?.metadata?.creditsUsed !== null &&\n bearerToken &&\n (typeof event.metadata.creditsUsed === 'string' ||\n typeof event.metadata.creditsUsed === 'number' ||\n typeof event.metadata.creditsUsed === 'bigint')\n ) {\n try {\n // Get redemption configuration from server (not from client metadata)\n const redemptionConfig = await this.getRedemptionConfig()\n\n if (!redemptionConfig.useBatch) {\n // Prefer the per-request context (authoritative in-band flag); fall\n // back to a per-taskId lookup for executors that mint their own task id.\n const httpContext =\n requestHttpContext ?? this.getHttpRequestContextForTask(event.taskId)\n // Execute redemption with server configuration for non-batch requests\n const response = await this.executeRedemption(\n bearerToken,\n BigInt(event.metadata.creditsUsed),\n httpContext,\n )\n\n // Update event metadata with response data\n if (response && event.metadata) {\n event.metadata.txHash = response.txHash ?? response.transaction\n event.metadata.creditsCharged = response.amountOfCredits\n ? Number(response.amountOfCredits)\n : event.metadata.creditsUsed\n }\n\n // x402 v2 A2A transport: stamp the settlement receipt onto the\n // persisted task in band. NOTE: a stream cannot retract the event\n // it already yielded above, so an in-band settlement is reflected\n // on the saved task (visible via tasks/get + resubscribe) — it\n // cannot withhold content the way a non-streaming result does.\n if (httpContext?.inBand) {\n const task = resultManager.getCurrentTask()\n if (task) {\n this.recordInBandSettlement(\n task,\n httpContext,\n response as SettlePermissionsResult,\n )\n await resultManager.processEvent(task)\n }\n }\n } else {\n // Batch redemption: on-chain settlement is deferred out-of-band. The\n // stream already yielded the content (can't retract), but stamp the\n // PERSISTED task with payment-verified + the deferred marker so a\n // streaming client (via tasks/get + resubscribe) isn't left reading a\n // completed task as \"nothing owed\" — matching the non-streaming path.\n const httpContext =\n requestHttpContext ?? this.getHttpRequestContextForTask(event.taskId)\n if (httpContext?.inBand) {\n const task = resultManager.getCurrentTask()\n if (task) {\n this.recordInBandSettlement(task, httpContext, undefined, true)\n await resultManager.processEvent(task)\n }\n }\n }\n } catch (err) {\n // x402 v2 A2A: settlement failed AFTER the paid event was already\n // streamed to the client (a stream cannot retract it). Do NOT swallow\n // it — log, and stamp payment-failed on the persisted task so\n // tasks/get + resubscribe reflect the failure (mirrors non-streaming).\n console.error('[PaymentsA2A] streaming settlement failed after execution:', err)\n const httpContext =\n requestHttpContext ?? this.getHttpRequestContextForTask(event.taskId)\n if (httpContext?.inBand) {\n try {\n const task = resultManager.getCurrentTask()\n if (task) {\n const errorReason = err instanceof Error ? err.message : String(err)\n if (task.status) task.status.state = 'failed'\n task.artifacts = undefined\n this.recordInBandSettlement(task, httpContext, {\n success: false,\n errorReason,\n transaction: '',\n network: '',\n })\n await resultManager.processEvent(task)\n }\n } catch (stampErr) {\n console.error('[PaymentsA2A] failed to stamp streaming payment-failed:', stampErr)\n }\n }\n }\n }\n\n // Handle push notification\n if (\n event.kind === 'status-update' &&\n event.final &&\n event.status?.state &&\n terminalStates.includes(event.status.state)\n ) {\n try {\n const taskPushNotificationConfig = await this.getTaskPushNotificationConfig({\n id: event.taskId,\n })\n if (taskPushNotificationConfig) {\n await this.sendPushNotification(\n event.taskId,\n event.status.state,\n taskPushNotificationConfig.pushNotificationConfig,\n {\n contextId: event.contextId,\n },\n )\n }\n } catch (err) {\n // Do nothing\n }\n }\n }\n } finally {\n // Cleanup when the stream is fully consumed or breaks\n //this.getEventBusManager().cleanupByTaskId(taskId)\n }\n }\n\n /**\n * Processes all events, calling handleTaskFinalization when a terminal status-update event is received.\n * In async mode, it can be launched in background.\n */\n protected async processEventsWithFinalization(\n taskId: string,\n resultManager: ResultManager,\n eventQueue: ExecutionEventQueue,\n bearerToken: string,\n validation: StartAgentRequest,\n options?: {\n firstResultResolver?: (event: any) => void\n firstResultRejector?: (err: any) => void\n },\n requestHttpContext?: HttpRequestContext,\n ) {\n let firstResultSent = false\n try {\n for await (const event of eventQueue.events()) {\n // Handle redemption before processing the event\n if (\n event.kind === 'status-update' &&\n event.final &&\n terminalStates.includes(event.status?.state)\n ) {\n // Prefer the per-request HTTP context (authoritative for this request,\n // carries the in-band flag). Fall back to a per-taskId lookup for\n // executors that mint their own task id (the event's taskId may then\n // differ from the request's generated one).\n const httpContext = requestHttpContext ?? this.getHttpRequestContextForTask(event.taskId)\n await this.handleTaskFinalization(resultManager, event, bearerToken, httpContext)\n }\n\n await resultManager.processEvent(event)\n if (options?.firstResultResolver && !firstResultSent) {\n if (event.kind === 'message' || event.kind === 'task') {\n options.firstResultResolver(event)\n firstResultSent = true\n }\n }\n }\n if (options?.firstResultRejector && !firstResultSent) {\n options.firstResultRejector(\n A2AError.internalError('Execution finished before a message or task was produced.'),\n )\n }\n } catch (error) {\n if (options?.firstResultRejector && !firstResultSent) {\n options.firstResultRejector(error)\n }\n throw error\n } finally {\n this.getEventBusManager().cleanupByTaskId(taskId)\n }\n }\n\n /**\n * Sends a message, validating credits before execution and burning credits after.\n * Also sends a push notification if the task reaches a terminal state.\n * This method overrides the parent implementation to allow eventBus subscription before agent execution.\n * @param params - Message send parameters\n * @returns The resulting message or task\n */\n async sendMessage(params: MessageSendParams): Promise<Message | Task> {\n // x402 v2 A2A transport: a payment-gated request with no token returns an\n // `input-required` task (in band) instead of executing the agent.\n const paymentRequiredTask = await this.buildPaymentRequiredTaskIfNeeded(params)\n if (paymentRequiredTask) {\n return paymentRequiredTask\n }\n\n // Create PaymentsRequestContext and related data\n const {\n paymentsRequestContext,\n taskId,\n httpContext,\n bearerToken,\n validation,\n requestContext,\n finalMessageForAgent,\n eventBus,\n eventQueue,\n resultManager,\n } = await this.createPaymentsRequestContext(params, false)\n\n // Execute agent with extended context\n ;(this as any).agentExecutor\n .execute(paymentsRequestContext as any, eventBus)\n .catch((err: any) => {\n const errorTask: Task = {\n id: requestContext.task?.id || uuidv4(),\n contextId: finalMessageForAgent.contextId || uuidv4(),\n status: {\n state: 'failed',\n message: {\n kind: 'message',\n role: 'agent',\n messageId: uuidv4(),\n parts: [{ kind: 'text', text: `Agent execution error: ${err.message}` }],\n taskId: requestContext.task?.id,\n contextId: finalMessageForAgent.contextId,\n },\n timestamp: new Date().toISOString(),\n },\n history: requestContext.task?.history ? [...requestContext.task.history] : [],\n kind: 'task',\n }\n if (finalMessageForAgent) {\n if (\n !errorTask.history?.find((m: any) => m.messageId === finalMessageForAgent.messageId)\n ) {\n errorTask.history?.push(finalMessageForAgent)\n }\n }\n eventBus.publish(errorTask)\n eventBus.publish({\n kind: 'status-update',\n taskId: errorTask.id,\n contextId: errorTask.contextId,\n status: errorTask.status,\n final: true,\n })\n eventBus.finished()\n })\n\n // Determine if execution should be blocking based on client request\n // The blocking parameter comes from params.configuration.blocking\n const isBlocking = params.configuration?.blocking !== false // Default to blocking if not specified\n\n if (isBlocking) {\n await this.processEventsWithFinalization(\n taskId,\n resultManager,\n eventQueue,\n bearerToken,\n validation,\n undefined,\n httpContext,\n )\n const finalResult = resultManager.getFinalResult()\n if (!finalResult) {\n throw A2AError.internalError(\n 'Agent execution finished without a result, and no task context found.',\n )\n }\n return finalResult\n } else {\n // Non-blocking execution - return immediately with first result\n if (!taskId) {\n throw A2AError.internalError('Task ID is required for non-blocking execution.')\n }\n const validTaskId = taskId\n return new Promise((resolve, reject) => {\n this.processEventsWithFinalization(\n validTaskId,\n resultManager,\n eventQueue,\n bearerToken,\n validation,\n {\n firstResultResolver: resolve,\n firstResultRejector: reject,\n },\n httpContext,\n )\n })\n }\n }\n\n /**\n * Handles credits burning and push notification when a task reaches a terminal state.\n * This is called asynchronously from the eventBus listener.\n * Supports batch and margin-based redemptions based on server configuration.\n * @param resultManager - The result manager\n * @param event - The status-update event with final state\n * @param bearerToken - The bearer token for payment validation\n * @param validation - The validation result from the request\n */\n private async handleTaskFinalization(\n resultManager: ResultManager,\n event: TaskStatusUpdateEvent,\n bearerToken: string,\n httpContext?: HttpRequestContext,\n ) {\n const creditsToBurn = event.metadata?.creditsUsed\n if (\n creditsToBurn !== undefined &&\n creditsToBurn !== null &&\n bearerToken &&\n (typeof creditsToBurn === 'string' ||\n typeof creditsToBurn === 'number' ||\n typeof creditsToBurn === 'bigint')\n ) {\n let settlement: SettlePermissionsResult | undefined\n let settlementError: unknown\n let settlementDeferred = false\n try {\n // Get redemption configuration from server (not from client metadata)\n const redemptionConfig = await this.getRedemptionConfig()\n // Batch redemption defers on-chain settlement out-of-band (no receipt here).\n settlementDeferred = redemptionConfig.useBatch ?? false\n\n if (!redemptionConfig.useBatch) {\n // Execute redemption with server configuration for non-batch requests\n const response = await this.executeRedemption(\n bearerToken,\n BigInt(creditsToBurn),\n httpContext,\n )\n settlement = response as SettlePermissionsResult\n\n // Update event metadata with redemption results\n event.metadata = {\n ...event.metadata,\n txHash: response.txHash ?? response.transaction,\n // Store the actual credits charged (especially important for margin-based)\n creditsCharged: response.amountOfCredits\n ? Number(response.amountOfCredits)\n : creditsToBurn,\n }\n }\n } catch (err) {\n // Settlement failed AFTER the agent executed. Always log it (the legacy\n // header path has no other surface for it). For the in-band x402 v2 A2A\n // path it is additionally surfaced below as payment-failed + suppressed\n // content; the legacy header path still delivers the result (no retract).\n console.error('[PaymentsA2A] settlement failed after execution:', err)\n settlementError = err\n }\n\n // Stamp the in-band x402 state onto the FINAL event so it survives when the\n // caller processes this event into the task's status (mutating the task\n // here would be overwritten by the final event). The event carries a Task\n // shape under `event.status`; the helpers mutate `event.status.message`.\n if (httpContext?.inBand && settlementError) {\n // x402 v2 A2A transport: a settlement failure after execution must NOT\n // deliver paid content — replace the agent's status message with a\n // failed one carrying payment-failed metadata + an error receipt.\n const errorReason =\n settlementError instanceof Error ? settlementError.message : String(settlementError)\n event.status = {\n state: 'failed',\n message: {\n kind: 'message',\n messageId: uuidv4(),\n role: 'agent',\n parts: [{ kind: 'text', text: `Payment settlement failed: ${errorReason}` }],\n taskId: event.taskId,\n contextId: event.contextId,\n metadata: {},\n },\n timestamp: new Date().toISOString(),\n }\n this.recordInBandSettlement({ status: event.status } as any, httpContext, {\n success: false,\n errorReason,\n transaction: '',\n network: settlement?.network || '',\n })\n } else if (httpContext?.inBand) {\n // Stamp in-band settlement state onto the final event's status message.\n this.recordInBandSettlement(\n { status: event.status } as any,\n httpContext,\n settlement,\n settlementDeferred,\n )\n }\n\n try {\n // Always update task metadata and process the task\n const task = resultManager.getCurrentTask()\n if (task) {\n // Update task metadata with current event metadata (executor / redemption).\n task.metadata = {\n ...task.metadata,\n ...event.metadata,\n }\n\n if (httpContext?.inBand && settlementError) {\n // x402 v2 A2A transport: a settlement failure must never deliver paid\n // content. The agent's status message was already replaced above; also\n // drop any artifacts it emitted so the paid result cannot surface there\n // (mirrors the Python SDK's _apply_inband_settlement). History is rebuilt\n // by processEvent below from the replaced (failed) status, so it carries\n // no paid content.\n task.artifacts = undefined\n }\n\n await resultManager.processEvent(task)\n // Delete http context associated with the task\n this.deleteHttpRequestContextForTask(event.taskId)\n }\n } catch (err) {\n // This block persists the payment-failed/suppressed task; if it throws the\n // suppression itself failed, so log loudly rather than swallow.\n console.error('[PaymentsA2A] failed to persist finalized task:', err)\n }\n }\n try {\n const taskPushNotificationConfig = await this.getTaskPushNotificationConfig({\n id: event.taskId,\n })\n if (taskPushNotificationConfig) {\n await this.sendPushNotification(\n event.taskId,\n event.status.state,\n taskPushNotificationConfig.pushNotificationConfig,\n { contextId: event.contextId },\n )\n }\n } catch (err) {\n // Do nothing\n }\n }\n\n /**\n * Streams messages and events for a task, with payments validation.\n * Also sends a push notification if a terminal status-update event is emitted.\n * @param params - Message send parameters\n * @returns Async generator of events\n */\n async *sendMessageStream(\n params: MessageSendParams,\n ): AsyncGenerator<A2AStreamEvent, void, undefined> {\n // x402 v2 A2A transport: a payment-gated request with no token yields a\n // single `input-required` task (in band) instead of executing the agent.\n const paymentRequiredTask = await this.buildPaymentRequiredTaskIfNeeded(params)\n if (paymentRequiredTask) {\n yield paymentRequiredTask\n return\n }\n\n // Create PaymentsRequestContext and related data\n const {\n paymentsRequestContext,\n taskId,\n httpContext,\n bearerToken,\n requestContext,\n finalMessageForAgent,\n eventBus,\n eventQueue,\n resultManager,\n } = await this.createPaymentsRequestContext(params, true)\n\n // Execute agent with extended context\n ;(this as any).agentExecutor\n .execute(paymentsRequestContext as any, eventBus)\n .catch((err: any) => {\n console.error(\n `Agent execution failed for stream message ${finalMessageForAgent.messageId}:`,\n err,\n )\n const contextId = finalMessageForAgent.contextId || uuidv4()\n const errorTaskStatus: TaskStatusUpdateEvent = {\n kind: 'status-update',\n taskId: requestContext.task?.id || uuidv4(),\n contextId,\n status: {\n state: 'failed',\n message: {\n kind: 'message',\n role: 'agent',\n messageId: uuidv4(),\n parts: [{ kind: 'text', text: `Agent execution error: ${err.message}` }],\n taskId: requestContext.task?.id,\n contextId,\n },\n timestamp: new Date().toISOString(),\n },\n final: true,\n }\n eventBus.publish(errorTaskStatus)\n })\n\n // Process streaming events with finalization\n yield* this.processStreamingEventsWithFinalization(\n taskId,\n resultManager,\n eventQueue,\n bearerToken,\n httpContext,\n )\n }\n\n /**\n * Sends a push notification when a task reaches a terminal state.\n * @param taskId - The task ID\n * @param state - The terminal state\n * @param pushNotificationConfig - The push notification configuration\n * @param payload - Additional payload to include in the notification\n */\n private async sendPushNotification(\n taskId: string,\n state: TaskState,\n pushNotificationConfig: PushNotificationConfig,\n payload: Record<string, any> = {},\n ) {\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n }\n if (pushNotificationConfig.authentication) {\n if (pushNotificationConfig.authentication.schemes.includes('basic')) {\n const basic = Buffer.from(`${pushNotificationConfig.authentication.credentials}`).toString(\n 'base64',\n )\n headers['Authorization'] = `Basic ${basic}`\n } else if (pushNotificationConfig.authentication.schemes.includes('bearer')) {\n headers['Authorization'] = `Bearer ${pushNotificationConfig.authentication.credentials}`\n } else if (pushNotificationConfig.authentication.schemes.includes('custom')) {\n Object.assign(headers, pushNotificationConfig.authentication.credentials)\n }\n }\n const body = JSON.stringify({\n taskId,\n state,\n payload,\n })\n const response = await fetch(pushNotificationConfig.url, {\n method: 'POST',\n headers,\n body,\n })\n if (!response.ok) {\n throw A2AError.internalError('Failed to send push notification.')\n }\n }\n\n /**\n * Migrates the HTTP context from a messageId to a taskId and deletes the temporary messageId context.\n * @param messageId - The messageId to migrate from\n * @param taskId - The taskId to migrate to\n */\n public migrateHttpRequestContextFromMessageToTask(messageId: string, taskId: string): void {\n const ctx = this.getHttpRequestContextForMessage(messageId)\n if (ctx) {\n this.setHttpRequestContextForTask(taskId, ctx)\n this.deleteHttpRequestContextForMessage(messageId)\n }\n }\n\n /**\n * Deletes the HTTP context associated with a messageId.\n * @param messageId - The messageId to delete context for\n */\n public deleteHttpRequestContextForMessage(messageId: string): void {\n this.httpContextByMessageId.delete(messageId)\n }\n\n /**\n * Protected getter to access the private taskStore property from the parent class.\n * This is a workaround due to SDK limitations.\n */\n protected getTaskStore(): TaskStore {\n return (this as any).taskStore as TaskStore\n }\n\n /**\n * Protected getter to access the private eventBusManager property from the parent class.\n * This is a workaround due to SDK limitations.\n */\n protected getEventBusManager(): ExecutionEventBusManager {\n return (this as any).eventBusManager as ExecutionEventBusManager\n }\n\n /**\n * Protected getter to access the private _createRequestContext method from the parent class.\n * This is a workaround due to SDK limitations.\n */\n protected async callCreateRequestContext(\n incomingMessage: any,\n taskId: string,\n isStream: boolean,\n ): Promise<any> {\n return await (this as any)._createRequestContext(incomingMessage, taskId, isStream)\n }\n\n /**\n * Protected getter to access the private _processEvents method from the parent class.\n * This is a workaround due to SDK limitations.\n */\n protected callProcessEvents(...args: any[]): any {\n return (this as any)._processEvents.apply(this, args)\n }\n\n /**\n * Resubscribes to a task's event stream, ensuring the task has updated metadata before yielding.\n * This method overrides the parent implementation to ensure metadata is updated before yielding.\n * @param params - Parameters containing the taskId\n * @returns Async generator of events\n */\n async *resubscribe(\n params: TaskIdParams,\n ): AsyncGenerator<Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined> {\n const task = await this.getTaskStore().load(params.id)\n if (!task) {\n throw A2AError.taskNotFound(params.id)\n }\n\n // Yield task immediately (with current metadata)\n yield task\n\n const finalStates: TaskState[] = ['completed', 'failed', 'canceled', 'rejected']\n if (finalStates.includes(task.status.state)) {\n return\n }\n\n const eventBus = this.getEventBusManager().getByTaskId(params.id)\n if (!eventBus) {\n console.warn(`Resubscribe: No active event bus for task ${params.id}.`)\n return\n }\n\n const eventQueue = new ExecutionEventQueue(eventBus)\n try {\n for await (const event of eventQueue.events()) {\n // Process event with ResultManager to ensure task is saved\n const resultManager = new ResultManager(this.getTaskStore())\n // Set context from task history if available\n if (task.history && task.history.length > 0) {\n resultManager.setContext(task.history[0])\n }\n await resultManager.processEvent(event)\n\n // Handle redemption and push notification for final status-update events\n if (\n event.kind === 'status-update' &&\n event.final &&\n event.taskId === params.id &&\n terminalStates.includes(event.status?.state)\n ) {\n // Get HTTP context for this task\n const httpContext = this.getHttpRequestContextForTask(event.taskId)\n if (httpContext) {\n const { bearerToken, validation } = httpContext\n if (bearerToken && validation) {\n // Handle task finalization (redemption and push notification)\n await this.handleTaskFinalization(resultManager, event, bearerToken, httpContext)\n }\n }\n }\n\n // Yield event after processing (so metadata is updated)\n if (event.kind === 'status-update' && event.taskId === params.id) {\n yield event\n } else if (event.kind === 'artifact-update' && event.taskId === params.id) {\n yield event\n } else if (event.kind === 'task' && event.id === params.id) {\n yield event\n }\n }\n } finally {\n eventQueue.stop()\n }\n }\n}\n"]}
1
+ {"version":3,"file":"paymentsRequestHandler.js","sourceRoot":"","sources":["../../src/a2a/paymentsRequestHandler.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,QAAQ,EAER,qBAAqB,EAErB,mBAAmB,EACnB,aAAa,GACd,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAAqB,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAErE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EACL,oBAAoB,GAGrB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,Y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D;gBACxD,IAAI,KAAK,CAAC,IAAI,KAAK,eAAe,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,EAAE,EAAE,CAAC;oBACjE,MAAM,KAAK,CAAA;gBACb,CAAC;qBAAM,IAAI,KAAK,CAAC,IAAI,KAAK,iBAAiB,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,EAAE,EAAE,CAAC;oBAC1E,MAAM,KAAK,CAAA;gBACb,CAAC;qBAAM,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,IAAI,KAAK,CAAC,EAAE,KAAK,MAAM,CAAC,EAAE,EAAE,CAAC;oBAC3D,MAAM,KAAK,CAAA;gBACb,CAAC;YACH,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,UAAU,CAAC,IAAI,EAAE,CAAA;QACnB,CAAC;IACH,CAAC;CACF","sourcesContent":["import type {\n AgentCard,\n Message,\n MessageSendParams,\n PushNotificationConfig,\n Task,\n TaskArtifactUpdateEvent,\n TaskIdParams,\n TaskState,\n TaskStatusUpdateEvent,\n} from '@a2a-js/sdk'\nimport type { ExecutionEventBusManager, TaskStore } from '@a2a-js/sdk/server'\nimport {\n A2AError,\n AgentExecutor,\n DefaultRequestHandler,\n ExecutionEventBus,\n ExecutionEventQueue,\n ResultManager,\n} from '@a2a-js/sdk/server'\nimport { v4 as uuidv4 } from 'uuid'\nimport { PaymentsError } from '../common/payments.error.js'\nimport { StartAgentRequest, isValidScheme } from '../common/types.js'\nimport { Payments } from '../payments.js'\nimport { decodeAccessToken } from '../utils.js'\nimport {\n buildPaymentRequired,\n type SettlePermissionsResult,\n type X402PaymentRequired,\n} from '../x402/facilitator-api.js'\nimport { x402A2AUtils } from './x402-a2a.js'\nimport type {\n A2AAuthResult,\n A2AStreamEvent,\n AgentRequestContext,\n HttpRequestContext,\n PaymentRedemptionConfig,\n PaymentsRequestContext,\n} from './types.js'\n\nconst terminalStates: TaskState[] = ['completed', 'failed', 'canceled', 'rejected']\n\n/**\n * A decimal string, and nothing else — no sign, no whitespace, no `0x`/`1e3`,\n * no fractional part. `Number()` accepts every one of those, and worse, maps the\n * empty-ish family (`''`, `' '`, `null`, `[]`, `false`) to **0** rather than\n * `NaN`, so `Number.isFinite` does not catch them. Publishing that 0 would say\n * \"you were charged nothing\" on a settle we simply could not read — the same\n * class of lie this helper exists to prevent on pay-as-you-go.\n *\n * Same reasoning, same shape as `DECIMAL_INTEGER_STRING` in `mpp/mpp-api.ts`.\n */\nconst DECIMAL_INTEGER_STRING = /^\\d+$/\n\n/**\n * The credits a settle actually redeemed, for `event.metadata.creditsCharged`.\n *\n * Reads {@link SettlePermissionsResult.creditsRedeemed} per billing model rather\n * than trusting it flat, because it does not mean the same thing under both:\n *\n * - `credits` — the plan holds a balance and `creditsRedeemed` is what came out\n * of it. Report it. It can legitimately differ from the credits the request\n * asked to burn (margin-based pricing), which is the whole reason to report\n * the settled figure rather than the requested one.\n * - `pay-as-you-go` — the plan holds no credit balance at all, so\n * `creditsRedeemed` is the string `'0'` *even on a settle that charged the\n * buyer*. Returning that `0` would tell a buyer they were charged nothing for\n * a payment that really happened, so report nothing instead. The charge is\n * referenced by `orderTx` (fiat) or `transaction` (crypto); the credits the\n * request asked to burn remain on the event as `creditsUsed`, so nothing is\n * lost by omitting a figure that has no meaning on this billing model.\n *\n * ⚠️ MCP does the OPPOSITE and that is deliberate — a settled decision (repo\n * owner, on the #443 review), not drift. `_meta['nevermined/credits']` reports\n * the `'0'` because it emits `billingModel` BESIDE it, so a consumer can read\n * it; `creditsCharged` here has no discriminator next to it, so a bare `0`\n * would say \"you were charged nothing\" about a charge that succeeded. Do not\n * reconcile the two.\n * - absent — a Nevermined API older than the discriminator (`creditsRedeemed`\n * has been on the settle response since 2026-03-25, `billingModel` only since\n * 2026-08-06). Apply the `credits` rule: a missing discriminator must never be\n * read as pay-as-you-go.\n *\n * Mind the type: these are **strings**. `'0'` is truthy while `Number('0') > 0`\n * is false, so a truthiness check and a numeric one disagree on exactly the\n * value that matters.\n *\n * Three ways this returns `undefined`, and they mean different things — the\n * first is a design decision, the other two are faults, which is why only the\n * faults warn:\n *\n * 1. the billing model has no credits figure to report (pay-as-you-go, or any\n * discriminator that is present and is not `credits`) — silent, by design;\n * 2. `creditsRedeemed` is absent, or not a plain decimal string — warns;\n * 3. the value is a decimal string too large for a JS number — warns.\n *\n * @param settlement - The settlement receipt as the facilitator returned it\n * @returns The credits redeemed, or `undefined` per the three cases above\n */\nfunction resolveCreditsCharged(settlement: SettlePermissionsResult): number | undefined {\n // ALLOWLIST, not a denylist. `=== 'pay-as-you-go'` let every other value fall\n // into the credits branch and publish a `0`: `null`, `''`, `'PAY-AS-YOU-GO'`,\n // a future third billing model, a non-string. The response is an unchecked\n // `as SettlePermissionsResult` over `response.json()`, so the union type\n // provides no runtime guarantee and the wrong values are reachable.\n //\n // `undefined` still means `credits` — that is the documented ruling above and\n // it is preserved exactly. What changes is that a discriminator which is\n // present but not `credits` now omits rather than reporting a zero.\n if (settlement.billingModel !== undefined && settlement.billingModel !== 'credits') {\n return undefined\n }\n\n // A FAILED settle has no measured redemption to report, so it gets no figure.\n // `settlePermissions` does not throw on one — it returns 200 with\n // `success: false` verbatim — so without this a failure published\n // `creditsCharged` as though it were measured: `{success: false,\n // creditsRedeemed: '7'}` reported 7 credits charged for a settle that charged\n // nothing. The published contract makes that a lie rather than merely noise,\n // because `markdown/a2a-integration.md` defines `0` as \"a real figure, not an\n // absence\" — a number here asserts the settle completed.\n //\n // ⚠️ `!== true`, not `=== false`, and the asymmetry with `billingModel` above\n // is deliberate. An ABSENT `billingModel` is a documented legacy shape (APIs\n // predating the field) and is read as `credits`; an absent `success` is not a\n // legacy shape — the field has always been there and is declared\n // non-optional — so its absence means the response is malformed, and a\n // malformed response is exactly when not to publish a figure.\n //\n // Silent, like the pay-as-you-go branch: a failed settle is a legitimate\n // outcome the caller already sees on `success`, not a reporting fault.\n if (settlement.success !== true) {\n return undefined\n }\n\n const raw = settlement.creditsRedeemed\n if (typeof raw !== 'string' || !DECIMAL_INTEGER_STRING.test(raw)) {\n // Silence here would be indistinguishable from the pay-as-you-go omission,\n // which is a deliberate design decision rather than a fault. Warn, as\n // `x402/express/middleware.ts` does on this same field.\n console.warn(\n raw === undefined\n ? `[PaymentsRequestHandler] settle reported no creditsRedeemed; omitting ` +\n `creditsCharged rather than publishing a figure`\n : `[PaymentsRequestHandler] settle reported an unusable creditsRedeemed ` +\n `(${JSON.stringify(raw)}); omitting creditsCharged rather than publishing a figure`,\n )\n return undefined\n }\n\n const redeemed = Number(raw)\n if (!Number.isSafeInteger(redeemed)) {\n // The wire carries this as a string precisely because it can exceed what a\n // JS number represents. Above 2^53 the conversion is silently wrong\n // (`'9007199254740993'` becomes 9007199254740992), and a wrong number is\n // worse than no number: the exact value is still on the task, verbatim, in\n // the `x402.payment.receipts` entry that `recordPaymentSuccess` writes.\n console.warn(\n `[PaymentsRequestHandler] creditsRedeemed ${raw} exceeds Number.MAX_SAFE_INTEGER; ` +\n `omitting creditsCharged rather than publishing a rounded figure`,\n )\n return undefined\n }\n\n return redeemed\n}\n\n/**\n * Options for configuring the PaymentsRequestHandler\n */\nexport interface PaymentsRequestHandlerOptions {\n /** Whether to execute tasks asynchronously */\n asyncExecution?: boolean\n /** Default batch mode for all requests (can be overridden per-request) */\n defaultBatch?: boolean\n /** Default margin percentage for all requests (can be overridden per-request) */\n defaultMarginPercent?: number\n}\n\n/**\n * PaymentsRequestHandler extends DefaultRequestHandler to add payments validation and burning.\n * It validates credits before executing a task and burns credits after successful execution.\n * It also sends push notifications when a task reaches a terminal state.\n * @param options - Handler options, including asyncExecution, defaultBatch, and defaultMarginPercent\n */\nexport class PaymentsRequestHandler extends DefaultRequestHandler {\n private paymentsService: Payments\n private httpContextByTaskId: Map<string, HttpRequestContext> = new Map()\n private httpContextByMessageId: Map<string, HttpRequestContext> = new Map()\n private asyncExecution: boolean\n private defaultBatch: boolean\n private defaultMarginPercent?: number\n\n /**\n * Store HTTP context temporarily by messageId (used in middleware when taskId is not yet available).\n * @param messageId - The messageId from the incoming message\n * @param ctx - The HTTP context (bearerToken, url, method)\n */\n public setHttpRequestContextForMessage(messageId: string, ctx: HttpRequestContext) {\n this.httpContextByMessageId.set(messageId, ctx)\n }\n\n /**\n * Store HTTP context by taskId (used in middleware when taskId is available).\n * @param taskId - The taskId of the task\n * @param ctx - The HTTP context (bearerToken, url, method)\n */\n public setHttpRequestContextForTask(taskId: string, ctx: HttpRequestContext) {\n this.httpContextByTaskId.set(taskId, ctx)\n }\n\n /**\n * @param agentCard - The agent card\n * @param taskStore - The task store\n * @param agentExecutor - The business logic executor\n * @param paymentsService - The payments service for validation and burning\n * @param eventBusManager - The event bus manager (optional)\n * @param options - Handler options (asyncExecution, defaultBatch, defaultMarginPercent)\n */\n constructor(\n agentCard: AgentCard,\n taskStore: TaskStore,\n agentExecutor: AgentExecutor,\n paymentsService: any,\n eventBusManager?: ExecutionEventBusManager,\n options?: PaymentsRequestHandlerOptions,\n ) {\n super(agentCard, taskStore, agentExecutor, eventBusManager)\n this.paymentsService = paymentsService\n this.asyncExecution = options?.asyncExecution ?? false\n this.defaultBatch = options?.defaultBatch ?? false\n this.defaultMarginPercent = options?.defaultMarginPercent\n }\n\n /**\n * Retrieve the HTTP context for a given taskId.\n * @param taskId - The taskId of the task\n * @returns The HTTP context (bearerToken, url, method) or undefined\n */\n private getHttpRequestContextForTask(taskId: string): HttpRequestContext | undefined {\n return this.httpContextByTaskId.get(taskId)\n }\n\n /**\n * Retrieve the HTTP context for a given messageId.\n * @param messageId - The messageId of the message\n * @returns The HTTP context (bearerToken, url, method) or undefined\n */\n private getHttpRequestContextForMessage(messageId: string): HttpRequestContext | undefined {\n return this.httpContextByMessageId.get(messageId)\n }\n\n /**\n * Deletes the HTTP context associated with a taskId.\n * @param taskId - The taskId to delete context for\n */\n public deleteHttpRequestContextForTask(taskId: string): void {\n this.httpContextByTaskId.delete(taskId)\n }\n\n /**\n * Get the handler options (defaultBatch, defaultMarginPercent).\n * Used by middleware to determine default redemption behavior.\n * @returns The handler options\n */\n public getHandlerOptions(): PaymentsRequestHandlerOptions {\n return {\n asyncExecution: this.asyncExecution,\n defaultBatch: this.defaultBatch,\n defaultMarginPercent: this.defaultMarginPercent,\n }\n }\n\n /**\n * Validates a request using the x402 payments service.\n * This method is used by the middleware to validate credits before processing requests.\n *\n * @param bearerToken - The bearer token for authentication\n * @param endpoint - Optional endpoint URL being requested\n * @param httpVerb - Optional HTTP method being used\n * @returns Promise resolving to the validation result\n */\n public async validateRequest(\n bearerToken: string,\n endpoint?: string,\n httpVerb?: string,\n ): Promise<any> {\n let planId: string | undefined\n const agentCard = await this.getAgentCard()\n const paymentExtension = agentCard.capabilities?.extensions?.find(\n (ext: any) => ext.uri === 'urn:nevermined:payment',\n )\n if (paymentExtension) {\n planId = paymentExtension.params?.planId as string\n }\n\n const decodedAccessToken = decodeAccessToken(bearerToken)\n\n if (!decodedAccessToken) {\n throw PaymentsError.unauthorized('Invalid access token.')\n }\n\n if (!planId) {\n throw PaymentsError.unauthorized('Plan ID not found in agent card.')\n }\n\n // Extract subscriberAddress from token (payload.authorization.from per x402 spec)\n const subscriberAddress = decodedAccessToken.payload?.authorization?.from\n\n if (!subscriberAddress) {\n throw PaymentsError.unauthorized(\n 'Cannot determine subscriberAddress from token (expected payload.authorization.from)',\n )\n }\n\n const agentId = paymentExtension?.params?.agentId as string | undefined\n const scheme = isValidScheme(decodedAccessToken.accepted?.scheme)\n ? decodedAccessToken.accepted.scheme\n : 'nvm:erc4337'\n\n const paymentRequired: X402PaymentRequired = buildPaymentRequired(planId, {\n endpoint: endpoint || '',\n agentId,\n httpVerb,\n scheme,\n environment: this.paymentsService.getEnvironmentName(),\n })\n\n const result = await this.paymentsService.facilitator.verifyPermissions({\n paymentRequired,\n x402AccessToken: bearerToken,\n maxAmount: 1n,\n })\n if (!result.isValid) {\n throw PaymentsError.unauthorized('Permission verification failed.')\n }\n return {\n success: true,\n planId,\n subscriberAddress,\n balance: { isSubscriber: true },\n }\n }\n\n /**\n * Gets redemption configuration for a task based on AgentCard and handler defaults.\n * The configuration is determined by the server, not by client metadata.\n *\n * @returns The redemption configuration\n */\n private async getRedemptionConfig(): Promise<PaymentRedemptionConfig> {\n const agentCard = await this.getAgentCard()\n const paymentExtension = agentCard.capabilities?.extensions?.find(\n (ext: any) => ext.uri === 'urn:nevermined:payment',\n )\n\n const agentConfig =\n (paymentExtension?.params?.redemptionConfig as PaymentRedemptionConfig) || {}\n\n return {\n useBatch: agentConfig.useBatch ?? this.defaultBatch ?? false,\n useMargin: agentConfig.useMargin ?? false,\n marginPercent: agentConfig.marginPercent ?? this.defaultMarginPercent,\n }\n }\n\n /**\n * Determines the appropriate redemption method based on server configuration.\n *\n * @param bearerToken - The bearer token for authentication\n * @param creditsUsed - The number of credits to burn\n * @param httpContext - Optional HTTP context with endpoint and method information\n * @returns The settlement receipt, verbatim as the facilitator returned it. A\n * settle the backend accepted but could not complete comes back as\n * `success: false` with an `errorReason` rather than throwing — see\n * {@link SettlePermissionsResult} for which fields evidence a charge under\n * which billing model.\n */\n private async executeRedemption(\n bearerToken: string,\n creditsUsed: bigint | number,\n httpContext?: HttpRequestContext,\n ): Promise<SettlePermissionsResult> {\n const decodedAccessToken = decodeAccessToken(bearerToken)\n if (!decodedAccessToken) {\n throw PaymentsError.unauthorized('Invalid access token.')\n }\n\n let planId: string | undefined\n let agentId: string | undefined\n const agentCard = await this.getAgentCard()\n const paymentExtension = agentCard.capabilities?.extensions?.find(\n (ext: any) => ext.uri === 'urn:nevermined:payment',\n )\n if (paymentExtension) {\n planId = paymentExtension.params?.planId as string | undefined\n agentId = paymentExtension.params?.agentId as string | undefined\n }\n\n if (!planId) {\n throw PaymentsError.unauthorized('Plan ID not found in agent card.')\n }\n\n const scheme = isValidScheme(decodedAccessToken.accepted?.scheme)\n ? decodedAccessToken.accepted.scheme\n : 'nvm:erc4337'\n\n // Build paymentRequired using the helper\n const paymentRequired = buildPaymentRequired(planId, {\n endpoint: httpContext?.urlRequested,\n agentId,\n httpVerb: httpContext?.httpMethodRequested,\n scheme,\n environment: this.paymentsService.getEnvironmentName(),\n })\n\n return await this.paymentsService.facilitator.settlePermissions({\n paymentRequired,\n x402AccessToken: bearerToken,\n maxAmount: BigInt(creditsUsed),\n })\n }\n\n /**\n * Creates PaymentsRequestContext from message parameters.\n * This method handles HTTP context retrieval, validation, and context creation.\n * @param params - Message send parameters\n * @param isStreaming - Whether this is for streaming (affects createRequestContext call)\n * @returns Object containing PaymentsRequestContext and related data\n */\n private async createPaymentsRequestContext(\n params: MessageSendParams,\n isStreaming = false,\n ): Promise<{\n paymentsRequestContext: PaymentsRequestContext\n taskId: string\n httpContext: HttpRequestContext\n bearerToken: string\n validation: StartAgentRequest\n requestContext: any\n finalMessageForAgent: Message\n eventBus: ExecutionEventBus\n eventQueue: ExecutionEventQueue\n resultManager: ResultManager\n }> {\n // Validate required parameters before any processing\n const missingParam = !params.message\n ? 'message'\n : !params.message.messageId\n ? 'message.messageId'\n : null\n if (missingParam) {\n throw A2AError.invalidParams(`${missingParam} is required.`)\n }\n\n // 1. Get HTTP context for the task or message\n let taskId = params.message.taskId\n let httpContext: HttpRequestContext | undefined\n if (taskId) {\n httpContext = this.getHttpRequestContextForTask(taskId)\n } else {\n const messageId = params.message.messageId\n httpContext = this.getHttpRequestContextForMessage(messageId)\n }\n\n if (!httpContext) {\n throw A2AError.internalError('HTTP context not found for task or message.')\n }\n\n // 2. Extract bearer token and validate presence of required fields.\n // This path only runs for an *authorized* context (a token was supplied), so\n // both bearerToken and validation must be present — assert the invariant\n // explicitly instead of carrying an `undefined as any`.\n const { bearerToken, validation } = httpContext\n if (!bearerToken) {\n throw PaymentsError.unauthorized('Missing bearer token for payment validation.')\n }\n if (!validation) {\n throw PaymentsError.unauthorized('Missing validation context for payment.')\n }\n\n // 3. Validate credits before executing the task\n const agentCard = await this.getAgentCard()\n const agentId = agentCard.capabilities?.extensions?.find(\n (ext) => ext.uri === 'urn:nevermined:payment',\n )?.params?.agentId\n if (!agentId) {\n throw A2AError.internalError('Agent ID not found in payment extension.')\n }\n\n // 4. Generate taskId if not present and migrate HTTP context\n const incomingMessage = params.message\n if (!taskId) {\n taskId = uuidv4()\n this.migrateHttpRequestContextFromMessageToTask(params.message.messageId, taskId)\n }\n\n // 5. Instantiate ResultManager and eventBus\n const resultManager = new ResultManager(this.getTaskStore())\n resultManager.setContext(incomingMessage)\n const requestContext = await this.callCreateRequestContext(incomingMessage, taskId, isStreaming)\n const finalMessageForAgent = requestContext.userMessage\n const eventBus = this.getEventBusManager().createOrGetByTaskId(taskId)\n const eventQueue = new ExecutionEventQueue(eventBus)\n\n // 6. Create PaymentsRequestContext\n const authResult: A2AAuthResult = {\n requestId: validation.agentRequestId,\n token: bearerToken,\n agentId: validation.agentId,\n agentRequest: validation,\n }\n\n const agentRequestContext: AgentRequestContext = {\n authResult,\n httpContext,\n paymentsService: this.paymentsService,\n }\n\n // 7. Create extended request context with agent request data\n const paymentsRequestContext: PaymentsRequestContext = {\n ...requestContext,\n payments: agentRequestContext,\n }\n\n return {\n paymentsRequestContext,\n taskId,\n httpContext,\n bearerToken,\n validation,\n requestContext,\n finalMessageForAgent,\n eventBus,\n eventQueue,\n resultManager,\n }\n }\n\n /**\n * x402 v2 A2A transport: if the request is payment-gated and arrived with no\n * token (the middleware stored a `paymentRequired` on the HTTP context), build\n * and return the spec-shaped `input-required` task carrying the\n * X402PaymentRequired object under `x402.payment.required` — WITHOUT executing\n * the agent. Returns `undefined` when a token was present (normal flow).\n *\n * @param params - The incoming message send parameters\n * @returns The `input-required` Task to return to the client, or `undefined`\n */\n private async buildPaymentRequiredTaskIfNeeded(\n params: MessageSendParams,\n ): Promise<Task | undefined> {\n const message = params.message\n if (!message) {\n return undefined\n }\n const incomingTaskId = message.taskId\n const httpContext = incomingTaskId\n ? this.getHttpRequestContextForTask(incomingTaskId)\n : this.getHttpRequestContextForMessage(message.messageId)\n\n if (!httpContext?.paymentRequired) {\n return undefined\n }\n\n // Correlate the input-required task with the incoming taskId when present so\n // the client's follow-up payment payload (same taskId) maps back to it.\n const taskId = incomingTaskId || uuidv4()\n const contextId = message.contextId || uuidv4()\n const task: Task = {\n kind: 'task',\n id: taskId,\n contextId,\n status: { state: 'submitted', timestamp: new Date().toISOString() },\n history: [message],\n }\n const paymentRequiredTask = x402A2AUtils.createPaymentRequiredTask(\n task,\n httpContext.paymentRequired,\n )\n\n // Persist the input-required task so the client's follow-up (same taskId)\n // can correlate to it (otherwise the SDK's _createRequestContext raises\n // \"Task not found\"). The follow-up carries the in-band payload, so the\n // middleware overwrites this taskId's HTTP context with the authorized one.\n await this.getTaskStore().save(paymentRequiredTask)\n if (!incomingTaskId) {\n this.deleteHttpRequestContextForMessage(message.messageId)\n }\n return paymentRequiredTask\n }\n\n /**\n * Stamp x402 settlement state onto the final task's metadata, in band, per the\n * x402 v2 A2A transport. Only applied when the token arrived in band (so the\n * legacy `payment-signature` header path is unchanged). On success the task\n * carries `x402.payment.status: payment-completed` + `x402.payment.receipts`;\n * on failure `payment-failed` + `x402.payment.error` + receipts.\n *\n * @param task - The current task (mutated in place)\n * @param httpContext - The request's HTTP context\n * @param settlement - The settlement result, or undefined when none ran\n */\n private recordInBandSettlement(\n task: Task | undefined,\n httpContext: HttpRequestContext | undefined,\n settlement?: SettlePermissionsResult,\n settlementDeferred = false,\n ): void {\n if (!task || !httpContext?.inBand) {\n return\n }\n // `!== true`, not `=== false` — the same rule as `resolveCreditsCharged` above,\n // for the same reason. `success` is declared non-optional, so its absence means\n // a malformed response rather than a legacy shape, and stamping one of those\n // `payment-completed` publishes the settle's figures under a success banner on\n // the surface a buyer is told to read for the authoritative receipt.\n // `settlePermissions` already reasons this way (`src/x402/facilitator-api.ts`).\n if (settlement && settlement.success !== true) {\n x402A2AUtils.recordPaymentFailure(\n task,\n settlement.errorReason || 'SETTLEMENT_FAILED',\n settlement,\n )\n } else if (settlement) {\n x402A2AUtils.recordPaymentSuccess(task, settlement)\n } else if (settlementDeferred) {\n // No in-band settlement result because redemption is BATCHED: the payload was\n // verified but on-chain settlement is deferred out-of-band (this handler never\n // confirms it). Mark payment-verified + the deferred marker, NOT\n // payment-completed — so the client knows it will be charged out-of-band\n // rather than reading a completed task as \"nothing owed\".\n x402A2AUtils.recordPaymentDeferred(task)\n } else {\n // Defensive default: verified, but no settlement result AND not batch-deferred\n // (e.g. a settle that returned nothing). Record a bare verify.\n x402A2AUtils.recordPaymentVerified(task)\n }\n }\n\n /**\n * Processes streaming events with finalization (credits burning and push notifications).\n * Similar to processEventsWithFinalization but yields events for streaming.\n * @param taskId - The task ID\n * @param resultManager - The result manager\n * @param eventQueue - The event queue\n * @param bearerToken - The bearer token\n * @param validation - The validation result\n * @returns Async generator yielding processed events\n */\n protected async *processStreamingEventsWithFinalization(\n taskId: string,\n resultManager: ResultManager,\n eventQueue: ExecutionEventQueue,\n bearerToken: string,\n requestHttpContext?: HttpRequestContext,\n ): AsyncGenerator<A2AStreamEvent, void, undefined> {\n try {\n for await (const event of eventQueue.events()) {\n await resultManager.processEvent(event)\n yield event\n\n if (\n event.kind === 'status-update' &&\n event.final &&\n event?.metadata?.creditsUsed !== undefined &&\n event?.metadata?.creditsUsed !== null &&\n bearerToken &&\n (typeof event.metadata.creditsUsed === 'string' ||\n typeof event.metadata.creditsUsed === 'number' ||\n typeof event.metadata.creditsUsed === 'bigint')\n ) {\n try {\n // Get redemption configuration from server (not from client metadata)\n const redemptionConfig = await this.getRedemptionConfig()\n\n if (!redemptionConfig.useBatch) {\n // Prefer the per-request context (authoritative in-band flag); fall\n // back to a per-taskId lookup for executors that mint their own task id.\n const httpContext =\n requestHttpContext ?? this.getHttpRequestContextForTask(event.taskId)\n // Execute redemption with server configuration for non-batch requests\n const response = await this.executeRedemption(\n bearerToken,\n BigInt(event.metadata.creditsUsed),\n httpContext,\n )\n\n // `txHash` is the A2A metadata key a buyer is shown for payment\n // support; the settle response reports that id as `transaction`.\n // There is no `txHash` on the wire — see handleTaskFinalization.\n if (response && event.metadata) {\n // Only on a settle that SUCCEEDED. `transaction` is documented as\n // an empty string when settlement failed, and a blank id beside a\n // completed task is the same defect as publishing `creditsCharged`\n // for a settle that charged nothing — see resolveCreditsCharged.\n if (response.success === true && response.transaction) {\n event.metadata.txHash = response.transaction\n }\n // Left unset when the billing model has no credits to report —\n // see resolveCreditsCharged. `creditsUsed` still carries what\n // the request asked to burn.\n const creditsCharged = resolveCreditsCharged(response)\n if (creditsCharged !== undefined) {\n event.metadata.creditsCharged = creditsCharged\n }\n }\n\n // x402 v2 A2A transport: stamp the settlement receipt onto the\n // persisted task in band. NOTE: a stream cannot retract the event\n // it already yielded above, so an in-band settlement is reflected\n // on the saved task (visible via tasks/get + resubscribe) — it\n // cannot withhold content the way a non-streaming result does.\n if (httpContext?.inBand) {\n const task = resultManager.getCurrentTask()\n if (task) {\n this.recordInBandSettlement(task, httpContext, response)\n await resultManager.processEvent(task)\n }\n }\n } else {\n // Batch redemption: on-chain settlement is deferred out-of-band. The\n // stream already yielded the content (can't retract), but stamp the\n // PERSISTED task with payment-verified + the deferred marker so a\n // streaming client (via tasks/get + resubscribe) isn't left reading a\n // completed task as \"nothing owed\" — matching the non-streaming path.\n const httpContext =\n requestHttpContext ?? this.getHttpRequestContextForTask(event.taskId)\n if (httpContext?.inBand) {\n const task = resultManager.getCurrentTask()\n if (task) {\n this.recordInBandSettlement(task, httpContext, undefined, true)\n await resultManager.processEvent(task)\n }\n }\n }\n } catch (err) {\n // x402 v2 A2A: settlement failed AFTER the paid event was already\n // streamed to the client (a stream cannot retract it). Do NOT swallow\n // it — log, and stamp payment-failed on the persisted task so\n // tasks/get + resubscribe reflect the failure (mirrors non-streaming).\n console.error('[PaymentsA2A] streaming settlement failed after execution:', err)\n const httpContext =\n requestHttpContext ?? this.getHttpRequestContextForTask(event.taskId)\n if (httpContext?.inBand) {\n try {\n const task = resultManager.getCurrentTask()\n if (task) {\n const errorReason = err instanceof Error ? err.message : String(err)\n if (task.status) task.status.state = 'failed'\n task.artifacts = undefined\n this.recordInBandSettlement(task, httpContext, {\n success: false,\n errorReason,\n transaction: '',\n network: '',\n })\n await resultManager.processEvent(task)\n }\n } catch (stampErr) {\n console.error('[PaymentsA2A] failed to stamp streaming payment-failed:', stampErr)\n }\n }\n }\n }\n\n // Handle push notification\n if (\n event.kind === 'status-update' &&\n event.final &&\n event.status?.state &&\n terminalStates.includes(event.status.state)\n ) {\n try {\n const taskPushNotificationConfig = await this.getTaskPushNotificationConfig({\n id: event.taskId,\n })\n if (taskPushNotificationConfig) {\n await this.sendPushNotification(\n event.taskId,\n event.status.state,\n taskPushNotificationConfig.pushNotificationConfig,\n {\n contextId: event.contextId,\n },\n )\n }\n } catch (err) {\n // Do nothing\n }\n }\n }\n } finally {\n // Cleanup when the stream is fully consumed or breaks\n //this.getEventBusManager().cleanupByTaskId(taskId)\n }\n }\n\n /**\n * Processes all events, calling handleTaskFinalization when a terminal status-update event is received.\n * In async mode, it can be launched in background.\n */\n protected async processEventsWithFinalization(\n taskId: string,\n resultManager: ResultManager,\n eventQueue: ExecutionEventQueue,\n bearerToken: string,\n validation: StartAgentRequest,\n options?: {\n firstResultResolver?: (event: any) => void\n firstResultRejector?: (err: any) => void\n },\n requestHttpContext?: HttpRequestContext,\n ) {\n let firstResultSent = false\n try {\n for await (const event of eventQueue.events()) {\n // Handle redemption before processing the event\n if (\n event.kind === 'status-update' &&\n event.final &&\n terminalStates.includes(event.status?.state)\n ) {\n // Prefer the per-request HTTP context (authoritative for this request,\n // carries the in-band flag). Fall back to a per-taskId lookup for\n // executors that mint their own task id (the event's taskId may then\n // differ from the request's generated one).\n const httpContext = requestHttpContext ?? this.getHttpRequestContextForTask(event.taskId)\n await this.handleTaskFinalization(resultManager, event, bearerToken, httpContext)\n }\n\n await resultManager.processEvent(event)\n if (options?.firstResultResolver && !firstResultSent) {\n if (event.kind === 'message' || event.kind === 'task') {\n options.firstResultResolver(event)\n firstResultSent = true\n }\n }\n }\n if (options?.firstResultRejector && !firstResultSent) {\n options.firstResultRejector(\n A2AError.internalError('Execution finished before a message or task was produced.'),\n )\n }\n } catch (error) {\n if (options?.firstResultRejector && !firstResultSent) {\n options.firstResultRejector(error)\n }\n throw error\n } finally {\n this.getEventBusManager().cleanupByTaskId(taskId)\n }\n }\n\n /**\n * Sends a message, validating credits before execution and burning credits after.\n * Also sends a push notification if the task reaches a terminal state.\n * This method overrides the parent implementation to allow eventBus subscription before agent execution.\n * @param params - Message send parameters\n * @returns The resulting message or task\n */\n async sendMessage(params: MessageSendParams): Promise<Message | Task> {\n // x402 v2 A2A transport: a payment-gated request with no token returns an\n // `input-required` task (in band) instead of executing the agent.\n const paymentRequiredTask = await this.buildPaymentRequiredTaskIfNeeded(params)\n if (paymentRequiredTask) {\n return paymentRequiredTask\n }\n\n // Create PaymentsRequestContext and related data\n const {\n paymentsRequestContext,\n taskId,\n httpContext,\n bearerToken,\n validation,\n requestContext,\n finalMessageForAgent,\n eventBus,\n eventQueue,\n resultManager,\n } = await this.createPaymentsRequestContext(params, false)\n\n // Execute agent with extended context\n ;(this as any).agentExecutor\n .execute(paymentsRequestContext as any, eventBus)\n .catch((err: any) => {\n const errorTask: Task = {\n id: requestContext.task?.id || uuidv4(),\n contextId: finalMessageForAgent.contextId || uuidv4(),\n status: {\n state: 'failed',\n message: {\n kind: 'message',\n role: 'agent',\n messageId: uuidv4(),\n parts: [{ kind: 'text', text: `Agent execution error: ${err.message}` }],\n taskId: requestContext.task?.id,\n contextId: finalMessageForAgent.contextId,\n },\n timestamp: new Date().toISOString(),\n },\n history: requestContext.task?.history ? [...requestContext.task.history] : [],\n kind: 'task',\n }\n if (finalMessageForAgent) {\n if (\n !errorTask.history?.find((m: any) => m.messageId === finalMessageForAgent.messageId)\n ) {\n errorTask.history?.push(finalMessageForAgent)\n }\n }\n eventBus.publish(errorTask)\n eventBus.publish({\n kind: 'status-update',\n taskId: errorTask.id,\n contextId: errorTask.contextId,\n status: errorTask.status,\n final: true,\n })\n eventBus.finished()\n })\n\n // Determine if execution should be blocking based on client request\n // The blocking parameter comes from params.configuration.blocking\n const isBlocking = params.configuration?.blocking !== false // Default to blocking if not specified\n\n if (isBlocking) {\n await this.processEventsWithFinalization(\n taskId,\n resultManager,\n eventQueue,\n bearerToken,\n validation,\n undefined,\n httpContext,\n )\n const finalResult = resultManager.getFinalResult()\n if (!finalResult) {\n throw A2AError.internalError(\n 'Agent execution finished without a result, and no task context found.',\n )\n }\n return finalResult\n } else {\n // Non-blocking execution - return immediately with first result\n if (!taskId) {\n throw A2AError.internalError('Task ID is required for non-blocking execution.')\n }\n const validTaskId = taskId\n return new Promise((resolve, reject) => {\n this.processEventsWithFinalization(\n validTaskId,\n resultManager,\n eventQueue,\n bearerToken,\n validation,\n {\n firstResultResolver: resolve,\n firstResultRejector: reject,\n },\n httpContext,\n )\n })\n }\n }\n\n /**\n * Handles credits burning and push notification when a task reaches a terminal state.\n * This is called asynchronously from the eventBus listener.\n * Supports batch and margin-based redemptions based on server configuration.\n * @param resultManager - The result manager\n * @param event - The status-update event with final state\n * @param bearerToken - The bearer token for payment validation\n * @param validation - The validation result from the request\n */\n private async handleTaskFinalization(\n resultManager: ResultManager,\n event: TaskStatusUpdateEvent,\n bearerToken: string,\n httpContext?: HttpRequestContext,\n ) {\n const creditsToBurn = event.metadata?.creditsUsed\n if (\n creditsToBurn !== undefined &&\n creditsToBurn !== null &&\n bearerToken &&\n (typeof creditsToBurn === 'string' ||\n typeof creditsToBurn === 'number' ||\n typeof creditsToBurn === 'bigint')\n ) {\n let settlement: SettlePermissionsResult | undefined\n let settlementError: unknown\n let settlementDeferred = false\n try {\n // Get redemption configuration from server (not from client metadata)\n const redemptionConfig = await this.getRedemptionConfig()\n // Batch redemption defers on-chain settlement out-of-band (no receipt here).\n settlementDeferred = redemptionConfig.useBatch ?? false\n\n if (!redemptionConfig.useBatch) {\n // Execute redemption with server configuration for non-batch requests\n const response = await this.executeRedemption(\n bearerToken,\n BigInt(creditsToBurn),\n httpContext,\n )\n settlement = response\n\n // Update event metadata with redemption results. `txHash` is the A2A\n // metadata key, not a wire field: the settle response reports the\n // transaction id as `transaction`.\n const creditsCharged = resolveCreditsCharged(response)\n const settled = response.success === true\n event.metadata = {\n ...event.metadata,\n // Same rule as `creditsCharged` below: a failed settle has no\n // transaction to name, and `transaction` is an empty string there.\n ...(settled && response.transaction ? { txHash: response.transaction } : {}),\n // The credits actually redeemed, omitted entirely when the billing\n // model has none to report — see resolveCreditsCharged. The credits\n // this request asked to burn stay available as `creditsUsed`.\n ...(creditsCharged !== undefined && { creditsCharged }),\n }\n }\n } catch (err) {\n // Settlement failed AFTER the agent executed. Always log it (the legacy\n // header path has no other surface for it). For the in-band x402 v2 A2A\n // path it is additionally surfaced below as payment-failed + suppressed\n // content; the legacy header path still delivers the result (no retract).\n console.error('[PaymentsA2A] settlement failed after execution:', err)\n settlementError = err\n }\n\n // Stamp the in-band x402 state onto the FINAL event so it survives when the\n // caller processes this event into the task's status (mutating the task\n // here would be overwritten by the final event). The event carries a Task\n // shape under `event.status`; the helpers mutate `event.status.message`.\n if (httpContext?.inBand && settlementError) {\n // x402 v2 A2A transport: a settlement failure after execution must NOT\n // deliver paid content — replace the agent's status message with a\n // failed one carrying payment-failed metadata + an error receipt.\n const errorReason =\n settlementError instanceof Error ? settlementError.message : String(settlementError)\n event.status = {\n state: 'failed',\n message: {\n kind: 'message',\n messageId: uuidv4(),\n role: 'agent',\n parts: [{ kind: 'text', text: `Payment settlement failed: ${errorReason}` }],\n taskId: event.taskId,\n contextId: event.contextId,\n metadata: {},\n },\n timestamp: new Date().toISOString(),\n }\n this.recordInBandSettlement({ status: event.status } as any, httpContext, {\n success: false,\n errorReason,\n transaction: '',\n network: settlement?.network || '',\n })\n } else if (httpContext?.inBand) {\n // Stamp in-band settlement state onto the final event's status message.\n this.recordInBandSettlement(\n { status: event.status } as any,\n httpContext,\n settlement,\n settlementDeferred,\n )\n }\n\n try {\n // Always update task metadata and process the task\n const task = resultManager.getCurrentTask()\n if (task) {\n // Update task metadata with current event metadata (executor / redemption).\n task.metadata = {\n ...task.metadata,\n ...event.metadata,\n }\n\n if (httpContext?.inBand && settlementError) {\n // x402 v2 A2A transport: a settlement failure must never deliver paid\n // content. The agent's status message was already replaced above; also\n // drop any artifacts it emitted so the paid result cannot surface there\n // (mirrors the Python SDK's _apply_inband_settlement). History is rebuilt\n // by processEvent below from the replaced (failed) status, so it carries\n // no paid content.\n task.artifacts = undefined\n }\n\n await resultManager.processEvent(task)\n // Delete http context associated with the task\n this.deleteHttpRequestContextForTask(event.taskId)\n }\n } catch (err) {\n // This block persists the payment-failed/suppressed task; if it throws the\n // suppression itself failed, so log loudly rather than swallow.\n console.error('[PaymentsA2A] failed to persist finalized task:', err)\n }\n }\n try {\n const taskPushNotificationConfig = await this.getTaskPushNotificationConfig({\n id: event.taskId,\n })\n if (taskPushNotificationConfig) {\n await this.sendPushNotification(\n event.taskId,\n event.status.state,\n taskPushNotificationConfig.pushNotificationConfig,\n { contextId: event.contextId },\n )\n }\n } catch (err) {\n // Do nothing\n }\n }\n\n /**\n * Streams messages and events for a task, with payments validation.\n * Also sends a push notification if a terminal status-update event is emitted.\n * @param params - Message send parameters\n * @returns Async generator of events\n */\n async *sendMessageStream(\n params: MessageSendParams,\n ): AsyncGenerator<A2AStreamEvent, void, undefined> {\n // x402 v2 A2A transport: a payment-gated request with no token yields a\n // single `input-required` task (in band) instead of executing the agent.\n const paymentRequiredTask = await this.buildPaymentRequiredTaskIfNeeded(params)\n if (paymentRequiredTask) {\n yield paymentRequiredTask\n return\n }\n\n // Create PaymentsRequestContext and related data\n const {\n paymentsRequestContext,\n taskId,\n httpContext,\n bearerToken,\n requestContext,\n finalMessageForAgent,\n eventBus,\n eventQueue,\n resultManager,\n } = await this.createPaymentsRequestContext(params, true)\n\n // Execute agent with extended context\n ;(this as any).agentExecutor\n .execute(paymentsRequestContext as any, eventBus)\n .catch((err: any) => {\n console.error(\n `Agent execution failed for stream message ${finalMessageForAgent.messageId}:`,\n err,\n )\n const contextId = finalMessageForAgent.contextId || uuidv4()\n const errorTaskStatus: TaskStatusUpdateEvent = {\n kind: 'status-update',\n taskId: requestContext.task?.id || uuidv4(),\n contextId,\n status: {\n state: 'failed',\n message: {\n kind: 'message',\n role: 'agent',\n messageId: uuidv4(),\n parts: [{ kind: 'text', text: `Agent execution error: ${err.message}` }],\n taskId: requestContext.task?.id,\n contextId,\n },\n timestamp: new Date().toISOString(),\n },\n final: true,\n }\n eventBus.publish(errorTaskStatus)\n })\n\n // Process streaming events with finalization\n yield* this.processStreamingEventsWithFinalization(\n taskId,\n resultManager,\n eventQueue,\n bearerToken,\n httpContext,\n )\n }\n\n /**\n * Sends a push notification when a task reaches a terminal state.\n * @param taskId - The task ID\n * @param state - The terminal state\n * @param pushNotificationConfig - The push notification configuration\n * @param payload - Additional payload to include in the notification\n */\n private async sendPushNotification(\n taskId: string,\n state: TaskState,\n pushNotificationConfig: PushNotificationConfig,\n payload: Record<string, any> = {},\n ) {\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n }\n if (pushNotificationConfig.authentication) {\n if (pushNotificationConfig.authentication.schemes.includes('basic')) {\n const basic = Buffer.from(`${pushNotificationConfig.authentication.credentials}`).toString(\n 'base64',\n )\n headers['Authorization'] = `Basic ${basic}`\n } else if (pushNotificationConfig.authentication.schemes.includes('bearer')) {\n headers['Authorization'] = `Bearer ${pushNotificationConfig.authentication.credentials}`\n } else if (pushNotificationConfig.authentication.schemes.includes('custom')) {\n Object.assign(headers, pushNotificationConfig.authentication.credentials)\n }\n }\n const body = JSON.stringify({\n taskId,\n state,\n payload,\n })\n const response = await fetch(pushNotificationConfig.url, {\n method: 'POST',\n headers,\n body,\n })\n if (!response.ok) {\n throw A2AError.internalError('Failed to send push notification.')\n }\n }\n\n /**\n * Migrates the HTTP context from a messageId to a taskId and deletes the temporary messageId context.\n * @param messageId - The messageId to migrate from\n * @param taskId - The taskId to migrate to\n */\n public migrateHttpRequestContextFromMessageToTask(messageId: string, taskId: string): void {\n const ctx = this.getHttpRequestContextForMessage(messageId)\n if (ctx) {\n this.setHttpRequestContextForTask(taskId, ctx)\n this.deleteHttpRequestContextForMessage(messageId)\n }\n }\n\n /**\n * Deletes the HTTP context associated with a messageId.\n * @param messageId - The messageId to delete context for\n */\n public deleteHttpRequestContextForMessage(messageId: string): void {\n this.httpContextByMessageId.delete(messageId)\n }\n\n /**\n * Protected getter to access the private taskStore property from the parent class.\n * This is a workaround due to SDK limitations.\n */\n protected getTaskStore(): TaskStore {\n return (this as any).taskStore as TaskStore\n }\n\n /**\n * Protected getter to access the private eventBusManager property from the parent class.\n * This is a workaround due to SDK limitations.\n */\n protected getEventBusManager(): ExecutionEventBusManager {\n return (this as any).eventBusManager as ExecutionEventBusManager\n }\n\n /**\n * Protected getter to access the private _createRequestContext method from the parent class.\n * This is a workaround due to SDK limitations.\n */\n protected async callCreateRequestContext(\n incomingMessage: any,\n taskId: string,\n isStream: boolean,\n ): Promise<any> {\n return await (this as any)._createRequestContext(incomingMessage, taskId, isStream)\n }\n\n /**\n * Protected getter to access the private _processEvents method from the parent class.\n * This is a workaround due to SDK limitations.\n */\n protected callProcessEvents(...args: any[]): any {\n return (this as any)._processEvents.apply(this, args)\n }\n\n /**\n * Resubscribes to a task's event stream, ensuring the task has updated metadata before yielding.\n * This method overrides the parent implementation to ensure metadata is updated before yielding.\n * @param params - Parameters containing the taskId\n * @returns Async generator of events\n */\n async *resubscribe(\n params: TaskIdParams,\n ): AsyncGenerator<Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined> {\n const task = await this.getTaskStore().load(params.id)\n if (!task) {\n throw A2AError.taskNotFound(params.id)\n }\n\n // Yield task immediately (with current metadata)\n yield task\n\n const finalStates: TaskState[] = ['completed', 'failed', 'canceled', 'rejected']\n if (finalStates.includes(task.status.state)) {\n return\n }\n\n const eventBus = this.getEventBusManager().getByTaskId(params.id)\n if (!eventBus) {\n console.warn(`Resubscribe: No active event bus for task ${params.id}.`)\n return\n }\n\n const eventQueue = new ExecutionEventQueue(eventBus)\n try {\n for await (const event of eventQueue.events()) {\n // Process event with ResultManager to ensure task is saved\n const resultManager = new ResultManager(this.getTaskStore())\n // Set context from task history if available\n if (task.history && task.history.length > 0) {\n resultManager.setContext(task.history[0])\n }\n await resultManager.processEvent(event)\n\n // Handle redemption and push notification for final status-update events\n if (\n event.kind === 'status-update' &&\n event.final &&\n event.taskId === params.id &&\n terminalStates.includes(event.status?.state)\n ) {\n // Get HTTP context for this task\n const httpContext = this.getHttpRequestContextForTask(event.taskId)\n if (httpContext) {\n const { bearerToken, validation } = httpContext\n if (bearerToken && validation) {\n // Handle task finalization (redemption and push notification)\n await this.handleTaskFinalization(resultManager, event, bearerToken, httpContext)\n }\n }\n }\n\n // Yield event after processing (so metadata is updated)\n if (event.kind === 'status-update' && event.taskId === params.id) {\n yield event\n } else if (event.kind === 'artifact-update' && event.taskId === params.id) {\n yield event\n } else if (event.kind === 'task' && event.id === params.id) {\n yield event\n }\n }\n } finally {\n eventQueue.stop()\n }\n }\n}\n"]}
@@ -113,6 +113,31 @@ export interface PaymentMetadata {
113
113
  agentId?: string;
114
114
  /** Configuration for credit redemption behavior */
115
115
  redemptionConfig?: PaymentRedemptionConfig;
116
+ /**
117
+ * The settle's transaction reference, written by the SDK after settlement.
118
+ * A chain tx hash on the crypto rails; the PSP transaction id on fiat (a
119
+ * Stripe PaymentIntent `pi_...`), so do not assume it is a hash.
120
+ *
121
+ * ABSENT unless the settle both succeeded AND reported a `transaction`. The
122
+ * wire's `transaction` is an empty string on a failed settle, and publishing
123
+ * that put a blank id on a completed task — so the key is omitted instead,
124
+ * and its PRESENCE means a settlement really happened. Absence does not by
125
+ * itself mean failure: a successful fiat charge is referenced by the receipt's
126
+ * `orderTx` and can carry an empty `transaction`. Same rule as `creditsCharged`.
127
+ */
128
+ txHash?: string;
129
+ /**
130
+ * Credits the settle ACTUALLY REDEEMED, written by the SDK after settlement —
131
+ * not the credits the request asked to burn, which stay on `creditsUsed`.
132
+ *
133
+ * ⚠️ Its ABSENCE is meaningful and is part of the contract. The key is omitted
134
+ * when there is no measured redemption to report: a pay-as-you-go plan (which
135
+ * holds no credit balance, so its `creditsRedeemed` is '0' even on a charge
136
+ * that succeeded), a settle that failed, or a backend that reported no usable
137
+ * figure. `0` means the opposite — a settle that completed and redeemed
138
+ * nothing. Read it with `in`, never truthiness. See `resolveCreditsCharged`.
139
+ */
140
+ creditsCharged?: number;
116
141
  }
117
142
  /**
118
143
  * Options required to register or retrieve a client in the registry.
@@ -123,6 +148,11 @@ export interface ClientRegistryOptions {
123
148
  planId: string;
124
149
  agentCardPath?: string;
125
150
  delegationConfig?: import('../common/types.js').DelegationConfig;
151
+ /**
152
+ * EIP-712 token version to request. `3` mints a single-use token bound to the
153
+ * agent's service endpoint, minted per paid call instead of cached.
154
+ */
155
+ tokenVersion?: import('../common/types.js').X402TokenVersion;
126
156
  }
127
157
  /**
128
158
  * Options for agent interaction methods (used by PaymentsClient).
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/a2a/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,0BAA0B,EAC1B,qCAAqC,EACrC,YAAY,EACZ,qCAAqC,EACtC,MAAM,aAAa,CAAA;AAEpB,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAC1E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAE9C;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,IAAI,G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AC,IAAI,CAAC,CAAA;IAC3F,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACvE;AAGD,YAAY,EACV,SAAS,EACT,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,0BAA0B,EAC1B,qCAAqC,EACrC,YAAY,EACZ,qCAAqC,EACrC,iBAAiB,EACjB,aAAa,GACd,CAAA;AAGD,YAAY,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/a2a/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG","sourcesContent":["/**\n * Types and interfaces for the A2A payments integration.\n *\n * This module defines the core types and interfaces used throughout the A2A\n * payments integration. It provides:\n * - Task context structures for user executors\n * - Handler result definitions\n * - Payment metadata interfaces\n * - Re-exports of A2A SDK types for convenience\n *\n * These types ensure type safety and provide clear contracts between\n * the user's executor implementation and the payments system.\n */\n\nimport type {\n AgentCard,\n Task,\n Message,\n Artifact,\n TaskState,\n Part,\n TaskStatusUpdateEvent,\n TaskArtifactUpdateEvent,\n PushNotificationConfig,\n MessageSendParams,\n SendMessageResponse,\n TaskQueryParams,\n GetTaskResponse,\n TaskPushNotificationConfig,\n SetTaskPushNotificationConfigResponse,\n TaskIdParams,\n GetTaskPushNotificationConfigResponse,\n} from '@a2a-js/sdk'\n\nimport type { ExecutionEventBus, AgentExecutor } from '@a2a-js/sdk/server'\nimport type { StartAgentRequest } from '../common/types.ts'\nimport type { Payments } from '../payments.ts'\n\n/**\n * Union type for A2A streaming events\n *\n * This type represents all possible events that can be yielded by A2A streaming methods.\n * It includes messages, tasks, status updates, and artifact updates.\n */\nexport type A2AStreamEvent = Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent\n\n/**\n * Context provided to the user's task handler.\n *\n * This interface contains all the information available to the user's\n * executor when handling an A2A task. It includes:\n * - The original user message\n * - Any existing task state (for continuation)\n * - Authentication information\n * - Request metadata\n *\n * The context is created by the PaymentsA2AAdapter and passed to the\n * user's handleTask method.\n */\nexport interface TaskContext {\n /** The original message from the user containing the request */\n userMessage: Message\n /** Any existing task state (for task continuation scenarios) */\n existingTask?: Task\n /** Bearer token for authentication and payment validation */\n bearerToken?: string\n /** Additional metadata from the original request */\n requestMetadata?: Record<string, any>\n /**\n * Emit a streaming event to the client (SSE, WebSocket, etc.) during task execution.\n * This function allows the executor to send intermediate messages or progress updates.\n *\n * @param parts - Array of message parts (text, etc.) to send as a streaming event\n * @param metadata - Optional metadata to include with the event\n */\n emitStreamingEvent?: (parts: Part[], metadata?: Record<string, any>) => void\n}\n\n/**\n * Result returned by the user's task handler.\n *\n * This interface defines the structure that user executors must return\n * from their handleTask method. The result includes:\n * - Parts that will be converted to A2A Message or Artifact objects\n * - Optional metadata for payment tracking and other purposes\n * - Task state information\n *\n * The result is processed by the PaymentsA2AAdapter to create the\n * appropriate A2A protocol objects and handle payment operations.\n */\nexport interface TaskHandlerResult {\n /** Parts that will be converted to A2A Message or Artifact objects */\n parts: Part[]\n /** Optional metadata including payment information and custom data */\n metadata?: PaymentMetadata & Record<string, any>\n /** The final state of the task */\n state?: TaskState\n}\n\n/**\n * Configuration for credit redemption behavior\n *\n * This interface defines how credits should be redeemed for a specific agent.\n * The configuration is set at the server level and cannot be manipulated by clients.\n */\nexport interface PaymentRedemptionConfig {\n /** Whether to use batch processing for redemptions */\n useBatch?: boolean\n /** Whether to use margin-based redemptions (if false, uses fixed credits) */\n useMargin?: boolean\n /** Margin percentage (0-100) when using margin-based redemptions */\n marginPercent?: number\n}\n\n/**\n * Metadata for payment/credits information to be included in A2A objects.\n *\n * This interface defines the payment-related metadata that can be included\n * in task handler results. This metadata is used for:\n * - Credit tracking and validation\n * - Payment processing\n * - Cost reporting\n * - Plan management\n *\n * The metadata is embedded in A2A Message objects and can be used by\n * clients to understand the cost of operations.\n */\nexport interface PaymentMetadata {\n /** Number of credits used for this operation */\n creditsUsed?: number\n /** ID of the payment plan associated with this operation */\n planId?: string\n /** Type of payment model used */\n paymentType?: 'fixed' | 'dynamic'\n /** Human-readable description of the cost */\n costDescription?: string\n /** Agent ID for payment tracking */\n agentId?: string\n /** Configuration for credit redemption behavior */\n redemptionConfig?: PaymentRedemptionConfig\n}\n\n/**\n * Options required to register or retrieve a client in the registry.\n */\nexport interface ClientRegistryOptions {\n agentBaseUrl: string\n agentId: string\n planId: string\n agentCardPath?: string\n delegationConfig?: import('../common/types.js').DelegationConfig\n}\n\n/**\n * Options for agent interaction methods (used by PaymentsClient).\n */\nexport interface AgentOptions {\n agentId: string\n planId?: string\n}\n\n/**\n * HTTP context associated with a task or message (for internal request tracking).\n *\n * INVARIANT — exactly one of two mutually-exclusive states:\n * - **payment-required**: a payment-gated request arrived with NO token, so only\n * `paymentRequired` is set (`bearerToken`/`validation` are absent). The handler\n * short-circuits to an `input-required` task instead of executing the agent.\n * - **authorized**: a token was supplied (in band via `x402.payment.payload` when\n * `inBand` is true, else the deprecated `payment-signature` header), so\n * `bearerToken` + `validation` are set (`paymentRequired` is absent).\n *\n * A `mode`-discriminated union would enforce this at the type level (tracked as a\n * follow-up); for now consumers guard the field they need — e.g. the settlement\n * path asserts `bearerToken` + `validation` are present.\n */\nexport type HttpRequestContext = {\n /** Set only in the authorized state. */\n bearerToken?: string\n urlRequested?: string\n httpMethodRequested?: string\n /** The validated request — set only in the authorized state. */\n validation?: StartAgentRequest\n /**\n * x402 v2 A2A in-band transport: set by the server middleware when a\n * payment-gated request arrives with NO token (neither in-band\n * `x402.payment.payload` nor the deprecated `payment-signature` header). The\n * handler short-circuits and returns an `input-required` task carrying this\n * X402PaymentRequired object under `x402.payment.required`, instead of\n * executing the agent. Set only in the payment-required state.\n */\n paymentRequired?: import('../x402/facilitator-api.js').X402PaymentRequired\n /**\n * Whether the bearer token was supplied in band (via `x402.payment.payload`\n * message metadata) rather than the deprecated `payment-signature` header.\n * When true, settlement receipts are stamped into the task metadata under the\n * spec-defined `x402.payment.*` keys.\n */\n inBand?: boolean\n}\n\n/**\n * Authentication result for A2A requests (equivalent to MCP AuthResult)\n */\nexport interface A2AAuthResult {\n /** The agent request ID for tracking */\n requestId: string\n /** The bearer token for authentication */\n token: string\n /** The agent ID */\n agentId: string\n /** The agent request data */\n agentRequest: StartAgentRequest\n}\n\n/**\n * Agent request context provided to A2A AgentExecutors\n *\n * This context contains all the payment-related data that an AgentExecutor needs\n * to process requests with payment integration. The agent is responsible for\n * calculating and specifying credits in its final response.\n */\nexport interface AgentRequestContext {\n /** Authentication result with request metadata */\n authResult: A2AAuthResult\n /** The HTTP context with request details */\n httpContext: HttpRequestContext\n /** The payments service instance for observability and other operations */\n paymentsService: Payments\n}\n\n/**\n * Base RequestContext interface (local definition based on actual usage)\n *\n * This defines the structure that the A2A SDK RequestContext actually has\n * based on how it's used in PaymentsRequestHandler.\n */\nexport interface RequestContext {\n /** The original message from the user containing the request */\n userMessage: Message\n /** Unique identifier for the task */\n taskId: string\n /** Unique identifier for the context/conversation */\n contextId: string\n /** Any existing task state (for task continuation scenarios) */\n task?: Task\n /** Reference tasks for multi-turn conversations */\n referenceTasks?: Task[]\n /** Additional metadata from the original request */\n requestMetadata?: Record<string, any>\n /** Any existing task state (for task continuation scenarios) */\n existingTask?: Task\n}\n\n/**\n * Extended RequestContext with agent request data injection\n *\n * This extends the standard A2A RequestContext to include agent request context\n * while maintaining compatibility with the A2A protocol.\n */\nexport interface PaymentsRequestContext extends RequestContext {\n /** Agent request context injection (following MCP pattern) */\n payments?: AgentRequestContext\n}\n\n/**\n * Payments-specific AgentExecutor that uses PaymentsRequestContext\n */\nexport interface PaymentsAgentExecutor {\n execute(requestContext: PaymentsRequestContext, eventBus: ExecutionEventBus): Promise<void>\n cancelTask(taskId: string, eventBus: ExecutionEventBus): Promise<void>\n}\n\n// Re-export A2A SDK types for convenience\nexport type {\n AgentCard,\n Task,\n Message,\n Artifact,\n TaskState,\n Part,\n TaskStatusUpdateEvent,\n PushNotificationConfig,\n MessageSendParams,\n SendMessageResponse,\n TaskQueryParams,\n GetTaskResponse,\n TaskPushNotificationConfig,\n SetTaskPushNotificationConfigResponse,\n TaskIdParams,\n GetTaskPushNotificationConfigResponse,\n ExecutionEventBus,\n AgentExecutor,\n}\n\n// Re-export server options type for convenience\nexport type { PaymentsA2AServerOptions } from './server.ts'\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/a2a/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG","sourcesContent":["/**\n * Types and interfaces for the A2A payments integration.\n *\n * This module defines the core types and interfaces used throughout the A2A\n * payments integration. It provides:\n * - Task context structures for user executors\n * - Handler result definitions\n * - Payment metadata interfaces\n * - Re-exports of A2A SDK types for convenience\n *\n * These types ensure type safety and provide clear contracts between\n * the user's executor implementation and the payments system.\n */\n\nimport type {\n AgentCard,\n Task,\n Message,\n Artifact,\n TaskState,\n Part,\n TaskStatusUpdateEvent,\n TaskArtifactUpdateEvent,\n PushNotificationConfig,\n MessageSendParams,\n SendMessageResponse,\n TaskQueryParams,\n GetTaskResponse,\n TaskPushNotificationConfig,\n SetTaskPushNotificationConfigResponse,\n TaskIdParams,\n GetTaskPushNotificationConfigResponse,\n} from '@a2a-js/sdk'\n\nimport type { ExecutionEventBus, AgentExecutor } from '@a2a-js/sdk/server'\nimport type { StartAgentRequest } from '../common/types.ts'\nimport type { Payments } from '../payments.ts'\n\n/**\n * Union type for A2A streaming events\n *\n * This type represents all possible events that can be yielded by A2A streaming methods.\n * It includes messages, tasks, status updates, and artifact updates.\n */\nexport type A2AStreamEvent = Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent\n\n/**\n * Context provided to the user's task handler.\n *\n * This interface contains all the information available to the user's\n * executor when handling an A2A task. It includes:\n * - The original user message\n * - Any existing task state (for continuation)\n * - Authentication information\n * - Request metadata\n *\n * The context is created by the PaymentsA2AAdapter and passed to the\n * user's handleTask method.\n */\nexport interface TaskContext {\n /** The original message from the user containing the request */\n userMessage: Message\n /** Any existing task state (for task continuation scenarios) */\n existingTask?: Task\n /** Bearer token for authentication and payment validation */\n bearerToken?: string\n /** Additional metadata from the original request */\n requestMetadata?: Record<string, any>\n /**\n * Emit a streaming event to the client (SSE, WebSocket, etc.) during task execution.\n * This function allows the executor to send intermediate messages or progress updates.\n *\n * @param parts - Array of message parts (text, etc.) to send as a streaming event\n * @param metadata - Optional metadata to include with the event\n */\n emitStreamingEvent?: (parts: Part[], metadata?: Record<string, any>) => void\n}\n\n/**\n * Result returned by the user's task handler.\n *\n * This interface defines the structure that user executors must return\n * from their handleTask method. The result includes:\n * - Parts that will be converted to A2A Message or Artifact objects\n * - Optional metadata for payment tracking and other purposes\n * - Task state information\n *\n * The result is processed by the PaymentsA2AAdapter to create the\n * appropriate A2A protocol objects and handle payment operations.\n */\nexport interface TaskHandlerResult {\n /** Parts that will be converted to A2A Message or Artifact objects */\n parts: Part[]\n /** Optional metadata including payment information and custom data */\n metadata?: PaymentMetadata & Record<string, any>\n /** The final state of the task */\n state?: TaskState\n}\n\n/**\n * Configuration for credit redemption behavior\n *\n * This interface defines how credits should be redeemed for a specific agent.\n * The configuration is set at the server level and cannot be manipulated by clients.\n */\nexport interface PaymentRedemptionConfig {\n /** Whether to use batch processing for redemptions */\n useBatch?: boolean\n /** Whether to use margin-based redemptions (if false, uses fixed credits) */\n useMargin?: boolean\n /** Margin percentage (0-100) when using margin-based redemptions */\n marginPercent?: number\n}\n\n/**\n * Metadata for payment/credits information to be included in A2A objects.\n *\n * This interface defines the payment-related metadata that can be included\n * in task handler results. This metadata is used for:\n * - Credit tracking and validation\n * - Payment processing\n * - Cost reporting\n * - Plan management\n *\n * The metadata is embedded in A2A Message objects and can be used by\n * clients to understand the cost of operations.\n */\nexport interface PaymentMetadata {\n /** Number of credits used for this operation */\n creditsUsed?: number\n /** ID of the payment plan associated with this operation */\n planId?: string\n /** Type of payment model used */\n paymentType?: 'fixed' | 'dynamic'\n /** Human-readable description of the cost */\n costDescription?: string\n /** Agent ID for payment tracking */\n agentId?: string\n /** Configuration for credit redemption behavior */\n redemptionConfig?: PaymentRedemptionConfig\n /**\n * The settle's transaction reference, written by the SDK after settlement.\n * A chain tx hash on the crypto rails; the PSP transaction id on fiat (a\n * Stripe PaymentIntent `pi_...`), so do not assume it is a hash.\n *\n * ABSENT unless the settle both succeeded AND reported a `transaction`. The\n * wire's `transaction` is an empty string on a failed settle, and publishing\n * that put a blank id on a completed task — so the key is omitted instead,\n * and its PRESENCE means a settlement really happened. Absence does not by\n * itself mean failure: a successful fiat charge is referenced by the receipt's\n * `orderTx` and can carry an empty `transaction`. Same rule as `creditsCharged`.\n */\n txHash?: string\n /**\n * Credits the settle ACTUALLY REDEEMED, written by the SDK after settlement —\n * not the credits the request asked to burn, which stay on `creditsUsed`.\n *\n * ⚠️ Its ABSENCE is meaningful and is part of the contract. The key is omitted\n * when there is no measured redemption to report: a pay-as-you-go plan (which\n * holds no credit balance, so its `creditsRedeemed` is '0' even on a charge\n * that succeeded), a settle that failed, or a backend that reported no usable\n * figure. `0` means the opposite — a settle that completed and redeemed\n * nothing. Read it with `in`, never truthiness. See `resolveCreditsCharged`.\n */\n creditsCharged?: number\n}\n\n/**\n * Options required to register or retrieve a client in the registry.\n */\nexport interface ClientRegistryOptions {\n agentBaseUrl: string\n agentId: string\n planId: string\n agentCardPath?: string\n delegationConfig?: import('../common/types.js').DelegationConfig\n /**\n * EIP-712 token version to request. `3` mints a single-use token bound to the\n * agent's service endpoint, minted per paid call instead of cached.\n */\n tokenVersion?: import('../common/types.js').X402TokenVersion\n}\n\n/**\n * Options for agent interaction methods (used by PaymentsClient).\n */\nexport interface AgentOptions {\n agentId: string\n planId?: string\n}\n\n/**\n * HTTP context associated with a task or message (for internal request tracking).\n *\n * INVARIANT — exactly one of two mutually-exclusive states:\n * - **payment-required**: a payment-gated request arrived with NO token, so only\n * `paymentRequired` is set (`bearerToken`/`validation` are absent). The handler\n * short-circuits to an `input-required` task instead of executing the agent.\n * - **authorized**: a token was supplied (in band via `x402.payment.payload` when\n * `inBand` is true, else the deprecated `payment-signature` header), so\n * `bearerToken` + `validation` are set (`paymentRequired` is absent).\n *\n * A `mode`-discriminated union would enforce this at the type level (tracked as a\n * follow-up); for now consumers guard the field they need — e.g. the settlement\n * path asserts `bearerToken` + `validation` are present.\n */\nexport type HttpRequestContext = {\n /** Set only in the authorized state. */\n bearerToken?: string\n urlRequested?: string\n httpMethodRequested?: string\n /** The validated request — set only in the authorized state. */\n validation?: StartAgentRequest\n /**\n * x402 v2 A2A in-band transport: set by the server middleware when a\n * payment-gated request arrives with NO token (neither in-band\n * `x402.payment.payload` nor the deprecated `payment-signature` header). The\n * handler short-circuits and returns an `input-required` task carrying this\n * X402PaymentRequired object under `x402.payment.required`, instead of\n * executing the agent. Set only in the payment-required state.\n */\n paymentRequired?: import('../x402/facilitator-api.js').X402PaymentRequired\n /**\n * Whether the bearer token was supplied in band (via `x402.payment.payload`\n * message metadata) rather than the deprecated `payment-signature` header.\n * When true, settlement receipts are stamped into the task metadata under the\n * spec-defined `x402.payment.*` keys.\n */\n inBand?: boolean\n}\n\n/**\n * Authentication result for A2A requests (equivalent to MCP AuthResult)\n */\nexport interface A2AAuthResult {\n /** The agent request ID for tracking */\n requestId: string\n /** The bearer token for authentication */\n token: string\n /** The agent ID */\n agentId: string\n /** The agent request data */\n agentRequest: StartAgentRequest\n}\n\n/**\n * Agent request context provided to A2A AgentExecutors\n *\n * This context contains all the payment-related data that an AgentExecutor needs\n * to process requests with payment integration. The agent is responsible for\n * calculating and specifying credits in its final response.\n */\nexport interface AgentRequestContext {\n /** Authentication result with request metadata */\n authResult: A2AAuthResult\n /** The HTTP context with request details */\n httpContext: HttpRequestContext\n /** The payments service instance for observability and other operations */\n paymentsService: Payments\n}\n\n/**\n * Base RequestContext interface (local definition based on actual usage)\n *\n * This defines the structure that the A2A SDK RequestContext actually has\n * based on how it's used in PaymentsRequestHandler.\n */\nexport interface RequestContext {\n /** The original message from the user containing the request */\n userMessage: Message\n /** Unique identifier for the task */\n taskId: string\n /** Unique identifier for the context/conversation */\n contextId: string\n /** Any existing task state (for task continuation scenarios) */\n task?: Task\n /** Reference tasks for multi-turn conversations */\n referenceTasks?: Task[]\n /** Additional metadata from the original request */\n requestMetadata?: Record<string, any>\n /** Any existing task state (for task continuation scenarios) */\n existingTask?: Task\n}\n\n/**\n * Extended RequestContext with agent request data injection\n *\n * This extends the standard A2A RequestContext to include agent request context\n * while maintaining compatibility with the A2A protocol.\n */\nexport interface PaymentsRequestContext extends RequestContext {\n /** Agent request context injection (following MCP pattern) */\n payments?: AgentRequestContext\n}\n\n/**\n * Payments-specific AgentExecutor that uses PaymentsRequestContext\n */\nexport interface PaymentsAgentExecutor {\n execute(requestContext: PaymentsRequestContext, eventBus: ExecutionEventBus): Promise<void>\n cancelTask(taskId: string, eventBus: ExecutionEventBus): Promise<void>\n}\n\n// Re-export A2A SDK types for convenience\nexport type {\n AgentCard,\n Task,\n Message,\n Artifact,\n TaskState,\n Part,\n TaskStatusUpdateEvent,\n PushNotificationConfig,\n MessageSendParams,\n SendMessageResponse,\n TaskQueryParams,\n GetTaskResponse,\n TaskPushNotificationConfig,\n SetTaskPushNotificationConfigResponse,\n TaskIdParams,\n GetTaskPushNotificationConfigResponse,\n ExecutionEventBus,\n AgentExecutor,\n}\n\n// Re-export server options type for convenience\nexport type { PaymentsA2AServerOptions } from './server.ts'\n"]}
@@ -116,13 +116,14 @@ export declare class AgentsAPI extends BasePaymentsAPI {
116
116
  * Gets the list of plans that can be ordered to get access to an agent.
117
117
  *
118
118
  * @param agentId - The unique identifier of the agent.
119
- * @param pagination - Optional pagination options to control the number of results returned.p
119
+ * @param pagination - Optional pagination options. Accepts a plain object
120
+ * (`{ page, offset, sortBy, sortOrder }`) or a `PaginationOptions` instance.
120
121
  * @returns A promise that resolves to the list of all different plans giving access to the agent.
121
122
  * @throws PaymentsError if the agent is not found.
122
123
  *
123
124
  * @example
124
125
  * ```
125
- * const result = payments.agents.getAgentPlans(planId)
126
+ * const result = payments.agents.getAgentPlans(agentId, { page: 1, offset: 10 })
126
127
  * // {
127
128
  * // total: 10,
128
129
  * // page: 1,
@@ -131,7 +132,7 @@ export declare class AgentsAPI extends BasePaymentsAPI {
131
132
  * // }
132
133
  * ```
133
134
  */
134
- getAgentPlans(agentId: string, pagination?: PaginationOptions): Promise<any>;
135
+ getAgentPlans(agentId: string, pagination?: Partial<PaginationOptions>): Promise<any>;
135
136
  /**
136
137
  * Lists the AI agents **you** published (the authenticated caller's own
137
138
  * agents). This is account management, not a marketplace search — it never
@@ -1 +1 @@
1
- {"version":3,"file":"agents-api.d.ts","sourceRoot":"","sources":["../../src/api/agents-api.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,eAAe,EAChB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAA6B,MAAM,oBAAoB,CAAA;AAYnG,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAE5D;;GAEG;AACH,qBAAa,SAAU,SAAQ,eAAe;IAC5C;;;;;OAKG;IACH,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,SAAS;IAItD;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACU,aAAa,CACxB,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,kBAAkB,EAC5B,YAAY,EAAE,MAAM,EAAE,EACtB,kBAAkB,CAAC,EAAE,kBAAkB,GACtC,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAsB/B;;;;;;;;;;;;;;;;;;;;;;;;;;;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E,aAAa,EAC5B,QAAQ,EAAE,kBAAkB,GAC3B,OAAO,CAAC,YAAY,CAAC;IAcxB;;;;;;;;;;;;;;;;;;;OAmBG;IACU,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,GAAE,OAAO,CAAC,iBAAiB,CAAM;IAavF;;;;;;;;;;;;OAYG;IACU,SAAS,CACpB,IAAI,SAAI,EACR,MAAM,SAAM,EACZ,MAAM,SAAY,EAClB,SAAS,GAAE,KAAK,GAAG,MAAe,EAClC,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,GAAG,EAAE,CAAA;KAAE,CAAC;IAc1E;;;;;;;;;;;;;;;;;;;;OAoBG;IACU,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAYnF;;;;;;;;;;;;;;;;;;;;OAoBG;IACU,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CAiBzF"}
@@ -178,13 +178,14 @@ export class AgentsAPI extends BasePaymentsAPI {
178
178
  * Gets the list of plans that can be ordered to get access to an agent.
179
179
  *
180
180
  * @param agentId - The unique identifier of the agent.
181
- * @param pagination - Optional pagination options to control the number of results returned.p
181
+ * @param pagination - Optional pagination options. Accepts a plain object
182
+ * (`{ page, offset, sortBy, sortOrder }`) or a `PaginationOptions` instance.
182
183
  * @returns A promise that resolves to the list of all different plans giving access to the agent.
183
184
  * @throws PaymentsError if the agent is not found.
184
185
  *
185
186
  * @example
186
187
  * ```
187
- * const result = payments.agents.getAgentPlans(planId)
188
+ * const result = payments.agents.getAgentPlans(agentId, { page: 1, offset: 10 })
188
189
  * // {
189
190
  * // total: 10,
190
191
  * // page: 1,
@@ -193,8 +194,10 @@ export class AgentsAPI extends BasePaymentsAPI {
193
194
  * // }
194
195
  * ```
195
196
  */
196
- async getAgentPlans(agentId, pagination = new PaginationOptions()) {
197
- const query = API_URL_GET_AGENT_PLANS.replace(':agentId', agentId) + '?' + pagination.asQueryParams();
197
+ async getAgentPlans(agentId, pagination = {}) {
198
+ const query = API_URL_GET_AGENT_PLANS.replace(':agentId', agentId) +
199
+ '?' +
200
+ new PaginationOptions(pagination).asQueryParams();
198
201
  const url = new URL(query, this.environment.backend);
199
202
  const response = await fetch(url, this.getPublicHTTPOptions('GET'));
200
203
  if (!response.ok) {