@base44-preview/sdk 0.8.35-pr.212.f5f8839 → 0.8.35-pr.214.3329626

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/client.js CHANGED
@@ -7,11 +7,11 @@ import { createConnectorsModule, createUserConnectorsModule, } from "./modules/c
7
7
  import { getAccessToken } from "./utils/auth-utils.js";
8
8
  import { createFunctionsModule } from "./modules/functions.js";
9
9
  import { createAgentsModule } from "./modules/agents.js";
10
+ import { createAiGatewayModule } from "./modules/ai-gateway.js";
10
11
  import { createAppLogsModule } from "./modules/app-logs.js";
11
12
  import { createUsersModule } from "./modules/users.js";
12
13
  import { RoomsSocket } from "./utils/socket-utils.js";
13
14
  import { createAnalyticsModule } from "./modules/analytics.js";
14
- import { createRealtimeModule } from "./modules/realtime.js";
15
15
  /**
16
16
  * Creates a Base44 client.
17
17
  *
@@ -51,19 +51,9 @@ import { createRealtimeModule } from "./modules/realtime.js";
51
51
  */
52
52
  export function createClient(config) {
53
53
  var _a, _b;
54
- const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, dispatcherWsUrl, } = config;
54
+ const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
55
55
  // Normalize appBaseUrl to always be a string (empty if not provided or invalid)
56
56
  const normalizedAppBaseUrl = typeof appBaseUrl === "string" ? appBaseUrl : "";
57
- // Derive the dispatcher WebSocket URL from serverUrl if not explicitly provided.
58
- // Convert https:// → wss:// (or http:// → ws://) and strip trailing slash.
59
- const resolvedDispatcherWsUrl = (() => {
60
- if (dispatcherWsUrl)
61
- return dispatcherWsUrl.replace(/\/$/, "");
62
- return serverUrl
63
- .replace(/\/$/, "")
64
- .replace(/^https:\/\//, "wss://")
65
- .replace(/^http:\/\//, "ws://");
66
- })();
67
57
  const socketConfig = {
68
58
  serverUrl,
69
59
  mountPath: "/ws-user-apps/socket.io/",
@@ -161,6 +151,7 @@ export function createClient(config) {
161
151
  serverUrl,
162
152
  token,
163
153
  }),
154
+ aiGateway: createAiGatewayModule({ serverUrl, token }),
164
155
  appLogs: createAppLogsModule(axiosClient, appId),
165
156
  users: createUsersModule(axiosClient, appId),
166
157
  analytics: createAnalyticsModule({
@@ -169,15 +160,6 @@ export function createClient(config) {
169
160
  appId,
170
161
  userAuthModule,
171
162
  }),
172
- realtime: createRealtimeModule({
173
- appId,
174
- dispatcherWsUrl: resolvedDispatcherWsUrl,
175
- getToken: async (handlerName, instanceId) => {
176
- // axiosClient interceptors unwrap response.data, so the result is the body directly
177
- const data = await axiosClient.post(`/apps/${appId}/realtime-token`, { handler_name: handlerName, instance_id: instanceId });
178
- return data.token;
179
- },
180
- }),
181
163
  cleanup: () => {
182
164
  userModules.analytics.cleanup();
183
165
  if (socket) {
@@ -212,6 +194,7 @@ export function createClient(config) {
212
194
  serverUrl,
213
195
  token,
214
196
  }),
197
+ aiGateway: createAiGatewayModule({ serverUrl, token: serviceToken }),
215
198
  appLogs: createAppLogsModule(serviceRoleAxiosClient, appId),
216
199
  cleanup: () => {
217
200
  if (socket) {
@@ -5,9 +5,9 @@ import type { SsoModule } from "./modules/sso.types.js";
5
5
  import type { ConnectorsModule, UserConnectorsModule } from "./modules/connectors.types.js";
6
6
  import type { FunctionsModule } from "./modules/functions.types.js";
7
7
  import type { AgentsModule } from "./modules/agents.types.js";
8
+ import type { AiGatewayModule } from "./modules/ai-gateway.types.js";
8
9
  import type { AppLogsModule } from "./modules/app-logs.types.js";
9
10
  import type { AnalyticsModule } from "./modules/analytics.types.js";
10
- import type { RealtimeModule } from "./modules/realtime.types.js";
11
11
  /**
12
12
  * Options for creating a Base44 client.
13
13
  */
@@ -73,13 +73,6 @@ export interface CreateClientConfig {
73
73
  * Additional client options.
74
74
  */
75
75
  options?: CreateClientOptions;
76
- /**
77
- * Base WebSocket URL for the Cloudflare Durable Object dispatcher.
78
- *
79
- * Defaults to the `serverUrl` with `https://` replaced by `wss://` (or `http://` by `ws://`).
80
- * Override when the dispatcher lives at a different host than the API.
81
- */
82
- dispatcherWsUrl?: string;
83
76
  }
84
77
  /**
85
78
  * The Base44 client instance.
@@ -89,12 +82,12 @@ export interface CreateClientConfig {
89
82
  export interface Base44Client {
90
83
  /** {@link AgentsModule | Agents module} for managing AI agent conversations. */
91
84
  agents: AgentsModule;
85
+ /** {@link AiGatewayModule | AI Gateway module} for connecting to the Base44 AI Gateway with your own SDK. */
86
+ aiGateway: AiGatewayModule;
92
87
  /** {@link AnalyticsModule | Analytics module} for tracking custom events in your app. */
93
88
  analytics: AnalyticsModule;
94
89
  /** {@link AppLogsModule | App logs module} for tracking app usage. */
95
90
  appLogs: AppLogsModule;
96
- /** {@link RealtimeModule | Realtime module} for subscribing to and sending messages via Cloudflare Durable Object-backed RealtimeHandlers. */
97
- realtime: RealtimeModule;
98
91
  /** {@link AuthModule | Auth module} for user authentication and management. */
99
92
  auth: AuthModule;
100
93
  /** {@link UserConnectorsModule | Connectors module} for app-user OAuth flows. */
@@ -134,6 +127,8 @@ export interface Base44Client {
134
127
  readonly asServiceRole: {
135
128
  /** {@link AgentsModule | Agents module} with elevated permissions. */
136
129
  agents: AgentsModule;
130
+ /** {@link AiGatewayModule | AI Gateway module} with the service-role token. */
131
+ aiGateway: AiGatewayModule;
137
132
  /** {@link AppLogsModule | App logs module} with elevated permissions. */
138
133
  appLogs: AppLogsModule;
139
134
  /** {@link ConnectorsModule | Connectors module} for OAuth token retrieval. */
package/dist/index.d.ts CHANGED
@@ -9,10 +9,9 @@ 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
13
  export type { AppLogsModule } from "./modules/app-logs.types.js";
13
- export type { RealtimeModule, RealtimeHandlerClient, RealtimeHandlerNameRegistry, RealtimeHandlerRegistry, } from "./modules/realtime.types.js";
14
14
  export type { SsoModule, SsoAccessTokenResponse } from "./modules/sso.types.js";
15
- export { RealtimeHandler, type Conn } from "./realtime-handler.js";
16
15
  export type { ConnectorsModule, UserConnectorsModule, } from "./modules/connectors.types.js";
17
16
  export type { CustomIntegrationsModule, CustomIntegrationCallParams, CustomIntegrationCallResponse, } from "./modules/custom-integrations.types.js";
18
17
  export type { GetAccessTokenOptions, SaveAccessTokenOptions, RemoveAccessTokenOptions, GetLoginUrlOptions, } from "./utils/auth-utils.types.js";
package/dist/index.js CHANGED
@@ -3,4 +3,3 @@ 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 { RealtimeHandler } from "./realtime-handler.js";
@@ -0,0 +1,2 @@
1
+ import { AiGatewayModule, AiGatewayModuleConfig } from "./ai-gateway.types.js";
2
+ export declare function createAiGatewayModule({ serverUrl, token, }: AiGatewayModuleConfig): AiGatewayModule;
@@ -0,0 +1,13 @@
1
+ import { getAccessToken } from "../utils/auth-utils.js";
2
+ export function createAiGatewayModule({ serverUrl, token, }) {
3
+ const connection = () => {
4
+ var _a;
5
+ return ({
6
+ baseURL: `${serverUrl}/api/ai/unified/v1`,
7
+ token: (_a = token !== null && token !== void 0 ? token : getAccessToken()) !== null && _a !== void 0 ? _a : "",
8
+ });
9
+ };
10
+ return {
11
+ connection,
12
+ };
13
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * A connection to the Base44 AI Gateway.
3
+ *
4
+ * Contains the base URL and bearer token to use with any OpenAI-compatible client
5
+ * (the OpenAI SDK, Mastra, and others) pointed at the Base44 AI Gateway.
6
+ */
7
+ export interface AiGatewayConnection {
8
+ /** Base URL of the gateway's OpenAI-compatible endpoint. */
9
+ baseURL: string;
10
+ /** Bearer token used to authenticate requests to the gateway. */
11
+ token: string;
12
+ }
13
+ /**
14
+ * Configuration for the AI Gateway module.
15
+ * @internal
16
+ */
17
+ export interface AiGatewayModuleConfig {
18
+ /** Server URL */
19
+ serverUrl?: string;
20
+ /** Authentication token */
21
+ token?: string;
22
+ }
23
+ /**
24
+ * The AI Gateway module.
25
+ *
26
+ * Exposes the connection details for the Base44 AI Gateway so you can call it from
27
+ * your own code using any OpenAI-compatible SDK — for example, to build a custom
28
+ * agent on top of the gateway.
29
+ */
30
+ export interface AiGatewayModule {
31
+ /**
32
+ * Gets the connection details for the Base44 AI Gateway.
33
+ *
34
+ * Returns the `baseURL` and `token` to pass to any OpenAI-compatible client (the
35
+ * OpenAI SDK, Mastra, and others), so you can call the gateway from your own code
36
+ * without constructing the URL or handling the token yourself.
37
+ *
38
+ * The `token` is the current caller's bearer token: the app user's token for
39
+ * `base44.aiGateway`, or the service-role token for `base44.asServiceRole.aiGateway`.
40
+ * When the caller is unauthenticated, `token` is an empty string and gateway
41
+ * requests will be rejected.
42
+ *
43
+ * @returns The gateway {@linkcode AiGatewayConnection | connection} (`baseURL` and `token`).
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * // Inside a backend function, call the gateway with any OpenAI-compatible SDK
48
+ * import { createClientFromRequest } from 'npm:@base44/sdk';
49
+ * import OpenAI from 'npm:openai';
50
+ *
51
+ * Deno.serve(async (req) => {
52
+ * const base44 = createClientFromRequest(req);
53
+ * const { baseURL, token } = base44.aiGateway.connection();
54
+ *
55
+ * const openai = new OpenAI({ baseURL, apiKey: token });
56
+ * const res = await openai.chat.completions.create({
57
+ * model: 'claude_sonnet_4_6',
58
+ * messages: [{ role: 'user', content: 'Hello!' }],
59
+ * });
60
+ * return Response.json({ text: res.choices[0].message.content });
61
+ * });
62
+ * ```
63
+ */
64
+ connection(): AiGatewayConnection;
65
+ }
@@ -1,4 +1,5 @@
1
1
  export * from "./app.types.js";
2
2
  export * from "./agents.types.js";
3
+ export * from "./ai-gateway.types.js";
3
4
  export * from "./connectors.types.js";
4
5
  export * from "./analytics.types.js";
@@ -1,4 +1,5 @@
1
1
  export * from "./app.types.js";
2
2
  export * from "./agents.types.js";
3
+ export * from "./ai-gateway.types.js";
3
4
  export * from "./connectors.types.js";
4
5
  export * from "./analytics.types.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.35-pr.212.f5f8839",
3
+ "version": "0.8.35-pr.214.3329626",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -27,7 +27,6 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "axios": "^1.17.0",
30
- "partysocket": "^0.0.23",
31
30
  "socket.io-client": "^4.8.3",
32
31
  "uuid": "^13.0.2"
33
32
  },
@@ -1,10 +0,0 @@
1
- export declare function createRealtimeModule(config: {
2
- appId: string;
3
- getToken(handlerName: string, instanceId: string): Promise<string>;
4
- dispatcherWsUrl: string;
5
- }): Record<string, RealtimeHandler>;
6
- interface RealtimeHandler {
7
- subscribe(instanceId: string, callback: (data: unknown) => void): () => void;
8
- send(instanceId: string, data: unknown): void;
9
- }
10
- export {};
@@ -1,62 +0,0 @@
1
- import PartySocket from "partysocket";
2
- // Module-level map: "HandlerName:instanceId" → active socket
3
- const activeSockets = new Map();
4
- function socketKey(handlerName, instanceId) {
5
- return `${handlerName}:${instanceId}`;
6
- }
7
- export function createRealtimeModule(config) {
8
- return new Proxy({}, {
9
- get(_, handlerName) {
10
- return {
11
- subscribe(instanceId, callback) {
12
- var _a;
13
- const key = socketKey(handlerName, instanceId);
14
- // close existing if any
15
- (_a = activeSockets.get(key)) === null || _a === void 0 ? void 0 : _a.close();
16
- // startClosed: don't connect until we have a token
17
- const ws = new PartySocket({
18
- host: config.dispatcherWsUrl,
19
- party: handlerName,
20
- room: instanceId,
21
- startClosed: true,
22
- });
23
- activeSockets.set(key, ws);
24
- ws.addEventListener("message", (ev) => {
25
- try {
26
- callback(JSON.parse(ev.data));
27
- }
28
- catch (_a) {
29
- // ignore malformed
30
- }
31
- });
32
- // Fetch token then open; re-fetch on every close (token expires in 30s)
33
- const connect = async () => {
34
- if (activeSockets.get(key) !== ws)
35
- return;
36
- try {
37
- const token = await config.getToken(handlerName, instanceId);
38
- ws.updateProperties({ party: handlerName, room: instanceId, query: { token } });
39
- ws.reconnect();
40
- }
41
- catch (_a) {
42
- // retry on next close
43
- }
44
- };
45
- ws.addEventListener("close", () => connect());
46
- connect();
47
- return () => {
48
- activeSockets.delete(key);
49
- ws.close();
50
- };
51
- },
52
- send(instanceId, data) {
53
- const key = socketKey(handlerName, instanceId);
54
- const ws = activeSockets.get(key);
55
- if (!ws)
56
- throw new Error(`No active subscription for ${handlerName}:${instanceId}`);
57
- ws.send(JSON.stringify(data));
58
- },
59
- };
60
- },
61
- });
62
- }
@@ -1,61 +0,0 @@
1
- /**
2
- * Extend this interface to add typed `subscribe` callbacks and `send` payloads
3
- * for your deployed RealtimeHandlers.
4
- *
5
- * This is separate from {@link RealtimeHandlerNameRegistry} (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 RealtimeHandlerRegistry {
12
- * ChatRoom: {
13
- * inbound: { type: "joined" | "left" | "message"; userId?: string; from?: string; text?: string };
14
- * outbound: { text: string };
15
- * };
16
- * }
17
- * }
18
- * ```
19
- */
20
- export interface RealtimeHandlerRegistry {
21
- }
22
- /**
23
- * Auto-populated by `base44 types generate` with the names of your deployed handlers.
24
- * Do not edit this interface manually — use {@link RealtimeHandlerRegistry} for message types.
25
- */
26
- export interface RealtimeHandlerNameRegistry {
27
- }
28
- type AllHandlerNames = keyof RealtimeHandlerRegistry | keyof RealtimeHandlerNameRegistry;
29
- type InboundFor<N extends string> = N extends keyof RealtimeHandlerRegistry ? RealtimeHandlerRegistry[N] extends {
30
- inbound: infer I;
31
- } ? I : unknown : unknown;
32
- type OutboundFor<N extends string> = N extends keyof RealtimeHandlerRegistry ? RealtimeHandlerRegistry[N] extends {
33
- outbound: infer O;
34
- } ? O : unknown : unknown;
35
- /**
36
- * Client for a single named RealtimeHandler.
37
- * Typed automatically when the handler is registered in {@link RealtimeHandlerRegistry}.
38
- */
39
- export interface RealtimeHandlerClient<N extends string = string> {
40
- /** Open a WebSocket subscription. Returns a synchronous unsubscribe function. */
41
- subscribe(instanceId: string, callback: (data: InboundFor<N>) => void): () => void;
42
- /** Send a message over the open socket. Throws if not subscribed. */
43
- send(instanceId: string, data: OutboundFor<N>): void;
44
- }
45
- /**
46
- * The realtime module provides access to Cloudflare Durable Object-backed
47
- * RealtimeHandlers deployed by the Base44 platform.
48
- *
49
- * Handler names are accessed as dynamic properties on this module:
50
- * ```typescript
51
- * const sub = await base44.realtime.MyHandler.subscribe("room-1", (msg) => {
52
- * console.log(msg); // typed if MyHandler is in RealtimeHandlerRegistry
53
- * });
54
- * sub.send({ text: "hello" });
55
- * sub.close();
56
- * ```
57
- */
58
- export type RealtimeModule = {
59
- [K in AllHandlerNames]: K extends keyof RealtimeHandlerRegistry ? RealtimeHandlerClient<string & K> : RealtimeHandlerClient;
60
- } & Record<string, RealtimeHandlerClient>;
61
- export {};
@@ -1,34 +0,0 @@
1
- /**
2
- * Type-only base class for Realtime Handlers.
3
- *
4
- * Import and extend this in your handler files:
5
- * import { RealtimeHandler } from "@base44/sdk";
6
- * export class MyHandler extends RealtimeHandler { ... }
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
- export interface Conn {
12
- userId: string;
13
- appId: string;
14
- instanceId: string;
15
- send(data: unknown): void;
16
- reject(code: number, reason: string): void;
17
- }
18
- export interface Storage {
19
- get<T>(key: string): Promise<T | undefined>;
20
- put(key: string, value: unknown): Promise<void>;
21
- delete(key: string): Promise<boolean>;
22
- }
23
- export declare abstract class RealtimeHandler<_State = unknown, Message = unknown> {
24
- abstract handleConnect(conn: Conn): void | Promise<void>;
25
- abstract handleMessage(conn: Conn, msg: Message): void | Promise<void>;
26
- abstract handleClose(conn: Conn): void | Promise<void>;
27
- abstract handleTick(): void | Promise<void>;
28
- onStart(): void | Promise<void>;
29
- protected broadcast(_data: unknown): void;
30
- protected getConnections(): Conn[];
31
- protected startLoop(_ms: number): Promise<void>;
32
- protected stopLoop(): Promise<void>;
33
- protected get storage(): Storage;
34
- }
@@ -1,28 +0,0 @@
1
- /**
2
- * Type-only base class for Realtime Handlers.
3
- *
4
- * Import and extend this in your handler files:
5
- * import { RealtimeHandler } from "@base44/sdk";
6
- * export class MyHandler extends RealtimeHandler { ... }
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
- export class RealtimeHandler {
12
- onStart() { }
13
- broadcast(_data) {
14
- throw new Error("RealtimeHandler.broadcast() is only available inside a deployed handler");
15
- }
16
- getConnections() {
17
- throw new Error("RealtimeHandler.getConnections() is only available inside a deployed handler");
18
- }
19
- startLoop(_ms) {
20
- throw new Error("RealtimeHandler.startLoop() is only available inside a deployed handler");
21
- }
22
- stopLoop() {
23
- throw new Error("RealtimeHandler.stopLoop() is only available inside a deployed handler");
24
- }
25
- get storage() {
26
- throw new Error("RealtimeHandler.storage is only available inside a deployed handler");
27
- }
28
- }