@aituber-onair/chat 0.2.0 → 0.3.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 +21 -2
- package/README.md +22 -3
- package/dist/cjs/constants/index.d.ts +1 -0
- package/dist/cjs/constants/index.d.ts.map +1 -1
- package/dist/cjs/constants/index.js +1 -0
- package/dist/cjs/constants/index.js.map +1 -1
- package/dist/cjs/constants/openrouter.d.ts +21 -0
- package/dist/cjs/constants/openrouter.d.ts.map +1 -0
- package/dist/cjs/constants/openrouter.js +34 -0
- package/dist/cjs/constants/openrouter.js.map +1 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +6 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/services/ChatServiceFactory.d.ts.map +1 -1
- package/dist/cjs/services/ChatServiceFactory.js +3 -0
- package/dist/cjs/services/ChatServiceFactory.js.map +1 -1
- package/dist/cjs/services/providers/ChatServiceProvider.d.ts +5 -1
- package/dist/cjs/services/providers/ChatServiceProvider.d.ts.map +1 -1
- package/dist/cjs/services/providers/openai/OpenAIChatService.d.ts.map +1 -1
- package/dist/cjs/services/providers/openai/OpenAIChatService.js +25 -7
- package/dist/cjs/services/providers/openai/OpenAIChatService.js.map +1 -1
- package/dist/cjs/services/providers/openai/OpenAIChatServiceProvider.d.ts.map +1 -1
- package/dist/cjs/services/providers/openai/OpenAIChatServiceProvider.js +8 -15
- package/dist/cjs/services/providers/openai/OpenAIChatServiceProvider.js.map +1 -1
- package/dist/cjs/services/providers/openrouter/OpenRouterChatService.d.ts +108 -0
- package/dist/cjs/services/providers/openrouter/OpenRouterChatService.d.ts.map +1 -0
- package/dist/cjs/services/providers/openrouter/OpenRouterChatService.js +397 -0
- package/dist/cjs/services/providers/openrouter/OpenRouterChatService.js.map +1 -0
- package/dist/cjs/services/providers/openrouter/OpenRouterChatServiceProvider.d.ts +53 -0
- package/dist/cjs/services/providers/openrouter/OpenRouterChatServiceProvider.d.ts.map +1 -0
- package/dist/cjs/services/providers/openrouter/OpenRouterChatServiceProvider.js +89 -0
- package/dist/cjs/services/providers/openrouter/OpenRouterChatServiceProvider.js.map +1 -0
- package/dist/esm/constants/index.d.ts +1 -0
- package/dist/esm/constants/index.d.ts.map +1 -1
- package/dist/esm/constants/index.js +1 -0
- package/dist/esm/constants/index.js.map +1 -1
- package/dist/esm/constants/openrouter.d.ts +21 -0
- package/dist/esm/constants/openrouter.d.ts.map +1 -0
- package/dist/esm/constants/openrouter.js +29 -0
- package/dist/esm/constants/openrouter.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/services/ChatServiceFactory.d.ts.map +1 -1
- package/dist/esm/services/ChatServiceFactory.js +3 -0
- package/dist/esm/services/ChatServiceFactory.js.map +1 -1
- package/dist/esm/services/providers/ChatServiceProvider.d.ts +5 -1
- package/dist/esm/services/providers/ChatServiceProvider.d.ts.map +1 -1
- package/dist/esm/services/providers/openai/OpenAIChatService.d.ts.map +1 -1
- package/dist/esm/services/providers/openai/OpenAIChatService.js +25 -7
- package/dist/esm/services/providers/openai/OpenAIChatService.js.map +1 -1
- package/dist/esm/services/providers/openai/OpenAIChatServiceProvider.d.ts.map +1 -1
- package/dist/esm/services/providers/openai/OpenAIChatServiceProvider.js +8 -15
- package/dist/esm/services/providers/openai/OpenAIChatServiceProvider.js.map +1 -1
- package/dist/esm/services/providers/openrouter/OpenRouterChatService.d.ts +108 -0
- package/dist/esm/services/providers/openrouter/OpenRouterChatService.d.ts.map +1 -0
- package/dist/esm/services/providers/openrouter/OpenRouterChatService.js +393 -0
- package/dist/esm/services/providers/openrouter/OpenRouterChatService.js.map +1 -0
- package/dist/esm/services/providers/openrouter/OpenRouterChatServiceProvider.d.ts +53 -0
- package/dist/esm/services/providers/openrouter/OpenRouterChatServiceProvider.d.ts.map +1 -0
- package/dist/esm/services/providers/openrouter/OpenRouterChatServiceProvider.js +85 -0
- package/dist/esm/services/providers/openrouter/OpenRouterChatServiceProvider.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { ChatService } from '../../ChatService';
|
|
2
|
+
import { Message, MessageWithVision } from '../../../types';
|
|
3
|
+
import { ToolDefinition, ToolChatCompletion } from '../../../types';
|
|
4
|
+
import { ChatResponseLength } from '../../../constants/chat';
|
|
5
|
+
/**
|
|
6
|
+
* OpenRouter implementation of ChatService
|
|
7
|
+
* OpenRouter provides access to multiple AI models through a unified API
|
|
8
|
+
*/
|
|
9
|
+
export declare class OpenRouterChatService implements ChatService {
|
|
10
|
+
/** Provider name */
|
|
11
|
+
readonly provider: string;
|
|
12
|
+
private apiKey;
|
|
13
|
+
private model;
|
|
14
|
+
private visionModel;
|
|
15
|
+
private tools;
|
|
16
|
+
private endpoint;
|
|
17
|
+
private responseLength?;
|
|
18
|
+
private appName?;
|
|
19
|
+
private appUrl?;
|
|
20
|
+
private reasoning_effort?;
|
|
21
|
+
private includeReasoning?;
|
|
22
|
+
private reasoningMaxTokens?;
|
|
23
|
+
private lastRequestTime;
|
|
24
|
+
private requestCount;
|
|
25
|
+
/**
|
|
26
|
+
* Constructor
|
|
27
|
+
* @param apiKey OpenRouter API key
|
|
28
|
+
* @param model Name of the model to use
|
|
29
|
+
* @param visionModel Name of the vision model
|
|
30
|
+
* @param tools Tool definitions (optional)
|
|
31
|
+
* @param endpoint API endpoint (optional)
|
|
32
|
+
* @param responseLength Response length configuration (optional)
|
|
33
|
+
* @param appName Application name for OpenRouter analytics (optional)
|
|
34
|
+
* @param appUrl Application URL for OpenRouter analytics (optional)
|
|
35
|
+
* @param reasoning_effort Reasoning effort level (optional)
|
|
36
|
+
* @param includeReasoning Whether to include reasoning in response (optional)
|
|
37
|
+
* @param reasoningMaxTokens Maximum tokens for reasoning (optional)
|
|
38
|
+
*/
|
|
39
|
+
constructor(apiKey: string, model?: string, visionModel?: string, tools?: ToolDefinition[], endpoint?: string, responseLength?: ChatResponseLength, appName?: string, appUrl?: string, reasoning_effort?: 'minimal' | 'low' | 'medium' | 'high', includeReasoning?: boolean, reasoningMaxTokens?: number);
|
|
40
|
+
/**
|
|
41
|
+
* Get the current model name
|
|
42
|
+
* @returns Model name
|
|
43
|
+
*/
|
|
44
|
+
getModel(): string;
|
|
45
|
+
/**
|
|
46
|
+
* Get the current vision model name
|
|
47
|
+
* @returns Vision model name
|
|
48
|
+
*/
|
|
49
|
+
getVisionModel(): string;
|
|
50
|
+
/**
|
|
51
|
+
* Apply rate limiting for free tier models
|
|
52
|
+
*/
|
|
53
|
+
private applyRateLimiting;
|
|
54
|
+
/**
|
|
55
|
+
* Process chat messages
|
|
56
|
+
* @param messages Array of messages to send
|
|
57
|
+
* @param onPartialResponse Callback to receive each part of streaming response
|
|
58
|
+
* @param onCompleteResponse Callback to execute when response is complete
|
|
59
|
+
*/
|
|
60
|
+
processChat(messages: Message[], onPartialResponse: (text: string) => void, onCompleteResponse: (text: string) => Promise<void>): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Process chat messages with images
|
|
63
|
+
* @param messages Array of messages to send (including images)
|
|
64
|
+
* @param onPartialResponse Callback to receive each part of streaming response
|
|
65
|
+
* @param onCompleteResponse Callback to execute when response is complete
|
|
66
|
+
*/
|
|
67
|
+
processVisionChat(messages: MessageWithVision[], onPartialResponse: (text: string) => void, onCompleteResponse: (text: string) => Promise<void>): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Process chat messages with tools (text only)
|
|
70
|
+
* @param messages Array of messages to send
|
|
71
|
+
* @param stream Whether to use streaming
|
|
72
|
+
* @param onPartialResponse Callback for partial responses
|
|
73
|
+
* @param maxTokens Maximum tokens for response (optional)
|
|
74
|
+
* @returns Tool chat completion
|
|
75
|
+
*/
|
|
76
|
+
chatOnce(messages: Message[], stream?: boolean, onPartialResponse?: (text: string) => void, maxTokens?: number): Promise<ToolChatCompletion>;
|
|
77
|
+
/**
|
|
78
|
+
* Process vision chat messages with tools
|
|
79
|
+
* @param messages Array of messages to send (including images)
|
|
80
|
+
* @param stream Whether to use streaming
|
|
81
|
+
* @param onPartialResponse Callback for partial responses
|
|
82
|
+
* @param maxTokens Maximum tokens for response (optional)
|
|
83
|
+
* @returns Tool chat completion
|
|
84
|
+
*/
|
|
85
|
+
visionChatOnce(messages: MessageWithVision[], stream?: boolean, onPartialResponse?: (text: string) => void, maxTokens?: number): Promise<ToolChatCompletion>;
|
|
86
|
+
/**
|
|
87
|
+
* Call OpenRouter API
|
|
88
|
+
*/
|
|
89
|
+
private callOpenRouter;
|
|
90
|
+
/**
|
|
91
|
+
* Build request body for OpenRouter API (OpenAI-compatible format)
|
|
92
|
+
*/
|
|
93
|
+
private buildRequestBody;
|
|
94
|
+
/**
|
|
95
|
+
* Handle streaming response from OpenRouter
|
|
96
|
+
* OpenRouter uses SSE format with potential comment lines
|
|
97
|
+
*/
|
|
98
|
+
private handleStream;
|
|
99
|
+
/**
|
|
100
|
+
* Parse streaming response with tool support
|
|
101
|
+
*/
|
|
102
|
+
private parseStream;
|
|
103
|
+
/**
|
|
104
|
+
* Parse non-streaming response
|
|
105
|
+
*/
|
|
106
|
+
private parseOneShot;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=OpenRouterChatService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenRouterChatService.d.ts","sourceRoot":"","sources":["../../../../../src/services/providers/openrouter/OpenRouterChatService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EACL,cAAc,EAEd,kBAAkB,EACnB,MAAM,gBAAgB,CAAC;AAQxB,OAAO,EACL,kBAAkB,EAEnB,MAAM,yBAAyB,CAAC;A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AI,CAAC,GAClD,OAAO,CAAC,IAAI,CAAC;IA8BhB;;;;;OAKG;IACG,iBAAiB,CACrB,QAAQ,EAAE,iBAAiB,EAAE,EAC7B,iBAAiB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EACzC,kBAAkB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAClD,OAAO,CAAC,IAAI,CAAC;IA8ChB;;;;;;;OAOG;IACG,QAAQ,CACZ,QAAQ,EAAE,OAAO,EAAE,EACnB,MAAM,UAAO,EACb,iBAAiB,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAe,EACpD,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,kBAAkB,CAAC;IAa9B;;;;;;;OAOG;IACG,cAAc,CAClB,QAAQ,EAAE,iBAAiB,EAAE,EAC7B,MAAM,GAAE,OAAe,EACvB,iBAAiB,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAe,EACpD,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,kBAAkB,CAAC;IAoB9B;;OAEG;YACW,cAAc;IA0B5B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAuExB;;;OAGG;YACW,YAAY;IAgD1B;;OAEG;YACW,WAAW;IA+EzB;;OAEG;IACH,OAAO,CAAC,YAAY;CAsBrB"}
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpenRouterChatService = void 0;
|
|
4
|
+
const openrouter_1 = require("../../../constants/openrouter");
|
|
5
|
+
const chat_1 = require("../../../constants/chat");
|
|
6
|
+
const streamTextAccumulator_1 = require("../../../utils/streamTextAccumulator");
|
|
7
|
+
const chatServiceHttpClient_1 = require("../../../utils/chatServiceHttpClient");
|
|
8
|
+
/**
|
|
9
|
+
* OpenRouter implementation of ChatService
|
|
10
|
+
* OpenRouter provides access to multiple AI models through a unified API
|
|
11
|
+
*/
|
|
12
|
+
class OpenRouterChatService {
|
|
13
|
+
/**
|
|
14
|
+
* Constructor
|
|
15
|
+
* @param apiKey OpenRouter API key
|
|
16
|
+
* @param model Name of the model to use
|
|
17
|
+
* @param visionModel Name of the vision model
|
|
18
|
+
* @param tools Tool definitions (optional)
|
|
19
|
+
* @param endpoint API endpoint (optional)
|
|
20
|
+
* @param responseLength Response length configuration (optional)
|
|
21
|
+
* @param appName Application name for OpenRouter analytics (optional)
|
|
22
|
+
* @param appUrl Application URL for OpenRouter analytics (optional)
|
|
23
|
+
* @param reasoning_effort Reasoning effort level (optional)
|
|
24
|
+
* @param includeReasoning Whether to include reasoning in response (optional)
|
|
25
|
+
* @param reasoningMaxTokens Maximum tokens for reasoning (optional)
|
|
26
|
+
*/
|
|
27
|
+
constructor(apiKey, model = openrouter_1.MODEL_GPT_OSS_20B_FREE, visionModel = openrouter_1.MODEL_GPT_OSS_20B_FREE, tools, endpoint = openrouter_1.ENDPOINT_OPENROUTER_API, responseLength, appName, appUrl, reasoning_effort, includeReasoning, reasoningMaxTokens) {
|
|
28
|
+
/** Provider name */
|
|
29
|
+
this.provider = 'openrouter';
|
|
30
|
+
this.lastRequestTime = 0;
|
|
31
|
+
this.requestCount = 0;
|
|
32
|
+
this.apiKey = apiKey;
|
|
33
|
+
this.model = model;
|
|
34
|
+
this.tools = tools || [];
|
|
35
|
+
this.endpoint = endpoint;
|
|
36
|
+
this.responseLength = responseLength;
|
|
37
|
+
this.appName = appName;
|
|
38
|
+
this.appUrl = appUrl;
|
|
39
|
+
this.reasoning_effort = reasoning_effort;
|
|
40
|
+
this.includeReasoning = includeReasoning;
|
|
41
|
+
this.reasoningMaxTokens = reasoningMaxTokens;
|
|
42
|
+
// Store vision model without validation at construction time
|
|
43
|
+
// Validation will be performed when vision methods are actually called
|
|
44
|
+
this.visionModel = visionModel;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get the current model name
|
|
48
|
+
* @returns Model name
|
|
49
|
+
*/
|
|
50
|
+
getModel() {
|
|
51
|
+
return this.model;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get the current vision model name
|
|
55
|
+
* @returns Vision model name
|
|
56
|
+
*/
|
|
57
|
+
getVisionModel() {
|
|
58
|
+
return this.visionModel;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Apply rate limiting for free tier models
|
|
62
|
+
*/
|
|
63
|
+
async applyRateLimiting() {
|
|
64
|
+
if (!(0, openrouter_1.isOpenRouterFreeModel)(this.model)) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const now = Date.now();
|
|
68
|
+
const timeSinceLastRequest = now - this.lastRequestTime;
|
|
69
|
+
// Reset counter if more than a minute has passed
|
|
70
|
+
if (timeSinceLastRequest > 60000) {
|
|
71
|
+
this.requestCount = 0;
|
|
72
|
+
}
|
|
73
|
+
// If we've hit the rate limit, wait
|
|
74
|
+
if (this.requestCount >= openrouter_1.OPENROUTER_FREE_RATE_LIMIT_PER_MINUTE) {
|
|
75
|
+
const waitTime = 60000 - timeSinceLastRequest;
|
|
76
|
+
if (waitTime > 0) {
|
|
77
|
+
console.log(`Rate limit reached for free tier. Waiting ${waitTime}ms...`);
|
|
78
|
+
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
79
|
+
this.requestCount = 0;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
this.lastRequestTime = now;
|
|
83
|
+
this.requestCount++;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Process chat messages
|
|
87
|
+
* @param messages Array of messages to send
|
|
88
|
+
* @param onPartialResponse Callback to receive each part of streaming response
|
|
89
|
+
* @param onCompleteResponse Callback to execute when response is complete
|
|
90
|
+
*/
|
|
91
|
+
async processChat(messages, onPartialResponse, onCompleteResponse) {
|
|
92
|
+
// Apply rate limiting for free tier
|
|
93
|
+
await this.applyRateLimiting();
|
|
94
|
+
// Not using tools
|
|
95
|
+
if (this.tools.length === 0) {
|
|
96
|
+
const res = await this.callOpenRouter(messages, this.model, true);
|
|
97
|
+
const full = await this.handleStream(res, onPartialResponse);
|
|
98
|
+
await onCompleteResponse(full);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
// Using tools
|
|
102
|
+
const { blocks, stop_reason } = await this.chatOnce(messages);
|
|
103
|
+
if (stop_reason === 'end') {
|
|
104
|
+
const full = blocks
|
|
105
|
+
.filter((b) => b.type === 'text')
|
|
106
|
+
.map((b) => b.text)
|
|
107
|
+
.join('');
|
|
108
|
+
await onCompleteResponse(full);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
throw new Error('processChat received tool_calls. ' +
|
|
112
|
+
'ChatProcessor must use chatOnce() loop when tools are enabled.');
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Process chat messages with images
|
|
116
|
+
* @param messages Array of messages to send (including images)
|
|
117
|
+
* @param onPartialResponse Callback to receive each part of streaming response
|
|
118
|
+
* @param onCompleteResponse Callback to execute when response is complete
|
|
119
|
+
*/
|
|
120
|
+
async processVisionChat(messages, onPartialResponse, onCompleteResponse) {
|
|
121
|
+
// Always validate vision capabilities when vision methods are called
|
|
122
|
+
if (!(0, openrouter_1.isOpenRouterVisionModel)(this.visionModel)) {
|
|
123
|
+
throw new Error(`Model ${this.visionModel} does not support vision capabilities.`);
|
|
124
|
+
}
|
|
125
|
+
// Apply rate limiting for free tier
|
|
126
|
+
await this.applyRateLimiting();
|
|
127
|
+
try {
|
|
128
|
+
// Not using tools
|
|
129
|
+
if (this.tools.length === 0) {
|
|
130
|
+
const res = await this.callOpenRouter(messages, this.visionModel, true);
|
|
131
|
+
const full = await this.handleStream(res, onPartialResponse);
|
|
132
|
+
await onCompleteResponse(full);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
// Using tools
|
|
136
|
+
const { blocks, stop_reason } = await this.visionChatOnce(messages, true, onPartialResponse);
|
|
137
|
+
if (stop_reason === 'end') {
|
|
138
|
+
const full = blocks
|
|
139
|
+
.filter((b) => b.type === 'text')
|
|
140
|
+
.map((b) => b.text)
|
|
141
|
+
.join('');
|
|
142
|
+
await onCompleteResponse(full);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
throw new Error('processVisionChat received tool_calls. ' +
|
|
146
|
+
'ChatProcessor must use visionChatOnce() loop when tools are enabled.');
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
console.error('Error in processVisionChat:', error);
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Process chat messages with tools (text only)
|
|
155
|
+
* @param messages Array of messages to send
|
|
156
|
+
* @param stream Whether to use streaming
|
|
157
|
+
* @param onPartialResponse Callback for partial responses
|
|
158
|
+
* @param maxTokens Maximum tokens for response (optional)
|
|
159
|
+
* @returns Tool chat completion
|
|
160
|
+
*/
|
|
161
|
+
async chatOnce(messages, stream = true, onPartialResponse = () => { }, maxTokens) {
|
|
162
|
+
await this.applyRateLimiting();
|
|
163
|
+
const res = await this.callOpenRouter(messages, this.model, stream, maxTokens);
|
|
164
|
+
return stream
|
|
165
|
+
? this.parseStream(res, onPartialResponse)
|
|
166
|
+
: this.parseOneShot(await res.json());
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Process vision chat messages with tools
|
|
170
|
+
* @param messages Array of messages to send (including images)
|
|
171
|
+
* @param stream Whether to use streaming
|
|
172
|
+
* @param onPartialResponse Callback for partial responses
|
|
173
|
+
* @param maxTokens Maximum tokens for response (optional)
|
|
174
|
+
* @returns Tool chat completion
|
|
175
|
+
*/
|
|
176
|
+
async visionChatOnce(messages, stream = false, onPartialResponse = () => { }, maxTokens) {
|
|
177
|
+
// Always validate vision capabilities when vision methods are called
|
|
178
|
+
if (!(0, openrouter_1.isOpenRouterVisionModel)(this.visionModel)) {
|
|
179
|
+
throw new Error(`Model ${this.visionModel} does not support vision capabilities.`);
|
|
180
|
+
}
|
|
181
|
+
await this.applyRateLimiting();
|
|
182
|
+
const res = await this.callOpenRouter(messages, this.visionModel, stream, maxTokens);
|
|
183
|
+
return stream
|
|
184
|
+
? this.parseStream(res, onPartialResponse)
|
|
185
|
+
: this.parseOneShot(await res.json());
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Call OpenRouter API
|
|
189
|
+
*/
|
|
190
|
+
async callOpenRouter(messages, model, stream = false, maxTokens) {
|
|
191
|
+
const body = this.buildRequestBody(messages, model, stream, maxTokens);
|
|
192
|
+
// Build headers
|
|
193
|
+
const headers = {
|
|
194
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
195
|
+
};
|
|
196
|
+
// Add optional analytics headers
|
|
197
|
+
if (this.appUrl) {
|
|
198
|
+
headers['HTTP-Referer'] = this.appUrl;
|
|
199
|
+
}
|
|
200
|
+
if (this.appName) {
|
|
201
|
+
headers['X-Title'] = this.appName;
|
|
202
|
+
}
|
|
203
|
+
const res = await chatServiceHttpClient_1.ChatServiceHttpClient.post(this.endpoint, body, headers);
|
|
204
|
+
return res;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Build request body for OpenRouter API (OpenAI-compatible format)
|
|
208
|
+
*/
|
|
209
|
+
buildRequestBody(messages, model, stream, maxTokens) {
|
|
210
|
+
const body = {
|
|
211
|
+
model,
|
|
212
|
+
messages,
|
|
213
|
+
stream,
|
|
214
|
+
};
|
|
215
|
+
// Add max_tokens if specified
|
|
216
|
+
const tokenLimit = maxTokens !== undefined
|
|
217
|
+
? maxTokens
|
|
218
|
+
: (0, chat_1.getMaxTokensForResponseLength)(this.responseLength);
|
|
219
|
+
// OpenRouter gpt-oss-20b model has known issues with token limits causing empty responses
|
|
220
|
+
// Remove all token limits to ensure proper functionality
|
|
221
|
+
if (tokenLimit) {
|
|
222
|
+
console.warn(`OpenRouter: Token limits are not supported for gpt-oss-20b model due to known issues. Using unlimited tokens instead.`);
|
|
223
|
+
// Do not set max_tokens - use unlimited tokens
|
|
224
|
+
}
|
|
225
|
+
// Add OpenRouter reasoning control
|
|
226
|
+
if (this.reasoning_effort ||
|
|
227
|
+
this.includeReasoning !== undefined ||
|
|
228
|
+
this.reasoningMaxTokens) {
|
|
229
|
+
body.reasoning = {};
|
|
230
|
+
if (this.reasoning_effort) {
|
|
231
|
+
// OpenRouter uses 'low' as the minimum effort level, map 'minimal' to 'low'
|
|
232
|
+
const effort = this.reasoning_effort === 'minimal' ? 'low' : this.reasoning_effort;
|
|
233
|
+
body.reasoning.effort = effort;
|
|
234
|
+
}
|
|
235
|
+
// Default to exclude reasoning if includeReasoning is not explicitly set to true
|
|
236
|
+
if (this.includeReasoning !== true) {
|
|
237
|
+
body.reasoning.exclude = true;
|
|
238
|
+
}
|
|
239
|
+
if (this.reasoningMaxTokens) {
|
|
240
|
+
body.reasoning.max_tokens = this.reasoningMaxTokens;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
// Default behavior: exclude reasoning to avoid empty responses
|
|
245
|
+
body.reasoning = { exclude: true };
|
|
246
|
+
}
|
|
247
|
+
// Add tools if available
|
|
248
|
+
if (this.tools.length > 0) {
|
|
249
|
+
body.tools = this.tools.map((t) => ({
|
|
250
|
+
type: 'function',
|
|
251
|
+
function: {
|
|
252
|
+
name: t.name,
|
|
253
|
+
description: t.description,
|
|
254
|
+
parameters: t.parameters,
|
|
255
|
+
},
|
|
256
|
+
}));
|
|
257
|
+
body.tool_choice = 'auto';
|
|
258
|
+
}
|
|
259
|
+
return body;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Handle streaming response from OpenRouter
|
|
263
|
+
* OpenRouter uses SSE format with potential comment lines
|
|
264
|
+
*/
|
|
265
|
+
async handleStream(res, onPartial) {
|
|
266
|
+
const reader = res.body.getReader();
|
|
267
|
+
const dec = new TextDecoder();
|
|
268
|
+
let buffer = '';
|
|
269
|
+
let full = '';
|
|
270
|
+
while (true) {
|
|
271
|
+
const { done, value } = await reader.read();
|
|
272
|
+
if (done)
|
|
273
|
+
break;
|
|
274
|
+
buffer += dec.decode(value, { stream: true });
|
|
275
|
+
// Process line by line
|
|
276
|
+
const lines = buffer.split('\n');
|
|
277
|
+
buffer = lines.pop() || ''; // Keep incomplete line
|
|
278
|
+
for (const line of lines) {
|
|
279
|
+
const trimmedLine = line.trim();
|
|
280
|
+
// Skip empty lines and comment lines (OpenRouter specific)
|
|
281
|
+
if (!trimmedLine || trimmedLine.startsWith(':'))
|
|
282
|
+
continue;
|
|
283
|
+
if (!trimmedLine.startsWith('data:'))
|
|
284
|
+
continue;
|
|
285
|
+
const jsonStr = trimmedLine.slice(5).trim();
|
|
286
|
+
if (jsonStr === '[DONE]') {
|
|
287
|
+
return full;
|
|
288
|
+
}
|
|
289
|
+
try {
|
|
290
|
+
const json = JSON.parse(jsonStr);
|
|
291
|
+
const content = json.choices?.[0]?.delta?.content || '';
|
|
292
|
+
if (content) {
|
|
293
|
+
onPartial(content);
|
|
294
|
+
full += content;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
catch (e) {
|
|
298
|
+
// Skip invalid JSON (could be partial or malformed)
|
|
299
|
+
console.debug('Failed to parse SSE data:', jsonStr);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return full;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Parse streaming response with tool support
|
|
307
|
+
*/
|
|
308
|
+
async parseStream(res, onPartial) {
|
|
309
|
+
const reader = res.body.getReader();
|
|
310
|
+
const dec = new TextDecoder();
|
|
311
|
+
const textBlocks = [];
|
|
312
|
+
const toolCallsMap = new Map();
|
|
313
|
+
let buf = '';
|
|
314
|
+
while (true) {
|
|
315
|
+
const { done, value } = await reader.read();
|
|
316
|
+
if (done)
|
|
317
|
+
break;
|
|
318
|
+
buf += dec.decode(value, { stream: true });
|
|
319
|
+
// Process line by line
|
|
320
|
+
const lines = buf.split('\n');
|
|
321
|
+
buf = lines.pop() || ''; // Keep incomplete line
|
|
322
|
+
for (const line of lines) {
|
|
323
|
+
const trimmedLine = line.trim();
|
|
324
|
+
// Skip empty lines and OpenRouter comment lines
|
|
325
|
+
if (!trimmedLine || trimmedLine.startsWith(':'))
|
|
326
|
+
continue;
|
|
327
|
+
if (!trimmedLine.startsWith('data:'))
|
|
328
|
+
continue;
|
|
329
|
+
const payload = trimmedLine.slice(5).trim();
|
|
330
|
+
if (payload === '[DONE]') {
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
try {
|
|
334
|
+
const json = JSON.parse(payload);
|
|
335
|
+
const delta = json.choices?.[0]?.delta;
|
|
336
|
+
if (delta?.content) {
|
|
337
|
+
onPartial(delta.content);
|
|
338
|
+
streamTextAccumulator_1.StreamTextAccumulator.append(textBlocks, delta.content);
|
|
339
|
+
}
|
|
340
|
+
// Handle tool calls
|
|
341
|
+
if (delta?.tool_calls) {
|
|
342
|
+
delta.tool_calls.forEach((c) => {
|
|
343
|
+
const entry = toolCallsMap.get(c.index) ?? {
|
|
344
|
+
id: c.id,
|
|
345
|
+
name: c.function?.name,
|
|
346
|
+
args: '',
|
|
347
|
+
};
|
|
348
|
+
entry.args += c.function?.arguments || '';
|
|
349
|
+
toolCallsMap.set(c.index, entry);
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
catch (e) {
|
|
354
|
+
console.debug('Failed to parse SSE data:', payload);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
// Convert tool_calls to blocks
|
|
359
|
+
const toolBlocks = Array.from(toolCallsMap.entries())
|
|
360
|
+
.sort((a, b) => a[0] - b[0])
|
|
361
|
+
.map(([_, e]) => ({
|
|
362
|
+
type: 'tool_use',
|
|
363
|
+
id: e.id,
|
|
364
|
+
name: e.name,
|
|
365
|
+
input: JSON.parse(e.args || '{}'),
|
|
366
|
+
}));
|
|
367
|
+
const blocks = [...textBlocks, ...toolBlocks];
|
|
368
|
+
return {
|
|
369
|
+
blocks,
|
|
370
|
+
stop_reason: toolBlocks.length ? 'tool_use' : 'end',
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Parse non-streaming response
|
|
375
|
+
*/
|
|
376
|
+
parseOneShot(data) {
|
|
377
|
+
const choice = data.choices?.[0];
|
|
378
|
+
const blocks = [];
|
|
379
|
+
if (choice?.finish_reason === 'tool_calls' && choice?.message?.tool_calls) {
|
|
380
|
+
choice.message.tool_calls.forEach((c) => blocks.push({
|
|
381
|
+
type: 'tool_use',
|
|
382
|
+
id: c.id,
|
|
383
|
+
name: c.function?.name,
|
|
384
|
+
input: JSON.parse(c.function?.arguments || '{}'),
|
|
385
|
+
}));
|
|
386
|
+
}
|
|
387
|
+
else if (choice?.message?.content) {
|
|
388
|
+
blocks.push({ type: 'text', text: choice.message.content });
|
|
389
|
+
}
|
|
390
|
+
return {
|
|
391
|
+
blocks,
|
|
392
|
+
stop_reason: choice?.finish_reason === 'tool_calls' ? 'tool_use' : 'end',
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
exports.OpenRouterChatService = OpenRouterChatService;
|
|
397
|
+
//# sourceMappingURL=OpenRouterChatService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenRouterChatService.js","sourceRoot":"","sources":["../../../../../src/services/providers/openrouter/OpenRouterChatService.ts"],"names":[],"mappings":";;;AAOA,8DAMuC;AACvC,kDAGiC;AACjC,gFAA6E;AAC7E,gFAA6E;AAE7E;;;GAGG;AACH,MAAa,qBAAqB;IAkBhC;;;;;;;;;;;;;OAaG;IACH,YACE,MAAc,EACd,QAAgB,mCAAsB,EACtC,cAAsB,mCAAsB,EAC5C,KAAwB,EACxB,WAAmB,oCAAuB,EAC1C,cAAmC,EACnC,OAAgB,EAChB,MAAe,EACf,gBAAwD,EACxD,gBAA0B,EAC1B,kBAA2B;QA1C7B,oBAAoB;QACX,aAAQ,GA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AAE,CAAC,CAAC,EAAE;gBACR,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE,IAAI;gBACtB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,EAAE,SAAS,IAAI,IAAI,CAAC;aACjD,CAAC,CACH,CAAC;QACJ,CAAC;aAAM,IAAI,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;YACpC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QAC9D,CAAC;QAED,OAAO;YACL,MAAM;YACN,WAAW,EAAE,MAAM,EAAE,aAAa,KAAK,YAAY,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK;SACzE,CAAC;IACJ,CAAC;CACF;AA9gBD,sDA8gBC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ChatService } from '../../ChatService';
|
|
2
|
+
import { ChatServiceOptions, ChatServiceProvider } from '../ChatServiceProvider';
|
|
3
|
+
/**
|
|
4
|
+
* OpenRouter API provider implementation
|
|
5
|
+
* Provides access to multiple AI models through OpenRouter's unified API
|
|
6
|
+
*/
|
|
7
|
+
export declare class OpenRouterChatServiceProvider implements ChatServiceProvider {
|
|
8
|
+
/**
|
|
9
|
+
* Create a chat service instance
|
|
10
|
+
* @param options Service options
|
|
11
|
+
* @returns OpenRouterChatService instance
|
|
12
|
+
*/
|
|
13
|
+
createChatService(options: ChatServiceOptions): ChatService;
|
|
14
|
+
/**
|
|
15
|
+
* Get the provider name
|
|
16
|
+
* @returns Provider name ('openrouter')
|
|
17
|
+
*/
|
|
18
|
+
getProviderName(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Get the list of supported models
|
|
21
|
+
* Currently only supports gpt-oss-20b:free
|
|
22
|
+
* @returns Array of supported model names
|
|
23
|
+
*/
|
|
24
|
+
getSupportedModels(): string[];
|
|
25
|
+
/**
|
|
26
|
+
* Get the default model
|
|
27
|
+
* @returns Default model name (gpt-oss-20b:free)
|
|
28
|
+
*/
|
|
29
|
+
getDefaultModel(): string;
|
|
30
|
+
/**
|
|
31
|
+
* Check if this provider supports vision (image processing)
|
|
32
|
+
* @returns Vision support status (false - gpt-oss-20b does not support vision)
|
|
33
|
+
*/
|
|
34
|
+
supportsVision(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Check if a specific model supports vision capabilities
|
|
37
|
+
* @param model The model name to check
|
|
38
|
+
* @returns True if the model supports vision, false otherwise
|
|
39
|
+
*/
|
|
40
|
+
supportsVisionForModel(model: string): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Get list of free tier models
|
|
43
|
+
* @returns Array of free model names
|
|
44
|
+
*/
|
|
45
|
+
getFreeModels(): string[];
|
|
46
|
+
/**
|
|
47
|
+
* Check if a model is free tier
|
|
48
|
+
* @param model Model name to check
|
|
49
|
+
* @returns True if the model is free
|
|
50
|
+
*/
|
|
51
|
+
isModelFree(model: string): boolean;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=OpenRouterChatServiceProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenRouterChatServiceProvider.d.ts","sourceRoot":"","sources":["../../../../../src/services/providers/openrouter/OpenRouterChatServiceProvider.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAGhC;;;GAGG;AACH,qBAAa,6BAA8B,YAAW,mBAAmB;IACvE;;;;OAIG;IACH,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW;IAsC3D;;;OAGG;IACH,eAAe,IAAI,MAAM;IAIzB;;;;OAIG;IACH,kBAAkB,IAAI,MAAM,EAAE;IAO9B;;;OAGG;IACH,eAAe,IAAI,MAAM;IAIzB;;;OAGG;IACH,cAAc,IAAI,OAAO;IAIzB;;;;OAIG;IACH,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAI9C;;;OAGG;IACH,aAAa,IAAI,MAAM,EAAE;IAIzB;;;;OAIG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAGpC"}
|