@honor-claw/yoyo 1.6.1-alpha.1 → 1.6.1-alpha.2

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.
@@ -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,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) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@honor-claw/yoyo",
3
- "version": "1.6.1-alpha.1",
3
+ "version": "1.6.1-alpha.2",
4
4
  "description": "OpenClaw Honor Yoyo connection plugin",
5
5
  "keywords": [
6
6
  "ai",