@base44-preview/sdk 0.8.5-pr.52.f01053f → 0.8.6-pr.52.c427ddb

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.js CHANGED
@@ -30,9 +30,15 @@ export function createClient(config) {
30
30
  appId,
31
31
  token,
32
32
  };
33
- const socket = RoomsSocket({
34
- config: socketConfig,
35
- });
33
+ let socket = null;
34
+ const getSocket = () => {
35
+ if (!socket) {
36
+ socket = RoomsSocket({
37
+ config: socketConfig,
38
+ });
39
+ }
40
+ return socket;
41
+ };
36
42
  const headers = {
37
43
  ...optionalHeaders,
38
44
  "X-App-Id": String(appId),
@@ -78,7 +84,7 @@ export function createClient(config) {
78
84
  functions: createFunctionsModule(functionsAxiosClient, appId),
79
85
  agents: createAgentsModule({
80
86
  axios: axiosClient,
81
- socket,
87
+ getSocket,
82
88
  appId,
83
89
  serverUrl,
84
90
  token,
@@ -86,7 +92,9 @@ export function createClient(config) {
86
92
  appLogs: createAppLogsModule(axiosClient, appId),
87
93
  users: createUsersModule(axiosClient, appId),
88
94
  cleanup: () => {
89
- socket.disconnect();
95
+ if (socket) {
96
+ socket.disconnect();
97
+ }
90
98
  },
91
99
  };
92
100
  const serviceRoleModules = {
@@ -97,14 +105,16 @@ export function createClient(config) {
97
105
  functions: createFunctionsModule(serviceRoleFunctionsAxiosClient, appId),
98
106
  agents: createAgentsModule({
99
107
  axios: serviceRoleAxiosClient,
100
- socket,
108
+ getSocket,
101
109
  appId,
102
110
  serverUrl,
103
111
  token,
104
112
  }),
105
113
  appLogs: createAppLogsModule(serviceRoleAxiosClient, appId),
106
114
  cleanup: () => {
107
- socket.disconnect();
115
+ if (socket) {
116
+ socket.disconnect();
117
+ }
108
118
  },
109
119
  };
110
120
  // Always try to get token from localStorage or URL parameters
@@ -140,9 +150,12 @@ export function createClient(config) {
140
150
  */
141
151
  setToken(newToken) {
142
152
  userModules.auth.setToken(newToken);
143
- socket.updateConfig({
144
- token: newToken,
145
- });
153
+ if (socket) {
154
+ socket.updateConfig({
155
+ token: newToken,
156
+ });
157
+ }
158
+ socketConfig.token = newToken;
146
159
  },
147
160
  /**
148
161
  * Get current configuration
@@ -4,12 +4,12 @@ import { AxiosInstance } from "axios";
4
4
  import { ModelFilterParams } from "../types.js";
5
5
  export type AgentsModuleConfig = {
6
6
  axios: AxiosInstance;
7
- socket: ReturnType<typeof RoomsSocket>;
7
+ getSocket: () => ReturnType<typeof RoomsSocket>;
8
8
  appId: string;
9
9
  serverUrl?: string;
10
10
  token?: string;
11
11
  };
12
- export declare function createAgentsModule({ axios, socket, appId, serverUrl, token, }: AgentsModuleConfig): {
12
+ export declare function createAgentsModule({ axios, getSocket, appId, serverUrl, token, }: AgentsModuleConfig): {
13
13
  getConversations: () => Promise<AgentConversation[]>;
14
14
  getConversation: (conversationId: string) => Promise<AgentConversation | undefined>;
15
15
  listConversations: (filterParams: ModelFilterParams) => Promise<AgentConversation[]>;
@@ -1,5 +1,5 @@
1
1
  import { getAccessToken } from "../utils/auth-utils.js";
2
- export function createAgentsModule({ axios, socket, appId, serverUrl, token, }) {
2
+ export function createAgentsModule({ axios, getSocket, appId, serverUrl, token, }) {
3
3
  const baseURL = `/apps/${appId}/agents`;
4
4
  const getConversations = () => {
5
5
  return axios.get(`${baseURL}/conversations`);
@@ -17,6 +17,7 @@ export function createAgentsModule({ axios, socket, appId, serverUrl, token, })
17
17
  };
18
18
  const addMessage = async (conversation, message) => {
19
19
  const room = `/agent-conversations/${conversation.id}`;
20
+ const socket = getSocket();
20
21
  await socket.updateModel(room, {
21
22
  ...conversation,
22
23
  messages: [...(conversation.messages || []), message],
@@ -25,6 +26,7 @@ export function createAgentsModule({ axios, socket, appId, serverUrl, token, })
25
26
  };
26
27
  const subscribeToConversation = (conversationId, onUpdate) => {
27
28
  const room = `/agent-conversations/${conversationId}`;
29
+ const socket = getSocket();
28
30
  return socket.subscribeToRoom(room, {
29
31
  connect: () => { },
30
32
  update_model: ({ data: jsonStr }) => {
@@ -1,12 +1,10 @@
1
1
  export declare const appParams: {
2
2
  appId?: undefined;
3
- serverUrl?: undefined;
4
3
  token?: undefined;
5
4
  fromUrl?: undefined;
6
5
  functionsVersion?: undefined;
7
6
  } | {
8
7
  appId: any;
9
- serverUrl: any;
10
8
  token: any;
11
9
  fromUrl: any;
12
10
  functionsVersion: any;
@@ -34,8 +34,7 @@ const getAppParams = () => {
34
34
  localStorage.removeItem('token');
35
35
  }
36
36
  return {
37
- appId: getAppParamValue("app_id", { defaultValue: import.meta.env.VITE_BASE44_APP_ID }),
38
- serverUrl: getAppParamValue("server_url", { defaultValue: import.meta.env.VITE_BASE44_BACKEND_URL }),
37
+ appId: getAppParamValue("app_id"),
39
38
  token: getAppParamValue("access_token", { removeFromUrl: true }),
40
39
  fromUrl: getAppParamValue("from_url", { defaultValue: window.location.href }),
41
40
  functionsVersion: getAppParamValue("functions_version", { defaultValue: import.meta.env.VITE_BASE44_FUNCTIONS_VERSION }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.5-pr.52.f01053f",
3
+ "version": "0.8.6-pr.52.c427ddb",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",