@mastra/cloudflare-d1 0.0.0-roamin-openaivoice-speak-options-passing-20250926163614 → 0.0.0-safe-stringify-telemetry-20251205024938
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 +143 -3
- package/dist/index.cjs +95 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +95 -30
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts.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 -9
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +11 -9
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +16 -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 {
|
|
@@ -1045,17 +1046,16 @@ var MemoryStorageD1 = class extends MemoryStorage {
|
|
|
1045
1046
|
}
|
|
1046
1047
|
return processedMsg;
|
|
1047
1048
|
});
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
messages.push(...format === `v2` ? list.get.all.v2() : list.get.all.v1());
|
|
1049
|
+
const allMessages = [...messages, ...processedMessages];
|
|
1050
|
+
const list = new MessageList().add(allMessages, "memory");
|
|
1051
|
+
let finalMessages = format === `v2` ? list.get.all.v2() : list.get.all.v1();
|
|
1052
|
+
finalMessages = finalMessages.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
1053
1053
|
return {
|
|
1054
|
-
messages,
|
|
1054
|
+
messages: finalMessages,
|
|
1055
1055
|
total,
|
|
1056
1056
|
page,
|
|
1057
1057
|
perPage,
|
|
1058
|
-
hasMore: selectBy?.last ? false : page * perPage +
|
|
1058
|
+
hasMore: selectBy?.last ? false : page * perPage + processedMessages.length < total
|
|
1059
1059
|
};
|
|
1060
1060
|
} catch (error) {
|
|
1061
1061
|
const mastraError = new MastraError(
|
|
@@ -1568,15 +1568,15 @@ var StoreOperationsD1 = class extends StoreOperations {
|
|
|
1568
1568
|
};
|
|
1569
1569
|
function transformScoreRow(row) {
|
|
1570
1570
|
const deserialized = { ...row };
|
|
1571
|
-
deserialized.input = safelyParseJSON(row.input);
|
|
1572
|
-
deserialized.output = safelyParseJSON(row.output);
|
|
1573
|
-
deserialized.scorer = safelyParseJSON(row.scorer);
|
|
1574
|
-
deserialized.preprocessStepResult = safelyParseJSON(row.preprocessStepResult);
|
|
1575
|
-
deserialized.analyzeStepResult = safelyParseJSON(row.analyzeStepResult);
|
|
1576
|
-
deserialized.metadata = safelyParseJSON(row.metadata);
|
|
1577
|
-
deserialized.additionalContext = safelyParseJSON(row.additionalContext);
|
|
1578
|
-
deserialized.runtimeContext = safelyParseJSON(row.runtimeContext);
|
|
1579
|
-
deserialized.entity = safelyParseJSON(row.entity);
|
|
1571
|
+
deserialized.input = row.input ? safelyParseJSON(row.input) : void 0;
|
|
1572
|
+
deserialized.output = row.output ? safelyParseJSON(row.output) : void 0;
|
|
1573
|
+
deserialized.scorer = row.scorer ? safelyParseJSON(row.scorer) : void 0;
|
|
1574
|
+
deserialized.preprocessStepResult = row.preprocessStepResult ? safelyParseJSON(row.preprocessStepResult) : void 0;
|
|
1575
|
+
deserialized.analyzeStepResult = row.analyzeStepResult ? safelyParseJSON(row.analyzeStepResult) : void 0;
|
|
1576
|
+
deserialized.metadata = row.metadata ? safelyParseJSON(row.metadata) : void 0;
|
|
1577
|
+
deserialized.additionalContext = row.additionalContext ? safelyParseJSON(row.additionalContext) : void 0;
|
|
1578
|
+
deserialized.runtimeContext = row.runtimeContext ? safelyParseJSON(row.runtimeContext) : void 0;
|
|
1579
|
+
deserialized.entity = row.entity ? safelyParseJSON(row.entity) : void 0;
|
|
1580
1580
|
deserialized.createdAt = row.createdAtZ || row.createdAt;
|
|
1581
1581
|
deserialized.updatedAt = row.updatedAtZ || row.updatedAt;
|
|
1582
1582
|
return deserialized;
|
|
@@ -1609,12 +1609,25 @@ var ScoresStorageD1 = class extends ScoresStorage {
|
|
|
1609
1609
|
}
|
|
1610
1610
|
}
|
|
1611
1611
|
async saveScore(score) {
|
|
1612
|
+
let parsedScore;
|
|
1613
|
+
try {
|
|
1614
|
+
parsedScore = saveScorePayloadSchema.parse(score);
|
|
1615
|
+
} catch (error) {
|
|
1616
|
+
throw new MastraError(
|
|
1617
|
+
{
|
|
1618
|
+
id: "CLOUDFLARE_D1_STORE_SCORES_SAVE_SCORE_FAILED_INVALID_SCORE_PAYLOAD",
|
|
1619
|
+
domain: ErrorDomain.STORAGE,
|
|
1620
|
+
category: ErrorCategory.USER,
|
|
1621
|
+
details: { scoreId: score.id }
|
|
1622
|
+
},
|
|
1623
|
+
error
|
|
1624
|
+
);
|
|
1625
|
+
}
|
|
1612
1626
|
try {
|
|
1613
1627
|
const id = crypto.randomUUID();
|
|
1614
1628
|
const fullTableName = this.operations.getTableName(TABLE_SCORERS);
|
|
1615
|
-
const { input, ...rest } = score;
|
|
1616
1629
|
const serializedRecord = {};
|
|
1617
|
-
for (const [key, value] of Object.entries(
|
|
1630
|
+
for (const [key, value] of Object.entries(parsedScore)) {
|
|
1618
1631
|
if (value !== null && value !== void 0) {
|
|
1619
1632
|
if (typeof value === "object") {
|
|
1620
1633
|
serializedRecord[key] = JSON.stringify(value);
|
|
@@ -1626,7 +1639,6 @@ var ScoresStorageD1 = class extends ScoresStorage {
|
|
|
1626
1639
|
}
|
|
1627
1640
|
}
|
|
1628
1641
|
serializedRecord.id = id;
|
|
1629
|
-
serializedRecord.input = JSON.stringify(input);
|
|
1630
1642
|
serializedRecord.createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1631
1643
|
serializedRecord.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1632
1644
|
const columns = Object.keys(serializedRecord);
|
|
@@ -1802,6 +1814,53 @@ var ScoresStorageD1 = class extends ScoresStorage {
|
|
|
1802
1814
|
);
|
|
1803
1815
|
}
|
|
1804
1816
|
}
|
|
1817
|
+
async getScoresBySpan({
|
|
1818
|
+
traceId,
|
|
1819
|
+
spanId,
|
|
1820
|
+
pagination
|
|
1821
|
+
}) {
|
|
1822
|
+
try {
|
|
1823
|
+
const fullTableName = this.operations.getTableName(TABLE_SCORERS);
|
|
1824
|
+
const countQuery = createSqlBuilder().count().from(fullTableName).where("traceId = ?", traceId).andWhere("spanId = ?", spanId);
|
|
1825
|
+
const countResult = await this.operations.executeQuery(countQuery.build());
|
|
1826
|
+
const total = Array.isArray(countResult) ? Number(countResult?.[0]?.count ?? 0) : Number(countResult?.count ?? 0);
|
|
1827
|
+
if (total === 0) {
|
|
1828
|
+
return {
|
|
1829
|
+
pagination: {
|
|
1830
|
+
total: 0,
|
|
1831
|
+
page: pagination.page,
|
|
1832
|
+
perPage: pagination.perPage,
|
|
1833
|
+
hasMore: false
|
|
1834
|
+
},
|
|
1835
|
+
scores: []
|
|
1836
|
+
};
|
|
1837
|
+
}
|
|
1838
|
+
const limit = pagination.perPage + 1;
|
|
1839
|
+
const selectQuery = createSqlBuilder().select("*").from(fullTableName).where("traceId = ?", traceId).andWhere("spanId = ?", spanId).orderBy("createdAt", "DESC").limit(limit).offset(pagination.page * pagination.perPage);
|
|
1840
|
+
const { sql, params } = selectQuery.build();
|
|
1841
|
+
const results = await this.operations.executeQuery({ sql, params });
|
|
1842
|
+
const rows = Array.isArray(results) ? results : [];
|
|
1843
|
+
const scores = rows.slice(0, pagination.perPage).map(transformScoreRow);
|
|
1844
|
+
return {
|
|
1845
|
+
pagination: {
|
|
1846
|
+
total,
|
|
1847
|
+
page: pagination.page,
|
|
1848
|
+
perPage: pagination.perPage,
|
|
1849
|
+
hasMore: rows.length > pagination.perPage
|
|
1850
|
+
},
|
|
1851
|
+
scores
|
|
1852
|
+
};
|
|
1853
|
+
} catch (error) {
|
|
1854
|
+
throw new MastraError(
|
|
1855
|
+
{
|
|
1856
|
+
id: "CLOUDFLARE_D1_STORE_SCORES_GET_SCORES_BY_SPAN_FAILED",
|
|
1857
|
+
domain: ErrorDomain.STORAGE,
|
|
1858
|
+
category: ErrorCategory.THIRD_PARTY
|
|
1859
|
+
},
|
|
1860
|
+
error
|
|
1861
|
+
);
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1805
1864
|
};
|
|
1806
1865
|
function isArrayOfRecords2(value) {
|
|
1807
1866
|
return value && Array.isArray(value) && value.length > 0;
|
|
@@ -2046,13 +2105,18 @@ var WorkflowsStorageD1 = class extends WorkflowsStorage {
|
|
|
2046
2105
|
toDate,
|
|
2047
2106
|
limit,
|
|
2048
2107
|
offset,
|
|
2049
|
-
resourceId
|
|
2108
|
+
resourceId,
|
|
2109
|
+
status
|
|
2050
2110
|
} = {}) {
|
|
2051
2111
|
const fullTableName = this.operations.getTableName(TABLE_WORKFLOW_SNAPSHOT);
|
|
2052
2112
|
try {
|
|
2053
2113
|
const builder = createSqlBuilder().select().from(fullTableName);
|
|
2054
2114
|
const countBuilder = createSqlBuilder().count().from(fullTableName);
|
|
2055
2115
|
if (workflowName) builder.whereAnd("workflow_name = ?", workflowName);
|
|
2116
|
+
if (status) {
|
|
2117
|
+
builder.whereAnd("json_extract(snapshot, '$.status') = ?", status);
|
|
2118
|
+
countBuilder.whereAnd("json_extract(snapshot, '$.status') = ?", status);
|
|
2119
|
+
}
|
|
2056
2120
|
if (resourceId) {
|
|
2057
2121
|
const hasResourceId = await this.operations.hasColumn(fullTableName, "resourceId");
|
|
2058
2122
|
if (hasResourceId) {
|
|
@@ -2233,7 +2297,8 @@ var D1Store = class extends MastraStorage {
|
|
|
2233
2297
|
resourceWorkingMemory: true,
|
|
2234
2298
|
hasColumn: true,
|
|
2235
2299
|
createTable: true,
|
|
2236
|
-
deleteMessages: false
|
|
2300
|
+
deleteMessages: false,
|
|
2301
|
+
getScoresBySpan: true
|
|
2237
2302
|
};
|
|
2238
2303
|
}
|
|
2239
2304
|
async createTable({
|
|
@@ -2345,15 +2410,8 @@ var D1Store = class extends MastraStorage {
|
|
|
2345
2410
|
async loadWorkflowSnapshot(params) {
|
|
2346
2411
|
return this.stores.workflows.loadWorkflowSnapshot(params);
|
|
2347
2412
|
}
|
|
2348
|
-
async getWorkflowRuns({
|
|
2349
|
-
|
|
2350
|
-
fromDate,
|
|
2351
|
-
toDate,
|
|
2352
|
-
limit,
|
|
2353
|
-
offset,
|
|
2354
|
-
resourceId
|
|
2355
|
-
} = {}) {
|
|
2356
|
-
return this.stores.workflows.getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, resourceId });
|
|
2413
|
+
async getWorkflowRuns(args = {}) {
|
|
2414
|
+
return this.stores.workflows.getWorkflowRuns(args);
|
|
2357
2415
|
}
|
|
2358
2416
|
async getWorkflowRunById({
|
|
2359
2417
|
runId,
|
|
@@ -2435,6 +2493,13 @@ var D1Store = class extends MastraStorage {
|
|
|
2435
2493
|
}) {
|
|
2436
2494
|
return this.stores.scores.getScoresByScorerId({ scorerId, pagination, entityId, entityType, source });
|
|
2437
2495
|
}
|
|
2496
|
+
async getScoresBySpan({
|
|
2497
|
+
traceId,
|
|
2498
|
+
spanId,
|
|
2499
|
+
pagination
|
|
2500
|
+
}) {
|
|
2501
|
+
return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
|
|
2502
|
+
}
|
|
2438
2503
|
/**
|
|
2439
2504
|
* Close the database connection
|
|
2440
2505
|
* No explicit cleanup needed for D1 in either REST or Workers Binding mode
|