@moss-dev/moss-web 1.0.1 → 1.3.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 +94 -4
- package/dist/auth/authenticator.interface.d.ts +14 -0
- package/dist/auth/authenticator.interface.js +1 -0
- package/dist/auth/caching.authenticator.d.ts +12 -0
- package/dist/auth/caching.authenticator.js +49 -0
- package/dist/client.d.ts +50 -6
- package/dist/client.js +230 -75
- package/dist/embedder.d.ts +13 -11
- package/dist/embedder.js +86 -66
- package/dist/index.d.ts +4 -2
- package/dist/index.js +2 -1
- package/dist/model-artifact-ownership.d.ts +18 -0
- package/dist/model-artifact-ownership.js +106 -0
- package/dist/model-config.d.ts +3 -0
- package/dist/model-config.js +8 -0
- package/dist/model-delivery.d.ts +81 -0
- package/dist/model-delivery.js +521 -0
- package/dist/sha256.d.ts +14 -0
- package/dist/sha256.js +152 -0
- package/dist/types.d.ts +53 -1
- package/dist/wasm-runtime-capability.d.ts +20 -0
- package/dist/wasm-runtime-capability.js +75 -0
- package/package.json +7 -7
- package/dist/query-model.d.ts +0 -9
- package/dist/query-model.js +0 -17
package/dist/types.d.ts
CHANGED
|
@@ -4,6 +4,22 @@ export interface MossClientOptions {
|
|
|
4
4
|
model?: MossModel;
|
|
5
5
|
wasmUrl?: string;
|
|
6
6
|
onnxWasmPath?: string;
|
|
7
|
+
modelArtifactOrigin?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Called while the embedding model that text queries need is loaded, as bytes arrive.
|
|
10
|
+
* An error thrown here is ignored and does not stop the load.
|
|
11
|
+
*/
|
|
12
|
+
onProgress?: (progress: ModelDownloadProgress) => void;
|
|
13
|
+
}
|
|
14
|
+
/** Progress of the embedding model file that the first text query waits on. */
|
|
15
|
+
export interface ModelDownloadProgress {
|
|
16
|
+
modelId: MossModel;
|
|
17
|
+
/** Bytes of the model file received so far. Starts again from 0 when a stalled request is retried. */
|
|
18
|
+
loadedBytes: number;
|
|
19
|
+
/** Size of the model file in bytes, as the verified release manifest records it. */
|
|
20
|
+
totalBytes: number;
|
|
21
|
+
/** True when the verified file came from the browser Cache API and no transfer took place. */
|
|
22
|
+
fromCache: boolean;
|
|
7
23
|
}
|
|
8
24
|
export interface ModelRef {
|
|
9
25
|
id: string;
|
|
@@ -18,12 +34,28 @@ export interface IndexInfo {
|
|
|
18
34
|
createdAt?: string;
|
|
19
35
|
updatedAt?: string;
|
|
20
36
|
model: ModelRef;
|
|
37
|
+
modelArtifactVersion?: string;
|
|
38
|
+
manifestSha256?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface ModelArtifactIdentity {
|
|
41
|
+
modelId: MossModel;
|
|
42
|
+
version: string;
|
|
43
|
+
manifestSha256: string;
|
|
21
44
|
}
|
|
22
45
|
export interface QueryResultDocumentInfo {
|
|
23
46
|
id: string;
|
|
24
47
|
text: string;
|
|
25
48
|
metadata?: Record<string, string>;
|
|
49
|
+
/**
|
|
50
|
+
* Relevance to the query from 0 to 1. It comes from vector similarity
|
|
51
|
+
* alone, so `alpha` and rank never change it. Results are ordered by hybrid
|
|
52
|
+
* relevance, so a lower result can show a higher score. A keyword-only query
|
|
53
|
+
* (`alpha` 0, or an index without vectors) scores every hit 0. Scores
|
|
54
|
+
* depend on the embedding model.
|
|
55
|
+
*/
|
|
26
56
|
score: number;
|
|
57
|
+
/** Source index. Set on multi-index results; absent for single-index. */
|
|
58
|
+
indexName?: string;
|
|
27
59
|
}
|
|
28
60
|
export interface SearchResult {
|
|
29
61
|
docs: QueryResultDocumentInfo[];
|
|
@@ -35,6 +67,14 @@ export interface QueryOptions {
|
|
|
35
67
|
topK?: number;
|
|
36
68
|
alpha?: number;
|
|
37
69
|
filter?: MetadataFilter;
|
|
70
|
+
/**
|
|
71
|
+
* How many hits a hybrid query (`alpha` between 0 and 1) ranks on each
|
|
72
|
+
* signal before fusion. A hit outside both lists is never returned, so a
|
|
73
|
+
* deeper list raises recall and query time. Defaults to `2 * topK`. A set
|
|
74
|
+
* value must be at least 1 and is raised to `topK` when below it.
|
|
75
|
+
* Keyword-only and vector-only queries (`alpha` 0 or 1) ignore it.
|
|
76
|
+
*/
|
|
77
|
+
candidateDepth?: number;
|
|
38
78
|
}
|
|
39
79
|
export type MetadataFilter = {
|
|
40
80
|
field: string;
|
|
@@ -68,6 +108,9 @@ export interface RefreshResult {
|
|
|
68
108
|
previousUpdatedAt: string;
|
|
69
109
|
newUpdatedAt: string;
|
|
70
110
|
wasUpdated: boolean;
|
|
111
|
+
modelId?: string;
|
|
112
|
+
modelArtifactVersion?: string;
|
|
113
|
+
manifestSha256?: string;
|
|
71
114
|
}
|
|
72
115
|
export interface DocumentInfo {
|
|
73
116
|
id: string;
|
|
@@ -85,6 +128,10 @@ export interface CreateIndexOptions {
|
|
|
85
128
|
onProgress?: (progress: JobProgress) => void;
|
|
86
129
|
}
|
|
87
130
|
export interface MutationOptions {
|
|
131
|
+
/**
|
|
132
|
+
* Whether a document replaces a stored one with the same ID.
|
|
133
|
+
* `addDocs` sends it only when set, and the cloud service decides how to apply it.
|
|
134
|
+
*/
|
|
88
135
|
upsert?: boolean;
|
|
89
136
|
onProgress?: (progress: JobProgress) => void;
|
|
90
137
|
}
|
|
@@ -94,7 +141,7 @@ export interface ParseFileInput {
|
|
|
94
141
|
contentType: string;
|
|
95
142
|
}
|
|
96
143
|
export type JobStatus = "pending_upload" | "uploading" | "building" | "completed" | "failed";
|
|
97
|
-
export type JobPhase = "downloading" | "deserializing" | "generating_embeddings" | "building_index" | "uploading" | "cleanup" | "waiting_for_parser" | "parsing" | "parsing_complete" | "queued";
|
|
144
|
+
export type JobPhase = "downloading" | "deserializing" | "generating_embeddings" | "building_index" | "uploading" | "cleanup" | "waiting_for_parser" | "parsing" | "parsing_complete" | "queued" | "crawling" | "parsing_documents";
|
|
98
145
|
export interface JobProgress {
|
|
99
146
|
jobId: string;
|
|
100
147
|
status: JobStatus;
|
|
@@ -118,4 +165,9 @@ export interface LoadIndexOptions {
|
|
|
118
165
|
autoRefresh?: boolean;
|
|
119
166
|
pollingIntervalInSeconds?: number;
|
|
120
167
|
}
|
|
168
|
+
/** Outcome of a bulk load. Indexes that succeed are kept even if others fail. */
|
|
169
|
+
export interface LoadIndexesResult {
|
|
170
|
+
loaded: string[];
|
|
171
|
+
failed: Record<string, string>;
|
|
172
|
+
}
|
|
121
173
|
export type ISODate = string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MetadataFilter, ModelArtifactIdentity, QueryOptions, SearchResult } from "./types.js";
|
|
2
|
+
/** Optional settings the runtime query methods take after `filter`. */
|
|
3
|
+
export interface RuntimeQueryTuning {
|
|
4
|
+
candidateDepth?: number;
|
|
5
|
+
}
|
|
6
|
+
/** The runtime tuning fields of `options`, or undefined when none is set. */
|
|
7
|
+
export declare function runtimeQueryTuning(options?: QueryOptions): RuntimeQueryTuning | undefined;
|
|
8
|
+
export interface ProvenanceAwareIndexManager {
|
|
9
|
+
queryWithModelIdentity(indexName: string, query: string, embedding: Float32Array, modelId: string, modelArtifactVersion: string, manifestSha256: string, topK: number | undefined, alpha: number | undefined, filter: MetadataFilter | undefined, tuning?: RuntimeQueryTuning): Promise<SearchResult>;
|
|
10
|
+
}
|
|
11
|
+
export declare function provenanceAwareIndexManager(manager: unknown): ProvenanceAwareIndexManager | null;
|
|
12
|
+
export declare function requireProvenanceAwareIndexManager(manager: unknown): ProvenanceAwareIndexManager;
|
|
13
|
+
export interface MultiIndexIndexManager {
|
|
14
|
+
queryMultiIndex(indexNames: string[], query: string, embedding: Float32Array, topK: number | undefined, alpha: number | undefined, filter: MetadataFilter | undefined, tuning?: RuntimeQueryTuning): Promise<SearchResult>;
|
|
15
|
+
queryMultiIndexWithModelIdentity(indexNames: string[], query: string, embedding: Float32Array, modelId: string, modelArtifactVersion: string, manifestSha256: string, topK: number | undefined, alpha: number | undefined, filter: MetadataFilter | undefined, tuning?: RuntimeQueryTuning): Promise<SearchResult>;
|
|
16
|
+
}
|
|
17
|
+
export declare function multiIndexIndexManager(manager: unknown): MultiIndexIndexManager | null;
|
|
18
|
+
export declare function requireMultiIndexIndexManager(manager: unknown): MultiIndexIndexManager;
|
|
19
|
+
export declare function exactModelArtifactIdentity(modelId: string, version?: string, manifestSha256?: string): ModelArtifactIdentity | null;
|
|
20
|
+
export declare function queryWithResolvedModelIdentity(manager: unknown, identity: ModelArtifactIdentity | null, indexName: string, query: string, embedding: Float32Array, topK: number | undefined, alpha: number | undefined, filter: MetadataFilter | undefined, tuning?: RuntimeQueryTuning): Promise<SearchResult>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** The runtime tuning fields of `options`, or undefined when none is set. */
|
|
2
|
+
export function runtimeQueryTuning(options) {
|
|
3
|
+
if (options?.candidateDepth === undefined) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
return { candidateDepth: options.candidateDepth };
|
|
7
|
+
}
|
|
8
|
+
export function provenanceAwareIndexManager(manager) {
|
|
9
|
+
if (typeof manager !== "object"
|
|
10
|
+
|| manager === null
|
|
11
|
+
|| typeof manager.queryWithModelIdentity !== "function") {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
return manager;
|
|
15
|
+
}
|
|
16
|
+
export function requireProvenanceAwareIndexManager(manager) {
|
|
17
|
+
const capable = provenanceAwareIndexManager(manager);
|
|
18
|
+
if (!capable) {
|
|
19
|
+
throw new Error("The installed @moss-dev/moss-wasm runtime cannot bind text inference to an exact model artifact; use queryWithEmbedding");
|
|
20
|
+
}
|
|
21
|
+
return capable;
|
|
22
|
+
}
|
|
23
|
+
const MULTI_INDEX_METHODS = [
|
|
24
|
+
"queryMultiIndex",
|
|
25
|
+
"queryMultiIndexWithModelIdentity",
|
|
26
|
+
];
|
|
27
|
+
export function multiIndexIndexManager(manager) {
|
|
28
|
+
if (typeof manager !== "object" || manager === null)
|
|
29
|
+
return null;
|
|
30
|
+
const candidate = manager;
|
|
31
|
+
for (const method of MULTI_INDEX_METHODS) {
|
|
32
|
+
if (typeof candidate[method] !== "function")
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return manager;
|
|
36
|
+
}
|
|
37
|
+
export function requireMultiIndexIndexManager(manager) {
|
|
38
|
+
const capable = multiIndexIndexManager(manager);
|
|
39
|
+
if (!capable) {
|
|
40
|
+
throw new Error("The installed @moss-dev/moss-wasm does not support multi-index operations (queryMultiIndex). Upgrade @moss-dev/moss-wasm.");
|
|
41
|
+
}
|
|
42
|
+
return capable;
|
|
43
|
+
}
|
|
44
|
+
export function exactModelArtifactIdentity(modelId, version, manifestSha256) {
|
|
45
|
+
if (modelId === "custom")
|
|
46
|
+
return null;
|
|
47
|
+
if (modelId !== "moss-minilm" && modelId !== "moss-mediumlm") {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
if (!version
|
|
51
|
+
|| !manifestSha256
|
|
52
|
+
|| version.trim() !== version
|
|
53
|
+
|| version === "."
|
|
54
|
+
|| version === ".."
|
|
55
|
+
|| /[\\/?#%\u0000-\u001f\u007f]/.test(version)
|
|
56
|
+
|| !/^[0-9a-f]{64}$/.test(manifestSha256)) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return { modelId, version, manifestSha256 };
|
|
60
|
+
}
|
|
61
|
+
export function queryWithResolvedModelIdentity(manager, identity, indexName, query, embedding, topK, alpha, filter, tuning) {
|
|
62
|
+
if (identity) {
|
|
63
|
+
const capable = provenanceAwareIndexManager(manager);
|
|
64
|
+
if (!capable) {
|
|
65
|
+
throw new Error("The installed @moss-dev/moss-wasm runtime cannot bind this foundation query embedding to its exact model artifact identity");
|
|
66
|
+
}
|
|
67
|
+
return capable.queryWithModelIdentity(indexName, query, embedding, identity.modelId, identity.version, identity.manifestSha256, topK, alpha, filter, tuning);
|
|
68
|
+
}
|
|
69
|
+
if (typeof manager !== "object"
|
|
70
|
+
|| manager === null
|
|
71
|
+
|| typeof manager.query !== "function") {
|
|
72
|
+
throw new Error("The installed @moss-dev/moss-wasm runtime cannot query this index");
|
|
73
|
+
}
|
|
74
|
+
return manager.query(indexName, query, embedding, topK, alpha, filter, tuning);
|
|
75
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moss-dev/moss-web",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Moss browser SDK — in-browser semantic search powered by WASM",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,16 +21,16 @@
|
|
|
21
21
|
"build": "tsc",
|
|
22
22
|
"clean": "rm -rf dist",
|
|
23
23
|
"prepack": "npm run clean && npm run build",
|
|
24
|
-
"
|
|
25
|
-
"
|
|
24
|
+
"samples": "npx vite",
|
|
25
|
+
"test": "npm run build && node --test"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@moss-dev/moss-wasm": "0.
|
|
29
|
-
"onnxruntime-web": "^1.
|
|
28
|
+
"@moss-dev/moss-wasm": "0.16.0",
|
|
29
|
+
"onnxruntime-web": "^1.27.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"typescript": "^
|
|
33
|
-
"vite": "^8.
|
|
32
|
+
"typescript": "^6.0.3",
|
|
33
|
+
"vite": "^8.1.3"
|
|
34
34
|
},
|
|
35
35
|
"keywords": [
|
|
36
36
|
"moss",
|
package/dist/query-model.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { MossModel } from "./types";
|
|
2
|
-
export declare const SUPPORTED_MODELS: readonly MossModel[];
|
|
3
|
-
export declare function isSupportedModel(id: string): id is MossModel;
|
|
4
|
-
/**
|
|
5
|
-
* Pick the embedding model for a query. The loaded index's model wins when
|
|
6
|
-
* known; a missing model id falls back to the configured client model.
|
|
7
|
-
* A known-but-unsupported model has no browser embedder and cannot be queried.
|
|
8
|
-
*/
|
|
9
|
-
export declare function resolveQueryModel(indexModelId: string | null | undefined, configuredModel: MossModel): MossModel;
|
package/dist/query-model.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export const SUPPORTED_MODELS = ["moss-minilm", "moss-mediumlm"];
|
|
2
|
-
export function isSupportedModel(id) {
|
|
3
|
-
return SUPPORTED_MODELS.includes(id);
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Pick the embedding model for a query. The loaded index's model wins when
|
|
7
|
-
* known; a missing model id falls back to the configured client model.
|
|
8
|
-
* A known-but-unsupported model has no browser embedder and cannot be queried.
|
|
9
|
-
*/
|
|
10
|
-
export function resolveQueryModel(indexModelId, configuredModel) {
|
|
11
|
-
if (indexModelId == null || indexModelId === "")
|
|
12
|
-
return configuredModel;
|
|
13
|
-
if (isSupportedModel(indexModelId))
|
|
14
|
-
return indexModelId;
|
|
15
|
-
throw new Error(`Index was built with model "${indexModelId}", which has no browser embedder. ` +
|
|
16
|
-
`Query this index through the Moss service SDK instead.`);
|
|
17
|
-
}
|