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.
Files changed (2) hide show
  1. package/index.js +30 -14
  2. 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.1.0', checks: {}, advice: [] };
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.0
128
- * Bring Your Own Model — connect your own AI API keys (OpenAI, Claude, Gemini)
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({ openai: 'sk-...', claude: 'sk-ant-...', gemini: 'AIza...' });
132
- * const reply = await ai.chat('openai', 'gpt-4o', [{ role: 'user', content: 'Hello!' }]);
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 (e.g. 'gpt-4o', 'claude-3-5-sonnet-20241022', 'gemini-1.5-pro')
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 (temperature, maxTokens, etc.)
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
- default: throw new Error(`[BytexAI] Unknown provider: "${provider}". Use 'openai', 'claude', or 'gemini'.`);
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
- 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', {
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 ${this.keys.openai}` },
176
+ headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${key}` },
161
177
  body: JSON.stringify({
162
- model: model || 'gpt-4o-mini',
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] OpenAI error: ${await res.text()}`);
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bytex-sdk",
3
- "version": "5.1.0",
3
+ "version": "5.2.0",
4
4
  "description": "Official ByteX Cloud SDK with AI (BYOM) support",
5
5
  "main": "index.js",
6
6
  "scripts": {