@mastra/cloudflare-d1 1.0.5 → 1.0.6-alpha.1
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 +28 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +35 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +35 -5
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/background-tasks/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +2 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @mastra/cloudflare-d1
|
|
2
2
|
|
|
3
|
+
## 1.0.6-alpha.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Respect optional `resourceId` in `getThreadById` so scoped thread lookups return `null` when the thread belongs to a different resource. ([#14237](https://github.com/mastra-ai/mastra/pull/14237))
|
|
8
|
+
|
|
9
|
+
Example:
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
const thread = await memory.getThreadById({
|
|
13
|
+
threadId: 'my-thread-id',
|
|
14
|
+
resourceId: 'my-user-id',
|
|
15
|
+
});
|
|
16
|
+
// Returns null if the thread does not belong to 'my-user-id'.
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [[`7c275a8`](https://github.com/mastra-ai/mastra/commit/7c275a810595e1a6c41ccc39720531ab65734700), [`890b24c`](https://github.com/mastra-ai/mastra/commit/890b24cc7d32ed6aa4dfe253e54dc6bf4099f690), [`0f48ebf`](https://github.com/mastra-ai/mastra/commit/0f48ebfc7ac7897b2092a189f45751924cf56d1c), [`f180e49`](https://github.com/mastra-ai/mastra/commit/f180e4990e71b04c9a475b523584071712f0048f), [`9260e01`](https://github.com/mastra-ai/mastra/commit/9260e015276fb1b500f7878ee452b47476bf1583), [`2f6c54e`](https://github.com/mastra-ai/mastra/commit/2f6c54e17c041cac1def54baaa6b771647836414), [`e06a159`](https://github.com/mastra-ai/mastra/commit/e06a1598ca07a6c3778aefc2a2d288363c6294ff), [`db34bc6`](https://github.com/mastra-ai/mastra/commit/db34bc6fb36cf125bda0c46be4d3fdc774b70cc4)]:
|
|
20
|
+
- @mastra/core@1.33.0-alpha.8
|
|
21
|
+
|
|
22
|
+
## 1.0.6-alpha.0
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Track `suspendedAt` and `suspendPayload` on background tasks. SQL adapters auto-migrate the new columns via `alterTable`. ([#16260](https://github.com/mastra-ai/mastra/pull/16260))
|
|
27
|
+
|
|
28
|
+
- Updated dependencies [[`9f17410`](https://github.com/mastra-ai/mastra/commit/9f1741080def23d42ee50b39887a385ae316a3c6), [`c6eb39e`](https://github.com/mastra-ai/mastra/commit/c6eb39ea6dca381c6563cb240237fbe608e02f93), [`900d086`](https://github.com/mastra-ai/mastra/commit/900d086bb737b9cf2fcf68f11b0389b801a2738c), [`4c0e286`](https://github.com/mastra-ai/mastra/commit/4c0e28637c9cfb4f416549b55e97ebfa13319dfc), [`25184ff`](https://github.com/mastra-ai/mastra/commit/25184ffaf1293ec95119426eb1a1f8d38831b96c), [`aebde9c`](https://github.com/mastra-ai/mastra/commit/aebde9cfacf56592c6b6350cae721740fe090b8a)]:
|
|
29
|
+
- @mastra/core@1.33.0-alpha.4
|
|
30
|
+
|
|
3
31
|
## 1.0.5
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-cloudflare-d1
|
|
|
3
3
|
description: Documentation for @mastra/cloudflare-d1. Use when working with @mastra/cloudflare-d1 APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/cloudflare-d1"
|
|
6
|
-
version: "1.0.
|
|
6
|
+
version: "1.0.6-alpha.1"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
package/dist/index.cjs
CHANGED
|
@@ -759,11 +759,13 @@ function rowToTask(row) {
|
|
|
759
759
|
runId: row.run_id ?? "",
|
|
760
760
|
result: parseJson(row.result),
|
|
761
761
|
error: parseJson(row.error),
|
|
762
|
+
suspendPayload: parseJson(row.suspend_payload),
|
|
762
763
|
retryCount: Number(row.retry_count ?? 0),
|
|
763
764
|
maxRetries: Number(row.max_retries ?? 0),
|
|
764
765
|
timeoutMs: Number(row.timeout_ms ?? 3e5),
|
|
765
766
|
createdAt: new Date(row.createdAt),
|
|
766
767
|
startedAt: row.startedAt ? new Date(row.startedAt) : void 0,
|
|
768
|
+
suspendedAt: row.suspendedAt ? new Date(row.suspendedAt) : void 0,
|
|
767
769
|
completedAt: row.completedAt ? new Date(row.completedAt) : void 0
|
|
768
770
|
};
|
|
769
771
|
}
|
|
@@ -776,6 +778,11 @@ var BackgroundTasksStorageD1 = class extends storage.BackgroundTasksStorage {
|
|
|
776
778
|
}
|
|
777
779
|
async init() {
|
|
778
780
|
await this.#db.createTable({ tableName: storage.TABLE_BACKGROUND_TASKS, schema: storage.TABLE_SCHEMAS[storage.TABLE_BACKGROUND_TASKS] });
|
|
781
|
+
await this.#db.alterTable({
|
|
782
|
+
tableName: storage.TABLE_BACKGROUND_TASKS,
|
|
783
|
+
schema: storage.TABLE_SCHEMAS[storage.TABLE_BACKGROUND_TASKS],
|
|
784
|
+
ifNotExists: ["suspend_payload", "suspendedAt"]
|
|
785
|
+
});
|
|
779
786
|
}
|
|
780
787
|
async dangerouslyClearAll() {
|
|
781
788
|
await this.#db.clearTable({ tableName: storage.TABLE_BACKGROUND_TASKS });
|
|
@@ -796,11 +803,13 @@ var BackgroundTasksStorageD1 = class extends storage.BackgroundTasksStorage {
|
|
|
796
803
|
"args",
|
|
797
804
|
"result",
|
|
798
805
|
"error",
|
|
806
|
+
"suspend_payload",
|
|
799
807
|
"retry_count",
|
|
800
808
|
"max_retries",
|
|
801
809
|
"timeout_ms",
|
|
802
810
|
"createdAt",
|
|
803
811
|
"startedAt",
|
|
812
|
+
"suspendedAt",
|
|
804
813
|
"completedAt"
|
|
805
814
|
],
|
|
806
815
|
[
|
|
@@ -815,11 +824,13 @@ var BackgroundTasksStorageD1 = class extends storage.BackgroundTasksStorage {
|
|
|
815
824
|
serializeJson(task.args),
|
|
816
825
|
serializeJson(task.result),
|
|
817
826
|
serializeJson(task.error),
|
|
827
|
+
serializeJson(task.suspendPayload),
|
|
818
828
|
task.retryCount,
|
|
819
829
|
task.maxRetries,
|
|
820
830
|
task.timeoutMs,
|
|
821
831
|
task.createdAt.toISOString(),
|
|
822
832
|
task.startedAt?.toISOString() ?? null,
|
|
833
|
+
task.suspendedAt?.toISOString() ?? null,
|
|
823
834
|
task.completedAt?.toISOString() ?? null
|
|
824
835
|
]
|
|
825
836
|
).build();
|
|
@@ -840,6 +851,10 @@ var BackgroundTasksStorageD1 = class extends storage.BackgroundTasksStorage {
|
|
|
840
851
|
sets.push("error = ?");
|
|
841
852
|
params.push(serializeJson(update.error));
|
|
842
853
|
}
|
|
854
|
+
if ("suspendPayload" in update) {
|
|
855
|
+
sets.push("suspend_payload = ?");
|
|
856
|
+
params.push(serializeJson(update.suspendPayload));
|
|
857
|
+
}
|
|
843
858
|
if ("retryCount" in update) {
|
|
844
859
|
sets.push("retry_count = ?");
|
|
845
860
|
params.push(update.retryCount);
|
|
@@ -848,6 +863,10 @@ var BackgroundTasksStorageD1 = class extends storage.BackgroundTasksStorage {
|
|
|
848
863
|
sets.push("startedAt = ?");
|
|
849
864
|
params.push(update.startedAt?.toISOString() ?? null);
|
|
850
865
|
}
|
|
866
|
+
if ("suspendedAt" in update) {
|
|
867
|
+
sets.push("suspendedAt = ?");
|
|
868
|
+
params.push(update.suspendedAt?.toISOString() ?? null);
|
|
869
|
+
}
|
|
851
870
|
if ("completedAt" in update) {
|
|
852
871
|
sets.push("completedAt = ?");
|
|
853
872
|
params.push(update.completedAt?.toISOString() ?? null);
|
|
@@ -891,7 +910,11 @@ var BackgroundTasksStorageD1 = class extends storage.BackgroundTasksStorage {
|
|
|
891
910
|
builder = builder.whereAnd("tool_name = ?", filter.toolName);
|
|
892
911
|
countBuilder = countBuilder.whereAnd("tool_name = ?", filter.toolName);
|
|
893
912
|
}
|
|
894
|
-
|
|
913
|
+
if (filter.toolCallId) {
|
|
914
|
+
builder = builder.whereAnd("tool_call_id = ?", filter.toolCallId);
|
|
915
|
+
countBuilder = countBuilder.whereAnd("tool_call_id = ?", filter.toolCallId);
|
|
916
|
+
}
|
|
917
|
+
const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "suspendedAt" ? "suspendedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : "createdAt";
|
|
895
918
|
if (filter.fromDate) {
|
|
896
919
|
builder = builder.whereAnd(`${dateCol} >= ?`, filter.fromDate.toISOString());
|
|
897
920
|
countBuilder = countBuilder.whereAnd(`${dateCol} >= ?`, filter.fromDate.toISOString());
|
|
@@ -903,7 +926,7 @@ var BackgroundTasksStorageD1 = class extends storage.BackgroundTasksStorage {
|
|
|
903
926
|
const { sql: countSql, params: countParams } = countBuilder.build();
|
|
904
927
|
const countRow = await this.#db.executeQuery({ sql: countSql, params: countParams, first: true });
|
|
905
928
|
const total = Number(countRow?.count ?? 0);
|
|
906
|
-
const orderCol = filter.orderBy === "startedAt" ? "startedAt" : filter.orderBy === "completedAt" ? "completedAt" : "createdAt";
|
|
929
|
+
const orderCol = filter.orderBy === "startedAt" ? "startedAt" : filter.orderBy === "suspendedAt" ? "suspendedAt" : filter.orderBy === "completedAt" ? "completedAt" : "createdAt";
|
|
907
930
|
builder = builder.orderBy(orderCol, filter.orderDirection === "desc" ? "DESC" : "ASC");
|
|
908
931
|
if (filter.perPage != null) {
|
|
909
932
|
builder = builder.limit(filter.perPage);
|
|
@@ -927,7 +950,7 @@ var BackgroundTasksStorageD1 = class extends storage.BackgroundTasksStorage {
|
|
|
927
950
|
conditions.push(`status IN (${statuses.map(() => "?").join(",")})`);
|
|
928
951
|
params.push(...statuses);
|
|
929
952
|
}
|
|
930
|
-
const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : "createdAt";
|
|
953
|
+
const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "suspendedAt" ? "suspendedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : "createdAt";
|
|
931
954
|
if (filter.fromDate) {
|
|
932
955
|
conditions.push(`${dateCol} >= ?`);
|
|
933
956
|
params.push(filter.fromDate.toISOString());
|
|
@@ -944,6 +967,10 @@ var BackgroundTasksStorageD1 = class extends storage.BackgroundTasksStorage {
|
|
|
944
967
|
conditions.push("run_id = ?");
|
|
945
968
|
params.push(filter.runId);
|
|
946
969
|
}
|
|
970
|
+
if (filter.toolCallId) {
|
|
971
|
+
conditions.push("tool_call_id = ?");
|
|
972
|
+
params.push(filter.toolCallId);
|
|
973
|
+
}
|
|
947
974
|
if (conditions.length === 0) return;
|
|
948
975
|
const fullTableName = this.#db.getTableName(storage.TABLE_BACKGROUND_TASKS);
|
|
949
976
|
await this.#db.executeQuery({
|
|
@@ -1103,12 +1130,15 @@ var MemoryStorageD1 = class extends storage.MemoryStorage {
|
|
|
1103
1130
|
);
|
|
1104
1131
|
}
|
|
1105
1132
|
}
|
|
1106
|
-
async getThreadById({
|
|
1133
|
+
async getThreadById({
|
|
1134
|
+
threadId,
|
|
1135
|
+
resourceId
|
|
1136
|
+
}) {
|
|
1107
1137
|
const thread = await this.#db.load({
|
|
1108
1138
|
tableName: storage.TABLE_THREADS,
|
|
1109
1139
|
keys: { id: threadId }
|
|
1110
1140
|
});
|
|
1111
|
-
if (!thread) return null;
|
|
1141
|
+
if (!thread || resourceId !== void 0 && thread.resourceId !== resourceId) return null;
|
|
1112
1142
|
try {
|
|
1113
1143
|
return {
|
|
1114
1144
|
...thread,
|