@base44-preview/platform 0.5.0-pr.328.bc88e75 → 0.5.0-pr.346.ce5b5be

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
@@ -213,7 +213,7 @@ Every exported shape and field has JSDoc. `npm run docs` validates it into `docs
213
213
  and `npm run copy-docs-local -- --target <mintlify-docs>` copies the result into
214
214
  `developers/references/platform-sdk/docs`. The pipeline's config for this package lives
215
215
  in `scripts/mintlify-post-processing/`, including `reference.ts`, the docs-only entry that combines
216
- the client and server entrypoints into one reference. The Socket messages page is built in mintlify-docs from
216
+ the client, server and React entrypoints into one reference. The Socket messages page is built in mintlify-docs from
217
217
  the service's AsyncAPI document, not here.
218
218
 
219
219
  `PlatformSocketError` extends `Error` with `code` and optional `appId`. Original
@@ -1,9 +1,8 @@
1
1
  import type { PlatformEvent, PlatformSnapshot } from "./chat.events.types.js";
2
2
  import type { PlatformSocketError } from "../errors.js";
3
3
  /**
4
- * The response body of [Create socket session](/api-reference/create-socket-session), which your
5
- * `getSession()` callback returns. Pass the response through unchanged. The client reads the three
6
- * fields below.
4
+ * The three fields of a [Create socket session](/api-reference/create-socket-session) response that
5
+ * the browser needs. Keep the response's `session_id` on your server.
7
6
  */
8
7
  export interface SocketSession {
9
8
  /** Token that authenticates the socket. The client keeps it in memory and sends it only when the socket connects. */
@@ -18,13 +17,15 @@ export interface ChatInitOptions {
18
17
  /**
19
18
  * Returns a new socket session from your server.
20
19
  *
21
- * Return the response body of [Create socket session](/api-reference/create-socket-session) as a
22
- * [`SocketSession`](#socketsession), and return a new session on every call. The client calls
20
+ * Return the `session_token`, `socket_url`, and `socket_path` of a
21
+ * [Create socket session](/api-reference/create-socket-session) response as a
22
+ * [`SocketSession`](#socketsession), and keep its `session_id` on your server. Return a new
23
+ * session on every call. The client calls
23
24
  * `getSession()` on the first {@linkcode ChatSession.connect | connect()}, and again only when
24
25
  * the session expires or Base44 rejects its token. If a new session has a different `socket_url`
25
26
  * or `socket_path`, the client moves to it and rejoins every active subscription.
26
27
  *
27
- * @returns The session, as your server received it.
28
+ * @returns The session's `session_token`, `socket_url`, and `socket_path`.
28
29
  */
29
30
  getSession: () => Promise<SocketSession>;
30
31
  /**
@@ -52,8 +53,7 @@ export interface ChatModule {
52
53
  *
53
54
  * Pass a `getSession()` callback in the options. The client calls it to get a
54
55
  * [socket session](/developers/references/apps-api/sections/socket-sessions), which your server
55
- * opens with [Create socket session](/api-reference/create-socket-session) and returns as the
56
- * response body. Each session is independent and gets its own socket session.
56
+ * opens with [Create socket session](/api-reference/create-socket-session). Each session is independent and gets its own socket session.
57
57
  *
58
58
  * Call {@linkcode ChatSession.connect | connect()} on the returned session to open the socket.
59
59
  *
@@ -18,25 +18,28 @@ export interface ToolCallAnswer {
18
18
  extraUserInput?: Record<string, unknown>;
19
19
  }
20
20
  /**
21
- * The four calls your backend makes to Base44 for the chat.
21
+ * The functions you write for the `backend` option. The hook calls them when it needs Base44, and
22
+ * each one usually forwards to a route on your own server, which adds your credentials.
22
23
  *
23
- * Each call wraps one Base44 API request with your credentials, so the browser never holds a
24
- * workspace API key or an access token. Your backend can be written in any language.
24
+ * Keeping the Base44 requests on your server means the browser never holds a workspace API key or
25
+ * an access token. Your server can be written in any language.
25
26
  *
26
- * - `createApp`: [Create app](/api-reference/create-app), with the first prompt as `initial_message`.
27
- * - `openLiveSession`: [Create socket session](/api-reference/create-socket-session) with `{ app_ids: [appId] }`.
28
- * Return the response body unchanged. It holds a session token, never the workspace API key.
29
- * - `sendMessage`: [Send chat message](/api-reference/send-chat-message).
30
- * - `submitToolCallInput`: [Submit tool-call input](/api-reference/submit-tool-call-input). Send an
27
+ * Each function's route calls one Base44 endpoint:
28
+ * - [`createApp()`](#createapp): [Create app](/api-reference/create-app), with the first prompt as `initial_message`.
29
+ * - [`openLiveSession()`](#openlivesession): [Create socket session](/api-reference/create-socket-session) with `{ app_ids: [appId] }`.
30
+ * Return its `session_token`, `socket_url`, and `socket_path`, and keep `session_id` on your server.
31
+ * None of them is the workspace API key.
32
+ * - [`sendMessage()`](#sendmessage): [Send chat message](/api-reference/send-chat-message).
33
+ * - [`submitToolCallInput()`](#submittoolcallinput): [Submit tool-call input](/api-reference/submit-tool-call-input). Send an
31
34
  * `X-Request-ID` built from the tool call ID, so a retry resumes the turn only once.
32
35
  *
33
36
  * Base44 keeps the Send chat message and Submit tool-call input requests open until the AI
34
37
  * finishes the turn. Resolve your call once Base44 accepts the request, not when it returns. The
35
- * chat follows the rest live. A rejected promise from any call sets `error` on the {@link useChat | chat}.
38
+ * chat follows the rest live. A rejected promise from any call sets [`error`](#error).
36
39
  *
37
40
  * @example
38
41
  * ```typescript
39
- * // Your four calls, behind your own API routes
42
+ * // Your four functions, behind your own API routes
40
43
  * async function post<T>(path: string, body: unknown): Promise<T> {
41
44
  * const response = await fetch(path, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) });
42
45
  * if (!response.ok) throw new Error(`${path} failed: ${response.status}`);
@@ -64,12 +67,14 @@ export interface ChatBackend {
64
67
  * whenever the session expires. Sessions last one hour.
65
68
  *
66
69
  * @param appId - ID of the app to follow.
67
- * @returns Promise resolving to the Create socket session response body, unchanged.
70
+ * @returns Promise resolving to the session.
68
71
  */
69
72
  openLiveSession(appId: string): Promise<SocketSession>;
70
73
  /**
71
- * Sends a prompt to an existing app. Base44 queues a prompt sent while the AI is working. When the
72
- * app has no queue, Base44 refuses it with a 409, so reject the promise.
74
+ * Sends a prompt to an existing app. Base44 queues a prompt sent while the AI is working. If Base44
75
+ * refuses the prompt, for example because the app is busy with an operation that blocks new
76
+ * messages, reject the promise. The hook then sets [`error`](#error), so your UI can show the
77
+ * failure.
73
78
  *
74
79
  * @param appId - ID of the app.
75
80
  * @param content - The prompt.
@@ -91,16 +96,21 @@ export interface ChatItem {
91
96
  id: string;
92
97
  /** Who wrote the message. */
93
98
  role: "user" | "assistant";
94
- /** The message text, as raw markdown. It comes before the steps, and is empty when the message only holds tool calls. */
99
+ /** The message text, as raw markdown. Show it before the message's steps. It's empty when the message only holds tool calls. */
95
100
  text: string;
96
- /** When the message was created, as an ISO timestamp. Base44's timestamps are UTC with no time zone. A pending prompt carries the browser's time. */
101
+ /**
102
+ * When the message was created, as an ISO 8601 timestamp in UTC. A timestamp from Base44 has no `Z`
103
+ * or offset, so add a `Z` before parsing it with `new Date()`. A pending prompt has the browser's
104
+ * time, which already ends in `Z`.
105
+ */
97
106
  createdAt: string;
98
107
  /** One step per tool call, in order. */
99
108
  steps: ChatStep[];
100
109
  /**
101
- * Whether this is a prompt sent from this chat that Base44 hasn't confirmed yet. It shows at once,
102
- * and Base44's own message replaces it. A failed send removes it. A prompt sent while the AI is
103
- * working waits in Base44's queue and stays pending until it runs.
110
+ * Whether this is a stand-in for a prompt you just sent. When you call [`send()`](#send) or
111
+ * [`create()`](#create), the prompt appears in `items` right away as a pending item, and Base44's
112
+ * copy of the message replaces it once it arrives. A failed send removes it. A prompt sent while the
113
+ * AI is working waits in Base44's queue, so it stays pending until it runs.
104
114
  */
105
115
  pending: boolean;
106
116
  }
@@ -112,20 +122,24 @@ export interface ChatStep {
112
122
  tool: string;
113
123
  /** The file paths the tool call touched. */
114
124
  files: string[];
115
- /** A line ready to show. It's Base44's description of the step when there is one, then the entity it touched, then the tool name and its files. */
125
+ /**
126
+ * A line to show for the step. It's Base44's description of the step when there is one. Otherwise
127
+ * it's the tool name followed by the entity the step touched and its record count, such as
128
+ * `create_records Task (3)`, or by the step's files.
129
+ */
116
130
  label: string;
117
131
  /**
118
- * Where the tool call is. A `waiting` step waits on the user. A `stopped` step was declined, or the
119
- * turn was stopped.
132
+ * The step's progress. A `waiting` step needs the user to answer its question. A `stopped` step was
133
+ * declined, or its turn was stopped. A status this release doesn't know counts as `done`.
120
134
  */
121
135
  status: "running" | "waiting" | "done" | "stopped" | "error";
122
136
  /**
123
- * The question this step waits on, with the actions that answer it. Present only while the step is
124
- * `waiting` in the last assistant message, which is the one that makes the chat wait. It goes away
125
- * once answered, and is absent for a question kind this release doesn't know.
137
+ * The {@link ChatQuestion | question} the step needs answered, with the actions that answer it. It's present only on a
138
+ * `waiting` step in the latest assistant reply, and goes away once answered. A `waiting` step in an
139
+ * older message has no question. It's also absent for a question kind this release doesn't know.
126
140
  */
127
141
  question?: ChatQuestion;
128
- /** What the user answered on a choice question, once answered. It stays after the question closes, so the chat's history shows it. */
142
+ /** The user's answers to a choice question, one for each question the step asked. It stays after the question closes, so you can show the answers in the chat's history. */
129
143
  answered?: ChatAnswer[];
130
144
  }
131
145
  /** One answer to a choice question, next to the question it answers. */
@@ -138,14 +152,17 @@ export interface ChatAnswer {
138
152
  text?: string;
139
153
  }
140
154
  /**
141
- * An open question, with the actions that answer this question and no other.
155
+ * An open question the AI waits on. A `waiting` step carries it as its `question`, and
156
+ * [`status`](#status) becomes `waiting`. Check `kind` to see which of the three kinds it is.
142
157
  *
143
- * Each kind carries only the actions that make sense for it, and every kind can be declined. The
144
- * actions never throw. A failure sets `error` on the {@link useChat | chat}, and the question opens again.
158
+ * Each kind has only the actions that fit it, and every kind can be declined. Calling an action
159
+ * closes the question right away and sends the answer through your
160
+ * [`submitToolCallInput()`](#submittoolcallinput). The actions never throw. A failure sets
161
+ * [`error`](#error), and the question opens again.
145
162
  *
146
- * The chat declines a question kind this release doesn't know, once per tool call, when Base44
147
- * names that kind on the last assistant message. If the decline fails, the chat's `error` says
148
- * so, and the chat tries again after it reconnects.
163
+ * The hook declines a question kind this release doesn't know, once per tool call, when Base44
164
+ * names that kind on the last assistant message. If the decline fails, [`error`](#error) says
165
+ * so, and the hook tries again after it reconnects.
149
166
  */
150
167
  export type ChatQuestion = ChoiceQuestion | SecretsQuestion | ApprovalQuestion;
151
168
  /** One of the questions in a {@link ChoiceQuestion}. */
@@ -168,28 +185,29 @@ export interface ChoiceQuestion {
168
185
  /** The questions, in order. */
169
186
  questions: ChoiceEntry[];
170
187
  /**
171
- * Answers with the picked labels, and free text where the user wrote some.
188
+ * Answers with the picked labels, and free text where the user wrote some. For a question whose
189
+ * `multi` is `false`, only the first picked label counts.
172
190
  *
173
191
  * @param picked - One list of picked labels per question, in the order of `questions`.
174
192
  * @param texts - One free-text answer per question, in the same order. Use it for a `text_input` question, or as a note beside a pick. A question with no pick and no text is skipped.
175
- * @returns Promise resolving once the answer is sent.
193
+ * @returns Promise resolving once Base44 accepts the answer, or once sending it fails and sets [`error`](#error). It never rejects.
176
194
  */
177
195
  answer(picked: string[][], texts?: string[]): Promise<void>;
178
196
  /**
179
197
  * Declines the question. The AI continues without the answer.
180
198
  *
181
- * @returns Promise resolving once the decline is sent.
199
+ * @returns Promise resolving once Base44 accepts the decline, or once sending it fails and sets [`error`](#error). It never rejects.
182
200
  */
183
201
  decline(): Promise<void>;
184
202
  }
185
203
  /** A value the AI needs, such as an API key. */
186
204
  export interface SecretField {
187
- /** Name of the field, used as its key in `submit`. */
205
+ /** Name of the field, which keys its value in [`submit()`](#submit). */
188
206
  name: string;
189
207
  /** Where to get the value. */
190
208
  description?: string;
191
209
  }
192
- /** The AI needs secrets, such as API keys. The values go to Base44 and the chat keeps none of them. */
210
+ /** The AI needs secrets, such as API keys. The values go to Base44, and the hook keeps none of them. */
193
211
  export interface SecretsQuestion {
194
212
  /** Kind of question. */
195
213
  kind: "secrets";
@@ -198,14 +216,14 @@ export interface SecretsQuestion {
198
216
  /**
199
217
  * Submits the values.
200
218
  *
201
- * @param values - The values, keyed by field name.
202
- * @returns Promise resolving once the values are sent.
219
+ * @param values - The values, keyed by each field's `name`.
220
+ * @returns Promise resolving once Base44 accepts the values, or once sending it fails and sets [`error`](#error). It never rejects.
203
221
  */
204
222
  submit(values: Record<string, string>): Promise<void>;
205
223
  /**
206
224
  * Declines the question. The AI continues without the values.
207
225
  *
208
- * @returns Promise resolving once the decline is sent.
226
+ * @returns Promise resolving once Base44 accepts the decline, or once sending it fails and sets [`error`](#error). It never rejects.
209
227
  */
210
228
  decline(): Promise<void>;
211
229
  }
@@ -215,7 +233,7 @@ export interface ApprovalQuestion {
215
233
  kind: "approval";
216
234
  /** Name of the tool that wants to run. */
217
235
  action: string;
218
- /** Why the action needs approval, when Base44 gives a reason. Empty otherwise. */
236
+ /** Why the action needs approval. It's Base44's reason when there is one, otherwise the `summary` in `details`, and empty when neither is given. */
219
237
  reason: string;
220
238
  /** The check that paused the action, such as `exec_tool_send_email` or `entity_rls_guard`. */
221
239
  guard: string;
@@ -224,13 +242,13 @@ export interface ApprovalQuestion {
224
242
  /**
225
243
  * Lets the action run.
226
244
  *
227
- * @returns Promise resolving once the approval is sent.
245
+ * @returns Promise resolving once Base44 accepts the approval, or once sending it fails and sets [`error`](#error). It never rejects.
228
246
  */
229
247
  approve(): Promise<void>;
230
248
  /**
231
249
  * Declines the action. It never runs, and the AI continues.
232
250
  *
233
- * @returns Promise resolving once the decline is sent.
251
+ * @returns Promise resolving once Base44 accepts the decline, or once sending it fails and sets [`error`](#error). It never rejects.
234
252
  */
235
253
  decline(): Promise<void>;
236
254
  }
@@ -252,85 +270,110 @@ export interface ApprovalDetails {
252
270
  inspectionFailed?: boolean;
253
271
  }
254
272
  /**
255
- * What the AI is doing. When several hold at once, the first in this list wins.
273
+ * What the AI is doing.
274
+ *
275
+ * When several hold at once, the first in this list wins.
256
276
  *
257
277
  * - `error`: Base44 reports that the last build failed.
258
- * - `waiting`: a question waits on the user.
259
- * - `building`: the AI is working.
260
- * - `submitted`: a prompt, a new app or an answer is on its way. It lasts until Base44 reports work, a reply or a queue change, or the call fails.
261
- * - `ready`: none of the above.
278
+ * - `waiting`: A question waits for the user's answer.
279
+ * - `building`: The AI is working.
280
+ * - `submitted`: A prompt, a new app, or an answer is on its way. It lasts until Base44 reports work, a reply, or a queue change, or until the call fails.
281
+ * - `ready`: None of the above.
262
282
  */
263
283
  export type ChatStatus = "ready" | "submitted" | "building" | "waiting" | "error";
264
284
  /**
265
285
  * Whether the chat follows the app live.
266
286
  *
267
- * - `connecting`: until the first snapshot arrives.
268
- * - `connected`: after the first snapshot.
269
- * - `disconnected`: live updates stopped for good. The session couldn't open, the retries ran out,
270
- * or Base44 ended the session or the app's subscription. {@link UseChatResult.error} says why.
287
+ * - `connecting`: The chat waits for the app's first snapshot.
288
+ * - `connected`: The first snapshot arrived, and updates follow live.
289
+ * - `disconnected`: Live updates stopped for good. The session couldn't open, the retries ran out,
290
+ * or Base44 ended the session or the app's subscription. Check [`error`](#error) to see why.
271
291
  *
272
292
  * Watching another app, or mounting the chat again, starts over.
273
293
  */
274
294
  export type ChatConnection = "connecting" | "connected" | "disconnected";
275
295
  /** A failure of a call, of the live connection, or of the build. */
276
296
  export interface ChatError {
277
- /** What went wrong, for people. */
297
+ /** A readable description of what went wrong, such as `The build failed`. */
278
298
  message: string;
279
299
  /**
280
- * What went wrong, for code. A connection error carries a `PlatformSocketErrorCode`, and a failed
281
- * build carries `build_failed`. A failed call to your backend carries none.
300
+ * A value your code can check to handle the error, such as `build_failed` for a failed build. A
301
+ * connection error has one of the session or app error codes listed under the chat module's
302
+ * [Errors](/developers/references/platform-sdk/docs/interfaces/chat#errors). A failed call to
303
+ * your backend has no code.
282
304
  */
283
305
  code?: string;
284
- /** The original error, for logging. */
306
+ /** The error the failure came from, such as the one your backend threw. Log it to debug the failure. It's absent when the hook found the failure itself, such as a failed build or a send with no app. */
285
307
  cause?: unknown;
286
308
  }
287
309
  /** Options for {@link useChat}. */
288
310
  export interface ChatOptions {
289
311
  /**
290
312
  * ID of the app to follow, or `null` until an app exists. While it's `null`, the chat follows the
291
- * app {@link UseChatResult.create} made. Any change to `appId` forgets that app.
313
+ * app that [`create()`](#create) made, so you don't have to pass the new ID back.
314
+ * Changing `appId` stops following that app, so setting it back to `null` starts a new chat.
315
+ * Switching to another app closes the old session and starts over.
292
316
  */
293
317
  appId: string | null;
294
- /** The four calls your backend makes to Base44. The chat reads the latest on every action, so an inline object works. */
318
+ /**
319
+ * The functions the hook calls to reach Base44 through your backend, described in
320
+ * [Backend calls](#backend-calls). The hook uses the `backend` from the latest render, so you can
321
+ * pass an inline object without memoizing it.
322
+ */
295
323
  backend: ChatBackend;
296
324
  /**
297
- * Called with the new app after {@link UseChatResult.create} succeeds. The chat already follows it.
298
- * Pass its ID back as `appId` to keep it in your own state.
325
+ * Called with the new app after [`create()`](#create) succeeds. The chat already follows the new
326
+ * app. To keep its ID in your own state, pass it back as `appId`.
299
327
  *
300
328
  * @param app - The app that was created.
301
329
  */
302
330
  onAppCreated?: (app: ChatApp) => void;
303
331
  }
304
- /** The chat that {@link useChat} returns. */
332
+ /**
333
+ * The chat state and actions that `useChat()` returns.
334
+ *
335
+ * @groupDescription Properties
336
+ * The hook returns one object, of type `UseChatResult`. Its state is below, and its functions are
337
+ * under [Returned actions](#returned-actions).
338
+ *
339
+ * @groupDescription Methods
340
+ * Functions on the same object, which you call to act on the chat, as in `chat.send(prompt)`. They
341
+ * never throw. A failure sets [`error`](#error).
342
+ */
305
343
  export interface UseChatResult {
306
- /** The conversation, oldest first, with open questions bound to their steps. */
344
+ /** The conversation, oldest first. Each open question appears with the step that asked it. */
307
345
  items: ChatItem[];
308
346
  /** What the AI is doing. */
309
347
  status: ChatStatus;
310
348
  /** Whether the chat follows the app live. */
311
349
  connection: ChatConnection;
312
350
  /**
313
- * The last failure. It's set whenever `status` is `error`, and on any failed call or connection
314
- * error. A failed call's error clears on the next action. A connection error stays until
315
- * {@link UseChatResult.clearError}. A failed build stays while Base44 reports it.
351
+ * The failure to show, or `null`. It's set when a call fails, when the live connection fails, and
352
+ * whenever `status` is `error`. When more than one of these conditions is true, `error` holds the
353
+ * failed call first, then the connection error, then the failed build. A failed call's error
354
+ * clears on the next action, and a connection error stays until [`clearError()`](#clearerror). A
355
+ * failed build's error stays while Base44 reports it. Switching to another app clears it.
316
356
  */
317
357
  error: ChatError | null;
318
358
  /**
319
- * Sends a prompt to the current app. Base44 queues it while the AI is working. The prompt shows
320
- * at once as a pending item, and the reply arrives through `items`. Without an app, it sets
321
- * `error`. Use {@link UseChatResult.create} for the first prompt.
359
+ * Sends a prompt to the app the chat follows. The prompt appears in [`items`](#items) right away
360
+ * as a pending item, and the reply arrives there too. Base44 queues the prompt while the AI is
361
+ * working. If the chat doesn't follow an app yet, it sets [`error`](#error) instead. Use
362
+ * [`create()`](#create) for the first prompt.
322
363
  *
323
364
  * @param prompt - The prompt to send.
324
- * @returns Promise resolving once Base44 accepts the prompt. It never rejects.
365
+ * @returns Promise resolving once Base44 accepts the prompt, or once the send fails and sets [`error`](#error). It never rejects.
325
366
  */
326
367
  send(prompt: string): Promise<void>;
327
368
  /**
328
- * Creates an app from its first prompt and reports it through `onAppCreated`.
369
+ * Creates an app from its first prompt. The prompt appears in [`items`](#items) right away as a
370
+ * pending item. Once the app exists, the hook passes it to [`onAppCreated`](#onappcreated). If
371
+ * `appId` is `null`, the chat then follows the new app. Otherwise it stays on the app it follows.
329
372
  *
330
373
  * @param prompt - The first prompt, which describes the app.
331
- * @returns Promise resolving once the app exists. It never rejects.
374
+ * @returns Promise resolving once the app exists, or once creating it fails and sets [`error`](#error). It never rejects.
332
375
  */
333
376
  create(prompt: string): Promise<void>;
334
- /** Clears {@link UseChatResult.error}. A failed build's error stays while Base44 reports it. */
377
+ /** Clears a failed call's or the connection's [`error`](#error). A failed build's error stays while Base44 reports it. */
335
378
  clearError(): void;
336
379
  }
@@ -1,35 +1,32 @@
1
1
  import type { UseChatResult, ChatOptions } from "./chat.types.js";
2
2
  /**
3
- * Runs the AI chat for one app in your own UI.
3
+ * Runs an app's AI chat in your own React UI. Requires a browser environment and can't be used in
4
+ * the backend.
4
5
  *
5
- * The hook renders nothing. It gives you the conversation and the actions, and you draw them:
6
+ * The hook is headless. It gives you the conversation and the [actions](#returned-actions), and your components render them:
6
7
  * - Follows the app live, and renews its socket session when it expires.
7
- * - Turns Base44's messages into {@link ChatItem | items}, with each open question bound to the step it belongs to.
8
- * - Reports what the AI is doing in {@link UseChatResult.status}, and the live connection in {@link UseChatResult.connection}.
9
- * - Sends prompts, creates apps and answers questions through the {@link ChatBackend | backend} you pass, so no credential reaches the browser.
10
- *
11
- * The actions never throw. A failure sets {@link UseChatResult.error}, and a question whose answer
12
- * failed opens again. The chat declines a question kind this release doesn't know.
13
- *
14
- * Requires a browser environment and can't be used in the backend.
15
- *
16
- * The chat follows `appId` when it's set. While `appId` is `null`, it follows the app
17
- * {@link UseChatResult.create} made, so passing the new ID back is optional. Any change to `appId`
18
- * forgets that app, so setting it back to `null` starts a new chat. Switching apps closes the old
19
- * session and starts over.
8
+ * - Turns Base44's messages into [items](#items), and shows each open [question](#questions) with the step that asked it.
9
+ * - Reports what the AI is doing in [`status`](#status), and the live connection in [`connection`](#connection).
10
+ * - Sends prompts, creates apps, and answers questions through the {@link ChatBackend | backend} you pass, so no credential reaches the browser.
20
11
  *
21
12
  * @param options - The app to follow, your backend's calls, and what to do with a created app.
22
- * @returns The conversation, its status, connection and error, and the actions `send`, `create` and `clearError`.
13
+ * @returns The chat's state, `items`, `status`, `connection`, and `error`, and its actions `send()`, `create()`, and `clearError()`.
23
14
  *
24
15
  * @example
25
- * ```typescript
26
- * // Draw the chat and answer an approval
16
+ * ```tsx
17
+ * // Render the chat and answer an approval
18
+ * import { useChat } from "@base44/platform/react";
19
+ * import Markdown from "react-markdown";
20
+ *
21
+ * // ...
22
+ *
23
+ * // Inside your component
27
24
  * const chat = useChat({ appId, backend, onAppCreated: selectApp });
28
25
  * return (
29
26
  * <>
30
27
  * {chat.items.map((item) => (
31
28
  * <div key={item.id} className={item.role}>
32
- * {item.text && <p>{item.text}</p>}
29
+ * {item.text && <Markdown>{item.text}</Markdown>}
33
30
  * {item.steps.map((step) =>
34
31
  * step.question?.kind === "approval" ? (
35
32
  * <button key={step.id} onClick={step.question.approve}>Allow {step.question.action}</button>
@@ -7,36 +7,33 @@ const BUILD_FAILED_ERROR = { message: "The build failed", code: "build_failed" }
7
7
  // The target of `submittedTo` while `create` runs, before the new app has an id.
8
8
  const NEW_APP = "new-app";
9
9
  /**
10
- * Runs the AI chat for one app in your own UI.
10
+ * Runs an app's AI chat in your own React UI. Requires a browser environment and can't be used in
11
+ * the backend.
11
12
  *
12
- * The hook renders nothing. It gives you the conversation and the actions, and you draw them:
13
+ * The hook is headless. It gives you the conversation and the [actions](#returned-actions), and your components render them:
13
14
  * - Follows the app live, and renews its socket session when it expires.
14
- * - Turns Base44's messages into {@link ChatItem | items}, with each open question bound to the step it belongs to.
15
- * - Reports what the AI is doing in {@link UseChatResult.status}, and the live connection in {@link UseChatResult.connection}.
16
- * - Sends prompts, creates apps and answers questions through the {@link ChatBackend | backend} you pass, so no credential reaches the browser.
17
- *
18
- * The actions never throw. A failure sets {@link UseChatResult.error}, and a question whose answer
19
- * failed opens again. The chat declines a question kind this release doesn't know.
20
- *
21
- * Requires a browser environment and can't be used in the backend.
22
- *
23
- * The chat follows `appId` when it's set. While `appId` is `null`, it follows the app
24
- * {@link UseChatResult.create} made, so passing the new ID back is optional. Any change to `appId`
25
- * forgets that app, so setting it back to `null` starts a new chat. Switching apps closes the old
26
- * session and starts over.
15
+ * - Turns Base44's messages into [items](#items), and shows each open [question](#questions) with the step that asked it.
16
+ * - Reports what the AI is doing in [`status`](#status), and the live connection in [`connection`](#connection).
17
+ * - Sends prompts, creates apps, and answers questions through the {@link ChatBackend | backend} you pass, so no credential reaches the browser.
27
18
  *
28
19
  * @param options - The app to follow, your backend's calls, and what to do with a created app.
29
- * @returns The conversation, its status, connection and error, and the actions `send`, `create` and `clearError`.
20
+ * @returns The chat's state, `items`, `status`, `connection`, and `error`, and its actions `send()`, `create()`, and `clearError()`.
30
21
  *
31
22
  * @example
32
- * ```typescript
33
- * // Draw the chat and answer an approval
23
+ * ```tsx
24
+ * // Render the chat and answer an approval
25
+ * import { useChat } from "@base44/platform/react";
26
+ * import Markdown from "react-markdown";
27
+ *
28
+ * // ...
29
+ *
30
+ * // Inside your component
34
31
  * const chat = useChat({ appId, backend, onAppCreated: selectApp });
35
32
  * return (
36
33
  * <>
37
34
  * {chat.items.map((item) => (
38
35
  * <div key={item.id} className={item.role}>
39
- * {item.text && <p>{item.text}</p>}
36
+ * {item.text && <Markdown>{item.text}</Markdown>}
40
37
  * {item.steps.map((step) =>
41
38
  * step.question?.kind === "approval" ? (
42
39
  * <button key={step.id} onClick={step.question.approve}>Allow {step.question.action}</button>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/platform",
3
- "version": "0.5.0-pr.328.bc88e75",
3
+ "version": "0.5.0-pr.346.ce5b5be",
4
4
  "description": "Base44 Platform SDK for white-label platforms: a browser client for following the AI chat and a server entrypoint for webhooks",
5
5
  "main": "dist/client/index.js",
6
6
  "types": "dist/client/index.d.ts",