@lingyao037/openclaw-lingyao-cli 0.3.5 → 0.4.1

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.js CHANGED
@@ -1,8 +1,67 @@
1
+ // src/index.ts
2
+ import {
3
+ defineChannelPluginEntry,
4
+ createChatChannelPlugin
5
+ } from "openclaw/plugin-sdk/core";
6
+
1
7
  // src/runtime.ts
8
+ import { readFileSync, writeFileSync, mkdirSync, existsSync, unlinkSync } from "fs";
9
+ import { join } from "path";
2
10
  var globalRuntime = null;
3
11
  function setRuntime(runtime) {
4
12
  globalRuntime = runtime;
5
13
  }
14
+ function adaptPluginRuntime(pr) {
15
+ const noop = (..._args) => {
16
+ };
17
+ const rawLogger = pr.logging?.getChildLogger?.() ?? {
18
+ info: console.info.bind(console),
19
+ warn: console.warn.bind(console),
20
+ error: console.error.bind(console)
21
+ };
22
+ const childLogger = {
23
+ info: rawLogger.info,
24
+ warn: rawLogger.warn,
25
+ error: rawLogger.error,
26
+ debug: rawLogger.debug ?? noop
27
+ };
28
+ const stateDir = pr.state?.resolveStateDir?.() ?? join(process.cwd(), ".lingyao-data");
29
+ const storeDir = join(stateDir, "lingyao");
30
+ return {
31
+ config: { enabled: true },
32
+ logger: childLogger,
33
+ storage: {
34
+ async get(key) {
35
+ try {
36
+ const filePath = join(storeDir, `${key}.json`);
37
+ if (!existsSync(filePath)) return null;
38
+ const data = readFileSync(filePath, "utf-8");
39
+ return JSON.parse(data);
40
+ } catch {
41
+ return null;
42
+ }
43
+ },
44
+ async set(key, value) {
45
+ if (!existsSync(storeDir)) {
46
+ mkdirSync(storeDir, { recursive: true });
47
+ }
48
+ const filePath = join(storeDir, `${key}.json`);
49
+ writeFileSync(filePath, JSON.stringify(value, null, 2), "utf-8");
50
+ },
51
+ async delete(key) {
52
+ const filePath = join(storeDir, `${key}.json`);
53
+ if (existsSync(filePath)) {
54
+ unlinkSync(filePath);
55
+ }
56
+ }
57
+ },
58
+ tools: {
59
+ async call() {
60
+ throw new Error("Tool calls not available in SDK mode");
61
+ }
62
+ }
63
+ };
64
+ }
6
65
 
7
66
  // src/adapters/config.ts
8
67
  function extractAccounts(cfg) {
@@ -34,9 +93,10 @@ function createConfigAdapter() {
34
93
  }
35
94
  return {
36
95
  id: resolvedId,
96
+ accountId: resolvedId,
37
97
  enabled: accountConfig?.enabled !== false,
38
98
  dmPolicy: accountConfig?.dmPolicy ?? "paired",
39
- allowFrom: Object.freeze(accountConfig?.allowFrom ?? []),
99
+ allowFrom: accountConfig?.allowFrom ?? [],
40
100
  rawConfig: accountConfig
41
101
  };
42
102
  },
@@ -268,6 +328,20 @@ function createOutboundAdapter(getOrchestrator2) {
268
328
  };
269
329
  }
270
330
 
331
+ // src/adapters/setup.ts
332
+ import { createPatchedAccountSetupAdapter } from "openclaw/plugin-sdk/setup";
333
+ function createSetupAdapter() {
334
+ return createPatchedAccountSetupAdapter({
335
+ channelKey: "lingyao",
336
+ alwaysUseAccounts: true,
337
+ ensureChannelEnabled: true,
338
+ ensureAccountEnabled: true,
339
+ buildPatch() {
340
+ return {};
341
+ }
342
+ });
343
+ }
344
+
271
345
  // src/orchestrator.ts
272
346
  import { hostname } from "os";
273
347
 
@@ -345,7 +419,7 @@ var ServerHttpClient = class {
345
419
  /**
346
420
  * 注册 Gateway 到服务器
347
421
  */
348
- async register(capabilities = {}) {
422
+ async register(capabilities2 = {}) {
349
423
  if (this.isConnecting) {
350
424
  throw new Error("Registration already in progress");
351
425
  }
@@ -360,7 +434,7 @@ var ServerHttpClient = class {
360
434
  capabilities: {
361
435
  websocket: false,
362
436
  compression: false,
363
- ...capabilities
437
+ ...capabilities2
364
438
  }
365
439
  }
366
440
  );
@@ -1056,6 +1130,42 @@ var AccountManager = class {
1056
1130
  this.runtime.logger.info(`Account revoked: ${deviceId}`);
1057
1131
  return true;
1058
1132
  }
1133
+ /**
1134
+ * Manually add a device by deviceId (user-initiated pairing).
1135
+ * No pairing code or deviceToken required — the user explicitly
1136
+ * trusts this device from the OpenClaw CLI.
1137
+ */
1138
+ async addDevice(deviceId, deviceInfo) {
1139
+ const existing = this.accounts.get(deviceId);
1140
+ if (existing) {
1141
+ existing.status = "active";
1142
+ existing.deviceInfo = deviceInfo;
1143
+ existing.lastSeenAt = Date.now();
1144
+ await this.saveAccounts();
1145
+ this.runtime.logger.info(`Device re-activated: ${deviceId} (${deviceInfo.name})`);
1146
+ return existing;
1147
+ }
1148
+ const now = Date.now();
1149
+ const account = {
1150
+ deviceId,
1151
+ deviceInfo,
1152
+ deviceToken: {
1153
+ deviceId,
1154
+ pairingId: `manual_${now}`,
1155
+ token: "",
1156
+ secret: "",
1157
+ expiresAt: 0,
1158
+ deviceInfo
1159
+ },
1160
+ pairedAt: now,
1161
+ lastSeenAt: now,
1162
+ status: "active"
1163
+ };
1164
+ this.accounts.set(deviceId, account);
1165
+ await this.saveAccounts();
1166
+ this.runtime.logger.info(`Device added: ${deviceId} (${deviceInfo.name})`);
1167
+ return account;
1168
+ }
1059
1169
  /**
1060
1170
  * Refresh device token
1061
1171
  */
@@ -3202,17 +3312,12 @@ function getOrchestrator() {
3202
3312
  return orchestrator;
3203
3313
  }
3204
3314
  var configAdapter = createConfigAdapter();
3315
+ var setupAdapter = createSetupAdapter();
3205
3316
  var messagingAdapter = createMessagingAdapter();
3206
3317
  var gatewayAdapter = createGatewayAdapter(getOrchestrator);
3207
3318
  var directoryAdapter = createDirectoryAdapter(getOrchestrator);
3208
3319
  var outboundAdapter = createOutboundAdapter(getOrchestrator);
3209
3320
  var statusAdapter = null;
3210
- function getStatusAdapter(runtime) {
3211
- if (!statusAdapter) {
3212
- statusAdapter = createStatusAdapter(getOrchestrator, runtime);
3213
- }
3214
- return statusAdapter;
3215
- }
3216
3321
  var securityOptions = {
3217
3322
  dm: {
3218
3323
  channelKey: "lingyao",
@@ -3242,41 +3347,101 @@ var pairingOptions = {
3242
3347
  }
3243
3348
  }
3244
3349
  };
3245
- function buildPluginBase(runtime) {
3246
- return {
3247
- id: "lingyao",
3248
- meta: {
3350
+ var capabilities = {
3351
+ chatTypes: ["direct"],
3352
+ media: false,
3353
+ reactions: false,
3354
+ threads: false,
3355
+ polls: false,
3356
+ edit: false,
3357
+ unsend: false,
3358
+ reply: false,
3359
+ effects: false,
3360
+ groupManagement: false,
3361
+ nativeCommands: false,
3362
+ blockStreaming: true
3363
+ };
3364
+ var meta = {
3365
+ id: "lingyao",
3366
+ label: "\u7075\u723B",
3367
+ selectionLabel: "\u7075\u723B (HarmonyOS)",
3368
+ docsPath: "/channels/lingyao",
3369
+ docsLabel: "\u7075\u723B\u6587\u6863",
3370
+ blurb: "\u901A\u8FC7 lingyao.live \u670D\u52A1\u5668\u4E2D\u8F6C\u4E0E\u9E3F\u8499\u7075\u723B App \u53CC\u5411\u540C\u6B65\u65E5\u8BB0\u548C\u8BB0\u5FC6",
3371
+ order: 50,
3372
+ aliases: ["lingyao", "\u7075\u723B"]
3373
+ };
3374
+ function buildPlugin() {
3375
+ const composed = createChatChannelPlugin({
3376
+ base: {
3249
3377
  id: "lingyao",
3250
- label: "\u7075\u723B",
3251
- selectionLabel: "\u7075\u723B (HarmonyOS)",
3252
- docsPath: "/channels/lingyao",
3253
- docsLabel: "\u7075\u723B\u6587\u6863",
3254
- blurb: "\u901A\u8FC7 lingyao.live \u670D\u52A1\u5668\u4E2D\u8F6C\u4E0E\u9E3F\u8499\u7075\u723B App \u53CC\u5411\u540C\u6B65\u65E5\u8BB0\u548C\u8BB0\u5FC6",
3255
- order: 50,
3256
- aliases: ["lingyao", "\u7075\u723B"]
3257
- },
3258
- capabilities: {
3259
- chatTypes: ["direct"],
3260
- media: false,
3261
- reactions: false,
3262
- threads: false,
3263
- polls: false,
3264
- edit: false,
3265
- unsend: false,
3266
- reply: false,
3267
- effects: false,
3268
- groupManagement: false,
3269
- nativeCommands: false,
3270
- blockStreaming: true
3378
+ meta,
3379
+ capabilities,
3380
+ config: configAdapter,
3381
+ setup: setupAdapter
3271
3382
  },
3272
- config: configAdapter,
3383
+ security: securityOptions,
3384
+ pairing: pairingOptions,
3385
+ outbound: outboundAdapter
3386
+ });
3387
+ return {
3388
+ ...composed,
3273
3389
  gateway: gatewayAdapter,
3274
- outbound: outboundAdapter,
3275
- status: getStatusAdapter(runtime),
3390
+ status: statusAdapter ?? void 0,
3276
3391
  directory: directoryAdapter,
3277
3392
  messaging: messagingAdapter
3278
3393
  };
3279
3394
  }
3395
+ var index_default = defineChannelPluginEntry({
3396
+ id: "lingyao",
3397
+ name: "Lingyao",
3398
+ description: "Lingyao Channel Plugin - bidirectional sync via lingyao.live server relay",
3399
+ plugin: {
3400
+ get id() {
3401
+ return "lingyao";
3402
+ },
3403
+ get meta() {
3404
+ return buildPlugin().meta;
3405
+ },
3406
+ get capabilities() {
3407
+ return buildPlugin().capabilities;
3408
+ },
3409
+ get config() {
3410
+ return buildPlugin().config;
3411
+ },
3412
+ get setup() {
3413
+ return buildPlugin().setup;
3414
+ },
3415
+ get security() {
3416
+ return buildPlugin().security;
3417
+ },
3418
+ get pairing() {
3419
+ return buildPlugin().pairing;
3420
+ },
3421
+ get outbound() {
3422
+ return buildPlugin().outbound;
3423
+ },
3424
+ get gateway() {
3425
+ return buildPlugin().gateway;
3426
+ },
3427
+ get status() {
3428
+ if (!statusAdapter) return void 0;
3429
+ return statusAdapter;
3430
+ },
3431
+ get directory() {
3432
+ return buildPlugin().directory;
3433
+ },
3434
+ get messaging() {
3435
+ return buildPlugin().messaging;
3436
+ }
3437
+ },
3438
+ setRuntime(runtime) {
3439
+ const adapted = adaptPluginRuntime(runtime);
3440
+ setRuntime(adapted);
3441
+ orchestrator = new MultiAccountOrchestrator(adapted);
3442
+ statusAdapter = createStatusAdapter(getOrchestrator, adapted);
3443
+ }
3444
+ });
3280
3445
  async function createPlugin(runtime, config = {}) {
3281
3446
  const fullConfig = { ...getDefaultConfig(), ...config };
3282
3447
  const validatedConfig = validateConfig(fullConfig);
@@ -3286,7 +3451,7 @@ async function createPlugin(runtime, config = {}) {
3286
3451
  }
3287
3452
  var pluginMetadata = {
3288
3453
  name: "lingyao",
3289
- version: "0.3.0",
3454
+ version: "0.4.0",
3290
3455
  description: "Lingyao Channel Plugin - bidirectional sync via lingyao.live server relay",
3291
3456
  type: "channel",
3292
3457
  capabilities: {
@@ -3297,27 +3462,6 @@ var pluginMetadata = {
3297
3462
  },
3298
3463
  defaultConfig: getDefaultConfig()
3299
3464
  };
3300
- var pluginEntry = {
3301
- id: "lingyao",
3302
- name: "Lingyao",
3303
- description: "Lingyao Channel Plugin - bidirectional sync via lingyao.live",
3304
- setRuntime(runtime) {
3305
- const rt = runtime;
3306
- setRuntime(rt);
3307
- orchestrator = new MultiAccountOrchestrator(rt);
3308
- },
3309
- get plugin() {
3310
- const rt = orchestrator?.runtime;
3311
- if (!rt) {
3312
- throw new Error("Runtime not set. Call setRuntime() before accessing plugin.");
3313
- }
3314
- return buildPluginBase(rt);
3315
- },
3316
- // Security and pairing options for createChatChannelPlugin composition
3317
- security: securityOptions,
3318
- pairing: pairingOptions
3319
- };
3320
- var index_default = pluginEntry;
3321
3465
  export {
3322
3466
  LINGYAO_SERVER_URL,
3323
3467
  LingyaoChannel,