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