pi-better-model-select 0.2.0 → 0.3.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 +55 -0
- package/README.md +17 -7
- package/docs/configuration.md +8 -2
- package/extensions/bms.ts +62 -50
- package/extensions/lib/defaults.ts +139 -51
- package/extensions/lib/effort-editor.ts +35 -20
- package/extensions/lib/flows.ts +126 -496
- package/extensions/lib/picker-dialog.ts +11 -19
- package/extensions/lib/picker.ts +89 -162
- package/extensions/lib/store.ts +3 -0
- package/extensions/lib/tui.ts +320 -0
- package/package.json +2 -1
|
@@ -1,29 +1,44 @@
|
|
|
1
1
|
import type { FlowCtx } from "./flows.ts";
|
|
2
|
+
import { editForm, tableSelect } from "./tui.ts";
|
|
2
3
|
import { capabilities, EFFORTS, isEffort, metadataPath, normalizeEfforts, patchSettings, readSettings, saveCapability, settingsPath, type Capability, type Effort } from "./defaults-store.ts";
|
|
3
4
|
|
|
4
5
|
export interface EffortDraft { capability: Capability; preferred?: Effort }
|
|
5
|
-
export
|
|
6
|
+
export function modelEffortDraft(ctx: FlowCtx, key: string, reasoning: boolean, reported?: Effort[]): EffortDraft {
|
|
6
7
|
const existing = capabilities(key, { reasoning });
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (reasoning) {
|
|
10
|
-
const mode = await ctx.ui.select(`Available efforts for ${key}\n${reported ? "Provider metadata" : existing.source}`, ["Use listed levels", "Configure manually"]);
|
|
11
|
-
if (!mode) return;
|
|
12
|
-
if (mode === "Configure manually") {
|
|
13
|
-
const raw = await ctx.ui.input(`Comma-separated Pi efforts: ${EFFORTS.join(", ")}`, levels.join(", "));
|
|
14
|
-
if (raw === undefined) return;
|
|
15
|
-
const parsed = normalizeEfforts(raw.split(",").map(value => value.trim()));
|
|
16
|
-
if (!parsed) { ctx.ui.notify("Choose one or more valid Pi effort levels. Nothing changed.", "warning"); return; }
|
|
17
|
-
levels = parsed;
|
|
18
|
-
source = "manual";
|
|
19
|
-
}
|
|
20
|
-
}
|
|
8
|
+
const levels = !reasoning ? ["off" as const] : reported ?? existing.levels;
|
|
9
|
+
const source: Capability["source"] = reported ? "provider" : existing.source === "Manual override" ? "manual" : "pi";
|
|
21
10
|
const previous = readSettings(settingsPath(ctx.cwd ?? process.cwd(), "user")).modelThinkingLevels?.[key];
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
11
|
+
return { capability: { levels: [...levels], source }, preferred: isEffort(previous) ? previous : undefined };
|
|
12
|
+
}
|
|
13
|
+
export async function editModelEfforts(ctx: FlowCtx, key: string, reasoning: boolean, reported?: Effort[], initial?: EffortDraft): Promise<EffortDraft | undefined> {
|
|
14
|
+
const draft = structuredClone(initial ?? modelEffortDraft(ctx, key, reasoning, reported));
|
|
15
|
+
if (!reasoning) draft.capability = { levels: ["off"], source: "pi" };
|
|
16
|
+
const saved = await editForm(ctx, {
|
|
17
|
+
title: `Efforts for ${key}`,
|
|
18
|
+
hint: "Apply returns a draft to the model form. Only the outer Save writes files.",
|
|
19
|
+
fields: [
|
|
20
|
+
{ key: "levels", label: "Available levels", value: draft.capability.levels.join(", "), description: `Source: ${draft.capability.source}. Provider support may be unverified.`, edit: async () => {
|
|
21
|
+
if (!reasoning) { ctx.ui.notify("Non-reasoning models only support off.", "info"); return; }
|
|
22
|
+
const raw = await ctx.ui.input(`Comma-separated Pi efforts: ${EFFORTS.join(", ")}`, draft.capability.levels.join(", "));
|
|
23
|
+
if (raw === undefined) return;
|
|
24
|
+
const levels = normalizeEfforts(raw.split(",").map(value => value.trim()));
|
|
25
|
+
if (!levels) { ctx.ui.notify("Choose one or more valid Pi effort levels.", "warning"); return; }
|
|
26
|
+
draft.capability = { levels, source: "manual" };
|
|
27
|
+
return levels.join(", ");
|
|
28
|
+
} },
|
|
29
|
+
{ key: "preferred", label: "Preferred effort", value: draft.preferred ?? "automatic", description: "Automatic removes the user per-model preference, not agent role defaults.", edit: async () => {
|
|
30
|
+
const selected = await tableSelect(ctx, { title: `Preferred effort for ${key}`, initialValue: draft.preferred ?? "automatic", rows: ["automatic", ...draft.capability.levels].map(value => ({ value, label: value })) });
|
|
31
|
+
if (selected === undefined) return;
|
|
32
|
+
draft.preferred = isEffort(selected) ? selected : undefined;
|
|
33
|
+
return selected;
|
|
34
|
+
} },
|
|
35
|
+
],
|
|
36
|
+
onSave: async () => {
|
|
37
|
+
if (draft.preferred && !draft.capability.levels.includes(draft.preferred)) { ctx.ui.notify("Preferred effort must be available. Choose another effort or automatic.", "warning"); return false; }
|
|
38
|
+
return true;
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
return saved ? draft : undefined;
|
|
27
42
|
}
|
|
28
43
|
/** Do not silently invalidate saved defaults when editing model capability hints. */
|
|
29
44
|
export function effortConflicts(data: Record<string, any>, key: string, levels: readonly Effort[], preferred?: Effort): string[] {
|