@mastra/cloudflare 1.0.0-beta.0 → 1.0.0-beta.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 +10 -0
- package/dist/index.cjs +34 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -21
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +5 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +1 -1
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +1 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/test-utils.d.ts.map +1 -1
- package/package.json +10 -8
package/dist/index.js
CHANGED
|
@@ -15,6 +15,17 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
15
15
|
if (!metadata) return void 0;
|
|
16
16
|
return typeof metadata === "string" ? JSON.parse(metadata) : metadata;
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Summarizes message content without exposing raw data (for logging).
|
|
20
|
+
* Returns type, length, and keys only to prevent PII leakage.
|
|
21
|
+
*/
|
|
22
|
+
summarizeMessageContent(content) {
|
|
23
|
+
if (!content) return { type: "undefined" };
|
|
24
|
+
if (typeof content === "string") return { type: "string", length: content.length };
|
|
25
|
+
if (Array.isArray(content)) return { type: "array", length: content.length };
|
|
26
|
+
if (typeof content === "object") return { type: "object", keys: Object.keys(content) };
|
|
27
|
+
return { type: typeof content };
|
|
28
|
+
}
|
|
18
29
|
async getThreadById({ threadId }) {
|
|
19
30
|
const thread = await this.operations.load({ tableName: TABLE_THREADS, keys: { id: threadId } });
|
|
20
31
|
if (!thread) return null;
|
|
@@ -153,7 +164,7 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
153
164
|
return this.operations.getKey(TABLE_MESSAGES, { threadId, id: messageId });
|
|
154
165
|
} catch (error) {
|
|
155
166
|
const message = error instanceof Error ? error.message : String(error);
|
|
156
|
-
this.logger
|
|
167
|
+
this.logger?.error(`Error getting message key for thread ${threadId} and message ${messageId}:`, { message });
|
|
157
168
|
throw error;
|
|
158
169
|
}
|
|
159
170
|
}
|
|
@@ -162,7 +173,7 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
162
173
|
return this.operations.getKey(TABLE_MESSAGES, { threadId, id: "messages" });
|
|
163
174
|
} catch (error) {
|
|
164
175
|
const message = error instanceof Error ? error.message : String(error);
|
|
165
|
-
this.logger
|
|
176
|
+
this.logger?.error(`Error getting thread messages key for thread ${threadId}:`, { message });
|
|
166
177
|
throw error;
|
|
167
178
|
}
|
|
168
179
|
}
|
|
@@ -252,7 +263,7 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
252
263
|
});
|
|
253
264
|
} catch (error) {
|
|
254
265
|
const message = error instanceof Error ? error.message : String(error);
|
|
255
|
-
this.logger
|
|
266
|
+
this.logger?.error(`Error updating sorted order for key ${orderKey}:`, { message });
|
|
256
267
|
throw error;
|
|
257
268
|
} finally {
|
|
258
269
|
if (this.updateQueue.get(orderKey) === nextPromise) {
|
|
@@ -270,7 +281,7 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
270
281
|
const arr = JSON.parse(typeof raw === "string" ? raw : JSON.stringify(raw));
|
|
271
282
|
return Array.isArray(arr) ? arr : [];
|
|
272
283
|
} catch (e) {
|
|
273
|
-
this.logger
|
|
284
|
+
this.logger?.error(`Error parsing order data for key ${orderKey}:`, { e });
|
|
274
285
|
return [];
|
|
275
286
|
}
|
|
276
287
|
}
|
|
@@ -325,9 +336,11 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
325
336
|
const messageMigrationTasks = [];
|
|
326
337
|
for (const message of validatedMessages) {
|
|
327
338
|
const existingMessage = await this.findMessageInAnyThread(message.id);
|
|
328
|
-
|
|
339
|
+
this.logger?.debug(
|
|
340
|
+
`Checking message ${message.id}: existing=${existingMessage?.threadId}, new=${message.threadId}`
|
|
341
|
+
);
|
|
329
342
|
if (existingMessage && existingMessage.threadId && existingMessage.threadId !== message.threadId) {
|
|
330
|
-
|
|
343
|
+
this.logger?.debug(`Migrating message ${message.id} from ${existingMessage.threadId} to ${message.threadId}`);
|
|
331
344
|
messageMigrationTasks.push(this.migrateMessage(message.id, existingMessage.threadId, message.threadId));
|
|
332
345
|
}
|
|
333
346
|
}
|
|
@@ -356,10 +369,8 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
356
369
|
...cleanMessage,
|
|
357
370
|
createdAt: serializeDate(cleanMessage.createdAt)
|
|
358
371
|
};
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
contentType: typeof serializedMessage.content,
|
|
362
|
-
isArray: Array.isArray(serializedMessage.content)
|
|
372
|
+
this.logger?.debug(`Saving message ${message.id}`, {
|
|
373
|
+
contentSummary: this.summarizeMessageContent(serializedMessage.content)
|
|
363
374
|
});
|
|
364
375
|
await this.operations.putKV({ tableName: TABLE_MESSAGES, key, value: serializedMessage });
|
|
365
376
|
})
|
|
@@ -458,7 +469,7 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
458
469
|
const latestIds = await this.getLastN(threadMessagesKey, limit);
|
|
459
470
|
latestIds.forEach((id) => messageIds.add(id));
|
|
460
471
|
} catch {
|
|
461
|
-
|
|
472
|
+
this.logger?.debug(`No message order found for thread ${threadId}, skipping latest messages`);
|
|
462
473
|
}
|
|
463
474
|
}
|
|
464
475
|
async fetchAndParseMessagesFromMultipleThreads(messageIds, include, targetThreadId) {
|
|
@@ -489,15 +500,13 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
489
500
|
const data = await this.operations.getKV(TABLE_MESSAGES, key);
|
|
490
501
|
if (!data) return null;
|
|
491
502
|
const parsed = typeof data === "string" ? JSON.parse(data) : data;
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
contentType: typeof parsed.content,
|
|
495
|
-
isArray: Array.isArray(parsed.content)
|
|
503
|
+
this.logger?.debug(`Retrieved message ${id} from thread ${threadId}`, {
|
|
504
|
+
contentSummary: this.summarizeMessageContent(parsed.content)
|
|
496
505
|
});
|
|
497
506
|
return parsed;
|
|
498
507
|
} catch (error) {
|
|
499
508
|
const message = error instanceof Error ? error.message : String(error);
|
|
500
|
-
this.logger
|
|
509
|
+
this.logger?.error(`Error retrieving message ${id}:`, { message });
|
|
501
510
|
return null;
|
|
502
511
|
}
|
|
503
512
|
})
|
|
@@ -1820,7 +1829,7 @@ var WorkflowsStorageCloudflare = class extends WorkflowsStorage {
|
|
|
1820
1829
|
workflow_name: workflowName,
|
|
1821
1830
|
run_id: runId,
|
|
1822
1831
|
resourceId,
|
|
1823
|
-
snapshot:
|
|
1832
|
+
snapshot: JSON.stringify(snapshot),
|
|
1824
1833
|
createdAt: /* @__PURE__ */ new Date(),
|
|
1825
1834
|
updatedAt: /* @__PURE__ */ new Date()
|
|
1826
1835
|
}
|
|
@@ -1905,7 +1914,8 @@ var WorkflowsStorageCloudflare = class extends WorkflowsStorage {
|
|
|
1905
1914
|
perPage = 20,
|
|
1906
1915
|
resourceId,
|
|
1907
1916
|
fromDate,
|
|
1908
|
-
toDate
|
|
1917
|
+
toDate,
|
|
1918
|
+
status
|
|
1909
1919
|
} = {}) {
|
|
1910
1920
|
try {
|
|
1911
1921
|
if (page < 0 || !Number.isInteger(page)) {
|
|
@@ -1936,10 +1946,11 @@ var WorkflowsStorageCloudflare = class extends WorkflowsStorage {
|
|
|
1936
1946
|
if (!data) continue;
|
|
1937
1947
|
try {
|
|
1938
1948
|
if (resourceId && !keyResourceId) continue;
|
|
1949
|
+
const snapshotData = typeof data.snapshot === "string" ? JSON.parse(data.snapshot) : data.snapshot;
|
|
1950
|
+
if (status && snapshotData.status !== status) continue;
|
|
1939
1951
|
const createdAt = ensureDate(data.createdAt);
|
|
1940
1952
|
if (fromDate && createdAt && createdAt < fromDate) continue;
|
|
1941
1953
|
if (toDate && createdAt && createdAt > toDate) continue;
|
|
1942
|
-
const snapshotData = typeof data.snapshot === "string" ? JSON.parse(data.snapshot) : data.snapshot;
|
|
1943
1954
|
const resourceIdToUse = keyResourceId || data.resourceId;
|
|
1944
1955
|
const run = this.parseWorkflowRun({
|
|
1945
1956
|
...data,
|
|
@@ -2190,7 +2201,8 @@ var CloudflareStore = class extends MastraStorage {
|
|
|
2190
2201
|
page = 0,
|
|
2191
2202
|
resourceId,
|
|
2192
2203
|
fromDate,
|
|
2193
|
-
toDate
|
|
2204
|
+
toDate,
|
|
2205
|
+
status
|
|
2194
2206
|
} = {}) {
|
|
2195
2207
|
return this.stores.workflows.listWorkflowRuns({
|
|
2196
2208
|
workflowName,
|
|
@@ -2198,7 +2210,8 @@ var CloudflareStore = class extends MastraStorage {
|
|
|
2198
2210
|
page,
|
|
2199
2211
|
resourceId,
|
|
2200
2212
|
fromDate,
|
|
2201
|
-
toDate
|
|
2213
|
+
toDate,
|
|
2214
|
+
status
|
|
2202
2215
|
});
|
|
2203
2216
|
}
|
|
2204
2217
|
async getWorkflowRunById({
|