| 153 | } |
| 154 | |
| 155 | func (rt *AgentTaskRuntime) ExportSnapshot() []map[string]any { |
| 156 | rt.mu.Lock() |
| 157 | defer rt.mu.Unlock() |
| 158 | records := make([]*AgentTaskRecord, 0, len(rt.records)) |
| 159 | for _, record := range rt.records { |
| 160 | records = append(records, record) |
| 161 | } |
| 162 | sort.SliceStable(records, func(i, j int) bool { |
| 163 | if records[i].CreatedAt == records[j].CreatedAt { |
| 164 | return records[i].TaskID < records[j].TaskID |
| 165 | } |
| 166 | return records[i].CreatedAt < records[j].CreatedAt |
| 167 | }) |
| 168 | out := make([]map[string]any, 0, len(records)) |
| 169 | for _, record := range records { |
| 170 | out = append(out, record.ToMap()) |
| 171 | } |
| 172 | return out |
| 173 | } |
| 174 | |
| 175 | func (rt *AgentTaskRuntime) ImportSnapshot(snapshot []map[string]any) { |
| 176 | rt.mu.Lock() |