@o-zakstam/voltagent-convex 1.1.2 → 1.1.4

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.
Files changed (95) hide show
  1. package/dist/client/{index.d.cts → defineVoltAgentAPI.d.ts} +59 -92
  2. package/dist/client/defineVoltAgentAPI.d.ts.map +1 -0
  3. package/dist/client/defineVoltAgentAPI.js +318 -0
  4. package/dist/client/defineVoltAgentAPI.js.map +1 -0
  5. package/dist/client/index.d.ts +6 -221
  6. package/dist/client/index.d.ts.map +1 -0
  7. package/dist/client/index.js +8 -285
  8. package/dist/client/index.js.map +1 -1
  9. package/dist/client/types.d.ts +13 -0
  10. package/dist/client/types.d.ts.map +1 -0
  11. package/dist/client/types.js +8 -0
  12. package/dist/client/types.js.map +1 -0
  13. package/dist/component/_generated/api.d.ts +44 -0
  14. package/dist/component/_generated/api.d.ts.map +1 -0
  15. package/dist/component/_generated/api.js +31 -0
  16. package/dist/component/_generated/api.js.map +1 -0
  17. package/dist/component/_generated/component.d.ts +352 -0
  18. package/dist/component/_generated/component.d.ts.map +1 -0
  19. package/dist/component/_generated/component.js +11 -0
  20. package/dist/component/_generated/component.js.map +1 -0
  21. package/dist/component/_generated/dataModel.d.ts +46 -0
  22. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  23. package/dist/component/_generated/dataModel.js +11 -0
  24. package/dist/component/_generated/dataModel.js.map +1 -0
  25. package/dist/component/_generated/server.d.ts +121 -0
  26. package/dist/component/_generated/server.d.ts.map +1 -0
  27. package/dist/component/_generated/server.js +78 -0
  28. package/dist/component/_generated/server.js.map +1 -0
  29. package/dist/component/conversations.d.ts +108 -0
  30. package/dist/component/conversations.d.ts.map +1 -0
  31. package/dist/component/conversations.js +278 -0
  32. package/dist/component/conversations.js.map +1 -0
  33. package/dist/component/convex.config.d.ts +13 -0
  34. package/dist/component/convex.config.d.ts.map +1 -0
  35. package/dist/component/convex.config.js +21 -0
  36. package/dist/component/convex.config.js.map +1 -0
  37. package/dist/component/messages.d.ts +235 -0
  38. package/dist/component/messages.d.ts.map +1 -0
  39. package/dist/component/messages.js +186 -0
  40. package/dist/component/messages.js.map +1 -0
  41. package/dist/component/schema.d.ts +535 -0
  42. package/dist/component/schema.d.ts.map +1 -0
  43. package/dist/component/schema.js +113 -0
  44. package/dist/component/schema.js.map +1 -0
  45. package/dist/component/steps.d.ts +65 -0
  46. package/dist/component/steps.d.ts.map +1 -0
  47. package/dist/component/steps.js +120 -0
  48. package/dist/component/steps.js.map +1 -0
  49. package/dist/component/validators.d.ts +633 -0
  50. package/dist/component/validators.d.ts.map +1 -0
  51. package/dist/component/validators.js +124 -0
  52. package/dist/component/validators.js.map +1 -0
  53. package/dist/component/workflows.d.ts +234 -0
  54. package/dist/component/workflows.d.ts.map +1 -0
  55. package/dist/component/workflows.js +229 -0
  56. package/dist/component/workflows.js.map +1 -0
  57. package/dist/component/workingMemory.d.ts +30 -0
  58. package/dist/component/workingMemory.d.ts.map +1 -0
  59. package/dist/component/workingMemory.js +131 -0
  60. package/dist/component/workingMemory.js.map +1 -0
  61. package/dist/index.d.ts +7 -318
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js +10 -434
  64. package/dist/index.js.map +1 -1
  65. package/dist/memory-adapter.d.ts +153 -0
  66. package/dist/memory-adapter.d.ts.map +1 -0
  67. package/dist/memory-adapter.js +462 -0
  68. package/dist/memory-adapter.js.map +1 -0
  69. package/dist/types.d.ts +167 -0
  70. package/dist/types.d.ts.map +1 -0
  71. package/dist/types.js +5 -0
  72. package/dist/types.js.map +1 -0
  73. package/package.json +25 -26
  74. package/src/client/defineVoltAgentAPI.ts +365 -0
  75. package/src/client/index.ts +8 -0
  76. package/src/client/types.ts +14 -0
  77. package/src/component/_generated/api.ts +60 -0
  78. package/src/component/_generated/component.ts +466 -0
  79. package/src/component/_generated/dataModel.ts +60 -0
  80. package/src/component/_generated/server.ts +156 -0
  81. package/src/index.ts +24 -0
  82. package/{dist/index.cjs → src/memory-adapter.ts} +345 -106
  83. package/src/types.ts +178 -0
  84. package/dist/client/index.cjs +0 -288
  85. package/dist/client/index.cjs.map +0 -1
  86. package/dist/index.cjs.map +0 -1
  87. package/dist/index.d.cts +0 -322
  88. /package/{convex → src/component}/conversations.ts +0 -0
  89. /package/{convex → src/component}/convex.config.ts +0 -0
  90. /package/{convex → src/component}/messages.ts +0 -0
  91. /package/{convex → src/component}/schema.ts +0 -0
  92. /package/{convex → src/component}/steps.ts +0 -0
  93. /package/{convex → src/component}/validators.ts +0 -0
  94. /package/{convex → src/component}/workflows.ts +0 -0
  95. /package/{convex → src/component}/workingMemory.ts +0 -0
@@ -1,125 +1,228 @@
1
- 'use strict';
1
+ /**
2
+ * Convex Memory Adapter for VoltAgent
3
+ *
4
+ * A StorageAdapter implementation that persists conversation data
5
+ * to Convex database using the VoltAgent Convex component.
6
+ */
2
7
 
3
- var core = require('@voltagent/core');
8
+ import {
9
+ ConversationAlreadyExistsError,
10
+ ConversationNotFoundError,
11
+ } from "@voltagent/core";
12
+ import type {
13
+ Conversation,
14
+ ConversationQueryOptions,
15
+ ConversationStepRecord,
16
+ CreateConversationInput,
17
+ GetConversationStepsOptions,
18
+ GetMessagesOptions,
19
+ OperationContext,
20
+ StorageAdapter,
21
+ WorkflowStateEntry,
22
+ WorkingMemoryScope,
23
+ } from "@voltagent/core";
24
+ import type { UIMessage } from "ai";
25
+ import type {
26
+ ConvexClient,
27
+ ConvexMemoryAdapterOptions,
28
+ Logger,
29
+ VoltAgentApi,
30
+ } from "./types";
4
31
 
5
- // src/memory-adapter.ts
6
- var defaultLogger = {
7
- debug: (message, ...args) => console.debug(`[ConvexMemory] ${message}`, ...args),
8
- info: (message, ...args) => console.info(`[ConvexMemory] ${message}`, ...args),
9
- warn: (message, ...args) => console.warn(`[ConvexMemory] ${message}`, ...args),
10
- error: (message, ...args) => console.error(`[ConvexMemory] ${message}`, ...args)
32
+ /**
33
+ * Default console logger implementation
34
+ */
35
+ const defaultLogger: Logger = {
36
+ debug: (message: string, ...args: unknown[]) =>
37
+ console.debug(`[ConvexMemory] ${message}`, ...args),
38
+ info: (message: string, ...args: unknown[]) =>
39
+ console.info(`[ConvexMemory] ${message}`, ...args),
40
+ warn: (message: string, ...args: unknown[]) =>
41
+ console.warn(`[ConvexMemory] ${message}`, ...args),
42
+ error: (message: string, ...args: unknown[]) =>
43
+ console.error(`[ConvexMemory] ${message}`, ...args),
11
44
  };
12
- var ConvexMemoryAdapter = class {
13
- client;
14
- api;
15
- debug;
16
- logger;
17
- constructor(options) {
45
+
46
+ /**
47
+ * Convex Memory Adapter for VoltAgent
48
+ *
49
+ * Implements the StorageAdapter interface to persist conversation history,
50
+ * working memory, and workflow state to a Convex database.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * import { ConvexHttpClient } from "convex/browser";
55
+ * import { api } from "./convex/_generated/api";
56
+ * import { ConvexMemoryAdapter } from "@voltagent/convex";
57
+ *
58
+ * const client = new ConvexHttpClient(process.env.CONVEX_URL);
59
+ *
60
+ * const adapter = new ConvexMemoryAdapter({
61
+ * client,
62
+ * api: api.voltagent,
63
+ * });
64
+ *
65
+ * const memory = new Memory({ storage: adapter });
66
+ * ```
67
+ */
68
+ export class ConvexMemoryAdapter implements StorageAdapter {
69
+ private client: ConvexClient;
70
+ private api: VoltAgentApi;
71
+ private debug: boolean;
72
+ private logger: Logger;
73
+
74
+ constructor(options: ConvexMemoryAdapterOptions) {
18
75
  if (!options.client) {
19
76
  throw new Error("Convex client is required");
20
77
  }
21
78
  if (!options.api) {
22
79
  throw new Error("Convex API is required");
23
80
  }
81
+
24
82
  this.client = options.client;
25
83
  this.api = options.api;
26
84
  this.debug = options.debug ?? false;
27
85
  this.logger = options.logger ?? defaultLogger;
86
+
28
87
  this.log("Convex Memory adapter initialized");
29
88
  }
89
+
30
90
  /**
31
91
  * Log debug messages
32
92
  */
33
- log(message, ...args) {
93
+ private log(message: string, ...args: unknown[]): void {
34
94
  if (this.debug) {
35
95
  this.logger.debug(message, ...args);
36
96
  }
37
97
  }
98
+
38
99
  /**
39
100
  * Generate a cryptographically secure random ID
40
101
  */
41
- generateId() {
102
+ private generateId(): string {
42
103
  return crypto.randomUUID();
43
104
  }
105
+
44
106
  // ============================================================================
45
107
  // Message Operations
46
108
  // ============================================================================
109
+
47
110
  /**
48
111
  * Add a single message to a conversation
49
112
  */
50
- async addMessage(message, userId, conversationId, _context) {
113
+ async addMessage(
114
+ message: UIMessage,
115
+ userId: string,
116
+ conversationId: string,
117
+ _context?: OperationContext,
118
+ ): Promise<void> {
51
119
  await this.client.mutation(this.api.addMessage, {
52
120
  id: message.id || this.generateId(),
53
121
  conversationId,
54
122
  userId,
55
123
  role: message.role,
56
124
  parts: message.parts,
57
- metadata: message.metadata || null
125
+ metadata: message.metadata || null,
58
126
  });
127
+
59
128
  this.log(`Added message to conversation ${conversationId}`);
60
129
  }
130
+
61
131
  /**
62
132
  * Add multiple messages to a conversation
63
133
  */
64
- async addMessages(messages, userId, conversationId, _context) {
134
+ async addMessages(
135
+ messages: UIMessage[],
136
+ userId: string,
137
+ conversationId: string,
138
+ _context?: OperationContext,
139
+ ): Promise<void> {
65
140
  const messagesToAdd = messages.map((message) => ({
66
141
  id: message.id || this.generateId(),
67
142
  conversationId,
68
143
  userId,
69
144
  role: message.role,
70
145
  parts: message.parts,
71
- metadata: message.metadata || null
146
+ metadata: message.metadata || null,
72
147
  }));
148
+
73
149
  await this.client.mutation(this.api.addMessages, {
74
- messages: messagesToAdd
150
+ messages: messagesToAdd,
75
151
  });
152
+
76
153
  this.log(
77
- `Added ${messages.length} messages to conversation ${conversationId}`
154
+ `Added ${messages.length} messages to conversation ${conversationId}`,
78
155
  );
79
156
  }
157
+
80
158
  /**
81
159
  * Get messages from a conversation with optional filtering
82
160
  */
83
- async getMessages(userId, conversationId, options, _context) {
161
+ async getMessages(
162
+ userId: string,
163
+ conversationId: string,
164
+ options?: GetMessagesOptions,
165
+ _context?: OperationContext,
166
+ ): Promise<UIMessage<{ createdAt: Date }>[]> {
84
167
  const { limit, before, after, roles } = options || {};
168
+
85
169
  const messages = await this.client.query(this.api.getMessages, {
86
170
  userId,
87
171
  conversationId,
88
172
  limit,
89
173
  before: before?.toISOString(),
90
174
  after: after?.toISOString(),
91
- roles
175
+ roles,
92
176
  });
93
- return messages.map((msg) => ({
177
+
178
+ return (
179
+ messages as Array<{
180
+ id: string;
181
+ role: string;
182
+ parts: unknown[];
183
+ metadata?: Record<string, unknown> & { createdAt?: string };
184
+ }>
185
+ ).map((msg) => ({
94
186
  id: msg.id,
95
- role: msg.role,
96
- parts: msg.parts,
187
+ role: msg.role as "system" | "user" | "assistant",
188
+ parts: msg.parts as UIMessage["parts"],
97
189
  metadata: {
98
190
  ...msg.metadata,
99
- createdAt: msg.metadata?.createdAt ? new Date(msg.metadata.createdAt) : /* @__PURE__ */ new Date()
100
- }
191
+ createdAt: msg.metadata?.createdAt
192
+ ? new Date(msg.metadata.createdAt as string)
193
+ : new Date(),
194
+ },
101
195
  }));
102
196
  }
197
+
103
198
  /**
104
199
  * Clear messages for a user (optionally for a specific conversation)
105
200
  */
106
- async clearMessages(userId, conversationId, _context) {
201
+ async clearMessages(
202
+ userId: string,
203
+ conversationId?: string,
204
+ _context?: OperationContext,
205
+ ): Promise<void> {
107
206
  await this.client.mutation(this.api.clearMessages, {
108
207
  userId,
109
- conversationId
208
+ conversationId,
110
209
  });
210
+
111
211
  this.log(`Cleared messages for user ${userId}`);
112
212
  }
213
+
113
214
  // ============================================================================
114
215
  // Conversation Steps Operations
115
216
  // ============================================================================
217
+
116
218
  /**
117
219
  * Save conversation steps for observability
118
220
  */
119
- async saveConversationSteps(steps) {
221
+ async saveConversationSteps(steps: ConversationStepRecord[]): Promise<void> {
120
222
  if (steps.length === 0) {
121
223
  return;
122
224
  }
225
+
123
226
  await this.client.mutation(this.api.saveConversationSteps, {
124
227
  steps: steps.map((step) => ({
125
228
  id: step.id,
@@ -137,69 +240,90 @@ var ConvexMemoryAdapter = class {
137
240
  usage: step.usage,
138
241
  subAgentId: step.subAgentId,
139
242
  subAgentName: step.subAgentName,
140
- createdAt: step.createdAt
141
- }))
243
+ createdAt: step.createdAt,
244
+ })),
142
245
  });
246
+
143
247
  this.log(`Saved ${steps.length} conversation steps`);
144
248
  }
249
+
145
250
  /**
146
251
  * Get conversation steps for observability
147
252
  */
148
- async getConversationSteps(userId, conversationId, options) {
253
+ async getConversationSteps(
254
+ userId: string,
255
+ conversationId: string,
256
+ options?: GetConversationStepsOptions,
257
+ ): Promise<ConversationStepRecord[]> {
149
258
  const steps = await this.client.query(this.api.getConversationSteps, {
150
259
  userId,
151
260
  conversationId,
152
261
  limit: options?.limit,
153
- operationId: options?.operationId
262
+ operationId: options?.operationId,
154
263
  });
155
- return steps;
264
+
265
+ return steps as ConversationStepRecord[];
156
266
  }
267
+
157
268
  // ============================================================================
158
269
  // Conversation Operations
159
270
  // ============================================================================
271
+
160
272
  /**
161
273
  * Create a new conversation
162
274
  */
163
- async createConversation(input) {
275
+ async createConversation(
276
+ input: CreateConversationInput,
277
+ ): Promise<Conversation> {
164
278
  try {
165
279
  const result = await this.client.mutation(this.api.createConversation, {
166
280
  id: input.id,
167
281
  resourceId: input.resourceId,
168
282
  userId: input.userId,
169
283
  title: input.title,
170
- metadata: input.metadata || {}
284
+ metadata: input.metadata || {},
171
285
  });
286
+
172
287
  this.log(`Created conversation ${input.id}`);
173
- return result;
288
+
289
+ return result as Conversation;
174
290
  } catch (error) {
175
291
  if (error instanceof Error && error.message.includes("already exists")) {
176
- throw new core.ConversationAlreadyExistsError(input.id);
292
+ throw new ConversationAlreadyExistsError(input.id);
177
293
  }
178
294
  throw error;
179
295
  }
180
296
  }
297
+
181
298
  /**
182
299
  * Get a conversation by ID
183
300
  */
184
- async getConversation(id) {
301
+ async getConversation(id: string): Promise<Conversation | null> {
185
302
  const conversation = await this.client.query(this.api.getConversation, {
186
- id
303
+ id,
187
304
  });
188
- return conversation;
305
+
306
+ return conversation as Conversation | null;
189
307
  }
308
+
190
309
  /**
191
310
  * Get conversations by resource ID
192
311
  */
193
- async getConversations(resourceId) {
312
+ async getConversations(resourceId: string): Promise<Conversation[]> {
194
313
  const conversations = await this.client.query(this.api.getConversations, {
195
- resourceId
314
+ resourceId,
196
315
  });
197
- return conversations;
316
+
317
+ return conversations as Conversation[];
198
318
  }
319
+
199
320
  /**
200
321
  * Get conversations by user ID with optional query options
201
322
  */
202
- async getConversationsByUserId(userId, options) {
323
+ async getConversationsByUserId(
324
+ userId: string,
325
+ options?: Omit<ConversationQueryOptions, "userId">,
326
+ ): Promise<Conversation[]> {
203
327
  const conversations = await this.client.query(
204
328
  this.api.getConversationsByUserId,
205
329
  {
@@ -207,167 +331,258 @@ var ConvexMemoryAdapter = class {
207
331
  limit: options?.limit,
208
332
  offset: options?.offset,
209
333
  orderBy: options?.orderBy,
210
- orderDirection: options?.orderDirection
211
- }
334
+ orderDirection: options?.orderDirection,
335
+ },
212
336
  );
213
- return conversations;
337
+
338
+ return conversations as Conversation[];
214
339
  }
340
+
215
341
  /**
216
342
  * Query conversations with filters
217
343
  */
218
- async queryConversations(options) {
344
+ async queryConversations(
345
+ options: ConversationQueryOptions,
346
+ ): Promise<Conversation[]> {
219
347
  const conversations = await this.client.query(this.api.queryConversations, {
220
348
  userId: options.userId,
221
349
  resourceId: options.resourceId,
222
350
  limit: options.limit,
223
351
  offset: options.offset,
224
352
  orderBy: options.orderBy,
225
- orderDirection: options.orderDirection
353
+ orderDirection: options.orderDirection,
226
354
  });
227
- return conversations;
355
+
356
+ return conversations as Conversation[];
228
357
  }
358
+
229
359
  /**
230
360
  * Update a conversation
231
361
  */
232
- async updateConversation(id, updates) {
362
+ async updateConversation(
363
+ id: string,
364
+ updates: Partial<Omit<Conversation, "id" | "createdAt" | "updatedAt">>,
365
+ ): Promise<Conversation> {
233
366
  try {
234
367
  const result = await this.client.mutation(this.api.updateConversation, {
235
368
  id,
236
369
  title: updates.title,
237
370
  resourceId: updates.resourceId,
238
- metadata: updates.metadata
371
+ metadata: updates.metadata,
239
372
  });
373
+
240
374
  this.log(`Updated conversation ${id}`);
241
- return result;
375
+
376
+ return result as Conversation;
242
377
  } catch (error) {
243
378
  if (error instanceof Error && error.message.includes("not found")) {
244
- throw new core.ConversationNotFoundError(id);
379
+ throw new ConversationNotFoundError(id);
245
380
  }
246
381
  throw error;
247
382
  }
248
383
  }
384
+
249
385
  /**
250
386
  * Delete a conversation and its associated data
251
387
  */
252
- async deleteConversation(id) {
388
+ async deleteConversation(id: string): Promise<void> {
253
389
  try {
254
390
  await this.client.mutation(this.api.deleteConversation, { id });
255
391
  this.log(`Deleted conversation ${id}`);
256
392
  } catch (error) {
257
393
  if (error instanceof Error && error.message.includes("not found")) {
258
- throw new core.ConversationNotFoundError(id);
394
+ throw new ConversationNotFoundError(id);
259
395
  }
260
396
  throw error;
261
397
  }
262
398
  }
399
+
263
400
  // ============================================================================
264
401
  // Working Memory Operations
265
402
  // ============================================================================
403
+
266
404
  /**
267
405
  * Get working memory content
268
406
  */
269
- async getWorkingMemory(params) {
407
+ async getWorkingMemory(params: {
408
+ conversationId?: string;
409
+ userId?: string;
410
+ scope: WorkingMemoryScope;
411
+ }): Promise<string | null> {
270
412
  const result = await this.client.query(this.api.getWorkingMemory, {
271
413
  conversationId: params.conversationId,
272
414
  userId: params.userId,
273
- scope: params.scope
415
+ scope: params.scope,
274
416
  });
275
- return result;
417
+
418
+ return result as string | null;
276
419
  }
420
+
277
421
  /**
278
422
  * Set working memory content
279
423
  */
280
- async setWorkingMemory(params) {
424
+ async setWorkingMemory(params: {
425
+ conversationId?: string;
426
+ userId?: string;
427
+ content: string;
428
+ scope: WorkingMemoryScope;
429
+ }): Promise<void> {
281
430
  try {
282
431
  await this.client.mutation(this.api.setWorkingMemory, {
283
432
  conversationId: params.conversationId,
284
433
  userId: params.userId,
285
434
  content: params.content,
286
- scope: params.scope
435
+ scope: params.scope,
287
436
  });
437
+
288
438
  this.log(`Set working memory for ${params.scope}`);
289
439
  } catch (error) {
290
- if (error instanceof Error && error.message.includes("not found") && params.conversationId) {
291
- throw new core.ConversationNotFoundError(params.conversationId);
440
+ if (
441
+ error instanceof Error &&
442
+ error.message.includes("not found") &&
443
+ params.conversationId
444
+ ) {
445
+ throw new ConversationNotFoundError(params.conversationId);
292
446
  }
293
447
  throw error;
294
448
  }
295
449
  }
450
+
296
451
  /**
297
452
  * Delete working memory content
298
453
  */
299
- async deleteWorkingMemory(params) {
454
+ async deleteWorkingMemory(params: {
455
+ conversationId?: string;
456
+ userId?: string;
457
+ scope: WorkingMemoryScope;
458
+ }): Promise<void> {
300
459
  await this.client.mutation(this.api.deleteWorkingMemory, {
301
460
  conversationId: params.conversationId,
302
461
  userId: params.userId,
303
- scope: params.scope
462
+ scope: params.scope,
304
463
  });
464
+
305
465
  this.log(`Deleted working memory for ${params.scope}`);
306
466
  }
467
+
307
468
  // ============================================================================
308
469
  // Workflow State Operations
309
470
  // ============================================================================
471
+
310
472
  /**
311
473
  * Get workflow state by execution ID
312
474
  */
313
- async getWorkflowState(executionId) {
475
+ async getWorkflowState(
476
+ executionId: string,
477
+ ): Promise<WorkflowStateEntry | null> {
314
478
  const state = await this.client.query(this.api.getWorkflowState, {
315
- executionId
479
+ executionId,
316
480
  });
481
+
317
482
  if (!state) return null;
318
- const typedState = state;
483
+
484
+ const typedState = state as {
485
+ id: string;
486
+ workflowId: string;
487
+ workflowName: string;
488
+ status: string;
489
+ input?: unknown;
490
+ context?: unknown;
491
+ suspension?: unknown;
492
+ events?: unknown[];
493
+ output?: unknown;
494
+ cancellation?: unknown;
495
+ userId?: string;
496
+ conversationId?: string;
497
+ metadata?: Record<string, unknown>;
498
+ createdAt: string;
499
+ updatedAt: string;
500
+ };
501
+
319
502
  return {
320
503
  id: typedState.id,
321
504
  workflowId: typedState.workflowId,
322
505
  workflowName: typedState.workflowName,
323
- status: typedState.status,
506
+ status: typedState.status as WorkflowStateEntry["status"],
324
507
  input: typedState.input,
325
- context: typedState.context,
326
- suspension: typedState.suspension,
327
- events: typedState.events,
508
+ context: typedState.context as WorkflowStateEntry["context"],
509
+ suspension: typedState.suspension as WorkflowStateEntry["suspension"],
510
+ events: typedState.events as WorkflowStateEntry["events"],
328
511
  output: typedState.output,
329
- cancellation: typedState.cancellation,
512
+ cancellation:
513
+ typedState.cancellation as WorkflowStateEntry["cancellation"],
330
514
  userId: typedState.userId,
331
515
  conversationId: typedState.conversationId,
332
516
  metadata: typedState.metadata,
333
517
  createdAt: new Date(typedState.createdAt),
334
- updatedAt: new Date(typedState.updatedAt)
518
+ updatedAt: new Date(typedState.updatedAt),
335
519
  };
336
520
  }
521
+
337
522
  /**
338
523
  * Query workflow runs with optional filters
339
524
  */
340
- async queryWorkflowRuns(query) {
525
+ async queryWorkflowRuns(query: {
526
+ workflowId?: string;
527
+ status?: WorkflowStateEntry["status"];
528
+ from?: Date;
529
+ to?: Date;
530
+ limit?: number;
531
+ offset?: number;
532
+ }): Promise<WorkflowStateEntry[]> {
341
533
  const states = await this.client.query(this.api.queryWorkflowRuns, {
342
534
  workflowId: query.workflowId,
343
535
  status: query.status,
344
536
  from: query.from?.toISOString(),
345
537
  to: query.to?.toISOString(),
346
538
  limit: query.limit,
347
- offset: query.offset
539
+ offset: query.offset,
348
540
  });
349
- return states.map((s) => ({
541
+
542
+ return (
543
+ states as Array<{
544
+ id: string;
545
+ workflowId: string;
546
+ workflowName: string;
547
+ status: string;
548
+ input?: unknown;
549
+ context?: unknown;
550
+ suspension?: unknown;
551
+ events?: unknown[];
552
+ output?: unknown;
553
+ cancellation?: unknown;
554
+ userId?: string;
555
+ conversationId?: string;
556
+ metadata?: Record<string, unknown>;
557
+ createdAt: string;
558
+ updatedAt: string;
559
+ }>
560
+ ).map((s) => ({
350
561
  id: s.id,
351
562
  workflowId: s.workflowId,
352
563
  workflowName: s.workflowName,
353
- status: s.status,
564
+ status: s.status as WorkflowStateEntry["status"],
354
565
  input: s.input,
355
- context: s.context,
356
- suspension: s.suspension,
357
- events: s.events,
566
+ context: s.context as WorkflowStateEntry["context"],
567
+ suspension: s.suspension as WorkflowStateEntry["suspension"],
568
+ events: s.events as WorkflowStateEntry["events"],
358
569
  output: s.output,
359
- cancellation: s.cancellation,
570
+ cancellation: s.cancellation as WorkflowStateEntry["cancellation"],
360
571
  userId: s.userId,
361
572
  conversationId: s.conversationId,
362
573
  metadata: s.metadata,
363
574
  createdAt: new Date(s.createdAt),
364
- updatedAt: new Date(s.updatedAt)
575
+ updatedAt: new Date(s.updatedAt),
365
576
  }));
366
577
  }
578
+
367
579
  /**
368
580
  * Set workflow state
369
581
  */
370
- async setWorkflowState(executionId, state) {
582
+ async setWorkflowState(
583
+ executionId: string,
584
+ state: WorkflowStateEntry,
585
+ ): Promise<void> {
371
586
  await this.client.mutation(this.api.setWorkflowState, {
372
587
  executionId,
373
588
  workflowId: state.workflowId,
@@ -383,14 +598,19 @@ var ConvexMemoryAdapter = class {
383
598
  conversationId: state.conversationId,
384
599
  metadata: state.metadata,
385
600
  createdAt: state.createdAt.toISOString(),
386
- updatedAt: state.updatedAt.toISOString()
601
+ updatedAt: state.updatedAt.toISOString(),
387
602
  });
603
+
388
604
  this.log(`Set workflow state ${executionId}`);
389
605
  }
606
+
390
607
  /**
391
608
  * Update workflow state
392
609
  */
393
- async updateWorkflowState(executionId, updates) {
610
+ async updateWorkflowState(
611
+ executionId: string,
612
+ updates: Partial<WorkflowStateEntry>,
613
+ ): Promise<void> {
394
614
  await this.client.mutation(this.api.updateWorkflowState, {
395
615
  executionId,
396
616
  status: updates.status,
@@ -398,40 +618,59 @@ var ConvexMemoryAdapter = class {
398
618
  events: updates.events,
399
619
  output: updates.output,
400
620
  cancellation: updates.cancellation,
401
- metadata: updates.metadata
621
+ metadata: updates.metadata,
402
622
  });
623
+
403
624
  this.log(`Updated workflow state ${executionId}`);
404
625
  }
626
+
405
627
  /**
406
628
  * Get suspended workflow states for a workflow
407
629
  */
408
- async getSuspendedWorkflowStates(workflowId) {
630
+ async getSuspendedWorkflowStates(
631
+ workflowId: string,
632
+ ): Promise<WorkflowStateEntry[]> {
409
633
  const states = await this.client.query(
410
634
  this.api.getSuspendedWorkflowStates,
411
635
  {
412
- workflowId
413
- }
636
+ workflowId,
637
+ },
414
638
  );
415
- return states.map((s) => ({
639
+
640
+ return (
641
+ states as Array<{
642
+ id: string;
643
+ workflowId: string;
644
+ workflowName: string;
645
+ status: string;
646
+ input?: unknown;
647
+ context?: unknown;
648
+ suspension?: unknown;
649
+ events?: unknown[];
650
+ output?: unknown;
651
+ cancellation?: unknown;
652
+ userId?: string;
653
+ conversationId?: string;
654
+ metadata?: Record<string, unknown>;
655
+ createdAt: string;
656
+ updatedAt: string;
657
+ }>
658
+ ).map((s) => ({
416
659
  id: s.id,
417
660
  workflowId: s.workflowId,
418
661
  workflowName: s.workflowName,
419
- status: s.status,
662
+ status: s.status as WorkflowStateEntry["status"],
420
663
  input: s.input,
421
- context: s.context,
422
- suspension: s.suspension,
423
- events: s.events,
664
+ context: s.context as WorkflowStateEntry["context"],
665
+ suspension: s.suspension as WorkflowStateEntry["suspension"],
666
+ events: s.events as WorkflowStateEntry["events"],
424
667
  output: s.output,
425
- cancellation: s.cancellation,
668
+ cancellation: s.cancellation as WorkflowStateEntry["cancellation"],
426
669
  userId: s.userId,
427
670
  conversationId: s.conversationId,
428
671
  metadata: s.metadata,
429
672
  createdAt: new Date(s.createdAt),
430
- updatedAt: new Date(s.updatedAt)
673
+ updatedAt: new Date(s.updatedAt),
431
674
  }));
432
675
  }
433
- };
434
-
435
- exports.ConvexMemoryAdapter = ConvexMemoryAdapter;
436
- //# sourceMappingURL=index.cjs.map
437
- //# sourceMappingURL=index.cjs.map
676
+ }