@auto-engineer/ai-gateway 0.11.15 → 0.11.17
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +8 -0
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +0 -2
- package/dist/src/config.js.map +1 -1
- package/dist/src/config.specs.js +1 -2
- package/dist/src/config.specs.js.map +1 -1
- package/dist/src/core/constants.d.ts +7 -0
- package/dist/src/core/constants.d.ts.map +1 -0
- package/dist/src/core/constants.js +8 -0
- package/dist/src/core/constants.js.map +1 -0
- package/dist/src/core/context.d.ts +7 -0
- package/dist/src/core/context.d.ts.map +1 -0
- package/dist/src/core/context.js +106 -0
- package/dist/src/core/context.js.map +1 -0
- package/dist/src/core/generators.d.ts +12 -0
- package/dist/src/core/generators.d.ts.map +1 -0
- package/dist/src/core/generators.js +310 -0
- package/dist/src/core/generators.js.map +1 -0
- package/dist/src/core/index.d.ts +8 -0
- package/dist/src/core/index.d.ts.map +1 -0
- package/dist/src/core/index.js +7 -0
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/core/providers/custom.d.ts +3 -0
- package/dist/src/core/providers/custom.d.ts.map +1 -0
- package/dist/src/core/providers/custom.js +9 -0
- package/dist/src/core/providers/custom.js.map +1 -0
- package/dist/src/core/types.d.ts +73 -0
- package/dist/src/core/types.d.ts.map +1 -0
- package/dist/src/core/types.js +9 -0
- package/dist/src/core/types.js.map +1 -0
- package/dist/src/core/utils/errors.d.ts +3 -0
- package/dist/src/core/utils/errors.d.ts.map +1 -0
- package/dist/src/core/utils/errors.js +82 -0
- package/dist/src/core/utils/errors.js.map +1 -0
- package/dist/src/core/utils/log.d.ts +3 -0
- package/dist/src/core/utils/log.d.ts.map +1 -0
- package/dist/src/core/utils/log.js +52 -0
- package/dist/src/core/utils/log.js.map +1 -0
- package/dist/src/core/utils/validation.d.ts +9 -0
- package/dist/src/core/utils/validation.d.ts.map +1 -0
- package/dist/src/core/utils/validation.js +45 -0
- package/dist/src/core/utils/validation.js.map +1 -0
- package/dist/src/index-custom.specs.js +16 -12
- package/dist/src/index-custom.specs.js.map +1 -1
- package/dist/src/index.d.ts +1 -39
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -566
- package/dist/src/index.js.map +1 -1
- package/dist/src/index.specs.js +6 -3
- package/dist/src/index.specs.js.map +1 -1
- package/dist/src/node/config.d.ts +3 -0
- package/dist/src/node/config.d.ts.map +1 -0
- package/dist/src/node/config.js +77 -0
- package/dist/src/node/config.js.map +1 -0
- package/dist/src/node/index.d.ts +11 -0
- package/dist/src/node/index.d.ts.map +1 -0
- package/dist/src/node/index.js +10 -0
- package/dist/src/node/index.js.map +1 -0
- package/dist/src/node/mcp-server.d.ts +50 -0
- package/dist/src/node/mcp-server.d.ts.map +1 -0
- package/dist/src/node/mcp-server.js +176 -0
- package/dist/src/node/mcp-server.js.map +1 -0
- package/dist/src/node/wrappers.d.ts +16 -0
- package/dist/src/node/wrappers.d.ts.map +1 -0
- package/dist/src/node/wrappers.js +100 -0
- package/dist/src/node/wrappers.js.map +1 -0
- package/dist/src/providers/custom.specs.js +1 -1
- package/dist/src/providers/custom.specs.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +19 -3
- package/src/config.specs.ts +1 -2
- package/src/config.ts +0 -2
- package/src/core/constants.ts +8 -0
- package/src/core/context.ts +106 -0
- package/src/core/generators.ts +424 -0
- package/src/core/index.ts +29 -0
- package/src/core/providers/custom.ts +10 -0
- package/src/core/types.ts +81 -0
- package/src/core/utils/errors.ts +91 -0
- package/src/core/utils/log.ts +65 -0
- package/src/core/utils/validation.ts +69 -0
- package/src/index-custom.specs.ts +16 -12
- package/src/index.specs.ts +7 -4
- package/src/index.ts +1 -756
- package/src/node/config.ts +105 -0
- package/src/node/index.ts +60 -0
- package/src/node/mcp-server.ts +261 -0
- package/src/node/wrappers.ts +136 -0
- package/src/providers/custom.specs.ts +2 -2
package/dist/src/index.js
CHANGED
|
@@ -1,567 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { openai } from '@ai-sdk/openai';
|
|
3
|
-
import { anthropic } from '@ai-sdk/anthropic';
|
|
4
|
-
import { google } from '@ai-sdk/google';
|
|
5
|
-
import { xai } from '@ai-sdk/xai';
|
|
6
|
-
import { configureAIProvider } from './config.js';
|
|
7
|
-
import { DEFAULT_MODELS, AIProvider } from './constants.js';
|
|
8
|
-
import { createCustomProvider } from './providers/custom.js';
|
|
9
|
-
export { AIProvider } from './constants.js';
|
|
10
|
-
import { z } from 'zod';
|
|
11
|
-
import { getRegisteredToolsForAI } from './mcp-server.js';
|
|
12
|
-
import { startServer } from './mcp-server.js';
|
|
13
|
-
import createDebug from 'debug';
|
|
14
|
-
// const debug = createDebug('auto:ai-gateway'); // TODO: Use for general debugging
|
|
15
|
-
const debugConfig = createDebug('auto:ai-gateway:config');
|
|
16
|
-
const debugAPI = createDebug('auto:ai-gateway:api');
|
|
17
|
-
const debugError = createDebug('auto:ai-gateway:error');
|
|
18
|
-
const debugTools = createDebug('auto:ai-gateway:tools');
|
|
19
|
-
const debugStream = createDebug('auto:ai-gateway:stream');
|
|
20
|
-
const debugValidation = createDebug('auto:ai-gateway:validation');
|
|
21
|
-
// Error type definitions
|
|
22
|
-
const ERROR_PATTERNS = [
|
|
23
|
-
{
|
|
24
|
-
patterns: ['rate limit', '429'],
|
|
25
|
-
statusCode: 429,
|
|
26
|
-
icon: '⚠️',
|
|
27
|
-
message: 'RATE LIMIT ERROR detected for %s',
|
|
28
|
-
checkRetryAfter: true,
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
patterns: ['401', 'unauthorized'],
|
|
32
|
-
statusCode: 401,
|
|
33
|
-
icon: '🔐',
|
|
34
|
-
message: 'AUTHENTICATION ERROR - Check your %s API key',
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
patterns: ['quota', 'credits', 'insufficient'],
|
|
38
|
-
icon: '💳',
|
|
39
|
-
message: 'QUOTA/CREDITS ERROR - Insufficient credits for %s',
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
patterns: ['model', 'not found'],
|
|
43
|
-
icon: '🤖',
|
|
44
|
-
message: 'MODEL ERROR - Model might not be available for %s',
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
patterns: ['timeout', 'timed out'],
|
|
48
|
-
icon: '⏱️',
|
|
49
|
-
message: 'TIMEOUT ERROR - Request timed out for %s',
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
patterns: ['ECONNREFUSED', 'ENOTFOUND', 'network'],
|
|
53
|
-
icon: '🌐',
|
|
54
|
-
message: 'NETWORK ERROR - Connection failed to %s',
|
|
55
|
-
},
|
|
56
|
-
];
|
|
57
|
-
// Helper to check and log specific error types
|
|
58
|
-
function checkErrorType(message, errorAny, provider) {
|
|
59
|
-
for (const errorType of ERROR_PATTERNS) {
|
|
60
|
-
const hasPattern = errorType.patterns.some((pattern) => message.includes(pattern));
|
|
61
|
-
const hasStatusCode = errorType.statusCode !== undefined && errorAny.status === errorType.statusCode;
|
|
62
|
-
if (hasPattern || hasStatusCode) {
|
|
63
|
-
debugError(`${errorType.icon} ${errorType.message}`, provider);
|
|
64
|
-
if (errorType.checkRetryAfter === true && errorAny.retryAfter !== undefined) {
|
|
65
|
-
debugError('Retry after: %s seconds', String(errorAny.retryAfter));
|
|
66
|
-
}
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
// Helper to extract additional error details
|
|
72
|
-
function extractErrorDetails(errorAny) {
|
|
73
|
-
if (errorAny.response !== undefined && typeof errorAny.response === 'object' && errorAny.response !== null) {
|
|
74
|
-
const response = errorAny.response;
|
|
75
|
-
debugError('Response status: %s', String(response.status ?? 'unknown'));
|
|
76
|
-
debugError('Response status text: %s', String(response.statusText ?? 'unknown'));
|
|
77
|
-
if (response.data !== undefined) {
|
|
78
|
-
debugError('Response data: %o', response.data);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (errorAny.code !== undefined) {
|
|
82
|
-
debugError('Error code: %s', String(errorAny.code));
|
|
83
|
-
}
|
|
84
|
-
if (errorAny.type !== undefined) {
|
|
85
|
-
debugError('Error type: %s', String(errorAny.type));
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Extract and log meaningful error information from Vercel AI SDK errors
|
|
90
|
-
*/
|
|
91
|
-
function extractAndLogError(error, provider, operation) {
|
|
92
|
-
debugError('%s failed for provider %s', operation, provider);
|
|
93
|
-
if (error instanceof Error) {
|
|
94
|
-
debugError('Error message: %s', error.message);
|
|
95
|
-
debugError('Error name: %s', error.name);
|
|
96
|
-
debugError('Error stack: %s', error.stack);
|
|
97
|
-
// Check for specific error types from Vercel AI SDK
|
|
98
|
-
const errorAny = error;
|
|
99
|
-
// Check various error types
|
|
100
|
-
checkErrorType(error.message, errorAny, provider);
|
|
101
|
-
// Extract additional error details if available
|
|
102
|
-
extractErrorDetails(errorAny);
|
|
103
|
-
// Log raw error object for debugging
|
|
104
|
-
debugError('Full error object: %O', error);
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
debugError('Unknown error type: %O', error);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
const defaultOptions = {
|
|
111
|
-
temperature: 0.7,
|
|
112
|
-
maxTokens: 1000,
|
|
113
|
-
};
|
|
114
|
-
export function getDefaultAIProvider() {
|
|
115
|
-
const envProvider = process.env.DEFAULT_AI_PROVIDER?.toLowerCase();
|
|
116
|
-
switch (envProvider) {
|
|
117
|
-
case 'openai':
|
|
118
|
-
return AIProvider.OpenAI;
|
|
119
|
-
case 'anthropic':
|
|
120
|
-
return AIProvider.Anthropic;
|
|
121
|
-
case 'google':
|
|
122
|
-
return AIProvider.Google;
|
|
123
|
-
case 'xai':
|
|
124
|
-
return AIProvider.XAI;
|
|
125
|
-
default: {
|
|
126
|
-
// Fallback to the first available provider
|
|
127
|
-
const available = getAvailableProviders();
|
|
128
|
-
return available.length > 0 ? available[0] : AIProvider.Anthropic;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
export function getDefaultModel(provider) {
|
|
133
|
-
// Check if DEFAULT_AI_MODEL is set in environment
|
|
134
|
-
const envModel = process.env.DEFAULT_AI_MODEL;
|
|
135
|
-
if (envModel !== undefined && envModel !== null && envModel.trim().length > 0) {
|
|
136
|
-
debugConfig('Using DEFAULT_AI_MODEL from environment: %s for provider %s', envModel, provider);
|
|
137
|
-
return envModel.trim();
|
|
138
|
-
}
|
|
139
|
-
if (provider === AIProvider.Custom) {
|
|
140
|
-
const config = configureAIProvider();
|
|
141
|
-
if (config.custom != null) {
|
|
142
|
-
debugConfig('Selected custom provider default model %s for provider %s', config.custom.defaultModel, provider);
|
|
143
|
-
return config.custom.defaultModel;
|
|
144
|
-
}
|
|
145
|
-
throw new Error('Custom provider not configured');
|
|
146
|
-
}
|
|
147
|
-
const model = DEFAULT_MODELS[provider] ??
|
|
148
|
-
(() => {
|
|
149
|
-
throw new Error(`Unknown provider: ${provider}`);
|
|
150
|
-
})();
|
|
151
|
-
debugConfig('Selected default model %s for provider %s', model, provider);
|
|
152
|
-
return model;
|
|
153
|
-
}
|
|
154
|
-
function getModel(provider, model) {
|
|
155
|
-
const modelName = model ?? getDefaultModel(provider);
|
|
156
|
-
debugConfig('Creating model instance for provider %s with model %s', provider, modelName);
|
|
157
|
-
switch (provider) {
|
|
158
|
-
case AIProvider.OpenAI:
|
|
159
|
-
return openai(modelName);
|
|
160
|
-
case AIProvider.Anthropic:
|
|
161
|
-
return anthropic(modelName);
|
|
162
|
-
case AIProvider.Google:
|
|
163
|
-
return google(modelName);
|
|
164
|
-
case AIProvider.XAI:
|
|
165
|
-
return xai(modelName);
|
|
166
|
-
case AIProvider.Custom: {
|
|
167
|
-
const config = configureAIProvider();
|
|
168
|
-
if (config.custom == null) {
|
|
169
|
-
throw new Error('Custom provider not configured');
|
|
170
|
-
}
|
|
171
|
-
const customProvider = createCustomProvider(config.custom);
|
|
172
|
-
return customProvider.languageModel(modelName);
|
|
173
|
-
}
|
|
174
|
-
default:
|
|
175
|
-
throw new Error(`Unknown provider: ${provider}`);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
export async function generateTextWithAI(prompt, options = {}) {
|
|
179
|
-
const resolvedProvider = options.provider ?? getDefaultAIProvider();
|
|
180
|
-
debugAPI('generateTextWithAI called - provider: %s, promptLength: %d', resolvedProvider, prompt.length);
|
|
181
|
-
const finalOptions = { ...defaultOptions, ...options };
|
|
182
|
-
const model = finalOptions.model ?? getDefaultModel(resolvedProvider);
|
|
183
|
-
const modelInstance = getModel(resolvedProvider, model);
|
|
184
|
-
if (finalOptions.includeTools === true) {
|
|
185
|
-
debugTools('Tools requested, starting MCP server');
|
|
186
|
-
await startServer();
|
|
187
|
-
const result = await generateTextWithToolsAI(prompt, options);
|
|
188
|
-
return result.text;
|
|
189
|
-
}
|
|
190
|
-
try {
|
|
191
|
-
debugAPI('Making API call to %s with model %s', resolvedProvider, model);
|
|
192
|
-
debugAPI('Request params - temperature: %d, maxTokens: %d', finalOptions.temperature, finalOptions.maxTokens);
|
|
193
|
-
const result = await generateText({
|
|
194
|
-
model: modelInstance,
|
|
195
|
-
prompt,
|
|
196
|
-
temperature: finalOptions.temperature,
|
|
197
|
-
maxTokens: finalOptions.maxTokens,
|
|
198
|
-
});
|
|
199
|
-
debugAPI('API call successful - response length: %d, usage: %o', result.text.length, result.usage);
|
|
200
|
-
return result.text;
|
|
201
|
-
}
|
|
202
|
-
catch (error) {
|
|
203
|
-
extractAndLogError(error, resolvedProvider, 'generateTextWithAI');
|
|
204
|
-
throw error;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
export async function* streamTextWithAI(prompt, options = {}) {
|
|
208
|
-
const resolvedProvider = options.provider ?? getDefaultAIProvider();
|
|
209
|
-
debugStream('streamTextWithAI called - provider: %s, promptLength: %d', resolvedProvider, prompt.length);
|
|
210
|
-
const finalOptions = { ...defaultOptions, ...options };
|
|
211
|
-
const model = getModel(resolvedProvider, finalOptions.model);
|
|
212
|
-
try {
|
|
213
|
-
debugStream('Starting stream from %s', resolvedProvider);
|
|
214
|
-
const stream = await streamText({
|
|
215
|
-
model,
|
|
216
|
-
prompt,
|
|
217
|
-
temperature: finalOptions.temperature,
|
|
218
|
-
maxTokens: finalOptions.maxTokens,
|
|
219
|
-
});
|
|
220
|
-
let totalChunks = 0;
|
|
221
|
-
let totalLength = 0;
|
|
222
|
-
for await (const chunk of stream.textStream) {
|
|
223
|
-
totalChunks++;
|
|
224
|
-
totalLength += chunk.length;
|
|
225
|
-
debugStream('Chunk %d received - size: %d bytes', totalChunks, chunk.length);
|
|
226
|
-
yield chunk;
|
|
227
|
-
}
|
|
228
|
-
debugStream('Stream completed - total chunks: %d, total length: %d', totalChunks, totalLength);
|
|
229
|
-
}
|
|
230
|
-
catch (error) {
|
|
231
|
-
extractAndLogError(error, resolvedProvider, 'streamTextWithAI');
|
|
232
|
-
throw error;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Generates text using streaming and collects the full response.
|
|
237
|
-
* Optionally calls a stream callback for each token if provided.
|
|
238
|
-
* Always returns the complete collected response.
|
|
239
|
-
*/
|
|
240
|
-
export async function generateTextStreamingWithAI(prompt, options = {}) {
|
|
241
|
-
const resolvedProvider = options.provider ?? getDefaultAIProvider();
|
|
242
|
-
debugStream('generateTextStreamingWithAI called - provider: %s', resolvedProvider);
|
|
243
|
-
const finalOptions = { ...defaultOptions, ...options };
|
|
244
|
-
let collectedResult = '';
|
|
245
|
-
const stream = streamTextWithAI(prompt, finalOptions);
|
|
246
|
-
let tokenCount = 0;
|
|
247
|
-
for await (const token of stream) {
|
|
248
|
-
tokenCount++;
|
|
249
|
-
// Collect all tokens for the final result
|
|
250
|
-
collectedResult += token;
|
|
251
|
-
// Call the stream callback if provided
|
|
252
|
-
if (finalOptions.streamCallback) {
|
|
253
|
-
finalOptions.streamCallback(token);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
debugStream('Streaming complete - total tokens: %d, result length: %d', tokenCount, collectedResult.length);
|
|
257
|
-
return collectedResult;
|
|
258
|
-
}
|
|
259
|
-
async function executeToolConversation(modelInstance, messages, registeredTools, hasTools, finalOptions, provider) {
|
|
260
|
-
let finalResult = '';
|
|
261
|
-
const allToolCalls = [];
|
|
262
|
-
let attempts = 0;
|
|
263
|
-
const maxAttempts = 5;
|
|
264
|
-
while (attempts < maxAttempts) {
|
|
265
|
-
attempts++;
|
|
266
|
-
debugTools('Tool execution attempt %d/%d', attempts, maxAttempts);
|
|
267
|
-
const opts = {
|
|
268
|
-
model: modelInstance,
|
|
269
|
-
messages,
|
|
270
|
-
temperature: finalOptions.temperature,
|
|
271
|
-
maxTokens: finalOptions.maxTokens,
|
|
272
|
-
...(hasTools && {
|
|
273
|
-
tools: registeredTools,
|
|
274
|
-
toolChoice: 'auto',
|
|
275
|
-
}),
|
|
276
|
-
};
|
|
277
|
-
debugTools('Request options: %o', { ...opts, tools: hasTools ? '[tools included]' : undefined });
|
|
278
|
-
try {
|
|
279
|
-
const result = await generateText(opts);
|
|
280
|
-
debugTools('Result received - has text: %s, tool calls: %d', !!result.text, result.toolCalls?.length ?? 0);
|
|
281
|
-
// Add assistant message to conversation
|
|
282
|
-
if (result.text) {
|
|
283
|
-
messages.push({ role: 'assistant', content: result.text });
|
|
284
|
-
finalResult = result.text;
|
|
285
|
-
debugTools('Assistant message added to conversation');
|
|
286
|
-
}
|
|
287
|
-
// If there are tool calls, execute them and continue conversation
|
|
288
|
-
if (result.toolCalls !== undefined && result.toolCalls.length > 0) {
|
|
289
|
-
allToolCalls.push(...result.toolCalls);
|
|
290
|
-
debugTools('Executing %d tool calls', result.toolCalls.length);
|
|
291
|
-
// Execute tools and create a simple follow-up prompt
|
|
292
|
-
const toolResults = await executeToolCalls(result.toolCalls, registeredTools);
|
|
293
|
-
debugTools('Tool execution completed, results length: %d', toolResults.length);
|
|
294
|
-
// Add the tool results as a user message and request a final response
|
|
295
|
-
messages.push({
|
|
296
|
-
role: 'user',
|
|
297
|
-
content: `${toolResults}Based on this product catalog data, please provide specific product recommendations for a soccer-loving daughter. Include product names, prices, and reasons why each item would be suitable.`,
|
|
298
|
-
});
|
|
299
|
-
// Continue the conversation to get AI's response to tool results
|
|
300
|
-
continue;
|
|
301
|
-
}
|
|
302
|
-
// If no tool calls, we're done
|
|
303
|
-
debugTools('No tool calls, conversation complete');
|
|
304
|
-
break;
|
|
305
|
-
}
|
|
306
|
-
catch (error) {
|
|
307
|
-
extractAndLogError(error, provider, 'generateTextWithToolsAI');
|
|
308
|
-
throw error;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
return { finalResult, allToolCalls };
|
|
312
|
-
}
|
|
313
|
-
export async function generateTextWithToolsAI(prompt, options = {}) {
|
|
314
|
-
const resolvedProvider = options.provider ?? getDefaultAIProvider();
|
|
315
|
-
debugTools('generateTextWithToolsAI called - provider: %s', resolvedProvider);
|
|
316
|
-
const finalOptions = { ...defaultOptions, ...options };
|
|
317
|
-
const model = finalOptions.model ?? getDefaultModel(resolvedProvider);
|
|
318
|
-
const modelInstance = getModel(resolvedProvider, model);
|
|
319
|
-
const registeredTools = finalOptions.includeTools === true ? getRegisteredToolsForAI() : {};
|
|
320
|
-
debugTools('Registered tools: %o', Object.keys(registeredTools));
|
|
321
|
-
const hasTools = Object.keys(registeredTools).length > 0;
|
|
322
|
-
debugTools('Has tools available: %s', hasTools);
|
|
323
|
-
// Build conversation messages
|
|
324
|
-
const messages = [{ role: 'user', content: prompt }];
|
|
325
|
-
const { finalResult, allToolCalls } = await executeToolConversation(modelInstance, messages, registeredTools, hasTools, finalOptions, resolvedProvider);
|
|
326
|
-
return {
|
|
327
|
-
text: finalResult,
|
|
328
|
-
toolCalls: allToolCalls,
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
async function executeToolCalls(toolCalls, registeredTools) {
|
|
332
|
-
debugTools('Executing %d tool calls', toolCalls.length);
|
|
333
|
-
let toolResults = '';
|
|
334
|
-
for (const toolCall of toolCalls) {
|
|
335
|
-
try {
|
|
336
|
-
const toolCallObj = toolCall;
|
|
337
|
-
debugTools('Executing tool: %s with args: %o', toolCallObj.toolName, toolCallObj.args);
|
|
338
|
-
const tool = registeredTools[toolCallObj.toolName];
|
|
339
|
-
if (tool?.execute) {
|
|
340
|
-
const toolResult = await tool.execute(toolCallObj.args);
|
|
341
|
-
toolResults += `Tool ${toolCallObj.toolName} returned: ${String(toolResult)}\n\n`;
|
|
342
|
-
debugTools('Tool %s executed successfully', toolCallObj.toolName);
|
|
343
|
-
}
|
|
344
|
-
else {
|
|
345
|
-
toolResults += `Error: Tool ${toolCallObj.toolName} not found or missing execute function\n\n`;
|
|
346
|
-
debugTools('Tool %s not found or missing execute function', toolCallObj.toolName);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
catch (error) {
|
|
350
|
-
const toolCallObj = toolCall;
|
|
351
|
-
debugError('Tool execution error for %s: %O', toolCallObj.toolName, error);
|
|
352
|
-
toolResults += `Error executing tool ${toolCallObj.toolName}: ${String(error)}\n\n`;
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
return toolResults;
|
|
356
|
-
}
|
|
357
|
-
export async function generateTextWithImageAI(text, imageBase64, options = {}) {
|
|
358
|
-
const resolvedProvider = options.provider ?? getDefaultAIProvider();
|
|
359
|
-
debugAPI('generateTextWithImageAI called - provider: %s, textLength: %d, imageSize: %d', resolvedProvider, text.length, imageBase64.length);
|
|
360
|
-
const finalOptions = { ...defaultOptions, ...options };
|
|
361
|
-
const model = finalOptions.model ?? getDefaultModel(resolvedProvider);
|
|
362
|
-
const modelInstance = getModel(resolvedProvider, model);
|
|
363
|
-
if (resolvedProvider !== AIProvider.OpenAI && resolvedProvider !== AIProvider.XAI) {
|
|
364
|
-
debugError('Provider %s does not support image inputs', resolvedProvider);
|
|
365
|
-
throw new Error(`Provider ${resolvedProvider} does not support image inputs`);
|
|
366
|
-
}
|
|
367
|
-
try {
|
|
368
|
-
debugAPI('Sending image+text to %s', resolvedProvider);
|
|
369
|
-
const result = await generateText({
|
|
370
|
-
model: modelInstance,
|
|
371
|
-
messages: [
|
|
372
|
-
{
|
|
373
|
-
role: 'user',
|
|
374
|
-
content: [
|
|
375
|
-
{ type: 'text', text },
|
|
376
|
-
{ type: 'image', image: imageBase64 },
|
|
377
|
-
],
|
|
378
|
-
},
|
|
379
|
-
],
|
|
380
|
-
temperature: finalOptions.temperature,
|
|
381
|
-
maxTokens: finalOptions.maxTokens,
|
|
382
|
-
});
|
|
383
|
-
debugAPI('Image API call successful - response length: %d', result.text.length);
|
|
384
|
-
return result.text;
|
|
385
|
-
}
|
|
386
|
-
catch (error) {
|
|
387
|
-
extractAndLogError(error, resolvedProvider, 'generateTextWithImageAI');
|
|
388
|
-
throw error;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
export function getAvailableProviders() {
|
|
392
|
-
const config = configureAIProvider();
|
|
393
|
-
const providers = [];
|
|
394
|
-
if (config.anthropic != null)
|
|
395
|
-
providers.push(AIProvider.Anthropic);
|
|
396
|
-
if (config.openai != null)
|
|
397
|
-
providers.push(AIProvider.OpenAI);
|
|
398
|
-
if (config.google != null)
|
|
399
|
-
providers.push(AIProvider.Google);
|
|
400
|
-
if (config.xai != null)
|
|
401
|
-
providers.push(AIProvider.XAI);
|
|
402
|
-
if (config.custom != null)
|
|
403
|
-
providers.push(AIProvider.Custom);
|
|
404
|
-
debugConfig('Available providers: %o', providers);
|
|
405
|
-
return providers;
|
|
406
|
-
}
|
|
407
|
-
function getEnhancedPrompt(prompt, lastError) {
|
|
408
|
-
const errorDetails = lastError.zodIssues
|
|
409
|
-
? JSON.stringify(lastError.zodIssues, null, 2)
|
|
410
|
-
: lastError.validationDetails?.cause?.issues
|
|
411
|
-
? JSON.stringify(lastError.validationDetails.cause.issues, null, 2)
|
|
412
|
-
: lastError.message;
|
|
413
|
-
debugValidation('Enhancing prompt with validation error details: %o', errorDetails);
|
|
414
|
-
return `${prompt}\\n\\n⚠️ IMPORTANT: Your previous response failed validation with the following errors:\\n${errorDetails}\\n\\nPlease fix these errors and ensure your response EXACTLY matches the required schema structure.`;
|
|
415
|
-
}
|
|
416
|
-
function isSchemaError(error) {
|
|
417
|
-
return (error.message.includes('response did not match schema') ||
|
|
418
|
-
error.message.includes('TypeValidationError') ||
|
|
419
|
-
error.name === 'AI_TypeValidationError');
|
|
420
|
-
}
|
|
421
|
-
function enhanceValidationError(error) {
|
|
422
|
-
const enhancedError = new Error(error.message);
|
|
423
|
-
Object.assign(enhancedError, error);
|
|
424
|
-
if (error.cause !== undefined || error.issues !== undefined || error.errors !== undefined) {
|
|
425
|
-
enhancedError.validationDetails = {
|
|
426
|
-
cause: error.cause,
|
|
427
|
-
issues: error.issues,
|
|
428
|
-
errors: error.errors,
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
|
-
if (error.message.includes('response did not match schema') &&
|
|
432
|
-
'cause' in error &&
|
|
433
|
-
typeof error.cause === 'object' &&
|
|
434
|
-
error.cause !== null &&
|
|
435
|
-
'issues' in error.cause) {
|
|
436
|
-
enhancedError.zodIssues = error.cause.issues;
|
|
437
|
-
}
|
|
438
|
-
return enhancedError;
|
|
439
|
-
}
|
|
440
|
-
function handleFailedRequest(lastError, maxRetries, attempt) {
|
|
441
|
-
if (!lastError || !isSchemaError(lastError) || attempt >= maxRetries - 1) {
|
|
442
|
-
debugValidation('Not retrying - isLastError: %s, isSchemaError: %s, attempt: %d/%d', !!lastError, lastError ? isSchemaError(lastError) : false, attempt + 1, maxRetries);
|
|
443
|
-
return { shouldRetry: false, enhancedError: lastError };
|
|
444
|
-
}
|
|
445
|
-
debugValidation('Schema validation failed on attempt %d/%d, will retry', attempt + 1, maxRetries);
|
|
446
|
-
const enhancedError = enhanceValidationError(lastError);
|
|
447
|
-
return { shouldRetry: true, enhancedError };
|
|
448
|
-
}
|
|
449
|
-
// Helper function to attempt structured data generation with retry logic
|
|
450
|
-
async function attemptStructuredGeneration(prompt, provider, options, registeredTools, hasTools) {
|
|
451
|
-
const maxSchemaRetries = 3;
|
|
452
|
-
let lastError;
|
|
453
|
-
for (let attempt = 0; attempt < maxSchemaRetries; attempt++) {
|
|
454
|
-
try {
|
|
455
|
-
debugValidation('Structured data generation attempt %d/%d', attempt + 1, maxSchemaRetries);
|
|
456
|
-
const model = getModel(provider, options.model);
|
|
457
|
-
const enhancedPrompt = attempt > 0 && lastError ? getEnhancedPrompt(prompt, lastError) : prompt;
|
|
458
|
-
if (attempt > 0) {
|
|
459
|
-
debugValidation('Using enhanced prompt for retry attempt %d', attempt + 1);
|
|
460
|
-
}
|
|
461
|
-
const opts = {
|
|
462
|
-
model,
|
|
463
|
-
prompt: enhancedPrompt,
|
|
464
|
-
schema: options.schema,
|
|
465
|
-
schemaName: options.schemaName,
|
|
466
|
-
schemaDescription: options.schemaDescription,
|
|
467
|
-
temperature: options.temperature,
|
|
468
|
-
maxTokens: options.maxTokens,
|
|
469
|
-
...(hasTools && {
|
|
470
|
-
tools: registeredTools,
|
|
471
|
-
toolChoice: 'auto',
|
|
472
|
-
}),
|
|
473
|
-
};
|
|
474
|
-
debugAPI('Generating structured object with schema: %s', options.schemaName ?? 'unnamed');
|
|
475
|
-
const result = await generateObject(opts);
|
|
476
|
-
debugAPI('Structured object generated successfully');
|
|
477
|
-
return result.object;
|
|
478
|
-
}
|
|
479
|
-
catch (error) {
|
|
480
|
-
lastError =
|
|
481
|
-
error instanceof Error
|
|
482
|
-
? error
|
|
483
|
-
: new Error('An unknown error occurred');
|
|
484
|
-
const { shouldRetry, enhancedError } = handleFailedRequest(lastError, maxSchemaRetries, attempt);
|
|
485
|
-
lastError = enhancedError;
|
|
486
|
-
if (!shouldRetry) {
|
|
487
|
-
throw lastError;
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
// If we exhausted all retries, throw the last error
|
|
492
|
-
throw lastError;
|
|
493
|
-
}
|
|
494
|
-
export async function generateStructuredDataWithAI(prompt, options) {
|
|
495
|
-
const resolvedProvider = options.provider ?? getDefaultAIProvider();
|
|
496
|
-
debugAPI('generateStructuredDataWithAI called - provider: %s, schema: %s', resolvedProvider, options.schemaName ?? 'unnamed');
|
|
497
|
-
if (options.includeTools === true) {
|
|
498
|
-
debugTools('Tools requested, starting MCP server');
|
|
499
|
-
await startServer();
|
|
500
|
-
}
|
|
501
|
-
const registeredTools = options.includeTools === true ? getRegisteredToolsForAI() : {};
|
|
502
|
-
debugTools('Registered tools for structured data: %o', Object.keys(registeredTools));
|
|
503
|
-
const hasTools = Object.keys(registeredTools).length > 0;
|
|
504
|
-
return attemptStructuredGeneration(prompt, resolvedProvider, options, registeredTools, hasTools);
|
|
505
|
-
}
|
|
506
|
-
export async function streamStructuredDataWithAI(prompt, options) {
|
|
507
|
-
const resolvedProvider = options.provider ?? getDefaultAIProvider();
|
|
508
|
-
debugStream('streamStructuredDataWithAI called - provider: %s, schema: %s', resolvedProvider, options.schemaName ?? 'unnamed');
|
|
509
|
-
const maxSchemaRetries = 3;
|
|
510
|
-
let lastError;
|
|
511
|
-
for (let attempt = 0; attempt < maxSchemaRetries; attempt++) {
|
|
512
|
-
try {
|
|
513
|
-
debugValidation('Stream structured data attempt %d/%d', attempt + 1, maxSchemaRetries);
|
|
514
|
-
const model = getModel(resolvedProvider, options.model);
|
|
515
|
-
const enhancedPrompt = attempt > 0 && lastError ? getEnhancedPrompt(prompt, lastError) : prompt;
|
|
516
|
-
const result = streamObject({
|
|
517
|
-
model,
|
|
518
|
-
prompt: enhancedPrompt,
|
|
519
|
-
schema: options.schema,
|
|
520
|
-
schemaName: options.schemaName,
|
|
521
|
-
schemaDescription: options.schemaDescription,
|
|
522
|
-
temperature: options.temperature,
|
|
523
|
-
maxTokens: options.maxTokens,
|
|
524
|
-
});
|
|
525
|
-
// Stream partial objects if callback provided
|
|
526
|
-
if (options.onPartialObject) {
|
|
527
|
-
debugStream('Starting partial object stream');
|
|
528
|
-
void (async () => {
|
|
529
|
-
try {
|
|
530
|
-
let partialCount = 0;
|
|
531
|
-
for await (const partialObject of result.partialObjectStream) {
|
|
532
|
-
partialCount++;
|
|
533
|
-
debugStream('Partial object %d received', partialCount);
|
|
534
|
-
options.onPartialObject?.(partialObject);
|
|
535
|
-
}
|
|
536
|
-
debugStream('Partial object stream complete - total partials: %d', partialCount);
|
|
537
|
-
}
|
|
538
|
-
catch (streamError) {
|
|
539
|
-
debugError('Error in partial object stream: %O', streamError);
|
|
540
|
-
}
|
|
541
|
-
})();
|
|
542
|
-
}
|
|
543
|
-
// Return the final complete object
|
|
544
|
-
const finalObject = await result.object;
|
|
545
|
-
debugStream('Final structured object received');
|
|
546
|
-
return finalObject;
|
|
547
|
-
}
|
|
548
|
-
catch (error) {
|
|
549
|
-
lastError =
|
|
550
|
-
error instanceof Error
|
|
551
|
-
? error
|
|
552
|
-
: new Error('An unknown error occurred');
|
|
553
|
-
const { shouldRetry, enhancedError } = handleFailedRequest(lastError, maxSchemaRetries, attempt);
|
|
554
|
-
lastError = enhancedError;
|
|
555
|
-
if (!shouldRetry) {
|
|
556
|
-
throw lastError;
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
// If we exhausted all retries, throw the last error
|
|
561
|
-
throw lastError;
|
|
562
|
-
}
|
|
563
|
-
// Export zod for convenience
|
|
564
|
-
export { z };
|
|
565
|
-
// Export MCP server singleton functions
|
|
566
|
-
export { server as mcpServer, registerTool, registerTools, startServer, isServerStarted, getRegisteredTools, getRegisteredToolsForAI, getToolHandler, getSchemaByName, executeRegisteredTool, } from './mcp-server.js';
|
|
1
|
+
export * from './node/index.js';
|
|
567
2
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":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C7B,OAAO,EAAE,CAAC,EAAE,CAAC;AAEb,wCAAwC;AACxC,OAAO,EACL,MAAM,IAAI,SAAS,EACnB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,eAAe,EACf,kBAAkB,EAClB,uBAAuB,EACvB,cAAc,EACd,eAAe,EACf,qBAAqB,GAGtB,MAAM,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
package/dist/src/index.specs.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
2
|
-
import { getAvailableProviders, getDefaultAIProvider, getDefaultModel } from './index.js';
|
|
3
|
-
import { DEFAULT_MODELS
|
|
2
|
+
import { getAvailableProviders, getDefaultAIProvider, getDefaultModel, resetGlobalContext } from './index.js';
|
|
3
|
+
import { DEFAULT_MODELS } from './core/constants.js';
|
|
4
|
+
import { AIProvider } from './core/types.js';
|
|
4
5
|
// Mock the config module
|
|
5
|
-
vi.mock('./config', () => ({
|
|
6
|
+
vi.mock('./node/config', () => ({
|
|
6
7
|
configureAIProvider: vi.fn(() => ({
|
|
7
8
|
anthropic: { apiKey: 'test-anthropic-key' },
|
|
8
9
|
openai: { apiKey: 'test-openai-key' },
|
|
@@ -15,6 +16,7 @@ describe('Provider Selection Logic', () => {
|
|
|
15
16
|
let originalProvider;
|
|
16
17
|
beforeEach(() => {
|
|
17
18
|
originalProvider = process.env.DEFAULT_AI_PROVIDER;
|
|
19
|
+
resetGlobalContext();
|
|
18
20
|
});
|
|
19
21
|
afterEach(() => {
|
|
20
22
|
if (originalProvider !== undefined) {
|
|
@@ -23,6 +25,7 @@ describe('Provider Selection Logic', () => {
|
|
|
23
25
|
else {
|
|
24
26
|
delete process.env.DEFAULT_AI_PROVIDER;
|
|
25
27
|
}
|
|
28
|
+
resetGlobalContext();
|
|
26
29
|
});
|
|
27
30
|
it('should respect DEFAULT_AI_PROVIDER environment variable when set to anthropic', () => {
|
|
28
31
|
process.env.DEFAULT_AI_PROVIDER = 'anthropic';
|