/** * `CustomToolContext` across subagent worker links (codec kind `"custom-tool-context"`). * * A worker-hosted child calls main-thread tools (MCP tools, kernel-defined custom tools) with its own * tool context, whose session manager, settings overlay and getters are worker-local live objects. * The sender encodes the context as a call-time snapshot plus remote async operations; the receiver * rebuilds a `CustomToolContext`: * * - `sessionManager` is a {@link ToolContextSessionView}: the scalar getters (`getCwd`, ids, paths, * leaf id, header) answer from the snapshot; `ensureOnDisk`, `allocateArtifactPath`, * `saveArtifact`, `getArtifactPath` and `putBlob` run on the sender's session manager. Synchronous * transcript reads (`getEntries`, `getBranch`, `getTree`, `getEntry`, `getLeafEntry`, `getLabel`, * `getUsageStatistics`), `putBlobSync` and `getArtifactManager` throw: the receiver can never block * on the sending thread, and shipping the transcript with every call is not viable. * - `isIdle()`/`hasQueuedMessages()` report the sender's state when the call was made. * - `abort()` aborts the sender's run (fire-and-forget). * - `settings`: a worker sends the nearest main-backed mirror of its settings (child-local overlay * values are not visible to main-side tool code); main sends its instance, which the worker mirrors. * - `modelRegistry`, `model`, `localProtocolOptions`, `autoApprove` cross as values/proxies. */ import type { Model } from "@oh-my-pi/pi-ai"; import type { ModelRegistry } from "../../config/model-registry.js"; import { Settings } from "../../config/settings.js"; import type { CustomToolContext } from "../../extensibility/custom-tools/types.js"; import type { LocalProtocolOptions } from "../../internal-urls/local-protocol.js"; import type { ArtifactManager } from "../../session/artifacts.js"; import type { BlobPutOptions, BlobPutResult } from "../../session/blob-store.js"; import type { SessionEntry, SessionHeader, SessionTreeNode, UsageStatistics } from "../../session/session-entries.js"; import type { ReadonlySessionManager } from "../../session/session-manager.js"; import type { RpcCodec } from "../rpc.js"; /** Codec kind of {@link toolContextCodec}. */ export declare const TOOL_CONTEXT_KIND = "custom-tool-context"; /** Wire snapshot of the sender's read-only session manager. */ export interface WireSessionView { readonly cwd: string; readonly recordedCwd: string | undefined; readonly sessionDir: string; readonly sessionId: string; readonly sessionFile: string | undefined; readonly sessionName: string | undefined; readonly artifactsDir: string | null; readonly leafId: string | null; readonly header: SessionHeader | null; readonly ensureOnDisk: () => Promise; readonly allocateArtifactPath: (toolType: string) => Promise<{ id?: string; path?: string; }>; readonly saveArtifact: (content: string, toolType: string) => Promise; readonly getArtifactPath: (id: string) => Promise; readonly putBlob: (data: Uint8Array, options?: BlobPutOptions) => Promise; } /** Wire form of a `CustomToolContext`. */ export interface WireToolContext { readonly session: WireSessionView; readonly modelRegistry: ModelRegistry; readonly model: Model | undefined; readonly idle: boolean; readonly queued: boolean; readonly abort: () => void; readonly settings: Settings | undefined; readonly localProtocolOptions: LocalProtocolOptions | undefined; readonly autoApprove: boolean | undefined; } /** Thrown by {@link ToolContextSessionView} operations that would need a synchronous cross-thread read. */ export declare class CrossThreadSessionReadError extends Error { constructor(method: string); } /** Receiver-side `ReadonlySessionManager` built from a {@link WireSessionView}; see the module doc. */ export declare class ToolContextSessionView implements ReadonlySessionManager { #private; constructor(wire: WireSessionView); getCwd(): string; getRecordedCwd(): string | undefined; getSessionDir(): string; getSessionId(): string; getSessionFile(): string | undefined; getSessionName(): string | undefined; getArtifactsDir(): string | null; getLeafId(): string | null; getHeader(): SessionHeader | null; ensureOnDisk(): Promise; allocateArtifactPath(toolType: string): Promise<{ id?: string; path?: string; }>; saveArtifact(content: string, toolType: string): Promise; getArtifactPath(id: string): Promise; putBlob(data: Buffer, options?: BlobPutOptions): Promise; putBlobSync(_data: Buffer, _options?: BlobPutOptions): BlobPutResult; getArtifactManager(): ArtifactManager | null; getLeafEntry(): SessionEntry | undefined; getEntry(_id: string): SessionEntry | undefined; getLabel(_id: string): string | undefined; getBranch(_fromId?: string): SessionEntry[]; getEntries(): SessionEntry[]; getTree(): SessionTreeNode[]; getUsageStatistics(): UsageStatistics; } /** Codec carrying tool contexts both ways; register on both ends of a link. */ export declare const toolContextCodec: RpcCodec;