/** * Pure view model for the Combos overview (route board): one row per combo, its channels in * routing order, and what each channel's provider has left. No React, no fetch. * * The layout follows the "one row per model group" idea of Magpie's routing page * (MIT, Copyright (c) 2026 yetone). No code is taken from it. */ import { COMBO_STRATEGIES, type ComboDraftError, type ComboItem, type ComboStrategy, comboPublicModelId, } from "./combo-workspace-data"; import type { TKey } from "./i18n/shared"; import { freshQuotaReportsFromResponse } from "./provider-workspace/report"; import { buildQuotaSummary, type QuotaSummaryWindow } from "./quota-summary"; /** What `/api/models` says about one combo row (`provider === "combo"`). */ export interface ComboCatalogMeta { displayName?: string; contextWindow?: number; disabled: boolean; } export interface RouteBoardProvider { name: string; disabled?: boolean; authMode?: string; } export type QuotaTone = "ok" | "warn" | "low"; export interface QuotaWindowView { id: string; /** Fixed window name; otherwise `label` is the provider's own window name. */ labelKey?: TKey; label?: string; remainingPercent: number; tone: QuotaTone; } /** Subscription windows, a pay-per-use key, or nothing reported. */ export type ChannelQuota = | { kind: "windows"; windows: QuotaWindowView[] } | { kind: "metered" } | { kind: "unknown" }; /** Accounts behind one provider; paused accounts take no traffic. */ export interface AccountCount { active: number; paused: number; } export interface RouteChannel { key: string; provider: string; model: string; lastResort: boolean; providerDisabled: boolean; } export interface ProviderQuotaLine { provider: string; quota: ChannelQuota; accounts?: AccountCount; } /** What the catalog says one member can take. */ /** * Where a member capability value comes from, as `/api/models` labels it per axis * (`capabilitySources`): the operator's declaration, a declaration a capability probe wrote, the * provider's own report, a same-name estimate, or nowhere. */ export type CapabilitySource = "manual" | "probed" | "reported" | "inferred" | "unknown"; const CAPABILITY_SOURCES: ReadonlySet = new Set(["manual", "probed", "reported", "inferred", "unknown"]); /** A same-name estimate and what it rests on. Display data only: it never routes. */ export interface InferredValue { value: T; basis: { source: "registry" | "vendor" | "provider" | "aggregator"; provider: string; modelId: string }; } export interface MemberInferred { context?: InferredValue; input?: InferredValue; efforts?: InferredValue; } /** `capabilitySources` from a `/api/models` row; undefined from a backend that does not send it. */ export function parseCapabilitySources(raw: unknown): MemberSources | undefined { if (!raw || typeof raw !== "object") return undefined; const axes = raw as { contextWindow?: unknown; inputModalities?: unknown; reasoningEfforts?: unknown }; const read = (value: unknown): CapabilitySource => typeof value === "string" && CAPABILITY_SOURCES.has(value) ? value as CapabilitySource : "unknown"; return { context: read(axes.contextWindow), input: read(axes.inputModalities), efforts: read(axes.reasoningEfforts) }; } /** `inferredCapabilities` from a `/api/models` row: only well-formed axes survive. */ export function parseInferredCapabilities(raw: unknown): MemberInferred | undefined { if (!raw || typeof raw !== "object") return undefined; const basisOf = (value: unknown): InferredValue["basis"] | undefined => { if (!value || typeof value !== "object") return undefined; const basis = value as { source?: unknown; provider?: unknown; modelId?: unknown }; return ["registry", "vendor", "provider", "aggregator"].includes(String(basis.source)) && typeof basis.provider === "string" && typeof basis.modelId === "string" ? { source: basis.source as InferredValue["basis"]["source"], provider: basis.provider, modelId: basis.modelId } : undefined; }; const axis = (value: unknown, valid: (candidate: unknown) => candidate is T): InferredValue | undefined => { if (!value || typeof value !== "object") return undefined; const entry = value as { value?: unknown; basis?: unknown }; const basis = basisOf(entry.basis); return basis && valid(entry.value) ? { value: entry.value, basis } : undefined; }; const isTokens = (value: unknown): value is number => typeof value === "number" && Number.isSafeInteger(value) && value > 0; const isList = (value: unknown): value is string[] => Array.isArray(value) && value.length > 0 && value.every((item) => typeof item === "string"); const axes = raw as { contextWindow?: unknown; inputModalities?: unknown; reasoningEfforts?: unknown }; const out: MemberInferred = { ...(axis(axes.contextWindow, isTokens) ? { context: axis(axes.contextWindow, isTokens)! } : {}), ...(axis(axes.inputModalities, isList) ? { input: axis(axes.inputModalities, isList)! } : {}), ...(axis(axes.reasoningEfforts, isList) ? { efforts: axis(axes.reasoningEfforts, isList)! } : {}), }; return Object.keys(out).length > 0 ? out : undefined; } /** * Members with estimates filled into the gaps, for the combo's combined row only. `used` says * whether any estimate went in, so the combined values can be labelled as including one. */ export function withInferredGaps(members: readonly MemberFacts[]): { members: MemberFacts[]; used: boolean } { let used = false; const filled = members.map((member) => { const next: MemberFacts = { ...member }; if (next.contextWindow === undefined && member.inferred?.context) { next.contextWindow = member.inferred.context.value; used = true; } if (next.inputModalities === undefined && member.inferred?.input) { next.inputModalities = member.inferred.input.value; used = true; } if (next.reasoningEfforts === undefined && member.inferred?.efforts) { next.reasoningEfforts = member.inferred.efforts.value; used = true; } return next; }); return { members: filled, used }; } /** What `POST /api/providers/probe-capabilities` answered, reduced to what the table shows. */ export type ProbeOutcome = | { kind: "confirm"; planned: number } | { kind: "inapplicable"; reason: string } | { kind: "busy" } | { kind: "failed" } | { kind: "done"; baselineOk: boolean; image?: "accepted" | "rejected" | "inconclusive"; accepted: string[]; rejected: string[]; inconclusive: string[]; applied: { inputModalities?: string[]; reasoningEfforts?: string[] }; }; export function parseProbeResponse(status: number, body: unknown): ProbeOutcome { if (status === 409) return { kind: "busy" }; if (status < 200 || status >= 300 || !body || typeof body !== "object") return { kind: "failed" }; const raw = body as Record; if (raw.applicable === false) return { kind: "inapplicable", reason: typeof raw.reason === "string" ? raw.reason : "unknown" }; if (raw.requiresConfirmation === true) { return { kind: "confirm", planned: typeof raw.plannedRequests === "number" && raw.plannedRequests > 0 ? raw.plannedRequests : 1 }; } if (raw.sent !== true || !raw.baseline || typeof raw.baseline !== "object") return { kind: "failed" }; const list = (value: unknown) => Array.isArray(value) ? value.filter((item): item is string => typeof item === "string") : []; const reasoning = (raw.reasoning ?? {}) as Record; const imageStatus = (raw.image as { status?: unknown } | undefined)?.status; const applied = (raw.applied ?? {}) as Record; return { kind: "done", baselineOk: (raw.baseline as { status?: unknown }).status === "accepted", ...(imageStatus === "accepted" || imageStatus === "rejected" || imageStatus === "inconclusive" ? { image: imageStatus } : {}), accepted: list(reasoning.accepted), rejected: list(reasoning.rejected), inconclusive: list(reasoning.inconclusive), applied: { ...(Array.isArray(applied.inputModalities) ? { inputModalities: list(applied.inputModalities) } : {}), ...(Array.isArray(applied.reasoningEfforts) ? { reasoningEfforts: list(applied.reasoningEfforts) } : {}), }, }; } export interface MemberSources { context: CapabilitySource; input: CapabilitySource; efforts: CapabilitySource; } export interface MemberFacts { contextWindow?: number; inputModalities?: readonly string[]; reasoningEfforts?: readonly string[]; sources?: MemberSources; inferred?: MemberInferred; } /** * Source of one capability field on a `/api/models` row. A manual flag wins; an explicit * `inferred` source (the T4c backend names it) comes next; any other present value is the * provider's report. */ export function capabilitySource(hasValue: boolean, manual: boolean, declaredSource?: unknown): CapabilitySource { if (manual) return "manual"; if (declaredSource === "inferred") return "inferred"; return hasValue ? "reported" : "unknown"; } /** * Members the catalog has no row for (a provider whose model list was never fetched) still have * whatever the operator set per model in config. Those values are manual by definition. */ export function configuredMemberModels(providers: Readonly>): MemberModel[] { const out = new Map(); const strings = (value: unknown) => Array.isArray(value) ? value.filter((v): v is string => typeof v === "string") : undefined; const entry = (provider: string, id: string) => { const key = channelKey(provider, id); const found = out.get(key) ?? { provider, id, sources: { context: "unknown", input: "unknown", efforts: "unknown" } }; out.set(key, found); return found as MemberModel & { sources: MemberSources }; }; for (const [provider, raw] of Object.entries(providers)) { if (!raw || typeof raw !== "object") continue; const config = raw as { modelContextWindows?: unknown; modelReasoningEfforts?: unknown; modelCapabilities?: unknown }; for (const [id, tokens] of Object.entries((config.modelContextWindows ?? {}) as Record)) { if (typeof tokens !== "number" || tokens <= 0) continue; const member = entry(provider, id); member.contextWindow = tokens; member.sources.context = "manual"; } for (const [id, ladder] of Object.entries((config.modelReasoningEfforts ?? {}) as Record)) { const list = strings(ladder); if (!list) continue; const member = entry(provider, id); member.reasoningEfforts = list; member.sources.efforts = "manual"; } for (const [id, capabilities] of Object.entries((config.modelCapabilities ?? {}) as Record)) { const list = strings((capabilities as { inputModalities?: unknown } | null)?.inputModalities); if (!list) continue; const member = entry(provider, id); member.inputModalities = list; member.sources.input = "manual"; } } return [...out.values()]; } /** Context typed by an operator: "200000", "200K", "1M", "1.5m". Undefined when it is not a positive whole token count. */ export function parseContextInput(text: string): number | undefined { const match = /^\s*(\d+(?:\.\d+)?)\s*([km]?)\s*$/i.exec(text.replace(/[,_]/g, "")); if (!match) return undefined; const unit = match[2]!.toLowerCase(); const tokens = Math.round(Number(match[1]) * (unit === "m" ? 1_000_000 : unit === "k" ? 1_000 : 1)); return Number.isSafeInteger(tokens) && tokens > 0 ? tokens : undefined; } export interface MemberDraft { context: string; input: readonly string[]; efforts: readonly string[]; } /** Only the fields the operator changed, in the shape `PUT /api/model-settings` takes. */ export function memberSettingsPatch(current: MemberFacts, draft: MemberDraft, order: readonly string[]): { patch: Record; invalid?: "context" } { const patch: Record = {}; const contextText = draft.context.trim(); if (contextText) { const tokens = parseContextInput(contextText); if (tokens === undefined) return { patch, invalid: "context" }; if (tokens !== current.contextWindow) patch.contextWindow = tokens; } const same = (a: readonly string[] | undefined, b: readonly string[]) => (a ?? []).length === b.length && b.every((value) => (a ?? []).includes(value)); if (!same(current.inputModalities, draft.input)) patch.inputModalities = [...draft.input]; if (!same(current.reasoningEfforts, draft.efforts)) { patch.reasoningEfforts = order.filter((level) => draft.efforts.includes(level)); } return { patch }; } /** Clears every per-model setting the operator made, so the provider's own values apply again. */ export function memberRestorePatch(sources: MemberSources | undefined): Record { const declared = (source: CapabilitySource | undefined) => source === "manual" || source === "probed"; return { ...(declared(sources?.context) ? { contextWindow: null } : {}), ...(declared(sources?.input) ? { inputModalities: null } : {}), ...(declared(sources?.efforts) ? { reasoningEfforts: null } : {}), }; } export interface MemberModel extends MemberFacts { provider: string; id: string; } export type ContextBasis = "min" | "max" | "catalog"; /** * The combo's context window as the policy advertises it. Intersection is the server's own catalog * number (it already takes the smallest member and applies context caps the member rows do not * show); only without one does it fall back to the smallest member here. Union takes the largest * member (union over context lands with the T4c backend). */ export function comboContextWindow( members: readonly MemberFacts[], policy: CapabilityPolicy, catalog: number | undefined, ): { tokens?: number; basis: ContextBasis } { const known = members.flatMap((member) => typeof member.contextWindow === "number" && member.contextWindow > 0 ? [member.contextWindow] : []); if (policy === "union" && known.length > 0) return { tokens: Math.max(...known, catalog ?? 0), basis: "max" }; if (policy === "intersection" && catalog !== undefined) return { tokens: catalog, basis: "min" }; if (known.length > 0) return { tokens: Math.min(...known), basis: "min" }; return catalog !== undefined ? { tokens: catalog, basis: "catalog" } : { basis: "catalog" }; } /** Combined list under the policy: every member's (intersection) or any member's (union); undefined when no member reports one. */ export function combineLists(lists: ReadonlyArray, policy: CapabilityPolicy, order: readonly string[] = []): string[] | undefined { const known = lists.filter((list): list is readonly string[] => list !== undefined); if (known.length === 0) return undefined; const merged = policy === "union" ? [...new Set(known.flat())] : known.reduce((common, list) => common.filter((value) => list.includes(value)), [...known[0]!]); const rank = (value: string) => { const index = order.indexOf(value); return index < 0 ? order.length : index; }; return merged.sort((a, b) => rank(a) - rank(b)); } export function memberFacts(models: readonly MemberModel[], provider: string, model: string): MemberFacts { return models.find((candidate) => candidate.provider === provider && candidate.id === model) ?? {}; } export interface RouteRow { combo: ComboItem; publicId: string; displayName: string; channels: RouteChannel[]; /** One entry per distinct provider, in first-use order. */ quotas: ProviderQuotaLine[]; contextWindow?: number; contextBasis: ContextBasis; enabled: boolean; lastResortCount: number; } /** Combo capability policy (T4c). Absent on the wire means the default. */ export type CapabilityPolicy = "intersection" | "union"; export type UnservablePolicy = "degrade" | "reject"; export interface ComboCapabilitySettings { capabilityPolicy: CapabilityPolicy; onUnservable: UnservablePolicy; } export const DEFAULT_CAPABILITY_SETTINGS: ComboCapabilitySettings = { capabilityPolicy: "intersection", onUnservable: "degrade" }; export function parseCapabilitySettings(raw: { capabilityPolicy?: unknown; onUnservable?: unknown }): ComboCapabilitySettings { return { capabilityPolicy: raw.capabilityPolicy === "union" ? "union" : "intersection", onUnservable: raw.onUnservable === "reject" ? "reject" : "degrade", }; } /** Fields the inline editor writes besides the targets; each is sent only when changed. */ export type ComboSettingsPatch = Partial & { cooldownWaitPolicy?: "before-last-resort" | null }; /** Only the fields that changed, so a server without them never sees them unless the operator asked. */ export function capabilityPatch(before: ComboCapabilitySettings, after: ComboCapabilitySettings): Partial { return { ...(after.capabilityPolicy !== before.capabilityPolicy ? { capabilityPolicy: after.capabilityPolicy } : {}), ...(after.onUnservable !== before.onUnservable ? { onUnservable: after.onUnservable } : {}), }; } /** Antigravity names its quota pools by family; spell them out like the provider does. */ const QUOTA_FAMILY_NAMES: Readonly> = { gem: "Gemini", cla: "Claude & GPT", argon: "Gemini 4 Argon", }; /** `Cla (Weekly)` → family "Claude & GPT", weekly window; anything else is left alone. */ export function quotaFamilyWindow(label: string): { family: string; weekly: boolean } | null { const match = /^([A-Za-z]+)( \(Weekly\))?$/.exec(label.trim()); const family = match ? QUOTA_FAMILY_NAMES[match[1]!.toLowerCase()] : undefined; return family ? { family, weekly: match![2] !== undefined } : null; } export const ROUTE_BOARD_STRATEGIES: readonly ComboStrategy[] = COMBO_STRATEGIES; export function channelKey(provider: string, model: string): string { return `${provider}\u0000${model}`; } /** Remaining-percent colour: green above 50%, amber from 20% to 50%, red below 20%. */ export function quotaTone(remainingPercent: number): QuotaTone { if (remainingPercent > 50) return "ok"; if (remainingPercent >= 20) return "warn"; return "low"; } const WINDOW_ORDER: TKey[] = ["quota.weeklyLimit", "quota.fiveHourLimit", "quota.monthlyLimit"]; function windowFamily(window: QuotaSummaryWindow): string { return (window.label ?? "").toLowerCase().split(/[\s(]/)[0] ?? ""; } /** * The windows that matter for this provider's models in this combo, at most two. * * A provider such as Antigravity reports one window per model family ("Gem", "Cla (Weekly)"). * A Claude channel must not show the Gemini window, so a window that names a family or a model * is kept only when a channel's model belongs to it. */ function pickWindows(windows: QuotaSummaryWindow[], models: readonly string[]): QuotaSummaryWindow[] { const measured = windows.filter((window) => window.percent !== undefined); const lowered = models.map((model) => model.toLowerCase()); const relevant = measured.filter((window) => { if (window.modelId !== undefined) return lowered.includes(window.modelId.toLowerCase()); if (window.labelKey !== undefined) return true; const family = windowFamily(window); return family.length >= 3 && lowered.some((model) => model.startsWith(family)); }); const generic = measured.filter((window) => window.labelKey !== undefined || window.modelId === undefined); const pool = relevant.length > 0 ? relevant : generic; const rank = (window: QuotaSummaryWindow) => { if (window.modelId !== undefined) return -1; const fixed = window.labelKey ? WINDOW_ORDER.indexOf(window.labelKey) : -1; if (fixed >= 0) return fixed; return /week/i.test(window.label ?? "") ? 0.5 : WINDOW_ORDER.length; }; return [...pool].sort((a, b) => rank(a) - rank(b)).slice(0, 2); } function accountCount(aggregation: unknown): AccountCount | undefined { if (!aggregation || typeof aggregation !== "object") return undefined; const { includedAccounts, excludedAccounts, pausedAccounts } = aggregation as Record; if (typeof includedAccounts !== "number") return undefined; const total = includedAccounts + (typeof excludedAccounts === "number" ? excludedAccounts : 0); const paused = typeof pausedAccounts === "number" ? Math.min(pausedAccounts, total) : 0; return { active: total - paused, paused }; } /** `GET /api/oauth/accounts` → active and paused counts; null when the body is not an account list. */ export function accountCountFromList(body: unknown): AccountCount | null { const accounts = body && typeof body === "object" ? (body as { accounts?: unknown }).accounts : undefined; if (!Array.isArray(accounts)) return null; const paused = accounts.filter((account) => (account as { paused?: unknown } | null)?.paused === true).length; return { active: accounts.length - paused, paused }; } /** Parse `/api/provider-quotas` `reports` once per render into provider → windows. */ export function quotaWindowsByProvider( reports: unknown, now = Date.now(), ): Map { const fresh = freshQuotaReportsFromResponse(reports, now); const out = new Map(); for (const row of buildQuotaSummary(fresh, (provider) => provider)) { if (row.passive) continue; const accounts = accountCount(fresh[row.provider]?.aggregation); out.set(row.provider, { windows: row.windows, ...(accounts !== undefined ? { accounts } : {}) }); } return out; } export function channelQuota( provider: RouteBoardProvider | undefined, reported: { windows: QuotaSummaryWindow[]; accounts?: AccountCount } | undefined, models: readonly string[], ): ChannelQuota { const windows = reported ? pickWindows(reported.windows, models) : []; if (windows.length > 0) { return { kind: "windows", windows: windows.map((window) => { const remainingPercent = Math.max(0, Math.min(100, 100 - (window.percent ?? 0))); return { id: window.id, ...(window.labelKey ? { labelKey: window.labelKey } : { label: window.label ?? window.id }), remainingPercent, tone: quotaTone(remainingPercent), }; }), }; } if (provider?.authMode === "key") return { kind: "metered" }; return { kind: "unknown" }; } export function buildRouteRows(input: { combos: readonly ComboItem[]; catalog: Readonly>; lastResort: Readonly>; providers: readonly RouteBoardProvider[]; quotaReports: unknown; /** Per-provider account counts read from the account list, for providers whose quota has no aggregate. */ accountCounts?: Readonly>; models?: readonly MemberModel[]; capability?: Readonly>; now?: number; }): RouteRow[] { const providers = new Map(input.providers.map((provider) => [provider.name, provider])); const reported = quotaWindowsByProvider(input.quotaReports, input.now); const rows = input.combos.map((combo) => { const lastResort = new Set(input.lastResort[combo.id] ?? []); const channels = combo.targets.map((target) => { const key = channelKey(target.provider, target.model); return { key, provider: target.provider, model: target.model, lastResort: lastResort.has(key), providerDisabled: providers.get(target.provider)?.disabled === true, }; }); const quotas: ProviderQuotaLine[] = []; for (const channel of channels) { if (quotas.some((line) => line.provider === channel.provider)) continue; const models = channels.filter((c) => c.provider === channel.provider).map((c) => c.model); const accounts = reported.get(channel.provider)?.accounts ?? input.accountCounts?.[channel.provider]; quotas.push({ provider: channel.provider, quota: channelQuota(providers.get(channel.provider), reported.get(channel.provider), models), ...(accounts !== undefined ? { accounts } : {}), }); } const meta = input.catalog[combo.id]; const policy = input.capability?.[combo.id]?.capabilityPolicy ?? "intersection"; const context = comboContextWindow( channels.map((channel) => memberFacts(input.models ?? [], channel.provider, channel.model)), policy, meta?.contextWindow, ); const publicId = comboPublicModelId(combo.id, combo.alias); return { combo, publicId, displayName: combo.displayName?.trim() || meta?.displayName?.trim() || combo.id, channels, quotas, ...(context.tokens !== undefined ? { contextWindow: context.tokens } : {}), contextBasis: context.basis, enabled: meta ? !meta.disabled : true, lastResortCount: channels.filter((channel) => channel.lastResort).length, }; }); // Switched-off combos go last so the live ones lead; the sort is stable within each group. return [...rows.filter((row) => row.enabled), ...rows.filter((row) => !row.enabled)]; } /** * Provider labels for one row. Two providers can share a display name (`anthropic` and * `anthropic-apikey` are both "Anthropic Claude"); the later one gets its id appended. */ export function distinctProviderLabels( providers: readonly string[], display: (provider: string) => string, ): Map { const labels = new Map(); const taken = new Set(); for (const provider of providers) { if (labels.has(provider)) continue; const name = display(provider); labels.set(provider, taken.has(name) ? `${name} (${provider})` : name); taken.add(name); } return labels; } /** `1M`, `200K`, `128K`. */ export function formatContextWindow(tokens: number): string { if (tokens >= 1_000_000) { const millions = tokens / 1_000_000; return `${Number(millions.toFixed(1))}M`; } return `${Math.round(tokens / 1000)}K`; } /** * What picking a strategy in the row menu does. * * JEV never saves from the row: with no decision service chosen it hands requests to the * hosted TypeSafe JEV service, so the operator picks it in the full editor where that is shown. */ export type StrategyChange = | { kind: "unchanged" } | { kind: "open-advanced" } | { kind: "invalid"; error: ComboDraftError; item: ComboItem } | { kind: "save"; item: ComboItem }; export function planStrategyChange( combo: ComboItem, next: ComboStrategy, validate: (item: ComboItem) => ComboDraftError | null, ): StrategyChange { if (next === combo.strategy) return { kind: "unchanged" }; if (next === "jev") return { kind: "open-advanced" }; const item = { ...combo, strategy: next }; const error = validate(item); return error ? { kind: "invalid", error, item } : { kind: "save", item }; } /** Move one channel; out-of-range moves leave the list as it was. */ export function moveChannel(list: readonly T[], from: number, to: number): T[] { if (from === to || from < 0 || to < 0 || from >= list.length || to >= list.length) return [...list]; const next = [...list]; const [moved] = next.splice(from, 1); next.splice(to, 0, moved!); return next; } /** Pointer must pass a row's midpoint by this much before the drop slot changes. */ export const DRAG_HYSTERESIS_PX = 8; /** * Drop slot for a dragged row, from the pointer's Y against the rows' midpoints as they were when * the drag started. The rows that make room move on screen, but these midpoints do not, so the * slot cannot flip back and forth as rows slide under a still pointer. `current` adds hysteresis: * the slot changes only once the pointer is clearly past the midpoint that separates the two. */ export function dragSlot(startMids: readonly number[], from: number, y: number, current: number): number { const others = startMids.filter((_, index) => index !== from); const slotAt = (pointer: number) => others.filter((mid) => mid < pointer).length; const next = slotAt(y); if (next === current) return current; // Moving down past others[current], or up past others[current - 1]: require the margin. const boundary = next > current ? others[current] : others[current - 1]; if (boundary === undefined) return next; return Math.abs(y - boundary) >= DRAG_HYSTERESIS_PX ? next : current; } /** `PUT /api/combos` target list for an edited channel list: `lastResort` sent explicitly. */ export function channelTargetsForPut( putTargets: readonly T[], channels: readonly Pick[], ): Array { return putTargets.map((target) => { const channel = channels.find((c) => c.provider === target.provider && c.model === target.model); return { ...target, lastResort: channel?.lastResort === true }; }); }