@lingyao037/openclaw-lingyao-cli 1.3.2 → 1.3.3
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/index.d.ts +7 -1
- package/dist/index.js +78 -95
- package/dist/index.js.map +1 -1
- package/dist/setup-entry.js +5 -1
- package/dist/setup-entry.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,13 @@ import { c as LingyaoConfig } from './types-BZMU9mea.js';
|
|
|
5
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';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Agent message
|
|
8
|
+
* Agent message types — used for type-safe message passing.
|
|
9
|
+
*
|
|
10
|
+
* NOTE: MessageProcessor has been removed. Inbound messages are now dispatched
|
|
11
|
+
* directly via SDK's dispatchInboundDirectDmWithRuntime in orchestrator.ts.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Agent message format - messages passed to Agent
|
|
9
15
|
*/
|
|
10
16
|
interface AgentMessage {
|
|
11
17
|
id: string;
|
package/dist/index.js
CHANGED
|
@@ -156,7 +156,10 @@ function createGatewayAdapter(getOrchestrator2) {
|
|
|
156
156
|
throw new Error("Orchestrator not initialized. Ensure setRuntime was called.");
|
|
157
157
|
}
|
|
158
158
|
ctx.log?.info(`Starting account "${ctx.accountId}"`);
|
|
159
|
-
await orchestrator2.start(ctx.account
|
|
159
|
+
await orchestrator2.start(ctx.account, {
|
|
160
|
+
channelRuntime: ctx.channelRuntime,
|
|
161
|
+
cfg: ctx.cfg
|
|
162
|
+
});
|
|
160
163
|
ctx.log?.info(`Account "${ctx.accountId}" started successfully`);
|
|
161
164
|
},
|
|
162
165
|
async stopAccount(ctx) {
|
|
@@ -443,6 +446,9 @@ function resolveLingyaoWsHeartbeatIntervalMs(account, httpClient) {
|
|
|
443
446
|
return Math.max(MIN_MS, Math.min(ms, MAX_MS));
|
|
444
447
|
}
|
|
445
448
|
|
|
449
|
+
// src/orchestrator.ts
|
|
450
|
+
import { dispatchInboundDirectDmWithRuntime } from "openclaw/plugin-sdk/channel-inbound";
|
|
451
|
+
|
|
446
452
|
// src/server-client.ts
|
|
447
453
|
import axios from "axios";
|
|
448
454
|
function isAxiosError(error) {
|
|
@@ -1403,60 +1409,6 @@ var AccountManager = class {
|
|
|
1403
1409
|
}
|
|
1404
1410
|
};
|
|
1405
1411
|
|
|
1406
|
-
// src/bot.ts
|
|
1407
|
-
var MessageProcessor = class {
|
|
1408
|
-
runtime;
|
|
1409
|
-
messageHandler = null;
|
|
1410
|
-
constructor(runtime) {
|
|
1411
|
-
this.runtime = runtime;
|
|
1412
|
-
}
|
|
1413
|
-
/**
|
|
1414
|
-
* Initialize the message processor
|
|
1415
|
-
*/
|
|
1416
|
-
async initialize() {
|
|
1417
|
-
this.runtime.logger.info("Message Processor initialized");
|
|
1418
|
-
}
|
|
1419
|
-
/**
|
|
1420
|
-
* Set the message handler for delivering messages to Agent
|
|
1421
|
-
*/
|
|
1422
|
-
setMessageHandler(handler) {
|
|
1423
|
-
this.messageHandler = handler;
|
|
1424
|
-
}
|
|
1425
|
-
/**
|
|
1426
|
-
* Get the currently registered Agent message handler.
|
|
1427
|
-
*/
|
|
1428
|
-
getMessageHandler() {
|
|
1429
|
-
return this.messageHandler;
|
|
1430
|
-
}
|
|
1431
|
-
/**
|
|
1432
|
-
* Deliver a normalized message directly to the registered Agent handler.
|
|
1433
|
-
*/
|
|
1434
|
-
async deliverToAgent(message) {
|
|
1435
|
-
if (!this.messageHandler) {
|
|
1436
|
-
this.runtime.logger.warn("No message handler set, message not delivered to Agent", {
|
|
1437
|
-
messageId: message.id,
|
|
1438
|
-
type: message.type,
|
|
1439
|
-
deviceId: message.deviceId
|
|
1440
|
-
});
|
|
1441
|
-
return;
|
|
1442
|
-
}
|
|
1443
|
-
this.runtime.logger.info("Delivering message to Agent", {
|
|
1444
|
-
messageId: message.id,
|
|
1445
|
-
type: message.type,
|
|
1446
|
-
from: message.from,
|
|
1447
|
-
deviceId: message.deviceId,
|
|
1448
|
-
contentLength: message.content?.length ?? 0
|
|
1449
|
-
});
|
|
1450
|
-
try {
|
|
1451
|
-
await this.messageHandler(message);
|
|
1452
|
-
this.runtime.logger.info("Agent handler completed", { messageId: message.id });
|
|
1453
|
-
} catch (error) {
|
|
1454
|
-
this.runtime.logger.error("Agent handler threw error", { messageId: message.id, error });
|
|
1455
|
-
throw error;
|
|
1456
|
-
}
|
|
1457
|
-
}
|
|
1458
|
-
};
|
|
1459
|
-
|
|
1460
1412
|
// src/probe.ts
|
|
1461
1413
|
var Probe = class {
|
|
1462
1414
|
runtime;
|
|
@@ -2307,32 +2259,13 @@ function generateGatewayId(accountId) {
|
|
|
2307
2259
|
var MultiAccountOrchestrator = class {
|
|
2308
2260
|
runtime;
|
|
2309
2261
|
accounts = /* @__PURE__ */ new Map();
|
|
2310
|
-
messageHandler = null;
|
|
2311
2262
|
constructor(runtime) {
|
|
2312
2263
|
this.runtime = runtime;
|
|
2313
2264
|
}
|
|
2314
|
-
/**
|
|
2315
|
-
* Set the message handler for delivering messages to the Agent.
|
|
2316
|
-
* Propagates to all running accounts.
|
|
2317
|
-
*/
|
|
2318
|
-
setMessageHandler(handler) {
|
|
2319
|
-
this.messageHandler = handler;
|
|
2320
|
-
for (const state of this.accounts.values()) {
|
|
2321
|
-
if (state.messageProcessor) {
|
|
2322
|
-
state.messageProcessor.setMessageHandler(handler);
|
|
2323
|
-
}
|
|
2324
|
-
}
|
|
2325
|
-
}
|
|
2326
|
-
/**
|
|
2327
|
-
* Get the current message handler (for gateway adapter injection).
|
|
2328
|
-
*/
|
|
2329
|
-
getMessageHandler() {
|
|
2330
|
-
return this.messageHandler;
|
|
2331
|
-
}
|
|
2332
2265
|
/**
|
|
2333
2266
|
* Start an account: create components, register to server, connect WS.
|
|
2334
2267
|
*/
|
|
2335
|
-
async start(account) {
|
|
2268
|
+
async start(account, context) {
|
|
2336
2269
|
const { id: accountId } = account;
|
|
2337
2270
|
const existing = this.accounts.get(accountId);
|
|
2338
2271
|
if (existing?.status === "running") {
|
|
@@ -2343,7 +2276,6 @@ var MultiAccountOrchestrator = class {
|
|
|
2343
2276
|
const gatewayId = account.gatewayId ?? generateGatewayId(accountId);
|
|
2344
2277
|
const storagePrefix = `lingyao:${accountId}`;
|
|
2345
2278
|
const accountManager = new AccountManager(this.runtime);
|
|
2346
|
-
const messageProcessor = new MessageProcessor(this.runtime);
|
|
2347
2279
|
const probe = new Probe(this.runtime);
|
|
2348
2280
|
const monitor = new Monitor(this.runtime);
|
|
2349
2281
|
const errorHandler = new ErrorHandler(this.runtime);
|
|
@@ -2358,21 +2290,18 @@ var MultiAccountOrchestrator = class {
|
|
|
2358
2290
|
wsClient: null,
|
|
2359
2291
|
httpClient,
|
|
2360
2292
|
accountManager,
|
|
2361
|
-
messageProcessor,
|
|
2362
2293
|
probe,
|
|
2363
2294
|
monitor,
|
|
2364
2295
|
errorHandler,
|
|
2365
2296
|
status: "starting",
|
|
2366
2297
|
startTime: Date.now(),
|
|
2367
|
-
gatewayId
|
|
2298
|
+
gatewayId,
|
|
2299
|
+
channelRuntime: context?.channelRuntime,
|
|
2300
|
+
cfg: context?.cfg
|
|
2368
2301
|
};
|
|
2369
2302
|
this.accounts.set(accountId, state);
|
|
2370
2303
|
try {
|
|
2371
2304
|
await accountManager.initialize();
|
|
2372
|
-
await messageProcessor.initialize();
|
|
2373
|
-
if (this.messageHandler) {
|
|
2374
|
-
messageProcessor.setMessageHandler(this.messageHandler);
|
|
2375
|
-
}
|
|
2376
2305
|
await this.registerToServer(state);
|
|
2377
2306
|
const wsHeartbeatMs = resolveLingyaoWsHeartbeatIntervalMs(account, httpClient);
|
|
2378
2307
|
this.runtime.logger.info(`Lingyao WebSocket heartbeat interval: ${wsHeartbeatMs}ms (relay serverConfig / config)`);
|
|
@@ -2548,33 +2477,87 @@ var MultiAccountOrchestrator = class {
|
|
|
2548
2477
|
};
|
|
2549
2478
|
}
|
|
2550
2479
|
/**
|
|
2551
|
-
* Handle sync message (diary or memory).
|
|
2480
|
+
* Handle sync message (diary or memory) via SDK dispatch pipeline.
|
|
2552
2481
|
*/
|
|
2553
2482
|
async handleSyncMessage(state, deviceId, message) {
|
|
2554
|
-
if (!state.
|
|
2555
|
-
this.runtime.logger.warn(`[${state.accountId}]
|
|
2483
|
+
if (!state.channelRuntime || !state.cfg) {
|
|
2484
|
+
this.runtime.logger.warn(`[${state.accountId}] channelRuntime/cfg not available, cannot dispatch to Agent`, {
|
|
2556
2485
|
messageId: message.id,
|
|
2557
2486
|
messageType: message.type,
|
|
2558
2487
|
deviceId
|
|
2559
2488
|
});
|
|
2560
2489
|
return;
|
|
2561
2490
|
}
|
|
2562
|
-
this.runtime.logger.info(`[${state.accountId}]
|
|
2491
|
+
this.runtime.logger.info(`[${state.accountId}] Dispatching sync message to Agent via SDK pipeline`, {
|
|
2563
2492
|
messageId: message.id,
|
|
2564
2493
|
messageType: message.type,
|
|
2565
2494
|
deviceId,
|
|
2566
2495
|
contentLength: message.content?.length ?? 0
|
|
2567
2496
|
});
|
|
2568
|
-
const
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2497
|
+
const dmRuntime = {
|
|
2498
|
+
channel: {
|
|
2499
|
+
routing: {
|
|
2500
|
+
resolveAgentRoute: state.channelRuntime.routing.resolveAgentRoute
|
|
2501
|
+
},
|
|
2502
|
+
session: {
|
|
2503
|
+
resolveStorePath: state.channelRuntime.session.resolveStorePath,
|
|
2504
|
+
readSessionUpdatedAt: state.channelRuntime.session.readSessionUpdatedAt,
|
|
2505
|
+
recordInboundSession: state.channelRuntime.session.recordInboundSession
|
|
2506
|
+
},
|
|
2507
|
+
reply: {
|
|
2508
|
+
resolveEnvelopeFormatOptions: state.channelRuntime.reply.resolveEnvelopeFormatOptions,
|
|
2509
|
+
formatAgentEnvelope: state.channelRuntime.reply.formatAgentEnvelope,
|
|
2510
|
+
finalizeInboundContext: state.channelRuntime.reply.finalizeInboundContext,
|
|
2511
|
+
dispatchReplyWithBufferedBlockDispatcher: state.channelRuntime.reply.dispatchReplyWithBufferedBlockDispatcher
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2576
2514
|
};
|
|
2577
|
-
|
|
2515
|
+
try {
|
|
2516
|
+
await dispatchInboundDirectDmWithRuntime({
|
|
2517
|
+
cfg: state.cfg,
|
|
2518
|
+
runtime: dmRuntime,
|
|
2519
|
+
channel: "lingyao",
|
|
2520
|
+
channelLabel: "\u7075\u723B",
|
|
2521
|
+
accountId: state.accountId,
|
|
2522
|
+
peer: { kind: "direct", id: deviceId },
|
|
2523
|
+
senderId: deviceId,
|
|
2524
|
+
senderAddress: deviceId,
|
|
2525
|
+
recipientAddress: state.gatewayId,
|
|
2526
|
+
conversationLabel: `\u7075\u723B DM with ${deviceId}`,
|
|
2527
|
+
rawBody: message.content,
|
|
2528
|
+
messageId: message.id,
|
|
2529
|
+
timestamp: message.timestamp,
|
|
2530
|
+
bodyForAgent: message.content,
|
|
2531
|
+
provider: "lingyao",
|
|
2532
|
+
surface: "lingyao",
|
|
2533
|
+
extraContext: {
|
|
2534
|
+
messageType: message.type === "sync_diary" ? "diary" : "memory",
|
|
2535
|
+
metadata: message.metadata || {}
|
|
2536
|
+
},
|
|
2537
|
+
deliver: async (payload) => {
|
|
2538
|
+
const sent = this.sendNotification(state.accountId, deviceId, {
|
|
2539
|
+
type: "agent_reply",
|
|
2540
|
+
text: payload.text,
|
|
2541
|
+
mediaUrl: payload.mediaUrl,
|
|
2542
|
+
mediaUrls: payload.mediaUrls
|
|
2543
|
+
});
|
|
2544
|
+
if (!sent) {
|
|
2545
|
+
this.runtime.logger.warn(
|
|
2546
|
+
`[${state.accountId}] Failed to deliver Agent reply to ${deviceId}: WS not connected`
|
|
2547
|
+
);
|
|
2548
|
+
}
|
|
2549
|
+
},
|
|
2550
|
+
onRecordError: (err) => {
|
|
2551
|
+
this.runtime.logger.error(`[${state.accountId}] Failed to record inbound session`, err);
|
|
2552
|
+
},
|
|
2553
|
+
onDispatchError: (err, info) => {
|
|
2554
|
+
this.runtime.logger.error(`[${state.accountId}] Dispatch error`, { err, kind: info.kind });
|
|
2555
|
+
}
|
|
2556
|
+
});
|
|
2557
|
+
} catch (error) {
|
|
2558
|
+
this.runtime.logger.error(`[${state.accountId}] dispatchInboundDirectDmWithRuntime failed`, error);
|
|
2559
|
+
throw error;
|
|
2560
|
+
}
|
|
2578
2561
|
}
|
|
2579
2562
|
/**
|
|
2580
2563
|
* Create event handler for WS connection events on a specific account.
|