web-sdk-pp-detection 0.1.0

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.
@@ -0,0 +1,617 @@
1
+ type Backend = "wasm" | "webgpu";
2
+ type BackendPreference = Backend | "auto";
3
+ type ExecutionMode = "main" | "worker";
4
+ type Precision = "fp32" | "fp16" | "int8" | "int4" | "fp8";
5
+ type ModelSourceKind = "git-lfs" | "huggingface" | "modelscope" | "custom";
6
+ interface ModelIdentity {
7
+ readonly id: string;
8
+ readonly version: string;
9
+ }
10
+ interface ModelSource {
11
+ readonly kind: ModelSourceKind;
12
+ readonly repository: string;
13
+ readonly revision: string;
14
+ readonly path: string;
15
+ readonly downloadUrl: string;
16
+ readonly bytes: number;
17
+ readonly sha256: string;
18
+ }
19
+ interface ModelVariant {
20
+ readonly id: string;
21
+ readonly precision: Precision;
22
+ readonly quantization?: string | null;
23
+ readonly backends: readonly Backend[];
24
+ readonly status?: "stable" | "labs" | "blocked";
25
+ }
26
+ interface DetectionModelVariant extends ModelVariant {
27
+ readonly opset: number;
28
+ readonly bytes: number;
29
+ readonly parameterCount: number | null;
30
+ readonly sources: readonly ModelSource[];
31
+ }
32
+ interface TensorContract {
33
+ readonly name: string;
34
+ readonly shape: readonly number[];
35
+ readonly dtype: string;
36
+ }
37
+ interface DetectionPreprocessing {
38
+ readonly size: {
39
+ readonly width: number;
40
+ readonly height: number;
41
+ };
42
+ readonly rescaleFactor: number;
43
+ readonly resizeMode?: "letterbox" | "stretch";
44
+ readonly interpolation?: "bilinear" | "bicubic";
45
+ readonly mean?: readonly number[];
46
+ readonly std?: readonly number[];
47
+ readonly doResize?: boolean;
48
+ readonly doRescale?: boolean;
49
+ readonly doNormalize?: boolean;
50
+ }
51
+ interface DetectionPostprocessing {
52
+ readonly type: "nms";
53
+ readonly scoreThreshold: number;
54
+ readonly iouThreshold: number;
55
+ readonly matrixCoordinates?: "pixels" | "normalized";
56
+ readonly queryCoordinates?: "pixels" | "normalized";
57
+ readonly queryBoxFormat?: "cxcywh" | "xyxy";
58
+ }
59
+ interface RuntimeDetectionManifest {
60
+ readonly schemaVersion: 1;
61
+ readonly model: ModelIdentity;
62
+ readonly input: TensorContract;
63
+ readonly outputs: readonly TensorContract[];
64
+ readonly preprocessing: DetectionPreprocessing;
65
+ readonly postprocessing: DetectionPostprocessing;
66
+ readonly labels: readonly string[];
67
+ readonly variants: readonly DetectionModelVariant[];
68
+ }
69
+ interface DetectionManifest {
70
+ readonly id: string;
71
+ readonly version: string;
72
+ readonly variants?: readonly ModelVariant[];
73
+ }
74
+ type ModelBackend = Backend;
75
+ type ModelPrecision = Precision;
76
+ interface ModelManifestMetadata {
77
+ readonly architecture: string;
78
+ readonly id: string;
79
+ readonly modelType: string;
80
+ readonly parameterCount: number | null;
81
+ readonly version: string;
82
+ }
83
+ interface ModelManifestSource {
84
+ readonly files: Readonly<Record<string, string>>;
85
+ readonly license: string;
86
+ readonly name: string;
87
+ readonly url: string;
88
+ }
89
+ interface ModelManifestVariant {
90
+ readonly backendCompatibility: readonly ModelBackend[];
91
+ readonly bytes: number;
92
+ readonly filename: string;
93
+ readonly id: string;
94
+ readonly opset: number;
95
+ readonly precision: ModelPrecision;
96
+ readonly quantization: string | null;
97
+ readonly sha256: string;
98
+ readonly url: string;
99
+ readonly validation: Readonly<{
100
+ included: boolean;
101
+ pass: boolean;
102
+ report: string;
103
+ }>;
104
+ }
105
+ interface ModelManifest {
106
+ readonly input: TensorContract;
107
+ readonly labels: readonly string[];
108
+ readonly minSdkVersion: string;
109
+ readonly model: ModelManifestMetadata;
110
+ readonly outputs: readonly TensorContract[];
111
+ readonly preprocessing: Readonly<{
112
+ doNormalize: boolean;
113
+ doRescale: boolean;
114
+ doResize: boolean;
115
+ readonly resizeMode?: "letterbox" | "stretch";
116
+ readonly interpolation?: "bilinear" | "bicubic";
117
+ imageMean: readonly [number, number, number];
118
+ imageStd: readonly [number, number, number];
119
+ resample: 2 | 3;
120
+ rescaleFactor: number;
121
+ size: Readonly<{
122
+ height: number;
123
+ width: number;
124
+ }>;
125
+ }>;
126
+ readonly schemaVersion: 1;
127
+ readonly source: ModelManifestSource;
128
+ readonly variantPriority: readonly string[];
129
+ readonly variants: readonly ModelManifestVariant[];
130
+ }
131
+ type PPDetectionModel = string | RuntimeDetectionManifest | ModelManifest | Readonly<{
132
+ data: ArrayBuffer;
133
+ manifest: RuntimeDetectionManifest | ModelManifest;
134
+ }>;
135
+ type PPDetectionProgressPhase = "capabilities" | "manifest" | "model" | "session" | "fallback" | "ready" | "preprocess" | "inference" | "postprocess";
136
+ interface PPDetectionProgressEvent {
137
+ readonly phase: PPDetectionProgressPhase;
138
+ readonly status: "start" | "progress" | "complete";
139
+ readonly loadedBytes?: number;
140
+ readonly totalBytes?: number;
141
+ readonly fallback?: PPDetectionFallback;
142
+ }
143
+ interface CreatePPDetectionOptions {
144
+ readonly allowFallback?: boolean;
145
+ readonly backend?: BackendPreference;
146
+ readonly cache?: boolean | "memory" | "indexeddb";
147
+ readonly executionMode?: ExecutionMode;
148
+ readonly manifest?: RuntimeDetectionManifest;
149
+ readonly model?: PPDetectionModel;
150
+ readonly onProgress?: (event: PPDetectionProgressEvent) => void;
151
+ readonly ort?: Readonly<{
152
+ module?: unknown;
153
+ wasm?: Readonly<{
154
+ paths?: string;
155
+ numThreads?: number;
156
+ }>;
157
+ }>;
158
+ readonly precision?: Precision | "auto";
159
+ readonly signal?: AbortSignal;
160
+ readonly source?: ModelSourceKind | "auto";
161
+ }
162
+ interface DetectionCapabilities {
163
+ readonly webgpu: boolean;
164
+ readonly worker: boolean;
165
+ readonly offscreenCanvas: boolean;
166
+ readonly wasmSimd: boolean;
167
+ readonly wasmThreads: boolean;
168
+ }
169
+ interface RuntimeInfo {
170
+ readonly requestedBackend: BackendPreference;
171
+ readonly actualBackend: Backend;
172
+ readonly requestedPrecision: Precision;
173
+ readonly actualPrecision: Precision;
174
+ readonly executionMode: ExecutionMode;
175
+ }
176
+ interface TimingBreakdown {
177
+ readonly modelDownloadMs?: number;
178
+ readonly modelCacheReadMs?: number;
179
+ readonly integrityMs?: number;
180
+ readonly sessionMs?: number;
181
+ readonly inferenceMs?: number;
182
+ readonly totalMs?: number;
183
+ }
184
+ interface DetectionTimings {
185
+ readonly decodeMs: number;
186
+ readonly preprocessMs: number;
187
+ readonly inferenceMs: number;
188
+ readonly postprocessMs: number;
189
+ readonly totalMs: number;
190
+ }
191
+ interface DetectionBox {
192
+ readonly x: number;
193
+ readonly y: number;
194
+ readonly width: number;
195
+ readonly height: number;
196
+ readonly xMin: number;
197
+ readonly yMin: number;
198
+ readonly xMax: number;
199
+ readonly yMax: number;
200
+ }
201
+ interface DetectionPoint {
202
+ readonly x: number;
203
+ readonly y: number;
204
+ }
205
+ interface Detection {
206
+ readonly index: number;
207
+ readonly classId: number;
208
+ readonly labelId: number;
209
+ readonly label: string;
210
+ readonly score: number;
211
+ readonly box: DetectionBox;
212
+ readonly polygon: readonly DetectionPoint[];
213
+ }
214
+ interface DetectOptions {
215
+ readonly threshold?: number;
216
+ readonly classThresholds?: Readonly<Record<string, number>>;
217
+ readonly signal?: AbortSignal;
218
+ readonly timestampMs?: number;
219
+ readonly metadata?: unknown;
220
+ }
221
+ interface PPDetectionFallback {
222
+ readonly cause: unknown;
223
+ readonly code: string;
224
+ readonly message: string;
225
+ readonly precision: Precision;
226
+ readonly provider: Backend;
227
+ readonly stage: string;
228
+ readonly variantId: string;
229
+ }
230
+ interface PPDetectionRuntimeInfo {
231
+ readonly requestedBackend: BackendPreference;
232
+ readonly backend: Backend;
233
+ readonly precision: Precision;
234
+ readonly mode: ExecutionMode;
235
+ readonly fallbacks: readonly PPDetectionFallback[];
236
+ readonly capabilities: DetectionCapabilities;
237
+ }
238
+ interface PPDetectionModelInfo {
239
+ readonly id: string;
240
+ readonly version: string;
241
+ readonly variantId: string;
242
+ readonly precision: Precision;
243
+ readonly bytes: number;
244
+ readonly parameterCount: number | null;
245
+ readonly opset: number;
246
+ readonly source: PPDetectionModelSourceInfo;
247
+ }
248
+ interface PPDetectionModelSourceInfo {
249
+ readonly kind: ModelSourceKind;
250
+ readonly revision: string;
251
+ readonly bytes: number;
252
+ readonly sha256: string;
253
+ }
254
+ interface PPDetectionLoadTimings {
255
+ readonly modelDownloadMs?: number;
256
+ readonly modelCacheReadMs?: number;
257
+ readonly integrityMs?: number;
258
+ readonly sessionMs: number;
259
+ readonly totalMs: number;
260
+ }
261
+ interface PPDetectionResult {
262
+ readonly detections: readonly Detection[];
263
+ readonly image: Readonly<{
264
+ input: Readonly<{
265
+ width: number;
266
+ height: number;
267
+ }>;
268
+ original: Readonly<{
269
+ width: number;
270
+ height: number;
271
+ }>;
272
+ }>;
273
+ readonly model: PPDetectionModelInfo;
274
+ readonly runtime: PPDetectionRuntimeInfo;
275
+ readonly timings: DetectionTimings;
276
+ readonly frame?: Readonly<{
277
+ timestampMs?: number;
278
+ metadata?: unknown;
279
+ }>;
280
+ }
281
+ interface ModelInfo {
282
+ readonly id: string;
283
+ readonly version: string;
284
+ readonly variantId: string;
285
+ readonly precision: Precision;
286
+ readonly bytes?: number;
287
+ readonly parameterCount?: number | null;
288
+ }
289
+
290
+ interface CapabilityProbeOptions {
291
+ readonly global?: typeof globalThis;
292
+ }
293
+ declare function probeCapabilities(options?: CapabilityProbeOptions): DetectionCapabilities;
294
+
295
+ interface ImageRaster {
296
+ readonly width: number;
297
+ readonly height: number;
298
+ readonly rgba: Uint8ClampedArray;
299
+ }
300
+ type ImageSource = Blob | File | ImageBitmap | HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | OffscreenCanvas | ImageData | VideoFrame | ImageRaster;
301
+ interface DecodedImage extends ImageRaster {
302
+ readonly decodeMs: number;
303
+ }
304
+
305
+ interface DrawableImage {
306
+ readonly width?: number;
307
+ readonly height?: number;
308
+ readonly naturalWidth?: number;
309
+ readonly naturalHeight?: number;
310
+ readonly videoWidth?: number;
311
+ readonly videoHeight?: number;
312
+ readonly displayWidth?: number;
313
+ readonly displayHeight?: number;
314
+ close?(): void;
315
+ }
316
+ interface RasterContext {
317
+ drawImage(source: unknown, dx: number, dy: number): void;
318
+ getImageData(x: number, y: number, width: number, height: number): {
319
+ data: Uint8ClampedArray;
320
+ };
321
+ }
322
+ interface RasterCanvas {
323
+ getContext(type: "2d", options?: CanvasRenderingContext2DSettings): RasterContext | null;
324
+ }
325
+ interface DecodeImageEnvironment {
326
+ readonly createCanvas?: (width: number, height: number) => RasterCanvas;
327
+ readonly createImageBitmap?: (source: Blob) => Promise<DrawableImage>;
328
+ readonly signal?: AbortSignal;
329
+ readonly now?: () => number;
330
+ }
331
+
332
+ interface InferenceInput {
333
+ readonly inputName: string;
334
+ readonly data: Float32Array;
335
+ readonly dims: readonly number[];
336
+ }
337
+ interface DetectionExecutor {
338
+ run(input: InferenceInput, signal?: AbortSignal): Promise<unknown>;
339
+ dispose(): Promise<void>;
340
+ }
341
+ interface PPDetectionDetectorOptions {
342
+ readonly capabilities: DetectionCapabilities;
343
+ readonly manifest: RuntimeDetectionManifest;
344
+ readonly model: PPDetectionModelInfo;
345
+ readonly runtime: PPDetectionRuntimeInfo;
346
+ readonly loadTimings: PPDetectionLoadTimings;
347
+ readonly loadExecutor: (signal?: AbortSignal) => Promise<DetectionExecutor>;
348
+ readonly decodeEnvironment?: Omit<DecodeImageEnvironment, "signal">;
349
+ readonly now?: () => number;
350
+ readonly onProgress?: (event: PPDetectionProgressEvent) => void;
351
+ readonly clearCurrentModelCache?: () => Promise<void>;
352
+ readonly clearAllCache?: () => Promise<void>;
353
+ readonly getCacheEstimate?: () => Promise<{
354
+ bytes: number;
355
+ entries: number;
356
+ }>;
357
+ readonly disposeResources?: () => Promise<void> | void;
358
+ }
359
+ declare class PPDetectionDetectorImplementation {
360
+ private readonly options;
361
+ readonly capabilities: DetectionCapabilities;
362
+ readonly manifest: RuntimeDetectionManifest;
363
+ readonly model: PPDetectionModelInfo;
364
+ readonly runtime: PPDetectionRuntimeInfo;
365
+ readonly loadTimings: PPDetectionLoadTimings;
366
+ private readonly clock;
367
+ private executor?;
368
+ private loadPromise?;
369
+ private disposePromise?;
370
+ private queue;
371
+ private disposed;
372
+ constructor(options: PPDetectionDetectorOptions);
373
+ load(options?: {
374
+ signal?: AbortSignal;
375
+ }): Promise<void>;
376
+ detect(input: ImageSource, options?: DetectOptions): Promise<PPDetectionResult>;
377
+ getCacheEstimate(): Promise<{
378
+ bytes: number;
379
+ entries: number;
380
+ }>;
381
+ clearCurrentModelCache(): Promise<void>;
382
+ clearAllCache(): Promise<void>;
383
+ clearModelCache(): Promise<void>;
384
+ dispose(): Promise<void>;
385
+ private detectOnce;
386
+ }
387
+ type PPDetectionDetector = PPDetectionDetectorImplementation;
388
+
389
+ type PPDetectionErrorCode = "CAPABILITY_UNSUPPORTED" | "INVALID_INPUT" | "INVALID_MANIFEST" | "MODEL_INCOMPATIBLE" | "MODEL_SOURCE_UNAVAILABLE" | "MODEL_DOWNLOAD_FAILED" | "MODEL_INTEGRITY_FAILED" | "SESSION_CREATE_FAILED" | "INFERENCE_FAILED" | "OUT_OF_MEMORY" | "ABORTED" | "DISPOSED";
390
+ declare class PPDetectionError extends Error {
391
+ readonly code: PPDetectionErrorCode;
392
+ readonly details: Readonly<Record<string, unknown>>;
393
+ constructor(code: PPDetectionErrorCode, message: string, details?: Readonly<Record<string, unknown>>, options?: ErrorOptions);
394
+ }
395
+
396
+ interface SelectExecutionOptions {
397
+ readonly backend?: BackendPreference;
398
+ readonly precision?: Precision;
399
+ readonly executionMode?: ExecutionMode;
400
+ readonly allowFallback?: boolean;
401
+ }
402
+ interface ExecutionCandidate {
403
+ readonly variantId: string;
404
+ readonly backend: Backend;
405
+ readonly precision: Precision;
406
+ readonly executionMode: ExecutionMode;
407
+ }
408
+ type ExecutionPlan = RuntimeInfo & {
409
+ readonly variantId: string;
410
+ readonly candidates: readonly ExecutionCandidate[];
411
+ };
412
+ declare function selectExecutionPlan(options: SelectExecutionOptions, capabilities: DetectionCapabilities, manifest: DetectionManifest): ExecutionPlan;
413
+
414
+ interface OrtInferenceSession {
415
+ run(feeds: Record<string, unknown>, options?: Record<string, unknown>): Promise<unknown>;
416
+ release?(): Promise<void> | void;
417
+ }
418
+ interface OrtModule {
419
+ readonly env: {
420
+ readonly wasm?: Record<string, unknown>;
421
+ };
422
+ readonly InferenceSession: {
423
+ create(model: ArrayBuffer, options: Record<string, unknown>): Promise<OrtInferenceSession>;
424
+ };
425
+ readonly Tensor?: new (type: string, data: unknown, dims: readonly number[]) => unknown;
426
+ }
427
+ interface OrtSessionHandle {
428
+ readonly plan: ExecutionPlan;
429
+ readonly sessionMs: number;
430
+ run(feeds: Record<string, unknown>, options?: {
431
+ readonly signal?: AbortSignal;
432
+ }): Promise<unknown>;
433
+ dispose(): Promise<void>;
434
+ }
435
+ interface CreateOrtSessionOptions {
436
+ readonly ort?: OrtModule;
437
+ readonly loadOrt?: () => Promise<OrtModule>;
438
+ readonly wasmPaths?: string;
439
+ readonly numThreads?: number;
440
+ readonly sessionOptions?: Readonly<Record<string, unknown>>;
441
+ }
442
+ declare function createOrtSession(modelBytes: ArrayBuffer, plan: ExecutionPlan, options?: CreateOrtSessionOptions): Promise<OrtSessionHandle>;
443
+
444
+ interface WorkerOrtOptions {
445
+ readonly wasmPaths?: string;
446
+ readonly numThreads?: number;
447
+ }
448
+ type WorkerRequest = {
449
+ readonly id: string;
450
+ readonly type: "load";
451
+ readonly modelBytes: ArrayBuffer;
452
+ readonly plan: ExecutionPlan;
453
+ readonly ort?: WorkerOrtOptions;
454
+ } | {
455
+ readonly id: string;
456
+ readonly type: "run";
457
+ readonly input: unknown;
458
+ } | {
459
+ readonly id: string;
460
+ readonly type: "cancel";
461
+ readonly requestId: string;
462
+ } | {
463
+ readonly id: string;
464
+ readonly type: "dispose";
465
+ };
466
+ type WorkerResponse = {
467
+ readonly id: string;
468
+ readonly type: "progress";
469
+ readonly phase: string;
470
+ readonly status: string;
471
+ readonly loadedBytes?: number;
472
+ readonly totalBytes?: number;
473
+ } | {
474
+ readonly id: string;
475
+ readonly type: "result";
476
+ readonly result: unknown;
477
+ } | {
478
+ readonly id: string;
479
+ readonly type: "error";
480
+ readonly error: {
481
+ readonly code: string;
482
+ readonly message: string;
483
+ readonly details?: Record<string, unknown>;
484
+ };
485
+ };
486
+
487
+ declare function parseDetectionManifest(value: unknown): RuntimeDetectionManifest;
488
+
489
+ declare function parseModelManifest(value: unknown): ModelManifest;
490
+ declare function adaptModelManifest(manifest: ModelManifest): RuntimeDetectionManifest;
491
+
492
+ type ModelSourceSelection = ModelSourceKind | "auto";
493
+ interface ResolveModelAssetSelection {
494
+ readonly variantId?: string;
495
+ readonly sourceKind?: ModelSourceSelection;
496
+ }
497
+ interface ResolvedModelAsset {
498
+ readonly model: ModelIdentity;
499
+ readonly variant: DetectionModelVariant;
500
+ readonly source: ModelSource;
501
+ }
502
+ declare function resolveModelAsset(selection: ResolveModelAssetSelection, manifest: RuntimeDetectionManifest): ResolvedModelAsset;
503
+
504
+ type ModelFetcher = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
505
+ interface ModelDownloadProgress {
506
+ readonly loadedBytes: number;
507
+ readonly totalBytes?: number;
508
+ }
509
+ interface LoadModelAssetOptions {
510
+ readonly fetcher?: ModelFetcher;
511
+ readonly signal?: AbortSignal;
512
+ readonly onProgress?: (progress: ModelDownloadProgress) => void;
513
+ }
514
+ interface ModelBytes {
515
+ readonly bytes: ArrayBuffer;
516
+ readonly timings: Pick<TimingBreakdown, "modelDownloadMs" | "integrityMs">;
517
+ }
518
+ declare function loadModelAsset(asset: ResolvedModelAsset, options?: LoadModelAssetOptions): Promise<ModelBytes>;
519
+
520
+ interface CacheEstimate {
521
+ readonly bytes: number;
522
+ readonly entries: number;
523
+ }
524
+ interface ModelCache {
525
+ get(key: string): Promise<ArrayBuffer | undefined>;
526
+ put(key: string, bytes: ArrayBuffer): Promise<void>;
527
+ clearCurrent(key: string): Promise<void>;
528
+ clearAll(): Promise<void>;
529
+ estimate(): Promise<CacheEstimate>;
530
+ close?(): Promise<void> | void;
531
+ }
532
+
533
+ interface ModelManagerOptions {
534
+ readonly fetcher?: ModelFetcher;
535
+ readonly cache?: "memory" | "indexeddb" | false | ModelCache;
536
+ }
537
+ interface LoadManagedModelOptions {
538
+ readonly manifest: unknown;
539
+ readonly variantId?: string;
540
+ readonly sourceKind?: ModelSourceSelection;
541
+ readonly signal?: AbortSignal;
542
+ readonly onProgress?: (progress: ModelDownloadProgress) => void;
543
+ }
544
+ interface ModelSourceFailure {
545
+ readonly kind: ModelSourceKind;
546
+ readonly code: string;
547
+ readonly message: string;
548
+ }
549
+ interface LoadedManagedModel {
550
+ readonly bytes: ArrayBuffer;
551
+ readonly manifest: RuntimeDetectionManifest;
552
+ readonly variant: DetectionModelVariant;
553
+ readonly source: ModelSource;
554
+ readonly cacheKey: string;
555
+ readonly fromCache: boolean;
556
+ readonly failures: readonly ModelSourceFailure[];
557
+ readonly timings: TimingBreakdown;
558
+ }
559
+ declare class ModelManager {
560
+ private readonly fetcher?;
561
+ private readonly cache;
562
+ private readonly lifecycle;
563
+ private readonly activeLoads;
564
+ private currentKey?;
565
+ private disposed;
566
+ private disposePromise?;
567
+ constructor(options?: ModelManagerOptions);
568
+ cacheKey(variant: DetectionModelVariant, source: ModelSource, model?: ModelIdentity): string;
569
+ load(options: LoadManagedModelOptions): Promise<LoadedManagedModel>;
570
+ private loadActive;
571
+ estimate(): Promise<CacheEstimate>;
572
+ getCacheEstimate(): Promise<CacheEstimate>;
573
+ clearCurrentModelCache(): Promise<void>;
574
+ clearAllCache(): Promise<void>;
575
+ dispose(): Promise<void>;
576
+ }
577
+
578
+ declare class MemoryModelCache implements ModelCache {
579
+ private readonly entries;
580
+ get(key: string): Promise<ArrayBuffer | undefined>;
581
+ put(key: string, bytes: ArrayBuffer): Promise<void>;
582
+ clearCurrent(key: string): Promise<void>;
583
+ clearAll(): Promise<void>;
584
+ estimate(): Promise<CacheEstimate>;
585
+ close(): Promise<void>;
586
+ }
587
+
588
+ interface IndexedDBModelCacheOptions {
589
+ readonly indexedDB?: IDBFactory;
590
+ readonly databaseName?: string;
591
+ }
592
+ declare class IndexedDBModelCache implements ModelCache {
593
+ private readonly factory;
594
+ private readonly databaseName;
595
+ private database?;
596
+ constructor(options?: IndexedDBModelCacheOptions);
597
+ get(key: string): Promise<ArrayBuffer | undefined>;
598
+ put(key: string, bytes: ArrayBuffer): Promise<void>;
599
+ clearCurrent(key: string): Promise<void>;
600
+ clearAll(): Promise<void>;
601
+ estimate(): Promise<CacheEstimate>;
602
+ close(): Promise<void>;
603
+ private open;
604
+ private request;
605
+ }
606
+
607
+ declare global {
608
+ var __PPDETECTION_SCRIPT_URL__: string | undefined;
609
+ }
610
+ declare const CURRENT_SDK_VERSION = "0.1.0";
611
+
612
+ declare function probePPDetectionCapabilities(options?: CapabilityProbeOptions): DetectionCapabilities;
613
+
614
+ declare function createPPDetection(options?: CreatePPDetectionOptions): Promise<PPDetectionDetectorImplementation>;
615
+ declare function clearModelCache(): Promise<void>;
616
+
617
+ export { type Backend, type BackendPreference, CURRENT_SDK_VERSION, type CacheEstimate, type CapabilityProbeOptions, type CreateOrtSessionOptions, type CreatePPDetectionOptions, type DecodedImage, type DetectOptions, type Detection, type DetectionBox, type DetectionCapabilities, type DetectionManifest, type DetectionModelVariant, type DetectionPoint, type DetectionPostprocessing, type DetectionPreprocessing, type DetectionTimings, type ExecutionCandidate, type ExecutionMode, type ExecutionPlan, type ImageRaster, type ImageSource, IndexedDBModelCache, type IndexedDBModelCacheOptions, type LoadManagedModelOptions, type LoadModelAssetOptions, type LoadedManagedModel, MemoryModelCache, type ModelBackend, type ModelBytes, type ModelCache, type ModelDownloadProgress, type ModelFetcher, type ModelInfo, ModelManager, type ModelManagerOptions, type ModelManifest, type ModelManifestMetadata, type ModelManifestSource, type ModelManifestVariant, type ModelPrecision, type ModelSource, type ModelSourceFailure, type ModelSourceKind, type ModelSourceSelection, type ModelVariant, type OrtModule, type OrtSessionHandle, type PPDetectionDetector, PPDetectionError, type PPDetectionErrorCode, type PPDetectionFallback, type PPDetectionLoadTimings, type PPDetectionModel, type PPDetectionModelInfo, type PPDetectionModelSourceInfo, type PPDetectionProgressEvent, type PPDetectionResult, type PPDetectionRuntimeInfo, type Precision, type ResolveModelAssetSelection, type ResolvedModelAsset, type RuntimeDetectionManifest, type RuntimeInfo, type SelectExecutionOptions, type TensorContract, type TimingBreakdown, type WorkerOrtOptions, type WorkerRequest, type WorkerResponse, adaptModelManifest, clearModelCache, createOrtSession, createPPDetection, loadModelAsset, parseDetectionManifest, parseModelManifest, probeCapabilities, probePPDetectionCapabilities, resolveModelAsset, selectExecutionPlan };