UNPKG

@mastra/core

Version:

Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.

35 lines 1.22 kB
/** * File Write Lock * * Per-file promise queue that serializes write operations to the same path. * Prevents read-modify-write race conditions when multiple tool calls * target the same file concurrently. */ /** Options for constructing a FileWriteLock. */ export interface FileWriteLockOptions { /** Maximum time (ms) a single lock-holder may run before being rejected. Default: 30 000. */ timeoutMs?: number; } /** * Interface for per-file write locking. */ export interface FileWriteLock { /** Execute `fn` while holding an exclusive lock on `filePath`. */ withLock<T>(filePath: string, fn: () => Promise<T>): Promise<T>; /** Number of paths that currently have queued operations. */ get size(): number; } /** * In-memory implementation of FileWriteLock using per-path promise queues. * * Adapted from mastracode's `withWriteLock` pattern. */ export declare class InMemoryFileWriteLock implements FileWriteLock { private queues; private readonly timeoutMs; constructor(opts?: FileWriteLockOptions); get size(): number; withLock<T>(filePath: string, fn: () => Promise<T>): Promise<T>; private normalizePath; } //# sourceMappingURL=file-write-lock.d.ts.map