import { type Tool, type CopilotSession } from "@github/copilot-sdk"; import type { ToolFactsAccessor } from "./tool-facts-accessor.js"; import type { TurnResult, TurnOptions, ManagedSessionConfig } from "./types.js"; /** * The canvas tools — declaration AND per-turn handler both build from these * specs, the same drift-proofing SHOW_ARTIFACT_TOOL_SPEC uses. * * Every session has them, root and sub-agent alike, and every session draws * only its OWN canvases — up to five slots (canvas.html, canvas2..canvas5), * each with a rev and an agent-chosen name. The parent's canvases and a * child's are fully independent surfaces. */ /** * The canvas response contract, normalized to its canonical shape or refused. * * The contract is the SECURITY boundary for interactive canvases: the browser * accepts a postMessage from the canvas iframe only when it names a declared * action and matches its field types exactly, and accepts NOTHING when no * contract was drawn. Keeping the grammar tiny — flat actions, primitive * fields, hard caps — is what keeps the browser-side validator simple enough * to trust. */ export { normalizeCanvasResponseContract } from "./canvas-app-manifest.js"; /** Strip invisible/zero-width characters, then whitespace. */ export declare function stripInvisibleContent(value: string): string; export declare const DEFAULT_TURN_TIMEOUT_MS: number; export declare const DEFAULT_TURN_INACTIVITY_TIMEOUT_MS: number; export declare const TURN_INACTIVITY_ERROR_MARKER = "connection is closed or the subprocess is wedged"; /** * ManagedSession — wraps a CopilotSession and provides the interface * that the orchestration calls into (via SessionProxy). * * Key design decisions: * 1. Uses send() + on() internally, never sendAndWait(). * 2. runTurn() returns a TurnResult to the orchestration — the orchestration * decides what to do with wait/input_required/completed. * 3. The session stays alive in memory across runTurn() calls. * 4. Abort is cooperative — the orchestration cancels via race, which * triggers abort() on this session. * * @internal */ export declare class ManagedSession { readonly sessionId: string; private copilotSession; private config; /** Skills the `load_skill` tool may return, by reference from the worker. */ private skillCatalog; private factsAccessor; setFactsAccessor(accessor: ToolFactsAccessor | null): void; setSkillCatalog(list: Array<{ name: string; description: string; prompt: string; }>): void; /** Set for the duration of runTurn(); read by the lock-bypassing stop path. */ private activeTurn; private nativeFeatureRevoked; canAdmitNativeTask(): boolean; /** A cached OFF is sticky for this turn, even if the next poll is ON. */ refreshNativeFeaturePolicy(): void; /** Set only by requestStop(); classifies the turn unwind as "stopped". */ private stopRequest; /** Resolver for the current turn's completion promise — hang escalation hook. */ private settleTurnResolver; constructor(sessionId: string, copilotSession: CopilotSession, config: ManagedSessionConfig); /** * System tool definitions for session creation. * These are registered at createSession time so the LLM sees them. * Handlers are placeholder stubs — real handlers are set per-turn in runTurn(). * * `agentIdentity` selects the bundles only some agents carry. A tool * declaration is resident context on every turn of every session that * carries it, so the ten provider budget tools go to the two Token * Manager agents and nobody else. Omitting it declares the tools every * session gets. */ static systemToolDefs(opts?: { agentIdentity?: string | null; }): Tool[]; /** * Sub-agent tool definitions. * These are the LLM-visible tools for spawning and managing sub-agents. * Like wait/ask_user, handlers are stubs — real handlers set per-turn in runTurn(). */ static subAgentToolDefs(): Tool[]; /** * Child management tool definitions (complete, cancel, delete). * Separated for clarity but included in subAgentToolDefs(). */ static _childManagementToolDefs(): Tool[]; /** * Run one LLM turn. * * The wait tool is injected automatically. If the LLM calls wait() * with seconds > waitThreshold, we abort the session and return * a "wait" result so the orchestration can schedule a durable timer. * * Similarly, if onUserInputRequest fires, we abort and return * "input_required" so the orchestration can wait for the user's answer. * * Stop classification: a user stop (requestStop → abort) reclassifies the * unwind as `{ type: "stopped" }` regardless of how the inner turn settled * — checked BEFORE pendingActions so a stop that races a wait()/ask_user * control-tool abort wins instead of being swallowed into a durable timer, * and applied to error unwinds so a forced settle/disconnect is not * misclassified as a retryable error. */ runTurn(prompt: string, opts?: TurnOptions): Promise; /** The in-flight turn, if any. Read by the lock-bypassing stop path. */ getActiveTurn(): { turnIndex: number; startedAt: number; } | null; /** * Mark the in-flight turn as user-stopped so its unwind classifies as * `stopped`. Returns the active turn info, or null when no turn is * running. Does NOT abort by itself — callers pair this with abort(). */ requestStop(reason: string): { turnIndex: number; } | null; /** * Hang escalation: resolve the current turn's completion promise directly. * runTurn() settles only on the SDK's `session.idle` event; if a wedged * stream never fires it, this forces the unwind without depending on any * further SDK behavior. Pair with requestStop() so the unwind classifies * as `stopped`. Returns false when no turn is in flight. */ forceSettleTurn(reason: string): boolean; private _runTurnInner; /** * Abort the current in-flight message. * Session remains alive for future runTurn() calls. */ abort(): void; /** * Destroy the session — release resources, flush to disk. */ destroy(): Promise; /** * Get conversation messages from the underlying session. * copilot-sdk 1.0.6 renamed getMessages() → getEvents() (same * "session.getMessages" RPC underneath); keep our wrapper name stable. */ getMessages(): Promise; /** * Update configuration for the next turn. */ getNativeTaskAccess(): import("./native-task-policy.js").NativeTaskAccess | undefined; updateConfig(config: Partial): void; requiresModelRebind(config: Partial): boolean; /** Get the underlying CopilotSession (for direct access when needed). */ getCopilotSession(): CopilotSession; } //# sourceMappingURL=managed-session.d.ts.map