@honor-claw/yoyo 1.6.1-beta.1 → 1.6.1-beta.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.
@@ -3,6 +3,8 @@ import { getProxyUrl as t, shouldUseProxy as n } from "../utils/proxy.mjs";
3
3
  import { ProxyAgent as r, request as i } from "undici";
4
4
  //#region src/apis/http-client.ts
5
5
  var a = class extends Error {
6
+ status;
7
+ data;
6
8
  constructor(e, t, n) {
7
9
  super(n), this.status = e, this.data = t, this.name = "HttpError";
8
10
  }
@@ -9,6 +9,7 @@ var r = { style: "SOUL.md" }, i = "[yoyoclaw-channel]", a = class {
9
9
  config;
10
10
  pendingFirstMessages = /* @__PURE__ */ new Map();
11
11
  initializedDeviceIds = /* @__PURE__ */ new Set();
12
+ pendingNodeConnects = /* @__PURE__ */ new Map();
12
13
  contextUpdateHandlers = {
13
14
  style: this.updateStyleContext.bind(this),
14
15
  "model.primary": this.updatePrimaryModel.bind(this),
@@ -116,7 +117,43 @@ var r = { style: "SOUL.md" }, i = "[yoyoclaw-channel]", a = class {
116
117
  }
117
118
  }
118
119
  forwardToNodeGateway(t, n, r, a) {
119
- e().info(`${i} forwarding user message to node gateway from ${n}, session: ${t}`), r.send(a);
120
+ e().info(`${i} forwarding user message to node gateway from ${n}, session: ${t}`);
121
+ let o = this.readNodeConnectRequest(a);
122
+ o && this.pendingNodeConnects.set(o.requestId, o.nodeId);
123
+ try {
124
+ r.send(a);
125
+ } catch (e) {
126
+ throw o && this.pendingNodeConnects.delete(o.requestId), e;
127
+ }
128
+ }
129
+ readNodeConnectRequest(e) {
130
+ let t;
131
+ try {
132
+ t = JSON.parse(e);
133
+ } catch {
134
+ return;
135
+ }
136
+ if (t.type !== "req" || t.method !== "connect" || typeof t.id != "string" || !t.params || typeof t.params != "object") return;
137
+ let n = t.params;
138
+ if (n.role !== "node" || !n.device || typeof n.device != "object") return;
139
+ let r = n.device;
140
+ if (!(typeof r.id != "string" || !r.id.trim())) return {
141
+ requestId: t.id,
142
+ nodeId: r.id
143
+ };
144
+ }
145
+ handleNodeConnectResponse(e) {
146
+ let t = e;
147
+ if (t.type !== "res" || typeof t.id != "string") return;
148
+ let n = this.pendingNodeConnects.get(t.id);
149
+ n && (this.pendingNodeConnects.delete(t.id), !(t.ok !== !0 || !t.payload || typeof t.payload != "object") && t.payload.type === "hello-ok" && this.armNodePairingAutoApproval(n));
150
+ }
151
+ async armNodePairingAutoApproval(t) {
152
+ if (!await this.adminClientManager.waitForReady()) {
153
+ e().warn(`${i} admin client not available for node pairing auto approval, nodeId: ${t}`);
154
+ return;
155
+ }
156
+ await this.adminClientManager.getClient()?.approvePendingNodePairing(t);
120
157
  }
121
158
  processMessageBuffer(e, t, n, r) {
122
159
  let i = this.pendingFirstMessages.get(t);
@@ -156,7 +193,7 @@ var r = { style: "SOUL.md" }, i = "[yoyoclaw-channel]", a = class {
156
193
  e().warn(`${i} gateway message is not valid JSON`);
157
194
  return;
158
195
  }
159
- if (!a.ok && a.error?.code === "NOT_PAIRED") {
196
+ if (this.handleNodeConnectResponse(a), !a.ok && a.error?.code === "NOT_PAIRED") {
160
197
  let r = a.error?.details?.requestId;
161
198
  if (!r) {
162
199
  e().warn(`${i} NOT_PAIRED without requestId, ignoring...`);
@@ -1,7 +1,8 @@
1
- import { GATEWAY_CLIENT_IDS as e, GATEWAY_CLIENT_MODES as t } from "./types/client.mjs";
2
- import { ProtocolGatewayClient as n } from "./protocol-client.mjs";
1
+ import { useClawLogger as e } from "../utils/logger.mjs";
2
+ import { GATEWAY_CLIENT_IDS as t, GATEWAY_CLIENT_MODES as n } from "./types/client.mjs";
3
+ import { ProtocolGatewayClient as r } from "./protocol-client.mjs";
3
4
  //#region src/gateway-client/admin-client.ts
4
- var r = {
5
+ var i = {
5
6
  role: "operator",
6
7
  scopes: [
7
8
  "operator.admin",
@@ -11,12 +12,12 @@ var r = {
11
12
  "operator.approvals",
12
13
  "operator.pairing"
13
14
  ],
14
- clientId: e.CLI,
15
+ clientId: t.CLI,
15
16
  displayName: "YOYO-Control",
16
- clientMode: t.BACKEND
17
- }, i = class extends n {
17
+ clientMode: n.BACKEND
18
+ }, a = "[yoyoclaw-adminGatewayClient]", o = class extends r {
18
19
  constructor(e = {}) {
19
- super(e, r);
20
+ super(e, i);
20
21
  }
21
22
  async setAgentFile(e, t, n = "main") {
22
23
  return this.sendRequest("agents.files.set", {
@@ -49,6 +50,16 @@ var r = {
49
50
  async devicePairApprove(e) {
50
51
  return this.sendRequest("device.pair.approve", { requestId: e });
51
52
  }
53
+ async approvePendingNodePairing(t) {
54
+ let n = t.trim();
55
+ if (!n) return !1;
56
+ try {
57
+ let t = (await this.sendRequest("node.pair.list", {})).pending?.find((e) => e.nodeId === n);
58
+ return t ? (e().info(`${a} auto approving node pairing, nodeId: ${n}, requestId: ${t.requestId}`), await this.sendRequest("node.pair.approve", { requestId: t.requestId }), !0) : !1;
59
+ } catch (t) {
60
+ return e().error(`${a} node pairing auto approve failed, nodeId: ${n}, error: ${String(t)}`), !1;
61
+ }
62
+ }
52
63
  };
53
64
  //#endregion
54
- export { i as default };
65
+ export { o as default };
@@ -1,17 +1,18 @@
1
1
  import { useClawLogger as e } from "../utils/logger.mjs";
2
- import { loadOrCreateDeviceIdentity as t } from "../modules/device/identity.mjs";
3
- import { buildDeviceAuthCredential as n } from "../modules/device/credential-builder.mjs";
4
- import { GatewayClient as r } from "./client.mjs";
5
- import { ErrorCodes as i, GATEWAY_CLIENT_IDS as a, GATEWAY_CLIENT_MODES as o, WebSocketClientError as s } from "./types/client.mjs";
6
- import { randomUUID as c } from "node:crypto";
2
+ import { getProtocolVersion as t } from "../utils/version.mjs";
3
+ import { loadOrCreateDeviceIdentity as n } from "../modules/device/identity.mjs";
4
+ import { buildDeviceAuthCredential as r } from "../modules/device/credential-builder.mjs";
5
+ import { GatewayClient as i } from "./client.mjs";
6
+ import { ErrorCodes as a, GATEWAY_CLIENT_IDS as o, GATEWAY_CLIENT_MODES as s, WebSocketClientError as c } from "./types/client.mjs";
7
+ import { randomUUID as l } from "node:crypto";
7
8
  //#region src/gateway-client/protocol-client.ts
8
- var l = {
9
+ var u = {
9
10
  role: "operator",
10
11
  scopes: [],
11
- clientId: a.CLI,
12
+ clientId: o.CLI,
12
13
  displayName: "Protocol Client",
13
- clientMode: o.CLI
14
- }, u = 3e4, d = "1.0.0", f = "server", p = 2, m = 1e3, h = class extends r {
14
+ clientMode: s.CLI
15
+ }, d = 3e4, f = "1.0.0", p = "server", m = 2, h = 1e3, g = class extends i {
15
16
  protocolOpts;
16
17
  config;
17
18
  pendingRequests = /* @__PURE__ */ new Map();
@@ -27,7 +28,7 @@ var l = {
27
28
  isReconnecting = !1;
28
29
  constructor(e = {}, t = {}) {
29
30
  super(e), this.protocolOpts = e, this.config = {
30
- ...l,
31
+ ...u,
31
32
  ...t
32
33
  }, this.debug = process.env.DEBUG_GATEWAY === "true";
33
34
  }
@@ -67,15 +68,15 @@ var l = {
67
68
  if (t) if (this.logDebug("response", e), this.pendingRequests.delete(e.id), this.clearTimer(e.id), e.ok) t.resolve(e.payload);
68
69
  else {
69
70
  let n = e.error || {
70
- code: i.UNKNOWN,
71
+ code: a.UNKNOWN,
71
72
  message: "Unknown error"
72
73
  };
73
- t.reject(new s(this.toErrorCode(n.code), n.message, n.details, n.retryable));
74
+ t.reject(new c(this.toErrorCode(n.code), n.message, n.details, n.retryable));
74
75
  }
75
76
  }
76
77
  async sendConnect() {
77
- let e = this.config.clientMode ?? o.CLI, r = await t(), i = this.connectNonce ? n({
78
- deviceIdentity: r,
78
+ let e = this.config.clientMode ?? s.CLI, i = await n(), a = this.connectNonce ? r({
79
+ deviceIdentity: i,
79
80
  clientName: this.config.clientId,
80
81
  clientMode: e,
81
82
  role: this.config.role,
@@ -83,16 +84,16 @@ var l = {
83
84
  authToken: this.protocolOpts.token,
84
85
  nonce: this.connectNonce,
85
86
  platform: process.platform,
86
- deviceFamily: f
87
- }) : void 0, a = {
88
- minProtocol: 3,
89
- maxProtocol: 3,
87
+ deviceFamily: p
88
+ }) : void 0, o = {
89
+ minProtocol: t(),
90
+ maxProtocol: t(),
90
91
  client: {
91
92
  id: this.config.clientId,
92
93
  displayName: this.config.displayName,
93
- version: d,
94
+ version: f,
94
95
  platform: process.platform,
95
- deviceFamily: f,
96
+ deviceFamily: p,
96
97
  mode: e
97
98
  },
98
99
  role: this.config.role,
@@ -101,21 +102,21 @@ var l = {
101
102
  token: this.protocolOpts.token,
102
103
  password: this.protocolOpts.password
103
104
  },
104
- device: i
105
+ device: a
105
106
  };
106
- this.sendRequest("connect", a).then((e) => {
107
+ this.sendRequest("connect", o).then((e) => {
107
108
  this.helloOk = e, this.connected = !0, this.authenticated = !0, this.protocolOpts.onAuthenticated?.();
108
109
  }).catch((e) => {
109
- this.authenticated = !1, e instanceof s ? this.protocolOpts.onClose?.(`auth failed: [${e.code}] ${e.message}`) : this.protocolOpts.onClose?.(`auth failed: ${e.message}`);
110
+ this.authenticated = !1, e instanceof c ? this.protocolOpts.onClose?.(`auth failed: [${e.code}] ${e.message}`) : this.protocolOpts.onClose?.(`auth failed: ${e.message}`);
110
111
  });
111
112
  }
112
113
  async sendRequest(e, t) {
113
- let n = c();
114
+ let n = l();
114
115
  return this.logDebug("request", {
115
116
  id: n,
116
117
  method: e,
117
118
  params: t
118
- }), new Promise((r, a) => {
119
+ }), new Promise((r, i) => {
119
120
  let o = {
120
121
  type: "req",
121
122
  id: n,
@@ -124,22 +125,22 @@ var l = {
124
125
  };
125
126
  this.pendingRequests.set(n, {
126
127
  resolve: r,
127
- reject: a
128
+ reject: i
128
129
  });
129
130
  try {
130
131
  this.send(JSON.stringify(o));
131
132
  } catch (e) {
132
- this.pendingRequests.delete(n), a(new s(i.CONNECTION_FAILED, `WebSocket is not connected, ${JSON.stringify(e)}`));
133
+ this.pendingRequests.delete(n), i(new c(a.CONNECTION_FAILED, `WebSocket is not connected, ${JSON.stringify(e)}`));
133
134
  return;
134
135
  }
135
- let c = setTimeout(() => {
136
+ let s = setTimeout(() => {
136
137
  if (this.pendingRequests.has(n)) {
137
138
  this.pendingRequests.delete(n);
138
139
  let t = this.pendingTimers.get(n);
139
- t && clearTimeout(t), this.pendingTimers.delete(n), a(new s(i.TIMEOUT, `Request timeout: ${e}`));
140
+ t && clearTimeout(t), this.pendingTimers.delete(n), i(new c(a.TIMEOUT, `Request timeout: ${e}`));
140
141
  }
141
- }, u);
142
- this.pendingTimers.set(n, c);
142
+ }, d);
143
+ this.pendingTimers.set(n, s);
143
144
  });
144
145
  }
145
146
  isAuthenticated() {
@@ -149,7 +150,7 @@ var l = {
149
150
  return this.connected;
150
151
  }
151
152
  toErrorCode(e) {
152
- return Object.values(i).includes(e) ? e : i.UNKNOWN;
153
+ return Object.values(a).includes(e) ? e : a.UNKNOWN;
153
154
  }
154
155
  clearTimer(e) {
155
156
  let t = this.pendingTimers.get(e);
@@ -170,15 +171,15 @@ var l = {
170
171
  }
171
172
  scheduleReconnect() {
172
173
  if (!(this.closed || this.isReconnecting)) {
173
- if (this.reconnectAttempts >= p) {
174
- e().error(`[protocol-gateway] max reconnect attempts (${p}) reached, giving up`), this.protocolOpts.onReconnectFailed?.();
174
+ if (this.reconnectAttempts >= m) {
175
+ e().error(`[protocol-gateway] max reconnect attempts (${m}) reached, giving up`), this.protocolOpts.onReconnectFailed?.();
175
176
  return;
176
177
  }
177
- this.reconnectAttempts++, this.isReconnecting = !0, e().info(`[protocol-gateway] attempting to reconnect (attempt ${this.reconnectAttempts}/${p})`), this.reconnectTimer = setTimeout(() => {
178
+ this.reconnectAttempts++, this.isReconnecting = !0, e().info(`[protocol-gateway] attempting to reconnect (attempt ${this.reconnectAttempts}/${m})`), this.reconnectTimer = setTimeout(() => {
178
179
  this.isReconnecting = !1, this.closed || super.connect();
179
- }, m);
180
+ }, h);
180
181
  }
181
182
  }
182
183
  };
183
184
  //#endregion
184
- export { h as ProtocolGatewayClient };
185
+ export { g as ProtocolGatewayClient };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { setYoyoRuntime as e } from "./runtime.mjs";
2
- import { setClawLogger as t } from "./utils/logger.mjs";
1
+ import { setClawLogger as e } from "./utils/logger.mjs";
2
+ import { setYoyoRuntime as t } from "./runtime.mjs";
3
3
  import { registerCommands as n } from "./commands/index.mjs";
4
4
  import { registerHooks as r } from "./hooks/index.mjs";
5
5
  import { YoyoPluginConfigSchema as i } from "./schemas.mjs";
@@ -12,7 +12,7 @@ var o = {
12
12
  description: "OpenClaw Honor Yoyo connection plugin",
13
13
  configSchema: i,
14
14
  register(i) {
15
- e(i.runtime), t(i.logger), i.registerService(a(i)), r(i), n(i);
15
+ t(i.runtime), e(i.logger), i.registerService(a(i)), r(i), n(i);
16
16
  }
17
17
  };
18
18
  //#endregion
@@ -1,25 +1,34 @@
1
- import { isBetaVersion as e } from "../../utils/version.mjs";
2
- import { getYoyoRuntime as t } from "../../runtime.mjs";
3
- import { areStringArraysEqual as n } from "../../utils/array.mjs";
4
- import { getEnvFromProcessEnv as r } from "../../utils/env.mjs";
5
- import { wrapError as i } from "../../utils/error.mjs";
6
- import { useClawLogger as a } from "../../utils/logger.mjs";
7
- import { detectProvidersToRename as o, updateProviderReferences as s } from "./provider.mjs";
8
- import { STATE_FLAG as c, hasPersistedStateFlag as l, markPersistedStateFlag as u } from "./state-flags.mjs";
1
+ import { areStringArraysEqual as e } from "../../utils/array.mjs";
2
+ import { getEnvFromProcessEnv as t } from "../../utils/env.mjs";
3
+ import { wrapError as n } from "../../utils/error.mjs";
4
+ import { useClawLogger as r } from "../../utils/logger.mjs";
5
+ import { detectProvidersToRename as i, updateProviderReferences as a } from "./provider.mjs";
6
+ import { STATE_FLAG as o, hasPersistedStateFlag as s, markPersistedStateFlag as c } from "./state-flags.mjs";
7
+ import { getYoyoRuntime as l } from "../../runtime.mjs";
8
+ import { isBetaVersion as u } from "../../utils/version.mjs";
9
9
  //#region src/modules/configs/config-manager.ts
10
10
  var d = "yoyo", f = /* @__PURE__ */ "alarm.create,alarm.delete,alarm.disable,alarm.enable,alarm.query,alarm.update,app.close,app.open,call.phone,call.search,capture-screenshot,contact.search,file-upload,hotspot,local-search,message.search,message.send,mobile-data,no-disturb,quiet-mode,ringing-mode,schedule.create,schedule.delete,schedule.search,schedule.update,screen-record,vibration-mode,volume.operate,wlan,bluetooth,location-service,nfc,usb-shared-network,eyecomfort,status-bar-show,brightness,autoscreen-onnotice,dark-mode,device-operation,camera,app.uninstall,audio-record,battery,gui.create,gui.pause,gui.terminate,mcp.tool.call,task_result_query".split(","), p = class {
11
11
  loadConfig() {
12
12
  try {
13
- return t().config.loadConfig();
13
+ let e = l().config, t = e.current;
14
+ return typeof t == "function" ? structuredClone(t()) : structuredClone(e.loadConfig());
14
15
  } catch (e) {
15
- throw i(e, "Failed to load config");
16
+ throw n(e, "Failed to load config");
16
17
  }
17
18
  }
18
19
  async saveConfig(e) {
19
20
  try {
20
- await t().config.writeConfigFile(e);
21
+ let t = l().config, n = t.replaceConfigFile;
22
+ if (typeof n == "function") {
23
+ await n({
24
+ nextConfig: e,
25
+ afterWrite: { mode: "auto" }
26
+ });
27
+ return;
28
+ }
29
+ await t.writeConfigFile(e);
21
30
  } catch (e) {
22
- throw i(e, "Failed to save config");
31
+ throw n(e, "Failed to save config");
23
32
  }
24
33
  }
25
34
  getGatewayAuthConfig() {
@@ -53,14 +62,14 @@ var d = "yoyo", f = /* @__PURE__ */ "alarm.create,alarm.delete,alarm.disable,ala
53
62
  }
54
63
  getEnvInfo() {
55
64
  try {
56
- let e = this.loadConfig().plugins?.entries?.[d]?.config, t = e?.envInfo;
57
- if (t?.env) return t;
58
- let n = e?.env;
59
- if (n) return {
60
- env: n,
65
+ let e = this.loadConfig().plugins?.entries?.[d]?.config, n = e?.envInfo;
66
+ if (n?.env) return n;
67
+ let r = e?.env;
68
+ if (r) return {
69
+ env: r,
61
70
  source: "manual"
62
71
  };
63
- let i = r();
72
+ let i = t();
64
73
  return i ? {
65
74
  env: i,
66
75
  source: "env"
@@ -115,7 +124,7 @@ var d = "yoyo", f = /* @__PURE__ */ "alarm.create,alarm.delete,alarm.disable,ala
115
124
  };
116
125
  await this.saveConfig(r);
117
126
  } catch (e) {
118
- throw i(e, "Failed to update device config");
127
+ throw n(e, "Failed to update device config");
119
128
  }
120
129
  }
121
130
  async updateEnv(e) {
@@ -143,7 +152,7 @@ var d = "yoyo", f = /* @__PURE__ */ "alarm.create,alarm.delete,alarm.disable,ala
143
152
  };
144
153
  await this.saveConfig(n);
145
154
  } catch (e) {
146
- throw i(e, "Failed to update env config");
155
+ throw n(e, "Failed to update env config");
147
156
  }
148
157
  }
149
158
  async resetEnv() {
@@ -172,7 +181,7 @@ var d = "yoyo", f = /* @__PURE__ */ "alarm.create,alarm.delete,alarm.disable,ala
172
181
  };
173
182
  await this.saveConfig(n);
174
183
  } catch (e) {
175
- throw i(e, "Failed to reset env config");
184
+ throw n(e, "Failed to reset env config");
176
185
  }
177
186
  }
178
187
  async updateGrayTag(e) {
@@ -196,7 +205,7 @@ var d = "yoyo", f = /* @__PURE__ */ "alarm.create,alarm.delete,alarm.disable,ala
196
205
  };
197
206
  await this.saveConfig(n);
198
207
  } catch (e) {
199
- throw i(e, "Failed to update gray tag config");
208
+ throw n(e, "Failed to update gray tag config");
200
209
  }
201
210
  }
202
211
  async updateUserConfig(e) {
@@ -220,7 +229,7 @@ var d = "yoyo", f = /* @__PURE__ */ "alarm.create,alarm.delete,alarm.disable,ala
220
229
  };
221
230
  await this.saveConfig(n);
222
231
  } catch (e) {
223
- throw i(e, "Failed to update user config");
232
+ throw n(e, "Failed to update user config");
224
233
  }
225
234
  }
226
235
  async clearUserConfig() {
@@ -243,38 +252,38 @@ var d = "yoyo", f = /* @__PURE__ */ "alarm.create,alarm.delete,alarm.disable,ala
243
252
  };
244
253
  await this.saveConfig(t);
245
254
  } catch (e) {
246
- throw i(e, "Failed to clear user config");
255
+ throw n(e, "Failed to clear user config");
247
256
  }
248
257
  }
249
- async initializePluginConfig(t) {
258
+ async initializePluginConfig(l) {
250
259
  try {
251
- let i = this.loadConfig(), d = i.skills || {}, p = d.load || {}, m = p.watch === !0, h = !m || await l(c.DISABLE_SKILLS_LOAD_WATCH_MIGRATION_DONE), g = i.plugins?.allow || [], _ = !g.includes(t), v = g.includes(t) ? g : [...g, t], y = i.gateway?.nodes?.allowCommands || [], b = Array.from(new Set([...y, ...f])), x = !n(y, b), S = m && !h, C = i.plugins?.entries?.[t]?.config?.envInfo, w = i.plugins?.entries?.[t]?.config?.env, T = !!(C?.env || w), E = r(), D = !!C?.env && C.source === "env", O = !C?.env && !!w || D && E && C.env !== E, k = !T || O, A = {
252
- env: E || w || (e() ? "test" : "production"),
260
+ let n = this.loadConfig(), d = n.skills || {}, p = d.load || {}, m = p.watch === !0, h = !m || await s(o.DISABLE_SKILLS_LOAD_WATCH_MIGRATION_DONE), g = n.plugins?.allow || [], _ = !g.includes(l), v = g.includes(l) ? g : [...g, l], y = n.gateway?.nodes?.allowCommands || [], b = Array.from(new Set([...y, ...f])), x = !e(y, b), S = m && !h, C = n.plugins?.entries?.[l]?.config?.envInfo, w = n.plugins?.entries?.[l]?.config?.env, T = !!(C?.env || w), E = t(), D = !!C?.env && C.source === "env", O = !C?.env && !!w || D && E && C.env !== E, k = !T || O, A = {
261
+ env: E || w || (u() ? "test" : "production"),
253
262
  source: "env"
254
- }, j = i.plugins?.entries?.[t]?.config || {}, M = k ? {
263
+ }, j = n.plugins?.entries?.[l]?.config || {}, M = k ? {
255
264
  ...j,
256
265
  envInfo: A,
257
266
  env: void 0
258
- } : j, N = i.plugins?.entries?.[t]?.enabled !== !0, P = o(i), F = Object.keys(P).length > 0;
259
- if (F && a().info(`[claw-configs] Found ${Object.keys(P).length} providers to rename: ${Object.entries(P).map(([e, t]) => `${e} -> ${t}`).join(", ")}`), !_ && !x && !S && !k && !N && !F) return;
267
+ } : j, N = n.plugins?.entries?.[l]?.enabled !== !0, P = i(n), F = Object.keys(P).length > 0;
268
+ if (F && r().info(`[claw-configs] Found ${Object.keys(P).length} providers to rename: ${Object.entries(P).map(([e, t]) => `${e} -> ${t}`).join(", ")}`), !_ && !x && !S && !k && !N && !F) return;
260
269
  let I = {
261
- ...i,
270
+ ...n,
262
271
  plugins: {
263
- ...i.plugins,
272
+ ...n.plugins,
264
273
  allow: v,
265
274
  entries: {
266
- ...i.plugins?.entries,
267
- [t]: {
268
- ...i.plugins?.entries?.[t],
275
+ ...n.plugins?.entries,
276
+ [l]: {
277
+ ...n.plugins?.entries?.[l],
269
278
  enabled: !0,
270
279
  config: M
271
280
  }
272
281
  }
273
282
  },
274
283
  gateway: {
275
- ...i.gateway,
284
+ ...n.gateway,
276
285
  nodes: {
277
- ...i.gateway?.nodes,
286
+ ...n.gateway?.nodes,
278
287
  allowCommands: b
279
288
  }
280
289
  }
@@ -288,9 +297,9 @@ var d = "yoyo", f = /* @__PURE__ */ "alarm.create,alarm.delete,alarm.disable,ala
288
297
  watch: !1
289
298
  }
290
299
  }
291
- }, a().info("[claw-configs] Disabled skills.load.watch for yoyo migration")), F && (I = s(I, P), a().info("[claw-configs] Provider renaming completed")), await this.saveConfig(I), S && await u(c.DISABLE_SKILLS_LOAD_WATCH_MIGRATION_DONE);
300
+ }, r().info("[claw-configs] Disabled skills.load.watch for yoyo migration")), F && (I = a(I, P), r().info("[claw-configs] Provider renaming completed")), await this.saveConfig(I), S && await c(o.DISABLE_SKILLS_LOAD_WATCH_MIGRATION_DONE);
292
301
  } catch (e) {
293
- throw i(e, "failed to initialize plugin config");
302
+ throw n(e, "failed to initialize plugin config");
294
303
  }
295
304
  }
296
305
  }, m = null;
@@ -4,70 +4,68 @@ import { safeReadFile as n, safeWriteFile as r } from "../../utils/fs-safe.mjs";
4
4
  import { resolveEffectiveHomeDir as i } from "../../utils/home-dir.mjs";
5
5
  import a from "node:path";
6
6
  //#region src/modules/configs/identity-persist.ts
7
- var o = /* @__PURE__ */ function(e) {
8
- return e[e.LEGACY = 1] = "LEGACY", e[e.NEW = 2] = "NEW", e;
9
- }({}), s = ".openclaw", c = "yoyo", l = "identity.json", u = 6e4;
10
- function d() {
11
- return a.join(s, c, l);
7
+ var o = ".openclaw", s = "yoyo", c = "identity.json", l = 6e4;
8
+ function u() {
9
+ return a.join(o, s, c);
12
10
  }
13
- async function f(t) {
14
- let r = d();
11
+ async function d(t) {
12
+ let r = u();
15
13
  try {
16
14
  let e = (await n({
17
15
  rootDir: t,
18
16
  relativePath: r,
19
17
  maxBytes: 10 * 1024
20
18
  })).buffer.toString("utf8"), i = JSON.parse(e);
21
- return typeof i != "object" || !i ? v() : {
22
- ...v(),
19
+ return typeof i != "object" || !i ? _() : {
20
+ ..._(),
23
21
  ...i
24
22
  };
25
23
  } catch (t) {
26
24
  return e(t, "[yoyo-identity] failed to read identity"), null;
27
25
  }
28
26
  }
29
- async function p() {
27
+ async function f() {
30
28
  let e = i();
31
- return e ? await f(e) || null : (t().warn("[yoyo-identity] failed to find home dir"), null);
29
+ return e ? await d(e) || null : (t().warn("[yoyo-identity] failed to find home dir"), null);
32
30
  }
33
- async function m(e) {
31
+ async function p(e) {
34
32
  let n = i();
35
33
  if (!n) return t().warn("[yoyo-identity] failed to find home dir"), null;
36
- let a = await f(n), s = {
34
+ let a = await d(n), o = {
37
35
  ...a,
38
- version: a?.version || o.NEW
36
+ version: a?.version || 2
39
37
  };
40
- return e.legacyDeviceId && (s.legacyDeviceId = e.legacyDeviceId), e.deviceId && (s.deviceId = e.deviceId, s.publicKeyPem = e.publicKeyPem, s.privateKeyPem = e.privateKeyPem, s.createdAtMs = e.createdAtMs), e.version && (s.version = e.version), "gatewayAuthMd5" in e && (s.gatewayAuthMd5 = e.gatewayAuthMd5), "pluginVersionCode" in e && (s.pluginVersionCode = e.pluginVersionCode), "authorizationCache" in e && (s.authorizationCache = e.authorizationCache), await r({
38
+ return e.legacyDeviceId && (o.legacyDeviceId = e.legacyDeviceId), e.deviceId && (o.deviceId = e.deviceId, o.publicKeyPem = e.publicKeyPem, o.privateKeyPem = e.privateKeyPem, o.createdAtMs = e.createdAtMs), e.version && (o.version = e.version), "gatewayAuthMd5" in e && (o.gatewayAuthMd5 = e.gatewayAuthMd5), "pluginVersionCode" in e && (o.pluginVersionCode = e.pluginVersionCode), "authorizationCache" in e && (o.authorizationCache = e.authorizationCache), await r({
41
39
  rootDir: n,
42
- relativePath: d(),
43
- data: JSON.stringify(s, null, 2),
40
+ relativePath: u(),
41
+ data: JSON.stringify(o, null, 2),
44
42
  encoding: "utf8",
45
43
  mkdir: !0
46
- }), s;
44
+ }), o;
47
45
  }
48
- function h(e) {
46
+ function m(e) {
49
47
  let t = typeof e == "number" ? e : typeof e == "string" && e.trim() ? Number(e) : 0;
50
- return !Number.isFinite(t) || t < u ? 0 : Math.floor(t);
48
+ return !Number.isFinite(t) || t < l ? 0 : Math.floor(t);
51
49
  }
52
- async function g(e, t, n = Date.now()) {
53
- let r = await m({ authorizationCache: {
50
+ async function h(e, t, n = Date.now()) {
51
+ let r = await p({ authorizationCache: {
54
52
  jwtToken: e,
55
53
  receivedAtMs: n,
56
- expireMs: h(t)
54
+ expireMs: m(t)
57
55
  } });
58
56
  if (!r) throw Error("failed to write authorization cache");
59
57
  return r;
60
58
  }
61
- async function _() {
62
- let e = await p(), t = e?.authorizationCache;
63
- return t?.jwtToken ? m({ authorizationCache: {
59
+ async function g() {
60
+ let e = await f(), t = e?.authorizationCache;
61
+ return t?.jwtToken ? p({ authorizationCache: {
64
62
  jwtToken: void 0,
65
63
  receivedAtMs: t.receivedAtMs,
66
- expireMs: h(t.expireMs)
64
+ expireMs: m(t.expireMs)
67
65
  } }) : e;
68
66
  }
69
- function v() {
70
- return { version: o.NEW };
67
+ function _() {
68
+ return { version: 2 };
71
69
  }
72
70
  //#endregion
73
- export { o as IdentityVersion, g as cacheAuthorizationToken, _ as clearCachedAuthorizationToken, p as getPersistedIdentity, h as parseAuthorizationExpireMs, m as updatePersistedIdentity };
71
+ export { h as cacheAuthorizationToken, g as clearCachedAuthorizationToken, f as getPersistedIdentity, m as parseAuthorizationExpireMs, p as updatePersistedIdentity };
@@ -1,5 +1,5 @@
1
1
  import e from "os";
2
- import * as t from "winreg";
2
+ import t from "winreg";
3
3
  //#region src/modules/device/providers/windows.ts
4
4
  function n(e, n, r) {
5
5
  return new Promise((i) => {
@@ -1,6 +1,6 @@
1
- import { getYoyoPluginVersionCode as e } from "../../utils/version.mjs";
2
- import { useClawLogger as t } from "../../utils/logger.mjs";
3
- import { getConfigManager as n } from "../configs/config-manager.mjs";
1
+ import { useClawLogger as e } from "../../utils/logger.mjs";
2
+ import { getConfigManager as t } from "../configs/config-manager.mjs";
3
+ import { getYoyoPluginVersionCode as n } from "../../utils/version.mjs";
4
4
  import { isOKResponse as r } from "../../apis/helpers.mjs";
5
5
  import { createClawCloudClient as i } from "../../apis/claw-cloud.mjs";
6
6
  import { getPersistedIdentity as a, updatePersistedIdentity as o } from "../configs/identity-persist.mjs";
@@ -9,28 +9,28 @@ import "../../apis/index.mjs";
9
9
  import { formatHashForLog as s } from "../../utils/hash.mjs";
10
10
  import { createGatewayAuthMd5 as c, isSameGatewayAuthMd5 as l } from "./gateway-auth.mjs";
11
11
  //#region src/modules/device/registry.ts
12
- async function u(t, a) {
13
- if (!t || !a) throw Error("设备信息或用户信息缺失");
14
- let o = n().getGatewayAuthConfig(), s = c(o), l = e(), u = await i().registerDevice(t, a, o);
12
+ async function u(e, a) {
13
+ if (!e || !a) throw Error("设备信息或用户信息缺失");
14
+ let o = t().getGatewayAuthConfig(), s = c(o), l = n(), u = await i().registerDevice(e, a, o);
15
15
  if (!r(u)) throw Error(`注册失败:${u.data?.cnMessage}`);
16
16
  await f(s, l);
17
17
  }
18
18
  async function d(r, i) {
19
- let o = c(n().getGatewayAuthConfig()), d = e(), f = await a(), p = f?.gatewayAuthMd5, m = f?.pluginVersionCode, h = t();
19
+ let o = c(t().getGatewayAuthConfig()), d = n(), f = await a(), p = f?.gatewayAuthMd5, m = f?.pluginVersionCode, h = e();
20
20
  if (h.info(`[yoyoclaw-registry] checking registration state: gatewayAuth current=${s(o)}, persisted=${s(p)}; pluginVersionCode current=${d}, persisted=${m ?? "none"}`), l(p, o) && m === d) {
21
21
  h.info("[yoyoclaw-registry] registration state unchanged, skipping device registration");
22
22
  return;
23
23
  }
24
24
  h.info("[yoyoclaw-registry] registration state changed, registering device"), await u(r, i), h.info(`[yoyoclaw-registry] device registration succeeded, pluginVersionCode=${d}`);
25
25
  }
26
- async function f(e, n) {
26
+ async function f(t, n) {
27
27
  try {
28
28
  await o({
29
- gatewayAuthMd5: e,
29
+ gatewayAuthMd5: t,
30
30
  pluginVersionCode: n
31
- }), t().info("[yoyoclaw-registry] registration state persisted after device registration");
32
- } catch (e) {
33
- t().warn(`[yoyoclaw-registry] failed to persist registration state: ${String(e)}`);
31
+ }), e().info("[yoyoclaw-registry] registration state persisted after device registration");
32
+ } catch (t) {
33
+ e().warn(`[yoyoclaw-registry] failed to persist registration state: ${String(t)}`);
34
34
  }
35
35
  }
36
36
  //#endregion
@@ -1,16 +1,16 @@
1
1
  import { findPackageRoot as e } from "./package-json.mjs";
2
2
  import t from "node:path";
3
- import { fileURLToPath as n } from "node:url";
4
- import r from "node:os";
3
+ import n from "node:os";
4
+ import { fileURLToPath as r } from "node:url";
5
5
  //#region src/utils/home-dir.ts
6
6
  function i(e) {
7
7
  return e?.trim() || void 0;
8
8
  }
9
- function a(r = import.meta.url) {
10
- return e(r) ?? t.parse(n(r)).root;
9
+ function a(n = import.meta.url) {
10
+ return e(n) ?? t.parse(r(n)).root;
11
11
  }
12
- function o(e = process.env, n = r.homedir) {
13
- let i = s(e, n);
12
+ function o(e = process.env, r = n.homedir) {
13
+ let i = s(e, r);
14
14
  return i ? t.resolve(i) : void 0;
15
15
  }
16
16
  function s(e, t) {
@@ -1,27 +1,59 @@
1
1
  import { findPackageRoot as e, readPackageJson as t } from "./package-json.mjs";
2
+ import { getYoyoRuntime as n } from "../runtime.mjs";
2
3
  //#region src/utils/version.ts
3
- var n = "@honor-claw/yoyo";
4
- function r() {
5
- let e = o();
4
+ var r = "@honor-claw/yoyo", i = 3;
5
+ function a() {
6
+ try {
7
+ let e = n().version;
8
+ return o(e);
9
+ } catch {
10
+ return i;
11
+ }
12
+ }
13
+ function o(e) {
14
+ let t = s(e);
15
+ return t && c(t, [
16
+ 2026,
17
+ 5,
18
+ 12
19
+ ]) >= 0 ? 4 : i;
20
+ }
21
+ function s(e) {
22
+ if (!e) return null;
23
+ let t = e.split("-", 1)[0].split(".");
24
+ if (t.length === 0) return null;
25
+ let n = t.map((e) => Number.parseInt(e, 10));
26
+ return n.some((e) => !Number.isFinite(e) || e < 0) ? null : n;
27
+ }
28
+ function c(e, t) {
29
+ let n = Math.max(e.length, t.length);
30
+ for (let r = 0; r < n; r += 1) {
31
+ let n = e[r] ?? 0, i = t[r] ?? 0;
32
+ if (n !== i) return n - i;
33
+ }
34
+ return 0;
35
+ }
36
+ function l() {
37
+ let e = f();
6
38
  return e.includes("beta") || e.includes("alpha");
7
39
  }
8
- function i(e) {
40
+ function u(e) {
9
41
  if (!e) return 0;
10
42
  let t = Number.parseInt(e, 10);
11
43
  return Number.isFinite(t) && t >= 0 ? t : 0;
12
44
  }
13
- function a() {
14
- let [e, t, n] = o().split("-", 1)[0].split("."), r = i(e), a = i(t), s = i(n);
15
- return r * 1e6 + a * 1e3 + s;
45
+ function d() {
46
+ let [e, t, n] = f().split("-", 1)[0].split("."), r = u(e), i = u(t), a = u(n);
47
+ return r * 1e6 + i * 1e3 + a;
16
48
  }
17
- function o() {
49
+ function f() {
18
50
  try {
19
- let r = e(import.meta.url, n);
20
- if (!r) return "0.0.0";
21
- let i = t(r)?.version;
51
+ let n = e(import.meta.url, r);
52
+ if (!n) return "0.0.0";
53
+ let i = t(n)?.version;
22
54
  if (typeof i == "string") return i;
23
55
  } catch {}
24
56
  return "0.0.0";
25
57
  }
26
58
  //#endregion
27
- export { a as getYoyoPluginVersionCode, r as isBetaVersion };
59
+ export { a as getProtocolVersion, d as getYoyoPluginVersionCode, l as isBetaVersion };
@@ -1,6 +1,10 @@
1
1
  {
2
2
  "id": "yoyo",
3
3
  "skills": ["./skills"],
4
+ "enabledByDefault": true,
5
+ "activation": {
6
+ "onStartup": true
7
+ },
4
8
  "configSchema": {
5
9
  "type": "object",
6
10
  "additionalProperties": false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@honor-claw/yoyo",
3
- "version": "1.6.1-beta.1",
3
+ "version": "1.6.1-beta.3",
4
4
  "description": "OpenClaw Honor Yoyo connection plugin",
5
5
  "keywords": [
6
6
  "ai",
@@ -26,6 +26,10 @@
26
26
  "scripts": {
27
27
  "build": "vite build",
28
28
  "ci:check": "npx tsc --noEmit && npm run test:coverage",
29
+ "format": "oxfmt",
30
+ "format:fix": "oxfmt --write",
31
+ "lint": "oxlint src/",
32
+ "lint:fix": "oxlint --fix src/",
29
33
  "publish:alpha": "npm run build && node scripts/publish.js --alpha",
30
34
  "publish:beta": "npm run build && node scripts/publish.js",
31
35
  "publish:latest": "npm run build && node scripts/publish.js --release",
@@ -49,6 +53,8 @@
49
53
  "@types/node": "^25.0.10",
50
54
  "@types/ws": "^8.5.13",
51
55
  "@vitest/coverage-v8": "^2.1.8",
56
+ "oxfmt": "^0.55.0",
57
+ "oxlint": "^1.70.0",
52
58
  "typescript": "^6.0.2",
53
59
  "vite": "^8.0.10",
54
60
  "vitest": "^2.1.8"