@ekodb/ekodb-client 0.11.0 → 0.13.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 CHANGED
@@ -40,8 +40,6 @@ export interface ClientConfig {
40
40
  shouldRetry?: boolean;
41
41
  /** Maximum number of retry attempts (default: 3) */
42
42
  maxRetries?: number;
43
- /** Request timeout in milliseconds (default: 30000) */
44
- timeout?: number;
45
43
  /** Serialization format (default: MessagePack for best performance, use Json for debugging) */
46
44
  format?: SerializationFormat;
47
45
  }
@@ -110,6 +108,24 @@ export interface BatchDeleteOptions {
110
108
  bypassRipple?: boolean;
111
109
  transactionId?: string;
112
110
  }
111
+ export interface DistinctValuesOptions {
112
+ /** Optional filter expression (same format as find() filter). */
113
+ filter?: any;
114
+ /** Bypass ripple propagation for this query. */
115
+ bypassRipple?: boolean;
116
+ /** Bypass cache for this query. */
117
+ bypassCache?: boolean;
118
+ }
119
+ export interface DistinctValuesResponse {
120
+ /** Collection that was queried. */
121
+ collection: string;
122
+ /** Field whose distinct values were returned. */
123
+ field: string;
124
+ /** Unique values, sorted alphabetically. */
125
+ values: any[];
126
+ /** Number of distinct values. */
127
+ count: number;
128
+ }
113
129
  export interface CollectionConfig {
114
130
  collection_name: string;
115
131
  fields?: string[];
@@ -123,6 +139,18 @@ export interface ChatRequest {
123
139
  system_prompt?: string;
124
140
  bypass_ripple?: boolean;
125
141
  }
142
+ export interface ToolChoice {
143
+ type: "auto" | "none" | "required" | "tool";
144
+ name?: string;
145
+ }
146
+ export interface ToolConfig {
147
+ enabled: boolean;
148
+ allowed_tools?: string[];
149
+ allowed_collections?: string[];
150
+ max_iterations?: number;
151
+ allow_write_operations?: boolean;
152
+ tool_choice?: ToolChoice;
153
+ }
126
154
  export interface CreateChatSessionRequest {
127
155
  collections: CollectionConfig[];
128
156
  llm_provider: string;
@@ -132,11 +160,16 @@ export interface CreateChatSessionRequest {
132
160
  parent_id?: string;
133
161
  branch_point_idx?: number;
134
162
  max_context_messages?: number;
163
+ max_tokens?: number;
164
+ temperature?: number;
165
+ tool_config?: ToolConfig;
135
166
  }
136
167
  export interface ChatMessageRequest {
137
168
  message: string;
138
169
  bypass_ripple?: boolean;
139
170
  force_summarize?: boolean;
171
+ max_iterations?: number;
172
+ tool_config?: ToolConfig;
140
173
  }
141
174
  export interface TokenUsage {
142
175
  prompt_tokens: number;
@@ -195,16 +228,21 @@ export interface UpdateSessionRequest {
195
228
  llm_model?: string;
196
229
  collections?: CollectionConfig[];
197
230
  max_context_messages?: number;
231
+ bypass_ripple?: boolean;
232
+ title?: string;
233
+ memory?: any;
198
234
  }
199
235
  export declare enum MergeStrategy {
200
236
  Chronological = "Chronological",
201
237
  Summarized = "Summarized",
202
- LatestOnly = "LatestOnly"
238
+ LatestOnly = "LatestOnly",
239
+ Interleaved = "Interleaved"
203
240
  }
204
241
  export interface MergeSessionsRequest {
205
242
  source_chat_ids: string[];
206
243
  target_chat_id: string;
207
244
  merge_strategy: MergeStrategy;
245
+ bypass_ripple?: boolean;
208
246
  }
209
247
  /**
210
248
  * Available chat models by provider
@@ -214,6 +252,38 @@ export interface ChatModels {
214
252
  anthropic: string[];
215
253
  perplexity: string[];
216
254
  }
255
+ /**
256
+ * Request to generate embeddings
257
+ */
258
+ export interface EmbedRequest {
259
+ text?: string;
260
+ texts?: string[];
261
+ model?: string;
262
+ }
263
+ /**
264
+ * Response from embedding generation
265
+ */
266
+ export interface EmbedResponse {
267
+ embeddings: number[][];
268
+ model: string;
269
+ dimensions: number;
270
+ }
271
+ /**
272
+ * Request for stateless raw LLM completion — no session, no history, no RAG.
273
+ */
274
+ export interface RawCompletionRequest {
275
+ system_prompt: string;
276
+ message: string;
277
+ provider?: string;
278
+ model?: string;
279
+ max_tokens?: number;
280
+ }
281
+ /**
282
+ * Response from a raw LLM completion request.
283
+ */
284
+ export interface RawCompletionResponse {
285
+ content: string;
286
+ }
217
287
  /**
218
288
  * User function definition - reusable sequence of Functions that can be called by Scripts
219
289
  */
@@ -252,7 +322,6 @@ export declare class EkoDBClient {
252
322
  private token;
253
323
  private shouldRetry;
254
324
  private maxRetries;
255
- private timeout;
256
325
  private format;
257
326
  private rateLimitInfo;
258
327
  constructor(config: string | ClientConfig, apiKey?: string);
@@ -271,7 +340,17 @@ export declare class EkoDBClient {
271
340
  /**
272
341
  * Refresh the authentication token
273
342
  */
274
- private refreshToken;
343
+ refreshToken(): Promise<void>;
344
+ /**
345
+ * Get the current authentication token.
346
+ * Returns null if not yet authenticated. Call refreshToken() first.
347
+ */
348
+ getToken(): string | null;
349
+ /**
350
+ * Clear the cached authentication token.
351
+ * The next request will trigger a fresh token exchange.
352
+ */
353
+ clearTokenCache(): void;
275
354
  /**
276
355
  * Extract rate limit information from response headers
277
356
  */
@@ -324,6 +403,14 @@ export declare class EkoDBClient {
324
403
  * Find a document by ID
325
404
  */
326
405
  findById(collection: string, id: string): Promise<Record>;
406
+ /**
407
+ * Find a document by ID with field projection
408
+ * @param collection - Collection name
409
+ * @param id - Document ID
410
+ * @param selectFields - Fields to include in the result
411
+ * @param excludeFields - Fields to exclude from the result
412
+ */
413
+ findByIdWithProjection(collection: string, id: string, selectFields?: string[], excludeFields?: string[]): Promise<Record>;
327
414
  /**
328
415
  * Update a document
329
416
  * @param collection - Collection name
@@ -332,6 +419,31 @@ export declare class EkoDBClient {
332
419
  * @param options - Optional parameters (bypassRipple, transactionId, bypassCache, selectFields, excludeFields)
333
420
  */
334
421
  update(collection: string, id: string, record: Record, options?: UpdateOptions): Promise<Record>;
422
+ /**
423
+ * Apply an atomic field action to a single field of a record.
424
+ *
425
+ * Use this instead of `update()` for safe concurrent modifications like
426
+ * incrementing counters, pushing to arrays, or arithmetic operations.
427
+ *
428
+ * @param collection - Collection name
429
+ * @param id - Record ID
430
+ * @param action - The atomic action: increment, decrement, multiply, divide, modulo,
431
+ * push, pop, shift, unshift, remove, append, clear
432
+ * @param field - The field name to apply the action to
433
+ * @param value - The value for the action (omit for pop/shift/clear)
434
+ */
435
+ updateWithAction(collection: string, id: string, action: string, field: string, value?: any): Promise<Record>;
436
+ /**
437
+ * Apply a sequence of atomic field actions to a record in a single request.
438
+ *
439
+ * All actions are applied atomically — the record is fetched once, all actions
440
+ * run in order, and the result is persisted in a single update.
441
+ *
442
+ * @param collection - Collection name
443
+ * @param id - Record ID
444
+ * @param actions - Array of [action, field, value] tuples
445
+ */
446
+ updateWithActionSequence(collection: string, id: string, actions: [string, string, any][]): Promise<Record>;
335
447
  /**
336
448
  * Delete a document
337
449
  * @param collection - Collection name
@@ -619,6 +731,27 @@ export declare class EkoDBClient {
619
731
  * ```
620
732
  */
621
733
  search(collection: string, query: SearchQuery): Promise<SearchResponse>;
734
+ /**
735
+ * Get distinct (unique) values for a field across all records in a collection.
736
+ *
737
+ * Results are deduplicated and sorted alphabetically. Supports an optional filter
738
+ * to restrict which records are examined.
739
+ *
740
+ * @param collection - Collection name
741
+ * @param field - Field to get distinct values for
742
+ * @param options - Optional filter and bypass flags
743
+ *
744
+ * @example
745
+ * // All distinct statuses
746
+ * const resp = await client.distinctValues("orders", "status");
747
+ * console.log(resp.values); // ["active", "cancelled", "shipped"]
748
+ *
749
+ * // Only statuses for US orders
750
+ * const resp = await client.distinctValues("orders", "status", {
751
+ * filter: { type: "Condition", content: { field: "region", operator: "Eq", value: "us" } }
752
+ * });
753
+ */
754
+ distinctValues(collection: string, field: string, options?: DistinctValuesOptions): Promise<DistinctValuesResponse>;
622
755
  /**
623
756
  * Health check - verify the ekoDB server is responding
624
757
  */
@@ -627,6 +760,23 @@ export declare class EkoDBClient {
627
760
  * Create a new chat session
628
761
  */
629
762
  createChatSession(request: CreateChatSessionRequest): Promise<ChatResponse>;
763
+ /**
764
+ * Stateless raw LLM completion — no session, no history, no RAG.
765
+ *
766
+ * Sends a system prompt and user message directly to the LLM via ekoDB
767
+ * and returns the raw text response without any context injection or
768
+ * conversation management. Use this for structured-output tasks such as
769
+ * planning where the response must be parsed programmatically.
770
+ *
771
+ * @example
772
+ * const resp = await client.rawCompletion({
773
+ * system_prompt: "You are a helpful assistant.",
774
+ * message: "Summarize this in JSON.",
775
+ * max_tokens: 2048,
776
+ * });
777
+ * console.log(resp.content);
778
+ */
779
+ rawCompletion(request: RawCompletionRequest): Promise<RawCompletionResponse>;
630
780
  /**
631
781
  * Send a message in an existing chat session
632
782
  */
@@ -680,6 +830,12 @@ export declare class EkoDBClient {
680
830
  * @returns ChatModels object with models organized by provider
681
831
  */
682
832
  getChatModels(): Promise<ChatModels>;
833
+ /**
834
+ * Get all built-in server-side chat tool definitions.
835
+ * Returns a list of tool objects with name, description, and parameters fields.
836
+ * Used by planning agents to discover available tools dynamically.
837
+ */
838
+ getChatTools(): Promise<object[]>;
683
839
  /**
684
840
  * Get available models for a specific provider
685
841
  * @param provider - Provider name (e.g., "openai", "anthropic", "perplexity")
@@ -765,13 +921,7 @@ export declare class EkoDBClient {
765
921
  */
766
922
  websocket(wsURL: string): WebSocketClient;
767
923
  /**
768
- * Generate embeddings for text using ekoDB's native Functions
769
- *
770
- * This helper simplifies embedding generation by:
771
- * 1. Creating a temporary collection with the text
772
- * 2. Running a Script with FindAll + Embed Functions
773
- * 3. Extracting and returning the embedding vector
774
- * 4. Cleaning up temporary resources
924
+ * Generate embeddings for a single text
775
925
  *
776
926
  * @param text - The text to generate embeddings for
777
927
  * @param model - The embedding model to use (e.g., "text-embedding-3-small")
@@ -787,6 +937,18 @@ export declare class EkoDBClient {
787
937
  * ```
788
938
  */
789
939
  embed(text: string, model: string): Promise<number[]>;
940
+ /**
941
+ * Generate embeddings for multiple texts in a single batch request
942
+ *
943
+ * @param texts - Array of texts to generate embeddings for
944
+ * @param model - The embedding model to use
945
+ * @returns Array of embedding vectors
946
+ */
947
+ embedBatch(texts: string[], model: string): Promise<number[][]>;
948
+ /**
949
+ * Internal: make embed API request
950
+ */
951
+ private embedRequest;
790
952
  /**
791
953
  * Perform text search without embeddings
792
954
  *
@@ -852,24 +1014,110 @@ export declare class EkoDBClient {
852
1014
  */
853
1015
  findAllWithLimit(collection: string, limit: number): Promise<Record[]>;
854
1016
  }
1017
+ /** Mutation notification from a subscription. */
1018
+ export interface MutationNotification {
1019
+ collection: string;
1020
+ event: string;
1021
+ recordIds: string[];
1022
+ records?: any;
1023
+ timestamp: string;
1024
+ }
1025
+ /** A chunk/event from a streaming chat response. */
1026
+ export type ChatStreamEvent = {
1027
+ type: "chunk";
1028
+ content: string;
1029
+ } | {
1030
+ type: "end";
1031
+ messageId: string;
1032
+ tokenUsage?: any;
1033
+ toolCallHistory?: any;
1034
+ executionTimeMs: number;
1035
+ } | {
1036
+ type: "toolCall";
1037
+ chatId: string;
1038
+ callId: string;
1039
+ toolName: string;
1040
+ arguments: any;
1041
+ } | {
1042
+ type: "error";
1043
+ error: string;
1044
+ };
1045
+ /** Definition for a client-side tool the LLM can call. */
1046
+ export interface ClientToolDefinition {
1047
+ name: string;
1048
+ description: string;
1049
+ parameters: any;
1050
+ }
1051
+ /** Options for chatSend. */
1052
+ export interface ChatSendOptions {
1053
+ bypassRipple?: boolean;
1054
+ clientTools?: ClientToolDefinition[];
1055
+ maxIterations?: number;
1056
+ confirmTools?: string[];
1057
+ excludeTools?: string[];
1058
+ }
1059
+ /** Options for subscribe. */
1060
+ export interface SubscribeOptions {
1061
+ filterField?: string;
1062
+ filterValue?: string;
1063
+ }
1064
+ /** EventEmitter-like interface for subscriptions and chat streams. */
1065
+ export declare class EventStream<_T = unknown> {
1066
+ private listeners;
1067
+ private _closed;
1068
+ on(event: string, listener: (data: any) => void): this;
1069
+ /** @internal */
1070
+ emit(event: string, data?: any): void;
1071
+ get closed(): boolean;
1072
+ /** @internal */
1073
+ close(): void;
1074
+ }
855
1075
  /**
856
- * WebSocket client for real-time queries
1076
+ * WebSocket client for real-time queries, subscriptions, and chat streaming.
857
1077
  */
858
1078
  export declare class WebSocketClient {
859
1079
  private wsURL;
860
1080
  private token;
861
1081
  private ws;
1082
+ private dispatcherRunning;
1083
+ private pendingRequests;
1084
+ private subscriptions;
1085
+ private chatStreams;
1086
+ private registerToolsAck;
862
1087
  constructor(wsURL: string, token: string);
1088
+ private messageCounter;
1089
+ private genMessageId;
863
1090
  /**
864
- * Connect to WebSocket
1091
+ * Connect and start the dispatcher.
865
1092
  */
866
- private connect;
1093
+ private ensureConnected;
1094
+ private spawnDispatcher;
1095
+ private routeMessage;
1096
+ private sendRequest;
867
1097
  /**
868
- * Find all records in a collection via WebSocket
1098
+ * Find all records in a collection via WebSocket.
869
1099
  */
870
1100
  findAll(collection: string): Promise<Record[]>;
871
1101
  /**
872
- * Close the WebSocket connection
1102
+ * Subscribe to mutation notifications on a collection.
1103
+ * Returns an EventStream that emits "mutation" events.
1104
+ */
1105
+ subscribe(collection: string, options?: SubscribeOptions): Promise<EventStream<MutationNotification>>;
1106
+ /**
1107
+ * Send a chat message and receive a streaming response.
1108
+ * Returns an EventStream that emits "event" with ChatStreamEvent objects.
1109
+ */
1110
+ chatSend(chatId: string, message: string, options?: ChatSendOptions): Promise<EventStream<ChatStreamEvent>>;
1111
+ /**
1112
+ * Register client-side tools for a chat session.
1113
+ */
1114
+ registerClientTools(chatId: string, tools: ClientToolDefinition[]): Promise<void>;
1115
+ /**
1116
+ * Send a tool result back to the server during a chat stream.
1117
+ */
1118
+ sendToolResult(chatId: string, callId: string, success: boolean, result?: any, error?: string): Promise<void>;
1119
+ /**
1120
+ * Close the WebSocket connection.
873
1121
  */
874
1122
  close(): void;
875
1123
  }