@openagents-org/agent-launcher 0.2.185 → 0.2.187
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/package.json +2 -2
- package/registry.json +13 -8
- package/src/adapters/cline.js +34 -38
- package/src/adapters/codebuddy.js +0 -8
- package/src/adapters/codex.js +246 -66
- package/src/adapters/commandcode.js +0 -8
- package/src/adapters/copilot.js +13 -5
- package/src/adapters/hermes.js +40 -0
- package/src/adapters/llm-direct.js +2 -1
- package/src/adapters/opencode.js +57 -14
- package/src/adapters/openworker.js +0 -8
- package/src/adapters/utils.js +7 -4
- package/src/daemon.js +81 -1
- package/src/installer.js +232 -59
- package/src/model-list.js +100 -0
- package/src/paths.js +102 -0
- package/src/probe.js +23 -2
package/src/adapters/copilot.js
CHANGED
|
@@ -76,7 +76,7 @@ const SECRET_ENV_VARS = [
|
|
|
76
76
|
const ACT_ALLOW_TOOLS = ['shell', 'write'];
|
|
77
77
|
|
|
78
78
|
// How long to wait for a turn before giving up (no output / hung CLI).
|
|
79
|
-
const
|
|
79
|
+
const TURN_IDLE_TIMEOUT_MS = 10 * 60 * 1000;
|
|
80
80
|
|
|
81
81
|
class CopilotAdapter extends BaseAdapter {
|
|
82
82
|
/**
|
|
@@ -565,10 +565,15 @@ class CopilotAdapter extends BaseAdapter {
|
|
|
565
565
|
let pending = Promise.resolve();
|
|
566
566
|
let settled = false;
|
|
567
567
|
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
568
|
+
let timeout = null;
|
|
569
|
+
const resetTimeout = () => {
|
|
570
|
+
if (timeout) clearTimeout(timeout);
|
|
571
|
+
timeout = setTimeout(() => {
|
|
572
|
+
this._stopProcess(proc).catch(() => {});
|
|
573
|
+
finish({ timedOut: true, finalText: accumulatedText() });
|
|
574
|
+
}, TURN_IDLE_TIMEOUT_MS);
|
|
575
|
+
};
|
|
576
|
+
resetTimeout();
|
|
572
577
|
|
|
573
578
|
const finish = (summary) => {
|
|
574
579
|
if (settled) return;
|
|
@@ -657,6 +662,9 @@ class CopilotAdapter extends BaseAdapter {
|
|
|
657
662
|
}
|
|
658
663
|
};
|
|
659
664
|
|
|
665
|
+
if (proc.stdout) proc.stdout.on('data', resetTimeout);
|
|
666
|
+
if (proc.stderr) proc.stderr.on('data', resetTimeout);
|
|
667
|
+
|
|
660
668
|
proc.stdout.on('data', (chunk) => {
|
|
661
669
|
for (const ev of parser.push(chunk)) {
|
|
662
670
|
pending = pending.then(() => handle(ev)).catch(() => {});
|
package/src/adapters/hermes.js
CHANGED
|
@@ -25,6 +25,7 @@ const { spawn, bridgeSpawn } = require('../wsl');
|
|
|
25
25
|
|
|
26
26
|
const BaseAdapter = require('./base');
|
|
27
27
|
const { buildOpenclawSystemPrompt } = require('./workspace-prompt');
|
|
28
|
+
const { REASON } = require('./health-status');
|
|
28
29
|
const { whichBinary, whereBinary } = require('../paths');
|
|
29
30
|
|
|
30
31
|
const IS_WINDOWS = process.platform === 'win32';
|
|
@@ -123,6 +124,34 @@ class HermesAdapter extends BaseAdapter {
|
|
|
123
124
|
return null;
|
|
124
125
|
}
|
|
125
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Preflight gate (run by the daemon before join). Hermes can do nothing
|
|
129
|
+
* without its CLI, so when none can be resolved we surface a precise
|
|
130
|
+
* 'runtime_missing' reason and skip the workspace join — instead of joining,
|
|
131
|
+
* reporting "online" and then failing every message. That contradiction is
|
|
132
|
+
* exactly what users hit: the workspace showed a green hermes and "all set"
|
|
133
|
+
* while the smoke test on the same screen said "Not installed", because
|
|
134
|
+
* `create_agent --install` treats a failed third-party install script as a
|
|
135
|
+
* warning and connects the agent anyway.
|
|
136
|
+
*
|
|
137
|
+
* Re-resolves rather than trusting the constructor's lookup: an install that
|
|
138
|
+
* landed after the daemon started must not need a restart to be seen. NOTE:
|
|
139
|
+
* 'runtime_missing' (binary gone/never landed at run time), NOT
|
|
140
|
+
* 'not_installed' — install detection lives in the installer.
|
|
141
|
+
*/
|
|
142
|
+
preflight() {
|
|
143
|
+
if (!this._hermesBin) this._hermesBin = this._findHermesBinary();
|
|
144
|
+
if (!this._hermesBin) {
|
|
145
|
+
return {
|
|
146
|
+
ok: false,
|
|
147
|
+
reason: REASON.RUNTIME_MISSING,
|
|
148
|
+
message: `Hermes CLI not found — install with: ${HERMES_INSTALL_HINT}`,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
this._log(`Hermes CLI resolved: ${this._hermesBin}`);
|
|
152
|
+
return { ok: true };
|
|
153
|
+
}
|
|
154
|
+
|
|
126
155
|
_resolveProfile(explicit, agentName) {
|
|
127
156
|
if (explicit && explicit !== '' && explicit !== 'auto') return explicit;
|
|
128
157
|
// Match agent name to an existing ~/.hermes/profiles/<name> if present
|
|
@@ -371,6 +400,17 @@ class HermesAdapter extends BaseAdapter {
|
|
|
371
400
|
const sender = msg.senderName || msg.senderType || 'user';
|
|
372
401
|
this._log(`Processing workspace message from ${sender} in ${msgChannel}`);
|
|
373
402
|
|
|
403
|
+
// Re-resolve per message: the constructor's lookup is a snapshot, and an
|
|
404
|
+
// agent that was created before its CLI finished installing would
|
|
405
|
+
// otherwise stay broken until the daemon restarts.
|
|
406
|
+
if (!this._hermesBin) this._hermesBin = this._findHermesBinary();
|
|
407
|
+
if (!this._hermesBin) {
|
|
408
|
+
const message = `Hermes CLI not found — install with: ${HERMES_INSTALL_HINT}`;
|
|
409
|
+
this._reportStatus(REASON.RUNTIME_MISSING, message);
|
|
410
|
+
await this.sendError(msgChannel, message);
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
|
|
374
414
|
await this._autoTitleChannel(msgChannel, content);
|
|
375
415
|
await this.sendStatus(msgChannel, 'thinking...');
|
|
376
416
|
|
|
@@ -158,7 +158,8 @@ class LlmDirectAdapter extends BaseAdapter {
|
|
|
158
158
|
'Authorization': `Bearer ${this._apiKey}`,
|
|
159
159
|
};
|
|
160
160
|
const payload = JSON.stringify({
|
|
161
|
-
model
|
|
161
|
+
// The model picked in the workspace, which modelLabel() reports, wins.
|
|
162
|
+
model: this.modelLabel() || 'gpt-4o',
|
|
162
163
|
messages,
|
|
163
164
|
stream: true,
|
|
164
165
|
});
|
package/src/adapters/opencode.js
CHANGED
|
@@ -27,8 +27,10 @@ const { whichBinary, whereBinary, getEnhancedEnv } = require('../paths');
|
|
|
27
27
|
|
|
28
28
|
const IS_WINDOWS = process.platform === 'win32';
|
|
29
29
|
|
|
30
|
-
// Max
|
|
31
|
-
//
|
|
30
|
+
// Max time an `opencode run` may stay completely silent. This is deliberately
|
|
31
|
+
// an IDLE timeout, not a wall-clock cap: long coding tasks routinely exceed
|
|
32
|
+
// five minutes while continuing to emit text/tool events. A fixed spawn
|
|
33
|
+
// timeout killed those healthy runs midway through their answer.
|
|
32
34
|
const TIMEOUT_MS = 300000; // 5 minutes
|
|
33
35
|
|
|
34
36
|
// Pinned OpenCode CLI version. Do NOT use @latest anywhere (registry.json /
|
|
@@ -158,6 +160,34 @@ class OpenCodeAdapter extends BaseAdapter {
|
|
|
158
160
|
}
|
|
159
161
|
|
|
160
162
|
/** Environment the CLI is spawned with. */
|
|
163
|
+
|
|
164
|
+
/** Test seam for the inactivity watchdog. */
|
|
165
|
+
_runTimeoutMs() {
|
|
166
|
+
return TIMEOUT_MS;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Arm a watchdog that expires only after a continuous period without CLI
|
|
171
|
+
* output. Every stdout/stderr chunk proves the process is still making
|
|
172
|
+
* progress and pushes the deadline out again.
|
|
173
|
+
*/
|
|
174
|
+
_createIdleWatchdog(onTimeout) {
|
|
175
|
+
const timeoutMs = this._runTimeoutMs();
|
|
176
|
+
let timer = null;
|
|
177
|
+
let stopped = false;
|
|
178
|
+
const touch = () => {
|
|
179
|
+
if (stopped) return;
|
|
180
|
+
if (timer) clearTimeout(timer);
|
|
181
|
+
timer = setTimeout(onTimeout, timeoutMs);
|
|
182
|
+
};
|
|
183
|
+
const cancel = () => {
|
|
184
|
+
stopped = true;
|
|
185
|
+
if (timer) clearTimeout(timer);
|
|
186
|
+
timer = null;
|
|
187
|
+
};
|
|
188
|
+
touch();
|
|
189
|
+
return { touch, cancel, timeoutMs };
|
|
190
|
+
}
|
|
161
191
|
_spawnEnv() {
|
|
162
192
|
return { ...(this.agentEnv || process.env) };
|
|
163
193
|
}
|
|
@@ -701,8 +731,8 @@ class OpenCodeAdapter extends BaseAdapter {
|
|
|
701
731
|
* CRITICAL: opencode-ai does NOT read the OPENCODE_MODEL env var. When no
|
|
702
732
|
* model is given on the command line AND none is set in opencode.json, the
|
|
703
733
|
* non-interactive `run` command hangs forever waiting for interactive
|
|
704
|
-
* provider/model selection — it emits zero output until the
|
|
705
|
-
* kills it with SIGTERM
|
|
734
|
+
* provider/model selection — it emits zero output until the inactivity
|
|
735
|
+
* watchdog kills it with SIGTERM.
|
|
706
736
|
* Passing `--model` explicitly is what makes headless runs actually work.
|
|
707
737
|
*/
|
|
708
738
|
_resolveModel() {
|
|
@@ -843,7 +873,6 @@ class OpenCodeAdapter extends BaseAdapter {
|
|
|
843
873
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
844
874
|
env: spawnEnv,
|
|
845
875
|
cwd: runCwd,
|
|
846
|
-
timeout: TIMEOUT_MS,
|
|
847
876
|
detached: !IS_WINDOWS,
|
|
848
877
|
// Never let a console window appear. Besides being ugly, an attached
|
|
849
878
|
// console makes opencode start its interactive TUI and hang instead of
|
|
@@ -859,9 +888,16 @@ class OpenCodeAdapter extends BaseAdapter {
|
|
|
859
888
|
let pendingEvents = Promise.resolve();
|
|
860
889
|
const responseState = { finalText: '', allText: '', seenText: false };
|
|
861
890
|
let settled = false;
|
|
891
|
+
let timedOut = false;
|
|
892
|
+
const watchdog = this._createIdleWatchdog(() => {
|
|
893
|
+
timedOut = true;
|
|
894
|
+
this._log(`opencode idle for ${this._runTimeoutMs() / 1000}s; terminating`);
|
|
895
|
+
this._stopProcess(proc).catch(() => {});
|
|
896
|
+
});
|
|
862
897
|
const finish = (fn, arg) => {
|
|
863
898
|
if (settled) return;
|
|
864
899
|
settled = true;
|
|
900
|
+
watchdog.cancel();
|
|
865
901
|
if (this._channelProcesses[msgChannel] === proc) {
|
|
866
902
|
delete this._channelProcesses[msgChannel];
|
|
867
903
|
}
|
|
@@ -870,6 +906,7 @@ class OpenCodeAdapter extends BaseAdapter {
|
|
|
870
906
|
|
|
871
907
|
if (proc.stdout) {
|
|
872
908
|
proc.stdout.on('data', (d) => {
|
|
909
|
+
watchdog.touch();
|
|
873
910
|
const chunk = d.toString('utf-8');
|
|
874
911
|
stdout += chunk;
|
|
875
912
|
streamBuffer += chunk;
|
|
@@ -882,7 +919,10 @@ class OpenCodeAdapter extends BaseAdapter {
|
|
|
882
919
|
}
|
|
883
920
|
});
|
|
884
921
|
}
|
|
885
|
-
if (proc.stderr) proc.stderr.on('data', (d) => {
|
|
922
|
+
if (proc.stderr) proc.stderr.on('data', (d) => {
|
|
923
|
+
watchdog.touch();
|
|
924
|
+
stderr += d;
|
|
925
|
+
});
|
|
886
926
|
|
|
887
927
|
// Send the prompt via stdin, then close it so opencode knows the message
|
|
888
928
|
// is complete and never blocks waiting for more input. Guard the write:
|
|
@@ -897,9 +937,8 @@ class OpenCodeAdapter extends BaseAdapter {
|
|
|
897
937
|
|
|
898
938
|
proc.on('error', (err) => finish(reject, err));
|
|
899
939
|
// 'close' (not 'exit') fires after stdout/stderr have fully drained, so we
|
|
900
|
-
// never parse a truncated response. The
|
|
901
|
-
//
|
|
902
|
-
// signal name — report that as a timeout rather than "exited with code null".
|
|
940
|
+
// never parse a truncated response. The explicit `timedOut` flag keeps a
|
|
941
|
+
// watchdog termination distinct from an external signal or crash.
|
|
903
942
|
proc.on('close', async (code, signal) => {
|
|
904
943
|
try { await pendingEvents; } catch {}
|
|
905
944
|
|
|
@@ -917,14 +956,18 @@ class OpenCodeAdapter extends BaseAdapter {
|
|
|
917
956
|
// because stderr happened to be empty.
|
|
918
957
|
const stdoutErr = OpenCodeAdapter._extractErrorFromStdout(stdout);
|
|
919
958
|
|
|
920
|
-
if (
|
|
921
|
-
this._log(`opencode
|
|
959
|
+
if (timedOut) {
|
|
960
|
+
this._log(`opencode timed out after ${watchdog.timeoutMs / 1000}s idle (output: ${!!stdout})`);
|
|
922
961
|
const cls = this.constructor._classifyFailure({ code, signal, stdout, stderr, stdoutErr });
|
|
923
|
-
// A signal almost always means our own timeout fired; only override to
|
|
924
|
-
// a more specific provider error if stdout/stderr clearly show one.
|
|
925
962
|
const category = (cls.category === 'unknown_error' || cls.category === 'process_crashed')
|
|
926
963
|
? 'timeout' : cls.category;
|
|
927
|
-
return finish(reject, this._failure(category, cls.diagnostic || `
|
|
964
|
+
return finish(reject, this._failure(category, cls.diagnostic || `idle=${watchdog.timeoutMs}ms`, cls.detail));
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
if (signal) {
|
|
968
|
+
this._log(`opencode killed by signal ${signal} (output: ${!!stdout})`);
|
|
969
|
+
const cls = this.constructor._classifyFailure({ code, signal, stdout, stderr, stdoutErr });
|
|
970
|
+
return finish(reject, this._failure(cls.category, cls.diagnostic || `signal=${signal}`, cls.detail));
|
|
928
971
|
}
|
|
929
972
|
|
|
930
973
|
if (code !== 0) {
|
|
@@ -98,7 +98,6 @@ const SERVER_READY_TIMEOUT_MS = 90000;
|
|
|
98
98
|
const HEALTH_POLL_INTERVAL_MS = 400;
|
|
99
99
|
|
|
100
100
|
// Max wall-clock for one turn, after which we interrupt and report it.
|
|
101
|
-
const TURN_TIMEOUT_MS = 900000; // 15 minutes
|
|
102
101
|
|
|
103
102
|
// Idle watchdog over the event stream, in the same shape the CLI adapters use.
|
|
104
103
|
const WATCHDOG_INTERVAL_MS = 15000;
|
|
@@ -674,7 +673,6 @@ class OpenWorkerAdapter extends BaseAdapter {
|
|
|
674
673
|
if (settled) return;
|
|
675
674
|
settled = true;
|
|
676
675
|
clearInterval(watchdog);
|
|
677
|
-
clearTimeout(timeout);
|
|
678
676
|
if (this._channelSockets[channel] === socket) delete this._channelSockets[channel];
|
|
679
677
|
try { socket.close(); } catch {}
|
|
680
678
|
const userStopped = this._stoppingChannels.has(channel);
|
|
@@ -821,12 +819,6 @@ class OpenWorkerAdapter extends BaseAdapter {
|
|
|
821
819
|
}
|
|
822
820
|
}, WATCHDOG_INTERVAL_MS);
|
|
823
821
|
|
|
824
|
-
const timeout = setTimeout(() => {
|
|
825
|
-
this._log(`Turn exceeded ${TURN_TIMEOUT_MS}ms — interrupting`);
|
|
826
|
-
send({ type: 'interrupt' });
|
|
827
|
-
if (!error) error = 'The turn ran past its time limit and was stopped.';
|
|
828
|
-
finish({});
|
|
829
|
-
}, TURN_TIMEOUT_MS);
|
|
830
822
|
});
|
|
831
823
|
}
|
|
832
824
|
|
package/src/adapters/utils.js
CHANGED
|
@@ -88,19 +88,22 @@ function formatAttachmentsForPrompt(
|
|
|
88
88
|
const url = att.url || `${base}/v1/files/${fileId}`;
|
|
89
89
|
const curl = isWindows ? 'curl.exe' : 'curl';
|
|
90
90
|
const tmpDir = isWindows ? '$env:TEMP' : '/tmp';
|
|
91
|
+
// A web upload's filename is its workspace path (uploaded_files/<stamp>_<name>)
|
|
92
|
+
// and curl -o does not create folders, so that download failed with exit 23.
|
|
93
|
+
const localName = filename.split(/[\\/]/).pop() || fileId || 'attachment';
|
|
91
94
|
if (contentType.startsWith('image/')) {
|
|
92
95
|
lines.push(
|
|
93
96
|
`- Image: ${filename} (file_id: ${fileId}) — ` +
|
|
94
97
|
`download with curl, then use your Read tool on the local file to view it:\n` +
|
|
95
|
-
` Step 1: ${curl} -s -H "X-Workspace-Token: ${tokenExpr}" "${url}" -o ${tmpDir}/${
|
|
96
|
-
` Step 2: Use the Read tool on ${tmpDir}/${
|
|
98
|
+
` Step 1: ${curl} -s -H "X-Workspace-Token: ${tokenExpr}" "${url}" -o ${tmpDir}/${localName}\n` +
|
|
99
|
+
` Step 2: Use the Read tool on ${tmpDir}/${localName} to see the image`
|
|
97
100
|
);
|
|
98
101
|
} else {
|
|
99
102
|
lines.push(
|
|
100
103
|
`- File: ${filename} (file_id: ${fileId}, type: ${contentType}) — ` +
|
|
101
104
|
`download with curl, then use your Read tool on the local file:\n` +
|
|
102
|
-
` Step 1: ${curl} -s -H "X-Workspace-Token: ${tokenExpr}" "${url}" -o ${tmpDir}/${
|
|
103
|
-
` Step 2: Use the Read tool on ${tmpDir}/${
|
|
105
|
+
` Step 1: ${curl} -s -H "X-Workspace-Token: ${tokenExpr}" "${url}" -o ${tmpDir}/${localName}\n` +
|
|
106
|
+
` Step 2: Use the Read tool on ${tmpDir}/${localName} to read the file`
|
|
104
107
|
);
|
|
105
108
|
}
|
|
106
109
|
} else {
|
package/src/daemon.js
CHANGED
|
@@ -9,6 +9,7 @@ const { execSync, execFileSync } = require('child_process');
|
|
|
9
9
|
const { spawn } = require('./wsl');
|
|
10
10
|
const os = require('os');
|
|
11
11
|
const { WorkspaceClient } = require('./workspace-client');
|
|
12
|
+
const { listEndpointModels } = require('./model-list');
|
|
12
13
|
const { getEnhancedEnv, whichBinary, IS_WINDOWS, defaultAgentWorkdir } = require('./paths');
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -44,6 +45,23 @@ function filesystemRoots(platform = os.platform(), exists = fs.existsSync) {
|
|
|
44
45
|
return roots;
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Hostname of a configured base URL, or null when there is none. The roster
|
|
50
|
+
* carries only this: a relay URL can hold a credential in its userinfo or
|
|
51
|
+
* path. A value written without a scheme (`localhost:4000`) still names a host.
|
|
52
|
+
*/
|
|
53
|
+
function endpointHost(value) {
|
|
54
|
+
const raw = String(value || '').trim();
|
|
55
|
+
if (!raw) return null;
|
|
56
|
+
for (const candidate of [raw, `http://${raw}`]) {
|
|
57
|
+
try {
|
|
58
|
+
const host = new URL(candidate).hostname.toLowerCase();
|
|
59
|
+
if (host) return host;
|
|
60
|
+
} catch {}
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
47
65
|
/**
|
|
48
66
|
* Agent process lifecycle manager.
|
|
49
67
|
*
|
|
@@ -326,7 +344,8 @@ class Daemon {
|
|
|
326
344
|
// Model/key: per-agent env override, else the type-level saved env.
|
|
327
345
|
// Both power the workspace agent cards; the key goes out MASKED only,
|
|
328
346
|
// so the edit form can show a key is configured without the secret
|
|
329
|
-
// ever leaving the device.
|
|
347
|
+
// ever leaving the device. The endpoint goes out as a hostname, so
|
|
348
|
+
// the workspace can tell a relay from the vendor its model list is for.
|
|
330
349
|
let typeEnv = {};
|
|
331
350
|
try { typeEnv = this.envManager.load(a.type) || {}; } catch {}
|
|
332
351
|
const model = (a.env && a.env.LLM_MODEL) || typeEnv.LLM_MODEL || null;
|
|
@@ -338,6 +357,7 @@ class Daemon {
|
|
|
338
357
|
model: model || null,
|
|
339
358
|
workingDir: a.path || null,
|
|
340
359
|
apiKeyMasked: apiKey ? maskApiKey(apiKey) : null,
|
|
360
|
+
baseUrlHost: endpointHost(this._configuredBaseUrl(a, typeEnv)),
|
|
341
361
|
probe: this._probes[a.name] || null,
|
|
342
362
|
});
|
|
343
363
|
}
|
|
@@ -347,6 +367,52 @@ class Daemon {
|
|
|
347
367
|
return roster;
|
|
348
368
|
}
|
|
349
369
|
|
|
370
|
+
/**
|
|
371
|
+
* The base URL this agent's CLI is pointed at, found the way _buildAgentEnv
|
|
372
|
+
* builds its env: LLM_BASE_URL or a provider variable (OPENAI_BASE_URL,
|
|
373
|
+
* ANTHROPIC_BASE_URL, …) saved for it or mapped by resolve_env, and failing
|
|
374
|
+
* those, the daemon's own environment for the provider variable this type's
|
|
375
|
+
* LLM_BASE_URL maps to, which the spawned CLI inherits.
|
|
376
|
+
*/
|
|
377
|
+
_configuredBaseUrl(a, typeEnv) {
|
|
378
|
+
const saved = { ...typeEnv, ...(a.env || {}) };
|
|
379
|
+
let env = saved;
|
|
380
|
+
try { env = { ...saved, ...this.envManager.resolve(a.type, saved, this.registry) }; } catch {}
|
|
381
|
+
const set = (v) => String(v || '').trim();
|
|
382
|
+
if (set(env.LLM_BASE_URL)) return env.LLM_BASE_URL;
|
|
383
|
+
const key = Object.keys(env).find((k) => /_BASE_URL$/.test(k) && set(env[k]));
|
|
384
|
+
if (key) return env[key];
|
|
385
|
+
let rules = [];
|
|
386
|
+
try { rules = (this.registry && this.registry.getResolveRules(a.type)) || []; } catch {}
|
|
387
|
+
const inherited = rules.find((r) => r && r.from === 'LLM_BASE_URL' && r.to && set(process.env[r.to]));
|
|
388
|
+
return inherited ? process.env[inherited.to] : null;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Where this agent's CLI sends requests and with which key, for listing that
|
|
393
|
+
* endpoint's models. The key is looked up the way the CLI would find it: the
|
|
394
|
+
* protocol's own variables for an Anthropic-protocol agent, else LLM_API_KEY
|
|
395
|
+
* or the variable resolve_env maps it to, inherited from the daemon or not.
|
|
396
|
+
*/
|
|
397
|
+
_agentEndpoint(a) {
|
|
398
|
+
let typeEnv = {};
|
|
399
|
+
try { typeEnv = this.envManager.load(a.type) || {}; } catch {}
|
|
400
|
+
const env = this._buildAgentEnv(a);
|
|
401
|
+
let entry = null;
|
|
402
|
+
try { entry = this.registry.getEntry(a.type); } catch {}
|
|
403
|
+
const protocol = (entry && entry.protocol) || 'openai';
|
|
404
|
+
const rules = (entry && entry.resolve_env && entry.resolve_env.rules) || [];
|
|
405
|
+
const keyVars = protocol === 'anthropic'
|
|
406
|
+
? ['ANTHROPIC_AUTH_TOKEN', 'ANTHROPIC_API_KEY', 'LLM_API_KEY']
|
|
407
|
+
: ['LLM_API_KEY', ...rules.filter((r) => r && r.from === 'LLM_API_KEY').map((r) => r.to), 'OPENAI_API_KEY'];
|
|
408
|
+
const keyVar = keyVars.find((k) => k && String(env[k] || '').trim());
|
|
409
|
+
return {
|
|
410
|
+
baseUrl: this._configuredBaseUrl(a, typeEnv),
|
|
411
|
+
apiKey: keyVar ? String(env[keyVar]).trim() : '',
|
|
412
|
+
protocol,
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
|
|
350
416
|
/**
|
|
351
417
|
* Filesystem hint for the working-directory picker: home, its immediate
|
|
352
418
|
* (non-hidden) subfolders, and the device's filesystem roots. Roots let a
|
|
@@ -606,6 +672,20 @@ async _runNodeCommand(n, cmd) {
|
|
|
606
672
|
this._nodeHeartbeat();
|
|
607
673
|
ok = true;
|
|
608
674
|
message = `Detected ${this._runtimes.length} runtime(s)`;
|
|
675
|
+
} else if (action === 'list_models') {
|
|
676
|
+
// The model picker asks what the agent's own endpoint serves. The
|
|
677
|
+
// request needs the key, which is why it runs here.
|
|
678
|
+
if (!name) throw new Error('Missing agent name');
|
|
679
|
+
const agent = this.config.getAgent(name);
|
|
680
|
+
if (!agent || !this._agentOnNodeWorkspace(agent, n)) {
|
|
681
|
+
throw new Error(`Agent '${name}' is not managed by this workspace`);
|
|
682
|
+
}
|
|
683
|
+
const endpoint = this._agentEndpoint(agent);
|
|
684
|
+
if (!endpoint.baseUrl) throw new Error(`Agent '${name}' uses its CLI's default endpoint`);
|
|
685
|
+
const listed = await listEndpointModels(endpoint);
|
|
686
|
+
ok = listed.models.length > 0;
|
|
687
|
+
message = ok ? `Listed ${listed.models.length} model(s)` : listed.error;
|
|
688
|
+
data = { models: listed.models };
|
|
609
689
|
} else if (action === 'list_dir') {
|
|
610
690
|
data = this._listDir(args.path);
|
|
611
691
|
ok = true;
|