@mastra/lance 1.0.4 → 1.0.5
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/CHANGELOG.md +18 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-storage-lance.md +1 -1
- package/dist/index.cjs +188 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +189 -6
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/background-tasks/index.d.ts +19 -0
- package/dist/storage/domains/background-tasks/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +2 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @mastra/lance
|
|
2
2
|
|
|
3
|
+
## 1.0.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add `BackgroundTasksStorage` domain implementation so `@mastra/core` background task execution works with any storage adapter. ([#15307](https://github.com/mastra-ai/mastra/pull/15307))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`20f59b8`](https://github.com/mastra-ai/mastra/commit/20f59b876cf91199efbc49a0e36b391240708f08), [`aba393e`](https://github.com/mastra-ai/mastra/commit/aba393e2da7390c69b80e516a4f153cda6f09376), [`3d83d06`](https://github.com/mastra-ai/mastra/commit/3d83d06f776f00fb5f4163dddd32a030c5c20844), [`e2687a7`](https://github.com/mastra-ai/mastra/commit/e2687a7408790c384563816a9a28ed06735684c9), [`fdd54cf`](https://github.com/mastra-ai/mastra/commit/fdd54cf612a9af876e9fdd85e534454f6e7dd518), [`6315317`](https://github.com/mastra-ai/mastra/commit/63153175fe9a7b224e5be7c209bbebc01dd9b0d5), [`a371ac5`](https://github.com/mastra-ai/mastra/commit/a371ac534aa1bb368a1acf9d8b313378dfdc787e), [`0474c2b`](https://github.com/mastra-ai/mastra/commit/0474c2b2e7c7e1ad8691dca031284841391ff1ef), [`0a5fa1d`](https://github.com/mastra-ai/mastra/commit/0a5fa1d3cb0583889d06687155f26fd7d2edc76c), [`7e0e63e`](https://github.com/mastra-ai/mastra/commit/7e0e63e2e485e84442351f4c7a79a424c83539dc), [`ea43e64`](https://github.com/mastra-ai/mastra/commit/ea43e646dd95d507694b6112b0bf1df22ad552b2), [`f607106`](https://github.com/mastra-ai/mastra/commit/f607106854c6416c4a07d4082604b9f66d047221), [`30456b6`](https://github.com/mastra-ai/mastra/commit/30456b6b08c8fd17e109dd093b73d93b65e83bc5), [`9d11a8c`](https://github.com/mastra-ai/mastra/commit/9d11a8c1c8924eb975a245a5884d40ca1b7e0491), [`9d3b24b`](https://github.com/mastra-ai/mastra/commit/9d3b24b19407ae9c09586cf7766d38dc4dff4a69), [`00d1b16`](https://github.com/mastra-ai/mastra/commit/00d1b16b401199cb294fa23f43336547db4dca9b), [`47cee3e`](https://github.com/mastra-ai/mastra/commit/47cee3e137fe39109cf7fffd2a8cf47b76dc702e), [`62919a6`](https://github.com/mastra-ai/mastra/commit/62919a6ee0fbf3779ad21a97b1ec6696515d5104), [`d246696`](https://github.com/mastra-ai/mastra/commit/d246696139a3144a5b21b042d41c532688e957e1), [`354f9ce`](https://github.com/mastra-ai/mastra/commit/354f9ce1ca6af2074b6a196a23f8ec30012dccca), [`16e34ca`](https://github.com/mastra-ai/mastra/commit/16e34caa98b9a114b17a6125e4e3fd87f169d0d0), [`7020c06`](https://github.com/mastra-ai/mastra/commit/7020c0690b199d9da337f0e805f16948e557922e), [`8786a61`](https://github.com/mastra-ai/mastra/commit/8786a61fa54ba265f85eeff9985ca39863d18bb6), [`9467ea8`](https://github.com/mastra-ai/mastra/commit/9467ea87695749a53dfc041576410ebf9ee7bb67), [`7338d94`](https://github.com/mastra-ai/mastra/commit/7338d949380cf68b095342e8e42610dc51d557c1), [`c80dc16`](https://github.com/mastra-ai/mastra/commit/c80dc16e113e6cc159f510ffde501ad4711b2189), [`af8a57e`](https://github.com/mastra-ai/mastra/commit/af8a57ed9ba9685ad8601d5b71ae3706da6222f9), [`d63ffdb`](https://github.com/mastra-ai/mastra/commit/d63ffdbb2c11e76fe5ea45faab44bc15460f010c), [`47cee3e`](https://github.com/mastra-ai/mastra/commit/47cee3e137fe39109cf7fffd2a8cf47b76dc702e), [`1bd5104`](https://github.com/mastra-ai/mastra/commit/1bd51048b6da93507276d6623e3fd96a9e1a8944), [`e9837b5`](https://github.com/mastra-ai/mastra/commit/e9837b53699e18711b09e0ca010a4106376f2653), [`8f1b280`](https://github.com/mastra-ai/mastra/commit/8f1b280b7fe6999ec654f160cb69c1a8719e7a57), [`92dcf02`](https://github.com/mastra-ai/mastra/commit/92dcf029294210ac91b090900c1a0555a425c57a), [`0fd90a2`](https://github.com/mastra-ai/mastra/commit/0fd90a215caf5fca8099c15a67ca03e4427747a3), [`8fb2405`](https://github.com/mastra-ai/mastra/commit/8fb2405138f2d208b7962ad03f121ca25bcc28c5), [`12df98c`](https://github.com/mastra-ai/mastra/commit/12df98c4904643d9481f5c78f3bed443725b4c96)]:
|
|
10
|
+
- @mastra/core@1.26.0
|
|
11
|
+
|
|
12
|
+
## 1.0.5-alpha.0
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Add `BackgroundTasksStorage` domain implementation so `@mastra/core` background task execution works with any storage adapter. ([#15307](https://github.com/mastra-ai/mastra/pull/15307))
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [[`d63ffdb`](https://github.com/mastra-ai/mastra/commit/d63ffdbb2c11e76fe5ea45faab44bc15460f010c)]:
|
|
19
|
+
- @mastra/core@1.25.1-alpha.0
|
|
20
|
+
|
|
3
21
|
## 1.0.4
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The LanceDB storage implementation provides a high-performance storage solution using the LanceDB database system, which excels at handling both traditional data storage and vector operations.
|
|
4
4
|
|
|
5
|
-
> **Observability Not Supported:** LanceDB storage **doesn't support the observability domain**. Traces from the `DefaultExporter` can't be persisted to LanceDB, and
|
|
5
|
+
> **Observability Not Supported:** LanceDB storage **doesn't support the observability domain**. Traces from the `DefaultExporter` can't be persisted to LanceDB, and [Studio's](https://mastra.ai/docs/studio/overview) observability features won't work with LanceDB as your only storage provider. To enable observability, use [composite storage](https://mastra.ai/reference/storage/composite) to route observability data to a supported provider like ClickHouse or PostgreSQL.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
package/dist/index.cjs
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
var lancedb = require('@lancedb/lancedb');
|
|
4
4
|
var error = require('@mastra/core/error');
|
|
5
5
|
var storage = require('@mastra/core/storage');
|
|
6
|
-
var agent = require('@mastra/core/agent');
|
|
7
6
|
var base = require('@mastra/core/base');
|
|
8
7
|
var apacheArrow = require('apache-arrow');
|
|
8
|
+
var agent = require('@mastra/core/agent');
|
|
9
9
|
var evals = require('@mastra/core/evals');
|
|
10
10
|
var vector = require('@mastra/core/vector');
|
|
11
11
|
var filter = require('@mastra/core/vector/filter');
|
|
@@ -589,7 +589,188 @@ var LanceDB = class extends base.MastraBase {
|
|
|
589
589
|
}
|
|
590
590
|
};
|
|
591
591
|
|
|
592
|
-
// src/storage/domains/
|
|
592
|
+
// src/storage/domains/background-tasks/index.ts
|
|
593
|
+
function serializeJson(v) {
|
|
594
|
+
if (typeof v === "object" && v != null) return JSON.stringify(v);
|
|
595
|
+
return v ?? void 0;
|
|
596
|
+
}
|
|
597
|
+
function toRecord(task) {
|
|
598
|
+
return {
|
|
599
|
+
id: task.id,
|
|
600
|
+
tool_call_id: task.toolCallId,
|
|
601
|
+
tool_name: task.toolName,
|
|
602
|
+
agent_id: task.agentId,
|
|
603
|
+
thread_id: task.threadId ?? "",
|
|
604
|
+
resource_id: task.resourceId ?? "",
|
|
605
|
+
run_id: task.runId,
|
|
606
|
+
status: task.status,
|
|
607
|
+
args: serializeJson(task.args),
|
|
608
|
+
result: serializeJson(task.result),
|
|
609
|
+
error: serializeJson(task.error),
|
|
610
|
+
retry_count: task.retryCount,
|
|
611
|
+
max_retries: task.maxRetries,
|
|
612
|
+
timeout_ms: task.timeoutMs,
|
|
613
|
+
createdAt: task.createdAt,
|
|
614
|
+
startedAt: task.startedAt ?? /* @__PURE__ */ new Date(0),
|
|
615
|
+
completedAt: task.completedAt ?? /* @__PURE__ */ new Date(0)
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
function fromRecord(row) {
|
|
619
|
+
const parseJson = (val) => {
|
|
620
|
+
if (val == null || val === "") return void 0;
|
|
621
|
+
if (typeof val === "string") {
|
|
622
|
+
try {
|
|
623
|
+
return JSON.parse(val);
|
|
624
|
+
} catch {
|
|
625
|
+
return val;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
return val;
|
|
629
|
+
};
|
|
630
|
+
const startedAt = row.startedAt instanceof Date ? row.startedAt : row.startedAt ? new Date(row.startedAt) : void 0;
|
|
631
|
+
const completedAt = row.completedAt instanceof Date ? row.completedAt : row.completedAt ? new Date(row.completedAt) : void 0;
|
|
632
|
+
return {
|
|
633
|
+
id: String(row.id),
|
|
634
|
+
status: String(row.status),
|
|
635
|
+
toolName: String(row.tool_name),
|
|
636
|
+
toolCallId: String(row.tool_call_id),
|
|
637
|
+
args: parseJson(row.args) ?? {},
|
|
638
|
+
agentId: String(row.agent_id),
|
|
639
|
+
threadId: row.thread_id && row.thread_id !== "" ? String(row.thread_id) : void 0,
|
|
640
|
+
resourceId: row.resource_id && row.resource_id !== "" ? String(row.resource_id) : void 0,
|
|
641
|
+
runId: row.run_id ?? "",
|
|
642
|
+
result: parseJson(row.result),
|
|
643
|
+
error: parseJson(row.error),
|
|
644
|
+
retryCount: Number(row.retry_count ?? 0),
|
|
645
|
+
maxRetries: Number(row.max_retries ?? 0),
|
|
646
|
+
timeoutMs: Number(row.timeout_ms ?? 3e5),
|
|
647
|
+
createdAt: row.createdAt instanceof Date ? row.createdAt : new Date(row.createdAt),
|
|
648
|
+
startedAt: startedAt && startedAt.getTime() > 0 ? startedAt : void 0,
|
|
649
|
+
completedAt: completedAt && completedAt.getTime() > 0 ? completedAt : void 0
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
function escapeStr(val) {
|
|
653
|
+
return val.replace(/'/g, "''");
|
|
654
|
+
}
|
|
655
|
+
var StoreBackgroundTasksLance = class extends storage.BackgroundTasksStorage {
|
|
656
|
+
client;
|
|
657
|
+
#db;
|
|
658
|
+
constructor(config) {
|
|
659
|
+
super();
|
|
660
|
+
const client = resolveLanceConfig(config);
|
|
661
|
+
this.client = client;
|
|
662
|
+
this.#db = new LanceDB({ client });
|
|
663
|
+
}
|
|
664
|
+
async init() {
|
|
665
|
+
await this.#db.createTable({
|
|
666
|
+
tableName: storage.TABLE_BACKGROUND_TASKS,
|
|
667
|
+
schema: storage.TABLE_SCHEMAS[storage.TABLE_BACKGROUND_TASKS]
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
async dangerouslyClearAll() {
|
|
671
|
+
await this.#db.clearTable({ tableName: storage.TABLE_BACKGROUND_TASKS });
|
|
672
|
+
}
|
|
673
|
+
async createTask(task) {
|
|
674
|
+
const table = await this.client.openTable(storage.TABLE_BACKGROUND_TASKS);
|
|
675
|
+
await table.add([toRecord(task)], { mode: "append" });
|
|
676
|
+
}
|
|
677
|
+
async updateTask(taskId, update) {
|
|
678
|
+
const existing = await this.getTask(taskId);
|
|
679
|
+
if (!existing) return;
|
|
680
|
+
const merged = { ...existing };
|
|
681
|
+
if ("status" in update) merged.status = update.status;
|
|
682
|
+
if ("result" in update) merged.result = update.result;
|
|
683
|
+
if ("error" in update) merged.error = update.error;
|
|
684
|
+
if ("retryCount" in update) merged.retryCount = update.retryCount;
|
|
685
|
+
if ("startedAt" in update) merged.startedAt = update.startedAt;
|
|
686
|
+
if ("completedAt" in update) merged.completedAt = update.completedAt;
|
|
687
|
+
const table = await this.client.openTable(storage.TABLE_BACKGROUND_TASKS);
|
|
688
|
+
await table.delete(`id = '${escapeStr(taskId)}'`);
|
|
689
|
+
await table.add([toRecord(merged)], { mode: "append" });
|
|
690
|
+
}
|
|
691
|
+
async getTask(taskId) {
|
|
692
|
+
try {
|
|
693
|
+
const table = await this.client.openTable(storage.TABLE_BACKGROUND_TASKS);
|
|
694
|
+
const records = await table.query().where(`id = '${escapeStr(taskId)}'`).limit(1).toArray();
|
|
695
|
+
if (records.length === 0) return null;
|
|
696
|
+
return fromRecord(records[0]);
|
|
697
|
+
} catch {
|
|
698
|
+
return null;
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
async listTasks(filter) {
|
|
702
|
+
try {
|
|
703
|
+
const table = await this.client.openTable(storage.TABLE_BACKGROUND_TASKS);
|
|
704
|
+
const conditions = [];
|
|
705
|
+
if (filter.status) {
|
|
706
|
+
const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
|
|
707
|
+
const inList = statuses.map((s) => `'${escapeStr(s)}'`).join(", ");
|
|
708
|
+
conditions.push(`status IN (${inList})`);
|
|
709
|
+
}
|
|
710
|
+
if (filter.agentId) conditions.push(`agent_id = '${escapeStr(filter.agentId)}'`);
|
|
711
|
+
if (filter.threadId) conditions.push(`thread_id = '${escapeStr(filter.threadId)}'`);
|
|
712
|
+
if (filter.resourceId) conditions.push(`resource_id = '${escapeStr(filter.resourceId)}'`);
|
|
713
|
+
if (filter.runId) conditions.push(`run_id = '${escapeStr(filter.runId)}'`);
|
|
714
|
+
if (filter.toolName) conditions.push(`tool_name = '${escapeStr(filter.toolName)}'`);
|
|
715
|
+
let query = table.query();
|
|
716
|
+
if (conditions.length > 0) {
|
|
717
|
+
query = query.where(conditions.join(" AND "));
|
|
718
|
+
}
|
|
719
|
+
const records = await query.toArray();
|
|
720
|
+
let tasks = records.map(fromRecord);
|
|
721
|
+
const dateCol = filter.dateFilterBy ?? "createdAt";
|
|
722
|
+
if (filter.fromDate) {
|
|
723
|
+
tasks = tasks.filter((t) => {
|
|
724
|
+
const val = t[dateCol];
|
|
725
|
+
return val != null && val >= filter.fromDate;
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
if (filter.toDate) {
|
|
729
|
+
tasks = tasks.filter((t) => {
|
|
730
|
+
const val = t[dateCol];
|
|
731
|
+
return val != null && val < filter.toDate;
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
const orderBy = filter.orderBy ?? "createdAt";
|
|
735
|
+
const direction = filter.orderDirection ?? "asc";
|
|
736
|
+
tasks.sort((a, b) => {
|
|
737
|
+
const aVal = a[orderBy]?.getTime() ?? 0;
|
|
738
|
+
const bVal = b[orderBy]?.getTime() ?? 0;
|
|
739
|
+
return direction === "asc" ? aVal - bVal : bVal - aVal;
|
|
740
|
+
});
|
|
741
|
+
const total = tasks.length;
|
|
742
|
+
if (filter.page != null && filter.perPage != null) {
|
|
743
|
+
const start = filter.page * filter.perPage;
|
|
744
|
+
tasks = tasks.slice(start, start + filter.perPage);
|
|
745
|
+
} else if (filter.perPage != null) {
|
|
746
|
+
tasks = tasks.slice(0, filter.perPage);
|
|
747
|
+
}
|
|
748
|
+
return { tasks, total };
|
|
749
|
+
} catch {
|
|
750
|
+
return { tasks: [], total: 0 };
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
async deleteTask(taskId) {
|
|
754
|
+
const table = await this.client.openTable(storage.TABLE_BACKGROUND_TASKS);
|
|
755
|
+
await table.delete(`id = '${escapeStr(taskId)}'`);
|
|
756
|
+
}
|
|
757
|
+
async deleteTasks(filter) {
|
|
758
|
+
const { tasks } = await this.listTasks(filter);
|
|
759
|
+
if (tasks.length === 0) return;
|
|
760
|
+
const table = await this.client.openTable(storage.TABLE_BACKGROUND_TASKS);
|
|
761
|
+
for (const task of tasks) {
|
|
762
|
+
await table.delete(`id = '${escapeStr(task.id)}'`);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
async getRunningCount() {
|
|
766
|
+
const { total } = await this.listTasks({ status: "running" });
|
|
767
|
+
return total;
|
|
768
|
+
}
|
|
769
|
+
async getRunningCountByAgent(agentId) {
|
|
770
|
+
const { total } = await this.listTasks({ status: "running", agentId });
|
|
771
|
+
return total;
|
|
772
|
+
}
|
|
773
|
+
};
|
|
593
774
|
var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
594
775
|
client;
|
|
595
776
|
#db;
|
|
@@ -2010,7 +2191,8 @@ var LanceStorage = class _LanceStorage extends storage.MastraCompositeStore {
|
|
|
2010
2191
|
instance.stores = {
|
|
2011
2192
|
workflows: new StoreWorkflowsLance({ client: instance.lanceClient }),
|
|
2012
2193
|
scores: new StoreScoresLance({ client: instance.lanceClient }),
|
|
2013
|
-
memory: new StoreMemoryLance({ client: instance.lanceClient })
|
|
2194
|
+
memory: new StoreMemoryLance({ client: instance.lanceClient }),
|
|
2195
|
+
backgroundTasks: new StoreBackgroundTasksLance({ client: instance.lanceClient })
|
|
2014
2196
|
};
|
|
2015
2197
|
return instance;
|
|
2016
2198
|
} catch (e) {
|
|
@@ -2052,7 +2234,8 @@ var LanceStorage = class _LanceStorage extends storage.MastraCompositeStore {
|
|
|
2052
2234
|
instance.stores = {
|
|
2053
2235
|
workflows: new StoreWorkflowsLance({ client }),
|
|
2054
2236
|
scores: new StoreScoresLance({ client }),
|
|
2055
|
-
memory: new StoreMemoryLance({ client })
|
|
2237
|
+
memory: new StoreMemoryLance({ client }),
|
|
2238
|
+
backgroundTasks: new StoreBackgroundTasksLance({ client })
|
|
2056
2239
|
};
|
|
2057
2240
|
return instance;
|
|
2058
2241
|
}
|
|
@@ -3399,6 +3582,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3399
3582
|
|
|
3400
3583
|
exports.LanceStorage = LanceStorage;
|
|
3401
3584
|
exports.LanceVectorStore = LanceVectorStore;
|
|
3585
|
+
exports.StoreBackgroundTasksLance = StoreBackgroundTasksLance;
|
|
3402
3586
|
exports.StoreMemoryLance = StoreMemoryLance;
|
|
3403
3587
|
exports.StoreScoresLance = StoreScoresLance;
|
|
3404
3588
|
exports.StoreWorkflowsLance = StoreWorkflowsLance;
|