@base44-preview/sdk 0.8.49-pr.280.04af9f9 → 0.8.49-pr.288.a18e427

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
@@ -14,9 +14,6 @@ import { createAppModule } from "./modules/app.js";
14
14
  import { createUsersModule } from "./modules/users.js";
15
15
  import { RoomsSocket } from "./utils/socket-utils.js";
16
16
  import { createAnalyticsModule } from "./modules/analytics.js";
17
- import { createExperimentsModule } from "./modules/experiments.js";
18
- import { createExposureTracker } from "./modules/experiment-exposures.js";
19
- import { EXPERIMENTS_CONTEXT_HEADER, getBrowserExperimentsContext, readExperimentsContext } from "./modules/experiments-context.js";
20
17
  import { createActorsModule, resolveActorsHost, } from "./modules/actors.js";
21
18
  /**
22
19
  * Creates a Base44 client.
@@ -56,11 +53,10 @@ import { createActorsModule, resolveActorsHost, } from "./modules/actors.js";
56
53
  * ```
57
54
  */
58
55
  export function createClient(config) {
59
- var _a, _b, _c, _d, _e, _f, _g;
56
+ var _a, _b, _c, _d;
60
57
  const { serverUrl = "https://base44.app", appId, analytics, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
61
58
  // Normalize appBaseUrl to always be a string (empty if not provided or invalid)
62
59
  const normalizedAppBaseUrl = typeof appBaseUrl === "string" ? appBaseUrl : "";
63
- const experimentsContext = (_a = config.experiments) !== null && _a !== void 0 ? _a : getBrowserExperimentsContext(appId);
64
60
  const socketConfig = {
65
61
  serverUrl,
66
62
  mountPath: "/ws-user-apps/socket.io/",
@@ -77,14 +73,9 @@ export function createClient(config) {
77
73
  }
78
74
  return socket;
79
75
  };
80
- const { [EXPERIMENTS_CONTEXT_HEADER]: inheritedExperimentsContext, ...requestHeaders } = optionalHeaders !== null && optionalHeaders !== void 0 ? optionalHeaders : {};
81
76
  const headers = {
82
- ...requestHeaders,
77
+ ...optionalHeaders,
83
78
  "X-App-Id": String(appId),
84
- ...(experimentsContext ? {
85
- "Base44-Visitor-Id": experimentsContext.identity.visitorId,
86
- "Base44-Experiment-Preview": JSON.stringify((_b = experimentsContext.preview) !== null && _b !== void 0 ? _b : {}),
87
- } : {}),
88
79
  };
89
80
  const functionHeaders = functionsVersion
90
81
  ? {
@@ -130,25 +121,10 @@ export function createClient(config) {
130
121
  baseURL: `${serverUrl}/api`,
131
122
  headers,
132
123
  });
133
- const exposureTracker = createExposureTracker({
134
- axiosClient,
135
- appId,
136
- enabled: (_c = analytics === null || analytics === void 0 ? void 0 : analytics.enabled) !== null && _c !== void 0 ? _c : true,
137
- source: typeof window === "undefined" ? "backend" : "browser",
138
- pageUrl: experimentsContext === null || experimentsContext === void 0 ? void 0 : experimentsContext.pageUrl,
139
- });
140
- const experiments = createExperimentsModule({
141
- appId,
142
- getAuth: () => userAuthModule,
143
- trackExposure: exposureTracker.track,
144
- flushExposures: exposureTracker.flush,
145
- context: experimentsContext,
146
- });
147
124
  const userAuthModule = createAuthModule(axiosClient, functionsAxiosClient, appId, {
148
125
  appBaseUrl: normalizedAppBaseUrl,
149
126
  serverUrl,
150
127
  token,
151
- onAuthStateChange: experiments.onAuthStateChange,
152
128
  });
153
129
  // Apply the access token before any module that may issue authenticated
154
130
  // requests during construction (notably analytics, which fires an init
@@ -160,19 +136,11 @@ export function createClient(config) {
160
136
  userAuthModule.setToken(accessToken);
161
137
  }
162
138
  }
163
- if (experimentsContext) {
164
- const { userId, status } = experimentsContext.identity;
165
- // The document's cookie identity may differ from this client's localStorage token.
166
- const needsClientIdentity = typeof window !== "undefined" && userAuthModule.hasToken() &&
167
- experimentsContext.config.experiments.some((experiment) => experiment.assign_by === "user");
168
- experiments.onAuthStateChange(status === "pending" || needsClientIdentity ? { status: "pending" } :
169
- userId ? { status: "authenticated", userId } : { status: "anonymous" });
170
- }
171
139
  const actorsModule = createActorsModule({
172
140
  appId,
173
141
  // serverUrl is often relative/empty (same-origin app); the proxy-fallback
174
142
  // URL needs an absolute host, so fall back to the page origin.
175
- host: resolveActorsHost(serverUrl, typeof window !== "undefined" ? (_d = window.location) === null || _d === void 0 ? void 0 : _d.origin : undefined),
143
+ host: resolveActorsHost(serverUrl, typeof window !== "undefined" ? (_a = window.location) === null || _a === void 0 ? void 0 : _a.origin : undefined),
176
144
  functionsVersion,
177
145
  getAuthToken: () => token || getAccessToken(),
178
146
  mintConnectionToken: async (actorName, room, connectionId) => {
@@ -200,7 +168,6 @@ export function createClient(config) {
200
168
  integrations: createIntegrationsModule(axiosClient, appId),
201
169
  connectors: createUserConnectorsModule(axiosClient, appId),
202
170
  auth: userAuthModule,
203
- experiments: experiments.module,
204
171
  functions: createFunctionsModule(functionsAxiosClient, appId, {
205
172
  getAuthHeaders: () => {
206
173
  const headers = {};
@@ -211,7 +178,7 @@ export function createClient(config) {
211
178
  }
212
179
  return headers;
213
180
  },
214
- baseURL: (_e = functionsAxiosClient.defaults) === null || _e === void 0 ? void 0 : _e.baseURL,
181
+ baseURL: (_b = functionsAxiosClient.defaults) === null || _b === void 0 ? void 0 : _b.baseURL,
215
182
  }),
216
183
  agents: createAgentsModule({
217
184
  axios: axiosClient,
@@ -229,14 +196,11 @@ export function createClient(config) {
229
196
  serverUrl,
230
197
  appId,
231
198
  userAuthModule,
232
- enabled: (_f = analytics === null || analytics === void 0 ? void 0 : analytics.enabled) !== null && _f !== void 0 ? _f : true,
233
- getVisitorId: experiments.visitorId,
234
- experimentsContext,
199
+ enabled: (_c = analytics === null || analytics === void 0 ? void 0 : analytics.enabled) !== null && _c !== void 0 ? _c : true,
235
200
  }),
236
201
  actors: actorsModule.module,
237
202
  cleanup: () => {
238
203
  userModules.analytics.cleanup();
239
- experiments.cleanup();
240
204
  actorsModule.closeAll();
241
205
  if (socket) {
242
206
  socket.disconnect();
@@ -261,7 +225,7 @@ export function createClient(config) {
261
225
  }
262
226
  return headers;
263
227
  },
264
- baseURL: (_g = serviceRoleFunctionsAxiosClient.defaults) === null || _g === void 0 ? void 0 : _g.baseURL,
228
+ baseURL: (_d = serviceRoleFunctionsAxiosClient.defaults) === null || _d === void 0 ? void 0 : _d.baseURL,
265
229
  }),
266
230
  agents: createAgentsModule({
267
231
  axios: serviceRoleAxiosClient,
@@ -304,10 +268,7 @@ export function createClient(config) {
304
268
  appId: String(appId),
305
269
  serverUrl,
306
270
  functionsVersion,
307
- platformHeaders: {
308
- ...headers,
309
- ...(inheritedExperimentsContext ? { [EXPERIMENTS_CONTEXT_HEADER]: inheritedExperimentsContext } : {}),
310
- },
271
+ platformHeaders: optionalHeaders,
311
272
  }),
312
273
  /**
313
274
  * Sets a new authentication token for all subsequent requests.
@@ -459,10 +420,6 @@ export function createClientFromRequest(request) {
459
420
  }
460
421
  // Prepare additional headers to propagate
461
422
  const additionalHeaders = {};
462
- const encodedExperiments = request.headers.get(EXPERIMENTS_CONTEXT_HEADER);
463
- const experimentsContext = readExperimentsContext(encodedExperiments, appId);
464
- if (experimentsContext && encodedExperiments)
465
- additionalHeaders[EXPERIMENTS_CONTEXT_HEADER] = encodedExperiments;
466
423
  if (stateHeader) {
467
424
  additionalHeaders["Base44-State"] = stateHeader;
468
425
  }
@@ -483,6 +440,5 @@ export function createClientFromRequest(request) {
483
440
  serviceToken: serviceRoleToken,
484
441
  functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined,
485
442
  headers: additionalHeaders,
486
- experiments: experimentsContext ? { ...experimentsContext, pageUrl: request.url ? new URL(request.url).pathname : "/" } : undefined,
487
443
  });
488
444
  }
@@ -9,8 +9,6 @@ import type { AiGatewayModule } from "./modules/ai-gateway.types.js";
9
9
  import type { AppLogsModule } from "./modules/app-logs.types.js";
10
10
  import type { AppModule } from "./modules/app.types.js";
11
11
  import type { AnalyticsModule } from "./modules/analytics.types.js";
12
- import type { ExperimentsModule } from "./modules/experiments.types.js";
13
- import type { ExperimentsContext } from "./modules/experiments-config.types.js";
14
12
  import type { ActorsModule } from "./modules/actors.types.js";
15
13
  import type { FetchWithAuthInit } from "./utils/fetch-with-auth.js";
16
14
  /**
@@ -41,9 +39,9 @@ export interface CreateClientAnalyticsConfig {
41
39
  /**
42
40
  * Whether app analytics is enabled for this client.
43
41
  *
44
- * When disabled, automatic analytics, experiment exposures and calls to
45
- * `analytics.track()` are no-ops. The SDK does not create an analytics session
46
- * identifier, start heartbeat timers, or send analytics requests.
42
+ * When disabled, automatic analytics and calls to `analytics.track()` are
43
+ * no-ops. The SDK does not create an analytics session identifier, start
44
+ * heartbeat timers, or send analytics requests.
47
45
  *
48
46
  * @defaultValue `true`
49
47
  */
@@ -81,12 +79,6 @@ export interface CreateClientConfig {
81
79
  * Omit this option to preserve the default analytics behavior.
82
80
  */
83
81
  analytics?: CreateClientAnalyticsConfig;
84
- /**
85
- * Platform-validated context for local flag evaluation. Request-scoped on servers.
86
- * Automatically read from the platform bootstrap in browsers and trusted headers
87
- * by createClientFromRequest(). Not an authorization credential.
88
- */
89
- experiments?: ExperimentsContext;
90
82
  /**
91
83
  * User authentication token. Used to authenticate as a specific user.
92
84
  *
@@ -142,8 +134,6 @@ export interface Base44Client {
142
134
  connectors: UserConnectorsModule;
143
135
  /** {@link EntitiesModule | Entities module} for CRUD operations on your data models. */
144
136
  entities: EntitiesModule;
145
- /** {@link ExperimentsModule | Experiments module} for local feature flags and exposures. */
146
- experiments: ExperimentsModule;
147
137
  /** {@link FunctionsModule | Functions module} for invoking custom backend functions. */
148
138
  functions: FunctionsModule;
149
139
  /** {@link IntegrationsModule | Integrations module} for calling pre-built integration endpoints. */
package/dist/index.d.ts CHANGED
@@ -4,15 +4,12 @@ import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl } from
4
4
  export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
5
5
  export type { Base44Client, CreateClientAnalyticsConfig, CreateClientConfig, CreateClientOptions, Base44ErrorJSON, };
6
6
  export * from "./types.js";
7
- export { evaluateExperiments } from "./modules/experiments-evaluator.js";
8
- export type { ExperimentsConfig, ExperimentsContext, ExperimentsIdentity } from "./modules/experiments-config.types.js";
9
- export type { ExperimentsModule, ExperimentsSnapshot, } from "./modules/experiments.types.js";
10
7
  export type { DeleteManyResult, DeleteResult, EntitiesModule, EntityAggregateResult, EntityAggregateSpec, EntityDateBucketUnit, EntityDistinctOptions, EntityFilterOperators, EntityFilterQuery, EntityFilterValue, EntityHandler, EntityListOptions, EntityPage, EntityRecord, EntityTypeRegistry, EntityUpsertOptions, EntityUpsertResult, ImportResult, RealtimeEventType, RealtimeEvent, RealtimeCallback, SortField, UpdateManyResult, } from "./modules/entities.types.js";
11
8
  export type { AuthModule, LoginResponse, RegisterParams, VerifyOtpParams, ChangePasswordParams, ResetPasswordParams, User, } from "./modules/auth.types.js";
12
9
  export type { IntegrationsModule, IntegrationEndpointFunction, CoreIntegrations, InvokeLLMParams, GenerateImageParams, GenerateImageResult, UploadFileParams, UploadFileResult, SendEmailParams, SendEmailResult, ExtractDataFromUploadedFileParams, ExtractDataFromUploadedFileResult, UploadPrivateFileParams, UploadPrivateFileResult, CreateFileSignedUrlParams, CreateFileSignedUrlResult, } from "./modules/integrations.types.js";
13
10
  export type { FunctionsModule, FunctionName, FunctionNameRegistry, } from "./modules/functions.types.js";
14
11
  export type { AgentsModule, AgentName, AgentNameRegistry, AgentConversation, AgentMessage, AgentMessageReasoning, AgentMessageToolCall, AgentMessageUsage, AgentMessageCustomContext, AgentMessageMetadata, CreateConversationParams, } from "./modules/agents.types.js";
15
- export type { AiGatewayModule, AiGatewayConnection, } from "./modules/ai-gateway.types.js";
12
+ export type { AiGatewayModule, AiGatewayConnection, AiGatewayConnectionOptions, } from "./modules/ai-gateway.types.js";
16
13
  export type { AppLogsModule } from "./modules/app-logs.types.js";
17
14
  export type { AppModule, AppPublicSettings, AppPublicSettingsResponse, } from "./modules/app.types.js";
18
15
  export type { ActorsModule, ActorClient, ActorRef, Connection, ActorSubscription, ActorConnectOptions, ActorNameRegistry, ActorRegistry, } from "./modules/actors.types.js";
package/dist/index.js CHANGED
@@ -3,5 +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 { evaluateExperiments } from "./modules/experiments-evaluator.js";
7
6
  export { Actor } from "./actor.js";
@@ -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
  }
@@ -1,44 +1,19 @@
1
1
  import { AxiosInstance } from "axios";
2
- import { TrackEventParams, AnalyticsModuleOptions, SessionContext } from "./analytics.types";
2
+ import { TrackEventParams, AnalyticsModuleOptions } from "./analytics.types";
3
3
  import type { InternalAuthModule } from "./auth.types";
4
- import type { ExperimentsContext } from "./experiments-config.types.js";
5
4
  export declare const USER_HEARTBEAT_EVENT_NAME = "__user_heartbeat_event__";
6
5
  export declare const ANALYTICS_INITIALIZATION_EVENT_NAME = "__initialization_event__";
7
6
  export declare const ANALYTICS_SESSION_DURATION_EVENT_NAME = "__session_duration_event__";
8
7
  export declare const ANALYTICS_CONFIG_ENABLE_URL_PARAM_KEY = "analytics-enable";
9
8
  export declare const ANALYTICS_SESSION_ID_LOCAL_STORAGE_KEY = "base44_analytics_session_id";
10
- declare function createAnalyticsState(): {
11
- isHeartBeatProcessing: boolean;
12
- wasInitializationTracked: boolean;
13
- sessionContext: SessionContext | null;
14
- sessionContextPromise: Promise<SessionContext> | null;
15
- sessionStartTime: string | null;
16
- fallbackSessionId: string | null;
17
- config: Required<AnalyticsModuleOptions>;
18
- };
19
- type AnalyticsState = ReturnType<typeof createAnalyticsState>;
20
- /** @internal */
21
- export declare function getAnalyticsState(axiosClient: AxiosInstance): AnalyticsState;
22
9
  export interface AnalyticsModuleArgs {
23
10
  axiosClient: AxiosInstance;
24
11
  serverUrl: string;
25
12
  appId: string;
26
13
  userAuthModule: InternalAuthModule;
27
14
  enabled: boolean;
28
- getVisitorId?: () => string | undefined;
29
- experimentsContext?: ExperimentsContext;
30
15
  }
31
- /** @internal */
32
- export declare function isAnalyticsEnabled(enabled: boolean, state?: {
33
- isHeartBeatProcessing: boolean;
34
- wasInitializationTracked: boolean;
35
- sessionContext: SessionContext | null;
36
- sessionContextPromise: Promise<SessionContext> | null;
37
- sessionStartTime: string | null;
38
- fallbackSessionId: string | null;
39
- config: Required<AnalyticsModuleOptions>;
40
- }): boolean;
41
- export declare const createAnalyticsModule: ({ axiosClient, appId, userAuthModule, enabled, getVisitorId, experimentsContext, }: AnalyticsModuleArgs) => {
16
+ export declare const createAnalyticsModule: ({ axiosClient, serverUrl, appId, userAuthModule, enabled, }: AnalyticsModuleArgs) => {
42
17
  track: (params: TrackEventParams) => void;
43
18
  cleanup: () => void;
44
19
  };
@@ -52,15 +27,6 @@ export declare const createAnalyticsModule: ({ axiosClient, appId, userAuthModul
52
27
  *
53
28
  * @internal
54
29
  */
55
- export declare function resetAnalyticsSessionContext(axiosClient?: AxiosInstance): void;
30
+ export declare function resetAnalyticsSessionContext(): void;
56
31
  export declare function getAnalyticsConfigFromUrlParams(): AnalyticsModuleOptions | undefined;
57
- export declare function getAnalyticsSessionId(state?: {
58
- isHeartBeatProcessing: boolean;
59
- wasInitializationTracked: boolean;
60
- sessionContext: SessionContext | null;
61
- sessionContextPromise: Promise<SessionContext> | null;
62
- sessionStartTime: string | null;
63
- fallbackSessionId: string | null;
64
- config: Required<AnalyticsModuleOptions>;
65
- }): string;
66
- export {};
32
+ export declare function getAnalyticsSessionId(): string;