File size: 4,897 Bytes
0ed8124
 
 
 
 
 
 
 
 
 
 
 
 
21ad36a
0ed8124
21ad36a
0ed8124
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c3633b1
0ed8124
 
 
b4f163f
 
 
 
 
0ed8124
 
 
 
 
 
 
 
b4f163f
0ed8124
 
 
 
 
6c62075
 
 
 
 
 
 
 
 
0ed8124
 
 
 
 
 
 
 
 
c3633b1
 
 
 
 
 
0ed8124
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c3633b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0ed8124
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c62075
 
 
0ed8124
c3633b1
0ed8124
 
 
 
 
 
 
 
 
 
 
 
 
21ad36a
0ed8124
 
 
 
 
 
 
 
6c62075
 
 
 
 
0ed8124
 
 
 
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import type { ModelTierId, RequestedBackend } from '../engine';
import type { ArtifactDocument } from './agent-tools';

export type ModelId = 'bonsai-1.7b' | 'bonsai-4b' | 'bonsai-8b' | 'bonsai-27b';

export type Availability = 'loaded' | 'cached' | 'remote' | 'limited' | 'loading';

export type StreamState = 'idle' | 'loading' | 'streaming' | 'complete' | 'error';

export interface ModelOption {
  id: ModelId;
  manifestId: ModelTierId;
  label: string;
  architectureLabel: string;
  parameters: string;
  runtimeLabel: string;
  footprint: string;
  availability: Availability;
  contextLimit: number;
  defaultContext: number;
  limitReason?: string;
}

export interface ToolRun {
  id: string;
  name: string;
  input: string;
  output?: string;
  state: 'queued' | 'running' | 'complete' | 'error';
}

export interface MessageMetrics {
  tokens: number;
  tokensPerSecond: number;
  promptTokensPerSecond?: number;
  timeToFirstTokenMs: number;
}

export interface ToolCallActivity {
  name: string;
  argumentCharacters: number;
}

export interface ChatMessage {
  id: string;
  role: 'user' | 'assistant' | 'system';
  content: string;
  reasoning?: string;
  isThinking?: boolean;
  timestamp: string;
  state?: StreamState;
  toolActivity?: ToolCallActivity;
  tools?: ToolRun[];
  metrics?: MessageMetrics;
  error?: string;
}

export interface ChatSession {
  id: string;
  title: string;
  messages: ChatMessage[];
  modelId: ModelId;
  systemPrompt: string;
  updatedAt: number;
}

export interface TelemetrySnapshot {
  backend: 'WebGPU' | 'WASM' | 'Unavailable';
  device: string;
  modelMemoryBytes: number;
  kvMemoryBytes: number;
  storageUsedBytes: number;
  contextUsed: number;
  contextLimit: number;
  tokensPerSecond: number;
  prefillTokensPerSecond: number;
  decodeTokensPerSecond: number;
  inferencePhase: 'idle' | 'prefill' | 'decode' | 'complete';
  promptProcessed: number;
  promptTotal: number;
  completionTokens: number;
  timeToFirstTokenMs: number;
  gpuLayers: string;
  graphSplits: number | null;
}

export interface ToolEvent {
  id: string;
  timestamp: string;
  label: string;
  detail: string;
  state: 'running' | 'complete' | 'error';
}

export interface DownloadItem {
  modelId: ModelId;
  label: string;
  receivedBytes: number;
  totalBytes: number;
  state: 'queued' | 'downloading' | 'paused' | 'complete' | 'error';
}

export interface ShardRetryNotice {
  modelId: ModelId;
  shardIndex: number;
  shardCount: number;
  shardPath: string;
  error: string;
}

export interface StorageStatus {
  usedBytes: number;
  quotaBytes: number;
  persistent: boolean;
  downloads: DownloadItem[];
}

export interface ModelShardProgress {
  index: number;
  path: string;
  loadedBytes: number;
  verifiedBytes: number;
  totalBytes: number;
  state: 'queued' | 'cached' | 'downloading' | 'verifying' | 'complete' | 'error';
}

export interface ModelLoadProgress {
  modelId: ModelId | null;
  modelLabel: string;
  stage: 'idle' | 'manifest' | 'cache' | 'download' | 'verify' | 'load' | 'ready' | 'error';
  stageProgress: number;
  downloadedBytes: number;
  totalBytes: number;
  residentBytes: number;
  nativeStage: string | null;
  shards: ModelShardProgress[];
}

export interface RuntimeSettings {
  backend: RequestedBackend;
  contextSize: number;
  temperature: number;
  maxTokens: number;
  systemPrompt: string;
}

export interface ComposerSubmission {
  prompt: string;
  toolsEnabled: boolean;
}

export interface BonsaiShellProps {
  models: ModelOption[];
  activeModelId: ModelId;
  loadedModelId: ModelId | null;
  messages: ChatMessage[];
  conversations: ChatSession[];
  activeConversationId: string;
  conversationListOpen: boolean;
  streamState: StreamState;
  modelLoadProgress: ModelLoadProgress;
  telemetry: TelemetrySnapshot;
  toolEvents: ToolEvent[];
  storage: StorageStatus;
  artifact: ArtifactDocument | null;
  toolsEnabled: boolean;
  settings: RuntimeSettings;
  settingsOpen: boolean;
  runtimeStatus: string;
  error: string | null;
  shardRetry: ShardRetryNotice | null;
  onModelSelect: (modelId: ModelId) => void;
  onLoadModel: (modelId: ModelId) => void;
  onSend: (submission: ComposerSubmission) => void;
  onRegenerate: (messageId: string) => void;
  onCancel: () => void;
  onToolsEnabledChange: (enabled: boolean) => void;
  onOpenSettings: () => void;
  onCloseSettings: () => void;
  onSettingsChange: (settings: RuntimeSettings) => void;
  onPersistStorage: () => void;
  onClearStorage: () => void;
  onClearConversation: () => void;
  onOpenConversationList: () => void;
  onNewConversation: () => void;
  onOpenConversation: (conversationId: string) => void;
  onOpenConversationSettings: (conversationId: string) => void;
  onDeleteConversation: (conversationId: string) => void;
  onDismissError: () => void;
  onRetryShard: (modelId: ModelId) => void;
  onCloseArtifact: () => void;
}