-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapi.ts
More file actions
52 lines (47 loc) · 1.29 KB
/
Copy pathapi.ts
File metadata and controls
52 lines (47 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import axios from "axios";
import { config } from "./config.js";
import { checkVersionCompatibility } from "./utils/version-check.js";
const BASE_URL = config.api_base_url;
axios.interceptors.response.use(
(response) => response,
async (error) => {
// Network error (no response received)
if (!error.response) {
const networkError = new Error(
"Network error: No internet connection"
) as Error & { code: string };
networkError.code = "NETWORK_ERROR";
return Promise.reject(networkError);
}
if (error.response) {
const isCompatible = await checkVersionCompatibility(true);
if (!isCompatible) {
return Promise.reject(
new Error(
"CLI version deprecated. Try updating to the latest version."
)
);
}
}
return Promise.reject(error);
}
);
//check for valid api key
export const isValidAuthKey = async (authKey: string) => {
const isValid = await axios.post(`${BASE_URL}/auth/login`, { authKey });
return isValid.data;
};
export const toolFunctionCall = async (
tool_call_id,
resultArgs,
args,
function_name
) => {
const result = await axios.post(`${BASE_URL}/tool/toolFunctionCall`, {
tool_call_id,
resultArgs,
args,
function_name,
});
return result?.data;
};