File size: 8,866 Bytes
7d4338a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<!-- Model Switcher - Floating Preset Selector (left-aligned with inline model display) -->
<script type="module">
  import { store } from "/plugins/_model_config/webui/model-config-store.js";
</script>

<div x-data>
<template x-if="$store.modelConfig">
<div x-data="{ showDropdown: false }"
     x-init="
       await $store.modelConfig.refreshSwitcher($store.chats?.selected || '');
       $watch('$store.chats.selected', v => $store.modelConfig.refreshSwitcher(v || ''));
     ">
  <template x-if="$store.modelConfig.switcherAllowed && !$store.modelConfig.switcherLoading">
    <div class="model-switcher-container">
      <div class="model-switcher-anchor">
        <button class="btn-icon-action model-switcher-btn"
                :class="{ 'has-override': !!$store.modelConfig.switcherOverride }"
                @click="showDropdown = !showDropdown"
                @click.outside="showDropdown = false">
          <span class="material-symbols-outlined" style="font-size: 16px;">neurology</span>
          <span class="model-switcher-label" x-text="$store.modelConfig.getSwitcherLabel()"></span>
          <span class="material-symbols-outlined" style="font-size: 0.7rem;"
                x-text="showDropdown ? 'expand_less' : 'expand_more'"></span>
        </button>

        <!-- Inline active model pills (shown when a preset is active) -->
        <template x-if="$store.modelConfig.switcherOverride">
          <div class="model-switcher-active-pills">
            <template x-if="$store.modelConfig.getActiveModels().main">
              <div class="model-pill">
                <span class="model-pill-role">Main</span>
                <span class="model-pill-name" x-text="$store.modelConfig.getActiveModels().main.name"></span>
              </div>
            </template>
            <template x-if="$store.modelConfig.getActiveModels().utility">
              <div class="model-pill">
                <span class="model-pill-role">Util</span>
                <span class="model-pill-name" x-text="$store.modelConfig.getActiveModels().utility.name"></span>
              </div>
            </template>
          </div>
        </template>

        <!-- Dropdown (opens upward) -->
        <div class="model-switcher-dropdown" x-show="showDropdown" x-transition.opacity>
          <!-- Use Default -->
          <template x-if="$store.modelConfig.switcherOverride">
            <div class="model-switcher-item revert" @click="
              $store.modelConfig.clearOverrideSwitch($store.chats?.selected || '');
              showDropdown = false;
            ">
              <span class="material-symbols-outlined" style="font-size: 15px;">undo</span>
              <span>Use Default</span>
            </div>
          </template>
          <div class="model-switcher-divider" x-show="$store.modelConfig.switcherOverride"></div>

          <!-- No presets message -->
          <template x-if="$store.modelConfig.switcherPresets.length === 0">
            <div class="model-switcher-item disabled">No presets configured</div>
          </template>

          <!-- Preset list -->
          <template x-for="preset in $store.modelConfig.switcherPresets" :key="preset.name">
            <div class="model-switcher-item"
                 :class="{ 'active': $store.modelConfig.switcherOverride?.preset_name === preset.name }"
                 @click="
                   $store.modelConfig.selectPresetSwitch($store.chats?.selected || '', preset.name);
                   showDropdown = false;
                 ">
              <div class="model-switcher-preset-name" x-text="preset.name"></div>
              <div class="model-switcher-preset-models">
                <template x-if="preset.chat?.name">
                  <div class="model-switcher-model-row">
                    <span class="model-switcher-model-label">Main</span>
                    <span class="model-switcher-model-value">
                      <span x-text="preset.chat.provider" style="opacity:0.5;"></span>
                      <span style="opacity:0.3; margin:0 3px;">/</span>
                      <span x-text="preset.chat.name"></span>
                    </span>
                  </div>
                </template>
                <template x-if="preset.utility?.name">
                  <div class="model-switcher-model-row">
                    <span class="model-switcher-model-label">Utility</span>
                    <span class="model-switcher-model-value">
                      <span x-text="preset.utility.provider" style="opacity:0.5;"></span>
                      <span style="opacity:0.3; margin:0 3px;">/</span>
                      <span x-text="preset.utility.name"></span>
                    </span>
                  </div>
                </template>
              </div>
            </div>
          </template>

          <!-- Edit Presets shortcut -->
          <div class="model-switcher-divider" style="opacity:0.2;"></div>
          <div class="model-switcher-item model-switcher-edit" @click="
            openModal('/plugins/_model_config/webui/main.html');
            showDropdown = false;
          ">
            <span class="material-symbols-outlined" style="font-size: 14px;">tune</span>
            <span>Edit Presets</span>
          </div>
        </div>
      </div>
    </div>
  </template>
</div>
</template>
</div>

<style>
  .model-switcher-container {
    position: relative;
    z-index: 10;
  }
  .model-switcher-anchor {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .model-switcher-btn {
    width: auto;
    height: auto;
    gap: 4px;
    padding: var(--spacing-xs) var(--spacing-sm);
    border: none;
    font-size: 0.75rem;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .model-switcher-btn:hover {
    border: none;
  }
  .model-switcher-btn.has-override {
    /* color: var(--color-text); */
  }
  .model-switcher-label {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Inline active model pills */
  .model-switcher-active-pills {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 1;
    min-width: 0;
  }
  .model-pill {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 12px;
    background: color-mix(in srgb, var(--color-highlight) 8%, transparent);
    border: 1px solid color-mix(in srgb, var(--color-highlight) 15%, transparent);
    font-size: 0.68rem;
    white-space: nowrap;
    min-width: 0;
    overflow: hidden;
  }
  .model-pill-role {
    font-weight: 600;
    opacity: 0.55;
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex-shrink: 0;
  }
  .model-pill-name {
    opacity: 0.85;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
  }

  /* Dropdown - opens upward, aligned to left */
  .model-switcher-dropdown {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    min-width: 280px;
    max-height: 550px;
    overflow-y: auto;
    background-color: var(--color-panel);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 100;
  }
  .model-switcher-item {
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.1s ease;
  }
  .model-switcher-item:hover {
    background: var(--color-background-hover, rgba(255,255,255,0.06));
  }
  .model-switcher-item.active {
    background: color-mix(in srgb, var(--color-highlight) 12%, transparent);
  }
  .model-switcher-item.revert {
    display: flex;
    align-items: center;
    gap: 6px;
    opacity: 0.8;
  }
  .model-switcher-item.disabled {
    opacity: 0.4;
    cursor: default;
    font-style: italic;
  }
  .model-switcher-item.disabled:hover {
    background: transparent;
  }
  .model-switcher-divider {
    border-top: 1px solid var(--color-border);
    margin: 4px 0;
    opacity: 0.3;
  }
  .model-switcher-preset-name {
    font-weight: 500;
  }
  .model-switcher-preset-models {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 4px;
  }
  .model-switcher-model-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.7rem;
    opacity: 0.7;
  }
  .model-switcher-model-label {
    width: 40px;
    flex-shrink: 0;
    font-weight: 500;
    opacity: 0.7;
  }
  .model-switcher-model-value {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .model-switcher-edit {
    display: flex;
    align-items: center;
    gap: 6px;
    opacity: 0.6;
    font-size: 0.75rem;
  }

  /* Responsive: hide pills on narrow screens */
  @media (max-width: 600px) {
    .model-switcher-active-pills {
      display: none;
    }
  }
</style>