// Every read the unified workspace screens make: the organization list, the theme table and the // per-organization routes under /api/orgs//. Nothing here writes. A read that fails throws, so // each caller says "unavailable" for that one part instead of guessing. (() => { const read = async path => { const response = await fetch(path, { cache: 'no-store', redirect: 'manual' }); // The status travels with the failure, so a caller can tell a refusal (403) from a bus that is down. if (!response.ok || response.type === 'opaqueredirect') { const error = new Error('Read unavailable'); error.status = response.type === 'opaqueredirect' ? 0 : response.status; throw error; } return response.json(); }; const orgPath = (id, path) => `/api/orgs/${encodeURIComponent(id)}/${path}`; const organizations = () => read('/api/orgs'); const themes = () => read('/api/themes'); const projects = id => read(orgPath(id, 'chat/projects')); const threads = id => read(orgPath(id, 'chat/threads')); const instances = id => read(orgPath(id, 'bus/instances')); // Held roles with the state the bus derives (working, waiting, idle), and which run holds which thread. const agents = id => read(orgPath(id, 'bus/agents')); const claims = id => read(orgPath(id, 'bus/thread.claims')); const queue = id => read(orgPath(id, 'queue')); const business = id => read(orgPath(id, 'business')); const settings = id => read(orgPath(id, 'settings')); const projectFiles = (id, project) => read(orgPath(id, `project-files?project=${encodeURIComponent(project)}`)); // U1's cross-organization read (GET /api/workspace). Only the keys it accepts are sent, each once: // an unknown or repeated key is a 400 there. const WORKSPACE_KEYS = ['sections', 'org', 'status', 'state', 'name', 'sort', 'order', 'project']; const workspace = (params = {}) => { const q = new URLSearchParams(); for (const key of WORKSPACE_KEYS) { const v = params[key]; if (v !== undefined && v !== null && v !== '') q.set(key, Array.isArray(v) ? v.join(',') : String(v)); } const qs = q.toString(); return read(`/api/workspace${qs ? `?${qs}` : ''}`); }; // The three agent levels (root, organization, project) for every organization on the list, owner only. const agentLevels = () => read('/api/agents/levels'); window.MosaicWorkspaceData = Object.freeze({ organizations, themes, projects, threads, instances, agents, claims, queue, business, settings, projectFiles, workspace, agentLevels }); })();