import { Anchor, Button, CopyButton, Drawer, Group, PasswordInput, Stack, Text } from '@mantine/core'; import { IconBrandDiscord, IconBrandGithubCopilot, IconBrandGoogle, IconBrandJira, IconBrandOpenai, IconBrandSlack, IconBrandTeams, IconBrandTelegram, IconAffiliate, IconCheck, IconCode, IconCopy, IconKey, IconMessageChatbot, IconSend, IconSparkles, IconTicket, IconWebhook, } from '@/components/icons'; import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { useState, type FormEvent, type ReactNode } from 'react'; import { Link } from 'react-router-dom'; import { getJson, sendJson } from '../../api/client'; import { ErrorAlert, fmtTs, PageHeader } from '../../components/common'; import type { NotifySettings } from '../../notify/NotificationsSettings'; import { BotStatusLine, TelegramCard } from '../../notify/TelegramCard'; import { recentlyUsed, useAccessTokens } from '../../account/useAccessTokens'; import '../../notify/notify.css'; import './integrations.css'; type Delivery = { at: string; ok: boolean; status: number | null; error: string | null } | null; export interface HookIntegration { configured: boolean; host: string | null; last_delivery: Delivery } /** Messaging tools that receive notifications through an incoming webhook (one-way). */ export type HookKey = 'slack' | 'teams' | 'google_chat' | 'discord'; export type IntegrationsState = Record; /** AI assistants that use Astra through the MCP connector (/mcp, with a personal access token). */ type AssistantKey = 'copilot' | 'chatgpt' | 'claude' | 'github' | 'cursor'; type Key = 'telegram' | HookKey | AssistantKey | 'a2a' | 'webhook' | 'jira' | 'servicenow'; type Status = { tone: 'green' | 'neutral' | 'red'; words: string; planned?: boolean; outline?: boolean }; const PLANNED: Status = { tone: 'neutral', words: 'Planned', planned: true, outline: true }; const COMING_NEXT: Status = { tone: 'neutral', words: 'Coming next', planned: true, outline: true }; const AVAILABLE: Status = { tone: 'neutral', words: 'Available', outline: true }; const status = (configured: boolean, last: Delivery | undefined): Status => !configured ? { tone: 'neutral', words: 'Not set up' } : last && !last.ok ? { tone: 'red', words: 'Needs attention' } : { tone: 'green', words: 'Connected' }; const useNotifySettings = () => useQuery({ queryKey: ['notify-settings'], queryFn: () => getJson('/api/notifications/settings'), retry: false }); const useIntegrations = () => useQuery({ queryKey: ['integrations'], queryFn: () => getJson('/api/integrations'), retry: false }); interface CardDef { id: Key; icon: ReactNode; name: string; description: string; caps: string[]; st: Status } /** One integration: its mark, what it does, whether it is connected (or planned), and the way to set it up. */ function IntegrationCard({ id, icon, name, description, caps, st, onOpen }: CardDef & { onOpen: () => void }) { const verb = st.planned ? 'Learn more' : st.tone === 'neutral' ? 'Set up' : 'Manage'; return (
{icon} {st.words}

{name}

{description}

    {caps.map((c) =>
  • {c}
  • )}
); } const HOOKS: Record = { slack: { name: 'Slack', host: 'hooks.slack.com', steps: ['Create a Slack app for your workspace.', 'Open Incoming Webhooks and switch them on.', 'Choose Add New Webhook to Workspace and pick the channel.', 'Copy the webhook URL and paste it below.'], help: 'https://api.slack.com/messaging/webhooks', helpLabel: 'Slack: sending messages using incoming webhooks', }, teams: { name: 'Microsoft Teams', host: 'your Teams workflow', steps: ['In Microsoft Teams, open the Workflows app.', 'Start from the template "Post to a channel when a webhook request is received".', 'Choose the team and channel, then finish the workflow.', 'Copy the webhook URL it shows and paste it below.'], help: 'https://support.microsoft.com/office/create-incoming-webhooks-with-workflows-for-microsoft-teams-8ae491c7-0394-4861-ba59-055e33f75498', helpLabel: 'Microsoft: create incoming webhooks with Workflows', }, google_chat: { name: 'Google Chat', host: 'chat.googleapis.com', steps: ['In Google Chat, open the space that should get the messages.', 'Open Apps & integrations, then Webhooks.', 'Choose Add webhook, give it a name and save.', 'Copy the webhook URL and paste it below.'], help: 'https://developers.google.com/workspace/chat/quickstart/webhooks', helpLabel: 'Google: send messages to Google Chat with incoming webhooks', }, discord: { name: 'Discord', host: 'discord.com', steps: ['In Discord, open the settings of the channel that should get the messages.', 'Open Integrations, then Webhooks.', 'Choose New Webhook.', 'Choose Copy Webhook URL and paste it below.'], help: 'https://support.discord.com/hc/en-us/articles/228383668', helpLabel: 'Discord: intro to webhooks', }, }; const lastLine = (last: Delivery | undefined) => last ? `Last delivery ${fmtTs(last.at)}: ${last.ok ? 'delivered' : `failed${last.error ? ` (${last.error})` : ''}`}.` : null; /** A messaging tool with an incoming webhook: paste the URL once (a secret, never shown back), test, disconnect. */ function HookSetup({ kind, state }: { kind: HookKey; state: HookIntegration | undefined }) { const qc = useQueryClient(); const [url, setUrl] = useState(''); const [sure, setSure] = useState(false); const h = HOOKS[kind]; const refresh = () => void qc.invalidateQueries({ queryKey: ['integrations'] }); const save = useMutation({ mutationFn: () => sendJson('PUT', `/api/integrations/${kind}`, { webhook_url: url.trim() }), onSuccess: () => { setUrl(''); refresh(); } }); const test = useMutation({ mutationFn: () => sendJson<{ queued: boolean; id: number }>('POST', `/api/integrations/${kind}/test`), onSuccess: refresh }); const remove = useMutation({ mutationFn: () => sendJson('DELETE', `/api/integrations/${kind}`), onSuccess: () => { setSure(false); refresh(); } }); const last = state?.last_delivery; const onSubmit = (e: FormEvent) => { e.preventDefault(); if (url.trim()) save.mutate(); }; return ( {state?.configured ? (

Connected ({state.host ?? h.host}). New notifications go there.

) : ( <>
    {h.steps.map((t) =>
  1. {t}
  2. )}
{h.helpLabel} )}
setUrl(e.currentTarget.value)} description={state?.configured ? 'Paste a new URL to replace the current one. It is stored as a secret and never shown again.' : 'Stored as a secret and never shown again.'} />
{state?.configured && ( <> {!sure ? : ( Stop sending to {h.name}? )} {test.isSuccess && Test message queued. It should arrive within a few seconds.} )} {last && {lastLine(last)}}
); } /** The generic signed webhook (n8n and other tools): configured on the server, shown here read-only. */ function WebhookSetup({ s }: { s: NotifySettings | undefined }) { const last = s?.last_delivery; return (

{s?.webhook_configured ? `Connected (${s.webhook_host ?? 'webhook'}), ${s.signing ? 'signed' : 'not signed'}.` : 'Not set up.'}

  1. Set FPT_NOTIFY_WEBHOOK_URL to the address that should receive the events (for example an n8n webhook).
  2. Set FPT_NOTIFY_SECRET to a long random value; every event is signed with it (X-Patchwise-Signature).
  3. For n8n, import integrations/n8n/patchwise-telegram.json and follow its README.
{last && {lastLine(last)}}
); } /** An integration that is planned: what it will do, in plain words, and a Connect button that is not available yet. */ function PlannedSetup({ intro, lists, note }: { intro: string; lists: { title: string; items: string[] }[]; note?: string }) { return ( {intro} {lists.map((l) => (

{l.title}

    {l.items.map((t) =>
  • {t}
  • )}
))} {note && {note}} Coming next
); } /** A block of settings to paste, with a Copy button. Never holds a real token: placeholders and environment variables only. */ function Snippet({ title, code, label }: { title: string; code: string; label: string }) { return (

{title}

{({ copied, copy }) => ( )}
{code}
); } const ASSISTANT_CAN = [ { title: 'It can read', items: ['Patch readiness by business area', 'What is waiting for you', 'Test run status and reports'] }, { title: 'It can act, each step confirmed by you', items: ['Start a test run', 'Approve scenarios'] }, ]; /** The settings each assistant needs, for the given /mcp address. */ function clientSetup(kind: AssistantKey, url: string): ReactNode { const claudeDesktop = JSON.stringify({ mcpServers: { patchwise: { command: 'npx', args: ['-y', 'mcp-remote', url, '--header', 'Authorization:${PATCHWISE_AUTH}'], env: { PATCHWISE_AUTH: 'Bearer ' } } } }, null, 2); const claudeCode = `claude mcp add --transport http patchwise ${url} --header "Authorization: Bearer $PATCHWISE_TOKEN"`; const vscode = JSON.stringify({ servers: { patchwise: { type: 'http', url, headers: { Authorization: 'Bearer ${input:patchwise-token}' } } }, inputs: [{ type: 'promptString', id: 'patchwise-token', description: 'Astra token', password: true }] }, null, 2); const cursor = JSON.stringify({ mcpServers: { patchwise: { url, headers: { Authorization: 'Bearer ${env:PATCHWISE_TOKEN}' } } } }, null, 2); if (kind === 'claude') return ( <> Set PATCHWISE_TOKEN in your terminal first. Claude.ai on the web needs sign-in with OAuth: coming next. ); if (kind === 'github') return ( <> VS Code asks for the token the first time GitHub Copilot uses Astra, and keeps it in its secret storage. ); if (kind === 'cursor') return ( <> Set PATCHWISE_TOKEN in your environment, then restart Cursor. ); if (kind === 'copilot') return (

Microsoft Copilot (Copilot Studio)

  1. In Copilot Studio, open your agent, then Tools, Add a tool, Model Context Protocol.
  2. Server URL: the address above.
  3. Authentication: API key, sent in the header Authorization, with the value Bearer <your token>.
  4. Save, then try: "What is waiting for me in Astra?"
); return null; } /** An address to paste into another tool, with a Copy button. */ function AddressRow({ title, label, value, testId }: { title: string; label: string; value: string; testId: string }) { return (

{title}

{({ copied, copy }) => ( )}
{value}
); } /** What another agent can ask Astra for over A2A, one line each (the skills on the Agent Card). */ const A2A_SKILLS: { id: string; words: string }[] = [ { id: 'assess-readiness', words: 'How ready each business area is for a patch, with the numbers behind it.' }, { id: 'design-tests', words: 'Design scenarios from the pod and patch facts your agent sends.' }, { id: 'test-these-cases', words: 'Turn your own test cases into scripts and try them on a pod.' }, { id: 'run-tests', words: 'Start a test run; it waits until a person approves in Astra.' }, { id: 'get-report', words: 'Fetch the verdict, counts and the report of a finished run.' }, ]; /** A short client for the A2A endpoint: send cases, then follow the task. The token comes from an environment variable. */ function a2aExample(base: string): string { return `import os, time, httpx BASE = "${base}" HEADERS = {"Authorization": "Bearer " + os.environ["PATCHWISE_TOKEN"]} send = { "jsonrpc": "2.0", "id": 1, "method": "message/send", "params": {"message": { "role": "user", "messageId": "msg-1", "metadata": {"skill": "test-these-cases"}, "parts": [{"kind": "data", "data": {"cases": [{ "title": "Approve a requisition under the limit", "area": "P2P", "steps": [{"action": "Open Procurement > Requisitions > Manage Requisitions", "expected": "The requisitions list opens"}], }]}}], }}, } task = httpx.post(BASE + "/a2a", json=send, headers=HEADERS).json()["result"] # follow the task: it stops at input-required until a person approves in Astra while task["status"]["state"] not in ("completed", "failed", "canceled", "input-required"): time.sleep(10) get = {"jsonrpc": "2.0", "id": 2, "method": "tasks/get", "params": {"id": task["id"]}} task = httpx.post(BASE + "/a2a", json=get, headers=HEADERS).json()["result"] print(task["status"]["state"]) `; } /** Your own agent talking to Astra over A2A: what it can ask for, the addresses, the token, and an example. */ function A2ASetup() { const origin = typeof window !== 'undefined' ? window.location.origin : ''; return ( Your own agent, for example one that reads your pod and its patch updates, can ask Astra to design tests, test your own cases, start test runs and fetch the report. It acts as the person whose token it uses, with their permissions.

What it can ask for

    {A2A_SKILLS.map((s) =>
  • {s.id}: {s.words}
  • )}
A person always approves in Astra before anything runs as a real test. Sign-off is never available through A2A. Choose “read and act” so the agent can start runs (you still approve each one).
); } /** An AI assistant: what it can do through Astra, the token it needs, the /mcp address and its own settings. */ function AssistantSetup({ kind }: { kind: AssistantKey }) { const url = `${typeof window !== 'undefined' ? window.location.origin : ''}/mcp`; const web = kind === 'chatgpt'; return ( It uses Astra as you, with your permissions, through one MCP connector (Model Context Protocol). Sign-off and failure verdicts stay in Astra. {ASSISTANT_CAN.map((l) => (

{l.title}

    {l.items.map((t) =>
  • {t}
  • )}
))} {web ? ( Needs sign-in with OAuth: coming next. Until then use Claude Desktop or Claude Code, VS Code with GitHub Copilot, or Cursor. ) : ( <> On your Account page; it is shown once. {clientSetup(kind, url)} )}
); } const ASSISTANTS: AssistantKey[] = ['copilot', 'chatgpt', 'claude', 'github', 'cursor']; const PLANNED_DRAWER: Partial> = { jira: ( ), servicenow: ( ), }; /** Integrations: where Astra reaches people (messaging), the AI assistants that will ask it, and the tools it feeds. */ export function IntegrationsPage() { const ns = useNotifySettings(); const ints = useIntegrations(); const tokens = useAccessTokens(); const [open, setOpen] = useState(null); const assistant: Status = recentlyUsed(tokens.data?.items) ? { tone: 'green', words: 'Connected' } : AVAILABLE; const tg = ns.data?.telegram; const hook = (k: HookKey) => status(!!ints.data?.[k]?.configured, ints.data?.[k]?.last_delivery); const mcpCaps = ['Ask about readiness and runs', 'Start runs with confirmation']; const ide = ['Ask about readiness and runs', 'From your editor']; const sections: { id: string; title: string; lede: string; cards: CardDef[] }[] = [ { id: 'messaging', title: 'Messaging', lede: 'Coworkers tell people here when a test run needs them.', cards: [ { id: 'telegram', icon: , name: 'Telegram', description: 'Coworkers message you, and you can start runs and approve from the chat.', caps: ['Notifications', 'Two-way: start runs, approve'], st: status(!!tg?.token_set && !!tg?.chat, tg?.last_delivery) }, { id: 'teams', icon: , name: 'Microsoft Teams', description: 'Notifications in a Teams channel, through a Workflows webhook.', caps: ['Notifications', 'Two-way bot: planned'], st: hook('teams') }, { id: 'slack', icon: , name: 'Slack', description: 'Notifications in a Slack channel, through an incoming webhook.', caps: ['Notifications', 'Two-way bot: planned'], st: hook('slack') }, { id: 'google_chat', icon: , name: 'Google Chat', description: 'Notifications in a Google Chat space, through an incoming webhook.', caps: ['Notifications'], st: hook('google_chat') }, { id: 'discord', icon: , name: 'Discord', description: 'Notifications in a Discord channel, through a channel webhook.', caps: ['Notifications'], st: hook('discord') }, ] }, { id: 'assistants', title: 'AI assistants', lede: 'Ask Astra from the assistant you already use.', cards: [ { id: 'copilot', icon: , name: 'Microsoft Copilot', description: 'Ask about readiness and start runs from a Copilot Studio agent.', caps: mcpCaps, st: assistant }, { id: 'chatgpt', icon: , name: 'ChatGPT', description: 'Ask about readiness and start runs from ChatGPT.', caps: mcpCaps, st: COMING_NEXT }, { id: 'claude', icon: , name: 'Claude', description: 'Ask about readiness and start runs from Claude Desktop or Claude Code.', caps: mcpCaps, st: assistant }, { id: 'github', icon: , name: 'GitHub Copilot (VS Code)', description: 'Ask Astra from GitHub Copilot chat in VS Code.', caps: ide, st: assistant }, { id: 'cursor', icon: , name: 'Cursor', description: "Ask Astra from Cursor's assistant.", caps: ide, st: assistant }, ] }, { id: 'agents', title: 'Your own agents', lede: 'Agents you build can work with Astra through Agent2Agent (A2A).', cards: [ { id: 'a2a', icon: , name: 'Agent2Agent (A2A)', description: 'Your agent sends pod and patch facts or your own test cases; Astra designs and runs the tests and returns the report.', caps: ['Send pod and patch facts', 'Your test cases', 'Follow runs', 'Get reports'], st: AVAILABLE }, ] }, { id: 'tools', title: 'Tools', lede: 'Systems that receive Astra events and results.', cards: [ { id: 'webhook', icon: , name: 'Webhook (n8n and other tools)', description: 'Signed events for automation tools such as n8n.', caps: ['Notifications', 'Signed (HMAC)'], st: status(!!ns.data?.webhook_configured, ns.data?.last_delivery) }, { id: 'jira', icon: , name: 'Jira', description: 'Planned: defects confirmed in Astra raised as Jira issues.', caps: ['Defects'], st: PLANNED }, { id: 'servicenow', icon: , name: 'ServiceNow', description: "Attach the readiness verdict and sign-off evidence to the patch's change request, and raise confirmed defects as incidents.", caps: ['Change requests', 'Incidents'], st: PLANNED }, ] }, ]; const current = sections.flatMap((s) => s.cards).find((c) => c.id === open); return ( Where Astra reaches you, and the AI assistants that can work with it. Notifications go to every connected place; Telegram also lets people start runs and approve from the chat.} /> {sections.map((s) => (

{s.title}

{s.lede}

{s.cards.map((c) => setOpen(c.id)} />)}
))} setOpen(null)} position="right" size="md" title={current ? current.name : ''} closeButtonProps={{ 'aria-label': 'Close the setup' }}> {open === 'telegram' && ( Each person links their own chat from their Account page; their chat then acts as them, with their permissions. )} {open && open in HOOKS && } {open === 'webhook' && } {open && (ASSISTANTS as Key[]).includes(open) && } {open === 'a2a' && } {open && PLANNED_DRAWER[open]}
); }