(input)
| 38 | } |
| 39 | |
| 40 | async *submitMessage(input) { |
| 41 | const text = input.trim(); |
| 42 | if (!text) return { handled: false }; |
| 43 | |
| 44 | if (text.startsWith("/")) { |
| 45 | return yield* this.handleCommand(text); |
| 46 | } |
| 47 | |
| 48 | const userMessage = { role: "user", content: text }; |
| 49 | this.messages.push(userMessage); |
| 50 | yield { type: "messages_updated", messages: [...this.messages] }; |
| 51 | |
| 52 | this.abortController = new AbortController(); |
| 53 | const systemPrompt = await buildSystemPrompt({ cwd: this.toolContext.cwd }); |
| 54 | |
| 55 | const loop = query({ |
| 56 | messages: [...this.messages], |
| 57 | model: this.getActiveModel(), |
| 58 | systemPrompt, |
| 59 | toolContext: { |
| 60 | ...this.toolContext, |
| 61 | abortSignal: this.abortController.signal, |
| 62 | }, |
| 63 | }); |
| 64 | |
| 65 | while (true) { |
| 66 | const { value, done } = await loop.next(); |
| 67 | if (done) { |
| 68 | this.messages = [...value.state.messages]; |
| 69 | this.totalUsage.input_tokens += value.usage.input_tokens; |
| 70 | this.totalUsage.output_tokens += value.usage.output_tokens; |
| 71 | yield { type: "usage_updated", totalUsage: { ...this.totalUsage } }; |
| 72 | return { handled: true, reason: value.reason }; |
| 73 | } |
| 74 | |
| 75 | yield value; |
| 76 | |
| 77 | if (value.type === "assistant_message" || value.type === "tool_result_message") { |
| 78 | this.messages.push(value.message); |
| 79 | yield { type: "messages_updated", messages: [...this.messages] }; |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | async *handleCommand(command) { |
| 85 | if (command === "/clear") { |
nothing calls this directly
no test coverage detected