bytex-sdk 5.1.0 → 5.2.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/index.js +30 -14
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -88,7 +88,7 @@ export class BytexCloud {
|
|
|
88
88
|
* ByteX X-RAY v2.5 (Self-Healing Diagnostic)
|
|
89
89
|
*/
|
|
90
90
|
async xray() {
|
|
91
|
-
const report = { timestamp: new Date().toISOString(), sdk_version: '2.
|
|
91
|
+
const report = { timestamp: new Date().toISOString(), sdk_version: '5.2.0', checks: {}, advice: [] };
|
|
92
92
|
const { data: { session } } = await this.supabase.auth.getSession();
|
|
93
93
|
|
|
94
94
|
// 1. Connectivity Check
|
|
@@ -124,12 +124,14 @@ export class BytexCloud {
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
/**
|
|
127
|
-
* ByteX AI (BYOM) v1.
|
|
128
|
-
* Bring Your Own Model — connect your own AI API keys
|
|
127
|
+
* ByteX AI (BYOM) v1.1
|
|
128
|
+
* Bring Your Own Model — connect your own AI API keys
|
|
129
129
|
*
|
|
130
130
|
* Usage:
|
|
131
|
-
* const ai = new BytexAI({
|
|
132
|
-
*
|
|
131
|
+
* const ai = new BytexAI({
|
|
132
|
+
* openai: 'sk-...',
|
|
133
|
+
* custom: { key: '...', endpoint: 'https://api.groq.com/openai/v1' }
|
|
134
|
+
* });
|
|
133
135
|
*/
|
|
134
136
|
export class BytexAI {
|
|
135
137
|
constructor(keys = {}) {
|
|
@@ -138,10 +140,10 @@ export class BytexAI {
|
|
|
138
140
|
|
|
139
141
|
/**
|
|
140
142
|
* Universal chat method.
|
|
141
|
-
* @param {'openai'|'claude'|'gemini'} provider - The AI provider
|
|
142
|
-
* @param {string} model - The model name
|
|
143
|
+
* @param {'openai'|'claude'|'gemini'|'custom'} provider - The AI provider
|
|
144
|
+
* @param {string} model - The model name
|
|
143
145
|
* @param {Array<{role: string, content: string}>} messages - Chat messages
|
|
144
|
-
* @param {object} options - Optional params
|
|
146
|
+
* @param {object} options - Optional params
|
|
145
147
|
* @returns {Promise<string>} - The AI reply text
|
|
146
148
|
*/
|
|
147
149
|
async chat(provider, model, messages, options = {}) {
|
|
@@ -149,23 +151,37 @@ export class BytexAI {
|
|
|
149
151
|
case 'openai': return this._openai(model, messages, options);
|
|
150
152
|
case 'claude': return this._claude(model, messages, options);
|
|
151
153
|
case 'gemini': return this._gemini(model, messages, options);
|
|
152
|
-
|
|
154
|
+
case 'custom': return this._custom(model, messages, options);
|
|
155
|
+
default: throw new Error(`[BytexAI] Unknown provider: "${provider}". Use 'openai', 'claude', 'gemini', or 'custom'.`);
|
|
153
156
|
}
|
|
154
157
|
}
|
|
155
158
|
|
|
156
159
|
async _openai(model, messages, options) {
|
|
157
|
-
|
|
158
|
-
|
|
160
|
+
return this._openaiCompatible('https://api.openai.com/v1', this.keys.openai, model || 'gpt-4o-mini', messages, options);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async _custom(model, messages, options) {
|
|
164
|
+
const config = this.keys.custom || {};
|
|
165
|
+
if (!config.key || !config.endpoint) {
|
|
166
|
+
throw new Error('[BytexAI] Custom provider requires both "key" and "endpoint" (OpenAI-compatible).');
|
|
167
|
+
}
|
|
168
|
+
return this._openaiCompatible(config.endpoint, config.key, model, messages, options);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async _openaiCompatible(baseURL, key, model, messages, options) {
|
|
172
|
+
if (!key) throw new Error(`[BytexAI] API key for ${baseURL} is missing.`);
|
|
173
|
+
const url = baseURL.endsWith('/') ? `${baseURL}chat/completions` : `${baseURL}/chat/completions`;
|
|
174
|
+
const res = await fetch(url, {
|
|
159
175
|
method: 'POST',
|
|
160
|
-
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${
|
|
176
|
+
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${key}` },
|
|
161
177
|
body: JSON.stringify({
|
|
162
|
-
model: model
|
|
178
|
+
model: model,
|
|
163
179
|
messages,
|
|
164
180
|
temperature: options.temperature ?? 0.7,
|
|
165
181
|
max_tokens: options.maxTokens ?? 1024,
|
|
166
182
|
})
|
|
167
183
|
});
|
|
168
|
-
if (!res.ok) throw new Error(`[BytexAI]
|
|
184
|
+
if (!res.ok) throw new Error(`[BytexAI] API error (${baseURL}): ${await res.text()}`);
|
|
169
185
|
const data = await res.json();
|
|
170
186
|
return data.choices[0].message.content;
|
|
171
187
|
}
|