@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.
- package/dist/apis/http-client.mjs +2 -0
- package/dist/cloud-channel/message-handler.mjs +39 -2
- package/dist/gateway-client/admin-client.mjs +19 -8
- package/dist/gateway-client/protocol-client.mjs +38 -37
- package/dist/index.mjs +3 -3
- package/dist/modules/configs/config-manager.mjs +48 -39
- package/dist/modules/configs/identity-persist.mjs +28 -30
- package/dist/modules/device/providers/windows.mjs +1 -1
- package/dist/modules/device/registry.mjs +12 -12
- package/dist/utils/home-dir.mjs +6 -6
- package/dist/utils/version.mjs +44 -12
- package/openclaw.plugin.json +4 -0
- package/package.json +7 -1
|
@@ -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}`)
|
|
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 };
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { useClawLogger as e } from "../utils/logger.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
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
|
|
9
|
+
var u = {
|
|
9
10
|
role: "operator",
|
|
10
11
|
scopes: [],
|
|
11
|
-
clientId:
|
|
12
|
+
clientId: o.CLI,
|
|
12
13
|
displayName: "Protocol Client",
|
|
13
|
-
clientMode:
|
|
14
|
-
},
|
|
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
|
-
...
|
|
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:
|
|
71
|
+
code: a.UNKNOWN,
|
|
71
72
|
message: "Unknown error"
|
|
72
73
|
};
|
|
73
|
-
t.reject(new
|
|
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 ??
|
|
78
|
-
deviceIdentity:
|
|
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:
|
|
87
|
-
}) : void 0,
|
|
88
|
-
minProtocol:
|
|
89
|
-
maxProtocol:
|
|
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:
|
|
94
|
+
version: f,
|
|
94
95
|
platform: process.platform,
|
|
95
|
-
deviceFamily:
|
|
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:
|
|
105
|
+
device: a
|
|
105
106
|
};
|
|
106
|
-
this.sendRequest("connect",
|
|
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
|
|
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 =
|
|
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,
|
|
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:
|
|
128
|
+
reject: i
|
|
128
129
|
});
|
|
129
130
|
try {
|
|
130
131
|
this.send(JSON.stringify(o));
|
|
131
132
|
} catch (e) {
|
|
132
|
-
this.pendingRequests.delete(n),
|
|
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
|
|
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),
|
|
140
|
+
t && clearTimeout(t), this.pendingTimers.delete(n), i(new c(a.TIMEOUT, `Request timeout: ${e}`));
|
|
140
141
|
}
|
|
141
|
-
},
|
|
142
|
-
this.pendingTimers.set(n,
|
|
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(
|
|
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 >=
|
|
174
|
-
e().error(`[protocol-gateway] max reconnect attempts (${
|
|
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}/${
|
|
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
|
-
},
|
|
180
|
+
}, h);
|
|
180
181
|
}
|
|
181
182
|
}
|
|
182
183
|
};
|
|
183
184
|
//#endregion
|
|
184
|
-
export {
|
|
185
|
+
export { g as ProtocolGatewayClient };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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
|
-
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
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
|
-
|
|
13
|
+
let e = l().config, t = e.current;
|
|
14
|
+
return typeof t == "function" ? structuredClone(t()) : structuredClone(e.loadConfig());
|
|
14
15
|
} catch (e) {
|
|
15
|
-
throw
|
|
16
|
+
throw n(e, "Failed to load config");
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
async saveConfig(e) {
|
|
19
20
|
try {
|
|
20
|
-
|
|
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
|
|
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,
|
|
57
|
-
if (
|
|
58
|
-
let
|
|
59
|
-
if (
|
|
60
|
-
env:
|
|
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 =
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
255
|
+
throw n(e, "Failed to clear user config");
|
|
247
256
|
}
|
|
248
257
|
}
|
|
249
|
-
async initializePluginConfig(
|
|
258
|
+
async initializePluginConfig(l) {
|
|
250
259
|
try {
|
|
251
|
-
let
|
|
252
|
-
env: E || w || (
|
|
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 =
|
|
263
|
+
}, j = n.plugins?.entries?.[l]?.config || {}, M = k ? {
|
|
255
264
|
...j,
|
|
256
265
|
envInfo: A,
|
|
257
266
|
env: void 0
|
|
258
|
-
} : j, N =
|
|
259
|
-
if (F &&
|
|
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
|
-
...
|
|
270
|
+
...n,
|
|
262
271
|
plugins: {
|
|
263
|
-
...
|
|
272
|
+
...n.plugins,
|
|
264
273
|
allow: v,
|
|
265
274
|
entries: {
|
|
266
|
-
...
|
|
267
|
-
[
|
|
268
|
-
...
|
|
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
|
-
...
|
|
284
|
+
...n.gateway,
|
|
276
285
|
nodes: {
|
|
277
|
-
...
|
|
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
|
-
},
|
|
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
|
|
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 =
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
14
|
-
let r =
|
|
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 ?
|
|
22
|
-
...
|
|
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
|
|
27
|
+
async function f() {
|
|
30
28
|
let e = i();
|
|
31
|
-
return e ? await
|
|
29
|
+
return e ? await d(e) || null : (t().warn("[yoyo-identity] failed to find home dir"), null);
|
|
32
30
|
}
|
|
33
|
-
async function
|
|
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
|
|
34
|
+
let a = await d(n), o = {
|
|
37
35
|
...a,
|
|
38
|
-
version: a?.version ||
|
|
36
|
+
version: a?.version || 2
|
|
39
37
|
};
|
|
40
|
-
return e.legacyDeviceId && (
|
|
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:
|
|
43
|
-
data: JSON.stringify(
|
|
40
|
+
relativePath: u(),
|
|
41
|
+
data: JSON.stringify(o, null, 2),
|
|
44
42
|
encoding: "utf8",
|
|
45
43
|
mkdir: !0
|
|
46
|
-
}),
|
|
44
|
+
}), o;
|
|
47
45
|
}
|
|
48
|
-
function
|
|
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 <
|
|
48
|
+
return !Number.isFinite(t) || t < l ? 0 : Math.floor(t);
|
|
51
49
|
}
|
|
52
|
-
async function
|
|
53
|
-
let r = await
|
|
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:
|
|
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
|
|
63
|
-
return t?.jwtToken ?
|
|
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:
|
|
64
|
+
expireMs: m(t.expireMs)
|
|
67
65
|
} }) : e;
|
|
68
66
|
}
|
|
69
|
-
function
|
|
70
|
-
return { version:
|
|
67
|
+
function _() {
|
|
68
|
+
return { version: 2 };
|
|
71
69
|
}
|
|
72
70
|
//#endregion
|
|
73
|
-
export {
|
|
71
|
+
export { h as cacheAuthorizationToken, g as clearCachedAuthorizationToken, f as getPersistedIdentity, m as parseAuthorizationExpireMs, p as updatePersistedIdentity };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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(
|
|
13
|
-
if (!
|
|
14
|
-
let 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(
|
|
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(
|
|
26
|
+
async function f(t, n) {
|
|
27
27
|
try {
|
|
28
28
|
await o({
|
|
29
|
-
gatewayAuthMd5:
|
|
29
|
+
gatewayAuthMd5: t,
|
|
30
30
|
pluginVersionCode: n
|
|
31
|
-
}),
|
|
32
|
-
} catch (
|
|
33
|
-
|
|
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
|
package/dist/utils/home-dir.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { findPackageRoot as e } from "./package-json.mjs";
|
|
2
2
|
import t from "node:path";
|
|
3
|
-
import
|
|
4
|
-
import r from "node:
|
|
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(
|
|
10
|
-
return e(
|
|
9
|
+
function a(n = import.meta.url) {
|
|
10
|
+
return e(n) ?? t.parse(r(n)).root;
|
|
11
11
|
}
|
|
12
|
-
function o(e = process.env,
|
|
13
|
-
let i = s(e,
|
|
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) {
|
package/dist/utils/version.mjs
CHANGED
|
@@ -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
|
|
4
|
-
function
|
|
5
|
-
|
|
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
|
|
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
|
|
14
|
-
let [e, t, n] =
|
|
15
|
-
return r * 1e6 +
|
|
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
|
|
49
|
+
function f() {
|
|
18
50
|
try {
|
|
19
|
-
let
|
|
20
|
-
if (!
|
|
21
|
-
let i = t(
|
|
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,
|
|
59
|
+
export { a as getProtocolVersion, d as getYoyoPluginVersionCode, l as isBetaVersion };
|
package/openclaw.plugin.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@honor-claw/yoyo",
|
|
3
|
-
"version": "1.6.1-beta.
|
|
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"
|