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

Function onConnect

packages/kaos/test/ssh-create.test.ts:192–229  ·  view source on GitHub ↗
(client, config, harnessState)

Source from the content-addressed store, hash-verified

190 '/keys/second': 'second-key',
191 },
192 onConnect(client, config, harnessState) {
193 const authHandler = config.authHandler;
194 if (typeof authHandler !== 'function') {
195 client.emit('error', new Error('missing authHandler'));
196 return;
197 }
198
199 const requestNextKey = (): void => {
200 authHandler([], false, (auth: string | AnyAuthMethod | false) => {
201 expect(auth).not.toBe(false);
202 expect(typeof auth).toBe('object');
203 if (auth === false || typeof auth !== 'object') {
204 client.emit('error', new Error('authHandler returned no auth method'));
205 return;
206 }
207 if (auth.type !== 'publickey') {
208 client.emit('error', new Error(`unexpected auth type: ${auth.type}`));
209 return;
210 }
211 const key =
212 typeof auth.key === 'string'
213 ? auth.key
214 : Buffer.isBuffer(auth.key)
215 ? auth.key.toString('utf-8')
216 : JSON.stringify(auth.key);
217 harnessState.attemptedKeys.push(key);
218 if (key === 'first-key') {
219 requestNextKey();
220 return;
221 }
222 queueMicrotask(() => {
223 client.emit('ready');
224 });
225 });
226 };
227
228 requestNextKey();
229 },
230 });
231
232 const ssh = await SSHKaos.create({

Callers

nothing calls this directly

Calls 3

requestNextKeyFunction · 0.85
pumpFunction · 0.85
emitMethod · 0.45

Tested by

no test coverage detected