@aituber-onair/chat 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +318 -0
- package/README.md +318 -0
- package/dist/cjs/constants/chat.d.ts +26 -0
- package/dist/cjs/constants/chat.d.ts.map +1 -0
- package/dist/cjs/constants/chat.js +34 -0
- package/dist/cjs/constants/chat.js.map +1 -0
- package/dist/cjs/constants/claude.d.ts +9 -0
- package/dist/cjs/constants/claude.d.ts.map +1 -0
- package/dist/cjs/constants/claude.js +20 -0
- package/dist/cjs/constants/claude.js.map +1 -0
- package/dist/cjs/constants/gemini.d.ts +11 -0
- package/dist/cjs/constants/gemini.d.ts.map +1 -0
- package/dist/cjs/constants/gemini.js +26 -0
- package/dist/cjs/constants/gemini.js.map +1 -0
- package/dist/cjs/constants/index.d.ts +9 -0
- package/dist/cjs/constants/index.d.ts.map +1 -0
- package/dist/cjs/constants/index.js +25 -0
- package/dist/cjs/constants/index.js.map +1 -0
- package/dist/cjs/constants/openai.d.ts +13 -0
- package/dist/cjs/constants/openai.d.ts.map +1 -0
- package/dist/cjs/constants/openai.js +28 -0
- package/dist/cjs/constants/openai.js.map +1 -0
- package/dist/cjs/constants/prompts.d.ts +3 -0
- package/dist/cjs/constants/prompts.d.ts.map +1 -0
- package/dist/cjs/constants/prompts.js +16 -0
- package/dist/cjs/constants/prompts.js.map +1 -0
- package/dist/cjs/index.d.ts +17 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +45 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/services/ChatService.d.ts +51 -0
- package/dist/cjs/services/ChatService.d.ts.map +1 -0
- package/dist/cjs/services/ChatService.js +3 -0
- package/dist/cjs/services/ChatService.js.map +1 -0
- package/dist/cjs/services/ChatServiceFactory.d.ts +39 -0
- package/dist/cjs/services/ChatServiceFactory.d.ts.map +1 -0
- package/dist/cjs/services/ChatServiceFactory.js +65 -0
- package/dist/cjs/services/ChatServiceFactory.js.map +1 -0
- package/dist/cjs/services/providers/ChatServiceProvider.d.ts +52 -0
- package/dist/cjs/services/providers/ChatServiceProvider.d.ts.map +1 -0
- package/dist/cjs/services/providers/ChatServiceProvider.js +3 -0
- package/dist/cjs/services/providers/ChatServiceProvider.js.map +1 -0
- package/dist/cjs/services/providers/claude/ClaudeChatService.d.ts +142 -0
- package/dist/cjs/services/providers/claude/ClaudeChatService.d.ts.map +1 -0
- package/dist/cjs/services/providers/claude/ClaudeChatService.js +501 -0
- package/dist/cjs/services/providers/claude/ClaudeChatService.js.map +1 -0
- package/dist/cjs/services/providers/claude/ClaudeChatServiceProvider.d.ts +40 -0
- package/dist/cjs/services/providers/claude/ClaudeChatServiceProvider.d.ts.map +1 -0
- package/dist/cjs/services/providers/claude/ClaudeChatServiceProvider.js +68 -0
- package/dist/cjs/services/providers/claude/ClaudeChatServiceProvider.js.map +1 -0
- package/dist/cjs/services/providers/gemini/GeminiChatService.d.ts +104 -0
- package/dist/cjs/services/providers/gemini/GeminiChatService.d.ts.map +1 -0
- package/dist/cjs/services/providers/gemini/GeminiChatService.js +653 -0
- package/dist/cjs/services/providers/gemini/GeminiChatService.js.map +1 -0
- package/dist/cjs/services/providers/gemini/GeminiChatServiceProvider.d.ts +40 -0
- package/dist/cjs/services/providers/gemini/GeminiChatServiceProvider.d.ts.map +1 -0
- package/dist/cjs/services/providers/gemini/GeminiChatServiceProvider.js +70 -0
- package/dist/cjs/services/providers/gemini/GeminiChatServiceProvider.js.map +1 -0
- package/dist/cjs/services/providers/openai/OpenAIChatService.d.ts +110 -0
- package/dist/cjs/services/providers/openai/OpenAIChatService.d.ts.map +1 -0
- package/dist/cjs/services/providers/openai/OpenAIChatService.js +544 -0
- package/dist/cjs/services/providers/openai/OpenAIChatService.js.map +1 -0
- package/dist/cjs/services/providers/openai/OpenAIChatServiceProvider.d.ts +40 -0
- package/dist/cjs/services/providers/openai/OpenAIChatServiceProvider.d.ts.map +1 -0
- package/dist/cjs/services/providers/openai/OpenAIChatServiceProvider.js +80 -0
- package/dist/cjs/services/providers/openai/OpenAIChatServiceProvider.js.map +1 -0
- package/dist/cjs/types/chat.d.ts +46 -0
- package/dist/cjs/types/chat.d.ts.map +1 -0
- package/dist/cjs/types/chat.js +6 -0
- package/dist/cjs/types/chat.js.map +1 -0
- package/dist/cjs/types/index.d.ts +8 -0
- package/dist/cjs/types/index.d.ts.map +1 -0
- package/dist/cjs/types/index.js +25 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/cjs/types/mcp.d.ts +37 -0
- package/dist/cjs/types/mcp.d.ts.map +1 -0
- package/dist/cjs/types/mcp.js +6 -0
- package/dist/cjs/types/mcp.js.map +1 -0
- package/dist/cjs/types/toolChat.d.ts +42 -0
- package/dist/cjs/types/toolChat.d.ts.map +1 -0
- package/dist/cjs/types/toolChat.js +3 -0
- package/dist/cjs/types/toolChat.js.map +1 -0
- package/dist/cjs/utils/chatServiceHttpClient.d.ts +47 -0
- package/dist/cjs/utils/chatServiceHttpClient.d.ts.map +1 -0
- package/dist/cjs/utils/chatServiceHttpClient.js +131 -0
- package/dist/cjs/utils/chatServiceHttpClient.js.map +1 -0
- package/dist/cjs/utils/emotionParser.d.ts +46 -0
- package/dist/cjs/utils/emotionParser.d.ts.map +1 -0
- package/dist/cjs/utils/emotionParser.js +59 -0
- package/dist/cjs/utils/emotionParser.js.map +1 -0
- package/dist/cjs/utils/index.d.ts +8 -0
- package/dist/cjs/utils/index.d.ts.map +1 -0
- package/dist/cjs/utils/index.js +24 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/mcpSchemaFetcher.d.ts +19 -0
- package/dist/cjs/utils/mcpSchemaFetcher.d.ts.map +1 -0
- package/dist/cjs/utils/mcpSchemaFetcher.js +98 -0
- package/dist/cjs/utils/mcpSchemaFetcher.js.map +1 -0
- package/dist/cjs/utils/screenplay.d.ts +20 -0
- package/dist/cjs/utils/screenplay.d.ts.map +1 -0
- package/dist/cjs/utils/screenplay.js +41 -0
- package/dist/cjs/utils/screenplay.js.map +1 -0
- package/dist/cjs/utils/streamTextAccumulator.d.ts +25 -0
- package/dist/cjs/utils/streamTextAccumulator.d.ts.map +1 -0
- package/dist/cjs/utils/streamTextAccumulator.js +47 -0
- package/dist/cjs/utils/streamTextAccumulator.js.map +1 -0
- package/dist/esm/constants/chat.d.ts +26 -0
- package/dist/esm/constants/chat.d.ts.map +1 -0
- package/dist/esm/constants/chat.js +30 -0
- package/dist/esm/constants/chat.js.map +1 -0
- package/dist/esm/constants/claude.d.ts +9 -0
- package/dist/esm/constants/claude.d.ts.map +1 -0
- package/dist/esm/constants/claude.js +17 -0
- package/dist/esm/constants/claude.js.map +1 -0
- package/dist/esm/constants/gemini.d.ts +11 -0
- package/dist/esm/constants/gemini.d.ts.map +1 -0
- package/dist/esm/constants/gemini.js +23 -0
- package/dist/esm/constants/gemini.js.map +1 -0
- package/dist/esm/constants/index.d.ts +9 -0
- package/dist/esm/constants/index.d.ts.map +1 -0
- package/dist/esm/constants/index.js +9 -0
- package/dist/esm/constants/index.js.map +1 -0
- package/dist/esm/constants/openai.d.ts +13 -0
- package/dist/esm/constants/openai.d.ts.map +1 -0
- package/dist/esm/constants/openai.js +25 -0
- package/dist/esm/constants/openai.js.map +1 -0
- package/dist/esm/constants/prompts.d.ts +3 -0
- package/dist/esm/constants/prompts.d.ts.map +1 -0
- package/dist/esm/constants/prompts.js +13 -0
- package/dist/esm/constants/prompts.js.map +1 -0
- package/dist/esm/index.d.ts +17 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +21 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/services/ChatService.d.ts +51 -0
- package/dist/esm/services/ChatService.d.ts.map +1 -0
- package/dist/esm/services/ChatService.js +2 -0
- package/dist/esm/services/ChatService.js.map +1 -0
- package/dist/esm/services/ChatServiceFactory.d.ts +39 -0
- package/dist/esm/services/ChatServiceFactory.d.ts.map +1 -0
- package/dist/esm/services/ChatServiceFactory.js +61 -0
- package/dist/esm/services/ChatServiceFactory.js.map +1 -0
- package/dist/esm/services/providers/ChatServiceProvider.d.ts +52 -0
- package/dist/esm/services/providers/ChatServiceProvider.d.ts.map +1 -0
- package/dist/esm/services/providers/ChatServiceProvider.js +2 -0
- package/dist/esm/services/providers/ChatServiceProvider.js.map +1 -0
- package/dist/esm/services/providers/claude/ClaudeChatService.d.ts +142 -0
- package/dist/esm/services/providers/claude/ClaudeChatService.d.ts.map +1 -0
- package/dist/esm/services/providers/claude/ClaudeChatService.js +497 -0
- package/dist/esm/services/providers/claude/ClaudeChatService.js.map +1 -0
- package/dist/esm/services/providers/claude/ClaudeChatServiceProvider.d.ts +40 -0
- package/dist/esm/services/providers/claude/ClaudeChatServiceProvider.d.ts.map +1 -0
- package/dist/esm/services/providers/claude/ClaudeChatServiceProvider.js +64 -0
- package/dist/esm/services/providers/claude/ClaudeChatServiceProvider.js.map +1 -0
- package/dist/esm/services/providers/gemini/GeminiChatService.d.ts +104 -0
- package/dist/esm/services/providers/gemini/GeminiChatService.d.ts.map +1 -0
- package/dist/esm/services/providers/gemini/GeminiChatService.js +649 -0
- package/dist/esm/services/providers/gemini/GeminiChatService.js.map +1 -0
- package/dist/esm/services/providers/gemini/GeminiChatServiceProvider.d.ts +40 -0
- package/dist/esm/services/providers/gemini/GeminiChatServiceProvider.d.ts.map +1 -0
- package/dist/esm/services/providers/gemini/GeminiChatServiceProvider.js +66 -0
- package/dist/esm/services/providers/gemini/GeminiChatServiceProvider.js.map +1 -0
- package/dist/esm/services/providers/openai/OpenAIChatService.d.ts +110 -0
- package/dist/esm/services/providers/openai/OpenAIChatService.d.ts.map +1 -0
- package/dist/esm/services/providers/openai/OpenAIChatService.js +540 -0
- package/dist/esm/services/providers/openai/OpenAIChatService.js.map +1 -0
- package/dist/esm/services/providers/openai/OpenAIChatServiceProvider.d.ts +40 -0
- package/dist/esm/services/providers/openai/OpenAIChatServiceProvider.d.ts.map +1 -0
- package/dist/esm/services/providers/openai/OpenAIChatServiceProvider.js +76 -0
- package/dist/esm/services/providers/openai/OpenAIChatServiceProvider.js.map +1 -0
- package/dist/esm/types/chat.d.ts +46 -0
- package/dist/esm/types/chat.d.ts.map +1 -0
- package/dist/esm/types/chat.js +5 -0
- package/dist/esm/types/chat.js.map +1 -0
- package/dist/esm/types/index.d.ts +8 -0
- package/dist/esm/types/index.d.ts.map +1 -0
- package/dist/esm/types/index.js +9 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/types/mcp.d.ts +37 -0
- package/dist/esm/types/mcp.d.ts.map +1 -0
- package/dist/esm/types/mcp.js +5 -0
- package/dist/esm/types/mcp.js.map +1 -0
- package/dist/esm/types/toolChat.d.ts +42 -0
- package/dist/esm/types/toolChat.d.ts.map +1 -0
- package/dist/esm/types/toolChat.js +2 -0
- package/dist/esm/types/toolChat.js.map +1 -0
- package/dist/esm/utils/chatServiceHttpClient.d.ts +47 -0
- package/dist/esm/utils/chatServiceHttpClient.d.ts.map +1 -0
- package/dist/esm/utils/chatServiceHttpClient.js +126 -0
- package/dist/esm/utils/chatServiceHttpClient.js.map +1 -0
- package/dist/esm/utils/emotionParser.d.ts +46 -0
- package/dist/esm/utils/emotionParser.d.ts.map +1 -0
- package/dist/esm/utils/emotionParser.js +55 -0
- package/dist/esm/utils/emotionParser.js.map +1 -0
- package/dist/esm/utils/index.d.ts +8 -0
- package/dist/esm/utils/index.d.ts.map +1 -0
- package/dist/esm/utils/index.js +8 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/mcpSchemaFetcher.d.ts +19 -0
- package/dist/esm/utils/mcpSchemaFetcher.d.ts.map +1 -0
- package/dist/esm/utils/mcpSchemaFetcher.js +94 -0
- package/dist/esm/utils/mcpSchemaFetcher.js.map +1 -0
- package/dist/esm/utils/screenplay.d.ts +20 -0
- package/dist/esm/utils/screenplay.d.ts.map +1 -0
- package/dist/esm/utils/screenplay.js +36 -0
- package/dist/esm/utils/screenplay.js.map +1 -0
- package/dist/esm/utils/streamTextAccumulator.d.ts +25 -0
- package/dist/esm/utils/streamTextAccumulator.d.ts.map +1 -0
- package/dist/esm/utils/streamTextAccumulator.js +43 -0
- package/dist/esm/utils/streamTextAccumulator.js.map +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
import { ENDPOINT_CLAUDE_API, MODEL_CLAUDE_3_HAIKU, CLAUDE_VISION_SUPPORTED_MODELS, } from '../../../constants';
|
|
2
|
+
import { getMaxTokensForResponseLength, } from '../../../constants/chat';
|
|
3
|
+
import { ChatServiceHttpClient } from '../../../utils/chatServiceHttpClient';
|
|
4
|
+
/**
|
|
5
|
+
* Claude implementation of ChatService
|
|
6
|
+
*/
|
|
7
|
+
export class ClaudeChatService {
|
|
8
|
+
/**
|
|
9
|
+
* Constructor
|
|
10
|
+
* @param apiKey Anthropic API key
|
|
11
|
+
* @param model Name of the model to use
|
|
12
|
+
* @param visionModel Name of the vision model
|
|
13
|
+
* @param tools Array of tool definitions
|
|
14
|
+
* @param mcpServers Array of MCP server configurations (optional)
|
|
15
|
+
* @throws Error if the vision model doesn't support vision capabilities
|
|
16
|
+
*/
|
|
17
|
+
constructor(apiKey, model = MODEL_CLAUDE_3_HAIKU, visionModel = MODEL_CLAUDE_3_HAIKU, tools = [], mcpServers = [], responseLength) {
|
|
18
|
+
/** Provider name */
|
|
19
|
+
this.provider = 'claude';
|
|
20
|
+
this.apiKey = apiKey;
|
|
21
|
+
this.model = model || MODEL_CLAUDE_3_HAIKU;
|
|
22
|
+
this.visionModel = visionModel || MODEL_CLAUDE_3_HAIKU;
|
|
23
|
+
this.tools = tools;
|
|
24
|
+
this.mcpServers = mcpServers;
|
|
25
|
+
this.responseLength = responseLength;
|
|
26
|
+
// Validate vision model supports vision capabilities
|
|
27
|
+
if (!CLAUDE_VISION_SUPPORTED_MODELS.includes(this.visionModel)) {
|
|
28
|
+
throw new Error(`Model ${this.visionModel} does not support vision capabilities.`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get the current model name
|
|
33
|
+
* @returns Model name
|
|
34
|
+
*/
|
|
35
|
+
getModel() {
|
|
36
|
+
return this.model;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get the current vision model name
|
|
40
|
+
* @returns Vision model name
|
|
41
|
+
*/
|
|
42
|
+
getVisionModel() {
|
|
43
|
+
return this.visionModel;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get configured MCP servers
|
|
47
|
+
* @returns Array of MCP server configurations
|
|
48
|
+
*/
|
|
49
|
+
getMCPServers() {
|
|
50
|
+
return this.mcpServers;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Add MCP server configuration
|
|
54
|
+
* @param serverConfig MCP server configuration
|
|
55
|
+
*/
|
|
56
|
+
addMCPServer(serverConfig) {
|
|
57
|
+
this.mcpServers.push(serverConfig);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Remove MCP server by name
|
|
61
|
+
* @param serverName Name of the server to remove
|
|
62
|
+
*/
|
|
63
|
+
removeMCPServer(serverName) {
|
|
64
|
+
this.mcpServers = this.mcpServers.filter((server) => server.name !== serverName);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Check if MCP servers are configured
|
|
68
|
+
* @returns True if MCP servers are configured
|
|
69
|
+
*/
|
|
70
|
+
hasMCPServers() {
|
|
71
|
+
return this.mcpServers.length > 0;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Process chat messages
|
|
75
|
+
* @param messages Array of messages to send
|
|
76
|
+
* @param onPartialResponse Callback to receive each part of streaming response
|
|
77
|
+
* @param onCompleteResponse Callback to execute when response is complete
|
|
78
|
+
*/
|
|
79
|
+
async processChat(messages, onPartialResponse, onCompleteResponse) {
|
|
80
|
+
// not use tools or MCP servers
|
|
81
|
+
if (this.tools.length === 0 && this.mcpServers.length === 0) {
|
|
82
|
+
const res = await this.callClaude(messages, this.model, true);
|
|
83
|
+
const full = await this.parsePureStream(res, onPartialResponse);
|
|
84
|
+
await onCompleteResponse(full);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
// use tools or MCP servers
|
|
88
|
+
const result = await this.chatOnce(messages, true, onPartialResponse);
|
|
89
|
+
if (result.stop_reason === 'end') {
|
|
90
|
+
const full = result.blocks
|
|
91
|
+
.filter((b) => b.type === 'text')
|
|
92
|
+
.map((b) => b.text)
|
|
93
|
+
.join('');
|
|
94
|
+
await onCompleteResponse(full);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
/* if tool_use, throw error */
|
|
98
|
+
throw new Error('processChat received tool_calls. ChatProcessor must use chatOnce() loop when tools are enabled.');
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Process chat messages with images
|
|
102
|
+
* @param messages Array of messages to send (including images)
|
|
103
|
+
* @param onPartialResponse Callback to receive each part of streaming response
|
|
104
|
+
* @param onCompleteResponse Callback to execute when response is complete
|
|
105
|
+
*/
|
|
106
|
+
async processVisionChat(messages, onPartialResponse, onCompleteResponse) {
|
|
107
|
+
/* same branch logic for vision */
|
|
108
|
+
if (this.tools.length === 0 && this.mcpServers.length === 0) {
|
|
109
|
+
const res = await this.callClaude(messages, this.visionModel, true);
|
|
110
|
+
const full = await this.parsePureStream(res, onPartialResponse);
|
|
111
|
+
await onCompleteResponse(full);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const result = await this.visionChatOnce(messages); // non-stream (tools only)
|
|
115
|
+
if (result.stop_reason === 'end') {
|
|
116
|
+
const full = result.blocks
|
|
117
|
+
.filter((b) => b.type === 'text')
|
|
118
|
+
.map((b) => b.text)
|
|
119
|
+
.join('');
|
|
120
|
+
await onCompleteResponse(full);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
throw new Error('processVisionChat received tool_calls. ChatProcessor must use chatOnce() loop when tools are enabled.');
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Convert AITuber OnAir messages to Claude format
|
|
127
|
+
* @param messages Array of messages
|
|
128
|
+
* @returns Claude formatted messages
|
|
129
|
+
*/
|
|
130
|
+
convertMessagesToClaudeFormat(messages) {
|
|
131
|
+
return messages.map((msg) => {
|
|
132
|
+
return {
|
|
133
|
+
role: this.mapRoleToClaude(msg.role),
|
|
134
|
+
content: msg.content,
|
|
135
|
+
};
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Convert AITuber OnAir vision messages to Claude format
|
|
140
|
+
* @param messages Array of vision messages
|
|
141
|
+
* @returns Claude formatted vision messages
|
|
142
|
+
*/
|
|
143
|
+
convertVisionMessagesToClaudeFormat(messages) {
|
|
144
|
+
return messages.map((msg) => {
|
|
145
|
+
// If message content is a string, create a text-only message
|
|
146
|
+
if (typeof msg.content === 'string') {
|
|
147
|
+
return {
|
|
148
|
+
role: this.mapRoleToClaude(msg.role),
|
|
149
|
+
content: [
|
|
150
|
+
{
|
|
151
|
+
type: 'text',
|
|
152
|
+
text: msg.content,
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
// If message content is an array of blocks, convert each block
|
|
158
|
+
if (Array.isArray(msg.content)) {
|
|
159
|
+
const content = msg.content
|
|
160
|
+
.map((block) => {
|
|
161
|
+
if (block.type === 'image_url') {
|
|
162
|
+
// check if the image url is a data url
|
|
163
|
+
if (block.image_url.url.startsWith('data:')) {
|
|
164
|
+
const m = block.image_url.url.match(/^data:([^;]+);base64,(.+)$/);
|
|
165
|
+
if (m) {
|
|
166
|
+
return {
|
|
167
|
+
type: 'image',
|
|
168
|
+
source: { type: 'base64', media_type: m[1], data: m[2] },
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
// if the image url is a normal url
|
|
174
|
+
return {
|
|
175
|
+
type: 'image',
|
|
176
|
+
source: {
|
|
177
|
+
type: 'url',
|
|
178
|
+
url: block.image_url.url,
|
|
179
|
+
media_type: this.getMimeTypeFromUrl(block.image_url.url),
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
return block;
|
|
184
|
+
})
|
|
185
|
+
.filter((b) => b);
|
|
186
|
+
return {
|
|
187
|
+
role: this.mapRoleToClaude(msg.role),
|
|
188
|
+
content,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
role: this.mapRoleToClaude(msg.role),
|
|
193
|
+
content: [],
|
|
194
|
+
};
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Map AITuber OnAir roles to Claude roles
|
|
199
|
+
* @param role AITuber OnAir role
|
|
200
|
+
* @returns Claude role
|
|
201
|
+
*/
|
|
202
|
+
mapRoleToClaude(role) {
|
|
203
|
+
switch (role) {
|
|
204
|
+
case 'system':
|
|
205
|
+
// Claude handles system messages separately, but we'll map it anyway
|
|
206
|
+
return 'system';
|
|
207
|
+
case 'user':
|
|
208
|
+
return 'user';
|
|
209
|
+
case 'assistant':
|
|
210
|
+
return 'assistant';
|
|
211
|
+
default:
|
|
212
|
+
return 'user';
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Get MIME type from URL
|
|
217
|
+
* @param url Image URL
|
|
218
|
+
* @returns MIME type
|
|
219
|
+
*/
|
|
220
|
+
getMimeTypeFromUrl(url) {
|
|
221
|
+
const extension = url.split('.').pop()?.toLowerCase();
|
|
222
|
+
switch (extension) {
|
|
223
|
+
case 'jpg':
|
|
224
|
+
case 'jpeg':
|
|
225
|
+
return 'image/jpeg';
|
|
226
|
+
case 'png':
|
|
227
|
+
return 'image/png';
|
|
228
|
+
case 'gif':
|
|
229
|
+
return 'image/gif';
|
|
230
|
+
case 'webp':
|
|
231
|
+
return 'image/webp';
|
|
232
|
+
default:
|
|
233
|
+
return 'image/jpeg';
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Call Claude API
|
|
238
|
+
* @param messages Array of messages to send
|
|
239
|
+
* @param model Model name
|
|
240
|
+
* @param stream Whether to stream the response
|
|
241
|
+
* @param maxTokens Maximum tokens for response (optional)
|
|
242
|
+
* @returns Response
|
|
243
|
+
*/
|
|
244
|
+
async callClaude(messages, model, stream, maxTokens) {
|
|
245
|
+
const system = messages.find((m) => m.role === 'system')?.content ?? '';
|
|
246
|
+
const content = messages.filter((m) => m.role !== 'system');
|
|
247
|
+
const hasVision = content.some((m) => Array.isArray(m.content) &&
|
|
248
|
+
m.content.some((b) => b.type === 'image_url' || b.type === 'image'));
|
|
249
|
+
const body = {
|
|
250
|
+
model,
|
|
251
|
+
system,
|
|
252
|
+
messages: hasVision
|
|
253
|
+
? this.convertVisionMessagesToClaudeFormat(content)
|
|
254
|
+
: this.convertMessagesToClaudeFormat(content),
|
|
255
|
+
stream,
|
|
256
|
+
max_tokens: maxTokens !== undefined
|
|
257
|
+
? maxTokens
|
|
258
|
+
: getMaxTokensForResponseLength(this.responseLength),
|
|
259
|
+
};
|
|
260
|
+
if (this.tools.length) {
|
|
261
|
+
body.tools = this.tools.map((t) => ({
|
|
262
|
+
name: t.name,
|
|
263
|
+
description: t.description,
|
|
264
|
+
input_schema: t.parameters,
|
|
265
|
+
}));
|
|
266
|
+
body.tool_choice = { type: 'auto' };
|
|
267
|
+
}
|
|
268
|
+
// Add MCP servers if configured
|
|
269
|
+
if (this.mcpServers.length > 0) {
|
|
270
|
+
body.mcp_servers = this.mcpServers;
|
|
271
|
+
}
|
|
272
|
+
const headers = {
|
|
273
|
+
'Content-Type': 'application/json',
|
|
274
|
+
'x-api-key': this.apiKey,
|
|
275
|
+
'anthropic-version': '2023-06-01',
|
|
276
|
+
'anthropic-dangerous-direct-browser-access': 'true',
|
|
277
|
+
};
|
|
278
|
+
// Add beta header if MCP servers are configured
|
|
279
|
+
if (this.mcpServers.length > 0) {
|
|
280
|
+
headers['anthropic-beta'] = 'mcp-client-2025-04-04';
|
|
281
|
+
}
|
|
282
|
+
const res = await ChatServiceHttpClient.post(ENDPOINT_CLAUDE_API, body, headers);
|
|
283
|
+
return res;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Parse stream response
|
|
287
|
+
* @param res Response
|
|
288
|
+
* @param onPartial Callback to receive each part of streaming response
|
|
289
|
+
* @returns ClaudeInternalCompletion
|
|
290
|
+
*/
|
|
291
|
+
async parseStream(res, onPartial) {
|
|
292
|
+
const reader = res.body.getReader();
|
|
293
|
+
const dec = new TextDecoder();
|
|
294
|
+
const textBlocks = [];
|
|
295
|
+
const toolCalls = new Map();
|
|
296
|
+
let buf = '';
|
|
297
|
+
while (true) {
|
|
298
|
+
const { done, value } = await reader.read();
|
|
299
|
+
if (done)
|
|
300
|
+
break;
|
|
301
|
+
buf += dec.decode(value, { stream: true });
|
|
302
|
+
let nl;
|
|
303
|
+
while ((nl = buf.indexOf('\n')) !== -1) {
|
|
304
|
+
const line = buf.slice(0, nl).trim();
|
|
305
|
+
buf = buf.slice(nl + 1);
|
|
306
|
+
if (!line.startsWith('data:'))
|
|
307
|
+
continue;
|
|
308
|
+
const payload = line.slice(5).trim();
|
|
309
|
+
if (payload === '[DONE]')
|
|
310
|
+
break;
|
|
311
|
+
const ev = JSON.parse(payload);
|
|
312
|
+
/* content delta */
|
|
313
|
+
if (ev.type === 'content_block_delta' && ev.delta?.text) {
|
|
314
|
+
onPartial(ev.delta.text);
|
|
315
|
+
textBlocks.push({ type: 'text', text: ev.delta.text });
|
|
316
|
+
}
|
|
317
|
+
/* tool_call delta */
|
|
318
|
+
if (ev.type === 'content_block_start' &&
|
|
319
|
+
ev.content_block?.type === 'tool_use') {
|
|
320
|
+
toolCalls.set(ev.index, {
|
|
321
|
+
id: ev.content_block.id,
|
|
322
|
+
name: ev.content_block.name,
|
|
323
|
+
args: '',
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
else if (ev.type === 'content_block_start' &&
|
|
327
|
+
ev.content_block?.type === 'mcp_tool_use') {
|
|
328
|
+
// Handle MCP tool use
|
|
329
|
+
toolCalls.set(ev.index, {
|
|
330
|
+
id: ev.content_block.id,
|
|
331
|
+
name: ev.content_block.name,
|
|
332
|
+
args: '',
|
|
333
|
+
server_name: ev.content_block.server_name,
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
else if (ev.type === 'content_block_start' && // case of non-stream
|
|
337
|
+
ev.content_block?.type === 'tool_result') {
|
|
338
|
+
textBlocks.push({
|
|
339
|
+
type: 'tool_result',
|
|
340
|
+
tool_use_id: ev.content_block.tool_use_id,
|
|
341
|
+
content: ev.content_block.content ?? '',
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
else if (ev.type === 'content_block_start' &&
|
|
345
|
+
ev.content_block?.type === 'mcp_tool_result') {
|
|
346
|
+
// Handle MCP tool result
|
|
347
|
+
textBlocks.push({
|
|
348
|
+
type: 'mcp_tool_result',
|
|
349
|
+
tool_use_id: ev.content_block.tool_use_id,
|
|
350
|
+
is_error: ev.content_block.is_error ?? false,
|
|
351
|
+
content: ev.content_block.content ?? [],
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
/* case of input_json_delta */
|
|
355
|
+
if (ev.type === 'content_block_delta' &&
|
|
356
|
+
ev.delta?.type === 'input_json_delta') {
|
|
357
|
+
const entry = toolCalls.get(ev.index);
|
|
358
|
+
if (entry)
|
|
359
|
+
entry.args += ev.delta.partial_json || '';
|
|
360
|
+
}
|
|
361
|
+
/* case of content_block_stop */
|
|
362
|
+
if (ev.type === 'content_block_stop' && toolCalls.has(ev.index)) {
|
|
363
|
+
const { id, name, args, server_name } = toolCalls.get(ev.index);
|
|
364
|
+
if (server_name) {
|
|
365
|
+
// MCP tool use
|
|
366
|
+
textBlocks.push({
|
|
367
|
+
type: 'mcp_tool_use',
|
|
368
|
+
id,
|
|
369
|
+
name,
|
|
370
|
+
server_name,
|
|
371
|
+
input: JSON.parse(args || '{}'),
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
// Standard tool use
|
|
376
|
+
textBlocks.push({
|
|
377
|
+
type: 'tool_use',
|
|
378
|
+
id,
|
|
379
|
+
name,
|
|
380
|
+
input: JSON.parse(args || '{}'),
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
toolCalls.delete(ev.index);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return {
|
|
388
|
+
blocks: textBlocks,
|
|
389
|
+
stop_reason: textBlocks.some((b) => b.type === 'tool_use' || b.type === 'mcp_tool_use')
|
|
390
|
+
? 'tool_use'
|
|
391
|
+
: 'end',
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
async parsePureStream(res, onPartial) {
|
|
395
|
+
const { blocks } = await this.parseStream(res, onPartial);
|
|
396
|
+
return blocks
|
|
397
|
+
.filter((b) => b.type === 'text')
|
|
398
|
+
.map((b) => b.text)
|
|
399
|
+
.join('');
|
|
400
|
+
}
|
|
401
|
+
parseOneShot(data) {
|
|
402
|
+
const blocks = [];
|
|
403
|
+
(data.content ?? []).forEach((c) => {
|
|
404
|
+
if (c.type === 'text') {
|
|
405
|
+
blocks.push({ type: 'text', text: c.text });
|
|
406
|
+
}
|
|
407
|
+
else if (c.type === 'tool_use') {
|
|
408
|
+
blocks.push({
|
|
409
|
+
type: 'tool_use',
|
|
410
|
+
id: c.id,
|
|
411
|
+
name: c.name,
|
|
412
|
+
input: c.input ?? {},
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
else if (c.type === 'mcp_tool_use') {
|
|
416
|
+
blocks.push({
|
|
417
|
+
type: 'mcp_tool_use',
|
|
418
|
+
id: c.id,
|
|
419
|
+
name: c.name,
|
|
420
|
+
server_name: c.server_name,
|
|
421
|
+
input: c.input ?? {},
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
else if (c.type === 'tool_result') {
|
|
425
|
+
blocks.push({
|
|
426
|
+
type: 'tool_result',
|
|
427
|
+
tool_use_id: c.tool_use_id,
|
|
428
|
+
content: c.content ?? '',
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
else if (c.type === 'mcp_tool_result') {
|
|
432
|
+
blocks.push({
|
|
433
|
+
type: 'mcp_tool_result',
|
|
434
|
+
tool_use_id: c.tool_use_id,
|
|
435
|
+
is_error: c.is_error ?? false,
|
|
436
|
+
content: c.content ?? [],
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
return {
|
|
441
|
+
blocks,
|
|
442
|
+
stop_reason: blocks.some((b) => b.type === 'tool_use' || b.type === 'mcp_tool_use')
|
|
443
|
+
? 'tool_use'
|
|
444
|
+
: 'end',
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Process chat messages
|
|
449
|
+
* @param messages Array of messages to send
|
|
450
|
+
* @param stream Whether to stream the response
|
|
451
|
+
* @param onPartial Callback to receive each part of streaming response
|
|
452
|
+
* @param maxTokens Maximum tokens for response (optional)
|
|
453
|
+
* @returns ToolChatCompletion
|
|
454
|
+
*/
|
|
455
|
+
async chatOnce(messages, stream = true, onPartial = () => { }, maxTokens) {
|
|
456
|
+
const res = await this.callClaude(messages, this.model, stream, maxTokens);
|
|
457
|
+
const internalResult = stream
|
|
458
|
+
? await this.parseStream(res, onPartial)
|
|
459
|
+
: this.parseOneShot(await res.json());
|
|
460
|
+
// Convert ClaudeInternalCompletion to ToolChatCompletion for compatibility
|
|
461
|
+
return this.convertToStandardCompletion(internalResult);
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Process vision chat messages
|
|
465
|
+
* @param messages Array of messages to send
|
|
466
|
+
* @param stream Whether to stream the response
|
|
467
|
+
* @param onPartial Callback to receive each part of streaming response
|
|
468
|
+
* @param maxTokens Maximum tokens for response (optional)
|
|
469
|
+
* @returns ToolChatCompletion
|
|
470
|
+
*/
|
|
471
|
+
async visionChatOnce(messages, stream = false, onPartial = () => { }, maxTokens) {
|
|
472
|
+
const res = await this.callClaude(messages, this.visionModel, stream, maxTokens);
|
|
473
|
+
const internalResult = stream
|
|
474
|
+
? await this.parseStream(res, onPartial)
|
|
475
|
+
: this.parseOneShot(await res.json());
|
|
476
|
+
// Convert ClaudeInternalCompletion to ToolChatCompletion for compatibility
|
|
477
|
+
return this.convertToStandardCompletion(internalResult);
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Convert internal completion to standard ToolChatCompletion
|
|
481
|
+
* @param completion Internal completion result
|
|
482
|
+
* @returns Standard ToolChatCompletion
|
|
483
|
+
*/
|
|
484
|
+
convertToStandardCompletion(completion) {
|
|
485
|
+
// Filter out MCP-specific blocks and convert to standard format
|
|
486
|
+
const standardBlocks = completion.blocks.filter((block) => {
|
|
487
|
+
return (block.type === 'text' ||
|
|
488
|
+
block.type === 'tool_use' ||
|
|
489
|
+
block.type === 'tool_result');
|
|
490
|
+
});
|
|
491
|
+
return {
|
|
492
|
+
blocks: standardBlocks,
|
|
493
|
+
stop_reason: completion.stop_reason,
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
//# sourceMappingURL=ClaudeChatService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClaudeChatService.js","sourceRoot":"","sources":["../../../../../src/services/providers/claude/ClaudeChatService.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,8BAA8B,GAC/B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAEL,6BAA6B,GAC9B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAoB7E;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAW5B;;;;;;;;OAQG;IACH,YACE,MAAc,EACd,QAAgB,oBAAoB,EACpC,cAAsB,oBAAoB,EAC1C,QAA0B,EAAE,EAC5B,aAAgC,EAAE,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C3B,CAAC,CAAC,MAAM,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,SAAS,CAAC;YACxC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;QAExC,2EAA2E;QAC3E,OAAO,IAAI,CAAC,2BAA2B,CAAC,cAAc,CAAC,CAAC;IAC1D,CAAC;IAED;;;;OAIG;IACK,2BAA2B,CACjC,UAAoC;QAEpC,gEAAgE;QAChE,MAAM,cAAc,GAAG,UAAU,CAAC,MAAM,CAAC,MAAM,CAC7C,CAAC,KAAK,EAA8B,EAAE;YACpC,OAAO,CACL,KAAK,CAAC,IAAI,KAAK,MAAM;gBACrB,KAAK,CAAC,IAAI,KAAK,UAAU;gBACzB,KAAK,CAAC,IAAI,KAAK,aAAa,CAC7B,CAAC;QACJ,CAAC,CACF,CAAC;QAEF,OAAO;YACL,MAAM,EAAE,cAAc;YACtB,WAAW,EAAE,UAAU,CAAC,WAAW;SACpC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ChatService } from '../../ChatService';
|
|
2
|
+
import { ChatServiceOptions, ChatServiceProvider } from '../ChatServiceProvider';
|
|
3
|
+
/**
|
|
4
|
+
* Claude API provider implementation
|
|
5
|
+
*/
|
|
6
|
+
export declare class ClaudeChatServiceProvider implements ChatServiceProvider {
|
|
7
|
+
/**
|
|
8
|
+
* Create a chat service instance
|
|
9
|
+
* @param options Service options (can include mcpServers)
|
|
10
|
+
* @returns ClaudeChatService instance
|
|
11
|
+
*/
|
|
12
|
+
createChatService(options: ChatServiceOptions): ChatService;
|
|
13
|
+
/**
|
|
14
|
+
* Get the provider name
|
|
15
|
+
* @returns Provider name ('claude')
|
|
16
|
+
*/
|
|
17
|
+
getProviderName(): string;
|
|
18
|
+
/**
|
|
19
|
+
* Get the list of supported models
|
|
20
|
+
* @returns Array of supported model names
|
|
21
|
+
*/
|
|
22
|
+
getSupportedModels(): string[];
|
|
23
|
+
/**
|
|
24
|
+
* Get the default model
|
|
25
|
+
* @returns Default model name
|
|
26
|
+
*/
|
|
27
|
+
getDefaultModel(): string;
|
|
28
|
+
/**
|
|
29
|
+
* Check if this provider supports vision (image processing)
|
|
30
|
+
* @returns Vision support status (true)
|
|
31
|
+
*/
|
|
32
|
+
supportsVision(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Check if a specific model supports vision capabilities
|
|
35
|
+
* @param model The model name to check
|
|
36
|
+
* @returns True if the model supports vision, false otherwise
|
|
37
|
+
*/
|
|
38
|
+
supportsVisionForModel(model: string): boolean;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=ClaudeChatServiceProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClaudeChatServiceProvider.d.ts","sourceRoot":"","sources":["../../../../../src/services/providers/claude/ClaudeChatServiceProvider.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAEhC;;GAEG;AACH,qBAAa,yBAA0B,YAAW,mBAAmB;IACnE;;;;OAIG;IACH,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW;IAkB3D;;;OAGG;IACH,eAAe,IAAI,MAAM;IAIzB;;;OAGG;IACH,kBAAkB,IAAI,MAAM,EAAE;IAW9B;;;OAGG;IACH,eAAe,IAAI,MAAM;IAIzB;;;OAGG;IACH,cAAc,IAAI,OAAO;IAIzB;;;;OAIG;IACH,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAG/C"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { MODEL_CLAUDE_3_HAIKU, MODEL_CLAUDE_3_5_HAIKU, MODEL_CLAUDE_3_5_SONNET, MODEL_CLAUDE_3_7_SONNET, MODEL_CLAUDE_4_SONNET, MODEL_CLAUDE_4_OPUS, CLAUDE_VISION_SUPPORTED_MODELS, } from '../../../constants';
|
|
2
|
+
import { ClaudeChatService } from './ClaudeChatService';
|
|
3
|
+
/**
|
|
4
|
+
* Claude API provider implementation
|
|
5
|
+
*/
|
|
6
|
+
export class ClaudeChatServiceProvider {
|
|
7
|
+
/**
|
|
8
|
+
* Create a chat service instance
|
|
9
|
+
* @param options Service options (can include mcpServers)
|
|
10
|
+
* @returns ClaudeChatService instance
|
|
11
|
+
*/
|
|
12
|
+
createChatService(options) {
|
|
13
|
+
// Use the visionModel if provided, otherwise use the model that supports vision
|
|
14
|
+
const visionModel = options.visionModel ||
|
|
15
|
+
(this.supportsVisionForModel(options.model || this.getDefaultModel())
|
|
16
|
+
? options.model
|
|
17
|
+
: this.getDefaultModel());
|
|
18
|
+
return new ClaudeChatService(options.apiKey, options.model || this.getDefaultModel(), visionModel, options.tools ?? [], options.mcpServers ?? [], options.responseLength);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get the provider name
|
|
22
|
+
* @returns Provider name ('claude')
|
|
23
|
+
*/
|
|
24
|
+
getProviderName() {
|
|
25
|
+
return 'claude';
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get the list of supported models
|
|
29
|
+
* @returns Array of supported model names
|
|
30
|
+
*/
|
|
31
|
+
getSupportedModels() {
|
|
32
|
+
return [
|
|
33
|
+
MODEL_CLAUDE_3_HAIKU,
|
|
34
|
+
MODEL_CLAUDE_3_5_HAIKU,
|
|
35
|
+
MODEL_CLAUDE_3_5_SONNET,
|
|
36
|
+
MODEL_CLAUDE_3_7_SONNET,
|
|
37
|
+
MODEL_CLAUDE_4_SONNET,
|
|
38
|
+
MODEL_CLAUDE_4_OPUS,
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get the default model
|
|
43
|
+
* @returns Default model name
|
|
44
|
+
*/
|
|
45
|
+
getDefaultModel() {
|
|
46
|
+
return MODEL_CLAUDE_3_HAIKU;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Check if this provider supports vision (image processing)
|
|
50
|
+
* @returns Vision support status (true)
|
|
51
|
+
*/
|
|
52
|
+
supportsVision() {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Check if a specific model supports vision capabilities
|
|
57
|
+
* @param model The model name to check
|
|
58
|
+
* @returns True if the model supports vision, false otherwise
|
|
59
|
+
*/
|
|
60
|
+
supportsVisionForModel(model) {
|
|
61
|
+
return CLAUDE_VISION_SUPPORTED_MODELS.includes(model);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=ClaudeChatServiceProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClaudeChatServiceProvider.js","sourceRoot":"","sources":["../../../../../src/services/providers/claude/ClaudeChatServiceProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EACnB,8BAA8B,GAC/B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAOxD;;GAEG;AACH,MAAM,OAAO,yBAAyB;IACpC;;;;OAIG;IACH,iBAAiB,CAAC,OAA2B;QAC3C,gFAAgF;QAChF,MAAM,WAAW,GACf,OAAO,CAAC,WAAW;YACnB,CAAC,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;gBACnE,CAAC,CAAC,OAAO,CAAC,KAAK;gBACf,CAAC,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC;QAE9B,OAAO,IAAI,iBAAiB,CAC1B,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,eAAe,EAAE,EACvC,WAAW,EACX,OAAO,CA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