@depup/base44__sdk 0.8.40-depup.0 → 0.8.41-depup.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,15 +13,17 @@ npm install @depup/base44__sdk
13
13
 
14
14
  | Field | Value |
15
15
  |-------|-------|
16
- | Original | [@base44/sdk](https://www.npmjs.com/package/@base44/sdk) @ 0.8.40 |
17
- | Processed | 2026-07-21 |
16
+ | Original | [@base44/sdk](https://www.npmjs.com/package/@base44/sdk) @ 0.8.41 |
17
+ | Processed | 2026-07-30 |
18
18
  | Smoke test | passed |
19
- | Deps updated | 1 |
19
+ | Deps updated | 3 |
20
20
 
21
21
  ## Dependency Changes
22
22
 
23
23
  | Dependency | From | To |
24
24
  |------------|------|-----|
25
+ | axios | ^1.18.1 | ^1.19.0 |
26
+ | partysocket | ^0.0.23 | ^1.3.0 |
25
27
  | uuid | ^13.0.2 | ^14.0.1 |
26
28
 
27
29
  ---
package/changes.json CHANGED
@@ -1,10 +1,18 @@
1
1
  {
2
2
  "bumped": {
3
+ "axios": {
4
+ "from": "^1.18.1",
5
+ "to": "^1.19.0"
6
+ },
7
+ "partysocket": {
8
+ "from": "^0.0.23",
9
+ "to": "^1.3.0"
10
+ },
3
11
  "uuid": {
4
12
  "from": "^13.0.2",
5
13
  "to": "^14.0.1"
6
14
  }
7
15
  },
8
- "timestamp": "2026-07-21T16:02:37.704Z",
9
- "totalUpdated": 1
16
+ "timestamp": "2026-07-30T00:36:38.307Z",
17
+ "totalUpdated": 3
10
18
  }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Type-only base class for Actors.
3
+ *
4
+ * Import and extend this in your actor files:
5
+ * import { Actor } from "@base44/sdk";
6
+ * export class MyActor extends Actor { ... }
7
+ *
8
+ * At deploy time the bundler replaces this import with the compiled
9
+ * Cloudflare Durable Object implementation — this file provides types only.
10
+ */
11
+ import type { Base44Client } from "./client";
12
+ /**
13
+ * A single client connection. `Send` is the message type this connection accepts
14
+ * via {@link send} — the actor's *outgoing* (server→client) messages.
15
+ */
16
+ export interface Conn<Send = unknown> {
17
+ /** Unique per-connection id (one per socket/tab), the same value the client
18
+ * receives from `subscribe()`. Use this — not userId — to identify a distinct
19
+ * client, so multiple tabs of the same user are separate connections. */
20
+ id: string;
21
+ userId: string;
22
+ appId: string;
23
+ instanceId: string;
24
+ send(data: Send): void;
25
+ reject(code: number, reason: string): void;
26
+ }
27
+ export interface Storage {
28
+ get<T>(key: string): Promise<T | undefined>;
29
+ put(key: string, value: unknown): Promise<void>;
30
+ delete(key: string): Promise<boolean>;
31
+ /** Wipe the room's entire persisted storage (match-end cleanup). Safe: a
32
+ * later rejoin re-bootstraps exactly like a brand-new room. */
33
+ deleteAll(): Promise<void>;
34
+ }
35
+ /**
36
+ * Base class for an Actor.
37
+ *
38
+ * @typeParam Incoming - messages this actor *receives* from clients
39
+ * (`handleMessage`'s `msg`) — the schema's `toServer` section.
40
+ * @typeParam Outgoing - messages this actor *sends* to clients
41
+ * (`conn.send`/`broadcast`) — the schema's `toClient` section.
42
+ *
43
+ * With a generated `schema.jsonc`, wire both from the registry so they can't drift
44
+ * from the client's types:
45
+ * ```ts
46
+ * type Reg = ActorRegistry["MyActor"];
47
+ * class MyActor extends Actor<Reg["toServer"], Reg["toClient"]> { ... }
48
+ * ```
49
+ */
50
+ export declare abstract class Actor<Incoming = unknown, Outgoing = unknown> {
51
+ abstract handleConnect(conn: Conn<Outgoing>): void | Promise<void>;
52
+ abstract handleMessage(conn: Conn<Outgoing>, msg: Incoming): void | Promise<void>;
53
+ abstract handleClose(conn: Conn<Outgoing>): void | Promise<void>;
54
+ abstract handleTick(): void | Promise<void>;
55
+ /**
56
+ * Optional wake hook: runs once when the instance starts, before any
57
+ * connection is handled — safe to load persisted state here.
58
+ */
59
+ handleStart(): void | Promise<void>;
60
+ /**
61
+ * Managed ticker (opt-in). Override {@link shouldTick} and the platform runs
62
+ * {@link handleTick} on a timer of {@link tickIntervalMs} while it returns true,
63
+ * and stops (letting the Durable Object hibernate — no compute cost) when it
64
+ * returns false. The platform owns scheduling, rescheduling, self-heal, and
65
+ * error-safety — you don't call {@link startLoop}/{@link stopLoop}.
66
+ *
67
+ * Re-evaluated after every connect/message/close and on every tick, so keep it
68
+ * cheap and pure (no async, no side effects). Example: `return this.players >= 2`.
69
+ */
70
+ protected tickIntervalMs: number;
71
+ protected shouldTick?(): boolean;
72
+ protected broadcast(_data: Outgoing): void;
73
+ protected getConnections(): Conn<Outgoing>[];
74
+ protected startLoop(_ms: number): Promise<void>;
75
+ protected stopLoop(): Promise<void>;
76
+ protected get instanceId(): string;
77
+ protected get storage(): Storage;
78
+ /**
79
+ * Anonymous Base44 client scoped to this actor instance — no user or service
80
+ * auth, so entity access is RLS-gated (same as a logged-out visitor). Always
81
+ * operates on production data: an actor runs server-side with no per-connection
82
+ * identity, so a Test DB preview selected in the editor does not apply here.
83
+ * Example: `const rows = await this.client.entities.Score.list();`
84
+ */
85
+ protected get client(): Base44Client;
86
+ }
package/dist/actor.js ADDED
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Type-only base class for Actors.
3
+ *
4
+ * Import and extend this in your actor files:
5
+ * import { Actor } from "@base44/sdk";
6
+ * export class MyActor extends Actor { ... }
7
+ *
8
+ * At deploy time the bundler replaces this import with the compiled
9
+ * Cloudflare Durable Object implementation — this file provides types only.
10
+ */
11
+ /**
12
+ * Base class for an Actor.
13
+ *
14
+ * @typeParam Incoming - messages this actor *receives* from clients
15
+ * (`handleMessage`'s `msg`) — the schema's `toServer` section.
16
+ * @typeParam Outgoing - messages this actor *sends* to clients
17
+ * (`conn.send`/`broadcast`) — the schema's `toClient` section.
18
+ *
19
+ * With a generated `schema.jsonc`, wire both from the registry so they can't drift
20
+ * from the client's types:
21
+ * ```ts
22
+ * type Reg = ActorRegistry["MyActor"];
23
+ * class MyActor extends Actor<Reg["toServer"], Reg["toClient"]> { ... }
24
+ * ```
25
+ */
26
+ export class Actor {
27
+ constructor() {
28
+ /**
29
+ * Managed ticker (opt-in). Override {@link shouldTick} and the platform runs
30
+ * {@link handleTick} on a timer of {@link tickIntervalMs} while it returns true,
31
+ * and stops (letting the Durable Object hibernate — no compute cost) when it
32
+ * returns false. The platform owns scheduling, rescheduling, self-heal, and
33
+ * error-safety — you don't call {@link startLoop}/{@link stopLoop}.
34
+ *
35
+ * Re-evaluated after every connect/message/close and on every tick, so keep it
36
+ * cheap and pure (no async, no side effects). Example: `return this.players >= 2`.
37
+ */
38
+ this.tickIntervalMs = 100;
39
+ }
40
+ /**
41
+ * Optional wake hook: runs once when the instance starts, before any
42
+ * connection is handled — safe to load persisted state here.
43
+ */
44
+ handleStart() { }
45
+ broadcast(_data) {
46
+ throw new Error("Actor.broadcast() is only available inside a deployed actor");
47
+ }
48
+ getConnections() {
49
+ throw new Error("Actor.getConnections() is only available inside a deployed actor");
50
+ }
51
+ startLoop(_ms) {
52
+ throw new Error("Actor.startLoop() is only available inside a deployed actor");
53
+ }
54
+ stopLoop() {
55
+ throw new Error("Actor.stopLoop() is only available inside a deployed actor");
56
+ }
57
+ get instanceId() {
58
+ throw new Error("Actor.instanceId is only available inside a deployed actor");
59
+ }
60
+ get storage() {
61
+ throw new Error("Actor.storage is only available inside a deployed actor");
62
+ }
63
+ /**
64
+ * Anonymous Base44 client scoped to this actor instance — no user or service
65
+ * auth, so entity access is RLS-gated (same as a logged-out visitor). Always
66
+ * operates on production data: an actor runs server-side with no per-connection
67
+ * identity, so a Test DB preview selected in the editor does not apply here.
68
+ * Example: `const rows = await this.client.entities.Score.list();`
69
+ */
70
+ get client() {
71
+ throw new Error("Actor.client is only available inside a deployed actor");
72
+ }
73
+ }
package/dist/client.js CHANGED
@@ -12,6 +12,7 @@ import { createAppLogsModule } from "./modules/app-logs.js";
12
12
  import { createUsersModule } from "./modules/users.js";
13
13
  import { RoomsSocket } from "./utils/socket-utils.js";
14
14
  import { createAnalyticsModule } from "./modules/analytics.js";
15
+ import { createActorsModule, resolveActorsHost } from "./modules/actors.js";
15
16
  /**
16
17
  * Creates a Base44 client.
17
18
  *
@@ -50,7 +51,7 @@ import { createAnalyticsModule } from "./modules/analytics.js";
50
51
  * ```
51
52
  */
52
53
  export function createClient(config) {
53
- var _a, _b;
54
+ var _a, _b, _c;
54
55
  const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
55
56
  // Normalize appBaseUrl to always be a string (empty if not provided or invalid)
56
57
  const normalizedAppBaseUrl = typeof appBaseUrl === "string" ? appBaseUrl : "";
@@ -123,6 +124,14 @@ export function createClient(config) {
123
124
  userAuthModule.setToken(accessToken);
124
125
  }
125
126
  }
127
+ const actorsModule = createActorsModule({
128
+ appId,
129
+ // serverUrl is often relative/empty (same-origin app); PartySocket needs an
130
+ // absolute host, so fall back to the page origin.
131
+ host: resolveActorsHost(serverUrl, typeof window !== "undefined" ? (_a = window.location) === null || _a === void 0 ? void 0 : _a.origin : undefined),
132
+ functionsVersion,
133
+ getAuthToken: () => token || getAccessToken(),
134
+ });
126
135
  const userModules = {
127
136
  entities: createEntitiesModule({
128
137
  axios: axiosClient,
@@ -142,7 +151,7 @@ export function createClient(config) {
142
151
  }
143
152
  return headers;
144
153
  },
145
- baseURL: (_a = functionsAxiosClient.defaults) === null || _a === void 0 ? void 0 : _a.baseURL,
154
+ baseURL: (_b = functionsAxiosClient.defaults) === null || _b === void 0 ? void 0 : _b.baseURL,
146
155
  }),
147
156
  agents: createAgentsModule({
148
157
  axios: axiosClient,
@@ -160,8 +169,10 @@ export function createClient(config) {
160
169
  appId,
161
170
  userAuthModule,
162
171
  }),
172
+ actors: actorsModule.module,
163
173
  cleanup: () => {
164
174
  userModules.analytics.cleanup();
175
+ actorsModule.closeAll();
165
176
  if (socket) {
166
177
  socket.disconnect();
167
178
  }
@@ -185,7 +196,7 @@ export function createClient(config) {
185
196
  }
186
197
  return headers;
187
198
  },
188
- baseURL: (_b = serviceRoleFunctionsAxiosClient.defaults) === null || _b === void 0 ? void 0 : _b.baseURL,
199
+ baseURL: (_c = serviceRoleFunctionsAxiosClient.defaults) === null || _c === void 0 ? void 0 : _c.baseURL,
189
200
  }),
190
201
  agents: createAgentsModule({
191
202
  axios: serviceRoleAxiosClient,
@@ -8,6 +8,7 @@ import type { AgentsModule } from "./modules/agents.types.js";
8
8
  import type { AiGatewayModule } from "./modules/ai-gateway.types.js";
9
9
  import type { AppLogsModule } from "./modules/app-logs.types.js";
10
10
  import type { AnalyticsModule } from "./modules/analytics.types.js";
11
+ import type { ActorsModule } from "./modules/actors.types.js";
11
12
  /**
12
13
  * Options for creating a Base44 client.
13
14
  */
@@ -88,6 +89,8 @@ export interface Base44Client {
88
89
  analytics: AnalyticsModule;
89
90
  /** {@link AppLogsModule | App logs module} for tracking app usage. */
90
91
  appLogs: AppLogsModule;
92
+ /** {@link ActorsModule | Actors module} for subscribing to and sending messages via Cloudflare Durable Object-backed Actors. */
93
+ actors: ActorsModule;
91
94
  /** {@link AuthModule | Auth module} for user authentication and management. */
92
95
  auth: AuthModule;
93
96
  /** {@link UserConnectorsModule | Connectors module} for app-user OAuth flows. */
@@ -139,9 +142,7 @@ export interface Base44Client {
139
142
  functions: FunctionsModule;
140
143
  /** {@link IntegrationsModule | Integrations module} with elevated permissions. */
141
144
  integrations: IntegrationsModule;
142
- /** {@link SsoModule | SSO module} for generating SSO tokens.
143
- * @internal
144
- */
145
+ /** {@link SsoModule | SSO module} for generating SSO tokens. */
145
146
  sso: SsoModule;
146
147
  /** Cleanup function to disconnect WebSocket connections. */
147
148
  cleanup: () => void;
package/dist/index.d.ts CHANGED
@@ -11,7 +11,9 @@ export type { FunctionsModule, FunctionName, FunctionNameRegistry, } from "./mod
11
11
  export type { AgentsModule, AgentName, AgentNameRegistry, AgentConversation, AgentMessage, AgentMessageReasoning, AgentMessageToolCall, AgentMessageUsage, AgentMessageCustomContext, AgentMessageMetadata, CreateConversationParams, } from "./modules/agents.types.js";
12
12
  export type { AiGatewayModule, AiGatewayConnection, } from "./modules/ai-gateway.types.js";
13
13
  export type { AppLogsModule } from "./modules/app-logs.types.js";
14
+ export type { ActorsModule, ActorClient, ActorRef, Connection, ActorSubscription, ActorConnectOptions, ActorNameRegistry, ActorRegistry, } from "./modules/actors.types.js";
14
15
  export type { SsoModule, SsoAccessTokenResponse } from "./modules/sso.types.js";
16
+ export { Actor, type Conn } from "./actor.js";
15
17
  export type { ConnectorsModule, UserConnectorsModule, } from "./modules/connectors.types.js";
16
18
  export type { CustomIntegrationsModule, CustomIntegrationCallParams, CustomIntegrationCallResponse, } from "./modules/custom-integrations.types.js";
17
19
  export type { GetAccessTokenOptions, SaveAccessTokenOptions, RemoveAccessTokenOptions, GetLoginUrlOptions, } from "./utils/auth-utils.types.js";
package/dist/index.js CHANGED
@@ -3,3 +3,4 @@ import { Base44Error } from "./utils/axios-client.js";
3
3
  import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, } from "./utils/auth-utils.js";
4
4
  export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
5
5
  export * from "./types.js";
6
+ export { Actor } from "./actor.js";
@@ -0,0 +1,25 @@
1
+ import type { ActorRef } from "./actors.types.js";
2
+ interface ActorsConfig {
3
+ appId: string;
4
+ /** Current user access token, if authenticated. Rides the WS query so the
5
+ * platform proxy can authenticate the connection; anonymous connects omit it. */
6
+ getAuthToken(): string | null | undefined;
7
+ /** Same semantics as function calls: editors with a non-prod version get the
8
+ * draft actor script; everyone else gets the published one. */
9
+ functionsVersion?: string;
10
+ /** Absolute host PartySocket dials (it strips the scheme and connects wss, ws
11
+ * for localhost). Resolved by {@link resolveActorsHost}. */
12
+ host: string;
13
+ }
14
+ /**
15
+ * Absolute host for the actor WebSocket. PartySocket needs an absolute host and
16
+ * can't resolve a relative/empty `serverUrl` (same-origin apps use a relative
17
+ * `/api`, so `serverUrl` is often `""`), so fall back to the page origin.
18
+ * PartySocket handles the scheme (https→wss, ws for localhost).
19
+ */
20
+ export declare function resolveActorsHost(serverUrl: string, browserOrigin?: string): string;
21
+ export declare function createActorsModule(config: ActorsConfig): {
22
+ module: Record<string, (instanceId: string) => ActorRef>;
23
+ closeAll: () => void;
24
+ };
25
+ export {};
@@ -0,0 +1,135 @@
1
+ import PartySocket from "partysocket";
2
+ // Heartbeat / half-open detection: PartySocket only reconnects on a close/error
3
+ // event, so ping periodically and force a reconnect if nothing returns in DEAD_MS.
4
+ const PING_MS = 1000;
5
+ const DEAD_MS = 3000;
6
+ /**
7
+ * A live connection to an actor instance. Only obtainable from
8
+ * {@link ActorRef.connect}, so `subscribe`/`send` are always valid — the socket
9
+ * exists for this object's whole lifetime.
10
+ */
11
+ class Connection {
12
+ constructor(actorName, instanceId, config, options, onClose) {
13
+ var _a;
14
+ this.onClose = onClose;
15
+ this.listeners = new Set();
16
+ this.heartbeat = null;
17
+ this.id = (_a = options === null || options === void 0 ? void 0 : options.id) !== null && _a !== void 0 ? _a : crypto.randomUUID();
18
+ const ws = new PartySocket({
19
+ host: config.host,
20
+ party: actorName,
21
+ room: instanceId,
22
+ id: this.id,
23
+ // Re-read on every (re)connect so a login/logout is picked up.
24
+ query: () => {
25
+ const token = config.getAuthToken();
26
+ return {
27
+ app_id: config.appId,
28
+ handler: actorName,
29
+ ...(token ? { token } : {}),
30
+ ...(config.functionsVersion ? { fv: config.functionsVersion } : {}),
31
+ };
32
+ },
33
+ });
34
+ this.ws = ws;
35
+ let lastMsg = Date.now();
36
+ const bumpAlive = () => { lastMsg = Date.now(); };
37
+ ws.addEventListener("open", bumpAlive);
38
+ ws.addEventListener("message", (ev) => {
39
+ bumpAlive();
40
+ let data;
41
+ try {
42
+ data = JSON.parse(ev.data);
43
+ }
44
+ catch (_a) {
45
+ return;
46
+ }
47
+ const msgType = data && typeof data === "object" ? data.type : undefined;
48
+ if (msgType === "__pong")
49
+ return;
50
+ for (const listener of this.listeners)
51
+ listener(data);
52
+ });
53
+ this.heartbeat = setInterval(() => {
54
+ if (Date.now() - lastMsg > DEAD_MS) {
55
+ bumpAlive(); // avoid a reconnect storm while the new socket comes up
56
+ ws.reconnect();
57
+ return;
58
+ }
59
+ try {
60
+ // The deployed shim echoes __ping → __pong (base44-userapp-bundler
61
+ // shim/actor.ts); without that, an idle room reconnects every DEAD_MS.
62
+ ws.send(JSON.stringify({ type: "__ping" }));
63
+ }
64
+ catch (_a) {
65
+ // not open; the watchdog above will reconnect
66
+ }
67
+ }, PING_MS);
68
+ }
69
+ subscribe(callback) {
70
+ this.listeners.add(callback);
71
+ return {
72
+ unsubscribe: () => { this.listeners.delete(callback); },
73
+ };
74
+ }
75
+ send(data) {
76
+ this.ws.send(JSON.stringify(data));
77
+ }
78
+ close() {
79
+ if (this.heartbeat) {
80
+ clearInterval(this.heartbeat);
81
+ this.heartbeat = null;
82
+ }
83
+ this.listeners.clear();
84
+ this.ws.close();
85
+ this.onClose();
86
+ }
87
+ }
88
+ /** Handle for one actor instance: `connect()` opens the socket (idempotent). */
89
+ function makeActorRef(actorName, instanceId, config, connections) {
90
+ let conn = null;
91
+ return {
92
+ connect(options) {
93
+ if (conn)
94
+ return conn;
95
+ const c = new Connection(actorName, instanceId, config, options, () => {
96
+ connections.delete(c);
97
+ if (conn === c)
98
+ conn = null; // allow a fresh connect() after close
99
+ });
100
+ conn = c;
101
+ connections.add(c);
102
+ return c;
103
+ },
104
+ };
105
+ }
106
+ /**
107
+ * Absolute host for the actor WebSocket. PartySocket needs an absolute host and
108
+ * can't resolve a relative/empty `serverUrl` (same-origin apps use a relative
109
+ * `/api`, so `serverUrl` is often `""`), so fall back to the page origin.
110
+ * PartySocket handles the scheme (https→wss, ws for localhost).
111
+ */
112
+ export function resolveActorsHost(serverUrl, browserOrigin) {
113
+ return serverUrl && !serverUrl.startsWith("/") ? serverUrl : browserOrigin !== null && browserOrigin !== void 0 ? browserOrigin : serverUrl;
114
+ }
115
+ export function createActorsModule(config) {
116
+ // Live connections this client opened, so client.cleanup() can reclaim any the
117
+ // app forgot to close() (each connection removes itself here on close).
118
+ const connections = new Set();
119
+ const module = new Proxy({}, {
120
+ get(_, key) {
121
+ // Symbols and `then` resolve to undefined (so the module isn't mistaken
122
+ // for a thenable when awaited); any string key is an actor name.
123
+ if (typeof key !== "string" || key === "then")
124
+ return undefined;
125
+ return (instanceId) => makeActorRef(key, instanceId, config, connections);
126
+ },
127
+ });
128
+ return {
129
+ module,
130
+ closeAll: () => {
131
+ for (const c of [...connections])
132
+ c.close();
133
+ },
134
+ };
135
+ }
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Extend this interface to add typed `subscribe` callbacks and `send` payloads
3
+ * for your deployed Actors.
4
+ *
5
+ * This is separate from {@link ActorNameRegistry} (which is auto-generated
6
+ * by `base44 types generate`), so there are no conflicts.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * declare module "@base44/sdk" {
11
+ * interface ActorRegistry {
12
+ * ChatRoom: {
13
+ * toClient: { type: "joined" | "left" | "message"; userId?: string; from?: string; text?: string };
14
+ * toServer: { type: "message"; text: string };
15
+ * };
16
+ * }
17
+ * }
18
+ * ```
19
+ */
20
+ export interface ActorRegistry {
21
+ }
22
+ /**
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.
25
+ */
26
+ export interface ActorNameRegistry {
27
+ }
28
+ type AllActorNames = keyof ActorRegistry | keyof ActorNameRegistry;
29
+ type ToClientFor<N extends string> = N extends keyof ActorRegistry ? ActorRegistry[N] extends {
30
+ toClient: infer I;
31
+ } ? I : unknown : unknown;
32
+ type ToServerFor<N extends string> = N extends keyof ActorRegistry ? ActorRegistry[N] extends {
33
+ toServer: infer O;
34
+ } ? O : unknown : unknown;
35
+ /** Options for {@link ActorRef.connect}. */
36
+ export interface ActorConnectOptions {
37
+ /**
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.
41
+ */
42
+ id?: string;
43
+ }
44
+ /** Handle for one listener registered via {@link Connection.subscribe}. */
45
+ export interface ActorSubscription {
46
+ /** Remove this listener; other listeners and the socket stay live. */
47
+ unsubscribe(): void;
48
+ }
49
+ /**
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.
53
+ */
54
+ export interface Connection<N extends string = string> {
55
+ /** The connection id (the value the actor sees as `conn.id`). */
56
+ readonly id: string;
57
+ /** Register a message listener. Multiple are allowed; returns a per-listener unsubscribe. */
58
+ subscribe(callback: (data: ToClientFor<N>) => void): ActorSubscription;
59
+ /** Send a message. Buffered by the socket until it's open. */
60
+ send(data: ToServerFor<N>): void;
61
+ /** Tear down the socket, heartbeat, and all listeners. */
62
+ close(): void;
63
+ }
64
+ /**
65
+ * A handle to one actor instance — `base44.actors.MyActor(id)`. Call
66
+ * {@link connect} to open the socket and get a {@link Connection}.
67
+ */
68
+ export interface ActorRef<N extends string = string> {
69
+ /** Open the WebSocket and return the {@link Connection}. Idempotent. */
70
+ connect(options?: ActorConnectOptions): Connection<N>;
71
+ }
72
+ /**
73
+ * Client for a single named Actor — call it with an instance id to get an
74
+ * {@link ActorRef}. Typed automatically when the actor is registered in
75
+ * {@link ActorRegistry}.
76
+ */
77
+ export interface ActorClient<N extends string = string> {
78
+ (instanceId: string): ActorRef<N>;
79
+ }
80
+ /**
81
+ * The actors module provides access to Cloudflare Durable Object-backed
82
+ * Actors deployed by the Base44 platform.
83
+ *
84
+ * ```typescript
85
+ * const conn = base44.actors.MyActor("room-1").connect();
86
+ * const sub = conn.subscribe((msg) => console.log(msg)); // typed via ActorRegistry
87
+ * conn.send({ type: "message", text: "hi" });
88
+ * sub.unsubscribe();
89
+ * conn.close();
90
+ * ```
91
+ */
92
+ export type ActorsModule = {
93
+ [K in AllActorNames]: K extends keyof ActorRegistry ? ActorClient<string & K> : ActorClient;
94
+ } & Record<string, ActorClient>;
95
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,13 +1,13 @@
1
1
  /**
2
- * A connection to the Base44 AI Gateway.
3
- *
4
- * Contains the base URL and bearer token to use with any OpenAI-compatible
5
- * client pointed at the Base44 AI Gateway.
2
+ * Connection details for the Base44 AI Gateway.
6
3
  */
7
4
  export interface AiGatewayConnection {
8
- /** Base URL of the gateway's OpenAI-compatible endpoint. */
5
+ /** Base URL of the gateway's OpenAI-compatible Chat Completions endpoint. */
9
6
  baseURL: string;
10
- /** Bearer token used to authenticate requests to the gateway. */
7
+ /**
8
+ * Bearer token that authenticates the request. Empty string when the caller is
9
+ * unauthenticated.
10
+ */
11
11
  token: string;
12
12
  }
13
13
  /**
@@ -25,13 +25,45 @@ export interface AiGatewayModuleConfig {
25
25
  /**
26
26
  * AI Gateway module for calling Base44's managed AI models from your own code.
27
27
  *
28
- * The gateway exposes an OpenAI-compatible Chat Completions endpoint, so any
29
- * OpenAI-compatible SDK works against it:
30
- * - Build custom AI agents or call models directly from your backend code
31
- * - Uses your app's models, billing, and credit quota, no API key to manage
28
+ * `connection()` hands you a `baseURL` and `token` that authenticate as your
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.
36
+ *
37
+ * Call `connection()` from a backend function rather than the browser. This
38
+ * keeps your instructions, tools, and business logic server-side, and lets
39
+ * you enforce your own auth, rate, and spend limits around the call. The
40
+ * `token` it returns is the caller's regular session token, the same one
41
+ * used for every other SDK call.
42
+ *
43
+ * ## Models
44
+ *
45
+ * You can use any of the [models available through `InvokeLLM`](/developers/references/sdk/docs/type-aliases/integrations#invokellm).
46
+ * Pass `'automatic'` to let Base44 choose one, or pin a specific model such
47
+ * as `'claude_sonnet_4_6'`, `'gpt_5_5'`, or `'gemini_3_1_pro'`.
48
+ *
49
+ * ## Authentication Modes
50
+ *
51
+ * There's no permission difference between modes. Both just determine which
52
+ * token `connection()` returns:
53
+ *
54
+ * - **User authentication** (`base44.aiGateway`): Returns the signed-in app user's token.
55
+ * - **Service role authentication** (`base44.asServiceRole.aiGateway`): Returns the service-role token instead, for calling the gateway when there's no signed-in user, such as from a scheduled automation.
56
+ *
57
+ * ## Billing and limits
58
+ *
59
+ * Requests are billed to your app's credit quota, which is the same shared
60
+ * quota your app's built-in AI features use, and isn't split per user. If the
61
+ * app runs out of credits, the gateway stops working for every user of the
62
+ * app until the quota resets. A request is rejected before the model runs if
63
+ * the app is out of credits. If you need to cap usage per user, build that
64
+ * check yourself, for example by tracking calls per user in your own entity.
32
65
  *
33
- * Available in user authentication mode (`base44.aiGateway`) and with the
34
- * service-role token via `base44.asServiceRole.aiGateway`.
66
+ * Streaming responses aren't supported yet, so leave `stream` unset on your requests.
35
67
  */
36
68
  export interface AiGatewayModule {
37
69
  /**
@@ -39,19 +71,38 @@ export interface AiGatewayModule {
39
71
  *
40
72
  * Returns the `baseURL` and `token` to pass to any OpenAI-compatible client.
41
73
  *
42
- * The `token` is the current caller's bearer token: the app user's token for
43
- * `base44.aiGateway`, or the service-role token for `base44.asServiceRole.aiGateway`.
44
- * When the caller is unauthenticated, `token` is an empty string.
45
- *
46
74
  * @returns The gateway {@linkcode AiGatewayConnection | connection} (`baseURL` and `token`).
47
75
  *
48
76
  * @example
49
77
  * ```typescript
78
+ * // Call a model directly
79
+ * import { createClientFromRequest } from "@base44/sdk";
80
+ * import OpenAI from "openai";
81
+ *
82
+ * // Runs inside a backend function
83
+ * const base44 = createClientFromRequest(request);
84
+ * const { baseURL, token } = base44.aiGateway.connection();
85
+ * const openai = new OpenAI({ baseURL, apiKey: token });
86
+ *
87
+ * const response = await openai.chat.completions.create({
88
+ * model: "automatic",
89
+ * messages: [{ role: "user", content: "Summarize this week's top support tickets." }],
90
+ * });
91
+ *
92
+ * console.log(response.choices[0].message.content);
93
+ * ```
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * // Use a tool-calling agent
98
+ * import { createClientFromRequest } from "@base44/sdk";
50
99
  * import { ToolLoopAgent, tool, stepCountIs, hasToolCall } from "ai";
51
100
  * import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
52
101
  * import { z } from "zod";
53
102
  *
54
- * const request = await base44.entities.ReturnRequest.get(returnId);
103
+ * // Runs inside a backend function, reviewing a return request
104
+ * const base44 = createClientFromRequest(request);
105
+ * const returnRequest = await base44.entities.ReturnRequest.get(returnId);
55
106
  * const { baseURL, token } = base44.aiGateway.connection();
56
107
  * // Point any OpenAI-compatible client at `baseURL` with `apiKey: token`.
57
108
  * const models = createOpenAICompatible({ name: "base44", baseURL, apiKey: token });
@@ -66,7 +117,7 @@ export interface AiGatewayModule {
66
117
  * description: "This customer's past orders, optionally filtered by status",
67
118
  * inputSchema: z.object({ status: z.string().optional() }),
68
119
  * execute: ({ status }) => {
69
- * const query = { customer_email: request.customer_email };
120
+ * const query = { customer_email: returnRequest.customer_email };
70
121
  * if (status) query.status = status;
71
122
  * return base44.entities.Order.filter(query, "-created_date", 50);
72
123
  * },
@@ -81,7 +132,7 @@ export interface AiGatewayModule {
81
132
  * stopWhen: [stepCountIs(8), hasToolCall("submitVerdict")],
82
133
  * });
83
134
  *
84
- * await agent.generate({ prompt: `Review this return request: ${JSON.stringify(request)}` });
135
+ * await agent.generate({ prompt: `Review this return request: ${JSON.stringify(returnRequest)}` });
85
136
  * ```
86
137
  */
87
138
  connection(): AiGatewayConnection;
@@ -1,6 +1,5 @@
1
1
  /**
2
2
  * Response from SSO access token endpoint.
3
- * @internal
4
3
  */
5
4
  export interface SsoAccessTokenResponse {
6
5
  access_token: string;
@@ -13,46 +12,53 @@ export interface SsoAccessTokenResponse {
13
12
  * services.
14
13
  *
15
14
  * This module is only available to use with a client in service role authentication mode, which means it can only be used in backend environments.
16
- *
17
- * @internal
18
- *
19
- * @example
20
- * ```typescript
21
- * // Access SSO module with service role
22
- * const response = await base44.asServiceRole.sso.getAccessToken('user_123');
23
- * console.log(response.data.access_token);
24
- * ```
25
15
  */
26
16
  export interface SsoModule {
27
17
  /**
28
- * Gets SSO access token for a specific user.
18
+ * Gets an SSO access token for the user who made the current request.
29
19
  *
30
- * Retrieves a Single Sign-On access token that can be used to authenticate
31
- * a user with external services or systems.
20
+ * Use this token to authenticate the user with external systems or services.
21
+ * This only works for that same user. Create the client with
22
+ * {@link createClientFromRequest} so it acts on behalf of the request's user,
23
+ * then pass that user's ID as `userid`. If `userid` is any other user, the
24
+ * call fails. An expired token is refreshed automatically when a refresh token
25
+ * is available.
32
26
  *
33
- * @param userid - The user ID to get the access token for.
27
+ * @param userid - The ID of the user who made the current request, such as the
28
+ * `id` returned by {@link AuthModule | base44.auth.me()}.
34
29
  * @returns Promise resolving to the SSO access token response.
35
30
  *
36
31
  * @example
37
32
  * ```typescript
38
- * // Get SSO access token for a user
39
- * const response = await base44.asServiceRole.sso.getAccessToken('user_123');
40
- * console.log(response.access_token);
33
+ * // Get the user's SSO access token to call an external system
34
+ * import { createClientFromRequest } from 'npm:@base44/sdk';
35
+ *
36
+ * Deno.serve(async (req) => {
37
+ * const base44 = createClientFromRequest(req);
38
+ * const user = await base44.auth.me();
39
+ * const { access_token } = await base44.asServiceRole.sso.getAccessToken(user.id);
40
+ *
41
+ * return Response.json({ access_token });
42
+ * });
41
43
  * ```
42
44
  */
43
45
  getAccessToken(userid: string): Promise<SsoAccessTokenResponse>;
44
46
  /**
45
- * Gets the stored SSO OIDC ID token for the current app user.
47
+ * Gets the stored SSO OIDC ID token for the user who made the current request.
46
48
  *
47
- * The service-role client must include an on-behalf-of token for the same
48
- * user specified by `userid`. This method returns the stored token as-is and
49
- * does not refresh it.
49
+ * This only works for that same user, not for arbitrary users. Create the
50
+ * client with {@link createClientFromRequest} so it acts on behalf of the
51
+ * request's user, then pass that user's ID as `userid`. If `userid` is any
52
+ * other user, the call fails. The stored token is returned as-is and is never
53
+ * refreshed, so the call fails if the token has already expired.
50
54
  *
51
- * @param userid - The current app user's ID.
55
+ * @param userid - The ID of the user who made the current request, such as the
56
+ * `id` returned by {@link AuthModule | base44.auth.me()}.
52
57
  * @returns Promise resolving to the raw ID-token string.
53
58
  *
54
59
  * @example
55
60
  * ```typescript
61
+ * // Get the user's ID token to read identity claims such as email
56
62
  * import { createClientFromRequest } from 'npm:@base44/sdk';
57
63
  *
58
64
  * Deno.serve(async (req) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@depup/base44__sdk",
3
- "version": "0.8.40-depup.0",
3
+ "version": "0.8.41-depup.1",
4
4
  "description": "JavaScript SDK for Base44 API (with updated dependencies)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -27,7 +27,8 @@
27
27
  "create-docs:process": "node scripts/mintlify-post-processing/file-processing/file-processing.js"
28
28
  },
29
29
  "dependencies": {
30
- "axios": "^1.18.1",
30
+ "axios": "^1.19.0",
31
+ "partysocket": "^1.3.0",
31
32
  "socket.io-client": "^4.8.3",
32
33
  "uuid": "^14.0.1"
33
34
  },
@@ -72,15 +73,23 @@
72
73
  "homepage": "https://github.com/base44/javascript-sdk#readme",
73
74
  "depup": {
74
75
  "changes": {
76
+ "axios": {
77
+ "from": "^1.18.1",
78
+ "to": "^1.19.0"
79
+ },
80
+ "partysocket": {
81
+ "from": "^0.0.23",
82
+ "to": "^1.3.0"
83
+ },
75
84
  "uuid": {
76
85
  "from": "^13.0.2",
77
86
  "to": "^14.0.1"
78
87
  }
79
88
  },
80
- "depsUpdated": 1,
89
+ "depsUpdated": 3,
81
90
  "originalPackage": "@base44/sdk",
82
- "originalVersion": "0.8.40",
83
- "processedAt": "2026-07-21T16:02:47.902Z",
91
+ "originalVersion": "0.8.41",
92
+ "processedAt": "2026-07-30T00:36:51.927Z",
84
93
  "smokeTest": "passed"
85
94
  }
86
95
  }