llama-web-bridge 0.1.91 → 0.1.93

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.
@@ -364,6 +364,11 @@ export class ModelUnloadedError extends Error {
364
364
  constructor(message?: string);
365
365
  }
366
366
 
367
+ export interface ModelTransferLengthError extends Error {
368
+ readonly name: 'ModelTransferLengthError';
369
+ readonly code: 'MODEL_TRANSFER_LENGTH_ERROR';
370
+ }
371
+
367
372
  export type ModelStagingErrorCode =
368
373
  | 'MODEL_STAGING_ALLOCATION_FAILED'
369
374
  | 'MODEL_TENSOR_SIZE_LIMIT_EXCEEDED'
@@ -547,15 +552,58 @@ export function enableBridgeWorkerHost(): void;
547
552
  * remain out of band; disposal rejects queued/new work while active work settles
548
553
  * first. See docs/api.md "Operation serialization".
549
554
  */
555
+ export type CoreMemoryVariant = 'wasm32' | 'memory64';
556
+ export type CoreThreadingMode = 'threaded' | 'single-thread';
557
+ export type CoreExecutionMode = 'worker' | 'main-thread';
558
+ export type CoreFallbackReason = 'unsupported' | 'timeout' | 'init_error';
559
+
560
+ export interface CorePreflightResult {
561
+ variant: CoreMemoryVariant;
562
+ threading: CoreThreadingMode;
563
+ execution: CoreExecutionMode;
564
+ fallback: boolean;
565
+ fallbackReason: CoreFallbackReason | null;
566
+ loaderUrl: string | null;
567
+ wasmUrl: string | null;
568
+ }
569
+
570
+ export type CoreAssetErrorCode = 'CORE_ASSET_UNAVAILABLE' | 'CORE_PREFLIGHT_UNSUPPORTED';
571
+ export type CoreAssetKind = 'loader' | 'wasm' | 'worker';
572
+
573
+ export interface CoreAssetErrorDetails {
574
+ asset: CoreAssetKind;
575
+ url?: string | null;
576
+ httpStatus?: number | null;
577
+ variant?: CoreMemoryVariant | null;
578
+ }
579
+
580
+ export class CoreAssetError extends Error {
581
+ readonly code: CoreAssetErrorCode;
582
+ readonly asset: CoreAssetKind;
583
+ readonly url: string | null;
584
+ readonly httpStatus: number | null;
585
+ readonly variant: CoreMemoryVariant | null;
586
+ constructor(code: CoreAssetErrorCode, message: string, details: CoreAssetErrorDetails);
587
+ }
588
+
550
589
  export class LlamaWebGpuBridge {
551
590
  static supportsSafariAdaptiveGpu: boolean;
552
591
  /** `true` when `createCompletion` accepts `onUsage`. Bridges before v0.1.54 lack it; through v0.1.52 their worker mode rejects a function option with a `DataCloneError`. */
553
592
  static supportsCompletionUsage: boolean;
554
593
  /** This bridge supports cache queries and opt-in projector caching. */
555
594
  static supportsModelCacheQuery: boolean;
595
+ /** This bridge honors `jsBackedModelStaging` and validates worker/core staging support. */
596
+ static supportsJsBackedModelStaging: boolean;
597
+ static supportsCorePreflight: boolean;
556
598
 
557
599
  constructor(config?: LlamaWebGpuBridgeConfig);
558
600
 
601
+ /**
602
+ * Initializes the selected core before model transfer. Wasm and transient core initialization failures can be retried.
603
+ * The browser caches a failed loader import by URL. To retry that import, reload the page or use a different loader URL.
604
+ */
605
+ preflightCore(): Promise<CorePreflightResult>;
606
+ /** Can reject with `ModelTransferLengthError` if transfer length validation fails. */
559
607
  loadModelFromUrl(url: string | string[], options?: LoadModelOptions): Promise<unknown>;
560
608
  prefetchModelToCache(url: string | string[], options?: LoadModelOptions): Promise<unknown>;
561
609
  evictModelFromCache(url: string | string[], options?: Record<string, unknown>): Promise<unknown>;
@@ -591,6 +639,7 @@ export class LlamaWebGpuBridge {
591
639
  embedBatch(inputs: EmbedInput[], options?: EmbedOptions): Promise<number[][]>;
592
640
  scoreNextToken(prompt: string, options?: NextTokenScoreOptions): Promise<NextTokenScores>;
593
641
 
642
+ /** Can reject with `ModelTransferLengthError` if transfer length validation fails. */
594
643
  loadMultimodalProjector(url: string, options?: MultimodalProjectorLoadOptions): Promise<unknown>;
595
644
  unloadMultimodalProjector(): Promise<unknown>;
596
645
  supportsVision(): boolean;