@tiens.nguyen/gu-cli 1.0.911 → 1.0.913
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 +185 -19
- package/gonext_agent_chat.py +0 -0
- package/gu-repl.mjs +21 -8
- package/model-doctor.mjs +7 -3
- package/package.json +1 -1
package/free-model.mjs
CHANGED
|
@@ -51,20 +51,98 @@ const sameServer = (a, b) => {
|
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
/** Is this coder URL the free model's? */
|
|
54
|
-
export const isFreeServer = (state, url) =>
|
|
54
|
+
export const isFreeServer = (state, url) =>
|
|
55
|
+
Boolean(state?.url) && (sameServer(state.url, url) || (Array.isArray(state.urls) && state.urls.some((u) => sameServer(u, url))));
|
|
55
56
|
|
|
56
57
|
/** The state as of `now`: a new month starts at zero spent. */
|
|
57
58
|
export function current(state, now = new Date()) {
|
|
58
59
|
if (!state) return null;
|
|
59
60
|
const p = periodKey(now);
|
|
60
|
-
|
|
61
|
+
if (state.period === p) return state;
|
|
62
|
+
const providers = Object.fromEntries(Object.entries(state.providers ?? {}).map(([u, v]) => [u, { ...v, spentMicro: 0 }]));
|
|
63
|
+
return { ...state, period: p, spentMicro: 0, providers };
|
|
61
64
|
}
|
|
62
65
|
|
|
63
|
-
/**
|
|
64
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Which allowance a turn on `url` draws from (GH #445): an extra provider's own, or the primary's. The state is
|
|
68
|
+
* `current()` already. → { extra: url | null, label, allowanceMicro, spentMicro }
|
|
69
|
+
*/
|
|
70
|
+
export function slotFor(state, url) {
|
|
71
|
+
const key = Object.keys(state?.providers ?? {}).find((u) => sameServer(u, url));
|
|
72
|
+
if (key) {
|
|
73
|
+
const v = state.providers[key];
|
|
74
|
+
return { extra: key, label: v.label || safeHost(key), allowanceMicro: whole(v.allowanceMicro), spentMicro: whole(v.spentMicro) };
|
|
75
|
+
}
|
|
76
|
+
return { extra: null, label: "", allowanceMicro: whole(state?.allowanceMicro), spentMicro: whole(state?.spentMicro) };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const safeHost = (u) => {
|
|
80
|
+
try {
|
|
81
|
+
return new URL(u).hostname;
|
|
82
|
+
} catch {
|
|
83
|
+
return String(u);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Every provider of a preset, the primary first (GH #444): [{ baseUrl, apiKey, keyId, models: [{ id, price }] }].
|
|
89
|
+
* An older server sends only the primary.
|
|
90
|
+
*/
|
|
91
|
+
export function presetProviders(preset) {
|
|
92
|
+
const extras = Array.isArray(preset?.extraProviders) ? preset.extraProviders.filter((p) => p && typeof p.baseUrl === "string") : [];
|
|
93
|
+
return [
|
|
94
|
+
{ baseUrl: preset.baseUrl, apiKey: preset.apiKey || "", keyId: preset.keyId, models: presetModels(preset) },
|
|
95
|
+
...extras.map((p) => ({
|
|
96
|
+
baseUrl: p.baseUrl,
|
|
97
|
+
// "" = this provider's allowance is used up: the service does not hand out its key (nothing to add or change)
|
|
98
|
+
apiKey: p.apiKey || "",
|
|
99
|
+
keyId: p.keyId,
|
|
100
|
+
label: p.label || "",
|
|
101
|
+
allowanceMicro: whole(p.allowanceMicro),
|
|
102
|
+
spentMicro: whole(p.spentMicro),
|
|
103
|
+
models: presetModels({ model: p.models?.[0]?.id, price: p.models?.[0]?.price, models: p.models }),
|
|
104
|
+
})),
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Did the service hand out the primary provider's key? (Not when ITS allowance is used up.) */
|
|
109
|
+
export const hasPrimaryKey = (preset) => Boolean(preset?.apiKey);
|
|
110
|
+
|
|
111
|
+
/** The models the preset offers: [{ id, price }], default first. An older server sends just `model` + `price`. */
|
|
112
|
+
export function presetModels(preset) {
|
|
113
|
+
const list = Array.isArray(preset?.models) ? preset.models.filter((m) => m && typeof m.id === "string" && m.id) : [];
|
|
114
|
+
return list.length ? list : [{ id: preset.model, price: preset.price }];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The price a turn on `model` is charged at: that model's own, else the DEAREST of the list — a model the
|
|
119
|
+
* server did not list is never charged as free or cheap.
|
|
120
|
+
*/
|
|
121
|
+
export function allPresetModels(preset) {
|
|
122
|
+
return presetProviders(preset).flatMap((p) => p.models);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function priceForModel(state, model) {
|
|
126
|
+
const m = state?.models ?? {};
|
|
127
|
+
if (model && m[model]) return m[model];
|
|
128
|
+
const all = Object.values(m);
|
|
129
|
+
if (!all.length) return state?.price ?? {};
|
|
130
|
+
return {
|
|
131
|
+
inputPerM: Math.max(...all.map((p) => Number(p.inputPerM) || 0)),
|
|
132
|
+
outputPerM: Math.max(...all.map((p) => Number(p.outputPerM) || 0)),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** After a turn on the free model (on `model`, one of its list): the new state. */
|
|
137
|
+
export function addTurn(state, usage, now = new Date(), model = "", url = "") {
|
|
65
138
|
const s = current(state, now);
|
|
66
139
|
if (!s) return null;
|
|
67
|
-
|
|
140
|
+
const cost = turnCostMicro(usage, priceForModel(s, model));
|
|
141
|
+
const slot = url ? slotFor(s, url) : null;
|
|
142
|
+
if (slot?.extra) {
|
|
143
|
+
return { ...s, providers: { ...s.providers, [slot.extra]: { ...s.providers[slot.extra], spentMicro: slot.spentMicro + cost } } };
|
|
144
|
+
}
|
|
145
|
+
return { ...s, spentMicro: whole(s.spentMicro) + cost };
|
|
68
146
|
}
|
|
69
147
|
|
|
70
148
|
/** After the service answered the preset: what gu keeps (never the key itself). */
|
|
@@ -76,6 +154,18 @@ export function stateFromPreset(preset, prev, now = new Date()) {
|
|
|
76
154
|
model: preset.model,
|
|
77
155
|
keyId: preset.keyId,
|
|
78
156
|
price: preset.price,
|
|
157
|
+
models: Object.fromEntries(allPresetModels(preset).map((m) => [m.id, m.price])),
|
|
158
|
+
// Every provider's endpoint: a turn on any of them is the free model's (#444).
|
|
159
|
+
urls: presetProviders(preset).map((p) => p.baseUrl),
|
|
160
|
+
// Each provider's key fingerprint, so a rotated key on any of them is noticed.
|
|
161
|
+
keyIds: Object.fromEntries(presetProviders(preset).map((p) => [p.baseUrl, p.keyId])),
|
|
162
|
+
// Each extra provider's OWN allowance and spend (#445): the higher of ours and the service's, like the primary's.
|
|
163
|
+
providers: Object.fromEntries(
|
|
164
|
+
presetProviders(preset).slice(1).map((p) => {
|
|
165
|
+
const before = prev && prev.period === periodKey(now) ? whole(prev.providers?.[p.baseUrl]?.spentMicro) : 0;
|
|
166
|
+
return [p.baseUrl, { label: p.label, allowanceMicro: p.allowanceMicro, spentMicro: Math.max(before, p.spentMicro) }];
|
|
167
|
+
})
|
|
168
|
+
),
|
|
79
169
|
period: p,
|
|
80
170
|
allowanceMicro: whole(preset.allowanceMicro),
|
|
81
171
|
// The higher of ours and the service's: a reinstall cannot reset it, another computer's use counts.
|
|
@@ -88,26 +178,31 @@ const usd = (micro) => `$${(whole(micro) / 1e6).toFixed(2)}`;
|
|
|
88
178
|
/**
|
|
89
179
|
* The line to show, or null. `over` is the refusal itself; warn/low are shown once per level.
|
|
90
180
|
*/
|
|
91
|
-
export function notice(state, now = new Date()) {
|
|
181
|
+
export function notice(state, now = new Date(), url = "") {
|
|
92
182
|
const s = current(state, now);
|
|
93
|
-
if (!s
|
|
94
|
-
const
|
|
95
|
-
|
|
183
|
+
if (!s) return null;
|
|
184
|
+
const slot = slotFor(s, url);
|
|
185
|
+
if (!slot.allowanceMicro) return null;
|
|
186
|
+
const level = levelFor(slot.spentMicro, slot.allowanceMicro);
|
|
187
|
+
const pct = Math.min(100, Math.floor((100 * slot.spentMicro) / slot.allowanceMicro));
|
|
188
|
+
const name = slot.extra ? slot.label : "free model";
|
|
189
|
+
const Name = slot.extra ? slot.label : "Free model";
|
|
96
190
|
if (level === "over") {
|
|
97
|
-
|
|
191
|
+
const other = slot.extra ? " — or another free model with /model —" : "";
|
|
192
|
+
return { level, text: `Your ${name} allowance for this month (${usd(slot.allowanceMicro)}) is used up. Add your own model key with /model${other} — or a local one with Ollama — to keep going; it renews on the 1st.` };
|
|
98
193
|
}
|
|
99
|
-
if (level === "low") return { level, text:
|
|
100
|
-
if (level === "warn") return { level, text:
|
|
194
|
+
if (level === "low") return { level, text: `${Name}: ${pct}% of this month's ${usd(slot.allowanceMicro)} used — almost gone. Add your own key with /model before it ends.` };
|
|
195
|
+
if (level === "warn") return { level, text: `${Name}: ${pct}% of this month's ${usd(slot.allowanceMicro)} used.` };
|
|
101
196
|
return { level, text: null };
|
|
102
197
|
}
|
|
103
198
|
|
|
104
199
|
/**
|
|
105
200
|
* Is a NEW turn on this coder refused? Only at the START of a turn — never mid-turn — and only when
|
|
106
|
-
* the coder IS the free model. → the sentence, or null.
|
|
201
|
+
* the coder IS the free model (any provider; each has its own allowance). → the sentence, or null.
|
|
107
202
|
*/
|
|
108
203
|
export function blockReason(state, coderUrl, now = new Date()) {
|
|
109
204
|
if (!isFreeServer(state, coderUrl)) return null;
|
|
110
|
-
const n = notice(state, now);
|
|
205
|
+
const n = notice(state, now, coderUrl);
|
|
111
206
|
return n?.level === "over" ? n.text : null;
|
|
112
207
|
}
|
|
113
208
|
|
|
@@ -130,6 +225,11 @@ export function writeState(dir, state) {
|
|
|
130
225
|
}
|
|
131
226
|
}
|
|
132
227
|
|
|
228
|
+
/** What to tell the person when the server has no free model to give yet. */
|
|
229
|
+
export const NOT_CONFIGURED_TEXT =
|
|
230
|
+
"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. " +
|
|
231
|
+
"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.";
|
|
232
|
+
|
|
133
233
|
async function call(fetchImpl, url, init, timeoutMs) {
|
|
134
234
|
try {
|
|
135
235
|
const r = await fetchImpl(url, { ...init, signal: AbortSignal.timeout(timeoutMs) });
|
|
@@ -148,7 +248,8 @@ export async function fetchPreset({ hostedBase, token, fetchImpl = fetch, timeou
|
|
|
148
248
|
const r = await call(fetchImpl, `${String(hostedBase).replace(/\/+$/, "")}/api/billing/cli-token/model-preset`, {
|
|
149
249
|
headers: { Authorization: `Bearer ${String(token).trim()}` },
|
|
150
250
|
}, timeoutMs);
|
|
151
|
-
|
|
251
|
+
// The primary's key is "" when ITS allowance is used up but another provider's is not (GH #445): still a preset.
|
|
252
|
+
if (r.ok && typeof r.body.baseUrl === "string" && typeof r.body.apiKey === "string" && (r.body.apiKey || r.body.over === true)) {
|
|
152
253
|
return { ok: true, preset: r.body };
|
|
153
254
|
}
|
|
154
255
|
if (r.status === 0) return { ok: false, why: "offline", error: "could not reach the gu service." };
|
|
@@ -162,7 +263,11 @@ export async function reportSpend({ hostedBase, token, state, fetchImpl = fetch,
|
|
|
162
263
|
const r = await call(fetchImpl, `${String(hostedBase).replace(/\/+$/, "")}/api/billing/cli-token/model-usage`, {
|
|
163
264
|
method: "POST",
|
|
164
265
|
headers: { Authorization: `Bearer ${String(token).trim()}`, "Content-Type": "application/json" },
|
|
165
|
-
body: JSON.stringify({
|
|
266
|
+
body: JSON.stringify({
|
|
267
|
+
period: state.period,
|
|
268
|
+
spentMicro: whole(state.spentMicro),
|
|
269
|
+
extras: Object.entries(state.providers ?? {}).map(([baseUrl, v]) => ({ baseUrl, spentMicro: whole(v.spentMicro) })),
|
|
270
|
+
}),
|
|
166
271
|
}, timeoutMs);
|
|
167
272
|
return r.ok && Number.isFinite(Number(r.body.spentMicro)) ? Number(r.body.spentMicro) : null;
|
|
168
273
|
}
|
|
@@ -175,14 +280,35 @@ export async function reportSpend({ hostedBase, token, state, fetchImpl = fetch,
|
|
|
175
280
|
* → { ok: true, rowId, keyAdded } | { ok: false, why }
|
|
176
281
|
*/
|
|
177
282
|
export async function applyPreset(preset, api, { rotateOnly = false } = {}) {
|
|
283
|
+
// The primary's allowance is used up (its key withheld): nothing to add or switch for it; the other providers still apply.
|
|
284
|
+
if (!preset.apiKey) {
|
|
285
|
+
let added = false;
|
|
286
|
+
for (const p of presetProviders(preset).slice(1)) {
|
|
287
|
+
if (!p.apiKey) continue;
|
|
288
|
+
const r = await applyExtraProvider(p, api);
|
|
289
|
+
if (!r.ok) return r;
|
|
290
|
+
added = added || r.keyAdded;
|
|
291
|
+
}
|
|
292
|
+
return { ok: true, rowId: "", keyAdded: added };
|
|
293
|
+
}
|
|
178
294
|
const settings = await api.settings();
|
|
179
295
|
if (!settings) return { ok: false, why: "couldn't read this account's settings from the local API" };
|
|
180
296
|
const rows = Array.isArray(settings.agentCodingBackends) ? settings.agentCodingBackends : [];
|
|
181
297
|
const mine = rows.find((r) => r && sameServer(r.url, preset.baseUrl));
|
|
182
|
-
|
|
298
|
+
// Every model of the list goes on the server's row, so /model offers them (#441). A later change of the list
|
|
299
|
+
// (rotateOnly) updates the row's list but never the model the person is on.
|
|
300
|
+
const ids = presetModels(preset).map((m) => m.id);
|
|
301
|
+
const extra = (def) => [...new Set([...(mine?.models ?? []), ...ids])].filter((m) => m !== def);
|
|
302
|
+
// A key rotation that leaves the list as it was saves no settings at all.
|
|
303
|
+
const listSame = Boolean(mine) && JSON.stringify([...(mine.models ?? [])].sort()) === JSON.stringify(extra(mine.defaultModel || preset.model).sort());
|
|
304
|
+
if (!rotateOnly || !mine || !listSame) {
|
|
183
305
|
const nextRows = mine
|
|
184
|
-
? rows.map((r) =>
|
|
185
|
-
|
|
306
|
+
? rows.map((r) => {
|
|
307
|
+
if (r !== mine) return r;
|
|
308
|
+
const def = rotateOnly ? r.defaultModel || preset.model : preset.model;
|
|
309
|
+
return { ...r, defaultModel: def, models: extra(def), enabled: true };
|
|
310
|
+
})
|
|
311
|
+
: [...rows, { kind: "openai", url: preset.baseUrl, defaultModel: preset.model, models: ids.filter((m) => m !== preset.model), enabled: true }];
|
|
186
312
|
const patch = {
|
|
187
313
|
agentCodingBackends: nextRows,
|
|
188
314
|
...(rotateOnly ? {} : {
|
|
@@ -210,5 +336,45 @@ export async function applyPreset(preset, api, { rotateOnly = false } = {}) {
|
|
|
210
336
|
keyAdded = true;
|
|
211
337
|
}
|
|
212
338
|
if (!(await api.setDefaultKey(row.id, keyId))) return { ok: false, why: "couldn't make the key that server's default" };
|
|
339
|
+
// The other providers (#444): a server row and a key each. They never change the coder or the agent model.
|
|
340
|
+
for (const extraProvider of presetProviders(preset).slice(1)) {
|
|
341
|
+
if (!extraProvider.apiKey) continue; // that provider's allowance is used up
|
|
342
|
+
const r = await applyExtraProvider(extraProvider, api);
|
|
343
|
+
if (!r.ok) return r;
|
|
344
|
+
keyAdded = keyAdded || r.keyAdded;
|
|
345
|
+
}
|
|
213
346
|
return { ok: true, rowId: row.id, keyAdded };
|
|
214
347
|
}
|
|
348
|
+
|
|
349
|
+
async function applyExtraProvider(p, api) {
|
|
350
|
+
const ids = p.models.map((m) => m.id);
|
|
351
|
+
const settings = await api.settings();
|
|
352
|
+
if (!settings) return { ok: false, why: "couldn't read this account's settings from the local API" };
|
|
353
|
+
const rows = Array.isArray(settings.agentCodingBackends) ? settings.agentCodingBackends : [];
|
|
354
|
+
const mine = rows.find((r) => r && sameServer(r.url, p.baseUrl));
|
|
355
|
+
if (!mine) {
|
|
356
|
+
const next = [...rows, { kind: "openai", url: p.baseUrl, defaultModel: ids[0], models: ids.slice(1), enabled: true }];
|
|
357
|
+
if (!(await api.saveSettings({ agentCodingBackends: next }))) return { ok: false, why: "the local API refused the settings" };
|
|
358
|
+
} else {
|
|
359
|
+
const def = mine.defaultModel || ids[0];
|
|
360
|
+
const list = [...new Set([...(mine.models ?? []), ...ids])].filter((m) => m !== def);
|
|
361
|
+
if (JSON.stringify([...list].sort()) !== JSON.stringify([...(mine.models ?? [])].sort())) {
|
|
362
|
+
const next = rows.map((r) => (r === mine ? { ...r, models: list, enabled: true } : r));
|
|
363
|
+
if (!(await api.saveSettings({ agentCodingBackends: next }))) return { ok: false, why: "the local API refused the settings" };
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
const fresh = (await api.settings()) ?? {};
|
|
367
|
+
const row = (fresh.agentCodingBackends ?? []).find((r) => r && sameServer(r.url, p.baseUrl));
|
|
368
|
+
if (!row?.id) return { ok: false, why: "the server row was not saved" };
|
|
369
|
+
const keys = (await api.keys()) ?? [];
|
|
370
|
+
const named = keys.find((k) => k?.backendId === row.id && k?.name === `${FREE_KEY_NAME} ${p.keyId}`);
|
|
371
|
+
let keyId = named?.id ?? "";
|
|
372
|
+
let keyAdded = false;
|
|
373
|
+
if (!keyId) {
|
|
374
|
+
keyId = await api.addKey(`${FREE_KEY_NAME} ${p.keyId}`, p.apiKey, row.id);
|
|
375
|
+
if (!keyId) return { ok: false, why: "the local API refused the key" };
|
|
376
|
+
keyAdded = true;
|
|
377
|
+
}
|
|
378
|
+
if (!(await api.setDefaultKey(row.id, keyId))) return { ok: false, why: "couldn't make the key that server's default" };
|
|
379
|
+
return { ok: true, keyAdded };
|
|
380
|
+
}
|
package/gonext_agent_chat.py
CHANGED
|
File without changes
|
package/gu-repl.mjs
CHANGED
|
@@ -8916,12 +8916,23 @@ 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
|
-
|
|
8924
|
-
|
|
8928
|
+
// A rotated key on ANY provider (the primary's, or an extra one's) counts (GH #444).
|
|
8929
|
+
const keysNow = JSON.stringify(Object.fromEntries(fm.presetProviders(got.preset).map((p) => [p.baseUrl, p.keyId])));
|
|
8930
|
+
const keysThen = JSON.stringify(freeModel?.keyIds ?? Object.fromEntries([[freeModel?.url, freeModel?.keyId]]));
|
|
8931
|
+
const keyChanged = !first && keysNow !== keysThen;
|
|
8932
|
+
// The owner added or removed a model or a provider: the server rows' lists follow (what the person is on stays).
|
|
8933
|
+
const ids = (p) => fm.allPresetModels(p).map((m) => m.id).join(",");
|
|
8934
|
+
const listChanged = !first && !keyChanged && Object.keys(freeModel.models ?? {}).join(",") !== ids(got.preset);
|
|
8935
|
+
if (!first && !keyChanged && !listChanged) {
|
|
8925
8936
|
freeModel = fm.stateFromPreset(got.preset, freeModel);
|
|
8926
8937
|
fm.writeState(freeModelDir(), freeModel);
|
|
8927
8938
|
return true;
|
|
@@ -8933,7 +8944,7 @@ async function setUpFreeModel({ token, announce = false } = {}) {
|
|
|
8933
8944
|
}
|
|
8934
8945
|
freeModel = fm.stateFromPreset(got.preset, freeModel);
|
|
8935
8946
|
fm.writeState(freeModelDir(), freeModel);
|
|
8936
|
-
if (first) {
|
|
8947
|
+
if (first && fm.hasPrimaryKey(got.preset)) {
|
|
8937
8948
|
await refreshAfterPresetApply(null, { model: got.preset.model, url: got.preset.baseUrl }, { coder: true });
|
|
8938
8949
|
console.log(GUTTER + accent(`✓ ${got.preset.model} is now your agent model and your coding model.`) +
|
|
8939
8950
|
dim(" Free use renews each month; /model switches back to your own."));
|
|
@@ -8950,7 +8961,8 @@ async function freeModelAtStart() {
|
|
|
8950
8961
|
try {
|
|
8951
8962
|
const fm = await import("./free-model.mjs");
|
|
8952
8963
|
freeModel = fm.readState(freeModelDir());
|
|
8953
|
-
|
|
8964
|
+
// Ask even with no saved state (GH #440/#442): a code redeemed while the server had no free model, or on
|
|
8965
|
+
// another computer, gets its model here without a second /voucher. Quiet unless there is one to set up.
|
|
8954
8966
|
const ct = await import("./cli-token.mjs");
|
|
8955
8967
|
const st = await ct.readState(join(homedir(), ".gonext"));
|
|
8956
8968
|
if (st?.token) await setUpFreeModel({ token: st.token });
|
|
@@ -8965,11 +8977,12 @@ async function noteFreeModelTurn(inputTokens, breakdown, outputTokens, coder) {
|
|
|
8965
8977
|
const fm = await import("./free-model.mjs");
|
|
8966
8978
|
if (!freeModel || !fm.isFreeServer(freeModel, coder?.url) || !(inputTokens > 0)) return;
|
|
8967
8979
|
const cache = readTurnCache(breakdown) ?? { cached: 0, cacheReported: false };
|
|
8968
|
-
freeModel = fm.addTurn(freeModel, { input: inputTokens, cached: cache.cached, cacheReported: cache.cacheReported, output: outputTokens ?? 0 });
|
|
8980
|
+
freeModel = fm.addTurn(freeModel, { input: inputTokens, cached: cache.cached, cacheReported: cache.cacheReported, output: outputTokens ?? 0 }, new Date(), coder?.model, coder?.url);
|
|
8969
8981
|
fm.writeState(freeModelDir(), freeModel);
|
|
8970
|
-
const n = fm.notice(freeModel);
|
|
8971
|
-
|
|
8972
|
-
|
|
8982
|
+
const n = fm.notice(freeModel, new Date(), coder?.url);
|
|
8983
|
+
const noticeKey = `${freeModel.period}:${fm.slotFor(freeModel, coder?.url).extra ?? "main"}:${n?.level}`;
|
|
8984
|
+
if (n?.text && freeModelNoticed !== noticeKey) {
|
|
8985
|
+
freeModelNoticed = noticeKey;
|
|
8973
8986
|
console.log(GUTTER + (n.level === "ok" ? dim(n.text) : yellow(n.text)) + "\n");
|
|
8974
8987
|
}
|
|
8975
8988
|
const ct = await import("./cli-token.mjs");
|
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.913",
|
|
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",
|