Context
With the recent release of @contextvm/sdk@0.12.5, the core SDK now fully supports the CEP-8 explicit payment gating lifecycle (-32042 Payment Required and -32043 Payment Pending).
Currently, contextvm-site relies on the legacy transparent payment flow, which requires the server to wait for out-of-band payments. We need to update the web client to request the explicit_gating mode. This will allow the UI to capture payment requirements, show the invoice in the chat, and explicitly signal the SDK to retry the request once the user completes the payment.
Proposed Implementation
1. Update Dependencies
- Bump
@contextvm/sdk to ^0.13.0 in package.json.
2. Add Promise Resolvers to Payment State
- Update
PaymentNotificationsService (src/lib/services/payments/payment-notifications.svelte.ts) to include a resolver registry (pendingResolvers = new Map()).
- Add
registerResolver(requestId, resolve) and resolvePayment(requestId, { paid, reason }) methods so the UI can communicate payment completion back to the SDK.
3. Configure Explicit Gating in the MCP Client
4. Update the Payment UI Panel
-
In PaymentStatusPanel.svelte, add user interaction buttons beneath the QR code:
- "I have paid": Calls
paymentNotificationsService.resolvePayment(payment.requestEventId, { paid: true }), which triggers the SDK to autonomously retry the original request.
- "Cancel": Calls
resolvePayment(..., { paid: false, reason: 'user_cancelled' }).
-
(Optional) Add WebLN integration for 1-click payments.
Context
With the recent release of
@contextvm/sdk@0.12.5, the core SDK now fully supports the CEP-8 explicit payment gating lifecycle (-32042 Payment Requiredand-32043 Payment Pending).Currently,
contextvm-siterelies on the legacy transparent payment flow, which requires the server to wait for out-of-band payments. We need to update the web client to request theexplicit_gatingmode. This will allow the UI to capture payment requirements, show the invoice in the chat, and explicitly signal the SDK to retry the request once the user completes the payment.Proposed Implementation
1. Update Dependencies
@contextvm/sdkto^0.13.0inpackage.json.2. Add Promise Resolvers to Payment State
PaymentNotificationsService(src/lib/services/payments/payment-notifications.svelte.ts) to include a resolver registry (pendingResolvers = new Map()).registerResolver(requestId, resolve)andresolvePayment(requestId, { paid, reason })methods so the UI can communicate payment completion back to the SDK.3. Configure Explicit Gating in the MCP Client
In
mcpClient.svelte.ts, update thewithClientPaymentswrapper configuration:paymentInteraction: 'explicit_gating'.onPaymentRequiredcallback.PaymentOptioninto the existingPaymentUiStateshape and publish it to thepaymentNotificationsService.Promisethat registers itsresolvefunction with thepaymentNotificationsService(keyed by the original request ID).4. Update the Payment UI Panel
In
PaymentStatusPanel.svelte, add user interaction buttons beneath the QR code:paymentNotificationsService.resolvePayment(payment.requestEventId, { paid: true }), which triggers the SDK to autonomously retry the original request.resolvePayment(..., { paid: false, reason: 'user_cancelled' }).(Optional) Add WebLN integration for 1-click payments.