@moss-dev/moss-wasm 0.16.0 → 0.17.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.
package/moss_wasm.d.ts CHANGED
@@ -1,18 +1,46 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
 
4
+ /** What Web Crypto needs to decrypt the payload of a sealed model. */
5
+ export interface SealedModelDecryptParams {
6
+ iv: Uint8Array;
7
+ tag: Uint8Array;
8
+ additionalData: Uint8Array;
9
+ payloadOffset: number;
10
+ payloadLength: number;
11
+ }
12
+
13
+ /** Where the tokenizer and graph lie in a decrypted sealed model payload. */
14
+ export interface SealedModelSections {
15
+ tokenizerOffset: number;
16
+ tokenizerLength: number;
17
+ graphOffset: number;
18
+ graphLength: number;
19
+ }
20
+
21
+
22
+
4
23
  export class IndexManager {
5
24
  free(): void;
6
25
  [Symbol.dispose](): void;
26
+ /**
27
+ * Sends the pending usage counts now.
28
+ * They also go out every 3 seconds, on `pagehide` and when the manager is freed.
29
+ */
30
+ flushUsageTelemetry(): Promise<any>;
7
31
  getIndexInfo(index_name: string): Promise<any>;
8
32
  hasIndex(index_name: string): Promise<any>;
9
33
  loadIndex(index_name: string): Promise<any>;
10
34
  constructor(project_id: string, project_key: string);
11
- query(index_name: string, query_text: string, query_embedding: Float32Array, top_k: number | null | undefined, alpha: number | null | undefined, filter: any, tuning: any): Promise<any>;
12
- queryMultiIndex(index_names: string[], query_text: string, query_embedding: Float32Array, top_k: number | null | undefined, alpha: number | null | undefined, filter: any, tuning: any): Promise<any>;
13
- queryMultiIndexWithModelIdentity(index_names: string[], query_text: string, query_embedding: Float32Array, model_id: string, model_artifact_version: string, manifest_sha256: string, top_k: number | null | undefined, alpha: number | null | undefined, filter: any, tuning: any): Promise<any>;
14
- queryWithModelIdentity(index_name: string, query_text: string, query_embedding: Float32Array, model_id: string, model_artifact_version: string, manifest_sha256: string, top_k: number | null | undefined, alpha: number | null | undefined, filter: any, tuning: any): Promise<any>;
35
+ query(index_name: string, query_text: string, query_embedding: Float32Array | null | undefined, top_k: number | null | undefined, alpha: number | null | undefined, filter: any, tuning: any): Promise<any>;
36
+ queryMultiIndex(index_names: string[], query_text: string, query_embedding: Float32Array | null | undefined, top_k: number | null | undefined, alpha: number | null | undefined, filter: any, tuning: any): Promise<any>;
37
+ queryMultiIndexWithModelIdentity(index_names: string[], query_text: string, query_embedding: Float32Array | null | undefined, model_id: string, model_artifact_version: string, manifest_sha256: string, top_k: number | null | undefined, alpha: number | null | undefined, filter: any, tuning: any): Promise<any>;
38
+ queryWithModelIdentity(index_name: string, query_text: string, query_embedding: Float32Array | null | undefined, model_id: string, model_artifact_version: string, manifest_sha256: string, top_k: number | null | undefined, alpha: number | null | undefined, filter: any, tuning: any): Promise<any>;
15
39
  refreshIndex(index_name: string): Promise<any>;
40
+ /**
41
+ * Always true. Its presence tells the browser SDK that `refreshIndex` skips an unchanged snapshot.
42
+ */
43
+ refreshSkipsUnchanged(): boolean;
16
44
  unloadIndex(index_name: string): Promise<any>;
17
45
  unloadIndexes(index_names: string[]): Promise<any>;
18
46
  static withAuthenticator(project_id: string, get_auth_header: Function, invalidate_cache?: Function | null, base_url?: string | null): IndexManager;
@@ -23,10 +51,10 @@ export class IndexManager {
23
51
  export class ManageClient {
24
52
  free(): void;
25
53
  [Symbol.dispose](): void;
26
- addDocs(name: string, docs: any, upsert?: boolean | null): Promise<any>;
27
- createIndex(name: string, docs: any, model_id: string): Promise<any>;
28
- createIndexFromFiles(name: string, files: any, model_id: string): Promise<any>;
29
- deleteDocs(name: string, doc_ids: string[]): Promise<any>;
54
+ addDocs(name: string, docs: any, upsert?: boolean | null, on_progress?: Function | null): Promise<any>;
55
+ createIndex(name: string, docs: any, model_id: string, on_progress?: Function | null): Promise<any>;
56
+ createIndexFromFiles(name: string, files: any, model_id: string, on_progress?: Function | null): Promise<any>;
57
+ deleteDocs(name: string, doc_ids: string[], on_progress?: Function | null): Promise<any>;
30
58
  deleteIndex(name: string): Promise<any>;
31
59
  getDocs(name: string, doc_ids?: string[] | null): Promise<any>;
32
60
  getIndex(name: string): Promise<any>;
@@ -41,6 +69,12 @@ export class ModelContentKeys {
41
69
  private constructor();
42
70
  free(): void;
43
71
  [Symbol.dispose](): void;
72
+ /**
73
+ * Imports the content key into Web Crypto as an AES-GCM key that only decrypts.
74
+ * It cannot be exported, and the buffer `importKey` copies it from is then zeroed.
75
+ * The promise rejects when the global `crypto.subtle` is missing, as in an insecure context.
76
+ */
77
+ importWebCryptoKey(): Promise<CryptoKey>;
44
78
  readonly keyId: number;
45
79
  }
46
80
 
@@ -75,12 +109,41 @@ export class Tokenizer {
75
109
  tokenize(text: string): any;
76
110
  }
77
111
 
112
+ /**
113
+ * Opens a sealed model whose raw SHA-256 already matched the release entry.
114
+ *
115
+ * The envelope digest is read from the header instead of recomputed. The
116
+ * match pins every byte, and GCM still authenticates the digest through the
117
+ * AAD, so bytes that were never matched still fail closed, only later.
118
+ */
119
+ export function openMatchedSealedModel(bytes: Uint8Array, keys: ModelContentKeys, sku: string): SealedModel;
120
+
78
121
  export function openSealedModel(bytes: Uint8Array, keys: ModelContentKeys, sku: string): SealedModel;
79
122
 
80
123
  export function poolAndNormalize(token_embeddings: Float32Array, attention_mask: Int32Array, hidden_dim: number): Float32Array;
81
124
 
82
125
  export function sdk_version(): string;
83
126
 
127
+ /**
128
+ * Returns the nonce, tag, AAD and payload range Web Crypto needs to open a sealed model.
129
+ * Only its header is copied out of `bytes`, whose raw SHA-256 already matched the release entry.
130
+ * The header gets the checks of `openMatchedSealedModel`, and its key id must be the granted one.
131
+ */
132
+ export function sealedModelDecryptParams(bytes: Uint8Array, keys: ModelContentKeys, sku: string): SealedModelDecryptParams;
133
+
134
+ /**
135
+ * Returns where the tokenizer and graph lie in a sealed model payload Web Crypto decrypted.
136
+ * Only the inner header, the sku and the first bytes of the graph are copied out of `plaintext`.
137
+ * They get the checks `openSealedModel` runs after decrypting: the sku, an ORT graph, no gate op.
138
+ */
139
+ export function sealedModelSections(plaintext: Uint8Array, sku: string): SealedModelSections;
140
+
141
+ /**
142
+ * Builds a tokenizer from the tokenizer section of a payload that Web Crypto decrypted,
143
+ * as `takeTokenizer` does, and wipes the copy of the bytes it parsed once the tokenizer is built.
144
+ */
145
+ export function sealedModelTokenizer(tokenizer_json: Uint8Array): Tokenizer;
146
+
84
147
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
85
148
 
86
149
  export interface InitOutput {
@@ -92,6 +155,7 @@ export interface InitOutput {
92
155
  readonly __wbg_projectkeyauthenticator_free: (a: number, b: number) => void;
93
156
  readonly __wbg_sealedmodel_free: (a: number, b: number) => void;
94
157
  readonly __wbg_tokenizer_free: (a: number, b: number) => void;
158
+ readonly indexmanager_flushUsageTelemetry: (a: number) => any;
95
159
  readonly indexmanager_getIndexInfo: (a: number, b: number, c: number) => any;
96
160
  readonly indexmanager_hasIndex: (a: number, b: number, c: number) => any;
97
161
  readonly indexmanager_loadIndex: (a: number, b: number, c: number) => any;
@@ -101,15 +165,16 @@ export interface InitOutput {
101
165
  readonly indexmanager_queryMultiIndexWithModelIdentity: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: any, q: any) => any;
102
166
  readonly indexmanager_queryWithModelIdentity: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: any, q: any) => any;
103
167
  readonly indexmanager_refreshIndex: (a: number, b: number, c: number) => any;
168
+ readonly indexmanager_refreshSkipsUnchanged: (a: number) => number;
104
169
  readonly indexmanager_unloadIndex: (a: number, b: number, c: number) => any;
105
170
  readonly indexmanager_unloadIndexes: (a: number, b: number, c: number) => any;
106
171
  readonly indexmanager_withAuthenticator: (a: number, b: number, c: any, d: number, e: number, f: number) => number;
107
172
  readonly indexmanager_withBaseUrl: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
108
173
  readonly indexmanager_withBaseUrls: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => number;
109
- readonly manageclient_addDocs: (a: number, b: number, c: number, d: any, e: number) => any;
110
- readonly manageclient_createIndex: (a: number, b: number, c: number, d: any, e: number, f: number) => any;
111
- readonly manageclient_createIndexFromFiles: (a: number, b: number, c: number, d: any, e: number, f: number) => any;
112
- readonly manageclient_deleteDocs: (a: number, b: number, c: number, d: number, e: number) => any;
174
+ readonly manageclient_addDocs: (a: number, b: number, c: number, d: any, e: number, f: number) => any;
175
+ readonly manageclient_createIndex: (a: number, b: number, c: number, d: any, e: number, f: number, g: number) => any;
176
+ readonly manageclient_createIndexFromFiles: (a: number, b: number, c: number, d: any, e: number, f: number, g: number) => any;
177
+ readonly manageclient_deleteDocs: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
113
178
  readonly manageclient_deleteIndex: (a: number, b: number, c: number) => any;
114
179
  readonly manageclient_getDocs: (a: number, b: number, c: number, d: number, e: number) => any;
115
180
  readonly manageclient_getIndex: (a: number, b: number, c: number) => any;
@@ -118,23 +183,28 @@ export interface InitOutput {
118
183
  readonly manageclient_new: (a: number, b: number, c: number, d: number) => number;
119
184
  readonly manageclient_withAuthenticator: (a: number, b: number, c: any, d: number, e: number, f: number) => number;
120
185
  readonly manageclient_withBaseUrl: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
186
+ readonly modelcontentkeys_importWebCryptoKey: (a: number) => any;
121
187
  readonly modelcontentkeys_keyId: (a: number) => number;
122
188
  readonly modelkeyexchange_capabilityQuery: (a: number, b: number, c: number) => [number, number];
123
189
  readonly modelkeyexchange_new: () => [number, number, number];
124
190
  readonly modelkeyexchange_unwrap: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
191
+ readonly openMatchedSealedModel: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
125
192
  readonly openSealedModel: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
126
193
  readonly poolAndNormalize: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
127
194
  readonly projectkeyauthenticator_getAuthHeader: (a: number) => any;
128
195
  readonly projectkeyauthenticator_invalidate: (a: number) => any;
129
196
  readonly projectkeyauthenticator_new: (a: number, b: number, c: number, d: number) => number;
130
197
  readonly sdk_version: () => [number, number];
198
+ readonly sealedModelDecryptParams: (a: any, b: number, c: number, d: number) => [number, number, number];
199
+ readonly sealedModelSections: (a: any, b: number, c: number) => [number, number, number];
200
+ readonly sealedModelTokenizer: (a: any) => [number, number, number];
131
201
  readonly sealedmodel_takeGraph: (a: number) => [number, number, number];
132
202
  readonly sealedmodel_takeTokenizer: (a: number) => [number, number, number];
133
203
  readonly tokenizer_new: (a: number, b: number) => [number, number, number];
134
204
  readonly tokenizer_tokenize: (a: number, b: number, c: number) => [number, number, number];
135
- readonly wasm_bindgen_9e362b674ca4cea___convert__closures_____invoke___wasm_bindgen_9e362b674ca4cea___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_9e362b674ca4cea___JsError___true_: (a: number, b: number, c: any) => [number, number];
136
- readonly wasm_bindgen_9e362b674ca4cea___convert__closures_____invoke___js_sys_77b4e3062c519671___Function_fn_wasm_bindgen_9e362b674ca4cea___JsValue_____wasm_bindgen_9e362b674ca4cea___sys__Undefined___js_sys_77b4e3062c519671___Function_fn_wasm_bindgen_9e362b674ca4cea___JsValue_____wasm_bindgen_9e362b674ca4cea___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
137
- readonly wasm_bindgen_9e362b674ca4cea___convert__closures_____invoke_______true_: (a: number, b: number) => void;
205
+ readonly wasm_bindgen_79e945b5d148b8ef___convert__closures_____invoke___wasm_bindgen_79e945b5d148b8ef___JsValue__core_608f92abc48d28da___result__Result_____wasm_bindgen_79e945b5d148b8ef___JsError___true_: (a: number, b: number, c: any) => [number, number];
206
+ readonly wasm_bindgen_79e945b5d148b8ef___convert__closures_____invoke___js_sys_47ef7e31b3f1968c___Function_fn_wasm_bindgen_79e945b5d148b8ef___JsValue_____wasm_bindgen_79e945b5d148b8ef___sys__Undefined___js_sys_47ef7e31b3f1968c___Function_fn_wasm_bindgen_79e945b5d148b8ef___JsValue_____wasm_bindgen_79e945b5d148b8ef___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
207
+ readonly wasm_bindgen_79e945b5d148b8ef___convert__closures_____invoke_______true_: (a: number, b: number) => void;
138
208
  readonly __wbindgen_malloc: (a: number, b: number) => number;
139
209
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
140
210
  readonly __wbindgen_exn_store: (a: number) => void;
package/moss_wasm.js CHANGED
@@ -17,6 +17,15 @@ export class IndexManager {
17
17
  const ptr = this.__destroy_into_raw();
18
18
  wasm.__wbg_indexmanager_free(ptr, 0);
19
19
  }
20
+ /**
21
+ * Sends the pending usage counts now.
22
+ * They also go out every 3 seconds, on `pagehide` and when the manager is freed.
23
+ * @returns {Promise<any>}
24
+ */
25
+ flushUsageTelemetry() {
26
+ const ret = wasm.indexmanager_flushUsageTelemetry(this.__wbg_ptr);
27
+ return ret;
28
+ }
20
29
  /**
21
30
  * @param {string} index_name
22
31
  * @returns {Promise<any>}
@@ -64,7 +73,7 @@ export class IndexManager {
64
73
  /**
65
74
  * @param {string} index_name
66
75
  * @param {string} query_text
67
- * @param {Float32Array} query_embedding
76
+ * @param {Float32Array | null | undefined} query_embedding
68
77
  * @param {number | null | undefined} top_k
69
78
  * @param {number | null | undefined} alpha
70
79
  * @param {any} filter
@@ -76,15 +85,15 @@ export class IndexManager {
76
85
  const len0 = WASM_VECTOR_LEN;
77
86
  const ptr1 = passStringToWasm0(query_text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
78
87
  const len1 = WASM_VECTOR_LEN;
79
- const ptr2 = passArrayF32ToWasm0(query_embedding, wasm.__wbindgen_malloc);
80
- const len2 = WASM_VECTOR_LEN;
88
+ var ptr2 = isLikeNone(query_embedding) ? 0 : passArrayF32ToWasm0(query_embedding, wasm.__wbindgen_malloc);
89
+ var len2 = WASM_VECTOR_LEN;
81
90
  const ret = wasm.indexmanager_query(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, isLikeNone(top_k) ? Number.MAX_SAFE_INTEGER : (top_k) >>> 0, isLikeNone(alpha) ? Number.MAX_SAFE_INTEGER : Math.fround(alpha), filter, tuning);
82
91
  return ret;
83
92
  }
84
93
  /**
85
94
  * @param {string[]} index_names
86
95
  * @param {string} query_text
87
- * @param {Float32Array} query_embedding
96
+ * @param {Float32Array | null | undefined} query_embedding
88
97
  * @param {number | null | undefined} top_k
89
98
  * @param {number | null | undefined} alpha
90
99
  * @param {any} filter
@@ -96,15 +105,15 @@ export class IndexManager {
96
105
  const len0 = WASM_VECTOR_LEN;
97
106
  const ptr1 = passStringToWasm0(query_text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
98
107
  const len1 = WASM_VECTOR_LEN;
99
- const ptr2 = passArrayF32ToWasm0(query_embedding, wasm.__wbindgen_malloc);
100
- const len2 = WASM_VECTOR_LEN;
108
+ var ptr2 = isLikeNone(query_embedding) ? 0 : passArrayF32ToWasm0(query_embedding, wasm.__wbindgen_malloc);
109
+ var len2 = WASM_VECTOR_LEN;
101
110
  const ret = wasm.indexmanager_queryMultiIndex(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, isLikeNone(top_k) ? Number.MAX_SAFE_INTEGER : (top_k) >>> 0, isLikeNone(alpha) ? Number.MAX_SAFE_INTEGER : Math.fround(alpha), filter, tuning);
102
111
  return ret;
103
112
  }
104
113
  /**
105
114
  * @param {string[]} index_names
106
115
  * @param {string} query_text
107
- * @param {Float32Array} query_embedding
116
+ * @param {Float32Array | null | undefined} query_embedding
108
117
  * @param {string} model_id
109
118
  * @param {string} model_artifact_version
110
119
  * @param {string} manifest_sha256
@@ -119,8 +128,8 @@ export class IndexManager {
119
128
  const len0 = WASM_VECTOR_LEN;
120
129
  const ptr1 = passStringToWasm0(query_text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
121
130
  const len1 = WASM_VECTOR_LEN;
122
- const ptr2 = passArrayF32ToWasm0(query_embedding, wasm.__wbindgen_malloc);
123
- const len2 = WASM_VECTOR_LEN;
131
+ var ptr2 = isLikeNone(query_embedding) ? 0 : passArrayF32ToWasm0(query_embedding, wasm.__wbindgen_malloc);
132
+ var len2 = WASM_VECTOR_LEN;
124
133
  const ptr3 = passStringToWasm0(model_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
125
134
  const len3 = WASM_VECTOR_LEN;
126
135
  const ptr4 = passStringToWasm0(model_artifact_version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
@@ -133,7 +142,7 @@ export class IndexManager {
133
142
  /**
134
143
  * @param {string} index_name
135
144
  * @param {string} query_text
136
- * @param {Float32Array} query_embedding
145
+ * @param {Float32Array | null | undefined} query_embedding
137
146
  * @param {string} model_id
138
147
  * @param {string} model_artifact_version
139
148
  * @param {string} manifest_sha256
@@ -148,8 +157,8 @@ export class IndexManager {
148
157
  const len0 = WASM_VECTOR_LEN;
149
158
  const ptr1 = passStringToWasm0(query_text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
150
159
  const len1 = WASM_VECTOR_LEN;
151
- const ptr2 = passArrayF32ToWasm0(query_embedding, wasm.__wbindgen_malloc);
152
- const len2 = WASM_VECTOR_LEN;
160
+ var ptr2 = isLikeNone(query_embedding) ? 0 : passArrayF32ToWasm0(query_embedding, wasm.__wbindgen_malloc);
161
+ var len2 = WASM_VECTOR_LEN;
153
162
  const ptr3 = passStringToWasm0(model_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
154
163
  const len3 = WASM_VECTOR_LEN;
155
164
  const ptr4 = passStringToWasm0(model_artifact_version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
@@ -169,6 +178,14 @@ export class IndexManager {
169
178
  const ret = wasm.indexmanager_refreshIndex(this.__wbg_ptr, ptr0, len0);
170
179
  return ret;
171
180
  }
181
+ /**
182
+ * Always true. Its presence tells the browser SDK that `refreshIndex` skips an unchanged snapshot.
183
+ * @returns {boolean}
184
+ */
185
+ refreshSkipsUnchanged() {
186
+ const ret = wasm.indexmanager_refreshSkipsUnchanged(this.__wbg_ptr);
187
+ return ret !== 0;
188
+ }
172
189
  /**
173
190
  * @param {string} index_name
174
191
  * @returns {Promise<any>}
@@ -263,53 +280,57 @@ export class ManageClient {
263
280
  * @param {string} name
264
281
  * @param {any} docs
265
282
  * @param {boolean | null} [upsert]
283
+ * @param {Function | null} [on_progress]
266
284
  * @returns {Promise<any>}
267
285
  */
268
- addDocs(name, docs, upsert) {
286
+ addDocs(name, docs, upsert, on_progress) {
269
287
  const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
270
288
  const len0 = WASM_VECTOR_LEN;
271
- const ret = wasm.manageclient_addDocs(this.__wbg_ptr, ptr0, len0, docs, isLikeNone(upsert) ? 0xFFFFFF : upsert ? 1 : 0);
289
+ const ret = wasm.manageclient_addDocs(this.__wbg_ptr, ptr0, len0, docs, isLikeNone(upsert) ? 0xFFFFFF : upsert ? 1 : 0, isLikeNone(on_progress) ? 0 : addToExternrefTable0(on_progress));
272
290
  return ret;
273
291
  }
274
292
  /**
275
293
  * @param {string} name
276
294
  * @param {any} docs
277
295
  * @param {string} model_id
296
+ * @param {Function | null} [on_progress]
278
297
  * @returns {Promise<any>}
279
298
  */
280
- createIndex(name, docs, model_id) {
299
+ createIndex(name, docs, model_id, on_progress) {
281
300
  const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
282
301
  const len0 = WASM_VECTOR_LEN;
283
302
  const ptr1 = passStringToWasm0(model_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
284
303
  const len1 = WASM_VECTOR_LEN;
285
- const ret = wasm.manageclient_createIndex(this.__wbg_ptr, ptr0, len0, docs, ptr1, len1);
304
+ const ret = wasm.manageclient_createIndex(this.__wbg_ptr, ptr0, len0, docs, ptr1, len1, isLikeNone(on_progress) ? 0 : addToExternrefTable0(on_progress));
286
305
  return ret;
287
306
  }
288
307
  /**
289
308
  * @param {string} name
290
309
  * @param {any} files
291
310
  * @param {string} model_id
311
+ * @param {Function | null} [on_progress]
292
312
  * @returns {Promise<any>}
293
313
  */
294
- createIndexFromFiles(name, files, model_id) {
314
+ createIndexFromFiles(name, files, model_id, on_progress) {
295
315
  const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
296
316
  const len0 = WASM_VECTOR_LEN;
297
317
  const ptr1 = passStringToWasm0(model_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
298
318
  const len1 = WASM_VECTOR_LEN;
299
- const ret = wasm.manageclient_createIndexFromFiles(this.__wbg_ptr, ptr0, len0, files, ptr1, len1);
319
+ const ret = wasm.manageclient_createIndexFromFiles(this.__wbg_ptr, ptr0, len0, files, ptr1, len1, isLikeNone(on_progress) ? 0 : addToExternrefTable0(on_progress));
300
320
  return ret;
301
321
  }
302
322
  /**
303
323
  * @param {string} name
304
324
  * @param {string[]} doc_ids
325
+ * @param {Function | null} [on_progress]
305
326
  * @returns {Promise<any>}
306
327
  */
307
- deleteDocs(name, doc_ids) {
328
+ deleteDocs(name, doc_ids, on_progress) {
308
329
  const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
309
330
  const len0 = WASM_VECTOR_LEN;
310
331
  const ptr1 = passArrayJsValueToWasm0(doc_ids, wasm.__wbindgen_malloc);
311
332
  const len1 = WASM_VECTOR_LEN;
312
- const ret = wasm.manageclient_deleteDocs(this.__wbg_ptr, ptr0, len0, ptr1, len1);
333
+ const ret = wasm.manageclient_deleteDocs(this.__wbg_ptr, ptr0, len0, ptr1, len1, isLikeNone(on_progress) ? 0 : addToExternrefTable0(on_progress));
313
334
  return ret;
314
335
  }
315
336
  /**
@@ -427,6 +448,16 @@ export class ModelContentKeys {
427
448
  const ptr = this.__destroy_into_raw();
428
449
  wasm.__wbg_modelcontentkeys_free(ptr, 0);
429
450
  }
451
+ /**
452
+ * Imports the content key into Web Crypto as an AES-GCM key that only decrypts.
453
+ * It cannot be exported, and the buffer `importKey` copies it from is then zeroed.
454
+ * The promise rejects when the global `crypto.subtle` is missing, as in an insecure context.
455
+ * @returns {Promise<CryptoKey>}
456
+ */
457
+ importWebCryptoKey() {
458
+ const ret = wasm.modelcontentkeys_importWebCryptoKey(this.__wbg_ptr);
459
+ return ret;
460
+ }
430
461
  /**
431
462
  * @returns {number}
432
463
  */
@@ -627,6 +658,30 @@ export class Tokenizer {
627
658
  }
628
659
  if (Symbol.dispose) Tokenizer.prototype[Symbol.dispose] = Tokenizer.prototype.free;
629
660
 
661
+ /**
662
+ * Opens a sealed model whose raw SHA-256 already matched the release entry.
663
+ *
664
+ * The envelope digest is read from the header instead of recomputed. The
665
+ * match pins every byte, and GCM still authenticates the digest through the
666
+ * AAD, so bytes that were never matched still fail closed, only later.
667
+ * @param {Uint8Array} bytes
668
+ * @param {ModelContentKeys} keys
669
+ * @param {string} sku
670
+ * @returns {SealedModel}
671
+ */
672
+ export function openMatchedSealedModel(bytes, keys, sku) {
673
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
674
+ const len0 = WASM_VECTOR_LEN;
675
+ _assertClass(keys, ModelContentKeys);
676
+ const ptr1 = passStringToWasm0(sku, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
677
+ const len1 = WASM_VECTOR_LEN;
678
+ const ret = wasm.openMatchedSealedModel(ptr0, len0, keys.__wbg_ptr, ptr1, len1);
679
+ if (ret[2]) {
680
+ throw takeFromExternrefTable0(ret[1]);
681
+ }
682
+ return SealedModel.__wrap(ret[0]);
683
+ }
684
+
630
685
  /**
631
686
  * @param {Uint8Array} bytes
632
687
  * @param {ModelContentKeys} keys
@@ -681,6 +736,58 @@ export function sdk_version() {
681
736
  wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
682
737
  }
683
738
  }
739
+
740
+ /**
741
+ * Returns the nonce, tag, AAD and payload range Web Crypto needs to open a sealed model.
742
+ * Only its header is copied out of `bytes`, whose raw SHA-256 already matched the release entry.
743
+ * The header gets the checks of `openMatchedSealedModel`, and its key id must be the granted one.
744
+ * @param {Uint8Array} bytes
745
+ * @param {ModelContentKeys} keys
746
+ * @param {string} sku
747
+ * @returns {SealedModelDecryptParams}
748
+ */
749
+ export function sealedModelDecryptParams(bytes, keys, sku) {
750
+ _assertClass(keys, ModelContentKeys);
751
+ const ptr0 = passStringToWasm0(sku, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
752
+ const len0 = WASM_VECTOR_LEN;
753
+ const ret = wasm.sealedModelDecryptParams(bytes, keys.__wbg_ptr, ptr0, len0);
754
+ if (ret[2]) {
755
+ throw takeFromExternrefTable0(ret[1]);
756
+ }
757
+ return takeFromExternrefTable0(ret[0]);
758
+ }
759
+
760
+ /**
761
+ * Returns where the tokenizer and graph lie in a sealed model payload Web Crypto decrypted.
762
+ * Only the inner header, the sku and the first bytes of the graph are copied out of `plaintext`.
763
+ * They get the checks `openSealedModel` runs after decrypting: the sku, an ORT graph, no gate op.
764
+ * @param {Uint8Array} plaintext
765
+ * @param {string} sku
766
+ * @returns {SealedModelSections}
767
+ */
768
+ export function sealedModelSections(plaintext, sku) {
769
+ const ptr0 = passStringToWasm0(sku, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
770
+ const len0 = WASM_VECTOR_LEN;
771
+ const ret = wasm.sealedModelSections(plaintext, ptr0, len0);
772
+ if (ret[2]) {
773
+ throw takeFromExternrefTable0(ret[1]);
774
+ }
775
+ return takeFromExternrefTable0(ret[0]);
776
+ }
777
+
778
+ /**
779
+ * Builds a tokenizer from the tokenizer section of a payload that Web Crypto decrypted,
780
+ * as `takeTokenizer` does, and wipes the copy of the bytes it parsed once the tokenizer is built.
781
+ * @param {Uint8Array} tokenizer_json
782
+ * @returns {Tokenizer}
783
+ */
784
+ export function sealedModelTokenizer(tokenizer_json) {
785
+ const ret = wasm.sealedModelTokenizer(tokenizer_json);
786
+ if (ret[2]) {
787
+ throw takeFromExternrefTable0(ret[1]);
788
+ }
789
+ return Tokenizer.__wrap(ret[0]);
790
+ }
684
791
  function __wbg_get_imports() {
685
792
  const import0 = {
686
793
  __proto__: null,
@@ -780,6 +887,9 @@ function __wbg_get_imports() {
780
887
  __wbg_abort_eee9248a6d680839: function(arg0, arg1) {
781
888
  arg0.abort(arg1);
782
889
  },
890
+ __wbg_addEventListener_d85450ee1320c989: function() { return handleError(function (arg0, arg1, arg2, arg3) {
891
+ arg0.addEventListener(getStringFromWasm0(arg1, arg2), arg3);
892
+ }, arguments); },
783
893
  __wbg_append_01c74e5c6b58aa64: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
784
894
  arg0.append(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
785
895
  }, arguments); },
@@ -819,6 +929,21 @@ function __wbg_get_imports() {
819
929
  const ret = arg0.fetch(arg1);
820
930
  return ret;
821
931
  },
932
+ __wbg_fetch_e166fd0eb785670a: function() { return handleError(function (arg0, arg1, arg2) {
933
+ const ret = fetch(getStringFromWasm0(arg0, arg1), arg2);
934
+ return ret;
935
+ }, arguments); },
936
+ __wbg_fill_5663f5c647107cce: function(arg0, arg1, arg2, arg3) {
937
+ const ret = arg0.fill(arg1, arg2 >>> 0, arg3 >>> 0);
938
+ return ret;
939
+ },
940
+ __wbg_getItem_b96269ddc16cf24a: function() { return handleError(function (arg0, arg1, arg2, arg3) {
941
+ const ret = arg1.getItem(getStringFromWasm0(arg2, arg3));
942
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
943
+ var len1 = WASM_VECTOR_LEN;
944
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
945
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
946
+ }, arguments); },
822
947
  __wbg_getRandomValues_3f44b700395062e5: function() { return handleError(function (arg0, arg1) {
823
948
  globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
824
949
  }, arguments); },
@@ -857,6 +982,10 @@ function __wbg_get_imports() {
857
982
  const ret = arg0.headers;
858
983
  return ret;
859
984
  },
985
+ __wbg_importKey_10a137b5a53c66ba: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) {
986
+ const ret = arg0.importKey(getStringFromWasm0(arg1, arg2), arg3, getStringFromWasm0(arg4, arg5), arg6 !== 0, arg7);
987
+ return ret;
988
+ }, arguments); },
860
989
  __wbg_instanceof_ArrayBuffer_4480b9e0068a8adb: function(arg0) {
861
990
  let result;
862
991
  try {
@@ -968,7 +1097,7 @@ function __wbg_get_imports() {
968
1097
  const a = state0.a;
969
1098
  state0.a = 0;
970
1099
  try {
971
- return wasm_bindgen_9e362b674ca4cea___convert__closures_____invoke___js_sys_77b4e3062c519671___Function_fn_wasm_bindgen_9e362b674ca4cea___JsValue_____wasm_bindgen_9e362b674ca4cea___sys__Undefined___js_sys_77b4e3062c519671___Function_fn_wasm_bindgen_9e362b674ca4cea___JsValue_____wasm_bindgen_9e362b674ca4cea___sys__Undefined_______true_(a, state0.b, arg0, arg1);
1100
+ return wasm_bindgen_79e945b5d148b8ef___convert__closures_____invoke___js_sys_47ef7e31b3f1968c___Function_fn_wasm_bindgen_79e945b5d148b8ef___JsValue_____wasm_bindgen_79e945b5d148b8ef___sys__Undefined___js_sys_47ef7e31b3f1968c___Function_fn_wasm_bindgen_79e945b5d148b8ef___JsValue_____wasm_bindgen_79e945b5d148b8ef___sys__Undefined_______true_(a, state0.b, arg0, arg1);
972
1101
  } finally {
973
1102
  state0.a = a;
974
1103
  }
@@ -979,6 +1108,10 @@ function __wbg_get_imports() {
979
1108
  state0.a = 0;
980
1109
  }
981
1110
  },
1111
+ __wbg_new_b667d279fd5aa943: function(arg0, arg1) {
1112
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
1113
+ return ret;
1114
+ },
982
1115
  __wbg_new_cd45aabdf6073e84: function(arg0) {
983
1116
  const ret = new Uint8Array(arg0);
984
1117
  return ret;
@@ -998,7 +1131,7 @@ function __wbg_get_imports() {
998
1131
  const a = state0.a;
999
1132
  state0.a = 0;
1000
1133
  try {
1001
- return wasm_bindgen_9e362b674ca4cea___convert__closures_____invoke___js_sys_77b4e3062c519671___Function_fn_wasm_bindgen_9e362b674ca4cea___JsValue_____wasm_bindgen_9e362b674ca4cea___sys__Undefined___js_sys_77b4e3062c519671___Function_fn_wasm_bindgen_9e362b674ca4cea___JsValue_____wasm_bindgen_9e362b674ca4cea___sys__Undefined_______true_(a, state0.b, arg0, arg1);
1134
+ return wasm_bindgen_79e945b5d148b8ef___convert__closures_____invoke___js_sys_47ef7e31b3f1968c___Function_fn_wasm_bindgen_79e945b5d148b8ef___JsValue_____wasm_bindgen_79e945b5d148b8ef___sys__Undefined___js_sys_47ef7e31b3f1968c___Function_fn_wasm_bindgen_79e945b5d148b8ef___JsValue_____wasm_bindgen_79e945b5d148b8ef___sys__Undefined_______true_(a, state0.b, arg0, arg1);
1002
1135
  } finally {
1003
1136
  state0.a = a;
1004
1137
  }
@@ -1025,6 +1158,10 @@ function __wbg_get_imports() {
1025
1158
  const ret = Date.now();
1026
1159
  return ret;
1027
1160
  },
1161
+ __wbg_of_85f52f8b6491a7ca: function(arg0) {
1162
+ const ret = Array.of(arg0);
1163
+ return ret;
1164
+ },
1028
1165
  __wbg_prototypesetcall_4770620bbe4688a0: function(arg0, arg1, arg2) {
1029
1166
  Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
1030
1167
  },
@@ -1035,10 +1172,24 @@ function __wbg_get_imports() {
1035
1172
  __wbg_queueMicrotask_6a09b7bc46549209: function(arg0) {
1036
1173
  queueMicrotask(arg0);
1037
1174
  },
1175
+ __wbg_reject_90df95b492dd8563: function(arg0) {
1176
+ const ret = Promise.reject(arg0);
1177
+ return ret;
1178
+ },
1179
+ __wbg_removeEventListener_a3f23c70077bdcc1: function() { return handleError(function (arg0, arg1, arg2, arg3) {
1180
+ arg0.removeEventListener(getStringFromWasm0(arg1, arg2), arg3);
1181
+ }, arguments); },
1038
1182
  __wbg_resolve_2191a4dfe481c25b: function(arg0) {
1039
1183
  const ret = Promise.resolve(arg0);
1040
1184
  return ret;
1041
1185
  },
1186
+ __wbg_setItem_364a11cf21db9039: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
1187
+ arg0.setItem(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
1188
+ }, arguments); },
1189
+ __wbg_setTimeout_123855a087c71568: function(arg0, arg1) {
1190
+ const ret = setTimeout(arg0, arg1);
1191
+ return ret;
1192
+ },
1042
1193
  __wbg_setTimeout_f757f00851f76c42: function(arg0, arg1) {
1043
1194
  const ret = setTimeout(arg0, arg1);
1044
1195
  return ret;
@@ -1050,6 +1201,10 @@ function __wbg_get_imports() {
1050
1201
  __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
1051
1202
  arg0[arg1] = arg2;
1052
1203
  },
1204
+ __wbg_set_8535240470bf2500: function() { return handleError(function (arg0, arg1, arg2) {
1205
+ const ret = Reflect.set(arg0, arg1, arg2);
1206
+ return ret;
1207
+ }, arguments); },
1053
1208
  __wbg_set_8a16b38e4805b298: function(arg0, arg1, arg2) {
1054
1209
  arg0[arg1 >>> 0] = arg2;
1055
1210
  },
@@ -1102,6 +1257,10 @@ function __wbg_get_imports() {
1102
1257
  const ret = JSON.stringify(arg0);
1103
1258
  return ret;
1104
1259
  }, arguments); },
1260
+ __wbg_subarray_3ed232c8a6baee09: function(arg0, arg1, arg2) {
1261
+ const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
1262
+ return ret;
1263
+ },
1105
1264
  __wbg_text_d3a29f7525a132c3: function() { return handleError(function (arg0) {
1106
1265
  const ret = arg0.text();
1107
1266
  return ret;
@@ -1126,13 +1285,13 @@ function __wbg_get_imports() {
1126
1285
  return ret;
1127
1286
  },
1128
1287
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
1129
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 156, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1130
- const ret = makeMutClosure(arg0, arg1, wasm_bindgen_9e362b674ca4cea___convert__closures_____invoke___wasm_bindgen_9e362b674ca4cea___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_9e362b674ca4cea___JsError___true_);
1288
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 155, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1289
+ const ret = makeMutClosure(arg0, arg1, wasm_bindgen_79e945b5d148b8ef___convert__closures_____invoke___wasm_bindgen_79e945b5d148b8ef___JsValue__core_608f92abc48d28da___result__Result_____wasm_bindgen_79e945b5d148b8ef___JsError___true_);
1131
1290
  return ret;
1132
1291
  },
1133
1292
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
1134
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 306, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1135
- const ret = makeMutClosure(arg0, arg1, wasm_bindgen_9e362b674ca4cea___convert__closures_____invoke_______true_);
1293
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 47, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1294
+ const ret = makeMutClosure(arg0, arg1, wasm_bindgen_79e945b5d148b8ef___convert__closures_____invoke_______true_);
1136
1295
  return ret;
1137
1296
  },
1138
1297
  __wbindgen_cast_0000000000000003: function(arg0) {
@@ -1171,19 +1330,19 @@ function __wbg_get_imports() {
1171
1330
  };
1172
1331
  }
1173
1332
 
1174
- function wasm_bindgen_9e362b674ca4cea___convert__closures_____invoke_______true_(arg0, arg1) {
1175
- wasm.wasm_bindgen_9e362b674ca4cea___convert__closures_____invoke_______true_(arg0, arg1);
1333
+ function wasm_bindgen_79e945b5d148b8ef___convert__closures_____invoke_______true_(arg0, arg1) {
1334
+ wasm.wasm_bindgen_79e945b5d148b8ef___convert__closures_____invoke_______true_(arg0, arg1);
1176
1335
  }
1177
1336
 
1178
- function wasm_bindgen_9e362b674ca4cea___convert__closures_____invoke___wasm_bindgen_9e362b674ca4cea___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_9e362b674ca4cea___JsError___true_(arg0, arg1, arg2) {
1179
- const ret = wasm.wasm_bindgen_9e362b674ca4cea___convert__closures_____invoke___wasm_bindgen_9e362b674ca4cea___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_9e362b674ca4cea___JsError___true_(arg0, arg1, arg2);
1337
+ function wasm_bindgen_79e945b5d148b8ef___convert__closures_____invoke___wasm_bindgen_79e945b5d148b8ef___JsValue__core_608f92abc48d28da___result__Result_____wasm_bindgen_79e945b5d148b8ef___JsError___true_(arg0, arg1, arg2) {
1338
+ const ret = wasm.wasm_bindgen_79e945b5d148b8ef___convert__closures_____invoke___wasm_bindgen_79e945b5d148b8ef___JsValue__core_608f92abc48d28da___result__Result_____wasm_bindgen_79e945b5d148b8ef___JsError___true_(arg0, arg1, arg2);
1180
1339
  if (ret[1]) {
1181
1340
  throw takeFromExternrefTable0(ret[0]);
1182
1341
  }
1183
1342
  }
1184
1343
 
1185
- function wasm_bindgen_9e362b674ca4cea___convert__closures_____invoke___js_sys_77b4e3062c519671___Function_fn_wasm_bindgen_9e362b674ca4cea___JsValue_____wasm_bindgen_9e362b674ca4cea___sys__Undefined___js_sys_77b4e3062c519671___Function_fn_wasm_bindgen_9e362b674ca4cea___JsValue_____wasm_bindgen_9e362b674ca4cea___sys__Undefined_______true_(arg0, arg1, arg2, arg3) {
1186
- wasm.wasm_bindgen_9e362b674ca4cea___convert__closures_____invoke___js_sys_77b4e3062c519671___Function_fn_wasm_bindgen_9e362b674ca4cea___JsValue_____wasm_bindgen_9e362b674ca4cea___sys__Undefined___js_sys_77b4e3062c519671___Function_fn_wasm_bindgen_9e362b674ca4cea___JsValue_____wasm_bindgen_9e362b674ca4cea___sys__Undefined_______true_(arg0, arg1, arg2, arg3);
1344
+ function wasm_bindgen_79e945b5d148b8ef___convert__closures_____invoke___js_sys_47ef7e31b3f1968c___Function_fn_wasm_bindgen_79e945b5d148b8ef___JsValue_____wasm_bindgen_79e945b5d148b8ef___sys__Undefined___js_sys_47ef7e31b3f1968c___Function_fn_wasm_bindgen_79e945b5d148b8ef___JsValue_____wasm_bindgen_79e945b5d148b8ef___sys__Undefined_______true_(arg0, arg1, arg2, arg3) {
1345
+ wasm.wasm_bindgen_79e945b5d148b8ef___convert__closures_____invoke___js_sys_47ef7e31b3f1968c___Function_fn_wasm_bindgen_79e945b5d148b8ef___JsValue_____wasm_bindgen_79e945b5d148b8ef___sys__Undefined___js_sys_47ef7e31b3f1968c___Function_fn_wasm_bindgen_79e945b5d148b8ef___JsValue_____wasm_bindgen_79e945b5d148b8ef___sys__Undefined_______true_(arg0, arg1, arg2, arg3);
1187
1346
  }
1188
1347
 
1189
1348
 
package/moss_wasm_bg.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@moss-dev/moss-wasm",
3
3
  "type": "module",
4
4
  "description": "Moss WASM bindings for in-browser semantic search",
5
- "version": "0.16.0",
5
+ "version": "0.17.0",
6
6
  "license": "SEE LICENSE IN LICENSE",
7
7
  "repository": {
8
8
  "type": "git",