@iflow-ai/iflow-cli-sdk 0.2.0-beta.9 → 0.2.1-beta.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/CHANGELOG.md +19 -12
- package/README_CN.md +39 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +314 -68
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
+
import { ExecaChildProcess } from 'execa';
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* iFlow SDK 错误类定义
|
|
5
7
|
*
|
|
@@ -255,6 +257,15 @@ export interface AuthMethodInfo {
|
|
|
255
257
|
baseUrl?: string;
|
|
256
258
|
modelName?: string;
|
|
257
259
|
}
|
|
260
|
+
/**
|
|
261
|
+
* 传输模式枚举
|
|
262
|
+
*/
|
|
263
|
+
export declare enum TransportMode {
|
|
264
|
+
/** WebSocket 模式 - 通过 WebSocket 连接通信(默认) */
|
|
265
|
+
WEBSOCKET = "websocket",
|
|
266
|
+
/** stdio 模式 - 通过标准输入输出通信 */
|
|
267
|
+
STDIO = "stdio"
|
|
268
|
+
}
|
|
258
269
|
export interface IFlowOptions {
|
|
259
270
|
url?: string;
|
|
260
271
|
cwd?: string;
|
|
@@ -264,6 +275,26 @@ export interface IFlowOptions {
|
|
|
264
275
|
processStartPort?: number;
|
|
265
276
|
autoStartProcess?: boolean;
|
|
266
277
|
stream?: boolean;
|
|
278
|
+
/** 传输模式,可选 "websocket"(默认)或 "stdio" */
|
|
279
|
+
transportMode?: `${TransportMode}`;
|
|
280
|
+
/**
|
|
281
|
+
* 自定义 iflow 可执行文件的绝对路径(可选)
|
|
282
|
+
*
|
|
283
|
+
* @remarks
|
|
284
|
+
* - 如果指定,将优先使用此路径,不会执行系统 PATH 查找
|
|
285
|
+
* - 必须是绝对路径(如 `/usr/local/bin/iflow` 或 `C:\Program Files\iflow\iflow.exe`)
|
|
286
|
+
* - SDK 会验证文件是否存在且可执行
|
|
287
|
+
* - 如果路径无效,会立即抛出错误
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```typescript
|
|
291
|
+
* const client = new IFlowClient({
|
|
292
|
+
* iflowPath: "/opt/custom/iflow",
|
|
293
|
+
* autoStartProcess: true
|
|
294
|
+
* });
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
iflowPath?: string;
|
|
267
298
|
authMethodId?: string;
|
|
268
299
|
authMethodInfo?: AuthMethodInfo;
|
|
269
300
|
mcpServers?: MCPServerConfigs;
|
|
@@ -424,8 +455,6 @@ export interface PlanMessage {
|
|
|
424
455
|
type: `${MessageType.PLAN}`;
|
|
425
456
|
/** 计划项 */
|
|
426
457
|
entries: PlanEntry[];
|
|
427
|
-
/** 会话 ID */
|
|
428
|
-
sessionId: string;
|
|
429
458
|
}
|
|
430
459
|
/** 用户消息片段接口 */
|
|
431
460
|
export interface UserMessageChunk {
|
|
@@ -436,7 +465,6 @@ export interface UserMessageChunk {
|
|
|
436
465
|
export interface UserMessage {
|
|
437
466
|
type: `${MessageType.USER}`;
|
|
438
467
|
chunks: UserMessageChunk[];
|
|
439
|
-
sessionId: string;
|
|
440
468
|
}
|
|
441
469
|
/** 助手消息接口 */
|
|
442
470
|
export interface AssistantMessage {
|
|
@@ -446,7 +474,6 @@ export interface AssistantMessage {
|
|
|
446
474
|
text?: string;
|
|
447
475
|
thought?: string;
|
|
448
476
|
};
|
|
449
|
-
sessionId: string;
|
|
450
477
|
agentId?: string;
|
|
451
478
|
agentInfo?: AgentInfo;
|
|
452
479
|
}
|
|
@@ -475,7 +502,6 @@ export interface ToolCallConfirmation {
|
|
|
475
502
|
export interface ToolCallMessage {
|
|
476
503
|
type: `${MessageType.TOOL_CALL}`;
|
|
477
504
|
id: string;
|
|
478
|
-
sessionId: string;
|
|
479
505
|
label: string;
|
|
480
506
|
icon: {
|
|
481
507
|
type: `${ToolCallIconType}`;
|
|
@@ -496,13 +522,10 @@ export interface ErrorMessage {
|
|
|
496
522
|
code: number;
|
|
497
523
|
message: string;
|
|
498
524
|
details?: Record<string, unknown>;
|
|
499
|
-
sessionId?: string;
|
|
500
525
|
}
|
|
501
526
|
export interface TaskFinishMessage {
|
|
502
527
|
type: `${MessageType.TASK_FINISH}`;
|
|
503
528
|
stopReason?: `${StopReason}`;
|
|
504
|
-
/** 会话 ID */
|
|
505
|
-
sessionId: string;
|
|
506
529
|
}
|
|
507
530
|
export interface QuestionOption {
|
|
508
531
|
label: string;
|
|
@@ -517,14 +540,10 @@ export interface Question {
|
|
|
517
540
|
export interface AskUserQuestionsMessage {
|
|
518
541
|
type: `${MessageType.ASK_USER_QUESTIONS}`;
|
|
519
542
|
questions: Question[];
|
|
520
|
-
/** 会话 ID */
|
|
521
|
-
sessionId: string;
|
|
522
543
|
}
|
|
523
544
|
export interface ExitPlanModeMessage {
|
|
524
545
|
type: `${MessageType.EXIT_PLAN_MODE}`;
|
|
525
546
|
plan: string;
|
|
526
|
-
/** 会话 ID */
|
|
527
|
-
sessionId: string;
|
|
528
547
|
}
|
|
529
548
|
export interface PermissionRequestMessage {
|
|
530
549
|
type: `${MessageType.PERMISSION_REQUEST}`;
|
|
@@ -563,6 +582,19 @@ export interface Modes {
|
|
|
563
582
|
currentModeId: string;
|
|
564
583
|
availableModes: ModeInfo[];
|
|
565
584
|
}
|
|
585
|
+
/**
|
|
586
|
+
* 模型能力描述接口
|
|
587
|
+
*/
|
|
588
|
+
export interface ModelCapabilities {
|
|
589
|
+
/** 是否支持深度思考/推理模式(如 Chain of Thought) */
|
|
590
|
+
thinking?: boolean;
|
|
591
|
+
/** 是否支持图像输入/理解 */
|
|
592
|
+
image?: boolean;
|
|
593
|
+
/** 是否支持音频输入/理解 */
|
|
594
|
+
audio?: boolean;
|
|
595
|
+
/** 是否支持视频输入/理解 */
|
|
596
|
+
video?: boolean;
|
|
597
|
+
}
|
|
566
598
|
/**
|
|
567
599
|
* 模型信息接口
|
|
568
600
|
*/
|
|
@@ -570,6 +602,8 @@ export interface ModelInfo {
|
|
|
570
602
|
id: string;
|
|
571
603
|
name: string;
|
|
572
604
|
description: string;
|
|
605
|
+
/** 模型支持的能力集合 */
|
|
606
|
+
capabilities?: ModelCapabilities;
|
|
573
607
|
}
|
|
574
608
|
/**
|
|
575
609
|
* 模型集合接口
|
|
@@ -752,71 +786,55 @@ export interface SetThinkResult {
|
|
|
752
786
|
currentThinkConfig?: string;
|
|
753
787
|
}
|
|
754
788
|
/**
|
|
755
|
-
*
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
/** 日志级别,默认为 INFO */
|
|
759
|
-
level?: keyof typeof LogLevel;
|
|
760
|
-
}
|
|
761
|
-
declare class Logger {
|
|
762
|
-
private readonly level;
|
|
763
|
-
constructor(options?: Partial<LoggerOptions>);
|
|
764
|
-
debug(message: string): void;
|
|
765
|
-
info(message: string): void;
|
|
766
|
-
warn(message: string): void;
|
|
767
|
-
error(message: string, error?: Error): void;
|
|
768
|
-
private log;
|
|
769
|
-
}
|
|
770
|
-
/**
|
|
771
|
-
* Transport 类构造选项
|
|
789
|
+
* ITransport - 传输层抽象接口
|
|
790
|
+
*
|
|
791
|
+
* 定义了传输层的统一接口,支持不同的传输协议(WebSocket、stdio 等)
|
|
772
792
|
*/
|
|
773
|
-
export interface
|
|
774
|
-
/** WebSocket 连接 URL */
|
|
775
|
-
url: string;
|
|
776
|
-
/** 日志记录器实例 */
|
|
777
|
-
logger?: Logger;
|
|
778
|
-
/** 连接超时时间(毫秒),默认 300000ms (5分钟) */
|
|
779
|
-
timeout?: number;
|
|
780
|
-
}
|
|
781
|
-
declare class Transport {
|
|
782
|
-
private readonly url;
|
|
783
|
-
private readonly logger;
|
|
784
|
-
private readonly timeout;
|
|
785
|
-
private ws;
|
|
786
|
-
private connected;
|
|
787
|
-
private messageQueue;
|
|
788
|
-
private waitingResolvers;
|
|
789
|
-
private generalWaiters;
|
|
790
|
-
constructor(options: TransportOptions);
|
|
791
|
-
get isConnected(): boolean;
|
|
792
|
-
private checkConnected;
|
|
793
|
-
connect(): Promise<void>;
|
|
793
|
+
export interface ITransport {
|
|
794
794
|
/**
|
|
795
|
-
*
|
|
796
|
-
* 收到消息后,优先分发给等待的 resolver,否则放入消息队列
|
|
795
|
+
* 检查是否已连接
|
|
797
796
|
*/
|
|
798
|
-
|
|
797
|
+
readonly isConnected: boolean;
|
|
799
798
|
/**
|
|
800
|
-
*
|
|
799
|
+
* 建立连接
|
|
800
|
+
*/
|
|
801
|
+
connect(): Promise<void>;
|
|
802
|
+
/**
|
|
803
|
+
* 关闭连接
|
|
801
804
|
*/
|
|
802
|
-
private rejectAllWaiters;
|
|
803
805
|
close(): Promise<void>;
|
|
806
|
+
/**
|
|
807
|
+
* 发送消息
|
|
808
|
+
* @param data 要发送的数据,可以是字符串或对象
|
|
809
|
+
*/
|
|
804
810
|
send(data: string | object): Promise<void>;
|
|
805
811
|
/**
|
|
806
812
|
* 等待指定 requestId 的响应
|
|
807
|
-
* 用于 Protocol 层等待特定请求的响应,支持并发请求
|
|
808
813
|
* @param requestId 请求 ID(可以是 number 或 string)
|
|
809
814
|
* @returns Promise,resolve 时返回响应消息的原始字符串
|
|
810
815
|
*/
|
|
811
816
|
waitForResponse(requestId: number | string): Promise<string>;
|
|
812
|
-
receive(): AsyncGenerator<string>;
|
|
813
817
|
/**
|
|
814
|
-
*
|
|
815
|
-
*
|
|
816
|
-
* - 如果不提供 requestId,则从消息队列获取,队列为空时等待任何新消息
|
|
817
|
-
* @param requestId 可选的请求 ID(可以是 number 或 string),用于精确匹配响应
|
|
818
|
+
* 接收消息的异步生成器
|
|
819
|
+
* @returns 异步迭代器,yield 每条消息的原始字符串
|
|
818
820
|
*/
|
|
819
|
-
|
|
821
|
+
receive(): AsyncGenerator<string>;
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* 日志记录器配置选项
|
|
825
|
+
*/
|
|
826
|
+
export interface LoggerOptions {
|
|
827
|
+
/** 日志级别,默认为 INFO */
|
|
828
|
+
level?: keyof typeof LogLevel;
|
|
829
|
+
}
|
|
830
|
+
declare class Logger {
|
|
831
|
+
private readonly level;
|
|
832
|
+
constructor(options?: Partial<LoggerOptions>);
|
|
833
|
+
debug(message: string): void;
|
|
834
|
+
info(message: string): void;
|
|
835
|
+
warn(message: string): void;
|
|
836
|
+
error(message: string, error?: Error): void;
|
|
837
|
+
private log;
|
|
820
838
|
}
|
|
821
839
|
/**
|
|
822
840
|
* FileHandler 类构造选项
|
|
@@ -966,8 +984,8 @@ export interface Selection {
|
|
|
966
984
|
export interface ProtocolOptions {
|
|
967
985
|
/** 日志记录器实例 */
|
|
968
986
|
logger?: Logger;
|
|
969
|
-
/** WebSocket
|
|
970
|
-
transport:
|
|
987
|
+
/** 传输层实例(WebSocket 或 stdio) */
|
|
988
|
+
transport: ITransport;
|
|
971
989
|
/** 文件处理器实例,用于文件读写操作 */
|
|
972
990
|
fileHandler?: FileHandler;
|
|
973
991
|
/** 权限模式,控制工具调用的审批方式 */
|
|
@@ -1116,7 +1134,7 @@ export declare class IFlowClient {
|
|
|
1116
1134
|
/** ACP 协议处理器 */
|
|
1117
1135
|
protected protocol: Protocol | null;
|
|
1118
1136
|
/** WebSocket 传输层 */
|
|
1119
|
-
protected transport:
|
|
1137
|
+
protected transport: ITransport | null;
|
|
1120
1138
|
/** 连接状态标识 */
|
|
1121
1139
|
protected connected: boolean;
|
|
1122
1140
|
/** 认证状态标识 */
|
|
@@ -1169,12 +1187,74 @@ export declare class IFlowClient {
|
|
|
1169
1187
|
constructor(options?: IFlowOptions);
|
|
1170
1188
|
isConnected(): boolean;
|
|
1171
1189
|
getConnectionState(): "disconnected" | "connecting" | "connected";
|
|
1172
|
-
|
|
1190
|
+
getSessionId(): string | null;
|
|
1191
|
+
/**
|
|
1192
|
+
* 连接到 iFlow CLI
|
|
1193
|
+
*
|
|
1194
|
+
* @param options - 连接选项
|
|
1195
|
+
* @param options.skipSession - 是否跳过会话创建/加载(默认 false)
|
|
1196
|
+
* - `false`(默认):完整连接流程,包括初始化、认证、创建/加载会话
|
|
1197
|
+
* - `true`:执行初始化和认证,但跳过会话创建/加载,需要后续手动调用 `newSession()` 或 `loadSession()`
|
|
1198
|
+
*
|
|
1199
|
+
* @example
|
|
1200
|
+
* ```typescript
|
|
1201
|
+
* // 标准连接(自动创建/加载会话)
|
|
1202
|
+
* await client.connect();
|
|
1203
|
+
*
|
|
1204
|
+
* // 连接并认证,但不创建会话(需要手动调用 newSession 或 loadSession)
|
|
1205
|
+
* await client.connect({ skipSession: true });
|
|
1206
|
+
* await client.newSession(); // 或 await client.loadSession('session-id');
|
|
1207
|
+
* ```
|
|
1208
|
+
*/
|
|
1209
|
+
connect({ skipSession }?: {
|
|
1210
|
+
skipSession?: boolean;
|
|
1211
|
+
}): Promise<void>;
|
|
1173
1212
|
private _doConnect;
|
|
1213
|
+
/**
|
|
1214
|
+
* 确保客户端已认证
|
|
1215
|
+
* @private
|
|
1216
|
+
*/
|
|
1217
|
+
private _ensureAuthenticated;
|
|
1218
|
+
/**
|
|
1219
|
+
* 创建新会话的核心逻辑(内部使用)
|
|
1220
|
+
* @private
|
|
1221
|
+
*/
|
|
1222
|
+
private _createNewSession;
|
|
1223
|
+
/**
|
|
1224
|
+
* 初始化会话(创建或加载)
|
|
1225
|
+
* @private
|
|
1226
|
+
*/
|
|
1227
|
+
private _initializeSession;
|
|
1228
|
+
/**
|
|
1229
|
+
* 加载已存在的会话
|
|
1230
|
+
*
|
|
1231
|
+
* @param sessionId - 要加载的会话 ID
|
|
1232
|
+
*
|
|
1233
|
+
* @example
|
|
1234
|
+
* ```typescript
|
|
1235
|
+
* // 使用 skipSession 连接后,手动加载会话
|
|
1236
|
+
* await client.connect({ skipSession: true });
|
|
1237
|
+
* await client.loadSession("existing-session-id");
|
|
1238
|
+
* ```
|
|
1239
|
+
*/
|
|
1174
1240
|
loadSession(sessionId: string): Promise<void>;
|
|
1241
|
+
/**
|
|
1242
|
+
* 创建新会话
|
|
1243
|
+
*
|
|
1244
|
+
* @returns 新创建的会话 ID
|
|
1245
|
+
*
|
|
1246
|
+
* @example
|
|
1247
|
+
* ```typescript
|
|
1248
|
+
* // 使用 skipSession 连接后,手动创建新会话
|
|
1249
|
+
* await client.connect({ skipSession: true });
|
|
1250
|
+
* const sessionId = await client.newSession();
|
|
1251
|
+
* console.log(`Created session: ${sessionId}`);
|
|
1252
|
+
* ```
|
|
1253
|
+
*/
|
|
1254
|
+
newSession(): Promise<string>;
|
|
1175
1255
|
disconnect(): Promise<void>;
|
|
1176
|
-
sendMessage(text: string, files?: Array<FilePath | ImagePrompt | Selection
|
|
1177
|
-
interrupt(
|
|
1256
|
+
sendMessage(text: string, files?: Array<FilePath | ImagePrompt | Selection>): Promise<void>;
|
|
1257
|
+
interrupt(): Promise<void>;
|
|
1178
1258
|
receiveMessages(): AsyncGenerator<Message>;
|
|
1179
1259
|
/**
|
|
1180
1260
|
* @deprecated 此方法已弃用。请使用 respondToToolConfirmation 方法来处理工具权限确认。
|
|
@@ -1230,6 +1310,172 @@ export declare class RawDataClient extends IFlowClient {
|
|
|
1230
1310
|
getProtocolStats(): Record<string, any>;
|
|
1231
1311
|
sendRaw(data: string | Record<string, any>): Promise<void>;
|
|
1232
1312
|
}
|
|
1313
|
+
/**
|
|
1314
|
+
* Transport 类构造选项
|
|
1315
|
+
*/
|
|
1316
|
+
export interface TransportOptions {
|
|
1317
|
+
/** WebSocket 连接 URL */
|
|
1318
|
+
url: string;
|
|
1319
|
+
/** 日志记录器实例 */
|
|
1320
|
+
logger?: Logger;
|
|
1321
|
+
/** 连接超时时间(毫秒),默认 300000ms (5分钟) */
|
|
1322
|
+
timeout?: number;
|
|
1323
|
+
}
|
|
1324
|
+
/**
|
|
1325
|
+
* Transport - WebSocket 传输层
|
|
1326
|
+
*
|
|
1327
|
+
* 负责管理与 iFlow CLI 的 WebSocket 连接,提供:
|
|
1328
|
+
* - 连接建立和断开管理
|
|
1329
|
+
* - 消息发送和接收
|
|
1330
|
+
* - 连接状态监控
|
|
1331
|
+
* - 错误处理和重连机制
|
|
1332
|
+
* - 超时控制
|
|
1333
|
+
*
|
|
1334
|
+
* 这是 SDK 的底层通信组件,所有与 iFlow CLI 的数据交换都通过此类进行。
|
|
1335
|
+
*
|
|
1336
|
+
* @example
|
|
1337
|
+
* ```typescript
|
|
1338
|
+
* const transport = new Transport({
|
|
1339
|
+
* url: "ws://localhost:8090/acp",
|
|
1340
|
+
* timeout: 30000,
|
|
1341
|
+
* logger: new Logger({ level: "DEBUG" })
|
|
1342
|
+
* });
|
|
1343
|
+
*
|
|
1344
|
+
* await transport.connect();
|
|
1345
|
+
* transport.send({ method: "initialize", params: {} });
|
|
1346
|
+
*
|
|
1347
|
+
* transport.onMessage((message) => {
|
|
1348
|
+
* console.log("Received:", message);
|
|
1349
|
+
* });
|
|
1350
|
+
* ```
|
|
1351
|
+
*/
|
|
1352
|
+
export declare class Transport implements ITransport {
|
|
1353
|
+
private readonly url;
|
|
1354
|
+
private readonly logger;
|
|
1355
|
+
private readonly timeout;
|
|
1356
|
+
private ws;
|
|
1357
|
+
private connected;
|
|
1358
|
+
private messageQueue;
|
|
1359
|
+
private waitingResolvers;
|
|
1360
|
+
private generalWaiters;
|
|
1361
|
+
constructor(options: TransportOptions);
|
|
1362
|
+
get isConnected(): boolean;
|
|
1363
|
+
private checkConnected;
|
|
1364
|
+
connect(): Promise<void>;
|
|
1365
|
+
/**
|
|
1366
|
+
* 设置持续的消息监听器
|
|
1367
|
+
* 收到消息后,优先分发给等待的 resolver,否则放入消息队列
|
|
1368
|
+
*/
|
|
1369
|
+
private setupMessageListener;
|
|
1370
|
+
/**
|
|
1371
|
+
* 拒绝所有等待的 Promise(包括基于 requestId 的和通用的)
|
|
1372
|
+
*/
|
|
1373
|
+
private rejectAllWaiters;
|
|
1374
|
+
close(): Promise<void>;
|
|
1375
|
+
send(data: string | object): Promise<void>;
|
|
1376
|
+
/**
|
|
1377
|
+
* 等待指定 requestId 的响应
|
|
1378
|
+
* 用于 Protocol 层等待特定请求的响应,支持并发请求
|
|
1379
|
+
* @param requestId 请求 ID(可以是 number 或 string)
|
|
1380
|
+
* @returns Promise,resolve 时返回响应消息的原始字符串
|
|
1381
|
+
*/
|
|
1382
|
+
waitForResponse(requestId: number | string): Promise<string>;
|
|
1383
|
+
receive(): AsyncGenerator<string>;
|
|
1384
|
+
/**
|
|
1385
|
+
* 接收原始数据
|
|
1386
|
+
* - 如果提供 requestId,则等待匹配该 requestId 的响应
|
|
1387
|
+
* - 如果不提供 requestId,则从消息队列获取,队列为空时等待任何新消息
|
|
1388
|
+
* @param requestId 可选的请求 ID(可以是 number 或 string),用于精确匹配响应
|
|
1389
|
+
*/
|
|
1390
|
+
private receiveRawData;
|
|
1391
|
+
}
|
|
1392
|
+
/**
|
|
1393
|
+
* StdioTransport 类构造选项
|
|
1394
|
+
*/
|
|
1395
|
+
export interface StdioTransportOptions {
|
|
1396
|
+
/** 子进程实例,用于 stdin/stdout 通信 */
|
|
1397
|
+
process: ExecaChildProcess;
|
|
1398
|
+
/** 日志记录器实例 */
|
|
1399
|
+
logger?: Logger;
|
|
1400
|
+
/** 连接超时时间(毫秒),默认 300000ms (5分钟) */
|
|
1401
|
+
timeout?: number;
|
|
1402
|
+
/** 消息队列最大大小,默认 1000 条消息 */
|
|
1403
|
+
maxQueueSize?: number;
|
|
1404
|
+
}
|
|
1405
|
+
/**
|
|
1406
|
+
* StdioTransport - stdio 传输层
|
|
1407
|
+
*
|
|
1408
|
+
* 负责通过 stdin/stdout 与 iFlow CLI 进程通信,提供:
|
|
1409
|
+
* - 基于标准输入输出的通信
|
|
1410
|
+
* - 消息发送和接收
|
|
1411
|
+
* - 连接状态监控
|
|
1412
|
+
* - 错误处理
|
|
1413
|
+
* - 超时控制
|
|
1414
|
+
*
|
|
1415
|
+
* 这是 SDK 支持 stdio 协议的核心组件,适用于非 WebSocket 场景。
|
|
1416
|
+
*
|
|
1417
|
+
* @example
|
|
1418
|
+
* ```typescript
|
|
1419
|
+
* import { execa } from "execa";
|
|
1420
|
+
*
|
|
1421
|
+
* const process = execa("iflow", ["--experimental-acp", "--stdio"]);
|
|
1422
|
+
* const transport = new StdioTransport({
|
|
1423
|
+
* process,
|
|
1424
|
+
* timeout: 30000,
|
|
1425
|
+
* logger: new Logger({ level: "DEBUG" })
|
|
1426
|
+
* });
|
|
1427
|
+
*
|
|
1428
|
+
* await transport.connect();
|
|
1429
|
+
* transport.send({ method: "initialize", params: {} });
|
|
1430
|
+
*
|
|
1431
|
+
* for await (const message of transport.receive()) {
|
|
1432
|
+
* console.log("Received:", message);
|
|
1433
|
+
* }
|
|
1434
|
+
* ```
|
|
1435
|
+
*/
|
|
1436
|
+
export declare class StdioTransport implements ITransport {
|
|
1437
|
+
private readonly logger;
|
|
1438
|
+
private readonly timeout;
|
|
1439
|
+
private readonly childProcess;
|
|
1440
|
+
private readonly maxQueueSize;
|
|
1441
|
+
private connected;
|
|
1442
|
+
private readlineInterface;
|
|
1443
|
+
private errorHandler;
|
|
1444
|
+
private exitHandler;
|
|
1445
|
+
private messageQueue;
|
|
1446
|
+
private waitingResolvers;
|
|
1447
|
+
private generalWaiters;
|
|
1448
|
+
constructor(options: StdioTransportOptions);
|
|
1449
|
+
get isConnected(): boolean;
|
|
1450
|
+
private checkConnected;
|
|
1451
|
+
connect(): Promise<void>;
|
|
1452
|
+
/**
|
|
1453
|
+
* 设置持续的消息监听器
|
|
1454
|
+
* 收到消息后,优先分发给等待的 resolver,否则放入消息队列
|
|
1455
|
+
*/
|
|
1456
|
+
private setupMessageListener;
|
|
1457
|
+
/**
|
|
1458
|
+
* 拒绝所有等待的 Promise(包括基于 requestId 的和通用的)
|
|
1459
|
+
*/
|
|
1460
|
+
private rejectAllWaiters;
|
|
1461
|
+
close(): Promise<void>;
|
|
1462
|
+
send(data: string | object): Promise<void>;
|
|
1463
|
+
/**
|
|
1464
|
+
* 等待指定 requestId 的响应
|
|
1465
|
+
* 用于 Protocol 层等待特定请求的响应,支持并发请求
|
|
1466
|
+
* @param requestId 请求 ID(可以是 number 或 string)
|
|
1467
|
+
* @returns Promise,resolve 时返回响应消息的原始字符串
|
|
1468
|
+
*/
|
|
1469
|
+
waitForResponse(requestId: number | string): Promise<string>;
|
|
1470
|
+
receive(): AsyncGenerator<string>;
|
|
1471
|
+
/**
|
|
1472
|
+
* 接收原始数据
|
|
1473
|
+
* - 如果提供 requestId,则等待匹配该 requestId 的响应
|
|
1474
|
+
* - 如果不提供 requestId,则从消息队列获取,队列为空时等待任何新消息
|
|
1475
|
+
* @param requestId 可选的请求 ID(可以是 number 或 string),用于精确匹配响应
|
|
1476
|
+
*/
|
|
1477
|
+
private receiveRawData;
|
|
1478
|
+
}
|
|
1233
1479
|
/**
|
|
1234
1480
|
* 简单的异步查询函数 - 发送提示并等待完整响应
|
|
1235
1481
|
*
|