@base44-preview/platform 0.2.0-pr.315.9d1cad2 → 0.2.0-pr.315.add18a9

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,201 +1,336 @@
1
1
  import type { SocketSession } from "../client/modules/builder.types.js";
2
- /** An app the builder works on, as the chat needs it. */
2
+ /** An app the AI chat works on. */
3
3
  export interface Base44App {
4
- /** App identifier: 24 lowercase hexadecimal characters. */
4
+ /** ID of the app, 24 lowercase hexadecimal characters. */
5
5
  id: string;
6
- /** Display name. */
6
+ /** Display name of the app. */
7
7
  name: string;
8
8
  }
9
- /** A reply to a question the builder waits on. Declining is `approve: false`. */
9
+ /** An answer to a question the AI waits on. Declining is `approve: false`. */
10
10
  export interface ToolCallAnswer {
11
- /** The tool call being answered. */
11
+ /** ID of the tool call being answered. */
12
12
  toolCallId: string;
13
- /** The assistant message that holds the tool call. */
13
+ /** ID of the assistant message that holds the tool call. */
14
14
  messageId: string;
15
- /** Whether to let the call run (`true`) or turn it down (`false`). */
15
+ /** Whether to let the tool call run (`true`) or turn it down (`false`). */
16
16
  approve: boolean;
17
- /** Content the question asked for: `{ answers }` for a choice, `{ secrets }` for secrets. */
17
+ /** What the question asked for. A choice sends `{ answers }`, and a secrets question sends `{ secrets }`. */
18
18
  extraUserInput?: Record<string, unknown>;
19
19
  }
20
20
  /**
21
- * The four calls your backend provides. Each wraps one Base44 REST call with your
22
- * credentials, so the hook never holds a workspace key or an access token, and the
23
- * backend can be written in any language:
21
+ * The four calls your backend makes to Base44 for the chat.
24
22
  *
25
- * - `createApp`: `POST /api/apps` with the first prompt as `initial_message`.
26
- * - `openLiveSession`: `POST /api/service/socket-sessions` with `{ app_ids: [appId] }`, returning
27
- * Base44's response body unchanged. Called again whenever the session expires; sessions last
28
- * one hour. The body holds a session token, never the workspace key.
29
- * - `sendMessage`: `POST /api/apps/{id}/chat/message`. Base44 queues a prompt sent while the
30
- * builder is busy, or refuses it with a 409 where the app has no queue: reject then.
31
- * - `submitToolCallInput`: `POST /api/apps/{id}/chat/submit-tool-call-input`, with an
32
- * `X-Request-ID` derived from the tool call id so a retry resumes the turn only once.
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.
33
25
  *
34
- * Base44 holds `sendMessage` and `submitToolCallInput` open for the whole turn, so resolve once
35
- * the request is accepted rather than when it returns: the live session shows the rest.
36
- * A rejected promise from any of them lands in {@link Base44Chat.error}.
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
31
+ * `X-Request-ID` built from the tool call ID, so a retry resumes the turn only once.
32
+ *
33
+ * Base44 keeps the Send chat message and Submit tool-call input requests open until the AI
34
+ * 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 {@link Base44Chat.error}.
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * // Your four calls, behind your own API routes
40
+ * async function post<T>(path: string, body: unknown): Promise<T> {
41
+ * const response = await fetch(path, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) });
42
+ * if (!response.ok) throw new Error(`${path} failed: ${response.status}`);
43
+ * return response.json();
44
+ * }
45
+ *
46
+ * const backend: Base44ChatBackend = {
47
+ * createApp: (prompt) => post("/api/chat/apps", { prompt }),
48
+ * openLiveSession: (appId) => post("/api/chat/session", { appId }),
49
+ * sendMessage: (appId, content) => post("/api/chat/message", { appId, content }),
50
+ * submitToolCallInput: (appId, answer) => post("/api/chat/answer", { appId, answer }),
51
+ * };
52
+ * ```
37
53
  */
38
54
  export interface Base44ChatBackend {
39
- /** Creates an app from its first prompt. The build starts inside this call. */
40
- createApp(message: string): Promise<Base44App>;
41
- /** Opens a read-only live-updates session for one app. */
55
+ /**
56
+ * Creates an app from its first prompt. The AI starts building inside this call.
57
+ *
58
+ * @param prompt - The first prompt, which describes the app.
59
+ * @returns Promise resolving to the new app.
60
+ */
61
+ createApp(prompt: string): Promise<Base44App>;
62
+ /**
63
+ * Opens a read-only socket session for one app. The chat calls it on the first connect and again
64
+ * whenever the session expires. Sessions last one hour.
65
+ *
66
+ * @param appId - ID of the app to follow.
67
+ * @returns Promise resolving to the Create socket session response body, unchanged.
68
+ */
42
69
  openLiveSession(appId: string): Promise<SocketSession>;
43
- /** Sends a prompt to an existing app. */
70
+ /**
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.
73
+ *
74
+ * @param appId - ID of the app.
75
+ * @param content - The prompt.
76
+ * @returns Promise resolving once Base44 accepts the prompt.
77
+ */
44
78
  sendMessage(appId: string, content: string): Promise<void>;
45
- /** Answers, or declines, a question the builder waits on. */
79
+ /**
80
+ * Answers or declines a question the AI waits on.
81
+ *
82
+ * @param appId - ID of the app.
83
+ * @param answer - The tool call and the answer to it.
84
+ * @returns Promise resolving once Base44 accepts the answer.
85
+ */
46
86
  submitToolCallInput(appId: string, answer: ToolCallAnswer): Promise<void>;
47
87
  }
48
- /** One message of the chat, in a shape made for rendering. */
88
+ /** One message of the chat, shaped for rendering. */
49
89
  export interface ChatItem {
50
- /** Message identifier. */
90
+ /** ID of the message. */
51
91
  id: string;
52
- /** Who wrote it. */
92
+ /** Who wrote the message. */
53
93
  role: "user" | "assistant";
54
- /** Raw markdown; it comes before the steps. Empty when the message is only tool activity. */
94
+ /** The message text, as raw markdown. It comes before the steps, and is empty when the message only holds tool calls. */
55
95
  text: string;
56
- /** When Base44 created the message, as an ISO timestamp. */
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. */
57
97
  createdAt: string;
58
- /** One per tool call, in order. */
98
+ /** One step per tool call, in order. */
59
99
  steps: ChatStep[];
60
- /** A prompt sent from this chat that Base44 has not confirmed yet. It shows at once, and gives
61
- * way to Base44's own message; a failed send removes it. A prompt sent while the builder is busy
62
- * waits in Base44's queue and stays pending until it runs. */
100
+ /**
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.
104
+ */
63
105
  pending: boolean;
64
106
  }
65
107
  /** One tool call, as a line of activity. */
66
108
  export interface ChatStep {
67
- /** The tool call id. */
109
+ /** ID of the tool call. */
68
110
  id: string;
69
- /** The tool's name, e.g. `write_file`. */
111
+ /** Name of the tool, such as `write_file`. */
70
112
  tool: string;
71
- /** The paths it touched. */
113
+ /** The file paths the tool call touched. */
72
114
  files: string[];
73
- /** Tool and files, ready to show. */
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. */
74
116
  label: string;
75
- /** Where the call is. `waiting` waits on the user; `stopped` was declined, or the build was stopped. */
117
+ /** Base44's description of what the step did, such as what a command or code run did. */
118
+ summary?: string;
119
+ /**
120
+ * Where the tool call is. A `waiting` step waits on the user. A `stopped` step was declined, or the
121
+ * turn was stopped.
122
+ */
76
123
  status: "running" | "waiting" | "done" | "stopped" | "error";
77
- /** The question this step waits on, bound to the actions that answer it. Only while `status` is
78
- * `waiting`, and gone once answered. */
124
+ /**
125
+ * The question this step waits on, with the actions that answer it. Present only while the step is
126
+ * `waiting` in the last assistant message, which is the one that makes the chat wait. It goes away
127
+ * once answered, and is absent for a question kind this release doesn't know.
128
+ */
79
129
  question?: ChatQuestion;
130
+ /** What the user answered on a choice question, once answered. It stays after the question closes, so the chat's history shows it. */
131
+ answered?: ChatAnswer[];
132
+ }
133
+ /** One answer to a choice question, next to the question it answers. */
134
+ export interface ChatAnswer {
135
+ /** The question text. */
136
+ question: string;
137
+ /** The labels the user picked. */
138
+ labels: string[];
139
+ /** The free text the user wrote, if any. */
140
+ text?: string;
80
141
  }
81
142
  /**
82
143
  * An open question, with the actions that answer this question and no other.
83
- * Each kind carries only the actions that make sense for it, and every kind can be declined.
84
- * A kind this release doesn't know is declined for you and never appears.
85
- * The actions never throw: a failure lands in {@link Base44Chat.error} and the question opens again.
144
+ *
145
+ * Each kind carries only the actions that make sense for it, and every kind can be declined. The
146
+ * actions never throw. A failure sets {@link Base44Chat.error}, and the question opens again.
147
+ *
148
+ * The chat declines a question kind this release doesn't know, once per tool call, when Base44
149
+ * names that kind on the last assistant message. If the decline fails, {@link Base44Chat.error} says
150
+ * so, and the chat tries again after it reconnects.
86
151
  */
87
152
  export type ChatQuestion = ChoiceQuestion | SecretsQuestion | ApprovalQuestion;
88
- /** One of the questions a `choice` asks. */
153
+ /** One of the questions in a {@link ChoiceQuestion}. */
89
154
  export interface ChoiceEntry {
90
155
  /** The question text. */
91
156
  text: string;
92
- /** Optional supporting text. */
157
+ /** Supporting text for the question. */
93
158
  description?: string;
159
+ /** Base44's type of question, such as `text_input` for one that takes only a free-text answer. */
160
+ type?: string;
94
161
  /** The option labels to pick from. */
95
162
  options: string[];
96
- /** Whether more than one option may be picked. */
163
+ /** Whether more than one option can be picked. */
97
164
  multi: boolean;
98
165
  }
99
- /** The builder offers options and wants a pick. */
166
+ /** The AI offers options and waits for the user to pick. */
100
167
  export interface ChoiceQuestion {
101
- /** Discriminator. */
168
+ /** Kind of question. */
102
169
  kind: "choice";
103
- /** The questions asked, in order. */
170
+ /** The questions, in order. */
104
171
  questions: ChoiceEntry[];
105
- /** Answers with the picked labels: one list per question, in the same order as `questions`. An empty list skips that question. */
106
- answer(picked: string[][]): Promise<void>;
107
- /** Declines: the builder continues without the answer. */
172
+ /**
173
+ * Answers with the picked labels, and free text where the user wrote some.
174
+ *
175
+ * @param picked - One list of picked labels per question, in the order of `questions`.
176
+ * @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.
177
+ * @returns Promise resolving once the answer is sent.
178
+ */
179
+ answer(picked: string[][], texts?: string[]): Promise<void>;
180
+ /**
181
+ * Declines the question. The AI continues without the answer.
182
+ *
183
+ * @returns Promise resolving once the decline is sent.
184
+ */
108
185
  decline(): Promise<void>;
109
186
  }
110
- /** A value the builder needs, such as an API key. */
187
+ /** A value the AI needs, such as an API key. */
111
188
  export interface SecretField {
112
- /** The field name, used as the key in `submit`. */
189
+ /** Name of the field, used as its key in `submit`. */
113
190
  name: string;
114
- /** Optional explanation of where to obtain the value. */
191
+ /** Where to get the value. */
115
192
  description?: string;
116
193
  }
117
- /** The builder needs secrets, such as API keys. They go to Base44 and are never kept here. */
194
+ /** The AI needs secrets, such as API keys. The values go to Base44 and the chat keeps none of them. */
118
195
  export interface SecretsQuestion {
119
- /** Discriminator. */
196
+ /** Kind of question. */
120
197
  kind: "secrets";
121
198
  /** The fields to fill. */
122
199
  fields: SecretField[];
123
- /** Submits the values, keyed by field name. */
200
+ /**
201
+ * Submits the values.
202
+ *
203
+ * @param values - The values, keyed by field name.
204
+ * @returns Promise resolving once the values are sent.
205
+ */
124
206
  submit(values: Record<string, string>): Promise<void>;
125
- /** Declines: the builder continues without the values. */
207
+ /**
208
+ * Declines the question. The AI continues without the values.
209
+ *
210
+ * @returns Promise resolving once the decline is sent.
211
+ */
126
212
  decline(): Promise<void>;
127
213
  }
128
- /** The builder wants permission to run a proposed action. */
214
+ /** The AI asks for permission to run an action. */
129
215
  export interface ApprovalQuestion {
130
- /** Discriminator. */
216
+ /** Kind of question. */
131
217
  kind: "approval";
132
- /** The tool that wants to run. */
218
+ /** Name of the tool that wants to run. */
133
219
  action: string;
134
- /** Why it was parked, when the guard says; empty otherwise. */
220
+ /** Why the action needs approval, when Base44 gives a reason. Empty otherwise. */
135
221
  reason: string;
136
- /** Lets the action run. */
222
+ /** The check that paused the action, such as `exec_tool_send_email` or `entity_rls_guard`. */
223
+ guard: string;
224
+ /** What the action would do, as far as the check publishes it. Show it so the user knows what they approve. */
225
+ details: ApprovalDetails;
226
+ /**
227
+ * Lets the action run.
228
+ *
229
+ * @returns Promise resolving once the approval is sent.
230
+ */
137
231
  approve(): Promise<void>;
138
- /** Declines: the action never runs and the builder continues. */
232
+ /**
233
+ * Declines the action. It never runs, and the AI continues.
234
+ *
235
+ * @returns Promise resolving once the decline is sent.
236
+ */
139
237
  decline(): Promise<void>;
140
238
  }
239
+ /** What an action that waits for approval would do. Each check publishes only some of these. */
240
+ export interface ApprovalDetails {
241
+ /** The AI's summary of what the code does. */
242
+ summary?: string;
243
+ /** The entity whose records or access rules change. */
244
+ entityName?: string;
245
+ /** How the access rules change. */
246
+ changeType?: string;
247
+ /** The access operations whose rules change. */
248
+ changedOps?: string[];
249
+ /** The backend function under test. */
250
+ functionName?: string;
251
+ /** The entity method the code calls, such as `delete`. */
252
+ method?: string;
253
+ /** Whether the check couldn't verify the function's source. */
254
+ inspectionFailed?: boolean;
255
+ }
141
256
  /**
142
- * What the builder is doing, one value at a time. The first that holds wins:
143
- *
144
- * - `error`: Base44 reports the app's build failed.
145
- * - `waiting`: a step waits on the user.
146
- * - `building`: the builder is working.
147
- * - `submitted`: a prompt, a new app or an answer is on its way, until Base44 reports work,
148
- * a reply or a queue change, or the call fails.
149
- * - `ready`: everything else.
257
+ * What the AI is doing. When several hold at once, the first in this list wins.
150
258
  *
151
- * To let the user send only when the builder can take a prompt now:
152
- * `status === "ready" || status === "error"`.
259
+ * - `error`: Base44 reports that the last build failed.
260
+ * - `waiting`: a question waits on the user.
261
+ * - `building`: the AI is working.
262
+ * - `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.
263
+ * - `ready`: none of the above.
153
264
  */
154
265
  export type ChatStatus = "ready" | "submitted" | "building" | "waiting" | "error";
155
- /** Whether the chat sees the builder live: `connecting` until the first snapshot, `connected`
156
- * after it, `reconnecting` while the socket retries a dropped connection, and `disconnected`
157
- * once live updates have stopped for good: the session could not open, the retries ran out, or
158
- * Base44 ended the session or the app's subscription. {@link Base44Chat.error} says why. Watching
159
- * another app, or mounting the chat again, starts over. */
160
- export type ChatConnection = "connecting" | "connected" | "reconnecting" | "disconnected";
161
- /** A failure: of a call, of the live connection, or of the build itself. */
266
+ /**
267
+ * Whether the chat follows the app live.
268
+ *
269
+ * - `connecting`: until the first snapshot arrives.
270
+ * - `connected`: after the first snapshot.
271
+ * - `disconnected`: live updates stopped for good. The session couldn't open, the retries ran out,
272
+ * or Base44 ended the session or the app's subscription. {@link Base44Chat.error} says why.
273
+ *
274
+ * Watching another app, or mounting the chat again, starts over.
275
+ */
276
+ export type ChatConnection = "connecting" | "connected" | "disconnected";
277
+ /** A failure of a call, of the live connection, or of the build. */
162
278
  export interface ChatError {
163
279
  /** What went wrong, for people. */
164
280
  message: string;
165
- /** For code: a `PlatformSocketErrorCode` for a connection error, or `build_failed` when Base44
166
- * reports the build failed. Absent for a failed call. */
281
+ /**
282
+ * What went wrong, for code. A connection error carries a `PlatformSocketErrorCode`, and a failed
283
+ * build carries `build_failed`. A failed call to your backend carries none.
284
+ */
167
285
  code?: string;
168
286
  /** The original error, for logging. */
169
287
  cause?: unknown;
170
288
  }
171
- /** Options of {@link useBase44Chat}. */
289
+ /** Options for {@link useBase44Chat}. */
172
290
  export interface Base44ChatOptions {
173
- /** The app to watch, or `null` until an app exists. While it is `null`, the chat watches the
174
- * app {@link Base44Chat.create} just made; any change to it forgets that app. */
291
+ /**
292
+ * ID of the app to follow, or `null` until an app exists. While it's `null`, the chat follows the
293
+ * app {@link Base44Chat.create} made. Any change to `appId` forgets that app.
294
+ */
175
295
  appId: string | null;
176
- /** Your backend's four calls. Read on every action, so an inline object is fine. */
296
+ /** The four calls your backend makes to Base44. The chat reads the latest on every action, so an inline object works. */
177
297
  backend: Base44ChatBackend;
178
- /** Called with the new app after {@link Base44Chat.create} succeeds. The chat already watches
179
- * it; pass its id back as `appId` to keep it watched from your own state. */
298
+ /**
299
+ * Called with the new app after {@link Base44Chat.create} succeeds. The chat already follows it.
300
+ * Pass its ID back as `appId` to keep it in your own state.
301
+ */
180
302
  onAppCreated?: (app: Base44App) => void;
181
303
  }
182
- /** What {@link useBase44Chat} returns. */
304
+ /** The chat that {@link useBase44Chat} returns. */
183
305
  export interface Base44Chat {
184
306
  /** The conversation, oldest first, with open questions bound to their steps. */
185
307
  items: ChatItem[];
186
- /** What the builder is doing. */
308
+ /** What the AI is doing. */
187
309
  status: ChatStatus;
188
- /** Whether the chat sees it live. */
310
+ /** Whether the chat follows the app live. */
189
311
  connection: ChatConnection;
190
- /** Set whenever `status` is `error`, and on any failed call, until {@link Base44Chat.clearError}
191
- * or the next action clears it. A failed build stays while Base44 reports it. */
312
+ /**
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 Base44Chat.clearError}. A failed build stays while Base44 reports it.
316
+ */
192
317
  error: ChatError | null;
193
- /** Sends a prompt to the current app; Base44 queues it while the builder is busy. Resolves once
194
- * the request is accepted, and the reply arrives through `items`. Needs an app: without one it
195
- * sets `error`, and `create` makes the first. */
196
- send(message: string): Promise<void>;
197
- /** Creates a new app from its first prompt and reports it through `onAppCreated`. */
198
- create(message: string): Promise<void>;
199
- /** Clears a failed call's or the connection's {@link Base44Chat.error}. */
318
+ /**
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 Base44Chat.create} for the first prompt.
322
+ *
323
+ * @param prompt - The prompt to send.
324
+ * @returns Promise resolving once Base44 accepts the prompt. It never rejects.
325
+ */
326
+ send(prompt: string): Promise<void>;
327
+ /**
328
+ * Creates an app from its first prompt and reports it through `onAppCreated`.
329
+ *
330
+ * @param prompt - The first prompt, which describes the app.
331
+ * @returns Promise resolving once the app exists. It never rejects.
332
+ */
333
+ create(prompt: string): Promise<void>;
334
+ /** Clears {@link Base44Chat.error}. A failed build's error stays while Base44 reports it. */
200
335
  clearError(): void;
201
336
  }
@@ -1,4 +1,4 @@
1
- /** The `@base44/platform/react` entry: one app's builder chat as a hook. React is an optional peer, loaded only here. */
1
+ /** The `@base44/platform/react` entry: the AI chat for one app, as a React hook. React is an optional peer, loaded only here. */
2
2
  export { useBase44Chat } from "./useBase44Chat.js";
3
- export type { ApprovalQuestion, Base44App, Base44Chat, Base44ChatOptions, Base44ChatBackend, ChatConnection, ChatError, ChatItem, ChatQuestion, ChatStatus, ChatStep, ChoiceEntry, ChoiceQuestion, SecretField, SecretsQuestion, ToolCallAnswer, } from "./chat.types.js";
3
+ export type { ApprovalDetails, ApprovalQuestion, Base44App, Base44Chat, Base44ChatOptions, Base44ChatBackend, ChatAnswer, ChatConnection, ChatError, ChatItem, ChatQuestion, ChatStatus, ChatStep, ChoiceEntry, ChoiceQuestion, SecretField, SecretsQuestion, ToolCallAnswer, } from "./chat.types.js";
4
4
  export type { SocketSession } from "../client/modules/builder.types.js";
@@ -1,2 +1,2 @@
1
- /** The `@base44/platform/react` entry: one app's builder chat as a hook. React is an optional peer, loaded only here. */
1
+ /** The `@base44/platform/react` entry: the AI chat for one app, as a React hook. React is an optional peer, loaded only here. */
2
2
  export { useBase44Chat } from "./useBase44Chat.js";
@@ -1,27 +1,29 @@
1
1
  import type { Base44Chat, Base44ChatOptions } from "./chat.types.js";
2
2
  /**
3
- * Runs one app's builder chat, headless: it keeps the live connection through
4
- * the platform client, turns Base44's messages into {@link ChatItem | items}, binds
5
- * every open question to the step it belongs to. You render the items.
3
+ * Runs the AI chat for one app in your own UI.
6
4
  *
7
- * All Base44 calls go through the {@link Base44ChatBackend | backend} you pass, so no
8
- * credential reaches the browser. Actions never throw: a failure lands in
9
- * {@link Base44Chat.error}, and a question whose reply failed opens again. A question kind
10
- * this release doesn't know is declined for you.
5
+ * The hook renders nothing. It gives you the conversation and the actions, and you draw them:
6
+ * - 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 Base44Chat.status}, and the live connection in {@link Base44Chat.connection}.
9
+ * - Sends prompts, creates apps and answers questions through the {@link Base44ChatBackend | backend} you pass, so no credential reaches the browser.
11
10
  *
12
- * Requires a browser environment. One live session is opened per app and renewed through
13
- * `backend.openLiveSession` when it expires; switching apps closes the old one and starts over.
11
+ * The actions never throw. A failure sets {@link Base44Chat.error}, and a question whose answer
12
+ * failed opens again. The chat declines a question kind this release doesn't know.
14
13
  *
15
- * The chat watches `appId` when it is set. While it is `null`, the chat watches the app
16
- * {@link Base44Chat.create} just made, so passing the new id back is optional; any change to
17
- * `appId` forgets that app, so setting `appId` back to `null` starts a new chat.
14
+ * Requires a browser environment and can't be used in the backend.
18
15
  *
19
- * @param options - The app to watch, your backend's calls, and what to do with a created app.
16
+ * The chat follows `appId` when it's set. While `appId` is `null`, it follows the app
17
+ * {@link Base44Chat.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.
20
+ *
21
+ * @param options - The app to follow, your backend's calls, and what to do with a created app.
20
22
  * @returns The conversation, its status, connection and error, and the actions `send`, `create` and `clearError`.
21
23
  *
22
24
  * @example
23
25
  * ```typescript
24
- * // Render the items, answer a question
26
+ * // Draw the chat and answer an approval
25
27
  * const chat = useBase44Chat({ appId, backend, onAppCreated: selectApp });
26
28
  * return (
27
29
  * <>
@@ -38,9 +40,7 @@ import type { Base44Chat, Base44ChatOptions } from "./chat.types.js";
38
40
  * </div>
39
41
  * ))}
40
42
  * {chat.error && <p role="alert">{chat.error.message}</p>}
41
- * <button disabled={chat.status !== "ready" && chat.status !== "error"} onClick={() => (appId ? chat.send(prompt) : chat.create(prompt))}>
42
- * Send
43
- * </button>
43
+ * <button onClick={() => (appId ? chat.send(prompt) : chat.create(prompt))}>Send</button>
44
44
  * </>
45
45
  * );
46
46
  * ```