@clawhive/openclaw-plugin 0.2.3 → 0.2.4
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/src/authorization.js +10 -3
- package/dist/src/client.d.ts +8 -1
- package/dist/src/client.js +11 -0
- package/dist/src/deviceCode.d.ts +1 -0
- package/dist/src/deviceCode.js +11 -2
- package/package.json +1 -1
|
@@ -94,7 +94,8 @@ export async function authorizeClawHivePlugin(api, deps = {}) {
|
|
|
94
94
|
const { account, cloudApi } = (deps.createCloudApi ?? createClawHiveCloudApi)(api);
|
|
95
95
|
if (cloudApi.pluginToken) {
|
|
96
96
|
try {
|
|
97
|
-
await cloudApi.registerPluginNode();
|
|
97
|
+
const registration = await cloudApi.registerPluginNode();
|
|
98
|
+
await syncRegistrationIdentity(api, { account, registration });
|
|
98
99
|
api.logger.info("ClawHive is already authorized. Restart the gateway if you are waiting for it to connect.");
|
|
99
100
|
return;
|
|
100
101
|
}
|
|
@@ -118,13 +119,19 @@ export async function authorizeClawHivePlugin(api, deps = {}) {
|
|
|
118
119
|
start,
|
|
119
120
|
logger: api.logger,
|
|
120
121
|
});
|
|
122
|
+
cloudApi.setAuthorizationIdentity({
|
|
123
|
+
pluginToken: approval.plugin_token,
|
|
124
|
+
userId: approval.user_id,
|
|
125
|
+
});
|
|
126
|
+
const registration = await cloudApi.registerPluginNode();
|
|
121
127
|
const latestCfg = api.runtime.config.loadConfig();
|
|
122
128
|
await api.runtime.config.writeConfigFile(writeRegistrationIdentity(latestCfg, {
|
|
123
129
|
anonKey: account.anonKey,
|
|
124
130
|
pluginToken: approval.plugin_token,
|
|
125
|
-
userId:
|
|
131
|
+
userId: registration.user_id,
|
|
132
|
+
pluginNodeId: registration.plugin_node.id,
|
|
126
133
|
}));
|
|
127
|
-
api.logger.info("ClawHive authorization completed. Restart the gateway
|
|
134
|
+
api.logger.info("ClawHive authorization completed and plugin node registered. Restart the gateway if you are waiting for it to connect.");
|
|
128
135
|
}
|
|
129
136
|
catch (error) {
|
|
130
137
|
if (error instanceof DeviceCodeDeniedError) {
|
package/dist/src/client.d.ts
CHANGED
|
@@ -47,6 +47,7 @@ export type PluginNode = {
|
|
|
47
47
|
node_name?: string | null;
|
|
48
48
|
plugin_version?: string | null;
|
|
49
49
|
plugin_status: "online" | "offline" | "degraded";
|
|
50
|
+
runtime_type?: "openclaw" | "hermes";
|
|
50
51
|
last_heartbeat_at?: string | null;
|
|
51
52
|
};
|
|
52
53
|
export type PluginRegisterResult = {
|
|
@@ -77,11 +78,13 @@ export type SyncAgentInput = {
|
|
|
77
78
|
export type SyncedAgent = {
|
|
78
79
|
id: string;
|
|
79
80
|
user_id: string;
|
|
81
|
+
plugin_node_id?: string | null;
|
|
82
|
+
runtime_type: "openclaw" | "hermes";
|
|
83
|
+
runtime_agent_id: string;
|
|
80
84
|
openclaw_agent_id: string;
|
|
81
85
|
name: string;
|
|
82
86
|
description: string | null;
|
|
83
87
|
avatar_url: string | null;
|
|
84
|
-
source_type: string;
|
|
85
88
|
config: Record<string, unknown>;
|
|
86
89
|
created_at: string;
|
|
87
90
|
};
|
|
@@ -179,6 +182,10 @@ export declare class ClawHiveCloudApi {
|
|
|
179
182
|
get baseUrl(): string;
|
|
180
183
|
get userId(): string | null;
|
|
181
184
|
get pluginToken(): string | null;
|
|
185
|
+
setAuthorizationIdentity(identity: {
|
|
186
|
+
pluginToken: string;
|
|
187
|
+
userId: string;
|
|
188
|
+
}): void;
|
|
182
189
|
private requireUserId;
|
|
183
190
|
private requirePluginToken;
|
|
184
191
|
startDeviceCode(opts?: {
|
package/dist/src/client.js
CHANGED
|
@@ -68,6 +68,10 @@ export class ClawHiveCloudApi {
|
|
|
68
68
|
get pluginToken() {
|
|
69
69
|
return this.config.pluginToken ?? null;
|
|
70
70
|
}
|
|
71
|
+
setAuthorizationIdentity(identity) {
|
|
72
|
+
this.config.pluginToken = identity.pluginToken;
|
|
73
|
+
this.config.userId = identity.userId;
|
|
74
|
+
}
|
|
71
75
|
requireUserId() {
|
|
72
76
|
if (!this.config.userId) {
|
|
73
77
|
throw new Error("ClawHiveCloudApi: userId is not set. Call registerPluginNode() before making user-scoped calls.");
|
|
@@ -86,6 +90,7 @@ export class ClawHiveCloudApi {
|
|
|
86
90
|
method: "POST",
|
|
87
91
|
auth: "none",
|
|
88
92
|
body: {
|
|
93
|
+
runtime_type: "openclaw",
|
|
89
94
|
node_name: opts?.nodeName ?? this.config.nodeName ?? "OpenClaw Desktop",
|
|
90
95
|
plugin_version: opts?.pluginVersion ?? this.config.pluginVersion ?? "0.2.0",
|
|
91
96
|
description: opts?.description,
|
|
@@ -128,6 +133,7 @@ export class ClawHiveCloudApi {
|
|
|
128
133
|
plugin_node_id: this.config.pluginNodeId ?? null,
|
|
129
134
|
node_name: this.config.nodeName ?? "OpenClaw Desktop",
|
|
130
135
|
plugin_version: this.config.pluginVersion ?? "0.2.0",
|
|
136
|
+
runtime_type: "openclaw",
|
|
131
137
|
};
|
|
132
138
|
if (this.config.userId) {
|
|
133
139
|
body.user_id = this.config.userId;
|
|
@@ -139,6 +145,7 @@ export class ClawHiveCloudApi {
|
|
|
139
145
|
body,
|
|
140
146
|
});
|
|
141
147
|
this.config.userId = result.user_id;
|
|
148
|
+
this.config.pluginNodeId = result.plugin_node.id;
|
|
142
149
|
return result;
|
|
143
150
|
}
|
|
144
151
|
async createPairingCode(pluginNodeId, ttlSeconds) {
|
|
@@ -172,6 +179,7 @@ export class ClawHiveCloudApi {
|
|
|
172
179
|
auth: "plugin",
|
|
173
180
|
body: {
|
|
174
181
|
plugin_node_id: params.pluginNodeId,
|
|
182
|
+
runtime_type: "openclaw",
|
|
175
183
|
session_id: params.sessionId,
|
|
176
184
|
agent_id: params.agentId,
|
|
177
185
|
user_id: this.requireUserId(),
|
|
@@ -190,7 +198,10 @@ export class ClawHiveCloudApi {
|
|
|
190
198
|
auth: "plugin",
|
|
191
199
|
body: {
|
|
192
200
|
user_id: this.requireUserId(),
|
|
201
|
+
plugin_node_id: this.config.pluginNodeId,
|
|
202
|
+
runtime_type: "openclaw",
|
|
193
203
|
agents: agents.map((agent) => ({
|
|
204
|
+
runtime_agent_id: agent.openclawAgentId,
|
|
194
205
|
openclaw_agent_id: agent.openclawAgentId,
|
|
195
206
|
name: agent.name,
|
|
196
207
|
description: agent.description ?? null,
|
package/dist/src/deviceCode.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export type DeviceCodeAwaitResult = {
|
|
|
7
7
|
user_id: string;
|
|
8
8
|
plugin_token: string;
|
|
9
9
|
};
|
|
10
|
+
export declare function normalizeDeviceCodeUrl(url: string): string;
|
|
10
11
|
export declare function printDeviceCodePrompt(start: DeviceCodeStartResult, logger: DeviceCodeLogger): Promise<void>;
|
|
11
12
|
export declare function awaitDeviceCodeApproval(params: {
|
|
12
13
|
api: ClawHiveCloudApi;
|
package/dist/src/deviceCode.js
CHANGED
|
@@ -5,15 +5,24 @@ async function renderQr(text) {
|
|
|
5
5
|
qrcodeTerminal.generate(text, { small: true }, (qr) => resolve(qr));
|
|
6
6
|
});
|
|
7
7
|
}
|
|
8
|
+
export function normalizeDeviceCodeUrl(url) {
|
|
9
|
+
const parsed = new URL(url);
|
|
10
|
+
if (parsed.hostname === "127.0.0.1") {
|
|
11
|
+
parsed.hostname = "localhost";
|
|
12
|
+
}
|
|
13
|
+
return parsed.toString();
|
|
14
|
+
}
|
|
8
15
|
export async function printDeviceCodePrompt(start, logger) {
|
|
9
|
-
const
|
|
16
|
+
const verificationUri = normalizeDeviceCodeUrl(start.verification_uri);
|
|
17
|
+
const verificationUriComplete = normalizeDeviceCodeUrl(start.verification_uri_complete);
|
|
18
|
+
const qr = await renderQr(verificationUriComplete);
|
|
10
19
|
const expiresInMin = Math.floor(start.expires_in / 60);
|
|
11
20
|
const lines = [
|
|
12
21
|
"",
|
|
13
22
|
"════════════════════════════════════════════════════════════",
|
|
14
23
|
" ClawHive: authorize this OpenClaw install.",
|
|
15
24
|
"",
|
|
16
|
-
` Visit: ${
|
|
25
|
+
` Visit: ${verificationUri}`,
|
|
17
26
|
` Enter the code: ${start.user_code}`,
|
|
18
27
|
"",
|
|
19
28
|
" Or scan this QR to jump straight to the approval page:",
|