@base44-preview/platform 0.4.0-pr.344.ece486e → 0.4.0-pr.345.2183bda
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
CHANGED
|
@@ -237,15 +237,15 @@ remains the existing SDK dependency. Chat commands and HTTP APIs are outside thi
|
|
|
237
237
|
|
|
238
238
|
## React
|
|
239
239
|
|
|
240
|
-
`@base44/platform/react` adds one hook, `
|
|
240
|
+
`@base44/platform/react` adds one hook, `useChat`, that runs the AI chat for one
|
|
241
241
|
app on top of this client: it opens the live session and renews it, turns messages into items
|
|
242
242
|
made for rendering, binds every question the AI asks to the step it belongs to. It renders nothing. React is an optional peer dependency, loaded only by this
|
|
243
243
|
entry; the root entry stays framework-free.
|
|
244
244
|
|
|
245
245
|
```tsx
|
|
246
|
-
import {
|
|
246
|
+
import { useChat } from "@base44/platform/react";
|
|
247
247
|
|
|
248
|
-
const chat =
|
|
248
|
+
const chat = useChat({ appId, backend, onAppCreated });
|
|
249
249
|
chat.items.map((item) =>
|
|
250
250
|
item.steps.map((step) => step.question?.kind === "approval" && <button onClick={step.question.approve}>Allow</button>),
|
|
251
251
|
);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SocketSession } from "../client/modules/chat.types.js";
|
|
2
2
|
/** An app the AI chat works on. */
|
|
3
|
-
export interface
|
|
3
|
+
export interface ChatApp {
|
|
4
4
|
/** ID of the app, 24 lowercase hexadecimal characters. */
|
|
5
5
|
id: string;
|
|
6
6
|
/** Display name of the app. */
|
|
@@ -32,7 +32,7 @@ export interface ToolCallAnswer {
|
|
|
32
32
|
*
|
|
33
33
|
* Base44 keeps the Send chat message and Submit tool-call input requests open until the AI
|
|
34
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 `error` on the {@link
|
|
35
|
+
* chat follows the rest live. A rejected promise from any call sets `error` on the {@link useChat | chat}.
|
|
36
36
|
*
|
|
37
37
|
* @example
|
|
38
38
|
* ```typescript
|
|
@@ -43,7 +43,7 @@ export interface ToolCallAnswer {
|
|
|
43
43
|
* return response.json();
|
|
44
44
|
* }
|
|
45
45
|
*
|
|
46
|
-
* const backend:
|
|
46
|
+
* const backend: ChatBackend = {
|
|
47
47
|
* createApp: (prompt) => post("/api/chat/apps", { prompt }),
|
|
48
48
|
* openLiveSession: (appId) => post("/api/chat/session", { appId }),
|
|
49
49
|
* sendMessage: (appId, content) => post("/api/chat/message", { appId, content }),
|
|
@@ -51,14 +51,14 @@ export interface ToolCallAnswer {
|
|
|
51
51
|
* };
|
|
52
52
|
* ```
|
|
53
53
|
*/
|
|
54
|
-
export interface
|
|
54
|
+
export interface ChatBackend {
|
|
55
55
|
/**
|
|
56
56
|
* Creates an app from its first prompt. The AI starts building inside this call.
|
|
57
57
|
*
|
|
58
58
|
* @param prompt - The first prompt, which describes the app.
|
|
59
59
|
* @returns Promise resolving to the new app.
|
|
60
60
|
*/
|
|
61
|
-
createApp(prompt: string): Promise<
|
|
61
|
+
createApp(prompt: string): Promise<ChatApp>;
|
|
62
62
|
/**
|
|
63
63
|
* Opens a read-only socket session for one app. The chat calls it on the first connect and again
|
|
64
64
|
* whenever the session expires. Sessions last one hour.
|
|
@@ -141,7 +141,7 @@ export interface ChatAnswer {
|
|
|
141
141
|
* An open question, with the actions that answer this question and no other.
|
|
142
142
|
*
|
|
143
143
|
* Each kind carries only the actions that make sense for it, and every kind can be declined. The
|
|
144
|
-
* actions never throw. A failure sets `error` on the {@link
|
|
144
|
+
* actions never throw. A failure sets `error` on the {@link useChat | chat}, and the question opens again.
|
|
145
145
|
*
|
|
146
146
|
* The chat declines a question kind this release doesn't know, once per tool call, when Base44
|
|
147
147
|
* names that kind on the last assistant message. If the decline fails, the chat's `error` says
|
|
@@ -267,7 +267,7 @@ export type ChatStatus = "ready" | "submitted" | "building" | "waiting" | "error
|
|
|
267
267
|
* - `connecting`: until the first snapshot arrives.
|
|
268
268
|
* - `connected`: after the first snapshot.
|
|
269
269
|
* - `disconnected`: live updates stopped for good. The session couldn't open, the retries ran out,
|
|
270
|
-
* or Base44 ended the session or the app's subscription. {@link
|
|
270
|
+
* or Base44 ended the session or the app's subscription. {@link UseChatResult.error} says why.
|
|
271
271
|
*
|
|
272
272
|
* Watching another app, or mounting the chat again, starts over.
|
|
273
273
|
*/
|
|
@@ -284,25 +284,23 @@ export interface ChatError {
|
|
|
284
284
|
/** The original error, for logging. */
|
|
285
285
|
cause?: unknown;
|
|
286
286
|
}
|
|
287
|
-
/** Options for {@link
|
|
288
|
-
export interface
|
|
287
|
+
/** Options for {@link useChat}. */
|
|
288
|
+
export interface ChatOptions {
|
|
289
289
|
/**
|
|
290
290
|
* ID of the app to follow, or `null` until an app exists. While it's `null`, the chat follows the
|
|
291
|
-
* app {@link
|
|
291
|
+
* app {@link UseChatResult.create} made. Any change to `appId` forgets that app.
|
|
292
292
|
*/
|
|
293
293
|
appId: string | null;
|
|
294
294
|
/** The four calls your backend makes to Base44. The chat reads the latest on every action, so an inline object works. */
|
|
295
|
-
backend:
|
|
295
|
+
backend: ChatBackend;
|
|
296
296
|
/**
|
|
297
|
-
* Called with the new app after {@link
|
|
297
|
+
* Called with the new app after {@link UseChatResult.create} succeeds. The chat already follows it.
|
|
298
298
|
* Pass its ID back as `appId` to keep it in your own state.
|
|
299
|
-
*
|
|
300
|
-
* @param app - The app that was created.
|
|
301
299
|
*/
|
|
302
|
-
onAppCreated?: (app:
|
|
300
|
+
onAppCreated?: (app: ChatApp) => void;
|
|
303
301
|
}
|
|
304
|
-
/** The chat that {@link
|
|
305
|
-
export interface
|
|
302
|
+
/** The chat that {@link useChat} returns. */
|
|
303
|
+
export interface UseChatResult {
|
|
306
304
|
/** The conversation, oldest first, with open questions bound to their steps. */
|
|
307
305
|
items: ChatItem[];
|
|
308
306
|
/** What the AI is doing. */
|
|
@@ -312,13 +310,13 @@ export interface Base44Chat {
|
|
|
312
310
|
/**
|
|
313
311
|
* The last failure. It's set whenever `status` is `error`, and on any failed call or connection
|
|
314
312
|
* error. A failed call's error clears on the next action. A connection error stays until
|
|
315
|
-
* {@link
|
|
313
|
+
* {@link UseChatResult.clearError}. A failed build stays while Base44 reports it.
|
|
316
314
|
*/
|
|
317
315
|
error: ChatError | null;
|
|
318
316
|
/**
|
|
319
317
|
* Sends a prompt to the current app. Base44 queues it while the AI is working. The prompt shows
|
|
320
318
|
* at once as a pending item, and the reply arrives through `items`. Without an app, it sets
|
|
321
|
-
* `error`. Use {@link
|
|
319
|
+
* `error`. Use {@link UseChatResult.create} for the first prompt.
|
|
322
320
|
*
|
|
323
321
|
* @param prompt - The prompt to send.
|
|
324
322
|
* @returns Promise resolving once Base44 accepts the prompt. It never rejects.
|
|
@@ -331,6 +329,6 @@ export interface Base44Chat {
|
|
|
331
329
|
* @returns Promise resolving once the app exists. It never rejects.
|
|
332
330
|
*/
|
|
333
331
|
create(prompt: string): Promise<void>;
|
|
334
|
-
/** Clears {@link
|
|
332
|
+
/** Clears {@link UseChatResult.error}. A failed build's error stays while Base44 reports it. */
|
|
335
333
|
clearError(): void;
|
|
336
334
|
}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
/** The `@base44/platform/react` entry: the AI chat for one app, as a React hook. React is an optional peer, loaded only here. */
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { useChat } from "./useChat.js";
|
|
3
|
+
import type { UseChatResult, ChatApp, ChatBackend, ChatOptions } from "./chat.types.js";
|
|
4
|
+
export { useChat };
|
|
5
|
+
export type { ApprovalDetails, ApprovalQuestion, ChatApp, UseChatResult, ChatOptions, ChatBackend, ChatAnswer, ChatConnection, ChatError, ChatItem, ChatQuestion, ChatStatus, ChatStep, ChoiceEntry, ChoiceQuestion, SecretField, SecretsQuestion, ToolCallAnswer, } from "./chat.types.js";
|
|
4
6
|
export type { SocketSession } from "../client/modules/chat.types.js";
|
|
7
|
+
/** @deprecated Renamed to {@link useChat}. Removed in 0.6.0. @hidden */
|
|
8
|
+
export declare const useBase44Chat: typeof useChat;
|
|
9
|
+
/** @deprecated Renamed to {@link UseChatResult}. Removed in 0.6.0. @hidden */
|
|
10
|
+
export type Base44Chat = UseChatResult;
|
|
11
|
+
/** @deprecated Renamed to {@link ChatOptions}. Removed in 0.6.0. @hidden */
|
|
12
|
+
export type Base44ChatOptions = ChatOptions;
|
|
13
|
+
/** @deprecated Renamed to {@link ChatBackend}. Removed in 0.6.0. @hidden */
|
|
14
|
+
export type Base44ChatBackend = ChatBackend;
|
|
15
|
+
/** @deprecated Renamed to {@link ChatApp}. Removed in 0.6.0. @hidden */
|
|
16
|
+
export type Base44App = ChatApp;
|
package/dist/react/index.js
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
/** The `@base44/platform/react` entry: the AI chat for one app, as a React hook. React is an optional peer, loaded only here. */
|
|
2
|
-
|
|
2
|
+
import { useChat } from "./useChat.js";
|
|
3
|
+
export { useChat };
|
|
4
|
+
// The names before 0.5.0, kept for one release so existing code keeps working.
|
|
5
|
+
/** @deprecated Renamed to {@link useChat}. Removed in 0.6.0. @hidden */
|
|
6
|
+
export const useBase44Chat = useChat;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { UseChatResult, ChatOptions } from "./chat.types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Runs the AI chat for one app in your own UI.
|
|
4
4
|
*
|
|
5
5
|
* The hook renders nothing. It gives you the conversation and the actions, and you draw them:
|
|
6
6
|
* - Follows the app live, and renews its socket session when it expires.
|
|
7
7
|
* - Turns Base44's messages into {@link ChatItem | items}, with each open question bound to the step it belongs to.
|
|
8
|
-
* - Reports what the AI is doing in {@link
|
|
9
|
-
* - Sends prompts, creates apps and answers questions through the {@link
|
|
8
|
+
* - Reports what the AI is doing in {@link UseChatResult.status}, and the live connection in {@link UseChatResult.connection}.
|
|
9
|
+
* - Sends prompts, creates apps and answers questions through the {@link ChatBackend | backend} you pass, so no credential reaches the browser.
|
|
10
10
|
*
|
|
11
|
-
* The actions never throw. A failure sets {@link
|
|
11
|
+
* The actions never throw. A failure sets {@link UseChatResult.error}, and a question whose answer
|
|
12
12
|
* failed opens again. The chat declines a question kind this release doesn't know.
|
|
13
13
|
*
|
|
14
14
|
* Requires a browser environment and can't be used in the backend.
|
|
15
15
|
*
|
|
16
16
|
* The chat follows `appId` when it's set. While `appId` is `null`, it follows the app
|
|
17
|
-
* {@link
|
|
17
|
+
* {@link UseChatResult.create} made, so passing the new ID back is optional. Any change to `appId`
|
|
18
18
|
* forgets that app, so setting it back to `null` starts a new chat. Switching apps closes the old
|
|
19
19
|
* session and starts over.
|
|
20
20
|
*
|
|
@@ -24,7 +24,7 @@ import type { Base44Chat, Base44ChatOptions } from "./chat.types.js";
|
|
|
24
24
|
* @example
|
|
25
25
|
* ```typescript
|
|
26
26
|
* // Draw the chat and answer an approval
|
|
27
|
-
* const chat =
|
|
27
|
+
* const chat = useChat({ appId, backend, onAppCreated: selectApp });
|
|
28
28
|
* return (
|
|
29
29
|
* <>
|
|
30
30
|
* {chat.items.map((item) => (
|
|
@@ -45,4 +45,4 @@ import type { Base44Chat, Base44ChatOptions } from "./chat.types.js";
|
|
|
45
45
|
* );
|
|
46
46
|
* ```
|
|
47
47
|
*/
|
|
48
|
-
export declare function
|
|
48
|
+
export declare function useChat({ appId, backend, onAppCreated }: ChatOptions): UseChatResult;
|
|
@@ -12,16 +12,16 @@ const NEW_APP = "new-app";
|
|
|
12
12
|
* The hook renders nothing. It gives you the conversation and the actions, and you draw them:
|
|
13
13
|
* - Follows the app live, and renews its socket session when it expires.
|
|
14
14
|
* - Turns Base44's messages into {@link ChatItem | items}, with each open question bound to the step it belongs to.
|
|
15
|
-
* - Reports what the AI is doing in {@link
|
|
16
|
-
* - Sends prompts, creates apps and answers questions through the {@link
|
|
15
|
+
* - Reports what the AI is doing in {@link UseChatResult.status}, and the live connection in {@link UseChatResult.connection}.
|
|
16
|
+
* - Sends prompts, creates apps and answers questions through the {@link ChatBackend | backend} you pass, so no credential reaches the browser.
|
|
17
17
|
*
|
|
18
|
-
* The actions never throw. A failure sets {@link
|
|
18
|
+
* The actions never throw. A failure sets {@link UseChatResult.error}, and a question whose answer
|
|
19
19
|
* failed opens again. The chat declines a question kind this release doesn't know.
|
|
20
20
|
*
|
|
21
21
|
* Requires a browser environment and can't be used in the backend.
|
|
22
22
|
*
|
|
23
23
|
* The chat follows `appId` when it's set. While `appId` is `null`, it follows the app
|
|
24
|
-
* {@link
|
|
24
|
+
* {@link UseChatResult.create} made, so passing the new ID back is optional. Any change to `appId`
|
|
25
25
|
* forgets that app, so setting it back to `null` starts a new chat. Switching apps closes the old
|
|
26
26
|
* session and starts over.
|
|
27
27
|
*
|
|
@@ -31,7 +31,7 @@ const NEW_APP = "new-app";
|
|
|
31
31
|
* @example
|
|
32
32
|
* ```typescript
|
|
33
33
|
* // Draw the chat and answer an approval
|
|
34
|
-
* const chat =
|
|
34
|
+
* const chat = useChat({ appId, backend, onAppCreated: selectApp });
|
|
35
35
|
* return (
|
|
36
36
|
* <>
|
|
37
37
|
* {chat.items.map((item) => (
|
|
@@ -52,7 +52,7 @@ const NEW_APP = "new-app";
|
|
|
52
52
|
* );
|
|
53
53
|
* ```
|
|
54
54
|
*/
|
|
55
|
-
export function
|
|
55
|
+
export function useChat({ appId, backend, onAppCreated }) {
|
|
56
56
|
var _a;
|
|
57
57
|
const [messages, setMessages] = useState([]);
|
|
58
58
|
const [buildState, setBuildState] = useState();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base44-preview/platform",
|
|
3
|
-
"version": "0.4.0-pr.
|
|
3
|
+
"version": "0.4.0-pr.345.2183bda",
|
|
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",
|