@yitom/acp-client 0.1.11 → 0.1.13

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 CHANGED
@@ -41,12 +41,32 @@
41
41
  | `codex-acp` | ChatGPT | `~/.codex/auth.json` / 自定义供应商 API Key | 支持隔离 `CODEX_HOME` 生成 `config.toml` |
42
42
  | `claude` | Claude | `~/.claude.json` / `ANTHROPIC_API_KEY` | 自动复用本机 Claude Code CLI 登录态 |
43
43
  | `cursor-cli` | Cursor | `CURSOR_API_KEY` / 系统 Keychain 登录态 | 自动探测 `%LOCALAPPDATA%\cursor-agent\agent.cmd` |
44
- | `deepseek` | DeepSeek | `DEEPSEEK_API_KEY` | 缺 key 提前拦截判停,避免子进程秒退 |
44
+ | `deepseek` | DeepSeek | `DEEPSEEK_API_KEY` 或 `~/.dsh/.credentials.yaml` | 缺凭证提前判停;`DSH_BIN` 指向稳定安装,`DSH_PACKAGE` pin 版本 |
45
45
  | `gemini` | Gemini | `~/.gemini/oauth_creds.json` / `GEMINI_API_KEY` | 自动探测 OAuth 凭证与系统 Key |
46
46
  | `copilot` | Copilot | `~/.copilot/config.json` / `GH_TOKEN` | 自动提取 `loggedInUsers` 凭证列表 |
47
47
  | `opencode` | OpenCode | `$XDG_DATA_HOME/opencode/auth.json` | 遵循 XDG / `%LOCALAPPDATA%` 规范 |
48
48
  | `agy` | agy | 官方桥接器免密直连 | `tryDirectSessionFirst` 免鉴权直通 |
49
49
 
50
+ ### DeepSeek(dsh)在新机器上接入
51
+
52
+ 不需要改任何本机 profile,三步即可复现:
53
+
54
+ ```bash
55
+ node scripts/setup-dsh-acp.mjs # 装/复用用户级运行时并自检 ACP 握手
56
+ export DEEPSEEK_API_KEY=sk-... # 或在 dsh/桌面版里登录(二选一)
57
+ ```
58
+
59
+ 如果用户本机根本没装/没登录 harness,宿主可以直接用内置的「URL + Token」表单,免环境变量:
60
+
61
+ ```typescript
62
+ import { saveDeepseekProvider, getDeepseekProviderStatus } from '@yitom/acp-client'
63
+
64
+ getDeepseekProviderStatus() // { configured, baseUrl?, isOfficial, hasApiKey }
65
+ saveDeepseekProvider({ baseUrl: 'https://api.deepseek.com', apiKey: 'sk-...' }) // URL 留空即官方端点
66
+ ```
67
+
68
+ SDK 会按 `DSH_BIN` → 用户级稳定安装(自动取已装最高版本)→ `DSH_PACKAGE` → `bunx` 的顺序解析启动目标,并在 spawn 时附加 `--patch` 覆盖层把会话模型修正为 `deepseek-flash`(= DeepSeek-V4.1-Flash;桌面端的 `1017` 只是 UI 徽标)。详见 [API 参考 §DeepSeek](./docs/api-reference.md)。
69
+
50
70
  ---
51
71
 
52
72
  ## 🚀 快速上手 (1 分钟代码)
@@ -151,3 +171,27 @@ bun run packages/acp/examples/standalone-acp-demo.ts
151
171
  With `@yitom/agy-acp-map` 0.1.24 / 0.1.25 / 0.1.26, `resources.directory` is delivered through the bridge session extension `_meta.appResources.directory`. Rules, native Skills and session MCP live in a private temporary additional workspace; cwd, global configuration and authentication remain unchanged. Close/delete/orderly shutdown remove the temporary workspace. Unknown bridge versions keep compatibility guidance and the app-skills MCP fallback. This extension is bridge-specific, not a standard ACP configuration-home API. `configurationScope: "session"` also supports agy; its configuration report remains conservative until the bridge accepts the session extension.
152
172
 
153
173
  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.
174
+
175
+ ### OpenCode ACP question compatibility
176
+
177
+ When a host supplies application resources, OpenCode 1.18.35 and 2.0.6 receive a child-process-only
178
+ OPENCODE_CONFIG_CONTENT overlay setting permission.question to deny. Its upstream ACP event
179
+ dispatcher omits native questions in 1.18.35 and cancels form.created in 2.0.6.
180
+ The v2 adapter prepares only the question overlay; native rules and skills remain unverified. The SDK preserves existing providers,
181
+ models, MCP servers, instructions and all unrelated permission rules, including shorthand
182
+ permission defaults. It never edits project/global OpenCode config files or authentication homes.
183
+ Overlay and isolated session configuration use the same policy.
184
+
185
+ Inspect resourceReport.openCodeQuestions: fallback + prepared means the overlay was prepared,
186
+ not proof that the runtime applied it. Unknown releases report unverified + unchanged; no semver
187
+ range or permission capability is treated as proof of question support. Hosts should provide
188
+ an available MCP question tool or a textual question, wait for the user, and keep security
189
+ approval separate. Standard ACP request_permission remains independent; elicitation support
190
+ is negotiated separately and is not implied by permissions or this fallback.
191
+
192
+ GitHub Actions builds and smoke-checks Linux, Windows and macOS packages and uploads a dist
193
+ artifact per OS. Only version-tag pushes publish to npm; branch/PR builds do not publish.
194
+
195
+ ### 宿主接入的通用生命周期
196
+
197
+ `src/client/sdk-client.ts` 统一官方 SDK 流桥接、请求超时与方法类型推导;`connectSdkClient` 可传第四参 `{ name }`。`src/client/session-open.ts` 统一恢复/新建、原生扩展回退与有界工具输出恢复。`preserveMcpOnRetry: true` 保留重试时的 MCP 工具;缺省保持旧客户端的裸调回退策略。窗口、IPC、诊断日志由宿主提供,不进入协议包。
@@ -1,6 +1,6 @@
1
1
  import { type AcpAvailableCommand } from '../session/available-commands';
2
2
  import type { AcpAgentQuota } from '../contracts';
3
- import { type InitializeResponse } from '@agentclientprotocol/sdk';
3
+ import { type InitializeResponse, type McpServer } from '@agentclientprotocol/sdk';
4
4
  import type { AcpConnectionStatus, AcpPermissionOutcome, AcpProxySettings, AcpRuntimeInfo, AcpSessionRestoreMethod, AppError, InkdownVirtualResource } from "../contracts";
5
5
  import { type Result } from "../contracts";
6
6
  import type { AppResourceReport } from '../resources/app-resources';
@@ -161,7 +161,7 @@ export declare class AcpClient {
161
161
  /** 创建或恢复会话 */
162
162
  createSession(options?: {
163
163
  resumeSessionId?: string | null;
164
- mcpServers?: unknown[];
164
+ mcpServers?: McpServer[];
165
165
  }): Promise<Result<AcpSessionHandle, AppError>>;
166
166
  /** 向指定会话发送消息 */
167
167
  promptSession(sessionId: string, promptText: string, options?: {
@@ -1,5 +1,5 @@
1
1
  import { type AcpPermissionOutcome, type InkdownVirtualResource } from "../contracts";
2
- import { type ClientApp } from '@agentclientprotocol/sdk';
2
+ import { type ClientApp, type RequestPermissionRequest, type SessionNotification } 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: Record<string, unknown>;
15
+ params: RequestPermissionRequest;
16
16
  }) => Promise<AcpPermissionOutcome>;
17
17
  /** session/update 通知透传(回放压制由调用方做) */
18
- onSessionUpdate: (params: Record<string, unknown>) => void;
18
+ onSessionUpdate: (params: SessionNotification) => void;
19
19
  }
20
20
  /**
21
21
  * Agent → Client 回调:permission + fs + terminal(声明能力后才会收到)。
@@ -1,5 +1,5 @@
1
1
  import type { ChildProcessWithoutNullStreams } from 'node:child_process';
2
- import { type ClientApp, type ClientConnection, type ClientContext, type Stream } from '@agentclientprotocol/sdk';
2
+ import { type ClientApp, type ClientConnection, type ClientContext, type AgentRequestMethod, type AgentRequestParamsByMethod, type AgentRequestResponsesByMethod, 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,12 +23,16 @@ 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): {
26
+ runtimeId?: string, options?: {
27
+ name?: string;
28
+ }): {
27
29
  app: ClientApp;
28
30
  connection: ClientConnection;
29
31
  streamHandle: SdkStreamHandle;
30
32
  };
31
33
  /** 带显式超时的 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. */
32
36
  export declare function sdkRequest<Response, Params>(agent: ClientContext, method: string, params: Params, timeoutMs?: number): Promise<Response>;
33
37
  /** Close owned sessions before transport/process teardown; unsupported failures stay bounded. */
34
38
  export declare function closeAcpSessions(agent: ClientContext, sessionIds: Iterable<string>, timeoutMs?: number): Promise<string[]>;
@@ -1,5 +1,7 @@
1
- import type { AcpSessionRestoreAttempt, AcpSessionRestoreMethod } from "../contracts";
1
+ import { type McpServer } from '@agentclientprotocol/sdk';
2
+ import type { AcpSessionRestoreAttempt, AcpSessionRestoreMethod } from '../contracts';
2
3
  export type AcpRpcRequest = (method: string, params?: unknown) => Promise<unknown>;
4
+ export declare function isAuthenticationRequired(message: string): boolean;
3
5
  export interface RestoreOrCreateSessionInput {
4
6
  /** SDK 调用源:(method, params) => agent.request(method, params)(超时由 sdk-client 显式透传) */
5
7
  request: AcpRpcRequest;
@@ -7,9 +9,10 @@ export interface RestoreOrCreateSessionInput {
7
9
  resumeSessionId: string | null;
8
10
  resumeSupported: boolean;
9
11
  loadSupported: boolean;
10
- /** 客户端自带的 MCP server(Inkdown 工具);Agent 不支持 HTTP 传输时传空数组 */
11
- mcpServers?: unknown[];
12
- /** Runtime-specific native options; not a standard ACP system prompt field. */
12
+ /** 客户端自带的窗口 MCP stdio 配置 */
13
+ mcpServers?: McpServer[];
14
+ /** Keep the same tools on retry; hosts requiring reader tools should enable this. */
15
+ preserveMcpOnRetry?: boolean;
13
16
  sessionMeta?: Record<string, unknown>;
14
17
  /** session/load 回放期间回调(主进程用来压制 UI 更新) */
15
18
  onSuppressUpdates?: (suppress: boolean) => void;
@@ -18,8 +21,11 @@ export interface RestoreOrCreateSessionInput {
18
21
  log?: (level: 'info' | 'warn', message: string, data?: Record<string, unknown>) => void;
19
22
  }
20
23
  export interface RestoreOrCreateSessionResult {
21
- /** Agent accepted the supplied MCP descriptors; not proof of tool execution. */
22
24
  mcpServersAccepted: boolean;
25
+ recoveredToolOutputs?: Array<{
26
+ toolCallId: string;
27
+ text: string;
28
+ }>;
23
29
  nativeSessionAccepted: boolean;
24
30
  sessionId: string;
25
31
  configOptions: unknown;
@@ -42,3 +48,8 @@ export declare function isTransientAcpTransportError(error: unknown): boolean;
42
48
  * resume/load 对瞬时传输错误最多再试 1 次;失败明细写入 restoreAttempts。
43
49
  */
44
50
  export declare function restoreOrCreateAcpSession(input: RestoreOrCreateSessionInput): Promise<RestoreOrCreateSessionResult>;
51
+ /** Preserve MCP when a bridge rejects only its optional native resource extension. */
52
+ export declare function requestSessionWithResources(request: AcpRpcRequest, method: string, params: Record<string, unknown>, sessionMeta?: Record<string, unknown>): Promise<{
53
+ result: Record<string, unknown>;
54
+ nativeSessionAccepted: boolean;
55
+ }>;
@@ -119,6 +119,11 @@ export interface AcpConfigOptionValue {
119
119
  value: string;
120
120
  name: string;
121
121
  description?: string;
122
+ /**
123
+ * 分组名(ACP 允许 select 选项嵌套 `{group, name, options}`)。
124
+ * 解析时拍平为一维列表并保留分组标签,value 保持 agent 原始编码不变。
125
+ */
126
+ group?: string;
122
127
  }
123
128
  export interface AcpConfigOption {
124
129
  configId: string;
@@ -267,6 +272,28 @@ export interface AcpProxySettings {
267
272
  host: string;
268
273
  port: number;
269
274
  }
275
+ /**
276
+ * DeepSeek(dsh)自定义端点/凭证:宿主表单「URL + Token」的落库形状。
277
+ * 落库后由 SDK 在 spawn 时转成 `DEEPSEEK_BASE_URL` / `DEEPSEEK_API_KEY`,
278
+ * 不写 harness 自己的 `$DSH_HOME/.credentials.yaml`(留在官方位置)。
279
+ */
280
+ export interface AcpDeepseekProviderStatus {
281
+ configured: boolean;
282
+ /** 已落库的端点;未配置时不返回 */
283
+ baseUrl?: string;
284
+ /**
285
+ * 是否使用官方默认端点(未配置或配置值等于官方地址)。
286
+ * 宿主据此渲染「官方 / 自定义」二选一。
287
+ */
288
+ isOfficial: boolean;
289
+ hasApiKey: boolean;
290
+ }
291
+ export interface AcpDeepseekProviderSavePayload {
292
+ /** 空串/未填时回落官方端点 */
293
+ baseUrl?: string;
294
+ /** 空串时保留已存的 Key(只改端点不重填 Token 的常见操作) */
295
+ apiKey?: string;
296
+ }
270
297
  export declare const CODEX_ACP_NPM_PACKAGE: '@agentclientprotocol/codex-acp';
271
298
  export declare const CLAUDE_ACP_NPM_PACKAGE: '@agentclientprotocol/claude-agent-acp';
272
299
  export declare const DEEPSEEK_DSH_NPM_PACKAGE: '@deepseek-ai/dsh';