()
| 44 | } |
| 45 | |
| 46 | export async function loadInboxThreadList(): Promise<InboxThread[]> { |
| 47 | const threads = listInboxThreads() |
| 48 | |
| 49 | return mapWithConcurrency(threads, INBOX_PROMPT_BACKFILL_CONCURRENCY, async (thread) => { |
| 50 | try { |
| 51 | if (thread.prompt?.trim()) { |
| 52 | return thread |
| 53 | } |
| 54 | |
| 55 | const loadedThread = await loadThread(thread.sessionPath) |
| 56 | let prompt: string | null = null |
| 57 | |
| 58 | for (let index = loadedThread.messages.length - 1; index >= 0; index -= 1) { |
| 59 | const message = loadedThread.messages[index] |
| 60 | if (message?.role === 'user') { |
| 61 | const nextPrompt = message.content.join('\n\n').trim() |
| 62 | prompt = nextPrompt.length > 0 ? nextPrompt : null |
| 63 | break |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | if (!prompt) { |
| 68 | return thread |
| 69 | } |
| 70 | |
| 71 | upsertInboxThreadPrompt(thread.sessionPath, prompt) |
| 72 | return { ...thread, prompt } |
| 73 | } catch (error) { |
| 74 | console.warn(`Failed to backfill inbox prompt for ${thread.sessionPath}.`, error) |
| 75 | return thread |
| 76 | } |
| 77 | }) |
| 78 | } |
| 79 | |
| 80 | export async function loadThreadSnapshot( |
| 81 | sessionPath: string, |
nothing calls this directly
no test coverage detected