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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
// Allow dead code in alpha crate — many modules are scaffolded but not yet wired up.
// TODO: Remove this as modules mature and are integrated.
// Pre-existing style lints — fix incrementally, not all at once.
// TODO: Address these and remove the allows.
//! Xybrid Core
//!
//! ## Quick Start
//!
//! Use the [`prelude`] module for common imports:
//!
//! ```rust,ignore
//! use xybrid_core::prelude::*;
//!
//! // Create an executor and run inference
//! let mut executor = TemplateExecutor::with_base_path("models/whisper");
//! let input = Envelope::from_audio(audio_bytes);
//! let output = executor.execute(&metadata, &input)?;
//! ```
//!
//! ## Module Organization
//!
//! The crate is organized into logical groups:
//!
//! ### Core Execution (see `EXECUTION_LAYERS.md`)
//! - [`orchestrator`] - High-level pipeline coordination
//! - [`executor`] - Stage execution with adapter selection
//! - [`template_executor`] - Metadata-driven model inference
//!
//! ### Data Types
//! - [`ir`] - Intermediate representation (Envelope, EnvelopeKind)
//! - [`context`] - Device metrics and stage descriptors
//! - [`execution_template`] - Model metadata schema
//!
//! ### Runtime
//! - [`runtime_adapter`] - ONNX session management
//! - [`pipeline`] - Pipeline configuration and execution
//! - [`streaming`] - Real-time audio streaming
//!
//! ### Bundles
//! - [`bundler`] - .xyb bundle creation and extraction
//!
//! ### High-Level APIs
//! - [`cloud`] - Cloud client (third-party API integrations)
//! - [`tts`] - Text-to-speech client
//! - [`gateway`] - OpenAI-compatible gateway types
//!
//! ## Public vs Internal Modules
//!
//! Modules marked with `#[doc(hidden)]` are internal implementation details
//! and may change without notice. Use the public API modules listed above.
// ============================================================================
// Feature Combination Guards
// These compile_error! blocks prevent invalid feature combinations at build time.
// See docs/FEATURE_MATRIX.md for valid combinations.
// ============================================================================
// llm-mistral uses x86 AVX2/FP16 intrinsics that cause SIGILL on Android ARM devices
// without ARMv8.2-A FP16 extensions (which most devices lack).
// Use llm-llamacpp instead - it has runtime SIMD detection.
compile_error!;
// ort-download and ort-dynamic are mutually exclusive ORT loading strategies.
// ort-download: Downloads prebuilt ONNX Runtime binaries at build time (desktop/iOS).
// ort-dynamic: Loads .so/.dylib at runtime from platform-specific location (Android AAR).
compile_error!;
// candle-metal requires Apple's Metal GPU framework (macOS/iOS only).
compile_error!;
// candle-cuda requires NVIDIA CUDA which is not available on Apple platforms.
compile_error!;
// ort-coreml enables Apple's CoreML/Neural Engine acceleration (macOS/iOS only).
compile_error!;
/// Version of the `xybrid-core` crate, sourced from Cargo metadata at compile time.
///
/// Re-exported by `xybrid-sdk` so registry telemetry headers can report the
/// runtime core version without a parallel constant.
pub const VERSION: &str = env!;
// ============================================================================
// Prelude - Common imports for convenience
// ============================================================================
/// Common imports for xybrid-core users.
///
/// # Example
///
/// ```rust,ignore
/// use xybrid_core::prelude::*;
/// ```
/// Unified error types for xybrid-core public API.
///
/// This module provides the canonical error hierarchy:
/// - [`XybridError`](error::XybridError) - Top-level error type
/// - [`InferenceError`](error::InferenceError) - Model inference failures
/// - [`PipelineError`](error::PipelineError) - Pipeline execution failures
///
/// # Example
///
/// ```rust,ignore
/// use xybrid_core::error::{XybridError, XybridResult};
///
/// fn run_model() -> XybridResult<String> {
/// // ...
/// }
/// ```
pub use ;
/// Typed abort reasons shared by execution, routing feedback, and SDK wrappers.
// ============================================================================
// Core Execution Layer (Orchestrator → Executor → TemplateExecutor)
// See EXECUTION_LAYERS.md for architecture documentation
// ============================================================================
/// High-level pipeline orchestration (policy, routing, streaming)
/// Stage execution with adapter selection
/// Unified execution module (template schema + executor)
///
/// This module contains:
/// - [`execution::template`] - Model metadata schema (model_metadata.json)
/// - [`execution::TemplateExecutor`] - Metadata-driven inference engine
/// - [`execution::modes`] - Execution modes (SingleShot, Autoregressive, Whisper, TTS)
// Backwards compatibility: re-export old module paths
// TODO: Deprecate these in a future version
/// Deprecated: use `execution` module instead
/// Cache provider abstraction for model availability checks.
/// Allows Core to check cache without depending on SDK.
/// Runtime feature-flag introspection (which backends were compiled in).
// ============================================================================
// Data Types & Intermediate Representation
// ============================================================================
/// Envelope-based data passing (Audio, Text, Embedding)
/// Conversation context for multi-turn LLM interactions
/// Device metrics and stage descriptors
// Backwards compatibility: re-export execution::template as execution_template
/// Deprecated: use `execution::template` instead
// ============================================================================
// Runtime & Pipeline Execution
// ============================================================================
/// ONNX runtime adapter and session management
/// Pipeline configuration, stages, and runners
/// Pipeline DSL configuration (unified schema for CLI and SDK)
/// Real-time audio streaming infrastructure
// ============================================================================
// Audio & Domain APIs
// ============================================================================
/// Audio processing (mel spectrogram, WAV decode)
/// .xyb bundle creation and extraction
/// Device detection (CPU, GPU, Metal, NNAPI)
// ============================================================================
// High-Level Client APIs
// ============================================================================
/// Cloud client (third-party API integrations via gateway or direct)
/// For local/on-device inference, use `target: device` in pipeline YAML.
/// TTS client (text-to-speech)
/// OpenAI-compatible gateway types
/// HTTP utilities (retry logic, circuit breakers)
// ============================================================================
// Internal Modules (implementation details, may change without notice)
// ============================================================================
/// Execution target definitions (local, edge, cloud)
/// Stage name parsing and resolution
/// Preprocessing utilities (audio bytes to mel)
/// Text-to-phoneme conversion for TTS
/// Telemetry collection
/// Distributed tracing
/// Event bus for orchestrator events
/// Control plane synchronization
/// Universal architecture system (model configuration)
/// Testing utilities (mocks, fixtures)
// ============================================================================
// Crate-Internal Modules
// ============================================================================
/// Cloud LLM provider implementations (internal)
pub