@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
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
// Translation between the public types and the plain objects that cross the
|
|
2
|
+
// TurboModule boundary. Every convenience field (voiceId, speed, sampleRate,
|
|
3
|
+
// channels, role) is folded into / lifted out of envelope metadata HERE, once,
|
|
4
|
+
// so the native codecs stay generic and lossless: an envelope is a payload
|
|
5
|
+
// kind plus string metadata, exactly like bolt's `XybridEnvelope`.
|
|
6
|
+
//
|
|
7
|
+
// Pure functions only — no native calls — so tests/wire.test.mjs covers them
|
|
8
|
+
// on Node.
|
|
9
|
+
// Metadata keys the Rust core reads; see the Swift/Kotlin envelope factories.
|
|
10
|
+
const KEY_VOICE_ID = 'voice_id';
|
|
11
|
+
const KEY_SPEED = 'speed';
|
|
12
|
+
const KEY_SAMPLE_RATE = 'sample_rate';
|
|
13
|
+
const KEY_CHANNELS = 'channels';
|
|
14
|
+
const KEY_ROLE = 'xybrid.role';
|
|
15
|
+
const ROLES = ['system', 'user', 'assistant'];
|
|
16
|
+
// -- Envelopes ----------------------------------------------------------------
|
|
17
|
+
function setIfDefined(target, key, value) {
|
|
18
|
+
if (value !== undefined && value !== null)
|
|
19
|
+
target[key] = String(value);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Fold an envelope's convenience fields into metadata. Typed fields win over
|
|
23
|
+
* raw `metadata` entries for the same key; audio input defaults to 16 kHz
|
|
24
|
+
* mono, like the Swift and Kotlin `Envelope.audio` factories.
|
|
25
|
+
*/
|
|
26
|
+
export function toWireEnvelope(envelope) {
|
|
27
|
+
if (envelope == null || typeof envelope !== 'object') {
|
|
28
|
+
throw new TypeError('An envelope must be an object with a `kind` field');
|
|
29
|
+
}
|
|
30
|
+
const metadata = { ...(envelope.metadata ?? {}) };
|
|
31
|
+
setIfDefined(metadata, KEY_ROLE, envelope.role);
|
|
32
|
+
switch (envelope.kind) {
|
|
33
|
+
case 'text':
|
|
34
|
+
requireType(envelope.text, 'string', 'text envelope: `text`');
|
|
35
|
+
setIfDefined(metadata, KEY_VOICE_ID, envelope.voiceId);
|
|
36
|
+
setIfDefined(metadata, KEY_SPEED, envelope.speed);
|
|
37
|
+
return { kind: 'text', text: envelope.text, metadata };
|
|
38
|
+
case 'audio':
|
|
39
|
+
requireType(envelope.bytesBase64, 'string', 'audio envelope: `bytesBase64`');
|
|
40
|
+
setIfDefined(metadata, KEY_SAMPLE_RATE, envelope.sampleRate ?? metadata[KEY_SAMPLE_RATE] ?? 16000);
|
|
41
|
+
setIfDefined(metadata, KEY_CHANNELS, envelope.channels ?? metadata[KEY_CHANNELS] ?? 1);
|
|
42
|
+
return { kind: 'audio', bytesBase64: envelope.bytesBase64, metadata };
|
|
43
|
+
case 'embedding':
|
|
44
|
+
if (!Array.isArray(envelope.data)) {
|
|
45
|
+
throw new TypeError('embedding envelope: `data` must be a number array');
|
|
46
|
+
}
|
|
47
|
+
return { kind: 'embedding', data: envelope.data, metadata };
|
|
48
|
+
case 'image':
|
|
49
|
+
requireType(envelope.bytesBase64, 'string', 'image envelope: `bytesBase64`');
|
|
50
|
+
return {
|
|
51
|
+
kind: 'image',
|
|
52
|
+
bytesBase64: envelope.bytesBase64,
|
|
53
|
+
format: normalizeImageFormat(envelope.format),
|
|
54
|
+
metadata,
|
|
55
|
+
};
|
|
56
|
+
case 'multipart':
|
|
57
|
+
if (!Array.isArray(envelope.parts)) {
|
|
58
|
+
throw new TypeError('multipart envelope: `parts` must be an array');
|
|
59
|
+
}
|
|
60
|
+
return { kind: 'multipart', parts: envelope.parts.map(toWireEnvelope), metadata };
|
|
61
|
+
default:
|
|
62
|
+
throw new TypeError(`Unknown envelope kind: ${String(envelope.kind)}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** Lift well-known metadata keys back into typed fields. Lossless. */
|
|
66
|
+
export function fromWireEnvelope(wire) {
|
|
67
|
+
const metadata = { ...(wire.metadata ?? {}) };
|
|
68
|
+
const role = metadata[KEY_ROLE];
|
|
69
|
+
const base = {
|
|
70
|
+
...(role && ROLES.includes(role) ? { role } : {}),
|
|
71
|
+
metadata,
|
|
72
|
+
};
|
|
73
|
+
switch (wire.kind) {
|
|
74
|
+
case 'text': {
|
|
75
|
+
const speed = parseNumber(metadata[KEY_SPEED]);
|
|
76
|
+
return {
|
|
77
|
+
kind: 'text',
|
|
78
|
+
text: wire.text,
|
|
79
|
+
...(metadata[KEY_VOICE_ID] !== undefined ? { voiceId: metadata[KEY_VOICE_ID] } : {}),
|
|
80
|
+
...(speed !== undefined ? { speed } : {}),
|
|
81
|
+
...base,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
case 'audio': {
|
|
85
|
+
const sampleRate = parseNumber(metadata[KEY_SAMPLE_RATE]);
|
|
86
|
+
const channels = parseNumber(metadata[KEY_CHANNELS]);
|
|
87
|
+
return {
|
|
88
|
+
kind: 'audio',
|
|
89
|
+
bytesBase64: wire.bytesBase64,
|
|
90
|
+
...(sampleRate !== undefined ? { sampleRate } : {}),
|
|
91
|
+
...(channels !== undefined ? { channels } : {}),
|
|
92
|
+
...base,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
case 'embedding':
|
|
96
|
+
return { kind: 'embedding', data: wire.data, ...base };
|
|
97
|
+
case 'image':
|
|
98
|
+
return {
|
|
99
|
+
kind: 'image',
|
|
100
|
+
bytesBase64: wire.bytesBase64,
|
|
101
|
+
format: normalizeImageFormat(wire.format),
|
|
102
|
+
...base,
|
|
103
|
+
};
|
|
104
|
+
case 'multipart':
|
|
105
|
+
return { kind: 'multipart', parts: wire.parts.map(fromWireEnvelope), ...base };
|
|
106
|
+
default:
|
|
107
|
+
throw new Error(`Unexpected envelope kind from native: ${String(wire.kind)}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/** Accept `jpg` as an alias and reject anything the core cannot decode. */
|
|
111
|
+
export function normalizeImageFormat(format) {
|
|
112
|
+
const normalized = String(format ?? '').trim().toLowerCase();
|
|
113
|
+
if (normalized === 'jpg' || normalized === 'jpeg')
|
|
114
|
+
return 'jpeg';
|
|
115
|
+
if (normalized === 'png' || normalized === 'webp')
|
|
116
|
+
return normalized;
|
|
117
|
+
throw new TypeError(`Unsupported image format '${format}'. Supported: png, jpeg, jpg, webp`);
|
|
118
|
+
}
|
|
119
|
+
// -- Options ------------------------------------------------------------------
|
|
120
|
+
const GENERATION_KEYS = [
|
|
121
|
+
'maxTokens',
|
|
122
|
+
'temperature',
|
|
123
|
+
'topP',
|
|
124
|
+
'minP',
|
|
125
|
+
'topK',
|
|
126
|
+
'repetitionPenalty',
|
|
127
|
+
'stopSequences',
|
|
128
|
+
'grammar',
|
|
129
|
+
'tools',
|
|
130
|
+
];
|
|
131
|
+
export function toWireToolDefinition(tool) {
|
|
132
|
+
const parameters = tool.parameters;
|
|
133
|
+
return {
|
|
134
|
+
name: tool.name,
|
|
135
|
+
description: tool.description,
|
|
136
|
+
parametersJson: typeof parameters === 'string' ? parameters : JSON.stringify(parameters),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
export function toWireGenerationConfig(config) {
|
|
140
|
+
const { tools, ...rest } = config;
|
|
141
|
+
return {
|
|
142
|
+
...rest,
|
|
143
|
+
...(tools ? { tools: tools.map(toWireToolDefinition) } : {}),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
export function fromWireGenerationConfig(wire) {
|
|
147
|
+
const { tools, ...rest } = wire;
|
|
148
|
+
return {
|
|
149
|
+
...rest,
|
|
150
|
+
tools: (tools ?? []).map((tool) => ({
|
|
151
|
+
name: tool.name,
|
|
152
|
+
description: tool.description,
|
|
153
|
+
parameters: tool.parametersJson,
|
|
154
|
+
})),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Build the wire options. Sampling parameters must sit under
|
|
159
|
+
* `generationConfig`; passing them at the top level is a mistake that would
|
|
160
|
+
* otherwise be silently ignored, so it throws.
|
|
161
|
+
*/
|
|
162
|
+
export function toWireRunOptions(options, handles = {}) {
|
|
163
|
+
if (options != null && typeof options !== 'object') {
|
|
164
|
+
throw new TypeError('Run options must be an object');
|
|
165
|
+
}
|
|
166
|
+
const misplaced = GENERATION_KEYS.filter((key) => options != null && key in options);
|
|
167
|
+
if (misplaced.length > 0) {
|
|
168
|
+
throw new TypeError(`Sampling parameters belong under \`generationConfig\` (got ${misplaced.join(', ')} ` +
|
|
169
|
+
'at the top level of the run options)');
|
|
170
|
+
}
|
|
171
|
+
const wire = {};
|
|
172
|
+
if (options?.generationConfig) {
|
|
173
|
+
wire.generationConfig = toWireGenerationConfig(options.generationConfig);
|
|
174
|
+
}
|
|
175
|
+
if (options?.abortOn)
|
|
176
|
+
wire.abortOn = [...options.abortOn];
|
|
177
|
+
if (options?.fallbackToCloud !== undefined)
|
|
178
|
+
wire.fallbackToCloud = options.fallbackToCloud;
|
|
179
|
+
if (options?.maxGraceTokens !== undefined)
|
|
180
|
+
wire.maxGraceTokens = options.maxGraceTokens;
|
|
181
|
+
if (options?.correlationId !== undefined)
|
|
182
|
+
wire.correlationId = options.correlationId;
|
|
183
|
+
if (handles.context)
|
|
184
|
+
wire.context = handles.context;
|
|
185
|
+
if (handles.cancel)
|
|
186
|
+
wire.cancel = handles.cancel;
|
|
187
|
+
return Object.keys(wire).length > 0 ? wire : null;
|
|
188
|
+
}
|
|
189
|
+
export function toWireToolResult(result) {
|
|
190
|
+
const { content } = result;
|
|
191
|
+
return {
|
|
192
|
+
callId: result.callId,
|
|
193
|
+
name: result.name,
|
|
194
|
+
contentJson: typeof content === 'string' ? content : JSON.stringify(content ?? null),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
// -- Results ------------------------------------------------------------------
|
|
198
|
+
/** Convenience payload fields derived from an envelope (no copies). */
|
|
199
|
+
function payloadFields(envelope) {
|
|
200
|
+
switch (envelope.kind) {
|
|
201
|
+
case 'text':
|
|
202
|
+
return { text: envelope.text };
|
|
203
|
+
case 'audio':
|
|
204
|
+
return { audioBytesBase64: envelope.bytesBase64 };
|
|
205
|
+
case 'embedding':
|
|
206
|
+
return { embedding: envelope.data };
|
|
207
|
+
default:
|
|
208
|
+
return {};
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
export function fromWireResult(wire) {
|
|
212
|
+
return {
|
|
213
|
+
envelope: fromWireEnvelope(wire.envelope),
|
|
214
|
+
outputType: wire.outputType,
|
|
215
|
+
modelId: wire.modelId,
|
|
216
|
+
...payloadFields(wire.envelope),
|
|
217
|
+
...(wire.reasoningContent !== undefined ? { reasoningContent: wire.reasoningContent } : {}),
|
|
218
|
+
toolCalls: wire.toolCalls ?? [],
|
|
219
|
+
latencyMs: wire.latencyMs,
|
|
220
|
+
metrics: wire.metrics,
|
|
221
|
+
executionTarget: wire.executionTarget,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
export function fromWireStreamToken(wire) {
|
|
225
|
+
return { ...wire, toolCalls: wire.toolCalls ?? [] };
|
|
226
|
+
}
|
|
227
|
+
function fromWireStage(wire) {
|
|
228
|
+
const payload = payloadFields(wire.envelope);
|
|
229
|
+
return {
|
|
230
|
+
stageId: wire.stageId,
|
|
231
|
+
envelope: fromWireEnvelope(wire.envelope),
|
|
232
|
+
outputType: wire.outputType,
|
|
233
|
+
...(payload.text !== undefined ? { text: payload.text } : {}),
|
|
234
|
+
...(payload.audioBytesBase64 !== undefined
|
|
235
|
+
? { audioBytesBase64: payload.audioBytesBase64 }
|
|
236
|
+
: {}),
|
|
237
|
+
latencyMs: wire.latencyMs,
|
|
238
|
+
executionTarget: wire.executionTarget,
|
|
239
|
+
metrics: wire.metrics,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
export function fromWirePipelineResult(wire) {
|
|
243
|
+
const payload = payloadFields(wire.envelope);
|
|
244
|
+
return {
|
|
245
|
+
envelope: fromWireEnvelope(wire.envelope),
|
|
246
|
+
outputType: wire.outputType,
|
|
247
|
+
...(payload.text !== undefined ? { text: payload.text } : {}),
|
|
248
|
+
...(payload.audioBytesBase64 !== undefined
|
|
249
|
+
? { audioBytesBase64: payload.audioBytesBase64 }
|
|
250
|
+
: {}),
|
|
251
|
+
latencyMs: wire.latencyMs,
|
|
252
|
+
stages: wire.stages.map(fromWireStage),
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
export function fromWireDownloadStatus(wire) {
|
|
256
|
+
// Both shims omit `totalBytes` when unknown; drop an explicit null too so
|
|
257
|
+
// callers can rely on `status.totalBytes === undefined`.
|
|
258
|
+
const { totalBytes, ...rest } = wire;
|
|
259
|
+
return totalBytes == null ? rest : { ...rest, totalBytes };
|
|
260
|
+
}
|
|
261
|
+
// -- Helpers ------------------------------------------------------------------
|
|
262
|
+
function requireType(value, type, what) {
|
|
263
|
+
if (typeof value !== type)
|
|
264
|
+
throw new TypeError(`${what} must be a ${type}`);
|
|
265
|
+
}
|
|
266
|
+
function parseNumber(raw) {
|
|
267
|
+
if (raw === undefined)
|
|
268
|
+
return undefined;
|
|
269
|
+
const value = Number(raw);
|
|
270
|
+
return Number.isFinite(value) ? value : undefined;
|
|
271
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { AppState } from 'react-native';
|
|
2
|
+
import NativeXybrid from './NativeXybrid';
|
|
3
|
+
import { ModelLoader } from './model';
|
|
4
|
+
let initialized = false;
|
|
5
|
+
/**
|
|
6
|
+
* Process-wide SDK entry points. Local inference needs no setup at all —
|
|
7
|
+
* `initialize` only matters for the optional platform features.
|
|
8
|
+
*/
|
|
9
|
+
export const Xybrid = {
|
|
10
|
+
/**
|
|
11
|
+
* Apply process-wide configuration. The SDK otherwise configures itself
|
|
12
|
+
* anonymously on first use, so call this before anything else when you
|
|
13
|
+
* have options. Configuration is applied once per app process: repeating
|
|
14
|
+
* it with the same options resolves, with different options rejects
|
|
15
|
+
* (`xybrid_config_error`) — restart the app to change them.
|
|
16
|
+
*/
|
|
17
|
+
async initialize(options = {}) {
|
|
18
|
+
await NativeXybrid.initialize(options);
|
|
19
|
+
initialized = true;
|
|
20
|
+
},
|
|
21
|
+
/** Whether {@link initialize} has resolved in this JS context. */
|
|
22
|
+
get isInitialized() {
|
|
23
|
+
return initialized;
|
|
24
|
+
},
|
|
25
|
+
/** Describe a registry model without loading it (same as `ModelLoader.fromRegistry`). */
|
|
26
|
+
model(id) {
|
|
27
|
+
return ModelLoader.fromRegistry(id);
|
|
28
|
+
},
|
|
29
|
+
/** The native SDK version, e.g. `0.9.0`. */
|
|
30
|
+
version() {
|
|
31
|
+
return NativeXybrid.sdkVersion();
|
|
32
|
+
},
|
|
33
|
+
/** Whether an API key resolves, from {@link initialize} or the environment. */
|
|
34
|
+
hasApiKey() {
|
|
35
|
+
return NativeXybrid.hasApiKey();
|
|
36
|
+
},
|
|
37
|
+
/** Set the key for a cloud provider the gateway forwards to (not the Xybrid key). */
|
|
38
|
+
setProviderApiKey(provider, apiKey) {
|
|
39
|
+
return NativeXybrid.setProviderApiKey(provider, apiKey);
|
|
40
|
+
},
|
|
41
|
+
/** Point the cloud gateway at a platform base URL; the `/v1` suffix is added for you. */
|
|
42
|
+
setPlatformUrl(url) {
|
|
43
|
+
return NativeXybrid.setPlatformUrl(url);
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
* Default speculative cloud serving on or off for loads that don't opt in
|
|
47
|
+
* per load (`ModelLoader.fromRegistrySpeculative` always speculates). Needs
|
|
48
|
+
* an API key. LLM/chat only — prefer the per-load form when the app also
|
|
49
|
+
* loads ASR/TTS models.
|
|
50
|
+
*/
|
|
51
|
+
setSpeculativeCloud(enabled) {
|
|
52
|
+
return NativeXybrid.setSpeculativeCloud(enabled);
|
|
53
|
+
},
|
|
54
|
+
isSpeculativeCloudEnabled() {
|
|
55
|
+
return NativeXybrid.isSpeculativeCloudEnabled();
|
|
56
|
+
},
|
|
57
|
+
/**
|
|
58
|
+
* Release every idle model's memory; resolves how many were released. Runs
|
|
59
|
+
* in flight are skipped, and a released model reloads itself on next use.
|
|
60
|
+
*/
|
|
61
|
+
releaseMemory() {
|
|
62
|
+
return NativeXybrid.releaseMemory();
|
|
63
|
+
},
|
|
64
|
+
/**
|
|
65
|
+
* Call {@link releaseMemory} on every OS memory warning (React Native
|
|
66
|
+
* `AppState` `memoryWarning`, iOS and Android). Returns the unsubscribe
|
|
67
|
+
* function.
|
|
68
|
+
*/
|
|
69
|
+
releaseMemoryOnWarning() {
|
|
70
|
+
const subscription = AppState.addEventListener('memoryWarning', () => {
|
|
71
|
+
NativeXybrid.releaseMemory().catch(() => { });
|
|
72
|
+
});
|
|
73
|
+
return () => subscription.remove();
|
|
74
|
+
},
|
|
75
|
+
/** Release least-recently-used idle models before loads under memory pressure. */
|
|
76
|
+
setAutoRelease(enabled) {
|
|
77
|
+
return NativeXybrid.setAutoRelease(enabled);
|
|
78
|
+
},
|
|
79
|
+
isAutoReleaseEnabled() {
|
|
80
|
+
return NativeXybrid.isAutoReleaseEnabled();
|
|
81
|
+
},
|
|
82
|
+
// -- Device state. Both platforms already observe battery (and Android
|
|
83
|
+
// thermal) natively; these exist for tests and custom readings. --
|
|
84
|
+
/** Push a battery percentage (0–100) to the routing engine. */
|
|
85
|
+
setBatteryLevel(percent) {
|
|
86
|
+
return NativeXybrid.setBatteryLevel(percent);
|
|
87
|
+
},
|
|
88
|
+
clearBatteryLevel() {
|
|
89
|
+
return NativeXybrid.clearBatteryLevel();
|
|
90
|
+
},
|
|
91
|
+
setThermalState(state) {
|
|
92
|
+
return NativeXybrid.setThermalState(state);
|
|
93
|
+
},
|
|
94
|
+
clearThermalState() {
|
|
95
|
+
return NativeXybrid.clearThermalState();
|
|
96
|
+
},
|
|
97
|
+
// -- Model cache. Every call walks or deletes the cache on disk, off the
|
|
98
|
+
// JS thread. --
|
|
99
|
+
/** Aggregate storage usage across every managed cache location. */
|
|
100
|
+
async modelCacheStatus() {
|
|
101
|
+
return (await NativeXybrid.cacheStatus());
|
|
102
|
+
},
|
|
103
|
+
/** Physical entries; a model can appear more than once. */
|
|
104
|
+
async modelCacheEntries() {
|
|
105
|
+
return (await NativeXybrid.cacheEntries());
|
|
106
|
+
},
|
|
107
|
+
/** Whether `modelId` occupies any cache entry. */
|
|
108
|
+
hasCachedModelData(modelId) {
|
|
109
|
+
return NativeXybrid.cacheIsModelCached(modelId);
|
|
110
|
+
},
|
|
111
|
+
/** A local path for `modelId`, or `null`. Presence does not mean extracted. */
|
|
112
|
+
cachedModelPath(modelId) {
|
|
113
|
+
return NativeXybrid.cacheModelPath(modelId);
|
|
114
|
+
},
|
|
115
|
+
/** Models extracted, validated and ready to run offline. */
|
|
116
|
+
extractedModelIds() {
|
|
117
|
+
return NativeXybrid.cacheExtractedModelIds();
|
|
118
|
+
},
|
|
119
|
+
/** Remove every cache entry for `modelId`. Don't race a load of the same model. */
|
|
120
|
+
removeCachedModel(modelId) {
|
|
121
|
+
return NativeXybrid.cacheRemoveModel(modelId);
|
|
122
|
+
},
|
|
123
|
+
/** Clear all managed cache storage. Don't race any model load. */
|
|
124
|
+
clearModelCache() {
|
|
125
|
+
return NativeXybrid.cacheClear();
|
|
126
|
+
},
|
|
127
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
export interface Spec extends TurboModule {
|
|
3
|
+
initialize(options: Object | null): Promise<void>;
|
|
4
|
+
sdkVersion(): Promise<string>;
|
|
5
|
+
hasApiKey(): Promise<boolean>;
|
|
6
|
+
setProviderApiKey(provider: string, apiKey: string): Promise<void>;
|
|
7
|
+
setPlatformUrl(url: string): Promise<void>;
|
|
8
|
+
setSpeculativeCloud(enabled: boolean): Promise<void>;
|
|
9
|
+
isSpeculativeCloudEnabled(): Promise<boolean>;
|
|
10
|
+
willSpeculate(modelId: string): Promise<boolean>;
|
|
11
|
+
releaseMemory(): Promise<number>;
|
|
12
|
+
setAutoRelease(enabled: boolean): Promise<void>;
|
|
13
|
+
isAutoReleaseEnabled(): Promise<boolean>;
|
|
14
|
+
setBatteryLevel(percent: number): Promise<void>;
|
|
15
|
+
clearBatteryLevel(): Promise<void>;
|
|
16
|
+
setThermalState(state: string): Promise<void>;
|
|
17
|
+
clearThermalState(): Promise<void>;
|
|
18
|
+
cacheStatus(): Promise<Object>;
|
|
19
|
+
cacheEntries(): Promise<Object[]>;
|
|
20
|
+
cacheIsModelCached(modelId: string): Promise<boolean>;
|
|
21
|
+
cacheModelPath(modelId: string): Promise<string | null>;
|
|
22
|
+
cacheExtractedModelIds(): Promise<string[]>;
|
|
23
|
+
cacheRemoveModel(modelId: string): Promise<number>;
|
|
24
|
+
cacheClear(): Promise<number>;
|
|
25
|
+
jsonSchemaToGbnf(schemaJson: string): Promise<string>;
|
|
26
|
+
toolResultsEnvelope(userText: string, priorAssistantText: string, results: Object[]): Promise<Object>;
|
|
27
|
+
dispose(handle: string): Promise<void>;
|
|
28
|
+
loadModel(source: Object): Promise<string>;
|
|
29
|
+
modelInfo(model: string): Promise<Object>;
|
|
30
|
+
isLoaded(model: string): Promise<boolean>;
|
|
31
|
+
warmup(model: string): Promise<void>;
|
|
32
|
+
unload(model: string): Promise<void>;
|
|
33
|
+
isCloudServing(model: string): Promise<boolean>;
|
|
34
|
+
downloadStatus(model: string): Promise<Object>;
|
|
35
|
+
awaitDownload(model: string, timeoutMs: number): Promise<Object>;
|
|
36
|
+
voices(model: string): Promise<Object[]>;
|
|
37
|
+
defaultVoice(model: string): Promise<Object | null>;
|
|
38
|
+
voice(model: string, voiceId: string): Promise<Object | null>;
|
|
39
|
+
run(model: string, envelope: Object, options: Object | null): Promise<Object>;
|
|
40
|
+
streamStart(model: string, envelope: Object, options: Object | null): Promise<string>;
|
|
41
|
+
streamNext(stream: string): Promise<Object | null>;
|
|
42
|
+
createCancelToken(): Promise<string>;
|
|
43
|
+
cancel(token: string): Promise<void>;
|
|
44
|
+
createContext(contextId: string | null): Promise<string>;
|
|
45
|
+
contextPush(context: string, envelope: Object): Promise<void>;
|
|
46
|
+
contextSetSystem(context: string, envelope: Object): Promise<void>;
|
|
47
|
+
contextClear(context: string): Promise<void>;
|
|
48
|
+
contextInfo(context: string): Promise<Object>;
|
|
49
|
+
contextHistory(context: string): Promise<Object[]>;
|
|
50
|
+
contextSetMaxHistoryLength(context: string, length: number): Promise<void>;
|
|
51
|
+
startDownload(modelId: string, platform: string | null): Promise<string>;
|
|
52
|
+
downloadHandleStatus(download: string): Promise<Object>;
|
|
53
|
+
downloadHandleError(download: string): Promise<string | null>;
|
|
54
|
+
cancelDownload(download: string): Promise<void>;
|
|
55
|
+
loadPipeline(source: Object): Promise<string>;
|
|
56
|
+
pipelineInfo(pipeline: string): Promise<Object>;
|
|
57
|
+
runPipeline(pipeline: string, envelope: Object, options: Object | null): Promise<Object>;
|
|
58
|
+
openStreamingSession(model: string, config: Object | null): Promise<string>;
|
|
59
|
+
sessionFeed(session: string, samplesBase64: string): Promise<void>;
|
|
60
|
+
sessionNextPartial(session: string): Promise<Object | null>;
|
|
61
|
+
sessionFlush(session: string): Promise<string>;
|
|
62
|
+
sessionReset(session: string): Promise<void>;
|
|
63
|
+
sessionCancel(session: string): Promise<void>;
|
|
64
|
+
sessionIsRunning(session: string): Promise<boolean>;
|
|
65
|
+
}
|
|
66
|
+
declare const _default: Spec;
|
|
67
|
+
export default _default;
|
|
68
|
+
//# sourceMappingURL=NativeXybrid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeXybrid.d.ts","sourceRoot":"","sources":["../../src/NativeXybrid.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IAKvC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9B,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnE,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,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CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9C,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAChD,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAIzF,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5E,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnE,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC5D,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/C,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACrD;;AAED,wBAAkE"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Standard (RFC 4648, padded) base64 of `bytes`. */
|
|
2
|
+
export declare function bytesToBase64(bytes: Uint8Array): string;
|
|
3
|
+
/** Base64 of Float32 PCM samples as little-endian bytes. */
|
|
4
|
+
export declare function float32ToBase64(samples: Float32Array | ArrayLike<number>): string;
|
|
5
|
+
//# sourceMappingURL=base64.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../src/base64.ts"],"names":[],"mappings":"AAOA,qDAAqD;AACrD,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CA4BvD;AAED,4DAA4D;AAC5D,wBAAgB,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAGjF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The part of the standard `AbortSignal` this SDK needs, so any
|
|
3
|
+
* implementation (React Native's `AbortController`, a polyfill) works.
|
|
4
|
+
*/
|
|
5
|
+
export interface AbortSignalLike {
|
|
6
|
+
readonly aborted: boolean;
|
|
7
|
+
addEventListener(type: 'abort', listener: () => void): void;
|
|
8
|
+
removeEventListener(type: 'abort', listener: () => void): void;
|
|
9
|
+
}
|
|
10
|
+
/** A native cancellation token bound to an `AbortSignal` for one call. */
|
|
11
|
+
export interface CancelBinding {
|
|
12
|
+
/** Native token handle, or `null` when the call has no signal. */
|
|
13
|
+
readonly token: string | null;
|
|
14
|
+
/** Detach from the signal and free the native token. Never rejects. */
|
|
15
|
+
release(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create a native stop button wired to `signal`. Aborting the signal cancels
|
|
19
|
+
* the token, which stops generation at the next token boundary. A signal
|
|
20
|
+
* that is already aborted cancels the token before the call starts, so the
|
|
21
|
+
* call rejects with `xybrid_cancelled` instead of running.
|
|
22
|
+
*/
|
|
23
|
+
export declare function bindCancel(signal: AbortSignalLike | undefined): Promise<CancelBinding>;
|
|
24
|
+
//# sourceMappingURL=cancel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cancel.d.ts","sourceRoot":"","sources":["../../src/cancel.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IAC5D,mBAAmB,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;CAChE;AAED,0EAA0E;AAC1E,MAAM,WAAW,aAAa;IAC5B,kEAAkE;IAClE,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,uEAAuE;IACvE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAID;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,CAkB5F"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ConversationInfo, Envelope } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Multi-turn conversation history, held natively. Pass it to
|
|
4
|
+
* `model.run(envelope, { context })` or `runStreaming`; inference reads the
|
|
5
|
+
* history but never changes it. The prompt you run is appended to the
|
|
6
|
+
* history for that run only, so push both turns *after* the run — pushing the
|
|
7
|
+
* prompt first would send it twice:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* const chat = await ConversationContext.create();
|
|
11
|
+
* await chat.setSystem('You are terse.');
|
|
12
|
+
*
|
|
13
|
+
* const question = Envelope.user('What is the capital of France?');
|
|
14
|
+
* const reply = await model.run(question, { context: chat });
|
|
15
|
+
* await chat.push(question);
|
|
16
|
+
* await chat.push(reply.envelope); // already tagged `assistant`
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare class ConversationContext {
|
|
20
|
+
/** Opaque native handle. */
|
|
21
|
+
readonly handle: string;
|
|
22
|
+
private constructor();
|
|
23
|
+
/** A new, empty conversation; `id` defaults to a fresh one (telemetry correlation). */
|
|
24
|
+
static create(id?: string): Promise<ConversationContext>;
|
|
25
|
+
/** Append a turn. Give it a `role` (see `Envelope.user` / `Envelope.assistant`). */
|
|
26
|
+
push(envelope: Envelope): Promise<void>;
|
|
27
|
+
/** Set the persistent system prompt; it survives {@link clear}. */
|
|
28
|
+
setSystem(system: Envelope | string): Promise<void>;
|
|
29
|
+
/** Drop the history; the system prompt is kept. */
|
|
30
|
+
clear(): Promise<void>;
|
|
31
|
+
/** Id, history length and whether a system prompt is set. */
|
|
32
|
+
info(): Promise<ConversationInfo>;
|
|
33
|
+
/** History turns in order, excluding the system prompt. */
|
|
34
|
+
history(): Promise<Envelope[]>;
|
|
35
|
+
/** Cap the history; older turns are pruned first, immediately. */
|
|
36
|
+
setMaxHistoryLength(length: number): Promise<void>;
|
|
37
|
+
/** Free the native context. Runs already started keep their snapshot. */
|
|
38
|
+
release(): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAG1D;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,mBAAmB;IAE5B,4BAA4B;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM;IAFzB,OAAO;IAKP,uFAAuF;WAC1E,MAAM,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAI9D,oFAAoF;IACpF,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvC,mEAAmE;IACnE,SAAS,CAAC,MAAM,EAAE,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMnD,mDAAmD;IACnD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,6DAA6D;IACvD,IAAI,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAIvC,2DAA2D;IACrD,OAAO,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAKpC,kEAAkE;IAClE,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD,yEAAyE;IACzE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAGzB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { AudioEnvelope, EmbeddingEnvelope, Envelope as EnvelopeType, ImageEnvelope, ImageFormat, MessageRole, MultiPartEnvelope, TextEnvelope, ToolResult } from './types';
|
|
2
|
+
/** Input to (and output of) a model. Narrow on `kind`. */
|
|
3
|
+
export type Envelope = EnvelopeType;
|
|
4
|
+
/**
|
|
5
|
+
* Envelope factories, named like the Swift and Kotlin `Envelope` helpers.
|
|
6
|
+
* Object literals (`{ kind: 'text', text }`) work just as well; these only
|
|
7
|
+
* save typing and apply the same defaults.
|
|
8
|
+
*/
|
|
9
|
+
export declare const Envelope: {
|
|
10
|
+
/** A text prompt, or text to speak with an optional TTS voice and speed. */
|
|
11
|
+
text(text: string, options?: {
|
|
12
|
+
voiceId?: string;
|
|
13
|
+
speed?: number;
|
|
14
|
+
role?: MessageRole;
|
|
15
|
+
}): TextEnvelope;
|
|
16
|
+
/** A user turn for a conversation. */
|
|
17
|
+
user(text: string): TextEnvelope;
|
|
18
|
+
/** An assistant turn for a conversation (e.g. a model reply you keep). */
|
|
19
|
+
assistant(text: string): TextEnvelope;
|
|
20
|
+
/** A system prompt. */
|
|
21
|
+
system(text: string): TextEnvelope;
|
|
22
|
+
/** PCM/WAV audio, base64-encoded. Defaults to 16 kHz mono. */
|
|
23
|
+
audio(bytesBase64: string, options?: {
|
|
24
|
+
sampleRate?: number;
|
|
25
|
+
channels?: number;
|
|
26
|
+
}): AudioEnvelope;
|
|
27
|
+
/** An embedding vector. */
|
|
28
|
+
embedding(data: number[]): EmbeddingEnvelope;
|
|
29
|
+
/**
|
|
30
|
+
* An encoded image for vision-language models. The bytes are validated
|
|
31
|
+
* natively at run time (`xybrid_invalid_image` on bad input).
|
|
32
|
+
*/
|
|
33
|
+
image(bytesBase64: string, format: ImageFormat | "jpg"): ImageEnvelope;
|
|
34
|
+
/** A user message with image attachments, for vision-language models. */
|
|
35
|
+
userMessage(text: string, images?: ImageEnvelope[]): MultiPartEnvelope;
|
|
36
|
+
/**
|
|
37
|
+
* The continuation envelope for the turn after the model asked for tools.
|
|
38
|
+
*
|
|
39
|
+
* One `run` is one model turn, so the tool loop lives in your code: run a
|
|
40
|
+
* request carrying `generationConfig.tools`, execute every
|
|
41
|
+
* `result.toolCalls` entry, then run this envelope (with the same tools) to
|
|
42
|
+
* feed the outcomes back.
|
|
43
|
+
*
|
|
44
|
+
* @param userText the original user message of the turn being continued.
|
|
45
|
+
* @param priorAssistantText that turn's raw output — `result.text` from a
|
|
46
|
+
* batch run, or the terminal token's `rawText` when streaming.
|
|
47
|
+
* @param results tool outcomes, in call order.
|
|
48
|
+
*/
|
|
49
|
+
toolResults(userText: string, priorAssistantText: string, results: ToolResult[]): Promise<Envelope>;
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=envelope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../src/envelope.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,QAAQ,IAAI,YAAY,EACxB,aAAa,EACb,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,UAAU,EACX,MAAM,SAAS,CAAC;AAQjB,0DAA0D;AAC1D,MAAM,MAAM,QAAQ,GAAG,YAAY,CAAC;AAEpC;;;;GAIG;AACH,eAAO,MAAM,QAAQ;IACnB,4EAA4E;eAEpE,MAAM,YACH;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,WAAW,CAAA;KAAE,GAChE,YAAY;IAIf,sCAAsC;eAC3B,MAAM,GAAG,YAAY;IAIhC,0EAA0E;oBAC1D,MAAM,GAAG,YAAY;IAIrC,uBAAuB;iBACV,MAAM,GAAG,YAAY;IAIlC,8DAA8D;uBAE/C,MAAM,YACV;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GAClD,aAAa;IAShB,2BAA2B;oBACX,MAAM,EAAE,GAAG,iBAAiB;IAI5C;;;OAGG;uBACgB,MAAM,UAAU,WAAW,GAAG,KAAK,GAAG,aAAa;IAItE,yEAAyE;sBACvD,MAAM,WAAU,aAAa,EAAE,GAAQ,iBAAiB;IAW1E;;;;;;;;;;;;OAYG;0BAES,MAAM,sBACI,MAAM,WACjB,UAAU,EAAE,GACpB,OAAO,CAAC,QAAQ,CAAC;CAQrB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Stable error codes for `XybridError.code`. */
|
|
2
|
+
export declare const XybridErrorCodes: readonly ["xybrid_model_not_found", "xybrid_directory_not_found", "xybrid_metadata_not_found", "xybrid_metadata_invalid", "xybrid_load_error", "xybrid_inference_error", "xybrid_aborted_cloud_fallback", "xybrid_streaming_unsupported", "xybrid_not_loaded", "xybrid_config_error", "xybrid_network_error", "xybrid_offline", "xybrid_io_error", "xybrid_cache_error", "xybrid_pipeline_error", "xybrid_circuit_open", "xybrid_rate_limited", "xybrid_timeout", "xybrid_missing_artifact", "xybrid_unsupported_model_capability", "xybrid_unsupported_backend_capability", "xybrid_invalid_image", "xybrid_cancelled", "xybrid_handle", "xybrid_invalid_argument", "xybrid_unknown"];
|
|
3
|
+
export type XybridErrorCode = (typeof XybridErrorCodes)[number];
|
|
4
|
+
/** A rejection raised by the Xybrid native module. */
|
|
5
|
+
export interface XybridError extends Error {
|
|
6
|
+
code: XybridErrorCode;
|
|
7
|
+
}
|
|
8
|
+
/** Narrow an unknown rejection to a {@link XybridError}. */
|
|
9
|
+
export declare function isXybridError(error: unknown): error is XybridError;
|
|
10
|
+
/** Whether retrying the same call later can succeed (network, rate limit, timeout, offline). */
|
|
11
|
+
export declare function isRetryable(error: unknown): boolean;
|
|
12
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAKA,iDAAiD;AACjD,eAAO,MAAM,gBAAgB,wpBA+BnB,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEhE,sDAAsD;AACtD,MAAM,WAAW,WAAY,SAAQ,KAAK;IACxC,IAAI,EAAE,eAAe,CAAC;CACvB;AAID,4DAA4D;AAC5D,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAIlE;AAUD,gGAAgG;AAChG,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEnD"}
|