@moss-js/moss-core 0.24.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 ADDED
@@ -0,0 +1,19 @@
1
+ # Moss JavaScript Binding
2
+
3
+ Rust-powered Node.js native addon that exposes the Moss core indexing and model APIs via N-API.
4
+
5
+ ## Getting Started
6
+
7
+ ```bash
8
+ npm install @moss-js/moss-core
9
+ ```
10
+
11
+ The package bundles prebuilt binaries for common targets; npm will download the correct artifact for your platform during install.
12
+
13
+ ## Prerequisites For Local Builds
14
+
15
+ - Node.js 20+ (matches the engines field in `package.json`)
16
+ - Rust toolchain with `cargo`
17
+ - `npm` 8+
18
+
19
+ Refer to the `test/` directory for additional usage examples.
package/index.d.ts ADDED
@@ -0,0 +1,658 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+ /**
4
+ * Low-level interface for working with a Moss search index from Node.js.
5
+ *
6
+ * Instances of this type keep an in-memory index that you can populate with
7
+ * precomputed embeddings, execute hybrid semantic queries, and serialize to
8
+ * the `.moss` file format. Most JavaScript developers should prefer the
9
+ * higher-level `MossClient`, but this type is available when you need direct
10
+ * control over embeddings and lifecycle.
11
+ */
12
+ export declare class Index {
13
+ /**
14
+ * Create a new in-memory index instance.
15
+ *
16
+ * @param name Index name used for diagnostics and serialization.
17
+ * @param modelId Embedding model identifier (`"moss-minilm"`, `"moss-mediumlm"`, or `"custom"`).
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const index = new Index('knowledge-base', 'moss-minilm')
22
+ * ```
23
+ */
24
+ constructor(name: string, modelId: string)
25
+ /**
26
+ * Get metadata describing the current index state.
27
+ *
28
+ * @returns Index information including status, document counts, and model details.
29
+ */
30
+ getInfo(): IndexInfo
31
+ /**
32
+ * Add new documents or update existing ones using precomputed embeddings.
33
+ *
34
+ * Embeddings **must** be generated separately and supplied alongside the
35
+ * documents in the same order.
36
+ *
37
+ * @param docs Documents to insert or update.
38
+ * @param embeddings One embedding vector per document.
39
+ * @param options Optional write behaviour (upsert by default).
40
+ * @returns Object containing the number of added and updated documents.
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * await index.addDocuments(docs, embeddings, { upsert: true })
45
+ * ```
46
+ */
47
+ addDocuments(docs: Array<DocumentInfo>, embeddings: Array<Array<number>>, options?: AddDocumentsOptions | null): IndexUpdateResult
48
+ /**
49
+ * Delete one or more documents by their identifier.
50
+ *
51
+ * @param docIds Document identifiers to remove.
52
+ * @returns Number of documents deleted.
53
+ */
54
+ deleteDocuments(docIds: Array<string>): number
55
+ /**
56
+ * Retrieve documents from the index.
57
+ *
58
+ * When `options.docIds` is omitted all documents are returned. Provide a
59
+ * list of IDs to fetch specific entries.
60
+ */
61
+ getDocuments(options?: GetDocumentsOptions | null): Array<DocumentInfo>
62
+ /**
63
+ * Perform a semantic similarity search using a precomputed query embedding.
64
+ *
65
+ * @param query Original search text used for logging and metadata.
66
+ * @param topK Maximum number of results to return (defaults to 5).
67
+ * @param queryEmbedding Precomputed embedding vector representing the query.
68
+ * @param alpha Optional hybrid fusion weight between dense and sparse scores (default `0.8`).
69
+ * @returns Search result containing ranked documents with scores.
70
+ */
71
+ query(query: string, topK: number, queryEmbedding: Array<number>, alpha?: number | null, filter?: object | null): SearchResult
72
+ /**
73
+ * Serialize the in-memory index into a plain JavaScript object.
74
+ *
75
+ * Useful for persisting the index or converting to the `.moss` binary format.
76
+ */
77
+ serialize(): SerializedIndex
78
+ /**
79
+ * Load serialized metadata and embeddings into the index instance.
80
+ *
81
+ * @param data Serialized index object produced by `serialize` or deserialized from `.moss` files.
82
+ * @param documents Full document objects matching the doc_ids in the serialized data.
83
+ */
84
+ deserialize(data: SerializedIndex, documents: Array<DocumentInfo>): void
85
+ /** Number of documents currently stored in the index. */
86
+ get docCount(): number
87
+ /** Remove all documents and embeddings from the index. */
88
+ clear(): void
89
+ }
90
+
91
+ /** Rust-backed local index manager with optional auto-refresh polling. */
92
+ export declare class IndexManager {
93
+ constructor(projectId: string, projectKey: string, baseUrl?: string | null)
94
+ /**
95
+ * Creates an IndexManager that delegates authentication to a JS `IAuthenticator`.
96
+ *
97
+ * `notifyFn` is a JS function `(requestId: number) => void`. When Rust needs a token,
98
+ * it calls this function with a unique `requestId`. The JS side must call
99
+ * `resolveAuthRequest(requestId, token)` or `rejectAuthRequest(requestId, error)`.
100
+ *
101
+ * `baseUrl` overrides the default cloud API endpoint — useful for testing against a local server.
102
+ */
103
+ static withAuthenticator(projectId: string, notifyFn: (err: Error | null, requestId: number) => void, baseUrl?: string | null): IndexManager
104
+ /**
105
+ * Set the stable per-device identifier emitted as `deviceId` on every
106
+ * telemetry event. No-op when telemetry is disabled for this manager,
107
+ * or when the manager has been closed.
108
+ */
109
+ setDeviceId(deviceId?: string | undefined | null): void
110
+ /** Set billable and Moss-owned telemetry identity together. */
111
+ setIdentity(deviceId?: string | undefined | null, userId?: string | undefined | null, mossDeviceId?: string | undefined | null): void
112
+ loadIndex(indexName: string, options?: LoadIndexOptions | null): Promise<IndexInfo>
113
+ unloadIndex(indexName: string): Promise<void>
114
+ /**
115
+ * Best-effort bulk load. Per-name failures are reported in `failed` and do
116
+ * not roll back indexes that loaded; `options` apply to the whole batch.
117
+ */
118
+ loadIndexes(indexNames: Array<string>, options?: LoadIndexOptions | null): Promise<LoadIndexesResult>
119
+ /** Best-effort bulk unload; names that are not loaded are ignored. */
120
+ unloadIndexes(indexNames: Array<string>): Promise<void>
121
+ hasIndex(indexName: string): Promise<boolean>
122
+ query(indexName: string, query: string, queryEmbedding: Array<number>, topK?: number, alpha?: number, filter?: object): Promise<SearchResult>
123
+ queryText(indexName: string, query: string, topK?: number, alpha?: number, filter?: object): Promise<SearchResult>
124
+ /**
125
+ * Multi-index search with a caller-supplied query embedding. Every name
126
+ * must be loaded and share one embedding model; results carry `indexName`.
127
+ * `alpha` works as in `query`: 1.0 embedding-only (raw cosine scores),
128
+ * 0.0 keyword-only, in between hybrid via RRF. Defaults: topK 10, alpha 0.8.
129
+ */
130
+ queryMultiIndex(indexNames: Array<string>, query: string, queryEmbedding: Array<number>, topK?: number, alpha?: number, filter?: object): Promise<SearchResult>
131
+ /**
132
+ * Multi-index search where the core embeds the query text. Same contract as
133
+ * `queryMultiIndex`. With `alpha` above 0 the core embeds the query, which needs
134
+ * builtin-model indexes with an exact artifact identity; `alpha` 0 skips
135
+ * embedding and also works for custom-model and identity-less indexes.
136
+ */
137
+ queryMultiIndexText(indexNames: Array<string>, query: string, topK?: number, alpha?: number, filter?: object): Promise<SearchResult>
138
+ loadQueryModel(indexName: string): Promise<void>
139
+ refreshIndex(indexName: string): Promise<RefreshResult>
140
+ getIndexInfo(indexName: string): Promise<IndexInfo>
141
+ /**
142
+ * Release the manager's native resources: aborts index pollers and
143
+ * starts a final telemetry flush via the core Drop (fire-and-forget,
144
+ * not awaited by this promise). In-flight calls that already
145
+ * hold the manager finish normally; the memory is freed when the
146
+ * last one completes. Idempotent. The process-wide shared runtime
147
+ * is unaffected.
148
+ */
149
+ close(): Promise<void>
150
+ }
151
+ export type JsIndexManager = IndexManager
152
+
153
+ /** Rust-backed cloud orchestration client for index mutations and metadata operations. */
154
+ export declare class ManageClient {
155
+ constructor(projectId: string, projectKey: string, baseUrl?: string | null)
156
+ /**
157
+ * Creates a ManageClient that delegates authentication to a JS `IAuthenticator`.
158
+ *
159
+ * `notifyFn` is a JS function `(requestId: number) => void`. When Rust needs a token,
160
+ * it calls this function with a unique `requestId`. The JS side must then call
161
+ * `authenticator.getAuthHeader()` and pass the result to `resolveAuthRequest(requestId, token)`
162
+ * or `rejectAuthRequest(requestId, error)`.
163
+ *
164
+ * `baseUrl` overrides the default cloud API endpoint — useful for testing against a local server.
165
+ */
166
+ static withAuthenticator(projectId: string, notifyFn: (err: Error | null, requestId: number) => void, baseUrl?: string | null): ManageClient
167
+ createIndex(name: string, docs: Array<DocumentInfo>, modelId: string, onProgress?: (progress: JobProgress) => void): Promise<MutationResult>
168
+ createIndexFromFiles(name: string, files: Array<ParseFileInput>, modelId: string, onProgress?: (progress: JobProgress) => void, parseOptions?: ParseOptions | null): Promise<MutationResult>
169
+ addDocs(name: string, docs: Array<DocumentInfo>, options?: MutationOptions | null, onProgress?: (progress: JobProgress) => void): Promise<MutationResult>
170
+ deleteDocs(name: string, docIds: Array<string>, onProgress?: (progress: JobProgress) => void): Promise<MutationResult>
171
+ getJobStatus(jobId: string): Promise<JobStatusResponse>
172
+ getIndex(name: string): Promise<IndexInfo>
173
+ listIndexes(): Promise<Array<IndexInfo>>
174
+ deleteIndex(name: string): Promise<boolean>
175
+ getDocs(name: string, options?: GetDocumentsOptions | null): Promise<Array<DocumentInfo>>
176
+ }
177
+ export type JsManageClient = ManageClient
178
+
179
+ /**
180
+ * Local-first session index backed by `moss::session::SessionIndex`.
181
+ *
182
+ * Holds documents + embeddings in process memory, supports
183
+ * add/delete/get/query without a network round-trip, and can push the
184
+ * resulting index to the cloud or persist to disk for offline reuse.
185
+ *
186
+ * Mirrors the Python `SessionIndex` surface 1:1 — see the
187
+ * `moss` (Python) SDK docs for the full semantic model.
188
+ */
189
+ export declare class SessionIndex {
190
+ static modelArtifactContractVersion(): number
191
+ /**
192
+ * Create a session for `name`. The session is empty until
193
+ * `addDocuments` / `addDocumentsText` populates it, or `loadIndex`
194
+ * pulls an existing cloud index into it.
195
+ *
196
+ * `moss::session::SessionIndex::new` validates credentials against
197
+ * the cloud synchronously and explicitly refuses to run inside any
198
+ * tokio runtime context. Exposing this as `#[napi(factory)] async`
199
+ * (rather than `#[napi(constructor)]`) plus dispatching the work
200
+ * to a fresh OS thread keeps the Node main thread responsive: the
201
+ * caller sees a `Promise`, and the blocking cloud call runs in
202
+ * truly-isolated thread space.
203
+ * `artifactVersion` and `manifestSha256` must be supplied together or both omitted.
204
+ */
205
+ static create(name: string, modelId: string, projectId: string, projectKey: string, clientId?: string | null, artifactVersion?: string | null, manifestSha256?: string | null): Promise<SessionIndex>
206
+ /**
207
+ * Create a session that delegates authentication to a JS `IAuthenticator`,
208
+ * mirroring `IndexManager.withAuthenticator`. Credential validation on
209
+ * open, `pushIndex`, `loadIndex`, and usage telemetry all authenticate
210
+ * via `notifyFn` rather than a static project key — so a custom-auth
211
+ * client (short-lived JWTs, no project key on device) can use sessions.
212
+ *
213
+ * `notifyFn` is a JS function `(err, requestId) => void`. When Rust needs
214
+ * a token it calls `notifyFn` with a unique `requestId`; the JS side must
215
+ * call `resolveAuthRequest(requestId, token)` or
216
+ * `rejectAuthRequest(requestId, error)`. `baseUrl` overrides the default
217
+ * cloud endpoint.
218
+ * `artifactVersion` and `manifestSha256` must be supplied together or both omitted.
219
+ */
220
+ static withAuthenticator(name: string, modelId: string, projectId: string, notifyFn: (err: Error | null, requestId: number) => void, baseUrl?: string | null, clientId?: string | null, artifactVersion?: string | null, manifestSha256?: string | null): Promise<SessionIndex>
221
+ /** Number of documents currently in the session. */
222
+ get docCount(): number
223
+ /**
224
+ * Session index name. Identifies the cloud index when `pushIndex` /
225
+ * `loadIndex` is called.
226
+ */
227
+ get name(): string
228
+ /**
229
+ * Embedding model id this session is configured for
230
+ * (`"moss-minilm"`, `"moss-mediumlm"`, `"moss-litelm"`, or `"custom"`).
231
+ */
232
+ get modelId(): string
233
+ /**
234
+ * Set the stable per-device identifier emitted as `deviceId` on every
235
+ * telemetry event. No-op when telemetry is disabled for this session,
236
+ * or when the session has been closed.
237
+ */
238
+ setDeviceId(deviceId?: string | undefined | null): void
239
+ /** Set billable and Moss-owned telemetry identity together. */
240
+ setIdentity(deviceId?: string | undefined | null, userId?: string | undefined | null, mossDeviceId?: string | undefined | null): void
241
+ /**
242
+ * Add or upsert documents with precomputed embeddings.
243
+ *
244
+ * Embeddings must be supplied in the same order as `docs`. For
245
+ * `modelId = "custom"` this is the only ingest path.
246
+ */
247
+ addDocuments(docs: Array<DocumentInfo>, embeddings: Array<Array<number>>, options?: AddDocumentsOptions | null): SessionUpdateResult
248
+ /**
249
+ * Add or upsert documents using the session's bundled embedding model
250
+ * to compute embeddings locally. The model is loaded on demand on the
251
+ * first call (or the first `queryText`); call `loadModel()` upfront
252
+ * to pre-warm and move that cost out of the latency-sensitive path.
253
+ * Rejects when `modelId = "custom"` — use `addDocuments` with
254
+ * precomputed vectors in that case.
255
+ */
256
+ addDocumentsText(docs: Array<DocumentInfo>, options?: AddDocumentsOptions | null): SessionUpdateResult
257
+ /**
258
+ * Remove documents by id. Returns the number of documents removed
259
+ * (may be less than `docIds.length` if some ids weren't present).
260
+ */
261
+ deleteDocuments(docIds: Array<string>): number
262
+ /**
263
+ * Fetch documents currently in the session. With `options.docIds`
264
+ * returns matching documents; without, returns all.
265
+ */
266
+ getDocuments(options?: GetDocumentsOptions | null): Array<DocumentInfo>
267
+ /**
268
+ * Hybrid (keyword + semantic) search over the session, using a
269
+ * precomputed query embedding. `alpha` blends sparse (0.0) and
270
+ * dense (1.0) scores; defaults to 0.8.
271
+ */
272
+ query(query: string, topK: number, queryEmbedding: Array<number>, alpha?: number | null, filter?: object | null): SearchResult
273
+ /**
274
+ * Same as `query` but computes the query embedding locally using
275
+ * the session's bundled model. The model is loaded on demand on the
276
+ * first call; `loadModel()` is available as an optional pre-warm.
277
+ * Rejects on `modelId = "custom"`.
278
+ */
279
+ queryText(query: string, topK: number, alpha?: number | null, filter?: object | null): SearchResult
280
+ /**
281
+ * Pre-download and initialize the embedding model. Optional — the
282
+ * session calls this lazily on the first `addDocumentsText` /
283
+ * `queryText`, but invoking it upfront moves the cold start out of
284
+ * the latency-sensitive path. No-op for `modelId = "custom"`.
285
+ */
286
+ loadModel(): void
287
+ /**
288
+ * Load an existing cloud index into the session by name.
289
+ *
290
+ * With `options.autoRefresh = true`, a background poller pulls
291
+ * newer cloud versions in on the next read at the configured
292
+ * interval (default 600 s). The poller pauses while the session
293
+ * has un-pushed local edits, so local additions are never
294
+ * clobbered.
295
+ *
296
+ * Returns the number of documents loaded into the session.
297
+ */
298
+ loadIndex(indexName: string, options?: LoadSessionOptions | null): Promise<number>
299
+ /**
300
+ * Upload the session contents to the cloud, creating or replacing
301
+ * the index with the same name. Documents are pushed with their
302
+ * locally-computed embeddings — no server-side re-embedding.
303
+ */
304
+ pushIndex(): Promise<PushIndexResult>
305
+ /**
306
+ * Persist the session beneath `<cachePath>/<name>/` using the core's
307
+ * crash-safe generation format. A failure or interruption before
308
+ * publication leaves the previously committed snapshot loadable; restore it
309
+ * without a cloud round-trip via `loadFromDisk`.
310
+ */
311
+ saveToDisk(cachePath: string): void
312
+ /**
313
+ * Restore the committed snapshot previously written by `saveToDisk` from
314
+ * `<cachePath>/<name>/`. The snapshot is validated before the live session
315
+ * changes; corruption rejects the call and leaves current state intact.
316
+ * Returns the number of documents loaded.
317
+ */
318
+ loadFromDisk(cachePath: string): number
319
+ /**
320
+ * Release the session's native resources now instead of waiting for
321
+ * GC: aborts the auto-refresh poller, starts a final telemetry flush
322
+ * (fire-and-forget, not awaited by this promise), and drops the
323
+ * index plus its shared embedding-model reference. Idempotent.
324
+ * Afterwards `name` and `modelId` still read, `setDeviceId` is a no-op, and every
325
+ * other method fails with "SessionIndex is closed". The process-wide
326
+ * shared runtime is unaffected.
327
+ *
328
+ * Async so the core Drop runs inside the runtime context and takes
329
+ * its non-blocking telemetry path instead of blocking the JS thread.
330
+ */
331
+ close(): Promise<void>
332
+ }
333
+ export type JsSessionIndex = SessionIndex
334
+
335
+ /** Options controlling how documents are written into the index. */
336
+ export interface AddDocumentsOptions {
337
+ /** When true, existing documents with the same ID will be updated (default true). */
338
+ upsert: boolean
339
+ }
340
+
341
+ /** Auth token endpoint — POST projectId + projectKey, receive JWT. */
342
+ export const CLOUD_API_AUTH_URL: string
343
+
344
+ /** Base URL for the Moss identity service. */
345
+ export const CLOUD_API_IDENTITY_URL: string
346
+
347
+ /** Base URL for the Moss index management service. */
348
+ export const CLOUD_API_INDEX_URL: string
349
+
350
+ /** Query endpoint for the Moss query service. */
351
+ export const CLOUD_QUERY_URL: string
352
+
353
+ /**
354
+ * Deserialize Moss binary data into a JsSerializedIndex object.
355
+ *
356
+ * @param blob - A Uint8Array view containing the binary data.
357
+ * @returns The deserialized SerializedIndex object.
358
+ */
359
+ export declare function deserializeFromBinary(blob: Uint8Array): SerializedIndex
360
+
361
+ /** Document payload that can be indexed and later retrieved. */
362
+ export interface DocumentInfo {
363
+ /** Unique identifier within the index. */
364
+ id: string
365
+ /** Canonical text content used for embedding generation. */
366
+ text: string
367
+ /** Optional metadata map persisted alongside the document. */
368
+ metadata?: Record<string, string>
369
+ /** Optional precomputed embedding vector (f64 for JS compatibility). */
370
+ embedding?: Array<number>
371
+ /**
372
+ * Optional opaque structured payload (e.g. a JSON string), stored
373
+ * verbatim and returned as-is — never embedded or searched.
374
+ */
375
+ payload?: string
376
+ }
377
+
378
+ /** Optional filters when retrieving documents from an index. */
379
+ export interface GetDocumentsOptions {
380
+ /** List of document IDs to fetch; omitted returns all documents. */
381
+ docIds?: Array<string>
382
+ }
383
+
384
+ /** Information about a persisted index including status and model metadata. */
385
+ export interface IndexInfo {
386
+ /** Unique identifier of the index. */
387
+ id: string
388
+ /** Human-readable index name. */
389
+ name: string
390
+ /** Index build or schema version string. */
391
+ version?: string
392
+ /** Current lifecycle status of the index build. */
393
+ status: IndexStatus
394
+ /** Number of documents stored in the index. */
395
+ docCount: number
396
+ /** RFC 3339 timestamp indicating when the index was created. */
397
+ createdAt?: string
398
+ /** RFC 3339 timestamp indicating the last update time. */
399
+ updatedAt?: string
400
+ /** Embedding model details bound to the index. */
401
+ model: ModelRef
402
+ }
403
+
404
+ /** Lifecycle status for background index creation processes. */
405
+ export declare const enum IndexStatus {
406
+ NotStarted = 'NotStarted',
407
+ Building = 'Building',
408
+ Ready = 'Ready',
409
+ Failed = 'Failed'
410
+ }
411
+
412
+ /**
413
+ * A simple struct to return the added/updated counts to JS,
414
+ * since JS doesn't support tuples.
415
+ */
416
+ export interface IndexUpdateResult {
417
+ added: number
418
+ updated: number
419
+ }
420
+
421
+ /** Job phase for async cloud operations. */
422
+ export declare const enum JobPhase {
423
+ Downloading = 'downloading',
424
+ Deserializing = 'deserializing',
425
+ GeneratingEmbeddings = 'generating_embeddings',
426
+ BuildingIndex = 'building_index',
427
+ Uploading = 'uploading',
428
+ Cleanup = 'cleanup',
429
+ WaitingForParser = 'waiting_for_parser',
430
+ Parsing = 'parsing',
431
+ ParsingComplete = 'parsing_complete',
432
+ Queued = 'queued',
433
+ Crawling = 'crawling',
434
+ ParsingDocuments = 'parsing_documents'
435
+ }
436
+
437
+ /** Progress update for async cloud operations. */
438
+ export interface JobProgress {
439
+ jobId: string
440
+ status: JobStatus
441
+ progress: number
442
+ currentPhase?: JobPhase
443
+ }
444
+
445
+ /** Job status for async cloud operations. */
446
+ export declare const enum JobStatus {
447
+ PendingUpload = 'pending_upload',
448
+ Uploading = 'uploading',
449
+ Building = 'building',
450
+ Completed = 'completed',
451
+ Failed = 'failed'
452
+ }
453
+
454
+ /** Status payload for a long-running async job. */
455
+ export interface JobStatusResponse {
456
+ jobId: string
457
+ status: JobStatus
458
+ progress: number
459
+ currentPhase?: JobPhase
460
+ error?: string
461
+ createdAt: string
462
+ updatedAt: string
463
+ completedAt?: string
464
+ }
465
+
466
+ /** Outcome of a best-effort bulk `loadIndexes` call. */
467
+ export interface LoadIndexesResult {
468
+ /** Names of indexes that were successfully loaded into memory. */
469
+ loaded: Array<string>
470
+ /** Names that failed to load, mapping name to error message. */
471
+ failed: Record<string, string>
472
+ }
473
+
474
+ /** Options for loading an index with auto-refresh configuration. */
475
+ export interface LoadIndexOptions {
476
+ /** Enable auto-refresh polling for this index. */
477
+ autoRefresh?: boolean
478
+ /** Polling interval in seconds (default: 600 / 10 minutes). */
479
+ pollingIntervalInSeconds?: number
480
+ /** Optional filesystem path for caching index data to disk. */
481
+ cachePath?: string
482
+ }
483
+
484
+ export interface LoadSessionOptions {
485
+ /**
486
+ * If `true`, the SDK starts a background poller that pulls newer cloud
487
+ * versions of this index into the session at the configured interval.
488
+ * Paused automatically while the session has un-pushed local edits.
489
+ */
490
+ autoRefresh?: boolean
491
+ /**
492
+ * Poll interval in seconds (default 600 = 10 minutes). Only consulted
493
+ * when `autoRefresh` is `true`.
494
+ */
495
+ pollingIntervalInSeconds?: number
496
+ }
497
+
498
+ /** Public CDN endpoint for downloading Moss embedding models locally. */
499
+ export const MODEL_DOWNLOAD_URL: string
500
+
501
+ /** Reference to the embedding model powering a Moss index. */
502
+ export interface ModelRef {
503
+ /** Model identifier string. */
504
+ id: string
505
+ /** Semantic version or build identifier of the model. */
506
+ version?: string
507
+ }
508
+
509
+ /** Options for async mutation operations. */
510
+ export interface MutationOptions {
511
+ upsert?: boolean
512
+ }
513
+
514
+ /** Completed result from an async mutation operation. */
515
+ export interface MutationResult {
516
+ jobId: string
517
+ indexName: string
518
+ docCount: number
519
+ }
520
+
521
+ /** Input descriptor for a single file in the parse pipeline. */
522
+ export interface ParseFileInput {
523
+ /** File identifier sent to the server. Required. */
524
+ name: string
525
+ /** MIME type (e.g. "application/pdf"). Required. */
526
+ contentType: string
527
+ /** Filesystem path to the file. Required when `data` is not provided. */
528
+ path?: string
529
+ /** Raw file bytes. Takes precedence over `path` when provided. */
530
+ data?: Array<number>
531
+ }
532
+
533
+ /**
534
+ * Options controlling how the server parses uploaded documents.
535
+ *
536
+ * Every field is optional; omitted fields use the parsing service defaults.
537
+ * Use `ocrMode: "full_ocr"` for scanned documents with no text layer.
538
+ */
539
+ export interface ParseOptions {
540
+ /** Slower, higher fidelity extraction. Useful for dense tables. */
541
+ useHighResolution?: boolean
542
+ /** "smart_layout_detection" or "page_by_page". */
543
+ segmentationMethod?: string
544
+ /** "auto_ocr" or "full_ocr". */
545
+ ocrMode?: string
546
+ /** Merge tables spanning a page break into one segment. */
547
+ mergeTables?: boolean
548
+ }
549
+
550
+ export interface PushIndexResult {
551
+ jobId: string
552
+ indexName: string
553
+ docCount: number
554
+ status: string
555
+ }
556
+
557
+ /** Options for query operations. */
558
+ export interface QueryOptions {
559
+ /** Caller-provided embedding vector. When supplied, skips embedding generation. */
560
+ embedding?: Array<number>
561
+ /** Number of top results to return. */
562
+ topK?: number
563
+ /** Weight for hybrid search fusion (0.0 to 1.0). Default 0.8. */
564
+ alpha?: number
565
+ /** Optional metadata filter for narrowing results. */
566
+ filter?: any
567
+ }
568
+
569
+ /** Document returned from a query with similarity metadata. */
570
+ export interface QueryResultDocumentInfo {
571
+ /** Document identifier. */
572
+ id: string
573
+ /** Original document text. */
574
+ text: string
575
+ /** Optional metadata associated with the document. */
576
+ metadata?: Record<string, string>
577
+ /** Similarity score between 0 and 1 (higher is more relevant). */
578
+ score: number
579
+ /** Optional opaque payload stored with the document, returned as-is. */
580
+ payload?: string
581
+ /** Source index name. Set on `queryMultiIndex` results; absent for single-index queries. */
582
+ indexName?: string
583
+ }
584
+
585
+ /** Result of an index refresh operation. */
586
+ export interface RefreshResult {
587
+ /** Name of the index that was refreshed. */
588
+ indexName: string
589
+ /** Timestamp before the refresh operation. */
590
+ previousUpdatedAt: string
591
+ /** Timestamp after the refresh operation. */
592
+ newUpdatedAt: string
593
+ /** Whether the index was actually updated (true if cloud had newer version). */
594
+ wasUpdated: boolean
595
+ }
596
+
597
+ /** Called by JS to reject a pending auth request. */
598
+ export declare function rejectAuthRequest(requestId: number, error: string): void
599
+
600
+ /**
601
+ * Called by JS to resolve a pending auth request.
602
+ * `token` should be the raw token string — `JsAuthBridge` adds the "Bearer " prefix.
603
+ */
604
+ export declare function resolveAuthRequest(requestId: number, token: string): void
605
+
606
+ /** Version of the published `@moss-js/moss-core` package, matching its `package.json`. */
607
+ export const SDK_VERSION_NUMBER: string
608
+
609
+ /** Result payload returned by a semantic query operation. */
610
+ export interface SearchResult {
611
+ /** Matching documents ordered by similarity. */
612
+ docs: Array<QueryResultDocumentInfo>
613
+ /** Original query string for reference. */
614
+ query: string
615
+ /** Optional index name when available. */
616
+ indexName?: string
617
+ /** Optional execution time in milliseconds. */
618
+ timeTakenInMs?: number
619
+ }
620
+
621
+ /** Complete serialized representation of an index for `.moss` file storage. */
622
+ export interface SerializedIndex {
623
+ /** Name of the index. */
624
+ name: string
625
+ /** Index build or format version. */
626
+ version: string
627
+ /** Associated embedding model metadata. */
628
+ model: ModelRef
629
+ /** Dimensionality of each embedding vector. */
630
+ dimension: number
631
+ /** Embedding vectors stored row-wise. */
632
+ embeddings: Array<Array<number>>
633
+ /** Document identifiers parallel to the embeddings array. */
634
+ docIds: Array<string>
635
+ envelope?: SerializedIndexEnvelope
636
+ }
637
+
638
+ export interface SerializedIndexEnvelope {
639
+ /** Serialized envelope schema version. */
640
+ version: number
641
+ /** Exact immutable model artifact version, paired with `manifestSha256`. */
642
+ modelArtifactVersion?: string
643
+ /** Lowercase SHA-256 of the authoritative artifact manifest. */
644
+ manifestSha256?: string
645
+ }
646
+
647
+ /**
648
+ * Serialize a JsSerializedIndex object into a binary Buffer (.moss file format).
649
+ *
650
+ * @param index - The index object to serialize.
651
+ * @returns A Node.js Buffer containing the binary data.
652
+ */
653
+ export declare function serializeToBinary(index: SerializedIndex): Buffer
654
+
655
+ export interface SessionUpdateResult {
656
+ added: number
657
+ updated: number
658
+ }
package/index.js ADDED
@@ -0,0 +1,601 @@
1
+ // prettier-ignore
2
+ /* eslint-disable */
3
+ // @ts-nocheck
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ const { readFileSync } = require('node:fs')
7
+ let nativeBinding = null
8
+ const loadErrors = []
9
+
10
+ const isMusl = () => {
11
+ let musl = false
12
+ if (process.platform === 'linux') {
13
+ musl = isMuslFromFilesystem()
14
+ if (musl === null) {
15
+ musl = isMuslFromReport()
16
+ }
17
+ if (musl === null) {
18
+ musl = isMuslFromChildProcess()
19
+ }
20
+ }
21
+ return musl
22
+ }
23
+
24
+ const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
25
+
26
+ const isMuslFromFilesystem = () => {
27
+ try {
28
+ return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
29
+ } catch {
30
+ return null
31
+ }
32
+ }
33
+
34
+ const isMuslFromReport = () => {
35
+ let report = null
36
+ if (typeof process.report?.getReport === 'function') {
37
+ process.report.excludeNetwork = true
38
+ report = process.report.getReport()
39
+ }
40
+ if (!report) {
41
+ return null
42
+ }
43
+ if (report.header && report.header.glibcVersionRuntime) {
44
+ return false
45
+ }
46
+ if (Array.isArray(report.sharedObjects)) {
47
+ if (report.sharedObjects.some(isFileMusl)) {
48
+ return true
49
+ }
50
+ }
51
+ return false
52
+ }
53
+
54
+ const isMuslFromChildProcess = () => {
55
+ try {
56
+ return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
57
+ } catch (e) {
58
+ // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
59
+ return false
60
+ }
61
+ }
62
+
63
+ function requireNative() {
64
+ if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
65
+ try {
66
+ return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
67
+ } catch (err) {
68
+ loadErrors.push(err)
69
+ }
70
+ } else if (process.platform === 'android') {
71
+ if (process.arch === 'arm64') {
72
+ try {
73
+ return require('./js-binding.android-arm64.node')
74
+ } catch (e) {
75
+ loadErrors.push(e)
76
+ }
77
+ try {
78
+ const binding = require('@moss-js/moss-core-android-arm64')
79
+ const bindingPackageVersion = require('@moss-js/moss-core-android-arm64/package.json').version
80
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
81
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
82
+ }
83
+ return binding
84
+ } catch (e) {
85
+ loadErrors.push(e)
86
+ }
87
+ } else if (process.arch === 'arm') {
88
+ try {
89
+ return require('./js-binding.android-arm-eabi.node')
90
+ } catch (e) {
91
+ loadErrors.push(e)
92
+ }
93
+ try {
94
+ const binding = require('@moss-js/moss-core-android-arm-eabi')
95
+ const bindingPackageVersion = require('@moss-js/moss-core-android-arm-eabi/package.json').version
96
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
97
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
98
+ }
99
+ return binding
100
+ } catch (e) {
101
+ loadErrors.push(e)
102
+ }
103
+ } else {
104
+ loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
105
+ }
106
+ } else if (process.platform === 'win32') {
107
+ if (process.arch === 'x64') {
108
+ if (process.config?.variables?.shlib_suffix === 'dll.a' || process.config?.variables?.node_target_type === 'shared_library') {
109
+ try {
110
+ return require('./js-binding.win32-x64-gnu.node')
111
+ } catch (e) {
112
+ loadErrors.push(e)
113
+ }
114
+ try {
115
+ const binding = require('@moss-js/moss-core-win32-x64-gnu')
116
+ const bindingPackageVersion = require('@moss-js/moss-core-win32-x64-gnu/package.json').version
117
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
118
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
119
+ }
120
+ return binding
121
+ } catch (e) {
122
+ loadErrors.push(e)
123
+ }
124
+ } else {
125
+ try {
126
+ return require('./js-binding.win32-x64-msvc.node')
127
+ } catch (e) {
128
+ loadErrors.push(e)
129
+ }
130
+ try {
131
+ const binding = require('@moss-js/moss-core-win32-x64-msvc')
132
+ const bindingPackageVersion = require('@moss-js/moss-core-win32-x64-msvc/package.json').version
133
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
134
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
135
+ }
136
+ return binding
137
+ } catch (e) {
138
+ loadErrors.push(e)
139
+ }
140
+ }
141
+ } else if (process.arch === 'ia32') {
142
+ try {
143
+ return require('./js-binding.win32-ia32-msvc.node')
144
+ } catch (e) {
145
+ loadErrors.push(e)
146
+ }
147
+ try {
148
+ const binding = require('@moss-js/moss-core-win32-ia32-msvc')
149
+ const bindingPackageVersion = require('@moss-js/moss-core-win32-ia32-msvc/package.json').version
150
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
151
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
152
+ }
153
+ return binding
154
+ } catch (e) {
155
+ loadErrors.push(e)
156
+ }
157
+ } else if (process.arch === 'arm64') {
158
+ try {
159
+ return require('./js-binding.win32-arm64-msvc.node')
160
+ } catch (e) {
161
+ loadErrors.push(e)
162
+ }
163
+ try {
164
+ const binding = require('@moss-js/moss-core-win32-arm64-msvc')
165
+ const bindingPackageVersion = require('@moss-js/moss-core-win32-arm64-msvc/package.json').version
166
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
167
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
168
+ }
169
+ return binding
170
+ } catch (e) {
171
+ loadErrors.push(e)
172
+ }
173
+ } else {
174
+ loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
175
+ }
176
+ } else if (process.platform === 'darwin') {
177
+ try {
178
+ return require('./js-binding.darwin-universal.node')
179
+ } catch (e) {
180
+ loadErrors.push(e)
181
+ }
182
+ try {
183
+ const binding = require('@moss-js/moss-core-darwin-universal')
184
+ const bindingPackageVersion = require('@moss-js/moss-core-darwin-universal/package.json').version
185
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
186
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
187
+ }
188
+ return binding
189
+ } catch (e) {
190
+ loadErrors.push(e)
191
+ }
192
+ if (process.arch === 'x64') {
193
+ try {
194
+ return require('./js-binding.darwin-x64.node')
195
+ } catch (e) {
196
+ loadErrors.push(e)
197
+ }
198
+ try {
199
+ const binding = require('@moss-js/moss-core-darwin-x64')
200
+ const bindingPackageVersion = require('@moss-js/moss-core-darwin-x64/package.json').version
201
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
202
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
203
+ }
204
+ return binding
205
+ } catch (e) {
206
+ loadErrors.push(e)
207
+ }
208
+ } else if (process.arch === 'arm64') {
209
+ try {
210
+ return require('./js-binding.darwin-arm64.node')
211
+ } catch (e) {
212
+ loadErrors.push(e)
213
+ }
214
+ try {
215
+ const binding = require('@moss-js/moss-core-darwin-arm64')
216
+ const bindingPackageVersion = require('@moss-js/moss-core-darwin-arm64/package.json').version
217
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
218
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
219
+ }
220
+ return binding
221
+ } catch (e) {
222
+ loadErrors.push(e)
223
+ }
224
+ } else {
225
+ loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
226
+ }
227
+ } else if (process.platform === 'freebsd') {
228
+ if (process.arch === 'x64') {
229
+ try {
230
+ return require('./js-binding.freebsd-x64.node')
231
+ } catch (e) {
232
+ loadErrors.push(e)
233
+ }
234
+ try {
235
+ const binding = require('@moss-js/moss-core-freebsd-x64')
236
+ const bindingPackageVersion = require('@moss-js/moss-core-freebsd-x64/package.json').version
237
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
238
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
239
+ }
240
+ return binding
241
+ } catch (e) {
242
+ loadErrors.push(e)
243
+ }
244
+ } else if (process.arch === 'arm64') {
245
+ try {
246
+ return require('./js-binding.freebsd-arm64.node')
247
+ } catch (e) {
248
+ loadErrors.push(e)
249
+ }
250
+ try {
251
+ const binding = require('@moss-js/moss-core-freebsd-arm64')
252
+ const bindingPackageVersion = require('@moss-js/moss-core-freebsd-arm64/package.json').version
253
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
254
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
255
+ }
256
+ return binding
257
+ } catch (e) {
258
+ loadErrors.push(e)
259
+ }
260
+ } else {
261
+ loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
262
+ }
263
+ } else if (process.platform === 'linux') {
264
+ if (process.arch === 'x64') {
265
+ if (isMusl()) {
266
+ try {
267
+ return require('./js-binding.linux-x64-musl.node')
268
+ } catch (e) {
269
+ loadErrors.push(e)
270
+ }
271
+ try {
272
+ const binding = require('@moss-js/moss-core-linux-x64-musl')
273
+ const bindingPackageVersion = require('@moss-js/moss-core-linux-x64-musl/package.json').version
274
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
275
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
276
+ }
277
+ return binding
278
+ } catch (e) {
279
+ loadErrors.push(e)
280
+ }
281
+ } else {
282
+ try {
283
+ return require('./js-binding.linux-x64-gnu.node')
284
+ } catch (e) {
285
+ loadErrors.push(e)
286
+ }
287
+ try {
288
+ const binding = require('@moss-js/moss-core-linux-x64-gnu')
289
+ const bindingPackageVersion = require('@moss-js/moss-core-linux-x64-gnu/package.json').version
290
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
291
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
292
+ }
293
+ return binding
294
+ } catch (e) {
295
+ loadErrors.push(e)
296
+ }
297
+ }
298
+ } else if (process.arch === 'arm64') {
299
+ if (isMusl()) {
300
+ try {
301
+ return require('./js-binding.linux-arm64-musl.node')
302
+ } catch (e) {
303
+ loadErrors.push(e)
304
+ }
305
+ try {
306
+ const binding = require('@moss-js/moss-core-linux-arm64-musl')
307
+ const bindingPackageVersion = require('@moss-js/moss-core-linux-arm64-musl/package.json').version
308
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
309
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
310
+ }
311
+ return binding
312
+ } catch (e) {
313
+ loadErrors.push(e)
314
+ }
315
+ } else {
316
+ try {
317
+ return require('./js-binding.linux-arm64-gnu.node')
318
+ } catch (e) {
319
+ loadErrors.push(e)
320
+ }
321
+ try {
322
+ const binding = require('@moss-js/moss-core-linux-arm64-gnu')
323
+ const bindingPackageVersion = require('@moss-js/moss-core-linux-arm64-gnu/package.json').version
324
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
325
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
326
+ }
327
+ return binding
328
+ } catch (e) {
329
+ loadErrors.push(e)
330
+ }
331
+ }
332
+ } else if (process.arch === 'arm') {
333
+ if (isMusl()) {
334
+ try {
335
+ return require('./js-binding.linux-arm-musleabihf.node')
336
+ } catch (e) {
337
+ loadErrors.push(e)
338
+ }
339
+ try {
340
+ const binding = require('@moss-js/moss-core-linux-arm-musleabihf')
341
+ const bindingPackageVersion = require('@moss-js/moss-core-linux-arm-musleabihf/package.json').version
342
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
343
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
344
+ }
345
+ return binding
346
+ } catch (e) {
347
+ loadErrors.push(e)
348
+ }
349
+ } else {
350
+ try {
351
+ return require('./js-binding.linux-arm-gnueabihf.node')
352
+ } catch (e) {
353
+ loadErrors.push(e)
354
+ }
355
+ try {
356
+ const binding = require('@moss-js/moss-core-linux-arm-gnueabihf')
357
+ const bindingPackageVersion = require('@moss-js/moss-core-linux-arm-gnueabihf/package.json').version
358
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
359
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
360
+ }
361
+ return binding
362
+ } catch (e) {
363
+ loadErrors.push(e)
364
+ }
365
+ }
366
+ } else if (process.arch === 'loong64') {
367
+ if (isMusl()) {
368
+ try {
369
+ return require('./js-binding.linux-loong64-musl.node')
370
+ } catch (e) {
371
+ loadErrors.push(e)
372
+ }
373
+ try {
374
+ const binding = require('@moss-js/moss-core-linux-loong64-musl')
375
+ const bindingPackageVersion = require('@moss-js/moss-core-linux-loong64-musl/package.json').version
376
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
377
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
378
+ }
379
+ return binding
380
+ } catch (e) {
381
+ loadErrors.push(e)
382
+ }
383
+ } else {
384
+ try {
385
+ return require('./js-binding.linux-loong64-gnu.node')
386
+ } catch (e) {
387
+ loadErrors.push(e)
388
+ }
389
+ try {
390
+ const binding = require('@moss-js/moss-core-linux-loong64-gnu')
391
+ const bindingPackageVersion = require('@moss-js/moss-core-linux-loong64-gnu/package.json').version
392
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
393
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
394
+ }
395
+ return binding
396
+ } catch (e) {
397
+ loadErrors.push(e)
398
+ }
399
+ }
400
+ } else if (process.arch === 'riscv64') {
401
+ if (isMusl()) {
402
+ try {
403
+ return require('./js-binding.linux-riscv64-musl.node')
404
+ } catch (e) {
405
+ loadErrors.push(e)
406
+ }
407
+ try {
408
+ const binding = require('@moss-js/moss-core-linux-riscv64-musl')
409
+ const bindingPackageVersion = require('@moss-js/moss-core-linux-riscv64-musl/package.json').version
410
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
411
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
412
+ }
413
+ return binding
414
+ } catch (e) {
415
+ loadErrors.push(e)
416
+ }
417
+ } else {
418
+ try {
419
+ return require('./js-binding.linux-riscv64-gnu.node')
420
+ } catch (e) {
421
+ loadErrors.push(e)
422
+ }
423
+ try {
424
+ const binding = require('@moss-js/moss-core-linux-riscv64-gnu')
425
+ const bindingPackageVersion = require('@moss-js/moss-core-linux-riscv64-gnu/package.json').version
426
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
427
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
428
+ }
429
+ return binding
430
+ } catch (e) {
431
+ loadErrors.push(e)
432
+ }
433
+ }
434
+ } else if (process.arch === 'ppc64') {
435
+ try {
436
+ return require('./js-binding.linux-ppc64-gnu.node')
437
+ } catch (e) {
438
+ loadErrors.push(e)
439
+ }
440
+ try {
441
+ const binding = require('@moss-js/moss-core-linux-ppc64-gnu')
442
+ const bindingPackageVersion = require('@moss-js/moss-core-linux-ppc64-gnu/package.json').version
443
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
444
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
445
+ }
446
+ return binding
447
+ } catch (e) {
448
+ loadErrors.push(e)
449
+ }
450
+ } else if (process.arch === 's390x') {
451
+ try {
452
+ return require('./js-binding.linux-s390x-gnu.node')
453
+ } catch (e) {
454
+ loadErrors.push(e)
455
+ }
456
+ try {
457
+ const binding = require('@moss-js/moss-core-linux-s390x-gnu')
458
+ const bindingPackageVersion = require('@moss-js/moss-core-linux-s390x-gnu/package.json').version
459
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
460
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
461
+ }
462
+ return binding
463
+ } catch (e) {
464
+ loadErrors.push(e)
465
+ }
466
+ } else {
467
+ loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
468
+ }
469
+ } else if (process.platform === 'openharmony') {
470
+ if (process.arch === 'arm64') {
471
+ try {
472
+ return require('./js-binding.openharmony-arm64.node')
473
+ } catch (e) {
474
+ loadErrors.push(e)
475
+ }
476
+ try {
477
+ const binding = require('@moss-js/moss-core-openharmony-arm64')
478
+ const bindingPackageVersion = require('@moss-js/moss-core-openharmony-arm64/package.json').version
479
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
480
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
481
+ }
482
+ return binding
483
+ } catch (e) {
484
+ loadErrors.push(e)
485
+ }
486
+ } else if (process.arch === 'x64') {
487
+ try {
488
+ return require('./js-binding.openharmony-x64.node')
489
+ } catch (e) {
490
+ loadErrors.push(e)
491
+ }
492
+ try {
493
+ const binding = require('@moss-js/moss-core-openharmony-x64')
494
+ const bindingPackageVersion = require('@moss-js/moss-core-openharmony-x64/package.json').version
495
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
496
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
497
+ }
498
+ return binding
499
+ } catch (e) {
500
+ loadErrors.push(e)
501
+ }
502
+ } else if (process.arch === 'arm') {
503
+ try {
504
+ return require('./js-binding.openharmony-arm.node')
505
+ } catch (e) {
506
+ loadErrors.push(e)
507
+ }
508
+ try {
509
+ const binding = require('@moss-js/moss-core-openharmony-arm')
510
+ const bindingPackageVersion = require('@moss-js/moss-core-openharmony-arm/package.json').version
511
+ if (bindingPackageVersion !== '0.24.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
512
+ throw new Error(`Native binding package version mismatch, expected 0.24.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
513
+ }
514
+ return binding
515
+ } catch (e) {
516
+ loadErrors.push(e)
517
+ }
518
+ } else {
519
+ loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
520
+ }
521
+ } else {
522
+ loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
523
+ }
524
+ }
525
+
526
+ nativeBinding = requireNative()
527
+
528
+ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
529
+ let wasiBinding = null
530
+ let wasiBindingError = null
531
+ try {
532
+ wasiBinding = require('./js-binding.wasi.cjs')
533
+ nativeBinding = wasiBinding
534
+ } catch (err) {
535
+ if (process.env.NAPI_RS_FORCE_WASI) {
536
+ wasiBindingError = err
537
+ }
538
+ }
539
+ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
540
+ try {
541
+ wasiBinding = require('@moss-js/moss-core-wasm32-wasi')
542
+ nativeBinding = wasiBinding
543
+ } catch (err) {
544
+ if (process.env.NAPI_RS_FORCE_WASI) {
545
+ if (!wasiBindingError) {
546
+ wasiBindingError = err
547
+ } else {
548
+ wasiBindingError.cause = err
549
+ }
550
+ loadErrors.push(err)
551
+ }
552
+ }
553
+ }
554
+ if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) {
555
+ const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error')
556
+ error.cause = wasiBindingError
557
+ throw error
558
+ }
559
+ }
560
+
561
+ if (!nativeBinding) {
562
+ if (loadErrors.length > 0) {
563
+ throw new Error(
564
+ `Cannot find native binding. ` +
565
+ `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
566
+ 'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
567
+ {
568
+ cause: loadErrors.reduce((err, cur) => {
569
+ cur.cause = err
570
+ return cur
571
+ }),
572
+ },
573
+ )
574
+ }
575
+ throw new Error(`Failed to load native binding`)
576
+ }
577
+
578
+ module.exports = nativeBinding
579
+ module.exports.Index = nativeBinding.Index
580
+ module.exports.IndexManager = nativeBinding.IndexManager
581
+ module.exports.JsIndexManager = nativeBinding.JsIndexManager
582
+ module.exports.ManageClient = nativeBinding.ManageClient
583
+ module.exports.JsManageClient = nativeBinding.JsManageClient
584
+ module.exports.SessionIndex = nativeBinding.SessionIndex
585
+ module.exports.JsSessionIndex = nativeBinding.JsSessionIndex
586
+ module.exports.CLOUD_API_AUTH_URL = nativeBinding.CLOUD_API_AUTH_URL
587
+ module.exports.CLOUD_API_IDENTITY_URL = nativeBinding.CLOUD_API_IDENTITY_URL
588
+ module.exports.CLOUD_API_INDEX_URL = nativeBinding.CLOUD_API_INDEX_URL
589
+ module.exports.CLOUD_QUERY_URL = nativeBinding.CLOUD_QUERY_URL
590
+ module.exports.deserializeFromBinary = nativeBinding.deserializeFromBinary
591
+ module.exports.IndexStatus = nativeBinding.IndexStatus
592
+ module.exports.JsIndexStatus = nativeBinding.JsIndexStatus
593
+ module.exports.JobPhase = nativeBinding.JobPhase
594
+ module.exports.JsJobPhase = nativeBinding.JsJobPhase
595
+ module.exports.JobStatus = nativeBinding.JobStatus
596
+ module.exports.JsJobStatus = nativeBinding.JsJobStatus
597
+ module.exports.MODEL_DOWNLOAD_URL = nativeBinding.MODEL_DOWNLOAD_URL
598
+ module.exports.rejectAuthRequest = nativeBinding.rejectAuthRequest
599
+ module.exports.resolveAuthRequest = nativeBinding.resolveAuthRequest
600
+ module.exports.SDK_VERSION_NUMBER = nativeBinding.SDK_VERSION_NUMBER
601
+ module.exports.serializeToBinary = nativeBinding.serializeToBinary
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@moss-js/moss-core",
3
+ "version": "0.24.0",
4
+ "description": "Connects JS SDK to Rust Moss-Core using N-API",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./index.d.ts",
10
+ "require": "./index.js",
11
+ "default": "./index.js"
12
+ }
13
+ },
14
+ "repository": {
15
+ "type": "git"
16
+ },
17
+ "license": "Proprietary",
18
+ "keywords": [
19
+ "napi-rs",
20
+ "NAPI",
21
+ "N-API",
22
+ "Rust",
23
+ "node-addon",
24
+ "node-addon-api"
25
+ ],
26
+ "files": [
27
+ "index.d.ts",
28
+ "index.js",
29
+ "*.node",
30
+ "*.dylib",
31
+ "LICENSE-onnxruntime"
32
+ ],
33
+ "napi": {
34
+ "binaryName": "js-binding",
35
+ "targets": [
36
+ "x86_64-pc-windows-msvc",
37
+ "x86_64-unknown-linux-gnu",
38
+ "aarch64-unknown-linux-gnu",
39
+ "aarch64-apple-darwin",
40
+ "x86_64-apple-darwin"
41
+ ]
42
+ },
43
+ "engines": {
44
+ "node": ">=20"
45
+ },
46
+ "publishConfig": {
47
+ "registry": "https://registry.npmjs.org/",
48
+ "access": "public"
49
+ },
50
+ "scripts": {
51
+ "artifacts": "napi artifacts",
52
+ "build": "napi build --platform --release",
53
+ "build:release-surface": "napi build --platform --release --target-dir target/release-surface-build --output-dir target/release-surface",
54
+ "build:debug": "napi build --platform",
55
+ "format:rs": "cargo fmt",
56
+ "test:abi": "node test/parse-options-abi.mjs",
57
+ "version": "napi version"
58
+ },
59
+ "devDependencies": {
60
+ "@napi-rs/cli": "^3.2.0",
61
+ "@oxc-node/core": "^0.0.35",
62
+ "typescript": "^5.9.2"
63
+ },
64
+ "optionalDependencies": {
65
+ "@moss-js/moss-core-win32-x64-msvc": "0.24.0",
66
+ "@moss-js/moss-core-linux-x64-gnu": "0.24.0",
67
+ "@moss-js/moss-core-linux-arm64-gnu": "0.24.0",
68
+ "@moss-js/moss-core-darwin-arm64": "0.24.0",
69
+ "@moss-js/moss-core-darwin-x64": "0.24.0"
70
+ }
71
+ }