( options: RunLocalQueryEngineTurnOptions, deps?: LocalQueryEngineControllerDeps, )
| 22 | * provided callback. Returns after the turn generator completes. |
| 23 | */ |
| 24 | export 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 | } |
no test coverage detected