import type { Context } from '@deepseek-ai/cordis'; import { createUserMessage } from '@deepseek-ai/dsh-llm'; import { SessionId } from '@deepseek-ai/dsh-session'; import { type Delivery, type GatewayState, type HandleResult, type HostCall, type Inbound } from './gateway/index.ts'; import type { ModelPick } from './model-command.ts'; export type AgentFace = { id?: unknown; followup: (message: ReturnType) => void; cancel: (cause: { kind: 'user'; }) => void; ctx?: Context; options?: { provider?: string; model?: string; }; }; export type AgentOptionsFace = { provider?: string; model?: string; }; /** * Compose one messaging-owned Agent scope before it is published. * * The callback is deliberately scoped to the Agent factory's setup hook. A * messaging command must not be registered on the Host-wide command layer: * doing so makes it collide with a same-named command supplied by the core * product (for example, the built-in `/model`). */ export type AgentSetup = (agentCtx: Context, agent?: AgentFace) => void; export type HostAgents = { get: (id: ReturnType) => AgentFace | undefined; create: (opts: { sessionId: ReturnType; meta?: { cwd?: string; }; agentOptions?: AgentOptionsFace; setup?: AgentSetup; }) => Promise<{ agent: AgentFace; dispose: () => void; }>; resume: (opts: { resumeSessionId: ReturnType; agentOptions?: AgentOptionsFace; setup?: AgentSetup; }) => Promise<{ agent: AgentFace; dispose: () => void; }>; }; export type HostCommands = { execute: (agent: AgentFace, line: string, attachments: never[], signal: AbortSignal) => Promise<{ result?: { kind: string; text?: string; }; } | undefined>; list: (agent: AgentFace) => { name: string; description: string; }[]; }; export type SkillPiece = { name: string; description: string; }; export declare function assistantTextFromEvent(event: { type: string; data?: unknown; }): string; export declare function turnErrorFromEvent(event: { type: string; data?: unknown; }): string | undefined; export declare class GatewayRuntime { state: GatewayState; readonly path: string; private readonly agents; private readonly commands; private readonly getCommands?; private readonly setupAgent?; private readonly configured; private seq; private leftoverCalls; private pending; private flushWork; private skills; private readonly turnStarted; private readonly turnText; private readonly commitVisibleSent; private readonly turnRaw; private readonly sentVisible; private readonly approvalWaiters; readonly outbox: Delivery[]; onDeliveries: (deliveries: readonly Delivery[]) => void; private sinks; watchDeliveries(fn: (deliveries: readonly Delivery[]) => void): () => void; private readonly defaultModel?; private readonly selectModel?; private readonly cwd?; private readonly onHostSession?; private readonly onArchiveSession?; constructor(args: { path?: string; agents: HostAgents; commands?: HostCommands; getCommands?: () => HostCommands | undefined; setupAgent?: AgentSetup; state?: GatewayState; defaultModel?: (platform?: string) => ModelPick | undefined; selectModel?: (id: string, pick: ModelPick) => Promise; skills?: SkillPiece[]; cwd?: (platform: string) => string | undefined; onHostSession?: (info: { id: string; title: string; cwd: string; platform: string; created: boolean; recents: boolean; }) => void; onArchiveSession?: (id: string) => void; }); setSkills(skills: readonly SkillPiece[]): void; replaceCatalog(commands: readonly { name: string; description: string; }[]): void; run(inbound: Inbound): Promise; flush(): Promise; takeRecoveryCalls(): HostCall[]; apply(inbound: Inbound): HandleResult; list(): import("./gateway/types.ts").MessagingList; nextId(): import("./gateway/types.ts").InboundId; now(): import("./gateway/types.ts").Timestamp; noteAgentStatus(hostId: string, status: string): void; noteSessionEvent(hostId: string, event: { type: string; data?: unknown; }): void; private sendFeishuBubble; /** At most one early bubble: the first spoken sentence. Do not period-split the rest. */ private flushFeishuFirstSpoken; /** * First beat of the turn may already be out. Remainder of this committed * message is one bubble. Later messages in the same turn stay whole. */ private flushFeishuCommitted; perform(call: HostCall): Promise; private performInner; private beginTurn; private endTurn; private commit; private syncCatalog; private keyForHost; private modelFor; private agentSetup; private sessionPlatform; private sessionWantsChatFeel; private sessionIsFeishu; private hostWantsChatFeel; private hostIsFeishu; private feelOpts; private installGatewayChatHooks; private ensureApprovalWaiter; private holdFeishuApproval; /** Return the complete setup used for a messaging-owned Agent. */ setupForAgent(hostId?: string): AgentSetup | undefined; /** * Mount messaging-owned scoped contributions onto an already-live Agent. * This is used when startup discovers that a persisted session was already * resumed by another lifecycle pass, so the resume setup callback did not * get a chance to run in this pass. */ ensureAgentSetup(hostId: string): void; private pinHost; private archiveHost; private rotateAgent; private ensureAgent; private bindNewAgent; } export declare function captureAgents(ctx: Context): HostAgents; export declare function captureCommands(ctx: Context): HostCommands | undefined;