@base44-preview/sdk 0.8.4-pr.53.f19b952 → 0.8.4-pr.55.172cc47

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
@@ -29,9 +29,15 @@ export function createClient(config) {
29
29
  appId,
30
30
  token,
31
31
  };
32
- const socket = RoomsSocket({
33
- config: socketConfig,
34
- });
32
+ let socket = null;
33
+ const getSocket = () => {
34
+ if (!socket) {
35
+ socket = RoomsSocket({
36
+ config: socketConfig,
37
+ });
38
+ }
39
+ return socket;
40
+ };
35
41
  const headers = {
36
42
  ...optionalHeaders,
37
43
  "X-App-Id": String(appId),
@@ -77,14 +83,16 @@ export function createClient(config) {
77
83
  functions: createFunctionsModule(functionsAxiosClient, appId),
78
84
  agents: createAgentsModule({
79
85
  axios: axiosClient,
80
- socket,
86
+ getSocket,
81
87
  appId,
82
88
  serverUrl,
83
89
  token,
84
90
  }),
85
91
  appLogs: createAppLogsModule(axiosClient, appId),
86
92
  cleanup: () => {
87
- socket.disconnect();
93
+ if (socket) {
94
+ socket.disconnect();
95
+ }
88
96
  },
89
97
  };
90
98
  const serviceRoleModules = {
@@ -95,14 +103,16 @@ export function createClient(config) {
95
103
  functions: createFunctionsModule(serviceRoleFunctionsAxiosClient, appId),
96
104
  agents: createAgentsModule({
97
105
  axios: serviceRoleAxiosClient,
98
- socket,
106
+ getSocket,
99
107
  appId,
100
108
  serverUrl,
101
109
  token,
102
110
  }),
103
111
  appLogs: createAppLogsModule(serviceRoleAxiosClient, appId),
104
112
  cleanup: () => {
105
- socket.disconnect();
113
+ if (socket) {
114
+ socket.disconnect();
115
+ }
106
116
  },
107
117
  };
108
118
  // Always try to get token from localStorage or URL parameters
@@ -138,9 +148,12 @@ export function createClient(config) {
138
148
  */
139
149
  setToken(newToken) {
140
150
  userModules.auth.setToken(newToken);
141
- socket.updateConfig({
142
- token: newToken,
143
- });
151
+ if (socket) {
152
+ socket.updateConfig({
153
+ token: newToken,
154
+ });
155
+ }
156
+ socketConfig.token = newToken;
144
157
  },
145
158
  /**
146
159
  * Get current configuration
@@ -172,7 +185,6 @@ export function createClientFromRequest(request) {
172
185
  const appId = request.headers.get("Base44-App-Id");
173
186
  const serverUrlHeader = request.headers.get("Base44-Api-Url");
174
187
  const functionsVersion = request.headers.get("Base44-Functions-Version");
175
- const clientIpHeader = request.headers.get("Base44-Client-IP");
176
188
  if (!appId) {
177
189
  throw new Error("Base44-App-Id header is required, but is was not found on the request");
178
190
  }
@@ -195,17 +207,11 @@ export function createClientFromRequest(request) {
195
207
  }
196
208
  userToken = authHeader.split(" ")[1];
197
209
  }
198
- // Prepare additional headers to propagate
199
- const additionalHeaders = {};
200
- if (clientIpHeader) {
201
- additionalHeaders["Base44-Client-IP"] = clientIpHeader;
202
- }
203
210
  return createClient({
204
211
  serverUrl: serverUrlHeader || "https://base44.app",
205
212
  appId,
206
213
  token: userToken,
207
214
  serviceToken: serviceRoleToken,
208
215
  functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined,
209
- headers: additionalHeaders,
210
216
  });
211
217
  }
@@ -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 }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.4-pr.53.f19b952",
3
+ "version": "0.8.4-pr.55.172cc47",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",