@steerable/agent-shell 0.8.5 → 0.9.1
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/README.md +14 -0
- package/dist/brand.d.ts +5 -0
- package/dist/brand.js +4 -0
- package/dist/llm/index.js +2 -2
- package/dist/local-backend/router.js +24 -5
- package/dist/sidecar/boot.js +19 -1
- package/dist/sidecar/egress-proxy.d.ts +21 -3
- package/dist/sidecar/egress-proxy.js +26 -3
- package/dist/sidecar/reverse-spawn.js +8 -1
- package/dist/sidecar/supervisor.d.ts +25 -3
- package/dist/sidecar/supervisor.js +59 -24
- package/dist/storage/llm-settings.d.ts +48 -0
- package/dist/storage/llm-settings.js +108 -0
- package/dist/storage/sqlite-driver.js +31 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
Product-neutral Node HostRuntime and headless HTTP host for Steerable Framework.
|
|
4
4
|
|
|
5
|
+
## Runtime bundle
|
|
6
|
+
|
|
7
|
+
The sidecar, its `run_code` interpreter and the egress proxy are binary
|
|
8
|
+
artifacts. The shell resolves them from the first place that has them: an
|
|
9
|
+
explicit `STEERABLE_SIDECAR_PYTHON` (or the `host-runtime.json` a desktop
|
|
10
|
+
product writes), a packaged `python-runtime/` directory, the
|
|
11
|
+
`@steerable/runtime-<target>` npm package, then a repository `.venv`. A missing
|
|
12
|
+
bundle raises `SidecarRuntimeMissingError` with the reason and the target, and
|
|
13
|
+
a digest mismatch refuses to start.
|
|
14
|
+
|
|
15
|
+
`egressProxyMissingWarning()` is the one-line notice a command line should print
|
|
16
|
+
when the proxy is absent: the host allow-list is then not enforced by domain and
|
|
17
|
+
network rules fall back to ports.
|
|
18
|
+
|
|
5
19
|
## Desktop composition
|
|
6
20
|
|
|
7
21
|
Tauri desktop products supervise the same BS executable used by browser mode,
|
package/dist/brand.d.ts
CHANGED
|
@@ -25,6 +25,11 @@ export interface Brand {
|
|
|
25
25
|
homeHint?: string;
|
|
26
26
|
/** 新对话 / 首页未选手动专家时绑定的内置智能体 id */
|
|
27
27
|
defaultAgentId: string;
|
|
28
|
+
/**
|
|
29
|
+
* 首次打开、且没有可用模型凭据时,先显示配置页再进对话页。
|
|
30
|
+
* 缺省关闭:产品自带首启流程或预置了凭据时不受影响。
|
|
31
|
+
*/
|
|
32
|
+
firstRunSetup?: boolean;
|
|
28
33
|
}
|
|
29
34
|
/**
|
|
30
35
|
* 注入产品品牌(产品组装根在第一个 import 时调用)。重复注入抛错
|
package/dist/brand.js
CHANGED
|
@@ -36,6 +36,10 @@ const SHELL_BRAND = {
|
|
|
36
36
|
agentName: 'Agent',
|
|
37
37
|
tagline: 'A local desktop AI partner',
|
|
38
38
|
defaultAgentId: LOCAL_ASSISTANT_AGENT_ID,
|
|
39
|
+
// The framework's own shell has no preconfigured credential, so a new user
|
|
40
|
+
// needs one step before the chat is usable. Products that ship a configured
|
|
41
|
+
// model, or their own first-run flow, leave this off.
|
|
42
|
+
firstRunSetup: true,
|
|
39
43
|
};
|
|
40
44
|
let productBrand = null;
|
|
41
45
|
let cached = null;
|
package/dist/llm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { productConfigDirectConnection } from '../product-config.js';
|
|
2
|
-
import { sidecarWireProvider } from '../storage/llm-settings.js';
|
|
2
|
+
import { sidecarWireProvider, withResolvedApiKey } from '../storage/llm-settings.js';
|
|
3
3
|
import { OllamaProvider } from './ollama.js';
|
|
4
4
|
import { OpenAICompatProvider } from './openai-compat.js';
|
|
5
5
|
import { SidecarLlmProvider } from './sidecar-provider.js';
|
|
@@ -76,7 +76,7 @@ export class LlmService {
|
|
|
76
76
|
return saved;
|
|
77
77
|
}
|
|
78
78
|
getProvider() {
|
|
79
|
-
const settings = this.getSettings();
|
|
79
|
+
const settings = withResolvedApiKey(this.getSettings());
|
|
80
80
|
const sidecarOn = isSidecarEnabled();
|
|
81
81
|
const signature = `${sidecarOn ? 'sidecar' : 'in-proc'}:${JSON.stringify(settings)}`;
|
|
82
82
|
if (this.provider && this.cachedConfigSignature === signature) {
|
|
@@ -23,7 +23,7 @@ import { isSkillPinned, isToolAllowed, mergeAgentCapabilities, normalizeToolPoli
|
|
|
23
23
|
import { getBrand } from '../brand.js';
|
|
24
24
|
import { recordInsightEvent, recordInsightTurn, recordInsightProfile } from '../insights/record.js';
|
|
25
25
|
import { buildInsightsExportPayload, flushInsightsOutbox, uploadInsightsBundle } from '../insights/flush.js';
|
|
26
|
-
import { sanitizeCompatOverrides, sanitizePresetsChoice, sanitizeLlmProvider, sanitizeVendorId, sidecarWireProvider, listingBaseUrl, vendorModelsListUrl, usesOpenAiCompatExtras } from '../storage/llm-settings.js';
|
|
26
|
+
import { sanitizeCompatOverrides, sanitizePresetsChoice, sanitizeLlmProvider, sanitizeVendorId, sidecarWireProvider, listingBaseUrl, vendorModelsListUrl, usesOpenAiCompatExtras, withResolvedApiKey, resolveApiKey } from '../storage/llm-settings.js';
|
|
27
27
|
import { setDefaultExecTimeoutMs } from '../local-executor.js';
|
|
28
28
|
import { allowEgressForBaseUrl, getActiveEgressBroker, getEgressPosture } from '../sidecar/egress-proxy.js';
|
|
29
29
|
import { buildExecSandbox, parseExecPolicy } from '../sidecar/exec-sandbox.js';
|
|
@@ -1800,7 +1800,7 @@ export class LocalBackendRouter {
|
|
|
1800
1800
|
// Bearer、Anthropic x-api-key、Google x-goog-api-key),再与 models.dev
|
|
1801
1801
|
// 能力表 join。refresh=1 绕过 60s 缓存。凭证随设置显式下发。
|
|
1802
1802
|
if (method === 'GET' && pathname === '/api/v2/llm/models') {
|
|
1803
|
-
const settings = llmService.getSettings();
|
|
1803
|
+
const settings = withResolvedApiKey(llmService.getSettings());
|
|
1804
1804
|
const draftBase = url.searchParams.get('baseUrl');
|
|
1805
1805
|
const draftKey = url.searchParams.get('apiKey');
|
|
1806
1806
|
const provider = sanitizeLlmProvider(url.searchParams.get('provider') || settings.provider);
|
|
@@ -1861,7 +1861,7 @@ export class LocalBackendRouter {
|
|
|
1861
1861
|
}
|
|
1862
1862
|
if (method === 'POST' && pathname === '/api/v2/llm/diagnose') {
|
|
1863
1863
|
const payload = this.toRecord(request.body);
|
|
1864
|
-
const settings = llmService.getSettings();
|
|
1864
|
+
const settings = withResolvedApiKey(llmService.getSettings());
|
|
1865
1865
|
const baseUrl = typeof payload.baseUrl === 'string' && payload.baseUrl.trim()
|
|
1866
1866
|
? payload.baseUrl.trim()
|
|
1867
1867
|
: settings.baseUrl;
|
|
@@ -1912,6 +1912,25 @@ export class LocalBackendRouter {
|
|
|
1912
1912
|
});
|
|
1913
1913
|
return { status: 200, data: account };
|
|
1914
1914
|
}
|
|
1915
|
+
// Whether a turn can start on the current credential. The web shell's
|
|
1916
|
+
// first-run page and the CLI preflight both read this rather than
|
|
1917
|
+
// inspecting the settings object themselves.
|
|
1918
|
+
if (method === 'GET' && pathname === '/api/v2/llm/credential') {
|
|
1919
|
+
const settings = resolveRuntimeLlmSettings(await this.store.getLlmSettings());
|
|
1920
|
+
const resolved = resolveApiKey(settings, process.env);
|
|
1921
|
+
return {
|
|
1922
|
+
status: 200,
|
|
1923
|
+
data: {
|
|
1924
|
+
ok: Boolean(resolved.key) || resolved.source.kind === 'not_required',
|
|
1925
|
+
source: resolved.source.kind,
|
|
1926
|
+
...(resolved.source.kind === 'env' ? { envName: resolved.source.name } : {}),
|
|
1927
|
+
envNames: resolved.envNames,
|
|
1928
|
+
provider: settings.provider,
|
|
1929
|
+
vendorId: settings.vendorId ?? null,
|
|
1930
|
+
model: settings.model,
|
|
1931
|
+
},
|
|
1932
|
+
};
|
|
1933
|
+
}
|
|
1915
1934
|
if (pathname === '/api/v2/local-settings/llm') {
|
|
1916
1935
|
if (method === 'GET') {
|
|
1917
1936
|
return {
|
|
@@ -2983,7 +3002,7 @@ export class LocalBackendRouter {
|
|
|
2983
3002
|
};
|
|
2984
3003
|
})))
|
|
2985
3004
|
.filter(Boolean);
|
|
2986
|
-
const settings = llmService.getSettings();
|
|
3005
|
+
const settings = withResolvedApiKey(llmService.getSettings());
|
|
2987
3006
|
const { personaAgents, capability, identityName } = turnAgents;
|
|
2988
3007
|
let personaPreamble = '';
|
|
2989
3008
|
if (personaAgents.length === 1) {
|
|
@@ -3695,7 +3714,7 @@ export class LocalBackendRouter {
|
|
|
3695
3714
|
emit(this.sse('error', { message: 'coreloop enabled but sidecar is not running' }));
|
|
3696
3715
|
return { status: 503 };
|
|
3697
3716
|
}
|
|
3698
|
-
const settings = llmService.getSettings();
|
|
3717
|
+
const settings = withResolvedApiKey(llmService.getSettings());
|
|
3699
3718
|
const PLACEHOLDER_MODELS = new Set(['default', 'auto', '', 'undefined', 'null']);
|
|
3700
3719
|
const rawModel = typeof payload.model === 'string' ? payload.model.trim() : '';
|
|
3701
3720
|
const overrideModel = PLACEHOLDER_MODELS.has(rawModel) ? undefined : rawModel;
|
package/dist/sidecar/boot.js
CHANGED
|
@@ -21,6 +21,7 @@ import { WEB_TOOL_RPC_TIMEOUT_MS, webToolsEnabled } from '../tool-router.js';
|
|
|
21
21
|
import { sidecarWebSearchEnv } from '../storage/web-search-settings.js';
|
|
22
22
|
import { executeHostedWebSearch } from '../hosted-web-search.js';
|
|
23
23
|
import { getProductConfig } from '../product-config.js';
|
|
24
|
+
import { resolvePlatformRuntime } from '@steerable/agent-runtime';
|
|
24
25
|
let egressProxyRef = null;
|
|
25
26
|
let supervisorRef = null;
|
|
26
27
|
let sidecarGeneration = 0;
|
|
@@ -145,8 +146,11 @@ async function startEgressProxyIfEnabled(store) {
|
|
|
145
146
|
const executable = await ensureEgressProxyExecutable(path.dirname(fileURLToPath(import.meta.url)));
|
|
146
147
|
if (!executable) {
|
|
147
148
|
log.warn('[egress-proxy] steerable-egress-proxy binary was not found; staying on port-level enforcement');
|
|
149
|
+
// Degraded, not disabled: the user's host allow-list is not enforced by
|
|
150
|
+
// domain any more. Recorded so the CLI can warn on the first line of run.
|
|
148
151
|
recordEgressPosture({
|
|
149
152
|
mode: 'port-only-fallback',
|
|
153
|
+
notice: 'egress_proxy_missing',
|
|
150
154
|
reason: '未找到 steerable-egress-proxy 二进制,按主机管控未启用',
|
|
151
155
|
});
|
|
152
156
|
return null;
|
|
@@ -251,6 +255,20 @@ export async function wirePluginRegistry(supervisor, toolRouter) {
|
|
|
251
255
|
}));
|
|
252
256
|
await toolRouter.refreshPluginTools();
|
|
253
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* Interpreter for `run_code` programs: explicit `STEERABLE_PYTHON` →
|
|
260
|
+
* platform package → null (the tool stays unavailable).
|
|
261
|
+
*
|
|
262
|
+
* The platform package ships the same interpreter the sidecar uses, so an
|
|
263
|
+
* installed CLI gets `run_code` without a second setup step.
|
|
264
|
+
*/
|
|
265
|
+
function resolveRunCodePython() {
|
|
266
|
+
const explicit = process.env.STEERABLE_PYTHON?.trim();
|
|
267
|
+
if (explicit)
|
|
268
|
+
return explicit;
|
|
269
|
+
const platform = resolvePlatformRuntime();
|
|
270
|
+
return platform.kind === 'ok' ? platform.runtime.runCodePython : undefined;
|
|
271
|
+
}
|
|
254
272
|
/**
|
|
255
273
|
* The complete Python sidecar hosts the Rust CoreLoop and is mandatory.
|
|
256
274
|
* Boot is registered synchronously so early RPC thin clients (skill-loader
|
|
@@ -259,7 +277,7 @@ export async function wirePluginRegistry(supervisor, toolRouter) {
|
|
|
259
277
|
export async function startHostSidecar(deps) {
|
|
260
278
|
hostSidecarDeps = deps;
|
|
261
279
|
const generation = ++sidecarGeneration;
|
|
262
|
-
const pythonRunner =
|
|
280
|
+
const pythonRunner = resolveRunCodePython();
|
|
263
281
|
const runCodeEnabled = true;
|
|
264
282
|
// ready 后的完整接线:注册全局 handle + reverse channels + web 工具握手。
|
|
265
283
|
// 正常 boot 路径与「boot 失败后后台 restart 迟到就绪」路径共用。
|
|
@@ -104,11 +104,27 @@ export declare function verifiedCachedEgress(cacheDir: string, version: string,
|
|
|
104
104
|
/** Download the artifact-lock egress binary. Returns the printed path, or null. */
|
|
105
105
|
export declare function downloadPublishedEgress(repoRoot: string, cacheDir: string): Promise<string | null>;
|
|
106
106
|
/**
|
|
107
|
-
* Env override, then
|
|
108
|
-
* whose SHA-256 still matches, then the verified
|
|
109
|
-
* A missing binary stays null so boot can fall back to
|
|
107
|
+
* Env override, then the platform npm package, then a locally built private
|
|
108
|
+
* binary, then a cached copy whose SHA-256 still matches, then the verified
|
|
109
|
+
* public Release asset. A missing binary stays null so boot can fall back to
|
|
110
|
+
* port-level rules.
|
|
111
|
+
*
|
|
112
|
+
* The platform package comes before the in-repo build so an installed CLI
|
|
113
|
+
* enforces host-level egress rules without a framework checkout. Callers that
|
|
114
|
+
* treat a missing proxy as a degraded posture must say so; see
|
|
115
|
+
* {@link egressProxyMissingWarning}.
|
|
110
116
|
*/
|
|
111
117
|
export declare function ensureEgressProxyExecutable(startDir: string, download?: (repoRoot: string, cacheDir: string) => Promise<string | null>, cacheDir?: string): Promise<string | null>;
|
|
118
|
+
/**
|
|
119
|
+
* One-line warning for a host running without the egress proxy.
|
|
120
|
+
*
|
|
121
|
+
* Without it the sandbox still confines writes, but network rules fall back
|
|
122
|
+
* to port-level filtering, so a host allow-list becomes "any host on 443".
|
|
123
|
+
* That is a posture change the user has to hear about, not a `doctor` detail.
|
|
124
|
+
*
|
|
125
|
+
* @returns The warning text, including the supported fix.
|
|
126
|
+
*/
|
|
127
|
+
export declare function egressProxyMissingWarning(): string;
|
|
112
128
|
export declare function buildEgressProxyPlan(options: {
|
|
113
129
|
executable: string;
|
|
114
130
|
port: number;
|
|
@@ -160,6 +176,8 @@ export interface EgressPosture {
|
|
|
160
176
|
mode: 'per-host-proxy' | 'port-only-fallback' | 'disabled';
|
|
161
177
|
/** 退回/关闭的原因(人可读,一行)。per-host-proxy 时为 null。 */
|
|
162
178
|
reason: string | null;
|
|
179
|
+
/** 需要用户当场知道的降级,用来决定 CLI 首行警告。 */
|
|
180
|
+
notice?: 'egress_proxy_missing';
|
|
163
181
|
}
|
|
164
182
|
export declare function recordEgressPosture(posture: EgressPosture): void;
|
|
165
183
|
/**
|
|
@@ -25,6 +25,7 @@ import os from 'node:os';
|
|
|
25
25
|
import path from 'node:path';
|
|
26
26
|
import { defaultSearchBaseUrl } from '../storage/web-search-settings.js';
|
|
27
27
|
import { resolveSidecarPython } from './supervisor.js';
|
|
28
|
+
import { resolvePlatformRuntime } from '@steerable/agent-runtime';
|
|
28
29
|
/**
|
|
29
30
|
* `baseUrl` 对应的允许条目形态:裸主机(框架侧隐含 443/80)或 `host:port`。
|
|
30
31
|
*
|
|
@@ -231,14 +232,23 @@ export function downloadPublishedEgress(repoRoot, cacheDir) {
|
|
|
231
232
|
});
|
|
232
233
|
}
|
|
233
234
|
/**
|
|
234
|
-
* Env override, then
|
|
235
|
-
* whose SHA-256 still matches, then the verified
|
|
236
|
-
* A missing binary stays null so boot can fall back to
|
|
235
|
+
* Env override, then the platform npm package, then a locally built private
|
|
236
|
+
* binary, then a cached copy whose SHA-256 still matches, then the verified
|
|
237
|
+
* public Release asset. A missing binary stays null so boot can fall back to
|
|
238
|
+
* port-level rules.
|
|
239
|
+
*
|
|
240
|
+
* The platform package comes before the in-repo build so an installed CLI
|
|
241
|
+
* enforces host-level egress rules without a framework checkout. Callers that
|
|
242
|
+
* treat a missing proxy as a degraded posture must say so; see
|
|
243
|
+
* {@link egressProxyMissingWarning}.
|
|
237
244
|
*/
|
|
238
245
|
export async function ensureEgressProxyExecutable(startDir, download = downloadPublishedEgress, cacheDir = egressBinaryCacheDir()) {
|
|
239
246
|
const fromEnv = resolveEgressProxyExecutable();
|
|
240
247
|
if (fromEnv)
|
|
241
248
|
return fromEnv;
|
|
249
|
+
const platform = resolvePlatformRuntime();
|
|
250
|
+
if (platform.kind === 'ok' && platform.runtime.egressProxy)
|
|
251
|
+
return platform.runtime.egressProxy;
|
|
242
252
|
const repoRoot = findFrameworkRoot(startDir);
|
|
243
253
|
if (!repoRoot)
|
|
244
254
|
return null;
|
|
@@ -255,6 +265,19 @@ export async function ensureEgressProxyExecutable(startDir, download = downloadP
|
|
|
255
265
|
const downloaded = await download(repoRoot, cacheDir);
|
|
256
266
|
return downloaded && verifiedCachedEgress(cacheDir, version, target);
|
|
257
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* One-line warning for a host running without the egress proxy.
|
|
270
|
+
*
|
|
271
|
+
* Without it the sandbox still confines writes, but network rules fall back
|
|
272
|
+
* to port-level filtering, so a host allow-list becomes "any host on 443".
|
|
273
|
+
* That is a posture change the user has to hear about, not a `doctor` detail.
|
|
274
|
+
*
|
|
275
|
+
* @returns The warning text, including the supported fix.
|
|
276
|
+
*/
|
|
277
|
+
export function egressProxyMissingWarning() {
|
|
278
|
+
return ('警告:未找到出口代理,网络只按端口放行,不按域名过滤。' +
|
|
279
|
+
'修复:npm install -g @steerable/agent-cli --include=optional,或设置 STEERABLE_EGRESS_PROXY_BIN。');
|
|
280
|
+
}
|
|
258
281
|
export function buildEgressProxyPlan(options) {
|
|
259
282
|
const { executable, port, providerBaseUrl, providerApiKey } = options;
|
|
260
283
|
const proxiedHosts = [];
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import { spawn } from 'node:child_process';
|
|
18
18
|
import { existsSync } from 'node:fs';
|
|
19
|
+
import { resolvePlatformRuntime } from '@steerable/agent-runtime';
|
|
19
20
|
import { dirname, join } from 'node:path';
|
|
20
21
|
import { fileURLToPath } from 'node:url';
|
|
21
22
|
import { createInterface } from 'node:readline';
|
|
@@ -34,11 +35,17 @@ export function resolveWinSpawnHelperPath() {
|
|
|
34
35
|
return override && existsSync(override) ? override : null;
|
|
35
36
|
}
|
|
36
37
|
// Packaged desktop hosts pass the bundled helper through the override.
|
|
37
|
-
// npm-published shell cannot see the host checkout via __dirname
|
|
38
|
+
// npm-published shell cannot see the host checkout via __dirname, so the
|
|
39
|
+
// platform runtime package is consulted next: it is the only place a global
|
|
40
|
+
// install can ship the helper.
|
|
38
41
|
const candidates = [
|
|
39
42
|
join(process.cwd(), 'resources', 'windows-spawn-helper', binary),
|
|
40
43
|
join(__dirname, '..', '..', 'resources', 'windows-spawn-helper', binary),
|
|
41
44
|
];
|
|
45
|
+
const platform = resolvePlatformRuntime();
|
|
46
|
+
if (platform.kind === 'ok' && platform.runtime.winSpawnHelper) {
|
|
47
|
+
candidates.push(platform.runtime.winSpawnHelper);
|
|
48
|
+
}
|
|
42
49
|
for (const candidate of candidates) {
|
|
43
50
|
if (existsSync(candidate))
|
|
44
51
|
return candidate;
|
|
@@ -215,10 +215,32 @@ export declare class SidecarSupervisor extends EventEmitter {
|
|
|
215
215
|
private failPending;
|
|
216
216
|
private resolvePythonBinary;
|
|
217
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Why the sidecar interpreter could not be located. The CLI turns this into
|
|
220
|
+
* actionable text and exit code 78 rather than printing a stack trace.
|
|
221
|
+
*/
|
|
222
|
+
export declare class SidecarRuntimeMissingError extends Error {
|
|
223
|
+
readonly reason: 'not_installed' | 'unsupported_platform' | 'invalid_manifest' | 'digest_mismatch';
|
|
224
|
+
readonly target: string | null;
|
|
225
|
+
readonly detail: string;
|
|
226
|
+
constructor(failure: {
|
|
227
|
+
reason: 'not_installed' | 'unsupported_platform' | 'invalid_manifest' | 'digest_mismatch';
|
|
228
|
+
target: string | null;
|
|
229
|
+
detail: string;
|
|
230
|
+
});
|
|
231
|
+
}
|
|
218
232
|
/**
|
|
219
233
|
* Resolve the sidecar's Python interpreter: explicit option →
|
|
220
|
-
* STEERABLE_SIDECAR_PYTHON → bundled python-runtime →
|
|
221
|
-
* venv (dev layout)
|
|
222
|
-
*
|
|
234
|
+
* STEERABLE_SIDECAR_PYTHON → bundled python-runtime → platform npm package →
|
|
235
|
+
* sibling framework venv (dev layout).
|
|
236
|
+
*
|
|
237
|
+
* The platform package sits after the bundled resources so a desktop product's
|
|
238
|
+
* vendored runtime keeps winning, and before the dev venv so an installed CLI
|
|
239
|
+
* works without a framework checkout.
|
|
240
|
+
*
|
|
241
|
+
* Module-level so the egress-proxy launcher (W1.3.3) spawns the same
|
|
242
|
+
* interpreter the sidecar uses.
|
|
243
|
+
*
|
|
244
|
+
* @throws {SidecarRuntimeMissingError} When no candidate exists, naming the reason.
|
|
223
245
|
*/
|
|
224
246
|
export declare function resolveSidecarPython(pythonExecutable?: string): string;
|
|
@@ -19,6 +19,8 @@ import { promisify } from 'node:util';
|
|
|
19
19
|
const __filename = fileURLToPath(import.meta.url);
|
|
20
20
|
const __dirname = dirname(__filename);
|
|
21
21
|
import { resolveWinSpawnHelperPath } from './reverse-spawn.js';
|
|
22
|
+
import { resolvePlatformRuntime } from '@steerable/agent-runtime';
|
|
23
|
+
import { bundledRuntimeTag } from '@steerable/agent-protocol';
|
|
22
24
|
import { SidecarBootError, SidecarMethodError, SidecarSandboxUnavailableError, SidecarShutdownError, } from './errors.js';
|
|
23
25
|
const READY_PREFIX = '__SIDECAR_READY__:';
|
|
24
26
|
const DEFAULT_BOOT_TIMEOUT_MS = 15_000;
|
|
@@ -914,11 +916,41 @@ export class SidecarSupervisor extends EventEmitter {
|
|
|
914
916
|
return resolveSidecarPython(this.options.pythonExecutable);
|
|
915
917
|
}
|
|
916
918
|
}
|
|
919
|
+
/**
|
|
920
|
+
* Why the sidecar interpreter could not be located. The CLI turns this into
|
|
921
|
+
* actionable text and exit code 78 rather than printing a stack trace.
|
|
922
|
+
*/
|
|
923
|
+
export class SidecarRuntimeMissingError extends Error {
|
|
924
|
+
reason;
|
|
925
|
+
target;
|
|
926
|
+
detail;
|
|
927
|
+
constructor(failure) {
|
|
928
|
+
super(failure.reason === 'unsupported_platform'
|
|
929
|
+
? `Steerable publishes no runtime bundle for ${failure.detail}`
|
|
930
|
+
: failure.reason === 'digest_mismatch'
|
|
931
|
+
? `platform runtime file does not match its published digest: ${failure.detail}`
|
|
932
|
+
: failure.reason === 'invalid_manifest'
|
|
933
|
+
? `platform runtime descriptor is unusable: ${failure.detail}`
|
|
934
|
+
: `platform runtime package is not installed: ${failure.detail}`);
|
|
935
|
+
this.name = 'SidecarRuntimeMissingError';
|
|
936
|
+
this.reason = failure.reason;
|
|
937
|
+
this.target = failure.target;
|
|
938
|
+
this.detail = failure.detail;
|
|
939
|
+
}
|
|
940
|
+
}
|
|
917
941
|
/**
|
|
918
942
|
* Resolve the sidecar's Python interpreter: explicit option →
|
|
919
|
-
* STEERABLE_SIDECAR_PYTHON → bundled python-runtime →
|
|
920
|
-
* venv (dev layout)
|
|
921
|
-
*
|
|
943
|
+
* STEERABLE_SIDECAR_PYTHON → bundled python-runtime → platform npm package →
|
|
944
|
+
* sibling framework venv (dev layout).
|
|
945
|
+
*
|
|
946
|
+
* The platform package sits after the bundled resources so a desktop product's
|
|
947
|
+
* vendored runtime keeps winning, and before the dev venv so an installed CLI
|
|
948
|
+
* works without a framework checkout.
|
|
949
|
+
*
|
|
950
|
+
* Module-level so the egress-proxy launcher (W1.3.3) spawns the same
|
|
951
|
+
* interpreter the sidecar uses.
|
|
952
|
+
*
|
|
953
|
+
* @throws {SidecarRuntimeMissingError} When no candidate exists, naming the reason.
|
|
922
954
|
*/
|
|
923
955
|
export function resolveSidecarPython(pythonExecutable) {
|
|
924
956
|
if (pythonExecutable) {
|
|
@@ -927,27 +959,29 @@ export function resolveSidecarPython(pythonExecutable) {
|
|
|
927
959
|
const explicit = process.env.STEERABLE_SIDECAR_PYTHON;
|
|
928
960
|
if (explicit && existsSync(explicit))
|
|
929
961
|
return explicit;
|
|
930
|
-
const platformTag = (
|
|
931
|
-
switch (process.platform) {
|
|
932
|
-
case 'darwin':
|
|
933
|
-
return process.arch === 'arm64' ? 'darwin-arm64' : 'darwin-x64';
|
|
934
|
-
case 'win32':
|
|
935
|
-
return 'win32-x64';
|
|
936
|
-
default:
|
|
937
|
-
return 'linux-x64';
|
|
938
|
-
}
|
|
939
|
-
})();
|
|
962
|
+
const platformTag = bundledRuntimeTag(process.platform, process.arch);
|
|
940
963
|
const binaryName = process.platform === 'win32' ? 'python.exe' : 'python3';
|
|
941
964
|
// build_sidecar.py 的产物布局是 <platform>/python/<exe>(Windows:
|
|
942
965
|
// python/python.exe;POSIX:python/bin/python3,见 build_sidecar.py 的
|
|
943
966
|
// python_binary())。保留无 python/ 层的旧布局候选做向后兼容。
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
967
|
+
if (platformTag) {
|
|
968
|
+
const runtimeBase = join(__dirname, '..', '..', 'python-runtime');
|
|
969
|
+
const candidates = [
|
|
970
|
+
join(runtimeBase, platformTag, 'python', binaryName),
|
|
971
|
+
join(runtimeBase, platformTag, 'python', 'bin', binaryName),
|
|
972
|
+
join(runtimeBase, platformTag, binaryName),
|
|
973
|
+
join(runtimeBase, platformTag, 'bin', binaryName),
|
|
974
|
+
];
|
|
975
|
+
for (const candidate of candidates) {
|
|
976
|
+
if (existsSync(candidate))
|
|
977
|
+
return candidate;
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
// Installed CLI: the per-platform npm package carries the same signed
|
|
981
|
+
// bundle the desktop products vendor.
|
|
982
|
+
const platform = resolvePlatformRuntime();
|
|
983
|
+
if (platform.kind === 'ok')
|
|
984
|
+
return platform.runtime.sidecarPython;
|
|
951
985
|
// Dev-layout convenience: the framework repo root .venv (uv sync). The
|
|
952
986
|
// shell lives inside the framework repo (packages/agent-shell/ts), so the
|
|
953
987
|
// venv is an in-repo ancestor — no sibling-checkout probing. Without this,
|
|
@@ -959,19 +993,20 @@ export function resolveSidecarPython(pythonExecutable) {
|
|
|
959
993
|
// 本模块在两个平面执行:源码(vitest,ts/src/sidecar/)与编译产物
|
|
960
994
|
// (ts/dist/sidecar/)——到框架仓库根分别是四层与五层,两个候选都压入,
|
|
961
995
|
// 由下方 existsSync 挑出存在的那个。
|
|
996
|
+
const devCandidates = [];
|
|
962
997
|
for (const up of [
|
|
963
998
|
join('..', '..', '..', '..'),
|
|
964
999
|
join('..', '..', '..', '..', '..'),
|
|
965
1000
|
]) {
|
|
966
1001
|
const frameworkVenv = join(__dirname, up, '.venv');
|
|
967
|
-
|
|
1002
|
+
devCandidates.push(join(frameworkVenv, 'bin', 'python3'));
|
|
968
1003
|
if (process.platform === 'win32') {
|
|
969
|
-
|
|
1004
|
+
devCandidates.push(join(frameworkVenv, 'Scripts', 'python.exe'));
|
|
970
1005
|
}
|
|
971
1006
|
}
|
|
972
|
-
for (const candidate of
|
|
1007
|
+
for (const candidate of devCandidates) {
|
|
973
1008
|
if (existsSync(candidate))
|
|
974
1009
|
return candidate;
|
|
975
1010
|
}
|
|
976
|
-
throw new
|
|
1011
|
+
throw new SidecarRuntimeMissingError(platform);
|
|
977
1012
|
}
|
|
@@ -121,6 +121,54 @@ export declare function llmSettingsMatchOllamaDefaults(s: LlmSettings): boolean;
|
|
|
121
121
|
* `apiKey` the base object happens to carry.
|
|
122
122
|
*/
|
|
123
123
|
export declare function mergeLlmSettings(settings: LlmSettings): LlmSettings;
|
|
124
|
+
/** 环境变量里找到的 key,或配置里存的 key;`not_required` = 本地提供方。 */
|
|
125
|
+
export type ApiKeySource = {
|
|
126
|
+
kind: 'config';
|
|
127
|
+
} | {
|
|
128
|
+
kind: 'env';
|
|
129
|
+
name: string;
|
|
130
|
+
} | {
|
|
131
|
+
kind: 'not_required';
|
|
132
|
+
} | {
|
|
133
|
+
kind: 'missing';
|
|
134
|
+
};
|
|
135
|
+
export interface ResolvedApiKey {
|
|
136
|
+
key: string | null;
|
|
137
|
+
source: ApiKeySource;
|
|
138
|
+
/** 当前提供方按顺序会检查的环境变量名,用于提示文案。 */
|
|
139
|
+
envNames: readonly string[];
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Environment variables consulted for this provider and vendor, in order.
|
|
143
|
+
*
|
|
144
|
+
* @returns Variable names; empty when the provider runs locally and needs no key.
|
|
145
|
+
*/
|
|
146
|
+
export declare function apiKeyEnvNames(settings: Pick<LlmSettings, 'provider' | 'vendorId' | 'baseUrl'>): readonly string[];
|
|
147
|
+
/**
|
|
148
|
+
* Resolves the credential for one turn: stored settings first, then the
|
|
149
|
+
* provider's environment variables.
|
|
150
|
+
*
|
|
151
|
+
* An environment key never reaches storage, so `config get apiKey` can report
|
|
152
|
+
* where a working key came from without copying it into the database.
|
|
153
|
+
*
|
|
154
|
+
* @param settings Current LLM settings.
|
|
155
|
+
* @param env Environment to read; defaults to `process.env`.
|
|
156
|
+
* @returns The key and its source.
|
|
157
|
+
*/
|
|
158
|
+
export declare function resolveApiKey(settings: Pick<LlmSettings, 'provider' | 'vendorId' | 'baseUrl' | 'apiKey'>, env?: Record<string, string | undefined>): ResolvedApiKey;
|
|
159
|
+
/**
|
|
160
|
+
* Applies {@link resolveApiKey} to a settings object.
|
|
161
|
+
*
|
|
162
|
+
* @returns Settings whose `apiKey` is the resolved key (absent when none).
|
|
163
|
+
*/
|
|
164
|
+
export declare function withResolvedApiKey(settings: LlmSettings, env?: Record<string, string | undefined>): LlmSettings;
|
|
165
|
+
/**
|
|
166
|
+
* Masks a key for display: the first three and last four characters survive.
|
|
167
|
+
*
|
|
168
|
+
* @param key The credential, or null/undefined when none is configured.
|
|
169
|
+
* @returns Display text: `sk-…a1b2`, `…12`, or an empty string.
|
|
170
|
+
*/
|
|
171
|
+
export declare function maskApiKey(key: string | null | undefined): string;
|
|
124
172
|
/**
|
|
125
173
|
* 把设置页/POST 体里的 compat 载荷收敛成合法的 `OpenAICompatOverrides`:
|
|
126
174
|
* 只保留框架 `from_dict` 认识的键、按旗标种类校正类型,空数组与非法值
|
|
@@ -187,6 +187,114 @@ export function mergeLlmSettings(settings) {
|
|
|
187
187
|
merged.vendorId = base.vendorId;
|
|
188
188
|
return merged;
|
|
189
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* 环境变量名按提供方声明;openai-compat 的主机区分 DeepSeek 与 OpenAI,
|
|
192
|
+
* 其他网关按先后顺序取第一个有值的。
|
|
193
|
+
*/
|
|
194
|
+
const PROVIDER_API_KEY_ENV = {
|
|
195
|
+
'openai-compat': ['DEEPSEEK_API_KEY', 'OPENAI_API_KEY', 'OPENAI_COMPAT_API_KEY'],
|
|
196
|
+
anthropic: ['ANTHROPIC_API_KEY'],
|
|
197
|
+
google: ['GEMINI_API_KEY'],
|
|
198
|
+
'openai-responses': ['OPENAI_API_KEY'],
|
|
199
|
+
ollama: [],
|
|
200
|
+
};
|
|
201
|
+
const VENDOR_API_KEY_ENV = {
|
|
202
|
+
deepseek: ['DEEPSEEK_API_KEY'],
|
|
203
|
+
openai: ['OPENAI_API_KEY'],
|
|
204
|
+
anthropic: ['ANTHROPIC_API_KEY'],
|
|
205
|
+
google: ['GEMINI_API_KEY'],
|
|
206
|
+
openrouter: ['OPENROUTER_API_KEY'],
|
|
207
|
+
'alibaba-cn': ['DASHSCOPE_API_KEY'],
|
|
208
|
+
'moonshotai-cn': ['MOONSHOT_API_KEY'],
|
|
209
|
+
moonshot: ['MOONSHOT_API_KEY'],
|
|
210
|
+
zhipuai: ['ZHIPU_API_KEY'],
|
|
211
|
+
groq: ['GROQ_API_KEY'],
|
|
212
|
+
xai: ['XAI_API_KEY'],
|
|
213
|
+
lmstudio: ['LMSTUDIO_API_KEY'],
|
|
214
|
+
};
|
|
215
|
+
const LOOPBACK_HOSTS = new Set(['localhost', '127.0.0.1', '::1', '0.0.0.0']);
|
|
216
|
+
function hostnameOf(baseUrl) {
|
|
217
|
+
if (!baseUrl)
|
|
218
|
+
return '';
|
|
219
|
+
try {
|
|
220
|
+
return new URL(baseUrl).hostname.toLowerCase();
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
return '';
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function isLoopback(baseUrl) {
|
|
227
|
+
const host = hostnameOf(baseUrl);
|
|
228
|
+
return host.length > 0 && LOOPBACK_HOSTS.has(host);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Environment variables consulted for this provider and vendor, in order.
|
|
232
|
+
*
|
|
233
|
+
* @returns Variable names; empty when the provider runs locally and needs no key.
|
|
234
|
+
*/
|
|
235
|
+
export function apiKeyEnvNames(settings) {
|
|
236
|
+
if (settings.provider === 'ollama' || isLoopback(settings.baseUrl))
|
|
237
|
+
return [];
|
|
238
|
+
const vendor = settings.vendorId?.trim().toLowerCase();
|
|
239
|
+
const fromVendor = vendor ? VENDOR_API_KEY_ENV[vendor] : undefined;
|
|
240
|
+
if (fromVendor)
|
|
241
|
+
return fromVendor;
|
|
242
|
+
if (settings.provider === 'openai-compat') {
|
|
243
|
+
// A custom gateway keeps the general list; the vendor entry (above) wins
|
|
244
|
+
// when the settings name one.
|
|
245
|
+
return PROVIDER_API_KEY_ENV['openai-compat'];
|
|
246
|
+
}
|
|
247
|
+
return PROVIDER_API_KEY_ENV[settings.provider] ?? [];
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Resolves the credential for one turn: stored settings first, then the
|
|
251
|
+
* provider's environment variables.
|
|
252
|
+
*
|
|
253
|
+
* An environment key never reaches storage, so `config get apiKey` can report
|
|
254
|
+
* where a working key came from without copying it into the database.
|
|
255
|
+
*
|
|
256
|
+
* @param settings Current LLM settings.
|
|
257
|
+
* @param env Environment to read; defaults to `process.env`.
|
|
258
|
+
* @returns The key and its source.
|
|
259
|
+
*/
|
|
260
|
+
export function resolveApiKey(settings, env = process.env) {
|
|
261
|
+
const stored = settings.apiKey?.trim();
|
|
262
|
+
if (stored)
|
|
263
|
+
return { key: stored, source: { kind: 'config' }, envNames: apiKeyEnvNames(settings) };
|
|
264
|
+
const envNames = apiKeyEnvNames(settings);
|
|
265
|
+
if (envNames.length === 0)
|
|
266
|
+
return { key: null, source: { kind: 'not_required' }, envNames };
|
|
267
|
+
for (const name of envNames) {
|
|
268
|
+
const value = env[name]?.trim();
|
|
269
|
+
if (value)
|
|
270
|
+
return { key: value, source: { kind: 'env', name }, envNames };
|
|
271
|
+
}
|
|
272
|
+
return { key: null, source: { kind: 'missing' }, envNames };
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Applies {@link resolveApiKey} to a settings object.
|
|
276
|
+
*
|
|
277
|
+
* @returns Settings whose `apiKey` is the resolved key (absent when none).
|
|
278
|
+
*/
|
|
279
|
+
export function withResolvedApiKey(settings, env = process.env) {
|
|
280
|
+
const resolved = resolveApiKey(settings, env);
|
|
281
|
+
const { apiKey: _stored, ...rest } = settings;
|
|
282
|
+
return resolved.key ? { ...rest, apiKey: resolved.key } : rest;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Masks a key for display: the first three and last four characters survive.
|
|
286
|
+
*
|
|
287
|
+
* @param key The credential, or null/undefined when none is configured.
|
|
288
|
+
* @returns Display text: `sk-…a1b2`, `…12`, or an empty string.
|
|
289
|
+
*/
|
|
290
|
+
export function maskApiKey(key) {
|
|
291
|
+
const value = key?.trim() ?? '';
|
|
292
|
+
if (!value)
|
|
293
|
+
return '';
|
|
294
|
+
if (value.length < 12)
|
|
295
|
+
return `…${value.slice(-2)}`;
|
|
296
|
+
return `${value.slice(0, 3)}…${value.slice(-4)}`;
|
|
297
|
+
}
|
|
190
298
|
const COMPAT_BOOL_KEYS = [
|
|
191
299
|
'supportsUsageInStreaming',
|
|
192
300
|
'supportsReasoningEffort',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
1
|
+
import { chmodSync, existsSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import Database from 'better-sqlite3';
|
|
4
4
|
import { getProductConfig } from '../product-config.js';
|
|
@@ -90,6 +90,32 @@ function blockUpgrade(message) {
|
|
|
90
90
|
queueMicrotask(() => process.exit(75));
|
|
91
91
|
throw new StorageUpgradeBlockedError(message);
|
|
92
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Removes group and other permissions from the database and its WAL files.
|
|
95
|
+
*
|
|
96
|
+
* The settings table stores the provider API key in plain text, so the file is
|
|
97
|
+
* as sensitive as a key file. `-wal` and `-shm` are created lazily by SQLite
|
|
98
|
+
* with the process umask and can hold the same rows, so they are tightened
|
|
99
|
+
* whenever they exist. Windows has no POSIX mode; there the file inherits the
|
|
100
|
+
* user-profile ACL, which already excludes other accounts.
|
|
101
|
+
*
|
|
102
|
+
* @param dbPath Absolute path to the database file.
|
|
103
|
+
*/
|
|
104
|
+
function restrictToOwner(dbPath) {
|
|
105
|
+
if (process.platform === 'win32')
|
|
106
|
+
return;
|
|
107
|
+
for (const suffix of ['', '-wal', '-shm']) {
|
|
108
|
+
const file = `${dbPath}${suffix}`;
|
|
109
|
+
try {
|
|
110
|
+
if (existsSync(file))
|
|
111
|
+
chmodSync(file, 0o600);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
// A read-only or network mount cannot take the mode change. The database
|
|
115
|
+
// still works; the report belongs to the caller that owns the volume.
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
93
119
|
/** Default local SQLite storage driver. */
|
|
94
120
|
export class SqliteStorageDriver {
|
|
95
121
|
db = null;
|
|
@@ -145,6 +171,10 @@ export class SqliteStorageDriver {
|
|
|
145
171
|
db.pragma(`busy_timeout = ${MAIN_DB_BUSY_TIMEOUT_MS}`);
|
|
146
172
|
db.pragma('journal_mode = WAL');
|
|
147
173
|
db.pragma('foreign_keys = ON');
|
|
174
|
+
// The settings table holds the provider API key, so the file must not be
|
|
175
|
+
// readable by other local accounts. SQLite creates `-wal` and `-shm`
|
|
176
|
+
// alongside and inherits the process umask, so they are tightened too.
|
|
177
|
+
restrictToOwner(dbPath);
|
|
148
178
|
this.db = db;
|
|
149
179
|
const local = new SqliteScopedStore(db, LOCAL_SCOPE);
|
|
150
180
|
await local.initialize();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steerable/agent-shell",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Steerable framework — product-neutral Node HostRuntime and headless HTTP server shared by Tauri desktop and browser deployments; scenario packs extend it through @steerable/pack-sdk.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://steerableframework.com/",
|
|
@@ -53,9 +53,10 @@
|
|
|
53
53
|
"jpeg-js": "^0.4.4",
|
|
54
54
|
"node-pty": "^1.1.0",
|
|
55
55
|
"pngjs": "^7.0.0",
|
|
56
|
-
"@steerable/agent-harness": "0.
|
|
57
|
-
"@steerable/agent-protocol": "0.
|
|
58
|
-
"@steerable/
|
|
56
|
+
"@steerable/agent-harness": "0.9.1",
|
|
57
|
+
"@steerable/agent-protocol": "0.9.1",
|
|
58
|
+
"@steerable/agent-runtime": "0.9.1",
|
|
59
|
+
"@steerable/pack-sdk": "0.9.1"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
61
62
|
"@types/better-sqlite3": "^7.6.13",
|