| 1 | package config |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "os" |
| 6 | fileencoding "reasonix/internal/fileutil/encoding" |
| 7 | ) |
| 8 | |
| 9 | // SaveWebSearchModelTo preserves comments and unknown fields in an existing user |
| 10 | // file. The caller holds the same config edit lock used by all Desktop setters. |
| 11 | func (c *Config) SaveWebSearchModelTo(path string) error { |
| 12 | if c == nil { |
| 13 | return fmt.Errorf("save search model: nil config") |
| 14 | } |
| 15 | if c.editLoadErr != nil { |
| 16 | return c.editLoadErr |
| 17 | } |
| 18 | if err := currentUserConfigEditLockError(); err != nil { |
| 19 | return err |
| 20 | } |
| 21 | resolved, err := resolveConfigAccessPath(path, true) |
| 22 | if err != nil { |
| 23 | return err |
| 24 | } |
| 25 | raw, err := fileencoding.ReadFileUTF8(resolved) |
| 26 | if os.IsNotExist(err) { |
| 27 | return c.SaveTo(path) |
| 28 | } |
| 29 | if err != nil { |
| 30 | return err |
| 31 | } |
| 32 | body := upsertTOMLSectionKey(string(raw), "agent", "web_search_model", fmt.Sprintf("web_search_model = %q", c.Agent.WebSearchModel)) |
| 33 | return c.writeModelConfigResolved(resolved, body, configFilePerm(path)) |
| 34 | } |
| 35 |