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!,
});
// Six sources feeding the same sandbox.
await router.integrations.connect('intercom', { onConnectUrl: open, scope: 'org' });
await router.integrations.connect('slack_v2', { onConnectUrl: open, scope: 'workspace' });
await router.integrations.connect('hubspot', { onConnectUrl: open, scope: 'org' });
await router.integrations.connect('stripe', { onConnectUrl: open, scope: 'org' });
await router.integrations.connect('zendesk', { onConnectUrl: open, scope: 'org' });
await router.integrations.connect('github', { onConnectUrl: open, scope: 'org' });
for await (const event of router.run({
provider: 'anthropic',
model: 'claude-opus-4-7',
system: `You are a customer success analyst. For each active customer, cross-reference:
• Intercom — response sentiment, unanswered messages, tone shift.
• Slack — quiet-then-loud patterns, negative tone, lost champions.
• HubSpot — renewal within 90 days, declining contact engagement.
• Stripe — MRR drop, failed charges, downgrades.
• Zendesk — escalations, ticket aging, repeat complaints.
• GitHub — open bugs they filed, unresponded PRs.
Produce a ranked list of the top 10 at-risk customers. For each, cite the specific signals
across at least 3 of the 6 sources. Score risk (low / medium / high / critical).
Skip customers where the signals only come from one source — we need corroboration.`,
message: 'Generate today\'s customer health report.',
endUserId: 'cs-team',
})) {
if (event.type === 'text') process.stdout.write(event.text);
if (event.type === 'tool_call') console.log(`\n→ ${event.name}`);
}