()
| 111 | } |
| 112 | |
| 113 | const drain = () => { |
| 114 | if (draining || state.closed || state.queue.length === 0) { |
| 115 | return |
| 116 | } |
| 117 | |
| 118 | draining = (async () => { |
| 119 | try { |
| 120 | while (!state.closed && state.queue.length > 0) { |
| 121 | const prompt = state.queue.shift() |
| 122 | if (!prompt) { |
| 123 | continue |
| 124 | } |
| 125 | |
| 126 | const queued = state.queued.find((item) => item.prompt === prompt) |
| 127 | if (queued) removeLocalQueued(queued) |
| 128 | |
| 129 | if (prompt.mode !== "shell" && isNewCommand(prompt.text)) { |
| 130 | syncQueue() |
| 131 | if (!input.onNewSession) { |
| 132 | emit( |
| 133 | { |
| 134 | type: "stream.patch", |
| 135 | patch: { |
| 136 | status: "new sessions unavailable", |
| 137 | }, |
| 138 | }, |
| 139 | { |
| 140 | status: "new sessions unavailable", |
| 141 | }, |
| 142 | ) |
| 143 | continue |
| 144 | } |
| 145 | |
| 146 | emit( |
| 147 | { |
| 148 | type: "stream.patch", |
| 149 | patch: { |
| 150 | phase: "running", |
| 151 | status: "starting new session", |
| 152 | queue: state.queue.length, |
| 153 | }, |
| 154 | }, |
| 155 | { |
| 156 | phase: "running", |
| 157 | status: "starting new session", |
| 158 | queue: state.queue.length, |
| 159 | }, |
| 160 | ) |
| 161 | await input.onNewSession() |
| 162 | continue |
| 163 | } |
| 164 | |
| 165 | const sent = |
| 166 | prompt.mode === "shell" |
| 167 | ? prompt |
| 168 | : { |
| 169 | ...prompt, |
| 170 | messageID: prompt.messageID ?? queued?.messageID ?? MessageID.ascending(), |
no test coverage detected