(toolInfo: Record<string, unknown>)
| 250 | * Handles both array format and markdown checklist string format |
| 251 | */ |
| 252 | export function parseTodosFromToolInfo(toolInfo: Record<string, unknown>): TodoItem[] | null { |
| 253 | // Try to get todos directly as an array |
| 254 | const todosArray = toolInfo.todos as unknown[] | undefined |
| 255 | if (Array.isArray(todosArray)) { |
| 256 | return todosArray |
| 257 | .map((item, index) => { |
| 258 | if (typeof item === "object" && item !== null) { |
| 259 | const todo = item as Record<string, unknown> |
| 260 | return { |
| 261 | id: (todo.id as string) || `todo-${index}`, |
| 262 | content: (todo.content as string) || "", |
| 263 | status: ((todo.status as string) || "pending") as TodoItem["status"], |
| 264 | } |
| 265 | } |
| 266 | return null |
| 267 | }) |
| 268 | .filter((item): item is TodoItem => item !== null) |
| 269 | } |
| 270 | |
| 271 | // Try to parse markdown checklist format from todos string |
| 272 | const todosString = toolInfo.todos as string | undefined |
| 273 | if (typeof todosString === "string") { |
| 274 | return parseMarkdownChecklist(todosString) |
| 275 | } |
| 276 | |
| 277 | return null |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * Parse a markdown checklist string into TodoItem array |
no test coverage detected