@dogpile/sdk 0.1.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.
Files changed (88) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/LICENSE +16 -0
  3. package/README.md +842 -0
  4. package/dist/browser/index.d.ts +8 -0
  5. package/dist/browser/index.d.ts.map +1 -0
  6. package/dist/browser/index.js +4493 -0
  7. package/dist/browser/index.js.map +1 -0
  8. package/dist/index.d.ts +17 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +14 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/providers/openai-compatible.d.ts +44 -0
  13. package/dist/providers/openai-compatible.d.ts.map +1 -0
  14. package/dist/providers/openai-compatible.js +305 -0
  15. package/dist/providers/openai-compatible.js.map +1 -0
  16. package/dist/runtime/broadcast.d.ts +18 -0
  17. package/dist/runtime/broadcast.d.ts.map +1 -0
  18. package/dist/runtime/broadcast.js +335 -0
  19. package/dist/runtime/broadcast.js.map +1 -0
  20. package/dist/runtime/cancellation.d.ts +6 -0
  21. package/dist/runtime/cancellation.d.ts.map +1 -0
  22. package/dist/runtime/cancellation.js +35 -0
  23. package/dist/runtime/cancellation.js.map +1 -0
  24. package/dist/runtime/coordinator.d.ts +18 -0
  25. package/dist/runtime/coordinator.d.ts.map +1 -0
  26. package/dist/runtime/coordinator.js +434 -0
  27. package/dist/runtime/coordinator.js.map +1 -0
  28. package/dist/runtime/decisions.d.ts +5 -0
  29. package/dist/runtime/decisions.d.ts.map +1 -0
  30. package/dist/runtime/decisions.js +31 -0
  31. package/dist/runtime/decisions.js.map +1 -0
  32. package/dist/runtime/defaults.d.ts +63 -0
  33. package/dist/runtime/defaults.d.ts.map +1 -0
  34. package/dist/runtime/defaults.js +426 -0
  35. package/dist/runtime/defaults.js.map +1 -0
  36. package/dist/runtime/engine.d.ts +79 -0
  37. package/dist/runtime/engine.d.ts.map +1 -0
  38. package/dist/runtime/engine.js +723 -0
  39. package/dist/runtime/engine.js.map +1 -0
  40. package/dist/runtime/model.d.ts +14 -0
  41. package/dist/runtime/model.d.ts.map +1 -0
  42. package/dist/runtime/model.js +82 -0
  43. package/dist/runtime/model.js.map +1 -0
  44. package/dist/runtime/sequential.d.ts +18 -0
  45. package/dist/runtime/sequential.d.ts.map +1 -0
  46. package/dist/runtime/sequential.js +277 -0
  47. package/dist/runtime/sequential.js.map +1 -0
  48. package/dist/runtime/shared.d.ts +18 -0
  49. package/dist/runtime/shared.d.ts.map +1 -0
  50. package/dist/runtime/shared.js +288 -0
  51. package/dist/runtime/shared.js.map +1 -0
  52. package/dist/runtime/termination.d.ts +77 -0
  53. package/dist/runtime/termination.d.ts.map +1 -0
  54. package/dist/runtime/termination.js +355 -0
  55. package/dist/runtime/termination.js.map +1 -0
  56. package/dist/runtime/tools.d.ts +314 -0
  57. package/dist/runtime/tools.d.ts.map +1 -0
  58. package/dist/runtime/tools.js +969 -0
  59. package/dist/runtime/tools.js.map +1 -0
  60. package/dist/runtime/validation.d.ts +23 -0
  61. package/dist/runtime/validation.d.ts.map +1 -0
  62. package/dist/runtime/validation.js +656 -0
  63. package/dist/runtime/validation.js.map +1 -0
  64. package/dist/types.d.ts +2434 -0
  65. package/dist/types.d.ts.map +1 -0
  66. package/dist/types.js +81 -0
  67. package/dist/types.js.map +1 -0
  68. package/package.json +157 -0
  69. package/src/browser/index.ts +7 -0
  70. package/src/index.ts +195 -0
  71. package/src/providers/openai-compatible.ts +406 -0
  72. package/src/runtime/broadcast.test.ts +355 -0
  73. package/src/runtime/broadcast.ts +428 -0
  74. package/src/runtime/cancellation.ts +40 -0
  75. package/src/runtime/coordinator.test.ts +468 -0
  76. package/src/runtime/coordinator.ts +581 -0
  77. package/src/runtime/decisions.ts +38 -0
  78. package/src/runtime/defaults.ts +547 -0
  79. package/src/runtime/engine.ts +880 -0
  80. package/src/runtime/model.ts +117 -0
  81. package/src/runtime/sequential.test.ts +262 -0
  82. package/src/runtime/sequential.ts +357 -0
  83. package/src/runtime/shared.test.ts +265 -0
  84. package/src/runtime/shared.ts +367 -0
  85. package/src/runtime/termination.ts +463 -0
  86. package/src/runtime/tools.ts +1518 -0
  87. package/src/runtime/validation.ts +771 -0
  88. package/src/types.ts +2729 -0
@@ -0,0 +1,355 @@
1
+ /**
2
+ * Create a budget termination condition.
3
+ *
4
+ * The returned object is JSON-serializable and can be used directly in
5
+ * `terminate` or composed with {@link firstOf}.
6
+ */
7
+ export function budget(options) {
8
+ return {
9
+ kind: "budget",
10
+ ...options
11
+ };
12
+ }
13
+ /**
14
+ * Create a convergence termination condition.
15
+ *
16
+ * The condition fires when the run has produced `stableTurns` sufficiently
17
+ * similar protocol outputs.
18
+ */
19
+ export function convergence(options) {
20
+ return {
21
+ kind: "convergence",
22
+ ...options
23
+ };
24
+ }
25
+ /**
26
+ * Create a judge termination condition.
27
+ *
28
+ * The rubric is stored as serializable configuration so callers can replay or
29
+ * persist traces without SDK-owned state.
30
+ */
31
+ export function judge(options) {
32
+ return {
33
+ kind: "judge",
34
+ ...options
35
+ };
36
+ }
37
+ /**
38
+ * Compose termination conditions so whichever child fires first wins.
39
+ *
40
+ * Conditions are evaluated in the order supplied by the caller. At least one
41
+ * condition is required so the composite is always meaningful and the public
42
+ * type remains a non-empty tuple.
43
+ */
44
+ export function firstOf(...conditions) {
45
+ if (conditions.length === 0) {
46
+ throw new RangeError("firstOf requires at least one termination condition.");
47
+ }
48
+ return {
49
+ kind: "firstOf",
50
+ conditions
51
+ };
52
+ }
53
+ /**
54
+ * Evaluate a serializable termination condition against the current run state.
55
+ *
56
+ * Budget, convergence, judge, and firstOf conditions are enforced from their
57
+ * own normalized inputs so one stop class cannot accidentally satisfy another.
58
+ */
59
+ export function evaluateTermination(condition, context) {
60
+ switch (condition.kind) {
61
+ case "budget":
62
+ return evaluateBudget(condition, context);
63
+ case "firstOf":
64
+ return evaluateFirstOf(condition, context).decision;
65
+ case "convergence":
66
+ return evaluateConvergence(condition, context);
67
+ case "judge":
68
+ return evaluateJudge(condition, context);
69
+ }
70
+ }
71
+ /**
72
+ * Evaluate an ordered firstOf composition and return the winning child, if any.
73
+ */
74
+ export function evaluateFirstOf(condition, context) {
75
+ const evaluated = [];
76
+ for (const [index, child] of condition.conditions.entries()) {
77
+ const decision = evaluateTermination(child, context);
78
+ evaluated.push(decision);
79
+ if (decision.type === "stop") {
80
+ return {
81
+ kind: "firstOf-output",
82
+ decision,
83
+ winningConditionIndex: index,
84
+ evaluated
85
+ };
86
+ }
87
+ }
88
+ return {
89
+ kind: "firstOf-output",
90
+ decision: { type: "continue", condition },
91
+ winningConditionIndex: null,
92
+ evaluated
93
+ };
94
+ }
95
+ /**
96
+ * Evaluate a termination condition and return a trace-ready stop record.
97
+ *
98
+ * Protocol runners use this helper so the first policy decision that halts a
99
+ * run is recorded exactly once on the terminal event.
100
+ */
101
+ export function evaluateTerminationStop(condition, context) {
102
+ if (condition.kind === "firstOf") {
103
+ const output = evaluateFirstOf(condition, context);
104
+ if (output.decision.type !== "stop" || output.winningConditionIndex === null) {
105
+ return null;
106
+ }
107
+ const winningCondition = condition.conditions[output.winningConditionIndex];
108
+ if (!winningCondition) {
109
+ throw new RangeError("firstOf stop referenced a missing winning condition.");
110
+ }
111
+ return stopRecord(condition, output.decision, {
112
+ kind: "firstOf-stop",
113
+ winningConditionIndex: output.winningConditionIndex,
114
+ winningCondition,
115
+ firedCondition: output.decision.condition,
116
+ evaluated: output.evaluated
117
+ });
118
+ }
119
+ const decision = evaluateTermination(condition, context);
120
+ if (decision.type !== "stop") {
121
+ return null;
122
+ }
123
+ return stopRecord(condition, decision);
124
+ }
125
+ /**
126
+ * Combine independently evaluated termination decisions with SDK precedence.
127
+ *
128
+ * Budget caps win over judge decisions, and judge decisions win over
129
+ * convergence. This keeps simultaneous stops deterministic while preserving
130
+ * each evaluator's normalized stop reason on the returned decision.
131
+ */
132
+ export function combineTerminationDecisions(decisions) {
133
+ const stopDecisions = decisions.filter((decision) => decision.type === "stop");
134
+ if (stopDecisions.length === 0) {
135
+ const firstDecision = decisions[0];
136
+ if (!firstDecision) {
137
+ throw new RangeError("combineTerminationDecisions requires at least one decision.");
138
+ }
139
+ return firstDecision;
140
+ }
141
+ return stopDecisions.reduce((winner, candidate) => stopPrecedence(candidate.normalizedReason) < stopPrecedence(winner.normalizedReason) ? candidate : winner);
142
+ }
143
+ /**
144
+ * Evaluate cost, token, iteration, and timeout caps for a budget condition.
145
+ */
146
+ export function evaluateBudget(condition, context) {
147
+ const iteration = context.iteration ?? context.transcript.length;
148
+ const elapsedMs = context.elapsedMs ?? 0;
149
+ const costStop = stopIfReached(condition, "maxUsd", "cost", context.cost.usd);
150
+ if (costStop) {
151
+ return costStop;
152
+ }
153
+ const tokenStop = stopIfReached(condition, "maxTokens", "tokens", context.cost.totalTokens);
154
+ if (tokenStop) {
155
+ return tokenStop;
156
+ }
157
+ const iterationStop = stopIfReached(condition, "maxIterations", "iterations", iteration);
158
+ if (iterationStop) {
159
+ return iterationStop;
160
+ }
161
+ const timeoutStop = stopIfReached(condition, "timeoutMs", "timeout", elapsedMs);
162
+ if (timeoutStop) {
163
+ return timeoutStop;
164
+ }
165
+ return { type: "continue", condition };
166
+ }
167
+ /**
168
+ * Evaluate protocol-level convergence from recent coordination outputs.
169
+ *
170
+ * This intentionally ignores budget caps and judge quality state. Budget and
171
+ * judge conditions can be composed with convergence through `firstOf`, but a
172
+ * convergence condition itself only reads protocol output signals.
173
+ */
174
+ export function evaluateConvergence(condition, context) {
175
+ const stableTurns = Math.max(1, Math.ceil(condition.stableTurns));
176
+ if (context.transcript.length < stableTurns) {
177
+ return { type: "continue", condition };
178
+ }
179
+ const recentEntries = context.transcript.slice(-stableTurns);
180
+ const recentOutputs = recentEntries.map((entry) => entry.output);
181
+ const similarities = consecutiveSimilarities(recentEntries);
182
+ const observedSimilarity = similarities.length === 0 ? 1 : Math.min(...similarities);
183
+ if (observedSimilarity < condition.minSimilarity) {
184
+ return { type: "continue", condition };
185
+ }
186
+ return {
187
+ type: "stop",
188
+ condition,
189
+ reason: "convergence",
190
+ normalizedReason: "convergence",
191
+ detail: {
192
+ protocol: context.protocol,
193
+ stableTurns,
194
+ minSimilarity: condition.minSimilarity,
195
+ observedSimilarity,
196
+ outputs: recentOutputs
197
+ }
198
+ };
199
+ }
200
+ /**
201
+ * Evaluate caller-owned judge state without reading budget or convergence data.
202
+ *
203
+ * Explicit accept/reject verdicts always halt. Score-only decisions halt when
204
+ * they meet `minScore`; when `minScore` is omitted, any score-only decision is
205
+ * treated as the judge's terminal decision.
206
+ */
207
+ export function evaluateJudge(condition, context) {
208
+ const decision = context.judgeDecision ?? scoreDecisionFromQuality(context.quality);
209
+ if (!decision) {
210
+ return { type: "continue", condition };
211
+ }
212
+ switch (decision.type) {
213
+ case "accept":
214
+ return judgeStop(condition, "accepted", decision);
215
+ case "reject":
216
+ return judgeStop(condition, "rejected", decision);
217
+ case "score": {
218
+ const minScore = condition.minScore;
219
+ if (minScore !== undefined && decision.score < minScore) {
220
+ return { type: "continue", condition };
221
+ }
222
+ return judgeStop(condition, "score-threshold", decision, minScore);
223
+ }
224
+ }
225
+ }
226
+ function stopIfReached(condition, cap, reason, observed) {
227
+ const limit = condition[cap];
228
+ if (limit === undefined || observed < limit) {
229
+ return null;
230
+ }
231
+ return {
232
+ type: "stop",
233
+ condition,
234
+ reason: "budget",
235
+ normalizedReason: normalizeBudgetStopReason(reason),
236
+ budgetReason: reason,
237
+ detail: {
238
+ cap,
239
+ limit,
240
+ observed
241
+ }
242
+ };
243
+ }
244
+ function scoreDecisionFromQuality(quality) {
245
+ if (quality === undefined) {
246
+ return null;
247
+ }
248
+ return {
249
+ type: "score",
250
+ score: quality
251
+ };
252
+ }
253
+ function judgeStop(condition, judgeReason, decision, minScore) {
254
+ return {
255
+ type: "stop",
256
+ condition,
257
+ reason: "judge",
258
+ normalizedReason: normalizeJudgeStopReason(judgeReason),
259
+ judgeReason,
260
+ detail: judgeStopDetail(decision, minScore)
261
+ };
262
+ }
263
+ function normalizeBudgetStopReason(reason) {
264
+ switch (reason) {
265
+ case "cost":
266
+ return "budget:cost";
267
+ case "tokens":
268
+ return "budget:tokens";
269
+ case "iterations":
270
+ return "budget:iterations";
271
+ case "timeout":
272
+ return "budget:timeout";
273
+ }
274
+ }
275
+ function normalizeJudgeStopReason(reason) {
276
+ switch (reason) {
277
+ case "accepted":
278
+ return "judge:accepted";
279
+ case "rejected":
280
+ return "judge:rejected";
281
+ case "score-threshold":
282
+ return "judge:score-threshold";
283
+ }
284
+ }
285
+ function stopPrecedence(reason) {
286
+ if (reason.startsWith("budget:")) {
287
+ return 0;
288
+ }
289
+ if (reason.startsWith("judge:")) {
290
+ return 1;
291
+ }
292
+ return 2;
293
+ }
294
+ function judgeStopDetail(decision, minScore) {
295
+ return {
296
+ decision: decision.type,
297
+ ...(decision.score !== undefined ? { score: decision.score } : {}),
298
+ ...(minScore !== undefined ? { minScore } : {}),
299
+ ...(decision.rationale !== undefined ? { rationale: decision.rationale } : {}),
300
+ ...(decision.metadata !== undefined ? { metadata: decision.metadata } : {})
301
+ };
302
+ }
303
+ function stopRecord(rootCondition, decision, firstOfRecord) {
304
+ return {
305
+ kind: "termination-stop",
306
+ rootCondition,
307
+ firedCondition: decision.condition,
308
+ reason: decision.reason,
309
+ normalizedReason: decision.normalizedReason,
310
+ ...(decision.budgetReason !== undefined ? { budgetReason: decision.budgetReason } : {}),
311
+ ...(decision.judgeReason !== undefined ? { judgeReason: decision.judgeReason } : {}),
312
+ ...(decision.detail !== undefined ? { detail: decision.detail } : {}),
313
+ ...(firstOfRecord !== undefined ? { firstOf: firstOfRecord } : {})
314
+ };
315
+ }
316
+ function consecutiveSimilarities(entries) {
317
+ const similarities = [];
318
+ for (let index = 1; index < entries.length; index += 1) {
319
+ const previous = entries[index - 1];
320
+ const current = entries[index];
321
+ if (previous && current) {
322
+ similarities.push(outputSimilarity(previous.output, current.output));
323
+ }
324
+ }
325
+ return similarities;
326
+ }
327
+ function outputSimilarity(left, right) {
328
+ const normalizedLeft = normalizeOutput(left);
329
+ const normalizedRight = normalizeOutput(right);
330
+ if (normalizedLeft === normalizedRight) {
331
+ return 1;
332
+ }
333
+ const leftTokens = tokenize(normalizedLeft);
334
+ const rightTokens = tokenize(normalizedRight);
335
+ if (leftTokens.length === 0 || rightTokens.length === 0) {
336
+ return 0;
337
+ }
338
+ const leftSet = new Set(leftTokens);
339
+ const rightSet = new Set(rightTokens);
340
+ let intersection = 0;
341
+ for (const token of leftSet) {
342
+ if (rightSet.has(token)) {
343
+ intersection += 1;
344
+ }
345
+ }
346
+ const union = new Set([...leftSet, ...rightSet]).size;
347
+ return union === 0 ? 0 : intersection / union;
348
+ }
349
+ function normalizeOutput(output) {
350
+ return output.trim().toLowerCase();
351
+ }
352
+ function tokenize(output) {
353
+ return output.split(/[^a-z0-9]+/u).filter((token) => token.length > 0);
354
+ }
355
+ //# sourceMappingURL=termination.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"termination.js","sourceRoot":"","sources":["../../src/runtime/termination.ts"],"names":[],"mappings":"AAoBA;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,OAAiD;IACtE,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,GAAG,OAAO;KACX,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,OAAsD;IAChF,OAAO;QACL,IAAI,EAAE,aAAa;QACnB,GAAG,OAAO;KACX,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAC,OAAgD;IACpE,OAAO;QACL,IAAI,EAAE,OAAO;QACb,GAAG,OAAO;KACX,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,GAAG,UAAwC;IACjE,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,UAAU,CAAC,sDAAsD,CAAC,CAAC;IAC/E,CAAC;IAED,OAAO;QACL,IAA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;IACpC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC;IACtC,IAAI,YAAY,GAAG,CAAC,CAAC;IAErB,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACxB,YAAY,IAAI,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;IACtD,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,GAAG,KAAK,CAAC;AAChD,CAAC;AAED,SAAS,eAAe,CAAC,MAAc;IACrC,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AACrC,CAAC;AAED,SAAS,QAAQ,CAAC,MAAc;IAC9B,OAAO,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACzE,CAAC"}
@@ -0,0 +1,314 @@
1
+ import type { JsonObject, JsonValue, RuntimeTool, RuntimeToolAdapterContract, RuntimeToolAdapterError, RuntimeToolExecutionContext, RuntimeToolExecutor, RuntimeToolIdentity, RuntimeToolInputSchema, RuntimeToolPermission, RuntimeToolResult, TranscriptToolCall, RuntimeToolTraceContext, RuntimeToolValidationResult, RunEvent, ModelMessage, ModelResponse } from "../types.js";
2
+ type VercelAIToolExecuteOptions = {
3
+ readonly toolCallId: string;
4
+ readonly messages: ModelMessage[];
5
+ readonly abortSignal?: AbortSignal;
6
+ readonly experimental_context: RuntimeToolExecutionContext;
7
+ };
8
+ type VercelAIToolExecuteFunction<Input, Output> = (input: Input, options: VercelAIToolExecuteOptions) => Output | PromiseLike<Output> | AsyncIterable<Output>;
9
+ type VercelAICompatibleSchema<Input> = unknown;
10
+ /**
11
+ * Built-in Dogpile tool names with stable protocol-facing semantics.
12
+ */
13
+ export type DogpileBuiltInToolName = "webSearch" | "codeExec";
14
+ /**
15
+ * Input accepted by the built-in web search tool contract.
16
+ */
17
+ export interface WebSearchToolInput extends JsonObject {
18
+ readonly query: string;
19
+ readonly maxResults?: number;
20
+ }
21
+ /**
22
+ * One normalized web search result.
23
+ */
24
+ export interface WebSearchToolResult extends JsonObject {
25
+ readonly title: string;
26
+ readonly url: string;
27
+ readonly snippet?: string;
28
+ readonly metadata?: JsonObject;
29
+ }
30
+ /**
31
+ * Output returned by the built-in web search tool contract.
32
+ */
33
+ export interface WebSearchToolOutput extends JsonObject {
34
+ readonly results: WebSearchToolResult[];
35
+ }
36
+ /**
37
+ * Fetch implementation accepted by the built-in web search adapter.
38
+ */
39
+ export type WebSearchFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
40
+ /**
41
+ * Request data produced before the built-in web search adapter calls `fetch`.
42
+ */
43
+ export interface WebSearchFetchRequest {
44
+ readonly url: string | URL;
45
+ readonly init?: RequestInit;
46
+ }
47
+ /**
48
+ * Build a search backend request from normalized web search input.
49
+ */
50
+ export type WebSearchFetchRequestBuilder = (input: Readonly<WebSearchToolInput>, context: RuntimeToolExecutionContext) => WebSearchFetchRequest;
51
+ /**
52
+ * Parse a search backend response into Dogpile's stable web search output.
53
+ */
54
+ export type WebSearchFetchResponseParser = (response: Response, input: Readonly<WebSearchToolInput>, context: RuntimeToolExecutionContext) => WebSearchToolOutput | Promise<WebSearchToolOutput>;
55
+ /**
56
+ * Options for the built-in fetch-based web search adapter.
57
+ */
58
+ export interface WebSearchToolAdapterOptions {
59
+ readonly endpoint: string | URL;
60
+ readonly fetch?: WebSearchFetch;
61
+ readonly headers?: HeadersInit;
62
+ readonly defaultMaxResults?: number;
63
+ readonly identity?: BuiltInDogpileToolIdentityOptions;
64
+ readonly permissions?: readonly RuntimeToolPermission[];
65
+ readonly buildRequest?: WebSearchFetchRequestBuilder;
66
+ readonly parseResponse?: WebSearchFetchResponseParser;
67
+ }
68
+ /**
69
+ * Options for the built-in code execution adapter.
70
+ */
71
+ export interface CodeExecToolAdapterOptions {
72
+ readonly execute: CodeExecSandboxExecutor;
73
+ readonly defaultTimeoutMs?: number;
74
+ readonly maxTimeoutMs?: number;
75
+ readonly languages?: readonly CodeExecToolLanguage[];
76
+ readonly allowNetwork?: boolean;
77
+ readonly identity?: BuiltInDogpileToolIdentityOptions;
78
+ readonly permissions?: readonly RuntimeToolPermission[];
79
+ }
80
+ /**
81
+ * Input accepted by the built-in code execution tool contract.
82
+ *
83
+ * @remarks
84
+ * Dogpile core does not provide a sandbox implementation. Callers supply the
85
+ * executor while Dogpile normalizes the public tool identity and schema.
86
+ */
87
+ export interface CodeExecToolInput extends JsonObject {
88
+ readonly language: "javascript" | "typescript" | "python" | "bash" | "shell";
89
+ readonly code: string;
90
+ readonly timeoutMs?: number;
91
+ }
92
+ /**
93
+ * Output returned by the built-in code execution tool contract.
94
+ */
95
+ export interface CodeExecToolOutput extends JsonObject {
96
+ readonly stdout: string;
97
+ readonly stderr: string;
98
+ readonly exitCode: number;
99
+ readonly metadata?: JsonObject;
100
+ }
101
+ /**
102
+ * Language identifiers accepted by Dogpile's built-in code execution contract.
103
+ */
104
+ export type CodeExecToolLanguage = CodeExecToolInput["language"];
105
+ /**
106
+ * Executor signature for the built-in web search contract.
107
+ */
108
+ export type WebSearchToolExecutor = (input: Readonly<WebSearchToolInput>, context: RuntimeToolExecutionContext) => RuntimeToolResult<WebSearchToolOutput> | Promise<RuntimeToolResult<WebSearchToolOutput>>;
109
+ /**
110
+ * Executor signature for the built-in code execution contract.
111
+ */
112
+ export type CodeExecToolExecutor = (input: Readonly<CodeExecToolInput>, context: RuntimeToolExecutionContext) => RuntimeToolResult<CodeExecToolOutput> | Promise<RuntimeToolResult<CodeExecToolOutput>>;
113
+ /**
114
+ * Caller-owned sandbox implementation used by Dogpile's built-in code execution adapter.
115
+ */
116
+ export type CodeExecSandboxExecutor = (input: Readonly<CodeExecToolInput>, context: RuntimeToolExecutionContext) => CodeExecToolOutput | Promise<CodeExecToolOutput>;
117
+ /**
118
+ * Optional identity fields callers may layer onto built-in Dogpile tools.
119
+ */
120
+ export interface BuiltInDogpileToolIdentityOptions {
121
+ readonly namespace?: string;
122
+ readonly version?: string;
123
+ readonly description?: string;
124
+ }
125
+ /**
126
+ * Definition used to normalize Dogpile's built-in web search tool.
127
+ */
128
+ export interface WebSearchDogpileToolDefinition {
129
+ readonly name: "webSearch";
130
+ readonly execute: WebSearchToolExecutor;
131
+ readonly identity?: BuiltInDogpileToolIdentityOptions;
132
+ readonly inputSchema?: RuntimeToolInputSchema;
133
+ readonly permissions?: readonly RuntimeToolPermission[];
134
+ }
135
+ /**
136
+ * Definition used to normalize Dogpile's built-in code execution tool.
137
+ */
138
+ export interface CodeExecDogpileToolDefinition {
139
+ readonly name: "codeExec";
140
+ readonly execute: CodeExecToolExecutor;
141
+ readonly identity?: BuiltInDogpileToolIdentityOptions;
142
+ readonly inputSchema?: RuntimeToolInputSchema;
143
+ readonly permissions?: readonly RuntimeToolPermission[];
144
+ }
145
+ /**
146
+ * Built-in Dogpile tool definitions accepted by the normalization helper.
147
+ */
148
+ export type BuiltInDogpileToolDefinition = WebSearchDogpileToolDefinition | CodeExecDogpileToolDefinition;
149
+ /**
150
+ * Caller-supplied built-in tool executors keyed by Dogpile's stable built-in names.
151
+ */
152
+ export interface BuiltInDogpileToolExecutors {
153
+ readonly webSearch?: WebSearchToolExecutor | WebSearchDogpileToolDefinition;
154
+ readonly codeExec?: CodeExecToolExecutor | CodeExecDogpileToolDefinition;
155
+ }
156
+ export type BuiltInDogpileRuntimeTool = RuntimeToolAdapterContract<WebSearchToolInput, WebSearchToolOutput> | RuntimeToolAdapterContract<CodeExecToolInput, CodeExecToolOutput>;
157
+ /**
158
+ * Vercel AI SDK tool shape accepted by Dogpile's normalization adapter.
159
+ */
160
+ export interface VercelAITool<Input extends JsonObject = JsonObject, Output extends JsonValue = JsonValue> {
161
+ readonly description?: string;
162
+ readonly inputSchema: VercelAICompatibleSchema<Input>;
163
+ readonly execute?: VercelAIToolExecuteFunction<Input, Output>;
164
+ }
165
+ /**
166
+ * Optional identity fields callers may layer onto normalized Vercel AI tools.
167
+ */
168
+ export interface VercelAIToolIdentityOptions {
169
+ readonly id?: string;
170
+ readonly namespace?: string;
171
+ readonly version?: string;
172
+ readonly description?: string;
173
+ }
174
+ /**
175
+ * Definition used to normalize one Vercel AI SDK tool into Dogpile's runtime tool interface.
176
+ */
177
+ export interface VercelAIToolDefinition<Name extends string = string, Input extends JsonObject = JsonObject, Output extends JsonValue = JsonValue> {
178
+ readonly name: Name;
179
+ readonly tool: VercelAITool<Input, Output>;
180
+ readonly identity?: VercelAIToolIdentityOptions;
181
+ readonly inputSchema?: RuntimeToolInputSchema;
182
+ readonly messages?: readonly ModelMessage[];
183
+ }
184
+ /**
185
+ * Caller-supplied Vercel AI SDK tool set keyed by model-visible tool name.
186
+ */
187
+ export interface VercelAIToolSetEntry {
188
+ readonly description?: string;
189
+ readonly inputSchema: VercelAICompatibleSchema<unknown>;
190
+ readonly execute?: VercelAIToolExecuteFunction<never, JsonValue>;
191
+ }
192
+ /**
193
+ * Caller-supplied Vercel AI SDK tool set keyed by model-visible tool name.
194
+ */
195
+ export type VercelAIToolSet = Readonly<Record<string, VercelAIToolSetEntry>>;
196
+ /**
197
+ * Options shared while normalizing a Vercel AI SDK tool set.
198
+ */
199
+ export interface VercelAIToolSetNormalizationOptions {
200
+ readonly namespace?: string;
201
+ readonly version?: string;
202
+ readonly messages?: readonly ModelMessage[];
203
+ readonly identity?: Readonly<Record<string, VercelAIToolIdentityOptions>>;
204
+ }
205
+ /**
206
+ * Options for the shared protocol-agnostic runtime tool executor.
207
+ */
208
+ export interface RuntimeToolExecutorOptions {
209
+ readonly runId: string;
210
+ readonly protocol: RuntimeToolExecutionContext["protocol"];
211
+ readonly tier: RuntimeToolExecutionContext["tier"];
212
+ readonly tools: readonly RuntimeTool<JsonObject, JsonValue>[];
213
+ readonly emit?: (event: RunEvent) => void;
214
+ readonly getTrace?: () => RuntimeToolTraceContext;
215
+ readonly metadata?: JsonObject;
216
+ readonly abortSignal?: AbortSignal;
217
+ readonly makeToolCallId?: (tool: RuntimeToolIdentity, callIndex: number) => string;
218
+ }
219
+ /**
220
+ * Return the default Dogpile identity for one built-in tool name.
221
+ */
222
+ export declare function builtInDogpileToolIdentity(name: "webSearch"): RuntimeToolIdentity;
223
+ export declare function builtInDogpileToolIdentity(name: "codeExec"): RuntimeToolIdentity;
224
+ /**
225
+ * Return the default Dogpile input schema for one built-in tool name.
226
+ */
227
+ export declare function builtInDogpileToolInputSchema(name: "webSearch"): RuntimeToolInputSchema;
228
+ export declare function builtInDogpileToolInputSchema(name: "codeExec"): RuntimeToolInputSchema;
229
+ /**
230
+ * Return the default permission declarations for one built-in tool name.
231
+ */
232
+ export declare function builtInDogpileToolPermissions(name: DogpileBuiltInToolName): readonly RuntimeToolPermission[];
233
+ /**
234
+ * Validate one built-in Dogpile tool input before adapter execution.
235
+ */
236
+ export declare function validateBuiltInDogpileToolInput(name: "webSearch", input: Readonly<Partial<WebSearchToolInput>>): RuntimeToolValidationResult;
237
+ export declare function validateBuiltInDogpileToolInput(name: "codeExec", input: Readonly<Partial<CodeExecToolInput>>): RuntimeToolValidationResult;
238
+ export declare function validateBuiltInDogpileToolInput(name: DogpileBuiltInToolName, input: Readonly<Partial<WebSearchToolInput> | Partial<CodeExecToolInput>>): RuntimeToolValidationResult;
239
+ /**
240
+ * Create the shared runtime tool executor used by every first-party protocol.
241
+ *
242
+ * @remarks
243
+ * The executor owns call id generation, read-only trace context construction,
244
+ * adapter validation, error normalization, and matched `tool-call` /
245
+ * `tool-result` events. Protocols only supply a normalized
246
+ * {@link RuntimeToolExecutionRequest}, which keeps tool execution independent
247
+ * of Coordinator, Sequential, Broadcast, or Shared control flow.
248
+ */
249
+ export declare function createRuntimeToolExecutor(options: RuntimeToolExecutorOptions): RuntimeToolExecutor;
250
+ /**
251
+ * Return a JSON-serializable manifest for tools visible to a protocol run.
252
+ */
253
+ export declare function runtimeToolManifest(tools: readonly RuntimeTool<JsonObject, JsonValue>[]): JsonObject[];
254
+ /**
255
+ * Return request metadata that makes runtime tools visible to provider
256
+ * adapters, or an empty object when no tools are available.
257
+ */
258
+ export declare function runtimeToolAvailability(tools: readonly RuntimeTool<JsonObject, JsonValue>[]): JsonObject;
259
+ /**
260
+ * Execute normalized tool requests returned by a provider response.
261
+ */
262
+ export declare function executeModelResponseToolRequests(options: {
263
+ readonly response: ModelResponse;
264
+ readonly executor: RuntimeToolExecutor;
265
+ readonly agentId: string;
266
+ readonly role: string;
267
+ readonly turn: number;
268
+ readonly metadata?: JsonObject;
269
+ }): Promise<readonly TranscriptToolCall[]>;
270
+ /**
271
+ * Convert an unknown adapter failure into Dogpile's serializable error data.
272
+ */
273
+ export declare function normalizeRuntimeToolAdapterError(error: unknown): RuntimeToolAdapterError;
274
+ /**
275
+ * Create Dogpile's built-in fetch-based web search adapter.
276
+ *
277
+ * @remarks
278
+ * The adapter is backend-neutral: by default it sends a GET request with
279
+ * `q` and `limit` query parameters, then accepts either `{ results: [...] }`
280
+ * or a bare array of result objects from the response JSON. Callers can replace
281
+ * request construction or response parsing for a specific search API while
282
+ * keeping Dogpile's shared runtime tool contract, identity, permissions, input
283
+ * validation, and serializable errors.
284
+ */
285
+ export declare function createWebSearchToolAdapter(options: WebSearchToolAdapterOptions): RuntimeToolAdapterContract<WebSearchToolInput, WebSearchToolOutput>;
286
+ /**
287
+ * Create Dogpile's built-in code execution adapter around a caller-owned sandbox.
288
+ *
289
+ * @remarks
290
+ * Dogpile core stays runtime-portable and never evaluates code itself. This
291
+ * adapter supplies the stable `codeExec` identity, schema, permissions,
292
+ * validation, timeout defaults, abort handling, and serializable errors while
293
+ * the host application owns the sandbox boundary.
294
+ */
295
+ export declare function createCodeExecToolAdapter(options: CodeExecToolAdapterOptions): RuntimeToolAdapterContract<CodeExecToolInput, CodeExecToolOutput>;
296
+ /**
297
+ * Normalize one built-in Dogpile tool definition into the shared runtime tool interface.
298
+ */
299
+ export declare function normalizeBuiltInDogpileTool(definition: WebSearchDogpileToolDefinition): RuntimeToolAdapterContract<WebSearchToolInput, WebSearchToolOutput>;
300
+ export declare function normalizeBuiltInDogpileTool(definition: CodeExecDogpileToolDefinition): RuntimeToolAdapterContract<CodeExecToolInput, CodeExecToolOutput>;
301
+ /**
302
+ * Normalize configured built-in Dogpile tool executors into runtime tools.
303
+ */
304
+ export declare function normalizeBuiltInDogpileTools(tools: BuiltInDogpileToolExecutors): readonly BuiltInDogpileRuntimeTool[];
305
+ /**
306
+ * Normalize one Vercel AI SDK tool into Dogpile's shared runtime tool interface.
307
+ */
308
+ export declare function normalizeVercelAITool<Name extends string, Input extends JsonObject, Output extends JsonValue>(definition: VercelAIToolDefinition<Name, Input, Output>): Promise<RuntimeTool<Input, Output>>;
309
+ /**
310
+ * Normalize a Vercel AI SDK tool set into runtime tools in caller-defined key order.
311
+ */
312
+ export declare function normalizeVercelAITools(tools: VercelAIToolSet, options?: VercelAIToolSetNormalizationOptions): Promise<readonly RuntimeTool<JsonObject, JsonValue>[]>;
313
+ export {};
314
+ //# sourceMappingURL=tools.d.ts.map