@mastra/lance 0.0.0-memory-system-message-error-20250813233316 → 0.0.0-message-file-url-handling-fix-20250904234524

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/index.js CHANGED
@@ -379,6 +379,20 @@ var StoreMemoryLance = class extends MemoryStorage {
379
379
  );
380
380
  }
381
381
  }
382
+ normalizeMessage(message) {
383
+ const { thread_id, ...rest } = message;
384
+ return {
385
+ ...rest,
386
+ threadId: thread_id,
387
+ content: typeof message.content === "string" ? (() => {
388
+ try {
389
+ return JSON.parse(message.content);
390
+ } catch {
391
+ return message.content;
392
+ }
393
+ })() : message.content
394
+ };
395
+ }
382
396
  async getMessages({
383
397
  threadId,
384
398
  resourceId,
@@ -387,6 +401,7 @@ var StoreMemoryLance = class extends MemoryStorage {
387
401
  threadConfig
388
402
  }) {
389
403
  try {
404
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
390
405
  if (threadConfig) {
391
406
  throw new Error("ThreadConfig is not supported by LanceDB storage");
392
407
  }
@@ -419,21 +434,7 @@ var StoreMemoryLance = class extends MemoryStorage {
419
434
  allRecords,
420
435
  await getTableSchema({ tableName: TABLE_MESSAGES, client: this.client })
421
436
  );
422
- const normalized = messages.map((msg) => {
423
- const { thread_id, ...rest } = msg;
424
- return {
425
- ...rest,
426
- threadId: thread_id,
427
- content: typeof msg.content === "string" ? (() => {
428
- try {
429
- return JSON.parse(msg.content);
430
- } catch {
431
- return msg.content;
432
- }
433
- })() : msg.content
434
- };
435
- });
436
- const list = new MessageList({ threadId, resourceId }).add(normalized, "memory");
437
+ const list = new MessageList({ threadId, resourceId }).add(messages.map(this.normalizeMessage), "memory");
437
438
  if (format === "v2") return list.get.all.v2();
438
439
  return list.get.all.v1();
439
440
  } catch (error) {
@@ -441,7 +442,41 @@ var StoreMemoryLance = class extends MemoryStorage {
441
442
  {
442
443
  id: "LANCE_STORE_GET_MESSAGES_FAILED",
443
444
  domain: ErrorDomain.STORAGE,
444
- category: ErrorCategory.THIRD_PARTY
445
+ category: ErrorCategory.THIRD_PARTY,
446
+ details: {
447
+ threadId,
448
+ resourceId: resourceId ?? ""
449
+ }
450
+ },
451
+ error
452
+ );
453
+ }
454
+ }
455
+ async getMessagesById({
456
+ messageIds,
457
+ format
458
+ }) {
459
+ if (messageIds.length === 0) return [];
460
+ try {
461
+ const table = await this.client.openTable(TABLE_MESSAGES);
462
+ const quotedIds = messageIds.map((id) => `'${id}'`).join(", ");
463
+ const allRecords = await table.query().where(`id IN (${quotedIds})`).toArray();
464
+ const messages = processResultWithTypeConversion(
465
+ allRecords,
466
+ await getTableSchema({ tableName: TABLE_MESSAGES, client: this.client })
467
+ );
468
+ const list = new MessageList().add(messages.map(this.normalizeMessage), "memory");
469
+ if (format === `v1`) return list.get.all.v1();
470
+ return list.get.all.v2();
471
+ } catch (error) {
472
+ throw new MastraError(
473
+ {
474
+ id: "LANCE_STORE_GET_MESSAGES_BY_ID_FAILED",
475
+ domain: ErrorDomain.STORAGE,
476
+ category: ErrorCategory.THIRD_PARTY,
477
+ details: {
478
+ messageIds: JSON.stringify(messageIds)
479
+ }
445
480
  },
446
481
  error
447
482
  );
@@ -582,13 +617,11 @@ var StoreMemoryLance = class extends MemoryStorage {
582
617
  return Array.from(allIndices).sort((a, b) => a - b).map((index) => records[index]);
583
618
  }
584
619
  async getMessagesPaginated(args) {
620
+ const { threadId, resourceId, selectBy, format = "v1" } = args;
621
+ const page = selectBy?.pagination?.page ?? 0;
622
+ const perPage = selectBy?.pagination?.perPage ?? 10;
585
623
  try {
586
- const { threadId, resourceId, selectBy, format = "v1" } = args;
587
- if (!threadId) {
588
- throw new Error("Thread ID is required for getMessagesPaginated");
589
- }
590
- const page = selectBy?.pagination?.page ?? 0;
591
- const perPage = selectBy?.pagination?.perPage ?? 10;
624
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
592
625
  const dateRange = selectBy?.pagination?.dateRange;
593
626
  const fromDate = dateRange?.start;
594
627
  const toDate = dateRange?.end;
@@ -690,14 +723,21 @@ var StoreMemoryLance = class extends MemoryStorage {
690
723
  hasMore: total > (page + 1) * perPage
691
724
  };
692
725
  } catch (error) {
693
- throw new MastraError(
726
+ const mastraError = new MastraError(
694
727
  {
695
728
  id: "LANCE_STORE_GET_MESSAGES_PAGINATED_FAILED",
696
729
  domain: ErrorDomain.STORAGE,
697
- category: ErrorCategory.THIRD_PARTY
730
+ category: ErrorCategory.THIRD_PARTY,
731
+ details: {
732
+ threadId,
733
+ resourceId: resourceId ?? ""
734
+ }
698
735
  },
699
736
  error
700
737
  );
738
+ this.logger?.trackException?.(mastraError);
739
+ this.logger?.error?.(mastraError.toString());
740
+ return { messages: [], total: 0, page, perPage, hasMore: false };
701
741
  }
702
742
  }
703
743
  /**
@@ -1757,6 +1797,22 @@ var StoreWorkflowsLance = class extends WorkflowsStorage {
1757
1797
  super();
1758
1798
  this.client = client;
1759
1799
  }
1800
+ updateWorkflowResults({
1801
+ // workflowName,
1802
+ // runId,
1803
+ // stepId,
1804
+ // result,
1805
+ // runtimeContext,
1806
+ }) {
1807
+ throw new Error("Method not implemented.");
1808
+ }
1809
+ updateWorkflowState({
1810
+ // workflowName,
1811
+ // runId,
1812
+ // opts,
1813
+ }) {
1814
+ throw new Error("Method not implemented.");
1815
+ }
1760
1816
  async persistWorkflowSnapshot({
1761
1817
  workflowName,
1762
1818
  runId,
@@ -2087,6 +2143,12 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
2087
2143
  }) {
2088
2144
  return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format, threadConfig });
2089
2145
  }
2146
+ async getMessagesById({
2147
+ messageIds,
2148
+ format
2149
+ }) {
2150
+ return this.stores.memory.getMessagesById({ messageIds, format });
2151
+ }
2090
2152
  async saveMessages(args) {
2091
2153
  return this.stores.memory.saveMessages(args);
2092
2154
  }
@@ -2120,6 +2182,22 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
2120
2182
  async getWorkflowRunById(args) {
2121
2183
  return this.stores.workflows.getWorkflowRunById(args);
2122
2184
  }
2185
+ async updateWorkflowResults({
2186
+ workflowName,
2187
+ runId,
2188
+ stepId,
2189
+ result,
2190
+ runtimeContext
2191
+ }) {
2192
+ return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
2193
+ }
2194
+ async updateWorkflowState({
2195
+ workflowName,
2196
+ runId,
2197
+ opts
2198
+ }) {
2199
+ return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
2200
+ }
2123
2201
  async persistWorkflowSnapshot({
2124
2202
  workflowName,
2125
2203
  runId,