import { z } from "zod";
import { client, agentTask, Sessions } from "anchorbrowser";
client.setConfig({ auth: () => process.env.ANCHORBROWSER_API_KEY });
const HiringSignals = z.object({
thread_title: z.string(),
matches: z.array(
z.object({
company: z.string(),
role: z.string(),
location: z.string(),
url: z.string().nullish(),
})
),
});
const task = await agentTask(
`Open the most recent "Ask HN: Who is hiring?" story from the search results. In that thread, read the top-level comments and find the first five companies that are hiring for data engineering or data platform roles. For each one, collect the company name, the role title, the location, and an application link if the comment has one.`,
{
taskOptions: {
url: "https://hn.algolia.com/?query=Ask%20HN%3A%20Who%20is%20hiring&sort=byDate&type=story",
outputSchema: z.toJSONSchema(HiringSignals),
},
}
);
try {
if (task.status !== "success") throw new Error(`Task failed: ${task.result}`);
const signals = HiringSignals.parse(JSON.parse(task.data.result));
console.log(signals);
} finally {
await Sessions.deleteSession({ path: { session_id: task.sessionId } });
}