// The agent passes page_context.environment.apiUrl in as an argument, so the // allowlist keeps the user's DATA_TOKEN from being sent to any other host. const APPROVED_API_URL = /^https:\/\/(?:api\.tela\.com|(?:api|tela-api-pr-\d+)\.telastaging\.com)$/ type ClientContext = { pageUrl?: string posthogSessionId?: string browserInfo?: { userAgent?: string, screenResolution?: string } } const [apiUrl, category, surface] = process.argv.slice(2) const [clientJson = '', ...descriptionLines] = (await Bun.stdin.text()).split('\n') const description = descriptionLines.join('\n').trim() if (!category || !surface || !description) { console.error('Usage: bun ./.claude/skills/report-issue/report.ts <<\'TELA_REPORT_END\'\n\n\nTELA_REPORT_END') process.exit(1) } if (!apiUrl || !APPROVED_API_URL.test(apiUrl)) { console.error(`API URL not approved for this agent: ${apiUrl || '(missing)'}. Pass page_context.environment.apiUrl.`) process.exit(1) } const dataToken = process.env.DATA_TOKEN if (!dataToken) { console.error('DATA_TOKEN is required') process.exit(1) } const client = JSON.parse(clientJson.trim() || '{}') as ClientContext const res = await fetch(`${apiUrl}/report-issue`, { method: 'POST', headers: { 'x-data-token': dataToken, 'Content-Type': 'application/json' }, body: JSON.stringify({ category, description, source: surface === 'workstation' ? 'workstation-assistant' : 'dashboard-assistant', pageUrl: client.pageUrl, posthogSessionId: client.posthogSessionId, browserInfo: client.browserInfo, }), }) process.stdout.write(`${res.status} ${await res.text()}\n`) export {}