| 137 | } |
| 138 | |
| 139 | class ModelStore { |
| 140 | models: Model[] = []; |
| 141 | version: number | undefined = undefined; // Persisted version |
| 142 | deviceTier: Tier | null = null; // resolved device classification |
| 143 | rulesVersion: string | null = null; // provenance of the preset list |
| 144 | |
| 145 | /** |
| 146 | * Returns models with projection models filtered out for display purposes |
| 147 | */ |
| 148 | get displayModels(): Model[] { |
| 149 | return [...filterProjectionModels(this.models), ...this.remoteModels]; |
| 150 | } |
| 151 | |
| 152 | appState: AppStateStatus = AppState.currentState; |
| 153 | useAutoRelease: boolean = true; |
| 154 | // UI loading state - true during model load/release transitions |
| 155 | isContextLoading: boolean = false; |
| 156 | loadingModel: Model | undefined = undefined; |
| 157 | |
| 158 | // Unified context initialization parameters |
| 159 | contextInitParams: ContextInitParams = createDefaultContextInitParams(); |
| 160 | |
| 161 | max_threads: number = 4; // Will be set in constructor |
| 162 | |
| 163 | activeModelId: string | undefined = undefined; |
| 164 | |
| 165 | // Flag to track if multimodal is currently active |
| 166 | isMultimodalActive: boolean = false; |
| 167 | activeProjectionModelId: string | undefined = undefined; |
| 168 | |
| 169 | // Track initialization settings for the active context |
| 170 | activeContextSettings: ContextInitParams | undefined = undefined; |
| 171 | |
| 172 | context: LlamaContext | undefined = undefined; |
| 173 | |
| 174 | engine: CompletionEngine | undefined = undefined; |
| 175 | |
| 176 | lastUsedModelId: string | undefined = undefined; |
| 177 | |
| 178 | // Auto-release tracking (persistent) |
| 179 | wasAutoReleased: boolean = false; |
| 180 | lastAutoReleasedModelId: string | undefined = undefined; |
| 181 | |
| 182 | // System UI protection (runtime) |
| 183 | private autoReleaseDisabledReasons = new Set<string>(); |
| 184 | |
| 185 | MIN_CONTEXT_SIZE = 200; |
| 186 | |
| 187 | inferencing: boolean = false; |
| 188 | isStreaming: boolean = false; |
| 189 | |
| 190 | // Track active completion promise for safe context release |
| 191 | // This prevents race condition where context is freed while completion is still running |
| 192 | private activeCompletionPromise: Promise<any> | null = null; |
| 193 | |
| 194 | // Mutex to serialize model load/release operations to prevent memory leaks |
| 195 | private contextOperationMutex: Promise<void> = Promise.resolve(); |
| 196 |
nothing calls this directly
no test coverage detected