refactor: centralize channel ui metadata

This commit is contained in:
Peter Steinberger
2026-01-20 13:10:26 +00:00
parent 6f9861bb9b
commit fdb171cb15
19 changed files with 240 additions and 68 deletions

View File

@@ -106,6 +106,7 @@ import { loginWeb } from "../../web/login.js";
import { startWebLoginWithQr, waitForWebLogin } from "../../web/login-qr.js";
import { sendMessageWhatsApp, sendPollWhatsApp } from "../../web/outbound.js";
import { registerMemoryCli } from "../../cli/memory-cli.js";
import { formatNativeDependencyHint } from "./native-deps.js";
import type { PluginRuntime } from "./types.js";
@@ -134,6 +135,7 @@ export function createPluginRuntime(): PluginRuntime {
system: {
enqueueSystemEvent,
runCommandWithTimeout,
formatNativeDependencyHint,
},
media: {
loadWebMedia,

View File

@@ -0,0 +1,28 @@
export type NativeDependencyHintParams = {
packageName: string;
manager?: "pnpm" | "npm" | "yarn";
rebuildCommand?: string;
approveBuildsCommand?: string;
downloadCommand?: string;
};
export function formatNativeDependencyHint(params: NativeDependencyHintParams): string {
const manager = params.manager ?? "pnpm";
const rebuildCommand =
params.rebuildCommand ??
(manager === "npm"
? `npm rebuild ${params.packageName}`
: manager === "yarn"
? `yarn rebuild ${params.packageName}`
: `pnpm rebuild ${params.packageName}`);
const approveBuildsCommand =
params.approveBuildsCommand ??
(manager === "pnpm" ? `pnpm approve-builds (select ${params.packageName})` : undefined);
const steps = [approveBuildsCommand, rebuildCommand, params.downloadCommand].filter(
(step): step is string => Boolean(step),
);
if (steps.length === 0) {
return `Install ${params.packageName} and rebuild its native module.`;
}
return `Install ${params.packageName} and rebuild its native module (${steps.join("; ")}).`;
}

View File

@@ -59,6 +59,7 @@ type RecordChannelActivity = typeof import("../../infra/channel-activity.js").re
type GetChannelActivity = typeof import("../../infra/channel-activity.js").getChannelActivity;
type EnqueueSystemEvent = typeof import("../../infra/system-events.js").enqueueSystemEvent;
type RunCommandWithTimeout = typeof import("../../process/exec.js").runCommandWithTimeout;
type FormatNativeDependencyHint = typeof import("./native-deps.js").formatNativeDependencyHint;
type LoadWebMedia = typeof import("../../web/media.js").loadWebMedia;
type DetectMime = typeof import("../../media/mime.js").detectMime;
type MediaKindFromMime = typeof import("../../media/constants.js").mediaKindFromMime;
@@ -146,6 +147,7 @@ export type PluginRuntime = {
system: {
enqueueSystemEvent: EnqueueSystemEvent;
runCommandWithTimeout: RunCommandWithTimeout;
formatNativeDependencyHint: FormatNativeDependencyHint;
};
media: {
loadWebMedia: LoadWebMedia;