@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,28 @@
|
|
|
1
|
+
export { Xybrid, type XybridInitOptions } from './xybrid';
|
|
2
|
+
export { Model, ModelDownload, ModelLoader, type ModelSource, type RunOptions, } from './model';
|
|
3
|
+
export { ConversationContext } from './context';
|
|
4
|
+
export { Pipeline } from './pipeline';
|
|
5
|
+
export { StreamingSession } from './session';
|
|
6
|
+
export { Envelope } from './envelope';
|
|
7
|
+
export { GenerationConfigs, creative, greedy } from './presets';
|
|
8
|
+
export { XybridErrorCodes, isRetryable, isXybridError, type XybridError, type XybridErrorCode, } from './errors';
|
|
9
|
+
export type { AbortSignalLike } from './cancel';
|
|
10
|
+
export { bytesToBase64, float32ToBase64 } from './base64';
|
|
11
|
+
export type { AbortSignalKind, AudioEnvelope, CacheEntry, CacheEntryLocation, CacheStatus, ConversationInfo, DownloadState, DownloadStatus, EmbeddingEnvelope, EnvelopeKind, EnvelopeMetadata, ExecutionTarget, GenerationConfig, ImageEnvelope, ImageFormat, InferenceMetrics, InferenceResult, MessageRole, ModelInfo, MultiPartEnvelope, OutputType, PartialResult, PipelineInfo, PipelineResult, StageLatency, StageResult, StreamToken, StreamingConfig, TextEnvelope, ThermalState, ToolCall, ToolDefinition, ToolResult, VoiceInfo, } from './types';
|
|
12
|
+
/**
|
|
13
|
+
* Convert a JSON Schema (object or JSON string) into a GBNF grammar for
|
|
14
|
+
* `generationConfig.grammar`, so a local LLM emits schema-valid JSON. Runs the
|
|
15
|
+
* same native converter every binding uses; rejects with
|
|
16
|
+
* `xybrid_config_error` on invalid JSON or an unsupported construct.
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* const grammar = await jsonSchemaToGbnf({
|
|
20
|
+
* type: 'object',
|
|
21
|
+
* properties: { name: { type: 'string' } },
|
|
22
|
+
* required: ['name'],
|
|
23
|
+
* });
|
|
24
|
+
* const result = await model.run(prompt, { generationConfig: { grammar } });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function jsonSchemaToGbnf(schema: object | string): Promise<string>;
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @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AAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAIzE"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { type AbortSignalLike } from './cancel';
|
|
2
|
+
import type { ConversationContext } from './context';
|
|
3
|
+
import { StreamingSession } from './session';
|
|
4
|
+
import type { AbortSignalKind, DownloadStatus, Envelope, GenerationConfig, InferenceResult, ModelInfo, StreamToken, StreamingConfig, VoiceInfo } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Per-call options, mirroring bolt's `XybridRunOptions` plus the two handles
|
|
7
|
+
* the other SDKs pass as separate arguments (a conversation context and a
|
|
8
|
+
* stop button).
|
|
9
|
+
*/
|
|
10
|
+
export interface RunOptions {
|
|
11
|
+
/** Sampling parameters for LLM inference. */
|
|
12
|
+
generationConfig?: GenerationConfig;
|
|
13
|
+
/** Device-stress signals that abort the run early. */
|
|
14
|
+
abortOn?: AbortSignalKind[];
|
|
15
|
+
/** Allow this call to fall back to the cloud gateway under device stress. */
|
|
16
|
+
fallbackToCloud?: boolean;
|
|
17
|
+
/** Tokens to emit after an abort signal before stopping. */
|
|
18
|
+
maxGraceTokens?: number;
|
|
19
|
+
/** Correlation id threaded into telemetry for this call. */
|
|
20
|
+
correlationId?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Seed the run with this conversation's history (multi-turn chat). The
|
|
23
|
+
* context is not modified: push the turns you want to keep yourself.
|
|
24
|
+
*/
|
|
25
|
+
context?: ConversationContext;
|
|
26
|
+
/**
|
|
27
|
+
* Stop button. Aborting stops generation at the next token boundary. A
|
|
28
|
+
* batch `run` is only cancellable before generation starts; use
|
|
29
|
+
* `runStreaming` when a mid-flight stop matters.
|
|
30
|
+
*/
|
|
31
|
+
signal?: AbortSignalLike;
|
|
32
|
+
}
|
|
33
|
+
/** Where a model comes from. Build one with the {@link ModelLoader} factories. */
|
|
34
|
+
export type ModelSource = {
|
|
35
|
+
kind: 'registry';
|
|
36
|
+
id: string;
|
|
37
|
+
} | {
|
|
38
|
+
kind: 'registrySpeculative';
|
|
39
|
+
id: string;
|
|
40
|
+
} | {
|
|
41
|
+
kind: 'bundle';
|
|
42
|
+
path: string;
|
|
43
|
+
} | {
|
|
44
|
+
kind: 'directory';
|
|
45
|
+
path: string;
|
|
46
|
+
} | {
|
|
47
|
+
kind: 'huggingFace';
|
|
48
|
+
repo: string;
|
|
49
|
+
revision?: string;
|
|
50
|
+
} | {
|
|
51
|
+
kind: 'modelFile';
|
|
52
|
+
path: string;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* A cheap description of a model. Creating one does no I/O; {@link load}
|
|
56
|
+
* resolves, downloads if needed, and loads it.
|
|
57
|
+
*/
|
|
58
|
+
export declare class ModelLoader {
|
|
59
|
+
readonly source: ModelSource;
|
|
60
|
+
private constructor();
|
|
61
|
+
/** Describe any source. */
|
|
62
|
+
static from(source: ModelSource): ModelLoader;
|
|
63
|
+
/** A model from the Xybrid registry. The recommended path. */
|
|
64
|
+
static fromRegistry(id: string): ModelLoader;
|
|
65
|
+
/**
|
|
66
|
+
* Serve from the cloud gateway while the registry weights download in the
|
|
67
|
+
* background, instead of blocking on the download. `load()` then resolves
|
|
68
|
+
* almost immediately with a model that switches to on-device by itself.
|
|
69
|
+
* Needs an API key and an uncached model — {@link willSpeculate} tells you
|
|
70
|
+
* up front — otherwise it behaves like {@link fromRegistry}. LLM/chat only.
|
|
71
|
+
*/
|
|
72
|
+
static fromRegistrySpeculative(id: string): ModelLoader;
|
|
73
|
+
/** A local `.xyb` bundle. */
|
|
74
|
+
static fromBundle(path: string): ModelLoader;
|
|
75
|
+
/** A local directory containing `model_metadata.json`. */
|
|
76
|
+
static fromDirectory(path: string): ModelLoader;
|
|
77
|
+
/** A Hugging Face repository (`org/repo` or `org/repo:variant`), optionally pinned. */
|
|
78
|
+
static fromHuggingFace(repo: string, options?: {
|
|
79
|
+
revision?: string;
|
|
80
|
+
}): ModelLoader;
|
|
81
|
+
/** A raw GGUF file; `model_metadata.json` is generated next to it if absent. */
|
|
82
|
+
static fromModelFile(path: string): ModelLoader;
|
|
83
|
+
/** Resolve, download if needed, and load. Rejects with a typed `xybrid_*` code. */
|
|
84
|
+
load(): Promise<Model>;
|
|
85
|
+
/**
|
|
86
|
+
* Whether {@link load} would actually speculate: a speculative source, an
|
|
87
|
+
* API key, and a model not yet cached. Never touches the network.
|
|
88
|
+
*/
|
|
89
|
+
willSpeculate(): Promise<boolean>;
|
|
90
|
+
/**
|
|
91
|
+
* Start downloading the weights in the background without loading them —
|
|
92
|
+
* the object to drive a progress bar from. The download fills the cache, so
|
|
93
|
+
* the {@link load} afterwards returns at once. Resolves `null` for sources
|
|
94
|
+
* with nothing to fetch (bundle, directory, Hugging Face, model file).
|
|
95
|
+
*/
|
|
96
|
+
download(options?: {
|
|
97
|
+
platform?: string;
|
|
98
|
+
}): Promise<ModelDownload | null>;
|
|
99
|
+
}
|
|
100
|
+
/** A model loaded in native memory. Call {@link release} when done with it. */
|
|
101
|
+
export declare class Model {
|
|
102
|
+
/** Opaque native handle — not the model id; see {@link info}. */
|
|
103
|
+
readonly handle: string;
|
|
104
|
+
/** @internal Use {@link ModelLoader.load}. */
|
|
105
|
+
constructor(
|
|
106
|
+
/** Opaque native handle — not the model id; see {@link info}. */
|
|
107
|
+
handle: string);
|
|
108
|
+
/** Identity and capabilities, in one native call. */
|
|
109
|
+
info(): Promise<ModelInfo>;
|
|
110
|
+
/** Whether the weights are resident (false after {@link unload} until the next run). */
|
|
111
|
+
isLoaded(): Promise<boolean>;
|
|
112
|
+
/**
|
|
113
|
+
* Run one inference. Pass sampling parameters under `generationConfig`,
|
|
114
|
+
* a conversation under `context`, and an `AbortSignal` under `signal`.
|
|
115
|
+
*/
|
|
116
|
+
run(envelope: Envelope, options?: RunOptions): Promise<InferenceResult>;
|
|
117
|
+
/**
|
|
118
|
+
* Stream inference token by token. Yields each {@link StreamToken}; the
|
|
119
|
+
* final {@link InferenceResult} is the generator's return value.
|
|
120
|
+
*
|
|
121
|
+
* ```ts
|
|
122
|
+
* for await (const token of model.runStreaming(Envelope.text('Hi'))) {
|
|
123
|
+
* setText((prev) => prev + token.token);
|
|
124
|
+
* }
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* Generation stops natively when iteration ends — completion, `break`, a
|
|
128
|
+
* thrown error, or an aborted `signal`. A generator that is merely
|
|
129
|
+
* abandoned is never cleaned up (JS runs no `finally` on GC), so on
|
|
130
|
+
* unmount abort the signal or call `gen.return()`.
|
|
131
|
+
*
|
|
132
|
+
* When the turn ends on tool calls, the terminal token carries `toolCalls`
|
|
133
|
+
* and `rawText` (pass it to `Envelope.toolResults`).
|
|
134
|
+
*/
|
|
135
|
+
runStreaming(envelope: Envelope, options?: RunOptions): AsyncGenerator<StreamToken, InferenceResult | undefined, void>;
|
|
136
|
+
/**
|
|
137
|
+
* Open a live ASR session: feed microphone PCM in, read partial transcripts
|
|
138
|
+
* out. Audio must be Float32, mono, 16 kHz. Rejects with
|
|
139
|
+
* `xybrid_streaming_unsupported` for a model that cannot stream.
|
|
140
|
+
*/
|
|
141
|
+
stream(config?: StreamingConfig): Promise<StreamingSession>;
|
|
142
|
+
/** Prime the model so first-token latency measures inference, not cold start. */
|
|
143
|
+
warmup(): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* Free the weights while keeping this handle valid — the next run reloads
|
|
146
|
+
* them. Contrast with {@link release}, which frees the handle.
|
|
147
|
+
*/
|
|
148
|
+
unload(): Promise<void>;
|
|
149
|
+
/**
|
|
150
|
+
* Whether runs are currently answered by the cloud because the local
|
|
151
|
+
* weights aren't ready (speculative loads). Predicts the next run;
|
|
152
|
+
* `InferenceResult.executionTarget` reports what a finished run did.
|
|
153
|
+
*/
|
|
154
|
+
isCloudServing(): Promise<boolean>;
|
|
155
|
+
/** Download progress of a speculative load; `ready` at 1.0 for local models. */
|
|
156
|
+
downloadStatus(): Promise<DownloadStatus>;
|
|
157
|
+
/**
|
|
158
|
+
* Yield the speculative download's status whenever it changes, ending
|
|
159
|
+
* after a terminal state. A local model yields one `ready` frame.
|
|
160
|
+
*/
|
|
161
|
+
downloadProgress(options?: {
|
|
162
|
+
intervalMs?: number;
|
|
163
|
+
}): AsyncGenerator<DownloadStatus, void, void>;
|
|
164
|
+
/**
|
|
165
|
+
* Wait natively until the download settles or `timeoutMs` elapses, then
|
|
166
|
+
* report it. `0` makes it a non-blocking read.
|
|
167
|
+
*/
|
|
168
|
+
awaitDownload(timeoutMs: number): Promise<DownloadStatus>;
|
|
169
|
+
/** TTS voices; empty for models without voices. */
|
|
170
|
+
voices(): Promise<VoiceInfo[]>;
|
|
171
|
+
/** The default TTS voice, if the model has voices. */
|
|
172
|
+
defaultVoice(): Promise<VoiceInfo | null>;
|
|
173
|
+
/** One TTS voice by id. */
|
|
174
|
+
voice(voiceId: string): Promise<VoiceInfo | null>;
|
|
175
|
+
/**
|
|
176
|
+
* Free the native model — weights live in the native heap, so release
|
|
177
|
+
* models you no longer need. Also stops token streams started from it.
|
|
178
|
+
* Later calls on this instance reject with `xybrid_handle`.
|
|
179
|
+
*/
|
|
180
|
+
release(): Promise<void>;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* A model download running in the background, separate from loading. Start
|
|
184
|
+
* one with {@link ModelLoader.download}. Releasing the handle does not stop
|
|
185
|
+
* the transfer — call {@link cancel}.
|
|
186
|
+
*/
|
|
187
|
+
export declare class ModelDownload {
|
|
188
|
+
readonly handle: string;
|
|
189
|
+
/** @internal */
|
|
190
|
+
constructor(handle: string);
|
|
191
|
+
/** Progress, bytes and state in one consistent read. */
|
|
192
|
+
status(): Promise<DownloadStatus>;
|
|
193
|
+
/** The failure message once the download failed, else `null`. */
|
|
194
|
+
error(): Promise<string | null>;
|
|
195
|
+
/** Stop the transfer. The status then settles on `cancelled`. */
|
|
196
|
+
cancel(): Promise<void>;
|
|
197
|
+
/**
|
|
198
|
+
* Yield the status whenever it changes, ending after a terminal state
|
|
199
|
+
* (`ready`, `failed`, `cancelled`). Polls natively every `intervalMs`.
|
|
200
|
+
*
|
|
201
|
+
* ```ts
|
|
202
|
+
* for await (const s of download.progress()) setProgress(s.progress);
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
progress(options?: {
|
|
206
|
+
intervalMs?: number;
|
|
207
|
+
}): AsyncGenerator<DownloadStatus, void, void>;
|
|
208
|
+
/** Free the handle (the transfer keeps going unless cancelled). */
|
|
209
|
+
release(): Promise<void>;
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/model.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,QAAQ,EACR,gBAAgB,EAChB,eAAe,EACf,SAAS,EACT,WAAW,EACX,eAAe,EACf,SAAS,EACV,MAAM,SAAS,CAAC;AAYjB;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,6CAA6C;IAC7C,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,sDAAsD;IACtD,OAAO,CAAC,EAAE,eAAe,EAAE,CAAC;IAC5B,6EAA6E;IAC7E,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,4DAA4D;IAC5D,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,4DAA4D;IAC5D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B;;;;OAIG;IACH,MAAM,CAAC,EAAE,eAAe,CAAC;CAC1B;AAED,kFAAkF;AAClF,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EA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AC;IAM/D,mDAAmD;IAC7C,MAAM,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAIpC,sDAAsD;IAChD,YAAY,IAAI,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAI/C,2BAA2B;IACrB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAIvD;;;;OAIG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAGzB;AA+BD;;;;GAIG;AACH,qBAAa,aAAa;IAEZ,QAAQ,CAAC,MAAM,EAAE,MAAM;IADnC,gBAAgB;gBACK,MAAM,EAAE,MAAM;IAEnC,wDAAwD;IAClD,MAAM,IAAI,OAAO,CAAC,cAAc,CAAC;IAMvC,iEAAiE;IACjE,KAAK,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAI/B,iEAAiE;IACjE,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAIvB;;;;;;;OAOG;IACH,QAAQ,CAAC,OAAO,GAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,cAAc,CAAC,cAAc,EAAE,IAAI,EAAE,IAAI,CAAC;IAI3F,mEAAmE;IACnE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAGzB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Envelope, PipelineInfo, PipelineResult } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* A multi-stage pipeline (e.g. ASR → LLM → TTS) defined in YAML. A run
|
|
4
|
+
* returns every stage's output, so a voice assistant can show what it heard
|
|
5
|
+
* and what it answered while it plays the audio:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const pipeline = await Pipeline.fromFile(path);
|
|
9
|
+
* const result = await pipeline.run(Envelope.audio(pcmBase64));
|
|
10
|
+
* const heard = result.stages.find((s) => s.stageId === 'asr')?.text;
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare class Pipeline {
|
|
14
|
+
/** Opaque native handle. */
|
|
15
|
+
readonly handle: string;
|
|
16
|
+
private constructor();
|
|
17
|
+
/** Parse and load a pipeline from YAML content. */
|
|
18
|
+
static fromYaml(yaml: string): Promise<Pipeline>;
|
|
19
|
+
/** Read, parse and load a pipeline YAML file. */
|
|
20
|
+
static fromFile(path: string): Promise<Pipeline>;
|
|
21
|
+
/** Load a pipeline bundle. */
|
|
22
|
+
static fromBundle(path: string): Promise<Pipeline>;
|
|
23
|
+
/** Name and stage ids, in execution order. */
|
|
24
|
+
info(): Promise<PipelineInfo>;
|
|
25
|
+
/**
|
|
26
|
+
* Run every stage, downloading any missing model first. Per-stage
|
|
27
|
+
* generation settings belong in the YAML; only `correlationId` applies here.
|
|
28
|
+
*/
|
|
29
|
+
run(envelope: Envelope, options?: {
|
|
30
|
+
correlationId?: string;
|
|
31
|
+
}): Promise<PipelineResult>;
|
|
32
|
+
/** Free the native pipeline. */
|
|
33
|
+
release(): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=pipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../src/pipeline.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAOtE;;;;;;;;;;GAUG;AACH,qBAAa,QAAQ;IAEjB,4BAA4B;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM;IAFzB,OAAO;IAKP,mDAAmD;WACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAItD,iDAAiD;WACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAItD,8BAA8B;WACjB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAIxD,8CAA8C;IACxC,IAAI,IAAI,OAAO,CAAC,YAAY,CAAC;IAInC;;;OAGG;IACG,GAAG,CACP,QAAQ,EAAE,QAAQ,EAClB,OAAO,GAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAO,GACvC,OAAO,CAAC,cAAc,CAAC;IAS1B,gCAAgC;IAChC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAGzB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { GenerationConfig, ToolDefinition } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Greedy decoding (deterministic, temperature 0): the usual choice for
|
|
4
|
+
* extraction and tool calling.
|
|
5
|
+
*/
|
|
6
|
+
export declare function greedy(options?: {
|
|
7
|
+
maxTokens?: number;
|
|
8
|
+
grammar?: string;
|
|
9
|
+
tools?: ToolDefinition[];
|
|
10
|
+
}): GenerationConfig;
|
|
11
|
+
/** Higher temperature, for more varied output. */
|
|
12
|
+
export declare function creative(options?: {
|
|
13
|
+
maxTokens?: number;
|
|
14
|
+
tools?: ToolDefinition[];
|
|
15
|
+
}): GenerationConfig;
|
|
16
|
+
/** Preset factories for {@link GenerationConfig}. */
|
|
17
|
+
export declare const GenerationConfigs: {
|
|
18
|
+
greedy: typeof greedy;
|
|
19
|
+
creative: typeof creative;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=presets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["../../src/presets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAKhE;;;GAGG;AACH,wBAAgB,MAAM,CACpB,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,cAAc,EAAE,CAAA;CAAO,GAC/E,gBAAgB,CAQlB;AAED,kDAAkD;AAClD,wBAAgB,QAAQ,CACtB,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,cAAc,EAAE,CAAA;CAAO,GAC7D,gBAAgB,CAQlB;AAED,qDAAqD;AACrD,eAAO,MAAM,iBAAiB;;;CAAuB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { PartialResult } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* A live ASR session: feed microphone PCM in, read partial transcripts out.
|
|
4
|
+
* Open one with `model.stream()`.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* const session = await model.stream();
|
|
8
|
+
* (async () => {
|
|
9
|
+
* for await (const partial of session.partials()) setCaption(partial.text);
|
|
10
|
+
* })();
|
|
11
|
+
* // from your audio callback (Float32, mono, 16 kHz):
|
|
12
|
+
* await session.feed(samples);
|
|
13
|
+
* // when the user stops talking:
|
|
14
|
+
* const transcript = await session.flush();
|
|
15
|
+
* await session.release();
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare class StreamingSession {
|
|
19
|
+
/** Opaque native handle. */
|
|
20
|
+
readonly handle: string;
|
|
21
|
+
/** @internal Use `model.stream()`. */
|
|
22
|
+
constructor(
|
|
23
|
+
/** Opaque native handle. */
|
|
24
|
+
handle: string);
|
|
25
|
+
/**
|
|
26
|
+
* Queue PCM samples (Float32, mono, 16 kHz). Transcription happens off the
|
|
27
|
+
* JS thread; this only waits when the native queue is full.
|
|
28
|
+
*/
|
|
29
|
+
feed(samples: Float32Array | ArrayLike<number>): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Partial transcripts as they arrive, ending when the session finishes
|
|
32
|
+
* (after {@link flush} or {@link cancel}). Each partial is cumulative:
|
|
33
|
+
* render it in place of the previous one. Use one iterator per session.
|
|
34
|
+
*/
|
|
35
|
+
partials(): AsyncGenerator<PartialResult, void, void>;
|
|
36
|
+
/**
|
|
37
|
+
* Drain the buffered audio and return the complete transcript. The session
|
|
38
|
+
* is over afterwards.
|
|
39
|
+
*/
|
|
40
|
+
flush(): Promise<string>;
|
|
41
|
+
/** Start over on fresh audio without reloading the model. */
|
|
42
|
+
reset(): Promise<void>;
|
|
43
|
+
/** Stop and discard buffered audio — the "user walked away" path. */
|
|
44
|
+
cancel(): Promise<void>;
|
|
45
|
+
/** Whether the session still accepts audio. */
|
|
46
|
+
isRunning(): Promise<boolean>;
|
|
47
|
+
/** Free the native session (cancelling it if still running). */
|
|
48
|
+
release(): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,gBAAgB;IAGzB,4BAA4B;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM;IAHzB,sCAAsC;;IAEpC,4BAA4B;IACnB,MAAM,EAAE,MAAM;IAGzB;;;OAGG;IACH,IAAI,CAAC,OAAO,EAAE,YAAY,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9D;;;;OAIG;IACI,QAAQ,IAAI,cAAc,CAAC,aAAa,EAAE,IAAI,EAAE,IAAI,CAAC;IAQ5D;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IAIxB,6DAA6D;IAC7D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,qEAAqE;IACrE,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAIvB,+CAA+C;IAC/C,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAI7B,gEAAgE;IAChE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAGzB"}
|