fix: rebase onto main + restore build/lint (#567) (thanks @erikpr1994)

This commit is contained in:
Peter Steinberger
2026-01-09 15:23:41 +01:00
parent fd3cbd96a8
commit c228df8f90
5 changed files with 75 additions and 33 deletions

View File

@@ -718,9 +718,7 @@ export async function setAuthProfileOrder(params: {
const providerKey = normalizeProviderId(params.provider);
const sanitized =
params.order && Array.isArray(params.order)
? params.order
.map((entry) => String(entry).trim())
.filter(Boolean)
? params.order.map((entry) => String(entry).trim()).filter(Boolean)
: [];
const deduped: string[] = [];

View File

@@ -88,7 +88,9 @@ const resolveAuthLabel = async (
mode: ModelAuthDetailMode = "compact",
): Promise<{ label: string; source: string }> => {
const formatPath = (value: string) => shortenHomePath(value);
const store = ensureAuthProfileStore(agentDir, { allowKeychainPrompt: false });
const store = ensureAuthProfileStore(agentDir, {
allowKeychainPrompt: false,
});
const order = resolveAuthProfileOrder({ cfg, store, provider });
const providerKey = normalizeProviderId(provider);
const lastGood = (() => {
@@ -121,7 +123,8 @@ const resolveAuthLabel = async (
const configProfile = cfg.auth?.profiles?.[profileId];
const missing =
!profile ||
(configProfile?.provider && configProfile.provider !== profile.provider) ||
(configProfile?.provider &&
configProfile.provider !== profile.provider) ||
(configProfile?.mode &&
configProfile.mode !== profile.type &&
!(configProfile.mode === "oauth" && profile.type === "token"));
@@ -170,7 +173,11 @@ const resolveAuthLabel = async (
if (lastGood && profileId === lastGood) flags.push("lastGood");
if (isProfileInCooldown(store, profileId)) {
const until = store.usageStats?.[profileId]?.cooldownUntil;
if (typeof until === "number" && Number.isFinite(until) && until > now) {
if (
typeof until === "number" &&
Number.isFinite(until) &&
until > now
) {
flags.push(`cooldown ${formatUntil(until)}`);
} else {
flags.push("cooldown");
@@ -197,7 +204,11 @@ const resolveAuthLabel = async (
Number.isFinite(profile.expires) &&
profile.expires > 0
) {
flags.push(profile.expires <= now ? "expired" : `exp ${formatUntil(profile.expires)}`);
flags.push(
profile.expires <= now
? "expired"
: `exp ${formatUntil(profile.expires)}`,
);
}
const suffix = flags.length > 0 ? ` (${flags.join(", ")})` : "";
return `${profileId}=token:${maskApiKey(profile.token)}${suffix}`;
@@ -218,7 +229,11 @@ const resolveAuthLabel = async (
Number.isFinite(profile.expires) &&
profile.expires > 0
) {
flags.push(profile.expires <= now ? "expired" : `exp ${formatUntil(profile.expires)}`);
flags.push(
profile.expires <= now
? "expired"
: `exp ${formatUntil(profile.expires)}`,
);
}
const suffixLabel = suffix ? ` ${suffix}` : "";
const suffixFlags = flags.length > 0 ? ` (${flags.join(", ")})` : "";
@@ -242,7 +257,8 @@ const resolveAuthLabel = async (
if (customKey) {
return {
label: maskApiKey(customKey),
source: mode === "verbose" ? `models.json: ${formatPath(modelsPath)}` : "",
source:
mode === "verbose" ? `models.json: ${formatPath(modelsPath)}` : "",
};
}
return { label: "missing", source: "missing" };
@@ -803,16 +819,16 @@ export async function handleDirectiveOnly(params: {
}
modelSelection = resolved.selection;
if (modelSelection) {
if (directives.rawModelProfile) {
const profileResolved = resolveProfileOverride({
rawProfile: directives.rawModelProfile,
provider: modelSelection.provider,
cfg: params.cfg,
agentDir,
});
if (profileResolved.error) {
return { text: profileResolved.error };
}
if (directives.rawModelProfile) {
const profileResolved = resolveProfileOverride({
rawProfile: directives.rawModelProfile,
provider: modelSelection.provider,
cfg: params.cfg,
agentDir,
});
if (profileResolved.error) {
return { text: profileResolved.error };
}
profileOverride = profileResolved.profileId;
}
const nextLabel = `${modelSelection.provider}/${modelSelection.model}`;
@@ -994,6 +1010,10 @@ export async function persistInlineDirectives(params: {
agentCfg,
} = params;
let { provider, model } = params;
const activeAgentId = sessionKey
? resolveAgentIdFromSessionKey(sessionKey)
: resolveDefaultAgentId(cfg);
const agentDir = resolveAgentDir(cfg, activeAgentId);
if (sessionEntry && sessionStore && sessionKey) {
let updated = false;

View File

@@ -392,7 +392,9 @@ export function registerModelsCli(program: Command) {
order
.command("set")
.description("Set per-agent auth order override (locks rotation to this list)")
.description(
"Set per-agent auth order override (locks rotation to this list)",
)
.requiredOption("--provider <name>", "Provider id (e.g. anthropic)")
.option("--agent <id>", "Agent id (default: configured default agent)")
.argument("<profileIds...>", "Auth profile ids (e.g. anthropic:claude-cli)")
@@ -414,7 +416,9 @@ export function registerModelsCli(program: Command) {
order
.command("clear")
.description("Clear per-agent auth order override (fall back to config/round-robin)")
.description(
"Clear per-agent auth order override (fall back to config/round-robin)",
)
.requiredOption("--provider <name>", "Provider id (e.g. anthropic)")
.option("--agent <id>", "Agent id (default: configured default agent)")
.action(async (opts) => {

View File

@@ -80,6 +80,7 @@ import {
DEFAULT_WORKSPACE,
ensureWorkspaceAndSessions,
guardCancel,
openUrl,
printWizardHeader,
probeGatewayReachable,
randomToken,

View File

@@ -1,16 +1,22 @@
import { resolveAgentDir, resolveDefaultAgentId } from "../../agents/agent-scope.js";
import {
resolveAgentDir,
resolveDefaultAgentId,
} from "../../agents/agent-scope.js";
import {
type AuthProfileStore,
ensureAuthProfileStore,
setAuthProfileOrder,
type AuthProfileStore,
} from "../../agents/auth-profiles.js";
import { normalizeProviderId } from "../../agents/model-selection.js";
import { loadConfig } from "../../config/config.js";
import { normalizeAgentId } from "../../routing/session-key.js";
import type { RuntimeEnv } from "../../runtime.js";
import { shortenHomePath } from "../../utils.js";
import { normalizeAgentId } from "../../routing/session-key.js";
function resolveTargetAgent(cfg: ReturnType<typeof loadConfig>, raw?: string): {
function resolveTargetAgent(
cfg: ReturnType<typeof loadConfig>,
raw?: string,
): {
agentId: string;
agentDir: string;
} {
@@ -37,7 +43,9 @@ export async function modelsAuthOrderGetCommand(
const cfg = loadConfig();
const { agentId, agentDir } = resolveTargetAgent(cfg, opts.agent);
const store = ensureAuthProfileStore(agentDir, { allowKeychainPrompt: false });
const store = ensureAuthProfileStore(agentDir, {
allowKeychainPrompt: false,
});
const order = describeOrder(store, provider);
if (opts.json) {
@@ -59,9 +67,13 @@ export async function modelsAuthOrderGetCommand(
runtime.log(`Agent: ${agentId}`);
runtime.log(`Provider: ${provider}`);
runtime.log(`Auth file: ${shortenHomePath(`${agentDir}/auth-profiles.json`)}`);
runtime.log(
order.length > 0 ? `Order override: ${order.join(", ")}` : "Order override: (none)",
`Auth file: ${shortenHomePath(`${agentDir}/auth-profiles.json`)}`,
);
runtime.log(
order.length > 0
? `Order override: ${order.join(", ")}`
: "Order override: (none)",
);
}
@@ -75,8 +87,13 @@ export async function modelsAuthOrderClearCommand(
const cfg = loadConfig();
const { agentId, agentDir } = resolveTargetAgent(cfg, opts.agent);
const updated = await setAuthProfileOrder({ agentDir, provider, order: null });
if (!updated) throw new Error("Failed to update auth-profiles.json (lock busy?).");
const updated = await setAuthProfileOrder({
agentDir,
provider,
order: null,
});
if (!updated)
throw new Error("Failed to update auth-profiles.json (lock busy?).");
runtime.log(`Agent: ${agentId}`);
runtime.log(`Provider: ${provider}`);
@@ -94,7 +111,9 @@ export async function modelsAuthOrderSetCommand(
const cfg = loadConfig();
const { agentId, agentDir } = resolveTargetAgent(cfg, opts.agent);
const store = ensureAuthProfileStore(agentDir, { allowKeychainPrompt: false });
const store = ensureAuthProfileStore(agentDir, {
allowKeychainPrompt: false,
});
const providerKey = normalizeProviderId(provider);
const requested = (opts.order ?? [])
.map((entry) => String(entry).trim())
@@ -120,10 +139,10 @@ export async function modelsAuthOrderSetCommand(
provider,
order: requested,
});
if (!updated) throw new Error("Failed to update auth-profiles.json (lock busy?).");
if (!updated)
throw new Error("Failed to update auth-profiles.json (lock busy?).");
runtime.log(`Agent: ${agentId}`);
runtime.log(`Provider: ${provider}`);
runtime.log(`Order override: ${describeOrder(updated, provider).join(", ")}`);
}