@agnt-sdk/studio 0.0.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/README.md +162 -0
- package/dist/AgntExecutor.d.ts +56 -0
- package/dist/AgntExecutor.d.ts.map +1 -0
- package/dist/AgntExecutor.js +117 -0
- package/dist/AgntExecutor.js.map +1 -0
- package/dist/BaseExecutor.d.ts +69 -0
- package/dist/BaseExecutor.d.ts.map +1 -0
- package/dist/BaseExecutor.js +528 -0
- package/dist/BaseExecutor.js.map +1 -0
- package/dist/ImageCache.d.ts +94 -0
- package/dist/ImageCache.d.ts.map +1 -0
- package/dist/ImageCache.js +232 -0
- package/dist/ImageCache.js.map +1 -0
- package/dist/cli/commands/init.d.ts +5 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +47 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/pull.d.ts +10 -0
- package/dist/cli/commands/pull.d.ts.map +1 -0
- package/dist/cli/commands/pull.js +82 -0
- package/dist/cli/commands/pull.js.map +1 -0
- package/dist/cli/index.d.ts +6 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +28 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/utils/api.d.ts +38 -0
- package/dist/cli/utils/api.d.ts.map +1 -0
- package/dist/cli/utils/api.js +44 -0
- package/dist/cli/utils/api.js.map +1 -0
- package/dist/cli/utils/config.d.ts +5 -0
- package/dist/cli/utils/config.d.ts.map +1 -0
- package/dist/cli/utils/config.js +5 -0
- package/dist/cli/utils/config.js.map +1 -0
- package/dist/conditions.d.ts +14 -0
- package/dist/conditions.d.ts.map +1 -0
- package/dist/conditions.js +59 -0
- package/dist/conditions.js.map +1 -0
- package/dist/executorFactory.d.ts +10 -0
- package/dist/executorFactory.d.ts.map +1 -0
- package/dist/executorFactory.js +45 -0
- package/dist/executorFactory.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/anthropic.d.ts +22 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +280 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/bedrock.d.ts +23 -0
- package/dist/providers/bedrock.d.ts.map +1 -0
- package/dist/providers/bedrock.js +281 -0
- package/dist/providers/bedrock.js.map +1 -0
- package/dist/providers/deepseek.d.ts +22 -0
- package/dist/providers/deepseek.d.ts.map +1 -0
- package/dist/providers/deepseek.js +193 -0
- package/dist/providers/deepseek.js.map +1 -0
- package/dist/providers/google.d.ts +22 -0
- package/dist/providers/google.d.ts.map +1 -0
- package/dist/providers/google.js +357 -0
- package/dist/providers/google.js.map +1 -0
- package/dist/providers/openai.d.ts +22 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +194 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/systemTools.d.ts +6 -0
- package/dist/systemTools.d.ts.map +1 -0
- package/dist/systemTools.js +15 -0
- package/dist/systemTools.js.map +1 -0
- package/dist/tracing.d.ts +32 -0
- package/dist/tracing.d.ts.map +1 -0
- package/dist/tracing.js +38 -0
- package/dist/tracing.js.map +1 -0
- package/dist/types.d.ts +280 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GoogleExecutor - Provider adapter for Google Gemini models
|
|
3
|
+
*
|
|
4
|
+
* Uses native @google/generative-ai SDK
|
|
5
|
+
*/
|
|
6
|
+
import { GoogleGenerativeAI } from '@google/generative-ai';
|
|
7
|
+
import BaseExecutor from '../BaseExecutor.js';
|
|
8
|
+
export default class GoogleExecutor extends BaseExecutor {
|
|
9
|
+
client;
|
|
10
|
+
constructor(config) {
|
|
11
|
+
super(config);
|
|
12
|
+
// Get Google credentials
|
|
13
|
+
const googleCreds = this.credentials.google;
|
|
14
|
+
if (!googleCreds) {
|
|
15
|
+
throw new Error('[GoogleExecutor] credentials.google is required');
|
|
16
|
+
}
|
|
17
|
+
if (!googleCreds.apiKey) {
|
|
18
|
+
throw new Error('[GoogleExecutor] credentials.google.apiKey is required');
|
|
19
|
+
}
|
|
20
|
+
// Browser safety check
|
|
21
|
+
const isBrowser = typeof globalThis !== 'undefined' &&
|
|
22
|
+
typeof globalThis.window !== 'undefined';
|
|
23
|
+
if (isBrowser && !googleCreds.dangerouslyAllowBrowser) {
|
|
24
|
+
throw new Error('[GoogleExecutor] Using API keys in the browser is unsafe. ' +
|
|
25
|
+
'Set dangerouslyAllowBrowser: true in credentials.google to acknowledge the risk.');
|
|
26
|
+
}
|
|
27
|
+
// Initialize Google client
|
|
28
|
+
this.client = new GoogleGenerativeAI(googleCreds.apiKey);
|
|
29
|
+
this.log(`[GoogleExecutor] Initialized with model: ${this.model}`);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Invoke Google Gemini API
|
|
33
|
+
* Returns: { message: { role, content, tool_calls }, usage: { input_tokens, output_tokens } }
|
|
34
|
+
*/
|
|
35
|
+
async invoke(messages, options = {}) {
|
|
36
|
+
// Extract provider-specific parameters from model config
|
|
37
|
+
const providerParams = this.#extractProviderParams();
|
|
38
|
+
// Format messages for Gemini (separate system from conversation)
|
|
39
|
+
const { systemInstruction, contents } = this.#formatMessages(messages);
|
|
40
|
+
// Build model config
|
|
41
|
+
const modelConfig = {
|
|
42
|
+
...providerParams
|
|
43
|
+
};
|
|
44
|
+
// Add tools if provided
|
|
45
|
+
if (options.tools && options.tools.length > 0) {
|
|
46
|
+
const tools = this.#formatTools(options.tools);
|
|
47
|
+
modelConfig.tools = tools;
|
|
48
|
+
// Handle tool_choice
|
|
49
|
+
if (options.tool_choice === 'required') {
|
|
50
|
+
// Gemini doesn't have a direct equivalent to "required"
|
|
51
|
+
// We'll use function calling mode ANY
|
|
52
|
+
modelConfig.toolConfig = {
|
|
53
|
+
functionCallingConfig: {
|
|
54
|
+
mode: 'ANY'
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Get generative model
|
|
60
|
+
const model = this.client.getGenerativeModel({
|
|
61
|
+
model: this.model,
|
|
62
|
+
systemInstruction,
|
|
63
|
+
...modelConfig
|
|
64
|
+
});
|
|
65
|
+
this.log('[GoogleExecutor] Invoking:', {
|
|
66
|
+
model: this.model,
|
|
67
|
+
temperature: providerParams.temperature,
|
|
68
|
+
topP: providerParams.topP,
|
|
69
|
+
tools: options.tools?.length || 0
|
|
70
|
+
});
|
|
71
|
+
// Call Gemini API
|
|
72
|
+
const result = await model.generateContent({
|
|
73
|
+
contents
|
|
74
|
+
});
|
|
75
|
+
const response = result.response;
|
|
76
|
+
const candidate = response.candidates?.[0];
|
|
77
|
+
if (!candidate) {
|
|
78
|
+
throw new Error('[GoogleExecutor] No candidate in response');
|
|
79
|
+
}
|
|
80
|
+
// Extract content and tool calls
|
|
81
|
+
const textContent = this.#extractTextContent(candidate.content);
|
|
82
|
+
const toolCalls = this.#extractToolCalls(candidate.content);
|
|
83
|
+
// Extract usage
|
|
84
|
+
// Include thoughtsTokenCount (Gemini 2.5+) in output tokens since it's generated reasoning
|
|
85
|
+
const metadata = response.usageMetadata;
|
|
86
|
+
const thoughtsTokens = metadata?.thoughtsTokenCount || 0;
|
|
87
|
+
const usage = {
|
|
88
|
+
input_tokens: response.usageMetadata?.promptTokenCount || 0,
|
|
89
|
+
output_tokens: (response.usageMetadata?.candidatesTokenCount || 0) + thoughtsTokens
|
|
90
|
+
};
|
|
91
|
+
// Format response to match expected structure
|
|
92
|
+
return {
|
|
93
|
+
message: {
|
|
94
|
+
role: 'assistant',
|
|
95
|
+
content: textContent,
|
|
96
|
+
tool_calls: toolCalls
|
|
97
|
+
},
|
|
98
|
+
usage
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Check if message has tool calls
|
|
103
|
+
*/
|
|
104
|
+
hasToolCalls(message) {
|
|
105
|
+
return Boolean(message?.tool_calls && message.tool_calls.length > 0);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Format messages for Gemini API
|
|
109
|
+
* Gemini expects: systemInstruction (string) + contents (Content[])
|
|
110
|
+
* Content = { role: 'user' | 'model', parts: Part[] }
|
|
111
|
+
*/
|
|
112
|
+
#formatMessages(messages) {
|
|
113
|
+
const systemMessages = messages.filter(m => m.role === 'system');
|
|
114
|
+
const systemInstruction = systemMessages.map(m => m.content).join('\n\n');
|
|
115
|
+
const contents = [];
|
|
116
|
+
for (const msg of messages) {
|
|
117
|
+
// Skip system messages (handled separately)
|
|
118
|
+
if (msg.role === 'system') {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
// Handle tool messages
|
|
122
|
+
if (msg.role === 'tool') {
|
|
123
|
+
// For Google, tool_call_id IS the function name (we set id = name in extractToolCalls)
|
|
124
|
+
const toolName = msg.tool_call_id || msg.name || 'unknown';
|
|
125
|
+
// Tool results go into a 'function' part with a 'functionResponse'
|
|
126
|
+
contents.push({
|
|
127
|
+
role: 'function',
|
|
128
|
+
parts: [
|
|
129
|
+
{
|
|
130
|
+
functionResponse: {
|
|
131
|
+
name: toolName,
|
|
132
|
+
response: JSON.parse(msg.content)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
});
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
// Handle assistant messages with tool_calls
|
|
140
|
+
if (msg.role === 'assistant' && msg.tool_calls && msg.tool_calls.length > 0) {
|
|
141
|
+
const parts = [];
|
|
142
|
+
// Add text content if present
|
|
143
|
+
if (msg.content) {
|
|
144
|
+
parts.push({
|
|
145
|
+
text: typeof msg.content === 'string' ? msg.content : JSON.stringify(msg.content)
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
// Add function calls
|
|
149
|
+
for (const toolCall of msg.tool_calls) {
|
|
150
|
+
parts.push({
|
|
151
|
+
functionCall: {
|
|
152
|
+
name: toolCall.name,
|
|
153
|
+
args: toolCall.args
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
contents.push({
|
|
158
|
+
role: 'model',
|
|
159
|
+
parts
|
|
160
|
+
});
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
// Handle regular user/assistant messages
|
|
164
|
+
const role = msg.role === 'assistant' ? 'model' : 'user';
|
|
165
|
+
if (typeof msg.content === 'string') {
|
|
166
|
+
contents.push({
|
|
167
|
+
role,
|
|
168
|
+
parts: [{ text: msg.content }]
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
else if (Array.isArray(msg.content)) {
|
|
172
|
+
// Handle multimodal content
|
|
173
|
+
const parts = this.#formatMultimodalContent(msg.content);
|
|
174
|
+
contents.push({
|
|
175
|
+
role,
|
|
176
|
+
parts
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
systemInstruction: systemInstruction || undefined,
|
|
182
|
+
contents
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Format multimodal content (text + images)
|
|
187
|
+
*/
|
|
188
|
+
#formatMultimodalContent(content) {
|
|
189
|
+
const parts = [];
|
|
190
|
+
for (const item of content) {
|
|
191
|
+
if (item.type === 'text') {
|
|
192
|
+
parts.push({ text: item.text });
|
|
193
|
+
}
|
|
194
|
+
else if (item.type === 'image_url') {
|
|
195
|
+
// Gemini expects inline data
|
|
196
|
+
const imageUrl = item.image_url?.url || item.image_url;
|
|
197
|
+
if (imageUrl.startsWith('data:')) {
|
|
198
|
+
// Extract base64 data
|
|
199
|
+
const match = imageUrl.match(/^data:([^;]+);base64,(.+)$/);
|
|
200
|
+
if (match) {
|
|
201
|
+
parts.push({
|
|
202
|
+
inlineData: {
|
|
203
|
+
mimeType: match[1],
|
|
204
|
+
data: match[2]
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return parts;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Format tools for Gemini
|
|
215
|
+
* Gemini expects: { functionDeclarations: FunctionDeclaration[] }[]
|
|
216
|
+
*/
|
|
217
|
+
#formatTools(tools) {
|
|
218
|
+
const functionDeclarations = [];
|
|
219
|
+
for (const tool of tools) {
|
|
220
|
+
let functionDef;
|
|
221
|
+
// OpenAI format: { type: "function", function: { name, description, parameters } }
|
|
222
|
+
if (tool.type === 'function' && tool.function) {
|
|
223
|
+
functionDef = {
|
|
224
|
+
name: tool.function.name,
|
|
225
|
+
description: tool.function.description || '',
|
|
226
|
+
parameters: this.#cleanParametersForGemini(tool.function.parameters)
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
// Anthropic format: { name, description, input_schema }
|
|
230
|
+
else if (tool.input_schema) {
|
|
231
|
+
functionDef = {
|
|
232
|
+
name: tool.name,
|
|
233
|
+
description: tool.description || '',
|
|
234
|
+
parameters: this.#cleanParametersForGemini(tool.input_schema)
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
// Studio format: { name, description, parameters }
|
|
238
|
+
else if (tool.parameters) {
|
|
239
|
+
functionDef = {
|
|
240
|
+
name: tool.name,
|
|
241
|
+
description: tool.description || '',
|
|
242
|
+
parameters: this.#cleanParametersForGemini(tool.parameters)
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
if (functionDef) {
|
|
246
|
+
functionDeclarations.push(functionDef);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return [{ functionDeclarations }];
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Clean parameters to only include fields Gemini supports
|
|
253
|
+
* Uses whitelist approach for standard JSON Schema fields
|
|
254
|
+
*/
|
|
255
|
+
#cleanParametersForGemini(parameters) {
|
|
256
|
+
if (!parameters || typeof parameters !== 'object') {
|
|
257
|
+
return parameters;
|
|
258
|
+
}
|
|
259
|
+
// Handle arrays
|
|
260
|
+
if (Array.isArray(parameters)) {
|
|
261
|
+
return parameters.map(item => this.#cleanParametersForGemini(item));
|
|
262
|
+
}
|
|
263
|
+
// Whitelist of JSON Schema fields that Gemini supports
|
|
264
|
+
// NOTE: Gemini has strict limits on schema complexity. We only include
|
|
265
|
+
// the most basic fields to avoid "too many states" errors.
|
|
266
|
+
// Excluded: format, minimum, maximum, minLength, maxLength, pattern, minItems, maxItems
|
|
267
|
+
// These create constraints that can exceed Gemini's serving limits.
|
|
268
|
+
const allowedFields = [
|
|
269
|
+
'type',
|
|
270
|
+
'properties',
|
|
271
|
+
'required',
|
|
272
|
+
'description',
|
|
273
|
+
'items',
|
|
274
|
+
'enum',
|
|
275
|
+
'default',
|
|
276
|
+
'nullable',
|
|
277
|
+
'anyOf',
|
|
278
|
+
'allOf',
|
|
279
|
+
'oneOf'
|
|
280
|
+
];
|
|
281
|
+
const cleaned = {};
|
|
282
|
+
for (const key of allowedFields) {
|
|
283
|
+
if (key in parameters) {
|
|
284
|
+
// Recursively clean nested objects (properties, items, etc.)
|
|
285
|
+
if (key === 'properties' && typeof parameters[key] === 'object') {
|
|
286
|
+
cleaned[key] = {};
|
|
287
|
+
for (const propKey in parameters[key]) {
|
|
288
|
+
const cleanedProp = this.#cleanParametersForGemini(parameters[key][propKey]);
|
|
289
|
+
// Only include property if it has at least one field after cleaning
|
|
290
|
+
if (cleanedProp && typeof cleanedProp === 'object' && Object.keys(cleanedProp).length > 0) {
|
|
291
|
+
cleaned[key][propKey] = cleanedProp;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
else if (key === 'items' && typeof parameters[key] === 'object') {
|
|
296
|
+
cleaned[key] = this.#cleanParametersForGemini(parameters[key]);
|
|
297
|
+
}
|
|
298
|
+
else if ((key === 'anyOf' || key === 'allOf' || key === 'oneOf') && Array.isArray(parameters[key])) {
|
|
299
|
+
cleaned[key] = parameters[key].map((item) => this.#cleanParametersForGemini(item));
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
cleaned[key] = parameters[key];
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
// Filter the 'required' array to only include properties that exist in cleaned.properties
|
|
307
|
+
// This prevents Gemini errors when required references non-existent properties
|
|
308
|
+
if (cleaned.required && Array.isArray(cleaned.required) && cleaned.properties) {
|
|
309
|
+
cleaned.required = cleaned.required.filter((propName) => propName in cleaned.properties);
|
|
310
|
+
// Remove required array if it's empty
|
|
311
|
+
if (cleaned.required.length === 0) {
|
|
312
|
+
delete cleaned.required;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return cleaned;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Extract text content from Gemini response
|
|
319
|
+
*/
|
|
320
|
+
#extractTextContent(content) {
|
|
321
|
+
if (!content.parts || content.parts.length === 0) {
|
|
322
|
+
return '';
|
|
323
|
+
}
|
|
324
|
+
const textParts = content.parts
|
|
325
|
+
.filter(part => 'text' in part)
|
|
326
|
+
.map(part => part.text);
|
|
327
|
+
return textParts.join('');
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Extract tool calls from Gemini response
|
|
331
|
+
*/
|
|
332
|
+
#extractToolCalls(content) {
|
|
333
|
+
if (!content.parts || content.parts.length === 0) {
|
|
334
|
+
return [];
|
|
335
|
+
}
|
|
336
|
+
const toolCalls = [];
|
|
337
|
+
for (const part of content.parts) {
|
|
338
|
+
if ('functionCall' in part && part.functionCall) {
|
|
339
|
+
toolCalls.push({
|
|
340
|
+
id: part.functionCall.name, // Use function name as ID since Google doesn't provide IDs
|
|
341
|
+
name: part.functionCall.name,
|
|
342
|
+
args: part.functionCall.args || {}
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return toolCalls;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Extract provider-specific parameters from model config
|
|
350
|
+
*/
|
|
351
|
+
#extractProviderParams() {
|
|
352
|
+
const metadata = this.primaryModelConfig.metadata || {};
|
|
353
|
+
const { displayName, ...providerParams } = metadata;
|
|
354
|
+
return providerParams;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
//# sourceMappingURL=google.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google.js","sourceRoot":"","sources":["../../src/providers/google.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,kBAAkB,EAA4C,MAAM,uBAAuB,CAAC;AACrG,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAG9C,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,YAAY;IAC9C,MAAM,CAAqB;IAEnC,YAAY,MAA0B;QACpC,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,yBAAyB;QACzB,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;QAC5C,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACrE,CAAC;QACD,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;QAC5E,CAAC;QAED,uBAAuB;QACvB,MAAM,SAAS,GAAG,OAAO,UAAU,KAAK,WAAW;YACjC,OAAQ,UAAkB,CAAC,MAAM,KAAK,WAAW,CAAC;QACpE,IAAI,SAAS,IAAI,CAAC,WAAW,CAAC,uBAAuB,EAAE,CAAC;YACtD,MAAM,IAAI,KAAK,CACb,4DAA4D;gBAC5D,kFAAkF,CACnF,CAAC;QACJ,CAAC;QAED,2BAA2B;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,kBAAkB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAEzD,IAAI,CAAC,GAAG,CAAC,4CA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5B,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;YACjC,IAAI,cAAc,IAAI,IAAI,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;gBAChD,SAAS,CAAC,IAAI,CAAC;oBACb,EAAE,EAAE,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,2DAA2D;oBACvF,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,IAAI;oBAC5B,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,IAAI,IAAI,EAAE;iBACnC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,sBAAsB;QACpB,MAAM,QAAQ,GAAI,IAAI,CAAC,kBAA0B,CAAC,QAAQ,IAAI,EAAE,CAAC;QACjE,MAAM,EAAE,WAAW,EAAE,GAAG,cAAc,EAAE,GAAG,QAAQ,CAAC;QACpD,OAAO,cAAc,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAIExecutor - Provider adapter for OpenAI models
|
|
3
|
+
*
|
|
4
|
+
* Uses native openai SDK (not LangChain)
|
|
5
|
+
*/
|
|
6
|
+
import BaseExecutor from '../BaseExecutor.js';
|
|
7
|
+
import type { BaseExecutorConfig, Message, InvokeOptions, InvokeResult } from '../types.js';
|
|
8
|
+
export default class OpenAIExecutor extends BaseExecutor {
|
|
9
|
+
#private;
|
|
10
|
+
private client;
|
|
11
|
+
constructor(config: BaseExecutorConfig);
|
|
12
|
+
/**
|
|
13
|
+
* Invoke OpenAI API
|
|
14
|
+
* Returns: { message: { role, content, tool_calls }, usage: { input_tokens, output_tokens } }
|
|
15
|
+
*/
|
|
16
|
+
invoke(messages: Message[], options?: InvokeOptions): Promise<InvokeResult>;
|
|
17
|
+
/**
|
|
18
|
+
* Check if message has tool calls
|
|
19
|
+
*/
|
|
20
|
+
hasToolCalls(message: Message): boolean;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/providers/openai.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE5F,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,YAAY;;IACtD,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,kBAAkB;IAqBtC;;;OAGG;IACG,MAAM,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IAiDrF;;OAEG;IACH,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO;CAoIxC"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAIExecutor - Provider adapter for OpenAI models
|
|
3
|
+
*
|
|
4
|
+
* Uses native openai SDK (not LangChain)
|
|
5
|
+
*/
|
|
6
|
+
import OpenAI from 'openai';
|
|
7
|
+
import BaseExecutor from '../BaseExecutor.js';
|
|
8
|
+
export default class OpenAIExecutor extends BaseExecutor {
|
|
9
|
+
client;
|
|
10
|
+
constructor(config) {
|
|
11
|
+
super(config);
|
|
12
|
+
// Get OpenAI credentials
|
|
13
|
+
const openaiCreds = this.credentials.openai;
|
|
14
|
+
if (!openaiCreds) {
|
|
15
|
+
throw new Error('[OpenAIExecutor] credentials.openai is required');
|
|
16
|
+
}
|
|
17
|
+
if (!openaiCreds.apiKey) {
|
|
18
|
+
throw new Error('[OpenAIExecutor] credentials.openai.apiKey is required');
|
|
19
|
+
}
|
|
20
|
+
// Initialize OpenAI client
|
|
21
|
+
this.client = new OpenAI({
|
|
22
|
+
apiKey: openaiCreds.apiKey,
|
|
23
|
+
dangerouslyAllowBrowser: openaiCreds.dangerouslyAllowBrowser
|
|
24
|
+
});
|
|
25
|
+
this.log(`[OpenAIExecutor] Initialized with model: ${this.model}`);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Invoke OpenAI API
|
|
29
|
+
* Returns: { message: { role, content, tool_calls }, usage: { input_tokens, output_tokens } }
|
|
30
|
+
*/
|
|
31
|
+
async invoke(messages, options = {}) {
|
|
32
|
+
// Build request parameters
|
|
33
|
+
const params = {
|
|
34
|
+
model: this.model,
|
|
35
|
+
messages: this.#formatMessages(messages),
|
|
36
|
+
};
|
|
37
|
+
// Add all provider-specific parameters from model config
|
|
38
|
+
// This passes through any OpenAI API params: temperature, top_p, reasoning, etc.
|
|
39
|
+
const providerParams = this.#extractProviderParams();
|
|
40
|
+
Object.assign(params, providerParams);
|
|
41
|
+
// Add tools if provided
|
|
42
|
+
if (options.tools && options.tools.length > 0) {
|
|
43
|
+
params.tools = options.tools.map(t => this.#formatTool(t));
|
|
44
|
+
}
|
|
45
|
+
// Add tool_choice if specified
|
|
46
|
+
if (options.tool_choice && options.tool_choice !== 'auto') {
|
|
47
|
+
params.tool_choice = this.#formatToolChoice(options.tool_choice);
|
|
48
|
+
}
|
|
49
|
+
this.log('[OpenAIExecutor] Invoking:', {
|
|
50
|
+
model: params.model,
|
|
51
|
+
temperature: params.temperature,
|
|
52
|
+
top_p: params.top_p,
|
|
53
|
+
tools: params.tools?.length || 0
|
|
54
|
+
});
|
|
55
|
+
// Call OpenAI API
|
|
56
|
+
const response = await this.client.chat.completions.create(params);
|
|
57
|
+
const choice = response.choices[0];
|
|
58
|
+
const message = choice.message;
|
|
59
|
+
// Format response to match expected structure
|
|
60
|
+
return {
|
|
61
|
+
message: {
|
|
62
|
+
role: message.role,
|
|
63
|
+
content: message.content || '',
|
|
64
|
+
tool_calls: this.#extractToolCalls(message.tool_calls)
|
|
65
|
+
},
|
|
66
|
+
usage: {
|
|
67
|
+
input_tokens: response.usage.prompt_tokens,
|
|
68
|
+
output_tokens: response.usage.completion_tokens
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Check if message has tool calls
|
|
74
|
+
*/
|
|
75
|
+
hasToolCalls(message) {
|
|
76
|
+
return Boolean(message?.tool_calls && message.tool_calls.length > 0);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Format messages for OpenAI API
|
|
80
|
+
*/
|
|
81
|
+
#formatMessages(messages) {
|
|
82
|
+
return messages.map(msg => {
|
|
83
|
+
// Handle tool messages
|
|
84
|
+
if (msg.role === 'tool') {
|
|
85
|
+
return {
|
|
86
|
+
role: 'tool',
|
|
87
|
+
tool_call_id: msg.tool_call_id,
|
|
88
|
+
content: msg.content
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// Handle regular messages
|
|
92
|
+
return {
|
|
93
|
+
role: msg.role,
|
|
94
|
+
content: msg.content
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Format tool definition for OpenAI
|
|
100
|
+
* OpenAI expects: { type: "function", function: { name, description, parameters } }
|
|
101
|
+
*/
|
|
102
|
+
#formatTool(tool) {
|
|
103
|
+
// Already in OpenAI format: { type: "function", function: { name, description, parameters } }
|
|
104
|
+
if (tool.type === 'function' && tool.function) {
|
|
105
|
+
return tool;
|
|
106
|
+
}
|
|
107
|
+
// If has function field but no type (partial OpenAI format)
|
|
108
|
+
if (tool.function) {
|
|
109
|
+
return {
|
|
110
|
+
type: 'function',
|
|
111
|
+
function: tool.function
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
// Anthropic format: { name, description, input_schema } - convert to OpenAI
|
|
115
|
+
if (tool.input_schema) {
|
|
116
|
+
return {
|
|
117
|
+
type: 'function',
|
|
118
|
+
function: {
|
|
119
|
+
name: tool.name,
|
|
120
|
+
description: tool.description || '',
|
|
121
|
+
parameters: tool.input_schema
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
// Studio format: { name, description, parameters } - convert to OpenAI format
|
|
126
|
+
if (tool.parameters) {
|
|
127
|
+
return {
|
|
128
|
+
type: 'function',
|
|
129
|
+
function: {
|
|
130
|
+
name: tool.name,
|
|
131
|
+
description: tool.description || '',
|
|
132
|
+
parameters: tool.parameters
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
// Fallback: wrap in OpenAI format
|
|
137
|
+
this.log('[OpenAIExecutor] Warning: Unrecognized tool format:', JSON.stringify(tool));
|
|
138
|
+
return {
|
|
139
|
+
type: 'function',
|
|
140
|
+
function: {
|
|
141
|
+
name: tool.name || 'unknown',
|
|
142
|
+
description: tool.description || '',
|
|
143
|
+
parameters: tool.parameters || tool.input_schema || { type: 'object', properties: {} }
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Format tool_choice for OpenAI
|
|
149
|
+
*/
|
|
150
|
+
#formatToolChoice(toolChoice) {
|
|
151
|
+
if (typeof toolChoice === 'string') {
|
|
152
|
+
// "required" or "any" -> "required"
|
|
153
|
+
if (toolChoice === 'required' || toolChoice === 'any') {
|
|
154
|
+
return 'required';
|
|
155
|
+
}
|
|
156
|
+
return 'auto';
|
|
157
|
+
}
|
|
158
|
+
// If it's a specific tool: { type: "function", function: { name: "..." } }
|
|
159
|
+
if (toolChoice.type === 'function' || toolChoice.function?.name) {
|
|
160
|
+
return toolChoice;
|
|
161
|
+
}
|
|
162
|
+
// Anthropic format: { type: "tool", name: "..." }
|
|
163
|
+
if (toolChoice.type === 'tool' && toolChoice.name) {
|
|
164
|
+
return {
|
|
165
|
+
type: 'function',
|
|
166
|
+
function: { name: toolChoice.name }
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
return 'auto';
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Extract tool calls from OpenAI response
|
|
173
|
+
*/
|
|
174
|
+
#extractToolCalls(toolCalls) {
|
|
175
|
+
if (!toolCalls || toolCalls.length === 0) {
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
return toolCalls.map(tc => ({
|
|
179
|
+
id: tc.id,
|
|
180
|
+
name: tc.function.name,
|
|
181
|
+
args: JSON.parse(tc.function.arguments)
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Extract provider-specific parameters from model config
|
|
186
|
+
* Excludes displayName, passes rest to OpenAI API
|
|
187
|
+
*/
|
|
188
|
+
#extractProviderParams() {
|
|
189
|
+
const metadata = this.primaryModelConfig.metadata || {};
|
|
190
|
+
const { displayName, ...providerParams } = metadata;
|
|
191
|
+
return providerParams;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=openai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/providers/openai.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAG9C,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,YAAY;IAC9C,MAAM,CAAS;IAEvB,YAAY,MAA0B;QACpC,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,yBAAyB;QACzB,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;QAC5C,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACrE,CAAC;QACD,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;QAC5E,CAAC;QAED,2BAA2B;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC;YACvB,MAAM,EAAE,WAAW,C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 -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* System tool names — tools that are handled natively by the executor/platform.
|
|
3
|
+
* Tool calls NOT in this set are considered 'custom' and may trigger pause/resume.
|
|
4
|
+
*/
|
|
5
|
+
export declare const SYSTEM_TOOL_NAMES: Set<string>;
|
|
6
|
+
//# sourceMappingURL=systemTools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"systemTools.d.ts","sourceRoot":"","sources":["../src/systemTools.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,iBAAiB,aAS5B,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* System tool names — tools that are handled natively by the executor/platform.
|
|
3
|
+
* Tool calls NOT in this set are considered 'custom' and may trigger pause/resume.
|
|
4
|
+
*/
|
|
5
|
+
export const SYSTEM_TOOL_NAMES = new Set([
|
|
6
|
+
'finish_agent_run',
|
|
7
|
+
'output',
|
|
8
|
+
'web_search',
|
|
9
|
+
'get_weather',
|
|
10
|
+
'perform_calculation',
|
|
11
|
+
// Skill plugin tools — resolved at execution time from mounted skills
|
|
12
|
+
'fetch_skills',
|
|
13
|
+
'read_skill',
|
|
14
|
+
]);
|
|
15
|
+
//# sourceMappingURL=systemTools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"systemTools.js","sourceRoot":"","sources":["../src/systemTools.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IACvC,kBAAkB;IAClB,QAAQ;IACR,YAAY;IACZ,aAAa;IACb,qBAAqB;IACrB,sEAAsE;IACtE,cAAc;IACd,YAAY;CACb,CAAC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tracing Utilities
|
|
3
|
+
*
|
|
4
|
+
* Fire-and-forget trace payloads to the observability API.
|
|
5
|
+
*/
|
|
6
|
+
import type { TracingConfig, Message, PromptManifestV2 } from './types.js';
|
|
7
|
+
export interface TracePayload {
|
|
8
|
+
promptName: string;
|
|
9
|
+
manifest: PromptManifestV2;
|
|
10
|
+
etag: string | null;
|
|
11
|
+
variables: Record<string, any>;
|
|
12
|
+
messages: Message[];
|
|
13
|
+
output: any;
|
|
14
|
+
inputTokens: number;
|
|
15
|
+
outputTokens: number;
|
|
16
|
+
totalTokens: number;
|
|
17
|
+
cost: number;
|
|
18
|
+
duration: number;
|
|
19
|
+
model: {
|
|
20
|
+
provider: string;
|
|
21
|
+
name: string;
|
|
22
|
+
metadata: Record<string, any>;
|
|
23
|
+
};
|
|
24
|
+
status: string;
|
|
25
|
+
metadata: Record<string, any>;
|
|
26
|
+
tags: string[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Send trace to observability API (fire-and-forget — does not block execution)
|
|
30
|
+
*/
|
|
31
|
+
export declare function sendTrace(tracing: TracingConfig, payload: TracePayload, log: (message: string, ...args: any[]) => void): Promise<void>;
|
|
32
|
+
//# sourceMappingURL=tracing.d.ts.map
|