@iflow-ai/iflow-cli-sdk 0.1.0
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/LICENSE +21 -0
- package/README.md +401 -0
- package/README_CN.md +401 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.d.ts +966 -0
- package/dist/index.esm.js +1 -0
- package/package.json +78 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,966 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* iFlow SDK 错误类定义
|
|
5
|
+
*
|
|
6
|
+
* 提供完整的错误处理体系,包括连接错误、协议错误、权限错误等。
|
|
7
|
+
* 所有错误类都继承自 IFlowError 基类,提供统一的错误处理接口。
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* IFlowError - SDK 基础错误类
|
|
11
|
+
*
|
|
12
|
+
* 所有 iFlow SDK 相关错误的基类,提供错误详情存储功能。
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* try {
|
|
17
|
+
* await client.connect();
|
|
18
|
+
* } catch (error) {
|
|
19
|
+
* if (error instanceof IFlowError) {
|
|
20
|
+
* console.log("Error details:", error.details);
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare class IFlowError extends Error {
|
|
26
|
+
/** 错误详细信息,包含上下文数据 */
|
|
27
|
+
readonly details: Record<string, any>;
|
|
28
|
+
/**
|
|
29
|
+
* @param message - 错误消息
|
|
30
|
+
* @param details - 可选的错误详情对象
|
|
31
|
+
*/
|
|
32
|
+
constructor(message: string, details?: Record<string, any>);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* TimeoutError - 超时错误
|
|
36
|
+
*
|
|
37
|
+
* 当操作超过指定时间限制时抛出,如连接超时、响应超时等。
|
|
38
|
+
*/
|
|
39
|
+
export declare class TimeoutError extends IFlowError {
|
|
40
|
+
constructor(message: string, details?: Record<string, any>);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* JSONDecodeError - JSON 解析错误
|
|
44
|
+
*
|
|
45
|
+
* 当接收到的数据无法解析为有效 JSON 时抛出。
|
|
46
|
+
* 包含原始数据以便调试。
|
|
47
|
+
*/
|
|
48
|
+
export declare class JSONDecodeError extends IFlowError {
|
|
49
|
+
/** 导致解析失败的原始数据 */
|
|
50
|
+
readonly rawData: string;
|
|
51
|
+
/**
|
|
52
|
+
* @param message - 错误消息
|
|
53
|
+
* @param rawData - 导致解析失败的原始数据
|
|
54
|
+
*/
|
|
55
|
+
constructor(message: string, rawData: string);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* IFlowNotInstalledError - iFlow CLI 未安装错误
|
|
59
|
+
*
|
|
60
|
+
* 当系统中未找到 iFlow CLI 时抛出。
|
|
61
|
+
* 用户需要先安装 iFlow CLI 才能使用 SDK。
|
|
62
|
+
*/
|
|
63
|
+
export declare class IFlowNotInstalledError extends IFlowError {
|
|
64
|
+
constructor(message: string, details?: Record<string, any>);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* IFlowProcessError - iFlow 进程错误
|
|
68
|
+
*
|
|
69
|
+
* 当 iFlow CLI 进程启动失败或运行异常时抛出。
|
|
70
|
+
*/
|
|
71
|
+
export declare class IFlowProcessError extends IFlowError {
|
|
72
|
+
constructor(message: string, details?: Record<string, any>);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* PortNotAvailableError - 端口不可用错误
|
|
76
|
+
*
|
|
77
|
+
* 当指定的端口已被占用或无法绑定时抛出。
|
|
78
|
+
*/
|
|
79
|
+
export declare class PortNotAvailableError extends IFlowError {
|
|
80
|
+
constructor(message: string, details?: Record<string, any>);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* ConnectionError - 连接错误
|
|
84
|
+
*
|
|
85
|
+
* 当 WebSocket 连接失败或断开时抛出。
|
|
86
|
+
*/
|
|
87
|
+
export declare class ConnectionError extends IFlowError {
|
|
88
|
+
constructor(message: string, details?: Record<string, any>);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* TransportError - 传输层错误
|
|
92
|
+
*
|
|
93
|
+
* 当 WebSocket 传输过程中发生错误时抛出。
|
|
94
|
+
*/
|
|
95
|
+
export declare class TransportError extends IFlowError {
|
|
96
|
+
constructor(message: string, details?: Record<string, any>);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* PermissionError - 权限错误
|
|
100
|
+
*
|
|
101
|
+
* 当工具调用或文件操作权限不足时抛出。
|
|
102
|
+
*/
|
|
103
|
+
export declare class PermissionError extends IFlowError {
|
|
104
|
+
constructor(message: string, details?: Record<string, any>);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* ValidationError - 验证错误
|
|
108
|
+
*
|
|
109
|
+
* 当输入参数或数据格式验证失败时抛出。
|
|
110
|
+
*/
|
|
111
|
+
export declare class ValidationError extends IFlowError {
|
|
112
|
+
constructor(message: string, details?: Record<string, any>);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* ProtocolError - 协议错误
|
|
116
|
+
*
|
|
117
|
+
* 当 ACP 协议消息格式错误或协议违规时抛出。
|
|
118
|
+
*/
|
|
119
|
+
export declare class ProtocolError extends IFlowError {
|
|
120
|
+
constructor(message: string, details?: Record<string, any>);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* AuthenticationError - 认证错误
|
|
124
|
+
*
|
|
125
|
+
* 当身份验证失败时抛出。
|
|
126
|
+
*/
|
|
127
|
+
export declare class AuthenticationError extends IFlowError {
|
|
128
|
+
constructor(message: string, details?: Record<string, any>);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* iFlow SDK 配置选项类型定义
|
|
132
|
+
*
|
|
133
|
+
* 定义了 IFlowClient 的各种配置选项,包括日志级别、权限模式、
|
|
134
|
+
* 审批模式、钩子事件类型等。
|
|
135
|
+
*/
|
|
136
|
+
/**
|
|
137
|
+
* 日志级别枚举
|
|
138
|
+
*/
|
|
139
|
+
export declare enum LogLevel {
|
|
140
|
+
/** 调试级别 - 输出所有日志信息,包括详细的调试信息 */
|
|
141
|
+
DEBUG = 0,
|
|
142
|
+
/** 信息级别 - 输出一般信息、警告和错误 */
|
|
143
|
+
INFO = 1,
|
|
144
|
+
/** 警告级别 - 只输出警告和错误信息 */
|
|
145
|
+
WARN = 2,
|
|
146
|
+
/** 错误级别 - 只输出错误信息 */
|
|
147
|
+
ERROR = 3
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* 权限模式枚举
|
|
151
|
+
*
|
|
152
|
+
*/
|
|
153
|
+
export declare enum PermissionMode {
|
|
154
|
+
/** 自动模式 - 自动批准所有工具调用 */
|
|
155
|
+
AUTO = "auto",
|
|
156
|
+
/** 手动模式 - 需要手动确认每个工具调用 */
|
|
157
|
+
MANUAL = "manual",
|
|
158
|
+
/** 选择性模式 - 根据工具类型选择性批准 */
|
|
159
|
+
SELECTIVE = "selective"
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* 审批模式枚举
|
|
163
|
+
*/
|
|
164
|
+
export declare enum ApprovalMode {
|
|
165
|
+
/** 默认模式 - 使用系统默认的审批策略 */
|
|
166
|
+
DEFAULT = "default",
|
|
167
|
+
/** 自动编辑模式 - 自动批准文件编辑操作 */
|
|
168
|
+
AUTO_EDIT = "autoEdit",
|
|
169
|
+
/** YOLO 模式 - 自动批准所有操作(谨慎使用) */
|
|
170
|
+
YOLO = "yolo",
|
|
171
|
+
/** 计划模式 - 需要审批任务计划 */
|
|
172
|
+
PLAN = "plan"
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* 钩子事件类型枚举
|
|
176
|
+
*/
|
|
177
|
+
export declare enum HookEventType {
|
|
178
|
+
/** 工具使用前 - 在工具调用执行前触发 */
|
|
179
|
+
PRE_TOOL_USE = "PreToolUse",
|
|
180
|
+
/** 工具使用后 - 在工具调用执行后触发 */
|
|
181
|
+
POST_TOOL_USE = "PostToolUse",
|
|
182
|
+
/** 停止事件 - 在任务停止时触发 */
|
|
183
|
+
STOP = "Stop",
|
|
184
|
+
/** 子代理停止 - 在子代理停止时触发 */
|
|
185
|
+
SUBAGENT_STOP = "SubagentStop",
|
|
186
|
+
/** 环境设置 - 在环境设置时触发 */
|
|
187
|
+
SET_UP_ENVIRONMENT = "SetUpEnvironment"
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* MCP 服务器环境变量配置
|
|
191
|
+
*/
|
|
192
|
+
export interface MCPServerEnv {
|
|
193
|
+
/** 环境变量名称 */
|
|
194
|
+
name: string;
|
|
195
|
+
/** 环境变量值 */
|
|
196
|
+
value: string;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* MCP 服务器配置
|
|
200
|
+
*/
|
|
201
|
+
export interface MCPServerConfig {
|
|
202
|
+
/** 服务器名称,用于标识 */
|
|
203
|
+
name: string;
|
|
204
|
+
/** 启动命令 */
|
|
205
|
+
command: string;
|
|
206
|
+
/** 命令行参数数组 */
|
|
207
|
+
args: string[];
|
|
208
|
+
/** 环境变量配置数组 */
|
|
209
|
+
env: MCPServerEnv[];
|
|
210
|
+
}
|
|
211
|
+
export type MCPServerConfigs = MCPServerConfig[];
|
|
212
|
+
export interface HookCommand {
|
|
213
|
+
type: "command";
|
|
214
|
+
command: string;
|
|
215
|
+
timeout?: number;
|
|
216
|
+
}
|
|
217
|
+
export interface HookConfig {
|
|
218
|
+
matcher?: string;
|
|
219
|
+
hooks: HookCommand[];
|
|
220
|
+
}
|
|
221
|
+
export type HookConfigs = {
|
|
222
|
+
[key in HookEventType]?: HookConfig[];
|
|
223
|
+
};
|
|
224
|
+
export interface CommandConfig {
|
|
225
|
+
name: string;
|
|
226
|
+
content: string;
|
|
227
|
+
}
|
|
228
|
+
export type CommandConfigs = CommandConfig[];
|
|
229
|
+
export interface SubAgentConfig {
|
|
230
|
+
agentType: string;
|
|
231
|
+
whenToUse: string;
|
|
232
|
+
allowedTools: string[];
|
|
233
|
+
systemPrompt: string;
|
|
234
|
+
name?: string;
|
|
235
|
+
description?: string;
|
|
236
|
+
allowedMcps?: string[];
|
|
237
|
+
proactive?: boolean;
|
|
238
|
+
location?: "global" | "project";
|
|
239
|
+
model?: string;
|
|
240
|
+
isInheritTools?: boolean;
|
|
241
|
+
isInheritMcps?: boolean;
|
|
242
|
+
}
|
|
243
|
+
export type SubAgentConfigs = SubAgentConfig[];
|
|
244
|
+
export interface SessionSettings {
|
|
245
|
+
system_prompt?: string;
|
|
246
|
+
append_system_prompt?: string;
|
|
247
|
+
allowed_tools?: string[];
|
|
248
|
+
disallowed_tools?: string[];
|
|
249
|
+
permission_mode?: `${ApprovalMode}`;
|
|
250
|
+
max_turns?: number;
|
|
251
|
+
add_dirs?: string[];
|
|
252
|
+
}
|
|
253
|
+
export interface AuthMethodInfo {
|
|
254
|
+
apiKey?: string;
|
|
255
|
+
baseUrl?: string;
|
|
256
|
+
modelName?: string;
|
|
257
|
+
}
|
|
258
|
+
export interface IFlowOptions {
|
|
259
|
+
url?: string;
|
|
260
|
+
cwd?: string;
|
|
261
|
+
timeout?: number;
|
|
262
|
+
logLevel?: keyof typeof LogLevel;
|
|
263
|
+
processStartPort?: number;
|
|
264
|
+
autoStartProcess?: boolean;
|
|
265
|
+
authMethodId?: string;
|
|
266
|
+
authMethodInfo?: AuthMethodInfo;
|
|
267
|
+
mcpServers?: MCPServerConfigs;
|
|
268
|
+
hooks?: HookConfigs;
|
|
269
|
+
commands?: CommandConfigs;
|
|
270
|
+
agents?: SubAgentConfigs;
|
|
271
|
+
sessionSettings?: SessionSettings;
|
|
272
|
+
permissionMode?: `${PermissionMode}`;
|
|
273
|
+
autoApproveTypes?: string[];
|
|
274
|
+
fileAccess?: boolean;
|
|
275
|
+
fileMaxSize?: number;
|
|
276
|
+
fileReadOnly?: boolean;
|
|
277
|
+
fileAllowedDirs?: string[];
|
|
278
|
+
metadata?: Record<string, any>;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* iFlow SDK 消息类型定义
|
|
282
|
+
* 定义了与 iFlow CLI 通信过程中使用的所有消息类型、枚举和接口。
|
|
283
|
+
*/
|
|
284
|
+
/**
|
|
285
|
+
* 任务计划优先级枚举
|
|
286
|
+
*/
|
|
287
|
+
export declare enum PlanPriority {
|
|
288
|
+
/** 高优先级 - 需要立即处理的重要任务 */
|
|
289
|
+
HIGH = "high",
|
|
290
|
+
/** 中等优先级 - 正常处理的任务 */
|
|
291
|
+
MEDIUM = "medium",
|
|
292
|
+
/** 低优先级 - 可以延后处理的任务 */
|
|
293
|
+
LOW = "low"
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* 任务计划状态枚举
|
|
297
|
+
*/
|
|
298
|
+
export declare enum PlanStatus {
|
|
299
|
+
/** 待处理 - 任务已创建但尚未开始 */
|
|
300
|
+
PENDING = "pending",
|
|
301
|
+
/** 进行中 - 任务正在执行 */
|
|
302
|
+
IN_PROGRESS = "in_progress",
|
|
303
|
+
/** 已完成 - 任务执行完毕 */
|
|
304
|
+
COMPLETED = "completed"
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* 停止原因枚举
|
|
308
|
+
*/
|
|
309
|
+
export declare enum StopReason {
|
|
310
|
+
/** 正常结束 - AI 主动结束对话轮次 */
|
|
311
|
+
END_TURN = "end_turn",
|
|
312
|
+
/** 达到最大令牌数 - 响应长度超出限制 */
|
|
313
|
+
MAX_TOKENS = "max_tokens",
|
|
314
|
+
/** 拒绝响应 - AI 拒绝执行请求 */
|
|
315
|
+
REFUSAL = "refusal",
|
|
316
|
+
/** 用户取消 - 用户主动取消操作 */
|
|
317
|
+
CANCELLED = "cancelled"
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* 工具调用状态枚举
|
|
321
|
+
*/
|
|
322
|
+
export declare enum ToolCallStatus {
|
|
323
|
+
/** 待处理 - 工具调用请求已发出但尚未开始执行 */
|
|
324
|
+
PENDING = "pending",
|
|
325
|
+
/** 执行中 - 工具正在执行 */
|
|
326
|
+
IN_PROGRESS = "in_progress",
|
|
327
|
+
/** 执行完成 - 工具成功执行并返回结果 */
|
|
328
|
+
COMPLETED = "completed",
|
|
329
|
+
/** 执行失败 - 工具执行过程中发生错误 */
|
|
330
|
+
FAILED = "failed"
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* 工具调用内容类型枚举
|
|
334
|
+
*/
|
|
335
|
+
export declare enum ToolCallContentType {
|
|
336
|
+
/** 差异格式 - 显示文件变更的 diff 格式 */
|
|
337
|
+
DIFF = "diff",
|
|
338
|
+
/** Markdown 格式 - 结构化的 Markdown 文本 */
|
|
339
|
+
MARKDOWN = "markdown"
|
|
340
|
+
}
|
|
341
|
+
export declare enum ToolCallConfirmationType {
|
|
342
|
+
/** 编辑 - 编辑文件 */
|
|
343
|
+
EDIT = "edit",
|
|
344
|
+
/** 执行 - 执行命令 */
|
|
345
|
+
EXECUTE = "execute",
|
|
346
|
+
/** MCP - MCP 服务器 */
|
|
347
|
+
MCP = "mcp",
|
|
348
|
+
/** FETCH - FETCH 服务器 */
|
|
349
|
+
FETCH = "fetch",
|
|
350
|
+
/** OTHER - 其他 */
|
|
351
|
+
OTHER = "other"
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* 工具调用确认结果枚举
|
|
355
|
+
*/
|
|
356
|
+
export declare enum ToolCallConfirmationOutcome {
|
|
357
|
+
/** 允许 - 允许工具调用 */
|
|
358
|
+
ALLOW = "allow",
|
|
359
|
+
/** 总是允许 - 总是允许工具调用 */
|
|
360
|
+
ALWAYS_ALLOW = "alwaysAllow",
|
|
361
|
+
/** 总是允许工具 - 总是允许工具调用 */
|
|
362
|
+
ALWAYS_ALLOW_TOOL = "alwaysAllowTool",
|
|
363
|
+
/** 总是允许 MCP 服务器 - 总是允许 MCP 服务器 */
|
|
364
|
+
ALWAYS_ALLOW_MCP_SERVER = "alwaysAllowMcpServer",
|
|
365
|
+
/** 拒绝 - 拒绝工具调用 */
|
|
366
|
+
REJECT = "reject"
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* 工具调用图标类型枚举
|
|
370
|
+
*/
|
|
371
|
+
export declare enum ToolCallIconType {
|
|
372
|
+
/** URL - URL 图标 */
|
|
373
|
+
URL = "url",
|
|
374
|
+
/** EMOJI - 表情图标 */
|
|
375
|
+
EMOJI = "emoji"
|
|
376
|
+
}
|
|
377
|
+
/** 消息类型枚举 */
|
|
378
|
+
export declare enum MessageType {
|
|
379
|
+
PLAN = "plan",
|
|
380
|
+
/** USER - 用户消息 */
|
|
381
|
+
USER = "user",
|
|
382
|
+
/** ASSISTANT - 助手消息 */
|
|
383
|
+
ASSISTANT = "assistant",
|
|
384
|
+
/** TOOL_CALL - 工具调用消息 */
|
|
385
|
+
TOOL_CALL = "tool_call",
|
|
386
|
+
/** ERROR - 错误消息 */
|
|
387
|
+
ERROR = "error",
|
|
388
|
+
/** TASK_FINISH - 任务完成消息 */
|
|
389
|
+
TASK_FINISH = "task_finish"
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* 代理信息接口
|
|
393
|
+
*/
|
|
394
|
+
export interface AgentInfo {
|
|
395
|
+
/** 代理 ID */
|
|
396
|
+
agentId: string;
|
|
397
|
+
/** 代理索引 */
|
|
398
|
+
agentIndex?: number;
|
|
399
|
+
/** 任务 ID */
|
|
400
|
+
taskId?: string;
|
|
401
|
+
/** 时间戳 */
|
|
402
|
+
timestamp?: number;
|
|
403
|
+
}
|
|
404
|
+
/** 计划项接口 */
|
|
405
|
+
export interface PlanEntry {
|
|
406
|
+
/** 内容 */
|
|
407
|
+
content: string;
|
|
408
|
+
/** 状态 */
|
|
409
|
+
status: `${PlanStatus}`;
|
|
410
|
+
/** 优先级 */
|
|
411
|
+
priority: `${PlanPriority}`;
|
|
412
|
+
}
|
|
413
|
+
/** 计划消息接口 */
|
|
414
|
+
export interface PlanMessage {
|
|
415
|
+
/** 类型 */
|
|
416
|
+
type: `${MessageType.PLAN}`;
|
|
417
|
+
/** 计划项 */
|
|
418
|
+
entries: PlanEntry[];
|
|
419
|
+
}
|
|
420
|
+
/** 用户消息片段接口 */
|
|
421
|
+
export interface UserMessageChunk {
|
|
422
|
+
/** 文本 */
|
|
423
|
+
text: string;
|
|
424
|
+
}
|
|
425
|
+
/** 用户消息接口 */
|
|
426
|
+
export interface UserMessage {
|
|
427
|
+
type: `${MessageType.USER}`;
|
|
428
|
+
chunks: UserMessageChunk[];
|
|
429
|
+
}
|
|
430
|
+
/** 助手消息接口 */
|
|
431
|
+
export interface AssistantMessage {
|
|
432
|
+
/** 类型 */
|
|
433
|
+
type: `${MessageType.ASSISTANT}`;
|
|
434
|
+
chunk: {
|
|
435
|
+
text?: string;
|
|
436
|
+
thought?: string;
|
|
437
|
+
};
|
|
438
|
+
agentId?: string;
|
|
439
|
+
agentInfo?: AgentInfo;
|
|
440
|
+
}
|
|
441
|
+
export interface ToolCallContent {
|
|
442
|
+
type: `${ToolCallContentType}`;
|
|
443
|
+
markdown?: string;
|
|
444
|
+
path?: string;
|
|
445
|
+
oldText?: string;
|
|
446
|
+
newText?: string;
|
|
447
|
+
}
|
|
448
|
+
export interface ToolCallLocation {
|
|
449
|
+
path: string;
|
|
450
|
+
lineStart?: number;
|
|
451
|
+
lineEnd?: number;
|
|
452
|
+
}
|
|
453
|
+
export interface ToolCallConfirmation {
|
|
454
|
+
type: `${ToolCallConfirmationType}`;
|
|
455
|
+
description?: string;
|
|
456
|
+
command?: string;
|
|
457
|
+
rootCommand?: string;
|
|
458
|
+
serverName?: string;
|
|
459
|
+
toolName?: string;
|
|
460
|
+
toolDisplayName?: string;
|
|
461
|
+
urls?: string[];
|
|
462
|
+
}
|
|
463
|
+
export interface ToolCallMessage {
|
|
464
|
+
type: `${MessageType.TOOL_CALL}`;
|
|
465
|
+
id: string;
|
|
466
|
+
label: string;
|
|
467
|
+
icon: {
|
|
468
|
+
type: `${ToolCallIconType}`;
|
|
469
|
+
value: string;
|
|
470
|
+
};
|
|
471
|
+
status: `${ToolCallStatus}`;
|
|
472
|
+
toolName?: string;
|
|
473
|
+
content?: ToolCallContent;
|
|
474
|
+
locations?: ToolCallLocation[];
|
|
475
|
+
confirmation?: ToolCallConfirmation;
|
|
476
|
+
args?: any;
|
|
477
|
+
output?: string;
|
|
478
|
+
agentId?: string;
|
|
479
|
+
agentInfo?: AgentInfo;
|
|
480
|
+
}
|
|
481
|
+
export interface ErrorMessage {
|
|
482
|
+
type: `${MessageType.ERROR}`;
|
|
483
|
+
code: number;
|
|
484
|
+
message: string;
|
|
485
|
+
details?: Record<string, any>;
|
|
486
|
+
}
|
|
487
|
+
export interface TaskFinishMessage {
|
|
488
|
+
type: `${MessageType.TASK_FINISH}`;
|
|
489
|
+
stopReason?: `${StopReason}`;
|
|
490
|
+
}
|
|
491
|
+
export type Message = PlanMessage | UserMessage | AssistantMessage | ToolCallMessage | ErrorMessage | TaskFinishMessage;
|
|
492
|
+
export interface RawMessage {
|
|
493
|
+
isControl: boolean;
|
|
494
|
+
messageType: string;
|
|
495
|
+
rawData: string;
|
|
496
|
+
jsonData?: Record<string, any>;
|
|
497
|
+
parsedMessage?: Message;
|
|
498
|
+
timestamp: number;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* 日志记录器配置选项
|
|
502
|
+
*/
|
|
503
|
+
export interface LoggerOptions {
|
|
504
|
+
/** 日志级别,默认为 INFO */
|
|
505
|
+
level?: keyof typeof LogLevel;
|
|
506
|
+
}
|
|
507
|
+
declare class Logger {
|
|
508
|
+
private readonly level;
|
|
509
|
+
constructor(options?: Partial<LoggerOptions>);
|
|
510
|
+
debug(message: string): void;
|
|
511
|
+
info(message: string): void;
|
|
512
|
+
warn(message: string): void;
|
|
513
|
+
error(message: string, error?: Error): void;
|
|
514
|
+
private log;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Transport 类构造选项
|
|
518
|
+
*/
|
|
519
|
+
export interface TransportOptions {
|
|
520
|
+
/** WebSocket 连接 URL */
|
|
521
|
+
url: string;
|
|
522
|
+
/** 日志记录器实例 */
|
|
523
|
+
logger?: Logger;
|
|
524
|
+
/** 连接超时时间(毫秒),默认 300000ms (5分钟) */
|
|
525
|
+
timeout?: number;
|
|
526
|
+
}
|
|
527
|
+
declare class Transport {
|
|
528
|
+
private readonly url;
|
|
529
|
+
private readonly logger;
|
|
530
|
+
private readonly timeout;
|
|
531
|
+
private ws;
|
|
532
|
+
private connected;
|
|
533
|
+
constructor(options: TransportOptions);
|
|
534
|
+
get isConnected(): boolean;
|
|
535
|
+
private checkConnected;
|
|
536
|
+
connect(): Promise<void>;
|
|
537
|
+
close(): Promise<void>;
|
|
538
|
+
send(data: string | object): Promise<void>;
|
|
539
|
+
receive(): AsyncGenerator<string>;
|
|
540
|
+
private receiveRawData;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* FileHandler 类构造选项
|
|
544
|
+
*/
|
|
545
|
+
export interface FileHandlerOptions {
|
|
546
|
+
/** 工作目录,默认为当前进程工作目录 */
|
|
547
|
+
cwd?: string;
|
|
548
|
+
/** 日志记录器实例 */
|
|
549
|
+
logger?: Logger;
|
|
550
|
+
/** 只读模式,禁止写入操作 */
|
|
551
|
+
readOnly?: boolean;
|
|
552
|
+
/** 最大文件大小限制(字节),默认 10MB */
|
|
553
|
+
maxFileSize?: number;
|
|
554
|
+
/** 允许访问的目录列表,为空则允许访问所有目录 */
|
|
555
|
+
allowedDirs?: string[];
|
|
556
|
+
}
|
|
557
|
+
declare class FileHandler {
|
|
558
|
+
private readonly cwd;
|
|
559
|
+
private readonly logger;
|
|
560
|
+
private readonly readOnly;
|
|
561
|
+
private readonly maxFileSize;
|
|
562
|
+
private readonly allowedDirs;
|
|
563
|
+
constructor(options?: FileHandlerOptions);
|
|
564
|
+
private isPathAllowed;
|
|
565
|
+
readFile(filePath: string, line?: number, limit?: number): Promise<string>;
|
|
566
|
+
writeFile(filePath: string, content: string): Promise<void>;
|
|
567
|
+
addAllowedDir(dir: string): Promise<void>;
|
|
568
|
+
removeAllowedDir(dir: string): void;
|
|
569
|
+
}
|
|
570
|
+
export type ACPRequestId = number | string;
|
|
571
|
+
declare enum ACPSessionUpdateType {
|
|
572
|
+
PLAN = "plan",
|
|
573
|
+
TOOL_CALL = "tool_call",
|
|
574
|
+
TOOL_CALL_UPDATE = "tool_call_update",
|
|
575
|
+
USER_MESSAGE_CHUNK = "user_message_chunk",
|
|
576
|
+
AGENT_MESSAGE_CHUNK = "agent_message_chunk",
|
|
577
|
+
AGENT_THOUGHT_CHUNK = "agent_thought_chunk"
|
|
578
|
+
}
|
|
579
|
+
export interface ACPInitializeResult {
|
|
580
|
+
protocolVersion: number;
|
|
581
|
+
isAuthenticated?: boolean;
|
|
582
|
+
}
|
|
583
|
+
export type ACPSessionUpdateData = ACPSessionUpdatePlanData | ACPSessionUpdateToolCallData | ACPSessionUpdateToolCallUpdateData | ACPSessionUpdateUserMessageChunkData | ACPSessionUpdateAgentMessageChunkData | ACPSessionUpdateAgentThoughtChunkData;
|
|
584
|
+
export interface ACPSessionUpdatePlanData {
|
|
585
|
+
sessionUpdate: `${ACPSessionUpdateType.PLAN}`;
|
|
586
|
+
entries?: Partial<PlanEntry>[];
|
|
587
|
+
}
|
|
588
|
+
export interface ACPSessionUpdateToolCallData {
|
|
589
|
+
sessionUpdate: `${ACPSessionUpdateType.TOOL_CALL}`;
|
|
590
|
+
toolCallId: string;
|
|
591
|
+
title?: string;
|
|
592
|
+
status?: `${ToolCallStatus}`;
|
|
593
|
+
toolName?: string;
|
|
594
|
+
agentId?: string;
|
|
595
|
+
}
|
|
596
|
+
export interface ACPSessionUpdateToolCallUpdateData {
|
|
597
|
+
sessionUpdate: `${ACPSessionUpdateType.TOOL_CALL_UPDATE}`;
|
|
598
|
+
toolCallId: string;
|
|
599
|
+
title?: string;
|
|
600
|
+
status?: `${ToolCallStatus}`;
|
|
601
|
+
toolName?: string;
|
|
602
|
+
agentId?: string;
|
|
603
|
+
content?: Array<{
|
|
604
|
+
type: "content";
|
|
605
|
+
content?: {
|
|
606
|
+
type: "text";
|
|
607
|
+
text?: string;
|
|
608
|
+
};
|
|
609
|
+
}>;
|
|
610
|
+
}
|
|
611
|
+
export interface ACPSessionUpdateUserMessageChunkData {
|
|
612
|
+
sessionUpdate: `${ACPSessionUpdateType.USER_MESSAGE_CHUNK}`;
|
|
613
|
+
content?: {
|
|
614
|
+
type: "text";
|
|
615
|
+
text?: string;
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
export interface ACPSessionUpdateAgentMessageChunkData {
|
|
619
|
+
sessionUpdate: `${ACPSessionUpdateType.AGENT_MESSAGE_CHUNK}`;
|
|
620
|
+
content?: {
|
|
621
|
+
type: "text";
|
|
622
|
+
text?: string;
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
export interface ACPSessionUpdateAgentThoughtChunkData {
|
|
626
|
+
sessionUpdate: `${ACPSessionUpdateType.AGENT_THOUGHT_CHUNK}`;
|
|
627
|
+
content?: {
|
|
628
|
+
type: "text";
|
|
629
|
+
text?: string;
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
export interface ACPRequestPermissionParams {
|
|
633
|
+
toolCall?: {
|
|
634
|
+
type?: string;
|
|
635
|
+
title?: string;
|
|
636
|
+
};
|
|
637
|
+
options?: Array<{
|
|
638
|
+
optionId: string;
|
|
639
|
+
}>;
|
|
640
|
+
}
|
|
641
|
+
declare enum ProtocolMessageType {
|
|
642
|
+
ERROR = "error",
|
|
643
|
+
RESPONSE = "response",
|
|
644
|
+
FILE_READ = "file_read",
|
|
645
|
+
FILE_WRITE = "file_write",
|
|
646
|
+
SESSION_UPDATE = "session_update",
|
|
647
|
+
TOOL_CALL = "tool_call",
|
|
648
|
+
TOOL_UPDATE = "tool_update",
|
|
649
|
+
TOOL_CONFIRMATION = "tool_confirmation",
|
|
650
|
+
TASK_FINISH = "task_finish",
|
|
651
|
+
UNKNOWN = "unknown"
|
|
652
|
+
}
|
|
653
|
+
export interface ProtocolErrorMessage {
|
|
654
|
+
type: `${ProtocolMessageType.ERROR}`;
|
|
655
|
+
code: number;
|
|
656
|
+
error: string;
|
|
657
|
+
method?: string;
|
|
658
|
+
}
|
|
659
|
+
export interface ProtocolResponseMessage {
|
|
660
|
+
type: `${ProtocolMessageType.RESPONSE}`;
|
|
661
|
+
id: ACPRequestId;
|
|
662
|
+
result: any;
|
|
663
|
+
}
|
|
664
|
+
export interface ProtocolFileReadMessage {
|
|
665
|
+
type: `${ProtocolMessageType.FILE_READ}`;
|
|
666
|
+
path: string;
|
|
667
|
+
content: string;
|
|
668
|
+
}
|
|
669
|
+
export interface ProtocolFileWriteMessage {
|
|
670
|
+
type: `${ProtocolMessageType.FILE_WRITE}`;
|
|
671
|
+
path: string;
|
|
672
|
+
content: string;
|
|
673
|
+
}
|
|
674
|
+
export interface ProtocolSessionUpdateMessage {
|
|
675
|
+
type: `${ProtocolMessageType.SESSION_UPDATE}`;
|
|
676
|
+
sessionId: string;
|
|
677
|
+
updateData: ACPSessionUpdateData;
|
|
678
|
+
}
|
|
679
|
+
export interface ProtocolToolConfirmationMessage {
|
|
680
|
+
type: `${ProtocolMessageType.TOOL_CONFIRMATION}`;
|
|
681
|
+
params: ACPRequestPermissionParams;
|
|
682
|
+
response: {
|
|
683
|
+
outcome: {
|
|
684
|
+
outcome: string;
|
|
685
|
+
optionId?: string;
|
|
686
|
+
};
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
export interface ProtocolToolCallMessage {
|
|
690
|
+
type: `${ProtocolMessageType.TOOL_CALL}`;
|
|
691
|
+
id: string;
|
|
692
|
+
params: any;
|
|
693
|
+
}
|
|
694
|
+
export interface ProtocolToolUpdateMessage {
|
|
695
|
+
type: `${ProtocolMessageType.TOOL_UPDATE}`;
|
|
696
|
+
params: any;
|
|
697
|
+
}
|
|
698
|
+
export interface ProtocolTaskFinishMessage {
|
|
699
|
+
type: `${ProtocolMessageType.TASK_FINISH}`;
|
|
700
|
+
params: any;
|
|
701
|
+
}
|
|
702
|
+
export interface ProtocolUnknownMessage {
|
|
703
|
+
type: `${ProtocolMessageType.UNKNOWN}`;
|
|
704
|
+
method: string;
|
|
705
|
+
params: any;
|
|
706
|
+
}
|
|
707
|
+
export type ProtocolMessage = ProtocolErrorMessage | ProtocolResponseMessage | ProtocolFileReadMessage | ProtocolFileWriteMessage | ProtocolSessionUpdateMessage | ProtocolToolCallMessage | ProtocolToolUpdateMessage | ProtocolToolConfirmationMessage | ProtocolTaskFinishMessage | ProtocolUnknownMessage;
|
|
708
|
+
export interface TextPrompt {
|
|
709
|
+
type: "text";
|
|
710
|
+
text: string;
|
|
711
|
+
}
|
|
712
|
+
export interface ImagePrompt {
|
|
713
|
+
type: "image";
|
|
714
|
+
data: string;
|
|
715
|
+
mimeType: string;
|
|
716
|
+
}
|
|
717
|
+
export interface AudioPrompt {
|
|
718
|
+
type: "audio";
|
|
719
|
+
data: string;
|
|
720
|
+
mimeType: string;
|
|
721
|
+
}
|
|
722
|
+
export interface ResourceLinkPrompt {
|
|
723
|
+
type: "resource_link";
|
|
724
|
+
uri: string;
|
|
725
|
+
name: string;
|
|
726
|
+
title: string;
|
|
727
|
+
size: number;
|
|
728
|
+
}
|
|
729
|
+
export type Prompt = TextPrompt | ImagePrompt | AudioPrompt | ResourceLinkPrompt;
|
|
730
|
+
/**
|
|
731
|
+
* Protocol 类构造选项
|
|
732
|
+
*/
|
|
733
|
+
export interface ProtocolOptions {
|
|
734
|
+
/** 日志记录器实例 */
|
|
735
|
+
logger?: Logger;
|
|
736
|
+
/** WebSocket 传输层实例 */
|
|
737
|
+
transport: Transport;
|
|
738
|
+
/** 文件处理器实例,用于文件读写操作 */
|
|
739
|
+
fileHandler?: FileHandler;
|
|
740
|
+
/** 权限模式,控制工具调用的审批方式 */
|
|
741
|
+
permissionMode?: `${PermissionMode}`;
|
|
742
|
+
/** 自动批准的工具类型列表 */
|
|
743
|
+
autoApproveTypes?: string[];
|
|
744
|
+
}
|
|
745
|
+
declare class Protocol {
|
|
746
|
+
private readonly logger;
|
|
747
|
+
private readonly transport;
|
|
748
|
+
private readonly fileHandler?;
|
|
749
|
+
private readonly permissionMode;
|
|
750
|
+
private readonly autoApproveTypes;
|
|
751
|
+
private requestId;
|
|
752
|
+
private initialized;
|
|
753
|
+
private authenticated;
|
|
754
|
+
constructor(options: ProtocolOptions);
|
|
755
|
+
private nextRequestId;
|
|
756
|
+
private checkAuthenticated;
|
|
757
|
+
private sendResult;
|
|
758
|
+
private sendError;
|
|
759
|
+
private waitForReadySignal;
|
|
760
|
+
private waitForMessageResponse;
|
|
761
|
+
initialize(params?: {
|
|
762
|
+
mcpServers?: MCPServerConfigs;
|
|
763
|
+
hooks?: HookConfigs;
|
|
764
|
+
commands?: CommandConfigs;
|
|
765
|
+
agents?: SubAgentConfigs;
|
|
766
|
+
}): Promise<ACPInitializeResult>;
|
|
767
|
+
authenticate(params?: {
|
|
768
|
+
methodId?: string;
|
|
769
|
+
methodInfo?: AuthMethodInfo;
|
|
770
|
+
}): Promise<void>;
|
|
771
|
+
createSession(params?: {
|
|
772
|
+
cwd?: string;
|
|
773
|
+
mcpServers?: MCPServerConfigs;
|
|
774
|
+
hooks?: HookConfigs;
|
|
775
|
+
commands?: CommandConfigs;
|
|
776
|
+
agents?: SubAgentConfigs;
|
|
777
|
+
settings?: SessionSettings;
|
|
778
|
+
}): Promise<string>;
|
|
779
|
+
loadSession(params: {
|
|
780
|
+
sessionId: string;
|
|
781
|
+
cwd?: string;
|
|
782
|
+
mcpServers?: MCPServerConfigs;
|
|
783
|
+
}): Promise<void>;
|
|
784
|
+
sendPrompt(params: {
|
|
785
|
+
sessionId: string;
|
|
786
|
+
prompt: Prompt[];
|
|
787
|
+
}): Promise<number>;
|
|
788
|
+
cancelSession(params: {
|
|
789
|
+
sessionId: string;
|
|
790
|
+
}): Promise<void>;
|
|
791
|
+
handleMessages(): AsyncGenerator<ProtocolMessage>;
|
|
792
|
+
private handleClientMessage;
|
|
793
|
+
private handleReadTextFile;
|
|
794
|
+
private handleWriteTextFile;
|
|
795
|
+
private handleSessionUpdate;
|
|
796
|
+
private handleRequestPermission;
|
|
797
|
+
private handlePushToolCall;
|
|
798
|
+
private handleUpdateToolCall;
|
|
799
|
+
private handleNotifyTaskFinish;
|
|
800
|
+
private handleUnknownMessage;
|
|
801
|
+
}
|
|
802
|
+
/**
|
|
803
|
+
* IFlowClient - iFlow CLI SDK 的核心客户端类
|
|
804
|
+
*
|
|
805
|
+
* 提供与 iFlow CLI 的完整交互能力,包括:
|
|
806
|
+
* - 自动进程管理:自动启动和管理 iFlow CLI 进程
|
|
807
|
+
* - WebSocket 通信:基于 ACP 协议的双向实时通信
|
|
808
|
+
* - 工具调用管理:处理和控制工具执行,支持细粒度权限控制
|
|
809
|
+
* - 多代理支持:跟踪和管理多个 AI 代理(SubAgent)
|
|
810
|
+
* - 任务规划:接收和处理结构化任务计划
|
|
811
|
+
* - 会话管理:创建、加载和管理对话会话
|
|
812
|
+
*
|
|
813
|
+
* @example
|
|
814
|
+
* ```typescript
|
|
815
|
+
* // 基本用法 - SDK 自动管理进程
|
|
816
|
+
* const client = new IFlowClient();
|
|
817
|
+
* await client.connect();
|
|
818
|
+
* await client.sendMessage("Hello, iFlow!");
|
|
819
|
+
*
|
|
820
|
+
* for await (const message of client.receiveMessages()) {
|
|
821
|
+
* console.log(message);
|
|
822
|
+
* }
|
|
823
|
+
* ```
|
|
824
|
+
*
|
|
825
|
+
* @example
|
|
826
|
+
* ```typescript
|
|
827
|
+
* // 高级配置
|
|
828
|
+
* const client = new IFlowClient({
|
|
829
|
+
* permissionMode: PermissionMode.AUTO,
|
|
830
|
+
* sessionSettings: {
|
|
831
|
+
* allowed_tools: ["read_file", "write_file"],
|
|
832
|
+
* system_prompt: "You are a helpful assistant"
|
|
833
|
+
* },
|
|
834
|
+
* agents: [{
|
|
835
|
+
* agentType: "code-reviewer",
|
|
836
|
+
* name: "reviewer",
|
|
837
|
+
* allowedTools: ["fs", "grep"]
|
|
838
|
+
* }]
|
|
839
|
+
* });
|
|
840
|
+
* ```
|
|
841
|
+
*/
|
|
842
|
+
export declare class IFlowClient {
|
|
843
|
+
/** 客户端配置选项 */
|
|
844
|
+
private readonly options;
|
|
845
|
+
/** 日志记录器 */
|
|
846
|
+
protected readonly logger: Logger;
|
|
847
|
+
/** ACP 协议处理器 */
|
|
848
|
+
protected protocol: Protocol | null;
|
|
849
|
+
/** WebSocket 传输层 */
|
|
850
|
+
protected transport: Transport | null;
|
|
851
|
+
/** 连接状态标识 */
|
|
852
|
+
protected connected: boolean;
|
|
853
|
+
/** 认证状态标识 */
|
|
854
|
+
protected authenticated: boolean;
|
|
855
|
+
/** 消息处理任务 */
|
|
856
|
+
private messageTask;
|
|
857
|
+
/** 消息队列,用于缓存接收到的消息 */
|
|
858
|
+
private messageQueue;
|
|
859
|
+
/** 待处理的工具调用映射表,key 为工具调用 ID */
|
|
860
|
+
private pendingToolCalls;
|
|
861
|
+
/** WebSocket 连接 URL */
|
|
862
|
+
private url;
|
|
863
|
+
/** 当前会话 ID */
|
|
864
|
+
private sessionId;
|
|
865
|
+
/** 进程管理器,用于自动启动和管理 iFlow CLI 进程 */
|
|
866
|
+
private processManager;
|
|
867
|
+
/** 进程启动状态标识 */
|
|
868
|
+
private processStarted;
|
|
869
|
+
/**
|
|
870
|
+
* 构造函数 - 创建 IFlowClient 实例
|
|
871
|
+
*
|
|
872
|
+
* @param options - 可选的配置选项,包括连接设置、权限模式、代理配置等
|
|
873
|
+
*/
|
|
874
|
+
constructor(options?: IFlowOptions);
|
|
875
|
+
connect(): Promise<void>;
|
|
876
|
+
loadSession(sessionId: string): Promise<void>;
|
|
877
|
+
disconnect(): Promise<void>;
|
|
878
|
+
sendMessage(text: string, files?: string[]): Promise<void>;
|
|
879
|
+
interrupt(): Promise<void>;
|
|
880
|
+
receiveMessages(): AsyncGenerator<Message>;
|
|
881
|
+
approveToolCall(toolId: string, outcome?: `${ToolCallConfirmationOutcome}`): Promise<void>;
|
|
882
|
+
rejectToolCall(toolId: string): Promise<void>;
|
|
883
|
+
protected handleMessages(): Promise<void>;
|
|
884
|
+
protected processProtocolMessage(protocolMessage: ProtocolMessage): Message | null;
|
|
885
|
+
}
|
|
886
|
+
export declare class RawDataClient extends IFlowClient {
|
|
887
|
+
private readonly captureRaw;
|
|
888
|
+
private readonly rawQueue;
|
|
889
|
+
private readonly rawHistory;
|
|
890
|
+
private readonly rawQueueResolvers;
|
|
891
|
+
private readonly messageQueueResolvers;
|
|
892
|
+
constructor(options?: IFlowOptions, captureRaw?: boolean);
|
|
893
|
+
protected handleMessages(): Promise<void>;
|
|
894
|
+
private captureRawStream;
|
|
895
|
+
private handleParsedStream;
|
|
896
|
+
receiveRawMessages(): AsyncGenerator<RawMessage>;
|
|
897
|
+
receiveDualStream(): AsyncGenerator<[
|
|
898
|
+
RawMessage,
|
|
899
|
+
Message | undefined
|
|
900
|
+
]>;
|
|
901
|
+
getRawHistory(): RawMessage[];
|
|
902
|
+
getProtocolStats(): Record<string, any>;
|
|
903
|
+
sendRaw(data: string | Record<string, any>): Promise<void>;
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* 简单的异步查询函数 - 发送提示并等待完整响应
|
|
907
|
+
*
|
|
908
|
+
* 这是最简单的使用方式,适合单次查询场景。
|
|
909
|
+
* SDK 会自动管理连接生命周期。
|
|
910
|
+
*
|
|
911
|
+
* @param prompt - 用户提示文本
|
|
912
|
+
* @param files - 可选的文件路径数组,用于上下文
|
|
913
|
+
* @param options - 可选的 iFlow 配置选项
|
|
914
|
+
* @returns Promise<string> - 完整的 AI 响应文本
|
|
915
|
+
*
|
|
916
|
+
* @example
|
|
917
|
+
* ```typescript
|
|
918
|
+
* const response = await query("What is the capital of France?");
|
|
919
|
+
* console.log(response); // "The capital of France is Paris."
|
|
920
|
+
* ```
|
|
921
|
+
*/
|
|
922
|
+
export declare function query(prompt: string, files?: string[], options?: IFlowOptions): Promise<string>;
|
|
923
|
+
/**
|
|
924
|
+
* 同步查询函数 - 阻塞等待响应完成
|
|
925
|
+
*
|
|
926
|
+
* 注意:这是一个同步函数,会阻塞当前线程直到响应完成。
|
|
927
|
+
* 建议在大多数情况下使用异步的 query() 函数。
|
|
928
|
+
*
|
|
929
|
+
* @param prompt - 用户提示文本
|
|
930
|
+
* @param files - 可选的文件路径数组,用于上下文
|
|
931
|
+
* @param options - 可选的 iFlow 配置选项
|
|
932
|
+
* @returns string - 完整的 AI 响应文本
|
|
933
|
+
* @throws Error - 如果查询过程中发生错误
|
|
934
|
+
*
|
|
935
|
+
* @example
|
|
936
|
+
* ```typescript
|
|
937
|
+
* try {
|
|
938
|
+
* const response = querySync("Hello, world!");
|
|
939
|
+
* console.log(response);
|
|
940
|
+
* } catch (error) {
|
|
941
|
+
* console.error("Query failed:", error);
|
|
942
|
+
* }
|
|
943
|
+
* ```
|
|
944
|
+
*/
|
|
945
|
+
export declare function querySync(prompt: string, files?: string[], options?: IFlowOptions): string;
|
|
946
|
+
/**
|
|
947
|
+
* 流式查询函数 - 实时返回响应片段
|
|
948
|
+
*
|
|
949
|
+
* 使用异步生成器模式,可以实时接收 AI 响应的每个文本片段,
|
|
950
|
+
* 适合需要实时显示响应进度的场景。
|
|
951
|
+
*
|
|
952
|
+
* @param prompt - 用户提示文本
|
|
953
|
+
* @param files - 可选的文件路径数组,用于上下文
|
|
954
|
+
* @param options - 可选的 iFlow 配置选项
|
|
955
|
+
* @yields string - AI 响应的文本片段
|
|
956
|
+
*
|
|
957
|
+
* @example
|
|
958
|
+
* ```typescript
|
|
959
|
+
* for await (const chunk of queryStream("Explain quantum computing")) {
|
|
960
|
+
* process.stdout.write(chunk); // 实时显示响应
|
|
961
|
+
* }
|
|
962
|
+
* ```
|
|
963
|
+
*/
|
|
964
|
+
export declare function queryStream(prompt: string, files?: string[], options?: IFlowOptions): AsyncGenerator<string>;
|
|
965
|
+
|
|
966
|
+
export {};
|