({ prompt, onEvent }: SendPromptOptions)
| 163 | } |
| 164 | |
| 165 | async sendPrompt({ prompt, onEvent }: SendPromptOptions) { |
| 166 | await this.ensureAgentFresh() |
| 167 | |
| 168 | const run = await this.agent.send(buildPrompt(prompt), { |
| 169 | ...(this.mode === "local" ? { model: this.modelSelection } : {}), |
| 170 | ...(this.mode === "local" && this.force ? { local: { force: true } } : {}), |
| 171 | }) |
| 172 | |
| 173 | this.currentRun = run |
| 174 | |
| 175 | try { |
| 176 | for await (const event of run.stream()) { |
| 177 | emitSdkMessage(event, onEvent) |
| 178 | } |
| 179 | |
| 180 | const result = await run.wait() |
| 181 | const usage = (result as { usage?: TokenUsage }).usage |
| 182 | onEvent({ |
| 183 | type: "result", |
| 184 | status: result.status, |
| 185 | durationMs: result.durationMs, |
| 186 | usage, |
| 187 | }) |
| 188 | } finally { |
| 189 | if (this.currentRun === run) { |
| 190 | this.currentRun = null |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | private createAgent() { |
| 196 | const options = { |
no test coverage detected