2026-02-18 01:29:02 +00:00
|
|
|
import { type ChannelId, getChannelPlugin } from "../../channels/plugins/index.js";
|
2026-02-18 01:34:35 +00:00
|
|
|
import type { OpenClawConfig } from "../../config/config.js";
|
2026-01-08 06:46:40 +01:00
|
|
|
import { DEFAULT_ACCOUNT_ID } from "../../routing/session-key.js";
|
|
|
|
|
import { defaultRuntime, type RuntimeEnv } from "../../runtime.js";
|
2026-02-16 14:52:09 +00:00
|
|
|
import { requireValidConfigSnapshot } from "../config-validation.js";
|
2026-01-08 06:46:40 +01:00
|
|
|
|
2026-01-13 06:16:43 +00:00
|
|
|
export type ChatChannel = ChannelId;
|
2026-01-08 06:46:40 +01:00
|
|
|
|
|
|
|
|
export async function requireValidConfig(
|
|
|
|
|
runtime: RuntimeEnv = defaultRuntime,
|
2026-01-30 03:15:10 +01:00
|
|
|
): Promise<OpenClawConfig | null> {
|
2026-02-16 14:52:09 +00:00
|
|
|
return await requireValidConfigSnapshot(runtime);
|
2026-01-08 06:46:40 +01:00
|
|
|
}
|
|
|
|
|
|
2026-01-14 14:31:43 +00:00
|
|
|
export function formatAccountLabel(params: { accountId: string; name?: string }) {
|
2026-01-08 06:46:40 +01:00
|
|
|
const base = params.accountId || DEFAULT_ACCOUNT_ID;
|
2026-01-31 16:19:20 +09:00
|
|
|
if (params.name?.trim()) {
|
|
|
|
|
return `${base} (${params.name.trim()})`;
|
|
|
|
|
}
|
2026-01-08 06:46:40 +01:00
|
|
|
return base;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-13 06:16:43 +00:00
|
|
|
export const channelLabel = (channel: ChatChannel) => {
|
|
|
|
|
const plugin = getChannelPlugin(channel);
|
|
|
|
|
return plugin?.meta.label ?? channel;
|
2026-01-11 11:45:25 +00:00
|
|
|
};
|
2026-01-08 06:46:40 +01:00
|
|
|
|
2026-01-13 06:16:43 +00:00
|
|
|
export function formatChannelAccountLabel(params: {
|
|
|
|
|
channel: ChatChannel;
|
2026-01-08 07:20:02 +01:00
|
|
|
accountId: string;
|
|
|
|
|
name?: string;
|
2026-01-13 06:16:43 +00:00
|
|
|
channelStyle?: (value: string) => string;
|
2026-01-08 07:20:02 +01:00
|
|
|
accountStyle?: (value: string) => string;
|
|
|
|
|
}): string {
|
2026-01-13 06:16:43 +00:00
|
|
|
const channelText = channelLabel(params.channel);
|
2026-01-08 07:20:02 +01:00
|
|
|
const accountText = formatAccountLabel({
|
|
|
|
|
accountId: params.accountId,
|
|
|
|
|
name: params.name,
|
|
|
|
|
});
|
2026-01-14 14:31:43 +00:00
|
|
|
const styledChannel = params.channelStyle ? params.channelStyle(channelText) : channelText;
|
|
|
|
|
const styledAccount = params.accountStyle ? params.accountStyle(accountText) : accountText;
|
2026-01-13 06:16:43 +00:00
|
|
|
return `${styledChannel} ${styledAccount}`;
|
2026-01-08 07:20:02 +01:00
|
|
|
}
|
|
|
|
|
|
2026-01-08 06:46:40 +01:00
|
|
|
export function shouldUseWizard(params?: { hasFlags?: boolean }) {
|
|
|
|
|
return params?.hasFlags === false;
|
|
|
|
|
}
|