Skip to content

Feature: Implement CEP-8 Explicit Gating Lifecycle in Chat  #32

Description

@1amKhush

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

  • In mcpClient.svelte.ts, update the withClientPayments wrapper configuration:

    • Set paymentInteraction: 'explicit_gating'.
    • Implement the onPaymentRequired callback.
    • Inside the callback, format the first available PaymentOption into the existing PaymentUiState shape and publish it to the paymentNotificationsService.
    • Return a Promise that registers its resolve function with the paymentNotificationsService (keyed by the original request ID).

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions