@0perator/operator 0.1.284 → 0.1.313
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 +24 -2
- package/dist/acp/agent.js +3 -2
- package/dist/acp/config-options.js +15 -1
- package/dist/acp/tool-map.js +2 -1
- package/dist/auth/commands.js +69 -13
- package/dist/autonomy/agent-cli.js +304 -0
- package/dist/autonomy/cloud-agent.js +439 -0
- package/dist/autonomy/cron-lifecycle.js +78 -0
- package/dist/autonomy/cron-lock.js +121 -0
- package/dist/autonomy/cron.js +216 -43
- package/dist/autonomy/delegate.js +5 -1
- package/dist/autonomy/incidents.js +135 -0
- package/dist/autonomy/session-factory.js +25 -16
- package/dist/background/index.js +40 -0
- package/dist/bus/inbox.js +20 -0
- package/dist/classifier/config.js +47 -0
- package/dist/classifier/modes.js +41 -0
- package/dist/classifier/types.js +1 -0
- package/dist/cli.js +529 -53
- package/dist/config/features.js +69 -0
- package/dist/config/persona.js +118 -99
- package/dist/config/scaffold.js +15 -0
- package/dist/config/settings.js +96 -6
- package/dist/consolidation/sleep.js +73 -11
- package/dist/engine/agent.js +275 -18
- package/dist/engine/anthropic-chat.js +343 -0
- package/dist/engine/aurora.js +101 -13
- package/dist/engine/batch-scheduler.js +41 -9
- package/dist/engine/classifier.js +85 -0
- package/dist/engine/compaction.js +24 -5
- package/dist/engine/fast-start.js +25 -0
- package/dist/engine/loop-guard.js +448 -0
- package/dist/engine/moa.js +5 -1
- package/dist/engine/net-error.js +24 -0
- package/dist/engine/repetition-guard.js +180 -0
- package/dist/engine/selfheal.js +8 -0
- package/dist/engine/toolcalls.js +51 -1
- package/dist/engine/verify-gate.js +2 -0
- package/dist/flywheel/processor.js +78 -31
- package/dist/flywheel/srft.js +13 -0
- package/dist/hooks/index.js +196 -0
- package/dist/mcp/config.js +21 -1
- package/dist/memory/index.js +0 -0
- package/dist/memory/providers.js +210 -0
- package/dist/memory/session-catalog.js +422 -0
- package/dist/memory/session-providers.js +121 -0
- package/dist/memory/session-sources.js +335 -0
- package/dist/memory/skylark.js +131 -0
- package/dist/models/bench.js +103 -0
- package/dist/models/registry.js +144 -0
- package/dist/models/switch.js +69 -0
- package/dist/observability/blackbox.js +37 -0
- package/dist/permissions/policy.js +31 -6
- package/dist/router/discovery.js +127 -0
- package/dist/router/models.js +117 -24
- package/dist/router/portal.js +100 -0
- package/dist/router/router.js +1 -1
- package/dist/services/preflight.js +55 -7
- package/dist/session.js +316 -46
- package/dist/tools/chauffeur.js +12 -0
- package/dist/tools/executor.js +19 -9
- package/dist/tools/find-files.js +483 -0
- package/dist/tools/git-pr.js +94 -0
- package/dist/tools/incident-tools.js +82 -0
- package/dist/tools/memory.js +12 -2
- package/dist/tools/registry.js +281 -85
- package/dist/tools/semantic-compress.js +124 -0
- package/dist/tools/shell-context.js +1 -0
- package/dist/tools/shell-jobs.js +160 -0
- package/dist/tools/shell-session.js +170 -4
- package/dist/tools/wave-tools.js +609 -0
- package/dist/tools/wave2-tools.js +411 -0
- package/dist/ui/App.js +15 -4
- package/dist/ui/BgPanel.js +30 -6
- package/dist/ui/Composer.js +11 -1
- package/dist/ui/QuestionPrompt.js +31 -11
- package/dist/ui/SessionPicker.js +86 -0
- package/dist/ui/StatusRule.js +5 -5
- package/dist/ui/ToolStep.js +2 -1
- package/dist/ui/Transcript.js +17 -1
- package/dist/ui/index.js +1 -1
- package/dist/ui/liveTools.js +21 -3
- package/dist/ui/slashCommands.js +2 -0
- package/dist/util/screenshots.js +74 -8
- package/dist/util/slash.js +2 -2
- package/package.json +8 -2
- package/dist/engine/cli.js +0 -1171
- package/dist/router/models.js.bak +0 -78
- package/dist/router/models.js.bak-1791259923 +0 -78
- package/dist/router/models.js.bak-pre-gateway +0 -78
- package/dist/router/models.js.bak-pre-patch2 +0 -78
- package/dist/router/models.js.bak2 +0 -78
- package/dist/services/model-autodetect.js +0 -240
- package/dist/tools/native-redirect.js +0 -140
- package/dist/tools/power-tools.js +0 -627
- package/dist/tools/registry.js.bak-1791259948 +0 -1914
- package/dist/tools/registry.js.bak-pre-plugins +0 -1914
- package/dist/ui/BusTray.js +0 -70
- package/dist/ui/resize.js +0 -160
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
export const DEFAULT_MODEL_ID = "operator-1m";
|
|
2
|
-
// Back-compat aliases: the user-facing ids were renamed aurora-* -> operator-* (the outward name is
|
|
3
|
-
// Operator; "aurora" is the internal model, never shown). The OLD ids still resolve — a persisted
|
|
4
|
-
// settings.activeModel: "aurora-1m", a `/model aurora-1m`, or any muscle memory keeps working — so the
|
|
5
|
-
// rename loses nothing. The served model name ("aurora-code-1") + endpoints stay internal, untouched.
|
|
6
|
-
export const MODEL_ALIASES = {
|
|
7
|
-
"aurora-1m": "operator-1m",
|
|
8
|
-
"aurora-128k": "operator-128k",
|
|
9
|
-
};
|
|
10
|
-
export const BUILTIN_MODELS = [
|
|
11
|
-
{ id: "operator-1m", label: "Operator 300K", kind: "single", desc: "307,200-token (300K) context (:8097)", endpoint: "http://127.0.0.1:8097/v1", model: "aurora-code-1", ctx: 307200 },
|
|
12
|
-
{ id: "operator-128k", label: "Operator 128K", kind: "single", desc: "128K context, lighter RAM (:8096)", endpoint: "http://127.0.0.1:8096/v1", model: "aurora-code-1", ctx: 131072 },
|
|
13
|
-
// QwenCloud Token Plan BYO connectors (SPEC/providers.md §2 "API-key connectors"). Same keychain
|
|
14
|
-
// account ("qwen") serves both; the picker hides them until connected (§1 honest availability), and
|
|
15
|
-
// authHeaders NEVER sends the Operator token to this host. ctx starts conservative and self-clamps
|
|
16
|
-
// to the served truth (observeContext).
|
|
17
|
-
{ id: "qwen3.8-max", label: "Qwen 3.8 Max", kind: "single", desc: "BYO QwenCloud Token Plan — credits from your plan", endpoint: "https://token-plan.maas.qwencloudapi.com/compatible-mode/v1", model: "qwen3.8-max", ctx: 262144, byo: "qwen", transport: "openai" },
|
|
18
|
-
{ id: "qwen3.8-flash", label: "Qwen 3.8 Flash", kind: "single", desc: "BYO QwenCloud Token Plan — fast tier, your credits", endpoint: "https://token-plan.maas.qwencloudapi.com/compatible-mode/v1", model: "qwen3.8-flash", ctx: 262144, byo: "qwen", transport: "openai" },
|
|
19
|
-
// Venice 24B — SELF-HOSTED like Aurora (NOT a third-party connector): the open uncensored weights
|
|
20
|
-
// (Dolphin-Mistral-24B-Venice-Edition Q4_K_M, JL1 Ai Storage) served via llama.cpp on JL1:8110, bound
|
|
21
|
-
// 0.0.0.0 so the engine (on JL2) reaches it over LAN. Uncensored at the weights — answers directly, no
|
|
22
|
-
// retry needed; complements the engine-level unrestricted layer. Runs ALONGSIDE Aurora (:8097); the
|
|
23
|
-
// llama.cpp router health-checks + recovers, and ctx self-clamps to the served truth (observeContext).
|
|
24
|
-
{ id: "venice-24b", label: "Venice 24B (uncensored)", kind: "single", desc: "self-hosted uncensored Dolphin-Mistral-24B-Venice (fleet llama.cpp, JL1:8110)", endpoint: "http://192.168.1.103:8110/v1", model: "dolphin-venice-24b", ctx: 8192 },
|
|
25
|
-
{ id: "moa", label: "MOA (Mixture of Agents)", kind: "orchestrated", desc: "fan out to proposers, synthesize with an aggregator" },
|
|
26
|
-
];
|
|
27
|
-
/** The runtime registry: the built-ins, with any settings.models entries merged in (overriding a
|
|
28
|
-
* built-in by id, or adding a new one) — same shape either way, so /model doesn't care which. */
|
|
29
|
-
export function modelRegistry(overrides) {
|
|
30
|
-
if (!overrides?.length)
|
|
31
|
-
return BUILTIN_MODELS;
|
|
32
|
-
const byId = new Map(BUILTIN_MODELS.map((m) => [m.id, m]));
|
|
33
|
-
for (const m of overrides)
|
|
34
|
-
byId.set(m.id, { ...byId.get(m.id), ...m });
|
|
35
|
-
return [...byId.values()];
|
|
36
|
-
}
|
|
37
|
-
export function findModel(registry, id) {
|
|
38
|
-
const canon = MODEL_ALIASES[id] ?? id; // aurora-1m -> operator-1m (old ids keep resolving)
|
|
39
|
-
return registry.find((m) => m.id === canon);
|
|
40
|
-
}
|
|
41
|
-
/** The configured context window (tokens) for a model id — from BUILTIN_MODELS + settings overrides — or
|
|
42
|
-
* Infinity if unknown. Used to pick a LEAN harness: a small-context model (e.g. a self-hosted 8K Venice)
|
|
43
|
-
* can't take Operator's full memory + handoff injection (sized for Aurora's 300K); it fills the window and
|
|
44
|
-
* the model recites the memory instead of answering. Callers drop the heavy memory/handoff below a
|
|
45
|
-
* threshold while keeping the base persona (incl. the Direct/unrestricted section), so it stays uncensored. */
|
|
46
|
-
export function modelCtxFor(id, overrides) {
|
|
47
|
-
if (!id)
|
|
48
|
-
return Number.POSITIVE_INFINITY;
|
|
49
|
-
return findModel(modelRegistry(overrides), id)?.ctx ?? Number.POSITIVE_INFINITY;
|
|
50
|
-
}
|
|
51
|
-
/** ctx window below which the lean harness (no heavy memory/handoff) kicks in. Aurora/Qwen (128K+) stay
|
|
52
|
-
* full; a self-hosted small model (Venice 8K, or a 16K bump) goes lean. */
|
|
53
|
-
export const LEAN_HARNESS_CTX = 32768;
|
|
54
|
-
/** Pure selection reducer for /model — no I/O (no settings read/write, no router mutation), so it's
|
|
55
|
-
* directly testable. The moa-needs-config check lives in Session.setModel (it needs settings.moa,
|
|
56
|
-
* which this module intentionally doesn't import). `hasByo` (injected by the caller, see auth/byo)
|
|
57
|
-
* gates BYO connector profiles: honest "not connected" beats a request-time 401. */
|
|
58
|
-
export function selectModel(registry, id, hasByo) {
|
|
59
|
-
const profile = findModel(registry, id);
|
|
60
|
-
if (!profile)
|
|
61
|
-
return { error: `unknown model "${id}" — choices: ${registry.map((m) => m.id).join(", ")}` };
|
|
62
|
-
if (profile.kind === "single" && !profile.endpoint)
|
|
63
|
-
return { error: `model "${id}" has no endpoint configured` };
|
|
64
|
-
if (profile.byo && hasByo && !hasByo(profile.byo)) {
|
|
65
|
-
return { error: `"${id}" is not connected — store the ${profile.byo} key first: operator auth byo ${profile.byo}` };
|
|
66
|
-
}
|
|
67
|
-
return { profile };
|
|
68
|
-
}
|
|
69
|
-
/** The picker-truth view of a registry: drops BYO profiles whose key isn't connected (and ALL
|
|
70
|
-
* unresolvable ones when the resolver is absent — a picker must never offer what setModel refuses). */
|
|
71
|
-
export function visibleModels(registry, hasByo) {
|
|
72
|
-
return registry.filter((p) => !p.byo || (hasByo ? hasByo(p.byo) : false));
|
|
73
|
-
}
|
|
74
|
-
/** Strip a trailing /v1 so a ModelProfile/MoaAggregator endpoint can feed the AuroraRouter, whose
|
|
75
|
-
* base is bare (engine/aurora.ts's chat() appends /v1/chat/completions itself). */
|
|
76
|
-
export function endpointBase(endpoint) {
|
|
77
|
-
return endpoint.replace(/\/v1\/?$/, "");
|
|
78
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
export const DEFAULT_MODEL_ID = "operator-1m";
|
|
2
|
-
// Back-compat aliases: the user-facing ids were renamed aurora-* -> operator-* (the outward name is
|
|
3
|
-
// Operator; "aurora" is the internal model, never shown). The OLD ids still resolve — a persisted
|
|
4
|
-
// settings.activeModel: "aurora-1m", a `/model aurora-1m`, or any muscle memory keeps working — so the
|
|
5
|
-
// rename loses nothing. The served model name ("aurora-code-1") + endpoints stay internal, untouched.
|
|
6
|
-
export const MODEL_ALIASES = {
|
|
7
|
-
"aurora-1m": "operator-1m",
|
|
8
|
-
"aurora-128k": "operator-128k",
|
|
9
|
-
};
|
|
10
|
-
export const BUILTIN_MODELS = [
|
|
11
|
-
{ id: "operator-1m", label: "Operator 300K", kind: "single", desc: "307,200-token (300K) context (:8097)", endpoint: "http://127.0.0.1:8097/v1", model: "aurora-code-1", ctx: 307200 },
|
|
12
|
-
{ id: "operator-128k", label: "Operator 128K", kind: "single", desc: "128K context, lighter RAM (:8096)", endpoint: "http://127.0.0.1:8096/v1", model: "aurora-code-1", ctx: 131072 },
|
|
13
|
-
// QwenCloud Token Plan BYO connectors (SPEC/providers.md §2 "API-key connectors"). Same keychain
|
|
14
|
-
// account ("qwen") serves both; the picker hides them until connected (§1 honest availability), and
|
|
15
|
-
// authHeaders NEVER sends the Operator token to this host. ctx starts conservative and self-clamps
|
|
16
|
-
// to the served truth (observeContext).
|
|
17
|
-
{ id: "qwen3.8-max", label: "Qwen 3.8 Max", kind: "single", desc: "BYO QwenCloud Token Plan — credits from your plan", endpoint: "https://token-plan.maas.qwencloudapi.com/compatible-mode/v1", model: "qwen3.8-max", ctx: 262144, byo: "qwen", transport: "openai" },
|
|
18
|
-
{ id: "qwen3.8-flash", label: "Qwen 3.8 Flash", kind: "single", desc: "BYO QwenCloud Token Plan — fast tier, your credits", endpoint: "https://token-plan.maas.qwencloudapi.com/compatible-mode/v1", model: "qwen3.8-flash", ctx: 262144, byo: "qwen", transport: "openai" },
|
|
19
|
-
// Venice 24B — SELF-HOSTED like Aurora (NOT a third-party connector): the open uncensored weights
|
|
20
|
-
// (Dolphin-Mistral-24B-Venice-Edition Q4_K_M, JL1 Ai Storage) served via llama.cpp on JL1:8110, bound
|
|
21
|
-
// 0.0.0.0 so the engine (on JL2) reaches it over LAN. Uncensored at the weights — answers directly, no
|
|
22
|
-
// retry needed; complements the engine-level unrestricted layer. Runs ALONGSIDE Aurora (:8097); the
|
|
23
|
-
// llama.cpp router health-checks + recovers, and ctx self-clamps to the served truth (observeContext).
|
|
24
|
-
{ id: "venice-24b", label: "Venice 24B (uncensored)", kind: "single", desc: "self-hosted uncensored Dolphin-Mistral-24B-Venice (fleet llama.cpp, JL1:8110)", endpoint: "http://192.168.1.103:8110/v1", model: "dolphin-venice-24b", ctx: 8192 },
|
|
25
|
-
{ id: "moa", label: "MOA (Mixture of Agents)", kind: "orchestrated", desc: "fan out to proposers, synthesize with an aggregator" },
|
|
26
|
-
];
|
|
27
|
-
/** The runtime registry: the built-ins, with any settings.models entries merged in (overriding a
|
|
28
|
-
* built-in by id, or adding a new one) — same shape either way, so /model doesn't care which. */
|
|
29
|
-
export function modelRegistry(overrides) {
|
|
30
|
-
if (!overrides?.length)
|
|
31
|
-
return BUILTIN_MODELS;
|
|
32
|
-
const byId = new Map(BUILTIN_MODELS.map((m) => [m.id, m]));
|
|
33
|
-
for (const m of overrides)
|
|
34
|
-
byId.set(m.id, { ...byId.get(m.id), ...m });
|
|
35
|
-
return [...byId.values()];
|
|
36
|
-
}
|
|
37
|
-
export function findModel(registry, id) {
|
|
38
|
-
const canon = MODEL_ALIASES[id] ?? id; // aurora-1m -> operator-1m (old ids keep resolving)
|
|
39
|
-
return registry.find((m) => m.id === canon);
|
|
40
|
-
}
|
|
41
|
-
/** The configured context window (tokens) for a model id — from BUILTIN_MODELS + settings overrides — or
|
|
42
|
-
* Infinity if unknown. Used to pick a LEAN harness: a small-context model (e.g. a self-hosted 8K Venice)
|
|
43
|
-
* can't take Operator's full memory + handoff injection (sized for Aurora's 300K); it fills the window and
|
|
44
|
-
* the model recites the memory instead of answering. Callers drop the heavy memory/handoff below a
|
|
45
|
-
* threshold while keeping the base persona (incl. the Direct/unrestricted section), so it stays uncensored. */
|
|
46
|
-
export function modelCtxFor(id, overrides) {
|
|
47
|
-
if (!id)
|
|
48
|
-
return Number.POSITIVE_INFINITY;
|
|
49
|
-
return findModel(modelRegistry(overrides), id)?.ctx ?? Number.POSITIVE_INFINITY;
|
|
50
|
-
}
|
|
51
|
-
/** ctx window below which the lean harness (no heavy memory/handoff) kicks in. Aurora/Qwen (128K+) stay
|
|
52
|
-
* full; a self-hosted small model (Venice 8K, or a 16K bump) goes lean. */
|
|
53
|
-
export const LEAN_HARNESS_CTX = 32768;
|
|
54
|
-
/** Pure selection reducer for /model — no I/O (no settings read/write, no router mutation), so it's
|
|
55
|
-
* directly testable. The moa-needs-config check lives in Session.setModel (it needs settings.moa,
|
|
56
|
-
* which this module intentionally doesn't import). `hasByo` (injected by the caller, see auth/byo)
|
|
57
|
-
* gates BYO connector profiles: honest "not connected" beats a request-time 401. */
|
|
58
|
-
export function selectModel(registry, id, hasByo) {
|
|
59
|
-
const profile = findModel(registry, id);
|
|
60
|
-
if (!profile)
|
|
61
|
-
return { error: `unknown model "${id}" — choices: ${registry.map((m) => m.id).join(", ")}` };
|
|
62
|
-
if (profile.kind === "single" && !profile.endpoint)
|
|
63
|
-
return { error: `model "${id}" has no endpoint configured` };
|
|
64
|
-
if (profile.byo && hasByo && !hasByo(profile.byo)) {
|
|
65
|
-
return { error: `"${id}" is not connected — store the ${profile.byo} key first: operator auth byo ${profile.byo}` };
|
|
66
|
-
}
|
|
67
|
-
return { profile };
|
|
68
|
-
}
|
|
69
|
-
/** The picker-truth view of a registry: drops BYO profiles whose key isn't connected (and ALL
|
|
70
|
-
* unresolvable ones when the resolver is absent — a picker must never offer what setModel refuses). */
|
|
71
|
-
export function visibleModels(registry, hasByo) {
|
|
72
|
-
return registry.filter((p) => !p.byo || (hasByo ? hasByo(p.byo) : false));
|
|
73
|
-
}
|
|
74
|
-
/** Strip a trailing /v1 so a ModelProfile/MoaAggregator endpoint can feed the AuroraRouter, whose
|
|
75
|
-
* base is bare (engine/aurora.ts's chat() appends /v1/chat/completions itself). */
|
|
76
|
-
export function endpointBase(endpoint) {
|
|
77
|
-
return endpoint.replace(/\/v1\/?$/, "");
|
|
78
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
export const DEFAULT_MODEL_ID = "operator-1m";
|
|
2
|
-
// Back-compat aliases: the user-facing ids were renamed aurora-* -> operator-* (the outward name is
|
|
3
|
-
// Operator; "aurora" is the internal model, never shown). The OLD ids still resolve — a persisted
|
|
4
|
-
// settings.activeModel: "aurora-1m", a `/model aurora-1m`, or any muscle memory keeps working — so the
|
|
5
|
-
// rename loses nothing. The served model name ("aurora-code-1") + endpoints stay internal, untouched.
|
|
6
|
-
export const MODEL_ALIASES = {
|
|
7
|
-
"aurora-1m": "operator-1m",
|
|
8
|
-
"aurora-128k": "operator-128k",
|
|
9
|
-
};
|
|
10
|
-
export const BUILTIN_MODELS = [
|
|
11
|
-
{ id: "operator-1m", label: "Operator 300K", kind: "single", desc: "307,200-token (300K) context (:8097)", endpoint: "http://127.0.0.1:8097/v1", model: "aurora-code-1", ctx: 307200 },
|
|
12
|
-
{ id: "operator-128k", label: "Operator 128K", kind: "single", desc: "128K context, lighter RAM (:8096)", endpoint: "http://127.0.0.1:8096/v1", model: "aurora-code-1", ctx: 131072 },
|
|
13
|
-
// QwenCloud Token Plan BYO connectors (SPEC/providers.md §2 "API-key connectors"). Same keychain
|
|
14
|
-
// account ("qwen") serves both; the picker hides them until connected (§1 honest availability), and
|
|
15
|
-
// authHeaders NEVER sends the Operator token to this host. ctx starts conservative and self-clamps
|
|
16
|
-
// to the served truth (observeContext).
|
|
17
|
-
{ id: "qwen3.8-max", label: "Qwen 3.8 Max", kind: "single", desc: "BYO QwenCloud Token Plan — credits from your plan", endpoint: "https://token-plan.maas.qwencloudapi.com/compatible-mode/v1", model: "qwen3.8-max", ctx: 262144, byo: "qwen", transport: "openai" },
|
|
18
|
-
{ id: "qwen3.8-flash", label: "Qwen 3.8 Flash", kind: "single", desc: "BYO QwenCloud Token Plan — fast tier, your credits", endpoint: "https://token-plan.maas.qwencloudapi.com/compatible-mode/v1", model: "qwen3.8-flash", ctx: 262144, byo: "qwen", transport: "openai" },
|
|
19
|
-
// Venice 24B — SELF-HOSTED like Aurora (NOT a third-party connector): the open uncensored weights
|
|
20
|
-
// (Dolphin-Mistral-24B-Venice-Edition Q4_K_M, JL1 Ai Storage) served via llama.cpp on JL1:8110, bound
|
|
21
|
-
// 0.0.0.0 so the engine (on JL2) reaches it over LAN. Uncensored at the weights — answers directly, no
|
|
22
|
-
// retry needed; complements the engine-level unrestricted layer. Runs ALONGSIDE Aurora (:8097); the
|
|
23
|
-
// llama.cpp router health-checks + recovers, and ctx self-clamps to the served truth (observeContext).
|
|
24
|
-
{ id: "venice-24b", label: "Venice 24B (uncensored)", kind: "single", desc: "self-hosted uncensored Dolphin-Mistral-24B-Venice (fleet llama.cpp, JL1:8110)", endpoint: "http://192.168.1.103:8110/v1", model: "dolphin-venice-24b", ctx: 8192 },
|
|
25
|
-
{ id: "moa", label: "MOA (Mixture of Agents)", kind: "orchestrated", desc: "fan out to proposers, synthesize with an aggregator" },
|
|
26
|
-
];
|
|
27
|
-
/** The runtime registry: the built-ins, with any settings.models entries merged in (overriding a
|
|
28
|
-
* built-in by id, or adding a new one) — same shape either way, so /model doesn't care which. */
|
|
29
|
-
export function modelRegistry(overrides) {
|
|
30
|
-
if (!overrides?.length)
|
|
31
|
-
return BUILTIN_MODELS;
|
|
32
|
-
const byId = new Map(BUILTIN_MODELS.map((m) => [m.id, m]));
|
|
33
|
-
for (const m of overrides)
|
|
34
|
-
byId.set(m.id, { ...byId.get(m.id), ...m });
|
|
35
|
-
return [...byId.values()];
|
|
36
|
-
}
|
|
37
|
-
export function findModel(registry, id) {
|
|
38
|
-
const canon = MODEL_ALIASES[id] ?? id; // aurora-1m -> operator-1m (old ids keep resolving)
|
|
39
|
-
return registry.find((m) => m.id === canon);
|
|
40
|
-
}
|
|
41
|
-
/** The configured context window (tokens) for a model id — from BUILTIN_MODELS + settings overrides — or
|
|
42
|
-
* Infinity if unknown. Used to pick a LEAN harness: a small-context model (e.g. a self-hosted 8K Venice)
|
|
43
|
-
* can't take Operator's full memory + handoff injection (sized for Aurora's 300K); it fills the window and
|
|
44
|
-
* the model recites the memory instead of answering. Callers drop the heavy memory/handoff below a
|
|
45
|
-
* threshold while keeping the base persona (incl. the Direct/unrestricted section), so it stays uncensored. */
|
|
46
|
-
export function modelCtxFor(id, overrides) {
|
|
47
|
-
if (!id)
|
|
48
|
-
return Number.POSITIVE_INFINITY;
|
|
49
|
-
return findModel(modelRegistry(overrides), id)?.ctx ?? Number.POSITIVE_INFINITY;
|
|
50
|
-
}
|
|
51
|
-
/** ctx window below which the lean harness (no heavy memory/handoff) kicks in. Aurora/Qwen (128K+) stay
|
|
52
|
-
* full; a self-hosted small model (Venice 8K, or a 16K bump) goes lean. */
|
|
53
|
-
export const LEAN_HARNESS_CTX = 32768;
|
|
54
|
-
/** Pure selection reducer for /model — no I/O (no settings read/write, no router mutation), so it's
|
|
55
|
-
* directly testable. The moa-needs-config check lives in Session.setModel (it needs settings.moa,
|
|
56
|
-
* which this module intentionally doesn't import). `hasByo` (injected by the caller, see auth/byo)
|
|
57
|
-
* gates BYO connector profiles: honest "not connected" beats a request-time 401. */
|
|
58
|
-
export function selectModel(registry, id, hasByo) {
|
|
59
|
-
const profile = findModel(registry, id);
|
|
60
|
-
if (!profile)
|
|
61
|
-
return { error: `unknown model "${id}" — choices: ${registry.map((m) => m.id).join(", ")}` };
|
|
62
|
-
if (profile.kind === "single" && !profile.endpoint)
|
|
63
|
-
return { error: `model "${id}" has no endpoint configured` };
|
|
64
|
-
if (profile.byo && hasByo && !hasByo(profile.byo)) {
|
|
65
|
-
return { error: `"${id}" is not connected — store the ${profile.byo} key first: operator auth byo ${profile.byo}` };
|
|
66
|
-
}
|
|
67
|
-
return { profile };
|
|
68
|
-
}
|
|
69
|
-
/** The picker-truth view of a registry: drops BYO profiles whose key isn't connected (and ALL
|
|
70
|
-
* unresolvable ones when the resolver is absent — a picker must never offer what setModel refuses). */
|
|
71
|
-
export function visibleModels(registry, hasByo) {
|
|
72
|
-
return registry.filter((p) => !p.byo || (hasByo ? hasByo(p.byo) : false));
|
|
73
|
-
}
|
|
74
|
-
/** Strip a trailing /v1 so a ModelProfile/MoaAggregator endpoint can feed the AuroraRouter, whose
|
|
75
|
-
* base is bare (engine/aurora.ts's chat() appends /v1/chat/completions itself). */
|
|
76
|
-
export function endpointBase(endpoint) {
|
|
77
|
-
return endpoint.replace(/\/v1\/?$/, "");
|
|
78
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
export const DEFAULT_MODEL_ID = "operator-1m";
|
|
2
|
-
// Back-compat aliases: the user-facing ids were renamed aurora-* -> operator-* (the outward name is
|
|
3
|
-
// Operator; "aurora" is the internal model, never shown). The OLD ids still resolve — a persisted
|
|
4
|
-
// settings.activeModel: "aurora-1m", a `/model aurora-1m`, or any muscle memory keeps working — so the
|
|
5
|
-
// rename loses nothing. The served model name ("aurora-code-1") + endpoints stay internal, untouched.
|
|
6
|
-
export const MODEL_ALIASES = {
|
|
7
|
-
"aurora-1m": "operator-1m",
|
|
8
|
-
"aurora-128k": "operator-128k",
|
|
9
|
-
};
|
|
10
|
-
export const BUILTIN_MODELS = [
|
|
11
|
-
{ id: "operator-1m", label: "Operator 300K", kind: "single", desc: "307,200-token (300K) context (:8097)", endpoint: "http://127.0.0.1:8097/v1", model: "aurora-code-1", ctx: 307200 },
|
|
12
|
-
{ id: "operator-128k", label: "Operator 128K", kind: "single", desc: "128K context, lighter RAM (:8096)", endpoint: "http://127.0.0.1:8096/v1", model: "aurora-code-1", ctx: 131072 },
|
|
13
|
-
// QwenCloud Token Plan BYO connectors (SPEC/providers.md §2 "API-key connectors"). Same keychain
|
|
14
|
-
// account ("qwen") serves both; the picker hides them until connected (§1 honest availability), and
|
|
15
|
-
// authHeaders NEVER sends the Operator token to this host. ctx starts conservative and self-clamps
|
|
16
|
-
// to the served truth (observeContext).
|
|
17
|
-
{ id: "qwen3.8-max", label: "Qwen 3.8 Max", kind: "single", desc: "BYO QwenCloud Token Plan — credits from your plan", endpoint: "https://token-plan.maas.qwencloudapi.com/compatible-mode/v1", model: "qwen3.8-max", ctx: 262144, byo: "qwen", transport: "openai" },
|
|
18
|
-
{ id: "qwen3.8-flash", label: "Qwen 3.8 Flash", kind: "single", desc: "BYO QwenCloud Token Plan — fast tier, your credits", endpoint: "https://token-plan.maas.qwencloudapi.com/compatible-mode/v1", model: "qwen3.8-flash", ctx: 262144, byo: "qwen", transport: "openai" },
|
|
19
|
-
// Venice 24B — SELF-HOSTED like Aurora (NOT a third-party connector): the open uncensored weights
|
|
20
|
-
// (Dolphin-Mistral-24B-Venice-Edition Q4_K_M, JL1 Ai Storage) served via llama.cpp on JL1:8110, bound
|
|
21
|
-
// 0.0.0.0 so the engine (on JL2) reaches it over LAN. Uncensored at the weights — answers directly, no
|
|
22
|
-
// retry needed; complements the engine-level unrestricted layer. Runs ALONGSIDE Aurora (:8097); the
|
|
23
|
-
// llama.cpp router health-checks + recovers, and ctx self-clamps to the served truth (observeContext).
|
|
24
|
-
{ id: "venice-24b", label: "Venice 24B (uncensored)", kind: "single", desc: "self-hosted uncensored Dolphin-Mistral-24B-Venice (fleet llama.cpp, JL1:8110)", endpoint: "http://192.168.1.103:8110/v1", model: "dolphin-venice-24b", ctx: 8192 },
|
|
25
|
-
{ id: "moa", label: "MOA (Mixture of Agents)", kind: "orchestrated", desc: "fan out to proposers, synthesize with an aggregator" },
|
|
26
|
-
];
|
|
27
|
-
/** The runtime registry: the built-ins, with any settings.models entries merged in (overriding a
|
|
28
|
-
* built-in by id, or adding a new one) — same shape either way, so /model doesn't care which. */
|
|
29
|
-
export function modelRegistry(overrides) {
|
|
30
|
-
if (!overrides?.length)
|
|
31
|
-
return BUILTIN_MODELS;
|
|
32
|
-
const byId = new Map(BUILTIN_MODELS.map((m) => [m.id, m]));
|
|
33
|
-
for (const m of overrides)
|
|
34
|
-
byId.set(m.id, { ...byId.get(m.id), ...m });
|
|
35
|
-
return [...byId.values()];
|
|
36
|
-
}
|
|
37
|
-
export function findModel(registry, id) {
|
|
38
|
-
const canon = MODEL_ALIASES[id] ?? id; // aurora-1m -> operator-1m (old ids keep resolving)
|
|
39
|
-
return registry.find((m) => m.id === canon);
|
|
40
|
-
}
|
|
41
|
-
/** The configured context window (tokens) for a model id — from BUILTIN_MODELS + settings overrides — or
|
|
42
|
-
* Infinity if unknown. Used to pick a LEAN harness: a small-context model (e.g. a self-hosted 8K Venice)
|
|
43
|
-
* can't take Operator's full memory + handoff injection (sized for Aurora's 300K); it fills the window and
|
|
44
|
-
* the model recites the memory instead of answering. Callers drop the heavy memory/handoff below a
|
|
45
|
-
* threshold while keeping the base persona (incl. the Direct/unrestricted section), so it stays uncensored. */
|
|
46
|
-
export function modelCtxFor(id, overrides) {
|
|
47
|
-
if (!id)
|
|
48
|
-
return Number.POSITIVE_INFINITY;
|
|
49
|
-
return findModel(modelRegistry(overrides), id)?.ctx ?? Number.POSITIVE_INFINITY;
|
|
50
|
-
}
|
|
51
|
-
/** ctx window below which the lean harness (no heavy memory/handoff) kicks in. Aurora/Qwen (128K+) stay
|
|
52
|
-
* full; a self-hosted small model (Venice 8K, or a 16K bump) goes lean. */
|
|
53
|
-
export const LEAN_HARNESS_CTX = 32768;
|
|
54
|
-
/** Pure selection reducer for /model — no I/O (no settings read/write, no router mutation), so it's
|
|
55
|
-
* directly testable. The moa-needs-config check lives in Session.setModel (it needs settings.moa,
|
|
56
|
-
* which this module intentionally doesn't import). `hasByo` (injected by the caller, see auth/byo)
|
|
57
|
-
* gates BYO connector profiles: honest "not connected" beats a request-time 401. */
|
|
58
|
-
export function selectModel(registry, id, hasByo) {
|
|
59
|
-
const profile = findModel(registry, id);
|
|
60
|
-
if (!profile)
|
|
61
|
-
return { error: `unknown model "${id}" — choices: ${registry.map((m) => m.id).join(", ")}` };
|
|
62
|
-
if (profile.kind === "single" && !profile.endpoint)
|
|
63
|
-
return { error: `model "${id}" has no endpoint configured` };
|
|
64
|
-
if (profile.byo && hasByo && !hasByo(profile.byo)) {
|
|
65
|
-
return { error: `"${id}" is not connected — store the ${profile.byo} key first: operator auth byo ${profile.byo}` };
|
|
66
|
-
}
|
|
67
|
-
return { profile };
|
|
68
|
-
}
|
|
69
|
-
/** The picker-truth view of a registry: drops BYO profiles whose key isn't connected (and ALL
|
|
70
|
-
* unresolvable ones when the resolver is absent — a picker must never offer what setModel refuses). */
|
|
71
|
-
export function visibleModels(registry, hasByo) {
|
|
72
|
-
return registry.filter((p) => !p.byo || (hasByo ? hasByo(p.byo) : false));
|
|
73
|
-
}
|
|
74
|
-
/** Strip a trailing /v1 so a ModelProfile/MoaAggregator endpoint can feed the AuroraRouter, whose
|
|
75
|
-
* base is bare (engine/aurora.ts's chat() appends /v1/chat/completions itself). */
|
|
76
|
-
export function endpointBase(endpoint) {
|
|
77
|
-
return endpoint.replace(/\/v1\/?$/, "");
|
|
78
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
export const DEFAULT_MODEL_ID = "operator-1m";
|
|
2
|
-
// Back-compat aliases: the user-facing ids were renamed aurora-* -> operator-* (the outward name is
|
|
3
|
-
// Operator; "aurora" is the internal model, never shown). The OLD ids still resolve — a persisted
|
|
4
|
-
// settings.activeModel: "aurora-1m", a `/model aurora-1m`, or any muscle memory keeps working — so the
|
|
5
|
-
// rename loses nothing. The served model name ("aurora-code-1") + endpoints stay internal, untouched.
|
|
6
|
-
export const MODEL_ALIASES = {
|
|
7
|
-
"aurora-1m": "operator-1m",
|
|
8
|
-
"aurora-128k": "operator-128k",
|
|
9
|
-
};
|
|
10
|
-
export const BUILTIN_MODELS = [
|
|
11
|
-
{ id: "operator-1m", label: "Operator 300K", kind: "single", desc: "307,200-token (300K) context (:8097)", endpoint: "http://127.0.0.1:8097/v1", model: "aurora-code-1", ctx: 307200 },
|
|
12
|
-
{ id: "operator-128k", label: "Operator 128K", kind: "single", desc: "128K context, lighter RAM (:8096)", endpoint: "http://127.0.0.1:8096/v1", model: "aurora-code-1", ctx: 131072 },
|
|
13
|
-
// QwenCloud Token Plan BYO connectors (SPEC/providers.md §2 "API-key connectors"). Same keychain
|
|
14
|
-
// account ("qwen") serves both; the picker hides them until connected (§1 honest availability), and
|
|
15
|
-
// authHeaders NEVER sends the Operator token to this host. ctx starts conservative and self-clamps
|
|
16
|
-
// to the served truth (observeContext).
|
|
17
|
-
{ id: "qwen3.8-max", label: "Qwen 3.8 Max", kind: "single", desc: "BYO QwenCloud Token Plan — credits from your plan", endpoint: "https://token-plan.maas.qwencloudapi.com/compatible-mode/v1", model: "qwen3.8-max", ctx: 262144, byo: "qwen", transport: "openai" },
|
|
18
|
-
{ id: "qwen3.8-flash", label: "Qwen 3.8 Flash", kind: "single", desc: "BYO QwenCloud Token Plan — fast tier, your credits", endpoint: "https://token-plan.maas.qwencloudapi.com/compatible-mode/v1", model: "qwen3.8-flash", ctx: 262144, byo: "qwen", transport: "openai" },
|
|
19
|
-
// Venice 24B — SELF-HOSTED like Aurora (NOT a third-party connector): the open uncensored weights
|
|
20
|
-
// (Dolphin-Mistral-24B-Venice-Edition Q4_K_M, JL1 Ai Storage) served via llama.cpp on JL1:8110, bound
|
|
21
|
-
// 0.0.0.0 so the engine (on JL2) reaches it over LAN. Uncensored at the weights — answers directly, no
|
|
22
|
-
// retry needed; complements the engine-level unrestricted layer. Runs ALONGSIDE Aurora (:8097); the
|
|
23
|
-
// llama.cpp router health-checks + recovers, and ctx self-clamps to the served truth (observeContext).
|
|
24
|
-
{ id: "venice-24b", label: "Venice 24B (uncensored)", kind: "single", desc: "self-hosted uncensored Dolphin-Mistral-24B-Venice (fleet llama.cpp, JL1:8110)", endpoint: "http://192.168.1.103:8110/v1", model: "dolphin-venice-24b", ctx: 8192 },
|
|
25
|
-
{ id: "moa", label: "MOA (Mixture of Agents)", kind: "orchestrated", desc: "fan out to proposers, synthesize with an aggregator" },
|
|
26
|
-
];
|
|
27
|
-
/** The runtime registry: the built-ins, with any settings.models entries merged in (overriding a
|
|
28
|
-
* built-in by id, or adding a new one) — same shape either way, so /model doesn't care which. */
|
|
29
|
-
export function modelRegistry(overrides) {
|
|
30
|
-
if (!overrides?.length)
|
|
31
|
-
return BUILTIN_MODELS;
|
|
32
|
-
const byId = new Map(BUILTIN_MODELS.map((m) => [m.id, m]));
|
|
33
|
-
for (const m of overrides)
|
|
34
|
-
byId.set(m.id, { ...byId.get(m.id), ...m });
|
|
35
|
-
return [...byId.values()];
|
|
36
|
-
}
|
|
37
|
-
export function findModel(registry, id) {
|
|
38
|
-
const canon = MODEL_ALIASES[id] ?? id; // aurora-1m -> operator-1m (old ids keep resolving)
|
|
39
|
-
return registry.find((m) => m.id === canon);
|
|
40
|
-
}
|
|
41
|
-
/** The configured context window (tokens) for a model id — from BUILTIN_MODELS + settings overrides — or
|
|
42
|
-
* Infinity if unknown. Used to pick a LEAN harness: a small-context model (e.g. a self-hosted 8K Venice)
|
|
43
|
-
* can't take Operator's full memory + handoff injection (sized for Aurora's 300K); it fills the window and
|
|
44
|
-
* the model recites the memory instead of answering. Callers drop the heavy memory/handoff below a
|
|
45
|
-
* threshold while keeping the base persona (incl. the Direct/unrestricted section), so it stays uncensored. */
|
|
46
|
-
export function modelCtxFor(id, overrides) {
|
|
47
|
-
if (!id)
|
|
48
|
-
return Number.POSITIVE_INFINITY;
|
|
49
|
-
return findModel(modelRegistry(overrides), id)?.ctx ?? Number.POSITIVE_INFINITY;
|
|
50
|
-
}
|
|
51
|
-
/** ctx window below which the lean harness (no heavy memory/handoff) kicks in. Aurora/Qwen (128K+) stay
|
|
52
|
-
* full; a self-hosted small model (Venice 8K, or a 16K bump) goes lean. */
|
|
53
|
-
export const LEAN_HARNESS_CTX = 32768;
|
|
54
|
-
/** Pure selection reducer for /model — no I/O (no settings read/write, no router mutation), so it's
|
|
55
|
-
* directly testable. The moa-needs-config check lives in Session.setModel (it needs settings.moa,
|
|
56
|
-
* which this module intentionally doesn't import). `hasByo` (injected by the caller, see auth/byo)
|
|
57
|
-
* gates BYO connector profiles: honest "not connected" beats a request-time 401. */
|
|
58
|
-
export function selectModel(registry, id, hasByo) {
|
|
59
|
-
const profile = findModel(registry, id);
|
|
60
|
-
if (!profile)
|
|
61
|
-
return { error: `unknown model "${id}" — choices: ${registry.map((m) => m.id).join(", ")}` };
|
|
62
|
-
if (profile.kind === "single" && !profile.endpoint)
|
|
63
|
-
return { error: `model "${id}" has no endpoint configured` };
|
|
64
|
-
if (profile.byo && hasByo && !hasByo(profile.byo)) {
|
|
65
|
-
return { error: `"${id}" is not connected — store the ${profile.byo} key first: operator auth byo ${profile.byo}` };
|
|
66
|
-
}
|
|
67
|
-
return { profile };
|
|
68
|
-
}
|
|
69
|
-
/** The picker-truth view of a registry: drops BYO profiles whose key isn't connected (and ALL
|
|
70
|
-
* unresolvable ones when the resolver is absent — a picker must never offer what setModel refuses). */
|
|
71
|
-
export function visibleModels(registry, hasByo) {
|
|
72
|
-
return registry.filter((p) => !p.byo || (hasByo ? hasByo(p.byo) : false));
|
|
73
|
-
}
|
|
74
|
-
/** Strip a trailing /v1 so a ModelProfile/MoaAggregator endpoint can feed the AuroraRouter, whose
|
|
75
|
-
* base is bare (engine/aurora.ts's chat() appends /v1/chat/completions itself). */
|
|
76
|
-
export function endpointBase(endpoint) {
|
|
77
|
-
return endpoint.replace(/\/v1\/?$/, "");
|
|
78
|
-
}
|
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
// Model auto-detect boot — connect to whatever model is HEALTHY, local or remote, instead of hard-launching
|
|
2
|
-
// one port and freezing the boot when it is down. (Incident 2026-10-10: the JL2 Aurora gguf vanished, the
|
|
3
|
-
// boot kickstarted com.imi.aurora-serve and HARD-WAITED 90s on a dead :8097, then quit — bricking Operator
|
|
4
|
-
// while cortana, a healthy 35B, answered on JL1:8112 the whole time.)
|
|
5
|
-
//
|
|
6
|
-
// The shape, and the split that makes it testable:
|
|
7
|
-
// • buildCandidates() PURE — the ordered list to try: (a) the active model's endpoint, (b) same-model
|
|
8
|
-
// standbys (failover, fleet nodes), (c) every other registry profile; cloud/BYO last.
|
|
9
|
-
// • detectBoot() the decision flow over an INJECTED probe/launch/sleep (no network in tests):
|
|
10
|
-
// probe → first healthy by priority wins → (only if none) wait out a model that is
|
|
11
|
-
// already loading → cloud tier → Service-lever launch as the LAST resort → degraded.
|
|
12
|
-
// • probeCandidate() the real network probe (short timeout, /health and /v1/models raced in parallel).
|
|
13
|
-
// Nothing here knows what "aurora" is: every entry is just {base, model, ctx}. Aurora is one candidate.
|
|
14
|
-
import { authHeaders } from "../engine/aurora.js";
|
|
15
|
-
import { endpointBase } from "../router/models.js";
|
|
16
|
-
const norm = (base) => base.replace(/\/+$/, "").toLowerCase();
|
|
17
|
-
const keyOf = (c) => `${norm(c.base)}|${c.model}`;
|
|
18
|
-
/** host:port of a base, for the one-line "→ model: …" notice. Falls back to the raw string. */
|
|
19
|
-
export function hostPort(base) {
|
|
20
|
-
try {
|
|
21
|
-
return new URL(base).host;
|
|
22
|
-
}
|
|
23
|
-
catch {
|
|
24
|
-
return base;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
/** The ordered candidate list. PURE. Priority: active → standbys → registry (local/LAN first, cloud last);
|
|
28
|
-
* de-duplicated on base+model so the registry's own copy of the active profile never probes twice. */
|
|
29
|
-
export function buildCandidates(i) {
|
|
30
|
-
const out = [];
|
|
31
|
-
const seen = new Set();
|
|
32
|
-
const add = (c) => {
|
|
33
|
-
const k = keyOf(c);
|
|
34
|
-
if (seen.has(k))
|
|
35
|
-
return;
|
|
36
|
-
seen.add(k);
|
|
37
|
-
out.push(c);
|
|
38
|
-
};
|
|
39
|
-
const a = i.active;
|
|
40
|
-
// An active BYO profile (the owner's /model qwen3.8-max) carries its vendor key + dialect on the registry entry.
|
|
41
|
-
const ap = i.registry.find((p) => p.id === a.id);
|
|
42
|
-
add({ id: a.id, label: a.label ?? a.id, base: a.base, model: a.model, ctx: a.ctx, profileId: a.id, token: a.token ?? (ap?.byo ? i.byoToken?.(ap.byo) : undefined), transport: a.transport ?? ap?.transport, cloud: false, source: "active" });
|
|
43
|
-
if (i.enabled === false)
|
|
44
|
-
return out;
|
|
45
|
-
for (const s of i.standby) {
|
|
46
|
-
if (!s.base)
|
|
47
|
-
continue;
|
|
48
|
-
add({ id: s.id, label: s.id, base: s.base, model: s.model, ctx: s.ctx, cloud: false, source: "standby" });
|
|
49
|
-
}
|
|
50
|
-
const profiles = i.registry.filter((p) => p.kind === "single" && !!p.endpoint && p.autodetect !== false);
|
|
51
|
-
const cloud = (p) => !!p.byo;
|
|
52
|
-
for (const p of [...profiles.filter((p) => !cloud(p)), ...(i.allowCloud === false ? [] : profiles.filter(cloud))]) {
|
|
53
|
-
const token = p.byo ? i.byoToken?.(p.byo) : undefined;
|
|
54
|
-
if (p.byo && !token)
|
|
55
|
-
continue; // a connector with no resolvable key can never answer — don't list a guaranteed ✗
|
|
56
|
-
add({ id: p.id, label: p.label, base: endpointBase(p.endpoint), model: p.model ?? p.id, ctx: p.ctx ?? a.ctx, profileId: p.id, token, transport: p.transport, cloud: cloud(p), source: "registry" });
|
|
57
|
-
}
|
|
58
|
-
return out;
|
|
59
|
-
}
|
|
60
|
-
/** The router chain to adopt for a chosen candidate: it first, then the other LOCAL candidates that serve the
|
|
61
|
-
* SAME model (the aurora nodes), so a mid-session death still hops to a sibling instead of stranding. A
|
|
62
|
-
* different model is never mixed in — a failover must not silently change which model answers. PURE. */
|
|
63
|
-
export function routerChain(chosen, all) {
|
|
64
|
-
const toEp = (c) => ({ name: c.id, base: c.base, model: c.model, ctxLimit: c.ctx, token: c.token, transport: c.transport });
|
|
65
|
-
const sib = all.filter((c) => c !== chosen && !c.cloud && !chosen.cloud && c.model === chosen.model && keyOf(c) !== keyOf(chosen));
|
|
66
|
-
return [toEp(chosen), ...sib.map(toEp)];
|
|
67
|
-
}
|
|
68
|
-
/** Probe one candidate. `/health` (llama.cpp, mlx_lm, gateways) and `/v1/models` (Ollama, any OpenAI-compatible
|
|
69
|
-
* server with no /health) are raced IN PARALLEL under ONE short timeout, so the worst case is the timeout, not
|
|
70
|
-
* a serial pair. ready = a 2xx that doesn't say it is still starting; loading = the port answered 503 (llama.cpp
|
|
71
|
-
* serves 503 while it mmaps the model — alive, must not be restarted); down = refused / timed out / 4xx. Never throws. */
|
|
72
|
-
export async function probeCandidate(c, o = {}) {
|
|
73
|
-
const f = o.fetchImpl ?? fetch;
|
|
74
|
-
const ctrl = new AbortController();
|
|
75
|
-
const timer = setTimeout(() => ctrl.abort(), o.timeoutMs ?? 2500);
|
|
76
|
-
const onAbort = () => ctrl.abort();
|
|
77
|
-
o.signal?.addEventListener("abort", onAbort, { once: true });
|
|
78
|
-
const headers = authHeaders({ base: c.base, model: c.model, token: c.token });
|
|
79
|
-
const base = c.base.replace(/\/+$/, "");
|
|
80
|
-
const get = async (path) => {
|
|
81
|
-
try {
|
|
82
|
-
const r = await f(`${base}${path}`, { signal: ctrl.signal, headers });
|
|
83
|
-
if (r.status === 503)
|
|
84
|
-
return "loading";
|
|
85
|
-
if (!r.ok)
|
|
86
|
-
return "down";
|
|
87
|
-
if (path !== "/health")
|
|
88
|
-
return "ready";
|
|
89
|
-
const j = await r.json().catch(() => undefined);
|
|
90
|
-
return j && typeof j.status === "string" && j.status !== "ok" ? "loading" : "ready"; // 200 {"status":"loading model"} is alive-but-not-serving
|
|
91
|
-
}
|
|
92
|
-
catch {
|
|
93
|
-
return "down";
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
try {
|
|
97
|
-
// First `ready` wins at once (a healthy endpoint must not wait on its slower sibling request); otherwise the
|
|
98
|
-
// verdict is "loading" if either request saw a 503, else "down".
|
|
99
|
-
return await new Promise((resolve) => {
|
|
100
|
-
const seen = [];
|
|
101
|
-
for (const p of [get("/health"), get("/v1/models")]) {
|
|
102
|
-
void p.then((s) => {
|
|
103
|
-
if (s === "ready")
|
|
104
|
-
return resolve("ready");
|
|
105
|
-
seen.push(s);
|
|
106
|
-
if (seen.length === 2)
|
|
107
|
-
resolve(seen.includes("loading") ? "loading" : "down");
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
finally {
|
|
113
|
-
clearTimeout(timer);
|
|
114
|
-
o.signal?.removeEventListener("abort", onAbort);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
/** Fire every probe in parallel, then walk them in PRIORITY order: the first `ready` wins the moment every
|
|
118
|
-
* higher-priority candidate has settled — so a healthy active endpoint returns at once and never waits on a
|
|
119
|
-
* dead LAN host's timeout further down the list. Stragglers are aborted. */
|
|
120
|
-
async function pickFirstReady(cands, deps) {
|
|
121
|
-
const ctrl = new AbortController();
|
|
122
|
-
const memo = new Map(); // one probe per base+token — qwen3.8-max and -flash share a host
|
|
123
|
-
const run = (c) => {
|
|
124
|
-
const k = `${norm(c.base)}|${c.token ? "t" : ""}`;
|
|
125
|
-
let p = memo.get(k);
|
|
126
|
-
if (!p) {
|
|
127
|
-
p = deps.probe(c, ctrl.signal).catch(() => "down");
|
|
128
|
-
memo.set(k, p);
|
|
129
|
-
}
|
|
130
|
-
return p;
|
|
131
|
-
};
|
|
132
|
-
const pending = cands.map(run);
|
|
133
|
-
const attempts = [];
|
|
134
|
-
try {
|
|
135
|
-
for (let i = 0; i < cands.length; i++) {
|
|
136
|
-
const status = await pending[i];
|
|
137
|
-
attempts.push({ candidate: cands[i], status });
|
|
138
|
-
if (status === "ready")
|
|
139
|
-
return { chosen: cands[i], attempts };
|
|
140
|
-
}
|
|
141
|
-
return { attempts };
|
|
142
|
-
}
|
|
143
|
-
finally {
|
|
144
|
-
ctrl.abort();
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
/** The boot decision flow. Never throws, never blocks longer than: one probe timeout (+ `waitSec` if a model is
|
|
148
|
-
* already loading, + the caller-bounded launch when nothing is healthy and one is configured). */
|
|
149
|
-
export async function detectBoot(cands, deps) {
|
|
150
|
-
const sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
151
|
-
const now = deps.now ?? Date.now;
|
|
152
|
-
const waitSec = deps.waitSec ?? 25;
|
|
153
|
-
const local = cands.filter((c) => !c.cloud);
|
|
154
|
-
const cloud = cands.filter((c) => c.cloud);
|
|
155
|
-
const tried = [];
|
|
156
|
-
const note = (a) => { for (const x of a)
|
|
157
|
-
if (!tried.some((t) => t.candidate === x.candidate))
|
|
158
|
-
tried.push(x); };
|
|
159
|
-
const done = (chosen, launch) => {
|
|
160
|
-
const failed = tried.filter((t) => t.candidate !== chosen && t.status !== "ready");
|
|
161
|
-
if (launch?.state === "started")
|
|
162
|
-
return { kind: "launched", chosen, tried: failed, launch };
|
|
163
|
-
return { kind: chosen === cands[0] ? "primary" : "alternate", chosen, tried: failed };
|
|
164
|
-
};
|
|
165
|
-
const first = await pickFirstReady(local, deps);
|
|
166
|
-
note(first.attempts);
|
|
167
|
-
if (first.chosen)
|
|
168
|
-
return done(first.chosen);
|
|
169
|
-
// Something is already coming up on its own (llama.cpp 503 while it mmaps): wait it out, bounded — never
|
|
170
|
-
// restart a mid-load model, and never freeze on it past `waitSec`.
|
|
171
|
-
const loading = local.filter((c) => tried.some((t) => t.candidate === c && t.status === "loading"));
|
|
172
|
-
if (loading.length) {
|
|
173
|
-
deps.onProgress?.(`${loading[0].label} is loading…`);
|
|
174
|
-
const deadline = now() + waitSec * 1000;
|
|
175
|
-
while (now() < deadline) {
|
|
176
|
-
await sleep(1000);
|
|
177
|
-
const r = await pickFirstReady(loading, deps);
|
|
178
|
-
for (const a of r.attempts) {
|
|
179
|
-
const t = tried.find((x) => x.candidate === a.candidate);
|
|
180
|
-
if (t)
|
|
181
|
-
t.status = a.status;
|
|
182
|
-
}
|
|
183
|
-
if (r.chosen)
|
|
184
|
-
return done(r.chosen);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
if (cloud.length) {
|
|
188
|
-
deps.onProgress?.("no local model answered — trying connected cloud models…");
|
|
189
|
-
const r = await pickFirstReady(cloud, deps);
|
|
190
|
-
note(r.attempts);
|
|
191
|
-
if (r.chosen)
|
|
192
|
-
return done(r.chosen);
|
|
193
|
-
}
|
|
194
|
-
// LAST resort — and never while something is mid-load (that service is already starting itself).
|
|
195
|
-
let launch;
|
|
196
|
-
if (deps.launch && !loading.length) {
|
|
197
|
-
deps.onProgress?.("no model reachable — trying the local launchd model…");
|
|
198
|
-
launch = await deps.launch().catch((e) => ({ state: "down", detail: String(e?.message ?? e) }));
|
|
199
|
-
if (launch.state === "up" || launch.state === "started") {
|
|
200
|
-
const r = await pickFirstReady(local, deps);
|
|
201
|
-
for (const a of r.attempts) {
|
|
202
|
-
const t = tried.find((x) => x.candidate === a.candidate);
|
|
203
|
-
if (t)
|
|
204
|
-
t.status = a.status;
|
|
205
|
-
else
|
|
206
|
-
tried.push(a);
|
|
207
|
-
}
|
|
208
|
-
if (r.chosen)
|
|
209
|
-
return done(r.chosen, launch);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
return { kind: "degraded", tried, launch };
|
|
213
|
-
}
|
|
214
|
-
/** What a boot outcome says about ONE base, for the dashboard's service tiles. undefined = it was never probed
|
|
215
|
-
* (e.g. a healthy higher-priority endpoint won before the walk reached it) — never claim a state we didn't observe. PURE. */
|
|
216
|
-
export function stateOfBase(o, base) {
|
|
217
|
-
const b = norm(base);
|
|
218
|
-
if (o.kind !== "degraded" && norm(o.chosen.base) === b)
|
|
219
|
-
return o.kind === "launched" ? "started" : "up";
|
|
220
|
-
return o.tried.some((t) => norm(t.candidate.base) === b) ? "down" : undefined;
|
|
221
|
-
}
|
|
222
|
-
const mark = (s) => (s === "ready" ? "✓" : s === "loading" ? "…" : "✗");
|
|
223
|
-
/** The scrollback notice for an outcome — "" for the happy path (the services line already confirms it). PURE. */
|
|
224
|
-
export function describeOutcome(o) {
|
|
225
|
-
if (o.kind === "primary")
|
|
226
|
-
return "";
|
|
227
|
-
if (o.kind === "degraded") {
|
|
228
|
-
const rows = o.tried.map((t) => ` ${mark(t.status)} ${t.candidate.id} ${hostPort(t.candidate.base)} ${t.status}`);
|
|
229
|
-
const lane = o.launch ? `\n launch: ${o.launch.detail ?? o.launch.state}` : "";
|
|
230
|
-
return `no model reachable — tried:\n${rows.join("\n")}${lane}\nOperator is open but has no model yet. Pick one with /model <id>, pin an endpoint with /route <name>, or point Operator at a running model in your settings and relaunch. The next message re-checks.`;
|
|
231
|
-
}
|
|
232
|
-
const c = o.chosen;
|
|
233
|
-
const where = `${c.id} @ ${hostPort(c.base)}`;
|
|
234
|
-
const cloudNote = c.cloud ? " (cloud — your own API key; nothing local was reachable)" : "";
|
|
235
|
-
// Two endpoints can share an id (KODE_AURORA re-points the active operator-1m while the registry still lists its
|
|
236
|
-
// own) — name the host only where the id alone would be ambiguous.
|
|
237
|
-
const nameOf = (c) => (o.tried.filter((t) => t.candidate.id === c.id).length > 1 ? `${c.id}@${hostPort(c.base)}` : c.id);
|
|
238
|
-
const skipped = o.tried.length ? `\n skipped: ${o.tried.map((t) => `${nameOf(t.candidate)} (${t.status})`).join(", ")}` : "";
|
|
239
|
-
return `→ model: ${where}${cloudNote}${o.kind === "launched" ? " (launched)" : ""}${skipped}`;
|
|
240
|
-
}
|