@xybrid/react-native 0.10.0-rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +298 -0
- package/android/build.gradle +61 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/ai/xybrid/reactnative/XybridCodec.kt +481 -0
- package/android/src/main/java/ai/xybrid/reactnative/XybridHandles.kt +139 -0
- package/android/src/main/java/ai/xybrid/reactnative/XybridModule.kt +665 -0
- package/android/src/main/java/ai/xybrid/reactnative/XybridPackage.kt +27 -0
- package/ios/XybridCodec.swift +508 -0
- package/ios/XybridHandles.swift +191 -0
- package/ios/XybridModule.mm +494 -0
- package/ios/XybridModuleImpl.swift +887 -0
- package/ios/XybridSwift/Xybrid.swift +1401 -0
- package/ios/XybridSwift/xybrid_bolt.swift +3198 -0
- package/ios/xybrid_natives.rb +178 -0
- package/lib/commonjs/NativeXybrid.js +24 -0
- package/lib/commonjs/base64.js +45 -0
- package/lib/commonjs/cancel.js +35 -0
- package/lib/commonjs/context.js +67 -0
- package/lib/commonjs/envelope.js +79 -0
- package/lib/commonjs/errors.js +61 -0
- package/lib/commonjs/index.js +59 -0
- package/lib/commonjs/model.js +307 -0
- package/lib/commonjs/pipeline.js +55 -0
- package/lib/commonjs/presets.js +32 -0
- package/lib/commonjs/session.js +76 -0
- package/lib/commonjs/types.js +10 -0
- package/lib/commonjs/wire.js +285 -0
- package/lib/commonjs/xybrid.js +133 -0
- package/lib/module/NativeXybrid.js +22 -0
- package/lib/module/base64.js +41 -0
- package/lib/module/cancel.js +29 -0
- package/lib/module/context.js +60 -0
- package/lib/module/envelope.js +73 -0
- package/lib/module/errors.js +56 -0
- package/lib/module/index.js +36 -0
- package/lib/module/model.js +298 -0
- package/lib/module/pipeline.js +48 -0
- package/lib/module/presets.js +27 -0
- package/lib/module/session.js +69 -0
- package/lib/module/types.js +9 -0
- package/lib/module/wire.js +271 -0
- package/lib/module/xybrid.js +127 -0
- package/lib/typescript/NativeXybrid.d.ts +68 -0
- package/lib/typescript/NativeXybrid.d.ts.map +1 -0
- package/lib/typescript/base64.d.ts +5 -0
- package/lib/typescript/base64.d.ts.map +1 -0
- package/lib/typescript/cancel.d.ts +24 -0
- package/lib/typescript/cancel.d.ts.map +1 -0
- package/lib/typescript/context.d.ts +40 -0
- package/lib/typescript/context.d.ts.map +1 -0
- package/lib/typescript/envelope.d.ts +51 -0
- package/lib/typescript/envelope.d.ts.map +1 -0
- package/lib/typescript/errors.d.ts +12 -0
- package/lib/typescript/errors.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +28 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/model.d.ts +211 -0
- package/lib/typescript/model.d.ts.map +1 -0
- package/lib/typescript/pipeline.d.ts +35 -0
- package/lib/typescript/pipeline.d.ts.map +1 -0
- package/lib/typescript/presets.d.ts +21 -0
- package/lib/typescript/presets.d.ts.map +1 -0
- package/lib/typescript/session.d.ts +50 -0
- package/lib/typescript/session.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +313 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/lib/typescript/wire.d.ts +130 -0
- package/lib/typescript/wire.d.ts.map +1 -0
- package/lib/typescript/xybrid.d.ts +89 -0
- package/lib/typescript/xybrid.d.ts.map +1 -0
- package/package.json +88 -0
- package/react-native-xybrid.podspec +50 -0
- package/src/NativeXybrid.ts +131 -0
- package/src/base64.ts +43 -0
- package/src/cancel.ts +47 -0
- package/src/context.ts +70 -0
- package/src/envelope.ts +115 -0
- package/src/errors.ts +67 -0
- package/src/index.ts +91 -0
- package/src/model.ts +408 -0
- package/src/pipeline.ts +66 -0
- package/src/presets.ts +36 -0
- package/src/session.ts +76 -0
- package/src/types.ts +362 -0
- package/src/wire.ts +408 -0
- package/src/xybrid.ts +176 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
// Public types. They mirror the bolt `#[data]` records in
|
|
2
|
+
// crates/xybrid-bolt/src/lib.rs field for field (camelCase), so a value means
|
|
3
|
+
// the same thing here as in the Swift and Kotlin SDKs. tests/parity.test.mjs
|
|
4
|
+
// fails when bolt gains a field or export that is neither mapped here nor
|
|
5
|
+
// listed as intentionally excluded in parity.json.
|
|
6
|
+
//
|
|
7
|
+
// Binary payloads (audio, images) cross as base64 strings: TurboModules have
|
|
8
|
+
// no ArrayBuffer type. See README "Binary payloads".
|
|
9
|
+
|
|
10
|
+
/** Thermal band pushed to the routing engine. */
|
|
11
|
+
export type ThermalState = 'normal' | 'warm' | 'hot' | 'critical';
|
|
12
|
+
|
|
13
|
+
/** LLM message role, stored as `xybrid.role` envelope metadata. */
|
|
14
|
+
export type MessageRole = 'system' | 'user' | 'assistant';
|
|
15
|
+
|
|
16
|
+
/** Image encodings accepted by vision-language models. */
|
|
17
|
+
export type ImageFormat = 'png' | 'jpeg' | 'webp';
|
|
18
|
+
|
|
19
|
+
/** Free-form envelope metadata. Well-known keys have typed fields instead. */
|
|
20
|
+
export type EnvelopeMetadata = Record<string, string>;
|
|
21
|
+
|
|
22
|
+
interface EnvelopeBase {
|
|
23
|
+
/** LLM message role (`xybrid.role` metadata). */
|
|
24
|
+
role?: MessageRole;
|
|
25
|
+
/** Raw metadata entries; typed fields win when both are set. */
|
|
26
|
+
metadata?: EnvelopeMetadata;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Text input: an LLM prompt, or text to speak for TTS models. */
|
|
30
|
+
export interface TextEnvelope extends EnvelopeBase {
|
|
31
|
+
kind: 'text';
|
|
32
|
+
text: string;
|
|
33
|
+
/** TTS voice (`voice_id` metadata). */
|
|
34
|
+
voiceId?: string;
|
|
35
|
+
/** TTS speed multiplier (`speed` metadata). */
|
|
36
|
+
speed?: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Audio input or output: PCM/WAV bytes. */
|
|
40
|
+
export interface AudioEnvelope extends EnvelopeBase {
|
|
41
|
+
kind: 'audio';
|
|
42
|
+
/** PCM/WAV bytes, base64-encoded. */
|
|
43
|
+
bytesBase64: string;
|
|
44
|
+
/** Sample rate in Hz (`sample_rate` metadata). Defaults to 16000 on input. */
|
|
45
|
+
sampleRate?: number;
|
|
46
|
+
/** Channel count (`channels` metadata). Defaults to 1 on input. */
|
|
47
|
+
channels?: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** An embedding vector. */
|
|
51
|
+
export interface EmbeddingEnvelope extends EnvelopeBase {
|
|
52
|
+
kind: 'embedding';
|
|
53
|
+
data: number[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** An encoded image for vision-language models. */
|
|
57
|
+
export interface ImageEnvelope extends EnvelopeBase {
|
|
58
|
+
kind: 'image';
|
|
59
|
+
/** PNG, JPEG or WebP bytes, base64-encoded. */
|
|
60
|
+
bytesBase64: string;
|
|
61
|
+
format: ImageFormat;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** A multi-part message, e.g. a prompt plus image attachments. */
|
|
65
|
+
export interface MultiPartEnvelope extends EnvelopeBase {
|
|
66
|
+
kind: 'multipart';
|
|
67
|
+
parts: Envelope[];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Input to (and output of) a model. Narrow on `kind`. */
|
|
71
|
+
export type Envelope =
|
|
72
|
+
| TextEnvelope
|
|
73
|
+
| AudioEnvelope
|
|
74
|
+
| EmbeddingEnvelope
|
|
75
|
+
| ImageEnvelope
|
|
76
|
+
| MultiPartEnvelope;
|
|
77
|
+
|
|
78
|
+
/** The payload kinds an {@link Envelope} can carry. */
|
|
79
|
+
export type EnvelopeKind = Envelope['kind'];
|
|
80
|
+
|
|
81
|
+
/** A tool (function) the model may ask to call. */
|
|
82
|
+
export interface ToolDefinition {
|
|
83
|
+
name: string;
|
|
84
|
+
description: string;
|
|
85
|
+
/**
|
|
86
|
+
* JSON Schema of the arguments, as an object or a JSON string. Crosses the
|
|
87
|
+
* boundary as a string (`parametersJson` in the other SDKs).
|
|
88
|
+
*/
|
|
89
|
+
parameters: object | string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** A tool call the model emitted. */
|
|
93
|
+
export interface ToolCall {
|
|
94
|
+
/** Echo this back as {@link ToolResult.callId}. */
|
|
95
|
+
id: string;
|
|
96
|
+
name: string;
|
|
97
|
+
/** Arguments as a JSON string, exactly as the model produced them. */
|
|
98
|
+
argumentsJson: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** The outcome of running one tool, fed back with `Envelope.toolResults`. */
|
|
102
|
+
export interface ToolResult {
|
|
103
|
+
/** The {@link ToolCall.id} this answers. */
|
|
104
|
+
callId: string;
|
|
105
|
+
name: string;
|
|
106
|
+
/**
|
|
107
|
+
* The tool's output: any JSON-serializable value, or an already-encoded
|
|
108
|
+
* JSON string.
|
|
109
|
+
*/
|
|
110
|
+
content: unknown;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Sampling parameters for LLM inference. Unset fields use model defaults. */
|
|
114
|
+
export interface GenerationConfig {
|
|
115
|
+
maxTokens?: number;
|
|
116
|
+
temperature?: number;
|
|
117
|
+
topP?: number;
|
|
118
|
+
minP?: number;
|
|
119
|
+
topK?: number;
|
|
120
|
+
repetitionPenalty?: number;
|
|
121
|
+
stopSequences?: string[];
|
|
122
|
+
/**
|
|
123
|
+
* GBNF grammar constraining output (local llama backend only). Build one
|
|
124
|
+
* from a JSON Schema with `jsonSchemaToGbnf`, or pass raw GBNF.
|
|
125
|
+
*/
|
|
126
|
+
grammar?: string;
|
|
127
|
+
/** Tools the model may call this turn. Empty means no tool calling. */
|
|
128
|
+
tools?: ToolDefinition[];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Device-stress signals that abort a run early (bolt `XybridAbortSignal`). */
|
|
132
|
+
export type AbortSignalKind =
|
|
133
|
+
| 'memoryPressureWarn'
|
|
134
|
+
| 'memoryPressureCritical'
|
|
135
|
+
| 'thermalHot'
|
|
136
|
+
| 'thermalCritical';
|
|
137
|
+
|
|
138
|
+
/** Where a result was produced — observed fact, not a routing preference. */
|
|
139
|
+
export type ExecutionTarget = 'local' | 'cloud';
|
|
140
|
+
|
|
141
|
+
/** What kind of payload a model produces. */
|
|
142
|
+
export type OutputType = 'text' | 'audio' | 'embedding' | 'unknown';
|
|
143
|
+
|
|
144
|
+
/** Latency of one pipeline stage. */
|
|
145
|
+
export interface StageLatency {
|
|
146
|
+
stageId: string;
|
|
147
|
+
latencyMs: number;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Measurements from the native runtime. LLM-only values are absent when the
|
|
152
|
+
* model or backend does not report them.
|
|
153
|
+
*/
|
|
154
|
+
export interface InferenceMetrics {
|
|
155
|
+
/** Total wall-clock inference time in milliseconds. */
|
|
156
|
+
totalMs: number;
|
|
157
|
+
/** Time to first generated token in milliseconds. */
|
|
158
|
+
ttftMs?: number;
|
|
159
|
+
/** Overall generated-token throughput. */
|
|
160
|
+
tokensPerSecond?: number;
|
|
161
|
+
/** Prompt-processing throughput. */
|
|
162
|
+
prefillTps?: number;
|
|
163
|
+
/** Generated-token decode throughput. */
|
|
164
|
+
decodeTps?: number;
|
|
165
|
+
/** Number of generated tokens. */
|
|
166
|
+
tokensOut?: number;
|
|
167
|
+
/** Per-stage measurements in native execution order. */
|
|
168
|
+
stageLatenciesMs: StageLatency[];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** The result of one inference. */
|
|
172
|
+
export interface InferenceResult {
|
|
173
|
+
/** The output, losslessly (payload plus metadata). */
|
|
174
|
+
envelope: Envelope;
|
|
175
|
+
outputType: OutputType;
|
|
176
|
+
/** The model that answered — identical on the local and cloud legs. */
|
|
177
|
+
modelId: string;
|
|
178
|
+
/** Text output, when the model produced text. */
|
|
179
|
+
text?: string;
|
|
180
|
+
/** Audio output (base64), when the model produced audio. */
|
|
181
|
+
audioBytesBase64?: string;
|
|
182
|
+
/** Embedding output, when the model produced one. */
|
|
183
|
+
embedding?: number[];
|
|
184
|
+
/**
|
|
185
|
+
* Chain-of-thought (`<think>` blocks) surfaced separately from `text`,
|
|
186
|
+
* which never includes it. Absent when the model emitted none.
|
|
187
|
+
*/
|
|
188
|
+
reasoningContent?: string;
|
|
189
|
+
/** Tool calls the model emitted this turn. Empty unless tools were offered. */
|
|
190
|
+
toolCalls: ToolCall[];
|
|
191
|
+
latencyMs: number;
|
|
192
|
+
metrics: InferenceMetrics;
|
|
193
|
+
/** Where this answer actually came from. */
|
|
194
|
+
executionTarget: ExecutionTarget;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** One token from a streaming run. */
|
|
198
|
+
export interface StreamToken {
|
|
199
|
+
/** The decoded text of this step. */
|
|
200
|
+
token: string;
|
|
201
|
+
/** Raw token id, when the backend exposes one. */
|
|
202
|
+
tokenId?: number;
|
|
203
|
+
/** Zero-based position in the generated sequence. */
|
|
204
|
+
index: number;
|
|
205
|
+
/** Every emitted token so far, concatenated (tool-call blocks suppressed). */
|
|
206
|
+
cumulativeText: string;
|
|
207
|
+
/**
|
|
208
|
+
* Set on the final token only: `'stop'`, `'length'`, or `'tool_calls'`
|
|
209
|
+
* when the turn ended on a tool-call block.
|
|
210
|
+
*/
|
|
211
|
+
finishReason?: string;
|
|
212
|
+
/** Tool calls parsed from the turn — terminal token only. */
|
|
213
|
+
toolCalls: ToolCall[];
|
|
214
|
+
/**
|
|
215
|
+
* The turn's raw output, tool-call block included — pass it to
|
|
216
|
+
* `Envelope.toolResults` as `priorAssistantText`. Present only alongside
|
|
217
|
+
* `toolCalls`.
|
|
218
|
+
*/
|
|
219
|
+
rawText?: string;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** Lifecycle of a model download. */
|
|
223
|
+
export type DownloadState = 'downloading' | 'ready' | 'failed' | 'cancelled';
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Download progress, bytes and state in one consistent read. `progress` is
|
|
227
|
+
* aggregated across every artifact, never moves backwards, and reaches 1.0
|
|
228
|
+
* only alongside `ready`.
|
|
229
|
+
*/
|
|
230
|
+
export interface DownloadStatus {
|
|
231
|
+
state: DownloadState;
|
|
232
|
+
/** 0.0 to 1.0. */
|
|
233
|
+
progress: number;
|
|
234
|
+
/** Bytes written so far, across every artifact. */
|
|
235
|
+
downloadedBytes: number;
|
|
236
|
+
/**
|
|
237
|
+
* Declared total across every artifact; absent when the source publishes
|
|
238
|
+
* no size (a Hugging Face repo, or a registry entry without one).
|
|
239
|
+
*/
|
|
240
|
+
totalBytes?: number;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** A TTS voice. */
|
|
244
|
+
export interface VoiceInfo {
|
|
245
|
+
id: string;
|
|
246
|
+
name: string;
|
|
247
|
+
gender?: string;
|
|
248
|
+
language?: string;
|
|
249
|
+
style?: string;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** Identity and capabilities of a loaded model. */
|
|
253
|
+
export interface ModelInfo {
|
|
254
|
+
/** Registry / metadata id — not the native handle. */
|
|
255
|
+
modelId: string;
|
|
256
|
+
version: string;
|
|
257
|
+
outputType: OutputType;
|
|
258
|
+
isLlm: boolean;
|
|
259
|
+
supportsStreaming: boolean;
|
|
260
|
+
/** Whether the model emits true token-by-token output. */
|
|
261
|
+
supportsTokenStreaming: boolean;
|
|
262
|
+
/**
|
|
263
|
+
* Whether the bundle declares tool-calling support; `null` when it says
|
|
264
|
+
* nothing. Advisory — enforcement happens at run time.
|
|
265
|
+
*/
|
|
266
|
+
supportsToolCalling: boolean | null;
|
|
267
|
+
hasVoices: boolean;
|
|
268
|
+
/** The model's resolved generation defaults. */
|
|
269
|
+
defaultGenerationConfig: GenerationConfig;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** Where a physical cache entry lives. */
|
|
273
|
+
export type CacheEntryLocation = 'registry' | 'extracted' | 'huggingFace' | 'huggingFaceHub';
|
|
274
|
+
|
|
275
|
+
/** One physical model entry in managed cache storage. */
|
|
276
|
+
export interface CacheEntry {
|
|
277
|
+
modelId: string;
|
|
278
|
+
location: CacheEntryLocation;
|
|
279
|
+
path: string;
|
|
280
|
+
sizeBytes: number;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** Aggregate storage usage across every managed cache location. */
|
|
284
|
+
export interface CacheStatus {
|
|
285
|
+
totalSizeBytes: number;
|
|
286
|
+
entryCount: number;
|
|
287
|
+
modelCount: number;
|
|
288
|
+
extractedModelCount: number;
|
|
289
|
+
cacheRoot: string;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** Snapshot of a conversation context. */
|
|
293
|
+
export interface ConversationInfo {
|
|
294
|
+
id: string;
|
|
295
|
+
/** History turns, excluding the system envelope. */
|
|
296
|
+
historyLength: number;
|
|
297
|
+
hasSystem: boolean;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** What one pipeline stage produced. */
|
|
301
|
+
export interface StageResult {
|
|
302
|
+
/** The YAML `id:` (or the model id when the stage declares none). */
|
|
303
|
+
stageId: string;
|
|
304
|
+
/** This stage's output — also the next stage's input. */
|
|
305
|
+
envelope: Envelope;
|
|
306
|
+
outputType: OutputType;
|
|
307
|
+
text?: string;
|
|
308
|
+
audioBytesBase64?: string;
|
|
309
|
+
latencyMs: number;
|
|
310
|
+
/** Stages of one pipeline can run in different places. */
|
|
311
|
+
executionTarget: ExecutionTarget;
|
|
312
|
+
metrics: InferenceMetrics;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** Result of a pipeline run: the final output plus every stage's own. */
|
|
316
|
+
export interface PipelineResult {
|
|
317
|
+
/** The final stage's output. */
|
|
318
|
+
envelope: Envelope;
|
|
319
|
+
outputType: OutputType;
|
|
320
|
+
text?: string;
|
|
321
|
+
audioBytesBase64?: string;
|
|
322
|
+
/** Wall-clock time of the whole run. */
|
|
323
|
+
latencyMs: number;
|
|
324
|
+
/** Every executed stage, in order. */
|
|
325
|
+
stages: StageResult[];
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/** Static description of a loaded pipeline. */
|
|
329
|
+
export interface PipelineInfo {
|
|
330
|
+
name: string | null;
|
|
331
|
+
stageNames: string[];
|
|
332
|
+
stageCount: number;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/** Chunking options for a live ASR session. */
|
|
336
|
+
export interface StreamingConfig {
|
|
337
|
+
/** Must be 16000 — the ASR backends are fixed there. Default 16000. */
|
|
338
|
+
sampleRate?: number;
|
|
339
|
+
/**
|
|
340
|
+
* Chunk on speech boundaries with a Silero VAD model in `modelDir`
|
|
341
|
+
* (containing `model.onnx`). Omit for fixed time windows.
|
|
342
|
+
*/
|
|
343
|
+
vad?: { modelDir: string } | null;
|
|
344
|
+
/** VAD sensitivity, 0.0–1.0. Default 0.5. Ignored without `vad`. */
|
|
345
|
+
vadThreshold?: number;
|
|
346
|
+
/** Language hint such as `'en'`; omit for the model default. */
|
|
347
|
+
language?: string;
|
|
348
|
+
/** Whisper encoder context in mel frames; omit for the model default. */
|
|
349
|
+
audioCtx?: number;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** A partial transcript from a live ASR session. */
|
|
353
|
+
export interface PartialResult {
|
|
354
|
+
/** Transcript so far. Cumulative — replace the previous partial. */
|
|
355
|
+
text: string;
|
|
356
|
+
/** `true` once this span is committed and will not change. */
|
|
357
|
+
isStable: boolean;
|
|
358
|
+
/** Monotonic chunk sequence number. */
|
|
359
|
+
chunkSequence: number;
|
|
360
|
+
/** Audio covered so far, in milliseconds. */
|
|
361
|
+
audioDurationMs: number;
|
|
362
|
+
}
|