minimal-agent 0.18.14 → 0.18.16
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/README.md +2 -2
- package/package.json +1 -1
- package/src/cli/configMenu.js +19 -2
- package/src/cli/configMenu.tsx +25 -2
- package/src/cli/wizards/networkProxyWizard.js +69 -11
- package/src/cli/wizards/networkProxyWizard.tsx +148 -26
- package/src/cli/wizards/providerPresets.js +30 -19
- package/src/cli/wizards/providerPresets.ts +30 -19
- package/src/config/reasoningEffort.js +3 -3
- package/src/config/reasoningEffort.ts +3 -3
- package/src/llm/client.js +7 -4
- package/src/llm/client.ts +6 -3
- package/src/llm/gatewayClient.js +2 -1
- package/src/llm/gatewayClient.ts +2 -1
- package/src/llm/providers/anthropicFormat.js +3 -1
- package/src/llm/providers/anthropicFormat.ts +4 -1
- package/src/llm/providers/responsesFormat.js +3 -1
- package/src/llm/providers/responsesFormat.ts +3 -1
- package/src/main.js +9 -0
- package/src/main.tsx +9 -0
- package/src/network/httpFetch.js +30 -0
- package/src/network/httpFetch.ts +42 -0
- package/src/network/proxy.js +38 -3
- package/src/network/proxy.ts +48 -3
- package/src/network/proxyProbe.js +193 -0
- package/src/network/proxyProbe.ts +244 -0
- package/src/network/proxyRuntime.js +110 -0
- package/src/network/proxyRuntime.ts +117 -0
- package/src/runtime/commandCatalog.js +1 -0
- package/src/runtime/commandCatalog.ts +9 -0
- package/src/types.ts +1 -1
- package/src/ui/App.js +69 -2
- package/src/ui/App.tsx +78 -2
- package/src/ui/configRefresh.js +34 -0
- package/src/ui/configRefresh.ts +62 -0
- package/src/ui/effortCommand.js +19 -0
- package/src/ui/effortCommand.ts +36 -0
- package/src/web/protocol.ts +1 -1
package/src/ui/App.tsx
CHANGED
|
@@ -56,6 +56,13 @@ import { InputBox } from './InputBox.js';
|
|
|
56
56
|
import { LiveArea } from './LiveArea.js';
|
|
57
57
|
import { MessageList } from './MessageList.js';
|
|
58
58
|
import { ModelPicker } from './ModelPicker.js';
|
|
59
|
+
import { effortChoicesText, parseEffortCommand } from './effortCommand.js';
|
|
60
|
+
import {
|
|
61
|
+
carrySessionEffort,
|
|
62
|
+
modelIdToReload,
|
|
63
|
+
snapshotForConfig,
|
|
64
|
+
type ConfigOpenSnapshot,
|
|
65
|
+
} from './configRefresh.js';
|
|
59
66
|
import type { PickerModel } from './ModelPicker.js';
|
|
60
67
|
import { QueuedMessagesBanner } from './QueuedMessagesBanner.js';
|
|
61
68
|
import { SessionPicker } from './SessionPicker.js';
|
|
@@ -211,6 +218,8 @@ export function App({ provider, initialHistory }: Props): JSX.Element {
|
|
|
211
218
|
|
|
212
219
|
// /config —— 硬编码菜单覆盖层,纯本地 UI 态(与 sessionPicker 同构)。
|
|
213
220
|
const [configMenuOpen, setConfigMenuOpen] = React.useState(false);
|
|
221
|
+
// 打开 /config 时会话跑在哪条模型配置上;关闭时据此让运行中的 provider 跟上配置
|
|
222
|
+
const configOpenRef = React.useRef<ConfigOpenSnapshot | null>(null);
|
|
214
223
|
|
|
215
224
|
// /model —— 基座模型选择器;/advisor select —— 顾问模型选择器
|
|
216
225
|
const [baseModelPicker, setBaseModelPicker] = React.useState<{
|
|
@@ -356,6 +365,48 @@ export function App({ provider, initialHistory }: Props): JSX.Element {
|
|
|
356
365
|
],
|
|
357
366
|
);
|
|
358
367
|
|
|
368
|
+
/**
|
|
369
|
+
* /config 关闭后:状态栏的模型名/上下文大小/压缩阈值都读 providerRef,不刷新就一直是
|
|
370
|
+
* 打开前的旧值(把上下文改到 512K,状态栏仍是 204.8K)。重新解析会话所用的那条配置,
|
|
371
|
+
* 上下文变小时先用旧 provider 压缩一次(与 /model 同规则),再切换。
|
|
372
|
+
*/
|
|
373
|
+
const handleConfigDone = React.useCallback(async () => {
|
|
374
|
+
setConfigMenuOpen(false);
|
|
375
|
+
const open = configOpenRef.current;
|
|
376
|
+
configOpenRef.current = null;
|
|
377
|
+
if (!open) return;
|
|
378
|
+
const { config } = await configService.getSnapshot();
|
|
379
|
+
const targetId = modelIdToReload(open, config);
|
|
380
|
+
if (!targetId) return;
|
|
381
|
+
const resolved = await configService.providerForModel(targetId);
|
|
382
|
+
if (!resolved) return;
|
|
383
|
+
const current = chat.getCurrentProvider();
|
|
384
|
+
const next = carrySessionEffort(current, open, resolved);
|
|
385
|
+
const unchanged = JSON.stringify(current) === JSON.stringify(next);
|
|
386
|
+
if (unchanged) return;
|
|
387
|
+
if (config?.baseModelId !== open.baseModelId) {
|
|
388
|
+
await updateSessionMetadata(getWorkingDir(), chat.activeSessionId, {
|
|
389
|
+
modelId: null,
|
|
390
|
+
preferredModel: { source: 'local', modelId: targetId },
|
|
391
|
+
effectiveModel: { source: 'local', modelId: targetId },
|
|
392
|
+
fallbackReason: undefined,
|
|
393
|
+
restoreWhenAvailable: false,
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
await compactBeforeShrinkingContext(next);
|
|
397
|
+
chat.setProvider(next);
|
|
398
|
+
forceRerender((v) => v + 1);
|
|
399
|
+
chat.ephemeralLine(
|
|
400
|
+
`[/config] 当前 Session 已采用新配置:${next.name}(上下文 ${next.contextWindow}),下一轮对话生效。`,
|
|
401
|
+
);
|
|
402
|
+
}, [
|
|
403
|
+
chat.getCurrentProvider,
|
|
404
|
+
chat.setProvider,
|
|
405
|
+
chat.activeSessionId,
|
|
406
|
+
chat.ephemeralLine,
|
|
407
|
+
compactBeforeShrinkingContext,
|
|
408
|
+
]);
|
|
409
|
+
|
|
359
410
|
React.useEffect(() => {
|
|
360
411
|
let cancelled = false;
|
|
361
412
|
void listSessionSummaries(getWorkingDir())
|
|
@@ -1013,6 +1064,29 @@ export function App({ provider, initialHistory }: Props): JSX.Element {
|
|
|
1013
1064
|
}
|
|
1014
1065
|
}
|
|
1015
1066
|
|
|
1067
|
+
// /effort [档位|auto] —— 只改当前 Session 的推理强度(不写回配置,与 /model 同语义)。
|
|
1068
|
+
const effortCommand = parseEffortCommand(trimmed);
|
|
1069
|
+
if (effortCommand.matched) {
|
|
1070
|
+
const current = chat.getCurrentProvider();
|
|
1071
|
+
if (effortCommand.action === 'show') {
|
|
1072
|
+
chat.ephemeralLine(
|
|
1073
|
+
`[/effort] 当前 ${current.model} 的推理强度:${current.reasoningEffort ?? '未设置(服务端默认)'}\n` +
|
|
1074
|
+
` 用法:/effort <${effortChoicesText()}>;各模型接受的档位不同,不被接受时会自动去掉该参数并告警。`,
|
|
1075
|
+
);
|
|
1076
|
+
} else if (effortCommand.action === 'invalid') {
|
|
1077
|
+
chat.ephemeralLine(`[/effort] 不认识 "${effortCommand.input}",可选:${effortChoicesText()}`);
|
|
1078
|
+
} else {
|
|
1079
|
+
const { reasoningEffort: _previous, ...rest } = current;
|
|
1080
|
+
chat.setProvider(
|
|
1081
|
+
effortCommand.effort ? { ...rest, reasoningEffort: effortCommand.effort } : rest,
|
|
1082
|
+
);
|
|
1083
|
+
chat.ephemeralLine(
|
|
1084
|
+
`[/effort] 当前 Session 的推理强度已设为 ${effortCommand.effort ?? '未设置(服务端默认)'},下一轮对话生效。`,
|
|
1085
|
+
);
|
|
1086
|
+
}
|
|
1087
|
+
return;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1016
1090
|
const modelArgMatch = /^\/model(?:\s+(.+))?$/.exec(trimmed);
|
|
1017
1091
|
if (modelArgMatch) {
|
|
1018
1092
|
const arg = modelArgMatch[1]?.trim();
|
|
@@ -1194,6 +1268,8 @@ export function App({ provider, initialHistory }: Props): JSX.Element {
|
|
|
1194
1268
|
// 精确匹配,不接受多余文字(与 /advisor 等硬拦截命令同规则)。仅交互式 TUI
|
|
1195
1269
|
// 支持;-p 非交互模式没有 Ink 树可渲染菜单,此命令在那里就是普通聊天文本。
|
|
1196
1270
|
if (trimmed === '/config') {
|
|
1271
|
+
const { config } = await configService.getSnapshot();
|
|
1272
|
+
configOpenRef.current = snapshotForConfig(chat.getCurrentProvider(), config);
|
|
1197
1273
|
setConfigMenuOpen(true);
|
|
1198
1274
|
return;
|
|
1199
1275
|
}
|
|
@@ -1232,7 +1308,7 @@ export function App({ provider, initialHistory }: Props): JSX.Element {
|
|
|
1232
1308
|
const draftKey = `${getWorkingDir()}\0${chat.activeSessionId}`;
|
|
1233
1309
|
if (!drafts.current.has(draftKey)) drafts.current.set(draftKey, { current: { text: '', cursor: 0 } });
|
|
1234
1310
|
const advisorLabel = !advisorStatus.configured ? '未配置' : !advisorStatus.enabled ? '已关闭' : advisorStatus.mode === 'manual' ? '仅手动' : '自动启用';
|
|
1235
|
-
const bannerText = `minimal-agent · ${currentProvider.name}/${currentProvider.model} · /model 切模型 · /computer 控制桌面 · /copy 复制回复 · /paste-image 添加图片 · /new 清空 · /compact 压缩 · Ctrl+C 中断`;
|
|
1311
|
+
const bannerText = `minimal-agent · ${currentProvider.name}/${currentProvider.model} · /model 切模型 · /effort 思考强度 · /computer 控制桌面 · /copy 复制回复 · /paste-image 添加图片 · /new 清空 · /compact 压缩 · Ctrl+C 中断`;
|
|
1236
1312
|
|
|
1237
1313
|
return (
|
|
1238
1314
|
<Box flexDirection="column">
|
|
@@ -1318,7 +1394,7 @@ export function App({ provider, initialHistory }: Props): JSX.Element {
|
|
|
1318
1394
|
{configMenuOpen ? (
|
|
1319
1395
|
<ConfigMenu
|
|
1320
1396
|
mode="reconfigure"
|
|
1321
|
-
onDone={() =>
|
|
1397
|
+
onDone={() => void handleConfigDone()}
|
|
1322
1398
|
/>
|
|
1323
1399
|
) : baseModelPicker ? (
|
|
1324
1400
|
<ModelPicker
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function snapshotForConfig(current, config) {
|
|
2
|
+
const entry = current.source === 'gateway'
|
|
3
|
+
? undefined
|
|
4
|
+
: config?.models.find((m) => m.baseURL === current.baseURL && m.model === current.model);
|
|
5
|
+
return {
|
|
6
|
+
modelId: entry?.id ?? null,
|
|
7
|
+
baseModelId: config?.baseModelId ?? null,
|
|
8
|
+
...(entry?.reasoningEffort ? { configEffort: entry.reasoningEffort } : {}),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/** 关闭 /config 后应重新解析的模型 id;null = 不动当前 provider。 */
|
|
12
|
+
export function modelIdToReload(open, config) {
|
|
13
|
+
if (!config)
|
|
14
|
+
return null;
|
|
15
|
+
// 用户在 /config 里换了基座:会话跟随(这是他刚做的明确选择)。
|
|
16
|
+
if (config.baseModelId !== open.baseModelId)
|
|
17
|
+
return config.baseModelId ?? null;
|
|
18
|
+
if (!open.modelId)
|
|
19
|
+
return null;
|
|
20
|
+
if (config.models.some((m) => m.id === open.modelId))
|
|
21
|
+
return open.modelId;
|
|
22
|
+
return config.baseModelId ?? null; // 会话用的模型被删了 → 退回基座
|
|
23
|
+
}
|
|
24
|
+
/** 配置里的推理强度没动过时,保留会话里 /effort 设的值;改了就以配置为准。 */
|
|
25
|
+
export function carrySessionEffort(current, open, next) {
|
|
26
|
+
const configUnchanged = open.configEffort === next.reasoningEffort;
|
|
27
|
+
const sessionDiffers = current.reasoningEffort !== open.configEffort;
|
|
28
|
+
if (!configUnchanged || !sessionDiffers)
|
|
29
|
+
return next;
|
|
30
|
+
const { reasoningEffort: _dropped, ...rest } = next;
|
|
31
|
+
return (current.reasoningEffort
|
|
32
|
+
? { ...rest, reasoningEffort: current.reasoningEffort }
|
|
33
|
+
: rest);
|
|
34
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* /config 关闭后让正在运行的会话跟上配置(纯逻辑,便于测试)。
|
|
3
|
+
*
|
|
4
|
+
* 状态栏的模型名、上下文大小、压缩阈值都读 useChat 的 providerRef,而它只在启动和
|
|
5
|
+
* /model、/effort 时更新——在 /config 里改了上下文窗口,运行中的会话仍用旧值。
|
|
6
|
+
* 流程:打开 /config 时 snapshotForConfig 记下"会话跑在哪条模型配置上",关闭时
|
|
7
|
+
* modelIdToReload 决定重新解析哪条,carrySessionEffort 保住 /effort 的会话级覆盖。
|
|
8
|
+
*/
|
|
9
|
+
import type { MinimalAgentConfig } from '../config/configFile.js';
|
|
10
|
+
import type { ReasoningEffort } from '../config/reasoningEffort.js';
|
|
11
|
+
import type { Provider } from '../types.js';
|
|
12
|
+
|
|
13
|
+
export interface ConfigOpenSnapshot {
|
|
14
|
+
/** 会话当前所用的本机模型配置 id;在线模型或匹配不上时为 null。 */
|
|
15
|
+
modelId: string | null;
|
|
16
|
+
baseModelId: string | null;
|
|
17
|
+
/** 该配置条目里写的推理强度(用来区分「会话级 /effort 覆盖」与「配置值」)。 */
|
|
18
|
+
configEffort?: ReasoningEffort;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function snapshotForConfig(
|
|
22
|
+
current: Provider,
|
|
23
|
+
config: MinimalAgentConfig | null,
|
|
24
|
+
): ConfigOpenSnapshot {
|
|
25
|
+
const entry =
|
|
26
|
+
current.source === 'gateway'
|
|
27
|
+
? undefined
|
|
28
|
+
: config?.models.find((m) => m.baseURL === current.baseURL && m.model === current.model);
|
|
29
|
+
return {
|
|
30
|
+
modelId: entry?.id ?? null,
|
|
31
|
+
baseModelId: config?.baseModelId ?? null,
|
|
32
|
+
...(entry?.reasoningEffort ? { configEffort: entry.reasoningEffort } : {}),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** 关闭 /config 后应重新解析的模型 id;null = 不动当前 provider。 */
|
|
37
|
+
export function modelIdToReload(
|
|
38
|
+
open: ConfigOpenSnapshot,
|
|
39
|
+
config: MinimalAgentConfig | null,
|
|
40
|
+
): string | null {
|
|
41
|
+
if (!config) return null;
|
|
42
|
+
// 用户在 /config 里换了基座:会话跟随(这是他刚做的明确选择)。
|
|
43
|
+
if (config.baseModelId !== open.baseModelId) return config.baseModelId ?? null;
|
|
44
|
+
if (!open.modelId) return null;
|
|
45
|
+
if (config.models.some((m) => m.id === open.modelId)) return open.modelId;
|
|
46
|
+
return config.baseModelId ?? null; // 会话用的模型被删了 → 退回基座
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 配置里的推理强度没动过时,保留会话里 /effort 设的值;改了就以配置为准。 */
|
|
50
|
+
export function carrySessionEffort(
|
|
51
|
+
current: Provider,
|
|
52
|
+
open: ConfigOpenSnapshot,
|
|
53
|
+
next: Provider,
|
|
54
|
+
): Provider {
|
|
55
|
+
const configUnchanged = open.configEffort === next.reasoningEffort;
|
|
56
|
+
const sessionDiffers = current.reasoningEffort !== open.configEffort;
|
|
57
|
+
if (!configUnchanged || !sessionDiffers) return next;
|
|
58
|
+
const { reasoningEffort: _dropped, ...rest } = next;
|
|
59
|
+
return (current.reasoningEffort
|
|
60
|
+
? { ...rest, reasoningEffort: current.reasoningEffort }
|
|
61
|
+
: rest) as Provider;
|
|
62
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { REASONING_EFFORTS } from '../config/reasoningEffort.js';
|
|
2
|
+
const CLEAR_WORDS = new Set(['auto', 'default', 'unset', 'reset']);
|
|
3
|
+
export function parseEffortCommand(input) {
|
|
4
|
+
const match = /^\/effort(?:\s+(\S+))?\s*$/i.exec(input.trim());
|
|
5
|
+
if (!match)
|
|
6
|
+
return { matched: false };
|
|
7
|
+
const arg = match[1]?.toLowerCase();
|
|
8
|
+
if (!arg)
|
|
9
|
+
return { matched: true, action: 'show' };
|
|
10
|
+
if (CLEAR_WORDS.has(arg))
|
|
11
|
+
return { matched: true, action: 'set', effort: null };
|
|
12
|
+
if (REASONING_EFFORTS.includes(arg)) {
|
|
13
|
+
return { matched: true, action: 'set', effort: arg };
|
|
14
|
+
}
|
|
15
|
+
return { matched: true, action: 'invalid', input: arg };
|
|
16
|
+
}
|
|
17
|
+
export function effortChoicesText() {
|
|
18
|
+
return `${REASONING_EFFORTS.join(' / ')} / auto`;
|
|
19
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { REASONING_EFFORTS, type ReasoningEffort } from '../config/reasoningEffort.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `/effort [档位|auto]` 的纯解析(可单测)。只改当前 Session 的运行时 provider,
|
|
5
|
+
* 与 `/model` 同语义:不写回 config.json,进程重启后恢复配置里的值。
|
|
6
|
+
*
|
|
7
|
+
* - `/effort` → 显示当前档位与可选项
|
|
8
|
+
* - `/effort high` → 切到该档位
|
|
9
|
+
* - `/effort auto` → 不再发送该参数,沿用服务端对该模型的默认强度(也认 default / unset / off 以外的别名见下)
|
|
10
|
+
*
|
|
11
|
+
* 档位取值是各家文档出现过的并集,具体某个模型接不接受由服务端裁决:被拒绝时 client.ts
|
|
12
|
+
* 会去掉参数重发并告警,所以这里不替用户猜"这个模型支持哪几档"。
|
|
13
|
+
*/
|
|
14
|
+
export type EffortCommand =
|
|
15
|
+
| { matched: false }
|
|
16
|
+
| { matched: true; action: 'show' }
|
|
17
|
+
| { matched: true; action: 'set'; effort: ReasoningEffort | null }
|
|
18
|
+
| { matched: true; action: 'invalid'; input: string };
|
|
19
|
+
|
|
20
|
+
const CLEAR_WORDS = new Set(['auto', 'default', 'unset', 'reset']);
|
|
21
|
+
|
|
22
|
+
export function parseEffortCommand(input: string): EffortCommand {
|
|
23
|
+
const match = /^\/effort(?:\s+(\S+))?\s*$/i.exec(input.trim());
|
|
24
|
+
if (!match) return { matched: false };
|
|
25
|
+
const arg = match[1]?.toLowerCase();
|
|
26
|
+
if (!arg) return { matched: true, action: 'show' };
|
|
27
|
+
if (CLEAR_WORDS.has(arg)) return { matched: true, action: 'set', effort: null };
|
|
28
|
+
if ((REASONING_EFFORTS as readonly string[]).includes(arg)) {
|
|
29
|
+
return { matched: true, action: 'set', effort: arg as ReasoningEffort };
|
|
30
|
+
}
|
|
31
|
+
return { matched: true, action: 'invalid', input: arg };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function effortChoicesText(): string {
|
|
35
|
+
return `${REASONING_EFFORTS.join(' / ')} / auto`;
|
|
36
|
+
}
|
package/src/web/protocol.ts
CHANGED
|
@@ -298,7 +298,7 @@ export interface SkillInfo {
|
|
|
298
298
|
export type ApiFormat = 'openai' | 'openai-responses' | 'anthropic';
|
|
299
299
|
|
|
300
300
|
/** 推理强度;缺省 = 不发送,沿用服务端对该模型的默认强度。 */
|
|
301
|
-
export type ReasoningEffort = 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
301
|
+
export type ReasoningEffort = 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
302
302
|
|
|
303
303
|
/** 模型列表的一个条目(脱敏视图——apiKey 只给 configured 布尔位,不下发原文)。 */
|
|
304
304
|
export interface ModelView {
|