UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

72 lines • 3.45 kB
import type { DeltaHook } from '../../events/base.ts'; import { Delta, type PathSpec } from '../../types.ts'; import type { resolveMsGraphConfig } from './config.ts'; /** One drive a delta pull reads, and where its mount root sits. Mirrors Python `DeltaTarget`. */ export interface DeltaTarget { /** The drive's Graph URL. */ drive: string; /** The mount root's path from the drive root, '' for the drive root itself. */ folder: string; /** The mount root's virtual path. */ virtual: string; } /** * Checkpointed delta over Graph's `/delta` feed, one per drive. * * Graph pings a subscription with no description of the change, so a ping * reads each drive's feed from the link the last read handed out. The feed * names an item by id with its name and parent, never its path, so the hook * places it by its parents up to the mount root, keeping each folder it has * looked up (name and parent, by id) in the checkpoint, where the folders' own * changes keep them current; an item whose parents never reach the root is * outside the mount. The checkpoint also keeps the path of each item a read * placed: one that moves leaves that path, with everything below a folder, and * one deleted leaves it. An item seen for the first time is created when it is * as Graph made it (its created and modified times agree) and updated * otherwise; one deleted before any * read placed it names nothing, and is left to the index's expiry. Each read * first applies the feed's folder renames and moves, so an item listed before * its folder is still placed where the folder is now. A feed Graph asks to * resync reports its mount root as unknown and starts again from the present, * forgetting every place it kept. Each read finds the drives the root covers * again: a library added since is created and read from then on, one gone is * deleted, and one renamed moves. * * Mirrors Python `GraphDeltaHook` (`core/msgraph/events.py`). */ export declare class GraphDeltaHook implements DeltaHook { private readonly config; private readonly targets; constructor(config: ReturnType<typeof resolveMsGraphConfig>, targets: (root: PathSpec) => Promise<DeltaTarget[]>); pull(root: PathSpec, checkpoint: string | null): Promise<Delta>; /** * A drive's state at its present: the feed link that lists nothing yet, the * mount root's id, and nothing placed. */ private baseline; /** * Read one drive's feed into `changes` and move `kept` on. * * A mount rooted below the drive root names its root by path, so each read * finds that folder again: one deleted, replaced or moved away (its own move * or an ancestor's) reports the root as unknown and starts placing items * afresh under whatever the path is now. */ private read; /** * Every item a feed link lists, once each at its last row, and the link the * next read starts from. Graph may list an item more than once across pages; * its last row is its state. */ private feed; /** A feed link at the drive's present, which lists nothing. */ private latest; /** The id of the folder the mount root is, null when no folder is at its path. */ private top; /** * A folder's name and parent id, null when it is gone; the drive root has * no parent on a mount rooted below it. */ private lookUp; } //# sourceMappingURL=events.d.ts.map