flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

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

689 lines26,930 bytesCodeBlame

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