// app/api/webhooks/autousers/route.ts (continued from recipe 1)
if (event.type === "autouser_run.failed") {
const r = event.data.object;
await fetch("https://api.linear.app/graphql", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: process.env.LINEAR_API_KEY!,
},
body: JSON.stringify({
query: `
mutation IssueCreate($input: IssueCreateInput!) {
issueCreate(input: $input) { success issue { id identifier url } }
}
`,
variables: {
input: {
teamId: process.env.LINEAR_TEAM_ID!,
title: `Autouser run failed: ${r.id}`,
description: [
`**Evaluation:** ${r.evaluationId}`,
`**Persona:** ${r.autouserId}`,
`**Error:** ${r.error}`,
`**Cost burned:** $${r.estimatedCostUsd}`,
``,
`https://app.autousers.ai/evaluations/${r.evaluationId}/autouser-runs/${r.id}`,
].join("\n"),
priority: 2,
labelIds: [process.env.LINEAR_FAILURE_LABEL_ID!],
},
},
}),
});
}