* Return a stream of messages from the agent. * @param userMessage - The message to send to the agent. * @param streamOptions - Optional options for the stream (e.g., abort signal). * @returns The stream of messages from the agent.
(
userMessage: UserMessage,
streamOptions?: SessionStreamOptions,
)
| 55 | * @returns The stream of messages from the agent. |
| 56 | */ |
| 57 | async stream( |
| 58 | userMessage: UserMessage, |
| 59 | streamOptions?: SessionStreamOptions, |
| 60 | ): Promise< |
| 61 | AsyncIterableIterator<SystemMessage | AssistantMessage | ToolMessage> |
| 62 | > { |
| 63 | this.emit("message", userMessage); |
| 64 | const runner = createAgentRunner(this.agentType); |
| 65 | const rawStream = runner.stream(userMessage, { |
| 66 | ...this.options, |
| 67 | signal: streamOptions?.signal, |
| 68 | }); |
| 69 | this.options.isNewSession = false; |
| 70 | // eslint-disable-next-line @typescript-eslint/no-this-alias |
| 71 | const self = this; |
| 72 | async function* wrappedStream() { |
| 73 | for await (const message of await rawStream) { |
| 74 | self.emit("message", message); |
| 75 | yield message; |
| 76 | } |
| 77 | } |
| 78 | return wrappedStream(); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Send a message to the agent and return the last message. |
no test coverage detected