@base44-preview/platform 0.5.0-pr.354.8f0539a → 0.5.0-pr.354.eeb83f0
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.
|
@@ -35,22 +35,17 @@ export declare function unknownKindToolCalls(sortedMessages: Message[]): {
|
|
|
35
35
|
}[];
|
|
36
36
|
/** @internal The ids of every tool call Base44 reports waiting. */
|
|
37
37
|
export declare function waitingToolCallIds(sortedMessages: Message[]): Set<string>;
|
|
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. */
|
|
38
|
+
/** @internal A prompt sent from this chat that Base44 has not confirmed, for the app it went to. */
|
|
40
39
|
export interface PendingPrompt {
|
|
41
40
|
id: string;
|
|
42
41
|
content: string;
|
|
43
42
|
createdAt: string;
|
|
44
43
|
appId: string;
|
|
45
|
-
queued: boolean;
|
|
46
44
|
}
|
|
47
45
|
/** @internal Prompts that arrived from Base44 as messages settle the pending ones with the same
|
|
48
46
|
* text. Base44's public send carries no client id, so text is the only link, and a prompt someone
|
|
49
47
|
* else sent to the same app never settles one of ours. */
|
|
50
48
|
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[];
|
|
54
49
|
/** @internal Pending prompts as items, drawn after the messages Base44 has. */
|
|
55
50
|
export declare function pendingPromptItems(pendingPrompts: PendingPrompt[]): ChatItem[];
|
|
56
51
|
/** @internal Base44's question formats, as one simple shape per kind, each bound to the call that
|
package/dist/react/chat-items.js
CHANGED
|
@@ -161,19 +161,6 @@ export function settlePendingPrompts(pendingPrompts, appId, arrivedPrompts) {
|
|
|
161
161
|
}
|
|
162
162
|
return stillPending;
|
|
163
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
|
-
}
|
|
177
164
|
/** @internal Pending prompts as items, drawn after the messages Base44 has. */
|
|
178
165
|
export function pendingPromptItems(pendingPrompts) {
|
|
179
166
|
return pendingPrompts.map(prompt => ({ id: prompt.id, role: "user", text: prompt.content, createdAt: prompt.createdAt, steps: [], pending: true }));
|
|
@@ -37,7 +37,9 @@ export interface ToolCallAnswer {
|
|
|
37
37
|
* finishes the turn, which can take minutes. Forward the request and return its result: the hook
|
|
38
38
|
* learns from the live updates as soon as Base44 has the prompt or the answer, and a failure after
|
|
39
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).
|
|
40
|
+
* before then sets [`error`](#error). Next.js server actions run one at a time, so one that waits
|
|
41
|
+
* out the turn holds up every later call: resolve it once Base44 hasn't refused the request
|
|
42
|
+
* within a few seconds. Base44 refuses at once.
|
|
41
43
|
*
|
|
42
44
|
* @example
|
|
43
45
|
* ```typescript
|
package/dist/react/useChat.js
CHANGED
|
@@ -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,
|
|
4
|
+
import { isWaitingForUser, 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.
|
|
@@ -72,7 +72,8 @@ export function useChat({ appId, backend, onAppCreated }) {
|
|
|
72
72
|
// refusal. Each entry holds what resolves the action.
|
|
73
73
|
// Tool calls answered from here, whose submission ends when Base44 stops reporting them waiting.
|
|
74
74
|
const answersAwaitingBase44 = useRef(new Map());
|
|
75
|
-
// Prompts sent from here, by pending id, until Base44's copy settles them
|
|
75
|
+
// Prompts sent from here, by pending id, until Base44's copy settles them. A prompt Base44 queues
|
|
76
|
+
// needs none: Base44 answers that send at once.
|
|
76
77
|
const promptsAwaitingBase44 = useRef(new Map());
|
|
77
78
|
// The tool calls Base44 reports waiting, as of the last render.
|
|
78
79
|
const waitingToolCalls = useRef(new Set());
|
|
@@ -149,11 +150,6 @@ export function useChat({ appId, backend, onAppCreated }) {
|
|
|
149
150
|
setPendingPrompts(prompts => settlePendingPrompts(prompts, followedAppId, arrivedPrompts));
|
|
150
151
|
}
|
|
151
152
|
};
|
|
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
|
-
};
|
|
157
153
|
// A snapshot replaces the conversation when it is the first, or follows a rewrite of main
|
|
158
154
|
// (undo, restore, sync); after a plain rejoin the messages before its window stay.
|
|
159
155
|
let nextSnapshotReplaces = true;
|
|
@@ -196,10 +192,8 @@ export function useChat({ appId, backend, onAppCreated }) {
|
|
|
196
192
|
});
|
|
197
193
|
chatSession.subscribe(followedAppId, {
|
|
198
194
|
onSnapshot: snapshot => {
|
|
199
|
-
var _a;
|
|
200
195
|
// A snapshot holds old prompts too, so only an exact match settles one.
|
|
201
196
|
handleIncomingMessages(snapshot.messages);
|
|
202
|
-
handleQueue((_a = snapshot.queue) === null || _a === void 0 ? void 0 : _a.items);
|
|
203
197
|
const replaceMessages = nextSnapshotReplaces;
|
|
204
198
|
nextSnapshotReplaces = false;
|
|
205
199
|
setMessages(heldMessages => (replaceMessages ? snapshot.messages : mergeSnapshot(heldMessages, snapshot.messages)));
|
|
@@ -224,10 +218,8 @@ export function useChat({ appId, backend, onAppCreated }) {
|
|
|
224
218
|
nextSnapshotReplaces = true;
|
|
225
219
|
// A prompt sent while the AI is working waits in Base44's queue: Base44 has it, and it
|
|
226
220
|
// stays pending until it runs.
|
|
227
|
-
if (event.type === "queue.updated" && event.data.branch_id == null)
|
|
221
|
+
if (event.type === "queue.updated" && event.data.branch_id == null)
|
|
228
222
|
setSubmittedTo(null);
|
|
229
|
-
handleQueue(event.data.items);
|
|
230
|
-
}
|
|
231
223
|
},
|
|
232
224
|
// Only snapshot_unavailable leaves the subscription running.
|
|
233
225
|
onError: error => (error.code === "snapshot_unavailable" ? reportConnectionError(error) : endLiveUpdates(error)),
|
|
@@ -307,14 +299,15 @@ export function useChat({ appId, backend, onAppCreated }) {
|
|
|
307
299
|
if (answerTaken)
|
|
308
300
|
setSubmittedTo(target => (target === followedAppIdRef.current ? null : target));
|
|
309
301
|
}, [sortedMessages]);
|
|
310
|
-
// A prompt's send ends once Base44
|
|
311
|
-
//
|
|
302
|
+
// A prompt's send ends once Base44's copy settled the pending prompt. A prompt not shown yet is
|
|
303
|
+
// still on its way to the list, not settled.
|
|
312
304
|
useEffect(() => {
|
|
313
305
|
for (const [promptId, sentPrompt] of promptsAwaitingBase44.current) {
|
|
314
|
-
|
|
315
|
-
if (pendingPrompt)
|
|
306
|
+
if (pendingPrompts.some(prompt => prompt.id === promptId)) {
|
|
316
307
|
sentPrompt.shown = true;
|
|
317
|
-
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
if (!sentPrompt.shown)
|
|
318
311
|
continue;
|
|
319
312
|
promptsAwaitingBase44.current.delete(promptId);
|
|
320
313
|
sentPrompt.resolve();
|
|
@@ -331,7 +324,7 @@ export function useChat({ appId, backend, onAppCreated }) {
|
|
|
331
324
|
else if (submissionInFlight)
|
|
332
325
|
status = "submitted";
|
|
333
326
|
const addPendingPrompt = useCallback((content, targetAppId) => {
|
|
334
|
-
const pendingPrompt = { id: `pending-${++pendingPromptCount.current}`, content, createdAt: new Date().toISOString(), appId: targetAppId
|
|
327
|
+
const pendingPrompt = { id: `pending-${++pendingPromptCount.current}`, content, createdAt: new Date().toISOString(), appId: targetAppId };
|
|
335
328
|
setPendingPrompts(prompts => [...prompts, pendingPrompt]);
|
|
336
329
|
return pendingPrompt;
|
|
337
330
|
}, []);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base44-preview/platform",
|
|
3
|
-
"version": "0.5.0-pr.354.
|
|
3
|
+
"version": "0.5.0-pr.354.eeb83f0",
|
|
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",
|