@ai-sdk-tool/parser 3.0.0-canary.0 → 3.0.0-canary.2
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-LB5ALTRD.js} +1510 -455
- package/dist/chunk-LB5ALTRD.js.map +1 -0
- package/dist/community.cjs +1499 -474
- package/dist/community.cjs.map +1 -1
- package/dist/community.js +2 -2
- package/dist/community.js.map +1 -1
- package/dist/index.cjs +1529 -458
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +87 -23
- package/dist/index.d.ts +87 -23
- package/dist/index.js +21 -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,97 @@ 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
|
+
/**
|
|
125
|
+
* Heuristic Engine for XML Tool-Call Parsing
|
|
126
|
+
*
|
|
127
|
+
* Pluggable pipeline for text normalization, repair, and object coercion.
|
|
128
|
+
*
|
|
129
|
+
* Phases:
|
|
130
|
+
* 1. pre-parse: Text normalization before initial parse
|
|
131
|
+
* 2. fallback-reparse: Text repair when initial parse fails
|
|
132
|
+
* 3. post-parse: Object repair/coercion after successful parse
|
|
133
|
+
*/
|
|
134
|
+
type HeuristicPhase = "pre-parse" | "fallback-reparse" | "post-parse";
|
|
135
|
+
interface IntermediateCall {
|
|
136
|
+
toolName: string;
|
|
137
|
+
schema: unknown;
|
|
138
|
+
rawSegment: string;
|
|
139
|
+
parsed: unknown | null;
|
|
140
|
+
errors: unknown[];
|
|
141
|
+
meta?: Record<string, unknown>;
|
|
142
|
+
}
|
|
143
|
+
interface HeuristicResult {
|
|
144
|
+
rawSegment?: string;
|
|
145
|
+
parsed?: unknown;
|
|
146
|
+
reparse?: boolean;
|
|
147
|
+
stop?: boolean;
|
|
148
|
+
warnings?: string[];
|
|
149
|
+
}
|
|
150
|
+
interface ToolCallHeuristic$1 {
|
|
151
|
+
id: string;
|
|
152
|
+
phase: HeuristicPhase;
|
|
153
|
+
applies(ctx: IntermediateCall): boolean;
|
|
154
|
+
run(ctx: IntermediateCall): HeuristicResult;
|
|
155
|
+
}
|
|
156
|
+
interface PipelineConfig$1 {
|
|
157
|
+
preParse?: ToolCallHeuristic$1[];
|
|
158
|
+
fallbackReparse?: ToolCallHeuristic$1[];
|
|
159
|
+
postParse?: ToolCallHeuristic$1[];
|
|
160
|
+
}
|
|
161
|
+
interface HeuristicEngineOptions {
|
|
162
|
+
parse: (xml: string, schema: unknown) => unknown;
|
|
163
|
+
onError?: (message: string, metadata?: Record<string, unknown>) => void;
|
|
164
|
+
maxReparses?: number;
|
|
165
|
+
}
|
|
166
|
+
declare function applyHeuristicPipeline(ctx: IntermediateCall, config: PipelineConfig$1, options: HeuristicEngineOptions): IntermediateCall;
|
|
167
|
+
declare function createIntermediateCall(toolName: string, rawSegment: string, schema: unknown): IntermediateCall;
|
|
168
|
+
declare function mergePipelineConfigs(...configs: PipelineConfig$1[]): PipelineConfig$1;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Default heuristics for XML tool-call parsing.
|
|
172
|
+
* Modular, reusable versions of normalization/repair logic from morph-xml-protocol.
|
|
173
|
+
*/
|
|
174
|
+
|
|
175
|
+
declare const normalizeCloseTagsHeuristic: ToolCallHeuristic$1;
|
|
176
|
+
declare const escapeInvalidLtHeuristic: ToolCallHeuristic$1;
|
|
177
|
+
declare const balanceTagsHeuristic: ToolCallHeuristic$1;
|
|
178
|
+
declare const dedupeShellStringTagsHeuristic: ToolCallHeuristic$1;
|
|
179
|
+
declare const repairAgainstSchemaHeuristic: ToolCallHeuristic$1;
|
|
180
|
+
declare const defaultPipelineConfig: PipelineConfig$1;
|
|
125
181
|
|
|
126
|
-
|
|
182
|
+
type PipelineConfig = PipelineConfig$1;
|
|
183
|
+
type ToolCallHeuristic = ToolCallHeuristic$1;
|
|
184
|
+
interface MorphXmlProtocolOptions {
|
|
185
|
+
heuristics?: ToolCallHeuristic[];
|
|
186
|
+
pipeline?: PipelineConfig;
|
|
187
|
+
maxReparses?: number;
|
|
188
|
+
}
|
|
189
|
+
declare const morphXmlProtocol: (protocolOptions?: MorphXmlProtocolOptions) => ToolCallProtocol;
|
|
190
|
+
|
|
191
|
+
declare function createToolMiddleware({ protocol, toolSystemPromptTemplate, placement, }: {
|
|
127
192
|
protocol: ToolCallProtocol | (() => ToolCallProtocol);
|
|
128
193
|
toolSystemPromptTemplate: (tools: string) => string;
|
|
194
|
+
placement?: "first" | "last";
|
|
129
195
|
}): LanguageModelV3Middleware;
|
|
130
196
|
|
|
131
197
|
type DebugLevel = "off" | "stream" | "parse";
|
|
132
198
|
declare function getDebugLevel(): DebugLevel;
|
|
199
|
+
declare function logParseFailure({ phase, reason, snippet, error, }: {
|
|
200
|
+
phase: "generated-text" | "stream" | string;
|
|
201
|
+
reason: string;
|
|
202
|
+
snippet?: string;
|
|
203
|
+
error?: unknown;
|
|
204
|
+
}): void;
|
|
133
205
|
declare function logRawChunk(part: unknown): void;
|
|
134
206
|
declare function logParsedChunk(part: unknown): void;
|
|
135
207
|
declare function logParsedSummary({ toolCalls, originalText, }: {
|
|
@@ -145,12 +217,12 @@ declare function logParsedSummary({ toolCalls, originalText, }: {
|
|
|
145
217
|
* matches exactly one of the provided tools based on its 'name' property,
|
|
146
218
|
* and then applies the corresponding tool's 'parameters' schema to its 'arguments' property.
|
|
147
219
|
*
|
|
148
|
-
* @param tools An array of tool definitions (LanguageModelV3FunctionTool or
|
|
220
|
+
* @param tools An array of tool definitions (LanguageModelV3FunctionTool or LanguageModelV3ProviderTool).
|
|
149
221
|
* Each tool must have a unique 'name' and its 'parameters' must be a valid JSON Schema.
|
|
150
222
|
* @returns A JSONSchema7 object representing the dynamic validation logic.
|
|
151
|
-
* @throws Error if a 'provider
|
|
223
|
+
* @throws Error if a 'provider' tool is encountered, as they are not supported by this middleware.
|
|
152
224
|
*/
|
|
153
|
-
declare function createDynamicIfThenElseSchema(tools: (LanguageModelV3FunctionTool |
|
|
225
|
+
declare function createDynamicIfThenElseSchema(tools: (LanguageModelV3FunctionTool | LanguageModelV3ProviderTool)[]): JSONSchema7;
|
|
154
226
|
|
|
155
227
|
/**
|
|
156
228
|
* Returns the index of the start of the searchedText in the text, or null if it
|
|
@@ -164,7 +236,7 @@ declare function extractOnErrorOption(providerOptions?: unknown): {
|
|
|
164
236
|
onError?: OnErrorFn;
|
|
165
237
|
} | undefined;
|
|
166
238
|
|
|
167
|
-
|
|
239
|
+
interface ToolCallMiddlewareProviderOptions {
|
|
168
240
|
toolCallMiddleware?: {
|
|
169
241
|
debugSummary?: {
|
|
170
242
|
originalText?: string;
|
|
@@ -179,7 +251,7 @@ type ToolCallMiddlewareProviderOptions = {
|
|
|
179
251
|
inputSchema: string;
|
|
180
252
|
}>;
|
|
181
253
|
};
|
|
182
|
-
}
|
|
254
|
+
}
|
|
183
255
|
declare const originalToolsSchema: {
|
|
184
256
|
encode: typeof encodeOriginalTools;
|
|
185
257
|
decode: typeof decodeOriginalTools;
|
|
@@ -211,7 +283,7 @@ declare function escapeRegExp(literal: string): string;
|
|
|
211
283
|
/**
|
|
212
284
|
* Options for configuring JSON parsing behavior
|
|
213
285
|
*/
|
|
214
|
-
|
|
286
|
+
interface ParseOptions {
|
|
215
287
|
/**
|
|
216
288
|
* Enable relaxed JSON syntax parsing (unquoted keys, single quotes, trailing commas, comments)
|
|
217
289
|
* @default true
|
|
@@ -243,7 +315,7 @@ type ParseOptions = {
|
|
|
243
315
|
* @returns The transformed value
|
|
244
316
|
*/
|
|
245
317
|
reviver?: (key: string, value: unknown) => unknown;
|
|
246
|
-
}
|
|
318
|
+
}
|
|
247
319
|
/**
|
|
248
320
|
* Transform relaxed JSON syntax to standard JSON string
|
|
249
321
|
*
|
|
@@ -315,14 +387,6 @@ declare function parse(text: string, optsOrReviver?: ParseOptions | ((key: strin
|
|
|
315
387
|
*/
|
|
316
388
|
declare function stringify(obj: unknown): string;
|
|
317
389
|
|
|
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
390
|
declare function isToolCallContent(content: unknown): content is LanguageModelV3ToolCall;
|
|
327
391
|
declare function isToolResultPart(content: unknown): content is LanguageModelV3ToolResultPart;
|
|
328
392
|
declare function hasInputProperty(obj: unknown): obj is {
|
|
@@ -333,4 +397,4 @@ declare const gemmaToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
|
333
397
|
declare const hermesToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
334
398
|
declare const morphXmlToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
335
399
|
|
|
336
|
-
export { type DebugLevel, type OnErrorFn,
|
|
400
|
+
export { type DebugLevel, type HeuristicEngineOptions, type HeuristicPhase, type HeuristicResult, type IntermediateCall, type MorphXmlProtocolOptions, type OnErrorFn, type PipelineConfig$1 as PipelineConfig, type ParseOptions as RJSONParseOptions, type ToolCallHeuristic$1 as ToolCallHeuristic, type ToolCallMiddlewareProviderOptions, applyHeuristicPipeline, balanceTagsHeuristic, createDynamicIfThenElseSchema, createIntermediateCall, createToolMiddleware, decodeOriginalTools, dedupeShellStringTagsHeuristic, defaultPipelineConfig, encodeOriginalTools, escapeInvalidLtHeuristic, escapeRegExp, extractOnErrorOption, extractToolNamesFromOriginalTools, gemmaToolMiddleware, getDebugLevel, getPotentialStartIndex, hasInputProperty, hermesToolMiddleware, isToolCallContent, isToolChoiceActive, isToolResultPart, jsonMixProtocol, logParseFailure, logParsedChunk, logParsedSummary, logRawChunk, mergePipelineConfigs, morphXmlProtocol, morphXmlToolMiddleware, normalizeCloseTagsHeuristic, originalToolsSchema, parse as parseRJSON, repairAgainstSchemaHeuristic, 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,97 @@ 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
|
+
/**
|
|
125
|
+
* Heuristic Engine for XML Tool-Call Parsing
|
|
126
|
+
*
|
|
127
|
+
* Pluggable pipeline for text normalization, repair, and object coercion.
|
|
128
|
+
*
|
|
129
|
+
* Phases:
|
|
130
|
+
* 1. pre-parse: Text normalization before initial parse
|
|
131
|
+
* 2. fallback-reparse: Text repair when initial parse fails
|
|
132
|
+
* 3. post-parse: Object repair/coercion after successful parse
|
|
133
|
+
*/
|
|
134
|
+
type HeuristicPhase = "pre-parse" | "fallback-reparse" | "post-parse";
|
|
135
|
+
interface IntermediateCall {
|
|
136
|
+
toolName: string;
|
|
137
|
+
schema: unknown;
|
|
138
|
+
rawSegment: string;
|
|
139
|
+
parsed: unknown | null;
|
|
140
|
+
errors: unknown[];
|
|
141
|
+
meta?: Record<string, unknown>;
|
|
142
|
+
}
|
|
143
|
+
interface HeuristicResult {
|
|
144
|
+
rawSegment?: string;
|
|
145
|
+
parsed?: unknown;
|
|
146
|
+
reparse?: boolean;
|
|
147
|
+
stop?: boolean;
|
|
148
|
+
warnings?: string[];
|
|
149
|
+
}
|
|
150
|
+
interface ToolCallHeuristic$1 {
|
|
151
|
+
id: string;
|
|
152
|
+
phase: HeuristicPhase;
|
|
153
|
+
applies(ctx: IntermediateCall): boolean;
|
|
154
|
+
run(ctx: IntermediateCall): HeuristicResult;
|
|
155
|
+
}
|
|
156
|
+
interface PipelineConfig$1 {
|
|
157
|
+
preParse?: ToolCallHeuristic$1[];
|
|
158
|
+
fallbackReparse?: ToolCallHeuristic$1[];
|
|
159
|
+
postParse?: ToolCallHeuristic$1[];
|
|
160
|
+
}
|
|
161
|
+
interface HeuristicEngineOptions {
|
|
162
|
+
parse: (xml: string, schema: unknown) => unknown;
|
|
163
|
+
onError?: (message: string, metadata?: Record<string, unknown>) => void;
|
|
164
|
+
maxReparses?: number;
|
|
165
|
+
}
|
|
166
|
+
declare function applyHeuristicPipeline(ctx: IntermediateCall, config: PipelineConfig$1, options: HeuristicEngineOptions): IntermediateCall;
|
|
167
|
+
declare function createIntermediateCall(toolName: string, rawSegment: string, schema: unknown): IntermediateCall;
|
|
168
|
+
declare function mergePipelineConfigs(...configs: PipelineConfig$1[]): PipelineConfig$1;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Default heuristics for XML tool-call parsing.
|
|
172
|
+
* Modular, reusable versions of normalization/repair logic from morph-xml-protocol.
|
|
173
|
+
*/
|
|
174
|
+
|
|
175
|
+
declare const normalizeCloseTagsHeuristic: ToolCallHeuristic$1;
|
|
176
|
+
declare const escapeInvalidLtHeuristic: ToolCallHeuristic$1;
|
|
177
|
+
declare const balanceTagsHeuristic: ToolCallHeuristic$1;
|
|
178
|
+
declare const dedupeShellStringTagsHeuristic: ToolCallHeuristic$1;
|
|
179
|
+
declare const repairAgainstSchemaHeuristic: ToolCallHeuristic$1;
|
|
180
|
+
declare const defaultPipelineConfig: PipelineConfig$1;
|
|
125
181
|
|
|
126
|
-
|
|
182
|
+
type PipelineConfig = PipelineConfig$1;
|
|
183
|
+
type ToolCallHeuristic = ToolCallHeuristic$1;
|
|
184
|
+
interface MorphXmlProtocolOptions {
|
|
185
|
+
heuristics?: ToolCallHeuristic[];
|
|
186
|
+
pipeline?: PipelineConfig;
|
|
187
|
+
maxReparses?: number;
|
|
188
|
+
}
|
|
189
|
+
declare const morphXmlProtocol: (protocolOptions?: MorphXmlProtocolOptions) => ToolCallProtocol;
|
|
190
|
+
|
|
191
|
+
declare function createToolMiddleware({ protocol, toolSystemPromptTemplate, placement, }: {
|
|
127
192
|
protocol: ToolCallProtocol | (() => ToolCallProtocol);
|
|
128
193
|
toolSystemPromptTemplate: (tools: string) => string;
|
|
194
|
+
placement?: "first" | "last";
|
|
129
195
|
}): LanguageModelV3Middleware;
|
|
130
196
|
|
|
131
197
|
type DebugLevel = "off" | "stream" | "parse";
|
|
132
198
|
declare function getDebugLevel(): DebugLevel;
|
|
199
|
+
declare function logParseFailure({ phase, reason, snippet, error, }: {
|
|
200
|
+
phase: "generated-text" | "stream" | string;
|
|
201
|
+
reason: string;
|
|
202
|
+
snippet?: string;
|
|
203
|
+
error?: unknown;
|
|
204
|
+
}): void;
|
|
133
205
|
declare function logRawChunk(part: unknown): void;
|
|
134
206
|
declare function logParsedChunk(part: unknown): void;
|
|
135
207
|
declare function logParsedSummary({ toolCalls, originalText, }: {
|
|
@@ -145,12 +217,12 @@ declare function logParsedSummary({ toolCalls, originalText, }: {
|
|
|
145
217
|
* matches exactly one of the provided tools based on its 'name' property,
|
|
146
218
|
* and then applies the corresponding tool's 'parameters' schema to its 'arguments' property.
|
|
147
219
|
*
|
|
148
|
-
* @param tools An array of tool definitions (LanguageModelV3FunctionTool or
|
|
220
|
+
* @param tools An array of tool definitions (LanguageModelV3FunctionTool or LanguageModelV3ProviderTool).
|
|
149
221
|
* Each tool must have a unique 'name' and its 'parameters' must be a valid JSON Schema.
|
|
150
222
|
* @returns A JSONSchema7 object representing the dynamic validation logic.
|
|
151
|
-
* @throws Error if a 'provider
|
|
223
|
+
* @throws Error if a 'provider' tool is encountered, as they are not supported by this middleware.
|
|
152
224
|
*/
|
|
153
|
-
declare function createDynamicIfThenElseSchema(tools: (LanguageModelV3FunctionTool |
|
|
225
|
+
declare function createDynamicIfThenElseSchema(tools: (LanguageModelV3FunctionTool | LanguageModelV3ProviderTool)[]): JSONSchema7;
|
|
154
226
|
|
|
155
227
|
/**
|
|
156
228
|
* Returns the index of the start of the searchedText in the text, or null if it
|
|
@@ -164,7 +236,7 @@ declare function extractOnErrorOption(providerOptions?: unknown): {
|
|
|
164
236
|
onError?: OnErrorFn;
|
|
165
237
|
} | undefined;
|
|
166
238
|
|
|
167
|
-
|
|
239
|
+
interface ToolCallMiddlewareProviderOptions {
|
|
168
240
|
toolCallMiddleware?: {
|
|
169
241
|
debugSummary?: {
|
|
170
242
|
originalText?: string;
|
|
@@ -179,7 +251,7 @@ type ToolCallMiddlewareProviderOptions = {
|
|
|
179
251
|
inputSchema: string;
|
|
180
252
|
}>;
|
|
181
253
|
};
|
|
182
|
-
}
|
|
254
|
+
}
|
|
183
255
|
declare const originalToolsSchema: {
|
|
184
256
|
encode: typeof encodeOriginalTools;
|
|
185
257
|
decode: typeof decodeOriginalTools;
|
|
@@ -211,7 +283,7 @@ declare function escapeRegExp(literal: string): string;
|
|
|
211
283
|
/**
|
|
212
284
|
* Options for configuring JSON parsing behavior
|
|
213
285
|
*/
|
|
214
|
-
|
|
286
|
+
interface ParseOptions {
|
|
215
287
|
/**
|
|
216
288
|
* Enable relaxed JSON syntax parsing (unquoted keys, single quotes, trailing commas, comments)
|
|
217
289
|
* @default true
|
|
@@ -243,7 +315,7 @@ type ParseOptions = {
|
|
|
243
315
|
* @returns The transformed value
|
|
244
316
|
*/
|
|
245
317
|
reviver?: (key: string, value: unknown) => unknown;
|
|
246
|
-
}
|
|
318
|
+
}
|
|
247
319
|
/**
|
|
248
320
|
* Transform relaxed JSON syntax to standard JSON string
|
|
249
321
|
*
|
|
@@ -315,14 +387,6 @@ declare function parse(text: string, optsOrReviver?: ParseOptions | ((key: strin
|
|
|
315
387
|
*/
|
|
316
388
|
declare function stringify(obj: unknown): string;
|
|
317
389
|
|
|
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
390
|
declare function isToolCallContent(content: unknown): content is LanguageModelV3ToolCall;
|
|
327
391
|
declare function isToolResultPart(content: unknown): content is LanguageModelV3ToolResultPart;
|
|
328
392
|
declare function hasInputProperty(obj: unknown): obj is {
|
|
@@ -333,4 +397,4 @@ declare const gemmaToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
|
333
397
|
declare const hermesToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
334
398
|
declare const morphXmlToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
|
|
335
399
|
|
|
336
|
-
export { type DebugLevel, type OnErrorFn,
|
|
400
|
+
export { type DebugLevel, type HeuristicEngineOptions, type HeuristicPhase, type HeuristicResult, type IntermediateCall, type MorphXmlProtocolOptions, type OnErrorFn, type PipelineConfig$1 as PipelineConfig, type ParseOptions as RJSONParseOptions, type ToolCallHeuristic$1 as ToolCallHeuristic, type ToolCallMiddlewareProviderOptions, applyHeuristicPipeline, balanceTagsHeuristic, createDynamicIfThenElseSchema, createIntermediateCall, createToolMiddleware, decodeOriginalTools, dedupeShellStringTagsHeuristic, defaultPipelineConfig, encodeOriginalTools, escapeInvalidLtHeuristic, escapeRegExp, extractOnErrorOption, extractToolNamesFromOriginalTools, gemmaToolMiddleware, getDebugLevel, getPotentialStartIndex, hasInputProperty, hermesToolMiddleware, isToolCallContent, isToolChoiceActive, isToolResultPart, jsonMixProtocol, logParseFailure, logParsedChunk, logParsedSummary, logRawChunk, mergePipelineConfigs, morphXmlProtocol, morphXmlToolMiddleware, normalizeCloseTagsHeuristic, originalToolsSchema, parse as parseRJSON, repairAgainstSchemaHeuristic, stringify as stringifyRJSON, transform as transformRJSON };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
+
applyHeuristicPipeline,
|
|
3
|
+
balanceTagsHeuristic,
|
|
2
4
|
createDynamicIfThenElseSchema,
|
|
5
|
+
createIntermediateCall,
|
|
3
6
|
createToolMiddleware,
|
|
4
7
|
decodeOriginalTools,
|
|
8
|
+
dedupeShellStringTagsHeuristic,
|
|
9
|
+
defaultPipelineConfig,
|
|
5
10
|
encodeOriginalTools,
|
|
11
|
+
escapeInvalidLtHeuristic,
|
|
6
12
|
escapeRegExp,
|
|
7
13
|
extractOnErrorOption,
|
|
8
14
|
extractToolNamesFromOriginalTools,
|
|
@@ -15,23 +21,31 @@ import {
|
|
|
15
21
|
isToolChoiceActive,
|
|
16
22
|
isToolResultPart,
|
|
17
23
|
jsonMixProtocol,
|
|
24
|
+
logParseFailure,
|
|
18
25
|
logParsedChunk,
|
|
19
26
|
logParsedSummary,
|
|
20
27
|
logRawChunk,
|
|
28
|
+
mergePipelineConfigs,
|
|
21
29
|
morphXmlProtocol,
|
|
22
30
|
morphXmlToolMiddleware,
|
|
31
|
+
normalizeCloseTagsHeuristic,
|
|
23
32
|
originalToolsSchema,
|
|
24
33
|
parse,
|
|
25
|
-
|
|
34
|
+
repairAgainstSchemaHeuristic,
|
|
26
35
|
stringify,
|
|
27
36
|
transform
|
|
28
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-LB5ALTRD.js";
|
|
29
38
|
export {
|
|
30
|
-
|
|
39
|
+
applyHeuristicPipeline,
|
|
40
|
+
balanceTagsHeuristic,
|
|
31
41
|
createDynamicIfThenElseSchema,
|
|
42
|
+
createIntermediateCall,
|
|
32
43
|
createToolMiddleware,
|
|
33
44
|
decodeOriginalTools,
|
|
45
|
+
dedupeShellStringTagsHeuristic,
|
|
46
|
+
defaultPipelineConfig,
|
|
34
47
|
encodeOriginalTools,
|
|
48
|
+
escapeInvalidLtHeuristic,
|
|
35
49
|
escapeRegExp,
|
|
36
50
|
extractOnErrorOption,
|
|
37
51
|
extractToolNamesFromOriginalTools,
|
|
@@ -44,13 +58,17 @@ export {
|
|
|
44
58
|
isToolChoiceActive,
|
|
45
59
|
isToolResultPart,
|
|
46
60
|
jsonMixProtocol,
|
|
61
|
+
logParseFailure,
|
|
47
62
|
logParsedChunk,
|
|
48
63
|
logParsedSummary,
|
|
49
64
|
logRawChunk,
|
|
65
|
+
mergePipelineConfigs,
|
|
50
66
|
morphXmlProtocol,
|
|
51
67
|
morphXmlToolMiddleware,
|
|
68
|
+
normalizeCloseTagsHeuristic,
|
|
52
69
|
originalToolsSchema,
|
|
53
70
|
parse as parseRJSON,
|
|
71
|
+
repairAgainstSchemaHeuristic,
|
|
54
72
|
stringify as stringifyRJSON,
|
|
55
73
|
transform as transformRJSON
|
|
56
74
|
};
|
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.2",
|
|
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
|
}
|