* implement dnd uploader show file upload progress write files to hotdirector build simple flaskAPI to process files one off * move document processor calls to util build out dockerfile to run both procs at the same time update UI to check for document processor before upload * disable pragma update on boot * dockerfile changes * add filetype restrictions based on python app support response and show rejected files in the UI * cleanup * stub migrations on boot to prevent exit condition * update CF template for AWS deploy
111 lines
3.0 KiB
JavaScript
111 lines
3.0 KiB
JavaScript
import { API_BASE } from "../utils/constants";
|
|
import { baseHeaders } from "../utils/request";
|
|
|
|
const Workspace = {
|
|
new: async function (data = {}) {
|
|
const { workspace, message } = await fetch(`${API_BASE}/workspace/new`, {
|
|
method: "POST",
|
|
body: JSON.stringify(data),
|
|
headers: baseHeaders(),
|
|
})
|
|
.then((res) => res.json())
|
|
.catch((e) => {
|
|
return { workspace: null, message: e.message };
|
|
});
|
|
|
|
return { workspace, message };
|
|
},
|
|
update: async function (slug, data = {}) {
|
|
const { workspace, message } = await fetch(
|
|
`${API_BASE}/workspace/${slug}/update`,
|
|
{
|
|
method: "POST",
|
|
body: JSON.stringify(data),
|
|
headers: baseHeaders(),
|
|
}
|
|
)
|
|
.then((res) => res.json())
|
|
.catch((e) => {
|
|
return { workspace: null, message: e.message };
|
|
});
|
|
|
|
return { workspace, message };
|
|
},
|
|
modifyEmbeddings: async function (slug, changes = {}) {
|
|
const { workspace, message } = await fetch(
|
|
`${API_BASE}/workspace/${slug}/update-embeddings`,
|
|
{
|
|
method: "POST",
|
|
body: JSON.stringify(changes), // contains 'adds' and 'removes' keys that are arrays of filepaths
|
|
headers: baseHeaders(),
|
|
}
|
|
)
|
|
.then((res) => res.json())
|
|
.catch((e) => {
|
|
return { workspace: null, message: e.message };
|
|
});
|
|
|
|
return { workspace, message };
|
|
},
|
|
chatHistory: async function (slug) {
|
|
const history = await fetch(`${API_BASE}/workspace/${slug}/chats`, {
|
|
headers: baseHeaders(),
|
|
})
|
|
.then((res) => res.json())
|
|
.then((res) => res.history || [])
|
|
.catch(() => []);
|
|
return history;
|
|
},
|
|
sendChat: async function ({ slug }, message, mode = "query") {
|
|
const chatResult = await fetch(`${API_BASE}/workspace/${slug}/chat`, {
|
|
method: "POST",
|
|
body: JSON.stringify({ message, mode }),
|
|
headers: baseHeaders(),
|
|
})
|
|
.then((res) => res.json())
|
|
.catch((e) => {
|
|
console.error(e);
|
|
return null;
|
|
});
|
|
|
|
return chatResult;
|
|
},
|
|
all: async function () {
|
|
const workspaces = await fetch(`${API_BASE}/workspaces`)
|
|
.then((res) => res.json())
|
|
.then((res) => res.workspaces || [])
|
|
.catch(() => []);
|
|
|
|
return workspaces;
|
|
},
|
|
bySlug: async function (slug = "") {
|
|
const workspace = await fetch(`${API_BASE}/workspace/${slug}`, {
|
|
headers: baseHeaders(),
|
|
})
|
|
.then((res) => res.json())
|
|
.then((res) => res.workspace)
|
|
.catch(() => null);
|
|
return workspace;
|
|
},
|
|
delete: async function (slug) {
|
|
const result = await fetch(`${API_BASE}/workspace/${slug}`, {
|
|
method: "DELETE",
|
|
headers: baseHeaders(),
|
|
})
|
|
.then((res) => res.ok)
|
|
.catch(() => false);
|
|
|
|
return result;
|
|
},
|
|
uploadFile: async function (slug, formData) {
|
|
const response = await fetch(`${API_BASE}/workspace/${slug}/upload`, {
|
|
method: "POST",
|
|
body: formData,
|
|
headers: baseHeaders(),
|
|
});
|
|
return response;
|
|
},
|
|
};
|
|
|
|
export default Workspace;
|