@mastra/cloudflare-d1 0.13.2 → 0.13.3
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 +22 -0
- package/dist/index.cjs +72 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +72 -4
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +8 -0
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +9 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @mastra/cloudflare-d1
|
|
2
2
|
|
|
3
|
+
## 0.13.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Update peer deps ([#8154](https://github.com/mastra-ai/mastra/pull/8154))
|
|
8
|
+
|
|
9
|
+
- Cloudflare D1 support fetch scores by trace and span id ([#8154](https://github.com/mastra-ai/mastra/pull/8154))
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`dc099b4`](https://github.com/mastra-ai/mastra/commit/dc099b40fb31147ba3f362f98d991892033c4c67), [`504438b`](https://github.com/mastra-ai/mastra/commit/504438b961bde211071186bba63a842c4e3db879), [`b342a68`](https://github.com/mastra-ai/mastra/commit/b342a68e1399cf1ece9ba11bda112db89d21118c), [`a7243e2`](https://github.com/mastra-ai/mastra/commit/a7243e2e58762667a6e3921e755e89d6bb0a3282), [`7fceb0a`](https://github.com/mastra-ai/mastra/commit/7fceb0a327d678e812f90f5387c5bc4f38bd039e), [`303a9c0`](https://github.com/mastra-ai/mastra/commit/303a9c0d7dd58795915979f06a0512359e4532fb), [`df64f9e`](https://github.com/mastra-ai/mastra/commit/df64f9ef814916fff9baedd861c988084e7c41de), [`370f8a6`](https://github.com/mastra-ai/mastra/commit/370f8a6480faec70fef18d72e5f7538f27004301), [`809eea0`](https://github.com/mastra-ai/mastra/commit/809eea092fa80c3f69b9eaf078d843b57fd2a88e), [`683e5a1`](https://github.com/mastra-ai/mastra/commit/683e5a1466e48b686825b2c11f84680f296138e4), [`3679378`](https://github.com/mastra-ai/mastra/commit/3679378673350aa314741dc826f837b1984149bc), [`7775bc2`](https://github.com/mastra-ai/mastra/commit/7775bc20bb1ad1ab24797fb420e4f96c65b0d8ec), [`623ffaf`](https://github.com/mastra-ai/mastra/commit/623ffaf2d969e11e99a0224633cf7b5a0815c857), [`9fc1613`](https://github.com/mastra-ai/mastra/commit/9fc16136400186648880fd990119ac15f7c02ee4), [`61f62aa`](https://github.com/mastra-ai/mastra/commit/61f62aa31bc88fe4ddf8da6240dbcfbeb07358bd), [`db1891a`](https://github.com/mastra-ai/mastra/commit/db1891a4707443720b7cd8a260dc7e1d49b3609c), [`e8f379d`](https://github.com/mastra-ai/mastra/commit/e8f379d390efa264c4e0874f9ac0cf8839b07777), [`652066b`](https://github.com/mastra-ai/mastra/commit/652066bd1efc6bb6813ba950ed1d7573e8b7d9d4), [`3e292ba`](https://github.com/mastra-ai/mastra/commit/3e292ba00837886d5d68a34cbc0d9b703c991883), [`418c136`](https://github.com/mastra-ai/mastra/commit/418c1366843d88e491bca3f87763899ce855ca29), [`ea8d386`](https://github.com/mastra-ai/mastra/commit/ea8d386cd8c5593664515fd5770c06bf2aa980ef), [`67b0f00`](https://github.com/mastra-ai/mastra/commit/67b0f005b520335c71fb85cbaa25df4ce8484a81), [`c2a4919`](https://github.com/mastra-ai/mastra/commit/c2a4919ba6797d8bdb1509e02287496eef69303e), [`c84b7d0`](https://github.com/mastra-ai/mastra/commit/c84b7d093c4657772140cbfd2b15ef72f3315ed5), [`0130986`](https://github.com/mastra-ai/mastra/commit/0130986fc62d0edcc626dd593282661dbb9af141)]:
|
|
12
|
+
- @mastra/core@0.19.0
|
|
13
|
+
|
|
14
|
+
## 0.13.3-alpha.0
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Update peer deps ([#8154](https://github.com/mastra-ai/mastra/pull/8154))
|
|
19
|
+
|
|
20
|
+
- Cloudflare D1 support fetch scores by trace and span id ([#8154](https://github.com/mastra-ai/mastra/pull/8154))
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [[`504438b`](https://github.com/mastra-ai/mastra/commit/504438b961bde211071186bba63a842c4e3db879), [`a7243e2`](https://github.com/mastra-ai/mastra/commit/a7243e2e58762667a6e3921e755e89d6bb0a3282), [`7fceb0a`](https://github.com/mastra-ai/mastra/commit/7fceb0a327d678e812f90f5387c5bc4f38bd039e), [`df64f9e`](https://github.com/mastra-ai/mastra/commit/df64f9ef814916fff9baedd861c988084e7c41de), [`809eea0`](https://github.com/mastra-ai/mastra/commit/809eea092fa80c3f69b9eaf078d843b57fd2a88e), [`683e5a1`](https://github.com/mastra-ai/mastra/commit/683e5a1466e48b686825b2c11f84680f296138e4), [`3679378`](https://github.com/mastra-ai/mastra/commit/3679378673350aa314741dc826f837b1984149bc), [`7775bc2`](https://github.com/mastra-ai/mastra/commit/7775bc20bb1ad1ab24797fb420e4f96c65b0d8ec), [`db1891a`](https://github.com/mastra-ai/mastra/commit/db1891a4707443720b7cd8a260dc7e1d49b3609c), [`e8f379d`](https://github.com/mastra-ai/mastra/commit/e8f379d390efa264c4e0874f9ac0cf8839b07777), [`652066b`](https://github.com/mastra-ai/mastra/commit/652066bd1efc6bb6813ba950ed1d7573e8b7d9d4), [`ea8d386`](https://github.com/mastra-ai/mastra/commit/ea8d386cd8c5593664515fd5770c06bf2aa980ef), [`c2a4919`](https://github.com/mastra-ai/mastra/commit/c2a4919ba6797d8bdb1509e02287496eef69303e), [`0130986`](https://github.com/mastra-ai/mastra/commit/0130986fc62d0edcc626dd593282661dbb9af141)]:
|
|
23
|
+
- @mastra/core@0.19.0-alpha.1
|
|
24
|
+
|
|
3
25
|
## 0.13.2
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -5,6 +5,7 @@ var storage = require('@mastra/core/storage');
|
|
|
5
5
|
var Cloudflare = require('cloudflare');
|
|
6
6
|
var utils = require('@mastra/core/utils');
|
|
7
7
|
var agent = require('@mastra/core/agent');
|
|
8
|
+
var scores = require('@mastra/core/scores');
|
|
8
9
|
|
|
9
10
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
11
|
|
|
@@ -1615,12 +1616,25 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
1615
1616
|
}
|
|
1616
1617
|
}
|
|
1617
1618
|
async saveScore(score) {
|
|
1619
|
+
let parsedScore;
|
|
1620
|
+
try {
|
|
1621
|
+
parsedScore = scores.saveScorePayloadSchema.parse(score);
|
|
1622
|
+
} catch (error$1) {
|
|
1623
|
+
throw new error.MastraError(
|
|
1624
|
+
{
|
|
1625
|
+
id: "CLOUDFLARE_D1_STORE_SCORES_SAVE_SCORE_FAILED_INVALID_SCORE_PAYLOAD",
|
|
1626
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1627
|
+
category: error.ErrorCategory.USER,
|
|
1628
|
+
details: { scoreId: score.id }
|
|
1629
|
+
},
|
|
1630
|
+
error$1
|
|
1631
|
+
);
|
|
1632
|
+
}
|
|
1618
1633
|
try {
|
|
1619
1634
|
const id = crypto.randomUUID();
|
|
1620
1635
|
const fullTableName = this.operations.getTableName(storage.TABLE_SCORERS);
|
|
1621
|
-
const { input, ...rest } = score;
|
|
1622
1636
|
const serializedRecord = {};
|
|
1623
|
-
for (const [key, value] of Object.entries(
|
|
1637
|
+
for (const [key, value] of Object.entries(parsedScore)) {
|
|
1624
1638
|
if (value !== null && value !== void 0) {
|
|
1625
1639
|
if (typeof value === "object") {
|
|
1626
1640
|
serializedRecord[key] = JSON.stringify(value);
|
|
@@ -1632,7 +1646,6 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
1632
1646
|
}
|
|
1633
1647
|
}
|
|
1634
1648
|
serializedRecord.id = id;
|
|
1635
|
-
serializedRecord.input = JSON.stringify(input);
|
|
1636
1649
|
serializedRecord.createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1637
1650
|
serializedRecord.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1638
1651
|
const columns = Object.keys(serializedRecord);
|
|
@@ -1808,6 +1821,53 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
1808
1821
|
);
|
|
1809
1822
|
}
|
|
1810
1823
|
}
|
|
1824
|
+
async getScoresBySpan({
|
|
1825
|
+
traceId,
|
|
1826
|
+
spanId,
|
|
1827
|
+
pagination
|
|
1828
|
+
}) {
|
|
1829
|
+
try {
|
|
1830
|
+
const fullTableName = this.operations.getTableName(storage.TABLE_SCORERS);
|
|
1831
|
+
const countQuery = createSqlBuilder().count().from(fullTableName).where("traceId = ?", traceId).andWhere("spanId = ?", spanId);
|
|
1832
|
+
const countResult = await this.operations.executeQuery(countQuery.build());
|
|
1833
|
+
const total = Array.isArray(countResult) ? Number(countResult?.[0]?.count ?? 0) : Number(countResult?.count ?? 0);
|
|
1834
|
+
if (total === 0) {
|
|
1835
|
+
return {
|
|
1836
|
+
pagination: {
|
|
1837
|
+
total: 0,
|
|
1838
|
+
page: pagination.page,
|
|
1839
|
+
perPage: pagination.perPage,
|
|
1840
|
+
hasMore: false
|
|
1841
|
+
},
|
|
1842
|
+
scores: []
|
|
1843
|
+
};
|
|
1844
|
+
}
|
|
1845
|
+
const limit = pagination.perPage + 1;
|
|
1846
|
+
const selectQuery = createSqlBuilder().select("*").from(fullTableName).where("traceId = ?", traceId).andWhere("spanId = ?", spanId).orderBy("createdAt", "DESC").limit(limit).offset(pagination.page * pagination.perPage);
|
|
1847
|
+
const { sql, params } = selectQuery.build();
|
|
1848
|
+
const results = await this.operations.executeQuery({ sql, params });
|
|
1849
|
+
const rows = Array.isArray(results) ? results : [];
|
|
1850
|
+
const scores = rows.slice(0, pagination.perPage).map(transformScoreRow);
|
|
1851
|
+
return {
|
|
1852
|
+
pagination: {
|
|
1853
|
+
total,
|
|
1854
|
+
page: pagination.page,
|
|
1855
|
+
perPage: pagination.perPage,
|
|
1856
|
+
hasMore: rows.length > pagination.perPage
|
|
1857
|
+
},
|
|
1858
|
+
scores
|
|
1859
|
+
};
|
|
1860
|
+
} catch (error$1) {
|
|
1861
|
+
throw new error.MastraError(
|
|
1862
|
+
{
|
|
1863
|
+
id: "CLOUDFLARE_D1_STORE_SCORES_GET_SCORES_BY_SPAN_FAILED",
|
|
1864
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1865
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
1866
|
+
},
|
|
1867
|
+
error$1
|
|
1868
|
+
);
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1811
1871
|
};
|
|
1812
1872
|
function isArrayOfRecords2(value) {
|
|
1813
1873
|
return value && Array.isArray(value) && value.length > 0;
|
|
@@ -2239,7 +2299,8 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
2239
2299
|
resourceWorkingMemory: true,
|
|
2240
2300
|
hasColumn: true,
|
|
2241
2301
|
createTable: true,
|
|
2242
|
-
deleteMessages: false
|
|
2302
|
+
deleteMessages: false,
|
|
2303
|
+
getScoresBySpan: true
|
|
2243
2304
|
};
|
|
2244
2305
|
}
|
|
2245
2306
|
async createTable({
|
|
@@ -2441,6 +2502,13 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
2441
2502
|
}) {
|
|
2442
2503
|
return this.stores.scores.getScoresByScorerId({ scorerId, pagination, entityId, entityType, source });
|
|
2443
2504
|
}
|
|
2505
|
+
async getScoresBySpan({
|
|
2506
|
+
traceId,
|
|
2507
|
+
spanId,
|
|
2508
|
+
pagination
|
|
2509
|
+
}) {
|
|
2510
|
+
return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
|
|
2511
|
+
}
|
|
2444
2512
|
/**
|
|
2445
2513
|
* Close the database connection
|
|
2446
2514
|
* No explicit cleanup needed for D1 in either REST or Workers Binding mode
|