session: rename PersistedSession → PersistedAgent
This commit is contained in:
parent
84a64e9251
commit
8a4f77c118
|
|
@ -343,7 +343,7 @@ func (a *Session) handleCommand(ctx context.Context, input string) bool {
|
|||
if readErr != nil {
|
||||
continue
|
||||
}
|
||||
var ps PersistedSession
|
||||
var ps PersistedAgent
|
||||
if json.Unmarshal(data, &ps) != nil {
|
||||
continue
|
||||
}
|
||||
|
|
@ -406,7 +406,7 @@ func (a *Session) handleCommand(ctx context.Context, input string) bool {
|
|||
a.emit(infoEvent(fmt.Sprintf("error: %v", err)))
|
||||
return
|
||||
}
|
||||
var ps PersistedSession
|
||||
var ps PersistedAgent
|
||||
if err := json.Unmarshal(data, &ps); err != nil {
|
||||
a.emit(infoEvent(fmt.Sprintf("error: %v", err)))
|
||||
return
|
||||
|
|
|
|||
|
|
@ -2168,7 +2168,7 @@ func TestRestoreSession_RoundTrip(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("ReadFile: %v", err)
|
||||
}
|
||||
var ps PersistedSession
|
||||
var ps PersistedAgent
|
||||
if err := json.Unmarshal(data, &ps); err != nil {
|
||||
t.Fatalf("Unmarshal: %v", err)
|
||||
}
|
||||
|
|
@ -2222,7 +2222,7 @@ func TestReactionPersistsAndRestores(t *testing.T) {
|
|||
if err := s.saveTo(path, "id", "agent", "/tmp"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ps, err := LoadPersistedSession(path)
|
||||
ps, err := LoadPersistedAgent(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -2238,7 +2238,7 @@ func TestRestoreSession_GoalFromFirstUserMessage(t *testing.T) {
|
|||
{Role: "user", Content: "the real goal"},
|
||||
{Role: "user", Content: "second user msg"},
|
||||
}
|
||||
s := RestoreHistory(&PersistedSession{Messages: msgs})
|
||||
s := RestoreHistory(&PersistedAgent{Messages: msgs})
|
||||
if s.goal != "the real goal" {
|
||||
t.Errorf("goal = %q; want %q", s.goal, "the real goal")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@ type Reaction struct {
|
|||
CreatedAt time.Time `json:"createdAt"`
|
||||
}
|
||||
|
||||
// PersistedSession is the on-disk format for a saved session.
|
||||
type PersistedSession struct {
|
||||
// PersistedAgent is the on-disk format for a saved session.
|
||||
type PersistedAgent struct {
|
||||
ID string `json:"id"`
|
||||
Agent string `json:"agent,omitempty"`
|
||||
Backend string `json:"backend,omitempty"`
|
||||
|
|
@ -130,7 +130,7 @@ func sanitizeMessages(msgs []backend.Message) []backend.Message {
|
|||
}
|
||||
|
||||
func (s *History) saveToFull(path, id, agentName, backendName, modelName, cwd, remote string) error {
|
||||
ps := PersistedSession{
|
||||
ps := PersistedAgent{
|
||||
ID: id,
|
||||
Agent: agentName,
|
||||
Backend: backendName,
|
||||
|
|
@ -163,13 +163,13 @@ func (s *History) saveToFull(path, id, agentName, backendName, modelName, cwd, r
|
|||
return os.Rename(tmpPath, path)
|
||||
}
|
||||
|
||||
// LoadPersistedSession reads a PersistedSession from a JSON file.
|
||||
func LoadPersistedSession(path string) (*PersistedSession, error) {
|
||||
// LoadPersistedAgent reads a PersistedAgent from a JSON file.
|
||||
func LoadPersistedAgent(path string) (*PersistedAgent, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var ps PersistedSession
|
||||
var ps PersistedAgent
|
||||
if err := json.Unmarshal(data, &ps); err != nil {
|
||||
return nil, fmt.Errorf("parse session %s: %w", path, err)
|
||||
}
|
||||
|
|
@ -177,7 +177,7 @@ func LoadPersistedSession(path string) (*PersistedSession, error) {
|
|||
}
|
||||
|
||||
// RestoreHistory reconstructs a Session from a persisted message list.
|
||||
func RestoreHistory(ps *PersistedSession) *History {
|
||||
func RestoreHistory(ps *PersistedAgent) *History {
|
||||
s := &History{
|
||||
messages: ps.Messages,
|
||||
TaskState: ps.TaskState,
|
||||
|
|
|
|||
Reference in New Issue