@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}`)
|
|
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 {
|
|
2
|
-
import {
|
|
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
|
|
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:
|
|
15
|
+
clientId: t.CLI,
|
|
15
16
|
displayName: "YOYO-Control",
|
|
16
|
-
clientMode:
|
|
17
|
-
},
|
|
17
|
+
clientMode: n.BACKEND
|
|
18
|
+
}, a = "[yoyoclaw-adminGatewayClient]", o = class extends r {
|
|
18
19
|
constructor(e = {}) {
|
|
19
|
-
super(e,
|
|
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 {
|
|
65
|
+
export { o as default };
|