(input: WriteStdinInput)
| 237 | } |
| 238 | |
| 239 | async write(input: WriteStdinInput): Promise<ProcessSnapshot> { |
| 240 | const session = this.getOwnedSession(input.workspaceId, input.sessionId); |
| 241 | const chars = input.chars ?? ""; |
| 242 | const interactionRequested = |
| 243 | chars.length > 0 || input.columns !== undefined || input.rows !== undefined; |
| 244 | |
| 245 | if (input.columns !== undefined || input.rows !== undefined) { |
| 246 | session.columns = terminalSize(input.columns, session.columns); |
| 247 | session.rows = terminalSize(input.rows, session.rows); |
| 248 | if (!session.process?.resize) { |
| 249 | throw new Error(`Process session ${session.id} is not a PTY and cannot be resized.`); |
| 250 | } |
| 251 | session.process.resize(session.columns, session.rows); |
| 252 | } |
| 253 | |
| 254 | const interruptRequested = chars.includes("\u0003") && session.running; |
| 255 | if (interruptRequested) { |
| 256 | session.process?.kill("SIGINT"); |
| 257 | } |
| 258 | const writableChars = chars.replaceAll("\u0003", ""); |
| 259 | if (writableChars && session.running) session.process?.write(writableChars); |
| 260 | |
| 261 | if ((interactionRequested || !session.buffer.hasOutput()) && session.running) { |
| 262 | const fallback = interactionRequested ? DEFAULT_INTERACTIVE_YIELD_MS : DEFAULT_POLL_YIELD_MS; |
| 263 | const maximum = interactionRequested ? MAX_COMMAND_YIELD_MS : MAX_POLL_YIELD_MS; |
| 264 | const yieldTimeMs = boundedInteger(input.yieldTimeMs, fallback, maximum); |
| 265 | await this.waitForExit(session, yieldTimeMs); |
| 266 | } |
| 267 | |
| 268 | const snapshot = this.consume(session, input.maxOutputTokens); |
| 269 | if (!session.running) this.removeSession(session.id); |
| 270 | return snapshot; |
| 271 | } |
| 272 | |
| 273 | terminate(workspaceId: string, sessionId: number): void { |
| 274 | const session = this.getOwnedSession(workspaceId, sessionId); |
nothing calls this directly
no test coverage detected