@lingyao037/openclaw-lingyao-cli 1.3.2 → 1.3.4

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/cli.mjs CHANGED
@@ -38,20 +38,19 @@ const NC = '\x1b[0m';
38
38
  function getMachineId() {
39
39
  try {
40
40
  const interfaces = os.networkInterfaces();
41
- const macs = [];
41
+ const macSet = new Set();
42
42
 
43
43
  for (const iface of Object.values(interfaces)) {
44
44
  if (!iface) continue;
45
45
  for (const alias of iface) {
46
46
  if (!alias.internal && alias.mac && alias.mac !== '00:00:00:00:00:00') {
47
- macs.push(alias.mac);
47
+ macSet.add(alias.mac);
48
48
  }
49
49
  }
50
50
  }
51
51
 
52
- if (macs.length > 0) {
53
- macs.sort();
54
- const macStr = macs.join('');
52
+ if (macSet.size > 0) {
53
+ const macStr = [...macSet].sort().join('');
55
54
  // MD5 哈希,与 orchestrator.ts 保持一致
56
55
  return createHash('md5').update(macStr).digest('hex').substring(0, 8);
57
56
  }
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 format - messages passed directly to Agent
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;
@@ -2282,16 +2234,16 @@ var ErrorHandler = class {
2282
2234
  function getMachineId() {
2283
2235
  try {
2284
2236
  const interfaces = networkInterfaces();
2285
- const macs = [];
2237
+ const macSet = /* @__PURE__ */ new Set();
2286
2238
  for (const iface of Object.values(interfaces)) {
2287
2239
  if (!iface) continue;
2288
2240
  for (const alias of iface) {
2289
2241
  if (!alias.internal && alias.mac && alias.mac !== "00:00:00:00:00:00") {
2290
- macs.push(alias.mac);
2242
+ macSet.add(alias.mac);
2291
2243
  }
2292
2244
  }
2293
2245
  }
2294
- macs.sort();
2246
+ const macs = [...macSet].sort();
2295
2247
  if (macs.length > 0) {
2296
2248
  return createHash("md5").update(macs.join("")).digest("hex").substring(0, 8);
2297
2249
  }
@@ -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.messageProcessor) {
2555
- this.runtime.logger.warn(`[${state.accountId}] Message processor not initialized, dropping message`, {
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}] Routing sync message to Agent`, {
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 agentMessage = {
2569
- id: message.id,
2570
- type: message.type === "sync_diary" ? "diary" : "memory",
2571
- from: deviceId,
2572
- deviceId,
2573
- content: message.content,
2574
- metadata: message.metadata || {},
2575
- timestamp: message.timestamp
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
- await state.messageProcessor.deliverToAgent(agentMessage);
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.