@bismawy/pi-arnative 0.9.0 → 0.9.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 +5 -0
- package/README.md +10 -2
- package/extensions/animations.ts +0 -0
- package/extensions/arnative.ts +0 -0
- package/extensions/autocompact.ts +0 -0
- package/extensions/footer.ts +0 -0
- package/extensions/model-heal.ts +0 -0
- package/extensions/section-headers.ts +0 -0
- package/extensions/timestamps.ts +0 -0
- package/extensions/todos.ts +0 -0
- package/extensions/tools.ts +0 -0
- package/extensions/ui-render-tweaks.ts +0 -0
- package/extensions/usage.ts +0 -0
- package/lib/box.ts +0 -0
- package/lib/check.ts +0 -0
- package/lib/compat.ts +0 -0
- package/lib/format.ts +0 -0
- package/lib/list-picker.ts +0 -0
- package/lib/model-heal.ts +0 -0
- package/lib/patch.ts +0 -0
- package/lib/preset-store.ts +0 -0
- package/lib/provider.ts +256 -43
- package/lib/shortcuts.ts +0 -0
- package/lib/spinner.ts +0 -0
- package/lib/status-widget.ts +0 -0
- package/lib/todos.ts +0 -0
- package/lib/usage-store.ts +0 -0
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.9.1] - 2026-11-02
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- **Providers → Edit changes the endpoint, the id or the key, one field per row.** Opening a provider now leads with `Edit`, and its menu shows what is stored beside each row: the base URL, the provider id, the key masked to its last four characters. A base URL is saved as typed (only a bare host gains its `http://`), so an edit lands what the user wrote instead of re-deriving `/v1` the way the add flow does, and the notify points at `Probe models` for the list that may have moved with it. A rename moves the models.json key and the auth.json credential together — the provider keeps its place in the list, a `name` that only repeated the old id follows it, the id is checked against the same `[A-Za-z0-9_-]` rule as create, and an id already taken is refused; if models.json cannot be written the credential is put back, so a failed rename never orphans the key. A new key lands in auth.json, the store pi reads before an inline `models.json` key, and the literal inline copy is dropped so the secret lives in one place, while an env-var or shell reference (`$VAR`, `!cmd`) is configuration and stays untouched; an emptied field keeps what is stored rather than blanking an endpoint or a credential. The three write paths share one row picker and one field patch with the action menu, which also gained the `Edit` row (`lib/provider.ts`, `withProviderFields`, `renameProvider`, `renameAuth`, `saveProviderKey`, `inlineKey`, `keyHint`; pinned in the module self-check).
|
|
9
|
+
|
|
5
10
|
## [0.9.0] - 2026-10-31
|
|
6
11
|
|
|
7
12
|
### Added
|
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ pi-arnative replaces pi’s default terminal chrome with a unified visual interf
|
|
|
20
20
|
- Working Spinners: 18 animated presets with live picker preview and optional `[g]` gradient sweep.
|
|
21
21
|
- Transcript Clock: Per-message timestamps with clean bubble backgrounds.
|
|
22
22
|
- Usage Dashboard: Real-time token counts and cost tracking across local sessions via `/usage`.
|
|
23
|
-
- Custom Providers: Interactive `/providers` wizard to probe endpoints, pick models, set thinking levels, and save OpenAI-, Anthropic-, Gemini-, or Ollama-compatible channels to `models.json` and `auth.json`.
|
|
23
|
+
- Custom Providers: Interactive `/providers` wizard to probe endpoints, pick models, set thinking levels, edit the base URL, provider id or API key, and save OpenAI-, Anthropic-, Gemini-, or Ollama-compatible channels to `models.json` and `auth.json`.
|
|
24
24
|
- Model Heal: Background sync (`/model-heal`) that fills missing compat flags, `/models` token limits, and accepted reasoning effort levels in `models.json`.
|
|
25
25
|
- Auto-compact: Automatic context compaction after a turn settles using smart window tiers or a fixed token budget.
|
|
26
26
|
|
|
@@ -47,9 +47,17 @@ Requires a [Nerd Font](https://www.nerdfonts.com/font-downloads). On a fresh ins
|
|
|
47
47
|
|
|
48
48
|
Local development:
|
|
49
49
|
```bash
|
|
50
|
-
npm run dev
|
|
50
|
+
npm run dev # run pi against this checkout, nothing installed
|
|
51
|
+
npm run overlay # copy extensions/ lib/ themes/ into the installed npm package
|
|
51
52
|
```
|
|
52
53
|
|
|
54
|
+
To see a change before publishing it: `npm run overlay`, then press `/reload` in pi — pi
|
|
55
|
+
re-evaluates extension TypeScript in the same process, so the reload loads the copied code with no
|
|
56
|
+
reinstall and no restart. The package stays an npm install; nothing points pi at this directory. A
|
|
57
|
+
module deleted here is pruned from the installed copy (a stale entry point would keep loading), and
|
|
58
|
+
`pi update --extensions` restores the published code once a higher version exists.
|
|
59
|
+
`npm run overlay -- --dry-run` lists what would move; `PI_CODING_AGENT_DIR` targets another agent dir.
|
|
60
|
+
|
|
53
61
|
## Shortcuts
|
|
54
62
|
|
|
55
63
|
| Key (Linux / Win) | Action |
|
package/extensions/animations.ts
CHANGED
|
File without changes
|
package/extensions/arnative.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/extensions/footer.ts
CHANGED
|
File without changes
|
package/extensions/model-heal.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/extensions/timestamps.ts
CHANGED
|
File without changes
|
package/extensions/todos.ts
CHANGED
|
File without changes
|
package/extensions/tools.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/extensions/usage.ts
CHANGED
|
File without changes
|
package/lib/box.ts
CHANGED
|
File without changes
|
package/lib/check.ts
CHANGED
|
File without changes
|
package/lib/compat.ts
CHANGED
|
File without changes
|
package/lib/format.ts
CHANGED
|
File without changes
|
package/lib/list-picker.ts
CHANGED
|
File without changes
|
package/lib/model-heal.ts
CHANGED
|
File without changes
|
package/lib/patch.ts
CHANGED
|
File without changes
|
package/lib/preset-store.ts
CHANGED
|
File without changes
|
package/lib/provider.ts
CHANGED
|
@@ -250,6 +250,43 @@ export function providerNames(config: unknown): string[] {
|
|
|
250
250
|
return isObj(config) && isObj(config.providers) ? Object.keys(config.providers) : [];
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
+
/** Pure patch of one provider's scalar fields (endpoint, id, display name, inline key).
|
|
254
|
+
* `undefined` drops the field; models, compat, headers and every sibling survive — the
|
|
255
|
+
* same contract as {@link withProviderModels}. */
|
|
256
|
+
export function withProviderFields(config: unknown, name: string, patch: Record<string, string | undefined>): Record<string, unknown> {
|
|
257
|
+
const root = isObj(config) ? { ...config } : {};
|
|
258
|
+
const providers = isObj(root.providers) ? { ...root.providers } : {};
|
|
259
|
+
const next: Record<string, unknown> = { ...(isObj(providers[name]) ? providers[name] : {}), ...patch };
|
|
260
|
+
for (const [key, value] of Object.entries(next)) if (value === undefined) delete next[key];
|
|
261
|
+
providers[name] = next;
|
|
262
|
+
root.providers = providers;
|
|
263
|
+
return root;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** Pure rename: the provider keeps its position in the list, and a `name` that only
|
|
267
|
+
* repeated the old id follows it (a hand-written display name stays as written). */
|
|
268
|
+
export function renameProvider(config: unknown, from: string, to: string): Record<string, unknown> {
|
|
269
|
+
const root = isObj(config) ? { ...config } : {};
|
|
270
|
+
const providers = isObj(root.providers) ? { ...root.providers } : {};
|
|
271
|
+
if (!(from in providers)) return root;
|
|
272
|
+
root.providers = Object.fromEntries(
|
|
273
|
+
Object.entries(providers).map(([key, value]): [string, unknown] => {
|
|
274
|
+
if (key !== from) return [key, value];
|
|
275
|
+
const entry: Record<string, unknown> = isObj(value) ? { ...value } : {};
|
|
276
|
+
if (entry.name === from) entry.name = to;
|
|
277
|
+
return [to, entry];
|
|
278
|
+
}),
|
|
279
|
+
);
|
|
280
|
+
return root;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** The credential follows its provider in auth.json; a provider with no entry stays without one. */
|
|
284
|
+
export function renameAuth(auth: unknown, from: string, to: string): Record<string, unknown> {
|
|
285
|
+
const root = isObj(auth) ? { ...auth } : {};
|
|
286
|
+
if (!(from in root)) return root;
|
|
287
|
+
return Object.fromEntries(Object.entries(root).map(([key, value]): [string, unknown] => [key === from ? to : key, value]));
|
|
288
|
+
}
|
|
289
|
+
|
|
253
290
|
export interface ProviderSummary {
|
|
254
291
|
name: string;
|
|
255
292
|
api?: string;
|
|
@@ -395,6 +432,34 @@ export function saveProvider(name: string, entry: ProviderEntry, key: string | u
|
|
|
395
432
|
if (key) writeJson(authPath(), withAuth(readJson(authPath()), name, key));
|
|
396
433
|
}
|
|
397
434
|
|
|
435
|
+
/** Writes one provider's key: a real key lands in auth.json (the file /login writes, and the
|
|
436
|
+
* credential pi prefers over an inline models.json apiKey), `undefined` removes it. A
|
|
437
|
+
* literal inline key is dropped from models.json so the secret lives in one place; an
|
|
438
|
+
* env-var or shell reference is configuration, not a secret, and stays put. */
|
|
439
|
+
export function saveProviderKey(name: string, key: string | undefined): void {
|
|
440
|
+
const auth = readJson(authPath());
|
|
441
|
+
// Nothing stored and nothing to store: leave a missing auth.json missing.
|
|
442
|
+
if (key || (isObj(auth) && name in auth)) writeJson(authPath(), key ? withAuth(auth, name, key) : withoutAuth(auth, name));
|
|
443
|
+
const config = readJson(modelsPath());
|
|
444
|
+
const entry = isObj(config) && isObj(config.providers) && isObj(config.providers[name]) ? (config.providers[name] as Record<string, unknown>) : undefined;
|
|
445
|
+
if (!entry || typeof entry.apiKey !== "string" || /^[$!]/.test(entry.apiKey)) return;
|
|
446
|
+
writeJson(modelsPath(), withProviderFields(config, name, { apiKey: undefined }));
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/** `dummy`/`ollama` are placeholders a keyless entry carries so pi can list its models;
|
|
450
|
+
* `$VAR`, `${VAR}` and `!command` are references, not secrets. Neither is a stored key. */
|
|
451
|
+
const PLACEHOLDER_KEYS = new Set(["dummy", "ollama"]);
|
|
452
|
+
export function inlineKey(entry: ProviderEntry): string | undefined {
|
|
453
|
+
const value = entry.apiKey;
|
|
454
|
+
if (!value || PLACEHOLDER_KEYS.has(value) || /^[$!]/.test(value)) return undefined;
|
|
455
|
+
return value;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/** One secret as it may be shown on screen: its last four characters, never the whole key. */
|
|
459
|
+
export function keyHint(key: string): string {
|
|
460
|
+
return key.length > 8 ? `••••${key.slice(-4)}` : "••••";
|
|
461
|
+
}
|
|
462
|
+
|
|
398
463
|
export function deleteProviderNamed(name: string): boolean {
|
|
399
464
|
const config = readJson(modelsPath());
|
|
400
465
|
if (!providerNames(config).includes(name)) return false;
|
|
@@ -685,10 +750,8 @@ const selectModelsFlow = async (ctx: ExtensionCommandContext, name: string, entr
|
|
|
685
750
|
};
|
|
686
751
|
|
|
687
752
|
const probeModelsFlow = async (ctx: ExtensionCommandContext, name: string, entry: ProviderEntry): Promise<void> => {
|
|
688
|
-
// The real key lives in auth.json;
|
|
689
|
-
const
|
|
690
|
-
const inline = entry.apiKey && entry.apiKey !== "dummy" && entry.apiKey !== "ollama" ? entry.apiKey : "";
|
|
691
|
-
const key = stored ?? inline;
|
|
753
|
+
// The real key lives in auth.json; a placeholder never authenticates a probe.
|
|
754
|
+
const key = readAuthKey(name) ?? inlineKey(entry) ?? "";
|
|
692
755
|
probingStatus(ctx, "probing endpoint…");
|
|
693
756
|
let result: ProbeResult | undefined;
|
|
694
757
|
try {
|
|
@@ -755,13 +818,12 @@ const thinkingFlow = async (ctx: ExtensionCommandContext, name: string, entry: P
|
|
|
755
818
|
busy = label;
|
|
756
819
|
progress = "starting…";
|
|
757
820
|
refresh();
|
|
758
|
-
const inline = entry.apiKey && entry.apiKey !== "dummy" && entry.apiKey !== "ollama" ? entry.apiKey : undefined;
|
|
759
821
|
try {
|
|
760
822
|
const supported = await probeEffort(
|
|
761
823
|
{ provider: name, id: label, api: entry.api, baseUrl: entry.baseUrl, reasoning: true, compat },
|
|
762
824
|
{
|
|
763
825
|
baseUrl: entry.baseUrl,
|
|
764
|
-
key: readAuthKey(name) ??
|
|
826
|
+
key: readAuthKey(name) ?? inlineKey(entry),
|
|
765
827
|
onLevel: (level, _accepted, index) => {
|
|
766
828
|
progress = `${level} · ${index + 1}/7`;
|
|
767
829
|
refresh();
|
|
@@ -872,66 +934,172 @@ const thinkingFlow = async (ctx: ExtensionCommandContext, name: string, entry: P
|
|
|
872
934
|
if (warn) ctx.ui.notify(`[arnative] ${warn}`, "info");
|
|
873
935
|
};
|
|
874
936
|
|
|
937
|
+
const ACTION_EDIT = "Edit";
|
|
875
938
|
const ACTION_SELECT = "Select models";
|
|
876
939
|
const ACTION_PROBE = "Probe models";
|
|
877
940
|
const ACTION_THINKING = "Thinking";
|
|
878
941
|
const ACTION_DELETE = "Delete";
|
|
879
942
|
|
|
880
|
-
const
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
943
|
+
const EDIT_BASE = "Base URL";
|
|
944
|
+
const EDIT_NAME = "Provider name";
|
|
945
|
+
const EDIT_KEY = "API key";
|
|
946
|
+
|
|
947
|
+
const ACTIONS_DESCRIPTION = "Edit the endpoint, key or models, re-probe, or delete.";
|
|
948
|
+
|
|
949
|
+
/** One menu row picker shared by the action and edit menus: Enter returns the row's label,
|
|
950
|
+
* `←` and Esc return undefined (the caller decides what that leaves for). */
|
|
951
|
+
const chooseRow = async (ctx: ExtensionCommandContext, title: string, description: string, rows: ListRow[]): Promise<string | undefined> => {
|
|
952
|
+
if (ctx.mode !== "tui") {
|
|
953
|
+
const picked = await ctx.ui.select(title, rows.map(rowText));
|
|
954
|
+
if (picked === undefined) return undefined;
|
|
955
|
+
// Labels are distinct prefixes of their own flat row, so `startsWith` is unambiguous.
|
|
956
|
+
return rows.find((r) => picked.startsWith(r.label))?.label;
|
|
957
|
+
}
|
|
958
|
+
const chosen = await ctx.ui.custom<string | null>((tui, theme, _kb, done) => {
|
|
959
|
+
const picker = new ListPicker(
|
|
960
|
+
theme,
|
|
961
|
+
rows,
|
|
962
|
+
undefined,
|
|
963
|
+
{
|
|
964
|
+
preview: () => {},
|
|
965
|
+
revert: () => {},
|
|
966
|
+
done: () => done(rows[picker.index]?.label),
|
|
967
|
+
cancel: () => done(null),
|
|
968
|
+
// `←` leaves this menu for its parent; Esc closes the screen it is on.
|
|
969
|
+
back: () => done(null),
|
|
970
|
+
requestRender: () => tui.requestRender(),
|
|
971
|
+
},
|
|
972
|
+
{ title: screenTitle(title), description, legend: LIST_LEGEND_MOVE },
|
|
973
|
+
false,
|
|
974
|
+
ctx.thinkingLevel,
|
|
975
|
+
);
|
|
976
|
+
return picker;
|
|
977
|
+
});
|
|
978
|
+
return chosen ?? undefined;
|
|
979
|
+
};
|
|
980
|
+
|
|
981
|
+
/** One field written through to models.json, with the notify that says what landed. */
|
|
982
|
+
const saveField = (ctx: ExtensionCommandContext, name: string, patch: Record<string, string | undefined>, note: string): void => {
|
|
983
|
+
try {
|
|
984
|
+
writeJson(modelsPath(), withProviderFields(readJson(modelsPath()), name, patch));
|
|
985
|
+
} catch (error) {
|
|
986
|
+
ctx.ui.notify(`[arnative] Not saved: ${error instanceof Error ? error.message : "config file unreadable"}.`, "error");
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
989
|
+
ctx.ui.notify(`[arnative] ${note}`, "info");
|
|
990
|
+
};
|
|
991
|
+
|
|
992
|
+
/** Base URL: stored exactly as typed (normalized only for a bare host). The flavor's own
|
|
993
|
+
* `/v1` rewriting stays in the add flow — an edit must land what the user wrote. */
|
|
994
|
+
const editBaseUrlFlow = async (ctx: ExtensionCommandContext, name: string, entry: ProviderEntry): Promise<void> => {
|
|
995
|
+
const value = await readInput(ctx, "Edit", "Base URL — the endpoint pi calls (include /v1 for OpenAI-style)", "https://api.example.com/v1", entry.baseUrl);
|
|
996
|
+
// Esc cancels; an emptied field keeps what is stored rather than blanking the endpoint.
|
|
997
|
+
if (!value) return;
|
|
998
|
+
const baseUrl = normalizeBase(value);
|
|
999
|
+
if (baseUrl === entry.baseUrl) return;
|
|
1000
|
+
saveField(ctx, name, { baseUrl }, `${name}: base URL is now ${baseUrl}. Run Probe models to re-read its list.`);
|
|
1001
|
+
};
|
|
1002
|
+
|
|
1003
|
+
/** Provider id: the models.json key and the auth.json credential move together, so the key
|
|
1004
|
+
* never ends up under an id no provider answers to. Returns the id to keep using. */
|
|
1005
|
+
const editNameFlow = async (ctx: ExtensionCommandContext, name: string): Promise<string> => {
|
|
1006
|
+
const value = await readInput(ctx, "Edit", "provider id (letters, digits, - and _)", name, name);
|
|
1007
|
+
if (!value || value === name) return name;
|
|
1008
|
+
if (!/^[A-Za-z0-9_-]+$/.test(value)) {
|
|
1009
|
+
ctx.ui.notify(`[arnative] "${value}" is not a usable provider id (letters, digits, - and _ only).`, "warning");
|
|
1010
|
+
return name;
|
|
1011
|
+
}
|
|
1012
|
+
if (providerNames(loadModelsConfig()).includes(value)) {
|
|
1013
|
+
ctx.ui.notify(`[arnative] "${value}" is already a provider — pick another id.`, "warning");
|
|
1014
|
+
return name;
|
|
1015
|
+
}
|
|
1016
|
+
const auth = readJson(authPath());
|
|
1017
|
+
const holdsKey = isObj(auth) && isObj(auth[name]);
|
|
1018
|
+
try {
|
|
1019
|
+
if (holdsKey) writeJson(authPath(), renameAuth(auth, name, value));
|
|
1020
|
+
try {
|
|
1021
|
+
writeJson(modelsPath(), renameProvider(readJson(modelsPath()), name, value));
|
|
1022
|
+
} catch (error) {
|
|
1023
|
+
// Put the credential back where the old id still looks for it.
|
|
1024
|
+
if (holdsKey) writeJson(authPath(), auth);
|
|
1025
|
+
throw error;
|
|
1026
|
+
}
|
|
1027
|
+
} catch (error) {
|
|
1028
|
+
ctx.ui.notify(`[arnative] Not renamed: ${error instanceof Error ? error.message : "config file unreadable"}.`, "error");
|
|
1029
|
+
return name;
|
|
1030
|
+
}
|
|
1031
|
+
ctx.ui.notify(`[arnative] Renamed ${name} → ${value}. Open /model to refresh.`, "info");
|
|
1032
|
+
return value;
|
|
1033
|
+
};
|
|
1034
|
+
|
|
1035
|
+
/** API key: written to auth.json (the store pi prefers over an inline models.json key), so
|
|
1036
|
+
* a literal key leaves models.json instead of being stored twice. */
|
|
1037
|
+
const editKeyFlow = async (ctx: ExtensionCommandContext, name: string, entry: ProviderEntry): Promise<void> => {
|
|
1038
|
+
const stored = readAuthKey(name) ?? inlineKey(entry);
|
|
1039
|
+
const field = stored ? `API key — stored ${keyHint(stored)}, empty keeps it` : "API key — empty for a keyless endpoint";
|
|
1040
|
+
const value = await readInput(ctx, "Edit", field, "sk-…");
|
|
1041
|
+
if (!value) return;
|
|
1042
|
+
try {
|
|
1043
|
+
saveProviderKey(name, value);
|
|
1044
|
+
} catch (error) {
|
|
1045
|
+
ctx.ui.notify(`[arnative] Not saved: ${error instanceof Error ? error.message : "config file unreadable"}.`, "error");
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
1048
|
+
ctx.ui.notify(`[arnative] ${name}: API key replaced (${keyHint(value)}). Open /model to refresh.`, "info");
|
|
1049
|
+
};
|
|
1050
|
+
|
|
1051
|
+
/** The Edit menu: one field per row, each write immediate. Returns the provider id to keep
|
|
1052
|
+
* using — a rename changes it, and every later action follows the new one. */
|
|
1053
|
+
const editFlow = async (ctx: ExtensionCommandContext, name: string): Promise<string> => {
|
|
1054
|
+
let id = name;
|
|
1055
|
+
for (;;) {
|
|
1056
|
+
const entry = loadProviderEntry(loadModelsConfig(), id);
|
|
1057
|
+
if (!entry) {
|
|
1058
|
+
ctx.ui.notify(`[arnative] ${id} is gone — the list will refresh.`, "warning");
|
|
1059
|
+
return id;
|
|
1060
|
+
}
|
|
1061
|
+
const key = readAuthKey(id) ?? inlineKey(entry);
|
|
1062
|
+
const rows: ListRow[] = [
|
|
1063
|
+
{ label: EDIT_BASE, note: entry.baseUrl || "not set" },
|
|
1064
|
+
{ label: EDIT_NAME, note: id },
|
|
1065
|
+
{ label: EDIT_KEY, note: key ? keyHint(key) : "not set" },
|
|
1066
|
+
];
|
|
1067
|
+
const action = await chooseRow(ctx, `Edit · ${id}`, "one field per row — each saves on Enter", rows);
|
|
1068
|
+
if (!action) return id;
|
|
1069
|
+
if (action === EDIT_BASE) await editBaseUrlFlow(ctx, id, entry);
|
|
1070
|
+
else if (action === EDIT_NAME) id = await editNameFlow(ctx, id);
|
|
1071
|
+
else await editKeyFlow(ctx, id, entry);
|
|
1072
|
+
}
|
|
884
1073
|
};
|
|
885
1074
|
|
|
886
1075
|
/** Enter on an existing provider: an action menu instead of a straight delete. Every
|
|
887
|
-
* action writes through to models.json (and auth.json for delete) before
|
|
1076
|
+
* action writes through to models.json (and auth.json for edit, rename and delete) before
|
|
1077
|
+
* returning. */
|
|
888
1078
|
const providerActionFlow = async (ctx: ExtensionCommandContext, name: string): Promise<void> => {
|
|
1079
|
+
let id = name;
|
|
889
1080
|
for (;;) {
|
|
890
|
-
const entry = loadProviderEntry(loadModelsConfig(),
|
|
1081
|
+
const entry = loadProviderEntry(loadModelsConfig(), id);
|
|
891
1082
|
if (!entry) {
|
|
892
|
-
ctx.ui.notify(`[arnative] ${
|
|
1083
|
+
ctx.ui.notify(`[arnative] ${id} is gone — the list will refresh.`, "warning");
|
|
893
1084
|
return;
|
|
894
1085
|
}
|
|
895
1086
|
const rows: ListRow[] = [
|
|
1087
|
+
{ label: ACTION_EDIT, note: "base URL, provider name, API key" },
|
|
896
1088
|
{ label: ACTION_SELECT, note: "tick the models this provider exposes" },
|
|
897
1089
|
{ label: ACTION_PROBE, note: "re-read the model list from the endpoint" },
|
|
898
1090
|
{ label: ACTION_THINKING, note: "toggle reasoning per model (auto-detected)" },
|
|
899
1091
|
{ label: ACTION_DELETE, note: "remove the provider and its stored key" },
|
|
900
1092
|
];
|
|
901
|
-
|
|
902
|
-
if (ctx.mode === "tui") {
|
|
903
|
-
action = await ctx.ui.custom<string | null>((tui, theme, _kb, done) => {
|
|
904
|
-
const picker = new ListPicker(
|
|
905
|
-
theme,
|
|
906
|
-
rows,
|
|
907
|
-
undefined,
|
|
908
|
-
{
|
|
909
|
-
preview: () => {},
|
|
910
|
-
revert: () => {},
|
|
911
|
-
done: () => done(rows[picker.index]?.label),
|
|
912
|
-
cancel: () => done(null),
|
|
913
|
-
// `←` leaves the actions for the provider list; Esc closes the whole menu.
|
|
914
|
-
back: () => done(null),
|
|
915
|
-
requestRender: () => tui.requestRender(),
|
|
916
|
-
},
|
|
917
|
-
{ ...ACTIONS_TEXT, title: screenTitle(`Provider · ${name}`) },
|
|
918
|
-
false,
|
|
919
|
-
ctx.thinkingLevel,
|
|
920
|
-
);
|
|
921
|
-
return picker;
|
|
922
|
-
});
|
|
923
|
-
} else {
|
|
924
|
-
const picked = await ctx.ui.select(`${name} — edit or delete`, rows.map(rowText));
|
|
925
|
-
action = picked === undefined ? undefined : rows.find((r) => picked.startsWith(r.label))?.label;
|
|
926
|
-
}
|
|
1093
|
+
const action = await chooseRow(ctx, `Provider · ${id}`, ACTIONS_DESCRIPTION, rows);
|
|
927
1094
|
if (!action) return;
|
|
928
1095
|
if (action === ACTION_DELETE) {
|
|
929
|
-
await deleteProviderFlow(ctx,
|
|
1096
|
+
await deleteProviderFlow(ctx, id);
|
|
930
1097
|
return;
|
|
931
1098
|
}
|
|
932
|
-
if (action ===
|
|
933
|
-
else if (action ===
|
|
934
|
-
else if (action ===
|
|
1099
|
+
if (action === ACTION_EDIT) id = await editFlow(ctx, id);
|
|
1100
|
+
else if (action === ACTION_SELECT) await selectModelsFlow(ctx, id, entry);
|
|
1101
|
+
else if (action === ACTION_PROBE) await probeModelsFlow(ctx, id, entry);
|
|
1102
|
+
else if (action === ACTION_THINKING) await thinkingFlow(ctx, id, entry);
|
|
935
1103
|
}
|
|
936
1104
|
};
|
|
937
1105
|
|
|
@@ -1067,6 +1235,34 @@ if (isMain(import.meta.url)) {
|
|
|
1067
1235
|
assert((auth.b as { key: string }).key === "2" && auth.a !== undefined, "withAuth adds one credential");
|
|
1068
1236
|
assert(withoutAuth(auth, "a").a === undefined, "withoutAuth removes one");
|
|
1069
1237
|
|
|
1238
|
+
// Secrets: the hint never shows more than the tail, and only a literal inline key counts.
|
|
1239
|
+
assert(keyHint("sk-abcdefgh1234") === "••••1234", "the hint keeps the last four characters");
|
|
1240
|
+
assert(keyHint("short") === "••••", "a short secret shows nothing at all");
|
|
1241
|
+
assert(!keyHint("sk-abcdefgh1234").includes("abcdefgh"), "the body of the key never reaches the screen");
|
|
1242
|
+
assert(inlineKey({ baseUrl: "b", api: "openai-completions", apiKey: "dummy", models: [] }) === undefined, "a placeholder is not a key");
|
|
1243
|
+
assert(inlineKey({ baseUrl: "b", api: "openai-completions", apiKey: "ollama", models: [] }) === undefined, "the keyless placeholder is not a key");
|
|
1244
|
+
assert(inlineKey({ baseUrl: "b", api: "openai-completions", apiKey: "$OPENAI_KEY", models: [] }) === undefined, "an env reference is not a key");
|
|
1245
|
+
assert(inlineKey({ baseUrl: "b", api: "openai-completions", apiKey: "sk-1", models: [] }) === "sk-1", "a literal key is read back");
|
|
1246
|
+
|
|
1247
|
+
// The Edit screen's patches: one field lands, the models and every sibling survive, and
|
|
1248
|
+
// a rename keeps the provider's place in the list with its credential following it.
|
|
1249
|
+
const fieldEntry = { providers: { r: { name: "r", baseUrl: "old", api: "openai-completions", apiKey: "sk-1", compat: { x: 1 }, models: [{ id: "m1" }] } } };
|
|
1250
|
+
const patched = withProviderFields(fieldEntry, "r", { baseUrl: "https://new.example/v1" });
|
|
1251
|
+
const patchedEntry = (patched.providers as Record<string, Record<string, unknown>>).r!;
|
|
1252
|
+
assert(patchedEntry.baseUrl === "https://new.example/v1" && patchedEntry.apiKey === "sk-1", "withProviderFields rewrites the named field only");
|
|
1253
|
+
assert((patchedEntry.models as unknown[]).length === 1 && patchedEntry.compat !== undefined, "an endpoint edit keeps models and compat");
|
|
1254
|
+
assert(((fieldEntry.providers as Record<string, Record<string, unknown>>).r!).baseUrl === "old", "withProviderFields does not mutate its input");
|
|
1255
|
+
assert((withProviderFields(fieldEntry, "r", { apiKey: undefined }).providers as Record<string, Record<string, unknown>>).r!.apiKey === undefined, "an undefined patch drops the field");
|
|
1256
|
+
const renamed = renameProvider({ providers: { a: { name: "a", models: [{ id: "m" }] }, b: { name: "" } } }, "a", "c");
|
|
1257
|
+
assert(providerNames(renamed).join() === "c,b", "renameProvider keeps the position and changes the id");
|
|
1258
|
+
assert((renamed.providers as Record<string, { name?: string; models?: unknown[] }>).c!.name === "c", "a name that repeated the old id follows it");
|
|
1259
|
+
assert(((renamed.providers as Record<string, { models?: unknown[] }>).c!.models ?? []).length === 1, "a rename keeps the models");
|
|
1260
|
+
assert((renameProvider({ providers: { a: { name: "Keep" } } }, "a", "c").providers as Record<string, { name?: string }>).c!.name === "Keep", "a hand-written display name is untouched");
|
|
1261
|
+
assert((renameProvider({ providers: { a: {} } }, "missing", "c").providers as Record<string, unknown>).a !== undefined, "renaming a missing provider writes nothing");
|
|
1262
|
+
const movedAuth = renameAuth({ a: { type: "api_key", key: "1" }, b: { type: "api_key", key: "2" } }, "a", "c");
|
|
1263
|
+
assert((movedAuth.c as { key: string }).key === "1" && movedAuth.a === undefined && (movedAuth.b as { key: string }).key === "2", "renameAuth moves one credential");
|
|
1264
|
+
assert(renameAuth({}, "a", "c").a === undefined, "an absent credential is not invented");
|
|
1265
|
+
|
|
1070
1266
|
// The model picker screen: checks toggle, `a` cycles, Esc leaves, Enter returns the ids.
|
|
1071
1267
|
const fakeTheme = { fg: (_c: string, t: string) => t, bold: (t: string) => t };
|
|
1072
1268
|
const renderModels = (checked: Set<string>, rows: ListRow[]) =>
|
|
@@ -1184,6 +1380,23 @@ if (isMain(import.meta.url)) {
|
|
|
1184
1380
|
assert(readAuthKey("t2") === undefined, "the interrupted save never reached auth.json");
|
|
1185
1381
|
rmSync(blockedTmp, { recursive: true, force: true });
|
|
1186
1382
|
assert(readdirSync(tmp).every((f) => !f.endsWith(".tmp")), "a completed save leaves no temp files behind");
|
|
1383
|
+
// Edit writes: the key moves to auth.json and leaves models.json, so the secret lives in
|
|
1384
|
+
// one place; an env reference is configuration and stays put.
|
|
1385
|
+
saveProvider("t3", { name: "t3", baseUrl: "https://z.com/v1", api: "openai-completions", apiKey: "sk-inline", models: [{ id: "m" }] }, undefined);
|
|
1386
|
+
saveProviderKey("t3", "sk-edited");
|
|
1387
|
+
assert(readAuthKey("t3") === "sk-edited", "an edited key lands in auth.json");
|
|
1388
|
+
const t3 = (loadModelsConfig().providers as Record<string, Record<string, unknown>>).t3!;
|
|
1389
|
+
assert(t3.apiKey === undefined, "the inline copy is dropped, so the secret lives in one place");
|
|
1390
|
+
assert(t3.baseUrl === "https://z.com/v1" && (t3.models as unknown[]).length === 1, "the key edit leaves the rest of the entry alone");
|
|
1391
|
+
saveProviderKey("t3", undefined);
|
|
1392
|
+
assert(readAuthKey("t3") === undefined, "an empty key removes the credential");
|
|
1393
|
+
saveProvider("t4", { name: "t4", baseUrl: "https://w.com/v1", api: "openai-completions", apiKey: "$W_KEY", models: [] }, undefined);
|
|
1394
|
+
saveProviderKey("t4", "sk-y");
|
|
1395
|
+
assert((loadModelsConfig().providers as Record<string, Record<string, unknown>>).t4!.apiKey === "$W_KEY", "an env reference survives an edit");
|
|
1396
|
+
saveProvider("t5", { name: "t5", baseUrl: "https://v.com/v1", api: "openai-completions", models: [{ id: "m" }] }, "sk-t5");
|
|
1397
|
+
saveModelsConfig(renameProvider(loadModelsConfig(), "t5", "t6"));
|
|
1398
|
+
assert(providerNames(loadModelsConfig()).includes("t6") && !providerNames(loadModelsConfig()).includes("t5"), "a rename reaches models.json");
|
|
1399
|
+
assert(loadProviderEntry(loadModelsConfig(), "t6")?.models[0]!.id === "m", "the renamed provider keeps its models");
|
|
1187
1400
|
delete process.env.PI_CODING_AGENT_DIR;
|
|
1188
1401
|
rmSync(tmp, { recursive: true, force: true });
|
|
1189
1402
|
|
package/lib/shortcuts.ts
CHANGED
|
File without changes
|
package/lib/spinner.ts
CHANGED
|
File without changes
|
package/lib/status-widget.ts
CHANGED
|
File without changes
|
package/lib/todos.ts
CHANGED
|
File without changes
|
package/lib/usage-store.ts
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bismawy/pi-arnative",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.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",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
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/todos.ts --extension ./extensions/arnative.ts",
|
|
44
44
|
"test": "node lib/box.ts && node lib/patch.ts && node lib/ansi.ts && node lib/color.ts && node lib/shortcuts.ts && node lib/status-widget.ts && node lib/preset-store.ts && node lib/spinner.ts && node lib/todos.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/todos.ts && node extensions/arnative.ts && node scripts/reporter.mjs --self-check && node --test --test-reporter=./scripts/reporter.mjs",
|
|
45
45
|
"preview": "node scripts/preview.mjs",
|
|
46
|
+
"overlay": "node scripts/overlay.mjs",
|
|
46
47
|
"themes": "node themes/gen-themes.mjs",
|
|
47
48
|
"release:check": "node scripts/release-check.mjs pre-tag",
|
|
48
49
|
"prepublishOnly": "npm test && node scripts/release-check.mjs pre-publish"
|