import { smithers, Workflow, Task, Sequence } from "smithers-orchestrator";
import { ToolLoopAgent as Agent } from "ai";
import { anthropic } from "@ai-sdk/anthropic";
import { drizzle } from "drizzle-orm/bun-sqlite";
import {
sqliteTable,
text,
integer,
primaryKey,
} from "drizzle-orm/sqlite-core";
const inputTable = sqliteTable("input", {
runId: text("run_id").primaryKey(),
topic: text("topic").notNull(),
});
const researchTable = sqliteTable(
"research",
{
runId: text("run_id").notNull(),
nodeId: text("node_id").notNull(),
findings: text("findings").notNull(),
},
(t) => ({
pk: primaryKey({ columns: [t.runId, t.nodeId] }),
}),
);
const summaryTable = sqliteTable(
"summary",
{
runId: text("run_id").notNull(),
nodeId: text("node_id").notNull(),
summary: text("summary").notNull(),
},
(t) => ({
pk: primaryKey({ columns: [t.runId, t.nodeId] }),
}),
);
const schema = {
input: inputTable,
output: summaryTable,
research: researchTable,
summary: summaryTable,
};
const db = drizzle("./workflow.db", { schema });
const researcher = new Agent({
model: anthropic("claude-sonnet-4-20250514"),
instructions: "You are a research assistant.",
});
export default smithers(db, (ctx) => (
<Workflow name="research-pipeline" cache>
<Task id="research" output={schema.research} agent={researcher}>
{`Research the topic: ${ctx.input.topic}`}
</Task>
<Task id="summary" output={schema.summary}>
{{ summary: "Workflow complete." }}
</Task>
</Workflow>
));