@ai-sdk-tool/parser 3.0.0-canary.1 → 3.0.0-canary.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/index.d.cts CHANGED
@@ -121,7 +121,72 @@ interface JsonMixOptions {
121
121
  }
122
122
  declare const jsonMixProtocol: ({ toolCallStart, toolCallEnd, toolResponseStart, toolResponseEnd, }?: JsonMixOptions) => ToolCallProtocol;
123
123
 
124
- declare const morphXmlProtocol: () => ToolCallProtocol;
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;
181
+
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;
125
190
 
126
191
  declare function createToolMiddleware({ protocol, toolSystemPromptTemplate, placement, }: {
127
192
  protocol: ToolCallProtocol | (() => ToolCallProtocol);
@@ -332,4 +397,4 @@ declare const gemmaToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
332
397
  declare const hermesToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
333
398
  declare const morphXmlToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
334
399
 
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 };
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
@@ -121,7 +121,72 @@ interface JsonMixOptions {
121
121
  }
122
122
  declare const jsonMixProtocol: ({ toolCallStart, toolCallEnd, toolResponseStart, toolResponseEnd, }?: JsonMixOptions) => ToolCallProtocol;
123
123
 
124
- declare const morphXmlProtocol: () => ToolCallProtocol;
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;
181
+
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;
125
190
 
126
191
  declare function createToolMiddleware({ protocol, toolSystemPromptTemplate, placement, }: {
127
192
  protocol: ToolCallProtocol | (() => ToolCallProtocol);
@@ -332,4 +397,4 @@ declare const gemmaToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
332
397
  declare const hermesToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
333
398
  declare const morphXmlToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
334
399
 
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 };
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,
@@ -19,18 +25,27 @@ import {
19
25
  logParsedChunk,
20
26
  logParsedSummary,
21
27
  logRawChunk,
28
+ mergePipelineConfigs,
22
29
  morphXmlProtocol,
23
30
  morphXmlToolMiddleware,
31
+ normalizeCloseTagsHeuristic,
24
32
  originalToolsSchema,
25
33
  parse,
34
+ repairAgainstSchemaHeuristic,
26
35
  stringify,
27
36
  transform
28
- } from "./chunk-L4X363EL.js";
37
+ } from "./chunk-2B2YNKXY.js";
29
38
  export {
39
+ applyHeuristicPipeline,
40
+ balanceTagsHeuristic,
30
41
  createDynamicIfThenElseSchema,
42
+ createIntermediateCall,
31
43
  createToolMiddleware,
32
44
  decodeOriginalTools,
45
+ dedupeShellStringTagsHeuristic,
46
+ defaultPipelineConfig,
33
47
  encodeOriginalTools,
48
+ escapeInvalidLtHeuristic,
34
49
  escapeRegExp,
35
50
  extractOnErrorOption,
36
51
  extractToolNamesFromOriginalTools,
@@ -47,10 +62,13 @@ export {
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk-tool/parser",
3
- "version": "3.0.0-canary.1",
3
+ "version": "3.0.0-canary.3",
4
4
  "description": "AI SDK middleware for tool call parsing",
5
5
  "type": "module",
6
6
  "repository": {
@@ -31,16 +31,16 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@ai-sdk/provider": "3.0.0",
34
- "@ai-sdk/provider-utils": "4.0.0",
35
- "@ai-sdk-tool/rxml": "0.1.1"
34
+ "@ai-sdk/provider-utils": "4.0.1",
35
+ "@ai-sdk-tool/rxml": "0.1.2-canary.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@ai-sdk/openai-compatible": "2.0.0",
38
+ "@ai-sdk/openai-compatible": "2.0.1",
39
39
  "@types/node": "^25.0.3",
40
- "ai": "6.0.1",
40
+ "ai": "6.0.3",
41
41
  "tsup": "^8.5.1",
42
42
  "zod": "^4.2.1",
43
- "@ai-sdkx/tsconfig": "0.0.0"
43
+ "@ai-sdkx/tsconfig": "0.0.1-canary.0"
44
44
  },
45
45
  "keywords": [],
46
46
  "author": "",