(session: SessionSummaryRecord)
| 82 | } |
| 83 | |
| 84 | export function upsertThreadSummary(session: SessionSummaryRecord) { |
| 85 | const db = getThreadStateDatabase() |
| 86 | ensureProject(session.cwd) |
| 87 | |
| 88 | const storedThreadForPath = db |
| 89 | .prepare( |
| 90 | ` |
| 91 | SELECT id, session_path AS sessionPath |
| 92 | FROM threads |
| 93 | WHERE session_path = ? |
| 94 | `, |
| 95 | ) |
| 96 | .get(session.sessionPath) as ThreadIdPathRow | undefined |
| 97 | const storedDuplicateIdRows = db |
| 98 | .prepare( |
| 99 | ` |
| 100 | SELECT id, session_path AS sessionPath |
| 101 | FROM threads |
| 102 | WHERE (id = ? OR id LIKE ? ESCAPE '\\') |
| 103 | AND session_path != ? |
| 104 | `, |
| 105 | ) |
| 106 | .all(session.id, `${escapeLikePattern(session.id)}:%`, session.sessionPath) as ThreadIdPathRow[] |
| 107 | |
| 108 | const threadId = |
| 109 | storedThreadForPath?.id && storedThreadForPath.id !== session.id |
| 110 | ? storedThreadForPath.id |
| 111 | : storedDuplicateIdRows.length > 0 |
| 112 | ? getDisambiguatedThreadId(session) |
| 113 | : session.id |
| 114 | |
| 115 | db.prepare( |
| 116 | ` |
| 117 | INSERT INTO threads (id, cwd, session_path, title, last_modified_ms) |
| 118 | VALUES (?, ?, ?, ?, ?) |
| 119 | ON CONFLICT(session_path) DO UPDATE SET |
| 120 | id = excluded.id, |
| 121 | cwd = excluded.cwd, |
| 122 | title = excluded.title, |
| 123 | last_modified_ms = excluded.last_modified_ms, |
| 124 | updated_at = CURRENT_TIMESTAMP |
| 125 | `, |
| 126 | ).run(threadId, session.cwd, session.sessionPath, session.title, session.lastModifiedMs) |
| 127 | |
| 128 | return threadId |
| 129 | } |
| 130 | |
| 131 | export function setSessionNativeExtensions(sessionPath: string, enabled: string[]) { |
| 132 | const db = getThreadStateDatabase() |
no test coverage detected