@base44-preview/sdk 0.7.0-pr.27.96b80f1 → 0.7.0-pr.27.df967f0
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 +46 -28
- package/dist/client.js +43 -20
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -0
- package/dist/modules/agents.d.ts +16 -10
- package/dist/modules/agents.js +18 -69
- package/dist/modules/auth.js +1 -0
- package/dist/modules/types.d.ts +44 -0
- package/dist/modules/types.js +1 -0
- package/dist/types.d.ts +9 -0
- package/dist/types.js +1 -0
- package/dist/utils/axios-client.d.ts +2 -1
- package/dist/utils/axios-client.js +2 -1
- package/dist/utils/socket-utils.d.ts +16 -17
- package/dist/utils/socket-utils.js +62 -20
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export type CreateClientOptions = {
|
|
2
|
+
onError?: (error: Error) => void;
|
|
3
|
+
};
|
|
4
|
+
export type Base44Client = ReturnType<typeof createClient>;
|
|
1
5
|
/**
|
|
2
6
|
* Create a Base44 client instance
|
|
3
7
|
* @param {Object} config - Client configuration
|
|
@@ -14,6 +18,8 @@ export declare function createClient(config: {
|
|
|
14
18
|
token?: string;
|
|
15
19
|
serviceToken?: string;
|
|
16
20
|
requiresAuth?: boolean;
|
|
21
|
+
functionsVersion?: string;
|
|
22
|
+
options?: CreateClientOptions;
|
|
17
23
|
}): {
|
|
18
24
|
/**
|
|
19
25
|
* Set authentication token for all requests
|
|
@@ -39,14 +45,17 @@ export declare function createClient(config: {
|
|
|
39
45
|
invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
|
|
40
46
|
};
|
|
41
47
|
agents: {
|
|
42
|
-
getConversations: () => Promise<import("
|
|
43
|
-
getConversation: (conversationId: string) => Promise<import("
|
|
44
|
-
listConversations: (filterParams:
|
|
45
|
-
createConversation: (conversation:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
getConversations: () => Promise<import("./types.js").AgentConversation[]>;
|
|
49
|
+
getConversation: (conversationId: string) => Promise<import("./types.js").AgentConversation | undefined>;
|
|
50
|
+
listConversations: (filterParams: import("./types.js").ModelFilterParams) => Promise<import("./types.js").AgentConversation[]>;
|
|
51
|
+
createConversation: (conversation: {
|
|
52
|
+
agent_name: string;
|
|
53
|
+
metadata?: Record<string, any>;
|
|
54
|
+
}) => Promise<import("./types.js").AgentConversation>;
|
|
55
|
+
addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
|
|
56
|
+
subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
|
|
49
57
|
};
|
|
58
|
+
cleanup: () => void;
|
|
50
59
|
};
|
|
51
60
|
entities: {};
|
|
52
61
|
integrations: {};
|
|
@@ -66,14 +75,17 @@ export declare function createClient(config: {
|
|
|
66
75
|
invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
|
|
67
76
|
};
|
|
68
77
|
agents: {
|
|
69
|
-
getConversations: () => Promise<import("
|
|
70
|
-
getConversation: (conversationId: string) => Promise<import("
|
|
71
|
-
listConversations: (filterParams:
|
|
72
|
-
createConversation: (conversation:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
getConversations: () => Promise<import("./types.js").AgentConversation[]>;
|
|
79
|
+
getConversation: (conversationId: string) => Promise<import("./types.js").AgentConversation | undefined>;
|
|
80
|
+
listConversations: (filterParams: import("./types.js").ModelFilterParams) => Promise<import("./types.js").AgentConversation[]>;
|
|
81
|
+
createConversation: (conversation: {
|
|
82
|
+
agent_name: string;
|
|
83
|
+
metadata?: Record<string, any>;
|
|
84
|
+
}) => Promise<import("./types.js").AgentConversation>;
|
|
85
|
+
addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
|
|
86
|
+
subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
|
|
76
87
|
};
|
|
88
|
+
cleanup: () => void;
|
|
77
89
|
};
|
|
78
90
|
export declare function createClientFromRequest(request: Request): {
|
|
79
91
|
/**
|
|
@@ -100,14 +112,17 @@ export declare function createClientFromRequest(request: Request): {
|
|
|
100
112
|
invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
|
|
101
113
|
};
|
|
102
114
|
agents: {
|
|
103
|
-
getConversations: () => Promise<import("
|
|
104
|
-
getConversation: (conversationId: string) => Promise<import("
|
|
105
|
-
listConversations: (filterParams:
|
|
106
|
-
createConversation: (conversation:
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
115
|
+
getConversations: () => Promise<import("./types.js").AgentConversation[]>;
|
|
116
|
+
getConversation: (conversationId: string) => Promise<import("./types.js").AgentConversation | undefined>;
|
|
117
|
+
listConversations: (filterParams: import("./types.js").ModelFilterParams) => Promise<import("./types.js").AgentConversation[]>;
|
|
118
|
+
createConversation: (conversation: {
|
|
119
|
+
agent_name: string;
|
|
120
|
+
metadata?: Record<string, any>;
|
|
121
|
+
}) => Promise<import("./types.js").AgentConversation>;
|
|
122
|
+
addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
|
|
123
|
+
subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
|
|
110
124
|
};
|
|
125
|
+
cleanup: () => void;
|
|
111
126
|
};
|
|
112
127
|
entities: {};
|
|
113
128
|
integrations: {};
|
|
@@ -127,12 +142,15 @@ export declare function createClientFromRequest(request: Request): {
|
|
|
127
142
|
invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
|
|
128
143
|
};
|
|
129
144
|
agents: {
|
|
130
|
-
getConversations: () => Promise<import("
|
|
131
|
-
getConversation: (conversationId: string) => Promise<import("
|
|
132
|
-
listConversations: (filterParams:
|
|
133
|
-
createConversation: (conversation:
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
145
|
+
getConversations: () => Promise<import("./types.js").AgentConversation[]>;
|
|
146
|
+
getConversation: (conversationId: string) => Promise<import("./types.js").AgentConversation | undefined>;
|
|
147
|
+
listConversations: (filterParams: import("./types.js").ModelFilterParams) => Promise<import("./types.js").AgentConversation[]>;
|
|
148
|
+
createConversation: (conversation: {
|
|
149
|
+
agent_name: string;
|
|
150
|
+
metadata?: Record<string, any>;
|
|
151
|
+
}) => Promise<import("./types.js").AgentConversation>;
|
|
152
|
+
addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
|
|
153
|
+
subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
|
|
137
154
|
};
|
|
155
|
+
cleanup: () => void;
|
|
138
156
|
};
|
package/dist/client.js
CHANGED
|
@@ -6,6 +6,7 @@ import { createSsoModule } from "./modules/sso.js";
|
|
|
6
6
|
import { getAccessToken } from "./utils/auth-utils.js";
|
|
7
7
|
import { createFunctionsModule } from "./modules/functions.js";
|
|
8
8
|
import { createAgentsModule } from "./modules/agents.js";
|
|
9
|
+
import { RoomsSocket } from "./utils/socket-utils.js";
|
|
9
10
|
/**
|
|
10
11
|
* Create a Base44 client instance
|
|
11
12
|
* @param {Object} config - Client configuration
|
|
@@ -17,42 +18,56 @@ import { createAgentsModule } from "./modules/agents.js";
|
|
|
17
18
|
* @returns {Object} Base44 client instance
|
|
18
19
|
*/
|
|
19
20
|
export function createClient(config) {
|
|
20
|
-
const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, } = config;
|
|
21
|
+
const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, options, functionsVersion, } = config;
|
|
22
|
+
const socketConfig = {
|
|
23
|
+
serverUrl,
|
|
24
|
+
mountPath: "/ws-user-apps/socket.io/",
|
|
25
|
+
transports: ["websocket"],
|
|
26
|
+
appId,
|
|
27
|
+
token,
|
|
28
|
+
};
|
|
29
|
+
const socket = RoomsSocket({
|
|
30
|
+
config: socketConfig,
|
|
31
|
+
});
|
|
32
|
+
const headers = {
|
|
33
|
+
"X-App-Id": String(appId),
|
|
34
|
+
};
|
|
35
|
+
const functionHeaders = functionsVersion
|
|
36
|
+
? {
|
|
37
|
+
...headers,
|
|
38
|
+
"Base44-Functions-Version": functionsVersion,
|
|
39
|
+
}
|
|
40
|
+
: headers;
|
|
21
41
|
const axiosClient = createAxiosClient({
|
|
22
42
|
baseURL: `${serverUrl}/api`,
|
|
23
|
-
headers
|
|
24
|
-
"X-App-Id": String(appId),
|
|
25
|
-
},
|
|
43
|
+
headers,
|
|
26
44
|
token,
|
|
27
45
|
requiresAuth,
|
|
28
46
|
appId,
|
|
29
47
|
serverUrl,
|
|
48
|
+
onError: options === null || options === void 0 ? void 0 : options.onError,
|
|
30
49
|
});
|
|
31
50
|
const functionsAxiosClient = createAxiosClient({
|
|
32
51
|
baseURL: `${serverUrl}/api`,
|
|
33
|
-
headers:
|
|
34
|
-
"X-App-Id": String(appId),
|
|
35
|
-
},
|
|
52
|
+
headers: functionHeaders,
|
|
36
53
|
token,
|
|
37
54
|
requiresAuth,
|
|
38
55
|
appId,
|
|
39
56
|
serverUrl,
|
|
40
57
|
interceptResponses: false,
|
|
58
|
+
onError: options === null || options === void 0 ? void 0 : options.onError,
|
|
41
59
|
});
|
|
42
60
|
const serviceRoleAxiosClient = createAxiosClient({
|
|
43
61
|
baseURL: `${serverUrl}/api`,
|
|
44
|
-
headers
|
|
45
|
-
"X-App-Id": String(appId),
|
|
46
|
-
},
|
|
62
|
+
headers,
|
|
47
63
|
token: serviceToken,
|
|
48
64
|
serverUrl,
|
|
49
65
|
appId,
|
|
66
|
+
onError: options === null || options === void 0 ? void 0 : options.onError,
|
|
50
67
|
});
|
|
51
68
|
const serviceRoleFunctionsAxiosClient = createAxiosClient({
|
|
52
69
|
baseURL: `${serverUrl}/api`,
|
|
53
|
-
headers:
|
|
54
|
-
"X-App-Id": String(appId),
|
|
55
|
-
},
|
|
70
|
+
headers: functionHeaders,
|
|
56
71
|
token: serviceToken,
|
|
57
72
|
serverUrl,
|
|
58
73
|
appId,
|
|
@@ -64,10 +79,13 @@ export function createClient(config) {
|
|
|
64
79
|
auth: createAuthModule(axiosClient, functionsAxiosClient, appId),
|
|
65
80
|
functions: createFunctionsModule(functionsAxiosClient, appId),
|
|
66
81
|
agents: createAgentsModule({
|
|
67
|
-
|
|
82
|
+
axios: axiosClient,
|
|
83
|
+
socket,
|
|
68
84
|
appId,
|
|
69
|
-
token,
|
|
70
85
|
}),
|
|
86
|
+
cleanup: () => {
|
|
87
|
+
socket.disconnect();
|
|
88
|
+
},
|
|
71
89
|
};
|
|
72
90
|
const serviceRoleModules = {
|
|
73
91
|
entities: createEntitiesModule(serviceRoleAxiosClient, appId),
|
|
@@ -75,10 +93,13 @@ export function createClient(config) {
|
|
|
75
93
|
sso: createSsoModule(serviceRoleAxiosClient, appId, token),
|
|
76
94
|
functions: createFunctionsModule(serviceRoleFunctionsAxiosClient, appId),
|
|
77
95
|
agents: createAgentsModule({
|
|
78
|
-
|
|
96
|
+
axios: serviceRoleAxiosClient,
|
|
97
|
+
socket,
|
|
79
98
|
appId,
|
|
80
|
-
token: serviceToken,
|
|
81
99
|
}),
|
|
100
|
+
cleanup: () => {
|
|
101
|
+
socket.disconnect();
|
|
102
|
+
},
|
|
82
103
|
};
|
|
83
104
|
// Always try to get token from localStorage or URL parameters
|
|
84
105
|
if (typeof window !== "undefined") {
|
|
@@ -86,9 +107,6 @@ export function createClient(config) {
|
|
|
86
107
|
const accessToken = token || getAccessToken();
|
|
87
108
|
if (accessToken) {
|
|
88
109
|
userModules.auth.setToken(accessToken);
|
|
89
|
-
userModules.agents.updateConfig({
|
|
90
|
-
token: accessToken,
|
|
91
|
-
});
|
|
92
110
|
}
|
|
93
111
|
}
|
|
94
112
|
// If authentication is required, verify token and redirect to login if needed
|
|
@@ -116,6 +134,9 @@ export function createClient(config) {
|
|
|
116
134
|
*/
|
|
117
135
|
setToken(newToken) {
|
|
118
136
|
userModules.auth.setToken(newToken);
|
|
137
|
+
socket.updateConfig({
|
|
138
|
+
token: newToken,
|
|
139
|
+
});
|
|
119
140
|
},
|
|
120
141
|
/**
|
|
121
142
|
* Get current configuration
|
|
@@ -146,6 +167,7 @@ export function createClientFromRequest(request) {
|
|
|
146
167
|
const serviceRoleAuthHeader = request.headers.get("Base44-Service-Authorization");
|
|
147
168
|
const appId = request.headers.get("Base44-App-Id");
|
|
148
169
|
const serverUrlHeader = request.headers.get("Base44-Api-Url");
|
|
170
|
+
const functionsVersion = request.headers.get("Base44-Functions-Version");
|
|
149
171
|
if (!appId) {
|
|
150
172
|
throw new Error("Base44-App-Id header is required, but is was not found on the request");
|
|
151
173
|
}
|
|
@@ -173,5 +195,6 @@ export function createClientFromRequest(request) {
|
|
|
173
195
|
appId,
|
|
174
196
|
token: userToken,
|
|
175
197
|
serviceToken: serviceRoleToken,
|
|
198
|
+
functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined,
|
|
176
199
|
});
|
|
177
200
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { createClient, createClientFromRequest } from "./client.js";
|
|
1
|
+
import { createClient, createClientFromRequest, type Base44Client } 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 { Base44Client };
|
|
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";
|
package/dist/modules/agents.d.ts
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
|
+
import { RoomsSocket } from "../utils/socket-utils.js";
|
|
2
|
+
import { AgentConversation, AgentMessage } from "./types.js";
|
|
3
|
+
import { AxiosInstance } from "axios";
|
|
4
|
+
import { ModelFilterParams } from "../types.js";
|
|
1
5
|
export type AgentsModuleConfig = {
|
|
2
|
-
|
|
6
|
+
axios: AxiosInstance;
|
|
7
|
+
socket: ReturnType<typeof RoomsSocket>;
|
|
3
8
|
appId: string;
|
|
4
|
-
token?: string;
|
|
5
9
|
};
|
|
6
|
-
export declare function createAgentsModule({
|
|
7
|
-
getConversations: () => Promise<
|
|
8
|
-
getConversation: (conversationId: string) => Promise<
|
|
9
|
-
listConversations: (filterParams:
|
|
10
|
-
createConversation: (conversation:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
export declare function createAgentsModule({ axios, socket, appId, }: AgentsModuleConfig): {
|
|
11
|
+
getConversations: () => Promise<AgentConversation[]>;
|
|
12
|
+
getConversation: (conversationId: string) => Promise<AgentConversation | undefined>;
|
|
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;
|
|
14
20
|
};
|
package/dist/modules/agents.js
CHANGED
|
@@ -1,71 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export function createAgentsModule({ appId, serverUrl, token, }) {
|
|
4
|
-
let currentConversation = null;
|
|
5
|
-
const socketConfig = {
|
|
6
|
-
serverUrl,
|
|
7
|
-
mountPath: "/ws-user-apps/socket.io/",
|
|
8
|
-
transports: ["websocket"],
|
|
9
|
-
query: {
|
|
10
|
-
appId,
|
|
11
|
-
token,
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
const axiosConfig = {
|
|
15
|
-
serverUrl,
|
|
16
|
-
appId,
|
|
17
|
-
token,
|
|
18
|
-
};
|
|
19
|
-
let axios = createAgentsAxiosClient({
|
|
20
|
-
serverUrl,
|
|
21
|
-
appId,
|
|
22
|
-
token,
|
|
23
|
-
});
|
|
24
|
-
const roomSocket = RoomsSocket({
|
|
25
|
-
config: socketConfig,
|
|
26
|
-
});
|
|
27
|
-
const updateConfig = (config) => {
|
|
28
|
-
axios = createAgentsAxiosClient({ ...axiosConfig, ...config });
|
|
29
|
-
roomSocket.updateConfig({ ...socketConfig, ...config });
|
|
30
|
-
};
|
|
1
|
+
export function createAgentsModule({ axios, socket, appId, }) {
|
|
2
|
+
const baseURL = `/apps/${appId}/agents`;
|
|
31
3
|
const getConversations = () => {
|
|
32
|
-
return axios.get(
|
|
4
|
+
return axios.get(`${baseURL}/conversations`);
|
|
33
5
|
};
|
|
34
6
|
const getConversation = (conversationId) => {
|
|
35
|
-
return axios.get(
|
|
7
|
+
return axios.get(`${baseURL}/conversations/${conversationId}`);
|
|
36
8
|
};
|
|
37
9
|
const listConversations = (filterParams) => {
|
|
38
|
-
return axios.get(
|
|
10
|
+
return axios.get(`${baseURL}/conversations`, {
|
|
11
|
+
params: filterParams,
|
|
12
|
+
});
|
|
39
13
|
};
|
|
40
14
|
const createConversation = (conversation) => {
|
|
41
|
-
return axios.post(
|
|
15
|
+
return axios.post(`${baseURL}/conversations`, conversation);
|
|
42
16
|
};
|
|
43
|
-
const addMessage = (conversation, message) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
currentConversation = conversation;
|
|
51
|
-
convLatestMessages = conversation.messages;
|
|
52
|
-
}
|
|
53
|
-
conversation.messages = [...convLatestMessages, message];
|
|
54
|
-
roomSocket.handlers.update_model({
|
|
55
|
-
room: `/agent-conversations/${conversation.id}`,
|
|
56
|
-
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],
|
|
57
22
|
});
|
|
58
|
-
return axios.post(
|
|
23
|
+
return axios.post(`${baseURL}/conversations/${conversation.id}/messages`, message);
|
|
59
24
|
};
|
|
60
25
|
const subscribeToConversation = (conversationId, onUpdate) => {
|
|
61
|
-
|
|
26
|
+
const room = `/agent-conversations/${conversationId}`;
|
|
27
|
+
return socket.subscribeToRoom(room, {
|
|
62
28
|
connect: () => { },
|
|
63
29
|
update_model: ({ data: jsonStr }) => {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
currentConversation = data;
|
|
67
|
-
}
|
|
68
|
-
onUpdate(data);
|
|
30
|
+
const conv = JSON.parse(jsonStr);
|
|
31
|
+
onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(conv);
|
|
69
32
|
},
|
|
70
33
|
});
|
|
71
34
|
};
|
|
@@ -76,19 +39,5 @@ export function createAgentsModule({ appId, serverUrl, token, }) {
|
|
|
76
39
|
createConversation,
|
|
77
40
|
addMessage,
|
|
78
41
|
subscribeToConversation,
|
|
79
|
-
updateConfig,
|
|
80
42
|
};
|
|
81
43
|
}
|
|
82
|
-
function createAgentsAxiosClient({ serverUrl, appId, token, }) {
|
|
83
|
-
const axios = createAxiosClient({
|
|
84
|
-
baseURL: `${serverUrl}/api/apps/${appId}/agents`,
|
|
85
|
-
appId,
|
|
86
|
-
serverUrl,
|
|
87
|
-
token,
|
|
88
|
-
interceptResponses: false,
|
|
89
|
-
headers: {
|
|
90
|
-
"X-App-Id": String(appId),
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
return axios;
|
|
94
|
-
}
|
package/dist/modules/auth.js
CHANGED
|
@@ -77,6 +77,7 @@ export function createAuthModule(axios, functionsAxiosClient, appId) {
|
|
|
77
77
|
setToken(token, saveToStorage = true) {
|
|
78
78
|
if (!token)
|
|
79
79
|
return;
|
|
80
|
+
// handle token change for axios clients
|
|
80
81
|
axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
81
82
|
functionsAxiosClient.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
82
83
|
// Save token to localStorage if requested
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type AgentConversation = {
|
|
2
|
+
id: string;
|
|
3
|
+
app_id: string;
|
|
4
|
+
agent_name: string;
|
|
5
|
+
created_by_id: string;
|
|
6
|
+
messages: AgentMessage[];
|
|
7
|
+
metadata?: Record<string, any>;
|
|
8
|
+
};
|
|
9
|
+
export type AgentMessage = {
|
|
10
|
+
id: string;
|
|
11
|
+
role: "user" | "assistant" | "system";
|
|
12
|
+
reasoning?: {
|
|
13
|
+
start_date: string;
|
|
14
|
+
end_date?: string;
|
|
15
|
+
content: string;
|
|
16
|
+
};
|
|
17
|
+
content?: string | Record<string, any> | null;
|
|
18
|
+
file_urls?: string[] | null;
|
|
19
|
+
tool_calls?: {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
arguments_string: string;
|
|
23
|
+
status: "running" | "success" | "error" | "stopped";
|
|
24
|
+
results?: string | null;
|
|
25
|
+
}[] | null;
|
|
26
|
+
usage?: {
|
|
27
|
+
prompt_tokens?: number;
|
|
28
|
+
completion_tokens?: number;
|
|
29
|
+
} | null;
|
|
30
|
+
hidden?: boolean;
|
|
31
|
+
custom_context?: {
|
|
32
|
+
message: string;
|
|
33
|
+
data: Record<string, any>;
|
|
34
|
+
type: string;
|
|
35
|
+
}[] | null;
|
|
36
|
+
model?: string | null;
|
|
37
|
+
checkpoint_id?: string | null;
|
|
38
|
+
metadata?: {
|
|
39
|
+
created_date: string;
|
|
40
|
+
created_by_email: string;
|
|
41
|
+
created_by_full_name: string | null;
|
|
42
|
+
};
|
|
43
|
+
additional_message_params?: Record<string, any>;
|
|
44
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./modules/types.js";
|
|
@@ -23,7 +23,7 @@ export declare class Base44Error extends Error {
|
|
|
23
23
|
* @param {string} options.serverUrl - Server URL (needed for login redirect)
|
|
24
24
|
* @returns {import('axios').AxiosInstance} Configured axios instance
|
|
25
25
|
*/
|
|
26
|
-
export declare function createAxiosClient({ baseURL, headers, token, requiresAuth, appId, serverUrl, interceptResponses, }: {
|
|
26
|
+
export declare function createAxiosClient({ baseURL, headers, token, requiresAuth, appId, serverUrl, interceptResponses, onError, }: {
|
|
27
27
|
baseURL: string;
|
|
28
28
|
headers?: Record<string, string>;
|
|
29
29
|
token?: string;
|
|
@@ -31,4 +31,5 @@ export declare function createAxiosClient({ baseURL, headers, token, requiresAut
|
|
|
31
31
|
appId: string;
|
|
32
32
|
serverUrl: string;
|
|
33
33
|
interceptResponses?: boolean;
|
|
34
|
+
onError?: (error: Error) => void;
|
|
34
35
|
}): import("axios").AxiosInstance;
|
|
@@ -64,7 +64,7 @@ function redirectToLogin(serverUrl, appId) {
|
|
|
64
64
|
* @param {string} options.serverUrl - Server URL (needed for login redirect)
|
|
65
65
|
* @returns {import('axios').AxiosInstance} Configured axios instance
|
|
66
66
|
*/
|
|
67
|
-
export function createAxiosClient({ baseURL, headers = {}, token, requiresAuth = false, appId, serverUrl, interceptResponses = true, }) {
|
|
67
|
+
export function createAxiosClient({ baseURL, headers = {}, token, requiresAuth = false, appId, serverUrl, interceptResponses = true, onError, }) {
|
|
68
68
|
const client = axios.create({
|
|
69
69
|
baseURL,
|
|
70
70
|
headers: {
|
|
@@ -107,6 +107,7 @@ export function createAxiosClient({ baseURL, headers = {}, token, requiresAuth =
|
|
|
107
107
|
redirectToLogin(serverUrl, appId);
|
|
108
108
|
}, 100);
|
|
109
109
|
}
|
|
110
|
+
onError === null || onError === void 0 ? void 0 : onError(base44Error);
|
|
110
111
|
return Promise.reject(base44Error);
|
|
111
112
|
});
|
|
112
113
|
}
|
|
@@ -3,20 +3,19 @@ export type RoomsSocketConfig = {
|
|
|
3
3
|
serverUrl: string;
|
|
4
4
|
mountPath: string;
|
|
5
5
|
transports: string[];
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
token?: string;
|
|
9
|
-
};
|
|
6
|
+
appId: string;
|
|
7
|
+
token?: string;
|
|
10
8
|
};
|
|
11
9
|
export type TSocketRoom = string;
|
|
12
10
|
export type TJsonStr = string;
|
|
13
11
|
type RoomsSocketEventsMap = {
|
|
14
12
|
listen: {
|
|
15
|
-
connect: () => void;
|
|
13
|
+
connect: () => Promise<void> | void;
|
|
16
14
|
update_model: (msg: {
|
|
17
15
|
room: string;
|
|
18
16
|
data: TJsonStr;
|
|
19
|
-
}) => void;
|
|
17
|
+
}) => Promise<void> | void;
|
|
18
|
+
error: (error: Error) => Promise<void> | void;
|
|
20
19
|
};
|
|
21
20
|
emit: {
|
|
22
21
|
join: (room: string) => void;
|
|
@@ -24,25 +23,25 @@ type RoomsSocketEventsMap = {
|
|
|
24
23
|
};
|
|
25
24
|
};
|
|
26
25
|
type TEvent = keyof RoomsSocketEventsMap["listen"];
|
|
27
|
-
type THandler<E extends TEvent> =
|
|
26
|
+
type THandler<E extends TEvent> = RoomsSocketEventsMap["listen"][E];
|
|
27
|
+
export type RoomsSocket = ReturnType<typeof RoomsSocket>;
|
|
28
28
|
export declare function RoomsSocket({ config }: {
|
|
29
29
|
config: RoomsSocketConfig;
|
|
30
30
|
}): {
|
|
31
|
-
socket:
|
|
32
|
-
connect: () => void;
|
|
31
|
+
socket: Socket<{
|
|
32
|
+
connect: () => Promise<void> | void;
|
|
33
33
|
update_model: (msg: {
|
|
34
34
|
room: string;
|
|
35
35
|
data: TJsonStr;
|
|
36
|
-
}) => void;
|
|
36
|
+
}) => Promise<void> | void;
|
|
37
|
+
error: (error: Error) => Promise<void> | void;
|
|
37
38
|
}, {
|
|
38
39
|
join: (room: string) => void;
|
|
39
40
|
leave: (room: string) => void;
|
|
40
|
-
}
|
|
41
|
-
subscribeToRoom: (room: TSocketRoom, handlers: { [k in TEvent]: THandler<k>; }) => () => void;
|
|
42
|
-
updateConfig: (config: RoomsSocketConfig) => void;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
update_model: THandler<"update_model">;
|
|
46
|
-
};
|
|
41
|
+
}>;
|
|
42
|
+
subscribeToRoom: (room: TSocketRoom, handlers: Partial<{ [k in TEvent]: THandler<k>; }>) => () => void;
|
|
43
|
+
updateConfig: (config: Partial<RoomsSocketConfig>) => void;
|
|
44
|
+
updateModel: (room: string, data: any) => Promise<void>;
|
|
45
|
+
disconnect: () => void;
|
|
47
46
|
};
|
|
48
47
|
export {};
|
|
@@ -1,49 +1,80 @@
|
|
|
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
|
-
query:
|
|
8
|
+
query: {
|
|
9
|
+
app_id: config.appId,
|
|
10
|
+
token: (_a = config.token) !== null && _a !== void 0 ? _a : getAccessToken(),
|
|
11
|
+
},
|
|
7
12
|
});
|
|
8
|
-
socket.on("connect", () => {
|
|
13
|
+
socket.on("connect", async () => {
|
|
14
|
+
var _a;
|
|
9
15
|
console.log("connect", socket.id);
|
|
10
|
-
handlers.connect();
|
|
16
|
+
return (_a = handlers.connect) === null || _a === void 0 ? void 0 : _a.call(handlers);
|
|
17
|
+
});
|
|
18
|
+
socket.on("update_model", async (msg) => {
|
|
19
|
+
var _a;
|
|
20
|
+
return (_a = handlers.update_model) === null || _a === void 0 ? void 0 : _a.call(handlers, msg);
|
|
21
|
+
});
|
|
22
|
+
socket.on("error", async (error) => {
|
|
23
|
+
var _a;
|
|
24
|
+
return (_a = handlers.error) === null || _a === void 0 ? void 0 : _a.call(handlers, error);
|
|
11
25
|
});
|
|
12
|
-
socket.on("
|
|
13
|
-
|
|
26
|
+
socket.on("connect_error", async (error) => {
|
|
27
|
+
var _a;
|
|
28
|
+
console.error("connect_error", error);
|
|
29
|
+
return (_a = handlers.error) === null || _a === void 0 ? void 0 : _a.call(handlers, error);
|
|
14
30
|
});
|
|
15
31
|
return socket;
|
|
16
32
|
}
|
|
17
33
|
export function RoomsSocket({ config }) {
|
|
34
|
+
let currentConfig = { ...config };
|
|
18
35
|
const roomsToListeners = {};
|
|
19
36
|
const handlers = {
|
|
20
|
-
connect: () => {
|
|
37
|
+
connect: async () => {
|
|
38
|
+
const promises = [];
|
|
21
39
|
Object.keys(roomsToListeners).forEach((room) => {
|
|
22
|
-
var _a;
|
|
23
40
|
joinRoom(room);
|
|
24
|
-
|
|
25
|
-
|
|
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());
|
|
26
45
|
});
|
|
27
46
|
});
|
|
47
|
+
await Promise.all(promises);
|
|
28
48
|
},
|
|
29
|
-
update_model: (msg) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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);
|
|
53
|
+
},
|
|
54
|
+
error: async (error) => {
|
|
55
|
+
console.error("error", error);
|
|
56
|
+
const promises = Object.values(roomsToListeners)
|
|
57
|
+
.flat()
|
|
58
|
+
.map((listener) => { var _a; return (_a = listener.error) === null || _a === void 0 ? void 0 : _a.call(listener, error); });
|
|
59
|
+
await Promise.all(promises);
|
|
36
60
|
},
|
|
37
61
|
};
|
|
38
62
|
let socket = initializeSocket(config, handlers);
|
|
39
63
|
function cleanup() {
|
|
64
|
+
disconnect();
|
|
65
|
+
}
|
|
66
|
+
function disconnect() {
|
|
40
67
|
if (socket) {
|
|
41
68
|
socket.disconnect();
|
|
42
69
|
}
|
|
43
70
|
}
|
|
44
71
|
function updateConfig(config) {
|
|
45
72
|
cleanup();
|
|
46
|
-
|
|
73
|
+
currentConfig = {
|
|
74
|
+
...currentConfig,
|
|
75
|
+
...config,
|
|
76
|
+
};
|
|
77
|
+
socket = initializeSocket(currentConfig, handlers);
|
|
47
78
|
}
|
|
48
79
|
function joinRoom(room) {
|
|
49
80
|
socket.emit("join", room);
|
|
@@ -51,6 +82,11 @@ export function RoomsSocket({ config }) {
|
|
|
51
82
|
function leaveRoom(room) {
|
|
52
83
|
socket.emit("leave", room);
|
|
53
84
|
}
|
|
85
|
+
async function updateModel(room, data) {
|
|
86
|
+
var _a;
|
|
87
|
+
const dataStr = JSON.stringify(data);
|
|
88
|
+
return (_a = handlers.update_model) === null || _a === void 0 ? void 0 : _a.call(handlers, { room, data: dataStr });
|
|
89
|
+
}
|
|
54
90
|
function getListeners(room) {
|
|
55
91
|
return roomsToListeners[room];
|
|
56
92
|
}
|
|
@@ -61,13 +97,19 @@ export function RoomsSocket({ config }) {
|
|
|
61
97
|
}
|
|
62
98
|
roomsToListeners[room].push(handlers);
|
|
63
99
|
return () => {
|
|
64
|
-
|
|
100
|
+
var _a, _b;
|
|
101
|
+
roomsToListeners[room] =
|
|
102
|
+
(_b = (_a = roomsToListeners[room]) === null || _a === void 0 ? void 0 : _a.filter((listener) => listener !== handlers)) !== null && _b !== void 0 ? _b : [];
|
|
103
|
+
if (roomsToListeners[room].length === 0) {
|
|
104
|
+
leaveRoom(room);
|
|
105
|
+
}
|
|
65
106
|
};
|
|
66
107
|
};
|
|
67
108
|
return {
|
|
68
|
-
socket
|
|
109
|
+
socket,
|
|
69
110
|
subscribeToRoom,
|
|
70
111
|
updateConfig,
|
|
71
|
-
|
|
112
|
+
updateModel,
|
|
113
|
+
disconnect,
|
|
72
114
|
};
|
|
73
115
|
}
|