@moss-dev/moss-web 1.9.0 → 1.10.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 +5 -3
- 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 +18 -1
- package/package.json +1 -1
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.10.0 resolves `@moss-dev/moss-wasm@0.18.2`. 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,
|
|
@@ -513,8 +513,10 @@ for (const file of (await client.tasks.files.list(done.id)).data) {
|
|
|
513
513
|
}
|
|
514
514
|
```
|
|
515
515
|
|
|
516
|
-
Each call takes the options of `responses.create
|
|
517
|
-
never
|
|
516
|
+
Each call takes the options of `responses.create`, and retries as it does, but
|
|
517
|
+
never after a 409. `create` and `run` also take `apiKey`, and send only that
|
|
518
|
+
call's key as `X-Moss-Provider-Key`, for the task's model calls; see the pricing
|
|
519
|
+
docs. Tasks never use the client's `apiKey`, and the other calls never send a key. Each
|
|
518
520
|
create sends an `Idempotency-Key`, a new one per call or yours in its `headers`,
|
|
519
521
|
and the same one on every retry. The gateway answers a repeated key with the
|
|
520
522
|
same body, within 24 hours, with the task it created, so a retried create never
|
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;
|
|
@@ -133,6 +133,7 @@ export interface MossInferenceOptions {
|
|
|
133
133
|
/**
|
|
134
134
|
* Your own OpenAI, Anthropic or Google key, for a vendor model such as `gpt-4o-mini`.
|
|
135
135
|
* `moss` ignores it, and a vendor model without one is refused. A call's `apiKey` wins.
|
|
136
|
+
* Used by `responses` only: tasks never send it.
|
|
136
137
|
*/
|
|
137
138
|
apiKey?: string;
|
|
138
139
|
/** The limit for each whole call, streaming included. None by default. */
|
|
@@ -416,8 +417,16 @@ export interface TaskFileContent {
|
|
|
416
417
|
/** The `Content-Type` the gateway sent, `application/octet-stream` when it sent none. */
|
|
417
418
|
contentType: string;
|
|
418
419
|
}
|
|
419
|
-
/** Per-call settings of
|
|
420
|
+
/** Per-call settings of a Tasks API call that is not a create, which sends no provider key. */
|
|
420
421
|
export type TaskRequestOptions = Omit<InferenceRequestOptions, "apiKey">;
|
|
422
|
+
/** Settings of `tasks.create`. Only its own `apiKey` goes as `X-Moss-Provider-Key`. */
|
|
423
|
+
export interface TaskCreateOptions extends TaskRequestOptions {
|
|
424
|
+
/**
|
|
425
|
+
* The provider key for the task's model calls. The client's `apiKey` is never used for tasks.
|
|
426
|
+
* An empty string is an error.
|
|
427
|
+
*/
|
|
428
|
+
apiKey?: string;
|
|
429
|
+
}
|
|
421
430
|
/**
|
|
422
431
|
* Settings of `tasks.wait` and `tasks.run`. Every request takes the others,
|
|
423
432
|
* with the client's `timeout` for each one.
|
|
@@ -428,3 +437,11 @@ export interface TaskWaitOptions extends Omit<TaskRequestOptions, "timeout"> {
|
|
|
428
437
|
/** The pause between polls in milliseconds, 2000 by default. */
|
|
429
438
|
pollInterval?: number;
|
|
430
439
|
}
|
|
440
|
+
/** Settings of `tasks.run`: those of `wait`, and the `apiKey` of the create. */
|
|
441
|
+
export interface TaskRunOptions extends TaskWaitOptions {
|
|
442
|
+
/**
|
|
443
|
+
* The provider key for the task's model calls. The client's `apiKey` is never used for tasks.
|
|
444
|
+
* An empty string is an error.
|
|
445
|
+
*/
|
|
446
|
+
apiKey?: string;
|
|
447
|
+
}
|