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
247 changes: 72 additions & 175 deletions src/lib/onboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ const onboardSession: typeof import("./state/onboard-session") = require("./stat
const { OnboardRuntimeBoundary }: typeof import("./onboard/runtime-boundary") = require("./onboard/runtime-boundary");
const { handleGatewayState }: typeof import("./onboard/machine/handlers/gateway") = require("./onboard/machine/handlers/gateway");
const { handlePreflightState }: typeof import("./onboard/machine/handlers/preflight") = require("./onboard/machine/handlers/preflight");
const { handleProviderInferenceState }: typeof import("./onboard/machine/handlers/provider-inference") = require("./onboard/machine/handlers/provider-inference");
const policies: typeof import("./policy") = require("./policy");
const tiers: typeof import("./policy/tiers") = require("./policy/tiers");
const { ensureUsageNoticeConsent } = require("./onboard/usage-notice");
Expand Down Expand Up @@ -9405,181 +9406,77 @@ async function onboard(opts: OnboardOptions = {}): Promise<void> {
console.error(" Start a fresh onboard with --name <sandbox> to choose a different name.");
process.exit(1);
}
let model = session?.model || null;
let provider = session?.provider || null;
let endpointUrl = session?.endpointUrl || null;
let credentialEnv = session?.credentialEnv || null;
let hermesAuthMethod: HermesAuthMethod | null =
normalizeHermesAuthMethod(session?.hermesAuthMethod) ||
(provider === hermesProviderAuth.HERMES_PROVIDER_NAME &&
session?.credentialEnv === HERMES_NOUS_API_KEY_CREDENTIAL_ENV
? HERMES_AUTH_METHOD_API_KEY
: null);
let hermesToolGateways = normalizeHermesToolGatewaySelections(session?.hermesToolGateways);
let preferredInferenceApi = session?.preferredInferenceApi || null;
let nimContainer = session?.nimContainer || null;
let webSearchConfig = session?.webSearchConfig || null;
let forceProviderSelection = forceProviderSelectionForAgentChange;
while (true) {
const resumeProviderSelection =
!forceProviderSelection &&
resume &&
session?.steps?.provider_selection?.status === "complete" &&
typeof provider === "string" &&
typeof model === "string";
if (resumeProviderSelection) {
skippedStepMessage("provider_selection", `${provider} / ${model}`);
hydrateCredentialEnv(credentialEnv);
// #3342: resume short-circuits provider selection — repair the
// ollama-local systemd loopback override here so legacy 0.0.0.0
// drop-ins from older NemoClaw versions get rewritten every resume.
repairLocalInferenceSystemdOverrideOrExit(provider, isNonInteractive);
} else {
// #2753: do not persist sandboxName to onboard-session.json before
// the sandbox actually exists in the gateway (Step 6 markStepComplete
// below). A SIGINT between any earlier step and createSandbox would
// otherwise leave a phantom that `nemoclaw list` resurrects until
// manually destroyed.
await startRecordedStep("provider_selection");
const selection = await setupNim(gpu, sandboxName, agent);
model = selection.model;
provider = selection.provider;
endpointUrl = selection.endpointUrl;
credentialEnv = selection.credentialEnv;
hermesAuthMethod = selection.hermesAuthMethod;
hermesToolGateways = selection.hermesToolGateways;
preferredInferenceApi = selection.preferredInferenceApi;
nimContainer = selection.nimContainer;
await recordStepComplete(
"provider_selection",
toSessionUpdates({
provider,
model,
endpointUrl,
credentialEnv,
hermesAuthMethod,
hermesToolGateways,
preferredInferenceApi,
nimContainer,
}),
);
}

if (typeof provider !== "string" || typeof model !== "string") {
console.error(" Inference selection did not yield a provider/model.");
process.exit(1);
}
process.env.NEMOCLAW_OPENSHELL_BIN = getOpenshellBinary();
const needsBedrockRuntimeAdapter =
provider === "compatible-anthropic-endpoint" &&
bedrockRuntimeOnboard.needsBedrockRuntimeAdapter(endpointUrl);
const resumeInference =
!needsBedrockRuntimeAdapter &&
!forceProviderSelection &&
resume &&
isInferenceRouteReady(provider, model);
if (resumeInference) {
if (provider === hermesProviderAuth.HERMES_PROVIDER_NAME) {
if (!sandboxName) {
sandboxName = await promptValidatedSandboxName(agent);
}
await startRecordedStep("inference", { provider, model });
const inferenceResult = await setupInference(
sandboxName,
model,
provider,
endpointUrl,
credentialEnv,
hermesAuthMethod,
hermesToolGateways,
);
if (inferenceResult?.retry === "selection") {
forceProviderSelection = true;
continue;
}
await recordStepComplete(
"inference",
toSessionUpdates({ provider, model, hermesAuthMethod, nimContainer, hermesToolGateways }),
);
break;
}
if (isRoutedInferenceProvider(provider)) {
try {
await reconcileModelRouter();
} catch (err) {
console.error(
` ✗ Failed to reconcile model router: ${err instanceof Error ? err.message : String(err)}`,
);
process.exit(1);
}
}
skippedStepMessage("inference", `${provider} / ${model}`);
if (nimContainer && sandboxName) {
registry.updateSandbox(sandboxName, { nimContainer });
}
await recordStepComplete(
"inference",
toSessionUpdates({ provider, model, hermesAuthMethod, nimContainer, hermesToolGateways }),
);
break;
}

if (!sandboxName) {
sandboxName = await promptValidatedSandboxName(agent);
}
const buildEstimateNote =
process.env.NEMOCLAW_IGNORE_RUNTIME_RESOURCES === "1"
? null
: formatSandboxBuildEstimateNote(assessHost());
console.log(
formatOnboardConfigSummary({
provider,
model,
credentialEnv,
hermesAuthMethod,
webSearchConfig,
hermesToolGateways,
enabledChannels: selectedMessagingChannels.length > 0 ? selectedMessagingChannels : null,
sandboxName,
notes: buildEstimateNote ? [buildEstimateNote] : [],
}),
);
console.log(" Web search and messaging channels will be prompted next.");
if (!isNonInteractive()) {
if (!(await promptYesNoOrDefault(" Apply this configuration?", null, true))) {
console.log(` Aborted. Re-run \`${cliName()} onboard\` to start over.`);
console.log(" Credentials entered so far were only staged in memory for this run.");
console.log(
" No new gateway credential was registered because onboarding stopped here.",
);
process.exit(0);
}
}

await startRecordedStep("inference", { provider, model });
const inferenceResult = await setupInference(
sandboxName,
model,
provider,
endpointUrl,
credentialEnv,
hermesAuthMethod,
hermesToolGateways,
);
delete process.env.NVIDIA_API_KEY;
if (inferenceResult?.retry === "selection") {
forceProviderSelection = true;
continue;
}
if (nimContainer && sandboxName) {
registry.updateSandbox(sandboxName, { nimContainer });
}
await recordStepComplete(
"inference",
toSessionUpdates({ provider, model, hermesAuthMethod, nimContainer, hermesToolGateways }),
);
break;
}
const providerInferenceResult = await handleProviderInferenceState({
resume,
session,
gpu,
sandboxName,
agent,
forceProviderSelection: forceProviderSelectionForAgentChange,
initial: {
model: session?.model || null,
provider: session?.provider || null,
endpointUrl: session?.endpointUrl || null,
credentialEnv: session?.credentialEnv || null,
hermesAuthMethod: session?.hermesAuthMethod || null,
hermesToolGateways: normalizeHermesToolGatewaySelections(session?.hermesToolGateways),
preferredInferenceApi: session?.preferredInferenceApi || null,
nimContainer: session?.nimContainer || null,
webSearchConfig: session?.webSearchConfig || null,
},
selectedMessagingChannels,
env: process.env,
constants: {
hermesProviderName: hermesProviderAuth.HERMES_PROVIDER_NAME,
hermesApiKeyAuthMethod: HERMES_AUTH_METHOD_API_KEY,
hermesApiKeyCredentialEnv: HERMES_NOUS_API_KEY_CREDENTIAL_ENV,
},
deps: {
normalizeHermesAuthMethod,
setupNim,
setupInference,
startRecordedStep,
recordStepComplete,
toSessionUpdates: (updates) => toSessionUpdates(updates as Parameters<typeof toSessionUpdates>[0]),
skippedStepMessage,
hydrateCredentialEnv,
repairLocalInferenceSystemdOverrideOrExit,
isNonInteractive,
getOpenshellBinary,
needsBedrockRuntimeAdapter: (providerName, url) =>
providerName === "compatible-anthropic-endpoint" &&
bedrockRuntimeOnboard.needsBedrockRuntimeAdapter(url),
isInferenceRouteReady,
isRoutedInferenceProvider,
reconcileModelRouter,
registryUpdateSandbox: (name, updates) => registry.updateSandbox(name, updates),
promptValidatedSandboxName,
assessHost,
formatSandboxBuildEstimateNote,
formatOnboardConfigSummary,
promptYesNoOrDefault,
cliName,
log: (message) => console.log(message),
error: (message) => console.error(message),
exitProcess: (code) => process.exit(code),
deleteEnv: (name) => {
delete process.env[name];
},
},
});
session = providerInferenceResult.session;
sandboxName = providerInferenceResult.sandboxName;
const {
model,
provider,
endpointUrl,
credentialEnv,
hermesAuthMethod,
hermesToolGateways,
preferredInferenceApi,
nimContainer,
} = providerInferenceResult;
let webSearchConfig = providerInferenceResult.webSearchConfig;

const webSearchSupportProbePath = fromDockerfile ? path.resolve(fromDockerfile) : null;
const webSearchSupported = agentSupportsWebSearch(agent, webSearchSupportProbePath, ROOT);
Expand Down
Loading