tuxevil-rotator 4.2.2 → 4.4.0
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/CHANGELOG.md +48 -1
- package/README.md +11 -4
- package/package.json +2 -1
- package/plugins/opencode-discovery/capabilities.d.mts +7 -0
- package/plugins/opencode-discovery/capabilities.mjs +54 -0
- package/plugins/opencode-discovery/index.d.mts +2 -1
- package/plugins/opencode-discovery/index.mjs +6 -1
- package/plugins/opencode-discovery/package.json +3 -1
- package/src/access-evidence.ts +153 -0
- package/src/access-probe.ts +85 -0
- package/src/admin-auth.ts +4 -1
- package/src/audio-transcription.ts +32 -6
- package/src/auto-access-shadow.ts +11 -0
- package/src/auto-model-access.ts +185 -0
- package/src/auto-output-health.ts +12 -0
- package/src/auto-routing-evaluation.ts +80 -0
- package/src/auto-routing-quality.ts +308 -0
- package/src/auto-routing.ts +403 -26
- package/src/cli.ts +3 -3
- package/src/compat/model-specs.ts +4 -0
- package/src/compat.ts +253 -37
- package/src/compression/index.ts +6 -6
- package/src/compression/lite.ts +3 -9
- package/src/compression/rtk/index.ts +0 -3
- package/src/config-defaults.ts +7 -0
- package/src/dashboard-app.ts +1 -0
- package/src/dashboard.ts +5 -0
- package/src/db-store.ts +10 -0
- package/src/index.ts +2 -0
- package/src/install-agent.ts +211 -129
- package/src/install-opencode.ts +80 -18
- package/src/model-access-api.ts +74 -0
- package/src/model-access.ts +56 -0
- package/src/ollama-output-gate.ts +18 -0
- package/src/onboarding.ts +1 -1
- package/src/provider-catalog-evidence.ts +26 -0
- package/src/providers/google-antigravity/catalog.ts +14 -6
- package/src/providers/google-antigravity/dynamic-catalog.ts +87 -3
- package/src/providers/google-antigravity/forward.ts +4 -2
- package/src/providers/google-antigravity/quota.ts +7 -0
- package/src/providers/ollama/context-window.ts +13 -0
- package/src/providers/ollama/forward.ts +10 -0
- package/src/providers/ollama/quota.ts +4 -0
- package/src/providers/ollama/translators.ts +19 -2
- package/src/providers/openai-codex/catalog.ts +157 -18
- package/src/providers/openai-codex/compat.ts +5 -1
- package/src/providers/openai-codex/credentials.ts +22 -6
- package/src/providers/openai-codex/index.ts +9 -1
- package/src/providers/openai-codex/quota.ts +19 -6
- package/src/providers/opencode-zen/forward.ts +1 -1
- package/src/providers/opencode-zen/quota.ts +2 -0
- package/src/proxy.ts +113 -5
- package/src/quota-observation.ts +26 -0
- package/src/quota-pools.ts +322 -0
- package/src/rotator.ts +167 -40
- package/src/settings-repository.ts +1 -0
- package/src/types.ts +106 -29
- package/src/usage-limits-auth.ts +24 -0
- package/src/usage-limits.ts +148 -0
- package/src/validators.ts +26 -0
- package/src/web/app.tsx +4 -0
- package/src/web/components/icons.tsx +15 -0
- package/src/web/components/overlays.tsx +4 -0
- package/src/web/components/ui.tsx +9 -9
- package/src/web/lib/audio-recorder.ts +159 -0
- package/src/web/lib/colors.ts +4 -0
- package/src/web/lib/playground-storage.ts +261 -0
- package/src/web/lib/playground.ts +483 -0
- package/src/web/lib/pool-navigation.ts +4 -0
- package/src/web/lib/pools.ts +2 -243
- package/src/web/nav.ts +1 -0
- package/src/web/pages/AccountDetail.tsx +2 -1
- package/src/web/pages/ModelAccess.tsx +88 -0
- package/src/web/pages/Models.tsx +2 -0
- package/src/web/pages/Overview.tsx +26 -9
- package/src/web/pages/Playground.tsx +1692 -0
- package/src/web/pages/Transcription.tsx +562 -0
- package/src/web/state/api.ts +6 -0
- package/src/web/state/playground-client.ts +136 -0
- package/src/web/state/playground.ts +69 -0
- package/src/web/state/router.ts +2 -2
- package/src/web/state/transcription-client.ts +93 -0
- package/src/web/styles/app.css +501 -0
- package/tools/telemetry-receiver/receiver.js +59 -46
package/src/install-agent.ts
CHANGED
|
@@ -4,10 +4,18 @@ import { resolve, dirname } from "node:path";
|
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
|
|
6
6
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
|
-
const OPENCODE_PLUGIN_SOURCE_DIR = resolve(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const OPENCODE_PLUGIN_SOURCE_DIR = resolve(
|
|
8
|
+
__dirname,
|
|
9
|
+
"../plugins/opencode-discovery",
|
|
10
|
+
);
|
|
11
|
+
const OPENCODE_PLUGIN_RUNTIME_FILES = [
|
|
12
|
+
"index.mjs",
|
|
13
|
+
"package.json",
|
|
14
|
+
"capabilities.mjs",
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
export type SupportedAgent =
|
|
18
|
+
"opencode" | "hermes" | "pi" | "codex" | "openclaw";
|
|
11
19
|
|
|
12
20
|
export interface AgentInstallOptions {
|
|
13
21
|
targets?: Array<SupportedAgent | "auto" | "all">;
|
|
@@ -33,21 +41,41 @@ export function buildCompositeInstallerScript(
|
|
|
33
41
|
providerId: string;
|
|
34
42
|
providerName: string;
|
|
35
43
|
apiKey?: string;
|
|
36
|
-
}
|
|
44
|
+
},
|
|
37
45
|
): string {
|
|
38
|
-
if (
|
|
39
|
-
|
|
46
|
+
if (
|
|
47
|
+
!OPENCODE_PLUGIN_RUNTIME_FILES.every((name) => name in opencodePluginFiles)
|
|
48
|
+
) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`opencodePluginFiles must include all of: ${OPENCODE_PLUGIN_RUNTIME_FILES.join(", ")}`,
|
|
51
|
+
);
|
|
40
52
|
}
|
|
41
53
|
|
|
42
54
|
const pluginFileWriteLines = OPENCODE_PLUGIN_RUNTIME_FILES.map((name) => {
|
|
43
|
-
const base64 = Buffer.from(opencodePluginFiles[name], "utf8").toString(
|
|
55
|
+
const base64 = Buffer.from(opencodePluginFiles[name], "utf8").toString(
|
|
56
|
+
"base64",
|
|
57
|
+
);
|
|
44
58
|
return `echo "${base64}" | base64 -d > "$OPENCODE_DIR/plugins/opencode-discovery/${name}"`;
|
|
45
59
|
}).join("\n");
|
|
46
60
|
const rotatorUrl = options.rotatorUrl.replace(/\/+$/, "");
|
|
47
61
|
const providerId = options.providerId || "tuxevil-rotator";
|
|
48
62
|
const providerName = options.providerName || "Tuxevil Rotator";
|
|
49
63
|
const apiKey = options.apiKey || "no-key";
|
|
50
|
-
const targets =
|
|
64
|
+
const targets =
|
|
65
|
+
options.targets && options.targets.length > 0 ? options.targets : ["auto"];
|
|
66
|
+
const allowedTargets = new Set([
|
|
67
|
+
"opencode",
|
|
68
|
+
"hermes",
|
|
69
|
+
"pi",
|
|
70
|
+
"codex",
|
|
71
|
+
"openclaw",
|
|
72
|
+
"auto",
|
|
73
|
+
"all",
|
|
74
|
+
]);
|
|
75
|
+
if (targets.some((target) => !allowedTargets.has(target)))
|
|
76
|
+
throw new Error(
|
|
77
|
+
"Unknown agent target. Use opencode, hermes, openclaw, pi, codex, auto or all.",
|
|
78
|
+
);
|
|
51
79
|
const shouldAuto = targets.includes("auto") || targets.includes("all");
|
|
52
80
|
|
|
53
81
|
return `#!/usr/bin/env bash
|
|
@@ -64,6 +92,20 @@ echo "==> Rotator URL: $ROTATOR_URL"
|
|
|
64
92
|
echo "==> Provider ID: $PROVIDER_ID"
|
|
65
93
|
echo "=========================================================="
|
|
66
94
|
|
|
95
|
+
# One catalog snapshot and shared capability mapper for every selected agent.
|
|
96
|
+
AGENT_WORK_DIR=$(mktemp -d)
|
|
97
|
+
trap 'rm -rf "$AGENT_WORK_DIR"' EXIT
|
|
98
|
+
printf %s "${Buffer.from(opencodePluginFiles["capabilities.mjs"], "utf8").toString("base64")}" | base64 -d > "$AGENT_WORK_DIR/capabilities.mjs"
|
|
99
|
+
node --input-type=module -e '
|
|
100
|
+
import fs from "node:fs";
|
|
101
|
+
import { pathToFileURL } from "node:url";
|
|
102
|
+
const { fetchModels } = await import(pathToFileURL(process.argv[1]).href);
|
|
103
|
+
let models = [];
|
|
104
|
+
try { models = await fetchModels(process.argv[2], process.argv[3]); }
|
|
105
|
+
catch { console.warn("==> Catalog unavailable; keeping existing model settings."); }
|
|
106
|
+
fs.writeFileSync(process.argv[4], JSON.stringify(models));
|
|
107
|
+
' "$AGENT_WORK_DIR/capabilities.mjs" "$ROTATOR_URL" "$API_KEY" "$AGENT_WORK_DIR/models.json"
|
|
108
|
+
|
|
67
109
|
# Helper to check if agent should be installed
|
|
68
110
|
should_install() {
|
|
69
111
|
local agent="$1"
|
|
@@ -95,6 +137,7 @@ if should_install "opencode" "$OPENCODE_DIR"; then
|
|
|
95
137
|
${pluginFileWriteLines}
|
|
96
138
|
|
|
97
139
|
node -e '
|
|
140
|
+
(async () => {
|
|
98
141
|
const fs = require("fs");
|
|
99
142
|
const path = require("path");
|
|
100
143
|
|
|
@@ -161,9 +204,14 @@ ${pluginFileWriteLines}
|
|
|
161
204
|
config.provider[providerID].options.apiKey = apiKey;
|
|
162
205
|
}
|
|
163
206
|
|
|
207
|
+
const { mergeOpenCodeModels } = await import(require("url").pathToFileURL(process.argv[6]).href);
|
|
208
|
+
const live = JSON.parse(fs.readFileSync(process.argv[5], "utf8"));
|
|
209
|
+
if (live.length) config.provider[providerID].models = mergeOpenCodeModels(config.provider[providerID].models, live);
|
|
210
|
+
if (fs.existsSync(configFile)) fs.copyFileSync(configFile, configFile + ".bak." + Date.now());
|
|
164
211
|
fs.writeFileSync(configFile, JSON.stringify(config, null, 2) + "\\n", "utf8");
|
|
165
212
|
console.log("==> [OpenCode] Configured successfully.");
|
|
166
|
-
|
|
213
|
+
})().catch(error => { console.error(error.message); process.exitCode = 1; });
|
|
214
|
+
' "$PROVIDER_ID" "$PROVIDER_NAME" "$ROTATOR_URL" "$API_KEY" "$AGENT_WORK_DIR/models.json" "$AGENT_WORK_DIR/capabilities.mjs"
|
|
167
215
|
else
|
|
168
216
|
echo "==> [OpenCode] Skipped (not selected or directory not found)."
|
|
169
217
|
fi
|
|
@@ -171,85 +219,74 @@ fi
|
|
|
171
219
|
# -------------------------------------------------------------
|
|
172
220
|
# 2. Hermes Configuration
|
|
173
221
|
# -------------------------------------------------------------
|
|
174
|
-
HERMES_DIR="
|
|
222
|
+
HERMES_DIR="\${HERMES_HOME:-$HOME/.hermes}"
|
|
175
223
|
if should_install "hermes" "$HERMES_DIR"; then
|
|
176
224
|
echo ""
|
|
177
225
|
echo "==> [Hermes] Configuring in $HERMES_DIR..."
|
|
178
226
|
mkdir -p "$HERMES_DIR"
|
|
179
227
|
|
|
180
228
|
python3 -c '
|
|
181
|
-
import os, sys
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
provider_id = sys.argv[1]
|
|
185
|
-
rotator_url = sys.argv[2]
|
|
186
|
-
api_key = sys.argv[3]
|
|
187
|
-
|
|
229
|
+
import os, sys, json, time, shutil
|
|
230
|
+
config_file = os.path.join(sys.argv[5], "config.yaml")
|
|
231
|
+
provider_id, rotator_url, api_key, models_file = sys.argv[1:5]
|
|
188
232
|
try:
|
|
189
233
|
import yaml
|
|
190
|
-
has_yaml = True
|
|
191
234
|
except ImportError:
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
data = {}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
p["discover_models"] = True
|
|
215
|
-
updated = True
|
|
216
|
-
break
|
|
217
|
-
|
|
218
|
-
if not updated:
|
|
219
|
-
custom_providers.append({
|
|
220
|
-
"name": provider_id,
|
|
221
|
-
"base_url": rotator_url,
|
|
222
|
-
"api_key": api_key,
|
|
223
|
-
"discover_models": True
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
data["custom_providers"] = custom_providers
|
|
227
|
-
with open(config_file, "w", encoding="utf-8") as f:
|
|
228
|
-
yaml.safe_dump(data, f, sort_keys=False)
|
|
229
|
-
print("==> [Hermes] Updated custom_providers with discover_models=True via PyYAML.")
|
|
235
|
+
yaml = None
|
|
236
|
+
content = open(config_file, encoding="utf-8").read() if os.path.exists(config_file) else ""
|
|
237
|
+
try:
|
|
238
|
+
data = (yaml.safe_load(content) if yaml else json.loads(content)) if content.strip() else {}
|
|
239
|
+
except Exception as error:
|
|
240
|
+
raise SystemExit("Cannot safely parse existing Hermes YAML; install PyYAML. Configuration was preserved.") from error
|
|
241
|
+
if not isinstance(data, dict):
|
|
242
|
+
raise SystemExit("Hermes configuration must be a mapping; configuration was preserved.")
|
|
243
|
+
custom = data.setdefault("custom_providers", [])
|
|
244
|
+
if not isinstance(custom, list):
|
|
245
|
+
raise SystemExit("Hermes custom_providers must be a list; configuration was preserved.")
|
|
246
|
+
modern = data.get("providers", {})
|
|
247
|
+
modern_entry = modern.get(provider_id) if isinstance(modern, dict) else None
|
|
248
|
+
entry = modern_entry if isinstance(modern_entry, dict) else next((p for p in custom if isinstance(p, dict) and p.get("name") == provider_id), None)
|
|
249
|
+
# Reuse an already connected legacy provider only when the endpoint matches.
|
|
250
|
+
if entry is None:
|
|
251
|
+
entry = next((p for p in custom if isinstance(p, dict) and p.get("name") in ("antigravity", "tuxevil-rotator") and str(p.get("base_url", "")).rstrip("/") == rotator_url), None)
|
|
252
|
+
if entry is None:
|
|
253
|
+
entry = {"name": provider_id}
|
|
254
|
+
custom.append(entry)
|
|
255
|
+
if entry is modern_entry:
|
|
256
|
+
entry["api"] = rotator_url
|
|
230
257
|
else:
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
""
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
258
|
+
entry["base_url"] = rotator_url
|
|
259
|
+
entry.setdefault("api_mode", "chat_completions")
|
|
260
|
+
entry.pop("discover_models", None)
|
|
261
|
+
if api_key != "no-key" or not (entry.get("api_key") or entry.get("key_env")):
|
|
262
|
+
entry["api_key"] = api_key
|
|
263
|
+
with open(models_file, encoding="utf-8") as f:
|
|
264
|
+
live = json.load(f)
|
|
265
|
+
models = entry.get("models", {})
|
|
266
|
+
if isinstance(models, list):
|
|
267
|
+
models = {name: {} for name in models if isinstance(name, str)}
|
|
268
|
+
if not isinstance(models, dict):
|
|
269
|
+
raise SystemExit("Hermes provider models must be a mapping or list; configuration was preserved.")
|
|
270
|
+
for model in live:
|
|
271
|
+
meta = model.get("meta", {})
|
|
272
|
+
prior = models.get(model["id"], {})
|
|
273
|
+
models[model["id"]] = {"context_length": meta.get("context_length", model.get("context_window", 128000)), **prior}
|
|
274
|
+
# A named-provider override enables native /reasoning controls without pinning
|
|
275
|
+
# an effort or changing defaults for any other provider.
|
|
276
|
+
if meta.get("provider") == "openai-codex" or meta.get("family") == "openai-codex":
|
|
277
|
+
overrides = data.setdefault("model_overrides", {}).setdefault("custom:" + entry.get("name", provider_id), {})
|
|
278
|
+
overrides.setdefault(model["id"], {}).setdefault("supports_reasoning", meta.get("reasoning", False))
|
|
279
|
+
if models:
|
|
280
|
+
entry["models"] = models
|
|
281
|
+
if content:
|
|
282
|
+
shutil.copy2(config_file, config_file + ".bak." + str(time.time_ns()))
|
|
283
|
+
with open(config_file, "w", encoding="utf-8") as f:
|
|
284
|
+
if yaml:
|
|
285
|
+
yaml.safe_dump(data, f, sort_keys=False)
|
|
248
286
|
else:
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
' "$PROVIDER_ID" "$ROTATOR_URL" "$API_KEY"
|
|
287
|
+
json.dump(data, f, indent=2)
|
|
288
|
+
print("==> [Hermes] Connected; choose a Codex model and use /reasoning low|medium|high|xhigh|max as supported.")
|
|
289
|
+
' "$PROVIDER_ID" "$ROTATOR_URL" "$API_KEY" "$AGENT_WORK_DIR/models.json" "$HERMES_DIR"
|
|
253
290
|
else
|
|
254
291
|
echo "==> [Hermes] Skipped (not selected or directory not found)."
|
|
255
292
|
fi
|
|
@@ -266,39 +303,12 @@ if should_install "pi" "$PI_DIR"; then
|
|
|
266
303
|
node -e '
|
|
267
304
|
const fs = require("fs");
|
|
268
305
|
const path = require("path");
|
|
269
|
-
const http = require("http");
|
|
270
|
-
const https = require("https");
|
|
271
306
|
|
|
272
307
|
const modelsFile = path.join(process.env.HOME, ".pi/agent/models.json");
|
|
273
308
|
const providerID = process.argv[1];
|
|
274
309
|
const baseURL = process.argv[2];
|
|
275
310
|
const apiKey = process.argv[3];
|
|
276
311
|
|
|
277
|
-
async function fetchModels(url) {
|
|
278
|
-
return new Promise((resolve) => {
|
|
279
|
-
try {
|
|
280
|
-
const parsed = new URL(url.replace(/\\/+$/, "") + "/models");
|
|
281
|
-
const client = parsed.protocol === "https:" ? https : http;
|
|
282
|
-
const req = client.get(parsed, { timeout: 3000 }, (res) => {
|
|
283
|
-
let data = "";
|
|
284
|
-
res.on("data", chunk => data += chunk);
|
|
285
|
-
res.on("end", () => {
|
|
286
|
-
try {
|
|
287
|
-
const json = JSON.parse(data);
|
|
288
|
-
resolve(Array.isArray(json?.data) ? json.data : []);
|
|
289
|
-
} catch {
|
|
290
|
-
resolve([]);
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
req.on("error", () => resolve([]));
|
|
295
|
-
req.on("timeout", () => { req.destroy(); resolve([]); });
|
|
296
|
-
} catch {
|
|
297
|
-
resolve([]);
|
|
298
|
-
}
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
|
|
302
312
|
async function main() {
|
|
303
313
|
let modelsData = { providers: {} };
|
|
304
314
|
if (fs.existsSync(modelsFile)) {
|
|
@@ -312,18 +322,16 @@ if should_install "pi" "$PI_DIR"; then
|
|
|
312
322
|
}
|
|
313
323
|
modelsData.providers = modelsData.providers || {};
|
|
314
324
|
|
|
315
|
-
const rawModels =
|
|
325
|
+
const rawModels = JSON.parse(fs.readFileSync(process.argv[4], "utf8"));
|
|
326
|
+
const { mapAgentModel } = await import(require("url").pathToFileURL(process.argv[5]).href);
|
|
316
327
|
let mappedModels = [];
|
|
317
328
|
|
|
318
329
|
if (rawModels.length > 0) {
|
|
319
|
-
mappedModels = rawModels.map(
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
contextWindow: m.meta?.context_length || m.context_window || 128000,
|
|
325
|
-
maxTokens: m.meta?.max_output_tokens || 8192
|
|
326
|
-
}));
|
|
330
|
+
mappedModels = rawModels.map(raw => {
|
|
331
|
+
const model = mapAgentModel(raw);
|
|
332
|
+
if (model.compat) model.compat = { supportsReasoningEffort: true };
|
|
333
|
+
return model;
|
|
334
|
+
});
|
|
327
335
|
console.log("==> [Pi Agent] Discovered " + mappedModels.length + " live models from rotator.");
|
|
328
336
|
} else {
|
|
329
337
|
// Fallback baseline if rotator is not immediately reachable
|
|
@@ -335,10 +343,21 @@ if should_install "pi" "$PI_DIR"; then
|
|
|
335
343
|
console.log("==> [Pi Agent] Rotator unreachable during install; populated standard baseline models.");
|
|
336
344
|
}
|
|
337
345
|
|
|
346
|
+
const existing = modelsData.providers[providerID] || {};
|
|
347
|
+
if (!rawModels.length && existing.models?.length) mappedModels = existing.models;
|
|
348
|
+
else {
|
|
349
|
+
const merged = new Map((existing.models || []).map(model => [model.id, model]));
|
|
350
|
+
for (const model of mappedModels) {
|
|
351
|
+
const old = merged.get(model.id) || {};
|
|
352
|
+
merged.set(model.id, { ...model, ...old, ...(model.compat || old.compat ? { compat: { ...model.compat, ...old.compat } } : {}) });
|
|
353
|
+
}
|
|
354
|
+
mappedModels = [...merged.values()];
|
|
355
|
+
}
|
|
338
356
|
modelsData.providers[providerID] = {
|
|
357
|
+
...existing,
|
|
339
358
|
baseUrl: baseURL,
|
|
340
359
|
api: "openai-completions",
|
|
341
|
-
apiKey: apiKey,
|
|
360
|
+
apiKey: apiKey !== "no-key" ? apiKey : existing.apiKey || apiKey,
|
|
342
361
|
models: mappedModels
|
|
343
362
|
};
|
|
344
363
|
|
|
@@ -346,8 +365,8 @@ if should_install "pi" "$PI_DIR"; then
|
|
|
346
365
|
console.log("==> [Pi Agent] Configured successfully in " + modelsFile);
|
|
347
366
|
}
|
|
348
367
|
|
|
349
|
-
main();
|
|
350
|
-
' "$PROVIDER_ID" "$ROTATOR_URL" "$API_KEY"
|
|
368
|
+
main().catch(error => { console.error(error.message); process.exitCode = 1; });
|
|
369
|
+
' "$PROVIDER_ID" "$ROTATOR_URL" "$API_KEY" "$AGENT_WORK_DIR/models.json" "$AGENT_WORK_DIR/capabilities.mjs"
|
|
351
370
|
else
|
|
352
371
|
echo "==> [Pi Agent] Skipped (not selected or directory not found)."
|
|
353
372
|
fi
|
|
@@ -397,6 +416,47 @@ else
|
|
|
397
416
|
echo "==> [Codex CLI] Skipped (not selected or directory not found)."
|
|
398
417
|
fi
|
|
399
418
|
|
|
419
|
+
# -------------------------------------------------------------
|
|
420
|
+
# 5. OpenClaw Configuration
|
|
421
|
+
# -------------------------------------------------------------
|
|
422
|
+
OPENCLAW_DIR="\${OPENCLAW_STATE_DIR:-$HOME/.openclaw}"
|
|
423
|
+
if should_install "openclaw" "$OPENCLAW_DIR"; then
|
|
424
|
+
node -e '
|
|
425
|
+
const fs = require("fs"), path = require("path");
|
|
426
|
+
(async () => {
|
|
427
|
+
const configFile = process.env.OPENCLAW_CONFIG_PATH || path.join(process.argv[1], "openclaw.json");
|
|
428
|
+
const [providerID, baseURL, apiKey, modelsFile, helper] = process.argv.slice(2);
|
|
429
|
+
const { mapAgentModel } = await import(require("url").pathToFileURL(helper).href);
|
|
430
|
+
const live = JSON.parse(fs.readFileSync(modelsFile, "utf8"));
|
|
431
|
+
const content = fs.existsSync(configFile) ? fs.readFileSync(configFile, "utf8") : "";
|
|
432
|
+
let config;
|
|
433
|
+
try { config = content ? JSON.parse(content) : {}; }
|
|
434
|
+
catch { throw new Error("Cannot safely parse OpenClaw JSON; existing configuration was preserved."); }
|
|
435
|
+
config.models ||= {};
|
|
436
|
+
config.models.mode ||= "merge";
|
|
437
|
+
config.models.providers ||= {};
|
|
438
|
+
const prior = config.models.providers[providerID] || {};
|
|
439
|
+
const models = new Map((prior.models || []).map(model => [model.id, model]));
|
|
440
|
+
for (const raw of live) {
|
|
441
|
+
const generated = mapAgentModel(raw), old = models.get(raw.id) || {};
|
|
442
|
+
models.set(raw.id, { cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, ...generated, ...old,
|
|
443
|
+
...(generated.compat || old.compat ? { compat: { ...generated.compat, ...old.compat } } : {}) });
|
|
444
|
+
}
|
|
445
|
+
config.models.providers[providerID] = { ...prior, baseUrl: baseURL,
|
|
446
|
+
api: prior.api && prior.api !== "openai" ? prior.api : "openai-completions",
|
|
447
|
+
apiKey: apiKey !== "no-key" ? apiKey : prior.apiKey || "no-key", models: [...models.values()] };
|
|
448
|
+
const allowlist = config.agents?.defaults?.models;
|
|
449
|
+
if (allowlist) for (const model of models.values()) allowlist[providerID + "/" + model.id] ||= {};
|
|
450
|
+
fs.mkdirSync(path.dirname(configFile), { recursive: true });
|
|
451
|
+
if (content) fs.copyFileSync(configFile, configFile + ".bak." + Date.now());
|
|
452
|
+
fs.writeFileSync(configFile, JSON.stringify(config, null, 2) + "\\n");
|
|
453
|
+
console.log("==> [OpenClaw] Connected; choose a Codex model and use /think high (or another advertised effort).");
|
|
454
|
+
})().catch(error => { console.error(error.message); process.exitCode = 1; });
|
|
455
|
+
' "$OPENCLAW_DIR" "$PROVIDER_ID" "$ROTATOR_URL" "$API_KEY" "$AGENT_WORK_DIR/models.json" "$AGENT_WORK_DIR/capabilities.mjs"
|
|
456
|
+
else
|
|
457
|
+
echo "==> [OpenClaw] Skipped (not selected or directory not found)."
|
|
458
|
+
fi
|
|
459
|
+
|
|
400
460
|
echo ""
|
|
401
461
|
echo "==> All target agents processed successfully!"
|
|
402
462
|
`;
|
|
@@ -405,9 +465,13 @@ echo "==> All target agents processed successfully!"
|
|
|
405
465
|
/**
|
|
406
466
|
* Installs configuration for one or more agents locally or over SSH.
|
|
407
467
|
*/
|
|
408
|
-
export async function installAgents(
|
|
468
|
+
export async function installAgents(
|
|
469
|
+
options: AgentInstallOptions,
|
|
470
|
+
): Promise<void> {
|
|
409
471
|
if (!existsSync(resolve(OPENCODE_PLUGIN_SOURCE_DIR, "index.mjs"))) {
|
|
410
|
-
throw new Error(
|
|
472
|
+
throw new Error(
|
|
473
|
+
`OpenCode plugin directory missing index.mjs at ${OPENCODE_PLUGIN_SOURCE_DIR}`,
|
|
474
|
+
);
|
|
411
475
|
}
|
|
412
476
|
|
|
413
477
|
const opencodePluginFiles: Record<string, string> = {};
|
|
@@ -424,7 +488,8 @@ export async function installAgents(options: AgentInstallOptions): Promise<void>
|
|
|
424
488
|
|
|
425
489
|
const providerId = options.providerId || "tuxevil-rotator";
|
|
426
490
|
const providerName = options.providerName || "Tuxevil Rotator";
|
|
427
|
-
const targets: Array<SupportedAgent | "auto" | "all"> =
|
|
491
|
+
const targets: Array<SupportedAgent | "auto" | "all"> =
|
|
492
|
+
options.targets && options.targets.length > 0 ? options.targets : ["auto"];
|
|
428
493
|
|
|
429
494
|
const script = buildCompositeInstallerScript(opencodePluginFiles, {
|
|
430
495
|
targets,
|
|
@@ -435,14 +500,22 @@ export async function installAgents(options: AgentInstallOptions): Promise<void>
|
|
|
435
500
|
});
|
|
436
501
|
|
|
437
502
|
if (options.dryRun) {
|
|
438
|
-
console.log(
|
|
503
|
+
console.log(
|
|
504
|
+
"=== Dry Run Mode: Composite Script that would be executed ===",
|
|
505
|
+
);
|
|
439
506
|
console.log(script);
|
|
440
507
|
return;
|
|
441
508
|
}
|
|
442
509
|
|
|
443
510
|
// Local installation
|
|
444
|
-
if (
|
|
445
|
-
|
|
511
|
+
if (
|
|
512
|
+
!options.host ||
|
|
513
|
+
options.host === "localhost" ||
|
|
514
|
+
options.host === "127.0.0.1"
|
|
515
|
+
) {
|
|
516
|
+
console.log(
|
|
517
|
+
`==> Installing agent configuration locally for rotator: ${rotatorUrl}...`,
|
|
518
|
+
);
|
|
446
519
|
execSync("bash -s", {
|
|
447
520
|
input: script,
|
|
448
521
|
stdio: ["pipe", "inherit", "inherit"],
|
|
@@ -451,11 +524,16 @@ export async function installAgents(options: AgentInstallOptions): Promise<void>
|
|
|
451
524
|
}
|
|
452
525
|
|
|
453
526
|
// Remote installation via SSH
|
|
454
|
-
const sshTarget = options.user
|
|
527
|
+
const sshTarget = options.user
|
|
528
|
+
? `${options.user}@${options.host}`
|
|
529
|
+
: options.host;
|
|
455
530
|
const sshArgs: string[] = [
|
|
456
|
-
"-o",
|
|
457
|
-
"
|
|
458
|
-
"-o",
|
|
531
|
+
"-o",
|
|
532
|
+
"BatchMode=yes",
|
|
533
|
+
"-o",
|
|
534
|
+
"ConnectTimeout=10",
|
|
535
|
+
"-o",
|
|
536
|
+
"StrictHostKeyChecking=accept-new",
|
|
459
537
|
];
|
|
460
538
|
|
|
461
539
|
if (options.port) {
|
|
@@ -467,7 +545,9 @@ export async function installAgents(options: AgentInstallOptions): Promise<void>
|
|
|
467
545
|
|
|
468
546
|
const sshCmd = `ssh ${sshArgs.join(" ")} ${sshTarget} "bash -s"`;
|
|
469
547
|
|
|
470
|
-
console.log(
|
|
548
|
+
console.log(
|
|
549
|
+
`==> Installing agent configuration remotely on ${sshTarget} (Rotator: ${rotatorUrl})...`,
|
|
550
|
+
);
|
|
471
551
|
try {
|
|
472
552
|
execSync(sshCmd, {
|
|
473
553
|
input: script,
|
|
@@ -475,6 +555,8 @@ export async function installAgents(options: AgentInstallOptions): Promise<void>
|
|
|
475
555
|
});
|
|
476
556
|
} catch (err: unknown) {
|
|
477
557
|
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
478
|
-
throw new Error(`SSH installation failed on ${sshTarget}: ${errorMsg}`, {
|
|
558
|
+
throw new Error(`SSH installation failed on ${sshTarget}: ${errorMsg}`, {
|
|
559
|
+
cause: err,
|
|
560
|
+
});
|
|
479
561
|
}
|
|
480
562
|
}
|