MCPcopy Index your code
hub / github.com/tiann/hapi / runLocalRemoteLoop

Function runLocalRemoteLoop

cli/src/agent/loopBase.ts:27–61  ·  view source on GitHub ↗
(opts: {
    session: TSession;
    startingMode?: 'local' | 'remote';
    logTag: string;
    runLocal: LoopLauncher<TSession>;
    runRemote: LoopLauncher<TSession>;
})

Source from the content-addressed store, hash-verified

25}
26
27export async function runLocalRemoteLoop<TSession extends AgentSessionBase<any>>(opts: {
28 session: TSession;
29 startingMode?: 'local' | 'remote';
30 logTag: string;
31 runLocal: LoopLauncher<TSession>;
32 runRemote: LoopLauncher<TSession>;
33}): Promise<void> {
34 let mode: 'local' | 'remote' = opts.startingMode ?? 'local';
35
36 while (true) {
37 logger.debug(`[${opts.logTag}] Iteration with mode: ${mode}`);
38
39 if (mode === 'local') {
40 const reason = await opts.runLocal(opts.session);
41 if (reason === 'exit') {
42 return;
43 }
44
45 mode = 'remote';
46 opts.session.onModeChange(mode);
47 continue;
48 }
49
50 if (mode === 'remote') {
51 const reason = await opts.runRemote(opts.session);
52 if (reason === 'exit') {
53 return;
54 }
55
56 mode = 'local';
57 opts.session.onModeChange(mode);
58 continue;
59 }
60 }
61}

Callers 1

runLocalRemoteSessionFunction · 0.85

Calls 1

debugMethod · 0.80

Tested by

no test coverage detected