@base44/sdk 0.8.5 → 0.8.6
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 +30 -10
- package/dist/modules/agents.d.ts +2 -2
- package/dist/modules/agents.js +3 -1
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -30,9 +30,15 @@ export function createClient(config) {
|
|
|
30
30
|
appId,
|
|
31
31
|
token,
|
|
32
32
|
};
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
108
|
+
getSocket,
|
|
101
109
|
appId,
|
|
102
110
|
serverUrl,
|
|
103
111
|
token,
|
|
104
112
|
}),
|
|
105
113
|
appLogs: createAppLogsModule(serviceRoleAxiosClient, appId),
|
|
106
114
|
cleanup: () => {
|
|
107
|
-
socket
|
|
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
|
|
144
|
-
|
|
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
|
|
@@ -174,6 +187,7 @@ export function createClientFromRequest(request) {
|
|
|
174
187
|
const appId = request.headers.get("Base44-App-Id");
|
|
175
188
|
const serverUrlHeader = request.headers.get("Base44-Api-Url");
|
|
176
189
|
const functionsVersion = request.headers.get("Base44-Functions-Version");
|
|
190
|
+
const stateHeader = request.headers.get("Base44-State");
|
|
177
191
|
if (!appId) {
|
|
178
192
|
throw new Error("Base44-App-Id header is required, but is was not found on the request");
|
|
179
193
|
}
|
|
@@ -196,11 +210,17 @@ export function createClientFromRequest(request) {
|
|
|
196
210
|
}
|
|
197
211
|
userToken = authHeader.split(" ")[1];
|
|
198
212
|
}
|
|
213
|
+
// Prepare additional headers to propagate
|
|
214
|
+
const additionalHeaders = {};
|
|
215
|
+
if (stateHeader) {
|
|
216
|
+
additionalHeaders["Base44-State"] = stateHeader;
|
|
217
|
+
}
|
|
199
218
|
return createClient({
|
|
200
219
|
serverUrl: serverUrlHeader || "https://base44.app",
|
|
201
220
|
appId,
|
|
202
221
|
token: userToken,
|
|
203
222
|
serviceToken: serviceRoleToken,
|
|
204
223
|
functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined,
|
|
224
|
+
headers: additionalHeaders,
|
|
205
225
|
});
|
|
206
226
|
}
|
package/dist/modules/agents.d.ts
CHANGED
|
@@ -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
|
-
|
|
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,
|
|
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[]>;
|
package/dist/modules/agents.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getAccessToken } from "../utils/auth-utils.js";
|
|
2
|
-
export function createAgentsModule({ axios,
|
|
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 }) => {
|