@base44-preview/platform 0.1.0-pr.319.850fe58 → 0.2.0-pr.313.52851f2

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 (59) hide show
  1. package/README.md +69 -124
  2. package/dist/client.d.ts +30 -0
  3. package/dist/client.js +32 -0
  4. package/dist/client.types.d.ts +10 -0
  5. package/dist/errors.d.ts +47 -0
  6. package/dist/errors.js +47 -0
  7. package/dist/errors.types.d.ts +98 -0
  8. package/dist/index.d.ts +8 -0
  9. package/dist/{client/index.js → index.js} +1 -1
  10. package/dist/modules/builder-protocol.d.ts +24 -0
  11. package/dist/modules/builder-protocol.js +52 -0
  12. package/dist/{client/modules → modules}/builder-socket.d.ts +9 -5
  13. package/dist/{client/modules → modules}/builder-socket.js +106 -86
  14. package/dist/{client/modules → modules}/builder-subscription.d.ts +2 -2
  15. package/dist/modules/builder.d.ts +3 -0
  16. package/dist/modules/builder.events.generated.d.ts +2194 -0
  17. package/dist/modules/builder.events.generated.js +3 -0
  18. package/dist/modules/builder.events.types.d.ts +61 -0
  19. package/dist/modules/builder.js +7 -0
  20. package/dist/modules/builder.types.d.ts +192 -0
  21. package/package.json +15 -22
  22. package/dist/client/client.d.ts +0 -9
  23. package/dist/client/client.js +0 -9
  24. package/dist/client/client.types.d.ts +0 -12
  25. package/dist/client/errors.d.ts +0 -10
  26. package/dist/client/errors.js +0 -10
  27. package/dist/client/errors.types.d.ts +0 -2
  28. package/dist/client/index.d.ts +0 -7
  29. package/dist/client/modules/builder-protocol.d.ts +0 -15
  30. package/dist/client/modules/builder-protocol.js +0 -34
  31. package/dist/client/modules/builder.d.ts +0 -4
  32. package/dist/client/modules/builder.events.types.d.ts +0 -368
  33. package/dist/client/modules/builder.js +0 -7
  34. package/dist/client/modules/builder.types.d.ts +0 -47
  35. package/dist/server/errors.d.ts +0 -15
  36. package/dist/server/errors.js +0 -18
  37. package/dist/server/errors.types.d.ts +0 -4
  38. package/dist/server/errors.types.js +0 -1
  39. package/dist/server/index.d.ts +0 -6
  40. package/dist/server/index.js +0 -3
  41. package/dist/server/modules/webhooks-signature.d.ts +0 -11
  42. package/dist/server/modules/webhooks-signature.js +0 -65
  43. package/dist/server/modules/webhooks.d.ts +0 -3
  44. package/dist/server/modules/webhooks.events.generated.d.ts +0 -174
  45. package/dist/server/modules/webhooks.events.generated.js +0 -3
  46. package/dist/server/modules/webhooks.js +0 -77
  47. package/dist/server/modules/webhooks.types.d.ts +0 -102
  48. package/dist/server/modules/webhooks.types.js +0 -1
  49. package/dist/server/server.d.ts +0 -10
  50. package/dist/server/server.js +0 -23
  51. package/dist/server/server.types.d.ts +0 -10
  52. package/dist/server/server.types.js +0 -1
  53. package/dist/shared/server-url.d.ts +0 -2
  54. package/dist/shared/server-url.js +0 -8
  55. /package/dist/{client/client.types.js → client.types.js} +0 -0
  56. /package/dist/{client/errors.types.js → errors.types.js} +0 -0
  57. /package/dist/{client/modules → modules}/builder-subscription.js +0 -0
  58. /package/dist/{client/modules → modules}/builder.events.types.js +0 -0
  59. /package/dist/{client/modules → modules}/builder.types.js +0 -0
@@ -0,0 +1,3 @@
1
+ // Generated from asyncapi.json by scripts/gen-events.mjs. Do not edit; run `npm run gen:events`.
2
+ /** @internal */
3
+ export const serverEventNames = ["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", "session.ended", "room.access_denied", "room.access_revoked", "room.snapshot_unavailable", "app.snapshot"];
@@ -0,0 +1,61 @@
1
+ import type { Message, QueueState, ServerEventMap, Snapshot } from "./builder.events.generated.js";
2
+ /**
3
+ * Maps each live event name to the type of its `data` payload.
4
+ *
5
+ * Generated from the service's AsyncAPI document, so it covers every app event the service sends.
6
+ * The client handles the session events `app.snapshot`, `session.ended` and `room.*` itself, and
7
+ * reports them through `onSnapshot` and `onError` instead.
8
+ */
9
+ export type PlatformEventMap = {
10
+ [K in keyof ServerEventMap as K extends "app.snapshot" | "session.ended" | `room.${string}` ? never : K]: ServerEventMap[K];
11
+ };
12
+ /**
13
+ * One live event for a subscribed app.
14
+ *
15
+ * Check `type` to narrow `data` to that event's payload. A key missing from `data` means the value
16
+ * is unchanged, and an explicit `null` clears it. For every event and its payload, see
17
+ * [Socket messages](/developers/references/apps-api/sections/socket-messages).
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * // Narrow an event by type
22
+ * function onEvent(event: PlatformEvent) {
23
+ * if (event.type === "message.updated") {
24
+ * const { message } = event.data;
25
+ * console.log(`Message ${message.id} changed`);
26
+ * }
27
+ * }
28
+ * ```
29
+ */
30
+ export type PlatformEvent = {
31
+ [K in keyof PlatformEventMap]: {
32
+ /** Event name. Narrows the type of `data`. */
33
+ type: K;
34
+ /** ID of the app the event belongs to. */
35
+ appId: string;
36
+ /** Event payload. */
37
+ data: PlatformEventMap[K];
38
+ };
39
+ }[keyof PlatformEventMap];
40
+ /**
41
+ * An app's current state.
42
+ *
43
+ * Arrives after every join and rejoin, and after a rewrite of the main conversation. Replace
44
+ * everything you hold for the app with it. It holds only the last 50 messages.
45
+ *
46
+ * Its fields are the `data` of [`app.snapshot`](/developers/references/apps-api/sections/socket-messages#app-snapshot),
47
+ * plus `room`.
48
+ */
49
+ export interface PlatformSnapshot extends Omit<Snapshot, "queue"> {
50
+ /** The app's room, `/apps/{app_id}`. */
51
+ room: string;
52
+ /** The main branch's prompt queue. Missing when the server sends none. */
53
+ queue?: QueueState;
54
+ }
55
+ /**
56
+ * One tool call in a message's `tool_calls`. Checking `name` narrows it to that tool's call and
57
+ * `OtherToolCall`, which covers tools the SDK doesn't know, so check a field with `in` before using it.
58
+ */
59
+ export type ToolCall = NonNullable<Message["tool_calls"]>[number];
60
+ /** Why a safety guard parked a tool call for approval. Check `guard` to narrow it. */
61
+ export type GuardApproval = NonNullable<ToolCall["approval"]>;
@@ -0,0 +1,7 @@
1
+ import { BuilderSocket } from "./builder-socket.js";
2
+ /** @internal */
3
+ export function createBuilder() {
4
+ return {
5
+ init(options) { return new BuilderSocket(options); },
6
+ };
7
+ }
@@ -0,0 +1,192 @@
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. For every event and its payload,
167
+ * see [Socket messages](/developers/references/apps-api/sections/socket-messages).
168
+ */
169
+ onEvent: (event: PlatformEvent) => void | Promise<void>;
170
+ /**
171
+ * Called on errors for this app. Every error ends the subscription except `snapshot_unavailable`.
172
+ * See the [error codes](/developers/references/platform-sdk/docs/classes/PlatformSocketError#platformsocketerrorcode).
173
+ */
174
+ onError: (error: PlatformSocketError) => void;
175
+ }
176
+ /** One app subscription. */
177
+ export interface PlatformSubscription {
178
+ /** ID of the app. */
179
+ readonly appId: string;
180
+ /** Whether the subscription still receives updates. It turns false after an error or {@linkcode unsubscribe | unsubscribe()}. */
181
+ readonly active: boolean;
182
+ /**
183
+ * Stops updates for the app and frees its subscription slot. Calling it again does nothing.
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * // Stop following an app
188
+ * subscription.unsubscribe();
189
+ * ```
190
+ */
191
+ unsubscribe(): void;
192
+ }
package/package.json CHANGED
@@ -1,18 +1,14 @@
1
1
  {
2
2
  "name": "@base44-preview/platform",
3
- "version": "0.1.0-pr.319.850fe58",
4
- "description": "Client and server SDK for building on the Base44 platform",
5
- "main": "dist/client/index.js",
6
- "types": "dist/client/index.d.ts",
3
+ "version": "0.2.0-pr.313.52851f2",
4
+ "description": "Browser client for building on the Base44 platform",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
7
  "type": "module",
8
8
  "exports": {
9
9
  ".": {
10
- "types": "./dist/client/index.d.ts",
11
- "default": "./dist/client/index.js"
12
- },
13
- "./server": {
14
- "types": "./dist/server/index.d.ts",
15
- "default": "./dist/server/index.js"
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
16
12
  },
17
13
  "./package.json": "./package.json"
18
14
  },
@@ -24,13 +20,20 @@
24
20
  },
25
21
  "scripts": {
26
22
  "build": "tsc",
23
+ "gen:events": "node scripts/gen-events.mjs",
24
+ "check:events": "node scripts/gen-events.mjs --check",
25
+ "sync:asyncapi": "node scripts/sync-asyncapi.mjs",
27
26
  "docs": "typedoc",
28
27
  "test": "npm run test:types && npm run test:unit && npm run docs && npm run test:package",
29
28
  "test:types": "tsc --noEmit -p tsconfig.type-tests.json",
30
29
  "test:unit": "vitest run",
31
30
  "test:package": "npm run build && node --test tests/package.test.mjs",
32
31
  "prepublishOnly": "npm run build",
33
- "generate:webhooks": "node scripts/generate-webhook-types.mjs"
32
+ "create-docs": "npm run create-docs:generate && npm run create-docs:process",
33
+ "create-docs-local": "npm run create-docs && npm run copy-docs-local",
34
+ "copy-docs-local": "node ../sdk/scripts/mintlify-post-processing/copy-to-local-docs.js --package-dir .",
35
+ "create-docs:generate": "node -e \"fs.rmSync('docs',{recursive:true,force:true})\" && typedoc --options typedoc.mintlify.json",
36
+ "create-docs:process": "node ../sdk/scripts/mintlify-post-processing/file-processing/file-processing.js --package-dir ."
34
37
  },
35
38
  "dependencies": {
36
39
  "socket.io-client": "^4.8.3"
@@ -51,17 +54,7 @@
51
54
  "url": "https://github.com/base44/javascript-sdk/issues"
52
55
  },
53
56
  "homepage": "https://github.com/base44/javascript-sdk/tree/main/packages/platform#readme",
54
- "typesVersions": {
55
- "*": {
56
- "server": [
57
- "dist/server/index.d.ts"
58
- ]
59
- }
60
- },
61
57
  "devDependencies": {
62
- "json-schema-to-typescript": "^16.0.0"
63
- },
64
- "engines": {
65
- "node": ">=20"
58
+ "json-schema-to-typescript": "16.0.0"
66
59
  }
67
60
  }
@@ -1,9 +0,0 @@
1
- import type { PlatformClientOptions } from "./client.types.js";
2
- import type { BuilderModule } from "./modules/builder.types.js";
3
- /** Browser platform client. Construction creates no sockets, timers or network requests. */
4
- export declare class Base44PlatformClient {
5
- /** Lazy builder subscriptions with independent session lifecycles. */
6
- readonly builder: BuilderModule;
7
- /** Configure shared service/auth settings; each module initializes its own resources. */
8
- constructor(options: PlatformClientOptions);
9
- }
@@ -1,9 +0,0 @@
1
- import { normalizeServerUrl } from "../shared/server-url.js";
2
- import { createBuilder } from "./modules/builder.js";
3
- /** Browser platform client. Construction creates no sockets, timers or network requests. */
4
- export class Base44PlatformClient {
5
- /** Configure shared service/auth settings; each module initializes its own resources. */
6
- constructor(options) {
7
- this.builder = Object.freeze(createBuilder({ ...options, serverUrl: normalizeServerUrl(options.serverUrl) }));
8
- }
9
- }
@@ -1,12 +0,0 @@
1
- /** Shared configuration for browser platform modules. Never supply an API key. */
2
- export interface PlatformClientOptions {
3
- /** Origin of the platform service, e.g. https://base44.app. No path/query/credentials. */
4
- serverUrl: string;
5
- /**
6
- * Return a socket-session token from your backend, which opens the session with its
7
- * workspace key (`POST /api/service/socket-sessions`) for the apps this page watches.
8
- * Called when a builder session first connects, and again only after the server
9
- * rejects or expires the current session. Sessions last one hour.
10
- */
11
- getSessionToken: () => string | Promise<string>;
12
- }
@@ -1,10 +0,0 @@
1
- import type { PlatformSocketErrorCode } from "./errors.types.js";
2
- /** Sanitized failure. Original session-token provider, handler and server exceptions are not retained. */
3
- export declare class PlatformSocketError extends Error {
4
- /** Stable machine-readable category. */
5
- readonly code: PlatformSocketErrorCode;
6
- /** Associated app, when the server identifies a valid room. */
7
- readonly appId?: string;
8
- /** Create a sanitized error with no credential-bearing cause or payload. */
9
- constructor(code: PlatformSocketErrorCode, appId?: string);
10
- }
@@ -1,10 +0,0 @@
1
- /** Sanitized failure. Original session-token provider, handler and server exceptions are not retained. */
2
- export class PlatformSocketError extends Error {
3
- /** Create a sanitized error with no credential-bearing cause or payload. */
4
- constructor(code, appId) {
5
- super(`Platform socket: ${code}`);
6
- this.name = "PlatformSocketError";
7
- this.code = code;
8
- this.appId = appId;
9
- }
10
- }
@@ -1,2 +0,0 @@
1
- /** Server refusals and client transport/processing failures. */
2
- export type PlatformSocketErrorCode = "connection_denied" | "connection_failed" | "session_unavailable" | "session_revoked" | "session_replaced" | "access_denied" | "access_revoked" | "snapshot_unavailable" | "subscription_limit" | "delivery_overflow" | "protocol_error" | "handler_failed" | "client_closed";
@@ -1,7 +0,0 @@
1
- /** Browser platform modules, separate from the runtime and server SDKs. */
2
- export { Base44PlatformClient } from "./client.js";
3
- export { PlatformSocketError } from "./errors.js";
4
- export type { PlatformSocketErrorCode } from "./errors.types.js";
5
- export type { PlatformClientOptions } from "./client.types.js";
6
- export type { BuilderModule, BuilderInitOptions, BuilderSession, PlatformSubscription, SubscriptionOptions } from "./modules/builder.types.js";
7
- export type { AppStatus, AppStatusChanged, BranchScoped, ChatMessage, ImageResolved, MessageParams, MessageRemoved, MessageUpdated, PlatformEvent, PlatformEventMap, PreviewNavigationRequested, QueueItem, QueueUpdated, Snapshot, SnapshotQueue, TaskProgressed, ToolArguments, ToolCall, ToolDisplay, ToolEntityMutationArguments, ToolGuardApproval, ToolMediaArguments, ToolMediaResult, ToolPackageArguments, ToolPackageOperation, ToolPlanArguments, ToolPlanUpdate, ToolPrdArguments, ToolQuestion, ToolQuestionAnswer, ToolQuestionArguments, ToolQuestionInput, ToolQuestionOption, ToolSecretArguments, ToolSecretField, } from "./modules/builder.events.types.js";
@@ -1,15 +0,0 @@
1
- import type { PlatformEvent, PlatformEventMap, Snapshot } from "./builder.events.types.js";
2
- export declare const eventNames: readonly ["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"];
3
- /** Notices that name an app room, by the error code each one reports. */
4
- export declare const roomNotices: {
5
- readonly "room.access_denied": "access_denied";
6
- readonly "room.access_revoked": "access_revoked";
7
- readonly "room.snapshot_unavailable": "snapshot_unavailable";
8
- };
9
- export declare const appPattern: RegExp;
10
- export declare const roomFor: (appId: string) => string;
11
- export declare function object(value: unknown): Record<string, unknown>;
12
- export declare function appFromRoom(value: unknown): string | undefined;
13
- /** Every event is `{room, data}`; payload schemas are the service's, so only the envelope is validated. */
14
- export declare function decode(type: keyof PlatformEventMap, appId: string, raw: unknown): PlatformEvent;
15
- export declare function decodeSnapshot(raw: unknown): Snapshot;
@@ -1,34 +0,0 @@
1
- export const eventNames = [
2
- "message.updated", "message.removed", "app.status_changed", "preview.reload_requested",
3
- "preview.navigation_requested", "queue.updated", "task.progressed", "image.resolved",
4
- "conversation.changed", "files.changed", "branch.deleted", "repository.changed", "pull_request.changed",
5
- ];
6
- /** Notices that name an app room, by the error code each one reports. */
7
- export const roomNotices = {
8
- "room.access_denied": "access_denied",
9
- "room.access_revoked": "access_revoked",
10
- "room.snapshot_unavailable": "snapshot_unavailable",
11
- };
12
- export const appPattern = /^[a-f0-9]{24}$/;
13
- export const roomFor = (appId) => `/apps/${appId}`;
14
- export function object(value) {
15
- if (!value || typeof value !== "object" || Array.isArray(value))
16
- throw new Error("Invalid frame");
17
- return value;
18
- }
19
- export function appFromRoom(value) {
20
- return typeof value === "string" && /^\/apps\/[a-f0-9]{24}$/.test(value) ? value.slice(6) : undefined;
21
- }
22
- /** Every event is `{room, data}`; payload schemas are the service's, so only the envelope is validated. */
23
- export function decode(type, appId, raw) {
24
- return { type, appId, data: object(object(raw).data) };
25
- }
26
- export function decodeSnapshot(raw) {
27
- const frame = object(raw);
28
- const data = object(frame.data);
29
- if (!appFromRoom(frame.room) || !Array.isArray(data.messages) || (data.status !== null && typeof data.status !== "object")) {
30
- throw new Error("Invalid snapshot");
31
- }
32
- const queue = data.queue !== null && typeof data.queue === "object" ? { queue: data.queue } : {};
33
- return { room: frame.room, status: data.status, messages: data.messages, ...queue };
34
- }
@@ -1,4 +0,0 @@
1
- import type { PlatformClientOptions } from "../client.types.js";
2
- import type { BuilderModule } from "./builder.types.js";
3
- /** @internal */
4
- export declare function createBuilder(config: PlatformClientOptions): BuilderModule;