MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / fetchConnections

Function fetchConnections

apps/kimi-code/src/cli/sub/server/ps.ts:80–106  ·  view source on GitHub ↗
(origin: string, token: string)

Source from the content-addressed store, hash-verified

78}
79
80async function fetchConnections(origin: string, token: string): Promise<ConnectionInfo[]> {
81 const controller = new AbortController();
82 const timeout = setTimeout(() => {
83 controller.abort();
84 }, FETCH_TIMEOUT_MS);
85 try {
86 const res = await fetch(`${origin}/api/v1/connections`, {
87 headers: authHeaders(token),
88 signal: controller.signal,
89 });
90 if (!res.ok) {
91 throw new Error(`Failed to list clients: HTTP ${String(res.status)} from ${origin}.`);
92 }
93 const body = (await res.json()) as ConnectionsEnvelope;
94 if (body.code !== 0) {
95 throw new Error(`Failed to list clients: ${body.msg}`);
96 }
97 return body.data?.connections ?? [];
98 } catch (error) {
99 if (error instanceof Error && error.name === 'AbortError') {
100 throw new Error(`Timed out listing clients from ${origin}.`);
101 }
102 throw error;
103 } finally {
104 clearTimeout(timeout);
105 }
106}
107
108function formatTable(connections: ConnectionInfo[]): string {
109 if (connections.length === 0) {

Callers 1

handlePsCommandFunction · 0.85

Calls 3

authHeadersFunction · 0.90
jsonMethod · 0.80
abortMethod · 0.65

Tested by

no test coverage detected