viber-channel 0.8.46 → 0.8.47
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/lib/capabilities.ts +15 -8
- package/lib/codex_model_pair.ts +21 -11
- package/lib/codex_models_refresh.ts +326 -0
- package/lib/team_role_tool.ts +1 -2
- package/package.json +1 -1
- package/lib/codex_default.ts +0 -11
package/lib/capabilities.ts
CHANGED
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
*
|
|
14
14
|
* Pure (no I/O) so it is trivially testable and identical across hosts.
|
|
15
15
|
*/
|
|
16
|
-
import { CODEX_DEFAULT_PAIR } from "./codex_default.js";
|
|
17
16
|
|
|
18
17
|
export function capabilitiesText(channelVersion: string | null = null): string {
|
|
19
18
|
return [
|
|
@@ -120,7 +119,8 @@ export function capabilitiesText(channelVersion: string | null = null): string {
|
|
|
120
119
|
" only; all roles of one template must share one permission) · count optional;",
|
|
121
120
|
" model/effort: on claude leave them OUT (runtime default) UNLESS the owner asks:",
|
|
122
121
|
" model opus|sonnet|haiku|fable, effort low|medium|high|xhigh|max. On codex BOTH are",
|
|
123
|
-
|
|
122
|
+
" REQUIRED: a model the owner's codex lists (see CODEX MODELS below), effort low",
|
|
123
|
+
" unless the owner asks for another.",
|
|
124
124
|
" (On the web, sidebar ⋯ → Add agent launches ONE named agent from the same library.)",
|
|
125
125
|
"OLD ONE-ROLE TEMPLATES (#678): a template with a single role was only a workaround",
|
|
126
126
|
" to launch one agent before launch-agent existed. Do not create new ones:",
|
|
@@ -191,15 +191,13 @@ export function capabilitiesText(channelVersion: string | null = null): string {
|
|
|
191
191
|
" permission REQUIRED read-only | read-write (gemma: read-only only)",
|
|
192
192
|
" rolePrompt REQUIRED non-empty, ≤ 600 chars AFTER {prefix} expands to 32 chars",
|
|
193
193
|
" model claude: optional, opus | sonnet | haiku | fable (a family, never a",
|
|
194
|
-
" version); codex: REQUIRED,
|
|
195
|
-
"
|
|
196
|
-
" gpt-5.5; gemma: ≤ 64, stored but not applied",
|
|
194
|
+
" version); codex: REQUIRED, a model of the owner's codex list",
|
|
195
|
+
" (CODEX MODELS below); gemma: ≤ 64, stored but not applied",
|
|
197
196
|
" effort claude: optional, low | medium | high | xhigh | max;",
|
|
198
|
-
" codex: REQUIRED, one
|
|
199
|
-
" max except gpt-5.5, ultra except the luna models and gpt-5.5;",
|
|
197
|
+
" codex: REQUIRED, one that model accepts (low on all);",
|
|
200
198
|
" gemma: refused",
|
|
201
199
|
" claude: leave model/effort OUT (runtime default) unless the",
|
|
202
|
-
|
|
200
|
+
" owner asks; codex: the model the owner names, effort low unless they ask",
|
|
203
201
|
" plugins claude only, optional: [\"name@marketplace\", …] ≤ 8, enabled for",
|
|
204
202
|
" that agent's session only (e.g. playwright@claude-plugins-official)",
|
|
205
203
|
" chrome claude only, optional: true launches it with Claude in Chrome",
|
|
@@ -242,6 +240,15 @@ export function capabilitiesText(channelVersion: string | null = null): string {
|
|
|
242
240
|
"to them FIRST and read their reply on that DM. Their `gh` has no usable token in",
|
|
243
241
|
"the sandbox (#525): run gh (labels, PR comments) for them.",
|
|
244
242
|
"",
|
|
243
|
+
"CODEX MODELS (#747): no list is written anywhere — the owner's list is what `model/list`",
|
|
244
|
+
"of THEIR codex CLI answers, sent by the Viber app when it starts. A codex role naming a",
|
|
245
|
+
"model that list lacks is refused \"not available\", and the refusal names the known ones.",
|
|
246
|
+
"When the owner says a new codex model is out, or such a refusal names a model the owner",
|
|
247
|
+
"wants, run on the owner's machine:",
|
|
248
|
+
" viber-gateway refresh-models",
|
|
249
|
+
"It updates the codex CLI when npm has a newer one, reads model/list and sends it; it prints",
|
|
250
|
+
"the codex version and the models sent (exit 0), or why it failed (exit 1). Then retry.",
|
|
251
|
+
"",
|
|
245
252
|
"Never launch agents by calling vibe-master yourself: launch-team / launch-agent (or the",
|
|
246
253
|
"web) is the ONLY launch path (#660), the one the runner supervises and relaunches.",
|
|
247
254
|
"viber-gateway has no --help: an unknown verb runs the startup command (exit 2",
|
package/lib/codex_model_pair.ts
CHANGED
|
@@ -93,14 +93,11 @@ async function collectCatalogue(fetchPage: ModelListFetch, expired: () => boolea
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
96
|
+
* #747: THIS codex's whole catalogue (`model/list`, every page), model slug → efforts, in the
|
|
97
|
+
* order codex answers. One deadline covers the whole pagination; an RPC failure, a malformed
|
|
98
|
+
* answer or the deadline all throw.
|
|
98
99
|
*/
|
|
99
|
-
export async function
|
|
100
|
-
pair: CodexPair,
|
|
101
|
-
fetchPage: ModelListFetch,
|
|
102
|
-
timeoutMs: number,
|
|
103
|
-
): Promise<void> {
|
|
100
|
+
export async function readCodexCatalogue(fetchPage: ModelListFetch, timeoutMs: number): Promise<Map<string, string[]>> {
|
|
104
101
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
105
102
|
let expired = false;
|
|
106
103
|
const deadline = new Promise<never>((_, reject) => {
|
|
@@ -111,20 +108,33 @@ export async function verifyCodexPair(
|
|
|
111
108
|
});
|
|
112
109
|
const walk = collectCatalogue(fetchPage, () => expired);
|
|
113
110
|
walk.catch(() => {}); // after the deadline its own rejection has nobody left to tell
|
|
111
|
+
try {
|
|
112
|
+
return await Promise.race([walk, deadline]);
|
|
113
|
+
} finally {
|
|
114
|
+
clearTimeout(timer);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Throw unless THIS codex's catalogue carries the pair (the bridge, at startup).
|
|
120
|
+
*/
|
|
121
|
+
export async function verifyCodexPair(
|
|
122
|
+
pair: CodexPair,
|
|
123
|
+
fetchPage: ModelListFetch,
|
|
124
|
+
timeoutMs: number,
|
|
125
|
+
): Promise<void> {
|
|
114
126
|
let catalogue: Map<string, string[]>;
|
|
115
127
|
try {
|
|
116
|
-
catalogue = await
|
|
128
|
+
catalogue = await readCodexCatalogue(fetchPage, timeoutMs);
|
|
117
129
|
} catch (err) {
|
|
118
130
|
const why = err instanceof Error ? err.message : String(err);
|
|
119
131
|
throw new Error(`cannot check codex model ${pair.model} / effort ${pair.effort}: ${why}`);
|
|
120
|
-
} finally {
|
|
121
|
-
clearTimeout(timer);
|
|
122
132
|
}
|
|
123
133
|
const efforts = catalogue.get(pair.model);
|
|
124
134
|
if (efforts === undefined) {
|
|
125
135
|
throw new Error(
|
|
126
136
|
`codex model ${pair.model} is absent from the catalogue of THIS codex (has: ${[...catalogue.keys()].join(", ")}) — ` +
|
|
127
|
-
"
|
|
137
|
+
"run `viber-gateway refresh-models` (it updates codex) or re-edit the template",
|
|
128
138
|
);
|
|
129
139
|
}
|
|
130
140
|
if (!efforts.includes(pair.effort)) {
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #747 — the ONE function that refreshes the codex model catalogue of this machine's owner.
|
|
3
|
+
*
|
|
4
|
+
* Called by exactly two triggers, never anything else (JP, 2026-11-18):
|
|
5
|
+
* - the Viber app at startup (in the background: it never delays the runner);
|
|
6
|
+
* - `viber-gateway refresh-models`, which the owner's agent runs when told a model came out,
|
|
7
|
+
* or when a role write is refused "not available".
|
|
8
|
+
* No periodic check, no second path.
|
|
9
|
+
*
|
|
10
|
+
* Steps: update the codex CLI when npm has a newer one (only when codex came from npm) →
|
|
11
|
+
* `model/list` of the installed codex → PUT the catalogue to viber-api with the runner token.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { readCodexCatalogue, type ModelListPage } from "./codex_model_pair.ts";
|
|
15
|
+
import { cfAccessHeaders } from "./cfAccess.ts";
|
|
16
|
+
import { exec, execFile, spawn } from "./hidden_proc.ts";
|
|
17
|
+
import { loadRunnerAuth } from "./runner_stream.ts";
|
|
18
|
+
|
|
19
|
+
export const CODEX_NPM_PACKAGE = "@openai/codex";
|
|
20
|
+
/** One deadline over the WHOLE app-server exchange, initialize included (Opus review). */
|
|
21
|
+
const APP_SERVER_TIMEOUT_MS = 30_000;
|
|
22
|
+
const SHELL_TIMEOUT_MS = 5 * 60_000;
|
|
23
|
+
|
|
24
|
+
export type Catalogue = Record<string, string[]>;
|
|
25
|
+
|
|
26
|
+
export interface RefreshDeps {
|
|
27
|
+
/** `codex --version` → "0.170.0", or null when codex is not installed. */
|
|
28
|
+
installedVersion(): Promise<string | null>;
|
|
29
|
+
/** The version npm calls latest, or null when npm cannot answer. */
|
|
30
|
+
npmLatest(): Promise<string | null>;
|
|
31
|
+
/** The codex on PATH, and whether it lives in npm's global prefix (only then do we update it). */
|
|
32
|
+
pathCodex(): Promise<{ path: string | null; npmOwned: boolean }>;
|
|
33
|
+
/** `npm i -g @openai/codex@<version>`; throws on failure. */
|
|
34
|
+
npmInstall(version: string): Promise<void>;
|
|
35
|
+
/** `model/list` of the installed codex, in its order. */
|
|
36
|
+
readCatalogue(): Promise<Catalogue>;
|
|
37
|
+
/** PUT the catalogue; answers the model names it replaced (null: none before). Throws on a refusal. */
|
|
38
|
+
upload(cliVersion: string, models: Catalogue): Promise<string[] | null>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface RefreshReport {
|
|
42
|
+
ok: boolean;
|
|
43
|
+
/** One line per fact, in order — what the verb prints and the app logs. */
|
|
44
|
+
lines: string[];
|
|
45
|
+
before?: string | null;
|
|
46
|
+
after?: string;
|
|
47
|
+
added: string[];
|
|
48
|
+
removed: string[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Numeric dotted compare; a pre-release tag (0.171.0-alpha.1) is never "newer" than its release. */
|
|
52
|
+
export function isNewer(candidate: string, installed: string): boolean {
|
|
53
|
+
const parse = (v: string): number[] | null => {
|
|
54
|
+
if (!/^\d+(\.\d+)*$/.test(v)) return null;
|
|
55
|
+
return v.split(".").map(Number);
|
|
56
|
+
};
|
|
57
|
+
const a = parse(candidate);
|
|
58
|
+
const b = parse(installed);
|
|
59
|
+
if (a === null || b === null) return false;
|
|
60
|
+
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
|
61
|
+
const d = (a[i] ?? 0) - (b[i] ?? 0);
|
|
62
|
+
if (d !== 0) return d > 0;
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function why(err: unknown): string {
|
|
68
|
+
return err instanceof Error ? err.message : String(err);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Update the CLI when npm has newer; returns the version installed afterwards (or null). */
|
|
72
|
+
async function updateCli(deps: RefreshDeps, before: string | null, lines: string[]): Promise<string | null> {
|
|
73
|
+
// Opus review: an absent codex is never installed — the refresh updates, it does not provision.
|
|
74
|
+
if (before === null) return null;
|
|
75
|
+
const latest = await deps.npmLatest().catch(() => null);
|
|
76
|
+
if (latest === null) {
|
|
77
|
+
lines.push("npm: latest codex version unknown — CLI left as is");
|
|
78
|
+
return before;
|
|
79
|
+
}
|
|
80
|
+
if (!isNewer(latest, before)) {
|
|
81
|
+
lines.push(`codex ${before} is up to date (npm latest ${latest})`);
|
|
82
|
+
return before;
|
|
83
|
+
}
|
|
84
|
+
const onPath = await deps.pathCodex().catch(() => ({ path: null, npmOwned: false }));
|
|
85
|
+
if (!onPath.npmOwned) {
|
|
86
|
+
lines.push(`codex ${before} on PATH (${onPath.path ?? "unknown"}) is not npm's global install — not updated (npm latest ${latest})`);
|
|
87
|
+
return before;
|
|
88
|
+
}
|
|
89
|
+
// JP (2026-11-18): updated even while codex agents run. On Windows a running codex.exe is
|
|
90
|
+
// locked and the install may fail — the failure is said in clear (the owner then stops the
|
|
91
|
+
// codex agents and re-runs), never skipped in silence.
|
|
92
|
+
try {
|
|
93
|
+
await deps.npmInstall(latest);
|
|
94
|
+
} catch (err) {
|
|
95
|
+
lines.push(
|
|
96
|
+
`codex update to ${latest} FAILED: ${why(err)} — if codex agents are running, stop them and run viber-gateway refresh-models again`,
|
|
97
|
+
);
|
|
98
|
+
return before;
|
|
99
|
+
}
|
|
100
|
+
const after = await deps.installedVersion();
|
|
101
|
+
lines.push(`codex updated: ${before} -> ${after ?? "absent"}`);
|
|
102
|
+
return after;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export async function refreshCodexModels(deps: RefreshDeps): Promise<RefreshReport> {
|
|
106
|
+
const lines: string[] = [];
|
|
107
|
+
const report = (ok: boolean, extra: Partial<RefreshReport> = {}): RefreshReport => ({
|
|
108
|
+
ok,
|
|
109
|
+
lines,
|
|
110
|
+
added: [],
|
|
111
|
+
removed: [],
|
|
112
|
+
...extra,
|
|
113
|
+
});
|
|
114
|
+
const before = await deps.installedVersion();
|
|
115
|
+
const version = await updateCli(deps, before, lines);
|
|
116
|
+
if (version === null) {
|
|
117
|
+
lines.push("codex is not installed: no model list to send");
|
|
118
|
+
return report(false, { before });
|
|
119
|
+
}
|
|
120
|
+
let models: Catalogue;
|
|
121
|
+
try {
|
|
122
|
+
models = await deps.readCatalogue();
|
|
123
|
+
} catch (err) {
|
|
124
|
+
lines.push(`model/list of codex ${version} FAILED: ${why(err)} — nothing sent`);
|
|
125
|
+
return report(false, { before, after: version });
|
|
126
|
+
}
|
|
127
|
+
if (Object.keys(models).length === 0) {
|
|
128
|
+
lines.push(`model/list of codex ${version} is empty — nothing sent`);
|
|
129
|
+
return report(false, { before, after: version });
|
|
130
|
+
}
|
|
131
|
+
let previous: string[] | null;
|
|
132
|
+
try {
|
|
133
|
+
previous = await deps.upload(version, models);
|
|
134
|
+
} catch (err) {
|
|
135
|
+
lines.push(`sending the model list FAILED: ${why(err)}`);
|
|
136
|
+
return report(false, { before, after: version });
|
|
137
|
+
}
|
|
138
|
+
const names = Object.keys(models);
|
|
139
|
+
const added = previous === null ? names : names.filter((m) => !previous.includes(m));
|
|
140
|
+
const removed = previous === null ? [] : previous.filter((m) => !(m in models));
|
|
141
|
+
lines.push(`codex ${version}: ${names.length} model(s) sent — ${names.join(", ")}`);
|
|
142
|
+
if (previous !== null) {
|
|
143
|
+
lines.push(`added: ${added.length > 0 ? added.join(", ") : "none"}; removed: ${removed.length > 0 ? removed.join(", ") : "none"}`);
|
|
144
|
+
}
|
|
145
|
+
return report(true, { before, after: version, added, removed });
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// ── production deps ────────────────────────────────────────────────────────────────────────
|
|
149
|
+
|
|
150
|
+
function shell(command: string): Promise<string> {
|
|
151
|
+
return new Promise((resolve, reject) => {
|
|
152
|
+
exec(command, { timeout: SHELL_TIMEOUT_MS }, (err, stdout, stderr) => {
|
|
153
|
+
if (err) reject(new Error(`${command}: ${String(stderr || err.message).trim().split("\n")[0]}`));
|
|
154
|
+
else resolve(String(stdout).trim());
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Whether `path` lies inside `dir` (case-insensitive on Windows). */
|
|
160
|
+
export function isUnder(path: string, dir: string, win: boolean = process.platform === "win32"): boolean {
|
|
161
|
+
const norm = (p: string): string => {
|
|
162
|
+
const q = p.replace(/\\/g, "/").replace(/\/+$/, "");
|
|
163
|
+
return win ? q.toLowerCase() : q;
|
|
164
|
+
};
|
|
165
|
+
return norm(path).startsWith(`${norm(dir)}/`);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** The file `bin` runs: a path as given, a bare name through `lookup` (PATH); null if unknown. */
|
|
169
|
+
export async function resolveCodexBin(bin: string, lookup: (name: string) => Promise<string | null>): Promise<string | null> {
|
|
170
|
+
if (/[\\/]/.test(bin)) return bin;
|
|
171
|
+
if (!/^[A-Za-z0-9._-]+$/.test(bin)) return null; // never hand an odd name to a shell
|
|
172
|
+
return lookup(bin);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* `<bin> --version` → its version, or null. The binary runs WITHOUT a shell (Codex review): an
|
|
177
|
+
* override with spaces (C:/Program Files/…) stays one argument, and no metacharacter reaches a shell.
|
|
178
|
+
*/
|
|
179
|
+
export async function codexVersionOf(
|
|
180
|
+
bin: string,
|
|
181
|
+
run: (file: string, args: string[]) => Promise<string>,
|
|
182
|
+
): Promise<string | null> {
|
|
183
|
+
return parseCodexVersion(await run(bin, ["--version"]).catch(() => ""));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function runFile(file: string, args: string[]): Promise<string> {
|
|
187
|
+
return new Promise((resolve, reject) => {
|
|
188
|
+
execFile(file, args, { timeout: SHELL_TIMEOUT_MS }, (err, stdout) => {
|
|
189
|
+
if (err) reject(err);
|
|
190
|
+
else resolve(String(stdout).trim());
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function codexBin(): string {
|
|
196
|
+
return process.env.VIBER_CODEX_BIN?.trim() || "codex";
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** `codex-cli 0.170.0` → "0.170.0". */
|
|
200
|
+
export function parseCodexVersion(out: string): string | null {
|
|
201
|
+
return /(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)/.exec(out)?.[1] ?? null;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* One `codex app-server`, initialize, walk `model/list`, then kill it. Spawned like the bridge
|
|
206
|
+
* spawns it (no shell): with a shell, `kill()` would end the shell and orphan the app-server.
|
|
207
|
+
*/
|
|
208
|
+
async function readCatalogueFromAppServer(): Promise<Catalogue> {
|
|
209
|
+
const child = spawn(codexBin(), ["app-server"], { stdio: ["pipe", "pipe", "pipe"] });
|
|
210
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
211
|
+
const deadline = new Promise<never>((_, reject) => {
|
|
212
|
+
timer = setTimeout(
|
|
213
|
+
() => reject(new Error(`codex app-server did not answer within ${APP_SERVER_TIMEOUT_MS} ms`)),
|
|
214
|
+
APP_SERVER_TIMEOUT_MS,
|
|
215
|
+
);
|
|
216
|
+
});
|
|
217
|
+
const pending = new Map<number, { resolve: (v: unknown) => void; reject: (e: Error) => void }>();
|
|
218
|
+
let buffer = "";
|
|
219
|
+
let nextId = 1;
|
|
220
|
+
child.stdout.setEncoding("utf-8");
|
|
221
|
+
child.stdout.on("data", (chunk: string) => {
|
|
222
|
+
buffer += chunk;
|
|
223
|
+
for (let nl = buffer.indexOf("\n"); nl !== -1; nl = buffer.indexOf("\n")) {
|
|
224
|
+
const line = buffer.slice(0, nl).trim();
|
|
225
|
+
buffer = buffer.slice(nl + 1);
|
|
226
|
+
if (line === "") continue;
|
|
227
|
+
let msg: { id?: unknown; result?: unknown; error?: { message?: string } };
|
|
228
|
+
try {
|
|
229
|
+
msg = JSON.parse(line);
|
|
230
|
+
} catch {
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
const waiter = typeof msg.id === "number" ? pending.get(msg.id) : undefined;
|
|
234
|
+
if (waiter === undefined) continue;
|
|
235
|
+
pending.delete(msg.id as number);
|
|
236
|
+
if (msg.error) waiter.reject(new Error(msg.error.message ?? "RPC error"));
|
|
237
|
+
else waiter.resolve(msg.result);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
child.on("exit", (code) => {
|
|
241
|
+
for (const w of pending.values()) w.reject(new Error(`codex app-server exited (${code})`));
|
|
242
|
+
pending.clear();
|
|
243
|
+
});
|
|
244
|
+
child.on("error", (err) => {
|
|
245
|
+
for (const w of pending.values()) w.reject(err);
|
|
246
|
+
pending.clear();
|
|
247
|
+
});
|
|
248
|
+
const request = (method: string, params: unknown): Promise<unknown> =>
|
|
249
|
+
new Promise((resolve, reject) => {
|
|
250
|
+
const id = nextId++;
|
|
251
|
+
pending.set(id, { resolve, reject });
|
|
252
|
+
child.stdin.write(`${JSON.stringify({ id, method, params })}\n`);
|
|
253
|
+
});
|
|
254
|
+
const exchange = async (): Promise<Catalogue> => {
|
|
255
|
+
await request("initialize", { clientInfo: { name: "viber-refresh-models", title: "Viber", version: "0.1.0" } });
|
|
256
|
+
child.stdin.write(`${JSON.stringify({ method: "initialized" })}\n`);
|
|
257
|
+
const catalogue = await readCodexCatalogue(
|
|
258
|
+
async (cursor) => (await request("model/list", { cursor, includeHidden: false })) as ModelListPage,
|
|
259
|
+
APP_SERVER_TIMEOUT_MS,
|
|
260
|
+
);
|
|
261
|
+
return Object.fromEntries(catalogue);
|
|
262
|
+
};
|
|
263
|
+
const run = exchange();
|
|
264
|
+
run.catch(() => {}); // past the deadline its own rejection has nobody left to tell
|
|
265
|
+
try {
|
|
266
|
+
return await Promise.race([run, deadline]);
|
|
267
|
+
} finally {
|
|
268
|
+
clearTimeout(timer);
|
|
269
|
+
child.kill();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** The production deps, against this machine's runner identity (`<home>/.viber/runner.json`). */
|
|
274
|
+
export function productionRefreshDeps(home: string): RefreshDeps {
|
|
275
|
+
const auth = loadRunnerAuth(home);
|
|
276
|
+
const url = `${auth.base_url}/api/runners/${auth.runner_id}/codex-models`;
|
|
277
|
+
const headers = () => ({ Authorization: `Bearer ${auth.runner_token}`, ...cfAccessHeaders() });
|
|
278
|
+
return {
|
|
279
|
+
installedVersion: () => codexVersionOf(codexBin(), runFile),
|
|
280
|
+
npmLatest: async () => parseCodexVersion(await shell(`npm view ${CODEX_NPM_PACKAGE} version`)),
|
|
281
|
+
pathCodex: async () => {
|
|
282
|
+
// Codex review: the codex judged is the one model/list runs — codexBin(), the
|
|
283
|
+
// VIBER_CODEX_BIN override included. Only a bare name is looked up on PATH.
|
|
284
|
+
const found = await resolveCodexBin(codexBin(), async (name) => {
|
|
285
|
+
const where = process.platform === "win32" ? `where ${name}` : `command -v ${name}`;
|
|
286
|
+
return (await shell(where).catch(() => "")).split(/\r?\n/)[0]?.trim() || null;
|
|
287
|
+
});
|
|
288
|
+
const prefix = await shell("npm prefix -g").catch(() => "");
|
|
289
|
+
return { path: found, npmOwned: found !== null && prefix !== "" && isUnder(found, prefix) };
|
|
290
|
+
},
|
|
291
|
+
npmInstall: async (version) => {
|
|
292
|
+
if (!/^\d+\.\d+\.\d+$/.test(version)) throw new Error(`refusing to install version "${version}"`);
|
|
293
|
+
await shell(`npm i -g ${CODEX_NPM_PACKAGE}@${version}`);
|
|
294
|
+
},
|
|
295
|
+
readCatalogue: readCatalogueFromAppServer,
|
|
296
|
+
upload: async (cliVersion, models) => {
|
|
297
|
+
const res = await fetch(url, {
|
|
298
|
+
method: "PUT",
|
|
299
|
+
redirect: "error",
|
|
300
|
+
headers: { ...headers(), "Content-Type": "application/json" },
|
|
301
|
+
body: JSON.stringify({ cli_version: cliVersion, models }),
|
|
302
|
+
});
|
|
303
|
+
if (!res.ok) throw new Error(`${res.status} ${(await res.text()).slice(0, 200)}`);
|
|
304
|
+
const body = (await res.json()) as { previous?: unknown };
|
|
305
|
+
return Array.isArray(body.previous) ? body.previous.filter((m): m is string => typeof m === "string") : null;
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* THE entry point both triggers call — the app at startup and `viber-gateway refresh-models` —
|
|
312
|
+
* so they cannot drift apart. Never throws: a missing runner.json is a failed report too.
|
|
313
|
+
*/
|
|
314
|
+
export async function refreshCodexModelsFor(home: string): Promise<RefreshReport> {
|
|
315
|
+
let deps: RefreshDeps;
|
|
316
|
+
try {
|
|
317
|
+
deps = productionRefreshDeps(home);
|
|
318
|
+
} catch (err) {
|
|
319
|
+
return { ok: false, lines: [`this machine is not enrolled (${why(err)}) — nothing sent`], added: [], removed: [] };
|
|
320
|
+
}
|
|
321
|
+
try {
|
|
322
|
+
return await refreshCodexModels(deps);
|
|
323
|
+
} catch (err) {
|
|
324
|
+
return { ok: false, lines: [`refresh FAILED: ${why(err)}`], added: [], removed: [] };
|
|
325
|
+
}
|
|
326
|
+
}
|
package/lib/team_role_tool.ts
CHANGED
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import type { AgentToolResult, AgentToolsContext } from "./agent_tools.js";
|
|
14
14
|
import { callAgentAdmin, errorText, type AdminRequest } from "./agent_admin_call.js";
|
|
15
|
-
import { CODEX_DEFAULT_PAIR } from "./codex_default.js";
|
|
16
15
|
|
|
17
16
|
export const TEAM_ROLE_ACTIONS = ["list", "get", "create", "update", "delete"] as const;
|
|
18
17
|
type Action = (typeof TEAM_ROLE_ACTIONS)[number];
|
|
@@ -64,7 +63,7 @@ export const TEAM_ROLES_TOOL_DEF = {
|
|
|
64
63
|
type: ["string", "null"],
|
|
65
64
|
description:
|
|
66
65
|
"claude: leave model and effort OUT (the runtime picks its own default) UNLESS the owner explicitly asks; model is a family (opus, sonnet, haiku or fable). " +
|
|
67
|
-
|
|
66
|
+
"codex: model AND effort are REQUIRED — a model the owner's codex lists (a refusal names them; `viber-gateway refresh-models` sends a new one), effort low unless the owner asks. Full rules: the capabilities tool.",
|
|
68
67
|
},
|
|
69
68
|
effort: {
|
|
70
69
|
type: ["string", "null"],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "viber-channel",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.47",
|
|
4
4
|
"description": "Voice + text MCP channel between a Claude Code session and the Viber UI (https://viber.dgypx.dev). Push transcripts to Claude; send_message tool delivers text back to the UI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/lib/codex_default.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The codex model/effort pair an agent uses when the owner names none (#665) — ONE
|
|
3
|
-
* place in the channel. It was written as prose three times (capabilities twice, the
|
|
4
|
-
* team_roles description once; debt noted in PR 675, closed in #673). It must equal the
|
|
5
|
-
* API's `CODEX_DEFAULT_MODEL` / `CODEX_DEFAULT_EFFORT` (viber-api/src/db/roleFields.ts):
|
|
6
|
-
* a test reads them from there.
|
|
7
|
-
*/
|
|
8
|
-
export const CODEX_DEFAULT_MODEL = "gpt-5.6-sol";
|
|
9
|
-
export const CODEX_DEFAULT_EFFORT = "low";
|
|
10
|
-
/** As the texts write it: `gpt-5.6-sol / low`. */
|
|
11
|
-
export const CODEX_DEFAULT_PAIR = `${CODEX_DEFAULT_MODEL} / ${CODEX_DEFAULT_EFFORT}`;
|