Send appends prompt to the conversation and streams the assistant reply. The returned channel closes when the runtime stream stops. A clean stream emits a final Done event first; a stream that reports an ErrorEvent emits one Err event, suppresses later projected events, then keeps draining until the
(ctx context.Context, prompt string)
| 222 | // If ctx is cancelled, Send drains the runtime stream until it stops, but no |
| 223 | // further events are delivered to the caller. |
| 224 | func (s *Session) Send(ctx context.Context, prompt string) (<-chan Event, error) { |
| 225 | s.mu.Lock() |
| 226 | if s.rt == nil || s.session == nil { |
| 227 | s.mu.Unlock() |
| 228 | return nil, ErrNotInitialized |
| 229 | } |
| 230 | if s.closed { |
| 231 | s.mu.Unlock() |
| 232 | return nil, ErrClosed |
| 233 | } |
| 234 | if s.activeCancel != nil { |
| 235 | s.mu.Unlock() |
| 236 | return nil, ErrRunActive |
| 237 | } |
| 238 | runCtx, cancel := context.WithCancel(ctx) |
| 239 | s.activeCancel = cancel |
| 240 | s.activeRun++ |
| 241 | runID := s.activeRun |
| 242 | s.session.AddMessage(session.UserMessage(prompt)) |
| 243 | events := s.rt.RunStream(runCtx, s.session) |
| 244 | s.mu.Unlock() |
| 245 | |
| 246 | out := make(chan Event, eventBufferSize(s.cfg.EventBuffer)) |
| 247 | go s.forwardEvents(runCtx, events, out, cancel, runID) |
| 248 | return out, nil |
| 249 | } |
| 250 | |
| 251 | // Confirm answers the pending tool confirmation, if any. |
| 252 | func (s *Session) Confirm(ctx context.Context, req dagentruntime.ResumeRequest) error { |
nothing calls this directly
no test coverage detected