@ai-sdk-tool/parser 3.0.0-canary.0 → 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-FOANBZRH.js → chunk-L4X363EL.js} +889 -235
- package/dist/chunk-L4X363EL.js.map +1 -0
- package/dist/community.cjs +873 -240
- package/dist/community.cjs.map +1 -1
- package/dist/community.js +2 -2
- package/dist/community.js.map +1 -1
- package/dist/index.cjs +881 -220
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -22
- package/dist/index.d.ts +21 -22
- package/dist/index.js +3 -3
- package/package.json +23 -16
- package/dist/chunk-FOANBZRH.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 { LanguageModelV3FunctionTool, LanguageModelV3ToolCall, LanguageModelV3ToolResultPart, LanguageModelV3Content, LanguageModelV3StreamPart, LanguageModelV3Middleware,
|
|
2
|
+
import { LanguageModelV3FunctionTool, LanguageModelV3ToolCall, LanguageModelV3ToolResultPart, LanguageModelV3Content, LanguageModelV3StreamPart, LanguageModelV3Middleware, LanguageModelV3ProviderTool, JSONSchema7 } from '@ai-sdk/provider';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* ToolCallProtocol
|
|
@@ -16,7 +16,7 @@ import { LanguageModelV3FunctionTool, LanguageModelV3ToolCall, LanguageModelV3To
|
|
|
16
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 {
|
|
20
20
|
/**
|
|
21
21
|
* Produces a provider-facing string that describes all available tools.
|
|
22
22
|
*
|
|
@@ -111,25 +111,32 @@ type ToolCallProtocol = {
|
|
|
111
111
|
text: string;
|
|
112
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
|
+
placement?: "first" | "last";
|
|
129
130
|
}): LanguageModelV3Middleware;
|
|
130
131
|
|
|
131
132
|
type DebugLevel = "off" | "stream" | "parse";
|
|
132
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;
|
|
133
140
|
declare function logRawChunk(part: unknown): void;
|
|
134
141
|
declare function logParsedChunk(part: unknown): void;
|
|
135
142
|
declare function logParsedSummary({ toolCalls, originalText, }: {
|
|
@@ -145,12 +152,12 @@ declare function logParsedSummary({ toolCalls, originalText, }: {
|
|
|
145
152
|
* matches exactly one of the provided tools based on its 'name' property,
|
|
146
153
|
* and then applies the corresponding tool's 'parameters' schema to its 'arguments' property.
|
|
147
154
|
*
|
|
148
|
-
* @param tools An array of tool definitions (LanguageModelV3FunctionTool or
|
|
155
|
+
* @param tools An array of tool definitions (LanguageModelV3FunctionTool or LanguageModelV3ProviderTool).
|
|
149
156
|
* Each tool must have a unique 'name' and its 'parameters' must be a valid JSON Schema.
|
|
150
157
|
* @returns A JSONSchema7 object representing the dynamic validation logic.
|
|
151
|
-
* @throws Error if a 'provider
|
|
158
|
+
* @throws Error if a 'provider' tool is encountered, as they are not supported by this middleware.
|
|
152
159
|
*/
|
|
153
|
-
declare function createDynamicIfThenElseSchema(tools: (LanguageModelV3FunctionTool |
|
|
160
|
+
declare function createDynamicIfThenElseSchema(tools: (LanguageModelV3FunctionTool | LanguageModelV3ProviderTool)[]): JSONSchema7;
|
|
154
161
|
|
|
155
162
|
/**
|
|
156
163
|
* Returns the index of the start of the searchedText in the text, or null if it
|
|
@@ -164,7 +171,7 @@ declare function extractOnErrorOption(providerOptions?: unknown): {
|
|
|
164
171
|
onError?: OnErrorFn;
|
|
165
172
|
} | undefined;
|
|
166
173
|
|
|
167
|
-
|
|
174
|
+
interface ToolCallMiddlewareProviderOptions {
|
|
168
175
|
toolCallMiddleware?: {
|
|
169
176
|
debugSummary?: {
|
|
170
177
|
originalText?: string;
|
|
@@ -179,7 +186,7 @@ type ToolCallMiddlewareProviderOptions = {
|
|
|
179
186
|
inputSchema: string;
|
|
180
187
|
}>;
|
|
181
188
|
};
|
|
182
|
-
}
|
|
189
|
+
}
|
|
183
190
|
declare const originalToolsSchema: {
|
|
184
191
|
encode: typeof encodeOriginalTools;
|
|
185
192
|
decode: typeof decodeOriginalTools;
|
|
@@ -211,7 +218,7 @@ declare function escapeRegExp(literal: string): string;
|
|
|
211
218
|
/**
|
|
212
219
|
* Options for configuring JSON parsing behavior
|
|
213
220
|
*/
|
|
214
|
-
|
|
221
|
+
interface ParseOptions {
|
|
215
222
|
/**
|
|
216
223
|
* Enable relaxed JSON syntax parsing (unquoted keys, single quotes, trailing commas, comments)
|
|
217
224
|
* @default true
|
|
@@ -243,7 +250,7 @@ type ParseOptions = {
|
|
|
243
250
|
* @returns The transformed value
|
|
244
251
|
*/
|
|
245
252
|
reviver?: (key: string, value: unknown) => unknown;
|
|
246
|
-
}
|
|
253
|
+
}
|
|
247
254
|
/**
|
|
248
255
|
* Transform relaxed JSON syntax to standard JSON string
|
|
249
256
|
*
|
|
@@ -315,14 +322,6 @@ declare function parse(text: string, optsOrReviver?: ParseOptions | ((key: strin
|
|
|
315
322
|
*/
|
|
316
323
|
declare function stringify(obj: unknown): string;
|
|
317
324
|
|
|
318
|
-
type robustJson_ParseOptions = ParseOptions;
|
|
319
|
-
declare const robustJson_parse: typeof parse;
|
|
320
|
-
declare const robustJson_stringify: typeof stringify;
|
|
321
|
-
declare const robustJson_transform: typeof transform;
|
|
322
|
-
declare namespace robustJson {
|
|
323
|
-
export { type robustJson_ParseOptions as ParseOptions, robustJson_parse as parse, robustJson_stringify as stringify, robustJson_transform as transform };
|
|
324
|
-
}
|
|
325
|
-
|
|
326
325
|
declare function isToolCallContent(content: unknown): content is LanguageModelV3ToolCall;
|
|
327
326
|
declare function isToolResultPart(content: unknown): content is LanguageModelV3ToolResultPart;
|
|
328
327
|
declare function hasInputProperty(obj: unknown): obj is {
|
|
@@ -333,4 +332,4 @@ declare const gemmaToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
|
333
332
|
declare const hermesToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
334
333
|
declare const morphXmlToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
335
334
|
|
|
336
|
-
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 { LanguageModelV3FunctionTool, LanguageModelV3ToolCall, LanguageModelV3ToolResultPart, LanguageModelV3Content, LanguageModelV3StreamPart, LanguageModelV3Middleware,
|
|
2
|
+
import { LanguageModelV3FunctionTool, LanguageModelV3ToolCall, LanguageModelV3ToolResultPart, LanguageModelV3Content, LanguageModelV3StreamPart, LanguageModelV3Middleware, LanguageModelV3ProviderTool, JSONSchema7 } from '@ai-sdk/provider';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* ToolCallProtocol
|
|
@@ -16,7 +16,7 @@ import { LanguageModelV3FunctionTool, LanguageModelV3ToolCall, LanguageModelV3To
|
|
|
16
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 {
|
|
20
20
|
/**
|
|
21
21
|
* Produces a provider-facing string that describes all available tools.
|
|
22
22
|
*
|
|
@@ -111,25 +111,32 @@ type ToolCallProtocol = {
|
|
|
111
111
|
text: string;
|
|
112
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
|
+
placement?: "first" | "last";
|
|
129
130
|
}): LanguageModelV3Middleware;
|
|
130
131
|
|
|
131
132
|
type DebugLevel = "off" | "stream" | "parse";
|
|
132
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;
|
|
133
140
|
declare function logRawChunk(part: unknown): void;
|
|
134
141
|
declare function logParsedChunk(part: unknown): void;
|
|
135
142
|
declare function logParsedSummary({ toolCalls, originalText, }: {
|
|
@@ -145,12 +152,12 @@ declare function logParsedSummary({ toolCalls, originalText, }: {
|
|
|
145
152
|
* matches exactly one of the provided tools based on its 'name' property,
|
|
146
153
|
* and then applies the corresponding tool's 'parameters' schema to its 'arguments' property.
|
|
147
154
|
*
|
|
148
|
-
* @param tools An array of tool definitions (LanguageModelV3FunctionTool or
|
|
155
|
+
* @param tools An array of tool definitions (LanguageModelV3FunctionTool or LanguageModelV3ProviderTool).
|
|
149
156
|
* Each tool must have a unique 'name' and its 'parameters' must be a valid JSON Schema.
|
|
150
157
|
* @returns A JSONSchema7 object representing the dynamic validation logic.
|
|
151
|
-
* @throws Error if a 'provider
|
|
158
|
+
* @throws Error if a 'provider' tool is encountered, as they are not supported by this middleware.
|
|
152
159
|
*/
|
|
153
|
-
declare function createDynamicIfThenElseSchema(tools: (LanguageModelV3FunctionTool |
|
|
160
|
+
declare function createDynamicIfThenElseSchema(tools: (LanguageModelV3FunctionTool | LanguageModelV3ProviderTool)[]): JSONSchema7;
|
|
154
161
|
|
|
155
162
|
/**
|
|
156
163
|
* Returns the index of the start of the searchedText in the text, or null if it
|
|
@@ -164,7 +171,7 @@ declare function extractOnErrorOption(providerOptions?: unknown): {
|
|
|
164
171
|
onError?: OnErrorFn;
|
|
165
172
|
} | undefined;
|
|
166
173
|
|
|
167
|
-
|
|
174
|
+
interface ToolCallMiddlewareProviderOptions {
|
|
168
175
|
toolCallMiddleware?: {
|
|
169
176
|
debugSummary?: {
|
|
170
177
|
originalText?: string;
|
|
@@ -179,7 +186,7 @@ type ToolCallMiddlewareProviderOptions = {
|
|
|
179
186
|
inputSchema: string;
|
|
180
187
|
}>;
|
|
181
188
|
};
|
|
182
|
-
}
|
|
189
|
+
}
|
|
183
190
|
declare const originalToolsSchema: {
|
|
184
191
|
encode: typeof encodeOriginalTools;
|
|
185
192
|
decode: typeof decodeOriginalTools;
|
|
@@ -211,7 +218,7 @@ declare function escapeRegExp(literal: string): string;
|
|
|
211
218
|
/**
|
|
212
219
|
* Options for configuring JSON parsing behavior
|
|
213
220
|
*/
|
|
214
|
-
|
|
221
|
+
interface ParseOptions {
|
|
215
222
|
/**
|
|
216
223
|
* Enable relaxed JSON syntax parsing (unquoted keys, single quotes, trailing commas, comments)
|
|
217
224
|
* @default true
|
|
@@ -243,7 +250,7 @@ type ParseOptions = {
|
|
|
243
250
|
* @returns The transformed value
|
|
244
251
|
*/
|
|
245
252
|
reviver?: (key: string, value: unknown) => unknown;
|
|
246
|
-
}
|
|
253
|
+
}
|
|
247
254
|
/**
|
|
248
255
|
* Transform relaxed JSON syntax to standard JSON string
|
|
249
256
|
*
|
|
@@ -315,14 +322,6 @@ declare function parse(text: string, optsOrReviver?: ParseOptions | ((key: strin
|
|
|
315
322
|
*/
|
|
316
323
|
declare function stringify(obj: unknown): string;
|
|
317
324
|
|
|
318
|
-
type robustJson_ParseOptions = ParseOptions;
|
|
319
|
-
declare const robustJson_parse: typeof parse;
|
|
320
|
-
declare const robustJson_stringify: typeof stringify;
|
|
321
|
-
declare const robustJson_transform: typeof transform;
|
|
322
|
-
declare namespace robustJson {
|
|
323
|
-
export { type robustJson_ParseOptions as ParseOptions, robustJson_parse as parse, robustJson_stringify as stringify, robustJson_transform as transform };
|
|
324
|
-
}
|
|
325
|
-
|
|
326
325
|
declare function isToolCallContent(content: unknown): content is LanguageModelV3ToolCall;
|
|
327
326
|
declare function isToolResultPart(content: unknown): content is LanguageModelV3ToolResultPart;
|
|
328
327
|
declare function hasInputProperty(obj: unknown): obj is {
|
|
@@ -333,4 +332,4 @@ declare const gemmaToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
|
333
332
|
declare const hermesToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
334
333
|
declare const morphXmlToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
335
334
|
|
|
336
|
-
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,6 +15,7 @@ import {
|
|
|
15
15
|
isToolChoiceActive,
|
|
16
16
|
isToolResultPart,
|
|
17
17
|
jsonMixProtocol,
|
|
18
|
+
logParseFailure,
|
|
18
19
|
logParsedChunk,
|
|
19
20
|
logParsedSummary,
|
|
20
21
|
logRawChunk,
|
|
@@ -22,12 +23,10 @@ import {
|
|
|
22
23
|
morphXmlToolMiddleware,
|
|
23
24
|
originalToolsSchema,
|
|
24
25
|
parse,
|
|
25
|
-
robust_json_exports,
|
|
26
26
|
stringify,
|
|
27
27
|
transform
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-L4X363EL.js";
|
|
29
29
|
export {
|
|
30
|
-
robust_json_exports as RJSON,
|
|
31
30
|
createDynamicIfThenElseSchema,
|
|
32
31
|
createToolMiddleware,
|
|
33
32
|
decodeOriginalTools,
|
|
@@ -44,6 +43,7 @@ export {
|
|
|
44
43
|
isToolChoiceActive,
|
|
45
44
|
isToolResultPart,
|
|
46
45
|
jsonMixProtocol,
|
|
46
|
+
logParseFailure,
|
|
47
47
|
logParsedChunk,
|
|
48
48
|
logParsedSummary,
|
|
49
49
|
logRawChunk,
|
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk-tool/parser",
|
|
3
|
-
"version": "3.0.0-canary.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "3.0.0-canary.1",
|
|
4
|
+
"description": "AI SDK middleware for tool call parsing",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/minpeter/ai-sdk-tool-call-middleware",
|
|
9
|
+
"directory": "packages/parser"
|
|
10
|
+
},
|
|
6
11
|
"main": "./dist/index.js",
|
|
7
12
|
"module": "./dist/index.mjs",
|
|
8
13
|
"types": "./dist/index.d.ts",
|
|
@@ -24,25 +29,27 @@
|
|
|
24
29
|
"publishConfig": {
|
|
25
30
|
"access": "public"
|
|
26
31
|
},
|
|
27
|
-
"keywords": [],
|
|
28
|
-
"author": "",
|
|
29
|
-
"license": "Apache-2.0",
|
|
30
32
|
"dependencies": {
|
|
31
|
-
"@ai-sdk/provider": "3.0.0
|
|
32
|
-
"@ai-sdk/provider-utils": "4.0.0
|
|
33
|
+
"@ai-sdk/provider": "3.0.0",
|
|
34
|
+
"@ai-sdk/provider-utils": "4.0.0",
|
|
33
35
|
"@ai-sdk-tool/rxml": "0.1.1"
|
|
34
36
|
},
|
|
35
37
|
"devDependencies": {
|
|
36
|
-
"@ai-sdk/openai-compatible": "2.0.0
|
|
37
|
-
"@types/node": "^
|
|
38
|
-
"ai": "6.0.
|
|
39
|
-
"tsup": "^8.5.
|
|
40
|
-
"zod": "^4.1
|
|
38
|
+
"@ai-sdk/openai-compatible": "2.0.0",
|
|
39
|
+
"@types/node": "^25.0.3",
|
|
40
|
+
"ai": "6.0.1",
|
|
41
|
+
"tsup": "^8.5.1",
|
|
42
|
+
"zod": "^4.2.1",
|
|
43
|
+
"@ai-sdkx/tsconfig": "0.0.0"
|
|
41
44
|
},
|
|
45
|
+
"keywords": [],
|
|
46
|
+
"author": "",
|
|
47
|
+
"license": "Apache-2.0",
|
|
42
48
|
"scripts": {
|
|
43
|
-
"build": "tsup",
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"typecheck": "tsc --noEmit"
|
|
49
|
+
"build": "pnpm clean && tsup --tsconfig tsconfig.build.json",
|
|
50
|
+
"build:watch": "pnpm clean && tsup --watch --tsconfig tsconfig.build.json",
|
|
51
|
+
"clean": "rm -rf dist *.tsbuildinfo",
|
|
52
|
+
"typecheck": "tsc --noEmit",
|
|
53
|
+
"test": "vitest run"
|
|
47
54
|
}
|
|
48
55
|
}
|