diff options
Diffstat (limited to 'libpanto-go/panto.go')
| -rw-r--r-- | libpanto-go/panto.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/libpanto-go/panto.go b/libpanto-go/panto.go index 5644b61..da3bcb1 100644 --- a/libpanto-go/panto.go +++ b/libpanto-go/panto.go @@ -693,6 +693,25 @@ func (s *Stream) Close() { } } +// Reopen resets a failed stream back to its turn-open boundary so the caller +// can resume Next() after changing the agent config (e.g. catch a terminal +// bad-request, swap the provider config via Agent.SetConfig, and retry the +// SAME turn without re-appending the user message). It is valid only on a +// stream whose Next() has surfaced a terminal error; otherwise it returns an +// error. On success the stream's local error/done state is cleared so the +// iteration can continue. +func (s *Stream) Reopen() error { + if s == nil || s.ptr == nil { + return fmt.Errorf("reopen on a closed stream") + } + if C.panto_stream_reopen(s.ptr) != C.PANTO_OK { + return lastError() + } + s.err = nil + s.done = false + return nil +} + func (s *Stream) Next() (Event, bool, error) { if s.err != nil { return Event{}, false, s.err |
