@ai-sdk-tool/parser 3.0.0-canary.3 → 3.1.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
@@ -1,125 +1,6 @@
1
1
  import * as _ai_sdk_provider from '@ai-sdk/provider';
2
- import { LanguageModelV3FunctionTool, LanguageModelV3ToolCall, LanguageModelV3ToolResultPart, LanguageModelV3Content, LanguageModelV3StreamPart, LanguageModelV3Middleware, LanguageModelV3ProviderTool, JSONSchema7 } from '@ai-sdk/provider';
3
-
4
- /**
5
- * ToolCallProtocol
6
- *
7
- * A pluggable strategy that defines how tools are surfaced to a model, how
8
- * tool calls are rendered into provider-facing text, and how model output is
9
- * parsed back into the AI SDK v2 content/stream primitives.
10
- *
11
- * Implementations can choose any wire format (e.g. XML, JSON-with-tags, etc.)
12
- * as long as they respect the contract below:
13
- * - Static formatting helpers (`formatTools`, `formatToolCall`, `formatToolResponse`)
14
- * are used to construct strings that the model will read.
15
- * - Parsing helpers (`parseGeneratedText`, `createStreamParser`) must convert
16
- * model output back into structured `LanguageModelV3Content` parts, emitting
17
- * `text` for regular content and `tool-call` for detected tool invocations.
18
- */
19
- interface ToolCallProtocol {
20
- /**
21
- * Produces a provider-facing string that describes all available tools.
22
- *
23
- * Typical usage is to serialize each tool's `name`, `description`, and
24
- * JSON schema and inject that text into a system prompt using the supplied
25
- * `toolSystemPromptTemplate`.
26
- *
27
- * Implementations should be resilient to empty inputs.
28
- *
29
- * @param tools List of tools that can be invoked by the model.
30
- * @param toolSystemPromptTemplate Function that receives the serialized
31
- * tools and returns the final prompt text.
32
- * @returns A string to be embedded into the model's system prompt.
33
- */
34
- formatTools({ tools, toolSystemPromptTemplate, }: {
35
- tools: LanguageModelV3FunctionTool[];
36
- toolSystemPromptTemplate: (tools: string) => string;
37
- }): string;
38
- /**
39
- * Renders a single tool invocation into provider-facing text.
40
- *
41
- * Implementations may accept `toolCall.input` as a JSON string or as an
42
- * object (some runtimes normalize prior to calling). The result should be a
43
- * string that the model can understand and that the paired parser can later
44
- * recognize and recover as a `tool-call`.
45
- *
46
- * @param toolCall The tool call to format for the model.
47
- * @returns A textual representation of the tool call (e.g., an XML element).
48
- */
49
- formatToolCall(toolCall: LanguageModelV3ToolCall): string;
50
- /**
51
- * Formats a tool result payload so the model can consume it as plain text.
52
- *
53
- * This is commonly used to echo tool outputs back to the model in a format
54
- * symmetrical to `formatToolCall`.
55
- *
56
- * @param toolResult The result part produced after executing a tool.
57
- * @returns Textual representation of the tool result for the model.
58
- */
59
- formatToolResponse(toolResult: LanguageModelV3ToolResultPart): string;
60
- /**
61
- * Parses a fully generated text (non-streaming) response from the model and
62
- * converts it into a sequence of `LanguageModelV3Content` parts.
63
- *
64
- * Implementations should:
65
- * - Detect tool-call segments addressed to known `tools` and emit
66
- * `{ type: "tool-call", toolName, input }` parts.
67
- * - Emit `{ type: "text", text }` parts for any non-tool segments.
68
- * - Call `options.onError` and fall back to emitting the original text if a
69
- * segment cannot be parsed into a valid tool call.
70
- *
71
- * @param text The model output to parse.
72
- * @param tools The list of tools that may be invoked.
73
- * @param options Optional error callback for non-fatal parsing issues.
74
- * @returns A list of structured content parts derived from the text.
75
- */
76
- parseGeneratedText({ text, tools, options, }: {
77
- text: string;
78
- tools: LanguageModelV3FunctionTool[];
79
- options?: {
80
- onError?: (message: string, metadata?: Record<string, unknown>) => void;
81
- };
82
- }): LanguageModelV3Content[];
83
- /**
84
- * Creates a TransformStream that converts streaming model deltas
85
- * (`LanguageModelV3StreamPart`) into a normalized sequence of stream parts,
86
- * including `text-start`/`text-delta`/`text-end` and `tool-call` events.
87
- *
88
- * The stream parser should:
89
- * - Buffer text until a complete tool-call segment can be recognized, then
90
- * emit a `tool-call` part and properly close/open text segments around it.
91
- * - Be robust to partial/incomplete fragments commonly seen in streaming.
92
- * - Invoke `options.onError` and pass through the original text when a
93
- * segment cannot be parsed into a valid tool call.
94
- *
95
- * @param tools The list of tools that may be invoked by the model.
96
- * @param options Optional error callback for non-fatal streaming issues.
97
- * @returns A TransformStream that accepts and emits `LanguageModelV3StreamPart`s.
98
- */
99
- createStreamParser({ tools, options, }: {
100
- tools: LanguageModelV3FunctionTool[];
101
- options?: {
102
- onError?: (message: string, metadata?: Record<string, unknown>) => void;
103
- };
104
- }): TransformStream<LanguageModelV3StreamPart, LanguageModelV3StreamPart>;
105
- /**
106
- * Optionally returns the exact substrings that would be parsed as tool-calls
107
- * from the provided text for this protocol.
108
- * Used for debug logging in parse mode.
109
- */
110
- extractToolCallSegments?: ({ text, tools, }: {
111
- text: string;
112
- tools: LanguageModelV3FunctionTool[];
113
- }) => string[];
114
- }
115
-
116
- interface JsonMixOptions {
117
- toolCallStart?: string;
118
- toolCallEnd?: string;
119
- toolResponseStart?: string;
120
- toolResponseEnd?: string;
121
- }
122
- declare const jsonMixProtocol: ({ toolCallStart, toolCallEnd, toolResponseStart, toolResponseEnd, }?: JsonMixOptions) => ToolCallProtocol;
2
+ import { LanguageModelV3FunctionTool, LanguageModelV3ToolCall, LanguageModelV3Content, LanguageModelV3StreamPart, LanguageModelV3ProviderTool, JSONSchema7, LanguageModelV3, LanguageModelV3Middleware, LanguageModelV3Prompt, SharedV3ProviderOptions } from '@ai-sdk/provider';
3
+ import { ToolResultPart } from '@ai-sdk/provider-utils';
123
4
 
124
5
  /**
125
6
  * Heuristic Engine for XML Tool-Call Parsing
@@ -179,20 +60,57 @@ declare const dedupeShellStringTagsHeuristic: ToolCallHeuristic$1;
179
60
  declare const repairAgainstSchemaHeuristic: ToolCallHeuristic$1;
180
61
  declare const defaultPipelineConfig: PipelineConfig$1;
181
62
 
63
+ interface TCMProtocol {
64
+ formatTools({ tools, toolSystemPromptTemplate, }: {
65
+ tools: LanguageModelV3FunctionTool[];
66
+ toolSystemPromptTemplate: (tools: LanguageModelV3FunctionTool[]) => string;
67
+ }): string;
68
+ formatToolCall(toolCall: LanguageModelV3ToolCall): string;
69
+ parseGeneratedText({ text, tools, options, }: {
70
+ text: string;
71
+ tools: LanguageModelV3FunctionTool[];
72
+ options?: {
73
+ onError?: (message: string, metadata?: Record<string, unknown>) => void;
74
+ };
75
+ }): LanguageModelV3Content[];
76
+ createStreamParser({ tools, options, }: {
77
+ tools: LanguageModelV3FunctionTool[];
78
+ options?: {
79
+ onError?: (message: string, metadata?: Record<string, unknown>) => void;
80
+ };
81
+ }): TransformStream<LanguageModelV3StreamPart, LanguageModelV3StreamPart>;
82
+ extractToolCallSegments?: ({ text, tools, }: {
83
+ text: string;
84
+ tools: LanguageModelV3FunctionTool[];
85
+ }) => string[];
86
+ }
87
+ type TCMCoreProtocol = TCMProtocol;
88
+ declare function isProtocolFactory(protocol: TCMProtocol | (() => TCMProtocol)): protocol is () => TCMProtocol;
89
+ declare function isTCMProtocolFactory(protocol: TCMProtocol | (() => TCMProtocol)): protocol is () => TCMProtocol;
90
+
91
+ interface JsonProtocolOptions {
92
+ toolCallStart?: string;
93
+ toolCallEnd?: string;
94
+ }
95
+ declare const jsonProtocol: ({ toolCallStart, toolCallEnd, }?: JsonProtocolOptions) => TCMProtocol;
96
+
182
97
  type PipelineConfig = PipelineConfig$1;
183
98
  type ToolCallHeuristic = ToolCallHeuristic$1;
184
- interface MorphXmlProtocolOptions {
99
+ interface XmlProtocolOptions {
185
100
  heuristics?: ToolCallHeuristic[];
186
101
  pipeline?: PipelineConfig;
187
102
  maxReparses?: number;
188
103
  }
189
- declare const morphXmlProtocol: (protocolOptions?: MorphXmlProtocolOptions) => ToolCallProtocol;
104
+ declare const xmlProtocol: (protocolOptions?: XmlProtocolOptions) => TCMCoreProtocol;
190
105
 
191
- declare function createToolMiddleware({ protocol, toolSystemPromptTemplate, placement, }: {
192
- protocol: ToolCallProtocol | (() => ToolCallProtocol);
193
- toolSystemPromptTemplate: (tools: string) => string;
194
- placement?: "first" | "last";
195
- }): LanguageModelV3Middleware;
106
+ interface YamlProtocolOptions {
107
+ /**
108
+ * Whether to include a system prompt example showing YAML multiline syntax.
109
+ * @default true
110
+ */
111
+ includeMultilineExample?: boolean;
112
+ }
113
+ declare const yamlProtocol: (_protocolOptions?: YamlProtocolOptions) => TCMCoreProtocol;
196
114
 
197
115
  type DebugLevel = "off" | "stream" | "parse";
198
116
  declare function getDebugLevel(): DebugLevel;
@@ -388,13 +306,122 @@ declare function parse(text: string, optsOrReviver?: ParseOptions | ((key: strin
388
306
  declare function stringify(obj: unknown): string;
389
307
 
390
308
  declare function isToolCallContent(content: unknown): content is LanguageModelV3ToolCall;
391
- declare function isToolResultPart(content: unknown): content is LanguageModelV3ToolResultPart;
309
+ declare function isToolResultPart(content: unknown): content is ToolResultPart;
392
310
  declare function hasInputProperty(obj: unknown): obj is {
393
311
  input?: unknown;
394
312
  };
395
313
 
396
- declare const gemmaToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
314
+ declare function wrapGenerate({ protocol, doGenerate, params, }: {
315
+ protocol: TCMCoreProtocol;
316
+ doGenerate: () => ReturnType<LanguageModelV3["doGenerate"]>;
317
+ params: {
318
+ providerOptions?: ToolCallMiddlewareProviderOptions;
319
+ };
320
+ }): Promise<_ai_sdk_provider.LanguageModelV3GenerateResult>;
321
+
397
322
  declare const hermesToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
398
- declare const morphXmlToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
323
+ declare const xmlToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
324
+ declare const yamlToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
325
+
326
+ declare function wrapStream({ protocol, doStream, doGenerate, params, }: {
327
+ protocol: TCMCoreProtocol;
328
+ doStream: () => ReturnType<LanguageModelV3["doStream"]>;
329
+ doGenerate: () => ReturnType<LanguageModelV3["doGenerate"]>;
330
+ params: {
331
+ providerOptions?: ToolCallMiddlewareProviderOptions;
332
+ };
333
+ }): Promise<{
334
+ stream: ReadableStream<LanguageModelV3StreamPart>;
335
+ request?: {
336
+ body?: unknown;
337
+ };
338
+ response?: {
339
+ headers?: _ai_sdk_provider.SharedV3Headers;
340
+ };
341
+ }>;
342
+ declare function toolChoiceStream({ doGenerate, options, }: {
343
+ doGenerate: () => ReturnType<LanguageModelV3["doGenerate"]>;
344
+ options?: {
345
+ onError?: (message: string, metadata?: Record<string, unknown>) => void;
346
+ };
347
+ }): Promise<{
348
+ request: {
349
+ body?: unknown;
350
+ };
351
+ response: _ai_sdk_provider.LanguageModelV3ResponseMetadata & {
352
+ headers?: _ai_sdk_provider.SharedV3Headers;
353
+ body?: unknown;
354
+ };
355
+ stream: ReadableStream<LanguageModelV3StreamPart>;
356
+ }>;
357
+
358
+ declare function createToolMiddleware({ protocol, toolSystemPromptTemplate, toolResponsePromptTemplate, placement, }: {
359
+ protocol: TCMCoreProtocol | (() => TCMCoreProtocol);
360
+ toolSystemPromptTemplate: (tools: LanguageModelV3FunctionTool[]) => string;
361
+ toolResponsePromptTemplate?: (toolResult: ToolResultPart) => string;
362
+ placement?: "first" | "last";
363
+ }): LanguageModelV3Middleware;
364
+
365
+ declare function transformParams({ params, protocol, toolSystemPromptTemplate, toolResponsePromptTemplate, placement, }: {
366
+ params: {
367
+ prompt?: LanguageModelV3Prompt;
368
+ tools?: Array<LanguageModelV3FunctionTool | {
369
+ type: string;
370
+ }>;
371
+ providerOptions?: {
372
+ toolCallMiddleware?: {
373
+ toolChoice?: {
374
+ type: string;
375
+ };
376
+ };
377
+ };
378
+ toolChoice?: {
379
+ type: string;
380
+ toolName?: string;
381
+ };
382
+ };
383
+ protocol: TCMCoreProtocol | (() => TCMCoreProtocol);
384
+ toolSystemPromptTemplate: (tools: LanguageModelV3FunctionTool[]) => string;
385
+ toolResponsePromptTemplate?: (toolResult: ToolResultPart) => string;
386
+ placement?: "first" | "last";
387
+ }): {
388
+ prompt: LanguageModelV3Prompt;
389
+ tools: never[];
390
+ toolChoice: undefined;
391
+ providerOptions: SharedV3ProviderOptions;
392
+ } | {
393
+ responseFormat: {
394
+ type: "json";
395
+ schema: JSONSchema7;
396
+ name: string;
397
+ description: string | undefined;
398
+ };
399
+ providerOptions: {
400
+ toolCallMiddleware: {
401
+ toolChoice?: {
402
+ type: string;
403
+ toolName?: string;
404
+ } | undefined;
405
+ };
406
+ };
407
+ prompt: LanguageModelV3Prompt;
408
+ tools: never[];
409
+ toolChoice: undefined;
410
+ } | {
411
+ responseFormat: {
412
+ type: "json";
413
+ schema: JSONSchema7;
414
+ };
415
+ providerOptions: {
416
+ toolCallMiddleware: {
417
+ toolChoice: {
418
+ type: "required";
419
+ };
420
+ };
421
+ };
422
+ prompt: LanguageModelV3Prompt;
423
+ tools: never[];
424
+ toolChoice: undefined;
425
+ };
399
426
 
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 };
427
+ export { type DebugLevel, type HeuristicEngineOptions, type HeuristicPhase, type HeuristicResult, type IntermediateCall, type OnErrorFn, type ParseOptions, 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, isToolCallContent, isToolChoiceActive, isToolResultPart, jsonProtocol, logParseFailure, logParsedChunk, logParsedSummary, logRawChunk, mergePipelineConfigs, normalizeCloseTagsHeuristic, originalToolsSchema, parse, repairAgainstSchemaHeuristic, stringify, toolChoiceStream, transform, transformParams, wrapGenerate, wrapStream, xmlProtocol, xmlToolMiddleware, yamlProtocol, yamlToolMiddleware };
package/dist/index.d.ts CHANGED
@@ -1,125 +1,6 @@
1
1
  import * as _ai_sdk_provider from '@ai-sdk/provider';
2
- import { LanguageModelV3FunctionTool, LanguageModelV3ToolCall, LanguageModelV3ToolResultPart, LanguageModelV3Content, LanguageModelV3StreamPart, LanguageModelV3Middleware, LanguageModelV3ProviderTool, JSONSchema7 } from '@ai-sdk/provider';
3
-
4
- /**
5
- * ToolCallProtocol
6
- *
7
- * A pluggable strategy that defines how tools are surfaced to a model, how
8
- * tool calls are rendered into provider-facing text, and how model output is
9
- * parsed back into the AI SDK v2 content/stream primitives.
10
- *
11
- * Implementations can choose any wire format (e.g. XML, JSON-with-tags, etc.)
12
- * as long as they respect the contract below:
13
- * - Static formatting helpers (`formatTools`, `formatToolCall`, `formatToolResponse`)
14
- * are used to construct strings that the model will read.
15
- * - Parsing helpers (`parseGeneratedText`, `createStreamParser`) must convert
16
- * model output back into structured `LanguageModelV3Content` parts, emitting
17
- * `text` for regular content and `tool-call` for detected tool invocations.
18
- */
19
- interface ToolCallProtocol {
20
- /**
21
- * Produces a provider-facing string that describes all available tools.
22
- *
23
- * Typical usage is to serialize each tool's `name`, `description`, and
24
- * JSON schema and inject that text into a system prompt using the supplied
25
- * `toolSystemPromptTemplate`.
26
- *
27
- * Implementations should be resilient to empty inputs.
28
- *
29
- * @param tools List of tools that can be invoked by the model.
30
- * @param toolSystemPromptTemplate Function that receives the serialized
31
- * tools and returns the final prompt text.
32
- * @returns A string to be embedded into the model's system prompt.
33
- */
34
- formatTools({ tools, toolSystemPromptTemplate, }: {
35
- tools: LanguageModelV3FunctionTool[];
36
- toolSystemPromptTemplate: (tools: string) => string;
37
- }): string;
38
- /**
39
- * Renders a single tool invocation into provider-facing text.
40
- *
41
- * Implementations may accept `toolCall.input` as a JSON string or as an
42
- * object (some runtimes normalize prior to calling). The result should be a
43
- * string that the model can understand and that the paired parser can later
44
- * recognize and recover as a `tool-call`.
45
- *
46
- * @param toolCall The tool call to format for the model.
47
- * @returns A textual representation of the tool call (e.g., an XML element).
48
- */
49
- formatToolCall(toolCall: LanguageModelV3ToolCall): string;
50
- /**
51
- * Formats a tool result payload so the model can consume it as plain text.
52
- *
53
- * This is commonly used to echo tool outputs back to the model in a format
54
- * symmetrical to `formatToolCall`.
55
- *
56
- * @param toolResult The result part produced after executing a tool.
57
- * @returns Textual representation of the tool result for the model.
58
- */
59
- formatToolResponse(toolResult: LanguageModelV3ToolResultPart): string;
60
- /**
61
- * Parses a fully generated text (non-streaming) response from the model and
62
- * converts it into a sequence of `LanguageModelV3Content` parts.
63
- *
64
- * Implementations should:
65
- * - Detect tool-call segments addressed to known `tools` and emit
66
- * `{ type: "tool-call", toolName, input }` parts.
67
- * - Emit `{ type: "text", text }` parts for any non-tool segments.
68
- * - Call `options.onError` and fall back to emitting the original text if a
69
- * segment cannot be parsed into a valid tool call.
70
- *
71
- * @param text The model output to parse.
72
- * @param tools The list of tools that may be invoked.
73
- * @param options Optional error callback for non-fatal parsing issues.
74
- * @returns A list of structured content parts derived from the text.
75
- */
76
- parseGeneratedText({ text, tools, options, }: {
77
- text: string;
78
- tools: LanguageModelV3FunctionTool[];
79
- options?: {
80
- onError?: (message: string, metadata?: Record<string, unknown>) => void;
81
- };
82
- }): LanguageModelV3Content[];
83
- /**
84
- * Creates a TransformStream that converts streaming model deltas
85
- * (`LanguageModelV3StreamPart`) into a normalized sequence of stream parts,
86
- * including `text-start`/`text-delta`/`text-end` and `tool-call` events.
87
- *
88
- * The stream parser should:
89
- * - Buffer text until a complete tool-call segment can be recognized, then
90
- * emit a `tool-call` part and properly close/open text segments around it.
91
- * - Be robust to partial/incomplete fragments commonly seen in streaming.
92
- * - Invoke `options.onError` and pass through the original text when a
93
- * segment cannot be parsed into a valid tool call.
94
- *
95
- * @param tools The list of tools that may be invoked by the model.
96
- * @param options Optional error callback for non-fatal streaming issues.
97
- * @returns A TransformStream that accepts and emits `LanguageModelV3StreamPart`s.
98
- */
99
- createStreamParser({ tools, options, }: {
100
- tools: LanguageModelV3FunctionTool[];
101
- options?: {
102
- onError?: (message: string, metadata?: Record<string, unknown>) => void;
103
- };
104
- }): TransformStream<LanguageModelV3StreamPart, LanguageModelV3StreamPart>;
105
- /**
106
- * Optionally returns the exact substrings that would be parsed as tool-calls
107
- * from the provided text for this protocol.
108
- * Used for debug logging in parse mode.
109
- */
110
- extractToolCallSegments?: ({ text, tools, }: {
111
- text: string;
112
- tools: LanguageModelV3FunctionTool[];
113
- }) => string[];
114
- }
115
-
116
- interface JsonMixOptions {
117
- toolCallStart?: string;
118
- toolCallEnd?: string;
119
- toolResponseStart?: string;
120
- toolResponseEnd?: string;
121
- }
122
- declare const jsonMixProtocol: ({ toolCallStart, toolCallEnd, toolResponseStart, toolResponseEnd, }?: JsonMixOptions) => ToolCallProtocol;
2
+ import { LanguageModelV3FunctionTool, LanguageModelV3ToolCall, LanguageModelV3Content, LanguageModelV3StreamPart, LanguageModelV3ProviderTool, JSONSchema7, LanguageModelV3, LanguageModelV3Middleware, LanguageModelV3Prompt, SharedV3ProviderOptions } from '@ai-sdk/provider';
3
+ import { ToolResultPart } from '@ai-sdk/provider-utils';
123
4
 
124
5
  /**
125
6
  * Heuristic Engine for XML Tool-Call Parsing
@@ -179,20 +60,57 @@ declare const dedupeShellStringTagsHeuristic: ToolCallHeuristic$1;
179
60
  declare const repairAgainstSchemaHeuristic: ToolCallHeuristic$1;
180
61
  declare const defaultPipelineConfig: PipelineConfig$1;
181
62
 
63
+ interface TCMProtocol {
64
+ formatTools({ tools, toolSystemPromptTemplate, }: {
65
+ tools: LanguageModelV3FunctionTool[];
66
+ toolSystemPromptTemplate: (tools: LanguageModelV3FunctionTool[]) => string;
67
+ }): string;
68
+ formatToolCall(toolCall: LanguageModelV3ToolCall): string;
69
+ parseGeneratedText({ text, tools, options, }: {
70
+ text: string;
71
+ tools: LanguageModelV3FunctionTool[];
72
+ options?: {
73
+ onError?: (message: string, metadata?: Record<string, unknown>) => void;
74
+ };
75
+ }): LanguageModelV3Content[];
76
+ createStreamParser({ tools, options, }: {
77
+ tools: LanguageModelV3FunctionTool[];
78
+ options?: {
79
+ onError?: (message: string, metadata?: Record<string, unknown>) => void;
80
+ };
81
+ }): TransformStream<LanguageModelV3StreamPart, LanguageModelV3StreamPart>;
82
+ extractToolCallSegments?: ({ text, tools, }: {
83
+ text: string;
84
+ tools: LanguageModelV3FunctionTool[];
85
+ }) => string[];
86
+ }
87
+ type TCMCoreProtocol = TCMProtocol;
88
+ declare function isProtocolFactory(protocol: TCMProtocol | (() => TCMProtocol)): protocol is () => TCMProtocol;
89
+ declare function isTCMProtocolFactory(protocol: TCMProtocol | (() => TCMProtocol)): protocol is () => TCMProtocol;
90
+
91
+ interface JsonProtocolOptions {
92
+ toolCallStart?: string;
93
+ toolCallEnd?: string;
94
+ }
95
+ declare const jsonProtocol: ({ toolCallStart, toolCallEnd, }?: JsonProtocolOptions) => TCMProtocol;
96
+
182
97
  type PipelineConfig = PipelineConfig$1;
183
98
  type ToolCallHeuristic = ToolCallHeuristic$1;
184
- interface MorphXmlProtocolOptions {
99
+ interface XmlProtocolOptions {
185
100
  heuristics?: ToolCallHeuristic[];
186
101
  pipeline?: PipelineConfig;
187
102
  maxReparses?: number;
188
103
  }
189
- declare const morphXmlProtocol: (protocolOptions?: MorphXmlProtocolOptions) => ToolCallProtocol;
104
+ declare const xmlProtocol: (protocolOptions?: XmlProtocolOptions) => TCMCoreProtocol;
190
105
 
191
- declare function createToolMiddleware({ protocol, toolSystemPromptTemplate, placement, }: {
192
- protocol: ToolCallProtocol | (() => ToolCallProtocol);
193
- toolSystemPromptTemplate: (tools: string) => string;
194
- placement?: "first" | "last";
195
- }): LanguageModelV3Middleware;
106
+ interface YamlProtocolOptions {
107
+ /**
108
+ * Whether to include a system prompt example showing YAML multiline syntax.
109
+ * @default true
110
+ */
111
+ includeMultilineExample?: boolean;
112
+ }
113
+ declare const yamlProtocol: (_protocolOptions?: YamlProtocolOptions) => TCMCoreProtocol;
196
114
 
197
115
  type DebugLevel = "off" | "stream" | "parse";
198
116
  declare function getDebugLevel(): DebugLevel;
@@ -388,13 +306,122 @@ declare function parse(text: string, optsOrReviver?: ParseOptions | ((key: strin
388
306
  declare function stringify(obj: unknown): string;
389
307
 
390
308
  declare function isToolCallContent(content: unknown): content is LanguageModelV3ToolCall;
391
- declare function isToolResultPart(content: unknown): content is LanguageModelV3ToolResultPart;
309
+ declare function isToolResultPart(content: unknown): content is ToolResultPart;
392
310
  declare function hasInputProperty(obj: unknown): obj is {
393
311
  input?: unknown;
394
312
  };
395
313
 
396
- declare const gemmaToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
314
+ declare function wrapGenerate({ protocol, doGenerate, params, }: {
315
+ protocol: TCMCoreProtocol;
316
+ doGenerate: () => ReturnType<LanguageModelV3["doGenerate"]>;
317
+ params: {
318
+ providerOptions?: ToolCallMiddlewareProviderOptions;
319
+ };
320
+ }): Promise<_ai_sdk_provider.LanguageModelV3GenerateResult>;
321
+
397
322
  declare const hermesToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
398
- declare const morphXmlToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
323
+ declare const xmlToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
324
+ declare const yamlToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
325
+
326
+ declare function wrapStream({ protocol, doStream, doGenerate, params, }: {
327
+ protocol: TCMCoreProtocol;
328
+ doStream: () => ReturnType<LanguageModelV3["doStream"]>;
329
+ doGenerate: () => ReturnType<LanguageModelV3["doGenerate"]>;
330
+ params: {
331
+ providerOptions?: ToolCallMiddlewareProviderOptions;
332
+ };
333
+ }): Promise<{
334
+ stream: ReadableStream<LanguageModelV3StreamPart>;
335
+ request?: {
336
+ body?: unknown;
337
+ };
338
+ response?: {
339
+ headers?: _ai_sdk_provider.SharedV3Headers;
340
+ };
341
+ }>;
342
+ declare function toolChoiceStream({ doGenerate, options, }: {
343
+ doGenerate: () => ReturnType<LanguageModelV3["doGenerate"]>;
344
+ options?: {
345
+ onError?: (message: string, metadata?: Record<string, unknown>) => void;
346
+ };
347
+ }): Promise<{
348
+ request: {
349
+ body?: unknown;
350
+ };
351
+ response: _ai_sdk_provider.LanguageModelV3ResponseMetadata & {
352
+ headers?: _ai_sdk_provider.SharedV3Headers;
353
+ body?: unknown;
354
+ };
355
+ stream: ReadableStream<LanguageModelV3StreamPart>;
356
+ }>;
357
+
358
+ declare function createToolMiddleware({ protocol, toolSystemPromptTemplate, toolResponsePromptTemplate, placement, }: {
359
+ protocol: TCMCoreProtocol | (() => TCMCoreProtocol);
360
+ toolSystemPromptTemplate: (tools: LanguageModelV3FunctionTool[]) => string;
361
+ toolResponsePromptTemplate?: (toolResult: ToolResultPart) => string;
362
+ placement?: "first" | "last";
363
+ }): LanguageModelV3Middleware;
364
+
365
+ declare function transformParams({ params, protocol, toolSystemPromptTemplate, toolResponsePromptTemplate, placement, }: {
366
+ params: {
367
+ prompt?: LanguageModelV3Prompt;
368
+ tools?: Array<LanguageModelV3FunctionTool | {
369
+ type: string;
370
+ }>;
371
+ providerOptions?: {
372
+ toolCallMiddleware?: {
373
+ toolChoice?: {
374
+ type: string;
375
+ };
376
+ };
377
+ };
378
+ toolChoice?: {
379
+ type: string;
380
+ toolName?: string;
381
+ };
382
+ };
383
+ protocol: TCMCoreProtocol | (() => TCMCoreProtocol);
384
+ toolSystemPromptTemplate: (tools: LanguageModelV3FunctionTool[]) => string;
385
+ toolResponsePromptTemplate?: (toolResult: ToolResultPart) => string;
386
+ placement?: "first" | "last";
387
+ }): {
388
+ prompt: LanguageModelV3Prompt;
389
+ tools: never[];
390
+ toolChoice: undefined;
391
+ providerOptions: SharedV3ProviderOptions;
392
+ } | {
393
+ responseFormat: {
394
+ type: "json";
395
+ schema: JSONSchema7;
396
+ name: string;
397
+ description: string | undefined;
398
+ };
399
+ providerOptions: {
400
+ toolCallMiddleware: {
401
+ toolChoice?: {
402
+ type: string;
403
+ toolName?: string;
404
+ } | undefined;
405
+ };
406
+ };
407
+ prompt: LanguageModelV3Prompt;
408
+ tools: never[];
409
+ toolChoice: undefined;
410
+ } | {
411
+ responseFormat: {
412
+ type: "json";
413
+ schema: JSONSchema7;
414
+ };
415
+ providerOptions: {
416
+ toolCallMiddleware: {
417
+ toolChoice: {
418
+ type: "required";
419
+ };
420
+ };
421
+ };
422
+ prompt: LanguageModelV3Prompt;
423
+ tools: never[];
424
+ toolChoice: undefined;
425
+ };
399
426
 
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 };
427
+ export { type DebugLevel, type HeuristicEngineOptions, type HeuristicPhase, type HeuristicResult, type IntermediateCall, type OnErrorFn, type ParseOptions, 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, isToolCallContent, isToolChoiceActive, isToolResultPart, jsonProtocol, logParseFailure, logParsedChunk, logParsedSummary, logRawChunk, mergePipelineConfigs, normalizeCloseTagsHeuristic, originalToolsSchema, parse, repairAgainstSchemaHeuristic, stringify, toolChoiceStream, transform, transformParams, wrapGenerate, wrapStream, xmlProtocol, xmlToolMiddleware, yamlProtocol, yamlToolMiddleware };