| 219 | } |
| 220 | |
| 221 | class RuntimeHostRunRuntime implements MakaRunRuntime { |
| 222 | readonly #connection: RuntimeHostConnection; |
| 223 | readonly #driver: RuntimeHostMakaSessionDriver; |
| 224 | readonly #observer: ((outcome: MakaRunOutcome) => void | Promise<void>) | undefined; |
| 225 | readonly #graphEnabled: boolean; |
| 226 | readonly #sessionCwdOverride: MakaRunContextInput['sessionCwdOverride']; |
| 227 | readonly #maxSteps: number | undefined; |
| 228 | readonly #unsubscribeTranscriptReplacements: () => void; |
| 229 | #sessionId: string | undefined; |
| 230 | #activeTurn: { sessionId: string; turnId: string; runId: string } | undefined; |
| 231 | #stopRequested = false; |
| 232 | #closed = false; |
| 233 | readonly #interactions: NonInteractiveInteractionController; |
| 234 | #graphAdmissionTurnIds = new Set<string>(); |
| 235 | #latestTranscriptReplacement: StoredMessage[] | undefined; |
| 236 | readonly #graphTerminalWaiters = new Map< |
| 237 | string, |
| 238 | Set<{ |
| 239 | resolve(messages: StoredMessage[]): void; |
| 240 | reject(error: Error): void; |
| 241 | timer: ReturnType<typeof setTimeout>; |
| 242 | }> |
| 243 | >(); |
| 244 | |
| 245 | constructor( |
| 246 | connection: RuntimeHostConnection, |
| 247 | driver: RuntimeHostMakaSessionDriver, |
| 248 | observer: ((outcome: MakaRunOutcome) => void | Promise<void>) | undefined, |
| 249 | graphEnabled: boolean, |
| 250 | sessionCwdOverride: MakaRunContextInput['sessionCwdOverride'], |
| 251 | maxSteps: number | undefined, |
| 252 | ) { |
| 253 | this.#connection = connection; |
| 254 | this.#driver = driver; |
| 255 | this.#observer = observer; |
| 256 | this.#graphEnabled = graphEnabled; |
| 257 | this.#sessionCwdOverride = sessionCwdOverride; |
| 258 | this.#maxSteps = maxSteps; |
| 259 | this.#interactions = new NonInteractiveInteractionController(driver, (pending) => |
| 260 | this.#stopForInteraction(pending), |
| 261 | ); |
| 262 | this.#unsubscribeTranscriptReplacements = driver.subscribeTranscriptReplacements( |
| 263 | (_sessionId, _turnId, messages) => this.#acceptGraphTranscript(messages), |
| 264 | ); |
| 265 | } |
| 266 | |
| 267 | async createSession(input: CreateSessionInput): Promise<SessionSummary> { |
| 268 | const created = await this.#driver.createSession(input); |
| 269 | this.#sessionId = created.id; |
| 270 | return created; |
| 271 | } |
| 272 | |
| 273 | async readExecutionBoundary(sessionId: string): Promise<ExecutionBoundaryReadModel> { |
| 274 | await this.#attach(sessionId); |
| 275 | return this.#connection.request('session.execution_boundary.query', { sessionId }); |
| 276 | } |
| 277 | |
| 278 | async *sendMessage(sessionId: string, input: UserMessageInput): AsyncIterable<SessionEvent> { |
nothing calls this directly
no outgoing calls
no test coverage detected