import { a as JsonObject, c as RelationKind, d as ScriptEntities, f as ScriptRelations, i as FieldChange, l as SandboxEntity, n as EntityAssetLoader, o as JsonPrimitive, r as EntityKind, s as JsonValue, t as EntityAssetContent, u as SandboxRelation } from "./types-CjEJw7Bn.mjs"; import { DslAudit, ManualSyncDoc, StoredFile } from "@mengine/medeo-client"; //#region src/sandbox/types.d.ts /** A script run's result, ready to publish against the document version it read. */ interface ChangePlan { doc_id: string; /** The document version the run read, base64. */ base_version: string; /** Native operations on that version, base64; absent when the script changed nothing. */ loro_update?: string; preview: string; logs: string[]; /** Writes the script made that landed. */ commands_count: number; /** Media the plan created, by id and file key. */ created_media: { id: string; key: string; }[]; } interface ConsoleShim { log: (...args: unknown[]) => void; info: (...args: unknown[]) => void; warn: (...args: unknown[]) => void; error: (...args: unknown[]) => void; } //#endregion //#region src/sandbox/run.d.ts /** * Host API for running an agent edit script in an isolated Node worker. * * Requires Node.js >= 24.15 (engines) so the worker can load TypeScript via * `--experimental-transform-types`. Do not inherit `process.execArgv` — vitest * injects loaders that break worker boot. */ interface RunEditScriptOptions { /** Document the plan will be committed against; stated by the host. */ docId: string; /** The document as the script reads it: a native Loro snapshot. */ snapshot: Uint8Array; /** The snapshot's version, base64; the plan applies on top of it. */ baseVersion: string; script: string; /** Who the plan's audit names. */ audit?: Omit; /** Reads a medium's or a transcript's stored file: for `materialize`, and before the plan for every file it names. */ loadEntityAsset?: (entity: SandboxEntity) => Promise; /** Stores raw text in Memota: a PhoneticScript's phonemeScript, whenever a plan writes one. */ uploadText?: (text: string) => Promise; /** Deterministic id label for tests; omit for random ids. */ idLabel?: string; /** Hard wall-clock timeout from when the script starts; default 2000 ms. */ timeoutMs?: number; /** V8 old-generation ceiling for the worker; default 256 MB. */ memoryLimitMb?: number; /** Override worker module URL (defaults to sibling `worker.ts`). */ workerEntryUrl?: URL; } type EditScriptResult = { ok: true; plan: ChangePlan; /** Script execution time after worker readiness; excludes cold start. */ durationMs: number; } | { ok: false; phase: 'parse' | 'runtime' | 'timeout' | 'memory'; error: { message: string; line?: number; column?: number; stack?: string; }; partial: { commandsCount: number; logs: string[]; }; }; /** Run `script` against a fork of the snapshot; always resolves (never rejects). */ declare function runEditScript(options: RunEditScriptOptions): Promise; //#endregion //#region src/export/prompt.d.ts declare const MEDEO_TOOL_DESCRIPTION: string; //#endregion //#region src/sandbox/commit.d.ts type CommitPlanResult = { kind: 'committed'; commands_applied: number; collaborated: boolean; } /** The server holds the merge, but the merged document no longer projects: look again. */ | { kind: 'conflicted'; accepted: true; collaborated: boolean; message: string; } /** The push was not confirmed; publish the same plan again. */ | { kind: 'unconfirmed'; reason: 'push_failed'; message: string; } | { kind: 'rejected'; code?: string; message: string; }; /** * Publish a plan: merge its native update into the synced document and push. * Importing the same update twice changes nothing, so retrying an unconfirmed * plan re-sends exactly the operations it first carried. */ declare function commitPlan(doc: ManualSyncDoc, plan: ChangePlan): Promise; //#endregion //#region src/sandbox/lineage.d.ts /** A generation record the host knows, by file key: what was made, from what. */ interface AssetGenerationFact { outputAssetId: string; inputAssetIds: readonly string[]; } /** Every known generation record involving the given file keys, in either role. */ type GenerationFactsLoader = (docId: string, assetIds: readonly string[]) => Promise; type GenerationSyncOutcome = { status: 'synced'; linked: number; } | { status: 'failed'; message: string; }; //#endregion //#region src/schema.d.ts declare const MEDEO_TOOL_NAME = "medeo"; type MedeoToolOp = 'snapshot' | 'run-edit-script' | 'commit-plan'; /** * JSON Schema for the host-facing `medeo` tool surface. * * The schema intentionally does not return or accept the full op journal: * journals stay in the tool process and are referenced by `plan_id`. This keeps * large intermediate products out of model context while preserving the exact * journal used for commit. */ declare const MEDEO_TOOL_PARAMETERS: { readonly type: "object"; readonly required: readonly ["op", "doc_id"]; readonly additionalProperties: false; readonly properties: { readonly op: { readonly type: "string"; readonly enum: readonly ["snapshot", "run-edit-script", "commit-plan"]; readonly description: "Which Medeo document operation to run."; }; readonly doc_id: { readonly type: "string"; readonly minLength: 1; readonly description: "Medeo document id. Copy it from the host context; never invent it."; }; readonly script: { readonly type: "string"; readonly minLength: 1; readonly description: "JavaScript body for run-edit-script. It runs with entities, relations and console in scope; everything it does becomes one entity plan."; }; readonly timeout_ms: { readonly type: "integer"; readonly minimum: 1; readonly description: "Maximum script wall-clock time after worker startup (default 30000)."; }; readonly memory_limit_mb: { readonly type: "integer"; readonly minimum: 16; readonly description: "Worker old-generation memory ceiling in MB (default 256)."; }; readonly auto_commit: { readonly type: "boolean"; readonly description: "Commit the returned plan immediately after the sandbox succeeds. Default false: return preview plus plan_id for explicit commit."; }; readonly plan_id: { readonly type: "string"; readonly minLength: 1; readonly description: "Plan id returned by run-edit-script; required by commit-plan."; }; readonly validation: { readonly type: "string"; readonly enum: readonly ["preflight"]; readonly description: "Publish the native update already validated on its causal Loro fork."; }; }; readonly oneOf: readonly [{ readonly required: readonly ["op", "doc_id"]; readonly properties: { readonly op: { readonly const: "snapshot"; }; readonly doc_id: { readonly $ref: "#/properties/doc_id"; }; }; readonly additionalProperties: false; }, { readonly required: readonly ["op", "doc_id", "script"]; readonly properties: { readonly op: { readonly const: "run-edit-script"; }; readonly doc_id: { readonly $ref: "#/properties/doc_id"; }; readonly script: { readonly $ref: "#/properties/script"; }; readonly timeout_ms: { readonly $ref: "#/properties/timeout_ms"; }; readonly memory_limit_mb: { readonly $ref: "#/properties/memory_limit_mb"; }; readonly auto_commit: { readonly $ref: "#/properties/auto_commit"; }; }; readonly additionalProperties: false; }, { readonly required: readonly ["op", "doc_id", "plan_id"]; readonly properties: { readonly op: { readonly const: "commit-plan"; }; readonly doc_id: { readonly $ref: "#/properties/doc_id"; }; readonly plan_id: { readonly $ref: "#/properties/plan_id"; }; readonly validation: { readonly $ref: "#/properties/validation"; }; }; readonly additionalProperties: false; }]; }; //#endregion //#region src/host-tool.d.ts type ContextualValue = T | ((docId: string) => T | undefined); interface CreateMedeoToolOptions { /** * Mengine HTTP origin for a document. The host owns environment routing * (local/stg/prd/lane) and may return a different origin per document. * Documents cache by doc id, so the origin must remain stable for that doc. */ httpOrigin: ContextualValue; /** Optional bearer token, evaluated for each HTTP request. */ authToken?: ContextualValue; /** Optional end-user id header, evaluated for each HTTP request; also the plan audit's actor. */ userId?: ContextualValue; /** Loro peer for the tool's own follow-up writes; plans are authored on a fresh peer each run. */ peerId?: ContextualValue; /** * Resolve generation lineage by file key after a confirmed commit. Return * every known record involving the given keys, in either role; an empty array * means none is known, and a rejection is surfaced as a warning. */ loadGenerationFacts?: GenerationFactsLoader; /** Read a medium's own file, or a transcript's transcription file: for `materialize`, and before every plan for each file it names. */ loadEntityAsset?: EntityAssetLoader; /** * Store raw text in Memota as a text file and return its facts. A plan that writes a * PhoneticScript's phonemeScript stores it here first and writes the file's facts with it (D177). */ uploadText?: (docId: string, text: string) => Promise; fetchImpl?: typeof fetch; /** Defaults passed to runEditScript; each call may override them. */ sandbox?: { timeoutMs?: number; memoryLimitMb?: number; }; /** Maximum cached plans; oldest plans are evicted (default 16). */ maxPlans?: number; /** Maximum model-call version baselines retained across host contexts (default 128). */ maxModelContexts?: number; } interface MedeoModelContextInput { /** Internal MEngine document id. This is host-supplied and never model-facing. */ doc_id: string; /** Stable host conversation/session key used to compare consecutive model calls. */ context_id: string; } interface MedeoModelContext { /** Complete MEngine-owned prompt: workflow, runtime state, and sandbox TypeScript interface. */ prompt: string; document_version: string; updated_since_previous_model_call: boolean | null; } type MedeoToolInput = { op: 'snapshot'; doc_id: string; } | { op: 'run-edit-script'; doc_id: string; script: string; timeout_ms?: number; memory_limit_mb?: number; auto_commit?: boolean; } | { op: 'commit-plan'; doc_id: string; plan_id: string; validation?: 'preflight'; }; type MedeoToolWarning = { kind: 'pull_failed'; message: string; } | { kind: 'generation_sync_failed'; message: string; }; type MedeoCommitResult = CommitPlanResult & { /** Present only when the host supplies loadGenerationFacts and the commit was confirmed. */generation_sync?: GenerationSyncOutcome; warnings?: MedeoToolWarning[]; }; type MedeoToolResult = { ok: true; op: 'snapshot'; doc_id: string; version: string; preview: string; collaborated?: boolean; warnings?: MedeoToolWarning[]; } | { ok: true; op: 'run-edit-script'; doc_id: string; plan_id: string; base_version: string; ops_count: number; preview: string; logs: string[]; duration_ms: number; committed?: boolean; commit_result?: MedeoCommitResult; collaborated?: boolean; warnings?: MedeoToolWarning[]; } | { ok: false; op: 'run-edit-script'; doc_id: string; phase: 'parse' | 'runtime' | 'timeout' | 'memory'; error: { message: string; line?: number; column?: number; stack?: string; }; partial: { ops_count: number; logs: string[]; }; } | { ok: true; op: 'commit-plan'; doc_id: string; plan_id: string; committed: boolean; result: MedeoCommitResult; warnings?: MedeoToolWarning[]; } | { ok: false; op: MedeoToolOp; error: string; }; interface MedeoTool { name: typeof MEDEO_TOOL_NAME; description: typeof MEDEO_TOOL_DESCRIPTION; parameters: typeof MEDEO_TOOL_PARAMETERS; getModelContext(input: MedeoModelContextInput): Promise; handle(input: unknown): Promise; close(): Promise; } /** * Create the Medeo LLM tool. The package owns reading and syncing documents, * running scripts, caching plans and publishing them; the host supplies * routing, credentials and resource I/O. */ declare function createMedeoTool(options: CreateMedeoToolOptions): MedeoTool; //#endregion export { type AssetGenerationFact, type ChangePlan, type CommitPlanResult, type ConsoleShim, type CreateMedeoToolOptions, type EditScriptResult, type EntityAssetContent, type EntityAssetLoader, type EntityKind, type FieldChange, type GenerationFactsLoader, type GenerationSyncOutcome, type JsonObject, type JsonPrimitive, type JsonValue, MEDEO_TOOL_DESCRIPTION, MEDEO_TOOL_NAME, MEDEO_TOOL_PARAMETERS, type MedeoCommitResult, type MedeoModelContext, type MedeoModelContextInput, type MedeoTool, type MedeoToolInput, type MedeoToolOp, type MedeoToolResult, type MedeoToolWarning, type RelationKind, type RunEditScriptOptions, type SandboxEntity, type SandboxRelation, type ScriptEntities, type ScriptRelations, commitPlan, createMedeoTool, runEditScript }; //# sourceMappingURL=index.d.mts.map