@base44-preview/platform 0.3.0-pr.341.adc3ff5 → 0.4.0-pr.344.26b3201

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.
Files changed (42) hide show
  1. package/README.md +33 -31
  2. package/dist/client/client.d.ts +13 -9
  3. package/dist/client/client.js +15 -11
  4. package/dist/client/client.types.d.ts +4 -6
  5. package/dist/client/errors.d.ts +16 -10
  6. package/dist/client/errors.js +15 -9
  7. package/dist/client/errors.types.d.ts +25 -19
  8. package/dist/client/index.d.ts +3 -3
  9. package/dist/client/modules/{builder-protocol.d.ts → chat-protocol.d.ts} +2 -2
  10. package/dist/client/modules/{builder-protocol.js → chat-protocol.js} +1 -1
  11. package/dist/client/modules/{builder-socket.d.ts → chat-socket.d.ts} +3 -3
  12. package/dist/client/modules/{builder-socket.js → chat-socket.js} +4 -4
  13. package/dist/client/modules/{builder-subscription.d.ts → chat-subscription.d.ts} +2 -2
  14. package/dist/client/modules/chat.d.ts +3 -0
  15. package/dist/client/modules/{builder.events.types.d.ts → chat.events.types.d.ts} +35 -32
  16. package/dist/client/modules/chat.js +7 -0
  17. package/dist/client/modules/chat.types.d.ts +215 -0
  18. package/dist/react/chat-items.d.ts +4 -4
  19. package/dist/react/chat-items.js +3 -3
  20. package/dist/react/chat.types.d.ts +22 -20
  21. package/dist/react/index.d.ts +3 -3
  22. package/dist/react/index.js +1 -1
  23. package/dist/react/{useBase44Chat.d.ts → useChat.d.ts} +7 -7
  24. package/dist/react/{useBase44Chat.js → useChat.js} +10 -10
  25. package/dist/server/errors.d.ts +9 -9
  26. package/dist/server/errors.js +7 -7
  27. package/dist/server/errors.types.d.ts +3 -3
  28. package/dist/server/modules/webhooks.events.generated.d.ts +12 -12
  29. package/dist/server/modules/webhooks.events.generated.js +1 -1
  30. package/dist/server/modules/webhooks.types.d.ts +36 -31
  31. package/dist/server/server.d.ts +1 -1
  32. package/dist/server/server.js +1 -1
  33. package/dist/server/server.types.d.ts +2 -4
  34. package/package.json +2 -2
  35. package/dist/client/modules/builder.d.ts +0 -3
  36. package/dist/client/modules/builder.js +0 -7
  37. package/dist/client/modules/builder.types.d.ts +0 -193
  38. /package/dist/client/modules/{builder-subscription.js → chat-subscription.js} +0 -0
  39. /package/dist/client/modules/{builder.events.generated.d.ts → chat.events.generated.d.ts} +0 -0
  40. /package/dist/client/modules/{builder.events.generated.js → chat.events.generated.js} +0 -0
  41. /package/dist/client/modules/{builder.events.types.js → chat.events.types.js} +0 -0
  42. /package/dist/client/modules/{builder.types.js → chat.types.js} +0 -0
@@ -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 it. The [`verifyEvent()`](/developers/references/platform-sdk/docs/interfaces/webhooks#verifyevent) method rejects with
6
- * it, and [`createHandler()`](/developers/references/platform-sdk/docs/interfaces/webhooks#createhandler) answers it with a 400 and passes it
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
- * The error never carries the request body or its signature.
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 [verification error codes](#webhookverificationerrorcode). */
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 it. The [`verifyEvent()`](/developers/references/platform-sdk/docs/interfaces/webhooks#verifyevent) method rejects with
34
- * it, and [`createHandler()`](/developers/references/platform-sdk/docs/interfaces/webhooks#createhandler) answers it with a 500 and passes it
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 [configuration error codes](#webhookconfigurationerrorcode). */
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);
@@ -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 it. The [`verifyEvent()`](/developers/references/platform-sdk/docs/interfaces/webhooks#verifyevent) method rejects with
5
- * it, and [`createHandler()`](/developers/references/platform-sdk/docs/interfaces/webhooks#createhandler) answers it with a 400 and passes it
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
- * The error never carries the request body or its signature.
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 it. The [`verifyEvent()`](/developers/references/platform-sdk/docs/interfaces/webhooks#verifyevent) method rejects with
35
- * it, and [`createHandler()`](/developers/references/platform-sdk/docs/interfaces/webhooks#createhandler) answers it with a 500 and passes it
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` or `webhook-signature` headers.
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 is more than `toleranceSeconds` (300 by default) away from your server's clock, or isn't a number.
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 it succeeds once you fix the problem.
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 builder picks the message up, not when it is received: a
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 BuilderTurnStartedV1Data {
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 builder started working on the message (UTC).
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 `builder.turn_ended.v1`. The builder finished responding to a message.
175
+ * The `data` object of `chat.turn_ended.v1`. The AI finished responding to a message.
176
176
  */
177
- export interface BuilderTurnEndedV1Data {
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 builder started working on the message (UTC).
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 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.
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 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;
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", "builder.turn_started.v1", "builder.turn_ended.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", "builder.turn_started.v1", "builder.turn_ended.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"];
@@ -47,9 +47,9 @@ export interface UnknownWebhookEvent extends Omit<CloudEvent<string, Record<stri
47
47
  * A verified webhook event.
48
48
  *
49
49
  * Check `type` to narrow `data` to that event's payload. An event added to Base44 after this version
50
- * of the SDK arrives with `type: "unknown"`, its type in `name` and an unchecked `data`, so check a
51
- * field before using it. After you upgrade, it arrives under its own `type`. Answer it with a 2xx
52
- * too: Base44 retries any answer that isn't 2xx.
50
+ * of the SDK arrives with `type: "unknown"`, its type in `name`, and an unchecked `data`, so check a
51
+ * field before using it. After you upgrade, the event arrives under its own `type`. Answer it with a
52
+ * 2xx too, because Base44 retries any answer that isn't 2xx.
53
53
  *
54
54
  * @example
55
55
  * ```typescript
@@ -83,7 +83,7 @@ export interface VerifyEventOptions {
83
83
  /** How far, in seconds, a delivery's timestamp can be from your server's clock. Defaults to `300`. */
84
84
  toleranceSeconds?: number;
85
85
  }
86
- /** An event your callbacks receive. Every event except the `webhook.test.v1` activation probe, which the handler answers itself. */
86
+ /** An event your callbacks receive. Every event except the `webhook.test.v1` test event, which `createHandler()` answers itself. */
87
87
  export type DeliveredWebhookEvent = Exclude<WebhookEvent, CloudEvent<"webhook.test.v1", WebhookTestV1Data>>;
88
88
  /**
89
89
  * Handlers keyed by event type. Each handler receives the event narrowed to its type. The `unknown`
@@ -101,7 +101,7 @@ export interface CreateHandlerOptions extends VerifyEventOptions {
101
101
  /** Called for every verified event, before its handler in `on`. */
102
102
  onEvent?: (event: DeliveredWebhookEvent) => unknown;
103
103
  /**
104
- * Called after `onEvent` and the event's handler finish without throwing.
104
+ * Called after `onEvent()` and the event's handler finish without throwing.
105
105
  *
106
106
  * Return a `Response` to replace the default empty 204.
107
107
  */
@@ -110,22 +110,23 @@ export interface CreateHandlerOptions extends VerifyEventOptions {
110
110
  * Called when a delivery fails.
111
111
  *
112
112
  * The handler answers a `WebhookVerificationError` with a 400, and a `WebhookConfigurationError`, a
113
- * failed body read or anything a callback throws with a 500. Base44 retries either way, because it
114
- * retries any answer that isn't 2xx. The status only shows in its delivery log whether the delivery
115
- * or your side failed. The `event` argument is set when the delivery verified and a callback failed.
113
+ * failed body read, or anything a callback throws with a 500. Base44 retries both, because it retries
114
+ * every answer that isn't 2xx. The two codes only differ in Base44's delivery log, where a 400
115
+ * points to the delivery and a 500 points to your server. The `event` argument is set when the
116
+ * delivery verified and a callback failed.
116
117
  * Return a `Response` to replace the default answer.
117
118
  */
118
119
  onError?: (error: unknown, event?: DeliveredWebhookEvent) => Response | void | Promise<Response | void>;
119
120
  }
120
121
  /**
121
- * Webhooks module for receiving the events Base44 sends to your server.
122
+ * Webhooks module for receiving and verifying Base44's webhooks.
122
123
  *
123
- * Base44 sends a signed event to your endpoint when something happens in your workspace:
124
- * - An app is created, published, unpublished, moved to trash or restored.
125
- * - Base44 tests a new endpoint before activating it.
124
+ * Base44 sends a signed event to your endpoint:
125
+ * - When an app is created, published, unpublished, moved to trash, or restored.
126
+ * - When you add the endpoint, to test it.
126
127
  *
127
- * The module verifies each delivery's signature with your workspace's public keys, and gives you
128
- * the event with its payload typed. It runs on Node.js 20 and later and on edge runtimes, and makes
128
+ * The module verifies each delivery's signature with your workspace's public keys and returns the
129
+ * event with a typed payload. It runs on Node.js 20 and later and on edge runtimes, and makes
129
130
  * no network requests.
130
131
  *
131
132
  * Use {@linkcode createHandler | createHandler()} for a ready-made route handler, or
@@ -139,15 +140,17 @@ export interface WebhooksModule {
139
140
  * Pass the request body exactly as received, before any JSON parsing, because the signature covers
140
141
  * its exact bytes. Nothing is parsed until the signature checks out.
141
142
  *
142
- * To activate a new endpoint, answer the `webhook.test.v1` event with
143
- * `{ "challenge": event.data.challenge }` within 5 seconds. Answer every other event with a 2xx.
143
+ * Unlike {@linkcode createHandler | createHandler()}, `verifyEvent()` doesn't answer the request for
144
+ * you. When you add an endpoint, Base44 sends it a `webhook.test.v1` event and activates the endpoint
145
+ * only if you answer with `{ "challenge": event.data.challenge }` within 5 seconds. Answer every
146
+ * other event with a 2xx, or Base44 retries it.
144
147
  *
145
148
  * @param body - The raw request body, as text or bytes.
146
149
  * @param headers - The request headers.
147
150
  * @param options - Verification options, including your public keys.
148
- * @returns Promise resolving to the verified event.
149
- * @throws {WebhookVerificationError} When the delivery can't be trusted. Answer with a 400.
150
- * @throws {WebhookConfigurationError} When the public keys are missing or malformed, or the runtime can't use them. Answer with a 500.
151
+ * @returns A promise that resolves to the verified event.
152
+ * @throws {WebhookVerificationError} The promise rejects with a `WebhookVerificationError` when the delivery can't be trusted. Answer with a 400.
153
+ * @throws {WebhookConfigurationError} The promise rejects with a `WebhookConfigurationError` when the public keys are missing or malformed, or the runtime can't use them. Answer with a 500.
151
154
  *
152
155
  * @example
153
156
  * ```typescript
@@ -166,6 +169,7 @@ export interface WebhooksModule {
166
169
  *
167
170
  * switch (event.type) {
168
171
  * case 'webhook.test.v1':
172
+ * // Answer the test event so Base44 activates the endpoint
169
173
  * return Response.json({ challenge: event.data.challenge });
170
174
  * case 'app.deleted.v1':
171
175
  * await removeApp(event.data.app_id);
@@ -179,24 +183,25 @@ export interface WebhooksModule {
179
183
  /**
180
184
  * Creates a route handler that verifies deliveries and calls your handlers.
181
185
  *
182
- * The handler takes a fetch `Request` and returns a `Response`, so it works as a Next.js route
183
- * handler and in Hono, Cloudflare Workers, Deno and Bun. For each request it reads the raw body,
184
- * verifies it, answers the activation probe itself, and then calls `onEvent`, the event's handler in
185
- * `on`, and `onSuccess`, in that order.
186
+ * The returned function takes a standard Fetch API `Request` and returns a `Response`, so you can
187
+ * use it with any framework built on the Fetch API, such as Next.js route handlers, Hono,
188
+ * Cloudflare Workers, Deno, and Bun. For each request, it reads the raw body and
189
+ * verifies it. It answers the test event itself, and for every other event it calls `onEvent()`,
190
+ * then the event's handler in `on`, then `onSuccess()`.
186
191
  *
187
192
  * It answers with:
188
- * - 204 when the event was handled, including events with no handler and unknown events.
189
- * - 400 when the delivery doesn't verify, with the error code in the body.
190
- * - 500 when the public keys are misconfigured (`receiver_misconfigured`), the body can't be read
191
- * (`request_failed`) or a callback throws (`handler_failed`).
193
+ * - **204**: Event was handled, including events with no handler and unknown events.
194
+ * - **400**: Delivery doesn't verify. Body carries the error code.
195
+ * - **500**: Public keys are misconfigured (`receiver_misconfigured`), body can't be read
196
+ * (`request_failed`), or a callback throws (`handler_failed`).
192
197
  *
193
- * Base44 retries any answer that isn't 2xx, 400 and 500 alike. The status only shows in its delivery
194
- * log whether the delivery or your side failed.
198
+ * Base44 retries every answer that isn't 2xx, so it retries both 400 and 500. The two codes only
199
+ * differ in Base44's delivery log, where a 400 points to the delivery and a 500 points to your server.
195
200
  *
196
- * Base44 can deliver the same event more than once, so make your handlers safe to run twice for the
201
+ * Base44 might deliver the same event more than once, so make your handlers safe to run twice for the
197
202
  * same `event.id`.
198
203
  *
199
- * @param options - Your public keys, handlers and callbacks.
204
+ * @param options - Your public keys, handlers, and callbacks.
200
205
  * @returns A function that takes a `Request` and resolves to the `Response` to send.
201
206
  *
202
207
  * @example
@@ -7,7 +7,7 @@ import type { PlatformServer } from "./server.types.js";
7
7
  * such as [`webhooks`](/developers/references/platform-sdk/docs/interfaces/webhooks). It takes no
8
8
  * options and makes no network requests. Each module takes what it needs when you call it.
9
9
  *
10
- * @returns A server client with access to the platform's server modules.
10
+ * @returns A new platform server client.
11
11
  *
12
12
  * @example
13
13
  * ```typescript
@@ -7,7 +7,7 @@ import { createWebhooks } from "./modules/webhooks.js";
7
7
  * such as [`webhooks`](/developers/references/platform-sdk/docs/interfaces/webhooks). It takes no
8
8
  * options and makes no network requests. Each module takes what it needs when you call it.
9
9
  *
10
- * @returns A server client with access to the platform's server modules.
10
+ * @returns A new platform server client.
11
11
  *
12
12
  * @example
13
13
  * ```typescript
@@ -1,10 +1,8 @@
1
1
  import type { WebhooksModule } from "./modules/webhooks.types.js";
2
2
  /**
3
- * The platform server client.
4
- *
5
- * Provides access to the platform's server modules.
3
+ * The platform server client, with one property for each module.
6
4
  */
7
5
  export interface PlatformServer {
8
- /** [Webhooks module](/developers/references/platform-sdk/docs/interfaces/webhooks) for receiving the events Base44 sends to your server. */
6
+ /** [Webhooks module](/developers/references/platform-sdk/docs/interfaces/webhooks) for receiving and verifying Base44's webhooks. */
9
7
  readonly webhooks: WebhooksModule;
10
8
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@base44-preview/platform",
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",
3
+ "version": "0.4.0-pr.344.26b3201",
4
+ "description": "Base44 Platform SDK for white-label platforms: a browser client for following the AI chat and a server entrypoint for webhooks",
5
5
  "main": "dist/client/index.js",
6
6
  "types": "dist/client/index.d.ts",
7
7
  "type": "module",
@@ -1,3 +0,0 @@
1
- import type { BuilderModule } from "./builder.types.js";
2
- /** @internal */
3
- export declare function createBuilder(): BuilderModule;
@@ -1,7 +0,0 @@
1
- import { BuilderSocket } from "./builder-socket.js";
2
- /** @internal */
3
- export function createBuilder() {
4
- return {
5
- init(options) { return new BuilderSocket(options); },
6
- };
7
- }
@@ -1,193 +0,0 @@
1
- import type { PlatformEvent, PlatformSnapshot } from "./builder.events.types.js";
2
- import type { PlatformSocketError } from "../errors.js";
3
- /**
4
- * The socket session your server opened, as [Create socket session](/api-reference/create-socket-session) returned it.
5
- *
6
- * Pass the response body through unchanged. The client reads these three fields and ignores the
7
- * rest, such as `session_id` and `expires_in`.
8
- */
9
- export interface SocketSession {
10
- /** Token that authenticates the socket. The client keeps it in memory and sends it only when the socket connects. */
11
- session_token: string;
12
- /** Origin of the platform socket, with no path, query, fragment or credentials. */
13
- socket_url: string;
14
- /** Absolute path the socket connects on, such as `/ws/socket.io/`. */
15
- socket_path: string;
16
- }
17
- /** Options for {@linkcode BuilderModule.init | init()}. */
18
- export interface BuilderInitOptions {
19
- /**
20
- * Returns a new socket session from your server.
21
- *
22
- * Your server opens the session with its workspace API key through
23
- * [Create socket session](/api-reference/create-socket-session) and returns the response body, a [`SocketSession`](#socketsession).
24
- * The client calls this on the first `connect()`, and again only when the session expires or
25
- * Base44 rejects its token. Return a new session on every call. If a new session has a different
26
- * `socket_url` or `socket_path`, the client moves to it and rejoins every active subscription.
27
- *
28
- * @returns The session, as your server received it.
29
- */
30
- getSession: () => Promise<SocketSession>;
31
- /**
32
- * Called on errors that affect the whole session, such as a failed connection or an ended session.
33
- * Errors for one app go to that subscription's `onError` instead. See the
34
- * [error codes](/developers/references/platform-sdk/docs/classes/PlatformSocketError#platformsocketerrorcode).
35
- */
36
- onError: (error: PlatformSocketError) => void;
37
- }
38
- /**
39
- * Builder module for following the AI chat in your users' apps live.
40
- *
41
- * Each session holds one socket and up to eight app subscriptions. For each app you get a
42
- * snapshot of its chat, then every change as it happens:
43
- * - New and updated chat messages, with the AI's tool calls.
44
- * - The AI's status, from processing to ready.
45
- * - Preview reloads and navigation, the prompt queue, and generated images.
46
- *
47
- * The module does nothing until you call {@linkcode init | init()}.
48
- */
49
- export interface BuilderModule {
50
- /**
51
- * Creates a builder session without connecting it.
52
- *
53
- * Call {@linkcode BuilderSession.connect | connect()} on the returned session to open the socket.
54
- * Each session is independent, with its own socket, socket session and subscriptions.
55
- *
56
- * @param options - Session options.
57
- * @returns The new session.
58
- *
59
- * @example
60
- * ```typescript
61
- * // Create and connect a session
62
- * const builder = client.builder.init({
63
- * async getSession() {
64
- * const response = await fetch('/api/builder-socket-session', { method: 'POST' });
65
- * return response.json();
66
- * },
67
- * onError(error) {
68
- * console.error('Builder session error', error.code);
69
- * },
70
- * });
71
- * await builder.connect();
72
- * ```
73
- */
74
- init(options: BuilderInitOptions): BuilderSession;
75
- }
76
- /**
77
- * A `BuilderSession`: one socket with its app subscriptions and its reconnection. Use its methods
78
- * to connect, follow apps and close.
79
- */
80
- export interface BuilderSession {
81
- /**
82
- * Connects the session's socket.
83
- *
84
- * Resolves once the socket connects, before any snapshot arrives. If the connection drops, the
85
- * session retries five times and rejoins every active subscription, each with a fresh snapshot.
86
- * The first call fetches a session through `getSession`, and an expired or rejected token is
87
- * replaced once the same way. Concurrent calls share one attempt. Call it again after a failure or a `session_replaced` error.
88
- *
89
- * @returns Promise that resolves when the socket connects.
90
- * @throws {PlatformSocketError} With `connection_denied`, `connection_failed` or `session_unavailable`
91
- * when the session can't connect, or `client_closed` when the session is closed first.
92
- *
93
- * @example
94
- * ```typescript
95
- * // Connect and handle failure
96
- * try {
97
- * await builder.connect();
98
- * } catch (error) {
99
- * console.error('Could not connect', error.code);
100
- * }
101
- * ```
102
- */
103
- connect(): Promise<void>;
104
- /**
105
- * Subscribes to one app's chat.
106
- *
107
- * You can subscribe before or after connecting. Each app can have one subscription per session,
108
- * and a session can have up to eight. The app must be on the session's allowlist. The
109
- * subscription first receives a snapshot of the app, then each live event.
110
- *
111
- * Callbacks for an app run one at a time, in order, and the session waits for a returned promise
112
- * before the next one. A slow app doesn't hold up the others. If more than 1,000 deliveries wait
113
- * for one app, its subscription ends with `delivery_overflow`.
114
- *
115
- * @param appId - ID of the app to follow, 24 lowercase hexadecimal characters.
116
- * @param options - Callbacks for the app's snapshots, events and errors.
117
- * @returns The subscription.
118
- * @throws {TypeError} When `appId` isn't a valid app ID or the app already has a subscription.
119
- * @throws {PlatformSocketError} With `subscription_limit` when the session has eight subscriptions.
120
- *
121
- * @example
122
- * ```typescript
123
- * // Follow an app
124
- * const subscription = builder.subscribe(appId, {
125
- * onSnapshot(snapshot) {
126
- * renderChat(snapshot.messages);
127
- * },
128
- * onEvent(event) {
129
- * if (event.type === 'message.updated') upsertMessage(event.data.message);
130
- * },
131
- * onError(error) {
132
- * console.error(`App ${error.appId}`, error.code);
133
- * },
134
- * });
135
- * ```
136
- */
137
- subscribe(appId: string, options: SubscriptionOptions): PlatformSubscription;
138
- /**
139
- * Closes the session.
140
- *
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/builder#init)
143
- * for a new one.
144
- *
145
- * @example
146
- * ```typescript
147
- * // Close a session
148
- * builder.close();
149
- * ```
150
- */
151
- close(): void;
152
- }
153
- /** Callbacks for one app subscription. */
154
- export interface SubscriptionOptions {
155
- /**
156
- * Called with the app's current state, a [`PlatformSnapshot`](#platformsnapshot). Replace everything you hold for the app with it.
157
- *
158
- * Arrives after every join and rejoin, and after the main conversation is rewritten by an undo,
159
- * restore or sync. Live events follow it. It holds only the last 50 messages, so merge by message
160
- * ID to keep older history.
161
- */
162
- onSnapshot: (snapshot: PlatformSnapshot) => void | Promise<void>;
163
- /**
164
- * Called with each live event, a [`PlatformEvent`](#platformevent). Events for an app arrive one at a time, in order. If the callback
165
- * throws or rejects, the subscription ends with `handler_failed`. New event types can be added at
166
- * any time, so ignore types you don't handle. An event newer than this SDK arrives with
167
- * `type: "unknown"` and its name in `name`. For every event and its payload,
168
- * see [Socket messages](/developers/references/apps-api/sections/socket-messages).
169
- */
170
- onEvent: (event: PlatformEvent) => void | Promise<void>;
171
- /**
172
- * Called on errors for this app. Every error ends the subscription except `snapshot_unavailable`.
173
- * See the [error codes](/developers/references/platform-sdk/docs/classes/PlatformSocketError#platformsocketerrorcode).
174
- */
175
- onError: (error: PlatformSocketError) => void;
176
- }
177
- /** One app subscription. */
178
- export interface PlatformSubscription {
179
- /** ID of the app. */
180
- readonly appId: string;
181
- /** Whether the subscription still receives updates. It turns false after an error or {@linkcode unsubscribe | unsubscribe()}. */
182
- readonly active: boolean;
183
- /**
184
- * Stops updates for the app and frees its subscription slot. Calling it again does nothing.
185
- *
186
- * @example
187
- * ```typescript
188
- * // Stop following an app
189
- * subscription.unsubscribe();
190
- * ```
191
- */
192
- unsubscribe(): void;
193
- }