agent-loft 0.2.129 → 0.2.131
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/src/agents/codex/driver.ts +14 -9
- package/src/agents/codex/protocol.ts +2 -1
- package/src/agents/codex/session.ts +12 -1
- package/src/channels/web/api.ts +5 -0
- package/src/core/hub.ts +30 -4
- package/src/core/store.ts +2 -0
- package/src/core/types.ts +4 -0
- package/web/css/composer.css +18 -2
- package/web/css/overlay.css +155 -17
- package/web/css/tasks.css +2 -0
- package/web/lib/dom.js +1 -0
- package/web/state.js +1 -0
- package/web/views/composer-models.js +276 -0
- package/web/views/composer.js +7 -5
- package/web/views/conv-actions.js +3 -94
- package/web/views/experts.js +1 -0
- package/web/views/messages.js +1 -0
- package/web/views/topbar.js +27 -6
package/package.json
CHANGED
|
@@ -256,15 +256,20 @@ export class CodexDriver implements AgentDriver {
|
|
|
256
256
|
const res = await appServer.call<ModelListResponse>("model/list", {});
|
|
257
257
|
return (res.data ?? [])
|
|
258
258
|
.filter((m) => !m.hidden)
|
|
259
|
-
.map((m) =>
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
? {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
259
|
+
.map((m) => {
|
|
260
|
+
const fast = m.serviceTiers?.find((tier) => tier.id === "priority");
|
|
261
|
+
return {
|
|
262
|
+
id: m.model,
|
|
263
|
+
label: m.displayName || m.model,
|
|
264
|
+
...(m.description ? { description: m.description } : {}),
|
|
265
|
+
...(m.supportedReasoningEfforts?.length
|
|
266
|
+
? { efforts: m.supportedReasoningEfforts.map((e) => e.reasoningEffort) }
|
|
267
|
+
: {}),
|
|
268
|
+
...(m.defaultReasoningEffort ? { defaultEffort: m.defaultReasoningEffort } : {}),
|
|
269
|
+
...(fast ? { fastMode: { description: fast.description } } : {}),
|
|
270
|
+
...(m.isDefault ? { isDefault: true } : {}),
|
|
271
|
+
};
|
|
272
|
+
});
|
|
268
273
|
}
|
|
269
274
|
|
|
270
275
|
catalog(): Promise<ModelInfo[]> {
|
|
@@ -56,6 +56,7 @@ export type Model = {
|
|
|
56
56
|
description?: string;
|
|
57
57
|
hidden?: boolean;
|
|
58
58
|
isDefault?: boolean;
|
|
59
|
+
serviceTiers?: { id: string; description: string }[];
|
|
59
60
|
supportedReasoningEfforts?: ReasoningEffortOption[];
|
|
60
61
|
defaultReasoningEffort?: string;
|
|
61
62
|
};
|
|
@@ -84,7 +85,7 @@ export type Thread = {
|
|
|
84
85
|
};
|
|
85
86
|
|
|
86
87
|
/** collaborationMode 是实验字段(initialize 时开了 experimentalApi 才有):这条 thread 上次停在哪个模式 */
|
|
87
|
-
export type ThreadResponse = { thread: Thread; collaborationMode?: { mode?: string } | null };
|
|
88
|
+
export type ThreadResponse = { thread: Thread; model?: string; collaborationMode?: { mode?: string } | null };
|
|
88
89
|
export type ThreadListResponse = { data: Thread[]; nextCursor?: string | null };
|
|
89
90
|
|
|
90
91
|
/** 只列出我们会发的:文字,以及落在本机的图片。 */
|
|
@@ -572,7 +572,7 @@ export class CodexSession implements AgentSession {
|
|
|
572
572
|
}
|
|
573
573
|
throw new DisposedError();
|
|
574
574
|
}
|
|
575
|
-
this.adopt(res.thread);
|
|
575
|
+
this.adopt({ ...res.thread, model: res.model ?? res.thread.model });
|
|
576
576
|
this.planOnThread = res.collaborationMode?.mode === "plan";
|
|
577
577
|
// 到这里分叉才算完成;之前任何一步失败,下次重试都还会走 thread/fork,绝不会续写原会话
|
|
578
578
|
if (fork) this.forked = true;
|
|
@@ -674,6 +674,8 @@ export class CodexSession implements AgentSession {
|
|
|
674
674
|
sandboxPolicy: sandboxPolicyFor(this.sandboxMode, this.opts.cwd),
|
|
675
675
|
...(this.opts.model ? { model: this.opts.model } : {}),
|
|
676
676
|
...(this.opts.effort ? { effort: this.opts.effort } : {}),
|
|
677
|
+
// 只覆盖正在启动的轮次,恢复外部 thread 时也按这条对话的选择走。
|
|
678
|
+
serviceTierForTurn: this.fastEnabled ? "priority" : "default",
|
|
677
679
|
...(collaborationMode ? { collaborationMode } : {}),
|
|
678
680
|
});
|
|
679
681
|
})
|
|
@@ -762,6 +764,14 @@ export class CodexSession implements AgentSession {
|
|
|
762
764
|
this.runtime = { ...(nextModel ? { model: nextModel } : {}), ...(nextEffort ? { effort: nextEffort } : {}) };
|
|
763
765
|
}
|
|
764
766
|
|
|
767
|
+
setFastModel(model: string | undefined): void {
|
|
768
|
+
this.opts.fastModel = model;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
private get fastEnabled(): boolean {
|
|
772
|
+
return !!this.opts.fastModel && this.opts.fastModel === (this.opts.model || this.runtime.model);
|
|
773
|
+
}
|
|
774
|
+
|
|
765
775
|
/** 已知的模型 / 思考程度,不拉起进程、不发请求(顶栏显示用) */
|
|
766
776
|
peekRuntime(): RuntimeInfo {
|
|
767
777
|
return this.runtime;
|
|
@@ -830,6 +840,7 @@ export class CodexSession implements AgentSession {
|
|
|
830
840
|
// 转交出来的轮次不经过 turn/start:先把这条对话现在的工作目录、沙箱、模型写到 thread 上,权限才对得上
|
|
831
841
|
await appServer.call("thread/settings/update", {
|
|
832
842
|
threadId,
|
|
843
|
+
serviceTier: this.fastEnabled ? "priority" : null,
|
|
833
844
|
cwd: this.opts.cwd,
|
|
834
845
|
approvalPolicy: "on-request",
|
|
835
846
|
sandboxPolicy: sandboxPolicyFor(this.sandboxMode, this.opts.cwd),
|
package/src/channels/web/api.ts
CHANGED
|
@@ -1265,6 +1265,11 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
1265
1265
|
case "model":
|
|
1266
1266
|
text = await hub.setModel(key, value);
|
|
1267
1267
|
break;
|
|
1268
|
+
case "fastModel":
|
|
1269
|
+
text = await hub.setFastModel(key, value || undefined).catch((err: Error) => {
|
|
1270
|
+
throw new HttpError(400, err.message);
|
|
1271
|
+
});
|
|
1272
|
+
break;
|
|
1268
1273
|
case "effort":
|
|
1269
1274
|
text = await hub.setEffort(key, value);
|
|
1270
1275
|
break;
|
package/src/core/hub.ts
CHANGED
|
@@ -175,6 +175,7 @@ export type CommandReply =
|
|
|
175
175
|
models: ModelInfo[];
|
|
176
176
|
current?: string;
|
|
177
177
|
currentEffort?: string;
|
|
178
|
+
fastModel?: string;
|
|
178
179
|
effortSupported: boolean;
|
|
179
180
|
}
|
|
180
181
|
/** 能换成哪些专家(飞书:换专家 = 开新会话) */
|
|
@@ -193,6 +194,7 @@ export type ConversationInfo = {
|
|
|
193
194
|
sessionId?: string;
|
|
194
195
|
model?: string;
|
|
195
196
|
effort?: string;
|
|
197
|
+
fastModel?: string;
|
|
196
198
|
/** 实际在用的模型 / 思考程度(尽力而为,可能不全)。model/effort 只是显式选过的 */
|
|
197
199
|
runtimeModel?: string;
|
|
198
200
|
runtimeEffort?: string;
|
|
@@ -713,6 +715,7 @@ class Hub extends EventEmitter<{
|
|
|
713
715
|
...(binding.sessionId ? { sessionId: binding.sessionId } : {}),
|
|
714
716
|
...(binding.model ? { model: binding.model } : {}),
|
|
715
717
|
...(binding.effort ? { effort: binding.effort } : {}),
|
|
718
|
+
...(binding.fastModel ? { fastModel: binding.fastModel } : {}),
|
|
716
719
|
...(() => {
|
|
717
720
|
const rt = this.displayRuntime(conv, binding);
|
|
718
721
|
return { ...(rt.model ? { runtimeModel: rt.model } : {}), ...(rt.effort ? { runtimeEffort: rt.effort } : {}) };
|
|
@@ -840,6 +843,7 @@ class Hub extends EventEmitter<{
|
|
|
840
843
|
uploadsDir: ensureUploadsDir(key),
|
|
841
844
|
...(model ? { model } : {}),
|
|
842
845
|
...(effort ? { effort } : {}),
|
|
846
|
+
...(binding.fastModel ? { fastModel: binding.fastModel } : {}),
|
|
843
847
|
...(resumeId ? { resumeId } : {}),
|
|
844
848
|
...(fork ? { fork: true } : {}),
|
|
845
849
|
...(permission ? { permission } : {}),
|
|
@@ -1589,7 +1593,7 @@ class Hub extends EventEmitter<{
|
|
|
1589
1593
|
this.markSwitched(key, op.seq);
|
|
1590
1594
|
const next = this.nextWeixinConversation(conv);
|
|
1591
1595
|
this.clearFullPermission(next.key);
|
|
1592
|
-
updateAgentBinding(next.key, next.agent, { sessionId: undefined, forkFrom: undefined, pastSessions: undefined, taskResults: undefined, model: model || undefined, effort: undefined });
|
|
1596
|
+
updateAgentBinding(next.key, next.agent, { sessionId: undefined, forkFrom: undefined, pastSessions: undefined, taskResults: undefined, model: model || undefined, effort: undefined, fastModel: undefined });
|
|
1593
1597
|
this.emitEvent(next.key, { type: "meta" });
|
|
1594
1598
|
const runtime = await this.runtimeNow(next.key);
|
|
1595
1599
|
return `已开新会话(${this.label(conv.agent)},模型 ${runtime.model ?? "默认"}${
|
|
@@ -1674,14 +1678,18 @@ class Hub extends EventEmitter<{
|
|
|
1674
1678
|
models,
|
|
1675
1679
|
...(runtime.model ? { current: runtime.model } : {}),
|
|
1676
1680
|
...(runtime.effort ? { currentEffort: runtime.effort } : {}),
|
|
1681
|
+
fastModel: agentBinding(conv).fastModel,
|
|
1677
1682
|
effortSupported: driver.capabilities.effort,
|
|
1678
1683
|
};
|
|
1679
1684
|
}
|
|
1680
1685
|
|
|
1681
1686
|
private async setModelNow(key: string, model: string): Promise<string> {
|
|
1682
1687
|
const conv = getConversation(key)!;
|
|
1683
|
-
|
|
1684
|
-
|
|
1688
|
+
const session = this.session(key);
|
|
1689
|
+
await withTimeout(session.setModel(model), "切换模型");
|
|
1690
|
+
const fastModel = agentBinding(conv).fastModel === model ? model : undefined;
|
|
1691
|
+
session.setFastModel?.(fastModel);
|
|
1692
|
+
updateAgentBinding(key, conv.agent, { model, fastModel });
|
|
1685
1693
|
this.emitEvent(key, { type: "meta" });
|
|
1686
1694
|
return `模型已切换为 ${model}。`;
|
|
1687
1695
|
}
|
|
@@ -1767,7 +1775,7 @@ class Hub extends EventEmitter<{
|
|
|
1767
1775
|
if (!conv) return false;
|
|
1768
1776
|
const binding = agentBinding(conv);
|
|
1769
1777
|
if ((binding.model || undefined) === rt.model && (binding.effort || undefined) === rt.effort) return false;
|
|
1770
|
-
updateAgentBinding(key, conv.agent, { model: rt.model, effort: rt.effort });
|
|
1778
|
+
updateAgentBinding(key, conv.agent, { model: rt.model, effort: rt.effort, fastModel: binding.model === rt.model ? binding.fastModel : undefined });
|
|
1771
1779
|
if (this.live.has(key)) await this.drop(key, "定时任务换了模型");
|
|
1772
1780
|
this.emitEvent(key, { type: "meta" });
|
|
1773
1781
|
return true;
|
|
@@ -2410,6 +2418,24 @@ class Hub extends EventEmitter<{
|
|
|
2410
2418
|
return this.serial(key, () => this.setModelNow(key, model));
|
|
2411
2419
|
}
|
|
2412
2420
|
|
|
2421
|
+
/** 传入用户看到的模型,防止旧页面把加速开在刚换的新模型上。 */
|
|
2422
|
+
setFastModel(key: string, model: string | undefined): Promise<string> {
|
|
2423
|
+
return this.serial(key, async () => {
|
|
2424
|
+
const conv = getConversation(key)!;
|
|
2425
|
+
const session = this.session(key);
|
|
2426
|
+
if (!session.setFastModel) throw new Error("这个引擎不支持快速模式");
|
|
2427
|
+
if (model) {
|
|
2428
|
+
const { models, current } = await this.modelsNow(key);
|
|
2429
|
+
const selected = current ? models.find((m) => m.id === current) : models.find((m) => m.isDefault);
|
|
2430
|
+
if (selected?.id !== model || !selected.fastMode) throw new Error("当前模型不支持这个快速档位,请重新选择");
|
|
2431
|
+
}
|
|
2432
|
+
session.setFastModel(model);
|
|
2433
|
+
updateAgentBinding(key, conv.agent, { fastModel: model });
|
|
2434
|
+
this.emitEvent(key, { type: "meta" });
|
|
2435
|
+
return model ? "已开启快速模式,下一轮生效。" : "已关闭快速模式,下一轮生效。";
|
|
2436
|
+
});
|
|
2437
|
+
}
|
|
2438
|
+
|
|
2413
2439
|
setEffort(key: string, effort: string): Promise<string> {
|
|
2414
2440
|
return this.serial(key, () => this.setEffortNow(key, effort));
|
|
2415
2441
|
}
|
package/src/core/store.ts
CHANGED
package/src/core/types.ts
CHANGED
|
@@ -196,6 +196,8 @@ export type ModelInfo = {
|
|
|
196
196
|
label: string;
|
|
197
197
|
description?: string;
|
|
198
198
|
efforts?: string[];
|
|
199
|
+
defaultEffort?: string;
|
|
200
|
+
fastMode?: { description: string };
|
|
199
201
|
isDefault?: boolean;
|
|
200
202
|
};
|
|
201
203
|
|
|
@@ -245,6 +247,7 @@ export type SessionOptions = {
|
|
|
245
247
|
cwd: string;
|
|
246
248
|
model?: string;
|
|
247
249
|
effort?: string;
|
|
250
|
+
fastModel?: string;
|
|
248
251
|
resumeId?: string;
|
|
249
252
|
fork?: boolean;
|
|
250
253
|
/** 附件所在目录,agent 需要能直接读 */
|
|
@@ -311,6 +314,7 @@ export interface AgentSession {
|
|
|
311
314
|
cancelQueued?(input: UserInput): boolean;
|
|
312
315
|
interrupt(opts?: InterruptOptions): Promise<void>;
|
|
313
316
|
setModel(model?: string, effort?: string): Promise<void>;
|
|
317
|
+
setFastModel?(model: string | undefined): void;
|
|
314
318
|
describeRuntime(): Promise<RuntimeInfo>;
|
|
315
319
|
/** 手上已知的模型 / 思考程度,同步返回:不拉起进程、不发请求 */
|
|
316
320
|
peekRuntime?(): RuntimeInfo;
|
package/web/css/composer.css
CHANGED
|
@@ -138,6 +138,7 @@ button.ctx-item:hover {
|
|
|
138
138
|
display: inline-flex;
|
|
139
139
|
align-items: center;
|
|
140
140
|
gap: 5px;
|
|
141
|
+
min-width: 0;
|
|
141
142
|
max-width: min(260px, 45vw);
|
|
142
143
|
height: 32px;
|
|
143
144
|
padding: 0 10px;
|
|
@@ -145,19 +146,34 @@ button.ctx-item:hover {
|
|
|
145
146
|
font-size: 14px;
|
|
146
147
|
color: var(--fg);
|
|
147
148
|
white-space: nowrap;
|
|
149
|
+
transition: background-color 140ms ease;
|
|
148
150
|
}
|
|
149
151
|
|
|
150
|
-
.model-pill:hover
|
|
152
|
+
.model-pill:hover,
|
|
153
|
+
.model-pill[aria-expanded="true"] {
|
|
151
154
|
background: var(--bg-hover);
|
|
152
155
|
}
|
|
153
156
|
|
|
157
|
+
|
|
158
|
+
.model-pill .picker-prompt { display: none; }
|
|
159
|
+
.model-slot[data-picker="effort"] .model-pill > :not(.picker-prompt) { display: none; }
|
|
160
|
+
.model-slot[data-picker="effort"] .picker-prompt { display: inline; color: var(--fg-faint); }
|
|
161
|
+
.model-pill .fast-mark {
|
|
162
|
+
display: inline-flex;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.model-pill .fast-mark svg {
|
|
166
|
+
color: var(--fg);
|
|
167
|
+
fill: currentColor;
|
|
168
|
+
}
|
|
169
|
+
|
|
154
170
|
.model-pill .model-name {
|
|
155
171
|
overflow: hidden;
|
|
156
172
|
text-overflow: ellipsis;
|
|
157
173
|
}
|
|
158
174
|
|
|
159
175
|
.model-pill .sub {
|
|
160
|
-
color: var(--fg-
|
|
176
|
+
color: var(--fg-soft);
|
|
161
177
|
flex-shrink: 0;
|
|
162
178
|
}
|
|
163
179
|
|
package/web/css/overlay.css
CHANGED
|
@@ -459,29 +459,167 @@ button.list-item:hover {
|
|
|
459
459
|
height: 18px;
|
|
460
460
|
}
|
|
461
461
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
padding:
|
|
467
|
-
|
|
468
|
-
|
|
462
|
+
/* 输入框的强度滑杆与模型列表共用一个锚点。 */
|
|
463
|
+
.model-pop {
|
|
464
|
+
width: 256px;
|
|
465
|
+
min-width: 0;
|
|
466
|
+
padding: 0;
|
|
467
|
+
border-radius: 16px;
|
|
468
|
+
background: var(--bg-input);
|
|
469
|
+
box-shadow: 0 6px 18px color-mix(in srgb, var(--fg) 9%, transparent);
|
|
470
|
+
transform-origin: bottom right;
|
|
471
|
+
animation: picker-open 140ms ease-out;
|
|
469
472
|
}
|
|
470
473
|
|
|
471
|
-
.
|
|
472
|
-
|
|
474
|
+
.model-pop[data-view="effort"] {
|
|
475
|
+
padding: 6px 12px 8px;
|
|
476
|
+
overflow: visible;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
.effort-header {
|
|
480
|
+
position: relative;
|
|
481
|
+
display: grid;
|
|
482
|
+
padding: 3px 26px 0;
|
|
483
|
+
text-align: center;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
.effort-value { color: var(--fg); font-size: 14px; font-weight: 600; line-height: 20px; }
|
|
487
|
+
.effort-center { min-width: 0; }
|
|
488
|
+
.model-pop .picker-model-link {
|
|
489
|
+
display: inline-flex;
|
|
490
|
+
align-items: center;
|
|
473
491
|
justify-content: center;
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
492
|
+
max-width: 100%;
|
|
493
|
+
gap: 1px;
|
|
494
|
+
padding: 0 3px;
|
|
477
495
|
color: var(--fg-soft);
|
|
496
|
+
font-size: 12px;
|
|
497
|
+
line-height: 18px;
|
|
478
498
|
}
|
|
499
|
+
.effort-value { display: block; }
|
|
500
|
+
.picker-model-link > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
501
|
+
.picker-model-link svg { width: 11px; height: 11px; transform: rotate(180deg); }
|
|
479
502
|
|
|
480
|
-
.
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
503
|
+
.model-pop .picker-icon {
|
|
504
|
+
position: absolute;
|
|
505
|
+
top: 0;
|
|
506
|
+
display: grid;
|
|
507
|
+
place-items: center;
|
|
508
|
+
width: 28px;
|
|
509
|
+
height: 28px;
|
|
510
|
+
border-radius: 8px;
|
|
511
|
+
padding: 0;
|
|
512
|
+
color: var(--fg-faint);
|
|
513
|
+
}
|
|
514
|
+
.picker-icon svg { width: 15px; height: 15px; }
|
|
515
|
+
.picker-fast { left: -8px; }
|
|
516
|
+
.picker-reset { right: -8px; }
|
|
517
|
+
.model-pop .picker-fast[aria-checked="true"] { color: var(--fg); }
|
|
518
|
+
.picker-fast[aria-checked="true"] svg { fill: currentColor; }
|
|
519
|
+
.picker-tip {
|
|
520
|
+
position: absolute;
|
|
521
|
+
z-index: 1;
|
|
522
|
+
bottom: calc(100% + 5px);
|
|
523
|
+
left: max(50%, calc(42px - var(--picker-left)));
|
|
524
|
+
transform: translate(-50%, 3px);
|
|
525
|
+
opacity: 0;
|
|
526
|
+
visibility: hidden;
|
|
527
|
+
pointer-events: none;
|
|
528
|
+
padding: 6px 12px;
|
|
529
|
+
border-radius: 14px;
|
|
530
|
+
background: #1c1d1f;
|
|
531
|
+
color: #bdbec0;
|
|
532
|
+
font-size: 12px;
|
|
533
|
+
line-height: 17px;
|
|
534
|
+
text-align: left;
|
|
535
|
+
white-space: nowrap;
|
|
536
|
+
box-shadow: 0 4px 14px #0002;
|
|
537
|
+
transition: opacity 100ms, transform 100ms, visibility 100ms;
|
|
538
|
+
}
|
|
539
|
+
.picker-tip strong { display: block; color: white; font-weight: 500; }
|
|
540
|
+
@media (hover: hover) {
|
|
541
|
+
.picker-fast:hover .picker-tip { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
|
|
542
|
+
}
|
|
543
|
+
.picker-fast:focus-visible .picker-tip { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
|
|
544
|
+
|
|
545
|
+
.effort-slider {
|
|
546
|
+
position: relative;
|
|
547
|
+
display: grid;
|
|
548
|
+
align-items: center;
|
|
549
|
+
height: 36px;
|
|
550
|
+
margin-top: 7px;
|
|
551
|
+
touch-action: none;
|
|
552
|
+
user-select: none;
|
|
553
|
+
overflow: clip;
|
|
554
|
+
overflow-clip-margin: 3px;
|
|
555
|
+
cursor: pointer;
|
|
556
|
+
}
|
|
557
|
+
.effort-slider::before {
|
|
558
|
+
content: "";
|
|
559
|
+
position: absolute;
|
|
560
|
+
inset: 6px 0;
|
|
561
|
+
border-radius: 99px;
|
|
562
|
+
background: color-mix(in srgb, var(--fg) 10%, var(--bg-input));
|
|
563
|
+
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--fg) 6%, transparent);
|
|
564
|
+
}
|
|
565
|
+
.effort-lane { position: relative; height: 24px; margin: 0 13px; pointer-events: none; }
|
|
566
|
+
.effort-fill {
|
|
567
|
+
position: absolute;
|
|
568
|
+
inset: 0 auto 0 -13px;
|
|
569
|
+
width: calc(13px + var(--position));
|
|
570
|
+
border-radius: 99px 0 0 99px;
|
|
571
|
+
background: var(--fg);
|
|
572
|
+
transition: width 150ms cubic-bezier(.2,.85,.25,1);
|
|
573
|
+
}
|
|
574
|
+
.effort-lane i {
|
|
575
|
+
position: absolute;
|
|
576
|
+
top: 50%;
|
|
577
|
+
width: 4px;
|
|
578
|
+
height: 4px;
|
|
579
|
+
transform: translate(-50%, -50%);
|
|
580
|
+
border-radius: 50%;
|
|
581
|
+
background: color-mix(in srgb, var(--fg) 24%, transparent);
|
|
582
|
+
}
|
|
583
|
+
.effort-lane i.passed { background: color-mix(in srgb, var(--bg) 55%, transparent); }
|
|
584
|
+
.effort-handle {
|
|
585
|
+
position: absolute;
|
|
586
|
+
inset: 0;
|
|
587
|
+
transform: translateX(var(--position));
|
|
588
|
+
transition: transform 150ms cubic-bezier(.2,.85,.25,1);
|
|
589
|
+
}
|
|
590
|
+
.effort-handle::after {
|
|
591
|
+
content: "";
|
|
592
|
+
position: absolute;
|
|
593
|
+
top: 50%;
|
|
594
|
+
width: 27px;
|
|
595
|
+
height: 27px;
|
|
596
|
+
transform: translate(-50%, -50%);
|
|
597
|
+
border-radius: 50%;
|
|
598
|
+
background: var(--bg-input);
|
|
599
|
+
border: 1px solid color-mix(in srgb, var(--fg) 22%, var(--bg-input));
|
|
600
|
+
box-shadow: 0 1px 3px #0002;
|
|
601
|
+
}
|
|
602
|
+
.effort-slider.dragging { cursor: grabbing; }
|
|
603
|
+
.effort-slider.dragging :is(.effort-handle, .effort-fill) { transition: none; }
|
|
604
|
+
|
|
605
|
+
.model-pop[data-view="models"] { padding: 5px; }
|
|
606
|
+
.model-pop .pop-head { padding: 3px 7px; font-weight: 500; }
|
|
607
|
+
.picker-options { min-height: 0; max-height: 300px; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
|
|
608
|
+
.model-pop .picker-option { width: 100%; padding: 4px 7px; min-height: 29px; line-height: 20px; justify-content: space-between; }
|
|
609
|
+
.picker-option svg { width: 15px; height: 15px; }
|
|
610
|
+
.model-pop :is(button, [role="slider"]):focus-visible,
|
|
611
|
+
.model-pill:focus-visible { outline: 2px solid var(--fg); outline-offset: -2px; border-radius: 8px; }
|
|
612
|
+
|
|
613
|
+
@keyframes picker-open {
|
|
614
|
+
from { opacity: 0; transform: translateY(3px) scale(.985); }
|
|
615
|
+
}
|
|
616
|
+
@media (pointer: coarse) {
|
|
617
|
+
.effort-slider { height: 44px; }
|
|
618
|
+
.effort-slider::before { inset-block: 10px; }
|
|
619
|
+
.model-pop .picker-option { min-height: 40px; }
|
|
620
|
+
}
|
|
621
|
+
@media (prefers-reduced-motion: reduce) {
|
|
622
|
+
.model-pop, .model-pop *, .model-pill { animation: none; transition: none; }
|
|
485
623
|
}
|
|
486
624
|
|
|
487
625
|
.popover .pop-loading,
|
package/web/css/tasks.css
CHANGED
|
@@ -253,10 +253,12 @@ button.task-run:hover {
|
|
|
253
253
|
transition: transform 0.15s;
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
+
[role="switch"][aria-checked="true"] > .switch .slider,
|
|
256
257
|
.switch input:checked + .slider {
|
|
257
258
|
background: var(--accent);
|
|
258
259
|
}
|
|
259
260
|
|
|
261
|
+
[role="switch"][aria-checked="true"] > .switch .slider::before,
|
|
260
262
|
.switch input:checked + .slider::before {
|
|
261
263
|
transform: translateX(16px);
|
|
262
264
|
}
|
package/web/lib/dom.js
CHANGED
|
@@ -27,6 +27,7 @@ export function fill(el, ...kids) {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export const ICON = {
|
|
30
|
+
bolt: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="m13.5 2-10 12H11l-.5 8 10-13H13z"/></svg>',
|
|
30
31
|
shield: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3 5 6v5c0 4.4 2.9 8.3 7 10 4.1-1.7 7-5.6 7-10V6Z"/></svg>',
|
|
31
32
|
menu: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M4 6h16M4 12h16M4 18h16"/></svg>',
|
|
32
33
|
edit: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z"/></svg>',
|
package/web/state.js
CHANGED
|
@@ -11,6 +11,7 @@ export const S = {
|
|
|
11
11
|
defaultPermission: null,
|
|
12
12
|
/** 新对话里打开的计划模式(和 draftPermission 一样,建好对话后带过去) */
|
|
13
13
|
draftPlan: false,
|
|
14
|
+
draftFastModel: null,
|
|
14
15
|
current: null,
|
|
15
16
|
/** 新对话的引擎(claude / codex),跟着选的专家走 */
|
|
16
17
|
draftAgent: localStorage.getItem("aim.agent") || null,
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { api } from "../lib/api.js";
|
|
2
|
+
import { fill, h, icon } from "../lib/dom.js";
|
|
3
|
+
import { closeMenu, placePopover, showPopover } from "../lib/overlay.js";
|
|
4
|
+
import { S, ui } from "../state.js";
|
|
5
|
+
import { doAction } from "./conv-actions.js";
|
|
6
|
+
import { findExpert } from "./experts.js";
|
|
7
|
+
import { agentCatalog, catalogDefaults, draftPick, effortLabel, composerModelLabel, modelName, renderContext, saveDraftPick, visibleModels } from "./topbar.js";
|
|
8
|
+
|
|
9
|
+
export async function openModelPicker(view = "effort", catalog) {
|
|
10
|
+
const anchor = ui.modelSlot;
|
|
11
|
+
if (!anchor) return;
|
|
12
|
+
if (ui.menu?.dataset.for === "model") return closeMenu();
|
|
13
|
+
const key = S.current;
|
|
14
|
+
const expertId = S.draftExpert;
|
|
15
|
+
const conv = S.convs.get(key);
|
|
16
|
+
const agent = conv?.agent ?? S.draftAgent;
|
|
17
|
+
const pop = showPopover(anchor);
|
|
18
|
+
pop.dataset.for = "model";
|
|
19
|
+
pop.matchesContext = () => S.current === key && (!!key || (S.draftExpert === expertId && S.draftAgent === agent));
|
|
20
|
+
pop.classList.add("model-pop");
|
|
21
|
+
pop.setAttribute("role", "dialog");
|
|
22
|
+
pop.setAttribute("aria-label", "模型设置");
|
|
23
|
+
const trigger = () => anchor.querySelector("button");
|
|
24
|
+
trigger()?.setAttribute("aria-expanded", "true");
|
|
25
|
+
const position = () => {
|
|
26
|
+
pop.style.maxHeight = `min(480px, ${Math.max(0, anchor.getBoundingClientRect().top - 16)}px)`;
|
|
27
|
+
placePopover(pop, anchor);
|
|
28
|
+
pop.style.setProperty("--picker-left", pop.style.left);
|
|
29
|
+
};
|
|
30
|
+
window.addEventListener("resize", position);
|
|
31
|
+
window.visualViewport?.addEventListener("resize", position);
|
|
32
|
+
pop.onMenuClose = () => {
|
|
33
|
+
delete anchor.dataset.picker;
|
|
34
|
+
trigger()?.setAttribute("aria-expanded", "false");
|
|
35
|
+
window.removeEventListener("resize", position);
|
|
36
|
+
window.visualViewport?.removeEventListener("resize", position);
|
|
37
|
+
if (pop.contains(document.activeElement)) trigger()?.focus({ preventScroll: true });
|
|
38
|
+
};
|
|
39
|
+
fill(pop, h("div", { class: "pop-loading", role: "status", "aria-label": "正在读取模型" }, h("span", { class: "spinner" })));
|
|
40
|
+
position();
|
|
41
|
+
|
|
42
|
+
let models, current, currentEffort, fastModel;
|
|
43
|
+
let effortSupported = true;
|
|
44
|
+
try {
|
|
45
|
+
if (conv) {
|
|
46
|
+
const [data] = await Promise.all([
|
|
47
|
+
catalog ?? api(`/api/conversations/${encodeURIComponent(key)}/models`),
|
|
48
|
+
agentCatalog(agent).catch(() => []),
|
|
49
|
+
]);
|
|
50
|
+
({ models, current, currentEffort, fastModel, effortSupported } = data);
|
|
51
|
+
} else {
|
|
52
|
+
models = await agentCatalog(agent);
|
|
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;
|
|
62
|
+
}
|
|
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
|
+
const selectedModel = () => {
|
|
68
|
+
const exact = models.find((m) => m.id === current);
|
|
69
|
+
if (exact) return exact;
|
|
70
|
+
const name = modelName(agent, current);
|
|
71
|
+
return models.find((m) => m.id !== "default" && (m.label || m.id) === name);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const configuredEffort = [findExpert(conv ? (conv.expert?.id ?? agent) : expertId)?.effort, catalogDefaults.get(agent)?.effort];
|
|
75
|
+
let busy = false;
|
|
76
|
+
async function save(kind, value) {
|
|
77
|
+
if (!pop.matchesContext()) return false;
|
|
78
|
+
if (conv) {
|
|
79
|
+
const res = await doAction(kind, value, {}, { quiet: true });
|
|
80
|
+
if (!res) return false;
|
|
81
|
+
fastModel = res.info.fastModel;
|
|
82
|
+
currentEffort = res.info.runtimeEffort ?? res.info.effort ?? currentEffort;
|
|
83
|
+
} else {
|
|
84
|
+
const pick = draftPick();
|
|
85
|
+
if (kind === "fastModel") S.draftFastModel = value || null;
|
|
86
|
+
else {
|
|
87
|
+
if (kind === "model") {
|
|
88
|
+
if (S.draftFastModel !== value) S.draftFastModel = null;
|
|
89
|
+
const supported = models.find((m) => m.id === value)?.efforts;
|
|
90
|
+
if (pick.effort && !supported?.includes(pick.effort)) delete pick.effort;
|
|
91
|
+
currentEffort = pick.effort || configuredEffort.find(Boolean);
|
|
92
|
+
}
|
|
93
|
+
pick[kind] = value;
|
|
94
|
+
saveDraftPick();
|
|
95
|
+
}
|
|
96
|
+
fastModel = S.draftFastModel;
|
|
97
|
+
renderContext();
|
|
98
|
+
}
|
|
99
|
+
if (kind === "effort") currentEffort = value;
|
|
100
|
+
if (kind === "model") current = value;
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function setView(name) {
|
|
105
|
+
anchor.dataset.picker = pop.dataset.view = name;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function showModels(focus) {
|
|
109
|
+
setView("models");
|
|
110
|
+
const selected = selectedModel();
|
|
111
|
+
const list = h("div", { class: "picker-options", "aria-label": "选择模型", role: "group" });
|
|
112
|
+
for (const m of shown) {
|
|
113
|
+
list.append(h("button", {
|
|
114
|
+
class: "picker-option", "aria-pressed": String(m === selected),
|
|
115
|
+
onclick: async () => {
|
|
116
|
+
if (busy) return;
|
|
117
|
+
busy = true;
|
|
118
|
+
const ok = m === selected || await save("model", m.id);
|
|
119
|
+
busy = false;
|
|
120
|
+
if (ok && ui.menu === pop) {
|
|
121
|
+
if (supportsControls()) showEffort(true);
|
|
122
|
+
else closeMenu();
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
}, composerModelLabel(agent, m.label || m.id), m === selected ? icon("check") : null));
|
|
126
|
+
}
|
|
127
|
+
list.onkeydown = (e) => {
|
|
128
|
+
const option = e.target;
|
|
129
|
+
const to = { ArrowDown: option.nextElementSibling, ArrowUp: option.previousElementSibling,
|
|
130
|
+
Home: list.firstElementChild, End: list.lastElementChild };
|
|
131
|
+
if (Object.hasOwn(to, e.key)) { e.preventDefault(); to[e.key]?.focus(); }
|
|
132
|
+
};
|
|
133
|
+
fill(pop, h("div", { class: "pop-head" }, "选择模型"), list);
|
|
134
|
+
if (!shown.length) fill(list, h("div", { class: "pop-error" }, "暂无可选模型"));
|
|
135
|
+
position();
|
|
136
|
+
const active = list.querySelector('[aria-pressed="true"]') ?? list.querySelector("button");
|
|
137
|
+
active?.scrollIntoView({ block: "nearest" });
|
|
138
|
+
if (focus) active?.focus({ preventScroll: true });
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function supportedEfforts() {
|
|
142
|
+
const m = selectedModel() ?? models.find((m) => m.efforts?.length);
|
|
143
|
+
return effortSupported ? m?.efforts ?? [] : [];
|
|
144
|
+
}
|
|
145
|
+
function supportsControls() { return supportedEfforts().length || selectedModel()?.fastMode; }
|
|
146
|
+
|
|
147
|
+
function showEffort(focus) {
|
|
148
|
+
setView("effort");
|
|
149
|
+
const model = selectedModel();
|
|
150
|
+
const levels = supportedEfforts();
|
|
151
|
+
if (!levels.length) anchor.dataset.picker = "model";
|
|
152
|
+
const fallback = [...configuredEffort, model?.defaultEffort].find((v) => levels.includes(v));
|
|
153
|
+
const initial = levels.includes(currentEffort) ? currentEffort : fallback;
|
|
154
|
+
const resetTo = fallback ?? initial;
|
|
155
|
+
const title = h("strong", { class: "effort-value" }, initial ? effortLabel(initial) : "默认");
|
|
156
|
+
const name = h("button", {
|
|
157
|
+
class: "picker-model-link", "aria-label": "选择模型", onclick: () => { if (!busy) showModels(true); },
|
|
158
|
+
}, h("span", {}, composerModelLabel(agent, modelName(agent, current) || "选择模型")), icon("back"));
|
|
159
|
+
const reset = h("button", {
|
|
160
|
+
class: "picker-icon picker-reset", title: fallback ? "恢复默认思考程度" : "还原打开时的思考程度",
|
|
161
|
+
onclick: () => slider?.select(resetTo),
|
|
162
|
+
}, icon("undo"));
|
|
163
|
+
let nextEffort;
|
|
164
|
+
let slider;
|
|
165
|
+
async function commit(value) {
|
|
166
|
+
nextEffort = value;
|
|
167
|
+
if (busy) return;
|
|
168
|
+
busy = true;
|
|
169
|
+
while (nextEffort && pop.matchesContext()) {
|
|
170
|
+
const next = nextEffort;
|
|
171
|
+
nextEffort = undefined;
|
|
172
|
+
if (next !== currentEffort && !await save("effort", next) && !nextEffort) slider.restore(currentEffort ?? initial);
|
|
173
|
+
}
|
|
174
|
+
busy = false;
|
|
175
|
+
}
|
|
176
|
+
if (levels.length) slider = effortSlider(levels, initial, (value) => {
|
|
177
|
+
title.textContent = value ? effortLabel(value) : "默认";
|
|
178
|
+
reset.disabled = !resetTo || value === resetTo;
|
|
179
|
+
}, commit);
|
|
180
|
+
|
|
181
|
+
let fast;
|
|
182
|
+
if (model?.fastMode) {
|
|
183
|
+
const speed = model.fastMode.description?.match(/(\d+(?:\.\d+)?)\s*[x×]/i)?.[1];
|
|
184
|
+
fast = h("button", {
|
|
185
|
+
class: "picker-icon picker-fast", role: "switch", "aria-label": "快速模式",
|
|
186
|
+
"aria-checked": String(fastModel === model.id), "aria-describedby": "picker-fast-tip",
|
|
187
|
+
onclick: async () => {
|
|
188
|
+
if (busy) return;
|
|
189
|
+
busy = true;
|
|
190
|
+
const ok = await save("fastModel", fastModel === model.id ? "" : model.id);
|
|
191
|
+
busy = false;
|
|
192
|
+
if (ok) fast.setAttribute("aria-checked", String(fastModel === model.id));
|
|
193
|
+
if (nextEffort) void commit(nextEffort);
|
|
194
|
+
},
|
|
195
|
+
}, icon("bolt"), h("span", { class: "picker-tip", role: "tooltip", id: "picker-fast-tip" },
|
|
196
|
+
speed ? h("strong", {}, `${speed} 倍速度`) : null, h("span", {}, "用量更多")));
|
|
197
|
+
}
|
|
198
|
+
fill(pop, h("div", { class: "effort-header" }, fast,
|
|
199
|
+
h("div", { class: "effort-center" }, levels.length ? title : null, name),
|
|
200
|
+
resetTo ? reset : null), slider?.el);
|
|
201
|
+
position();
|
|
202
|
+
if (focus) (slider?.el ?? name).focus({ preventScroll: true });
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (view === "model" || !supportsControls()) showModels(true);
|
|
206
|
+
else showEffort(true);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** 拖动时按连续坐标绘制,释放时吸附到最近档位并保存。 */
|
|
210
|
+
function effortSlider(levels, initial, preview, commit) {
|
|
211
|
+
const last = levels.length - 1;
|
|
212
|
+
const lane = h("span", { class: "effort-lane", "aria-hidden": "true" },
|
|
213
|
+
h("span", { class: "effort-fill" }),
|
|
214
|
+
levels.map((_, i) => h("i", { style: { left: `${last ? i / last * 100 : 0}%` } })),
|
|
215
|
+
h("span", { class: "effort-handle" }));
|
|
216
|
+
const el = h("div", {
|
|
217
|
+
class: "effort-slider", role: "slider", tabindex: "0", "aria-label": "思考程度",
|
|
218
|
+
"aria-valuemin": "0", "aria-valuemax": last, "aria-disabled": String(!last),
|
|
219
|
+
}, lane);
|
|
220
|
+
const ticks = lane.querySelectorAll("i");
|
|
221
|
+
let value = initial;
|
|
222
|
+
let index = Math.max(0, levels.indexOf(value));
|
|
223
|
+
let drag;
|
|
224
|
+
function draw(position, label = levels[Math.round(position)]) {
|
|
225
|
+
index = Math.round(position);
|
|
226
|
+
ticks.forEach((tick, i) => tick.classList.toggle("passed", i < position));
|
|
227
|
+
lane.style.setProperty("--position", `${last ? position / last * 100 : 0}%`);
|
|
228
|
+
el.setAttribute("aria-valuenow", String(index));
|
|
229
|
+
el.setAttribute("aria-valuetext", label ? effortLabel(label) : "默认");
|
|
230
|
+
preview(label);
|
|
231
|
+
}
|
|
232
|
+
function restore(saved) {
|
|
233
|
+
value = saved;
|
|
234
|
+
if (!drag) draw(Math.max(0, levels.indexOf(value)), value ?? null);
|
|
235
|
+
}
|
|
236
|
+
function select(next) {
|
|
237
|
+
restore(next);
|
|
238
|
+
void commit(next);
|
|
239
|
+
}
|
|
240
|
+
function move(e) {
|
|
241
|
+
const fraction = (e.clientX - drag.left - drag.offset) / drag.width;
|
|
242
|
+
draw(Math.max(0, Math.min(1, fraction)) * last);
|
|
243
|
+
}
|
|
244
|
+
el.onpointerdown = (e) => {
|
|
245
|
+
if (drag || !last || e.button !== 0) return;
|
|
246
|
+
const { left, width } = lane.getBoundingClientRect();
|
|
247
|
+
const offset = e.clientX - (left + width * index / last);
|
|
248
|
+
drag = { id: e.pointerId, left, width, offset: Math.abs(offset) < 13 ? offset : 0 };
|
|
249
|
+
el.setPointerCapture(e.pointerId);
|
|
250
|
+
el.classList.add("dragging");
|
|
251
|
+
move(e);
|
|
252
|
+
};
|
|
253
|
+
el.onpointermove = (e) => { if (drag?.id === e.pointerId) move(e); };
|
|
254
|
+
el.onpointerup = (e) => {
|
|
255
|
+
if (drag?.id !== e.pointerId) return;
|
|
256
|
+
move(e);
|
|
257
|
+
drag = null;
|
|
258
|
+
el.classList.remove("dragging");
|
|
259
|
+
select(levels[index]);
|
|
260
|
+
};
|
|
261
|
+
el.onlostpointercapture = el.onpointercancel = () => {
|
|
262
|
+
if (!drag) return;
|
|
263
|
+
drag = null;
|
|
264
|
+
el.classList.remove("dragging");
|
|
265
|
+
restore(value);
|
|
266
|
+
};
|
|
267
|
+
el.onkeydown = (e) => {
|
|
268
|
+
if (drag || !last) return;
|
|
269
|
+
const steps = { ArrowRight: index + 1, ArrowUp: index + 1, ArrowLeft: index - 1, ArrowDown: index - 1, Home: 0, End: last };
|
|
270
|
+
if (!Object.hasOwn(steps, e.key)) return;
|
|
271
|
+
e.preventDefault();
|
|
272
|
+
select(levels[Math.max(0, Math.min(last, steps[e.key]))]);
|
|
273
|
+
};
|
|
274
|
+
restore(initial);
|
|
275
|
+
return { el, restore, select };
|
|
276
|
+
}
|
package/web/views/composer.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { openModelPicker } from "./composer-models.js";
|
|
1
2
|
import { fill, h, icon, ICON, isTouch, toast } from "../lib/dom.js";
|
|
2
3
|
import { api } from "../lib/api.js";
|
|
3
4
|
import { desktop, S, ui } from "../state.js";
|
|
@@ -10,7 +11,7 @@ import { renderTodos } from "./todos.js";
|
|
|
10
11
|
import { cancelVoice, SpeechRec, toggleVoice } from "./voice.js";
|
|
11
12
|
import { callButton, canCall } from "./voice-call.js";
|
|
12
13
|
import { closeSlashMenu, commandUsage, oneLine, slashKeydown, updateSlashMenu } from "./slash.js";
|
|
13
|
-
import { doAction,
|
|
14
|
+
import { doAction, openSessions } from "./conv-actions.js";
|
|
14
15
|
|
|
15
16
|
// ---------- 输入框 ----------
|
|
16
17
|
|
|
@@ -234,11 +235,12 @@ export async function ensureConversation() {
|
|
|
234
235
|
S.draftCwdPicked = false;
|
|
235
236
|
// 新对话里选过模型 / 思考程度:建好会话后先切过去再发消息
|
|
236
237
|
// 权限只对这一条新对话有效,不留给下一条(不放进按专家记住的 draftPick)
|
|
237
|
-
const pick = { ...draftPick(), permission: S.draftPermission, plan: S.draftPlan ? "on" : null };
|
|
238
|
+
const pick = { ...draftPick(), fastModel: S.draftFastModel, permission: S.draftPermission, plan: S.draftPlan ? "on" : null };
|
|
238
239
|
S.draftPermission = null;
|
|
239
240
|
S.draftPlan = false;
|
|
240
|
-
|
|
241
|
-
|
|
241
|
+
S.draftFastModel = null;
|
|
242
|
+
const FAILED = { model: "切换模型", effort: "切换思考程度", fastModel: "开启快速模式", permission: "设置权限", plan: "打开计划模式" };
|
|
243
|
+
for (const [action, value] of [["model", pick.model], ["effort", pick.effort], ["fastModel", pick.fastModel], ["permission", pick.permission], ["plan", pick.plan]]) {
|
|
242
244
|
if (!value) continue;
|
|
243
245
|
try {
|
|
244
246
|
const res = await api(`/api/conversations/${encodeURIComponent(info.key)}/action`, { method: "POST", body: { action, value } });
|
|
@@ -384,7 +386,7 @@ async function showCommandReply(text, reply, info) {
|
|
|
384
386
|
await openSessions(reply.allDirs);
|
|
385
387
|
return;
|
|
386
388
|
case "models":
|
|
387
|
-
await openModelPicker();
|
|
389
|
+
await openModelPicker(head === "effort" ? "effort" : "model", reply);
|
|
388
390
|
return;
|
|
389
391
|
case "agents":
|
|
390
392
|
note(
|
|
@@ -3,7 +3,7 @@ import { api } from "../lib/api.js";
|
|
|
3
3
|
import { relTime } from "../lib/time.js";
|
|
4
4
|
import { S, ui } from "../state.js";
|
|
5
5
|
import { agentLabel, convTitle, forgetProject, renderSidebar } from "./sidebar.js";
|
|
6
|
-
import {
|
|
6
|
+
import { baseName, renderContext, renderTopbar } from "./topbar.js";
|
|
7
7
|
import { closeMenu, confirmDialog, modal, placePopover, showPopover } from "../lib/overlay.js";
|
|
8
8
|
import { newDraft, openConversation, renderEmpty } from "./messages.js";
|
|
9
9
|
import { setDraftExpert } from "./experts.js";
|
|
@@ -12,7 +12,7 @@ import { FULL_WARNING, PERMISSIONS, permissionsUpTo, PLAN_INFO } from "../lib/pe
|
|
|
12
12
|
|
|
13
13
|
// ---------- 会话操作 ----------
|
|
14
14
|
|
|
15
|
-
export async function doAction(action, value, extra = {}) {
|
|
15
|
+
export async function doAction(action, value, extra = {}, { quiet = false } = {}) {
|
|
16
16
|
if (!S.current) return;
|
|
17
17
|
try {
|
|
18
18
|
const res = await api(`/api/conversations/${encodeURIComponent(S.current)}/action`, {
|
|
@@ -21,7 +21,7 @@ export async function doAction(action, value, extra = {}) {
|
|
|
21
21
|
});
|
|
22
22
|
S.convs.set(res.info.key, res.info);
|
|
23
23
|
renderTopbar();
|
|
24
|
-
toast(res.text);
|
|
24
|
+
if (!quiet) toast(res.text);
|
|
25
25
|
if (["new", "fork", "resume", "agent", "cd"].includes(action)) await openConversation(res.info.key);
|
|
26
26
|
return res;
|
|
27
27
|
} catch (err) {
|
|
@@ -78,97 +78,6 @@ export function switchAgent(id) {
|
|
|
78
78
|
renderEmpty();
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
/** 模型 / 思考程度选择:已有会话直接切,新对话先记下,发第一条消息时带过去 */
|
|
82
|
-
export async function openModelPicker(anchor = ui.modelSlot) {
|
|
83
|
-
if (!anchor) return;
|
|
84
|
-
if (ui.menu?.dataset.for === "model") return closeMenu();
|
|
85
|
-
const pop = showPopover(anchor);
|
|
86
|
-
pop.dataset.for = "model";
|
|
87
|
-
pop.classList.add("model-pop");
|
|
88
|
-
fill(pop, h("div", { class: "pop-loading" }, h("span", { class: "spinner" })));
|
|
89
|
-
placePopover(pop, anchor);
|
|
90
|
-
|
|
91
|
-
const conv = S.current ? S.convs.get(S.current) : null;
|
|
92
|
-
let models;
|
|
93
|
-
let current;
|
|
94
|
-
let currentEffort;
|
|
95
|
-
let effortSupported = true;
|
|
96
|
-
try {
|
|
97
|
-
if (conv) {
|
|
98
|
-
// 顺便把这个 agent 的默认模型 / 显示名准备好(缓存过就不会再请求)
|
|
99
|
-
const [data] = await Promise.all([
|
|
100
|
-
api(`/api/conversations/${encodeURIComponent(S.current)}/models`),
|
|
101
|
-
agentCatalog(conv.agent).catch(() => []),
|
|
102
|
-
]);
|
|
103
|
-
({ models, current, currentEffort, effortSupported } = data);
|
|
104
|
-
} else {
|
|
105
|
-
models = await agentCatalog(S.draftAgent);
|
|
106
|
-
const pick = draftPick();
|
|
107
|
-
current = pick.model ?? (models.find((m) => m.isDefault) ?? models.find((m) => m.id === "default"))?.id;
|
|
108
|
-
currentEffort = pick.effort;
|
|
109
|
-
}
|
|
110
|
-
} catch (err) {
|
|
111
|
-
if (ui.menu === pop) fill(pop, h("div", { class: "pop-error" }, err.message));
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
if (ui.menu !== pop) return;
|
|
115
|
-
|
|
116
|
-
const choose = async (kind, value) => {
|
|
117
|
-
if (kind === "model") current = value;
|
|
118
|
-
else currentEffort = value;
|
|
119
|
-
if (conv) {
|
|
120
|
-
await doAction(kind, value);
|
|
121
|
-
} else {
|
|
122
|
-
draftPick()[kind] = value;
|
|
123
|
-
saveDraftPick();
|
|
124
|
-
renderContext();
|
|
125
|
-
}
|
|
126
|
-
if (kind === "effort") closeMenu();
|
|
127
|
-
else if (ui.menu === pop) render();
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const agent = conv ? conv.agent : S.draftAgent;
|
|
131
|
-
// 当前值可能是别名、完整名或空(默认):先按 id 对,对不上再按显示名对,只勾一项
|
|
132
|
-
const currentItem = (list) => {
|
|
133
|
-
const byId = list.find((m) => m.id === current);
|
|
134
|
-
if (byId) return byId;
|
|
135
|
-
const name = modelName(agent, current);
|
|
136
|
-
return list.find((m) => m.id !== "default" && (m.label || m.id) === name) ?? null;
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
function render() {
|
|
140
|
-
const shown = visibleModels(agent, models);
|
|
141
|
-
const on = currentItem(shown);
|
|
142
|
-
const efforts = (on ?? currentItem(models))?.efforts ?? models.find((m) => m.efforts?.length)?.efforts ?? [];
|
|
143
|
-
if (!currentEffort) currentEffort = catalogDefaults.get(agent)?.effort;
|
|
144
|
-
fill(
|
|
145
|
-
pop,
|
|
146
|
-
h("div", { class: "pop-head" }, "模型"),
|
|
147
|
-
shown.map((m) =>
|
|
148
|
-
h(
|
|
149
|
-
"button",
|
|
150
|
-
{ class: `pop-item${m === on ? " on" : ""}`, onclick: () => void choose("model", m.id) },
|
|
151
|
-
h("span", { class: "grow" }, h("span", { class: "t" }, m.label || m.id), m.description ? h("span", { class: "s" }, m.description) : null),
|
|
152
|
-
m === on ? h("span", { class: "check" }, "✓") : null,
|
|
153
|
-
),
|
|
154
|
-
),
|
|
155
|
-
effortSupported && efforts.length
|
|
156
|
-
? [
|
|
157
|
-
h("div", { class: "sep" }),
|
|
158
|
-
h("div", { class: "pop-head" }, "思考程度"),
|
|
159
|
-
h(
|
|
160
|
-
"div",
|
|
161
|
-
{ class: "effort-seg" },
|
|
162
|
-
efforts.map((e) => h("button", { class: e === currentEffort ? "on" : "", onclick: () => void choose("effort", e) }, e)),
|
|
163
|
-
),
|
|
164
|
-
]
|
|
165
|
-
: null,
|
|
166
|
-
);
|
|
167
|
-
placePopover(pop, anchor);
|
|
168
|
-
}
|
|
169
|
-
render();
|
|
170
|
-
}
|
|
171
|
-
|
|
172
81
|
/**
|
|
173
82
|
* 权限级别 + 计划模式开关:已有对话直接切,新对话先记下,建好对话后带过去。
|
|
174
83
|
* max、current、agent、plan 由输入框上的按钮算好传进来(自动判断只有 Claude 有)
|
package/web/views/experts.js
CHANGED
package/web/views/messages.js
CHANGED
package/web/views/topbar.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { openModelPicker } from "./composer-models.js";
|
|
1
2
|
import { fill, h, icon, ICON, toast } from "../lib/dom.js";
|
|
2
3
|
import { api } from "../lib/api.js";
|
|
3
4
|
import { relTime } from "../lib/time.js";
|
|
@@ -7,7 +8,7 @@ import { convExpert, expertChoices, expertIcon, findExpert } from "./experts.js"
|
|
|
7
8
|
import { closeMenu, modal, placePopover, showMenu, showPopover, submenuButton } from "../lib/overlay.js";
|
|
8
9
|
import { openConversation } from "./messages.js";
|
|
9
10
|
import { openSchedule } from "./schedule.js";
|
|
10
|
-
import { changeCwd, deleteConv, doAction, forkConversation, handoffConversation,
|
|
11
|
+
import { changeCwd, deleteConv, doAction, forkConversation, handoffConversation, openPermissionPicker, renameConv, switchAgent } from "./conv-actions.js";
|
|
11
12
|
import { capOfAccess, defaultPermissionFor, minPermission, permissionsUpTo, PERMISSIONS } from "../lib/permission.js";
|
|
12
13
|
import { canSeeChanges, syncWorkspace, toggleWorkspace, workspaceButtons, workspaceStats } from "./workspace-entry.js";
|
|
13
14
|
import { syncCall } from "./voice-call.js";
|
|
@@ -374,6 +375,14 @@ export function modelName(agent, id) {
|
|
|
374
375
|
return id;
|
|
375
376
|
}
|
|
376
377
|
|
|
378
|
+
const effortLabels = new Map(Object.entries({
|
|
379
|
+
off: "关闭", none: "无", minimal: "最低", low: "低", medium: "中", high: "高", xhigh: "超高", max: "最大", ultra: "极高",
|
|
380
|
+
}));
|
|
381
|
+
export const effortLabel = (value) => effortLabels.get(value) ?? value;
|
|
382
|
+
|
|
383
|
+
export const composerModelLabel = (agent, name) => agent === "codex"
|
|
384
|
+
? name.replace(/^(gpt-[\d.]+)-(sol|astra|terra|luna)$/i, "$1 $2") : name;
|
|
385
|
+
|
|
377
386
|
/** 输入框上方的上下文条(目录 / agent)和输入框里的模型按钮 */
|
|
378
387
|
export function renderContext() {
|
|
379
388
|
if (!ui.ctxBar) return;
|
|
@@ -402,6 +411,7 @@ export function renderContext() {
|
|
|
402
411
|
// 直接显示实际的模型名和思考程度(和选择列表里一样的写法),不显示「默认模型」
|
|
403
412
|
let model;
|
|
404
413
|
let effort;
|
|
414
|
+
let fastOn = false;
|
|
405
415
|
const modelAgent = c ? c.agent : S.draftAgent;
|
|
406
416
|
if (modelAgent) {
|
|
407
417
|
ensureCatalog(modelAgent);
|
|
@@ -410,9 +420,16 @@ export function renderContext() {
|
|
|
410
420
|
// 新对话:没选过就是专家配的默认模型
|
|
411
421
|
const draft = c ? null : findExpert(S.draftExpert);
|
|
412
422
|
const id = c ? (c.runtimeModel ?? c.model) : (pick.model ?? (draft?.model || undefined));
|
|
423
|
+
const effectiveId = id || defaults.model || catalogLoaded.get(modelAgent)?.find((m) => m.isDefault)?.id;
|
|
424
|
+
const fastModel = c ? c.fastModel : S.draftFastModel;
|
|
425
|
+
fastOn = !!fastModel && fastModel === effectiveId;
|
|
413
426
|
model = modelName(modelAgent, id) ?? (catalogLoaded.has(modelAgent) ? "选择模型" : "…");
|
|
414
|
-
|
|
427
|
+
const selected = catalogLoaded.get(modelAgent)?.find((m) => m.id === effectiveId);
|
|
428
|
+
effort = (c ? (c.runtimeEffort ?? c.effort) : (pick.effort ?? (draft?.effort || undefined))) ?? defaults.effort ?? selected?.defaultEffort;
|
|
429
|
+
if (selected && !selected.efforts?.includes(effort)) effort = undefined;
|
|
415
430
|
}
|
|
431
|
+
const picker = ui.menu?.dataset.for === "model" ? ui.menu : null;
|
|
432
|
+
if (picker && !picker.matchesContext()) closeMenu();
|
|
416
433
|
renderCtxRing();
|
|
417
434
|
renderPermission(c, expert);
|
|
418
435
|
fill(
|
|
@@ -420,10 +437,14 @@ export function renderContext() {
|
|
|
420
437
|
model
|
|
421
438
|
? h(
|
|
422
439
|
"button",
|
|
423
|
-
{
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
440
|
+
{
|
|
441
|
+
class: "model-pill", title: "切换模型和思考程度", "aria-haspopup": "dialog",
|
|
442
|
+
"aria-expanded": String(ui.menu?.dataset.for === "model"), onclick: () => void openModelPicker(),
|
|
443
|
+
},
|
|
444
|
+
fastOn ? h("span", { class: "fast-mark", role: "img", "aria-label": "快速模式已开启" }, icon("bolt")) : null,
|
|
445
|
+
h("span", { class: "model-name" }, composerModelLabel(modelAgent, model)),
|
|
446
|
+
effort ? h("span", { class: "sub", title: effort }, effortLabel(effort)) : null,
|
|
447
|
+
h("span", { class: "picker-prompt" }, "选择推理强度"),
|
|
427
448
|
)
|
|
428
449
|
: null,
|
|
429
450
|
);
|