@base44-preview/sdk 0.7.0-pr.27.2a9d388 → 0.7.0-pr.27.9034994

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,6 +1,7 @@
1
1
  export type CreateClientOptions = {
2
2
  onError?: (error: Error) => void;
3
3
  };
4
+ export type Base44Client = ReturnType<typeof createClient>;
4
5
  /**
5
6
  * Create a Base44 client instance
6
7
  * @param {Object} config - Client configuration
@@ -17,7 +18,9 @@ export declare function createClient(config: {
17
18
  token?: string;
18
19
  serviceToken?: string;
19
20
  requiresAuth?: boolean;
21
+ functionsVersion?: string;
20
22
  options?: CreateClientOptions;
23
+ onRedirectToLogin?: () => void;
21
24
  }): {
22
25
  /**
23
26
  * Set authentication token for all requests
@@ -43,13 +46,17 @@ export declare function createClient(config: {
43
46
  invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
44
47
  };
45
48
  agents: {
46
- getConversations: () => Promise<import("./modules/agents.types.js").AgentConversation[]>;
47
- getConversation: (conversationId: string) => Promise<import("./modules/agents.types.js").AgentConversation | undefined>;
48
- listConversations: (filterParams: any) => Promise<import("./modules/agents.types.js").AgentConversation[]>;
49
- createConversation: (conversation: any) => Promise<import("./modules/agents.types.js").AgentConversation>;
50
- addMessage: (conversation: any, message: any) => Promise<import("./modules/agents.types.js").AgentMessage>;
51
- subscribeToConversation: (conversationId: string, onUpdate: any) => () => void;
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;
52
58
  };
59
+ cleanup: () => void;
53
60
  };
54
61
  entities: {};
55
62
  integrations: {};
@@ -69,13 +76,17 @@ export declare function createClient(config: {
69
76
  invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
70
77
  };
71
78
  agents: {
72
- getConversations: () => Promise<import("./modules/agents.types.js").AgentConversation[]>;
73
- getConversation: (conversationId: string) => Promise<import("./modules/agents.types.js").AgentConversation | undefined>;
74
- listConversations: (filterParams: any) => Promise<import("./modules/agents.types.js").AgentConversation[]>;
75
- createConversation: (conversation: any) => Promise<import("./modules/agents.types.js").AgentConversation>;
76
- addMessage: (conversation: any, message: any) => Promise<import("./modules/agents.types.js").AgentMessage>;
77
- subscribeToConversation: (conversationId: string, onUpdate: any) => () => void;
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;
78
88
  };
89
+ cleanup: () => void;
79
90
  };
80
91
  export declare function createClientFromRequest(request: Request): {
81
92
  /**
@@ -102,13 +113,17 @@ export declare function createClientFromRequest(request: Request): {
102
113
  invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
103
114
  };
104
115
  agents: {
105
- getConversations: () => Promise<import("./modules/agents.types.js").AgentConversation[]>;
106
- getConversation: (conversationId: string) => Promise<import("./modules/agents.types.js").AgentConversation | undefined>;
107
- listConversations: (filterParams: any) => Promise<import("./modules/agents.types.js").AgentConversation[]>;
108
- createConversation: (conversation: any) => Promise<import("./modules/agents.types.js").AgentConversation>;
109
- addMessage: (conversation: any, message: any) => Promise<import("./modules/agents.types.js").AgentMessage>;
110
- subscribeToConversation: (conversationId: string, onUpdate: any) => () => void;
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;
111
125
  };
126
+ cleanup: () => void;
112
127
  };
113
128
  entities: {};
114
129
  integrations: {};
@@ -128,11 +143,15 @@ export declare function createClientFromRequest(request: Request): {
128
143
  invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
129
144
  };
130
145
  agents: {
131
- getConversations: () => Promise<import("./modules/agents.types.js").AgentConversation[]>;
132
- getConversation: (conversationId: string) => Promise<import("./modules/agents.types.js").AgentConversation | undefined>;
133
- listConversations: (filterParams: any) => Promise<import("./modules/agents.types.js").AgentConversation[]>;
134
- createConversation: (conversation: any) => Promise<import("./modules/agents.types.js").AgentConversation>;
135
- addMessage: (conversation: any, message: any) => Promise<import("./modules/agents.types.js").AgentMessage>;
136
- subscribeToConversation: (conversationId: string, onUpdate: any) => () => void;
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;
137
155
  };
156
+ cleanup: () => void;
138
157
  };
package/dist/client.js CHANGED
@@ -18,7 +18,7 @@ import { RoomsSocket } from "./utils/socket-utils.js";
18
18
  * @returns {Object} Base44 client instance
19
19
  */
20
20
  export function createClient(config) {
21
- const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, options, } = config;
21
+ const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, options, functionsVersion, onRedirectToLogin, } = config;
22
22
  const socketConfig = {
23
23
  serverUrl,
24
24
  mountPath: "/ws-user-apps/socket.io/",
@@ -29,59 +29,70 @@ export function createClient(config) {
29
29
  const socket = RoomsSocket({
30
30
  config: socketConfig,
31
31
  });
32
+ const headers = {
33
+ "X-App-Id": String(appId),
34
+ };
35
+ const functionHeaders = functionsVersion
36
+ ? {
37
+ ...headers,
38
+ "Base44-Functions-Version": functionsVersion,
39
+ }
40
+ : headers;
32
41
  const axiosClient = createAxiosClient({
33
42
  baseURL: `${serverUrl}/api`,
34
- headers: {
35
- "X-App-Id": String(appId),
36
- },
43
+ headers,
37
44
  token,
38
45
  requiresAuth,
39
46
  appId,
40
47
  serverUrl,
41
48
  onError: options === null || options === void 0 ? void 0 : options.onError,
49
+ onRedirectToLogin,
42
50
  });
43
51
  const functionsAxiosClient = createAxiosClient({
44
52
  baseURL: `${serverUrl}/api`,
45
- headers: {
46
- "X-App-Id": String(appId),
47
- },
53
+ headers: functionHeaders,
48
54
  token,
49
55
  requiresAuth,
50
56
  appId,
51
57
  serverUrl,
52
58
  interceptResponses: false,
53
59
  onError: options === null || options === void 0 ? void 0 : options.onError,
60
+ onRedirectToLogin,
54
61
  });
55
62
  const serviceRoleAxiosClient = createAxiosClient({
56
63
  baseURL: `${serverUrl}/api`,
57
- headers: {
58
- "X-App-Id": String(appId),
59
- },
64
+ headers,
60
65
  token: serviceToken,
61
66
  serverUrl,
62
67
  appId,
63
68
  onError: options === null || options === void 0 ? void 0 : options.onError,
69
+ onRedirectToLogin,
64
70
  });
65
71
  const serviceRoleFunctionsAxiosClient = createAxiosClient({
66
72
  baseURL: `${serverUrl}/api`,
67
- headers: {
68
- "X-App-Id": String(appId),
69
- },
73
+ headers: functionHeaders,
70
74
  token: serviceToken,
71
75
  serverUrl,
72
76
  appId,
73
77
  interceptResponses: false,
78
+ onRedirectToLogin,
74
79
  });
75
80
  const userModules = {
76
81
  entities: createEntitiesModule(axiosClient, appId),
77
82
  integrations: createIntegrationsModule(axiosClient, appId),
78
- auth: createAuthModule(axiosClient, functionsAxiosClient, appId),
83
+ auth: createAuthModule(axiosClient, functionsAxiosClient, appId, {
84
+ onRedirectToLogin,
85
+ serverUrl,
86
+ }),
79
87
  functions: createFunctionsModule(functionsAxiosClient, appId),
80
88
  agents: createAgentsModule({
81
89
  axios: axiosClient,
82
90
  socket,
83
91
  appId,
84
92
  }),
93
+ cleanup: () => {
94
+ socket.disconnect();
95
+ },
85
96
  };
86
97
  const serviceRoleModules = {
87
98
  entities: createEntitiesModule(serviceRoleAxiosClient, appId),
@@ -93,6 +104,9 @@ export function createClient(config) {
93
104
  socket,
94
105
  appId,
95
106
  }),
107
+ cleanup: () => {
108
+ socket.disconnect();
109
+ },
96
110
  };
97
111
  // Always try to get token from localStorage or URL parameters
98
112
  if (typeof window !== "undefined") {
@@ -100,9 +114,6 @@ export function createClient(config) {
100
114
  const accessToken = token || getAccessToken();
101
115
  if (accessToken) {
102
116
  userModules.auth.setToken(accessToken);
103
- socket.updateConfig({
104
- token: accessToken,
105
- });
106
117
  }
107
118
  }
108
119
  // If authentication is required, verify token and redirect to login if needed
@@ -163,6 +174,7 @@ export function createClientFromRequest(request) {
163
174
  const serviceRoleAuthHeader = request.headers.get("Base44-Service-Authorization");
164
175
  const appId = request.headers.get("Base44-App-Id");
165
176
  const serverUrlHeader = request.headers.get("Base44-Api-Url");
177
+ const functionsVersion = request.headers.get("Base44-Functions-Version");
166
178
  if (!appId) {
167
179
  throw new Error("Base44-App-Id header is required, but is was not found on the request");
168
180
  }
@@ -190,5 +202,6 @@ export function createClientFromRequest(request) {
190
202
  appId,
191
203
  token: userToken,
192
204
  serviceToken: serviceRoleToken,
205
+ functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined,
193
206
  });
194
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";
@@ -1,6 +1,7 @@
1
1
  import { RoomsSocket } from "../utils/socket-utils.js";
2
2
  import { AgentConversation, AgentMessage } from "./agents.types.js";
3
3
  import { AxiosInstance } from "axios";
4
+ import { ModelFilterParams } from "../types.js";
4
5
  export type AgentsModuleConfig = {
5
6
  axios: AxiosInstance;
6
7
  socket: ReturnType<typeof RoomsSocket>;
@@ -9,8 +10,11 @@ export type AgentsModuleConfig = {
9
10
  export declare function createAgentsModule({ axios, socket, appId, }: AgentsModuleConfig): {
10
11
  getConversations: () => Promise<AgentConversation[]>;
11
12
  getConversation: (conversationId: string) => Promise<AgentConversation | undefined>;
12
- listConversations: (filterParams: any) => Promise<AgentConversation[]>;
13
- createConversation: (conversation: any) => Promise<AgentConversation>;
14
- addMessage: (conversation: any, message: any) => Promise<AgentMessage>;
15
- subscribeToConversation: (conversationId: string, onUpdate: any) => () => void;
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;
16
20
  };
@@ -1,5 +1,4 @@
1
1
  export function createAgentsModule({ axios, socket, appId, }) {
2
- let currentConversation = null;
3
2
  const baseURL = `/apps/${appId}/agents`;
4
3
  const getConversations = () => {
5
4
  return axios.get(`${baseURL}/conversations`);
@@ -15,32 +14,21 @@ export function createAgentsModule({ axios, socket, appId, }) {
15
14
  const createConversation = (conversation) => {
16
15
  return axios.post(`${baseURL}/conversations`, conversation);
17
16
  };
18
- const addMessage = (conversation, message) => {
19
- // this whole trick with current conversation so that we can call the onUpdateModel with the latest messages
20
- let convLatestMessages = null;
21
- if (currentConversation && currentConversation.id === conversation.id) {
22
- convLatestMessages = currentConversation.messages;
23
- }
24
- else {
25
- currentConversation = conversation;
26
- convLatestMessages = conversation.messages;
27
- }
28
- conversation.messages = [...convLatestMessages, message];
29
- socket.handlers.update_model({
30
- room: `/agent-conversations/${conversation.id}`,
31
- data: JSON.stringify(conversation),
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],
32
22
  });
33
23
  return axios.post(`${baseURL}/conversations/${conversation.id}/messages`, message);
34
24
  };
35
25
  const subscribeToConversation = (conversationId, onUpdate) => {
36
- return socket.subscribeToRoom(`/agent-conversations/${conversationId}`, {
26
+ const room = `/agent-conversations/${conversationId}`;
27
+ return socket.subscribeToRoom(room, {
37
28
  connect: () => { },
38
29
  update_model: ({ data: jsonStr }) => {
39
- const data = JSON.parse(jsonStr);
40
- if (currentConversation && currentConversation.id === data.id) {
41
- currentConversation = data;
42
- }
43
- onUpdate(data);
30
+ const conv = JSON.parse(jsonStr);
31
+ onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(conv);
44
32
  },
45
33
  });
46
34
  };
@@ -9,7 +9,7 @@ export type AgentConversation = {
9
9
  export type AgentMessage = {
10
10
  id: string;
11
11
  role: "user" | "assistant" | "system";
12
- reasoning: {
12
+ reasoning?: {
13
13
  start_date: string;
14
14
  end_date?: string;
15
15
  content: string;
@@ -23,7 +23,7 @@ export type AgentMessage = {
23
23
  status: "running" | "success" | "error" | "stopped";
24
24
  results?: string | null;
25
25
  }[] | null;
26
- usage: {
26
+ usage?: {
27
27
  prompt_tokens?: number;
28
28
  completion_tokens?: number;
29
29
  } | null;
@@ -33,8 +33,8 @@ export type AgentMessage = {
33
33
  data: Record<string, any>;
34
34
  type: string;
35
35
  }[] | null;
36
- model: string | null;
37
- checkpoint_id: string | null;
36
+ model?: string | null;
37
+ checkpoint_id?: string | null;
38
38
  metadata?: {
39
39
  created_date: string;
40
40
  created_by_email: string;
@@ -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
@@ -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, onError, }: {
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;
@@ -32,4 +32,5 @@ export declare function createAxiosClient({ baseURL, headers, token, requiresAut
32
32
  serverUrl: string;
33
33
  interceptResponses?: boolean;
34
34
  onError?: (error: Error) => void;
35
+ onRedirectToLogin?: () => void;
35
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, onError, }) {
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,7 +104,9 @@ 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
  }
110
112
  onError === null || onError === void 0 ? void 0 : onError(base44Error);
@@ -10,11 +10,12 @@ export type TSocketRoom = string;
10
10
  export type TJsonStr = string;
11
11
  type RoomsSocketEventsMap = {
12
12
  listen: {
13
- connect: () => void;
13
+ connect: () => Promise<void> | void;
14
14
  update_model: (msg: {
15
15
  room: string;
16
16
  data: TJsonStr;
17
- }) => void;
17
+ }) => Promise<void> | void;
18
+ error: (error: Error) => Promise<void> | void;
18
19
  };
19
20
  emit: {
20
21
  join: (room: string) => void;
@@ -22,26 +23,25 @@ type RoomsSocketEventsMap = {
22
23
  };
23
24
  };
24
25
  type TEvent = keyof RoomsSocketEventsMap["listen"];
25
- type THandler<E extends TEvent> = (...args: Parameters<RoomsSocketEventsMap["listen"][E]>) => void;
26
+ type THandler<E extends TEvent> = RoomsSocketEventsMap["listen"][E];
27
+ export type RoomsSocket = ReturnType<typeof RoomsSocket>;
26
28
  export declare function RoomsSocket({ config }: {
27
29
  config: RoomsSocketConfig;
28
30
  }): {
29
31
  socket: Socket<{
30
- connect: () => void;
32
+ connect: () => Promise<void> | void;
31
33
  update_model: (msg: {
32
34
  room: string;
33
35
  data: TJsonStr;
34
- }) => void;
36
+ }) => Promise<void> | void;
37
+ error: (error: Error) => Promise<void> | void;
35
38
  }, {
36
39
  join: (room: string) => void;
37
40
  leave: (room: string) => void;
38
41
  }>;
39
- subscribeToRoom: (room: TSocketRoom, handlers: { [k in TEvent]: THandler<k>; }) => () => void;
42
+ subscribeToRoom: (room: TSocketRoom, handlers: Partial<{ [k in TEvent]: THandler<k>; }>) => () => void;
40
43
  updateConfig: (config: Partial<RoomsSocketConfig>) => void;
41
- handlers: {
42
- connect: THandler<"connect">;
43
- update_model: THandler<"update_model">;
44
- };
44
+ updateModel: (room: string, data: any) => Promise<void>;
45
45
  disconnect: () => void;
46
46
  };
47
47
  export {};
@@ -1,19 +1,32 @@
1
1
  import { io } from "socket.io-client";
2
+ import { getAccessToken } from "./auth-utils.js";
2
3
  function initializeSocket(config, handlers) {
4
+ var _a;
3
5
  const socket = io(config.serverUrl, {
4
6
  path: config.mountPath,
5
7
  transports: config.transports,
6
8
  query: {
7
- appId: config.appId,
8
- token: config.token,
9
+ app_id: config.appId,
10
+ token: (_a = config.token) !== null && _a !== void 0 ? _a : getAccessToken(),
9
11
  },
10
12
  });
11
- socket.on("connect", () => {
13
+ socket.on("connect", async () => {
14
+ var _a;
12
15
  console.log("connect", socket.id);
13
- handlers.connect();
16
+ return (_a = handlers.connect) === null || _a === void 0 ? void 0 : _a.call(handlers);
14
17
  });
15
- socket.on("update_model", (msg) => {
16
- handlers.update_model(msg);
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);
17
30
  });
18
31
  return socket;
19
32
  }
@@ -21,22 +34,29 @@ export function RoomsSocket({ config }) {
21
34
  let currentConfig = { ...config };
22
35
  const roomsToListeners = {};
23
36
  const handlers = {
24
- connect: () => {
37
+ connect: async () => {
38
+ const promises = [];
25
39
  Object.keys(roomsToListeners).forEach((room) => {
26
- var _a;
27
40
  joinRoom(room);
28
- (_a = getListeners(room)) === null || _a === void 0 ? void 0 : _a.forEach(({ connect: connectHandler }) => {
29
- connectHandler();
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());
30
45
  });
31
46
  });
47
+ await Promise.all(promises);
32
48
  },
33
- update_model: (msg) => {
34
- var _a;
35
- if (roomsToListeners[msg.room]) {
36
- (_a = getListeners(msg.room)) === null || _a === void 0 ? void 0 : _a.forEach(({ update_model }) => {
37
- update_model(msg);
38
- });
39
- }
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);
40
60
  },
41
61
  };
42
62
  let socket = initializeSocket(config, handlers);
@@ -62,6 +82,11 @@ export function RoomsSocket({ config }) {
62
82
  function leaveRoom(room) {
63
83
  socket.emit("leave", room);
64
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
+ }
65
90
  function getListeners(room) {
66
91
  return roomsToListeners[room];
67
92
  }
@@ -72,14 +97,19 @@ export function RoomsSocket({ config }) {
72
97
  }
73
98
  roomsToListeners[room].push(handlers);
74
99
  return () => {
75
- roomsToListeners[room] = roomsToListeners[room].filter((listener) => listener !== handlers);
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
+ }
76
106
  };
77
107
  };
78
108
  return {
79
109
  socket,
80
110
  subscribeToRoom,
81
111
  updateConfig,
82
- handlers,
112
+ updateModel,
83
113
  disconnect,
84
114
  };
85
115
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.7.0-pr.27.2a9d388",
3
+ "version": "0.7.0-pr.27.9034994",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",