@ekodb/ekodb-client 0.13.0 → 0.14.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
@@ -320,6 +320,7 @@ export declare class EkoDBClient {
320
320
  private baseURL;
321
321
  private apiKey;
322
322
  private token;
323
+ private tokenExpiry;
323
324
  private shouldRetry;
324
325
  private maxRetries;
325
326
  private format;
@@ -342,15 +343,24 @@ export declare class EkoDBClient {
342
343
  */
343
344
  refreshToken(): Promise<void>;
344
345
  /**
345
- * Get the current authentication token.
346
- * Returns null if not yet authenticated. Call refreshToken() first.
346
+ * Get a valid authentication token.
347
+ *
348
+ * Returns a cached token if it has more than 60s of validity remaining.
349
+ * Otherwise fetches a new one via refreshToken(). This means callers
350
+ * never need to handle token refresh themselves — every getToken() call
351
+ * returns a token that's valid for at least 60 more seconds.
347
352
  */
348
- getToken(): string | null;
353
+ getToken(): Promise<string | null>;
349
354
  /**
350
- * Clear the cached authentication token.
355
+ * Clear the cached authentication token and expiry.
351
356
  * The next request will trigger a fresh token exchange.
352
357
  */
353
358
  clearTokenCache(): void;
359
+ /**
360
+ * Extract the `exp` claim from a JWT without verifying the signature.
361
+ * Returns the Unix timestamp (seconds) of expiry, or null if parsing fails.
362
+ */
363
+ private extractJWTExpiry;
354
364
  /**
355
365
  * Extract rate limit information from response headers
356
366
  */
@@ -777,10 +787,37 @@ export declare class EkoDBClient {
777
787
  * console.log(resp.content);
778
788
  */
779
789
  rawCompletion(request: RawCompletionRequest): Promise<RawCompletionResponse>;
790
+ /**
791
+ * Stateless raw LLM completion via SSE streaming.
792
+ *
793
+ * Same as rawCompletion() but uses Server-Sent Events to keep the
794
+ * connection alive. Preferred for deployed instances where reverse proxies
795
+ * may kill idle HTTP connections before the LLM responds.
796
+ */
797
+ rawCompletionStream(request: RawCompletionRequest): Promise<RawCompletionResponse>;
798
+ /**
799
+ * Stateless raw LLM completion via SSE streaming with token-level progress.
800
+ *
801
+ * Same as rawCompletionStream() but invokes `onToken` with each token as it
802
+ * arrives, allowing callers to show real-time progress.
803
+ */
804
+ rawCompletionStreamWithProgress(request: RawCompletionRequest, onToken: (token: string) => void): Promise<RawCompletionResponse>;
780
805
  /**
781
806
  * Send a message in an existing chat session
782
807
  */
783
808
  chatMessage(sessionId: string, request: ChatMessageRequest): Promise<ChatResponse>;
809
+ /**
810
+ * Send a message in an existing chat session via SSE streaming.
811
+ *
812
+ * Returns an EventStream that emits ChatStreamEvent objects as they arrive:
813
+ * - `{ type: "chunk", content: "..." }` for each token
814
+ * - `{ type: "end", messageId, executionTimeMs, tokenUsage?, contextWindow? }` when complete
815
+ * - `{ type: "error", error: "..." }` on failure
816
+ *
817
+ * Preferred over chatMessage() for long-running responses where reverse
818
+ * proxies may kill idle HTTP connections before the LLM responds.
819
+ */
820
+ chatMessageStream(chatId: string, request: ChatMessageRequest): EventStream<ChatStreamEvent>;
784
821
  /**
785
822
  * Get a chat session by ID
786
823
  */
@@ -904,6 +941,96 @@ export declare class EkoDBClient {
904
941
  * @param label - The user function label
905
942
  */
906
943
  deleteUserFunction(label: string): Promise<void>;
944
+ /** Create a new goal */
945
+ goalCreate(data: Record): Promise<Record>;
946
+ /** List all goals */
947
+ goalList(): Promise<Record>;
948
+ /** Get a goal by ID */
949
+ goalGet(id: string): Promise<Record>;
950
+ /** Update a goal by ID */
951
+ goalUpdate(id: string, data: Record): Promise<Record>;
952
+ /** Delete a goal by ID */
953
+ goalDelete(id: string): Promise<void>;
954
+ /** Create a new goal template */
955
+ goalTemplateCreate(data: Record): Promise<Record>;
956
+ /** List all goal templates */
957
+ goalTemplateList(): Promise<Record>;
958
+ /** Get a goal template by ID */
959
+ goalTemplateGet(id: string): Promise<Record>;
960
+ /** Update a goal template by ID */
961
+ goalTemplateUpdate(id: string, data: Record): Promise<Record>;
962
+ /** Delete a goal template by ID */
963
+ goalTemplateDelete(id: string): Promise<void>;
964
+ /** Search goals */
965
+ goalSearch(query: string): Promise<Record>;
966
+ /** Mark a goal as complete (status -> pending_review) */
967
+ goalComplete(id: string, data: Record): Promise<Record>;
968
+ /** Approve a goal (status -> in_progress) */
969
+ goalApprove(id: string): Promise<Record>;
970
+ /** Reject a goal (status -> failed) */
971
+ goalReject(id: string, data: Record): Promise<Record>;
972
+ /** Start a goal step (status -> in_progress) */
973
+ goalStepStart(id: string, stepIndex: number): Promise<Record>;
974
+ /** Complete a goal step with result */
975
+ goalStepComplete(id: string, stepIndex: number, data: Record): Promise<Record>;
976
+ /** Fail a goal step with error */
977
+ goalStepFail(id: string, stepIndex: number, data: Record): Promise<Record>;
978
+ /** Create a new scheduled task */
979
+ taskCreate(data: Record): Promise<Record>;
980
+ /** List all scheduled tasks */
981
+ taskList(): Promise<Record>;
982
+ /** Get a task by ID */
983
+ taskGet(id: string): Promise<Record>;
984
+ /** Update a task by ID */
985
+ taskUpdate(id: string, data: Record): Promise<Record>;
986
+ /** Delete a task by ID */
987
+ taskDelete(id: string): Promise<void>;
988
+ /** Get tasks that are due at the given time */
989
+ taskDue(now: string): Promise<Record>;
990
+ /** Start a task (status -> running) */
991
+ taskStart(id: string): Promise<Record>;
992
+ /** Mark a task as succeeded */
993
+ taskSucceed(id: string, data: Record): Promise<Record>;
994
+ /** Mark a task as failed */
995
+ taskFail(id: string, data: Record): Promise<Record>;
996
+ /** Pause a task */
997
+ taskPause(id: string): Promise<Record>;
998
+ /** Resume a paused task */
999
+ taskResume(id: string, data: Record): Promise<Record>;
1000
+ /** Create a new agent */
1001
+ agentCreate(data: Record): Promise<Record>;
1002
+ /** List all agents */
1003
+ agentList(): Promise<Record>;
1004
+ /** Get an agent by ID */
1005
+ agentGet(id: string): Promise<Record>;
1006
+ /** Get an agent by name */
1007
+ agentGetByName(name: string): Promise<Record>;
1008
+ /** Update an agent by ID */
1009
+ agentUpdate(id: string, data: Record): Promise<Record>;
1010
+ /** Delete an agent by ID */
1011
+ agentDelete(id: string): Promise<void>;
1012
+ /** Get agents by deployment ID */
1013
+ agentsByDeployment(deploymentId: string): Promise<Record>;
1014
+ /** Get documents linked to a KV key */
1015
+ kvGetLinks(key: string): Promise<Record>;
1016
+ /** Link a document to a KV key */
1017
+ kvLink(key: string, collection: string, documentId: string): Promise<Record>;
1018
+ /** Unlink a document from a KV key */
1019
+ kvUnlink(key: string, collection: string, documentId: string): Promise<Record>;
1020
+ /** Create a new schedule */
1021
+ createSchedule(data: Record): Promise<Record>;
1022
+ /** List all schedules */
1023
+ listSchedules(): Promise<Record>;
1024
+ /** Get a schedule by ID */
1025
+ getSchedule(id: string): Promise<Record>;
1026
+ /** Update a schedule */
1027
+ updateSchedule(id: string, data: Record): Promise<Record>;
1028
+ /** Delete a schedule */
1029
+ deleteSchedule(id: string): Promise<void>;
1030
+ /** Pause a schedule */
1031
+ pauseSchedule(id: string): Promise<Record>;
1032
+ /** Resume a schedule */
1033
+ resumeSchedule(id: string): Promise<Record>;
907
1034
  /**
908
1035
  * Check if a collection exists
909
1036
  * @param collection - Collection name to check
@@ -1032,6 +1159,8 @@ export type ChatStreamEvent = {
1032
1159
  tokenUsage?: any;
1033
1160
  toolCallHistory?: any;
1034
1161
  executionTimeMs: number;
1162
+ /** Model's context window size in tokens. */
1163
+ contextWindow?: number;
1035
1164
  } | {
1036
1165
  type: "toolCall";
1037
1166
  chatId: string;
@@ -1116,6 +1245,15 @@ export declare class WebSocketClient {
1116
1245
  * Send a tool result back to the server during a chat stream.
1117
1246
  */
1118
1247
  sendToolResult(chatId: string, callId: string, success: boolean, result?: any, error?: string): Promise<void>;
1248
+ /**
1249
+ * Stateless raw LLM completion via WebSocket.
1250
+ *
1251
+ * Sends a RawComplete message and waits for the Success response.
1252
+ * Preferred over HTTP for deployed instances: the persistent WSS
1253
+ * connection is already authenticated and won't be killed by reverse
1254
+ * proxy timeouts.
1255
+ */
1256
+ rawCompletion(request: RawCompletionRequest): Promise<RawCompletionResponse>;
1119
1257
  /**
1120
1258
  * Close the WebSocket connection.
1121
1259
  */