feat: extract MyAgent core and web console
This commit is contained in:
commit
e491b1a35b
83 files changed
+13651
No files matched your search
@@ -0,0 +1,45 @@
|
||||
export const API_BASE = (import.meta.env.VITE_API_BASE_URL || '').replace(/\/$/, '');
|
||||
|
||||
async function request(path, options = {}) {
|
||||
const res = await fetch(API_BASE + path, options);
|
||||
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
|
||||
return res;
|
||||
}
|
||||
|
||||
export const apiClient = {
|
||||
async json(path, options) {
|
||||
const res = await request(path, options);
|
||||
return await res.json();
|
||||
},
|
||||
async text(path, options) {
|
||||
const res = await request(path, options);
|
||||
return await res.text();
|
||||
},
|
||||
async raw(path, options) {
|
||||
return await request(path, options);
|
||||
}
|
||||
};
|
||||
|
||||
export function jsonOptions(body) {
|
||||
return {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body)
|
||||
};
|
||||
}
|
||||
|
||||
export function putJsonOptions(body) {
|
||||
return {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body)
|
||||
};
|
||||
}
|
||||
|
||||
export function textPutOptions(body) {
|
||||
return {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
|
||||
body
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user