echoclaw-relay-agent 0.30.1 → 0.30.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.
- package/dist/ConfigureHandler-YJIM5G2Q.js +210 -0
- package/dist/OpenClawConfig-RAWRUWWW.js +20 -0
- package/dist/{chunk-3UOE3TPO.js → chunk-7VXGWINT.js} +97 -28
- package/dist/chunk-HXUJ67U3.js +85 -0
- package/dist/chunk-S2KWH5JY.js +129 -0
- package/dist/cli.js +2 -2
- package/dist/configure/ConfigureHandler.d.ts +37 -0
- package/dist/configure/ModelVerifier.d.ts +9 -0
- package/dist/gateway/WorkspaceSync.d.ts +17 -12
- package/dist/index.js +58 -1
- package/dist/local/LocalAgent.d.ts +8 -0
- package/package.json +1 -1
- package/dist/ConfigureHandler-NXQ2MDTI.js +0 -342
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fetchAvailableModels,
|
|
3
|
+
verifyModel,
|
|
4
|
+
waitForGateway
|
|
5
|
+
} from "./chunk-HXUJ67U3.js";
|
|
6
|
+
import {
|
|
7
|
+
configureModel,
|
|
8
|
+
detectProvider,
|
|
9
|
+
getGatewayToken,
|
|
10
|
+
hasApiKeyConfigured
|
|
11
|
+
} from "./chunk-S2KWH5JY.js";
|
|
12
|
+
|
|
13
|
+
// src/configure/ConfigureHandler.ts
|
|
14
|
+
import { execFile } from "node:child_process";
|
|
15
|
+
import { promisify } from "node:util";
|
|
16
|
+
var execFileAsync = promisify(execFile);
|
|
17
|
+
var DEFAULT_GATEWAY_PORT = 18789;
|
|
18
|
+
async function findOpenClaw() {
|
|
19
|
+
try {
|
|
20
|
+
const { stdout } = await execFileAsync("which", ["openclaw"]);
|
|
21
|
+
return stdout.trim() || null;
|
|
22
|
+
} catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async function runOpenClaw(args, timeoutMs = 6e4) {
|
|
27
|
+
const openclawBin = await findOpenClaw();
|
|
28
|
+
if (!openclawBin) throw new Error("OpenClaw binary not found");
|
|
29
|
+
return execFileAsync(openclawBin, args, {
|
|
30
|
+
timeout: timeoutMs,
|
|
31
|
+
env: { ...process.env }
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async function checkOpenClawInstalled() {
|
|
35
|
+
try {
|
|
36
|
+
const { stdout } = await runOpenClaw(["--version"], 1e4);
|
|
37
|
+
const version = stdout.trim();
|
|
38
|
+
if (version) return { installed: true, version };
|
|
39
|
+
return { installed: false };
|
|
40
|
+
} catch {
|
|
41
|
+
return { installed: false };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function checkNeedsApiKey() {
|
|
45
|
+
return !await hasApiKeyConfigured();
|
|
46
|
+
}
|
|
47
|
+
async function handleConfigure(request, sendStatus) {
|
|
48
|
+
try {
|
|
49
|
+
sendStatus({
|
|
50
|
+
type: "agent_setup_status",
|
|
51
|
+
state: "configuring",
|
|
52
|
+
detail: "\u6B63\u5728\u68C0\u6D4B\u6A21\u578B\u63D0\u4F9B\u5546..."
|
|
53
|
+
}).catch(() => {
|
|
54
|
+
});
|
|
55
|
+
const providerConfig = detectProvider(request.apiKey, request.provider);
|
|
56
|
+
if (request.baseUrl) {
|
|
57
|
+
providerConfig.baseUrl = request.baseUrl;
|
|
58
|
+
}
|
|
59
|
+
if (request.model) {
|
|
60
|
+
providerConfig.modelId = request.model;
|
|
61
|
+
}
|
|
62
|
+
sendStatus({
|
|
63
|
+
type: "agent_setup_status",
|
|
64
|
+
state: "configuring",
|
|
65
|
+
detail: `\u6B63\u5728\u914D\u7F6E ${providerConfig.provider} \u6A21\u578B...`
|
|
66
|
+
}).catch(() => {
|
|
67
|
+
});
|
|
68
|
+
await configureModel(providerConfig);
|
|
69
|
+
let gatewayToken = await getGatewayToken();
|
|
70
|
+
if (!gatewayToken) {
|
|
71
|
+
sendStatus({
|
|
72
|
+
type: "agent_setup_status",
|
|
73
|
+
state: "configuring",
|
|
74
|
+
detail: "\u6B63\u5728\u751F\u6210 Gateway \u8BA4\u8BC1\u4EE4\u724C..."
|
|
75
|
+
}).catch(() => {
|
|
76
|
+
});
|
|
77
|
+
try {
|
|
78
|
+
await runOpenClaw(["doctor", "--generate-gateway-token", "--non-interactive"], 3e4);
|
|
79
|
+
} catch (err) {
|
|
80
|
+
return {
|
|
81
|
+
type: "agent_setup_status",
|
|
82
|
+
state: "error",
|
|
83
|
+
error: `\u751F\u6210 Gateway Token \u5931\u8D25: ${err.message}`
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
gatewayToken = await getGatewayToken();
|
|
87
|
+
if (!gatewayToken) {
|
|
88
|
+
return {
|
|
89
|
+
type: "agent_setup_status",
|
|
90
|
+
state: "error",
|
|
91
|
+
error: "Gateway Token \u751F\u6210\u540E\u4ECD\u4E0D\u53EF\u7528"
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
sendStatus({
|
|
96
|
+
type: "agent_setup_status",
|
|
97
|
+
state: "configuring",
|
|
98
|
+
detail: "\u6B63\u5728\u542F\u52A8 OpenClaw Gateway..."
|
|
99
|
+
}).catch(() => {
|
|
100
|
+
});
|
|
101
|
+
try {
|
|
102
|
+
await runOpenClaw(["gateway", "install"], 3e4);
|
|
103
|
+
} catch (installErr) {
|
|
104
|
+
sendStatus({
|
|
105
|
+
type: "agent_setup_status",
|
|
106
|
+
state: "configuring",
|
|
107
|
+
detail: `Gateway install: ${installErr.message?.slice(0, 100) ?? "skipped (may already be installed)"}`
|
|
108
|
+
}).catch(() => {
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
await runOpenClaw(["gateway", "start"], 15e3);
|
|
113
|
+
} catch (startErr) {
|
|
114
|
+
sendStatus({
|
|
115
|
+
type: "agent_setup_status",
|
|
116
|
+
state: "configuring",
|
|
117
|
+
detail: `Gateway start: ${startErr.message?.slice(0, 100) ?? "skipped (may already be running)"}`
|
|
118
|
+
}).catch(() => {
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
sendStatus({
|
|
122
|
+
type: "agent_setup_status",
|
|
123
|
+
state: "configuring",
|
|
124
|
+
detail: "\u7B49\u5F85 Gateway \u5C31\u7EEA..."
|
|
125
|
+
}).catch(() => {
|
|
126
|
+
});
|
|
127
|
+
const gatewayReady = await waitForGateway(DEFAULT_GATEWAY_PORT, gatewayToken, 3e4);
|
|
128
|
+
if (!gatewayReady) {
|
|
129
|
+
try {
|
|
130
|
+
await runOpenClaw(["gateway", "status", "--require-rpc"], 1e4);
|
|
131
|
+
} catch {
|
|
132
|
+
return {
|
|
133
|
+
type: "agent_setup_status",
|
|
134
|
+
state: "error",
|
|
135
|
+
error: "Gateway \u542F\u52A8\u8D85\u65F6\uFF0830s\uFF09\uFF0C\u8BF7\u68C0\u67E5 OpenClaw \u5B89\u88C5"
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
sendStatus({
|
|
140
|
+
type: "agent_setup_status",
|
|
141
|
+
state: "configuring",
|
|
142
|
+
detail: "\u6B63\u5728\u9A8C\u8BC1\u6A21\u578B\u8FDE\u63A5..."
|
|
143
|
+
}).catch(() => {
|
|
144
|
+
});
|
|
145
|
+
const verifyResult = await verifyModel(
|
|
146
|
+
DEFAULT_GATEWAY_PORT,
|
|
147
|
+
gatewayToken,
|
|
148
|
+
providerConfig.modelId
|
|
149
|
+
);
|
|
150
|
+
if (!verifyResult.success) {
|
|
151
|
+
return {
|
|
152
|
+
type: "agent_setup_status",
|
|
153
|
+
state: "error",
|
|
154
|
+
error: verifyResult.error ?? "\u6A21\u578B\u9A8C\u8BC1\u5931\u8D25"
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const availableModels = await fetchAvailableModels(DEFAULT_GATEWAY_PORT, gatewayToken);
|
|
158
|
+
return {
|
|
159
|
+
type: "agent_setup_status",
|
|
160
|
+
state: "ready",
|
|
161
|
+
detail: `${providerConfig.provider} \u6A21\u578B\u5DF2\u5C31\u7EEA`,
|
|
162
|
+
gatewayPort: DEFAULT_GATEWAY_PORT,
|
|
163
|
+
activeModel: providerConfig.modelId,
|
|
164
|
+
availableModels: availableModels.length > 0 ? availableModels : void 0
|
|
165
|
+
};
|
|
166
|
+
} catch (err) {
|
|
167
|
+
return {
|
|
168
|
+
type: "agent_setup_status",
|
|
169
|
+
state: "error",
|
|
170
|
+
error: `\u914D\u7F6E\u5931\u8D25: ${err.message}`
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
async function handleQueryModels() {
|
|
175
|
+
try {
|
|
176
|
+
const gatewayToken = await getGatewayToken();
|
|
177
|
+
if (!gatewayToken) {
|
|
178
|
+
return { type: "query_models_result", models: [], error: "Gateway token \u672A\u627E\u5230\uFF0C\u8BF7\u5148\u5B8C\u6210 API Key \u914D\u7F6E" };
|
|
179
|
+
}
|
|
180
|
+
const models = await fetchAvailableModels(DEFAULT_GATEWAY_PORT, gatewayToken);
|
|
181
|
+
const config = await (await import("./OpenClawConfig-RAWRUWWW.js")).readOpenClawConfig();
|
|
182
|
+
const activeModel = config?.agents?.defaults?.model;
|
|
183
|
+
return { type: "query_models_result", models, activeModel };
|
|
184
|
+
} catch (err) {
|
|
185
|
+
return { type: "query_models_result", models: [], error: `\u67E5\u8BE2\u6A21\u578B\u5931\u8D25: ${err.message}` };
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
async function handleSetModel(request) {
|
|
189
|
+
try {
|
|
190
|
+
if (!request.model || typeof request.model !== "string") {
|
|
191
|
+
return { type: "set_model_result", success: false, error: "\u65E0\u6548\u7684\u6A21\u578B ID" };
|
|
192
|
+
}
|
|
193
|
+
const { readOpenClawConfig, writeOpenClawConfig } = await import("./OpenClawConfig-RAWRUWWW.js");
|
|
194
|
+
const config = await readOpenClawConfig();
|
|
195
|
+
if (!config.agents) config.agents = {};
|
|
196
|
+
if (!config.agents.defaults) config.agents.defaults = {};
|
|
197
|
+
config.agents.defaults.model = request.model;
|
|
198
|
+
await writeOpenClawConfig(config);
|
|
199
|
+
return { type: "set_model_result", success: true, activeModel: request.model };
|
|
200
|
+
} catch (err) {
|
|
201
|
+
return { type: "set_model_result", success: false, error: `\u5207\u6362\u6A21\u578B\u5931\u8D25: ${err.message}` };
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
export {
|
|
205
|
+
checkNeedsApiKey,
|
|
206
|
+
checkOpenClawInstalled,
|
|
207
|
+
handleConfigure,
|
|
208
|
+
handleQueryModels,
|
|
209
|
+
handleSetModel
|
|
210
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OPENCLAW_CONFIG_DIR,
|
|
3
|
+
OPENCLAW_CONFIG_PATH,
|
|
4
|
+
configureModel,
|
|
5
|
+
detectProvider,
|
|
6
|
+
getGatewayToken,
|
|
7
|
+
hasApiKeyConfigured,
|
|
8
|
+
readOpenClawConfig,
|
|
9
|
+
writeOpenClawConfig
|
|
10
|
+
} from "./chunk-S2KWH5JY.js";
|
|
11
|
+
export {
|
|
12
|
+
OPENCLAW_CONFIG_DIR,
|
|
13
|
+
OPENCLAW_CONFIG_PATH,
|
|
14
|
+
configureModel,
|
|
15
|
+
detectProvider,
|
|
16
|
+
getGatewayToken,
|
|
17
|
+
hasApiKeyConfigured,
|
|
18
|
+
readOpenClawConfig,
|
|
19
|
+
writeOpenClawConfig
|
|
20
|
+
};
|