@yitom/acp-client 0.1.12 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -20
- package/dist/client/acp-client.d.ts +17 -2
- package/dist/client/client-handlers.d.ts +3 -3
- package/dist/client/mcp-session-recovery.d.ts +47 -0
- package/dist/client/sdk-client.d.ts +2 -6
- package/dist/client/session-open.d.ts +14 -7
- package/dist/index.cjs +1476 -775
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3706 -3006
- package/dist/mcp/connection-health.d.ts +21 -0
- package/dist/resources/app-resources.d.ts +0 -7
- package/dist/resources/runtime-bindings.d.ts +1 -6
- package/dist/runtimes/codex/codex-auth-preflight.d.ts +1 -1
- package/dist/runtimes/codex/codex-code-mode-home.d.ts +54 -0
- package/dist/runtimes/codex/index.d.ts +1 -0
- package/dist/runtimes/deepseek/index.d.ts +10 -6
- package/dist/runtimes/deepseek/quota.d.ts +42 -0
- package/dist/session/code-mode.d.ts +30 -0
- package/dist/sidecar.cjs +3929 -3148
- package/dist/version.d.ts +1 -1
- package/docs/adding-an-agent.md +14 -0
- package/docs/api-reference.md +61 -0
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -26,11 +26,13 @@
|
|
|
26
26
|
- **生命周期全托管**:
|
|
27
27
|
负责跨平台后台进程拉起(Windows PID 级联杀进程)、Stdio ndJson 传输桥接、协议初始化(Initialize 握手)、温进程池长驻复用、错误诊断(stderr 尾部日志聚合)。
|
|
28
28
|
- **会话状态机与容错**:
|
|
29
|
-
自动处理 `resume` → `load` → `new` 会话恢复流程,处理模型方言(models
|
|
29
|
+
自动处理 `resume` → `load` → `new` 会话恢复流程,处理模型方言(models 数组/对象)、默认保留 MCP 配置重试;提供健康监测后,在下一轮 prompt 前恢复失效的工具挂载。
|
|
30
30
|
- **解耦的事件钩子与审批**:
|
|
31
31
|
工具调用审批、权限请求、会话流式更新采用标准的回调与事件驱动,宿主自由决定如何确认(命令行交互 / 桌面弹窗 / Web 消息)。
|
|
32
32
|
- **应用资源目录(单目录接口)**:
|
|
33
33
|
宿主只传 `resources: { directory }`(`AGENTS.md` + `skills/<name>/SKILL.md`),SDK 负责读取、摘要、配置合并、资格/版本门、会话级记录与温复用标签;详见 `docs/api-reference.md §5` 与 `examples/app-resources-demo.ts`。
|
|
34
|
+
- **会话级 Code Mode(PTC)**:
|
|
35
|
+
Agent 在 `initialize` 声明 `agentCapabilities._meta.toolsMode.values` 后,`createSession({ codeMode: 'on' })` 会通过 `_meta.toolsMode = 'ptc'` 请求该表现层;模型改为写代码、以 `tools.<name>()` 调用全部可见工具(含本次会话挂载的 MCP 工具)。未声明的 Agent 不会被请求,也不会出现“开关无效”的假支持。详见 `docs/api-reference.md §1`。
|
|
34
36
|
|
|
35
37
|
---
|
|
36
38
|
|
|
@@ -152,22 +154,19 @@ With `@yitom/agy-acp-map` 0.1.24 / 0.1.25 / 0.1.26, `resources.directory` is del
|
|
|
152
154
|
|
|
153
155
|
Normal disconnect closes owned sessions on agents advertising `sessionCapabilities.close` before terminating the transport/process. Requests are bounded to two seconds; failures are logged and teardown continues. This permits session resource cleanup on Windows as well.
|
|
154
156
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
GitHub Actions builds and smoke-checks Linux, Windows and macOS packages and uploads a dist
|
|
173
|
-
artifact per OS. Only version-tag pushes publish to npm; branch/PR builds do not publish.
|
|
157
|
+
## MCP 长会话恢复
|
|
158
|
+
|
|
159
|
+
SDK 导出 `McpConnectionHealth`(传输/发现观测)与 `AcpMcpSessionRecovery`(通用恢复管理器),不依赖 Electron、窗口、管道或应用名称。
|
|
160
|
+
宿主把 MCP 工具发现和连接关闭通知给监测器,并通过 `createSession({ mcpServers, mcpHealth })` 绑定;随后 `AcpClient.promptSession()` / 会话 `prompt()` 会在已知断连后先恢复原会话、重新下发相同 MCP 配置并等待新的工具发现,再发送本轮消息。
|
|
161
|
+
失败阻止发送;不创建替代会话,不重发 prompt。取消、断连、恢复互斥、RPC 与发现超时统一由 SDK 处理。详见 [API 参考:MCP 恢复](./docs/api-reference.md#mcp-长会话恢复)。
|
|
162
|
+
没有监测信号时不凭空推断 MCP 可用性,也不以恢复 RPC 成功冒充工具可用;工具发现仍不等同于模型目录/工具执行验证。
|
|
163
|
+
此能力属于客户端兜底,不能修复 Agent 自身工作区服务回收后的内部状态。
|
|
164
|
+
|
|
165
|
+
## 测试入口
|
|
166
|
+
|
|
167
|
+
本项目统一使用 Vitest。Bun 用于安装依赖及启动 package.json 脚本;直接执行 bun test 会启动 Bun 内置测试器,不是项目测试入口。
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
bun run test # 全量 Vitest
|
|
171
|
+
bun run test:mcp # 仅 MCP 恢复与客户端接入测试
|
|
172
|
+
```
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import type { AcpMcpHealthMonitor } from '../mcp/connection-health';
|
|
1
2
|
import { type AcpAvailableCommand } from '../session/available-commands';
|
|
3
|
+
import { type AcpCodeMode } from '../session/code-mode';
|
|
2
4
|
import type { AcpAgentQuota } from '../contracts';
|
|
3
|
-
import { type InitializeResponse
|
|
5
|
+
import { type InitializeResponse } from '@agentclientprotocol/sdk';
|
|
4
6
|
import type { AcpConnectionStatus, AcpPermissionOutcome, AcpProxySettings, AcpRuntimeInfo, AcpSessionRestoreMethod, AppError, InkdownVirtualResource } from "../contracts";
|
|
5
7
|
import { type Result } from "../contracts";
|
|
6
8
|
import type { AppResourceReport } from '../resources/app-resources';
|
|
@@ -83,6 +85,8 @@ export declare class AcpSessionHandle {
|
|
|
83
85
|
/** 主动获取/刷新配额(优先缓存,过期或无缓存时触发适配器探针) */
|
|
84
86
|
getQuota(): Promise<AcpAgentQuota | null>;
|
|
85
87
|
get availableCommands(): AcpAvailableCommand[] | undefined;
|
|
88
|
+
/** Cancel an in-flight prompt or MCP recovery. */
|
|
89
|
+
cancel(): Promise<Result<void, AppError>>;
|
|
86
90
|
/** 修改会话配置项(如模型 ID、模式等) */
|
|
87
91
|
setConfigOption(configId: string, value: string | boolean): Promise<Result<unknown, AppError>>;
|
|
88
92
|
}
|
|
@@ -94,6 +98,8 @@ export declare class AcpSessionHandle {
|
|
|
94
98
|
* - 可在任意 Node.js 项目、CLI 命令行工具或 Web 服务中直接复用。
|
|
95
99
|
*/
|
|
96
100
|
export declare class AcpClient {
|
|
101
|
+
private readonly mcpRecovery;
|
|
102
|
+
private suppressRecoveryUpdates;
|
|
97
103
|
private status;
|
|
98
104
|
private readonly commandsCache;
|
|
99
105
|
private readonly quotaCache;
|
|
@@ -161,7 +167,14 @@ export declare class AcpClient {
|
|
|
161
167
|
/** 创建或恢复会话 */
|
|
162
168
|
createSession(options?: {
|
|
163
169
|
resumeSessionId?: string | null;
|
|
164
|
-
mcpServers?:
|
|
170
|
+
mcpServers?: unknown[];
|
|
171
|
+
/** Host MCP discovery/close observations enable automatic recovery before prompts. */
|
|
172
|
+
mcpHealth?: AcpMcpHealthMonitor;
|
|
173
|
+
/**
|
|
174
|
+
* 会话级 code mode(PTC):模型改为写代码、以 `tools.<name>()` 调用全部可见工具,
|
|
175
|
+
* 包括本次会话挂载的 MCP 工具。仅对声明支持的运行时生效(见 supportsCodeMode)。
|
|
176
|
+
*/
|
|
177
|
+
codeMode?: AcpCodeMode;
|
|
165
178
|
}): Promise<Result<AcpSessionHandle, AppError>>;
|
|
166
179
|
/** 向指定会话发送消息 */
|
|
167
180
|
promptSession(sessionId: string, promptText: string, options?: {
|
|
@@ -179,6 +192,8 @@ export declare class AcpClient {
|
|
|
179
192
|
* 恢复会话因送达状态未知,按新代次重新附带一次(有界、可诊断,不声称 exactly-once)。
|
|
180
193
|
*/
|
|
181
194
|
private buildCompatPrepend;
|
|
195
|
+
/** Cancel recovery before notifying the agent; prompts are never automatically replayed. */
|
|
196
|
+
cancelSession(sessionId: string): Promise<Result<void, AppError>>;
|
|
182
197
|
/** 动态更新会话配置项(如模型 ID) */
|
|
183
198
|
setSessionConfigOption(sessionId: string, configId: string, value: string | boolean): Promise<Result<unknown, AppError>>;
|
|
184
199
|
/** 断开连接并清理资源 */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AcpPermissionOutcome, type InkdownVirtualResource } from "../contracts";
|
|
2
|
-
import { type ClientApp
|
|
2
|
+
import { type ClientApp } from '@agentclientprotocol/sdk';
|
|
3
3
|
import type { AcpTerminalManager } from './acp-terminal';
|
|
4
4
|
export interface AcpClientHandlerDeps {
|
|
5
5
|
getWorkspaceRoot: () => string | null;
|
|
@@ -12,10 +12,10 @@ export interface AcpClientHandlerDeps {
|
|
|
12
12
|
*/
|
|
13
13
|
onPermission: (payload: {
|
|
14
14
|
sessionId?: string;
|
|
15
|
-
params:
|
|
15
|
+
params: Record<string, unknown>;
|
|
16
16
|
}) => Promise<AcpPermissionOutcome>;
|
|
17
17
|
/** session/update 通知透传(回放压制由调用方做) */
|
|
18
|
-
onSessionUpdate: (params:
|
|
18
|
+
onSessionUpdate: (params: Record<string, unknown>) => void;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Agent → Client 回调:permission + fs + terminal(声明能力后才会收到)。
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AcpMcpHealthMonitor } from '../mcp/connection-health';
|
|
2
|
+
export declare class AcpMcpRecoveryCancelledError extends Error {
|
|
3
|
+
}
|
|
4
|
+
export interface AcpMcpRecoveryEvent {
|
|
5
|
+
type: 'started' | 'failed' | 'discovered' | 'cancelled';
|
|
6
|
+
sessionId: string;
|
|
7
|
+
method?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface AcpMcpRecoveryOptions {
|
|
10
|
+
request: AcpMcpRecoveryRequest;
|
|
11
|
+
getCapabilities: () => {
|
|
12
|
+
resume: boolean;
|
|
13
|
+
load: boolean;
|
|
14
|
+
};
|
|
15
|
+
isConnected: () => boolean;
|
|
16
|
+
isBusy?: (sessionId: string) => boolean;
|
|
17
|
+
onSuppressUpdates?: (suppress: boolean) => void;
|
|
18
|
+
onEvent?: (event: AcpMcpRecoveryEvent) => void;
|
|
19
|
+
discoveryTimeoutMs?: number;
|
|
20
|
+
requestTimeoutMs?: number;
|
|
21
|
+
}
|
|
22
|
+
export type AcpMcpRecoveryRequest = (method: string, params: unknown, signal?: AbortSignal) => Promise<unknown>;
|
|
23
|
+
export interface AcpMcpSessionBinding {
|
|
24
|
+
sessionId: string;
|
|
25
|
+
cwd: string;
|
|
26
|
+
mcpServers: unknown[];
|
|
27
|
+
sessionMeta?: Record<string, unknown>;
|
|
28
|
+
monitor: AcpMcpHealthMonitor;
|
|
29
|
+
}
|
|
30
|
+
/** One manager per ACP connection owner. Does not own MCP transports or send prompts. */
|
|
31
|
+
export declare class AcpMcpSessionRecovery {
|
|
32
|
+
private readonly options;
|
|
33
|
+
private readonly sessions;
|
|
34
|
+
private generation;
|
|
35
|
+
private suppressing;
|
|
36
|
+
private active?;
|
|
37
|
+
constructor(options: AcpMcpRecoveryOptions);
|
|
38
|
+
get isRecovering(): boolean;
|
|
39
|
+
register(input: AcpMcpSessionBinding): void;
|
|
40
|
+
cancel(sessionId?: string): void;
|
|
41
|
+
reset(): void;
|
|
42
|
+
ensureReady(sessionId: string): Promise<void>;
|
|
43
|
+
private emit;
|
|
44
|
+
private recover;
|
|
45
|
+
private boundedRequest;
|
|
46
|
+
private bounded;
|
|
47
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ChildProcessWithoutNullStreams } from 'node:child_process';
|
|
2
|
-
import { type ClientApp, type ClientConnection, type ClientContext, type
|
|
2
|
+
import { type ClientApp, type ClientConnection, type ClientContext, type Stream } from '@agentclientprotocol/sdk';
|
|
3
3
|
/** SDK 请求超时:沿用旧手搓传输的 120s,显式透传 */
|
|
4
4
|
export declare const ACP_SDK_REQUEST_TIMEOUT_MS = 120000;
|
|
5
5
|
export interface SdkStreamHandle {
|
|
@@ -23,16 +23,12 @@ export declare function createSdkStreamHandle(child: ChildProcessWithoutNullStre
|
|
|
23
23
|
*/
|
|
24
24
|
export declare function connectSdkClient(child: ChildProcessWithoutNullStreams, configure: (app: ClientApp) => void,
|
|
25
25
|
/** 所属运行时 id:仅日志/隔离用,不改变 SDK 建连形态;缺省向后兼容单 codex 路径 */
|
|
26
|
-
runtimeId?: string
|
|
27
|
-
name?: string;
|
|
28
|
-
}): {
|
|
26
|
+
runtimeId?: string): {
|
|
29
27
|
app: ClientApp;
|
|
30
28
|
connection: ClientConnection;
|
|
31
29
|
streamHandle: SdkStreamHandle;
|
|
32
30
|
};
|
|
33
31
|
/** 带显式超时的 agent.request:超时 abort(触发 $/cancel_request)并拒绝 */
|
|
34
|
-
export declare function sdkRequest<Method extends AgentRequestMethod>(agent: ClientContext, method: Method, params: AgentRequestParamsByMethod[Method], timeoutMs?: number): Promise<AgentRequestResponsesByMethod[Method]>;
|
|
35
|
-
/** Explicit generic overload for vendor extensions and legacy callers. */
|
|
36
32
|
export declare function sdkRequest<Response, Params>(agent: ClientContext, method: string, params: Params, timeoutMs?: number): Promise<Response>;
|
|
37
33
|
/** Close owned sessions before transport/process teardown; unsupported failures stay bounded. */
|
|
38
34
|
export declare function closeAcpSessions(agent: ClientContext, sessionIds: Iterable<string>, timeoutMs?: number): Promise<string[]>;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { AcpSessionRestoreAttempt, AcpSessionRestoreMethod } from '../contracts';
|
|
1
|
+
import type { AcpSessionRestoreAttempt, AcpSessionRestoreMethod } from "../contracts";
|
|
3
2
|
export type AcpRpcRequest = (method: string, params?: unknown) => Promise<unknown>;
|
|
4
|
-
export declare function isAuthenticationRequired(message: string): boolean;
|
|
5
3
|
export interface RestoreOrCreateSessionInput {
|
|
6
4
|
/** SDK 调用源:(method, params) => agent.request(method, params)(超时由 sdk-client 显式透传) */
|
|
7
5
|
request: AcpRpcRequest;
|
|
@@ -9,11 +7,18 @@ export interface RestoreOrCreateSessionInput {
|
|
|
9
7
|
resumeSessionId: string | null;
|
|
10
8
|
resumeSupported: boolean;
|
|
11
9
|
loadSupported: boolean;
|
|
12
|
-
/**
|
|
13
|
-
mcpServers?:
|
|
14
|
-
/**
|
|
10
|
+
/** 客户端自带的 MCP server(Inkdown 工具);Agent 不支持 HTTP 传输时传空数组 */
|
|
11
|
+
mcpServers?: unknown[];
|
|
12
|
+
/** Default true: never silently remove tools after a failed session/new. */
|
|
15
13
|
preserveMcpOnRetry?: boolean;
|
|
14
|
+
/** Runtime-specific native options; not a standard ACP system prompt field. */
|
|
16
15
|
sessionMeta?: Record<string, unknown>;
|
|
16
|
+
/**
|
|
17
|
+
* Ask the runtime for its code-mode (PTC) presentation on this session.
|
|
18
|
+
* Callers must gate this on `supportsCodeMode(agentCapabilities, runtimeId)`;
|
|
19
|
+
* the helper only applies it to new|load|resume requests.
|
|
20
|
+
*/
|
|
21
|
+
codeMode?: boolean;
|
|
17
22
|
/** session/load 回放期间回调(主进程用来压制 UI 更新) */
|
|
18
23
|
onSuppressUpdates?: (suppress: boolean) => void;
|
|
19
24
|
/** 测试可设为 0 */
|
|
@@ -21,6 +26,7 @@ export interface RestoreOrCreateSessionInput {
|
|
|
21
26
|
log?: (level: 'info' | 'warn', message: string, data?: Record<string, unknown>) => void;
|
|
22
27
|
}
|
|
23
28
|
export interface RestoreOrCreateSessionResult {
|
|
29
|
+
/** Agent accepted the supplied MCP descriptors; not proof of tool execution. */
|
|
24
30
|
mcpServersAccepted: boolean;
|
|
25
31
|
recoveredToolOutputs?: Array<{
|
|
26
32
|
toolCallId: string;
|
|
@@ -34,6 +40,7 @@ export interface RestoreOrCreateSessionResult {
|
|
|
34
40
|
requestedSessionId?: string;
|
|
35
41
|
restoreAttempts: AcpSessionRestoreAttempt[];
|
|
36
42
|
}
|
|
43
|
+
export declare function isAuthenticationRequired(message: string): boolean;
|
|
37
44
|
/**
|
|
38
45
|
* SDK 瞬时错误判定:连接层故障(关闭/中断/超时/管道)可重试 1 次;
|
|
39
46
|
* 协议层拒绝(cancelled / method-not-found / invalid-params / 业务 not-found)
|
|
@@ -48,7 +55,7 @@ export declare function isTransientAcpTransportError(error: unknown): boolean;
|
|
|
48
55
|
* resume/load 对瞬时传输错误最多再试 1 次;失败明细写入 restoreAttempts。
|
|
49
56
|
*/
|
|
50
57
|
export declare function restoreOrCreateAcpSession(input: RestoreOrCreateSessionInput): Promise<RestoreOrCreateSessionResult>;
|
|
51
|
-
/**
|
|
58
|
+
/** Retry rejected native extensions without changing the MCP descriptors. */
|
|
52
59
|
export declare function requestSessionWithResources(request: AcpRpcRequest, method: string, params: Record<string, unknown>, sessionMeta?: Record<string, unknown>): Promise<{
|
|
53
60
|
result: Record<string, unknown>;
|
|
54
61
|
nativeSessionAccepted: boolean;
|