@base44-preview/sdk 0.8.48-pr.280.dac0f98 → 0.8.48-pr.282.1b5a2bd

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.
Files changed (36) hide show
  1. package/dist/client.js +68 -70
  2. package/dist/client.types.d.ts +5 -14
  3. package/dist/index.d.ts +0 -3
  4. package/dist/index.js +0 -1
  5. package/dist/modules/agents.d.ts +1 -1
  6. package/dist/modules/agents.js +3 -4
  7. package/dist/modules/agents.types.d.ts +2 -2
  8. package/dist/modules/ai-gateway.d.ts +1 -1
  9. package/dist/modules/ai-gateway.js +2 -3
  10. package/dist/modules/ai-gateway.types.d.ts +2 -2
  11. package/dist/modules/analytics.d.ts +4 -29
  12. package/dist/modules/analytics.js +82 -107
  13. package/dist/modules/auth.js +20 -38
  14. package/dist/modules/auth.types.d.ts +26 -13
  15. package/dist/utils/auth-utils.d.ts +2 -0
  16. package/dist/utils/auth-utils.js +11 -0
  17. package/dist/utils/embed-session.d.ts +50 -0
  18. package/dist/utils/embed-session.js +140 -0
  19. package/dist/utils/fetch-with-auth.js +0 -6
  20. package/dist/utils/socket-utils.d.ts +3 -1
  21. package/dist/utils/socket-utils.js +1 -2
  22. package/package.json +1 -1
  23. package/dist/modules/experiment-exposures.d.ts +0 -19
  24. package/dist/modules/experiment-exposures.js +0 -65
  25. package/dist/modules/experiments-config.types.d.ts +0 -39
  26. package/dist/modules/experiments-config.types.js +0 -1
  27. package/dist/modules/experiments-context.d.ts +0 -10
  28. package/dist/modules/experiments-context.js +0 -44
  29. package/dist/modules/experiments-evaluator.d.ts +0 -11
  30. package/dist/modules/experiments-evaluator.js +0 -45
  31. package/dist/modules/experiments-runtime.types.d.ts +0 -19
  32. package/dist/modules/experiments-runtime.types.js +0 -7
  33. package/dist/modules/experiments.d.ts +0 -16
  34. package/dist/modules/experiments.js +0 -134
  35. package/dist/modules/experiments.types.d.ts +0 -106
  36. package/dist/modules/experiments.types.js +0 -1
package/dist/client.js CHANGED
@@ -5,6 +5,7 @@ import { createAuthModule } from "./modules/auth.js";
5
5
  import { createSsoModule } from "./modules/sso.js";
6
6
  import { createConnectorsModule, createUserConnectorsModule, } from "./modules/connectors.js";
7
7
  import { getAccessToken } from "./utils/auth-utils.js";
8
+ import { exchangeEmbedToken, isEmbeddedTab, markEmbeddedTab, takeEmbedTokenFromUrl, } from "./utils/embed-session.js";
8
9
  import { createFetchWithAuth } from "./utils/fetch-with-auth.js";
9
10
  import { createFunctionsModule } from "./modules/functions.js";
10
11
  import { createAgentsModule } from "./modules/agents.js";
@@ -14,9 +15,6 @@ import { createAppModule } from "./modules/app.js";
14
15
  import { createUsersModule } from "./modules/users.js";
15
16
  import { RoomsSocket } from "./utils/socket-utils.js";
16
17
  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
18
  import { createActorsModule, resolveActorsHost, } from "./modules/actors.js";
21
19
  /**
22
20
  * Creates a Base44 client.
@@ -56,17 +54,24 @@ import { createActorsModule, resolveActorsHost, } from "./modules/actors.js";
56
54
  * ```
57
55
  */
58
56
  export function createClient(config) {
59
- var _a, _b, _c, _d, _e, _f, _g;
60
- const { serverUrl = "https://base44.app", appId, analytics, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
57
+ var _a, _b, _c, _d;
58
+ const { serverUrl = "https://base44.app", appId, analytics, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
61
59
  // Normalize appBaseUrl to always be a string (empty if not provided or invalid)
62
60
  const normalizedAppBaseUrl = typeof appBaseUrl === "string" ? appBaseUrl : "";
63
- const experimentsContext = (_a = config.experiments) !== null && _a !== void 0 ? _a : getBrowserExperimentsContext(appId);
61
+ const embedOtt = takeEmbedTokenFromUrl();
62
+ if (embedOtt) {
63
+ markEmbeddedTab();
64
+ }
65
+ const embedded = Boolean(embedOtt) || isEmbeddedTab();
66
+ // In a frame the passed token is the OTT itself or a stale stored one, not this session.
67
+ const token = embedded ? undefined : config.token;
64
68
  const socketConfig = {
65
69
  serverUrl,
66
70
  mountPath: "/ws-user-apps/socket.io/",
67
71
  transports: ["websocket"],
68
72
  appId,
69
- token,
73
+ // null (not undefined): inside a frame the socket must never fall back to storage.
74
+ token: embedded ? null : token,
70
75
  };
71
76
  let socket = null;
72
77
  const getSocket = () => {
@@ -77,14 +82,9 @@ export function createClient(config) {
77
82
  }
78
83
  return socket;
79
84
  };
80
- const { [EXPERIMENTS_CONTEXT_HEADER]: inheritedExperimentsContext, ...requestHeaders } = optionalHeaders !== null && optionalHeaders !== void 0 ? optionalHeaders : {};
81
85
  const headers = {
82
- ...requestHeaders,
86
+ ...optionalHeaders,
83
87
  "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
88
  };
89
89
  const functionHeaders = functionsVersion
90
90
  ? {
@@ -130,52 +130,64 @@ export function createClient(config) {
130
130
  baseURL: `${serverUrl}/api`,
131
131
  headers,
132
132
  });
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
- getAuth: () => userAuthModule,
142
- trackExposure: exposureTracker.track,
143
- flushExposures: exposureTracker.flush,
144
- context: experimentsContext,
145
- });
146
133
  const userAuthModule = createAuthModule(axiosClient, functionsAxiosClient, appId, {
147
134
  appBaseUrl: normalizedAppBaseUrl,
148
135
  serverUrl,
149
136
  token,
150
- onAuthStateChange: experiments.onAuthStateChange,
137
+ embedded,
151
138
  });
152
139
  // Apply the access token before any module that may issue authenticated
153
140
  // requests during construction (notably analytics, which fires an init
154
141
  // event whose flush calls auth.me()). Without this, the first User/me
155
142
  // request is built before setToken runs and goes out unauthenticated.
156
- if (typeof window !== "undefined") {
143
+ // Skipped in a frame: the session comes from the exchange below.
144
+ if (typeof window !== "undefined" && !embedded) {
157
145
  const accessToken = token || getAccessToken();
158
146
  if (accessToken) {
159
147
  userAuthModule.setToken(accessToken);
160
148
  }
161
149
  }
162
- if (experimentsContext) {
163
- const { userId, status } = experimentsContext.identity;
164
- // The document's cookie identity may differ from this client's localStorage token.
165
- const needsClientIdentity = typeof window !== "undefined" && userAuthModule.hasToken() &&
166
- experimentsContext.config.experiments.some((experiment) => experiment.assign_by === "user");
167
- experiments.onAuthStateChange(status === "pending" || needsClientIdentity ? { status: "pending" } :
168
- userId ? { status: "authenticated", userId } : { status: "anonymous" });
150
+ // Live token for every module; outside a frame it still falls back to storage.
151
+ const getToken = () => { var _a; return (_a = userAuthModule.getToken()) !== null && _a !== void 0 ? _a : (embedded ? null : getAccessToken()); };
152
+ const applyToken = (newToken, saveToStorage) => {
153
+ userAuthModule.setToken(newToken, saveToStorage);
154
+ socketConfig.token = newToken;
155
+ if (socket) {
156
+ socket.updateConfig({ token: newToken });
157
+ }
158
+ };
159
+ // Settles once the exchanged session is applied (memory only); at once otherwise.
160
+ const authReady = embedOtt
161
+ ? exchangeEmbedToken({ serverUrl, appId, ott: embedOtt }).then((sessionToken) => {
162
+ if (sessionToken) {
163
+ applyToken(sessionToken, false);
164
+ }
165
+ })
166
+ : Promise.resolve();
167
+ if (embedOtt) {
168
+ // Requests issued during the exchange wait for it. Registered after createAxiosClient's
169
+ // interceptors so it runs first and the anonymous-visitor header sees the Authorization.
170
+ for (const client of [axiosClient, functionsAxiosClient]) {
171
+ client.interceptors.request.use(async (requestConfig) => {
172
+ await authReady;
173
+ const sessionToken = getToken();
174
+ if (sessionToken && !requestConfig.headers.get("Authorization")) {
175
+ requestConfig.headers.set("Authorization", `Bearer ${sessionToken}`);
176
+ }
177
+ return requestConfig;
178
+ });
179
+ }
169
180
  }
170
181
  const actorsModule = createActorsModule({
171
182
  appId,
172
183
  // serverUrl is often relative/empty (same-origin app); the proxy-fallback
173
184
  // URL needs an absolute host, so fall back to the page origin.
174
- host: resolveActorsHost(serverUrl, typeof window !== "undefined" ? (_d = window.location) === null || _d === void 0 ? void 0 : _d.origin : undefined),
185
+ host: resolveActorsHost(serverUrl, typeof window !== "undefined" ? (_a = window.location) === null || _a === void 0 ? void 0 : _a.origin : undefined),
175
186
  functionsVersion,
176
- getAuthToken: () => token || getAccessToken(),
187
+ getAuthToken: getToken,
177
188
  mintConnectionToken: async (actorName, room, connectionId) => {
178
- const authToken = token || getAccessToken();
189
+ await authReady;
190
+ const authToken = getToken();
179
191
  return await actorsAxiosClient.post(`/apps/${appId}/actors/${encodeURIComponent(actorName)}/connection-token`, { room, connection_id: connectionId }, {
180
192
  headers: {
181
193
  ...(authToken ? { Authorization: `Bearer ${authToken}` } : {}),
@@ -199,27 +211,25 @@ export function createClient(config) {
199
211
  integrations: createIntegrationsModule(axiosClient, appId),
200
212
  connectors: createUserConnectorsModule(axiosClient, appId),
201
213
  auth: userAuthModule,
202
- experiments: experiments.module,
203
214
  functions: createFunctionsModule(functionsAxiosClient, appId, {
204
215
  getAuthHeaders: () => {
205
216
  const headers = {};
206
- // Get current token from storage or initial config
207
- const currentToken = token || getAccessToken();
208
- if (currentToken) {
209
- headers["Authorization"] = `Bearer ${currentToken}`;
217
+ const sessionToken = getToken();
218
+ if (sessionToken) {
219
+ headers["Authorization"] = `Bearer ${sessionToken}`;
210
220
  }
211
221
  return headers;
212
222
  },
213
- baseURL: (_e = functionsAxiosClient.defaults) === null || _e === void 0 ? void 0 : _e.baseURL,
223
+ baseURL: (_b = functionsAxiosClient.defaults) === null || _b === void 0 ? void 0 : _b.baseURL,
214
224
  }),
215
225
  agents: createAgentsModule({
216
226
  axios: axiosClient,
217
227
  getSocket,
218
228
  appId,
219
229
  serverUrl,
220
- token,
230
+ getToken,
221
231
  }),
222
- aiGateway: createAiGatewayModule({ serverUrl, token, appId }),
232
+ aiGateway: createAiGatewayModule({ serverUrl, getToken, appId }),
223
233
  appLogs: createAppLogsModule(axiosClient, appId),
224
234
  app: createAppModule(axiosClient, appId),
225
235
  users: createUsersModule(axiosClient, appId),
@@ -228,14 +238,11 @@ export function createClient(config) {
228
238
  serverUrl,
229
239
  appId,
230
240
  userAuthModule,
231
- enabled: (_f = analytics === null || analytics === void 0 ? void 0 : analytics.enabled) !== null && _f !== void 0 ? _f : true,
232
- getVisitorId: experiments.visitorId,
233
- experimentsContext,
241
+ enabled: (_c = analytics === null || analytics === void 0 ? void 0 : analytics.enabled) !== null && _c !== void 0 ? _c : true,
234
242
  }),
235
243
  actors: actorsModule.module,
236
244
  cleanup: () => {
237
245
  userModules.analytics.cleanup();
238
- experiments.cleanup();
239
246
  actorsModule.closeAll();
240
247
  if (socket) {
241
248
  socket.disconnect();
@@ -260,16 +267,20 @@ export function createClient(config) {
260
267
  }
261
268
  return headers;
262
269
  },
263
- baseURL: (_g = serviceRoleFunctionsAxiosClient.defaults) === null || _g === void 0 ? void 0 : _g.baseURL,
270
+ baseURL: (_d = serviceRoleFunctionsAxiosClient.defaults) === null || _d === void 0 ? void 0 : _d.baseURL,
264
271
  }),
265
272
  agents: createAgentsModule({
266
273
  axios: serviceRoleAxiosClient,
267
274
  getSocket,
268
275
  appId,
269
276
  serverUrl,
270
- token,
277
+ getToken: () => token,
278
+ }),
279
+ aiGateway: createAiGatewayModule({
280
+ serverUrl,
281
+ getToken: () => serviceToken,
282
+ appId,
271
283
  }),
272
- aiGateway: createAiGatewayModule({ serverUrl, token: serviceToken, appId }),
273
284
  appLogs: createAppLogsModule(serviceRoleAxiosClient, appId),
274
285
  cleanup: () => {
275
286
  if (socket) {
@@ -303,15 +314,13 @@ export function createClient(config) {
303
314
  appId: String(appId),
304
315
  serverUrl,
305
316
  functionsVersion,
306
- platformHeaders: {
307
- ...headers,
308
- ...(inheritedExperimentsContext ? { [EXPERIMENTS_CONTEXT_HEADER]: inheritedExperimentsContext } : {}),
309
- },
317
+ platformHeaders: optionalHeaders,
310
318
  }),
311
319
  /**
312
320
  * Sets a new authentication token for all subsequent requests.
313
321
  *
314
322
  * @param newToken - The new authentication token
323
+ * @param saveToStorage - Whether to also keep the token in local storage. Defaults to `true`.
315
324
  *
316
325
  * @example
317
326
  * ```typescript
@@ -323,14 +332,8 @@ export function createClient(config) {
323
332
  * base44.setToken(access_token);
324
333
  * ```
325
334
  */
326
- setToken(newToken) {
327
- userModules.auth.setToken(newToken);
328
- if (socket) {
329
- socket.updateConfig({
330
- token: newToken,
331
- });
332
- }
333
- socketConfig.token = newToken;
335
+ setToken(newToken, saveToStorage = true) {
336
+ applyToken(newToken, saveToStorage);
334
337
  },
335
338
  /**
336
339
  * Gets the current client configuration.
@@ -458,10 +461,6 @@ export function createClientFromRequest(request) {
458
461
  }
459
462
  // Prepare additional headers to propagate
460
463
  const additionalHeaders = {};
461
- const encodedExperiments = request.headers.get(EXPERIMENTS_CONTEXT_HEADER);
462
- const experimentsContext = readExperimentsContext(encodedExperiments, appId);
463
- if (experimentsContext && encodedExperiments)
464
- additionalHeaders[EXPERIMENTS_CONTEXT_HEADER] = encodedExperiments;
465
464
  if (stateHeader) {
466
465
  additionalHeaders["Base44-State"] = stateHeader;
467
466
  }
@@ -482,6 +481,5 @@ export function createClientFromRequest(request) {
482
481
  serviceToken: serviceRoleToken,
483
482
  functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined,
484
483
  headers: additionalHeaders,
485
- experiments: experimentsContext ? { ...experimentsContext, pageUrl: request.url ? new URL(request.url).pathname : "/" } : undefined,
486
484
  });
487
485
  }
@@ -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. */
@@ -210,8 +200,9 @@ export interface Base44Client {
210
200
  * Updates the token for both HTTP requests and WebSocket connections.
211
201
  *
212
202
  * @param newToken - The new authentication token.
203
+ * @param saveToStorage - Whether to also keep the token in local storage so it survives a page load. Defaults to `true`.
213
204
  */
214
- setToken(newToken: string): void;
205
+ setToken(newToken: string, saveToStorage?: boolean): void;
215
206
  /**
216
207
  * Gets the current client configuration.
217
208
  * @internal
package/dist/index.d.ts CHANGED
@@ -4,9 +4,6 @@ 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, EntityFilterOperators, EntityFilterQuery, EntityFilterValue, EntityHandler, EntityRecord, EntityTypeRegistry, 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";
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,2 +1,2 @@
1
1
  import { AgentsModule, AgentsModuleConfig } from "./agents.types.js";
2
- export declare function createAgentsModule({ axios, getSocket, appId, serverUrl, token, }: AgentsModuleConfig): AgentsModule;
2
+ export declare function createAgentsModule({ axios, getSocket, appId, serverUrl, getToken, }: AgentsModuleConfig): AgentsModule;
@@ -1,5 +1,4 @@
1
- import { getAccessToken } from "../utils/auth-utils.js";
2
- export function createAgentsModule({ axios, getSocket, appId, serverUrl, token, }) {
1
+ export function createAgentsModule({ axios, getSocket, appId, serverUrl, getToken, }) {
3
2
  const baseURL = `/apps/${appId}/agents`;
4
3
  // Track active conversations
5
4
  const currentConversations = {};
@@ -56,7 +55,7 @@ export function createAgentsModule({ axios, getSocket, appId, serverUrl, token,
56
55
  };
57
56
  const getWhatsAppConnectURL = (agentName) => {
58
57
  const baseUrl = `${serverUrl}/api/apps/${appId}/agents/${encodeURIComponent(agentName)}/whatsapp`;
59
- const accessToken = token !== null && token !== void 0 ? token : getAccessToken();
58
+ const accessToken = getToken();
60
59
  if (accessToken) {
61
60
  return `${baseUrl}?token=${accessToken}`;
62
61
  }
@@ -67,7 +66,7 @@ export function createAgentsModule({ axios, getSocket, appId, serverUrl, token,
67
66
  };
68
67
  const getTelegramConnectURL = (agentName) => {
69
68
  const baseUrl = `${serverUrl}/api/apps/${appId}/agents/${encodeURIComponent(agentName)}/telegram`;
70
- const accessToken = token !== null && token !== void 0 ? token : getAccessToken();
69
+ const accessToken = getToken();
71
70
  if (accessToken) {
72
71
  return `${baseUrl}?token=${accessToken}`;
73
72
  }
@@ -160,8 +160,8 @@ export interface AgentsModuleConfig {
160
160
  appId: string;
161
161
  /** Server URL */
162
162
  serverUrl?: string;
163
- /** Authentication token */
164
- token?: string;
163
+ /** Returns the current authentication token, if any */
164
+ getToken: () => string | null | undefined;
165
165
  }
166
166
  /**
167
167
  * Agents module for managing AI agent conversations.
@@ -1,2 +1,2 @@
1
1
  import { AiGatewayModule, AiGatewayModuleConfig } from "./ai-gateway.types.js";
2
- export declare function createAiGatewayModule({ serverUrl, token, appId, }: AiGatewayModuleConfig): AiGatewayModule;
2
+ export declare function createAiGatewayModule({ serverUrl, getToken, appId, }: AiGatewayModuleConfig): AiGatewayModule;
@@ -1,10 +1,9 @@
1
- import { getAccessToken } from "../utils/auth-utils.js";
2
- export function createAiGatewayModule({ serverUrl, token, appId, }) {
1
+ export function createAiGatewayModule({ serverUrl, getToken, appId, }) {
3
2
  const connection = () => {
4
3
  var _a;
5
4
  return ({
6
5
  baseURL: `${serverUrl}/api/apps/${appId}/ai/openai/v1`,
7
- token: (_a = token !== null && token !== void 0 ? token : getAccessToken()) !== null && _a !== void 0 ? _a : "",
6
+ token: (_a = getToken()) !== null && _a !== void 0 ? _a : "",
8
7
  });
9
8
  };
10
9
  return {
@@ -17,8 +17,8 @@ export interface AiGatewayConnection {
17
17
  export interface AiGatewayModuleConfig {
18
18
  /** Server URL */
19
19
  serverUrl?: string;
20
- /** Authentication token */
21
- token?: string;
20
+ /** Returns the current authentication token, if any */
21
+ getToken: () => string | null | undefined;
22
22
  /** Application ID */
23
23
  appId: string;
24
24
  }
@@ -1,7 +1,6 @@
1
1
  import { AxiosInstance } from "axios";
2
- import { TrackEventParams, TrackEventData, 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__";
@@ -13,22 +12,8 @@ export interface AnalyticsModuleArgs {
13
12
  appId: string;
14
13
  userAuthModule: InternalAuthModule;
15
14
  enabled: boolean;
16
- getVisitorId?: () => string | undefined;
17
- experimentsContext?: ExperimentsContext;
18
15
  }
19
- /** @internal */
20
- export declare function isAnalyticsEnabled(enabled: boolean, state?: {
21
- requestsQueue: TrackEventData[];
22
- isProcessing: boolean;
23
- isHeartBeatProcessing: boolean;
24
- wasInitializationTracked: boolean;
25
- sessionContext: SessionContext | null;
26
- sessionContextPromise: Promise<SessionContext> | null;
27
- sessionStartTime: string | null;
28
- fallbackSessionId: string | null;
29
- config: Required<AnalyticsModuleOptions>;
30
- }): boolean;
31
- export declare const createAnalyticsModule: ({ axiosClient, serverUrl, appId, userAuthModule, enabled, getVisitorId, experimentsContext, }: AnalyticsModuleArgs) => {
16
+ export declare const createAnalyticsModule: ({ axiosClient, serverUrl, appId, userAuthModule, enabled, }: AnalyticsModuleArgs) => {
32
17
  track: (params: TrackEventParams) => void;
33
18
  cleanup: () => void;
34
19
  };
@@ -42,16 +27,6 @@ export declare const createAnalyticsModule: ({ axiosClient, serverUrl, appId, us
42
27
  *
43
28
  * @internal
44
29
  */
45
- export declare function resetAnalyticsSessionContext(axiosClient?: AxiosInstance): void;
30
+ export declare function resetAnalyticsSessionContext(): void;
46
31
  export declare function getAnalyticsConfigFromUrlParams(): AnalyticsModuleOptions | undefined;
47
- export declare function getAnalyticsSessionId(state?: {
48
- requestsQueue: TrackEventData[];
49
- isProcessing: boolean;
50
- isHeartBeatProcessing: boolean;
51
- wasInitializationTracked: boolean;
52
- sessionContext: SessionContext | null;
53
- sessionContextPromise: Promise<SessionContext> | null;
54
- sessionStartTime: string | null;
55
- fallbackSessionId: string | null;
56
- config: Required<AnalyticsModuleOptions>;
57
- }): string;
32
+ export declare function getAnalyticsSessionId(): string;