Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | 9x 9x 4x 4x 5x 5x 5x 5x 2x 2x 1x 2x 5x 4x 4x 4x 4x 4x 3x 3x 4x 1x 1x 1x 1x 9x 3x 1x 1x 2x 9x 1x 1x 1x 1x 1x 3x 1x |
const isVscode = typeof window.vscode !== 'undefined';
if (isVscode) {
window.__pendingRequests = new Map();
window.addEventListener('message', (event) => {
const message = event.data;
Eif (message.type === 'apiResponse') {
const { id, error, data } = message;
if (window.__pendingRequests.has(id)) {
const { resolve, reject } = window.__pendingRequests.get(id);
if (error) reject(new Error(error));
else resolve(data);
window.__pendingRequests.delete(id);
}
}
});
}
async function fetch(url, options = {}) {
if (!isVscode) return window.fetch(url, options);
return new Promise((resolve, reject) => {
const id = Math.random().toString(36).substr(2, 9);
window.__pendingRequests.set(id, { resolve, reject });
let parsedBody = undefined;
if (options.body) {
if (typeof options.body === 'string') {
try { parsedBody = JSON.parse(options.body); } catch(e) { parsedBody = options.body; }
} else if (Eoptions.body instanceof FormData) {
parsedBody = {};
for(let [key, val] of options.body.entries()) parsedBody[key] = val;
}
}
window.vscode.postMessage({
type: 'apiCall',
id,
url: url.replace('http://localhost:5555', ''),
method: options.method || 'GET',
body: parsedBody
});
}).then((data) => {
return {
ok: true,
json: async () => data,
text: async () => typeof data === 'string' ? data : JSON.stringify(data)
};
}).catch(err => {
return {
ok: false,
status: 500,
text: async () => err.message
};
});
}
import { DEFAULT_API_BASE } from './constants';
const API_BASE = window.__SCIENCE_ANIMATOR_API_BASE__ || (typeof import.meta !== 'undefined' && import.meta.env?.VITE_API_BASE) || DEFAULT_API_BASE;
async function handleResponse(response) {
if (!response.ok) {
const text = await response.text().catch(() => `HTTP ${response.status}`);
throw new Error(text);
}
return response.json();
}
export const api = {
// Messages
getMessages: (limit, offset) => {
const params = new URLSearchParams();
Iif (limit) params.set('limit', limit);
Iif (offset) params.set('offset', offset);
const qs = params.toString();
return fetch(`${API_BASE}/api/messages${qs ? '?' + qs : ''}`).then(handleResponse);
},
addMessage: (msg) =>
fetch(`${API_BASE}/api/messages`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(msg),
}).then(handleResponse),
patchMessage: (id, data) =>
fetch(`${API_BASE}/api/messages/${id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
}).then(handleResponse),
deleteMessage: (id) =>
fetch(`${API_BASE}/api/messages/${id}`, { method: 'DELETE' }).then(handleResponse),
// Knowledge
getKnowledge: () => fetch(`${API_BASE}/api/knowledge`).then(handleResponse),
addKnowledge: (item) =>
fetch(`${API_BASE}/api/knowledge`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(item),
}).then(handleResponse),
deleteKnowledge: (id) =>
fetch(`${API_BASE}/api/knowledge/${id}`, { method: 'DELETE' }).then(handleResponse),
// Journal
getJournal: () => fetch(`${API_BASE}/api/journal`).then(handleResponse),
addJournalEntry: (entry) =>
fetch(`${API_BASE}/api/journal`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(entry),
}).then(handleResponse),
deleteJournalEntry: (id) =>
fetch(`${API_BASE}/api/journal/${id}`, { method: 'DELETE' }).then(handleResponse),
// Global Config (API keys, preferences)
getConfig: () => fetch(`${API_BASE}/api/config`).then(handleResponse),
saveConfig: (config) =>
fetch(`${API_BASE}/api/config`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(config),
}).then(handleResponse),
// Workspace Management
getCurrentWorkspace: () => fetch(`${API_BASE}/api/workspace`).then(handleResponse),
updateWorkspace: (data) =>
fetch(`${API_BASE}/api/workspace`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
}).then(handleResponse),
getWorkspaces: () => fetch(`${API_BASE}/api/workspaces`).then(handleResponse),
openWorkspace: (workspacePath, name) =>
fetch(`${API_BASE}/api/workspaces/open`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ path: workspacePath, name }),
}).then(handleResponse),
removeWorkspace: (workspacePath) =>
fetch(`${API_BASE}/api/workspaces`, {
method: 'DELETE',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ path: workspacePath }),
}).then(handleResponse),
indexWorkspace: (folder) =>
fetch(`${API_BASE}/api/workspace/index`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ folder: folder || undefined }),
}).then(handleResponse),
// Settings (workspace-scoped, legacy)
getSettings: () => fetch(`${API_BASE}/api/settings`).then(handleResponse),
saveSettings: (settings) =>
fetch(`${API_BASE}/api/settings`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(settings),
}).then(handleResponse),
// Speech-to-text
stt: (audio, mimeType) =>
fetch(`${API_BASE}/api/stt`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ audio, mimeType }),
}).then(handleResponse),
// Models
getModels: () => fetch(`${API_BASE}/api/models`).then(handleResponse),
refreshModels: () =>
fetch(`${API_BASE}/api/models/refresh`, { method: 'POST' }).then(handleResponse),
// ElevenLabs TTS proxy
tts: (text, voiceId = '2GqkwEG6Q10Sm27yuNar') =>
fetch(`${API_BASE}/api/tts`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text, voiceId }),
}).then(r => {
if (!r.ok) throw new Error(`TTS error: ${r.status}`);
return r.blob();
}),
// Deep Research (Interactions API)
listDeepResearch: () =>
fetch(`${API_BASE}/api/deep-research`).then(handleResponse),
startDeepResearch: (input, model) =>
fetch(`${API_BASE}/api/deep-research`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ input, model }),
}).then(handleResponse),
pollDeepResearch: (id) =>
fetch(`${API_BASE}/api/deep-research/${id}`).then(handleResponse),
// Audio cache info
getAudioCache: () => fetch(`${API_BASE}/api/audio-cache`).then(handleResponse),
getAudioCacheDir: () => fetch(`${API_BASE}/api/audio-cache/dir`).then(handleResponse),
// Export
exportSimulation: (messageId, html, audioHashes = []) =>
fetch(`${API_BASE}/api/export/simulation`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ messageId, html, audioHashes }),
}).then(r => {
if (!r.ok) throw new Error(`Export error: ${r.status}`);
return r.blob();
}),
exportSession: (roadmap, mission) =>
fetch(`${API_BASE}/api/export/session`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ roadmap, mission }),
}).then(r => {
if (!r.ok) throw new Error(`Export error: ${r.status}`);
return r.blob();
}),
// Academic paper generation
generatePaper: (data) =>
fetch(`${API_BASE}/api/export/paper`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
}).then(handleResponse),
// Health check
health: () => fetch(`${API_BASE}/api/health`).then(handleResponse),
};
|