| 1 | import type { ProviderKind } from "@g1t/contracts"; |
| 2 | |
| 3 | /** |
| 4 | * The workspace's integration setup pages, under `-/integrations/<section>`: |
| 5 | * one for each kind of provider connection. The directory at |
| 6 | * `-/integrations` links into them. Model providers have no page: they |
| 7 | * were for g1t's own agents, which are gone. |
| 8 | */ |
| 9 | export type IntegrationsSection = "alerts" | "trackers"; |
| 10 | |
| 11 | /** The kinds of provider that have a setup page. */ |
| 12 | export type SectionKind = Exclude<ProviderKind, "models">; |
| 13 | |
| 14 | const SECTIONS: Record<SectionKind, IntegrationsSection> = { |
| 15 | alerts: "alerts", |
| 16 | tracker: "trackers", |
| 17 | }; |
| 18 | |
| 19 | /** Whether a kind of provider has a setup page. */ |
| 20 | export function hasSection(kind: ProviderKind): kind is SectionKind { |
| 21 | return kind in SECTIONS; |
| 22 | } |
| 23 | |
| 24 | /** The page a kind of provider is set up on, or null when it has none. */ |
| 25 | export function integrationsSection(kind: ProviderKind): IntegrationsSection | null { |
| 26 | return hasSection(kind) ? SECTIONS[kind] : null; |
| 27 | } |
| 28 | |
| 29 | /** The kind of provider a section's page is for, or null when it is no section. */ |
| 30 | export function sectionKind(section: string | undefined): SectionKind | null { |
| 31 | const found = (Object.keys(SECTIONS) as SectionKind[]).find((kind) => SECTIONS[kind] === section); |
| 32 | return found ?? null; |
| 33 | } |