@base44-preview/sdk 0.8.49-pr.289.dd3fb8f → 0.8.50-pr.290.00d2bf0

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/dist/actor.d.ts CHANGED
@@ -25,8 +25,8 @@ export interface Storage {
25
25
  get<T>(key: string): Promise<T | undefined>;
26
26
  put(key: string, value: unknown): Promise<void>;
27
27
  delete(key: string): Promise<boolean>;
28
- /** Wipe the session's entire persisted storage. A later connection starts
29
- * with the same empty storage as a new session. */
28
+ /** Wipe the room's entire persisted storage (match-end cleanup). Safe: a
29
+ * later rejoin re-bootstraps exactly like a brand-new room. */
30
30
  deleteAll(): Promise<void>;
31
31
  }
32
32
  /**
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ export type { AuthModule, LoginResponse, RegisterParams, VerifyOtpParams, Change
9
9
  export type { IntegrationsModule, IntegrationEndpointFunction, CoreIntegrations, InvokeLLMParams, GenerateImageParams, GenerateImageResult, UploadFileParams, UploadFileResult, SendEmailParams, SendEmailResult, ExtractDataFromUploadedFileParams, ExtractDataFromUploadedFileResult, UploadPrivateFileParams, UploadPrivateFileResult, CreateFileSignedUrlParams, CreateFileSignedUrlResult, } from "./modules/integrations.types.js";
10
10
  export type { FunctionsModule, FunctionName, FunctionNameRegistry, } from "./modules/functions.types.js";
11
11
  export type { AgentsModule, AgentName, AgentNameRegistry, AgentConversation, AgentMessage, AgentMessageReasoning, AgentMessageToolCall, AgentMessageUsage, AgentMessageCustomContext, AgentMessageMetadata, CreateConversationParams, } from "./modules/agents.types.js";
12
- export type { AiGatewayModule, AiGatewayConnection, } from "./modules/ai-gateway.types.js";
12
+ export type { AiGatewayModule, AiGatewayConnection, AiGatewayConnectionOptions, } from "./modules/ai-gateway.types.js";
13
13
  export type { AppLogsModule } from "./modules/app-logs.types.js";
14
14
  export type { AppModule, AppPublicSettings, AppPublicSettingsResponse, } from "./modules/app.types.js";
15
15
  export type { ActorsModule, ActorClient, ActorRef, Connection, ActorSubscription, ActorConnectOptions, ActorNameRegistry, ActorRegistry, } from "./modules/actors.types.js";
@@ -1,15 +1,9 @@
1
1
  /**
2
- * Maps actor names to their incoming and outgoing message types.
2
+ * Extend this interface to add typed `subscribe` callbacks and `send` payloads
3
+ * for your deployed Actors.
3
4
  *
4
- * Extend this interface through module augmentation when you want typed actor
5
- * messages without generating types with the CLI. For each actor, `toServer`
6
- * defines incoming messages that a client sends to the actor. `toClient` defines
7
- * outgoing messages that the actor sends to connected clients.
8
- *
9
- * To generate types from deployed actors instead, use the
10
- * [`types generate`](/developers/references/cli/commands/types-generate) CLI command.
11
- * See [Typing messages in the client](/developers/backend/resources/actors/overview#typing-messages-in-the-client)
12
- * for how to define your message types.
5
+ * This is separate from {@link ActorNameRegistry} (which is auto-generated
6
+ * by `base44 types generate`), so there are no conflicts.
13
7
  *
14
8
  * @example
15
9
  * ```typescript
@@ -26,11 +20,8 @@
26
20
  export interface ActorRegistry {
27
21
  }
28
22
  /**
29
- * Lists actor names when your project includes types generated by the CLI
30
- * with [`types generate`](/developers/references/cli/commands/types-generate).
31
- *
32
- * The generated names provide autocomplete for deployed actors. To define
33
- * incoming and outgoing message types manually, augment {@link ActorRegistry}.
23
+ * Auto-populated by `base44 types generate` with the names of your deployed actors.
24
+ * Do not edit this interface manually — use {@link ActorRegistry} for message types.
34
25
  */
35
26
  export interface ActorNameRegistry {
36
27
  }
@@ -41,135 +32,71 @@ type ToClientFor<N extends string> = N extends keyof ActorRegistry ? ActorRegist
41
32
  type ToServerFor<N extends string> = N extends keyof ActorRegistry ? ActorRegistry[N] extends {
42
33
  toServer: infer O;
43
34
  } ? O : unknown : unknown;
44
- /**
45
- * Options for {@link ActorRef.connect}.
46
- */
35
+ /** Options for {@link ActorRef.connect}. */
47
36
  export interface ActorConnectOptions {
48
37
  /**
49
- * Connection ID that the actor receives as `conn.id`.
50
- *
51
- * Use a stable value, such as one stored per browser tab, so the actor
52
- * can recognize the same client if it reconnects. If omitted, the SDK generates one.
53
- *
54
- * See [Connection ID](/developers/backend/resources/actors/overview#connection-id)
55
- * for more details.
38
+ * The connection id — becomes the actor's `conn.id`. Supply a stable value
39
+ * (e.g. persisted per tab) so a reconnect reuses the same server-side
40
+ * identity; omit for an auto-generated per-connection id.
56
41
  */
57
42
  id?: string;
58
43
  }
59
- /**
60
- * Represents an outgoing-message listener registered with
61
- * {@link Connection.subscribe}.
62
- */
44
+ /** Handle for one listener registered via {@link Connection.subscribe}. */
63
45
  export interface ActorSubscription {
64
- /**
65
- * Removes this listener. Other listeners and the socket stay open.
66
- */
46
+ /** Remove this listener; other listeners and the socket stay live. */
67
47
  unsubscribe(): void;
68
48
  }
69
49
  /**
70
- * Represents a client's WebSocket connection to an actor session.
71
- *
72
- * {@link ActorRef.connect} returns this object while the socket connects.
73
- * The socket buffers messages sent during connection setup until it opens.
50
+ * A live connection to an actor instance, returned by {@link ActorRef.connect}.
51
+ * `subscribe`/`send` are always valid — you only get a `Connection` once the
52
+ * socket has been opened, so there's no pre-connect state to guard against.
74
53
  */
75
54
  export interface Connection<N extends string = string> {
76
- /** Connection ID that the actor receives as `conn.id`. */
55
+ /** The connection id (the value the actor sees as `conn.id`). */
77
56
  readonly id: string;
78
- /**
79
- * Registers a listener for outgoing messages from the actor.
80
- *
81
- * You can register multiple listeners on the same connection.
82
- *
83
- * @param callback - Called with each outgoing message sent to this connection.
84
- * @returns A handle you can use to remove this listener without closing the socket.
85
- */
57
+ /** Register a message listener. Multiple are allowed; returns a per-listener unsubscribe. */
86
58
  subscribe(callback: (data: ToClientFor<N>) => void): ActorSubscription;
87
- /**
88
- * Sends an incoming message to the actor.
89
- *
90
- * The socket buffers messages until it opens. After {@link close}, the socket
91
- * drops further sends.
92
- *
93
- * @param data - Incoming message to send. Typed through {@link ActorRegistry} when configured.
94
- */
59
+ /** Send a message. Buffered by the socket until it's open; dropped after
60
+ * {@link close}. */
95
61
  send(data: ToServerFor<N>): void;
96
62
  /**
97
- * Closes the connection and removes all listeners.
98
- *
99
- * Safe to call more than once. A connection also closes itself when it fails
100
- * permanently. See {@link ActorRef.connect} for how to open a fresh connection.
63
+ * Tear down the socket, heartbeat, and all listeners. Safe to call more
64
+ * than once. A connection also closes itself when it fails permanently —
65
+ * see {@link ActorRef.connect}.
101
66
  */
102
67
  close(): void;
103
68
  }
104
69
  /**
105
- * Represents an actor session selected by actor name and session ID.
106
- *
107
- * Call {@link connect} to open the WebSocket and get a {@link Connection}.
70
+ * A handle to one actor instance — `base44.actors.MyActor(id)`. Call
71
+ * {@link connect} to open the socket and get a {@link Connection}.
108
72
  */
109
73
  export interface ActorRef<N extends string = string> {
110
74
  /**
111
- * Creates or returns the {@link Connection} for this session.
112
- *
113
- * Repeated calls return the same connection until it closes. After a permanent
114
- * failure, such as a missing actor or denied connection, fix the cause and call
115
- * `connect()` again. Add subscriptions to the new connection.
116
- *
117
- * See [Connect a client to a session](/developers/backend/resources/actors/samples#connect-a-client-to-a-session)
118
- * for a sample flow.
75
+ * Open the WebSocket and return the {@link Connection}. Idempotent while the
76
+ * connection is open.
119
77
  *
120
- * @param options - Optional connection settings, such as a stable connection ID.
121
- * @returns The {@link Connection} for this actor session.
78
+ * A connection that fails permanently (for example, the actor doesn't exist
79
+ * or the caller isn't allowed to connect) closes itself and reports the
80
+ * error to the client's `onError` handler. Call `connect()` again after
81
+ * fixing the cause to get a fresh {@link Connection}, and re-subscribe.
122
82
  */
123
83
  connect(options?: ActorConnectOptions): Connection<N>;
124
84
  }
125
85
  /**
126
- * Selects a session for a named actor.
127
- *
128
- * Typed automatically when the actor is registered in {@link ActorRegistry} or
129
- * {@link ActorNameRegistry}.
86
+ * Client for a single named Actor — call it with an instance id to get an
87
+ * {@link ActorRef}. Typed automatically when the actor is registered in
88
+ * {@link ActorRegistry}.
130
89
  */
131
90
  export interface ActorClient<N extends string = string> {
132
- /**
133
- * Gets a reference to an actor session.
134
- *
135
- * Clients that specify the same actor name and session ID join the same session.
136
- *
137
- * @param instanceId - Session ID that identifies which session to connect to.
138
- * @returns A reference to the actor session.
139
- */
140
91
  (instanceId: string): ActorRef<N>;
141
92
  }
142
93
  /**
143
- * Provides access to actors and their shared, live sessions.
144
- *
145
- * Select an actor by name and session ID, then connect a client to the
146
- * session. Clients in the same session can exchange realtime messages through the
147
- * actor. The client works in the browser and in Node.
148
- *
149
- * ## Connection flow
150
- *
151
- * - Connect to a session with `base44.actors.<ActorName>(sessionId).connect()`.
152
- * - Subscribe to outgoing messages with {@link Connection.subscribe}.
153
- * - Send incoming messages with {@link Connection.send}.
154
- * - Close the connection with {@link Connection.close}.
94
+ * The actors module provides access to Cloudflare Durable Object-backed
95
+ * Actors deployed by the Base44 platform.
155
96
  *
156
- * See [Actors Overview](/developers/backend/resources/actors/overview)
157
- * for actor concepts and terminology, [Actor Class Reference](/developers/backend/resources/actors/reference)
158
- * for the backend class API, and [Sample Flows](/developers/backend/resources/actors/samples)
159
- * for common patterns.
160
- *
161
- * ## Authentication modes
162
- *
163
- * This module is available in anonymous or user authentication mode
164
- * (`base44.actors`). It isn't available with service role authentication. Apps that
165
- * require login can reject anonymous connections in the actor's `handleConnect()` method.
166
- * See [Manage client connections](/developers/backend/resources/actors/samples#manage-client-connections)
167
- * for a sample flow.
168
- *
169
- * @example
170
97
  * ```typescript
171
- * const conn = base44.actors.Chat("session-1").connect({ id: "tab-1" });
172
- * const sub = conn.subscribe((msg) => console.log(msg));
98
+ * const conn = base44.actors.MyActor("room-1").connect();
99
+ * const sub = conn.subscribe((msg) => console.log(msg)); // typed via ActorRegistry
173
100
  * conn.send({ type: "message", text: "hi" });
174
101
  * sub.unsubscribe();
175
102
  * conn.close();
@@ -1,11 +1,19 @@
1
1
  import { getAccessToken } from "../utils/auth-utils.js";
2
+ const PROVIDER_PATHS = {
3
+ openai: "openai",
4
+ typesafe: "typesafe",
5
+ };
2
6
  export function createAiGatewayModule({ serverUrl, token, appId, }) {
3
- const connection = () => {
7
+ const connection = ({ provider = "openai" } = {}) => {
4
8
  var _a;
5
- return ({
6
- baseURL: `${serverUrl}/api/apps/${appId}/ai/openai/v1`,
9
+ if (!Object.prototype.hasOwnProperty.call(PROVIDER_PATHS, provider)) {
10
+ throw new Error(`Unsupported AI Gateway provider: ${provider}`);
11
+ }
12
+ const providerPath = PROVIDER_PATHS[provider];
13
+ return {
14
+ baseURL: `${serverUrl}/api/apps/${appId}/ai/${providerPath}/v1`,
7
15
  token: (_a = token !== null && token !== void 0 ? token : getAccessToken()) !== null && _a !== void 0 ? _a : "",
8
- });
16
+ };
9
17
  };
10
18
  return {
11
19
  connection,
@@ -2,7 +2,7 @@
2
2
  * Connection details for the Base44 AI Gateway.
3
3
  */
4
4
  export interface AiGatewayConnection {
5
- /** Base URL of the gateway's OpenAI-compatible Chat Completions endpoint. */
5
+ /** Base URL of the selected gateway provider. */
6
6
  baseURL: string;
7
7
  /**
8
8
  * Bearer token that authenticates the request. Empty string when the caller is
@@ -10,6 +10,11 @@ export interface AiGatewayConnection {
10
10
  */
11
11
  token: string;
12
12
  }
13
+ /** Options for selecting an AI Gateway provider. */
14
+ export interface AiGatewayConnectionOptions {
15
+ /** Gateway provider to connect to. Defaults to `openai`. */
16
+ provider?: "openai" | "typesafe";
17
+ }
13
18
  /**
14
19
  * Configuration for the AI Gateway module.
15
20
  * @internal
@@ -34,13 +39,17 @@ export interface AiGatewayModuleConfig {
34
39
  * against the provider directly, no separate account, API key, or billing
35
40
  * setup with the underlying model provider required.
36
41
  *
42
+ * By default, `connection()` uses the OpenAI-compatible provider. Pass
43
+ * `{ provider: "typesafe" }` to connect to TypeSafe for structured evaluations
44
+ * with `@ai-sdk/typesafe-ai`.
45
+ *
37
46
  * Call `connection()` from a backend function rather than the browser. This
38
47
  * keeps your instructions, tools, and business logic server-side, and lets
39
48
  * you enforce your own auth, rate, and spend limits around the call. The
40
49
  * `token` it returns is the caller's regular session token, the same one
41
50
  * used for every other SDK call.
42
51
  *
43
- * ## Models
52
+ * ## OpenAI-compatible models
44
53
  *
45
54
  * You can use any of the [models available through `InvokeLLM`](/developers/references/sdk/docs/type-aliases/integrations#invokellm).
46
55
  * Pass `'automatic'` to let Base44 choose one, or pin a specific model such
@@ -69,7 +78,9 @@ export interface AiGatewayModule {
69
78
  /**
70
79
  * Gets the connection details for the Base44 AI Gateway.
71
80
  *
72
- * Returns the `baseURL` and `token` to pass to any OpenAI-compatible client.
81
+ * Returns the `baseURL` and `token` to pass to the selected provider client.
82
+ *
83
+ * @param options - Provider selection. Omit it to use the OpenAI-compatible gateway.
73
84
  *
74
85
  * @returns The gateway {@linkcode AiGatewayConnection | connection} (`baseURL` and `token`).
75
86
  *
@@ -135,5 +146,5 @@ export interface AiGatewayModule {
135
146
  * await agent.generate({ prompt: `Review this return request: ${JSON.stringify(returnRequest)}` });
136
147
  * ```
137
148
  */
138
- connection(): AiGatewayConnection;
149
+ connection(options?: AiGatewayConnectionOptions): AiGatewayConnection;
139
150
  }
@@ -950,6 +950,16 @@ type DynamicEntitiesModule = {
950
950
  * - **Anonymous or User authentication** (`base44.entities`): Access is scoped to the current user's permissions. Anonymous users can only access public entities, while authenticated users can access entities they have permission to view or modify.
951
951
  * - **Service role authentication** (`base44.asServiceRole.entities`): Operations bypass entity access rules and field-level security entirely. Can read and write any record in any entity.
952
952
  *
953
+ * ## How denied reads and writes differ
954
+ *
955
+ * Row-level security handles reads and writes differently.
956
+ *
957
+ * | Operation | When a rule denies it |
958
+ * | --- | --- |
959
+ * | `list()`, `filter()` | Returns an empty result, the same as if nothing matched. No error is thrown. |
960
+ * | `get()` | Throws a not-found error, whether or not the record exists. |
961
+ * | `create()`, `update()` | Throws a permission error with HTTP 403. |
962
+ *
953
963
  * ## Entity Handlers
954
964
  *
955
965
  * An entity handler is the object you get when you access an entity through `base44.entities.EntityName`. Every entity in your app automatically gets a handler with CRUD methods for managing records.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.49-pr.289.dd3fb8f",
3
+ "version": "0.8.50-pr.290.00d2bf0",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",