todo.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import z from "zod"
  2. import { Bus } from "../bus"
  3. import { Storage } from "../storage/storage"
  4. export namespace Todo {
  5. export const Info = z
  6. .object({
  7. content: z.string().describe("Brief description of the task"),
  8. status: z.string().describe("Current status of the task: pending, in_progress, completed, cancelled"),
  9. priority: z.string().describe("Priority level of the task: high, medium, low"),
  10. id: z.string().describe("Unique identifier for the todo item"),
  11. })
  12. .meta({ ref: "Todo" })
  13. export type Info = z.infer<typeof Info>
  14. export const Event = {
  15. Updated: Bus.event(
  16. "todo.updated",
  17. z.object({
  18. sessionID: z.string(),
  19. todos: z.array(Info),
  20. }),
  21. ),
  22. }
  23. export async function update(input: { sessionID: string; todos: Info[] }) {
  24. await Storage.write(["todo", input.sessionID], input.todos)
  25. Bus.publish(Event.Updated, input)
  26. }
  27. export async function get(sessionID: string) {
  28. return Storage.read<Info[]>(["todo", sessionID])
  29. .then((x) => x || [])
  30. .catch(() => [])
  31. }
  32. }