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

Function ensureConnection

apps/kimi-web/src/composables/useTerminal.ts:17–44  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15 let conn: KimiEventConnection | null = null;
16
17 function ensureConnection(): KimiEventConnection | null {
18 if (conn !== null) return conn;
19 if (typeof WebSocket === 'undefined') return null;
20 conn = getKimiWebApi().connectEvents({
21 onEvent: () => {},
22 onResync: () => {},
23 onError: (_code, msg) => {
24 error.value = msg;
25 },
26 onConnectionChange: (state) => {
27 connected.value = state;
28 },
29 onTerminalOutput: (sid, terminalId, data, seq) => {
30 if (sid !== sessionId.value || terminal.value?.id !== terminalId) return;
31 lastSeq.value = Math.max(lastSeq.value, seq);
32 for (const handler of outputHandlers) handler(data);
33 },
34 onTerminalExit: (sid, terminalId, exitCode) => {
35 if (sid !== sessionId.value || terminal.value?.id !== terminalId) return;
36 readOnly.value = true;
37 terminal.value = terminal.value
38 ? { ...terminal.value, status: 'exited', exitCode }
39 : terminal.value;
40 for (const handler of exitHandlers) handler(exitCode);
41 },
42 });
43 return conn;
44 }
45
46 async function start(size?: { cols?: number; rows?: number }): Promise<void> {
47 const sid = sessionId.value;

Callers 4

startFunction · 0.85
writeFunction · 0.85
resizeFunction · 0.85
closeFunction · 0.85

Calls 3

getKimiWebApiFunction · 0.90
connectEventsMethod · 0.65
handlerFunction · 0.50

Tested by

no test coverage detected