@ai-sdk-tool/parser 2.1.6 → 3.0.0-canary.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 +2 -2
- package/dist/chunk-FOANBZRH.js +2514 -0
- package/dist/chunk-FOANBZRH.js.map +1 -0
- package/dist/community.cjs +2584 -0
- package/dist/community.cjs.map +1 -0
- package/dist/community.d.cts +20 -0
- package/dist/community.d.ts +20 -0
- package/dist/community.js +98 -0
- package/dist/community.js.map +1 -0
- package/dist/index.cjs +1376 -941
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +80 -79
- package/dist/index.d.ts +80 -79
- package/dist/index.js +32 -2037
- package/dist/index.js.map +1 -1
- package/package.json +20 -14
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _ai_sdk_provider from '@ai-sdk/provider';
|
|
2
|
-
import {
|
|
2
|
+
import { LanguageModelV3FunctionTool, LanguageModelV3ToolCall, LanguageModelV3ToolResultPart, LanguageModelV3Content, LanguageModelV3StreamPart, LanguageModelV3Middleware, LanguageModelV3ProviderDefinedTool, JSONSchema7 } from '@ai-sdk/provider';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* ToolCallProtocol
|
|
@@ -13,10 +13,10 @@ import { LanguageModelV2FunctionTool, LanguageModelV2ToolCall, LanguageModelV2To
|
|
|
13
13
|
* - Static formatting helpers (`formatTools`, `formatToolCall`, `formatToolResponse`)
|
|
14
14
|
* are used to construct strings that the model will read.
|
|
15
15
|
* - Parsing helpers (`parseGeneratedText`, `createStreamParser`) must convert
|
|
16
|
-
* model output back into structured `
|
|
16
|
+
* model output back into structured `LanguageModelV3Content` parts, emitting
|
|
17
17
|
* `text` for regular content and `tool-call` for detected tool invocations.
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
type ToolCallProtocol = {
|
|
20
20
|
/**
|
|
21
21
|
* Produces a provider-facing string that describes all available tools.
|
|
22
22
|
*
|
|
@@ -32,7 +32,7 @@ interface ToolCallProtocol {
|
|
|
32
32
|
* @returns A string to be embedded into the model's system prompt.
|
|
33
33
|
*/
|
|
34
34
|
formatTools({ tools, toolSystemPromptTemplate, }: {
|
|
35
|
-
tools:
|
|
35
|
+
tools: LanguageModelV3FunctionTool[];
|
|
36
36
|
toolSystemPromptTemplate: (tools: string) => string;
|
|
37
37
|
}): string;
|
|
38
38
|
/**
|
|
@@ -46,7 +46,7 @@ interface ToolCallProtocol {
|
|
|
46
46
|
* @param toolCall The tool call to format for the model.
|
|
47
47
|
* @returns A textual representation of the tool call (e.g., an XML element).
|
|
48
48
|
*/
|
|
49
|
-
formatToolCall(toolCall:
|
|
49
|
+
formatToolCall(toolCall: LanguageModelV3ToolCall): string;
|
|
50
50
|
/**
|
|
51
51
|
* Formats a tool result payload so the model can consume it as plain text.
|
|
52
52
|
*
|
|
@@ -56,10 +56,10 @@ interface ToolCallProtocol {
|
|
|
56
56
|
* @param toolResult The result part produced after executing a tool.
|
|
57
57
|
* @returns Textual representation of the tool result for the model.
|
|
58
58
|
*/
|
|
59
|
-
formatToolResponse(toolResult:
|
|
59
|
+
formatToolResponse(toolResult: LanguageModelV3ToolResultPart): string;
|
|
60
60
|
/**
|
|
61
61
|
* Parses a fully generated text (non-streaming) response from the model and
|
|
62
|
-
* converts it into a sequence of `
|
|
62
|
+
* converts it into a sequence of `LanguageModelV3Content` parts.
|
|
63
63
|
*
|
|
64
64
|
* Implementations should:
|
|
65
65
|
* - Detect tool-call segments addressed to known `tools` and emit
|
|
@@ -75,14 +75,14 @@ interface ToolCallProtocol {
|
|
|
75
75
|
*/
|
|
76
76
|
parseGeneratedText({ text, tools, options, }: {
|
|
77
77
|
text: string;
|
|
78
|
-
tools:
|
|
78
|
+
tools: LanguageModelV3FunctionTool[];
|
|
79
79
|
options?: {
|
|
80
80
|
onError?: (message: string, metadata?: Record<string, unknown>) => void;
|
|
81
81
|
};
|
|
82
|
-
}):
|
|
82
|
+
}): LanguageModelV3Content[];
|
|
83
83
|
/**
|
|
84
84
|
* Creates a TransformStream that converts streaming model deltas
|
|
85
|
-
* (`
|
|
85
|
+
* (`LanguageModelV3StreamPart`) into a normalized sequence of stream parts,
|
|
86
86
|
* including `text-start`/`text-delta`/`text-end` and `tool-call` events.
|
|
87
87
|
*
|
|
88
88
|
* The stream parser should:
|
|
@@ -94,14 +94,14 @@ interface ToolCallProtocol {
|
|
|
94
94
|
*
|
|
95
95
|
* @param tools The list of tools that may be invoked by the model.
|
|
96
96
|
* @param options Optional error callback for non-fatal streaming issues.
|
|
97
|
-
* @returns A TransformStream that accepts and emits `
|
|
97
|
+
* @returns A TransformStream that accepts and emits `LanguageModelV3StreamPart`s.
|
|
98
98
|
*/
|
|
99
99
|
createStreamParser({ tools, options, }: {
|
|
100
|
-
tools:
|
|
100
|
+
tools: LanguageModelV3FunctionTool[];
|
|
101
101
|
options?: {
|
|
102
102
|
onError?: (message: string, metadata?: Record<string, unknown>) => void;
|
|
103
103
|
};
|
|
104
|
-
}): TransformStream<
|
|
104
|
+
}): TransformStream<LanguageModelV3StreamPart, LanguageModelV3StreamPart>;
|
|
105
105
|
/**
|
|
106
106
|
* Optionally returns the exact substrings that would be parsed as tool-calls
|
|
107
107
|
* from the provided text for this protocol.
|
|
@@ -109,9 +109,9 @@ interface ToolCallProtocol {
|
|
|
109
109
|
*/
|
|
110
110
|
extractToolCallSegments?: ({ text, tools, }: {
|
|
111
111
|
text: string;
|
|
112
|
-
tools:
|
|
112
|
+
tools: LanguageModelV3FunctionTool[];
|
|
113
113
|
}) => string[];
|
|
114
|
-
}
|
|
114
|
+
};
|
|
115
115
|
|
|
116
116
|
type JsonMixOptions = {
|
|
117
117
|
toolCallStart?: string;
|
|
@@ -126,7 +126,16 @@ declare const morphXmlProtocol: () => ToolCallProtocol;
|
|
|
126
126
|
declare function createToolMiddleware({ protocol, toolSystemPromptTemplate, }: {
|
|
127
127
|
protocol: ToolCallProtocol | (() => ToolCallProtocol);
|
|
128
128
|
toolSystemPromptTemplate: (tools: string) => string;
|
|
129
|
-
}):
|
|
129
|
+
}): LanguageModelV3Middleware;
|
|
130
|
+
|
|
131
|
+
type DebugLevel = "off" | "stream" | "parse";
|
|
132
|
+
declare function getDebugLevel(): DebugLevel;
|
|
133
|
+
declare function logRawChunk(part: unknown): void;
|
|
134
|
+
declare function logParsedChunk(part: unknown): void;
|
|
135
|
+
declare function logParsedSummary({ toolCalls, originalText, }: {
|
|
136
|
+
toolCalls: unknown[];
|
|
137
|
+
originalText: string;
|
|
138
|
+
}): void;
|
|
130
139
|
|
|
131
140
|
/**
|
|
132
141
|
* Dynamically generates a JSON Schema using 'if/then/else' to simulate 'oneOf' behavior
|
|
@@ -136,12 +145,12 @@ declare function createToolMiddleware({ protocol, toolSystemPromptTemplate, }: {
|
|
|
136
145
|
* matches exactly one of the provided tools based on its 'name' property,
|
|
137
146
|
* and then applies the corresponding tool's 'parameters' schema to its 'arguments' property.
|
|
138
147
|
*
|
|
139
|
-
* @param tools An array of tool definitions (
|
|
148
|
+
* @param tools An array of tool definitions (LanguageModelV3FunctionTool or LanguageModelV3ProviderDefinedTool).
|
|
140
149
|
* Each tool must have a unique 'name' and its 'parameters' must be a valid JSON Schema.
|
|
141
150
|
* @returns A JSONSchema7 object representing the dynamic validation logic.
|
|
142
151
|
* @throws Error if a 'provider-defined' tool is encountered, as they are not supported by this middleware.
|
|
143
152
|
*/
|
|
144
|
-
declare function createDynamicIfThenElseSchema(tools: (
|
|
153
|
+
declare function createDynamicIfThenElseSchema(tools: (LanguageModelV3FunctionTool | LanguageModelV3ProviderDefinedTool)[]): JSONSchema7;
|
|
145
154
|
|
|
146
155
|
/**
|
|
147
156
|
* Returns the index of the start of the searchedText in the text, or null if it
|
|
@@ -150,6 +159,53 @@ declare function createDynamicIfThenElseSchema(tools: (LanguageModelV2FunctionTo
|
|
|
150
159
|
*/
|
|
151
160
|
declare function getPotentialStartIndex(text: string, searchedText: string): number | null;
|
|
152
161
|
|
|
162
|
+
type OnErrorFn = (message: string, metadata?: Record<string, unknown>) => void;
|
|
163
|
+
declare function extractOnErrorOption(providerOptions?: unknown): {
|
|
164
|
+
onError?: OnErrorFn;
|
|
165
|
+
} | undefined;
|
|
166
|
+
|
|
167
|
+
type ToolCallMiddlewareProviderOptions = {
|
|
168
|
+
toolCallMiddleware?: {
|
|
169
|
+
debugSummary?: {
|
|
170
|
+
originalText?: string;
|
|
171
|
+
toolCalls?: string;
|
|
172
|
+
};
|
|
173
|
+
toolChoice?: {
|
|
174
|
+
type: string;
|
|
175
|
+
toolName?: string;
|
|
176
|
+
};
|
|
177
|
+
originalTools?: Array<{
|
|
178
|
+
name: string;
|
|
179
|
+
inputSchema: string;
|
|
180
|
+
}>;
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
declare const originalToolsSchema: {
|
|
184
|
+
encode: typeof encodeOriginalTools;
|
|
185
|
+
decode: typeof decodeOriginalTools;
|
|
186
|
+
};
|
|
187
|
+
declare function encodeOriginalTools(tools: LanguageModelV3FunctionTool[] | undefined): Array<{
|
|
188
|
+
name: string;
|
|
189
|
+
inputSchema: string;
|
|
190
|
+
}>;
|
|
191
|
+
declare function decodeOriginalTools(originalTools: Array<{
|
|
192
|
+
name: string;
|
|
193
|
+
inputSchema: string;
|
|
194
|
+
}> | undefined): LanguageModelV3FunctionTool[];
|
|
195
|
+
declare function extractToolNamesFromOriginalTools(originalTools: Array<{
|
|
196
|
+
name: string;
|
|
197
|
+
inputSchema: string;
|
|
198
|
+
}> | undefined): string[];
|
|
199
|
+
declare function isToolChoiceActive(params: {
|
|
200
|
+
providerOptions?: {
|
|
201
|
+
toolCallMiddleware?: {
|
|
202
|
+
toolChoice?: {
|
|
203
|
+
type: string;
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
}): boolean;
|
|
208
|
+
|
|
153
209
|
declare function escapeRegExp(literal: string): string;
|
|
154
210
|
|
|
155
211
|
/**
|
|
@@ -267,69 +323,14 @@ declare namespace robustJson {
|
|
|
267
323
|
export { type robustJson_ParseOptions as ParseOptions, robustJson_parse as parse, robustJson_stringify as stringify, robustJson_transform as transform };
|
|
268
324
|
}
|
|
269
325
|
|
|
270
|
-
|
|
271
|
-
declare function
|
|
272
|
-
declare function logRawChunk(part: unknown): void;
|
|
273
|
-
declare function logParsedChunk(part: unknown): void;
|
|
274
|
-
declare function logParsedSummary({ toolCalls, originalText, }: {
|
|
275
|
-
toolCalls: unknown[];
|
|
276
|
-
originalText: string;
|
|
277
|
-
}): void;
|
|
278
|
-
|
|
279
|
-
type OnErrorFn = (message: string, metadata?: Record<string, unknown>) => void;
|
|
280
|
-
declare function extractOnErrorOption(providerOptions?: unknown): {
|
|
281
|
-
onError?: OnErrorFn;
|
|
282
|
-
} | undefined;
|
|
283
|
-
|
|
284
|
-
type ToolCallMiddlewareProviderOptions = {
|
|
285
|
-
toolCallMiddleware?: {
|
|
286
|
-
debugSummary?: {
|
|
287
|
-
originalText?: string;
|
|
288
|
-
toolCalls?: string;
|
|
289
|
-
};
|
|
290
|
-
toolChoice?: {
|
|
291
|
-
type: string;
|
|
292
|
-
};
|
|
293
|
-
originalTools?: Array<{
|
|
294
|
-
name: string;
|
|
295
|
-
inputSchema: string;
|
|
296
|
-
}>;
|
|
297
|
-
};
|
|
298
|
-
};
|
|
299
|
-
declare const originalToolsSchema: {
|
|
300
|
-
encode: typeof encodeOriginalTools;
|
|
301
|
-
decode: typeof decodeOriginalTools;
|
|
302
|
-
};
|
|
303
|
-
declare function encodeOriginalTools(tools: LanguageModelV2FunctionTool[] | undefined): Array<{
|
|
304
|
-
name: string;
|
|
305
|
-
inputSchema: string;
|
|
306
|
-
}>;
|
|
307
|
-
declare function decodeOriginalTools(originalTools: Array<{
|
|
308
|
-
name: string;
|
|
309
|
-
inputSchema: string;
|
|
310
|
-
}> | undefined): LanguageModelV2FunctionTool[];
|
|
311
|
-
declare function extractToolNamesFromOriginalTools(originalTools: Array<{
|
|
312
|
-
name: string;
|
|
313
|
-
inputSchema: string;
|
|
314
|
-
}> | undefined): string[];
|
|
315
|
-
declare function isToolChoiceActive(params: {
|
|
316
|
-
providerOptions?: {
|
|
317
|
-
toolCallMiddleware?: {
|
|
318
|
-
toolChoice?: {
|
|
319
|
-
type: string;
|
|
320
|
-
};
|
|
321
|
-
};
|
|
322
|
-
};
|
|
323
|
-
}): boolean;
|
|
324
|
-
|
|
325
|
-
declare function isToolCallContent(content: unknown): content is LanguageModelV2ToolCall;
|
|
326
|
-
declare function isToolResultPart(content: unknown): content is LanguageModelV2ToolResultPart;
|
|
326
|
+
declare function isToolCallContent(content: unknown): content is LanguageModelV3ToolCall;
|
|
327
|
+
declare function isToolResultPart(content: unknown): content is LanguageModelV3ToolResultPart;
|
|
327
328
|
declare function hasInputProperty(obj: unknown): obj is {
|
|
328
329
|
input?: unknown;
|
|
329
330
|
};
|
|
330
331
|
|
|
331
|
-
declare const gemmaToolMiddleware: _ai_sdk_provider.
|
|
332
|
-
declare const hermesToolMiddleware: _ai_sdk_provider.
|
|
333
|
-
declare const
|
|
332
|
+
declare const gemmaToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
333
|
+
declare const hermesToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
334
|
+
declare const morphXmlToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
334
335
|
|
|
335
|
-
export { type DebugLevel, type OnErrorFn, robustJson as RJSON, type ToolCallMiddlewareProviderOptions, createDynamicIfThenElseSchema, createToolMiddleware, decodeOriginalTools, encodeOriginalTools, escapeRegExp, extractOnErrorOption, extractToolNamesFromOriginalTools, gemmaToolMiddleware, getDebugLevel, getPotentialStartIndex, hasInputProperty, hermesToolMiddleware, isToolCallContent, isToolChoiceActive, isToolResultPart, jsonMixProtocol, logParsedChunk, logParsedSummary, logRawChunk, morphXmlProtocol, originalToolsSchema,
|
|
336
|
+
export { type DebugLevel, type OnErrorFn, robustJson as RJSON, type ParseOptions as RJSONParseOptions, type ToolCallMiddlewareProviderOptions, createDynamicIfThenElseSchema, createToolMiddleware, decodeOriginalTools, encodeOriginalTools, escapeRegExp, extractOnErrorOption, extractToolNamesFromOriginalTools, gemmaToolMiddleware, getDebugLevel, getPotentialStartIndex, hasInputProperty, hermesToolMiddleware, isToolCallContent, isToolChoiceActive, isToolResultPart, jsonMixProtocol, logParsedChunk, logParsedSummary, logRawChunk, morphXmlProtocol, morphXmlToolMiddleware, originalToolsSchema, parse as parseRJSON, stringify as stringifyRJSON, transform as transformRJSON };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _ai_sdk_provider from '@ai-sdk/provider';
|
|
2
|
-
import {
|
|
2
|
+
import { LanguageModelV3FunctionTool, LanguageModelV3ToolCall, LanguageModelV3ToolResultPart, LanguageModelV3Content, LanguageModelV3StreamPart, LanguageModelV3Middleware, LanguageModelV3ProviderDefinedTool, JSONSchema7 } from '@ai-sdk/provider';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* ToolCallProtocol
|
|
@@ -13,10 +13,10 @@ import { LanguageModelV2FunctionTool, LanguageModelV2ToolCall, LanguageModelV2To
|
|
|
13
13
|
* - Static formatting helpers (`formatTools`, `formatToolCall`, `formatToolResponse`)
|
|
14
14
|
* are used to construct strings that the model will read.
|
|
15
15
|
* - Parsing helpers (`parseGeneratedText`, `createStreamParser`) must convert
|
|
16
|
-
* model output back into structured `
|
|
16
|
+
* model output back into structured `LanguageModelV3Content` parts, emitting
|
|
17
17
|
* `text` for regular content and `tool-call` for detected tool invocations.
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
type ToolCallProtocol = {
|
|
20
20
|
/**
|
|
21
21
|
* Produces a provider-facing string that describes all available tools.
|
|
22
22
|
*
|
|
@@ -32,7 +32,7 @@ interface ToolCallProtocol {
|
|
|
32
32
|
* @returns A string to be embedded into the model's system prompt.
|
|
33
33
|
*/
|
|
34
34
|
formatTools({ tools, toolSystemPromptTemplate, }: {
|
|
35
|
-
tools:
|
|
35
|
+
tools: LanguageModelV3FunctionTool[];
|
|
36
36
|
toolSystemPromptTemplate: (tools: string) => string;
|
|
37
37
|
}): string;
|
|
38
38
|
/**
|
|
@@ -46,7 +46,7 @@ interface ToolCallProtocol {
|
|
|
46
46
|
* @param toolCall The tool call to format for the model.
|
|
47
47
|
* @returns A textual representation of the tool call (e.g., an XML element).
|
|
48
48
|
*/
|
|
49
|
-
formatToolCall(toolCall:
|
|
49
|
+
formatToolCall(toolCall: LanguageModelV3ToolCall): string;
|
|
50
50
|
/**
|
|
51
51
|
* Formats a tool result payload so the model can consume it as plain text.
|
|
52
52
|
*
|
|
@@ -56,10 +56,10 @@ interface ToolCallProtocol {
|
|
|
56
56
|
* @param toolResult The result part produced after executing a tool.
|
|
57
57
|
* @returns Textual representation of the tool result for the model.
|
|
58
58
|
*/
|
|
59
|
-
formatToolResponse(toolResult:
|
|
59
|
+
formatToolResponse(toolResult: LanguageModelV3ToolResultPart): string;
|
|
60
60
|
/**
|
|
61
61
|
* Parses a fully generated text (non-streaming) response from the model and
|
|
62
|
-
* converts it into a sequence of `
|
|
62
|
+
* converts it into a sequence of `LanguageModelV3Content` parts.
|
|
63
63
|
*
|
|
64
64
|
* Implementations should:
|
|
65
65
|
* - Detect tool-call segments addressed to known `tools` and emit
|
|
@@ -75,14 +75,14 @@ interface ToolCallProtocol {
|
|
|
75
75
|
*/
|
|
76
76
|
parseGeneratedText({ text, tools, options, }: {
|
|
77
77
|
text: string;
|
|
78
|
-
tools:
|
|
78
|
+
tools: LanguageModelV3FunctionTool[];
|
|
79
79
|
options?: {
|
|
80
80
|
onError?: (message: string, metadata?: Record<string, unknown>) => void;
|
|
81
81
|
};
|
|
82
|
-
}):
|
|
82
|
+
}): LanguageModelV3Content[];
|
|
83
83
|
/**
|
|
84
84
|
* Creates a TransformStream that converts streaming model deltas
|
|
85
|
-
* (`
|
|
85
|
+
* (`LanguageModelV3StreamPart`) into a normalized sequence of stream parts,
|
|
86
86
|
* including `text-start`/`text-delta`/`text-end` and `tool-call` events.
|
|
87
87
|
*
|
|
88
88
|
* The stream parser should:
|
|
@@ -94,14 +94,14 @@ interface ToolCallProtocol {
|
|
|
94
94
|
*
|
|
95
95
|
* @param tools The list of tools that may be invoked by the model.
|
|
96
96
|
* @param options Optional error callback for non-fatal streaming issues.
|
|
97
|
-
* @returns A TransformStream that accepts and emits `
|
|
97
|
+
* @returns A TransformStream that accepts and emits `LanguageModelV3StreamPart`s.
|
|
98
98
|
*/
|
|
99
99
|
createStreamParser({ tools, options, }: {
|
|
100
|
-
tools:
|
|
100
|
+
tools: LanguageModelV3FunctionTool[];
|
|
101
101
|
options?: {
|
|
102
102
|
onError?: (message: string, metadata?: Record<string, unknown>) => void;
|
|
103
103
|
};
|
|
104
|
-
}): TransformStream<
|
|
104
|
+
}): TransformStream<LanguageModelV3StreamPart, LanguageModelV3StreamPart>;
|
|
105
105
|
/**
|
|
106
106
|
* Optionally returns the exact substrings that would be parsed as tool-calls
|
|
107
107
|
* from the provided text for this protocol.
|
|
@@ -109,9 +109,9 @@ interface ToolCallProtocol {
|
|
|
109
109
|
*/
|
|
110
110
|
extractToolCallSegments?: ({ text, tools, }: {
|
|
111
111
|
text: string;
|
|
112
|
-
tools:
|
|
112
|
+
tools: LanguageModelV3FunctionTool[];
|
|
113
113
|
}) => string[];
|
|
114
|
-
}
|
|
114
|
+
};
|
|
115
115
|
|
|
116
116
|
type JsonMixOptions = {
|
|
117
117
|
toolCallStart?: string;
|
|
@@ -126,7 +126,16 @@ declare const morphXmlProtocol: () => ToolCallProtocol;
|
|
|
126
126
|
declare function createToolMiddleware({ protocol, toolSystemPromptTemplate, }: {
|
|
127
127
|
protocol: ToolCallProtocol | (() => ToolCallProtocol);
|
|
128
128
|
toolSystemPromptTemplate: (tools: string) => string;
|
|
129
|
-
}):
|
|
129
|
+
}): LanguageModelV3Middleware;
|
|
130
|
+
|
|
131
|
+
type DebugLevel = "off" | "stream" | "parse";
|
|
132
|
+
declare function getDebugLevel(): DebugLevel;
|
|
133
|
+
declare function logRawChunk(part: unknown): void;
|
|
134
|
+
declare function logParsedChunk(part: unknown): void;
|
|
135
|
+
declare function logParsedSummary({ toolCalls, originalText, }: {
|
|
136
|
+
toolCalls: unknown[];
|
|
137
|
+
originalText: string;
|
|
138
|
+
}): void;
|
|
130
139
|
|
|
131
140
|
/**
|
|
132
141
|
* Dynamically generates a JSON Schema using 'if/then/else' to simulate 'oneOf' behavior
|
|
@@ -136,12 +145,12 @@ declare function createToolMiddleware({ protocol, toolSystemPromptTemplate, }: {
|
|
|
136
145
|
* matches exactly one of the provided tools based on its 'name' property,
|
|
137
146
|
* and then applies the corresponding tool's 'parameters' schema to its 'arguments' property.
|
|
138
147
|
*
|
|
139
|
-
* @param tools An array of tool definitions (
|
|
148
|
+
* @param tools An array of tool definitions (LanguageModelV3FunctionTool or LanguageModelV3ProviderDefinedTool).
|
|
140
149
|
* Each tool must have a unique 'name' and its 'parameters' must be a valid JSON Schema.
|
|
141
150
|
* @returns A JSONSchema7 object representing the dynamic validation logic.
|
|
142
151
|
* @throws Error if a 'provider-defined' tool is encountered, as they are not supported by this middleware.
|
|
143
152
|
*/
|
|
144
|
-
declare function createDynamicIfThenElseSchema(tools: (
|
|
153
|
+
declare function createDynamicIfThenElseSchema(tools: (LanguageModelV3FunctionTool | LanguageModelV3ProviderDefinedTool)[]): JSONSchema7;
|
|
145
154
|
|
|
146
155
|
/**
|
|
147
156
|
* Returns the index of the start of the searchedText in the text, or null if it
|
|
@@ -150,6 +159,53 @@ declare function createDynamicIfThenElseSchema(tools: (LanguageModelV2FunctionTo
|
|
|
150
159
|
*/
|
|
151
160
|
declare function getPotentialStartIndex(text: string, searchedText: string): number | null;
|
|
152
161
|
|
|
162
|
+
type OnErrorFn = (message: string, metadata?: Record<string, unknown>) => void;
|
|
163
|
+
declare function extractOnErrorOption(providerOptions?: unknown): {
|
|
164
|
+
onError?: OnErrorFn;
|
|
165
|
+
} | undefined;
|
|
166
|
+
|
|
167
|
+
type ToolCallMiddlewareProviderOptions = {
|
|
168
|
+
toolCallMiddleware?: {
|
|
169
|
+
debugSummary?: {
|
|
170
|
+
originalText?: string;
|
|
171
|
+
toolCalls?: string;
|
|
172
|
+
};
|
|
173
|
+
toolChoice?: {
|
|
174
|
+
type: string;
|
|
175
|
+
toolName?: string;
|
|
176
|
+
};
|
|
177
|
+
originalTools?: Array<{
|
|
178
|
+
name: string;
|
|
179
|
+
inputSchema: string;
|
|
180
|
+
}>;
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
declare const originalToolsSchema: {
|
|
184
|
+
encode: typeof encodeOriginalTools;
|
|
185
|
+
decode: typeof decodeOriginalTools;
|
|
186
|
+
};
|
|
187
|
+
declare function encodeOriginalTools(tools: LanguageModelV3FunctionTool[] | undefined): Array<{
|
|
188
|
+
name: string;
|
|
189
|
+
inputSchema: string;
|
|
190
|
+
}>;
|
|
191
|
+
declare function decodeOriginalTools(originalTools: Array<{
|
|
192
|
+
name: string;
|
|
193
|
+
inputSchema: string;
|
|
194
|
+
}> | undefined): LanguageModelV3FunctionTool[];
|
|
195
|
+
declare function extractToolNamesFromOriginalTools(originalTools: Array<{
|
|
196
|
+
name: string;
|
|
197
|
+
inputSchema: string;
|
|
198
|
+
}> | undefined): string[];
|
|
199
|
+
declare function isToolChoiceActive(params: {
|
|
200
|
+
providerOptions?: {
|
|
201
|
+
toolCallMiddleware?: {
|
|
202
|
+
toolChoice?: {
|
|
203
|
+
type: string;
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
}): boolean;
|
|
208
|
+
|
|
153
209
|
declare function escapeRegExp(literal: string): string;
|
|
154
210
|
|
|
155
211
|
/**
|
|
@@ -267,69 +323,14 @@ declare namespace robustJson {
|
|
|
267
323
|
export { type robustJson_ParseOptions as ParseOptions, robustJson_parse as parse, robustJson_stringify as stringify, robustJson_transform as transform };
|
|
268
324
|
}
|
|
269
325
|
|
|
270
|
-
|
|
271
|
-
declare function
|
|
272
|
-
declare function logRawChunk(part: unknown): void;
|
|
273
|
-
declare function logParsedChunk(part: unknown): void;
|
|
274
|
-
declare function logParsedSummary({ toolCalls, originalText, }: {
|
|
275
|
-
toolCalls: unknown[];
|
|
276
|
-
originalText: string;
|
|
277
|
-
}): void;
|
|
278
|
-
|
|
279
|
-
type OnErrorFn = (message: string, metadata?: Record<string, unknown>) => void;
|
|
280
|
-
declare function extractOnErrorOption(providerOptions?: unknown): {
|
|
281
|
-
onError?: OnErrorFn;
|
|
282
|
-
} | undefined;
|
|
283
|
-
|
|
284
|
-
type ToolCallMiddlewareProviderOptions = {
|
|
285
|
-
toolCallMiddleware?: {
|
|
286
|
-
debugSummary?: {
|
|
287
|
-
originalText?: string;
|
|
288
|
-
toolCalls?: string;
|
|
289
|
-
};
|
|
290
|
-
toolChoice?: {
|
|
291
|
-
type: string;
|
|
292
|
-
};
|
|
293
|
-
originalTools?: Array<{
|
|
294
|
-
name: string;
|
|
295
|
-
inputSchema: string;
|
|
296
|
-
}>;
|
|
297
|
-
};
|
|
298
|
-
};
|
|
299
|
-
declare const originalToolsSchema: {
|
|
300
|
-
encode: typeof encodeOriginalTools;
|
|
301
|
-
decode: typeof decodeOriginalTools;
|
|
302
|
-
};
|
|
303
|
-
declare function encodeOriginalTools(tools: LanguageModelV2FunctionTool[] | undefined): Array<{
|
|
304
|
-
name: string;
|
|
305
|
-
inputSchema: string;
|
|
306
|
-
}>;
|
|
307
|
-
declare function decodeOriginalTools(originalTools: Array<{
|
|
308
|
-
name: string;
|
|
309
|
-
inputSchema: string;
|
|
310
|
-
}> | undefined): LanguageModelV2FunctionTool[];
|
|
311
|
-
declare function extractToolNamesFromOriginalTools(originalTools: Array<{
|
|
312
|
-
name: string;
|
|
313
|
-
inputSchema: string;
|
|
314
|
-
}> | undefined): string[];
|
|
315
|
-
declare function isToolChoiceActive(params: {
|
|
316
|
-
providerOptions?: {
|
|
317
|
-
toolCallMiddleware?: {
|
|
318
|
-
toolChoice?: {
|
|
319
|
-
type: string;
|
|
320
|
-
};
|
|
321
|
-
};
|
|
322
|
-
};
|
|
323
|
-
}): boolean;
|
|
324
|
-
|
|
325
|
-
declare function isToolCallContent(content: unknown): content is LanguageModelV2ToolCall;
|
|
326
|
-
declare function isToolResultPart(content: unknown): content is LanguageModelV2ToolResultPart;
|
|
326
|
+
declare function isToolCallContent(content: unknown): content is LanguageModelV3ToolCall;
|
|
327
|
+
declare function isToolResultPart(content: unknown): content is LanguageModelV3ToolResultPart;
|
|
327
328
|
declare function hasInputProperty(obj: unknown): obj is {
|
|
328
329
|
input?: unknown;
|
|
329
330
|
};
|
|
330
331
|
|
|
331
|
-
declare const gemmaToolMiddleware: _ai_sdk_provider.
|
|
332
|
-
declare const hermesToolMiddleware: _ai_sdk_provider.
|
|
333
|
-
declare const
|
|
332
|
+
declare const gemmaToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
333
|
+
declare const hermesToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
334
|
+
declare const morphXmlToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
334
335
|
|
|
335
|
-
export { type DebugLevel, type OnErrorFn, robustJson as RJSON, type ToolCallMiddlewareProviderOptions, createDynamicIfThenElseSchema, createToolMiddleware, decodeOriginalTools, encodeOriginalTools, escapeRegExp, extractOnErrorOption, extractToolNamesFromOriginalTools, gemmaToolMiddleware, getDebugLevel, getPotentialStartIndex, hasInputProperty, hermesToolMiddleware, isToolCallContent, isToolChoiceActive, isToolResultPart, jsonMixProtocol, logParsedChunk, logParsedSummary, logRawChunk, morphXmlProtocol, originalToolsSchema,
|
|
336
|
+
export { type DebugLevel, type OnErrorFn, robustJson as RJSON, type ParseOptions as RJSONParseOptions, type ToolCallMiddlewareProviderOptions, createDynamicIfThenElseSchema, createToolMiddleware, decodeOriginalTools, encodeOriginalTools, escapeRegExp, extractOnErrorOption, extractToolNamesFromOriginalTools, gemmaToolMiddleware, getDebugLevel, getPotentialStartIndex, hasInputProperty, hermesToolMiddleware, isToolCallContent, isToolChoiceActive, isToolResultPart, jsonMixProtocol, logParsedChunk, logParsedSummary, logRawChunk, morphXmlProtocol, morphXmlToolMiddleware, originalToolsSchema, parse as parseRJSON, stringify as stringifyRJSON, transform as transformRJSON };
|