@happyvertical/ai 0.74.8
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/AGENT.md +33 -0
- package/LICENSE +7 -0
- package/README.md +384 -0
- package/dist/chunks/anthropic-BRwbhwIl.js +463 -0
- package/dist/chunks/anthropic-BRwbhwIl.js.map +1 -0
- package/dist/chunks/bedrock-Cf1xUerN.js +808 -0
- package/dist/chunks/bedrock-Cf1xUerN.js.map +1 -0
- package/dist/chunks/bifrost-3mXtQsTj.js +233 -0
- package/dist/chunks/bifrost-3mXtQsTj.js.map +1 -0
- package/dist/chunks/claude-cli-BrHRfkry.js +603 -0
- package/dist/chunks/claude-cli-BrHRfkry.js.map +1 -0
- package/dist/chunks/gateway-admin-C4GFPbZF.js +359 -0
- package/dist/chunks/gateway-admin-C4GFPbZF.js.map +1 -0
- package/dist/chunks/gemini-BfpHXDIQ.js +662 -0
- package/dist/chunks/gemini-BfpHXDIQ.js.map +1 -0
- package/dist/chunks/huggingface-280qv9iv.js +366 -0
- package/dist/chunks/huggingface-280qv9iv.js.map +1 -0
- package/dist/chunks/index-BT4thAvS.js +934 -0
- package/dist/chunks/index-BT4thAvS.js.map +1 -0
- package/dist/chunks/litellm-DhPKa_Jz.js +220 -0
- package/dist/chunks/litellm-DhPKa_Jz.js.map +1 -0
- package/dist/chunks/ollama-Di1ldur0.js +851 -0
- package/dist/chunks/ollama-Di1ldur0.js.map +1 -0
- package/dist/chunks/openai-5snI2diE.js +749 -0
- package/dist/chunks/openai-5snI2diE.js.map +1 -0
- package/dist/chunks/qwen-tts-DgPgdXxG.js +365 -0
- package/dist/chunks/qwen-tts-DgPgdXxG.js.map +1 -0
- package/dist/chunks/usage-DMWiJ2oB.js +21 -0
- package/dist/chunks/usage-DMWiJ2oB.js.map +1 -0
- package/dist/cli/claude-context.d.ts +3 -0
- package/dist/cli/claude-context.d.ts.map +1 -0
- package/dist/cli/claude-context.js +21 -0
- package/dist/cli/claude-context.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/node/factory.d.ts +27 -0
- package/dist/node/factory.d.ts.map +1 -0
- package/dist/shared/client.d.ts +410 -0
- package/dist/shared/client.d.ts.map +1 -0
- package/dist/shared/factory.d.ts +83 -0
- package/dist/shared/factory.d.ts.map +1 -0
- package/dist/shared/message.d.ts +71 -0
- package/dist/shared/message.d.ts.map +1 -0
- package/dist/shared/providers/anthropic.d.ts +82 -0
- package/dist/shared/providers/anthropic.d.ts.map +1 -0
- package/dist/shared/providers/bedrock.d.ts +49 -0
- package/dist/shared/providers/bedrock.d.ts.map +1 -0
- package/dist/shared/providers/bifrost.d.ts +25 -0
- package/dist/shared/providers/bifrost.d.ts.map +1 -0
- package/dist/shared/providers/claude-cli.d.ts +139 -0
- package/dist/shared/providers/claude-cli.d.ts.map +1 -0
- package/dist/shared/providers/gateway-admin.d.ts +35 -0
- package/dist/shared/providers/gateway-admin.d.ts.map +1 -0
- package/dist/shared/providers/gemini.d.ts +116 -0
- package/dist/shared/providers/gemini.d.ts.map +1 -0
- package/dist/shared/providers/huggingface.d.ts +33 -0
- package/dist/shared/providers/huggingface.d.ts.map +1 -0
- package/dist/shared/providers/litellm.d.ts +25 -0
- package/dist/shared/providers/litellm.d.ts.map +1 -0
- package/dist/shared/providers/ollama.d.ts +47 -0
- package/dist/shared/providers/ollama.d.ts.map +1 -0
- package/dist/shared/providers/openai.d.ts +272 -0
- package/dist/shared/providers/openai.d.ts.map +1 -0
- package/dist/shared/providers/qwen-tts.d.ts +85 -0
- package/dist/shared/providers/qwen-tts.d.ts.map +1 -0
- package/dist/shared/providers/usage.d.ts +14 -0
- package/dist/shared/providers/usage.d.ts.map +1 -0
- package/dist/shared/rate-limit.d.ts +13 -0
- package/dist/shared/rate-limit.d.ts.map +1 -0
- package/dist/shared/thread.d.ts +104 -0
- package/dist/shared/thread.d.ts.map +1 -0
- package/dist/shared/types.d.ts +1779 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/metadata.json +35 -0
- package/package.json +62 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AIInterface } from '../shared/types';
|
|
2
|
+
/**
|
|
3
|
+
* Re-export the universal getAI function
|
|
4
|
+
*/
|
|
5
|
+
export { getAI } from '../shared/factory';
|
|
6
|
+
/**
|
|
7
|
+
* Node.js-enhanced auto-detection of AI provider based on available credentials
|
|
8
|
+
* Includes support for environment variables
|
|
9
|
+
*
|
|
10
|
+
* Supports both HAVE_AI_* environment variables and provider-specific variables:
|
|
11
|
+
* - HAVE_AI_PROVIDER / HAVE_AI_TYPE → provider type
|
|
12
|
+
* - HAVE_AI_API_KEY → fallback API key
|
|
13
|
+
* - LITELLM_BASE_URL / LITELLM_API_KEY / LITELLM_ADMIN_API_KEY → LiteLLM-specific gateway config
|
|
14
|
+
* - BIFROST_BASE_URL / BIFROST_API_KEY / BIFROST_ADMIN_URL / BIFROST_ADMIN_USER / BIFROST_ADMIN_PASSWORD → Bifrost gateway config
|
|
15
|
+
* - OLLAMA_HOST / OLLAMA_BASE_URL / OLLAMA_API_KEY → Ollama host/auth config
|
|
16
|
+
* - OPENAI_API_KEY → OpenAI-specific key
|
|
17
|
+
* - ANTHROPIC_API_KEY → Anthropic-specific key
|
|
18
|
+
* - GEMINI_API_KEY / GOOGLE_API_KEY → Gemini-specific key
|
|
19
|
+
* - HF_TOKEN → Hugging Face token
|
|
20
|
+
* - AWS_* → AWS Bedrock credentials
|
|
21
|
+
*
|
|
22
|
+
* @param options - Configuration options that may contain provider-specific credentials
|
|
23
|
+
* @returns Promise resolving to an AI provider instance
|
|
24
|
+
* @throws ValidationError if no provider can be detected from the options
|
|
25
|
+
*/
|
|
26
|
+
export declare function getAIAuto(options?: Record<string, any>): Promise<AIInterface>;
|
|
27
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/node/factory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EACV,WAAW,EAWZ,MAAM,iBAAiB,CAAC;AAGzB;;GAEG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,SAAS,CAC7B,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAChC,OAAO,CAAC,WAAW,CAAC,CA8NtB"}
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import { default as OpenAI } from 'openai';
|
|
2
|
+
import { AIMessageOptions } from './message';
|
|
3
|
+
import { AIProviderType, AIRateLimitOptions } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Common options for AI client configuration
|
|
6
|
+
*/
|
|
7
|
+
export interface AIClientOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Type of AI client (e.g., 'openai')
|
|
10
|
+
*/
|
|
11
|
+
type?: AIProviderType | string;
|
|
12
|
+
/**
|
|
13
|
+
* Response format for AI completions
|
|
14
|
+
*/
|
|
15
|
+
responseFormat?: string;
|
|
16
|
+
/**
|
|
17
|
+
* API key for authentication
|
|
18
|
+
*/
|
|
19
|
+
apiKey?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Base URL for API requests
|
|
22
|
+
*/
|
|
23
|
+
baseUrl?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Admin API key for gateway providers that support provisioning.
|
|
26
|
+
*/
|
|
27
|
+
adminApiKey?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Admin base URL for gateway providers when it differs from `baseUrl`.
|
|
30
|
+
*/
|
|
31
|
+
adminBaseUrl?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Alias for adminBaseUrl.
|
|
34
|
+
*/
|
|
35
|
+
adminUrl?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Admin username for providers that use HTTP Basic auth.
|
|
38
|
+
*/
|
|
39
|
+
adminUser?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Admin username for providers that use HTTP Basic auth.
|
|
42
|
+
*/
|
|
43
|
+
adminUsername?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Admin password for providers that use HTTP Basic auth.
|
|
46
|
+
*/
|
|
47
|
+
adminPassword?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Custom admin headers for gateway providers.
|
|
50
|
+
*/
|
|
51
|
+
adminHeaders?: Record<string, string>;
|
|
52
|
+
/**
|
|
53
|
+
* Optional shared pacing / retry configuration for getAI().
|
|
54
|
+
*/
|
|
55
|
+
rateLimit?: AIRateLimitOptions;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Interface defining required methods for AI clients
|
|
59
|
+
*/
|
|
60
|
+
export interface AIClientInterface {
|
|
61
|
+
/**
|
|
62
|
+
* Configuration options for this client
|
|
63
|
+
*/
|
|
64
|
+
options: AIClientOptions;
|
|
65
|
+
/**
|
|
66
|
+
* Sends a message to the AI and gets a response
|
|
67
|
+
*
|
|
68
|
+
* @param text - Message text
|
|
69
|
+
* @param options - Message options
|
|
70
|
+
* @returns Promise resolving to the AI response
|
|
71
|
+
*/
|
|
72
|
+
message(text: string, options: AIMessageOptions): Promise<unknown>;
|
|
73
|
+
/**
|
|
74
|
+
* Gets a text completion from the AI
|
|
75
|
+
*
|
|
76
|
+
* @param text - Input text for completion
|
|
77
|
+
* @param options - Completion options
|
|
78
|
+
* @returns Promise resolving to the completion result
|
|
79
|
+
*/
|
|
80
|
+
textCompletion(text: string, options: AIMessageOptions): Promise<unknown>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Options for AI text completion requests
|
|
84
|
+
*/
|
|
85
|
+
export interface AITextCompletionOptions {
|
|
86
|
+
/**
|
|
87
|
+
* Model identifier to use
|
|
88
|
+
*/
|
|
89
|
+
model?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Timeout in milliseconds
|
|
92
|
+
*/
|
|
93
|
+
timeout?: number;
|
|
94
|
+
/**
|
|
95
|
+
* Role of the message sender
|
|
96
|
+
*/
|
|
97
|
+
role?: OpenAI.Chat.ChatCompletionRole;
|
|
98
|
+
/**
|
|
99
|
+
* Previous messages in the conversation
|
|
100
|
+
*/
|
|
101
|
+
history?: OpenAI.Chat.ChatCompletionMessageParam[];
|
|
102
|
+
/**
|
|
103
|
+
* Name of the message sender
|
|
104
|
+
*/
|
|
105
|
+
name?: string;
|
|
106
|
+
/**
|
|
107
|
+
* Penalty for token frequency
|
|
108
|
+
*/
|
|
109
|
+
frequencyPenalty?: number;
|
|
110
|
+
/**
|
|
111
|
+
* Token bias adjustments
|
|
112
|
+
*/
|
|
113
|
+
logitBias?: Record<string, number>;
|
|
114
|
+
/**
|
|
115
|
+
* Whether to return log probabilities
|
|
116
|
+
*/
|
|
117
|
+
logprobs?: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Number of top log probabilities to return
|
|
120
|
+
*/
|
|
121
|
+
topLogprobs?: number;
|
|
122
|
+
/**
|
|
123
|
+
* Maximum tokens to generate
|
|
124
|
+
*/
|
|
125
|
+
maxTokens?: number;
|
|
126
|
+
/**
|
|
127
|
+
* Number of completions to generate
|
|
128
|
+
*/
|
|
129
|
+
n?: number;
|
|
130
|
+
/**
|
|
131
|
+
* Penalty for token presence
|
|
132
|
+
*/
|
|
133
|
+
presencePenalty?: number;
|
|
134
|
+
/**
|
|
135
|
+
* Format for the response
|
|
136
|
+
*/
|
|
137
|
+
responseFormat?: {
|
|
138
|
+
type: 'text' | 'json_object';
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Random seed for deterministic results
|
|
142
|
+
*/
|
|
143
|
+
seed?: number;
|
|
144
|
+
/**
|
|
145
|
+
* Sequences that stop generation
|
|
146
|
+
*/
|
|
147
|
+
stop?: string | Array<string>;
|
|
148
|
+
/**
|
|
149
|
+
* Whether to stream responses
|
|
150
|
+
*/
|
|
151
|
+
stream?: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Sampling temperature
|
|
154
|
+
*/
|
|
155
|
+
temperature?: number;
|
|
156
|
+
/**
|
|
157
|
+
* Top-p sampling parameter
|
|
158
|
+
*/
|
|
159
|
+
topProbability?: number;
|
|
160
|
+
/**
|
|
161
|
+
* Available tools for the model
|
|
162
|
+
*/
|
|
163
|
+
tools?: Array<any>;
|
|
164
|
+
/**
|
|
165
|
+
* Tool selection behavior
|
|
166
|
+
*/
|
|
167
|
+
toolChoice?: 'none' | 'auto' | {
|
|
168
|
+
type: 'function';
|
|
169
|
+
function: {
|
|
170
|
+
name: string;
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* User identifier
|
|
175
|
+
*/
|
|
176
|
+
user?: string;
|
|
177
|
+
/**
|
|
178
|
+
* Callback for handling streaming responses
|
|
179
|
+
*/
|
|
180
|
+
onProgress?: (partialMessage: string) => void;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Base class for AI clients
|
|
184
|
+
* Provides a common interface for different AI service providers
|
|
185
|
+
*/
|
|
186
|
+
export declare class AIClient {
|
|
187
|
+
/**
|
|
188
|
+
* Configuration options for this client
|
|
189
|
+
*/
|
|
190
|
+
options: AIClientOptions;
|
|
191
|
+
/**
|
|
192
|
+
* Creates a new AIClient
|
|
193
|
+
*
|
|
194
|
+
* @param options - Client configuration options
|
|
195
|
+
*/
|
|
196
|
+
constructor(options: AIClientOptions);
|
|
197
|
+
/**
|
|
198
|
+
* Sends a message to the AI
|
|
199
|
+
* Base implementation returns a placeholder response
|
|
200
|
+
*
|
|
201
|
+
* @param text - Message text
|
|
202
|
+
* @param options - Message options
|
|
203
|
+
* @returns Promise resolving to a placeholder response
|
|
204
|
+
*/
|
|
205
|
+
message(_text: string, _options?: AITextCompletionOptions): Promise<string>;
|
|
206
|
+
/**
|
|
207
|
+
* Factory method to create appropriate AI client based on options
|
|
208
|
+
*
|
|
209
|
+
* @param options - Client configuration options
|
|
210
|
+
* @returns Promise resolving to an initialized AI client
|
|
211
|
+
* @throws Error if client type is invalid
|
|
212
|
+
*/
|
|
213
|
+
static create(options: AIClientOptions | AIClient): Promise<AIClient | OpenAIClient>;
|
|
214
|
+
/**
|
|
215
|
+
* Gets a text completion from the AI
|
|
216
|
+
* In base class, delegates to message method
|
|
217
|
+
*
|
|
218
|
+
* @param text - Input text for completion
|
|
219
|
+
* @param options - Completion options
|
|
220
|
+
* @returns Promise resolving to the completion result
|
|
221
|
+
*/
|
|
222
|
+
textCompletion(text: string, options?: AITextCompletionOptions): Promise<string>;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Creates an OpenAI client instance
|
|
226
|
+
*
|
|
227
|
+
* @param options - OpenAI configuration options
|
|
228
|
+
* @returns Promise resolving to an OpenAI client
|
|
229
|
+
*/
|
|
230
|
+
export declare function getOpenAI(options: {
|
|
231
|
+
apiKey?: string;
|
|
232
|
+
baseUrl?: string;
|
|
233
|
+
}): Promise<OpenAI>;
|
|
234
|
+
/**
|
|
235
|
+
* Options specific to OpenAI text completion requests
|
|
236
|
+
*/
|
|
237
|
+
export interface OpenAITextCompletionOptions {
|
|
238
|
+
/**
|
|
239
|
+
* Model identifier to use
|
|
240
|
+
*/
|
|
241
|
+
model?: string;
|
|
242
|
+
/**
|
|
243
|
+
* Timeout in milliseconds
|
|
244
|
+
*/
|
|
245
|
+
timeout?: number;
|
|
246
|
+
/**
|
|
247
|
+
* Role of the message sender
|
|
248
|
+
*/
|
|
249
|
+
role?: OpenAI.Chat.ChatCompletionRole;
|
|
250
|
+
/**
|
|
251
|
+
* Previous messages in the conversation
|
|
252
|
+
*/
|
|
253
|
+
history?: Array<OpenAI.Chat.ChatCompletionMessageParam>;
|
|
254
|
+
/**
|
|
255
|
+
* Name of the message sender
|
|
256
|
+
*/
|
|
257
|
+
name?: string;
|
|
258
|
+
/**
|
|
259
|
+
* Penalty for token frequency
|
|
260
|
+
*/
|
|
261
|
+
frequencyPenalty?: number;
|
|
262
|
+
/**
|
|
263
|
+
* Token bias adjustments
|
|
264
|
+
*/
|
|
265
|
+
logitBias?: Record<string, number>;
|
|
266
|
+
/**
|
|
267
|
+
* Whether to return log probabilities
|
|
268
|
+
*/
|
|
269
|
+
logprobs?: boolean;
|
|
270
|
+
/**
|
|
271
|
+
* Number of top log probabilities to return
|
|
272
|
+
*/
|
|
273
|
+
topLogprobs?: number;
|
|
274
|
+
/**
|
|
275
|
+
* Maximum tokens to generate
|
|
276
|
+
*/
|
|
277
|
+
maxTokens?: number;
|
|
278
|
+
/**
|
|
279
|
+
* Number of completions to generate
|
|
280
|
+
*/
|
|
281
|
+
n?: number;
|
|
282
|
+
/**
|
|
283
|
+
* Penalty for token presence
|
|
284
|
+
*/
|
|
285
|
+
presencePenalty?: number;
|
|
286
|
+
/**
|
|
287
|
+
* Format for the response
|
|
288
|
+
*/
|
|
289
|
+
responseFormat?: {
|
|
290
|
+
type: 'text' | 'json_object';
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* Random seed for deterministic results
|
|
294
|
+
*/
|
|
295
|
+
seed?: number;
|
|
296
|
+
/**
|
|
297
|
+
* Sequences that stop generation
|
|
298
|
+
*/
|
|
299
|
+
stop?: string | Array<string>;
|
|
300
|
+
/**
|
|
301
|
+
* Whether to stream responses
|
|
302
|
+
*/
|
|
303
|
+
stream?: boolean;
|
|
304
|
+
/**
|
|
305
|
+
* Sampling temperature
|
|
306
|
+
*/
|
|
307
|
+
temperature?: number;
|
|
308
|
+
/**
|
|
309
|
+
* Top-p sampling parameter
|
|
310
|
+
*/
|
|
311
|
+
topProbability?: number;
|
|
312
|
+
/**
|
|
313
|
+
* Available tools for the model
|
|
314
|
+
*/
|
|
315
|
+
tools?: Array<OpenAI.Chat.ChatCompletionTool>;
|
|
316
|
+
/**
|
|
317
|
+
* Tool selection behavior
|
|
318
|
+
*/
|
|
319
|
+
toolChoice?: 'none' | 'auto' | {
|
|
320
|
+
type: 'function';
|
|
321
|
+
function: {
|
|
322
|
+
name: string;
|
|
323
|
+
};
|
|
324
|
+
};
|
|
325
|
+
/**
|
|
326
|
+
* User identifier
|
|
327
|
+
*/
|
|
328
|
+
user?: string;
|
|
329
|
+
/**
|
|
330
|
+
* Callback for handling streaming responses
|
|
331
|
+
*/
|
|
332
|
+
onProgress?: (partialMessage: string) => void;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Configuration options specific to OpenAI client
|
|
336
|
+
*/
|
|
337
|
+
export interface OpenAIClientOptions extends AIClientOptions {
|
|
338
|
+
/**
|
|
339
|
+
* OpenAI API key
|
|
340
|
+
*/
|
|
341
|
+
apiKey?: string;
|
|
342
|
+
/**
|
|
343
|
+
* OpenAI API base URL
|
|
344
|
+
*/
|
|
345
|
+
baseUrl?: string;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Client implementation for the OpenAI API
|
|
349
|
+
*/
|
|
350
|
+
export declare class OpenAIClient extends AIClient {
|
|
351
|
+
/**
|
|
352
|
+
* OpenAI client instance
|
|
353
|
+
*/
|
|
354
|
+
protected openai: OpenAI;
|
|
355
|
+
/**
|
|
356
|
+
* Configuration options for this client
|
|
357
|
+
*/
|
|
358
|
+
options: OpenAIClientOptions;
|
|
359
|
+
/**
|
|
360
|
+
* Creates a new OpenAIClient
|
|
361
|
+
*
|
|
362
|
+
* @param options - OpenAI client configuration options
|
|
363
|
+
*/
|
|
364
|
+
constructor(options: OpenAIClientOptions);
|
|
365
|
+
/**
|
|
366
|
+
* Sends a message to OpenAI
|
|
367
|
+
*
|
|
368
|
+
* @param text - Message text
|
|
369
|
+
* @param options - Message options
|
|
370
|
+
* @returns Promise resolving to the OpenAI response
|
|
371
|
+
*/
|
|
372
|
+
message(text: string, options?: AIMessageOptions): Promise<string>;
|
|
373
|
+
/**
|
|
374
|
+
* Factory method to create and initialize an OpenAIClient
|
|
375
|
+
*
|
|
376
|
+
* @param options - OpenAI client configuration options
|
|
377
|
+
* @returns Promise resolving to an initialized OpenAIClient
|
|
378
|
+
*/
|
|
379
|
+
static create(options: OpenAIClientOptions): Promise<OpenAIClient>;
|
|
380
|
+
/**
|
|
381
|
+
* Initializes the OpenAI client
|
|
382
|
+
*/
|
|
383
|
+
protected initialize(): Promise<void>;
|
|
384
|
+
/**
|
|
385
|
+
* Sends a text completion request to the OpenAI API
|
|
386
|
+
*
|
|
387
|
+
* @param message - The message to send
|
|
388
|
+
* @param options - Configuration options for the completion request
|
|
389
|
+
* @returns Promise resolving to the completion text
|
|
390
|
+
* @throws Error if the OpenAI API response is invalid
|
|
391
|
+
*/
|
|
392
|
+
textCompletion(message: string, options?: OpenAITextCompletionOptions): Promise<string>;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Options for getting an AI client with type information
|
|
396
|
+
*/
|
|
397
|
+
type GetAIClientOptions = AIClientOptions & {
|
|
398
|
+
type?: AIProviderType;
|
|
399
|
+
};
|
|
400
|
+
/**
|
|
401
|
+
* Factory function to create and initialize an appropriate AI client
|
|
402
|
+
* Delegates to the modern getAI() factory for all provider types
|
|
403
|
+
*
|
|
404
|
+
* @param options - Client configuration options
|
|
405
|
+
* @returns Promise resolving to an initialized AI client
|
|
406
|
+
* @throws Error if client type is invalid
|
|
407
|
+
*/
|
|
408
|
+
export declare function getAIClient(options: GetAIClientOptions): Promise<AIClient>;
|
|
409
|
+
export {};
|
|
410
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/shared/client.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGlE;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,IAAI,CAAC,EAAE,cAAc,GAAG,MAAM,CA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,CACzB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,MAAM,CAAC;CAkGnB;AAED;;GAEG;AACH,KAAK,kBAAkB,GAAG,eAAe,GAAG;IAC1C,IAAI,CAAC,EAAE,cAAc,CAAC;CACvB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,QAAQ,CAAC,CAInB"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { AIClientOptions } from './client';
|
|
2
|
+
import { AIInterface, GetAIOptions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Creates an AI provider instance based on the provided options.
|
|
5
|
+
* Universal version that works in both browser and Node.js environments.
|
|
6
|
+
*
|
|
7
|
+
* Supports environment variable configuration using the pattern:
|
|
8
|
+
* - HAVE_AI_PROVIDER → provider type (string)
|
|
9
|
+
* - HAVE_AI_MODEL → defaultModel (string)
|
|
10
|
+
* - HAVE_AI_TIMEOUT → timeout (number)
|
|
11
|
+
* - HAVE_AI_MAX_RETRIES → maxRetries (number)
|
|
12
|
+
* - HAVE_AI_API_KEY → apiKey (string) - fallback if provider-specific key not set
|
|
13
|
+
* - HAVE_AI_BASE_URL → baseUrl (string)
|
|
14
|
+
*
|
|
15
|
+
* User-provided options always take precedence over environment variables.
|
|
16
|
+
*
|
|
17
|
+
* Accepts both GetAIOptions (provider-specific options with literal types)
|
|
18
|
+
* and AIClientOptions (legacy interface with generic string type) for
|
|
19
|
+
* backward compatibility with existing code.
|
|
20
|
+
*
|
|
21
|
+
* @param options - Configuration options for the AI provider. Can be GetAIOptions or AIClientOptions.
|
|
22
|
+
* @returns Promise resolving to an AI provider instance that implements the AIInterface
|
|
23
|
+
* @throws {ValidationError} When the provider type is unsupported or invalid
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* // Create OpenAI client with explicit options
|
|
28
|
+
* const openai = await getAI({
|
|
29
|
+
* type: 'openai',
|
|
30
|
+
* apiKey: process.env.OPENAI_API_KEY!,
|
|
31
|
+
* defaultModel: 'gpt-4o'
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* // Or use environment variables (HAVE_AI_PROVIDER=openai, HAVE_AI_API_KEY=sk-...)
|
|
35
|
+
* const client = await getAI({});
|
|
36
|
+
*
|
|
37
|
+
* // Create Anthropic client
|
|
38
|
+
* const anthropic = await getAI({
|
|
39
|
+
* type: 'anthropic',
|
|
40
|
+
* apiKey: process.env.ANTHROPIC_API_KEY!,
|
|
41
|
+
* defaultModel: 'claude-3-5-sonnet-20241022'
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // Works with AIClientOptions (legacy interface)
|
|
45
|
+
* const clientOptions: AIClientOptions = { type: 'openai', apiKey: '...' };
|
|
46
|
+
* const legacy = await getAI(clientOptions);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function getAI(options?: GetAIOptions | AIClientOptions): Promise<AIInterface>;
|
|
50
|
+
/**
|
|
51
|
+
* Browser-compatible auto-detection of AI provider based on available credentials.
|
|
52
|
+
* Does not rely on process.env, making it suitable for browser environments.
|
|
53
|
+
*
|
|
54
|
+
* @param options - Configuration options that may contain provider-specific credentials
|
|
55
|
+
* @returns Promise resolving to an AI provider instance based on detected credentials
|
|
56
|
+
* @throws {ValidationError} When no provider can be detected from the provided options
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* // Auto-detect OpenAI from apiKey
|
|
61
|
+
* const client1 = await getAIAuto({
|
|
62
|
+
* apiKey: 'sk-...', // Detected as OpenAI
|
|
63
|
+
* defaultModel: 'gpt-4o'
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* // Auto-detect Hugging Face from apiToken
|
|
67
|
+
* const client2 = await getAIAuto({
|
|
68
|
+
* apiToken: 'hf_...', // Detected as Hugging Face
|
|
69
|
+
* model: 'microsoft/DialoGPT-medium'
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* // Auto-detect AWS Bedrock from region and credentials
|
|
73
|
+
* const client3 = await getAIAuto({
|
|
74
|
+
* region: 'us-east-1',
|
|
75
|
+
* credentials: {
|
|
76
|
+
* accessKeyId: 'AKIA...',
|
|
77
|
+
* secretAccessKey: 'xxx'
|
|
78
|
+
* }
|
|
79
|
+
* });
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare function getAIAuto(options: Record<string, any>): Promise<AIInterface>;
|
|
83
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/shared/factory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhD,OAAO,KAAK,EACV,WAAW,EAOX,YAAY,EAMb,MAAM,SAAS,CAAC;AAqHjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,wBAAsB,KAAK,CACzB,OAAO,GAAE,YAAY,GAAG,eAAoB,GAC3C,OAAO,CAAC,WAAW,CAAC,CAwEtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAsB,SAAS,CAC7B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC3B,OAAO,CAAC,WAAW,CAAC,CA6CtB"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { AIThread } from './thread';
|
|
2
|
+
/**
|
|
3
|
+
* Options for creating AI messages
|
|
4
|
+
*/
|
|
5
|
+
export interface AIMessageOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Role of the message sender
|
|
8
|
+
*/
|
|
9
|
+
role?: 'user' | 'assistant' | 'system';
|
|
10
|
+
/**
|
|
11
|
+
* Format for the AI response
|
|
12
|
+
*/
|
|
13
|
+
responseFormat?: {
|
|
14
|
+
type: 'text' | 'json_object';
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Represents a message in an AI conversation
|
|
19
|
+
*/
|
|
20
|
+
export declare class AIMessage {
|
|
21
|
+
/**
|
|
22
|
+
* Original options used to create this message
|
|
23
|
+
*/
|
|
24
|
+
protected options: {
|
|
25
|
+
role: "user" | "assistant" | "system";
|
|
26
|
+
content: string;
|
|
27
|
+
name: string;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Name of the message sender
|
|
31
|
+
*/
|
|
32
|
+
name: string;
|
|
33
|
+
/**
|
|
34
|
+
* Content of the message
|
|
35
|
+
*/
|
|
36
|
+
content: string;
|
|
37
|
+
/**
|
|
38
|
+
* Role of the message sender in the conversation
|
|
39
|
+
*/
|
|
40
|
+
role: 'user' | 'assistant' | 'system';
|
|
41
|
+
/**
|
|
42
|
+
* Creates a new AI message
|
|
43
|
+
*
|
|
44
|
+
* @param options - Message configuration
|
|
45
|
+
* @param options.role - Role of the message sender
|
|
46
|
+
* @param options.content - Content of the message
|
|
47
|
+
* @param options.name - Name of the message sender
|
|
48
|
+
*/
|
|
49
|
+
constructor(options: {
|
|
50
|
+
role: 'user' | 'assistant' | 'system';
|
|
51
|
+
content: string;
|
|
52
|
+
name: string;
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* Factory method to create a new AI message
|
|
56
|
+
*
|
|
57
|
+
* @param options - Message configuration
|
|
58
|
+
* @param options.thread - Thread this message belongs to
|
|
59
|
+
* @param options.role - Role of the message sender
|
|
60
|
+
* @param options.content - Content of the message
|
|
61
|
+
* @param options.name - Name of the message sender
|
|
62
|
+
* @returns Promise resolving to a new AIMessage instance
|
|
63
|
+
*/
|
|
64
|
+
static create(options: {
|
|
65
|
+
thread: AIThread;
|
|
66
|
+
role: 'user' | 'assistant' | 'system';
|
|
67
|
+
content: string;
|
|
68
|
+
name: string;
|
|
69
|
+
}): Promise<AIMessage>;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/shared/message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;IAEvC;;OAEG;IACH,cAAc,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,GAAG,aAAa,CAAA;KAAE,CAAC;CACnD;AAED;;GAEG;AACH,qBAAa,SAAS;IACpB;;OAEG;IACH,SAAS,CAAC,OAAO;cA0BT,MAAM,GAAG,WAAW,GAAG,QAAQ;iBAC5B,MAAM;cACT,MAAM;MA5BI;IAElB;;OAEG;IACI,IAAI,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACI,OAAO,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACI,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;IAE7C;;;;;;;OAOG;gBACS,OAAO,EAAE;QACnB,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;QACtC,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;KACd;IAOD;;;;;;;;;OASG;WACU,MAAM,CAAC,OAAO,EAAE;QAC3B,MAAM,EAAE,QAAQ,CAAC;QACjB,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;QACtC,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;KACd;CAGF"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { AICapabilities, AIInterface, AIMessage, AIModel, AIResponse, AnthropicOptions, ChatOptions, CompletionOptions, EmbeddingOptions, EmbeddingResponse, ImageDescriptionOptions, ImageEmbeddingOptions, ImageGenerationOptions, ImageGenerationResponse, MessageOptions, TTSOptions, TTSResponse, Voice, VoiceCloneOptions, VoiceDesignOptions, VoiceListOptions } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Anthropic Claude provider implementation that handles all interactions with Anthropic's API.
|
|
4
|
+
* Supports Claude models, streaming, vision capabilities, and function calling.
|
|
5
|
+
* Does not support embeddings (use OpenAI or another provider for embeddings).
|
|
6
|
+
*/
|
|
7
|
+
export declare class AnthropicProvider implements AIInterface {
|
|
8
|
+
private options;
|
|
9
|
+
private client;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new Anthropic provider instance
|
|
12
|
+
* @param options - Configuration options for the Anthropic provider
|
|
13
|
+
*/
|
|
14
|
+
constructor(options: AnthropicOptions);
|
|
15
|
+
private initializeClientSync;
|
|
16
|
+
/**
|
|
17
|
+
* Ensures the Anthropic client is initialized by dynamically importing the SDK
|
|
18
|
+
* @throws {AIError} When the Anthropic SDK cannot be loaded
|
|
19
|
+
* @private
|
|
20
|
+
*/
|
|
21
|
+
private ensureClient;
|
|
22
|
+
/**
|
|
23
|
+
* Generate a chat completion using Claude models
|
|
24
|
+
* @param messages - Array of conversation messages
|
|
25
|
+
* @param options - Optional configuration for the chat completion
|
|
26
|
+
* @returns Promise resolving to the AI response with content and metadata
|
|
27
|
+
* @throws {AIError} When the API request fails or SDK is not available
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const response = await provider.chat([
|
|
32
|
+
* { role: 'system', content: 'You are a helpful assistant.' },
|
|
33
|
+
* { role: 'user', content: 'Explain quantum computing' }
|
|
34
|
+
* ], {
|
|
35
|
+
* model: 'claude-3-5-sonnet-20241022',
|
|
36
|
+
* maxTokens: 1000
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
chat(messages: AIMessage[], options?: ChatOptions): Promise<AIResponse>;
|
|
41
|
+
complete(prompt: string, options?: CompletionOptions): Promise<AIResponse>;
|
|
42
|
+
/**
|
|
43
|
+
* Simple message interface for single-turn interactions with optional history
|
|
44
|
+
*
|
|
45
|
+
* @param text - The message text to send
|
|
46
|
+
* @param options - Configuration options including history, model, etc.
|
|
47
|
+
* @returns Promise resolving to the response content string
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* // Simple usage
|
|
52
|
+
* const response = await provider.message('Hello!');
|
|
53
|
+
*
|
|
54
|
+
* // With history
|
|
55
|
+
* const response = await provider.message('What was my question?', {
|
|
56
|
+
* history: [
|
|
57
|
+
* { role: 'user', content: 'What is 2+2?' },
|
|
58
|
+
* { role: 'assistant', content: '4' }
|
|
59
|
+
* ]
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
message(text: string, options?: MessageOptions): Promise<string>;
|
|
64
|
+
embed(_text: string | string[], _options?: EmbeddingOptions): Promise<EmbeddingResponse>;
|
|
65
|
+
embedImage(_image: string | Buffer, _options?: ImageEmbeddingOptions): Promise<EmbeddingResponse>;
|
|
66
|
+
describeImage(_image: string | Buffer, _prompt?: string, _options?: ImageDescriptionOptions): Promise<string>;
|
|
67
|
+
generateImage(_prompt: string, _options?: ImageGenerationOptions): Promise<ImageGenerationResponse>;
|
|
68
|
+
stream(messages: AIMessage[], options?: ChatOptions): AsyncIterable<string>;
|
|
69
|
+
countTokens(text: string): Promise<number>;
|
|
70
|
+
getModels(): Promise<AIModel[]>;
|
|
71
|
+
getCapabilities(): Promise<AICapabilities>;
|
|
72
|
+
synthesizeSpeech(_text: string, _options?: TTSOptions): Promise<TTSResponse>;
|
|
73
|
+
streamSpeech(_text: string, _options?: TTSOptions): AsyncIterable<Buffer>;
|
|
74
|
+
cloneVoice(_options: VoiceCloneOptions): Promise<Voice>;
|
|
75
|
+
designVoice(_options: VoiceDesignOptions): Promise<Voice>;
|
|
76
|
+
getVoices(_options?: VoiceListOptions): Promise<Voice[]>;
|
|
77
|
+
private mapMessagesToAnthropic;
|
|
78
|
+
private mapToolChoice;
|
|
79
|
+
private mapFinishReason;
|
|
80
|
+
private mapError;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=anthropic.d.ts.map
|