@ctxprotocol/sdk 0.8.2 → 0.8.3
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.
- package/README.md +21 -5
- package/dist/client/index.cjs +49 -11
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +27 -3
- package/dist/client/index.d.ts +27 -3
- package/dist/client/index.js +49 -11
- package/dist/client/index.js.map +1 -1
- package/dist/index.cjs +49 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +49 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -101,6 +101,7 @@ console.log(result.session); // methodPrice, spent, remaining, maxSpend, ...
|
|
|
101
101
|
const answer = await client.query.run({
|
|
102
102
|
query: "What are the top whale movements on Base?",
|
|
103
103
|
modelId: "glm-model", // optional: choose a supported model
|
|
104
|
+
queryDepth: "auto", // optional: fast | auto | deep
|
|
104
105
|
includeDataUrl: true, // optional: persist full execution data to blob
|
|
105
106
|
});
|
|
106
107
|
console.log(answer.response); // AI-synthesized answer
|
|
@@ -298,10 +299,12 @@ If you can answer without a tool, just respond normally.`;
|
|
|
298
299
|
|
|
299
300
|
### Client Options
|
|
300
301
|
|
|
301
|
-
| Option
|
|
302
|
-
|
|
|
303
|
-
| `apiKey`
|
|
304
|
-
| `baseUrl`
|
|
302
|
+
| Option | Type | Required | Default | Description |
|
|
303
|
+
| ------------------ | -------- | -------- | ------------------------------ | --------------------------------------------- |
|
|
304
|
+
| `apiKey` | `string` | Yes | — | Your Context Protocol API key |
|
|
305
|
+
| `baseUrl` | `string` | No | `https://www.ctxprotocol.com` | API base URL (for development) |
|
|
306
|
+
| `requestTimeoutMs` | `number` | No | `300000` | Timeout for non-streaming API calls |
|
|
307
|
+
| `streamTimeoutMs` | `number` | No | `600000` | Timeout for establishing streaming API calls |
|
|
305
308
|
|
|
306
309
|
```typescript
|
|
307
310
|
// Production
|
|
@@ -313,6 +316,8 @@ const client = new ContextClient({
|
|
|
313
316
|
const client = new ContextClient({
|
|
314
317
|
apiKey: "sk_test_...",
|
|
315
318
|
baseUrl: "http://localhost:3000",
|
|
319
|
+
requestTimeoutMs: 420_000,
|
|
320
|
+
streamTimeoutMs: 840_000,
|
|
316
321
|
});
|
|
317
322
|
```
|
|
318
323
|
|
|
@@ -395,6 +400,11 @@ const closed = await client.tools.closeSession("sess_123");
|
|
|
395
400
|
|
|
396
401
|
Run an agentic query. The server discovers answer-safe tools, executes the full pipeline (up to 100 MCP calls per response turn), applies model-aware mediator/data budgeting, and returns an AI-synthesized answer.
|
|
397
402
|
|
|
403
|
+
`queryDepth` controls orchestration depth:
|
|
404
|
+
- `fast`: lower-latency path for simple lookups.
|
|
405
|
+
- `auto`: server routes to either `fast` or `deep` from query intent + selected tool complexity.
|
|
406
|
+
- `deep`: completeness-oriented path (default when omitted).
|
|
407
|
+
|
|
398
408
|
```typescript
|
|
399
409
|
// Simple string
|
|
400
410
|
const answer = await client.query.run("What are the top whale movements on Base?");
|
|
@@ -404,6 +414,7 @@ const answer = await client.query.run({
|
|
|
404
414
|
query: "Analyze whale activity on Base",
|
|
405
415
|
tools: ["tool-uuid-1", "tool-uuid-2"], // optional — auto-discover if omitted
|
|
406
416
|
modelId: "kimi-model-thinking", // optional
|
|
417
|
+
queryDepth: "auto", // optional: fast | auto | deep
|
|
407
418
|
includeData: true, // optional: include execution data inline
|
|
408
419
|
includeDataUrl: true, // optional: include blob URL for full data
|
|
409
420
|
});
|
|
@@ -416,12 +427,17 @@ console.log(answer.data); // Optional execution data (when includeData=t
|
|
|
416
427
|
console.log(answer.dataUrl); // Optional blob URL (when includeDataUrl=true)
|
|
417
428
|
```
|
|
418
429
|
|
|
430
|
+
When retrieval-first synthesis rollout is enabled server-side, full-data or truncation-sensitive query requests can switch to retrieval-first context assembly using private stage artifacts and canonical execution data slices. `includeData` and `includeDataUrl` continue to reference the same canonical dataset used for synthesis.
|
|
431
|
+
|
|
419
432
|
#### `client.query.stream(options)`
|
|
420
433
|
|
|
421
434
|
Same as `run()` but streams events in real-time via SSE.
|
|
422
435
|
|
|
423
436
|
```typescript
|
|
424
|
-
for await (const event of client.query.stream(
|
|
437
|
+
for await (const event of client.query.stream({
|
|
438
|
+
query: "What are the top whale movements?",
|
|
439
|
+
queryDepth: "fast",
|
|
440
|
+
})) {
|
|
425
441
|
switch (event.type) {
|
|
426
442
|
case "tool-status":
|
|
427
443
|
console.log(`Tool ${event.tool.name}: ${event.status}`);
|
package/dist/client/index.cjs
CHANGED
|
@@ -273,6 +273,7 @@ var Query = class {
|
|
|
273
273
|
modelId: opts.modelId,
|
|
274
274
|
includeData: opts.includeData,
|
|
275
275
|
includeDataUrl: opts.includeDataUrl,
|
|
276
|
+
queryDepth: opts.queryDepth,
|
|
276
277
|
stream: false
|
|
277
278
|
})
|
|
278
279
|
}
|
|
@@ -338,6 +339,7 @@ var Query = class {
|
|
|
338
339
|
modelId: opts.modelId,
|
|
339
340
|
includeData: opts.includeData,
|
|
340
341
|
includeDataUrl: opts.includeDataUrl,
|
|
342
|
+
queryDepth: opts.queryDepth,
|
|
341
343
|
stream: true
|
|
342
344
|
})
|
|
343
345
|
});
|
|
@@ -383,9 +385,14 @@ var Query = class {
|
|
|
383
385
|
};
|
|
384
386
|
|
|
385
387
|
// src/client/client.ts
|
|
388
|
+
var DEFAULT_BASE_URL = "https://www.ctxprotocol.com";
|
|
389
|
+
var DEFAULT_REQUEST_TIMEOUT_MS = 3e5;
|
|
390
|
+
var DEFAULT_STREAM_TIMEOUT_MS = 6e5;
|
|
386
391
|
var ContextClient = class {
|
|
387
392
|
apiKey;
|
|
388
393
|
baseUrl;
|
|
394
|
+
requestTimeoutMs;
|
|
395
|
+
streamTimeoutMs;
|
|
389
396
|
_closed = false;
|
|
390
397
|
/**
|
|
391
398
|
* Discovery resource for searching tools
|
|
@@ -408,14 +415,26 @@ var ContextClient = class {
|
|
|
408
415
|
*
|
|
409
416
|
* @param options - Client configuration options
|
|
410
417
|
* @param options.apiKey - Your Context Protocol API key (format: sk_live_...)
|
|
411
|
-
* @param options.baseUrl - Optional base URL override (defaults to https://ctxprotocol.com)
|
|
418
|
+
* @param options.baseUrl - Optional base URL override (defaults to https://www.ctxprotocol.com)
|
|
419
|
+
* @param options.requestTimeoutMs - Optional timeout for non-streaming requests (default 300000ms)
|
|
420
|
+
* @param options.streamTimeoutMs - Optional timeout for establishing stream requests (default 600000ms)
|
|
412
421
|
*/
|
|
413
422
|
constructor(options) {
|
|
414
423
|
if (!options.apiKey) {
|
|
415
424
|
throw new ContextError("API key is required");
|
|
416
425
|
}
|
|
426
|
+
const requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
427
|
+
const streamTimeoutMs = options.streamTimeoutMs ?? DEFAULT_STREAM_TIMEOUT_MS;
|
|
428
|
+
if (!Number.isFinite(requestTimeoutMs) || requestTimeoutMs <= 0) {
|
|
429
|
+
throw new ContextError("requestTimeoutMs must be a positive number");
|
|
430
|
+
}
|
|
431
|
+
if (!Number.isFinite(streamTimeoutMs) || streamTimeoutMs <= 0) {
|
|
432
|
+
throw new ContextError("streamTimeoutMs must be a positive number");
|
|
433
|
+
}
|
|
417
434
|
this.apiKey = options.apiKey;
|
|
418
|
-
this.baseUrl = (options.baseUrl ??
|
|
435
|
+
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
436
|
+
this.requestTimeoutMs = requestTimeoutMs;
|
|
437
|
+
this.streamTimeoutMs = streamTimeoutMs;
|
|
419
438
|
this.discovery = new Discovery(this);
|
|
420
439
|
this.tools = new Tools(this);
|
|
421
440
|
this.query = new Query(this);
|
|
@@ -429,7 +448,7 @@ var ContextClient = class {
|
|
|
429
448
|
}
|
|
430
449
|
/**
|
|
431
450
|
* Internal method for making authenticated HTTP requests
|
|
432
|
-
* Includes timeout
|
|
451
|
+
* Includes timeout and retry with exponential backoff for transient errors
|
|
433
452
|
*
|
|
434
453
|
* @internal
|
|
435
454
|
*/
|
|
@@ -439,7 +458,7 @@ var ContextClient = class {
|
|
|
439
458
|
}
|
|
440
459
|
const url = `${this.baseUrl}${endpoint}`;
|
|
441
460
|
const maxRetries = 3;
|
|
442
|
-
const timeoutMs =
|
|
461
|
+
const timeoutMs = this.requestTimeoutMs;
|
|
443
462
|
let lastError;
|
|
444
463
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
445
464
|
const controller = new AbortController();
|
|
@@ -507,6 +526,7 @@ var ContextClient = class {
|
|
|
507
526
|
/**
|
|
508
527
|
* Internal method for making authenticated HTTP requests that returns
|
|
509
528
|
* the raw Response object. Used for streaming endpoints (SSE).
|
|
529
|
+
* Includes a configurable timeout for stream setup.
|
|
510
530
|
*
|
|
511
531
|
* @internal
|
|
512
532
|
*/
|
|
@@ -515,14 +535,32 @@ var ContextClient = class {
|
|
|
515
535
|
throw new ContextError("Client has been closed");
|
|
516
536
|
}
|
|
517
537
|
const url = `${this.baseUrl}${endpoint}`;
|
|
518
|
-
const
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
...options
|
|
538
|
+
const controller = new AbortController();
|
|
539
|
+
const timeout = setTimeout(() => controller.abort(), this.streamTimeoutMs);
|
|
540
|
+
let response;
|
|
541
|
+
try {
|
|
542
|
+
response = await fetch(url, {
|
|
543
|
+
...options,
|
|
544
|
+
signal: controller.signal,
|
|
545
|
+
headers: {
|
|
546
|
+
"Content-Type": "application/json",
|
|
547
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
548
|
+
...options.headers
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
} catch (error) {
|
|
552
|
+
clearTimeout(timeout);
|
|
553
|
+
const lastError = error instanceof Error ? error : new Error(String(error));
|
|
554
|
+
if (lastError.name === "AbortError") {
|
|
555
|
+
throw new ContextError(
|
|
556
|
+
`Streaming request timed out after ${this.streamTimeoutMs / 1e3}s`,
|
|
557
|
+
void 0,
|
|
558
|
+
408
|
|
559
|
+
);
|
|
524
560
|
}
|
|
525
|
-
|
|
561
|
+
throw new ContextError(lastError.message);
|
|
562
|
+
}
|
|
563
|
+
clearTimeout(timeout);
|
|
526
564
|
if (!response.ok) {
|
|
527
565
|
let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
|
|
528
566
|
let errorCode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/client/types.ts","../../src/client/resources/discovery.ts","../../src/client/resources/tools.ts","../../src/client/resources/query.ts","../../src/client/client.ts"],"names":[],"mappings":";;;AA8iBO,IAAM,YAAA,GAAN,MAAM,aAAA,SAAqB,KAAA,CAAM;AAAA,EACtC,WAAA,CACE,OAAA,EACgB,IAAA,EACA,UAAA,EACA,OAAA,EAChB;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AAJG,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AACA,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AACA,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAGhB,IAAA,IAAA,CAAK,IAAA,GAAO,cAAA;AACZ,IAAA,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,aAAA,CAAa,SAAS,CAAA;AAAA,EACpD;AACF;;;ACnjBO,IAAM,YAAN,MAAgB;AAAA,EACrB,YAAoB,MAAA,EAAuB;AAAvB,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA,EAAwB;AAAA,EAW5C,MAAM,MAAA,CACJ,cAAA,EACA,KAAA,EACiB;AACjB,IAAA,MAAM,OAAA,GACJ,OAAO,cAAA,KAAmB,QAAA,GACtB,EAAE,KAAA,EAAO,cAAA,EAAgB,OAAM,GAC/B,cAAA;AAEN,IAAA,MAAM,MAAA,GAAS,IAAI,eAAA,EAAgB;AACnC,IAAA,MAAM,KAAA,GAAQ,QAAQ,KAAA,IAAS,EAAA;AAE/B,IAAA,IAAI,KAAA,EAAO;AACT,MAAA,MAAA,CAAO,GAAA,CAAI,KAAK,KA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":"index.cjs","sourcesContent":["/**\n * Configuration options for initializing the ContextClient\n */\nexport interface ContextClientOptions {\n /**\n * Your Context Protocol API key\n * @example \"sk_live_abc123...\"\n */\n apiKey: string;\n\n /**\n * Base URL for the Context Protocol API\n * @default \"https://ctxprotocol.com\"\n */\n baseUrl?: string;\n}\n\n/**\n * An individual MCP tool exposed by a tool listing\n */\nexport interface McpToolRateLimitHints {\n /** Suggested request budget for this method */\n maxRequestsPerMinute?: number;\n\n /** Suggested parallel call ceiling for this method */\n maxConcurrency?: number;\n\n /** Suggested minimum delay between sequential calls */\n cooldownMs?: number;\n\n /** Whether this method already supports bulk/batch retrieval */\n supportsBulk?: boolean;\n\n /** Preferred batch-oriented methods to call instead of fan-out loops */\n recommendedBatchTools?: string[];\n\n /** Optional human-readable notes for planning */\n notes?: string;\n}\n\nexport type DiscoveryMode = \"query\" | \"execute\";\nexport type McpToolSurface = \"answer\" | \"execute\" | \"both\";\nexport type McpToolLatencyClass = \"instant\" | \"fast\" | \"slow\" | \"streaming\";\n\nexport interface McpToolPricingMeta {\n executeUsd?: string;\n queryUsd?: string;\n [key: string]: unknown;\n}\n\nexport interface McpToolMeta {\n /** Declared method surface */\n surface?: McpToolSurface;\n\n /** Whether this method can be selected in query mode */\n queryEligible?: boolean;\n\n /** Declared latency class for planner/runtime gating */\n latencyClass?: McpToolLatencyClass;\n\n /** Method-level pricing metadata */\n pricing?: McpToolPricingMeta;\n\n /** Derived discovery flag for execute eligibility */\n executeEligible?: boolean;\n\n /** Derived discovery field for explicit execute pricing visibility */\n executePriceUsd?: string;\n\n /** Context injection requirements handled by the Context runtime */\n contextRequirements?: string[];\n\n /**\n * Optional planner/runtime pacing hints.\n * Tool contributors can publish these to reduce rate-limit failures.\n */\n rateLimit?: McpToolRateLimitHints;\n rateLimitHints?: McpToolRateLimitHints;\n\n /** Flat aliases accepted for convenience */\n maxRequestsPerMinute?: number;\n maxConcurrency?: number;\n cooldownMs?: number;\n supportsBulk?: boolean;\n recommendedBatchTools?: string[];\n notes?: string;\n\n [key: string]: unknown;\n}\n\nexport interface StructuredMethodGuidanceHints {\n /** Suggested call-order sequence extracted from method descriptions */\n callOrderHints?: string[];\n\n /** Parameter usage caveats extracted from method descriptions */\n parameterCaveats?: string[];\n\n /** Edge-case behavior notes extracted from method descriptions */\n edgeCaseNotes?: string[];\n}\n\nexport interface McpTool {\n /** Name of the MCP tool method */\n name: string;\n\n /** Description of what this method does */\n description: string;\n\n /**\n * JSON Schema for the input arguments this tool accepts.\n * Used by LLMs to generate correct arguments.\n */\n inputSchema?: Record<string, unknown>;\n\n /**\n * JSON Schema for the output this tool returns.\n * Used by LLMs to understand the response structure.\n */\n outputSchema?: Record<string, unknown>;\n\n /** MCP metadata extensions (context injection, rate-limit hints) */\n _meta?: McpToolMeta;\n\n /** Explicit execute eligibility in discovery responses */\n executeEligible?: boolean;\n\n /** Explicit execute price visibility in discovery responses */\n executePriceUsd?: string | null;\n\n /** Whether this method has normalized structured guidance hints */\n hasStructuredGuidance?: boolean;\n\n /** Optional structured guidance hints derived from the method description */\n structuredGuidance?: StructuredMethodGuidanceHints;\n}\n\n/**\n * Represents a tool available on the Context Protocol marketplace\n */\nexport interface Tool {\n /** Unique identifier for the tool (UUID) */\n id: string;\n\n /** Human-readable name of the tool */\n name: string;\n\n /** Description of what the tool does */\n description: string;\n\n /** Price per execution in USDC */\n price: string;\n\n /** Tool category (e.g., \"defi\", \"nft\") */\n category?: string;\n\n /** Whether the tool is verified by Context Protocol */\n isVerified?: boolean;\n\n /** Tool type - currently always \"mcp\" */\n kind?: string;\n\n /**\n * Available MCP tool methods\n * Use items from this array as `toolName` when executing\n */\n mcpTools?: McpTool[];\n\n // Trust metrics (Level 2 - Reputation Ledger)\n /** Total number of queries processed */\n totalQueries?: number;\n\n /** Success rate percentage (0-100) */\n successRate?: string;\n\n /** Uptime percentage (0-100) */\n uptimePercent?: string;\n\n /** Total USDC staked by the developer */\n totalStaked?: string;\n\n /** Whether the tool has \"Proven\" status (100+ queries, >95% success, >98% uptime) */\n isProven?: boolean;\n}\n\n/**\n * Response from the tools search endpoint\n */\nexport interface SearchResponse {\n /** Array of matching tools */\n tools: Tool[];\n\n /** Discovery mode used by the server */\n mode?: DiscoveryMode;\n\n /** The search query that was used */\n query: string;\n\n /** Total number of results */\n count: number;\n}\n\n/**\n * Options for searching tools\n */\nexport interface SearchOptions {\n /** Search query (semantic search) */\n query?: string;\n\n /** Maximum number of results (1-50, default 10) */\n limit?: number;\n\n /** Discovery mode with billing semantics */\n mode?: DiscoveryMode;\n\n /** Optional explicit method surface filter */\n surface?: McpToolSurface;\n\n /** Require methods marked query eligible */\n queryEligible?: boolean;\n\n /** Require explicit method execute pricing */\n requireExecutePricing?: boolean;\n\n /** Exclude methods by latency class */\n excludeLatencyClasses?: McpToolLatencyClass[];\n\n /** Convenience switch to exclude slow methods in query mode */\n excludeSlow?: boolean;\n}\n\n/**\n * Options for executing a tool\n */\nexport interface ExecuteOptions {\n /** The UUID of the tool to execute (from search results) */\n toolId: string;\n\n /** The specific MCP tool name to call (from tool's mcpTools array) */\n toolName: string;\n\n /** Arguments to pass to the tool */\n args?: Record<string, unknown>;\n\n /**\n * Optional idempotency key (UUID recommended).\n * Reuse the same key when retrying the same logical request.\n */\n idempotencyKey?: string;\n\n /** Explicit execute mode label for request clarity */\n mode?: \"execute\";\n\n /** Optional execute session identifier */\n sessionId?: string;\n\n /** Optional per-session spend budget envelope (USD) */\n maxSpendUsd?: string;\n\n /** Request session closure after this execute call settles */\n closeSession?: boolean;\n}\n\nexport type ExecuteSessionStatus = \"open\" | \"closed\" | \"expired\";\n\nexport interface ExecuteSessionSpend {\n mode: \"execute\";\n sessionId: string | null;\n methodPrice: string;\n spent: string;\n remaining: string | null;\n maxSpend: string | null;\n\n /** Optional lifecycle fields when the API returns session state */\n status?: ExecuteSessionStatus;\n expiresAt?: string;\n closeRequested?: boolean;\n pendingAccruedCount?: number;\n pendingAccruedUsd?: string;\n}\n\n/**\n * Successful execution response from the API\n */\nexport interface ExecuteApiSuccessResponse {\n success: true;\n mode: \"execute\";\n\n /** The result data from the tool execution */\n result: unknown;\n\n /** Information about the executed tool */\n tool: {\n id: string;\n name: string;\n };\n\n /** Method-level execute pricing used for this call */\n method: {\n name: string;\n executePriceUsd: string;\n };\n\n /** Spend envelope visibility for execute sessions */\n session: ExecuteSessionSpend;\n\n /** Execution duration in milliseconds */\n durationMs: number;\n}\n\n/**\n * Error response from the API\n */\nexport interface ExecuteApiErrorResponse {\n /** Human-readable error message */\n error: string;\n\n /** Explicit mode label for clarity */\n mode?: \"execute\";\n\n /** Error code for programmatic handling */\n code?: ContextErrorCode;\n\n /** URL to help resolve the issue */\n helpUrl?: string;\n\n /** Optional spend envelope context when available */\n session?: ExecuteSessionSpend;\n}\n\n/**\n * Raw API response from the execute endpoint\n */\nexport type ExecuteApiResponse = ExecuteApiSuccessResponse | ExecuteApiErrorResponse;\n\nexport interface ExecuteSessionStartOptions {\n /** Maximum spend budget for the session (USD string) */\n maxSpendUsd: string;\n}\n\nexport interface ExecuteSessionApiSuccessResponse {\n success: true;\n mode: \"execute\";\n session: ExecuteSessionSpend;\n}\n\nexport type ExecuteSessionApiResponse =\n | ExecuteSessionApiSuccessResponse\n | ExecuteApiErrorResponse;\n\nexport interface ExecuteSessionResult {\n mode: \"execute\";\n session: ExecuteSessionSpend;\n}\n\n/**\n * The resolved result returned to the user after SDK processing\n */\nexport interface ExecutionResult<T = unknown> {\n mode: \"execute\";\n\n /** The data returned by the tool */\n result: T;\n\n /** Information about the executed tool */\n tool: {\n id: string;\n name: string;\n };\n\n /** Method-level execute pricing used for this call */\n method: {\n name: string;\n executePriceUsd: string;\n };\n\n /** Spend envelope visibility for execute calls */\n session: ExecuteSessionSpend;\n\n /** Execution duration in milliseconds */\n durationMs: number;\n}\n\n// ---------------------------------------------------------------------------\n// Query types (pay-per-response / agentic mode)\n// ---------------------------------------------------------------------------\n\n/**\n * Options for the agentic query endpoint (pay-per-response).\n *\n * Unlike `execute()` which calls a single tool once, `query()` sends a\n * natural-language question and lets the server handle tool discovery,\n * multi-tool orchestration, self-healing retries, and AI synthesis.\n * One flat fee covers up to 100 MCP skill calls per tool.\n */\nexport interface QueryOptions {\n /** The natural-language question to answer */\n query: string;\n\n /**\n * Optional tool IDs to use. When omitted the server discovers tools\n * automatically (Auto Mode). When provided, only these tools are used\n * (Manual Mode).\n */\n tools?: string[];\n\n /**\n * Optional model ID for query orchestration/synthesis.\n * Supported IDs are published by the Context API.\n */\n modelId?: string;\n\n /**\n * Include execution data inline in the query response.\n * Useful for headless agents that need raw structured outputs.\n */\n includeData?: boolean;\n\n /**\n * Persist execution data to Vercel Blob and return a download URL.\n * Useful for large payload workflows where inline JSON is not ideal.\n */\n includeDataUrl?: boolean;\n\n /**\n * Optional idempotency key (UUID recommended).\n * Reuse the same key when retrying the same logical request.\n */\n idempotencyKey?: string;\n}\n\n/**\n * Information about a tool that was used during a query response\n */\nexport interface QueryToolUsage {\n /** Tool ID */\n id: string;\n\n /** Tool name */\n name: string;\n\n /** Number of MCP skill calls made for this tool */\n skillCalls: number;\n}\n\n/**\n * Cost breakdown for a query response.\n * All values are strings representing USD amounts.\n */\nexport interface QueryCost {\n /** AI model inference cost */\n modelCostUsd: string;\n\n /** Sum of all tool fees */\n toolCostUsd: string;\n\n /** Total cost (model + tools) */\n totalCostUsd: string;\n}\n\n/**\n * The resolved result of a pay-per-response query\n */\nexport interface QueryResult {\n /** The AI-synthesized response text */\n response: string;\n\n /** Tools that were used to answer the query */\n toolsUsed: QueryToolUsage[];\n\n /** Cost breakdown */\n cost: QueryCost;\n\n /** Total duration in milliseconds */\n durationMs: number;\n\n /** Optional execution data from tools (when includeData=true) */\n data?: unknown;\n\n /** Optional blob URL for persisted execution data (when includeDataUrl=true) */\n dataUrl?: string;\n}\n\n/**\n * Successful response from the /api/v1/query endpoint\n */\nexport interface QueryApiSuccessResponse {\n success: true;\n response: string;\n toolsUsed: QueryToolUsage[];\n cost: QueryCost;\n durationMs: number;\n data?: unknown;\n dataUrl?: string;\n}\n\n/**\n * Raw API response from the query endpoint\n */\nexport type QueryApiResponse = QueryApiSuccessResponse | ExecuteApiErrorResponse;\n\n// ---------------------------------------------------------------------------\n// Query stream event types\n// ---------------------------------------------------------------------------\n\n/** Emitted when a tool starts or changes execution status */\nexport interface QueryStreamToolStatusEvent {\n type: \"tool-status\";\n tool: { id: string; name: string };\n status: string;\n}\n\n/** Emitted for each chunk of the AI response text */\nexport interface QueryStreamTextDeltaEvent {\n type: \"text-delta\";\n delta: string;\n}\n\n/** Emitted when the full response is complete */\nexport interface QueryStreamDoneEvent {\n type: \"done\";\n result: QueryResult;\n}\n\n/**\n * Union of all events emitted during a streaming query\n */\nexport type QueryStreamEvent =\n | QueryStreamToolStatusEvent\n | QueryStreamTextDeltaEvent\n | QueryStreamDoneEvent;\n\n// ---------------------------------------------------------------------------\n// Error types\n// ---------------------------------------------------------------------------\n\n/**\n * Specific error codes returned by the Context Protocol API\n */\nexport type ContextErrorCode =\n | \"unauthorized\"\n | \"no_wallet\"\n | \"insufficient_allowance\"\n | \"payment_failed\"\n | \"execution_failed\"\n | \"query_failed\"\n | \"invalid_tool_method\"\n | \"method_not_execute_eligible\"\n | \"invalid_max_spend\"\n | \"session_not_found\"\n | \"session_forbidden\"\n | \"session_closed\"\n | \"session_expired\"\n | \"max_spend_mismatch\"\n | \"session_budget_exceeded\";\n\n/**\n * Error thrown by the Context Protocol client\n */\nexport class ContextError extends Error {\n constructor(\n message: string,\n public readonly code?: ContextErrorCode | string,\n public readonly statusCode?: number,\n public readonly helpUrl?: string\n ) {\n super(message);\n this.name = \"ContextError\";\n Object.setPrototypeOf(this, ContextError.prototype);\n }\n}\n","import type { SearchOptions, SearchResponse, Tool } from \"../types.js\";\nimport type { ContextClient } from \"../client.js\";\n\n/**\n * Discovery resource for searching and finding tools on the Context Protocol marketplace\n */\nexport class Discovery {\n constructor(private client: ContextClient) {}\n\n /**\n * Search for tools matching a query string.\n *\n * Backward-compatible signatures:\n * - `search(\"gas prices\", 10)`\n * - `search({ query: \"gas prices\", limit: 10, mode: \"execute\" })`\n */\n async search(query: string, limit?: number): Promise<Tool[]>;\n async search(options: SearchOptions): Promise<Tool[]>;\n async search(\n queryOrOptions: string | SearchOptions,\n limit?: number\n ): Promise<Tool[]> {\n const options: SearchOptions =\n typeof queryOrOptions === \"string\"\n ? { query: queryOrOptions, limit }\n : queryOrOptions;\n\n const params = new URLSearchParams();\n const query = options.query ?? \"\";\n\n if (query) {\n params.set(\"q\", query);\n }\n\n if (options.limit !== undefined) {\n params.set(\"limit\", String(options.limit));\n }\n\n if (options.mode) {\n params.set(\"mode\", options.mode);\n }\n\n if (options.surface) {\n params.set(\"surface\", options.surface);\n }\n\n if (options.queryEligible !== undefined) {\n params.set(\"queryEligible\", String(options.queryEligible));\n }\n\n if (options.requireExecutePricing !== undefined) {\n params.set(\n \"requireExecutePricing\",\n String(options.requireExecutePricing)\n );\n }\n\n if (\n options.excludeLatencyClasses &&\n options.excludeLatencyClasses.length > 0\n ) {\n params.set(\"excludeLatency\", options.excludeLatencyClasses.join(\",\"));\n }\n\n if (options.excludeSlow !== undefined) {\n params.set(\"excludeSlow\", String(options.excludeSlow));\n }\n\n const queryString = params.toString();\n const endpoint = `/api/v1/tools/search${queryString ? `?${queryString}` : \"\"}`;\n\n const response = await this.client._fetch<SearchResponse>(endpoint);\n\n return response.tools;\n }\n\n /**\n * Get featured/popular tools (empty query search)\n *\n * @param limit - Maximum number of results (1-50, default 10)\n * @returns Array of featured tools\n *\n * @example\n * ```typescript\n * const featured = await client.discovery.getFeatured(5);\n * ```\n */\n async getFeatured(\n limit?: number,\n options?: Omit<SearchOptions, \"query\" | \"limit\">\n ): Promise<Tool[]> {\n return this.search({\n ...(options ?? {}),\n query: \"\",\n ...(limit !== undefined ? { limit } : {}),\n });\n }\n}\n","import type {\n ExecuteOptions,\n ExecuteApiResponse,\n ExecuteSessionApiResponse,\n ExecuteSessionResult,\n ExecuteSessionStartOptions,\n ExecutionResult,\n} from \"../types.js\";\nimport { ContextError } from \"../types.js\";\nimport type { ContextClient } from \"../client.js\";\n\n/**\n * Tools resource for executing tools on the Context Protocol marketplace\n */\nexport class Tools {\n constructor(private client: ContextClient) {}\n\n /**\n * Execute a tool with the provided arguments\n *\n * @param options - Execution options\n * @param options.toolId - The UUID of the tool (from search results)\n * @param options.toolName - The specific MCP tool method to call (from tool's mcpTools array)\n * @param options.args - Arguments to pass to the tool\n * @returns The execution result with the tool's output data\n *\n * @throws {ContextError} With code `no_wallet` if wallet not set up\n * @throws {ContextError} With code `insufficient_allowance` if spending cap not set\n * @throws {ContextError} With code `payment_failed` if payment settlement fails\n * @throws {ContextError} With code `execution_failed` if tool execution fails\n *\n * @example\n * ```typescript\n * // First, search for a tool\n * const tools = await client.discovery.search(\"gas prices\");\n * const tool = tools[0];\n *\n * // Execute a specific method from the tool's mcpTools\n * const result = await client.tools.execute({\n * toolId: tool.id,\n * toolName: tool.mcpTools[0].name, // e.g., \"get_gas_prices\"\n * args: { chainId: 1 }\n * });\n *\n * console.log(result.result); // The tool's output\n * console.log(result.durationMs); // Execution time\n * ```\n */\n async execute<T = unknown>(options: ExecuteOptions): Promise<ExecutionResult<T>> {\n const {\n toolId,\n toolName,\n args,\n idempotencyKey,\n mode,\n sessionId,\n maxSpendUsd,\n closeSession,\n } = options;\n const headers = idempotencyKey\n ? { \"Idempotency-Key\": idempotencyKey }\n : undefined;\n\n const response = await this.client._fetch<ExecuteApiResponse>(\n \"/api/v1/tools/execute\",\n {\n method: \"POST\",\n headers,\n body: JSON.stringify({\n toolId,\n toolName,\n args,\n mode: mode ?? \"execute\",\n sessionId,\n maxSpendUsd,\n closeSession,\n }),\n }\n );\n\n // Handle error response\n if (\"error\" in response) {\n throw new ContextError(\n response.error,\n response.code,\n undefined, // Don't hardcode - this was a 200 OK with error body\n response.helpUrl\n );\n }\n\n // Handle success response\n if (response.success) {\n return {\n mode: response.mode,\n result: response.result as T,\n tool: response.tool,\n method: response.method,\n session: response.session,\n durationMs: response.durationMs,\n };\n }\n\n // Fallback - shouldn't reach here with valid API responses\n throw new ContextError(\"Unexpected response format from API\");\n }\n\n /**\n * Start an execute session with a max spend budget.\n */\n async startSession(\n options: ExecuteSessionStartOptions\n ): Promise<ExecuteSessionResult> {\n const response = await this.client._fetch<ExecuteSessionApiResponse>(\n \"/api/v1/tools/execute/sessions\",\n {\n method: \"POST\",\n body: JSON.stringify({\n mode: \"execute\",\n maxSpendUsd: options.maxSpendUsd,\n }),\n }\n );\n\n return this.resolveSessionLifecycleResponse(response);\n }\n\n /**\n * Fetch current execute session status by ID.\n */\n async getSession(sessionId: string): Promise<ExecuteSessionResult> {\n if (!sessionId) {\n throw new ContextError(\"sessionId is required\");\n }\n\n const encodedSessionId = encodeURIComponent(sessionId);\n const response = await this.client._fetch<ExecuteSessionApiResponse>(\n `/api/v1/tools/execute/sessions/${encodedSessionId}`\n );\n\n return this.resolveSessionLifecycleResponse(response);\n }\n\n /**\n * Close an execute session by ID.\n */\n async closeSession(sessionId: string): Promise<ExecuteSessionResult> {\n if (!sessionId) {\n throw new ContextError(\"sessionId is required\");\n }\n\n const encodedSessionId = encodeURIComponent(sessionId);\n const response = await this.client._fetch<ExecuteSessionApiResponse>(\n `/api/v1/tools/execute/sessions/${encodedSessionId}/close`,\n {\n method: \"POST\",\n body: JSON.stringify({ mode: \"execute\" }),\n }\n );\n\n return this.resolveSessionLifecycleResponse(response);\n }\n\n private resolveSessionLifecycleResponse(\n response: ExecuteSessionApiResponse\n ): ExecuteSessionResult {\n if (\"error\" in response) {\n throw new ContextError(\n response.error,\n response.code,\n undefined,\n response.helpUrl\n );\n }\n\n if (response.success) {\n return {\n mode: response.mode,\n session: response.session,\n };\n }\n\n throw new ContextError(\"Unexpected response format from API\");\n }\n}\n","import type {\n QueryOptions,\n QueryApiResponse,\n QueryResult,\n QueryStreamEvent,\n} from \"../types.js\";\nimport { ContextError } from \"../types.js\";\nimport type { ContextClient } from \"../client.js\";\n\n/**\n * Query resource for pay-per-response agentic queries.\n *\n * Unlike `tools.execute()` which calls a single tool once (pay-per-request),\n * the Query resource sends a natural-language question and lets the server\n * handle tool discovery, multi-tool orchestration, self-healing retries,\n * completeness checks, and AI synthesis — all for one flat fee.\n *\n * This is the \"prepared meal\" vs \"raw ingredients\" distinction:\n * - `tools.execute()` = raw data, full control, predictable cost\n * - `query.run()` / `query.stream()` = curated intelligence, one payment\n */\nexport class Query {\n constructor(private client: ContextClient) {}\n\n /**\n * Run an agentic query and wait for the full response.\n *\n * The server discovers relevant tools (or uses the ones you specify),\n * executes the full agentic pipeline (up to 100 MCP calls per tool),\n * and returns an AI-synthesized answer. Payment is settled after\n * successful execution via deferred settlement.\n *\n * @param options - Query options or a plain string question\n * @returns The complete query result with response text, tools used, and cost\n *\n * @throws {ContextError} With code `no_wallet` if wallet not set up\n * @throws {ContextError} With code `insufficient_allowance` if spending cap not set\n * @throws {ContextError} With code `payment_failed` if payment settlement fails\n * @throws {ContextError} With code `execution_failed` if the agentic pipeline fails\n *\n * @example\n * ```typescript\n * // Simple question — server discovers tools automatically\n * const answer = await client.query.run(\"What are the top whale movements on Base?\");\n * console.log(answer.response); // AI-synthesized answer\n * console.log(answer.toolsUsed); // Which tools were used\n * console.log(answer.cost); // Cost breakdown\n *\n * // With specific tools (Manual Mode)\n * const answer = await client.query.run({\n * query: \"Analyze whale activity\",\n * tools: [\"tool-uuid-1\", \"tool-uuid-2\"],\n * });\n * ```\n */\n async run(options: QueryOptions | string): Promise<QueryResult> {\n const opts = typeof options === \"string\" ? { query: options } : options;\n const headers = opts.idempotencyKey\n ? { \"Idempotency-Key\": opts.idempotencyKey }\n : undefined;\n\n const response = await this.client._fetch<QueryApiResponse>(\n \"/api/v1/query\",\n {\n method: \"POST\",\n headers,\n body: JSON.stringify({\n query: opts.query,\n tools: opts.tools,\n modelId: opts.modelId,\n includeData: opts.includeData,\n includeDataUrl: opts.includeDataUrl,\n stream: false,\n }),\n }\n );\n\n // Handle error response\n if (\"error\" in response) {\n throw new ContextError(\n response.error,\n response.code,\n undefined,\n response.helpUrl\n );\n }\n\n // Handle success response\n if (response.success) {\n return {\n response: response.response,\n toolsUsed: response.toolsUsed,\n cost: response.cost,\n durationMs: response.durationMs,\n data: response.data,\n dataUrl: response.dataUrl,\n };\n }\n\n throw new ContextError(\"Unexpected response format from query API\");\n }\n\n /**\n * Run an agentic query with streaming. Returns an async iterable that\n * yields events as the server processes the query in real-time.\n *\n * Event types:\n * - `tool-status` — A tool started executing or changed status\n * - `text-delta` — A chunk of the AI response text\n * - `done` — The full response is complete (includes final `QueryResult`)\n *\n * @param options - Query options or a plain string question\n * @returns An async iterable of stream events\n *\n * @example\n * ```typescript\n * for await (const event of client.query.stream(\"What are the top whale movements?\")) {\n * switch (event.type) {\n * case \"tool-status\":\n * console.log(`Tool ${event.tool.name}: ${event.status}`);\n * break;\n * case \"text-delta\":\n * process.stdout.write(event.delta);\n * break;\n * case \"done\":\n * console.log(\"\\nCost:\", event.result.cost.totalCostUsd);\n * break;\n * }\n * }\n * ```\n */\n async *stream(\n options: QueryOptions | string\n ): AsyncGenerator<QueryStreamEvent> {\n const opts = typeof options === \"string\" ? { query: options } : options;\n const headers = opts.idempotencyKey\n ? { \"Idempotency-Key\": opts.idempotencyKey }\n : undefined;\n\n const response = await this.client._fetchRaw(\"/api/v1/query\", {\n method: \"POST\",\n headers,\n body: JSON.stringify({\n query: opts.query,\n tools: opts.tools,\n modelId: opts.modelId,\n includeData: opts.includeData,\n includeDataUrl: opts.includeDataUrl,\n stream: true,\n }),\n });\n\n const body = response.body;\n if (!body) {\n throw new ContextError(\"No response body for streaming query\");\n }\n\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n const trimmed = line.trim();\n if (trimmed.startsWith(\"data: \")) {\n const data = trimmed.slice(6);\n if (data === \"[DONE]\") return;\n try {\n yield JSON.parse(data) as QueryStreamEvent;\n } catch {\n // Skip malformed SSE events\n }\n }\n }\n }\n\n // Process any remaining buffer\n if (buffer.trim().startsWith(\"data: \")) {\n const data = buffer.trim().slice(6);\n if (data !== \"[DONE]\") {\n try {\n yield JSON.parse(data) as QueryStreamEvent;\n } catch {\n // Skip malformed SSE events\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n }\n}\n","import type { ContextClientOptions } from \"./types.js\";\nimport { ContextError } from \"./types.js\";\nimport { Discovery } from \"./resources/discovery.js\";\nimport { Tools } from \"./resources/tools.js\";\nimport { Query } from \"./resources/query.js\";\n\n/**\n * The official TypeScript client for the Context Protocol.\n *\n * Use this client to discover and execute AI tools programmatically.\n *\n * @example\n * ```typescript\n * import { ContextClient } from \"@contextprotocol/client\";\n *\n * const client = new ContextClient({\n * apiKey: \"sk_live_...\"\n * });\n *\n * // Pay-per-request: Execute a specific tool\n * const result = await client.tools.execute({\n * toolId: \"tool-uuid\",\n * toolName: \"get_gas_prices\",\n * args: { chainId: 1 }\n * });\n *\n * // Pay-per-response: Ask a question, get a curated answer\n * const answer = await client.query.run(\"What are the top whale movements on Base?\");\n * console.log(answer.response);\n * ```\n */\nexport class ContextClient {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n private _closed = false;\n\n /**\n * Discovery resource for searching tools\n */\n public readonly discovery: Discovery;\n\n /**\n * Tools resource for executing tools (pay-per-request)\n */\n public readonly tools: Tools;\n\n /**\n * Query resource for agentic queries (pay-per-response).\n *\n * Unlike `tools.execute()` which calls a single tool once, `query` sends\n * a natural-language question and lets the server handle tool discovery,\n * multi-tool orchestration, self-healing, and AI synthesis — one flat fee.\n */\n public readonly query: Query;\n\n /**\n * Creates a new Context Protocol client\n *\n * @param options - Client configuration options\n * @param options.apiKey - Your Context Protocol API key (format: sk_live_...)\n * @param options.baseUrl - Optional base URL override (defaults to https://ctxprotocol.com)\n */\n constructor(options: ContextClientOptions) {\n if (!options.apiKey) {\n throw new ContextError(\"API key is required\");\n }\n\n this.apiKey = options.apiKey;\n this.baseUrl = (options.baseUrl ?? \"https://ctxprotocol.com\").replace(/\\/$/, \"\");\n\n // Initialize resources\n this.discovery = new Discovery(this);\n this.tools = new Tools(this);\n this.query = new Query(this);\n }\n\n /**\n * Close the client and clean up resources.\n * After calling close(), any in-flight requests may be aborted.\n */\n close(): void {\n this._closed = true;\n }\n\n /**\n * Internal method for making authenticated HTTP requests\n * Includes timeout (30s) and retry with exponential backoff for transient errors\n *\n * @internal\n */\n async _fetch<T>(endpoint: string, options: RequestInit = {}): Promise<T> {\n if (this._closed) {\n throw new ContextError(\"Client has been closed\");\n }\n\n const url = `${this.baseUrl}${endpoint}`;\n const maxRetries = 3;\n const timeoutMs = 30_000;\n\n let lastError: Error | undefined;\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), timeoutMs);\n\n try {\n const response = await fetch(url, {\n ...options,\n signal: controller.signal,\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.apiKey}`,\n ...options.headers,\n },\n });\n\n clearTimeout(timeout);\n\n if (!response.ok) {\n // Retry on 5xx server errors\n if (response.status >= 500 && attempt < maxRetries) {\n const delay = Math.min(1000 * 2 ** attempt, 10_000);\n await new Promise((resolve) => setTimeout(resolve, delay));\n continue;\n }\n\n let errorMessage = `HTTP ${response.status}: ${response.statusText}`;\n let errorCode: string | undefined;\n let helpUrl: string | undefined;\n\n try {\n const errorBody = await response.json();\n if (errorBody.error) {\n errorMessage = errorBody.error;\n errorCode = errorBody.code;\n helpUrl = errorBody.helpUrl;\n }\n } catch {\n // Use default error message if JSON parsing fails\n }\n\n throw new ContextError(errorMessage, errorCode, response.status, helpUrl);\n }\n\n return response.json() as Promise<T>;\n } catch (error) {\n clearTimeout(timeout);\n\n if (error instanceof ContextError) {\n throw error;\n }\n\n lastError = error instanceof Error ? error : new Error(String(error));\n\n // Retry on network errors and timeouts\n const isRetryable =\n lastError.name === \"AbortError\" ||\n lastError.message.includes(\"fetch failed\") ||\n lastError.message.includes(\"ECONNRESET\") ||\n lastError.message.includes(\"ETIMEDOUT\");\n\n if (isRetryable && attempt < maxRetries) {\n const delay = Math.min(1000 * 2 ** attempt, 10_000);\n await new Promise((resolve) => setTimeout(resolve, delay));\n continue;\n }\n\n if (lastError.name === \"AbortError\") {\n throw new ContextError(\n `Request timed out after ${timeoutMs / 1000}s`,\n undefined,\n 408\n );\n }\n\n throw new ContextError(\n lastError.message,\n undefined,\n undefined\n );\n }\n }\n\n throw lastError ?? new ContextError(\"Request failed after retries\");\n }\n\n /**\n * Internal method for making authenticated HTTP requests that returns\n * the raw Response object. Used for streaming endpoints (SSE).\n *\n * @internal\n */\n async _fetchRaw(endpoint: string, options: RequestInit = {}): Promise<Response> {\n if (this._closed) {\n throw new ContextError(\"Client has been closed\");\n }\n\n const url = `${this.baseUrl}${endpoint}`;\n\n const response = await fetch(url, {\n ...options,\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.apiKey}`,\n ...options.headers,\n },\n });\n\n if (!response.ok) {\n let errorMessage = `HTTP ${response.status}: ${response.statusText}`;\n let errorCode: string | undefined;\n let helpUrl: string | undefined;\n\n try {\n const errorBody = await response.json();\n if (errorBody.error) {\n errorMessage = errorBody.error;\n errorCode = errorBody.code;\n helpUrl = errorBody.helpUrl;\n }\n } catch {\n // Use default error message if JSON parsing fails\n }\n\n throw new ContextError(errorMessage, errorCode, response.status, helpUrl);\n }\n\n return response;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/client/types.ts","../../src/client/resources/discovery.ts","../../src/client/resources/tools.ts","../../src/client/resources/query.ts","../../src/client/client.ts"],"names":[],"mappings":";;;AAqkBO,IAAM,YAAA,GAAN,MAAM,aAAA,SAAqB,KAAA,CAAM;AAAA,EACtC,WAAA,CACE,OAAA,EACgB,IAAA,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AAM,MAAA,CAAO,KAAK,CAAC,CAAA;AAC1E,MAAA,IAAI,SAAA,CAAU,SAAS,YAAA,EAAc;AACnC,QAAA,MAAM,IAAI,YAAA;AAAA,UACR,CAAA,kCAAA,EAAqC,IAAA,CAAK,eAAA,GAAkB,GAAI,CAAA,CAAA,CAAA;AAAA,UAChE,MAAA;AAAA,UACA;AAAA,SACF;AAAA,MACF;AACA,MAAA,MAAM,IAAI,YAAA,CAAa,SAAA,CAAU,OAAO,CAAA;AAAA,IAC1C;AAEA,IAAA,YAAA,CAAa,OAAO,CAAA;AAEpB,IAAA,IAAI,CAAC,SAAS,EAAA,EAAI;AAChB,MAAA,IAAI,eAAe,CAAA,KAAA,EAAQ,QAAA,CAAS,MAAM,CAAA,EAAA,EAAK,SAAS,UAAU,CAAA,CAAA;AAClE,MAAA,IAAI,SAAA;AACJ,MAAA,IAAI,OAAA;AAEJ,MAAA,IAAI;AACF,QAAA,MAAM,SAAA,GAAY,MAAM,QAAA,CAAS,IAAA,EAAK;AACtC,QAAA,IAAI,UAAU,KAAA,EAAO;AACnB,UAAA,YAAA,GAAe,SAAA,CAAU,KAAA;AACzB,UAAA,SAAA,GAAY,SAAA,CAAU,IAAA;AACtB,UAAA,OAAA,GAAU,SAAA,CAAU,OAAA;AAAA,QACtB;AAAA,MACF,CAAA,CAAA,MAAQ;AAAA,MAER;AAEA,MAAA,MAAM,IAAI,YAAA,CAAa,YAAA,EAAc,SAAA,EAAW,QAAA,CAAS,QAAQ,OAAO,CAAA;AAAA,IAC1E;AAEA,IAAA,OAAO,QAAA;AAAA,EACT;AACF","file":"index.cjs","sourcesContent":["/**\n * Configuration options for initializing the ContextClient\n */\nexport interface ContextClientOptions {\n /**\n * Your Context Protocol API key\n * @example \"sk_live_abc123...\"\n */\n apiKey: string;\n\n /**\n * Base URL for the Context Protocol API\n * @default \"https://www.ctxprotocol.com\"\n */\n baseUrl?: string;\n\n /**\n * Request timeout for non-streaming API calls in milliseconds.\n * @default 300000\n */\n requestTimeoutMs?: number;\n\n /**\n * Request timeout for establishing streaming API calls in milliseconds.\n * @default 600000\n */\n streamTimeoutMs?: number;\n}\n\n/**\n * An individual MCP tool exposed by a tool listing\n */\nexport interface McpToolRateLimitHints {\n /** Suggested request budget for this method */\n maxRequestsPerMinute?: number;\n\n /** Suggested parallel call ceiling for this method */\n maxConcurrency?: number;\n\n /** Suggested minimum delay between sequential calls */\n cooldownMs?: number;\n\n /** Whether this method already supports bulk/batch retrieval */\n supportsBulk?: boolean;\n\n /** Preferred batch-oriented methods to call instead of fan-out loops */\n recommendedBatchTools?: string[];\n\n /** Optional human-readable notes for planning */\n notes?: string;\n}\n\nexport type DiscoveryMode = \"query\" | \"execute\";\nexport type McpToolSurface = \"answer\" | \"execute\" | \"both\";\nexport type McpToolLatencyClass = \"instant\" | \"fast\" | \"slow\" | \"streaming\";\n\nexport interface McpToolPricingMeta {\n executeUsd?: string;\n queryUsd?: string;\n [key: string]: unknown;\n}\n\nexport interface McpToolMeta {\n /** Declared method surface */\n surface?: McpToolSurface;\n\n /** Whether this method can be selected in query mode */\n queryEligible?: boolean;\n\n /** Declared latency class for planner/runtime gating */\n latencyClass?: McpToolLatencyClass;\n\n /** Method-level pricing metadata */\n pricing?: McpToolPricingMeta;\n\n /** Derived discovery flag for execute eligibility */\n executeEligible?: boolean;\n\n /** Derived discovery field for explicit execute pricing visibility */\n executePriceUsd?: string;\n\n /** Context injection requirements handled by the Context runtime */\n contextRequirements?: string[];\n\n /**\n * Optional planner/runtime pacing hints.\n * Tool contributors can publish these to reduce rate-limit failures.\n */\n rateLimit?: McpToolRateLimitHints;\n rateLimitHints?: McpToolRateLimitHints;\n\n /** Flat aliases accepted for convenience */\n maxRequestsPerMinute?: number;\n maxConcurrency?: number;\n cooldownMs?: number;\n supportsBulk?: boolean;\n recommendedBatchTools?: string[];\n notes?: string;\n\n [key: string]: unknown;\n}\n\nexport interface StructuredMethodGuidanceHints {\n /** Suggested call-order sequence extracted from method descriptions */\n callOrderHints?: string[];\n\n /** Parameter usage caveats extracted from method descriptions */\n parameterCaveats?: string[];\n\n /** Edge-case behavior notes extracted from method descriptions */\n edgeCaseNotes?: string[];\n}\n\nexport interface McpTool {\n /** Name of the MCP tool method */\n name: string;\n\n /** Description of what this method does */\n description: string;\n\n /**\n * JSON Schema for the input arguments this tool accepts.\n * Used by LLMs to generate correct arguments.\n */\n inputSchema?: Record<string, unknown>;\n\n /**\n * JSON Schema for the output this tool returns.\n * Used by LLMs to understand the response structure.\n */\n outputSchema?: Record<string, unknown>;\n\n /** MCP metadata extensions (context injection, rate-limit hints) */\n _meta?: McpToolMeta;\n\n /** Explicit execute eligibility in discovery responses */\n executeEligible?: boolean;\n\n /** Explicit execute price visibility in discovery responses */\n executePriceUsd?: string | null;\n\n /** Whether this method has normalized structured guidance hints */\n hasStructuredGuidance?: boolean;\n\n /** Optional structured guidance hints derived from the method description */\n structuredGuidance?: StructuredMethodGuidanceHints;\n}\n\n/**\n * Represents a tool available on the Context Protocol marketplace\n */\nexport interface Tool {\n /** Unique identifier for the tool (UUID) */\n id: string;\n\n /** Human-readable name of the tool */\n name: string;\n\n /** Description of what the tool does */\n description: string;\n\n /** Price per execution in USDC */\n price: string;\n\n /** Tool category (e.g., \"defi\", \"nft\") */\n category?: string;\n\n /** Whether the tool is verified by Context Protocol */\n isVerified?: boolean;\n\n /** Tool type - currently always \"mcp\" */\n kind?: string;\n\n /**\n * Available MCP tool methods\n * Use items from this array as `toolName` when executing\n */\n mcpTools?: McpTool[];\n\n // Trust metrics (Level 2 - Reputation Ledger)\n /** Total number of queries processed */\n totalQueries?: number;\n\n /** Success rate percentage (0-100) */\n successRate?: string;\n\n /** Uptime percentage (0-100) */\n uptimePercent?: string;\n\n /** Total USDC staked by the developer */\n totalStaked?: string;\n\n /** Whether the tool has \"Proven\" status (100+ queries, >95% success, >98% uptime) */\n isProven?: boolean;\n}\n\n/**\n * Response from the tools search endpoint\n */\nexport interface SearchResponse {\n /** Array of matching tools */\n tools: Tool[];\n\n /** Discovery mode used by the server */\n mode?: DiscoveryMode;\n\n /** The search query that was used */\n query: string;\n\n /** Total number of results */\n count: number;\n}\n\n/**\n * Options for searching tools\n */\nexport interface SearchOptions {\n /** Search query (semantic search) */\n query?: string;\n\n /** Maximum number of results (1-50, default 10) */\n limit?: number;\n\n /** Discovery mode with billing semantics */\n mode?: DiscoveryMode;\n\n /** Optional explicit method surface filter */\n surface?: McpToolSurface;\n\n /** Require methods marked query eligible */\n queryEligible?: boolean;\n\n /** Require explicit method execute pricing */\n requireExecutePricing?: boolean;\n\n /** Exclude methods by latency class */\n excludeLatencyClasses?: McpToolLatencyClass[];\n\n /** Convenience switch to exclude slow methods in query mode */\n excludeSlow?: boolean;\n}\n\n/**\n * Options for executing a tool\n */\nexport interface ExecuteOptions {\n /** The UUID of the tool to execute (from search results) */\n toolId: string;\n\n /** The specific MCP tool name to call (from tool's mcpTools array) */\n toolName: string;\n\n /** Arguments to pass to the tool */\n args?: Record<string, unknown>;\n\n /**\n * Optional idempotency key (UUID recommended).\n * Reuse the same key when retrying the same logical request.\n */\n idempotencyKey?: string;\n\n /** Explicit execute mode label for request clarity */\n mode?: \"execute\";\n\n /** Optional execute session identifier */\n sessionId?: string;\n\n /** Optional per-session spend budget envelope (USD) */\n maxSpendUsd?: string;\n\n /** Request session closure after this execute call settles */\n closeSession?: boolean;\n}\n\nexport type ExecuteSessionStatus = \"open\" | \"closed\" | \"expired\";\n\nexport interface ExecuteSessionSpend {\n mode: \"execute\";\n sessionId: string | null;\n methodPrice: string;\n spent: string;\n remaining: string | null;\n maxSpend: string | null;\n\n /** Optional lifecycle fields when the API returns session state */\n status?: ExecuteSessionStatus;\n expiresAt?: string;\n closeRequested?: boolean;\n pendingAccruedCount?: number;\n pendingAccruedUsd?: string;\n}\n\n/**\n * Successful execution response from the API\n */\nexport interface ExecuteApiSuccessResponse {\n success: true;\n mode: \"execute\";\n\n /** The result data from the tool execution */\n result: unknown;\n\n /** Information about the executed tool */\n tool: {\n id: string;\n name: string;\n };\n\n /** Method-level execute pricing used for this call */\n method: {\n name: string;\n executePriceUsd: string;\n };\n\n /** Spend envelope visibility for execute sessions */\n session: ExecuteSessionSpend;\n\n /** Execution duration in milliseconds */\n durationMs: number;\n}\n\n/**\n * Error response from the API\n */\nexport interface ExecuteApiErrorResponse {\n /** Human-readable error message */\n error: string;\n\n /** Explicit mode label for clarity */\n mode?: \"execute\";\n\n /** Error code for programmatic handling */\n code?: ContextErrorCode;\n\n /** URL to help resolve the issue */\n helpUrl?: string;\n\n /** Optional spend envelope context when available */\n session?: ExecuteSessionSpend;\n}\n\n/**\n * Raw API response from the execute endpoint\n */\nexport type ExecuteApiResponse = ExecuteApiSuccessResponse | ExecuteApiErrorResponse;\n\nexport interface ExecuteSessionStartOptions {\n /** Maximum spend budget for the session (USD string) */\n maxSpendUsd: string;\n}\n\nexport interface ExecuteSessionApiSuccessResponse {\n success: true;\n mode: \"execute\";\n session: ExecuteSessionSpend;\n}\n\nexport type ExecuteSessionApiResponse =\n | ExecuteSessionApiSuccessResponse\n | ExecuteApiErrorResponse;\n\nexport interface ExecuteSessionResult {\n mode: \"execute\";\n session: ExecuteSessionSpend;\n}\n\n/**\n * The resolved result returned to the user after SDK processing\n */\nexport interface ExecutionResult<T = unknown> {\n mode: \"execute\";\n\n /** The data returned by the tool */\n result: T;\n\n /** Information about the executed tool */\n tool: {\n id: string;\n name: string;\n };\n\n /** Method-level execute pricing used for this call */\n method: {\n name: string;\n executePriceUsd: string;\n };\n\n /** Spend envelope visibility for execute calls */\n session: ExecuteSessionSpend;\n\n /** Execution duration in milliseconds */\n durationMs: number;\n}\n\n// ---------------------------------------------------------------------------\n// Query types (pay-per-response / agentic mode)\n// ---------------------------------------------------------------------------\n\n/** Supported orchestration depth modes for query execution. */\nexport type QueryDepth = \"fast\" | \"auto\" | \"deep\";\n\n/**\n * Options for the agentic query endpoint (pay-per-response).\n *\n * Unlike `execute()` which calls a single tool once, `query()` sends a\n * natural-language question and lets the server handle tool discovery,\n * multi-tool orchestration, self-healing retries, and AI synthesis.\n * One flat fee covers up to 100 MCP skill calls per tool.\n */\nexport interface QueryOptions {\n /** The natural-language question to answer */\n query: string;\n\n /**\n * Optional tool IDs to use. When omitted the server discovers tools\n * automatically (Auto Mode). When provided, only these tools are used\n * (Manual Mode).\n */\n tools?: string[];\n\n /**\n * Optional model ID for query orchestration/synthesis.\n * Supported IDs are published by the Context API.\n */\n modelId?: string;\n\n /**\n * Include execution data inline in the query response.\n * Useful for headless agents that need raw structured outputs.\n */\n includeData?: boolean;\n\n /**\n * Persist execution data to Vercel Blob and return a download URL.\n * Useful for large payload workflows where inline JSON is not ideal.\n */\n includeDataUrl?: boolean;\n\n /**\n * Query orchestration depth mode:\n * - `fast`: lower-latency path\n * - `auto`: server decides between fast/deep\n * - `deep`: full completeness-oriented path\n */\n queryDepth?: QueryDepth;\n\n /**\n * Optional idempotency key (UUID recommended).\n * Reuse the same key when retrying the same logical request.\n */\n idempotencyKey?: string;\n}\n\n/**\n * Information about a tool that was used during a query response\n */\nexport interface QueryToolUsage {\n /** Tool ID */\n id: string;\n\n /** Tool name */\n name: string;\n\n /** Number of MCP skill calls made for this tool */\n skillCalls: number;\n}\n\n/**\n * Cost breakdown for a query response.\n * All values are strings representing USD amounts.\n */\nexport interface QueryCost {\n /** AI model inference cost */\n modelCostUsd: string;\n\n /** Sum of all tool fees */\n toolCostUsd: string;\n\n /** Total cost (model + tools) */\n totalCostUsd: string;\n}\n\n/**\n * The resolved result of a pay-per-response query\n */\nexport interface QueryResult {\n /** The AI-synthesized response text */\n response: string;\n\n /** Tools that were used to answer the query */\n toolsUsed: QueryToolUsage[];\n\n /** Cost breakdown */\n cost: QueryCost;\n\n /** Total duration in milliseconds */\n durationMs: number;\n\n /** Optional execution data from tools (when includeData=true) */\n data?: unknown;\n\n /** Optional blob URL for persisted execution data (when includeDataUrl=true) */\n dataUrl?: string;\n}\n\n/**\n * Successful response from the /api/v1/query endpoint\n */\nexport interface QueryApiSuccessResponse {\n success: true;\n response: string;\n toolsUsed: QueryToolUsage[];\n cost: QueryCost;\n durationMs: number;\n data?: unknown;\n dataUrl?: string;\n}\n\n/**\n * Raw API response from the query endpoint\n */\nexport type QueryApiResponse = QueryApiSuccessResponse | ExecuteApiErrorResponse;\n\n// ---------------------------------------------------------------------------\n// Query stream event types\n// ---------------------------------------------------------------------------\n\n/** Emitted when a tool starts or changes execution status */\nexport interface QueryStreamToolStatusEvent {\n type: \"tool-status\";\n tool: { id: string; name: string };\n status: string;\n}\n\n/** Emitted for each chunk of the AI response text */\nexport interface QueryStreamTextDeltaEvent {\n type: \"text-delta\";\n delta: string;\n}\n\n/** Emitted when the full response is complete */\nexport interface QueryStreamDoneEvent {\n type: \"done\";\n result: QueryResult;\n}\n\n/**\n * Union of all events emitted during a streaming query\n */\nexport type QueryStreamEvent =\n | QueryStreamToolStatusEvent\n | QueryStreamTextDeltaEvent\n | QueryStreamDoneEvent;\n\n// ---------------------------------------------------------------------------\n// Error types\n// ---------------------------------------------------------------------------\n\n/**\n * Specific error codes returned by the Context Protocol API\n */\nexport type ContextErrorCode =\n | \"unauthorized\"\n | \"no_wallet\"\n | \"insufficient_allowance\"\n | \"payment_failed\"\n | \"execution_failed\"\n | \"query_failed\"\n | \"invalid_tool_method\"\n | \"method_not_execute_eligible\"\n | \"invalid_max_spend\"\n | \"session_not_found\"\n | \"session_forbidden\"\n | \"session_closed\"\n | \"session_expired\"\n | \"max_spend_mismatch\"\n | \"session_budget_exceeded\";\n\n/**\n * Error thrown by the Context Protocol client\n */\nexport class ContextError extends Error {\n constructor(\n message: string,\n public readonly code?: ContextErrorCode | string,\n public readonly statusCode?: number,\n public readonly helpUrl?: string\n ) {\n super(message);\n this.name = \"ContextError\";\n Object.setPrototypeOf(this, ContextError.prototype);\n }\n}\n","import type { SearchOptions, SearchResponse, Tool } from \"../types.js\";\nimport type { ContextClient } from \"../client.js\";\n\n/**\n * Discovery resource for searching and finding tools on the Context Protocol marketplace\n */\nexport class Discovery {\n constructor(private client: ContextClient) {}\n\n /**\n * Search for tools matching a query string.\n *\n * Backward-compatible signatures:\n * - `search(\"gas prices\", 10)`\n * - `search({ query: \"gas prices\", limit: 10, mode: \"execute\" })`\n */\n async search(query: string, limit?: number): Promise<Tool[]>;\n async search(options: SearchOptions): Promise<Tool[]>;\n async search(\n queryOrOptions: string | SearchOptions,\n limit?: number\n ): Promise<Tool[]> {\n const options: SearchOptions =\n typeof queryOrOptions === \"string\"\n ? { query: queryOrOptions, limit }\n : queryOrOptions;\n\n const params = new URLSearchParams();\n const query = options.query ?? \"\";\n\n if (query) {\n params.set(\"q\", query);\n }\n\n if (options.limit !== undefined) {\n params.set(\"limit\", String(options.limit));\n }\n\n if (options.mode) {\n params.set(\"mode\", options.mode);\n }\n\n if (options.surface) {\n params.set(\"surface\", options.surface);\n }\n\n if (options.queryEligible !== undefined) {\n params.set(\"queryEligible\", String(options.queryEligible));\n }\n\n if (options.requireExecutePricing !== undefined) {\n params.set(\n \"requireExecutePricing\",\n String(options.requireExecutePricing)\n );\n }\n\n if (\n options.excludeLatencyClasses &&\n options.excludeLatencyClasses.length > 0\n ) {\n params.set(\"excludeLatency\", options.excludeLatencyClasses.join(\",\"));\n }\n\n if (options.excludeSlow !== undefined) {\n params.set(\"excludeSlow\", String(options.excludeSlow));\n }\n\n const queryString = params.toString();\n const endpoint = `/api/v1/tools/search${queryString ? `?${queryString}` : \"\"}`;\n\n const response = await this.client._fetch<SearchResponse>(endpoint);\n\n return response.tools;\n }\n\n /**\n * Get featured/popular tools (empty query search)\n *\n * @param limit - Maximum number of results (1-50, default 10)\n * @returns Array of featured tools\n *\n * @example\n * ```typescript\n * const featured = await client.discovery.getFeatured(5);\n * ```\n */\n async getFeatured(\n limit?: number,\n options?: Omit<SearchOptions, \"query\" | \"limit\">\n ): Promise<Tool[]> {\n return this.search({\n ...(options ?? {}),\n query: \"\",\n ...(limit !== undefined ? { limit } : {}),\n });\n }\n}\n","import type {\n ExecuteOptions,\n ExecuteApiResponse,\n ExecuteSessionApiResponse,\n ExecuteSessionResult,\n ExecuteSessionStartOptions,\n ExecutionResult,\n} from \"../types.js\";\nimport { ContextError } from \"../types.js\";\nimport type { ContextClient } from \"../client.js\";\n\n/**\n * Tools resource for executing tools on the Context Protocol marketplace\n */\nexport class Tools {\n constructor(private client: ContextClient) {}\n\n /**\n * Execute a tool with the provided arguments\n *\n * @param options - Execution options\n * @param options.toolId - The UUID of the tool (from search results)\n * @param options.toolName - The specific MCP tool method to call (from tool's mcpTools array)\n * @param options.args - Arguments to pass to the tool\n * @returns The execution result with the tool's output data\n *\n * @throws {ContextError} With code `no_wallet` if wallet not set up\n * @throws {ContextError} With code `insufficient_allowance` if spending cap not set\n * @throws {ContextError} With code `payment_failed` if payment settlement fails\n * @throws {ContextError} With code `execution_failed` if tool execution fails\n *\n * @example\n * ```typescript\n * // First, search for a tool\n * const tools = await client.discovery.search(\"gas prices\");\n * const tool = tools[0];\n *\n * // Execute a specific method from the tool's mcpTools\n * const result = await client.tools.execute({\n * toolId: tool.id,\n * toolName: tool.mcpTools[0].name, // e.g., \"get_gas_prices\"\n * args: { chainId: 1 }\n * });\n *\n * console.log(result.result); // The tool's output\n * console.log(result.durationMs); // Execution time\n * ```\n */\n async execute<T = unknown>(options: ExecuteOptions): Promise<ExecutionResult<T>> {\n const {\n toolId,\n toolName,\n args,\n idempotencyKey,\n mode,\n sessionId,\n maxSpendUsd,\n closeSession,\n } = options;\n const headers = idempotencyKey\n ? { \"Idempotency-Key\": idempotencyKey }\n : undefined;\n\n const response = await this.client._fetch<ExecuteApiResponse>(\n \"/api/v1/tools/execute\",\n {\n method: \"POST\",\n headers,\n body: JSON.stringify({\n toolId,\n toolName,\n args,\n mode: mode ?? \"execute\",\n sessionId,\n maxSpendUsd,\n closeSession,\n }),\n }\n );\n\n // Handle error response\n if (\"error\" in response) {\n throw new ContextError(\n response.error,\n response.code,\n undefined, // Don't hardcode - this was a 200 OK with error body\n response.helpUrl\n );\n }\n\n // Handle success response\n if (response.success) {\n return {\n mode: response.mode,\n result: response.result as T,\n tool: response.tool,\n method: response.method,\n session: response.session,\n durationMs: response.durationMs,\n };\n }\n\n // Fallback - shouldn't reach here with valid API responses\n throw new ContextError(\"Unexpected response format from API\");\n }\n\n /**\n * Start an execute session with a max spend budget.\n */\n async startSession(\n options: ExecuteSessionStartOptions\n ): Promise<ExecuteSessionResult> {\n const response = await this.client._fetch<ExecuteSessionApiResponse>(\n \"/api/v1/tools/execute/sessions\",\n {\n method: \"POST\",\n body: JSON.stringify({\n mode: \"execute\",\n maxSpendUsd: options.maxSpendUsd,\n }),\n }\n );\n\n return this.resolveSessionLifecycleResponse(response);\n }\n\n /**\n * Fetch current execute session status by ID.\n */\n async getSession(sessionId: string): Promise<ExecuteSessionResult> {\n if (!sessionId) {\n throw new ContextError(\"sessionId is required\");\n }\n\n const encodedSessionId = encodeURIComponent(sessionId);\n const response = await this.client._fetch<ExecuteSessionApiResponse>(\n `/api/v1/tools/execute/sessions/${encodedSessionId}`\n );\n\n return this.resolveSessionLifecycleResponse(response);\n }\n\n /**\n * Close an execute session by ID.\n */\n async closeSession(sessionId: string): Promise<ExecuteSessionResult> {\n if (!sessionId) {\n throw new ContextError(\"sessionId is required\");\n }\n\n const encodedSessionId = encodeURIComponent(sessionId);\n const response = await this.client._fetch<ExecuteSessionApiResponse>(\n `/api/v1/tools/execute/sessions/${encodedSessionId}/close`,\n {\n method: \"POST\",\n body: JSON.stringify({ mode: \"execute\" }),\n }\n );\n\n return this.resolveSessionLifecycleResponse(response);\n }\n\n private resolveSessionLifecycleResponse(\n response: ExecuteSessionApiResponse\n ): ExecuteSessionResult {\n if (\"error\" in response) {\n throw new ContextError(\n response.error,\n response.code,\n undefined,\n response.helpUrl\n );\n }\n\n if (response.success) {\n return {\n mode: response.mode,\n session: response.session,\n };\n }\n\n throw new ContextError(\"Unexpected response format from API\");\n }\n}\n","import type {\n QueryOptions,\n QueryApiResponse,\n QueryResult,\n QueryStreamEvent,\n} from \"../types.js\";\nimport { ContextError } from \"../types.js\";\nimport type { ContextClient } from \"../client.js\";\n\n/**\n * Query resource for pay-per-response agentic queries.\n *\n * Unlike `tools.execute()` which calls a single tool once (pay-per-request),\n * the Query resource sends a natural-language question and lets the server\n * handle tool discovery, multi-tool orchestration, self-healing retries,\n * completeness checks, and AI synthesis — all for one flat fee.\n *\n * This is the \"prepared meal\" vs \"raw ingredients\" distinction:\n * - `tools.execute()` = raw data, full control, predictable cost\n * - `query.run()` / `query.stream()` = curated intelligence, one payment\n */\nexport class Query {\n constructor(private client: ContextClient) {}\n\n /**\n * Run an agentic query and wait for the full response.\n *\n * The server discovers relevant tools (or uses the ones you specify),\n * executes the full agentic pipeline (up to 100 MCP calls per tool),\n * and returns an AI-synthesized answer. Payment is settled after\n * successful execution via deferred settlement.\n *\n * @param options - Query options or a plain string question\n * @returns The complete query result with response text, tools used, and cost\n *\n * @throws {ContextError} With code `no_wallet` if wallet not set up\n * @throws {ContextError} With code `insufficient_allowance` if spending cap not set\n * @throws {ContextError} With code `payment_failed` if payment settlement fails\n * @throws {ContextError} With code `execution_failed` if the agentic pipeline fails\n *\n * @example\n * ```typescript\n * // Simple question — server discovers tools automatically\n * const answer = await client.query.run(\"What are the top whale movements on Base?\");\n * console.log(answer.response); // AI-synthesized answer\n * console.log(answer.toolsUsed); // Which tools were used\n * console.log(answer.cost); // Cost breakdown\n *\n * // With specific tools (Manual Mode)\n * const answer = await client.query.run({\n * query: \"Analyze whale activity\",\n * tools: [\"tool-uuid-1\", \"tool-uuid-2\"],\n * });\n * ```\n */\n async run(options: QueryOptions | string): Promise<QueryResult> {\n const opts = typeof options === \"string\" ? { query: options } : options;\n const headers = opts.idempotencyKey\n ? { \"Idempotency-Key\": opts.idempotencyKey }\n : undefined;\n\n const response = await this.client._fetch<QueryApiResponse>(\n \"/api/v1/query\",\n {\n method: \"POST\",\n headers,\n body: JSON.stringify({\n query: opts.query,\n tools: opts.tools,\n modelId: opts.modelId,\n includeData: opts.includeData,\n includeDataUrl: opts.includeDataUrl,\n queryDepth: opts.queryDepth,\n stream: false,\n }),\n }\n );\n\n // Handle error response\n if (\"error\" in response) {\n throw new ContextError(\n response.error,\n response.code,\n undefined,\n response.helpUrl\n );\n }\n\n // Handle success response\n if (response.success) {\n return {\n response: response.response,\n toolsUsed: response.toolsUsed,\n cost: response.cost,\n durationMs: response.durationMs,\n data: response.data,\n dataUrl: response.dataUrl,\n };\n }\n\n throw new ContextError(\"Unexpected response format from query API\");\n }\n\n /**\n * Run an agentic query with streaming. Returns an async iterable that\n * yields events as the server processes the query in real-time.\n *\n * Event types:\n * - `tool-status` — A tool started executing or changed status\n * - `text-delta` — A chunk of the AI response text\n * - `done` — The full response is complete (includes final `QueryResult`)\n *\n * @param options - Query options or a plain string question\n * @returns An async iterable of stream events\n *\n * @example\n * ```typescript\n * for await (const event of client.query.stream(\"What are the top whale movements?\")) {\n * switch (event.type) {\n * case \"tool-status\":\n * console.log(`Tool ${event.tool.name}: ${event.status}`);\n * break;\n * case \"text-delta\":\n * process.stdout.write(event.delta);\n * break;\n * case \"done\":\n * console.log(\"\\nCost:\", event.result.cost.totalCostUsd);\n * break;\n * }\n * }\n * ```\n */\n async *stream(\n options: QueryOptions | string\n ): AsyncGenerator<QueryStreamEvent> {\n const opts = typeof options === \"string\" ? { query: options } : options;\n const headers = opts.idempotencyKey\n ? { \"Idempotency-Key\": opts.idempotencyKey }\n : undefined;\n\n const response = await this.client._fetchRaw(\"/api/v1/query\", {\n method: \"POST\",\n headers,\n body: JSON.stringify({\n query: opts.query,\n tools: opts.tools,\n modelId: opts.modelId,\n includeData: opts.includeData,\n includeDataUrl: opts.includeDataUrl,\n queryDepth: opts.queryDepth,\n stream: true,\n }),\n });\n\n const body = response.body;\n if (!body) {\n throw new ContextError(\"No response body for streaming query\");\n }\n\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n const trimmed = line.trim();\n if (trimmed.startsWith(\"data: \")) {\n const data = trimmed.slice(6);\n if (data === \"[DONE]\") return;\n try {\n yield JSON.parse(data) as QueryStreamEvent;\n } catch {\n // Skip malformed SSE events\n }\n }\n }\n }\n\n // Process any remaining buffer\n if (buffer.trim().startsWith(\"data: \")) {\n const data = buffer.trim().slice(6);\n if (data !== \"[DONE]\") {\n try {\n yield JSON.parse(data) as QueryStreamEvent;\n } catch {\n // Skip malformed SSE events\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n }\n}\n","import type { ContextClientOptions } from \"./types.js\";\nimport { ContextError } from \"./types.js\";\nimport { Discovery } from \"./resources/discovery.js\";\nimport { Tools } from \"./resources/tools.js\";\nimport { Query } from \"./resources/query.js\";\n\nconst DEFAULT_BASE_URL = \"https://www.ctxprotocol.com\";\nconst DEFAULT_REQUEST_TIMEOUT_MS = 300_000;\nconst DEFAULT_STREAM_TIMEOUT_MS = 600_000;\n\n/**\n * The official TypeScript client for the Context Protocol.\n *\n * Use this client to discover and execute AI tools programmatically.\n *\n * @example\n * ```typescript\n * import { ContextClient } from \"@contextprotocol/client\";\n *\n * const client = new ContextClient({\n * apiKey: \"sk_live_...\"\n * });\n *\n * // Pay-per-request: Execute a specific tool\n * const result = await client.tools.execute({\n * toolId: \"tool-uuid\",\n * toolName: \"get_gas_prices\",\n * args: { chainId: 1 }\n * });\n *\n * // Pay-per-response: Ask a question, get a curated answer\n * const answer = await client.query.run(\"What are the top whale movements on Base?\");\n * console.log(answer.response);\n * ```\n */\nexport class ContextClient {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n private readonly requestTimeoutMs: number;\n private readonly streamTimeoutMs: number;\n private _closed = false;\n\n /**\n * Discovery resource for searching tools\n */\n public readonly discovery: Discovery;\n\n /**\n * Tools resource for executing tools (pay-per-request)\n */\n public readonly tools: Tools;\n\n /**\n * Query resource for agentic queries (pay-per-response).\n *\n * Unlike `tools.execute()` which calls a single tool once, `query` sends\n * a natural-language question and lets the server handle tool discovery,\n * multi-tool orchestration, self-healing, and AI synthesis — one flat fee.\n */\n public readonly query: Query;\n\n /**\n * Creates a new Context Protocol client\n *\n * @param options - Client configuration options\n * @param options.apiKey - Your Context Protocol API key (format: sk_live_...)\n * @param options.baseUrl - Optional base URL override (defaults to https://www.ctxprotocol.com)\n * @param options.requestTimeoutMs - Optional timeout for non-streaming requests (default 300000ms)\n * @param options.streamTimeoutMs - Optional timeout for establishing stream requests (default 600000ms)\n */\n constructor(options: ContextClientOptions) {\n if (!options.apiKey) {\n throw new ContextError(\"API key is required\");\n }\n\n const requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;\n const streamTimeoutMs = options.streamTimeoutMs ?? DEFAULT_STREAM_TIMEOUT_MS;\n\n if (!Number.isFinite(requestTimeoutMs) || requestTimeoutMs <= 0) {\n throw new ContextError(\"requestTimeoutMs must be a positive number\");\n }\n\n if (!Number.isFinite(streamTimeoutMs) || streamTimeoutMs <= 0) {\n throw new ContextError(\"streamTimeoutMs must be a positive number\");\n }\n\n this.apiKey = options.apiKey;\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/$/, \"\");\n this.requestTimeoutMs = requestTimeoutMs;\n this.streamTimeoutMs = streamTimeoutMs;\n\n // Initialize resources\n this.discovery = new Discovery(this);\n this.tools = new Tools(this);\n this.query = new Query(this);\n }\n\n /**\n * Close the client and clean up resources.\n * After calling close(), any in-flight requests may be aborted.\n */\n close(): void {\n this._closed = true;\n }\n\n /**\n * Internal method for making authenticated HTTP requests\n * Includes timeout and retry with exponential backoff for transient errors\n *\n * @internal\n */\n async _fetch<T>(endpoint: string, options: RequestInit = {}): Promise<T> {\n if (this._closed) {\n throw new ContextError(\"Client has been closed\");\n }\n\n const url = `${this.baseUrl}${endpoint}`;\n const maxRetries = 3;\n const timeoutMs = this.requestTimeoutMs;\n\n let lastError: Error | undefined;\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), timeoutMs);\n\n try {\n const response = await fetch(url, {\n ...options,\n signal: controller.signal,\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.apiKey}`,\n ...options.headers,\n },\n });\n\n clearTimeout(timeout);\n\n if (!response.ok) {\n // Retry on 5xx server errors\n if (response.status >= 500 && attempt < maxRetries) {\n const delay = Math.min(1000 * 2 ** attempt, 10_000);\n await new Promise((resolve) => setTimeout(resolve, delay));\n continue;\n }\n\n let errorMessage = `HTTP ${response.status}: ${response.statusText}`;\n let errorCode: string | undefined;\n let helpUrl: string | undefined;\n\n try {\n const errorBody = await response.json();\n if (errorBody.error) {\n errorMessage = errorBody.error;\n errorCode = errorBody.code;\n helpUrl = errorBody.helpUrl;\n }\n } catch {\n // Use default error message if JSON parsing fails\n }\n\n throw new ContextError(errorMessage, errorCode, response.status, helpUrl);\n }\n\n return response.json() as Promise<T>;\n } catch (error) {\n clearTimeout(timeout);\n\n if (error instanceof ContextError) {\n throw error;\n }\n\n lastError = error instanceof Error ? error : new Error(String(error));\n\n // Retry on network errors and timeouts\n const isRetryable =\n lastError.name === \"AbortError\" ||\n lastError.message.includes(\"fetch failed\") ||\n lastError.message.includes(\"ECONNRESET\") ||\n lastError.message.includes(\"ETIMEDOUT\");\n\n if (isRetryable && attempt < maxRetries) {\n const delay = Math.min(1000 * 2 ** attempt, 10_000);\n await new Promise((resolve) => setTimeout(resolve, delay));\n continue;\n }\n\n if (lastError.name === \"AbortError\") {\n throw new ContextError(\n `Request timed out after ${timeoutMs / 1000}s`,\n undefined,\n 408\n );\n }\n\n throw new ContextError(\n lastError.message,\n undefined,\n undefined\n );\n }\n }\n\n throw lastError ?? new ContextError(\"Request failed after retries\");\n }\n\n /**\n * Internal method for making authenticated HTTP requests that returns\n * the raw Response object. Used for streaming endpoints (SSE).\n * Includes a configurable timeout for stream setup.\n *\n * @internal\n */\n async _fetchRaw(endpoint: string, options: RequestInit = {}): Promise<Response> {\n if (this._closed) {\n throw new ContextError(\"Client has been closed\");\n }\n\n const url = `${this.baseUrl}${endpoint}`;\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), this.streamTimeoutMs);\n\n let response: Response;\n try {\n response = await fetch(url, {\n ...options,\n signal: controller.signal,\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.apiKey}`,\n ...options.headers,\n },\n });\n } catch (error) {\n clearTimeout(timeout);\n const lastError = error instanceof Error ? error : new Error(String(error));\n if (lastError.name === \"AbortError\") {\n throw new ContextError(\n `Streaming request timed out after ${this.streamTimeoutMs / 1000}s`,\n undefined,\n 408\n );\n }\n throw new ContextError(lastError.message);\n }\n\n clearTimeout(timeout);\n\n if (!response.ok) {\n let errorMessage = `HTTP ${response.status}: ${response.statusText}`;\n let errorCode: string | undefined;\n let helpUrl: string | undefined;\n\n try {\n const errorBody = await response.json();\n if (errorBody.error) {\n errorMessage = errorBody.error;\n errorCode = errorBody.code;\n helpUrl = errorBody.helpUrl;\n }\n } catch {\n // Use default error message if JSON parsing fails\n }\n\n throw new ContextError(errorMessage, errorCode, response.status, helpUrl);\n }\n\n return response;\n }\n}\n"]}
|
package/dist/client/index.d.cts
CHANGED
|
@@ -9,9 +9,19 @@ interface ContextClientOptions {
|
|
|
9
9
|
apiKey: string;
|
|
10
10
|
/**
|
|
11
11
|
* Base URL for the Context Protocol API
|
|
12
|
-
* @default "https://ctxprotocol.com"
|
|
12
|
+
* @default "https://www.ctxprotocol.com"
|
|
13
13
|
*/
|
|
14
14
|
baseUrl?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Request timeout for non-streaming API calls in milliseconds.
|
|
17
|
+
* @default 300000
|
|
18
|
+
*/
|
|
19
|
+
requestTimeoutMs?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Request timeout for establishing streaming API calls in milliseconds.
|
|
22
|
+
* @default 600000
|
|
23
|
+
*/
|
|
24
|
+
streamTimeoutMs?: number;
|
|
15
25
|
}
|
|
16
26
|
/**
|
|
17
27
|
* An individual MCP tool exposed by a tool listing
|
|
@@ -287,6 +297,8 @@ interface ExecutionResult<T = unknown> {
|
|
|
287
297
|
/** Execution duration in milliseconds */
|
|
288
298
|
durationMs: number;
|
|
289
299
|
}
|
|
300
|
+
/** Supported orchestration depth modes for query execution. */
|
|
301
|
+
type QueryDepth = "fast" | "auto" | "deep";
|
|
290
302
|
/**
|
|
291
303
|
* Options for the agentic query endpoint (pay-per-response).
|
|
292
304
|
*
|
|
@@ -319,6 +331,13 @@ interface QueryOptions {
|
|
|
319
331
|
* Useful for large payload workflows where inline JSON is not ideal.
|
|
320
332
|
*/
|
|
321
333
|
includeDataUrl?: boolean;
|
|
334
|
+
/**
|
|
335
|
+
* Query orchestration depth mode:
|
|
336
|
+
* - `fast`: lower-latency path
|
|
337
|
+
* - `auto`: server decides between fast/deep
|
|
338
|
+
* - `deep`: full completeness-oriented path
|
|
339
|
+
*/
|
|
340
|
+
queryDepth?: QueryDepth;
|
|
322
341
|
/**
|
|
323
342
|
* Optional idempotency key (UUID recommended).
|
|
324
343
|
* Reuse the same key when retrying the same logical request.
|
|
@@ -607,6 +626,8 @@ declare class Query {
|
|
|
607
626
|
declare class ContextClient {
|
|
608
627
|
private readonly apiKey;
|
|
609
628
|
private readonly baseUrl;
|
|
629
|
+
private readonly requestTimeoutMs;
|
|
630
|
+
private readonly streamTimeoutMs;
|
|
610
631
|
private _closed;
|
|
611
632
|
/**
|
|
612
633
|
* Discovery resource for searching tools
|
|
@@ -629,7 +650,9 @@ declare class ContextClient {
|
|
|
629
650
|
*
|
|
630
651
|
* @param options - Client configuration options
|
|
631
652
|
* @param options.apiKey - Your Context Protocol API key (format: sk_live_...)
|
|
632
|
-
* @param options.baseUrl - Optional base URL override (defaults to https://ctxprotocol.com)
|
|
653
|
+
* @param options.baseUrl - Optional base URL override (defaults to https://www.ctxprotocol.com)
|
|
654
|
+
* @param options.requestTimeoutMs - Optional timeout for non-streaming requests (default 300000ms)
|
|
655
|
+
* @param options.streamTimeoutMs - Optional timeout for establishing stream requests (default 600000ms)
|
|
633
656
|
*/
|
|
634
657
|
constructor(options: ContextClientOptions);
|
|
635
658
|
/**
|
|
@@ -639,7 +662,7 @@ declare class ContextClient {
|
|
|
639
662
|
close(): void;
|
|
640
663
|
/**
|
|
641
664
|
* Internal method for making authenticated HTTP requests
|
|
642
|
-
* Includes timeout
|
|
665
|
+
* Includes timeout and retry with exponential backoff for transient errors
|
|
643
666
|
*
|
|
644
667
|
* @internal
|
|
645
668
|
*/
|
|
@@ -647,6 +670,7 @@ declare class ContextClient {
|
|
|
647
670
|
/**
|
|
648
671
|
* Internal method for making authenticated HTTP requests that returns
|
|
649
672
|
* the raw Response object. Used for streaming endpoints (SSE).
|
|
673
|
+
* Includes a configurable timeout for stream setup.
|
|
650
674
|
*
|
|
651
675
|
* @internal
|
|
652
676
|
*/
|
package/dist/client/index.d.ts
CHANGED
|
@@ -9,9 +9,19 @@ interface ContextClientOptions {
|
|
|
9
9
|
apiKey: string;
|
|
10
10
|
/**
|
|
11
11
|
* Base URL for the Context Protocol API
|
|
12
|
-
* @default "https://ctxprotocol.com"
|
|
12
|
+
* @default "https://www.ctxprotocol.com"
|
|
13
13
|
*/
|
|
14
14
|
baseUrl?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Request timeout for non-streaming API calls in milliseconds.
|
|
17
|
+
* @default 300000
|
|
18
|
+
*/
|
|
19
|
+
requestTimeoutMs?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Request timeout for establishing streaming API calls in milliseconds.
|
|
22
|
+
* @default 600000
|
|
23
|
+
*/
|
|
24
|
+
streamTimeoutMs?: number;
|
|
15
25
|
}
|
|
16
26
|
/**
|
|
17
27
|
* An individual MCP tool exposed by a tool listing
|
|
@@ -287,6 +297,8 @@ interface ExecutionResult<T = unknown> {
|
|
|
287
297
|
/** Execution duration in milliseconds */
|
|
288
298
|
durationMs: number;
|
|
289
299
|
}
|
|
300
|
+
/** Supported orchestration depth modes for query execution. */
|
|
301
|
+
type QueryDepth = "fast" | "auto" | "deep";
|
|
290
302
|
/**
|
|
291
303
|
* Options for the agentic query endpoint (pay-per-response).
|
|
292
304
|
*
|
|
@@ -319,6 +331,13 @@ interface QueryOptions {
|
|
|
319
331
|
* Useful for large payload workflows where inline JSON is not ideal.
|
|
320
332
|
*/
|
|
321
333
|
includeDataUrl?: boolean;
|
|
334
|
+
/**
|
|
335
|
+
* Query orchestration depth mode:
|
|
336
|
+
* - `fast`: lower-latency path
|
|
337
|
+
* - `auto`: server decides between fast/deep
|
|
338
|
+
* - `deep`: full completeness-oriented path
|
|
339
|
+
*/
|
|
340
|
+
queryDepth?: QueryDepth;
|
|
322
341
|
/**
|
|
323
342
|
* Optional idempotency key (UUID recommended).
|
|
324
343
|
* Reuse the same key when retrying the same logical request.
|
|
@@ -607,6 +626,8 @@ declare class Query {
|
|
|
607
626
|
declare class ContextClient {
|
|
608
627
|
private readonly apiKey;
|
|
609
628
|
private readonly baseUrl;
|
|
629
|
+
private readonly requestTimeoutMs;
|
|
630
|
+
private readonly streamTimeoutMs;
|
|
610
631
|
private _closed;
|
|
611
632
|
/**
|
|
612
633
|
* Discovery resource for searching tools
|
|
@@ -629,7 +650,9 @@ declare class ContextClient {
|
|
|
629
650
|
*
|
|
630
651
|
* @param options - Client configuration options
|
|
631
652
|
* @param options.apiKey - Your Context Protocol API key (format: sk_live_...)
|
|
632
|
-
* @param options.baseUrl - Optional base URL override (defaults to https://ctxprotocol.com)
|
|
653
|
+
* @param options.baseUrl - Optional base URL override (defaults to https://www.ctxprotocol.com)
|
|
654
|
+
* @param options.requestTimeoutMs - Optional timeout for non-streaming requests (default 300000ms)
|
|
655
|
+
* @param options.streamTimeoutMs - Optional timeout for establishing stream requests (default 600000ms)
|
|
633
656
|
*/
|
|
634
657
|
constructor(options: ContextClientOptions);
|
|
635
658
|
/**
|
|
@@ -639,7 +662,7 @@ declare class ContextClient {
|
|
|
639
662
|
close(): void;
|
|
640
663
|
/**
|
|
641
664
|
* Internal method for making authenticated HTTP requests
|
|
642
|
-
* Includes timeout
|
|
665
|
+
* Includes timeout and retry with exponential backoff for transient errors
|
|
643
666
|
*
|
|
644
667
|
* @internal
|
|
645
668
|
*/
|
|
@@ -647,6 +670,7 @@ declare class ContextClient {
|
|
|
647
670
|
/**
|
|
648
671
|
* Internal method for making authenticated HTTP requests that returns
|
|
649
672
|
* the raw Response object. Used for streaming endpoints (SSE).
|
|
673
|
+
* Includes a configurable timeout for stream setup.
|
|
650
674
|
*
|
|
651
675
|
* @internal
|
|
652
676
|
*/
|