import { AttioRecordInputEvent, Terse, TerseAgent } from "terse-sdk"
import { Apollo, Attio, AttioList } from "./terse.generated"
const client = new Terse()
await client.createWorkflow({
name: "contact-scoring",
triggers: [Attio.onRecordCreated({ list: AttioList.Contacts.NewContacts })],
skills: [
Attio.skill({ lists: [AttioList.Contacts.NewContacts] }),
Apollo.skill(),
],
onTrigger: async (event: AttioRecordInputEvent, agent: TerseAgent) => {
const company = await agent.tools.apollo.enrichCompany({
domain: event.record.values.company_domain,
})
const prompt = [
"Score this contact from 1-100 and explain why.",
`Company: ${event.record.values.company_name}`,
`Domain: ${event.record.values.company_domain}`,
`Industry: ${company.industry}`,
`Employee count: ${company.employeeCount}`,
`Revenue: ${company.estimatedRevenue}`,
`Technologies: ${company.technologies.join(", ")}`,
].join("\n")
const result = await agent.runAndWait(prompt, event)
// Parse structured score from model output
const scoreMatch = result.match(/\b(\d{1,3})\b/)
const score = scoreMatch ? parseInt(scoreMatch[1], 10) : 0
await agent.tools.attio.updateRecord({
list: AttioList.Contacts.NewContacts,
recordId: event.record.id,
fields: { contact_score: score, scoring_notes: result },
})
},
})