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

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 Base44SDK = ReturnType<typeof createClient>;
4
5
  /**
5
6
  * Create a Base44 client instance
6
7
  * @param {Object} config - Client configuration
@@ -43,13 +44,17 @@ export declare function createClient(config: {
43
44
  invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
44
45
  };
45
46
  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;
47
+ getConversations: () => Promise<import("./types.js").AgentConversation[]>;
48
+ getConversation: (conversationId: string) => Promise<import("./types.js").AgentConversation | undefined>;
49
+ listConversations: (filterParams: import("./types.js").ModelFilterParams) => Promise<import("./types.js").AgentConversation[]>;
50
+ createConversation: (conversation: {
51
+ agent_name: string;
52
+ metadata?: Record<string, any>;
53
+ }) => Promise<import("./types.js").AgentConversation>;
54
+ addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
55
+ subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
52
56
  };
57
+ cleanup: () => void;
53
58
  };
54
59
  entities: {};
55
60
  integrations: {};
@@ -69,13 +74,17 @@ export declare function createClient(config: {
69
74
  invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
70
75
  };
71
76
  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;
77
+ getConversations: () => Promise<import("./types.js").AgentConversation[]>;
78
+ getConversation: (conversationId: string) => Promise<import("./types.js").AgentConversation | undefined>;
79
+ listConversations: (filterParams: import("./types.js").ModelFilterParams) => Promise<import("./types.js").AgentConversation[]>;
80
+ createConversation: (conversation: {
81
+ agent_name: string;
82
+ metadata?: Record<string, any>;
83
+ }) => Promise<import("./types.js").AgentConversation>;
84
+ addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
85
+ subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
78
86
  };
87
+ cleanup: () => void;
79
88
  };
80
89
  export declare function createClientFromRequest(request: Request): {
81
90
  /**
@@ -102,13 +111,17 @@ export declare function createClientFromRequest(request: Request): {
102
111
  invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
103
112
  };
104
113
  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;
114
+ getConversations: () => Promise<import("./types.js").AgentConversation[]>;
115
+ getConversation: (conversationId: string) => Promise<import("./types.js").AgentConversation | undefined>;
116
+ listConversations: (filterParams: import("./types.js").ModelFilterParams) => Promise<import("./types.js").AgentConversation[]>;
117
+ createConversation: (conversation: {
118
+ agent_name: string;
119
+ metadata?: Record<string, any>;
120
+ }) => Promise<import("./types.js").AgentConversation>;
121
+ addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
122
+ subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
111
123
  };
124
+ cleanup: () => void;
112
125
  };
113
126
  entities: {};
114
127
  integrations: {};
@@ -128,11 +141,15 @@ export declare function createClientFromRequest(request: Request): {
128
141
  invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
129
142
  };
130
143
  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;
144
+ getConversations: () => Promise<import("./types.js").AgentConversation[]>;
145
+ getConversation: (conversationId: string) => Promise<import("./types.js").AgentConversation | undefined>;
146
+ listConversations: (filterParams: import("./types.js").ModelFilterParams) => Promise<import("./types.js").AgentConversation[]>;
147
+ createConversation: (conversation: {
148
+ agent_name: string;
149
+ metadata?: Record<string, any>;
150
+ }) => Promise<import("./types.js").AgentConversation>;
151
+ addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
152
+ subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
137
153
  };
154
+ cleanup: () => void;
138
155
  };
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
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- import { createClient, createClientFromRequest } from "./client.js";
1
+ import { createClient, createClientFromRequest, Base44SDK } 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 { Base44SDK };
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
- import { AgentConversation, AgentMessage } from "./agents.types.js";
2
+ import { AgentConversation, AgentMessage } from "./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,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";
@@ -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
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
  }
@@ -21,22 +34,27 @@ 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);
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);
32
53
  },
33
- update_model: (msg) => {
54
+ error: async (error) => {
34
55
  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
- }
56
+ console.error("error", error);
57
+ await ((_a = handlers.error) === null || _a === void 0 ? void 0 : _a.call(handlers, error));
40
58
  },
41
59
  };
42
60
  let socket = initializeSocket(config, handlers);
@@ -62,6 +80,11 @@ export function RoomsSocket({ config }) {
62
80
  function leaveRoom(room) {
63
81
  socket.emit("leave", room);
64
82
  }
83
+ async function updateModel(room, data) {
84
+ var _a;
85
+ const dataStr = JSON.stringify(data);
86
+ return (_a = handlers.update_model) === null || _a === void 0 ? void 0 : _a.call(handlers, { room, data: dataStr });
87
+ }
65
88
  function getListeners(room) {
66
89
  return roomsToListeners[room];
67
90
  }
@@ -79,7 +102,7 @@ export function RoomsSocket({ config }) {
79
102
  socket,
80
103
  subscribeToRoom,
81
104
  updateConfig,
82
- handlers,
105
+ updateModel,
83
106
  disconnect,
84
107
  };
85
108
  }
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.b5c0834",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
File without changes