Repository navigation
Expand file tree
/
Copy pathai-hud-state.ts
More file actions
77 lines (73 loc) · 2.11 KB
/
Copy pathai-hud-state.ts
File metadata and controls
77 lines (73 loc) · 2.11 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
import type { AiConversationExcerpt } from "./ai-history";
import type {
AiConversationTurn,
AiRealtimePhase,
AiRealtimeProtocolState,
} from "./ai-realtime-protocol";
import { createAiTranscriptLines } from "./ai-transcript";
import type { AiMcpApproval } from "./ai-realtime-tools";
import type { AiActiveTool } from "./ai-realtime-tools";
export type AiHudPhase = "unconfigured" | "displaying" | AiRealtimePhase;
export type AiHudSnapshot = {
readonly configured: boolean;
readonly phase: AiHudPhase;
readonly userText: string;
readonly assistantText: string;
readonly turns: readonly AiConversationTurn[];
readonly transcriptLines: readonly string[];
readonly history: readonly AiConversationExcerpt[];
readonly weekUsd: number;
readonly monthUsd: number;
readonly hasUnpricedUsage: boolean;
readonly responseComplete: boolean;
readonly canRevealFullResponse: boolean;
readonly activeTool?: AiActiveTool;
readonly pendingApproval?: AiMcpApproval;
readonly error?: string;
};
export function createAiHudSnapshot(
configured: boolean,
history: readonly AiConversationExcerpt[] = [],
weekUsd = 0,
monthUsd = 0,
hasUnpricedUsage = false,
): AiHudSnapshot {
return {
configured,
phase: configured ? "idle" : "unconfigured",
userText: "",
assistantText: "",
turns: [],
transcriptLines: [],
history: history.slice(0, 3),
weekUsd,
monthUsd,
hasUnpricedUsage,
responseComplete: false,
canRevealFullResponse: false,
};
}
export function updateAiHudProtocol(
current: AiHudSnapshot,
protocol: AiRealtimeProtocolState,
): AiHudSnapshot {
return {
...current,
phase: protocol.phase,
userText: protocol.userText,
assistantText: protocol.assistantText,
turns: protocol.turns,
transcriptLines: createAiTranscriptLines(
protocol.turns,
{
user: protocol.userText,
assistant: protocol.assistantText,
},
),
pendingApproval: protocol.pendingApproval,
activeTool: protocol.activeTool,
responseComplete: protocol.responseComplete,
canRevealFullResponse: false,
error: protocol.error,
};
}