/** * runConversation —— ag-ui SSE 下行适配器的公共入口(原 conversation 模块改名)。 * * 薄入口:把 conversation 协议请求映射成内核 {@link IAgentRunRequest},委托默认 * {@link agentRuntime}(或经 `agentLoop` 注入的临时 runtime)的 * {@link AgentRuntime.runAgentLoop} 产出 `AgentStreamEvent` 流,再用 * {@link streamToConversationEvents} 桥接成 ag-ui SSE。appwrite-gateway 的 HTTP 入口与 * linkque-cli/agentdev 都可直接消费这条流,仅负责「写到哪里」。 * * 协议依赖收口:本文件是 linkque-agent-runtime 内唯一依赖 conversation-contract 入参类型 * 的地方——`ConversationRunRequest`(协议)→ `IAgentRunRequest`(env 无关内核类型), * core 不再 import conversation-contract。 * * 设计要点: * - **不碰 IO / 不挂定时器**:返回纯 async iterable,与 Appwrite 无盘、无随机时钟约束兼容。 * - **内核不产 SSE**:core/agentRuntime 只产事件流;SSE 协议桥接在本适配器,消除原循环。 * - **注入 seam**:单测可经 `agentLoop` 注入 fake {@link IAgentLoop} 断言收到的 * {@link IAgentLoopRequest}(含 messages/技能/历史/工具),不碰真实 pi。生产路径不传 * `agentLoop`,走默认 PiAgentLoop。 */ import type { ConversationRunRequest, ConversationSseEvent } from '../../vendor/linkque-agent-conversation-contract/index.js'; import type { IAgentAuth } from '../../core/types.js'; import { type IAgentRuntime, type IAgentRuntimeRunOptions } from '../../core/agentRuntime.js'; import type { IAgentProtocol } from '../../vendor/linkque-agent-protocol/index.js'; import type { IAgentLoop } from '../../core/ports.js'; /** * runConversation 的额外可选项:在逐 run 运行选项之上加 protocol + agentLoop 注入 + * SSE id 生成器。 * * - `protocol`:提供时经 {@link AgentRuntime.create} 把 systemPrompt/model/resources * 固化进 runtime(推荐生产路径);缺省则裸 `new AgentRuntime()`(单测/noop,默认空)。 * - `agentLoop`:注入下行 fake loop(单测);与 protocol 可并存(经 ports 注入)。 */ export interface IRunConversationOptions extends IAgentRuntimeRunOptions { /** agent 协议声明;提供时用 AgentRuntime.create(protocol) 装配(收口 protocol→runtime)。 */ protocol?: IAgentProtocol; /** 已装配上行端口的 Runtime;CLI/Gateway 可据环境注入。 */ runtime?: IAgentRuntime; /** * 注入下行 agent loop(单测用)。缺省走默认 {@link PiAgentLoop};传入后经 ports 装配, * 若同时传 protocol 则 create(protocol, { agentLoop })。 */ agentLoop?: IAgentLoop; /** 桥接用 id 生成器(messageId),注入便于单测确定性。 */ generateId?: () => string; } /** * 把一份 conversation run 请求跑成 SSE 事件流。 * * @param request 会话协议请求(已由调用方用 parseConversationRunRequest 校验) * @param auth 模型 provider + apiKey(进程内注入,不落盘) * @param options 可选:agentOptions / sessionId / skillResources / mcpResources / * agentLoop(注入)/ generateId(注入) * @returns conversation-contract SSE 事件 async iterable * * @example * ```ts * for await (const ev of runConversation(request, auth)) { * res.write(encodeConversationSseEvent(ev)); * } * ``` */ export declare function runConversation(request: ConversationRunRequest, auth: IAgentAuth, options?: IRunConversationOptions): AsyncIterable;