@base44-preview/platform 0.2.0-pr.315.69f7032 → 0.2.0-pr.315.6eb7ed3
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 +6 -8
- package/dist/client/modules/builder-socket.d.ts +0 -1
- package/dist/client/modules/builder-socket.js +5 -19
- package/dist/client/modules/builder.types.d.ts +0 -6
- package/dist/react/chat-items.d.ts +28 -23
- package/dist/react/chat-items.js +114 -74
- package/dist/react/chat.types.d.ts +202 -104
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +1 -1
- package/dist/react/useBase44Chat.d.ts +17 -17
- package/dist/react/useBase44Chat.js +203 -171
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -101,8 +101,7 @@ their exceptions are isolated so they cannot interrupt another app's delivery.
|
|
|
101
101
|
|
|
102
102
|
- `PlatformClient` (`client.types.ts`): the `builder` module.
|
|
103
103
|
- `BuilderModule` (`modules/builder.types.ts`): lazy `init(options)` factory.
|
|
104
|
-
- `BuilderInitOptions`: `getSession
|
|
105
|
-
`onConnectionChange` that reports `connected` and `reconnecting`.
|
|
104
|
+
- `BuilderInitOptions`: `getSession` and the connection-level `onError` observer.
|
|
106
105
|
- `SocketSession`: the `session_token`, `socket_url` and `socket_path` that `getSession` returns.
|
|
107
106
|
- `BuilderSession`: `connect()`, `subscribe(appId, options)`, `close()`.
|
|
108
107
|
- `SubscriptionOptions`: required `onSnapshot`, `onEvent` and `onError`.
|
|
@@ -192,10 +191,9 @@ chat.items.map((item) =>
|
|
|
192
191
|
`openLiveSession`, `sendMessage` and `submitToolCallInput`, each wrapping one Base44 REST
|
|
193
192
|
call with your credentials, so the browser never holds a key. The hook returns `items`, a
|
|
194
193
|
`status` (`ready`, `submitted`, `building`, `waiting`, `error`), a `connection` (`connecting`,
|
|
195
|
-
`connected`, `
|
|
194
|
+
`connected`, `disconnected`), an `error`, and the actions `send`, `create` and `clearError`. `send` needs an app; `create` makes
|
|
196
195
|
the first, and the chat watches it while `appId` is `null`. A sent prompt shows at once as a
|
|
197
|
-
`pending` item
|
|
198
|
-
|
|
199
|
-
actions its kind allows
|
|
200
|
-
declined for you. Every shape has JSDoc in `src/react/chat.types.ts
|
|
201
|
-
[`examples/react-chat/`](examples/react-chat) shows Tiny Sunny's chat built on it, with its `backend`.
|
|
196
|
+
`pending` item until Base44's own message arrives; a prompt sent mid-build waits in Base44's
|
|
197
|
+
queue meanwhile. A question is a union on `kind` (`choice`, `secrets`, `approval`) and carries only the
|
|
198
|
+
actions its kind allows, and declining is always one of them. As in Base44's builder, only the
|
|
199
|
+
last assistant message makes the chat wait; a kind this release doesn't know is declined for you. Every shape has JSDoc in `src/react/chat.types.ts`.
|
|
@@ -11,7 +11,7 @@ export class BuilderSocket {
|
|
|
11
11
|
this.tokenFresh = false;
|
|
12
12
|
this.denialRetries = 0;
|
|
13
13
|
this.authAttempt = 0;
|
|
14
|
-
this.options = { getSession: options.getSession, onError: options.onError
|
|
14
|
+
this.options = { getSession: options.getSession, onError: options.onError };
|
|
15
15
|
}
|
|
16
16
|
/** Connect with the session's token. Resolves on CONNECT, before snapshots arrive.
|
|
17
17
|
* The first call fetches the session, whose address the socket opens on.
|
|
@@ -94,22 +94,15 @@ export class BuilderSocket {
|
|
|
94
94
|
this.join(subscription);
|
|
95
95
|
(_a = this.resolveConnect) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
96
96
|
this.clearConnecting();
|
|
97
|
-
this.connectionChanged("connected");
|
|
98
97
|
});
|
|
99
98
|
socket.on("disconnect", (reason) => {
|
|
100
99
|
++this.authAttempt;
|
|
101
|
-
if (this.closed || reason
|
|
102
|
-
return;
|
|
103
|
-
if (reason !== "io server disconnect") {
|
|
104
|
-
this.connectionChanged("reconnecting");
|
|
105
|
-
return;
|
|
106
|
-
} // Transport loss reconnects by itself.
|
|
100
|
+
if (this.closed || reason !== "io server disconnect")
|
|
101
|
+
return; // Transport loss reconnects by itself.
|
|
107
102
|
const ending = this.ending;
|
|
108
103
|
this.ending = undefined;
|
|
109
|
-
if (ending === "session_expired")
|
|
110
|
-
|
|
111
|
-
socket.connect();
|
|
112
|
-
}
|
|
104
|
+
if (ending === "session_expired")
|
|
105
|
+
socket.connect(); // Renew through getSession.
|
|
113
106
|
else
|
|
114
107
|
this.connectionError(new PlatformSocketError(ending !== null && ending !== void 0 ? ending : "connection_failed"));
|
|
115
108
|
});
|
|
@@ -233,13 +226,6 @@ export class BuilderSocket {
|
|
|
233
226
|
this.resolveConnect = undefined;
|
|
234
227
|
this.rejectConnect = undefined;
|
|
235
228
|
}
|
|
236
|
-
connectionChanged(state) {
|
|
237
|
-
var _a, _b;
|
|
238
|
-
try {
|
|
239
|
-
(_b = (_a = this.options).onConnectionChange) === null || _b === void 0 ? void 0 : _b.call(_a, state);
|
|
240
|
-
}
|
|
241
|
-
catch ( /* An observer cannot interrupt the connection. */_c) { /* An observer cannot interrupt the connection. */ }
|
|
242
|
-
}
|
|
243
229
|
connectionError(error) {
|
|
244
230
|
var _a;
|
|
245
231
|
(_a = this.rejectConnect) === null || _a === void 0 ? void 0 : _a.call(this, error);
|
|
@@ -34,12 +34,6 @@ export interface BuilderInitOptions {
|
|
|
34
34
|
* [error codes](/developers/references/platform-sdk/docs/classes/PlatformSocketError#platformsocketerrorcode).
|
|
35
35
|
*/
|
|
36
36
|
onError: (error: PlatformSocketError) => void;
|
|
37
|
-
/**
|
|
38
|
-
* Called when the socket connects, and when a connected socket drops and will retry.
|
|
39
|
-
* `reconnecting` arrives on a lost connection or an expired session that renews; `connected`
|
|
40
|
-
* on every successful connect. A retry that gives up reports through `onError` instead.
|
|
41
|
-
*/
|
|
42
|
-
onConnectionChange?: (state: "connected" | "reconnecting") => void;
|
|
43
37
|
}
|
|
44
38
|
/**
|
|
45
39
|
* Builder module for following the AI chat in your users' apps live.
|
|
@@ -1,31 +1,36 @@
|
|
|
1
1
|
import type { Message } from "../client/modules/builder.events.generated.js";
|
|
2
2
|
import type { ToolCall } from "../client/modules/builder.events.types.js";
|
|
3
3
|
import type { ChatItem, ChatQuestion, ChatStep } from "./chat.types.js";
|
|
4
|
-
/** @internal
|
|
5
|
-
export type
|
|
6
|
-
/** @internal
|
|
7
|
-
export type
|
|
4
|
+
/** @internal Sends the answer to the one tool call a question belongs to. */
|
|
5
|
+
export type AnswerToolCall = (approve: boolean, extraUserInput?: Record<string, unknown>) => Promise<void>;
|
|
6
|
+
/** @internal Sends an answer to a given tool call in a given message. */
|
|
7
|
+
export type SubmitAnswer = (toolCallId: string, messageId: string, approve: boolean, extraUserInput?: Record<string, unknown>) => Promise<void>;
|
|
8
8
|
/** @internal Events can arrive out of order, so messages are ordered by when they were created. */
|
|
9
9
|
export declare function sortMessages(messages: Message[]): Message[];
|
|
10
10
|
/** @internal Replaces the message with the same id in place, or adds it at the end. */
|
|
11
|
-
export declare function mergeMessage(
|
|
11
|
+
export declare function mergeMessage(messages: Message[], updatedMessage: Message): Message[];
|
|
12
12
|
/** @internal How many of the newest messages a snapshot holds. */
|
|
13
13
|
export declare const SNAPSHOT_SIZE = 50;
|
|
14
14
|
/** @internal A rejoin's snapshot holds only the newest messages: it is the truth for its window,
|
|
15
15
|
* and the messages before its oldest one stay. A snapshot with room to spare holds them all. */
|
|
16
|
-
export declare function mergeSnapshot(
|
|
17
|
-
/** @internal Turns sorted messages into items.
|
|
18
|
-
*
|
|
19
|
-
|
|
16
|
+
export declare function mergeSnapshot(heldMessages: Message[], snapshotMessages: Message[]): Message[];
|
|
17
|
+
/** @internal Turns sorted messages into items. A waiting tool call that is not answered yet and is
|
|
18
|
+
* of a kind this release knows carries its own question, in the last turn reply only: the one that
|
|
19
|
+
* makes the chat wait. Older waiting calls keep their status but no question. */
|
|
20
|
+
export declare function toItems(sortedMessages: Message[], answeredToolCallIds: string[], submitAnswer: SubmitAnswer): ChatItem[];
|
|
20
21
|
/** @internal Base44's tool call status, as a step's. */
|
|
21
|
-
export declare function stepStatus(
|
|
22
|
-
/** @internal Whether
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
export declare function stepStatus(toolCall: ToolCall): ChatStep["status"];
|
|
23
|
+
/** @internal Whether the chat waits on the user. Like Base44's builder, only the last turn reply
|
|
24
|
+
* counts, and a call answered or declined here stops counting. */
|
|
25
|
+
export declare function isWaitingForUser(sortedMessages: Message[], answeredToolCallIds: string[]): boolean;
|
|
26
|
+
/** @internal Waiting calls on the last turn reply whose kind Base44 names and this release doesn't
|
|
27
|
+
* know, to decline. A call with no kind comes only from old messages and is left alone. */
|
|
28
|
+
export declare function unknownKindToolCalls(sortedMessages: Message[]): {
|
|
26
29
|
toolCallId: string;
|
|
27
30
|
messageId: string;
|
|
28
31
|
}[];
|
|
32
|
+
/** @internal The ids of every tool call Base44 reports waiting. */
|
|
33
|
+
export declare function waitingToolCallIds(sortedMessages: Message[]): Set<string>;
|
|
29
34
|
/** @internal A prompt sent from this chat that Base44 has not confirmed, for the app it went to. */
|
|
30
35
|
export interface PendingPrompt {
|
|
31
36
|
id: string;
|
|
@@ -33,14 +38,14 @@ export interface PendingPrompt {
|
|
|
33
38
|
createdAt: string;
|
|
34
39
|
appId: string;
|
|
35
40
|
}
|
|
36
|
-
/** @internal Prompts that arrived from Base44 as messages settle the pending ones
|
|
37
|
-
*
|
|
38
|
-
* `
|
|
39
|
-
* on the way never stays pending. */
|
|
40
|
-
export declare function
|
|
41
|
-
/** @internal Pending prompts as items, after the messages Base44 has. */
|
|
42
|
-
export declare function
|
|
43
|
-
/** @internal Base44's question formats, as one simple shape per kind, each bound to the
|
|
41
|
+
/** @internal Prompts that arrived from Base44 as messages settle the pending ones with the same
|
|
42
|
+
* text. Base44's public send carries no client id, so text is the only link. With
|
|
43
|
+
* `settleOldestIfUnmatched`, an arrival that matches none settles the oldest, so a prompt Base44
|
|
44
|
+
* changed on the way never stays pending. */
|
|
45
|
+
export declare function settlePendingPrompts(pendingPrompts: PendingPrompt[], appId: string, arrivedPrompts: string[], settleOldestIfUnmatched: boolean): PendingPrompt[];
|
|
46
|
+
/** @internal Pending prompts as items, drawn after the messages Base44 has. */
|
|
47
|
+
export declare function pendingPromptItems(pendingPrompts: PendingPrompt[]): ChatItem[];
|
|
48
|
+
/** @internal Base44's question formats, as one simple shape per kind, each bound to the call that
|
|
44
49
|
* answers it. Base44 keys choice answers by position, so `picked` follows `questions`. A kind this
|
|
45
50
|
* release doesn't know has no shape. */
|
|
46
|
-
export declare function
|
|
51
|
+
export declare function toQuestion(toolCall: ToolCall, answerToolCall: AnswerToolCall): ChatQuestion | undefined;
|
package/dist/react/chat-items.js
CHANGED
|
@@ -1,134 +1,174 @@
|
|
|
1
1
|
/** @internal Events can arrive out of order, so messages are ordered by when they were created. */
|
|
2
2
|
export function sortMessages(messages) {
|
|
3
|
-
return [...messages].sort((
|
|
3
|
+
return [...messages].sort((first, second) => { var _a, _b, _c, _d; return ((_b = (_a = first.metadata) === null || _a === void 0 ? void 0 : _a.created_date) !== null && _b !== void 0 ? _b : "").localeCompare((_d = (_c = second.metadata) === null || _c === void 0 ? void 0 : _c.created_date) !== null && _d !== void 0 ? _d : ""); });
|
|
4
4
|
}
|
|
5
5
|
/** @internal Replaces the message with the same id in place, or adds it at the end. */
|
|
6
|
-
export function mergeMessage(
|
|
7
|
-
|
|
6
|
+
export function mergeMessage(messages, updatedMessage) {
|
|
7
|
+
const isKnown = messages.some(message => message.id === updatedMessage.id);
|
|
8
|
+
if (!isKnown)
|
|
9
|
+
return [...messages, updatedMessage];
|
|
10
|
+
return messages.map(message => (message.id === updatedMessage.id ? updatedMessage : message));
|
|
8
11
|
}
|
|
9
12
|
/** @internal How many of the newest messages a snapshot holds. */
|
|
10
13
|
export const SNAPSHOT_SIZE = 50;
|
|
11
14
|
/** @internal A rejoin's snapshot holds only the newest messages: it is the truth for its window,
|
|
12
15
|
* and the messages before its oldest one stay. A snapshot with room to spare holds them all. */
|
|
13
|
-
export function mergeSnapshot(
|
|
16
|
+
export function mergeSnapshot(heldMessages, snapshotMessages) {
|
|
14
17
|
var _a, _b, _c;
|
|
15
|
-
if (
|
|
16
|
-
return
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
18
|
+
if (snapshotMessages.length < SNAPSHOT_SIZE)
|
|
19
|
+
return snapshotMessages;
|
|
20
|
+
const oldestSnapshotDate = (_c = (_b = (_a = sortMessages(snapshotMessages)[0]) === null || _a === void 0 ? void 0 : _a.metadata) === null || _b === void 0 ? void 0 : _b.created_date) !== null && _c !== void 0 ? _c : "";
|
|
21
|
+
const snapshotIds = new Set(snapshotMessages.map(message => message.id));
|
|
22
|
+
const olderMessages = heldMessages.filter(message => { var _a, _b; return !snapshotIds.has(message.id) && ((_b = (_a = message.metadata) === null || _a === void 0 ? void 0 : _a.created_date) !== null && _b !== void 0 ? _b : "") < oldestSnapshotDate; });
|
|
23
|
+
return [...olderMessages, ...snapshotMessages];
|
|
20
24
|
}
|
|
21
|
-
/** @internal
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return
|
|
25
|
+
/** @internal An assistant message that answers a turn. Base44 injects notices that expect no reply. */
|
|
26
|
+
function isTurnReply(message) {
|
|
27
|
+
var _a;
|
|
28
|
+
return (message === null || message === void 0 ? void 0 : message.role) === "assistant" && !((_a = message.additional_message_params) === null || _a === void 0 ? void 0 : _a.skip_ai_response);
|
|
29
|
+
}
|
|
30
|
+
/** @internal The last assistant message that answers a turn, as Base44's own builder finds it. */
|
|
31
|
+
function lastTurnReply(sortedMessages) {
|
|
32
|
+
return [...sortedMessages].reverse().find(isTurnReply);
|
|
33
|
+
}
|
|
34
|
+
/** @internal Turns sorted messages into items. A waiting tool call that is not answered yet and is
|
|
35
|
+
* of a kind this release knows carries its own question, in the last turn reply only: the one that
|
|
36
|
+
* makes the chat wait. Older waiting calls keep their status but no question. */
|
|
37
|
+
export function toItems(sortedMessages, answeredToolCallIds, submitAnswer) {
|
|
38
|
+
const lastReply = lastTurnReply(sortedMessages);
|
|
39
|
+
return sortedMessages.map(message => {
|
|
25
40
|
var _a, _b, _c, _d;
|
|
26
41
|
return ({
|
|
27
|
-
id:
|
|
28
|
-
role:
|
|
29
|
-
text: (_a =
|
|
30
|
-
createdAt: (_c = (_b =
|
|
42
|
+
id: message.id,
|
|
43
|
+
role: message.role === "user" ? "user" : "assistant",
|
|
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 : "",
|
|
31
46
|
pending: false,
|
|
32
|
-
steps: ((_d =
|
|
47
|
+
steps: ((_d = message.tool_calls) !== null && _d !== void 0 ? _d : []).map(toolCall => {
|
|
48
|
+
const isAnswerable = message === lastReply && !answeredToolCallIds.includes(toolCall.id);
|
|
49
|
+
const answerToolCall = isAnswerable
|
|
50
|
+
? (approve, extraUserInput) => submitAnswer(toolCall.id, message.id, approve, extraUserInput)
|
|
51
|
+
: undefined;
|
|
52
|
+
return toStep(toolCall, answerToolCall);
|
|
53
|
+
}),
|
|
33
54
|
});
|
|
34
55
|
});
|
|
35
56
|
}
|
|
36
|
-
function toStep(
|
|
57
|
+
function toStep(toolCall, answerToolCall) {
|
|
37
58
|
var _a, _b;
|
|
38
|
-
const
|
|
59
|
+
const toolName = (_a = toolCall.name) !== null && _a !== void 0 ? _a : "";
|
|
39
60
|
// Only file tools carry `display.file_paths`.
|
|
40
|
-
const display = "display" in
|
|
61
|
+
const display = "display" in toolCall ? toolCall.display : undefined;
|
|
41
62
|
const files = (_b = display === null || display === void 0 ? void 0 : display.file_paths) !== null && _b !== void 0 ? _b : [];
|
|
42
|
-
const status = stepStatus(
|
|
43
|
-
const question = status === "waiting" &&
|
|
44
|
-
return { id:
|
|
63
|
+
const status = stepStatus(toolCall);
|
|
64
|
+
const question = status === "waiting" && answerToolCall ? toQuestion(toolCall, answerToolCall) : undefined;
|
|
65
|
+
return { id: toolCall.id, tool: toolName, files, label: [toolName, ...files].join(" "), status, ...(question && { question }) };
|
|
45
66
|
}
|
|
46
67
|
/** @internal Base44's tool call status, as a step's. */
|
|
47
|
-
export function stepStatus(
|
|
48
|
-
if (
|
|
68
|
+
export function stepStatus(toolCall) {
|
|
69
|
+
if (toolCall.status === "running")
|
|
49
70
|
return "running";
|
|
50
|
-
if (
|
|
71
|
+
if (toolCall.status === "waiting_for_user_input")
|
|
51
72
|
return "waiting";
|
|
52
|
-
if (
|
|
73
|
+
if (toolCall.status === "stopped")
|
|
53
74
|
return "stopped";
|
|
54
|
-
if (
|
|
75
|
+
if (toolCall.status === "error")
|
|
55
76
|
return "error";
|
|
56
77
|
return "done";
|
|
57
78
|
}
|
|
58
|
-
/** @internal Whether
|
|
59
|
-
|
|
60
|
-
|
|
79
|
+
/** @internal Whether the chat waits on the user. Like Base44's builder, only the last turn reply
|
|
80
|
+
* counts, and a call answered or declined here stops counting. */
|
|
81
|
+
export function isWaitingForUser(sortedMessages, answeredToolCallIds) {
|
|
82
|
+
var _a;
|
|
83
|
+
const lastReply = lastTurnReply(sortedMessages);
|
|
84
|
+
return !!((_a = lastReply === null || lastReply === void 0 ? void 0 : lastReply.tool_calls) === null || _a === void 0 ? void 0 : _a.some(toolCall => toolCall.status === "waiting_for_user_input" && !answeredToolCallIds.includes(toolCall.id)));
|
|
61
85
|
}
|
|
62
|
-
const
|
|
63
|
-
/** @internal Waiting
|
|
64
|
-
|
|
65
|
-
|
|
86
|
+
const KNOWN_QUESTION_KINDS = ["approval", "choice", "input"];
|
|
87
|
+
/** @internal Waiting calls on the last turn reply whose kind Base44 names and this release doesn't
|
|
88
|
+
* know, to decline. A call with no kind comes only from old messages and is left alone. */
|
|
89
|
+
export function unknownKindToolCalls(sortedMessages) {
|
|
90
|
+
var _a;
|
|
91
|
+
const lastReply = lastTurnReply(sortedMessages);
|
|
92
|
+
if (!lastReply)
|
|
93
|
+
return [];
|
|
94
|
+
return ((_a = lastReply.tool_calls) !== null && _a !== void 0 ? _a : [])
|
|
95
|
+
.filter(toolCall => {
|
|
66
96
|
var _a;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
97
|
+
const kind = (_a = toolCall.waiting_on) === null || _a === void 0 ? void 0 : _a.kind;
|
|
98
|
+
return toolCall.status === "waiting_for_user_input" && !!kind && !KNOWN_QUESTION_KINDS.includes(kind);
|
|
99
|
+
})
|
|
100
|
+
.map(toolCall => ({ toolCallId: toolCall.id, messageId: lastReply.id }));
|
|
71
101
|
}
|
|
72
|
-
/** @internal
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
102
|
+
/** @internal The ids of every tool call Base44 reports waiting. */
|
|
103
|
+
export function waitingToolCallIds(sortedMessages) {
|
|
104
|
+
return new Set(sortedMessages.flatMap(message => { var _a; return ((_a = message.tool_calls) !== null && _a !== void 0 ? _a : []).filter(toolCall => toolCall.status === "waiting_for_user_input").map(toolCall => toolCall.id); }));
|
|
105
|
+
}
|
|
106
|
+
/** @internal Prompts that arrived from Base44 as messages settle the pending ones with the same
|
|
107
|
+
* text. Base44's public send carries no client id, so text is the only link. With
|
|
108
|
+
* `settleOldestIfUnmatched`, an arrival that matches none settles the oldest, so a prompt Base44
|
|
109
|
+
* changed on the way never stays pending. */
|
|
110
|
+
export function settlePendingPrompts(pendingPrompts, appId, arrivedPrompts, settleOldestIfUnmatched) {
|
|
111
|
+
let stillPending = pendingPrompts;
|
|
112
|
+
for (const arrivedPrompt of arrivedPrompts) {
|
|
113
|
+
const pendingForApp = stillPending.filter(prompt => prompt.appId === appId);
|
|
114
|
+
const exactMatch = pendingForApp.find(prompt => prompt.content.trim() === arrivedPrompt.trim());
|
|
115
|
+
const settled = exactMatch !== null && exactMatch !== void 0 ? exactMatch : (settleOldestIfUnmatched ? pendingForApp[0] : undefined);
|
|
116
|
+
if (settled)
|
|
117
|
+
stillPending = stillPending.filter(prompt => prompt !== settled);
|
|
84
118
|
}
|
|
85
|
-
return
|
|
119
|
+
return stillPending;
|
|
86
120
|
}
|
|
87
|
-
/** @internal Pending prompts as items, after the messages Base44 has. */
|
|
88
|
-
export function
|
|
89
|
-
return
|
|
121
|
+
/** @internal Pending prompts as items, drawn after the messages Base44 has. */
|
|
122
|
+
export function pendingPromptItems(pendingPrompts) {
|
|
123
|
+
return pendingPrompts.map(prompt => ({ id: prompt.id, role: "user", text: prompt.content, createdAt: prompt.createdAt, steps: [], pending: true }));
|
|
90
124
|
}
|
|
91
|
-
/** @internal Base44's question formats, as one simple shape per kind, each bound to the
|
|
125
|
+
/** @internal Base44's question formats, as one simple shape per kind, each bound to the call that
|
|
92
126
|
* answers it. Base44 keys choice answers by position, so `picked` follows `questions`. A kind this
|
|
93
127
|
* release doesn't know has no shape. */
|
|
94
|
-
export function
|
|
128
|
+
export function toQuestion(toolCall, answerToolCall) {
|
|
95
129
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
96
|
-
const kind = (_a =
|
|
97
|
-
const decline = () =>
|
|
130
|
+
const kind = (_a = toolCall.waiting_on) === null || _a === void 0 ? void 0 : _a.kind;
|
|
131
|
+
const decline = () => answerToolCall(false);
|
|
98
132
|
if (kind === "choice") {
|
|
99
|
-
const questions = (_c = (_b =
|
|
133
|
+
const questions = (_c = (_b = toolArguments(toolCall)) === null || _b === void 0 ? void 0 : _b.questions) !== null && _c !== void 0 ? _c : [];
|
|
100
134
|
return {
|
|
101
135
|
kind,
|
|
102
|
-
questions: questions.map(
|
|
136
|
+
questions: questions.map(question => {
|
|
103
137
|
var _a, _b;
|
|
104
138
|
return ({
|
|
105
|
-
text: (_a =
|
|
106
|
-
description:
|
|
107
|
-
options: ((_b =
|
|
108
|
-
multi: !!
|
|
139
|
+
text: (_a = question.question) !== null && _a !== void 0 ? _a : "",
|
|
140
|
+
description: question.description,
|
|
141
|
+
options: ((_b = question.options) !== null && _b !== void 0 ? _b : []).map(option => { var _a; return (typeof option === "string" ? option : (_a = option.label) !== null && _a !== void 0 ? _a : ""); }),
|
|
142
|
+
multi: !!question.multi_select,
|
|
109
143
|
});
|
|
110
144
|
}),
|
|
111
|
-
answer: picked =>
|
|
145
|
+
answer: picked => {
|
|
146
|
+
const answers = picked
|
|
147
|
+
.map((labels, questionIndex) => ({ question_index: questionIndex, selected_labels: labels }))
|
|
148
|
+
.filter(answer => answer.selected_labels.length);
|
|
149
|
+
return answerToolCall(true, { answers });
|
|
150
|
+
},
|
|
112
151
|
decline,
|
|
113
152
|
};
|
|
114
153
|
}
|
|
115
154
|
if (kind === "input") {
|
|
116
|
-
const
|
|
155
|
+
const secretFields = (_e = (_d = toolArguments(toolCall)) === null || _d === void 0 ? void 0 : _d.secrets_schema) !== null && _e !== void 0 ? _e : [];
|
|
117
156
|
return {
|
|
118
157
|
kind: "secrets",
|
|
119
|
-
fields:
|
|
120
|
-
submit: values =>
|
|
158
|
+
fields: secretFields.map(field => { var _a; return ({ name: (_a = field.secretName) !== null && _a !== void 0 ? _a : "", description: field.description }); }),
|
|
159
|
+
submit: values => answerToolCall(true, { secrets: values }),
|
|
121
160
|
decline,
|
|
122
161
|
};
|
|
123
162
|
}
|
|
124
163
|
if (kind === "approval") {
|
|
125
164
|
// Guards that declare a reason or a summary carry them; the others name only themselves.
|
|
126
|
-
const approval =
|
|
127
|
-
|
|
165
|
+
const approval = toolCall.approval;
|
|
166
|
+
const reason = (_h = (_f = approval === null || approval === void 0 ? void 0 : approval.reason) !== null && _f !== void 0 ? _f : (_g = approval === null || approval === void 0 ? void 0 : approval.details) === null || _g === void 0 ? void 0 : _g.summary) !== null && _h !== void 0 ? _h : "";
|
|
167
|
+
return { kind, action: (_j = toolCall.name) !== null && _j !== void 0 ? _j : "", reason, approve: () => answerToolCall(true), decline };
|
|
128
168
|
}
|
|
129
169
|
return undefined;
|
|
130
170
|
}
|
|
131
171
|
// The waiting kind says which arguments a call carries; the tool's name only narrows the union.
|
|
132
|
-
function
|
|
133
|
-
return "arguments" in
|
|
172
|
+
function toolArguments(toolCall) {
|
|
173
|
+
return "arguments" in toolCall ? toolCall.arguments : undefined;
|
|
134
174
|
}
|