@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,463 @@
|
|
|
1
|
+
import { A as AIError, c as extractTextContent, a as ContextLengthError, M as ModelNotFoundError, R as RateLimitError, e as extractRetryAfterSeconds, b as AuthenticationError } from "./index-BT4thAvS.js";
|
|
2
|
+
import { e as emitUsage } from "./usage-DMWiJ2oB.js";
|
|
3
|
+
class AnthropicProvider {
|
|
4
|
+
options;
|
|
5
|
+
client;
|
|
6
|
+
// Will be Anthropic instance from @anthropic-ai/sdk
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new Anthropic provider instance
|
|
9
|
+
* @param options - Configuration options for the Anthropic provider
|
|
10
|
+
*/
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.options = {
|
|
13
|
+
defaultModel: "claude-3-5-sonnet-20241022",
|
|
14
|
+
anthropicVersion: "2023-06-01",
|
|
15
|
+
...options
|
|
16
|
+
};
|
|
17
|
+
this.initializeClientSync();
|
|
18
|
+
}
|
|
19
|
+
initializeClientSync() {
|
|
20
|
+
try {
|
|
21
|
+
import("@anthropic-ai/sdk").then(({ Anthropic }) => {
|
|
22
|
+
this.client = new Anthropic({
|
|
23
|
+
apiKey: this.options.apiKey,
|
|
24
|
+
baseURL: this.options.baseUrl,
|
|
25
|
+
timeout: this.options.timeout,
|
|
26
|
+
maxRetries: this.options.maxRetries,
|
|
27
|
+
defaultHeaders: {
|
|
28
|
+
"anthropic-version": this.options.anthropicVersion,
|
|
29
|
+
...this.options.headers
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}).catch(() => {
|
|
33
|
+
});
|
|
34
|
+
} catch (_error) {
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Ensures the Anthropic client is initialized by dynamically importing the SDK
|
|
39
|
+
* @throws {AIError} When the Anthropic SDK cannot be loaded
|
|
40
|
+
* @private
|
|
41
|
+
*/
|
|
42
|
+
async ensureClient() {
|
|
43
|
+
if (!this.client) {
|
|
44
|
+
try {
|
|
45
|
+
const { Anthropic } = await import("@anthropic-ai/sdk");
|
|
46
|
+
this.client = new Anthropic({
|
|
47
|
+
apiKey: this.options.apiKey,
|
|
48
|
+
baseURL: this.options.baseUrl,
|
|
49
|
+
timeout: this.options.timeout,
|
|
50
|
+
maxRetries: this.options.maxRetries,
|
|
51
|
+
defaultHeaders: {
|
|
52
|
+
"anthropic-version": this.options.anthropicVersion,
|
|
53
|
+
...this.options.headers
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
} catch (_error) {
|
|
57
|
+
throw new AIError(
|
|
58
|
+
"Failed to initialize Anthropic client. Make sure @anthropic-ai/sdk is installed.",
|
|
59
|
+
"INITIALIZATION_ERROR",
|
|
60
|
+
"anthropic"
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Generate a chat completion using Claude models
|
|
67
|
+
* @param messages - Array of conversation messages
|
|
68
|
+
* @param options - Optional configuration for the chat completion
|
|
69
|
+
* @returns Promise resolving to the AI response with content and metadata
|
|
70
|
+
* @throws {AIError} When the API request fails or SDK is not available
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const response = await provider.chat([
|
|
75
|
+
* { role: 'system', content: 'You are a helpful assistant.' },
|
|
76
|
+
* { role: 'user', content: 'Explain quantum computing' }
|
|
77
|
+
* ], {
|
|
78
|
+
* model: 'claude-3-5-sonnet-20241022',
|
|
79
|
+
* maxTokens: 1000
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
async chat(messages, options = {}) {
|
|
84
|
+
const startTime = Date.now();
|
|
85
|
+
try {
|
|
86
|
+
await this.ensureClient();
|
|
87
|
+
const { system, anthropicMessages } = this.mapMessagesToAnthropic(messages);
|
|
88
|
+
const model = options.model || this.options.defaultModel;
|
|
89
|
+
const requestParams = {
|
|
90
|
+
model,
|
|
91
|
+
messages: anthropicMessages,
|
|
92
|
+
max_tokens: options.maxTokens || 4096,
|
|
93
|
+
temperature: options.temperature,
|
|
94
|
+
top_p: options.topP,
|
|
95
|
+
stop_sequences: Array.isArray(options.stop) ? options.stop : options.stop ? [options.stop] : void 0,
|
|
96
|
+
system: system || void 0,
|
|
97
|
+
tools: options.tools && options.tools.length > 0 ? options.tools.map((tool) => ({
|
|
98
|
+
name: tool.function.name,
|
|
99
|
+
description: tool.function.description || "",
|
|
100
|
+
input_schema: tool.function.parameters || { type: "object" }
|
|
101
|
+
})) : void 0,
|
|
102
|
+
tool_choice: this.mapToolChoice(options.toolChoice),
|
|
103
|
+
stream: false
|
|
104
|
+
};
|
|
105
|
+
if (options.responseFormat?.type === "json_object") {
|
|
106
|
+
const jsonInstruction = "\n\nIMPORTANT: You must respond with valid JSON only. Do not include any explanatory text outside the JSON object.";
|
|
107
|
+
requestParams.system = requestParams.system ? requestParams.system + jsonInstruction : jsonInstruction.trim();
|
|
108
|
+
}
|
|
109
|
+
const response = await this.client.messages.create(requestParams);
|
|
110
|
+
const textContent = response.content.filter((block) => block.type === "text").map((block) => block.text).join("");
|
|
111
|
+
const toolCalls = response.content.filter((block) => block.type === "tool_use").map((block) => ({
|
|
112
|
+
id: block.id,
|
|
113
|
+
type: "function",
|
|
114
|
+
function: {
|
|
115
|
+
name: block.name,
|
|
116
|
+
arguments: JSON.stringify(block.input)
|
|
117
|
+
}
|
|
118
|
+
}));
|
|
119
|
+
const usage = {
|
|
120
|
+
promptTokens: response.usage.input_tokens,
|
|
121
|
+
completionTokens: response.usage.output_tokens,
|
|
122
|
+
totalTokens: response.usage.input_tokens + response.usage.output_tokens
|
|
123
|
+
};
|
|
124
|
+
emitUsage(
|
|
125
|
+
this.options,
|
|
126
|
+
"anthropic",
|
|
127
|
+
"chat",
|
|
128
|
+
response.model || model,
|
|
129
|
+
usage,
|
|
130
|
+
startTime,
|
|
131
|
+
options.usageTags
|
|
132
|
+
);
|
|
133
|
+
return {
|
|
134
|
+
content: textContent,
|
|
135
|
+
model: response.model,
|
|
136
|
+
finishReason: this.mapFinishReason(response.stop_reason),
|
|
137
|
+
usage,
|
|
138
|
+
toolCalls: toolCalls.length > 0 ? toolCalls : void 0
|
|
139
|
+
};
|
|
140
|
+
} catch (error) {
|
|
141
|
+
throw this.mapError(error);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async complete(prompt, options = {}) {
|
|
145
|
+
return this.chat([{ role: "user", content: prompt }], {
|
|
146
|
+
model: options.model,
|
|
147
|
+
maxTokens: options.maxTokens,
|
|
148
|
+
temperature: options.temperature,
|
|
149
|
+
topP: options.topP,
|
|
150
|
+
n: options.n,
|
|
151
|
+
stop: options.stop,
|
|
152
|
+
stream: options.stream,
|
|
153
|
+
onProgress: options.onProgress,
|
|
154
|
+
usageTags: options.usageTags
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Simple message interface for single-turn interactions with optional history
|
|
159
|
+
*
|
|
160
|
+
* @param text - The message text to send
|
|
161
|
+
* @param options - Configuration options including history, model, etc.
|
|
162
|
+
* @returns Promise resolving to the response content string
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* // Simple usage
|
|
167
|
+
* const response = await provider.message('Hello!');
|
|
168
|
+
*
|
|
169
|
+
* // With history
|
|
170
|
+
* const response = await provider.message('What was my question?', {
|
|
171
|
+
* history: [
|
|
172
|
+
* { role: 'user', content: 'What is 2+2?' },
|
|
173
|
+
* { role: 'assistant', content: '4' }
|
|
174
|
+
* ]
|
|
175
|
+
* });
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
async message(text, options = {}) {
|
|
179
|
+
const messages = [
|
|
180
|
+
...options.history || [],
|
|
181
|
+
{ role: options.role || "user", content: text }
|
|
182
|
+
];
|
|
183
|
+
const response = await this.chat(messages, {
|
|
184
|
+
model: options.model,
|
|
185
|
+
maxTokens: options.maxTokens,
|
|
186
|
+
temperature: options.temperature,
|
|
187
|
+
topP: options.topP,
|
|
188
|
+
stop: options.stop,
|
|
189
|
+
stream: options.stream,
|
|
190
|
+
frequencyPenalty: options.frequencyPenalty,
|
|
191
|
+
presencePenalty: options.presencePenalty,
|
|
192
|
+
responseFormat: options.responseFormat,
|
|
193
|
+
seed: options.seed,
|
|
194
|
+
tools: options.tools,
|
|
195
|
+
toolChoice: options.toolChoice,
|
|
196
|
+
onProgress: options.onProgress,
|
|
197
|
+
usageTags: options.usageTags
|
|
198
|
+
});
|
|
199
|
+
return response.content;
|
|
200
|
+
}
|
|
201
|
+
async embed(_text, _options = {}) {
|
|
202
|
+
throw new AIError(
|
|
203
|
+
"Anthropic Claude does not support embeddings. Use OpenAI or another provider for embeddings.",
|
|
204
|
+
"NOT_SUPPORTED",
|
|
205
|
+
"anthropic"
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
async embedImage(_image, _options = {}) {
|
|
209
|
+
throw new AIError(
|
|
210
|
+
"Anthropic Claude does not support image embeddings. Use OpenAI or Gemini.",
|
|
211
|
+
"NOT_SUPPORTED",
|
|
212
|
+
"anthropic"
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
async describeImage(_image, _prompt, _options = {}) {
|
|
216
|
+
throw new AIError(
|
|
217
|
+
"Image description is not yet implemented for Anthropic. Use OpenAI or Gemini.",
|
|
218
|
+
"NOT_IMPLEMENTED",
|
|
219
|
+
"anthropic"
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
async generateImage(_prompt, _options = {}) {
|
|
223
|
+
throw new AIError(
|
|
224
|
+
"Anthropic Claude does not support image generation. Use OpenAI or Gemini.",
|
|
225
|
+
"NOT_SUPPORTED",
|
|
226
|
+
"anthropic"
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
async *stream(messages, options = {}) {
|
|
230
|
+
const startTime = Date.now();
|
|
231
|
+
try {
|
|
232
|
+
await this.ensureClient();
|
|
233
|
+
const { system, anthropicMessages } = this.mapMessagesToAnthropic(messages);
|
|
234
|
+
const model = options.model || this.options.defaultModel;
|
|
235
|
+
const stream = await this.client.messages.create({
|
|
236
|
+
model,
|
|
237
|
+
messages: anthropicMessages,
|
|
238
|
+
max_tokens: options.maxTokens || 4096,
|
|
239
|
+
temperature: options.temperature,
|
|
240
|
+
top_p: options.topP,
|
|
241
|
+
stop_sequences: Array.isArray(options.stop) ? options.stop : options.stop ? [options.stop] : void 0,
|
|
242
|
+
system: system || void 0,
|
|
243
|
+
stream: true
|
|
244
|
+
});
|
|
245
|
+
for await (const chunk of stream) {
|
|
246
|
+
if (chunk.type === "content_block_delta" && chunk.delta.type === "text_delta") {
|
|
247
|
+
if (options.onProgress) {
|
|
248
|
+
options.onProgress(chunk.delta.text);
|
|
249
|
+
}
|
|
250
|
+
yield chunk.delta.text;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
emitUsage(
|
|
254
|
+
this.options,
|
|
255
|
+
"anthropic",
|
|
256
|
+
"stream",
|
|
257
|
+
model,
|
|
258
|
+
void 0,
|
|
259
|
+
startTime,
|
|
260
|
+
options.usageTags
|
|
261
|
+
);
|
|
262
|
+
} catch (error) {
|
|
263
|
+
throw this.mapError(error);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
async countTokens(text) {
|
|
267
|
+
return Math.ceil(text.length / 3.5);
|
|
268
|
+
}
|
|
269
|
+
async getModels() {
|
|
270
|
+
return [
|
|
271
|
+
{
|
|
272
|
+
id: "claude-3-5-sonnet-20241022",
|
|
273
|
+
name: "Claude 3.5 Sonnet",
|
|
274
|
+
description: "Most intelligent Claude model with balanced performance",
|
|
275
|
+
contextLength: 2e5,
|
|
276
|
+
capabilities: ["text", "chat", "vision", "functions"],
|
|
277
|
+
supportsFunctions: true,
|
|
278
|
+
supportsVision: true
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
id: "claude-3-5-haiku-20241022",
|
|
282
|
+
name: "Claude 3.5 Haiku",
|
|
283
|
+
description: "Fastest Claude model for simple tasks",
|
|
284
|
+
contextLength: 2e5,
|
|
285
|
+
capabilities: ["text", "chat", "vision"],
|
|
286
|
+
supportsFunctions: true,
|
|
287
|
+
supportsVision: true
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
id: "claude-3-opus-20240229",
|
|
291
|
+
name: "Claude 3 Opus",
|
|
292
|
+
description: "Most powerful Claude model for complex tasks",
|
|
293
|
+
contextLength: 2e5,
|
|
294
|
+
capabilities: ["text", "chat", "vision", "functions"],
|
|
295
|
+
supportsFunctions: true,
|
|
296
|
+
supportsVision: true
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
id: "claude-3-sonnet-20240229",
|
|
300
|
+
name: "Claude 3 Sonnet",
|
|
301
|
+
description: "Balanced Claude model for most tasks",
|
|
302
|
+
contextLength: 2e5,
|
|
303
|
+
capabilities: ["text", "chat", "vision"],
|
|
304
|
+
supportsFunctions: true,
|
|
305
|
+
supportsVision: true
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
id: "claude-3-haiku-20240307",
|
|
309
|
+
name: "Claude 3 Haiku",
|
|
310
|
+
description: "Fast Claude model for simple tasks",
|
|
311
|
+
contextLength: 2e5,
|
|
312
|
+
capabilities: ["text", "chat", "vision"],
|
|
313
|
+
supportsFunctions: false,
|
|
314
|
+
supportsVision: true
|
|
315
|
+
}
|
|
316
|
+
];
|
|
317
|
+
}
|
|
318
|
+
async getCapabilities() {
|
|
319
|
+
return {
|
|
320
|
+
chat: true,
|
|
321
|
+
completion: true,
|
|
322
|
+
embeddings: false,
|
|
323
|
+
// Claude doesn't support embeddings
|
|
324
|
+
streaming: true,
|
|
325
|
+
functions: true,
|
|
326
|
+
vision: true,
|
|
327
|
+
fineTuning: false,
|
|
328
|
+
imageEmbeddings: false,
|
|
329
|
+
imageGeneration: false,
|
|
330
|
+
tts: false,
|
|
331
|
+
voiceCloning: false,
|
|
332
|
+
voiceDesign: false,
|
|
333
|
+
maxContextLength: 2e5,
|
|
334
|
+
supportedOperations: [
|
|
335
|
+
"chat",
|
|
336
|
+
"completion",
|
|
337
|
+
"streaming",
|
|
338
|
+
"functions",
|
|
339
|
+
"vision"
|
|
340
|
+
]
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
// ============================================================================
|
|
344
|
+
// TTS Methods (Not supported - use Qwen3-TTS provider)
|
|
345
|
+
// ============================================================================
|
|
346
|
+
async synthesizeSpeech(_text, _options) {
|
|
347
|
+
throw new AIError(
|
|
348
|
+
"TTS is not supported by Anthropic provider. Use Qwen3-TTS provider.",
|
|
349
|
+
"NOT_IMPLEMENTED",
|
|
350
|
+
"anthropic"
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
streamSpeech(_text, _options) {
|
|
354
|
+
const error = new AIError(
|
|
355
|
+
"TTS streaming is not supported by Anthropic provider. Use Qwen3-TTS provider.",
|
|
356
|
+
"NOT_IMPLEMENTED",
|
|
357
|
+
"anthropic"
|
|
358
|
+
);
|
|
359
|
+
return {
|
|
360
|
+
[Symbol.asyncIterator]: () => ({
|
|
361
|
+
next: () => Promise.reject(error)
|
|
362
|
+
})
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
async cloneVoice(_options) {
|
|
366
|
+
throw new AIError(
|
|
367
|
+
"Voice cloning is not supported by Anthropic provider. Use Qwen3-TTS provider.",
|
|
368
|
+
"NOT_IMPLEMENTED",
|
|
369
|
+
"anthropic"
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
async designVoice(_options) {
|
|
373
|
+
throw new AIError(
|
|
374
|
+
"Voice design is not supported by Anthropic provider. Use Qwen3-TTS provider.",
|
|
375
|
+
"NOT_IMPLEMENTED",
|
|
376
|
+
"anthropic"
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
async getVoices(_options) {
|
|
380
|
+
throw new AIError(
|
|
381
|
+
"Voice listing is not supported by Anthropic provider. Use Qwen3-TTS provider.",
|
|
382
|
+
"NOT_IMPLEMENTED",
|
|
383
|
+
"anthropic"
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
mapMessagesToAnthropic(messages) {
|
|
387
|
+
let system;
|
|
388
|
+
const anthropicMessages = [];
|
|
389
|
+
for (const message of messages) {
|
|
390
|
+
const textContent = extractTextContent(message.content);
|
|
391
|
+
if (message.role === "system") {
|
|
392
|
+
system = system ? `${system}
|
|
393
|
+
|
|
394
|
+
${textContent}` : textContent;
|
|
395
|
+
} else {
|
|
396
|
+
anthropicMessages.push({
|
|
397
|
+
role: message.role === "assistant" ? "assistant" : "user",
|
|
398
|
+
content: textContent
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return { system, anthropicMessages };
|
|
403
|
+
}
|
|
404
|
+
mapToolChoice(toolChoice) {
|
|
405
|
+
if (!toolChoice || toolChoice === "auto") {
|
|
406
|
+
return { type: "auto" };
|
|
407
|
+
}
|
|
408
|
+
if (toolChoice === "none") {
|
|
409
|
+
return void 0;
|
|
410
|
+
}
|
|
411
|
+
if (typeof toolChoice === "object" && toolChoice.type === "function") {
|
|
412
|
+
return {
|
|
413
|
+
type: "tool",
|
|
414
|
+
name: toolChoice.function.name
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
return { type: "auto" };
|
|
418
|
+
}
|
|
419
|
+
mapFinishReason(reason) {
|
|
420
|
+
switch (reason) {
|
|
421
|
+
case "end_turn":
|
|
422
|
+
return "stop";
|
|
423
|
+
case "max_tokens":
|
|
424
|
+
return "length";
|
|
425
|
+
case "stop_sequence":
|
|
426
|
+
return "stop";
|
|
427
|
+
case "tool_use":
|
|
428
|
+
return "tool_calls";
|
|
429
|
+
default:
|
|
430
|
+
return "stop";
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
mapError(error) {
|
|
434
|
+
if (error instanceof AIError) {
|
|
435
|
+
return error;
|
|
436
|
+
}
|
|
437
|
+
if (typeof error === "object" && error !== null && "status" in error) {
|
|
438
|
+
const apiError = error;
|
|
439
|
+
switch (apiError.status) {
|
|
440
|
+
case 401:
|
|
441
|
+
return new AuthenticationError("anthropic");
|
|
442
|
+
case 429:
|
|
443
|
+
return new RateLimitError(
|
|
444
|
+
"anthropic",
|
|
445
|
+
extractRetryAfterSeconds(error)
|
|
446
|
+
);
|
|
447
|
+
case 404:
|
|
448
|
+
return new ModelNotFoundError(
|
|
449
|
+
apiError.message || "Model not found",
|
|
450
|
+
"anthropic"
|
|
451
|
+
);
|
|
452
|
+
case 413:
|
|
453
|
+
return new ContextLengthError("anthropic");
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown Anthropic error occurred";
|
|
457
|
+
return new AIError(errorMessage, "UNKNOWN_ERROR", "anthropic");
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
export {
|
|
461
|
+
AnthropicProvider
|
|
462
|
+
};
|
|
463
|
+
//# sourceMappingURL=anthropic-BRwbhwIl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic-BRwbhwIl.js","sources":["../../src/shared/providers/anthropic.ts"],"sourcesContent":["/**\n * Anthropic Claude provider implementation\n *\n * Provides a standardized interface for interacting with Anthropic's Claude models,\n * including chat completions, streaming responses, and vision capabilities.\n * Note: Claude models do not support embeddings - use OpenAI or another provider for that.\n */\n\nimport { extractRetryAfterSeconds } from '../rate-limit';\nimport type {\n AICapabilities,\n AIInterface,\n AIMessage,\n AIModel,\n AIResponse,\n AnthropicOptions,\n ChatOptions,\n CompletionOptions,\n EmbeddingOptions,\n EmbeddingResponse,\n ImageDescriptionOptions,\n ImageEmbeddingOptions,\n ImageGenerationOptions,\n ImageGenerationResponse,\n MessageOptions,\n TokenUsage,\n TTSOptions,\n TTSResponse,\n Voice,\n VoiceCloneOptions,\n VoiceDesignOptions,\n VoiceListOptions,\n} from '../types';\nimport {\n AIError,\n AuthenticationError,\n ContextLengthError,\n extractTextContent,\n ModelNotFoundError,\n RateLimitError,\n} from '../types';\nimport { emitUsage } from './usage';\n\n// Note: This implementation will require @anthropic-ai/sdk package\n// For now, this is a placeholder that defines the interface\n\n/**\n * Anthropic Claude provider implementation that handles all interactions with Anthropic's API.\n * Supports Claude models, streaming, vision capabilities, and function calling.\n * Does not support embeddings (use OpenAI or another provider for embeddings).\n */\nexport class AnthropicProvider implements AIInterface {\n private options: AnthropicOptions;\n private client: any; // Will be Anthropic instance from @anthropic-ai/sdk\n\n /**\n * Creates a new Anthropic provider instance\n * @param options - Configuration options for the Anthropic provider\n */\n constructor(options: AnthropicOptions) {\n this.options = {\n defaultModel: 'claude-3-5-sonnet-20241022',\n anthropicVersion: '2023-06-01',\n ...options,\n };\n\n // Initialize Anthropic client\n this.initializeClientSync();\n }\n\n private initializeClientSync() {\n try {\n // Dynamic import in constructor - this will work if the package is installed\n import('@anthropic-ai/sdk')\n .then(({ Anthropic }) => {\n this.client = new Anthropic({\n apiKey: this.options.apiKey,\n baseURL: this.options.baseUrl,\n timeout: this.options.timeout,\n maxRetries: this.options.maxRetries,\n defaultHeaders: {\n 'anthropic-version': this.options.anthropicVersion,\n ...this.options.headers,\n },\n });\n })\n .catch(() => {\n // Client will be null and we'll handle it in methods\n });\n } catch (_error) {\n // Client will be null and we'll handle it in methods\n }\n }\n\n /**\n * Ensures the Anthropic client is initialized by dynamically importing the SDK\n * @throws {AIError} When the Anthropic SDK cannot be loaded\n * @private\n */\n private async ensureClient() {\n if (!this.client) {\n try {\n const { Anthropic } = await import('@anthropic-ai/sdk');\n this.client = new Anthropic({\n apiKey: this.options.apiKey,\n baseURL: this.options.baseUrl,\n timeout: this.options.timeout,\n maxRetries: this.options.maxRetries,\n defaultHeaders: {\n 'anthropic-version': this.options.anthropicVersion,\n ...this.options.headers,\n },\n });\n } catch (_error) {\n throw new AIError(\n 'Failed to initialize Anthropic client. Make sure @anthropic-ai/sdk is installed.',\n 'INITIALIZATION_ERROR',\n 'anthropic',\n );\n }\n }\n }\n\n /**\n * Generate a chat completion using Claude models\n * @param messages - Array of conversation messages\n * @param options - Optional configuration for the chat completion\n * @returns Promise resolving to the AI response with content and metadata\n * @throws {AIError} When the API request fails or SDK is not available\n *\n * @example\n * ```typescript\n * const response = await provider.chat([\n * { role: 'system', content: 'You are a helpful assistant.' },\n * { role: 'user', content: 'Explain quantum computing' }\n * ], {\n * model: 'claude-3-5-sonnet-20241022',\n * maxTokens: 1000\n * });\n * ```\n */\n async chat(\n messages: AIMessage[],\n options: ChatOptions = {},\n ): Promise<AIResponse> {\n const startTime = Date.now();\n try {\n await this.ensureClient();\n\n const { system, anthropicMessages } =\n this.mapMessagesToAnthropic(messages);\n\n const model = options.model || this.options.defaultModel;\n\n // Build request parameters\n const requestParams: Record<string, any> = {\n model,\n messages: anthropicMessages,\n max_tokens: options.maxTokens || 4096,\n temperature: options.temperature,\n top_p: options.topP,\n stop_sequences: Array.isArray(options.stop)\n ? options.stop\n : options.stop\n ? [options.stop]\n : undefined,\n system: system || undefined,\n tools:\n options.tools && options.tools.length > 0\n ? options.tools.map((tool) => ({\n name: tool.function.name,\n description: tool.function.description || '',\n input_schema: tool.function.parameters || { type: 'object' },\n }))\n : undefined,\n tool_choice: this.mapToolChoice(options.toolChoice),\n stream: false,\n };\n\n // Add response format if specified\n if (options.responseFormat?.type === 'json_object') {\n const jsonInstruction =\n '\\n\\nIMPORTANT: You must respond with valid JSON only. Do not include any explanatory text outside the JSON object.';\n requestParams.system = requestParams.system\n ? requestParams.system + jsonInstruction\n : jsonInstruction.trim();\n }\n\n const response = await this.client.messages.create(requestParams);\n\n // Extract text content and tool calls from response\n const textContent = response.content\n .filter((block: any) => block.type === 'text')\n .map((block: any) => block.text)\n .join('');\n\n const toolCalls = response.content\n .filter((block: any) => block.type === 'tool_use')\n .map((block: any) => ({\n id: block.id,\n type: 'function' as const,\n function: {\n name: block.name,\n arguments: JSON.stringify(block.input),\n },\n }));\n\n const usage: TokenUsage = {\n promptTokens: response.usage.input_tokens,\n completionTokens: response.usage.output_tokens,\n totalTokens: response.usage.input_tokens + response.usage.output_tokens,\n };\n emitUsage(\n this.options,\n 'anthropic',\n 'chat',\n response.model || model,\n usage,\n startTime,\n options.usageTags,\n );\n\n return {\n content: textContent,\n model: response.model,\n finishReason: this.mapFinishReason(response.stop_reason),\n usage,\n toolCalls: toolCalls.length > 0 ? toolCalls : undefined,\n };\n } catch (error) {\n throw this.mapError(error);\n }\n }\n\n async complete(\n prompt: string,\n options: CompletionOptions = {},\n ): Promise<AIResponse> {\n return this.chat([{ role: 'user', content: prompt }], {\n model: options.model,\n maxTokens: options.maxTokens,\n temperature: options.temperature,\n topP: options.topP,\n n: options.n,\n stop: options.stop,\n stream: options.stream,\n onProgress: options.onProgress,\n usageTags: options.usageTags,\n });\n }\n\n /**\n * Simple message interface for single-turn interactions with optional history\n *\n * @param text - The message text to send\n * @param options - Configuration options including history, model, etc.\n * @returns Promise resolving to the response content string\n *\n * @example\n * ```typescript\n * // Simple usage\n * const response = await provider.message('Hello!');\n *\n * // With history\n * const response = await provider.message('What was my question?', {\n * history: [\n * { role: 'user', content: 'What is 2+2?' },\n * { role: 'assistant', content: '4' }\n * ]\n * });\n * ```\n */\n async message(text: string, options: MessageOptions = {}): Promise<string> {\n // Build messages array from history + current message\n const messages: AIMessage[] = [\n ...(options.history || []),\n { role: options.role || 'user', content: text },\n ];\n\n const response = await this.chat(messages, {\n model: options.model,\n maxTokens: options.maxTokens,\n temperature: options.temperature,\n topP: options.topP,\n stop: options.stop,\n stream: options.stream,\n frequencyPenalty: options.frequencyPenalty,\n presencePenalty: options.presencePenalty,\n responseFormat: options.responseFormat,\n seed: options.seed,\n tools: options.tools,\n toolChoice: options.toolChoice,\n onProgress: options.onProgress,\n usageTags: options.usageTags,\n });\n\n return response.content;\n }\n\n async embed(\n _text: string | string[],\n _options: EmbeddingOptions = {},\n ): Promise<EmbeddingResponse> {\n // Anthropic Claude doesn't provide embeddings API\n throw new AIError(\n 'Anthropic Claude does not support embeddings. Use OpenAI or another provider for embeddings.',\n 'NOT_SUPPORTED',\n 'anthropic',\n );\n }\n\n async embedImage(\n _image: string | Buffer,\n _options: ImageEmbeddingOptions = {},\n ): Promise<EmbeddingResponse> {\n throw new AIError(\n 'Anthropic Claude does not support image embeddings. Use OpenAI or Gemini.',\n 'NOT_SUPPORTED',\n 'anthropic',\n );\n }\n\n async describeImage(\n _image: string | Buffer,\n _prompt?: string,\n _options: ImageDescriptionOptions = {},\n ): Promise<string> {\n // Note: Claude does support vision, but we're keeping this as a stub for now\n // A full implementation could use the chat API with image content\n throw new AIError(\n 'Image description is not yet implemented for Anthropic. Use OpenAI or Gemini.',\n 'NOT_IMPLEMENTED',\n 'anthropic',\n );\n }\n\n async generateImage(\n _prompt: string,\n _options: ImageGenerationOptions = {},\n ): Promise<ImageGenerationResponse> {\n throw new AIError(\n 'Anthropic Claude does not support image generation. Use OpenAI or Gemini.',\n 'NOT_SUPPORTED',\n 'anthropic',\n );\n }\n\n async *stream(\n messages: AIMessage[],\n options: ChatOptions = {},\n ): AsyncIterable<string> {\n const startTime = Date.now();\n try {\n await this.ensureClient();\n\n const { system, anthropicMessages } =\n this.mapMessagesToAnthropic(messages);\n\n const model = options.model || this.options.defaultModel;\n\n const stream = await this.client.messages.create({\n model,\n messages: anthropicMessages,\n max_tokens: options.maxTokens || 4096,\n temperature: options.temperature,\n top_p: options.topP,\n stop_sequences: Array.isArray(options.stop)\n ? options.stop\n : options.stop\n ? [options.stop]\n : undefined,\n system: system || undefined,\n stream: true,\n });\n\n for await (const chunk of stream) {\n if (\n chunk.type === 'content_block_delta' &&\n chunk.delta.type === 'text_delta'\n ) {\n if (options.onProgress) {\n options.onProgress(chunk.delta.text);\n }\n yield chunk.delta.text;\n }\n }\n\n emitUsage(\n this.options,\n 'anthropic',\n 'stream',\n model!,\n undefined,\n startTime,\n options.usageTags,\n );\n } catch (error) {\n throw this.mapError(error);\n }\n }\n\n async countTokens(text: string): Promise<number> {\n // Anthropic doesn't provide a direct token counting API\n // This is an approximation - Claude uses a different tokenizer than OpenAI\n return Math.ceil(text.length / 3.5); // Slightly different ratio for Claude\n }\n\n async getModels(): Promise<AIModel[]> {\n // Return static list of known Claude models\n return [\n {\n id: 'claude-3-5-sonnet-20241022',\n name: 'Claude 3.5 Sonnet',\n description: 'Most intelligent Claude model with balanced performance',\n contextLength: 200000,\n capabilities: ['text', 'chat', 'vision', 'functions'],\n supportsFunctions: true,\n supportsVision: true,\n },\n {\n id: 'claude-3-5-haiku-20241022',\n name: 'Claude 3.5 Haiku',\n description: 'Fastest Claude model for simple tasks',\n contextLength: 200000,\n capabilities: ['text', 'chat', 'vision'],\n supportsFunctions: true,\n supportsVision: true,\n },\n {\n id: 'claude-3-opus-20240229',\n name: 'Claude 3 Opus',\n description: 'Most powerful Claude model for complex tasks',\n contextLength: 200000,\n capabilities: ['text', 'chat', 'vision', 'functions'],\n supportsFunctions: true,\n supportsVision: true,\n },\n {\n id: 'claude-3-sonnet-20240229',\n name: 'Claude 3 Sonnet',\n description: 'Balanced Claude model for most tasks',\n contextLength: 200000,\n capabilities: ['text', 'chat', 'vision'],\n supportsFunctions: true,\n supportsVision: true,\n },\n {\n id: 'claude-3-haiku-20240307',\n name: 'Claude 3 Haiku',\n description: 'Fast Claude model for simple tasks',\n contextLength: 200000,\n capabilities: ['text', 'chat', 'vision'],\n supportsFunctions: false,\n supportsVision: true,\n },\n ];\n }\n\n async getCapabilities(): Promise<AICapabilities> {\n return {\n chat: true,\n completion: true,\n embeddings: false, // Claude doesn't support embeddings\n streaming: true,\n functions: true,\n vision: true,\n fineTuning: false,\n imageEmbeddings: false,\n imageGeneration: false,\n tts: false,\n voiceCloning: false,\n voiceDesign: false,\n maxContextLength: 200000,\n supportedOperations: [\n 'chat',\n 'completion',\n 'streaming',\n 'functions',\n 'vision',\n ],\n };\n }\n\n // ============================================================================\n // TTS Methods (Not supported - use Qwen3-TTS provider)\n // ============================================================================\n\n async synthesizeSpeech(\n _text: string,\n _options?: TTSOptions,\n ): Promise<TTSResponse> {\n throw new AIError(\n 'TTS is not supported by Anthropic provider. Use Qwen3-TTS provider.',\n 'NOT_IMPLEMENTED',\n 'anthropic',\n );\n }\n\n streamSpeech(_text: string, _options?: TTSOptions): AsyncIterable<Buffer> {\n const error = new AIError(\n 'TTS streaming is not supported by Anthropic provider. Use Qwen3-TTS provider.',\n 'NOT_IMPLEMENTED',\n 'anthropic',\n );\n return {\n [Symbol.asyncIterator]: () => ({\n next: () => Promise.reject(error),\n }),\n };\n }\n\n async cloneVoice(_options: VoiceCloneOptions): Promise<Voice> {\n throw new AIError(\n 'Voice cloning is not supported by Anthropic provider. Use Qwen3-TTS provider.',\n 'NOT_IMPLEMENTED',\n 'anthropic',\n );\n }\n\n async designVoice(_options: VoiceDesignOptions): Promise<Voice> {\n throw new AIError(\n 'Voice design is not supported by Anthropic provider. Use Qwen3-TTS provider.',\n 'NOT_IMPLEMENTED',\n 'anthropic',\n );\n }\n\n async getVoices(_options?: VoiceListOptions): Promise<Voice[]> {\n throw new AIError(\n 'Voice listing is not supported by Anthropic provider. Use Qwen3-TTS provider.',\n 'NOT_IMPLEMENTED',\n 'anthropic',\n );\n }\n\n private mapMessagesToAnthropic(messages: AIMessage[]): {\n system?: string;\n anthropicMessages: Array<{ role: 'user' | 'assistant'; content: string }>;\n } {\n // Anthropic handles system messages separately\n let system: string | undefined;\n const anthropicMessages: Array<{\n role: 'user' | 'assistant';\n content: string;\n }> = [];\n\n for (const message of messages) {\n const textContent = extractTextContent(message.content);\n if (message.role === 'system') {\n // Combine multiple system messages\n system = system ? `${system}\\n\\n${textContent}` : textContent;\n } else {\n anthropicMessages.push({\n role: message.role === 'assistant' ? 'assistant' : 'user',\n content: textContent,\n });\n }\n }\n\n return { system, anthropicMessages };\n }\n\n private mapToolChoice(\n toolChoice?:\n | 'auto'\n | 'none'\n | { type: 'function'; function: { name: string } },\n ): any {\n if (!toolChoice || toolChoice === 'auto') {\n return { type: 'auto' };\n }\n\n if (toolChoice === 'none') {\n return undefined; // Anthropic doesn't have explicit 'none', just omit tools\n }\n\n if (typeof toolChoice === 'object' && toolChoice.type === 'function') {\n return {\n type: 'tool',\n name: toolChoice.function.name,\n };\n }\n\n return { type: 'auto' };\n }\n\n private mapFinishReason(reason: string | null): AIResponse['finishReason'] {\n switch (reason) {\n case 'end_turn':\n return 'stop';\n case 'max_tokens':\n return 'length';\n case 'stop_sequence':\n return 'stop';\n case 'tool_use':\n return 'tool_calls';\n default:\n return 'stop';\n }\n }\n\n private mapError(error: unknown): AIError {\n if (error instanceof AIError) {\n return error;\n }\n\n // Map common HTTP status codes from Anthropic API\n if (typeof error === 'object' && error !== null && 'status' in error) {\n const apiError = error as { status: number; message?: string };\n switch (apiError.status) {\n case 401:\n return new AuthenticationError('anthropic');\n case 429:\n return new RateLimitError(\n 'anthropic',\n extractRetryAfterSeconds(error),\n );\n case 404:\n return new ModelNotFoundError(\n apiError.message || 'Model not found',\n 'anthropic',\n );\n case 413:\n return new ContextLengthError('anthropic');\n }\n }\n\n const errorMessage =\n error instanceof Error\n ? error.message\n : 'Unknown Anthropic error occurred';\n return new AIError(errorMessage, 'UNKNOWN_ERROR', 'anthropic');\n }\n}\n"],"names":[],"mappings":";;AAmDO,MAAM,kBAAyC;AAAA,EAC5C;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMR,YAAY,SAA2B;AACrC,SAAK,UAAU;AAAA,MACb,cAAc;AAAA,MACd,kBAAkB;AAAA,MAClB,GAAG;AAAA,IAAA;AAIL,SAAK,qBAAA;AAAA,EACP;AAAA,EAEQ,uBAAuB;AAC7B,QAAI;AAEF,aAAO,mBAAmB,EACvB,KAAK,CAAC,EAAE,gBAAgB;AACvB,aAAK,SAAS,IAAI,UAAU;AAAA,UAC1B,QAAQ,KAAK,QAAQ;AAAA,UACrB,SAAS,KAAK,QAAQ;AAAA,UACtB,SAAS,KAAK,QAAQ;AAAA,UACtB,YAAY,KAAK,Q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