@moss-dev/moss-web 1.4.0 → 1.5.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/README.md +10 -64
- package/dist/client.js +1 -1
- package/dist/embedder.js +4 -1
- package/dist/model-delivery.d.ts +2 -1
- package/dist/model-delivery.js +3 -2
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Built on WebAssembly for near-native performance in any modern browser.
|
|
|
10
10
|
- **Semantic & Hybrid Search** — Beyond keyword matching
|
|
11
11
|
- **Multi-Index Support** — Manage multiple isolated search spaces
|
|
12
12
|
- **Full CRUD** — Create, update, and delete indexes and documents from the browser
|
|
13
|
-
- **Privacy-First** — Queries run entirely in the browser
|
|
13
|
+
- **Privacy-First** — Queries run entirely in the browser and never leave the device. Usage telemetry is sent (see [Telemetry](#telemetry))
|
|
14
14
|
|
|
15
15
|
## Installation
|
|
16
16
|
|
|
@@ -18,10 +18,10 @@ Built on WebAssembly for near-native performance in any modern browser.
|
|
|
18
18
|
npm install @moss-dev/moss-web
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
Version 1.
|
|
21
|
+
Version 1.5.0 resolves `@moss-dev/moss-wasm@0.18.0`. Text `query()` loads its
|
|
22
22
|
model through the Moss service using the client's credentials, so the service
|
|
23
23
|
must be reachable the first time a model is loaded; there is no offline
|
|
24
|
-
fallback.
|
|
24
|
+
fallback. Before 1.2.0 the only published npm versions were 1.0.0 and 1.0.1,
|
|
25
25
|
where `queryWithEmbedding()` remains available for caller-supplied embeddings.
|
|
26
26
|
|
|
27
27
|
## Quick Start
|
|
@@ -246,67 +246,13 @@ client.dispose();
|
|
|
246
246
|
|
|
247
247
|
## Telemetry
|
|
248
248
|
|
|
249
|
-
The browser SDK always sends usage
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
and sends the count, and `dispose()` sends what is left. While there are none,
|
|
257
|
-
it gets a token every 30 seconds, so a page that is closing can send without
|
|
258
|
-
waiting for one. It gets these tokens the way other requests do, so a cached
|
|
259
|
-
token costs no request, and with an authenticator whose tokens are not cached,
|
|
260
|
-
each one is a `getAuthToken()` call. Counts wait until the first token request
|
|
261
|
-
succeeds. A failed send is dropped. It never fails a query or raises an
|
|
262
|
-
unhandled promise rejection.
|
|
263
|
-
|
|
264
|
-
Each send is one usage body and the query events in JSON arrays of up to 500,
|
|
265
|
-
the bodies the native SDKs send. One send carries at most 10,000 query events,
|
|
266
|
-
and later queries wait for the next send. A send uses `keepalive`, so a
|
|
267
|
-
navigation does not cancel it, when it fits in about 60 KB that every client on
|
|
268
|
-
the page shares, since browsers allow 64 KiB of keepalive requests in flight per
|
|
269
|
-
page. On `pagehide` and `dispose()` the client starts at once the sends that fit.
|
|
270
|
-
After `pagehide` the rest stay counted for a page restored from the back/forward
|
|
271
|
-
cache, and are lost when the page unloads.
|
|
272
|
-
|
|
273
|
-
### Device id
|
|
274
|
-
|
|
275
|
-
`deviceId` is the billable device key. A page reads it once, when its first
|
|
276
|
-
client initializes, from `localStorage` under `moss-device-id`. When there is
|
|
277
|
-
none, the SDK creates a random UUID and stores it there, so page reloads and
|
|
278
|
-
every client on the origin reuse it. Later clients on the same page reuse the id
|
|
279
|
-
in memory and do not touch `localStorage`, so after the site's data is cleared,
|
|
280
|
-
the next page load stores a new id. Where `localStorage` is missing or throws,
|
|
281
|
-
each page, worker or process gets a new id that lasts until it ends. That
|
|
282
|
-
happens in some private windows and sandboxed frames, in Web Workers, and under
|
|
283
|
-
Node or server rendering, so each of those counts as a new device. Browsers also
|
|
284
|
-
scope the stored id: a third-party iframe gets one id per top-level site, and
|
|
285
|
-
Safari deletes it after 7 days of use without a visit to the site.
|
|
286
|
-
|
|
287
|
-
### Fields on every event
|
|
288
|
-
|
|
289
|
-
| Field | Value |
|
|
290
|
-
|---|---|
|
|
291
|
-
| `action` | Always `"telemetry"`. |
|
|
292
|
-
| `eventType` | The event type, from the table below. |
|
|
293
|
-
| `projectId` | Your project id. |
|
|
294
|
-
| `clientId`, `sessionId` | The same random id, one per client. |
|
|
295
|
-
| `sdkVersion`, `sdkPackageVersion` | Version of `@moss-dev/moss-wasm`. |
|
|
296
|
-
| `nativeCoreVersion` | Version of the Rust core. |
|
|
297
|
-
| `deviceId`, `mossDeviceId` | The device id, the same value in both. |
|
|
298
|
-
|
|
299
|
-
### Event types
|
|
300
|
-
|
|
301
|
-
| Event | Sent when | Extra fields |
|
|
302
|
-
|---|---|---|
|
|
303
|
-
| `index.usage.periodic_flush` | Every 3 seconds while there are new queries | `queryCount`, and `docsEmbedded` and `tokensEstimated`, always 0 |
|
|
304
|
-
| `index.usage.final_flush` | On `dispose()` and `pagehide`, when queries are left | The same as `index.usage.periodic_flush` |
|
|
305
|
-
| `index.query` | Once per single index query, in a batch | None |
|
|
306
|
-
| `index.query_multi` | Once per multi-index query, in a batch | None |
|
|
307
|
-
|
|
308
|
-
Query events carry no index name, latency or model, because a query only adds
|
|
309
|
-
to a count. No document text, query text, metadata or embedding is ever sent.
|
|
249
|
+
The browser SDK always sends usage telemetry to the Moss cloud, and there is no
|
|
250
|
+
option to turn it off. It sends your project id, a random id per client, SDK
|
|
251
|
+
versions, query counts and a device id, which is a random UUID stored in
|
|
252
|
+
`localStorage` under `moss-device-id`. Telemetry never includes index names,
|
|
253
|
+
query text, document text, metadata or embeddings.
|
|
254
|
+
|
|
255
|
+
See [Telemetry](https://docs.moss.dev/docs/reference/telemetry) for every field and when it is sent.
|
|
310
256
|
|
|
311
257
|
## License
|
|
312
258
|
|
package/dist/client.js
CHANGED
|
@@ -98,7 +98,7 @@ export class MossClient {
|
|
|
98
98
|
this.projectKeyAuthenticator = projectKeyAuth;
|
|
99
99
|
deliveryAuth = {
|
|
100
100
|
getAuthHeader: () => projectKeyAuth.getAuthHeader(),
|
|
101
|
-
invalidate: () => projectKeyAuth.invalidate(),
|
|
101
|
+
invalidate: (rejected) => projectKeyAuth.invalidate(rejected),
|
|
102
102
|
};
|
|
103
103
|
if (this.options.baseUrl) {
|
|
104
104
|
this.indexManager = IndexManager.withBaseUrl(this.projectId, this.projectKey, this.options.baseUrl);
|
package/dist/embedder.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
// Outside Node, #ort is onnxruntime-web/wasm, which loads the plain wasm build.
|
|
2
|
+
// The default entry adds WebGPU and a jsep wasm about twice the size, unused here.
|
|
3
|
+
// Under Node, #ort is the default entry, whose node build reads the wasm from disk.
|
|
4
|
+
import * as ort from "#ort";
|
|
2
5
|
import { modelHiddenDim } from "./model-config.js";
|
|
3
6
|
import { loadSealedModel } from "./model-delivery.js";
|
|
4
7
|
export class Embedder {
|
package/dist/model-delivery.d.ts
CHANGED
|
@@ -43,7 +43,8 @@ export interface WebCryptoSealedModelRuntime {
|
|
|
43
43
|
}
|
|
44
44
|
export interface ModelDeliveryAuth {
|
|
45
45
|
getAuthHeader(): Promise<string>;
|
|
46
|
-
|
|
46
|
+
/** Called with the header a 401 refused, before the retry asks for a header again. */
|
|
47
|
+
invalidate(rejected: string): Promise<void> | void;
|
|
47
48
|
}
|
|
48
49
|
export interface ModelDeliveryOptions {
|
|
49
50
|
projectId: string;
|
package/dist/model-delivery.js
CHANGED
|
@@ -166,10 +166,11 @@ export async function requestModelDeliveryGrant(options, sku, capabilityQuery) {
|
|
|
166
166
|
let response;
|
|
167
167
|
let body;
|
|
168
168
|
try {
|
|
169
|
-
|
|
169
|
+
const header = await options.auth.getAuthHeader();
|
|
170
|
+
response = await send(header);
|
|
170
171
|
if (response.status === 401) {
|
|
171
172
|
response.body?.cancel().catch(() => undefined);
|
|
172
|
-
await options.auth.invalidate();
|
|
173
|
+
await options.auth.invalidate(header);
|
|
173
174
|
response = await send(await options.auth.getAuthHeader());
|
|
174
175
|
}
|
|
175
176
|
body = response.ok
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moss-dev/moss-web",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Moss browser SDK — in-browser semantic search powered by WASM",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -12,6 +12,12 @@
|
|
|
12
12
|
"import": "./dist/index.js"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
|
+
"imports": {
|
|
16
|
+
"#ort": {
|
|
17
|
+
"node": "onnxruntime-web",
|
|
18
|
+
"default": "onnxruntime-web/wasm"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
15
21
|
"files": [
|
|
16
22
|
"dist",
|
|
17
23
|
"README.md",
|
|
@@ -25,8 +31,8 @@
|
|
|
25
31
|
"test": "npm run build && node --test"
|
|
26
32
|
},
|
|
27
33
|
"dependencies": {
|
|
28
|
-
"@moss-dev/moss-wasm": "0.
|
|
29
|
-
"onnxruntime-web": "
|
|
34
|
+
"@moss-dev/moss-wasm": "0.18.0",
|
|
35
|
+
"onnxruntime-web": "1.30.0"
|
|
30
36
|
},
|
|
31
37
|
"devDependencies": {
|
|
32
38
|
"typescript": "^6.0.3",
|