g1t/apps/web/app/routes/workspace/integrations.tsx

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