@tiens.nguyen/gu-cli 1.0.910 → 1.0.912
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/free-model.mjs +43 -6
- package/gonext_agent_chat.py +4 -3
- package/gu-repl.mjs +12 -3
- package/model-doctor.mjs +7 -3
- package/package.json +1 -1
package/free-model.mjs
CHANGED
|
@@ -60,11 +60,32 @@ export function current(state, now = new Date()) {
|
|
|
60
60
|
return state.period === p ? state : { ...state, period: p, spentMicro: 0 };
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
/**
|
|
64
|
-
export function
|
|
63
|
+
/** The models the preset offers: [{ id, price }], default first. An older server sends just `model` + `price`. */
|
|
64
|
+
export function presetModels(preset) {
|
|
65
|
+
const list = Array.isArray(preset?.models) ? preset.models.filter((m) => m && typeof m.id === "string" && m.id) : [];
|
|
66
|
+
return list.length ? list : [{ id: preset.model, price: preset.price }];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The price a turn on `model` is charged at: that model's own, else the DEAREST of the list — a model the
|
|
71
|
+
* server did not list is never charged as free or cheap.
|
|
72
|
+
*/
|
|
73
|
+
export function priceForModel(state, model) {
|
|
74
|
+
const m = state?.models ?? {};
|
|
75
|
+
if (model && m[model]) return m[model];
|
|
76
|
+
const all = Object.values(m);
|
|
77
|
+
if (!all.length) return state?.price ?? {};
|
|
78
|
+
return {
|
|
79
|
+
inputPerM: Math.max(...all.map((p) => Number(p.inputPerM) || 0)),
|
|
80
|
+
outputPerM: Math.max(...all.map((p) => Number(p.outputPerM) || 0)),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** After a turn on the free model (on `model`, one of its list): the new state. */
|
|
85
|
+
export function addTurn(state, usage, now = new Date(), model = "") {
|
|
65
86
|
const s = current(state, now);
|
|
66
87
|
if (!s) return null;
|
|
67
|
-
return { ...s, spentMicro: whole(s.spentMicro) + turnCostMicro(usage, s
|
|
88
|
+
return { ...s, spentMicro: whole(s.spentMicro) + turnCostMicro(usage, priceForModel(s, model)) };
|
|
68
89
|
}
|
|
69
90
|
|
|
70
91
|
/** After the service answered the preset: what gu keeps (never the key itself). */
|
|
@@ -76,6 +97,7 @@ export function stateFromPreset(preset, prev, now = new Date()) {
|
|
|
76
97
|
model: preset.model,
|
|
77
98
|
keyId: preset.keyId,
|
|
78
99
|
price: preset.price,
|
|
100
|
+
models: Object.fromEntries(presetModels(preset).map((m) => [m.id, m.price])),
|
|
79
101
|
period: p,
|
|
80
102
|
allowanceMicro: whole(preset.allowanceMicro),
|
|
81
103
|
// The higher of ours and the service's: a reinstall cannot reset it, another computer's use counts.
|
|
@@ -130,6 +152,11 @@ export function writeState(dir, state) {
|
|
|
130
152
|
}
|
|
131
153
|
}
|
|
132
154
|
|
|
155
|
+
/** What to tell the person when the server has no free model to give yet. */
|
|
156
|
+
export const NOT_CONFIGURED_TEXT =
|
|
157
|
+
"Your code is saved, but the free model is not switched on at the gu service yet, so there is nothing to set up now. " +
|
|
158
|
+
"Nothing is lost: gu asks again each time it starts and switches it on by itself. To keep working now, add your own model key with /model.";
|
|
159
|
+
|
|
133
160
|
async function call(fetchImpl, url, init, timeoutMs) {
|
|
134
161
|
try {
|
|
135
162
|
const r = await fetchImpl(url, { ...init, signal: AbortSignal.timeout(timeoutMs) });
|
|
@@ -179,10 +206,20 @@ export async function applyPreset(preset, api, { rotateOnly = false } = {}) {
|
|
|
179
206
|
if (!settings) return { ok: false, why: "couldn't read this account's settings from the local API" };
|
|
180
207
|
const rows = Array.isArray(settings.agentCodingBackends) ? settings.agentCodingBackends : [];
|
|
181
208
|
const mine = rows.find((r) => r && sameServer(r.url, preset.baseUrl));
|
|
182
|
-
|
|
209
|
+
// Every model of the list goes on the server's row, so /model offers them (#441). A later change of the list
|
|
210
|
+
// (rotateOnly) updates the row's list but never the model the person is on.
|
|
211
|
+
const ids = presetModels(preset).map((m) => m.id);
|
|
212
|
+
const extra = (def) => [...new Set([...(mine?.models ?? []), ...ids])].filter((m) => m !== def);
|
|
213
|
+
// A key rotation that leaves the list as it was saves no settings at all.
|
|
214
|
+
const listSame = Boolean(mine) && JSON.stringify([...(mine.models ?? [])].sort()) === JSON.stringify(extra(mine.defaultModel || preset.model).sort());
|
|
215
|
+
if (!rotateOnly || !mine || !listSame) {
|
|
183
216
|
const nextRows = mine
|
|
184
|
-
? rows.map((r) =>
|
|
185
|
-
|
|
217
|
+
? rows.map((r) => {
|
|
218
|
+
if (r !== mine) return r;
|
|
219
|
+
const def = rotateOnly ? r.defaultModel || preset.model : preset.model;
|
|
220
|
+
return { ...r, defaultModel: def, models: extra(def), enabled: true };
|
|
221
|
+
})
|
|
222
|
+
: [...rows, { kind: "openai", url: preset.baseUrl, defaultModel: preset.model, models: ids.filter((m) => m !== preset.model), enabled: true }];
|
|
186
223
|
const patch = {
|
|
187
224
|
agentCodingBackends: nextRows,
|
|
188
225
|
...(rotateOnly ? {} : {
|
package/gonext_agent_chat.py
CHANGED
|
@@ -3243,9 +3243,10 @@ _DEEPSEEK_V4_RE = re.compile(r"deepseek[-_.]?v4", re.I)
|
|
|
3243
3243
|
# Hosts known to take DeepSeek's own `thinking` request field (GH #430). Another host serving the
|
|
3244
3244
|
# same model (OpenRouter, Together, vLLM…) spells the switch differently or not at all, so it
|
|
3245
3245
|
# keeps today's request unchanged unless GONEXT_DEEPSEEK_THINKING=off forces the field.
|
|
3246
|
-
# GH #433: the
|
|
3247
|
-
#
|
|
3248
|
-
# rejects the field, _repair_request drops it and says so, and the
|
|
3246
|
+
# GH #433: the free model runs on the Token Plan host above. The Qwen Cloud pay-as-you-go hosts are listed
|
|
3247
|
+
# too, in case the owner points the free model there — NOT confirmed live (the docs only show
|
|
3248
|
+
# `enable_thinking`); if such a host rejects the field, _repair_request drops it and says so, and the
|
|
3249
|
+
# turn simply runs with thinking on.
|
|
3249
3250
|
_DEEPSEEK_THINKING_HOSTS = frozenset({
|
|
3250
3251
|
"api.deepseek.com",
|
|
3251
3252
|
"token-plan.maas.qwencloudapi.com",
|
package/gu-repl.mjs
CHANGED
|
@@ -8916,12 +8916,20 @@ async function setUpFreeModel({ token, announce = false } = {}) {
|
|
|
8916
8916
|
fm.fetchPreset({ hostedBase: await freeModelHostedBase(), token })
|
|
8917
8917
|
);
|
|
8918
8918
|
if (!got.ok) {
|
|
8919
|
+
if (got.why === "not-configured") {
|
|
8920
|
+
// The code is redeemed, the server just has no key yet; every start asks again (freeModelAtStart).
|
|
8921
|
+
if (announce) console.log(GUTTER + yellow(fm.NOT_CONFIGURED_TEXT));
|
|
8922
|
+
return false;
|
|
8923
|
+
}
|
|
8919
8924
|
if (announce || got.why === "over") console.log(GUTTER + (got.why === "over" ? yellow(got.error) : dim(got.error)));
|
|
8920
8925
|
return false;
|
|
8921
8926
|
}
|
|
8922
8927
|
const first = !freeModel || freeModel.url !== got.preset.baseUrl;
|
|
8923
8928
|
const keyChanged = !first && freeModel.keyId !== got.preset.keyId;
|
|
8924
|
-
|
|
8929
|
+
// The owner added or removed a model: the server row's list follows (what the person is on stays).
|
|
8930
|
+
const ids = (p) => fm.presetModels(p).map((m) => m.id).join(",");
|
|
8931
|
+
const listChanged = !first && !keyChanged && Object.keys(freeModel.models ?? {}).join(",") !== ids(got.preset);
|
|
8932
|
+
if (!first && !keyChanged && !listChanged) {
|
|
8925
8933
|
freeModel = fm.stateFromPreset(got.preset, freeModel);
|
|
8926
8934
|
fm.writeState(freeModelDir(), freeModel);
|
|
8927
8935
|
return true;
|
|
@@ -8950,7 +8958,8 @@ async function freeModelAtStart() {
|
|
|
8950
8958
|
try {
|
|
8951
8959
|
const fm = await import("./free-model.mjs");
|
|
8952
8960
|
freeModel = fm.readState(freeModelDir());
|
|
8953
|
-
|
|
8961
|
+
// Ask even with no saved state (GH #440/#442): a code redeemed while the server had no free model, or on
|
|
8962
|
+
// another computer, gets its model here without a second /voucher. Quiet unless there is one to set up.
|
|
8954
8963
|
const ct = await import("./cli-token.mjs");
|
|
8955
8964
|
const st = await ct.readState(join(homedir(), ".gonext"));
|
|
8956
8965
|
if (st?.token) await setUpFreeModel({ token: st.token });
|
|
@@ -8965,7 +8974,7 @@ async function noteFreeModelTurn(inputTokens, breakdown, outputTokens, coder) {
|
|
|
8965
8974
|
const fm = await import("./free-model.mjs");
|
|
8966
8975
|
if (!freeModel || !fm.isFreeServer(freeModel, coder?.url) || !(inputTokens > 0)) return;
|
|
8967
8976
|
const cache = readTurnCache(breakdown) ?? { cached: 0, cacheReported: false };
|
|
8968
|
-
freeModel = fm.addTurn(freeModel, { input: inputTokens, cached: cache.cached, cacheReported: cache.cacheReported, output: outputTokens ?? 0 });
|
|
8977
|
+
freeModel = fm.addTurn(freeModel, { input: inputTokens, cached: cache.cached, cacheReported: cache.cacheReported, output: outputTokens ?? 0 }, new Date(), coder?.model);
|
|
8969
8978
|
fm.writeState(freeModelDir(), freeModel);
|
|
8970
8979
|
const n = fm.notice(freeModel);
|
|
8971
8980
|
if (n?.text && freeModelNoticed !== `${freeModel.period}:${n.level}`) {
|
package/model-doctor.mjs
CHANGED
|
@@ -1514,9 +1514,13 @@ export async function ensureAgentDeps({ log, confirm, modelHost = canHostMlxMode
|
|
|
1514
1514
|
// nobody asked for (it fired during a test run against the developer's own config).
|
|
1515
1515
|
out.python = await pinPythonForDaemon({ log });
|
|
1516
1516
|
}
|
|
1517
|
-
// Opt-in (gu-cli deps, the installer): the first `gu` start must not ask a second question.
|
|
1518
|
-
|
|
1519
|
-
|
|
1517
|
+
// Opt-in (gu-cli deps, the installer): the first `gu` start must not ask a second question. But a start that has
|
|
1518
|
+
// just built gu's Python environment is the only chance on a machine where the installer found no Python (a new
|
|
1519
|
+
// Windows 11, GH #439): the person already said yes to the install, so the skills' libraries come with it, unasked.
|
|
1520
|
+
const justBuilt = out.agentLibs === "installed";
|
|
1521
|
+
if ((skillsPack || justBuilt) && (out.agentLibs === "present" || out.agentLibs === "installed")) {
|
|
1522
|
+
if (justBuilt && !skillsPack) log(" Also installing the libraries the Word / Excel / PowerPoint / PDF skills use …");
|
|
1523
|
+
out.skillsLibs = await ensureSkillsLibs({ log, confirm, agreed: justBuilt ? [...agreed, "skillsLibs"] : agreed });
|
|
1520
1524
|
if (out.skillsLibs === "installed") out.python = await pinPythonForDaemon({ log });
|
|
1521
1525
|
out.skillsNode = await ensureSkillsNodeLibs({ log });
|
|
1522
1526
|
}
|
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.912",
|
|
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",
|