@ctxprotocol/sdk 0.8.4 → 0.8.5

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.
@@ -299,12 +299,14 @@ interface ExecutionResult<T = unknown> {
299
299
  }
300
300
  /** Supported orchestration depth modes for query execution. */
301
301
  type QueryDepth = "fast" | "auto" | "deep";
302
+ type QueryDeepMode = "deep-light" | "deep-heavy";
302
303
  /**
303
304
  * Options for the agentic query endpoint (pay-per-response).
304
305
  *
305
306
  * Unlike `execute()` which calls a single tool once, `query()` sends a
306
- * natural-language question and lets the server handle tool discovery,
307
- * multi-tool orchestration, self-healing retries, and AI synthesis.
307
+ * natural-language question and lets the server handle discovery-first
308
+ * orchestration (`discover/probe -> plan-from-evidence -> execute ->
309
+ * bounded fallback`) plus synthesis.
308
310
  * One flat fee covers up to 100 MCP skill calls per tool.
309
311
  */
310
312
  interface QueryOptions {
@@ -333,8 +335,8 @@ interface QueryOptions {
333
335
  includeDataUrl?: boolean;
334
336
  /**
335
337
  * Include machine-readable developer trace output for this query response.
336
- * When enabled, the server may return timeline data describing retries,
337
- * fallbacks, loop checks, and intermediate recovery behavior.
338
+ * When enabled, the server may return summary counters plus diagnostics
339
+ * for lane selection, scout probe adequacy, and bounded fallback behavior.
338
340
  */
339
341
  includeDeveloperTrace?: boolean;
340
342
  /**
@@ -344,6 +346,11 @@ interface QueryOptions {
344
346
  * - `deep`: full completeness-oriented path
345
347
  */
346
348
  queryDepth?: QueryDepth;
349
+ /**
350
+ * Development/testing only: force the server's internal deep lane.
351
+ * Ignored by normal production usage and invalid when `queryDepth` is `fast`.
352
+ */
353
+ debugScoutDeepMode?: QueryDeepMode;
347
354
  /**
348
355
  * Optional idempotency key (UUID recommended).
349
356
  * Reuse the same key when retrying the same logical request.
@@ -368,6 +375,98 @@ interface QueryDeveloperTraceLoopInfo {
368
375
  maxIterations?: number;
369
376
  [key: string]: unknown;
370
377
  }
378
+ /**
379
+ * Tool selection metadata attached to discovery/planning diagnostics.
380
+ */
381
+ interface QueryDeveloperTraceToolSelection {
382
+ toolId: string;
383
+ toolName: string;
384
+ selectedMethodCount: number;
385
+ selectedMethods: string[];
386
+ omittedSelectedMethodCount: number;
387
+ priceUsd?: string;
388
+ }
389
+ /**
390
+ * Initial planner diagnostic details.
391
+ */
392
+ interface QueryPlanningTraceDiagnostic {
393
+ plannerQuery: string;
394
+ scoutEvidenceAttached: boolean;
395
+ scoutEvidencePromptBlock: string | null;
396
+ allowedModules: string[];
397
+ }
398
+ /**
399
+ * Rediscovery/fallback diagnostic details.
400
+ */
401
+ interface QueryRediscoveryTraceDiagnostic {
402
+ considered: boolean;
403
+ executed: boolean;
404
+ skipReason: string | null;
405
+ missingCapability: string | null;
406
+ rediscoveryQuery: string | null;
407
+ capabilityLooksLikeSearchNeed: boolean;
408
+ allowSearchFallbackOnElapsedCap: boolean;
409
+ searchFallbackUsed: boolean;
410
+ preRediscoveryBudgetReasonCode: string | null;
411
+ candidateSearchResults: QueryDeveloperTraceToolSelection[];
412
+ selectedAlternatives: QueryDeveloperTraceToolSelection[];
413
+ mergedTools: QueryDeveloperTraceToolSelection[];
414
+ usingPaidFallback: boolean;
415
+ branchPlan: QueryPlanningTraceDiagnostic | null;
416
+ }
417
+ /**
418
+ * Rich developer-trace diagnostics for discovery-first orchestration internals.
419
+ */
420
+ interface QueryDeveloperTraceDiagnostics {
421
+ selection: {
422
+ selectedDepth: string;
423
+ deepMode: string | null;
424
+ debugScoutDeepMode: string | null;
425
+ plannerReasoningStage: string;
426
+ scoutEnabled: boolean;
427
+ preserveFastOneShot: boolean;
428
+ candidateMethodCount: number;
429
+ scoutProbeStatus: string;
430
+ scoutProbeAdequacy: string;
431
+ scoutProbeConfidence: number;
432
+ scoutMetadataConfidence: number;
433
+ scoutProbeShortlistedMethodCount: number;
434
+ scoutProbeMissingCapability: string | null;
435
+ scoutPrePlanProbeCalls: number;
436
+ scoutPrePlanProbeBudgetReasonCode: string | null;
437
+ scoutChangedInitialPlan: boolean;
438
+ scoutChangedPlannerReasoningStage: boolean;
439
+ scoutInitialSelectedDepth: string;
440
+ scoutInitialDeepMode: string | null;
441
+ scoutInitialPlannerReasoningStage: string;
442
+ scoutInitialReasonCode: string;
443
+ scoutFinalReasonCode: string;
444
+ scoutEvidenceAttachedToPlanning: boolean;
445
+ scoutLlmSelectionUsed: boolean;
446
+ scoutLlmSelectionFallback: boolean;
447
+ scoutLlmSelectionLatencyMs: number | null;
448
+ selectedTools: QueryDeveloperTraceToolSelection[];
449
+ };
450
+ planning: {
451
+ initial: QueryPlanningTraceDiagnostic;
452
+ };
453
+ cost?: {
454
+ planningCostUsd: number;
455
+ initialExecutionCostUsd: number;
456
+ rediscoveryAdditionalCostUsd: number;
457
+ synthesisCostUsd: number;
458
+ totalModelCostUsd: number;
459
+ toolCostUsd: number;
460
+ totalChargedUsd: number;
461
+ };
462
+ completeness: {
463
+ evaluations: unknown[];
464
+ triggerNeedsDifferentTools: boolean;
465
+ triggerMissingCapability: string | null;
466
+ };
467
+ rediscovery: QueryRediscoveryTraceDiagnostic | null;
468
+ [key: string]: unknown;
469
+ }
371
470
  /**
372
471
  * A single developer-trace timeline step.
373
472
  */
@@ -403,6 +502,10 @@ interface QueryDeveloperTraceSummary {
403
502
  interface QueryDeveloperTrace {
404
503
  summary?: QueryDeveloperTraceSummary;
405
504
  timeline?: QueryDeveloperTraceStep[];
505
+ requestId?: string;
506
+ query?: string;
507
+ source?: string;
508
+ diagnostics?: QueryDeveloperTraceDiagnostics;
406
509
  [key: string]: unknown;
407
510
  }
408
511
  /**
@@ -428,6 +531,19 @@ interface QueryCost {
428
531
  /** Total cost (model + tools) */
429
532
  totalCostUsd: string;
430
533
  }
534
+ /**
535
+ * High-level orchestration outcome metrics returned by the query API.
536
+ */
537
+ interface QueryOrchestrationMetrics {
538
+ parityStage: string;
539
+ orchestrationMode: string;
540
+ /** Whether the first plan path succeeded without fallback. */
541
+ firstPassSuccess: boolean;
542
+ /** Whether execution signaled a missing capability on first pass. */
543
+ capabilityMissSignaled: boolean;
544
+ /** Whether bounded rediscovery/fallback executed. */
545
+ rediscoveryExecuted: boolean;
546
+ }
431
547
  /**
432
548
  * The resolved result of a pay-per-response query
433
549
  */
@@ -446,6 +562,8 @@ interface QueryResult {
446
562
  dataUrl?: string;
447
563
  /** Optional machine-readable Developer Mode trace payload */
448
564
  developerTrace?: QueryDeveloperTrace;
565
+ /** Optional orchestration outcome metrics for benchmarking and rollout analysis */
566
+ orchestrationMetrics?: QueryOrchestrationMetrics;
449
567
  }
450
568
  /**
451
569
  * Successful response from the /api/v1/query endpoint
@@ -459,6 +577,7 @@ interface QueryApiSuccessResponse {
459
577
  data?: unknown;
460
578
  dataUrl?: string;
461
579
  developerTrace?: QueryDeveloperTrace;
580
+ orchestrationMetrics?: QueryOrchestrationMetrics;
462
581
  }
463
582
  /**
464
583
  * Raw API response from the query endpoint
@@ -488,10 +607,18 @@ interface QueryStreamDoneEvent {
488
607
  type: "done";
489
608
  result: QueryResult;
490
609
  }
610
+ /** Emitted when the server reports a recoverable or terminal query error */
611
+ interface QueryStreamErrorEvent {
612
+ type: "error";
613
+ error: string;
614
+ code?: ContextErrorCode | string;
615
+ scope?: string;
616
+ reasonCode?: string;
617
+ }
491
618
  /**
492
619
  * Union of all events emitted during a streaming query
493
620
  */
494
- type QueryStreamEvent = QueryStreamToolStatusEvent | QueryStreamTextDeltaEvent | QueryStreamDeveloperTraceEvent | QueryStreamDoneEvent;
621
+ type QueryStreamEvent = QueryStreamToolStatusEvent | QueryStreamTextDeltaEvent | QueryStreamDeveloperTraceEvent | QueryStreamDoneEvent | QueryStreamErrorEvent;
495
622
  /**
496
623
  * Specific error codes returned by the Context Protocol API
497
624
  */
@@ -593,8 +720,8 @@ declare class Tools {
593
720
  *
594
721
  * Unlike `tools.execute()` which calls a single tool once (pay-per-request),
595
722
  * the Query resource sends a natural-language question and lets the server
596
- * handle tool discovery, multi-tool orchestration, self-healing retries,
597
- * completeness checks, and AI synthesis — all for one flat fee.
723
+ * handle discovery-first orchestration (`discover/probe -> plan-from-evidence ->
724
+ * execute -> bounded fallback`) plus AI synthesis — all for one flat fee.
598
725
  *
599
726
  * This is the "prepared meal" vs "raw ingredients" distinction:
600
727
  * - `tools.execute()` = raw data, full control, predictable cost
@@ -611,7 +738,7 @@ declare class Query {
611
738
  * Run an agentic query and wait for the full response.
612
739
  *
613
740
  * The server discovers relevant tools (or uses the ones you specify),
614
- * executes the full agentic pipeline (up to 100 MCP calls per tool),
741
+ * executes the discovery-first pipeline (up to 100 MCP calls per tool),
615
742
  * and returns an AI-synthesized answer. Payment is settled after
616
743
  * successful execution via deferred settlement.
617
744
  *
@@ -647,6 +774,7 @@ declare class Query {
647
774
  * - `tool-status` — A tool started executing or changed status
648
775
  * - `text-delta` — A chunk of the AI response text
649
776
  * - `developer-trace` — Runtime trace metadata (when includeDeveloperTrace=true)
777
+ * - `error` — A structured query/runtime error emitted before stream completion
650
778
  * - `done` — The full response is complete (includes final `QueryResult`)
651
779
  *
652
780
  * @param options - Query options or a plain string question
@@ -668,6 +796,9 @@ declare class Query {
668
796
  * case "done":
669
797
  * console.log("\nCost:", event.result.cost.totalCostUsd);
670
798
  * break;
799
+ * case "error":
800
+ * console.error("Stream error:", event.error);
801
+ * break;
671
802
  * }
672
803
  * }
673
804
  * ```
@@ -743,7 +874,9 @@ declare class ContextClient {
743
874
  *
744
875
  * @internal
745
876
  */
746
- _fetch<T>(endpoint: string, options?: RequestInit): Promise<T>;
877
+ _fetch<T>(endpoint: string, options?: RequestInit, fetchOptions?: {
878
+ retry?: boolean;
879
+ }): Promise<T>;
747
880
  /**
748
881
  * Internal method for making authenticated HTTP requests that returns
749
882
  * the raw Response object. Used for streaming endpoints (SSE).
@@ -754,4 +887,4 @@ declare class ContextClient {
754
887
  _fetchRaw(endpoint: string, options?: RequestInit): Promise<Response>;
755
888
  }
756
889
 
757
- export { ContextClient, type ContextClientOptions, ContextError, type ContextErrorCode, Discovery, type ExecuteApiErrorResponse, type ExecuteApiResponse, type ExecuteApiSuccessResponse, type ExecuteOptions, type ExecuteSessionApiResponse, type ExecuteSessionApiSuccessResponse, type ExecuteSessionResult, type ExecuteSessionSpend, type ExecuteSessionStartOptions, type ExecuteSessionStatus, type ExecutionResult, type McpTool, type McpToolMeta, type McpToolRateLimitHints, Query, type QueryApiResponse, type QueryApiSuccessResponse, type QueryCost, type QueryDeveloperTrace, type QueryDeveloperTraceLoopInfo, type QueryDeveloperTraceStep, type QueryDeveloperTraceSummary, type QueryDeveloperTraceToolRef, type QueryOptions, type QueryResult, type QueryStreamDeveloperTraceEvent, type QueryStreamDoneEvent, type QueryStreamEvent, type QueryStreamTextDeltaEvent, type QueryStreamToolStatusEvent, type QueryToolUsage, type SearchOptions, type SearchResponse, type Tool, Tools };
890
+ export { ContextClient, type ContextClientOptions, ContextError, type ContextErrorCode, Discovery, type ExecuteApiErrorResponse, type ExecuteApiResponse, type ExecuteApiSuccessResponse, type ExecuteOptions, type ExecuteSessionApiResponse, type ExecuteSessionApiSuccessResponse, type ExecuteSessionResult, type ExecuteSessionSpend, type ExecuteSessionStartOptions, type ExecuteSessionStatus, type ExecutionResult, type McpTool, type McpToolMeta, type McpToolRateLimitHints, Query, type QueryApiResponse, type QueryApiSuccessResponse, type QueryCost, type QueryDeepMode, type QueryDeveloperTrace, type QueryDeveloperTraceLoopInfo, type QueryDeveloperTraceStep, type QueryDeveloperTraceSummary, type QueryDeveloperTraceToolRef, type QueryOptions, type QueryResult, type QueryStreamDeveloperTraceEvent, type QueryStreamDoneEvent, type QueryStreamErrorEvent, type QueryStreamEvent, type QueryStreamTextDeltaEvent, type QueryStreamToolStatusEvent, type QueryToolUsage, type SearchOptions, type SearchResponse, type Tool, Tools };
@@ -299,12 +299,14 @@ interface ExecutionResult<T = unknown> {
299
299
  }
300
300
  /** Supported orchestration depth modes for query execution. */
301
301
  type QueryDepth = "fast" | "auto" | "deep";
302
+ type QueryDeepMode = "deep-light" | "deep-heavy";
302
303
  /**
303
304
  * Options for the agentic query endpoint (pay-per-response).
304
305
  *
305
306
  * Unlike `execute()` which calls a single tool once, `query()` sends a
306
- * natural-language question and lets the server handle tool discovery,
307
- * multi-tool orchestration, self-healing retries, and AI synthesis.
307
+ * natural-language question and lets the server handle discovery-first
308
+ * orchestration (`discover/probe -> plan-from-evidence -> execute ->
309
+ * bounded fallback`) plus synthesis.
308
310
  * One flat fee covers up to 100 MCP skill calls per tool.
309
311
  */
310
312
  interface QueryOptions {
@@ -333,8 +335,8 @@ interface QueryOptions {
333
335
  includeDataUrl?: boolean;
334
336
  /**
335
337
  * Include machine-readable developer trace output for this query response.
336
- * When enabled, the server may return timeline data describing retries,
337
- * fallbacks, loop checks, and intermediate recovery behavior.
338
+ * When enabled, the server may return summary counters plus diagnostics
339
+ * for lane selection, scout probe adequacy, and bounded fallback behavior.
338
340
  */
339
341
  includeDeveloperTrace?: boolean;
340
342
  /**
@@ -344,6 +346,11 @@ interface QueryOptions {
344
346
  * - `deep`: full completeness-oriented path
345
347
  */
346
348
  queryDepth?: QueryDepth;
349
+ /**
350
+ * Development/testing only: force the server's internal deep lane.
351
+ * Ignored by normal production usage and invalid when `queryDepth` is `fast`.
352
+ */
353
+ debugScoutDeepMode?: QueryDeepMode;
347
354
  /**
348
355
  * Optional idempotency key (UUID recommended).
349
356
  * Reuse the same key when retrying the same logical request.
@@ -368,6 +375,98 @@ interface QueryDeveloperTraceLoopInfo {
368
375
  maxIterations?: number;
369
376
  [key: string]: unknown;
370
377
  }
378
+ /**
379
+ * Tool selection metadata attached to discovery/planning diagnostics.
380
+ */
381
+ interface QueryDeveloperTraceToolSelection {
382
+ toolId: string;
383
+ toolName: string;
384
+ selectedMethodCount: number;
385
+ selectedMethods: string[];
386
+ omittedSelectedMethodCount: number;
387
+ priceUsd?: string;
388
+ }
389
+ /**
390
+ * Initial planner diagnostic details.
391
+ */
392
+ interface QueryPlanningTraceDiagnostic {
393
+ plannerQuery: string;
394
+ scoutEvidenceAttached: boolean;
395
+ scoutEvidencePromptBlock: string | null;
396
+ allowedModules: string[];
397
+ }
398
+ /**
399
+ * Rediscovery/fallback diagnostic details.
400
+ */
401
+ interface QueryRediscoveryTraceDiagnostic {
402
+ considered: boolean;
403
+ executed: boolean;
404
+ skipReason: string | null;
405
+ missingCapability: string | null;
406
+ rediscoveryQuery: string | null;
407
+ capabilityLooksLikeSearchNeed: boolean;
408
+ allowSearchFallbackOnElapsedCap: boolean;
409
+ searchFallbackUsed: boolean;
410
+ preRediscoveryBudgetReasonCode: string | null;
411
+ candidateSearchResults: QueryDeveloperTraceToolSelection[];
412
+ selectedAlternatives: QueryDeveloperTraceToolSelection[];
413
+ mergedTools: QueryDeveloperTraceToolSelection[];
414
+ usingPaidFallback: boolean;
415
+ branchPlan: QueryPlanningTraceDiagnostic | null;
416
+ }
417
+ /**
418
+ * Rich developer-trace diagnostics for discovery-first orchestration internals.
419
+ */
420
+ interface QueryDeveloperTraceDiagnostics {
421
+ selection: {
422
+ selectedDepth: string;
423
+ deepMode: string | null;
424
+ debugScoutDeepMode: string | null;
425
+ plannerReasoningStage: string;
426
+ scoutEnabled: boolean;
427
+ preserveFastOneShot: boolean;
428
+ candidateMethodCount: number;
429
+ scoutProbeStatus: string;
430
+ scoutProbeAdequacy: string;
431
+ scoutProbeConfidence: number;
432
+ scoutMetadataConfidence: number;
433
+ scoutProbeShortlistedMethodCount: number;
434
+ scoutProbeMissingCapability: string | null;
435
+ scoutPrePlanProbeCalls: number;
436
+ scoutPrePlanProbeBudgetReasonCode: string | null;
437
+ scoutChangedInitialPlan: boolean;
438
+ scoutChangedPlannerReasoningStage: boolean;
439
+ scoutInitialSelectedDepth: string;
440
+ scoutInitialDeepMode: string | null;
441
+ scoutInitialPlannerReasoningStage: string;
442
+ scoutInitialReasonCode: string;
443
+ scoutFinalReasonCode: string;
444
+ scoutEvidenceAttachedToPlanning: boolean;
445
+ scoutLlmSelectionUsed: boolean;
446
+ scoutLlmSelectionFallback: boolean;
447
+ scoutLlmSelectionLatencyMs: number | null;
448
+ selectedTools: QueryDeveloperTraceToolSelection[];
449
+ };
450
+ planning: {
451
+ initial: QueryPlanningTraceDiagnostic;
452
+ };
453
+ cost?: {
454
+ planningCostUsd: number;
455
+ initialExecutionCostUsd: number;
456
+ rediscoveryAdditionalCostUsd: number;
457
+ synthesisCostUsd: number;
458
+ totalModelCostUsd: number;
459
+ toolCostUsd: number;
460
+ totalChargedUsd: number;
461
+ };
462
+ completeness: {
463
+ evaluations: unknown[];
464
+ triggerNeedsDifferentTools: boolean;
465
+ triggerMissingCapability: string | null;
466
+ };
467
+ rediscovery: QueryRediscoveryTraceDiagnostic | null;
468
+ [key: string]: unknown;
469
+ }
371
470
  /**
372
471
  * A single developer-trace timeline step.
373
472
  */
@@ -403,6 +502,10 @@ interface QueryDeveloperTraceSummary {
403
502
  interface QueryDeveloperTrace {
404
503
  summary?: QueryDeveloperTraceSummary;
405
504
  timeline?: QueryDeveloperTraceStep[];
505
+ requestId?: string;
506
+ query?: string;
507
+ source?: string;
508
+ diagnostics?: QueryDeveloperTraceDiagnostics;
406
509
  [key: string]: unknown;
407
510
  }
408
511
  /**
@@ -428,6 +531,19 @@ interface QueryCost {
428
531
  /** Total cost (model + tools) */
429
532
  totalCostUsd: string;
430
533
  }
534
+ /**
535
+ * High-level orchestration outcome metrics returned by the query API.
536
+ */
537
+ interface QueryOrchestrationMetrics {
538
+ parityStage: string;
539
+ orchestrationMode: string;
540
+ /** Whether the first plan path succeeded without fallback. */
541
+ firstPassSuccess: boolean;
542
+ /** Whether execution signaled a missing capability on first pass. */
543
+ capabilityMissSignaled: boolean;
544
+ /** Whether bounded rediscovery/fallback executed. */
545
+ rediscoveryExecuted: boolean;
546
+ }
431
547
  /**
432
548
  * The resolved result of a pay-per-response query
433
549
  */
@@ -446,6 +562,8 @@ interface QueryResult {
446
562
  dataUrl?: string;
447
563
  /** Optional machine-readable Developer Mode trace payload */
448
564
  developerTrace?: QueryDeveloperTrace;
565
+ /** Optional orchestration outcome metrics for benchmarking and rollout analysis */
566
+ orchestrationMetrics?: QueryOrchestrationMetrics;
449
567
  }
450
568
  /**
451
569
  * Successful response from the /api/v1/query endpoint
@@ -459,6 +577,7 @@ interface QueryApiSuccessResponse {
459
577
  data?: unknown;
460
578
  dataUrl?: string;
461
579
  developerTrace?: QueryDeveloperTrace;
580
+ orchestrationMetrics?: QueryOrchestrationMetrics;
462
581
  }
463
582
  /**
464
583
  * Raw API response from the query endpoint
@@ -488,10 +607,18 @@ interface QueryStreamDoneEvent {
488
607
  type: "done";
489
608
  result: QueryResult;
490
609
  }
610
+ /** Emitted when the server reports a recoverable or terminal query error */
611
+ interface QueryStreamErrorEvent {
612
+ type: "error";
613
+ error: string;
614
+ code?: ContextErrorCode | string;
615
+ scope?: string;
616
+ reasonCode?: string;
617
+ }
491
618
  /**
492
619
  * Union of all events emitted during a streaming query
493
620
  */
494
- type QueryStreamEvent = QueryStreamToolStatusEvent | QueryStreamTextDeltaEvent | QueryStreamDeveloperTraceEvent | QueryStreamDoneEvent;
621
+ type QueryStreamEvent = QueryStreamToolStatusEvent | QueryStreamTextDeltaEvent | QueryStreamDeveloperTraceEvent | QueryStreamDoneEvent | QueryStreamErrorEvent;
495
622
  /**
496
623
  * Specific error codes returned by the Context Protocol API
497
624
  */
@@ -593,8 +720,8 @@ declare class Tools {
593
720
  *
594
721
  * Unlike `tools.execute()` which calls a single tool once (pay-per-request),
595
722
  * the Query resource sends a natural-language question and lets the server
596
- * handle tool discovery, multi-tool orchestration, self-healing retries,
597
- * completeness checks, and AI synthesis — all for one flat fee.
723
+ * handle discovery-first orchestration (`discover/probe -> plan-from-evidence ->
724
+ * execute -> bounded fallback`) plus AI synthesis — all for one flat fee.
598
725
  *
599
726
  * This is the "prepared meal" vs "raw ingredients" distinction:
600
727
  * - `tools.execute()` = raw data, full control, predictable cost
@@ -611,7 +738,7 @@ declare class Query {
611
738
  * Run an agentic query and wait for the full response.
612
739
  *
613
740
  * The server discovers relevant tools (or uses the ones you specify),
614
- * executes the full agentic pipeline (up to 100 MCP calls per tool),
741
+ * executes the discovery-first pipeline (up to 100 MCP calls per tool),
615
742
  * and returns an AI-synthesized answer. Payment is settled after
616
743
  * successful execution via deferred settlement.
617
744
  *
@@ -647,6 +774,7 @@ declare class Query {
647
774
  * - `tool-status` — A tool started executing or changed status
648
775
  * - `text-delta` — A chunk of the AI response text
649
776
  * - `developer-trace` — Runtime trace metadata (when includeDeveloperTrace=true)
777
+ * - `error` — A structured query/runtime error emitted before stream completion
650
778
  * - `done` — The full response is complete (includes final `QueryResult`)
651
779
  *
652
780
  * @param options - Query options or a plain string question
@@ -668,6 +796,9 @@ declare class Query {
668
796
  * case "done":
669
797
  * console.log("\nCost:", event.result.cost.totalCostUsd);
670
798
  * break;
799
+ * case "error":
800
+ * console.error("Stream error:", event.error);
801
+ * break;
671
802
  * }
672
803
  * }
673
804
  * ```
@@ -743,7 +874,9 @@ declare class ContextClient {
743
874
  *
744
875
  * @internal
745
876
  */
746
- _fetch<T>(endpoint: string, options?: RequestInit): Promise<T>;
877
+ _fetch<T>(endpoint: string, options?: RequestInit, fetchOptions?: {
878
+ retry?: boolean;
879
+ }): Promise<T>;
747
880
  /**
748
881
  * Internal method for making authenticated HTTP requests that returns
749
882
  * the raw Response object. Used for streaming endpoints (SSE).
@@ -754,4 +887,4 @@ declare class ContextClient {
754
887
  _fetchRaw(endpoint: string, options?: RequestInit): Promise<Response>;
755
888
  }
756
889
 
757
- export { ContextClient, type ContextClientOptions, ContextError, type ContextErrorCode, Discovery, type ExecuteApiErrorResponse, type ExecuteApiResponse, type ExecuteApiSuccessResponse, type ExecuteOptions, type ExecuteSessionApiResponse, type ExecuteSessionApiSuccessResponse, type ExecuteSessionResult, type ExecuteSessionSpend, type ExecuteSessionStartOptions, type ExecuteSessionStatus, type ExecutionResult, type McpTool, type McpToolMeta, type McpToolRateLimitHints, Query, type QueryApiResponse, type QueryApiSuccessResponse, type QueryCost, type QueryDeveloperTrace, type QueryDeveloperTraceLoopInfo, type QueryDeveloperTraceStep, type QueryDeveloperTraceSummary, type QueryDeveloperTraceToolRef, type QueryOptions, type QueryResult, type QueryStreamDeveloperTraceEvent, type QueryStreamDoneEvent, type QueryStreamEvent, type QueryStreamTextDeltaEvent, type QueryStreamToolStatusEvent, type QueryToolUsage, type SearchOptions, type SearchResponse, type Tool, Tools };
890
+ export { ContextClient, type ContextClientOptions, ContextError, type ContextErrorCode, Discovery, type ExecuteApiErrorResponse, type ExecuteApiResponse, type ExecuteApiSuccessResponse, type ExecuteOptions, type ExecuteSessionApiResponse, type ExecuteSessionApiSuccessResponse, type ExecuteSessionResult, type ExecuteSessionSpend, type ExecuteSessionStartOptions, type ExecuteSessionStatus, type ExecutionResult, type McpTool, type McpToolMeta, type McpToolRateLimitHints, Query, type QueryApiResponse, type QueryApiSuccessResponse, type QueryCost, type QueryDeepMode, type QueryDeveloperTrace, type QueryDeveloperTraceLoopInfo, type QueryDeveloperTraceStep, type QueryDeveloperTraceSummary, type QueryDeveloperTraceToolRef, type QueryOptions, type QueryResult, type QueryStreamDeveloperTraceEvent, type QueryStreamDoneEvent, type QueryStreamErrorEvent, type QueryStreamEvent, type QueryStreamTextDeltaEvent, type QueryStreamToolStatusEvent, type QueryToolUsage, type SearchOptions, type SearchResponse, type Tool, Tools };