@base44-preview/sdk 0.7.0-pr.27.ff44f1a → 0.7.0-pr.29.2474cce
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 +1 -36
- package/dist/client.js +20 -37
- package/dist/modules/functions.js +9 -1
- package/dist/utils/extract-snapshot-id-from-host.d.ts +7 -0
- package/dist/utils/extract-snapshot-id-from-host.js +30 -0
- package/package.json +2 -3
- package/dist/modules/agents.d.ts +0 -15
- package/dist/modules/agents.js +0 -96
- package/dist/modules/agents.types.d.ts +0 -44
- package/dist/modules/agents.types.js +0 -1
- package/dist/utils/socket-utils.d.ts +0 -48
- package/dist/utils/socket-utils.js +0 -73
package/dist/client.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare function createClient(config: {
|
|
|
14
14
|
token?: string;
|
|
15
15
|
serviceToken?: string;
|
|
16
16
|
requiresAuth?: boolean;
|
|
17
|
+
functionsVersion?: string;
|
|
17
18
|
}): {
|
|
18
19
|
/**
|
|
19
20
|
* Set authentication token for all requests
|
|
@@ -38,15 +39,6 @@ export declare function createClient(config: {
|
|
|
38
39
|
functions: {
|
|
39
40
|
invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
|
|
40
41
|
};
|
|
41
|
-
agents: {
|
|
42
|
-
getConversations: () => Promise<import("./modules/agents.types.js").AgentConversation[]>;
|
|
43
|
-
getConversation: (conversationId: string) => Promise<import("./modules/agents.types.js").AgentConversation | undefined>;
|
|
44
|
-
listConversations: (filterParams: any) => Promise<import("./modules/agents.types.js").AgentConversation[]>;
|
|
45
|
-
createConversation: (conversation: any) => Promise<import("./modules/agents.types.js").AgentConversation>;
|
|
46
|
-
addMessage: (conversation: any, message: any) => Promise<import("./modules/agents.types.js").AgentMessage>;
|
|
47
|
-
subscribeToConversation: (conversationId: string, onUpdate: any) => () => void;
|
|
48
|
-
updateConfig: (config: Partial<import("./modules/agents.js").AgentsModuleConfig>) => void;
|
|
49
|
-
};
|
|
50
42
|
};
|
|
51
43
|
entities: {};
|
|
52
44
|
integrations: {};
|
|
@@ -65,15 +57,6 @@ export declare function createClient(config: {
|
|
|
65
57
|
functions: {
|
|
66
58
|
invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
|
|
67
59
|
};
|
|
68
|
-
agents: {
|
|
69
|
-
getConversations: () => Promise<import("./modules/agents.types.js").AgentConversation[]>;
|
|
70
|
-
getConversation: (conversationId: string) => Promise<import("./modules/agents.types.js").AgentConversation | undefined>;
|
|
71
|
-
listConversations: (filterParams: any) => Promise<import("./modules/agents.types.js").AgentConversation[]>;
|
|
72
|
-
createConversation: (conversation: any) => Promise<import("./modules/agents.types.js").AgentConversation>;
|
|
73
|
-
addMessage: (conversation: any, message: any) => Promise<import("./modules/agents.types.js").AgentMessage>;
|
|
74
|
-
subscribeToConversation: (conversationId: string, onUpdate: any) => () => void;
|
|
75
|
-
updateConfig: (config: Partial<import("./modules/agents.js").AgentsModuleConfig>) => void;
|
|
76
|
-
};
|
|
77
60
|
};
|
|
78
61
|
export declare function createClientFromRequest(request: Request): {
|
|
79
62
|
/**
|
|
@@ -99,15 +82,6 @@ export declare function createClientFromRequest(request: Request): {
|
|
|
99
82
|
functions: {
|
|
100
83
|
invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
|
|
101
84
|
};
|
|
102
|
-
agents: {
|
|
103
|
-
getConversations: () => Promise<import("./modules/agents.types.js").AgentConversation[]>;
|
|
104
|
-
getConversation: (conversationId: string) => Promise<import("./modules/agents.types.js").AgentConversation | undefined>;
|
|
105
|
-
listConversations: (filterParams: any) => Promise<import("./modules/agents.types.js").AgentConversation[]>;
|
|
106
|
-
createConversation: (conversation: any) => Promise<import("./modules/agents.types.js").AgentConversation>;
|
|
107
|
-
addMessage: (conversation: any, message: any) => Promise<import("./modules/agents.types.js").AgentMessage>;
|
|
108
|
-
subscribeToConversation: (conversationId: string, onUpdate: any) => () => void;
|
|
109
|
-
updateConfig: (config: Partial<import("./modules/agents.js").AgentsModuleConfig>) => void;
|
|
110
|
-
};
|
|
111
85
|
};
|
|
112
86
|
entities: {};
|
|
113
87
|
integrations: {};
|
|
@@ -126,13 +100,4 @@ export declare function createClientFromRequest(request: Request): {
|
|
|
126
100
|
functions: {
|
|
127
101
|
invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
|
|
128
102
|
};
|
|
129
|
-
agents: {
|
|
130
|
-
getConversations: () => Promise<import("./modules/agents.types.js").AgentConversation[]>;
|
|
131
|
-
getConversation: (conversationId: string) => Promise<import("./modules/agents.types.js").AgentConversation | undefined>;
|
|
132
|
-
listConversations: (filterParams: any) => Promise<import("./modules/agents.types.js").AgentConversation[]>;
|
|
133
|
-
createConversation: (conversation: any) => Promise<import("./modules/agents.types.js").AgentConversation>;
|
|
134
|
-
addMessage: (conversation: any, message: any) => Promise<import("./modules/agents.types.js").AgentMessage>;
|
|
135
|
-
subscribeToConversation: (conversationId: string, onUpdate: any) => () => void;
|
|
136
|
-
updateConfig: (config: Partial<import("./modules/agents.js").AgentsModuleConfig>) => void;
|
|
137
|
-
};
|
|
138
103
|
};
|
package/dist/client.js
CHANGED
|
@@ -5,7 +5,6 @@ import { createAuthModule } from "./modules/auth.js";
|
|
|
5
5
|
import { createSsoModule } from "./modules/sso.js";
|
|
6
6
|
import { getAccessToken } from "./utils/auth-utils.js";
|
|
7
7
|
import { createFunctionsModule } from "./modules/functions.js";
|
|
8
|
-
import { createAgentsModule } from "./modules/agents.js";
|
|
9
8
|
/**
|
|
10
9
|
* Create a Base44 client instance
|
|
11
10
|
* @param {Object} config - Client configuration
|
|
@@ -17,12 +16,17 @@ import { createAgentsModule } from "./modules/agents.js";
|
|
|
17
16
|
* @returns {Object} Base44 client instance
|
|
18
17
|
*/
|
|
19
18
|
export function createClient(config) {
|
|
20
|
-
const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, } = config;
|
|
19
|
+
const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, functionsVersion } = config;
|
|
20
|
+
const headers = {
|
|
21
|
+
"X-App-Id": String(appId),
|
|
22
|
+
};
|
|
23
|
+
const functionHeaders = functionsVersion ? {
|
|
24
|
+
...headers,
|
|
25
|
+
"Base44-Functions-Version": functionsVersion
|
|
26
|
+
} : headers;
|
|
21
27
|
const axiosClient = createAxiosClient({
|
|
22
28
|
baseURL: `${serverUrl}/api`,
|
|
23
|
-
headers
|
|
24
|
-
"X-App-Id": String(appId),
|
|
25
|
-
},
|
|
29
|
+
headers,
|
|
26
30
|
token,
|
|
27
31
|
requiresAuth,
|
|
28
32
|
appId,
|
|
@@ -30,9 +34,7 @@ export function createClient(config) {
|
|
|
30
34
|
});
|
|
31
35
|
const functionsAxiosClient = createAxiosClient({
|
|
32
36
|
baseURL: `${serverUrl}/api`,
|
|
33
|
-
headers:
|
|
34
|
-
"X-App-Id": String(appId),
|
|
35
|
-
},
|
|
37
|
+
headers: functionHeaders,
|
|
36
38
|
token,
|
|
37
39
|
requiresAuth,
|
|
38
40
|
appId,
|
|
@@ -41,18 +43,14 @@ export function createClient(config) {
|
|
|
41
43
|
});
|
|
42
44
|
const serviceRoleAxiosClient = createAxiosClient({
|
|
43
45
|
baseURL: `${serverUrl}/api`,
|
|
44
|
-
headers
|
|
45
|
-
"X-App-Id": String(appId),
|
|
46
|
-
},
|
|
46
|
+
headers,
|
|
47
47
|
token: serviceToken,
|
|
48
48
|
serverUrl,
|
|
49
49
|
appId,
|
|
50
50
|
});
|
|
51
51
|
const serviceRoleFunctionsAxiosClient = createAxiosClient({
|
|
52
52
|
baseURL: `${serverUrl}/api`,
|
|
53
|
-
headers:
|
|
54
|
-
"X-App-Id": String(appId),
|
|
55
|
-
},
|
|
53
|
+
headers: functionHeaders,
|
|
56
54
|
token: serviceToken,
|
|
57
55
|
serverUrl,
|
|
58
56
|
appId,
|
|
@@ -63,22 +61,12 @@ export function createClient(config) {
|
|
|
63
61
|
integrations: createIntegrationsModule(axiosClient, appId),
|
|
64
62
|
auth: createAuthModule(axiosClient, functionsAxiosClient, appId),
|
|
65
63
|
functions: createFunctionsModule(functionsAxiosClient, appId),
|
|
66
|
-
agents: createAgentsModule({
|
|
67
|
-
serverUrl,
|
|
68
|
-
appId,
|
|
69
|
-
token,
|
|
70
|
-
}),
|
|
71
64
|
};
|
|
72
65
|
const serviceRoleModules = {
|
|
73
66
|
entities: createEntitiesModule(serviceRoleAxiosClient, appId),
|
|
74
67
|
integrations: createIntegrationsModule(serviceRoleAxiosClient, appId),
|
|
75
68
|
sso: createSsoModule(serviceRoleAxiosClient, appId, token),
|
|
76
69
|
functions: createFunctionsModule(serviceRoleFunctionsAxiosClient, appId),
|
|
77
|
-
agents: createAgentsModule({
|
|
78
|
-
serverUrl,
|
|
79
|
-
appId,
|
|
80
|
-
token: serviceToken,
|
|
81
|
-
}),
|
|
82
70
|
};
|
|
83
71
|
// Always try to get token from localStorage or URL parameters
|
|
84
72
|
if (typeof window !== "undefined") {
|
|
@@ -86,9 +74,6 @@ export function createClient(config) {
|
|
|
86
74
|
const accessToken = token || getAccessToken();
|
|
87
75
|
if (accessToken) {
|
|
88
76
|
userModules.auth.setToken(accessToken);
|
|
89
|
-
userModules.agents.updateConfig({
|
|
90
|
-
token: accessToken,
|
|
91
|
-
});
|
|
92
77
|
}
|
|
93
78
|
}
|
|
94
79
|
// If authentication is required, verify token and redirect to login if needed
|
|
@@ -134,10 +119,10 @@ export function createClient(config) {
|
|
|
134
119
|
*/
|
|
135
120
|
get asServiceRole() {
|
|
136
121
|
if (!serviceToken) {
|
|
137
|
-
throw new Error(
|
|
122
|
+
throw new Error('Service token is required to use asServiceRole. Please provide a serviceToken when creating the client.');
|
|
138
123
|
}
|
|
139
124
|
return serviceRoleModules;
|
|
140
|
-
}
|
|
125
|
+
}
|
|
141
126
|
};
|
|
142
127
|
return client;
|
|
143
128
|
}
|
|
@@ -146,6 +131,7 @@ export function createClientFromRequest(request) {
|
|
|
146
131
|
const serviceRoleAuthHeader = request.headers.get("Base44-Service-Authorization");
|
|
147
132
|
const appId = request.headers.get("Base44-App-Id");
|
|
148
133
|
const serverUrlHeader = request.headers.get("Base44-Api-Url");
|
|
134
|
+
const functionsVersion = request.headers.get("Base44-Functions-Version");
|
|
149
135
|
if (!appId) {
|
|
150
136
|
throw new Error("Base44-App-Id header is required, but is was not found on the request");
|
|
151
137
|
}
|
|
@@ -153,25 +139,22 @@ export function createClientFromRequest(request) {
|
|
|
153
139
|
let serviceRoleToken;
|
|
154
140
|
let userToken;
|
|
155
141
|
if (serviceRoleAuthHeader !== null) {
|
|
156
|
-
if (serviceRoleAuthHeader ===
|
|
157
|
-
!serviceRoleAuthHeader.startsWith("Bearer ") ||
|
|
158
|
-
serviceRoleAuthHeader.split(" ").length !== 2) {
|
|
142
|
+
if (serviceRoleAuthHeader === '' || !serviceRoleAuthHeader.startsWith('Bearer ') || serviceRoleAuthHeader.split(' ').length !== 2) {
|
|
159
143
|
throw new Error('Invalid authorization header format. Expected "Bearer <token>"');
|
|
160
144
|
}
|
|
161
|
-
serviceRoleToken = serviceRoleAuthHeader.split(
|
|
145
|
+
serviceRoleToken = serviceRoleAuthHeader.split(' ')[1];
|
|
162
146
|
}
|
|
163
147
|
if (authHeader !== null) {
|
|
164
|
-
if (authHeader ===
|
|
165
|
-
!authHeader.startsWith("Bearer ") ||
|
|
166
|
-
authHeader.split(" ").length !== 2) {
|
|
148
|
+
if (authHeader === '' || !authHeader.startsWith('Bearer ') || authHeader.split(' ').length !== 2) {
|
|
167
149
|
throw new Error('Invalid authorization header format. Expected "Bearer <token>"');
|
|
168
150
|
}
|
|
169
|
-
userToken = authHeader.split(
|
|
151
|
+
userToken = authHeader.split(' ')[1];
|
|
170
152
|
}
|
|
171
153
|
return createClient({
|
|
172
154
|
serverUrl: serverUrlHeader || "https://base44.app",
|
|
173
155
|
appId,
|
|
174
156
|
token: userToken,
|
|
175
157
|
serviceToken: serviceRoleToken,
|
|
158
|
+
functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined
|
|
176
159
|
});
|
|
177
160
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { extractSnapshotIdFromHost } from "../utils/extract-snapshot-id-from-host.js";
|
|
1
2
|
/**
|
|
2
3
|
* Creates the functions module for the Base44 SDK
|
|
3
4
|
* @param {import('axios').AxiosInstance} axios - Axios instance
|
|
@@ -35,7 +36,14 @@ export function createFunctionsModule(axios, appId) {
|
|
|
35
36
|
formData = data;
|
|
36
37
|
contentType = "application/json";
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
+
// Extract functions version from the current URL host
|
|
40
|
+
const functionsVersion = extractSnapshotIdFromHost();
|
|
41
|
+
return axios.post(`/apps/${appId}/functions/${functionName}`, formData || data, {
|
|
42
|
+
headers: {
|
|
43
|
+
"Content-Type": contentType,
|
|
44
|
+
"X-Functions-Version": functionsVersion
|
|
45
|
+
}
|
|
46
|
+
});
|
|
39
47
|
},
|
|
40
48
|
};
|
|
41
49
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the snapshot ID or environment type from the current hostname
|
|
3
|
+
* Used to determine which backend function deployment to call
|
|
4
|
+
*
|
|
5
|
+
* @returns {string} The snapshot ID for checkpoints, 'preview' for preview URLs, or 'prod' for production
|
|
6
|
+
*/
|
|
7
|
+
export declare function extractSnapshotIdFromHost(): string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the snapshot ID or environment type from the current hostname
|
|
3
|
+
* Used to determine which backend function deployment to call
|
|
4
|
+
*
|
|
5
|
+
* @returns {string} The snapshot ID for checkpoints, 'preview' for preview URLs, or 'prod' for production
|
|
6
|
+
*/
|
|
7
|
+
export function extractSnapshotIdFromHost() {
|
|
8
|
+
if (typeof window === "undefined") {
|
|
9
|
+
return "prod";
|
|
10
|
+
}
|
|
11
|
+
const hostname = window.location.hostname;
|
|
12
|
+
// Check if it's a checkpoint URL
|
|
13
|
+
if (hostname.startsWith("checkpoint--")) {
|
|
14
|
+
// Format: checkpoint--{app_id}--{snapshot_id}.domain
|
|
15
|
+
const parts = hostname.split("--");
|
|
16
|
+
if (parts.length >= 3) {
|
|
17
|
+
// Extract snapshot_id (last part before the domain)
|
|
18
|
+
const snapshotPart = parts[2];
|
|
19
|
+
// Remove domain extension if present
|
|
20
|
+
const snapshotId = snapshotPart.split(".")[0];
|
|
21
|
+
return snapshotId;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// Check if it's a preview URL
|
|
25
|
+
if (hostname.startsWith("preview--")) {
|
|
26
|
+
return "preview";
|
|
27
|
+
}
|
|
28
|
+
// Production URLs - return "prod"
|
|
29
|
+
return "prod";
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base44-preview/sdk",
|
|
3
|
-
"version": "0.7.0-pr.
|
|
3
|
+
"version": "0.7.0-pr.29.2474cce",
|
|
4
4
|
"description": "JavaScript SDK for Base44 API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,8 +19,7 @@
|
|
|
19
19
|
"prepublishOnly": "npm run build"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"axios": "^1.6.2"
|
|
23
|
-
"socket.io-client": "^4.7.5"
|
|
22
|
+
"axios": "^1.6.2"
|
|
24
23
|
},
|
|
25
24
|
"devDependencies": {
|
|
26
25
|
"@vitest/coverage-istanbul": "^1.0.0",
|
package/dist/modules/agents.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { AgentConversation, AgentMessage } from "./agents.types";
|
|
2
|
-
export type AgentsModuleConfig = {
|
|
3
|
-
serverUrl: string;
|
|
4
|
-
appId: string;
|
|
5
|
-
token?: string;
|
|
6
|
-
};
|
|
7
|
-
export declare function createAgentsModule({ appId, serverUrl, token, }: AgentsModuleConfig): {
|
|
8
|
-
getConversations: () => Promise<AgentConversation[]>;
|
|
9
|
-
getConversation: (conversationId: string) => Promise<AgentConversation | undefined>;
|
|
10
|
-
listConversations: (filterParams: any) => Promise<AgentConversation[]>;
|
|
11
|
-
createConversation: (conversation: any) => Promise<AgentConversation>;
|
|
12
|
-
addMessage: (conversation: any, message: any) => Promise<AgentMessage>;
|
|
13
|
-
subscribeToConversation: (conversationId: string, onUpdate: any) => () => void;
|
|
14
|
-
updateConfig: (config: Partial<AgentsModuleConfig>) => void;
|
|
15
|
-
};
|
package/dist/modules/agents.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { RoomsSocket } from "../utils/socket-utils";
|
|
2
|
-
import { createAxiosClient } from "../utils/axios-client";
|
|
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
|
-
};
|
|
31
|
-
const getConversations = () => {
|
|
32
|
-
return axios.get(`/conversations`);
|
|
33
|
-
};
|
|
34
|
-
const getConversation = (conversationId) => {
|
|
35
|
-
return axios.get(`/conversations/${conversationId}`);
|
|
36
|
-
};
|
|
37
|
-
const listConversations = (filterParams) => {
|
|
38
|
-
return axios.get(`/conversations`, {
|
|
39
|
-
params: filterParams,
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
const createConversation = (conversation) => {
|
|
43
|
-
return axios.post(`/conversations`, conversation);
|
|
44
|
-
};
|
|
45
|
-
const addMessage = (conversation, message) => {
|
|
46
|
-
// this whole trick with current conversation so that we can call the onUpdateModel with the latest messages
|
|
47
|
-
let convLatestMessages = null;
|
|
48
|
-
if (currentConversation && currentConversation.id === conversation.id) {
|
|
49
|
-
convLatestMessages = currentConversation.messages;
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
currentConversation = conversation;
|
|
53
|
-
convLatestMessages = conversation.messages;
|
|
54
|
-
}
|
|
55
|
-
conversation.messages = [...convLatestMessages, message];
|
|
56
|
-
roomSocket.handlers.update_model({
|
|
57
|
-
room: `/agent-conversations/${conversation.id}`,
|
|
58
|
-
data: JSON.stringify(conversation),
|
|
59
|
-
});
|
|
60
|
-
return axios.post(`/conversations/${conversation.id}/messages`, message);
|
|
61
|
-
};
|
|
62
|
-
const subscribeToConversation = (conversationId, onUpdate) => {
|
|
63
|
-
return roomSocket.subscribeToRoom(`/agent-conversations/${conversationId}`, {
|
|
64
|
-
connect: () => { },
|
|
65
|
-
update_model: ({ data: jsonStr }) => {
|
|
66
|
-
const data = JSON.parse(jsonStr);
|
|
67
|
-
if (currentConversation && currentConversation.id === data.id) {
|
|
68
|
-
currentConversation = data;
|
|
69
|
-
}
|
|
70
|
-
onUpdate(data);
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
return {
|
|
75
|
-
getConversations,
|
|
76
|
-
getConversation,
|
|
77
|
-
listConversations,
|
|
78
|
-
createConversation,
|
|
79
|
-
addMessage,
|
|
80
|
-
subscribeToConversation,
|
|
81
|
-
updateConfig,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
function createAgentsAxiosClient({ serverUrl, appId, token, }) {
|
|
85
|
-
const axios = createAxiosClient({
|
|
86
|
-
baseURL: `${serverUrl}/api/apps/${appId}/agents`,
|
|
87
|
-
appId,
|
|
88
|
-
serverUrl,
|
|
89
|
-
token,
|
|
90
|
-
interceptResponses: true,
|
|
91
|
-
headers: {
|
|
92
|
-
"X-App-Id": String(appId),
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
return axios;
|
|
96
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Socket } from "socket.io-client";
|
|
2
|
-
export type RoomsSocketConfig = {
|
|
3
|
-
serverUrl: string;
|
|
4
|
-
mountPath: string;
|
|
5
|
-
transports: string[];
|
|
6
|
-
query: {
|
|
7
|
-
appId: string;
|
|
8
|
-
token?: string;
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
export type TSocketRoom = string;
|
|
12
|
-
export type TJsonStr = string;
|
|
13
|
-
type RoomsSocketEventsMap = {
|
|
14
|
-
listen: {
|
|
15
|
-
connect: () => void;
|
|
16
|
-
update_model: (msg: {
|
|
17
|
-
room: string;
|
|
18
|
-
data: TJsonStr;
|
|
19
|
-
}) => void;
|
|
20
|
-
};
|
|
21
|
-
emit: {
|
|
22
|
-
join: (room: string) => void;
|
|
23
|
-
leave: (room: string) => void;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
type TEvent = keyof RoomsSocketEventsMap["listen"];
|
|
27
|
-
type THandler<E extends TEvent> = (...args: Parameters<RoomsSocketEventsMap["listen"][E]>) => void;
|
|
28
|
-
export declare function RoomsSocket({ config }: {
|
|
29
|
-
config: RoomsSocketConfig;
|
|
30
|
-
}): {
|
|
31
|
-
socket: Readonly<Socket<{
|
|
32
|
-
connect: () => void;
|
|
33
|
-
update_model: (msg: {
|
|
34
|
-
room: string;
|
|
35
|
-
data: TJsonStr;
|
|
36
|
-
}) => void;
|
|
37
|
-
}, {
|
|
38
|
-
join: (room: string) => void;
|
|
39
|
-
leave: (room: string) => void;
|
|
40
|
-
}>>;
|
|
41
|
-
subscribeToRoom: (room: TSocketRoom, handlers: { [k in TEvent]: THandler<k>; }) => () => void;
|
|
42
|
-
updateConfig: (config: RoomsSocketConfig) => void;
|
|
43
|
-
handlers: {
|
|
44
|
-
connect: THandler<"connect">;
|
|
45
|
-
update_model: THandler<"update_model">;
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
export {};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { io } from "socket.io-client";
|
|
2
|
-
function initializeSocket(config, handlers) {
|
|
3
|
-
const socket = io(config.serverUrl, {
|
|
4
|
-
path: config.mountPath,
|
|
5
|
-
transports: config.transports,
|
|
6
|
-
query: config.query,
|
|
7
|
-
});
|
|
8
|
-
socket.on("connect", () => {
|
|
9
|
-
console.log("connect", socket.id);
|
|
10
|
-
handlers.connect();
|
|
11
|
-
});
|
|
12
|
-
socket.on("update_model", (msg) => {
|
|
13
|
-
handlers.update_model(msg);
|
|
14
|
-
});
|
|
15
|
-
return socket;
|
|
16
|
-
}
|
|
17
|
-
export function RoomsSocket({ config }) {
|
|
18
|
-
const roomsToListeners = {};
|
|
19
|
-
const handlers = {
|
|
20
|
-
connect: () => {
|
|
21
|
-
Object.keys(roomsToListeners).forEach((room) => {
|
|
22
|
-
var _a;
|
|
23
|
-
joinRoom(room);
|
|
24
|
-
(_a = getListeners(room)) === null || _a === void 0 ? void 0 : _a.forEach(({ connect: connectHandler }) => {
|
|
25
|
-
connectHandler();
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
},
|
|
29
|
-
update_model: (msg) => {
|
|
30
|
-
var _a;
|
|
31
|
-
if (roomsToListeners[msg.room]) {
|
|
32
|
-
(_a = getListeners(msg.room)) === null || _a === void 0 ? void 0 : _a.forEach(({ update_model }) => {
|
|
33
|
-
update_model(msg);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
let socket = initializeSocket(config, handlers);
|
|
39
|
-
function cleanup() {
|
|
40
|
-
if (socket) {
|
|
41
|
-
socket.disconnect();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function updateConfig(config) {
|
|
45
|
-
cleanup();
|
|
46
|
-
socket = initializeSocket(config, handlers);
|
|
47
|
-
}
|
|
48
|
-
function joinRoom(room) {
|
|
49
|
-
socket.emit("join", room);
|
|
50
|
-
}
|
|
51
|
-
function leaveRoom(room) {
|
|
52
|
-
socket.emit("leave", room);
|
|
53
|
-
}
|
|
54
|
-
function getListeners(room) {
|
|
55
|
-
return roomsToListeners[room];
|
|
56
|
-
}
|
|
57
|
-
const subscribeToRoom = (room, handlers) => {
|
|
58
|
-
if (!roomsToListeners[room]) {
|
|
59
|
-
joinRoom(room);
|
|
60
|
-
roomsToListeners[room] = [];
|
|
61
|
-
}
|
|
62
|
-
roomsToListeners[room].push(handlers);
|
|
63
|
-
return () => {
|
|
64
|
-
roomsToListeners[room] = roomsToListeners[room].filter((listener) => listener !== handlers);
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
return {
|
|
68
|
-
socket: Object.freeze(socket),
|
|
69
|
-
subscribeToRoom,
|
|
70
|
-
updateConfig,
|
|
71
|
-
handlers,
|
|
72
|
-
};
|
|
73
|
-
}
|