mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-03-30 22:03:58 +00:00
- Rename packages/opencode → packages/tfcode (directory only) - Rename bin/opencode → bin/tfcode (CLI binary) - Rename .opencode → .tfcode (config directory) - Update package.json name and bin field - Update config directory path references (.tfcode) - Keep internal code references as 'opencode' for easy upstream sync - Keep @opencode-ai/* workspace package names This minimal branding approach allows clean merges from upstream opencode repository while providing tfcode branding for users.
58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
import { BusEvent } from "@/bus/bus-event"
|
|
import { Bus } from "@/bus"
|
|
import { SessionID } from "./schema"
|
|
import z from "zod"
|
|
import { Database, eq, asc } from "../storage/db"
|
|
import { TodoTable } from "./session.sql"
|
|
|
|
export namespace Todo {
|
|
export const Info = z
|
|
.object({
|
|
content: z.string().describe("Brief description of the task"),
|
|
status: z.string().describe("Current status of the task: pending, in_progress, completed, cancelled"),
|
|
priority: z.string().describe("Priority level of the task: high, medium, low"),
|
|
})
|
|
.meta({ ref: "Todo" })
|
|
export type Info = z.infer<typeof Info>
|
|
|
|
export const Event = {
|
|
Updated: BusEvent.define(
|
|
"todo.updated",
|
|
z.object({
|
|
sessionID: SessionID.zod,
|
|
todos: z.array(Info),
|
|
}),
|
|
),
|
|
}
|
|
|
|
export function update(input: { sessionID: SessionID; todos: Info[] }) {
|
|
Database.transaction((db) => {
|
|
db.delete(TodoTable).where(eq(TodoTable.session_id, input.sessionID)).run()
|
|
if (input.todos.length === 0) return
|
|
db.insert(TodoTable)
|
|
.values(
|
|
input.todos.map((todo, position) => ({
|
|
session_id: input.sessionID,
|
|
content: todo.content,
|
|
status: todo.status,
|
|
priority: todo.priority,
|
|
position,
|
|
})),
|
|
)
|
|
.run()
|
|
})
|
|
Bus.publish(Event.Updated, input)
|
|
}
|
|
|
|
export function get(sessionID: SessionID) {
|
|
const rows = Database.use((db) =>
|
|
db.select().from(TodoTable).where(eq(TodoTable.session_id, sessionID)).orderBy(asc(TodoTable.position)).all(),
|
|
)
|
|
return rows.map((row) => ({
|
|
content: row.content,
|
|
status: row.status,
|
|
priority: row.priority,
|
|
}))
|
|
}
|
|
}
|