@ai-sdk-tool/parser 2.1.7 → 3.0.0-canary.1
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/dist/chunk-L4X363EL.js +3168 -0
- package/dist/chunk-L4X363EL.js.map +1 -0
- package/dist/community.cjs +2073 -1020
- package/dist/community.cjs.map +1 -1
- package/dist/community.d.cts +2 -2
- package/dist/community.d.ts +2 -2
- package/dist/community.js +2 -2
- package/dist/community.js.map +1 -1
- package/dist/index.cjs +2095 -1004
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +91 -91
- package/dist/index.d.ts +91 -91
- package/dist/index.js +10 -4
- package/package.json +23 -22
- package/dist/chunk-GSD5HDOQ.js +0 -2068
- package/dist/chunk-GSD5HDOQ.js.map +0 -1
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, LanguageModelV3ProviderTool, JSONSchema7 } from '@ai-sdk/provider';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* ToolCallProtocol
|
|
@@ -13,7 +13,7 @@ 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
|
interface ToolCallProtocol {
|
|
@@ -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,24 +109,40 @@ 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
|
+
interface JsonMixOptions {
|
|
117
117
|
toolCallStart?: string;
|
|
118
118
|
toolCallEnd?: string;
|
|
119
119
|
toolResponseStart?: string;
|
|
120
120
|
toolResponseEnd?: string;
|
|
121
|
-
}
|
|
121
|
+
}
|
|
122
122
|
declare const jsonMixProtocol: ({ toolCallStart, toolCallEnd, toolResponseStart, toolResponseEnd, }?: JsonMixOptions) => ToolCallProtocol;
|
|
123
123
|
|
|
124
124
|
declare const morphXmlProtocol: () => ToolCallProtocol;
|
|
125
125
|
|
|
126
|
-
declare function createToolMiddleware({ protocol, toolSystemPromptTemplate, }: {
|
|
126
|
+
declare function createToolMiddleware({ protocol, toolSystemPromptTemplate, placement, }: {
|
|
127
127
|
protocol: ToolCallProtocol | (() => ToolCallProtocol);
|
|
128
128
|
toolSystemPromptTemplate: (tools: string) => string;
|
|
129
|
-
|
|
129
|
+
placement?: "first" | "last";
|
|
130
|
+
}): LanguageModelV3Middleware;
|
|
131
|
+
|
|
132
|
+
type DebugLevel = "off" | "stream" | "parse";
|
|
133
|
+
declare function getDebugLevel(): DebugLevel;
|
|
134
|
+
declare function logParseFailure({ phase, reason, snippet, error, }: {
|
|
135
|
+
phase: "generated-text" | "stream" | string;
|
|
136
|
+
reason: string;
|
|
137
|
+
snippet?: string;
|
|
138
|
+
error?: unknown;
|
|
139
|
+
}): void;
|
|
140
|
+
declare function logRawChunk(part: unknown): void;
|
|
141
|
+
declare function logParsedChunk(part: unknown): void;
|
|
142
|
+
declare function logParsedSummary({ toolCalls, originalText, }: {
|
|
143
|
+
toolCalls: unknown[];
|
|
144
|
+
originalText: string;
|
|
145
|
+
}): void;
|
|
130
146
|
|
|
131
147
|
/**
|
|
132
148
|
* Dynamically generates a JSON Schema using 'if/then/else' to simulate 'oneOf' behavior
|
|
@@ -136,12 +152,12 @@ declare function createToolMiddleware({ protocol, toolSystemPromptTemplate, }: {
|
|
|
136
152
|
* matches exactly one of the provided tools based on its 'name' property,
|
|
137
153
|
* and then applies the corresponding tool's 'parameters' schema to its 'arguments' property.
|
|
138
154
|
*
|
|
139
|
-
* @param tools An array of tool definitions (
|
|
155
|
+
* @param tools An array of tool definitions (LanguageModelV3FunctionTool or LanguageModelV3ProviderTool).
|
|
140
156
|
* Each tool must have a unique 'name' and its 'parameters' must be a valid JSON Schema.
|
|
141
157
|
* @returns A JSONSchema7 object representing the dynamic validation logic.
|
|
142
|
-
* @throws Error if a 'provider
|
|
158
|
+
* @throws Error if a 'provider' tool is encountered, as they are not supported by this middleware.
|
|
143
159
|
*/
|
|
144
|
-
declare function createDynamicIfThenElseSchema(tools: (
|
|
160
|
+
declare function createDynamicIfThenElseSchema(tools: (LanguageModelV3FunctionTool | LanguageModelV3ProviderTool)[]): JSONSchema7;
|
|
145
161
|
|
|
146
162
|
/**
|
|
147
163
|
* Returns the index of the start of the searchedText in the text, or null if it
|
|
@@ -150,12 +166,59 @@ declare function createDynamicIfThenElseSchema(tools: (LanguageModelV2FunctionTo
|
|
|
150
166
|
*/
|
|
151
167
|
declare function getPotentialStartIndex(text: string, searchedText: string): number | null;
|
|
152
168
|
|
|
169
|
+
type OnErrorFn = (message: string, metadata?: Record<string, unknown>) => void;
|
|
170
|
+
declare function extractOnErrorOption(providerOptions?: unknown): {
|
|
171
|
+
onError?: OnErrorFn;
|
|
172
|
+
} | undefined;
|
|
173
|
+
|
|
174
|
+
interface ToolCallMiddlewareProviderOptions {
|
|
175
|
+
toolCallMiddleware?: {
|
|
176
|
+
debugSummary?: {
|
|
177
|
+
originalText?: string;
|
|
178
|
+
toolCalls?: string;
|
|
179
|
+
};
|
|
180
|
+
toolChoice?: {
|
|
181
|
+
type: string;
|
|
182
|
+
toolName?: string;
|
|
183
|
+
};
|
|
184
|
+
originalTools?: Array<{
|
|
185
|
+
name: string;
|
|
186
|
+
inputSchema: string;
|
|
187
|
+
}>;
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
declare const originalToolsSchema: {
|
|
191
|
+
encode: typeof encodeOriginalTools;
|
|
192
|
+
decode: typeof decodeOriginalTools;
|
|
193
|
+
};
|
|
194
|
+
declare function encodeOriginalTools(tools: LanguageModelV3FunctionTool[] | undefined): Array<{
|
|
195
|
+
name: string;
|
|
196
|
+
inputSchema: string;
|
|
197
|
+
}>;
|
|
198
|
+
declare function decodeOriginalTools(originalTools: Array<{
|
|
199
|
+
name: string;
|
|
200
|
+
inputSchema: string;
|
|
201
|
+
}> | undefined): LanguageModelV3FunctionTool[];
|
|
202
|
+
declare function extractToolNamesFromOriginalTools(originalTools: Array<{
|
|
203
|
+
name: string;
|
|
204
|
+
inputSchema: string;
|
|
205
|
+
}> | undefined): string[];
|
|
206
|
+
declare function isToolChoiceActive(params: {
|
|
207
|
+
providerOptions?: {
|
|
208
|
+
toolCallMiddleware?: {
|
|
209
|
+
toolChoice?: {
|
|
210
|
+
type: string;
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
}): boolean;
|
|
215
|
+
|
|
153
216
|
declare function escapeRegExp(literal: string): string;
|
|
154
217
|
|
|
155
218
|
/**
|
|
156
219
|
* Options for configuring JSON parsing behavior
|
|
157
220
|
*/
|
|
158
|
-
|
|
221
|
+
interface ParseOptions {
|
|
159
222
|
/**
|
|
160
223
|
* Enable relaxed JSON syntax parsing (unquoted keys, single quotes, trailing commas, comments)
|
|
161
224
|
* @default true
|
|
@@ -187,7 +250,7 @@ type ParseOptions = {
|
|
|
187
250
|
* @returns The transformed value
|
|
188
251
|
*/
|
|
189
252
|
reviver?: (key: string, value: unknown) => unknown;
|
|
190
|
-
}
|
|
253
|
+
}
|
|
191
254
|
/**
|
|
192
255
|
* Transform relaxed JSON syntax to standard JSON string
|
|
193
256
|
*
|
|
@@ -259,77 +322,14 @@ declare function parse(text: string, optsOrReviver?: ParseOptions | ((key: strin
|
|
|
259
322
|
*/
|
|
260
323
|
declare function stringify(obj: unknown): string;
|
|
261
324
|
|
|
262
|
-
|
|
263
|
-
declare
|
|
264
|
-
declare const robustJson_stringify: typeof stringify;
|
|
265
|
-
declare const robustJson_transform: typeof transform;
|
|
266
|
-
declare namespace robustJson {
|
|
267
|
-
export { type robustJson_ParseOptions as ParseOptions, robustJson_parse as parse, robustJson_stringify as stringify, robustJson_transform as transform };
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
type DebugLevel = "off" | "stream" | "parse";
|
|
271
|
-
declare function getDebugLevel(): DebugLevel;
|
|
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;
|
|
325
|
+
declare function isToolCallContent(content: unknown): content is LanguageModelV3ToolCall;
|
|
326
|
+
declare function isToolResultPart(content: unknown): content is LanguageModelV3ToolResultPart;
|
|
327
327
|
declare function hasInputProperty(obj: unknown): obj is {
|
|
328
328
|
input?: unknown;
|
|
329
329
|
};
|
|
330
330
|
|
|
331
|
-
declare const gemmaToolMiddleware: _ai_sdk_provider.
|
|
332
|
-
declare const hermesToolMiddleware: _ai_sdk_provider.
|
|
333
|
-
declare const morphXmlToolMiddleware: _ai_sdk_provider.
|
|
331
|
+
declare const gemmaToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
332
|
+
declare const hermesToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
333
|
+
declare const morphXmlToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
334
334
|
|
|
335
|
-
export { type DebugLevel, type OnErrorFn,
|
|
335
|
+
export { type DebugLevel, type OnErrorFn, type ParseOptions as RJSONParseOptions, type ToolCallMiddlewareProviderOptions, createDynamicIfThenElseSchema, createToolMiddleware, decodeOriginalTools, encodeOriginalTools, escapeRegExp, extractOnErrorOption, extractToolNamesFromOriginalTools, gemmaToolMiddleware, getDebugLevel, getPotentialStartIndex, hasInputProperty, hermesToolMiddleware, isToolCallContent, isToolChoiceActive, isToolResultPart, jsonMixProtocol, logParseFailure, 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, LanguageModelV3ProviderTool, JSONSchema7 } from '@ai-sdk/provider';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* ToolCallProtocol
|
|
@@ -13,7 +13,7 @@ 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
|
interface ToolCallProtocol {
|
|
@@ -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,24 +109,40 @@ 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
|
+
interface JsonMixOptions {
|
|
117
117
|
toolCallStart?: string;
|
|
118
118
|
toolCallEnd?: string;
|
|
119
119
|
toolResponseStart?: string;
|
|
120
120
|
toolResponseEnd?: string;
|
|
121
|
-
}
|
|
121
|
+
}
|
|
122
122
|
declare const jsonMixProtocol: ({ toolCallStart, toolCallEnd, toolResponseStart, toolResponseEnd, }?: JsonMixOptions) => ToolCallProtocol;
|
|
123
123
|
|
|
124
124
|
declare const morphXmlProtocol: () => ToolCallProtocol;
|
|
125
125
|
|
|
126
|
-
declare function createToolMiddleware({ protocol, toolSystemPromptTemplate, }: {
|
|
126
|
+
declare function createToolMiddleware({ protocol, toolSystemPromptTemplate, placement, }: {
|
|
127
127
|
protocol: ToolCallProtocol | (() => ToolCallProtocol);
|
|
128
128
|
toolSystemPromptTemplate: (tools: string) => string;
|
|
129
|
-
|
|
129
|
+
placement?: "first" | "last";
|
|
130
|
+
}): LanguageModelV3Middleware;
|
|
131
|
+
|
|
132
|
+
type DebugLevel = "off" | "stream" | "parse";
|
|
133
|
+
declare function getDebugLevel(): DebugLevel;
|
|
134
|
+
declare function logParseFailure({ phase, reason, snippet, error, }: {
|
|
135
|
+
phase: "generated-text" | "stream" | string;
|
|
136
|
+
reason: string;
|
|
137
|
+
snippet?: string;
|
|
138
|
+
error?: unknown;
|
|
139
|
+
}): void;
|
|
140
|
+
declare function logRawChunk(part: unknown): void;
|
|
141
|
+
declare function logParsedChunk(part: unknown): void;
|
|
142
|
+
declare function logParsedSummary({ toolCalls, originalText, }: {
|
|
143
|
+
toolCalls: unknown[];
|
|
144
|
+
originalText: string;
|
|
145
|
+
}): void;
|
|
130
146
|
|
|
131
147
|
/**
|
|
132
148
|
* Dynamically generates a JSON Schema using 'if/then/else' to simulate 'oneOf' behavior
|
|
@@ -136,12 +152,12 @@ declare function createToolMiddleware({ protocol, toolSystemPromptTemplate, }: {
|
|
|
136
152
|
* matches exactly one of the provided tools based on its 'name' property,
|
|
137
153
|
* and then applies the corresponding tool's 'parameters' schema to its 'arguments' property.
|
|
138
154
|
*
|
|
139
|
-
* @param tools An array of tool definitions (
|
|
155
|
+
* @param tools An array of tool definitions (LanguageModelV3FunctionTool or LanguageModelV3ProviderTool).
|
|
140
156
|
* Each tool must have a unique 'name' and its 'parameters' must be a valid JSON Schema.
|
|
141
157
|
* @returns A JSONSchema7 object representing the dynamic validation logic.
|
|
142
|
-
* @throws Error if a 'provider
|
|
158
|
+
* @throws Error if a 'provider' tool is encountered, as they are not supported by this middleware.
|
|
143
159
|
*/
|
|
144
|
-
declare function createDynamicIfThenElseSchema(tools: (
|
|
160
|
+
declare function createDynamicIfThenElseSchema(tools: (LanguageModelV3FunctionTool | LanguageModelV3ProviderTool)[]): JSONSchema7;
|
|
145
161
|
|
|
146
162
|
/**
|
|
147
163
|
* Returns the index of the start of the searchedText in the text, or null if it
|
|
@@ -150,12 +166,59 @@ declare function createDynamicIfThenElseSchema(tools: (LanguageModelV2FunctionTo
|
|
|
150
166
|
*/
|
|
151
167
|
declare function getPotentialStartIndex(text: string, searchedText: string): number | null;
|
|
152
168
|
|
|
169
|
+
type OnErrorFn = (message: string, metadata?: Record<string, unknown>) => void;
|
|
170
|
+
declare function extractOnErrorOption(providerOptions?: unknown): {
|
|
171
|
+
onError?: OnErrorFn;
|
|
172
|
+
} | undefined;
|
|
173
|
+
|
|
174
|
+
interface ToolCallMiddlewareProviderOptions {
|
|
175
|
+
toolCallMiddleware?: {
|
|
176
|
+
debugSummary?: {
|
|
177
|
+
originalText?: string;
|
|
178
|
+
toolCalls?: string;
|
|
179
|
+
};
|
|
180
|
+
toolChoice?: {
|
|
181
|
+
type: string;
|
|
182
|
+
toolName?: string;
|
|
183
|
+
};
|
|
184
|
+
originalTools?: Array<{
|
|
185
|
+
name: string;
|
|
186
|
+
inputSchema: string;
|
|
187
|
+
}>;
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
declare const originalToolsSchema: {
|
|
191
|
+
encode: typeof encodeOriginalTools;
|
|
192
|
+
decode: typeof decodeOriginalTools;
|
|
193
|
+
};
|
|
194
|
+
declare function encodeOriginalTools(tools: LanguageModelV3FunctionTool[] | undefined): Array<{
|
|
195
|
+
name: string;
|
|
196
|
+
inputSchema: string;
|
|
197
|
+
}>;
|
|
198
|
+
declare function decodeOriginalTools(originalTools: Array<{
|
|
199
|
+
name: string;
|
|
200
|
+
inputSchema: string;
|
|
201
|
+
}> | undefined): LanguageModelV3FunctionTool[];
|
|
202
|
+
declare function extractToolNamesFromOriginalTools(originalTools: Array<{
|
|
203
|
+
name: string;
|
|
204
|
+
inputSchema: string;
|
|
205
|
+
}> | undefined): string[];
|
|
206
|
+
declare function isToolChoiceActive(params: {
|
|
207
|
+
providerOptions?: {
|
|
208
|
+
toolCallMiddleware?: {
|
|
209
|
+
toolChoice?: {
|
|
210
|
+
type: string;
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
}): boolean;
|
|
215
|
+
|
|
153
216
|
declare function escapeRegExp(literal: string): string;
|
|
154
217
|
|
|
155
218
|
/**
|
|
156
219
|
* Options for configuring JSON parsing behavior
|
|
157
220
|
*/
|
|
158
|
-
|
|
221
|
+
interface ParseOptions {
|
|
159
222
|
/**
|
|
160
223
|
* Enable relaxed JSON syntax parsing (unquoted keys, single quotes, trailing commas, comments)
|
|
161
224
|
* @default true
|
|
@@ -187,7 +250,7 @@ type ParseOptions = {
|
|
|
187
250
|
* @returns The transformed value
|
|
188
251
|
*/
|
|
189
252
|
reviver?: (key: string, value: unknown) => unknown;
|
|
190
|
-
}
|
|
253
|
+
}
|
|
191
254
|
/**
|
|
192
255
|
* Transform relaxed JSON syntax to standard JSON string
|
|
193
256
|
*
|
|
@@ -259,77 +322,14 @@ declare function parse(text: string, optsOrReviver?: ParseOptions | ((key: strin
|
|
|
259
322
|
*/
|
|
260
323
|
declare function stringify(obj: unknown): string;
|
|
261
324
|
|
|
262
|
-
|
|
263
|
-
declare
|
|
264
|
-
declare const robustJson_stringify: typeof stringify;
|
|
265
|
-
declare const robustJson_transform: typeof transform;
|
|
266
|
-
declare namespace robustJson {
|
|
267
|
-
export { type robustJson_ParseOptions as ParseOptions, robustJson_parse as parse, robustJson_stringify as stringify, robustJson_transform as transform };
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
type DebugLevel = "off" | "stream" | "parse";
|
|
271
|
-
declare function getDebugLevel(): DebugLevel;
|
|
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;
|
|
325
|
+
declare function isToolCallContent(content: unknown): content is LanguageModelV3ToolCall;
|
|
326
|
+
declare function isToolResultPart(content: unknown): content is LanguageModelV3ToolResultPart;
|
|
327
327
|
declare function hasInputProperty(obj: unknown): obj is {
|
|
328
328
|
input?: unknown;
|
|
329
329
|
};
|
|
330
330
|
|
|
331
|
-
declare const gemmaToolMiddleware: _ai_sdk_provider.
|
|
332
|
-
declare const hermesToolMiddleware: _ai_sdk_provider.
|
|
333
|
-
declare const morphXmlToolMiddleware: _ai_sdk_provider.
|
|
331
|
+
declare const gemmaToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
332
|
+
declare const hermesToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
333
|
+
declare const morphXmlToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
334
334
|
|
|
335
|
-
export { type DebugLevel, type OnErrorFn,
|
|
335
|
+
export { type DebugLevel, type OnErrorFn, type ParseOptions as RJSONParseOptions, type ToolCallMiddlewareProviderOptions, createDynamicIfThenElseSchema, createToolMiddleware, decodeOriginalTools, encodeOriginalTools, escapeRegExp, extractOnErrorOption, extractToolNamesFromOriginalTools, gemmaToolMiddleware, getDebugLevel, getPotentialStartIndex, hasInputProperty, hermesToolMiddleware, isToolCallContent, isToolChoiceActive, isToolResultPart, jsonMixProtocol, logParseFailure, logParsedChunk, logParsedSummary, logRawChunk, morphXmlProtocol, morphXmlToolMiddleware, originalToolsSchema, parse as parseRJSON, stringify as stringifyRJSON, transform as transformRJSON };
|
package/dist/index.js
CHANGED
|
@@ -15,16 +15,18 @@ import {
|
|
|
15
15
|
isToolChoiceActive,
|
|
16
16
|
isToolResultPart,
|
|
17
17
|
jsonMixProtocol,
|
|
18
|
+
logParseFailure,
|
|
18
19
|
logParsedChunk,
|
|
19
20
|
logParsedSummary,
|
|
20
21
|
logRawChunk,
|
|
21
22
|
morphXmlProtocol,
|
|
22
23
|
morphXmlToolMiddleware,
|
|
23
24
|
originalToolsSchema,
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
parse,
|
|
26
|
+
stringify,
|
|
27
|
+
transform
|
|
28
|
+
} from "./chunk-L4X363EL.js";
|
|
26
29
|
export {
|
|
27
|
-
robust_json_exports as RJSON,
|
|
28
30
|
createDynamicIfThenElseSchema,
|
|
29
31
|
createToolMiddleware,
|
|
30
32
|
decodeOriginalTools,
|
|
@@ -41,11 +43,15 @@ export {
|
|
|
41
43
|
isToolChoiceActive,
|
|
42
44
|
isToolResultPart,
|
|
43
45
|
jsonMixProtocol,
|
|
46
|
+
logParseFailure,
|
|
44
47
|
logParsedChunk,
|
|
45
48
|
logParsedSummary,
|
|
46
49
|
logRawChunk,
|
|
47
50
|
morphXmlProtocol,
|
|
48
51
|
morphXmlToolMiddleware,
|
|
49
|
-
originalToolsSchema
|
|
52
|
+
originalToolsSchema,
|
|
53
|
+
parse as parseRJSON,
|
|
54
|
+
stringify as stringifyRJSON,
|
|
55
|
+
transform as transformRJSON
|
|
50
56
|
};
|
|
51
57
|
//# sourceMappingURL=index.js.map
|