37 lines
978 B
Go
37 lines
978 B
Go
package opencode
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/protocol"
|
|
)
|
|
|
|
// The canonical V2 Session.Message.Compaction union exposes status in history.
|
|
// Do not expose its summary, recent context or provider state as assistant text.
|
|
func (c *Chat) readCompaction(ctx context.Context, id string) *protocol.ChatCompaction {
|
|
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
|
defer cancel()
|
|
raw, err := c.call(ctx, "get", "/api/session/"+id+"/message?limit=50", nil)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
var page struct {
|
|
Data []struct {
|
|
Type string `json:"type"`
|
|
Status string `json:"status"`
|
|
} `json:"data"`
|
|
}
|
|
if json.Unmarshal(raw, &page) != nil {
|
|
return nil
|
|
}
|
|
for _, message := range page.Data {
|
|
if message.Type == "compaction" && message.Status == "running" {
|
|
// No id: public started/ended events cannot correlate history ids.
|
|
return &protocol.ChatCompaction{Status: "running"}
|
|
}
|
|
}
|
|
return nil
|
|
}
|