@moss-dev/moss-web 1.9.0 → 1.11.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 +13 -9
- package/dist/client.js +18 -0
- package/dist/index.d.ts +1 -1
- package/dist/inference/index.d.ts +7 -4
- package/dist/inference/index.js +22 -7
- package/dist/inference/types.d.ts +20 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ 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.11.0 resolves `@moss-dev/moss-wasm@0.19.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
24
|
fallback. Before 1.2.0 the only published npm versions were 1.0.0 and 1.0.1,
|
|
@@ -329,8 +329,9 @@ Each call takes `apiKey`, `signal`, `timeout`, `idleTimeout`, `maxRetries` and
|
|
|
329
329
|
`maxRetries` (2 by default, `0` for none) sends a call again when the connection
|
|
330
330
|
fails, or when the gateway answers 408, 409, 429 or 5xx before the stream
|
|
331
331
|
starts, after a `Retry-After` of up to 60 s, else a backoff of 0.5 s doubling
|
|
332
|
-
up to 8 s, within `timeout`.
|
|
333
|
-
|
|
332
|
+
up to 8 s, within `timeout`. Moss searches the indexes a call names in
|
|
333
|
+
`indexes`, else those in an `X-Moss-Indexes` header, else none, and
|
|
334
|
+
`indexes: []` or `retrieve: false` skips the search. Moss can answer an
|
|
334
335
|
identical request from its reply cache; `cache: false` always asks the model.
|
|
335
336
|
`stream.requestId` and a response's `requestId`, which `JSON.stringify` leaves
|
|
336
337
|
out, hold the response's `X-Moss-Request-Id`.
|
|
@@ -513,8 +514,10 @@ for (const file of (await client.tasks.files.list(done.id)).data) {
|
|
|
513
514
|
}
|
|
514
515
|
```
|
|
515
516
|
|
|
516
|
-
Each call takes the options of `responses.create
|
|
517
|
-
never
|
|
517
|
+
Each call takes the options of `responses.create`, and retries as it does, but
|
|
518
|
+
never after a 409. `create` and `run` also take `apiKey`, and send only that
|
|
519
|
+
call's key as `X-Moss-Provider-Key`, for the task's model calls; see the pricing
|
|
520
|
+
docs. Tasks never use the client's `apiKey`, and the other calls never send a key. Each
|
|
518
521
|
create sends an `Idempotency-Key`, a new one per call or yours in its `headers`,
|
|
519
522
|
and the same one on every retry. The gateway answers a repeated key with the
|
|
520
523
|
same body, within 24 hours, with the task it created, so a retried create never
|
|
@@ -599,10 +602,11 @@ The page's headers reach the gateway only when the route forwards them by name,
|
|
|
599
602
|
since every visitor can set them. Back to the page it passes `Content-Type`,
|
|
600
603
|
`Retry-After` and `X-Moss-Request-Id`, so an `InferenceError` there carries
|
|
601
604
|
`retryAfter` and `requestId`. The route refuses an index that is not in its
|
|
602
|
-
list, and always sends `X-Moss-Indexes`,
|
|
603
|
-
|
|
604
|
-
in page code do not reach the gateway, and
|
|
605
|
-
|
|
605
|
+
list, and always sends `X-Moss-Indexes`, its whole list when the page names
|
|
606
|
+
none, because a call without it searches no index. So `retrieve`,
|
|
607
|
+
`indexes: []`, `cache` and `apiKey` in page code do not reach the gateway, and
|
|
608
|
+
a route that wants them sets those headers itself, such as
|
|
609
|
+
`X-Moss-Provider-Key` for your own provider key. The
|
|
606
610
|
route also drops any MCP entry the page sends and adds its own server, so the
|
|
607
611
|
page never holds MCP credentials.
|
|
608
612
|
|
package/dist/client.js
CHANGED
|
@@ -33,6 +33,23 @@ function sameModelArtifactIdentity(left, right) {
|
|
|
33
33
|
&& left.version === right.version
|
|
34
34
|
&& left.manifestSha256 === right.manifestSha256;
|
|
35
35
|
}
|
|
36
|
+
/** An `Error` with the `INVALID_ARGUMENT` code, the shape core failures reach the browser in. */
|
|
37
|
+
function invalidArgument(message) {
|
|
38
|
+
return Object.assign(new Error(message), { code: "INVALID_ARGUMENT" });
|
|
39
|
+
}
|
|
40
|
+
/** Throws INVALID_ARGUMENT unless `projectId` and `auth` can authenticate a client. */
|
|
41
|
+
function assertCredentials(projectId, auth) {
|
|
42
|
+
if (typeof projectId !== "string" || projectId === "") {
|
|
43
|
+
throw invalidArgument("projectId must be a non-empty string.");
|
|
44
|
+
}
|
|
45
|
+
const key = typeof auth === "string" && auth !== "";
|
|
46
|
+
const authenticator = typeof auth === "object" &&
|
|
47
|
+
auth !== null &&
|
|
48
|
+
typeof auth.getAuthToken === "function";
|
|
49
|
+
if (!key && !authenticator) {
|
|
50
|
+
throw invalidArgument("projectKey must be a non-empty string, or an authenticator with a getAuthToken function.");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
36
53
|
/** True for a query with no text to match: empty or only whitespace. */
|
|
37
54
|
function isBlankQuery(query) {
|
|
38
55
|
return query.trim().length === 0;
|
|
@@ -50,6 +67,7 @@ export class MossClient {
|
|
|
50
67
|
});
|
|
51
68
|
this.autoRefreshLoops = new Map();
|
|
52
69
|
this.autoRefreshUnsupportedWarned = false;
|
|
70
|
+
assertCredentials(projectId, auth);
|
|
53
71
|
this.projectId = projectId;
|
|
54
72
|
if (typeof auth === "string") {
|
|
55
73
|
this.projectKey = auth;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ export type { Responses, TaskFiles, Tasks } from "./inference/index.js";
|
|
|
6
6
|
export { ResponseStream } from "./inference/stream.js";
|
|
7
7
|
export { InferenceError } from "./inference/error.js";
|
|
8
8
|
export type { InferenceErrorType } from "./inference/error.js";
|
|
9
|
-
export type { EasyInputMessage, FunctionCallOutput, FunctionTool, InferenceRequestOptions, McpCall, McpServer, MossInferenceOptions, Response, ResponseCreateParams, ResponseCreateParamsBase, ResponseCreateParamsNonStreaming, ResponseCreateParamsStreaming, ResponseFunctionToolCall, ResponseInputItem, ResponseOutputItem, ResponseReasoningItem, ResponseOutputMessage, ResponseOutputText, ResponseStreamEvent, ResponseUsage, Task, TaskCreateParams, TaskEnvironment, TaskError, TaskFile, TaskFileContent, TaskFileList, TaskLimits, TaskRequestOptions, TaskResult, TaskStatus, TaskUsage, TaskVerification, TaskWaitOptions, } from "./inference/types.js";
|
|
9
|
+
export type { EasyInputMessage, FunctionCallOutput, FunctionTool, InferenceRequestOptions, McpCall, McpServer, MossInferenceOptions, Response, ResponseCreateParams, ResponseCreateParamsBase, ResponseCreateParamsNonStreaming, ResponseCreateParamsStreaming, ResponseFunctionToolCall, ResponseInputItem, ResponseOutputItem, ResponseReasoningItem, ResponseOutputMessage, ResponseOutputText, ResponseStreamEvent, ResponseUsage, Task, TaskCreateOptions, TaskCreateParams, TaskEnvironment, TaskError, TaskFile, TaskFileContent, TaskFileList, TaskLimits, TaskRequestOptions, TaskResult, TaskRunOptions, TaskStatus, TaskUsage, TaskVerification, TaskWaitOptions, } from "./inference/types.js";
|
|
10
10
|
export type { MossClientOptions, MossModel, IndexInfo, SearchResult, QueryResultDocumentInfo, QueryOptions, MetadataFilter, FilterCondition, RefreshResult, ModelRef, ModelArtifactIdentity, ModelDownloadProgress, DocumentInfo, MutationResult, CreateIndexOptions, MutationOptions, ParseFileInput, JobStatus, JobPhase, JobProgress, JobStatusResponse, GetDocumentsOptions, LoadIndexOptions, LoadIndexesResult, ISODate, } from "./types.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ResponseStream } from "./stream.js";
|
|
2
|
-
import type { InferenceRequestOptions, MossInferenceOptions, Response as MossResponse, ResponseCreateParams, ResponseCreateParamsNonStreaming, ResponseCreateParamsStreaming, Task, TaskCreateParams, TaskFileContent, TaskFileList, TaskRequestOptions, TaskWaitOptions } from "./types.js";
|
|
2
|
+
import type { InferenceRequestOptions, MossInferenceOptions, Response as MossResponse, ResponseCreateParams, ResponseCreateParamsNonStreaming, ResponseCreateParamsStreaming, Task, TaskCreateOptions, TaskCreateParams, TaskFileContent, TaskFileList, TaskRequestOptions, TaskRunOptions, TaskWaitOptions } from "./types.js";
|
|
3
3
|
/** The `responses` namespace of a {@link MossInference} client, shaped like OpenAI's. */
|
|
4
4
|
export interface Responses {
|
|
5
5
|
/**
|
|
@@ -43,8 +43,10 @@ export interface Tasks {
|
|
|
43
43
|
* and the same one on every retry. The gateway answers a repeated key with the same body,
|
|
44
44
|
* within 24 hours, with the task it created, so a retried create never starts a second task.
|
|
45
45
|
* To retry a create yourself, pass your own key.
|
|
46
|
+
* Only the call's own `apiKey` goes as `X-Moss-Provider-Key`, for the task's model calls; see
|
|
47
|
+
* the pricing docs. The client's `apiKey` is never used, and no other task call sends a key.
|
|
46
48
|
*/
|
|
47
|
-
create<Output = unknown>(params: TaskCreateParams, options?:
|
|
49
|
+
create<Output = unknown>(params: TaskCreateParams, options?: TaskCreateOptions): Promise<Task<Output>>;
|
|
48
50
|
/** Fetches a task by its id. */
|
|
49
51
|
retrieve<Output = unknown>(taskId: string, options?: TaskRequestOptions): Promise<Task<Output>>;
|
|
50
52
|
/**
|
|
@@ -61,10 +63,11 @@ export interface Tasks {
|
|
|
61
63
|
wait<Output = unknown>(taskId: string, options?: TaskWaitOptions): Promise<Task<Output>>;
|
|
62
64
|
/**
|
|
63
65
|
* Creates a task and waits for it, as `create` and then `wait` do.
|
|
64
|
-
* `timeout` and `pollInterval` apply to the wait, and the other options
|
|
66
|
+
* `timeout` and `pollInterval` apply to the wait, `apiKey` to the create, and the other options
|
|
67
|
+
* to every request.
|
|
65
68
|
* Once the task exists, every InferenceError it rejects with names the task in `taskId`.
|
|
66
69
|
*/
|
|
67
|
-
run<Output = unknown>(params: TaskCreateParams, options?:
|
|
70
|
+
run<Output = unknown>(params: TaskCreateParams, options?: TaskRunOptions): Promise<Task<Output>>;
|
|
68
71
|
/**
|
|
69
72
|
* The agent's step-by-step record, as the gateway sent it.
|
|
70
73
|
* It rejects with `not_found_error` until `trace_available` is true.
|
package/dist/inference/index.js
CHANGED
|
@@ -226,9 +226,9 @@ function tasksOf(send) {
|
|
|
226
226
|
retrieve,
|
|
227
227
|
cancel: async (taskId, options) => task({ method: "POST", path: `${taskPath(taskId)}/cancel` }, options),
|
|
228
228
|
wait: async (taskId, options = {}) => poll(taskId, waiting(options)),
|
|
229
|
-
run: async (params, options = {}) => {
|
|
229
|
+
run: async (params, { apiKey, ...options } = {}) => {
|
|
230
230
|
const settings = waiting(options);
|
|
231
|
-
const { id } = await create(params, settings.call);
|
|
231
|
+
const { id } = await create(params, { ...settings.call, apiKey });
|
|
232
232
|
return poll(id, settings);
|
|
233
233
|
},
|
|
234
234
|
trace: async (taskId, options) => decode(await send({ method: "GET", path: `${taskPath(taskId)}/trace` }, options), false),
|
|
@@ -262,7 +262,7 @@ export class MossInference {
|
|
|
262
262
|
_MossInference_timeout.set(this, void 0);
|
|
263
263
|
_MossInference_idleTimeout.set(this, void 0);
|
|
264
264
|
_MossInference_maxRetries.set(this, void 0);
|
|
265
|
-
/** The provider key for calls that do not pass their own. */
|
|
265
|
+
/** The provider key for `responses` calls that do not pass their own. Tasks never use it. */
|
|
266
266
|
_MossInference_apiKey.set(this, void 0);
|
|
267
267
|
if (projectId !== null || projectKey !== null) {
|
|
268
268
|
if (projectId === null || projectKey === null)
|
|
@@ -315,13 +315,24 @@ _MossInference_path = new WeakMap(), _MossInference_headers = new WeakMap(), _Mo
|
|
|
315
315
|
const settings = __classPrivateFieldGet(this, _MossInference_instances, "m", _MossInference_settings).call(this, options);
|
|
316
316
|
if (call.within !== undefined)
|
|
317
317
|
settings.timeout = Math.max(Math.min(settings.timeout ?? MAX_DELAY, call.within), 1);
|
|
318
|
-
const own = {
|
|
319
|
-
|
|
318
|
+
const own = {
|
|
319
|
+
Accept: call.accept ?? "application/json",
|
|
320
|
+
};
|
|
321
|
+
if (call.body) {
|
|
322
|
+
if ("apiKey" in call.body || "api_key" in call.body)
|
|
323
|
+
throw invalid("Pass the provider key as apiKey in the options of create, not in params.");
|
|
320
324
|
own["Content-Type"] = "application/json";
|
|
325
|
+
if (options.apiKey != null)
|
|
326
|
+
own["X-Moss-Provider-Key"] = credential("apiKey", options.apiKey);
|
|
327
|
+
}
|
|
321
328
|
const headers = __classPrivateFieldGet(this, _MossInference_instances, "m", _MossInference_merge).call(this, options.headers, own, "Idempotency-Key");
|
|
322
329
|
if (call.body && !headers.has("Idempotency-Key"))
|
|
323
330
|
headers.set("Idempotency-Key", uuid());
|
|
324
|
-
const init = {
|
|
331
|
+
const init = {
|
|
332
|
+
method: call.method,
|
|
333
|
+
headers,
|
|
334
|
+
body: call.body && json(call.body),
|
|
335
|
+
};
|
|
325
336
|
const sent = await __classPrivateFieldGet(this, _MossInference_instances, "m", _MossInference_send).call(this, url, init, settings, TASK_RETRY);
|
|
326
337
|
const { response, controller, idle, settle, fields } = sent;
|
|
327
338
|
try {
|
|
@@ -402,7 +413,11 @@ async function _MossInference_send(url, init, { timeout, idleTimeout, maxRetries
|
|
|
402
413
|
let wait = Math.min(500 * 2 ** attempt, 8000) * (1 - Math.random() / 4);
|
|
403
414
|
try {
|
|
404
415
|
idle.arm();
|
|
405
|
-
response = await fetch(url, {
|
|
416
|
+
response = await fetch(url, {
|
|
417
|
+
...init,
|
|
418
|
+
signal: controller.signal,
|
|
419
|
+
redirect: "manual",
|
|
420
|
+
});
|
|
406
421
|
idle.clear();
|
|
407
422
|
fields = responseFields(response);
|
|
408
423
|
const after = fields.retryAfter ?? Infinity;
|
|
@@ -66,7 +66,8 @@ export interface ResponseCreateParamsBase {
|
|
|
66
66
|
instructions?: string | null;
|
|
67
67
|
stream?: boolean | null;
|
|
68
68
|
/**
|
|
69
|
-
* Moss indexes to search,
|
|
69
|
+
* Moss indexes to search, none when empty. Left out, Moss
|
|
70
|
+
* searches the indexes in an `X-Moss-Indexes` header, else none.
|
|
70
71
|
* Names travel in a single header, so each must be Latin-1 text with no comma.
|
|
71
72
|
*/
|
|
72
73
|
indexes?: string[];
|
|
@@ -133,6 +134,7 @@ export interface MossInferenceOptions {
|
|
|
133
134
|
/**
|
|
134
135
|
* Your own OpenAI, Anthropic or Google key, for a vendor model such as `gpt-4o-mini`.
|
|
135
136
|
* `moss` ignores it, and a vendor model without one is refused. A call's `apiKey` wins.
|
|
137
|
+
* Used by `responses` only: tasks never send it.
|
|
136
138
|
*/
|
|
137
139
|
apiKey?: string;
|
|
138
140
|
/** The limit for each whole call, streaming included. None by default. */
|
|
@@ -416,8 +418,16 @@ export interface TaskFileContent {
|
|
|
416
418
|
/** The `Content-Type` the gateway sent, `application/octet-stream` when it sent none. */
|
|
417
419
|
contentType: string;
|
|
418
420
|
}
|
|
419
|
-
/** Per-call settings of
|
|
421
|
+
/** Per-call settings of a Tasks API call that is not a create, which sends no provider key. */
|
|
420
422
|
export type TaskRequestOptions = Omit<InferenceRequestOptions, "apiKey">;
|
|
423
|
+
/** Settings of `tasks.create`. Only its own `apiKey` goes as `X-Moss-Provider-Key`. */
|
|
424
|
+
export interface TaskCreateOptions extends TaskRequestOptions {
|
|
425
|
+
/**
|
|
426
|
+
* The provider key for the task's model calls. The client's `apiKey` is never used for tasks.
|
|
427
|
+
* An empty string is an error.
|
|
428
|
+
*/
|
|
429
|
+
apiKey?: string;
|
|
430
|
+
}
|
|
421
431
|
/**
|
|
422
432
|
* Settings of `tasks.wait` and `tasks.run`. Every request takes the others,
|
|
423
433
|
* with the client's `timeout` for each one.
|
|
@@ -428,3 +438,11 @@ export interface TaskWaitOptions extends Omit<TaskRequestOptions, "timeout"> {
|
|
|
428
438
|
/** The pause between polls in milliseconds, 2000 by default. */
|
|
429
439
|
pollInterval?: number;
|
|
430
440
|
}
|
|
441
|
+
/** Settings of `tasks.run`: those of `wait`, and the `apiKey` of the create. */
|
|
442
|
+
export interface TaskRunOptions extends TaskWaitOptions {
|
|
443
|
+
/**
|
|
444
|
+
* The provider key for the task's model calls. The client's `apiKey` is never used for tasks.
|
|
445
|
+
* An empty string is an error.
|
|
446
|
+
*/
|
|
447
|
+
apiKey?: string;
|
|
448
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moss-dev/moss-web",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Moss browser SDK — in-browser semantic search powered by WASM",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"test": "npm run build && node --test"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@moss-dev/moss-wasm": "0.
|
|
35
|
+
"@moss-dev/moss-wasm": "0.19.0",
|
|
36
36
|
"onnxruntime-web": "1.30.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|