@ekodb/ekodb-client 0.13.0 → 0.15.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.
@@ -190,6 +190,30 @@ function waitForMessage(ws) {
190
190
  (0, vitest_1.expect)(events[2].executionTimeMs).toBe(150);
191
191
  client.close();
192
192
  });
193
+ (0, vitest_1.it)("includes context_window in end event", async () => {
194
+ const client = new client_1.WebSocketClient(`ws://localhost:${port}/api/ws`, "test-token");
195
+ const streamPromise = client.chatSend("chat-cw", "test");
196
+ await new Promise((r) => wss.once("connection", r));
197
+ const ws = getLastConnection();
198
+ await waitForMessage(ws);
199
+ const stream = await streamPromise;
200
+ const events = [];
201
+ stream.on("event", (e) => events.push(e));
202
+ ws.send(JSON.stringify({
203
+ type: "ChatStreamEnd",
204
+ payload: {
205
+ chat_id: "chat-cw",
206
+ message_id: "msg-cw",
207
+ execution_time_ms: 100,
208
+ context_window: 128000,
209
+ },
210
+ }));
211
+ await new Promise((r) => stream.on("close", r));
212
+ (0, vitest_1.expect)(events).toHaveLength(1);
213
+ (0, vitest_1.expect)(events[0].type).toBe("end");
214
+ (0, vitest_1.expect)(events[0].contextWindow).toBe(128000);
215
+ client.close();
216
+ });
193
217
  (0, vitest_1.it)("handles chat stream error", async () => {
194
218
  const client = new client_1.WebSocketClient(`ws://localhost:${port}/api/ws`, "test-token");
195
219
  const streamPromise = client.chatSend("chat-2", "test");
@@ -404,4 +428,69 @@ function waitForMessage(ws) {
404
428
  (0, vitest_1.expect)(closed).toBe(true);
405
429
  });
406
430
  });
431
+ // --------------------------------------------------------------------------
432
+ // rawCompletion
433
+ // --------------------------------------------------------------------------
434
+ (0, vitest_1.describe)("rawCompletion", () => {
435
+ (0, vitest_1.it)("sends RawComplete request and returns content", async () => {
436
+ const client = new client_1.WebSocketClient(`ws://localhost:${port}/api/ws`, "test-token");
437
+ const resultPromise = client.rawCompletion({
438
+ system_prompt: "You are helpful.",
439
+ message: "Say hello.",
440
+ });
441
+ await new Promise((r) => wss.once("connection", r));
442
+ const ws = getLastConnection();
443
+ const msg = await waitForMessage(ws);
444
+ (0, vitest_1.expect)(msg.type).toBe("RawComplete");
445
+ (0, vitest_1.expect)(msg.payload.system_prompt).toBe("You are helpful.");
446
+ (0, vitest_1.expect)(msg.payload.message).toBe("Say hello.");
447
+ ws.send(JSON.stringify({
448
+ type: "Success",
449
+ payload: {
450
+ data: { content: "Hello! How can I help?" },
451
+ },
452
+ }));
453
+ const result = await resultPromise;
454
+ (0, vitest_1.expect)(result.content).toBe("Hello! How can I help?");
455
+ client.close();
456
+ });
457
+ (0, vitest_1.it)("includes optional fields when provided", async () => {
458
+ const client = new client_1.WebSocketClient(`ws://localhost:${port}/api/ws`, "test-token");
459
+ const resultPromise = client.rawCompletion({
460
+ system_prompt: "System.",
461
+ message: "User.",
462
+ provider: "openai",
463
+ model: "gpt-4o-mini",
464
+ max_tokens: 512,
465
+ });
466
+ await new Promise((r) => wss.once("connection", r));
467
+ const ws = getLastConnection();
468
+ const msg = await waitForMessage(ws);
469
+ (0, vitest_1.expect)(msg.payload.provider).toBe("openai");
470
+ (0, vitest_1.expect)(msg.payload.model).toBe("gpt-4o-mini");
471
+ (0, vitest_1.expect)(msg.payload.max_tokens).toBe(512);
472
+ ws.send(JSON.stringify({
473
+ type: "Success",
474
+ payload: { data: { content: "Done." } },
475
+ }));
476
+ await resultPromise;
477
+ client.close();
478
+ });
479
+ (0, vitest_1.it)("rejects on error response", async () => {
480
+ const client = new client_1.WebSocketClient(`ws://localhost:${port}/api/ws`, "test-token");
481
+ const resultPromise = client.rawCompletion({
482
+ system_prompt: "System.",
483
+ message: "User.",
484
+ });
485
+ await new Promise((r) => wss.once("connection", r));
486
+ const ws = getLastConnection();
487
+ await waitForMessage(ws);
488
+ ws.send(JSON.stringify({
489
+ type: "Error",
490
+ message: "Model not found",
491
+ }));
492
+ await (0, vitest_1.expect)(resultPromise).rejects.toThrow("Model not found");
493
+ client.close();
494
+ });
495
+ });
407
496
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ekodb/ekodb-client",
3
- "version": "0.13.0",
3
+ "version": "0.15.0",
4
4
  "description": "Official TypeScript/JavaScript client for ekoDB",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",