/** * Host wiring: attach/detach a live dsh session to one durable Codex thread. * * The generic prompt path (`session.prompt` → `agent.followup`/`steer`) * routes to whatever agent the registry holds for the session id. Replacing * that entry with a {@link GatewayAgent} therefore redirects the whole * conversation to Codex without any dsh host patch; removing it returns the * session to cold state, so the host's ordinary resume path rebuilds a * standard loop agent on the next prompt (Q1). * * Registry replacement uses the public `enter`/`announce` primitives for our * own entry and removes the superseded entries from the registries' stores: * the loop factory never exposes the old entry's detach capability, and the * stores explicitly reject same-id replacement. The superseded loop agent is * cancelled (parked); its factory-owned teardown later finds its detach * already consumed and no-ops safely. * * @module dsh-subagent-codex-plus/gateway/attach */ import type { Context } from '@deepseek-ai/cordis'; import { type Agent, type AgentOptions } from '@deepseek-ai/dsh-agent'; import type { SessionId } from '@deepseek-ai/dsh-session'; import { GatewayAgent } from './agent.ts'; import type { GatewayEventForwarderOptions } from './events.ts'; import { CodexGateway } from './gateway.ts'; /** A live session↔Codex attachment. */ export interface AttachedGateway { /** The registered gateway agent (now the session's routing target). */ readonly agent: GatewayAgent; /** The underlying app-server/thread gateway. */ readonly gateway: CodexGateway; /** Durable Codex thread id. */ readonly threadId: string; /** Detach: unregister, restore the session to cold state, stop the child. */ detach(): Promise; } export interface AttachGatewayOptions { /** Working directory for the app-server child and thread. */ readonly cwd: string; /** App-server argv (defaults to the package-local codex bin). */ readonly argv?: readonly string[]; /** Resume an existing durable thread instead of creating one. */ readonly threadId?: string; /** Optional per-thread model override. */ readonly model?: string; /** Optional approval policy for gateway turns. */ readonly approvalPolicy?: string; /** Extra environment for the app-server child. */ readonly env?: Record; /** Per-agent model options carried on the registered agent. */ readonly agentOptions?: AgentOptions; /** Codex → dsh session event forwarding policy (R1-A1/A2). */ readonly eventForwarder?: GatewayEventForwarderOptions; } /** * Attach a session to a Codex thread: start (or resume) the gateway, build a * scoped GatewayAgent, and swap it into the registries in place of the * session's live loop agent. * @param ctx - host context carrying `agents`/`sessions`. * @param sessionId - the live session to take over. * @param options - gateway and agent configuration. * @returns the attachment; call `detach()` to restore normal mode. * @throws when the session is not live, is already attached, or the swap fails. */ export declare function attachGateway(ctx: Context, sessionId: SessionId, options: AttachGatewayOptions): Promise; /** Whether an agent is one of ours (guards boot-time auto-reattach loops). */ export declare function isGatewayAgent(agent: Agent): agent is GatewayAgent;