@ekodb/ekodb-client 0.18.2 → 0.19.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/dist/client.d.ts +27 -0
- package/dist/client.js +17 -0
- package/dist/client.test.js +35 -0
- package/dist/index.d.ts +1 -1
- package/package.json +2 -2
- package/src/client.test.ts +45 -0
- package/src/client.ts +47 -0
- package/src/index.ts +2 -0
package/dist/client.d.ts
CHANGED
|
@@ -258,6 +258,22 @@ export interface ChatModels {
|
|
|
258
258
|
anthropic: string[];
|
|
259
259
|
perplexity: string[];
|
|
260
260
|
}
|
|
261
|
+
/**
|
|
262
|
+
* Request to compact a chat session's history on demand.
|
|
263
|
+
*/
|
|
264
|
+
export interface CompactChatRequest {
|
|
265
|
+
keep_recent?: number;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Result of an on-demand chat history compaction.
|
|
269
|
+
*/
|
|
270
|
+
export interface CompactChatResponse {
|
|
271
|
+
folded: number;
|
|
272
|
+
kept_recent: number;
|
|
273
|
+
summary_chars: number;
|
|
274
|
+
summary_message_id: string | null;
|
|
275
|
+
already_compact: boolean;
|
|
276
|
+
}
|
|
261
277
|
/**
|
|
262
278
|
* Request to generate embeddings
|
|
263
279
|
*/
|
|
@@ -866,6 +882,17 @@ export declare class EkoDBClient {
|
|
|
866
882
|
* Toggle the "forgotten" status of a message
|
|
867
883
|
*/
|
|
868
884
|
toggleForgottenMessage(sessionId: string, messageId: string, forgotten: boolean): Promise<void>;
|
|
885
|
+
/**
|
|
886
|
+
* Compact a chat session's history on demand.
|
|
887
|
+
*
|
|
888
|
+
* Folds older messages into a summary while preserving the most recent
|
|
889
|
+
* messages verbatim, reducing context size for long-running sessions.
|
|
890
|
+
*
|
|
891
|
+
* @param chatId - Chat session ID
|
|
892
|
+
* @param keepRecent - Number of recent messages to preserve verbatim (optional)
|
|
893
|
+
* @returns Compaction result with counts and the summary message ID
|
|
894
|
+
*/
|
|
895
|
+
compactChat(chatId: string, keepRecent?: number): Promise<CompactChatResponse>;
|
|
869
896
|
/**
|
|
870
897
|
* Merge multiple chat sessions into one
|
|
871
898
|
*/
|
package/dist/client.js
CHANGED
|
@@ -1277,6 +1277,23 @@ class EkoDBClient {
|
|
|
1277
1277
|
async toggleForgottenMessage(sessionId, messageId, forgotten) {
|
|
1278
1278
|
await this.makeRequest("PATCH", `/api/chat/${sessionId}/messages/${messageId}/forgotten`, { forgotten }, 0, true);
|
|
1279
1279
|
}
|
|
1280
|
+
/**
|
|
1281
|
+
* Compact a chat session's history on demand.
|
|
1282
|
+
*
|
|
1283
|
+
* Folds older messages into a summary while preserving the most recent
|
|
1284
|
+
* messages verbatim, reducing context size for long-running sessions.
|
|
1285
|
+
*
|
|
1286
|
+
* @param chatId - Chat session ID
|
|
1287
|
+
* @param keepRecent - Number of recent messages to preserve verbatim (optional)
|
|
1288
|
+
* @returns Compaction result with counts and the summary message ID
|
|
1289
|
+
*/
|
|
1290
|
+
async compactChat(chatId, keepRecent) {
|
|
1291
|
+
const body = {};
|
|
1292
|
+
if (keepRecent !== undefined) {
|
|
1293
|
+
body.keep_recent = keepRecent;
|
|
1294
|
+
}
|
|
1295
|
+
return this.makeRequest("POST", `/api/chat/${chatId}/compact`, body, 0, true);
|
|
1296
|
+
}
|
|
1280
1297
|
/**
|
|
1281
1298
|
* Merge multiple chat sessions into one
|
|
1282
1299
|
*/
|
package/dist/client.test.js
CHANGED
|
@@ -489,6 +489,41 @@ function mockErrorResponse(status, message) {
|
|
|
489
489
|
mockJsonResponse({ status: "deleted" });
|
|
490
490
|
await (0, vitest_1.expect)(client.deleteChatSession("chat_123")).resolves.not.toThrow();
|
|
491
491
|
});
|
|
492
|
+
(0, vitest_1.it)("compacts chat history", async () => {
|
|
493
|
+
const client = createTestClient();
|
|
494
|
+
mockTokenResponse();
|
|
495
|
+
mockJsonResponse({
|
|
496
|
+
folded: 12,
|
|
497
|
+
kept_recent: 8,
|
|
498
|
+
summary_chars: 1024,
|
|
499
|
+
summary_message_id: "msg_summary_001",
|
|
500
|
+
already_compact: false,
|
|
501
|
+
});
|
|
502
|
+
const result = await client.compactChat("chat_123", 8);
|
|
503
|
+
(0, vitest_1.expect)(result).toHaveProperty("folded", 12);
|
|
504
|
+
(0, vitest_1.expect)(result).toHaveProperty("kept_recent", 8);
|
|
505
|
+
(0, vitest_1.expect)(result).toHaveProperty("summary_message_id", "msg_summary_001");
|
|
506
|
+
(0, vitest_1.expect)(result).toHaveProperty("already_compact", false);
|
|
507
|
+
const [, init] = mockFetch.mock.calls[1];
|
|
508
|
+
(0, vitest_1.expect)(init.method).toBe("POST");
|
|
509
|
+
(0, vitest_1.expect)(JSON.parse(init.body)).toEqual({ keep_recent: 8 });
|
|
510
|
+
});
|
|
511
|
+
(0, vitest_1.it)("compacts chat history without keepRecent", async () => {
|
|
512
|
+
const client = createTestClient();
|
|
513
|
+
mockTokenResponse();
|
|
514
|
+
mockJsonResponse({
|
|
515
|
+
folded: 0,
|
|
516
|
+
kept_recent: 0,
|
|
517
|
+
summary_chars: 0,
|
|
518
|
+
summary_message_id: null,
|
|
519
|
+
already_compact: true,
|
|
520
|
+
});
|
|
521
|
+
const result = await client.compactChat("chat_123");
|
|
522
|
+
(0, vitest_1.expect)(result.already_compact).toBe(true);
|
|
523
|
+
(0, vitest_1.expect)(result.summary_message_id).toBeNull();
|
|
524
|
+
const [, init] = mockFetch.mock.calls[1];
|
|
525
|
+
(0, vitest_1.expect)(JSON.parse(init.body)).toEqual({});
|
|
526
|
+
});
|
|
492
527
|
});
|
|
493
528
|
// ============================================================================
|
|
494
529
|
// Error Handling Tests
|
package/dist/index.d.ts
CHANGED
|
@@ -12,4 +12,4 @@ export type { Schema, FieldTypeSchema, IndexConfig, CollectionMetadata, } from "
|
|
|
12
12
|
export type { JoinConfig } from "./join";
|
|
13
13
|
export type { UserFunction, ParameterDefinition, FunctionStageConfig, GroupFunctionConfig, SortFieldConfig, FunctionResult, FunctionStats, StageStats, } from "./functions";
|
|
14
14
|
export type { MutationNotification, ChatStreamEvent, ClientToolDefinition, ChatSendOptions, SubscribeOptions, } from "./client";
|
|
15
|
-
export type { Record, Query, BatchOperationResult, ClientConfig, RateLimitInfo, CollectionConfig, ChatRequest, CreateChatSessionRequest, ChatMessageRequest, TokenUsage, ChatResponse, ChatSession, ChatSessionResponse, ListSessionsQuery, ListSessionsResponse, GetMessagesQuery, GetMessagesResponse, UpdateSessionRequest, MergeSessionsRequest, ChatModels, EmbedRequest, EmbedResponse, RawCompletionRequest, RawCompletionResponse, ToolChoice, ToolConfig, } from "./client";
|
|
15
|
+
export type { Record, Query, BatchOperationResult, ClientConfig, RateLimitInfo, CollectionConfig, ChatRequest, CreateChatSessionRequest, ChatMessageRequest, TokenUsage, ChatResponse, ChatSession, ChatSessionResponse, ListSessionsQuery, ListSessionsResponse, GetMessagesQuery, GetMessagesResponse, UpdateSessionRequest, MergeSessionsRequest, ChatModels, CompactChatRequest, CompactChatResponse, EmbedRequest, EmbedResponse, RawCompletionRequest, RawCompletionResponse, ToolChoice, ToolConfig, } from "./client";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ekodb/ekodb-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "Official TypeScript/JavaScript client for ekoDB",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,6 +27,6 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@msgpack/msgpack": "^3.1.3",
|
|
30
|
-
"ws": "^8.
|
|
30
|
+
"ws": "^8.20.1"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/src/client.test.ts
CHANGED
|
@@ -665,6 +665,51 @@ describe("EkoDBClient chat", () => {
|
|
|
665
665
|
|
|
666
666
|
await expect(client.deleteChatSession("chat_123")).resolves.not.toThrow();
|
|
667
667
|
});
|
|
668
|
+
|
|
669
|
+
it("compacts chat history", async () => {
|
|
670
|
+
const client = createTestClient();
|
|
671
|
+
|
|
672
|
+
mockTokenResponse();
|
|
673
|
+
mockJsonResponse({
|
|
674
|
+
folded: 12,
|
|
675
|
+
kept_recent: 8,
|
|
676
|
+
summary_chars: 1024,
|
|
677
|
+
summary_message_id: "msg_summary_001",
|
|
678
|
+
already_compact: false,
|
|
679
|
+
});
|
|
680
|
+
|
|
681
|
+
const result = await client.compactChat("chat_123", 8);
|
|
682
|
+
|
|
683
|
+
expect(result).toHaveProperty("folded", 12);
|
|
684
|
+
expect(result).toHaveProperty("kept_recent", 8);
|
|
685
|
+
expect(result).toHaveProperty("summary_message_id", "msg_summary_001");
|
|
686
|
+
expect(result).toHaveProperty("already_compact", false);
|
|
687
|
+
|
|
688
|
+
const [, init] = mockFetch.mock.calls[1];
|
|
689
|
+
expect(init.method).toBe("POST");
|
|
690
|
+
expect(JSON.parse(init.body as string)).toEqual({ keep_recent: 8 });
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
it("compacts chat history without keepRecent", async () => {
|
|
694
|
+
const client = createTestClient();
|
|
695
|
+
|
|
696
|
+
mockTokenResponse();
|
|
697
|
+
mockJsonResponse({
|
|
698
|
+
folded: 0,
|
|
699
|
+
kept_recent: 0,
|
|
700
|
+
summary_chars: 0,
|
|
701
|
+
summary_message_id: null,
|
|
702
|
+
already_compact: true,
|
|
703
|
+
});
|
|
704
|
+
|
|
705
|
+
const result = await client.compactChat("chat_123");
|
|
706
|
+
|
|
707
|
+
expect(result.already_compact).toBe(true);
|
|
708
|
+
expect(result.summary_message_id).toBeNull();
|
|
709
|
+
|
|
710
|
+
const [, init] = mockFetch.mock.calls[1];
|
|
711
|
+
expect(JSON.parse(init.body as string)).toEqual({});
|
|
712
|
+
});
|
|
668
713
|
});
|
|
669
714
|
|
|
670
715
|
// ============================================================================
|
package/src/client.ts
CHANGED
|
@@ -304,6 +304,26 @@ export interface ChatModels {
|
|
|
304
304
|
perplexity: string[];
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
+
/**
|
|
308
|
+
* Request to compact a chat session's history on demand.
|
|
309
|
+
*/
|
|
310
|
+
export interface CompactChatRequest {
|
|
311
|
+
keep_recent?: number;
|
|
312
|
+
// No bypass_ripple: compaction writes chat-message records, which the server
|
|
313
|
+
// does not ripple (same convention as all chat-message writes).
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Result of an on-demand chat history compaction.
|
|
318
|
+
*/
|
|
319
|
+
export interface CompactChatResponse {
|
|
320
|
+
folded: number;
|
|
321
|
+
kept_recent: number;
|
|
322
|
+
summary_chars: number;
|
|
323
|
+
summary_message_id: string | null;
|
|
324
|
+
already_compact: boolean;
|
|
325
|
+
}
|
|
326
|
+
|
|
307
327
|
/**
|
|
308
328
|
* Request to generate embeddings
|
|
309
329
|
*/
|
|
@@ -2042,6 +2062,33 @@ export class EkoDBClient {
|
|
|
2042
2062
|
);
|
|
2043
2063
|
}
|
|
2044
2064
|
|
|
2065
|
+
/**
|
|
2066
|
+
* Compact a chat session's history on demand.
|
|
2067
|
+
*
|
|
2068
|
+
* Folds older messages into a summary while preserving the most recent
|
|
2069
|
+
* messages verbatim, reducing context size for long-running sessions.
|
|
2070
|
+
*
|
|
2071
|
+
* @param chatId - Chat session ID
|
|
2072
|
+
* @param keepRecent - Number of recent messages to preserve verbatim (optional)
|
|
2073
|
+
* @returns Compaction result with counts and the summary message ID
|
|
2074
|
+
*/
|
|
2075
|
+
async compactChat(
|
|
2076
|
+
chatId: string,
|
|
2077
|
+
keepRecent?: number,
|
|
2078
|
+
): Promise<CompactChatResponse> {
|
|
2079
|
+
const body: CompactChatRequest = {};
|
|
2080
|
+
if (keepRecent !== undefined) {
|
|
2081
|
+
body.keep_recent = keepRecent;
|
|
2082
|
+
}
|
|
2083
|
+
return this.makeRequest<CompactChatResponse>(
|
|
2084
|
+
"POST",
|
|
2085
|
+
`/api/chat/${chatId}/compact`,
|
|
2086
|
+
body,
|
|
2087
|
+
0,
|
|
2088
|
+
true, // Force JSON for chat operations
|
|
2089
|
+
);
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2045
2092
|
/**
|
|
2046
2093
|
* Merge multiple chat sessions into one
|
|
2047
2094
|
*/
|