@burtson-labs/bandit-engine 2.0.35 → 2.0.37
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.md +6 -5
- package/dist/{aiProviderStore-3YS2BZU3.mjs → aiProviderStore-UJRDUYOF.mjs} +2 -2
- package/dist/{chat-2LYIZNWZ.mjs → chat-SZK3EBDO.mjs} +5 -5
- package/dist/chat-provider.js +227 -11
- package/dist/chat-provider.js.map +1 -1
- package/dist/chat-provider.mjs +4 -4
- package/dist/{chunk-6PQRG6W4.mjs → chunk-2ZZA2IFL.mjs} +3 -3
- package/dist/{chunk-GBANNFRD.mjs → chunk-ED5NNDKO.mjs} +3 -3
- package/dist/{chunk-XD5VJCFN.mjs → chunk-FJO5ZWYU.mjs} +3 -3
- package/dist/{chunk-XXMCI2WK.mjs → chunk-G4OXOTNJ.mjs} +41 -8
- package/dist/{chunk-XXMCI2WK.mjs.map → chunk-G4OXOTNJ.mjs.map} +1 -1
- package/dist/{chunk-LG2JCTOE.mjs → chunk-PLNFTIGX.mjs} +4 -4
- package/dist/{chunk-7RLN6ZGT.mjs → chunk-S635Q6OQ.mjs} +3 -3
- package/dist/{chunk-IGD4KGB5.mjs → chunk-ZAVV2AT5.mjs} +4 -4
- package/dist/{chunk-IHJPVIGB.mjs → chunk-ZNNOTDRD.mjs} +208 -1
- package/dist/chunk-ZNNOTDRD.mjs.map +1 -0
- package/dist/cli/cli.js +1104 -68
- package/dist/cli/cli.js.map +1 -1
- package/dist/{gateway-BiHRHJMM.d.ts → gateway-Ckf_KusF.d.mts} +4 -4
- package/dist/{gateway-BiHRHJMM.d.mts → gateway-Ckf_KusF.d.ts} +4 -4
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +318 -69
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -8
- package/dist/management/management.js +316 -67
- package/dist/management/management.js.map +1 -1
- package/dist/management/management.mjs +6 -6
- package/dist/modals/chat-modal/chat-modal.js +236 -20
- package/dist/modals/chat-modal/chat-modal.js.map +1 -1
- package/dist/modals/chat-modal/chat-modal.mjs +4 -4
- package/dist/public-types.d.mts +1 -1
- package/dist/public-types.d.ts +1 -1
- package/package.json +1 -1
- package/dist/chunk-IHJPVIGB.mjs.map +0 -1
- /package/dist/{aiProviderStore-3YS2BZU3.mjs.map → aiProviderStore-UJRDUYOF.mjs.map} +0 -0
- /package/dist/{chat-2LYIZNWZ.mjs.map → chat-SZK3EBDO.mjs.map} +0 -0
- /package/dist/{chunk-6PQRG6W4.mjs.map → chunk-2ZZA2IFL.mjs.map} +0 -0
- /package/dist/{chunk-GBANNFRD.mjs.map → chunk-ED5NNDKO.mjs.map} +0 -0
- /package/dist/{chunk-XD5VJCFN.mjs.map → chunk-FJO5ZWYU.mjs.map} +0 -0
- /package/dist/{chunk-LG2JCTOE.mjs.map → chunk-PLNFTIGX.mjs.map} +0 -0
- /package/dist/{chunk-7RLN6ZGT.mjs.map → chunk-S635Q6OQ.mjs.map} +0 -0
- /package/dist/{chunk-IGD4KGB5.mjs.map → chunk-ZAVV2AT5.mjs.map} +0 -0
|
@@ -8,14 +8,14 @@ import {
|
|
|
8
8
|
useNotificationService,
|
|
9
9
|
useTTS,
|
|
10
10
|
useVoiceStore
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-ED5NNDKO.mjs";
|
|
12
12
|
import {
|
|
13
13
|
brandingService_default,
|
|
14
14
|
toTitleCase,
|
|
15
15
|
useAIQueryStore,
|
|
16
16
|
useConversationStore,
|
|
17
17
|
useMemoryStore
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-FJO5ZWYU.mjs";
|
|
19
19
|
import {
|
|
20
20
|
indexedDBService_default,
|
|
21
21
|
useModelStore,
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
} from "./chunk-XUBYA5I7.mjs";
|
|
25
25
|
import {
|
|
26
26
|
useAIProviderStore
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-ZNNOTDRD.mjs";
|
|
28
28
|
import {
|
|
29
29
|
debugLogger
|
|
30
30
|
} from "./chunk-KCI46M23.mjs";
|
|
@@ -2807,4 +2807,4 @@ export {
|
|
|
2807
2807
|
MAX_WINDOWED_HEIGHT,
|
|
2808
2808
|
chat_modal_default
|
|
2809
2809
|
};
|
|
2810
|
-
//# sourceMappingURL=chunk-
|
|
2810
|
+
//# sourceMappingURL=chunk-PLNFTIGX.mjs.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
authenticationService
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-FJO5ZWYU.mjs";
|
|
4
4
|
import {
|
|
5
5
|
indexedDBService_default,
|
|
6
6
|
usePackageSettingsStore
|
|
7
7
|
} from "./chunk-XUBYA5I7.mjs";
|
|
8
8
|
import {
|
|
9
9
|
useAIProviderStore
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-ZNNOTDRD.mjs";
|
|
11
11
|
import {
|
|
12
12
|
debugLogger
|
|
13
13
|
} from "./chunk-KCI46M23.mjs";
|
|
@@ -261,4 +261,4 @@ var aiProviderInitService = AIProviderInitService.getInstance();
|
|
|
261
261
|
export {
|
|
262
262
|
aiProviderInitService
|
|
263
263
|
};
|
|
264
|
-
//# sourceMappingURL=chunk-
|
|
264
|
+
//# sourceMappingURL=chunk-S635Q6OQ.mjs.map
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
useNotificationService,
|
|
20
20
|
useTTS,
|
|
21
21
|
useVoiceStore
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-ED5NNDKO.mjs";
|
|
23
23
|
import {
|
|
24
24
|
authenticationService,
|
|
25
25
|
brandingService_default,
|
|
@@ -43,7 +43,7 @@ import {
|
|
|
43
43
|
useMemoryStore,
|
|
44
44
|
useProjectStore,
|
|
45
45
|
useVectorStore
|
|
46
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-FJO5ZWYU.mjs";
|
|
47
47
|
import {
|
|
48
48
|
indexedDBService_default,
|
|
49
49
|
useModelStore,
|
|
@@ -52,7 +52,7 @@ import {
|
|
|
52
52
|
} from "./chunk-XUBYA5I7.mjs";
|
|
53
53
|
import {
|
|
54
54
|
useAIProviderStore
|
|
55
|
-
} from "./chunk-
|
|
55
|
+
} from "./chunk-ZNNOTDRD.mjs";
|
|
56
56
|
import {
|
|
57
57
|
debugLogger
|
|
58
58
|
} from "./chunk-KCI46M23.mjs";
|
|
@@ -9507,4 +9507,4 @@ var chat_default = Chat;
|
|
|
9507
9507
|
export {
|
|
9508
9508
|
chat_default
|
|
9509
9509
|
};
|
|
9510
|
-
//# sourceMappingURL=chunk-
|
|
9510
|
+
//# sourceMappingURL=chunk-ZAVV2AT5.mjs.map
|
|
@@ -2249,6 +2249,208 @@ var PlaygroundProvider = class {
|
|
|
2249
2249
|
}
|
|
2250
2250
|
};
|
|
2251
2251
|
|
|
2252
|
+
// src/services/ai-provider/providers/xai.provider.ts
|
|
2253
|
+
import { Observable as Observable9, from as from6, switchMap as switchMap5, map as map12, throwError as throwError5 } from "rxjs";
|
|
2254
|
+
var XAIProvider = class {
|
|
2255
|
+
config;
|
|
2256
|
+
baseUrl;
|
|
2257
|
+
constructor(config) {
|
|
2258
|
+
this.config = config;
|
|
2259
|
+
this.baseUrl = config.baseUrl || "https://api.x.ai/v1";
|
|
2260
|
+
}
|
|
2261
|
+
chat(request) {
|
|
2262
|
+
const url = `${this.baseUrl}/chat/completions`;
|
|
2263
|
+
const payload = {
|
|
2264
|
+
model: request.model,
|
|
2265
|
+
messages: request.messages,
|
|
2266
|
+
stream: Boolean(request.stream),
|
|
2267
|
+
temperature: request.temperature,
|
|
2268
|
+
max_tokens: request.maxTokens
|
|
2269
|
+
};
|
|
2270
|
+
if (request.stream) {
|
|
2271
|
+
return this.streamChatRequest(url, payload);
|
|
2272
|
+
} else {
|
|
2273
|
+
return this.nonStreamChatRequest(url, payload);
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2276
|
+
generate(request) {
|
|
2277
|
+
const chatRequest = {
|
|
2278
|
+
model: request.model,
|
|
2279
|
+
messages: [{ role: "user", content: request.prompt }],
|
|
2280
|
+
stream: request.stream,
|
|
2281
|
+
options: request.options
|
|
2282
|
+
};
|
|
2283
|
+
return this.chat(chatRequest).pipe(
|
|
2284
|
+
map12((response) => ({
|
|
2285
|
+
response: response.message.content,
|
|
2286
|
+
done: response.done
|
|
2287
|
+
}))
|
|
2288
|
+
);
|
|
2289
|
+
}
|
|
2290
|
+
listModels() {
|
|
2291
|
+
const url = `${this.baseUrl}/models`;
|
|
2292
|
+
return from6(fetch(url, {
|
|
2293
|
+
headers: this.getHeaders()
|
|
2294
|
+
})).pipe(
|
|
2295
|
+
switchMap5((response) => {
|
|
2296
|
+
if (!response.ok) {
|
|
2297
|
+
return throwError5(() => new Error(`Failed to list models: ${response.status}`));
|
|
2298
|
+
}
|
|
2299
|
+
return from6(response.json());
|
|
2300
|
+
}),
|
|
2301
|
+
map12(
|
|
2302
|
+
(data) => data.data.map((model) => ({
|
|
2303
|
+
name: model.id,
|
|
2304
|
+
details: {
|
|
2305
|
+
format: "xai",
|
|
2306
|
+
family: model.object
|
|
2307
|
+
}
|
|
2308
|
+
}))
|
|
2309
|
+
)
|
|
2310
|
+
);
|
|
2311
|
+
}
|
|
2312
|
+
async validateServiceAvailability(args) {
|
|
2313
|
+
try {
|
|
2314
|
+
const controller = new AbortController();
|
|
2315
|
+
const timeoutId = setTimeout(() => controller.abort(), args.timeoutMs);
|
|
2316
|
+
const response = await fetch(`${this.baseUrl}/models`, {
|
|
2317
|
+
headers: this.getHeaders(),
|
|
2318
|
+
signal: controller.signal
|
|
2319
|
+
});
|
|
2320
|
+
clearTimeout(timeoutId);
|
|
2321
|
+
return {
|
|
2322
|
+
url: this.baseUrl,
|
|
2323
|
+
isAvailable: response.ok
|
|
2324
|
+
};
|
|
2325
|
+
} catch (error) {
|
|
2326
|
+
if (args.fallbackUrl) {
|
|
2327
|
+
try {
|
|
2328
|
+
const controller = new AbortController();
|
|
2329
|
+
const timeoutId = setTimeout(() => controller.abort(), args.timeoutMs);
|
|
2330
|
+
const response = await fetch(`${args.fallbackUrl}/models`, {
|
|
2331
|
+
headers: this.getHeaders(),
|
|
2332
|
+
signal: controller.signal
|
|
2333
|
+
});
|
|
2334
|
+
clearTimeout(timeoutId);
|
|
2335
|
+
if (response.ok) {
|
|
2336
|
+
this.baseUrl = args.fallbackUrl;
|
|
2337
|
+
return {
|
|
2338
|
+
url: args.fallbackUrl,
|
|
2339
|
+
isAvailable: true
|
|
2340
|
+
};
|
|
2341
|
+
}
|
|
2342
|
+
} catch (fallbackError) {
|
|
2343
|
+
debugLogger.warn("xAI fallback validation failed", { error: fallbackError });
|
|
2344
|
+
}
|
|
2345
|
+
}
|
|
2346
|
+
return {
|
|
2347
|
+
url: this.baseUrl,
|
|
2348
|
+
isAvailable: false
|
|
2349
|
+
};
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
2352
|
+
getProviderType() {
|
|
2353
|
+
return "xai" /* XAI */;
|
|
2354
|
+
}
|
|
2355
|
+
getConfig() {
|
|
2356
|
+
return this.config;
|
|
2357
|
+
}
|
|
2358
|
+
streamChatRequest(url, payload) {
|
|
2359
|
+
return new Observable9((observer) => {
|
|
2360
|
+
const task = fetch(url, {
|
|
2361
|
+
method: "POST",
|
|
2362
|
+
headers: {
|
|
2363
|
+
...this.getHeaders(),
|
|
2364
|
+
"Content-Type": "application/json"
|
|
2365
|
+
},
|
|
2366
|
+
body: JSON.stringify(payload)
|
|
2367
|
+
});
|
|
2368
|
+
task.then((response) => {
|
|
2369
|
+
if (!response.ok) {
|
|
2370
|
+
observer.error(new Error(`xAI request failed: ${response.status}`));
|
|
2371
|
+
return;
|
|
2372
|
+
}
|
|
2373
|
+
const reader = response.body?.getReader();
|
|
2374
|
+
const decoder = new TextDecoder();
|
|
2375
|
+
let buffer = "";
|
|
2376
|
+
const read = () => {
|
|
2377
|
+
reader?.read().then(({ done, value }) => {
|
|
2378
|
+
if (done) {
|
|
2379
|
+
observer.next({
|
|
2380
|
+
message: { content: "", role: "assistant" },
|
|
2381
|
+
done: true
|
|
2382
|
+
});
|
|
2383
|
+
observer.complete();
|
|
2384
|
+
return;
|
|
2385
|
+
}
|
|
2386
|
+
buffer += decoder.decode(value, { stream: true });
|
|
2387
|
+
const lines = buffer.split("\n");
|
|
2388
|
+
buffer = lines.pop() ?? "";
|
|
2389
|
+
for (const line of lines) {
|
|
2390
|
+
if (line.trim() && line.startsWith("data: ")) {
|
|
2391
|
+
const data = line.slice(6).trim();
|
|
2392
|
+
if (data === "[DONE]") {
|
|
2393
|
+
observer.next({
|
|
2394
|
+
message: { content: "", role: "assistant" },
|
|
2395
|
+
done: true
|
|
2396
|
+
});
|
|
2397
|
+
observer.complete();
|
|
2398
|
+
return;
|
|
2399
|
+
}
|
|
2400
|
+
try {
|
|
2401
|
+
const parsed = JSON.parse(data);
|
|
2402
|
+
const content = parsed.choices?.[0]?.delta?.content ?? "";
|
|
2403
|
+
if (content) {
|
|
2404
|
+
observer.next({
|
|
2405
|
+
message: { content, role: "assistant" },
|
|
2406
|
+
done: false
|
|
2407
|
+
});
|
|
2408
|
+
}
|
|
2409
|
+
} catch (err) {
|
|
2410
|
+
debugLogger.error("Error parsing xAI stream data:", { data, error: err });
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
read();
|
|
2415
|
+
}).catch((err) => observer.error(err));
|
|
2416
|
+
};
|
|
2417
|
+
read();
|
|
2418
|
+
}).catch((err) => observer.error(err));
|
|
2419
|
+
});
|
|
2420
|
+
}
|
|
2421
|
+
nonStreamChatRequest(url, payload) {
|
|
2422
|
+
return from6(fetch(url, {
|
|
2423
|
+
method: "POST",
|
|
2424
|
+
headers: {
|
|
2425
|
+
...this.getHeaders(),
|
|
2426
|
+
"Content-Type": "application/json"
|
|
2427
|
+
},
|
|
2428
|
+
body: JSON.stringify(payload)
|
|
2429
|
+
})).pipe(
|
|
2430
|
+
switchMap5((response) => {
|
|
2431
|
+
if (!response.ok) {
|
|
2432
|
+
return throwError5(() => new Error(`xAI request failed: ${response.status}`));
|
|
2433
|
+
}
|
|
2434
|
+
return from6(response.json());
|
|
2435
|
+
}),
|
|
2436
|
+
map12((data) => ({
|
|
2437
|
+
message: {
|
|
2438
|
+
content: data.choices?.[0]?.message?.content ?? "",
|
|
2439
|
+
role: "assistant"
|
|
2440
|
+
},
|
|
2441
|
+
done: true
|
|
2442
|
+
}))
|
|
2443
|
+
);
|
|
2444
|
+
}
|
|
2445
|
+
getHeaders() {
|
|
2446
|
+
const headers = {};
|
|
2447
|
+
if (this.config.apiKey) {
|
|
2448
|
+
headers["Authorization"] = `Bearer ${this.config.apiKey}`;
|
|
2449
|
+
}
|
|
2450
|
+
return headers;
|
|
2451
|
+
}
|
|
2452
|
+
};
|
|
2453
|
+
|
|
2252
2454
|
// src/services/ai-provider/ai-provider.factory.ts
|
|
2253
2455
|
var AIProviderFactory = class {
|
|
2254
2456
|
static createProvider(config) {
|
|
@@ -2261,6 +2463,8 @@ var AIProviderFactory = class {
|
|
|
2261
2463
|
return new AzureOpenAIProvider(config);
|
|
2262
2464
|
case "anthropic" /* ANTHROPIC */:
|
|
2263
2465
|
return new AnthropicProvider(config);
|
|
2466
|
+
case "xai" /* XAI */:
|
|
2467
|
+
return new XAIProvider(config);
|
|
2264
2468
|
case "gateway" /* GATEWAY */:
|
|
2265
2469
|
return new GatewayProvider(config);
|
|
2266
2470
|
case "playground" /* PLAYGROUND */:
|
|
@@ -2275,6 +2479,7 @@ var AIProviderFactory = class {
|
|
|
2275
2479
|
"openai" /* OPENAI */,
|
|
2276
2480
|
"azure-openai" /* AZURE_OPENAI */,
|
|
2277
2481
|
"anthropic" /* ANTHROPIC */,
|
|
2482
|
+
"xai" /* XAI */,
|
|
2278
2483
|
"gateway" /* GATEWAY */,
|
|
2279
2484
|
"playground" /* PLAYGROUND */
|
|
2280
2485
|
];
|
|
@@ -2290,6 +2495,8 @@ var AIProviderFactory = class {
|
|
|
2290
2495
|
return !!(config.baseUrl && config.apiKey && config.apiVersion && config.deploymentName);
|
|
2291
2496
|
case "anthropic" /* ANTHROPIC */:
|
|
2292
2497
|
return !!config.apiKey;
|
|
2498
|
+
case "xai" /* XAI */:
|
|
2499
|
+
return !!config.apiKey;
|
|
2293
2500
|
case "gateway" /* GATEWAY */:
|
|
2294
2501
|
return !!(config.gatewayUrl && config.provider);
|
|
2295
2502
|
case "playground" /* PLAYGROUND */:
|
|
@@ -2331,4 +2538,4 @@ export {
|
|
|
2331
2538
|
AIProviderFactory,
|
|
2332
2539
|
useAIProviderStore
|
|
2333
2540
|
};
|
|
2334
|
-
//# sourceMappingURL=chunk-
|
|
2541
|
+
//# sourceMappingURL=chunk-ZNNOTDRD.mjs.map
|