@bismawy/pi-arnative 0.7.0 → 0.8.0-rc.1
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 +15 -0
- package/README.md +17 -4
- package/extensions/arnative.ts +89 -6
- package/extensions/autocompact.ts +294 -0
- package/extensions/footer.ts +3 -3
- 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/provider.ts +186 -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
|
|
|
@@ -381,7 +416,10 @@ export function loadProviderEntry(config: unknown, name: string): ProviderEntry
|
|
|
381
416
|
? (value.models as unknown[]).flatMap((m): ProviderModel[] => {
|
|
382
417
|
if (!isObj(m) || typeof m.id !== "string") return [];
|
|
383
418
|
const level = wireToLevel(m.reasoning, m.thinkingLevelMap);
|
|
384
|
-
|
|
419
|
+
const contextWindow = typeof m.contextWindow === "number" ? m.contextWindow : undefined;
|
|
420
|
+
const maxTokens = typeof m.maxTokens === "number" ? m.maxTokens : undefined;
|
|
421
|
+
const meta = contextWindow === undefined && maxTokens === undefined ? undefined : { contextWindow, maxTokens };
|
|
422
|
+
return [{ id: m.id, ...(level === "off" ? {} : { level }), ...(meta ? { meta } : {}), ...(isObj(m.compat) ? { compat: m.compat } : {}) }];
|
|
385
423
|
})
|
|
386
424
|
: [];
|
|
387
425
|
return {
|
|
@@ -584,7 +622,7 @@ const addProviderFlow = async (ctx: ExtensionCommandContext): Promise<void> => {
|
|
|
584
622
|
name,
|
|
585
623
|
baseUrl: chatBaseUrl(flavor, endpoint),
|
|
586
624
|
api: flavor,
|
|
587
|
-
models: mergeLevels({ name, baseUrl:
|
|
625
|
+
models: mergeLevels({ name, baseUrl: chatBaseUrl(flavor, endpoint), api: flavor, models: [] }, picked, result?.meta),
|
|
588
626
|
};
|
|
589
627
|
// A keyless endpoint still needs a resolvable credential for pi to list the models.
|
|
590
628
|
if (!key) entry.apiKey = result?.keyless ? "ollama" : "dummy";
|
|
@@ -669,25 +707,86 @@ const probeModelsFlow = async (ctx: ExtensionCommandContext, name: string, entry
|
|
|
669
707
|
if (answer === undefined || answer === "") return;
|
|
670
708
|
picked = answer.split(/[\s,]+/).filter(Boolean);
|
|
671
709
|
}
|
|
672
|
-
saveModelsNamed(ctx, name, mergeLevels(entry, picked));
|
|
710
|
+
saveModelsNamed(ctx, name, mergeLevels(entry, picked, result.meta));
|
|
673
711
|
};
|
|
674
712
|
|
|
675
|
-
const THINKING_LEGEND = "[↑↓] Move [Space] Cycle [Enter] Save [Esc] Cancel";
|
|
713
|
+
const THINKING_LEGEND = "[↑↓] Move [Space] Cycle [A] All auto [R] All off [p] Probe [Enter] Save [Esc] Cancel";
|
|
676
714
|
|
|
677
715
|
/** Space cycles one model through off → auto → minimal → … → max. `auto` means
|
|
678
716
|
* `reasoning: true` with no map (every `/think` level passes through unchanged); an
|
|
679
|
-
* explicit level pins `thinkingLevelMap` to that single value.
|
|
717
|
+
* explicit level pins `thinkingLevelMap` to that single value. `p` asks the channel which
|
|
718
|
+
* effort names it really accepts and stores the answer as the model's map. */
|
|
680
719
|
const thinkingFlow = async (ctx: ExtensionCommandContext, name: string, entry: ProviderEntry): Promise<void> => {
|
|
681
720
|
const levels = new Map(entry.models.map((m) => [m.id, m.level ?? detectLevel(m.id)] as const));
|
|
721
|
+
const probed = new Map<string, Record<string, string | null>>();
|
|
682
722
|
const cycle = (label: string): void => {
|
|
683
723
|
const current = levels.get(label) ?? "off";
|
|
684
724
|
const next = THINKING_SETTINGS[(THINKING_SETTINGS.indexOf(current) + 1) % THINKING_SETTINGS.length]!;
|
|
685
725
|
levels.set(label, next);
|
|
726
|
+
// A probed map belongs to `auto` only: a pinned level states its own answer.
|
|
727
|
+
if (next !== "auto") probed.delete(label);
|
|
686
728
|
};
|
|
687
729
|
const rows: ListRow[] = entry.models.map((m) => ({ label: m.id }));
|
|
730
|
+
/** "medium→high, max off" — what a probed map actually changed. */
|
|
731
|
+
const summary = (map: Record<string, string | null>): string => {
|
|
732
|
+
const parts = Object.entries(map)
|
|
733
|
+
.filter(([level, value]) => value !== level && !(value === null && level === "off"))
|
|
734
|
+
.map(([level, value]) => (value === null ? `${level} off` : `${level}→${value}`));
|
|
735
|
+
return parts.length === 0 ? "all levels accepted" : parts.join(", ");
|
|
736
|
+
};
|
|
737
|
+
let busy: string | undefined;
|
|
738
|
+
let progress: string | undefined;
|
|
739
|
+
let warn: string | undefined;
|
|
740
|
+
let refresh: () => void = () => {};
|
|
741
|
+
let closed = false;
|
|
742
|
+
const probe = async (label: string): Promise<void> => {
|
|
743
|
+
const model = entry.models.find((m) => m.id === label);
|
|
744
|
+
const compat = model?.compat ?? {};
|
|
745
|
+
if (!isEffortProbeable({ provider: name, id: label, api: entry.api, baseUrl: entry.baseUrl, reasoning: true, compat }, compat)) {
|
|
746
|
+
warn = `${label}: this channel does not take a probing request (not an OpenAI-compatible reasoning model).`;
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
busy = label;
|
|
750
|
+
progress = "starting…";
|
|
751
|
+
refresh();
|
|
752
|
+
const inline = entry.apiKey && entry.apiKey !== "dummy" && entry.apiKey !== "ollama" ? entry.apiKey : undefined;
|
|
753
|
+
try {
|
|
754
|
+
const supported = await probeEffort(
|
|
755
|
+
{ provider: name, id: label, api: entry.api, baseUrl: entry.baseUrl, reasoning: true, compat },
|
|
756
|
+
{
|
|
757
|
+
baseUrl: entry.baseUrl,
|
|
758
|
+
key: readAuthKey(name) ?? inline,
|
|
759
|
+
onLevel: (level, _accepted, index) => {
|
|
760
|
+
progress = `${level} · ${index + 1}/7`;
|
|
761
|
+
refresh();
|
|
762
|
+
},
|
|
763
|
+
},
|
|
764
|
+
);
|
|
765
|
+
if (supported.length === 0) {
|
|
766
|
+
warn = `${label}: no effort level answered — the map is unchanged.`;
|
|
767
|
+
return;
|
|
768
|
+
}
|
|
769
|
+
const current = probed.get(label) ?? levelToWire(levels.get(label))?.thinkingLevelMap;
|
|
770
|
+
const next = buildEffortMap(current, supported);
|
|
771
|
+
if (next) probed.set(label, next);
|
|
772
|
+
levels.set(label, "auto");
|
|
773
|
+
warn = `${label}: ${next ? summary(next) : "every level is accepted as-is"}.`;
|
|
774
|
+
} finally {
|
|
775
|
+
busy = undefined;
|
|
776
|
+
progress = undefined;
|
|
777
|
+
refresh();
|
|
778
|
+
}
|
|
779
|
+
};
|
|
688
780
|
let saved: boolean;
|
|
689
781
|
if (ctx.mode === "tui") {
|
|
690
782
|
const outcome = await ctx.ui.custom<boolean | null>((tui, theme, _kb, done) => {
|
|
783
|
+
refresh = () => {
|
|
784
|
+
if (!closed) tui.requestRender();
|
|
785
|
+
};
|
|
786
|
+
const close = (value: boolean | null) => {
|
|
787
|
+
closed = true;
|
|
788
|
+
done(value);
|
|
789
|
+
};
|
|
691
790
|
const picker = new ListPicker(
|
|
692
791
|
theme,
|
|
693
792
|
rows,
|
|
@@ -695,16 +794,43 @@ const thinkingFlow = async (ctx: ExtensionCommandContext, name: string, entry: P
|
|
|
695
794
|
{
|
|
696
795
|
preview: () => {},
|
|
697
796
|
revert: () => {},
|
|
698
|
-
|
|
699
|
-
|
|
797
|
+
// A probe is a round trip, but it never owns the screen: leaving mid-probe just
|
|
798
|
+
// discards the answer, because the save reads `probed` before it lands.
|
|
799
|
+
done: () => close(true),
|
|
800
|
+
cancel: () => close(null),
|
|
700
801
|
// A fill screen: `←` is hidden — it must not throw away half-set levels.
|
|
701
802
|
back: false,
|
|
702
|
-
requestRender: () =>
|
|
803
|
+
requestRender: () => refresh(),
|
|
703
804
|
toggle: () => {
|
|
704
805
|
const label = rows[picker.index]?.label;
|
|
705
|
-
if (label) cycle(label);
|
|
806
|
+
if (label && !busy) cycle(label);
|
|
807
|
+
},
|
|
808
|
+
press: (keyData) => {
|
|
809
|
+
if (busy) return;
|
|
810
|
+
// Plain letters only: Ctrl/Alt/F-keys are swallowed or remapped by some
|
|
811
|
+
// terminals, so the two bulk keys stay on the same key everywhere. Shift keeps
|
|
812
|
+
// them deliberate — pi-tui lowercases a key id, so "A" would mean plain `a`.
|
|
813
|
+
if (matchesKey(keyData, "shift+a")) {
|
|
814
|
+
for (const id of levels.keys()) levels.set(id, "auto");
|
|
815
|
+
probed.clear();
|
|
816
|
+
refresh();
|
|
817
|
+
return;
|
|
818
|
+
}
|
|
819
|
+
if (matchesKey(keyData, "shift+r")) {
|
|
820
|
+
for (const id of levels.keys()) levels.set(id, "off");
|
|
821
|
+
probed.clear();
|
|
822
|
+
refresh();
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
const label = rows[picker.index]?.label;
|
|
826
|
+
if (!label || !matchesKey(keyData, "p")) return;
|
|
827
|
+
void probe(label);
|
|
828
|
+
},
|
|
829
|
+
note: (label) => {
|
|
830
|
+
if (busy === label) return `probing ${progress ?? ""}`.trim();
|
|
831
|
+
const map = probed.get(label);
|
|
832
|
+
return `${levels.get(label) ?? "off"}${map ? ` · ${summary(map)}` : ""}`;
|
|
706
833
|
},
|
|
707
|
-
note: (label) => levels.get(label) ?? "off",
|
|
708
834
|
description: () => `cycle: ${THINKING_SETTINGS.join(" → ")}`,
|
|
709
835
|
legend: () =>
|
|
710
836
|
`${theme.fg("accent", `${[...levels.values()].filter((l) => l !== "off").length}/${rows.length} thinking`)}${theme.fg("dim", ` · ${THINKING_LEGEND}`)}`,
|
|
@@ -728,7 +854,16 @@ const thinkingFlow = async (ctx: ExtensionCommandContext, name: string, entry: P
|
|
|
728
854
|
saved = true;
|
|
729
855
|
}
|
|
730
856
|
if (!saved) return;
|
|
731
|
-
saveModelsNamed(
|
|
857
|
+
saveModelsNamed(
|
|
858
|
+
ctx,
|
|
859
|
+
name,
|
|
860
|
+
entry.models.map((m) => {
|
|
861
|
+
const level = levels.get(m.id);
|
|
862
|
+
const map = level === "off" ? undefined : probed.get(m.id);
|
|
863
|
+
return { id: m.id, level, ...(map ? { map } : {}) };
|
|
864
|
+
}),
|
|
865
|
+
);
|
|
866
|
+
if (warn) ctx.ui.notify(`[arnative] ${warn}`, "info");
|
|
732
867
|
};
|
|
733
868
|
|
|
734
869
|
const ACTION_SELECT = "Select models";
|
|
@@ -881,7 +1016,7 @@ if (isMain(import.meta.url)) {
|
|
|
881
1016
|
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
1017
|
const authed = buildCandidates("https://x.com", "sk-1")[0]!;
|
|
883
1018
|
assert(authed.url === "https://x.com/api/tags", "the ollama probe comes first");
|
|
884
|
-
const openaiShape = { data: [{ id: "m1" }, { id: "m2" }] };
|
|
1019
|
+
const openaiShape = { data: [{ id: "m1", context_length: 262_144, max_output_tokens: 32_000 }, { id: "m2" }] };
|
|
885
1020
|
const geminiShape = { models: [{ name: "models/gemini-x" }] };
|
|
886
1021
|
const ollamaShape = { models: [{ name: "qwen:7b" }] };
|
|
887
1022
|
assert(parseModelList(listPath, openaiShape)!.join() === "m1,m2", "data[].id parses");
|
|
@@ -907,6 +1042,7 @@ if (isMain(import.meta.url)) {
|
|
|
907
1042
|
assert(probeGemini?.flavor === "google-generative-ai" && probeGemini.models[0] === "gemini-x", "a gemini answer is detected");
|
|
908
1043
|
const probeOpenai = await probeEndpoint("https://api.x.com/v1", "k", route({ "/v1/models": openaiShape }));
|
|
909
1044
|
assert(probeOpenai?.flavor === "openai-completions" && probeOpenai.baseUrl === "https://api.x.com/v1", "an openai answer is detected");
|
|
1045
|
+
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
1046
|
const none = await probeEndpoint("https://api.x.com", "", route({}));
|
|
911
1047
|
assert(none === undefined, "no answer → undefined, the caller falls back to manual entry");
|
|
912
1048
|
const empty = await probeEndpoint("https://api.x.com/v1", "", route({ "/v1/models": { data: [] } }));
|
|
@@ -965,10 +1101,8 @@ if (isMain(import.meta.url)) {
|
|
|
965
1101
|
assert(detectLevel("deepseek-reasoner") === "auto", "reasoner means flexible thinking");
|
|
966
1102
|
assert(detectLevel("o1-mini") === "auto", "an o-generation id means flexible thinking");
|
|
967
1103
|
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");
|
|
1104
|
+
assert(detectLevel("ocz/mimo-v2.6-flash-free") === "auto", "a plain flash id starts at auto");
|
|
1105
|
+
assert(detectLevel("oc/big-pickle") === "auto", "an unrelated id starts at auto");
|
|
972
1106
|
|
|
973
1107
|
// Levels serialize to pi's wire shape and read back unchanged.
|
|
974
1108
|
const wireHigh = levelToWire("high") as { reasoning?: boolean; thinkingLevelMap?: Record<string, string | null> };
|
|
@@ -989,9 +1123,25 @@ if (isMain(import.meta.url)) {
|
|
|
989
1123
|
assert(savedProvider.compat !== undefined && savedProvider.name === "R", "withProviderModels keeps sibling fields");
|
|
990
1124
|
const savedModels = savedProvider.models as { id: string; reasoning?: boolean; thinkingLevelMap?: Record<string, string | null> }[];
|
|
991
1125
|
assert(savedModels[0]!.id === "m2" && savedModels[0]!.reasoning === true && savedModels[0]!.thinkingLevelMap?.high === "high", "withProviderModels serializes the level");
|
|
992
|
-
const
|
|
1126
|
+
const savedCompat = (savedModels[0] as { compat?: Record<string, unknown> }).compat;
|
|
1127
|
+
assert(savedCompat?.supportsLongCacheRetention === false && savedCompat?.sendSessionAffinityHeaders === true, "a save writes the compat flags a relay needs");
|
|
1128
|
+
|
|
1129
|
+
// A probe's limits land in the entry and survive a later edit that does not mention them.
|
|
1130
|
+
const withMeta = withProviderModels(rich, "r", [{ id: "m1", level: "auto", meta: { contextWindow: 1_000_000, maxTokens: 64_000 } }]);
|
|
1131
|
+
const metaModels = (withMeta.providers as Record<string, { models: { id: string; contextWindow?: number; maxTokens?: number }[] }>).r!.models;
|
|
1132
|
+
assert(metaModels[0]!.contextWindow === 1_000_000 && metaModels[0]!.maxTokens === 64_000, "a probed window and cap are written");
|
|
1133
|
+
const keptMeta = withProviderModels(withMeta, "r", [{ id: "m1", level: "high" }]);
|
|
1134
|
+
const keptModel = (keptMeta.providers as Record<string, { models: { contextWindow?: number; maxTokens?: number }[] }>).r!.models[0]!;
|
|
1135
|
+
assert(keptModel.contextWindow === 1_000_000 && keptModel.maxTokens === 64_000, "an edit that says nothing about limits keeps them");
|
|
1136
|
+
assert((loadProviderEntry(withMeta, "r")?.models[0]!.meta?.contextWindow ?? 0) === 1_000_000, "the limits load back as meta");
|
|
1137
|
+
const probedMap = withProviderModels(rich, "r", [{ id: "m1", level: "auto", map: { medium: "high", xhigh: null } }]);
|
|
1138
|
+
const probedModel = (probedMap.providers as Record<string, { models: { reasoning?: boolean; thinkingLevelMap?: Record<string, string | null> }[] }>).r!.models[0]!;
|
|
1139
|
+
assert(probedModel.reasoning === true && probedModel.thinkingLevelMap?.medium === "high", "a probed map wins over the level's own pin");
|
|
1140
|
+
const levelAfterProbe = withProviderModels(probedMap, "r", [{ id: "m1", level: "high" }]);
|
|
1141
|
+
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");
|
|
1142
|
+
const merged = mergeLevels({ name: "n", baseUrl: "b", api: "openai-completions", models: [{ id: "m1", level: "auto" }, { id: "m2", level: "off" }] }, ["m2", "x-thinking"]);
|
|
993
1143
|
assert(merged[0]!.id === "m2" && merged[0]!.level === "off", "a stored chat model stays chat");
|
|
994
|
-
assert(merged[1]!.level === "auto", "a new
|
|
1144
|
+
assert(merged[1]!.level === "auto", "a new id defaults to auto");
|
|
995
1145
|
const keptFlag = mergeLevels({ name: "n", baseUrl: "b", api: "openai-completions", models: [{ id: "m1", level: "low" }] }, ["m1"]);
|
|
996
1146
|
assert(keptFlag[0]!.level === "low", "a stored level survives a reselect");
|
|
997
1147
|
const entryLoaded = loadProviderEntry(rich, "r");
|
|
@@ -1001,6 +1151,10 @@ if (isMain(import.meta.url)) {
|
|
|
1001
1151
|
assert(roundTrip?.models[0]!.level === "xhigh", "a saved level loads back as itself");
|
|
1002
1152
|
assert(levelsSummary([{ id: "a" }, { id: "b", level: "high" }, { id: "c", level: "auto" }]) === "2 thinking (high, auto)", "the save notify names the registered levels");
|
|
1003
1153
|
assert(levelsSummary([{ id: "a" }]) === "0 thinking", "an all-chat save says so plainly");
|
|
1154
|
+
// The Thinking screen's bulk keys are Shift+letter: pi-tui lowercases a key id, so this
|
|
1155
|
+
// pins that they stay distinct from the plain letters navigation already uses.
|
|
1156
|
+
assert(matchesKey("A", "shift+a") && !matchesKey("a", "shift+a"), "Shift+A is its own key, not plain a");
|
|
1157
|
+
assert(matchesKey("R", "shift+r") && !matchesKey("r", "shift+r"), "Shift+R is its own key, not plain r");
|
|
1004
1158
|
|
|
1005
1159
|
// The stored key is read back from auth.json in an isolated agent dir (never the user's).
|
|
1006
1160
|
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-rc.1",
|
|
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/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 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/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",
|