@0perator/operator 0.1.326 → 0.1.329

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.
@@ -350,13 +350,13 @@ export class LoopGuard {
350
350
  // else might.
351
351
  export const AUTOPOST_POLLERS = new Set(["agent_status"]);
352
352
  export const POLL_SPIN_DEFAULTS = { nudgeAfter: 2, stopAfter: 3 };
353
- export const POLL_SPIN_NUDGE = "Sub-agent results auto-post to this conversation the moment they finish — you do not need to poll " +
354
- "agent_status to learn that. Reads and status checks while they run are not progress: finish only what does " +
355
- "NOT depend on them, give a one-line status, and END YOUR TURN — the results resume this conversation on their " +
353
+ export const POLL_SPIN_NUDGE = "Sub-agent reports auto-post as new messages at the start of your next turn — polling agent_status cannot " +
354
+ "bring one in sooner. Reads and status checks while they run are not progress: finish only what does NOT " +
355
+ "depend on them, give a one-line status, and END YOUR TURN — the reports resume this conversation on their " +
356
356
  "own, and a turn that keeps polling holds the model slot and starves the sub-agents.";
357
- export const POLL_SPIN_STOP = "[stopped — waiting on sub-agents: agent_status was polled repeatedly with no mutating work and no change in status. Sub-agent results " +
358
- "auto-post when they finish and will resume this turn, so polling only burns time and tokens. Nothing was " +
359
- "lost — the results arrive on their own.]";
357
+ export const POLL_SPIN_STOP = "[stopped — waiting on sub-agents: agent_status was polled repeatedly with no mutating work and no change in status. Sub-agent reports " +
358
+ "auto-post as new messages when they finish and resume this conversation, so polling only burns time and tokens. Nothing was " +
359
+ "lost — the reports arrive on their own.]";
360
360
  /** Watches settled tool rounds for an auto-post-poller spin. Fed one round at a time via observe(); a
361
361
  * productive (non-poller) tool OR a changed poll result resets the streak. Side-effect-free: the engine acts
362
362
  * on the returned action (inject the nudge once, then end the turn). */
@@ -403,6 +403,71 @@ export class PollSpinGuard {
403
403
  return { action: "allow", streak: this.streak };
404
404
  }
405
405
  }
406
+ // ── Yield-after-dispatch guard ───────────────────────────────────────────────
407
+ // The poll-spin guard keys on agent_status. The 2026-10-28 0.1.326 run showed the other shape: after spawning
408
+ // three sub-agents the parent never polled — it re-researched the SAME topics itself for 30 minutes (web_search /
409
+ // web_fetch every round, nothing written), holding the shared model slot while the sub-agents crawled. Once
410
+ // background sub-agents have been dispatched this turn, a round with no MUTATING call is waiting-with-busywork,
411
+ // not progress: nudge at `nudgeAfter`, end the turn at `stopAfter` so the auto-posted reports resume it and the
412
+ // sub-agents get the slot. Only spawn_agent counts as a dispatch — delegate_task / delegate_to_agent block until
413
+ // the child is done, so nothing is running after they return.
414
+ export const DISPATCH_TOOLS = new Set(["spawn_agent"]);
415
+ /** Calls that only book-keep around a dispatch (the plan pane, the agent panel): a dispatch round made of these
416
+ * alone has no independent work in it. */
417
+ export const DISPATCH_BOOKKEEPING = new Set(["task_add", "task_update", "task_list", "task_clear", "agent_status", "message_agent"]);
418
+ export const YIELD_DEFAULTS = { nudgeAfter: 1, stopAfter: 2 };
419
+ export const YIELD_NUDGE = "Your sub-agents are running and this round changed nothing. Do not redo their work: write down anything you " +
420
+ "found (task_update / scratchpad), give a one-line status, and END YOUR TURN — each report arrives as a new " +
421
+ "message at the start of your next turn; a turn that keeps reading holds the model slot and starves them.";
422
+ export const YIELD_STOP = "[turn ended — sub-agents are running and the last round changed nothing. The turn yields the model slot to " +
423
+ "them; each report arrives as a new message and resumes this conversation. Nothing was lost.]";
424
+ export const YIELD_DISPATCHED = "[turn ended — sub-agents dispatched. This model endpoint has one slot, so the turn yields it to them now; " +
425
+ "each report arrives as a new message and resumes this conversation. Nothing was lost.]";
426
+ /** Watches settled tool rounds after a spawn_agent dispatch. Fed one round at a time via observe(); a MUTATING
427
+ * round resets the streak. The endpoint's slot count sets the policy: on ONE slot (the fleet default) the parent
428
+ * working beside its sub-agents is pure contention — every parent round waits behind a sub-agent round and then
429
+ * holds the slot itself (3+ min per round live on 2026-10-28) — so a dispatch round with nothing but bookkeeping
430
+ * in it ends the turn at once, and the first non-mutating round after any dispatch ends it; with several slots
431
+ * the parent may work alongside them (nudge at 1, end at 2). Side-effect-free, like PollSpinGuard. */
432
+ export class YieldAfterDispatchGuard {
433
+ nudgeAfter;
434
+ stopAfter;
435
+ dispatched;
436
+ streak = 0;
437
+ nudged = false;
438
+ /** `armed`: the turn begins with sub-agents already running (a wake turn that delivers one report while others
439
+ * work) — it is past the dispatch from round one, so the same policy applies from its first round. */
440
+ constructor(nudgeAfter = YIELD_DEFAULTS.nudgeAfter, stopAfter = YIELD_DEFAULTS.stopAfter, armed = false) {
441
+ this.nudgeAfter = nudgeAfter;
442
+ this.stopAfter = stopAfter;
443
+ this.dispatched = armed;
444
+ }
445
+ /** One settled round: the tools it ran (names), whether any call changed the workspace, and how many requests
446
+ * the model endpoint serves at once (engine/aurora.ts endpointSlots — 1 unless KODE_ENDPOINT_SLOTS says more). */
447
+ observe(names, mutating, slots = 1) {
448
+ const single = slots <= 1;
449
+ if (names.some((n) => DISPATCH_TOOLS.has(n))) {
450
+ this.dispatched = true;
451
+ this.streak = 0;
452
+ const pure = names.every((n) => DISPATCH_TOOLS.has(n) || DISPATCH_BOOKKEEPING.has(n));
453
+ return single && pure ? { action: "halt", streak: 0, message: YIELD_DISPATCHED } : { action: "allow", streak: 0 };
454
+ }
455
+ if (!this.dispatched)
456
+ return { action: "allow", streak: 0 };
457
+ if (mutating) {
458
+ this.streak = 0;
459
+ return { action: "allow", streak: 0 };
460
+ }
461
+ this.streak += 1;
462
+ if (single || this.streak >= this.stopAfter)
463
+ return { action: "halt", streak: this.streak, message: YIELD_STOP };
464
+ if (this.streak >= this.nudgeAfter && !this.nudged) {
465
+ this.nudged = true;
466
+ return { action: "nudge", streak: this.streak, message: YIELD_NUDGE };
467
+ }
468
+ return { action: "allow", streak: this.streak };
469
+ }
470
+ }
406
471
  // ── No-write-progress detector ───────────────────────────────────────────────
407
472
  // Catches investigate-loops: consecutive rounds of tool calls where ZERO are mutating calls.
408
473
  // The existing loop guard (identical-call, cycle, failure) evades this by varying args each round.
@@ -0,0 +1,78 @@
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
+ }
@@ -0,0 +1,78 @@
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
+ }
@@ -0,0 +1,78 @@
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
+ }
@@ -0,0 +1,78 @@
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
+ }
@@ -0,0 +1,78 @@
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
+ }