@tencent-ai/cloud-agent-sdk 0.1.1 → 0.1.5
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/dist/index.cjs +16114 -0
- package/dist/index.d.cts +2466 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +2466 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +16063 -0
- package/dist/index.mjs.map +1 -0
- package/dist/tencent-ai-cloud-agent-sdk-0.1.5.tgz +0 -0
- package/package.json +13 -10
- package/dist/index.d.ts +0 -13
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -15
- package/dist/index.js.map +0 -1
- package/dist/tencent-ai-cloud-agent-sdk-0.1.1.tgz +0 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,2466 @@
|
|
|
1
|
+
import { AgentCapabilities as AgentCapabilities$1, ClientCapabilities, InitializeResponse, LoadSessionResponse, NewSessionResponse, PromptResponse as PromptResponse$1, RequestPermissionRequest, RequestPermissionRequest as RequestPermissionRequest$1, SessionNotification, SessionNotification as SessionNotification$1, SetSessionModeResponse, SetSessionModelResponse } from "@agentclientprotocol/sdk";
|
|
2
|
+
import { EntryInfo, EntryInfo as EntryInfo$1, Filesystem, FilesystemEvent, FilesystemEvent as FilesystemEvent$1, Sandbox, WatchHandle, WriteInfo } from "e2b";
|
|
3
|
+
|
|
4
|
+
//#region ../agent-provider/lib/common/_legacy/IPCAgentProvider.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Widget Channel 接口
|
|
7
|
+
* 定义 Widget 与 Agent Manager 的通信抽象
|
|
8
|
+
* 面向 ACP 协议设计,使用 sessionId 作为主要标识符
|
|
9
|
+
*/
|
|
10
|
+
interface IWidgetChannel {
|
|
11
|
+
/**
|
|
12
|
+
* 发送通知到指定 session(fire-and-forget)
|
|
13
|
+
* Channel 层负责路由到正确的 window
|
|
14
|
+
* 不需要等待响应时使用此方法
|
|
15
|
+
*
|
|
16
|
+
* @param sessionId ACP 会话 ID
|
|
17
|
+
* @param message 消息内容
|
|
18
|
+
* @returns 是否发送成功
|
|
19
|
+
*/
|
|
20
|
+
sendNotification(sessionId: string, message: any): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* 调用远程方法并等待响应
|
|
23
|
+
* 需要响应时使用此方法(推荐)
|
|
24
|
+
*
|
|
25
|
+
* @param sessionId ACP 会话 ID
|
|
26
|
+
* @param message 消息内容
|
|
27
|
+
* @param timeoutMs 超时时间(毫秒,默认 5000)
|
|
28
|
+
* @returns Promise 包含响应数据
|
|
29
|
+
*/
|
|
30
|
+
callMethod(sessionId: string, message: any, timeoutMs?: number): Promise<any>;
|
|
31
|
+
/**
|
|
32
|
+
* 绑定 session 到 window
|
|
33
|
+
* 用于创建新对话时建立 sessionId → windowId 映射
|
|
34
|
+
*
|
|
35
|
+
* @param sessionId ACP 会话 ID
|
|
36
|
+
* @param windowId 窗口 ID
|
|
37
|
+
*/
|
|
38
|
+
bindSession?(sessionId: string, windowId: number): void;
|
|
39
|
+
/**
|
|
40
|
+
* 解除 session 绑定
|
|
41
|
+
*
|
|
42
|
+
* @param sessionId ACP 会话 ID
|
|
43
|
+
*/
|
|
44
|
+
unbindSession?(sessionId: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* 获取所有窗口的所有会话
|
|
47
|
+
* Channel 层负责向所有窗口广播并聚合结果
|
|
48
|
+
*
|
|
49
|
+
* @returns Promise<ConversationData[]> 所有窗口的会话列表
|
|
50
|
+
*/
|
|
51
|
+
getAllSessions(): Promise<ConversationData[]>;
|
|
52
|
+
/** 注册事件监听器 */
|
|
53
|
+
on(event: string, handler: (data?: any) => void): void;
|
|
54
|
+
/** 注销事件监听器 */
|
|
55
|
+
off(event: string, handler: (data?: any) => void): void;
|
|
56
|
+
/** 触发事件(向外部发送事件) */
|
|
57
|
+
emit(event: string, data?: any): void;
|
|
58
|
+
/** 清除所有事件监听器 */
|
|
59
|
+
clear?(): void;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region ../agent-provider/lib/common/_legacy/types.d.ts
|
|
63
|
+
/**
|
|
64
|
+
* 会话信息(后端格式)
|
|
65
|
+
*/
|
|
66
|
+
interface ConversationData {
|
|
67
|
+
id: string;
|
|
68
|
+
title: string;
|
|
69
|
+
lastMessage: string;
|
|
70
|
+
timestamp: number;
|
|
71
|
+
branch?: string;
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region ../agent-client-protocol/lib/common/types.d.ts
|
|
75
|
+
/**
|
|
76
|
+
* Types of artifacts that can be created by the agent
|
|
77
|
+
*
|
|
78
|
+
* Note: 'task' and 'diff' were removed as they can be implemented using standard ACP:
|
|
79
|
+
* - task: Use `sessionUpdate: "plan"` with `PlanEntry[]`
|
|
80
|
+
* - diff: Use `ToolCallContent` with `type: "diff"`
|
|
81
|
+
*/
|
|
82
|
+
type ArtifactType = 'plan' | 'walkthrough' | 'snapshot' | 'video' | 'web_preview' | 'custom';
|
|
83
|
+
/**
|
|
84
|
+
* Status of an artifact
|
|
85
|
+
*/
|
|
86
|
+
type ArtifactStatus = 'creating' | 'ready' | 'updating' | 'archived';
|
|
87
|
+
/**
|
|
88
|
+
* Artifact metadata base interface
|
|
89
|
+
*/
|
|
90
|
+
interface ArtifactMeta {
|
|
91
|
+
mimeType?: string;
|
|
92
|
+
size?: number;
|
|
93
|
+
preview?: string;
|
|
94
|
+
[key: string]: unknown;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Base artifact interface
|
|
98
|
+
*/
|
|
99
|
+
interface BaseArtifact {
|
|
100
|
+
id: string;
|
|
101
|
+
type: ArtifactType;
|
|
102
|
+
title: string;
|
|
103
|
+
uri: string;
|
|
104
|
+
status: ArtifactStatus;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* An artifact created by the agent
|
|
108
|
+
* Generic parameter allows type-safe metadata for specific artifact types
|
|
109
|
+
*/
|
|
110
|
+
interface Artifact<TMeta extends ArtifactMeta = ArtifactMeta> extends BaseArtifact {
|
|
111
|
+
_meta?: TMeta;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Question option structure
|
|
115
|
+
*/
|
|
116
|
+
interface QuestionOption {
|
|
117
|
+
/** Display text (1-5 words) */
|
|
118
|
+
label: string;
|
|
119
|
+
/** Option description */
|
|
120
|
+
description: string;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Single question structure
|
|
124
|
+
*/
|
|
125
|
+
interface UserQuestion {
|
|
126
|
+
/** Question ID */
|
|
127
|
+
id: string;
|
|
128
|
+
/** Question text */
|
|
129
|
+
question: string;
|
|
130
|
+
/** Short label (max 12 chars) */
|
|
131
|
+
header?: string;
|
|
132
|
+
/** Available options (2-4) */
|
|
133
|
+
options: QuestionOption[];
|
|
134
|
+
/** Allow multiple selections */
|
|
135
|
+
multiSelect?: boolean;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Schema for 'question' inputType
|
|
139
|
+
*/
|
|
140
|
+
interface QuestionInputSchema {
|
|
141
|
+
/** Questions to ask (1-4) */
|
|
142
|
+
questions: UserQuestion[];
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Response data for 'question' inputType
|
|
146
|
+
*/
|
|
147
|
+
interface QuestionInputData {
|
|
148
|
+
/** User's answers keyed by question ID */
|
|
149
|
+
answers: Record<string, string | string[]>;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Token usage information
|
|
153
|
+
* Sent via extNotification: _codebuddy.ai/usage_update
|
|
154
|
+
*/
|
|
155
|
+
interface UsageUpdate {
|
|
156
|
+
sessionId: string;
|
|
157
|
+
inputTokens?: number;
|
|
158
|
+
outputTokens?: number;
|
|
159
|
+
totalTokens?: number;
|
|
160
|
+
cost?: number;
|
|
161
|
+
model?: string;
|
|
162
|
+
_meta?: Record<string, unknown>;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Checkpoint information visible to clients
|
|
166
|
+
*/
|
|
167
|
+
interface CheckpointInfo {
|
|
168
|
+
/** Checkpoint ID */
|
|
169
|
+
id: string;
|
|
170
|
+
/** Label/description */
|
|
171
|
+
label?: string;
|
|
172
|
+
/** Creation timestamp */
|
|
173
|
+
createdAt: number;
|
|
174
|
+
/** File change summary */
|
|
175
|
+
fileChanges: FileChangeSummary;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* File change summary for a checkpoint
|
|
179
|
+
*/
|
|
180
|
+
interface FileChangeSummary {
|
|
181
|
+
/** List of changed files */
|
|
182
|
+
files: FileChangeInfo[];
|
|
183
|
+
/** Total lines added */
|
|
184
|
+
totalAdditions: number;
|
|
185
|
+
/** Total lines deleted */
|
|
186
|
+
totalDeletions: number;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Change type for a file
|
|
190
|
+
*/
|
|
191
|
+
type FileChangeType = 'created' | 'modified' | 'deleted';
|
|
192
|
+
/**
|
|
193
|
+
* Information about a single file change
|
|
194
|
+
*/
|
|
195
|
+
interface FileChangeInfo {
|
|
196
|
+
/** File URI (agent://files/{path}) */
|
|
197
|
+
uri: string;
|
|
198
|
+
/** Type of change */
|
|
199
|
+
changeType: FileChangeType;
|
|
200
|
+
/** Lines added */
|
|
201
|
+
additions: number;
|
|
202
|
+
/** Lines deleted */
|
|
203
|
+
deletions: number;
|
|
204
|
+
/** Unified diff format content */
|
|
205
|
+
diff?: string;
|
|
206
|
+
/** File language */
|
|
207
|
+
language?: string;
|
|
208
|
+
/** Virtual URI for original content (agent-diff://...) */
|
|
209
|
+
originalUri?: string;
|
|
210
|
+
/** Virtual URI for modified content (agent-diff://...) */
|
|
211
|
+
modifiedUri?: string;
|
|
212
|
+
}
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region ../agent-client-protocol/lib/common/sdk.d.ts
|
|
215
|
+
/**
|
|
216
|
+
* Configuration for a specific artifact type
|
|
217
|
+
*/
|
|
218
|
+
interface ArtifactTypeConfig {
|
|
219
|
+
/** Whether this artifact type is enabled */
|
|
220
|
+
enabled?: boolean;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Artifacts configuration in codebuddy.ai extension
|
|
224
|
+
*/
|
|
225
|
+
type ArtifactsConfig = { [K in ArtifactType]?: ArtifactTypeConfig };
|
|
226
|
+
/**
|
|
227
|
+
* codebuddy.ai extension capabilities for Client
|
|
228
|
+
*/
|
|
229
|
+
interface CodebuddyClientMeta {}
|
|
230
|
+
/**
|
|
231
|
+
* codebuddy.ai extension capabilities for Agent
|
|
232
|
+
*/
|
|
233
|
+
interface CodebuddyAgentMeta {
|
|
234
|
+
/** Artifact types the agent can produce */
|
|
235
|
+
artifacts?: ArtifactsConfig;
|
|
236
|
+
/** Whether the agent supports checkpoint notifications */
|
|
237
|
+
checkpoint?: boolean;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Client capabilities with codebuddy.ai extensions
|
|
241
|
+
*/
|
|
242
|
+
interface ClientCapabilities$1 extends ClientCapabilities {
|
|
243
|
+
_meta?: {
|
|
244
|
+
'codebuddy.ai'?: CodebuddyClientMeta;
|
|
245
|
+
[key: string]: unknown;
|
|
246
|
+
} | null;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Agent capabilities with codebuddy.ai extensions
|
|
250
|
+
*/
|
|
251
|
+
interface AgentCapabilities extends AgentCapabilities$1 {
|
|
252
|
+
_meta?: {
|
|
253
|
+
'codebuddy.ai'?: CodebuddyAgentMeta;
|
|
254
|
+
[key: string]: unknown;
|
|
255
|
+
} | null;
|
|
256
|
+
}
|
|
257
|
+
//#endregion
|
|
258
|
+
//#region ../agent-client-protocol/lib/common/client/questions.d.ts
|
|
259
|
+
/**
|
|
260
|
+
* Strongly-typed question request for client API
|
|
261
|
+
* Narrows ToolInputRequest to 'question' inputType with proper schema typing
|
|
262
|
+
*/
|
|
263
|
+
interface QuestionRequest {
|
|
264
|
+
/** Session ID */
|
|
265
|
+
sessionId: string;
|
|
266
|
+
/** Associated tool call ID */
|
|
267
|
+
toolCallId: string;
|
|
268
|
+
/** Questions to present to the user */
|
|
269
|
+
questions: QuestionInputSchema['questions'];
|
|
270
|
+
/** Request timeout in ms */
|
|
271
|
+
timeout?: number;
|
|
272
|
+
/** Additional metadata */
|
|
273
|
+
_meta?: Record<string, unknown>;
|
|
274
|
+
}
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region ../agent-client-protocol/lib/common/client/types.d.ts
|
|
277
|
+
/**
|
|
278
|
+
* Client connection states
|
|
279
|
+
*/
|
|
280
|
+
type ClientState = 'disconnected' | 'connecting' | 'connected' | 'initialized' | 'error';
|
|
281
|
+
/**
|
|
282
|
+
* Logger interface
|
|
283
|
+
*/
|
|
284
|
+
interface Logger$1 {
|
|
285
|
+
debug(message: string, ...args: unknown[]): void;
|
|
286
|
+
info(message: string, ...args: unknown[]): void;
|
|
287
|
+
warn(message: string, ...args: unknown[]): void;
|
|
288
|
+
error(message: string, ...args: unknown[]): void;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Events emitted by the client
|
|
292
|
+
*/
|
|
293
|
+
interface ClientEvents extends Record<string, unknown> {
|
|
294
|
+
connecting: void;
|
|
295
|
+
connected: void;
|
|
296
|
+
disconnected: void;
|
|
297
|
+
error: Error;
|
|
298
|
+
stateChange: {
|
|
299
|
+
previous: ClientState;
|
|
300
|
+
current: ClientState;
|
|
301
|
+
};
|
|
302
|
+
sessionUpdate: SessionNotification;
|
|
303
|
+
artifactCreated: Artifact;
|
|
304
|
+
artifactUpdated: Artifact;
|
|
305
|
+
artifactDeleted: Artifact;
|
|
306
|
+
usageUpdate: UsageUpdate;
|
|
307
|
+
permissionRequest: {
|
|
308
|
+
requestId: string;
|
|
309
|
+
params: RequestPermissionRequest;
|
|
310
|
+
};
|
|
311
|
+
permissionResolved: {
|
|
312
|
+
requestId: string;
|
|
313
|
+
optionId: string;
|
|
314
|
+
};
|
|
315
|
+
permissionRejected: {
|
|
316
|
+
requestId: string;
|
|
317
|
+
reason?: string;
|
|
318
|
+
};
|
|
319
|
+
permissionTimeout: {
|
|
320
|
+
requestId: string;
|
|
321
|
+
};
|
|
322
|
+
questionRequest: {
|
|
323
|
+
toolCallId: string;
|
|
324
|
+
request: QuestionRequest;
|
|
325
|
+
};
|
|
326
|
+
questionAnswered: {
|
|
327
|
+
toolCallId: string;
|
|
328
|
+
answers: QuestionInputData;
|
|
329
|
+
};
|
|
330
|
+
questionCancelled: {
|
|
331
|
+
toolCallId: string;
|
|
332
|
+
reason?: string;
|
|
333
|
+
};
|
|
334
|
+
questionTimeout: {
|
|
335
|
+
toolCallId: string;
|
|
336
|
+
};
|
|
337
|
+
checkpointCreated: CheckpointInfo;
|
|
338
|
+
checkpointUpdated: CheckpointInfo;
|
|
339
|
+
}
|
|
340
|
+
//#endregion
|
|
341
|
+
//#region ../agent-provider/lib/common/providers/local-agent-provider/acp/types.d.ts
|
|
342
|
+
/**
|
|
343
|
+
* 可用命令定义 (符合 ACP 协议)
|
|
344
|
+
* 参考: https://agentclientprotocol.com/protocol/slash-commands
|
|
345
|
+
*/
|
|
346
|
+
interface AvailableCommand {
|
|
347
|
+
/** 命令名称 (如 "web", "test", "plan") */
|
|
348
|
+
readonly name: string;
|
|
349
|
+
/** 人类可读的命令描述 */
|
|
350
|
+
readonly description: string;
|
|
351
|
+
/** 可选的输入规范 */
|
|
352
|
+
readonly input?: {
|
|
353
|
+
/** 输入提示,当用户未提供输入时显示 */readonly hint?: string;
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
//#endregion
|
|
357
|
+
//#region ../agent-provider/lib/common/types.d.ts
|
|
358
|
+
/**
|
|
359
|
+
* Base options for filesystem operations
|
|
360
|
+
* 对齐 e2b SDK FilesystemRequestOpts
|
|
361
|
+
*/
|
|
362
|
+
interface FilesystemRequestOpts {
|
|
363
|
+
user?: string;
|
|
364
|
+
requestTimeoutMs?: number;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Options for list operation
|
|
368
|
+
* 对齐 e2b SDK FilesystemListOpts
|
|
369
|
+
*/
|
|
370
|
+
interface FilesystemListOpts extends FilesystemRequestOpts {
|
|
371
|
+
depth?: number;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Options for watchDir operation
|
|
375
|
+
* 对齐 e2b SDK WatchOpts
|
|
376
|
+
*/
|
|
377
|
+
interface WatchOpts extends FilesystemRequestOpts {
|
|
378
|
+
timeoutMs?: number;
|
|
379
|
+
onExit?: (err?: Error) => void | Promise<void>;
|
|
380
|
+
recursive?: boolean;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Entry for batch write operation
|
|
384
|
+
* 对齐 e2b SDK WriteEntry
|
|
385
|
+
*/
|
|
386
|
+
type WriteEntry = {
|
|
387
|
+
path: string;
|
|
388
|
+
data: string | ArrayBuffer | Blob | ReadableStream;
|
|
389
|
+
};
|
|
390
|
+
/**
|
|
391
|
+
* E2B Sandbox connection information
|
|
392
|
+
* 与 e2b SDK 的 ConnectionOpts 对齐
|
|
393
|
+
*/
|
|
394
|
+
interface E2BSandboxConnectionInfo {
|
|
395
|
+
/** Sandbox ID */
|
|
396
|
+
sandboxId: string;
|
|
397
|
+
/** API key for authentication (e2b_ 开头的 key) */
|
|
398
|
+
apiKey?: string;
|
|
399
|
+
/** Access token for authentication (JWT 格式的 token) */
|
|
400
|
+
accessToken?: string;
|
|
401
|
+
/** Domain for the API (不带 https://) */
|
|
402
|
+
domain?: string;
|
|
403
|
+
/** API URL override (internal) */
|
|
404
|
+
apiUrl?: string;
|
|
405
|
+
/** Request timeout in milliseconds */
|
|
406
|
+
requestTimeoutMs?: number;
|
|
407
|
+
/** Debug mode */
|
|
408
|
+
debug?: boolean;
|
|
409
|
+
/**
|
|
410
|
+
* Additional headers to send with the request.
|
|
411
|
+
*/
|
|
412
|
+
headers?: Record<string, string>;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Filesystem resource interface
|
|
416
|
+
* Mirrors e2b SDK Filesystem API
|
|
417
|
+
* 完全对齐 e2b SDK 的 Filesystem 类
|
|
418
|
+
*/
|
|
419
|
+
interface FilesResource {
|
|
420
|
+
/** Read file content as text (default) */
|
|
421
|
+
read(path: string, opts?: FilesystemRequestOpts & {
|
|
422
|
+
format?: 'text';
|
|
423
|
+
}): Promise<string>;
|
|
424
|
+
/** Read file content as bytes */
|
|
425
|
+
read(path: string, opts: FilesystemRequestOpts & {
|
|
426
|
+
format: 'bytes';
|
|
427
|
+
}): Promise<Uint8Array>;
|
|
428
|
+
/** Read file content as blob */
|
|
429
|
+
read(path: string, opts: FilesystemRequestOpts & {
|
|
430
|
+
format: 'blob';
|
|
431
|
+
}): Promise<Blob>;
|
|
432
|
+
/** Read file content as stream */
|
|
433
|
+
read(path: string, opts: FilesystemRequestOpts & {
|
|
434
|
+
format: 'stream';
|
|
435
|
+
}): Promise<ReadableStream<Uint8Array>>;
|
|
436
|
+
/** Write content to a single file */
|
|
437
|
+
write(path: string, data: string | ArrayBuffer | Blob | ReadableStream, opts?: FilesystemRequestOpts): Promise<WriteInfo>;
|
|
438
|
+
/** Write multiple files in batch */
|
|
439
|
+
write(files: WriteEntry[], opts?: FilesystemRequestOpts): Promise<WriteInfo[]>;
|
|
440
|
+
/** List directory contents with optional depth */
|
|
441
|
+
list(path: string, opts?: FilesystemListOpts): Promise<EntryInfo$1[]>;
|
|
442
|
+
/** Check if path exists */
|
|
443
|
+
exists(path: string, opts?: FilesystemRequestOpts): Promise<boolean>;
|
|
444
|
+
/** Create directory */
|
|
445
|
+
makeDir(path: string, opts?: FilesystemRequestOpts): Promise<boolean>;
|
|
446
|
+
/** Remove file or directory */
|
|
447
|
+
remove(path: string, opts?: FilesystemRequestOpts): Promise<void>;
|
|
448
|
+
/** Rename/move file or directory */
|
|
449
|
+
rename(oldPath: string, newPath: string, opts?: FilesystemRequestOpts): Promise<EntryInfo$1>;
|
|
450
|
+
/** Get file or directory information */
|
|
451
|
+
getInfo(path: string, opts?: FilesystemRequestOpts): Promise<EntryInfo$1>;
|
|
452
|
+
/** Watch directory for changes */
|
|
453
|
+
watchDir(path: string, onEvent: (event: FilesystemEvent) => void | Promise<void>, opts?: WatchOpts & {
|
|
454
|
+
onExit?: (err?: Error) => void | Promise<void>;
|
|
455
|
+
}): Promise<WatchHandle>;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Filesystem provider interface - implemented by Provider
|
|
459
|
+
*/
|
|
460
|
+
interface FilesystemProvider {
|
|
461
|
+
/**
|
|
462
|
+
* Get filesystem resource for an agent
|
|
463
|
+
* @param agentId - Agent ID (used to get the corresponding sandbox connection)
|
|
464
|
+
*/
|
|
465
|
+
getFilesystem(agentId: string): Promise<FilesResource>;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Transport type for agents
|
|
469
|
+
*/
|
|
470
|
+
type AgentTransport = 'cloud' | 'local';
|
|
471
|
+
/**
|
|
472
|
+
* Agent connection status
|
|
473
|
+
*/
|
|
474
|
+
type AgentStatus = 'disconnected' | 'connecting' | 'connected' | 'initialized' | 'error';
|
|
475
|
+
/**
|
|
476
|
+
* Agent information
|
|
477
|
+
*/
|
|
478
|
+
interface Agent {
|
|
479
|
+
id: string;
|
|
480
|
+
name: string;
|
|
481
|
+
description?: string;
|
|
482
|
+
version?: string;
|
|
483
|
+
transport: AgentTransport;
|
|
484
|
+
status: AgentStatus;
|
|
485
|
+
capabilities?: AgentCapabilities;
|
|
486
|
+
metadata?: Record<string, unknown>;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Session mode configuration
|
|
490
|
+
*/
|
|
491
|
+
interface SessionMode {
|
|
492
|
+
id: string;
|
|
493
|
+
name: string;
|
|
494
|
+
description?: string | null;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Session information
|
|
498
|
+
*/
|
|
499
|
+
interface Session {
|
|
500
|
+
id: string;
|
|
501
|
+
agentId: string;
|
|
502
|
+
availableModes?: SessionMode[];
|
|
503
|
+
currentMode?: string;
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Parameters for creating a new session
|
|
507
|
+
*/
|
|
508
|
+
interface CreateSessionParams {
|
|
509
|
+
cwd: string;
|
|
510
|
+
mcpServers?: McpServerConfig[];
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Parameters for loading an existing session
|
|
514
|
+
* If sessionId is not provided, reloads the current session
|
|
515
|
+
*/
|
|
516
|
+
interface LoadSessionParams {
|
|
517
|
+
/** Session ID to load (optional - uses current session if not provided) */
|
|
518
|
+
sessionId?: string;
|
|
519
|
+
cwd: string;
|
|
520
|
+
mcpServers?: McpServerConfig[];
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* MCP server configuration
|
|
524
|
+
*/
|
|
525
|
+
interface McpServerConfig {
|
|
526
|
+
name: string;
|
|
527
|
+
command: string;
|
|
528
|
+
args?: string[];
|
|
529
|
+
env?: Record<string, string>;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Prompt content block types
|
|
533
|
+
*/
|
|
534
|
+
type PromptContentBlock = {
|
|
535
|
+
type: 'text';
|
|
536
|
+
text: string;
|
|
537
|
+
_meta?: {
|
|
538
|
+
[key: string]: unknown;
|
|
539
|
+
} | null | undefined;
|
|
540
|
+
} | {
|
|
541
|
+
type: 'image';
|
|
542
|
+
data: string;
|
|
543
|
+
mimeType: string;
|
|
544
|
+
} | {
|
|
545
|
+
type: 'resource';
|
|
546
|
+
uri: string;
|
|
547
|
+
};
|
|
548
|
+
/**
|
|
549
|
+
* Parameters for sending a prompt
|
|
550
|
+
*/
|
|
551
|
+
interface PromptParams {
|
|
552
|
+
content: string | PromptContentBlock[];
|
|
553
|
+
planMode?: boolean;
|
|
554
|
+
_meta?: Record<string, unknown>;
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Events emitted by agent connections
|
|
558
|
+
*/
|
|
559
|
+
interface ConnectionEvents extends ClientEvents {
|
|
560
|
+
spawn: {
|
|
561
|
+
pid: number;
|
|
562
|
+
};
|
|
563
|
+
exit: {
|
|
564
|
+
code: number | null;
|
|
565
|
+
signal: string | null;
|
|
566
|
+
};
|
|
567
|
+
questionRequest: {
|
|
568
|
+
toolCallId: string;
|
|
569
|
+
request: QuestionRequest;
|
|
570
|
+
};
|
|
571
|
+
questionAnswered: {
|
|
572
|
+
toolCallId: string;
|
|
573
|
+
answers: QuestionInputData;
|
|
574
|
+
};
|
|
575
|
+
questionCancelled: {
|
|
576
|
+
toolCallId: string;
|
|
577
|
+
reason?: string;
|
|
578
|
+
};
|
|
579
|
+
questionTimeout: {
|
|
580
|
+
toolCallId: string;
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Event listener type
|
|
585
|
+
*/
|
|
586
|
+
type ConnectionEventListener<T> = (data: T) => void | Promise<void>;
|
|
587
|
+
/**
|
|
588
|
+
* Abstract interface for agent connections
|
|
589
|
+
* Implemented by CloudAgentConnection and LocalAgentConnection
|
|
590
|
+
*/
|
|
591
|
+
interface AgentConnection {
|
|
592
|
+
/** Agent ID */
|
|
593
|
+
readonly agentId: string;
|
|
594
|
+
on<K extends keyof ConnectionEvents>(event: K, listener: ConnectionEventListener<ConnectionEvents[K]>): this;
|
|
595
|
+
off<K extends keyof ConnectionEvents>(event: K, listener: ConnectionEventListener<ConnectionEvents[K]>): this;
|
|
596
|
+
once<K extends keyof ConnectionEvents>(event: K, listener: ConnectionEventListener<ConnectionEvents[K]>): this;
|
|
597
|
+
emit<K extends keyof ConnectionEvents>(event: K, data: ConnectionEvents[K]): boolean;
|
|
598
|
+
removeAllListeners<K extends keyof ConnectionEvents>(event?: K): this;
|
|
599
|
+
/** Transport type */
|
|
600
|
+
readonly transport: AgentTransport;
|
|
601
|
+
/** Current connection state */
|
|
602
|
+
readonly state: AgentStatus;
|
|
603
|
+
/** Whether the connection is initialized */
|
|
604
|
+
readonly isInitialized: boolean;
|
|
605
|
+
/** Agent capabilities (available after initialization) */
|
|
606
|
+
readonly capabilities?: AgentCapabilities;
|
|
607
|
+
/** Initialize response (available after initialization) */
|
|
608
|
+
readonly initializeResult?: InitializeResponse;
|
|
609
|
+
connect(): Promise<InitializeResponse>;
|
|
610
|
+
disconnect(): void | Promise<void>;
|
|
611
|
+
createSession(params: CreateSessionParams): Promise<NewSessionResponse>;
|
|
612
|
+
loadSession(params: LoadSessionParams): Promise<LoadSessionResponse>;
|
|
613
|
+
setSessionMode(sessionId: string, modeId: string): Promise<SetSessionModeResponse>;
|
|
614
|
+
/**
|
|
615
|
+
* Set the session model
|
|
616
|
+
* @experimental This API is unstable and may change
|
|
617
|
+
*/
|
|
618
|
+
setSessionModel(sessionId: string, modelId: string): Promise<SetSessionModelResponse>;
|
|
619
|
+
prompt(sessionId: string, params: PromptParams): Promise<PromptResponse$1>;
|
|
620
|
+
promptStream(sessionId: string, params: PromptParams): AsyncIterable<SessionNotification>;
|
|
621
|
+
cancel(sessionId: string): Promise<void>;
|
|
622
|
+
resolvePermission(requestId: string, optionId: string): boolean;
|
|
623
|
+
rejectPermission(requestId: string, reason?: string): boolean;
|
|
624
|
+
getPendingPermissions(): Map<string, {
|
|
625
|
+
params: RequestPermissionRequest;
|
|
626
|
+
createdAt: number;
|
|
627
|
+
}>;
|
|
628
|
+
hasPendingPermissions(): boolean;
|
|
629
|
+
answerQuestion(toolCallId: string, answers: QuestionInputData): boolean;
|
|
630
|
+
cancelQuestion(toolCallId: string, reason?: string): boolean;
|
|
631
|
+
getPendingQuestions(): Map<string, {
|
|
632
|
+
request: QuestionRequest;
|
|
633
|
+
createdAt: number;
|
|
634
|
+
}>;
|
|
635
|
+
hasPendingQuestions(): boolean;
|
|
636
|
+
/**
|
|
637
|
+
* 工具回调操作
|
|
638
|
+
* 用于对正在执行的工具进行 skip 或 cancel 操作
|
|
639
|
+
* @param sessionId 会话 ID
|
|
640
|
+
* @param toolCallId 工具调用 ID
|
|
641
|
+
* @param toolName 工具名称
|
|
642
|
+
* @param action 操作类型 ('skip' | 'cancel')
|
|
643
|
+
*/
|
|
644
|
+
toolCallback(sessionId: string, toolCallId: string, toolName: string, action: 'skip' | 'cancel'): Promise<{
|
|
645
|
+
success: boolean;
|
|
646
|
+
error?: string;
|
|
647
|
+
}>;
|
|
648
|
+
extMethod(method: string, params: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Base configuration for connections
|
|
652
|
+
*/
|
|
653
|
+
interface BaseConnectionConfig {
|
|
654
|
+
/** Logger instance */
|
|
655
|
+
logger?: Logger$1;
|
|
656
|
+
/** Permission timeout (ms) */
|
|
657
|
+
permissionTimeout?: number;
|
|
658
|
+
/** Auto-reject permissions on timeout */
|
|
659
|
+
permissionAutoRejectOnTimeout?: boolean;
|
|
660
|
+
/** Auto-approve all permissions */
|
|
661
|
+
autoApprove?: boolean;
|
|
662
|
+
/** Client capabilities (sent during initialization) */
|
|
663
|
+
clientCapabilities?: ClientCapabilities$1;
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Configuration for cloud agent connections
|
|
667
|
+
*/
|
|
668
|
+
interface CloudConnectionConfig extends BaseConnectionConfig {
|
|
669
|
+
/** Agent endpoint URL */
|
|
670
|
+
endpoint: string;
|
|
671
|
+
/** Authorization token */
|
|
672
|
+
authToken?: string;
|
|
673
|
+
/** Custom headers */
|
|
674
|
+
headers?: Record<string, string>;
|
|
675
|
+
/** Reconnect options */
|
|
676
|
+
reconnect?: {
|
|
677
|
+
enabled?: boolean;
|
|
678
|
+
initialDelay?: number;
|
|
679
|
+
maxDelay?: number;
|
|
680
|
+
maxRetries?: number;
|
|
681
|
+
};
|
|
682
|
+
/** Initialize timeout (ms) */
|
|
683
|
+
initializeTimeout?: number;
|
|
684
|
+
/** Custom fetch implementation */
|
|
685
|
+
fetch?: typeof fetch;
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Model reasoning configuration
|
|
689
|
+
*/
|
|
690
|
+
interface ModelReasoning {
|
|
691
|
+
/** Reasoning effort level */
|
|
692
|
+
effort: 'low' | 'medium' | 'high';
|
|
693
|
+
/** When to show summary */
|
|
694
|
+
summary: 'never' | 'always' | 'auto';
|
|
695
|
+
}
|
|
696
|
+
/**
|
|
697
|
+
* Model information
|
|
698
|
+
*/
|
|
699
|
+
interface ModelInfo$1 {
|
|
700
|
+
/** 模型唯一标识符,例如"gpt-3.5-turbo" */
|
|
701
|
+
readonly id: string;
|
|
702
|
+
/** 可选,模型名称,例如"GPT-3.5 Turbo" */
|
|
703
|
+
readonly name?: string;
|
|
704
|
+
/** 可选,模型供应商,例如"OpenAI" */
|
|
705
|
+
readonly vendor?: string;
|
|
706
|
+
/** 可选,模型版本,例如"2024-06-01" */
|
|
707
|
+
readonly version?: string;
|
|
708
|
+
/** 可选,模型家族,例如"gpt" */
|
|
709
|
+
readonly family?: string;
|
|
710
|
+
/** 可选,最大输入 token 数,例如 4096 */
|
|
711
|
+
readonly maxInputTokens?: number;
|
|
712
|
+
/** 可选,最大输出 token 数,例如 1024 */
|
|
713
|
+
readonly maxOutputTokens?: number;
|
|
714
|
+
/** 描述 */
|
|
715
|
+
readonly description?: string;
|
|
716
|
+
/** 英文描述 */
|
|
717
|
+
readonly descriptionEn?: string;
|
|
718
|
+
/** 中文描述 */
|
|
719
|
+
readonly descriptionZh?: string;
|
|
720
|
+
/** 是否可配置 */
|
|
721
|
+
readonly configurable?: boolean;
|
|
722
|
+
/** 已经配置 */
|
|
723
|
+
readonly configured?: boolean;
|
|
724
|
+
/** 接口地址(全路径) */
|
|
725
|
+
readonly url?: string;
|
|
726
|
+
/** 模型 apiKey,自定义模型需要 */
|
|
727
|
+
readonly apiKey?: string;
|
|
728
|
+
/** 是否支持 extra 上下文 */
|
|
729
|
+
readonly supportsExtra?: boolean;
|
|
730
|
+
/** 是否支持工具调用 */
|
|
731
|
+
readonly supportsToolCall?: boolean;
|
|
732
|
+
/** 是否支持图片 */
|
|
733
|
+
readonly supportsImages?: boolean;
|
|
734
|
+
/** 是否支持推理 */
|
|
735
|
+
readonly supportsReasoning?: boolean;
|
|
736
|
+
/** 是否只支持推理模型 */
|
|
737
|
+
readonly onlyReasoning?: boolean;
|
|
738
|
+
/** 开始上下文处理的 token 阈值 */
|
|
739
|
+
readonly maxAllowedSize?: number;
|
|
740
|
+
/** tags */
|
|
741
|
+
readonly tags?: string[];
|
|
742
|
+
/** 是否关闭多模态能力 */
|
|
743
|
+
readonly disabledMultimodal?: boolean;
|
|
744
|
+
/** 模型消耗的积分信息 */
|
|
745
|
+
readonly credits?: string;
|
|
746
|
+
/** 推理配置 */
|
|
747
|
+
readonly reasoning?: ModelReasoning;
|
|
748
|
+
/** 最多支持的图片数量 */
|
|
749
|
+
readonly maxImageCount?: number;
|
|
750
|
+
/** 是否是默认模型 */
|
|
751
|
+
readonly isDefault?: boolean;
|
|
752
|
+
/** 温度 */
|
|
753
|
+
readonly temperature?: number;
|
|
754
|
+
/** icon */
|
|
755
|
+
readonly iconUrl?: string;
|
|
756
|
+
/** 模型类型:enterprise 表示企业版模型,built-in 表示内置模型 */
|
|
757
|
+
readonly modelType?: 'enterprise' | 'built-in';
|
|
758
|
+
/** 模型可信安全级别 */
|
|
759
|
+
readonly trustLevel?: ModelTrustLevel;
|
|
760
|
+
/** 是否禁用该模型(用于安全限制等场景) */
|
|
761
|
+
readonly disabled?: boolean;
|
|
762
|
+
/** 禁用原因说明(例如:"当前项目为敏感项目,建议使用内部模型") */
|
|
763
|
+
readonly disabledReason?: string;
|
|
764
|
+
/** 禁用模型交互 */
|
|
765
|
+
readonly disabledAction?: {
|
|
766
|
+
type: 'link' | 'applyGroup';
|
|
767
|
+
text?: string;
|
|
768
|
+
link?: string;
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
declare enum ModelTrustLevel {
|
|
772
|
+
/** 未经验证,存在潜在风险 */
|
|
773
|
+
UNVERIFIED = "unverified",
|
|
774
|
+
/** 用户配置 */
|
|
775
|
+
CUSTOM = "custom",
|
|
776
|
+
/** 认证安全 */
|
|
777
|
+
CERTIFIED = "certified"
|
|
778
|
+
}
|
|
779
|
+
//#endregion
|
|
780
|
+
//#region ../agent-provider/lib/common/providers/cloud-agent-provider/cloud-connection.d.ts
|
|
781
|
+
/**
|
|
782
|
+
* Cloud Agent Connection implementation
|
|
783
|
+
* Uses Streamable HTTP transport to connect to cloud-hosted ACP agents
|
|
784
|
+
* Uses composition pattern - implements event emitter methods internally
|
|
785
|
+
*/
|
|
786
|
+
declare class CloudAgentConnection implements AgentConnection {
|
|
787
|
+
private client;
|
|
788
|
+
private listeners;
|
|
789
|
+
private onceListeners;
|
|
790
|
+
/**
|
|
791
|
+
* Flag to suppress sessionUpdate event emission during streaming.
|
|
792
|
+
* When true, onSessionUpdate callback won't emit to avoid duplicate messages with promptStream.
|
|
793
|
+
*/
|
|
794
|
+
private _isStreaming;
|
|
795
|
+
readonly agentId: string;
|
|
796
|
+
readonly transport: "cloud";
|
|
797
|
+
constructor(agentId: string, config: CloudConnectionConfig);
|
|
798
|
+
private setupEventForwarding;
|
|
799
|
+
on<K extends keyof ConnectionEvents>(event: K, listener: ConnectionEventListener<ConnectionEvents[K]>): this;
|
|
800
|
+
off<K extends keyof ConnectionEvents>(event: K, listener: ConnectionEventListener<ConnectionEvents[K]>): this;
|
|
801
|
+
once<K extends keyof ConnectionEvents>(event: K, listener: ConnectionEventListener<ConnectionEvents[K]>): this;
|
|
802
|
+
emit<K extends keyof ConnectionEvents>(event: K, data: ConnectionEvents[K]): boolean;
|
|
803
|
+
removeAllListeners<K extends keyof ConnectionEvents>(event?: K): this;
|
|
804
|
+
get state(): AgentStatus;
|
|
805
|
+
get isInitialized(): boolean;
|
|
806
|
+
get capabilities(): AgentCapabilities | undefined;
|
|
807
|
+
get initializeResult(): InitializeResponse | undefined;
|
|
808
|
+
connect(): Promise<InitializeResponse>;
|
|
809
|
+
disconnect(): Promise<void>;
|
|
810
|
+
createSession(params: CreateSessionParams): Promise<NewSessionResponse>;
|
|
811
|
+
loadSession(params: LoadSessionParams): Promise<LoadSessionResponse>;
|
|
812
|
+
setSessionMode(sessionId: string, modeId: string): Promise<SetSessionModeResponse>;
|
|
813
|
+
setSessionModel(sessionId: string, modelId: string): Promise<SetSessionModelResponse>;
|
|
814
|
+
prompt(sessionId: string, params: PromptParams): Promise<PromptResponse$1>;
|
|
815
|
+
promptStream(sessionId: string, params: PromptParams): AsyncIterable<SessionNotification>;
|
|
816
|
+
cancel(sessionId: string): Promise<void>;
|
|
817
|
+
resolvePermission(requestId: string, optionId: string): boolean;
|
|
818
|
+
rejectPermission(requestId: string, reason?: string): boolean;
|
|
819
|
+
getPendingPermissions(): Map<string, {
|
|
820
|
+
params: RequestPermissionRequest;
|
|
821
|
+
createdAt: number;
|
|
822
|
+
}>;
|
|
823
|
+
hasPendingPermissions(): boolean;
|
|
824
|
+
answerQuestion(toolCallId: string, answers: QuestionInputData): boolean;
|
|
825
|
+
cancelQuestion(toolCallId: string, reason?: string): boolean;
|
|
826
|
+
getPendingQuestions(): Map<string, {
|
|
827
|
+
request: QuestionRequest;
|
|
828
|
+
createdAt: number;
|
|
829
|
+
}>;
|
|
830
|
+
hasPendingQuestions(): boolean;
|
|
831
|
+
toolCallback(sessionId: string, toolCallId: string, toolName: string, action: 'skip' | 'cancel'): Promise<{
|
|
832
|
+
success: boolean;
|
|
833
|
+
error?: string;
|
|
834
|
+
}>;
|
|
835
|
+
extMethod(method: string, params: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
836
|
+
}
|
|
837
|
+
//#endregion
|
|
838
|
+
//#region ../agent-provider/lib/common/client/types.d.ts
|
|
839
|
+
/**
|
|
840
|
+
* Agent 来源类型
|
|
841
|
+
*/
|
|
842
|
+
type AgentStateType = 'local' | 'cloud';
|
|
843
|
+
/**
|
|
844
|
+
* 云端 Agent 可见性
|
|
845
|
+
*/
|
|
846
|
+
type CloudAgentVisibility = 'PRIVATE' | 'PUBLIC' | 'TEAM';
|
|
847
|
+
/**
|
|
848
|
+
* 云端 Agent 来源信息
|
|
849
|
+
*/
|
|
850
|
+
interface CloudAgentSourceInfo {
|
|
851
|
+
/** 提供商: github, gitlab 等 */
|
|
852
|
+
provider: string;
|
|
853
|
+
/** 分支/引用 */
|
|
854
|
+
ref: string;
|
|
855
|
+
/** 仓库路径 */
|
|
856
|
+
repository: string;
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* 云端 Agent 目标信息
|
|
860
|
+
*/
|
|
861
|
+
interface CloudAgentTarget {
|
|
862
|
+
/** 是否自动创建 PR */
|
|
863
|
+
autoCreatePr: boolean;
|
|
864
|
+
/** 分支名称 */
|
|
865
|
+
branchName?: string;
|
|
866
|
+
/** PR URL */
|
|
867
|
+
prUrl?: string;
|
|
868
|
+
/** Agent URL */
|
|
869
|
+
url?: string;
|
|
870
|
+
}
|
|
871
|
+
/**
|
|
872
|
+
* AgentState 基础接口
|
|
873
|
+
* 所有类型的 AgentState 都必须实现此接口
|
|
874
|
+
*/
|
|
875
|
+
interface BaseAgentState {
|
|
876
|
+
/** Unique agent ID */
|
|
877
|
+
id: string;
|
|
878
|
+
/** Display name */
|
|
879
|
+
name?: string;
|
|
880
|
+
/** Description */
|
|
881
|
+
description?: string;
|
|
882
|
+
/** Agent type */
|
|
883
|
+
type: AgentStateType;
|
|
884
|
+
/** Current connection status */
|
|
885
|
+
status: AgentStatus;
|
|
886
|
+
/** Agent capabilities (available after connection) */
|
|
887
|
+
capabilities?: AgentCapabilities;
|
|
888
|
+
/** When the agent was created */
|
|
889
|
+
createdAt?: Date;
|
|
890
|
+
/** When the agent was last updated */
|
|
891
|
+
updatedAt?: Date;
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* LocalAgentState - 本地 Agent 状态
|
|
895
|
+
* 来自本地 IPC 通信的 Agent
|
|
896
|
+
*/
|
|
897
|
+
interface LocalAgentState extends BaseAgentState {
|
|
898
|
+
type: 'local';
|
|
899
|
+
/** 工作目录 */
|
|
900
|
+
cwd: string;
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* CloudAgentState - 云端 Agent 状态
|
|
904
|
+
* 来自远程 API 的云端实例
|
|
905
|
+
*/
|
|
906
|
+
interface CloudAgentState extends BaseAgentState {
|
|
907
|
+
type: 'cloud';
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* AgentState - Unified agent state object exposed to client users
|
|
911
|
+
*
|
|
912
|
+
* This is the primary way clients access agent information.
|
|
913
|
+
* Uses discriminated union pattern to distinguish between local and cloud agents.
|
|
914
|
+
*/
|
|
915
|
+
type AgentState = LocalAgentState | CloudAgentState;
|
|
916
|
+
/**
|
|
917
|
+
* 类型守卫:判断是否为 CloudAgentState
|
|
918
|
+
*/
|
|
919
|
+
declare function isCloudAgentState(state: AgentState): state is CloudAgentState;
|
|
920
|
+
/**
|
|
921
|
+
* Logger interface
|
|
922
|
+
*/
|
|
923
|
+
interface Logger {
|
|
924
|
+
debug(message: string, ...args: unknown[]): void;
|
|
925
|
+
info(message: string, ...args: unknown[]): void;
|
|
926
|
+
warn(message: string, ...args: unknown[]): void;
|
|
927
|
+
error(message: string, ...args: unknown[]): void;
|
|
928
|
+
}
|
|
929
|
+
/**
|
|
930
|
+
* Filter condition for listing agents
|
|
931
|
+
*/
|
|
932
|
+
interface ListAgentFilter {
|
|
933
|
+
/** Filter field name (e.g., 'status', 'name') */
|
|
934
|
+
field: string;
|
|
935
|
+
/** Filter value (comma-separated for multiple values) */
|
|
936
|
+
value: string;
|
|
937
|
+
}
|
|
938
|
+
/**
|
|
939
|
+
* Sort options for listing agents
|
|
940
|
+
*/
|
|
941
|
+
interface ListAgentSort {
|
|
942
|
+
/** Sort field (e.g., 'createdAt', 'status') */
|
|
943
|
+
orderBy: string;
|
|
944
|
+
/** Sort direction */
|
|
945
|
+
order?: 'asc' | 'desc';
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* Query options for listing agents
|
|
949
|
+
*
|
|
950
|
+
* These options are supported by both CloudAgentProvider and LocalAgentProvider.
|
|
951
|
+
* Cloud: Server-side filtering, sorting, and pagination
|
|
952
|
+
* Local: Client-side filtering and sorting, no pagination (returns all)
|
|
953
|
+
*/
|
|
954
|
+
interface ListAgentOptions {
|
|
955
|
+
/**
|
|
956
|
+
* Page number (starts from 1)
|
|
957
|
+
* Cloud: Used for API pagination
|
|
958
|
+
* Local: Ignored (returns all sessions)
|
|
959
|
+
*/
|
|
960
|
+
page?: number;
|
|
961
|
+
/**
|
|
962
|
+
* Page size
|
|
963
|
+
* Cloud: Number of items per page (default 20, max 100)
|
|
964
|
+
* Local: Ignored (returns all sessions)
|
|
965
|
+
*/
|
|
966
|
+
size?: number;
|
|
967
|
+
/**
|
|
968
|
+
* Sort options
|
|
969
|
+
* Cloud: Sorts results by specified field and order
|
|
970
|
+
* Local: Sorts results by specified field and order
|
|
971
|
+
*/
|
|
972
|
+
sort?: ListAgentSort;
|
|
973
|
+
/**
|
|
974
|
+
* Filter conditions
|
|
975
|
+
* Cloud: Filters results by specified field values
|
|
976
|
+
* Local: Filters results by specified field values
|
|
977
|
+
*/
|
|
978
|
+
filters?: ListAgentFilter[];
|
|
979
|
+
/**
|
|
980
|
+
* Day range filter (e.g., agents created in last N days)
|
|
981
|
+
* Cloud: Filters by creation date
|
|
982
|
+
* Local: Filters by creation date
|
|
983
|
+
*/
|
|
984
|
+
dayRange?: number;
|
|
985
|
+
/**
|
|
986
|
+
* Title search keyword (matches agent title)
|
|
987
|
+
* Cloud: Server-side search
|
|
988
|
+
* Local: Client-side search
|
|
989
|
+
*/
|
|
990
|
+
title?: string;
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* Pagination metadata returned from list operations
|
|
994
|
+
*/
|
|
995
|
+
interface PaginationInfo {
|
|
996
|
+
/** Current page number (starts from 1) */
|
|
997
|
+
page: number;
|
|
998
|
+
/** Page size */
|
|
999
|
+
size: number;
|
|
1000
|
+
/** Total number of items */
|
|
1001
|
+
total: number;
|
|
1002
|
+
/** Total number of pages */
|
|
1003
|
+
totalPages: number;
|
|
1004
|
+
/** Whether there is a next page */
|
|
1005
|
+
hasNext: boolean;
|
|
1006
|
+
/** Whether there is a previous page */
|
|
1007
|
+
hasPrev: boolean;
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* Response from list operations that includes pagination
|
|
1011
|
+
*/
|
|
1012
|
+
interface ListAgentResult<T = AgentState> {
|
|
1013
|
+
/** List of agent states or session info */
|
|
1014
|
+
agents: T[];
|
|
1015
|
+
/** Pagination information */
|
|
1016
|
+
pagination: PaginationInfo;
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* Session information (returned by list, mapped from Agent)
|
|
1020
|
+
*/
|
|
1021
|
+
interface SessionInfo {
|
|
1022
|
+
/** Session ID (from agent.session) */
|
|
1023
|
+
id: string;
|
|
1024
|
+
/** Associated agent ID */
|
|
1025
|
+
agentId: string;
|
|
1026
|
+
/** Agent name */
|
|
1027
|
+
name?: string;
|
|
1028
|
+
/** Agent status */
|
|
1029
|
+
status: AgentStatus;
|
|
1030
|
+
/** When the session/agent was created */
|
|
1031
|
+
createdAt?: Date;
|
|
1032
|
+
/** Last activity timestamp */
|
|
1033
|
+
lastActivityAt?: Date;
|
|
1034
|
+
/** Working directory (for local agents) */
|
|
1035
|
+
cwd?: string;
|
|
1036
|
+
}
|
|
1037
|
+
/**
|
|
1038
|
+
* Parameters for creating a new session
|
|
1039
|
+
*/
|
|
1040
|
+
interface CreateSessionParams$1 {
|
|
1041
|
+
/** Working directory */
|
|
1042
|
+
cwd: string;
|
|
1043
|
+
/** MCP server configurations */
|
|
1044
|
+
mcpServers?: McpServerConfig[];
|
|
1045
|
+
}
|
|
1046
|
+
/**
|
|
1047
|
+
* Parameters for loading an existing session
|
|
1048
|
+
*/
|
|
1049
|
+
interface LoadSessionParams$1 {
|
|
1050
|
+
/** Session ID to load (required) */
|
|
1051
|
+
sessionId: string;
|
|
1052
|
+
/** Working directory */
|
|
1053
|
+
cwd: string;
|
|
1054
|
+
/** MCP server configurations */
|
|
1055
|
+
mcpServers?: McpServerConfig[];
|
|
1056
|
+
}
|
|
1057
|
+
/**
|
|
1058
|
+
* Parameters for initializing a workspace
|
|
1059
|
+
*/
|
|
1060
|
+
interface InitializeWorkspaceParams {
|
|
1061
|
+
/** Working directory */
|
|
1062
|
+
cwd: string;
|
|
1063
|
+
/** MCP server configurations */
|
|
1064
|
+
mcpServers?: McpServerConfig[];
|
|
1065
|
+
}
|
|
1066
|
+
/**
|
|
1067
|
+
* Response for workspace initialization
|
|
1068
|
+
*/
|
|
1069
|
+
interface InitializeWorkspaceResponse {
|
|
1070
|
+
/** Whether initialization was successful */
|
|
1071
|
+
success: boolean;
|
|
1072
|
+
/** Error message (if failed) */
|
|
1073
|
+
error?: string;
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Prompts resource interface (ACP verbs)
|
|
1077
|
+
* Operations use the current session automatically
|
|
1078
|
+
*/
|
|
1079
|
+
interface PromptsResource {
|
|
1080
|
+
/** Send a prompt and wait for completion */
|
|
1081
|
+
send(params: PromptParams): Promise<PromptResponse>;
|
|
1082
|
+
/** Stream a prompt (yields session updates) */
|
|
1083
|
+
stream(params: PromptParams): AsyncIterable<SessionNotification$1>;
|
|
1084
|
+
/** Cancel an ongoing prompt */
|
|
1085
|
+
cancel(): Promise<void>;
|
|
1086
|
+
}
|
|
1087
|
+
/**
|
|
1088
|
+
* Artifacts resource interface
|
|
1089
|
+
*/
|
|
1090
|
+
interface ArtifactsResource {
|
|
1091
|
+
/** List all artifacts */
|
|
1092
|
+
list(params?: {
|
|
1093
|
+
type?: ArtifactType;
|
|
1094
|
+
}): Promise<Artifact[]>;
|
|
1095
|
+
/** Get a single artifact */
|
|
1096
|
+
retrieve(artifactId: string): Promise<Artifact>;
|
|
1097
|
+
/** Get artifact content */
|
|
1098
|
+
content(artifactId: string): Promise<string>;
|
|
1099
|
+
}
|
|
1100
|
+
/**
|
|
1101
|
+
* Models resource interface
|
|
1102
|
+
*/
|
|
1103
|
+
interface ModelsResource {
|
|
1104
|
+
/** Get available models for a repository */
|
|
1105
|
+
list(repo: string): Promise<ModelInfo$1[]>;
|
|
1106
|
+
}
|
|
1107
|
+
/**
|
|
1108
|
+
* Prompt response
|
|
1109
|
+
*/
|
|
1110
|
+
interface PromptResponse {
|
|
1111
|
+
/** Stop reason */
|
|
1112
|
+
stopReason: 'end_turn' | 'max_tokens' | 'tool_use' | 'cancelled' | 'error';
|
|
1113
|
+
/** Response metadata */
|
|
1114
|
+
_meta?: Record<string, unknown>;
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* Sessions resource events for monitoring session list changes
|
|
1118
|
+
*/
|
|
1119
|
+
interface SessionsResourceEvents {
|
|
1120
|
+
/** Emitted when the sessions list changes (create, delete, update) */
|
|
1121
|
+
sessionsChanged: SessionInfo[];
|
|
1122
|
+
/** Emitted when a new session is created */
|
|
1123
|
+
sessionCreated: SessionInfo;
|
|
1124
|
+
/** Emitted when a session is deleted */
|
|
1125
|
+
sessionDeleted: {
|
|
1126
|
+
sessionId: string;
|
|
1127
|
+
};
|
|
1128
|
+
/** Emitted when a session is updated (status change, etc.) */
|
|
1129
|
+
sessionUpdated: SessionInfo;
|
|
1130
|
+
}
|
|
1131
|
+
/**
|
|
1132
|
+
* Event handler type for sessions resource events
|
|
1133
|
+
*/
|
|
1134
|
+
type SessionsResourceEventHandler<K extends keyof SessionsResourceEvents> = (data: SessionsResourceEvents[K]) => void | Promise<void>;
|
|
1135
|
+
/**
|
|
1136
|
+
* Session events for event subscription
|
|
1137
|
+
*/
|
|
1138
|
+
interface SessionEvents {
|
|
1139
|
+
/** Emitted when session updates occur */
|
|
1140
|
+
sessionUpdate: SessionNotification$1;
|
|
1141
|
+
/** Emitted when an artifact is created */
|
|
1142
|
+
artifactCreated: Artifact;
|
|
1143
|
+
/** Emitted when an artifact is updated */
|
|
1144
|
+
artifactUpdated: Artifact;
|
|
1145
|
+
/** Emitted when an artifact is deleted */
|
|
1146
|
+
artifactDeleted: Artifact;
|
|
1147
|
+
/** Emitted when a permission request is received */
|
|
1148
|
+
permissionRequest: {
|
|
1149
|
+
requestId: string;
|
|
1150
|
+
params: RequestPermissionRequest$1;
|
|
1151
|
+
};
|
|
1152
|
+
/** Emitted when a question request is received (ask_followup_question) */
|
|
1153
|
+
questionRequest: {
|
|
1154
|
+
toolCallId: string;
|
|
1155
|
+
request: QuestionRequest;
|
|
1156
|
+
};
|
|
1157
|
+
/** Emitted when usage data is updated */
|
|
1158
|
+
usageUpdate: UsageUpdate;
|
|
1159
|
+
/** Emitted when a checkpoint is created */
|
|
1160
|
+
checkpointCreated: CheckpointInfo;
|
|
1161
|
+
/** Emitted when a checkpoint is updated */
|
|
1162
|
+
checkpointUpdated: CheckpointInfo;
|
|
1163
|
+
/** Emitted when connected to agent */
|
|
1164
|
+
connected: void;
|
|
1165
|
+
/** Emitted when disconnected from agent */
|
|
1166
|
+
disconnected: void;
|
|
1167
|
+
/** Emitted when an error occurs */
|
|
1168
|
+
error: Error;
|
|
1169
|
+
}
|
|
1170
|
+
/**
|
|
1171
|
+
* Event handler type for session events
|
|
1172
|
+
*/
|
|
1173
|
+
type SessionEventHandler<K extends keyof SessionEvents> = (data: SessionEvents[K]) => void | Promise<void>;
|
|
1174
|
+
/**
|
|
1175
|
+
* Agent operations (accessed via session.agent)
|
|
1176
|
+
*/
|
|
1177
|
+
interface SessionAgentOperations {
|
|
1178
|
+
/** Agent ID */
|
|
1179
|
+
readonly id: string;
|
|
1180
|
+
/** Agent state */
|
|
1181
|
+
readonly state: AgentState;
|
|
1182
|
+
/** Whether the agent is connected */
|
|
1183
|
+
readonly isConnected: boolean;
|
|
1184
|
+
/** Agent capabilities */
|
|
1185
|
+
readonly capabilities?: AgentCapabilities;
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Active Session interface
|
|
1189
|
+
* Represents an active session with its resources and operations
|
|
1190
|
+
*
|
|
1191
|
+
* Key design:
|
|
1192
|
+
* - Session is the primary API surface
|
|
1193
|
+
* - agentState provides direct access to underlying agent state
|
|
1194
|
+
* - disconnect() is called directly on session (not session.agent)
|
|
1195
|
+
*/
|
|
1196
|
+
interface ActiveSession {
|
|
1197
|
+
/** Session ID */
|
|
1198
|
+
readonly id: string;
|
|
1199
|
+
/** Agent ID */
|
|
1200
|
+
readonly agentId: string;
|
|
1201
|
+
/** Agent state (direct access to underlying agent state) */
|
|
1202
|
+
readonly agentState: AgentState;
|
|
1203
|
+
/** Agent capabilities (available after connection) */
|
|
1204
|
+
readonly capabilities?: AgentCapabilities;
|
|
1205
|
+
/** Available session modes */
|
|
1206
|
+
readonly availableModes?: SessionMode[];
|
|
1207
|
+
/** Current session mode */
|
|
1208
|
+
readonly currentMode?: string;
|
|
1209
|
+
/** Available slash commands (updated via available_commands_update) */
|
|
1210
|
+
readonly availableCommands: AvailableCommand[];
|
|
1211
|
+
/** Whether the session is active */
|
|
1212
|
+
readonly isActive: boolean;
|
|
1213
|
+
/** Agent operations */
|
|
1214
|
+
readonly agent: SessionAgentOperations;
|
|
1215
|
+
/** Prompts resource */
|
|
1216
|
+
readonly prompts: PromptsResource;
|
|
1217
|
+
/** Artifacts resource */
|
|
1218
|
+
readonly artifacts: ArtifactsResource;
|
|
1219
|
+
/** Files resource */
|
|
1220
|
+
readonly files: FilesResource;
|
|
1221
|
+
/** Resolve a permission request */
|
|
1222
|
+
resolvePermission(requestId: string, optionId: string): boolean;
|
|
1223
|
+
/** Reject a permission request */
|
|
1224
|
+
rejectPermission(requestId: string, reason?: string): boolean;
|
|
1225
|
+
/** Answer a question request with user's selections */
|
|
1226
|
+
answerQuestion(toolCallId: string, answers: QuestionInputData): boolean;
|
|
1227
|
+
/** Cancel a question request */
|
|
1228
|
+
cancelQuestion(toolCallId: string, reason?: string): boolean;
|
|
1229
|
+
/** Callback for tool operations (skip or cancel) */
|
|
1230
|
+
toolCallback(toolCallId: string, toolName: string, action: 'skip' | 'cancel'): Promise<{
|
|
1231
|
+
success: boolean;
|
|
1232
|
+
error?: string;
|
|
1233
|
+
}>;
|
|
1234
|
+
/** Set the current session mode */
|
|
1235
|
+
setMode(modeId: string): Promise<void>;
|
|
1236
|
+
/** Set the current session model */
|
|
1237
|
+
setSessionModel(modelId: string): Promise<void>;
|
|
1238
|
+
/** Subscribe to an event */
|
|
1239
|
+
on<K extends keyof SessionEvents>(event: K, handler: SessionEventHandler<K>): this;
|
|
1240
|
+
/** Unsubscribe from an event */
|
|
1241
|
+
off<K extends keyof SessionEvents>(event: K, handler: SessionEventHandler<K>): this;
|
|
1242
|
+
/** Subscribe to an event once */
|
|
1243
|
+
once<K extends keyof SessionEvents>(event: K, handler: SessionEventHandler<K>): this;
|
|
1244
|
+
/** Disconnect from the session/agent */
|
|
1245
|
+
disconnect(): void;
|
|
1246
|
+
/** Symbol.dispose for 'using' keyword support */
|
|
1247
|
+
[Symbol.dispose](): void;
|
|
1248
|
+
}
|
|
1249
|
+
/**
|
|
1250
|
+
* 环境类型
|
|
1251
|
+
*/
|
|
1252
|
+
type EnvironmentType = 'local' | 'cloud';
|
|
1253
|
+
/**
|
|
1254
|
+
* Agent provider interface
|
|
1255
|
+
*
|
|
1256
|
+
* Responsible for:
|
|
1257
|
+
* - Managing agent state/configuration storage
|
|
1258
|
+
* - Creating connections to agents
|
|
1259
|
+
* - Abstracting away transport details (cloud/local)
|
|
1260
|
+
*
|
|
1261
|
+
* The provider.connect() method returns an AgentConnection.
|
|
1262
|
+
* The client wraps the connection in an ActiveSession instance.
|
|
1263
|
+
*
|
|
1264
|
+
* @typeParam C - Connection type used by this provider (e.g., CloudAgentConnection, LocalAgentConnection)
|
|
1265
|
+
*/
|
|
1266
|
+
interface AgentProvider<C extends AgentConnection = AgentConnection> {
|
|
1267
|
+
/**
|
|
1268
|
+
* Create a new agent and return its ID
|
|
1269
|
+
*
|
|
1270
|
+
* @param params - Optional session params (used by LocalAgentProvider to get cwd)
|
|
1271
|
+
* @returns Agent ID (Cloud: UUID, Local: cwd)
|
|
1272
|
+
*/
|
|
1273
|
+
create?(params?: CreateSessionParams$1): Promise<string>;
|
|
1274
|
+
/** Get agent state by ID */
|
|
1275
|
+
get(agentId: string): Promise<AgentState | undefined>;
|
|
1276
|
+
/**
|
|
1277
|
+
* List all agent states with pagination information
|
|
1278
|
+
*
|
|
1279
|
+
* @param options - Optional query parameters for filtering, sorting, and pagination
|
|
1280
|
+
* Cloud providers use these for API queries and return server pagination
|
|
1281
|
+
* Local providers apply client-side filtering and return synthetic pagination
|
|
1282
|
+
* @returns Object containing agents array and pagination info
|
|
1283
|
+
*/
|
|
1284
|
+
list(options?: ListAgentOptions): Promise<ListAgentResult<AgentState>>;
|
|
1285
|
+
/** Connect to an agent and return the connection */
|
|
1286
|
+
connect(agentId: string): Promise<C>;
|
|
1287
|
+
/** Delete an agent by ID */
|
|
1288
|
+
delete(agentId: string): Promise<boolean>;
|
|
1289
|
+
/**
|
|
1290
|
+
* Archive an agent by ID (optional)
|
|
1291
|
+
* Used by CloudAgentProvider for archiving agents
|
|
1292
|
+
*
|
|
1293
|
+
* @param agentId - Agent ID to archive
|
|
1294
|
+
* @returns Object containing the archived agent ID
|
|
1295
|
+
*/
|
|
1296
|
+
archive?(agentId: string): Promise<{
|
|
1297
|
+
id: string;
|
|
1298
|
+
}>;
|
|
1299
|
+
/** Filesystem provider (optional - some providers may not support filesystem operations) */
|
|
1300
|
+
readonly filesystem?: FilesystemProvider;
|
|
1301
|
+
/**
|
|
1302
|
+
* Get available models for a repository (optional)
|
|
1303
|
+
* Implementation varies by provider type
|
|
1304
|
+
* @param repo - Repository identifier
|
|
1305
|
+
* @returns Array of model information
|
|
1306
|
+
*/
|
|
1307
|
+
getModels?(repo: string): Promise<ModelInfo$1[]>;
|
|
1308
|
+
/**
|
|
1309
|
+
* Register sessionId → agentId mapping (optional, used by LocalAgentProvider)
|
|
1310
|
+
* Called after session creation to maintain the mapping for loadSession
|
|
1311
|
+
*
|
|
1312
|
+
* @param sessionId - Session ID returned by connection.createSession()
|
|
1313
|
+
* @param agentId - Agent ID (cwd for Local)
|
|
1314
|
+
*/
|
|
1315
|
+
registerSession?(sessionId: string, agentId: string): void;
|
|
1316
|
+
/**
|
|
1317
|
+
* Open a workspace window (optional, used by LocalAgentProvider)
|
|
1318
|
+
*
|
|
1319
|
+
* @param params - Workspace params including cwd
|
|
1320
|
+
* @returns Response with success status
|
|
1321
|
+
*/
|
|
1322
|
+
openWorkspace?(params: InitializeWorkspaceParams): Promise<InitializeWorkspaceResponse>;
|
|
1323
|
+
/**
|
|
1324
|
+
* Register an event listener
|
|
1325
|
+
* Provider implementations should forward events to the underlying transport
|
|
1326
|
+
*
|
|
1327
|
+
* @param event - Event name
|
|
1328
|
+
* @param handler - Event handler function
|
|
1329
|
+
*/
|
|
1330
|
+
on?(event: string, handler: (...args: any[]) => void): void;
|
|
1331
|
+
/**
|
|
1332
|
+
* Unregister an event listener
|
|
1333
|
+
*
|
|
1334
|
+
* @param event - Event name
|
|
1335
|
+
* @param handler - Event handler function to remove
|
|
1336
|
+
*/
|
|
1337
|
+
off?(event: string, handler: (...args: any[]) => void): void;
|
|
1338
|
+
}
|
|
1339
|
+
/**
|
|
1340
|
+
* AgentClient initialization options
|
|
1341
|
+
*/
|
|
1342
|
+
interface AgentClientOptions {
|
|
1343
|
+
/** Agent provider (required) */
|
|
1344
|
+
provider: AgentProvider;
|
|
1345
|
+
/** Logger instance */
|
|
1346
|
+
logger?: Logger;
|
|
1347
|
+
/** Client capabilities (sent during initialization) */
|
|
1348
|
+
clientCapabilities?: ClientCapabilities$1;
|
|
1349
|
+
/**
|
|
1350
|
+
* 运行环境类型
|
|
1351
|
+
* - 'local': IDE 本地环境
|
|
1352
|
+
* - 'cloud': 云端环境
|
|
1353
|
+
*/
|
|
1354
|
+
environmentType?: EnvironmentType;
|
|
1355
|
+
}
|
|
1356
|
+
/**
|
|
1357
|
+
* Client sessions resource interface
|
|
1358
|
+
* Top-level API for session management
|
|
1359
|
+
*
|
|
1360
|
+
* Key design:
|
|
1361
|
+
* - list() returns sessions with pagination info (mapped from agents)
|
|
1362
|
+
* - create() creates a new session (auto-creates agent and connects)
|
|
1363
|
+
* - load() loads an existing session (finds agent by sessionId and connects)
|
|
1364
|
+
* - archive() archives a session/agent
|
|
1365
|
+
* - initializeWorkspace() initializes a workspace for future sessions
|
|
1366
|
+
*/
|
|
1367
|
+
interface ClientSessionsResource {
|
|
1368
|
+
/**
|
|
1369
|
+
* List all sessions with pagination info
|
|
1370
|
+
* Cloud: Returns server-side filtered/sorted/paginated results
|
|
1371
|
+
* Local: Returns client-side filtered/sorted results (synthetic pagination)
|
|
1372
|
+
*/
|
|
1373
|
+
list(options?: ListAgentOptions): Promise<ListAgentResult<SessionInfo>>;
|
|
1374
|
+
/** Create a new session (auto-creates agent and connects) */
|
|
1375
|
+
create(params: CreateSessionParams$1): Promise<ActiveSession>;
|
|
1376
|
+
/** Load an existing session (finds agent by sessionId and connects) */
|
|
1377
|
+
load(params: LoadSessionParams$1): Promise<ActiveSession>;
|
|
1378
|
+
/**
|
|
1379
|
+
* Archive a session/agent
|
|
1380
|
+
* @param sessionId - Session ID to archive
|
|
1381
|
+
* @returns Object containing the archived session ID
|
|
1382
|
+
*/
|
|
1383
|
+
archive(sessionId: string): Promise<{
|
|
1384
|
+
id: string;
|
|
1385
|
+
}>;
|
|
1386
|
+
/** Initialize a workspace for future sessions */
|
|
1387
|
+
initializeWorkspace(params: InitializeWorkspaceParams): Promise<InitializeWorkspaceResponse>;
|
|
1388
|
+
/** Models resource for getting available models */
|
|
1389
|
+
readonly models: ModelsResource;
|
|
1390
|
+
/** Get current workspaces list */
|
|
1391
|
+
getCurrentWorkspaces(filter?: {
|
|
1392
|
+
activeOnly?: boolean;
|
|
1393
|
+
}): Promise<WorkspaceInfo[]>;
|
|
1394
|
+
/** Subscribe to sessions resource events */
|
|
1395
|
+
on<K extends keyof SessionsResourceEvents>(event: K, handler: SessionsResourceEventHandler<K>): void;
|
|
1396
|
+
/** Unsubscribe from sessions resource events */
|
|
1397
|
+
off<K extends keyof SessionsResourceEvents>(event: K, handler: SessionsResourceEventHandler<K>): void;
|
|
1398
|
+
/** Open a workspace (for LocalAgentProvider) */
|
|
1399
|
+
openWorkspace(params: InitializeWorkspaceParams): Promise<InitializeWorkspaceResponse>;
|
|
1400
|
+
}
|
|
1401
|
+
/**
|
|
1402
|
+
* Workspace information (aligned with FolderSelectResult)
|
|
1403
|
+
*/
|
|
1404
|
+
interface WorkspaceInfo {
|
|
1405
|
+
/** Folder path */
|
|
1406
|
+
path: string;
|
|
1407
|
+
/** Folder display name */
|
|
1408
|
+
label: string;
|
|
1409
|
+
}
|
|
1410
|
+
//#endregion
|
|
1411
|
+
//#region ../agent-provider/lib/common/providers/cloud-agent-provider/api-types.d.ts
|
|
1412
|
+
/**
|
|
1413
|
+
* Response for archive agent
|
|
1414
|
+
* POST /v2/cloudagent/agentmgmt/agents/{id}/archive
|
|
1415
|
+
*/
|
|
1416
|
+
interface ArchiveAgentResponse {
|
|
1417
|
+
/** Agent ID */
|
|
1418
|
+
id: string;
|
|
1419
|
+
}
|
|
1420
|
+
//#endregion
|
|
1421
|
+
//#region ../agent-provider/lib/common/providers/cloud-agent-provider/cloud-provider.d.ts
|
|
1422
|
+
/**
|
|
1423
|
+
* Configuration for CloudAgentProvider
|
|
1424
|
+
*/
|
|
1425
|
+
interface CloudAgentProviderOptions {
|
|
1426
|
+
/** Base endpoint URL for agent management API (e.g., 'https://api.example.com') */
|
|
1427
|
+
endpoint: string;
|
|
1428
|
+
/** Authorization token */
|
|
1429
|
+
authToken?: string;
|
|
1430
|
+
/** Custom headers */
|
|
1431
|
+
headers?: Record<string, string>;
|
|
1432
|
+
/** Logger instance */
|
|
1433
|
+
logger?: Logger;
|
|
1434
|
+
/** Custom fetch implementation */
|
|
1435
|
+
fetch?: typeof fetch;
|
|
1436
|
+
/** Client capabilities (sent during agent initialization) */
|
|
1437
|
+
clientCapabilities?: ClientCapabilities$1;
|
|
1438
|
+
}
|
|
1439
|
+
/**
|
|
1440
|
+
* CloudAgentProvider - Manages cloud-hosted agents via REST API
|
|
1441
|
+
*
|
|
1442
|
+
* API Endpoints:
|
|
1443
|
+
* - POST {endpoint}/v2/cloudagent/agentmgmt/agents - Create new agent
|
|
1444
|
+
* - GET {endpoint}/v2/cloudagent/agentmgmt/agents/{id} - Get agent data
|
|
1445
|
+
* - GET {endpoint}/v2/cloudagent/agentmgmt/agents - List all agents
|
|
1446
|
+
* - POST {endpoint}/v2/cloudagent/agentmgmt/agents/{id}/delete - Delete agent
|
|
1447
|
+
* - GET {endpoint}/v2/cloudagent/agentmgmt/agents/{id}/session - Get agent session (includes sandboxId)
|
|
1448
|
+
* - GET {endpoint}/v2/cloudagent/agentmgmt/models - Get available models
|
|
1449
|
+
*
|
|
1450
|
+
* The provider stores agent endpoint configurations in the cloud backend.
|
|
1451
|
+
* When connect() is called, it creates a CloudAgentConnection to the agent's
|
|
1452
|
+
* endpoint and returns an Agent instance.
|
|
1453
|
+
*
|
|
1454
|
+
* @example
|
|
1455
|
+
* ```typescript
|
|
1456
|
+
* const provider = new CloudAgentProvider({
|
|
1457
|
+
* endpoint: 'https://staging-copilot.tencent.com',
|
|
1458
|
+
* authToken: 'token'
|
|
1459
|
+
* });
|
|
1460
|
+
*
|
|
1461
|
+
* // List all agents (uses default pagination and sorting)
|
|
1462
|
+
* const allAgents = await provider.list();
|
|
1463
|
+
*
|
|
1464
|
+
* // List agents with custom pagination
|
|
1465
|
+
* const page2 = await provider.list({
|
|
1466
|
+
* page: 2,
|
|
1467
|
+
* size: 50
|
|
1468
|
+
* });
|
|
1469
|
+
*
|
|
1470
|
+
* // List agents with filtering
|
|
1471
|
+
* const runningAgents = await provider.list({
|
|
1472
|
+
* filters: [
|
|
1473
|
+
* { field: 'status', value: 'running' }
|
|
1474
|
+
* ]
|
|
1475
|
+
* });
|
|
1476
|
+
*
|
|
1477
|
+
* // List agents with custom sorting
|
|
1478
|
+
* const sortedAgents = await provider.list({
|
|
1479
|
+
* sort: {
|
|
1480
|
+
* orderBy: 'createdAt',
|
|
1481
|
+
* order: 'desc'
|
|
1482
|
+
* }
|
|
1483
|
+
* });
|
|
1484
|
+
*
|
|
1485
|
+
* // List agents created in last 14 days with multiple filters
|
|
1486
|
+
* const recentAgents = await provider.list({
|
|
1487
|
+
* dayRange: 14,
|
|
1488
|
+
* filters: [
|
|
1489
|
+
* { field: 'status', value: 'running,stopped' }
|
|
1490
|
+
* ],
|
|
1491
|
+
* page: 1,
|
|
1492
|
+
* size: 20
|
|
1493
|
+
* });
|
|
1494
|
+
*
|
|
1495
|
+
* // Get agent state
|
|
1496
|
+
* const state = await provider.get('agent-id');
|
|
1497
|
+
*
|
|
1498
|
+
* // Connect to agent
|
|
1499
|
+
* const agent = await provider.connect('agent-id');
|
|
1500
|
+
*
|
|
1501
|
+
* // Use agent
|
|
1502
|
+
* const session = await agent.sessions.create({ cwd: '/workspace' });
|
|
1503
|
+
*
|
|
1504
|
+
* // Get available models
|
|
1505
|
+
* const models = await provider.getModels('my-repo');
|
|
1506
|
+
* ```
|
|
1507
|
+
*/
|
|
1508
|
+
declare class CloudAgentProvider implements AgentProvider<CloudAgentConnection>, FilesystemProvider {
|
|
1509
|
+
private options;
|
|
1510
|
+
private logger?;
|
|
1511
|
+
private fetchImpl;
|
|
1512
|
+
/** Cache for filesystem instances (keyed by agentId) */
|
|
1513
|
+
private filesystemCache;
|
|
1514
|
+
constructor(options: CloudAgentProviderOptions);
|
|
1515
|
+
/**
|
|
1516
|
+
* Get the filesystem provider (returns self)
|
|
1517
|
+
*/
|
|
1518
|
+
get filesystem(): FilesystemProvider;
|
|
1519
|
+
/**
|
|
1520
|
+
* Get filesystem resource for an agent
|
|
1521
|
+
*
|
|
1522
|
+
* Creates or returns cached E2BFilesystem instance for the agent's sandbox.
|
|
1523
|
+
*
|
|
1524
|
+
* @param agentId - Agent ID to get filesystem for
|
|
1525
|
+
* @returns FilesResource instance for the agent's sandbox
|
|
1526
|
+
*/
|
|
1527
|
+
getFilesystem(agentId: string): Promise<FilesResource>;
|
|
1528
|
+
/**
|
|
1529
|
+
* Get sandbox information from backend
|
|
1530
|
+
*
|
|
1531
|
+
* Uses GET {endpoint}/v2/cloudagent/agentmgmt/agents/{agentId}/session
|
|
1532
|
+
* to retrieve sandbox information. Extracts sandboxId from the session response
|
|
1533
|
+
* and constructs the apiUrl for E2B proxy.
|
|
1534
|
+
*
|
|
1535
|
+
* @param agentId - Agent ID
|
|
1536
|
+
* @returns E2B Sandbox connection information with sandboxId and apiUrl
|
|
1537
|
+
*/
|
|
1538
|
+
private getSandboxInfo;
|
|
1539
|
+
/**
|
|
1540
|
+
* Get agent state by ID
|
|
1541
|
+
*/
|
|
1542
|
+
get(agentId: string): Promise<CloudAgentState | undefined>;
|
|
1543
|
+
/**
|
|
1544
|
+
* List all agent states with pagination information
|
|
1545
|
+
*
|
|
1546
|
+
* @param options - Optional query parameters for filtering, sorting, and pagination
|
|
1547
|
+
* @returns Object containing agents array and pagination info
|
|
1548
|
+
*/
|
|
1549
|
+
list(options?: ListAgentOptions): Promise<ListAgentResult<CloudAgentState>>;
|
|
1550
|
+
/**
|
|
1551
|
+
* Create a new agent
|
|
1552
|
+
* POST {endpoint}/v2/cloudagent/agentmgmt/agents
|
|
1553
|
+
*/
|
|
1554
|
+
create(): Promise<string>;
|
|
1555
|
+
/**
|
|
1556
|
+
* Connect to an agent and return the connection
|
|
1557
|
+
*
|
|
1558
|
+
* This method:
|
|
1559
|
+
* 1. Fetches the agent configuration from the backend
|
|
1560
|
+
* 2. Creates a CloudAgentConnection to the agent's endpoint
|
|
1561
|
+
* 3. Connects and initializes the connection
|
|
1562
|
+
* 4. Returns the connected CloudAgentConnection
|
|
1563
|
+
*/
|
|
1564
|
+
connect(agentId: string): Promise<CloudAgentConnection>;
|
|
1565
|
+
/**
|
|
1566
|
+
* Delete an agent by ID
|
|
1567
|
+
* POST {endpoint}/v2/cloudagent/agentmgmt/agents/{agentId}/delete
|
|
1568
|
+
*/
|
|
1569
|
+
delete(agentId: string): Promise<boolean>;
|
|
1570
|
+
/**
|
|
1571
|
+
* Archive an agent by ID
|
|
1572
|
+
* POST {endpoint}/v2/cloudagent/agentmgmt/agents/{agentId}/archive
|
|
1573
|
+
*
|
|
1574
|
+
* @param agentId - Agent ID to archive
|
|
1575
|
+
* @returns ArchiveAgentResponse containing the archived agent ID
|
|
1576
|
+
*
|
|
1577
|
+
* @example
|
|
1578
|
+
* ```typescript
|
|
1579
|
+
* const result = await provider.archive('agent-123');
|
|
1580
|
+
* console.log('Archived agent:', result.id);
|
|
1581
|
+
* ```
|
|
1582
|
+
*/
|
|
1583
|
+
archive(agentId: string): Promise<ArchiveAgentResponse>;
|
|
1584
|
+
/**
|
|
1585
|
+
* Get available models for a repository
|
|
1586
|
+
*
|
|
1587
|
+
* GET {endpoint}/v2/cloudagent/agentmgmt/models?repo={repo}
|
|
1588
|
+
*
|
|
1589
|
+
* @param repo - Repository identifier
|
|
1590
|
+
* @returns Array of model names (backend only provides names, not full ModelInfo)
|
|
1591
|
+
*/
|
|
1592
|
+
getModels(repo: string): Promise<ModelInfo$1[]>;
|
|
1593
|
+
private toAgentState;
|
|
1594
|
+
private request;
|
|
1595
|
+
}
|
|
1596
|
+
//#endregion
|
|
1597
|
+
//#region ../agent-provider/lib/common/providers/cloud-agent-provider/e2b-filesystem.d.ts
|
|
1598
|
+
/**
|
|
1599
|
+
* E2B Filesystem Implementation
|
|
1600
|
+
*
|
|
1601
|
+
* Wraps E2B Sandbox SDK's filesystem operations to implement FilesResource interface.
|
|
1602
|
+
*
|
|
1603
|
+
* @example
|
|
1604
|
+
* ```typescript
|
|
1605
|
+
* const fs = await E2BFilesystem.connect({
|
|
1606
|
+
* sandboxId: 'sandbox-123',
|
|
1607
|
+
* apiKey: 'e2b_xxx'
|
|
1608
|
+
* });
|
|
1609
|
+
*
|
|
1610
|
+
* // Read/write files
|
|
1611
|
+
* await fs.write('/test.txt', 'Hello World');
|
|
1612
|
+
* const content = await fs.read('/test.txt');
|
|
1613
|
+
*
|
|
1614
|
+
* // Watch for changes
|
|
1615
|
+
* const handle = await fs.watchDir('/workspace', (event) => {
|
|
1616
|
+
* console.log('File changed:', event);
|
|
1617
|
+
* });
|
|
1618
|
+
* ```
|
|
1619
|
+
*/
|
|
1620
|
+
declare class E2BFilesystem implements FilesResource {
|
|
1621
|
+
private sandbox;
|
|
1622
|
+
constructor(sandbox: Sandbox);
|
|
1623
|
+
/**
|
|
1624
|
+
* Connect to an E2B Sandbox and create filesystem instance
|
|
1625
|
+
*/
|
|
1626
|
+
static connect(info: E2BSandboxConnectionInfo): Promise<E2BFilesystem>;
|
|
1627
|
+
/**
|
|
1628
|
+
* Get the underlying E2B Sandbox instance
|
|
1629
|
+
*/
|
|
1630
|
+
getSandbox(): Sandbox;
|
|
1631
|
+
read(path: string, opts?: FilesystemRequestOpts & {
|
|
1632
|
+
format?: 'text';
|
|
1633
|
+
}): Promise<string>;
|
|
1634
|
+
read(path: string, opts: FilesystemRequestOpts & {
|
|
1635
|
+
format: 'bytes';
|
|
1636
|
+
}): Promise<Uint8Array>;
|
|
1637
|
+
read(path: string, opts: FilesystemRequestOpts & {
|
|
1638
|
+
format: 'blob';
|
|
1639
|
+
}): Promise<Blob>;
|
|
1640
|
+
read(path: string, opts: FilesystemRequestOpts & {
|
|
1641
|
+
format: 'stream';
|
|
1642
|
+
}): Promise<ReadableStream<Uint8Array>>;
|
|
1643
|
+
write(path: string, data: string | ArrayBuffer | Blob | ReadableStream, opts?: FilesystemRequestOpts): Promise<WriteInfo>;
|
|
1644
|
+
write(files: WriteEntry[], opts?: FilesystemRequestOpts): Promise<WriteInfo[]>;
|
|
1645
|
+
list(path: string, opts?: FilesystemListOpts): Promise<EntryInfo$1[]>;
|
|
1646
|
+
exists(path: string, opts?: FilesystemRequestOpts): Promise<boolean>;
|
|
1647
|
+
makeDir(path: string, opts?: FilesystemRequestOpts): Promise<boolean>;
|
|
1648
|
+
remove(path: string, opts?: FilesystemRequestOpts): Promise<void>;
|
|
1649
|
+
rename(oldPath: string, newPath: string, opts?: FilesystemRequestOpts): Promise<EntryInfo$1>;
|
|
1650
|
+
getInfo(path: string, opts?: FilesystemRequestOpts): Promise<EntryInfo$1>;
|
|
1651
|
+
watchDir(path: string, onEvent: (event: FilesystemEvent$1) => void | Promise<void>, opts?: WatchOpts & {
|
|
1652
|
+
onExit?: (err?: Error) => void | Promise<void>;
|
|
1653
|
+
}): Promise<WatchHandle>;
|
|
1654
|
+
}
|
|
1655
|
+
//#endregion
|
|
1656
|
+
//#region ../agent-provider/lib/common/client/client.d.ts
|
|
1657
|
+
/**
|
|
1658
|
+
* AgentClient - Session-centric client
|
|
1659
|
+
*
|
|
1660
|
+
* Provides a session-centric API that internally manages agents.
|
|
1661
|
+
* Users interact with sessions; the agent lifecycle is handled internally.
|
|
1662
|
+
*
|
|
1663
|
+
* @example
|
|
1664
|
+
* ```typescript
|
|
1665
|
+
* // Create client with a provider
|
|
1666
|
+
* const provider = new CloudAgentProvider({
|
|
1667
|
+
* endpoint: 'https://api.example.com',
|
|
1668
|
+
* authToken: 'token'
|
|
1669
|
+
* });
|
|
1670
|
+
*
|
|
1671
|
+
* const client = new AgentClient({
|
|
1672
|
+
* provider,
|
|
1673
|
+
* logger: console
|
|
1674
|
+
* });
|
|
1675
|
+
*
|
|
1676
|
+
* // List all sessions
|
|
1677
|
+
* const sessions = await client.sessions.list();
|
|
1678
|
+
*
|
|
1679
|
+
* // Create new session (auto-creates agent and connects)
|
|
1680
|
+
* const session = await client.sessions.create({ cwd: '/workspace' });
|
|
1681
|
+
* console.log(session.agentState.status); // agent status
|
|
1682
|
+
* console.log(session.agentState.id); // agent ID
|
|
1683
|
+
*
|
|
1684
|
+
* // Send prompt
|
|
1685
|
+
* await session.prompts.send({ content: 'Hello' });
|
|
1686
|
+
*
|
|
1687
|
+
* // Get available models
|
|
1688
|
+
* const models = await client.sessions.models.list('my-repo');
|
|
1689
|
+
*
|
|
1690
|
+
* // Use 'using' keyword for automatic cleanup
|
|
1691
|
+
* {
|
|
1692
|
+
* using session = await client.sessions.create({ cwd: '/workspace' });
|
|
1693
|
+
* // ... use session
|
|
1694
|
+
* } // session automatically disposed
|
|
1695
|
+
*
|
|
1696
|
+
* // Or manually disconnect
|
|
1697
|
+
* session.disconnect();
|
|
1698
|
+
*
|
|
1699
|
+
* // Load existing session
|
|
1700
|
+
* const loadedSession = await client.sessions.load({
|
|
1701
|
+
* sessionId: 'xxx',
|
|
1702
|
+
* cwd: '/workspace'
|
|
1703
|
+
* });
|
|
1704
|
+
* ```
|
|
1705
|
+
*/
|
|
1706
|
+
declare class AgentClient {
|
|
1707
|
+
private logger?;
|
|
1708
|
+
private provider;
|
|
1709
|
+
private sessionManager;
|
|
1710
|
+
/**
|
|
1711
|
+
* Sessions resource namespace (primary API entry point)
|
|
1712
|
+
*/
|
|
1713
|
+
readonly sessions: ClientSessionsResource;
|
|
1714
|
+
/**
|
|
1715
|
+
* 运行环境类型
|
|
1716
|
+
* - 'local': IDE 本地环境
|
|
1717
|
+
* - 'cloud': 云端环境
|
|
1718
|
+
*/
|
|
1719
|
+
readonly environmentType: 'local' | 'cloud';
|
|
1720
|
+
constructor(options: AgentClientOptions);
|
|
1721
|
+
private createSessionsResource;
|
|
1722
|
+
private createModelsResource;
|
|
1723
|
+
/**
|
|
1724
|
+
* Dispose the client
|
|
1725
|
+
*
|
|
1726
|
+
* Note: Active sessions are not automatically disposed.
|
|
1727
|
+
* The caller is responsible for disconnecting sessions they created.
|
|
1728
|
+
*/
|
|
1729
|
+
dispose(): void;
|
|
1730
|
+
}
|
|
1731
|
+
//#endregion
|
|
1732
|
+
//#region ../agent-provider/lib/common/client/session.d.ts
|
|
1733
|
+
/**
|
|
1734
|
+
* Filesystem getter function type
|
|
1735
|
+
* Returns a FilesResource instance for file operations
|
|
1736
|
+
*/
|
|
1737
|
+
type FilesystemGetter = () => Promise<FilesResource>;
|
|
1738
|
+
/**
|
|
1739
|
+
* Options for creating an ActiveSessionImpl instance
|
|
1740
|
+
*/
|
|
1741
|
+
interface ActiveSessionImplOptions {
|
|
1742
|
+
/** Logger instance */
|
|
1743
|
+
logger?: Logger;
|
|
1744
|
+
/** Getter function for filesystem resource (provided by SessionManager) */
|
|
1745
|
+
getFilesystem?: FilesystemGetter;
|
|
1746
|
+
}
|
|
1747
|
+
/**
|
|
1748
|
+
* ActiveSessionImpl - Implements the ActiveSession interface
|
|
1749
|
+
*
|
|
1750
|
+
* This class wraps an AgentConnection and provides the session-centric API.
|
|
1751
|
+
* It is created by SessionManager when creating or loading sessions.
|
|
1752
|
+
*
|
|
1753
|
+
* @example
|
|
1754
|
+
* ```typescript
|
|
1755
|
+
* // Created by client.sessions.new() or client.sessions.load()
|
|
1756
|
+
* const session = await client.sessions.new({ cwd: '/workspace' });
|
|
1757
|
+
*
|
|
1758
|
+
* // Access agent state
|
|
1759
|
+
* console.log(session.agentState.status);
|
|
1760
|
+
*
|
|
1761
|
+
* // Send prompt
|
|
1762
|
+
* const response = await session.prompts.send({ content: 'Hello!' });
|
|
1763
|
+
*
|
|
1764
|
+
* // Cleanup
|
|
1765
|
+
* session.disconnect();
|
|
1766
|
+
* ```
|
|
1767
|
+
*/
|
|
1768
|
+
declare class ActiveSessionImpl implements ActiveSession {
|
|
1769
|
+
private _id;
|
|
1770
|
+
private _agentId;
|
|
1771
|
+
private _availableModes?;
|
|
1772
|
+
private _currentMode?;
|
|
1773
|
+
private _availableCommands;
|
|
1774
|
+
private logger?;
|
|
1775
|
+
private connection;
|
|
1776
|
+
private _getFilesystem?;
|
|
1777
|
+
private listeners;
|
|
1778
|
+
private onceListeners;
|
|
1779
|
+
/**
|
|
1780
|
+
* Agent operations namespace
|
|
1781
|
+
*/
|
|
1782
|
+
readonly agent: SessionAgentOperations;
|
|
1783
|
+
/**
|
|
1784
|
+
* Prompts resource namespace
|
|
1785
|
+
*/
|
|
1786
|
+
readonly prompts: PromptsResource;
|
|
1787
|
+
/**
|
|
1788
|
+
* Artifacts resource namespace
|
|
1789
|
+
*/
|
|
1790
|
+
readonly artifacts: ArtifactsResource;
|
|
1791
|
+
/**
|
|
1792
|
+
* Files resource namespace (lazily loaded via getter)
|
|
1793
|
+
*/
|
|
1794
|
+
readonly files: FilesResource;
|
|
1795
|
+
/**
|
|
1796
|
+
* Create an ActiveSessionImpl instance
|
|
1797
|
+
*
|
|
1798
|
+
* @param sessionId - Session ID
|
|
1799
|
+
* @param agentId - Agent ID
|
|
1800
|
+
* @param connection - Already connected AgentConnection
|
|
1801
|
+
* @param options - Additional options
|
|
1802
|
+
*/
|
|
1803
|
+
constructor(sessionId: string, agentId: string, connection: AgentConnection, options?: ActiveSessionImplOptions);
|
|
1804
|
+
/**
|
|
1805
|
+
* Session ID
|
|
1806
|
+
*/
|
|
1807
|
+
get id(): string;
|
|
1808
|
+
/**
|
|
1809
|
+
* Agent ID
|
|
1810
|
+
*/
|
|
1811
|
+
get agentId(): string;
|
|
1812
|
+
/**
|
|
1813
|
+
* Agent state (live connection state)
|
|
1814
|
+
* Returns LocalAgentState or CloudAgentState based on transport type
|
|
1815
|
+
*/
|
|
1816
|
+
get agentState(): AgentState;
|
|
1817
|
+
/**
|
|
1818
|
+
* Get agent capabilities (available after connection)
|
|
1819
|
+
*/
|
|
1820
|
+
get capabilities(): AgentCapabilities | undefined;
|
|
1821
|
+
/**
|
|
1822
|
+
* Available session modes
|
|
1823
|
+
*/
|
|
1824
|
+
get availableModes(): SessionMode[] | undefined;
|
|
1825
|
+
/**
|
|
1826
|
+
* Current session mode
|
|
1827
|
+
*/
|
|
1828
|
+
get currentMode(): string | undefined;
|
|
1829
|
+
/**
|
|
1830
|
+
* Available slash commands
|
|
1831
|
+
*
|
|
1832
|
+
* When Agent sends available_commands_update, this list is automatically updated.
|
|
1833
|
+
* Commands can be accessed directly without waiting for events.
|
|
1834
|
+
*/
|
|
1835
|
+
get availableCommands(): AvailableCommand[];
|
|
1836
|
+
/**
|
|
1837
|
+
* Check if the session is active
|
|
1838
|
+
*/
|
|
1839
|
+
get isActive(): boolean;
|
|
1840
|
+
/**
|
|
1841
|
+
* Set session modes (called after create/load)
|
|
1842
|
+
*/
|
|
1843
|
+
setModes(availableModes?: SessionMode[], currentMode?: string): void;
|
|
1844
|
+
private createAgentOperations;
|
|
1845
|
+
private createPromptsResource;
|
|
1846
|
+
private createArtifactsResource;
|
|
1847
|
+
/**
|
|
1848
|
+
* Create files resource with lazy-loaded filesystem
|
|
1849
|
+
*
|
|
1850
|
+
* The filesystem is lazily loaded on first use to avoid unnecessary
|
|
1851
|
+
* connections to the sandbox. The actual filesystem instance is obtained
|
|
1852
|
+
* via the getter function provided by SessionManager.
|
|
1853
|
+
*/
|
|
1854
|
+
private createFilesResource;
|
|
1855
|
+
/**
|
|
1856
|
+
* Resolve a permission request
|
|
1857
|
+
*/
|
|
1858
|
+
resolvePermission(requestId: string, optionId: string): boolean;
|
|
1859
|
+
/**
|
|
1860
|
+
* Reject a permission request
|
|
1861
|
+
*/
|
|
1862
|
+
rejectPermission(requestId: string, reason?: string): boolean;
|
|
1863
|
+
/**
|
|
1864
|
+
* Answer a question request with user's selections
|
|
1865
|
+
*/
|
|
1866
|
+
answerQuestion(toolCallId: string, answers: QuestionInputData): boolean;
|
|
1867
|
+
/**
|
|
1868
|
+
* Cancel a question request
|
|
1869
|
+
*/
|
|
1870
|
+
cancelQuestion(toolCallId: string, reason?: string): boolean;
|
|
1871
|
+
/**
|
|
1872
|
+
* Callback for tool operations (skip or cancel)
|
|
1873
|
+
* @param toolCallId Tool call ID
|
|
1874
|
+
* @param toolName Tool name
|
|
1875
|
+
* @param action Action to perform ('skip' or 'cancel')
|
|
1876
|
+
*/
|
|
1877
|
+
toolCallback(toolCallId: string, toolName: string, action: 'skip' | 'cancel'): Promise<{
|
|
1878
|
+
success: boolean;
|
|
1879
|
+
error?: string;
|
|
1880
|
+
}>;
|
|
1881
|
+
/**
|
|
1882
|
+
* Set the current session mode
|
|
1883
|
+
*
|
|
1884
|
+
* @param modeId - The mode ID to switch to (must be in availableModes)
|
|
1885
|
+
* @throws Error if modeId is not in availableModes or connection fails
|
|
1886
|
+
*
|
|
1887
|
+
* @example
|
|
1888
|
+
* ```typescript
|
|
1889
|
+
* // Switch to 'code' mode
|
|
1890
|
+
* await session.setMode('code');
|
|
1891
|
+
*
|
|
1892
|
+
* // Switch to 'architect' mode
|
|
1893
|
+
* await session.setMode('architect');
|
|
1894
|
+
* ```
|
|
1895
|
+
*/
|
|
1896
|
+
setMode(modeId: string): Promise<void>;
|
|
1897
|
+
/**
|
|
1898
|
+
* Set the current session model
|
|
1899
|
+
*
|
|
1900
|
+
* @param modelId - The model ID to switch to
|
|
1901
|
+
* @example
|
|
1902
|
+
* ```typescript
|
|
1903
|
+
* // Switch to Claude Sonnet 4
|
|
1904
|
+
* await session.setSessionModel('claude-sonnet-4-20250514');
|
|
1905
|
+
*
|
|
1906
|
+
* // Switch to GPT-4o
|
|
1907
|
+
* await session.setSessionModel('gpt-4o');
|
|
1908
|
+
* ```
|
|
1909
|
+
*/
|
|
1910
|
+
setSessionModel(modelId: string): Promise<void>;
|
|
1911
|
+
/**
|
|
1912
|
+
* Subscribe to session events
|
|
1913
|
+
*/
|
|
1914
|
+
on<K extends keyof SessionEvents>(event: K, handler: SessionEventHandler<K>): this;
|
|
1915
|
+
/**
|
|
1916
|
+
* Unsubscribe from session events
|
|
1917
|
+
*/
|
|
1918
|
+
off<K extends keyof SessionEvents>(event: K, handler: SessionEventHandler<K>): this;
|
|
1919
|
+
/**
|
|
1920
|
+
* Subscribe to a session event once
|
|
1921
|
+
*/
|
|
1922
|
+
once<K extends keyof SessionEvents>(event: K, handler: SessionEventHandler<K>): this;
|
|
1923
|
+
/**
|
|
1924
|
+
* Emit an event to all registered listeners
|
|
1925
|
+
*/
|
|
1926
|
+
private emit;
|
|
1927
|
+
/**
|
|
1928
|
+
* Remove all listeners for an event
|
|
1929
|
+
*/
|
|
1930
|
+
private removeAllListeners;
|
|
1931
|
+
/**
|
|
1932
|
+
* Disconnect from the session/agent
|
|
1933
|
+
*/
|
|
1934
|
+
disconnect(): void;
|
|
1935
|
+
/**
|
|
1936
|
+
* Symbol.dispose for 'using' keyword support
|
|
1937
|
+
* Automatically disconnects and cleans up when session goes out of scope
|
|
1938
|
+
*
|
|
1939
|
+
* @example
|
|
1940
|
+
* ```typescript
|
|
1941
|
+
* {
|
|
1942
|
+
* using session = await client.sessions.new({ cwd: '/workspace' });
|
|
1943
|
+
* // ... use session
|
|
1944
|
+
* } // session automatically disposed
|
|
1945
|
+
* ```
|
|
1946
|
+
*/
|
|
1947
|
+
[Symbol.dispose](): void;
|
|
1948
|
+
private getConnectionOrThrow;
|
|
1949
|
+
private setupConnectionEvents;
|
|
1950
|
+
private mapPromptResponse;
|
|
1951
|
+
}
|
|
1952
|
+
//#endregion
|
|
1953
|
+
//#region ../agent-provider/lib/common/client/session-manager.d.ts
|
|
1954
|
+
/**
|
|
1955
|
+
* Options for creating a SessionManager instance
|
|
1956
|
+
*/
|
|
1957
|
+
interface SessionManagerOptions {
|
|
1958
|
+
/** Agent provider (required) */
|
|
1959
|
+
provider: AgentProvider;
|
|
1960
|
+
/** Logger instance */
|
|
1961
|
+
logger?: Logger;
|
|
1962
|
+
}
|
|
1963
|
+
/**
|
|
1964
|
+
* SessionManager - Session lifecycle management
|
|
1965
|
+
*
|
|
1966
|
+
* This class manages the relationship between sessions and agents.
|
|
1967
|
+
* Since the backend is agent-centric, SessionManager handles the mapping:
|
|
1968
|
+
* - Sessions are views over agents
|
|
1969
|
+
* - sessionId may equal agentId in simple cases
|
|
1970
|
+
*
|
|
1971
|
+
* Features:
|
|
1972
|
+
* - Session caching: reuses existing ActiveSession instances
|
|
1973
|
+
* - Automatic cleanup on session disconnect
|
|
1974
|
+
*
|
|
1975
|
+
* @example
|
|
1976
|
+
* ```typescript
|
|
1977
|
+
* const manager = new SessionManager({ provider, logger });
|
|
1978
|
+
*
|
|
1979
|
+
* // List sessions
|
|
1980
|
+
* const sessions = await manager.listSessions();
|
|
1981
|
+
*
|
|
1982
|
+
* // Create new session
|
|
1983
|
+
* const session = await manager.createSession({ cwd: '/workspace' });
|
|
1984
|
+
*
|
|
1985
|
+
* // Load existing session (returns cached instance if available)
|
|
1986
|
+
* const loaded = await manager.loadSession({ sessionId: 'xxx', cwd: '/workspace' });
|
|
1987
|
+
* ```
|
|
1988
|
+
*/
|
|
1989
|
+
declare class SessionManager {
|
|
1990
|
+
private provider;
|
|
1991
|
+
private logger?;
|
|
1992
|
+
constructor(options: SessionManagerOptions);
|
|
1993
|
+
/**
|
|
1994
|
+
* List all sessions with pagination info (mapped from agents)
|
|
1995
|
+
*
|
|
1996
|
+
* Each agent maps to a session. The sessionId is derived from the agent.
|
|
1997
|
+
* Cloud: Returns server-side filtered/sorted/paginated results
|
|
1998
|
+
* Local: Returns client-side filtered/sorted results (synthetic pagination)
|
|
1999
|
+
*
|
|
2000
|
+
* @param options - Optional query parameters for filtering, sorting, and pagination
|
|
2001
|
+
*/
|
|
2002
|
+
listSessions(options?: ListAgentOptions): Promise<ListAgentResult<SessionInfo>>;
|
|
2003
|
+
/**
|
|
2004
|
+
* Create a new session
|
|
2005
|
+
*
|
|
2006
|
+
* Steps:
|
|
2007
|
+
* 1. Create new agent (if provider supports it) or use existing
|
|
2008
|
+
* 2. Connect to agent
|
|
2009
|
+
* 3. Call ACP newSession
|
|
2010
|
+
* 4. Register session mapping (for LocalAgentProvider)
|
|
2011
|
+
* 5. Return ActiveSession instance
|
|
2012
|
+
*/
|
|
2013
|
+
createSession(params: CreateSessionParams$1): Promise<ActiveSession>;
|
|
2014
|
+
/**
|
|
2015
|
+
* Load an existing session
|
|
2016
|
+
*
|
|
2017
|
+
* Steps:
|
|
2018
|
+
* 1. Check cache for existing session
|
|
2019
|
+
* 2. Find agent by sessionId (sessionId === agentId in current design)
|
|
2020
|
+
* 3. Connect to agent
|
|
2021
|
+
* 4. Call ACP loadSession
|
|
2022
|
+
* 5. Return ActiveSession instance (cached)
|
|
2023
|
+
*/
|
|
2024
|
+
loadSession(params: LoadSessionParams$1): Promise<ActiveSession>;
|
|
2025
|
+
}
|
|
2026
|
+
//#endregion
|
|
2027
|
+
//#region ../agent-provider/lib/backend/agent-api.d.ts
|
|
2028
|
+
/**
|
|
2029
|
+
* Cloud Agent API 类型定义
|
|
2030
|
+
*
|
|
2031
|
+
* 定义与 /v2/cloudagent/agentmgmt/agents API 相关的数据结构
|
|
2032
|
+
*/
|
|
2033
|
+
/**
|
|
2034
|
+
* 过滤条件
|
|
2035
|
+
*/
|
|
2036
|
+
interface AgentFilter {
|
|
2037
|
+
/** 过滤字段 */
|
|
2038
|
+
field: string;
|
|
2039
|
+
/** 过滤值 */
|
|
2040
|
+
value: string;
|
|
2041
|
+
}
|
|
2042
|
+
/**
|
|
2043
|
+
* 排序条件
|
|
2044
|
+
*/
|
|
2045
|
+
interface SortCondition {
|
|
2046
|
+
/** 排序方向: asc | desc */
|
|
2047
|
+
order: 'asc' | 'desc';
|
|
2048
|
+
/** 排序字段 */
|
|
2049
|
+
orderBy: string;
|
|
2050
|
+
}
|
|
2051
|
+
/**
|
|
2052
|
+
* 获取 Agent 列表请求参数
|
|
2053
|
+
*/
|
|
2054
|
+
interface GetAgentsRequest {
|
|
2055
|
+
/** 时间范围(天) */
|
|
2056
|
+
dayRange?: number;
|
|
2057
|
+
/** 过滤条件列表 */
|
|
2058
|
+
filters?: AgentFilter[];
|
|
2059
|
+
/** 页码 */
|
|
2060
|
+
page?: number;
|
|
2061
|
+
/** 每页大小 */
|
|
2062
|
+
size?: number;
|
|
2063
|
+
/** 排序条件 */
|
|
2064
|
+
sort?: SortCondition;
|
|
2065
|
+
}
|
|
2066
|
+
/**
|
|
2067
|
+
* Agent 来源信息
|
|
2068
|
+
*/
|
|
2069
|
+
interface CloudAgentSource {
|
|
2070
|
+
/** 提供商: github, gitlab 等 */
|
|
2071
|
+
provider: string;
|
|
2072
|
+
/** 分支/引用 */
|
|
2073
|
+
ref: string;
|
|
2074
|
+
/** 仓库路径 */
|
|
2075
|
+
repository: string;
|
|
2076
|
+
}
|
|
2077
|
+
/**
|
|
2078
|
+
* Agent 目标信息
|
|
2079
|
+
*/
|
|
2080
|
+
interface CloudAgentTarget$1 {
|
|
2081
|
+
/** 是否自动创建 PR */
|
|
2082
|
+
autoCreatePr: boolean;
|
|
2083
|
+
/** 分支名称 */
|
|
2084
|
+
branchName?: string;
|
|
2085
|
+
/** PR URL */
|
|
2086
|
+
prUrl?: string;
|
|
2087
|
+
/** Agent URL */
|
|
2088
|
+
url?: string;
|
|
2089
|
+
}
|
|
2090
|
+
/**
|
|
2091
|
+
* Agent 状态
|
|
2092
|
+
*/
|
|
2093
|
+
type CloudAgentStatus = 'CREATING' | 'RUNNING' | 'STOPPED' | 'FAILED' | 'DELETING';
|
|
2094
|
+
/**
|
|
2095
|
+
* Agent 可见性
|
|
2096
|
+
*/
|
|
2097
|
+
type CloudAgentVisibility$1 = 'PRIVATE' | 'PUBLIC' | 'TEAM';
|
|
2098
|
+
/**
|
|
2099
|
+
* Cloud Agent 信息
|
|
2100
|
+
* 重命名为 CloudAgent 以避免与 ACP SDK 的 Agent 类型冲突
|
|
2101
|
+
*/
|
|
2102
|
+
interface CloudAgent {
|
|
2103
|
+
/** 创建时间 (ISO 8601) */
|
|
2104
|
+
createdAt: string;
|
|
2105
|
+
/** Agent ID */
|
|
2106
|
+
id: string;
|
|
2107
|
+
/** Agent 名称 */
|
|
2108
|
+
name: string;
|
|
2109
|
+
/** 来源信息 */
|
|
2110
|
+
source: CloudAgentSource;
|
|
2111
|
+
/** 状态 */
|
|
2112
|
+
status: CloudAgentStatus;
|
|
2113
|
+
/** 摘要 */
|
|
2114
|
+
summary?: string;
|
|
2115
|
+
/** 目标信息 */
|
|
2116
|
+
target: CloudAgentTarget$1;
|
|
2117
|
+
/** 可见性 */
|
|
2118
|
+
visibility: CloudAgentVisibility$1;
|
|
2119
|
+
}
|
|
2120
|
+
/**
|
|
2121
|
+
* 分页信息
|
|
2122
|
+
*/
|
|
2123
|
+
interface Pagination {
|
|
2124
|
+
/** 是否有下一页 */
|
|
2125
|
+
hasNext: boolean;
|
|
2126
|
+
/** 是否有上一页 */
|
|
2127
|
+
hasPrev: boolean;
|
|
2128
|
+
/** 当前页码 */
|
|
2129
|
+
page: number;
|
|
2130
|
+
/** 每页大小 */
|
|
2131
|
+
size: number;
|
|
2132
|
+
/** 总数 */
|
|
2133
|
+
total: number;
|
|
2134
|
+
/** 总页数 */
|
|
2135
|
+
totalPages: number;
|
|
2136
|
+
}
|
|
2137
|
+
/**
|
|
2138
|
+
* 获取 Agent 列表响应
|
|
2139
|
+
*/
|
|
2140
|
+
interface GetAgentsResponse {
|
|
2141
|
+
/** Agent 列表 */
|
|
2142
|
+
agents: CloudAgent[];
|
|
2143
|
+
/** 分页信息 */
|
|
2144
|
+
pagination: Pagination;
|
|
2145
|
+
}
|
|
2146
|
+
//#endregion
|
|
2147
|
+
//#region ../agent-provider/lib/backend/types.d.ts
|
|
2148
|
+
/**
|
|
2149
|
+
* 账号版本类型
|
|
2150
|
+
*/
|
|
2151
|
+
type Edition = 'pro' | 'personal' | 'ultimate' | 'exclusive';
|
|
2152
|
+
/**
|
|
2153
|
+
* 版本展示类型(用于 UI 展示)
|
|
2154
|
+
* - free: 免费版(个人版未订阅 Pro)
|
|
2155
|
+
* - pro: Pro 版(个人版已订阅 Pro)
|
|
2156
|
+
* - ultimate: 旗舰版(团队版)
|
|
2157
|
+
* - exclusive: 专享版(企业版)
|
|
2158
|
+
*/
|
|
2159
|
+
type EditionDisplayType = 'free' | 'pro' | 'ultimate' | 'exclusive';
|
|
2160
|
+
/**
|
|
2161
|
+
* 部署状态
|
|
2162
|
+
*/
|
|
2163
|
+
interface DeployStatus {
|
|
2164
|
+
statusCode: number;
|
|
2165
|
+
statusMsg: string;
|
|
2166
|
+
detailMsg: string;
|
|
2167
|
+
}
|
|
2168
|
+
/**
|
|
2169
|
+
* 套餐代码
|
|
2170
|
+
*/
|
|
2171
|
+
type CommodityCode = 'free' | 'proMon' | 'gift' | 'activity' | 'proYear' | 'freeMon' | 'extra';
|
|
2172
|
+
/**
|
|
2173
|
+
* 账号套餐信息
|
|
2174
|
+
*/
|
|
2175
|
+
interface AccountPlan {
|
|
2176
|
+
/** 是否是 Pro 版本 */
|
|
2177
|
+
isPro: boolean;
|
|
2178
|
+
/** 到期时间戳 */
|
|
2179
|
+
expireAt?: string | number;
|
|
2180
|
+
/** 自动续费标志 0-关闭 1-开启 */
|
|
2181
|
+
renewFlag: 0 | 1;
|
|
2182
|
+
/** 套餐代码 */
|
|
2183
|
+
PackageCode?: CommodityCode;
|
|
2184
|
+
/** 套餐名称 */
|
|
2185
|
+
name: string;
|
|
2186
|
+
}
|
|
2187
|
+
/**
|
|
2188
|
+
* 账号信息
|
|
2189
|
+
*/
|
|
2190
|
+
interface Account {
|
|
2191
|
+
/** 用户ID(唯一标识) */
|
|
2192
|
+
uid: string;
|
|
2193
|
+
/** 用户昵称 */
|
|
2194
|
+
nickname: string;
|
|
2195
|
+
/** 版本类型 */
|
|
2196
|
+
type: Edition;
|
|
2197
|
+
/** 版本展示类型(用于 UI 展示) */
|
|
2198
|
+
editionType: EditionDisplayType;
|
|
2199
|
+
/** 是否最后一次登录 */
|
|
2200
|
+
lastLogin: boolean;
|
|
2201
|
+
/** 企业ID */
|
|
2202
|
+
enterpriseId?: string;
|
|
2203
|
+
/** 企业名称 */
|
|
2204
|
+
enterpriseName?: string;
|
|
2205
|
+
/** 企业LOGO */
|
|
2206
|
+
enterpriseLogo?: string;
|
|
2207
|
+
/** 企业内用户名 */
|
|
2208
|
+
enterpriseUserName?: string;
|
|
2209
|
+
/** 插件是否启用 */
|
|
2210
|
+
pluginEnabled?: boolean;
|
|
2211
|
+
/** 部署状态 */
|
|
2212
|
+
deployStatus?: DeployStatus;
|
|
2213
|
+
/** 是否是 Pro 版本 */
|
|
2214
|
+
isPro?: boolean;
|
|
2215
|
+
/** 到期时间戳 */
|
|
2216
|
+
expireAt?: string | number;
|
|
2217
|
+
/** 自动续费标志 0-关闭 1-开启 */
|
|
2218
|
+
renewFlag?: 0 | 1;
|
|
2219
|
+
/** 套餐代码 */
|
|
2220
|
+
PackageCode?: CommodityCode;
|
|
2221
|
+
/** 套餐名称 */
|
|
2222
|
+
name?: string;
|
|
2223
|
+
}
|
|
2224
|
+
/**
|
|
2225
|
+
* 推理配置
|
|
2226
|
+
*/
|
|
2227
|
+
interface ReasoningConfig {
|
|
2228
|
+
/** 推理努力程度 */
|
|
2229
|
+
effort: 'low' | 'medium' | 'high';
|
|
2230
|
+
/** 摘要模式 */
|
|
2231
|
+
summary: 'auto' | 'always' | 'never';
|
|
2232
|
+
}
|
|
2233
|
+
/**
|
|
2234
|
+
* 模型信息
|
|
2235
|
+
*/
|
|
2236
|
+
interface ModelInfo {
|
|
2237
|
+
/** 模型ID */
|
|
2238
|
+
id: string;
|
|
2239
|
+
/** 模型名称 */
|
|
2240
|
+
name: string;
|
|
2241
|
+
/** 供应商 */
|
|
2242
|
+
vendor: string;
|
|
2243
|
+
/** 最大输出 token 数 */
|
|
2244
|
+
maxOutputTokens: number;
|
|
2245
|
+
/** 最大输入 token 数 */
|
|
2246
|
+
maxInputTokens: number;
|
|
2247
|
+
/** 是否支持工具调用 */
|
|
2248
|
+
supportsToolCall: boolean;
|
|
2249
|
+
/** 是否支持图像 */
|
|
2250
|
+
supportsImages: boolean;
|
|
2251
|
+
/** 是否禁用多模态 */
|
|
2252
|
+
disabledMultimodal: boolean;
|
|
2253
|
+
/** 最大允许大小 */
|
|
2254
|
+
maxAllowedSize: number;
|
|
2255
|
+
/** 是否支持推理 */
|
|
2256
|
+
supportsReasoning: boolean;
|
|
2257
|
+
/** 是否仅推理模式 */
|
|
2258
|
+
onlyReasoning: boolean;
|
|
2259
|
+
/** 温度参数 */
|
|
2260
|
+
temperature: number;
|
|
2261
|
+
/** 推理配置 */
|
|
2262
|
+
reasoning: ReasoningConfig;
|
|
2263
|
+
/** 英文描述 */
|
|
2264
|
+
descriptionEn: string;
|
|
2265
|
+
/** 中文描述 */
|
|
2266
|
+
descriptionZh: string;
|
|
2267
|
+
}
|
|
2268
|
+
/**
|
|
2269
|
+
* GetModels 请求参数
|
|
2270
|
+
*/
|
|
2271
|
+
interface GetModelsRequest {
|
|
2272
|
+
/** 仓库路径 */
|
|
2273
|
+
repository: string;
|
|
2274
|
+
}
|
|
2275
|
+
/**
|
|
2276
|
+
* GetModels 响应
|
|
2277
|
+
*/
|
|
2278
|
+
interface GetModelsResponse {
|
|
2279
|
+
/** 模型列表 */
|
|
2280
|
+
models: ModelInfo[];
|
|
2281
|
+
}
|
|
2282
|
+
/**
|
|
2283
|
+
* Backend Provider 配置选项
|
|
2284
|
+
*/
|
|
2285
|
+
interface BackendProviderConfig {
|
|
2286
|
+
/** API 基础 URL (例如: https://api.example.com) */
|
|
2287
|
+
baseUrl: string;
|
|
2288
|
+
/** 认证 Token */
|
|
2289
|
+
authToken?: string;
|
|
2290
|
+
}
|
|
2291
|
+
/**
|
|
2292
|
+
* IBackendProvider 接口
|
|
2293
|
+
*
|
|
2294
|
+
* 定义与后端 API 交互的抽象接口
|
|
2295
|
+
*/
|
|
2296
|
+
interface IBackendProvider {
|
|
2297
|
+
/**
|
|
2298
|
+
* 获取 Agent 列表
|
|
2299
|
+
* @param request 请求参数
|
|
2300
|
+
* @returns Promise<GetAgentsResponse> Agent 列表响应
|
|
2301
|
+
*/
|
|
2302
|
+
getAgents(request: GetAgentsRequest): Promise<GetAgentsResponse>;
|
|
2303
|
+
/**
|
|
2304
|
+
* 获取可用模型列表
|
|
2305
|
+
* @param request 请求参数(包含仓库路径)
|
|
2306
|
+
* @returns Promise<GetModelsResponse> 模型列表响应
|
|
2307
|
+
*/
|
|
2308
|
+
getModels(request: GetModelsRequest): Promise<GetModelsResponse>;
|
|
2309
|
+
/**
|
|
2310
|
+
* 获取当前账号信息
|
|
2311
|
+
* @returns Promise<Account | null> 账号信息,未登录时返回 null
|
|
2312
|
+
*/
|
|
2313
|
+
getAccount(): Promise<Account | null>;
|
|
2314
|
+
/**
|
|
2315
|
+
* 触发登录流程
|
|
2316
|
+
* - Web 环境: 跳转到登录页面
|
|
2317
|
+
* - IDE 环境: 通过 IPC 通知 IDE 打开登录流程
|
|
2318
|
+
*/
|
|
2319
|
+
login(): Promise<void>;
|
|
2320
|
+
/**
|
|
2321
|
+
* 登出账号
|
|
2322
|
+
*/
|
|
2323
|
+
logout(): Promise<void>;
|
|
2324
|
+
/**
|
|
2325
|
+
* 监听事件(可选,用于 IPC 环境)
|
|
2326
|
+
* @param event 事件名称
|
|
2327
|
+
* @param callback 回调函数
|
|
2328
|
+
* @returns 取消订阅函数
|
|
2329
|
+
*/
|
|
2330
|
+
on?(event: string, callback: (data?: unknown) => void): () => void;
|
|
2331
|
+
}
|
|
2332
|
+
//#endregion
|
|
2333
|
+
//#region ../agent-provider/lib/backend/backend-provider.d.ts
|
|
2334
|
+
/**
|
|
2335
|
+
* Backend Provider 实现类
|
|
2336
|
+
*/
|
|
2337
|
+
declare class BackendProvider implements IBackendProvider {
|
|
2338
|
+
private readonly baseUrl;
|
|
2339
|
+
private readonly authToken?;
|
|
2340
|
+
constructor(config: BackendProviderConfig);
|
|
2341
|
+
/**
|
|
2342
|
+
* 获取 Agent 列表
|
|
2343
|
+
* API 端点: GET /v2/cloudagent/agentmgmt/agents
|
|
2344
|
+
*/
|
|
2345
|
+
getAgents(request?: GetAgentsRequest): Promise<GetAgentsResponse>;
|
|
2346
|
+
/**
|
|
2347
|
+
* 获取可用模型列表
|
|
2348
|
+
* API 端点: GET /v2/cloudagent/models (假设)
|
|
2349
|
+
*
|
|
2350
|
+
* 当前实现: 返回 Mock 数据
|
|
2351
|
+
*/
|
|
2352
|
+
getModels(request: GetModelsRequest): Promise<GetModelsResponse>;
|
|
2353
|
+
/**
|
|
2354
|
+
* 获取当前账号信息
|
|
2355
|
+
* API 端点: GET /console/accounts (返回账号列表)
|
|
2356
|
+
*
|
|
2357
|
+
* 逻辑:
|
|
2358
|
+
* 1. 从 localStorage 读取 CODEBUDDY_IDE_SELECTED_ACCOUNT_ID
|
|
2359
|
+
* 2. 根据 CODEBUDDY_IDE_SELECTED_ACCOUNT_ID 找到对应账号
|
|
2360
|
+
* - personal 类型: 用 uid 匹配
|
|
2361
|
+
* - 其他类型: 用 enterpriseId 匹配
|
|
2362
|
+
* 3. 如果没有选中的账号,跳转到账号选择页面
|
|
2363
|
+
* 4. 获取套餐信息并合并到账号中
|
|
2364
|
+
*/
|
|
2365
|
+
getAccount(): Promise<Account | null>;
|
|
2366
|
+
/**
|
|
2367
|
+
* 获取当前套餐信息
|
|
2368
|
+
* 从计量计费接口获取用户的套餐信息
|
|
2369
|
+
* API: POST /billing/meter/get-user-resource
|
|
2370
|
+
*/
|
|
2371
|
+
private getCurrentPlan;
|
|
2372
|
+
/**
|
|
2373
|
+
* 根据账号类型和 Pro 状态计算版本展示类型
|
|
2374
|
+
* - personal + isPro = 'pro'
|
|
2375
|
+
* - personal + !isPro = 'free'
|
|
2376
|
+
* - ultimate = 'ultimate' (旗舰版/团队版)
|
|
2377
|
+
* - exclusive = 'exclusive' (专享版/企业版)
|
|
2378
|
+
*/
|
|
2379
|
+
private getEditionDisplayType;
|
|
2380
|
+
/**
|
|
2381
|
+
* 触发登录流程
|
|
2382
|
+
* Web 环境: 跳转到登录页面
|
|
2383
|
+
*/
|
|
2384
|
+
login(): Promise<void>;
|
|
2385
|
+
/**
|
|
2386
|
+
* 登出账号
|
|
2387
|
+
* Web 环境: 跳转到登出页面或清除 cookie
|
|
2388
|
+
*/
|
|
2389
|
+
logout(): Promise<void>;
|
|
2390
|
+
}
|
|
2391
|
+
/**
|
|
2392
|
+
* 创建 BackendProvider 实例
|
|
2393
|
+
*/
|
|
2394
|
+
declare function createBackendProvider(config: BackendProviderConfig): BackendProvider;
|
|
2395
|
+
//#endregion
|
|
2396
|
+
//#region ../agent-provider/lib/backend/ipc-backend-provider.d.ts
|
|
2397
|
+
/**
|
|
2398
|
+
* IPC Backend Provider 配置
|
|
2399
|
+
*/
|
|
2400
|
+
interface IPCBackendProviderConfig {
|
|
2401
|
+
/** Widget Channel 接口 */
|
|
2402
|
+
channel: IWidgetChannel;
|
|
2403
|
+
/** 是否启用调试日志 */
|
|
2404
|
+
debug?: boolean;
|
|
2405
|
+
/** 请求超时时间(毫秒,默认 30000) */
|
|
2406
|
+
timeoutMs?: number;
|
|
2407
|
+
}
|
|
2408
|
+
/**
|
|
2409
|
+
* IPC Backend Provider 实现类
|
|
2410
|
+
*
|
|
2411
|
+
* 通过 IWidgetChannel 与后端通信获取 Agent 列表
|
|
2412
|
+
*/
|
|
2413
|
+
declare class IPCBackendProvider implements IBackendProvider {
|
|
2414
|
+
private readonly channel;
|
|
2415
|
+
private readonly debug;
|
|
2416
|
+
private readonly timeoutMs;
|
|
2417
|
+
constructor(config: IPCBackendProviderConfig);
|
|
2418
|
+
/**
|
|
2419
|
+
* 发送统一格式的后端请求
|
|
2420
|
+
* @param requestType 请求类型
|
|
2421
|
+
* @param params 请求参数
|
|
2422
|
+
* @returns 响应数据
|
|
2423
|
+
*/
|
|
2424
|
+
private sendBackendRequest;
|
|
2425
|
+
/**
|
|
2426
|
+
* 获取 Agent 列表
|
|
2427
|
+
* 通过 IWidgetChannel 发送请求到后端
|
|
2428
|
+
*/
|
|
2429
|
+
getAgents(request?: GetAgentsRequest): Promise<GetAgentsResponse>;
|
|
2430
|
+
/**
|
|
2431
|
+
* 获取可用模型列表
|
|
2432
|
+
* 通过 IWidgetChannel 发送请求到后端
|
|
2433
|
+
*/
|
|
2434
|
+
getModels(request: GetModelsRequest): Promise<GetModelsResponse>;
|
|
2435
|
+
/**
|
|
2436
|
+
* 获取当前账号信息
|
|
2437
|
+
* IDE 环境: 通过 IPC 获取账号信息
|
|
2438
|
+
*/
|
|
2439
|
+
getAccount(): Promise<Account | null>;
|
|
2440
|
+
/**
|
|
2441
|
+
* 触发登录流程
|
|
2442
|
+
* IDE 环境: 通过 IPC 通知 IDE 打开登录流程
|
|
2443
|
+
*/
|
|
2444
|
+
login(): Promise<void>;
|
|
2445
|
+
/**
|
|
2446
|
+
* 登出账号
|
|
2447
|
+
* IDE 环境: 通过 IPC 通知 IDE 登出
|
|
2448
|
+
*/
|
|
2449
|
+
logout(): Promise<void>;
|
|
2450
|
+
/**
|
|
2451
|
+
* 监听 channel 事件
|
|
2452
|
+
* 用于监听账户变化等事件
|
|
2453
|
+
*/
|
|
2454
|
+
on(event: string, callback: (data?: unknown) => void): () => void;
|
|
2455
|
+
/**
|
|
2456
|
+
* 调试日志
|
|
2457
|
+
*/
|
|
2458
|
+
private log;
|
|
2459
|
+
}
|
|
2460
|
+
/**
|
|
2461
|
+
* 创建 IPCBackendProvider 实例
|
|
2462
|
+
*/
|
|
2463
|
+
declare function createIPCBackendProvider(config: IPCBackendProviderConfig): IPCBackendProvider;
|
|
2464
|
+
//#endregion
|
|
2465
|
+
export { type Account, type AccountPlan, type ActiveSession, ActiveSessionImpl, type AgentCapabilities, AgentClient, type AgentClientOptions, type AgentConnection, type Agent as AgentInfo, type AgentProvider, type AgentState, type AgentStateType, type AgentStatus, type AgentTransport, type PromptResponse as ApiPromptResponse, type ArtifactsResource, BackendProvider, type BackendProviderConfig, type BaseAgentState, type BaseConnectionConfig, type CreateSessionParams as ClientCreateSessionParams, type CreateSessionParams, type LoadSessionParams as ClientLoadSessionParams, type LoadSessionParams, type ClientSessionsResource, CloudAgentConnection, CloudAgentProvider, type CloudAgentProviderOptions, type CloudAgentSourceInfo, type CloudAgentState, type CloudAgentTarget, type CloudAgentVisibility, type CloudConnectionConfig, type CommodityCode, type ConnectionEvents, type DeployStatus, E2BFilesystem, type E2BSandboxConnectionInfo, type Edition, type EditionDisplayType, type EntryInfo, type FilesResource, type Filesystem, type FilesystemListOpts, type FilesystemProvider, type FilesystemRequestOpts, type GetModelsRequest, type GetModelsResponse, type IBackendProvider, IPCBackendProvider, type ListAgentFilter, type ListAgentOptions, type ListAgentSort, type Logger, type McpServerConfig, type ModelInfo, type PromptContentBlock, type PromptParams, type PromptsResource, type ReasoningConfig, type Session, type SessionAgentOperations, type SessionEventHandler, type SessionEvents, type SessionInfo, SessionManager, type SessionMode, type WatchOpts, type WriteEntry, createBackendProvider, createIPCBackendProvider, isCloudAgentState };
|
|
2466
|
+
//# sourceMappingURL=index.d.mts.map
|