@mastra/cloudflare-d1 0.0.0-stream-vnext-usage-20250908171242 → 0.0.0-suspendRuntimeContextTypeFix-20250930142630
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 +65 -3
- package/dist/index.cjs +78 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +78 -6
- 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/domains/workflows/index.d.ts +2 -1
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +11 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { MastraStorage, StoreOperations, ScoresStorage, TABLE_SCORERS, LegacyEva
|
|
|
3
3
|
import Cloudflare from 'cloudflare';
|
|
4
4
|
import { parseSqlIdentifier } from '@mastra/core/utils';
|
|
5
5
|
import { MessageList } from '@mastra/core/agent';
|
|
6
|
+
import { saveScorePayloadSchema } from '@mastra/core/scores';
|
|
6
7
|
|
|
7
8
|
// src/storage/index.ts
|
|
8
9
|
var SqlBuilder = class {
|
|
@@ -1609,12 +1610,25 @@ var ScoresStorageD1 = class extends ScoresStorage {
|
|
|
1609
1610
|
}
|
|
1610
1611
|
}
|
|
1611
1612
|
async saveScore(score) {
|
|
1613
|
+
let parsedScore;
|
|
1614
|
+
try {
|
|
1615
|
+
parsedScore = saveScorePayloadSchema.parse(score);
|
|
1616
|
+
} catch (error) {
|
|
1617
|
+
throw new MastraError(
|
|
1618
|
+
{
|
|
1619
|
+
id: "CLOUDFLARE_D1_STORE_SCORES_SAVE_SCORE_FAILED_INVALID_SCORE_PAYLOAD",
|
|
1620
|
+
domain: ErrorDomain.STORAGE,
|
|
1621
|
+
category: ErrorCategory.USER,
|
|
1622
|
+
details: { scoreId: score.id }
|
|
1623
|
+
},
|
|
1624
|
+
error
|
|
1625
|
+
);
|
|
1626
|
+
}
|
|
1612
1627
|
try {
|
|
1613
1628
|
const id = crypto.randomUUID();
|
|
1614
1629
|
const fullTableName = this.operations.getTableName(TABLE_SCORERS);
|
|
1615
|
-
const { input, ...rest } = score;
|
|
1616
1630
|
const serializedRecord = {};
|
|
1617
|
-
for (const [key, value] of Object.entries(
|
|
1631
|
+
for (const [key, value] of Object.entries(parsedScore)) {
|
|
1618
1632
|
if (value !== null && value !== void 0) {
|
|
1619
1633
|
if (typeof value === "object") {
|
|
1620
1634
|
serializedRecord[key] = JSON.stringify(value);
|
|
@@ -1626,7 +1640,6 @@ var ScoresStorageD1 = class extends ScoresStorage {
|
|
|
1626
1640
|
}
|
|
1627
1641
|
}
|
|
1628
1642
|
serializedRecord.id = id;
|
|
1629
|
-
serializedRecord.input = JSON.stringify(input);
|
|
1630
1643
|
serializedRecord.createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1631
1644
|
serializedRecord.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1632
1645
|
const columns = Object.keys(serializedRecord);
|
|
@@ -1802,6 +1815,53 @@ var ScoresStorageD1 = class extends ScoresStorage {
|
|
|
1802
1815
|
);
|
|
1803
1816
|
}
|
|
1804
1817
|
}
|
|
1818
|
+
async getScoresBySpan({
|
|
1819
|
+
traceId,
|
|
1820
|
+
spanId,
|
|
1821
|
+
pagination
|
|
1822
|
+
}) {
|
|
1823
|
+
try {
|
|
1824
|
+
const fullTableName = this.operations.getTableName(TABLE_SCORERS);
|
|
1825
|
+
const countQuery = createSqlBuilder().count().from(fullTableName).where("traceId = ?", traceId).andWhere("spanId = ?", spanId);
|
|
1826
|
+
const countResult = await this.operations.executeQuery(countQuery.build());
|
|
1827
|
+
const total = Array.isArray(countResult) ? Number(countResult?.[0]?.count ?? 0) : Number(countResult?.count ?? 0);
|
|
1828
|
+
if (total === 0) {
|
|
1829
|
+
return {
|
|
1830
|
+
pagination: {
|
|
1831
|
+
total: 0,
|
|
1832
|
+
page: pagination.page,
|
|
1833
|
+
perPage: pagination.perPage,
|
|
1834
|
+
hasMore: false
|
|
1835
|
+
},
|
|
1836
|
+
scores: []
|
|
1837
|
+
};
|
|
1838
|
+
}
|
|
1839
|
+
const limit = pagination.perPage + 1;
|
|
1840
|
+
const selectQuery = createSqlBuilder().select("*").from(fullTableName).where("traceId = ?", traceId).andWhere("spanId = ?", spanId).orderBy("createdAt", "DESC").limit(limit).offset(pagination.page * pagination.perPage);
|
|
1841
|
+
const { sql, params } = selectQuery.build();
|
|
1842
|
+
const results = await this.operations.executeQuery({ sql, params });
|
|
1843
|
+
const rows = Array.isArray(results) ? results : [];
|
|
1844
|
+
const scores = rows.slice(0, pagination.perPage).map(transformScoreRow);
|
|
1845
|
+
return {
|
|
1846
|
+
pagination: {
|
|
1847
|
+
total,
|
|
1848
|
+
page: pagination.page,
|
|
1849
|
+
perPage: pagination.perPage,
|
|
1850
|
+
hasMore: rows.length > pagination.perPage
|
|
1851
|
+
},
|
|
1852
|
+
scores
|
|
1853
|
+
};
|
|
1854
|
+
} catch (error) {
|
|
1855
|
+
throw new MastraError(
|
|
1856
|
+
{
|
|
1857
|
+
id: "CLOUDFLARE_D1_STORE_SCORES_GET_SCORES_BY_SPAN_FAILED",
|
|
1858
|
+
domain: ErrorDomain.STORAGE,
|
|
1859
|
+
category: ErrorCategory.THIRD_PARTY
|
|
1860
|
+
},
|
|
1861
|
+
error
|
|
1862
|
+
);
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1805
1865
|
};
|
|
1806
1866
|
function isArrayOfRecords2(value) {
|
|
1807
1867
|
return value && Array.isArray(value) && value.length > 0;
|
|
@@ -1879,7 +1939,7 @@ var TracesStorageD1 = class extends TracesStorage {
|
|
|
1879
1939
|
const allDataResult = await this.operations.executeQuery(
|
|
1880
1940
|
createSqlBuilder().select("*").from(fullTableName).where("1=1").build()
|
|
1881
1941
|
);
|
|
1882
|
-
console.
|
|
1942
|
+
console.info("allDataResult", allDataResult);
|
|
1883
1943
|
const countResult = await this.operations.executeQuery(countQuery.build());
|
|
1884
1944
|
const total = Number(countResult?.[0]?.count ?? 0);
|
|
1885
1945
|
dataQuery.orderBy("startTime", "DESC").limit(perPage).offset(page * perPage);
|
|
@@ -1950,6 +2010,7 @@ var WorkflowsStorageD1 = class extends WorkflowsStorage {
|
|
|
1950
2010
|
async persistWorkflowSnapshot({
|
|
1951
2011
|
workflowName,
|
|
1952
2012
|
runId,
|
|
2013
|
+
resourceId,
|
|
1953
2014
|
snapshot
|
|
1954
2015
|
}) {
|
|
1955
2016
|
const fullTableName = this.operations.getTableName(TABLE_WORKFLOW_SNAPSHOT);
|
|
@@ -1960,11 +2021,13 @@ var WorkflowsStorageD1 = class extends WorkflowsStorage {
|
|
|
1960
2021
|
});
|
|
1961
2022
|
const persisting = currentSnapshot ? {
|
|
1962
2023
|
...currentSnapshot,
|
|
2024
|
+
resourceId,
|
|
1963
2025
|
snapshot: JSON.stringify(snapshot),
|
|
1964
2026
|
updatedAt: now
|
|
1965
2027
|
} : {
|
|
1966
2028
|
workflow_name: workflowName,
|
|
1967
2029
|
run_id: runId,
|
|
2030
|
+
resourceId,
|
|
1968
2031
|
snapshot,
|
|
1969
2032
|
createdAt: now,
|
|
1970
2033
|
updatedAt: now
|
|
@@ -2230,7 +2293,8 @@ var D1Store = class extends MastraStorage {
|
|
|
2230
2293
|
resourceWorkingMemory: true,
|
|
2231
2294
|
hasColumn: true,
|
|
2232
2295
|
createTable: true,
|
|
2233
|
-
deleteMessages: false
|
|
2296
|
+
deleteMessages: false,
|
|
2297
|
+
getScoresBySpan: true
|
|
2234
2298
|
};
|
|
2235
2299
|
}
|
|
2236
2300
|
async createTable({
|
|
@@ -2334,9 +2398,10 @@ var D1Store = class extends MastraStorage {
|
|
|
2334
2398
|
async persistWorkflowSnapshot({
|
|
2335
2399
|
workflowName,
|
|
2336
2400
|
runId,
|
|
2401
|
+
resourceId,
|
|
2337
2402
|
snapshot
|
|
2338
2403
|
}) {
|
|
2339
|
-
return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, snapshot });
|
|
2404
|
+
return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
|
|
2340
2405
|
}
|
|
2341
2406
|
async loadWorkflowSnapshot(params) {
|
|
2342
2407
|
return this.stores.workflows.loadWorkflowSnapshot(params);
|
|
@@ -2431,6 +2496,13 @@ var D1Store = class extends MastraStorage {
|
|
|
2431
2496
|
}) {
|
|
2432
2497
|
return this.stores.scores.getScoresByScorerId({ scorerId, pagination, entityId, entityType, source });
|
|
2433
2498
|
}
|
|
2499
|
+
async getScoresBySpan({
|
|
2500
|
+
traceId,
|
|
2501
|
+
spanId,
|
|
2502
|
+
pagination
|
|
2503
|
+
}) {
|
|
2504
|
+
return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
|
|
2505
|
+
}
|
|
2434
2506
|
/**
|
|
2435
2507
|
* Close the database connection
|
|
2436
2508
|
* No explicit cleanup needed for D1 in either REST or Workers Binding mode
|