@ai-sdk-tool/parser 3.0.0-canary.2 → 3.0.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,7 @@
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;
1
+ import { T as ToolCallProtocol } from './tool-call-protocol-Bn2CBcD-.cjs';
2
+ export { i as isProtocolFactory } from './tool-call-protocol-Bn2CBcD-.cjs';
3
+ import { LanguageModelV3FunctionTool, LanguageModelV3ProviderTool, JSONSchema7, LanguageModelV3ToolCall, LanguageModelV3ToolResultPart } from '@ai-sdk/provider';
4
+ export { createToolMiddleware, gemmaToolMiddleware, hermesToolMiddleware, morphXmlToolMiddleware, orchestratorToolMiddleware } from './v6.cjs';
123
5
 
124
6
  /**
125
7
  * Heuristic Engine for XML Tool-Call Parsing
@@ -179,6 +61,14 @@ declare const dedupeShellStringTagsHeuristic: ToolCallHeuristic$1;
179
61
  declare const repairAgainstSchemaHeuristic: ToolCallHeuristic$1;
180
62
  declare const defaultPipelineConfig: PipelineConfig$1;
181
63
 
64
+ interface JsonMixOptions {
65
+ toolCallStart?: string;
66
+ toolCallEnd?: string;
67
+ toolResponseStart?: string;
68
+ toolResponseEnd?: string;
69
+ }
70
+ declare const jsonMixProtocol: ({ toolCallStart, toolCallEnd, toolResponseStart, toolResponseEnd, }?: JsonMixOptions) => ToolCallProtocol;
71
+
182
72
  type PipelineConfig = PipelineConfig$1;
183
73
  type ToolCallHeuristic = ToolCallHeuristic$1;
184
74
  interface MorphXmlProtocolOptions {
@@ -188,11 +78,18 @@ interface MorphXmlProtocolOptions {
188
78
  }
189
79
  declare const morphXmlProtocol: (protocolOptions?: MorphXmlProtocolOptions) => ToolCallProtocol;
190
80
 
191
- declare function createToolMiddleware({ protocol, toolSystemPromptTemplate, placement, }: {
192
- protocol: ToolCallProtocol | (() => ToolCallProtocol);
193
- toolSystemPromptTemplate: (tools: string) => string;
194
- placement?: "first" | "last";
195
- }): LanguageModelV3Middleware;
81
+ interface YamlXmlProtocolOptions {
82
+ /**
83
+ * Whether to include a system prompt example showing YAML multiline syntax.
84
+ * @default true
85
+ */
86
+ includeMultilineExample?: boolean;
87
+ }
88
+ declare const yamlXmlProtocol: (_protocolOptions?: YamlXmlProtocolOptions) => ToolCallProtocol;
89
+ /**
90
+ * Default system prompt template for Orchestrator-style YAML+XML tool calling.
91
+ */
92
+ declare function orchestratorSystemPromptTemplate(tools: string, includeMultilineExample?: boolean): string;
196
93
 
197
94
  type DebugLevel = "off" | "stream" | "parse";
198
95
  declare function getDebugLevel(): DebugLevel;
@@ -393,8 +290,4 @@ declare function hasInputProperty(obj: unknown): obj is {
393
290
  input?: unknown;
394
291
  };
395
292
 
396
- declare const gemmaToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
397
- declare const hermesToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
398
- declare const morphXmlToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
399
-
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 };
293
+ export { type DebugLevel, type HeuristicEngineOptions, type HeuristicPhase, type HeuristicResult, type IntermediateCall, type MorphXmlProtocolOptions, type OnErrorFn, type ParseOptions, type PipelineConfig$1 as PipelineConfig, type ToolCallHeuristic$1 as ToolCallHeuristic, type ToolCallMiddlewareProviderOptions, ToolCallProtocol, type YamlXmlProtocolOptions, applyHeuristicPipeline, balanceTagsHeuristic, createDynamicIfThenElseSchema, createIntermediateCall, decodeOriginalTools, dedupeShellStringTagsHeuristic, defaultPipelineConfig, encodeOriginalTools, escapeInvalidLtHeuristic, escapeRegExp, extractOnErrorOption, extractToolNamesFromOriginalTools, getDebugLevel, getPotentialStartIndex, hasInputProperty, isToolCallContent, isToolChoiceActive, isToolResultPart, jsonMixProtocol, logParseFailure, logParsedChunk, logParsedSummary, logRawChunk, mergePipelineConfigs, morphXmlProtocol, normalizeCloseTagsHeuristic, orchestratorSystemPromptTemplate, originalToolsSchema, parse, repairAgainstSchemaHeuristic, stringify, transform, yamlXmlProtocol };
package/dist/index.d.ts CHANGED
@@ -1,125 +1,7 @@
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;
1
+ import { T as ToolCallProtocol } from './tool-call-protocol-Bn2CBcD-.js';
2
+ export { i as isProtocolFactory } from './tool-call-protocol-Bn2CBcD-.js';
3
+ import { LanguageModelV3FunctionTool, LanguageModelV3ProviderTool, JSONSchema7, LanguageModelV3ToolCall, LanguageModelV3ToolResultPart } from '@ai-sdk/provider';
4
+ export { createToolMiddleware, gemmaToolMiddleware, hermesToolMiddleware, morphXmlToolMiddleware, orchestratorToolMiddleware } from './v6.js';
123
5
 
124
6
  /**
125
7
  * Heuristic Engine for XML Tool-Call Parsing
@@ -179,6 +61,14 @@ declare const dedupeShellStringTagsHeuristic: ToolCallHeuristic$1;
179
61
  declare const repairAgainstSchemaHeuristic: ToolCallHeuristic$1;
180
62
  declare const defaultPipelineConfig: PipelineConfig$1;
181
63
 
64
+ interface JsonMixOptions {
65
+ toolCallStart?: string;
66
+ toolCallEnd?: string;
67
+ toolResponseStart?: string;
68
+ toolResponseEnd?: string;
69
+ }
70
+ declare const jsonMixProtocol: ({ toolCallStart, toolCallEnd, toolResponseStart, toolResponseEnd, }?: JsonMixOptions) => ToolCallProtocol;
71
+
182
72
  type PipelineConfig = PipelineConfig$1;
183
73
  type ToolCallHeuristic = ToolCallHeuristic$1;
184
74
  interface MorphXmlProtocolOptions {
@@ -188,11 +78,18 @@ interface MorphXmlProtocolOptions {
188
78
  }
189
79
  declare const morphXmlProtocol: (protocolOptions?: MorphXmlProtocolOptions) => ToolCallProtocol;
190
80
 
191
- declare function createToolMiddleware({ protocol, toolSystemPromptTemplate, placement, }: {
192
- protocol: ToolCallProtocol | (() => ToolCallProtocol);
193
- toolSystemPromptTemplate: (tools: string) => string;
194
- placement?: "first" | "last";
195
- }): LanguageModelV3Middleware;
81
+ interface YamlXmlProtocolOptions {
82
+ /**
83
+ * Whether to include a system prompt example showing YAML multiline syntax.
84
+ * @default true
85
+ */
86
+ includeMultilineExample?: boolean;
87
+ }
88
+ declare const yamlXmlProtocol: (_protocolOptions?: YamlXmlProtocolOptions) => ToolCallProtocol;
89
+ /**
90
+ * Default system prompt template for Orchestrator-style YAML+XML tool calling.
91
+ */
92
+ declare function orchestratorSystemPromptTemplate(tools: string, includeMultilineExample?: boolean): string;
196
93
 
197
94
  type DebugLevel = "off" | "stream" | "parse";
198
95
  declare function getDebugLevel(): DebugLevel;
@@ -393,8 +290,4 @@ declare function hasInputProperty(obj: unknown): obj is {
393
290
  input?: unknown;
394
291
  };
395
292
 
396
- declare const gemmaToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
397
- declare const hermesToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
398
- declare const morphXmlToolMiddleware: _ai_sdk_provider.LanguageModelV3Middleware;
399
-
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 };
293
+ export { type DebugLevel, type HeuristicEngineOptions, type HeuristicPhase, type HeuristicResult, type IntermediateCall, type MorphXmlProtocolOptions, type OnErrorFn, type ParseOptions, type PipelineConfig$1 as PipelineConfig, type ToolCallHeuristic$1 as ToolCallHeuristic, type ToolCallMiddlewareProviderOptions, ToolCallProtocol, type YamlXmlProtocolOptions, applyHeuristicPipeline, balanceTagsHeuristic, createDynamicIfThenElseSchema, createIntermediateCall, decodeOriginalTools, dedupeShellStringTagsHeuristic, defaultPipelineConfig, encodeOriginalTools, escapeInvalidLtHeuristic, escapeRegExp, extractOnErrorOption, extractToolNamesFromOriginalTools, getDebugLevel, getPotentialStartIndex, hasInputProperty, isToolCallContent, isToolChoiceActive, isToolResultPart, jsonMixProtocol, logParseFailure, logParsedChunk, logParsedSummary, logRawChunk, mergePipelineConfigs, morphXmlProtocol, normalizeCloseTagsHeuristic, orchestratorSystemPromptTemplate, originalToolsSchema, parse, repairAgainstSchemaHeuristic, stringify, transform, yamlXmlProtocol };
package/dist/index.js CHANGED
@@ -1,9 +1,18 @@
1
+ import "./chunk-DFOXAWP6.js";
2
+ import {
3
+ createToolMiddleware,
4
+ gemmaToolMiddleware,
5
+ hermesToolMiddleware,
6
+ morphXmlToolMiddleware,
7
+ orchestratorSystemPromptTemplate,
8
+ orchestratorToolMiddleware,
9
+ yamlXmlProtocol
10
+ } from "./chunk-QPJA5CS6.js";
1
11
  import {
2
12
  applyHeuristicPipeline,
3
13
  balanceTagsHeuristic,
4
14
  createDynamicIfThenElseSchema,
5
15
  createIntermediateCall,
6
- createToolMiddleware,
7
16
  decodeOriginalTools,
8
17
  dedupeShellStringTagsHeuristic,
9
18
  defaultPipelineConfig,
@@ -12,11 +21,10 @@ import {
12
21
  escapeRegExp,
13
22
  extractOnErrorOption,
14
23
  extractToolNamesFromOriginalTools,
15
- gemmaToolMiddleware,
16
24
  getDebugLevel,
17
25
  getPotentialStartIndex,
18
26
  hasInputProperty,
19
- hermesToolMiddleware,
27
+ isProtocolFactory,
20
28
  isToolCallContent,
21
29
  isToolChoiceActive,
22
30
  isToolResultPart,
@@ -27,14 +35,13 @@ import {
27
35
  logRawChunk,
28
36
  mergePipelineConfigs,
29
37
  morphXmlProtocol,
30
- morphXmlToolMiddleware,
31
38
  normalizeCloseTagsHeuristic,
32
39
  originalToolsSchema,
33
40
  parse,
34
41
  repairAgainstSchemaHeuristic,
35
42
  stringify,
36
43
  transform
37
- } from "./chunk-LB5ALTRD.js";
44
+ } from "./chunk-NOYHOQOL.js";
38
45
  export {
39
46
  applyHeuristicPipeline,
40
47
  balanceTagsHeuristic,
@@ -54,6 +61,7 @@ export {
54
61
  getPotentialStartIndex,
55
62
  hasInputProperty,
56
63
  hermesToolMiddleware,
64
+ isProtocolFactory,
57
65
  isToolCallContent,
58
66
  isToolChoiceActive,
59
67
  isToolResultPart,
@@ -66,10 +74,13 @@ export {
66
74
  morphXmlProtocol,
67
75
  morphXmlToolMiddleware,
68
76
  normalizeCloseTagsHeuristic,
77
+ orchestratorSystemPromptTemplate,
78
+ orchestratorToolMiddleware,
69
79
  originalToolsSchema,
70
- parse as parseRJSON,
80
+ parse,
71
81
  repairAgainstSchemaHeuristic,
72
- stringify as stringifyRJSON,
73
- transform as transformRJSON
82
+ stringify,
83
+ transform,
84
+ yamlXmlProtocol
74
85
  };
75
86
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,84 @@
1
+ interface TCMCoreToolCall {
2
+ toolCallId: string;
3
+ toolName: string;
4
+ input: string;
5
+ }
6
+ interface TCMCoreToolResult {
7
+ toolCallId: string;
8
+ toolName: string;
9
+ result: unknown;
10
+ }
11
+ interface TCMCoreTextPart {
12
+ type: "text";
13
+ text: string;
14
+ }
15
+ type TCMCoreContentPart = TCMCoreTextPart | (TCMCoreToolCall & {
16
+ type: "tool-call";
17
+ });
18
+ type TCMCoreStreamPart = {
19
+ type: "text-start";
20
+ id: string;
21
+ } | {
22
+ type: "text-delta";
23
+ textDelta: string;
24
+ delta?: string;
25
+ id?: string;
26
+ } | {
27
+ type: "text-end";
28
+ id: string;
29
+ } | {
30
+ type: "tool-call";
31
+ toolCallId: string;
32
+ toolName: string;
33
+ input: string;
34
+ } | {
35
+ type: "tool-call-delta";
36
+ toolCallId: string;
37
+ toolName: string;
38
+ argsTextDelta: string;
39
+ } | {
40
+ type: "error";
41
+ error: unknown;
42
+ } | {
43
+ type: "finish";
44
+ finishReason: string;
45
+ usage?: {
46
+ promptTokens: number;
47
+ completionTokens: number;
48
+ };
49
+ };
50
+ interface TCMCoreFunctionTool {
51
+ type: "function";
52
+ name: string;
53
+ description?: string;
54
+ inputSchema: unknown;
55
+ }
56
+
57
+ interface ToolCallProtocol {
58
+ formatTools({ tools, toolSystemPromptTemplate, }: {
59
+ tools: TCMCoreFunctionTool[];
60
+ toolSystemPromptTemplate: (tools: string) => string;
61
+ }): string;
62
+ formatToolCall(toolCall: TCMCoreToolCall): string;
63
+ formatToolResponse(toolResult: TCMCoreToolResult): string;
64
+ parseGeneratedText({ text, tools, options, }: {
65
+ text: string;
66
+ tools: TCMCoreFunctionTool[];
67
+ options?: {
68
+ onError?: (message: string, metadata?: Record<string, unknown>) => void;
69
+ };
70
+ }): TCMCoreContentPart[];
71
+ createStreamParser({ tools, options, }: {
72
+ tools: TCMCoreFunctionTool[];
73
+ options?: {
74
+ onError?: (message: string, metadata?: Record<string, unknown>) => void;
75
+ };
76
+ }): TransformStream<TCMCoreStreamPart, TCMCoreStreamPart>;
77
+ extractToolCallSegments?: ({ text, tools, }: {
78
+ text: string;
79
+ tools: TCMCoreFunctionTool[];
80
+ }) => string[];
81
+ }
82
+ declare function isProtocolFactory(protocol: ToolCallProtocol | (() => ToolCallProtocol)): protocol is () => ToolCallProtocol;
83
+
84
+ export { type ToolCallProtocol as T, isProtocolFactory as i };
@@ -0,0 +1,84 @@
1
+ interface TCMCoreToolCall {
2
+ toolCallId: string;
3
+ toolName: string;
4
+ input: string;
5
+ }
6
+ interface TCMCoreToolResult {
7
+ toolCallId: string;
8
+ toolName: string;
9
+ result: unknown;
10
+ }
11
+ interface TCMCoreTextPart {
12
+ type: "text";
13
+ text: string;
14
+ }
15
+ type TCMCoreContentPart = TCMCoreTextPart | (TCMCoreToolCall & {
16
+ type: "tool-call";
17
+ });
18
+ type TCMCoreStreamPart = {
19
+ type: "text-start";
20
+ id: string;
21
+ } | {
22
+ type: "text-delta";
23
+ textDelta: string;
24
+ delta?: string;
25
+ id?: string;
26
+ } | {
27
+ type: "text-end";
28
+ id: string;
29
+ } | {
30
+ type: "tool-call";
31
+ toolCallId: string;
32
+ toolName: string;
33
+ input: string;
34
+ } | {
35
+ type: "tool-call-delta";
36
+ toolCallId: string;
37
+ toolName: string;
38
+ argsTextDelta: string;
39
+ } | {
40
+ type: "error";
41
+ error: unknown;
42
+ } | {
43
+ type: "finish";
44
+ finishReason: string;
45
+ usage?: {
46
+ promptTokens: number;
47
+ completionTokens: number;
48
+ };
49
+ };
50
+ interface TCMCoreFunctionTool {
51
+ type: "function";
52
+ name: string;
53
+ description?: string;
54
+ inputSchema: unknown;
55
+ }
56
+
57
+ interface ToolCallProtocol {
58
+ formatTools({ tools, toolSystemPromptTemplate, }: {
59
+ tools: TCMCoreFunctionTool[];
60
+ toolSystemPromptTemplate: (tools: string) => string;
61
+ }): string;
62
+ formatToolCall(toolCall: TCMCoreToolCall): string;
63
+ formatToolResponse(toolResult: TCMCoreToolResult): string;
64
+ parseGeneratedText({ text, tools, options, }: {
65
+ text: string;
66
+ tools: TCMCoreFunctionTool[];
67
+ options?: {
68
+ onError?: (message: string, metadata?: Record<string, unknown>) => void;
69
+ };
70
+ }): TCMCoreContentPart[];
71
+ createStreamParser({ tools, options, }: {
72
+ tools: TCMCoreFunctionTool[];
73
+ options?: {
74
+ onError?: (message: string, metadata?: Record<string, unknown>) => void;
75
+ };
76
+ }): TransformStream<TCMCoreStreamPart, TCMCoreStreamPart>;
77
+ extractToolCallSegments?: ({ text, tools, }: {
78
+ text: string;
79
+ tools: TCMCoreFunctionTool[];
80
+ }) => string[];
81
+ }
82
+ declare function isProtocolFactory(protocol: ToolCallProtocol | (() => ToolCallProtocol)): protocol is () => ToolCallProtocol;
83
+
84
+ export { type ToolCallProtocol as T, isProtocolFactory as i };