feat(mcp): подготовить сервер и доступ к приёмке
This commit is contained in:
commit
bf3d50e1ff
3835 files changed
+537122
No files matched your search
@@ -0,0 +1,73 @@
|
||||
import {
|
||||
serverListSchema,
|
||||
serverReadSchema,
|
||||
testConnectionSchema,
|
||||
type ServerCreate,
|
||||
type ServerRead,
|
||||
type ServerUpdate,
|
||||
type TestConnectionRequest,
|
||||
} from "@mmapp/contracts/servers"
|
||||
import { requestJson as httpRequestJson } from "@/shared/api/http-client"
|
||||
|
||||
function requestJson<T>(baseUrl: string, path: string, init?: RequestInit): Promise<T> {
|
||||
return httpRequestJson<T>(baseUrl, path, {
|
||||
...init,
|
||||
// The executor retains its 180s bound; allow 5s for the final HTTP response.
|
||||
signal: AbortSignal.timeout(path.endsWith("/poll") ? 185_000 : 30_000),
|
||||
})
|
||||
}
|
||||
|
||||
type TestConnectionResponse = {
|
||||
success: boolean
|
||||
latencyMs?: number
|
||||
identity?: string
|
||||
version?: string
|
||||
boardName?: string
|
||||
uptime?: string
|
||||
message: string
|
||||
}
|
||||
|
||||
export async function listServers(baseUrl: string): Promise<ServerRead[]> {
|
||||
const payload = await requestJson<unknown>(baseUrl, "/api/servers")
|
||||
return serverListSchema.parse(payload)
|
||||
}
|
||||
|
||||
export async function getServer(baseUrl: string, id: string): Promise<ServerRead> {
|
||||
const payload = await requestJson<unknown>(baseUrl, `/api/servers/${id}`)
|
||||
return serverReadSchema.parse(payload)
|
||||
}
|
||||
|
||||
export async function createServer(baseUrl: string, data: ServerCreate): Promise<ServerRead> {
|
||||
const payload = await requestJson<unknown>(baseUrl, "/api/servers", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
return serverReadSchema.parse(payload)
|
||||
}
|
||||
|
||||
export async function updateServer(baseUrl: string, id: string, data: ServerUpdate): Promise<ServerRead> {
|
||||
const payload = await requestJson<unknown>(baseUrl, `/api/servers/${id}`, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
return serverReadSchema.parse(payload)
|
||||
}
|
||||
|
||||
export async function deleteServer(baseUrl: string, id: string): Promise<void> {
|
||||
await requestJson<void>(baseUrl, `/api/servers/${id}`, { method: "DELETE" })
|
||||
}
|
||||
|
||||
export async function pollServer(baseUrl: string, id: string): Promise<void> {
|
||||
await requestJson<unknown>(baseUrl, `/api/servers/${id}/poll`, { method: "POST" })
|
||||
}
|
||||
|
||||
export async function testServerConnection(
|
||||
baseUrl: string,
|
||||
payload: TestConnectionRequest,
|
||||
): Promise<TestConnectionResponse> {
|
||||
testConnectionSchema.parse(payload)
|
||||
return requestJson<TestConnectionResponse>(baseUrl, "/api/servers/test-connection", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(payload),
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user