@meandr/chat-sdk 0.0.1 → 0.0.3

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 CHANGED
@@ -41,17 +41,18 @@ const result = await chat.send("Where is my order?");
41
41
  The client does nothing until it's used, so create it with the page: until then it sends nothing, loads nothing and
42
42
  leaves nothing behind. Create one client per page, not one per component render. It activates in one of three ways:
43
43
 
44
- - **`open()`**, when the visitor shows interest: opens the chat, or starts typing. It loads their latest conversation.
44
+ - **`open()`**, when the visitor shows interest: opens the chat, or starts typing. It loads their latest conversation
45
+ they haven't ended, its last 20 messages.
45
46
  - **`send(text)`** opens by itself.
46
47
  - **`start()`** has the assistant speak first, such as a greeting or a summary of what needs the visitor's attention.
47
- What it does is the chat's own start instructions, set in its settings (`CHAT_START_PROMPT`), so a page or a visitor
48
+ What it does is the chat's own start instructions, its **Intro prompt** setting (`CHAT_START_PROMPT`), so a page or a visitor
48
49
  can't supply them; the visitor sees only the answer. Without them, it's refused (`start_not_allowed`). With no
49
50
  conversation shown, after `newConversation()` say, it speaks in a new one.
50
51
 
51
52
  ## Who the user is
52
53
 
53
54
  Give the client one way to get your user's token. A token is a JWT your backend signs with the chat's **Session
54
- signing secret**. See the help center's "Sign your users in to Meandr Chat".
55
+ secret key**. See the help center's "Sign your users in to Meandr Chat".
55
56
 
56
57
  | Option | For | The client |
57
58
  |---|---|---|
@@ -82,6 +83,7 @@ inherits it. A page that gives no way resumes it.
82
83
  | `tokenUrl` | `string`: an address, absolute or relative to the page |
83
84
  | `getToken` | `({ expired, signal }) => string \| null \| Promise<string \| null>` |
84
85
  | `fetch` | your own `fetch`, for tests or a wrapper. Add no headers: the chat's CORS allows only `Authorization` and `Content-Type`, so a tracing header such as `traceparent` fails every request |
86
+ | `context` | `() => PageContext \| undefined \| Promise<PageContext \| undefined>`: what your page tells the model of itself, read at each `send()` and `start()`: see [Page context](#page-context) |
85
87
 
86
88
  An option the client doesn't know, or a token option set to `undefined`, is an error, so a typo or a missing value
87
89
  can't silently resume someone's session.
@@ -93,16 +95,24 @@ can't silently resume someone's session.
93
95
  | `getState()` | the current state, below |
94
96
  | `subscribe(listener)` | calls `listener(state)` now and on every change; returns the function that unsubscribes |
95
97
  | `open()` | opens the session: call it when the visitor shows interest. Calling it again while open does nothing. Resolves with the state once it opened, or failed for a reason waiting won't fix: see `status` and `error` |
96
- | `send(text)` | sends the message and streams the answer into the state. Resolves with `{ ok: true, message, stop }`, the stored answer, or `{ ok: false, error }` |
97
- | `start()` | has the assistant speak first, as the chat's start instructions say, and streams the answer: in the user's latest conversation, usually the one shown, or a new one when none is shown or the chat is set so. Resolves as `send` does |
98
- | `newConversation()` | forgets the current conversation: the next message, or `start()`, starts a new one |
98
+ | `send(text, { files })` | sends the message and streams the answer into the state. `files` are those `attach` gave, as ChatFiles or ids; with any, `text` may be `""`. Resolves with `{ ok: true, message, stop }`, the stored answer, or `{ ok: false, error }` |
99
+ | `attach(file, { name, onProgress, signal })` | uploads a `File` or `Blob` for a message of the visitor's within the hour, opening the session if need be: see [Files](#files). `name` is the file's own unless given, else `"file"`; `onProgress(sent, total)` follows its bytes; `signal` cancels it. Resolves with `{ ok: true, file }`, a ChatFile, or `{ ok: false, error }`, and changes nothing in the state |
100
+ | `readFile(file, { signal })` | fetches a file the visitor attached, by its ChatFile or id, with the session's credentials, opening the session if need be. Resolves with `{ ok: true, blob }` or `{ ok: false, error }` |
101
+ | `start()` | has the assistant speak first, as the chat's start instructions say, and streams the answer: in the user's latest conversation they haven't ended, usually the one shown, or a new one when none is shown. Resolves as `send` does |
102
+ | `endConversation()` | ends the conversation shown and forgets it at once, so no page shows it again by itself: see [Conversations](#conversations). Resolves once the chat has it, or after about a minute of trying; never rejects |
103
+ | `newConversation()` | ends the conversation shown, as `endConversation()` does: the next message, or `start()`, starts a new one |
104
+ | `listConversations({ before, signal })` | lists the user's conversations, 20 at a time, most recently active first, opening the session if need be: see [Conversations](#conversations). `before`, a Conversation or its id, goes on after that one; `signal` cancels it. Resolves with `{ ok: true, conversations, hasMore }`, each with its `title`, or `{ ok: false, error }`, and changes nothing in the state |
105
+ | `openConversation(conversation)` | shows that conversation, a Conversation or its id, in place of the current one once it's read: its last 20 messages. It ends nothing, and the next message goes there. Resolves with `{ ok: true, conversation }`, or `{ ok: false, error }` with the current one still shown |
106
+ | `deleteConversation(conversation)` | deletes that conversation, a Conversation or its id, with its messages and files, opening the session if need be. One already gone counts as deleted; the one shown is forgotten. Resolves with `{ ok: true }` or `{ ok: false, error }`, and is refused as `busy` while an answer is being written in it |
107
+ | `loadOlder()` | adds the 20 messages before the oldest shown to the front of `messages`, while `hasOlder`. Resolves with `{ ok: true, messages }`, those it added, or `{ ok: false, error }` |
99
108
  | `reopen({ token })` | the user changed without a page load: signed in, signed out or switched team. Forgets everything shown and, if the chat was open, opens it again. Pass `token` when you give `token` |
100
109
  | `signOut()` | ends the session and forgets the user, even if the page never showed the chat. Call it from your sign-out and await it before you navigate: it settles within three seconds, and never rejects |
101
110
  | `destroy()` | stops everything this client does; it sends nothing more |
102
111
 
103
112
  No member rejects for a chat failure: the result and the state carry it. Members work passed around on their own, as
104
- in `onClick={chat.newConversation}` or `onFocus={chat.open}`; `send` and `reopen` take arguments, so call those
105
- yourself rather than handing them an event.
113
+ in `onClick={chat.endConversation}` or `onFocus={chat.open}`; `send`, `attach`, `readFile`, `listConversations`,
114
+ `openConversation`, `deleteConversation` and `reopen` take arguments, so call those yourself rather than handing them
115
+ an event.
106
116
 
107
117
  ## The state
108
118
 
@@ -110,20 +120,154 @@ yourself rather than handing them an event.
110
120
  |---|---|
111
121
  | `status` | `"idle"` before opening, `"opening"`, `"ready"`, or `"error"` when opening failed (`error` says why) |
112
122
  | `anonymous` | whether the session is an anonymous visitor's; `null` before opening |
113
- | `conversation` | `{ id, createdAt, updatedAt }`, or `null` before the first message |
114
- | `messages` | the conversation's stored messages, oldest first: `{ id, role, text, tools?, createdAt }`. `tools` names the tools the answer used |
115
- | `outgoing` | the message being sent, until the page shows it stored. With `error` set, it may not have reached the chat: offer to send it again, which never stores it twice |
116
- | `answer` | the answer being written in this page: `{ text, tools: [{ name, status }] }`, or `null` |
123
+ | `conversation` | `{ id, createdAt, updatedAt, endedAt }`, or `null` before the first message. `endedAt` is when the user ended it, `null` while they haven't; their next message there reopens it |
124
+ | `messages` | the conversation's stored messages, oldest first: its last 20 when it's shown, and older ones as `loadOlder()` adds them. Each is `{ id, role, text, tools?, toolTitles?, files?, createdAt }`. `tools` names the tools the answer used, and `toolTitles`, with it, gives each one's title by name, its name where the chat knows none; `files` are the ChatFiles the visitor attached |
125
+ | `hasOlder` | the conversation shown has messages older than those in `messages`: `loadOlder()` adds them |
126
+ | `outgoing` | the text of the message being sent, `""` with files alone, until the page shows it stored. With `error` set, it may not have reached the chat: offer to send it again, with its files, which never stores it twice |
127
+ | `answer` | the answer being written in this page: `{ text, tools: [{ name, status, title }] }`, or `null`. Show a tool's `title`: its name when the chat knows none |
117
128
  | `answering` | an answer is being written in this conversation: in this page, or one the page lost or a previous page left running |
118
129
  | `waiting` | `{ code, until }` while the client waits by itself, such as `rate_limited`, or `null`. `until` is a time in milliseconds, as from `Date.now()` |
119
130
  | `stop` | why the last answer ended: `"end"`, `"max_tokens"` (cut short), `"refusal"` or `"paused"`; `null` when unknown |
120
131
  | `error` | the last failure, until the next action |
132
+ | `files` | what the chat takes, as its session says: `{ types, maxBytes, perMessage }`, the media types, a file's most bytes and a message's most files. `null` before opening and while it takes no file: offer attaching only when it isn't `null` |
133
+ | `conversationList` | whether the chat lists the user's conversations, as its session says: offer the list, and opening and deleting conversations from it, only while it's `true`. `null` before opening |
121
134
 
122
135
  Show `messages`, then `outgoing`, then `answer`. Disable sending while `answering` or `status` is `"opening"`. An
123
136
  assistant's `text` is Markdown from a model: render it with `@meandr/chat-sdk/markdown`, or another renderer that
124
137
  never passes raw HTML through. A user's text is plain text.
125
138
 
126
- The state is replaced, never changed in place. Messages that didn't change keep their objects.
139
+ The state is replaced, never changed in place. Messages that didn't change keep their objects, and so does `files`.
140
+
141
+ ## Conversations
142
+
143
+ A conversation goes on, through reloads and a closed chat, until the user ends it. Then no page shows it again by
144
+ itself, and the next message, or `start()`, begins a new one. Offer ending always. Messages come 20 at a time: a
145
+ conversation shows its last 20, and `loadOlder()` adds the 20 before the oldest shown while `hasOlder`. Where the
146
+ chat's **Conversation list** setting is on (`CHAT_CONVERSATION_LIST`), a page may also offer the user's conversations,
147
+ ended ones included, to open or delete:
148
+
149
+ ```js
150
+ endButton.onclick = () => {
151
+ chat.endConversation(); // shows none at once; the end outlives the page
152
+ panel.hidden = true;
153
+ };
154
+ newButton.onclick = chat.newConversation; // ends it too: the next message begins another
155
+ listButton.hidden = !state.conversationList; // the list, opening and deleting: only while the chat lists them
156
+
157
+ const page = await chat.listConversations(); // the 20 most recently active, and page.hasMore
158
+ if (page.ok) rows = page.conversations; // { id, title, createdAt, updatedAt, endedAt }
159
+ const next = await chat.listConversations({ before: rows[rows.length - 1] }); // the 20 after those
160
+
161
+ await chat.openConversation(rows[2]); // shows it, ending none: the next message goes there
162
+ await chat.deleteConversation(rows[3]); // with its messages and files
163
+
164
+ scroller.onscroll = () => {
165
+ if (scroller.scrollTop === 0 && chat.getState().hasOlder) chat.loadOlder(); // then keep the visitor's place
166
+ };
167
+ ```
168
+
169
+ - **Ending** forgets the conversation shown at once, and tells the chat with `keepalive`, so the end goes through
170
+ when the page navigates away right after. It's tried again through about a minute while the chat can't be reached
171
+ or asks to wait. `endConversation()` resolves once the chat has it, and never rejects. A first message or `start()`
172
+ still on its way, its new conversation not named yet, resolves `aborted` at once but goes on unseen until the chat
173
+ names that conversation, which is then ended. Called before the session opens, it ends the conversation the session
174
+ opens on, which the page then never shows; with no opening under way, it resolves at once. `newConversation()` does
175
+ the same, for a "New conversation" that begins the next one at once.
176
+ - **The list** comes most recently active first, 20 at a time: pass the last one shown as `before` for the next 20,
177
+ while `hasMore`. A conversation that gets a message meanwhile moves to the top, so the walk may miss it or show it
178
+ twice: read the first page again to see what's new. A `title` is the start of the conversation's first message, `""`
179
+ while it has none, as after a `start()` alone; only the list carries it. `endedAt` says which ones the user ended.
180
+ - **Opening** one reads it, then shows its last 20 messages in place of the current one, following an answer still
181
+ being written in it. The current one isn't ended, and stays shown when the read fails. One the user ended shows with
182
+ its `endedAt`, and their next message there reopens it. A `newConversation()`, a later `openConversation()`, or a
183
+ message or `start()` before it's shown wins, and it resolves `aborted`. A conversation that isn't the user's is
184
+ `not_found`.
185
+ - **Deleting** one takes its messages and files with it. One already gone counts as deleted, and the one shown is
186
+ forgotten. While an answer is being written in it, it's refused as `busy`.
187
+ - **Older messages** go to the front of `messages`; `loadOlder()` resolves with them, `[]` when none remain, and calls
188
+ while one runs share it. A conversation read again, as when the client follows a lost stream, keeps those it loaded.
189
+ - **Where the chat lists none** (`conversationList` is `false`), `listConversations()` and `deleteConversation()` are
190
+ refused without a request (`conversation_list_off`), and a conversation the user ended is gone for them. Opening the
191
+ others and loading older messages work either way.
192
+ - **Gone elsewhere:** a conversation shown that another tab deleted, or ended where the chat lists none, reads as
193
+ missing. The client forgets it at its next read or message, which says `not_found`.
194
+ - **`start()`** speaks in the user's latest conversation they haven't ended, which may not be the one shown: the page
195
+ then shows that conversation, with the answer alone. With none shown, after `endConversation()` say, it speaks in a
196
+ new one.
197
+
198
+ ## Files
199
+
200
+ Where the chat's **Attachments** setting is on (`CHAT_ATTACHMENTS`), a visitor may attach them to a message for the model to
201
+ read: images (PNG, JPEG, WebP, GIF), PDFs, and text (plain, Markdown, CSV). They never reach your workspace's tools.
202
+
203
+ ```js
204
+ const { types } = state.files; // offer attaching only while state.files isn't null
205
+ input.accept = types.concat(types.includes("text/plain") ? [".txt", ".md", ".csv"] : []).join(",");
206
+
207
+ const files = []; // the message's, as the visitor picks them
208
+ const picked = await chat.attach(input.files[0], { onProgress: (sent, total) => (bar.value = sent / total) });
209
+ if (picked.ok) files.push(picked.file); // or picked.error, such as unsupported_type
210
+ await chat.send(text, { files }); // once every upload is in; text may be ""
211
+
212
+ const read = await chat.readFile(message.files[0]);
213
+ if (read.ok) img.src = URL.createObjectURL(read.blob);
214
+ ```
215
+
216
+ - **Offer attaching only while the state's `files` isn't `null`.** Its `types` can be your `<input>`'s `accept`:
217
+ browsers often give Markdown and CSV files no type, so add `.txt`, `.md` and `.csv` when it lists `text/plain`, which
218
+ the chat takes with the other two. A message takes at most `perMessage` files.
219
+ - **Upload each file as it's picked**, showing its progress, and send the message once all are in. The chat deletes a
220
+ file no message takes within an hour, and a message takes each file once.
221
+ - **A ChatFile** is `{ id, name, type, size, createdAt }`: its name as the chat keeps it, its media type as the chat
222
+ reads it from its bytes, and its size in bytes.
223
+ - **Progress** comes from `XMLHttpRequest`, since `fetch` reports none: with `onProgress`, the upload doesn't go through
224
+ a `fetch` you gave.
225
+ - **Refused before sending,** with status 0, since a browser may see a refusal that comes mid-upload as a network
226
+ error: a file past `maxBytes` (`too_large`), and any file once a session says the chat takes none (`attachments_off`).
227
+ Until a session says, or from a chat that doesn't, a file past 10 MiB, which no chat takes, is refused the same way.
228
+ - **Showing a file:** `readFile` fetches it with the session's cookie or token, so make an object URL of its blob: an
229
+ `<img>` pointing at the chat can't carry the token. The blob keeps an image's type; anything else is
230
+ `application/octet-stream`, a file to save rather than one the browser renders. Files already sent stay readable
231
+ while the chat takes no new ones.
232
+
233
+ ## Page context
234
+
235
+ Each message and start can tell the model what the visitor's page shows, so "this order" or "the drawer I have open"
236
+ means something to it. The `context` option is read at each `send()` and `start()`, so it's always the current view:
237
+
238
+ ```js
239
+ const chat = createChat({
240
+ url: "https://calm-otter.meandr.io",
241
+ tokenUrl: "/chat_token",
242
+ context: () => ({
243
+ url: location.origin + location.pathname, // the query and hash can carry tokens
244
+ title: document.title,
245
+ view: { section: "Orders", drawer: { open: true, order: "A-1042", tab: "Refunds" } },
246
+ }),
247
+ });
248
+ ```
249
+
250
+ The chat gets, beside the message:
251
+
252
+ ```json
253
+ {"timezone":"Europe/Tallinn","url":"https://console.shop.example/orders","title":"Orders · Console","view":{"section":"Orders","drawer":{"open":true,"order":"A-1042","tab":"Refunds"}}}
254
+ ```
255
+
256
+ - **Known keys,** all optional: `url` (at most 2048 bytes), `title` (512) and `timezone` (an IANA name, 64). Any other
257
+ key goes as you give it.
258
+ - **The browser's time zone** goes by default, under what the option gives, so the model knows the visitor's local
259
+ time: give `timezone` to name another, or `timezone: undefined` to send none. Without the option, every message and
260
+ start carries the time zone alone.
261
+ - **Send only what you mean to.** The model reads it as what the page reports, information rather than instructions,
262
+ and the chat stores it with the message. URLs can carry tokens, such as a reset link's or a sign-in code:
263
+ `location.origin + location.pathname` leaves out the query and the hash.
264
+ - **The visitor's browser sends it,** so a visitor can change it, fooling only their own conversation: never let it
265
+ decide what a user may do. Facts your backend vouches for, such as the user's name, go in the token's `profile`
266
+ claim instead.
267
+ - **Never at the message's cost:** past the chat's limit (8 KiB by default, as its session says), with a `url`,
268
+ `title` or `timezone` the chat would refuse, or when the option throws, gives no object or takes over 5 s, the
269
+ message goes without the page's part, keeping the time zone, and the console warns once for each reason. A chat
270
+ older than page context, whose session says no limit, gets the time zone alone.
127
271
 
128
272
  ## Errors
129
273
 
@@ -142,10 +286,14 @@ Show your own words for the code:
142
286
  | `origin_not_allowed`, `origin_required` | The chat isn't available on this site. (The error's message names the site.) |
143
287
  | `workspace_not_available`, `not_connected` | The chat isn't available right now. |
144
288
  | `start_not_allowed` | (nothing: the chat isn't set to speak first) |
145
- | `not_found` | This conversation is gone. |
146
- | `busy` | Still answering your previous message. |
147
- | `too_large` | That message is too long. |
148
- | `rate_limited` | You're sending messages too fast. Try again in a moment. |
289
+ | `attachments_off` | This chat doesn't take files. |
290
+ | `unsupported_type` | That kind of file can't be attached. |
291
+ | `storage_full` | You can't attach more files for now. (The visitor's files, those in conversations included, fill the space the chat allows.) |
292
+ | `conversation_list_off` | (nothing: offer the list, opening and deleting only while `conversationList` is `true`) |
293
+ | `not_found` | This conversation is gone. (From `readFile`: That file is gone.) |
294
+ | `busy` | Still answering your previous message. (From `deleteConversation`: It's still answering there. Try again when it's done.) |
295
+ | `too_large` | That message is too long. (From `attach`: That file is too large.) |
296
+ | `rate_limited` | You're sending messages too fast. Try again in a moment. (Also when the workspace is past its plan's limit on requests.) |
149
297
  | `overloaded` | The chat is busy. Try again in a moment. (The chat's machine is short of memory.) |
150
298
  | `model_busy` | The assistant is busy. Try again in a moment. |
151
299
  | `interrupted`, `timeout`, `unavailable`, `no_answer` | The answer failed. Try again. |
@@ -168,13 +316,17 @@ Codes the client doesn't know may come: show a general error for those.
168
316
  settings change: it tries again briskly through the first minute, then every 15 to 30 s, until the chat answers or
169
317
  the page leaves. `waiting` says so meanwhile, so the page never needs a reload, and a `send` or `start` called
170
318
  meanwhile waits with it.
171
- - **Waiting:** it waits as long as the chat says, up to a minute, when the visitor writes too fast or the chat's
172
- machine is short of memory, and up to two minutes when the user's previous answer is still running, in another tab
173
- perhaps. Past the answers the chat writes at once, an answer waits its turn on the open stream, so nothing is
174
- refused for it.
319
+ - **Waiting:** it waits as long as the chat says, up to a minute, when the visitor writes too fast, the workspace is
320
+ past its plan's limit on requests or the chat's machine is short of memory, and up to two minutes when the user's
321
+ previous answer is still running, in another tab perhaps. Past the answers the chat writes at once, an answer waits
322
+ its turn on the open stream, so nothing is refused for it.
175
323
  - **Nothing twice:** it tries a message again only when the chat refused it before storing it. When the connection
176
324
  drops or the chat fails while sending, it looks for the message in the conversation before saying it failed. A
177
325
  start that fails with `network` may have begun, so calling it again can have the assistant speak twice.
326
+ - **Files:** an upload the chat refused before keeping it is tried again as a message is: an ended session is opened
327
+ again once, and it waits up to a minute as the chat says. One whose answer was lost, such as with `network`, isn't,
328
+ since the chat may have kept it: attach it again. An upload is given up on when it stops moving for 30 s, or, without
329
+ `onProgress`, when no answer starts within 30 s plus its size's time at 32 KB/s.
178
330
  - **A lost stream:** the answer runs on and is stored. The client asks for the conversation every few seconds, for up
179
331
  to ten minutes, until the answer ends, as it does when it opens on an answer a previous page left running. An answer
180
332
  still waiting its turn when its stream closed was dropped: that's `no_answer`, and sending again stores the message
@@ -246,7 +398,8 @@ the chat's, and only signed-in users can chat: your server must answer for them.
246
398
 
247
399
  ## Content Security Policy
248
400
 
249
- Allow `connect-src` for your workspace's URL and your token address.
401
+ Allow `connect-src` for your workspace's URL and your token address, and `img-src blob:` to show files through object
402
+ URLs.
250
403
 
251
404
  ## License
252
405
 
package/dist/api.d.ts CHANGED
@@ -4,16 +4,20 @@ export interface Call {
4
4
  method: "GET" | "POST" | "DELETE";
5
5
  path: string;
6
6
  body?: unknown;
7
+ type?: string;
7
8
  bearer?: string | null;
8
9
  signal?: AbortSignal;
9
10
  stream?: boolean;
11
+ progress?: (sent: number) => void;
12
+ keepalive?: boolean;
10
13
  }
11
14
  export declare function apiBase(url: string): string;
12
15
  export declare function aborted(): ChatError;
13
16
  export declare function within<T>(p: Promise<T>, signal: AbortSignal | undefined, ms: number, late: () => Error): Promise<T>;
14
- export declare function timed(fetchFn: Fetch, url: string, init: RequestInit, signal?: AbortSignal): Promise<Response>;
17
+ export declare function timed(fetchFn: Fetch, url: string, init: RequestInit, signal?: AbortSignal, ms?: number): Promise<Response>;
15
18
  export declare function request(fetchFn: Fetch, base: string, c: Call): Promise<Response>;
16
19
  export declare function discard(res: Response): void;
20
+ export declare function chunks(res: Response, signal?: AbortSignal): Promise<Uint8Array<ArrayBuffer>[]>;
17
21
  export declare function body(res: Response, signal?: AbortSignal): Promise<unknown>;
18
22
  export declare function readJSON(res: Response, signal?: AbortSignal): Promise<unknown>;
19
23
  export declare function failure(res: Response, signal?: AbortSignal): Promise<ChatError>;
package/dist/errors.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Message } from "./types.js";
2
- export type ChatErrorCode = "unauthorized" | "token_expired" | "token_failed" | "session_expired" | "origin_not_allowed" | "origin_required" | "workspace_not_available" | "not_found" | "busy" | "too_large" | "rate_limited" | "overloaded" | "not_connected" | "interrupted" | "timeout" | "unavailable" | "model_busy" | "no_answer" | "network" | "aborted" | "bad_request" | "internal" | "protocol";
2
+ export type ChatErrorCode = "unauthorized" | "token_expired" | "token_failed" | "session_expired" | "origin_not_allowed" | "origin_required" | "workspace_not_available" | "start_not_allowed" | "attachments_off" | "storage_full" | "conversation_list_off" | "not_found" | "busy" | "too_large" | "unsupported_type" | "rate_limited" | "overloaded" | "not_connected" | "interrupted" | "timeout" | "unavailable" | "model_busy" | "no_answer" | "network" | "aborted" | "bad_request" | "internal" | "protocol";
3
3
  export interface ChatErrorInit {
4
4
  status?: number;
5
5
  retryAfter?: number | null;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { createChat } from "./client.js";
2
2
  export { ChatError, isChatError } from "./errors.js";
3
3
  export type { ChatErrorCode } from "./errors.js";
4
- export type { Answer, Chat, ChatOptions, ChatState, ChatStatus, Conversation, Message, ReopenOptions, SendResult, Stop, TokenRequest, TokenSource, ToolProgress, ToolStatus, Waiting, } from "./types.js";
4
+ export type { Answer, AttachOptions, AttachResult, Chat, ChatFile, ChatOptions, ChatState, ChatStatus, Conversation, DeleteConversationResult, FileLimits, ListConversationsOptions, ListConversationsResult, LoadOlderResult, Message, OpenConversationResult, PageContext, ReadFileOptions, ReadFileResult, ReopenOptions, SendOptions, SendResult, Stop, TokenRequest, TokenSource, ToolProgress, ToolStatus, Waiting, } from "./types.js";