@base44-preview/sdk 0.8.48-pr.280.dac0f98 → 0.8.48-pr.282.028b41c

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 +90 -85
  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 +25 -41
  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 +51 -0
  18. package/dist/utils/embed-session.js +145 -0
  19. package/dist/utils/fetch-with-auth.js +0 -6
  20. package/dist/utils/socket-utils.d.ts +3 -2
  21. package/dist/utils/socket-utils.js +5 -11
  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,35 +54,20 @@ 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);
64
- const socketConfig = {
65
- serverUrl,
66
- mountPath: "/ws-user-apps/socket.io/",
67
- transports: ["websocket"],
68
- appId,
69
- token,
70
- };
71
- let socket = null;
72
- const getSocket = () => {
73
- if (!socket) {
74
- socket = RoomsSocket({
75
- config: socketConfig,
76
- });
77
- }
78
- return socket;
79
- };
80
- const { [EXPERIMENTS_CONTEXT_HEADER]: inheritedExperimentsContext, ...requestHeaders } = optionalHeaders !== null && optionalHeaders !== void 0 ? optionalHeaders : {};
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;
81
68
  const headers = {
82
- ...requestHeaders,
69
+ ...optionalHeaders,
83
70
  "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
71
  };
89
72
  const functionHeaders = functionsVersion
90
73
  ? {
@@ -130,52 +113,88 @@ export function createClient(config) {
130
113
  baseURL: `${serverUrl}/api`,
131
114
  headers,
132
115
  });
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
116
  const userAuthModule = createAuthModule(axiosClient, functionsAxiosClient, appId, {
147
117
  appBaseUrl: normalizedAppBaseUrl,
148
118
  serverUrl,
149
119
  token,
150
- onAuthStateChange: experiments.onAuthStateChange,
120
+ embedded,
151
121
  });
152
122
  // Apply the access token before any module that may issue authenticated
153
123
  // requests during construction (notably analytics, which fires an init
154
124
  // event whose flush calls auth.me()). Without this, the first User/me
155
125
  // request is built before setToken runs and goes out unauthenticated.
156
- if (typeof window !== "undefined") {
126
+ // Skipped in a frame: the session comes from the exchange below.
127
+ if (typeof window !== "undefined" && !embedded) {
157
128
  const accessToken = token || getAccessToken();
158
129
  if (accessToken) {
159
130
  userAuthModule.setToken(accessToken);
160
131
  }
161
132
  }
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" });
133
+ // Live token for every module; outside a frame it still falls back to storage.
134
+ const getToken = () => { var _a; return (_a = userAuthModule.getToken()) !== null && _a !== void 0 ? _a : (embedded ? null : getAccessToken()); };
135
+ const socketConfig = {
136
+ serverUrl,
137
+ mountPath: "/ws-user-apps/socket.io/",
138
+ transports: ["websocket"],
139
+ appId,
140
+ getToken,
141
+ };
142
+ let socket = null;
143
+ const getSocket = () => {
144
+ if (!socket) {
145
+ socket = RoomsSocket({ config: socketConfig });
146
+ }
147
+ return socket;
148
+ };
149
+ const applyToken = (newToken, saveToStorage) => {
150
+ userAuthModule.setToken(newToken, saveToStorage);
151
+ socket === null || socket === void 0 ? void 0 : socket.reconnect();
152
+ };
153
+ // Settles once the exchanged session is applied (memory only); at once
154
+ // otherwise. Never rejects: every request waits on it, so a failure here
155
+ // must not turn into a rejection on each of them.
156
+ const authReady = embedOtt
157
+ ? exchangeEmbedToken({ serverUrl, appId, ott: embedOtt })
158
+ .then((sessionToken) => {
159
+ var _a;
160
+ if (sessionToken) {
161
+ applyToken(sessionToken, false);
162
+ return;
163
+ }
164
+ // The app is about to run anonymous. Say why, once, instead of
165
+ // leaving only the 401s that follow.
166
+ const error = new Error("Base44: the embed token was refused, so this app is not signed in.");
167
+ console.error(error.message);
168
+ (_a = options === null || options === void 0 ? void 0 : options.onError) === null || _a === void 0 ? void 0 : _a.call(options, error);
169
+ })
170
+ .catch((e) => {
171
+ console.error("Base44: applying the embedded session failed:", e);
172
+ })
173
+ : Promise.resolve();
174
+ if (embedOtt) {
175
+ // Requests issued during the exchange wait for it. Registered after createAxiosClient's
176
+ // interceptors so it runs first and the anonymous-visitor header sees the Authorization.
177
+ for (const client of [axiosClient, functionsAxiosClient]) {
178
+ client.interceptors.request.use(async (requestConfig) => {
179
+ await authReady;
180
+ const sessionToken = getToken();
181
+ if (sessionToken && !requestConfig.headers.get("Authorization")) {
182
+ requestConfig.headers.set("Authorization", `Bearer ${sessionToken}`);
183
+ }
184
+ return requestConfig;
185
+ });
186
+ }
169
187
  }
170
188
  const actorsModule = createActorsModule({
171
189
  appId,
172
190
  // serverUrl is often relative/empty (same-origin app); the proxy-fallback
173
191
  // 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),
192
+ host: resolveActorsHost(serverUrl, typeof window !== "undefined" ? (_a = window.location) === null || _a === void 0 ? void 0 : _a.origin : undefined),
175
193
  functionsVersion,
176
- getAuthToken: () => token || getAccessToken(),
194
+ getAuthToken: getToken,
177
195
  mintConnectionToken: async (actorName, room, connectionId) => {
178
- const authToken = token || getAccessToken();
196
+ await authReady;
197
+ const authToken = getToken();
179
198
  return await actorsAxiosClient.post(`/apps/${appId}/actors/${encodeURIComponent(actorName)}/connection-token`, { room, connection_id: connectionId }, {
180
199
  headers: {
181
200
  ...(authToken ? { Authorization: `Bearer ${authToken}` } : {}),
@@ -199,27 +218,25 @@ export function createClient(config) {
199
218
  integrations: createIntegrationsModule(axiosClient, appId),
200
219
  connectors: createUserConnectorsModule(axiosClient, appId),
201
220
  auth: userAuthModule,
202
- experiments: experiments.module,
203
221
  functions: createFunctionsModule(functionsAxiosClient, appId, {
204
222
  getAuthHeaders: () => {
205
223
  const headers = {};
206
- // Get current token from storage or initial config
207
- const currentToken = token || getAccessToken();
208
- if (currentToken) {
209
- headers["Authorization"] = `Bearer ${currentToken}`;
224
+ const sessionToken = getToken();
225
+ if (sessionToken) {
226
+ headers["Authorization"] = `Bearer ${sessionToken}`;
210
227
  }
211
228
  return headers;
212
229
  },
213
- baseURL: (_e = functionsAxiosClient.defaults) === null || _e === void 0 ? void 0 : _e.baseURL,
230
+ baseURL: (_b = functionsAxiosClient.defaults) === null || _b === void 0 ? void 0 : _b.baseURL,
214
231
  }),
215
232
  agents: createAgentsModule({
216
233
  axios: axiosClient,
217
234
  getSocket,
218
235
  appId,
219
236
  serverUrl,
220
- token,
237
+ getToken,
221
238
  }),
222
- aiGateway: createAiGatewayModule({ serverUrl, token, appId }),
239
+ aiGateway: createAiGatewayModule({ serverUrl, getToken, appId }),
223
240
  appLogs: createAppLogsModule(axiosClient, appId),
224
241
  app: createAppModule(axiosClient, appId),
225
242
  users: createUsersModule(axiosClient, appId),
@@ -228,14 +245,11 @@ export function createClient(config) {
228
245
  serverUrl,
229
246
  appId,
230
247
  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,
248
+ enabled: (_c = analytics === null || analytics === void 0 ? void 0 : analytics.enabled) !== null && _c !== void 0 ? _c : true,
234
249
  }),
235
250
  actors: actorsModule.module,
236
251
  cleanup: () => {
237
252
  userModules.analytics.cleanup();
238
- experiments.cleanup();
239
253
  actorsModule.closeAll();
240
254
  if (socket) {
241
255
  socket.disconnect();
@@ -260,16 +274,20 @@ export function createClient(config) {
260
274
  }
261
275
  return headers;
262
276
  },
263
- baseURL: (_g = serviceRoleFunctionsAxiosClient.defaults) === null || _g === void 0 ? void 0 : _g.baseURL,
277
+ baseURL: (_d = serviceRoleFunctionsAxiosClient.defaults) === null || _d === void 0 ? void 0 : _d.baseURL,
264
278
  }),
265
279
  agents: createAgentsModule({
266
280
  axios: serviceRoleAxiosClient,
267
281
  getSocket,
268
282
  appId,
269
283
  serverUrl,
270
- token,
284
+ getToken: () => token,
285
+ }),
286
+ aiGateway: createAiGatewayModule({
287
+ serverUrl,
288
+ getToken: () => serviceToken,
289
+ appId,
271
290
  }),
272
- aiGateway: createAiGatewayModule({ serverUrl, token: serviceToken, appId }),
273
291
  appLogs: createAppLogsModule(serviceRoleAxiosClient, appId),
274
292
  cleanup: () => {
275
293
  if (socket) {
@@ -303,15 +321,13 @@ export function createClient(config) {
303
321
  appId: String(appId),
304
322
  serverUrl,
305
323
  functionsVersion,
306
- platformHeaders: {
307
- ...headers,
308
- ...(inheritedExperimentsContext ? { [EXPERIMENTS_CONTEXT_HEADER]: inheritedExperimentsContext } : {}),
309
- },
324
+ platformHeaders: optionalHeaders,
310
325
  }),
311
326
  /**
312
327
  * Sets a new authentication token for all subsequent requests.
313
328
  *
314
329
  * @param newToken - The new authentication token
330
+ * @param saveToStorage - Whether to also keep the token in local storage. Defaults to `true`.
315
331
  *
316
332
  * @example
317
333
  * ```typescript
@@ -323,14 +339,8 @@ export function createClient(config) {
323
339
  * base44.setToken(access_token);
324
340
  * ```
325
341
  */
326
- setToken(newToken) {
327
- userModules.auth.setToken(newToken);
328
- if (socket) {
329
- socket.updateConfig({
330
- token: newToken,
331
- });
332
- }
333
- socketConfig.token = newToken;
342
+ setToken(newToken, saveToStorage = true) {
343
+ applyToken(newToken, saveToStorage);
334
344
  },
335
345
  /**
336
346
  * Gets the current client configuration.
@@ -458,10 +468,6 @@ export function createClientFromRequest(request) {
458
468
  }
459
469
  // Prepare additional headers to propagate
460
470
  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
471
  if (stateHeader) {
466
472
  additionalHeaders["Base44-State"] = stateHeader;
467
473
  }
@@ -482,6 +488,5 @@ export function createClientFromRequest(request) {
482
488
  serviceToken: serviceRoleToken,
483
489
  functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined,
484
490
  headers: additionalHeaders,
485
- experiments: experimentsContext ? { ...experimentsContext, pageUrl: request.url ? new URL(request.url).pathname : "/" } : undefined,
486
491
  });
487
492
  }
@@ -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;