@ai-sdk-tool/parser 3.1.2 → 3.1.3
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-3KQVEBKO.js} +26 -688
- package/dist/chunk-3KQVEBKO.js.map +1 -0
- package/dist/community.cjs +101 -649
- package/dist/community.cjs.map +1 -1
- package/dist/community.js +1 -1
- package/dist/index.cjs +19 -684
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -108
- package/dist/index.d.ts +2 -108
- package/dist/index.js +1 -7
- package/package.json +10 -9
- package/dist/chunk-TQT6XSP7.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
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';
|
|
@@ -198,113 +199,6 @@ declare function isToolChoiceActive(params: {
|
|
|
198
199
|
|
|
199
200
|
declare function escapeRegExp(literal: string): string;
|
|
200
201
|
|
|
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
202
|
declare function isToolResultPart(content: unknown): content is ToolResultPart;
|
|
309
203
|
declare function hasInputProperty(obj: unknown): obj is {
|
|
310
204
|
input?: unknown;
|
|
@@ -423,4 +317,4 @@ declare function transformParams({ params, protocol, toolSystemPromptTemplate, t
|
|
|
423
317
|
toolChoice: undefined;
|
|
424
318
|
};
|
|
425
319
|
|
|
426
|
-
export { type DebugLevel, type HeuristicEngineOptions, type HeuristicPhase, type HeuristicResult, type IntermediateCall, type OnErrorFn, type
|
|
320
|
+
export { type DebugLevel, type HeuristicEngineOptions, type HeuristicPhase, type HeuristicResult, type IntermediateCall, type OnErrorFn, type PipelineConfig$1 as PipelineConfig, type TCMCoreProtocol, type TCMProtocol, type ToolCallHeuristic$1 as ToolCallHeuristic, type ToolCallMiddlewareProviderOptions, type XmlProtocolOptions, type YamlProtocolOptions, applyHeuristicPipeline, balanceTagsHeuristic, createDynamicIfThenElseSchema, createIntermediateCall, createToolMiddleware, decodeOriginalTools, dedupeShellStringTagsHeuristic, defaultPipelineConfig, encodeOriginalTools, escapeInvalidLtHeuristic, escapeRegExp, extractOnErrorOption, extractToolNamesFromOriginalTools, getDebugLevel, getPotentialStartIndex, hasInputProperty, hermesToolMiddleware, isProtocolFactory, isTCMProtocolFactory, isToolChoiceActive, isToolResultPart, jsonProtocol, logParseFailure, logParsedChunk, logParsedSummary, logRawChunk, mergePipelineConfigs, normalizeCloseTagsHeuristic, originalToolsSchema, repairAgainstSchemaHeuristic, toolChoiceStream, transformParams, wrapGenerate, wrapStream, xmlProtocol, xmlToolMiddleware, yamlProtocol, yamlToolMiddleware };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
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';
|
|
@@ -198,113 +199,6 @@ declare function isToolChoiceActive(params: {
|
|
|
198
199
|
|
|
199
200
|
declare function escapeRegExp(literal: string): string;
|
|
200
201
|
|
|
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
202
|
declare function isToolResultPart(content: unknown): content is ToolResultPart;
|
|
309
203
|
declare function hasInputProperty(obj: unknown): obj is {
|
|
310
204
|
input?: unknown;
|
|
@@ -423,4 +317,4 @@ declare function transformParams({ params, protocol, toolSystemPromptTemplate, t
|
|
|
423
317
|
toolChoice: undefined;
|
|
424
318
|
};
|
|
425
319
|
|
|
426
|
-
export { type DebugLevel, type HeuristicEngineOptions, type HeuristicPhase, type HeuristicResult, type IntermediateCall, type OnErrorFn, type
|
|
320
|
+
export { type DebugLevel, type HeuristicEngineOptions, type HeuristicPhase, type HeuristicResult, type IntermediateCall, type OnErrorFn, type PipelineConfig$1 as PipelineConfig, type TCMCoreProtocol, type TCMProtocol, type ToolCallHeuristic$1 as ToolCallHeuristic, type ToolCallMiddlewareProviderOptions, type XmlProtocolOptions, type YamlProtocolOptions, applyHeuristicPipeline, balanceTagsHeuristic, createDynamicIfThenElseSchema, createIntermediateCall, createToolMiddleware, decodeOriginalTools, dedupeShellStringTagsHeuristic, defaultPipelineConfig, encodeOriginalTools, escapeInvalidLtHeuristic, escapeRegExp, extractOnErrorOption, extractToolNamesFromOriginalTools, getDebugLevel, getPotentialStartIndex, hasInputProperty, hermesToolMiddleware, isProtocolFactory, isTCMProtocolFactory, isToolChoiceActive, isToolResultPart, jsonProtocol, logParseFailure, logParsedChunk, logParsedSummary, logRawChunk, mergePipelineConfigs, normalizeCloseTagsHeuristic, originalToolsSchema, repairAgainstSchemaHeuristic, toolChoiceStream, transformParams, wrapGenerate, wrapStream, xmlProtocol, xmlToolMiddleware, yamlProtocol, yamlToolMiddleware };
|
package/dist/index.js
CHANGED
|
@@ -28,11 +28,8 @@ import {
|
|
|
28
28
|
mergePipelineConfigs,
|
|
29
29
|
normalizeCloseTagsHeuristic,
|
|
30
30
|
originalToolsSchema,
|
|
31
|
-
parse,
|
|
32
31
|
repairAgainstSchemaHeuristic,
|
|
33
|
-
stringify,
|
|
34
32
|
toolChoiceStream,
|
|
35
|
-
transform,
|
|
36
33
|
transformParams,
|
|
37
34
|
wrapGenerate,
|
|
38
35
|
wrapStream,
|
|
@@ -40,7 +37,7 @@ import {
|
|
|
40
37
|
xmlToolMiddleware,
|
|
41
38
|
yamlProtocol,
|
|
42
39
|
yamlToolMiddleware
|
|
43
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-3KQVEBKO.js";
|
|
44
41
|
export {
|
|
45
42
|
applyHeuristicPipeline,
|
|
46
43
|
balanceTagsHeuristic,
|
|
@@ -71,11 +68,8 @@ export {
|
|
|
71
68
|
mergePipelineConfigs,
|
|
72
69
|
normalizeCloseTagsHeuristic,
|
|
73
70
|
originalToolsSchema,
|
|
74
|
-
parse,
|
|
75
71
|
repairAgainstSchemaHeuristic,
|
|
76
|
-
stringify,
|
|
77
72
|
toolChoiceStream,
|
|
78
|
-
transform,
|
|
79
73
|
transformParams,
|
|
80
74
|
wrapGenerate,
|
|
81
75
|
wrapStream,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk-tool/parser",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.3",
|
|
4
4
|
"description": "AI SDK middleware for tool call parsing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -30,18 +30,19 @@
|
|
|
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/rxml": "0.1.2"
|
|
33
|
+
"@ai-sdk/provider": "3.0.4",
|
|
34
|
+
"@ai-sdk/provider-utils": "4.0.8",
|
|
35
|
+
"yaml": "^2.8.2",
|
|
36
|
+
"@ai-sdk-tool/rxml": "0.1.2",
|
|
37
|
+
"@ai-sdk-tool/rjson": "0.1.0"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
|
-
"@ai-sdk/openai-compatible": "2.0.
|
|
40
|
-
"@types/node": "^25.0.
|
|
41
|
-
"ai": "6.0.
|
|
40
|
+
"@ai-sdk/openai-compatible": "2.0.13",
|
|
41
|
+
"@types/node": "^25.0.9",
|
|
42
|
+
"ai": "6.0.38",
|
|
42
43
|
"tsup": "^8.5.1",
|
|
43
44
|
"zod": "^4.3.5",
|
|
44
|
-
"@ai-
|
|
45
|
+
"@ai-sdk-tool/tsconfig": "0.0.1"
|
|
45
46
|
},
|
|
46
47
|
"keywords": [],
|
|
47
48
|
"author": "",
|