@base44-preview/sdk 0.8.48-pr.288.6247e7c → 0.8.48-pr.289.b9ea964

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 room's entire persisted storage (match-end cleanup). Safe: a
29
- * later rejoin re-bootstraps exactly like a brand-new room. */
28
+ /** Wipe the session's entire persisted storage. A later connection starts
29
+ * with the same empty storage as a new session. */
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, AiGatewayConnectionOptions, } from "./modules/ai-gateway.types.js";
12
+ export type { AiGatewayModule, AiGatewayConnection, } 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,9 +1,10 @@
1
1
  /**
2
- * Extend this interface to add typed `subscribe` callbacks and `send` payloads
3
- * for your deployed Actors.
2
+ * Maps actor names to their incoming and outgoing message types.
4
3
  *
5
- * This is separate from {@link ActorNameRegistry} (which is auto-generated
6
- * by `base44 types generate`), so there are no conflicts.
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.
7
8
  *
8
9
  * @example
9
10
  * ```typescript
@@ -20,8 +21,10 @@
20
21
  export interface ActorRegistry {
21
22
  }
22
23
  /**
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.
24
+ * Lists actor names when your project includes types generated by the CLI.
25
+ *
26
+ * The generated names provide autocomplete for deployed actors. To define
27
+ * incoming and outgoing message types manually, augment {@link ActorRegistry}.
25
28
  */
26
29
  export interface ActorNameRegistry {
27
30
  }
@@ -32,71 +35,163 @@ type ToClientFor<N extends string> = N extends keyof ActorRegistry ? ActorRegist
32
35
  type ToServerFor<N extends string> = N extends keyof ActorRegistry ? ActorRegistry[N] extends {
33
36
  toServer: infer O;
34
37
  } ? O : unknown : unknown;
35
- /** Options for {@link ActorRef.connect}. */
38
+ /**
39
+ * Options for {@link ActorRef.connect}.
40
+ */
36
41
  export interface ActorConnectOptions {
37
42
  /**
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.
43
+ * Connection ID that the actor receives as `conn.id`.
44
+ *
45
+ * Specify a stable value, such as a value persisted per client, so
46
+ * reconnections from that client reuse the same connection ID. Omit this property
47
+ * to generate an ID.
41
48
  */
42
49
  id?: string;
43
50
  }
44
- /** Handle for one listener registered via {@link Connection.subscribe}. */
51
+ /**
52
+ * Represents an outgoing-message listener registered with
53
+ * {@link Connection.subscribe}.
54
+ */
45
55
  export interface ActorSubscription {
46
- /** Remove this listener; other listeners and the socket stay live. */
56
+ /**
57
+ * Removes this listener. Other listeners and the socket stay open.
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const sub = conn.subscribe((msg) => console.log(msg));
62
+ * sub.unsubscribe();
63
+ * ```
64
+ */
47
65
  unsubscribe(): void;
48
66
  }
49
67
  /**
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.
68
+ * Represents a client's WebSocket connection to an actor session.
69
+ *
70
+ * {@link ActorRef.connect} returns this object while the socket connects.
71
+ * The socket buffers messages sent during connection setup until it opens.
53
72
  */
54
73
  export interface Connection<N extends string = string> {
55
- /** The connection id (the value the actor sees as `conn.id`). */
74
+ /** Connection ID that the actor receives as `conn.id`. */
56
75
  readonly id: string;
57
- /** Register a message listener. Multiple are allowed; returns a per-listener unsubscribe. */
76
+ /**
77
+ * Registers a listener for outgoing messages from the actor.
78
+ *
79
+ * You can register multiple listeners on the same connection.
80
+ *
81
+ * @param callback - Called with each outgoing message sent to this connection.
82
+ * @returns A handle you can use to remove this listener without closing the socket.
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * const conn = base44.actors.Chat("session-1").connect();
87
+ * const sub = conn.subscribe((msg) => {
88
+ * if (msg.type === "message") console.log(msg.text);
89
+ * });
90
+ * ```
91
+ */
58
92
  subscribe(callback: (data: ToClientFor<N>) => void): ActorSubscription;
59
- /** Send a message. Buffered by the socket until it's open; dropped after
60
- * {@link close}. */
93
+ /**
94
+ * Sends an incoming message to the actor.
95
+ *
96
+ * The socket buffers messages until it opens. After {@link close}, the socket
97
+ * drops further sends.
98
+ *
99
+ * @param data - Incoming message to send. Typed through {@link ActorRegistry} when configured.
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * conn.send({ type: "message", text: "Hello" });
104
+ * ```
105
+ */
61
106
  send(data: ToServerFor<N>): void;
62
107
  /**
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}.
108
+ * Closes the connection and removes all listeners.
109
+ *
110
+ * Safe to call more than once. A connection also closes itself when it fails
111
+ * permanently. See {@link ActorRef.connect} for how to open a fresh connection.
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * conn.close();
116
+ * ```
66
117
  */
67
118
  close(): void;
68
119
  }
69
120
  /**
70
- * A handle to one actor instance — `base44.actors.MyActor(id)`. Call
71
- * {@link connect} to open the socket and get a {@link Connection}.
121
+ * Represents an actor session selected by actor name and session ID.
122
+ *
123
+ * Call {@link connect} to open the WebSocket and get a {@link Connection}.
72
124
  */
73
125
  export interface ActorRef<N extends string = string> {
74
126
  /**
75
- * Open the WebSocket and return the {@link Connection}. Idempotent while the
76
- * connection is open.
127
+ * Creates or returns the {@link Connection} for this session.
128
+ *
129
+ * Repeated calls return the same connection until it closes. After a permanent
130
+ * failure, such as a missing actor or denied connection, fix the cause and call
131
+ * `connect()` again. Add subscriptions to the new connection.
77
132
  *
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.
133
+ * @param options - Optional connection settings, such as a stable connection ID.
134
+ * @returns The {@link Connection} for this actor session.
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * const conn = base44.actors.Chat("session-1").connect({ id: "tab-abc" });
139
+ * conn.subscribe((msg) => console.log(msg));
140
+ * ```
82
141
  */
83
142
  connect(options?: ActorConnectOptions): Connection<N>;
84
143
  }
85
144
  /**
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}.
145
+ * Selects a session for a named actor.
146
+ *
147
+ * Typed automatically when the actor is registered in {@link ActorRegistry} or
148
+ * {@link ActorNameRegistry}.
89
149
  */
90
150
  export interface ActorClient<N extends string = string> {
151
+ /**
152
+ * Gets a reference to an actor session.
153
+ *
154
+ * Clients that specify the same actor name and session ID join the same session.
155
+ *
156
+ * @param instanceId - Session ID that identifies which session to connect to.
157
+ * @returns A reference to the actor session.
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * const session = base44.actors.Chat("lobby-1");
162
+ * const conn = session.connect();
163
+ * ```
164
+ */
91
165
  (instanceId: string): ActorRef<N>;
92
166
  }
93
167
  /**
94
- * The actors module provides access to Cloudflare Durable Object-backed
95
- * Actors deployed by the Base44 platform.
168
+ * Provides access to actors and their shared, live sessions.
169
+ *
170
+ * Select an actor by name and session ID, then connect a client to the
171
+ * session. Clients in the same session can exchange realtime messages through the
172
+ * actor. The client works in the browser and in Node.
173
+ *
174
+ * ## Connection flow
175
+ *
176
+ * - Connect to a session with `base44.actors.<ActorName>(sessionId).connect()`.
177
+ * - Subscribe to outgoing messages with {@link Connection.subscribe}.
178
+ * - Send incoming messages with {@link Connection.send}.
179
+ * - Close the connection with {@link Connection.close}.
96
180
  *
181
+ * See [Actors Overview](/developers/backend/resources/actors/overview)
182
+ * for actor concepts and terminology, and the [Actor Class Reference](/developers/backend/resources/actors/reference)
183
+ * for the backend class API.
184
+ *
185
+ * ## Authentication modes
186
+ *
187
+ * This module is available in anonymous or user authentication mode
188
+ * (`base44.actors`). It isn't available with service role authentication. Apps that
189
+ * require login can reject anonymous connections in the actor's `handleConnect()` method.
190
+ *
191
+ * @example
97
192
  * ```typescript
98
- * const conn = base44.actors.MyActor("room-1").connect();
99
- * const sub = conn.subscribe((msg) => console.log(msg)); // typed via ActorRegistry
193
+ * const conn = base44.actors.Chat("session-1").connect({ id: "tab-1" });
194
+ * const sub = conn.subscribe((msg) => console.log(msg));
100
195
  * conn.send({ type: "message", text: "hi" });
101
196
  * sub.unsubscribe();
102
197
  * conn.close();
@@ -1,19 +1,11 @@
1
1
  import { getAccessToken } from "../utils/auth-utils.js";
2
- const PROVIDER_PATHS = {
3
- openai: "openai",
4
- typesafe: "typesafe",
5
- };
6
2
  export function createAiGatewayModule({ serverUrl, token, appId, }) {
7
- const connection = ({ provider = "openai" } = {}) => {
3
+ const connection = () => {
8
4
  var _a;
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`,
5
+ return ({
6
+ baseURL: `${serverUrl}/api/apps/${appId}/ai/openai/v1`,
15
7
  token: (_a = token !== null && token !== void 0 ? token : getAccessToken()) !== null && _a !== void 0 ? _a : "",
16
- };
8
+ });
17
9
  };
18
10
  return {
19
11
  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 selected gateway provider. */
5
+ /** Base URL of the gateway's OpenAI-compatible Chat Completions endpoint. */
6
6
  baseURL: string;
7
7
  /**
8
8
  * Bearer token that authenticates the request. Empty string when the caller is
@@ -10,11 +10,6 @@ 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
- }
18
13
  /**
19
14
  * Configuration for the AI Gateway module.
20
15
  * @internal
@@ -31,10 +26,13 @@ export interface AiGatewayModuleConfig {
31
26
  * AI Gateway module for calling Base44's managed AI models from your own code.
32
27
  *
33
28
  * `connection()` hands you a `baseURL` and `token` that authenticate as your
34
- * Base44 app. It defaults to the OpenAI-compatible Chat Completions provider;
35
- * pass `{ provider: "typesafe" }` for the TypeSafe evaluation provider. Pass
36
- * the returned values to the corresponding client with no separate provider
37
- * account, API key, or billing setup.
29
+ * Base44 app. An OpenAI-compatible client is any library, such as the `openai`
30
+ * SDK or the Vercel AI SDK, that has the same request and response format
31
+ * as OpenAI's Chat Completions API and lets you point it at a custom `baseURL`
32
+ * instead of OpenAI's own servers. Pass `connection()`'s values to one of
33
+ * these clients and it works against Base44's gateway exactly as it would
34
+ * against the provider directly, no separate account, API key, or billing
35
+ * setup with the underlying model provider required.
38
36
  *
39
37
  * Call `connection()` from a backend function rather than the browser. This
40
38
  * keeps your instructions, tools, and business logic server-side, and lets
@@ -42,13 +40,7 @@ export interface AiGatewayModuleConfig {
42
40
  * `token` it returns is the caller's regular session token, the same one
43
41
  * used for every other SDK call.
44
42
  *
45
- * ## Providers
46
- *
47
- * - **OpenAI-compatible** (default): Works with clients such as the `openai`
48
- * SDK or Vercel AI SDK clients that accept a custom `baseURL`.
49
- * - **TypeSafe**: Works with `@ai-sdk/typesafe-ai` for structured evaluations.
50
- *
51
- * ## OpenAI-compatible models
43
+ * ## Models
52
44
  *
53
45
  * You can use any of the [models available through `InvokeLLM`](/developers/references/sdk/docs/type-aliases/integrations#invokellm).
54
46
  * Pass `'automatic'` to let Base44 choose one, or pin a specific model such
@@ -77,15 +69,13 @@ export interface AiGatewayModule {
77
69
  /**
78
70
  * Gets the connection details for the Base44 AI Gateway.
79
71
  *
80
- * Returns the `baseURL` and `token` to pass to the selected provider client.
81
- *
82
- * @param options - Provider selection. Omit it to use the OpenAI-compatible gateway.
72
+ * Returns the `baseURL` and `token` to pass to any OpenAI-compatible client.
83
73
  *
84
74
  * @returns The gateway {@linkcode AiGatewayConnection | connection} (`baseURL` and `token`).
85
75
  *
86
76
  * @example
87
77
  * ```typescript
88
- * // Call an OpenAI-compatible model directly
78
+ * // Call a model directly
89
79
  * import { createClientFromRequest } from "@base44/sdk";
90
80
  * import OpenAI from "openai";
91
81
  *
@@ -145,5 +135,5 @@ export interface AiGatewayModule {
145
135
  * await agent.generate({ prompt: `Review this return request: ${JSON.stringify(returnRequest)}` });
146
136
  * ```
147
137
  */
148
- connection(options?: AiGatewayConnectionOptions): AiGatewayConnection;
138
+ connection(): AiGatewayConnection;
149
139
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.48-pr.288.6247e7c",
3
+ "version": "0.8.48-pr.289.b9ea964",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",