@ai-sdk-tool/parser 3.1.2 → 3.2.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/dist/{chunk-TQT6XSP7.js → chunk-PIUBQRFC.js} +166 -1374
- package/dist/chunk-PIUBQRFC.js.map +1 -0
- package/dist/community.cjs +216 -1310
- package/dist/community.cjs.map +1 -1
- package/dist/community.js +1 -1
- package/dist/index.cjs +168 -1388
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -171
- package/dist/index.d.ts +9 -171
- package/dist/index.js +1 -25
- package/package.json +11 -9
- package/dist/chunk-TQT6XSP7.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,65 +1,8 @@
|
|
|
1
|
+
export * from '@ai-sdk-tool/rjson';
|
|
1
2
|
import * as _ai_sdk_provider from '@ai-sdk/provider';
|
|
2
3
|
import { LanguageModelV3FunctionTool, LanguageModelV3ToolCall, LanguageModelV3Content, LanguageModelV3StreamPart, LanguageModelV3ProviderTool, JSONSchema7, LanguageModelV3, LanguageModelV3Middleware, LanguageModelV3Prompt, SharedV3ProviderOptions } from '@ai-sdk/provider';
|
|
3
4
|
import { ToolResultPart } from '@ai-sdk/provider-utils';
|
|
4
5
|
|
|
5
|
-
/**
|
|
6
|
-
* Heuristic Engine for XML Tool-Call Parsing
|
|
7
|
-
*
|
|
8
|
-
* Pluggable pipeline for text normalization, repair, and object coercion.
|
|
9
|
-
*
|
|
10
|
-
* Phases:
|
|
11
|
-
* 1. pre-parse: Text normalization before initial parse
|
|
12
|
-
* 2. fallback-reparse: Text repair when initial parse fails
|
|
13
|
-
* 3. post-parse: Object repair/coercion after successful parse
|
|
14
|
-
*/
|
|
15
|
-
type HeuristicPhase = "pre-parse" | "fallback-reparse" | "post-parse";
|
|
16
|
-
interface IntermediateCall {
|
|
17
|
-
toolName: string;
|
|
18
|
-
schema: unknown;
|
|
19
|
-
rawSegment: string;
|
|
20
|
-
parsed: unknown | null;
|
|
21
|
-
errors: unknown[];
|
|
22
|
-
meta?: Record<string, unknown>;
|
|
23
|
-
}
|
|
24
|
-
interface HeuristicResult {
|
|
25
|
-
rawSegment?: string;
|
|
26
|
-
parsed?: unknown;
|
|
27
|
-
reparse?: boolean;
|
|
28
|
-
stop?: boolean;
|
|
29
|
-
warnings?: string[];
|
|
30
|
-
}
|
|
31
|
-
interface ToolCallHeuristic$1 {
|
|
32
|
-
id: string;
|
|
33
|
-
phase: HeuristicPhase;
|
|
34
|
-
applies(ctx: IntermediateCall): boolean;
|
|
35
|
-
run(ctx: IntermediateCall): HeuristicResult;
|
|
36
|
-
}
|
|
37
|
-
interface PipelineConfig$1 {
|
|
38
|
-
preParse?: ToolCallHeuristic$1[];
|
|
39
|
-
fallbackReparse?: ToolCallHeuristic$1[];
|
|
40
|
-
postParse?: ToolCallHeuristic$1[];
|
|
41
|
-
}
|
|
42
|
-
interface HeuristicEngineOptions {
|
|
43
|
-
parse: (xml: string, schema: unknown) => unknown;
|
|
44
|
-
onError?: (message: string, metadata?: Record<string, unknown>) => void;
|
|
45
|
-
maxReparses?: number;
|
|
46
|
-
}
|
|
47
|
-
declare function applyHeuristicPipeline(ctx: IntermediateCall, config: PipelineConfig$1, options: HeuristicEngineOptions): IntermediateCall;
|
|
48
|
-
declare function createIntermediateCall(toolName: string, rawSegment: string, schema: unknown): IntermediateCall;
|
|
49
|
-
declare function mergePipelineConfigs(...configs: PipelineConfig$1[]): PipelineConfig$1;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Default heuristics for XML tool-call parsing.
|
|
53
|
-
* Modular, reusable versions of normalization/repair logic from morph-xml-protocol.
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
declare const normalizeCloseTagsHeuristic: ToolCallHeuristic$1;
|
|
57
|
-
declare const escapeInvalidLtHeuristic: ToolCallHeuristic$1;
|
|
58
|
-
declare const balanceTagsHeuristic: ToolCallHeuristic$1;
|
|
59
|
-
declare const dedupeShellStringTagsHeuristic: ToolCallHeuristic$1;
|
|
60
|
-
declare const repairAgainstSchemaHeuristic: ToolCallHeuristic$1;
|
|
61
|
-
declare const defaultPipelineConfig: PipelineConfig$1;
|
|
62
|
-
|
|
63
6
|
interface TCMProtocol {
|
|
64
7
|
formatTools({ tools, toolSystemPromptTemplate, }: {
|
|
65
8
|
tools: LanguageModelV3FunctionTool[];
|
|
@@ -94,12 +37,14 @@ interface JsonProtocolOptions {
|
|
|
94
37
|
}
|
|
95
38
|
declare const jsonProtocol: ({ toolCallStart, toolCallEnd, }?: JsonProtocolOptions) => TCMProtocol;
|
|
96
39
|
|
|
97
|
-
type PipelineConfig = PipelineConfig$1;
|
|
98
|
-
type ToolCallHeuristic = ToolCallHeuristic$1;
|
|
99
40
|
interface XmlProtocolOptions {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
41
|
+
parseOptions?: {
|
|
42
|
+
repair?: boolean;
|
|
43
|
+
maxReparses?: number;
|
|
44
|
+
onError?: (message: string, metadata?: Record<string, unknown>) => void;
|
|
45
|
+
noChildNodes?: string[];
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
};
|
|
103
48
|
}
|
|
104
49
|
declare const xmlProtocol: (protocolOptions?: XmlProtocolOptions) => TCMCoreProtocol;
|
|
105
50
|
|
|
@@ -198,113 +143,6 @@ declare function isToolChoiceActive(params: {
|
|
|
198
143
|
|
|
199
144
|
declare function escapeRegExp(literal: string): string;
|
|
200
145
|
|
|
201
|
-
/**
|
|
202
|
-
* Options for configuring JSON parsing behavior
|
|
203
|
-
*/
|
|
204
|
-
interface ParseOptions {
|
|
205
|
-
/**
|
|
206
|
-
* Enable relaxed JSON syntax parsing (unquoted keys, single quotes, trailing commas, comments)
|
|
207
|
-
* @default true
|
|
208
|
-
*/
|
|
209
|
-
relaxed?: boolean;
|
|
210
|
-
/**
|
|
211
|
-
* Collect parsing warnings instead of throwing immediately. Implies tolerant mode.
|
|
212
|
-
* At the end of parsing, if warnings exist, throws with warning details.
|
|
213
|
-
* @default false
|
|
214
|
-
*/
|
|
215
|
-
warnings?: boolean;
|
|
216
|
-
/**
|
|
217
|
-
* Continue parsing when encountering recoverable errors, collecting warnings.
|
|
218
|
-
* In strict mode (false), throws immediately on first error.
|
|
219
|
-
* @default false
|
|
220
|
-
*/
|
|
221
|
-
tolerant?: boolean;
|
|
222
|
-
/**
|
|
223
|
-
* Allow duplicate object keys in JSON.
|
|
224
|
-
* - true: Allow duplicates (uses last value, like native JSON.parse)
|
|
225
|
-
* - false: Reject duplicates with error (enforces JSON specification)
|
|
226
|
-
* @default false
|
|
227
|
-
*/
|
|
228
|
-
duplicate?: boolean;
|
|
229
|
-
/**
|
|
230
|
-
* Optional reviver function to transform parsed values (same as JSON.parse reviver)
|
|
231
|
-
* @param key - The object key or array index
|
|
232
|
-
* @param value - The parsed value
|
|
233
|
-
* @returns The transformed value
|
|
234
|
-
*/
|
|
235
|
-
reviver?: (key: string, value: unknown) => unknown;
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Transform relaxed JSON syntax to standard JSON string
|
|
239
|
-
*
|
|
240
|
-
* Converts relaxed JSON features (unquoted keys, single quotes, trailing commas, comments)
|
|
241
|
-
* into valid standard JSON syntax that can be parsed by native JSON.parse().
|
|
242
|
-
*
|
|
243
|
-
* @param text - The relaxed JSON string to transform
|
|
244
|
-
* @returns A standard JSON string
|
|
245
|
-
*
|
|
246
|
-
* @example
|
|
247
|
-
* ```typescript
|
|
248
|
-
* transform('{key: "value", trailing: "comma",}')
|
|
249
|
-
* // Returns: '{"key": "value", "trailing": "comma"}'
|
|
250
|
-
*
|
|
251
|
-
* transform("{'single': 'quotes'}")
|
|
252
|
-
* // Returns: '{"single": "quotes"}'
|
|
253
|
-
* ```
|
|
254
|
-
*/
|
|
255
|
-
declare function transform(text: string): string;
|
|
256
|
-
/**
|
|
257
|
-
* Parse a JSON string with enhanced features beyond standard JSON.parse()
|
|
258
|
-
*
|
|
259
|
-
* Supports both strict JSON and relaxed JSON syntax with configurable error handling
|
|
260
|
-
* and duplicate key validation.
|
|
261
|
-
*
|
|
262
|
-
* @param text - The JSON string to parse
|
|
263
|
-
* @param optsOrReviver - Either a ParseOptions object for configuration, or a reviver function (like JSON.parse)
|
|
264
|
-
*
|
|
265
|
-
* @returns The parsed JavaScript value
|
|
266
|
-
*
|
|
267
|
-
* @throws {SyntaxError} When parsing fails in strict mode, or when warnings are collected in tolerant mode
|
|
268
|
-
*
|
|
269
|
-
* @example
|
|
270
|
-
* ```typescript
|
|
271
|
-
* // Standard JSON parsing
|
|
272
|
-
* parse('{"key": "value"}')
|
|
273
|
-
*
|
|
274
|
-
* // Relaxed JSON with unquoted keys and trailing commas
|
|
275
|
-
* parse('{key: "value", trailing: "comma",}', { relaxed: true })
|
|
276
|
-
*
|
|
277
|
-
* // Strict duplicate key validation
|
|
278
|
-
* parse('{"key": 1, "key": 2}', { duplicate: false }) // throws error
|
|
279
|
-
*
|
|
280
|
-
* // Allow duplicates (uses last value)
|
|
281
|
-
* parse('{"key": 1, "key": 2}', { duplicate: true }) // returns {key: 2}
|
|
282
|
-
*
|
|
283
|
-
* // Tolerant mode with warning collection
|
|
284
|
-
* parse('malformed json', { tolerant: true, warnings: true })
|
|
285
|
-
* ```
|
|
286
|
-
*/
|
|
287
|
-
declare function parse(text: string, optsOrReviver?: ParseOptions | ((key: string, value: unknown) => unknown)): unknown;
|
|
288
|
-
/**
|
|
289
|
-
* Convert JavaScript value to JSON string with sorted object keys
|
|
290
|
-
*
|
|
291
|
-
* Similar to JSON.stringify but with consistent key ordering (sorted alphabetically).
|
|
292
|
-
* Handles undefined values by converting them to null.
|
|
293
|
-
*
|
|
294
|
-
* @param obj - The value to convert to JSON string
|
|
295
|
-
* @returns A JSON string representation
|
|
296
|
-
*
|
|
297
|
-
* @example
|
|
298
|
-
* ```typescript
|
|
299
|
-
* stringify({z: 1, a: 2, m: 3})
|
|
300
|
-
* // Returns: '{"a":2,"m":3,"z":1}' (keys sorted)
|
|
301
|
-
*
|
|
302
|
-
* stringify({key: undefined})
|
|
303
|
-
* // Returns: '{"key":null}' (undefined becomes null)
|
|
304
|
-
* ```
|
|
305
|
-
*/
|
|
306
|
-
declare function stringify(obj: unknown): string;
|
|
307
|
-
|
|
308
146
|
declare function isToolResultPart(content: unknown): content is ToolResultPart;
|
|
309
147
|
declare function hasInputProperty(obj: unknown): obj is {
|
|
310
148
|
input?: unknown;
|
|
@@ -423,4 +261,4 @@ declare function transformParams({ params, protocol, toolSystemPromptTemplate, t
|
|
|
423
261
|
toolChoice: undefined;
|
|
424
262
|
};
|
|
425
263
|
|
|
426
|
-
export { type DebugLevel, type
|
|
264
|
+
export { type DebugLevel, type OnErrorFn, type TCMCoreProtocol, type TCMProtocol, type ToolCallMiddlewareProviderOptions, type XmlProtocolOptions, type YamlProtocolOptions, createDynamicIfThenElseSchema, createToolMiddleware, decodeOriginalTools, encodeOriginalTools, escapeRegExp, extractOnErrorOption, extractToolNamesFromOriginalTools, getDebugLevel, getPotentialStartIndex, hasInputProperty, hermesToolMiddleware, isProtocolFactory, isTCMProtocolFactory, isToolChoiceActive, isToolResultPart, jsonProtocol, logParseFailure, logParsedChunk, logParsedSummary, logRawChunk, originalToolsSchema, toolChoiceStream, transformParams, wrapGenerate, wrapStream, xmlProtocol, xmlToolMiddleware, yamlProtocol, yamlToolMiddleware };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,65 +1,8 @@
|
|
|
1
|
+
export * from '@ai-sdk-tool/rjson';
|
|
1
2
|
import * as _ai_sdk_provider from '@ai-sdk/provider';
|
|
2
3
|
import { LanguageModelV3FunctionTool, LanguageModelV3ToolCall, LanguageModelV3Content, LanguageModelV3StreamPart, LanguageModelV3ProviderTool, JSONSchema7, LanguageModelV3, LanguageModelV3Middleware, LanguageModelV3Prompt, SharedV3ProviderOptions } from '@ai-sdk/provider';
|
|
3
4
|
import { ToolResultPart } from '@ai-sdk/provider-utils';
|
|
4
5
|
|
|
5
|
-
/**
|
|
6
|
-
* Heuristic Engine for XML Tool-Call Parsing
|
|
7
|
-
*
|
|
8
|
-
* Pluggable pipeline for text normalization, repair, and object coercion.
|
|
9
|
-
*
|
|
10
|
-
* Phases:
|
|
11
|
-
* 1. pre-parse: Text normalization before initial parse
|
|
12
|
-
* 2. fallback-reparse: Text repair when initial parse fails
|
|
13
|
-
* 3. post-parse: Object repair/coercion after successful parse
|
|
14
|
-
*/
|
|
15
|
-
type HeuristicPhase = "pre-parse" | "fallback-reparse" | "post-parse";
|
|
16
|
-
interface IntermediateCall {
|
|
17
|
-
toolName: string;
|
|
18
|
-
schema: unknown;
|
|
19
|
-
rawSegment: string;
|
|
20
|
-
parsed: unknown | null;
|
|
21
|
-
errors: unknown[];
|
|
22
|
-
meta?: Record<string, unknown>;
|
|
23
|
-
}
|
|
24
|
-
interface HeuristicResult {
|
|
25
|
-
rawSegment?: string;
|
|
26
|
-
parsed?: unknown;
|
|
27
|
-
reparse?: boolean;
|
|
28
|
-
stop?: boolean;
|
|
29
|
-
warnings?: string[];
|
|
30
|
-
}
|
|
31
|
-
interface ToolCallHeuristic$1 {
|
|
32
|
-
id: string;
|
|
33
|
-
phase: HeuristicPhase;
|
|
34
|
-
applies(ctx: IntermediateCall): boolean;
|
|
35
|
-
run(ctx: IntermediateCall): HeuristicResult;
|
|
36
|
-
}
|
|
37
|
-
interface PipelineConfig$1 {
|
|
38
|
-
preParse?: ToolCallHeuristic$1[];
|
|
39
|
-
fallbackReparse?: ToolCallHeuristic$1[];
|
|
40
|
-
postParse?: ToolCallHeuristic$1[];
|
|
41
|
-
}
|
|
42
|
-
interface HeuristicEngineOptions {
|
|
43
|
-
parse: (xml: string, schema: unknown) => unknown;
|
|
44
|
-
onError?: (message: string, metadata?: Record<string, unknown>) => void;
|
|
45
|
-
maxReparses?: number;
|
|
46
|
-
}
|
|
47
|
-
declare function applyHeuristicPipeline(ctx: IntermediateCall, config: PipelineConfig$1, options: HeuristicEngineOptions): IntermediateCall;
|
|
48
|
-
declare function createIntermediateCall(toolName: string, rawSegment: string, schema: unknown): IntermediateCall;
|
|
49
|
-
declare function mergePipelineConfigs(...configs: PipelineConfig$1[]): PipelineConfig$1;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Default heuristics for XML tool-call parsing.
|
|
53
|
-
* Modular, reusable versions of normalization/repair logic from morph-xml-protocol.
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
declare const normalizeCloseTagsHeuristic: ToolCallHeuristic$1;
|
|
57
|
-
declare const escapeInvalidLtHeuristic: ToolCallHeuristic$1;
|
|
58
|
-
declare const balanceTagsHeuristic: ToolCallHeuristic$1;
|
|
59
|
-
declare const dedupeShellStringTagsHeuristic: ToolCallHeuristic$1;
|
|
60
|
-
declare const repairAgainstSchemaHeuristic: ToolCallHeuristic$1;
|
|
61
|
-
declare const defaultPipelineConfig: PipelineConfig$1;
|
|
62
|
-
|
|
63
6
|
interface TCMProtocol {
|
|
64
7
|
formatTools({ tools, toolSystemPromptTemplate, }: {
|
|
65
8
|
tools: LanguageModelV3FunctionTool[];
|
|
@@ -94,12 +37,14 @@ interface JsonProtocolOptions {
|
|
|
94
37
|
}
|
|
95
38
|
declare const jsonProtocol: ({ toolCallStart, toolCallEnd, }?: JsonProtocolOptions) => TCMProtocol;
|
|
96
39
|
|
|
97
|
-
type PipelineConfig = PipelineConfig$1;
|
|
98
|
-
type ToolCallHeuristic = ToolCallHeuristic$1;
|
|
99
40
|
interface XmlProtocolOptions {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
41
|
+
parseOptions?: {
|
|
42
|
+
repair?: boolean;
|
|
43
|
+
maxReparses?: number;
|
|
44
|
+
onError?: (message: string, metadata?: Record<string, unknown>) => void;
|
|
45
|
+
noChildNodes?: string[];
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
};
|
|
103
48
|
}
|
|
104
49
|
declare const xmlProtocol: (protocolOptions?: XmlProtocolOptions) => TCMCoreProtocol;
|
|
105
50
|
|
|
@@ -198,113 +143,6 @@ declare function isToolChoiceActive(params: {
|
|
|
198
143
|
|
|
199
144
|
declare function escapeRegExp(literal: string): string;
|
|
200
145
|
|
|
201
|
-
/**
|
|
202
|
-
* Options for configuring JSON parsing behavior
|
|
203
|
-
*/
|
|
204
|
-
interface ParseOptions {
|
|
205
|
-
/**
|
|
206
|
-
* Enable relaxed JSON syntax parsing (unquoted keys, single quotes, trailing commas, comments)
|
|
207
|
-
* @default true
|
|
208
|
-
*/
|
|
209
|
-
relaxed?: boolean;
|
|
210
|
-
/**
|
|
211
|
-
* Collect parsing warnings instead of throwing immediately. Implies tolerant mode.
|
|
212
|
-
* At the end of parsing, if warnings exist, throws with warning details.
|
|
213
|
-
* @default false
|
|
214
|
-
*/
|
|
215
|
-
warnings?: boolean;
|
|
216
|
-
/**
|
|
217
|
-
* Continue parsing when encountering recoverable errors, collecting warnings.
|
|
218
|
-
* In strict mode (false), throws immediately on first error.
|
|
219
|
-
* @default false
|
|
220
|
-
*/
|
|
221
|
-
tolerant?: boolean;
|
|
222
|
-
/**
|
|
223
|
-
* Allow duplicate object keys in JSON.
|
|
224
|
-
* - true: Allow duplicates (uses last value, like native JSON.parse)
|
|
225
|
-
* - false: Reject duplicates with error (enforces JSON specification)
|
|
226
|
-
* @default false
|
|
227
|
-
*/
|
|
228
|
-
duplicate?: boolean;
|
|
229
|
-
/**
|
|
230
|
-
* Optional reviver function to transform parsed values (same as JSON.parse reviver)
|
|
231
|
-
* @param key - The object key or array index
|
|
232
|
-
* @param value - The parsed value
|
|
233
|
-
* @returns The transformed value
|
|
234
|
-
*/
|
|
235
|
-
reviver?: (key: string, value: unknown) => unknown;
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Transform relaxed JSON syntax to standard JSON string
|
|
239
|
-
*
|
|
240
|
-
* Converts relaxed JSON features (unquoted keys, single quotes, trailing commas, comments)
|
|
241
|
-
* into valid standard JSON syntax that can be parsed by native JSON.parse().
|
|
242
|
-
*
|
|
243
|
-
* @param text - The relaxed JSON string to transform
|
|
244
|
-
* @returns A standard JSON string
|
|
245
|
-
*
|
|
246
|
-
* @example
|
|
247
|
-
* ```typescript
|
|
248
|
-
* transform('{key: "value", trailing: "comma",}')
|
|
249
|
-
* // Returns: '{"key": "value", "trailing": "comma"}'
|
|
250
|
-
*
|
|
251
|
-
* transform("{'single': 'quotes'}")
|
|
252
|
-
* // Returns: '{"single": "quotes"}'
|
|
253
|
-
* ```
|
|
254
|
-
*/
|
|
255
|
-
declare function transform(text: string): string;
|
|
256
|
-
/**
|
|
257
|
-
* Parse a JSON string with enhanced features beyond standard JSON.parse()
|
|
258
|
-
*
|
|
259
|
-
* Supports both strict JSON and relaxed JSON syntax with configurable error handling
|
|
260
|
-
* and duplicate key validation.
|
|
261
|
-
*
|
|
262
|
-
* @param text - The JSON string to parse
|
|
263
|
-
* @param optsOrReviver - Either a ParseOptions object for configuration, or a reviver function (like JSON.parse)
|
|
264
|
-
*
|
|
265
|
-
* @returns The parsed JavaScript value
|
|
266
|
-
*
|
|
267
|
-
* @throws {SyntaxError} When parsing fails in strict mode, or when warnings are collected in tolerant mode
|
|
268
|
-
*
|
|
269
|
-
* @example
|
|
270
|
-
* ```typescript
|
|
271
|
-
* // Standard JSON parsing
|
|
272
|
-
* parse('{"key": "value"}')
|
|
273
|
-
*
|
|
274
|
-
* // Relaxed JSON with unquoted keys and trailing commas
|
|
275
|
-
* parse('{key: "value", trailing: "comma",}', { relaxed: true })
|
|
276
|
-
*
|
|
277
|
-
* // Strict duplicate key validation
|
|
278
|
-
* parse('{"key": 1, "key": 2}', { duplicate: false }) // throws error
|
|
279
|
-
*
|
|
280
|
-
* // Allow duplicates (uses last value)
|
|
281
|
-
* parse('{"key": 1, "key": 2}', { duplicate: true }) // returns {key: 2}
|
|
282
|
-
*
|
|
283
|
-
* // Tolerant mode with warning collection
|
|
284
|
-
* parse('malformed json', { tolerant: true, warnings: true })
|
|
285
|
-
* ```
|
|
286
|
-
*/
|
|
287
|
-
declare function parse(text: string, optsOrReviver?: ParseOptions | ((key: string, value: unknown) => unknown)): unknown;
|
|
288
|
-
/**
|
|
289
|
-
* Convert JavaScript value to JSON string with sorted object keys
|
|
290
|
-
*
|
|
291
|
-
* Similar to JSON.stringify but with consistent key ordering (sorted alphabetically).
|
|
292
|
-
* Handles undefined values by converting them to null.
|
|
293
|
-
*
|
|
294
|
-
* @param obj - The value to convert to JSON string
|
|
295
|
-
* @returns A JSON string representation
|
|
296
|
-
*
|
|
297
|
-
* @example
|
|
298
|
-
* ```typescript
|
|
299
|
-
* stringify({z: 1, a: 2, m: 3})
|
|
300
|
-
* // Returns: '{"a":2,"m":3,"z":1}' (keys sorted)
|
|
301
|
-
*
|
|
302
|
-
* stringify({key: undefined})
|
|
303
|
-
* // Returns: '{"key":null}' (undefined becomes null)
|
|
304
|
-
* ```
|
|
305
|
-
*/
|
|
306
|
-
declare function stringify(obj: unknown): string;
|
|
307
|
-
|
|
308
146
|
declare function isToolResultPart(content: unknown): content is ToolResultPart;
|
|
309
147
|
declare function hasInputProperty(obj: unknown): obj is {
|
|
310
148
|
input?: unknown;
|
|
@@ -423,4 +261,4 @@ declare function transformParams({ params, protocol, toolSystemPromptTemplate, t
|
|
|
423
261
|
toolChoice: undefined;
|
|
424
262
|
};
|
|
425
263
|
|
|
426
|
-
export { type DebugLevel, type
|
|
264
|
+
export { type DebugLevel, type OnErrorFn, type TCMCoreProtocol, type TCMProtocol, type ToolCallMiddlewareProviderOptions, type XmlProtocolOptions, type YamlProtocolOptions, createDynamicIfThenElseSchema, createToolMiddleware, decodeOriginalTools, encodeOriginalTools, escapeRegExp, extractOnErrorOption, extractToolNamesFromOriginalTools, getDebugLevel, getPotentialStartIndex, hasInputProperty, hermesToolMiddleware, isProtocolFactory, isTCMProtocolFactory, isToolChoiceActive, isToolResultPart, jsonProtocol, logParseFailure, logParsedChunk, logParsedSummary, logRawChunk, originalToolsSchema, toolChoiceStream, transformParams, wrapGenerate, wrapStream, xmlProtocol, xmlToolMiddleware, yamlProtocol, yamlToolMiddleware };
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
applyHeuristicPipeline,
|
|
3
|
-
balanceTagsHeuristic,
|
|
4
2
|
createDynamicIfThenElseSchema,
|
|
5
|
-
createIntermediateCall,
|
|
6
3
|
createToolMiddleware,
|
|
7
4
|
decodeOriginalTools,
|
|
8
|
-
dedupeShellStringTagsHeuristic,
|
|
9
|
-
defaultPipelineConfig,
|
|
10
5
|
encodeOriginalTools,
|
|
11
|
-
escapeInvalidLtHeuristic,
|
|
12
6
|
escapeRegExp,
|
|
13
7
|
extractOnErrorOption,
|
|
14
8
|
extractToolNamesFromOriginalTools,
|
|
@@ -25,14 +19,8 @@ import {
|
|
|
25
19
|
logParsedChunk,
|
|
26
20
|
logParsedSummary,
|
|
27
21
|
logRawChunk,
|
|
28
|
-
mergePipelineConfigs,
|
|
29
|
-
normalizeCloseTagsHeuristic,
|
|
30
22
|
originalToolsSchema,
|
|
31
|
-
parse,
|
|
32
|
-
repairAgainstSchemaHeuristic,
|
|
33
|
-
stringify,
|
|
34
23
|
toolChoiceStream,
|
|
35
|
-
transform,
|
|
36
24
|
transformParams,
|
|
37
25
|
wrapGenerate,
|
|
38
26
|
wrapStream,
|
|
@@ -40,18 +28,12 @@ import {
|
|
|
40
28
|
xmlToolMiddleware,
|
|
41
29
|
yamlProtocol,
|
|
42
30
|
yamlToolMiddleware
|
|
43
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-PIUBQRFC.js";
|
|
44
32
|
export {
|
|
45
|
-
applyHeuristicPipeline,
|
|
46
|
-
balanceTagsHeuristic,
|
|
47
33
|
createDynamicIfThenElseSchema,
|
|
48
|
-
createIntermediateCall,
|
|
49
34
|
createToolMiddleware,
|
|
50
35
|
decodeOriginalTools,
|
|
51
|
-
dedupeShellStringTagsHeuristic,
|
|
52
|
-
defaultPipelineConfig,
|
|
53
36
|
encodeOriginalTools,
|
|
54
|
-
escapeInvalidLtHeuristic,
|
|
55
37
|
escapeRegExp,
|
|
56
38
|
extractOnErrorOption,
|
|
57
39
|
extractToolNamesFromOriginalTools,
|
|
@@ -68,14 +50,8 @@ export {
|
|
|
68
50
|
logParsedChunk,
|
|
69
51
|
logParsedSummary,
|
|
70
52
|
logRawChunk,
|
|
71
|
-
mergePipelineConfigs,
|
|
72
|
-
normalizeCloseTagsHeuristic,
|
|
73
53
|
originalToolsSchema,
|
|
74
|
-
parse,
|
|
75
|
-
repairAgainstSchemaHeuristic,
|
|
76
|
-
stringify,
|
|
77
54
|
toolChoiceStream,
|
|
78
|
-
transform,
|
|
79
55
|
transformParams,
|
|
80
56
|
wrapGenerate,
|
|
81
57
|
wrapStream,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk-tool/parser",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "AI SDK middleware for tool call parsing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -30,18 +30,20 @@
|
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@ai-sdk/provider": "3.0.
|
|
34
|
-
"@ai-sdk/provider-utils": "4.0.
|
|
35
|
-
"yaml": "^2.
|
|
36
|
-
"@ai-sdk-tool/
|
|
33
|
+
"@ai-sdk/provider": "3.0.4",
|
|
34
|
+
"@ai-sdk/provider-utils": "4.0.8",
|
|
35
|
+
"yaml": "^2.8.2",
|
|
36
|
+
"@ai-sdk-tool/schema-coerce": "0.1.0",
|
|
37
|
+
"@ai-sdk-tool/rjson": "0.1.0",
|
|
38
|
+
"@ai-sdk-tool/rxml": "0.2.0"
|
|
37
39
|
},
|
|
38
40
|
"devDependencies": {
|
|
39
|
-
"@ai-sdk/openai-compatible": "2.0.
|
|
40
|
-
"@types/node": "^25.0.
|
|
41
|
-
"ai": "6.0.
|
|
41
|
+
"@ai-sdk/openai-compatible": "2.0.13",
|
|
42
|
+
"@types/node": "^25.0.9",
|
|
43
|
+
"ai": "6.0.38",
|
|
42
44
|
"tsup": "^8.5.1",
|
|
43
45
|
"zod": "^4.3.5",
|
|
44
|
-
"@ai-
|
|
46
|
+
"@ai-sdk-tool/tsconfig": "0.0.1"
|
|
45
47
|
},
|
|
46
48
|
"keywords": [],
|
|
47
49
|
"author": "",
|