@iflow-ai/iflow-cli-sdk 0.2.1 → 0.2.2
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 +22 -0
- package/README_CN.md +27 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +307 -56
- 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;
|
|
@@ -755,71 +786,55 @@ export interface SetThinkResult {
|
|
|
755
786
|
currentThinkConfig?: string;
|
|
756
787
|
}
|
|
757
788
|
/**
|
|
758
|
-
*
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
/** 日志级别,默认为 INFO */
|
|
762
|
-
level?: keyof typeof LogLevel;
|
|
763
|
-
}
|
|
764
|
-
declare class Logger {
|
|
765
|
-
private readonly level;
|
|
766
|
-
constructor(options?: Partial<LoggerOptions>);
|
|
767
|
-
debug(message: string): void;
|
|
768
|
-
info(message: string): void;
|
|
769
|
-
warn(message: string): void;
|
|
770
|
-
error(message: string, error?: Error): void;
|
|
771
|
-
private log;
|
|
772
|
-
}
|
|
773
|
-
/**
|
|
774
|
-
* Transport 类构造选项
|
|
789
|
+
* ITransport - 传输层抽象接口
|
|
790
|
+
*
|
|
791
|
+
* 定义了传输层的统一接口,支持不同的传输协议(WebSocket、stdio 等)
|
|
775
792
|
*/
|
|
776
|
-
export interface
|
|
777
|
-
/** WebSocket 连接 URL */
|
|
778
|
-
url: string;
|
|
779
|
-
/** 日志记录器实例 */
|
|
780
|
-
logger?: Logger;
|
|
781
|
-
/** 连接超时时间(毫秒),默认 300000ms (5分钟) */
|
|
782
|
-
timeout?: number;
|
|
783
|
-
}
|
|
784
|
-
declare class Transport {
|
|
785
|
-
private readonly url;
|
|
786
|
-
private readonly logger;
|
|
787
|
-
private readonly timeout;
|
|
788
|
-
private ws;
|
|
789
|
-
private connected;
|
|
790
|
-
private messageQueue;
|
|
791
|
-
private waitingResolvers;
|
|
792
|
-
private generalWaiters;
|
|
793
|
-
constructor(options: TransportOptions);
|
|
794
|
-
get isConnected(): boolean;
|
|
795
|
-
private checkConnected;
|
|
796
|
-
connect(): Promise<void>;
|
|
793
|
+
export interface ITransport {
|
|
797
794
|
/**
|
|
798
|
-
*
|
|
799
|
-
* 收到消息后,优先分发给等待的 resolver,否则放入消息队列
|
|
795
|
+
* 检查是否已连接
|
|
800
796
|
*/
|
|
801
|
-
|
|
797
|
+
readonly isConnected: boolean;
|
|
802
798
|
/**
|
|
803
|
-
*
|
|
799
|
+
* 建立连接
|
|
800
|
+
*/
|
|
801
|
+
connect(): Promise<void>;
|
|
802
|
+
/**
|
|
803
|
+
* 关闭连接
|
|
804
804
|
*/
|
|
805
|
-
private rejectAllWaiters;
|
|
806
805
|
close(): Promise<void>;
|
|
806
|
+
/**
|
|
807
|
+
* 发送消息
|
|
808
|
+
* @param data 要发送的数据,可以是字符串或对象
|
|
809
|
+
*/
|
|
807
810
|
send(data: string | object): Promise<void>;
|
|
808
811
|
/**
|
|
809
812
|
* 等待指定 requestId 的响应
|
|
810
|
-
* 用于 Protocol 层等待特定请求的响应,支持并发请求
|
|
811
813
|
* @param requestId 请求 ID(可以是 number 或 string)
|
|
812
814
|
* @returns Promise,resolve 时返回响应消息的原始字符串
|
|
813
815
|
*/
|
|
814
816
|
waitForResponse(requestId: number | string): Promise<string>;
|
|
815
|
-
receive(): AsyncGenerator<string>;
|
|
816
817
|
/**
|
|
817
|
-
*
|
|
818
|
-
*
|
|
819
|
-
* - 如果不提供 requestId,则从消息队列获取,队列为空时等待任何新消息
|
|
820
|
-
* @param requestId 可选的请求 ID(可以是 number 或 string),用于精确匹配响应
|
|
818
|
+
* 接收消息的异步生成器
|
|
819
|
+
* @returns 异步迭代器,yield 每条消息的原始字符串
|
|
821
820
|
*/
|
|
822
|
-
|
|
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;
|
|
823
838
|
}
|
|
824
839
|
/**
|
|
825
840
|
* FileHandler 类构造选项
|
|
@@ -969,14 +984,16 @@ export interface Selection {
|
|
|
969
984
|
export interface ProtocolOptions {
|
|
970
985
|
/** 日志记录器实例 */
|
|
971
986
|
logger?: Logger;
|
|
972
|
-
/** WebSocket
|
|
973
|
-
transport:
|
|
987
|
+
/** 传输层实例(WebSocket 或 stdio) */
|
|
988
|
+
transport: ITransport;
|
|
974
989
|
/** 文件处理器实例,用于文件读写操作 */
|
|
975
990
|
fileHandler?: FileHandler;
|
|
976
991
|
/** 权限模式,控制工具调用的审批方式 */
|
|
977
992
|
permissionMode?: `${PermissionMode}`;
|
|
978
993
|
/** 自动批准的工具类型列表 */
|
|
979
994
|
autoApproveTypes?: string[];
|
|
995
|
+
/** 协议操作超时时间(毫秒),用于 initialize/authenticate/createSession 等 RPC 调用,默认 30000 */
|
|
996
|
+
timeout?: number;
|
|
980
997
|
}
|
|
981
998
|
declare class Protocol {
|
|
982
999
|
private readonly logger;
|
|
@@ -984,6 +1001,8 @@ declare class Protocol {
|
|
|
984
1001
|
private readonly fileHandler?;
|
|
985
1002
|
private readonly permissionMode;
|
|
986
1003
|
private readonly autoApproveTypes;
|
|
1004
|
+
/** 协议操作超时时间(毫秒) */
|
|
1005
|
+
private readonly timeout;
|
|
987
1006
|
private requestId;
|
|
988
1007
|
private initialized;
|
|
989
1008
|
private authenticated;
|
|
@@ -1019,6 +1038,10 @@ declare class Protocol {
|
|
|
1019
1038
|
sessionId: string;
|
|
1020
1039
|
cwd?: string;
|
|
1021
1040
|
mcpServers?: MCPServerConfigs;
|
|
1041
|
+
hooks?: HookConfigs;
|
|
1042
|
+
commands?: CommandConfigs;
|
|
1043
|
+
agents?: SubAgentConfigs;
|
|
1044
|
+
settings?: SessionSettings;
|
|
1022
1045
|
}): Promise<void>;
|
|
1023
1046
|
sendPrompt(params: {
|
|
1024
1047
|
sessionId: string;
|
|
@@ -1037,7 +1060,7 @@ declare class Protocol {
|
|
|
1037
1060
|
}): Promise<string>;
|
|
1038
1061
|
setThink(params: ACPSetThinkParams): Promise<ACPSetThinkResult>;
|
|
1039
1062
|
respondToAskUserQuestions(requestId: ACPRequestId, answers: Record<string, string | string[]>): Promise<void>;
|
|
1040
|
-
respondToExitPlanMode(requestId: ACPRequestId, approved: boolean): Promise<void>;
|
|
1063
|
+
respondToExitPlanMode(requestId: ACPRequestId, approved: boolean, reason?: string): Promise<void>;
|
|
1041
1064
|
sendPermissionResponse(requestId: ACPRequestId, optionId: string): Promise<void>;
|
|
1042
1065
|
cancelPermissionResponse(requestId: ACPRequestId): Promise<void>;
|
|
1043
1066
|
handleMessages(): AsyncGenerator<ProtocolMessage>;
|
|
@@ -1119,7 +1142,7 @@ export declare class IFlowClient {
|
|
|
1119
1142
|
/** ACP 协议处理器 */
|
|
1120
1143
|
protected protocol: Protocol | null;
|
|
1121
1144
|
/** WebSocket 传输层 */
|
|
1122
|
-
protected transport:
|
|
1145
|
+
protected transport: ITransport | null;
|
|
1123
1146
|
/** 连接状态标识 */
|
|
1124
1147
|
protected connected: boolean;
|
|
1125
1148
|
/** 认证状态标识 */
|
|
@@ -1172,9 +1195,71 @@ export declare class IFlowClient {
|
|
|
1172
1195
|
constructor(options?: IFlowOptions);
|
|
1173
1196
|
isConnected(): boolean;
|
|
1174
1197
|
getConnectionState(): "disconnected" | "connecting" | "connected";
|
|
1175
|
-
|
|
1198
|
+
getSessionId(): string | null;
|
|
1199
|
+
/**
|
|
1200
|
+
* 连接到 iFlow CLI
|
|
1201
|
+
*
|
|
1202
|
+
* @param options - 连接选项
|
|
1203
|
+
* @param options.skipSession - 是否跳过会话创建/加载(默认 false)
|
|
1204
|
+
* - `false`(默认):完整连接流程,包括初始化、认证、创建/加载会话
|
|
1205
|
+
* - `true`:执行初始化和认证,但跳过会话创建/加载,需要后续手动调用 `newSession()` 或 `loadSession()`
|
|
1206
|
+
*
|
|
1207
|
+
* @example
|
|
1208
|
+
* ```typescript
|
|
1209
|
+
* // 标准连接(自动创建/加载会话)
|
|
1210
|
+
* await client.connect();
|
|
1211
|
+
*
|
|
1212
|
+
* // 连接并认证,但不创建会话(需要手动调用 newSession 或 loadSession)
|
|
1213
|
+
* await client.connect({ skipSession: true });
|
|
1214
|
+
* await client.newSession(); // 或 await client.loadSession('session-id');
|
|
1215
|
+
* ```
|
|
1216
|
+
*/
|
|
1217
|
+
connect({ skipSession }?: {
|
|
1218
|
+
skipSession?: boolean;
|
|
1219
|
+
}): Promise<void>;
|
|
1176
1220
|
private _doConnect;
|
|
1221
|
+
/**
|
|
1222
|
+
* 确保客户端已认证
|
|
1223
|
+
* @private
|
|
1224
|
+
*/
|
|
1225
|
+
private _ensureAuthenticated;
|
|
1226
|
+
/**
|
|
1227
|
+
* 创建新会话的核心逻辑(内部使用)
|
|
1228
|
+
* @private
|
|
1229
|
+
*/
|
|
1230
|
+
private _createNewSession;
|
|
1231
|
+
/**
|
|
1232
|
+
* 初始化会话(创建或加载)
|
|
1233
|
+
* @private
|
|
1234
|
+
*/
|
|
1235
|
+
private _initializeSession;
|
|
1236
|
+
/**
|
|
1237
|
+
* 加载已存在的会话
|
|
1238
|
+
*
|
|
1239
|
+
* @param sessionId - 要加载的会话 ID
|
|
1240
|
+
*
|
|
1241
|
+
* @example
|
|
1242
|
+
* ```typescript
|
|
1243
|
+
* // 使用 skipSession 连接后,手动加载会话
|
|
1244
|
+
* await client.connect({ skipSession: true });
|
|
1245
|
+
* await client.loadSession("existing-session-id");
|
|
1246
|
+
* ```
|
|
1247
|
+
*/
|
|
1177
1248
|
loadSession(sessionId: string): Promise<void>;
|
|
1249
|
+
/**
|
|
1250
|
+
* 创建新会话
|
|
1251
|
+
*
|
|
1252
|
+
* @returns 新创建的会话 ID
|
|
1253
|
+
*
|
|
1254
|
+
* @example
|
|
1255
|
+
* ```typescript
|
|
1256
|
+
* // 使用 skipSession 连接后,手动创建新会话
|
|
1257
|
+
* await client.connect({ skipSession: true });
|
|
1258
|
+
* const sessionId = await client.newSession();
|
|
1259
|
+
* console.log(`Created session: ${sessionId}`);
|
|
1260
|
+
* ```
|
|
1261
|
+
*/
|
|
1262
|
+
newSession(): Promise<string>;
|
|
1178
1263
|
disconnect(): Promise<void>;
|
|
1179
1264
|
sendMessage(text: string, files?: Array<FilePath | ImagePrompt | Selection>): Promise<void>;
|
|
1180
1265
|
interrupt(): Promise<void>;
|
|
@@ -1190,7 +1275,7 @@ export declare class IFlowClient {
|
|
|
1190
1275
|
*/
|
|
1191
1276
|
rejectToolCall(toolId: string): Promise<void>;
|
|
1192
1277
|
respondToAskUserQuestions(answers: Record<string, string | string[]>): Promise<void>;
|
|
1193
|
-
respondToExitPlanMode(approved: boolean): Promise<void>;
|
|
1278
|
+
respondToExitPlanMode(approved: boolean, reason?: string): Promise<void>;
|
|
1194
1279
|
respondToToolConfirmation(requestId: number | string, optionId: string): Promise<void>;
|
|
1195
1280
|
cancelToolConfirmation(requestId: number | string): Promise<void>;
|
|
1196
1281
|
/**
|
|
@@ -1233,6 +1318,172 @@ export declare class RawDataClient extends IFlowClient {
|
|
|
1233
1318
|
getProtocolStats(): Record<string, any>;
|
|
1234
1319
|
sendRaw(data: string | Record<string, any>): Promise<void>;
|
|
1235
1320
|
}
|
|
1321
|
+
/**
|
|
1322
|
+
* Transport 类构造选项
|
|
1323
|
+
*/
|
|
1324
|
+
export interface TransportOptions {
|
|
1325
|
+
/** WebSocket 连接 URL */
|
|
1326
|
+
url: string;
|
|
1327
|
+
/** 日志记录器实例 */
|
|
1328
|
+
logger?: Logger;
|
|
1329
|
+
/** 连接超时时间(毫秒),默认 300000ms (5分钟) */
|
|
1330
|
+
timeout?: number;
|
|
1331
|
+
}
|
|
1332
|
+
/**
|
|
1333
|
+
* Transport - WebSocket 传输层
|
|
1334
|
+
*
|
|
1335
|
+
* 负责管理与 iFlow CLI 的 WebSocket 连接,提供:
|
|
1336
|
+
* - 连接建立和断开管理
|
|
1337
|
+
* - 消息发送和接收
|
|
1338
|
+
* - 连接状态监控
|
|
1339
|
+
* - 错误处理和重连机制
|
|
1340
|
+
* - 超时控制
|
|
1341
|
+
*
|
|
1342
|
+
* 这是 SDK 的底层通信组件,所有与 iFlow CLI 的数据交换都通过此类进行。
|
|
1343
|
+
*
|
|
1344
|
+
* @example
|
|
1345
|
+
* ```typescript
|
|
1346
|
+
* const transport = new Transport({
|
|
1347
|
+
* url: "ws://localhost:8090/acp",
|
|
1348
|
+
* timeout: 30000,
|
|
1349
|
+
* logger: new Logger({ level: "DEBUG" })
|
|
1350
|
+
* });
|
|
1351
|
+
*
|
|
1352
|
+
* await transport.connect();
|
|
1353
|
+
* transport.send({ method: "initialize", params: {} });
|
|
1354
|
+
*
|
|
1355
|
+
* transport.onMessage((message) => {
|
|
1356
|
+
* console.log("Received:", message);
|
|
1357
|
+
* });
|
|
1358
|
+
* ```
|
|
1359
|
+
*/
|
|
1360
|
+
export declare class Transport implements ITransport {
|
|
1361
|
+
private readonly url;
|
|
1362
|
+
private readonly logger;
|
|
1363
|
+
private readonly timeout;
|
|
1364
|
+
private ws;
|
|
1365
|
+
private connected;
|
|
1366
|
+
private messageQueue;
|
|
1367
|
+
private waitingResolvers;
|
|
1368
|
+
private generalWaiters;
|
|
1369
|
+
constructor(options: TransportOptions);
|
|
1370
|
+
get isConnected(): boolean;
|
|
1371
|
+
private checkConnected;
|
|
1372
|
+
connect(): Promise<void>;
|
|
1373
|
+
/**
|
|
1374
|
+
* 设置持续的消息监听器
|
|
1375
|
+
* 收到消息后,优先分发给等待的 resolver,否则放入消息队列
|
|
1376
|
+
*/
|
|
1377
|
+
private setupMessageListener;
|
|
1378
|
+
/**
|
|
1379
|
+
* 拒绝所有等待的 Promise(包括基于 requestId 的和通用的)
|
|
1380
|
+
*/
|
|
1381
|
+
private rejectAllWaiters;
|
|
1382
|
+
close(): Promise<void>;
|
|
1383
|
+
send(data: string | object): Promise<void>;
|
|
1384
|
+
/**
|
|
1385
|
+
* 等待指定 requestId 的响应
|
|
1386
|
+
* 用于 Protocol 层等待特定请求的响应,支持并发请求
|
|
1387
|
+
* @param requestId 请求 ID(可以是 number 或 string)
|
|
1388
|
+
* @returns Promise,resolve 时返回响应消息的原始字符串
|
|
1389
|
+
*/
|
|
1390
|
+
waitForResponse(requestId: number | string): Promise<string>;
|
|
1391
|
+
receive(): AsyncGenerator<string>;
|
|
1392
|
+
/**
|
|
1393
|
+
* 接收原始数据
|
|
1394
|
+
* - 如果提供 requestId,则等待匹配该 requestId 的响应
|
|
1395
|
+
* - 如果不提供 requestId,则从消息队列获取,队列为空时等待任何新消息
|
|
1396
|
+
* @param requestId 可选的请求 ID(可以是 number 或 string),用于精确匹配响应
|
|
1397
|
+
*/
|
|
1398
|
+
private receiveRawData;
|
|
1399
|
+
}
|
|
1400
|
+
/**
|
|
1401
|
+
* StdioTransport 类构造选项
|
|
1402
|
+
*/
|
|
1403
|
+
export interface StdioTransportOptions {
|
|
1404
|
+
/** 子进程实例,用于 stdin/stdout 通信 */
|
|
1405
|
+
process: ExecaChildProcess;
|
|
1406
|
+
/** 日志记录器实例 */
|
|
1407
|
+
logger?: Logger;
|
|
1408
|
+
/** 连接超时时间(毫秒),默认 300000ms (5分钟) */
|
|
1409
|
+
timeout?: number;
|
|
1410
|
+
/** 消息队列最大大小,默认 1000 条消息 */
|
|
1411
|
+
maxQueueSize?: number;
|
|
1412
|
+
}
|
|
1413
|
+
/**
|
|
1414
|
+
* StdioTransport - stdio 传输层
|
|
1415
|
+
*
|
|
1416
|
+
* 负责通过 stdin/stdout 与 iFlow CLI 进程通信,提供:
|
|
1417
|
+
* - 基于标准输入输出的通信
|
|
1418
|
+
* - 消息发送和接收
|
|
1419
|
+
* - 连接状态监控
|
|
1420
|
+
* - 错误处理
|
|
1421
|
+
* - 超时控制
|
|
1422
|
+
*
|
|
1423
|
+
* 这是 SDK 支持 stdio 协议的核心组件,适用于非 WebSocket 场景。
|
|
1424
|
+
*
|
|
1425
|
+
* @example
|
|
1426
|
+
* ```typescript
|
|
1427
|
+
* import { execa } from "execa";
|
|
1428
|
+
*
|
|
1429
|
+
* const process = execa("iflow", ["--experimental-acp", "--stdio"]);
|
|
1430
|
+
* const transport = new StdioTransport({
|
|
1431
|
+
* process,
|
|
1432
|
+
* timeout: 30000,
|
|
1433
|
+
* logger: new Logger({ level: "DEBUG" })
|
|
1434
|
+
* });
|
|
1435
|
+
*
|
|
1436
|
+
* await transport.connect();
|
|
1437
|
+
* transport.send({ method: "initialize", params: {} });
|
|
1438
|
+
*
|
|
1439
|
+
* for await (const message of transport.receive()) {
|
|
1440
|
+
* console.log("Received:", message);
|
|
1441
|
+
* }
|
|
1442
|
+
* ```
|
|
1443
|
+
*/
|
|
1444
|
+
export declare class StdioTransport implements ITransport {
|
|
1445
|
+
private readonly logger;
|
|
1446
|
+
private readonly timeout;
|
|
1447
|
+
private readonly childProcess;
|
|
1448
|
+
private readonly maxQueueSize;
|
|
1449
|
+
private connected;
|
|
1450
|
+
private readlineInterface;
|
|
1451
|
+
private errorHandler;
|
|
1452
|
+
private exitHandler;
|
|
1453
|
+
private messageQueue;
|
|
1454
|
+
private waitingResolvers;
|
|
1455
|
+
private generalWaiters;
|
|
1456
|
+
constructor(options: StdioTransportOptions);
|
|
1457
|
+
get isConnected(): boolean;
|
|
1458
|
+
private checkConnected;
|
|
1459
|
+
connect(): Promise<void>;
|
|
1460
|
+
/**
|
|
1461
|
+
* 设置持续的消息监听器
|
|
1462
|
+
* 收到消息后,优先分发给等待的 resolver,否则放入消息队列
|
|
1463
|
+
*/
|
|
1464
|
+
private setupMessageListener;
|
|
1465
|
+
/**
|
|
1466
|
+
* 拒绝所有等待的 Promise(包括基于 requestId 的和通用的)
|
|
1467
|
+
*/
|
|
1468
|
+
private rejectAllWaiters;
|
|
1469
|
+
close(): Promise<void>;
|
|
1470
|
+
send(data: string | object): Promise<void>;
|
|
1471
|
+
/**
|
|
1472
|
+
* 等待指定 requestId 的响应
|
|
1473
|
+
* 用于 Protocol 层等待特定请求的响应,支持并发请求
|
|
1474
|
+
* @param requestId 请求 ID(可以是 number 或 string)
|
|
1475
|
+
* @returns Promise,resolve 时返回响应消息的原始字符串
|
|
1476
|
+
*/
|
|
1477
|
+
waitForResponse(requestId: number | string): Promise<string>;
|
|
1478
|
+
receive(): AsyncGenerator<string>;
|
|
1479
|
+
/**
|
|
1480
|
+
* 接收原始数据
|
|
1481
|
+
* - 如果提供 requestId,则等待匹配该 requestId 的响应
|
|
1482
|
+
* - 如果不提供 requestId,则从消息队列获取,队列为空时等待任何新消息
|
|
1483
|
+
* @param requestId 可选的请求 ID(可以是 number 或 string),用于精确匹配响应
|
|
1484
|
+
*/
|
|
1485
|
+
private receiveRawData;
|
|
1486
|
+
}
|
|
1236
1487
|
/**
|
|
1237
1488
|
* 简单的异步查询函数 - 发送提示并等待完整响应
|
|
1238
1489
|
*
|