g1t/apps/web/app/routes/workspace/integrations.tsx
Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Integrations: your own model provider, alerts that open issues, tickets agents read | 1 | import { |
| 2 | AlertTriangle, | |
| 3 | CheckCircle2, | |
| 4 | ChevronRight, | |
| 5 | Cpu, | |
| 6 | Siren, | |
| 7 | Ticket, | |
| 8 | X, | |
| 9 | } from "lucide-react"; | |
| Models per workspace: several providers, routed by kind of work | 10 | import { env } from "cloudflare:workers"; |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 11 | import type { ReactNode } from "react"; |
| 12 | import { Form, Link, useNavigation } from "react-router"; | |
| 13 | ||
| 14 | import { | |
| 15 | type Connection, | |
| 16 | type ConnectionConfig, | |
| 17 | type Delivery, | |
| Models per workspace: several providers, routed by kind of work | 18 | MODEL_TASKS, |
| 19 | type ModelRoute, | |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 20 | type Provider, |
| 21 | type ProviderKind, | |
| 22 | PROVIDERS, | |
| 23 | } from "@g1t/contracts"; | |
| 24 | ||
| 25 | import type { Route } from "./+types/integrations"; | |
| Social cards for every page: og.g1t.sh | 26 | import { page } from "../../lib/meta"; |
| A catalogue of model providers, and settings that feel like settings | 27 | import { MODEL_CATALOG, ModelCatalog, ModelProviderFields, ProviderMark, ProviderTiles, Routing } from "../../components/model-providers"; |
| Workspace names and icons, and a component kit for every control | 28 | import { Avatar, Button, CopyLine, ErrorText, Field, Input, TimeAgo } from "../../components/ui"; |
| 29 | import { CheckboxOption } from "../../components/ui/checkbox"; | |
| 30 | import { Combobox } from "../../components/ui/combobox"; | |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 31 | import { billing, integrations, repos } from "../../lib/services.server"; |
| 32 | import { assertSameOrigin, getViewer, requireUser, roleIn, unwrap } from "../../lib/session.server"; | |
| 33 | ||
| Social cards for every page: og.g1t.sh | 34 | export function meta({ params, ...args }: Route.MetaArgs) { |
| 35 | return page(args, { title: `Integrations · ${params.owner} · g1t` }); | |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 36 | } |
| 37 | ||
| 38 | const isProvider = (value: string | null): value is Provider => value != null && value in PROVIDERS; | |
| 39 | ||
| 40 | export async function loader({ params, context, request }: Route.LoaderArgs) { | |
| 41 | const viewer = getViewer(context); | |
| 42 | const role = roleIn(viewer, params.owner); | |
| 43 | if (!role) throw new Response(null, { status: 404 }); | |
| 44 | const slug = params.owner.toLowerCase(); | |
| Models per workspace: several providers, routed by kind of work | 45 | const [connections, listed, account, access, routes] = await Promise.all([ |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 46 | integrations.list(slug, viewer), |
| 47 | repos.list(viewer, { namespace: slug }), | |
| 48 | billing.account(slug, viewer), | |
| Models per workspace: several providers, routed by kind of work | 49 | env.RUNNER.modelAccess(slug), |
| 50 | integrations.routes(slug, viewer), | |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 51 | ]); |
| 52 | const all = unwrap(connections); | |
| 53 | // What each alert source has sent lately, to see it is wired up. | |
| 54 | const deliveries: Record<string, Delivery[]> = {}; | |
| 55 | await Promise.all( | |
| 56 | all | |
| 57 | .filter((connection) => connection.kind === "alerts") | |
| 58 | .map(async (connection) => { | |
| 59 | const found = await integrations.deliveries(slug, viewer, connection.id); | |
| 60 | deliveries[connection.id] = found.ok ? found.value.slice(0, 5) : []; | |
| 61 | }), | |
| 62 | ); | |
| 63 | const adding = new URL(request.url).searchParams.get("add"); | |
| 64 | return { | |
| 65 | slug, | |
| 66 | role, | |
| 67 | connections: all, | |
| 68 | deliveries, | |
| 69 | repos: listed.map((repo) => `${repo.namespace}/${repo.name}`), | |
| 70 | adding: isProvider(adding) ? adding : null, | |
| Models per workspace: several providers, routed by kind of work | 71 | hostedOpen: access.hosted, |
| A free allowance on g1t's models, so anyone can try its agents | 72 | trial: access.trial, |
| Models per workspace: several providers, routed by kind of work | 73 | routes: routes.ok ? routes.value : [], |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 74 | feeMicros: account.ok ? account.value.orchestrationFeeMicros : 100_000, |
| New workspaces are told to connect a model, before anything fails | 75 | free: account.ok ? Boolean(account.value.status.free) : false, |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 76 | marginPercent: account.ok ? account.value.marginPercent : 20, |
| 77 | }; | |
| 78 | } | |
| 79 | ||
| 80 | function text(form: FormData, name: string): string | undefined { | |
| 81 | const value = String(form.get(name) ?? "").trim(); | |
| 82 | return value || undefined; | |
| 83 | } | |
| 84 | ||
| 85 | /** The settings a form describes, for the provider it is for. */ | |
| 86 | function configFrom(form: FormData): ConnectionConfig { | |
| 87 | const keys = text(form, "keys"); | |
| 88 | return { | |
| 89 | repo: text(form, "repo"), | |
| 90 | assign: form.get("assign") === "on", | |
| 91 | label: text(form, "label"), | |
| 92 | writeBack: form.get("writeBack") !== "off", | |
| 93 | organization: text(form, "organization"), | |
| 94 | site: text(form, "site"), | |
| 95 | email: text(form, "email"), | |
| 96 | keys: keys ? keys.split(/[\s,]+/).filter(Boolean) : [], | |
| 97 | baseUrl: text(form, "baseUrl"), | |
| 98 | authHeader: text(form, "authHeader"), | |
| 99 | model: text(form, "model"), | |
| 100 | }; | |
| 101 | } | |
| 102 | ||
| 103 | export async function action({ request, params, context }: Route.ActionArgs) { | |
| 104 | assertSameOrigin(request); | |
| 105 | const user = requireUser(context, request); | |
| 106 | const slug = params.owner.toLowerCase(); | |
| 107 | const form = await request.formData(); | |
| 108 | const intent = form.get("intent"); | |
| 109 | const id = String(form.get("id") ?? ""); | |
| 110 | if (intent === "disconnect") { | |
| 111 | const removed = await integrations.disconnect(user, slug, id); | |
| 112 | return { error: removed.ok ? null : removed.error.message }; | |
| 113 | } | |
| 114 | if (intent === "test") { | |
| 115 | const tested = await integrations.test(user, slug, id); | |
| 116 | return tested.ok ? { tested: { id, ...tested.value } } : { error: tested.error.message }; | |
| 117 | } | |
| Models per workspace: several providers, routed by kind of work | 118 | if (intent === "routes") { |
| 119 | const routes: ModelRoute[] = []; | |
| 120 | for (const task of MODEL_TASKS) { | |
| 121 | const choice = String(form.get(`route-${task}`) ?? ""); | |
| 122 | if (!choice) continue; | |
| 123 | if (choice === "g1t") routes.push({ task, connectionId: null, model: null }); | |
| 124 | else { | |
| 125 | const [connectionId, model] = choice.split("::"); | |
| 126 | routes.push({ task, connectionId, model: model || null }); | |
| 127 | } | |
| 128 | } | |
| 129 | const saved = await integrations.setRoutes(user, slug, routes); | |
| 130 | return saved.ok ? { routed: true } : { error: saved.error.message }; | |
| 131 | } | |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 132 | if (intent === "update") { |
| 133 | const updated = await integrations.update(user, slug, id, { | |
| 134 | signingSecret: text(form, "signingSecret"), | |
| 135 | secret: text(form, "secret"), | |
| 136 | }); | |
| 137 | return { error: updated.ok ? null : updated.error.message }; | |
| 138 | } | |
| 139 | const provider = String(form.get("provider") ?? ""); | |
| 140 | if (!isProvider(provider)) return { error: "Choose what to connect." }; | |
| 141 | const connected = await integrations.connect(user, slug, { | |
| 142 | provider, | |
| 143 | name: text(form, "name"), | |
| 144 | config: configFrom(form), | |
| 145 | secret: text(form, "secret"), | |
| 146 | signingSecret: text(form, "signingSecret"), | |
| 147 | }); | |
| 148 | return connected.ok ? { connected: connected.value } : { error: connected.error.message, provider }; | |
| 149 | } | |
| 150 | ||
| 151 | const KIND_INFO: Record<ProviderKind, { title: string; icon: ReactNode; blurb: string }> = { | |
| 152 | models: { | |
| Model providers: gateway tokens for endpoints, tidier rows, and the docs | 153 | title: "Model providers", |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 154 | icon: <Cpu size={16} />, |
| Model providers: gateway tokens for endpoints, tidier rows, and the docs | 155 | blurb: "Connect as many as you use, then choose which model does which work, and so who pays for it.", |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 156 | }, |
| 157 | alerts: { | |
| 158 | title: "Alerts", | |
| 159 | icon: <Siren size={16} />, | |
| 160 | blurb: "Problems your monitoring finds become issues, and agents can start on them before anyone looks.", | |
| 161 | }, | |
| 162 | tracker: { | |
| 163 | title: "Trackers", | |
| 164 | icon: <Ticket size={16} />, | |
| 165 | blurb: "Tickets agents can read when work mentions them, that people can import as issues, and that hear back when the work lands.", | |
| 166 | }, | |
| 167 | }; | |
| 168 | ||
| A catalogue of model providers, and settings that feel like settings | 169 | const PROVIDER_BLURB: Partial<Record<Provider, string>> = { |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 170 | sentry: "New errors open issues, with the stack trace. Resolved in Sentry when the fix merges.", |
| 171 | datadog: "Monitors that trigger open issues. Recoveries are noted on them.", | |
| 172 | webhook: "Anything that can send signed JSON: PagerDuty, Grafana, your own scripts.", | |
| 173 | jira: "Agents read TECH-1234 when work mentions it. Import tickets; they hear back.", | |
| 174 | linear: "Agents read ENG-42 when work mentions it. Import issues; they hear back.", | |
| 175 | }; | |
| 176 | ||
| 177 | function dollars(micros: number): string { | |
| 178 | return `$${(micros / 1_000_000).toFixed(2)}`; | |
| 179 | } | |
| 180 | ||
| 181 | export default function WorkspaceIntegrations({ loaderData, actionData }: Route.ComponentProps) { | |
| A free allowance on g1t's models, so anyone can try its agents | 182 | const { slug, role, connections, deliveries, repos: repoNames, adding, feeMicros, free, marginPercent, hostedOpen, trial, routes } = |
| Models per workspace: several providers, routed by kind of work | 183 | loaderData; |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 184 | const owner = role === "owner"; |
| 185 | const busy = useNavigation().state === "submitting"; | |
| Models per workspace: several providers, routed by kind of work | 186 | const modelConnections = connections.filter((connection) => connection.kind === "models"); |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 187 | const justConnected = actionData && "connected" in actionData ? actionData.connected : null; |
| 188 | const tested = (actionData && "tested" in actionData ? actionData.tested : null) ?? null; | |
| 189 | const error = (actionData && "error" in actionData ? actionData.error : null) ?? null; | |
| 190 | ||
| 191 | return ( | |
| A catalogue of model providers, and settings that feel like settings | 192 | <div> |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 193 | {justConnected && <Connected connected={justConnected} />} |
| 194 | <div className="mt-4"> | |
| 195 | <ErrorText>{error}</ErrorText> | |
| 196 | </div> | |
| 197 | ||
| 198 | {/* Models -------------------------------------------------------------- */} | |
| A catalogue of model providers, and settings that feel like settings | 199 | <Section kind="models" first> |
| Models per workspace: several providers, routed by kind of work | 200 | {!hostedOpen && modelConnections.length === 0 && ( |
| 201 | <div className="mb-4 flex items-center gap-3 rounded-xl border border-warn/30 bg-warn/5 p-4"> | |
| 202 | <span className="inline-flex size-8 shrink-0 items-center justify-center rounded-lg bg-warn/10 text-warn ring-1 ring-warn/30"> | |
| 203 | <AlertTriangle size={16} /> | |
| 204 | </span> | |
| 205 | <p className="text-sm text-muted"> | |
| A free allowance on g1t's models, so anyone can try its agents | 206 | <span className="font-medium text-fg">Choose how your agents reach a model.</span>{" "} |
| 207 | {trial?.reason === "used" | |
| 208 | ? `${slug} has used its free allowance on g1t's models.` | |
| 209 | : trial?.reason === "pool" || trial?.reason === "ended" | |
| 210 | ? "The free allowance on g1t's models has ended." | |
| 211 | : `g1t's hosted models are not open to ${slug}.`}{" "} | |
| 212 | Connect a provider of your own below and your agents start at once, billed by that provider. | |
| Models per workspace: several providers, routed by kind of work | 213 | </p> |
| 214 | </div> | |
| 215 | )} | |
| 216 | <Connections list={modelConnections} owner={owner} busy={busy} tested={tested} deliveries={deliveries} /> | |
| A catalogue of model providers, and settings that feel like settings | 217 | {modelConnections.length === 0 && hostedOpen && ( |
| 218 | <p className="flex items-center gap-2 rounded-xl border border-line bg-surface px-4 py-3 text-sm text-muted"> | |
| 219 | <CheckCircle2 size={15} className="shrink-0 text-merged" /> | |
| A free allowance on g1t's models, so anyone can try its agents | 220 | {trial?.open |
| 221 | ? `All work runs on g1t's models, free: ${slug} has ${dollars(Math.max(0, trial.limitMicros - trial.usedMicros))} of its ${dollars(trial.limitMicros)} allowance left${trial.endsAt ? `, until ${new Date(trial.endsAt).toLocaleDateString("en-US", { month: "long", day: "numeric", timeZone: "America/Los_Angeles" })}` : ""}. Connect a provider of your own for more, or to choose models.` | |
| 222 | : free | |
| 223 | ? "All work runs on g1t's models, free while g1t is being built out. Connect a provider of your own to choose models and pay for them there." | |
| 224 | : `All work runs on g1t's models, charged to your credit at cost plus ${marginPercent}%. Connect a provider of your own to choose models and pay for them there.`} | |
| A catalogue of model providers, and settings that feel like settings | 225 | </p> |
| 226 | )} | |
| 227 | {modelConnections.length > 0 && ( | |
| Models per workspace: several providers, routed by kind of work | 228 | <Routing |
| 229 | connections={modelConnections} | |
| 230 | routes={routes} | |
| 231 | hostedOpen={hostedOpen} | |
| 232 | marginPercent={marginPercent} | |
| 233 | owner={owner} | |
| 234 | busy={busy} | |
| 235 | saved={actionData != null && "routed" in actionData} | |
| 236 | /> | |
| A catalogue of model providers, and settings that feel like settings | 237 | )} |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 238 | <p className="mt-3 text-xs text-faint"> |
| New workspaces are told to connect a model, before anything fails | 239 | On your own providers, their bills are yours.{" "} |
| 240 | {free | |
| 241 | ? `g1t charges nothing while it is being built out; once pricing starts, ${dollars(feeMicros)} a run for the sandbox and orchestration.` | |
| 242 | : `g1t charges ${dollars(feeMicros)} a run for the sandbox and orchestration.`}{" "} | |
| 243 | Keys go only from g1t's model proxy to the provider: the agent's | |
| Models per workspace: several providers, routed by kind of work | 244 | sandbox holds a token that dies with the run. |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 245 | </p> |
| A catalogue of model providers, and settings that feel like settings | 246 | {owner && <ModelCatalog slug={slug} adding={adding} />} |
| Integrations: connect forms open under the tile that was chosen | 247 | {adding && PROVIDERS[adding].kind === "models" && owner && ( |
| 248 | <AddForm | |
| 249 | provider={adding} | |
| 250 | slug={slug} | |
| 251 | repos={repoNames} | |
| 252 | busy={busy} | |
| 253 | error={actionData && "provider" in actionData ? error : null} | |
| 254 | /> | |
| 255 | )} | |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 256 | </Section> |
| 257 | ||
| 258 | {/* Alerts -------------------------------------------------------------- */} | |
| 259 | <Section kind="alerts"> | |
| 260 | <Connections | |
| 261 | list={connections.filter((c) => c.kind === "alerts")} | |
| 262 | owner={owner} | |
| 263 | busy={busy} | |
| 264 | tested={tested} | |
| 265 | deliveries={deliveries} | |
| 266 | /> | |
| 267 | {owner && <Choices kind="alerts" slug={slug} adding={adding} />} | |
| Integrations: connect forms open under the tile that was chosen | 268 | {adding && PROVIDERS[adding].kind === "alerts" && owner && ( |
| 269 | <AddForm | |
| 270 | provider={adding} | |
| 271 | slug={slug} | |
| 272 | repos={repoNames} | |
| 273 | busy={busy} | |
| 274 | error={actionData && "provider" in actionData ? error : null} | |
| 275 | /> | |
| 276 | )} | |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 277 | </Section> |
| 278 | ||
| 279 | {/* Trackers ------------------------------------------------------------ */} | |
| 280 | <Section kind="tracker"> | |
| 281 | <Connections | |
| 282 | list={connections.filter((c) => c.kind === "tracker")} | |
| 283 | owner={owner} | |
| 284 | busy={busy} | |
| 285 | tested={tested} | |
| 286 | deliveries={deliveries} | |
| 287 | /> | |
| 288 | {owner && <Choices kind="tracker" slug={slug} adding={adding} />} | |
| Integrations: connect forms open under the tile that was chosen | 289 | {adding && PROVIDERS[adding].kind === "tracker" && owner && ( |
| 290 | <AddForm | |
| 291 | provider={adding} | |
| 292 | slug={slug} | |
| 293 | repos={repoNames} | |
| 294 | busy={busy} | |
| 295 | error={actionData && "provider" in actionData ? error : null} | |
| 296 | /> | |
| 297 | )} | |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 298 | </Section> |
| 299 | ||
| 300 | {!owner && <p className="mt-8 text-sm text-muted">An owner of {slug} can add and remove integrations.</p>} | |
| 301 | </div> | |
| 302 | ); | |
| Models per workspace: several providers, routed by kind of work | 303 | } |
| 304 | ||
| A catalogue of model providers, and settings that feel like settings | 305 | function Section({ kind, first, children }: { kind: ProviderKind; first?: boolean; children: ReactNode }) { |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 306 | const info = KIND_INFO[kind]; |
| 307 | return ( | |
| A catalogue of model providers, and settings that feel like settings | 308 | <section className={first ? "" : "mt-12"}> |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 309 | <h3 className="flex items-center gap-2 text-sm font-medium"> |
| 310 | <span className="text-muted">{info.icon}</span> | |
| 311 | {info.title} | |
| 312 | </h3> | |
| 313 | <p className="mt-1 mb-4 text-sm text-muted">{info.blurb}</p> | |
| 314 | {children} | |
| 315 | </section> | |
| 316 | ); | |
| 317 | } | |
| 318 | ||
| 319 | function Connections({ | |
| 320 | list, | |
| 321 | owner, | |
| 322 | busy, | |
| 323 | tested, | |
| 324 | deliveries, | |
| 325 | }: { | |
| 326 | list: Connection[]; | |
| 327 | owner: boolean; | |
| 328 | busy: boolean; | |
| 329 | tested: { id: string; ok: boolean; message: string } | null; | |
| 330 | deliveries: Record<string, Delivery[]>; | |
| 331 | }) { | |
| 332 | if (list.length === 0) return null; | |
| 333 | return ( | |
| 334 | <ul className="mb-4 divide-y divide-line overflow-hidden rounded-xl border border-line bg-surface"> | |
| 335 | {list.map((connection) => ( | |
| 336 | <li key={connection.id} className="p-4"> | |
| 337 | <ConnectionRow | |
| 338 | connection={connection} | |
| 339 | owner={owner} | |
| 340 | busy={busy} | |
| 341 | tested={tested} | |
| 342 | deliveries={deliveries[connection.id] ?? []} | |
| 343 | /> | |
| 344 | </li> | |
| 345 | ))} | |
| 346 | </ul> | |
| 347 | ); | |
| 348 | } | |
| 349 | ||
| Model providers: gateway tokens for endpoints, tidier rows, and the docs | 350 | /** Just the host of an address, which is what tells connections apart. */ |
| 351 | function host(url: string | undefined): string | undefined { | |
| 352 | if (!url) return undefined; | |
| 353 | try { | |
| 354 | return new URL(url).host; | |
| 355 | } catch { | |
| 356 | return url; | |
| 357 | } | |
| 358 | } | |
| 359 | ||
| Integrations: your own model provider, alerts that open issues, tickets agents read | 360 | function ConnectionRow({ |
| 361 | connection, | |
| 362 | owner, | |
| 363 | busy, | |
| 364 | tested, | |
| 365 | deliveries, | |
| 366 | }: { | |
| 367 | connection: Connection; | |
| 368 | owner: boolean; | |
| 369 | busy: boolean; | |
| 370 | tested: { id: string; ok: boolean; message: string } | null; | |
| 371 | deliveries: Delivery[]; | |
| 372 | }) { | |
| 373 | const { config } = connection; | |
| 374 | const facts = [ | |
| 375 | PROVIDERS[connection.provider].label, | |
| 376 | config.repo && `issues in ${config.repo}`, | |
| 377 | config.assign && "agents start at once", | |
| 378 | config.organization, | |
| Model providers: gateway tokens for endpoints, tidier rows, and the docs | 379 | host(config.site), |
| 380 | host(config.baseUrl), | |
| Models per workspace: several providers, routed by kind of work | 381 | config.model && `default ${config.model}`, |
| 382 | connection.models.length > 0 && `${connection.models.length} models`, | |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 383 | config.keys?.length ? config.keys.join(", ") : null, |
| 384 | connection.secretHint && `key ${connection.secretHint}`, | |
| 385 | ].filter(Boolean); | |
| 386 | const waitingForSecret = connection.provider === "sentry" && !deliveries.length && !connection.lastUsedAt; | |
| 387 | return ( | |
| 388 | <div> | |
| Model providers: gateway tokens for endpoints, tidier rows, and the docs | 389 | <div className="flex items-center gap-3"> |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 390 | <ProviderMark provider={connection.provider} /> |
| 391 | <div className="min-w-0 grow"> | |
| 392 | <p className="truncate text-sm font-medium">{connection.name}</p> | |
| 393 | <p className="truncate text-xs text-muted">{facts.join(" · ")}</p> | |
| 394 | </div> | |
| 395 | {connection.lastUsedAt && ( | |
| Model providers: gateway tokens for endpoints, tidier rows, and the docs | 396 | <span className="hidden shrink-0 text-xs text-faint sm:inline"> |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 397 | Used <TimeAgo at={connection.lastUsedAt} /> |
| 398 | </span> | |
| 399 | )} | |
| 400 | {owner && ( | |
| Model providers: gateway tokens for endpoints, tidier rows, and the docs | 401 | <Form method="post" className="flex shrink-0 gap-2"> |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 402 | <input type="hidden" name="id" value={connection.id} /> |
| 403 | <Button variant="quiet" type="submit" name="intent" value="test" disabled={busy}> | |
| 404 | Test | |
| 405 | </Button> | |
| 406 | <Button variant="quiet" type="submit" name="intent" value="disconnect" disabled={busy} aria-label="Disconnect"> | |
| 407 | <X size={14} /> | |
| 408 | </Button> | |
| 409 | </Form> | |
| 410 | )} | |
| 411 | </div> | |
| 412 | {tested?.id === connection.id && ( | |
| 413 | <p className={`mt-3 text-sm ${tested.ok ? "text-accent" : "text-danger"}`}>{tested.message}</p> | |
| 414 | )} | |
| 415 | {connection.lastError && ( | |
| 416 | <p className="mt-3 flex items-start gap-2 text-xs text-warn"> | |
| 417 | <AlertTriangle size={13} className="mt-0.5 shrink-0" /> | |
| 418 | {connection.lastError} | |
| 419 | </p> | |
| 420 | )} | |
| 421 | {connection.webhookUrl && ( | |
| 422 | <div className="mt-3"> | |
| 423 | <p className="mb-1.5 text-xs text-faint">Where it sends alerts</p> | |
| 424 | <CopyLine text={connection.webhookUrl} /> | |
| 425 | </div> | |
| 426 | )} | |
| 427 | {owner && waitingForSecret && ( | |
| 428 | <Form method="post" className="mt-3 flex flex-wrap items-end gap-2"> | |
| 429 | <input type="hidden" name="intent" value="update" /> | |
| 430 | <input type="hidden" name="id" value={connection.id} /> | |
| 431 | <div className="min-w-64 grow"> | |
| 432 | <Field label="Client secret" hint="From the internal integration's page in Sentry, once it has this address. Leave it if it is already saved."> | |
| 433 | <Input name="signingSecret" type="password" placeholder="Paste to replace" /> | |
| 434 | </Field> | |
| 435 | </div> | |
| 436 | <Button type="submit" variant="quiet" disabled={busy}> | |
| 437 | Save | |
| 438 | </Button> | |
| 439 | </Form> | |
| 440 | )} | |
| 441 | {deliveries.length > 0 && ( | |
| 442 | <ul className="mt-3 space-y-1 text-xs"> | |
| 443 | {deliveries.map((delivery) => ( | |
| 444 | <li key={delivery.id} className="flex items-center gap-2 text-muted"> | |
| 445 | <span | |
| 446 | className={`size-1.5 shrink-0 rounded-full ${ | |
| 447 | delivery.outcome === "refused" | |
| 448 | ? "bg-danger" | |
| 449 | : delivery.outcome === "ignored" | |
| 450 | ? "bg-faint" | |
| 451 | : "bg-accent" | |
| 452 | }`} | |
| 453 | /> | |
| 454 | <span className="font-mono text-faint">{delivery.event}</span> | |
| 455 | <span className="min-w-0 truncate">{delivery.detail}</span> | |
| 456 | {delivery.issue && ( | |
| 457 | <Link | |
| 458 | to={`/${delivery.issue.replace("#", "/issues/")}`} | |
| 459 | className="shrink-0 font-mono text-fg hover:underline" | |
| 460 | > | |
| 461 | {delivery.issue} | |
| 462 | </Link> | |
| 463 | )} | |
| 464 | <span className="ml-auto shrink-0 text-faint"> | |
| 465 | <TimeAgo at={delivery.receivedAt} /> | |
| 466 | </span> | |
| 467 | </li> | |
| 468 | ))} | |
| 469 | </ul> | |
| 470 | )} | |
| 471 | </div> | |
| 472 | ); | |
| 473 | } | |
| 474 | ||
| A catalogue of model providers, and settings that feel like settings | 475 | /** What a provider is for, in a line. */ |
| 476 | function blurb(provider: Provider): string { | |
| 477 | return PROVIDER_BLURB[provider] ?? MODEL_CATALOG[provider]?.blurb ?? ""; | |
| 478 | } | |
| 479 | ||
| Integrations: your own model provider, alerts that open issues, tickets agents read | 480 | function Choices({ kind, slug, adding }: { kind: ProviderKind; slug: string; adding: Provider | null }) { |
| 481 | const providers = (Object.keys(PROVIDERS) as Provider[]).filter((p) => PROVIDERS[p].kind === kind); | |
| 482 | return ( | |
| A catalogue of model providers, and settings that feel like settings | 483 | <div className="mt-3"> |
| 484 | <ProviderTiles providers={providers} slug={slug} adding={adding} blurb={blurb} /> | |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 485 | </div> |
| 486 | ); | |
| 487 | } | |
| 488 | ||
| 489 | function RepoField({ repos, required, hint }: { repos: string[]; required?: boolean; hint: string }) { | |
| 490 | return ( | |
| 491 | <Field label="Repository" hint={hint}> | |
| Workspace names and icons, and a component kit for every control | 492 | <Combobox |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 493 | name="repo" |
| 494 | defaultValue={repos[0] ?? ""} | |
| Workspace names and icons, and a component kit for every control | 495 | aria-label="Repository" |
| 496 | placeholder={repos.length === 0 ? "No repositories yet" : "Choose a repository"} | |
| 497 | searchPlaceholder="Find a repository" | |
| 498 | emptyText="No repository by that name." | |
| 499 | options={[ | |
| 500 | ...(required ? [] : [{ value: "", label: "None" }]), | |
| 501 | ...repos.map((repo) => ({ value: repo, label: repo, icon: <Avatar name={repo.split("/").pop() ?? repo} size={16} square /> })), | |
| 502 | ]} | |
| 503 | className="font-mono text-[0.8125rem]" | |
| 504 | /> | |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 505 | </Field> |
| 506 | ); | |
| 507 | } | |
| 508 | ||
| 509 | function AssignField() { | |
| 510 | return ( | |
| Workspace names and icons, and a component kit for every control | 511 | <CheckboxOption |
| 512 | name="assign" | |
| 513 | label={<span className="font-medium">Put a g1t agent on each new issue</span>} | |
| 514 | description={ | |
| 515 | <span className="text-muted"> | |
| 516 | It opens a pull request, gets reviewed, and lands through your merge rules, before anyone has to look. | |
| 517 | Agents run only where g1t agents are enabled. | |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 518 | </span> |
| Workspace names and icons, and a component kit for every control | 519 | } |
| 520 | /> | |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 521 | ); |
| 522 | } | |
| 523 | ||
| 524 | function AddForm({ | |
| 525 | provider, | |
| 526 | slug, | |
| 527 | repos, | |
| 528 | busy, | |
| 529 | error, | |
| 530 | }: { | |
| 531 | provider: Provider; | |
| 532 | slug: string; | |
| 533 | repos: string[]; | |
| 534 | busy: boolean; | |
| 535 | error: string | null; | |
| 536 | }) { | |
| A catalogue of model providers, and settings that feel like settings | 537 | const fields: Partial<Record<Provider, ReactNode>> = { |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 538 | sentry: ( |
| 539 | <> | |
| 540 | <Field label="Organization" hint="Its slug, as in acme.sentry.io."> | |
| 541 | <Input name="organization" required placeholder="acme" /> | |
| 542 | </Field> | |
| 543 | <RepoField repos={repos} required hint="Where issues are opened." /> | |
| 544 | <Field label="Auth token" hint="The internal integration's token, with Issue & Event read and write. Lets g1t read stack traces and resolve issues. Optional, but recommended."> | |
| 545 | <Input name="secret" type="password" /> | |
| 546 | </Field> | |
| 547 | <Field label="Client secret" hint="You get this from Sentry after giving it this connection's address; you can add it on the next step."> | |
| 548 | <Input name="signingSecret" type="password" /> | |
| 549 | </Field> | |
| 550 | <AssignField /> | |
| 551 | </> | |
| 552 | ), | |
| 553 | datadog: ( | |
| 554 | <> | |
| 555 | <RepoField repos={repos} required hint="Where issues are opened." /> | |
| 556 | <AssignField /> | |
| 557 | </> | |
| 558 | ), | |
| 559 | webhook: ( | |
| 560 | <> | |
| 561 | <RepoField repos={repos} required hint="Where issues are opened." /> | |
| 562 | <AssignField /> | |
| 563 | </> | |
| 564 | ), | |
| 565 | jira: ( | |
| 566 | <> | |
| 567 | <Field label="Site" hint="Your Jira's address."> | |
| 568 | <Input name="site" type="url" required placeholder="https://acme.atlassian.net" /> | |
| 569 | </Field> | |
| 570 | <Field label="Email" hint="The account the API token belongs to."> | |
| 571 | <Input name="email" type="email" required autoComplete="off" /> | |
| 572 | </Field> | |
| 573 | <Field label="API token" hint="From id.atlassian.com → Security → API tokens."> | |
| 574 | <Input name="secret" type="password" required /> | |
| 575 | </Field> | |
| 576 | <Field label="Project keys" hint="Optional. The projects this answers for, such as TECH, OPS. Empty answers for any key."> | |
| 577 | <Input name="keys" placeholder="TECH, OPS" /> | |
| 578 | </Field> | |
| 579 | </> | |
| 580 | ), | |
| 581 | linear: ( | |
| 582 | <> | |
| 583 | <Field label="API key" hint="From Linear → Settings → Security & access → Personal API keys."> | |
| 584 | <Input name="secret" type="password" required placeholder="lin_api_…" /> | |
| 585 | </Field> | |
| 586 | <Field label="Team keys" hint="Optional. Such as ENG. Empty answers for any key."> | |
| 587 | <Input name="keys" placeholder="ENG" /> | |
| 588 | </Field> | |
| 589 | </> | |
| 590 | ), | |
| 591 | }; | |
| 592 | return ( | |
| Integrations: connect forms open under the tile that was chosen | 593 | <section id="add" className="mt-4 scroll-mt-20 rounded-xl border border-line bg-surface p-5"> |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 594 | <div className="flex items-center gap-3"> |
| 595 | <ProviderMark provider={provider} /> | |
| 596 | <div className="grow"> | |
| Integrations: connect forms open under the tile that was chosen | 597 | <h3 className="font-medium"> |
| Models per workspace: several providers, routed by kind of work | 598 | Connect {provider.endsWith("_endpoint") ? `an ${PROVIDERS[provider].label}` : PROVIDERS[provider].label} |
| Integrations: connect forms open under the tile that was chosen | 599 | </h3> |
| A catalogue of model providers, and settings that feel like settings | 600 | <p className="text-xs text-muted">{blurb(provider)}</p> |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 601 | </div> |
| 602 | <Link to={`/${slug}/-/integrations`} className="rounded-md p-1.5 text-faint hover:bg-raised hover:text-fg" aria-label="Close"> | |
| 603 | <X size={16} /> | |
| 604 | </Link> | |
| 605 | </div> | |
| 606 | <Form method="post" className="mt-5 grid max-w-xl gap-4"> | |
| 607 | <input type="hidden" name="provider" value={provider} /> | |
| A catalogue of model providers, and settings that feel like settings | 608 | {fields[provider] ?? <ModelProviderFields provider={provider} />} |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 609 | <ErrorText>{error}</ErrorText> |
| 610 | <div> | |
| 611 | <Button type="submit" disabled={busy}> | |
| 612 | {busy ? "Connecting…" : "Connect"} | |
| 613 | </Button> | |
| 614 | </div> | |
| 615 | </Form> | |
| 616 | </section> | |
| 617 | ); | |
| 618 | } | |
| 619 | ||
| 620 | /** What to do next, right after connecting: shown once. */ | |
| 621 | function Connected({ connected }: { connected: { connection: Connection; signingSecret: string | null } }) { | |
| 622 | const { connection, signingSecret } = connected; | |
| 623 | const url = connection.webhookUrl; | |
| 624 | return ( | |
| 625 | <div className="mt-6 rounded-xl border border-accent-dim/60 bg-accent/5 p-5"> | |
| 626 | <p className="flex items-center gap-2 font-medium"> | |
| 627 | <CheckCircle2 size={16} className="text-accent" /> | |
| 628 | {connection.name} is connected. | |
| 629 | </p> | |
| 630 | {connection.provider === "sentry" && url && ( | |
| 631 | <ol className="mt-3 list-decimal space-y-2 pl-5 text-sm text-muted"> | |
| 632 | <li> | |
| 633 | In Sentry, open Settings → Developer Settings → Custom Integrations, and create an internal | |
| 634 | integration. | |
| 635 | </li> | |
| 636 | <li> | |
| 637 | Set its webhook URL to <CopyLine text={url} /> | |
| 638 | </li> | |
| 639 | <li>Turn on Alert Rule Action, and under Webhooks, tick issue.</li> | |
| 640 | <li>Give it Issue & Event read and write, save, and paste its client secret below, on the connection.</li> | |
| 641 | </ol> | |
| 642 | )} | |
| 643 | {(connection.provider === "datadog" || connection.provider === "webhook") && url && signingSecret && ( | |
| 644 | <div className="mt-3 space-y-3 text-sm text-muted"> | |
| 645 | <p>This secret is shown once. Copy it now.</p> | |
| 646 | <CopyLine text={signingSecret} /> | |
| 647 | {connection.provider === "datadog" ? ( | |
| 648 | <> | |
| 649 | <p> | |
| 650 | In Datadog, open Integrations → Webhooks and add one named <code>g1t</code> with this URL: | |
| 651 | </p> | |
| 652 | <CopyLine text={url} /> | |
| 653 | <p>Custom headers:</p> | |
| 654 | <CopyLine text={`{"Authorization": "Bearer ${signingSecret}"}`} /> | |
| 655 | <p>Payload:</p> | |
| 656 | <CopyLine | |
| 657 | text={`{"id": "$ALERT_ID", "title": "$EVENT_TITLE", "body": "$EVENT_MSG", "url": "$LINK", "status": "$ALERT_TRANSITION", "priority": "$PRIORITY"}`} | |
| 658 | /> | |
| 659 | <p> | |
| 660 | Then mention <code>@webhook-g1t</code> in any monitor's message. | |
| 661 | </p> | |
| 662 | </> | |
| 663 | ) : ( | |
| 664 | <> | |
| 665 | <p>Send JSON with at least a title to:</p> | |
| 666 | <CopyLine text={url} /> | |
| 667 | <p> | |
| 668 | with <code>Authorization: Bearer <secret></code>, or an HMAC-SHA256 of the body in{" "} | |
| 669 | <code>X-G1t-Signature</code>. An <code>id</code> keeps repeats on one issue. | |
| 670 | </p> | |
| 671 | </> | |
| 672 | )} | |
| 673 | </div> | |
| 674 | )} | |
| 675 | {connection.kind === "tracker" && ( | |
| 676 | <p className="mt-2 text-sm text-muted"> | |
| 677 | Agents now read tickets that work mentions, and you can import one from any repository's new | |
| 678 | issue page. Use Test to check the token. | |
| 679 | </p> | |
| 680 | )} | |
| 681 | {connection.kind === "models" && ( | |
| 682 | <p className="mt-2 text-sm text-muted"> | |
| Models per workspace: several providers, routed by kind of work | 683 | {connection.lastError |
| 684 | ? `It was saved, but the check failed: ${connection.lastError}` | |
| 685 | : connection.models.length > 0 | |
| 686 | ? `It offers ${connection.models.length} models. Choose which work goes to it under “Which model does which work”.` | |
| 687 | : "Choose which work goes to it under “Which model does which work”."} | |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 688 | </p> |
| 689 | )} | |
| 690 | </div> | |
| 691 | ); | |
| 692 | } |