import * as _agentclientprotocol_sdk0 from "@agentclientprotocol/sdk"; //#region src/v1/acp/vendor/sdk.d.ts type PromptResponse$1 = _agentclientprotocol_sdk0.PromptResponse; type CancelNotification = _agentclientprotocol_sdk0.CancelNotification; type SessionNotification = _agentclientprotocol_sdk0.SessionNotification; type ContentBlock = _agentclientprotocol_sdk0.ContentBlock; type TextContent = _agentclientprotocol_sdk0.TextContent; type ImageContent = _agentclientprotocol_sdk0.ImageContent; type AudioContent = _agentclientprotocol_sdk0.AudioContent; type ResourceLink = _agentclientprotocol_sdk0.ResourceLink; type EmbeddedResource = _agentclientprotocol_sdk0.EmbeddedResource; //#endregion //#region src/v1/types.d.ts /** * 公共数据类型 */ /** 规则配置 */ interface ManifestRule { name: string; downloadUrl: string; scope?: 'USER' | 'PROJECT'; } /** 技能配置 */ interface ManifestSkill { name: string; downloadUrl?: string; scope?: 'USER' | 'PROJECT'; } /** 子代理配置 */ interface ManifestSubagent { name: string; downloadUrl?: string; scope?: 'USER' | 'PROJECT'; } /** Slash Command 配置 */ interface ManifestSlashCommand { name: string; downloadUrl?: string; scope?: 'USER' | 'PROJECT'; } /** 插件配置 */ interface ManifestPlugin { name: string; marketplace?: string; marketplaceUrl?: string; downloadUrl?: string; } /** MCP 配置 */ interface ManifestMcp { name: string; downloadUrl: string; scope?: 'USER' | 'PROJECT'; } /** 工作空间配置 */ interface ManifestWorkspace { name: string; repository?: string; ref?: string; depth?: number; includeSubmodules?: boolean; downloadUrl?: string; localPath?: string; templatesDownloadUrl?: string; initShellCommand?: string; initCommand?: string; } /** 环境变量 */ interface ManifestEnv { key: string; value: string; } /** 密钥 */ interface ManifestSecret { key: string; value: string; } /** Agent Manifest 完整类型 */ interface AgentManifest { id: string; name: string; manifestVersion: string; system_prompt?: string; system_prompt_file?: string; useWorkspaceRoot?: boolean; isolateConfigDir?: boolean; settings?: string; rules?: ManifestRule[]; skills?: ManifestSkill[]; subagents?: ManifestSubagent[]; slashCommands?: ManifestSlashCommand[]; plugins?: ManifestPlugin[]; mcp?: ManifestMcp[]; workspaces?: ManifestWorkspace[]; secrets?: ManifestSecret[]; envs?: ManifestEnv[]; [k: string]: unknown; } type RuntimeStatus = 'CREATING' | 'RUNNING' | 'PRE-STOPPED' | 'STOPPED' | 'FAILED'; interface AcpLink { url: string; token: string; tokenExpiresAt: number; } interface SandboxLink { endpoint: string; dataPlaneEndpoint: string; sandboxId: string; } interface RuntimeLinks { acpLink?: AcpLink; sandboxLink?: SandboxLink; clusterDomainSuffix?: string; } /** Runtime 简要信息(列表接口返回) */ interface RuntimeBrief { id: string; runtimeName: string; createdAt: string; } /** Runtime 完整信息(get/create 接口返回) */ interface RuntimeInfo extends RuntimeBrief { sandboxTemplateId?: string; sandboxSpec?: SandboxSpec; status: RuntimeStatus; currentVersionId?: string; originRuntimeId?: string; metadata?: Record; failureReason?: string; links?: RuntimeLinks; sessions: SessionBrief[]; updatedAt: string; } type SessionStatus = 'CREATING' | 'ACTIVE' | 'IDLE' | 'TERMINATED'; interface SessionBrief { sessionId: string; sessionStatus: SessionStatus; sessionName?: string; } interface SessionInfo { runtimeId: string; sessionId: string; sessionName?: string; sessionStatus: SessionStatus; lastActivityAt?: string; createdAt: string; updatedAt: string; } /** Sandbox 规格配置(CPU / 内存 / 其他厂商扩展)。 */ interface SandboxSpec { cpu?: string; memory?: string; [k: string]: unknown; } /** `POST /runtimes` 请求体。 */ interface CreateRuntimeRequest { runtimeName: string; agentManifest?: AgentManifest; sandboxTemplateId?: string; sandboxSpec?: SandboxSpec; sandboxType?: string; visibility?: 'PRIVATE' | 'PUBLIC'; metadata?: Record; } /** `POST /runtimes/{id}/update` 请求体。 */ interface UpdateRuntimeRequest { runtimeName?: string; visibility?: 'PRIVATE' | 'PUBLIC'; metadata?: Record; } /** `POST /runtimes/{id}/sessions` 请求体。 */ interface CreateSessionRequest { sessionId?: string; sessionName?: string; agentManifest?: AgentManifest; } /** `POST /runtimes/{id}/sessions/{sid}/update` 请求体。 */ interface UpdateSessionRequest { sessionName?: string; agentManifest?: AgentManifest; } /** * `session.prompt()` 的返回值。 * * **当前只暴露 `stopReason`**——虽然上游 ACP 协议 `PromptResponse` 还有 * `_meta` / `userMessageId` / `usage` 等字段,但它们在 sandbox-proxy 当前的 * 实现下: * - `_meta` / `userMessageId` 根本不填 * - `usage` 依赖底层 agent SDK 的 result 消息,稳定性和数据源未对齐 * * 暴露这些字段容易误导用户,等服务端契约稳定后再放开。 * * 如果要拼接 agent 最终文本,请走 `onChunk` / `session.subscribe()` 的 * notification 通道(`agent_message_chunk`)——协议把"流式内容"和"终局结果" * 分离,这是订阅模型的根本原因。 */ type PromptResponse = Pick; interface Pagination { page: number; pageSize: number; total: number; totalPages: number; } interface PageResult { items: T[]; pagination: Pagination; } interface DeleteResult { code: string; message: string; runtimeId?: string; sessionId?: string; } //#endregion //#region src/v1/opts.d.ts /** * 日志器接口(鸭子类型)。 * * 兼容 `console` / pino / winston / consola / bunyan —— 和 OpenAI / Anthropic * 官方 SDK 保持一致。SDK 内部只调用这 4 个方法。 * * 详见 docs/agentos/sdk/07-error-retry.md § 4.1。 */ interface Logger { debug(message: string, ...args: unknown[]): void; info(message: string, ...args: unknown[]): void; warn(message: string, ...args: unknown[]): void; error(message: string, ...args: unknown[]): void; } /** 日志级别(数值越大越详细)。 */ type LogLevel = 'off' | 'error' | 'warn' | 'info' | 'debug'; /** * 重试决策的上下文信息(传给 `RetryOpts.retryOn`)。 * * 让用户在自定义判定函数里能感知"当前是哪种请求 / 第几次尝试"。 */ interface RetryContext { /** 当前重试次数(首次尝试为 1)。 */ attempt: number; /** HTTP 方法(`GET` / `POST` / `PATCH` / `DELETE`)。 */ method: string; /** 完整请求 URL。 */ url: string; } /** * 自定义重试判定。 * * 返回 `true` 则按 `maxAttempts` 继续重试,返回 `false` 则立即抛错给调用方。 * 传入 `RetryOpts.retryOn` 会**完全替换** SDK 内置默认判定(不叠加、不 fallback)。 */ type RetryOn = (err: Error, ctx: RetryContext) => boolean; interface RetryOpts { /** 最大尝试次数(含首次),默认 3。 */ maxAttempts?: number; /** 首次退避毫秒,默认 300。 */ backoffMs?: number; /** 退避指数因子,默认 2。 */ backoffFactor?: number; /** 是否加 ±20% 抖动,默认 true。 */ jitter?: boolean; /** * 自定义判定。不传时用 SDK 内置默认判定: * - `AuthError` / `NotFoundError` / `ValidationError` / `AcpProtocolError` → 不重试 * - `TimeoutError` → 仅 `GET` 方法重试(非幂等方法超时可能导致重复副作用) * - `NetworkError` → 全部方法重试 * - `AbortError`(用户主动取消)→ 不重试 * - 其他(fetch 原生异常等)→ 重试 */ retryOn?: RetryOn; } interface ConnectionOpts { apiKey?: string; baseUrl?: string; /** * 来源应用标识,发送为 `X-Source-App` header。默认 `'cloud-agent'`。 * * 该值会写入 runtime 表的 `source_app` 字段,影响 `runtimes.list()` 的可见性过滤。 * 如无特殊需求请勿改为 `'default-app'`(服务端 ListRuntimes 会硬编码排除该值)。 */ sourceApp?: string; sourceTenantId?: string; userId?: string; timeoutMs?: number; headers?: Record; retry?: RetryOpts | false; /** * 日志级别。默认 `'warn'`;也可用环境变量 `CLOUD_AGENT_SDK_LOG` 配置。 * 优先级:`logLevel` > env > `'warn'`。 * * 级别说明: * - `'off'`:全静默 * - `'error'` / `'warn'` / `'info'`:SDK 自身日志(vendor 内部沉默) * - `'debug'`:SDK 全部日志 + 透传给 ACP vendor(暴露状态迁移、artifact 收发等) */ logLevel?: LogLevel; /** 自定义日志器;默认 `globalThis.console`。 */ logger?: Logger; /** * 替换底层 fetch 实现。常见用法: * - 接入 OpenTelemetry:传入 `@opentelemetry/instrumentation-fetch` 包装过的 fetch * - 自定义代理 / 拦截 / mock * 默认使用全局 `fetch`(Node 18+ 和现代浏览器原生支持)。 */ fetch?: typeof fetch; /** 请求发出前回调。`headers` 已脱敏(敏感字段替换为 `'***'`)。 */ onRequest?: (req: { method: string; url: string; headers: Record; }) => void; /** 响应到达后回调。`headers` 已脱敏。 */ onResponse?: (res: { status: number; headers: Record; url: string; }) => void; } interface RequestOpts { timeoutMs?: number; /** 附加自定义 header(业务可塞 `traceparent` 等,SDK 原样透传)。 */ headers?: Record; retry?: RetryOpts | false; signal?: AbortSignal; /** 发送为 `X-Request-Id`;业务自定义 ID 可用此字段。 */ requestId?: string; } interface RuntimeCreateOpts extends RequestOpts { runtimeName: string; agentManifest?: AgentManifest; sandboxTemplateId?: string; sandboxSpec?: SandboxSpec; sandboxType?: string; visibility?: 'PRIVATE' | 'PUBLIC'; metadata?: Record; } interface RuntimeConnectOpts extends RequestOpts { acpToken?: string; autoRefreshToken?: boolean; reconnectMaxAttempts?: number; reconnectBackoffMs?: number; reconnectMaxBackoffMs?: number; heartbeatTimeoutMs?: number; initialize?: boolean; lastEventId?: string; } interface SessionCreateOpts extends RequestOpts { sessionId?: string; sessionName?: string; agentManifest?: AgentManifest; /** 指定 Agent ID 时,走 Agent Session 接口(使用 Agent 已发布版本的 manifest)。 */ agentId?: string; } interface PromptOpts { /** 取消信号。触发时 SDK 会向服务端发 `session/cancel`,并中止本次等待。 */ signal?: AbortSignal; /** 超时毫秒(默认 无限;由 AbortSignal.timeout 自行组合即可)。 */ timeoutMs?: number; includeThinking?: boolean; model?: string; /** * Prompt 开始后触发一次(已自动 connect 完成、RPC 即将发出)。 * * 常用于"开始打字"之类的 UI 状态切换。 */ onTurnStart?: () => void; /** * Prompt 结束后触发一次,收到 `PromptResponse`(当前含 `stopReason`)。 * 失败时不触发本回调(错误由 `prompt()` 的 Promise reject 传递)。 */ onTurnEnd?: (response: PromptResponse) => void; /** * 便利钩子:prompt 期间每条上游 `SessionNotification` 都会触发一次。 * * 内部实现等价于"prompt 开始时临时 `session.subscribe(fn)`,prompt 结束时 * 自动 unsubscribe"。只关心本次 prompt 的流式内容时用它,无需手动管理订阅 * 生命周期;如果你想跨 prompt 持续订阅,直接用 `session.subscribe()`。 */ onChunk?: (notification: SessionNotification) => void; } interface RuntimeListOpts extends RequestOpts { page?: number; pageSize?: number; metadata?: Record; } interface SessionListOpts extends RequestOpts { page?: number; pageSize?: number; sessionStatus?: string; } //#endregion //#region src/v1/rest/client.d.ts /** * SDK 内置的默认重试判定。 * * 传 `retry: { retryOn: ... }` 会**完全替换**这里的规则(不叠加)。 * 公开这个函数是为了让用户在自定义 `retryOn` 里可以手动调用回落到默认: * * ```ts * retry: { * retryOn: (err, ctx) => { * if (err instanceof TimeoutError && ctx.url.includes('/upload')) return false; * return DEFAULT_RETRY_ON(err, ctx); * }, * } * ``` */ declare const DEFAULT_RETRY_ON: RetryOn; declare class RestClient { private readonly opts; private readonly logger; private readonly fetchImpl; constructor(opts: ConnectionOpts); /** GET 请求。 */ get(path: string, query?: Record, opts?: RequestOpts): Promise; /** POST 请求。 */ post(path: string, body?: unknown, opts?: RequestOpts): Promise; /** PUT 请求。 */ put(path: string, body?: unknown, opts?: RequestOpts): Promise; /** PATCH 请求。 */ patch(path: string, body?: unknown, opts?: RequestOpts): Promise; /** DELETE 请求。 */ delete(path: string, opts?: RequestOpts): Promise; /** 构建完整 URL。 */ private buildUrl; /** 构建请求 headers(含认证、身份、trace、自定义)。 */ private buildHeaders; /** 发起请求(含超时 + 重试 + 日志 + 脱敏 + hooks)。 */ private request; /** 解包响应 `{ code, msg, data }` → `data` 或抛错。 */ private unwrap; /** HTTP 状态码映射为错误。 */ private httpStatusToError; /** 业务 code 映射为错误。 */ private codeToError; /** * 重试逻辑。 * * 是否重试只看 `opts.retryOn(err, ctx)`。用户传的 retryOn **完全替换** SDK * 默认判定(不叠加、不 fallback 到 error 类上的任何字段)。 */ private withRetry; /** 计算退避时间。 */ private getBackoffMs; } //#endregion //#region src/v1/agent.d.ts /** Agent 详情(create/get 返回) */ interface AgentInfo { id: string; agentId: string; agentName: string; description: string; avatar: string; model: string; manifest: Record | null; enabled: boolean; createdAt: string; updatedAt: string; } /** Agent 列表项(不含 manifest,减少传输) */ interface AgentListItem { id: string; agentId: string; agentName: string; description: string; avatar: string; model: string; enabled: boolean; createdAt: string; updatedAt: string; } /** 版本详情 */ interface AgentVersionInfo { id: string; agentId: string; versionNumber: string; description: string; isCurrent: boolean; status: number; model: string; manifest: Record | null; creatorId: string; creatorName: string; createdAt: string; updatedAt: string; } /** 版本列表项 */ interface AgentVersionListItem { id: string; versionNumber: string; description: string; isCurrent: boolean; status: number; instanceCount: number; creatorName: string; createdAt: string; } /** ACP 连接信息 */ interface AgentACPLink { url: string; token: string; tokenExpiresAt: number; } /** 创建 Session 响应 */ interface AgentSessionResponse { sessionId: string; runtimeId: string; acp?: AgentACPLink; createdAt: string; } /** 创建 Agent */ interface CreateAgentRequest { agentName: string; model: string; manifest: Record | AgentManifest; description?: string; avatar?: string; } /** 创建 Agent Session */ interface CreateAgentSessionRequest { agentId: string; runtimeId: string; sessionName?: string; } /** 发布版本 */ interface PublishVersionRequest { model: string; manifest: Record | AgentManifest; description?: string; agentName?: string; } /** 保存草稿 */ interface SaveDraftRequest { model: string; manifest: Record | AgentManifest; description?: string; agentName?: string; } /** 分页结果(Agent 列表专用,对齐后端) */ interface AgentListResponse { total: number; page: number; pageSize: number; items: AgentListItem[]; } /** 分页结果(Version 列表专用) */ interface VersionListResponse { total: number; page: number; pageSize: number; items: AgentVersionListItem[]; } declare class Agent { readonly id: string; /** Agent 详情快照 */ private _info; /** @internal */ private readonly _restClient; /** @internal */ constructor(restClient: RestClient, info: AgentInfo); get agentInfo(): AgentInfo; get agentName(): string; get description(): string; get model(): string; get enabled(): boolean; readonly versions: { /** 版本列表 */list: (opts?: RequestOpts & { page?: number; pageSize?: number; }) => Promise>; /** 获取版本详情 */ get: (versionId: string, opts?: RequestOpts) => Promise; /** 发布新版本 */ publish: (req: PublishVersionRequest, opts?: RequestOpts) => Promise; /** 删除版本 */ delete: (versionId: string, opts?: RequestOpts) => Promise; /** 切换当前版本 */ setCurrent: (versionId: string, opts?: RequestOpts) => Promise; }; readonly draft: { /** 保存草稿 */save: (req: SaveDraftRequest, opts?: RequestOpts) => Promise; /** 获取草稿 */ get: (opts?: RequestOpts) => Promise; /** 发布草稿 */ publish: (description?: string, opts?: RequestOpts) => Promise; }; } //#endregion //#region src/v1/session.d.ts declare class Session { readonly id: string; readonly runtimeId: string; private readonly _runtime; private readonly _restClient; /** 数据面 ACP 客户端(connect() 后可用) */ private _acpClient; /** connect 前预注册的订阅器;连接建立后会灌入当前 acp client。 */ private readonly _pendingSubscribers; /** 控制面状态(来自最近一次 info() / update())。 */ private _status; /** @internal */ constructor(id: string, runtime: Runtime, restClient: RestClient); get status(): SessionStatus | undefined; /** ACP 连接是否已建立 */ get connected(): boolean; /** 拉最新元数据 */ info(opts?: RequestOpts): Promise; /** 更新 name / manifest */ update(req: UpdateSessionRequest, opts?: RequestOpts): Promise; /** 软删除 */ delete(opts?: RequestOpts): Promise; /** * 建立到沙箱的 ACP 连接。 * * 内部流程:GET SSE → 获取 connectionId → initialize → session/load。 * 调用后 `prompt` / `subscribe` / `cancel` 才可用。 * * 幂等:已连接时直接返回;并发调用时后来的等前者完成。 */ connect(opts?: RuntimeConnectOpts): Promise; /** 断开 ACP 连接。所有订阅器被自动清除。 */ disconnect(): Promise; /** * 发送 prompt 并等待 `PromptResponse`。 * * @param input 纯文本字符串(自动包装成 text block)或 `ContentBlock[]`(多模态) * @param opts 见 `PromptOpts`,支持 `signal` 取消、`onChunk` 便利钩子等 * * @returns `PromptResponse`(当前只含 `stopReason`) * * **时序**: * - 如果未 connect,会自动 connect * - RPC 发出期间,上游会通过 **SSE notification 通道**推送 `session/update`, * 这些消息**不会进 Promise 的结果**,需要通过 `subscribe()` 或 `onChunk` * 回调接收 * - 同 session 并发 prompt 会被内部**串行化**(ACP 协议要求) * * @example * ```ts * // 最简:只要结果 * const r = await session.prompt('2+2?'); * * // 流式打印 + 结果 * const r = await session.prompt('write a poem', { * onChunk: (n) => { * if (n.update.sessionUpdate === 'agent_message_chunk' && * n.update.content.type === 'text') { * process.stdout.write(n.update.content.text); * } * }, * }); * * // 取消 * const ctrl = new AbortController(); * setTimeout(() => ctrl.abort(), 5000); * const r = await session.prompt('long task', { signal: ctrl.signal }); * ``` */ prompt(input: string | ContentBlock[], opts?: PromptOpts): Promise; /** * 订阅该 session 所有上游 notifications。 * * Listener 收到的是上游 `SessionNotification` 原样(`{ sessionId, update, _meta? }`)。 * `update` 是上游 11-tag 判别联合,在 switch 分支里类型自动收窄。 * * 订阅独立于 prompt 生命周期——connect 之后注册,直到 unsubscribe 或 * disconnect 为止。未 connect 时也可以先注册,后续 connect / reconnect 到 * 该 session 后会自动生效。一个 session 支持任意多个订阅者。 * * @returns unsubscribe 函数,调用即退订。 * * @example * ```ts * const unsub = session.subscribe((n) => { * switch (n.update.sessionUpdate) { * case 'agent_message_chunk': * if (n.update.content.type === 'text') print(n.update.content.text); * break; * case 'tool_call': * console.log('tool:', n.update.title); * break; * } * }); * // ... * unsub(); * ``` */ subscribe(listener: (notification: SessionNotification) => void): () => void; /** * 取消当前运行的 prompt(如果有)。 * * 向服务端发 `session/cancel` notification,服务端会以 `stopReason: 'cancelled'` * 结束当前 prompt,对应的 `prompt()` Promise 正常 resolve(不 reject)。 * * **尽力而为**:服务端 RPC 失败时打 warn 日志吞掉,不抛给调用方—— * 因为"用户点了取消按钮"的 UX 契约就是"本地能返回"。 */ cancel(): Promise; /** * 设置 session 使用的模型。 * * 必须在 `connect()` 之后调用。 * * @param modelId 目标模型 ID,例如 `"gpt-4o"` / `"claude-3-7-sonnet"` * * @experimental 对应 ACP 协议的 `unstable_setSessionModel`,API 尚未稳定。 * * @example * ```ts * await session.connect(); * await session.setModel('claude-3-7-sonnet'); * const r = await session.prompt('hello'); * ``` */ setModel(modelId: string): Promise; } //#endregion //#region src/v1/runtime.d.ts declare class Runtime { readonly id: string; /** 控制面信息快照(创建/刷新时更新) */ private _info; /** 数据面连接信息 */ readonly sandboxId?: string; readonly sandboxDomain?: string; private _acpUrl?; private _acpToken?; /** 内部依赖 */ private readonly _restClient; /** @internal 供 Session 构造 AcpClient 时读取(logger / fetch)。 */ readonly _connectionOpts: ConnectionOpts; /** 默认 session ID */ private _defaultSessionId; /** @internal */ constructor(restClient: RestClient, connectionOpts: ConnectionOpts, info: RuntimeInfo); get runtimeInfo(): RuntimeInfo; get acpUrl(): string | undefined; get acpToken(): string | undefined; /** 更新 Runtime 元数据 */ update(req: UpdateRuntimeRequest, opts?: RequestOpts): Promise; /** 软删除 */ delete(opts?: RequestOpts): Promise; /** 刷新 token(拉最新 RuntimeInfo,更新 acpLink) */ refreshToken(opts?: RequestOpts): Promise; readonly sessions: { /** * 创建新 Session(控制面),返回 Session 实例。 * * - 不传 `agentId`:走 `/runtimes/{id}/sessions`,使用入参 manifest * - 传 `agentId`:走 `/agents/sessions`,使用 Agent 已发布版本的 manifest */ create: (opts: SessionCreateOpts) => Promise; /** 获取 Session(返回实例) */ get: (sessionId: string, opts?: RequestOpts) => Promise; /** 分页列表(返回纯数据) */ list: (opts?: SessionListOpts) => Promise>; /** 默认 session(Runtime 创建时自动生成的) */ default: () => Session; }; } //#endregion //#region src/v1/client.d.ts declare class CloudAgentClient { private readonly opts; /** @internal */ readonly _restClient: RestClient; /** 构造(同步,不发网络请求) */ constructor(opts?: ConnectionOpts); /** 派生新实例(覆盖部分配置,如切换 sourceApp) */ with(overrides: Partial): CloudAgentClient; readonly agents: { /** * 创建 Agent * * 创建后自动生成一个 v1 版本。 */ create: (req: CreateAgentRequest, opts?: RequestOpts) => Promise; /** 获取 Agent 详情(返回 Agent 实例) */ get: (agentId: string, opts?: RequestOpts) => Promise; /** Agent 分页列表 */ list: (opts?: RequestOpts & { page?: number; pageSize?: number; keyword?: string; }) => Promise; /** 删除 Agent */ delete: (agentId: string, opts?: RequestOpts) => Promise; }; readonly runtimes: { /** * 创建 Runtime(同步接口,返回时沙箱已 RUNNING) * 返回 Runtime 实例,可直接操作 sessions。 * * **自动注入 `CODEBUDDY_API_KEY`**:沙箱内 agent 调大模型网关需要这个 secret * (见服务端 `sandbox_builder.go`)。SDK 兜底逻辑: * * - 如果 `opts.agentManifest.secrets` 已显式声明 `CODEBUDDY_API_KEY` → 保留用户值 * - 否则若 `opts.agentManifest` 已传 **且** `ConnectionOpts.apiKey` 存在 * → 追加一条 `CODEBUDDY_API_KEY` secret(不 mutate 入参) * * 这样用户只需在 `new CloudAgentClient({ apiKey })` 里提供一次,不必在每次 * `runtimes.create` 里重复声明同一个 key。 * * 注意:SDK 不会在用户完全没传 `agentManifest` 时帮他编造 `id/name/manifestVersion` * 等业务字段——那些是用户自己的 agent 身份标识,必须显式指定。 */ create: (opts: RuntimeCreateOpts) => Promise; /** 获取 Runtime(返回实例) */ get: (runtimeId: string, opts?: RequestOpts) => Promise; /** 分页列表(轻量返回 RuntimeBrief,仅含 id/runtimeName/createdAt) */ list: (opts?: RuntimeListOpts) => Promise>; }; } //#endregion //#region src/v1/manifest.d.ts declare class ManifestBuilder { private _id?; private _name?; private _version?; private _systemPrompt?; private _systemPromptFile?; private _useWorkspaceRoot?; private _isolateConfigDir?; private _settings?; private _rules; private _skills; private _subagents; private _slashCommands; private _plugins; private _mcp; private _workspaces; private _secrets; private _envs; private _extra; id(id: string): this; name(name: string): this; version(version: string): this; systemPrompt(prompt: string): this; systemPromptFile(url: string): this; useWorkspaceRoot(value?: boolean): this; isolateConfigDir(value?: boolean): this; settings(url: string): this; rules(...rules: ManifestRule[]): this; skills(...skills: Array): this; subagents(...subagents: Array): this; slashCommands(...cmds: Array): this; plugins(...plugins: ManifestPlugin[]): this; mcp(...mcps: ManifestMcp[]): this; workspaces(...wss: ManifestWorkspace[]): this; secrets(...secrets: ManifestSecret[]): this; envs(...envs: ManifestEnv[]): this; /** 设置任意扩展字段 */ raw(key: string, value: unknown): this; /** 校验必填字段并构建 */ build(): AgentManifest; } //#endregion //#region src/v1/acp/client.d.ts type AcpConnectionState = 'INITIAL' | 'CONNECTING' | 'OPEN' | 'CLOSING' | 'CLOSED'; /** Notification 订阅器签名 —— 收到的是上游 `SessionNotification` 原样。 */ type NotificationListener = (notification: SessionNotification) => void; //#endregion //#region src/v1/errors.d.ts /** * 错误类型体系 * * 对齐 Anthropic / OpenAI SDK 的做法 —— 只暴露**服务端 requestId** * 这一个定位 ID。SDK 内部日志通过 logger name (`cloud-agent-sdk`) 和 * 业务上下文(sessionId / connectionId / runtimeId)做定位,用户侧想把 * SDK 日志和业务日志串起来的标准姿势是 `AsyncLocalStorage` 注入业务 id * (见 docs 里的指南)。 * * 重试决策**不**挂在错误类上。是否重试由 `RetryOpts.retryOn(err, ctx)` 统一决定 * (见 `rest/client.ts` 里的 `DEFAULT_RETRY_ON`)。这样决策只有一个入口, * 用户可以通过 `retry: { retryOn: ... }` 完全覆盖。 */ interface CloudAgentErrorOpts { code?: number; httpStatus?: number; /** * 服务端返回的 `x-request-id` 或 body.requestId。 * 贴给服务端团队排障用。网络错 / 超时时可能为 `undefined` * (请求还没到服务端),此时排查靠客户端日志(logger `cloud-agent-sdk`)。 */ requestId?: string; cause?: Error; } declare class CloudAgentError extends Error { readonly code: number; readonly httpStatus?: number; readonly requestId?: string; readonly originalCause?: Error; constructor(message: string, opts?: CloudAgentErrorOpts); } declare class NetworkError extends CloudAgentError { constructor(message: string, opts?: CloudAgentErrorOpts); } declare class TimeoutError extends CloudAgentError { constructor(message: string, opts?: CloudAgentErrorOpts); } declare class AuthError extends CloudAgentError { constructor(message: string, opts?: CloudAgentErrorOpts); } declare class NotFoundError extends CloudAgentError { constructor(message: string, opts?: CloudAgentErrorOpts); } declare class ValidationError extends CloudAgentError { constructor(message: string, opts?: CloudAgentErrorOpts); } declare class AcpProtocolError extends CloudAgentError { constructor(message: string, opts?: CloudAgentErrorOpts); } //#endregion export { type AcpConnectionState, type AcpLink, AcpProtocolError, Agent, type AgentACPLink, type AgentInfo, type AgentListItem, type AgentListResponse, type AgentManifest, type AgentSessionResponse, type AgentVersionInfo, type AgentVersionListItem, type AudioContent, AuthError, type CancelNotification, CloudAgentClient, CloudAgentError, type ConnectionOpts, type ContentBlock, type CreateAgentRequest, type CreateAgentSessionRequest, type CreateRuntimeRequest, type CreateSessionRequest, DEFAULT_RETRY_ON, type DeleteResult, type EmbeddedResource, type ImageContent, type LogLevel, type Logger, ManifestBuilder, type ManifestEnv, type ManifestMcp, type ManifestPlugin, type ManifestRule, type ManifestSecret, type ManifestSkill, type ManifestSlashCommand, type ManifestSubagent, type ManifestWorkspace, NetworkError, NotFoundError, type NotificationListener, type PageResult, type Pagination, type PromptOpts, type PromptResponse, type PublishVersionRequest, type RequestOpts, type ResourceLink, type RetryContext, type RetryOn, type RetryOpts, Runtime, type RuntimeBrief, type RuntimeConnectOpts, type RuntimeCreateOpts, type RuntimeInfo, type RuntimeLinks, type RuntimeStatus, type SandboxLink, type SandboxSpec, type SaveDraftRequest, Session, type SessionBrief, type SessionCreateOpts, type SessionInfo, type SessionNotification, type SessionStatus, type TextContent, TimeoutError, type UpdateRuntimeRequest, type UpdateSessionRequest, ValidationError, type VersionListResponse }; //# sourceMappingURL=index.d.mts.map