/// import { Cell, Default, NAME, pattern, UI, wish } from "commontools"; interface TodoItem { title: string; done: Default; } interface Input { items: Cell>; } interface Output { items: Cell; } export default pattern(({ items }) => { return { [NAME]: "Todo with Suggestions", [UI]: (

Todo List

{/* Add new item */} { const title = e.detail?.message?.trim(); if (title) { items.push({ title, done: false }); } }} /> {/* Todo items with per-item suggestions */}
{items.map((item) => { // AI suggestion based on current todos const wishResult = wish({ query: item.title, context: { item, items }, }); return (
{ const current = items.get(); const index = current.findIndex((el) => Cell.equals(item, el) ); if (index >= 0) { items.set(current.toSpliced(index, 1)); } }} > ×
AI Suggestion {wishResult}
); })}
), items, }; });