/** * SDK 本地 Session 封装。 * * 关键点(中文) * - 面向 `new Agent(...)` 的本地会话使用场景。 * - 对外保留稳定 Session facade,把状态、turn、view 逻辑下沉到独立 service。 * - 内部使用 `SessionMessages` 统一管理 Active、Segment 与流式 Assistant 草稿。 */ import type { LanguageModel } from "ai"; import type { AgentSessionConfigSnapshot, AgentSessionForkInput, AgentSessionInfo, AgentSessionStatus, AgentSessionSetInput, AgentSessionSetOptions, AgentSessionSystemSnapshot } from "../types/agent/SessionTypes.js"; import type { AgentSession } from "../types/agent/SessionActor.js"; import type { SessionPort } from "../types/session/SessionPort.js"; import type { SessionMutationSubscriber, SessionMutationUnsubscribe } from "../types/session/SessionMutation.js"; import type { RespondSessionInteractionInput, SessionInteractionResult, SessionPendingInteraction } from "../types/session/SessionInteraction.js"; import type { ListSessionMessagesInput, SessionMessagePage } from "../types/session/SessionMessage.js"; import type { AgentSessionPromptInput } from "../types/sdk/AgentSessionPrompt.js"; import type { AgentSessionStopResult } from "../types/sdk/AgentSessionStop.js"; import type { AgentSessionCompactHandle } from "../types/sdk/AgentSessionCompact.js"; import type { AgentSessionTurnHandle } from "../types/sdk/AgentSessionTurn.js"; import type { SessionOptions } from "../types/session/SessionOptions.js"; import type { AgentPluginExecutionRuntime } from "../types/plugin/PluginRuntime.js"; /** * SDK 本地 Session。 */ export declare class Session implements AgentSession { readonly id: string; readonly agent_id: string; private readonly workspace_path; private readonly store; private readonly get_session_store; private readonly tools; private readonly logger; private readonly get_managed_plugin_system_blocks; private readonly ensure_configured_hook?; private readonly composer; private readonly session_messages; private readonly executor; private readonly events; private readonly session_interactions; private readonly shell_approval_adapter; private readonly local_state; private readonly get_workspace_env; private readonly get_agent_model; private readonly get_agent_plugins; private readonly get_instruction_system_blocks; private effective_instruction_system_blocks; /** 当前 Session 的一次性初始化任务,避免缓存实例被重复恢复运行时状态。 */ private initialize_promise; private instruction_initialize_promise; private effective_workspace_env; private effective_agent_plugins; /** 当前 Session 首次生成后固定的完整 system snapshot。 */ private system_snapshot_blocks; /** 串行化 snapshot / syncshot 对 system 与 instruction.md 的修改。 */ private system_mutation_chain; private readonly state; /** 当前 Session 独享的 Command FIFO。 */ private readonly session_queue; private readonly session_loop; private runtime_port; constructor(options: SessionOptions); /** * 初始化当前 session。 */ initialize(): Promise; /** * 把当前 Session 首次生成后固定的完整 system 显式固化到 instruction.md。 * * 关键点(中文) * - 包含 instruction、SDK core、plugin system 与 Session context。 * - 多个 system block 按原顺序合并为一个 Markdown 文档。 */ snapshot(): Promise; /** * 使用 Agent 当前 instruction 与 plugin 重新生成一次完整 system。 * * 关键点(中文) * - 只替换内存 snapshot,不改变 plugin execution view。 * - instruction.md 已存在时同步覆盖;不存在时不自动创建。 * - 当前已经发出的 provider 请求不受影响,后续 step 使用新 snapshot。 */ syncshot(): Promise; /** * 读取当前 session 配置快照。 */ get config(): AgentSessionConfigSnapshot; /** * 写入当前 session 默认配置。 */ set(input: AgentSessionSetInput, options?: AgentSessionSetOptions): Promise; /** * 追加一条新的 Session prompt。 */ prompt(input: AgentSessionPromptInput): Promise; /** * 停止当前 turn,并取消尚未被吸收的排队 prompt。 */ stop(): Promise; /** * 把一次显式历史压缩加入当前 Session 的有序输入队列。 */ compact(): Promise; /** 把 Workspace env 快照加入当前 Session 的有序输入队列。 */ enqueue_workspace_env(input: { /** 当前 Workspace env 修改的稳定标识。 */ command_id: string; /** 下一 Session Step 使用的完整环境变量快照。 */ env: Record; }): void; /** 把 Agent Plugin 执行视图加入当前 Session 的有序输入队列。 */ enqueue_agent_plugins(input: { /** 当前 Plugin 修改的稳定标识。 */ command_id: string; /** 当前 Plugin 修改的用户可读标题。 */ title: string; /** 下一 Session Step 使用的 Plugin 执行视图。 */ plugins: AgentPluginExecutionRuntime; }): void; /** 创建一个具体 Session Command 对象并加入当前 FIFO。 */ private enqueue_command; /** * 订阅当前 Session 的未来事件。 */ subscribe(subscriber: SessionMutationSubscriber): SessionMutationUnsubscribe; /** 列出当前 Session 正在等待用户响应的 Interaction。 */ interactions(): Promise; /** 读取当前 Session 的运行与安全状态。 */ status(): Promise; /** 提交当前 Session 的 Interaction 用户响应。 */ respond(input: RespondSessionInteractionInput): Promise; /** * 追加一条 user 文本消息。 */ append_user_message(input: { text: string; }): Promise; /** * 追加一条 assistant 文本消息。 */ append_assistant_message(input: { text: string; }): Promise; /** * 读取当前 session 详情。 */ get_info(): Promise; /** * 读取当前 session records 分页。 */ messages(input?: ListSessionMessagesInput): Promise; /** * 读取当前 session 生效的 system 快照。 */ system(): Promise; /** * 返回当前 session 是否正在执行。 */ is_executing(): boolean; /** * 从当前 session 创建一个分叉会话。 */ fork(input?: AgentSessionForkInput | string): Promise; /** 截取 Fork 目标 Message 及其之前的完整历史。 */ private resolve_fork_messages; /** * 返回供受托管 plugin 使用的 session 端口。 */ get_runtime_port(): SessionPort; /** 取消并释放当前 Session 的标题后台任务。 */ dispose_title_generation(): void; /** * 在执行前确保 session 已完成初始化与宿主装配。 */ ensure_ready_for_execution(): Promise; private create_fork_session; /** * 创建当前 Session 的同类子会话。 * * 关键点(中文) * - 默认沿用当前实例的 class,避免自定义 Session 在 fork 后退回默认实现。 * - 子类仍可覆盖该方法,接管更特殊的子会话创建逻辑。 */ protected create_child_session(options: SessionOptions): this; /** 恢复显式固化的完整 system snapshot;文件不存在时等待首次生成。 */ private initialize_instruction; private create_local_state; /** 创建只依赖统一 Composer 的 Turn Executor。 */ private create_executor; /** 为 Composer 创建当前 Step 的只读 Session 快照。 */ private create_compose_input; /** 创建 Composer 共用的稳定 Session 身份快照。 */ private create_compose_identity; /** 生成并提交 canonical 历史压缩;该职责不进入 Executor。 */ private compact_history; /** 使用统一 Composer 生成只读 system/history 查询结果。 */ private compose_for_view; /** 固定或应用当前 Session 的 system snapshot。 */ private apply_system_snapshot; /** 串行执行一次 Session system 修改。 */ private run_system_mutation; /** 把指定完整 system blocks 原子写入 instruction.md。 */ private write_system_snapshot; /** 提交 Composer 生成的 Segment 压缩计划。 */ private commit_compaction_plan; /** * 返回当前 Session 实际使用的模型实例。 * * 解析顺序固定为 Session 覆盖模型,其次回退到 Agent 模型。 */ get_model(): LanguageModel | undefined; /** 按 Session 优先、Agent 兜底规则读取当前配置的 AgentModel。 */ private get_selected_model; /** 读取当前有效模型对应的上下文窗口。 */ private get_model_context_window; /** 持久化并发布一条 canonical Action Message。 */ private emit_action_event; } //# sourceMappingURL=Session.d.ts.map