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

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
@@ -50,6 +50,7 @@ export declare function createClient(config: {
50
50
  addMessage: (conversation: any, message: any) => Promise<import("./modules/agents.types.js").AgentMessage>;
51
51
  subscribeToConversation: (conversationId: string, onUpdate: any) => () => void;
52
52
  };
53
+ cleanup: () => void;
53
54
  };
54
55
  entities: {};
55
56
  integrations: {};
@@ -76,6 +77,7 @@ export declare function createClient(config: {
76
77
  addMessage: (conversation: any, message: any) => Promise<import("./modules/agents.types.js").AgentMessage>;
77
78
  subscribeToConversation: (conversationId: string, onUpdate: any) => () => void;
78
79
  };
80
+ cleanup: () => void;
79
81
  };
80
82
  export declare function createClientFromRequest(request: Request): {
81
83
  /**
@@ -109,6 +111,7 @@ export declare function createClientFromRequest(request: Request): {
109
111
  addMessage: (conversation: any, message: any) => Promise<import("./modules/agents.types.js").AgentMessage>;
110
112
  subscribeToConversation: (conversationId: string, onUpdate: any) => () => void;
111
113
  };
114
+ cleanup: () => void;
112
115
  };
113
116
  entities: {};
114
117
  integrations: {};
@@ -135,4 +138,5 @@ export declare function createClientFromRequest(request: Request): {
135
138
  addMessage: (conversation: any, message: any) => Promise<import("./modules/agents.types.js").AgentMessage>;
136
139
  subscribeToConversation: (conversationId: string, onUpdate: any) => () => void;
137
140
  };
141
+ cleanup: () => void;
138
142
  };
package/dist/client.js CHANGED
@@ -82,6 +82,9 @@ export function createClient(config) {
82
82
  socket,
83
83
  appId,
84
84
  }),
85
+ cleanup: () => {
86
+ socket.disconnect();
87
+ },
85
88
  };
86
89
  const serviceRoleModules = {
87
90
  entities: createEntitiesModule(serviceRoleAxiosClient, appId),
@@ -93,6 +96,9 @@ export function createClient(config) {
93
96
  socket,
94
97
  appId,
95
98
  }),
99
+ cleanup: () => {
100
+ socket.disconnect();
101
+ },
96
102
  };
97
103
  // Always try to get token from localStorage or URL parameters
98
104
  if (typeof window !== "undefined") {
@@ -100,9 +106,6 @@ export function createClient(config) {
100
106
  const accessToken = token || getAccessToken();
101
107
  if (accessToken) {
102
108
  userModules.auth.setToken(accessToken);
103
- socket.updateConfig({
104
- token: accessToken,
105
- });
106
109
  }
107
110
  }
108
111
  // If authentication is required, verify token and redirect to login if needed
@@ -15,6 +15,7 @@ type RoomsSocketEventsMap = {
15
15
  room: string;
16
16
  data: TJsonStr;
17
17
  }) => void;
18
+ error: (error: Error) => void;
18
19
  };
19
20
  emit: {
20
21
  join: (room: string) => void;
@@ -32,15 +33,17 @@ export declare function RoomsSocket({ config }: {
32
33
  room: string;
33
34
  data: TJsonStr;
34
35
  }) => void;
36
+ error: (error: Error) => void;
35
37
  }, {
36
38
  join: (room: string) => void;
37
39
  leave: (room: string) => void;
38
40
  }>;
39
- subscribeToRoom: (room: TSocketRoom, handlers: { [k in TEvent]: THandler<k>; }) => () => void;
41
+ subscribeToRoom: (room: TSocketRoom, handlers: Partial<{ [k in TEvent]: THandler<k>; }>) => () => void;
40
42
  updateConfig: (config: Partial<RoomsSocketConfig>) => void;
41
43
  handlers: {
42
44
  connect: THandler<"connect">;
43
45
  update_model: THandler<"update_model">;
46
+ error: THandler<"error">;
44
47
  };
45
48
  disconnect: () => void;
46
49
  };
@@ -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
13
  socket.on("connect", () => {
14
+ var _a;
12
15
  console.log("connect", socket.id);
13
- handlers.connect();
16
+ (_a = handlers.connect) === null || _a === void 0 ? void 0 : _a.call(handlers);
14
17
  });
15
18
  socket.on("update_model", (msg) => {
16
- handlers.update_model(msg);
19
+ var _a;
20
+ (_a = handlers.update_model) === null || _a === void 0 ? void 0 : _a.call(handlers, msg);
21
+ });
22
+ socket.on("error", (error) => {
23
+ var _a;
24
+ (_a = handlers.error) === null || _a === void 0 ? void 0 : _a.call(handlers, error);
25
+ });
26
+ socket.on("connect_error", (error) => {
27
+ var _a;
28
+ console.error("connect_error", error);
29
+ (_a = handlers.error) === null || _a === void 0 ? void 0 : _a.call(handlers, error);
17
30
  });
18
31
  return socket;
19
32
  }
@@ -26,7 +39,7 @@ export function RoomsSocket({ config }) {
26
39
  var _a;
27
40
  joinRoom(room);
28
41
  (_a = getListeners(room)) === null || _a === void 0 ? void 0 : _a.forEach(({ connect: connectHandler }) => {
29
- connectHandler();
42
+ connectHandler === null || connectHandler === void 0 ? void 0 : connectHandler();
30
43
  });
31
44
  });
32
45
  },
@@ -34,10 +47,15 @@ export function RoomsSocket({ config }) {
34
47
  var _a;
35
48
  if (roomsToListeners[msg.room]) {
36
49
  (_a = getListeners(msg.room)) === null || _a === void 0 ? void 0 : _a.forEach(({ update_model }) => {
37
- update_model(msg);
50
+ update_model === null || update_model === void 0 ? void 0 : update_model(msg);
38
51
  });
39
52
  }
40
53
  },
54
+ error: (error) => {
55
+ var _a;
56
+ console.error("error", error);
57
+ (_a = handlers.error) === null || _a === void 0 ? void 0 : _a.call(handlers, error);
58
+ },
41
59
  };
42
60
  let socket = initializeSocket(config, handlers);
43
61
  function cleanup() {
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.eb342e0",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",