| 57 | type SessionRow = typeof SessionTable.$inferSelect |
| 58 | |
| 59 | export function fromRow(row: SessionRow): Info { |
| 60 | const summary = |
| 61 | row.summary_additions !== null || row.summary_deletions !== null || row.summary_files !== null |
| 62 | ? { |
| 63 | additions: row.summary_additions ?? 0, |
| 64 | deletions: row.summary_deletions ?? 0, |
| 65 | files: row.summary_files ?? 0, |
| 66 | diffs: row.summary_diffs ?? undefined, |
| 67 | } |
| 68 | : undefined |
| 69 | const share = row.share_url ? { url: row.share_url } : undefined |
| 70 | const revert = row.revert |
| 71 | ? { |
| 72 | messageID: MessageID.make(row.revert.messageID), |
| 73 | partID: row.revert.partID ? PartID.make(row.revert.partID) : undefined, |
| 74 | snapshot: row.revert.snapshot, |
| 75 | diff: row.revert.diff, |
| 76 | } |
| 77 | : undefined |
| 78 | return { |
| 79 | id: row.id, |
| 80 | slug: row.slug, |
| 81 | projectID: row.project_id, |
| 82 | workspaceID: row.workspace_id ?? undefined, |
| 83 | directory: row.directory, |
| 84 | path: row.path ?? undefined, |
| 85 | parentID: row.parent_id ?? undefined, |
| 86 | title: row.title, |
| 87 | agent: row.agent ?? undefined, |
| 88 | model: row.model |
| 89 | ? { |
| 90 | id: ModelV2.ID.make(row.model.id), |
| 91 | providerID: ProviderV2.ID.make(row.model.providerID), |
| 92 | variant: row.model.variant, |
| 93 | } |
| 94 | : undefined, |
| 95 | version: row.version, |
| 96 | summary, |
| 97 | cost: row.cost, |
| 98 | tokens: { |
| 99 | input: row.tokens_input, |
| 100 | output: row.tokens_output, |
| 101 | reasoning: row.tokens_reasoning, |
| 102 | cache: { |
| 103 | read: row.tokens_cache_read, |
| 104 | write: row.tokens_cache_write, |
| 105 | }, |
| 106 | }, |
| 107 | share, |
| 108 | metadata: row.metadata ?? undefined, |
| 109 | revert, |
| 110 | permission: row.permission ? [...row.permission] : undefined, |
| 111 | time: { |
| 112 | created: row.time_created, |
| 113 | updated: row.time_updated, |
| 114 | compacting: row.time_compacting ?? undefined, |
| 115 | archived: row.time_archived ?? undefined, |
| 116 | }, |