Spaces:
Running
Running
| 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; | |
| } | |