@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.
- package/dist/converters-BPYo8xdH.d.mts +245 -0
- package/dist/converters-BPYo8xdH.d.ts +245 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +58 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -10
- package/dist/index.mjs.map +1 -1
- package/dist/providers/index.js +54 -8
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/index.mjs +54 -8
- package/dist/providers/index.mjs.map +1 -1
- package/dist/tools/index.d.mts +76 -213
- package/dist/tools/index.d.ts +76 -213
- package/dist/tools/index.js +342 -4
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/index.mjs +323 -3
- package/dist/tools/index.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { ToolCallRequest, AnthropicToolDefinition, UniversalTool, GoogleToolDefinition, OpenAIToolDefinition } from '@quilltap/plugin-types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Tool Call Parsers
|
|
5
|
+
*
|
|
6
|
+
* Provider-specific parsers for extracting tool calls from LLM responses.
|
|
7
|
+
* Each parser converts from a provider's native format to the standardized
|
|
8
|
+
* ToolCallRequest format.
|
|
9
|
+
*
|
|
10
|
+
* @module @quilltap/plugin-utils/tools/parsers
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Supported tool call response formats
|
|
15
|
+
*/
|
|
16
|
+
type ToolCallFormat = 'openai' | 'anthropic' | 'google' | 'auto';
|
|
17
|
+
/**
|
|
18
|
+
* Parse OpenAI format tool calls from LLM response
|
|
19
|
+
*
|
|
20
|
+
* Extracts tool calls from OpenAI/Grok API responses which return
|
|
21
|
+
* tool_calls in the message object.
|
|
22
|
+
*
|
|
23
|
+
* Expected response structures:
|
|
24
|
+
* - `response.tool_calls` (direct)
|
|
25
|
+
* - `response.choices[0].message.tool_calls` (nested)
|
|
26
|
+
*
|
|
27
|
+
* @param response - The raw response from provider API
|
|
28
|
+
* @returns Array of parsed tool call requests
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const response = await openai.chat.completions.create({...});
|
|
33
|
+
* const toolCalls = parseOpenAIToolCalls(response);
|
|
34
|
+
* // Returns: [{ name: 'search_web', arguments: { query: 'hello' } }]
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
declare function parseOpenAIToolCalls(response: unknown): ToolCallRequest[];
|
|
38
|
+
/**
|
|
39
|
+
* Parse Anthropic format tool calls from LLM response
|
|
40
|
+
*
|
|
41
|
+
* Extracts tool calls from Anthropic API responses which return
|
|
42
|
+
* tool_use blocks in the content array.
|
|
43
|
+
*
|
|
44
|
+
* Expected response structure:
|
|
45
|
+
* - `response.content` array with `{ type: 'tool_use', name, input }`
|
|
46
|
+
*
|
|
47
|
+
* @param response - The raw response from provider API
|
|
48
|
+
* @returns Array of parsed tool call requests
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const response = await anthropic.messages.create({...});
|
|
53
|
+
* const toolCalls = parseAnthropicToolCalls(response);
|
|
54
|
+
* // Returns: [{ name: 'search_web', arguments: { query: 'hello' } }]
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare function parseAnthropicToolCalls(response: unknown): ToolCallRequest[];
|
|
58
|
+
/**
|
|
59
|
+
* Parse Google Gemini format tool calls from LLM response
|
|
60
|
+
*
|
|
61
|
+
* Extracts tool calls from Google Gemini API responses which return
|
|
62
|
+
* functionCall objects in the parts array.
|
|
63
|
+
*
|
|
64
|
+
* Expected response structure:
|
|
65
|
+
* - `response.candidates[0].content.parts` array with `{ functionCall: { name, args } }`
|
|
66
|
+
*
|
|
67
|
+
* @param response - The raw response from provider API
|
|
68
|
+
* @returns Array of parsed tool call requests
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const response = await gemini.generateContent({...});
|
|
73
|
+
* const toolCalls = parseGoogleToolCalls(response);
|
|
74
|
+
* // Returns: [{ name: 'search_web', arguments: { query: 'hello' } }]
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare function parseGoogleToolCalls(response: unknown): ToolCallRequest[];
|
|
78
|
+
/**
|
|
79
|
+
* Detect the format of a tool call response
|
|
80
|
+
*
|
|
81
|
+
* Analyzes the response structure to determine which provider format it uses.
|
|
82
|
+
*
|
|
83
|
+
* @param response - The raw response from a provider API
|
|
84
|
+
* @returns The detected format, or null if unrecognized
|
|
85
|
+
*/
|
|
86
|
+
declare function detectToolCallFormat(response: unknown): ToolCallFormat | null;
|
|
87
|
+
/**
|
|
88
|
+
* Parse tool calls with auto-detection or explicit format
|
|
89
|
+
*
|
|
90
|
+
* A unified parser that can either auto-detect the response format
|
|
91
|
+
* or use a specified format. This is useful when you're not sure
|
|
92
|
+
* which provider's response you're handling.
|
|
93
|
+
*
|
|
94
|
+
* @param response - The raw response from a provider API
|
|
95
|
+
* @param format - The format to use: 'openai', 'anthropic', 'google', or 'auto'
|
|
96
|
+
* @returns Array of parsed tool call requests
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* // Auto-detect format
|
|
101
|
+
* const toolCalls = parseToolCalls(response, 'auto');
|
|
102
|
+
*
|
|
103
|
+
* // Or specify format explicitly
|
|
104
|
+
* const toolCalls = parseToolCalls(response, 'openai');
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
declare function parseToolCalls(response: unknown, format?: ToolCallFormat): ToolCallRequest[];
|
|
108
|
+
/**
|
|
109
|
+
* Check if a response contains tool calls
|
|
110
|
+
*
|
|
111
|
+
* Quick check to determine if a response has any tool calls
|
|
112
|
+
* without fully parsing them.
|
|
113
|
+
*
|
|
114
|
+
* @param response - The raw response from a provider API
|
|
115
|
+
* @returns True if the response contains tool calls
|
|
116
|
+
*/
|
|
117
|
+
declare function hasToolCalls(response: unknown): boolean;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Tool Format Converters
|
|
121
|
+
*
|
|
122
|
+
* Utilities for converting between different provider tool formats.
|
|
123
|
+
* The universal format (OpenAI-style) serves as the baseline for all conversions.
|
|
124
|
+
*
|
|
125
|
+
* @module @quilltap/plugin-utils/tools/converters
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Convert OpenAI/Universal format tool to Anthropic format
|
|
130
|
+
*
|
|
131
|
+
* Anthropic uses a tool_use format with:
|
|
132
|
+
* - name: string
|
|
133
|
+
* - description: string
|
|
134
|
+
* - input_schema: JSON schema object
|
|
135
|
+
*
|
|
136
|
+
* @param tool - Universal tool or OpenAI tool definition
|
|
137
|
+
* @returns Tool formatted for Anthropic's tool_use
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* const anthropicTool = convertToAnthropicFormat(universalTool);
|
|
142
|
+
* // Returns: {
|
|
143
|
+
* // name: 'search_web',
|
|
144
|
+
* // description: 'Search the web',
|
|
145
|
+
* // input_schema: {
|
|
146
|
+
* // type: 'object',
|
|
147
|
+
* // properties: { query: { type: 'string' } },
|
|
148
|
+
* // required: ['query']
|
|
149
|
+
* // }
|
|
150
|
+
* // }
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
declare function convertToAnthropicFormat(tool: UniversalTool | OpenAIToolDefinition): AnthropicToolDefinition;
|
|
154
|
+
/**
|
|
155
|
+
* Convert OpenAI/Universal format tool to Google Gemini format
|
|
156
|
+
*
|
|
157
|
+
* Google uses a function calling format with:
|
|
158
|
+
* - name: string
|
|
159
|
+
* - description: string
|
|
160
|
+
* - parameters: JSON schema object
|
|
161
|
+
*
|
|
162
|
+
* @param tool - Universal tool or OpenAI tool definition
|
|
163
|
+
* @returns Tool formatted for Google's functionCall
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* const googleTool = convertToGoogleFormat(universalTool);
|
|
168
|
+
* // Returns: {
|
|
169
|
+
* // name: 'search_web',
|
|
170
|
+
* // description: 'Search the web',
|
|
171
|
+
* // parameters: {
|
|
172
|
+
* // type: 'object',
|
|
173
|
+
* // properties: { query: { type: 'string' } },
|
|
174
|
+
* // required: ['query']
|
|
175
|
+
* // }
|
|
176
|
+
* // }
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
declare function convertToGoogleFormat(tool: UniversalTool | OpenAIToolDefinition): GoogleToolDefinition;
|
|
180
|
+
/**
|
|
181
|
+
* Convert Anthropic format tool to Universal/OpenAI format
|
|
182
|
+
*
|
|
183
|
+
* @param tool - Anthropic format tool
|
|
184
|
+
* @returns Tool in universal OpenAI format
|
|
185
|
+
*/
|
|
186
|
+
declare function convertFromAnthropicFormat(tool: AnthropicToolDefinition): UniversalTool;
|
|
187
|
+
/**
|
|
188
|
+
* Convert Google format tool to Universal/OpenAI format
|
|
189
|
+
*
|
|
190
|
+
* @param tool - Google format tool
|
|
191
|
+
* @returns Tool in universal OpenAI format
|
|
192
|
+
*/
|
|
193
|
+
declare function convertFromGoogleFormat(tool: GoogleToolDefinition): UniversalTool;
|
|
194
|
+
/**
|
|
195
|
+
* Apply prompt/description length limit to a tool
|
|
196
|
+
*
|
|
197
|
+
* Modifies a tool's description if it exceeds maxBytes, appending a warning
|
|
198
|
+
* that the description was truncated. This is useful for providers with
|
|
199
|
+
* strict token limits.
|
|
200
|
+
*
|
|
201
|
+
* @param tool - Tool object (any format) with a description property
|
|
202
|
+
* @param maxBytes - Maximum bytes allowed for description (including warning)
|
|
203
|
+
* @returns Modified tool with truncated description if needed
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* const limitedTool = applyDescriptionLimit(tool, 500);
|
|
208
|
+
* // If description > 500 bytes, truncates and adds warning
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
declare function applyDescriptionLimit<T extends {
|
|
212
|
+
description: string;
|
|
213
|
+
}>(tool: T, maxBytes: number): T;
|
|
214
|
+
/**
|
|
215
|
+
* Target format for tool conversion
|
|
216
|
+
*/
|
|
217
|
+
type ToolConvertTarget = 'openai' | 'anthropic' | 'google';
|
|
218
|
+
/**
|
|
219
|
+
* Convert a universal tool to a specific provider format
|
|
220
|
+
*
|
|
221
|
+
* @param tool - Universal tool or OpenAI tool definition
|
|
222
|
+
* @param target - Target provider format
|
|
223
|
+
* @returns Tool in the target format
|
|
224
|
+
*/
|
|
225
|
+
declare function convertToolTo(tool: UniversalTool | OpenAIToolDefinition, target: ToolConvertTarget): UniversalTool | OpenAIToolDefinition | AnthropicToolDefinition | GoogleToolDefinition;
|
|
226
|
+
/**
|
|
227
|
+
* Convert multiple tools to a specific provider format
|
|
228
|
+
*
|
|
229
|
+
* @param tools - Array of universal tools or OpenAI tool definitions
|
|
230
|
+
* @param target - Target provider format
|
|
231
|
+
* @returns Array of tools in the target format
|
|
232
|
+
*/
|
|
233
|
+
declare function convertToolsTo(tools: Array<UniversalTool | OpenAIToolDefinition>, target: ToolConvertTarget): Array<UniversalTool | OpenAIToolDefinition | AnthropicToolDefinition | GoogleToolDefinition>;
|
|
234
|
+
/**
|
|
235
|
+
* Alias for convertToAnthropicFormat
|
|
236
|
+
* @deprecated Use convertToAnthropicFormat instead
|
|
237
|
+
*/
|
|
238
|
+
declare const convertOpenAIToAnthropicFormat: typeof convertToAnthropicFormat;
|
|
239
|
+
/**
|
|
240
|
+
* Alias for convertToGoogleFormat
|
|
241
|
+
* @deprecated Use convertToGoogleFormat instead
|
|
242
|
+
*/
|
|
243
|
+
declare const convertOpenAIToGoogleFormat: typeof convertToGoogleFormat;
|
|
244
|
+
|
|
245
|
+
export { type ToolCallFormat as T, type ToolConvertTarget as a, applyDescriptionLimit as b, convertFromAnthropicFormat as c, convertFromGoogleFormat as d, convertOpenAIToAnthropicFormat as e, convertOpenAIToGoogleFormat as f, convertToAnthropicFormat as g, convertToGoogleFormat as h, convertToolTo as i, convertToolsTo as j, detectToolCallFormat as k, hasToolCalls as l, parseGoogleToolCalls as m, parseOpenAIToolCalls as n, parseToolCalls as o, parseAnthropicToolCalls as p };
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { ToolCallRequest, AnthropicToolDefinition, UniversalTool, GoogleToolDefinition, OpenAIToolDefinition } from '@quilltap/plugin-types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Tool Call Parsers
|
|
5
|
+
*
|
|
6
|
+
* Provider-specific parsers for extracting tool calls from LLM responses.
|
|
7
|
+
* Each parser converts from a provider's native format to the standardized
|
|
8
|
+
* ToolCallRequest format.
|
|
9
|
+
*
|
|
10
|
+
* @module @quilltap/plugin-utils/tools/parsers
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Supported tool call response formats
|
|
15
|
+
*/
|
|
16
|
+
type ToolCallFormat = 'openai' | 'anthropic' | 'google' | 'auto';
|
|
17
|
+
/**
|
|
18
|
+
* Parse OpenAI format tool calls from LLM response
|
|
19
|
+
*
|
|
20
|
+
* Extracts tool calls from OpenAI/Grok API responses which return
|
|
21
|
+
* tool_calls in the message object.
|
|
22
|
+
*
|
|
23
|
+
* Expected response structures:
|
|
24
|
+
* - `response.tool_calls` (direct)
|
|
25
|
+
* - `response.choices[0].message.tool_calls` (nested)
|
|
26
|
+
*
|
|
27
|
+
* @param response - The raw response from provider API
|
|
28
|
+
* @returns Array of parsed tool call requests
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const response = await openai.chat.completions.create({...});
|
|
33
|
+
* const toolCalls = parseOpenAIToolCalls(response);
|
|
34
|
+
* // Returns: [{ name: 'search_web', arguments: { query: 'hello' } }]
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
declare function parseOpenAIToolCalls(response: unknown): ToolCallRequest[];
|
|
38
|
+
/**
|
|
39
|
+
* Parse Anthropic format tool calls from LLM response
|
|
40
|
+
*
|
|
41
|
+
* Extracts tool calls from Anthropic API responses which return
|
|
42
|
+
* tool_use blocks in the content array.
|
|
43
|
+
*
|
|
44
|
+
* Expected response structure:
|
|
45
|
+
* - `response.content` array with `{ type: 'tool_use', name, input }`
|
|
46
|
+
*
|
|
47
|
+
* @param response - The raw response from provider API
|
|
48
|
+
* @returns Array of parsed tool call requests
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const response = await anthropic.messages.create({...});
|
|
53
|
+
* const toolCalls = parseAnthropicToolCalls(response);
|
|
54
|
+
* // Returns: [{ name: 'search_web', arguments: { query: 'hello' } }]
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare function parseAnthropicToolCalls(response: unknown): ToolCallRequest[];
|
|
58
|
+
/**
|
|
59
|
+
* Parse Google Gemini format tool calls from LLM response
|
|
60
|
+
*
|
|
61
|
+
* Extracts tool calls from Google Gemini API responses which return
|
|
62
|
+
* functionCall objects in the parts array.
|
|
63
|
+
*
|
|
64
|
+
* Expected response structure:
|
|
65
|
+
* - `response.candidates[0].content.parts` array with `{ functionCall: { name, args } }`
|
|
66
|
+
*
|
|
67
|
+
* @param response - The raw response from provider API
|
|
68
|
+
* @returns Array of parsed tool call requests
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const response = await gemini.generateContent({...});
|
|
73
|
+
* const toolCalls = parseGoogleToolCalls(response);
|
|
74
|
+
* // Returns: [{ name: 'search_web', arguments: { query: 'hello' } }]
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare function parseGoogleToolCalls(response: unknown): ToolCallRequest[];
|
|
78
|
+
/**
|
|
79
|
+
* Detect the format of a tool call response
|
|
80
|
+
*
|
|
81
|
+
* Analyzes the response structure to determine which provider format it uses.
|
|
82
|
+
*
|
|
83
|
+
* @param response - The raw response from a provider API
|
|
84
|
+
* @returns The detected format, or null if unrecognized
|
|
85
|
+
*/
|
|
86
|
+
declare function detectToolCallFormat(response: unknown): ToolCallFormat | null;
|
|
87
|
+
/**
|
|
88
|
+
* Parse tool calls with auto-detection or explicit format
|
|
89
|
+
*
|
|
90
|
+
* A unified parser that can either auto-detect the response format
|
|
91
|
+
* or use a specified format. This is useful when you're not sure
|
|
92
|
+
* which provider's response you're handling.
|
|
93
|
+
*
|
|
94
|
+
* @param response - The raw response from a provider API
|
|
95
|
+
* @param format - The format to use: 'openai', 'anthropic', 'google', or 'auto'
|
|
96
|
+
* @returns Array of parsed tool call requests
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* // Auto-detect format
|
|
101
|
+
* const toolCalls = parseToolCalls(response, 'auto');
|
|
102
|
+
*
|
|
103
|
+
* // Or specify format explicitly
|
|
104
|
+
* const toolCalls = parseToolCalls(response, 'openai');
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
declare function parseToolCalls(response: unknown, format?: ToolCallFormat): ToolCallRequest[];
|
|
108
|
+
/**
|
|
109
|
+
* Check if a response contains tool calls
|
|
110
|
+
*
|
|
111
|
+
* Quick check to determine if a response has any tool calls
|
|
112
|
+
* without fully parsing them.
|
|
113
|
+
*
|
|
114
|
+
* @param response - The raw response from a provider API
|
|
115
|
+
* @returns True if the response contains tool calls
|
|
116
|
+
*/
|
|
117
|
+
declare function hasToolCalls(response: unknown): boolean;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Tool Format Converters
|
|
121
|
+
*
|
|
122
|
+
* Utilities for converting between different provider tool formats.
|
|
123
|
+
* The universal format (OpenAI-style) serves as the baseline for all conversions.
|
|
124
|
+
*
|
|
125
|
+
* @module @quilltap/plugin-utils/tools/converters
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Convert OpenAI/Universal format tool to Anthropic format
|
|
130
|
+
*
|
|
131
|
+
* Anthropic uses a tool_use format with:
|
|
132
|
+
* - name: string
|
|
133
|
+
* - description: string
|
|
134
|
+
* - input_schema: JSON schema object
|
|
135
|
+
*
|
|
136
|
+
* @param tool - Universal tool or OpenAI tool definition
|
|
137
|
+
* @returns Tool formatted for Anthropic's tool_use
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* const anthropicTool = convertToAnthropicFormat(universalTool);
|
|
142
|
+
* // Returns: {
|
|
143
|
+
* // name: 'search_web',
|
|
144
|
+
* // description: 'Search the web',
|
|
145
|
+
* // input_schema: {
|
|
146
|
+
* // type: 'object',
|
|
147
|
+
* // properties: { query: { type: 'string' } },
|
|
148
|
+
* // required: ['query']
|
|
149
|
+
* // }
|
|
150
|
+
* // }
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
declare function convertToAnthropicFormat(tool: UniversalTool | OpenAIToolDefinition): AnthropicToolDefinition;
|
|
154
|
+
/**
|
|
155
|
+
* Convert OpenAI/Universal format tool to Google Gemini format
|
|
156
|
+
*
|
|
157
|
+
* Google uses a function calling format with:
|
|
158
|
+
* - name: string
|
|
159
|
+
* - description: string
|
|
160
|
+
* - parameters: JSON schema object
|
|
161
|
+
*
|
|
162
|
+
* @param tool - Universal tool or OpenAI tool definition
|
|
163
|
+
* @returns Tool formatted for Google's functionCall
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* const googleTool = convertToGoogleFormat(universalTool);
|
|
168
|
+
* // Returns: {
|
|
169
|
+
* // name: 'search_web',
|
|
170
|
+
* // description: 'Search the web',
|
|
171
|
+
* // parameters: {
|
|
172
|
+
* // type: 'object',
|
|
173
|
+
* // properties: { query: { type: 'string' } },
|
|
174
|
+
* // required: ['query']
|
|
175
|
+
* // }
|
|
176
|
+
* // }
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
declare function convertToGoogleFormat(tool: UniversalTool | OpenAIToolDefinition): GoogleToolDefinition;
|
|
180
|
+
/**
|
|
181
|
+
* Convert Anthropic format tool to Universal/OpenAI format
|
|
182
|
+
*
|
|
183
|
+
* @param tool - Anthropic format tool
|
|
184
|
+
* @returns Tool in universal OpenAI format
|
|
185
|
+
*/
|
|
186
|
+
declare function convertFromAnthropicFormat(tool: AnthropicToolDefinition): UniversalTool;
|
|
187
|
+
/**
|
|
188
|
+
* Convert Google format tool to Universal/OpenAI format
|
|
189
|
+
*
|
|
190
|
+
* @param tool - Google format tool
|
|
191
|
+
* @returns Tool in universal OpenAI format
|
|
192
|
+
*/
|
|
193
|
+
declare function convertFromGoogleFormat(tool: GoogleToolDefinition): UniversalTool;
|
|
194
|
+
/**
|
|
195
|
+
* Apply prompt/description length limit to a tool
|
|
196
|
+
*
|
|
197
|
+
* Modifies a tool's description if it exceeds maxBytes, appending a warning
|
|
198
|
+
* that the description was truncated. This is useful for providers with
|
|
199
|
+
* strict token limits.
|
|
200
|
+
*
|
|
201
|
+
* @param tool - Tool object (any format) with a description property
|
|
202
|
+
* @param maxBytes - Maximum bytes allowed for description (including warning)
|
|
203
|
+
* @returns Modified tool with truncated description if needed
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* const limitedTool = applyDescriptionLimit(tool, 500);
|
|
208
|
+
* // If description > 500 bytes, truncates and adds warning
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
declare function applyDescriptionLimit<T extends {
|
|
212
|
+
description: string;
|
|
213
|
+
}>(tool: T, maxBytes: number): T;
|
|
214
|
+
/**
|
|
215
|
+
* Target format for tool conversion
|
|
216
|
+
*/
|
|
217
|
+
type ToolConvertTarget = 'openai' | 'anthropic' | 'google';
|
|
218
|
+
/**
|
|
219
|
+
* Convert a universal tool to a specific provider format
|
|
220
|
+
*
|
|
221
|
+
* @param tool - Universal tool or OpenAI tool definition
|
|
222
|
+
* @param target - Target provider format
|
|
223
|
+
* @returns Tool in the target format
|
|
224
|
+
*/
|
|
225
|
+
declare function convertToolTo(tool: UniversalTool | OpenAIToolDefinition, target: ToolConvertTarget): UniversalTool | OpenAIToolDefinition | AnthropicToolDefinition | GoogleToolDefinition;
|
|
226
|
+
/**
|
|
227
|
+
* Convert multiple tools to a specific provider format
|
|
228
|
+
*
|
|
229
|
+
* @param tools - Array of universal tools or OpenAI tool definitions
|
|
230
|
+
* @param target - Target provider format
|
|
231
|
+
* @returns Array of tools in the target format
|
|
232
|
+
*/
|
|
233
|
+
declare function convertToolsTo(tools: Array<UniversalTool | OpenAIToolDefinition>, target: ToolConvertTarget): Array<UniversalTool | OpenAIToolDefinition | AnthropicToolDefinition | GoogleToolDefinition>;
|
|
234
|
+
/**
|
|
235
|
+
* Alias for convertToAnthropicFormat
|
|
236
|
+
* @deprecated Use convertToAnthropicFormat instead
|
|
237
|
+
*/
|
|
238
|
+
declare const convertOpenAIToAnthropicFormat: typeof convertToAnthropicFormat;
|
|
239
|
+
/**
|
|
240
|
+
* Alias for convertToGoogleFormat
|
|
241
|
+
* @deprecated Use convertToGoogleFormat instead
|
|
242
|
+
*/
|
|
243
|
+
declare const convertOpenAIToGoogleFormat: typeof convertToGoogleFormat;
|
|
244
|
+
|
|
245
|
+
export { type ToolCallFormat as T, type ToolConvertTarget as a, applyDescriptionLimit as b, convertFromAnthropicFormat as c, convertFromGoogleFormat as d, convertOpenAIToAnthropicFormat as e, convertOpenAIToGoogleFormat as f, convertToAnthropicFormat as g, convertToGoogleFormat as h, convertToolTo as i, convertToolsTo as j, detectToolCallFormat as k, hasToolCalls as l, parseGoogleToolCalls as m, parseOpenAIToolCalls as n, parseToolCalls as o, parseAnthropicToolCalls as p };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { AnthropicToolDefinition, GoogleToolDefinition, LogContext, LogLevel, OpenAIToolDefinition, PluginLogger, ToolCall, ToolCallRequest, ToolFormatOptions, ToolResult, UniversalTool, createConsoleLogger, createNoopLogger } from '@quilltap/plugin-types';
|
|
2
|
-
export { ToolCallFormat, ToolConvertTarget, applyDescriptionLimit, convertFromAnthropicFormat, convertFromGoogleFormat, convertOpenAIToAnthropicFormat, convertOpenAIToGoogleFormat, convertToAnthropicFormat, convertToGoogleFormat, convertToolTo, convertToolsTo, detectToolCallFormat, hasToolCalls, parseAnthropicToolCalls, parseGoogleToolCalls, parseOpenAIToolCalls, parseToolCalls } from './
|
|
2
|
+
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
3
|
export { PluginLoggerWithChild, __clearCoreLoggerFactory, __injectCoreLoggerFactory, createPluginLogger, getLogLevelFromEnv, hasCoreLogger } from './logging/index.mjs';
|
|
4
4
|
export { OpenAICompatibleProvider, OpenAICompatibleProviderConfig } from './providers/index.mjs';
|
|
5
5
|
export { CreateRoleplayTemplatePluginOptions, CreateSingleTemplatePluginOptions, createRoleplayTemplatePlugin, createSingleTemplatePlugin, validateRoleplayTemplatePlugin, validateTemplateConfig } from './roleplay-templates/index.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { AnthropicToolDefinition, GoogleToolDefinition, LogContext, LogLevel, OpenAIToolDefinition, PluginLogger, ToolCall, ToolCallRequest, ToolFormatOptions, ToolResult, UniversalTool, createConsoleLogger, createNoopLogger } from '@quilltap/plugin-types';
|
|
2
|
-
export { ToolCallFormat, ToolConvertTarget, applyDescriptionLimit, convertFromAnthropicFormat, convertFromGoogleFormat, convertOpenAIToAnthropicFormat, convertOpenAIToGoogleFormat, convertToAnthropicFormat, convertToGoogleFormat, convertToolTo, convertToolsTo, detectToolCallFormat, hasToolCalls, parseAnthropicToolCalls, parseGoogleToolCalls, parseOpenAIToolCalls, parseToolCalls } from './
|
|
2
|
+
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
3
|
export { PluginLoggerWithChild, __clearCoreLoggerFactory, __injectCoreLoggerFactory, createPluginLogger, getLogLevelFromEnv, hasCoreLogger } from './logging/index.js';
|
|
4
4
|
export { OpenAICompatibleProvider, OpenAICompatibleProviderConfig } from './providers/index.js';
|
|
5
5
|
export { CreateRoleplayTemplatePluginOptions, CreateSingleTemplatePluginOptions, createRoleplayTemplatePlugin, createSingleTemplatePlugin, validateRoleplayTemplatePlugin, validateTemplateConfig } from './roleplay-templates/index.js';
|
package/dist/index.js
CHANGED
|
@@ -95,7 +95,8 @@ function parseOpenAIToolCalls(response) {
|
|
|
95
95
|
try {
|
|
96
96
|
toolCalls.push({
|
|
97
97
|
name: tc.function.name,
|
|
98
|
-
arguments: JSON.parse(argsStr)
|
|
98
|
+
arguments: JSON.parse(argsStr),
|
|
99
|
+
callId: tc.id || void 0
|
|
99
100
|
});
|
|
100
101
|
} catch {
|
|
101
102
|
continue;
|
|
@@ -120,7 +121,8 @@ function parseAnthropicToolCalls(response) {
|
|
|
120
121
|
if (b.type === "tool_use" && b.name) {
|
|
121
122
|
toolCalls.push({
|
|
122
123
|
name: b.name,
|
|
123
|
-
arguments: b.input || {}
|
|
124
|
+
arguments: b.input || {},
|
|
125
|
+
callId: b.id || void 0
|
|
124
126
|
});
|
|
125
127
|
}
|
|
126
128
|
}
|
|
@@ -458,10 +460,33 @@ var OpenAICompatibleProvider = class {
|
|
|
458
460
|
apiKey: this.getEffectiveApiKey(apiKey),
|
|
459
461
|
baseURL: this.baseUrl
|
|
460
462
|
});
|
|
461
|
-
const messages = params.messages.filter((m) =>
|
|
462
|
-
role
|
|
463
|
-
|
|
464
|
-
}))
|
|
463
|
+
const messages = params.messages.filter((m) => {
|
|
464
|
+
if (m.role === "tool" && !m.toolCallId) return false;
|
|
465
|
+
return true;
|
|
466
|
+
}).map((m) => {
|
|
467
|
+
if (m.role === "tool" && m.toolCallId) {
|
|
468
|
+
return {
|
|
469
|
+
role: "tool",
|
|
470
|
+
tool_call_id: m.toolCallId,
|
|
471
|
+
content: m.content
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
if (m.role === "assistant" && m.toolCalls && m.toolCalls.length > 0) {
|
|
475
|
+
return {
|
|
476
|
+
role: "assistant",
|
|
477
|
+
content: m.content || null,
|
|
478
|
+
tool_calls: m.toolCalls.map((tc) => ({
|
|
479
|
+
id: tc.id,
|
|
480
|
+
type: tc.type,
|
|
481
|
+
function: tc.function
|
|
482
|
+
}))
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
return {
|
|
486
|
+
role: m.role,
|
|
487
|
+
content: m.content
|
|
488
|
+
};
|
|
489
|
+
});
|
|
465
490
|
try {
|
|
466
491
|
const response = await client.chat.completions.create({
|
|
467
492
|
model: params.model,
|
|
@@ -506,10 +531,33 @@ var OpenAICompatibleProvider = class {
|
|
|
506
531
|
apiKey: this.getEffectiveApiKey(apiKey),
|
|
507
532
|
baseURL: this.baseUrl
|
|
508
533
|
});
|
|
509
|
-
const messages = params.messages.filter((m) =>
|
|
510
|
-
role
|
|
511
|
-
|
|
512
|
-
}))
|
|
534
|
+
const messages = params.messages.filter((m) => {
|
|
535
|
+
if (m.role === "tool" && !m.toolCallId) return false;
|
|
536
|
+
return true;
|
|
537
|
+
}).map((m) => {
|
|
538
|
+
if (m.role === "tool" && m.toolCallId) {
|
|
539
|
+
return {
|
|
540
|
+
role: "tool",
|
|
541
|
+
tool_call_id: m.toolCallId,
|
|
542
|
+
content: m.content
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
if (m.role === "assistant" && m.toolCalls && m.toolCalls.length > 0) {
|
|
546
|
+
return {
|
|
547
|
+
role: "assistant",
|
|
548
|
+
content: m.content || null,
|
|
549
|
+
tool_calls: m.toolCalls.map((tc) => ({
|
|
550
|
+
id: tc.id,
|
|
551
|
+
type: tc.type,
|
|
552
|
+
function: tc.function
|
|
553
|
+
}))
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
return {
|
|
557
|
+
role: m.role,
|
|
558
|
+
content: m.content
|
|
559
|
+
};
|
|
560
|
+
});
|
|
513
561
|
try {
|
|
514
562
|
const stream = await client.chat.completions.create({
|
|
515
563
|
model: params.model,
|