~bigbes/lethe

ref: b100feee542aaacd159d90f8c35b2c68a26e8893 lethe/web/src/api/adapters.ts -rw-r--r-- 1.4 KiB
b100feee — Eugene Blikh web: home route with real session list, filters, keyboard cursor a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
export type Tool = 'claude-code' | 'opencode' | 'crush' | 'pi' | 'kimi' | string
export type Host = 'laptop' | 'workpc' | string

export interface SessionDTO {
  owner: string
  tool: string
  host: string
  session_id: string
  started_at: number     // unix epoch seconds
  ended_at: number
  working_dir?: string
  source_file: string
  summary: string
  turn_count: number
  tokens_in_total: number
  tokens_out_total: number
  model?: string
  metadata?: unknown
}

export interface Session {
  id: string             // `${tool}/${host}/${session_id}`
  tool: string
  host: string
  cwd: string            // working_dir ?? ''
  model?: string
  started: string        // ISO 8601
  ended: string | null   // null if ended_at <= started_at
  summary: string
  turns: number
  tokensIn: number
  tokensOut: number
  hasError: boolean      // TODO: always false until error tracking is implemented
}

export function adaptSession(d: SessionDTO): Session {
  return {
    id: `${d.tool}/${d.host}/${d.session_id}`,
    tool: d.tool,
    host: d.host,
    cwd: d.working_dir ?? '',
    model: d.model,
    started: new Date(d.started_at * 1000).toISOString(),
    ended: d.ended_at > d.started_at ? new Date(d.ended_at * 1000).toISOString() : null,
    summary: d.summary,
    turns: d.turn_count,
    tokensIn: d.tokens_in_total,
    tokensOut: d.tokens_out_total,
    hasError: false,
  }
}