@ctxprotocol/sdk 0.9.0 → 0.10.0
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 +23 -9
- package/dist/client/index.cjs +66 -8
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +5 -635
- package/dist/client/index.d.ts +5 -635
- package/dist/client/index.js +66 -8
- package/dist/client/index.js.map +1 -1
- package/dist/contrib/search/index.cjs +703 -0
- package/dist/contrib/search/index.cjs.map +1 -0
- package/dist/contrib/search/index.d.cts +33 -0
- package/dist/contrib/search/index.d.ts +33 -0
- package/dist/contrib/search/index.js +690 -0
- package/dist/contrib/search/index.js.map +1 -0
- package/dist/index.cjs +66 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +66 -8
- package/dist/index.js.map +1 -1
- package/dist/types-Bgjq3OBR.d.cts +1071 -0
- package/dist/types-Bgjq3OBR.d.ts +1071 -0
- package/package.json +11 -1
|
@@ -0,0 +1,1071 @@
|
|
|
1
|
+
declare const CONTRIBUTOR_SEARCH_METADATA_VERSION: "ctx-contributor-search/v1";
|
|
2
|
+
declare const CONTRIBUTOR_SEARCH_VALIDATION_VERSION: "ctx-contributor-search-validation/v1";
|
|
3
|
+
type ContributorSearchOutcome = "selected" | "shortlist_only" | "capability_miss";
|
|
4
|
+
type ContributorSearchConfidence = "high" | "medium" | "low";
|
|
5
|
+
type ContributorSearchDegradedOutcomePolicy = "return_shortlist" | "allow_low_confidence_selected";
|
|
6
|
+
type ContributorSearchDegradedReasonCode = "judge_disabled" | "judge_missing" | "judge_timeout" | "judge_budget_exceeded" | "judge_invalid_output" | "judge_error" | "validator_rejected" | "ambiguous_shortlist" | "no_viable_candidates";
|
|
7
|
+
type ContributorSearchValidationCaseKind = "named_regression" | "generic_overlap" | "still_ambiguous" | "capability_miss";
|
|
8
|
+
type ContributorSearchValidatorStatus = "accepted" | "rejected" | "not_run";
|
|
9
|
+
interface SearchIntent {
|
|
10
|
+
intentId: string;
|
|
11
|
+
rawRequest: string;
|
|
12
|
+
query: string;
|
|
13
|
+
clause: string | null;
|
|
14
|
+
metadata?: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
interface SearchCandidateProvenance {
|
|
17
|
+
source: string;
|
|
18
|
+
query: string;
|
|
19
|
+
rank: number | null;
|
|
20
|
+
fetchedAt: string | null;
|
|
21
|
+
metadata?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
interface SearchCandidate {
|
|
24
|
+
candidateId: string;
|
|
25
|
+
title: string;
|
|
26
|
+
description?: string | null;
|
|
27
|
+
rawIds?: Record<string, string>;
|
|
28
|
+
rankFeatures?: Record<string, boolean | number | string | null>;
|
|
29
|
+
provenance: SearchCandidateProvenance[];
|
|
30
|
+
metadata?: Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
interface SearchShortlist {
|
|
33
|
+
maxSize: number;
|
|
34
|
+
candidates: SearchCandidate[];
|
|
35
|
+
}
|
|
36
|
+
interface ContributorSearchConfig {
|
|
37
|
+
provider?: string | null;
|
|
38
|
+
model?: string | null;
|
|
39
|
+
timeoutMs?: number | null;
|
|
40
|
+
budgetUsd?: string | null;
|
|
41
|
+
disableJudge?: boolean;
|
|
42
|
+
degradedOutcomePolicy?: ContributorSearchDegradedOutcomePolicy;
|
|
43
|
+
maxShortlistSize?: number;
|
|
44
|
+
}
|
|
45
|
+
interface ContributorSearchResolvedConfig {
|
|
46
|
+
provider: string | null;
|
|
47
|
+
model: string | null;
|
|
48
|
+
timeoutMs: number | null;
|
|
49
|
+
budgetUsd: string | null;
|
|
50
|
+
disableJudge: boolean;
|
|
51
|
+
degradedOutcomePolicy: ContributorSearchDegradedOutcomePolicy;
|
|
52
|
+
maxShortlistSize: number;
|
|
53
|
+
}
|
|
54
|
+
interface ContributorSearchJudgeUsage {
|
|
55
|
+
promptTokens?: number;
|
|
56
|
+
completionTokens?: number;
|
|
57
|
+
totalTokens?: number;
|
|
58
|
+
costUsd?: string | null;
|
|
59
|
+
latencyMs?: number | null;
|
|
60
|
+
}
|
|
61
|
+
interface ContributorSearchJudgeInput {
|
|
62
|
+
rawRequest: string;
|
|
63
|
+
intents: SearchIntent[];
|
|
64
|
+
shortlist: SearchShortlist;
|
|
65
|
+
instructions?: string;
|
|
66
|
+
policy: ContributorSearchResolvedConfig;
|
|
67
|
+
}
|
|
68
|
+
interface ContributorSearchJudgeContext {
|
|
69
|
+
provider: string | null;
|
|
70
|
+
model: string | null;
|
|
71
|
+
timeoutMs: number | null;
|
|
72
|
+
budgetUsd: string | null;
|
|
73
|
+
traceLabel: string | null;
|
|
74
|
+
}
|
|
75
|
+
interface ContributorSearchJudgeResult {
|
|
76
|
+
primaryCandidateId: string | null;
|
|
77
|
+
relatedCandidateIds: string[];
|
|
78
|
+
rejectedCandidateIds: string[];
|
|
79
|
+
confidence: ContributorSearchConfidence;
|
|
80
|
+
reason: string;
|
|
81
|
+
usage?: ContributorSearchJudgeUsage;
|
|
82
|
+
}
|
|
83
|
+
interface ContributorSearchJudge {
|
|
84
|
+
evaluate(input: ContributorSearchJudgeInput, context: ContributorSearchJudgeContext): Promise<ContributorSearchJudgeResult>;
|
|
85
|
+
}
|
|
86
|
+
interface ContributorSearchDegradedOutcome {
|
|
87
|
+
reasonCode: ContributorSearchDegradedReasonCode;
|
|
88
|
+
message: string;
|
|
89
|
+
}
|
|
90
|
+
interface ContributorSearchMetadataSource {
|
|
91
|
+
source: string;
|
|
92
|
+
query: string;
|
|
93
|
+
candidateCount: number;
|
|
94
|
+
}
|
|
95
|
+
interface ContributorSearchJudgeSnapshot {
|
|
96
|
+
provider: string | null;
|
|
97
|
+
model: string | null;
|
|
98
|
+
timeoutMs: number | null;
|
|
99
|
+
budgetUsd: string | null;
|
|
100
|
+
disabled: boolean;
|
|
101
|
+
applied: boolean;
|
|
102
|
+
usage: ContributorSearchJudgeUsage | null;
|
|
103
|
+
}
|
|
104
|
+
interface ContributorSearchTraceSummary {
|
|
105
|
+
usedDeterministicFallback: boolean;
|
|
106
|
+
validatorStatus: ContributorSearchValidatorStatus;
|
|
107
|
+
validatorReasonCode: string | null;
|
|
108
|
+
validatorReason: string | null;
|
|
109
|
+
}
|
|
110
|
+
interface ContributorSearchMetadata {
|
|
111
|
+
version: typeof CONTRIBUTOR_SEARCH_METADATA_VERSION;
|
|
112
|
+
outcome: ContributorSearchOutcome;
|
|
113
|
+
confidence: ContributorSearchConfidence;
|
|
114
|
+
selectedCandidateId: string | null;
|
|
115
|
+
shortlistCandidateIds: string[];
|
|
116
|
+
relatedCandidateIds: string[];
|
|
117
|
+
rejectedCandidateIds: string[];
|
|
118
|
+
candidateCount: number;
|
|
119
|
+
shortlistCount: number;
|
|
120
|
+
intentQueries: string[];
|
|
121
|
+
degraded: ContributorSearchDegradedOutcome | null;
|
|
122
|
+
judge: ContributorSearchJudgeSnapshot;
|
|
123
|
+
provenance: ContributorSearchMetadataSource[];
|
|
124
|
+
trace: ContributorSearchTraceSummary;
|
|
125
|
+
}
|
|
126
|
+
interface ContributorSearchTraceRecord {
|
|
127
|
+
toolId: string | null;
|
|
128
|
+
toolName: string | null;
|
|
129
|
+
timestampMs: number | null;
|
|
130
|
+
searchMetadata: ContributorSearchMetadata;
|
|
131
|
+
}
|
|
132
|
+
interface ContributorSearchResolution {
|
|
133
|
+
outcome: ContributorSearchOutcome;
|
|
134
|
+
selectedCandidate: SearchCandidate | null;
|
|
135
|
+
shortlist: SearchCandidate[];
|
|
136
|
+
relatedCandidates: SearchCandidate[];
|
|
137
|
+
rejectedCandidates: SearchCandidate[];
|
|
138
|
+
confidence: ContributorSearchConfidence;
|
|
139
|
+
reason: string;
|
|
140
|
+
degraded: ContributorSearchDegradedOutcome | null;
|
|
141
|
+
searchMetadata: ContributorSearchMetadata;
|
|
142
|
+
}
|
|
143
|
+
interface ContributorSearchValidationExpectation {
|
|
144
|
+
outcome: ContributorSearchOutcome;
|
|
145
|
+
selectedCandidateId?: string | null;
|
|
146
|
+
degradedReasonCode?: ContributorSearchDegradedReasonCode | null;
|
|
147
|
+
}
|
|
148
|
+
interface ContributorSearchValidationArtifact {
|
|
149
|
+
version: typeof CONTRIBUTOR_SEARCH_VALIDATION_VERSION;
|
|
150
|
+
generatedAt: string;
|
|
151
|
+
caseId: string;
|
|
152
|
+
caseKind: ContributorSearchValidationCaseKind;
|
|
153
|
+
rawRequest: string;
|
|
154
|
+
intents: SearchIntent[];
|
|
155
|
+
candidates: SearchCandidate[];
|
|
156
|
+
resolution: {
|
|
157
|
+
outcome: ContributorSearchOutcome;
|
|
158
|
+
selectedCandidateId: string | null;
|
|
159
|
+
shortlistCandidateIds: string[];
|
|
160
|
+
relatedCandidateIds: string[];
|
|
161
|
+
rejectedCandidateIds: string[];
|
|
162
|
+
confidence: ContributorSearchConfidence;
|
|
163
|
+
reason: string;
|
|
164
|
+
degradedReasonCode: ContributorSearchDegradedReasonCode | null;
|
|
165
|
+
};
|
|
166
|
+
searchMetadata: ContributorSearchMetadata;
|
|
167
|
+
expectation?: ContributorSearchValidationExpectation;
|
|
168
|
+
}
|
|
169
|
+
interface ResolveContributorSearchParams {
|
|
170
|
+
rawRequest: string;
|
|
171
|
+
intents: SearchIntent[];
|
|
172
|
+
candidates: SearchCandidate[];
|
|
173
|
+
judge?: ContributorSearchJudge;
|
|
174
|
+
helperConfig?: ContributorSearchConfig;
|
|
175
|
+
contributorConfig?: ContributorSearchConfig;
|
|
176
|
+
overrides?: ContributorSearchConfig;
|
|
177
|
+
instructions?: string;
|
|
178
|
+
isCandidateValid?: (candidate: SearchCandidate) => boolean;
|
|
179
|
+
traceLabel?: string | null;
|
|
180
|
+
}
|
|
181
|
+
declare class ContributorSearchBudgetExceededError extends Error {
|
|
182
|
+
constructor(message?: string);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Configuration options for initializing the ContextClient
|
|
187
|
+
*/
|
|
188
|
+
interface ContextClientOptions {
|
|
189
|
+
/**
|
|
190
|
+
* Your Context Protocol API key
|
|
191
|
+
* @example "sk_live_abc123..."
|
|
192
|
+
*/
|
|
193
|
+
apiKey: string;
|
|
194
|
+
/**
|
|
195
|
+
* Base URL for the Context Protocol API
|
|
196
|
+
* @default "https://www.ctxprotocol.com"
|
|
197
|
+
*/
|
|
198
|
+
baseUrl?: string;
|
|
199
|
+
/**
|
|
200
|
+
* Request timeout for non-streaming API calls in milliseconds.
|
|
201
|
+
* @default 300000
|
|
202
|
+
*/
|
|
203
|
+
requestTimeoutMs?: number;
|
|
204
|
+
/**
|
|
205
|
+
* Request timeout for establishing streaming API calls in milliseconds.
|
|
206
|
+
* @default 600000
|
|
207
|
+
*/
|
|
208
|
+
streamTimeoutMs?: number;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* An individual MCP tool exposed by a tool listing
|
|
212
|
+
*/
|
|
213
|
+
interface McpToolRateLimitHints {
|
|
214
|
+
/** Suggested request budget for this method */
|
|
215
|
+
maxRequestsPerMinute?: number;
|
|
216
|
+
/** Suggested parallel call ceiling for this method */
|
|
217
|
+
maxConcurrency?: number;
|
|
218
|
+
/** Suggested minimum delay between sequential calls */
|
|
219
|
+
cooldownMs?: number;
|
|
220
|
+
/** Whether this method already supports bulk/batch retrieval */
|
|
221
|
+
supportsBulk?: boolean;
|
|
222
|
+
/** Preferred batch-oriented methods to call instead of fan-out loops */
|
|
223
|
+
recommendedBatchTools?: string[];
|
|
224
|
+
/** Optional human-readable notes for planning */
|
|
225
|
+
notes?: string;
|
|
226
|
+
}
|
|
227
|
+
type DiscoveryMode = "query" | "execute";
|
|
228
|
+
type McpToolSurface = "answer" | "execute" | "both";
|
|
229
|
+
type McpToolLatencyClass = "instant" | "fast" | "slow" | "streaming";
|
|
230
|
+
interface McpToolPricingMeta {
|
|
231
|
+
executeUsd?: string;
|
|
232
|
+
queryUsd?: string;
|
|
233
|
+
[key: string]: unknown;
|
|
234
|
+
}
|
|
235
|
+
interface McpToolMeta {
|
|
236
|
+
/** Declared method surface */
|
|
237
|
+
surface?: McpToolSurface;
|
|
238
|
+
/** Whether this method can be selected in query mode */
|
|
239
|
+
queryEligible?: boolean;
|
|
240
|
+
/** Declared latency class for planner/runtime gating */
|
|
241
|
+
latencyClass?: McpToolLatencyClass;
|
|
242
|
+
/** Method-level pricing metadata */
|
|
243
|
+
pricing?: McpToolPricingMeta;
|
|
244
|
+
/** Derived discovery flag for execute eligibility */
|
|
245
|
+
executeEligible?: boolean;
|
|
246
|
+
/** Derived discovery field for explicit execute pricing visibility */
|
|
247
|
+
executePriceUsd?: string;
|
|
248
|
+
/** Context injection requirements handled by the Context runtime */
|
|
249
|
+
contextRequirements?: string[];
|
|
250
|
+
/**
|
|
251
|
+
* Optional planner/runtime pacing hints.
|
|
252
|
+
* Tool contributors can publish these to reduce rate-limit failures.
|
|
253
|
+
*/
|
|
254
|
+
rateLimit?: McpToolRateLimitHints;
|
|
255
|
+
rateLimitHints?: McpToolRateLimitHints;
|
|
256
|
+
/** Flat aliases accepted for convenience */
|
|
257
|
+
maxRequestsPerMinute?: number;
|
|
258
|
+
maxConcurrency?: number;
|
|
259
|
+
cooldownMs?: number;
|
|
260
|
+
supportsBulk?: boolean;
|
|
261
|
+
recommendedBatchTools?: string[];
|
|
262
|
+
notes?: string;
|
|
263
|
+
[key: string]: unknown;
|
|
264
|
+
}
|
|
265
|
+
interface StructuredMethodGuidanceHints {
|
|
266
|
+
/** Suggested call-order sequence extracted from method descriptions */
|
|
267
|
+
callOrderHints?: string[];
|
|
268
|
+
/** Parameter usage caveats extracted from method descriptions */
|
|
269
|
+
parameterCaveats?: string[];
|
|
270
|
+
/** Edge-case behavior notes extracted from method descriptions */
|
|
271
|
+
edgeCaseNotes?: string[];
|
|
272
|
+
}
|
|
273
|
+
interface McpTool {
|
|
274
|
+
/** Name of the MCP tool method */
|
|
275
|
+
name: string;
|
|
276
|
+
/** Description of what this method does */
|
|
277
|
+
description: string;
|
|
278
|
+
/**
|
|
279
|
+
* JSON Schema for the input arguments this tool accepts.
|
|
280
|
+
* Used by LLMs to generate correct arguments.
|
|
281
|
+
*/
|
|
282
|
+
inputSchema?: Record<string, unknown>;
|
|
283
|
+
/**
|
|
284
|
+
* JSON Schema for the output this tool returns.
|
|
285
|
+
* Used by LLMs to understand the response structure.
|
|
286
|
+
*/
|
|
287
|
+
outputSchema?: Record<string, unknown>;
|
|
288
|
+
/** MCP metadata extensions (context injection, rate-limit hints) */
|
|
289
|
+
_meta?: McpToolMeta;
|
|
290
|
+
/** Explicit execute eligibility in discovery responses */
|
|
291
|
+
executeEligible?: boolean;
|
|
292
|
+
/** Explicit execute price visibility in discovery responses */
|
|
293
|
+
executePriceUsd?: string | null;
|
|
294
|
+
/** Whether this method has normalized structured guidance hints */
|
|
295
|
+
hasStructuredGuidance?: boolean;
|
|
296
|
+
/** Optional structured guidance hints derived from the method description */
|
|
297
|
+
structuredGuidance?: StructuredMethodGuidanceHints;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Represents a tool available on the Context Protocol marketplace
|
|
301
|
+
*/
|
|
302
|
+
interface Tool {
|
|
303
|
+
/** Unique identifier for the tool (UUID) */
|
|
304
|
+
id: string;
|
|
305
|
+
/** Human-readable name of the tool */
|
|
306
|
+
name: string;
|
|
307
|
+
/** Description of what the tool does */
|
|
308
|
+
description: string;
|
|
309
|
+
/** Price per execution in USDC */
|
|
310
|
+
price: string;
|
|
311
|
+
/** Tool category (e.g., "defi", "nft") */
|
|
312
|
+
category?: string;
|
|
313
|
+
/** Whether the tool is verified by Context Protocol */
|
|
314
|
+
isVerified?: boolean;
|
|
315
|
+
/** Tool type - currently always "mcp" */
|
|
316
|
+
kind?: string;
|
|
317
|
+
/**
|
|
318
|
+
* Available MCP tool methods
|
|
319
|
+
* Use items from this array as `toolName` when executing
|
|
320
|
+
*/
|
|
321
|
+
mcpTools?: McpTool[];
|
|
322
|
+
/** Total number of queries processed */
|
|
323
|
+
totalQueries?: number;
|
|
324
|
+
/** Success rate percentage (0-100) */
|
|
325
|
+
successRate?: string;
|
|
326
|
+
/** Uptime percentage (0-100) */
|
|
327
|
+
uptimePercent?: string;
|
|
328
|
+
/** Total USDC staked by the developer */
|
|
329
|
+
totalStaked?: string;
|
|
330
|
+
/** Whether the tool has "Proven" status (100+ queries, >95% success, >98% uptime) */
|
|
331
|
+
isProven?: boolean;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Response from the tools search endpoint
|
|
335
|
+
*/
|
|
336
|
+
interface SearchResponse {
|
|
337
|
+
/** Array of matching tools */
|
|
338
|
+
tools: Tool[];
|
|
339
|
+
/** Discovery mode used by the server */
|
|
340
|
+
mode?: DiscoveryMode;
|
|
341
|
+
/** The search query that was used */
|
|
342
|
+
query: string;
|
|
343
|
+
/** Total number of results */
|
|
344
|
+
count: number;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Options for searching tools
|
|
348
|
+
*/
|
|
349
|
+
interface SearchOptions {
|
|
350
|
+
/** Search query (semantic search) */
|
|
351
|
+
query?: string;
|
|
352
|
+
/** Maximum number of results (1-50, default 10) */
|
|
353
|
+
limit?: number;
|
|
354
|
+
/** Discovery mode with billing semantics */
|
|
355
|
+
mode?: DiscoveryMode;
|
|
356
|
+
/** Optional explicit method surface filter */
|
|
357
|
+
surface?: McpToolSurface;
|
|
358
|
+
/** Require methods marked query eligible */
|
|
359
|
+
queryEligible?: boolean;
|
|
360
|
+
/** Require explicit method execute pricing */
|
|
361
|
+
requireExecutePricing?: boolean;
|
|
362
|
+
/** Exclude methods by latency class */
|
|
363
|
+
excludeLatencyClasses?: McpToolLatencyClass[];
|
|
364
|
+
/** Convenience switch to exclude slow methods in query mode */
|
|
365
|
+
excludeSlow?: boolean;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Options for executing a tool
|
|
369
|
+
*/
|
|
370
|
+
interface ExecuteOptions {
|
|
371
|
+
/** The UUID of the tool to execute (from search results) */
|
|
372
|
+
toolId: string;
|
|
373
|
+
/** The specific MCP tool name to call (from tool's mcpTools array) */
|
|
374
|
+
toolName: string;
|
|
375
|
+
/** Arguments to pass to the tool */
|
|
376
|
+
args?: Record<string, unknown>;
|
|
377
|
+
/**
|
|
378
|
+
* Optional idempotency key (UUID recommended).
|
|
379
|
+
* Reuse the same key when retrying the same logical request.
|
|
380
|
+
*/
|
|
381
|
+
idempotencyKey?: string;
|
|
382
|
+
/** Explicit execute mode label for request clarity */
|
|
383
|
+
mode?: "execute";
|
|
384
|
+
/** Optional execute session identifier */
|
|
385
|
+
sessionId?: string;
|
|
386
|
+
/** Optional per-session spend budget envelope (USD) */
|
|
387
|
+
maxSpendUsd?: string;
|
|
388
|
+
/** Request session closure after this execute call settles */
|
|
389
|
+
closeSession?: boolean;
|
|
390
|
+
}
|
|
391
|
+
type ExecuteSessionStatus = "open" | "closed" | "expired";
|
|
392
|
+
interface ExecuteSessionSpend {
|
|
393
|
+
mode: "execute";
|
|
394
|
+
sessionId: string | null;
|
|
395
|
+
methodPrice: string;
|
|
396
|
+
spent: string;
|
|
397
|
+
remaining: string | null;
|
|
398
|
+
maxSpend: string | null;
|
|
399
|
+
/** Optional lifecycle fields when the API returns session state */
|
|
400
|
+
status?: ExecuteSessionStatus;
|
|
401
|
+
expiresAt?: string;
|
|
402
|
+
closeRequested?: boolean;
|
|
403
|
+
pendingAccruedCount?: number;
|
|
404
|
+
pendingAccruedUsd?: string;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Successful execution response from the API
|
|
408
|
+
*/
|
|
409
|
+
interface ExecuteApiSuccessResponse {
|
|
410
|
+
success: true;
|
|
411
|
+
mode: "execute";
|
|
412
|
+
/** The result data from the tool execution */
|
|
413
|
+
result: unknown;
|
|
414
|
+
/** Information about the executed tool */
|
|
415
|
+
tool: {
|
|
416
|
+
id: string;
|
|
417
|
+
name: string;
|
|
418
|
+
};
|
|
419
|
+
/** Method-level execute pricing used for this call */
|
|
420
|
+
method: {
|
|
421
|
+
name: string;
|
|
422
|
+
executePriceUsd: string;
|
|
423
|
+
};
|
|
424
|
+
/** Spend envelope visibility for execute sessions */
|
|
425
|
+
session: ExecuteSessionSpend;
|
|
426
|
+
/** Execution duration in milliseconds */
|
|
427
|
+
durationMs: number;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Error response from the API
|
|
431
|
+
*/
|
|
432
|
+
interface ExecuteApiErrorResponse {
|
|
433
|
+
/** Human-readable error message */
|
|
434
|
+
error: string;
|
|
435
|
+
/** Explicit mode label for clarity */
|
|
436
|
+
mode?: "execute";
|
|
437
|
+
/** Error code for programmatic handling */
|
|
438
|
+
code?: ContextErrorCode;
|
|
439
|
+
/** URL to help resolve the issue */
|
|
440
|
+
helpUrl?: string;
|
|
441
|
+
/** Optional spend envelope context when available */
|
|
442
|
+
session?: ExecuteSessionSpend;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Raw API response from the execute endpoint
|
|
446
|
+
*/
|
|
447
|
+
type ExecuteApiResponse = ExecuteApiSuccessResponse | ExecuteApiErrorResponse;
|
|
448
|
+
interface ExecuteSessionStartOptions {
|
|
449
|
+
/** Maximum spend budget for the session (USD string) */
|
|
450
|
+
maxSpendUsd: string;
|
|
451
|
+
}
|
|
452
|
+
interface ExecuteSessionApiSuccessResponse {
|
|
453
|
+
success: true;
|
|
454
|
+
mode: "execute";
|
|
455
|
+
session: ExecuteSessionSpend;
|
|
456
|
+
}
|
|
457
|
+
type ExecuteSessionApiResponse = ExecuteSessionApiSuccessResponse | ExecuteApiErrorResponse;
|
|
458
|
+
interface ExecuteSessionResult {
|
|
459
|
+
mode: "execute";
|
|
460
|
+
session: ExecuteSessionSpend;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* The resolved result returned to the user after SDK processing
|
|
464
|
+
*/
|
|
465
|
+
interface ExecutionResult<T = unknown> {
|
|
466
|
+
mode: "execute";
|
|
467
|
+
/** The data returned by the tool */
|
|
468
|
+
result: T;
|
|
469
|
+
/** Information about the executed tool */
|
|
470
|
+
tool: {
|
|
471
|
+
id: string;
|
|
472
|
+
name: string;
|
|
473
|
+
};
|
|
474
|
+
/** Method-level execute pricing used for this call */
|
|
475
|
+
method: {
|
|
476
|
+
name: string;
|
|
477
|
+
executePriceUsd: string;
|
|
478
|
+
};
|
|
479
|
+
/** Spend envelope visibility for execute calls */
|
|
480
|
+
session: ExecuteSessionSpend;
|
|
481
|
+
/** Execution duration in milliseconds */
|
|
482
|
+
durationMs: number;
|
|
483
|
+
}
|
|
484
|
+
/** Supported orchestration depth modes for query execution. */
|
|
485
|
+
type QueryDepth = "fast" | "auto" | "deep";
|
|
486
|
+
type QueryDeepMode = "deep" | "deep-light" | "deep-heavy";
|
|
487
|
+
type QueryClarificationPolicy = "return" | "auto" | "error";
|
|
488
|
+
type QueryOutcomeType = "answer" | "clarification_required" | "capability_miss";
|
|
489
|
+
type QueryResponseShape = "answer" | "answer_with_evidence" | "evidence_only";
|
|
490
|
+
type QueryResponseEnvelopeViewType = "table" | "leaderboard" | "heatmap" | "timeseries";
|
|
491
|
+
interface QueryClarificationOption {
|
|
492
|
+
id: string;
|
|
493
|
+
toolId: string;
|
|
494
|
+
toolName: string;
|
|
495
|
+
methodName: string;
|
|
496
|
+
label: string;
|
|
497
|
+
description: string;
|
|
498
|
+
fitScore: number;
|
|
499
|
+
recommended: boolean;
|
|
500
|
+
}
|
|
501
|
+
interface QueryClarificationPayload {
|
|
502
|
+
question: string;
|
|
503
|
+
options: QueryClarificationOption[];
|
|
504
|
+
allowFreeform: boolean;
|
|
505
|
+
recommendedOptionId: string;
|
|
506
|
+
originalQuery: string;
|
|
507
|
+
}
|
|
508
|
+
interface QueryCapabilityMissPayload {
|
|
509
|
+
message: string;
|
|
510
|
+
missingCapabilities: string[];
|
|
511
|
+
suggestedRewrites: string[];
|
|
512
|
+
originalQuery: string;
|
|
513
|
+
}
|
|
514
|
+
interface QueryAssumptionMetadata {
|
|
515
|
+
mode: "auto";
|
|
516
|
+
optionId: string;
|
|
517
|
+
label: string;
|
|
518
|
+
reason: string;
|
|
519
|
+
}
|
|
520
|
+
type QueryClarificationDecisionReasonCode = "rollout_disabled" | "no_grounded_candidates" | "single_grounded_interpretation" | "required_discriminator_ambiguity" | "contract_scope_ambiguity" | "cost_or_latency_ambiguity" | "semantic_scope_ambiguity" | "capability_miss";
|
|
521
|
+
type QueryAttemptForkReason = "manual_fork" | "clarification_branch" | "bounded_rediscovery" | "resume_replay" | "patch_retry" | "unknown";
|
|
522
|
+
interface QueryClarificationEvidenceSources {
|
|
523
|
+
usesMethodSchemas: boolean;
|
|
524
|
+
usesProbeArgs: boolean;
|
|
525
|
+
usesMethodMetadata: boolean;
|
|
526
|
+
usesToolSelectionContext: boolean;
|
|
527
|
+
usesLlmSelection: boolean;
|
|
528
|
+
}
|
|
529
|
+
interface QueryClarificationCandidateSummary {
|
|
530
|
+
optionId: string;
|
|
531
|
+
fitScore: number;
|
|
532
|
+
llmRelevanceScore: number | null;
|
|
533
|
+
requiredParams: string[];
|
|
534
|
+
unresolvedRequiredParams: string[];
|
|
535
|
+
probeArgKeys: string[];
|
|
536
|
+
inputFieldNames: string[];
|
|
537
|
+
outputKeys: string[];
|
|
538
|
+
latencyClass: string;
|
|
539
|
+
executePriceUsd: string | null;
|
|
540
|
+
queryEligible: boolean;
|
|
541
|
+
}
|
|
542
|
+
interface QueryClarificationDiagnostics {
|
|
543
|
+
orchestrationMode: string;
|
|
544
|
+
rolloutStage: string;
|
|
545
|
+
shadowMode: boolean;
|
|
546
|
+
policy: QueryClarificationPolicy;
|
|
547
|
+
outcomeType: QueryOutcomeType;
|
|
548
|
+
triggered: boolean;
|
|
549
|
+
optionCount: number;
|
|
550
|
+
candidateCount: number;
|
|
551
|
+
viableCandidateCount: number;
|
|
552
|
+
recommendedOptionId: string | null;
|
|
553
|
+
recommendedOptionReason: string | null;
|
|
554
|
+
autoResolved: boolean;
|
|
555
|
+
autoSelectEnabled: boolean;
|
|
556
|
+
assumptionMade: QueryAssumptionMetadata | null;
|
|
557
|
+
missingCapability: string | null;
|
|
558
|
+
decisionReasonCode: QueryClarificationDecisionReasonCode;
|
|
559
|
+
decisionSignals: string[];
|
|
560
|
+
evidenceSources: QueryClarificationEvidenceSources;
|
|
561
|
+
comparedOptionIds: string[];
|
|
562
|
+
decisionStrategy: "deterministic" | "llm_primary";
|
|
563
|
+
judgeAttempted: boolean;
|
|
564
|
+
judgeApplied: boolean;
|
|
565
|
+
judgeOutcomeType: QueryOutcomeType | null;
|
|
566
|
+
judgeConfidence: number | null;
|
|
567
|
+
judgeReason: string | null;
|
|
568
|
+
judgeError: string | null;
|
|
569
|
+
validatorReason: string | null;
|
|
570
|
+
fallbackReason: string | null;
|
|
571
|
+
copyStrategy: "deterministic" | "llm_rewritten";
|
|
572
|
+
rewriteAttempted: boolean;
|
|
573
|
+
rewriteApplied: boolean;
|
|
574
|
+
rewriteError: string | null;
|
|
575
|
+
candidateSummaries: QueryClarificationCandidateSummary[];
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Options for the agentic query endpoint (pay-per-response).
|
|
579
|
+
*
|
|
580
|
+
* Unlike `execute()` which calls a single tool once, `query()` sends a
|
|
581
|
+
* natural-language question and lets the server handle discovery-first
|
|
582
|
+
* orchestration (`discover/probe -> plan-from-evidence -> execute ->
|
|
583
|
+
* bounded fallback`) plus synthesis.
|
|
584
|
+
* One flat fee covers up to 100 MCP skill calls per tool.
|
|
585
|
+
*/
|
|
586
|
+
interface QueryOptions {
|
|
587
|
+
/** The natural-language question to answer */
|
|
588
|
+
query: string;
|
|
589
|
+
/**
|
|
590
|
+
* How the SDK should handle clarification-required pre-plan situations:
|
|
591
|
+
* - `return`: surface a structured clarification result to the caller
|
|
592
|
+
* - `auto`: enable clarification auto-select and continue with the server's deterministic recommended option
|
|
593
|
+
* - `error`: turn structured clarification/capability outcomes into terminal errors
|
|
594
|
+
*/
|
|
595
|
+
clarificationPolicy?: QueryClarificationPolicy;
|
|
596
|
+
/**
|
|
597
|
+
* Optional tool IDs to use. When omitted the server discovers tools
|
|
598
|
+
* automatically (Auto Mode). When provided, only these tools are used
|
|
599
|
+
* (Manual Mode).
|
|
600
|
+
*/
|
|
601
|
+
tools?: string[];
|
|
602
|
+
/**
|
|
603
|
+
* Resume a prior durable query attempt from its latest checkpoint.
|
|
604
|
+
* Cannot be combined with `tools` or `forkFrom`.
|
|
605
|
+
*/
|
|
606
|
+
resumeFrom?: QueryAttemptReference;
|
|
607
|
+
/**
|
|
608
|
+
* Fork a new durable query attempt from a previous attempt.
|
|
609
|
+
* Optional `reason` keeps the server's non-breaking lineage metadata honest.
|
|
610
|
+
* Cannot be combined with `tools` or `resumeFrom`.
|
|
611
|
+
*/
|
|
612
|
+
forkFrom?: QueryForkReference;
|
|
613
|
+
/**
|
|
614
|
+
* Optional answer model ID for final synthesis.
|
|
615
|
+
* Supported IDs are published by the Context API. Ignored when
|
|
616
|
+
* `responseShape` is `evidence_only` because synthesis is skipped.
|
|
617
|
+
*/
|
|
618
|
+
answerModelId?: string;
|
|
619
|
+
/**
|
|
620
|
+
* Structured response mode for query answers.
|
|
621
|
+
* - `answer`: backward-compatible natural-language answer
|
|
622
|
+
* - `answer_with_evidence`: prose answer plus a structured evidence package
|
|
623
|
+
* - `evidence_only`: structured evidence package with a machine-friendly summary
|
|
624
|
+
*/
|
|
625
|
+
responseShape?: QueryResponseShape;
|
|
626
|
+
/**
|
|
627
|
+
* Include execution data inline in the query response.
|
|
628
|
+
* Useful for headless agents that need raw structured outputs.
|
|
629
|
+
* Handshake completion remains a chat-only flow today; raw execution data
|
|
630
|
+
* is not a typed resume/callback contract for approvals.
|
|
631
|
+
*/
|
|
632
|
+
includeData?: boolean;
|
|
633
|
+
/**
|
|
634
|
+
* Persist execution data to Vercel Blob and return a download URL.
|
|
635
|
+
* Useful for large payload workflows where inline JSON is not ideal.
|
|
636
|
+
*/
|
|
637
|
+
includeDataUrl?: boolean;
|
|
638
|
+
/**
|
|
639
|
+
* Include machine-readable developer trace output for this query response.
|
|
640
|
+
* When enabled, the server may return summary counters plus diagnostics
|
|
641
|
+
* for lane selection, scout probe adequacy, and bounded fallback behavior.
|
|
642
|
+
*/
|
|
643
|
+
includeDeveloperTrace?: boolean;
|
|
644
|
+
/**
|
|
645
|
+
* Query orchestration depth mode:
|
|
646
|
+
* - `fast`: lower-latency path
|
|
647
|
+
* - `auto`: server decides between fast/deep
|
|
648
|
+
* - `deep`: full completeness-oriented path
|
|
649
|
+
*/
|
|
650
|
+
queryDepth?: QueryDepth;
|
|
651
|
+
/**
|
|
652
|
+
* Development/testing only: force the server's internal deep lane.
|
|
653
|
+
* `deep` is the canonical value. Legacy `deep-light` / `deep-heavy`
|
|
654
|
+
* aliases are still accepted temporarily for compatibility and normalize
|
|
655
|
+
* to the same runtime lane. Invalid when `queryDepth` is `fast`.
|
|
656
|
+
*/
|
|
657
|
+
debugScoutDeepMode?: QueryDeepMode;
|
|
658
|
+
/**
|
|
659
|
+
* Optional idempotency key (UUID recommended).
|
|
660
|
+
* Reuse the same key when retrying the same logical request.
|
|
661
|
+
*/
|
|
662
|
+
idempotencyKey?: string;
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Tool reference attached to developer trace timeline steps.
|
|
666
|
+
*/
|
|
667
|
+
interface QueryDeveloperTraceToolRef {
|
|
668
|
+
id?: string;
|
|
669
|
+
name?: string;
|
|
670
|
+
method?: string;
|
|
671
|
+
[key: string]: unknown;
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Loop metadata attached to developer trace timeline steps.
|
|
675
|
+
*/
|
|
676
|
+
interface QueryDeveloperTraceLoopInfo {
|
|
677
|
+
name?: string;
|
|
678
|
+
iteration?: number;
|
|
679
|
+
maxIterations?: number;
|
|
680
|
+
[key: string]: unknown;
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* Tool selection metadata attached to discovery/planning diagnostics.
|
|
684
|
+
*/
|
|
685
|
+
interface QueryDeveloperTraceToolSelection {
|
|
686
|
+
toolId: string;
|
|
687
|
+
toolName: string;
|
|
688
|
+
selectedMethodCount: number;
|
|
689
|
+
selectedMethods: string[];
|
|
690
|
+
omittedSelectedMethodCount: number;
|
|
691
|
+
priceUsd?: string;
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Initial planner diagnostic details.
|
|
695
|
+
*/
|
|
696
|
+
interface QueryPlanningTraceDiagnostic {
|
|
697
|
+
plannerQuery: string;
|
|
698
|
+
scoutEvidenceAttached: boolean;
|
|
699
|
+
scoutEvidencePromptBlock: string | null;
|
|
700
|
+
allowedModules: string[];
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Rediscovery/fallback diagnostic details.
|
|
704
|
+
*/
|
|
705
|
+
interface QueryRediscoveryTraceDiagnostic {
|
|
706
|
+
considered: boolean;
|
|
707
|
+
executed: boolean;
|
|
708
|
+
skipReason: string | null;
|
|
709
|
+
missingCapability: string | null;
|
|
710
|
+
rediscoveryQuery: string | null;
|
|
711
|
+
capabilityLooksLikeSearchNeed: boolean;
|
|
712
|
+
allowSearchFallbackOnElapsedCap: boolean;
|
|
713
|
+
searchFallbackUsed: boolean;
|
|
714
|
+
preRediscoveryBudgetReasonCode: string | null;
|
|
715
|
+
candidateSearchResults: QueryDeveloperTraceToolSelection[];
|
|
716
|
+
selectedAlternatives: QueryDeveloperTraceToolSelection[];
|
|
717
|
+
mergedTools: QueryDeveloperTraceToolSelection[];
|
|
718
|
+
usingPaidFallback: boolean;
|
|
719
|
+
branchPlan: QueryPlanningTraceDiagnostic | null;
|
|
720
|
+
}
|
|
721
|
+
interface QueryCompletenessRepairEvent {
|
|
722
|
+
attempt: number;
|
|
723
|
+
outcome: "attempted" | "skipped_by_guardrail" | "skipped_no_retry_budget" | "skipped_needs_different_tools" | "skipped_no_retry_path" | "patch_failed" | "replan_failed" | "patched" | "replanned";
|
|
724
|
+
semanticRetryCount: number;
|
|
725
|
+
maxSemanticRetries: number;
|
|
726
|
+
strategy: "patch" | "replan" | null;
|
|
727
|
+
summary: string | null;
|
|
728
|
+
failReason: string | null;
|
|
729
|
+
requestedReplan: boolean;
|
|
730
|
+
hadSyntaxFix: boolean;
|
|
731
|
+
editCount: number | null;
|
|
732
|
+
skipReason: string | null;
|
|
733
|
+
boundedAnswerReason: "retry_guardrail_same_endpoint_fanout" | "retry_guardrail_upstream_abort" | null;
|
|
734
|
+
blockingDiagnostics: Array<{
|
|
735
|
+
code: string;
|
|
736
|
+
severity: string;
|
|
737
|
+
message: string;
|
|
738
|
+
}>;
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* Rich developer-trace diagnostics for discovery-first orchestration internals.
|
|
742
|
+
*/
|
|
743
|
+
interface QueryDeveloperTraceDiagnostics {
|
|
744
|
+
selection: {
|
|
745
|
+
selectedDepth: string;
|
|
746
|
+
deepMode: string | null;
|
|
747
|
+
debugScoutDeepMode: string | null;
|
|
748
|
+
plannerReasoningStage: string;
|
|
749
|
+
scoutEnabled: boolean;
|
|
750
|
+
preserveFastOneShot: boolean;
|
|
751
|
+
candidateMethodCount: number;
|
|
752
|
+
scoutProbeStatus: string;
|
|
753
|
+
scoutProbeAdequacy: string;
|
|
754
|
+
scoutProbeConfidence: number;
|
|
755
|
+
scoutMetadataConfidence: number;
|
|
756
|
+
scoutProbeQuerySafeCandidateCount: number;
|
|
757
|
+
scoutProbeRankedMethodCount: number;
|
|
758
|
+
scoutProbeAmbiguityPoolCount: number;
|
|
759
|
+
scoutProbeShortlistedMethodCount: number;
|
|
760
|
+
scoutProbeMissingCapability: string | null;
|
|
761
|
+
scoutPrePlanProbeCalls: number;
|
|
762
|
+
scoutPrePlanProbeBudgetReasonCode: string | null;
|
|
763
|
+
scoutChangedInitialPlan: boolean;
|
|
764
|
+
scoutChangedPlannerReasoningStage: boolean;
|
|
765
|
+
scoutInitialSelectedDepth: string;
|
|
766
|
+
scoutInitialDeepMode: string | null;
|
|
767
|
+
scoutInitialPlannerReasoningStage: string;
|
|
768
|
+
scoutInitialReasonCode: string;
|
|
769
|
+
scoutFinalReasonCode: string;
|
|
770
|
+
scoutEvidenceAttachedToPlanning: boolean;
|
|
771
|
+
scoutLlmSelectionUsed: boolean;
|
|
772
|
+
scoutLlmSelectionFallback: boolean;
|
|
773
|
+
scoutLlmSelectionLatencyMs: number | null;
|
|
774
|
+
selectedTools: QueryDeveloperTraceToolSelection[];
|
|
775
|
+
};
|
|
776
|
+
planning: {
|
|
777
|
+
initial: QueryPlanningTraceDiagnostic;
|
|
778
|
+
};
|
|
779
|
+
cost?: {
|
|
780
|
+
planningCostUsd: number;
|
|
781
|
+
initialExecutionCostUsd: number;
|
|
782
|
+
rediscoveryAdditionalCostUsd: number;
|
|
783
|
+
synthesisCostUsd: number;
|
|
784
|
+
totalModelCostUsd: number;
|
|
785
|
+
toolCostUsd: number;
|
|
786
|
+
totalChargedUsd: number;
|
|
787
|
+
};
|
|
788
|
+
completeness: {
|
|
789
|
+
evaluations: unknown[];
|
|
790
|
+
repairEvents: QueryCompletenessRepairEvent[];
|
|
791
|
+
triggerNeedsDifferentTools: boolean;
|
|
792
|
+
triggerMissingCapability: string | null;
|
|
793
|
+
};
|
|
794
|
+
rediscovery: QueryRediscoveryTraceDiagnostic | null;
|
|
795
|
+
clarification?: QueryClarificationDiagnostics;
|
|
796
|
+
contributorSearches?: ContributorSearchTraceRecord[];
|
|
797
|
+
[key: string]: unknown;
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* A single developer-trace timeline step.
|
|
801
|
+
*/
|
|
802
|
+
interface QueryDeveloperTraceStep {
|
|
803
|
+
stepType?: string;
|
|
804
|
+
event?: string;
|
|
805
|
+
status?: string;
|
|
806
|
+
message?: string;
|
|
807
|
+
timestampMs?: number;
|
|
808
|
+
tool?: QueryDeveloperTraceToolRef;
|
|
809
|
+
attempt?: number;
|
|
810
|
+
loop?: QueryDeveloperTraceLoopInfo;
|
|
811
|
+
metadata?: Record<string, unknown>;
|
|
812
|
+
[key: string]: unknown;
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* Aggregate counters that summarize developer-trace behavior.
|
|
816
|
+
*/
|
|
817
|
+
interface QueryDeveloperTraceSummary {
|
|
818
|
+
toolCalls?: number;
|
|
819
|
+
retryCount?: number;
|
|
820
|
+
selfHealCount?: number;
|
|
821
|
+
fallbackCount?: number;
|
|
822
|
+
failureCount?: number;
|
|
823
|
+
recoveryCount?: number;
|
|
824
|
+
completionChecks?: number;
|
|
825
|
+
loopCount?: number;
|
|
826
|
+
[key: string]: unknown;
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* Developer Mode trace payload returned per query response (opt-in).
|
|
830
|
+
*/
|
|
831
|
+
interface QueryDeveloperTrace {
|
|
832
|
+
summary?: QueryDeveloperTraceSummary;
|
|
833
|
+
timeline?: QueryDeveloperTraceStep[];
|
|
834
|
+
requestId?: string;
|
|
835
|
+
query?: string;
|
|
836
|
+
source?: string;
|
|
837
|
+
diagnostics?: QueryDeveloperTraceDiagnostics;
|
|
838
|
+
[key: string]: unknown;
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* Information about a tool that was used during a query response
|
|
842
|
+
*/
|
|
843
|
+
interface QueryToolUsage {
|
|
844
|
+
/** Tool ID */
|
|
845
|
+
id: string;
|
|
846
|
+
/** Tool name */
|
|
847
|
+
name: string;
|
|
848
|
+
/** Number of MCP skill calls made for this tool */
|
|
849
|
+
skillCalls: number;
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* Cost breakdown for a query response.
|
|
853
|
+
* All values are strings representing USD amounts.
|
|
854
|
+
*/
|
|
855
|
+
interface QueryCost {
|
|
856
|
+
/** AI model inference cost */
|
|
857
|
+
modelCostUsd: string;
|
|
858
|
+
/** Sum of all tool fees */
|
|
859
|
+
toolCostUsd: string;
|
|
860
|
+
/** Total cost (model + tools) */
|
|
861
|
+
totalCostUsd: string;
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* High-level orchestration outcome metrics returned by the query API.
|
|
865
|
+
*/
|
|
866
|
+
interface QueryOrchestrationMetrics {
|
|
867
|
+
parityStage: string;
|
|
868
|
+
orchestrationMode: string;
|
|
869
|
+
/** Whether the first plan path succeeded without fallback. */
|
|
870
|
+
firstPassSuccess: boolean;
|
|
871
|
+
/** Whether execution signaled a missing capability on first pass. */
|
|
872
|
+
capabilityMissSignaled: boolean;
|
|
873
|
+
/** Whether bounded rediscovery/fallback executed. */
|
|
874
|
+
rediscoveryExecuted: boolean;
|
|
875
|
+
}
|
|
876
|
+
interface QueryAttemptReference {
|
|
877
|
+
sessionId: string;
|
|
878
|
+
attemptId: string;
|
|
879
|
+
}
|
|
880
|
+
/** Public fork handle for creating a new attempt from a prior Query session. */
|
|
881
|
+
interface QueryForkReference extends QueryAttemptReference {
|
|
882
|
+
reason?: QueryAttemptForkReason;
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
885
|
+
* Public continuation state returned by headless Query responses.
|
|
886
|
+
* Internal selected-tool lineage, Scout reuse, and clarification snapshots
|
|
887
|
+
* remain durable server state but are not exposed as chat-style payloads.
|
|
888
|
+
*/
|
|
889
|
+
interface QuerySessionState {
|
|
890
|
+
sessionId: string;
|
|
891
|
+
attemptId: string;
|
|
892
|
+
parentAttemptId: string | null;
|
|
893
|
+
rootAttemptId: string;
|
|
894
|
+
mode: "initial" | "resume" | "fork";
|
|
895
|
+
origin: "initial_request" | "resume" | "fork";
|
|
896
|
+
status: "active" | "completed" | "failed" | "aborted";
|
|
897
|
+
checkpoint: {
|
|
898
|
+
currentStage: string | null;
|
|
899
|
+
latestCheckpointArtifactId: string | null;
|
|
900
|
+
canonicalDatasetId: string | null;
|
|
901
|
+
executionProgramCurrentRevisionId: string | null;
|
|
902
|
+
};
|
|
903
|
+
}
|
|
904
|
+
interface QueryResponseEnvelopeFact {
|
|
905
|
+
id: string;
|
|
906
|
+
label: string;
|
|
907
|
+
path: string | null;
|
|
908
|
+
relevanceScore: number | null;
|
|
909
|
+
value: unknown;
|
|
910
|
+
}
|
|
911
|
+
interface QueryResponseEnvelopeSourceRef {
|
|
912
|
+
id: string;
|
|
913
|
+
provider: string | null;
|
|
914
|
+
dataset: string | null;
|
|
915
|
+
observedAt: string | null;
|
|
916
|
+
publishedAt: string | null;
|
|
917
|
+
artifactRef: string | null;
|
|
918
|
+
url: string | null;
|
|
919
|
+
note: string | null;
|
|
920
|
+
}
|
|
921
|
+
interface QueryResponseEnvelope {
|
|
922
|
+
responseShape: Exclude<QueryResponseShape, "answer">;
|
|
923
|
+
response: string;
|
|
924
|
+
summary: string;
|
|
925
|
+
evidence: {
|
|
926
|
+
facts: QueryResponseEnvelopeFact[];
|
|
927
|
+
sourceRefs: QueryResponseEnvelopeSourceRef[];
|
|
928
|
+
assumptions: string[];
|
|
929
|
+
knownUnknowns: string[];
|
|
930
|
+
retrievalPlanReasonCodes: string[];
|
|
931
|
+
};
|
|
932
|
+
artifacts: {
|
|
933
|
+
dataUrl: string | null;
|
|
934
|
+
canonicalDataRef: {
|
|
935
|
+
datasetId: string;
|
|
936
|
+
hash: string;
|
|
937
|
+
bytes: number;
|
|
938
|
+
publicDataUrl: string | null;
|
|
939
|
+
} | null;
|
|
940
|
+
stageArtifactKinds: string[];
|
|
941
|
+
};
|
|
942
|
+
view: {
|
|
943
|
+
type: QueryResponseEnvelopeViewType;
|
|
944
|
+
label: string;
|
|
945
|
+
} | null;
|
|
946
|
+
freshness: {
|
|
947
|
+
asOf: string | null;
|
|
948
|
+
sourceTimestamps: string[];
|
|
949
|
+
note: string;
|
|
950
|
+
};
|
|
951
|
+
confidence: {
|
|
952
|
+
level: "high" | "medium" | "low";
|
|
953
|
+
reason: string;
|
|
954
|
+
verifiedFactCount: number;
|
|
955
|
+
inferredFactCount: number;
|
|
956
|
+
gapCount: number;
|
|
957
|
+
gapSignals: Array<{
|
|
958
|
+
code: string;
|
|
959
|
+
severity: string;
|
|
960
|
+
detail: string;
|
|
961
|
+
}>;
|
|
962
|
+
};
|
|
963
|
+
usage: {
|
|
964
|
+
durationMs: number;
|
|
965
|
+
cost: QueryCost;
|
|
966
|
+
toolsUsed: QueryToolUsage[];
|
|
967
|
+
outcomeType: QueryOutcomeType;
|
|
968
|
+
orchestrationMetrics?: QueryOrchestrationMetrics;
|
|
969
|
+
};
|
|
970
|
+
}
|
|
971
|
+
interface QueryBaseResult {
|
|
972
|
+
/** The answer text or machine-friendly summary returned for this query. */
|
|
973
|
+
response: string;
|
|
974
|
+
/** Tools that were used to answer the query */
|
|
975
|
+
toolsUsed: QueryToolUsage[];
|
|
976
|
+
/** Cost breakdown */
|
|
977
|
+
cost: QueryCost;
|
|
978
|
+
/** Total duration in milliseconds */
|
|
979
|
+
durationMs: number;
|
|
980
|
+
/** Optional execution data from tools (when includeData=true) */
|
|
981
|
+
data?: unknown;
|
|
982
|
+
/** Optional blob URL for persisted execution data (when includeDataUrl=true) */
|
|
983
|
+
dataUrl?: string;
|
|
984
|
+
/** Optional machine-readable Developer Mode trace payload */
|
|
985
|
+
developerTrace?: QueryDeveloperTrace;
|
|
986
|
+
/** Optional orchestration outcome metrics for benchmarking and rollout analysis */
|
|
987
|
+
orchestrationMetrics?: QueryOrchestrationMetrics;
|
|
988
|
+
/**
|
|
989
|
+
* Optional public durable continuation handles for resume/fork flows.
|
|
990
|
+
* Query exposes handle-based continuation, not chat-style continuation payloads.
|
|
991
|
+
*/
|
|
992
|
+
querySession?: QuerySessionState;
|
|
993
|
+
}
|
|
994
|
+
/**
|
|
995
|
+
* The resolved result of a pay-per-response query
|
|
996
|
+
*/
|
|
997
|
+
type QueryResult = (QueryBaseResult & Partial<QueryResponseEnvelope> & {
|
|
998
|
+
outcomeType: "answer";
|
|
999
|
+
assumptionMade?: QueryAssumptionMetadata;
|
|
1000
|
+
}) | (QueryBaseResult & {
|
|
1001
|
+
outcomeType: "clarification_required";
|
|
1002
|
+
clarification: QueryClarificationPayload;
|
|
1003
|
+
}) | (QueryBaseResult & {
|
|
1004
|
+
outcomeType: "capability_miss";
|
|
1005
|
+
capabilityMiss: QueryCapabilityMissPayload;
|
|
1006
|
+
});
|
|
1007
|
+
/**
|
|
1008
|
+
* Successful response from the /api/v1/query endpoint
|
|
1009
|
+
*/
|
|
1010
|
+
type QueryApiSuccessResponse = {
|
|
1011
|
+
success: true;
|
|
1012
|
+
} & QueryResult;
|
|
1013
|
+
/**
|
|
1014
|
+
* Raw API response from the query endpoint
|
|
1015
|
+
*/
|
|
1016
|
+
type QueryApiResponse = QueryApiSuccessResponse | ExecuteApiErrorResponse;
|
|
1017
|
+
/** Emitted when a tool starts or changes execution status */
|
|
1018
|
+
interface QueryStreamToolStatusEvent {
|
|
1019
|
+
type: "tool-status";
|
|
1020
|
+
tool: {
|
|
1021
|
+
id: string;
|
|
1022
|
+
name: string;
|
|
1023
|
+
};
|
|
1024
|
+
status: string;
|
|
1025
|
+
}
|
|
1026
|
+
/** Emitted for each chunk of the AI response text */
|
|
1027
|
+
interface QueryStreamTextDeltaEvent {
|
|
1028
|
+
type: "text-delta";
|
|
1029
|
+
delta: string;
|
|
1030
|
+
}
|
|
1031
|
+
/** Emitted when the server streams developer trace updates/chunks */
|
|
1032
|
+
interface QueryStreamDeveloperTraceEvent {
|
|
1033
|
+
type: "developer-trace";
|
|
1034
|
+
trace: QueryDeveloperTrace;
|
|
1035
|
+
}
|
|
1036
|
+
/** Emitted when the full response is complete */
|
|
1037
|
+
interface QueryStreamDoneEvent {
|
|
1038
|
+
type: "done";
|
|
1039
|
+
result: QueryResult;
|
|
1040
|
+
}
|
|
1041
|
+
/** Emitted when the server reports a recoverable or terminal query error */
|
|
1042
|
+
interface QueryStreamErrorEvent {
|
|
1043
|
+
type: "error";
|
|
1044
|
+
error: string;
|
|
1045
|
+
code?: ContextErrorCode | string;
|
|
1046
|
+
scope?: string;
|
|
1047
|
+
reasonCode?: string;
|
|
1048
|
+
outcomeType?: Exclude<QueryOutcomeType, "answer">;
|
|
1049
|
+
clarification?: QueryClarificationPayload;
|
|
1050
|
+
capabilityMiss?: QueryCapabilityMissPayload;
|
|
1051
|
+
querySession?: QuerySessionState;
|
|
1052
|
+
}
|
|
1053
|
+
/**
|
|
1054
|
+
* Union of all events emitted during a streaming query
|
|
1055
|
+
*/
|
|
1056
|
+
type QueryStreamEvent = QueryStreamToolStatusEvent | QueryStreamTextDeltaEvent | QueryStreamDeveloperTraceEvent | QueryStreamDoneEvent | QueryStreamErrorEvent;
|
|
1057
|
+
/**
|
|
1058
|
+
* Specific error codes returned by the Context Protocol API
|
|
1059
|
+
*/
|
|
1060
|
+
type ContextErrorCode = "unauthorized" | "no_wallet" | "insufficient_allowance" | "payment_failed" | "execution_failed" | "query_failed" | "invalid_tool_method" | "method_not_execute_eligible" | "invalid_max_spend" | "session_not_found" | "session_forbidden" | "session_closed" | "session_expired" | "max_spend_mismatch" | "session_budget_exceeded";
|
|
1061
|
+
/**
|
|
1062
|
+
* Error thrown by the Context Protocol client
|
|
1063
|
+
*/
|
|
1064
|
+
declare class ContextError extends Error {
|
|
1065
|
+
readonly code?: (ContextErrorCode | string) | undefined;
|
|
1066
|
+
readonly statusCode?: number | undefined;
|
|
1067
|
+
readonly helpUrl?: string | undefined;
|
|
1068
|
+
constructor(message: string, code?: (ContextErrorCode | string) | undefined, statusCode?: number | undefined, helpUrl?: string | undefined);
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
export { type QueryForkReference as $, type SearchCandidateProvenance as A, ContextError as B, type ContributorSearchResolution as C, type ContextClientOptions as D, type McpToolMeta as E, type McpToolRateLimitHints as F, type SearchResponse as G, type SearchOptions as H, type ExecuteOptions as I, type ExecuteSessionStartOptions as J, type ExecuteSessionStatus as K, type ExecuteSessionSpend as L, type McpTool as M, type ExecuteSessionResult as N, type ExecutionResult as O, type ExecuteApiSuccessResponse as P, type QueryDeveloperTrace as Q, type ResolveContributorSearchParams as R, type SearchCandidate as S, type Tool as T, type ExecuteApiErrorResponse as U, type ExecuteApiResponse as V, type ExecuteSessionApiSuccessResponse as W, type ExecuteSessionApiResponse as X, type QueryDeepMode as Y, type QueryAttemptForkReason as Z, type QueryAttemptReference as _, type ContributorSearchMetadata as a, type QueryOptions as a0, type QueryResult as a1, type QuerySessionState as a2, type QueryToolUsage as a3, type QueryCost as a4, type QueryCompletenessRepairEvent as a5, type QueryDeveloperTraceDiagnostics as a6, type QueryDeveloperTraceSummary as a7, type QueryDeveloperTraceStep as a8, type QueryDeveloperTraceToolRef as a9, type QueryDeveloperTraceLoopInfo as aa, type QueryApiSuccessResponse as ab, type QueryApiResponse as ac, type QueryStreamEvent as ad, type QueryStreamToolStatusEvent as ae, type QueryStreamTextDeltaEvent as af, type QueryStreamDeveloperTraceEvent as ag, type QueryStreamDoneEvent as ah, type QueryStreamErrorEvent as ai, type ContextErrorCode as aj, type QueryClarificationPayload as ak, type QueryClarificationOption as al, type QueryClarificationPolicy as am, type QueryCapabilityMissPayload as an, type QueryAssumptionMetadata as ao, type QueryOutcomeType as ap, type SearchShortlist as b, type SearchIntent as c, type ContributorSearchConfig as d, type ContributorSearchResolvedConfig as e, type ContributorSearchTraceRecord as f, type ContributorSearchValidationCaseKind as g, type ContributorSearchValidationExpectation as h, type ContributorSearchValidationArtifact as i, ContributorSearchBudgetExceededError as j, CONTRIBUTOR_SEARCH_METADATA_VERSION as k, CONTRIBUTOR_SEARCH_VALIDATION_VERSION as l, type ContributorSearchConfidence as m, type ContributorSearchDegradedOutcome as n, type ContributorSearchDegradedOutcomePolicy as o, type ContributorSearchDegradedReasonCode as p, type ContributorSearchJudge as q, type ContributorSearchJudgeContext as r, type ContributorSearchJudgeInput as s, type ContributorSearchJudgeResult as t, type ContributorSearchJudgeSnapshot as u, type ContributorSearchJudgeUsage as v, type ContributorSearchMetadataSource as w, type ContributorSearchOutcome as x, type ContributorSearchTraceSummary as y, type ContributorSearchValidatorStatus as z };
|