Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 13 additions & 122 deletions bin/lib/onboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const {
validateLocalProvider,
} = require("./local-inference");
const {
CLOUD_MODEL_OPTIONS,
DEFAULT_CLOUD_MODEL,
getProviderSelectionConfig,
parseGatewayInference,
Expand Down Expand Up @@ -64,6 +63,7 @@ const urlUtils = require("../../dist/lib/url-utils");
const buildContext = require("../../dist/lib/build-context");
const dashboard = require("../../dist/lib/dashboard");
const httpProbe = require("../../dist/lib/http-probe");
const modelPrompts = require("../../dist/lib/model-prompts");
const providerModels = require("../../dist/lib/provider-models");
const validationRecovery = require("../../dist/lib/validation-recovery");
const webSearch = require("../../dist/lib/web-search");
Expand Down Expand Up @@ -172,19 +172,6 @@ const REMOTE_PROVIDER_CONFIG = {
},
};

const REMOTE_MODEL_OPTIONS = {
openai: ["gpt-5.4", "gpt-5.4-mini", "gpt-5.4-nano", "gpt-5.4-pro-2026-03-05"],
anthropic: ["claude-sonnet-4-6", "claude-haiku-4-5", "claude-opus-4-6"],
gemini: [
"gemini-3.1-pro-preview",
"gemini-3.1-flash-lite-preview",
"gemini-3-flash-preview",
"gemini-2.5-pro",
"gemini-2.5-flash",
"gemini-2.5-flash-lite",
],
};

// Non-interactive mode: set by --non-interactive flag or env var.
// When active, all prompts use env var overrides or sensible defaults.
let NON_INTERACTIVE = false;
Expand Down Expand Up @@ -1375,120 +1362,14 @@ async function validateCustomAnthropicSelection(
return { ok: false, retry };
}

const { validateNvidiaEndpointModel, validateAnthropicModel, validateOpenAiLikeModel } =
providerModels;
const { promptManualModelId, promptCloudModel, promptRemoteModel, promptInputModel } = modelPrompts;
const { validateAnthropicModel, validateOpenAiLikeModel } = providerModels;
Comment thread
coderabbitai[bot] marked this conversation as resolved.

async function promptManualModelId(promptLabel, errorLabel, validator = null) {
while (true) {
const manual = await prompt(promptLabel);
const trimmed = manual.trim();
const navigation = getNavigationChoice(trimmed);
if (navigation === "back") {
return BACK_TO_SELECTION;
}
if (navigation === "exit") {
exitOnboardFromPrompt();
}
if (!trimmed || !isSafeModelId(trimmed)) {
console.error(` Invalid ${errorLabel} model id.`);
continue;
}
if (validator) {
const validation = validator(trimmed);
if (!validation.ok) {
console.error(` ${validation.message}`);
continue;
}
}
return trimmed;
}
}
// Build context helpers — delegated to src/lib/build-context.ts
const { shouldIncludeBuildContextPath, copyBuildContextDir, printSandboxCreateRecoveryHints } =
buildContext;
// classifySandboxCreateFailure — see validation import above

async function promptCloudModel() {
console.log("");
console.log(" Cloud models:");
CLOUD_MODEL_OPTIONS.forEach((option, index) => {
console.log(` ${index + 1}) ${option.label} (${option.id})`);
});
console.log(` ${CLOUD_MODEL_OPTIONS.length + 1}) Other...`);
console.log("");

const choice = await prompt(" Choose model [1]: ");
const navigation = getNavigationChoice(choice);
if (navigation === "back") {
return BACK_TO_SELECTION;
}
if (navigation === "exit") {
exitOnboardFromPrompt();
}
const index = parseInt(choice || "1", 10) - 1;
if (index >= 0 && index < CLOUD_MODEL_OPTIONS.length) {
return CLOUD_MODEL_OPTIONS[index].id;
}

return promptManualModelId(" NVIDIA Endpoints model id: ", "NVIDIA Endpoints", (model) =>
validateNvidiaEndpointModel(model, getCredential("NVIDIA_API_KEY")),
);
}

async function promptRemoteModel(label, providerKey, defaultModel, validator = null) {
const options = REMOTE_MODEL_OPTIONS[providerKey] || [];
const defaultIndex = Math.max(0, options.indexOf(defaultModel));

console.log("");
console.log(` ${label} models:`);
options.forEach((option, index) => {
console.log(` ${index + 1}) ${option}`);
});
console.log(` ${options.length + 1}) Other...`);
console.log("");

const choice = await prompt(` Choose model [${defaultIndex + 1}]: `);
const navigation = getNavigationChoice(choice);
if (navigation === "back") {
return BACK_TO_SELECTION;
}
if (navigation === "exit") {
exitOnboardFromPrompt();
}
const index = parseInt(choice || String(defaultIndex + 1), 10) - 1;
if (index >= 0 && index < options.length) {
return options[index];
}

return promptManualModelId(` ${label} model id: `, label, validator);
}

async function promptInputModel(label, defaultModel, validator = null) {
while (true) {
const value = await prompt(` ${label} model [${defaultModel}]: `);
const navigation = getNavigationChoice(value);
if (navigation === "back") {
return BACK_TO_SELECTION;
}
if (navigation === "exit") {
exitOnboardFromPrompt();
}
const trimmed = (value || defaultModel).trim();
if (!trimmed || !isSafeModelId(trimmed)) {
console.error(` Invalid ${label} model id.`);
continue;
}
if (validator) {
const validation = validator(trimmed);
if (!validation.ok) {
console.error(` ${validation.message}`);
continue;
}
}
return trimmed;
}
}

async function promptOllamaModel(gpu = null) {
const installed = getOllamaModelOptions(runCapture);
const options = installed.length > 0 ? installed : getBootstrapOllamaModelOptions(gpu);
Expand Down Expand Up @@ -2958,6 +2839,11 @@ async function setupNim(gpu) {
} else {
model = await promptOllamaModel(gpu);
}
if (model === BACK_TO_SELECTION) {
console.log(" Returning to provider selection.");
console.log("");
continue selectionLoop;
}
const probe = prepareOllamaModel(model, installedModels);
if (!probe.ok) {
console.error(` ${probe.message}`);
Expand Down Expand Up @@ -3010,6 +2896,11 @@ async function setupNim(gpu) {
} else {
model = await promptOllamaModel(gpu);
}
if (model === BACK_TO_SELECTION) {
console.log(" Returning to provider selection.");
console.log("");
continue selectionLoop;
}
const probe = prepareOllamaModel(model, installedModels);
if (!probe.ok) {
console.error(` ${probe.message}`);
Expand Down
142 changes: 142 additions & 0 deletions src/lib/model-prompts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { describe, expect, it, vi } from "vitest";

import {
BACK_TO_SELECTION,
promptCloudModel,
promptInputModel,
promptManualModelId,
promptRemoteModel,
} from "./model-prompts";

function promptSequence(responses: string[]) {
const queue = [...responses];
return vi.fn(async () => queue.shift() ?? "");
}

describe("model prompt helpers", () => {
it("returns the selected cloud model from the curated list", async () => {
const promptFn = promptSequence(["2"]);
const result = await promptCloudModel({
promptFn,
writeLine: vi.fn(),
cloudModelOptions: [
{ id: "nemotron", label: "Nemotron" },
{ id: "llama", label: "Llama" },
],
});

expect(result).toBe("llama");
});

it("validates manual cloud model ids against the saved NVIDIA key", async () => {
const promptFn = promptSequence(["9", "bad-model", "nemotron-custom"]);
const errorLine = vi.fn();
const result = await promptCloudModel({
promptFn,
errorLine,
writeLine: vi.fn(),
cloudModelOptions: [{ id: "nemotron", label: "Nemotron" }],
getCredentialFn: () => "nvapi-test",
validateNvidiaEndpointModelFn: (model) => ({
ok: model === "nemotron-custom",
message: `Model '${model}' is not available from NVIDIA Endpoints. Checked https://integrate.api.nvidia.com/v1/models.`,
}),
});

expect(result).toBe("nemotron-custom");
expect(errorLine).toHaveBeenCalledWith(
" Model 'bad-model' is not available from NVIDIA Endpoints. Checked https://integrate.api.nvidia.com/v1/models.",
);
});

it("returns back-to-selection with a clear message when the NVIDIA key is missing", async () => {
const errorLine = vi.fn();
const result = await promptCloudModel({
promptFn: promptSequence(["abc"]),
errorLine,
writeLine: vi.fn(),
cloudModelOptions: [{ id: "nemotron", label: "Nemotron" }],
getCredentialFn: () => null,
});

expect(result).toBe(BACK_TO_SELECTION);
expect(errorLine).toHaveBeenCalledWith(
" NVIDIA_API_KEY is required before validating a custom NVIDIA Endpoints model.",
);
});

it("defers transient manual validation failures back to the caller flow", async () => {
const errorLine = vi.fn();
const result = await promptManualModelId(
" Model: ",
"Provider",
() => ({ ok: false, message: "Could not validate model against /models: timeout" }),
{ promptFn: promptSequence(["custom-model"]), errorLine },
);

expect(result).toBe("custom-model");
expect(errorLine).toHaveBeenCalledWith(
" Could not validate model against /models: timeout",
);
});

it("returns back-to-selection for manual ids and input prompts", async () => {
await expect(
promptManualModelId(" Model: ", "Provider", null, { promptFn: promptSequence(["back"]) }),
).resolves.toBe(BACK_TO_SELECTION);
await expect(
promptInputModel("Provider", "default-model", null, { promptFn: promptSequence(["back"]) }),
).resolves.toBe(BACK_TO_SELECTION);
});

it("uses the default remote model choice when the user presses enter", async () => {
const result = await promptRemoteModel("OpenAI", "openai", "gpt-5.4-mini", null, {
promptFn: promptSequence([""]),
writeLine: vi.fn(),
});

expect(result).toBe("gpt-5.4-mini");
});

it("treats non-numeric curated selections as manual-entry fallback", async () => {
const result = await promptRemoteModel("OpenAI", "openai", "gpt-5.4-mini", null, {
promptFn: promptSequence(["abc", "custom-model"]),
writeLine: vi.fn(),
});

expect(result).toBe("custom-model");
});

it("retries invalid input models until validation succeeds", async () => {
const promptFn = promptSequence(["bad model", "other", "candidate"]);
const errorLine = vi.fn();
const result = await promptInputModel(
"Custom",
"default-model",
(model) => ({ ok: model === "candidate", message: "try again" }),
{ promptFn, errorLine },
);

expect(result).toBe("candidate");
expect(errorLine).toHaveBeenCalledWith(" Invalid Custom model id.");
expect(errorLine).toHaveBeenCalledWith(" try again");
});

it("returns input models immediately when validation should be deferred", async () => {
const errorLine = vi.fn();
const result = await promptInputModel(
"Custom",
"default-model",
() => ({ ok: false, message: "Could not validate model against /models: auth failed" }),
{ promptFn: promptSequence(["candidate"]), errorLine },
);

expect(result).toBe("candidate");
expect(errorLine).toHaveBeenCalledWith(
" Could not validate model against /models: auth failed",
);
});
});
Loading
Loading