Merge pull request #8356 from continuedev/dallin/cli-loading-fixes
fix(CLI): HOTFIX allow default config fallback for headless
This commit is contained in:
commit
ddf4e0f165
5 changed files with 49 additions and 14 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import * as fs from "fs";
|
||||
import { dirname } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import * as path from "path";
|
||||
|
||||
import {
|
||||
|
|
@ -24,6 +25,7 @@ import {
|
|||
} from "./auth/workos.js";
|
||||
import { CLIPlatformClient } from "./CLIPlatformClient.js";
|
||||
import { env } from "./env.js";
|
||||
import { logger } from "./util/logger.js";
|
||||
|
||||
export interface ConfigLoadResult {
|
||||
config: AssistantUnrolled;
|
||||
|
|
@ -95,16 +97,28 @@ function determineConfigSource(
|
|||
return { type: "cli-flag", path: cliConfigPath };
|
||||
}
|
||||
|
||||
// In headless, config fallback behavior isn't supported
|
||||
if (isHeadless) {
|
||||
return { type: "no-config" };
|
||||
}
|
||||
|
||||
// Priority 2: Saved config URI (only for file-based auth)
|
||||
if (!isEnvironmentAuthConfig(authConfig) && authConfig !== null) {
|
||||
const savedUri = getConfigUri(authConfig);
|
||||
|
||||
if (savedUri) {
|
||||
return { type: "saved-uri", uri: savedUri };
|
||||
if (savedUri.startsWith("file:")) {
|
||||
let exists = false; // wrote like this for nested depth linting rule lol
|
||||
try {
|
||||
const filepath = fileURLToPath(savedUri);
|
||||
exists = fs.existsSync(filepath);
|
||||
} catch (e) {
|
||||
logger.warn("Invalid saved file URI " + savedUri, e);
|
||||
}
|
||||
if (exists) {
|
||||
return { type: "saved-uri", uri: savedUri };
|
||||
} else {
|
||||
logger.warn("Saved config URI does not exist: " + savedUri);
|
||||
}
|
||||
} else {
|
||||
// slug
|
||||
return { type: "saved-uri", uri: savedUri };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -117,6 +131,10 @@ function determineConfigSource(
|
|||
}
|
||||
return { type: "default-agent" };
|
||||
} else {
|
||||
// In headless, user assistant fallback behavior isn't supported
|
||||
if (isHeadless) {
|
||||
return { type: "no-config" };
|
||||
}
|
||||
// Authenticated: try user assistants first
|
||||
return { type: "user-assistant", slug: "" }; // Empty slug means "first available"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -677,11 +677,14 @@ describe("ConfigService", () => {
|
|||
config,
|
||||
mockApiClient as any,
|
||||
{ accessToken: "token" } as any,
|
||||
true,
|
||||
),
|
||||
).rejects.toThrow("No model specified and failed to load default model");
|
||||
).rejects.toThrow(
|
||||
"No model specified in headless mode (and failed to load default model)",
|
||||
);
|
||||
});
|
||||
|
||||
test("should throw error when loaded default model is empty", async () => {
|
||||
test("should throw error when loaded default model is empty in headless", async () => {
|
||||
const config = {
|
||||
name: "test-config",
|
||||
version: "1.0.0",
|
||||
|
|
@ -704,8 +707,11 @@ describe("ConfigService", () => {
|
|||
config,
|
||||
mockApiClient as any,
|
||||
{ accessToken: "token" } as any,
|
||||
true,
|
||||
),
|
||||
).rejects.toThrow("No model specified and failed to load default model");
|
||||
).rejects.toThrow(
|
||||
"No model specified in headless mode (and failed to load default model)",
|
||||
);
|
||||
});
|
||||
|
||||
test("should work with null access token", async () => {
|
||||
|
|
|
|||
|
|
@ -215,6 +215,7 @@ export class ConfigService
|
|||
config: AssistantUnrolled,
|
||||
apiClient: DefaultApiInterface,
|
||||
authConfig: AuthConfig | undefined,
|
||||
isHeadless?: boolean,
|
||||
): Promise<AssistantUnrolled> {
|
||||
const hasChatModel = !!config.models?.find(
|
||||
(m) => !!m && (!m.roles || m.roles.includes("chat")),
|
||||
|
|
@ -233,8 +234,16 @@ export class ConfigService
|
|||
}
|
||||
config.models = [...(config.models || []), defaultModel];
|
||||
} catch (e) {
|
||||
logger.error("Failed to load default model with no model specified", e);
|
||||
throw new Error("No model specified and failed to load default model");
|
||||
if (isHeadless) {
|
||||
throw new Error(
|
||||
"No model specified in headless mode (and failed to load default model)",
|
||||
);
|
||||
} else {
|
||||
logger.error(
|
||||
"Failed to load default model with no model specified",
|
||||
e,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return config;
|
||||
|
|
@ -270,6 +279,7 @@ export class ConfigService
|
|||
merged,
|
||||
apiClient,
|
||||
authConfig,
|
||||
init.isHeadless,
|
||||
);
|
||||
|
||||
// Config URI persistence is now handled by the streamlined loader
|
||||
|
|
|
|||
|
|
@ -64,8 +64,9 @@ export class ModelService
|
|||
preferredModelName = agentFileServiceState.agentFileModel?.name;
|
||||
modelSource = "agentFile";
|
||||
} else {
|
||||
preferredModelName = getModelName(authConfig);
|
||||
if (preferredModelName) {
|
||||
const persistedName = getModelName(authConfig);
|
||||
if (persistedName) {
|
||||
preferredModelName = persistedName;
|
||||
modelSource = "persisted";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ describe("UpdateNotification", () => {
|
|||
|
||||
const { lastFrame } = render(<UpdateNotification />);
|
||||
|
||||
expect(lastFrame()).toContain("◉ Updating to v1.0.1");
|
||||
expect(lastFrame()).toContain("Updating to v1.0.1");
|
||||
});
|
||||
|
||||
it("should show updated message when update completes", () => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue