@auto-engineer/ai-gateway 0.6.3 → 0.8.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/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-test.log +17 -35
- package/.turbo/turbo-type-check.log +4 -5
- package/CHANGELOG.md +6 -0
- package/README.md +365 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +31 -2
- package/dist/config.js.map +1 -1
- package/dist/config.specs.d.ts +2 -0
- package/dist/config.specs.d.ts.map +1 -0
- package/dist/config.specs.js +123 -0
- package/dist/config.specs.js.map +1 -0
- package/dist/constants.d.ts +20 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +15 -0
- package/dist/constants.js.map +1 -0
- package/dist/index-custom.specs.d.ts +2 -0
- package/dist/index-custom.specs.d.ts.map +1 -0
- package/dist/index-custom.specs.js +161 -0
- package/dist/index-custom.specs.js.map +1 -0
- package/dist/index.d.ts +12 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +93 -59
- package/dist/index.js.map +1 -1
- package/dist/index.specs.js +152 -11
- package/dist/index.specs.js.map +1 -1
- package/dist/providers/custom.d.ts +6 -0
- package/dist/providers/custom.d.ts.map +1 -0
- package/dist/providers/custom.js +16 -0
- package/dist/providers/custom.js.map +1 -0
- package/dist/providers/custom.specs.d.ts +2 -0
- package/dist/providers/custom.specs.d.ts.map +1 -0
- package/dist/providers/custom.specs.js +129 -0
- package/dist/providers/custom.specs.js.map +1 -0
- package/package.json +5 -5
- package/src/config.specs.ts +147 -0
- package/src/config.ts +46 -2
- package/src/constants.ts +21 -0
- package/src/index-custom.specs.ts +192 -0
- package/src/index.specs.ts +199 -10
- package/src/index.ts +99 -78
- package/src/providers/custom.specs.ts +161 -0
- package/src/providers/custom.ts +24 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/.turbo/turbo-format.log +0 -14
- package/.turbo/turbo-lint.log +0 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+
OpenAI = "openai",
|
|
3
|
+
Anthropic = "anthropic",
|
|
4
|
+
Google = "google",
|
|
5
|
+
XAI = "xai",
|
|
6
|
+
Custom = "custom"
|
|
7
|
+
}
|
|
8
|
+
export interface CustomProviderConfig {
|
|
9
|
+
name: string;
|
|
10
|
+
baseUrl: string;
|
|
11
|
+
apiKey: string;
|
|
12
|
+
defaultModel: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const DEFAULT_MODELS: {
|
|
15
|
+
readonly openai: "gpt-4o-mini";
|
|
16
|
+
readonly anthropic: "claude-sonnet-4-20250514";
|
|
17
|
+
readonly google: "gemini-2.5-pro";
|
|
18
|
+
readonly xai: "grok-4";
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU;IACpB,MAAM,WAAW;IACjB,SAAS,cAAc;IACvB,MAAM,WAAW;IACjB,GAAG,QAAQ;IACX,MAAM,WAAW;CAClB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,cAAc;;;;;CAKjB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export var AIProvider;
|
|
2
|
+
(function (AIProvider) {
|
|
3
|
+
AIProvider["OpenAI"] = "openai";
|
|
4
|
+
AIProvider["Anthropic"] = "anthropic";
|
|
5
|
+
AIProvider["Google"] = "google";
|
|
6
|
+
AIProvider["XAI"] = "xai";
|
|
7
|
+
AIProvider["Custom"] = "custom";
|
|
8
|
+
})(AIProvider || (AIProvider = {}));
|
|
9
|
+
export const DEFAULT_MODELS = {
|
|
10
|
+
[AIProvider.OpenAI]: 'gpt-4o-mini',
|
|
11
|
+
[AIProvider.Anthropic]: 'claude-sonnet-4-20250514',
|
|
12
|
+
[AIProvider.Google]: 'gemini-2.5-pro',
|
|
13
|
+
[AIProvider.XAI]: 'grok-4',
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,UAMX;AAND,WAAY,UAAU;IACpB,+BAAiB,CAAA;IACjB,qCAAuB,CAAA;IACvB,+BAAiB,CAAA;IACjB,yBAAW,CAAA;IACX,+BAAiB,CAAA;AACnB,CAAC,EANW,UAAU,KAAV,UAAU,QAMrB;AASD,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,aAAa;IAClC,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,0BAA0B;IAClD,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,gBAAgB;IACrC,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,QAAQ;CAClB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-custom.specs.d.ts","sourceRoot":"","sources":["../src/index-custom.specs.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { AIProvider } from './constants.js';
|
|
3
|
+
import { getAvailableProviders, getDefaultModel, getDefaultAIProvider } from './index.js';
|
|
4
|
+
// Mock the config module
|
|
5
|
+
vi.mock('./config', () => ({
|
|
6
|
+
configureAIProvider: vi.fn(),
|
|
7
|
+
}));
|
|
8
|
+
// Mock the custom provider
|
|
9
|
+
vi.mock('./providers/custom', () => ({
|
|
10
|
+
createCustomProvider: vi.fn(() => ({
|
|
11
|
+
languageModel: vi.fn(),
|
|
12
|
+
})),
|
|
13
|
+
}));
|
|
14
|
+
describe('Index Integration with Custom Providers', () => {
|
|
15
|
+
const originalEnv = process.env;
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
vi.resetModules();
|
|
18
|
+
process.env = { ...originalEnv };
|
|
19
|
+
vi.clearAllMocks();
|
|
20
|
+
});
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
process.env = originalEnv;
|
|
23
|
+
});
|
|
24
|
+
describe('getAvailableProviders', () => {
|
|
25
|
+
it('should include custom provider when configured', async () => {
|
|
26
|
+
const { configureAIProvider } = await import('./config.js');
|
|
27
|
+
vi.mocked(configureAIProvider).mockReturnValue({
|
|
28
|
+
custom: {
|
|
29
|
+
name: 'litellm',
|
|
30
|
+
baseUrl: 'https://api.litellm.ai',
|
|
31
|
+
apiKey: 'sk-key',
|
|
32
|
+
defaultModel: 'claude-3-sonnet',
|
|
33
|
+
},
|
|
34
|
+
anthropic: { apiKey: 'sk-anthropic' },
|
|
35
|
+
});
|
|
36
|
+
const providers = getAvailableProviders();
|
|
37
|
+
expect(providers).toContain(AIProvider.Custom);
|
|
38
|
+
expect(providers).toContain(AIProvider.Anthropic);
|
|
39
|
+
});
|
|
40
|
+
it('should not include custom provider when not configured', async () => {
|
|
41
|
+
const { configureAIProvider } = await import('./config.js');
|
|
42
|
+
vi.mocked(configureAIProvider).mockReturnValue({
|
|
43
|
+
anthropic: { apiKey: 'sk-anthropic' },
|
|
44
|
+
});
|
|
45
|
+
const providers = getAvailableProviders();
|
|
46
|
+
expect(providers).not.toContain(AIProvider.Custom);
|
|
47
|
+
expect(providers).toContain(AIProvider.Anthropic);
|
|
48
|
+
});
|
|
49
|
+
it('should handle multiple providers including custom', async () => {
|
|
50
|
+
const { configureAIProvider } = await import('./config.js');
|
|
51
|
+
vi.mocked(configureAIProvider).mockReturnValue({
|
|
52
|
+
openai: { apiKey: 'sk-openai' },
|
|
53
|
+
anthropic: { apiKey: 'sk-anthropic' },
|
|
54
|
+
google: { apiKey: 'sk-google' },
|
|
55
|
+
xai: { apiKey: 'sk-xai' },
|
|
56
|
+
custom: {
|
|
57
|
+
name: 'custom',
|
|
58
|
+
baseUrl: 'https://api.custom.com',
|
|
59
|
+
apiKey: 'sk-custom',
|
|
60
|
+
defaultModel: 'custom-model',
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
const providers = getAvailableProviders();
|
|
64
|
+
expect(providers).toHaveLength(5);
|
|
65
|
+
expect(providers).toContain(AIProvider.OpenAI);
|
|
66
|
+
expect(providers).toContain(AIProvider.Anthropic);
|
|
67
|
+
expect(providers).toContain(AIProvider.Google);
|
|
68
|
+
expect(providers).toContain(AIProvider.XAI);
|
|
69
|
+
expect(providers).toContain(AIProvider.Custom);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
describe('getDefaultModel', () => {
|
|
73
|
+
it('should return custom provider default model when provider is Custom', async () => {
|
|
74
|
+
const { configureAIProvider } = await import('./config.js');
|
|
75
|
+
vi.mocked(configureAIProvider).mockReturnValue({
|
|
76
|
+
custom: {
|
|
77
|
+
name: 'litellm',
|
|
78
|
+
baseUrl: 'https://api.litellm.ai',
|
|
79
|
+
apiKey: 'sk-key',
|
|
80
|
+
defaultModel: 'claude-3-sonnet',
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
const model = getDefaultModel(AIProvider.Custom);
|
|
84
|
+
expect(model).toBe('claude-3-sonnet');
|
|
85
|
+
});
|
|
86
|
+
it('should throw error when custom provider not configured but requested', async () => {
|
|
87
|
+
const { configureAIProvider } = await import('./config.js');
|
|
88
|
+
vi.mocked(configureAIProvider).mockReturnValue({
|
|
89
|
+
anthropic: { apiKey: 'sk-anthropic' },
|
|
90
|
+
});
|
|
91
|
+
expect(() => getDefaultModel(AIProvider.Custom)).toThrow('Custom provider not configured');
|
|
92
|
+
});
|
|
93
|
+
it('should use environment variable DEFAULT_AI_MODEL for custom provider', async () => {
|
|
94
|
+
process.env.DEFAULT_AI_MODEL = 'env-override-model';
|
|
95
|
+
const { configureAIProvider } = await import('./config.js');
|
|
96
|
+
vi.mocked(configureAIProvider).mockReturnValue({
|
|
97
|
+
custom: {
|
|
98
|
+
name: 'custom',
|
|
99
|
+
baseUrl: 'https://api.custom.com',
|
|
100
|
+
apiKey: 'sk-key',
|
|
101
|
+
defaultModel: 'config-model',
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
const model = getDefaultModel(AIProvider.Custom);
|
|
105
|
+
expect(model).toBe('env-override-model');
|
|
106
|
+
});
|
|
107
|
+
it('should handle different custom provider models', async () => {
|
|
108
|
+
const testCases = ['gpt-4o', 'claude-3-opus', 'llama3.1:70b', 'mistral-large', 'gemini-1.5-pro'];
|
|
109
|
+
const { configureAIProvider } = await import('./config.js');
|
|
110
|
+
testCases.forEach((testModel) => {
|
|
111
|
+
vi.mocked(configureAIProvider).mockReturnValue({
|
|
112
|
+
custom: {
|
|
113
|
+
name: 'test',
|
|
114
|
+
baseUrl: 'https://api.test.com',
|
|
115
|
+
apiKey: 'sk-key',
|
|
116
|
+
defaultModel: testModel,
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
const model = getDefaultModel(AIProvider.Custom);
|
|
120
|
+
expect(model).toBe(testModel);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
describe('getDefaultAIProvider', () => {
|
|
125
|
+
it('should use custom provider as fallback when available', async () => {
|
|
126
|
+
process.env.DEFAULT_AI_PROVIDER = 'nonexistent';
|
|
127
|
+
const { configureAIProvider } = await import('./config.js');
|
|
128
|
+
vi.mocked(configureAIProvider).mockReturnValue({
|
|
129
|
+
custom: {
|
|
130
|
+
name: 'custom',
|
|
131
|
+
baseUrl: 'https://api.custom.com',
|
|
132
|
+
apiKey: 'sk-key',
|
|
133
|
+
defaultModel: 'custom-model',
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
// Mock getAvailableProviders to return custom
|
|
137
|
+
const mockGetAvailableProviders = vi.fn(() => [AIProvider.Custom]);
|
|
138
|
+
vi.doMock('./index', async () => ({
|
|
139
|
+
...(await vi.importActual('./index')),
|
|
140
|
+
getAvailableProviders: mockGetAvailableProviders,
|
|
141
|
+
}));
|
|
142
|
+
const { getDefaultAIProvider: getDefaultAIProviderMocked } = await import('./index.js');
|
|
143
|
+
const provider = getDefaultAIProviderMocked();
|
|
144
|
+
expect(provider).toBe(AIProvider.Custom);
|
|
145
|
+
});
|
|
146
|
+
it('should respect explicit DEFAULT_AI_PROVIDER environment variable', () => {
|
|
147
|
+
const testCases = [
|
|
148
|
+
{ env: 'openai', expected: AIProvider.OpenAI },
|
|
149
|
+
{ env: 'anthropic', expected: AIProvider.Anthropic },
|
|
150
|
+
{ env: 'google', expected: AIProvider.Google },
|
|
151
|
+
{ env: 'xai', expected: AIProvider.XAI },
|
|
152
|
+
];
|
|
153
|
+
testCases.forEach(({ env, expected }) => {
|
|
154
|
+
process.env.DEFAULT_AI_PROVIDER = env;
|
|
155
|
+
const provider = getDefaultAIProvider();
|
|
156
|
+
expect(provider).toBe(expected);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
//# sourceMappingURL=index-custom.specs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-custom.specs.js","sourceRoot":"","sources":["../src/index-custom.specs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEvF,yBAAyB;AACzB,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;IACzB,mBAAmB,EAAE,EAAE,CAAC,EAAE,EAAE;CAC7B,CAAC,CAAC,CAAC;AAEJ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,EAAE,QAAQ,EAAE,UAAU,CAAC,MAAM,EAAE;gBAC9C,EAAE,GAAG,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,CAAC,SAAS,EAAE;gBACpD,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,CAAC,MAAM,EAAE;gBAC9C,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,CAAC,GAAG,EAAE;aACzC,CAAC;YAEF,SAAS,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE;gBACtC,OAAO,CAAC,GAAG,CAAC,mBAAmB,GAAG,GAAG,CAAC;gBACtC,MAAM,QAAQ,GAAG,oBAAoB,EAAE,CAAC;gBACxC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAClC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
+
import { AIProvider } from './constants';
|
|
2
|
+
export { AIProvider } from './constants';
|
|
1
3
|
import { z } from 'zod';
|
|
2
|
-
export declare enum AIProvider {
|
|
3
|
-
OpenAI = "openai",
|
|
4
|
-
Anthropic = "anthropic",
|
|
5
|
-
Google = "google",
|
|
6
|
-
XAI = "xai"
|
|
7
|
-
}
|
|
8
4
|
export interface AIOptions {
|
|
5
|
+
provider?: AIProvider;
|
|
9
6
|
model?: string;
|
|
10
7
|
temperature?: number;
|
|
11
8
|
maxTokens?: number;
|
|
@@ -20,22 +17,24 @@ export interface StructuredAIOptions<T> extends Omit<AIOptions, 'streamCallback'
|
|
|
20
17
|
export interface StreamStructuredAIOptions<T> extends StructuredAIOptions<T> {
|
|
21
18
|
onPartialObject?: (partialObject: unknown) => void;
|
|
22
19
|
}
|
|
23
|
-
export declare function
|
|
24
|
-
export declare function
|
|
20
|
+
export declare function getDefaultAIProvider(): AIProvider;
|
|
21
|
+
export declare function getDefaultModel(provider: AIProvider): string;
|
|
22
|
+
export declare function generateTextWithAI(prompt: string, options?: AIOptions): Promise<string>;
|
|
23
|
+
export declare function streamTextWithAI(prompt: string, options?: AIOptions): AsyncGenerator<string>;
|
|
25
24
|
/**
|
|
26
25
|
* Generates text using streaming and collects the full response.
|
|
27
26
|
* Optionally calls a stream callback for each token if provided.
|
|
28
27
|
* Always returns the complete collected response.
|
|
29
28
|
*/
|
|
30
|
-
export declare function generateTextStreamingWithAI(prompt: string,
|
|
31
|
-
export declare function generateTextWithToolsAI(prompt: string,
|
|
29
|
+
export declare function generateTextStreamingWithAI(prompt: string, options?: AIOptions): Promise<string>;
|
|
30
|
+
export declare function generateTextWithToolsAI(prompt: string, options?: AIOptions): Promise<{
|
|
32
31
|
text: string;
|
|
33
32
|
toolCalls?: unknown[];
|
|
34
33
|
}>;
|
|
35
|
-
export declare function generateTextWithImageAI(text: string, imageBase64: string,
|
|
34
|
+
export declare function generateTextWithImageAI(text: string, imageBase64: string, options?: AIOptions): Promise<string>;
|
|
36
35
|
export declare function getAvailableProviders(): AIProvider[];
|
|
37
|
-
export declare function generateStructuredDataWithAI<T>(prompt: string,
|
|
38
|
-
export declare function streamStructuredDataWithAI<T>(prompt: string,
|
|
36
|
+
export declare function generateStructuredDataWithAI<T>(prompt: string, options: StructuredAIOptions<T>): Promise<T>;
|
|
37
|
+
export declare function streamStructuredDataWithAI<T>(prompt: string, options: StreamStructuredAIOptions<T>): Promise<T>;
|
|
39
38
|
export { z };
|
|
40
39
|
export { server as mcpServer, registerTool, registerTools, startServer, isServerStarted, getRegisteredTools, getRegisteredToolsForAI, getToolHandler, getSchemaByName, executeRegisteredTool, type ToolHandler, type RegisteredTool, } from './mcp-server';
|
|
41
40
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.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AAc,CAAC,MAAM,CAAC,CA4BvG;AAED;;;;GAIG;AACH,wBAAsB,2BAA2B,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,SAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAsB1G;AAgFD,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,SAAc,GACtB,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,EAAE,CAAA;CAAE,CAAC,CA4BlD;AAgCD,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE,SAAc,GACtB,OAAO,CAAC,MAAM,CAAC,CAwCjB;AAED,wBAAgB,qBAAqB,IAAI,UAAU,EAAE,CAUpD;AA4HD,wBAAsB,4BAA4B,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAiBjH;AAED,wBAAsB,0BAA0B,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,yBAAyB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAkErH;AAGD,OAAO,EAAE,CAAC,EAAE,CAAC;AAGb,OAAO,EACL,MAAM,IAAI,SAAS,EACnB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,eAAe,EACf,kBAAkB,EAClB,uBAAuB,EACvB,cAAc,EACd,eAAe,EACf,qBAAqB,EACrB,KAAK,WAAW,EAChB,KAAK,cAAc,GACpB,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,9 @@ import { anthropic } from '@ai-sdk/anthropic';
|
|
|
4
4
|
import { google } from '@ai-sdk/google';
|
|
5
5
|
import { xai } from '@ai-sdk/xai';
|
|
6
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';
|
|
7
10
|
import { z } from 'zod';
|
|
8
11
|
import { getRegisteredToolsForAI } from './mcp-server.js';
|
|
9
12
|
import { startServer } from './mcp-server.js';
|
|
@@ -104,33 +107,47 @@ function extractAndLogError(error, provider, operation) {
|
|
|
104
107
|
debugError('Unknown error type: %O', error);
|
|
105
108
|
}
|
|
106
109
|
}
|
|
107
|
-
export var AIProvider;
|
|
108
|
-
(function (AIProvider) {
|
|
109
|
-
AIProvider["OpenAI"] = "openai";
|
|
110
|
-
AIProvider["Anthropic"] = "anthropic";
|
|
111
|
-
AIProvider["Google"] = "google";
|
|
112
|
-
AIProvider["XAI"] = "xai";
|
|
113
|
-
})(AIProvider || (AIProvider = {}));
|
|
114
110
|
const defaultOptions = {
|
|
115
111
|
temperature: 0.7,
|
|
116
112
|
maxTokens: 1000,
|
|
117
113
|
};
|
|
118
|
-
function
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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;
|
|
132
129
|
}
|
|
133
|
-
}
|
|
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
|
+
})();
|
|
134
151
|
debugConfig('Selected default model %s for provider %s', model, provider);
|
|
135
152
|
return model;
|
|
136
153
|
}
|
|
@@ -146,23 +163,32 @@ function getModel(provider, model) {
|
|
|
146
163
|
return google(modelName);
|
|
147
164
|
case AIProvider.XAI:
|
|
148
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
|
+
}
|
|
149
174
|
default:
|
|
150
175
|
throw new Error(`Unknown provider: ${provider}`);
|
|
151
176
|
}
|
|
152
177
|
}
|
|
153
|
-
export async function generateTextWithAI(prompt,
|
|
154
|
-
|
|
178
|
+
export async function generateTextWithAI(prompt, options = {}) {
|
|
179
|
+
const resolvedProvider = options.provider ?? getDefaultAIProvider();
|
|
180
|
+
debugAPI('generateTextWithAI called - provider: %s, promptLength: %d', resolvedProvider, prompt.length);
|
|
155
181
|
const finalOptions = { ...defaultOptions, ...options };
|
|
156
|
-
const model = finalOptions.model ?? getDefaultModel(
|
|
157
|
-
const modelInstance = getModel(
|
|
182
|
+
const model = finalOptions.model ?? getDefaultModel(resolvedProvider);
|
|
183
|
+
const modelInstance = getModel(resolvedProvider, model);
|
|
158
184
|
if (finalOptions.includeTools === true) {
|
|
159
185
|
debugTools('Tools requested, starting MCP server');
|
|
160
186
|
await startServer();
|
|
161
|
-
const result = await generateTextWithToolsAI(prompt,
|
|
187
|
+
const result = await generateTextWithToolsAI(prompt, options);
|
|
162
188
|
return result.text;
|
|
163
189
|
}
|
|
164
190
|
try {
|
|
165
|
-
debugAPI('Making API call to %s with model %s',
|
|
191
|
+
debugAPI('Making API call to %s with model %s', resolvedProvider, model);
|
|
166
192
|
debugAPI('Request params - temperature: %d, maxTokens: %d', finalOptions.temperature, finalOptions.maxTokens);
|
|
167
193
|
const result = await generateText({
|
|
168
194
|
model: modelInstance,
|
|
@@ -174,16 +200,17 @@ export async function generateTextWithAI(prompt, provider, options = {}) {
|
|
|
174
200
|
return result.text;
|
|
175
201
|
}
|
|
176
202
|
catch (error) {
|
|
177
|
-
extractAndLogError(error,
|
|
203
|
+
extractAndLogError(error, resolvedProvider, 'generateTextWithAI');
|
|
178
204
|
throw error;
|
|
179
205
|
}
|
|
180
206
|
}
|
|
181
|
-
export async function* streamTextWithAI(prompt,
|
|
182
|
-
|
|
207
|
+
export async function* streamTextWithAI(prompt, options = {}) {
|
|
208
|
+
const resolvedProvider = options.provider ?? getDefaultAIProvider();
|
|
209
|
+
debugStream('streamTextWithAI called - provider: %s, promptLength: %d', resolvedProvider, prompt.length);
|
|
183
210
|
const finalOptions = { ...defaultOptions, ...options };
|
|
184
|
-
const model = getModel(
|
|
211
|
+
const model = getModel(resolvedProvider, finalOptions.model);
|
|
185
212
|
try {
|
|
186
|
-
debugStream('Starting stream from %s',
|
|
213
|
+
debugStream('Starting stream from %s', resolvedProvider);
|
|
187
214
|
const stream = await streamText({
|
|
188
215
|
model,
|
|
189
216
|
prompt,
|
|
@@ -201,7 +228,7 @@ export async function* streamTextWithAI(prompt, provider, options = {}) {
|
|
|
201
228
|
debugStream('Stream completed - total chunks: %d, total length: %d', totalChunks, totalLength);
|
|
202
229
|
}
|
|
203
230
|
catch (error) {
|
|
204
|
-
extractAndLogError(error,
|
|
231
|
+
extractAndLogError(error, resolvedProvider, 'streamTextWithAI');
|
|
205
232
|
throw error;
|
|
206
233
|
}
|
|
207
234
|
}
|
|
@@ -210,11 +237,12 @@ export async function* streamTextWithAI(prompt, provider, options = {}) {
|
|
|
210
237
|
* Optionally calls a stream callback for each token if provided.
|
|
211
238
|
* Always returns the complete collected response.
|
|
212
239
|
*/
|
|
213
|
-
export async function generateTextStreamingWithAI(prompt,
|
|
214
|
-
|
|
240
|
+
export async function generateTextStreamingWithAI(prompt, options = {}) {
|
|
241
|
+
const resolvedProvider = options.provider ?? getDefaultAIProvider();
|
|
242
|
+
debugStream('generateTextStreamingWithAI called - provider: %s', resolvedProvider);
|
|
215
243
|
const finalOptions = { ...defaultOptions, ...options };
|
|
216
244
|
let collectedResult = '';
|
|
217
|
-
const stream = streamTextWithAI(prompt,
|
|
245
|
+
const stream = streamTextWithAI(prompt, finalOptions);
|
|
218
246
|
let tokenCount = 0;
|
|
219
247
|
for await (const token of stream) {
|
|
220
248
|
tokenCount++;
|
|
@@ -282,18 +310,19 @@ async function executeToolConversation(modelInstance, messages, registeredTools,
|
|
|
282
310
|
}
|
|
283
311
|
return { finalResult, allToolCalls };
|
|
284
312
|
}
|
|
285
|
-
export async function generateTextWithToolsAI(prompt,
|
|
286
|
-
|
|
313
|
+
export async function generateTextWithToolsAI(prompt, options = {}) {
|
|
314
|
+
const resolvedProvider = options.provider ?? getDefaultAIProvider();
|
|
315
|
+
debugTools('generateTextWithToolsAI called - provider: %s', resolvedProvider);
|
|
287
316
|
const finalOptions = { ...defaultOptions, ...options };
|
|
288
|
-
const model = finalOptions.model ?? getDefaultModel(
|
|
289
|
-
const modelInstance = getModel(
|
|
317
|
+
const model = finalOptions.model ?? getDefaultModel(resolvedProvider);
|
|
318
|
+
const modelInstance = getModel(resolvedProvider, model);
|
|
290
319
|
const registeredTools = finalOptions.includeTools === true ? getRegisteredToolsForAI() : {};
|
|
291
320
|
debugTools('Registered tools: %o', Object.keys(registeredTools));
|
|
292
321
|
const hasTools = Object.keys(registeredTools).length > 0;
|
|
293
322
|
debugTools('Has tools available: %s', hasTools);
|
|
294
323
|
// Build conversation messages
|
|
295
324
|
const messages = [{ role: 'user', content: prompt }];
|
|
296
|
-
const { finalResult, allToolCalls } = await executeToolConversation(modelInstance, messages, registeredTools, hasTools, finalOptions,
|
|
325
|
+
const { finalResult, allToolCalls } = await executeToolConversation(modelInstance, messages, registeredTools, hasTools, finalOptions, resolvedProvider);
|
|
297
326
|
return {
|
|
298
327
|
text: finalResult,
|
|
299
328
|
toolCalls: allToolCalls,
|
|
@@ -325,17 +354,18 @@ async function executeToolCalls(toolCalls, registeredTools) {
|
|
|
325
354
|
}
|
|
326
355
|
return toolResults;
|
|
327
356
|
}
|
|
328
|
-
export async function generateTextWithImageAI(text, imageBase64,
|
|
329
|
-
|
|
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);
|
|
330
360
|
const finalOptions = { ...defaultOptions, ...options };
|
|
331
|
-
const model = finalOptions.model ?? getDefaultModel(
|
|
332
|
-
const modelInstance = getModel(
|
|
333
|
-
if (
|
|
334
|
-
debugError('Provider %s does not support image inputs',
|
|
335
|
-
throw new Error(`Provider ${
|
|
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`);
|
|
336
366
|
}
|
|
337
367
|
try {
|
|
338
|
-
debugAPI('Sending image+text to %s',
|
|
368
|
+
debugAPI('Sending image+text to %s', resolvedProvider);
|
|
339
369
|
const result = await generateText({
|
|
340
370
|
model: modelInstance,
|
|
341
371
|
messages: [
|
|
@@ -354,21 +384,23 @@ export async function generateTextWithImageAI(text, imageBase64, provider, optio
|
|
|
354
384
|
return result.text;
|
|
355
385
|
}
|
|
356
386
|
catch (error) {
|
|
357
|
-
extractAndLogError(error,
|
|
387
|
+
extractAndLogError(error, resolvedProvider, 'generateTextWithImageAI');
|
|
358
388
|
throw error;
|
|
359
389
|
}
|
|
360
390
|
}
|
|
361
391
|
export function getAvailableProviders() {
|
|
362
392
|
const config = configureAIProvider();
|
|
363
393
|
const providers = [];
|
|
364
|
-
if (config.openai != null)
|
|
365
|
-
providers.push(AIProvider.OpenAI);
|
|
366
394
|
if (config.anthropic != null)
|
|
367
395
|
providers.push(AIProvider.Anthropic);
|
|
396
|
+
if (config.openai != null)
|
|
397
|
+
providers.push(AIProvider.OpenAI);
|
|
368
398
|
if (config.google != null)
|
|
369
399
|
providers.push(AIProvider.Google);
|
|
370
400
|
if (config.xai != null)
|
|
371
401
|
providers.push(AIProvider.XAI);
|
|
402
|
+
if (config.custom != null)
|
|
403
|
+
providers.push(AIProvider.Custom);
|
|
372
404
|
debugConfig('Available providers: %o', providers);
|
|
373
405
|
return providers;
|
|
374
406
|
}
|
|
@@ -459,8 +491,9 @@ async function attemptStructuredGeneration(prompt, provider, options, registered
|
|
|
459
491
|
// If we exhausted all retries, throw the last error
|
|
460
492
|
throw lastError;
|
|
461
493
|
}
|
|
462
|
-
export async function generateStructuredDataWithAI(prompt,
|
|
463
|
-
|
|
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');
|
|
464
497
|
if (options.includeTools === true) {
|
|
465
498
|
debugTools('Tools requested, starting MCP server');
|
|
466
499
|
await startServer();
|
|
@@ -468,16 +501,17 @@ export async function generateStructuredDataWithAI(prompt, provider, options) {
|
|
|
468
501
|
const registeredTools = options.includeTools === true ? getRegisteredToolsForAI() : {};
|
|
469
502
|
debugTools('Registered tools for structured data: %o', Object.keys(registeredTools));
|
|
470
503
|
const hasTools = Object.keys(registeredTools).length > 0;
|
|
471
|
-
return attemptStructuredGeneration(prompt,
|
|
504
|
+
return attemptStructuredGeneration(prompt, resolvedProvider, options, registeredTools, hasTools);
|
|
472
505
|
}
|
|
473
|
-
export async function streamStructuredDataWithAI(prompt,
|
|
474
|
-
|
|
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');
|
|
475
509
|
const maxSchemaRetries = 3;
|
|
476
510
|
let lastError;
|
|
477
511
|
for (let attempt = 0; attempt < maxSchemaRetries; attempt++) {
|
|
478
512
|
try {
|
|
479
513
|
debugValidation('Stream structured data attempt %d/%d', attempt + 1, maxSchemaRetries);
|
|
480
|
-
const model = getModel(
|
|
514
|
+
const model = getModel(resolvedProvider, options.model);
|
|
481
515
|
const enhancedPrompt = attempt > 0 && lastError ? getEnhancedPrompt(prompt, lastError) : prompt;
|
|
482
516
|
const result = streamObject({
|
|
483
517
|
model,
|