@yitom/acp-client 0.1.15 → 0.1.16

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.
@@ -29,6 +29,19 @@ export interface AcpClientCallbacks {
29
29
  /** 日志打印 */
30
30
  onLog?: (level: 'info' | 'warn' | 'error', message: string, meta?: unknown) => void;
31
31
  }
32
+ export interface AcpPromptOptions {
33
+ /** 显式硬性总时长上限(毫秒;向后兼容旧参数,若未同时传 idleTimeoutMs 则禁用静默重置) */
34
+ timeoutMs?: number;
35
+ /** 活动重置的静默超时(毫秒;默认取 client promptIdleTimeoutMs 即 300_000;0 表示不限制) */
36
+ idleTimeoutMs?: number;
37
+ /** 可选硬性最大总时长上限(毫秒;默认取 client promptMaxDurationMs 即 0 不限制) */
38
+ maxDurationMs?: number;
39
+ /** 随 Prompt 一并发送的图片列表 */
40
+ images?: Array<{
41
+ mimeType: string;
42
+ data: string;
43
+ }>;
44
+ }
32
45
  export interface AcpClientOptions {
33
46
  /** 运行时标识,如 'codex-acp', 'claude', 'cursor-cli', 'deepseek', 'gemini' 等 */
34
47
  runtime?: string | AcpRuntimeInfo;
@@ -45,6 +58,18 @@ export interface AcpClientOptions {
45
58
  proxy?: Partial<AcpProxySettings>;
46
59
  /** 附加环境变量 */
47
60
  env?: NodeJS.ProcessEnv;
61
+ /** 控制面 RPC 默认超时(毫秒,默认 120_000) */
62
+ requestTimeoutMs?: number;
63
+ /** Prompt 流式静默超时(毫秒,收到事件/FS/终端/审批活动自动重置,默认 300_000;0 表示关闭) */
64
+ promptIdleTimeoutMs?: number;
65
+ /** Prompt 最大总时长上限(毫秒,默认 0 表示不限) */
66
+ promptMaxDurationMs?: number;
67
+ /** 配额缓存有效期(毫秒,默认 30_000) */
68
+ quotaCacheTtlMs?: number;
69
+ /** fs/read_text_file 单次最大读取字节上限(默认 2MB) */
70
+ maxReadBytes?: number;
71
+ /** 终端输出缓冲区上限(字节,默认 1MB) */
72
+ terminalOutputByteLimit?: number;
48
73
  /**
49
74
  * 应用资源目录(单目录接口):`{ directory: 绝对路径 }`,
50
75
  * 含 AGENTS.md 与 skills/ 下 SKILL.md。提供即走原生资源准备
@@ -73,13 +98,7 @@ export declare class AcpSessionHandle {
73
98
  /** 建会话时刻的应用资源加载报告快照(规则/技能分开记录) */
74
99
  resourceReport?: AppResourceReport | null | undefined);
75
100
  /** 向当前会话发送 Prompt / 消息交互 */
76
- prompt(promptText: string, options?: {
77
- timeoutMs?: number;
78
- images?: Array<{
79
- mimeType: string;
80
- data: string;
81
- }>;
82
- }): Promise<Result<unknown, AppError>>;
101
+ prompt(promptText: string, options?: AcpPromptOptions): Promise<Result<unknown, AppError>>;
83
102
  /** Agent 通过 available_commands_update 提供的斜杠命令(调用 = prompt 发送 `/name args` 文本) */
84
103
  /** 当前会话最近获取或解析到的配额(5h / 周额度 / 余额) */
85
104
  get quota(): AcpAgentQuota | undefined;
@@ -110,7 +129,13 @@ export declare class AcpClient {
110
129
  private readonly workspaceRoot;
111
130
  private readonly clientInfo;
112
131
  private readonly dataDir;
132
+ private readonly proxyOverride?;
113
133
  private readonly extraEnv;
134
+ private readonly requestTimeoutMs;
135
+ private readonly promptIdleTimeoutMs;
136
+ private readonly promptMaxDurationMs;
137
+ private readonly quotaCacheTtlMs;
138
+ private readonly maxReadBytes;
114
139
  private readonly configurationScope;
115
140
  private sessionConfig;
116
141
  private readonly resourcesDir;
@@ -124,8 +149,8 @@ export declare class AcpClient {
124
149
  private sdkConnection;
125
150
  private streamHandle;
126
151
  private initResponse;
127
- /** 在途 prompt 会话集合(忙时不打断温进程的判定依据) */
128
- private readonly inflightPrompts;
152
+ /** 在途 prompt 会话活动追踪器(忙时不打断温进程 + 支持事件重置静默超时) */
153
+ private readonly inflightTrackers;
129
154
  /** 本次连接周期的应用资源准备结果(无 resources 入口时为 null) */
130
155
  private resourcePrep;
131
156
  /** 连接代次(connect 推进;兼容记账与重连后重附带的诊断依据) */
@@ -183,13 +208,7 @@ export declare class AcpClient {
183
208
  codeMode?: AcpCodeMode;
184
209
  }): Promise<Result<AcpSessionHandle, AppError>>;
185
210
  /** 向指定会话发送消息 */
186
- promptSession(sessionId: string, promptText: string, options?: {
187
- timeoutMs?: number;
188
- images?: Array<{
189
- mimeType: string;
190
- data: string;
191
- }>;
192
- }): Promise<Result<unknown, AppError>>;
211
+ promptSession(sessionId: string, promptText: string, options?: AcpPromptOptions): Promise<Result<unknown, AppError>>;
193
212
  /**
194
213
  * 兼容引导前置文本(首轮一次制):
195
214
  * - 无 resources / 未知会话 / 原生已交付 → null(原文不动);
@@ -204,6 +223,8 @@ export declare class AcpClient {
204
223
  setSessionConfigOption(sessionId: string, configId: string, value: string | boolean): Promise<Result<unknown, AppError>>;
205
224
  /** 断开连接并清理资源 */
206
225
  disconnect(reason?: string): Promise<void>;
226
+ private touchSessionActivity;
227
+ private pauseSessionActivity;
207
228
  private cancelPermissionRequests;
208
229
  private setStatus;
209
230
  }
@@ -1,3 +1,4 @@
1
+ export declare const ACP_FS_MAX_READ_BYTES: number;
1
2
  export declare function isBinaryDocumentPath(filePath: string): boolean;
2
3
  export declare function assertPathInsideWorkspace(filePath: string, workspaceRoot: string): string;
3
4
  export declare function acpReadTextFile(params: {
@@ -5,6 +6,7 @@ export declare function acpReadTextFile(params: {
5
6
  workspaceRoot: string;
6
7
  line?: number;
7
8
  limit?: number;
9
+ maxReadBytes?: number;
8
10
  }): Promise<{
9
11
  content: string;
10
12
  }>;
@@ -1,3 +1,8 @@
1
+ export declare const ACP_TERMINAL_DEFAULT_OUTPUT_BYTE_LIMIT = 1048576;
2
+ export interface AcpTerminalManagerOptions {
3
+ defaultOutputByteLimit?: number;
4
+ onActivity?: (sessionId: string) => void;
5
+ }
1
6
  export interface AcpTerminalExitStatus {
2
7
  exitCode: number | null;
3
8
  signal: string | null;
@@ -22,6 +27,9 @@ export interface CreateAcpTerminalParams {
22
27
  /** ACP Client 侧无头终端:spawn 命令,供 Agent 轮询 output / wait / kill / release */
23
28
  export declare class AcpTerminalManager {
24
29
  private terminals;
30
+ private readonly defaultOutputByteLimit;
31
+ private readonly onActivity?;
32
+ constructor(options?: AcpTerminalManagerOptions);
25
33
  create(params: CreateAcpTerminalParams): {
26
34
  terminalId: string;
27
35
  };
@@ -17,6 +17,12 @@ export interface AcpClientHandlerDeps {
17
17
  }) => Promise<AcpPermissionOutcome>;
18
18
  /** session/update 通知透传(回放压制由调用方做) */
19
19
  onSessionUpdate: (params: Record<string, unknown>) => void;
20
+ /** 协议或工具活跃事件通知(用于重置 Prompt 静默超时) */
21
+ onActivity?: (sessionId?: string) => void;
22
+ /** 进入阻塞等待(如人工审批)时暂停静默超时,返回恢复函数 */
23
+ onPauseActivity?: (sessionId?: string) => () => void;
24
+ /** fs/read_text_file 单次最大读取字节上限 */
25
+ maxReadBytes?: number;
20
26
  }
21
27
  /**
22
28
  * Agent → Client 回调:permission + fs + terminal(声明能力后才会收到)。
@@ -1,7 +1,33 @@
1
1
  import type { ChildProcessWithoutNullStreams } from 'node:child_process';
2
2
  import { type ClientApp, type ClientConnection, type ClientContext, type Stream } from '@agentclientprotocol/sdk';
3
- /** SDK 请求超时:沿用旧手搓传输的 120s,显式透传 */
3
+ /** SDK 控制面请求默认超时:120s */
4
4
  export declare const ACP_SDK_REQUEST_TIMEOUT_MS = 120000;
5
+ /** 长流式 Prompt 默认静默超时:连续 5 分钟无任何事件/FS/终端/权限活动才超时 */
6
+ export declare const ACP_PROMPT_IDLE_TIMEOUT_MS = 300000;
7
+ /** 长流式 Prompt 默认最大总时长上限:0 表示不限(仅受静默超时约束) */
8
+ export declare const ACP_PROMPT_MAX_DURATION_MS = 0;
9
+ export type SdkRequestTimeoutKind = 'timeout' | 'idle' | 'max_duration';
10
+ export declare class SdkRequestTimeoutError extends Error {
11
+ readonly kind: SdkRequestTimeoutKind;
12
+ readonly method: string;
13
+ readonly durationMs: number;
14
+ constructor(kind: SdkRequestTimeoutKind, method: string, durationMs: number);
15
+ }
16
+ export interface SdkRequestActivityController {
17
+ /** 重置静默超时计时器(例如收到 session/update、fs、terminal 输出) */
18
+ touch(): void;
19
+ /** 暂停静默超时计时器(如等待用户权限审批),返回幂等恢复函数 */
20
+ pause(): () => void;
21
+ }
22
+ export declare function createSdkRequestActivityController(): SdkRequestActivityController;
23
+ export interface SdkRequestActivityOptions {
24
+ /** 活动重置的静默超时(毫秒);0 或未传且 maxDurationMs 存在时禁用 */
25
+ idleTimeoutMs?: number;
26
+ /** 硬性最大总时长上限(毫秒);0 或未传则不限制总时长 */
27
+ maxDurationMs?: number;
28
+ /** 关联的活动控制器 */
29
+ activity?: SdkRequestActivityController;
30
+ }
5
31
  export interface SdkStreamHandle {
6
32
  stream: Stream;
7
33
  /** 摘掉桥接(温进程复用时保住子进程 stdio,不关 fd) */
@@ -17,18 +43,30 @@ export interface SdkStreamHandle {
17
43
  */
18
44
  export declare function createSdkStreamHandle(child: ChildProcessWithoutNullStreams): SdkStreamHandle;
19
45
  /**
20
- * 长驻连接:client({ name: 'inkdown' }).connect(),持有 ClientConnection。
46
+ * 长驻连接:client(...).connect(),持有 ClientConnection。
21
47
  * 不用 connectWith 作用域式;调用方用返回的 connection.agent 发请求,
22
48
  * 断开时 connection.close() 取消在途请求。
23
49
  */
24
50
  export declare function connectSdkClient(child: ChildProcessWithoutNullStreams, configure: (app: ClientApp) => void,
25
51
  /** 所属运行时 id:仅日志/隔离用,不改变 SDK 建连形态;缺省向后兼容单 codex 路径 */
26
- runtimeId?: string): {
52
+ runtimeId?: string,
53
+ /** 客户端身份信息(默认 'acp-client') */
54
+ clientInfo?: {
55
+ name: string;
56
+ version?: string;
57
+ }): {
27
58
  app: ClientApp;
28
59
  connection: ClientConnection;
29
60
  streamHandle: SdkStreamHandle;
30
61
  };
31
- /** 带显式超时的 agent.request:超时 abort(触发 $/cancel_request)并拒绝 */
62
+ /**
63
+ * 支持活动静默重置 + 最大总时长上限的 agent.request:
64
+ * - idleTimeoutMs > 0:每次收到事件(touch)自动重置倒计时;等待人工审批等 pause() 期间暂停计时;
65
+ * - maxDurationMs > 0:可选硬性总时长天花板;
66
+ * - 任一触发即 abort(触发 $/cancel_request)并抛出 SdkRequestTimeoutError。
67
+ */
68
+ export declare function sdkRequestWithActivity<Response, Params>(agent: ClientContext, method: string, params: Params, options?: SdkRequestActivityOptions): Promise<Response>;
69
+ /** 带显式超时的 agent.request:超时 abort(触发 $/cancel_request)并拒绝;timeoutMs <= 0 时不设超时 */
32
70
  export declare function sdkRequest<Response, Params>(agent: ClientContext, method: string, params: Params, timeoutMs?: number): Promise<Response>;
33
71
  /** Close owned sessions before transport/process teardown; unsupported failures stay bounded. */
34
72
  export declare function closeAcpSessions(agent: ClientContext, sessionIds: Iterable<string>, timeoutMs?: number): Promise<string[]>;