xybrid library

Xybrid - Hybrid cloud-edge ML inference orchestrator.

This library provides a clean Dart API for running ML models on-device or in the cloud, with intelligent routing based on device capabilities.

Initialization

You must call Xybrid.init once before using any Xybrid functionality:

void main() async {
  await Xybrid.init();
  runApp(MyApp());
}

Quick Start

// Initialize once at app startup
await Xybrid.init();

// Load a model from registry
final loader = XybridModelLoader.fromRegistry('kokoro-82m');
final model = await loader.load();

// Run text-to-speech
final envelope = XybridEnvelope.text('Hello, world!');
final result = await model.run(envelope);
final audioBytes = result.audioBytes;

Pipelines

// Load and run a pipeline
final pipeline = XybridPipeline.fromYaml('''
name: speech-to-text
stages:
  - model: whisper-small
''');
final envelope = XybridEnvelope.audio(bytes: audioData, sampleRate: 16000);
final result = await pipeline.run(envelope);

Conversation Context (LLM)

// Create conversation context for multi-turn chat
final context = ConversationContext();
context.setSystem('You are a helpful assistant.');

// Run with context
context.pushText('Hello!', MessageRole.user);
final result = await model.runWithContext(
  XybridEnvelope.text('Hello!'),
  context,
);
context.pushText(result.text ?? '', MessageRole.assistant);

Classes

Classes

AbortPolicy
Per-run abort behavior exposed to Flutter callers.
CancellationToken
Cooperative cancel handle for an in-flight batch or streaming run.
ChoiceDecision
ConversationContext
Manages multi-turn conversation history for LLM models.
DecisionAnswer
DecisionContent
Content whose original JSON order and numeric spelling survive the bridge.
DecisionOption
One choice option in caller-defined order.
DecisionQuestion
A typed question whose schema is validated by the shared native decoder.
DecisionRequest
One local decision request containing 1–16 ordered questions.
Decisions
Complete ordered decisions; partial results are never returned.
DecisionScore
One ordered probability entry; negative-infinite logits stay representable.
DecisionValue
The canonical answer value. Probability outputs are not action policies.
DeviceSnapshot
Snapshot of the routing-engine's current view of device state.
FfiDownloadStatus
Download progress, bytes and state in one consistent read, so a polling UI cannot observe a torn pair (for example Ready with a stale 0.34 progress).
FfiPartialResult
A partial transcript emitted while audio is streaming.
FfiRedactionRule
FfiTranscriptionResult
Final transcript and the workflow that covered the utterance.
FfiTtsStreamResult
Terminal synthesis status and counters, including partial cancellation.
FfiVadMode
GenerationConfig
Generation parameters for LLM inference.
ImagePlane
One memory plane inside a raw pixel image.
LoadComplete
Model loading completed successfully.
LoadError
Model loading failed with an error.
LoadEvent
Event emitted during model loading with progress tracking.
LoadProgress
Download progress update.
ObservabilityConfig
Export configuration. Xybrid sends traces only; a Collector receives traces, metrics and logs. Prompts/outputs are captured by default unless metadataOnly is true (or disabled through the native environment policy).
ObservationOptions
Observation controls. Invalid explicit traceparent values are rejected. Suppressing the detailed trace still records aggregate metrics.
RunOptions
Per-run execution and observation controls. Cloud provider/model/gateway overrides and fallback permission apply to runStreamingWithFallback.
ScoreDecision
StreamToken
A single token emitted during streaming generation.
ToolCall
One tool call the model emitted this turn.
ToolDefinition
A tool the model may ask to call.
ToolResult
The outcome of running one tool, fed back to the model next turn.
Xybrid
Main entry point for the Xybrid SDK.
XybridEnvelope
Envelope containing input data for model inference.
XybridInferenceMetrics
Typed inference metrics surfaced on every XybridResult.
XybridModel
XybridModelLoader
Prepares a model for loading from the registry, Hugging Face, a local bundle or directory, or a raw GGUF file.
XybridObservability
Native observer control plane. Call after Xybrid.init(). All export runs in Rust; Dart supplies configuration and W3C context, never span batches.
XybridPipeline
A loaded pipeline ready for multi-stage inference.
XybridResult
Result of a model inference operation.
XybridStageLatency
Per-stage latency entry for pipeline runs.
XybridStreamSession
A live speech-to-text session that transcribes audio as it is fed.
YesNoDecision
YuvColorInfo
Color metadata required for raw YUV camera frames (nv12, nv21, i420).

Enums

AbortSignal
Resource or cancellation signals that can stop a local run.
DecisionOrigin
FfiDownloadState
Lifecycle of a model download.
FfiExecutionTarget
Where a result was produced — the observed fact, not a routing preference.
FfiTtsStatus
MemoryPressure
Derived memory-pressure classification from available / total.
MessageRole
Message role for conversation turns.
PixelFormat
Raw pixel-buffer format accepted by XybridEnvelope.imageRaw.
ScoreStatistic
ThermalState
Thermal pressure classification matching the desktop pollers' Celsius bands (Normal < 60, Warm 60–70, Hot 70–80, Critical >= 80).
YuvColorMatrix
YUV color conversion matrix for raw YUV camera frames.
YuvColorRange
YUV luma/chroma numeric range.

Functions

jsonSchemaToGbnf({required String schemaJson}) → String
Convert a JSON Schema (as a JSON string) into a GBNF grammar for `FfiGenerationConfig::grammar`.
wrapInWavHeader(Uint8List pcmBytes, {required int sampleRate, required int channels}) → Uint8List
Wraps raw PCM audio bytes in a WAV header for playback.

Typedefs

CacheEntry = FfiCacheEntry
A physical model entry occupying managed cache storage.
CacheEntryLocation = FfiCacheEntryLocation
The managed storage area containing a CacheEntry.
CacheStatus = FfiCacheStatus
Aggregate storage usage across all managed model-cache areas.
ExecutionLocation = FfiExecutionLocation
InferenceObservation = FfiInferenceObservation
InferenceRequest = FfiInferenceRequest
ModelLoadInfo = FfiModelLoadInfo
ModelLoadObservation = FfiModelLoadObservation
ObservabilityStats = FfiObservabilityStats
Native exporter status and delivery counters.
ObservationContext = FfiObservationContext
ObservationRef = FfiObservationRef
Trace and span identifiers returned by a traced inference.
ObservationUsage = FfiUsage
ToolCallInfo = FfiToolCallInfo
ToolObservation = FfiToolObservation
WorkflowObservation = FfiWorkflowObservation
Manual native handles. Dispose unfinished handles to cancel without flushing.

Exceptions / Errors

XybridException
Exception thrown when Xybrid operations fail.