( name: TName, payload: RuntimeHostRequestMap[TName], )
| 470 | } |
| 471 | |
| 472 | export async function invokeRuntimeHost<TName extends RuntimeHostRequestName>( |
| 473 | name: TName, |
| 474 | payload: RuntimeHostRequestMap[TName], |
| 475 | ): Promise<RuntimeHostResponseMap[TName]> { |
| 476 | const host = getHostForRequest(name, payload) |
| 477 | const child = await ensureRuntimeHost(host) |
| 478 | const id = randomUUID() |
| 479 | |
| 480 | return await new Promise<RuntimeHostResponseMap[TName]>((resolve, reject) => { |
| 481 | if (name === 'sendComposerPrompt') { |
| 482 | host.busy = true |
| 483 | clearHostIdleTimer(host) |
| 484 | } |
| 485 | |
| 486 | host.pendingRequests.set(id, { |
| 487 | name, |
| 488 | resolve: (value) => resolve(value as RuntimeHostResponseMap[TName]), |
| 489 | reject, |
| 490 | }) |
| 491 | |
| 492 | child.send({ type: 'request', id, name, payload }, (error) => { |
| 493 | if (!error) { |
| 494 | return |
| 495 | } |
| 496 | host.pendingRequests.delete(id) |
| 497 | if (name === 'sendComposerPrompt') { |
| 498 | host.busy = false |
| 499 | } |
| 500 | scheduleThreadHostIdleStop(host) |
| 501 | reject(error) |
| 502 | }) |
| 503 | }) |
| 504 | } |
| 505 | |
| 506 | export async function invalidateRuntimeHostSettings( |
| 507 | request: { |
no test coverage detected