@tiens.nguyen/gu-cli 1.0.916 → 1.0.917
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/client-expert-run.mjs +74 -40
- package/coding-key-prompt.mjs +24 -1
- package/coding-provider-setup.mjs +24 -0
- package/first-hi.mjs +80 -0
- package/gu-repl.mjs +33 -3
- package/model-setup-ui.mjs +52 -0
- package/ollama-setup.mjs +14 -0
- package/package.json +2 -1
package/client-expert-run.mjs
CHANGED
|
@@ -49,8 +49,12 @@ import {
|
|
|
49
49
|
parseModelSetupChoice,
|
|
50
50
|
providerChoiceMenu,
|
|
51
51
|
parseProviderChoice,
|
|
52
|
+
startMenu,
|
|
53
|
+
parseStartChoice,
|
|
54
|
+
keyProviderMenu,
|
|
55
|
+
parseKeyProvider,
|
|
52
56
|
} from "./model-setup-ui.mjs";
|
|
53
|
-
import { providerPresets } from "./coding-provider-setup.mjs";
|
|
57
|
+
import { providerPresets, detectProvider } from "./coding-provider-setup.mjs";
|
|
54
58
|
import { presetFilesIn } from "./presets-transfer.mjs";
|
|
55
59
|
import { readdirSync, statSync, readFileSync } from "node:fs";
|
|
56
60
|
import { parseOllamaTags, formatSize } from "./agent-model-command.mjs";
|
|
@@ -1542,52 +1546,79 @@ export async function runClientExpertSetup({
|
|
|
1542
1546
|
console.log(dim(" server this machine uses."));
|
|
1543
1547
|
throw new SkipModelQuestion();
|
|
1544
1548
|
}
|
|
1545
|
-
//
|
|
1546
|
-
//
|
|
1547
|
-
//
|
|
1549
|
+
// ONE START QUESTION (#490): what the person brings — a key, a free-model code, their own model, or nothing
|
|
1550
|
+
// yet. Enter = their own / the shared Ollama, which is what Enter has always meant here. A key, a code
|
|
1551
|
+
// or a preset is HANDED to gu itself (the terminal those flows need does not exist yet).
|
|
1548
1552
|
const presets = countSavedPresets();
|
|
1549
1553
|
console.log("");
|
|
1550
|
-
const [title, ...rows] =
|
|
1554
|
+
const [title, ...rows] = startMenu({ presets });
|
|
1551
1555
|
console.log(" " + bold(title));
|
|
1552
1556
|
for (const r of rows) console.log(dim(" " + r));
|
|
1553
|
-
let
|
|
1554
|
-
for (let t = 0; t < 3 && !
|
|
1555
|
-
|
|
1556
|
-
if (
|
|
1557
|
-
console.log(dim(" No presets saved yet. Save one later with /save-preset — pick
|
|
1558
|
-
|
|
1557
|
+
let start = null;
|
|
1558
|
+
for (let t = 0; t < 3 && !start; t++) {
|
|
1559
|
+
start = parseStartChoice(await askStep(" choose [3]: "));
|
|
1560
|
+
if (start === "preset" && presets === 0) {
|
|
1561
|
+
console.log(dim(" No presets saved yet. Save one later with /save-preset — pick another for now."));
|
|
1562
|
+
start = null;
|
|
1559
1563
|
}
|
|
1560
1564
|
}
|
|
1561
|
-
|
|
1562
|
-
if (
|
|
1563
|
-
chosenModels = { skipped: true, keys: [], loadPreset:
|
|
1565
|
+
start = start ?? "own";
|
|
1566
|
+
if (start === "later" || start === "preset") {
|
|
1567
|
+
chosenModels = { skipped: true, keys: [], loadPreset: start === "preset" };
|
|
1564
1568
|
throw new SkipModelQuestion();
|
|
1565
1569
|
}
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
// asks the key and then the model once gu starts — the terminal that flow needs does not exist yet.
|
|
1569
|
-
const provPresets = providerPresets("coding");
|
|
1570
|
-
console.log("");
|
|
1571
|
-
const [ptitle, ...prows] = providerChoiceMenu(provPresets);
|
|
1572
|
-
console.log(" " + bold(ptitle));
|
|
1573
|
-
for (const r of prows) console.log(dim(" " + r));
|
|
1574
|
-
let provider = null;
|
|
1575
|
-
for (let t = 0; t < 3 && !provider; t++) {
|
|
1576
|
-
provider = parseProviderChoice(await askStep(" choose [1]: "), provPresets);
|
|
1577
|
-
}
|
|
1578
|
-
provider = provider ?? { kind: "ollama" };
|
|
1579
|
-
if (provider.kind === "skip") {
|
|
1580
|
-
chosenModels = { skipped: true, keys: [], loadPreset: false };
|
|
1570
|
+
if (start === "free") {
|
|
1571
|
+
chosenModels = { skipped: true, keys: [], voucherAtStart: true };
|
|
1581
1572
|
throw new SkipModelQuestion();
|
|
1582
1573
|
}
|
|
1583
|
-
if (
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1574
|
+
if (start === "key") {
|
|
1575
|
+
// WHICH PROVIDER the key is for (#132 follow-up): picked from the presets or typed. That pick is HANDED
|
|
1576
|
+
// to gu's own add-provider flow, which asks the key (and now checks it, #492) and the model once gu starts.
|
|
1577
|
+
const provPresets = providerPresets("coding");
|
|
1578
|
+
// #491: PASTE THE KEY FIRST. Its shape usually names the provider, which saves the provider list. The guess
|
|
1579
|
+
// is always shown with the address the key would go to and confirmed: a key sent to the wrong company is
|
|
1580
|
+
// a key given away. The key is kept in memory only and handed to gu, which checks it (lists the models)
|
|
1581
|
+
// and saves it — it is never printed.
|
|
1582
|
+
let pasted = "";
|
|
1583
|
+
let provider = null;
|
|
1584
|
+
let backedOut = false;
|
|
1585
|
+
if (typeof askSecret === "function") {
|
|
1586
|
+
console.log(dim(" Paste your key and gu works out the provider — or press Enter to choose from a list."));
|
|
1587
|
+
const raw = await askSecret(" API key: ");
|
|
1588
|
+
if (raw === SKIP_ALL) backedOut = true;
|
|
1589
|
+
else pasted = String(raw ?? "").trim();
|
|
1590
|
+
const guess = pasted ? detectProvider(pasted, provPresets) : null;
|
|
1591
|
+
if (guess) {
|
|
1592
|
+
const where = (() => { try { return new URL(guess.url).host; } catch { return guess.url; } })();
|
|
1593
|
+
const yn = await askStep(` That looks like a ${guess.name} key. Send it to ${where}? [Y/n]: `);
|
|
1594
|
+
if (yn === SKIP_ALL) backedOut = true;
|
|
1595
|
+
else if (/^(|y|yes)$/i.test(String(yn ?? "").trim())) provider = { kind: "preset", preset: guess };
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
if (!provider && !backedOut) {
|
|
1599
|
+
console.log("");
|
|
1600
|
+
const [ptitle, ...prows] = keyProviderMenu(provPresets);
|
|
1601
|
+
console.log(" " + bold(ptitle));
|
|
1602
|
+
for (const r of prows) console.log(dim(" " + r));
|
|
1603
|
+
for (let t = 0; t < 3 && !provider; t++) {
|
|
1604
|
+
provider = parseKeyProvider(await askStep(" choose: "), provPresets);
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
provider = provider ?? { kind: "skip" };
|
|
1608
|
+
if (provider.kind === "skip") {
|
|
1609
|
+
chosenModels = { skipped: true, keys: [], loadPreset: false };
|
|
1610
|
+
} else {
|
|
1611
|
+
chosenModels = {
|
|
1612
|
+
skipped: true,
|
|
1613
|
+
keys: [],
|
|
1614
|
+
addProvider: {
|
|
1615
|
+
...(provider.kind === "preset"
|
|
1616
|
+
? { name: provider.preset.name, url: provider.preset.url, dialect: provider.preset.dialect ?? "openai" }
|
|
1617
|
+
: { name: "", url: "", dialect: "openai" }),
|
|
1618
|
+
...(pasted ? { key: pasted } : {}),
|
|
1619
|
+
},
|
|
1620
|
+
};
|
|
1621
|
+
}
|
|
1591
1622
|
throw new SkipModelQuestion();
|
|
1592
1623
|
}
|
|
1593
1624
|
console.log("");
|
|
@@ -1638,6 +1669,7 @@ export async function runClientExpertSetup({
|
|
|
1638
1669
|
const skipModels = Boolean(chosenModels?.skipped);
|
|
1639
1670
|
const loadPreset = Boolean(chosenModels?.loadPreset);
|
|
1640
1671
|
const addProvider = chosenModels?.addProvider ?? null;
|
|
1672
|
+
const voucherAtStart = Boolean(chosenModels?.voucherAtStart);
|
|
1641
1673
|
|
|
1642
1674
|
try {
|
|
1643
1675
|
const written = await seedSettings({
|
|
@@ -1660,8 +1692,10 @@ export async function runClientExpertSetup({
|
|
|
1660
1692
|
console.log("");
|
|
1661
1693
|
// "skipped" is only true when nothing was chosen: a provider that was picked is NOT skipped,
|
|
1662
1694
|
// its key and model are just asked in gu itself (GH #397).
|
|
1663
|
-
console.log(" " + cyan(addProvider ? `✓ ${addProvider.name || "Provider"} chosen` : "✓ Model setup skipped") + dim(addProvider
|
|
1664
|
-
? " — gu asks for its key and model as soon as it starts"
|
|
1695
|
+
console.log(" " + cyan(addProvider ? `✓ ${addProvider.name || "Provider"} chosen` : voucherAtStart ? "✓ Free model chosen" : "✓ Model setup skipped") + dim(addProvider
|
|
1696
|
+
? (addProvider.key ? " — gu checks your key and lists its models as soon as it starts" : " — gu asks for its key and model as soon as it starts")
|
|
1697
|
+
: voucherAtStart
|
|
1698
|
+
? " — gu asks for your code as soon as it starts"
|
|
1665
1699
|
: loadPreset
|
|
1666
1700
|
? " — the preset picker opens as soon as gu starts"
|
|
1667
1701
|
: " — set them any time with /model (or /use-presets)"));
|
|
@@ -1714,5 +1748,5 @@ export async function runClientExpertSetup({
|
|
|
1714
1748
|
);
|
|
1715
1749
|
// #301: the caller opens /use-presets once the terminal exists — the picker, the plan and the
|
|
1716
1750
|
// confirmation are that command's, not rebuilt here.
|
|
1717
|
-
return { complete: true, stoppedAt: null, ...(loadPreset ? { loadPreset: true } : {}), ...(addProvider ? { addProvider } : {}) };
|
|
1751
|
+
return { complete: true, stoppedAt: null, ...(loadPreset ? { loadPreset: true } : {}), ...(addProvider ? { addProvider } : {}), ...(voucherAtStart ? { voucherAtStart: true } : {}) };
|
|
1718
1752
|
}
|
package/coding-key-prompt.mjs
CHANGED
|
@@ -25,6 +25,7 @@ const identity = (s) => s;
|
|
|
25
25
|
* added to one of them would have left the other exactly as confusing.
|
|
26
26
|
*/
|
|
27
27
|
import { keyInUse } from "./server-keys.mjs";
|
|
28
|
+
import { resultLine } from "./first-hi.mjs";
|
|
28
29
|
|
|
29
30
|
export const SECRET_KEY_HINT = "type or paste the key, then press Enter — it stays masked";
|
|
30
31
|
|
|
@@ -92,7 +93,7 @@ export function codingNeedsKey(kind, url) {
|
|
|
92
93
|
* model/url are present whenever the coder became usable, so the caller can fix the
|
|
93
94
|
* already-printed banner and the bottom bar (task #190).
|
|
94
95
|
*/
|
|
95
|
-
export async function promptCodingKeyIfMissing(payload, { askSecret, saveCodingKey, log, colors = {} }) {
|
|
96
|
+
export async function promptCodingKeyIfMissing(payload, { askSecret, saveCodingKey, log, colors = {}, checkKey = null }) {
|
|
96
97
|
const dim = colors.dim ?? identity;
|
|
97
98
|
const cyan = colors.cyan ?? identity;
|
|
98
99
|
const red = colors.red ?? identity;
|
|
@@ -130,6 +131,28 @@ export async function promptCodingKeyIfMissing(payload, { askSecret, saveCodingK
|
|
|
130
131
|
? cyan(` ✓ saved — ${model} is now your coding model.\n`)
|
|
131
132
|
: red(" couldn't save the key — try again next start, or set it in web Settings → Agent.\n")
|
|
132
133
|
);
|
|
134
|
+
// #492: one real "hi" with the key just saved, so a wrong key or a blocked region is told NOW. A key that
|
|
135
|
+
// fails with 401/403 may be re-entered once; any other failure keeps the key and says what to try.
|
|
136
|
+
// Ollama's cloud is left out: its API dialect is not the one this check speaks.
|
|
137
|
+
if (ok && checkKey && !isOllamaCloudUrl(payload.codingKeyUrl)) {
|
|
138
|
+
let used = key;
|
|
139
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
140
|
+
log(dim(" checking the key…"));
|
|
141
|
+
const r = await checkKey(used, model, payload.codingKeyUrl);
|
|
142
|
+
const line = ` ${resultLine(r, model)}`;
|
|
143
|
+
if (r.ok) { log(cyan(line + "\n")); break; }
|
|
144
|
+
log(red(line));
|
|
145
|
+
if (attempt === 1 || (r.status !== 401 && r.status !== 403)) {
|
|
146
|
+
log(dim(" The key is saved. Check it with `gu doctor`, or change it with ctrl+k in /model.\n"));
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
log(dim(" Paste a different key, or press Enter to keep this one."));
|
|
150
|
+
const again = await askSecret(` ${model} API key: `);
|
|
151
|
+
if (!again) { log(""); break; }
|
|
152
|
+
if (!(await saveCodingKey(again))) { log(red(" couldn't save the key — set it in /model with ctrl+k.\n")); break; }
|
|
153
|
+
used = again;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
133
156
|
return { asked: true, saved: ok, model, url: payload.codingKeyUrl };
|
|
134
157
|
}
|
|
135
158
|
|
|
@@ -260,6 +260,8 @@ export function providerPresets(role = "coding") {
|
|
|
260
260
|
{ name: "Claude API (Anthropic)", url: CLAUDE_API_URL, roles: ["coding", "agent"] },
|
|
261
261
|
{ name: "OpenAI", url: DEFAULT_PROVIDER_URL, roles: ["coding", "agent", "embed"] },
|
|
262
262
|
{ name: "Kimi (Moonshot)", url: "https://api.moonshot.ai/v1", roles: ["coding", "agent"] },
|
|
263
|
+
// #490: DeepSeek is what many people already hold a key for. OpenAI-compatible, /v1 included.
|
|
264
|
+
{ name: "DeepSeek", url: "https://api.deepseek.com/v1", roles: ["coding", "agent"] },
|
|
263
265
|
// #132. Ollama's cloud speaks Ollama's own API (/api/tags), so the preset names its dialect.
|
|
264
266
|
{ name: "Ollama cloud", url: "https://ollama.com", dialect: "ollama", roles: ["coding", "agent"] },
|
|
265
267
|
// Qwen's two plans take DIFFERENT keys (Token Plan sk-sp-..., pay-as-you-go sk-ws-...), so the
|
|
@@ -270,6 +272,28 @@ export function providerPresets(role = "coding") {
|
|
|
270
272
|
return all.filter((p) => p.roles.includes(role));
|
|
271
273
|
}
|
|
272
274
|
|
|
275
|
+
/**
|
|
276
|
+
* WHICH PROVIDER A PASTED KEY BELONGS TO, from its shape (GH #491). → the preset from `presets`, or null.
|
|
277
|
+
*
|
|
278
|
+
* Only shapes that name ONE provider count. Many providers hand out a bare `sk-…`: OpenAI's older keys and
|
|
279
|
+
* Moonshot's look alike, so those return null and the person picks from the list. DeepSeek's are `sk-` and
|
|
280
|
+
* exactly 32 hex digits, which is distinctive.
|
|
281
|
+
*
|
|
282
|
+
* A guess is never acted on silently: the caller shows the provider's name and asks, because a key sent to
|
|
283
|
+
* the wrong company is a key given away.
|
|
284
|
+
*/
|
|
285
|
+
export function detectProvider(key, presets = providerPresets("coding")) {
|
|
286
|
+
const k = String(key ?? "").trim();
|
|
287
|
+
if (!k) return null;
|
|
288
|
+
const by = (name) => presets.find((p) => p.name === name) ?? null;
|
|
289
|
+
if (k.startsWith("sk-ant-")) return by("Claude API (Anthropic)");
|
|
290
|
+
if (k.startsWith("sk-sp-")) return by("Qwen Token Plan (OpenAI-compatible)");
|
|
291
|
+
if (k.startsWith("sk-ws-")) return by("Qwen pay-as-you-go (OpenAI-compatible)");
|
|
292
|
+
if (k.startsWith("sk-proj-") || k.startsWith("sk-svcacct-")) return by("OpenAI");
|
|
293
|
+
if (/^sk-[0-9a-f]{32}$/.test(k)) return by("DeepSeek");
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
|
|
273
297
|
/** mlx_lm's placeholder, which is a mapping and not a model anyone can pick. */
|
|
274
298
|
export const PLACEHOLDER_MODEL = "default_model";
|
|
275
299
|
|
package/first-hi.mjs
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE FIRST "hi" (GH #492) — right after a key is saved, ask the model one tiny question, so a wrong
|
|
3
|
+
* key, a blocked region or an empty allowance is told at setup and not on the first real question.
|
|
4
|
+
*
|
|
5
|
+
* Same idea and wording as the deploy app's "Model keys test" (electric-app-deploy/electron/modelKeysTest.ts):
|
|
6
|
+
* one small chat request with THAT provider's own key, and the answer explained in words a person can act on.
|
|
7
|
+
*
|
|
8
|
+
* The key never leaves this process except to the endpoint it belongs to: only https:// is used, and every
|
|
9
|
+
* text shown is scrubbed of the key, because a provider's error message can quote the key it refused.
|
|
10
|
+
*
|
|
11
|
+
* WHAT A GREEN LINE PROVES: this key and model work from THIS computer, now. Not that every region can.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export const FIRST_HI_TIMEOUT_MS = 45_000;
|
|
15
|
+
export const FIRST_HI_QUESTION = "hi";
|
|
16
|
+
|
|
17
|
+
/** Take the key out of a text. */
|
|
18
|
+
export function scrub(text, key) {
|
|
19
|
+
const k = String(key ?? "").trim();
|
|
20
|
+
const t = String(text ?? "");
|
|
21
|
+
return k.length >= 8 ? t.split(k).join("•••") : t;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** What a refusal means, for the person at the prompt. Pure. */
|
|
25
|
+
export function explain(status, providerMessage = "") {
|
|
26
|
+
const said = providerMessage ? ` The provider said: ${String(providerMessage).slice(0, 160)}` : "";
|
|
27
|
+
if (status === 401) return `The key was refused (wrong, revoked or expired).${said}`;
|
|
28
|
+
if (status === 403) return `Access denied: the key may not use this model, or this region is blocked (Claude refuses some regions).${said}`;
|
|
29
|
+
if (status === 404) return `The model name was not found at this endpoint.${said}`;
|
|
30
|
+
if (status === 429) return `Rate limited, or out of allowance.${said}`;
|
|
31
|
+
if (status >= 500) return `The provider had an error (${status}).${said}`;
|
|
32
|
+
return `The provider answered ${status}.${said}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const isObj = (v) => Boolean(v) && typeof v === "object" && !Array.isArray(v);
|
|
36
|
+
|
|
37
|
+
function providerMessage(body, text) {
|
|
38
|
+
if (isObj(body) && isObj(body.error) && typeof body.error.message === "string") return body.error.message;
|
|
39
|
+
if (isObj(body) && typeof body.message === "string") return body.message;
|
|
40
|
+
return String(text ?? "").slice(0, 160);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Ask `model` at `url` (an OpenAI-compatible base, e.g. https://api.openai.com/v1) "hi" with `key`.
|
|
45
|
+
* → { ok, status, ms, error } — never throws.
|
|
46
|
+
*/
|
|
47
|
+
export async function checkModel({ url, model, key, fetchImpl = fetch, timeoutMs = FIRST_HI_TIMEOUT_MS } = {}) {
|
|
48
|
+
const row = (over) => ({ ok: false, status: 0, ms: 0, error: "", ...over });
|
|
49
|
+
if (!/^https:\/\//i.test(String(url ?? ""))) return row({ error: "The endpoint is not https:// — not sending a key to it." });
|
|
50
|
+
if (!model) return row({ error: "No model is chosen." });
|
|
51
|
+
const started = Date.now();
|
|
52
|
+
try {
|
|
53
|
+
const res = await fetchImpl(`${String(url).replace(/\/+$/, "")}/chat/completions`, {
|
|
54
|
+
method: "POST",
|
|
55
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${key}` },
|
|
56
|
+
body: JSON.stringify({ model, messages: [{ role: "user", content: FIRST_HI_QUESTION }], max_tokens: 64 }),
|
|
57
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
58
|
+
});
|
|
59
|
+
const ms = Date.now() - started;
|
|
60
|
+
const text = await res.text().catch(() => "");
|
|
61
|
+
let body = null;
|
|
62
|
+
try { body = JSON.parse(text); } catch { /* not JSON */ }
|
|
63
|
+
if (!res.ok) return row({ status: res.status, ms, error: scrub(explain(res.status, providerMessage(body, text)), key) });
|
|
64
|
+
// A reasoning model can spend its small budget thinking and return no text: the key and model still work.
|
|
65
|
+
return row({ ok: true, status: res.status, ms });
|
|
66
|
+
} catch (e) {
|
|
67
|
+
const timedOut = e instanceof Error && (e.name === "TimeoutError" || e.name === "AbortError");
|
|
68
|
+
return row({
|
|
69
|
+
ms: Date.now() - started,
|
|
70
|
+
error: scrub(timedOut ? `No answer within ${Math.round(timeoutMs / 1000)} s.` : `Could not reach it: ${e instanceof Error ? e.message : String(e)}`, key),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The one line to print for a result. */
|
|
76
|
+
export function resultLine(r, model) {
|
|
77
|
+
return r.ok
|
|
78
|
+
? `✓ ready: ${model} answered in ${(r.ms / 1000).toFixed(1)} s`
|
|
79
|
+
: `✗ ${model} did not answer. ${r.error}`;
|
|
80
|
+
}
|
package/gu-repl.mjs
CHANGED
|
@@ -775,6 +775,8 @@ let clientExpertRanThisProcess = false;
|
|
|
775
775
|
let openPresetsAtStart = false;
|
|
776
776
|
// #132 follow-up: a hosted provider picked in first-run setup; its key and model are asked once the terminal exists.
|
|
777
777
|
let addProviderAtStart = null;
|
|
778
|
+
// #490: setup's "Free model" — gu asks for the code once the terminal exists.
|
|
779
|
+
let voucherAtStart = false;
|
|
778
780
|
|
|
779
781
|
// #220: a gu that STOPS ON AN ERROR says where help is — a start that failed (exit 1 before the
|
|
780
782
|
// prompt: no key, API unreachable, MongoDB down…) or a crash. One dim line, never during a session
|
|
@@ -927,6 +929,7 @@ if (!workerKey || !apiBase) {
|
|
|
927
929
|
const setup = await runClientExpertSetup({ ask: ask0, askStep: sp.askStep, askSecret: sp.askSecret });
|
|
928
930
|
if (setup.loadPreset) openPresetsAtStart = true;
|
|
929
931
|
if (setup.addProvider) addProviderAtStart = setup.addProvider;
|
|
932
|
+
if (setup.voucherAtStart) voucherAtStart = true;
|
|
930
933
|
// STOP when setup cannot go further.
|
|
931
934
|
//
|
|
932
935
|
// This used to fall through to the hosted sign-in, on the theory that "this machine
|
|
@@ -6851,7 +6854,8 @@ async function removeCodingProvider(ps, rows, p) {
|
|
|
6851
6854
|
* model skip listing and picking (/embed-model's curated list already chose; `plan` with it)
|
|
6852
6855
|
* newKey ask for a key even if the server has one (the stored one was refused)
|
|
6853
6856
|
*/
|
|
6854
|
-
async function addServer({ role = "coding", dialect = "openai", url: presetUrl = "", model: presetModel = "", plan: presetPlan = null, newKey = false, back = false } = {}) {
|
|
6857
|
+
async function addServer({ role = "coding", dialect = "openai", url: presetUrl = "", model: presetModel = "", plan: presetPlan = null, newKey = false, back = false, pastedKey = "" } = {}) {
|
|
6858
|
+
let pastedLeft = String(pastedKey ?? ""); // #491: a key pasted at first-run setup — used once, never asked for twice
|
|
6855
6859
|
let claudeSdkLater = false; // offered after the save, see step 1
|
|
6856
6860
|
const as = await import("./add-server.mjs");
|
|
6857
6861
|
const ps = await import("./coding-provider-setup.mjs");
|
|
@@ -6981,7 +6985,7 @@ async function addServer({ role = "coding", dialect = "openai", url: presetUrl =
|
|
|
6981
6985
|
key = "";
|
|
6982
6986
|
keyName = "";
|
|
6983
6987
|
typedKey = false;
|
|
6984
|
-
if (found && !newKey) {
|
|
6988
|
+
if (found && !newKey && !pastedLeft) {
|
|
6985
6989
|
// A KEY BELONGS TO THE SERVER: one already saved is used, whichever model it was saved for.
|
|
6986
6990
|
const keys = await withPendingStatus(`reading the keys for ${host}`, () => fetchServerKeys(found.id));
|
|
6987
6991
|
const folderKeyId = role === "agent" ? sessionAgentKeyId : role === "embed" ? sessionEmbedKeyId : sessionCodingKeyId;
|
|
@@ -7009,6 +7013,12 @@ async function addServer({ role = "coding", dialect = "openai", url: presetUrl =
|
|
|
7009
7013
|
typedKey = Boolean(t.secret);
|
|
7010
7014
|
return t.secret || need !== "required";
|
|
7011
7015
|
};
|
|
7016
|
+
if (!key && pastedLeft && need !== "none") {
|
|
7017
|
+
key = pastedLeft;
|
|
7018
|
+
pastedLeft = "";
|
|
7019
|
+
keyName = "";
|
|
7020
|
+
typedKey = true;
|
|
7021
|
+
}
|
|
7012
7022
|
if (!key && (need !== "none" || newKey)) {
|
|
7013
7023
|
if (need === "required") console.log(GUTTER + dim(`${host} needs an API key.`));
|
|
7014
7024
|
const got = await askKey();
|
|
@@ -11441,6 +11451,12 @@ async function deleteServerKeyFlow({ role, key, host, folderKeyId, lastOfServer
|
|
|
11441
11451
|
}
|
|
11442
11452
|
|
|
11443
11453
|
|
|
11454
|
+
/** #492: the first "hi" with a key just saved — see first-hi.mjs. */
|
|
11455
|
+
async function firstHiCheck(key, model, url) {
|
|
11456
|
+
const { checkModel } = await import("./first-hi.mjs");
|
|
11457
|
+
return withPendingStatus("asking the model hi", () => checkModel({ url, model, key }));
|
|
11458
|
+
}
|
|
11459
|
+
|
|
11444
11460
|
async function promptForCodingKey(override = "") {
|
|
11445
11461
|
let res;
|
|
11446
11462
|
try {
|
|
@@ -11464,6 +11480,7 @@ async function promptForCodingKey(override = "") {
|
|
|
11464
11480
|
saveCodingKey,
|
|
11465
11481
|
log: (s) => console.log(s),
|
|
11466
11482
|
colors: { dim, cyan: accent, red },
|
|
11483
|
+
checkKey: firstHiCheck,
|
|
11467
11484
|
});
|
|
11468
11485
|
}
|
|
11469
11486
|
|
|
@@ -14553,6 +14570,7 @@ async function main() {
|
|
|
14553
14570
|
if (setup?.complete) reloadWorkerEnv();
|
|
14554
14571
|
if (setup?.loadPreset) openPresetsAtStart = true;
|
|
14555
14572
|
if (setup?.addProvider) addProviderAtStart = setup.addProvider;
|
|
14573
|
+
if (setup?.voucherAtStart) voucherAtStart = true;
|
|
14556
14574
|
}
|
|
14557
14575
|
} catch {
|
|
14558
14576
|
/* never block the REPL on the mode question — the banner still shows what is configured */
|
|
@@ -15109,6 +15127,7 @@ async function main() {
|
|
|
15109
15127
|
saveCodingKey,
|
|
15110
15128
|
log: (s) => console.log(s),
|
|
15111
15129
|
colors: { dim, cyan: accent, red },
|
|
15130
|
+
checkKey: firstHiCheck,
|
|
15112
15131
|
});
|
|
15113
15132
|
// Task #190: saving the key is the moment the coder becomes real, and the payload that
|
|
15114
15133
|
// seeded defaultCodingModel above was fetched BEFORE that — it carried no coder at all.
|
|
@@ -15476,13 +15495,24 @@ async function main() {
|
|
|
15476
15495
|
console.log(GUTTER + dim(`(could not open the presets: ${e?.message ?? e} — run /use-presets)`));
|
|
15477
15496
|
}
|
|
15478
15497
|
}
|
|
15498
|
+
// #490: setup's "Free model" — ask for the code now, then the same /voucher flow as typing it.
|
|
15499
|
+
if (voucherAtStart) {
|
|
15500
|
+
voucherAtStart = false;
|
|
15501
|
+
try {
|
|
15502
|
+
const code = String(await ask(" Voucher code (Enter to skip, /voucher CODE later): ") ?? "").trim();
|
|
15503
|
+
if (code) await runVoucherCommand(`/voucher ${code}`);
|
|
15504
|
+
else console.log(GUTTER + dim("No code yet — use /voucher CODE any time, or /model to pick your own."));
|
|
15505
|
+
} catch (e) {
|
|
15506
|
+
console.log(GUTTER + dim(`(could not ask for the code: ${e?.message ?? e} — run /voucher CODE)`));
|
|
15507
|
+
}
|
|
15508
|
+
}
|
|
15479
15509
|
// #132 follow-up: the provider chosen in first-run setup — the URL (or the preset list when none was
|
|
15480
15510
|
// chosen), then the key, then the model, all by the same flow as "add another provider".
|
|
15481
15511
|
if (addProviderAtStart) {
|
|
15482
15512
|
const pick = addProviderAtStart;
|
|
15483
15513
|
addProviderAtStart = null;
|
|
15484
15514
|
try {
|
|
15485
|
-
await addServer({ role: "coding", dialect: pick.dialect || "openai", ...(pick.url ? { url: pick.url } : {}) });
|
|
15515
|
+
await addServer({ role: "coding", dialect: pick.dialect || "openai", ...(pick.url ? { url: pick.url } : {}), ...(pick.key ? { pastedKey: pick.key } : {}) });
|
|
15486
15516
|
} catch (e) {
|
|
15487
15517
|
console.log(GUTTER + dim(`(could not add the provider: ${e?.message ?? e} — run /model → add another provider)`));
|
|
15488
15518
|
}
|
package/model-setup-ui.mjs
CHANGED
|
@@ -140,3 +140,55 @@ export function parseModelSetupChoice(raw) {
|
|
|
140
140
|
if (t === "3" || t === "s" || t === "skip" || t === "n" || t === "no" || t === "-") return "skip";
|
|
141
141
|
return null;
|
|
142
142
|
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* THE ONE START QUESTION (GH #490). Replaces "guided / preset / skip" followed by an eight-row provider
|
|
146
|
+
* list: what people bring decides everything else. Enter keeps the long-standing path (an Ollama server —
|
|
147
|
+
* this machine's, or the shared one), so nobody who presses Enter gets something different.
|
|
148
|
+
*/
|
|
149
|
+
export function startMenu({ presets = 0 } = {}) {
|
|
150
|
+
return [
|
|
151
|
+
"How do you want to start?",
|
|
152
|
+
" 1 I have a key — Claude, DeepSeek, OpenAI, Qwen, Kimi…",
|
|
153
|
+
" 2 Free model — I have a code from gucli.com",
|
|
154
|
+
" 3 My own model — Ollama on this machine, or another server (Enter)",
|
|
155
|
+
" 4 Later — set it up with /model",
|
|
156
|
+
...(presets > 0 ? [` 5 Load a saved preset (${presets} saved)`] : []),
|
|
157
|
+
];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** An answer to startMenu → "key" | "free" | "own" | "later" | "preset", or null to ask again. */
|
|
161
|
+
export function parseStartChoice(raw) {
|
|
162
|
+
if (raw === SKIP_ALL) return "later";
|
|
163
|
+
const t = String(raw ?? "").trim().toLowerCase();
|
|
164
|
+
if (t === "" || t === "3" || t === "own" || t === "ollama" || t === "o") return "own";
|
|
165
|
+
if (t === "1" || t === "key" || t === "k") return "key";
|
|
166
|
+
if (t === "2" || t === "free" || t === "f" || t === "code") return "free";
|
|
167
|
+
if (t === "4" || t === "later" || t === "l" || t === "s" || t === "skip" || t === "n" || t === "no" || t === "-") return "later";
|
|
168
|
+
if (t === "5" || t === "preset" || t === "p") return "preset";
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** "I have a key" → which provider the key is for: every preset, then another URL. No default: a key fits one provider. */
|
|
173
|
+
export function keyProviderMenu(presets = []) {
|
|
174
|
+
return [
|
|
175
|
+
"Which provider is your key for?",
|
|
176
|
+
...presets.map((p, i) => ` ${i + 1} ${p.name} · ${p.url}`),
|
|
177
|
+
` ${presets.length + 1} Another provider — type its URL`,
|
|
178
|
+
" s Back out — set it up later with /model",
|
|
179
|
+
];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** → {kind:"preset"|"url"|"skip", preset?}, or null to ask again. */
|
|
183
|
+
export function parseKeyProvider(raw, presets = []) {
|
|
184
|
+
if (raw === SKIP_ALL) return { kind: "skip" };
|
|
185
|
+
const t = String(raw ?? "").trim().toLowerCase();
|
|
186
|
+
if (t === "s" || t === "skip" || t === "n" || t === "no" || t === "-") return { kind: "skip" };
|
|
187
|
+
if (t === "u" || t === "url") return { kind: "url" };
|
|
188
|
+
if (/^\d+$/.test(t)) {
|
|
189
|
+
const n = Number(t);
|
|
190
|
+
if (n >= 1 && n <= presets.length) return { kind: "preset", preset: presets[n - 1] };
|
|
191
|
+
if (n === presets.length + 1) return { kind: "url" };
|
|
192
|
+
}
|
|
193
|
+
return null;
|
|
194
|
+
}
|
package/ollama-setup.mjs
CHANGED
|
@@ -685,6 +685,16 @@ export async function askOllamaSetup(
|
|
|
685
685
|
// (another port or scheme) may be the one that answers.
|
|
686
686
|
const keys = new Map();
|
|
687
687
|
const SKIPPED = { skipped: true, keys: [] };
|
|
688
|
+
// #489: the DEFAULT address, once it failed on Enter. Enter on it again is the same question with
|
|
689
|
+
// the same answer, so it ends the step instead of asking three more times (a Windows 11 run: the
|
|
690
|
+
// shared server answered 502, Enter was pressed six times, and setup then claimed to be done).
|
|
691
|
+
let deadDefault = "";
|
|
692
|
+
const stillDead = (typed, url) => {
|
|
693
|
+
if (typed || !deadDefault || deadDefault !== url) return false;
|
|
694
|
+
log(` ${displayUrl(url)} is still not answering — skipping the models for now.`);
|
|
695
|
+
log(" Later: /model to pick a server, or /voucher CODE for a free model.");
|
|
696
|
+
return true;
|
|
697
|
+
};
|
|
688
698
|
// #301: a step SKIPPED ON PURPOSE, as against a server that never answered. Nothing chosen
|
|
689
699
|
// because of a skip means "leave the models unset"; nothing chosen because nothing answered
|
|
690
700
|
// stays null, and the caller falls back to the shared box as it always has.
|
|
@@ -744,9 +754,11 @@ export async function askOllamaSetup(
|
|
|
744
754
|
const a = readStepAnswer(await ask(` Agent + embedding server [${displayUrl(defaultUrl)}]: `));
|
|
745
755
|
if (a.kind === "all") return SKIPPED;
|
|
746
756
|
if (a.kind === "skip") { declined = true; break; }
|
|
757
|
+
if (stillDead(a.text, defaultUrl)) { declined = true; break; }
|
|
747
758
|
const tried = await loadServer(a.text, defaultUrl, null);
|
|
748
759
|
if (tried === SKIP_ALL) return SKIPPED;
|
|
749
760
|
if (!tried || tried.failed) {
|
|
761
|
+
if (!a.text) deadDefault = defaultUrl;
|
|
750
762
|
// One explanation, the best one available: the provider message when we recognise the
|
|
751
763
|
// address, otherwise the reachability advice we were going to give anyway.
|
|
752
764
|
const explained = await explainIfOpenAi(a.text || defaultUrl, probeStatus, log, describeOpenAiAgent);
|
|
@@ -782,6 +794,7 @@ export async function askOllamaSetup(
|
|
|
782
794
|
const a = readStepAnswer(await ask(` Coding-model server [${displayUrl(coderDefault)}]: `));
|
|
783
795
|
if (a.kind === "all") return SKIPPED;
|
|
784
796
|
if (a.kind === "skip") { declined = true; break; }
|
|
797
|
+
if (stillDead(a.text, coderDefault)) { declined = true; break; }
|
|
785
798
|
// Same box as the agent server → reuse the list we already have rather than fetching twice.
|
|
786
799
|
const same = normalizeOllamaUrl(a.text || coderDefault);
|
|
787
800
|
const tried =
|
|
@@ -790,6 +803,7 @@ export async function askOllamaSetup(
|
|
|
790
803
|
: await loadServer(a.text, coderDefault, agent);
|
|
791
804
|
if (tried === SKIP_ALL) return SKIPPED;
|
|
792
805
|
if (!tried || tried.failed) {
|
|
806
|
+
if (!a.text) deadDefault = coderDefault;
|
|
793
807
|
// One explanation, the best one available: the provider message when we recognise the
|
|
794
808
|
// address, otherwise the reachability advice we were going to give anyway.
|
|
795
809
|
const explained = await explainIfOpenAi(a.text || coderDefault, probeStatus, log, describeOpenAiCoder);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiens.nguyen/gu-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.917",
|
|
4
4
|
"description": "gu: the coding agent in your terminal. It reads your repo, makes the change and runs the tests, with your own models (Ollama or any OpenAI-compatible provider). Free installs keep the agent, its API and its database on your machine. macOS, Linux and Windows.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -83,6 +83,7 @@
|
|
|
83
83
|
"terminal-layout.mjs",
|
|
84
84
|
"turn-queue.mjs",
|
|
85
85
|
"free-model.mjs",
|
|
86
|
+
"first-hi.mjs",
|
|
86
87
|
"terminal-viewport.mjs",
|
|
87
88
|
"terminal-copy.mjs",
|
|
88
89
|
"version-check.mjs",
|