@mastra/core
Version:
73 lines • 3.44 kB
TypeScript
import type { StepResult, WorkflowRunState } from '../../../workflows/index.js';
import type { WorkflowRun, WorkflowRuns, StorageListWorkflowRunsInput, UpdateWorkflowStateOptions } from '../../types.js';
import type { InMemoryDB } from '../inmemory-db.js';
import { WorkflowsStorage } from './base.js';
/**
* Deep-clone in-memory workflow state.
*
* We previously used `JSON.parse(JSON.stringify(x))` here, but the agent loop
* and workflow engine legitimately place values in step results that don't
* survive JSON round-tripping:
* - `Date` instances (e.g. `response.timestamp`) — JSON turns them into ISO
* strings, downstream consumers that do `.getTime()` then break.
* - Explicitly-`undefined` properties (e.g. `headers`, `providerMetadata`,
* `usage.{cacheRead, cacheWrite, reasoning}`) — JSON drops keys with
* `undefined` values, breaking snapshot assertions that include them.
* - `Error` instances (e.g. tool execution failures, AssertionErrors from
* inside `tool.execute`) — JSON strips `message`/`name`/`stack` (non-
* enumerable). `structuredClone` isn't enough either — it preserves the
* Error type but drops subclass-specific enumerable props (`actual`,
* `expected`, `operator`).
*
* The custom walk below preserves all of that. It also handles builtins with
* internal slots explicitly — `Map`, `Set`, `RegExp`, `URL`, `ArrayBuffer`,
* typed arrays, and `DataView` — because cloning them via `Object.create(proto)`
* would produce a value that passes `instanceof` but whose methods throw (the
* internal slots were never initialized). Null-prototype dictionaries keep
* their null prototype.
*/
/** @internal Exported for testing only. */
export declare function cloneRunData<T>(value: T): T;
export declare class WorkflowsInMemory extends WorkflowsStorage {
private db;
constructor({ db }: {
db: InMemoryDB;
});
supportsConcurrentUpdates(): boolean;
dangerouslyClearAll(): Promise<void>;
private getWorkflowKey;
updateWorkflowResults({ workflowName, runId, stepId, result, requestContext, }: {
workflowName: string;
runId: string;
stepId: string;
result: StepResult<any, any, any, any>;
requestContext: Record<string, any>;
}): Promise<Record<string, StepResult<any, any, any, any>>>;
updateWorkflowState({ workflowName, runId, opts, }: {
workflowName: string;
runId: string;
opts: UpdateWorkflowStateOptions;
}): Promise<WorkflowRunState | undefined>;
persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot, createdAt, updatedAt, }: {
workflowName: string;
runId: string;
resourceId?: string;
snapshot: WorkflowRunState;
createdAt?: Date;
updatedAt?: Date;
}): Promise<void>;
loadWorkflowSnapshot({ workflowName, runId, }: {
workflowName: string;
runId: string;
}): Promise<WorkflowRunState | null>;
listWorkflowRuns({ workflowName, fromDate, toDate, perPage, page, resourceId, status, }?: StorageListWorkflowRunsInput): Promise<WorkflowRuns>;
getWorkflowRunById({ runId, workflowName, }: {
runId: string;
workflowName?: string;
}): Promise<WorkflowRun | null>;
deleteWorkflowRunById({ runId, workflowName }: {
runId: string;
workflowName: string;
}): Promise<void>;
}
//# sourceMappingURL=inmemory.d.ts.map