@lingyao037/openclaw-lingyao-cli 0.9.7 → 1.0.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/dist/cli.d.ts +78 -2
- package/dist/index.d.ts +4 -974
- package/dist/index.js +49 -1006
- package/dist/index.js.map +1 -1
- package/dist/setup-entry.d.ts +2 -2
- package/dist/setup-entry.js +22 -49
- package/dist/setup-entry.js.map +1 -1
- package/dist/{status-CVwSoPKi.d.ts → status-CS7AsRlS.d.ts} +1 -1
- package/dist/{types-LFC6Wpqo.d.ts → types-BZMU9mea.d.ts} +8 -1
- package/openclaw.plugin.json +13 -1
- package/package.json +1 -1
- package/dist/accounts-BykE02r0.d.ts +0 -80
package/dist/index.d.ts
CHANGED
|
@@ -1,397 +1,8 @@
|
|
|
1
|
-
import { R as ResolvedAccount, L as LingyaoProbeResult } from './status-
|
|
1
|
+
import { R as ResolvedAccount, L as LingyaoProbeResult } from './status-CS7AsRlS.js';
|
|
2
2
|
import * as openclaw_plugin_sdk from 'openclaw/plugin-sdk';
|
|
3
3
|
import { PluginRuntime, ChannelPlugin } from 'openclaw/plugin-sdk';
|
|
4
|
-
import {
|
|
5
|
-
export { A as AckRequest,
|
|
6
|
-
import { A as AccountManager } from './accounts-BykE02r0.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 灵爻服务器 HTTP 客户端
|
|
10
|
-
*
|
|
11
|
-
* 主动连接到灵爻服务器,实现 Gateway 注册、心跳、消息推送
|
|
12
|
-
* 符合 openapi.yaml 规范
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 服务器 API 配置
|
|
17
|
-
*/
|
|
18
|
-
interface ServerConfig {
|
|
19
|
-
baseURL: string;
|
|
20
|
-
apiBase: string;
|
|
21
|
-
timeout: number;
|
|
22
|
-
connectionTimeout: number;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Gateway 注册响应
|
|
26
|
-
*/
|
|
27
|
-
interface GatewayRegisterResponse {
|
|
28
|
-
gatewayToken: string;
|
|
29
|
-
expiresAt: number;
|
|
30
|
-
webhookSecret: string;
|
|
31
|
-
serverConfig: {
|
|
32
|
-
heartbeatInterval: number;
|
|
33
|
-
maxOfflineMessages: number;
|
|
34
|
-
supportedMessageTypes: string[];
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* 心跳响应
|
|
39
|
-
*/
|
|
40
|
-
interface HeartbeatResponse {
|
|
41
|
-
serverTime: number;
|
|
42
|
-
pendingMessages: number;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* 发送消息请求
|
|
46
|
-
*/
|
|
47
|
-
interface SendMessageRequest {
|
|
48
|
-
deviceId: string;
|
|
49
|
-
message: {
|
|
50
|
-
id: string;
|
|
51
|
-
type: 'notify_text' | 'notify_action';
|
|
52
|
-
timestamp: number;
|
|
53
|
-
payload: {
|
|
54
|
-
title?: string;
|
|
55
|
-
body?: string;
|
|
56
|
-
action?: {
|
|
57
|
-
type: 'open_memory' | 'view_diary' | 'custom';
|
|
58
|
-
params?: Record<string, unknown>;
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
options?: {
|
|
63
|
-
priority?: 'normal' | 'low' | 'high';
|
|
64
|
-
ttl?: number;
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* 发送消息响应
|
|
69
|
-
*/
|
|
70
|
-
interface SendMessageResponse {
|
|
71
|
-
messageId: string;
|
|
72
|
-
status: 'queued' | 'delivered' | 'failed';
|
|
73
|
-
deliveredAt: number | null;
|
|
74
|
-
queued: boolean;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Gateway 状态
|
|
78
|
-
*/
|
|
79
|
-
type GatewayStatus = 'online' | 'offline' | 'maintenance';
|
|
80
|
-
/**
|
|
81
|
-
* HTTP 客户端实现
|
|
82
|
-
*/
|
|
83
|
-
declare class ServerHttpClient {
|
|
84
|
-
private runtime;
|
|
85
|
-
private config;
|
|
86
|
-
private axiosInstance;
|
|
87
|
-
private gatewayToken;
|
|
88
|
-
private webhookSecret;
|
|
89
|
-
private tokenExpiresAt;
|
|
90
|
-
private heartbeatInterval;
|
|
91
|
-
private heartbeatTimer;
|
|
92
|
-
private gatewayId;
|
|
93
|
-
private isRegistered;
|
|
94
|
-
private isConnecting;
|
|
95
|
-
private storagePrefix;
|
|
96
|
-
constructor(runtime: LingyaoRuntime, gatewayId: string, serverConfig?: Partial<ServerConfig>, storagePrefix?: string);
|
|
97
|
-
/**
|
|
98
|
-
* 注册 Gateway 到服务器
|
|
99
|
-
*/
|
|
100
|
-
register(capabilities?: {
|
|
101
|
-
websocket?: boolean;
|
|
102
|
-
compression?: boolean;
|
|
103
|
-
maxMessageSize?: number;
|
|
104
|
-
}): Promise<GatewayRegisterResponse>;
|
|
105
|
-
/**
|
|
106
|
-
* 发送心跳
|
|
107
|
-
*/
|
|
108
|
-
heartbeat(status?: GatewayStatus, activeConnections?: number): Promise<HeartbeatResponse>;
|
|
109
|
-
/**
|
|
110
|
-
* 发送消息到灵爻 App
|
|
111
|
-
*/
|
|
112
|
-
sendMessage(deviceId: string, messageType: 'notify_text' | 'notify_action', payload: SendMessageRequest['message']['payload'], options?: SendMessageRequest['options']): Promise<SendMessageResponse>;
|
|
113
|
-
/**
|
|
114
|
-
* 启动心跳循环
|
|
115
|
-
*/
|
|
116
|
-
private startHeartbeat;
|
|
117
|
-
/**
|
|
118
|
-
* 停止心跳循环
|
|
119
|
-
*/
|
|
120
|
-
stopHeartbeat(): void;
|
|
121
|
-
/**
|
|
122
|
-
* 获取 Webhook Secret
|
|
123
|
-
*/
|
|
124
|
-
getWebhookSecret(): string | null;
|
|
125
|
-
/**
|
|
126
|
-
* 获取 Gateway Token
|
|
127
|
-
*/
|
|
128
|
-
getGatewayToken(): string | null;
|
|
129
|
-
/**
|
|
130
|
-
* 检查 Token 是否即将过期
|
|
131
|
-
*/
|
|
132
|
-
isTokenExpiringSoon(thresholdMs?: number): boolean;
|
|
133
|
-
/**
|
|
134
|
-
* 检查是否已注册
|
|
135
|
-
*/
|
|
136
|
-
isReady(): boolean;
|
|
137
|
-
/**
|
|
138
|
-
* Clear local gateway token/session (storage + in-memory). Used when WS handshake
|
|
139
|
-
* fails with 404 or when forcing re-registration with the same gatewayId.
|
|
140
|
-
*/
|
|
141
|
-
clearLocalSession(): Promise<void>;
|
|
142
|
-
/**
|
|
143
|
-
* 从存储恢复会话
|
|
144
|
-
*/
|
|
145
|
-
restoreFromStorage(): Promise<boolean>;
|
|
146
|
-
/**
|
|
147
|
-
* Build a namespaced storage key for multi-account support
|
|
148
|
-
*/
|
|
149
|
-
private storageKey;
|
|
150
|
-
/**
|
|
151
|
-
* 生成消息 ID
|
|
152
|
-
*/
|
|
153
|
-
private generateMessageId;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Lingyao WebSocket Client
|
|
158
|
-
*
|
|
159
|
-
* 主动连接到 lingyao.live 服务器的 WebSocket 客户端
|
|
160
|
-
* 实现:
|
|
161
|
-
* - 自动连接和重连
|
|
162
|
-
* - 心跳机制
|
|
163
|
-
* - 消息发送和接收
|
|
164
|
-
* - 在线状态管理
|
|
165
|
-
*/
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* WebSocket 连接状态
|
|
169
|
-
*/
|
|
170
|
-
type ConnectionState = "connecting" | "connected" | "disconnected" | "error";
|
|
171
|
-
/**
|
|
172
|
-
* WebSocket 消息类型(与 `lingyao/server/src/server.ts` 中 Gateway 协议一致)
|
|
173
|
-
*/
|
|
174
|
-
declare enum WSMessageType {
|
|
175
|
-
GATEWAY_REGISTER = "gateway_register",
|
|
176
|
-
GATEWAY_HEARTBEAT = "gateway_heartbeat",
|
|
177
|
-
GATEWAY_SEND_MESSAGE = "gateway_send_message",
|
|
178
|
-
GATEWAY_REGISTERED = "gateway_registered",
|
|
179
|
-
GATEWAY_HEARTBEAT_ACK = "gateway_heartbeat_ack",
|
|
180
|
-
MESSAGE_DELIVERED = "message_delivered",
|
|
181
|
-
MESSAGE_FAILED = "message_failed",
|
|
182
|
-
APP_MESSAGE = "app_message",
|
|
183
|
-
DEVICE_ONLINE = "device_online",
|
|
184
|
-
PAIRING_COMPLETED = "pairing_completed",
|
|
185
|
-
ERROR = "error"
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* WebSocket 消息基础格式
|
|
189
|
-
*/
|
|
190
|
-
interface WSMessage {
|
|
191
|
-
type: WSMessageType | string;
|
|
192
|
-
id: string;
|
|
193
|
-
timestamp: number;
|
|
194
|
-
payload?: any;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* 接收到的 App 消息
|
|
198
|
-
*/
|
|
199
|
-
interface AppMessage extends WSMessage {
|
|
200
|
-
type: WSMessageType.APP_MESSAGE;
|
|
201
|
-
payload: {
|
|
202
|
-
deviceId: string;
|
|
203
|
-
message: {
|
|
204
|
-
id: string;
|
|
205
|
-
type: "sync_diary" | "sync_memory" | "heartbeat";
|
|
206
|
-
timestamp: number;
|
|
207
|
-
content: string;
|
|
208
|
-
metadata?: Record<string, unknown>;
|
|
209
|
-
};
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* WebSocket 客户端事件
|
|
214
|
-
*/
|
|
215
|
-
type WSClientEvent = {
|
|
216
|
-
type: "connected";
|
|
217
|
-
connectionId: string;
|
|
218
|
-
} | {
|
|
219
|
-
type: "disconnected";
|
|
220
|
-
code: number;
|
|
221
|
-
reason: string;
|
|
222
|
-
} | {
|
|
223
|
-
type: "error";
|
|
224
|
-
error: Error;
|
|
225
|
-
} | {
|
|
226
|
-
type: "fatal_handshake";
|
|
227
|
-
reason: "http_404";
|
|
228
|
-
} | {
|
|
229
|
-
type: "message";
|
|
230
|
-
message: WSMessage;
|
|
231
|
-
} | {
|
|
232
|
-
type: "appMessage";
|
|
233
|
-
deviceId: string;
|
|
234
|
-
message: AppMessage["payload"]["message"];
|
|
235
|
-
} | {
|
|
236
|
-
type: "pairing_completed";
|
|
237
|
-
deviceId: string;
|
|
238
|
-
deviceInfo: {
|
|
239
|
-
name: string;
|
|
240
|
-
platform: string;
|
|
241
|
-
version: string;
|
|
242
|
-
};
|
|
243
|
-
sessionId: string;
|
|
244
|
-
};
|
|
245
|
-
/**
|
|
246
|
-
* WebSocket 客户端配置
|
|
247
|
-
*/
|
|
248
|
-
interface WSClientConfig {
|
|
249
|
-
url: string;
|
|
250
|
-
gatewayId: string;
|
|
251
|
-
token?: string;
|
|
252
|
-
reconnectInterval: number;
|
|
253
|
-
heartbeatInterval: number;
|
|
254
|
-
messageHandler?: (message: AppMessage) => void | Promise<void>;
|
|
255
|
-
eventHandler?: (event: WSClientEvent) => void;
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Lingyao WebSocket Client
|
|
259
|
-
*
|
|
260
|
-
* 主动连接到 lingyao.live 服务器的 WebSocket 客户端
|
|
261
|
-
*/
|
|
262
|
-
declare class LingyaoWSClient {
|
|
263
|
-
private config;
|
|
264
|
-
private ws;
|
|
265
|
-
private state;
|
|
266
|
-
private connectionId;
|
|
267
|
-
private heartbeatTimer;
|
|
268
|
-
private reconnectTimer;
|
|
269
|
-
/** When set, close handler will not schedule reconnect (e.g. HTTP 404 on upgrade). */
|
|
270
|
-
private suppressReconnect;
|
|
271
|
-
private messageHandlers;
|
|
272
|
-
private logger;
|
|
273
|
-
constructor(runtime: LingyaoRuntime, config: WSClientConfig);
|
|
274
|
-
/**
|
|
275
|
-
* 连接到服务器
|
|
276
|
-
*/
|
|
277
|
-
connect(): Promise<void>;
|
|
278
|
-
/**
|
|
279
|
-
* 设置 WebSocket 事件处理器
|
|
280
|
-
*/
|
|
281
|
-
private setupWebSocketHandlers;
|
|
282
|
-
/**
|
|
283
|
-
* 处理连接打开
|
|
284
|
-
*/
|
|
285
|
-
private handleOpen;
|
|
286
|
-
/**
|
|
287
|
-
* 处理接收消息
|
|
288
|
-
*/
|
|
289
|
-
private handleMessage;
|
|
290
|
-
/**
|
|
291
|
-
* 处理连接错误
|
|
292
|
-
*/
|
|
293
|
-
private handleErrorEvent;
|
|
294
|
-
/**
|
|
295
|
-
* 处理连接关闭
|
|
296
|
-
*/
|
|
297
|
-
private handleClose;
|
|
298
|
-
/**
|
|
299
|
-
* 发送注册消息
|
|
300
|
-
*/
|
|
301
|
-
private sendRegister;
|
|
302
|
-
/**
|
|
303
|
-
* 处理注册响应
|
|
304
|
-
*/
|
|
305
|
-
private handleRegistered;
|
|
306
|
-
/**
|
|
307
|
-
* 发送心跳
|
|
308
|
-
*/
|
|
309
|
-
private sendHeartbeat;
|
|
310
|
-
/**
|
|
311
|
-
* 处理心跳确认
|
|
312
|
-
*/
|
|
313
|
-
private handleHeartbeatAck;
|
|
314
|
-
/**
|
|
315
|
-
* 启动心跳
|
|
316
|
-
*/
|
|
317
|
-
private startHeartbeat;
|
|
318
|
-
/**
|
|
319
|
-
* 停止心跳
|
|
320
|
-
*/
|
|
321
|
-
private stopHeartbeat;
|
|
322
|
-
/**
|
|
323
|
-
* 安排重连
|
|
324
|
-
*/
|
|
325
|
-
private scheduleReconnect;
|
|
326
|
-
/**
|
|
327
|
-
* 发送消息到服务器
|
|
328
|
-
*/
|
|
329
|
-
send(message: WSMessage): void;
|
|
330
|
-
/**
|
|
331
|
-
* 发送通知到鸿蒙 App
|
|
332
|
-
*/
|
|
333
|
-
sendNotification(deviceId: string, notification: any): void;
|
|
334
|
-
/**
|
|
335
|
-
* 处理 App 消息
|
|
336
|
-
*/
|
|
337
|
-
private handleAppMessage;
|
|
338
|
-
/**
|
|
339
|
-
* 处理消息发送成功
|
|
340
|
-
*/
|
|
341
|
-
private handleMessageDelivered;
|
|
342
|
-
/**
|
|
343
|
-
* 设备上线(服务器可选推送)
|
|
344
|
-
*/
|
|
345
|
-
private handleDeviceOnline;
|
|
346
|
-
/**
|
|
347
|
-
* 处理配对完成通知(来自 lingyao.live 服务器)
|
|
348
|
-
*/
|
|
349
|
-
private handlePairingCompleted;
|
|
350
|
-
/**
|
|
351
|
-
* 处理消息发送失败
|
|
352
|
-
*/
|
|
353
|
-
private handleMessageFailed;
|
|
354
|
-
/**
|
|
355
|
-
* 处理服务器错误
|
|
356
|
-
*/
|
|
357
|
-
private handleError;
|
|
358
|
-
/**
|
|
359
|
-
* 注册消息处理器
|
|
360
|
-
*/
|
|
361
|
-
registerMessageHandler(type: string, handler: (message: WSMessage) => void): void;
|
|
362
|
-
/**
|
|
363
|
-
* 发送事件
|
|
364
|
-
*/
|
|
365
|
-
private emitEvent;
|
|
366
|
-
/**
|
|
367
|
-
* 更新 WebSocket 连接使用的 token
|
|
368
|
-
*/
|
|
369
|
-
updateToken(token: string): void;
|
|
370
|
-
/**
|
|
371
|
-
* 断开连接
|
|
372
|
-
*/
|
|
373
|
-
disconnect(): void;
|
|
374
|
-
/**
|
|
375
|
-
* 获取连接状态
|
|
376
|
-
*/
|
|
377
|
-
getState(): ConnectionState;
|
|
378
|
-
/**
|
|
379
|
-
* 获取连接 ID
|
|
380
|
-
*/
|
|
381
|
-
getConnectionId(): string | null;
|
|
382
|
-
/**
|
|
383
|
-
* 是否已连接
|
|
384
|
-
*/
|
|
385
|
-
isConnected(): boolean;
|
|
386
|
-
/**
|
|
387
|
-
* 生成消息 ID
|
|
388
|
-
*/
|
|
389
|
-
private generateMessageId;
|
|
390
|
-
/**
|
|
391
|
-
* 生成连接 ID
|
|
392
|
-
*/
|
|
393
|
-
private generateConnectionId;
|
|
394
|
-
}
|
|
4
|
+
import { c as LingyaoConfig } from './types-BZMU9mea.js';
|
|
5
|
+
export { A as AckRequest, b as DeviceInfo, D as DeviceToken, d as DiarySyncPayload, F as FailedEntry, H as HealthStatus, e as LINGYAO_SERVER_URL, a as LingyaoAccount, f as LingyaoAccountConfig, g as LingyaoMessage, L as LingyaoRuntime, M as MemorySyncPayload, h as MessageType, N as NotifyAction, i as NotifyPayload, j as NotifyRequest, P as PairingCode, k as PairingConfirmRequest, l as PairingConfirmResponse, m as PollRequest, n as PollResponse, Q as QueuedMessage, S as SyncRequest, o as SyncResponse, T as TokenRefreshRequest, p as TokenRefreshResponse, W as WebSocketConnection, q as getLingyaoGatewayWsUrl } from './types-BZMU9mea.js';
|
|
395
6
|
|
|
396
7
|
/**
|
|
397
8
|
* Agent message format - messages passed directly to Agent
|
|
@@ -405,571 +16,6 @@ interface AgentMessage {
|
|
|
405
16
|
metadata: Record<string, unknown>;
|
|
406
17
|
timestamp: number;
|
|
407
18
|
}
|
|
408
|
-
/**
|
|
409
|
-
* Message handler callback for delivering messages to Agent
|
|
410
|
-
*/
|
|
411
|
-
type MessageHandler = (message: AgentMessage) => void | Promise<void>;
|
|
412
|
-
/**
|
|
413
|
-
* Message Processor - Handles incoming messages and routes them to Agent
|
|
414
|
-
*/
|
|
415
|
-
declare class MessageProcessor {
|
|
416
|
-
private runtime;
|
|
417
|
-
private accountManager;
|
|
418
|
-
private messageQueue;
|
|
419
|
-
private seenMessages;
|
|
420
|
-
private messageHandler;
|
|
421
|
-
private readonly maxQueueSize;
|
|
422
|
-
constructor(runtime: LingyaoRuntime, accountManager: AccountManager);
|
|
423
|
-
/**
|
|
424
|
-
* Initialize the message processor
|
|
425
|
-
*/
|
|
426
|
-
initialize(): Promise<void>;
|
|
427
|
-
/**
|
|
428
|
-
* Set the message handler for delivering messages to Agent
|
|
429
|
-
*/
|
|
430
|
-
setMessageHandler(handler: MessageHandler): void;
|
|
431
|
-
/**
|
|
432
|
-
* Get the currently registered Agent message handler.
|
|
433
|
-
*/
|
|
434
|
-
getMessageHandler(): MessageHandler | null;
|
|
435
|
-
/**
|
|
436
|
-
* Deliver a normalized message directly to the registered Agent handler.
|
|
437
|
-
*/
|
|
438
|
-
deliverToAgent(message: AgentMessage): Promise<void>;
|
|
439
|
-
/**
|
|
440
|
-
* Process sync request from app
|
|
441
|
-
*/
|
|
442
|
-
processSync(deviceId: string, request: SyncRequest): Promise<SyncResponse>;
|
|
443
|
-
/**
|
|
444
|
-
* Process a single message
|
|
445
|
-
*/
|
|
446
|
-
private processMessage;
|
|
447
|
-
/**
|
|
448
|
-
* Process diary sync - Pass directly to Agent
|
|
449
|
-
*/
|
|
450
|
-
private processDiarySync;
|
|
451
|
-
/**
|
|
452
|
-
* Process memory sync - Pass directly to Agent
|
|
453
|
-
*/
|
|
454
|
-
private processMemorySync;
|
|
455
|
-
/**
|
|
456
|
-
* Process sync acknowledgment
|
|
457
|
-
*/
|
|
458
|
-
private processSyncAck;
|
|
459
|
-
/**
|
|
460
|
-
* Process heartbeat
|
|
461
|
-
*/
|
|
462
|
-
private processHeartbeat;
|
|
463
|
-
/**
|
|
464
|
-
* Poll for new messages (long-polling)
|
|
465
|
-
*/
|
|
466
|
-
pollMessages(deviceId: string, timeout?: number): Promise<LingyaoMessage[]>;
|
|
467
|
-
/**
|
|
468
|
-
* Queue a message for a device
|
|
469
|
-
*/
|
|
470
|
-
queueMessage(deviceId: string, message: LingyaoMessage): boolean;
|
|
471
|
-
/**
|
|
472
|
-
* Acknowledge messages
|
|
473
|
-
*/
|
|
474
|
-
acknowledgeMessages(messageIds: string[]): Promise<void>;
|
|
475
|
-
/**
|
|
476
|
-
* Check if message has been seen (deduplication)
|
|
477
|
-
*/
|
|
478
|
-
private isMessageSeen;
|
|
479
|
-
/**
|
|
480
|
-
* Mark message as seen
|
|
481
|
-
*/
|
|
482
|
-
private markMessageSeen;
|
|
483
|
-
/**
|
|
484
|
-
* Get queue size for a device
|
|
485
|
-
*/
|
|
486
|
-
getQueueSize(deviceId: string): number;
|
|
487
|
-
/**
|
|
488
|
-
* Get total queue size
|
|
489
|
-
*/
|
|
490
|
-
getTotalQueueSize(): number;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
/**
|
|
494
|
-
* 监控和指标收集模块
|
|
495
|
-
*/
|
|
496
|
-
|
|
497
|
-
/**
|
|
498
|
-
* 指标类型
|
|
499
|
-
*/
|
|
500
|
-
declare enum MetricType {
|
|
501
|
-
COUNTER = "counter",
|
|
502
|
-
GAUGE = "gauge",
|
|
503
|
-
HISTOGRAM = "histogram"
|
|
504
|
-
}
|
|
505
|
-
/**
|
|
506
|
-
* 指标数据
|
|
507
|
-
*/
|
|
508
|
-
interface MetricData {
|
|
509
|
-
name: string;
|
|
510
|
-
type: MetricType;
|
|
511
|
-
value: number;
|
|
512
|
-
timestamp: number;
|
|
513
|
-
labels?: Record<string, string>;
|
|
514
|
-
}
|
|
515
|
-
/**
|
|
516
|
-
* 指标配置
|
|
517
|
-
*/
|
|
518
|
-
interface MetricConfig {
|
|
519
|
-
name: string;
|
|
520
|
-
type: MetricType;
|
|
521
|
-
description?: string;
|
|
522
|
-
labels?: string[];
|
|
523
|
-
buckets?: number[];
|
|
524
|
-
}
|
|
525
|
-
/**
|
|
526
|
-
* 监控指标管理器
|
|
527
|
-
*/
|
|
528
|
-
declare class MetricsManager {
|
|
529
|
-
private metrics;
|
|
530
|
-
private counters;
|
|
531
|
-
private gauges;
|
|
532
|
-
private histograms;
|
|
533
|
-
private histogramBuckets;
|
|
534
|
-
constructor(_runtime: LingyaoRuntime);
|
|
535
|
-
/**
|
|
536
|
-
* 初始化默认指标
|
|
537
|
-
*/
|
|
538
|
-
private initializeDefaultMetrics;
|
|
539
|
-
/**
|
|
540
|
-
* 声明指标
|
|
541
|
-
*/
|
|
542
|
-
declareMetric(config: MetricConfig): void;
|
|
543
|
-
/**
|
|
544
|
-
* 计数器增加
|
|
545
|
-
*/
|
|
546
|
-
incrementCounter(name: string, value?: number, labels?: Record<string, string>): void;
|
|
547
|
-
/**
|
|
548
|
-
* 设置仪表盘值
|
|
549
|
-
*/
|
|
550
|
-
setGauge(name: string, value: number, labels?: Record<string, string>): void;
|
|
551
|
-
/**
|
|
552
|
-
* 记录直方图值
|
|
553
|
-
*/
|
|
554
|
-
recordHistogram(name: string, value: number, labels?: Record<string, string>): void;
|
|
555
|
-
/**
|
|
556
|
-
* 记录指标
|
|
557
|
-
*/
|
|
558
|
-
private recordMetric;
|
|
559
|
-
/**
|
|
560
|
-
* 获取所有指标
|
|
561
|
-
*/
|
|
562
|
-
getMetrics(): MetricData[];
|
|
563
|
-
/**
|
|
564
|
-
* 获取特定指标的当前值
|
|
565
|
-
*/
|
|
566
|
-
getMetricValue(name: string): number | undefined;
|
|
567
|
-
/**
|
|
568
|
-
* 获取直方图统计数据
|
|
569
|
-
*/
|
|
570
|
-
getHistogramStats(name: string): {
|
|
571
|
-
count: number;
|
|
572
|
-
min: number;
|
|
573
|
-
max: number;
|
|
574
|
-
avg: number;
|
|
575
|
-
p50: number;
|
|
576
|
-
p95: number;
|
|
577
|
-
p99: number;
|
|
578
|
-
} | null;
|
|
579
|
-
/**
|
|
580
|
-
* 重置所有指标
|
|
581
|
-
*/
|
|
582
|
-
reset(): void;
|
|
583
|
-
/**
|
|
584
|
-
* 生成 Prometheus 格式的指标导出
|
|
585
|
-
*/
|
|
586
|
-
exportPrometheus(): string;
|
|
587
|
-
}
|
|
588
|
-
/**
|
|
589
|
-
* 监控事件
|
|
590
|
-
*/
|
|
591
|
-
declare enum MonitoringEvent {
|
|
592
|
-
CONNECTION_OPEN = "connection_open",
|
|
593
|
-
CONNECTION_CLOSE = "connection_close",
|
|
594
|
-
CONNECTION_ERROR = "connection_error",
|
|
595
|
-
RECONNECT = "reconnect",
|
|
596
|
-
MESSAGE_RECEIVED = "message_received",
|
|
597
|
-
MESSAGE_SENT = "message_sent",
|
|
598
|
-
MESSAGE_DELIVERED = "message_delivered",
|
|
599
|
-
MESSAGE_FAILED = "message_failed",
|
|
600
|
-
HEARTBEAT_SENT = "heartbeat_sent",
|
|
601
|
-
HEARTBEAT_RECEIVED = "heartbeat_received",
|
|
602
|
-
HEARTBEAT_MISSED = "heartbeat_missed",
|
|
603
|
-
ERROR_OCCURRED = "error_occurred"
|
|
604
|
-
}
|
|
605
|
-
/**
|
|
606
|
-
* 监控事件数据
|
|
607
|
-
*/
|
|
608
|
-
interface MonitoringEventData {
|
|
609
|
-
event: MonitoringEvent;
|
|
610
|
-
timestamp: number;
|
|
611
|
-
data: Record<string, unknown>;
|
|
612
|
-
}
|
|
613
|
-
/**
|
|
614
|
-
* 监控器
|
|
615
|
-
*/
|
|
616
|
-
declare class Monitor {
|
|
617
|
-
private runtime;
|
|
618
|
-
private metrics;
|
|
619
|
-
private eventHandlers;
|
|
620
|
-
constructor(runtime: LingyaoRuntime);
|
|
621
|
-
/**
|
|
622
|
-
* 记录事件
|
|
623
|
-
*/
|
|
624
|
-
recordEvent(event: MonitoringEvent, data?: Record<string, unknown>): void;
|
|
625
|
-
/**
|
|
626
|
-
* 为事件更新指标
|
|
627
|
-
*/
|
|
628
|
-
private updateMetricsForEvent;
|
|
629
|
-
/**
|
|
630
|
-
* 注册事件处理器
|
|
631
|
-
*/
|
|
632
|
-
on(event: MonitoringEvent, handler: (data: MonitoringEventData) => void): void;
|
|
633
|
-
/**
|
|
634
|
-
* 移除事件处理器
|
|
635
|
-
*/
|
|
636
|
-
off(event: MonitoringEvent, handler: (data: MonitoringEventData) => void): void;
|
|
637
|
-
/**
|
|
638
|
-
* 获取指标管理器
|
|
639
|
-
*/
|
|
640
|
-
getMetrics(): MetricsManager;
|
|
641
|
-
/**
|
|
642
|
-
* 获取摘要报告
|
|
643
|
-
*/
|
|
644
|
-
getSummary(): {
|
|
645
|
-
uptime: number;
|
|
646
|
-
connections: number;
|
|
647
|
-
messages: {
|
|
648
|
-
sent: number;
|
|
649
|
-
received: number;
|
|
650
|
-
failed: number;
|
|
651
|
-
};
|
|
652
|
-
errors: number;
|
|
653
|
-
heartbeats: {
|
|
654
|
-
sent: number;
|
|
655
|
-
missed: number;
|
|
656
|
-
};
|
|
657
|
-
};
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
/**
|
|
661
|
-
* 错误处理模块
|
|
662
|
-
*/
|
|
663
|
-
|
|
664
|
-
/**
|
|
665
|
-
* 错误严重级别
|
|
666
|
-
*/
|
|
667
|
-
declare enum ErrorSeverity {
|
|
668
|
-
LOW = "low",
|
|
669
|
-
MEDIUM = "medium",
|
|
670
|
-
HIGH = "high",
|
|
671
|
-
CRITICAL = "critical"
|
|
672
|
-
}
|
|
673
|
-
/**
|
|
674
|
-
* Lingyao 错误基类
|
|
675
|
-
*/
|
|
676
|
-
declare class LingyaoError extends Error {
|
|
677
|
-
readonly code: string;
|
|
678
|
-
readonly severity: ErrorSeverity;
|
|
679
|
-
readonly timestamp: number;
|
|
680
|
-
readonly context?: Record<string, unknown>;
|
|
681
|
-
readonly cause?: Error;
|
|
682
|
-
constructor(message: string, code: string, severity?: ErrorSeverity, context?: Record<string, unknown>, cause?: Error);
|
|
683
|
-
/**
|
|
684
|
-
* 转换为 JSON 可序列化格式
|
|
685
|
-
*/
|
|
686
|
-
toJSON(): Record<string, unknown>;
|
|
687
|
-
}
|
|
688
|
-
/**
|
|
689
|
-
* 错误处理器
|
|
690
|
-
*/
|
|
691
|
-
declare class ErrorHandler {
|
|
692
|
-
private runtime;
|
|
693
|
-
private errorCounts;
|
|
694
|
-
private lastErrors;
|
|
695
|
-
private errorThresholds;
|
|
696
|
-
private cleanupTimer;
|
|
697
|
-
private errorTimestamps;
|
|
698
|
-
constructor(runtime: LingyaoRuntime);
|
|
699
|
-
destroy(): void;
|
|
700
|
-
private cleanupOldErrors;
|
|
701
|
-
/**
|
|
702
|
-
* 处理错误
|
|
703
|
-
*/
|
|
704
|
-
handleError(error: Error | LingyaoError): void;
|
|
705
|
-
/**
|
|
706
|
-
* 记录错误
|
|
707
|
-
*/
|
|
708
|
-
private recordError;
|
|
709
|
-
/**
|
|
710
|
-
* 检查错误阈值
|
|
711
|
-
*/
|
|
712
|
-
private checkThresholds;
|
|
713
|
-
/**
|
|
714
|
-
* 触发警报
|
|
715
|
-
*/
|
|
716
|
-
private triggerAlert;
|
|
717
|
-
/**
|
|
718
|
-
* 设置错误阈值
|
|
719
|
-
*/
|
|
720
|
-
setErrorThreshold(code: string, threshold: {
|
|
721
|
-
count: number;
|
|
722
|
-
window: number;
|
|
723
|
-
}): void;
|
|
724
|
-
/**
|
|
725
|
-
* 获取错误统计
|
|
726
|
-
*/
|
|
727
|
-
getErrorStats(): {
|
|
728
|
-
byCode: Record<string, number>;
|
|
729
|
-
total: number;
|
|
730
|
-
recent: Array<{
|
|
731
|
-
code: string;
|
|
732
|
-
error: LingyaoError;
|
|
733
|
-
timestamp: number;
|
|
734
|
-
}>;
|
|
735
|
-
};
|
|
736
|
-
/**
|
|
737
|
-
* 重置错误计数
|
|
738
|
-
*/
|
|
739
|
-
resetErrorCounts(code?: string): void;
|
|
740
|
-
/**
|
|
741
|
-
* 包装异步函数以自动处理错误
|
|
742
|
-
*/
|
|
743
|
-
wrapAsync<T>(fn: () => Promise<T>, context?: {
|
|
744
|
-
operation?: string;
|
|
745
|
-
fallback?: T;
|
|
746
|
-
retryable?: boolean;
|
|
747
|
-
}): Promise<T>;
|
|
748
|
-
/**
|
|
749
|
-
* 创建带有错误处理的重试逻辑
|
|
750
|
-
*/
|
|
751
|
-
retry<T>(fn: () => Promise<T>, options?: {
|
|
752
|
-
maxRetries?: number;
|
|
753
|
-
retryDelay?: number;
|
|
754
|
-
backoff?: boolean;
|
|
755
|
-
onRetry?: (error: Error, attempt: number) => void;
|
|
756
|
-
}): Promise<T>;
|
|
757
|
-
/**
|
|
758
|
-
* 判断错误是否可重试
|
|
759
|
-
*/
|
|
760
|
-
isRetryable(error: Error): boolean;
|
|
761
|
-
/**
|
|
762
|
-
* 判断错误是否需要降级处理
|
|
763
|
-
*/
|
|
764
|
-
shouldDegrade(error: Error): boolean;
|
|
765
|
-
/**
|
|
766
|
-
* 创建降级响应
|
|
767
|
-
*/
|
|
768
|
-
createDegradedResponse<T>(fallback: T, error?: Error): {
|
|
769
|
-
success: false;
|
|
770
|
-
degraded: true;
|
|
771
|
-
fallback: T;
|
|
772
|
-
error?: Error;
|
|
773
|
-
};
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
/**
|
|
777
|
-
* Token management utilities
|
|
778
|
-
*/
|
|
779
|
-
declare class TokenManager {
|
|
780
|
-
constructor(_runtime: LingyaoRuntime);
|
|
781
|
-
/**
|
|
782
|
-
* Generate a new device token
|
|
783
|
-
*/
|
|
784
|
-
generateDeviceToken(pairingId: string, deviceInfo: DeviceInfo, expiryDays?: number): DeviceToken;
|
|
785
|
-
/**
|
|
786
|
-
* Validate a device token
|
|
787
|
-
*/
|
|
788
|
-
validateToken(token: string, storedSecret: string): boolean;
|
|
789
|
-
/**
|
|
790
|
-
* Check if token is expired
|
|
791
|
-
*/
|
|
792
|
-
isTokenExpired(token: DeviceToken): boolean;
|
|
793
|
-
/**
|
|
794
|
-
* Refresh an existing token
|
|
795
|
-
*/
|
|
796
|
-
refreshToken(oldToken: DeviceToken, expiryDays?: number): DeviceToken;
|
|
797
|
-
/**
|
|
798
|
-
* Extract device ID from token string
|
|
799
|
-
*/
|
|
800
|
-
extractDeviceId(token: string): string | null;
|
|
801
|
-
/**
|
|
802
|
-
* Generate a unique device ID
|
|
803
|
-
*/
|
|
804
|
-
private generateDeviceId;
|
|
805
|
-
/**
|
|
806
|
-
* Generate a random secret key
|
|
807
|
-
*/
|
|
808
|
-
private generateSecret;
|
|
809
|
-
/**
|
|
810
|
-
* Generate a JWT-like token string
|
|
811
|
-
*/
|
|
812
|
-
private generateTokenString;
|
|
813
|
-
/**
|
|
814
|
-
* Sign data with secret
|
|
815
|
-
*/
|
|
816
|
-
private sign;
|
|
817
|
-
/**
|
|
818
|
-
* Base64URL encode without padding
|
|
819
|
-
*/
|
|
820
|
-
private base64UrlEncode;
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
/**
|
|
824
|
-
* 灵爻频道插件 - 服务器中转模式
|
|
825
|
-
*/
|
|
826
|
-
declare class LingyaoChannel {
|
|
827
|
-
private runtime;
|
|
828
|
-
private config;
|
|
829
|
-
private accountManager;
|
|
830
|
-
private tokenManager;
|
|
831
|
-
private serverClient;
|
|
832
|
-
private wsClient;
|
|
833
|
-
private processor;
|
|
834
|
-
private probe;
|
|
835
|
-
private monitor;
|
|
836
|
-
private errorHandler;
|
|
837
|
-
private startTime;
|
|
838
|
-
private gatewayId;
|
|
839
|
-
private isRunning;
|
|
840
|
-
private messageHandler;
|
|
841
|
-
constructor(runtime: LingyaoRuntime, config: LingyaoConfig);
|
|
842
|
-
/**
|
|
843
|
-
* 初始化频道
|
|
844
|
-
*/
|
|
845
|
-
initialize(): Promise<void>;
|
|
846
|
-
/**
|
|
847
|
-
* 启动频道
|
|
848
|
-
*/
|
|
849
|
-
start(): Promise<void>;
|
|
850
|
-
/**
|
|
851
|
-
* 向 lingyao 服务器注册 Gateway
|
|
852
|
-
*/
|
|
853
|
-
private registerToServer;
|
|
854
|
-
/**
|
|
855
|
-
* 处理来自鸿蒙 App 的消息
|
|
856
|
-
*/
|
|
857
|
-
private handleAppMessage;
|
|
858
|
-
/**
|
|
859
|
-
* 处理同步消息(日记、记忆等)
|
|
860
|
-
*/
|
|
861
|
-
private handleSyncMessage;
|
|
862
|
-
/**
|
|
863
|
-
* 映射消息类型
|
|
864
|
-
*/
|
|
865
|
-
private mapMessageType;
|
|
866
|
-
/**
|
|
867
|
-
* 处理 WebSocket 客户端事件
|
|
868
|
-
*/
|
|
869
|
-
private handleClientEvent;
|
|
870
|
-
/**
|
|
871
|
-
* 停止频道
|
|
872
|
-
*/
|
|
873
|
-
stop(): Promise<void>;
|
|
874
|
-
/**
|
|
875
|
-
* 发送通知到设备
|
|
876
|
-
*/
|
|
877
|
-
sendNotification(deviceId: string, notification: NotifyPayload): Promise<{
|
|
878
|
-
success: boolean;
|
|
879
|
-
error?: string;
|
|
880
|
-
queued?: boolean;
|
|
881
|
-
}>;
|
|
882
|
-
/**
|
|
883
|
-
* 发送文本到设备
|
|
884
|
-
*/
|
|
885
|
-
sendText(deviceId: string, text: string): Promise<{
|
|
886
|
-
success: boolean;
|
|
887
|
-
error?: string;
|
|
888
|
-
queued?: boolean;
|
|
889
|
-
}>;
|
|
890
|
-
/**
|
|
891
|
-
* 获取健康状态
|
|
892
|
-
*/
|
|
893
|
-
getHealthStatus(): Promise<HealthStatus>;
|
|
894
|
-
/**
|
|
895
|
-
* 获取配置
|
|
896
|
-
*/
|
|
897
|
-
getConfig(): LingyaoConfig;
|
|
898
|
-
/**
|
|
899
|
-
* 更新配置
|
|
900
|
-
*/
|
|
901
|
-
updateConfig(updates: Partial<LingyaoConfig>): Promise<void>;
|
|
902
|
-
/**
|
|
903
|
-
* 获取账号管理器
|
|
904
|
-
*/
|
|
905
|
-
getAccountManager(): AccountManager;
|
|
906
|
-
/**
|
|
907
|
-
* 获取 Token 管理器
|
|
908
|
-
*/
|
|
909
|
-
getTokenManager(): TokenManager;
|
|
910
|
-
/**
|
|
911
|
-
* 获取服务器客户端
|
|
912
|
-
*/
|
|
913
|
-
getServerClient(): ServerHttpClient | null;
|
|
914
|
-
/**
|
|
915
|
-
/**
|
|
916
|
-
* 获取 WebSocket 客户端
|
|
917
|
-
*/
|
|
918
|
-
getWSClient(): LingyaoWSClient | null;
|
|
919
|
-
/**
|
|
920
|
-
* 获取消息处理器
|
|
921
|
-
*/
|
|
922
|
-
getMessageProcessor(): MessageProcessor | null;
|
|
923
|
-
/**
|
|
924
|
-
* 设置消息处理器
|
|
925
|
-
*/
|
|
926
|
-
setMessageHandler(handler: (message: AgentMessage) => void | Promise<void>): void;
|
|
927
|
-
/**
|
|
928
|
-
* 获取监控器
|
|
929
|
-
*/
|
|
930
|
-
getMonitor(): Monitor;
|
|
931
|
-
/**
|
|
932
|
-
* 获取错误处理器
|
|
933
|
-
*/
|
|
934
|
-
getErrorHandler(): ErrorHandler;
|
|
935
|
-
/**
|
|
936
|
-
* 获取监控摘要
|
|
937
|
-
*/
|
|
938
|
-
getMonitoringSummary(): {
|
|
939
|
-
uptime: number;
|
|
940
|
-
connections: number;
|
|
941
|
-
messages: {
|
|
942
|
-
sent: number;
|
|
943
|
-
received: number;
|
|
944
|
-
failed: number;
|
|
945
|
-
};
|
|
946
|
-
errors: number;
|
|
947
|
-
heartbeats: {
|
|
948
|
-
sent: number;
|
|
949
|
-
missed: number;
|
|
950
|
-
};
|
|
951
|
-
};
|
|
952
|
-
/**
|
|
953
|
-
* 获取错误统计
|
|
954
|
-
*/
|
|
955
|
-
getErrorStats(): {
|
|
956
|
-
byCode: Record<string, number>;
|
|
957
|
-
total: number;
|
|
958
|
-
recent: Array<{
|
|
959
|
-
code: string;
|
|
960
|
-
error: LingyaoError;
|
|
961
|
-
timestamp: number;
|
|
962
|
-
}>;
|
|
963
|
-
};
|
|
964
|
-
/**
|
|
965
|
-
* 生成 Gateway ID
|
|
966
|
-
*/
|
|
967
|
-
private generateGatewayId;
|
|
968
|
-
/**
|
|
969
|
-
* 获取运行时主机名
|
|
970
|
-
*/
|
|
971
|
-
private getRuntimeHostname;
|
|
972
|
-
}
|
|
973
19
|
|
|
974
20
|
/**
|
|
975
21
|
* Validate configuration object
|
|
@@ -982,22 +28,6 @@ declare function getDefaultConfig(): LingyaoConfig;
|
|
|
982
28
|
|
|
983
29
|
declare const lingyaoPlugin: ChannelPlugin<ResolvedAccount, LingyaoProbeResult>;
|
|
984
30
|
declare function initializeLingyaoRuntime(runtime: PluginRuntime): void;
|
|
985
|
-
/** @deprecated Use the default export (OpenClaw SDK entry) instead. */
|
|
986
|
-
declare function createPlugin(runtime: LingyaoRuntime, config?: Partial<LingyaoConfig>): Promise<LingyaoChannel>;
|
|
987
|
-
/** @deprecated Use openclaw.plugin.json for plugin metadata. */
|
|
988
|
-
declare const pluginMetadata: {
|
|
989
|
-
name: string;
|
|
990
|
-
version: string;
|
|
991
|
-
description: string;
|
|
992
|
-
type: string;
|
|
993
|
-
capabilities: {
|
|
994
|
-
chatTypes: string[];
|
|
995
|
-
media: boolean;
|
|
996
|
-
reactions: boolean;
|
|
997
|
-
threads: boolean;
|
|
998
|
-
};
|
|
999
|
-
defaultConfig: LingyaoConfig;
|
|
1000
|
-
};
|
|
1001
31
|
|
|
1002
32
|
declare const plugin: {
|
|
1003
33
|
id: string;
|
|
@@ -1009,4 +39,4 @@ declare const plugin: {
|
|
|
1009
39
|
setChannelRuntime?: (runtime: openclaw_plugin_sdk.PluginRuntime) => void;
|
|
1010
40
|
};
|
|
1011
41
|
|
|
1012
|
-
export { type AgentMessage,
|
|
42
|
+
export { type AgentMessage, LingyaoConfig, plugin as default, getDefaultConfig, initializeLingyaoRuntime, lingyaoPlugin, validateConfig };
|