@ekodb/ekodb-client 0.2.1 → 0.4.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 +49 -3
- package/dist/client.js +144 -39
- package/dist/functions.d.ts +195 -0
- package/dist/functions.js +154 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +5 -1
- package/package.json +2 -1
- package/src/client.ts +245 -25
- package/src/functions.ts +420 -0
- package/src/index.ts +12 -0
package/dist/client.d.ts
CHANGED
|
@@ -4,9 +4,19 @@
|
|
|
4
4
|
import { QueryBuilder } from "./query-builder";
|
|
5
5
|
import { SearchQuery, SearchQueryBuilder, SearchResponse } from "./search";
|
|
6
6
|
import { Schema, SchemaBuilder, CollectionMetadata } from "./schema";
|
|
7
|
+
import { Script, FunctionResult } from "./functions";
|
|
7
8
|
export interface Record {
|
|
8
9
|
[key: string]: any;
|
|
9
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Serialization format for client-server communication
|
|
13
|
+
*/
|
|
14
|
+
export declare enum SerializationFormat {
|
|
15
|
+
/** JSON format (default, human-readable) */
|
|
16
|
+
Json = "Json",
|
|
17
|
+
/** MessagePack format (binary, 2-3x faster) */
|
|
18
|
+
MessagePack = "MessagePack"
|
|
19
|
+
}
|
|
10
20
|
/**
|
|
11
21
|
* Rate limit information from the server
|
|
12
22
|
*/
|
|
@@ -32,6 +42,8 @@ export interface ClientConfig {
|
|
|
32
42
|
maxRetries?: number;
|
|
33
43
|
/** Request timeout in milliseconds (default: 30000) */
|
|
34
44
|
timeout?: number;
|
|
45
|
+
/** Serialization format (default: MessagePack for best performance, use Json for debugging) */
|
|
46
|
+
format?: SerializationFormat;
|
|
35
47
|
}
|
|
36
48
|
/**
|
|
37
49
|
* Rate limit error
|
|
@@ -155,6 +167,7 @@ export declare class EkoDBClient {
|
|
|
155
167
|
private shouldRetry;
|
|
156
168
|
private maxRetries;
|
|
157
169
|
private timeout;
|
|
170
|
+
private format;
|
|
158
171
|
private rateLimitInfo;
|
|
159
172
|
constructor(config: string | ClientConfig, apiKey?: string);
|
|
160
173
|
/**
|
|
@@ -181,6 +194,12 @@ export declare class EkoDBClient {
|
|
|
181
194
|
* Sleep for a specified number of seconds
|
|
182
195
|
*/
|
|
183
196
|
private sleep;
|
|
197
|
+
/**
|
|
198
|
+
* Helper to determine if a path should use JSON
|
|
199
|
+
* Only CRUD operations (insert/update/delete/batch) use MessagePack
|
|
200
|
+
* Everything else uses JSON for compatibility
|
|
201
|
+
*/
|
|
202
|
+
private shouldUseJSON;
|
|
184
203
|
/**
|
|
185
204
|
* Make an HTTP request to the ekoDB API with retry logic
|
|
186
205
|
*/
|
|
@@ -227,18 +246,19 @@ export declare class EkoDBClient {
|
|
|
227
246
|
/**
|
|
228
247
|
* Batch insert multiple documents
|
|
229
248
|
*/
|
|
230
|
-
batchInsert(collection: string, records: Record[]): Promise<
|
|
249
|
+
batchInsert(collection: string, records: Record[], bypassRipple?: boolean): Promise<BatchOperationResult>;
|
|
231
250
|
/**
|
|
232
251
|
* Batch update multiple documents
|
|
233
252
|
*/
|
|
234
253
|
batchUpdate(collection: string, updates: Array<{
|
|
235
254
|
id: string;
|
|
236
255
|
data: Record;
|
|
237
|
-
|
|
256
|
+
bypassRipple?: boolean;
|
|
257
|
+
}>): Promise<BatchOperationResult>;
|
|
238
258
|
/**
|
|
239
259
|
* Batch delete multiple documents
|
|
240
260
|
*/
|
|
241
|
-
batchDelete(collection: string, ids: string[]): Promise<
|
|
261
|
+
batchDelete(collection: string, ids: string[], bypassRipple?: boolean): Promise<BatchOperationResult>;
|
|
242
262
|
/**
|
|
243
263
|
* Set a key-value pair
|
|
244
264
|
*/
|
|
@@ -376,6 +396,32 @@ export declare class EkoDBClient {
|
|
|
376
396
|
* Merge multiple chat sessions into one
|
|
377
397
|
*/
|
|
378
398
|
mergeChatSessions(request: MergeSessionsRequest): Promise<ChatSessionResponse>;
|
|
399
|
+
/**
|
|
400
|
+
* Save a new script definition
|
|
401
|
+
*/
|
|
402
|
+
saveScript(script: Script): Promise<string>;
|
|
403
|
+
/**
|
|
404
|
+
* Get a script by ID
|
|
405
|
+
*/
|
|
406
|
+
getScript(id: string): Promise<Script>;
|
|
407
|
+
/**
|
|
408
|
+
* List all scripts, optionally filtered by tags
|
|
409
|
+
*/
|
|
410
|
+
listScripts(tags?: string[]): Promise<Script[]>;
|
|
411
|
+
/**
|
|
412
|
+
* Update an existing script by ID
|
|
413
|
+
*/
|
|
414
|
+
updateScript(id: string, script: Script): Promise<void>;
|
|
415
|
+
/**
|
|
416
|
+
* Delete a script by ID
|
|
417
|
+
*/
|
|
418
|
+
deleteScript(id: string): Promise<void>;
|
|
419
|
+
/**
|
|
420
|
+
* Call a saved script by ID or label
|
|
421
|
+
*/
|
|
422
|
+
callScript(idOrLabel: string, params?: {
|
|
423
|
+
[key: string]: any;
|
|
424
|
+
}): Promise<FunctionResult>;
|
|
379
425
|
/**
|
|
380
426
|
* Create a WebSocket client
|
|
381
427
|
*/
|
package/dist/client.js
CHANGED
|
@@ -36,10 +36,21 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
36
36
|
};
|
|
37
37
|
})();
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.WebSocketClient = exports.EkoDBClient = exports.MergeStrategy = exports.RateLimitError = void 0;
|
|
39
|
+
exports.WebSocketClient = exports.EkoDBClient = exports.MergeStrategy = exports.RateLimitError = exports.SerializationFormat = void 0;
|
|
40
|
+
const msgpack_1 = require("@msgpack/msgpack");
|
|
40
41
|
const query_builder_1 = require("./query-builder");
|
|
41
42
|
const search_1 = require("./search");
|
|
42
43
|
const schema_1 = require("./schema");
|
|
44
|
+
/**
|
|
45
|
+
* Serialization format for client-server communication
|
|
46
|
+
*/
|
|
47
|
+
var SerializationFormat;
|
|
48
|
+
(function (SerializationFormat) {
|
|
49
|
+
/** JSON format (default, human-readable) */
|
|
50
|
+
SerializationFormat["Json"] = "Json";
|
|
51
|
+
/** MessagePack format (binary, 2-3x faster) */
|
|
52
|
+
SerializationFormat["MessagePack"] = "MessagePack";
|
|
53
|
+
})(SerializationFormat || (exports.SerializationFormat = SerializationFormat = {}));
|
|
43
54
|
/**
|
|
44
55
|
* Rate limit error
|
|
45
56
|
*/
|
|
@@ -68,6 +79,7 @@ class EkoDBClient {
|
|
|
68
79
|
this.shouldRetry = true;
|
|
69
80
|
this.maxRetries = 3;
|
|
70
81
|
this.timeout = 30000;
|
|
82
|
+
this.format = SerializationFormat.MessagePack; // Default to MessagePack for 2-3x performance
|
|
71
83
|
}
|
|
72
84
|
else {
|
|
73
85
|
this.baseURL = config.baseURL;
|
|
@@ -75,6 +87,7 @@ class EkoDBClient {
|
|
|
75
87
|
this.shouldRetry = config.shouldRetry ?? true;
|
|
76
88
|
this.maxRetries = config.maxRetries ?? 3;
|
|
77
89
|
this.timeout = config.timeout ?? 30000;
|
|
90
|
+
this.format = config.format ?? SerializationFormat.MessagePack; // Default to MessagePack for 2-3x performance
|
|
78
91
|
}
|
|
79
92
|
}
|
|
80
93
|
/**
|
|
@@ -138,29 +151,72 @@ class EkoDBClient {
|
|
|
138
151
|
sleep(seconds) {
|
|
139
152
|
return new Promise((resolve) => setTimeout(resolve, seconds * 1000));
|
|
140
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Helper to determine if a path should use JSON
|
|
156
|
+
* Only CRUD operations (insert/update/delete/batch) use MessagePack
|
|
157
|
+
* Everything else uses JSON for compatibility
|
|
158
|
+
*/
|
|
159
|
+
shouldUseJSON(path) {
|
|
160
|
+
// ONLY these operations support MessagePack
|
|
161
|
+
const msgpackPaths = [
|
|
162
|
+
"/api/insert/",
|
|
163
|
+
"/api/batch_insert/",
|
|
164
|
+
"/api/update/",
|
|
165
|
+
"/api/batch_update/",
|
|
166
|
+
"/api/delete/",
|
|
167
|
+
"/api/batch_delete/",
|
|
168
|
+
];
|
|
169
|
+
// Check if path starts with any MessagePack-supported operation
|
|
170
|
+
for (const prefix of msgpackPaths) {
|
|
171
|
+
if (path.startsWith(prefix)) {
|
|
172
|
+
return false; // Use MessagePack
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// Everything else uses JSON
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
141
178
|
/**
|
|
142
179
|
* Make an HTTP request to the ekoDB API with retry logic
|
|
143
180
|
*/
|
|
144
|
-
async makeRequest(method, path, data, attempt = 0) {
|
|
181
|
+
async makeRequest(method, path, data, attempt = 0, forceJson = false) {
|
|
145
182
|
if (!this.token) {
|
|
146
183
|
await this.refreshToken();
|
|
147
184
|
}
|
|
185
|
+
// Determine content type and serialization based on path
|
|
186
|
+
// Only CRUD operations support MessagePack, everything else uses JSON
|
|
187
|
+
const shouldForceJson = forceJson || this.shouldUseJSON(path);
|
|
188
|
+
const isMessagePack = !shouldForceJson && this.format === SerializationFormat.MessagePack;
|
|
189
|
+
const contentType = isMessagePack
|
|
190
|
+
? "application/msgpack"
|
|
191
|
+
: "application/json";
|
|
192
|
+
// Note: Modern fetch API automatically handles gzip/deflate decompression
|
|
193
|
+
// when server sends Content-Encoding header. No additional configuration needed.
|
|
148
194
|
const options = {
|
|
149
195
|
method,
|
|
150
196
|
headers: {
|
|
151
197
|
Authorization: `Bearer ${this.token}`,
|
|
152
|
-
"Content-Type":
|
|
198
|
+
"Content-Type": contentType,
|
|
199
|
+
Accept: contentType,
|
|
153
200
|
},
|
|
154
201
|
};
|
|
155
202
|
if (data) {
|
|
156
|
-
options.body =
|
|
203
|
+
options.body = isMessagePack
|
|
204
|
+
? (0, msgpack_1.encode)(data)
|
|
205
|
+
: JSON.stringify(data);
|
|
157
206
|
}
|
|
158
207
|
try {
|
|
159
208
|
const response = await fetch(`${this.baseURL}${path}`, options);
|
|
160
209
|
// Extract rate limit info from successful responses
|
|
161
210
|
if (response.ok) {
|
|
162
211
|
this.extractRateLimitInfo(response);
|
|
163
|
-
|
|
212
|
+
// Deserialize based on format
|
|
213
|
+
if (isMessagePack) {
|
|
214
|
+
const buffer = await response.arrayBuffer();
|
|
215
|
+
return (0, msgpack_1.decode)(new Uint8Array(buffer));
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
return response.json();
|
|
219
|
+
}
|
|
164
220
|
}
|
|
165
221
|
// Handle rate limiting (429)
|
|
166
222
|
if (response.status === 429) {
|
|
@@ -168,7 +224,7 @@ class EkoDBClient {
|
|
|
168
224
|
if (this.shouldRetry && attempt < this.maxRetries) {
|
|
169
225
|
console.log(`Rate limited. Retrying after ${retryAfter} seconds...`);
|
|
170
226
|
await this.sleep(retryAfter);
|
|
171
|
-
return this.makeRequest(method, path, data, attempt + 1);
|
|
227
|
+
return this.makeRequest(method, path, data, attempt + 1, forceJson);
|
|
172
228
|
}
|
|
173
229
|
throw new RateLimitError(retryAfter);
|
|
174
230
|
}
|
|
@@ -179,7 +235,7 @@ class EkoDBClient {
|
|
|
179
235
|
const retryDelay = 10;
|
|
180
236
|
console.log(`Service unavailable. Retrying after ${retryDelay} seconds...`);
|
|
181
237
|
await this.sleep(retryDelay);
|
|
182
|
-
return this.makeRequest(method, path, data, attempt + 1);
|
|
238
|
+
return this.makeRequest(method, path, data, attempt + 1, forceJson);
|
|
183
239
|
}
|
|
184
240
|
// Handle other errors
|
|
185
241
|
const text = await response.text();
|
|
@@ -193,7 +249,7 @@ class EkoDBClient {
|
|
|
193
249
|
const retryDelay = 3;
|
|
194
250
|
console.log(`Network error. Retrying after ${retryDelay} seconds...`);
|
|
195
251
|
await this.sleep(retryDelay);
|
|
196
|
-
return this.makeRequest(method, path, data, attempt + 1);
|
|
252
|
+
return this.makeRequest(method, path, data, attempt + 1, forceJson);
|
|
197
253
|
}
|
|
198
254
|
throw error;
|
|
199
255
|
}
|
|
@@ -255,57 +311,65 @@ class EkoDBClient {
|
|
|
255
311
|
/**
|
|
256
312
|
* Batch insert multiple documents
|
|
257
313
|
*/
|
|
258
|
-
async batchInsert(collection, records) {
|
|
259
|
-
const inserts = records.map((data) => ({
|
|
260
|
-
|
|
261
|
-
|
|
314
|
+
async batchInsert(collection, records, bypassRipple) {
|
|
315
|
+
const inserts = records.map((data) => ({
|
|
316
|
+
data,
|
|
317
|
+
bypass_ripple: bypassRipple,
|
|
318
|
+
}));
|
|
319
|
+
return this.makeRequest("POST", `/api/batch/insert/${collection}`, { inserts });
|
|
262
320
|
}
|
|
263
321
|
/**
|
|
264
322
|
* Batch update multiple documents
|
|
265
323
|
*/
|
|
266
324
|
async batchUpdate(collection, updates) {
|
|
267
|
-
const
|
|
268
|
-
|
|
325
|
+
const formattedUpdates = updates.map((u) => ({
|
|
326
|
+
id: u.id,
|
|
327
|
+
data: u.data,
|
|
328
|
+
bypass_ripple: u.bypassRipple,
|
|
329
|
+
}));
|
|
330
|
+
return this.makeRequest("PUT", `/api/batch/update/${collection}`, { updates: formattedUpdates });
|
|
269
331
|
}
|
|
270
332
|
/**
|
|
271
333
|
* Batch delete multiple documents
|
|
272
334
|
*/
|
|
273
|
-
async batchDelete(collection, ids) {
|
|
274
|
-
const deletes = ids.map((id) => ({
|
|
275
|
-
|
|
276
|
-
|
|
335
|
+
async batchDelete(collection, ids, bypassRipple) {
|
|
336
|
+
const deletes = ids.map((id) => ({
|
|
337
|
+
id: id,
|
|
338
|
+
bypass_ripple: bypassRipple,
|
|
339
|
+
}));
|
|
340
|
+
return this.makeRequest("DELETE", `/api/batch/delete/${collection}`, { deletes });
|
|
277
341
|
}
|
|
278
342
|
/**
|
|
279
343
|
* Set a key-value pair
|
|
280
344
|
*/
|
|
281
345
|
async kvSet(key, value) {
|
|
282
|
-
await this.makeRequest("POST", `/api/kv/set/${encodeURIComponent(key)}`, { value });
|
|
346
|
+
await this.makeRequest("POST", `/api/kv/set/${encodeURIComponent(key)}`, { value }, 0, true);
|
|
283
347
|
}
|
|
284
348
|
/**
|
|
285
349
|
* Get a value by key
|
|
286
350
|
*/
|
|
287
351
|
async kvGet(key) {
|
|
288
|
-
const result = await this.makeRequest("GET", `/api/kv/get/${encodeURIComponent(key)}
|
|
352
|
+
const result = await this.makeRequest("GET", `/api/kv/get/${encodeURIComponent(key)}`, undefined, 0, true);
|
|
289
353
|
return result.value;
|
|
290
354
|
}
|
|
291
355
|
/**
|
|
292
356
|
* Delete a key
|
|
293
357
|
*/
|
|
294
358
|
async kvDelete(key) {
|
|
295
|
-
await this.makeRequest("DELETE", `/api/kv/delete/${encodeURIComponent(key)}
|
|
359
|
+
await this.makeRequest("DELETE", `/api/kv/delete/${encodeURIComponent(key)}`, undefined, 0, true);
|
|
296
360
|
}
|
|
297
361
|
/**
|
|
298
362
|
* List all collections
|
|
299
363
|
*/
|
|
300
364
|
async listCollections() {
|
|
301
|
-
const result = await this.makeRequest("GET", "/api/collections");
|
|
365
|
+
const result = await this.makeRequest("GET", "/api/collections", undefined, 0, true);
|
|
302
366
|
return result.collections;
|
|
303
367
|
}
|
|
304
368
|
/**
|
|
305
369
|
* Delete a collection
|
|
306
370
|
*/
|
|
307
371
|
async deleteCollection(collection) {
|
|
308
|
-
await this.makeRequest("DELETE", `/api/collections/${collection}
|
|
372
|
+
await this.makeRequest("DELETE", `/api/collections/${collection}`, undefined, 0, true);
|
|
309
373
|
}
|
|
310
374
|
/**
|
|
311
375
|
* Create a collection with schema
|
|
@@ -325,7 +389,7 @@ class EkoDBClient {
|
|
|
325
389
|
*/
|
|
326
390
|
async createCollection(collection, schema) {
|
|
327
391
|
const schemaObj = schema instanceof schema_1.SchemaBuilder ? schema.build() : schema;
|
|
328
|
-
await this.makeRequest("POST", `/api/collections/${collection}`, schemaObj);
|
|
392
|
+
await this.makeRequest("POST", `/api/collections/${collection}`, schemaObj, 0, true);
|
|
329
393
|
}
|
|
330
394
|
/**
|
|
331
395
|
* Get collection metadata and schema
|
|
@@ -334,7 +398,7 @@ class EkoDBClient {
|
|
|
334
398
|
* @returns Collection metadata including schema and analytics
|
|
335
399
|
*/
|
|
336
400
|
async getCollection(collection) {
|
|
337
|
-
return this.makeRequest("GET", `/api/collections/${collection}
|
|
401
|
+
return this.makeRequest("GET", `/api/collections/${collection}`, undefined, 0, true);
|
|
338
402
|
}
|
|
339
403
|
/**
|
|
340
404
|
* Get collection schema
|
|
@@ -383,26 +447,26 @@ class EkoDBClient {
|
|
|
383
447
|
const queryObj = searchQuery instanceof search_1.SearchQueryBuilder
|
|
384
448
|
? searchQuery.build()
|
|
385
449
|
: searchQuery;
|
|
386
|
-
return this.makeRequest("POST", `/api/search/${collection}`, queryObj);
|
|
450
|
+
return this.makeRequest("POST", `/api/search/${collection}`, queryObj, 0, true);
|
|
387
451
|
}
|
|
388
452
|
// ========== Chat Methods ==========
|
|
389
453
|
/**
|
|
390
454
|
* Create a new chat session
|
|
391
455
|
*/
|
|
392
456
|
async createChatSession(request) {
|
|
393
|
-
return this.makeRequest("POST", "/api/chat", request);
|
|
457
|
+
return this.makeRequest("POST", "/api/chat", request, 0, true);
|
|
394
458
|
}
|
|
395
459
|
/**
|
|
396
460
|
* Send a message in an existing chat session
|
|
397
461
|
*/
|
|
398
462
|
async chatMessage(sessionId, request) {
|
|
399
|
-
return this.makeRequest("POST", `/api/chat/${sessionId}/messages`, request);
|
|
463
|
+
return this.makeRequest("POST", `/api/chat/${sessionId}/messages`, request, 0, true);
|
|
400
464
|
}
|
|
401
465
|
/**
|
|
402
466
|
* Get a chat session by ID
|
|
403
467
|
*/
|
|
404
468
|
async getChatSession(sessionId) {
|
|
405
|
-
return this.makeRequest("GET", `/api/chat/${sessionId}
|
|
469
|
+
return this.makeRequest("GET", `/api/chat/${sessionId}`, undefined, 0, true);
|
|
406
470
|
}
|
|
407
471
|
/**
|
|
408
472
|
* List all chat sessions
|
|
@@ -417,7 +481,7 @@ class EkoDBClient {
|
|
|
417
481
|
params.append("sort", query.sort);
|
|
418
482
|
const queryString = params.toString();
|
|
419
483
|
const path = queryString ? `/api/chat?${queryString}` : "/api/chat";
|
|
420
|
-
return this.makeRequest("GET", path);
|
|
484
|
+
return this.makeRequest("GET", path, undefined, 0, true);
|
|
421
485
|
}
|
|
422
486
|
/**
|
|
423
487
|
* Get messages from a chat session
|
|
@@ -434,55 +498,96 @@ class EkoDBClient {
|
|
|
434
498
|
const path = queryString
|
|
435
499
|
? `/api/chat/${sessionId}/messages?${queryString}`
|
|
436
500
|
: `/api/chat/${sessionId}/messages`;
|
|
437
|
-
return this.makeRequest("GET", path);
|
|
501
|
+
return this.makeRequest("GET", path, undefined, 0, true);
|
|
438
502
|
}
|
|
439
503
|
/**
|
|
440
504
|
* Update a chat session
|
|
441
505
|
*/
|
|
442
506
|
async updateChatSession(sessionId, request) {
|
|
443
|
-
return this.makeRequest("PUT", `/api/chat/${sessionId}`, request);
|
|
507
|
+
return this.makeRequest("PUT", `/api/chat/${sessionId}`, request, 0, true);
|
|
444
508
|
}
|
|
445
509
|
/**
|
|
446
510
|
* Branch a chat session
|
|
447
511
|
*/
|
|
448
512
|
async branchChatSession(request) {
|
|
449
|
-
return this.makeRequest("POST", "/api/chat/branch", request);
|
|
513
|
+
return this.makeRequest("POST", "/api/chat/branch", request, 0, true);
|
|
450
514
|
}
|
|
451
515
|
/**
|
|
452
516
|
* Delete a chat session
|
|
453
517
|
*/
|
|
454
518
|
async deleteChatSession(sessionId) {
|
|
455
|
-
await this.makeRequest("DELETE", `/api/chat/${sessionId}
|
|
519
|
+
await this.makeRequest("DELETE", `/api/chat/${sessionId}`, undefined, 0, true);
|
|
456
520
|
}
|
|
457
521
|
/**
|
|
458
522
|
* Regenerate an AI response message
|
|
459
523
|
*/
|
|
460
524
|
async regenerateMessage(sessionId, messageId) {
|
|
461
|
-
return this.makeRequest("POST", `/api/chat/${sessionId}/messages/${messageId}/regenerate
|
|
525
|
+
return this.makeRequest("POST", `/api/chat/${sessionId}/messages/${messageId}/regenerate`, undefined, 0, true);
|
|
462
526
|
}
|
|
463
527
|
/**
|
|
464
528
|
* Update a specific message
|
|
465
529
|
*/
|
|
466
530
|
async updateChatMessage(sessionId, messageId, content) {
|
|
467
|
-
await this.makeRequest("PUT", `/api/chat/${sessionId}/messages/${messageId}`, { content });
|
|
531
|
+
await this.makeRequest("PUT", `/api/chat/${sessionId}/messages/${messageId}`, { content }, 0, true);
|
|
468
532
|
}
|
|
469
533
|
/**
|
|
470
534
|
* Delete a specific message
|
|
471
535
|
*/
|
|
472
536
|
async deleteChatMessage(sessionId, messageId) {
|
|
473
|
-
await this.makeRequest("DELETE", `/api/chat/${sessionId}/messages/${messageId}
|
|
537
|
+
await this.makeRequest("DELETE", `/api/chat/${sessionId}/messages/${messageId}`, undefined, 0, true);
|
|
474
538
|
}
|
|
475
539
|
/**
|
|
476
540
|
* Toggle the "forgotten" status of a message
|
|
477
541
|
*/
|
|
478
542
|
async toggleForgottenMessage(sessionId, messageId, forgotten) {
|
|
479
|
-
await this.makeRequest("PATCH", `/api/chat/${sessionId}/messages/${messageId}/forgotten`, { forgotten });
|
|
543
|
+
await this.makeRequest("PATCH", `/api/chat/${sessionId}/messages/${messageId}/forgotten`, { forgotten }, 0, true);
|
|
480
544
|
}
|
|
481
545
|
/**
|
|
482
546
|
* Merge multiple chat sessions into one
|
|
483
547
|
*/
|
|
484
548
|
async mergeChatSessions(request) {
|
|
485
|
-
return this.makeRequest("POST", "/api/chat/merge", request);
|
|
549
|
+
return this.makeRequest("POST", "/api/chat/merge", request, 0, true);
|
|
550
|
+
}
|
|
551
|
+
// ========================================================================
|
|
552
|
+
// SCRIPTS API
|
|
553
|
+
// ========================================================================
|
|
554
|
+
/**
|
|
555
|
+
* Save a new script definition
|
|
556
|
+
*/
|
|
557
|
+
async saveScript(script) {
|
|
558
|
+
const result = await this.makeRequest("POST", "/api/functions", script);
|
|
559
|
+
return result.id;
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Get a script by ID
|
|
563
|
+
*/
|
|
564
|
+
async getScript(id) {
|
|
565
|
+
return this.makeRequest("GET", `/api/functions/${id}`);
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* List all scripts, optionally filtered by tags
|
|
569
|
+
*/
|
|
570
|
+
async listScripts(tags) {
|
|
571
|
+
const params = tags ? `?tags=${tags.join(",")}` : "";
|
|
572
|
+
return this.makeRequest("GET", `/api/functions${params}`);
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Update an existing script by ID
|
|
576
|
+
*/
|
|
577
|
+
async updateScript(id, script) {
|
|
578
|
+
await this.makeRequest("PUT", `/api/functions/${id}`, script);
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Delete a script by ID
|
|
582
|
+
*/
|
|
583
|
+
async deleteScript(id) {
|
|
584
|
+
await this.makeRequest("DELETE", `/api/functions/${id}`);
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Call a saved script by ID or label
|
|
588
|
+
*/
|
|
589
|
+
async callScript(idOrLabel, params) {
|
|
590
|
+
return this.makeRequest("POST", `/api/functions/${idOrLabel}`, params || {});
|
|
486
591
|
}
|
|
487
592
|
/**
|
|
488
593
|
* Create a WebSocket client
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scripts API for ekoDB TypeScript client
|
|
3
|
+
*/
|
|
4
|
+
export interface Script {
|
|
5
|
+
label: string;
|
|
6
|
+
name: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
version: string;
|
|
9
|
+
parameters: {
|
|
10
|
+
[key: string]: ParameterDefinition;
|
|
11
|
+
};
|
|
12
|
+
functions: FunctionStageConfig[];
|
|
13
|
+
tags: string[];
|
|
14
|
+
created_at?: string;
|
|
15
|
+
updated_at?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ParameterDefinition {
|
|
18
|
+
required: boolean;
|
|
19
|
+
default?: any;
|
|
20
|
+
description?: string;
|
|
21
|
+
param_type?: string;
|
|
22
|
+
}
|
|
23
|
+
export type FunctionStageConfig = {
|
|
24
|
+
type: "FindAll";
|
|
25
|
+
collection: string;
|
|
26
|
+
} | {
|
|
27
|
+
type: "Query";
|
|
28
|
+
collection: string;
|
|
29
|
+
filter?: Record<string, any>;
|
|
30
|
+
sort?: SortFieldConfig[];
|
|
31
|
+
limit?: number;
|
|
32
|
+
skip?: number;
|
|
33
|
+
} | {
|
|
34
|
+
type: "Project";
|
|
35
|
+
fields: string[];
|
|
36
|
+
exclude: boolean;
|
|
37
|
+
} | {
|
|
38
|
+
type: "Group";
|
|
39
|
+
by_fields: string[];
|
|
40
|
+
functions: GroupFunctionConfig[];
|
|
41
|
+
} | {
|
|
42
|
+
type: "Count";
|
|
43
|
+
output_field: string;
|
|
44
|
+
} | {
|
|
45
|
+
type: "Filter";
|
|
46
|
+
filter: Record<string, any>;
|
|
47
|
+
} | {
|
|
48
|
+
type: "Sort";
|
|
49
|
+
sort: SortFieldConfig[];
|
|
50
|
+
} | {
|
|
51
|
+
type: "Limit";
|
|
52
|
+
limit: number;
|
|
53
|
+
} | {
|
|
54
|
+
type: "Skip";
|
|
55
|
+
skip: number;
|
|
56
|
+
} | {
|
|
57
|
+
type: "Insert";
|
|
58
|
+
collection: string;
|
|
59
|
+
record: Record<string, any>;
|
|
60
|
+
bypass_ripple?: boolean;
|
|
61
|
+
ttl?: number;
|
|
62
|
+
} | {
|
|
63
|
+
type: "Update";
|
|
64
|
+
collection: string;
|
|
65
|
+
filter: Record<string, any>;
|
|
66
|
+
updates: Record<string, any>;
|
|
67
|
+
bypass_ripple?: boolean;
|
|
68
|
+
ttl?: number;
|
|
69
|
+
} | {
|
|
70
|
+
type: "UpdateById";
|
|
71
|
+
collection: string;
|
|
72
|
+
record_id: string;
|
|
73
|
+
updates: Record<string, any>;
|
|
74
|
+
bypass_ripple?: boolean;
|
|
75
|
+
ttl?: number;
|
|
76
|
+
} | {
|
|
77
|
+
type: "Delete";
|
|
78
|
+
collection: string;
|
|
79
|
+
filter: Record<string, any>;
|
|
80
|
+
bypass_ripple?: boolean;
|
|
81
|
+
} | {
|
|
82
|
+
type: "DeleteById";
|
|
83
|
+
collection: string;
|
|
84
|
+
record_id: string;
|
|
85
|
+
bypass_ripple?: boolean;
|
|
86
|
+
} | {
|
|
87
|
+
type: "BatchInsert";
|
|
88
|
+
collection: string;
|
|
89
|
+
records: Record<string, any>[];
|
|
90
|
+
bypass_ripple?: boolean;
|
|
91
|
+
} | {
|
|
92
|
+
type: "BatchDelete";
|
|
93
|
+
collection: string;
|
|
94
|
+
record_ids: string[];
|
|
95
|
+
bypass_ripple?: boolean;
|
|
96
|
+
} | {
|
|
97
|
+
type: "HttpRequest";
|
|
98
|
+
url: string;
|
|
99
|
+
method?: string;
|
|
100
|
+
headers?: Record<string, string>;
|
|
101
|
+
body?: any;
|
|
102
|
+
} | {
|
|
103
|
+
type: "VectorSearch";
|
|
104
|
+
collection: string;
|
|
105
|
+
query_vector: number[];
|
|
106
|
+
limit?: number;
|
|
107
|
+
threshold?: number;
|
|
108
|
+
} | {
|
|
109
|
+
type: "TextSearch";
|
|
110
|
+
collection: string;
|
|
111
|
+
query_text: string;
|
|
112
|
+
fields?: string[];
|
|
113
|
+
limit?: number;
|
|
114
|
+
fuzzy?: boolean;
|
|
115
|
+
} | {
|
|
116
|
+
type: "HybridSearch";
|
|
117
|
+
collection: string;
|
|
118
|
+
query_text: string;
|
|
119
|
+
query_vector?: number[];
|
|
120
|
+
limit?: number;
|
|
121
|
+
} | {
|
|
122
|
+
type: "Chat";
|
|
123
|
+
messages: ChatMessage[];
|
|
124
|
+
model?: string;
|
|
125
|
+
temperature?: number;
|
|
126
|
+
max_tokens?: number;
|
|
127
|
+
} | {
|
|
128
|
+
type: "Embed";
|
|
129
|
+
input_field: string;
|
|
130
|
+
output_field: string;
|
|
131
|
+
model?: string;
|
|
132
|
+
};
|
|
133
|
+
export interface ChatMessage {
|
|
134
|
+
role: string;
|
|
135
|
+
content: string;
|
|
136
|
+
}
|
|
137
|
+
export declare const ChatMessage: {
|
|
138
|
+
system: (content: string) => ChatMessage;
|
|
139
|
+
user: (content: string) => ChatMessage;
|
|
140
|
+
assistant: (content: string) => ChatMessage;
|
|
141
|
+
};
|
|
142
|
+
export interface GroupFunctionConfig {
|
|
143
|
+
output_field: string;
|
|
144
|
+
operation: "Sum" | "Average" | "Count" | "Min" | "Max" | "First" | "Last" | "Push";
|
|
145
|
+
input_field?: string;
|
|
146
|
+
}
|
|
147
|
+
export interface SortFieldConfig {
|
|
148
|
+
field: string;
|
|
149
|
+
ascending: boolean;
|
|
150
|
+
}
|
|
151
|
+
export interface FunctionResult {
|
|
152
|
+
records: Record<string, any>[];
|
|
153
|
+
stats: FunctionStats;
|
|
154
|
+
}
|
|
155
|
+
export interface FunctionStats {
|
|
156
|
+
input_count: number;
|
|
157
|
+
output_count: number;
|
|
158
|
+
execution_time_ms: number;
|
|
159
|
+
stages_executed: number;
|
|
160
|
+
stage_stats: StageStats[];
|
|
161
|
+
}
|
|
162
|
+
export interface StageStats {
|
|
163
|
+
stage: string;
|
|
164
|
+
input_count: number;
|
|
165
|
+
output_count: number;
|
|
166
|
+
execution_time_ms: number;
|
|
167
|
+
}
|
|
168
|
+
export declare const Stage: {
|
|
169
|
+
findAll: (collection: string) => FunctionStageConfig;
|
|
170
|
+
query: (collection: string, filter?: Record<string, any>, sort?: SortFieldConfig[], limit?: number, skip?: number) => FunctionStageConfig;
|
|
171
|
+
project: (fields: string[], exclude?: boolean) => FunctionStageConfig;
|
|
172
|
+
group: (by_fields: string[], functions: GroupFunctionConfig[]) => FunctionStageConfig;
|
|
173
|
+
count: (output_field?: string) => FunctionStageConfig;
|
|
174
|
+
insert: (collection: string, record: Record<string, any>, bypassRipple?: boolean, ttl?: number) => FunctionStageConfig;
|
|
175
|
+
update: (collection: string, filter: Record<string, any>, updates: Record<string, any>, bypassRipple?: boolean, ttl?: number) => FunctionStageConfig;
|
|
176
|
+
updateById: (collection: string, record_id: string, updates: Record<string, any>, bypassRipple?: boolean, ttl?: number) => FunctionStageConfig;
|
|
177
|
+
delete: (collection: string, filter: Record<string, any>, bypassRipple?: boolean) => FunctionStageConfig;
|
|
178
|
+
deleteById: (collection: string, record_id: string, bypassRipple?: boolean) => FunctionStageConfig;
|
|
179
|
+
batchInsert: (collection: string, records: Record<string, any>[], bypassRipple?: boolean) => FunctionStageConfig;
|
|
180
|
+
batchDelete: (collection: string, record_ids: string[], bypassRipple?: boolean) => FunctionStageConfig;
|
|
181
|
+
filter: (filter: Record<string, any>) => FunctionStageConfig;
|
|
182
|
+
sort: (sort: SortFieldConfig[]) => FunctionStageConfig;
|
|
183
|
+
limit: (limit: number) => FunctionStageConfig;
|
|
184
|
+
skip: (skip: number) => FunctionStageConfig;
|
|
185
|
+
httpRequest: (url: string, method?: string, headers?: Record<string, string>, body?: any) => FunctionStageConfig;
|
|
186
|
+
vectorSearch: (collection: string, query_vector: number[], limit?: number, threshold?: number) => FunctionStageConfig;
|
|
187
|
+
textSearch: (collection: string, query_text: string, options?: {
|
|
188
|
+
fields?: string[];
|
|
189
|
+
limit?: number;
|
|
190
|
+
fuzzy?: boolean;
|
|
191
|
+
}) => FunctionStageConfig;
|
|
192
|
+
hybridSearch: (collection: string, query_text: string, query_vector?: number[], limit?: number) => FunctionStageConfig;
|
|
193
|
+
chat: (messages: ChatMessage[], model?: string, temperature?: number, max_tokens?: number) => FunctionStageConfig;
|
|
194
|
+
embed: (input_field: string, output_field: string, model?: string) => FunctionStageConfig;
|
|
195
|
+
};
|