@mastra/upstash 1.6.1-alpha.1 → 1.6.2-alpha.0
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/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +7 -7
- package/dist/index.cjs +60 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +60 -2
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/run-fencing.d.ts +2 -0
- package/dist/storage/domains/run-fencing.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +9 -1
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -528,6 +528,26 @@ async function releaseRunOwnership(client, fence) {
|
|
|
528
528
|
async function getRunOwnership(client, runId) {
|
|
529
529
|
return (await evalOwner(client, READ, runId, [], Date.now())).record;
|
|
530
530
|
}
|
|
531
|
+
/** Run reads one pipeline request carries, keeping its HTTP body small. */
|
|
532
|
+
const READ_PIPELINE_BATCH_SIZE = 100;
|
|
533
|
+
/** The ownership records of `runIds`, with one pipeline request per {@link READ_PIPELINE_BATCH_SIZE} runs. */
|
|
534
|
+
async function getRunOwnerships(client, runIds) {
|
|
535
|
+
const records = /* @__PURE__ */ new Map();
|
|
536
|
+
const ids = [...new Set(runIds)];
|
|
537
|
+
for (let start = 0; start < ids.length; start += READ_PIPELINE_BATCH_SIZE) {
|
|
538
|
+
const chunk = ids.slice(start, start + READ_PIPELINE_BATCH_SIZE);
|
|
539
|
+
const now = Date.now();
|
|
540
|
+
const pipeline = client.pipeline();
|
|
541
|
+
for (const runId of chunk) pipeline.eval(READ, [runClaimKey(TABLE_WORKFLOW_RUN_OWNERS, runId)], []);
|
|
542
|
+
const replies = await pipeline.exec();
|
|
543
|
+
chunk.forEach((runId, i) => {
|
|
544
|
+
const raw = replies[i];
|
|
545
|
+
const record = toRunOwnershipRecord(runId, typeof raw === "string" ? JSON.parse(raw) : raw, now);
|
|
546
|
+
if (record) records.set(runId, record);
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
return records;
|
|
550
|
+
}
|
|
531
551
|
async function raiseRunFence(client, fence) {
|
|
532
552
|
const raised = await client.eval(RAISE, [runClaimKey(TABLE_MEMORY_RUN_FENCES, fence.runId)], [String(fence.generation), fence.ownerId]);
|
|
533
553
|
return Number(raised) === 1;
|
|
@@ -1886,6 +1906,27 @@ var ScoresUpstash = class extends ScoresStorage {
|
|
|
1886
1906
|
}
|
|
1887
1907
|
};
|
|
1888
1908
|
// src/storage/domains/workflows/index.ts
|
|
1909
|
+
/**
|
|
1910
|
+
* A run with its snapshot reduced to what `listWorkflowRuns({ summary: true })` returns: `status`
|
|
1911
|
+
* and `timestamp` when set, and `parentWorkflow` only when both of its IDs are non-empty strings.
|
|
1912
|
+
* A missing snapshot, or one that failed to parse and stayed a string, reduces to `{}`.
|
|
1913
|
+
*/
|
|
1914
|
+
function summarizeWorkflowRun(run) {
|
|
1915
|
+
const { status, timestamp, parentWorkflow } = run.snapshot !== null && typeof run.snapshot === "object" ? run.snapshot : {};
|
|
1916
|
+
const snapshot = {};
|
|
1917
|
+
if (status !== void 0 && status !== null) snapshot.status = status;
|
|
1918
|
+
if (timestamp !== void 0 && timestamp !== null) snapshot.timestamp = timestamp;
|
|
1919
|
+
const workflowId = parentWorkflow?.workflowId;
|
|
1920
|
+
const runId = parentWorkflow?.runId;
|
|
1921
|
+
if (typeof workflowId === "string" && workflowId !== "" && typeof runId === "string" && runId !== "") snapshot.parentWorkflow = {
|
|
1922
|
+
workflowId,
|
|
1923
|
+
runId
|
|
1924
|
+
};
|
|
1925
|
+
return {
|
|
1926
|
+
...run,
|
|
1927
|
+
snapshot
|
|
1928
|
+
};
|
|
1929
|
+
}
|
|
1889
1930
|
var WorkflowsUpstash = class extends WorkflowsStorage {
|
|
1890
1931
|
client;
|
|
1891
1932
|
#db;
|
|
@@ -1965,6 +2006,19 @@ var WorkflowsUpstash = class extends WorkflowsStorage {
|
|
|
1965
2006
|
throw this.#ownershipError("GET_RUN_OWNERSHIP", runId, error);
|
|
1966
2007
|
}
|
|
1967
2008
|
}
|
|
2009
|
+
/** Reads the records with one pipeline request per hundred runs. */
|
|
2010
|
+
async getRunOwnerships({ runIds }) {
|
|
2011
|
+
try {
|
|
2012
|
+
return await getRunOwnerships(this.client, runIds);
|
|
2013
|
+
} catch (error) {
|
|
2014
|
+
throw new MastraError({
|
|
2015
|
+
id: createStorageErrorId("UPSTASH", "GET_RUN_OWNERSHIPS", "FAILED"),
|
|
2016
|
+
domain: ErrorDomain.STORAGE,
|
|
2017
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
2018
|
+
details: { runCount: runIds.length }
|
|
2019
|
+
}, error);
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
1968
2022
|
async getWorkflowRunRecord({ namespace, runId, resourceId, workflowName }) {
|
|
1969
2023
|
if (workflowName) {
|
|
1970
2024
|
const keyVariants = [...resourceId ? [{
|
|
@@ -2320,7 +2374,11 @@ var WorkflowsUpstash = class extends WorkflowsStorage {
|
|
|
2320
2374
|
}, error);
|
|
2321
2375
|
}
|
|
2322
2376
|
}
|
|
2323
|
-
|
|
2377
|
+
/**
|
|
2378
|
+
* Lists runs newest first. With `summary`, each snapshot keeps only its status, timestamp and
|
|
2379
|
+
* parent run; the full snapshots are still read from Upstash.
|
|
2380
|
+
*/
|
|
2381
|
+
async listWorkflowRuns({ workflowName, fromDate, toDate, perPage, page, resourceId, status, summary } = {}) {
|
|
2324
2382
|
try {
|
|
2325
2383
|
if (page !== void 0 && page < 0) throw new MastraError({
|
|
2326
2384
|
id: createStorageErrorId("UPSTASH", "LIST_WORKFLOW_RUNS", "INVALID_PAGE"),
|
|
@@ -2358,7 +2416,7 @@ var WorkflowsUpstash = class extends WorkflowsStorage {
|
|
|
2358
2416
|
runs = runs.slice(offset, offset + normalizedPerPage);
|
|
2359
2417
|
}
|
|
2360
2418
|
return {
|
|
2361
|
-
runs,
|
|
2419
|
+
runs: summary ? runs.map(summarizeWorkflowRun) : runs,
|
|
2362
2420
|
total
|
|
2363
2421
|
};
|
|
2364
2422
|
} catch (error) {
|