Feat/agentic explicit gating#33
Conversation
|
@1amKhush is attempting to deploy a commit to the ContextVM's projects Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
This PR adds client-side support for CEP-8 “explicit gating” payments by propagating -32042/-32043 JSON-RPC errors through the MCP tool execution path, surfacing them as a first-class tool-call status (payment_required) and rendering invoices directly in the UI (including a new server-page toggle to request explicit_gating vs transparent mode).
Changes:
- Introduces explicit-gating error extraction/serialization utilities and wires them into
AgentOrchestratortool execution to mark tool calls aspayment_required. - Adds
PaymentErrorCardand integrates it into chat/tool UI and server capability forms to render invoices/QRs when gating errors occur. - Adds per-connection payment interaction mode selection and reconnect support in
McpClientService, plus a toggle UI on the public server page.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/routes/s/[pubkey]/+page.svelte | Adds a payment-mode toggle (transparent vs explicit_gating) and reconnect flow on the server page. |
| src/lib/types/chat-types.ts | Extends ToolCallData with payment_required status and an optional paymentError payload. |
| src/lib/services/payments/payment-errors.ts | Adds CEP-8 error codes plus helpers to extract/serialize explicit gating errors. |
| src/lib/services/payments/payment-errors.test.ts | Adds unit tests for explicit gating error extraction and serialization. |
| src/lib/services/mcpClient.svelte.ts | Adds connection mode tracking and reconnect-with-mode; updates payments middleware configuration. |
| src/lib/services/agent-orchestrator.ts | Catches CEP-8 errors during tool calls and marks tool calls as payment_required with serialized payload. |
| src/lib/services/agent-orchestrator.test.ts | Adds orchestrator tests for the new payment_required status + lossless serialization. |
| src/lib/components/ToolCallForm.svelte | Displays PaymentErrorCard when tool invocation fails with explicit gating errors. |
| src/lib/components/ResourceReadForm.svelte | Displays PaymentErrorCard when resource reads hit explicit gating errors. |
| src/lib/components/PromptGetForm.svelte | Displays PaymentErrorCard when prompt fetch hits explicit gating errors. |
| src/lib/components/chat/ToolCallCard.svelte | Updates tool-call status UI to include payment_required and renders PaymentErrorCard for tool calls. |
| src/lib/components/chat/PaymentErrorCard.svelte | New UI component to render invoice/QR/instructions from explicit gating errors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- mcpClient: Add transparent-mode payment_required notification handler - PaymentErrorCard: Fix retryAfter truthiness check and literal tab IDs - agent-orchestrator.test: Replace hardcoded delays with polling
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Description
This PR implements the end-to-end integration of the CEP-8 explicit gating payment lifecycle within the ContextVM web client.
By migrating away from the legacy transparent notification-based flow, we enable autonomous agent handling of payment requirements. When an MCP server demands payment, the LLM now natively receives the
-32042 Payment Requiredor-32043 Payment PendingJSON-RPC errors as structured context, allowing it to inform the user, wait for payment confirmation, or autonomously retry.Implements #32
Architectural Changes & Key Features
-32042and-32043JSON-RPC errors at the transport layer, losslessly serializing them intoExplicitGatingErrorpayloads that surface aspayment_requiredstatuses inside LLMToolCallData.UiOnlyPaymentHandler) in favor of dynamic CEP-8 "catch-all" behavior, allowing the server to dictate accepted Payment Method Identifiers (PMIs).PaymentErrorCard): Introduces a robust, standalone Svelte component to render single or multi-option payment invoices (with QR codes and copy actions) entirely uncoupled from the legacyPaymentStatusPanelstate.AgentOrchestratorto catch explicit gating errors, pausing the tool execution loop and feeding the invoice context directly back to the active model.[pubkey]/+page.svelte) that initiates a clean transport reconnect cycle to test tools in bothtransparentandexplicit_gatingmodes.Testing Performed
transparentpayment mode continues to function properly when explicit gating is not negotiated.PaymentErrorCardsuccessfully iterates and renders multiple payment methods with distinct, non-leaking tab states for QR/invoice views.bun testpasses, including new orchestrator unit tests validating the-32042extraction, serialization, and status-marking flows without timeout bottlenecks.svelte-checkreports 0 errors across the entire codebase.