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