@ekodb/ekodb-client 0.12.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[];
@@ -252,6 +268,22 @@ export interface EmbedResponse {
252
268
  model: string;
253
269
  dimensions: number;
254
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
+ }
255
287
  /**
256
288
  * User function definition - reusable sequence of Functions that can be called by Scripts
257
289
  */
@@ -290,7 +322,6 @@ export declare class EkoDBClient {
290
322
  private token;
291
323
  private shouldRetry;
292
324
  private maxRetries;
293
- private timeout;
294
325
  private format;
295
326
  private rateLimitInfo;
296
327
  constructor(config: string | ClientConfig, apiKey?: string);
@@ -309,7 +340,17 @@ export declare class EkoDBClient {
309
340
  /**
310
341
  * Refresh the authentication token
311
342
  */
312
- 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;
313
354
  /**
314
355
  * Extract rate limit information from response headers
315
356
  */
@@ -362,6 +403,14 @@ export declare class EkoDBClient {
362
403
  * Find a document by ID
363
404
  */
364
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>;
365
414
  /**
366
415
  * Update a document
367
416
  * @param collection - Collection name
@@ -370,6 +419,31 @@ export declare class EkoDBClient {
370
419
  * @param options - Optional parameters (bypassRipple, transactionId, bypassCache, selectFields, excludeFields)
371
420
  */
372
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>;
373
447
  /**
374
448
  * Delete a document
375
449
  * @param collection - Collection name
@@ -657,6 +731,27 @@ export declare class EkoDBClient {
657
731
  * ```
658
732
  */
659
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>;
660
755
  /**
661
756
  * Health check - verify the ekoDB server is responding
662
757
  */
@@ -665,6 +760,23 @@ export declare class EkoDBClient {
665
760
  * Create a new chat session
666
761
  */
667
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>;
668
780
  /**
669
781
  * Send a message in an existing chat session
670
782
  */
@@ -718,6 +830,12 @@ export declare class EkoDBClient {
718
830
  * @returns ChatModels object with models organized by provider
719
831
  */
720
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[]>;
721
839
  /**
722
840
  * Get available models for a specific provider
723
841
  * @param provider - Provider name (e.g., "openai", "anthropic", "perplexity")
@@ -896,24 +1014,110 @@ export declare class EkoDBClient {
896
1014
  */
897
1015
  findAllWithLimit(collection: string, limit: number): Promise<Record[]>;
898
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
+ }
899
1075
  /**
900
- * WebSocket client for real-time queries
1076
+ * WebSocket client for real-time queries, subscriptions, and chat streaming.
901
1077
  */
902
1078
  export declare class WebSocketClient {
903
1079
  private wsURL;
904
1080
  private token;
905
1081
  private ws;
1082
+ private dispatcherRunning;
1083
+ private pendingRequests;
1084
+ private subscriptions;
1085
+ private chatStreams;
1086
+ private registerToolsAck;
906
1087
  constructor(wsURL: string, token: string);
1088
+ private messageCounter;
1089
+ private genMessageId;
907
1090
  /**
908
- * Connect to WebSocket
1091
+ * Connect and start the dispatcher.
909
1092
  */
910
- private connect;
1093
+ private ensureConnected;
1094
+ private spawnDispatcher;
1095
+ private routeMessage;
1096
+ private sendRequest;
911
1097
  /**
912
- * Find all records in a collection via WebSocket
1098
+ * Find all records in a collection via WebSocket.
913
1099
  */
914
1100
  findAll(collection: string): Promise<Record[]>;
915
1101
  /**
916
- * 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.
917
1121
  */
918
1122
  close(): void;
919
1123
  }