Tesseract / studio /src /api /projects.js
rkbosamia's picture
Tesseract major version upgrade - v2
9c49532
Raw
History Blame Contribute Delete
2.25 kB
// Client for project FS + process endpoints. Phase 3 swapped the v1
// virtual-path system (/App.jsx, /styles.css) for real on-disk paths;
// the agent now edits anywhere in the tree via tools, so no bridge needed.
export async function getProject(projectId) {
const r = await fetch(`/api/projects/${projectId}`)
if (!r.ok) throw new Error(`getProject ${r.status}`)
return r.json()
}
export async function getTree(projectId) {
const r = await fetch(`/api/projects/${projectId}/tree`)
if (!r.ok) throw new Error(`getTree ${r.status}`)
return (await r.json()).entries
}
export async function readFile(projectId, path) {
const r = await fetch(`/api/projects/${projectId}/files?path=${encodeURIComponent(path)}`)
if (!r.ok) throw new Error(`readFile ${path} ${r.status}`)
return (await r.json()).content
}
export async function writeFile(projectId, path, content) {
const r = await fetch(`/api/projects/${projectId}/files`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ path, content }),
})
if (!r.ok) throw new Error(`writeFile ${path} ${r.status}`)
}
export async function deleteFile(projectId, path) {
const r = await fetch(
`/api/projects/${projectId}/files?path=${encodeURIComponent(path)}`,
{ method: 'DELETE' },
)
if (!r.ok && r.status !== 204) throw new Error(`deleteFile ${path} ${r.status}`)
}
// ── Process API ───────────────────────────────────────────────────────────────
export async function startProcesses(projectId) {
const r = await fetch(`/api/projects/${projectId}/processes/start`, { method: 'POST' })
if (!r.ok) throw new Error(`startProcesses ${r.status}`)
return r.json()
}
export async function stopProcesses(projectId) {
const r = await fetch(`/api/projects/${projectId}/processes/stop`, { method: 'POST' })
if (!r.ok) throw new Error(`stopProcesses ${r.status}`)
return r.json()
}
export async function getProcessStatus(projectId) {
const r = await fetch(`/api/projects/${projectId}/processes`)
if (!r.ok) throw new Error(`getProcessStatus ${r.status}`)
return r.json()
}