MCPcopy Create free account
hub / github.com/Noumena-Network/code / runLocalQueryEngineTurn

Function runLocalQueryEngineTurn

src/session/localQueryEngineController.ts:24–56  ·  view source on GitHub ↗
(
  options: RunLocalQueryEngineTurnOptions,
  deps?: LocalQueryEngineControllerDeps,
)

Source from the content-addressed store, hash-verified

22 * provided callback. Returns after the turn generator completes.
23 */
24export async function runLocalQueryEngineTurn(
25 options: RunLocalQueryEngineTurnOptions,
26 deps?: LocalQueryEngineControllerDeps,
27): Promise<Terminal> {
28 const { params, onEvent } = options
29 logForDebugging('[ncode-debug] runLocalQueryEngineTurn create stream')
30 const stream = deps?.runTurn
31 ? deps.runTurn(params)
32 : (await import('../QueryEngine.js')).runReplTurn(params)
33
34 while (true) {
35 logForDebugging('[ncode-debug] runLocalQueryEngineTurn before stream.next')
36 const next = await stream.next()
37 if (next.done) {
38 logForDebugging('[ncode-debug] runLocalQueryEngineTurn stream done')
39 return next.value
40 }
41 logForDebugging('[ncode-debug] runLocalQueryEngineTurn stream yielded event')
42 if (
43 !next.value ||
44 typeof next.value !== 'object' ||
45 !('type' in next.value)
46 ) {
47 logForDebugging(
48 `[ncode-debug] runLocalQueryEngineTurn yielded nonlocal event keys=${next.value && typeof next.value === 'object' ? Object.keys(next.value as Record<string, unknown>).join(',') : typeof next.value}`,
49 )
50 logForDebugging(
51 `[ncode-debug] runLocalQueryEngineTurn yielded nonlocal event value=${inspect(next.value, { depth: 4, breakLength: 120 })}`,
52 )
53 }
54 await onEvent(next.value)
55 }
56}

Callers 1

Calls 3

keysMethod · 0.80
logForDebuggingFunction · 0.50
nextMethod · 0.45

Tested by

no test coverage detected