@base44-preview/platform 0.3.0-pr.341.adc3ff5 → 0.4.0-pr.343.fe53e54
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 +4 -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
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 live AI chat
|
|
11
|
+
contract. A partner's browser watches the AI 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
|
|
21
|
+
const chat = client.chat.init({
|
|
22
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/chat-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 = chat.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 chat.connect();
|
|
36
36
|
// On view teardown:
|
|
37
37
|
subscription.unsubscribe();
|
|
38
|
-
|
|
38
|
+
chat.close();
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
## Receiving webhooks (server)
|
|
@@ -97,7 +97,7 @@ Delivery is at least once with no ordering guarantee: deduplicate on `event.id`,
|
|
|
97
97
|
|
|
98
98
|
## Sessions
|
|
99
99
|
|
|
100
|
-
`/api/
|
|
100
|
+
`/api/chat-socket-session` is your backend's route, not an SDK endpoint. It opens a
|
|
101
101
|
socket session through `POST /api/v1/socket-sessions` with `{ app_ids }`, and returns the
|
|
102
102
|
response body to the browser. It authenticates as `Authorization: Bearer` with either a
|
|
103
103
|
personal access token, which can watch the apps its owner can edit in its workspace, or a
|
|
@@ -108,7 +108,7 @@ backend adds or removes apps with `PUT`/`DELETE /api/v1/socket-sessions/{session
|
|
|
108
108
|
|
|
109
109
|
A session lasts one hour and is never extended. The token goes exclusively in
|
|
110
110
|
CONNECT `auth.session_token`, never a URL, and the SDK keeps it in memory only. It
|
|
111
|
-
is reused across automatic reconnects. `getSession` is called when a
|
|
111
|
+
is reused across automatic reconnects. `getSession` is called when a chat
|
|
112
112
|
session first connects, and again only when the server rejects the cached token or
|
|
113
113
|
expires the session; the SDK then reconnects once with the new session. If the new
|
|
114
114
|
session has a different `socket_url` or `socket_path`, the SDK closes the old socket,
|
|
@@ -124,26 +124,26 @@ older one, which stops with `session_replaced`. Open one session per page.
|
|
|
124
124
|
|
|
125
125
|
`createPlatformClient()` creates a lightweight module container: no Socket.IO
|
|
126
126
|
instance, timers, session request or network activity. It takes no options. Its
|
|
127
|
-
`
|
|
127
|
+
`chat` module follows the server SDK's module-factory pattern.
|
|
128
128
|
|
|
129
|
-
`client.
|
|
130
|
-
`
|
|
129
|
+
`client.chat.init({ getSession, onError })` synchronously creates an independent
|
|
130
|
+
`ChatSession` without connecting or creating a socket. Repeated calls create separate sessions, each owning its own
|
|
131
131
|
socket, listeners, subscriptions and cleanup. Close the returned session when its
|
|
132
132
|
view is disposed; the root client and other sessions remain usable.
|
|
133
133
|
|
|
134
|
-
`
|
|
134
|
+
`chat.connect()` fetches the first session, creates the socket at its address and
|
|
135
135
|
resolves on CONNECT, before any snapshot. The socket uses the default namespace on the
|
|
136
136
|
session's `socket_path`, WebSocket only, with a dedicated manager.
|
|
137
137
|
Transport reconnection uses five attempts, starting at one second and capped at ten
|
|
138
138
|
seconds with jitter; each attempt has a twenty-second timeout. A temporary server
|
|
139
139
|
refusal is retried the same way. After exhaustion, a refusal or `session_replaced`,
|
|
140
|
-
fix the cause and call `
|
|
140
|
+
fix the cause and call `chat.connect()`.
|
|
141
141
|
|
|
142
|
-
`
|
|
142
|
+
`chat.subscribe(appId, options)` returns a handle with `appId`, `active` and
|
|
143
143
|
idempotent `unsubscribe()`. App IDs are 24 lowercase hexadecimal characters. One
|
|
144
|
-
subscription per app and at most eight subscriptions are allowed per
|
|
145
|
-
Subscriptions can be created before connecting. `
|
|
146
|
-
session; call `client.
|
|
144
|
+
subscription per app and at most eight subscriptions are allowed per session.
|
|
145
|
+
Subscriptions can be created before connecting. `chat.close()` is terminal for that
|
|
146
|
+
session; call `client.chat.init(...)` again to start another.
|
|
147
147
|
|
|
148
148
|
## Snapshots and events
|
|
149
149
|
|
|
@@ -162,15 +162,15 @@ their exceptions are isolated so they cannot interrupt another app's delivery.
|
|
|
162
162
|
|
|
163
163
|
## Public shapes
|
|
164
164
|
|
|
165
|
-
- `PlatformClient` (`client.types.ts`): the `
|
|
166
|
-
- `
|
|
167
|
-
- `
|
|
165
|
+
- `PlatformClient` (`client.types.ts`): the `chat` module.
|
|
166
|
+
- `ChatModule` (`modules/chat.types.ts`): lazy `init(options)` factory.
|
|
167
|
+
- `ChatInitOptions`: `getSession` and the connection-level `onError` observer.
|
|
168
168
|
- `SocketSession`: the `session_token`, `socket_url` and `socket_path` that `getSession` returns.
|
|
169
|
-
- `
|
|
169
|
+
- `ChatSession`: `connect()`, `subscribe(appId, options)`, `close()`.
|
|
170
170
|
- `SubscriptionOptions`: required `onSnapshot`, `onEvent` and `onError`.
|
|
171
171
|
- `PlatformSubscription`: read-only `appId`, `active`, and `unsubscribe()`.
|
|
172
172
|
- `PlatformEvent`, `PlatformEventMap`, `PlatformSnapshot`, `ToolCall`, `GuardApproval`
|
|
173
|
-
(`modules/
|
|
173
|
+
(`modules/chat.events.types.ts`), derived from the generated event types.
|
|
174
174
|
- Error codes in `errors.types.ts`.
|
|
175
175
|
|
|
176
176
|
`PlatformEvent` is a **discriminated union**: switch on `event.type` to narrow
|
|
@@ -187,7 +187,7 @@ redaction of generated prose or user content.
|
|
|
187
187
|
## Event types
|
|
188
188
|
|
|
189
189
|
The socket protocol is defined by the service's AsyncAPI document, committed as
|
|
190
|
-
`asyncapi.json`. `src/client/modules/
|
|
190
|
+
`asyncapi.json`. `src/client/modules/chat.events.generated.ts` is generated from it with
|
|
191
191
|
`json-schema-to-typescript`: one type per schema, named after the backend model
|
|
192
192
|
(`Message`, `StatusObject`, `QueueState`, one `*Call` per tool, one `*Approval` per
|
|
193
193
|
guard), plus `ServerEventMap` and `ClientMessageMap`. Never edit it by hand.
|
|
@@ -230,16 +230,16 @@ exceptions, payloads and credentials are never attached.
|
|
|
230
230
|
| `delivery_overflow` | 1,000 deliveries queued for the app; subscribe again for a fresh snapshot. |
|
|
231
231
|
| `protocol_error` | Invalid routing or envelope. Stop and investigate. |
|
|
232
232
|
| `handler_failed` | An application callback failed; fix it and subscribe again. |
|
|
233
|
-
| `client_closed` | The
|
|
233
|
+
| `client_closed` | The session was explicitly closed; initialize another session. |
|
|
234
234
|
|
|
235
235
|
No SDK dependency, package version or lockfile changes are required. Socket.IO
|
|
236
236
|
remains the existing SDK dependency. Chat commands and HTTP APIs are outside this entry point.
|
|
237
237
|
|
|
238
238
|
## React
|
|
239
239
|
|
|
240
|
-
`@base44/platform/react` adds one hook, `useBase44Chat`, that runs
|
|
240
|
+
`@base44/platform/react` adds one hook, `useBase44Chat`, 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
|
-
made for rendering, binds every question the
|
|
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
|
|
@@ -259,5 +259,5 @@ call with your credentials, so the browser never holds a key. The hook returns `
|
|
|
259
259
|
the first, and the chat watches it while `appId` is `null`. A sent prompt shows at once as a
|
|
260
260
|
`pending` item until Base44's own message arrives; a prompt sent mid-build waits in Base44's
|
|
261
261
|
queue meanwhile. A question is a union on `kind` (`choice`, `secrets`, `approval`) and carries only the
|
|
262
|
-
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 app editor, only the
|
|
263
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
|
@@ -2,12 +2,16 @@ import type { PlatformClient } from "./client.types.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Creates a platform client.
|
|
4
4
|
*
|
|
5
|
-
* This is the entry point of the Platform SDK
|
|
6
|
-
* access to the platform's modules, such as
|
|
7
|
-
* It takes no options and
|
|
8
|
-
*
|
|
5
|
+
* This is the entry point of the Platform SDK in the browser. Import it from `@base44/platform`.
|
|
6
|
+
* The client gives your white-label app editor access to the platform's modules, such as
|
|
7
|
+
* [`chat`](/developers/references/platform-sdk/docs/interfaces/chat). It takes no options and
|
|
8
|
+
* doesn't connect to anything. Each call to
|
|
9
|
+
* [`client.chat.init()`](/developers/references/platform-sdk/docs/interfaces/chat#init) gets a
|
|
10
|
+
* socket session from the `getSession()` function you pass in. On your backend, use
|
|
11
|
+
* [`createPlatformServer()`](/developers/references/platform-sdk/docs/functions/createPlatformServer)
|
|
12
|
+
* from `@base44/platform/server`.
|
|
9
13
|
*
|
|
10
|
-
* @returns A platform client
|
|
14
|
+
* @returns A new platform client.
|
|
11
15
|
*
|
|
12
16
|
* @example
|
|
13
17
|
* ```typescript
|
|
@@ -17,14 +21,14 @@ import type { PlatformClient } from "./client.types.js";
|
|
|
17
21
|
* const client = createPlatformClient();
|
|
18
22
|
*
|
|
19
23
|
* // Use the client to follow the AI chat in an app
|
|
20
|
-
* const
|
|
24
|
+
* const chat = client.chat.init({
|
|
21
25
|
* async getSession() {
|
|
22
|
-
* const response = await fetch('/api/
|
|
26
|
+
* const response = await fetch('/api/chat-socket-session', { method: 'POST' });
|
|
23
27
|
* return response.json();
|
|
24
28
|
* },
|
|
25
|
-
* onError: (error) => console.error(error.code),
|
|
29
|
+
* onError: (error) => console.error('Live updates error', error.code),
|
|
26
30
|
* });
|
|
27
|
-
* await
|
|
31
|
+
* await chat.connect();
|
|
28
32
|
* ```
|
|
29
33
|
*/
|
|
30
34
|
export declare function createPlatformClient(): PlatformClient;
|
package/dist/client/client.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createChat } from "./modules/chat.js";
|
|
2
2
|
/**
|
|
3
3
|
* Creates a platform client.
|
|
4
4
|
*
|
|
5
|
-
* This is the entry point of the Platform SDK
|
|
6
|
-
* access to the platform's modules, such as
|
|
7
|
-
* It takes no options and
|
|
8
|
-
*
|
|
5
|
+
* This is the entry point of the Platform SDK in the browser. Import it from `@base44/platform`.
|
|
6
|
+
* The client gives your white-label app editor access to the platform's modules, such as
|
|
7
|
+
* [`chat`](/developers/references/platform-sdk/docs/interfaces/chat). It takes no options and
|
|
8
|
+
* doesn't connect to anything. Each call to
|
|
9
|
+
* [`client.chat.init()`](/developers/references/platform-sdk/docs/interfaces/chat#init) gets a
|
|
10
|
+
* socket session from the `getSession()` function you pass in. On your backend, use
|
|
11
|
+
* [`createPlatformServer()`](/developers/references/platform-sdk/docs/functions/createPlatformServer)
|
|
12
|
+
* from `@base44/platform/server`.
|
|
9
13
|
*
|
|
10
|
-
* @returns A platform client
|
|
14
|
+
* @returns A new platform client.
|
|
11
15
|
*
|
|
12
16
|
* @example
|
|
13
17
|
* ```typescript
|
|
@@ -17,16 +21,16 @@ import { createBuilder } from "./modules/builder.js";
|
|
|
17
21
|
* const client = createPlatformClient();
|
|
18
22
|
*
|
|
19
23
|
* // Use the client to follow the AI chat in an app
|
|
20
|
-
* const
|
|
24
|
+
* const chat = client.chat.init({
|
|
21
25
|
* async getSession() {
|
|
22
|
-
* const response = await fetch('/api/
|
|
26
|
+
* const response = await fetch('/api/chat-socket-session', { method: 'POST' });
|
|
23
27
|
* return response.json();
|
|
24
28
|
* },
|
|
25
|
-
* onError: (error) => console.error(error.code),
|
|
29
|
+
* onError: (error) => console.error('Live updates error', error.code),
|
|
26
30
|
* });
|
|
27
|
-
* await
|
|
31
|
+
* await chat.connect();
|
|
28
32
|
* ```
|
|
29
33
|
*/
|
|
30
34
|
export function createPlatformClient() {
|
|
31
|
-
return Object.freeze({
|
|
35
|
+
return Object.freeze({ chat: Object.freeze(createChat()) });
|
|
32
36
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ChatModule } from "./modules/chat.types.js";
|
|
2
2
|
/**
|
|
3
|
-
* The platform client.
|
|
4
|
-
*
|
|
5
|
-
* Provides access to the platform's modules.
|
|
3
|
+
* The platform client, with one property for each module.
|
|
6
4
|
*/
|
|
7
5
|
export interface PlatformClient {
|
|
8
|
-
/** [
|
|
9
|
-
readonly
|
|
6
|
+
/** [Chat module](/developers/references/platform-sdk/docs/interfaces/chat) for following the AI chat of your users' apps. */
|
|
7
|
+
readonly chat: ChatModule;
|
|
10
8
|
}
|
package/dist/client/errors.d.ts
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
import type { PlatformSocketErrorCode } from "./errors.types.js";
|
|
2
2
|
/**
|
|
3
|
-
* The error the SDK reports when something goes wrong
|
|
3
|
+
* The error the SDK reports when something goes wrong with live updates.
|
|
4
4
|
*
|
|
5
|
-
* You don't create
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* You don't create these errors. The SDK passes them to your `onError()` callbacks, rejects
|
|
6
|
+
* `connect()` with them, and throws them from `subscribe()`. Check `code` to see what happened,
|
|
7
|
+
* then look the code up below:
|
|
8
|
+
* - Session error codes go to the `onError()` you pass to `init()`. The whole
|
|
8
9
|
* session is affected, and `appId` isn't set.
|
|
9
|
-
* -
|
|
10
|
-
* and `appId` says which one.
|
|
10
|
+
* - App error codes go to the subscription's `onError()`. Only that app is
|
|
11
|
+
* affected, and `appId` says which one.
|
|
11
12
|
*
|
|
12
|
-
*
|
|
13
|
+
* These errors never carry the session token, a callback's exception, or the server's exception
|
|
14
|
+
* text.
|
|
13
15
|
*
|
|
14
16
|
* @example
|
|
15
17
|
* ```typescript
|
|
16
18
|
* // Handle session and app errors
|
|
17
|
-
* const
|
|
19
|
+
* const chat = client.chat.init({
|
|
20
|
+
* async getSession() {
|
|
21
|
+
* const response = await fetch('/api/chat-socket-session', { method: 'POST' });
|
|
22
|
+
* return response.json();
|
|
23
|
+
* },
|
|
18
24
|
* // Session error codes: the whole session is affected
|
|
19
25
|
* onError(error) {
|
|
20
26
|
* if (error.code === 'session_revoked') showSignedOut();
|
|
21
27
|
* },
|
|
22
28
|
* });
|
|
23
29
|
*
|
|
24
|
-
*
|
|
30
|
+
* chat.subscribe(appId, {
|
|
25
31
|
* onSnapshot: renderChat,
|
|
26
32
|
* onEvent: applyEvent,
|
|
27
33
|
* // App error codes: only this app is affected, and error.appId says which
|
|
@@ -32,7 +38,7 @@ import type { PlatformSocketErrorCode } from "./errors.types.js";
|
|
|
32
38
|
* ```
|
|
33
39
|
*/
|
|
34
40
|
export declare class PlatformSocketError extends Error {
|
|
35
|
-
/** What happened. One of the
|
|
41
|
+
/** What happened. One of the session error codes or app error codes. */
|
|
36
42
|
readonly code: PlatformSocketErrorCode;
|
|
37
43
|
/** ID of the app the error is about. Set for app error codes, and not set for session error codes. */
|
|
38
44
|
readonly appId?: string;
|
package/dist/client/errors.js
CHANGED
|
@@ -1,26 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The error the SDK reports when something goes wrong
|
|
2
|
+
* The error the SDK reports when something goes wrong with live updates.
|
|
3
3
|
*
|
|
4
|
-
* You don't create
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* You don't create these errors. The SDK passes them to your `onError()` callbacks, rejects
|
|
5
|
+
* `connect()` with them, and throws them from `subscribe()`. Check `code` to see what happened,
|
|
6
|
+
* then look the code up below:
|
|
7
|
+
* - Session error codes go to the `onError()` you pass to `init()`. The whole
|
|
7
8
|
* session is affected, and `appId` isn't set.
|
|
8
|
-
* -
|
|
9
|
-
* and `appId` says which one.
|
|
9
|
+
* - App error codes go to the subscription's `onError()`. Only that app is
|
|
10
|
+
* affected, and `appId` says which one.
|
|
10
11
|
*
|
|
11
|
-
*
|
|
12
|
+
* These errors never carry the session token, a callback's exception, or the server's exception
|
|
13
|
+
* text.
|
|
12
14
|
*
|
|
13
15
|
* @example
|
|
14
16
|
* ```typescript
|
|
15
17
|
* // Handle session and app errors
|
|
16
|
-
* const
|
|
18
|
+
* const chat = client.chat.init({
|
|
19
|
+
* async getSession() {
|
|
20
|
+
* const response = await fetch('/api/chat-socket-session', { method: 'POST' });
|
|
21
|
+
* return response.json();
|
|
22
|
+
* },
|
|
17
23
|
* // Session error codes: the whole session is affected
|
|
18
24
|
* onError(error) {
|
|
19
25
|
* if (error.code === 'session_revoked') showSignedOut();
|
|
20
26
|
* },
|
|
21
27
|
* });
|
|
22
28
|
*
|
|
23
|
-
*
|
|
29
|
+
* chat.subscribe(appId, {
|
|
24
30
|
* onSnapshot: renderChat,
|
|
25
31
|
* onEvent: applyEvent,
|
|
26
32
|
* // App error codes: only this app is affected, and error.appId says which
|
|
@@ -1,30 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Codes of errors that affect the whole session. They go to the `onError` you pass to `init()`,
|
|
3
|
-
* `connect()` rejects with them.
|
|
2
|
+
* Codes of errors that affect the whole session. They go to the `onError()` you pass to `init()`,
|
|
3
|
+
* and `connect()` rejects with them. A retryable error is one where the same call can succeed again
|
|
4
|
+
* without changing anything.
|
|
4
5
|
*/
|
|
5
6
|
export type SessionErrorCode =
|
|
6
7
|
/**
|
|
7
|
-
* `getSession` threw, took longer than 20 seconds, or returned a session without a
|
|
8
|
-
* `session_token`, `socket_url`
|
|
8
|
+
* The `getSession()` callback threw, took longer than 20 seconds, or returned a session without a
|
|
9
|
+
* valid `session_token`, a `socket_url` that is an HTTP or HTTPS origin, or a `socket_path` that is
|
|
10
|
+
* an absolute path.
|
|
9
11
|
*
|
|
10
|
-
* Check the endpoint that opens sessions, then call `connect()` again. Retryable
|
|
11
|
-
* invalid
|
|
12
|
+
* Check the endpoint that opens sessions, then call `connect()` again. Retryable. If a field is
|
|
13
|
+
* invalid, fix it on your server first.
|
|
12
14
|
*/
|
|
13
15
|
"session_unavailable"
|
|
14
16
|
/**
|
|
15
|
-
* Base44 refused the session even with a fresh token
|
|
17
|
+
* Base44 refused the session even with a fresh token. Either the token is invalid, or live updates
|
|
18
|
+
* aren't turned on for the workspace.
|
|
16
19
|
*
|
|
17
20
|
* Check that your server opens a new session on every call. Not retryable.
|
|
18
21
|
*/
|
|
19
22
|
| "connection_denied"
|
|
20
23
|
/**
|
|
21
|
-
* The socket couldn't connect after five retries, or the server closed
|
|
24
|
+
* The socket couldn't connect after five retries, or the server closed the connection.
|
|
22
25
|
*
|
|
23
26
|
* Call `connect()` again, for example when the tab next gets focus. Retryable.
|
|
24
27
|
*/
|
|
25
28
|
| "connection_failed"
|
|
26
29
|
/**
|
|
27
|
-
* Your server or an admin ended the session, or
|
|
30
|
+
* Your server or an admin ended the session, or the workspace API key that opened the session lost
|
|
31
|
+
* access.
|
|
28
32
|
*
|
|
29
33
|
* Open a new session from your server if the page should still follow apps. Not retryable.
|
|
30
34
|
*/
|
|
@@ -32,11 +36,12 @@ export type SessionErrorCode =
|
|
|
32
36
|
/**
|
|
33
37
|
* Another socket connected with the same session token.
|
|
34
38
|
*
|
|
35
|
-
* Use one session per tab. Don't reconnect automatically
|
|
39
|
+
* Use one session per tab. Don't reconnect automatically. Call `connect()` only to take the
|
|
40
|
+
* session back on purpose. Not retryable.
|
|
36
41
|
*/
|
|
37
42
|
| "session_replaced"
|
|
38
43
|
/**
|
|
39
|
-
* A session
|
|
44
|
+
* A message about the whole session didn't match the protocol.
|
|
40
45
|
*
|
|
41
46
|
* Update the SDK, then call `connect()` again. Not retryable.
|
|
42
47
|
*/
|
|
@@ -48,26 +53,27 @@ export type SessionErrorCode =
|
|
|
48
53
|
*/
|
|
49
54
|
| "client_closed";
|
|
50
55
|
/**
|
|
51
|
-
* Codes of errors for
|
|
52
|
-
* `subscription_limit`. Every one ends the subscription except `snapshot_unavailable`.
|
|
56
|
+
* Codes of errors for a single app. They go to the subscription's `onError()`, and `subscribe()`
|
|
57
|
+
* throws `subscription_limit`. Every one ends the subscription except `snapshot_unavailable`.
|
|
53
58
|
*/
|
|
54
59
|
export type AppErrorCode =
|
|
55
60
|
/**
|
|
56
|
-
* The
|
|
61
|
+
* The session doesn't have access to the app, or the connection subscribed to apps too often.
|
|
57
62
|
*
|
|
58
63
|
* Add the app to the session from your server, then subscribe again. Not retryable.
|
|
59
64
|
*/
|
|
60
65
|
"access_denied"
|
|
61
66
|
/**
|
|
62
|
-
* The app
|
|
67
|
+
* The session lost access to the app. Your server removed the app from the session, or the app
|
|
68
|
+
* left the workspace.
|
|
63
69
|
*
|
|
64
70
|
* Stop showing the app's live updates. Not retryable.
|
|
65
71
|
*/
|
|
66
72
|
| "access_revoked"
|
|
67
73
|
/**
|
|
68
|
-
* The subscription is active but its snapshot failed. Events keep arriving.
|
|
74
|
+
* The subscription is active, but its snapshot failed. Events keep arriving.
|
|
69
75
|
*
|
|
70
|
-
* Load the app's messages
|
|
76
|
+
* Load the app's messages from the Apps API instead.
|
|
71
77
|
*/
|
|
72
78
|
| "snapshot_unavailable"
|
|
73
79
|
/**
|
|
@@ -77,13 +83,13 @@ export type AppErrorCode =
|
|
|
77
83
|
*/
|
|
78
84
|
| "subscription_limit"
|
|
79
85
|
/**
|
|
80
|
-
* More than 1,000
|
|
86
|
+
* More than 1,000 snapshots and events were waiting for your callbacks.
|
|
81
87
|
*
|
|
82
88
|
* Make the callbacks faster, then subscribe again for a fresh snapshot. Retryable.
|
|
83
89
|
*/
|
|
84
90
|
| "delivery_overflow"
|
|
85
91
|
/**
|
|
86
|
-
* Your `onSnapshot` or `onEvent` callback threw or rejected.
|
|
92
|
+
* Your `onSnapshot()` or `onEvent()` callback threw or rejected.
|
|
87
93
|
*
|
|
88
94
|
* Fix the callback, then subscribe again. Not retryable.
|
|
89
95
|
*/
|
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 { ChatModule, ChatInitOptions, ChatSession, PlatformSubscription, SocketSession, SubscriptionOptions } from "./modules/chat.types.js";
|
|
7
|
+
export type { AppEvent, GuardApproval, PlatformEvent, PlatformEventMap, PlatformSnapshot, ToolCall, UnknownEvent } from "./modules/chat.events.types.js";
|
|
8
|
+
export type * from "./modules/chat.events.generated.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PlatformEvent, PlatformSnapshot } from "./
|
|
2
|
-
import type { SocketSession } from "./
|
|
1
|
+
import type { PlatformEvent, PlatformSnapshot } from "./chat.events.types.js";
|
|
2
|
+
import type { SocketSession } from "./chat.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 "./chat.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 { ChatInitOptions, ChatSession, PlatformSubscription, SubscriptionOptions } from "./chat.types.js";
|
|
2
2
|
/** @internal */
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class ChatSocket implements ChatSession {
|
|
4
4
|
private socket?;
|
|
5
5
|
private address?;
|
|
6
6
|
private readonly subscriptions;
|
|
@@ -16,7 +16,7 @@ export declare class BuilderSocket implements BuilderSession {
|
|
|
16
16
|
private connecting?;
|
|
17
17
|
private resolveConnect?;
|
|
18
18
|
private rejectConnect?;
|
|
19
|
-
constructor(options:
|
|
19
|
+
constructor(options: ChatInitOptions);
|
|
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 "./chat-protocol.js";
|
|
4
|
+
import { notify, Subscription } from "./chat-subscription.js";
|
|
5
5
|
const MAX_DENIAL_RETRIES = 5;
|
|
6
6
|
/** @internal */
|
|
7
|
-
export class
|
|
7
|
+
export class ChatSocket {
|
|
8
8
|
constructor(options) {
|
|
9
9
|
this.subscriptions = new Map();
|
|
10
10
|
this.closed = false;
|
|
@@ -48,7 +48,7 @@ export class BuilderSocket {
|
|
|
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 chat 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 "./chat.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 "./chat.types.js";
|
|
5
5
|
/** @internal */
|
|
6
6
|
export declare function notify(callback: (error: PlatformSocketError) => void, error: PlatformSocketError): void;
|
|
7
7
|
/** @internal */
|