@base44-preview/platform 0.2.0-pr.335.2bd5f4f → 0.2.0-pr.336.059c4cd
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 +68 -62
- package/dist/server/errors.d.ts +53 -0
- package/dist/server/errors.js +56 -0
- package/dist/server/errors.types.d.ts +60 -0
- package/dist/server/index.d.ts +6 -2
- package/dist/server/index.js +2 -1
- package/dist/server/modules/webhooks-signature.d.ts +11 -0
- package/dist/server/modules/webhooks-signature.js +65 -0
- package/dist/server/modules/webhooks.d.ts +3 -0
- package/dist/server/modules/webhooks.events.generated.d.ts +176 -0
- package/dist/server/modules/webhooks.events.generated.js +4 -0
- package/dist/server/modules/webhooks.js +91 -0
- package/dist/server/modules/webhooks.types.d.ts +218 -0
- package/dist/server/server.d.ts +28 -3
- package/dist/server/server.js +31 -7
- package/dist/server/server.types.d.ts +8 -8
- package/package.json +14 -28
- package/dist/react/Base44ChatProvider.d.ts +0 -43
- package/dist/react/Base44ChatProvider.js +0 -68
- package/dist/react/Message.d.ts +0 -39
- package/dist/react/Message.js +0 -55
- package/dist/react/chat-items.d.ts +0 -51
- package/dist/react/chat-items.js +0 -174
- package/dist/react/chat.types.d.ts +0 -299
- package/dist/react/components.types.d.ts +0 -63
- package/dist/react/context.d.ts +0 -50
- package/dist/react/context.js +0 -57
- package/dist/react/fallbacks.d.ts +0 -3
- package/dist/react/fallbacks.js +0 -13
- package/dist/react/index.d.ts +0 -8
- package/dist/react/index.js +0 -5
- package/dist/react/useBase44Chat.d.ts +0 -48
- package/dist/react/useBase44Chat.js +0 -312
- package/dist/server/server-url.d.ts +0 -2
- package/dist/server/server-url.js +0 -8
- /package/dist/{react/chat.types.js → server/errors.types.js} +0 -0
- /package/dist/{react/components.types.js → server/modules/webhooks.types.js} +0 -0
package/dist/react/Message.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
-
import { Fragment } from "react";
|
|
4
|
-
import { useResolvedComponents } from "./context.js";
|
|
5
|
-
/**
|
|
6
|
-
* Draws one chat item with the parts from the nearest {@link Base44ChatProvider}, always in the
|
|
7
|
-
* same order: its text, then one `Step` per tool call, each followed by its open question, if it has
|
|
8
|
-
* one. Only the last assistant message carries questions.
|
|
9
|
-
*
|
|
10
|
-
* It adds no element of its own, so wrap it to lay messages out.
|
|
11
|
-
*
|
|
12
|
-
* @param props - The item to draw.
|
|
13
|
-
* @returns The item's parts.
|
|
14
|
-
* @throws {Error} When there is no provider above the component.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```tsx
|
|
18
|
-
* // Align by role in your own wrapper
|
|
19
|
-
* <div className={item.role === "user" ? "ml-auto" : ""}>
|
|
20
|
-
* <Message item={item} />
|
|
21
|
-
* </div>
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export function Message({ item }) {
|
|
25
|
-
const { Text, Step } = useResolvedComponents("Message").message;
|
|
26
|
-
return (_jsxs(_Fragment, { children: [item.text && _jsx(Text, { text: item.text, role: item.role, pending: item.pending }), item.steps.map(step => (_jsxs(Fragment, { children: [_jsx(Step, { ...step }), step.question && _jsx(Question, { question: step.question })] }, step.id)))] }));
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Draws an open question with the part for its kind, from the nearest {@link Base44ChatProvider}.
|
|
30
|
-
* The part receives the question with its bound actions. {@link Message} already draws a message's
|
|
31
|
-
* questions; use this to show one somewhere else.
|
|
32
|
-
*
|
|
33
|
-
* @param props - The question to draw.
|
|
34
|
-
* @returns The part for the question's kind.
|
|
35
|
-
* @throws {Error} When there is no provider above the component.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```tsx
|
|
39
|
-
* // The open questions, pinned above the composer
|
|
40
|
-
* const { items } = useChatState();
|
|
41
|
-
* const open = items.flatMap((item) => item.steps.flatMap((step) => (step.question ? [step.question] : [])));
|
|
42
|
-
* return open.map((question, i) => <Question key={i} question={question} />);
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
export function Question({ question }) {
|
|
46
|
-
const { Choice, Secrets, Approval } = useResolvedComponents("Question").question;
|
|
47
|
-
switch (question.kind) {
|
|
48
|
-
case "choice":
|
|
49
|
-
return _jsx(Choice, { ...question });
|
|
50
|
-
case "secrets":
|
|
51
|
-
return _jsx(Secrets, { ...question });
|
|
52
|
-
case "approval":
|
|
53
|
-
return _jsx(Approval, { ...question });
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { Message } from "../client/modules/builder.events.generated.js";
|
|
2
|
-
import type { ToolCall } from "../client/modules/builder.events.types.js";
|
|
3
|
-
import type { ChatItem, ChatQuestion, ChatStep } from "./chat.types.js";
|
|
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
|
-
/** @internal Events can arrive out of order, so messages are ordered by when they were created. */
|
|
9
|
-
export declare function sortMessages(messages: Message[]): Message[];
|
|
10
|
-
/** @internal Replaces the message with the same id in place, or adds it at the end. */
|
|
11
|
-
export declare function mergeMessage(messages: Message[], updatedMessage: Message): Message[];
|
|
12
|
-
/** @internal How many of the newest messages a snapshot holds. */
|
|
13
|
-
export declare const SNAPSHOT_SIZE = 50;
|
|
14
|
-
/** @internal A rejoin's snapshot holds only the newest messages: it is the truth for its window,
|
|
15
|
-
* and the messages before its oldest one stay. A snapshot with room to spare holds them all. */
|
|
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[];
|
|
21
|
-
/** @internal Base44's tool call status, as a step's. */
|
|
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[]): {
|
|
29
|
-
toolCallId: string;
|
|
30
|
-
messageId: string;
|
|
31
|
-
}[];
|
|
32
|
-
/** @internal The ids of every tool call Base44 reports waiting. */
|
|
33
|
-
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. */
|
|
35
|
-
export interface PendingPrompt {
|
|
36
|
-
id: string;
|
|
37
|
-
content: string;
|
|
38
|
-
createdAt: string;
|
|
39
|
-
appId: string;
|
|
40
|
-
}
|
|
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
|
|
49
|
-
* answers it. Base44 keys choice answers by position, so `picked` follows `questions`. A kind this
|
|
50
|
-
* release doesn't know has no shape. */
|
|
51
|
-
export declare function toQuestion(toolCall: ToolCall, answerToolCall: AnswerToolCall): ChatQuestion | undefined;
|
package/dist/react/chat-items.js
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
/** @internal Events can arrive out of order, so messages are ordered by when they were created. */
|
|
2
|
-
export function sortMessages(messages) {
|
|
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
|
-
}
|
|
5
|
-
/** @internal Replaces the message with the same id in place, or adds it at the end. */
|
|
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));
|
|
11
|
-
}
|
|
12
|
-
/** @internal How many of the newest messages a snapshot holds. */
|
|
13
|
-
export const SNAPSHOT_SIZE = 50;
|
|
14
|
-
/** @internal A rejoin's snapshot holds only the newest messages: it is the truth for its window,
|
|
15
|
-
* and the messages before its oldest one stay. A snapshot with room to spare holds them all. */
|
|
16
|
-
export function mergeSnapshot(heldMessages, snapshotMessages) {
|
|
17
|
-
var _a, _b, _c;
|
|
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];
|
|
24
|
-
}
|
|
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 => {
|
|
40
|
-
var _a, _b, _c, _d;
|
|
41
|
-
return ({
|
|
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 : "",
|
|
46
|
-
pending: false,
|
|
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
|
-
}),
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
function toStep(toolCall, answerToolCall) {
|
|
58
|
-
var _a, _b;
|
|
59
|
-
const toolName = (_a = toolCall.name) !== null && _a !== void 0 ? _a : "";
|
|
60
|
-
// Only file tools carry `display.file_paths`.
|
|
61
|
-
const display = "display" in toolCall ? toolCall.display : undefined;
|
|
62
|
-
const files = (_b = display === null || display === void 0 ? void 0 : display.file_paths) !== null && _b !== void 0 ? _b : [];
|
|
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 }) };
|
|
66
|
-
}
|
|
67
|
-
/** @internal Base44's tool call status, as a step's. */
|
|
68
|
-
export function stepStatus(toolCall) {
|
|
69
|
-
if (toolCall.status === "running")
|
|
70
|
-
return "running";
|
|
71
|
-
if (toolCall.status === "waiting_for_user_input")
|
|
72
|
-
return "waiting";
|
|
73
|
-
if (toolCall.status === "stopped")
|
|
74
|
-
return "stopped";
|
|
75
|
-
if (toolCall.status === "error")
|
|
76
|
-
return "error";
|
|
77
|
-
return "done";
|
|
78
|
-
}
|
|
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)));
|
|
85
|
-
}
|
|
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 => {
|
|
96
|
-
var _a;
|
|
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 }));
|
|
101
|
-
}
|
|
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);
|
|
118
|
-
}
|
|
119
|
-
return stillPending;
|
|
120
|
-
}
|
|
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 }));
|
|
124
|
-
}
|
|
125
|
-
/** @internal Base44's question formats, as one simple shape per kind, each bound to the call that
|
|
126
|
-
* answers it. Base44 keys choice answers by position, so `picked` follows `questions`. A kind this
|
|
127
|
-
* release doesn't know has no shape. */
|
|
128
|
-
export function toQuestion(toolCall, answerToolCall) {
|
|
129
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
130
|
-
const kind = (_a = toolCall.waiting_on) === null || _a === void 0 ? void 0 : _a.kind;
|
|
131
|
-
const decline = () => answerToolCall(false);
|
|
132
|
-
if (kind === "choice") {
|
|
133
|
-
const questions = (_c = (_b = toolArguments(toolCall)) === null || _b === void 0 ? void 0 : _b.questions) !== null && _c !== void 0 ? _c : [];
|
|
134
|
-
return {
|
|
135
|
-
kind,
|
|
136
|
-
questions: questions.map(question => {
|
|
137
|
-
var _a, _b;
|
|
138
|
-
return ({
|
|
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,
|
|
143
|
-
});
|
|
144
|
-
}),
|
|
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
|
-
},
|
|
151
|
-
decline,
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
if (kind === "input") {
|
|
155
|
-
const secretFields = (_e = (_d = toolArguments(toolCall)) === null || _d === void 0 ? void 0 : _d.secrets_schema) !== null && _e !== void 0 ? _e : [];
|
|
156
|
-
return {
|
|
157
|
-
kind: "secrets",
|
|
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 }),
|
|
160
|
-
decline,
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
if (kind === "approval") {
|
|
164
|
-
// Guards that declare a reason or a summary carry them; the others name only themselves.
|
|
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 };
|
|
168
|
-
}
|
|
169
|
-
return undefined;
|
|
170
|
-
}
|
|
171
|
-
// The waiting kind says which arguments a call carries; the tool's name only narrows the union.
|
|
172
|
-
function toolArguments(toolCall) {
|
|
173
|
-
return "arguments" in toolCall ? toolCall.arguments : undefined;
|
|
174
|
-
}
|
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
import type { SocketSession } from "../client/modules/builder.types.js";
|
|
2
|
-
/** An app the AI chat works on. */
|
|
3
|
-
export interface Base44App {
|
|
4
|
-
/** ID of the app, 24 lowercase hexadecimal characters. */
|
|
5
|
-
id: string;
|
|
6
|
-
/** Display name of the app. */
|
|
7
|
-
name: string;
|
|
8
|
-
}
|
|
9
|
-
/** An answer to a question the AI waits on. Declining is `approve: false`. */
|
|
10
|
-
export interface ToolCallAnswer {
|
|
11
|
-
/** ID of the tool call being answered. */
|
|
12
|
-
toolCallId: string;
|
|
13
|
-
/** ID of the assistant message that holds the tool call. */
|
|
14
|
-
messageId: string;
|
|
15
|
-
/** Whether to let the tool call run (`true`) or turn it down (`false`). */
|
|
16
|
-
approve: boolean;
|
|
17
|
-
/** What the question asked for. A choice sends `{ answers }`, and a secrets question sends `{ secrets }`. */
|
|
18
|
-
extraUserInput?: Record<string, unknown>;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* The four calls your backend makes to Base44 for the chat.
|
|
22
|
-
*
|
|
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.
|
|
25
|
-
*
|
|
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
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
export interface Base44ChatBackend {
|
|
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
|
-
*/
|
|
69
|
-
openLiveSession(appId: string): Promise<SocketSession>;
|
|
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
|
-
*/
|
|
78
|
-
sendMessage(appId: string, content: string): Promise<void>;
|
|
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
|
-
*/
|
|
86
|
-
submitToolCallInput(appId: string, answer: ToolCallAnswer): Promise<void>;
|
|
87
|
-
}
|
|
88
|
-
/** One message of the chat, shaped for rendering. */
|
|
89
|
-
export interface ChatItem {
|
|
90
|
-
/** ID of the message. */
|
|
91
|
-
id: string;
|
|
92
|
-
/** Who wrote the message. */
|
|
93
|
-
role: "user" | "assistant";
|
|
94
|
-
/** The message text, as raw markdown. It comes before the steps, and is empty when the message only holds tool calls. */
|
|
95
|
-
text: string;
|
|
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. */
|
|
97
|
-
createdAt: string;
|
|
98
|
-
/** One step per tool call, in order. */
|
|
99
|
-
steps: ChatStep[];
|
|
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
|
-
*/
|
|
105
|
-
pending: boolean;
|
|
106
|
-
}
|
|
107
|
-
/** One tool call, as a line of activity. */
|
|
108
|
-
export interface ChatStep {
|
|
109
|
-
/** ID of the tool call. */
|
|
110
|
-
id: string;
|
|
111
|
-
/** Name of the tool, such as `write_file`. */
|
|
112
|
-
tool: string;
|
|
113
|
-
/** The file paths the tool call touched. */
|
|
114
|
-
files: string[];
|
|
115
|
-
/** The tool name and its files, ready to show. */
|
|
116
|
-
label: string;
|
|
117
|
-
/**
|
|
118
|
-
* Where the tool call is. A `waiting` step waits on the user. A `stopped` step was declined, or the
|
|
119
|
-
* turn was stopped.
|
|
120
|
-
*/
|
|
121
|
-
status: "running" | "waiting" | "done" | "stopped" | "error";
|
|
122
|
-
/**
|
|
123
|
-
* The question this step waits on, with the actions that answer it. Present only while the step is
|
|
124
|
-
* `waiting` in the last assistant message, which is the one that makes the chat wait. It goes away
|
|
125
|
-
* once answered, and is absent for a question kind this release doesn't know.
|
|
126
|
-
*/
|
|
127
|
-
question?: ChatQuestion;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* An open question, with the actions that answer this question and no other.
|
|
131
|
-
*
|
|
132
|
-
* Each kind carries only the actions that make sense for it, and every kind can be declined. The
|
|
133
|
-
* actions never throw. A failure sets {@link Base44Chat.error}, and the question opens again.
|
|
134
|
-
*
|
|
135
|
-
* The chat declines a question kind this release doesn't know, once per tool call, when Base44
|
|
136
|
-
* names that kind on the last assistant message. If the decline fails, {@link Base44Chat.error} says
|
|
137
|
-
* so, and the chat tries again after it reconnects.
|
|
138
|
-
*/
|
|
139
|
-
export type ChatQuestion = ChoiceQuestion | SecretsQuestion | ApprovalQuestion;
|
|
140
|
-
/** One of the questions in a {@link ChoiceQuestion}. */
|
|
141
|
-
export interface ChoiceEntry {
|
|
142
|
-
/** The question text. */
|
|
143
|
-
text: string;
|
|
144
|
-
/** Supporting text for the question. */
|
|
145
|
-
description?: string;
|
|
146
|
-
/** The option labels to pick from. */
|
|
147
|
-
options: string[];
|
|
148
|
-
/** Whether more than one option can be picked. */
|
|
149
|
-
multi: boolean;
|
|
150
|
-
}
|
|
151
|
-
/** The AI offers options and waits for the user to pick. */
|
|
152
|
-
export interface ChoiceQuestion {
|
|
153
|
-
/** Kind of question. */
|
|
154
|
-
kind: "choice";
|
|
155
|
-
/** The questions, in order. */
|
|
156
|
-
questions: ChoiceEntry[];
|
|
157
|
-
/**
|
|
158
|
-
* Answers with the picked labels.
|
|
159
|
-
*
|
|
160
|
-
* @param picked - One list of picked labels per question, in the order of `questions`. An empty list skips that question.
|
|
161
|
-
* @returns Promise resolving once the answer is sent.
|
|
162
|
-
*/
|
|
163
|
-
answer(picked: string[][]): Promise<void>;
|
|
164
|
-
/**
|
|
165
|
-
* Declines the question. The AI continues without the answer.
|
|
166
|
-
*
|
|
167
|
-
* @returns Promise resolving once the decline is sent.
|
|
168
|
-
*/
|
|
169
|
-
decline(): Promise<void>;
|
|
170
|
-
}
|
|
171
|
-
/** A value the AI needs, such as an API key. */
|
|
172
|
-
export interface SecretField {
|
|
173
|
-
/** Name of the field, used as its key in `submit`. */
|
|
174
|
-
name: string;
|
|
175
|
-
/** Where to get the value. */
|
|
176
|
-
description?: string;
|
|
177
|
-
}
|
|
178
|
-
/** The AI needs secrets, such as API keys. The values go to Base44 and the chat keeps none of them. */
|
|
179
|
-
export interface SecretsQuestion {
|
|
180
|
-
/** Kind of question. */
|
|
181
|
-
kind: "secrets";
|
|
182
|
-
/** The fields to fill. */
|
|
183
|
-
fields: SecretField[];
|
|
184
|
-
/**
|
|
185
|
-
* Submits the values.
|
|
186
|
-
*
|
|
187
|
-
* @param values - The values, keyed by field name.
|
|
188
|
-
* @returns Promise resolving once the values are sent.
|
|
189
|
-
*/
|
|
190
|
-
submit(values: Record<string, string>): Promise<void>;
|
|
191
|
-
/**
|
|
192
|
-
* Declines the question. The AI continues without the values.
|
|
193
|
-
*
|
|
194
|
-
* @returns Promise resolving once the decline is sent.
|
|
195
|
-
*/
|
|
196
|
-
decline(): Promise<void>;
|
|
197
|
-
}
|
|
198
|
-
/** The AI asks for permission to run an action. */
|
|
199
|
-
export interface ApprovalQuestion {
|
|
200
|
-
/** Kind of question. */
|
|
201
|
-
kind: "approval";
|
|
202
|
-
/** Name of the tool that wants to run. */
|
|
203
|
-
action: string;
|
|
204
|
-
/** Why the action needs approval, when Base44 gives a reason. Empty otherwise. */
|
|
205
|
-
reason: string;
|
|
206
|
-
/**
|
|
207
|
-
* Lets the action run.
|
|
208
|
-
*
|
|
209
|
-
* @returns Promise resolving once the approval is sent.
|
|
210
|
-
*/
|
|
211
|
-
approve(): Promise<void>;
|
|
212
|
-
/**
|
|
213
|
-
* Declines the action. It never runs, and the AI continues.
|
|
214
|
-
*
|
|
215
|
-
* @returns Promise resolving once the decline is sent.
|
|
216
|
-
*/
|
|
217
|
-
decline(): Promise<void>;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* What the AI is doing. When several hold at once, the first in this list wins.
|
|
221
|
-
*
|
|
222
|
-
* - `error`: Base44 reports that the last build failed.
|
|
223
|
-
* - `waiting`: a question waits on the user.
|
|
224
|
-
* - `building`: the AI is working.
|
|
225
|
-
* - `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.
|
|
226
|
-
* - `ready`: none of the above.
|
|
227
|
-
*/
|
|
228
|
-
export type ChatStatus = "ready" | "submitted" | "building" | "waiting" | "error";
|
|
229
|
-
/**
|
|
230
|
-
* Whether the chat follows the app live.
|
|
231
|
-
*
|
|
232
|
-
* - `connecting`: until the first snapshot arrives.
|
|
233
|
-
* - `connected`: after the first snapshot.
|
|
234
|
-
* - `disconnected`: live updates stopped for good. The session couldn't open, the retries ran out,
|
|
235
|
-
* or Base44 ended the session or the app's subscription. {@link Base44Chat.error} says why.
|
|
236
|
-
*
|
|
237
|
-
* Watching another app, or mounting the chat again, starts over.
|
|
238
|
-
*/
|
|
239
|
-
export type ChatConnection = "connecting" | "connected" | "disconnected";
|
|
240
|
-
/** A failure of a call, of the live connection, or of the build. */
|
|
241
|
-
export interface ChatError {
|
|
242
|
-
/** What went wrong, for people. */
|
|
243
|
-
message: string;
|
|
244
|
-
/**
|
|
245
|
-
* What went wrong, for code. A connection error carries a `PlatformSocketErrorCode`, and a failed
|
|
246
|
-
* build carries `build_failed`. A failed call to your backend carries none.
|
|
247
|
-
*/
|
|
248
|
-
code?: string;
|
|
249
|
-
/** The original error, for logging. */
|
|
250
|
-
cause?: unknown;
|
|
251
|
-
}
|
|
252
|
-
/** Options for {@link useBase44Chat}. */
|
|
253
|
-
export interface Base44ChatOptions {
|
|
254
|
-
/**
|
|
255
|
-
* ID of the app to follow, or `null` until an app exists. While it's `null`, the chat follows the
|
|
256
|
-
* app {@link Base44Chat.create} made. Any change to `appId` forgets that app.
|
|
257
|
-
*/
|
|
258
|
-
appId: string | null;
|
|
259
|
-
/** The four calls your backend makes to Base44. The chat reads the latest on every action, so an inline object works. */
|
|
260
|
-
backend: Base44ChatBackend;
|
|
261
|
-
/**
|
|
262
|
-
* Called with the new app after {@link Base44Chat.create} succeeds. The chat already follows it.
|
|
263
|
-
* Pass its ID back as `appId` to keep it in your own state.
|
|
264
|
-
*/
|
|
265
|
-
onAppCreated?: (app: Base44App) => void;
|
|
266
|
-
}
|
|
267
|
-
/** The chat that {@link useBase44Chat} returns. */
|
|
268
|
-
export interface Base44Chat {
|
|
269
|
-
/** The conversation, oldest first, with open questions bound to their steps. */
|
|
270
|
-
items: ChatItem[];
|
|
271
|
-
/** What the AI is doing. */
|
|
272
|
-
status: ChatStatus;
|
|
273
|
-
/** Whether the chat follows the app live. */
|
|
274
|
-
connection: ChatConnection;
|
|
275
|
-
/**
|
|
276
|
-
* The last failure. It's set whenever `status` is `error`, and on any failed call or connection
|
|
277
|
-
* error. A failed call's error clears on the next action. A connection error stays until
|
|
278
|
-
* {@link Base44Chat.clearError}. A failed build stays while Base44 reports it.
|
|
279
|
-
*/
|
|
280
|
-
error: ChatError | null;
|
|
281
|
-
/**
|
|
282
|
-
* Sends a prompt to the current app. Base44 queues it while the AI is working. The prompt shows
|
|
283
|
-
* at once as a pending item, and the reply arrives through `items`. Without an app, it sets
|
|
284
|
-
* `error`. Use {@link Base44Chat.create} for the first prompt.
|
|
285
|
-
*
|
|
286
|
-
* @param prompt - The prompt to send.
|
|
287
|
-
* @returns Promise resolving once Base44 accepts the prompt. It never rejects.
|
|
288
|
-
*/
|
|
289
|
-
send(prompt: string): Promise<void>;
|
|
290
|
-
/**
|
|
291
|
-
* Creates an app from its first prompt and reports it through `onAppCreated`.
|
|
292
|
-
*
|
|
293
|
-
* @param prompt - The first prompt, which describes the app.
|
|
294
|
-
* @returns Promise resolving once the app exists. It never rejects.
|
|
295
|
-
*/
|
|
296
|
-
create(prompt: string): Promise<void>;
|
|
297
|
-
/** Clears {@link Base44Chat.error}. A failed build's error stays while Base44 reports it. */
|
|
298
|
-
clearError(): void;
|
|
299
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { ComponentType, ReactNode } from "react";
|
|
2
|
-
import type { ApprovalQuestion, Base44Chat, Base44ChatOptions, ChatItem, ChatQuestion, ChatStep, ChoiceQuestion, SecretsQuestion } from "./chat.types.js";
|
|
3
|
-
/** Props of the `Text` part: one message's text. */
|
|
4
|
-
export interface TextProps {
|
|
5
|
-
/** The message text, as raw markdown. Never empty: an item without text draws no `Text`. */
|
|
6
|
-
text: string;
|
|
7
|
-
/** Who wrote the message, to align or color it. */
|
|
8
|
-
role: ChatItem["role"];
|
|
9
|
-
/** Whether this is a prompt Base44 hasn't confirmed yet. */
|
|
10
|
-
pending: boolean;
|
|
11
|
-
}
|
|
12
|
-
/** Props of the `Step` part: one tool call of a message. */
|
|
13
|
-
export type StepProps = ChatStep;
|
|
14
|
-
/** The parts of a message's own content. Each one left out is drawn as plain, unstyled HTML. */
|
|
15
|
-
export interface MessageComponents {
|
|
16
|
-
/** Draws a message's text. */
|
|
17
|
-
Text: ComponentType<TextProps>;
|
|
18
|
-
/** Draws one tool call as a line of activity. */
|
|
19
|
-
Step: ComponentType<StepProps>;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* One part per question kind, all required. Each receives the question itself: its content and the
|
|
23
|
-
* actions bound to it, so a part can only answer the question it draws.
|
|
24
|
-
*
|
|
25
|
-
* A release that adds a kind adds a part here, so upgrading tells you at compile time which part to
|
|
26
|
-
* write. Until you upgrade, the chat declines the new kind for you.
|
|
27
|
-
*/
|
|
28
|
-
export interface QuestionComponents {
|
|
29
|
-
/** Draws a pick between options. Call `answer` with one list of labels per question. */
|
|
30
|
-
Choice: ComponentType<ChoiceQuestion>;
|
|
31
|
-
/** Draws a form for values such as API keys. Call `submit` with the values keyed by field name. */
|
|
32
|
-
Secrets: ComponentType<SecretsQuestion>;
|
|
33
|
-
/** Draws a request to run an action. Call `approve` or `decline`. */
|
|
34
|
-
Approval: ComponentType<ApprovalQuestion>;
|
|
35
|
-
}
|
|
36
|
-
/** The parts you pass to {@link Base44ChatProvider}: every question part, and the message parts you replace. */
|
|
37
|
-
export interface ChatComponents {
|
|
38
|
-
/** Replacements for the message parts. */
|
|
39
|
-
message?: Partial<MessageComponents>;
|
|
40
|
-
/** A part for every question kind. */
|
|
41
|
-
question: QuestionComponents;
|
|
42
|
-
}
|
|
43
|
-
/** What {@link useChatState} returns: everything that changes as the chat runs. */
|
|
44
|
-
export type ChatState = Pick<Base44Chat, "items" | "status" | "connection" | "error">;
|
|
45
|
-
/** What {@link useChatActions} returns. The actions keep their identity while the app stays the same. */
|
|
46
|
-
export type ChatActions = Pick<Base44Chat, "send" | "create" | "clearError">;
|
|
47
|
-
/** Props of {@link Base44ChatProvider}: the {@link useBase44Chat} options, the parts, and the tree that reads them. */
|
|
48
|
-
export interface Base44ChatProviderProps extends Base44ChatOptions {
|
|
49
|
-
/** The parts that draw the chat. Read part by part, so an inline object works. */
|
|
50
|
-
components: ChatComponents;
|
|
51
|
-
/** The components that read the chat. */
|
|
52
|
-
children?: ReactNode;
|
|
53
|
-
}
|
|
54
|
-
/** Props of {@link Message}. */
|
|
55
|
-
export interface MessageProps {
|
|
56
|
-
/** The item to draw, one of the `items` from {@link useChatState}. */
|
|
57
|
-
item: ChatItem;
|
|
58
|
-
}
|
|
59
|
-
/** Props of {@link Question}. */
|
|
60
|
-
export interface QuestionProps {
|
|
61
|
-
/** The open question to draw, from {@link ChatStep.question}. */
|
|
62
|
-
question: ChatQuestion;
|
|
63
|
-
}
|