agent-loft 0.2.131 → 0.2.132
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/web/views/composer-models.js +59 -31
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ import { closeMenu, placePopover, showPopover } from "../lib/overlay.js";
|
|
|
4
4
|
import { S, ui } from "../state.js";
|
|
5
5
|
import { doAction } from "./conv-actions.js";
|
|
6
6
|
import { findExpert } from "./experts.js";
|
|
7
|
-
import { agentCatalog, catalogDefaults, draftPick, effortLabel, composerModelLabel, modelName, renderContext, saveDraftPick, visibleModels } from "./topbar.js";
|
|
7
|
+
import { agentCatalog, catalogDefaults, catalogLoaded, draftPick, effortLabel, composerModelLabel, modelName, renderContext, saveDraftPick, visibleModels } from "./topbar.js";
|
|
8
8
|
|
|
9
9
|
export async function openModelPicker(view = "effort", catalog) {
|
|
10
10
|
const anchor = ui.modelSlot;
|
|
@@ -36,34 +36,18 @@ export async function openModelPicker(view = "effort", catalog) {
|
|
|
36
36
|
window.visualViewport?.removeEventListener("resize", position);
|
|
37
37
|
if (pop.contains(document.activeElement)) trigger()?.focus({ preventScroll: true });
|
|
38
38
|
};
|
|
39
|
-
fill(pop, h("div", { class: "pop-loading", role: "status", "aria-label": "正在读取模型" }, h("span", { class: "spinner" })));
|
|
40
|
-
position();
|
|
41
|
-
|
|
42
39
|
let models, current, currentEffort, fastModel;
|
|
43
|
-
let effortSupported
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (ui.menu !== pop) return;
|
|
54
|
-
const expert = findExpert(expertId);
|
|
55
|
-
current = draftPick().model || expert?.model || catalogDefaults.get(agent)?.model;
|
|
56
|
-
currentEffort = draftPick().effort || expert?.effort;
|
|
57
|
-
fastModel = S.draftFastModel;
|
|
58
|
-
}
|
|
59
|
-
} catch (err) {
|
|
60
|
-
if (ui.menu === pop) fill(pop, h("div", { class: "pop-error", role: "alert" }, err.message));
|
|
61
|
-
return;
|
|
40
|
+
let effortSupported, configuredEffort;
|
|
41
|
+
let provisional = false;
|
|
42
|
+
function render(data) {
|
|
43
|
+
const focus = !pop.dataset.view || pop.contains(document.activeElement);
|
|
44
|
+
({ models, current, currentEffort, fastModel, effortSupported = true } = data);
|
|
45
|
+
current ||= (models.find((m) => m.isDefault) ?? models.find((m) => m.id === "default"))?.id;
|
|
46
|
+
currentEffort ||= catalogDefaults.get(agent)?.effort;
|
|
47
|
+
configuredEffort = [findExpert(conv ? (conv.expert?.id ?? agent) : expertId)?.effort, catalogDefaults.get(agent)?.effort];
|
|
48
|
+
if (view === "model" || !supportsControls()) showModels(focus);
|
|
49
|
+
else showEffort(focus);
|
|
62
50
|
}
|
|
63
|
-
if (ui.menu !== pop || !pop.matchesContext()) return;
|
|
64
|
-
current ||= (models.find((m) => m.isDefault) ?? models.find((m) => m.id === "default"))?.id;
|
|
65
|
-
currentEffort ||= catalogDefaults.get(agent)?.effort;
|
|
66
|
-
const shown = visibleModels(agent, models);
|
|
67
51
|
const selectedModel = () => {
|
|
68
52
|
const exact = models.find((m) => m.id === current);
|
|
69
53
|
if (exact) return exact;
|
|
@@ -71,7 +55,6 @@ export async function openModelPicker(view = "effort", catalog) {
|
|
|
71
55
|
return models.find((m) => m.id !== "default" && (m.label || m.id) === name);
|
|
72
56
|
};
|
|
73
57
|
|
|
74
|
-
const configuredEffort = [findExpert(conv ? (conv.expert?.id ?? agent) : expertId)?.effort, catalogDefaults.get(agent)?.effort];
|
|
75
58
|
let busy = false;
|
|
76
59
|
async function save(kind, value) {
|
|
77
60
|
if (!pop.matchesContext()) return false;
|
|
@@ -109,13 +92,14 @@ export async function openModelPicker(view = "effort", catalog) {
|
|
|
109
92
|
setView("models");
|
|
110
93
|
const selected = selectedModel();
|
|
111
94
|
const list = h("div", { class: "picker-options", "aria-label": "选择模型", role: "group" });
|
|
95
|
+
const shown = visibleModels(agent, models);
|
|
112
96
|
for (const m of shown) {
|
|
113
97
|
list.append(h("button", {
|
|
114
98
|
class: "picker-option", "aria-pressed": String(m === selected),
|
|
115
99
|
onclick: async () => {
|
|
116
100
|
if (busy) return;
|
|
117
101
|
busy = true;
|
|
118
|
-
const ok = m === selected || await save("model", m.id);
|
|
102
|
+
const ok = (!provisional && m === selected) || await save("model", m.id);
|
|
119
103
|
busy = false;
|
|
120
104
|
if (ok && ui.menu === pop) {
|
|
121
105
|
if (supportsControls()) showEffort(true);
|
|
@@ -202,8 +186,52 @@ export async function openModelPicker(view = "effort", catalog) {
|
|
|
202
186
|
if (focus) (slider?.el ?? name).focus({ preventScroll: true });
|
|
203
187
|
}
|
|
204
188
|
|
|
205
|
-
|
|
206
|
-
|
|
189
|
+
const isOpen = () => ui.menu === pop && pop.matchesContext();
|
|
190
|
+
const cached = catalogLoaded.get(agent);
|
|
191
|
+
let interacted = false;
|
|
192
|
+
if (conv && catalog && cached) return render(catalog);
|
|
193
|
+
if (conv && cached?.length) {
|
|
194
|
+
provisional = true;
|
|
195
|
+
render({
|
|
196
|
+
models: cached,
|
|
197
|
+
current: conv.runtimeModel ?? conv.model ?? catalogDefaults.get(agent)?.model,
|
|
198
|
+
currentEffort: conv.runtimeEffort ?? conv.effort,
|
|
199
|
+
fastModel: conv.fastModel,
|
|
200
|
+
effortSupported: S.agents.find((a) => a.id === agent)?.capabilities?.effort,
|
|
201
|
+
});
|
|
202
|
+
// 一旦开始操作,保留这次打开的控件与选择,避免迟到的响应打断点击或拖动。
|
|
203
|
+
const markInteraction = () => { interacted = true; };
|
|
204
|
+
for (const event of ["pointerdown", "keydown", "click"]) {
|
|
205
|
+
pop.addEventListener(event, markInteraction, { capture: true, once: true });
|
|
206
|
+
}
|
|
207
|
+
} else {
|
|
208
|
+
fill(pop, h("div", { class: "pop-loading", role: "status", "aria-label": "正在读取模型" }, h("span", { class: "spinner" })));
|
|
209
|
+
position();
|
|
210
|
+
}
|
|
211
|
+
try {
|
|
212
|
+
if (conv) {
|
|
213
|
+
const [data] = await Promise.all([
|
|
214
|
+
catalog ?? api(`/api/conversations/${encodeURIComponent(key)}/models`),
|
|
215
|
+
cached ?? agentCatalog(agent).catch(() => []),
|
|
216
|
+
]);
|
|
217
|
+
if (isOpen() && !interacted) {
|
|
218
|
+
provisional = false;
|
|
219
|
+
render(data);
|
|
220
|
+
}
|
|
221
|
+
} else {
|
|
222
|
+
const models = await agentCatalog(agent);
|
|
223
|
+
if (!isOpen()) return;
|
|
224
|
+
const expert = findExpert(expertId);
|
|
225
|
+
render({
|
|
226
|
+
models,
|
|
227
|
+
current: draftPick().model || expert?.model || catalogDefaults.get(agent)?.model,
|
|
228
|
+
currentEffort: draftPick().effort || expert?.effort,
|
|
229
|
+
fastModel: S.draftFastModel,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
} catch (err) {
|
|
233
|
+
if (isOpen() && !provisional) fill(pop, h("div", { class: "pop-error", role: "alert" }, err.message));
|
|
234
|
+
}
|
|
207
235
|
}
|
|
208
236
|
|
|
209
237
|
/** 拖动时按连续坐标绘制,释放时吸附到最近档位并保存。 */
|