/** * AgentSessions:本地 Agent session 集合入口。 * * 关键点(中文) * - 统一管理 session 缓存、创建、恢复、默认配置注入与列表查询。 * - 该服务只负责 session 生命周期与查询,不负责 plugin / RPC 启停。 * - Session 对象创建细节集中在这里,避免 facade 和 lifecycle 重复依赖 Session 构造逻辑。 */ import type { Tool } from "ai"; import type { AgentModel } from "../agent/AgentModel.js"; import type { Logger } from "../utils/logger/Logger.js"; import type { AgentCreateSessionInput, AgentArchiveSessionInput, AgentArchiveSessionsInput, AgentArchiveSessionResult, AgentArchiveSessionsResult, AgentCleanArchiveResult, AgentListSessionsInput, AgentSessionSummaryPage } from "../types/agent/SessionTypes.js"; import type { AgentSessionConstructor } from "../types/agent/AgentOptions.js"; import type { AgentSession, AgentSessions as AgentSessionsContract } from "../types/agent/SessionActor.js"; import type { AgentManagedSession } from "../types/session/SessionOptions.js"; import type { SessionPort } from "../types/session/SessionPort.js"; import type { AgentPluginExecutionRuntime } from "../types/plugin/PluginRuntime.js"; import type { AgentStore } from "../types/store/AgentStore.js"; type AgentSessionsOptions = { /** * 当前 agent 稳定标识。 */ agent_id: string; /** * 当前项目根目录。 */ workspace_path: string; /** 当前 Agent 独享的领域持久化入口。 */ store: AgentStore; /** * 当前 agent 默认工具集合。 */ tools: Record; /** * 当前统一日志器。 */ logger: Logger; /** * 当前静态 instruction 文本集合。 */ get_instruction: () => string[]; /** 延迟读取当前 Workspace configured env。 */ get_workspace_env: () => Record; /** 创建当前 configured Plugin registry 的 Session step 执行视图。 */ get_agent_plugins: () => AgentPluginExecutionRuntime; /** * 等待当前 Agent 持有的长期运行时启动完成。 */ ensure_agent_ready: () => Promise; /** * 当前 agent 使用的本地 Session 类。 */ session_class?: AgentSessionConstructor; /** 读取 Agent 当前持有的运行时模型实例。 */ get_agent_model: () => AgentModel | undefined; }; /** * 本地 Agent session 管理服务。 */ export declare class AgentSessions implements AgentSessionsContract { private readonly agent_id; private readonly workspace_path; private readonly store; private readonly tools; private readonly logger; private readonly get_instruction; private readonly get_workspace_env; private readonly get_agent_plugins; private readonly ensure_agent_ready; private readonly session_class; private readonly get_agent_model; private readonly sessions_by_id; constructor(options: AgentSessionsOptions); /** * 返回当前缓存的 session 实例。 */ list_cached_sessions(): AgentManagedSession[]; /** 返回当前所有执行中的 Session 标识。 */ list_executing_session_ids(): string[]; /** 返回当前执行中的 Session 数量。 */ get_executing_session_count(): number; /** 释放全部缓存 Session 的标题后台任务。 */ dispose_title_generation(): void; /** * 把 Agent env 修改广播到已有 Session 的统一输入队列。 */ broadcast_env(env: Record, command_id: string): void; /** * 把 Plugin registry 修改广播到已有 Session 的统一输入队列。 */ broadcast_plugins(input: { command_id: string; title: string; plugins: AgentPluginExecutionRuntime; }): void; /** * 获取或创建一个 session runtime port。 */ runtime(session_id: string): SessionPort; /** * 新建一个 session。 */ create(input?: AgentCreateSessionInput): Promise; /** * 获取一个已存在的 session。 */ get(session_id: string): Promise; /** * 永久删除一个 Session 及其全部 Agent 领域数据。 * * 关键点(中文) * - 正在执行的 Session 会先停止,避免删除后继续写入。 * - 该方法不处理任何 Plugin 自有数据。 */ remove(session_id: string): Promise; /** * 清空一个 Session 的消息目录。 */ clear_messages(session_id: string): Promise; /** * 列出当前 agent 的 session 摘要页。 */ list(input?: AgentListSessionsInput): Promise; /** * 归档单个 session。 */ archive(input: AgentArchiveSessionInput): Promise; /** * 列出当前 agent 的已归档 session 摘要页。 */ archived(input?: AgentArchiveSessionsInput): Promise; /** * 永久清空已归档 session。 */ clean_archive(): Promise; private get_or_create_session; private load_instruction_system_blocks; } export {}; //# sourceMappingURL=AgentSessions.d.ts.map