@ekodb/ekodb-client 0.13.0 → 0.15.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 CHANGED
@@ -348,6 +348,76 @@ for complete working examples:
348
348
  - `client_user_functions.ts` - User functions API
349
349
  - And more...
350
350
 
351
+ ### Goals, Tasks, and Agents
352
+
353
+ ```typescript
354
+ import { EkoDBClient } from "@ekodb/ekodb-client";
355
+
356
+ const client = new EkoDBClient("http://localhost:8080", "your-api-key");
357
+ await client.init();
358
+
359
+ // Goals
360
+ const goal = await client.goalCreate({
361
+ title: "Migrate data",
362
+ status: "active",
363
+ });
364
+ const goals = await client.goalList();
365
+ await client.goalComplete("goal-id", { summary: "Done" });
366
+ await client.goalApprove("goal-id");
367
+
368
+ // Tasks
369
+ const task = await client.taskCreate({
370
+ title: "Backup",
371
+ schedule: "0 0 * * *",
372
+ });
373
+ await client.taskStart("task-id");
374
+ await client.taskSucceed("task-id", { records: 1500 });
375
+
376
+ // Agents
377
+ const agent = await client.agentCreate({
378
+ name: "processor",
379
+ model: "gpt-4.1",
380
+ });
381
+ const agents = await client.agentList();
382
+ ```
383
+
384
+ ### Schedules
385
+
386
+ ```typescript
387
+ // Create a schedule
388
+ const sched = await client.createSchedule({
389
+ name: "nightly",
390
+ cron: "0 2 * * *",
391
+ });
392
+
393
+ // Pause a schedule
394
+ await client.pauseSchedule("sched-id");
395
+ ```
396
+
397
+ ### WebSocket Chat Streaming
398
+
399
+ ```typescript
400
+ const ws = client.websocket("ws://localhost:8080");
401
+
402
+ const stream = await ws.chatSend(chatId, "What is the capital of France?");
403
+ stream.on("event", (event) => {
404
+ switch (event.type) {
405
+ case "chunk":
406
+ process.stdout.write(event.content);
407
+ break;
408
+ case "end":
409
+ console.log(`\nDone (context: ${event.contextWindow} tokens)`);
410
+ break;
411
+ case "toolCall":
412
+ ws.sendToolResult(chatId, event.callId, true, result);
413
+ break;
414
+ case "error":
415
+ console.error(event.error);
416
+ break;
417
+ }
418
+ });
419
+ ```
420
+
351
421
  ## License
352
422
 
353
423
  MIT
package/dist/client.d.ts CHANGED
@@ -170,6 +170,7 @@ export interface ChatMessageRequest {
170
170
  force_summarize?: boolean;
171
171
  max_iterations?: number;
172
172
  tool_config?: ToolConfig;
173
+ llm_model?: string;
173
174
  }
174
175
  export interface TokenUsage {
175
176
  prompt_tokens: number;
@@ -320,6 +321,7 @@ export declare class EkoDBClient {
320
321
  private baseURL;
321
322
  private apiKey;
322
323
  private token;
324
+ private tokenExpiry;
323
325
  private shouldRetry;
324
326
  private maxRetries;
325
327
  private format;
@@ -342,15 +344,24 @@ export declare class EkoDBClient {
342
344
  */
343
345
  refreshToken(): Promise<void>;
344
346
  /**
345
- * Get the current authentication token.
346
- * Returns null if not yet authenticated. Call refreshToken() first.
347
+ * Get a valid authentication token.
348
+ *
349
+ * Returns a cached token if it has more than 60s of validity remaining.
350
+ * Otherwise fetches a new one via refreshToken(). This means callers
351
+ * never need to handle token refresh themselves — every getToken() call
352
+ * returns a token that's valid for at least 60 more seconds.
347
353
  */
348
- getToken(): string | null;
354
+ getToken(): Promise<string | null>;
349
355
  /**
350
- * Clear the cached authentication token.
356
+ * Clear the cached authentication token and expiry.
351
357
  * The next request will trigger a fresh token exchange.
352
358
  */
353
359
  clearTokenCache(): void;
360
+ /**
361
+ * Extract the `exp` claim from a JWT without verifying the signature.
362
+ * Returns the Unix timestamp (seconds) of expiry, or null if parsing fails.
363
+ */
364
+ private extractJWTExpiry;
354
365
  /**
355
366
  * Extract rate limit information from response headers
356
367
  */
@@ -756,6 +767,20 @@ export declare class EkoDBClient {
756
767
  * Health check - verify the ekoDB server is responding
757
768
  */
758
769
  health(): Promise<boolean>;
770
+ /**
771
+ * Execute a tool via ekoDB's server-side tool pipeline.
772
+ *
773
+ * Calls POST /api/chat/tools/execute which goes through the same
774
+ * execute_tool function as the LLM tool-calling loop — with all
775
+ * collection filtering, permission enforcement, and internal collection
776
+ * blocking. No LLM round-trip.
777
+ *
778
+ * @returns The tool result if executed, or null if the server doesn't
779
+ * support the endpoint (older ekoDB versions).
780
+ */
781
+ executeTool(toolName: string, params: {
782
+ [key: string]: any;
783
+ }, chatId?: string): Promise<any | null>;
759
784
  /**
760
785
  * Create a new chat session
761
786
  */
@@ -777,10 +802,37 @@ export declare class EkoDBClient {
777
802
  * console.log(resp.content);
778
803
  */
779
804
  rawCompletion(request: RawCompletionRequest): Promise<RawCompletionResponse>;
805
+ /**
806
+ * Stateless raw LLM completion via SSE streaming.
807
+ *
808
+ * Same as rawCompletion() but uses Server-Sent Events to keep the
809
+ * connection alive. Preferred for deployed instances where reverse proxies
810
+ * may kill idle HTTP connections before the LLM responds.
811
+ */
812
+ rawCompletionStream(request: RawCompletionRequest): Promise<RawCompletionResponse>;
813
+ /**
814
+ * Stateless raw LLM completion via SSE streaming with token-level progress.
815
+ *
816
+ * Same as rawCompletionStream() but invokes `onToken` with each token as it
817
+ * arrives, allowing callers to show real-time progress.
818
+ */
819
+ rawCompletionStreamWithProgress(request: RawCompletionRequest, onToken: (token: string) => void): Promise<RawCompletionResponse>;
780
820
  /**
781
821
  * Send a message in an existing chat session
782
822
  */
783
823
  chatMessage(sessionId: string, request: ChatMessageRequest): Promise<ChatResponse>;
824
+ /**
825
+ * Send a message in an existing chat session via SSE streaming.
826
+ *
827
+ * Returns an EventStream that emits ChatStreamEvent objects as they arrive:
828
+ * - `{ type: "chunk", content: "..." }` for each token
829
+ * - `{ type: "end", messageId, executionTimeMs, tokenUsage?, contextWindow? }` when complete
830
+ * - `{ type: "error", error: "..." }` on failure
831
+ *
832
+ * Preferred over chatMessage() for long-running responses where reverse
833
+ * proxies may kill idle HTTP connections before the LLM responds.
834
+ */
835
+ chatMessageStream(chatId: string, request: ChatMessageRequest): EventStream<ChatStreamEvent>;
784
836
  /**
785
837
  * Get a chat session by ID
786
838
  */
@@ -904,6 +956,96 @@ export declare class EkoDBClient {
904
956
  * @param label - The user function label
905
957
  */
906
958
  deleteUserFunction(label: string): Promise<void>;
959
+ /** Create a new goal */
960
+ goalCreate(data: Record): Promise<Record>;
961
+ /** List all goals */
962
+ goalList(): Promise<Record>;
963
+ /** Get a goal by ID */
964
+ goalGet(id: string): Promise<Record>;
965
+ /** Update a goal by ID */
966
+ goalUpdate(id: string, data: Record): Promise<Record>;
967
+ /** Delete a goal by ID */
968
+ goalDelete(id: string): Promise<void>;
969
+ /** Create a new goal template */
970
+ goalTemplateCreate(data: Record): Promise<Record>;
971
+ /** List all goal templates */
972
+ goalTemplateList(): Promise<Record>;
973
+ /** Get a goal template by ID */
974
+ goalTemplateGet(id: string): Promise<Record>;
975
+ /** Update a goal template by ID */
976
+ goalTemplateUpdate(id: string, data: Record): Promise<Record>;
977
+ /** Delete a goal template by ID */
978
+ goalTemplateDelete(id: string): Promise<void>;
979
+ /** Search goals */
980
+ goalSearch(query: string): Promise<Record>;
981
+ /** Mark a goal as complete (status -> pending_review) */
982
+ goalComplete(id: string, data: Record): Promise<Record>;
983
+ /** Approve a goal (status -> in_progress) */
984
+ goalApprove(id: string): Promise<Record>;
985
+ /** Reject a goal (status -> failed) */
986
+ goalReject(id: string, data: Record): Promise<Record>;
987
+ /** Start a goal step (status -> in_progress) */
988
+ goalStepStart(id: string, stepIndex: number): Promise<Record>;
989
+ /** Complete a goal step with result */
990
+ goalStepComplete(id: string, stepIndex: number, data: Record): Promise<Record>;
991
+ /** Fail a goal step with error */
992
+ goalStepFail(id: string, stepIndex: number, data: Record): Promise<Record>;
993
+ /** Create a new scheduled task */
994
+ taskCreate(data: Record): Promise<Record>;
995
+ /** List all scheduled tasks */
996
+ taskList(): Promise<Record>;
997
+ /** Get a task by ID */
998
+ taskGet(id: string): Promise<Record>;
999
+ /** Update a task by ID */
1000
+ taskUpdate(id: string, data: Record): Promise<Record>;
1001
+ /** Delete a task by ID */
1002
+ taskDelete(id: string): Promise<void>;
1003
+ /** Get tasks that are due at the given time */
1004
+ taskDue(now: string): Promise<Record>;
1005
+ /** Start a task (status -> running) */
1006
+ taskStart(id: string): Promise<Record>;
1007
+ /** Mark a task as succeeded */
1008
+ taskSucceed(id: string, data: Record): Promise<Record>;
1009
+ /** Mark a task as failed */
1010
+ taskFail(id: string, data: Record): Promise<Record>;
1011
+ /** Pause a task */
1012
+ taskPause(id: string): Promise<Record>;
1013
+ /** Resume a paused task */
1014
+ taskResume(id: string, data: Record): Promise<Record>;
1015
+ /** Create a new agent */
1016
+ agentCreate(data: Record): Promise<Record>;
1017
+ /** List all agents */
1018
+ agentList(): Promise<Record>;
1019
+ /** Get an agent by ID */
1020
+ agentGet(id: string): Promise<Record>;
1021
+ /** Get an agent by name */
1022
+ agentGetByName(name: string): Promise<Record>;
1023
+ /** Update an agent by ID */
1024
+ agentUpdate(id: string, data: Record): Promise<Record>;
1025
+ /** Delete an agent by ID */
1026
+ agentDelete(id: string): Promise<void>;
1027
+ /** Get agents by deployment ID */
1028
+ agentsByDeployment(deploymentId: string): Promise<Record>;
1029
+ /** Get documents linked to a KV key */
1030
+ kvGetLinks(key: string): Promise<Record>;
1031
+ /** Link a document to a KV key */
1032
+ kvLink(key: string, collection: string, documentId: string): Promise<Record>;
1033
+ /** Unlink a document from a KV key */
1034
+ kvUnlink(key: string, collection: string, documentId: string): Promise<Record>;
1035
+ /** Create a new schedule */
1036
+ createSchedule(data: Record): Promise<Record>;
1037
+ /** List all schedules */
1038
+ listSchedules(): Promise<Record>;
1039
+ /** Get a schedule by ID */
1040
+ getSchedule(id: string): Promise<Record>;
1041
+ /** Update a schedule */
1042
+ updateSchedule(id: string, data: Record): Promise<Record>;
1043
+ /** Delete a schedule */
1044
+ deleteSchedule(id: string): Promise<void>;
1045
+ /** Pause a schedule */
1046
+ pauseSchedule(id: string): Promise<Record>;
1047
+ /** Resume a schedule */
1048
+ resumeSchedule(id: string): Promise<Record>;
907
1049
  /**
908
1050
  * Check if a collection exists
909
1051
  * @param collection - Collection name to check
@@ -1032,6 +1174,8 @@ export type ChatStreamEvent = {
1032
1174
  tokenUsage?: any;
1033
1175
  toolCallHistory?: any;
1034
1176
  executionTimeMs: number;
1177
+ /** Model's context window size in tokens. */
1178
+ contextWindow?: number;
1035
1179
  } | {
1036
1180
  type: "toolCall";
1037
1181
  chatId: string;
@@ -1116,6 +1260,15 @@ export declare class WebSocketClient {
1116
1260
  * Send a tool result back to the server during a chat stream.
1117
1261
  */
1118
1262
  sendToolResult(chatId: string, callId: string, success: boolean, result?: any, error?: string): Promise<void>;
1263
+ /**
1264
+ * Stateless raw LLM completion via WebSocket.
1265
+ *
1266
+ * Sends a RawComplete message and waits for the Success response.
1267
+ * Preferred over HTTP for deployed instances: the persistent WSS
1268
+ * connection is already authenticated and won't be killed by reverse
1269
+ * proxy timeouts.
1270
+ */
1271
+ rawCompletion(request: RawCompletionRequest): Promise<RawCompletionResponse>;
1119
1272
  /**
1120
1273
  * Close the WebSocket connection.
1121
1274
  */