@plasius/gpu-model-runtime 0.1.1
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 +203 -0
- package/README.md +75 -0
- package/dist/index.cjs +567 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +275 -0
- package/dist/index.d.ts +275 -0
- package/dist/index.js +530 -0
- package/dist/index.js.map +1 -0
- package/package.json +102 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
type ModelSourceKind = "file-path" | "url" | "blob-storage-url" | "blob" | "array-buffer" | "uint8-array" | "stream";
|
|
2
|
+
type ModelProvenance = Readonly<{
|
|
3
|
+
sourceId?: string;
|
|
4
|
+
sourceSystem?: string;
|
|
5
|
+
acquiredAt?: string;
|
|
6
|
+
licenseHint?: string;
|
|
7
|
+
}>;
|
|
8
|
+
type ModelResourceInput = Readonly<{
|
|
9
|
+
bytes: ArrayBuffer | Blob | Uint8Array;
|
|
10
|
+
contentType?: string;
|
|
11
|
+
integrity?: string;
|
|
12
|
+
}>;
|
|
13
|
+
type ModelPackage = Readonly<{
|
|
14
|
+
entrypoint?: string;
|
|
15
|
+
baseUrl?: string;
|
|
16
|
+
resources?: Readonly<Record<string, ModelResourceInput>>;
|
|
17
|
+
}>;
|
|
18
|
+
type ModelSource = Readonly<{
|
|
19
|
+
kind: "file-path";
|
|
20
|
+
path: string;
|
|
21
|
+
mimeTypeHint?: string;
|
|
22
|
+
fileNameHint?: string;
|
|
23
|
+
package?: ModelPackage;
|
|
24
|
+
provenance?: ModelProvenance;
|
|
25
|
+
}> | Readonly<{
|
|
26
|
+
kind: "url";
|
|
27
|
+
url: string;
|
|
28
|
+
headers?: Readonly<Record<string, string>>;
|
|
29
|
+
mimeTypeHint?: string;
|
|
30
|
+
package?: ModelPackage;
|
|
31
|
+
provenance?: ModelProvenance;
|
|
32
|
+
}> | Readonly<{
|
|
33
|
+
kind: "blob-storage-url";
|
|
34
|
+
url: string;
|
|
35
|
+
credentialMode?: "anonymous" | "signed" | "runtime-resolved";
|
|
36
|
+
mimeTypeHint?: string;
|
|
37
|
+
package?: ModelPackage;
|
|
38
|
+
provenance?: ModelProvenance;
|
|
39
|
+
}> | Readonly<{
|
|
40
|
+
kind: "blob";
|
|
41
|
+
blob: Blob;
|
|
42
|
+
fileNameHint?: string;
|
|
43
|
+
mimeTypeHint?: string;
|
|
44
|
+
package?: ModelPackage;
|
|
45
|
+
provenance?: ModelProvenance;
|
|
46
|
+
}> | Readonly<{
|
|
47
|
+
kind: "array-buffer";
|
|
48
|
+
bytes: ArrayBuffer;
|
|
49
|
+
fileNameHint?: string;
|
|
50
|
+
mimeTypeHint?: string;
|
|
51
|
+
package?: ModelPackage;
|
|
52
|
+
provenance?: ModelProvenance;
|
|
53
|
+
}> | Readonly<{
|
|
54
|
+
kind: "uint8-array";
|
|
55
|
+
bytes: Uint8Array;
|
|
56
|
+
fileNameHint?: string;
|
|
57
|
+
mimeTypeHint?: string;
|
|
58
|
+
package?: ModelPackage;
|
|
59
|
+
provenance?: ModelProvenance;
|
|
60
|
+
}> | Readonly<{
|
|
61
|
+
kind: "stream";
|
|
62
|
+
stream: ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>;
|
|
63
|
+
fileNameHint?: string;
|
|
64
|
+
mimeTypeHint?: string;
|
|
65
|
+
byteLengthHint?: number;
|
|
66
|
+
package?: ModelPackage;
|
|
67
|
+
provenance?: ModelProvenance;
|
|
68
|
+
}>;
|
|
69
|
+
type ResourceReference = Readonly<{
|
|
70
|
+
path: string;
|
|
71
|
+
contentType?: string;
|
|
72
|
+
integrity?: string;
|
|
73
|
+
}>;
|
|
74
|
+
type ResolvedResource = Readonly<{
|
|
75
|
+
path: string;
|
|
76
|
+
bytes: Uint8Array;
|
|
77
|
+
contentType?: string;
|
|
78
|
+
contentHash: string;
|
|
79
|
+
rangeSupported: boolean;
|
|
80
|
+
}>;
|
|
81
|
+
interface ResourceResolver {
|
|
82
|
+
resolve(reference: string | ResourceReference, options?: ResolveResourceOptions): Promise<ResolvedResource>;
|
|
83
|
+
}
|
|
84
|
+
type ResolveResourceOptions = Readonly<{
|
|
85
|
+
signal?: AbortSignal;
|
|
86
|
+
range?: Readonly<{
|
|
87
|
+
start: number;
|
|
88
|
+
end?: number;
|
|
89
|
+
}>;
|
|
90
|
+
}>;
|
|
91
|
+
type FetchPolicy = Readonly<{
|
|
92
|
+
maxAttempts?: number;
|
|
93
|
+
baseDelayMs?: number;
|
|
94
|
+
maxDelayMs?: number;
|
|
95
|
+
timeoutMs?: number;
|
|
96
|
+
}>;
|
|
97
|
+
type RuntimeFetch = (input: string | URL, init?: RequestInit) => Promise<Response>;
|
|
98
|
+
type ReadFile = (path: string, signal?: AbortSignal) => Promise<Uint8Array>;
|
|
99
|
+
type HashBytes = (bytes: Uint8Array) => Promise<string>;
|
|
100
|
+
type Sleep = (milliseconds: number, signal?: AbortSignal) => Promise<void>;
|
|
101
|
+
type BlobStorageUrlResolver = (baseUrl: string, reference: string) => string | Promise<string>;
|
|
102
|
+
type RuntimeDependencies = Readonly<{
|
|
103
|
+
fetch?: RuntimeFetch;
|
|
104
|
+
readFile?: ReadFile;
|
|
105
|
+
hashBytes?: HashBytes;
|
|
106
|
+
sleep?: Sleep;
|
|
107
|
+
blobStorageUrlResolver?: BlobStorageUrlResolver;
|
|
108
|
+
}>;
|
|
109
|
+
type ResolvedModelSource = Readonly<{
|
|
110
|
+
source: ModelSource;
|
|
111
|
+
bytes: Uint8Array;
|
|
112
|
+
contentType?: string;
|
|
113
|
+
fileName?: string;
|
|
114
|
+
contentHash: string;
|
|
115
|
+
rangeSupported: boolean;
|
|
116
|
+
resourceResolver: ResourceResolver;
|
|
117
|
+
}>;
|
|
118
|
+
type SniffInput = Readonly<{
|
|
119
|
+
bytes: Uint8Array;
|
|
120
|
+
contentType?: string;
|
|
121
|
+
fileName?: string;
|
|
122
|
+
sourceKind: ModelSourceKind;
|
|
123
|
+
}>;
|
|
124
|
+
type AdapterLoadContext = Readonly<{
|
|
125
|
+
signal: AbortSignal;
|
|
126
|
+
mode: "strict" | "tolerant" | "forensic";
|
|
127
|
+
execution: "main" | "worker";
|
|
128
|
+
adapterOptions: unknown;
|
|
129
|
+
}>;
|
|
130
|
+
type AdapterLoadResult<TCanonicalModel, TRendererReady = unknown> = Readonly<{
|
|
131
|
+
canonicalModel: TCanonicalModel;
|
|
132
|
+
rendererReady?: TRendererReady;
|
|
133
|
+
diagnostics?: readonly unknown[];
|
|
134
|
+
}>;
|
|
135
|
+
interface ModelAdapter<TCanonicalModel, TRendererReady = unknown> {
|
|
136
|
+
readonly formatId: string;
|
|
137
|
+
readonly supportsWorker?: boolean;
|
|
138
|
+
sniff(input: SniffInput): number | boolean;
|
|
139
|
+
load(input: ResolvedModelSource, context: AdapterLoadContext): Promise<AdapterLoadResult<TCanonicalModel, TRendererReady>>;
|
|
140
|
+
}
|
|
141
|
+
type AdapterModule<TCanonicalModel, TRendererReady = unknown> = ModelAdapter<TCanonicalModel, TRendererReady> | Readonly<{
|
|
142
|
+
default: ModelAdapter<TCanonicalModel, TRendererReady>;
|
|
143
|
+
}>;
|
|
144
|
+
type AdapterRegistration<TCanonicalModel = unknown, TRendererReady = unknown> = Readonly<{
|
|
145
|
+
formatId: string;
|
|
146
|
+
extensions?: readonly string[];
|
|
147
|
+
mimeTypes?: readonly string[];
|
|
148
|
+
sniff?: (input: SniffInput) => number | boolean;
|
|
149
|
+
load: () => Promise<AdapterModule<TCanonicalModel, TRendererReady>>;
|
|
150
|
+
}>;
|
|
151
|
+
type WorkerLoadRequest = Readonly<{
|
|
152
|
+
formatId: string;
|
|
153
|
+
input: ResolvedModelSource;
|
|
154
|
+
context: AdapterLoadContext;
|
|
155
|
+
}>;
|
|
156
|
+
interface WorkerDispatcher {
|
|
157
|
+
dispatch<TCanonicalModel, TRendererReady = unknown>(request: WorkerLoadRequest): Promise<AdapterLoadResult<TCanonicalModel, TRendererReady>>;
|
|
158
|
+
}
|
|
159
|
+
type ModelCache = Readonly<{
|
|
160
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
161
|
+
set<T>(key: string, value: T): Promise<void>;
|
|
162
|
+
delete(key: string): Promise<boolean>;
|
|
163
|
+
clear(): Promise<void>;
|
|
164
|
+
}>;
|
|
165
|
+
type LoadModelOptions = Readonly<{
|
|
166
|
+
signal?: AbortSignal;
|
|
167
|
+
mode?: "strict" | "tolerant" | "forensic";
|
|
168
|
+
adapterOptions?: unknown;
|
|
169
|
+
formatId?: string;
|
|
170
|
+
fetchPolicy?: FetchPolicy;
|
|
171
|
+
integrity?: string;
|
|
172
|
+
useCache?: boolean;
|
|
173
|
+
worker?: Readonly<{
|
|
174
|
+
mode?: "auto" | "never" | "always";
|
|
175
|
+
}>;
|
|
176
|
+
}>;
|
|
177
|
+
type ModelLoadResult<TCanonicalModel, TRendererReady = unknown> = Readonly<{
|
|
178
|
+
canonicalModel: TCanonicalModel;
|
|
179
|
+
rendererReady?: TRendererReady;
|
|
180
|
+
diagnostics?: readonly unknown[];
|
|
181
|
+
contentHash: string;
|
|
182
|
+
cacheKey: string;
|
|
183
|
+
fromCache: boolean;
|
|
184
|
+
contentType?: string;
|
|
185
|
+
sourceKind: ModelSourceKind;
|
|
186
|
+
}>;
|
|
187
|
+
|
|
188
|
+
declare class MemoryModelCache implements ModelCache {
|
|
189
|
+
private readonly entries;
|
|
190
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
191
|
+
set<T>(key: string, value: T): Promise<void>;
|
|
192
|
+
delete(key: string): Promise<boolean>;
|
|
193
|
+
clear(): Promise<void>;
|
|
194
|
+
}
|
|
195
|
+
declare function createModelCacheKey(contentHash: string, formatId: string, adapterOptions: unknown): string;
|
|
196
|
+
|
|
197
|
+
type FetchedResource = Readonly<{
|
|
198
|
+
bytes: Uint8Array;
|
|
199
|
+
contentType?: string;
|
|
200
|
+
rangeSupported: boolean;
|
|
201
|
+
}>;
|
|
202
|
+
declare function defaultSleep(milliseconds: number, signal?: AbortSignal): Promise<void>;
|
|
203
|
+
declare function sha256Hex(bytes: Uint8Array): Promise<string>;
|
|
204
|
+
declare function fetchResource(url: string, options: Readonly<{
|
|
205
|
+
fetch: RuntimeFetch;
|
|
206
|
+
hashBytes: HashBytes;
|
|
207
|
+
sleep: Sleep;
|
|
208
|
+
headers?: Readonly<Record<string, string>>;
|
|
209
|
+
integrity?: string;
|
|
210
|
+
policy?: FetchPolicy;
|
|
211
|
+
resolveOptions?: ResolveResourceOptions;
|
|
212
|
+
}>): Promise<FetchedResource>;
|
|
213
|
+
declare function verifyIntegrity(bytes: Uint8Array, integrity: string | undefined, hashBytes: HashBytes): Promise<void>;
|
|
214
|
+
|
|
215
|
+
declare class AdapterRegistry {
|
|
216
|
+
private readonly registrations;
|
|
217
|
+
register<TCanonicalModel, TRendererReady>(registration: AdapterRegistration<TCanonicalModel, TRendererReady>): this;
|
|
218
|
+
resolve<TCanonicalModel = unknown, TRendererReady = unknown>(input: SniffInput, formatId?: string): Promise<ModelAdapter<TCanonicalModel, TRendererReady>>;
|
|
219
|
+
}
|
|
220
|
+
declare class PackageResourceResolver implements ResourceResolver {
|
|
221
|
+
private readonly memoryResources;
|
|
222
|
+
private readonly baseUrl?;
|
|
223
|
+
private readonly sourceKind;
|
|
224
|
+
private readonly fetch;
|
|
225
|
+
private readonly hashBytes;
|
|
226
|
+
private readonly sleep;
|
|
227
|
+
private readonly fetchPolicy;
|
|
228
|
+
private readonly headers?;
|
|
229
|
+
private readonly blobStorageUrlResolver?;
|
|
230
|
+
constructor(options: Readonly<{
|
|
231
|
+
sourceKind: ModelSourceKind;
|
|
232
|
+
baseUrl?: string;
|
|
233
|
+
package?: ModelPackage;
|
|
234
|
+
fetch: RuntimeFetch;
|
|
235
|
+
hashBytes: HashBytes;
|
|
236
|
+
sleep: Sleep;
|
|
237
|
+
fetchPolicy?: LoadModelOptions["fetchPolicy"];
|
|
238
|
+
headers?: Readonly<Record<string, string>>;
|
|
239
|
+
blobStorageUrlResolver?: RuntimeDependencies["blobStorageUrlResolver"];
|
|
240
|
+
}>);
|
|
241
|
+
resolve(reference: string | ResourceReference, options?: ResolveResourceOptions): Promise<ResolvedResource>;
|
|
242
|
+
private resolveUrl;
|
|
243
|
+
}
|
|
244
|
+
declare class ModelRuntime {
|
|
245
|
+
private readonly registry;
|
|
246
|
+
private readonly cache;
|
|
247
|
+
private readonly fetch;
|
|
248
|
+
private readonly readFile?;
|
|
249
|
+
private readonly hashBytes;
|
|
250
|
+
private readonly sleep;
|
|
251
|
+
private readonly workerDispatcher?;
|
|
252
|
+
private readonly blobStorageUrlResolver?;
|
|
253
|
+
private readonly cacheKeys;
|
|
254
|
+
constructor(options?: Readonly<{
|
|
255
|
+
registry?: AdapterRegistry;
|
|
256
|
+
cache?: ModelCache;
|
|
257
|
+
dependencies?: RuntimeDependencies;
|
|
258
|
+
workerDispatcher?: WorkerDispatcher;
|
|
259
|
+
}>);
|
|
260
|
+
get adapters(): AdapterRegistry;
|
|
261
|
+
invalidate(contentHash?: string): Promise<void>;
|
|
262
|
+
loadModel<TCanonicalModel, TRendererReady = unknown>(source: ModelSource, options?: LoadModelOptions): Promise<ModelLoadResult<TCanonicalModel, TRendererReady>>;
|
|
263
|
+
private loadWithExecution;
|
|
264
|
+
private resolveSource;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** Package identity and rollout metadata for the runtime boundary. */
|
|
268
|
+
declare const packageName: "@plasius/gpu-model-runtime";
|
|
269
|
+
declare const packageBootstrap: Readonly<{
|
|
270
|
+
readonly packageName: "@plasius/gpu-model-runtime";
|
|
271
|
+
readonly featureFlag: "gpu.model.conversion.enabled";
|
|
272
|
+
readonly status: "runtime";
|
|
273
|
+
}>;
|
|
274
|
+
|
|
275
|
+
export { type AdapterLoadContext, type AdapterLoadResult, type AdapterModule, type AdapterRegistration, AdapterRegistry, type BlobStorageUrlResolver, type FetchPolicy, type FetchedResource, type HashBytes, type LoadModelOptions, MemoryModelCache, type ModelAdapter, type ModelCache, type ModelLoadResult, type ModelPackage, type ModelProvenance, type ModelResourceInput, ModelRuntime, type ModelSource, type ModelSourceKind, PackageResourceResolver, type ReadFile, type ResolveResourceOptions, type ResolvedModelSource, type ResolvedResource, type ResourceReference, type ResourceResolver, type RuntimeDependencies, type RuntimeFetch, type Sleep, type SniffInput, type WorkerDispatcher, type WorkerLoadRequest, createModelCacheKey, defaultSleep, fetchResource, packageBootstrap, packageName, sha256Hex, verifyIntegrity };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
type ModelSourceKind = "file-path" | "url" | "blob-storage-url" | "blob" | "array-buffer" | "uint8-array" | "stream";
|
|
2
|
+
type ModelProvenance = Readonly<{
|
|
3
|
+
sourceId?: string;
|
|
4
|
+
sourceSystem?: string;
|
|
5
|
+
acquiredAt?: string;
|
|
6
|
+
licenseHint?: string;
|
|
7
|
+
}>;
|
|
8
|
+
type ModelResourceInput = Readonly<{
|
|
9
|
+
bytes: ArrayBuffer | Blob | Uint8Array;
|
|
10
|
+
contentType?: string;
|
|
11
|
+
integrity?: string;
|
|
12
|
+
}>;
|
|
13
|
+
type ModelPackage = Readonly<{
|
|
14
|
+
entrypoint?: string;
|
|
15
|
+
baseUrl?: string;
|
|
16
|
+
resources?: Readonly<Record<string, ModelResourceInput>>;
|
|
17
|
+
}>;
|
|
18
|
+
type ModelSource = Readonly<{
|
|
19
|
+
kind: "file-path";
|
|
20
|
+
path: string;
|
|
21
|
+
mimeTypeHint?: string;
|
|
22
|
+
fileNameHint?: string;
|
|
23
|
+
package?: ModelPackage;
|
|
24
|
+
provenance?: ModelProvenance;
|
|
25
|
+
}> | Readonly<{
|
|
26
|
+
kind: "url";
|
|
27
|
+
url: string;
|
|
28
|
+
headers?: Readonly<Record<string, string>>;
|
|
29
|
+
mimeTypeHint?: string;
|
|
30
|
+
package?: ModelPackage;
|
|
31
|
+
provenance?: ModelProvenance;
|
|
32
|
+
}> | Readonly<{
|
|
33
|
+
kind: "blob-storage-url";
|
|
34
|
+
url: string;
|
|
35
|
+
credentialMode?: "anonymous" | "signed" | "runtime-resolved";
|
|
36
|
+
mimeTypeHint?: string;
|
|
37
|
+
package?: ModelPackage;
|
|
38
|
+
provenance?: ModelProvenance;
|
|
39
|
+
}> | Readonly<{
|
|
40
|
+
kind: "blob";
|
|
41
|
+
blob: Blob;
|
|
42
|
+
fileNameHint?: string;
|
|
43
|
+
mimeTypeHint?: string;
|
|
44
|
+
package?: ModelPackage;
|
|
45
|
+
provenance?: ModelProvenance;
|
|
46
|
+
}> | Readonly<{
|
|
47
|
+
kind: "array-buffer";
|
|
48
|
+
bytes: ArrayBuffer;
|
|
49
|
+
fileNameHint?: string;
|
|
50
|
+
mimeTypeHint?: string;
|
|
51
|
+
package?: ModelPackage;
|
|
52
|
+
provenance?: ModelProvenance;
|
|
53
|
+
}> | Readonly<{
|
|
54
|
+
kind: "uint8-array";
|
|
55
|
+
bytes: Uint8Array;
|
|
56
|
+
fileNameHint?: string;
|
|
57
|
+
mimeTypeHint?: string;
|
|
58
|
+
package?: ModelPackage;
|
|
59
|
+
provenance?: ModelProvenance;
|
|
60
|
+
}> | Readonly<{
|
|
61
|
+
kind: "stream";
|
|
62
|
+
stream: ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>;
|
|
63
|
+
fileNameHint?: string;
|
|
64
|
+
mimeTypeHint?: string;
|
|
65
|
+
byteLengthHint?: number;
|
|
66
|
+
package?: ModelPackage;
|
|
67
|
+
provenance?: ModelProvenance;
|
|
68
|
+
}>;
|
|
69
|
+
type ResourceReference = Readonly<{
|
|
70
|
+
path: string;
|
|
71
|
+
contentType?: string;
|
|
72
|
+
integrity?: string;
|
|
73
|
+
}>;
|
|
74
|
+
type ResolvedResource = Readonly<{
|
|
75
|
+
path: string;
|
|
76
|
+
bytes: Uint8Array;
|
|
77
|
+
contentType?: string;
|
|
78
|
+
contentHash: string;
|
|
79
|
+
rangeSupported: boolean;
|
|
80
|
+
}>;
|
|
81
|
+
interface ResourceResolver {
|
|
82
|
+
resolve(reference: string | ResourceReference, options?: ResolveResourceOptions): Promise<ResolvedResource>;
|
|
83
|
+
}
|
|
84
|
+
type ResolveResourceOptions = Readonly<{
|
|
85
|
+
signal?: AbortSignal;
|
|
86
|
+
range?: Readonly<{
|
|
87
|
+
start: number;
|
|
88
|
+
end?: number;
|
|
89
|
+
}>;
|
|
90
|
+
}>;
|
|
91
|
+
type FetchPolicy = Readonly<{
|
|
92
|
+
maxAttempts?: number;
|
|
93
|
+
baseDelayMs?: number;
|
|
94
|
+
maxDelayMs?: number;
|
|
95
|
+
timeoutMs?: number;
|
|
96
|
+
}>;
|
|
97
|
+
type RuntimeFetch = (input: string | URL, init?: RequestInit) => Promise<Response>;
|
|
98
|
+
type ReadFile = (path: string, signal?: AbortSignal) => Promise<Uint8Array>;
|
|
99
|
+
type HashBytes = (bytes: Uint8Array) => Promise<string>;
|
|
100
|
+
type Sleep = (milliseconds: number, signal?: AbortSignal) => Promise<void>;
|
|
101
|
+
type BlobStorageUrlResolver = (baseUrl: string, reference: string) => string | Promise<string>;
|
|
102
|
+
type RuntimeDependencies = Readonly<{
|
|
103
|
+
fetch?: RuntimeFetch;
|
|
104
|
+
readFile?: ReadFile;
|
|
105
|
+
hashBytes?: HashBytes;
|
|
106
|
+
sleep?: Sleep;
|
|
107
|
+
blobStorageUrlResolver?: BlobStorageUrlResolver;
|
|
108
|
+
}>;
|
|
109
|
+
type ResolvedModelSource = Readonly<{
|
|
110
|
+
source: ModelSource;
|
|
111
|
+
bytes: Uint8Array;
|
|
112
|
+
contentType?: string;
|
|
113
|
+
fileName?: string;
|
|
114
|
+
contentHash: string;
|
|
115
|
+
rangeSupported: boolean;
|
|
116
|
+
resourceResolver: ResourceResolver;
|
|
117
|
+
}>;
|
|
118
|
+
type SniffInput = Readonly<{
|
|
119
|
+
bytes: Uint8Array;
|
|
120
|
+
contentType?: string;
|
|
121
|
+
fileName?: string;
|
|
122
|
+
sourceKind: ModelSourceKind;
|
|
123
|
+
}>;
|
|
124
|
+
type AdapterLoadContext = Readonly<{
|
|
125
|
+
signal: AbortSignal;
|
|
126
|
+
mode: "strict" | "tolerant" | "forensic";
|
|
127
|
+
execution: "main" | "worker";
|
|
128
|
+
adapterOptions: unknown;
|
|
129
|
+
}>;
|
|
130
|
+
type AdapterLoadResult<TCanonicalModel, TRendererReady = unknown> = Readonly<{
|
|
131
|
+
canonicalModel: TCanonicalModel;
|
|
132
|
+
rendererReady?: TRendererReady;
|
|
133
|
+
diagnostics?: readonly unknown[];
|
|
134
|
+
}>;
|
|
135
|
+
interface ModelAdapter<TCanonicalModel, TRendererReady = unknown> {
|
|
136
|
+
readonly formatId: string;
|
|
137
|
+
readonly supportsWorker?: boolean;
|
|
138
|
+
sniff(input: SniffInput): number | boolean;
|
|
139
|
+
load(input: ResolvedModelSource, context: AdapterLoadContext): Promise<AdapterLoadResult<TCanonicalModel, TRendererReady>>;
|
|
140
|
+
}
|
|
141
|
+
type AdapterModule<TCanonicalModel, TRendererReady = unknown> = ModelAdapter<TCanonicalModel, TRendererReady> | Readonly<{
|
|
142
|
+
default: ModelAdapter<TCanonicalModel, TRendererReady>;
|
|
143
|
+
}>;
|
|
144
|
+
type AdapterRegistration<TCanonicalModel = unknown, TRendererReady = unknown> = Readonly<{
|
|
145
|
+
formatId: string;
|
|
146
|
+
extensions?: readonly string[];
|
|
147
|
+
mimeTypes?: readonly string[];
|
|
148
|
+
sniff?: (input: SniffInput) => number | boolean;
|
|
149
|
+
load: () => Promise<AdapterModule<TCanonicalModel, TRendererReady>>;
|
|
150
|
+
}>;
|
|
151
|
+
type WorkerLoadRequest = Readonly<{
|
|
152
|
+
formatId: string;
|
|
153
|
+
input: ResolvedModelSource;
|
|
154
|
+
context: AdapterLoadContext;
|
|
155
|
+
}>;
|
|
156
|
+
interface WorkerDispatcher {
|
|
157
|
+
dispatch<TCanonicalModel, TRendererReady = unknown>(request: WorkerLoadRequest): Promise<AdapterLoadResult<TCanonicalModel, TRendererReady>>;
|
|
158
|
+
}
|
|
159
|
+
type ModelCache = Readonly<{
|
|
160
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
161
|
+
set<T>(key: string, value: T): Promise<void>;
|
|
162
|
+
delete(key: string): Promise<boolean>;
|
|
163
|
+
clear(): Promise<void>;
|
|
164
|
+
}>;
|
|
165
|
+
type LoadModelOptions = Readonly<{
|
|
166
|
+
signal?: AbortSignal;
|
|
167
|
+
mode?: "strict" | "tolerant" | "forensic";
|
|
168
|
+
adapterOptions?: unknown;
|
|
169
|
+
formatId?: string;
|
|
170
|
+
fetchPolicy?: FetchPolicy;
|
|
171
|
+
integrity?: string;
|
|
172
|
+
useCache?: boolean;
|
|
173
|
+
worker?: Readonly<{
|
|
174
|
+
mode?: "auto" | "never" | "always";
|
|
175
|
+
}>;
|
|
176
|
+
}>;
|
|
177
|
+
type ModelLoadResult<TCanonicalModel, TRendererReady = unknown> = Readonly<{
|
|
178
|
+
canonicalModel: TCanonicalModel;
|
|
179
|
+
rendererReady?: TRendererReady;
|
|
180
|
+
diagnostics?: readonly unknown[];
|
|
181
|
+
contentHash: string;
|
|
182
|
+
cacheKey: string;
|
|
183
|
+
fromCache: boolean;
|
|
184
|
+
contentType?: string;
|
|
185
|
+
sourceKind: ModelSourceKind;
|
|
186
|
+
}>;
|
|
187
|
+
|
|
188
|
+
declare class MemoryModelCache implements ModelCache {
|
|
189
|
+
private readonly entries;
|
|
190
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
191
|
+
set<T>(key: string, value: T): Promise<void>;
|
|
192
|
+
delete(key: string): Promise<boolean>;
|
|
193
|
+
clear(): Promise<void>;
|
|
194
|
+
}
|
|
195
|
+
declare function createModelCacheKey(contentHash: string, formatId: string, adapterOptions: unknown): string;
|
|
196
|
+
|
|
197
|
+
type FetchedResource = Readonly<{
|
|
198
|
+
bytes: Uint8Array;
|
|
199
|
+
contentType?: string;
|
|
200
|
+
rangeSupported: boolean;
|
|
201
|
+
}>;
|
|
202
|
+
declare function defaultSleep(milliseconds: number, signal?: AbortSignal): Promise<void>;
|
|
203
|
+
declare function sha256Hex(bytes: Uint8Array): Promise<string>;
|
|
204
|
+
declare function fetchResource(url: string, options: Readonly<{
|
|
205
|
+
fetch: RuntimeFetch;
|
|
206
|
+
hashBytes: HashBytes;
|
|
207
|
+
sleep: Sleep;
|
|
208
|
+
headers?: Readonly<Record<string, string>>;
|
|
209
|
+
integrity?: string;
|
|
210
|
+
policy?: FetchPolicy;
|
|
211
|
+
resolveOptions?: ResolveResourceOptions;
|
|
212
|
+
}>): Promise<FetchedResource>;
|
|
213
|
+
declare function verifyIntegrity(bytes: Uint8Array, integrity: string | undefined, hashBytes: HashBytes): Promise<void>;
|
|
214
|
+
|
|
215
|
+
declare class AdapterRegistry {
|
|
216
|
+
private readonly registrations;
|
|
217
|
+
register<TCanonicalModel, TRendererReady>(registration: AdapterRegistration<TCanonicalModel, TRendererReady>): this;
|
|
218
|
+
resolve<TCanonicalModel = unknown, TRendererReady = unknown>(input: SniffInput, formatId?: string): Promise<ModelAdapter<TCanonicalModel, TRendererReady>>;
|
|
219
|
+
}
|
|
220
|
+
declare class PackageResourceResolver implements ResourceResolver {
|
|
221
|
+
private readonly memoryResources;
|
|
222
|
+
private readonly baseUrl?;
|
|
223
|
+
private readonly sourceKind;
|
|
224
|
+
private readonly fetch;
|
|
225
|
+
private readonly hashBytes;
|
|
226
|
+
private readonly sleep;
|
|
227
|
+
private readonly fetchPolicy;
|
|
228
|
+
private readonly headers?;
|
|
229
|
+
private readonly blobStorageUrlResolver?;
|
|
230
|
+
constructor(options: Readonly<{
|
|
231
|
+
sourceKind: ModelSourceKind;
|
|
232
|
+
baseUrl?: string;
|
|
233
|
+
package?: ModelPackage;
|
|
234
|
+
fetch: RuntimeFetch;
|
|
235
|
+
hashBytes: HashBytes;
|
|
236
|
+
sleep: Sleep;
|
|
237
|
+
fetchPolicy?: LoadModelOptions["fetchPolicy"];
|
|
238
|
+
headers?: Readonly<Record<string, string>>;
|
|
239
|
+
blobStorageUrlResolver?: RuntimeDependencies["blobStorageUrlResolver"];
|
|
240
|
+
}>);
|
|
241
|
+
resolve(reference: string | ResourceReference, options?: ResolveResourceOptions): Promise<ResolvedResource>;
|
|
242
|
+
private resolveUrl;
|
|
243
|
+
}
|
|
244
|
+
declare class ModelRuntime {
|
|
245
|
+
private readonly registry;
|
|
246
|
+
private readonly cache;
|
|
247
|
+
private readonly fetch;
|
|
248
|
+
private readonly readFile?;
|
|
249
|
+
private readonly hashBytes;
|
|
250
|
+
private readonly sleep;
|
|
251
|
+
private readonly workerDispatcher?;
|
|
252
|
+
private readonly blobStorageUrlResolver?;
|
|
253
|
+
private readonly cacheKeys;
|
|
254
|
+
constructor(options?: Readonly<{
|
|
255
|
+
registry?: AdapterRegistry;
|
|
256
|
+
cache?: ModelCache;
|
|
257
|
+
dependencies?: RuntimeDependencies;
|
|
258
|
+
workerDispatcher?: WorkerDispatcher;
|
|
259
|
+
}>);
|
|
260
|
+
get adapters(): AdapterRegistry;
|
|
261
|
+
invalidate(contentHash?: string): Promise<void>;
|
|
262
|
+
loadModel<TCanonicalModel, TRendererReady = unknown>(source: ModelSource, options?: LoadModelOptions): Promise<ModelLoadResult<TCanonicalModel, TRendererReady>>;
|
|
263
|
+
private loadWithExecution;
|
|
264
|
+
private resolveSource;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** Package identity and rollout metadata for the runtime boundary. */
|
|
268
|
+
declare const packageName: "@plasius/gpu-model-runtime";
|
|
269
|
+
declare const packageBootstrap: Readonly<{
|
|
270
|
+
readonly packageName: "@plasius/gpu-model-runtime";
|
|
271
|
+
readonly featureFlag: "gpu.model.conversion.enabled";
|
|
272
|
+
readonly status: "runtime";
|
|
273
|
+
}>;
|
|
274
|
+
|
|
275
|
+
export { type AdapterLoadContext, type AdapterLoadResult, type AdapterModule, type AdapterRegistration, AdapterRegistry, type BlobStorageUrlResolver, type FetchPolicy, type FetchedResource, type HashBytes, type LoadModelOptions, MemoryModelCache, type ModelAdapter, type ModelCache, type ModelLoadResult, type ModelPackage, type ModelProvenance, type ModelResourceInput, ModelRuntime, type ModelSource, type ModelSourceKind, PackageResourceResolver, type ReadFile, type ResolveResourceOptions, type ResolvedModelSource, type ResolvedResource, type ResourceReference, type ResourceResolver, type RuntimeDependencies, type RuntimeFetch, type Sleep, type SniffInput, type WorkerDispatcher, type WorkerLoadRequest, createModelCacheKey, defaultSleep, fetchResource, packageBootstrap, packageName, sha256Hex, verifyIntegrity };
|