bytex-sdk 2.0.0 → 5.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/index.js +88 -1
- package/package.json +4 -4
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: '2.1.0', checks: {}, advice: [] };
|
|
92
92
|
const { data: { session } } = await this.supabase.auth.getSession();
|
|
93
93
|
|
|
94
94
|
// 1. Connectivity Check
|
|
@@ -122,3 +122,90 @@ export class BytexCloud {
|
|
|
122
122
|
|
|
123
123
|
_requireKey() { if (!this.apiKey) throw new Error('API Key required!'); }
|
|
124
124
|
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* ByteX AI (BYOM) v1.0
|
|
128
|
+
* Bring Your Own Model — connect your own AI API keys (OpenAI, Claude, Gemini)
|
|
129
|
+
*
|
|
130
|
+
* Usage:
|
|
131
|
+
* const ai = new BytexAI({ openai: 'sk-...', claude: 'sk-ant-...', gemini: 'AIza...' });
|
|
132
|
+
* const reply = await ai.chat('openai', 'gpt-4o', [{ role: 'user', content: 'Hello!' }]);
|
|
133
|
+
*/
|
|
134
|
+
export class BytexAI {
|
|
135
|
+
constructor(keys = {}) {
|
|
136
|
+
this.keys = keys;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Universal chat method.
|
|
141
|
+
* @param {'openai'|'claude'|'gemini'} provider - The AI provider
|
|
142
|
+
* @param {string} model - The model name (e.g. 'gpt-4o', 'claude-3-5-sonnet-20241022', 'gemini-1.5-pro')
|
|
143
|
+
* @param {Array<{role: string, content: string}>} messages - Chat messages
|
|
144
|
+
* @param {object} options - Optional params (temperature, maxTokens, etc.)
|
|
145
|
+
* @returns {Promise<string>} - The AI reply text
|
|
146
|
+
*/
|
|
147
|
+
async chat(provider, model, messages, options = {}) {
|
|
148
|
+
switch (provider) {
|
|
149
|
+
case 'openai': return this._openai(model, messages, options);
|
|
150
|
+
case 'claude': return this._claude(model, messages, options);
|
|
151
|
+
case 'gemini': return this._gemini(model, messages, options);
|
|
152
|
+
default: throw new Error(`[BytexAI] Unknown provider: "${provider}". Use 'openai', 'claude', or 'gemini'.`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async _openai(model, messages, options) {
|
|
157
|
+
if (!this.keys.openai) throw new Error('[BytexAI] OpenAI API key is missing. Pass it via: new BytexAI({ openai: "sk-..." })');
|
|
158
|
+
const res = await fetch('https://api.openai.com/v1/chat/completions', {
|
|
159
|
+
method: 'POST',
|
|
160
|
+
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.keys.openai}` },
|
|
161
|
+
body: JSON.stringify({
|
|
162
|
+
model: model || 'gpt-4o-mini',
|
|
163
|
+
messages,
|
|
164
|
+
temperature: options.temperature ?? 0.7,
|
|
165
|
+
max_tokens: options.maxTokens ?? 1024,
|
|
166
|
+
})
|
|
167
|
+
});
|
|
168
|
+
if (!res.ok) throw new Error(`[BytexAI] OpenAI error: ${await res.text()}`);
|
|
169
|
+
const data = await res.json();
|
|
170
|
+
return data.choices[0].message.content;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async _claude(model, messages, options) {
|
|
174
|
+
if (!this.keys.claude) throw new Error('[BytexAI] Claude API key is missing. Pass it via: new BytexAI({ claude: "sk-ant-..." })');
|
|
175
|
+
const system = messages.find(m => m.role === 'system')?.content;
|
|
176
|
+
const chatMessages = messages.filter(m => m.role !== 'system');
|
|
177
|
+
const res = await fetch('https://api.anthropic.com/v1/messages', {
|
|
178
|
+
method: 'POST',
|
|
179
|
+
headers: {
|
|
180
|
+
'Content-Type': 'application/json',
|
|
181
|
+
'x-api-key': this.keys.claude,
|
|
182
|
+
'anthropic-version': '2023-06-01'
|
|
183
|
+
},
|
|
184
|
+
body: JSON.stringify({
|
|
185
|
+
model: model || 'claude-3-5-haiku-20241022',
|
|
186
|
+
max_tokens: options.maxTokens ?? 1024,
|
|
187
|
+
...(system && { system }),
|
|
188
|
+
messages: chatMessages
|
|
189
|
+
})
|
|
190
|
+
});
|
|
191
|
+
if (!res.ok) throw new Error(`[BytexAI] Claude error: ${await res.text()}`);
|
|
192
|
+
const data = await res.json();
|
|
193
|
+
return data.content[0].text;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async _gemini(model, messages, options) {
|
|
197
|
+
if (!this.keys.gemini) throw new Error('[BytexAI] Gemini API key is missing. Pass it via: new BytexAI({ gemini: "AIza..." })');
|
|
198
|
+
const contents = messages
|
|
199
|
+
.filter(m => m.role !== 'system')
|
|
200
|
+
.map(m => ({ role: m.role === 'assistant' ? 'model' : 'user', parts: [{ text: m.content }] }));
|
|
201
|
+
const endpoint = `https://generativelanguage.googleapis.com/v1beta/models/${model || 'gemini-1.5-flash'}:generateContent?key=${this.keys.gemini}`;
|
|
202
|
+
const res = await fetch(endpoint, {
|
|
203
|
+
method: 'POST',
|
|
204
|
+
headers: { 'Content-Type': 'application/json' },
|
|
205
|
+
body: JSON.stringify({ contents, generationConfig: { temperature: options.temperature ?? 0.7, maxOutputTokens: options.maxTokens ?? 1024 } })
|
|
206
|
+
});
|
|
207
|
+
if (!res.ok) throw new Error(`[BytexAI] Gemini error: ${await res.text()}`);
|
|
208
|
+
const data = await res.json();
|
|
209
|
+
return data.candidates[0].content.parts[0].text;
|
|
210
|
+
}
|
|
211
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bytex-sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "5.1.0",
|
|
4
|
+
"description": "Official ByteX Cloud SDK with AI (BYOM) support",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"@supabase/supabase-js": "^2.105.4",
|
|
12
12
|
"chalk": "^5.3.0"
|
|
13
13
|
},
|
|
14
|
-
"keywords": [],
|
|
15
|
-
"author": "",
|
|
14
|
+
"keywords": ["bytex", "cloud", "storage", "ai", "byom", "byoc"],
|
|
15
|
+
"author": "ByteX Team",
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"type": "module"
|
|
18
18
|
}
|