@base44-preview/sdk 0.7.0-pr.29.d287222 → 0.7.2-dev.65e038a

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.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ export type CreateClientOptions = {
2
+ onError?: (error: Error) => void;
3
+ };
4
+ export type Base44Client = ReturnType<typeof createClient>;
1
5
  /**
2
6
  * Create a Base44 client instance
3
7
  * @param {Object} config - Client configuration
@@ -15,6 +19,8 @@ export declare function createClient(config: {
15
19
  serviceToken?: string;
16
20
  requiresAuth?: boolean;
17
21
  functionsVersion?: string;
22
+ options?: CreateClientOptions;
23
+ onRedirectToLogin?: () => void;
18
24
  }): {
19
25
  /**
20
26
  * Set authentication token for all requests
@@ -39,6 +45,18 @@ export declare function createClient(config: {
39
45
  functions: {
40
46
  invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
41
47
  };
48
+ agents: {
49
+ getConversations: () => Promise<import("./types.js").AgentConversation[]>;
50
+ getConversation: (conversationId: string) => Promise<import("./types.js").AgentConversation | undefined>;
51
+ listConversations: (filterParams: import("./types.js").ModelFilterParams) => Promise<import("./types.js").AgentConversation[]>;
52
+ createConversation: (conversation: {
53
+ agent_name: string;
54
+ metadata?: Record<string, any>;
55
+ }) => Promise<import("./types.js").AgentConversation>;
56
+ addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
57
+ subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
58
+ };
59
+ cleanup: () => void;
42
60
  };
43
61
  entities: {};
44
62
  integrations: {};
@@ -57,6 +75,18 @@ export declare function createClient(config: {
57
75
  functions: {
58
76
  invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
59
77
  };
78
+ agents: {
79
+ getConversations: () => Promise<import("./types.js").AgentConversation[]>;
80
+ getConversation: (conversationId: string) => Promise<import("./types.js").AgentConversation | undefined>;
81
+ listConversations: (filterParams: import("./types.js").ModelFilterParams) => Promise<import("./types.js").AgentConversation[]>;
82
+ createConversation: (conversation: {
83
+ agent_name: string;
84
+ metadata?: Record<string, any>;
85
+ }) => Promise<import("./types.js").AgentConversation>;
86
+ addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
87
+ subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
88
+ };
89
+ cleanup: () => void;
60
90
  };
61
91
  export declare function createClientFromRequest(request: Request): {
62
92
  /**
@@ -82,6 +112,18 @@ export declare function createClientFromRequest(request: Request): {
82
112
  functions: {
83
113
  invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
84
114
  };
115
+ agents: {
116
+ getConversations: () => Promise<import("./types.js").AgentConversation[]>;
117
+ getConversation: (conversationId: string) => Promise<import("./types.js").AgentConversation | undefined>;
118
+ listConversations: (filterParams: import("./types.js").ModelFilterParams) => Promise<import("./types.js").AgentConversation[]>;
119
+ createConversation: (conversation: {
120
+ agent_name: string;
121
+ metadata?: Record<string, any>;
122
+ }) => Promise<import("./types.js").AgentConversation>;
123
+ addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
124
+ subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
125
+ };
126
+ cleanup: () => void;
85
127
  };
86
128
  entities: {};
87
129
  integrations: {};
@@ -100,4 +142,16 @@ export declare function createClientFromRequest(request: Request): {
100
142
  functions: {
101
143
  invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
102
144
  };
145
+ agents: {
146
+ getConversations: () => Promise<import("./types.js").AgentConversation[]>;
147
+ getConversation: (conversationId: string) => Promise<import("./types.js").AgentConversation | undefined>;
148
+ listConversations: (filterParams: import("./types.js").ModelFilterParams) => Promise<import("./types.js").AgentConversation[]>;
149
+ createConversation: (conversation: {
150
+ agent_name: string;
151
+ metadata?: Record<string, any>;
152
+ }) => Promise<import("./types.js").AgentConversation>;
153
+ addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
154
+ subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
155
+ };
156
+ cleanup: () => void;
103
157
  };
package/dist/client.js CHANGED
@@ -5,6 +5,8 @@ import { createAuthModule } from "./modules/auth.js";
5
5
  import { createSsoModule } from "./modules/sso.js";
6
6
  import { getAccessToken } from "./utils/auth-utils.js";
7
7
  import { createFunctionsModule } from "./modules/functions.js";
8
+ import { createAgentsModule } from "./modules/agents.js";
9
+ import { RoomsSocket } from "./utils/socket-utils.js";
8
10
  /**
9
11
  * Create a Base44 client instance
10
12
  * @param {Object} config - Client configuration
@@ -16,14 +18,26 @@ import { createFunctionsModule } from "./modules/functions.js";
16
18
  * @returns {Object} Base44 client instance
17
19
  */
18
20
  export function createClient(config) {
19
- const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, functionsVersion } = config;
21
+ const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, options, functionsVersion, onRedirectToLogin, } = config;
22
+ const socketConfig = {
23
+ serverUrl,
24
+ mountPath: "/ws-user-apps/socket.io/",
25
+ transports: ["websocket"],
26
+ appId,
27
+ token,
28
+ };
29
+ const socket = RoomsSocket({
30
+ config: socketConfig,
31
+ });
20
32
  const headers = {
21
33
  "X-App-Id": String(appId),
22
34
  };
23
- const functionHeaders = functionsVersion ? {
24
- ...headers,
25
- "Base44-Functions-Version": functionsVersion
26
- } : headers;
35
+ const functionHeaders = functionsVersion
36
+ ? {
37
+ ...headers,
38
+ "Base44-Functions-Version": functionsVersion,
39
+ }
40
+ : headers;
27
41
  const axiosClient = createAxiosClient({
28
42
  baseURL: `${serverUrl}/api`,
29
43
  headers,
@@ -31,6 +45,8 @@ export function createClient(config) {
31
45
  requiresAuth,
32
46
  appId,
33
47
  serverUrl,
48
+ onError: options === null || options === void 0 ? void 0 : options.onError,
49
+ onRedirectToLogin,
34
50
  });
35
51
  const functionsAxiosClient = createAxiosClient({
36
52
  baseURL: `${serverUrl}/api`,
@@ -40,6 +56,8 @@ export function createClient(config) {
40
56
  appId,
41
57
  serverUrl,
42
58
  interceptResponses: false,
59
+ onError: options === null || options === void 0 ? void 0 : options.onError,
60
+ onRedirectToLogin,
43
61
  });
44
62
  const serviceRoleAxiosClient = createAxiosClient({
45
63
  baseURL: `${serverUrl}/api`,
@@ -47,6 +65,8 @@ export function createClient(config) {
47
65
  token: serviceToken,
48
66
  serverUrl,
49
67
  appId,
68
+ onError: options === null || options === void 0 ? void 0 : options.onError,
69
+ onRedirectToLogin,
50
70
  });
51
71
  const serviceRoleFunctionsAxiosClient = createAxiosClient({
52
72
  baseURL: `${serverUrl}/api`,
@@ -55,18 +75,38 @@ export function createClient(config) {
55
75
  serverUrl,
56
76
  appId,
57
77
  interceptResponses: false,
78
+ onRedirectToLogin,
58
79
  });
59
80
  const userModules = {
60
81
  entities: createEntitiesModule(axiosClient, appId),
61
82
  integrations: createIntegrationsModule(axiosClient, appId),
62
- auth: createAuthModule(axiosClient, functionsAxiosClient, appId),
83
+ auth: createAuthModule(axiosClient, functionsAxiosClient, appId, {
84
+ onRedirectToLogin,
85
+ serverUrl,
86
+ }),
63
87
  functions: createFunctionsModule(functionsAxiosClient, appId),
88
+ agents: createAgentsModule({
89
+ axios: axiosClient,
90
+ socket,
91
+ appId,
92
+ }),
93
+ cleanup: () => {
94
+ socket.disconnect();
95
+ },
64
96
  };
65
97
  const serviceRoleModules = {
66
98
  entities: createEntitiesModule(serviceRoleAxiosClient, appId),
67
99
  integrations: createIntegrationsModule(serviceRoleAxiosClient, appId),
68
100
  sso: createSsoModule(serviceRoleAxiosClient, appId, token),
69
101
  functions: createFunctionsModule(serviceRoleFunctionsAxiosClient, appId),
102
+ agents: createAgentsModule({
103
+ axios: serviceRoleAxiosClient,
104
+ socket,
105
+ appId,
106
+ }),
107
+ cleanup: () => {
108
+ socket.disconnect();
109
+ },
70
110
  };
71
111
  // Always try to get token from localStorage or URL parameters
72
112
  if (typeof window !== "undefined") {
@@ -101,6 +141,9 @@ export function createClient(config) {
101
141
  */
102
142
  setToken(newToken) {
103
143
  userModules.auth.setToken(newToken);
144
+ socket.updateConfig({
145
+ token: newToken,
146
+ });
104
147
  },
105
148
  /**
106
149
  * Get current configuration
@@ -119,10 +162,10 @@ export function createClient(config) {
119
162
  */
120
163
  get asServiceRole() {
121
164
  if (!serviceToken) {
122
- throw new Error('Service token is required to use asServiceRole. Please provide a serviceToken when creating the client.');
165
+ throw new Error("Service token is required to use asServiceRole. Please provide a serviceToken when creating the client.");
123
166
  }
124
167
  return serviceRoleModules;
125
- }
168
+ },
126
169
  };
127
170
  return client;
128
171
  }
@@ -139,22 +182,26 @@ export function createClientFromRequest(request) {
139
182
  let serviceRoleToken;
140
183
  let userToken;
141
184
  if (serviceRoleAuthHeader !== null) {
142
- if (serviceRoleAuthHeader === '' || !serviceRoleAuthHeader.startsWith('Bearer ') || serviceRoleAuthHeader.split(' ').length !== 2) {
185
+ if (serviceRoleAuthHeader === "" ||
186
+ !serviceRoleAuthHeader.startsWith("Bearer ") ||
187
+ serviceRoleAuthHeader.split(" ").length !== 2) {
143
188
  throw new Error('Invalid authorization header format. Expected "Bearer <token>"');
144
189
  }
145
- serviceRoleToken = serviceRoleAuthHeader.split(' ')[1];
190
+ serviceRoleToken = serviceRoleAuthHeader.split(" ")[1];
146
191
  }
147
192
  if (authHeader !== null) {
148
- if (authHeader === '' || !authHeader.startsWith('Bearer ') || authHeader.split(' ').length !== 2) {
193
+ if (authHeader === "" ||
194
+ !authHeader.startsWith("Bearer ") ||
195
+ authHeader.split(" ").length !== 2) {
149
196
  throw new Error('Invalid authorization header format. Expected "Bearer <token>"');
150
197
  }
151
- userToken = authHeader.split(' ')[1];
198
+ userToken = authHeader.split(" ")[1];
152
199
  }
153
200
  return createClient({
154
201
  serverUrl: serverUrlHeader || "https://base44.app",
155
202
  appId,
156
203
  token: userToken,
157
204
  serviceToken: serviceRoleToken,
158
- functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined
205
+ functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined,
159
206
  });
160
207
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- import { createClient, createClientFromRequest } from "./client.js";
1
+ import { createClient, createClientFromRequest, type Base44Client } from "./client.js";
2
2
  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
+ export type { Base44Client };
6
+ export * from "./types.js";
package/dist/index.js CHANGED
@@ -2,3 +2,4 @@ import { createClient, createClientFromRequest } from "./client.js";
2
2
  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
+ export * from "./types.js";
@@ -0,0 +1,20 @@
1
+ import { RoomsSocket } from "../utils/socket-utils.js";
2
+ import { AgentConversation, AgentMessage } from "./agents.types.js";
3
+ import { AxiosInstance } from "axios";
4
+ import { ModelFilterParams } from "../types.js";
5
+ export type AgentsModuleConfig = {
6
+ axios: AxiosInstance;
7
+ socket: ReturnType<typeof RoomsSocket>;
8
+ appId: string;
9
+ };
10
+ export declare function createAgentsModule({ axios, socket, appId, }: AgentsModuleConfig): {
11
+ getConversations: () => Promise<AgentConversation[]>;
12
+ getConversation: (conversationId: string) => Promise<AgentConversation | undefined>;
13
+ listConversations: (filterParams: ModelFilterParams) => Promise<AgentConversation[]>;
14
+ createConversation: (conversation: {
15
+ agent_name: string;
16
+ metadata?: Record<string, any>;
17
+ }) => Promise<AgentConversation>;
18
+ addMessage: (conversation: AgentConversation, message: AgentMessage) => Promise<AgentMessage>;
19
+ subscribeToConversation: (conversationId: string, onUpdate?: (conversation: AgentConversation) => void) => () => void;
20
+ };
@@ -0,0 +1,43 @@
1
+ export function createAgentsModule({ axios, socket, appId, }) {
2
+ const baseURL = `/apps/${appId}/agents`;
3
+ const getConversations = () => {
4
+ return axios.get(`${baseURL}/conversations`);
5
+ };
6
+ const getConversation = (conversationId) => {
7
+ return axios.get(`${baseURL}/conversations/${conversationId}`);
8
+ };
9
+ const listConversations = (filterParams) => {
10
+ return axios.get(`${baseURL}/conversations`, {
11
+ params: filterParams,
12
+ });
13
+ };
14
+ const createConversation = (conversation) => {
15
+ return axios.post(`${baseURL}/conversations`, conversation);
16
+ };
17
+ const addMessage = async (conversation, message) => {
18
+ const room = `/agent-conversations/${conversation.id}`;
19
+ await socket.updateModel(room, {
20
+ ...conversation,
21
+ messages: [...(conversation.messages || []), message],
22
+ });
23
+ return axios.post(`${baseURL}/conversations/${conversation.id}/messages`, message);
24
+ };
25
+ const subscribeToConversation = (conversationId, onUpdate) => {
26
+ const room = `/agent-conversations/${conversationId}`;
27
+ return socket.subscribeToRoom(room, {
28
+ connect: () => { },
29
+ update_model: ({ data: jsonStr }) => {
30
+ const conv = JSON.parse(jsonStr);
31
+ onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(conv);
32
+ },
33
+ });
34
+ };
35
+ return {
36
+ getConversations,
37
+ getConversation,
38
+ listConversations,
39
+ createConversation,
40
+ addMessage,
41
+ subscribeToConversation,
42
+ };
43
+ }
@@ -0,0 +1,44 @@
1
+ export type AgentConversation = {
2
+ id: string;
3
+ app_id: string;
4
+ agent_name: string;
5
+ created_by_id: string;
6
+ messages: AgentMessage[];
7
+ metadata?: Record<string, any>;
8
+ };
9
+ export type AgentMessage = {
10
+ id: string;
11
+ role: "user" | "assistant" | "system";
12
+ reasoning?: {
13
+ start_date: string;
14
+ end_date?: string;
15
+ content: string;
16
+ };
17
+ content?: string | Record<string, any> | null;
18
+ file_urls?: string[] | null;
19
+ tool_calls?: {
20
+ id: string;
21
+ name: string;
22
+ arguments_string: string;
23
+ status: "running" | "success" | "error" | "stopped";
24
+ results?: string | null;
25
+ }[] | null;
26
+ usage?: {
27
+ prompt_tokens?: number;
28
+ completion_tokens?: number;
29
+ } | null;
30
+ hidden?: boolean;
31
+ custom_context?: {
32
+ message: string;
33
+ data: Record<string, any>;
34
+ type: string;
35
+ }[] | null;
36
+ model?: string | null;
37
+ checkpoint_id?: string | null;
38
+ metadata?: {
39
+ created_date: string;
40
+ created_by_email: string;
41
+ created_by_full_name: string | null;
42
+ };
43
+ additional_message_params?: Record<string, any>;
44
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,115 @@
1
+ export interface AppMessageContent {
2
+ content?: string;
3
+ file_urls?: string[];
4
+ custom_context?: unknown;
5
+ additional_message_params?: Record<string, unknown>;
6
+ [key: string]: unknown;
7
+ }
8
+ export interface AppConversationMessage extends AppMessageContent {
9
+ id?: string | null;
10
+ role?: "user" | "assistant" | string;
11
+ }
12
+ export interface AppConversationLike {
13
+ id?: string | null;
14
+ messages?: AppMessageContent[] | null;
15
+ model?: string;
16
+ functions_fail_silently?: boolean;
17
+ }
18
+ export interface DenoProjectLike {
19
+ project_id: string;
20
+ project_name: string;
21
+ app_id: string;
22
+ deployment_name_to_info: Record<string, {
23
+ id: string;
24
+ code: string;
25
+ }>;
26
+ }
27
+ export interface AppLike {
28
+ id?: string;
29
+ conversation?: AppConversationLike | null;
30
+ app_stage?: "pending" | "product_flows" | "ready" | string;
31
+ created_date?: string;
32
+ updated_date?: string;
33
+ created_by?: string;
34
+ organization_id?: string;
35
+ name?: string;
36
+ user_description?: string;
37
+ entities?: Record<string, any>;
38
+ additional_user_data_schema?: any;
39
+ pages?: {
40
+ [key: string]: string;
41
+ };
42
+ components: {
43
+ [key: string]: any;
44
+ };
45
+ layout?: string;
46
+ globals_css?: string;
47
+ agents?: Record<string, any>;
48
+ logo_url?: string;
49
+ slug?: string;
50
+ public_settings?: "private_with_login" | "public_with_login" | "public_without_login" | "workspace_with_login" | string;
51
+ is_blocked?: boolean;
52
+ github_repo_url?: string;
53
+ main_page?: string;
54
+ installable_integrations?: any;
55
+ backend_project?: DenoProjectLike;
56
+ last_deployed_at?: string;
57
+ is_remixable?: boolean;
58
+ remixed_from_app_id?: string;
59
+ hide_entity_created_by?: boolean;
60
+ platform_version?: number;
61
+ enable_username_password?: boolean;
62
+ auth_config?: AuthConfigLike;
63
+ status?: {
64
+ state?: string;
65
+ details?: any;
66
+ last_updated_date?: string;
67
+ };
68
+ custom_instructions?: any;
69
+ frozen_files?: string[];
70
+ deep_coding_mode?: boolean;
71
+ needs_to_add_diff?: boolean;
72
+ installed_integration_context_items?: any[];
73
+ model?: string;
74
+ is_starred?: boolean;
75
+ agents_enabled?: boolean;
76
+ categories?: string[];
77
+ functions?: any;
78
+ function_names?: string[];
79
+ user_entity?: UserEntityLike;
80
+ app_code_hash?: string;
81
+ has_backend_functions_enabled?: boolean;
82
+ }
83
+ export interface UserLike {
84
+ id?: string | null;
85
+ }
86
+ export interface UserEntityLike {
87
+ type: string;
88
+ name: string;
89
+ title?: string;
90
+ properties?: {
91
+ role?: {
92
+ type?: string;
93
+ description?: string;
94
+ enum?: ("admin" | "user" | string)[];
95
+ };
96
+ email?: {
97
+ type?: string;
98
+ description?: string;
99
+ };
100
+ full_name?: {
101
+ type?: string;
102
+ description?: string;
103
+ };
104
+ };
105
+ required: string[];
106
+ }
107
+ export interface AuthConfigLike {
108
+ enable_username_password?: boolean;
109
+ enable_google_login?: boolean;
110
+ enable_microsoft_login?: boolean;
111
+ enable_facebook_login?: boolean;
112
+ sso_provider_name?: string;
113
+ enable_sso_login?: boolean;
114
+ }
115
+ export type LoginInfoResponse = Pick<AppLike, "id" | "name" | "slug" | "logo_url" | "user_description" | "updated_date" | "created_date" | "auth_config" | "platform_version">;
@@ -0,0 +1 @@
1
+ export {};
@@ -6,7 +6,10 @@ import { AxiosInstance } from "axios";
6
6
  * @param {string} serverUrl - Server URL
7
7
  * @returns {Object} Auth module with authentication methods
8
8
  */
9
- export declare function createAuthModule(axios: AxiosInstance, functionsAxiosClient: AxiosInstance, appId: string): {
9
+ export declare function createAuthModule(axios: AxiosInstance, functionsAxiosClient: AxiosInstance, appId: string, options: {
10
+ serverUrl: string;
11
+ onRedirectToLogin?: () => void;
12
+ }): {
10
13
  /**
11
14
  * Get current user information
12
15
  * @returns {Promise<Object>} Current user data
@@ -5,7 +5,7 @@
5
5
  * @param {string} serverUrl - Server URL
6
6
  * @returns {Object} Auth module with authentication methods
7
7
  */
8
- export function createAuthModule(axios, functionsAxiosClient, appId) {
8
+ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
9
9
  return {
10
10
  /**
11
11
  * Get current user information
@@ -32,6 +32,10 @@ export function createAuthModule(axios, functionsAxiosClient, appId) {
32
32
  if (typeof window === "undefined") {
33
33
  throw new Error("Login method can only be used in a browser environment");
34
34
  }
35
+ if (options.onRedirectToLogin) {
36
+ options.onRedirectToLogin();
37
+ return;
38
+ }
35
39
  // If nextUrl is not provided, use the current URL
36
40
  const redirectUrl = nextUrl || window.location.href;
37
41
  // Build the login URL
@@ -77,6 +81,7 @@ export function createAuthModule(axios, functionsAxiosClient, appId) {
77
81
  setToken(token, saveToStorage = true) {
78
82
  if (!token)
79
83
  return;
84
+ // handle token change for axios clients
80
85
  axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
81
86
  functionsAxiosClient.defaults.headers.common["Authorization"] = `Bearer ${token}`;
82
87
  // Save token to localStorage if requested
@@ -1,4 +1,3 @@
1
- import { extractSnapshotIdFromHost } from "../utils/extract-snapshot-id-from-host.js";
2
1
  /**
3
2
  * Creates the functions module for the Base44 SDK
4
3
  * @param {import('axios').AxiosInstance} axios - Axios instance
@@ -36,14 +35,7 @@ export function createFunctionsModule(axios, appId) {
36
35
  formData = data;
37
36
  contentType = "application/json";
38
37
  }
39
- // Extract functions version from the current URL host
40
- const functionsVersion = extractSnapshotIdFromHost();
41
- return axios.post(`/apps/${appId}/functions/${functionName}`, formData || data, {
42
- headers: {
43
- "Content-Type": contentType,
44
- "Base44-Functions-Version": functionsVersion
45
- }
46
- });
38
+ return axios.post(`/apps/${appId}/functions/${functionName}`, formData || data, { headers: { "Content-Type": contentType } });
47
39
  },
48
40
  };
49
41
  }
@@ -0,0 +1,2 @@
1
+ export * from "./app.types.js";
2
+ export * from "./agents.types.js";
@@ -0,0 +1,2 @@
1
+ export * from "./app.types.js";
2
+ export * from "./agents.types.js";
@@ -0,0 +1,9 @@
1
+ export * from "./modules/types.js";
2
+ export type ModelFilterParams = {
3
+ q?: Record<string, any>;
4
+ sort?: string | null;
5
+ sort_by?: string | null;
6
+ limit?: number | null;
7
+ skip?: number | null;
8
+ fields?: string[] | null;
9
+ };
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./modules/types.js";
@@ -23,7 +23,7 @@ export declare class Base44Error extends Error {
23
23
  * @param {string} options.serverUrl - Server URL (needed for login redirect)
24
24
  * @returns {import('axios').AxiosInstance} Configured axios instance
25
25
  */
26
- export declare function createAxiosClient({ baseURL, headers, token, requiresAuth, appId, serverUrl, interceptResponses, }: {
26
+ export declare function createAxiosClient({ baseURL, headers, token, requiresAuth, appId, serverUrl, interceptResponses, onError, onRedirectToLogin, }: {
27
27
  baseURL: string;
28
28
  headers?: Record<string, string>;
29
29
  token?: string;
@@ -31,4 +31,6 @@ export declare function createAxiosClient({ baseURL, headers, token, requiresAut
31
31
  appId: string;
32
32
  serverUrl: string;
33
33
  interceptResponses?: boolean;
34
+ onError?: (error: Error) => void;
35
+ onRedirectToLogin?: () => void;
34
36
  }): import("axios").AxiosInstance;
@@ -64,7 +64,7 @@ function redirectToLogin(serverUrl, appId) {
64
64
  * @param {string} options.serverUrl - Server URL (needed for login redirect)
65
65
  * @returns {import('axios').AxiosInstance} Configured axios instance
66
66
  */
67
- export function createAxiosClient({ baseURL, headers = {}, token, requiresAuth = false, appId, serverUrl, interceptResponses = true, }) {
67
+ export function createAxiosClient({ baseURL, headers = {}, token, requiresAuth = false, appId, serverUrl, interceptResponses = true, onError, onRedirectToLogin, }) {
68
68
  const client = axios.create({
69
69
  baseURL,
70
70
  headers: {
@@ -104,9 +104,12 @@ export function createAxiosClient({ baseURL, headers = {}, token, requiresAuth =
104
104
  console.log("Authentication required. Redirecting to login...");
105
105
  // Use a slight delay to allow the error to propagate first
106
106
  setTimeout(() => {
107
- redirectToLogin(serverUrl, appId);
107
+ onRedirectToLogin
108
+ ? onRedirectToLogin()
109
+ : redirectToLogin(serverUrl, appId);
108
110
  }, 100);
109
111
  }
112
+ onError === null || onError === void 0 ? void 0 : onError(base44Error);
110
113
  return Promise.reject(base44Error);
111
114
  });
112
115
  }
@@ -0,0 +1,47 @@
1
+ import { Socket } from "socket.io-client";
2
+ export type RoomsSocketConfig = {
3
+ serverUrl: string;
4
+ mountPath: string;
5
+ transports: string[];
6
+ appId: string;
7
+ token?: string;
8
+ };
9
+ export type TSocketRoom = string;
10
+ export type TJsonStr = string;
11
+ type RoomsSocketEventsMap = {
12
+ listen: {
13
+ connect: () => Promise<void> | void;
14
+ update_model: (msg: {
15
+ room: string;
16
+ data: TJsonStr;
17
+ }) => Promise<void> | void;
18
+ error: (error: Error) => Promise<void> | void;
19
+ };
20
+ emit: {
21
+ join: (room: string) => void;
22
+ leave: (room: string) => void;
23
+ };
24
+ };
25
+ type TEvent = keyof RoomsSocketEventsMap["listen"];
26
+ type THandler<E extends TEvent> = RoomsSocketEventsMap["listen"][E];
27
+ export type RoomsSocket = ReturnType<typeof RoomsSocket>;
28
+ export declare function RoomsSocket({ config }: {
29
+ config: RoomsSocketConfig;
30
+ }): {
31
+ socket: Socket<{
32
+ connect: () => Promise<void> | void;
33
+ update_model: (msg: {
34
+ room: string;
35
+ data: TJsonStr;
36
+ }) => Promise<void> | void;
37
+ error: (error: Error) => Promise<void> | void;
38
+ }, {
39
+ join: (room: string) => void;
40
+ leave: (room: string) => void;
41
+ }>;
42
+ subscribeToRoom: (room: TSocketRoom, handlers: Partial<{ [k in TEvent]: THandler<k>; }>) => () => void;
43
+ updateConfig: (config: Partial<RoomsSocketConfig>) => void;
44
+ updateModel: (room: string, data: any) => Promise<void>;
45
+ disconnect: () => void;
46
+ };
47
+ export {};
@@ -0,0 +1,115 @@
1
+ import { io } from "socket.io-client";
2
+ import { getAccessToken } from "./auth-utils.js";
3
+ function initializeSocket(config, handlers) {
4
+ var _a;
5
+ const socket = io(config.serverUrl, {
6
+ path: config.mountPath,
7
+ transports: config.transports,
8
+ query: {
9
+ app_id: config.appId,
10
+ token: (_a = config.token) !== null && _a !== void 0 ? _a : getAccessToken(),
11
+ },
12
+ });
13
+ socket.on("connect", async () => {
14
+ var _a;
15
+ console.log("connect", socket.id);
16
+ return (_a = handlers.connect) === null || _a === void 0 ? void 0 : _a.call(handlers);
17
+ });
18
+ socket.on("update_model", async (msg) => {
19
+ var _a;
20
+ return (_a = handlers.update_model) === null || _a === void 0 ? void 0 : _a.call(handlers, msg);
21
+ });
22
+ socket.on("error", async (error) => {
23
+ var _a;
24
+ return (_a = handlers.error) === null || _a === void 0 ? void 0 : _a.call(handlers, error);
25
+ });
26
+ socket.on("connect_error", async (error) => {
27
+ var _a;
28
+ console.error("connect_error", error);
29
+ return (_a = handlers.error) === null || _a === void 0 ? void 0 : _a.call(handlers, error);
30
+ });
31
+ return socket;
32
+ }
33
+ export function RoomsSocket({ config }) {
34
+ let currentConfig = { ...config };
35
+ const roomsToListeners = {};
36
+ const handlers = {
37
+ connect: async () => {
38
+ const promises = [];
39
+ Object.keys(roomsToListeners).forEach((room) => {
40
+ joinRoom(room);
41
+ const listeners = getListeners(room);
42
+ listeners === null || listeners === void 0 ? void 0 : listeners.forEach(({ connect }) => {
43
+ const promise = async () => connect === null || connect === void 0 ? void 0 : connect();
44
+ promises.push(promise());
45
+ });
46
+ });
47
+ await Promise.all(promises);
48
+ },
49
+ update_model: async (msg) => {
50
+ const listeners = getListeners(msg.room);
51
+ const promises = listeners.map((listener) => { var _a; return (_a = listener.update_model) === null || _a === void 0 ? void 0 : _a.call(listener, msg); });
52
+ await Promise.all(promises);
53
+ },
54
+ error: async (error) => {
55
+ console.error("error", error);
56
+ const promises = Object.values(roomsToListeners)
57
+ .flat()
58
+ .map((listener) => { var _a; return (_a = listener.error) === null || _a === void 0 ? void 0 : _a.call(listener, error); });
59
+ await Promise.all(promises);
60
+ },
61
+ };
62
+ let socket = initializeSocket(config, handlers);
63
+ function cleanup() {
64
+ disconnect();
65
+ }
66
+ function disconnect() {
67
+ if (socket) {
68
+ socket.disconnect();
69
+ }
70
+ }
71
+ function updateConfig(config) {
72
+ cleanup();
73
+ currentConfig = {
74
+ ...currentConfig,
75
+ ...config,
76
+ };
77
+ socket = initializeSocket(currentConfig, handlers);
78
+ }
79
+ function joinRoom(room) {
80
+ socket.emit("join", room);
81
+ }
82
+ function leaveRoom(room) {
83
+ socket.emit("leave", room);
84
+ }
85
+ async function updateModel(room, data) {
86
+ var _a;
87
+ const dataStr = JSON.stringify(data);
88
+ return (_a = handlers.update_model) === null || _a === void 0 ? void 0 : _a.call(handlers, { room, data: dataStr });
89
+ }
90
+ function getListeners(room) {
91
+ return roomsToListeners[room];
92
+ }
93
+ const subscribeToRoom = (room, handlers) => {
94
+ if (!roomsToListeners[room]) {
95
+ joinRoom(room);
96
+ roomsToListeners[room] = [];
97
+ }
98
+ roomsToListeners[room].push(handlers);
99
+ return () => {
100
+ var _a, _b;
101
+ roomsToListeners[room] =
102
+ (_b = (_a = roomsToListeners[room]) === null || _a === void 0 ? void 0 : _a.filter((listener) => listener !== handlers)) !== null && _b !== void 0 ? _b : [];
103
+ if (roomsToListeners[room].length === 0) {
104
+ leaveRoom(room);
105
+ }
106
+ };
107
+ };
108
+ return {
109
+ socket,
110
+ subscribeToRoom,
111
+ updateConfig,
112
+ updateModel,
113
+ disconnect,
114
+ };
115
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.7.0-pr.29.d287222",
3
+ "version": "0.7.2-dev.65e038a",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -19,7 +19,8 @@
19
19
  "prepublishOnly": "npm run build"
20
20
  },
21
21
  "dependencies": {
22
- "axios": "^1.6.2"
22
+ "axios": "^1.6.2",
23
+ "socket.io-client": "^4.7.5"
23
24
  },
24
25
  "devDependencies": {
25
26
  "@vitest/coverage-istanbul": "^1.0.0",
@@ -1,7 +0,0 @@
1
- /**
2
- * Extracts the snapshot ID or environment type from the current hostname
3
- * Used to determine which backend function deployment to call
4
- *
5
- * @returns {string} The snapshot ID for checkpoints, 'preview' for preview URLs, or 'prod' for production
6
- */
7
- export declare function extractSnapshotIdFromHost(): string;
@@ -1,30 +0,0 @@
1
- /**
2
- * Extracts the snapshot ID or environment type from the current hostname
3
- * Used to determine which backend function deployment to call
4
- *
5
- * @returns {string} The snapshot ID for checkpoints, 'preview' for preview URLs, or 'prod' for production
6
- */
7
- export function extractSnapshotIdFromHost() {
8
- if (typeof window === "undefined") {
9
- return "prod";
10
- }
11
- const hostname = window.location.hostname;
12
- // Check if it's a checkpoint URL
13
- if (hostname.startsWith("checkpoint--")) {
14
- // Format: checkpoint--{app_id}--{snapshot_id}.domain
15
- const parts = hostname.split("--");
16
- if (parts.length >= 3) {
17
- // Extract snapshot_id (last part before the domain)
18
- const snapshotPart = parts[2];
19
- // Remove domain extension if present
20
- const snapshotId = snapshotPart.split(".")[0];
21
- return snapshotId;
22
- }
23
- }
24
- // Check if it's a preview URL
25
- if (hostname.startsWith("preview--")) {
26
- return "preview";
27
- }
28
- // Production URLs - return "prod"
29
- return "prod";
30
- }