@ai-sdk-tool/parser 3.1.3 → 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/index.d.cts CHANGED
@@ -3,64 +3,6 @@ import * as _ai_sdk_provider from '@ai-sdk/provider';
3
3
  import { LanguageModelV3FunctionTool, LanguageModelV3ToolCall, LanguageModelV3Content, LanguageModelV3StreamPart, LanguageModelV3ProviderTool, JSONSchema7, LanguageModelV3, LanguageModelV3Middleware, LanguageModelV3Prompt, SharedV3ProviderOptions } from '@ai-sdk/provider';
4
4
  import { ToolResultPart } from '@ai-sdk/provider-utils';
5
5
 
6
- /**
7
- * Heuristic Engine for XML Tool-Call Parsing
8
- *
9
- * Pluggable pipeline for text normalization, repair, and object coercion.
10
- *
11
- * Phases:
12
- * 1. pre-parse: Text normalization before initial parse
13
- * 2. fallback-reparse: Text repair when initial parse fails
14
- * 3. post-parse: Object repair/coercion after successful parse
15
- */
16
- type HeuristicPhase = "pre-parse" | "fallback-reparse" | "post-parse";
17
- interface IntermediateCall {
18
- toolName: string;
19
- schema: unknown;
20
- rawSegment: string;
21
- parsed: unknown | null;
22
- errors: unknown[];
23
- meta?: Record<string, unknown>;
24
- }
25
- interface HeuristicResult {
26
- rawSegment?: string;
27
- parsed?: unknown;
28
- reparse?: boolean;
29
- stop?: boolean;
30
- warnings?: string[];
31
- }
32
- interface ToolCallHeuristic$1 {
33
- id: string;
34
- phase: HeuristicPhase;
35
- applies(ctx: IntermediateCall): boolean;
36
- run(ctx: IntermediateCall): HeuristicResult;
37
- }
38
- interface PipelineConfig$1 {
39
- preParse?: ToolCallHeuristic$1[];
40
- fallbackReparse?: ToolCallHeuristic$1[];
41
- postParse?: ToolCallHeuristic$1[];
42
- }
43
- interface HeuristicEngineOptions {
44
- parse: (xml: string, schema: unknown) => unknown;
45
- onError?: (message: string, metadata?: Record<string, unknown>) => void;
46
- maxReparses?: number;
47
- }
48
- declare function applyHeuristicPipeline(ctx: IntermediateCall, config: PipelineConfig$1, options: HeuristicEngineOptions): IntermediateCall;
49
- declare function createIntermediateCall(toolName: string, rawSegment: string, schema: unknown): IntermediateCall;
50
- declare function mergePipelineConfigs(...configs: PipelineConfig$1[]): PipelineConfig$1;
51
-
52
- /**
53
- * Default heuristics for XML tool-call parsing.
54
- * Modular, reusable versions of normalization/repair logic from morph-xml-protocol.
55
- */
56
-
57
- declare const normalizeCloseTagsHeuristic: ToolCallHeuristic$1;
58
- declare const escapeInvalidLtHeuristic: ToolCallHeuristic$1;
59
- declare const balanceTagsHeuristic: ToolCallHeuristic$1;
60
- declare const dedupeShellStringTagsHeuristic: ToolCallHeuristic$1;
61
- declare const repairAgainstSchemaHeuristic: ToolCallHeuristic$1;
62
- declare const defaultPipelineConfig: PipelineConfig$1;
63
-
64
6
  interface TCMProtocol {
65
7
  formatTools({ tools, toolSystemPromptTemplate, }: {
66
8
  tools: LanguageModelV3FunctionTool[];
@@ -95,12 +37,14 @@ interface JsonProtocolOptions {
95
37
  }
96
38
  declare const jsonProtocol: ({ toolCallStart, toolCallEnd, }?: JsonProtocolOptions) => TCMProtocol;
97
39
 
98
- type PipelineConfig = PipelineConfig$1;
99
- type ToolCallHeuristic = ToolCallHeuristic$1;
100
40
  interface XmlProtocolOptions {
101
- heuristics?: ToolCallHeuristic[];
102
- pipeline?: PipelineConfig;
103
- maxReparses?: number;
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
+ };
104
48
  }
105
49
  declare const xmlProtocol: (protocolOptions?: XmlProtocolOptions) => TCMCoreProtocol;
106
50
 
@@ -317,4 +261,4 @@ declare function transformParams({ params, protocol, toolSystemPromptTemplate, t
317
261
  toolChoice: undefined;
318
262
  };
319
263
 
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 };
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
@@ -3,64 +3,6 @@ import * as _ai_sdk_provider from '@ai-sdk/provider';
3
3
  import { LanguageModelV3FunctionTool, LanguageModelV3ToolCall, LanguageModelV3Content, LanguageModelV3StreamPart, LanguageModelV3ProviderTool, JSONSchema7, LanguageModelV3, LanguageModelV3Middleware, LanguageModelV3Prompt, SharedV3ProviderOptions } from '@ai-sdk/provider';
4
4
  import { ToolResultPart } from '@ai-sdk/provider-utils';
5
5
 
6
- /**
7
- * Heuristic Engine for XML Tool-Call Parsing
8
- *
9
- * Pluggable pipeline for text normalization, repair, and object coercion.
10
- *
11
- * Phases:
12
- * 1. pre-parse: Text normalization before initial parse
13
- * 2. fallback-reparse: Text repair when initial parse fails
14
- * 3. post-parse: Object repair/coercion after successful parse
15
- */
16
- type HeuristicPhase = "pre-parse" | "fallback-reparse" | "post-parse";
17
- interface IntermediateCall {
18
- toolName: string;
19
- schema: unknown;
20
- rawSegment: string;
21
- parsed: unknown | null;
22
- errors: unknown[];
23
- meta?: Record<string, unknown>;
24
- }
25
- interface HeuristicResult {
26
- rawSegment?: string;
27
- parsed?: unknown;
28
- reparse?: boolean;
29
- stop?: boolean;
30
- warnings?: string[];
31
- }
32
- interface ToolCallHeuristic$1 {
33
- id: string;
34
- phase: HeuristicPhase;
35
- applies(ctx: IntermediateCall): boolean;
36
- run(ctx: IntermediateCall): HeuristicResult;
37
- }
38
- interface PipelineConfig$1 {
39
- preParse?: ToolCallHeuristic$1[];
40
- fallbackReparse?: ToolCallHeuristic$1[];
41
- postParse?: ToolCallHeuristic$1[];
42
- }
43
- interface HeuristicEngineOptions {
44
- parse: (xml: string, schema: unknown) => unknown;
45
- onError?: (message: string, metadata?: Record<string, unknown>) => void;
46
- maxReparses?: number;
47
- }
48
- declare function applyHeuristicPipeline(ctx: IntermediateCall, config: PipelineConfig$1, options: HeuristicEngineOptions): IntermediateCall;
49
- declare function createIntermediateCall(toolName: string, rawSegment: string, schema: unknown): IntermediateCall;
50
- declare function mergePipelineConfigs(...configs: PipelineConfig$1[]): PipelineConfig$1;
51
-
52
- /**
53
- * Default heuristics for XML tool-call parsing.
54
- * Modular, reusable versions of normalization/repair logic from morph-xml-protocol.
55
- */
56
-
57
- declare const normalizeCloseTagsHeuristic: ToolCallHeuristic$1;
58
- declare const escapeInvalidLtHeuristic: ToolCallHeuristic$1;
59
- declare const balanceTagsHeuristic: ToolCallHeuristic$1;
60
- declare const dedupeShellStringTagsHeuristic: ToolCallHeuristic$1;
61
- declare const repairAgainstSchemaHeuristic: ToolCallHeuristic$1;
62
- declare const defaultPipelineConfig: PipelineConfig$1;
63
-
64
6
  interface TCMProtocol {
65
7
  formatTools({ tools, toolSystemPromptTemplate, }: {
66
8
  tools: LanguageModelV3FunctionTool[];
@@ -95,12 +37,14 @@ interface JsonProtocolOptions {
95
37
  }
96
38
  declare const jsonProtocol: ({ toolCallStart, toolCallEnd, }?: JsonProtocolOptions) => TCMProtocol;
97
39
 
98
- type PipelineConfig = PipelineConfig$1;
99
- type ToolCallHeuristic = ToolCallHeuristic$1;
100
40
  interface XmlProtocolOptions {
101
- heuristics?: ToolCallHeuristic[];
102
- pipeline?: PipelineConfig;
103
- maxReparses?: number;
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
+ };
104
48
  }
105
49
  declare const xmlProtocol: (protocolOptions?: XmlProtocolOptions) => TCMCoreProtocol;
106
50
 
@@ -317,4 +261,4 @@ declare function transformParams({ params, protocol, toolSystemPromptTemplate, t
317
261
  toolChoice: undefined;
318
262
  };
319
263
 
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 };
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,10 +19,7 @@ import {
25
19
  logParsedChunk,
26
20
  logParsedSummary,
27
21
  logRawChunk,
28
- mergePipelineConfigs,
29
- normalizeCloseTagsHeuristic,
30
22
  originalToolsSchema,
31
- repairAgainstSchemaHeuristic,
32
23
  toolChoiceStream,
33
24
  transformParams,
34
25
  wrapGenerate,
@@ -37,18 +28,12 @@ import {
37
28
  xmlToolMiddleware,
38
29
  yamlProtocol,
39
30
  yamlToolMiddleware
40
- } from "./chunk-3KQVEBKO.js";
31
+ } from "./chunk-PIUBQRFC.js";
41
32
  export {
42
- applyHeuristicPipeline,
43
- balanceTagsHeuristic,
44
33
  createDynamicIfThenElseSchema,
45
- createIntermediateCall,
46
34
  createToolMiddleware,
47
35
  decodeOriginalTools,
48
- dedupeShellStringTagsHeuristic,
49
- defaultPipelineConfig,
50
36
  encodeOriginalTools,
51
- escapeInvalidLtHeuristic,
52
37
  escapeRegExp,
53
38
  extractOnErrorOption,
54
39
  extractToolNamesFromOriginalTools,
@@ -65,10 +50,7 @@ export {
65
50
  logParsedChunk,
66
51
  logParsedSummary,
67
52
  logRawChunk,
68
- mergePipelineConfigs,
69
- normalizeCloseTagsHeuristic,
70
53
  originalToolsSchema,
71
- repairAgainstSchemaHeuristic,
72
54
  toolChoiceStream,
73
55
  transformParams,
74
56
  wrapGenerate,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk-tool/parser",
3
- "version": "3.1.3",
3
+ "version": "3.2.0",
4
4
  "description": "AI SDK middleware for tool call parsing",
5
5
  "type": "module",
6
6
  "repository": {
@@ -33,8 +33,9 @@
33
33
  "@ai-sdk/provider": "3.0.4",
34
34
  "@ai-sdk/provider-utils": "4.0.8",
35
35
  "yaml": "^2.8.2",
36
- "@ai-sdk-tool/rxml": "0.1.2",
37
- "@ai-sdk-tool/rjson": "0.1.0"
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"
38
39
  },
39
40
  "devDependencies": {
40
41
  "@ai-sdk/openai-compatible": "2.0.13",