@base44-preview/platform 0.5.0-pr.353.656b952 → 0.5.0-pr.354.8f0539a

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.
@@ -18,6 +18,10 @@ export declare function mergeSnapshot(heldMessages: Message[], snapshotMessages:
18
18
  * of a kind this release knows carries its own question, in the last turn reply only: the one that
19
19
  * makes the chat wait. Older waiting calls keep their status but no question. */
20
20
  export declare function toItems(sortedMessages: Message[], answeredToolCallIds: string[], submitAnswer: SubmitAnswer): ChatItem[];
21
+ /** @internal Base44 writes UTC with no zone, which `new Date()` would read as local time. The
22
+ * timestamp comes out with its `Z`, in the shape a pending prompt has. Anything but an ISO date and
23
+ * time is left as it is: `new Date()` guesses at other shapes. */
24
+ export declare function toUtcTimestamp(date: string | null | undefined): string;
21
25
  /** @internal Base44's tool call status, as a step's. */
22
26
  export declare function stepStatus(toolCall: ToolCall): ChatStep["status"];
23
27
  /** @internal Whether the chat waits on the user. Like Base44's app editor, only the last turn reply
@@ -31,17 +35,22 @@ export declare function unknownKindToolCalls(sortedMessages: Message[]): {
31
35
  }[];
32
36
  /** @internal The ids of every tool call Base44 reports waiting. */
33
37
  export declare function waitingToolCallIds(sortedMessages: Message[]): Set<string>;
34
- /** @internal A prompt sent from this chat that Base44 has not confirmed, for the app it went to. */
38
+ /** @internal A prompt sent from this chat that Base44 has not confirmed, for the app it went to.
39
+ * `queued` once Base44's queue holds it: Base44 has it, and it waits to run. */
35
40
  export interface PendingPrompt {
36
41
  id: string;
37
42
  content: string;
38
43
  createdAt: string;
39
44
  appId: string;
45
+ queued: boolean;
40
46
  }
41
47
  /** @internal Prompts that arrived from Base44 as messages settle the pending ones with the same
42
48
  * text. Base44's public send carries no client id, so text is the only link, and a prompt someone
43
49
  * else sent to the same app never settles one of ours. */
44
50
  export declare function settlePendingPrompts(pendingPrompts: PendingPrompt[], appId: string, arrivedPrompts: string[]): PendingPrompt[];
51
+ /** @internal Base44's queue for the app marks the pending prompts it holds, one queued prompt per
52
+ * pending one with the same text. Text is the only link here too. */
53
+ export declare function markQueuedPrompts(pendingPrompts: PendingPrompt[], appId: string, queuedPrompts: string[]): PendingPrompt[];
45
54
  /** @internal Pending prompts as items, drawn after the messages Base44 has. */
46
55
  export declare function pendingPromptItems(pendingPrompts: PendingPrompt[]): ChatItem[];
47
56
  /** @internal Base44's question formats, as one simple shape per kind, each bound to the call that
@@ -37,14 +37,14 @@ function lastTurnReply(sortedMessages) {
37
37
  export function toItems(sortedMessages, answeredToolCallIds, submitAnswer) {
38
38
  const lastReply = lastTurnReply(sortedMessages);
39
39
  return sortedMessages.map(message => {
40
- var _a, _b, _c, _d;
40
+ var _a, _b, _c;
41
41
  return ({
42
42
  id: message.id,
43
43
  role: message.role === "user" ? "user" : "assistant",
44
44
  text: (_a = message.content) !== null && _a !== void 0 ? _a : "",
45
- createdAt: (_c = (_b = message.metadata) === null || _b === void 0 ? void 0 : _b.created_date) !== null && _c !== void 0 ? _c : "",
45
+ createdAt: toUtcTimestamp((_b = message.metadata) === null || _b === void 0 ? void 0 : _b.created_date),
46
46
  pending: false,
47
- steps: ((_d = message.tool_calls) !== null && _d !== void 0 ? _d : []).map(toolCall => {
47
+ steps: ((_c = message.tool_calls) !== null && _c !== void 0 ? _c : []).map(toolCall => {
48
48
  const isAnswerable = message === lastReply && !answeredToolCallIds.includes(toolCall.id);
49
49
  const answerToolCall = isAnswerable
50
50
  ? (approve, extraUserInput) => submitAnswer(toolCall.id, message.id, approve, extraUserInput)
@@ -54,6 +54,18 @@ export function toItems(sortedMessages, answeredToolCallIds, submitAnswer) {
54
54
  });
55
55
  });
56
56
  }
57
+ /** @internal Base44 writes UTC with no zone, which `new Date()` would read as local time. The
58
+ * timestamp comes out with its `Z`, in the shape a pending prompt has. Anything but an ISO date and
59
+ * time is left as it is: `new Date()` guesses at other shapes. */
60
+ export function toUtcTimestamp(date) {
61
+ if (!date)
62
+ return "";
63
+ if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(date))
64
+ return date;
65
+ const hasZone = /(Z|[+-]\d{2}:?\d{2})$/i.test(date);
66
+ const parsed = new Date(hasZone ? date : `${date}Z`);
67
+ return Number.isNaN(parsed.getTime()) ? date : parsed.toISOString();
68
+ }
57
69
  function toStep(toolCall, answerToolCall) {
58
70
  var _a, _b, _c, _d;
59
71
  const toolName = (_a = toolCall.name) !== null && _a !== void 0 ? _a : "";
@@ -149,6 +161,19 @@ export function settlePendingPrompts(pendingPrompts, appId, arrivedPrompts) {
149
161
  }
150
162
  return stillPending;
151
163
  }
164
+ /** @internal Base44's queue for the app marks the pending prompts it holds, one queued prompt per
165
+ * pending one with the same text. Text is the only link here too. */
166
+ export function markQueuedPrompts(pendingPrompts, appId, queuedPrompts) {
167
+ const matched = new Set();
168
+ for (const queuedPrompt of queuedPrompts) {
169
+ const match = pendingPrompts.find(prompt => !matched.has(prompt) && prompt.appId === appId && prompt.content.trim() === queuedPrompt.trim());
170
+ if (match)
171
+ matched.add(match);
172
+ }
173
+ if ([...matched].every(prompt => prompt.queued))
174
+ return pendingPrompts;
175
+ return pendingPrompts.map(prompt => (matched.has(prompt) && !prompt.queued ? { ...prompt, queued: true } : prompt));
176
+ }
152
177
  /** @internal Pending prompts as items, drawn after the messages Base44 has. */
153
178
  export function pendingPromptItems(pendingPrompts) {
154
179
  return pendingPrompts.map(prompt => ({ id: prompt.id, role: "user", text: prompt.content, createdAt: prompt.createdAt, steps: [], pending: true }));
@@ -34,8 +34,10 @@ export interface ToolCallAnswer {
34
34
  * `X-Request-ID` built from the tool call ID, so a retry resumes the turn only once.
35
35
  *
36
36
  * Base44 keeps the Send chat message and Submit tool-call input requests open until the AI
37
- * finishes the turn. Resolve your call once Base44 accepts the request, not when it returns. The
38
- * chat follows the rest live. A rejected promise from any call sets [`error`](#error).
37
+ * finishes the turn, which can take minutes. Forward the request and return its result: the hook
38
+ * learns from the live updates as soon as Base44 has the prompt or the answer, and a failure after
39
+ * that, such as a timeout on your server, doesn't set an error. A rejected promise from any call
40
+ * before then sets [`error`](#error).
39
41
  *
40
42
  * @example
41
43
  * ```typescript
@@ -60,6 +62,22 @@ export interface ChatBackend {
60
62
  *
61
63
  * @param prompt - The first prompt, which describes the app.
62
64
  * @returns Promise resolving to the new app.
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * // Your server route for createApp(), with a personal access token
69
+ * export async function POST(request: Request) {
70
+ * const { prompt } = await request.json();
71
+ * const response = await fetch("https://app.base44.com/api/apps", {
72
+ * method: "POST",
73
+ * headers: { Authorization: `Bearer ${process.env.BASE44_ACCESS_TOKEN}`, "Content-Type": "application/json" },
74
+ * body: JSON.stringify({ initial_message: { content: prompt } }),
75
+ * });
76
+ * if (!response.ok) return new Response("Create app failed", { status: response.status });
77
+ * const app = await response.json();
78
+ * return Response.json({ id: app.id, name: app.name });
79
+ * }
80
+ * ```
63
81
  */
64
82
  createApp(prompt: string): Promise<ChatApp>;
65
83
  /**
@@ -68,6 +86,23 @@ export interface ChatBackend {
68
86
  *
69
87
  * @param appId - ID of the app to follow.
70
88
  * @returns Promise resolving to the session.
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * // Your server route for openLiveSession(), with a workspace API key
93
+ * export async function POST(request: Request) {
94
+ * const { appId } = await request.json();
95
+ * const response = await fetch("https://app.base44.com/api/v1/socket-sessions", {
96
+ * method: "POST",
97
+ * headers: { Authorization: `Bearer ${process.env.BASE44_API_KEY}`, "Content-Type": "application/json" },
98
+ * body: JSON.stringify({ app_ids: [appId] }),
99
+ * });
100
+ * if (!response.ok) return new Response("Create socket session failed", { status: response.status });
101
+ * const { session_token, socket_url, socket_path, session_id } = await response.json();
102
+ * await saveSession(appId, session_id); // Keep it on your server to change or end the session
103
+ * return Response.json({ session_token, socket_url, socket_path });
104
+ * }
105
+ * ```
71
106
  */
72
107
  openLiveSession(appId: string): Promise<SocketSession>;
73
108
  /**
@@ -78,15 +113,16 @@ export interface ChatBackend {
78
113
  *
79
114
  * @param appId - ID of the app.
80
115
  * @param content - The prompt.
81
- * @returns Promise resolving once Base44 accepts the prompt.
116
+ * @returns Promise resolving when Base44 answers the request, which can be when the turn ends.
82
117
  */
83
118
  sendMessage(appId: string, content: string): Promise<void>;
84
119
  /**
85
- * Answers or declines a question the AI waits on.
120
+ * Answers or declines a question the AI waits on. If Base44 refuses the answer, reject the
121
+ * promise. The hook then sets [`error`](#error) and shows the question again.
86
122
  *
87
123
  * @param appId - ID of the app.
88
124
  * @param answer - The tool call and the answer to it.
89
- * @returns Promise resolving once Base44 accepts the answer.
125
+ * @returns Promise resolving when Base44 answers the request, which can be when the turn ends.
90
126
  */
91
127
  submitToolCallInput(appId: string, answer: ToolCallAnswer): Promise<void>;
92
128
  }
@@ -99,9 +135,8 @@ export interface ChatItem {
99
135
  /** The message text, as raw markdown. Show it before the message's steps. It's empty when the message only holds tool calls. */
100
136
  text: string;
101
137
  /**
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`.
138
+ * When the message was created, as an ISO 8601 timestamp in UTC that ends in `Z`, such as
139
+ * `2026-10-25T11:00:00.000Z`. `new Date(createdAt)` reads it correctly in any time zone.
105
140
  */
106
141
  createdAt: string;
107
142
  /** One step per tool call, in order. */
@@ -214,6 +249,12 @@ export interface ChoiceQuestion {
214
249
  * Declines the question. The AI continues without the answer.
215
250
  *
216
251
  * @returns Promise resolving once Base44 accepts the decline, or once sending it fails and sets [`error`](#error). It never rejects.
252
+ *
253
+ * @example
254
+ * ```tsx
255
+ * // Skip the question
256
+ * <button onClick={question.decline}>Skip</button>
257
+ * ```
217
258
  */
218
259
  decline(): Promise<void>;
219
260
  }
@@ -266,6 +307,12 @@ export interface SecretsQuestion {
266
307
  * Declines the question. The AI continues without the values.
267
308
  *
268
309
  * @returns Promise resolving once Base44 accepts the decline, or once sending it fails and sets [`error`](#error). It never rejects.
310
+ *
311
+ * @example
312
+ * ```tsx
313
+ * // Skip without entering the secrets
314
+ * <button onClick={question.decline}>Skip</button>
315
+ * ```
269
316
  */
270
317
  decline(): Promise<void>;
271
318
  }
@@ -285,12 +332,33 @@ export interface ApprovalQuestion {
285
332
  * Lets the action run.
286
333
  *
287
334
  * @returns Promise resolving once Base44 accepts the approval, or once sending it fails and sets [`error`](#error). It never rejects.
335
+ *
336
+ * @example
337
+ * ```tsx
338
+ * // Show what the action would do, then allow or decline it
339
+ * function ApprovalPrompt({ question }: { question: ApprovalQuestion }) {
340
+ * return (
341
+ * <div>
342
+ * <p>The AI wants to run {question.action}.</p>
343
+ * {question.reason && <p>{question.reason}</p>}
344
+ * <button onClick={question.approve}>Allow</button>
345
+ * <button onClick={question.decline}>Decline</button>
346
+ * </div>
347
+ * );
348
+ * }
349
+ * ```
288
350
  */
289
351
  approve(): Promise<void>;
290
352
  /**
291
353
  * Declines the action. It never runs, and the AI continues.
292
354
  *
293
355
  * @returns Promise resolving once Base44 accepts the decline, or once sending it fails and sets [`error`](#error). It never rejects.
356
+ *
357
+ * @example
358
+ * ```tsx
359
+ * // Decline the action
360
+ * <button onClick={question.decline}>Decline</button>
361
+ * ```
294
362
  */
295
363
  decline(): Promise<void>;
296
364
  }
@@ -405,6 +473,27 @@ export interface UseChatResult {
405
473
  *
406
474
  * @param prompt - The prompt to send.
407
475
  * @returns Promise resolving once Base44 accepts the prompt, or once the send fails and sets [`error`](#error). It never rejects.
476
+ *
477
+ * @example
478
+ * ```tsx
479
+ * // Send the prompt from a form
480
+ * function PromptForm({ chat }: { chat: UseChatResult }) {
481
+ * const [prompt, setPrompt] = useState("");
482
+ * return (
483
+ * <form
484
+ * onSubmit={(event) => {
485
+ * event.preventDefault();
486
+ * chat.send(prompt);
487
+ * setPrompt("");
488
+ * }}
489
+ * >
490
+ * <input value={prompt} onChange={(event) => setPrompt(event.target.value)} />
491
+ * <button type="submit" disabled={!prompt.trim()}>Send</button>
492
+ * {chat.status === "building" && <small>The AI is working. New prompts wait in the queue.</small>}
493
+ * </form>
494
+ * );
495
+ * }
496
+ * ```
408
497
  */
409
498
  send(prompt: string): Promise<void>;
410
499
  /**
@@ -414,6 +503,15 @@ export interface UseChatResult {
414
503
  *
415
504
  * @param prompt - The first prompt, which describes the app.
416
505
  * @returns Promise resolving once the app exists, or once creating it fails and sets [`error`](#error). It never rejects.
506
+ *
507
+ * @example
508
+ * ```tsx
509
+ * // Create the app from the first prompt, and send the next prompts to it
510
+ * const [appId, setAppId] = useState<string | null>(null);
511
+ * const chat = useChat({ appId, backend, onAppCreated: (app) => setAppId(app.id) });
512
+ *
513
+ * const submit = (prompt: string) => (appId ? chat.send(prompt) : chat.create(prompt));
514
+ * ```
417
515
  */
418
516
  create(prompt: string): Promise<void>;
419
517
  /**
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
3
  import { createPlatformClient } from "../client/client.js";
4
- import { isWaitingForUser, mergeMessage, mergeSnapshot, pendingPromptItems, settlePendingPrompts, sortMessages, toItems, unknownKindToolCalls, waitingToolCallIds } from "./chat-items.js";
4
+ import { isWaitingForUser, markQueuedPrompts, mergeMessage, mergeSnapshot, pendingPromptItems, settlePendingPrompts, sortMessages, toItems, unknownKindToolCalls, waitingToolCallIds } from "./chat-items.js";
5
5
  // Base44's public status carries no reason, so a failed build has one error.
6
6
  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.
@@ -67,8 +67,15 @@ export function useChat({ appId, backend, onAppCreated }) {
67
67
  // Tool calls declined for the user, and those whose decline failed and may try again.
68
68
  const declinedToolCalls = useRef(new Set());
69
69
  const failedDeclines = useRef(new Set());
70
- // Tool calls answered from here whose submission ends when Base44 stops reporting them waiting.
71
- const answersAwaitingBase44 = useRef(new Set());
70
+ // Base44 keeps a send or an answer open until the turn ends, so the live updates say when Base44
71
+ // has it: that ends the action, and a failure after it, such as a timeout on the way, is no
72
+ // refusal. Each entry holds what resolves the action.
73
+ // Tool calls answered from here, whose submission ends when Base44 stops reporting them waiting.
74
+ const answersAwaitingBase44 = useRef(new Map());
75
+ // Prompts sent from here, by pending id, until Base44's copy settles them or its queue holds them.
76
+ const promptsAwaitingBase44 = useRef(new Map());
77
+ // The tool calls Base44 reports waiting, as of the last render.
78
+ const waitingToolCalls = useRef(new Set());
72
79
  // The app `create` made, shown while `appId` is null. Any change to `appId` forgets it.
73
80
  const [createdAppId, setCreatedAppId] = useState(null);
74
81
  const [previousAppIdProp, setPreviousAppIdProp] = useState(appId);
@@ -142,6 +149,11 @@ export function useChat({ appId, backend, onAppCreated }) {
142
149
  setPendingPrompts(prompts => settlePendingPrompts(prompts, followedAppId, arrivedPrompts));
143
150
  }
144
151
  };
152
+ const handleQueue = (queueItems) => {
153
+ const queuedPrompts = (queueItems !== null && queueItems !== void 0 ? queueItems : []).map(queueItem => { var _a; return (_a = queueItem.content) !== null && _a !== void 0 ? _a : ""; });
154
+ if (queuedPrompts.length)
155
+ setPendingPrompts(prompts => markQueuedPrompts(prompts, followedAppId, queuedPrompts));
156
+ };
145
157
  // A snapshot replaces the conversation when it is the first, or follows a rewrite of main
146
158
  // (undo, restore, sync); after a plain rejoin the messages before its window stay.
147
159
  let nextSnapshotReplaces = true;
@@ -184,8 +196,10 @@ export function useChat({ appId, backend, onAppCreated }) {
184
196
  });
185
197
  chatSession.subscribe(followedAppId, {
186
198
  onSnapshot: snapshot => {
199
+ var _a;
187
200
  // A snapshot holds old prompts too, so only an exact match settles one.
188
201
  handleIncomingMessages(snapshot.messages);
202
+ handleQueue((_a = snapshot.queue) === null || _a === void 0 ? void 0 : _a.items);
189
203
  const replaceMessages = nextSnapshotReplaces;
190
204
  nextSnapshotReplaces = false;
191
205
  setMessages(heldMessages => (replaceMessages ? snapshot.messages : mergeSnapshot(heldMessages, snapshot.messages)));
@@ -210,8 +224,10 @@ export function useChat({ appId, backend, onAppCreated }) {
210
224
  nextSnapshotReplaces = true;
211
225
  // A prompt sent while the AI is working waits in Base44's queue: Base44 has it, and it
212
226
  // stays pending until it runs.
213
- if (event.type === "queue.updated" && event.data.branch_id == null)
227
+ if (event.type === "queue.updated" && event.data.branch_id == null) {
214
228
  setSubmittedTo(null);
229
+ handleQueue(event.data.items);
230
+ }
215
231
  },
216
232
  // Only snapshot_unavailable leaves the subscription running.
217
233
  onError: error => (error.code === "snapshot_unavailable" ? reportConnectionError(error) : endLiveUpdates(error)),
@@ -223,8 +239,8 @@ export function useChat({ appId, backend, onAppCreated }) {
223
239
  chatSession.close();
224
240
  };
225
241
  }, [currentAppId]);
226
- // Answers one tool call. Its id leaves the answered list again if the submit fails, so the
227
- // question comes back.
242
+ // Answers one tool call. Its id leaves the answered list again if Base44 refuses the answer, so
243
+ // the question comes back.
228
244
  const submitAnswer = useCallback((toolCallId, messageId, approve, extraUserInput) => {
229
245
  if (!currentAppId)
230
246
  return Promise.resolve();
@@ -232,15 +248,19 @@ export function useChat({ appId, backend, onAppCreated }) {
232
248
  setActionError(null);
233
249
  setSubmittedTo(targetAppId);
234
250
  setAnsweredToolCallIds(ids => [...ids, toolCallId]);
235
- answersAwaitingBase44.current.add(toolCallId);
236
251
  const answer = { toolCallId, messageId, approve, extraUserInput };
237
- return backendRef.current.submitToolCallInput(targetAppId, answer).catch((error) => {
238
- answersAwaitingBase44.current.delete(toolCallId);
239
- if (!stillFollowing(targetAppId))
240
- return;
241
- setAnsweredToolCallIds(ids => ids.filter(answeredId => answeredId !== toolCallId));
242
- setSubmittedTo(null);
243
- reportActionError(error);
252
+ return new Promise(resolve => {
253
+ answersAwaitingBase44.current.set(toolCallId, resolve);
254
+ backendRef.current.submitToolCallInput(targetAppId, answer).then(resolve, (error) => {
255
+ resolve();
256
+ if (!answersAwaitingBase44.current.delete(toolCallId))
257
+ return;
258
+ if (!stillFollowing(targetAppId))
259
+ return;
260
+ setAnsweredToolCallIds(ids => ids.filter(answeredId => answeredId !== toolCallId));
261
+ setSubmittedTo(null);
262
+ reportActionError(error);
263
+ });
244
264
  });
245
265
  }, [currentAppId, reportActionError]);
246
266
  const sortedMessages = useMemo(() => sortMessages(messages), [messages]);
@@ -260,6 +280,9 @@ export function useChat({ appId, backend, onAppCreated }) {
260
280
  declinedToolCalls.current.add(declineKey);
261
281
  setAnsweredToolCallIds(ids => [...ids, toolCallId]);
262
282
  backendRef.current.submitToolCallInput(followedAppId, { toolCallId, messageId, approve: false }).catch((error) => {
283
+ // A call that no longer waits has the decline: the failure came after it.
284
+ if (!waitingToolCalls.current.has(toolCallId))
285
+ return;
263
286
  failedDeclines.current.add(declineKey);
264
287
  setAnsweredToolCallIds(ids => ids.filter(answeredId => answeredId !== toolCallId));
265
288
  reportActionError(error);
@@ -271,17 +294,32 @@ export function useChat({ appId, backend, onAppCreated }) {
271
294
  // An answer's submission ends there too: Base44 has taken it once the call no longer waits.
272
295
  useEffect(() => {
273
296
  const stillWaiting = waitingToolCallIds(sortedMessages);
297
+ waitingToolCalls.current = stillWaiting;
274
298
  setAnsweredToolCallIds(ids => (ids.every(answeredId => stillWaiting.has(answeredId)) ? ids : ids.filter(answeredId => stillWaiting.has(answeredId))));
275
299
  let answerTaken = false;
276
- for (const toolCallId of answersAwaitingBase44.current) {
300
+ for (const [toolCallId, resolveAnswer] of answersAwaitingBase44.current) {
277
301
  if (stillWaiting.has(toolCallId))
278
302
  continue;
279
303
  answersAwaitingBase44.current.delete(toolCallId);
304
+ resolveAnswer();
280
305
  answerTaken = true;
281
306
  }
282
307
  if (answerTaken)
283
308
  setSubmittedTo(target => (target === followedAppIdRef.current ? null : target));
284
309
  }, [sortedMessages]);
310
+ // A prompt's send ends once Base44 has it: its copy settled the pending prompt, or its queue holds
311
+ // it. A prompt not shown yet is still on its way to the list, not settled.
312
+ useEffect(() => {
313
+ for (const [promptId, sentPrompt] of promptsAwaitingBase44.current) {
314
+ const pendingPrompt = pendingPrompts.find(prompt => prompt.id === promptId);
315
+ if (pendingPrompt)
316
+ sentPrompt.shown = true;
317
+ if (pendingPrompt ? !pendingPrompt.queued : !sentPrompt.shown)
318
+ continue;
319
+ promptsAwaitingBase44.current.delete(promptId);
320
+ sentPrompt.resolve();
321
+ }
322
+ }, [pendingPrompts]);
285
323
  const submissionInFlight = (submittedTo === NEW_APP && !currentAppId) || (submittedTo !== null && submittedTo === currentAppId);
286
324
  let status = "ready";
287
325
  if (buildState === "error")
@@ -293,7 +331,7 @@ export function useChat({ appId, backend, onAppCreated }) {
293
331
  else if (submissionInFlight)
294
332
  status = "submitted";
295
333
  const addPendingPrompt = useCallback((content, targetAppId) => {
296
- const pendingPrompt = { id: `pending-${++pendingPromptCount.current}`, content, createdAt: new Date().toISOString(), appId: targetAppId };
334
+ const pendingPrompt = { id: `pending-${++pendingPromptCount.current}`, content, createdAt: new Date().toISOString(), appId: targetAppId, queued: false };
297
335
  setPendingPrompts(prompts => [...prompts, pendingPrompt]);
298
336
  return pendingPrompt;
299
337
  }, []);
@@ -306,12 +344,21 @@ export function useChat({ appId, backend, onAppCreated }) {
306
344
  setActionError(null);
307
345
  setSubmittedTo(targetAppId);
308
346
  const pendingPrompt = addPendingPrompt(prompt, targetAppId);
309
- return backendRef.current.sendMessage(targetAppId, prompt).catch((error) => {
310
- setPendingPrompts(prompts => prompts.filter(other => other !== pendingPrompt));
311
- if (!stillFollowing(targetAppId))
312
- return;
313
- setSubmittedTo(null);
314
- reportActionError(error);
347
+ return new Promise(resolve => {
348
+ promptsAwaitingBase44.current.set(pendingPrompt.id, { resolve, shown: false });
349
+ backendRef.current.sendMessage(targetAppId, prompt).then(() => {
350
+ promptsAwaitingBase44.current.delete(pendingPrompt.id);
351
+ resolve();
352
+ }, (error) => {
353
+ resolve();
354
+ if (!promptsAwaitingBase44.current.delete(pendingPrompt.id))
355
+ return;
356
+ setPendingPrompts(prompts => prompts.filter(other => other.id !== pendingPrompt.id));
357
+ if (!stillFollowing(targetAppId))
358
+ return;
359
+ setSubmittedTo(null);
360
+ reportActionError(error);
361
+ });
315
362
  });
316
363
  }, [currentAppId, reportActionError, addPendingPrompt]);
317
364
  const create = useCallback(async (prompt) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/platform",
3
- "version": "0.5.0-pr.353.656b952",
3
+ "version": "0.5.0-pr.354.8f0539a",
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",