mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-21 17:54:23 +01:00
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import z from "zod"
|
|
import { Bus } from "../bus"
|
|
import { Storage } from "../storage/storage"
|
|
|
|
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"),
|
|
id: z.string().describe("Unique identifier for the todo item"),
|
|
})
|
|
.meta({ ref: "Todo" })
|
|
export type Info = z.infer<typeof Info>
|
|
|
|
export const Event = {
|
|
Updated: Bus.event(
|
|
"todo.updated",
|
|
z.object({
|
|
sessionID: z.string(),
|
|
todos: z.array(Info),
|
|
}),
|
|
),
|
|
}
|
|
|
|
export async function update(input: { sessionID: string; todos: Info[] }) {
|
|
await Storage.write(["todo", input.sessionID], input.todos)
|
|
Bus.publish(Event.Updated, input)
|
|
}
|
|
|
|
export async function get(sessionID: string) {
|
|
return Storage.read<Info[]>(["todo", sessionID])
|
|
.then((x) => x || [])
|
|
.catch(() => [])
|
|
}
|
|
}
|