check nil

This commit is contained in:
lxowalle 2026-03-09 15:32:13 +08:00
parent 2c6b335512
commit a52fdb633f
2 changed files with 6 additions and 0 deletions

View file

@ -1754,6 +1754,9 @@ func (al *AgentLoop) buildCommandsRuntime(agent *AgentInstance, opts *processOpt
}
rt.ClearHistory = func() error {
if opts == nil {
return fmt.Errorf("process options not available")
}
if agent.Sessions == nil {
return fmt.Errorf("sessions not initialized for agent")
}

View file

@ -8,6 +8,9 @@ func clearCommand() Definition {
Description: "Clear the chat history",
Usage: "/clear",
Handler: func(_ context.Context, req Request, rt *Runtime) error {
if rt == nil || rt.ClearHistory == nil {
return req.Reply(unavailableMsg)
}
if err := rt.ClearHistory(); err != nil {
return req.Reply("Failed to clear chat history: " + err.Error())
}