|
809 | 809 | the client-side selected model to `full-model`, re-computing the available |
810 | 810 | variants and the suggested selected variant. Emits via |
811 | 811 | `notify-fields-changed-only!`, so it is a no-op when nothing changed. |
812 | | - Returns nil when `full-model` is missing or no longer in `(:models @db*)`, |
813 | | - so a stale persisted model does not bubble to the UI. Used by chat resume |
814 | | - flows (`chat/open`, `/resume`) to restore the model each chat was using. |
| 812 | + Returns the effective `{:model :variant :variants}` selection, or nil when |
| 813 | + `full-model` is missing or no longer in `(:models @db*)`, so a stale |
| 814 | + persisted model does not bubble to the UI. Used by chat resume flows |
| 815 | + (`chat/open`, `/resume`) to restore the model each chat was using. |
815 | 816 |
|
816 | 817 | When `chat-variant` is provided (the chat's persisted `:variant`) and is |
817 | 818 | still supported by `full-model`, the broadcast keeps it; otherwise it |
818 | 819 | falls back to the default agent's configured variant when valid, else |
819 | 820 | nil. This lets resume preserve the variant the user last saw on the |
820 | | - chat instead of resetting to the default agent's variant." |
| 821 | + chat instead of resetting to the default agent's variant. |
| 822 | +
|
| 823 | + When `chat-id` is provided, the broadcast is scoped to that chat and does |
| 824 | + not update the session-level config mirror." |
821 | 825 | ([full-model db* messenger config] |
822 | | - (notify-selected-model-changed! full-model db* messenger config nil)) |
| 826 | + (notify-selected-model-changed! full-model db* messenger config nil nil)) |
823 | 827 | ([full-model db* messenger config chat-variant] |
| 828 | + (notify-selected-model-changed! full-model db* messenger config chat-variant nil)) |
| 829 | + ([full-model db* messenger config chat-variant chat-id] |
824 | 830 | (when (and full-model (contains? (:models @db*) full-model)) |
825 | 831 | (let [default-agent-name (validate-agent-name |
826 | 832 | (or (:defaultAgent (:chat config)) |
|
839 | 845 | select-variant (cond |
840 | 846 | (valid? chat-variant) chat-variant |
841 | 847 | (valid? agent-variant) agent-variant |
842 | | - :else nil)] |
843 | | - (notify-fields-changed-only! |
844 | | - {:chat {:select-model full-model |
845 | | - :variants (or variants []) |
846 | | - :select-variant select-variant}} |
847 | | - messenger |
848 | | - db*))))) |
| 848 | + :else nil) |
| 849 | + selection {:model full-model |
| 850 | + :variants (or variants []) |
| 851 | + :variant select-variant} |
| 852 | + payload {:chat {:select-model (:model selection) |
| 853 | + :variants (:variants selection) |
| 854 | + :select-variant (:variant selection)}}] |
| 855 | + (if chat-id |
| 856 | + (notify-fields-changed-only! payload messenger db* chat-id) |
| 857 | + (notify-fields-changed-only! payload messenger db*)) |
| 858 | + selection)))) |
849 | 859 |
|
850 | 860 | (defn notify-selected-trust-changed! |
851 | 861 | "Server-initiated equivalent of a client-side trust toggle: aligns the |
852 | 862 | client-side trust indicator with the chat's persisted `:trust` value. |
853 | 863 | Emits via `notify-fields-changed-only!`, so it is a no-op when nothing |
854 | 864 | changed. Used by chat resume flows (`chat/open`, `/resume`) so the icon |
855 | 865 | the client shows matches the auto-approval behavior the server is about |
856 | | - to apply (#426)." |
857 | | - [trust db* messenger] |
858 | | - (notify-fields-changed-only! |
859 | | - {:chat {:select-trust (boolean trust)}} |
860 | | - messenger |
861 | | - db*)) |
| 866 | + to apply (#426). |
| 867 | +
|
| 868 | + When `chat-id` is provided, the broadcast is scoped to that chat and does |
| 869 | + not update the session-level config mirror. Returns the normalized boolean |
| 870 | + trust selection." |
| 871 | + ([trust db* messenger] |
| 872 | + (notify-selected-trust-changed! trust db* messenger nil)) |
| 873 | + ([trust db* messenger chat-id] |
| 874 | + (let [selection (boolean trust) |
| 875 | + payload {:chat {:select-trust selection}}] |
| 876 | + (if chat-id |
| 877 | + (notify-fields-changed-only! payload messenger db* chat-id) |
| 878 | + (notify-fields-changed-only! payload messenger db*)) |
| 879 | + selection))) |
862 | 880 |
|
863 | 881 | (def ^:private config-schema-url "https://eca.dev/config.json") |
864 | 882 |
|
|
0 commit comments