march-cli 0.1.5 → 0.1.7
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/package.json +1 -1
- package/src/cli/commands/model-command.mjs +40 -9
- package/src/cli/commands/provider-command.mjs +4 -0
- package/src/cli/input/select-with-keyboard.mjs +23 -8
- package/src/cli/tui/tui-handlers.mjs +7 -6
- package/src/provider/presets.mjs +2 -2
- package/src/supergrok/provider.mjs +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
import { getProviderLabel } from "../../provider/presets.mjs";
|
|
2
2
|
import { globalConfigJsonPath, upsertModelSelection } from "../../config/config-json.mjs";
|
|
3
3
|
|
|
4
|
+
// Deduplicate models by id, preferring canonical providers.
|
|
5
|
+
// When the same model id appears under multiple providers (e.g. supergrok-oauth
|
|
6
|
+
// and xai-oauth), keep only the entry with the preferred provider.
|
|
7
|
+
const PREFERRED_PROVIDERS = ["supergrok-oauth"];
|
|
8
|
+
|
|
9
|
+
function dedupByModelId(scopedModels) {
|
|
10
|
+
const seen = new Map();
|
|
11
|
+
const result = [];
|
|
12
|
+
for (const entry of scopedModels) {
|
|
13
|
+
const { model } = entry;
|
|
14
|
+
const existing = seen.get(model.id);
|
|
15
|
+
if (!existing) {
|
|
16
|
+
seen.set(model.id, entry);
|
|
17
|
+
result.push(entry);
|
|
18
|
+
} else {
|
|
19
|
+
// Prefer canonical provider when duplicates exist
|
|
20
|
+
const existingPref = PREFERRED_PROVIDERS.indexOf(existing.model.provider);
|
|
21
|
+
const currentPref = PREFERRED_PROVIDERS.indexOf(model.provider);
|
|
22
|
+
if (currentPref !== -1 && (existingPref === -1 || currentPref < existingPref)) {
|
|
23
|
+
const idx = result.indexOf(existing);
|
|
24
|
+
result[idx] = entry;
|
|
25
|
+
seen.set(model.id, entry);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
|
|
4
32
|
export function parseModelCommand(input) {
|
|
5
33
|
if (input !== "/model" && !input.startsWith("/model ")) {
|
|
6
34
|
return { type: "none" };
|
|
@@ -21,9 +49,10 @@ export async function selectModelByIndex(index, { runner }) {
|
|
|
21
49
|
}
|
|
22
50
|
|
|
23
51
|
export function buildModelSelectItems({ current, scopedModels = [] }) {
|
|
24
|
-
|
|
52
|
+
const deduped = dedupByModelId(scopedModels);
|
|
53
|
+
return deduped.map(({ model }, index) => ({
|
|
25
54
|
value: String(index),
|
|
26
|
-
label: `${
|
|
55
|
+
label: `${model.name || model.id} (${getProviderLabel(model.provider)})`,
|
|
27
56
|
description: current && model.id === current.id && model.provider === current.provider ? "current" : model.provider,
|
|
28
57
|
model,
|
|
29
58
|
}));
|
|
@@ -34,19 +63,20 @@ export async function handleModelCommand(parsed, { runner, ui = null, configHome
|
|
|
34
63
|
const scopedModels = runner.getScopedModels?.() || [];
|
|
35
64
|
if (!ui?.selectList || scopedModels.length === 0) return "Use Ctrl+L to choose a model.";
|
|
36
65
|
const current = runner.getCurrentModel?.();
|
|
37
|
-
const
|
|
38
|
-
|
|
66
|
+
const items = buildModelSelectItems({ current, scopedModels });
|
|
67
|
+
const selectedIndex = Math.max(0, items.findIndex((item) =>
|
|
68
|
+
current && item.model.id === current.id && item.model.provider === current.provider
|
|
39
69
|
));
|
|
40
|
-
const
|
|
41
|
-
items
|
|
70
|
+
const selectedItem = await ui.selectList({
|
|
71
|
+
items,
|
|
42
72
|
selectedIndex,
|
|
43
73
|
width: 72,
|
|
44
74
|
suppressInitialConfirm: true,
|
|
45
75
|
searchable: true,
|
|
46
76
|
getSearchText: modelSelectSearchText,
|
|
47
77
|
});
|
|
48
|
-
if (!
|
|
49
|
-
const model = await runner.setModel(
|
|
78
|
+
if (!selectedItem) return "Model unchanged.";
|
|
79
|
+
const model = await runner.setModel(selectedItem.model);
|
|
50
80
|
persistModelSelection(model, { configHomeDir });
|
|
51
81
|
return `Model: ${model.name || model.id} (${model.provider})`;
|
|
52
82
|
}
|
|
@@ -85,8 +115,9 @@ export function formatModelsList({ current, scopedModels = [] }) {
|
|
|
85
115
|
}
|
|
86
116
|
|
|
87
117
|
function formatGroupedModels({ current, scopedModels }) {
|
|
118
|
+
const deduped = dedupByModelId(scopedModels);
|
|
88
119
|
const groups = new Map();
|
|
89
|
-
for (const item of
|
|
120
|
+
for (const item of deduped) {
|
|
90
121
|
const provider = item.model.provider;
|
|
91
122
|
if (!groups.has(provider)) groups.set(provider, []);
|
|
92
123
|
groups.get(provider).push(item);
|
|
@@ -11,8 +11,12 @@ export function parseProviderCommand(input) {
|
|
|
11
11
|
|
|
12
12
|
export function listProviders({ runner }) {
|
|
13
13
|
const scopedModels = runner.getScopedModels?.() || [];
|
|
14
|
+
const seen = new Set();
|
|
14
15
|
const providers = new Map();
|
|
15
16
|
for (const { model } of scopedModels) {
|
|
17
|
+
// Deduplicate: skip models that differ only by provider (e.g. supergrok-oauth vs xai-oauth)
|
|
18
|
+
if (seen.has(model.id)) continue;
|
|
19
|
+
seen.add(model.id);
|
|
16
20
|
if (!providers.has(model.provider)) {
|
|
17
21
|
providers.set(model.provider, {
|
|
18
22
|
provider: model.provider,
|
|
@@ -12,9 +12,19 @@ export async function selectWithKeyboard({ input = process.stdin, output = proce
|
|
|
12
12
|
|
|
13
13
|
let selected = 0;
|
|
14
14
|
let renderedLines = 0;
|
|
15
|
+
const maxViewport = Math.max(4, (output.rows || 24) - 2);
|
|
16
|
+
let viewportStart = 0;
|
|
17
|
+
|
|
18
|
+
const viewportEnd = () => Math.min(viewportStart + maxViewport, items.length);
|
|
19
|
+
|
|
20
|
+
const adjustViewport = () => {
|
|
21
|
+
if (selected < viewportStart) viewportStart = selected;
|
|
22
|
+
else if (selected >= viewportStart + maxViewport) viewportStart = selected - maxViewport + 1;
|
|
23
|
+
};
|
|
24
|
+
|
|
15
25
|
const render = () => {
|
|
16
26
|
if (renderedLines > 0) output.write(`\x1b[${renderedLines}F`);
|
|
17
|
-
const lines = formatSelectionList({ message, items, selected });
|
|
27
|
+
const lines = formatSelectionList({ message, items, selected, viewportStart, viewportEnd: viewportEnd(), done: false });
|
|
18
28
|
for (const line of lines) output.write(`\x1b[2K\r${line}\n`);
|
|
19
29
|
renderedLines = lines.length;
|
|
20
30
|
};
|
|
@@ -26,8 +36,8 @@ export async function selectWithKeyboard({ input = process.stdin, output = proce
|
|
|
26
36
|
if (finished) return;
|
|
27
37
|
if (key === "\u0003" || key === "\u001b") finish(null);
|
|
28
38
|
else if (key === "\r" || key === "\n") finish(items[selected].value);
|
|
29
|
-
else if (key === "\u001b[A") { selected = (selected - 1 + items.length) % items.length; render(); }
|
|
30
|
-
else if (key === "\u001b[B") { selected = (selected + 1) % items.length; render(); }
|
|
39
|
+
else if (key === "\u001b[A") { selected = (selected - 1 + items.length) % items.length; adjustViewport(); render(); }
|
|
40
|
+
else if (key === "\u001b[B") { selected = (selected + 1) % items.length; adjustViewport(); render(); }
|
|
31
41
|
}
|
|
32
42
|
};
|
|
33
43
|
const finish = (value) => {
|
|
@@ -36,25 +46,30 @@ export async function selectWithKeyboard({ input = process.stdin, output = proce
|
|
|
36
46
|
input.setRawMode(false);
|
|
37
47
|
input.pause();
|
|
38
48
|
if (renderedLines > 0) output.write(`\x1b[${renderedLines}F`);
|
|
39
|
-
|
|
40
|
-
|
|
49
|
+
// final render shows just the selected item
|
|
50
|
+
const lines = formatSelectionList({ message, items, selected, viewportStart: 0, viewportEnd: items.length, done: value != null });
|
|
51
|
+
output.write(`\x1b[2K\r${lines[0]}\n`);
|
|
52
|
+
output.write(`\x1b[2K\r ${items[selected].label}\n`);
|
|
41
53
|
resolve(value);
|
|
42
54
|
};
|
|
43
55
|
input.setRawMode(true);
|
|
44
56
|
input.resume();
|
|
45
57
|
input.on("data", onData);
|
|
58
|
+
adjustViewport();
|
|
46
59
|
render();
|
|
47
60
|
});
|
|
48
61
|
}
|
|
49
62
|
|
|
50
|
-
export function formatSelectionList({ message, items, selected, done = false }) {
|
|
63
|
+
export function formatSelectionList({ message, items, selected, viewportStart = 0, viewportEnd = items.length, done = false }) {
|
|
51
64
|
const hint = done ? "selected" : "↑/↓, Enter";
|
|
52
65
|
const lines = [`${message} (${hint})`];
|
|
53
|
-
|
|
66
|
+
if (viewportStart > 0) lines.push(" …");
|
|
67
|
+
for (let i = viewportStart; i < viewportEnd; i++) {
|
|
54
68
|
const marker = i === selected ? "›" : " ";
|
|
55
69
|
const label = `${marker} ${items[i].label}`;
|
|
56
70
|
lines.push(i === selected ? `\x1b[7m${label}\x1b[0m` : label);
|
|
57
71
|
}
|
|
72
|
+
if (viewportEnd < items.length) lines.push(" …");
|
|
58
73
|
return lines;
|
|
59
74
|
}
|
|
60
75
|
|
|
@@ -64,4 +79,4 @@ function readLine({ input = process.stdin, output = process.stdout, prompt }) {
|
|
|
64
79
|
rl.close();
|
|
65
80
|
resolve(answer);
|
|
66
81
|
}));
|
|
67
|
-
}
|
|
82
|
+
}
|
|
@@ -76,19 +76,20 @@ export function wireTuiHandlers({
|
|
|
76
76
|
const scopedModels = runner.getScopedModels?.() || [];
|
|
77
77
|
if (ui.selectList && scopedModels.length > 0) {
|
|
78
78
|
const current = runner.getCurrentModel?.();
|
|
79
|
-
const
|
|
80
|
-
|
|
79
|
+
const items = buildModelSelectItems({ current, scopedModels });
|
|
80
|
+
const selectedIndex = Math.max(0, items.findIndex((item) =>
|
|
81
|
+
current && item.model.id === current.id && item.model.provider === current.provider
|
|
81
82
|
));
|
|
82
|
-
const
|
|
83
|
-
items
|
|
83
|
+
const selectedItem = await ui.selectList({
|
|
84
|
+
items,
|
|
84
85
|
selectedIndex,
|
|
85
86
|
width: 72,
|
|
86
87
|
});
|
|
87
|
-
if (!
|
|
88
|
+
if (!selectedItem) {
|
|
88
89
|
ui.writeln(brightBlack(`● model: unchanged`));
|
|
89
90
|
return;
|
|
90
91
|
}
|
|
91
|
-
const model = await runner.setModel(
|
|
92
|
+
const model = await runner.setModel(selectedItem.model);
|
|
92
93
|
persistModelSelection(model, { configHomeDir });
|
|
93
94
|
const name = model.name || model.id;
|
|
94
95
|
ui.writeln(brightBlack(`● model: ${name} (${model.provider})`));
|
package/src/provider/presets.mjs
CHANGED
|
@@ -28,10 +28,10 @@ const PROVIDER_LABELS = {
|
|
|
28
28
|
openai: "OpenAI",
|
|
29
29
|
"openai-codex": "OpenAI Codex",
|
|
30
30
|
openrouter: "OpenRouter",
|
|
31
|
-
"supergrok-oauth": "SuperGrok
|
|
31
|
+
"supergrok-oauth": "SuperGrok",
|
|
32
32
|
"vercel-ai-gateway": "Vercel AI Gateway",
|
|
33
33
|
xai: "xAI",
|
|
34
|
-
"xai-oauth": "xAI OAuth
|
|
34
|
+
"xai-oauth": "xAI OAuth",
|
|
35
35
|
zai: "ZAI",
|
|
36
36
|
xiaomi: "Xiaomi MiMo",
|
|
37
37
|
"xiaomi-token-plan-cn": "Xiaomi MiMo Token Plan (China)",
|
|
@@ -14,7 +14,7 @@ export function registerSuperGrokProvider(modelRegistry) {
|
|
|
14
14
|
if (!modelRegistry?.registerProvider) return;
|
|
15
15
|
for (const providerId of [SUPERGROK_OAUTH_PROVIDER_ID, XAI_OAUTH_COMPAT_PROVIDER_ID]) {
|
|
16
16
|
modelRegistry.registerProvider(providerId, {
|
|
17
|
-
name: providerId === SUPERGROK_OAUTH_PROVIDER_ID ? "SuperGrok
|
|
17
|
+
name: providerId === SUPERGROK_OAUTH_PROVIDER_ID ? "SuperGrok" : "xAI OAuth",
|
|
18
18
|
baseUrl: XAI_BASE_URL,
|
|
19
19
|
api: "openai-responses",
|
|
20
20
|
oauth: { ...superGrokOAuthProvider, id: providerId },
|
|
@@ -33,4 +33,4 @@ export function registerSuperGrokProvider(modelRegistry) {
|
|
|
33
33
|
|
|
34
34
|
export function getDefaultSuperGrokModelId() {
|
|
35
35
|
return DEFAULT_SUPERGROK_MODEL;
|
|
36
|
-
}
|
|
36
|
+
}
|