- hub: FastAPI backend (MCP server, ADB LAN controller, bridge, storage) - hub/web: Vue 3 admin console (device manager, screen mirror, chat workbench) - android: Kotlin shell app with WebView stage, OTA, telemetry, keep-alive - protocol: architecture, MCP schema, and WebSocket protocol specs
94 lines
4.5 KiB
JavaScript
94 lines
4.5 KiB
JavaScript
async function request(path, options = {}) {
|
|
const res = await fetch(path, {
|
|
headers: { 'Content-Type': 'application/json', ...(options.headers || {}) },
|
|
...options
|
|
})
|
|
if (!res.ok) {
|
|
const text = await res.text().catch(() => '')
|
|
let detail = text || res.statusText
|
|
try {
|
|
const j = JSON.parse(text)
|
|
if (j.detail) detail = j.detail
|
|
} catch (_) {}
|
|
throw new Error(detail)
|
|
}
|
|
return res.json()
|
|
}
|
|
|
|
export const hubApi = {
|
|
getDevices: () => request('/api/admin/devices'),
|
|
getDeviceMetrics: (deviceId, range = '1h') =>
|
|
request(`/api/admin/devices/${encodeURIComponent(deviceId)}/metrics?range=${encodeURIComponent(range)}`),
|
|
getConfig: () => request('/api/admin/config'),
|
|
saveGlobalConfig: (body) => request('/api/admin/config', { method: 'PUT', body: JSON.stringify(body) }),
|
|
saveChatAiConfig: (body) => request('/api/admin/chat-ai-config', { method: 'PUT', body: JSON.stringify(body) }),
|
|
saveDeviceRepairAi: (deviceId, body) =>
|
|
request(`/api/admin/devices/${encodeURIComponent(deviceId)}/repair-ai`, { method: 'PUT', body: JSON.stringify(body) }),
|
|
setDeviceLanDebug: (deviceId, body) =>
|
|
request(`/api/admin/devices/${encodeURIComponent(deviceId)}/lan-debug`, { method: 'PUT', body: JSON.stringify(body) }),
|
|
lanAdbAction: (deviceId, action, params = {}) =>
|
|
request(`/api/lan-debug/${encodeURIComponent(deviceId)}/action`, {
|
|
method: 'POST',
|
|
body: JSON.stringify({ action, params })
|
|
}),
|
|
pairWirelessAdb: (pairAddress, pairingCode, deviceId = null) =>
|
|
request('/api/lan-debug/pair', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ pair_address: pairAddress, pairing_code: pairingCode, device_id: deviceId })
|
|
}),
|
|
getSnapshots: (deviceId) => request(`/api/admin/snapshots/${encodeURIComponent(deviceId)}`),
|
|
rollbackDevice: (deviceId, snapshotId) =>
|
|
request(`/api/admin/devices/${encodeURIComponent(deviceId)}/rollback`, {
|
|
method: 'POST',
|
|
body: JSON.stringify({ snapshot_id: snapshotId })
|
|
}),
|
|
quickAction: (kind, deviceId) =>
|
|
request(`/api/admin/test/${kind}`, { method: 'POST', body: JSON.stringify({ device_id: deviceId }) }),
|
|
getOtaLatest: () => request('/api/ota/latest'),
|
|
pushOta: (deviceId = null) => {
|
|
const q = deviceId ? `?device_id=${encodeURIComponent(deviceId)}` : ''
|
|
return request(`/api/admin/ota/push${q}`, { method: 'POST' })
|
|
},
|
|
getAdbOtaStatus: (deviceId) => request(`/api/admin/ota/adb-status/${encodeURIComponent(deviceId)}`),
|
|
saveDeviceUiPrefs: (deviceId, body) =>
|
|
request(`/api/admin/devices/${encodeURIComponent(deviceId)}/ui-prefs`, { method: 'PUT', body: JSON.stringify(body) }),
|
|
getEvents: () => request('/api/admin/events'),
|
|
getAudits: () => request('/api/admin/audits'),
|
|
|
|
// Persistent multi-session background chat
|
|
listChatSessions: () => request('/api/admin/chat/sessions'),
|
|
createChatSession: (title = '新会话') =>
|
|
request('/api/admin/chat/sessions', { method: 'POST', body: JSON.stringify({ title }) }),
|
|
renameChatSession: (sessionId, title) =>
|
|
request(`/api/admin/chat/sessions/${encodeURIComponent(sessionId)}`, {
|
|
method: 'PUT',
|
|
body: JSON.stringify({ title })
|
|
}),
|
|
deleteChatSession: (sessionId) =>
|
|
request(`/api/admin/chat/sessions/${encodeURIComponent(sessionId)}`, { method: 'DELETE' }),
|
|
getSessionMessages: (sessionId) =>
|
|
request(`/api/admin/chat/sessions/${encodeURIComponent(sessionId)}/messages`),
|
|
sendSessionMessage: (sessionId, message) =>
|
|
request(`/api/admin/chat/sessions/${encodeURIComponent(sessionId)}/messages`, {
|
|
method: 'POST',
|
|
body: JSON.stringify({ message })
|
|
}),
|
|
|
|
// Quick prompt groups & items
|
|
listPrompts: () => request('/api/admin/prompts'),
|
|
createPromptGroup: (name, sortOrder = 0) =>
|
|
request('/api/admin/prompt-groups', { method: 'POST', body: JSON.stringify({ name, sort_order: sortOrder }) }),
|
|
updatePromptGroup: (groupId, name, sortOrder = 0) =>
|
|
request(`/api/admin/prompt-groups/${encodeURIComponent(groupId)}`, {
|
|
method: 'PUT',
|
|
body: JSON.stringify({ name, sort_order: sortOrder })
|
|
}),
|
|
deletePromptGroup: (groupId) =>
|
|
request(`/api/admin/prompt-groups/${encodeURIComponent(groupId)}`, { method: 'DELETE' }),
|
|
createPrompt: (body) => request('/api/admin/prompts', { method: 'POST', body: JSON.stringify(body) }),
|
|
updatePrompt: (promptId, body) =>
|
|
request(`/api/admin/prompts/${encodeURIComponent(promptId)}`, { method: 'PUT', body: JSON.stringify(body) }),
|
|
deletePrompt: (promptId) =>
|
|
request(`/api/admin/prompts/${encodeURIComponent(promptId)}`, { method: 'DELETE' })
|
|
}
|