1 // This file is automatically generated, so please do not edit it.
2 // @generated by `flutter_rust_bridge`@ 2.12.0.
3
4 // ignore_for_file: type=lint, unused_import, unnecessary_import
5
6 // ignore_for_file: invalid_use_of_internal_member
7
8 import 'frb_generated.dart';
9 import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
10 import 'package:freezed_annotation/freezed_annotation.dart' hide protected;
11 part 'api.freezed.dart';
12
13 // These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `assert_fields_are_eq`, `assert_fields_are_eq`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `eq`, `eq`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `from`, `from`, `from`, `from`, `from`, `from`, `from`, `from`, `from`, `from`, `from`, `from`, `from`, `from`
14
15 /// Return the platform-appropriate default `GgufModelConfig`.
16 ///
17 /// Selects the 1.5B model on iOS / tvOS / Android and the 3B model on
18 /// macOS / Windows / Linux.
19 GgufModelConfig defaultModelConfig() =>
20 RustLib.instance.api.crateApiDefaultModelConfig();
21
22 /// `GgufModelConfig` for Qwen 2.5 1.5B Instruct Q4_K_M (~941 MB).
23 GgufModelConfig qwen2515BConfig() =>
24 RustLib.instance.api.crateApiQwen2515BConfig();
25
26 /// `GgufModelConfig` for Qwen 2.5 3B Instruct Q4_K_M (~1.93 GB).
27 GgufModelConfig qwen253BConfig() =>
28 RustLib.instance.api.crateApiQwen253BConfig();
29
30 /// `GgufModelConfig` for Qwen 2.5 Coder 1.5B Instruct Q4_K_M (~941 MB).
31 GgufModelConfig qwen25Coder15BConfig() =>
32 RustLib.instance.api.crateApiQwen25Coder15BConfig();
33
34 /// `GgufModelConfig` for Qwen 2.5 Coder 3B Instruct Q4_K_M (~1.93 GB).
35 GgufModelConfig qwen25Coder3BConfig() =>
36 RustLib.instance.api.crateApiQwen25Coder3BConfig();
37
38 /// `GgufModelConfig` for Qwen 3 0.6B Q4_K_M (~0.5 GB).
39 GgufModelConfig qwen306BConfig() =>
40 RustLib.instance.api.crateApiQwen306BConfig();
41
42 /// `GgufModelConfig` for Qwen 3 1.7B Q4_K_M (~1.3 GB).
43 GgufModelConfig qwen317BConfig() =>
44 RustLib.instance.api.crateApiQwen317BConfig();
45
46 /// `GgufModelConfig` for Qwen 3 4B Q4_K_M (~2.7 GB).
47 GgufModelConfig qwen34BConfig() => RustLib.instance.api.crateApiQwen34BConfig();
48
49 /// `GgufModelConfig` for Qwen 3 8B Q4_K_M (~5 GB).
50 GgufModelConfig qwen38BConfig() => RustLib.instance.api.crateApiQwen38BConfig();
51
52 /// `GgufModelConfig` for Qwen 3 14B Q4_K_M (~8.4 GB).
53 GgufModelConfig qwen314BConfig() =>
54 RustLib.instance.api.crateApiQwen314BConfig();
55
56 /// `GgufModelConfig` for Qwen 3 32B Q4_K_M (~19.8 GB).
57 GgufModelConfig qwen332BConfig() =>
58 RustLib.instance.api.crateApiQwen332BConfig();
59
60 /// `GgufModelConfig` for Qwen 3 4B Instruct 2507 Q4_K_M (~2.5 GB).
61 GgufModelConfig qwen34BInstruct2507Config() =>
62 RustLib.instance.api.crateApiQwen34BInstruct2507Config();
63
64 /// `GgufModelConfig` for Qwen 3 4B Thinking 2507 Q4_K_M (~2.5 GB).
65 GgufModelConfig qwen34BThinking2507Config() =>
66 RustLib.instance.api.crateApiQwen34BThinking2507Config();
67
68 /// `GgufModelConfig` for Qwen 3 30B-A3B Instruct 2507 (MoE) Q4_K_M (~18.6 GB).
69 GgufModelConfig qwen330BA3BInstruct2507Config() =>
70 RustLib.instance.api.crateApiQwen330BA3BInstruct2507Config();
71
72 /// Default sampling config: `temperature=0.7`, `top_p=0.95`, `max_tokens=512`.
73 SamplingConfig defaultSamplingConfig() =>
74 RustLib.instance.api.crateApiDefaultSamplingConfig();
75
76 /// Deterministic sampling config: `temperature=0.0`, greedy, `max_tokens=512`.
77 SamplingConfig deterministicSamplingConfig() =>
78 RustLib.instance.api.crateApiDeterministicSamplingConfig();
79
80 /// Mobile sampling config: `temperature=0.7`, `top_p=0.95`, `max_tokens=128`.
81 SamplingConfig mobileSamplingConfig() =>
82 RustLib.instance.api.crateApiMobileSamplingConfig();
83
84 /// Seed the HuggingFace cache environment for sandboxed platforms.
85 ///
86 /// On iOS (and Android), the default `~/.cache/huggingface/hub` path is outside
87 /// the app sandbox and writes fail with `Operation not permitted (os error 1)`.
88 ///
89 /// Call this **once** at startup — before any `load_gguf_model` or
90 /// `download_model` — with the app's writable data directory.
91 ///
92 /// # Dart usage
93 ///
94 /// ```dart
95 /// import 'package:path_provider/path_provider.dart';
96 ///
97 /// final dir = await getApplicationSupportDirectory();
98 /// configureCacheDir(appDataDir: dir.path);
99 /// ```
100 ///
101 /// Internally this:
102 /// 1. Creates `<app_data_dir>/huggingface/hub/` if it doesn't exist.
103 /// 2. Sets the `HF_HOME` and `HF_HUB_CACHE` environment variables.
104 /// 3. Seeds `mistralrs_core::GLOBAL_HF_CACHE` so the model loader never
105 /// falls back to `Cache::default()`.
106 void configureCacheDir({required String appDataDir}) =>
107 RustLib.instance.api.crateApiConfigureCacheDir(appDataDir: appDataDir);
108
109 // Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<OndeChatEngine>>
110 abstract class OndeChatEngine implements RustOpaqueInterface {
111 /// Clear the conversation history while keeping the model loaded.
112 ///
113 /// Returns the number of turns that were removed.
114 Future<BigInt> clearHistory();
115
116 /// Clear the current system prompt.
117 Future<void> clearSystemPrompt();
118
119 /// One-shot generation from an explicit message list.
120 ///
121 /// Does **not** modify the conversation history.
122 Future<InferenceResult> generate({
123 required List<ChatMessage> messages,
124 SamplingConfig? sampling,
125 });
126
127 /// Returns a clone of the full conversation history.
128 Future<List<ChatMessage>> history();
129
130 /// Returns a point-in-time snapshot of the engine's state.
131 Future<EngineInfo> info();
132
133 /// Returns `true` if a model is currently loaded and ready.
134 Future<bool> isLoaded();
135
136 /// Load the model assigned to this Onde app from the dashboard.
137 ///
138 /// Returns the wall-clock seconds taken to load the model.
139 Future<double> loadAssignedModel({
140 required String appId,
141 required String appSecret,
142 String? systemPrompt,
143 SamplingConfig? sampling,
144 });
145
146 /// Load a GGUF model into the engine.
147 ///
148 /// Returns the load duration in seconds on success.
149 Future<double> loadGgufModel({
150 required GgufModelConfig config,
151 String? systemPrompt,
152 SamplingConfig? sampling,
153 });
154
155 /// Create a new engine with no model loaded.
156 factory OndeChatEngine() => RustLib.instance.api.crateApiOndeChatEngineNew();
157
158 /// Append a message to history without running inference.
159 ///
160 /// Useful for restoring a saved conversation or injecting context.
161 Future<void> pushHistory({required ChatMessage message});
162
163 /// Send a user message and receive a complete assistant reply.
164 ///
165 /// Both the user message and assistant reply are appended to the
166 /// conversation history on success.
167 Future<InferenceResult> sendMessage({required String message});
168
169 /// Replace the sampling configuration used for all subsequent inference.
170 Future<void> setSampling({required SamplingConfig sampling});
171
172 /// Set or replace the system prompt.
173 ///
174 /// The prompt is prepended to every inference request and is **not**
175 /// stored in the conversation history.
176 Future<void> setSystemPrompt({required String prompt});
177
178 /// Stream a reply token-by-token.
179 ///
180 /// Each [`StreamChunk`] carries a `delta` string. The final chunk has
181 /// `done == true`. The `sink` is closed automatically when the stream
182 /// ends or if the receiver is dropped.
183 Stream<StreamChunk> streamMessage({required String message});
184
185 /// Unload the current model and release its memory.
186 ///
187 /// Returns the display name of the model that was unloaded, or `None`
188 /// if no model was loaded.
189 Future<String?> unloadModel();
190 }
191
192 /// A single message in a conversation.
193 class ChatMessage {
194 final ChatRole role;
195 final String content;
196
197 const ChatMessage({required this.role, required this.content});
198
199 @override
200 int get hashCode => role.hashCode ^ content.hashCode;
201
202 @override
203 bool operator ==(Object other) =>
204 identical(this, other) ||
205 other is ChatMessage &&
206 runtimeType == other.runtimeType &&
207 role == other.role &&
208 content == other.content;
209 }
210
211 /// Role of a participant in a chat conversation.
212 enum ChatRole { system, user, assistant }
213
214 /// A point-in-time snapshot of the engine's state.
215 class EngineInfo {
216 final EngineStatus status;
217
218 /// Display name of the currently loaded model, if any.
219 final String? modelName;
220
221 /// Approximate memory footprint of the loaded model, if any.
222 final String? approxMemory;
223
224 /// Number of conversation turns in the current history.
225 final BigInt historyLength;
226
227 const EngineInfo({
228 required this.status,
229 this.modelName,
230 this.approxMemory,
231 required this.historyLength,
232 });
233
234 @override
235 int get hashCode =>
236 status.hashCode ^
237 modelName.hashCode ^
238 approxMemory.hashCode ^
239 historyLength.hashCode;
240
241 @override
242 bool operator ==(Object other) =>
243 identical(this, other) ||
244 other is EngineInfo &&
245 runtimeType == other.runtimeType &&
246 status == other.status &&
247 modelName == other.modelName &&
248 approxMemory == other.approxMemory &&
249 historyLength == other.historyLength;
250 }
251
252 /// Lifecycle status of the inference engine.
253 enum EngineStatus { unloaded, loading, ready, generating, error }
254
255 /// Configuration for loading a pre-quantised GGUF model.
256 class GgufModelConfig {
257 /// HuggingFace repository ID, e.g. `"bartowski/Qwen2.5-1.5B-Instruct-GGUF"`.
258 final String modelId;
259
260 /// GGUF filename(s) within the repository.
261 final List<String> files;
262
263 /// Optional explicit tokenizer model ID (required on Android).
264 final String? tokModelId;
265
266 /// Human-friendly display name, e.g. `"Qwen 2.5 1.5B"`.
267 final String displayName;
268
269 /// Approximate memory footprint, e.g. `"~941 MB (GGUF Q4_K_M)"`.
270 final String approxMemory;
271
272 const GgufModelConfig({
273 required this.modelId,
274 required this.files,
275 this.tokModelId,
276 required this.displayName,
277 required this.approxMemory,
278 });
279
280 @override
281 int get hashCode =>
282 modelId.hashCode ^
283 files.hashCode ^
284 tokModelId.hashCode ^
285 displayName.hashCode ^
286 approxMemory.hashCode;
287
288 @override
289 bool operator ==(Object other) =>
290 identical(this, other) ||
291 other is GgufModelConfig &&
292 runtimeType == other.runtimeType &&
293 modelId == other.modelId &&
294 files == other.files &&
295 tokModelId == other.tokModelId &&
296 displayName == other.displayName &&
297 approxMemory == other.approxMemory;
298 }
299
300 /// The result of a completed inference request.
301 class InferenceResult {
302 /// The generated assistant reply text.
303 final String text;
304
305 /// Wall-clock inference duration in seconds.
306 final double durationSecs;
307
308 /// Human-readable duration string, e.g. `"4.5s"` or `"2m 3.1s"`.
309 final String durationDisplay;
310
311 /// Finish reason reported by the model, e.g. `"stop"` or `"length"`.
312 final String finishReason;
313
314 /// Tool calls requested by the model (empty if none).
315 final List<ToolCallInfo> toolCalls;
316
317 const InferenceResult({
318 required this.text,
319 required this.durationSecs,
320 required this.durationDisplay,
321 required this.finishReason,
322 required this.toolCalls,
323 });
324
325 @override
326 int get hashCode =>
327 text.hashCode ^
328 durationSecs.hashCode ^
329 durationDisplay.hashCode ^
330 finishReason.hashCode ^
331 toolCalls.hashCode;
332
333 @override
334 bool operator ==(Object other) =>
335 identical(this, other) ||
336 other is InferenceResult &&
337 runtimeType == other.runtimeType &&
338 text == other.text &&
339 durationSecs == other.durationSecs &&
340 durationDisplay == other.durationDisplay &&
341 finishReason == other.finishReason &&
342 toolCalls == other.toolCalls;
343 }
344
345 @freezed
346 sealed class OndeError with _$OndeError implements FrbException {
347 const OndeError._();
348
349 const factory OndeError.noModelLoaded() = OndeError_NoModelLoaded;
350 const factory OndeError.alreadyLoaded({required String modelName}) =
351 OndeError_AlreadyLoaded;
352 const factory OndeError.modelBuild({required String reason}) =
353 OndeError_ModelBuild;
354 const factory OndeError.inference({required String reason}) =
355 OndeError_Inference;
356 const factory OndeError.cancelled() = OndeError_Cancelled;
357 const factory OndeError.other({required String reason}) = OndeError_Other;
358 }
359
360 /// Sampling parameters for text generation. All fields are optional — `None`
361 /// means "use the engine default".
362 class SamplingConfig {
363 final double? temperature;
364 final double? topP;
365 final BigInt? topK;
366 final double? minP;
367 final BigInt? maxTokens;
368 final double? frequencyPenalty;
369 final double? presencePenalty;
370
371 const SamplingConfig({
372 this.temperature,
373 this.topP,
374 this.topK,
375 this.minP,
376 this.maxTokens,
377 this.frequencyPenalty,
378 this.presencePenalty,
379 });
380
381 @override
382 int get hashCode =>
383 temperature.hashCode ^
384 topP.hashCode ^
385 topK.hashCode ^
386 minP.hashCode ^
387 maxTokens.hashCode ^
388 frequencyPenalty.hashCode ^
389 presencePenalty.hashCode;
390
391 @override
392 bool operator ==(Object other) =>
393 identical(this, other) ||
394 other is SamplingConfig &&
395 runtimeType == other.runtimeType &&
396 temperature == other.temperature &&
397 topP == other.topP &&
398 topK == other.topK &&
399 minP == other.minP &&
400 maxTokens == other.maxTokens &&
401 frequencyPenalty == other.frequencyPenalty &&
402 presencePenalty == other.presencePenalty;
403 }
404
405 /// A single streaming token chunk emitted during inference.
406 class StreamChunk {
407 /// The token text delta (may be empty on the final chunk).
408 final String delta;
409
410 /// `true` when this is the last chunk in the stream.
411 final bool done;
412
413 /// Finish reason (set only on the final chunk).
414 final String? finishReason;
415
416 const StreamChunk({
417 required this.delta,
418 required this.done,
419 this.finishReason,
420 });
421
422 @override
423 int get hashCode => delta.hashCode ^ done.hashCode ^ finishReason.hashCode;
424
425 @override
426 bool operator ==(Object other) =>
427 identical(this, other) ||
428 other is StreamChunk &&
429 runtimeType == other.runtimeType &&
430 delta == other.delta &&
431 done == other.done &&
432 finishReason == other.finishReason;
433 }
434
435 /// Structured tool-call request emitted by the model.
436 class ToolCallInfo {
437 final String id;
438 final String functionName;
439 final String arguments;
440
441 const ToolCallInfo({
442 required this.id,
443 required this.functionName,
444 required this.arguments,
445 });
446
447 @override
448 int get hashCode => id.hashCode ^ functionName.hashCode ^ arguments.hashCode;
449
450 @override
451 bool operator ==(Object other) =>
452 identical(this, other) ||
453 other is ToolCallInfo &&
454 runtimeType == other.runtimeType &&
455 id == other.id &&
456 functionName == other.functionName &&
457 arguments == other.arguments;
458 }