(
continuation: RuntimeContinuation,
run: AgentRun,
execution: PendingExecutionClaim,
messageOwner?: RuntimeMessageRunIdentity,
onRunStarted?: () => void | Promise<void>,
revalidateSafety?: () => Promise<void>,
)
| 1690 | } |
| 1691 | |
| 1692 | private async *runAgentContinuation( |
| 1693 | continuation: RuntimeContinuation, |
| 1694 | run: AgentRun, |
| 1695 | execution: PendingExecutionClaim, |
| 1696 | messageOwner?: RuntimeMessageRunIdentity, |
| 1697 | onRunStarted?: () => void | Promise<void>, |
| 1698 | revalidateSafety?: () => Promise<void>, |
| 1699 | ): AsyncIterable<SessionEvent> { |
| 1700 | const sessionEvents = new DeliveryAckQueue<SessionEvent>(); |
| 1701 | const { abortController, release: releaseExecutionAbort } = |
| 1702 | this.inheritExecutionAbort(execution); |
| 1703 | let flowDone = false; |
| 1704 | const owners = this.createRunOwnerScope(run, execution); |
| 1705 | let begin: Awaited<ReturnType<AgentRun['beginContinuation']>>; |
| 1706 | try { |
| 1707 | if (messageOwner) owners.bindMessage(this.deps.messageAuthority, messageOwner); |
| 1708 | begin = await this.runBackendActivation(async () => { |
| 1709 | if (!revalidateSafety) { |
| 1710 | throw new Error('Durable continuation omitted final safety revalidation'); |
| 1711 | } |
| 1712 | await revalidateSafety(); |
| 1713 | const started = await run.beginContinuation(continuation); |
| 1714 | await owners.bindInteraction(this.deps.interactionAuthority, { |
| 1715 | sessionId: continuation.sessionId, |
| 1716 | turnId: run.turnId, |
| 1717 | runId: run.runId, |
| 1718 | }); |
| 1719 | return started; |
| 1720 | }); |
| 1721 | await onRunStarted?.(); |
| 1722 | } catch (error) { |
| 1723 | releaseExecutionAbort(); |
| 1724 | if (error instanceof ContinuationStartCommitError) { |
| 1725 | await owners.abandonUnstartedContinuation(error); |
| 1726 | return; |
| 1727 | } |
| 1728 | await this.finalizeFailedRunStart(owners, run, execution, error); |
| 1729 | return; |
| 1730 | } |
| 1731 | |
| 1732 | const interactionRun = owners.interactionRun; |
| 1733 | |
| 1734 | const aiSdkFlow = new AiSdkFlow({ |
| 1735 | backend: begin.backend, |
| 1736 | stopBackend: this.stopBackendFor(begin.backend), |
| 1737 | beforeDispatch: () => this.assertRunCanDispatch(run, begin.backend), |
| 1738 | ...(interactionRun ? { hostedInteraction: interactionRun } : {}), |
| 1739 | drainAfterTerminal: true, |
| 1740 | onSessionEvent: async (sessionEvent, runtimeEvent) => { |
| 1741 | this.assertInteractionPublication(interactionRun, sessionEvent); |
| 1742 | await run.acceptMappedEvent(sessionEvent, runtimeEvent, { |
| 1743 | requireTerminalWrite: true, |
| 1744 | allowInteractionResume: await interactionResumeAllowed(interactionRun, sessionEvent), |
| 1745 | }); |
| 1746 | this.observeInteractionEvent(continuation.sessionId, begin.backend, sessionEvent); |
| 1747 | await sessionEvents.push(sessionEvent); |
| 1748 | }, |
| 1749 | onError: async (error) => { |
no test coverage detected