Share repair histories while debug artifacts wait for indices
This commit is contained in:
@@ -28,13 +28,46 @@ func (s *sectionInteractions) WriteIndexedInteraction(build structuredoutput.Ind
|
||||
}
|
||||
|
||||
func (s *sectionInteractions) write(offset int) {
|
||||
for _, build := range s.builders {
|
||||
for i, build := range s.builders {
|
||||
paths, _ := s.InteractionSink.WriteInteraction(build(offset, s.responsePath))
|
||||
s.written = append(s.written, paths)
|
||||
s.builders[i] = nil
|
||||
}
|
||||
s.builders = nil
|
||||
}
|
||||
|
||||
// repairHistory shares the append-only prefix of prepared repair requests.
|
||||
// Earlier snapshots keep their own lengths while additional turns add messages.
|
||||
type repairHistory struct {
|
||||
messages []structuredoutput.Message
|
||||
}
|
||||
|
||||
func (h *repairHistory) retain(prepared *structuredoutput.PreparedSnapshot) *structuredoutput.PreparedSnapshot {
|
||||
if prepared == nil {
|
||||
return nil
|
||||
}
|
||||
messages := prepared.Messages
|
||||
n := len(h.messages)
|
||||
if n == 0 || n > len(messages) || !slices.EqualFunc(h.messages, messages[:n], sameMessage) {
|
||||
h.messages = messages
|
||||
} else {
|
||||
h.messages = append(h.messages, messages[n:]...)
|
||||
}
|
||||
snapshot := *prepared
|
||||
snapshot.Messages = slices.Clip(h.messages)
|
||||
return &snapshot
|
||||
}
|
||||
|
||||
func sameMessage(a, b structuredoutput.Message) bool {
|
||||
if a.Role != b.Role || a.Content != b.Content {
|
||||
return false
|
||||
}
|
||||
if a.CacheControl == nil || b.CacheControl == nil {
|
||||
return a.CacheControl == b.CacheControl
|
||||
}
|
||||
return *a.CacheControl == *b.CacheControl
|
||||
}
|
||||
|
||||
func (s *sectionInteractions) artifacts(paths structuredoutput.InteractionArtifacts) structuredoutput.InteractionArtifacts {
|
||||
value, pending := strings.CutPrefix(paths.ResponsePayloadPath, pendingInteractionPrefix)
|
||||
if !pending {
|
||||
|
||||
Reference in New Issue
Block a user