forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatContent.ts
More file actions
150 lines (139 loc) · 5.35 KB
/
Copy pathchatContent.ts
File metadata and controls
150 lines (139 loc) · 5.35 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Published chat rendering contract for the Windows port. Sibling tracks (chat
// UI, agent timeline) code against these shapes. Types only — no rendering here.
//
// Mirrors macOS `Desktop/Sources/Providers/ChatProvider.swift` (ChatContentBlock,
// ToolCallStatus, ToolCallInput), `Chat/ChatResource.swift`,
// `Chat/ChatErrorState.swift`, and backend `backend/models/chat.py` (ChartData).
/** Lifecycle of a tool call. `slow`/`stalled` are still in-flight (promoted by
* the stall detector); only `completed`/`failed` are terminal. Mirrors macOS
* ChatProvider.swift `ToolCallStatus`. */
export type ToolCallStatus = 'running' | 'slow' | 'stalled' | 'completed' | 'failed'
/** Tool-call arguments for display. `summary` is the inline one-liner (path,
* command); `details` is the full JSON for the expanded view. Mirrors macOS
* ChatProvider.swift `ToolCallInput`. */
export interface ToolCallInput {
summary: string
details?: string
}
/**
* A block of content within an AI message. Discriminated union on `type`,
* mirroring macOS `ChatContentBlock` (ChatProvider.swift:165-191). Citations,
* resources (ChatResource), chart data, error state, and typing are SIBLING
* concerns rendered alongside blocks — they are NOT block kinds.
*
* Render-time pruning rule (for the future renderer PR, matching macOS):
* - `thinking` blocks are dropped once the stream for that turn completes.
* - `completed` tool-call groups are dropped after the turn settles, EXCEPT
* agent-related blocks (agentSpawn / agentCompletion), which persist.
*/
export type ChatContentBlock =
// Markdown text, including GFM tables (the renderer handles tables inline).
| { type: 'text'; id: string; text: string }
// A tool invocation. `output` lives on the same block (no separate
// tool_result block); status drives the inline spinner/label.
| {
type: 'toolCall'
id: string
name: string
status: ToolCallStatus
toolUseId?: string
input?: ToolCallInput
output?: string
}
// Model reasoning (pruned post-stream — see the rule above).
| { type: 'thinking'; id: string; text: string }
// Collapsible card with a summary + expandable full text (AI profile/discovery).
| { type: 'discoveryCard'; id: string; title: string; summary: string; fullText: string }
// A background agent was spawned from this turn (projects into a pill).
| {
type: 'agentSpawn'
id: string
pillId?: string
sessionId: string
runId: string
title: string
objective: string
}
// A background agent finished; carries its output + terminal status.
| {
type: 'agentCompletion'
id: string
pillId?: string
sessionId?: string
runId?: string
title: string
promptSnippet: string
output: string
status: string
}
/** Where a chat resource card came from. Mirrors macOS `ChatResourceOrigin`. */
export type ChatResourceOrigin = 'userAttachment' | 'generatedArtifact'
/** Lifecycle state of a chat resource card. Mirrors macOS `ChatResource.State`
* (the `failed` case's associated message is carried out-of-band in the UI). */
export type ChatResourceState =
| 'uploading'
| 'ready'
| 'failed'
| 'retained'
| 'opened'
| 'dismissed'
/**
* Resource / artifact card rendered in a sibling strip beside message blocks
* (user attachments and agent-generated artifacts share this shape). Mirrors
* macOS `Chat/ChatResource.swift`. Binary `imageData` from the Swift model is
* intentionally omitted here — the wire/render contract carries only references
* (`thumbnailUrl` / `uri`). Swift `thumbnailURL` is renamed `thumbnailUrl` here.
*/
export interface ChatResource {
id: string
origin: ChatResourceOrigin
title: string
subtitle?: string
mimeType?: string
thumbnailUrl?: string
uri?: string
artifactId?: string
sessionId?: string
runId?: string
state: ChatResourceState
}
/** The single primary recovery CTA on a chat error card. Mirrors macOS
* `ChatErrorRecoveryAction`. */
export type ChatErrorRecovery = 'retry' | 'signIn' | 'installRuntime' | 'dismiss'
/**
* The five recoverable, turn-level error states the chat surface renders inline
* (NOT block kinds). Mirrors macOS `Chat/ChatErrorState.swift`. Errors outside
* these five fall through to the generic error banner / dedicated sheets.
*/
export type ChatErrorState =
| { kind: 'authRequired' }
| { kind: 'timeout'; toolName?: string }
| { kind: 'bridgeUnavailable'; reason: 'nodeMissing' | 'runtimeMissing' | 'crashed' | 'unknown' }
| { kind: 'interrupted' }
| { kind: 'noDataFound' }
/** One (label, value) point in a chart dataset. Mirrors backend
* `chat.py:ChartDataPoint`. */
export interface ChartDataPoint {
label: string
value: number
}
/** A named series of chart points. `color` is an optional hex string. Mirrors
* backend `chat.py:ChartDataset` (`data_points` → `dataPoints`). */
export interface ChartDataset {
label: string
dataPoints: ChartDataPoint[]
color?: string
}
/**
* Backend-supplied chart payload for a chat message. Windows-only renderer
* (macOS has no chart UI) — type published here, no UI in this PR. Mirrors
* backend `chat.py:ChartData` (`chart_type` → `chartType`, `x_label` → `xLabel`,
* `y_label` → `yLabel`).
*/
export interface ChartData {
chartType: 'line' | 'bar'
title: string
xLabel?: string
yLabel?: string
datasets: ChartDataset[]
}