@xiaozhi-client/endpoint 1.10.8-beta.7 → 1.10.8-beta.8

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.
@@ -0,0 +1,762 @@
1
+ import { Tool } from '@modelcontextprotocol/sdk/types.js';
2
+ import { EventEmitter } from 'node:events';
3
+
4
+ /**
5
+ * 工具调用结果接口
6
+ * 使用更宽松的类型定义以兼容不同来源的 ToolCallResult
7
+ */
8
+ interface ToolCallResult {
9
+ content: Array<Record<string, unknown>>;
10
+ isError?: boolean;
11
+ _meta?: Record<string, unknown>;
12
+ toolResult?: unknown;
13
+ [key: string]: unknown;
14
+ }
15
+ /**
16
+ * 工具调用参数接口
17
+ */
18
+ interface ToolCallParams {
19
+ name: string;
20
+ arguments?: Record<string, unknown>;
21
+ }
22
+ /**
23
+ * 验证后的工具调用参数
24
+ */
25
+ interface ValidatedToolCallParams {
26
+ name: string;
27
+ arguments?: Record<string, unknown>;
28
+ }
29
+ /**
30
+ * 工具调用错误码枚举
31
+ */
32
+ declare enum ToolCallErrorCode {
33
+ /** 无效参数 */
34
+ INVALID_PARAMS = -32602,
35
+ /** 工具不存在 */
36
+ TOOL_NOT_FOUND = -32601,
37
+ /** 服务不可用 */
38
+ SERVICE_UNAVAILABLE = -32001,
39
+ /** 调用超时 */
40
+ TIMEOUT = -32002,
41
+ /** 工具执行错误 */
42
+ TOOL_EXECUTION_ERROR = -32000
43
+ }
44
+ /**
45
+ * 工具调用错误类
46
+ */
47
+ declare class ToolCallError extends Error {
48
+ code: ToolCallErrorCode;
49
+ data?: unknown | undefined;
50
+ constructor(code: ToolCallErrorCode, message: string, data?: unknown | undefined);
51
+ }
52
+ /**
53
+ * JSON Schema 类型定义
54
+ * 兼容 MCP SDK 的 JSON Schema 格式
55
+ */
56
+ type JSONSchema = (Record<string, unknown> & {
57
+ type: "object";
58
+ properties?: Record<string, unknown>;
59
+ required?: string[];
60
+ additionalProperties?: boolean;
61
+ }) | Record<string, unknown>;
62
+ /**
63
+ * 确保对象符合 MCP Tool JSON Schema 格式
64
+ * 返回类型兼容 MCP SDK 的 Tool 类型
65
+ */
66
+ declare function ensureToolJSONSchema(schema: JSONSchema): {
67
+ type: "object";
68
+ properties?: Record<string, object>;
69
+ required?: string[];
70
+ additionalProperties?: boolean;
71
+ };
72
+ /**
73
+ * 增强的工具信息接口
74
+ * 包含工具的启用状态和使用统计信息
75
+ */
76
+ interface EnhancedToolInfo {
77
+ /** 工具唯一标识符,格式为 "{serviceName}__{originalName}" */
78
+ name: string;
79
+ /** 工具描述信息 */
80
+ description: string;
81
+ /** 工具输入参数的 JSON Schema 定义 */
82
+ inputSchema: JSONSchema;
83
+ /** 工具所属的 MCP 服务名称 */
84
+ serviceName: string;
85
+ /** 工具在 MCP 服务中的原始名称 */
86
+ originalName: string;
87
+ /** 工具是否启用 */
88
+ enabled: boolean;
89
+ /** 工具使用次数统计 */
90
+ usageCount: number;
91
+ /** 工具最后使用时间 (ISO 8601 格式字符串) */
92
+ lastUsedTime: string;
93
+ }
94
+ /**
95
+ * MCP 服务管理器接口
96
+ * 用于工具调用,避免循环依赖
97
+ */
98
+ interface IMCPServiceManager {
99
+ /** 获取所有工具列表 */
100
+ getAllTools(): EnhancedToolInfo[];
101
+ /** 调用工具 */
102
+ callTool(toolName: string, arguments_: Record<string, unknown>): Promise<ToolCallResult>;
103
+ /** 初始化 */
104
+ initialize(): Promise<void>;
105
+ /** 清理资源 */
106
+ cleanup(): Promise<void>;
107
+ }
108
+ /**
109
+ * 连接状态枚举
110
+ */
111
+ declare enum ConnectionState {
112
+ DISCONNECTED = "disconnected",
113
+ CONNECTING = "connecting",
114
+ CONNECTED = "connected",
115
+ FAILED = "failed"
116
+ }
117
+ /**
118
+ * 连接选项接口
119
+ */
120
+ interface ConnectionOptions {
121
+ /** 连接超时时间(毫秒),默认 10000 */
122
+ connectionTimeout?: number;
123
+ /** 重连延迟时间(毫秒),默认 2000 */
124
+ reconnectDelay?: number;
125
+ }
126
+ /**
127
+ * EndpointConnection 状态接口
128
+ */
129
+ interface EndpointConnectionStatus {
130
+ /** 是否已连接 */
131
+ connected: boolean;
132
+ /** 是否已初始化 */
133
+ initialized: boolean;
134
+ /** 接入点 URL */
135
+ url: string;
136
+ /** 可用工具数量 */
137
+ availableTools: number;
138
+ /** 连接状态 */
139
+ connectionState: ConnectionState;
140
+ /** 最后一次错误信息 */
141
+ lastError: string | null;
142
+ }
143
+ /**
144
+ * 简单连接状态接口
145
+ */
146
+ interface SimpleConnectionStatus {
147
+ /** 接入点地址 */
148
+ endpoint: string;
149
+ /** 是否已连接 */
150
+ connected: boolean;
151
+ /** 是否已初始化 */
152
+ initialized: boolean;
153
+ /** 最后连接时间 */
154
+ lastConnected?: Date;
155
+ /** 最后错误信息 */
156
+ lastError?: string;
157
+ }
158
+ /**
159
+ * 完整连接状态接口(扩展 SimpleConnectionStatus)
160
+ */
161
+ interface ConnectionStatus extends SimpleConnectionStatus {
162
+ }
163
+ /**
164
+ * 配置变更事件类型
165
+ */
166
+ interface ConfigChangeEvent {
167
+ type: "endpoints_added" | "endpoints_removed" | "endpoints_updated" | "options_updated";
168
+ data: {
169
+ added?: string[];
170
+ removed?: string[];
171
+ updated?: string[];
172
+ oldOptions?: Partial<ConnectionOptions>;
173
+ newOptions?: Partial<ConnectionOptions>;
174
+ };
175
+ timestamp: Date;
176
+ }
177
+ /**
178
+ * 重连结果接口
179
+ */
180
+ interface ReconnectResult {
181
+ successCount: number;
182
+ failureCount: number;
183
+ results: Array<{
184
+ endpoint: string;
185
+ success: boolean;
186
+ error?: string;
187
+ }>;
188
+ }
189
+ /**
190
+ * MCP 服务器配置类型
191
+ * 支持三种配置方式:
192
+ * 1. 本地命令 (stdio): { command: string; args: string[]; env?: Record<string, string> }
193
+ * 2. SSE: { type: "sse"; url: string; headers?: Record<string, string> }
194
+ * 3. HTTP: { type?: "http"; url: string; headers?: Record<string, string> }
195
+ *
196
+ * 向后兼容:自动将 streamable-http/streamable_http/streamableHttp 转换为 http
197
+ */
198
+ type MCPServerConfig = LocalMCPServerConfig | SSEMCPServerConfig | HTTPMCPServerConfig;
199
+ /**
200
+ * 本地 MCP 服务器配置
201
+ */
202
+ interface LocalMCPServerConfig {
203
+ command: string;
204
+ args: string[];
205
+ env?: Record<string, string>;
206
+ }
207
+ /**
208
+ * SSE MCP 服务器配置
209
+ */
210
+ interface SSEMCPServerConfig {
211
+ type: "sse";
212
+ url: string;
213
+ headers?: Record<string, string>;
214
+ }
215
+ /**
216
+ * HTTP MCP 服务器配置
217
+ * 使用 type: "http"
218
+ * 向后兼容 streamable-http 写法
219
+ */
220
+ interface HTTPMCPServerConfig {
221
+ type?: "http" | "streamable-http";
222
+ url: string;
223
+ headers?: Record<string, string>;
224
+ }
225
+ /** @deprecated 使用 HTTPMCPServerConfig 代替 */
226
+ type StreamableHTTPMCPServerConfig = HTTPMCPServerConfig;
227
+ /**
228
+ * Endpoint 配置接口
229
+ * @deprecated 不再使用,Endpoint 构造函数改为接收 IMCPServiceManager
230
+ */
231
+ interface EndpointConfig {
232
+ /** MCP 服务器配置(声明式) */
233
+ mcpServers: Record<string, MCPServerConfig>;
234
+ /** 可选:重连延迟(毫秒),默认 2000 */
235
+ reconnectDelay?: number;
236
+ /** 可选:ModelScope API Key(全局) */
237
+ modelscopeApiKey?: string;
238
+ }
239
+ /**
240
+ * EndpointManager 配置接口
241
+ */
242
+ interface EndpointManagerConfig {
243
+ /** 可选:默认重连延迟(毫秒) */
244
+ defaultReconnectDelay?: number;
245
+ }
246
+ /**
247
+ * 小智平台 JWT Token Payload 接口
248
+ *
249
+ * @example
250
+ * ```typescript
251
+ * // 从 endpoint URL 解码得到的 payload
252
+ * const payload: XiaozhiTokenPayload = {
253
+ * userId: 302720,
254
+ * agentId: 1324149,
255
+ * endpointId: "agent_1324149",
256
+ * purpose: "mcp-endpoint",
257
+ * iat: 1768480930,
258
+ * exp: 1800038530
259
+ * };
260
+ * ```
261
+ */
262
+ interface XiaozhiTokenPayload {
263
+ /** 用户 ID */
264
+ userId: number;
265
+ /** 代理 ID */
266
+ agentId: number;
267
+ /** 接入点 ID,格式为 "agent_{agentId}" */
268
+ endpointId: string;
269
+ /** Token 用途 */
270
+ purpose: string;
271
+ /** 签发时间(Unix 时间戳) */
272
+ iat: number;
273
+ /** 过期时间(Unix 时间戳) */
274
+ exp: number;
275
+ }
276
+ /**
277
+ * 解析后的 Endpoint URL 信息
278
+ */
279
+ interface ParsedEndpointInfo {
280
+ /** 完整的 endpoint URL */
281
+ url: string;
282
+ /** 提取的 JWT Token */
283
+ token: string;
284
+ /** 解码后的 Token Payload */
285
+ payload: XiaozhiTokenPayload;
286
+ /** WebSocket 服务器地址(不含 token 参数) */
287
+ wsUrl: string;
288
+ }
289
+
290
+ /**
291
+ * Endpoint 类
292
+ * 管理单个小智接入点的 WebSocket 连接
293
+ * 实现 MCP (Model Context Protocol) 协议通信
294
+ *
295
+ * 使用方式:
296
+ * ```typescript
297
+ * const mcpManager = new SharedMCPAdapter(globalMCPManager);
298
+ * const endpoint = new Endpoint("ws://...", mcpManager);
299
+ * await endpoint.connect();
300
+ * ```
301
+ */
302
+
303
+ /**
304
+ * Endpoint 类
305
+ * 负责管理单个小智接入点的 WebSocket 连接
306
+ * 使用新的配置方式:直接在构造函数中传入 mcpServers 配置
307
+ */
308
+ declare class Endpoint {
309
+ private endpointUrl;
310
+ private ws;
311
+ private connectionStatus;
312
+ private serverInitialized;
313
+ private mcpAdapter;
314
+ private connectionState;
315
+ private lastError;
316
+ private connectionTimeout;
317
+ private toolCallTimeout;
318
+ private reconnectDelay;
319
+ /**
320
+ * 构造函数
321
+ *
322
+ * @param endpointUrl - 小智接入点 URL
323
+ * @param mcpManager - MCP 服务管理器(依赖注入)
324
+ * @param reconnectDelay - 可选的重连延迟(毫秒)
325
+ */
326
+ constructor(endpointUrl: string, mcpManager: IMCPServiceManager, reconnectDelay?: number);
327
+ /**
328
+ * 获取 Endpoint URL
329
+ */
330
+ getUrl(): string;
331
+ /**
332
+ * 获取当前所有工具列表
333
+ */
334
+ getTools(): Tool[];
335
+ /**
336
+ * 连接小智接入点
337
+ */
338
+ connect(): Promise<void>;
339
+ /**
340
+ * 尝试建立连接
341
+ */
342
+ private attemptConnection;
343
+ /**
344
+ * 处理连接成功
345
+ */
346
+ private handleConnectionSuccess;
347
+ /**
348
+ * 处理连接错误
349
+ */
350
+ private handleConnectionError;
351
+ /**
352
+ * 处理连接关闭
353
+ */
354
+ private handleConnectionClose;
355
+ /**
356
+ * 清理连接资源
357
+ */
358
+ private cleanupConnection;
359
+ /**
360
+ * 处理 MCP 消息
361
+ */
362
+ private handleMessage;
363
+ /**
364
+ * 发送响应消息
365
+ */
366
+ private sendResponse;
367
+ /**
368
+ * 获取服务器状态
369
+ */
370
+ getStatus(): EndpointConnectionStatus;
371
+ /**
372
+ * 检查连接状态
373
+ */
374
+ isConnected(): boolean;
375
+ /**
376
+ * 主动断开小智连接
377
+ */
378
+ disconnect(): Promise<void>;
379
+ /**
380
+ * 重连小智接入点
381
+ */
382
+ reconnect(): Promise<void>;
383
+ /**
384
+ * 处理工具调用请求
385
+ */
386
+ private handleToolCall;
387
+ /**
388
+ * 带超时控制的工具执行
389
+ */
390
+ private executeToolWithTimeout;
391
+ /**
392
+ * 处理工具调用错误
393
+ */
394
+ private handleToolCallError;
395
+ /**
396
+ * 发送错误响应
397
+ */
398
+ private sendErrorResponse;
399
+ }
400
+
401
+ /**
402
+ * EndpointManager
403
+ * 管理多个小智接入点的连接,共享外部传入的 MCPManager
404
+ *
405
+ * 使用方式:
406
+ * ```typescript
407
+ * // 1. 先创建并配置 MCPManager
408
+ * const mcpManager = new MCPManager();
409
+ * mcpManager.addServer("calculator", { command: "npx", args: ["-y", "calculator-mcp"] });
410
+ * await mcpManager.connect();
411
+ *
412
+ * // 2. 创建 EndpointManager 并设置 MCPManager
413
+ * const manager = new EndpointManager();
414
+ * manager.setMcpManager(mcpManager);
415
+ *
416
+ * // 3. 添加接入点
417
+ * manager.addEndpoint("ws://endpoint1");
418
+ * await manager.connect();
419
+ * ```
420
+ */
421
+
422
+ /**
423
+ * 小智接入点管理器
424
+ * 负责管理多个小智接入点的连接,共享 MCP 服务
425
+ *
426
+ * 注意:MCPManager 必须通过 setMcpManager() 方法设置,且由外部管理其生命周期
427
+ */
428
+ declare class EndpointManager extends EventEmitter {
429
+ private config?;
430
+ private endpoints;
431
+ private connectionStates;
432
+ private mcpManager;
433
+ private sharedMCPAdapter;
434
+ private mcpEventListeners;
435
+ /**
436
+ * 构造函数
437
+ *
438
+ * @param config - 可选的配置
439
+ */
440
+ constructor(config?: EndpointManagerConfig | undefined);
441
+ /**
442
+ * 设置 MCPManager 实例
443
+ *
444
+ * 注意:MCPManager 的生命周期由外部管理,EndpointManager 不负责连接和断开
445
+ *
446
+ * @param mcpManager - 外部创建并已连接的 MCPManager 实例
447
+ */
448
+ setMcpManager(mcpManager: IMCPServiceManager): void;
449
+ /**
450
+ * 添加 Endpoint(支持 URL 字符串或 Endpoint 实例)
451
+ *
452
+ * @param endpoint - Endpoint URL 字符串或 Endpoint 实例
453
+ */
454
+ addEndpoint(endpoint: string | Endpoint): void;
455
+ /**
456
+ * 内部添加 Endpoint 方法
457
+ */
458
+ private addEndpointInternal;
459
+ /**
460
+ * 移除 Endpoint 实例
461
+ *
462
+ * @param endpoint - Endpoint 实例
463
+ */
464
+ removeEndpoint(endpoint: Endpoint): void;
465
+ /**
466
+ * 连接 Endpoint
467
+ *
468
+ * 注意:此方法不负责连接 MCPManager,MCPManager 必须在调用此方法前已连接
469
+ *
470
+ * @param endpoint - 可选,指定要连接的端点 URL。如果不传入,则连接所有端点
471
+ */
472
+ connect(endpoint?: string): Promise<void>;
473
+ /**
474
+ * 断开连接
475
+ *
476
+ * 注意:此方法不断开 MCPManager,MCPManager 的生命周期由外部管理
477
+ *
478
+ * @param endpoint - 可选,指定要断开的端点 URL。如果不传入,则断开所有端点
479
+ */
480
+ disconnect(endpoint?: string): Promise<void>;
481
+ /**
482
+ * 获取所有 Endpoint URL
483
+ */
484
+ getEndpoints(): string[];
485
+ /**
486
+ * 获取指定 Endpoint 实例
487
+ *
488
+ * @param url - Endpoint URL
489
+ */
490
+ getEndpoint(url: string): Endpoint | undefined;
491
+ /**
492
+ * 获取所有连接状态
493
+ */
494
+ getConnectionStatus(): SimpleConnectionStatus[];
495
+ /**
496
+ * 检查是否有任何连接处于连接状态
497
+ */
498
+ isAnyConnected(): boolean;
499
+ /**
500
+ * 检查指定端点是否已连接
501
+ *
502
+ * @param url - 端点 URL
503
+ */
504
+ isEndpointConnected(url: string): boolean;
505
+ /**
506
+ * 获取指定端点的状态
507
+ *
508
+ * @param url - 端点 URL
509
+ */
510
+ getEndpointStatus(url: string): SimpleConnectionStatus | undefined;
511
+ /**
512
+ * 重连
513
+ *
514
+ * @param endpoint - 可选,指定要重连的端点 URL。如果不传入,则重连所有端点
515
+ * @param delay - 可选,disconnect 和 connect 之间的等待时间(毫秒),默认为 1000ms。
516
+ * 注意:此参数只控制断开和重新连接之间的等待时间,不影响底层 Endpoint 实例的重连延迟
517
+ */
518
+ reconnect(endpoint?: string, delay?: number): Promise<void>;
519
+ /**
520
+ * 重连所有端点
521
+ */
522
+ reconnectAll(): Promise<void>;
523
+ /**
524
+ * 重连指定的端点
525
+ *
526
+ * @param url - 要重连的端点 URL
527
+ */
528
+ reconnectEndpoint(url: string): Promise<void>;
529
+ /**
530
+ * 清除所有端点
531
+ *
532
+ * 注意:此方法不会清理 MCPManager,MCPManager 的生命周期由外部管理
533
+ */
534
+ clearEndpoints(): Promise<void>;
535
+ /**
536
+ * 清理资源
537
+ *
538
+ * 注意:此方法不会清理 MCPManager,MCPManager 的生命周期由外部管理
539
+ */
540
+ cleanup(): Promise<void>;
541
+ /**
542
+ * 连接单个端点
543
+ */
544
+ private connectSingleEndpoint;
545
+ /**
546
+ * 重连单个端点
547
+ */
548
+ private reconnectSingleEndpoint;
549
+ }
550
+
551
+ /**
552
+ * 共享 MCP 管理器适配器
553
+ *
554
+ * 接收全局 MCPManager 实例的引用,不创建独立连接
555
+ * 用于多个 Endpoint 共享同一个 MCPManager 实例
556
+ *
557
+ * @example
558
+ * ```typescript
559
+ * const globalMCPManager = new MCPManager();
560
+ * await globalMCPManager.connect();
561
+ *
562
+ * const adapter = new SharedMCPAdapter(globalMCPManager);
563
+ * const endpoint = new Endpoint("ws://...", adapter);
564
+ * ```
565
+ */
566
+
567
+ /**
568
+ * 共享 MCP 管理器适配器
569
+ * 实现 IMCPServiceManager 接口,将操作委托给全局 MCPManager
570
+ */
571
+ declare class SharedMCPAdapter implements IMCPServiceManager {
572
+ private globalMCPManager;
573
+ private isInitialized;
574
+ /**
575
+ * 构造函数
576
+ *
577
+ * @param globalMCPManager - 全局 MCPManager 实例
578
+ */
579
+ constructor(globalMCPManager: IMCPServiceManager);
580
+ /**
581
+ * 初始化适配器
582
+ *
583
+ * 注意:此方法不执行任何连接操作,仅标记初始化状态,因为全局 MCPManager 的生命周期由外部管理
584
+ */
585
+ initialize(): Promise<void>;
586
+ /**
587
+ * 获取所有工具列表
588
+ *
589
+ * 从全局 MCPManager 获取工具列表,并转换为增强格式
590
+ */
591
+ getAllTools(): EnhancedToolInfo[];
592
+ /**
593
+ * 调用工具
594
+ *
595
+ * 将工具调用委托给全局 MCPManager
596
+ *
597
+ * @param toolName - 工具名称(格式:serviceName__toolName)
598
+ * @param arguments_ - 工具调用参数
599
+ */
600
+ callTool(toolName: string, arguments_: Record<string, unknown>): Promise<ToolCallResult>;
601
+ /**
602
+ * 清理资源
603
+ *
604
+ * 注意:此方法不会断开全局 MCPManager,由创建者负责管理
605
+ */
606
+ cleanup(): Promise<void>;
607
+ }
608
+
609
+ /**
610
+ * 工具函数模块
611
+ *
612
+ * 内联的必要工具函数,确保包的独立性
613
+ */
614
+
615
+ /**
616
+ * 截断端点 URL 用于日志显示
617
+ *
618
+ * @param endpoint - 完整的端点 URL
619
+ * @returns 截断后的 URL
620
+ *
621
+ * @example
622
+ * ```typescript
623
+ * sliceEndpoint("ws://very-long-endpoint-url-here.example.com/endpoint")
624
+ * // 返回: "ws://very-long-endpoint-u...e.com/endpoint"
625
+ * ```
626
+ */
627
+ declare function sliceEndpoint(endpoint: string): string;
628
+ /**
629
+ * 验证工具调用参数
630
+ *
631
+ * @param params - 待验证的参数
632
+ * @returns 验证后的参数
633
+ * @throws {Error} 如果参数无效
634
+ *
635
+ * @example
636
+ * ```typescript
637
+ * const params = validateToolCallParams({
638
+ * name: "test_tool",
639
+ * arguments: { foo: "bar" }
640
+ * });
641
+ * ```
642
+ */
643
+ declare function validateToolCallParams(params: unknown): ValidatedToolCallParams;
644
+ /**
645
+ * 验证端点 URL 格式
646
+ *
647
+ * @param endpoint - 待验证的端点 URL
648
+ * @returns 是否为有效的 WebSocket URL
649
+ */
650
+ declare function isValidEndpointUrl(endpoint: string): boolean;
651
+ /**
652
+ * 深度合并对象
653
+ *
654
+ * @param target - 目标对象
655
+ * @param sources - 源对象
656
+ * @returns 合并后的对象
657
+ *
658
+ * @example
659
+ * ```typescript
660
+ * const result = deepMerge(
661
+ * { a: 1, b: { x: 1 } },
662
+ * { b: { y: 2 }, c: 3 }
663
+ * );
664
+ * // 返回: { a: 1, b: { x: 1, y: 2 }, c: 3 }
665
+ * ```
666
+ */
667
+ declare function deepMerge<T>(target: Partial<T>, ...sources: Array<Partial<T>>): T;
668
+ /**
669
+ * 延迟执行
670
+ *
671
+ * @param ms - 延迟时间(毫秒)
672
+ * @returns Promise
673
+ */
674
+ declare function sleep(ms: number): Promise<void>;
675
+ /**
676
+ * 格式化错误消息
677
+ *
678
+ * @param error - 错误对象
679
+ * @returns 格式化后的错误消息
680
+ */
681
+ declare function formatErrorMessage(error: unknown): string;
682
+ /**
683
+ * 解码 JWT Token(仅解析 payload,不验证签名)
684
+ *
685
+ * @param token - JWT Token 字符串
686
+ * @returns 解码后的 Token Payload,解码失败返回 null
687
+ *
688
+ * @example
689
+ * ```typescript
690
+ * const payload = decodeJWTToken("eyJ...token...");
691
+ * if (payload) {
692
+ * console.log(payload.endpointId); // "agent_1324149"
693
+ * }
694
+ * ```
695
+ */
696
+ declare function decodeJWTToken(token: string): XiaozhiTokenPayload | null;
697
+ /**
698
+ * 从 endpoint URL 中提取 token 参数
699
+ *
700
+ * @param url - 完整的 endpoint URL
701
+ * @returns 提取的 token 字符串,未找到返回 null
702
+ *
703
+ * @example
704
+ * ```typescript
705
+ * const token = extractTokenFromUrl(
706
+ * "wss://api.xiaozhi.me/mcp/?token=eyJ..."
707
+ * );
708
+ * ```
709
+ */
710
+ declare function extractTokenFromUrl(url: string): string | null;
711
+ /**
712
+ * 解析 endpoint URL 获取完整信息
713
+ *
714
+ * @param url - 完整的 endpoint URL
715
+ * @returns 解析后的 endpoint 信息,解析失败返回 null
716
+ *
717
+ * @example
718
+ * ```typescript
719
+ * const info = parseEndpointUrl(
720
+ * "wss://api.xiaozhi.me/mcp/?token=eyJ..."
721
+ * );
722
+ * if (info) {
723
+ * console.log(info.payload.endpointId); // "agent_1324149"
724
+ * console.log(info.wsUrl); // "wss://api.xiaozhi.me/mcp/"
725
+ * }
726
+ * ```
727
+ */
728
+ declare function parseEndpointUrl(url: string): ParsedEndpointInfo | null;
729
+
730
+ /**
731
+ * MCP 消息类型定义
732
+ *
733
+ * 定义最小化的 MCP 协议消息类型
734
+ */
735
+ /**
736
+ * MCP 消息接口
737
+ */
738
+ interface MCPMessage {
739
+ /** JSON-RPC 版本 */
740
+ jsonrpc: "2.0";
741
+ /** 方法名 */
742
+ method: string;
743
+ /** 参数 */
744
+ params?: unknown;
745
+ /** 请求 ID */
746
+ id: string | number;
747
+ }
748
+ /**
749
+ * 扩展的 MCP 消息接口(用于响应)
750
+ */
751
+ interface ExtendedMCPMessage {
752
+ jsonrpc: "2.0";
753
+ id: string | number;
754
+ result?: unknown;
755
+ error?: {
756
+ code: number;
757
+ message: string;
758
+ data?: unknown;
759
+ };
760
+ }
761
+
762
+ export { type ConfigChangeEvent, type ConnectionOptions, ConnectionState, type ConnectionStatus, Endpoint, type EndpointConfig, type EndpointConnectionStatus, EndpointManager, type EndpointManagerConfig, type ExtendedMCPMessage, type IMCPServiceManager, type JSONSchema, type LocalMCPServerConfig, type MCPMessage, type MCPServerConfig, type ParsedEndpointInfo, type ReconnectResult, type SSEMCPServerConfig, SharedMCPAdapter, type SimpleConnectionStatus, type StreamableHTTPMCPServerConfig, ToolCallError, ToolCallErrorCode, type ToolCallParams, type ToolCallResult, type ValidatedToolCallParams, type XiaozhiTokenPayload, decodeJWTToken, deepMerge, ensureToolJSONSchema, extractTokenFromUrl, formatErrorMessage, isValidEndpointUrl, parseEndpointUrl, sleep, sliceEndpoint, validateToolCallParams };