@base44-preview/platform 0.3.0-pr.341.adc3ff5 → 0.4.0-pr.344.ece486e
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 +28 -28
- package/dist/client/client.d.ts +13 -9
- package/dist/client/client.js +15 -11
- package/dist/client/client.types.d.ts +4 -6
- package/dist/client/errors.d.ts +16 -10
- package/dist/client/errors.js +15 -9
- package/dist/client/errors.types.d.ts +25 -19
- package/dist/client/index.d.ts +3 -3
- package/dist/client/modules/{builder-protocol.d.ts → chat-protocol.d.ts} +2 -2
- package/dist/client/modules/{builder-protocol.js → chat-protocol.js} +1 -1
- package/dist/client/modules/{builder-socket.d.ts → chat-socket.d.ts} +3 -3
- package/dist/client/modules/{builder-socket.js → chat-socket.js} +4 -4
- package/dist/client/modules/{builder-subscription.d.ts → chat-subscription.d.ts} +2 -2
- package/dist/client/modules/chat.d.ts +3 -0
- package/dist/client/modules/{builder.events.types.d.ts → chat.events.types.d.ts} +35 -32
- package/dist/client/modules/chat.js +7 -0
- package/dist/client/modules/chat.types.d.ts +215 -0
- package/dist/react/chat-items.d.ts +4 -4
- package/dist/react/chat-items.js +3 -3
- package/dist/react/chat.types.d.ts +6 -4
- package/dist/react/index.d.ts +1 -1
- package/dist/react/useBase44Chat.js +4 -4
- package/dist/server/errors.d.ts +9 -9
- package/dist/server/errors.js +7 -7
- package/dist/server/errors.types.d.ts +3 -3
- package/dist/server/modules/webhooks.events.generated.d.ts +12 -12
- package/dist/server/modules/webhooks.events.generated.js +1 -1
- package/dist/server/modules/webhooks.types.d.ts +36 -31
- package/dist/server/server.d.ts +1 -1
- package/dist/server/server.js +1 -1
- package/dist/server/server.types.d.ts +2 -4
- package/package.json +2 -2
- package/dist/client/modules/builder.d.ts +0 -3
- package/dist/client/modules/builder.js +0 -7
- package/dist/client/modules/builder.types.d.ts +0 -193
- /package/dist/client/modules/{builder-subscription.js → chat-subscription.js} +0 -0
- /package/dist/client/modules/{builder.events.generated.d.ts → chat.events.generated.d.ts} +0 -0
- /package/dist/client/modules/{builder.events.generated.js → chat.events.generated.js} +0 -0
- /package/dist/client/modules/{builder.events.types.js → chat.events.types.js} +0 -0
- /package/dist/client/modules/{builder.types.js → chat.types.js} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Message, QueueState, ServerEventMap, Snapshot } from "./
|
|
1
|
+
import type { Message, QueueState, ServerEventMap, Snapshot } from "./chat.events.generated.js";
|
|
2
2
|
/**
|
|
3
3
|
* Maps each live event name to the type of its `data` payload.
|
|
4
4
|
*
|
|
@@ -9,16 +9,38 @@ import type { Message, QueueState, ServerEventMap, Snapshot } from "./builder.ev
|
|
|
9
9
|
export type PlatformEventMap = {
|
|
10
10
|
[K in keyof ServerEventMap as K extends "app.snapshot" | "session.ended" | `room.${string}` ? never : K]: ServerEventMap[K];
|
|
11
11
|
};
|
|
12
|
+
/** An event the service sends for a subscribed app, named by its `type`. */
|
|
13
|
+
export interface AppEvent<K extends keyof PlatformEventMap> {
|
|
14
|
+
/** Event name. Narrows the type of `data`. */
|
|
15
|
+
type: K;
|
|
16
|
+
/** ID of the app the event belongs to. */
|
|
17
|
+
appId: string;
|
|
18
|
+
/** Event payload. */
|
|
19
|
+
data: PlatformEventMap[K];
|
|
20
|
+
}
|
|
21
|
+
/** An event this version of the SDK doesn't know. */
|
|
22
|
+
export interface UnknownEvent {
|
|
23
|
+
/** Always `"unknown"`. */
|
|
24
|
+
type: "unknown";
|
|
25
|
+
/** The event's name on the socket. */
|
|
26
|
+
name: string;
|
|
27
|
+
/** ID of the app the event belongs to. */
|
|
28
|
+
appId: string;
|
|
29
|
+
/** Event payload, not checked by the SDK. */
|
|
30
|
+
data: Record<string, unknown>;
|
|
31
|
+
}
|
|
12
32
|
/**
|
|
13
|
-
*
|
|
33
|
+
* A live event for a subscribed app.
|
|
14
34
|
*
|
|
15
|
-
* Check `type` to narrow `data` to that event's payload.
|
|
16
|
-
*
|
|
17
|
-
*
|
|
35
|
+
* Check `type` to narrow `data` to that event's payload. The `data` of an event holds only the
|
|
36
|
+
* fields that changed. Keep your value for any field the event leaves out, and clear a field the
|
|
37
|
+
* event sets to `null`.
|
|
38
|
+
* [Socket messages](/developers/references/apps-api/sections/socket-messages) lists every event
|
|
39
|
+
* and its payload.
|
|
18
40
|
*
|
|
19
41
|
* An event added to the service after this version of the SDK arrives with `type: "unknown"`, its
|
|
20
|
-
* name in `name
|
|
21
|
-
* arrives under its own `type`.
|
|
42
|
+
* event name in `name`, and an unchecked `data`, so check a field before using it. After you
|
|
43
|
+
* upgrade, the event arrives under its own `type`.
|
|
22
44
|
*
|
|
23
45
|
* @example
|
|
24
46
|
* ```typescript
|
|
@@ -28,42 +50,23 @@ export type PlatformEventMap = {
|
|
|
28
50
|
* const { message } = event.data;
|
|
29
51
|
* console.log(`Message ${message.id} changed`);
|
|
30
52
|
* }
|
|
53
|
+
* // A hypothetical event this version of the SDK doesn't know yet
|
|
31
54
|
* if (event.type === "unknown" && event.name === "app.renamed" && typeof event.data.name === "string") {
|
|
32
55
|
* console.log(`App renamed to ${event.data.name}`);
|
|
33
56
|
* }
|
|
34
57
|
* }
|
|
35
58
|
* ```
|
|
36
59
|
*/
|
|
37
|
-
export type PlatformEvent =
|
|
38
|
-
[K in keyof PlatformEventMap]: {
|
|
39
|
-
/** Event name. Narrows the type of `data`. */
|
|
40
|
-
type: K;
|
|
41
|
-
/** ID of the app the event belongs to. */
|
|
42
|
-
appId: string;
|
|
43
|
-
/** Event payload. */
|
|
44
|
-
data: PlatformEventMap[K];
|
|
45
|
-
};
|
|
46
|
-
}[keyof PlatformEventMap] | {
|
|
47
|
-
/** An event this version of the SDK doesn't know. */
|
|
48
|
-
type: "unknown";
|
|
49
|
-
/** The event's name on the socket. */
|
|
50
|
-
name: string;
|
|
51
|
-
/** ID of the app the event belongs to. */
|
|
52
|
-
appId: string;
|
|
53
|
-
/** Event payload, not checked by the SDK. */
|
|
54
|
-
data: Record<string, unknown>;
|
|
55
|
-
};
|
|
60
|
+
export type PlatformEvent = AppEvent<"message.updated"> | AppEvent<"message.removed"> | AppEvent<"app.status_changed"> | AppEvent<"preview.reload_requested"> | AppEvent<"preview.navigation_requested"> | AppEvent<"queue.updated"> | AppEvent<"task.progressed"> | AppEvent<"image.resolved"> | AppEvent<"conversation.changed"> | AppEvent<"files.changed"> | AppEvent<"branch.deleted"> | AppEvent<"repository.changed"> | AppEvent<"pull_request.changed"> | UnknownEvent;
|
|
56
61
|
/**
|
|
57
62
|
* An app's current state.
|
|
58
63
|
*
|
|
59
|
-
*
|
|
60
|
-
* everything you hold for the app with
|
|
61
|
-
*
|
|
62
|
-
* Its fields are the `data` of [`app.snapshot`](/developers/references/apps-api/sections/socket-messages#app-snapshot),
|
|
63
|
-
* plus `room`.
|
|
64
|
+
* The snapshot arrives when you subscribe, after every reconnect, and after the main conversation
|
|
65
|
+
* is rewritten. Replace everything you hold for the app with the snapshot. A snapshot holds only
|
|
66
|
+
* the last 50 messages.
|
|
64
67
|
*/
|
|
65
68
|
export interface PlatformSnapshot extends Omit<Snapshot, "queue"> {
|
|
66
|
-
/**
|
|
69
|
+
/** Identifies the app the snapshot is for, in the form `/apps/{app_id}`. */
|
|
67
70
|
room: string;
|
|
68
71
|
/** The main branch's prompt queue. Missing when the server sends none. */
|
|
69
72
|
queue?: QueueState;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import type { PlatformEvent, PlatformSnapshot } from "./chat.events.types.js";
|
|
2
|
+
import type { PlatformSocketError } from "../errors.js";
|
|
3
|
+
/**
|
|
4
|
+
* The response body of [Create socket session](/api-reference/create-socket-session), which your
|
|
5
|
+
* `getSession()` callback returns. Pass the response through unchanged. The client reads the three
|
|
6
|
+
* fields below.
|
|
7
|
+
*/
|
|
8
|
+
export interface SocketSession {
|
|
9
|
+
/** Token that authenticates the socket. The client keeps it in memory and sends it only when the socket connects. */
|
|
10
|
+
session_token: string;
|
|
11
|
+
/** Origin of the platform socket, with no path, query, fragment, or credentials. */
|
|
12
|
+
socket_url: string;
|
|
13
|
+
/** Absolute path the socket connects on, such as `/ws/socket.io/`. */
|
|
14
|
+
socket_path: string;
|
|
15
|
+
}
|
|
16
|
+
/** Options for {@linkcode ChatModule.init | init()}. */
|
|
17
|
+
export interface ChatInitOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Returns a new socket session from your server.
|
|
20
|
+
*
|
|
21
|
+
* Return the response body of [Create socket session](/api-reference/create-socket-session) as a
|
|
22
|
+
* [`SocketSession`](#socketsession), and return a new session on every call. The client calls
|
|
23
|
+
* `getSession()` on the first {@linkcode ChatSession.connect | connect()}, and again only when
|
|
24
|
+
* the session expires or Base44 rejects its token. If a new session has a different `socket_url`
|
|
25
|
+
* or `socket_path`, the client moves to it and rejoins every active subscription.
|
|
26
|
+
*
|
|
27
|
+
* @returns The session, as your server received it.
|
|
28
|
+
*/
|
|
29
|
+
getSession: () => Promise<SocketSession>;
|
|
30
|
+
/**
|
|
31
|
+
* Called on errors that affect the whole session, such as a failed connection or an ended session.
|
|
32
|
+
* Errors for one app go to that subscription's `onError()` instead. The
|
|
33
|
+
* [error codes](#errors)
|
|
34
|
+
* say what each error means.
|
|
35
|
+
*/
|
|
36
|
+
onError: (error: PlatformSocketError) => void;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Chat module for following the AI chat of your users' apps in real time. Call
|
|
40
|
+
* {@linkcode init | init()} to create a session and start following.
|
|
41
|
+
*
|
|
42
|
+
* A session holds one socket and up to eight app subscriptions. For each app, you get a
|
|
43
|
+
* snapshot of the app's chat, then every change as it happens:
|
|
44
|
+
* - New and updated chat messages, with the AI's tool calls.
|
|
45
|
+
* - The AI's status, from processing to ready.
|
|
46
|
+
* - Preview reloads and navigation, the prompt queue, and generated images.
|
|
47
|
+
*/
|
|
48
|
+
export interface ChatModule {
|
|
49
|
+
/**
|
|
50
|
+
* Creates a session without connecting it. A [session](#session-methods) is one socket plus the
|
|
51
|
+
* app subscriptions that share it.
|
|
52
|
+
*
|
|
53
|
+
* Pass a `getSession()` callback in the options. The client calls it to get a
|
|
54
|
+
* [socket session](/developers/references/apps-api/sections/socket-sessions), which your server
|
|
55
|
+
* opens with [Create socket session](/api-reference/create-socket-session) and returns as the
|
|
56
|
+
* response body. Each session is independent and gets its own socket session.
|
|
57
|
+
*
|
|
58
|
+
* Call {@linkcode ChatSession.connect | connect()} on the returned session to open the socket.
|
|
59
|
+
*
|
|
60
|
+
* @param options - Session options.
|
|
61
|
+
* @returns The new session.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* // Create and connect a session
|
|
66
|
+
* const chat = client.chat.init({
|
|
67
|
+
* async getSession() {
|
|
68
|
+
* const response = await fetch('/api/chat-socket-session', { method: 'POST' });
|
|
69
|
+
* return response.json();
|
|
70
|
+
* },
|
|
71
|
+
* onError(error) {
|
|
72
|
+
* console.error('Live updates error', error.code);
|
|
73
|
+
* },
|
|
74
|
+
* });
|
|
75
|
+
* await chat.connect();
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
init(options: ChatInitOptions): ChatSession;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* A session is one socket plus the app subscriptions that share it, and it reconnects automatically
|
|
82
|
+
* if the connection drops. Use the methods below to connect the socket, follow apps, and close the
|
|
83
|
+
* session.
|
|
84
|
+
*/
|
|
85
|
+
export interface ChatSession {
|
|
86
|
+
/**
|
|
87
|
+
* Connects the session's socket.
|
|
88
|
+
*
|
|
89
|
+
* The first call gets a socket session from [`getSession()`](#init). If the session has expired
|
|
90
|
+
* or Base44 rejects its token, the client calls `getSession()` once more for a new one.
|
|
91
|
+
* Concurrent calls share one attempt.
|
|
92
|
+
*
|
|
93
|
+
* The promise resolves once the socket connects, before any snapshot arrives. If the connection
|
|
94
|
+
* drops, the session retries five times and rejoins every active subscription, each with a fresh
|
|
95
|
+
* snapshot.
|
|
96
|
+
*
|
|
97
|
+
* Call `connect()` again after a failure or a `session_replaced` error.
|
|
98
|
+
*
|
|
99
|
+
* @returns A promise that resolves when the socket connects.
|
|
100
|
+
* @throws {PlatformSocketError} The promise rejects with a `PlatformSocketError` whose code is
|
|
101
|
+
* `connection_denied`, `connection_failed`, or `session_unavailable` when the session can't connect,
|
|
102
|
+
* or `client_closed` when the session is closed first.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* // Connect and handle failure
|
|
107
|
+
* try {
|
|
108
|
+
* await chat.connect();
|
|
109
|
+
* } catch (error) {
|
|
110
|
+
* console.error('Could not connect', error.code);
|
|
111
|
+
* }
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
connect(): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Subscribes to an app's chat.
|
|
117
|
+
*
|
|
118
|
+
* You can subscribe before or after connecting. A session has one subscription per app, up to
|
|
119
|
+
* eight in total. A session can only follow apps your server gave the session access to, either
|
|
120
|
+
* in [Create socket session](/api-reference/create-socket-session) or later with
|
|
121
|
+
* [Add app to session](/api-reference/add-app-to-session). Subscribing to any other app fails
|
|
122
|
+
* with `access_denied`. The subscription first receives a snapshot of the app, then each live
|
|
123
|
+
* event.
|
|
124
|
+
*
|
|
125
|
+
* Pass `onSnapshot()`, `onEvent()`, and `onError()` callbacks in the options to receive the app's
|
|
126
|
+
* snapshot, live events, and errors.
|
|
127
|
+
*
|
|
128
|
+
* Callbacks for an app run one at a time, in order. If a callback returns a promise, the session
|
|
129
|
+
* waits for it before calling the next callback for that app. Each app has its own queue, so a
|
|
130
|
+
* slow callback for one app doesn't delay the others. If more than 1,000 snapshots and events are
|
|
131
|
+
* waiting for an app's callbacks, the subscription ends with `delivery_overflow`.
|
|
132
|
+
*
|
|
133
|
+
* @param appId - ID of the app to follow, 24 lowercase hexadecimal characters.
|
|
134
|
+
* @param options - Callbacks for the app's snapshots, events, and errors.
|
|
135
|
+
* @returns The subscription.
|
|
136
|
+
* @throws {TypeError} The method throws a `TypeError` when `appId` isn't a valid app ID or the app already has a subscription.
|
|
137
|
+
* @throws {PlatformSocketError} The method throws a `PlatformSocketError` whose code is `subscription_limit` when the session already has eight subscriptions.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* // Follow an app
|
|
142
|
+
* const subscription = chat.subscribe(appId, {
|
|
143
|
+
* onSnapshot(snapshot) {
|
|
144
|
+
* renderChat(snapshot.messages);
|
|
145
|
+
* },
|
|
146
|
+
* onEvent(event) {
|
|
147
|
+
* if (event.type === 'message.updated') upsertMessage(event.data.message);
|
|
148
|
+
* },
|
|
149
|
+
* onError(error) {
|
|
150
|
+
* console.error(`App ${error.appId}`, error.code);
|
|
151
|
+
* },
|
|
152
|
+
* });
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
subscribe(appId: string, options: SubscriptionOptions): PlatformSubscription;
|
|
156
|
+
/**
|
|
157
|
+
* Closes the session.
|
|
158
|
+
*
|
|
159
|
+
* Call `close()` when the page closes or you no longer need live updates. Closing ends every
|
|
160
|
+
* subscription, stops reconnecting, and disconnects the socket. Calling `close()` again does
|
|
161
|
+
* nothing. A closed session can't be reused, so call [`init()`](/developers/references/platform-sdk/docs/interfaces/chat#init)
|
|
162
|
+
* for a new one.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* // Close a session
|
|
167
|
+
* chat.close();
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
close(): void;
|
|
171
|
+
}
|
|
172
|
+
/** Callbacks for one app subscription. */
|
|
173
|
+
export interface SubscriptionOptions {
|
|
174
|
+
/**
|
|
175
|
+
* Called with the app's current state, a [`PlatformSnapshot`](#platformsnapshot). Replace everything you hold for the app with the snapshot.
|
|
176
|
+
*
|
|
177
|
+
* The snapshot arrives when you subscribe, after every reconnect, and after the main conversation
|
|
178
|
+
* is rewritten by an undo, restore, or sync. Live events follow it. A snapshot holds only the last
|
|
179
|
+
* 50 messages, so load older history again if you show it.
|
|
180
|
+
*/
|
|
181
|
+
onSnapshot: (snapshot: PlatformSnapshot) => void | Promise<void>;
|
|
182
|
+
/**
|
|
183
|
+
* Called with each live event, a [`PlatformEvent`](#platformevent). Events for an app arrive one at a time, in order. If the callback
|
|
184
|
+
* throws or rejects, the subscription ends with `handler_failed`.
|
|
185
|
+
*
|
|
186
|
+
* New event types can be added at any time, so ignore the types you don't handle. An event newer
|
|
187
|
+
* than this SDK arrives with `type: "unknown"`, and its event name is in `name`.
|
|
188
|
+
* [Socket messages](/developers/references/apps-api/sections/socket-messages) lists every event
|
|
189
|
+
* and its payload.
|
|
190
|
+
*/
|
|
191
|
+
onEvent: (event: PlatformEvent) => void | Promise<void>;
|
|
192
|
+
/**
|
|
193
|
+
* Called on errors for this app. Every error ends the subscription except `snapshot_unavailable`.
|
|
194
|
+
* The [error codes](#errors)
|
|
195
|
+
* say what each error means.
|
|
196
|
+
*/
|
|
197
|
+
onError: (error: PlatformSocketError) => void;
|
|
198
|
+
}
|
|
199
|
+
/** A subscription to an app's chat. */
|
|
200
|
+
export interface PlatformSubscription {
|
|
201
|
+
/** ID of the app. */
|
|
202
|
+
readonly appId: string;
|
|
203
|
+
/** Whether the subscription still receives updates. The value becomes `false` after an error or a call to {@linkcode unsubscribe | unsubscribe()}. */
|
|
204
|
+
readonly active: boolean;
|
|
205
|
+
/**
|
|
206
|
+
* Stops updates for the app and frees its subscription slot. Calling it again does nothing.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* // Stop following an app
|
|
211
|
+
* subscription.unsubscribe();
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
unsubscribe(): void;
|
|
215
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Message } from "../client/modules/
|
|
2
|
-
import type { ToolCall } from "../client/modules/
|
|
1
|
+
import type { Message } from "../client/modules/chat.events.generated.js";
|
|
2
|
+
import type { ToolCall } from "../client/modules/chat.events.types.js";
|
|
3
3
|
import type { ChatItem, ChatQuestion, ChatStep } from "./chat.types.js";
|
|
4
4
|
/** @internal Sends the answer to the one tool call a question belongs to. */
|
|
5
5
|
export type AnswerToolCall = (approve: boolean, extraUserInput?: Record<string, unknown>) => Promise<void>;
|
|
@@ -20,7 +20,7 @@ export declare function mergeSnapshot(heldMessages: Message[], snapshotMessages:
|
|
|
20
20
|
export declare function toItems(sortedMessages: Message[], answeredToolCallIds: string[], submitAnswer: SubmitAnswer): ChatItem[];
|
|
21
21
|
/** @internal Base44's tool call status, as a step's. */
|
|
22
22
|
export declare function stepStatus(toolCall: ToolCall): ChatStep["status"];
|
|
23
|
-
/** @internal Whether the chat waits on the user. Like Base44's
|
|
23
|
+
/** @internal Whether the chat waits on the user. Like Base44's app editor, only the last turn reply
|
|
24
24
|
* counts, and a call answered or declined here stops counting. */
|
|
25
25
|
export declare function isWaitingForUser(sortedMessages: Message[], answeredToolCallIds: string[]): boolean;
|
|
26
26
|
/** @internal Waiting calls on the last turn reply whose kind Base44 names and this release doesn't
|
|
@@ -46,6 +46,6 @@ export declare function settlePendingPrompts(pendingPrompts: PendingPrompt[], ap
|
|
|
46
46
|
export declare function pendingPromptItems(pendingPrompts: PendingPrompt[]): ChatItem[];
|
|
47
47
|
/** @internal Base44's question formats, as one simple shape per kind, each bound to the call that
|
|
48
48
|
* answers it. Base44 keys choice answers by position, so `picked` and `texts` follow `questions`,
|
|
49
|
-
* and like Base44's
|
|
49
|
+
* and like Base44's app editor a single pick goes in `selected_label`, several in `selected_labels`,
|
|
50
50
|
* and free text in `custom_text`. A kind this release doesn't know has no shape. */
|
|
51
51
|
export declare function toQuestion(toolCall: ToolCall, answerToolCall: AnswerToolCall): ChatQuestion | undefined;
|
package/dist/react/chat-items.js
CHANGED
|
@@ -27,7 +27,7 @@ function isTurnReply(message) {
|
|
|
27
27
|
var _a;
|
|
28
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
29
|
}
|
|
30
|
-
/** @internal The last assistant message that answers a turn, as Base44's
|
|
30
|
+
/** @internal The last assistant message that answers a turn, as Base44's app editor finds it. */
|
|
31
31
|
function lastTurnReply(sortedMessages) {
|
|
32
32
|
return [...sortedMessages].reverse().find(isTurnReply);
|
|
33
33
|
}
|
|
@@ -110,7 +110,7 @@ export function stepStatus(toolCall) {
|
|
|
110
110
|
return "error";
|
|
111
111
|
return "done";
|
|
112
112
|
}
|
|
113
|
-
/** @internal Whether the chat waits on the user. Like Base44's
|
|
113
|
+
/** @internal Whether the chat waits on the user. Like Base44's app editor, only the last turn reply
|
|
114
114
|
* counts, and a call answered or declined here stops counting. */
|
|
115
115
|
export function isWaitingForUser(sortedMessages, answeredToolCallIds) {
|
|
116
116
|
var _a;
|
|
@@ -155,7 +155,7 @@ export function pendingPromptItems(pendingPrompts) {
|
|
|
155
155
|
}
|
|
156
156
|
/** @internal Base44's question formats, as one simple shape per kind, each bound to the call that
|
|
157
157
|
* answers it. Base44 keys choice answers by position, so `picked` and `texts` follow `questions`,
|
|
158
|
-
* and like Base44's
|
|
158
|
+
* and like Base44's app editor a single pick goes in `selected_label`, several in `selected_labels`,
|
|
159
159
|
* and free text in `custom_text`. A kind this release doesn't know has no shape. */
|
|
160
160
|
export function toQuestion(toolCall, answerToolCall) {
|
|
161
161
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SocketSession } from "../client/modules/
|
|
1
|
+
import type { SocketSession } from "../client/modules/chat.types.js";
|
|
2
2
|
/** An app the AI chat works on. */
|
|
3
3
|
export interface Base44App {
|
|
4
4
|
/** ID of the app, 24 lowercase hexadecimal characters. */
|
|
@@ -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 {@link
|
|
35
|
+
* chat follows the rest live. A rejected promise from any call sets `error` on the {@link useBase44Chat | chat}.
|
|
36
36
|
*
|
|
37
37
|
* @example
|
|
38
38
|
* ```typescript
|
|
@@ -141,10 +141,10 @@ 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 {@link
|
|
144
|
+
* actions never throw. A failure sets `error` on the {@link useBase44Chat | 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
|
-
* names that kind on the last assistant message. If the decline fails,
|
|
147
|
+
* names that kind on the last assistant message. If the decline fails, the chat's `error` says
|
|
148
148
|
* so, and the chat tries again after it reconnects.
|
|
149
149
|
*/
|
|
150
150
|
export type ChatQuestion = ChoiceQuestion | SecretsQuestion | ApprovalQuestion;
|
|
@@ -296,6 +296,8 @@ export interface Base44ChatOptions {
|
|
|
296
296
|
/**
|
|
297
297
|
* Called with the new app after {@link Base44Chat.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.
|
|
299
301
|
*/
|
|
300
302
|
onAppCreated?: (app: Base44App) => void;
|
|
301
303
|
}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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
|
export { useBase44Chat } from "./useBase44Chat.js";
|
|
3
3
|
export type { ApprovalDetails, ApprovalQuestion, Base44App, Base44Chat, Base44ChatOptions, Base44ChatBackend, ChatAnswer, ChatConnection, ChatError, ChatItem, ChatQuestion, ChatStatus, ChatStep, ChoiceEntry, ChoiceQuestion, SecretField, SecretsQuestion, ToolCallAnswer, } from "./chat.types.js";
|
|
4
|
-
export type { SocketSession } from "../client/modules/
|
|
4
|
+
export type { SocketSession } from "../client/modules/chat.types.js";
|
|
@@ -168,7 +168,7 @@ export function useBase44Chat({ appId, backend, onAppCreated }) {
|
|
|
168
168
|
// The client asks for a session on the first connect and whenever one expires, and forwards
|
|
169
169
|
// no detail of a failed call, so the backend's own error is kept to report.
|
|
170
170
|
let lastSessionError;
|
|
171
|
-
const
|
|
171
|
+
const chatSession = createPlatformClient().chat.init({
|
|
172
172
|
getSession: () => backendRef.current.openLiveSession(followedAppId).then(socketSession => {
|
|
173
173
|
lastSessionError = undefined;
|
|
174
174
|
return socketSession;
|
|
@@ -185,7 +185,7 @@ export function useBase44Chat({ appId, backend, onAppCreated }) {
|
|
|
185
185
|
setConnection("disconnected");
|
|
186
186
|
},
|
|
187
187
|
});
|
|
188
|
-
|
|
188
|
+
chatSession.subscribe(followedAppId, {
|
|
189
189
|
onSnapshot: snapshot => {
|
|
190
190
|
// A snapshot holds old prompts too, so only an exact match settles one.
|
|
191
191
|
handleIncomingMessages(snapshot.messages);
|
|
@@ -220,10 +220,10 @@ export function useBase44Chat({ appId, backend, onAppCreated }) {
|
|
|
220
220
|
onError: error => (error.code === "snapshot_unavailable" ? reportConnectionError(error) : endLiveUpdates(error)),
|
|
221
221
|
});
|
|
222
222
|
// A failed connect also reaches onError, which reports it.
|
|
223
|
-
|
|
223
|
+
chatSession.connect().catch(() => { });
|
|
224
224
|
return () => {
|
|
225
225
|
closed = true;
|
|
226
|
-
|
|
226
|
+
chatSession.close();
|
|
227
227
|
};
|
|
228
228
|
}, [currentAppId]);
|
|
229
229
|
// Answers one tool call. Its id leaves the answered list again if the submit fails, so the
|
package/dist/server/errors.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ import type { WebhookConfigurationErrorCode, WebhookVerificationErrorCode } from
|
|
|
2
2
|
/**
|
|
3
3
|
* The error the SDK reports when a webhook delivery can't be trusted.
|
|
4
4
|
*
|
|
5
|
-
* You don't create
|
|
6
|
-
*
|
|
7
|
-
* to your `onError`. Check `code` to see what happened, then look the code up below.
|
|
5
|
+
* You don't create these errors. The [`verifyEvent()`](/developers/references/platform-sdk/docs/interfaces/webhooks#verifyevent) method rejects with
|
|
6
|
+
* them, and [`createHandler()`](/developers/references/platform-sdk/docs/interfaces/webhooks#createhandler) answers them with a 400 and passes
|
|
7
|
+
* them to your `onError()`. Check `code` to see what happened, then look the code up below.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* These errors never carry the request body or its signature.
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* ```typescript
|
|
@@ -22,7 +22,7 @@ import type { WebhookConfigurationErrorCode, WebhookVerificationErrorCode } from
|
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
export declare class WebhookVerificationError extends Error {
|
|
25
|
-
/** What happened. One of the
|
|
25
|
+
/** What happened. One of the verification error codes. */
|
|
26
26
|
readonly code: WebhookVerificationErrorCode;
|
|
27
27
|
/** @internal */
|
|
28
28
|
constructor(code: WebhookVerificationErrorCode);
|
|
@@ -30,9 +30,9 @@ export declare class WebhookVerificationError extends Error {
|
|
|
30
30
|
/**
|
|
31
31
|
* The error the SDK reports when the public keys you passed can't be used, so no delivery can be verified.
|
|
32
32
|
*
|
|
33
|
-
* You don't create
|
|
34
|
-
*
|
|
35
|
-
* to your `onError`. Base44 retries the delivery, and the retries succeed once you fix the problem.
|
|
33
|
+
* You don't create these errors. The [`verifyEvent()`](/developers/references/platform-sdk/docs/interfaces/webhooks#verifyevent) method rejects with
|
|
34
|
+
* them, and [`createHandler()`](/developers/references/platform-sdk/docs/interfaces/webhooks#createhandler) answers them with a 500 and passes
|
|
35
|
+
* them to your `onError()`. Base44 retries the delivery, and the retries succeed once you fix the problem.
|
|
36
36
|
*
|
|
37
37
|
* @example
|
|
38
38
|
* ```typescript
|
|
@@ -46,7 +46,7 @@ export declare class WebhookVerificationError extends Error {
|
|
|
46
46
|
* ```
|
|
47
47
|
*/
|
|
48
48
|
export declare class WebhookConfigurationError extends Error {
|
|
49
|
-
/** What's wrong with the keys. One of the
|
|
49
|
+
/** What's wrong with the keys. One of the configuration error codes. */
|
|
50
50
|
readonly code: WebhookConfigurationErrorCode;
|
|
51
51
|
/** @internal */
|
|
52
52
|
constructor(code: WebhookConfigurationErrorCode, detail: string);
|
package/dist/server/errors.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The error the SDK reports when a webhook delivery can't be trusted.
|
|
3
3
|
*
|
|
4
|
-
* You don't create
|
|
5
|
-
*
|
|
6
|
-
* to your `onError`. Check `code` to see what happened, then look the code up below.
|
|
4
|
+
* You don't create these errors. The [`verifyEvent()`](/developers/references/platform-sdk/docs/interfaces/webhooks#verifyevent) method rejects with
|
|
5
|
+
* them, and [`createHandler()`](/developers/references/platform-sdk/docs/interfaces/webhooks#createhandler) answers them with a 400 and passes
|
|
6
|
+
* them to your `onError()`. Check `code` to see what happened, then look the code up below.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* These errors never carry the request body or its signature.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```typescript
|
|
@@ -31,9 +31,9 @@ export class WebhookVerificationError extends Error {
|
|
|
31
31
|
/**
|
|
32
32
|
* The error the SDK reports when the public keys you passed can't be used, so no delivery can be verified.
|
|
33
33
|
*
|
|
34
|
-
* You don't create
|
|
35
|
-
*
|
|
36
|
-
* to your `onError`. Base44 retries the delivery, and the retries succeed once you fix the problem.
|
|
34
|
+
* You don't create these errors. The [`verifyEvent()`](/developers/references/platform-sdk/docs/interfaces/webhooks#verifyevent) method rejects with
|
|
35
|
+
* them, and [`createHandler()`](/developers/references/platform-sdk/docs/interfaces/webhooks#createhandler) answers them with a 500 and passes
|
|
36
|
+
* them to your `onError()`. Base44 retries the delivery, and the retries succeed once you fix the problem.
|
|
37
37
|
*
|
|
38
38
|
* @example
|
|
39
39
|
* ```typescript
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export type WebhookVerificationErrorCode =
|
|
6
6
|
/**
|
|
7
|
-
* The request is missing one of the `webhook-id`, `webhook-timestamp
|
|
7
|
+
* The request is missing one of the `webhook-id`, `webhook-timestamp`, or `webhook-signature` headers.
|
|
8
8
|
*
|
|
9
9
|
* Check that a proxy in front of your endpoint forwards all request headers.
|
|
10
10
|
*/
|
|
11
11
|
"missing_headers"
|
|
12
12
|
/**
|
|
13
|
-
* The `webhook-timestamp` header
|
|
13
|
+
* The `webhook-timestamp` header isn't a number, or is further from your server's clock than `toleranceSeconds`, which defaults to 300.
|
|
14
14
|
*
|
|
15
15
|
* Check your server's clock. A replayed old delivery fails this way too.
|
|
16
16
|
*/
|
|
@@ -37,7 +37,7 @@ export type WebhookVerificationErrorCode =
|
|
|
37
37
|
/**
|
|
38
38
|
* Codes of errors that stop verification before it starts, because the public keys you passed can't
|
|
39
39
|
* be used. They're about your deployment, not the request, so answer them with a 500. Base44 retries
|
|
40
|
-
* the delivery, as it does for any answer that isn't 2xx, and
|
|
40
|
+
* the delivery, as it does for any answer that isn't 2xx, and the retry succeeds once you fix the problem.
|
|
41
41
|
*/
|
|
42
42
|
export type WebhookConfigurationErrorCode =
|
|
43
43
|
/**
|
|
@@ -138,10 +138,10 @@ export interface WebhookTestV1Data {
|
|
|
138
138
|
challenge: string;
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
141
|
-
* Sent when the
|
|
141
|
+
* Sent when the AI picks the message up, not when it is received: a
|
|
142
142
|
* message sent while another turn runs waits in the queue until then.
|
|
143
143
|
*/
|
|
144
|
-
export interface
|
|
144
|
+
export interface ChatTurnStartedV1Data {
|
|
145
145
|
/**
|
|
146
146
|
* The app the event is about.
|
|
147
147
|
*/
|
|
@@ -163,7 +163,7 @@ export interface BuilderTurnStartedV1Data {
|
|
|
163
163
|
*/
|
|
164
164
|
conversation_id?: string;
|
|
165
165
|
/**
|
|
166
|
-
* When the
|
|
166
|
+
* When the AI started working on the message (UTC).
|
|
167
167
|
*/
|
|
168
168
|
started_at: string;
|
|
169
169
|
/**
|
|
@@ -172,9 +172,9 @@ export interface BuilderTurnStartedV1Data {
|
|
|
172
172
|
continues_message_id?: string;
|
|
173
173
|
}
|
|
174
174
|
/**
|
|
175
|
-
* The `data` object of `
|
|
175
|
+
* The `data` object of `chat.turn_ended.v1`. The AI finished responding to a message.
|
|
176
176
|
*/
|
|
177
|
-
export interface
|
|
177
|
+
export interface ChatTurnEndedV1Data {
|
|
178
178
|
/**
|
|
179
179
|
* The app the event is about.
|
|
180
180
|
*/
|
|
@@ -196,7 +196,7 @@ export interface BuilderTurnEndedV1Data {
|
|
|
196
196
|
*/
|
|
197
197
|
conversation_id?: string;
|
|
198
198
|
/**
|
|
199
|
-
* When the
|
|
199
|
+
* When the AI started working on the message (UTC).
|
|
200
200
|
*/
|
|
201
201
|
started_at: string;
|
|
202
202
|
/**
|
|
@@ -204,7 +204,7 @@ export interface BuilderTurnEndedV1Data {
|
|
|
204
204
|
*/
|
|
205
205
|
continues_message_id?: string;
|
|
206
206
|
/**
|
|
207
|
-
* How the turn ended. `finished`: the
|
|
207
|
+
* How the turn ended. `finished`: the AI replied and has nothing pending. `waiting_for_user_input`: the AI stopped to ask something, such as a clarifying question or a plan to approve, and continues when the next message answers it. `failed`: the turn hit an error. `cancelled`: the turn was stopped before it ended. `interrupted`: the AI was interrupted, for example by a restart, and continues the work in a new turn whose `continues_message_id` is this message.
|
|
208
208
|
*/
|
|
209
209
|
status: "finished" | "waiting_for_user_input" | "failed" | "cancelled" | "interrupted";
|
|
210
210
|
/**
|
|
@@ -226,10 +226,10 @@ export interface WebhookEventMap {
|
|
|
226
226
|
"app.restored.v1": AppRestoredV1Data;
|
|
227
227
|
/** Carries no domain data — its only job is to be verifiable and echoed. */
|
|
228
228
|
"webhook.test.v1": WebhookTestV1Data;
|
|
229
|
-
/** Sent when the
|
|
230
|
-
"
|
|
231
|
-
/** The
|
|
232
|
-
"
|
|
229
|
+
/** Sent when the AI picks the message up, not when it is received: a */
|
|
230
|
+
"chat.turn_started.v1": ChatTurnStartedV1Data;
|
|
231
|
+
/** The AI finished responding to a message. */
|
|
232
|
+
"chat.turn_ended.v1": ChatTurnEndedV1Data;
|
|
233
233
|
}
|
|
234
234
|
/** Every event type in {@link WebhookEventMap}, so events from a newer Base44 can be told apart at runtime. @internal */
|
|
235
|
-
export declare const WEBHOOK_EVENT_TYPES: readonly ["app.created.v1", "app.published.v1", "app.unpublished.v1", "app.deleted.v1", "app.restored.v1", "webhook.test.v1", "
|
|
235
|
+
export declare const WEBHOOK_EVENT_TYPES: readonly ["app.created.v1", "app.published.v1", "app.unpublished.v1", "app.deleted.v1", "app.restored.v1", "webhook.test.v1", "chat.turn_started.v1", "chat.turn_ended.v1"];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// Generated by scripts/generate-webhook-types.mjs from the schemas published at
|
|
2
2
|
// https://base44.com/webhooks/schemas. Do not edit by hand; run `npm run generate:webhooks`.
|
|
3
3
|
/** Every event type in {@link WebhookEventMap}, so events from a newer Base44 can be told apart at runtime. @internal */
|
|
4
|
-
export const WEBHOOK_EVENT_TYPES = ["app.created.v1", "app.published.v1", "app.unpublished.v1", "app.deleted.v1", "app.restored.v1", "webhook.test.v1", "
|
|
4
|
+
export const WEBHOOK_EVENT_TYPES = ["app.created.v1", "app.published.v1", "app.unpublished.v1", "app.deleted.v1", "app.restored.v1", "webhook.test.v1", "chat.turn_started.v1", "chat.turn_ended.v1"];
|