@bismawy/pi-arnative 0.7.0 → 0.8.0
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/CHANGELOG.md +16 -0
- package/README.md +29 -4
- package/extensions/arnative.ts +173 -6
- package/extensions/autocompact.ts +294 -0
- package/extensions/footer.ts +3 -3
- package/extensions/model-heal.ts +248 -0
- package/extensions/timestamps.ts +30 -1
- package/extensions/tools.ts +3 -3
- package/extensions/ui-render-tweaks.ts +12 -1
- package/extensions/usage.ts +28 -28
- package/lib/compat.ts +415 -0
- package/lib/list-picker.ts +17 -1
- package/lib/model-heal.ts +640 -0
- package/lib/provider.ts +191 -32
- package/lib/usage-store.ts +1 -1
- package/package.json +3 -3
package/lib/provider.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { mkdirSync, mkdtempSync, readdirSync, readFileSync, renameSync, rmSync,
|
|
|
13
13
|
import { tmpdir } from "node:os";
|
|
14
14
|
import { dirname, join } from "node:path";
|
|
15
15
|
import { assert, isMain } from "../lib/check.ts";
|
|
16
|
+
import { buildEffortMap, isEffortProbeable, mergeMeta, parseModelMeta, probeEffort, suggestCompat, type Compat, type ModelMeta } from "./compat.ts";
|
|
16
17
|
import { screenTitle, type ScreenText } from "../lib/box.ts";
|
|
17
18
|
import { stripAnsi } from "../lib/ansi.ts";
|
|
18
19
|
import { INPUT_LEGEND, InputPicker, LIST_LEGEND_MOVE, ListPicker, rowText, type ListRow } from "./list-picker.ts";
|
|
@@ -130,6 +131,8 @@ export interface ProbeResult {
|
|
|
130
131
|
/** Chat base for the flavor (`chatBaseUrl`). */
|
|
131
132
|
baseUrl: string;
|
|
132
133
|
models: string[];
|
|
134
|
+
/** `contextWindow`/`maxTokens` from the same answer — no second request. */
|
|
135
|
+
meta: Map<string, ModelMeta>;
|
|
133
136
|
/** Path that answered, for the notify line. */
|
|
134
137
|
via: string;
|
|
135
138
|
keyless: boolean;
|
|
@@ -152,19 +155,21 @@ export async function probeEndpoint(base: string, key: string, fetchImpl: FetchL
|
|
|
152
155
|
signal: AbortSignal.timeout(timeoutMs),
|
|
153
156
|
});
|
|
154
157
|
if (!response.ok) throw new Error(`HTTP ${response.status ?? "error"}`);
|
|
155
|
-
const
|
|
158
|
+
const body = await response.json();
|
|
159
|
+
const models = parseModelList(candidate, body);
|
|
156
160
|
if (!models || models.length === 0) throw new Error("no models");
|
|
157
|
-
return { candidate, models };
|
|
161
|
+
return { candidate, models, meta: parseModelMeta(body) };
|
|
158
162
|
}),
|
|
159
163
|
);
|
|
160
164
|
for (let i = 0; i < candidates.length; i++) {
|
|
161
165
|
const result = settled[i];
|
|
162
166
|
if (result?.status !== "fulfilled") continue;
|
|
163
|
-
const { candidate, models } = result.value;
|
|
167
|
+
const { candidate, models, meta } = result.value;
|
|
164
168
|
return {
|
|
165
169
|
flavor: candidate.flavor,
|
|
166
170
|
baseUrl: chatBaseUrl(candidate.flavor, base),
|
|
167
171
|
models: [...new Set(models)],
|
|
172
|
+
meta,
|
|
168
173
|
via: new URL(candidate.url).pathname,
|
|
169
174
|
keyless: candidate.keyless,
|
|
170
175
|
};
|
|
@@ -187,6 +192,11 @@ export interface ProviderModel {
|
|
|
187
192
|
id: string;
|
|
188
193
|
/** Thinking level; undefined means chat (no `reasoning` flag). */
|
|
189
194
|
level?: ThinkingSetting;
|
|
195
|
+
/** An effort map a probe produced; it wins over the level's own single pin. */
|
|
196
|
+
map?: Record<string, string | null>;
|
|
197
|
+
/** Stopped in the stored entry, so a reselect never loses it. */
|
|
198
|
+
meta?: ModelMeta;
|
|
199
|
+
compat?: Compat;
|
|
190
200
|
}
|
|
191
201
|
|
|
192
202
|
export interface ProviderEntry {
|
|
@@ -199,9 +209,10 @@ export interface ProviderEntry {
|
|
|
199
209
|
}
|
|
200
210
|
|
|
201
211
|
/** Level heuristic over a relay catalog id: the catalogs expose only ids, so an explicit
|
|
202
|
-
* level suffix (`-high`, `-xhigh`, `-max`…) pins that level,
|
|
203
|
-
*
|
|
204
|
-
*
|
|
212
|
+
* level suffix (`-high`, `-xhigh`, `-max`…) pins that level, and everything else starts at
|
|
213
|
+
* `auto` — the endpoint decides. A chat-only model is switched to `off` by hand in the
|
|
214
|
+
* Thinking screen; pi passes an unmapped level through, so an endpoint that rejects
|
|
215
|
+
* reasoning parameters only breaks when `/think` is above `off`. */
|
|
205
216
|
export function detectLevel(id: string): ThinkingSetting {
|
|
206
217
|
const s = id.toLowerCase();
|
|
207
218
|
if (/-x-?high$/.test(s)) return "xhigh";
|
|
@@ -210,9 +221,7 @@ export function detectLevel(id: string): ThinkingSetting {
|
|
|
210
221
|
if (/-med(ium)?$/.test(s)) return "medium";
|
|
211
222
|
if (/-low$/.test(s)) return "low";
|
|
212
223
|
if (/-min(imal)?$/.test(s)) return "minimal";
|
|
213
|
-
|
|
214
|
-
if (/(^|[^a-z0-9])[or][134]([^0-9]|$)/.test(s)) return "auto";
|
|
215
|
-
return "off";
|
|
224
|
+
return "auto";
|
|
216
225
|
}
|
|
217
226
|
|
|
218
227
|
const isObj = (v: unknown): v is Record<string, unknown> => typeof v === "object" && v !== null;
|
|
@@ -223,7 +232,7 @@ export function withProvider(config: unknown, name: string, entry: ProviderEntry
|
|
|
223
232
|
const providers = isObj(root.providers) ? { ...root.providers } : {};
|
|
224
233
|
// The same wire serialization every edit uses, so a first save and a later edit of the
|
|
225
234
|
// same provider produce the same models.json shape.
|
|
226
|
-
providers[name] = { ...entry, models:
|
|
235
|
+
providers[name] = { ...entry, models: wireModels(name, entry, entry.models, []) };
|
|
227
236
|
root.providers = providers;
|
|
228
237
|
return root;
|
|
229
238
|
}
|
|
@@ -294,16 +303,42 @@ export function withProviderModels(config: unknown, name: string, models: Provid
|
|
|
294
303
|
const root = isObj(config) ? { ...config } : {};
|
|
295
304
|
const providers = isObj(root.providers) ? { ...root.providers } : {};
|
|
296
305
|
const base = isObj(providers[name]) ? providers[name] : {};
|
|
297
|
-
|
|
306
|
+
const stated: Record<string, unknown>[] = Array.isArray(base.models) ? base.models.filter(isObj) : [];
|
|
307
|
+
providers[name] = { ...base, models: wireModels(name, base, models, stated) };
|
|
298
308
|
root.providers = providers;
|
|
299
309
|
return root;
|
|
300
310
|
}
|
|
301
311
|
|
|
302
|
-
/**
|
|
303
|
-
|
|
312
|
+
/** One model in pi's wire shape: the level (or a probed map), the compat flags the rules
|
|
313
|
+
* imply, and the limits the probe found. Every other key of the stored entry survives —
|
|
314
|
+
* only `reasoning` and `thinkingLevelMap` are rewritten, because the level owns them. */
|
|
315
|
+
function wireModels(name: string, provider: { api?: unknown; baseUrl?: unknown }, models: ProviderModel[], stated: Record<string, unknown>[]): Record<string, unknown>[] {
|
|
316
|
+
const api = typeof provider.api === "string" ? provider.api : undefined;
|
|
317
|
+
const baseUrl = typeof provider.baseUrl === "string" ? provider.baseUrl : "";
|
|
318
|
+
return models.map((m) => {
|
|
319
|
+
const prev = stated.find((s) => s.id === m.id);
|
|
320
|
+
const next: Record<string, unknown> = { ...(prev ?? {}) };
|
|
321
|
+
next.id = m.id;
|
|
322
|
+
delete next.reasoning;
|
|
323
|
+
delete next.thinkingLevelMap;
|
|
324
|
+
Object.assign(next, m.map ? { reasoning: true, thinkingLevelMap: m.map } : levelToWire(m.level));
|
|
325
|
+
const stored = isObj(next.compat) ? next.compat : {};
|
|
326
|
+
const compat = { ...stored, ...suggestCompat({ provider: name, id: m.id, api, baseUrl, reasoning: next.reasoning === true, compat: stored }), ...(m.compat ?? {}) };
|
|
327
|
+
if (Object.keys(compat).length > 0) next.compat = compat;
|
|
328
|
+
const meta = m.meta ?? (prev && typeof prev === "object" ? { contextWindow: prev.contextWindow as number | undefined, maxTokens: prev.maxTokens as number | undefined } : undefined);
|
|
329
|
+
if (meta?.contextWindow !== undefined) next.contextWindow = meta.contextWindow;
|
|
330
|
+
if (meta?.maxTokens !== undefined) next.maxTokens = meta.maxTokens;
|
|
331
|
+
return next;
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/** A stored selection keeps its level; a new id gets the detected one. A probed limit is
|
|
336
|
+
* merged into the stored one, so a reselect never loses what an earlier probe learned. */
|
|
337
|
+
export function mergeLevels(entry: ProviderEntry, ids: string[], meta?: Map<string, ModelMeta>): ProviderModel[] {
|
|
304
338
|
return ids.map((id) => {
|
|
305
339
|
const existing = entry.models.find((m) => m.id === id);
|
|
306
|
-
|
|
340
|
+
const found = meta?.get(id);
|
|
341
|
+
return { id, level: existing?.level ?? detectLevel(id), meta: found ? mergeMeta(existing?.meta, found) : existing?.meta };
|
|
307
342
|
});
|
|
308
343
|
}
|
|
309
344
|
|
|
@@ -349,6 +384,11 @@ export function loadModelsConfig(): unknown {
|
|
|
349
384
|
return readJson(modelsPath());
|
|
350
385
|
}
|
|
351
386
|
|
|
387
|
+
/** Replace models.json whole, atomically (Model Heal writes a config it read and edited). */
|
|
388
|
+
export function saveModelsConfig(value: unknown): void {
|
|
389
|
+
writeJson(modelsPath(), value);
|
|
390
|
+
}
|
|
391
|
+
|
|
352
392
|
export function saveProvider(name: string, entry: ProviderEntry, key: string | undefined): void {
|
|
353
393
|
writeJson(modelsPath(), withProvider(readJson(modelsPath()), name, entry));
|
|
354
394
|
if (key) writeJson(authPath(), withAuth(readJson(authPath()), name, key));
|
|
@@ -381,7 +421,10 @@ export function loadProviderEntry(config: unknown, name: string): ProviderEntry
|
|
|
381
421
|
? (value.models as unknown[]).flatMap((m): ProviderModel[] => {
|
|
382
422
|
if (!isObj(m) || typeof m.id !== "string") return [];
|
|
383
423
|
const level = wireToLevel(m.reasoning, m.thinkingLevelMap);
|
|
384
|
-
|
|
424
|
+
const contextWindow = typeof m.contextWindow === "number" ? m.contextWindow : undefined;
|
|
425
|
+
const maxTokens = typeof m.maxTokens === "number" ? m.maxTokens : undefined;
|
|
426
|
+
const meta = contextWindow === undefined && maxTokens === undefined ? undefined : { contextWindow, maxTokens };
|
|
427
|
+
return [{ id: m.id, ...(level === "off" ? {} : { level }), ...(meta ? { meta } : {}), ...(isObj(m.compat) ? { compat: m.compat } : {}) }];
|
|
385
428
|
})
|
|
386
429
|
: [];
|
|
387
430
|
return {
|
|
@@ -584,7 +627,7 @@ const addProviderFlow = async (ctx: ExtensionCommandContext): Promise<void> => {
|
|
|
584
627
|
name,
|
|
585
628
|
baseUrl: chatBaseUrl(flavor, endpoint),
|
|
586
629
|
api: flavor,
|
|
587
|
-
models: mergeLevels({ name, baseUrl:
|
|
630
|
+
models: mergeLevels({ name, baseUrl: chatBaseUrl(flavor, endpoint), api: flavor, models: [] }, picked, result?.meta),
|
|
588
631
|
};
|
|
589
632
|
// A keyless endpoint still needs a resolvable credential for pi to list the models.
|
|
590
633
|
if (!key) entry.apiKey = result?.keyless ? "ollama" : "dummy";
|
|
@@ -669,25 +712,86 @@ const probeModelsFlow = async (ctx: ExtensionCommandContext, name: string, entry
|
|
|
669
712
|
if (answer === undefined || answer === "") return;
|
|
670
713
|
picked = answer.split(/[\s,]+/).filter(Boolean);
|
|
671
714
|
}
|
|
672
|
-
saveModelsNamed(ctx, name, mergeLevels(entry, picked));
|
|
715
|
+
saveModelsNamed(ctx, name, mergeLevels(entry, picked, result.meta));
|
|
673
716
|
};
|
|
674
717
|
|
|
675
|
-
const THINKING_LEGEND = "[↑↓] Move [Space] Cycle [Enter] Save [Esc] Cancel";
|
|
718
|
+
const THINKING_LEGEND = "[↑↓] Move [Space] Cycle [A] All auto [R] All off [p] Probe [Enter] Save [Esc] Cancel";
|
|
676
719
|
|
|
677
720
|
/** Space cycles one model through off → auto → minimal → … → max. `auto` means
|
|
678
721
|
* `reasoning: true` with no map (every `/think` level passes through unchanged); an
|
|
679
|
-
* explicit level pins `thinkingLevelMap` to that single value.
|
|
722
|
+
* explicit level pins `thinkingLevelMap` to that single value. `p` asks the channel which
|
|
723
|
+
* effort names it really accepts and stores the answer as the model's map. */
|
|
680
724
|
const thinkingFlow = async (ctx: ExtensionCommandContext, name: string, entry: ProviderEntry): Promise<void> => {
|
|
681
725
|
const levels = new Map(entry.models.map((m) => [m.id, m.level ?? detectLevel(m.id)] as const));
|
|
726
|
+
const probed = new Map<string, Record<string, string | null>>();
|
|
682
727
|
const cycle = (label: string): void => {
|
|
683
728
|
const current = levels.get(label) ?? "off";
|
|
684
729
|
const next = THINKING_SETTINGS[(THINKING_SETTINGS.indexOf(current) + 1) % THINKING_SETTINGS.length]!;
|
|
685
730
|
levels.set(label, next);
|
|
731
|
+
// A probed map belongs to `auto` only: a pinned level states its own answer.
|
|
732
|
+
if (next !== "auto") probed.delete(label);
|
|
686
733
|
};
|
|
687
734
|
const rows: ListRow[] = entry.models.map((m) => ({ label: m.id }));
|
|
735
|
+
/** "medium→high, max off" — what a probed map actually changed. */
|
|
736
|
+
const summary = (map: Record<string, string | null>): string => {
|
|
737
|
+
const parts = Object.entries(map)
|
|
738
|
+
.filter(([level, value]) => value !== level && !(value === null && level === "off"))
|
|
739
|
+
.map(([level, value]) => (value === null ? `${level} off` : `${level}→${value}`));
|
|
740
|
+
return parts.length === 0 ? "all levels accepted" : parts.join(", ");
|
|
741
|
+
};
|
|
742
|
+
let busy: string | undefined;
|
|
743
|
+
let progress: string | undefined;
|
|
744
|
+
let warn: string | undefined;
|
|
745
|
+
let refresh: () => void = () => {};
|
|
746
|
+
let closed = false;
|
|
747
|
+
const probe = async (label: string): Promise<void> => {
|
|
748
|
+
const model = entry.models.find((m) => m.id === label);
|
|
749
|
+
const compat = model?.compat ?? {};
|
|
750
|
+
if (!isEffortProbeable({ provider: name, id: label, api: entry.api, baseUrl: entry.baseUrl, reasoning: true, compat }, compat)) {
|
|
751
|
+
warn = `${label}: this channel does not take a probing request (not an OpenAI-compatible reasoning model).`;
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
busy = label;
|
|
755
|
+
progress = "starting…";
|
|
756
|
+
refresh();
|
|
757
|
+
const inline = entry.apiKey && entry.apiKey !== "dummy" && entry.apiKey !== "ollama" ? entry.apiKey : undefined;
|
|
758
|
+
try {
|
|
759
|
+
const supported = await probeEffort(
|
|
760
|
+
{ provider: name, id: label, api: entry.api, baseUrl: entry.baseUrl, reasoning: true, compat },
|
|
761
|
+
{
|
|
762
|
+
baseUrl: entry.baseUrl,
|
|
763
|
+
key: readAuthKey(name) ?? inline,
|
|
764
|
+
onLevel: (level, _accepted, index) => {
|
|
765
|
+
progress = `${level} · ${index + 1}/7`;
|
|
766
|
+
refresh();
|
|
767
|
+
},
|
|
768
|
+
},
|
|
769
|
+
);
|
|
770
|
+
if (supported.length === 0) {
|
|
771
|
+
warn = `${label}: no effort level answered — the map is unchanged.`;
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
const current = probed.get(label) ?? levelToWire(levels.get(label))?.thinkingLevelMap;
|
|
775
|
+
const next = buildEffortMap(current, supported);
|
|
776
|
+
if (next) probed.set(label, next);
|
|
777
|
+
levels.set(label, "auto");
|
|
778
|
+
warn = `${label}: ${next ? summary(next) : "every level is accepted as-is"}.`;
|
|
779
|
+
} finally {
|
|
780
|
+
busy = undefined;
|
|
781
|
+
progress = undefined;
|
|
782
|
+
refresh();
|
|
783
|
+
}
|
|
784
|
+
};
|
|
688
785
|
let saved: boolean;
|
|
689
786
|
if (ctx.mode === "tui") {
|
|
690
787
|
const outcome = await ctx.ui.custom<boolean | null>((tui, theme, _kb, done) => {
|
|
788
|
+
refresh = () => {
|
|
789
|
+
if (!closed) tui.requestRender();
|
|
790
|
+
};
|
|
791
|
+
const close = (value: boolean | null) => {
|
|
792
|
+
closed = true;
|
|
793
|
+
done(value);
|
|
794
|
+
};
|
|
691
795
|
const picker = new ListPicker(
|
|
692
796
|
theme,
|
|
693
797
|
rows,
|
|
@@ -695,16 +799,43 @@ const thinkingFlow = async (ctx: ExtensionCommandContext, name: string, entry: P
|
|
|
695
799
|
{
|
|
696
800
|
preview: () => {},
|
|
697
801
|
revert: () => {},
|
|
698
|
-
|
|
699
|
-
|
|
802
|
+
// A probe is a round trip, but it never owns the screen: leaving mid-probe just
|
|
803
|
+
// discards the answer, because the save reads `probed` before it lands.
|
|
804
|
+
done: () => close(true),
|
|
805
|
+
cancel: () => close(null),
|
|
700
806
|
// A fill screen: `←` is hidden — it must not throw away half-set levels.
|
|
701
807
|
back: false,
|
|
702
|
-
requestRender: () =>
|
|
808
|
+
requestRender: () => refresh(),
|
|
703
809
|
toggle: () => {
|
|
704
810
|
const label = rows[picker.index]?.label;
|
|
705
|
-
if (label) cycle(label);
|
|
811
|
+
if (label && !busy) cycle(label);
|
|
812
|
+
},
|
|
813
|
+
press: (keyData) => {
|
|
814
|
+
if (busy) return;
|
|
815
|
+
// Plain letters only: Ctrl/Alt/F-keys are swallowed or remapped by some
|
|
816
|
+
// terminals, so the two bulk keys stay on the same key everywhere. Shift keeps
|
|
817
|
+
// them deliberate — pi-tui lowercases a key id, so "A" would mean plain `a`.
|
|
818
|
+
if (matchesKey(keyData, "shift+a")) {
|
|
819
|
+
for (const id of levels.keys()) levels.set(id, "auto");
|
|
820
|
+
probed.clear();
|
|
821
|
+
refresh();
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
if (matchesKey(keyData, "shift+r")) {
|
|
825
|
+
for (const id of levels.keys()) levels.set(id, "off");
|
|
826
|
+
probed.clear();
|
|
827
|
+
refresh();
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
const label = rows[picker.index]?.label;
|
|
831
|
+
if (!label || !matchesKey(keyData, "p")) return;
|
|
832
|
+
void probe(label);
|
|
833
|
+
},
|
|
834
|
+
note: (label) => {
|
|
835
|
+
if (busy === label) return `probing ${progress ?? ""}`.trim();
|
|
836
|
+
const map = probed.get(label);
|
|
837
|
+
return `${levels.get(label) ?? "off"}${map ? ` · ${summary(map)}` : ""}`;
|
|
706
838
|
},
|
|
707
|
-
note: (label) => levels.get(label) ?? "off",
|
|
708
839
|
description: () => `cycle: ${THINKING_SETTINGS.join(" → ")}`,
|
|
709
840
|
legend: () =>
|
|
710
841
|
`${theme.fg("accent", `${[...levels.values()].filter((l) => l !== "off").length}/${rows.length} thinking`)}${theme.fg("dim", ` · ${THINKING_LEGEND}`)}`,
|
|
@@ -728,7 +859,16 @@ const thinkingFlow = async (ctx: ExtensionCommandContext, name: string, entry: P
|
|
|
728
859
|
saved = true;
|
|
729
860
|
}
|
|
730
861
|
if (!saved) return;
|
|
731
|
-
saveModelsNamed(
|
|
862
|
+
saveModelsNamed(
|
|
863
|
+
ctx,
|
|
864
|
+
name,
|
|
865
|
+
entry.models.map((m) => {
|
|
866
|
+
const level = levels.get(m.id);
|
|
867
|
+
const map = level === "off" ? undefined : probed.get(m.id);
|
|
868
|
+
return { id: m.id, level, ...(map ? { map } : {}) };
|
|
869
|
+
}),
|
|
870
|
+
);
|
|
871
|
+
if (warn) ctx.ui.notify(`[arnative] ${warn}`, "info");
|
|
732
872
|
};
|
|
733
873
|
|
|
734
874
|
const ACTION_SELECT = "Select models";
|
|
@@ -881,7 +1021,7 @@ if (isMain(import.meta.url)) {
|
|
|
881
1021
|
assert(paths.includes("https://x.com/v1/models") && paths.includes("https://x.com/api/tags") && paths.includes("https://x.com/v1beta/models"), "a bare base probes the common layouts");
|
|
882
1022
|
const authed = buildCandidates("https://x.com", "sk-1")[0]!;
|
|
883
1023
|
assert(authed.url === "https://x.com/api/tags", "the ollama probe comes first");
|
|
884
|
-
const openaiShape = { data: [{ id: "m1" }, { id: "m2" }] };
|
|
1024
|
+
const openaiShape = { data: [{ id: "m1", context_length: 262_144, max_output_tokens: 32_000 }, { id: "m2" }] };
|
|
885
1025
|
const geminiShape = { models: [{ name: "models/gemini-x" }] };
|
|
886
1026
|
const ollamaShape = { models: [{ name: "qwen:7b" }] };
|
|
887
1027
|
assert(parseModelList(listPath, openaiShape)!.join() === "m1,m2", "data[].id parses");
|
|
@@ -907,6 +1047,7 @@ if (isMain(import.meta.url)) {
|
|
|
907
1047
|
assert(probeGemini?.flavor === "google-generative-ai" && probeGemini.models[0] === "gemini-x", "a gemini answer is detected");
|
|
908
1048
|
const probeOpenai = await probeEndpoint("https://api.x.com/v1", "k", route({ "/v1/models": openaiShape }));
|
|
909
1049
|
assert(probeOpenai?.flavor === "openai-completions" && probeOpenai.baseUrl === "https://api.x.com/v1", "an openai answer is detected");
|
|
1050
|
+
assert(probeOpenai?.meta.get("m1")?.contextWindow === 262_144 && probeOpenai.meta.get("m1")?.maxTokens === 32_000, "the same answer carries the limits, so no second request is needed");
|
|
910
1051
|
const none = await probeEndpoint("https://api.x.com", "", route({}));
|
|
911
1052
|
assert(none === undefined, "no answer → undefined, the caller falls back to manual entry");
|
|
912
1053
|
const empty = await probeEndpoint("https://api.x.com/v1", "", route({ "/v1/models": { data: [] } }));
|
|
@@ -965,10 +1106,8 @@ if (isMain(import.meta.url)) {
|
|
|
965
1106
|
assert(detectLevel("deepseek-reasoner") === "auto", "reasoner means flexible thinking");
|
|
966
1107
|
assert(detectLevel("o1-mini") === "auto", "an o-generation id means flexible thinking");
|
|
967
1108
|
assert(detectLevel("deepseek-r1") === "auto", "r1 means flexible thinking");
|
|
968
|
-
assert(detectLevel("ocz/mimo-v2.6-flash-free") === "
|
|
969
|
-
assert(detectLevel("
|
|
970
|
-
assert(detectLevel("oc/big-pickle") === "off", "an unrelated id is chat");
|
|
971
|
-
assert(detectLevel("river/Qwen/Qwen3.8-27B-FP8") === "off", "qwen without a thinking token is chat");
|
|
1109
|
+
assert(detectLevel("ocz/mimo-v2.6-flash-free") === "auto", "a plain flash id starts at auto");
|
|
1110
|
+
assert(detectLevel("oc/big-pickle") === "auto", "an unrelated id starts at auto");
|
|
972
1111
|
|
|
973
1112
|
// Levels serialize to pi's wire shape and read back unchanged.
|
|
974
1113
|
const wireHigh = levelToWire("high") as { reasoning?: boolean; thinkingLevelMap?: Record<string, string | null> };
|
|
@@ -989,9 +1128,25 @@ if (isMain(import.meta.url)) {
|
|
|
989
1128
|
assert(savedProvider.compat !== undefined && savedProvider.name === "R", "withProviderModels keeps sibling fields");
|
|
990
1129
|
const savedModels = savedProvider.models as { id: string; reasoning?: boolean; thinkingLevelMap?: Record<string, string | null> }[];
|
|
991
1130
|
assert(savedModels[0]!.id === "m2" && savedModels[0]!.reasoning === true && savedModels[0]!.thinkingLevelMap?.high === "high", "withProviderModels serializes the level");
|
|
992
|
-
const
|
|
1131
|
+
const savedCompat = (savedModels[0] as { compat?: Record<string, unknown> }).compat;
|
|
1132
|
+
assert(savedCompat?.supportsLongCacheRetention === false && savedCompat?.sendSessionAffinityHeaders === true, "a save writes the compat flags a relay needs");
|
|
1133
|
+
|
|
1134
|
+
// A probe's limits land in the entry and survive a later edit that does not mention them.
|
|
1135
|
+
const withMeta = withProviderModels(rich, "r", [{ id: "m1", level: "auto", meta: { contextWindow: 1_000_000, maxTokens: 64_000 } }]);
|
|
1136
|
+
const metaModels = (withMeta.providers as Record<string, { models: { id: string; contextWindow?: number; maxTokens?: number }[] }>).r!.models;
|
|
1137
|
+
assert(metaModels[0]!.contextWindow === 1_000_000 && metaModels[0]!.maxTokens === 64_000, "a probed window and cap are written");
|
|
1138
|
+
const keptMeta = withProviderModels(withMeta, "r", [{ id: "m1", level: "high" }]);
|
|
1139
|
+
const keptModel = (keptMeta.providers as Record<string, { models: { contextWindow?: number; maxTokens?: number }[] }>).r!.models[0]!;
|
|
1140
|
+
assert(keptModel.contextWindow === 1_000_000 && keptModel.maxTokens === 64_000, "an edit that says nothing about limits keeps them");
|
|
1141
|
+
assert((loadProviderEntry(withMeta, "r")?.models[0]!.meta?.contextWindow ?? 0) === 1_000_000, "the limits load back as meta");
|
|
1142
|
+
const probedMap = withProviderModels(rich, "r", [{ id: "m1", level: "auto", map: { medium: "high", xhigh: null } }]);
|
|
1143
|
+
const probedModel = (probedMap.providers as Record<string, { models: { reasoning?: boolean; thinkingLevelMap?: Record<string, string | null> }[] }>).r!.models[0]!;
|
|
1144
|
+
assert(probedModel.reasoning === true && probedModel.thinkingLevelMap?.medium === "high", "a probed map wins over the level's own pin");
|
|
1145
|
+
const levelAfterProbe = withProviderModels(probedMap, "r", [{ id: "m1", level: "high" }]);
|
|
1146
|
+
assert((levelAfterProbe.providers as Record<string, { models: { thinkingLevelMap?: Record<string, string | null> }[] }>).r!.models[0]!.thinkingLevelMap?.high === "high", "changing the level replaces the probed map");
|
|
1147
|
+
const merged = mergeLevels({ name: "n", baseUrl: "b", api: "openai-completions", models: [{ id: "m1", level: "auto" }, { id: "m2", level: "off" }] }, ["m2", "x-thinking"]);
|
|
993
1148
|
assert(merged[0]!.id === "m2" && merged[0]!.level === "off", "a stored chat model stays chat");
|
|
994
|
-
assert(merged[1]!.level === "auto", "a new
|
|
1149
|
+
assert(merged[1]!.level === "auto", "a new id defaults to auto");
|
|
995
1150
|
const keptFlag = mergeLevels({ name: "n", baseUrl: "b", api: "openai-completions", models: [{ id: "m1", level: "low" }] }, ["m1"]);
|
|
996
1151
|
assert(keptFlag[0]!.level === "low", "a stored level survives a reselect");
|
|
997
1152
|
const entryLoaded = loadProviderEntry(rich, "r");
|
|
@@ -1001,6 +1156,10 @@ if (isMain(import.meta.url)) {
|
|
|
1001
1156
|
assert(roundTrip?.models[0]!.level === "xhigh", "a saved level loads back as itself");
|
|
1002
1157
|
assert(levelsSummary([{ id: "a" }, { id: "b", level: "high" }, { id: "c", level: "auto" }]) === "2 thinking (high, auto)", "the save notify names the registered levels");
|
|
1003
1158
|
assert(levelsSummary([{ id: "a" }]) === "0 thinking", "an all-chat save says so plainly");
|
|
1159
|
+
// The Thinking screen's bulk keys are Shift+letter: pi-tui lowercases a key id, so this
|
|
1160
|
+
// pins that they stay distinct from the plain letters navigation already uses.
|
|
1161
|
+
assert(matchesKey("A", "shift+a") && !matchesKey("a", "shift+a"), "Shift+A is its own key, not plain a");
|
|
1162
|
+
assert(matchesKey("R", "shift+r") && !matchesKey("r", "shift+r"), "Shift+R is its own key, not plain r");
|
|
1004
1163
|
|
|
1005
1164
|
// The stored key is read back from auth.json in an isolated agent dir (never the user's).
|
|
1006
1165
|
const tmp = mkdtempSync(join(tmpdir(), "arnative-providers-"));
|
package/lib/usage-store.ts
CHANGED
|
@@ -634,7 +634,7 @@ const canonicalModel = (id: string): string => {
|
|
|
634
634
|
*
|
|
635
635
|
* The rule used to also match a bare tail (`target.endsWith("/" + name)`), so the first run
|
|
636
636
|
* under a new provider inherited the history of every other provider whose id ended the same
|
|
637
|
-
* way: `
|
|
637
|
+
* way: `team/deepseek-ai/DeepSeek-V4.1-Flash` reported two other providers' deepseek totals
|
|
638
638
|
* (29.5M in / 3.2M out / 360.5M cache) as its own (2026-10-17). Two ids that differ are two
|
|
639
639
|
* routes — billed, rate-limited and counted apart — and only the vendor knows whether a short
|
|
640
640
|
* id and a path id are the same model, so the tab shows the tokens of the id it names. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bismawy/pi-arnative",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Refined aesthetics. Cohesive tools. Built for Pi. Warm themes, rounded tool boxes, tabbed header, compact footer and a /usage dashboard.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"@earendil-works/pi-tui": "*"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
|
-
"dev": "pi --extension ./extensions/tools.ts --extension ./extensions/section-headers.ts --extension ./extensions/footer.ts --extension ./extensions/timestamps.ts --extension ./extensions/ui-render-tweaks.ts --extension ./extensions/usage.ts --extension ./extensions/animations.ts --extension ./extensions/arnative.ts",
|
|
44
|
-
"test": "node lib/box.ts && node lib/ansi.ts && node lib/color.ts && node lib/shortcuts.ts && node lib/preset-store.ts && node lib/spinner.ts && node themes/gen-themes.mjs --check && node extensions/tools.ts && node lib/list-picker.ts && node lib/provider.ts && node extensions/footer.ts && node extensions/timestamps.ts && node extensions/ui-render-tweaks.ts && node extensions/usage.ts && node extensions/animations.ts && node extensions/arnative.ts && node --test",
|
|
43
|
+
"dev": "pi --extension ./extensions/tools.ts --extension ./extensions/section-headers.ts --extension ./extensions/footer.ts --extension ./extensions/timestamps.ts --extension ./extensions/ui-render-tweaks.ts --extension ./extensions/usage.ts --extension ./extensions/animations.ts --extension ./extensions/autocompact.ts --extension ./extensions/model-heal.ts --extension ./extensions/arnative.ts",
|
|
44
|
+
"test": "node lib/box.ts && node lib/ansi.ts && node lib/color.ts && node lib/shortcuts.ts && node lib/preset-store.ts && node lib/spinner.ts && node themes/gen-themes.mjs --check && node extensions/tools.ts && node lib/list-picker.ts && node lib/compat.ts && node lib/provider.ts && node lib/model-heal.ts && node extensions/footer.ts && node extensions/timestamps.ts && node extensions/ui-render-tweaks.ts && node extensions/usage.ts && node extensions/animations.ts && node extensions/autocompact.ts && node extensions/model-heal.ts && node extensions/arnative.ts && node --test",
|
|
45
45
|
"preview": "node scripts/preview.mjs",
|
|
46
46
|
"themes": "node themes/gen-themes.mjs",
|
|
47
47
|
"release:check": "node scripts/release-check.mjs pre-tag",
|