@ekodb/ekodb-client 0.13.0 → 0.14.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/README.md +70 -0
- package/dist/client.d.ts +142 -4
- package/dist/client.js +486 -7
- package/dist/client.test.js +810 -0
- package/dist/websocket.test.js +89 -0
- package/package.json +1 -1
- package/src/client.test.ts +1016 -0
- package/src/client.ts +823 -7
- package/src/websocket.test.ts +137 -0
package/src/websocket.test.ts
CHANGED
|
@@ -270,6 +270,43 @@ describe("WebSocketClient", () => {
|
|
|
270
270
|
client.close();
|
|
271
271
|
});
|
|
272
272
|
|
|
273
|
+
it("includes context_window in end event", async () => {
|
|
274
|
+
const client = new WebSocketClient(
|
|
275
|
+
`ws://localhost:${port}/api/ws`,
|
|
276
|
+
"test-token",
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
const streamPromise = client.chatSend("chat-cw", "test");
|
|
280
|
+
|
|
281
|
+
await new Promise((r) => wss.once("connection", r));
|
|
282
|
+
const ws = getLastConnection();
|
|
283
|
+
await waitForMessage(ws);
|
|
284
|
+
|
|
285
|
+
const stream = await streamPromise;
|
|
286
|
+
const events: any[] = [];
|
|
287
|
+
stream.on("event", (e) => events.push(e));
|
|
288
|
+
|
|
289
|
+
ws.send(
|
|
290
|
+
JSON.stringify({
|
|
291
|
+
type: "ChatStreamEnd",
|
|
292
|
+
payload: {
|
|
293
|
+
chat_id: "chat-cw",
|
|
294
|
+
message_id: "msg-cw",
|
|
295
|
+
execution_time_ms: 100,
|
|
296
|
+
context_window: 128000,
|
|
297
|
+
},
|
|
298
|
+
}),
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
await new Promise((r) => stream.on("close", r));
|
|
302
|
+
|
|
303
|
+
expect(events).toHaveLength(1);
|
|
304
|
+
expect(events[0].type).toBe("end");
|
|
305
|
+
expect(events[0].contextWindow).toBe(128000);
|
|
306
|
+
|
|
307
|
+
client.close();
|
|
308
|
+
});
|
|
309
|
+
|
|
273
310
|
it("handles chat stream error", async () => {
|
|
274
311
|
const client = new WebSocketClient(
|
|
275
312
|
`ws://localhost:${port}/api/ws`,
|
|
@@ -572,4 +609,104 @@ describe("WebSocketClient", () => {
|
|
|
572
609
|
expect(closed).toBe(true);
|
|
573
610
|
});
|
|
574
611
|
});
|
|
612
|
+
|
|
613
|
+
// --------------------------------------------------------------------------
|
|
614
|
+
// rawCompletion
|
|
615
|
+
// --------------------------------------------------------------------------
|
|
616
|
+
|
|
617
|
+
describe("rawCompletion", () => {
|
|
618
|
+
it("sends RawComplete request and returns content", async () => {
|
|
619
|
+
const client = new WebSocketClient(
|
|
620
|
+
`ws://localhost:${port}/api/ws`,
|
|
621
|
+
"test-token",
|
|
622
|
+
);
|
|
623
|
+
|
|
624
|
+
const resultPromise = client.rawCompletion({
|
|
625
|
+
system_prompt: "You are helpful.",
|
|
626
|
+
message: "Say hello.",
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
await new Promise((r) => wss.once("connection", r));
|
|
630
|
+
const ws = getLastConnection();
|
|
631
|
+
const msg = await waitForMessage(ws);
|
|
632
|
+
|
|
633
|
+
expect(msg.type).toBe("RawComplete");
|
|
634
|
+
expect(msg.payload.system_prompt).toBe("You are helpful.");
|
|
635
|
+
expect(msg.payload.message).toBe("Say hello.");
|
|
636
|
+
|
|
637
|
+
ws.send(
|
|
638
|
+
JSON.stringify({
|
|
639
|
+
type: "Success",
|
|
640
|
+
payload: {
|
|
641
|
+
data: { content: "Hello! How can I help?" },
|
|
642
|
+
},
|
|
643
|
+
}),
|
|
644
|
+
);
|
|
645
|
+
|
|
646
|
+
const result = await resultPromise;
|
|
647
|
+
expect(result.content).toBe("Hello! How can I help?");
|
|
648
|
+
|
|
649
|
+
client.close();
|
|
650
|
+
});
|
|
651
|
+
|
|
652
|
+
it("includes optional fields when provided", async () => {
|
|
653
|
+
const client = new WebSocketClient(
|
|
654
|
+
`ws://localhost:${port}/api/ws`,
|
|
655
|
+
"test-token",
|
|
656
|
+
);
|
|
657
|
+
|
|
658
|
+
const resultPromise = client.rawCompletion({
|
|
659
|
+
system_prompt: "System.",
|
|
660
|
+
message: "User.",
|
|
661
|
+
provider: "openai",
|
|
662
|
+
model: "gpt-4o-mini",
|
|
663
|
+
max_tokens: 512,
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
await new Promise((r) => wss.once("connection", r));
|
|
667
|
+
const ws = getLastConnection();
|
|
668
|
+
const msg = await waitForMessage(ws);
|
|
669
|
+
|
|
670
|
+
expect(msg.payload.provider).toBe("openai");
|
|
671
|
+
expect(msg.payload.model).toBe("gpt-4o-mini");
|
|
672
|
+
expect(msg.payload.max_tokens).toBe(512);
|
|
673
|
+
|
|
674
|
+
ws.send(
|
|
675
|
+
JSON.stringify({
|
|
676
|
+
type: "Success",
|
|
677
|
+
payload: { data: { content: "Done." } },
|
|
678
|
+
}),
|
|
679
|
+
);
|
|
680
|
+
|
|
681
|
+
await resultPromise;
|
|
682
|
+
client.close();
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
it("rejects on error response", async () => {
|
|
686
|
+
const client = new WebSocketClient(
|
|
687
|
+
`ws://localhost:${port}/api/ws`,
|
|
688
|
+
"test-token",
|
|
689
|
+
);
|
|
690
|
+
|
|
691
|
+
const resultPromise = client.rawCompletion({
|
|
692
|
+
system_prompt: "System.",
|
|
693
|
+
message: "User.",
|
|
694
|
+
});
|
|
695
|
+
|
|
696
|
+
await new Promise((r) => wss.once("connection", r));
|
|
697
|
+
const ws = getLastConnection();
|
|
698
|
+
await waitForMessage(ws);
|
|
699
|
+
|
|
700
|
+
ws.send(
|
|
701
|
+
JSON.stringify({
|
|
702
|
+
type: "Error",
|
|
703
|
+
message: "Model not found",
|
|
704
|
+
}),
|
|
705
|
+
);
|
|
706
|
+
|
|
707
|
+
await expect(resultPromise).rejects.toThrow("Model not found");
|
|
708
|
+
|
|
709
|
+
client.close();
|
|
710
|
+
});
|
|
711
|
+
});
|
|
575
712
|
});
|