@base44-preview/platform 0.5.0-pr.346.ce5b5be → 0.5.0-pr.353.5c12c6c

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.
@@ -60,6 +60,22 @@ export interface ChatBackend {
60
60
  *
61
61
  * @param prompt - The first prompt, which describes the app.
62
62
  * @returns Promise resolving to the new app.
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * // Your server route for createApp(), with a personal access token
67
+ * export async function POST(request: Request) {
68
+ * const { prompt } = await request.json();
69
+ * const response = await fetch("https://app.base44.com/api/apps", {
70
+ * method: "POST",
71
+ * headers: { Authorization: `Bearer ${process.env.BASE44_ACCESS_TOKEN}`, "Content-Type": "application/json" },
72
+ * body: JSON.stringify({ initial_message: { content: prompt } }),
73
+ * });
74
+ * if (!response.ok) return new Response("Create app failed", { status: response.status });
75
+ * const app = await response.json();
76
+ * return Response.json({ id: app.id, name: app.name });
77
+ * }
78
+ * ```
63
79
  */
64
80
  createApp(prompt: string): Promise<ChatApp>;
65
81
  /**
@@ -68,6 +84,23 @@ export interface ChatBackend {
68
84
  *
69
85
  * @param appId - ID of the app to follow.
70
86
  * @returns Promise resolving to the session.
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * // Your server route for openLiveSession(), with a workspace API key
91
+ * export async function POST(request: Request) {
92
+ * const { appId } = await request.json();
93
+ * const response = await fetch("https://app.base44.com/api/v1/socket-sessions", {
94
+ * method: "POST",
95
+ * headers: { Authorization: `Bearer ${process.env.BASE44_API_KEY}`, "Content-Type": "application/json" },
96
+ * body: JSON.stringify({ app_ids: [appId] }),
97
+ * });
98
+ * if (!response.ok) return new Response("Create socket session failed", { status: response.status });
99
+ * const { session_token, socket_url, socket_path, session_id } = await response.json();
100
+ * await saveSession(appId, session_id); // Keep it on your server to change or end the session
101
+ * return Response.json({ session_token, socket_url, socket_path });
102
+ * }
103
+ * ```
71
104
  */
72
105
  openLiveSession(appId: string): Promise<SocketSession>;
73
106
  /**
@@ -191,12 +224,35 @@ export interface ChoiceQuestion {
191
224
  * @param picked - One list of picked labels per question, in the order of `questions`.
192
225
  * @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.
193
226
  * @returns Promise resolving once Base44 accepts the answer, or once sending it fails and sets [`error`](#error). It never rejects.
227
+ *
228
+ * @example
229
+ * ```tsx
230
+ * // Answer a one-question choice with a button per option
231
+ * function ChoiceButtons({ question }: { question: ChoiceQuestion }) {
232
+ * const [entry] = question.questions;
233
+ * return (
234
+ * <div>
235
+ * <p>{entry.text}</p>
236
+ * {entry.options.map((label) => (
237
+ * <button key={label} onClick={() => question.answer([[label]])}>{label}</button>
238
+ * ))}
239
+ * <button onClick={question.decline}>Skip</button>
240
+ * </div>
241
+ * );
242
+ * }
243
+ * ```
194
244
  */
195
245
  answer(picked: string[][], texts?: string[]): Promise<void>;
196
246
  /**
197
247
  * Declines the question. The AI continues without the answer.
198
248
  *
199
249
  * @returns Promise resolving once Base44 accepts the decline, or once sending it fails and sets [`error`](#error). It never rejects.
250
+ *
251
+ * @example
252
+ * ```tsx
253
+ * // Skip the question
254
+ * <button onClick={question.decline}>Skip</button>
255
+ * ```
200
256
  */
201
257
  decline(): Promise<void>;
202
258
  }
@@ -218,12 +274,43 @@ export interface SecretsQuestion {
218
274
  *
219
275
  * @param values - The values, keyed by each field's `name`.
220
276
  * @returns Promise resolving once Base44 accepts the values, or once sending it fails and sets [`error`](#error). It never rejects.
277
+ *
278
+ * @example
279
+ * ```tsx
280
+ * // Ask for each secret, then submit the values by name
281
+ * function SecretsForm({ question }: { question: SecretsQuestion }) {
282
+ * return (
283
+ * <form
284
+ * onSubmit={(event) => {
285
+ * event.preventDefault();
286
+ * const form = new FormData(event.currentTarget);
287
+ * question.submit(Object.fromEntries(question.fields.map((field) => [field.name, String(form.get(field.name) ?? "")])));
288
+ * }}
289
+ * >
290
+ * {question.fields.map((field) => (
291
+ * <label key={field.name}>
292
+ * {field.name}
293
+ * <input name={field.name} type="password" placeholder={field.description} />
294
+ * </label>
295
+ * ))}
296
+ * <button type="submit">Save</button>
297
+ * <button type="button" onClick={question.decline}>Skip</button>
298
+ * </form>
299
+ * );
300
+ * }
301
+ * ```
221
302
  */
222
303
  submit(values: Record<string, string>): Promise<void>;
223
304
  /**
224
305
  * Declines the question. The AI continues without the values.
225
306
  *
226
307
  * @returns Promise resolving once Base44 accepts the decline, or once sending it fails and sets [`error`](#error). It never rejects.
308
+ *
309
+ * @example
310
+ * ```tsx
311
+ * // Skip without entering the secrets
312
+ * <button onClick={question.decline}>Skip</button>
313
+ * ```
227
314
  */
228
315
  decline(): Promise<void>;
229
316
  }
@@ -243,12 +330,33 @@ export interface ApprovalQuestion {
243
330
  * Lets the action run.
244
331
  *
245
332
  * @returns Promise resolving once Base44 accepts the approval, or once sending it fails and sets [`error`](#error). It never rejects.
333
+ *
334
+ * @example
335
+ * ```tsx
336
+ * // Show what the action would do, then allow or decline it
337
+ * function ApprovalPrompt({ question }: { question: ApprovalQuestion }) {
338
+ * return (
339
+ * <div>
340
+ * <p>The AI wants to run {question.action}.</p>
341
+ * {question.reason && <p>{question.reason}</p>}
342
+ * <button onClick={question.approve}>Allow</button>
343
+ * <button onClick={question.decline}>Decline</button>
344
+ * </div>
345
+ * );
346
+ * }
347
+ * ```
246
348
  */
247
349
  approve(): Promise<void>;
248
350
  /**
249
351
  * Declines the action. It never runs, and the AI continues.
250
352
  *
251
353
  * @returns Promise resolving once Base44 accepts the decline, or once sending it fails and sets [`error`](#error). It never rejects.
354
+ *
355
+ * @example
356
+ * ```tsx
357
+ * // Decline the action
358
+ * <button onClick={question.decline}>Decline</button>
359
+ * ```
252
360
  */
253
361
  decline(): Promise<void>;
254
362
  }
@@ -363,6 +471,27 @@ export interface UseChatResult {
363
471
  *
364
472
  * @param prompt - The prompt to send.
365
473
  * @returns Promise resolving once Base44 accepts the prompt, or once the send fails and sets [`error`](#error). It never rejects.
474
+ *
475
+ * @example
476
+ * ```tsx
477
+ * // Send the prompt from a form
478
+ * function PromptForm({ chat }: { chat: UseChatResult }) {
479
+ * const [prompt, setPrompt] = useState("");
480
+ * return (
481
+ * <form
482
+ * onSubmit={(event) => {
483
+ * event.preventDefault();
484
+ * chat.send(prompt);
485
+ * setPrompt("");
486
+ * }}
487
+ * >
488
+ * <input value={prompt} onChange={(event) => setPrompt(event.target.value)} />
489
+ * <button type="submit" disabled={!prompt.trim()}>Send</button>
490
+ * {chat.status === "building" && <small>The AI is working. New prompts wait in the queue.</small>}
491
+ * </form>
492
+ * );
493
+ * }
494
+ * ```
366
495
  */
367
496
  send(prompt: string): Promise<void>;
368
497
  /**
@@ -372,8 +501,30 @@ export interface UseChatResult {
372
501
  *
373
502
  * @param prompt - The first prompt, which describes the app.
374
503
  * @returns Promise resolving once the app exists, or once creating it fails and sets [`error`](#error). It never rejects.
504
+ *
505
+ * @example
506
+ * ```tsx
507
+ * // Create the app from the first prompt, and send the next prompts to it
508
+ * const [appId, setAppId] = useState<string | null>(null);
509
+ * const chat = useChat({ appId, backend, onAppCreated: (app) => setAppId(app.id) });
510
+ *
511
+ * const submit = (prompt: string) => (appId ? chat.send(prompt) : chat.create(prompt));
512
+ * ```
375
513
  */
376
514
  create(prompt: string): Promise<void>;
377
- /** Clears a failed call's or the connection's [`error`](#error). A failed build's error stays while Base44 reports it. */
515
+ /**
516
+ * Clears a failed call's or the connection's [`error`](#error). A failed build's error stays while Base44 reports it.
517
+ *
518
+ * @example
519
+ * ```tsx
520
+ * // Show the error, with a dismiss button unless the build failed
521
+ * {chat.error && (
522
+ * <div role="alert">
523
+ * {chat.error.message}
524
+ * {chat.error.code !== "build_failed" && <button onClick={chat.clearError}>Dismiss</button>}
525
+ * </div>
526
+ * )}
527
+ * ```
528
+ */
378
529
  clearError(): void;
379
530
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/platform",
3
- "version": "0.5.0-pr.346.ce5b5be",
3
+ "version": "0.5.0-pr.353.5c12c6c",
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",