@base44-preview/platform 0.3.0-pr.340.4cdf434 → 0.3.0-pr.341.adc3ff5
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 +35 -34
- package/dist/client/client.d.ts +5 -5
- package/dist/client/client.js +7 -7
- package/dist/client/client.types.d.ts +3 -3
- package/dist/client/errors.d.ts +3 -3
- package/dist/client/errors.js +3 -3
- package/dist/client/index.d.ts +3 -3
- package/dist/client/modules/{chat-protocol.d.ts → builder-protocol.d.ts} +2 -2
- package/dist/client/modules/{chat-protocol.js → builder-protocol.js} +1 -1
- package/dist/client/modules/{chat-socket.d.ts → builder-socket.d.ts} +3 -3
- package/dist/client/modules/{chat-socket.js → builder-socket.js} +4 -4
- package/dist/client/modules/{chat-subscription.d.ts → builder-subscription.d.ts} +2 -2
- package/dist/client/modules/builder.d.ts +3 -0
- package/dist/client/modules/{chat.events.types.d.ts → builder.events.types.d.ts} +1 -1
- package/dist/client/modules/builder.js +7 -0
- package/dist/client/modules/{chat.types.d.ts → builder.types.d.ts} +18 -18
- package/dist/react/chat-items.d.ts +4 -4
- package/dist/react/chat-items.js +3 -3
- package/dist/react/chat.types.d.ts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/useBase44Chat.js +4 -4
- package/dist/server/modules/webhooks.events.generated.d.ts +12 -12
- package/dist/server/modules/webhooks.events.generated.js +1 -1
- package/package.json +2 -2
- package/dist/client/modules/chat.d.ts +0 -3
- package/dist/client/modules/chat.js +0 -7
- /package/dist/client/modules/{chat-subscription.js → builder-subscription.js} +0 -0
- /package/dist/client/modules/{chat.events.generated.d.ts → builder.events.generated.d.ts} +0 -0
- /package/dist/client/modules/{chat.events.generated.js → builder.events.generated.js} +0 -0
- /package/dist/client/modules/{chat.events.types.js → builder.events.types.js} +0 -0
- /package/dist/client/modules/{chat.types.js → builder.types.js} +0 -0
package/README.md
CHANGED
|
@@ -7,8 +7,8 @@ npm install @base44/platform
|
|
|
7
7
|
The Platform SDK for white-label platforms built on Base44. It is independent of the app SDK
|
|
8
8
|
(`@base44/sdk`) and has two entrypoints:
|
|
9
9
|
|
|
10
|
-
- `@base44/platform`, for the browser: implements the read-only white-label
|
|
11
|
-
contract. A partner's browser watches the
|
|
10
|
+
- `@base44/platform`, for the browser: implements the read-only white-label builder socket
|
|
11
|
+
contract. A partner's browser watches the builder chat of up to eight apps over the platform's
|
|
12
12
|
shared socket. The workspace must have white-label sockets enabled; this SDK does not open sessions.
|
|
13
13
|
- `@base44/platform/server`, for your backend: verify the webhooks Base44 sends when apps are
|
|
14
14
|
created, published, unpublished, trashed or restored. See
|
|
@@ -18,24 +18,24 @@ The Platform SDK for white-label platforms built on Base44. It is independent of
|
|
|
18
18
|
import { createPlatformClient } from "@base44/platform";
|
|
19
19
|
|
|
20
20
|
const client = createPlatformClient();
|
|
21
|
-
const
|
|
22
|
-
// Returns the body of POST /api/
|
|
21
|
+
const builder = client.builder.init({
|
|
22
|
+
// Returns the body of POST /api/v1/socket-sessions, unchanged.
|
|
23
23
|
async getSession() {
|
|
24
|
-
const response = await fetch("/api/
|
|
24
|
+
const response = await fetch("/api/builder-socket-session", { method: "POST" });
|
|
25
25
|
if (!response.ok) throw new Error("Session request failed");
|
|
26
26
|
return response.json();
|
|
27
27
|
},
|
|
28
28
|
onError(error) { showConnectionError(error.code); },
|
|
29
29
|
});
|
|
30
|
-
const subscription =
|
|
30
|
+
const subscription = builder.subscribe(appId, {
|
|
31
31
|
onSnapshot(snapshot) { replaceAppState(snapshot); },
|
|
32
32
|
async onEvent(event) { await applyEvent(event); }, // awaited before the next event
|
|
33
33
|
onError(error) { showSubscriptionError(error.code); },
|
|
34
34
|
});
|
|
35
|
-
await
|
|
35
|
+
await builder.connect();
|
|
36
36
|
// On view teardown:
|
|
37
37
|
subscription.unsubscribe();
|
|
38
|
-
|
|
38
|
+
builder.close();
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
## Receiving webhooks (server)
|
|
@@ -97,17 +97,18 @@ Delivery is at least once with no ordering guarantee: deduplicate on `event.id`,
|
|
|
97
97
|
|
|
98
98
|
## Sessions
|
|
99
99
|
|
|
100
|
-
`/api/
|
|
101
|
-
socket session
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
`/api/builder-socket-session` is your backend's route, not an SDK endpoint. It opens a
|
|
101
|
+
socket session through `POST /api/v1/socket-sessions` with `{ app_ids }`, and returns the
|
|
102
|
+
response body to the browser. It authenticates as `Authorization: Bearer` with either a
|
|
103
|
+
personal access token, which can watch the apps its owner can edit in its workspace, or a
|
|
104
|
+
workspace API key with the `apps:watch` scope. The workspace needs the Builder plan or higher. `getSession` returns that body unchanged: the SDK reads `session_token`,
|
|
104
105
|
`socket_url` and `socket_path` and ignores other keys such as `session_id` and
|
|
105
|
-
`expires_in`. Never pass the workspace key or any other server credential to this client. Subscribe only to apps on the session's allowlist; your
|
|
106
|
-
backend adds or removes apps with `PUT`/`DELETE /api/
|
|
106
|
+
`expires_in`. Never pass the token, the workspace key or any other server credential to this client. Subscribe only to apps on the session's allowlist; your
|
|
107
|
+
backend adds or removes apps with `PUT`/`DELETE /api/v1/socket-sessions/{session_id}/apps/{app_id}`.
|
|
107
108
|
|
|
108
109
|
A session lasts one hour and is never extended. The token goes exclusively in
|
|
109
110
|
CONNECT `auth.session_token`, never a URL, and the SDK keeps it in memory only. It
|
|
110
|
-
is reused across automatic reconnects. `getSession` is called when a
|
|
111
|
+
is reused across automatic reconnects. `getSession` is called when a builder
|
|
111
112
|
session first connects, and again only when the server rejects the cached token or
|
|
112
113
|
expires the session; the SDK then reconnects once with the new session. If the new
|
|
113
114
|
session has a different `socket_url` or `socket_path`, the SDK closes the old socket,
|
|
@@ -123,26 +124,26 @@ older one, which stops with `session_replaced`. Open one session per page.
|
|
|
123
124
|
|
|
124
125
|
`createPlatformClient()` creates a lightweight module container: no Socket.IO
|
|
125
126
|
instance, timers, session request or network activity. It takes no options. Its
|
|
126
|
-
`
|
|
127
|
+
`builder` module follows the server SDK's module-factory pattern.
|
|
127
128
|
|
|
128
|
-
`client.
|
|
129
|
-
`
|
|
129
|
+
`client.builder.init({ getSession, onError })` synchronously creates an independent
|
|
130
|
+
`BuilderSession` without connecting or creating a socket. Repeated calls create separate sessions, each owning its own
|
|
130
131
|
socket, listeners, subscriptions and cleanup. Close the returned session when its
|
|
131
132
|
view is disposed; the root client and other sessions remain usable.
|
|
132
133
|
|
|
133
|
-
`
|
|
134
|
+
`builder.connect()` fetches the first session, creates the socket at its address and
|
|
134
135
|
resolves on CONNECT, before any snapshot. The socket uses the default namespace on the
|
|
135
136
|
session's `socket_path`, WebSocket only, with a dedicated manager.
|
|
136
137
|
Transport reconnection uses five attempts, starting at one second and capped at ten
|
|
137
138
|
seconds with jitter; each attempt has a twenty-second timeout. A temporary server
|
|
138
139
|
refusal is retried the same way. After exhaustion, a refusal or `session_replaced`,
|
|
139
|
-
fix the cause and call `
|
|
140
|
+
fix the cause and call `builder.connect()`.
|
|
140
141
|
|
|
141
|
-
`
|
|
142
|
+
`builder.subscribe(appId, options)` returns a handle with `appId`, `active` and
|
|
142
143
|
idempotent `unsubscribe()`. App IDs are 24 lowercase hexadecimal characters. One
|
|
143
|
-
subscription per app and at most eight subscriptions are allowed per
|
|
144
|
-
Subscriptions can be created before connecting. `
|
|
145
|
-
session; call `client.
|
|
144
|
+
subscription per app and at most eight subscriptions are allowed per builder session.
|
|
145
|
+
Subscriptions can be created before connecting. `builder.close()` is terminal for that
|
|
146
|
+
session; call `client.builder.init(...)` again to start another.
|
|
146
147
|
|
|
147
148
|
## Snapshots and events
|
|
148
149
|
|
|
@@ -161,15 +162,15 @@ their exceptions are isolated so they cannot interrupt another app's delivery.
|
|
|
161
162
|
|
|
162
163
|
## Public shapes
|
|
163
164
|
|
|
164
|
-
- `PlatformClient` (`client.types.ts`): the `
|
|
165
|
-
- `
|
|
166
|
-
- `
|
|
165
|
+
- `PlatformClient` (`client.types.ts`): the `builder` module.
|
|
166
|
+
- `BuilderModule` (`modules/builder.types.ts`): lazy `init(options)` factory.
|
|
167
|
+
- `BuilderInitOptions`: `getSession` and the connection-level `onError` observer.
|
|
167
168
|
- `SocketSession`: the `session_token`, `socket_url` and `socket_path` that `getSession` returns.
|
|
168
|
-
- `
|
|
169
|
+
- `BuilderSession`: `connect()`, `subscribe(appId, options)`, `close()`.
|
|
169
170
|
- `SubscriptionOptions`: required `onSnapshot`, `onEvent` and `onError`.
|
|
170
171
|
- `PlatformSubscription`: read-only `appId`, `active`, and `unsubscribe()`.
|
|
171
172
|
- `PlatformEvent`, `PlatformEventMap`, `PlatformSnapshot`, `ToolCall`, `GuardApproval`
|
|
172
|
-
(`modules/
|
|
173
|
+
(`modules/builder.events.types.ts`), derived from the generated event types.
|
|
173
174
|
- Error codes in `errors.types.ts`.
|
|
174
175
|
|
|
175
176
|
`PlatformEvent` is a **discriminated union**: switch on `event.type` to narrow
|
|
@@ -186,7 +187,7 @@ redaction of generated prose or user content.
|
|
|
186
187
|
## Event types
|
|
187
188
|
|
|
188
189
|
The socket protocol is defined by the service's AsyncAPI document, committed as
|
|
189
|
-
`asyncapi.json`. `src/client/modules/
|
|
190
|
+
`asyncapi.json`. `src/client/modules/builder.events.generated.ts` is generated from it with
|
|
190
191
|
`json-schema-to-typescript`: one type per schema, named after the backend model
|
|
191
192
|
(`Message`, `StatusObject`, `QueueState`, one `*Call` per tool, one `*Approval` per
|
|
192
193
|
guard), plus `ServerEventMap` and `ClientMessageMap`. Never edit it by hand.
|
|
@@ -229,16 +230,16 @@ exceptions, payloads and credentials are never attached.
|
|
|
229
230
|
| `delivery_overflow` | 1,000 deliveries queued for the app; subscribe again for a fresh snapshot. |
|
|
230
231
|
| `protocol_error` | Invalid routing or envelope. Stop and investigate. |
|
|
231
232
|
| `handler_failed` | An application callback failed; fix it and subscribe again. |
|
|
232
|
-
| `client_closed` | The
|
|
233
|
+
| `client_closed` | The builder session was explicitly closed; initialize another session. |
|
|
233
234
|
|
|
234
235
|
No SDK dependency, package version or lockfile changes are required. Socket.IO
|
|
235
236
|
remains the existing SDK dependency. Chat commands and HTTP APIs are outside this entry point.
|
|
236
237
|
|
|
237
238
|
## React
|
|
238
239
|
|
|
239
|
-
`@base44/platform/react` adds one hook, `useBase44Chat`, that runs
|
|
240
|
+
`@base44/platform/react` adds one hook, `useBase44Chat`, that runs a builder chat for one
|
|
240
241
|
app on top of this client: it opens the live session and renews it, turns messages into items
|
|
241
|
-
made for rendering, binds every question the
|
|
242
|
+
made for rendering, binds every question the builder asks to the step it belongs to. It renders nothing. React is an optional peer dependency, loaded only by this
|
|
242
243
|
entry; the root entry stays framework-free.
|
|
243
244
|
|
|
244
245
|
```tsx
|
|
@@ -258,5 +259,5 @@ call with your credentials, so the browser never holds a key. The hook returns `
|
|
|
258
259
|
the first, and the chat watches it while `appId` is `null`. A sent prompt shows at once as a
|
|
259
260
|
`pending` item until Base44's own message arrives; a prompt sent mid-build waits in Base44's
|
|
260
261
|
queue meanwhile. A question is a union on `kind` (`choice`, `secrets`, `approval`) and carries only the
|
|
261
|
-
actions its kind allows, and declining is always one of them. As in Base44's
|
|
262
|
+
actions its kind allows, and declining is always one of them. As in Base44's builder, only the
|
|
262
263
|
last assistant message makes the chat wait; a kind this release doesn't know is declined for you. Every shape has JSDoc in `src/react/chat.types.ts`.
|
package/dist/client/client.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import type { PlatformClient } from "./client.types.js";
|
|
|
3
3
|
* Creates a platform client.
|
|
4
4
|
*
|
|
5
5
|
* This is the entry point of the Platform SDK. The client gives your white-label app editor
|
|
6
|
-
* access to the platform's modules, such as [`
|
|
7
|
-
* It takes no options and opens nothing: each
|
|
6
|
+
* access to the platform's modules, such as [`builder`](/developers/references/platform-sdk/docs/interfaces/builder).
|
|
7
|
+
* It takes no options and opens nothing: each builder session gets its socket session from the
|
|
8
8
|
* `getSession` you pass to `init()`.
|
|
9
9
|
*
|
|
10
10
|
* @returns A platform client with access to the platform's modules.
|
|
@@ -17,14 +17,14 @@ import type { PlatformClient } from "./client.types.js";
|
|
|
17
17
|
* const client = createPlatformClient();
|
|
18
18
|
*
|
|
19
19
|
* // Use the client to follow the AI chat in an app
|
|
20
|
-
* const
|
|
20
|
+
* const builder = client.builder.init({
|
|
21
21
|
* async getSession() {
|
|
22
|
-
* const response = await fetch('/api/
|
|
22
|
+
* const response = await fetch('/api/builder-socket-session', { method: 'POST' });
|
|
23
23
|
* return response.json();
|
|
24
24
|
* },
|
|
25
25
|
* onError: (error) => console.error(error.code),
|
|
26
26
|
* });
|
|
27
|
-
* await
|
|
27
|
+
* await builder.connect();
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
30
|
export declare function createPlatformClient(): PlatformClient;
|
package/dist/client/client.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createBuilder } from "./modules/builder.js";
|
|
2
2
|
/**
|
|
3
3
|
* Creates a platform client.
|
|
4
4
|
*
|
|
5
5
|
* This is the entry point of the Platform SDK. The client gives your white-label app editor
|
|
6
|
-
* access to the platform's modules, such as [`
|
|
7
|
-
* It takes no options and opens nothing: each
|
|
6
|
+
* access to the platform's modules, such as [`builder`](/developers/references/platform-sdk/docs/interfaces/builder).
|
|
7
|
+
* It takes no options and opens nothing: each builder session gets its socket session from the
|
|
8
8
|
* `getSession` you pass to `init()`.
|
|
9
9
|
*
|
|
10
10
|
* @returns A platform client with access to the platform's modules.
|
|
@@ -17,16 +17,16 @@ import { createChat } from "./modules/chat.js";
|
|
|
17
17
|
* const client = createPlatformClient();
|
|
18
18
|
*
|
|
19
19
|
* // Use the client to follow the AI chat in an app
|
|
20
|
-
* const
|
|
20
|
+
* const builder = client.builder.init({
|
|
21
21
|
* async getSession() {
|
|
22
|
-
* const response = await fetch('/api/
|
|
22
|
+
* const response = await fetch('/api/builder-socket-session', { method: 'POST' });
|
|
23
23
|
* return response.json();
|
|
24
24
|
* },
|
|
25
25
|
* onError: (error) => console.error(error.code),
|
|
26
26
|
* });
|
|
27
|
-
* await
|
|
27
|
+
* await builder.connect();
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
30
|
export function createPlatformClient() {
|
|
31
|
-
return Object.freeze({
|
|
31
|
+
return Object.freeze({ builder: Object.freeze(createBuilder()) });
|
|
32
32
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BuilderModule } from "./modules/builder.types.js";
|
|
2
2
|
/**
|
|
3
3
|
* The platform client.
|
|
4
4
|
*
|
|
5
5
|
* Provides access to the platform's modules.
|
|
6
6
|
*/
|
|
7
7
|
export interface PlatformClient {
|
|
8
|
-
/** [
|
|
9
|
-
readonly
|
|
8
|
+
/** [Builder module](/developers/references/platform-sdk/docs/interfaces/builder) for following the AI chat in your users' apps live. */
|
|
9
|
+
readonly builder: BuilderModule;
|
|
10
10
|
}
|
package/dist/client/errors.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PlatformSocketErrorCode } from "./errors.types.js";
|
|
2
2
|
/**
|
|
3
|
-
* The error the SDK reports when something goes wrong in a
|
|
3
|
+
* The error the SDK reports when something goes wrong in a builder session.
|
|
4
4
|
*
|
|
5
5
|
* You don't create it. The SDK passes it to your `onError` callbacks, `connect()` rejects with it,
|
|
6
6
|
* and `subscribe()` throws it. Check `code` to see what happened, then look the code up below:
|
|
@@ -14,14 +14,14 @@ import type { PlatformSocketErrorCode } from "./errors.types.js";
|
|
|
14
14
|
* @example
|
|
15
15
|
* ```typescript
|
|
16
16
|
* // Handle session and app errors
|
|
17
|
-
* const
|
|
17
|
+
* const builder = client.builder.init({
|
|
18
18
|
* // Session error codes: the whole session is affected
|
|
19
19
|
* onError(error) {
|
|
20
20
|
* if (error.code === 'session_revoked') showSignedOut();
|
|
21
21
|
* },
|
|
22
22
|
* });
|
|
23
23
|
*
|
|
24
|
-
*
|
|
24
|
+
* builder.subscribe(appId, {
|
|
25
25
|
* onSnapshot: renderChat,
|
|
26
26
|
* onEvent: applyEvent,
|
|
27
27
|
* // App error codes: only this app is affected, and error.appId says which
|
package/dist/client/errors.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The error the SDK reports when something goes wrong in a
|
|
2
|
+
* The error the SDK reports when something goes wrong in a builder session.
|
|
3
3
|
*
|
|
4
4
|
* You don't create it. The SDK passes it to your `onError` callbacks, `connect()` rejects with it,
|
|
5
5
|
* and `subscribe()` throws it. Check `code` to see what happened, then look the code up below:
|
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
* @example
|
|
14
14
|
* ```typescript
|
|
15
15
|
* // Handle session and app errors
|
|
16
|
-
* const
|
|
16
|
+
* const builder = client.builder.init({
|
|
17
17
|
* // Session error codes: the whole session is affected
|
|
18
18
|
* onError(error) {
|
|
19
19
|
* if (error.code === 'session_revoked') showSignedOut();
|
|
20
20
|
* },
|
|
21
21
|
* });
|
|
22
22
|
*
|
|
23
|
-
*
|
|
23
|
+
* builder.subscribe(appId, {
|
|
24
24
|
* onSnapshot: renderChat,
|
|
25
25
|
* onEvent: applyEvent,
|
|
26
26
|
* // App error codes: only this app is affected, and error.appId says which
|
package/dist/client/index.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ export { createPlatformClient } from "./client.js";
|
|
|
3
3
|
export { PlatformSocketError } from "./errors.js";
|
|
4
4
|
export type { AppErrorCode, PlatformSocketErrorCode, SessionErrorCode } from "./errors.types.js";
|
|
5
5
|
export type { PlatformClient } from "./client.types.js";
|
|
6
|
-
export type {
|
|
7
|
-
export type { GuardApproval, PlatformEvent, PlatformEventMap, PlatformSnapshot, ToolCall } from "./modules/
|
|
8
|
-
export type * from "./modules/
|
|
6
|
+
export type { BuilderModule, BuilderInitOptions, BuilderSession, PlatformSubscription, SocketSession, SubscriptionOptions } from "./modules/builder.types.js";
|
|
7
|
+
export type { GuardApproval, PlatformEvent, PlatformEventMap, PlatformSnapshot, ToolCall } from "./modules/builder.events.types.js";
|
|
8
|
+
export type * from "./modules/builder.events.generated.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PlatformEvent, PlatformSnapshot } from "./
|
|
2
|
-
import type { SocketSession } from "./
|
|
1
|
+
import type { PlatformEvent, PlatformSnapshot } from "./builder.events.types.js";
|
|
2
|
+
import type { SocketSession } from "./builder.types.js";
|
|
3
3
|
/** App events delivered to `onEvent`: every server event except the session events the socket handles. */
|
|
4
4
|
export declare const eventNames: ("message.updated" | "message.removed" | "app.status_changed" | "preview.reload_requested" | "preview.navigation_requested" | "queue.updated" | "task.progressed" | "image.resolved" | "conversation.changed" | "files.changed" | "branch.deleted" | "repository.changed" | "pull_request.changed")[];
|
|
5
5
|
/** A name newer than this SDK's protocol, delivered to `onEvent` as `unknown`. New `room.*` notices have no error code, so they are dropped. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { serverEventNames } from "./
|
|
1
|
+
import { serverEventNames } from "./builder.events.generated.js";
|
|
2
2
|
const sessionEvents = ["app.snapshot", "session.ended"];
|
|
3
3
|
/** App events delivered to `onEvent`: every server event except the session events the socket handles. */
|
|
4
4
|
export const eventNames = serverEventNames.filter((name) => !sessionEvents.includes(name) && !name.startsWith("room."));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BuilderInitOptions, BuilderSession, PlatformSubscription, SubscriptionOptions } from "./builder.types.js";
|
|
2
2
|
/** @internal */
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class BuilderSocket implements BuilderSession {
|
|
4
4
|
private socket?;
|
|
5
5
|
private address?;
|
|
6
6
|
private readonly subscriptions;
|
|
@@ -16,7 +16,7 @@ export declare class ChatSocket implements ChatSession {
|
|
|
16
16
|
private connecting?;
|
|
17
17
|
private resolveConnect?;
|
|
18
18
|
private rejectConnect?;
|
|
19
|
-
constructor(options:
|
|
19
|
+
constructor(options: BuilderInitOptions);
|
|
20
20
|
/** Connect with the session's token. Resolves on CONNECT, before snapshots arrive.
|
|
21
21
|
* The first call fetches the session, whose address the socket opens on.
|
|
22
22
|
* Transport loss retries up to five times and rejoins active subscriptions.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { io } from "socket.io-client";
|
|
2
2
|
import { PlatformSocketError } from "../errors.js";
|
|
3
|
-
import { appFromRoom, appPattern, decode, decodeSession, decodeSnapshot, eventNames, isUnknownEvent, object, roomFor, roomNotices, sessionEndings } from "./
|
|
4
|
-
import { notify, Subscription } from "./
|
|
3
|
+
import { appFromRoom, appPattern, decode, decodeSession, decodeSnapshot, eventNames, isUnknownEvent, object, roomFor, roomNotices, sessionEndings } from "./builder-protocol.js";
|
|
4
|
+
import { notify, Subscription } from "./builder-subscription.js";
|
|
5
5
|
const MAX_DENIAL_RETRIES = 5;
|
|
6
6
|
/** @internal */
|
|
7
|
-
export class
|
|
7
|
+
export class BuilderSocket {
|
|
8
8
|
constructor(options) {
|
|
9
9
|
this.subscriptions = new Map();
|
|
10
10
|
this.closed = false;
|
|
@@ -48,7 +48,7 @@ export class ChatSocket {
|
|
|
48
48
|
if (!appPattern.test(appId))
|
|
49
49
|
throw new TypeError("appId must be 24 lowercase hexadecimal characters");
|
|
50
50
|
if (this.subscriptions.has(appId))
|
|
51
|
-
throw new TypeError("An app may only have one subscription per
|
|
51
|
+
throw new TypeError("An app may only have one subscription per builder session");
|
|
52
52
|
if (this.subscriptions.size >= 8)
|
|
53
53
|
throw new PlatformSocketError("subscription_limit", appId);
|
|
54
54
|
const subscription = new Subscription(appId, { ...options }, () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { PlatformEvent, PlatformSnapshot } from "./
|
|
1
|
+
import type { PlatformEvent, PlatformSnapshot } from "./builder.events.types.js";
|
|
2
2
|
import { PlatformSocketError } from "../errors.js";
|
|
3
3
|
import type { PlatformSocketErrorCode } from "../errors.types.js";
|
|
4
|
-
import type { PlatformSubscription, SubscriptionOptions } from "./
|
|
4
|
+
import type { PlatformSubscription, SubscriptionOptions } from "./builder.types.js";
|
|
5
5
|
/** @internal */
|
|
6
6
|
export declare function notify(callback: (error: PlatformSocketError) => void, error: PlatformSocketError): void;
|
|
7
7
|
/** @internal */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Message, QueueState, ServerEventMap, Snapshot } from "./
|
|
1
|
+
import type { Message, QueueState, ServerEventMap, Snapshot } from "./builder.events.generated.js";
|
|
2
2
|
/**
|
|
3
3
|
* Maps each live event name to the type of its `data` payload.
|
|
4
4
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PlatformEvent, PlatformSnapshot } from "./
|
|
1
|
+
import type { PlatformEvent, PlatformSnapshot } from "./builder.events.types.js";
|
|
2
2
|
import type { PlatformSocketError } from "../errors.js";
|
|
3
3
|
/**
|
|
4
4
|
* The socket session your server opened, as [Create socket session](/api-reference/create-socket-session) returned it.
|
|
@@ -14,8 +14,8 @@ export interface SocketSession {
|
|
|
14
14
|
/** Absolute path the socket connects on, such as `/ws/socket.io/`. */
|
|
15
15
|
socket_path: string;
|
|
16
16
|
}
|
|
17
|
-
/** Options for {@linkcode
|
|
18
|
-
export interface
|
|
17
|
+
/** Options for {@linkcode BuilderModule.init | init()}. */
|
|
18
|
+
export interface BuilderInitOptions {
|
|
19
19
|
/**
|
|
20
20
|
* Returns a new socket session from your server.
|
|
21
21
|
*
|
|
@@ -36,7 +36,7 @@ export interface ChatInitOptions {
|
|
|
36
36
|
onError: (error: PlatformSocketError) => void;
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
39
|
+
* Builder module for following the AI chat in your users' apps live.
|
|
40
40
|
*
|
|
41
41
|
* Each session holds one socket and up to eight app subscriptions. For each app you get a
|
|
42
42
|
* snapshot of its chat, then every change as it happens:
|
|
@@ -46,11 +46,11 @@ export interface ChatInitOptions {
|
|
|
46
46
|
*
|
|
47
47
|
* The module does nothing until you call {@linkcode init | init()}.
|
|
48
48
|
*/
|
|
49
|
-
export interface
|
|
49
|
+
export interface BuilderModule {
|
|
50
50
|
/**
|
|
51
|
-
* Creates a
|
|
51
|
+
* Creates a builder session without connecting it.
|
|
52
52
|
*
|
|
53
|
-
* Call {@linkcode
|
|
53
|
+
* Call {@linkcode BuilderSession.connect | connect()} on the returned session to open the socket.
|
|
54
54
|
* Each session is independent, with its own socket, socket session and subscriptions.
|
|
55
55
|
*
|
|
56
56
|
* @param options - Session options.
|
|
@@ -59,25 +59,25 @@ export interface ChatModule {
|
|
|
59
59
|
* @example
|
|
60
60
|
* ```typescript
|
|
61
61
|
* // Create and connect a session
|
|
62
|
-
* const
|
|
62
|
+
* const builder = client.builder.init({
|
|
63
63
|
* async getSession() {
|
|
64
|
-
* const response = await fetch('/api/
|
|
64
|
+
* const response = await fetch('/api/builder-socket-session', { method: 'POST' });
|
|
65
65
|
* return response.json();
|
|
66
66
|
* },
|
|
67
67
|
* onError(error) {
|
|
68
|
-
* console.error('
|
|
68
|
+
* console.error('Builder session error', error.code);
|
|
69
69
|
* },
|
|
70
70
|
* });
|
|
71
|
-
* await
|
|
71
|
+
* await builder.connect();
|
|
72
72
|
* ```
|
|
73
73
|
*/
|
|
74
|
-
init(options:
|
|
74
|
+
init(options: BuilderInitOptions): BuilderSession;
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
|
-
* A `
|
|
77
|
+
* A `BuilderSession`: one socket with its app subscriptions and its reconnection. Use its methods
|
|
78
78
|
* to connect, follow apps and close.
|
|
79
79
|
*/
|
|
80
|
-
export interface
|
|
80
|
+
export interface BuilderSession {
|
|
81
81
|
/**
|
|
82
82
|
* Connects the session's socket.
|
|
83
83
|
*
|
|
@@ -94,7 +94,7 @@ export interface ChatSession {
|
|
|
94
94
|
* ```typescript
|
|
95
95
|
* // Connect and handle failure
|
|
96
96
|
* try {
|
|
97
|
-
* await
|
|
97
|
+
* await builder.connect();
|
|
98
98
|
* } catch (error) {
|
|
99
99
|
* console.error('Could not connect', error.code);
|
|
100
100
|
* }
|
|
@@ -121,7 +121,7 @@ export interface ChatSession {
|
|
|
121
121
|
* @example
|
|
122
122
|
* ```typescript
|
|
123
123
|
* // Follow an app
|
|
124
|
-
* const subscription =
|
|
124
|
+
* const subscription = builder.subscribe(appId, {
|
|
125
125
|
* onSnapshot(snapshot) {
|
|
126
126
|
* renderChat(snapshot.messages);
|
|
127
127
|
* },
|
|
@@ -139,13 +139,13 @@ export interface ChatSession {
|
|
|
139
139
|
* Closes the session.
|
|
140
140
|
*
|
|
141
141
|
* Ends every subscription, stops reconnecting and disconnects the socket. Calling it again does
|
|
142
|
-
* nothing. A closed session can't be reused, so call [`init()`](/developers/references/platform-sdk/docs/interfaces/
|
|
142
|
+
* nothing. A closed session can't be reused, so call [`init()`](/developers/references/platform-sdk/docs/interfaces/builder#init)
|
|
143
143
|
* for a new one.
|
|
144
144
|
*
|
|
145
145
|
* @example
|
|
146
146
|
* ```typescript
|
|
147
147
|
* // Close a session
|
|
148
|
-
*
|
|
148
|
+
* builder.close();
|
|
149
149
|
* ```
|
|
150
150
|
*/
|
|
151
151
|
close(): void;
|
|
@@ -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/builder.events.generated.js";
|
|
2
|
+
import type { ToolCall } from "../client/modules/builder.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 builder, 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 builder 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 own builder 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 builder, 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 builder 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/builder.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. */
|
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/builder.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 builderSession = createPlatformClient().builder.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
|
+
builderSession.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
|
+
builderSession.connect().catch(() => { });
|
|
224
224
|
return () => {
|
|
225
225
|
closed = true;
|
|
226
|
-
|
|
226
|
+
builderSession.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
|
|
@@ -138,10 +138,10 @@ export interface WebhookTestV1Data {
|
|
|
138
138
|
challenge: string;
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
141
|
-
* Sent when the
|
|
141
|
+
* Sent when the builder 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 BuilderTurnStartedV1Data {
|
|
145
145
|
/**
|
|
146
146
|
* The app the event is about.
|
|
147
147
|
*/
|
|
@@ -163,7 +163,7 @@ export interface ChatTurnStartedV1Data {
|
|
|
163
163
|
*/
|
|
164
164
|
conversation_id?: string;
|
|
165
165
|
/**
|
|
166
|
-
* When the
|
|
166
|
+
* When the builder started working on the message (UTC).
|
|
167
167
|
*/
|
|
168
168
|
started_at: string;
|
|
169
169
|
/**
|
|
@@ -172,9 +172,9 @@ export interface ChatTurnStartedV1Data {
|
|
|
172
172
|
continues_message_id?: string;
|
|
173
173
|
}
|
|
174
174
|
/**
|
|
175
|
-
* The `data` object of `
|
|
175
|
+
* The `data` object of `builder.turn_ended.v1`. The builder finished responding to a message.
|
|
176
176
|
*/
|
|
177
|
-
export interface
|
|
177
|
+
export interface BuilderTurnEndedV1Data {
|
|
178
178
|
/**
|
|
179
179
|
* The app the event is about.
|
|
180
180
|
*/
|
|
@@ -196,7 +196,7 @@ export interface ChatTurnEndedV1Data {
|
|
|
196
196
|
*/
|
|
197
197
|
conversation_id?: string;
|
|
198
198
|
/**
|
|
199
|
-
* When the
|
|
199
|
+
* When the builder started working on the message (UTC).
|
|
200
200
|
*/
|
|
201
201
|
started_at: string;
|
|
202
202
|
/**
|
|
@@ -204,7 +204,7 @@ export interface ChatTurnEndedV1Data {
|
|
|
204
204
|
*/
|
|
205
205
|
continues_message_id?: string;
|
|
206
206
|
/**
|
|
207
|
-
* How the turn ended. `finished`: the
|
|
207
|
+
* How the turn ended. `finished`: the builder replied and has nothing pending. `waiting_for_user_input`: the builder 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 builder 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 builder picks the message up, not when it is received: a */
|
|
230
|
+
"builder.turn_started.v1": BuilderTurnStartedV1Data;
|
|
231
|
+
/** The builder finished responding to a message. */
|
|
232
|
+
"builder.turn_ended.v1": BuilderTurnEndedV1Data;
|
|
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", "builder.turn_started.v1", "builder.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", "builder.turn_started.v1", "builder.turn_ended.v1"];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base44-preview/platform",
|
|
3
|
-
"version": "0.3.0-pr.
|
|
4
|
-
"description": "Base44 Platform SDK for white-label platforms: a browser client for
|
|
3
|
+
"version": "0.3.0-pr.341.adc3ff5",
|
|
4
|
+
"description": "Base44 Platform SDK for white-label platforms: a browser client for watching the builder and a server entrypoint for webhooks",
|
|
5
5
|
"main": "dist/client/index.js",
|
|
6
6
|
"types": "dist/client/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|