chore: Fix type errors from reverts.

This commit is contained in:
cpojer
2026-02-17 11:22:31 +09:00
parent 262b7a157a
commit 4b8f53979e
9 changed files with 30 additions and 22 deletions

View File

@@ -40,8 +40,8 @@ export async function monitorIrcProvider(opts: IrcMonitorOptions): Promise<{ sto
});
const runtime: RuntimeEnv = opts.runtime ?? {
log: (message: string) => core.logging.getChildLogger().info(message),
error: (message: string) => core.logging.getChildLogger().error(message),
log: (...args: unknown[]) => core.logging.getChildLogger().info(args.map(String).join(" ")),
error: (...args: unknown[]) => core.logging.getChildLogger().error(args.map(String).join(" ")),
exit: () => {
throw new Error("Runtime exit not available");
},

View File

@@ -213,8 +213,8 @@ export async function monitorNextcloudTalkProvider(
accountId: opts.accountId,
});
const runtime: RuntimeEnv = opts.runtime ?? {
log: (message: string) => core.logging.getChildLogger().info(message),
error: (message: string) => core.logging.getChildLogger().error(message),
log: (...args: unknown[]) => core.logging.getChildLogger().info(args.map(String).join(" ")),
error: (...args: unknown[]) => core.logging.getChildLogger().error(args.map(String).join(" ")),
exit: () => {
throw new Error("Runtime exit not available");
},

View File

@@ -261,7 +261,7 @@ const formatUsagePair = (input?: number | null, output?: number | null) => {
return `🧮 Tokens: ${inputLabel} in / ${outputLabel} out`;
};
const formatMediaUnderstandingLine = (decisions?: MediaUnderstandingDecision[]) => {
const formatMediaUnderstandingLine = (decisions?: ReadonlyArray<MediaUnderstandingDecision>) => {
if (!decisions || decisions.length === 0) {
return null;
}

View File

@@ -84,6 +84,7 @@ export function registerBrowserExtensionCommands(
} catch (err) {
defaultRuntime.error(danger(String(err)));
defaultRuntime.exit(1);
return;
}
if (parent?.json) {

View File

@@ -24,6 +24,15 @@ const multiselect = <T>(params: Parameters<typeof clackMultiselect<T>>[0]) =>
),
});
function guardPromptCancel<T>(value: T | symbol, runtime: RuntimeEnv): T {
if (isCancel(value)) {
cancel(stylePromptTitle("Model scan cancelled.") ?? "Model scan cancelled.");
runtime.exit(0);
throw new Error("unreachable");
}
return value;
}
const pad = (value: string, size: number) => value.padEnd(size);
const truncate = (value: string, max: number) => {
@@ -262,12 +271,7 @@ export async function modelsScanCommand(
initialValues: preselected,
});
if (isCancel(selection)) {
cancel(stylePromptTitle("Model scan cancelled.") ?? "Model scan cancelled.");
runtime.exit(0);
}
selected = selection;
selected = guardPromptCancel(selection, runtime);
if (imageSorted.length > 0) {
const imageSelection = await multiselect({
message: "Select image fallback models (ordered)",
@@ -279,12 +283,7 @@ export async function modelsScanCommand(
initialValues: imagePreselected,
});
if (isCancel(imageSelection)) {
cancel(stylePromptTitle("Model scan cancelled.") ?? "Model scan cancelled.");
runtime.exit(0);
}
selectedImages = imageSelection;
selectedImages = guardPromptCancel(imageSelection, runtime);
}
} else if (!process.stdin.isTTY && !opts.yes && !noInput && !opts.json) {
throw new Error("Non-interactive scan: pass --yes to apply defaults.");

View File

@@ -31,6 +31,7 @@ export function guardCancel<T>(value: T | symbol, runtime: RuntimeEnv): T {
if (isCancel(value)) {
cancel(stylePromptTitle("Setup cancelled.") ?? "Setup cancelled.");
runtime.exit(0);
throw new Error("unreachable");
}
return value;
}

View File

@@ -19,8 +19,8 @@ const NON_INTERACTIVE_DEFAULT_OPTIONS = {
export function createThrowingRuntime(): NonInteractiveRuntime {
return {
log: () => {},
error: (msg: string) => {
throw new Error(msg);
error: (...args: unknown[]) => {
throw new Error(args.map(String).join(" "));
},
exit: (code: number) => {
throw new Error(`exit:${code}`);

View File

@@ -88,7 +88,8 @@ export async function handlePortError(
logDebug(`stderr: ${stderr.trim()}`);
}
}
return runtime.exit(1);
runtime.exit(1);
throw new Error("unreachable");
}
export { PortInUseError };

View File

@@ -1,3 +1,4 @@
import { inspect } from "node:util";
import { Chalk } from "chalk";
import type { Logger as TsLogger } from "tslog";
import { CHAT_CHANNEL_ORDER } from "../channels/registry.js";
@@ -320,9 +321,14 @@ export function runtimeForLogger(
logger: SubsystemLogger,
exit: RuntimeEnv["exit"] = defaultRuntime.exit,
): RuntimeEnv {
const formatArgs = (...args: unknown[]) =>
args
.map((arg) => (typeof arg === "string" ? arg : inspect(arg)))
.join(" ")
.trim();
return {
log: (message: string) => logger.info(message),
error: (message: string) => logger.error(message),
log: (...args: unknown[]) => logger.info(formatArgs(...args)),
error: (...args: unknown[]) => logger.error(formatArgs(...args)),
exit,
};
}