* feat: add prek pre-commit hooks and dependabot Pre-commit hooks (via prek): - Basic hygiene: trailing-whitespace, end-of-file-fixer, check-yaml, check-added-large-files, check-merge-conflict - Security: detect-secrets, zizmor (GitHub Actions audit) - Linting: shellcheck, actionlint, oxlint, swiftlint - Formatting: oxfmt, swiftformat Dependabot: - npm and GitHub Actions ecosystems - Grouped updates (production/development/actions) - 7-day cooldown for supply chain protection Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * docs: add prek install instruction to AGENTS.md --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import { html, nothing } from "lit";
|
|
|
|
import type { ChannelAccountSnapshot } from "../types";
|
|
import type { ChannelKey, ChannelsProps } from "./channels.types";
|
|
|
|
export function formatDuration(ms?: number | null) {
|
|
if (!ms && ms !== 0) return "n/a";
|
|
const sec = Math.round(ms / 1000);
|
|
if (sec < 60) return `${sec}s`;
|
|
const min = Math.round(sec / 60);
|
|
if (min < 60) return `${min}m`;
|
|
const hr = Math.round(min / 60);
|
|
return `${hr}h`;
|
|
}
|
|
|
|
export function channelEnabled(key: ChannelKey, props: ChannelsProps) {
|
|
const snapshot = props.snapshot;
|
|
const channels = snapshot?.channels as Record<string, unknown> | null;
|
|
if (!snapshot || !channels) return false;
|
|
const channelStatus = channels[key] as Record<string, unknown> | undefined;
|
|
const configured = typeof channelStatus?.configured === "boolean" && channelStatus.configured;
|
|
const running = typeof channelStatus?.running === "boolean" && channelStatus.running;
|
|
const connected = typeof channelStatus?.connected === "boolean" && channelStatus.connected;
|
|
const accounts = snapshot.channelAccounts?.[key] ?? [];
|
|
const accountActive = accounts.some(
|
|
(account) => account.configured || account.running || account.connected,
|
|
);
|
|
return configured || running || connected || accountActive;
|
|
}
|
|
|
|
export function getChannelAccountCount(
|
|
key: ChannelKey,
|
|
channelAccounts?: Record<string, ChannelAccountSnapshot[]> | null,
|
|
): number {
|
|
return channelAccounts?.[key]?.length ?? 0;
|
|
}
|
|
|
|
export function renderChannelAccountCount(
|
|
key: ChannelKey,
|
|
channelAccounts?: Record<string, ChannelAccountSnapshot[]> | null,
|
|
) {
|
|
const count = getChannelAccountCount(key, channelAccounts);
|
|
if (count < 2) return nothing;
|
|
return html`<div class="account-count">Accounts (${count})</div>`;
|
|
}
|