@quilltap/plugin-utils 1.4.1 → 1.5.1

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.
@@ -1,246 +1,109 @@
1
- import { ToolCallRequest, AnthropicToolDefinition, UniversalTool, GoogleToolDefinition, OpenAIToolDefinition } from '@quilltap/plugin-types';
1
+ import { ToolCallRequest } from '@quilltap/plugin-types';
2
2
  export { AnthropicToolDefinition, GoogleToolDefinition, OpenAIToolDefinition, ToolCall, ToolCallRequest, ToolFormatOptions, ToolResult, UniversalTool } from '@quilltap/plugin-types';
3
+ export { T as ToolCallFormat, a as ToolConvertTarget, b as applyDescriptionLimit, c as convertFromAnthropicFormat, d as convertFromGoogleFormat, e as convertOpenAIToAnthropicFormat, f as convertOpenAIToGoogleFormat, g as convertToAnthropicFormat, h as convertToGoogleFormat, i as convertToolTo, j as convertToolsTo, k as detectToolCallFormat, l as hasToolCalls, p as parseAnthropicToolCalls, m as parseGoogleToolCalls, n as parseOpenAIToolCalls, o as parseToolCalls } from '../converters-BPYo8xdH.mjs';
3
4
 
4
5
  /**
5
- * Tool Call Parsers
6
+ * Text-Based Tool Call Parsers
6
7
  *
7
- * Provider-specific parsers for extracting tool calls from LLM responses.
8
- * Each parser converts from a provider's native format to the standardized
9
- * ToolCallRequest format.
8
+ * Utility functions for parsing spontaneous XML-style tool calls from LLM
9
+ * text responses. These are for models that emit tool-call-like markup in
10
+ * their output instead of using native function calling APIs.
10
11
  *
11
- * @module @quilltap/plugin-utils/tools/parsers
12
- */
13
-
14
- /**
15
- * Supported tool call response formats
16
- */
17
- type ToolCallFormat = 'openai' | 'anthropic' | 'google' | 'auto';
18
- /**
19
- * Parse OpenAI format tool calls from LLM response
20
- *
21
- * Extracts tool calls from OpenAI/Grok API responses which return
22
- * tool_calls in the message object.
23
- *
24
- * Expected response structures:
25
- * - `response.tool_calls` (direct)
26
- * - `response.choices[0].message.tool_calls` (nested)
12
+ * Provider plugins import and compose these utilities to implement their
13
+ * `hasTextToolMarkers`, `parseTextToolCalls`, and `stripTextToolMarkers` methods.
27
14
  *
28
- * @param response - The raw response from provider API
29
- * @returns Array of parsed tool call requests
30
- *
31
- * @example
32
- * ```typescript
33
- * const response = await openai.chat.completions.create({...});
34
- * const toolCalls = parseOpenAIToolCalls(response);
35
- * // Returns: [{ name: 'search_web', arguments: { query: 'hello' } }]
36
- * ```
15
+ * @module @quilltap/plugin-utils/tools/text-parsers
37
16
  */
38
- declare function parseOpenAIToolCalls(response: unknown): ToolCallRequest[];
39
- /**
40
- * Parse Anthropic format tool calls from LLM response
41
- *
42
- * Extracts tool calls from Anthropic API responses which return
43
- * tool_use blocks in the content array.
44
- *
45
- * Expected response structure:
46
- * - `response.content` array with `{ type: 'tool_use', name, input }`
47
- *
48
- * @param response - The raw response from provider API
49
- * @returns Array of parsed tool call requests
50
- *
51
- * @example
52
- * ```typescript
53
- * const response = await anthropic.messages.create({...});
54
- * const toolCalls = parseAnthropicToolCalls(response);
55
- * // Returns: [{ name: 'search_web', arguments: { query: 'hello' } }]
56
- * ```
57
- */
58
- declare function parseAnthropicToolCalls(response: unknown): ToolCallRequest[];
59
- /**
60
- * Parse Google Gemini format tool calls from LLM response
61
- *
62
- * Extracts tool calls from Google Gemini API responses which return
63
- * functionCall objects in the parts array.
64
- *
65
- * Expected response structure:
66
- * - `response.candidates[0].content.parts` array with `{ functionCall: { name, args } }`
67
- *
68
- * @param response - The raw response from provider API
69
- * @returns Array of parsed tool call requests
70
- *
71
- * @example
72
- * ```typescript
73
- * const response = await gemini.generateContent({...});
74
- * const toolCalls = parseGoogleToolCalls(response);
75
- * // Returns: [{ name: 'search_web', arguments: { query: 'hello' } }]
76
- * ```
77
- */
78
- declare function parseGoogleToolCalls(response: unknown): ToolCallRequest[];
79
- /**
80
- * Detect the format of a tool call response
81
- *
82
- * Analyzes the response structure to determine which provider format it uses.
83
- *
84
- * @param response - The raw response from a provider API
85
- * @returns The detected format, or null if unrecognized
86
- */
87
- declare function detectToolCallFormat(response: unknown): ToolCallFormat | null;
88
- /**
89
- * Parse tool calls with auto-detection or explicit format
90
- *
91
- * A unified parser that can either auto-detect the response format
92
- * or use a specified format. This is useful when you're not sure
93
- * which provider's response you're handling.
94
- *
95
- * @param response - The raw response from a provider API
96
- * @param format - The format to use: 'openai', 'anthropic', 'google', or 'auto'
97
- * @returns Array of parsed tool call requests
98
- *
99
- * @example
100
- * ```typescript
101
- * // Auto-detect format
102
- * const toolCalls = parseToolCalls(response, 'auto');
103
- *
104
- * // Or specify format explicitly
105
- * const toolCalls = parseToolCalls(response, 'openai');
106
- * ```
107
- */
108
- declare function parseToolCalls(response: unknown, format?: ToolCallFormat): ToolCallRequest[];
109
- /**
110
- * Check if a response contains tool calls
111
- *
112
- * Quick check to determine if a response has any tool calls
113
- * without fully parsing them.
114
- *
115
- * @param response - The raw response from a provider API
116
- * @returns True if the response contains tool calls
117
- */
118
- declare function hasToolCalls(response: unknown): boolean;
119
17
 
120
18
  /**
121
- * Tool Format Converters
122
- *
123
- * Utilities for converting between different provider tool formats.
124
- * The universal format (OpenAI-style) serves as the baseline for all conversions.
125
- *
126
- * @module @quilltap/plugin-utils/tools/converters
19
+ * Parsed text-based tool call from LLM output
127
20
  */
128
-
21
+ interface ParsedTextTool {
22
+ /** The tool name */
23
+ toolName: string;
24
+ /** Arguments extracted from the markup */
25
+ arguments: Record<string, unknown>;
26
+ /** The full matched markup text (for stripping) */
27
+ fullMatch: string;
28
+ /** Start index in the original text */
29
+ startIndex: number;
30
+ /** End index in the original text */
31
+ endIndex: number;
32
+ /** Which format was detected */
33
+ format: 'deepseek' | 'claude' | 'generic' | 'function_call' | 'tool_use';
34
+ }
129
35
  /**
130
- * Convert OpenAI/Universal format tool to Anthropic format
131
- *
132
- * Anthropic uses a tool_use format with:
133
- * - name: string
134
- * - description: string
135
- * - input_schema: JSON schema object
136
- *
137
- * @param tool - Universal tool or OpenAI tool definition
138
- * @returns Tool formatted for Anthropic's tool_use
139
- *
140
- * @example
141
- * ```typescript
142
- * const anthropicTool = convertToAnthropicFormat(universalTool);
143
- * // Returns: {
144
- * // name: 'search_web',
145
- * // description: 'Search the web',
146
- * // input_schema: {
147
- * // type: 'object',
148
- * // properties: { query: { type: 'string' } },
149
- * // required: ['query']
150
- * // }
151
- * // }
152
- * ```
36
+ * Normalize a tool name from hallucinated markup to the canonical name.
37
+ * Returns the original name if no alias is found (passes through unknown tools).
153
38
  */
154
- declare function convertToAnthropicFormat(tool: UniversalTool | OpenAIToolDefinition): AnthropicToolDefinition;
39
+ declare function normalizeToolName(name: string): string;
155
40
  /**
156
- * Convert OpenAI/Universal format tool to Google Gemini format
41
+ * Convert a ParsedTextTool to the standard ToolCallRequest format.
157
42
  *
158
- * Google uses a function calling format with:
159
- * - name: string
160
- * - description: string
161
- * - parameters: JSON schema object
162
- *
163
- * @param tool - Universal tool or OpenAI tool definition
164
- * @returns Tool formatted for Google's functionCall
165
- *
166
- * @example
167
- * ```typescript
168
- * const googleTool = convertToGoogleFormat(universalTool);
169
- * // Returns: {
170
- * // name: 'search_web',
171
- * // description: 'Search the web',
172
- * // parameters: {
173
- * // type: 'object',
174
- * // properties: { query: { type: 'string' } },
175
- * // required: ['query']
176
- * // }
177
- * // }
178
- * ```
43
+ * For well-known tools, normalizes argument names (e.g., "search" → "query").
44
+ * For unknown tools, passes arguments through as-is.
179
45
  */
180
- declare function convertToGoogleFormat(tool: UniversalTool | OpenAIToolDefinition): GoogleToolDefinition;
46
+ declare function convertToToolCallRequest(parsed: ParsedTextTool): ToolCallRequest;
181
47
  /**
182
- * Convert Anthropic format tool to Universal/OpenAI format
183
- *
184
- * @param tool - Anthropic format tool
185
- * @returns Tool in universal OpenAI format
48
+ * Parse `<function_calls><invoke name="...">` format (DeepSeek and Claude-style)
186
49
  */
187
- declare function convertFromAnthropicFormat(tool: AnthropicToolDefinition): UniversalTool;
50
+ declare function parseFunctionCallsFormat(response: string): ParsedTextTool[];
188
51
  /**
189
- * Convert Google format tool to Universal/OpenAI format
190
- *
191
- * @param tool - Google format tool
192
- * @returns Tool in universal OpenAI format
52
+ * Parse `<tool_call>` format (generic XML)
193
53
  */
194
- declare function convertFromGoogleFormat(tool: GoogleToolDefinition): UniversalTool;
54
+ declare function parseToolCallFormat(response: string): ParsedTextTool[];
195
55
  /**
196
- * Apply prompt/description length limit to a tool
197
- *
198
- * Modifies a tool's description if it exceeds maxBytes, appending a warning
199
- * that the description was truncated. This is useful for providers with
200
- * strict token limits.
201
- *
202
- * @param tool - Tool object (any format) with a description property
203
- * @param maxBytes - Maximum bytes allowed for description (including warning)
204
- * @returns Modified tool with truncated description if needed
205
- *
206
- * @example
207
- * ```typescript
208
- * const limitedTool = applyDescriptionLimit(tool, 500);
209
- * // If description > 500 bytes, truncates and adds warning
210
- * ```
56
+ * Parse `<function_call name="...">` format
211
57
  */
212
- declare function applyDescriptionLimit<T extends {
213
- description: string;
214
- }>(tool: T, maxBytes: number): T;
58
+ declare function parseFunctionCallFormat(response: string): ParsedTextTool[];
215
59
  /**
216
- * Target format for tool conversion
60
+ * Parse `<tool_use>` format (Gemini and others)
61
+ *
62
+ * Handles multiple sub-formats:
63
+ * - Bare JSON: `<tool_use>{"name":"fn","input":{...}}</tool_use>`
64
+ * - XML children: `<tool_use><name>fn</name><arguments>...</arguments></tool_use>`
65
+ * - JSON in arguments: `<tool_use><name>fn</name><arguments>{"q":"v"}</arguments></tool_use>`
66
+ * - Attributed: `<tool_use name="fn"><arguments>...</arguments></tool_use>`
217
67
  */
218
- type ToolConvertTarget = 'openai' | 'anthropic' | 'google';
68
+ declare function parseToolUseFormat(response: string): ParsedTextTool[];
219
69
  /**
220
- * Convert a universal tool to a specific provider format
70
+ * Parse all known XML tool call formats from response text.
71
+ * Deduplicates by position and sorts by start index.
221
72
  *
222
- * @param tool - Universal tool or OpenAI tool definition
223
- * @param target - Target provider format
224
- * @returns Tool in the target format
73
+ * Plugins can call this directly or compose individual format parsers
74
+ * for provider-specific behavior.
225
75
  */
226
- declare function convertToolTo(tool: UniversalTool | OpenAIToolDefinition, target: ToolConvertTarget): UniversalTool | OpenAIToolDefinition | AnthropicToolDefinition | GoogleToolDefinition;
76
+ declare function parseAllXMLFormats(response: string): ParsedTextTool[];
227
77
  /**
228
- * Convert multiple tools to a specific provider format
229
- *
230
- * @param tools - Array of universal tools or OpenAI tool definitions
231
- * @param target - Target provider format
232
- * @returns Array of tools in the target format
78
+ * Convert parsed text tools to standard ToolCallRequest array.
79
+ * Convenience wrapper for plugins implementing parseTextToolCalls.
233
80
  */
234
- declare function convertToolsTo(tools: Array<UniversalTool | OpenAIToolDefinition>, target: ToolConvertTarget): Array<UniversalTool | OpenAIToolDefinition | AnthropicToolDefinition | GoogleToolDefinition>;
81
+ declare function parseAllXMLAsToolCalls(response: string): ToolCallRequest[];
235
82
  /**
236
- * Alias for convertToAnthropicFormat
237
- * @deprecated Use convertToAnthropicFormat instead
83
+ * Check if text contains any of the known XML tool call patterns.
84
+ * Quick regex check before full parsing.
238
85
  */
239
- declare const convertOpenAIToAnthropicFormat: typeof convertToAnthropicFormat;
86
+ declare function hasAnyXMLToolMarkers(response: string): boolean;
87
+ /** Check for `<function_calls>` markers (DeepSeek/Claude-style) */
88
+ declare function hasFunctionCallsMarkers(response: string): boolean;
89
+ /** Check for `<tool_call>` markers (generic) */
90
+ declare function hasToolCallMarkers(response: string): boolean;
91
+ /** Check for `<function_call>` markers */
92
+ declare function hasFunctionCallMarkers(response: string): boolean;
93
+ /** Check for `<tool_use>` markers (Gemini-style) */
94
+ declare function hasToolUseMarkers(response: string): boolean;
240
95
  /**
241
- * Alias for convertToGoogleFormat
242
- * @deprecated Use convertToGoogleFormat instead
96
+ * Strip all known XML tool call markers from text.
97
+ * Cleans up whitespace left behind.
243
98
  */
244
- declare const convertOpenAIToGoogleFormat: typeof convertToGoogleFormat;
99
+ declare function stripAllXMLToolMarkers(response: string): string;
100
+ /** Strip `<function_calls>` blocks */
101
+ declare function stripFunctionCallsMarkers(response: string): string;
102
+ /** Strip `<tool_call>` blocks */
103
+ declare function stripToolCallMarkers(response: string): string;
104
+ /** Strip `<function_call>` blocks */
105
+ declare function stripFunctionCallMarkers(response: string): string;
106
+ /** Strip `<tool_use>` blocks */
107
+ declare function stripToolUseMarkers(response: string): string;
245
108
 
246
- export { type ToolCallFormat, type ToolConvertTarget, applyDescriptionLimit, convertFromAnthropicFormat, convertFromGoogleFormat, convertOpenAIToAnthropicFormat, convertOpenAIToGoogleFormat, convertToAnthropicFormat, convertToGoogleFormat, convertToolTo, convertToolsTo, detectToolCallFormat, hasToolCalls, parseAnthropicToolCalls, parseGoogleToolCalls, parseOpenAIToolCalls, parseToolCalls };
109
+ export { type ParsedTextTool, convertToToolCallRequest as convertTextToolToRequest, hasAnyXMLToolMarkers, hasFunctionCallMarkers, hasFunctionCallsMarkers, hasToolCallMarkers, hasToolUseMarkers, normalizeToolName, parseAllXMLAsToolCalls, parseAllXMLFormats, parseFunctionCallFormat, parseFunctionCallsFormat, parseToolCallFormat, parseToolUseFormat, stripAllXMLToolMarkers, stripFunctionCallMarkers, stripFunctionCallsMarkers, stripToolCallMarkers, stripToolUseMarkers };
@@ -1,246 +1,109 @@
1
- import { ToolCallRequest, AnthropicToolDefinition, UniversalTool, GoogleToolDefinition, OpenAIToolDefinition } from '@quilltap/plugin-types';
1
+ import { ToolCallRequest } from '@quilltap/plugin-types';
2
2
  export { AnthropicToolDefinition, GoogleToolDefinition, OpenAIToolDefinition, ToolCall, ToolCallRequest, ToolFormatOptions, ToolResult, UniversalTool } from '@quilltap/plugin-types';
3
+ export { T as ToolCallFormat, a as ToolConvertTarget, b as applyDescriptionLimit, c as convertFromAnthropicFormat, d as convertFromGoogleFormat, e as convertOpenAIToAnthropicFormat, f as convertOpenAIToGoogleFormat, g as convertToAnthropicFormat, h as convertToGoogleFormat, i as convertToolTo, j as convertToolsTo, k as detectToolCallFormat, l as hasToolCalls, p as parseAnthropicToolCalls, m as parseGoogleToolCalls, n as parseOpenAIToolCalls, o as parseToolCalls } from '../converters-BPYo8xdH.js';
3
4
 
4
5
  /**
5
- * Tool Call Parsers
6
+ * Text-Based Tool Call Parsers
6
7
  *
7
- * Provider-specific parsers for extracting tool calls from LLM responses.
8
- * Each parser converts from a provider's native format to the standardized
9
- * ToolCallRequest format.
8
+ * Utility functions for parsing spontaneous XML-style tool calls from LLM
9
+ * text responses. These are for models that emit tool-call-like markup in
10
+ * their output instead of using native function calling APIs.
10
11
  *
11
- * @module @quilltap/plugin-utils/tools/parsers
12
- */
13
-
14
- /**
15
- * Supported tool call response formats
16
- */
17
- type ToolCallFormat = 'openai' | 'anthropic' | 'google' | 'auto';
18
- /**
19
- * Parse OpenAI format tool calls from LLM response
20
- *
21
- * Extracts tool calls from OpenAI/Grok API responses which return
22
- * tool_calls in the message object.
23
- *
24
- * Expected response structures:
25
- * - `response.tool_calls` (direct)
26
- * - `response.choices[0].message.tool_calls` (nested)
12
+ * Provider plugins import and compose these utilities to implement their
13
+ * `hasTextToolMarkers`, `parseTextToolCalls`, and `stripTextToolMarkers` methods.
27
14
  *
28
- * @param response - The raw response from provider API
29
- * @returns Array of parsed tool call requests
30
- *
31
- * @example
32
- * ```typescript
33
- * const response = await openai.chat.completions.create({...});
34
- * const toolCalls = parseOpenAIToolCalls(response);
35
- * // Returns: [{ name: 'search_web', arguments: { query: 'hello' } }]
36
- * ```
15
+ * @module @quilltap/plugin-utils/tools/text-parsers
37
16
  */
38
- declare function parseOpenAIToolCalls(response: unknown): ToolCallRequest[];
39
- /**
40
- * Parse Anthropic format tool calls from LLM response
41
- *
42
- * Extracts tool calls from Anthropic API responses which return
43
- * tool_use blocks in the content array.
44
- *
45
- * Expected response structure:
46
- * - `response.content` array with `{ type: 'tool_use', name, input }`
47
- *
48
- * @param response - The raw response from provider API
49
- * @returns Array of parsed tool call requests
50
- *
51
- * @example
52
- * ```typescript
53
- * const response = await anthropic.messages.create({...});
54
- * const toolCalls = parseAnthropicToolCalls(response);
55
- * // Returns: [{ name: 'search_web', arguments: { query: 'hello' } }]
56
- * ```
57
- */
58
- declare function parseAnthropicToolCalls(response: unknown): ToolCallRequest[];
59
- /**
60
- * Parse Google Gemini format tool calls from LLM response
61
- *
62
- * Extracts tool calls from Google Gemini API responses which return
63
- * functionCall objects in the parts array.
64
- *
65
- * Expected response structure:
66
- * - `response.candidates[0].content.parts` array with `{ functionCall: { name, args } }`
67
- *
68
- * @param response - The raw response from provider API
69
- * @returns Array of parsed tool call requests
70
- *
71
- * @example
72
- * ```typescript
73
- * const response = await gemini.generateContent({...});
74
- * const toolCalls = parseGoogleToolCalls(response);
75
- * // Returns: [{ name: 'search_web', arguments: { query: 'hello' } }]
76
- * ```
77
- */
78
- declare function parseGoogleToolCalls(response: unknown): ToolCallRequest[];
79
- /**
80
- * Detect the format of a tool call response
81
- *
82
- * Analyzes the response structure to determine which provider format it uses.
83
- *
84
- * @param response - The raw response from a provider API
85
- * @returns The detected format, or null if unrecognized
86
- */
87
- declare function detectToolCallFormat(response: unknown): ToolCallFormat | null;
88
- /**
89
- * Parse tool calls with auto-detection or explicit format
90
- *
91
- * A unified parser that can either auto-detect the response format
92
- * or use a specified format. This is useful when you're not sure
93
- * which provider's response you're handling.
94
- *
95
- * @param response - The raw response from a provider API
96
- * @param format - The format to use: 'openai', 'anthropic', 'google', or 'auto'
97
- * @returns Array of parsed tool call requests
98
- *
99
- * @example
100
- * ```typescript
101
- * // Auto-detect format
102
- * const toolCalls = parseToolCalls(response, 'auto');
103
- *
104
- * // Or specify format explicitly
105
- * const toolCalls = parseToolCalls(response, 'openai');
106
- * ```
107
- */
108
- declare function parseToolCalls(response: unknown, format?: ToolCallFormat): ToolCallRequest[];
109
- /**
110
- * Check if a response contains tool calls
111
- *
112
- * Quick check to determine if a response has any tool calls
113
- * without fully parsing them.
114
- *
115
- * @param response - The raw response from a provider API
116
- * @returns True if the response contains tool calls
117
- */
118
- declare function hasToolCalls(response: unknown): boolean;
119
17
 
120
18
  /**
121
- * Tool Format Converters
122
- *
123
- * Utilities for converting between different provider tool formats.
124
- * The universal format (OpenAI-style) serves as the baseline for all conversions.
125
- *
126
- * @module @quilltap/plugin-utils/tools/converters
19
+ * Parsed text-based tool call from LLM output
127
20
  */
128
-
21
+ interface ParsedTextTool {
22
+ /** The tool name */
23
+ toolName: string;
24
+ /** Arguments extracted from the markup */
25
+ arguments: Record<string, unknown>;
26
+ /** The full matched markup text (for stripping) */
27
+ fullMatch: string;
28
+ /** Start index in the original text */
29
+ startIndex: number;
30
+ /** End index in the original text */
31
+ endIndex: number;
32
+ /** Which format was detected */
33
+ format: 'deepseek' | 'claude' | 'generic' | 'function_call' | 'tool_use';
34
+ }
129
35
  /**
130
- * Convert OpenAI/Universal format tool to Anthropic format
131
- *
132
- * Anthropic uses a tool_use format with:
133
- * - name: string
134
- * - description: string
135
- * - input_schema: JSON schema object
136
- *
137
- * @param tool - Universal tool or OpenAI tool definition
138
- * @returns Tool formatted for Anthropic's tool_use
139
- *
140
- * @example
141
- * ```typescript
142
- * const anthropicTool = convertToAnthropicFormat(universalTool);
143
- * // Returns: {
144
- * // name: 'search_web',
145
- * // description: 'Search the web',
146
- * // input_schema: {
147
- * // type: 'object',
148
- * // properties: { query: { type: 'string' } },
149
- * // required: ['query']
150
- * // }
151
- * // }
152
- * ```
36
+ * Normalize a tool name from hallucinated markup to the canonical name.
37
+ * Returns the original name if no alias is found (passes through unknown tools).
153
38
  */
154
- declare function convertToAnthropicFormat(tool: UniversalTool | OpenAIToolDefinition): AnthropicToolDefinition;
39
+ declare function normalizeToolName(name: string): string;
155
40
  /**
156
- * Convert OpenAI/Universal format tool to Google Gemini format
41
+ * Convert a ParsedTextTool to the standard ToolCallRequest format.
157
42
  *
158
- * Google uses a function calling format with:
159
- * - name: string
160
- * - description: string
161
- * - parameters: JSON schema object
162
- *
163
- * @param tool - Universal tool or OpenAI tool definition
164
- * @returns Tool formatted for Google's functionCall
165
- *
166
- * @example
167
- * ```typescript
168
- * const googleTool = convertToGoogleFormat(universalTool);
169
- * // Returns: {
170
- * // name: 'search_web',
171
- * // description: 'Search the web',
172
- * // parameters: {
173
- * // type: 'object',
174
- * // properties: { query: { type: 'string' } },
175
- * // required: ['query']
176
- * // }
177
- * // }
178
- * ```
43
+ * For well-known tools, normalizes argument names (e.g., "search" → "query").
44
+ * For unknown tools, passes arguments through as-is.
179
45
  */
180
- declare function convertToGoogleFormat(tool: UniversalTool | OpenAIToolDefinition): GoogleToolDefinition;
46
+ declare function convertToToolCallRequest(parsed: ParsedTextTool): ToolCallRequest;
181
47
  /**
182
- * Convert Anthropic format tool to Universal/OpenAI format
183
- *
184
- * @param tool - Anthropic format tool
185
- * @returns Tool in universal OpenAI format
48
+ * Parse `<function_calls><invoke name="...">` format (DeepSeek and Claude-style)
186
49
  */
187
- declare function convertFromAnthropicFormat(tool: AnthropicToolDefinition): UniversalTool;
50
+ declare function parseFunctionCallsFormat(response: string): ParsedTextTool[];
188
51
  /**
189
- * Convert Google format tool to Universal/OpenAI format
190
- *
191
- * @param tool - Google format tool
192
- * @returns Tool in universal OpenAI format
52
+ * Parse `<tool_call>` format (generic XML)
193
53
  */
194
- declare function convertFromGoogleFormat(tool: GoogleToolDefinition): UniversalTool;
54
+ declare function parseToolCallFormat(response: string): ParsedTextTool[];
195
55
  /**
196
- * Apply prompt/description length limit to a tool
197
- *
198
- * Modifies a tool's description if it exceeds maxBytes, appending a warning
199
- * that the description was truncated. This is useful for providers with
200
- * strict token limits.
201
- *
202
- * @param tool - Tool object (any format) with a description property
203
- * @param maxBytes - Maximum bytes allowed for description (including warning)
204
- * @returns Modified tool with truncated description if needed
205
- *
206
- * @example
207
- * ```typescript
208
- * const limitedTool = applyDescriptionLimit(tool, 500);
209
- * // If description > 500 bytes, truncates and adds warning
210
- * ```
56
+ * Parse `<function_call name="...">` format
211
57
  */
212
- declare function applyDescriptionLimit<T extends {
213
- description: string;
214
- }>(tool: T, maxBytes: number): T;
58
+ declare function parseFunctionCallFormat(response: string): ParsedTextTool[];
215
59
  /**
216
- * Target format for tool conversion
60
+ * Parse `<tool_use>` format (Gemini and others)
61
+ *
62
+ * Handles multiple sub-formats:
63
+ * - Bare JSON: `<tool_use>{"name":"fn","input":{...}}</tool_use>`
64
+ * - XML children: `<tool_use><name>fn</name><arguments>...</arguments></tool_use>`
65
+ * - JSON in arguments: `<tool_use><name>fn</name><arguments>{"q":"v"}</arguments></tool_use>`
66
+ * - Attributed: `<tool_use name="fn"><arguments>...</arguments></tool_use>`
217
67
  */
218
- type ToolConvertTarget = 'openai' | 'anthropic' | 'google';
68
+ declare function parseToolUseFormat(response: string): ParsedTextTool[];
219
69
  /**
220
- * Convert a universal tool to a specific provider format
70
+ * Parse all known XML tool call formats from response text.
71
+ * Deduplicates by position and sorts by start index.
221
72
  *
222
- * @param tool - Universal tool or OpenAI tool definition
223
- * @param target - Target provider format
224
- * @returns Tool in the target format
73
+ * Plugins can call this directly or compose individual format parsers
74
+ * for provider-specific behavior.
225
75
  */
226
- declare function convertToolTo(tool: UniversalTool | OpenAIToolDefinition, target: ToolConvertTarget): UniversalTool | OpenAIToolDefinition | AnthropicToolDefinition | GoogleToolDefinition;
76
+ declare function parseAllXMLFormats(response: string): ParsedTextTool[];
227
77
  /**
228
- * Convert multiple tools to a specific provider format
229
- *
230
- * @param tools - Array of universal tools or OpenAI tool definitions
231
- * @param target - Target provider format
232
- * @returns Array of tools in the target format
78
+ * Convert parsed text tools to standard ToolCallRequest array.
79
+ * Convenience wrapper for plugins implementing parseTextToolCalls.
233
80
  */
234
- declare function convertToolsTo(tools: Array<UniversalTool | OpenAIToolDefinition>, target: ToolConvertTarget): Array<UniversalTool | OpenAIToolDefinition | AnthropicToolDefinition | GoogleToolDefinition>;
81
+ declare function parseAllXMLAsToolCalls(response: string): ToolCallRequest[];
235
82
  /**
236
- * Alias for convertToAnthropicFormat
237
- * @deprecated Use convertToAnthropicFormat instead
83
+ * Check if text contains any of the known XML tool call patterns.
84
+ * Quick regex check before full parsing.
238
85
  */
239
- declare const convertOpenAIToAnthropicFormat: typeof convertToAnthropicFormat;
86
+ declare function hasAnyXMLToolMarkers(response: string): boolean;
87
+ /** Check for `<function_calls>` markers (DeepSeek/Claude-style) */
88
+ declare function hasFunctionCallsMarkers(response: string): boolean;
89
+ /** Check for `<tool_call>` markers (generic) */
90
+ declare function hasToolCallMarkers(response: string): boolean;
91
+ /** Check for `<function_call>` markers */
92
+ declare function hasFunctionCallMarkers(response: string): boolean;
93
+ /** Check for `<tool_use>` markers (Gemini-style) */
94
+ declare function hasToolUseMarkers(response: string): boolean;
240
95
  /**
241
- * Alias for convertToGoogleFormat
242
- * @deprecated Use convertToGoogleFormat instead
96
+ * Strip all known XML tool call markers from text.
97
+ * Cleans up whitespace left behind.
243
98
  */
244
- declare const convertOpenAIToGoogleFormat: typeof convertToGoogleFormat;
99
+ declare function stripAllXMLToolMarkers(response: string): string;
100
+ /** Strip `<function_calls>` blocks */
101
+ declare function stripFunctionCallsMarkers(response: string): string;
102
+ /** Strip `<tool_call>` blocks */
103
+ declare function stripToolCallMarkers(response: string): string;
104
+ /** Strip `<function_call>` blocks */
105
+ declare function stripFunctionCallMarkers(response: string): string;
106
+ /** Strip `<tool_use>` blocks */
107
+ declare function stripToolUseMarkers(response: string): string;
245
108
 
246
- export { type ToolCallFormat, type ToolConvertTarget, applyDescriptionLimit, convertFromAnthropicFormat, convertFromGoogleFormat, convertOpenAIToAnthropicFormat, convertOpenAIToGoogleFormat, convertToAnthropicFormat, convertToGoogleFormat, convertToolTo, convertToolsTo, detectToolCallFormat, hasToolCalls, parseAnthropicToolCalls, parseGoogleToolCalls, parseOpenAIToolCalls, parseToolCalls };
109
+ export { type ParsedTextTool, convertToToolCallRequest as convertTextToolToRequest, hasAnyXMLToolMarkers, hasFunctionCallMarkers, hasFunctionCallsMarkers, hasToolCallMarkers, hasToolUseMarkers, normalizeToolName, parseAllXMLAsToolCalls, parseAllXMLFormats, parseFunctionCallFormat, parseFunctionCallsFormat, parseToolCallFormat, parseToolUseFormat, stripAllXMLToolMarkers, stripFunctionCallMarkers, stripFunctionCallsMarkers, stripToolCallMarkers, stripToolUseMarkers };