import type { SandboxEnv } from "./sandbox.js"; import type { FabricFs } from "./filesystem.js"; import type { SandboxRef, SerializedSandboxRef } from "./sandbox-ref.js"; import type { FilesystemSource } from "./filesystem-source.js"; import type { ApprovalCallback, ArtifactCreateOptions, ArtifactRef, CheckpointCreateOptions, CheckpointRestoreOptions, CheckpointResult, CompactionOptions, CompactionResult, FabricAgent, FabricEvent, PromptOptions, SessionData, SessionEntry, SessionOptions, ShellOptions, ShellResult, SignalEntryData, SkillOptions, TaskOptions } from "./types.js"; /** * Generate a deterministic `aff_\u003cULID\u003e` affinity key from an * `(agentId, sessionId)` pair. The same pair always produces the same key, * which is stable across restarts. Different pairs produce different keys * with overwhelming probability. */ export declare function generateAffinityKey(agentId: string, sessionId: string): string; export declare function isValidAffinityKey(key: string): boolean; export interface FabricSession { readonly id: string; readonly agent: FabricAgent; readonly sandbox: Promise; /** Out-of-band filesystem helper for host-side staging/artifact plumbing. */ readonly fs: FabricFs; prompt(text: string, options?: PromptOptions): Promise; stream(text: string, options?: PromptOptions): AsyncGenerator; skill(name: string, options?: SkillOptions): Promise; task(text: string, options?: TaskOptions): Promise; shell(command: string, options?: ShellOptions): Promise; mount(mountAt: string, source: FilesystemSource, options?: MountOptions): Promise; approval: { /** * Request a custom approval gate. Returns `true` if approved, throws if * denied / timed out / unavailable. * * Useful for guarding risky non-tool actions (deploys, public posts, * destructive cleanups). For tool/command approvals, configure * `policy.approvals` instead — those are gated automatically. */ request(input: ApprovalRequestInput): Promise; }; /** * Cross-session memory accessor. Auto-scopes by the session's tenantId. * See `init({ memory })` for the persistence backing — defaults to in-memory. */ memory: { get(key: string): Promise | undefined>; set(input: { key: string; value: TValue; metadata?: Record; ttlSeconds?: number; }): Promise; delete(key: string): Promise; list(filter?: import("./session-memory.js").SessionMemoryFilter): Promise; }; history(): Promise; /** * Append a typed signal entry to the session history. Signals are rendered * as XML tags in model context so the model sees them as structured context. */ createSignalEntry(data: SignalEntryData): Promise; checkpoint: { create(options: CheckpointCreateOptions | string): Promise; restore(options: CheckpointRestoreOptions | string): Promise; }; /** * Capture the sandbox state and return a portable handle. Pass the handle's * `attach()` to spin up parallel sessions sharing the captured state but * with independent forward writes. * * Requires the sandbox to support `fork()` (advertised in * `sandbox.capabilities.fork`). Throws `SANDBOX_UNAVAILABLE` otherwise. */ fork(label?: string): Promise; /** * Get a portable reference to this session's sandbox. Pass the ref to * `attachSandbox(ref)` in another session to share the same running * sandbox without taking ownership of its lifecycle. * * Pass `{ portable: true }` to receive a `SerializedSandboxRef` instead, * which can cross process / machine boundaries — the receiving process * passes it back to `attachSandbox()`, which delegates to whichever * decoder was registered for the provider. */ sandboxRef(options?: { portable?: false; }): Promise; sandboxRef(options: { portable: true; }): Promise; artifact(name: string, content: string | Uint8Array, options?: ArtifactCreateOptions): Promise; compact(options?: CompactionOptions): Promise; } export interface SandboxFork { /** Stable id of the snapshot underlying this fork. */ snapshotId: string; /** Optional human-readable label captured at fork time. */ label?: string; /** * Spin up a new session whose sandbox is a fork of the captured state. * Each call to `attach()` returns an independent session — writes in * branch A are invisible to branch B and to the origin. */ attach(options?: SessionOptions): Promise; } export interface MountOptions { /** * `'read'` (default) — the mount is treated as immutable; write tools * targeting paths under it will be rejected by capability policy. * `'write'` — agent may freely write under the mount. */ mode?: "read" | "write"; } export interface MountResult { /** Absolute path inside the sandbox where the source was mounted. */ mountAt: string; /** Number of files written to the sandbox. */ files: number; /** Total bytes written across all files. */ bytes: number; /** Source name (for telemetry / logs). */ source?: string; /** Effective mode (defaults to 'read'). */ mode: "read" | "write"; } interface CompactionPreparation { firstKeptIndex: number; messagesToSummarize: SessionEntry[]; turnPrefixMessages: SessionEntry[]; isSplitTurn: boolean; fileRefs: FileReferences; } export interface ApprovalRequestInput { /** Human-readable reason shown to the approver. */ reason: string; /** Short subject line for UIs. Defaults to `'custom'`. */ subject?: string; /** Risk classification (drives escalation policy). */ risk?: "low" | "medium" | "high"; /** Override the session's default approval timeout. */ timeoutMs?: number; /** * Stable key used to resume this approval after a process restart or * idempotent job retry. Keys are scoped to the session and approval kind. */ idempotencyKey?: string; /** Per-call approval callback. Falls back to session/agent `onApproval`. */ onApproval?: ApprovalCallback; } export declare class StubFabricSession implements FabricSession { readonly id: string; readonly agent: FabricAgent; private sandboxPromise; get sandbox(): Promise; readonly checkpoint: { create: (options: CheckpointCreateOptions | string) => Promise; restore: (options: CheckpointRestoreOptions | string) => Promise; }; readonly fs: FabricFs; readonly approval: { request: (input: ApprovalRequestInput) => Promise; }; /** * Cross-session memory accessor. Auto-scopes operations to this session's * `tenantId`. Backed by `init({ memory })` — no-ops via in-memory store * when the host didn't configure one. */ readonly memory: { get: (key: string) => Promise | undefined>; set: (input: { key: string; value: TValue; metadata?: Record; ttlSeconds?: number; }) => Promise; delete: (key: string) => Promise; list: (filter?: import("./session-memory.js").SessionMemoryFilter) => Promise[]>; }; private readonly options; private readonly store; private readonly eventSubscribers; private durableRuntime; private readonly mounts; /** Set when this session has registered its sandbox in the in-process ref registry. */ private ownedSandboxRefId; private readonly costBudget; private readonly skillCache; constructor(agent: FabricAgent, id: string, options?: SessionOptions); private getDurableRuntime; prompt(text: string, promptOptions?: PromptOptions): Promise; stream(text: string, options?: PromptOptions): AsyncGenerator; skill(name: string, options?: SkillOptions): Promise; task(text: string, options?: TaskOptions): Promise; private watchTaskCancellation; shell(command: string, options?: ShellOptions): Promise; mount(mountAt: string, source: FilesystemSource, options?: MountOptions): Promise; private checkMountWriteAccess; history(): Promise; createSignalEntry(data: SignalEntryData): Promise; sandboxRef(options?: { portable?: false; }): Promise; sandboxRef(options: { portable: true; }): Promise; fork(label?: string): Promise; artifact(name: string, content: string | Uint8Array, options?: ArtifactCreateOptions): Promise; compact(options?: CompactionOptions): Promise; private autoCompactIfNeeded; private resolveModelContextWindow; private readProviderModelMetadata; private generateCompactionSummary; private summarizeEntrySet; private requestCustomApproval; private createCheckpoint; private restoreCheckpoint; private createSandbox; private executeToolCalls; private requestCostLimitApproval; private requestApproval; private approvalPrincipal; private waitForStoredApproval; private effectiveAutonomy; private evaluateScopedCommandToolCall; private commandTextForApproval; private clampBashToolInput; private resolveTools; private activateSkillForTool; private resolveSkill; private resolveRole; private memoryFallback; private resolveMemory; private tenantScopeOptions; private ensureData; /** * Settle dangling state left by an interrupted turn before applying new * input (v2 A2 — port of flue's repairTrailingPartialToolBatch). * * A crash/abort between recording a `tool_call` and its outcome leaves an * assistant tool_use with no tool_result, which providers reject on the * next turn. A call declared durable is re-entered with the same logical * call id, replaying completed `step.do()` checkpoints. Other calls receive * a synthetic interrupted result because their real outcome is unknown. * The repair also settles trailing unfinished `task_start`s and * appends one advisory `signal` entry so the model knows the previous turn * was cut short. Idempotent: a repaired window has no dangling calls. */ private repairDanglingToolCalls; private authorizeRecoveredToolCall; private recordEntry; private finalizeDynamicResult; private createToolStep; private createToolProgressLogger; private recordSandboxOrphanSettlement; private recordToolResult; private emit; } interface FileReferences { readFiles: string[]; modifiedFiles: string[]; } /** Pure function — no I/O. Finds the token-based cut point, extracts messages to summarize, and tracks file ops. */ export declare function prepareCompaction(entries: SessionEntry[], keepRecentTokens: number, previousCompaction?: { firstKeptIndex: number; }): CompactionPreparation | undefined; export {}; //# sourceMappingURL=session.d.ts.map