@moss-dev/moss-web 1.6.0 → 1.8.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.
@@ -1,89 +1,123 @@
1
- /** One part of a message's content, such as text or an image. */
2
- export interface ChatCompletionContentPart {
3
- type: string;
4
- text?: string;
1
+ /** A message of the conversation, such as `{ role: "user", content: "Hi" }`. */
2
+ export interface EasyInputMessage {
3
+ type?: "message";
4
+ role: "user" | "assistant" | "system" | "developer";
5
+ /** Text, or a list of parts such as `{ type: "input_text", text }`. */
6
+ content: string | {
7
+ type: string;
8
+ [key: string]: any;
9
+ }[];
5
10
  [key: string]: any;
6
11
  }
7
- /** A tool call the model made, as the API returns it. */
8
- export interface ChatCompletionMessageToolCall {
9
- id: string;
10
- type: "function";
11
- function: {
12
- name: string;
13
- arguments: string;
14
- };
15
- }
16
- /** One message of the conversation, in OpenAI's shape. */
17
- export interface ChatCompletionMessageParam {
18
- role: "system" | "developer" | "user" | "assistant" | "tool" | "function";
19
- content?: string | ChatCompletionContentPart[] | null;
20
- name?: string;
21
- tool_calls?: (ChatCompletionMessageToolCall | {
12
+ /** The result of a {@link ResponseFunctionToolCall}, for the `input` of the next request. */
13
+ export interface FunctionCallOutput {
14
+ type: "function_call_output";
15
+ /** The `call_id` of the call. */
16
+ call_id: string;
17
+ /** Text, or a list of parts such as `{ type: "input_text", text }`. */
18
+ output: string | {
22
19
  type: string;
23
20
  [key: string]: any;
24
- })[];
25
- tool_call_id?: string;
21
+ }[];
26
22
  [key: string]: any;
27
23
  }
28
- /** A function the model may call. */
29
- export interface ChatCompletionTool {
24
+ /**
25
+ * An item of `input`: a message, the result of a function call,
26
+ * or an item of an earlier response's `output`, sent back unchanged.
27
+ */
28
+ export type ResponseInputItem = EasyInputMessage | FunctionCallOutput | ResponseOutputItem;
29
+ /** A function the model may call. Your code runs it and sends back the result. */
30
+ export interface FunctionTool {
30
31
  type: "function";
31
- function: {
32
- name: string;
33
- description?: string;
34
- parameters?: Record<string, unknown>;
35
- strict?: boolean | null;
36
- };
32
+ name: string;
33
+ description?: string | null;
34
+ parameters?: Record<string, unknown> | null;
35
+ strict?: boolean | null;
36
+ }
37
+ /** An MCP server the gateway calls for the model during the turn. */
38
+ export interface McpServer {
39
+ /** Marks this `tools` entry as an MCP server. */
40
+ type: "mcp";
41
+ /** The server's label, unique in the request. */
42
+ server_label: string;
43
+ /** The server's https URL. */
44
+ server_url: string;
45
+ /**
46
+ * Headers for this server only.
47
+ * In page code every visitor can read them, `Authorization` included.
48
+ */
49
+ headers?: Record<string, string>;
50
+ /** The only tools of the server the model may call. */
51
+ allowed_tools?: string[];
52
+ /** `streamable_http` by default, or `sse` for an older server. */
53
+ transport?: "streamable_http" | "sse";
37
54
  }
38
55
  /**
39
- * OpenAI's chat completion parameters plus the Moss retrieval options.
40
- * `indexes` and `retrieve` travel as headers, the rest in the body unchanged,
41
- * including parameters this type does not name. The body always says `stream: true`.
56
+ * OpenAI's Responses parameters plus the Moss options.
57
+ * `indexes`, `retrieve` and `cache` travel as headers, the rest in the body
58
+ * unchanged, including parameters this type does not name. The body always says `stream: true`.
42
59
  */
43
- export interface ChatCompletionCreateParamsBase {
60
+ export interface ResponseCreateParamsBase {
44
61
  /** `moss` by default, Moss's own model. A vendor model such as `gpt-4o-mini` needs `apiKey`. */
45
62
  model?: string;
46
- messages: ChatCompletionMessageParam[];
63
+ /** The text to answer, or the whole conversation so far, since Moss stores none. */
64
+ input: string | ResponseInputItem[];
65
+ /** The system message, before `input`. */
66
+ instructions?: string | null;
47
67
  stream?: boolean | null;
48
- /** Moss indexes the gateway searches. Names travel in a header, so they must be Latin-1. */
68
+ /**
69
+ * Moss indexes to search, every index when left out and none when empty.
70
+ * Names travel in a single header, so each must be Latin-1 text with no comma.
71
+ */
49
72
  indexes?: string[];
50
73
  /** False skips retrieval for this call. */
51
74
  retrieve?: boolean;
52
- temperature?: number | null;
53
- top_p?: number | null;
54
- max_tokens?: number | null;
55
- max_completion_tokens?: number | null;
56
- stop?: string | string[] | null;
57
- seed?: number | null;
58
- tools?: (ChatCompletionTool | {
75
+ /** False always asks the model instead of the gateway's reply cache. */
76
+ cache?: boolean;
77
+ /** Functions your code runs, MCP servers the gateway calls, or any other tool object. */
78
+ tools?: (FunctionTool | McpServer | {
59
79
  type: string;
60
80
  [key: string]: any;
61
81
  })[];
82
+ /** Whether and which tool the model calls, such as `{ type: "function", name }`. */
62
83
  tool_choice?: "none" | "auto" | "required" | {
63
84
  type: string;
64
85
  [key: string]: any;
65
86
  };
66
- response_format?: {
67
- type: string;
87
+ /** False asks the model for at most one tool call per response. */
88
+ parallel_tool_calls?: boolean | null;
89
+ /** The most tokens the response can have. A longer one ends `incomplete`. */
90
+ max_output_tokens?: number | null;
91
+ temperature?: number | null;
92
+ top_p?: number | null;
93
+ /** Such as `{ format: { type: "json_schema", name, schema } }` for structured output. */
94
+ text?: {
95
+ format?: {
96
+ type: string;
97
+ [key: string]: any;
98
+ };
68
99
  [key: string]: any;
69
- };
70
- stream_options?: {
71
- include_usage?: boolean;
72
100
  } | null;
101
+ /** Such as `{ effort: "low" }`. */
102
+ reasoning?: {
103
+ effort?: string | null;
104
+ [key: string]: any;
105
+ } | null;
106
+ metadata?: Record<string, string> | null;
73
107
  user?: string;
74
108
  /** Any other OpenAI parameter. */
75
109
  [param: string]: any;
76
110
  }
77
- /** Parameters that return a {@link ChatCompletionStream}. */
78
- export interface ChatCompletionCreateParamsStreaming extends ChatCompletionCreateParamsBase {
111
+ /** Parameters that return a {@link ResponseStream}. */
112
+ export interface ResponseCreateParamsStreaming extends ResponseCreateParamsBase {
79
113
  stream: true;
80
114
  }
81
- /** Parameters that return one aggregated {@link ChatCompletion}. */
82
- export interface ChatCompletionCreateParamsNonStreaming extends ChatCompletionCreateParamsBase {
115
+ /** Parameters that return one {@link Response}. */
116
+ export interface ResponseCreateParamsNonStreaming extends ResponseCreateParamsBase {
83
117
  stream?: false | null;
84
118
  }
85
- /** Parameters of `chat.completions.create`. */
86
- export type ChatCompletionCreateParams = ChatCompletionCreateParamsStreaming | ChatCompletionCreateParamsNonStreaming;
119
+ /** Parameters of `responses.create`. */
120
+ export type ResponseCreateParams = ResponseCreateParamsStreaming | ResponseCreateParamsNonStreaming;
87
121
  /**
88
122
  * Settings of a `MossInference` client.
89
123
  * Timeouts are in milliseconds, and `null` or `Infinity` removes the limit.
@@ -105,6 +139,11 @@ export interface MossInferenceOptions {
105
139
  timeout?: number | null;
106
140
  /** The longest wait for response headers or for more of the body. 120 000 by default. */
107
141
  idleTimeout?: number | null;
142
+ /**
143
+ * Retries before the stream starts, 2 by default and 0 for none.
144
+ * A failed connection or a 408, 409, 429 or 5xx response is retried.
145
+ */
146
+ maxRetries?: number;
108
147
  /** Headers sent on every call. */
109
148
  headers?: Record<string, string>;
110
149
  }
@@ -118,71 +157,140 @@ export interface InferenceRequestOptions {
118
157
  timeout?: number | null;
119
158
  /** Replaces the client's `idleTimeout` for this call. */
120
159
  idleTimeout?: number | null;
160
+ /** Replaces the client's `maxRetries` for this call. */
161
+ maxRetries?: number;
121
162
  /** Headers for this call, over the client's. The SDK's own headers win over both. */
122
163
  headers?: Record<string, string>;
123
164
  }
124
- /** Token counts for one call. */
125
- export interface CompletionUsage {
126
- prompt_tokens: number;
127
- completion_tokens: number;
165
+ /** Token counts for one call, with every field the gateway sent, such as `moss`. */
166
+ export interface ResponseUsage {
167
+ input_tokens: number;
168
+ input_tokens_details: {
169
+ cached_tokens: number;
170
+ [key: string]: any;
171
+ };
172
+ output_tokens: number;
173
+ output_tokens_details: {
174
+ reasoning_tokens: number;
175
+ [key: string]: any;
176
+ };
128
177
  total_tokens: number;
178
+ [key: string]: any;
129
179
  }
130
- /** A piece of a tool call inside a streamed delta. */
131
- export interface ChatCompletionChunkToolCall {
132
- index: number;
133
- id?: string;
134
- type?: "function";
135
- function?: {
136
- name?: string;
137
- arguments?: string;
138
- };
180
+ /** The text of a message, with its annotations. */
181
+ export interface ResponseOutputText {
182
+ type: "output_text";
183
+ text: string;
184
+ annotations: any[];
185
+ [key: string]: any;
139
186
  }
140
- /** What one chunk adds to a choice. */
141
- export interface ChatCompletionChunkDelta {
142
- role?: string;
143
- content?: string | null;
144
- tool_calls?: ChatCompletionChunkToolCall[];
187
+ /** A message of the model, an item of `output`. */
188
+ export interface ResponseOutputMessage {
189
+ type: "message";
190
+ id: string;
191
+ role: "assistant";
192
+ status: "in_progress" | "completed" | "incomplete";
193
+ content: ResponseOutputText[];
194
+ [key: string]: any;
145
195
  }
146
- /** One choice inside a streamed chunk. */
147
- export interface ChatCompletionChunkChoice {
148
- index: number;
149
- delta: ChatCompletionChunkDelta;
150
- finish_reason: string | null;
196
+ /**
197
+ * A call of one of your function tools, an item of `output`.
198
+ * Fields the model adds, such as Gemini's `extra_content`, stay on the object,
199
+ * so it goes back into `input` unchanged, before its {@link FunctionCallOutput}.
200
+ */
201
+ export interface ResponseFunctionToolCall {
202
+ type: "function_call";
203
+ id: string;
204
+ /** The id its {@link FunctionCallOutput} names. */
205
+ call_id: string;
206
+ name: string;
207
+ /** The arguments as JSON text. */
208
+ arguments: string;
209
+ status: "in_progress" | "completed" | "incomplete";
210
+ [key: string]: any;
151
211
  }
152
212
  /**
153
- * One streamed event, in OpenAI's shape.
154
- * Each chunk is the decoded JSON event,
155
- * so fields this type does not name are still on the object.
156
- * The last chunk may carry `usage` with an empty `choices` list.
213
+ * A call that the gateway ran on one of your MCP servers, an item of `output`.
214
+ * Sent back in `input` with the rest of `output`, it gives the model the tool's earlier result.
157
215
  */
158
- export interface ChatCompletionChunk {
216
+ export interface McpCall {
217
+ type: "mcp_call";
159
218
  id: string;
160
- object: "chat.completion.chunk";
161
- created: number;
162
- model: string;
163
- choices: ChatCompletionChunkChoice[];
164
- usage?: CompletionUsage | null;
219
+ /** The label of the MCP server, as sent in `tools`. */
220
+ server_label: string;
221
+ /** The tool's name on its server. */
222
+ name: string;
223
+ /** The arguments as JSON text. */
224
+ arguments: string;
225
+ /** The tool's result, cut when long, once it succeeded. */
226
+ output?: string | null;
227
+ /** What failed, once the tool failed. */
228
+ error?: {
229
+ type: string;
230
+ [key: string]: any;
231
+ } | null;
232
+ status: "in_progress" | "completed" | "failed";
233
+ /** How long the call took in milliseconds, once it ended. */
234
+ duration_ms?: number;
235
+ [key: string]: any;
165
236
  }
166
- /** The reply the model built for one choice. */
167
- export interface ChatCompletionMessage {
168
- role: "assistant";
169
- /** All text joined, or null when the model sent none. */
170
- content: string | null;
171
- /** Present only when the model called tools. */
172
- tool_calls?: ChatCompletionMessageToolCall[];
173
- }
174
- /** One choice of an aggregated completion. */
175
- export interface ChatCompletionChoice {
176
- index: number;
177
- message: ChatCompletionMessage;
178
- finish_reason: string | null;
179
- }
180
- /** A whole reply, built from every chunk of the stream. */
181
- export interface ChatCompletion {
237
+ /** The reasoning of a reasoning model, an item of `output`, kept as the gateway sent it. */
238
+ export interface ResponseReasoningItem {
239
+ type: "reasoning";
182
240
  id: string;
183
- object: "chat.completion";
184
- created: number;
241
+ [key: string]: any;
242
+ }
243
+ /** An item of `output`. An item of another type comes as the gateway sent it. */
244
+ export type ResponseOutputItem = ResponseOutputMessage | ResponseFunctionToolCall | McpCall | ResponseReasoningItem;
245
+ /**
246
+ * A response, the JSON the gateway sent, plus `output_text`.
247
+ * `JSON.stringify` keeps `output_text` and leaves out `requestId`.
248
+ * A call without `stream: true`, and `finalResponse()`, return the one of the last event.
249
+ */
250
+ export interface Response {
251
+ /** Such as `resp_...`. */
252
+ id: string;
253
+ object: "response";
254
+ /** In seconds since the epoch. */
255
+ created_at: number;
256
+ /** `incomplete` when `max_output_tokens` or a content filter cut the response. */
257
+ status: "completed" | "incomplete" | "failed" | "in_progress" | (string & {});
185
258
  model: string;
186
- choices: ChatCompletionChoice[];
187
- usage: CompletionUsage | null;
259
+ output: ResponseOutputItem[];
260
+ /** The text of every `output_text` part of every message in `output`, joined. */
261
+ output_text: string;
262
+ usage: ResponseUsage | null;
263
+ error: {
264
+ code: string;
265
+ message: string;
266
+ [key: string]: any;
267
+ } | null;
268
+ incomplete_details: {
269
+ reason: "max_output_tokens" | "content_filter" | (string & {});
270
+ } | null;
271
+ instructions: string | null;
272
+ metadata: Record<string, string> | null;
273
+ /** The `X-Moss-Request-Id` of the HTTP response. */
274
+ readonly requestId?: string;
275
+ /** The other request fields the gateway repeats, such as `temperature`. */
276
+ [key: string]: any;
277
+ }
278
+ /**
279
+ * One event of a streamed response, the JSON the gateway sent.
280
+ * Each type sets its own fields, such as `delta` on `response.output_text.delta`,
281
+ * `item` on `response.output_item.added` and `.done`, and `response` on
282
+ * `response.created`, `response.completed` and `response.incomplete`.
283
+ */
284
+ export interface ResponseStreamEvent {
285
+ type: string;
286
+ sequence_number?: number;
287
+ response?: Response;
288
+ output_index?: number;
289
+ item_id?: string;
290
+ item?: ResponseOutputItem;
291
+ content_index?: number;
292
+ delta?: string;
293
+ text?: string;
294
+ arguments?: string;
295
+ [key: string]: any;
188
296
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moss-dev/moss-web",
3
- "version": "1.6.0",
3
+ "version": "1.8.0",
4
4
  "type": "module",
5
5
  "description": "Moss browser SDK — in-browser semantic search powered by WASM",
6
6
  "main": "dist/index.js",