import { AgentRouter } from '@copass/agent-router';
import open from 'open';
const router = new AgentRouter({
auth: { type: 'api-key', key: process.env.COPASS_API_KEY! },
sandboxId: process.env.COPASS_SANDBOX_ID!,
});
// The incident response stack, one sandbox.
await router.integrations.connect('pagerduty', { onConnectUrl: open, scope: 'org' });
await router.integrations.connect('slack_v2', { onConnectUrl: open, scope: 'workspace' });
await router.integrations.connect('github', { onConnectUrl: open, scope: 'org' });
await router.integrations.connect('datadog', { onConnectUrl: open, scope: 'org' });
await router.integrations.connect('linear', { onConnectUrl: open, scope: 'org' });
for await (const event of router.run({
provider: 'anthropic',
model: 'claude-opus-4-7',
system: `You are an incident response assistant. Given a time window and an incident channel,
reconstruct the full timeline from five sources:
• PagerDuty — the triggering alerts, who was paged, ack/resolve times.
• Slack — the incident channel's messages, decisions made, people involved.
• GitHub — every deploy and PR merged in the window, and the rollback if there was one.
• Datadog — error rate, latency, and traffic shifts aligned to the timeline.
• Linear — tickets opened during or after, and the incident followups being tracked.
Output a post-mortem draft with:
1. Summary (one paragraph)
2. Timeline (chronological, with timestamps and source citations)
3. Root cause hypothesis
4. Contributing factors
5. What went well
6. Action items (link to Linear tickets already filed; propose new ones for gaps)`,
message: 'Draft the post-mortem for the #incident-2026-04-22-checkout channel, window 14:00 to 16:30 UTC.',
endUserId: 'oncall',
})) {
if (event.type === 'text') process.stdout.write(event.text);
if (event.type === 'tool_call') console.log(`\n→ ${event.name}`);
}