minimal-agent 0.18.21 → 0.18.22
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 +16 -3
- package/package.json +1 -1
- package/plugins/workflow-runner/plugin.js +1 -0
- package/plugins/workflow-runner/plugin.ts +1 -0
- package/plugins/workflow-runner/src/index.js +1 -0
- package/plugins/workflow-runner/src/index.ts +2 -0
- package/plugins/workflow-runner/src/runner.js +6 -1
- package/plugins/workflow-runner/src/runner.ts +5 -1
- package/plugins/workflow-runner/src/types.ts +1 -0
- package/plugins/workflow-runner/test/childWorkflow.test.ts +19 -0
- package/src/advisor/README.md +7 -3
- package/src/advisor/advisorNudge.js +3 -3
- package/src/advisor/advisorNudge.ts +3 -3
- package/src/advisor/deliveryReview.js +9 -2
- package/src/advisor/deliveryReview.ts +10 -2
- package/src/cli/args.js +1 -0
- package/src/cli/args.ts +1 -0
- package/src/cli/headlessTurn.js +143 -0
- package/src/cli/headlessTurn.ts +187 -0
- package/src/cli/lifecycle.js +52 -0
- package/src/cli/lifecycle.ts +59 -0
- package/src/cli/print.js +91 -240
- package/src/cli/print.ts +99 -301
- package/src/cli/quickModelSetup.js +3 -0
- package/src/cli/quickModelSetup.tsx +3 -0
- package/src/cli/streamJson.js +244 -334
- package/src/cli/streamJson.ts +248 -416
- package/src/cli/wizards/providerPresets.js +25 -14
- package/src/cli/wizards/providerPresets.ts +25 -14
- package/src/cli/wizards/providerWizard.js +29 -11
- package/src/cli/wizards/providerWizard.tsx +29 -11
- package/src/config/configDiagnostics.js +7 -3
- package/src/config/configDiagnostics.ts +6 -3
- package/src/context/compact.js +40 -10
- package/src/context/compact.ts +51 -12
- package/src/context/compactResources.js +39 -0
- package/src/context/compactResources.ts +35 -0
- package/src/context/manualCompact.js +20 -0
- package/src/context/manualCompact.ts +28 -0
- package/src/llm/client.js +4 -0
- package/src/llm/client.ts +4 -0
- package/src/llm/messageProvenance.js +1 -1
- package/src/llm/messageProvenance.ts +1 -1
- package/src/loop/deliveryIntent.js +3 -2
- package/src/loop/deliveryIntent.ts +4 -2
- package/src/loop/messages.js +1 -0
- package/src/loop/messages.ts +1 -0
- package/src/loop/options.ts +2 -0
- package/src/loop.js +4 -2
- package/src/loop.ts +4 -2
- package/src/main.js +40 -45
- package/src/main.tsx +33 -52
- package/src/plugins/artifactDelivery.js +76 -0
- package/src/plugins/artifactDelivery.ts +76 -0
- package/src/plugins/pluginApi.ts +2 -0
- package/src/plugins/pluginRunner.js +2 -0
- package/src/plugins/pluginRunner.ts +3 -0
- package/src/prompts/delegation.js +1 -1
- package/src/prompts/delegation.ts +1 -1
- package/src/prompts/policyRegistry.js +7 -6
- package/src/prompts/policyRegistry.ts +7 -6
- package/src/prompts/promptAssembly.js +2 -2
- package/src/prompts/promptAssembly.ts +2 -2
- package/src/runtime/requestIntent.js +86 -0
- package/src/runtime/requestIntent.ts +66 -0
- package/src/runtime/systemEvents.js +10 -1
- package/src/runtime/systemEvents.ts +9 -1
- package/src/session/commandTranscript.js +76 -0
- package/src/session/commandTranscript.ts +77 -0
- package/src/session/runTurn.js +24 -3
- package/src/session/runTurn.ts +24 -3
- package/src/tools/advisor/advisor.js +1 -1
- package/src/tools/advisor/advisor.ts +1 -1
- package/src/tools/advisor/advisorCoordination.js +3 -2
- package/src/tools/advisor/advisorCoordination.ts +3 -2
- package/src/tools/advisor/advisorDescription.js +1 -1
- package/src/tools/advisor/advisorDescription.ts +1 -1
- package/src/tools/agent/README.md +2 -0
- package/src/tools/agent/agent.js +3 -0
- package/src/tools/agent/agent.ts +3 -0
- package/src/tools/agent/agentHandoff.js +2 -1
- package/src/tools/agent/agentHandoff.ts +2 -1
- package/src/tools/agent/agentTaskService.js +26 -5
- package/src/tools/agent/agentTaskService.ts +23 -5
- package/src/tools/agent/agentTypes.js +1 -1
- package/src/tools/agent/agentTypes.ts +1 -1
- package/src/tools/applypatch/applyPatch.js +39 -13
- package/src/tools/applypatch/applyPatch.ts +35 -15
- package/src/tools/bash/bash.js +3 -0
- package/src/tools/bash/bash.ts +3 -0
- package/src/tools/download/download.js +147 -11
- package/src/tools/download/download.ts +193 -17
- package/src/tools/edit/edit.js +4 -4
- package/src/tools/edit/edit.ts +4 -4
- package/src/tools/edit/multi-edit.js +2 -2
- package/src/tools/edit/multi-edit.ts +2 -2
- package/src/tools/powershell/powershell.js +2 -0
- package/src/tools/powershell/powershell.ts +2 -0
- package/src/tools/shared/fileUtils.js +16 -6
- package/src/tools/shared/fileUtils.ts +15 -6
- package/src/tools/tasks/backgroundTaskService.js +108 -12
- package/src/tools/tasks/backgroundTaskService.ts +106 -14
- package/src/tools/tasks/taskOutput.js +15 -5
- package/src/tools/tasks/taskOutput.ts +13 -5
- package/src/tools/tasks/taskStop.js +2 -2
- package/src/tools/tasks/taskStop.ts +2 -2
- package/src/tools/toolPromptGuides.js +3 -3
- package/src/tools/toolPromptGuides.ts +3 -3
- package/src/tools/webfetch/webfetch.js +1 -1
- package/src/tools/webfetch/webfetch.ts +1 -1
- package/src/types.ts +4 -0
- package/src/ui/InputBox.js +2 -2
- package/src/ui/InputBox.tsx +2 -2
- package/src/ui/MessageList.js +2 -0
- package/src/ui/MessageList.tsx +2 -0
- package/src/ui/README.md +8 -2
- package/src/ui/activityPresentation.js +22 -2
- package/src/ui/activityPresentation.ts +21 -2
- package/src/ui/backgroundWake.js +20 -4
- package/src/ui/backgroundWake.ts +19 -4
- package/src/ui/commandTranscript.js +2 -69
- package/src/ui/commandTranscript.ts +2 -71
- package/src/ui/hooks/useChat.js +41 -25
- package/src/ui/hooks/useChat.ts +30 -23
- package/src/web/protocol.ts +3 -2
- package/src/cli/wizards/advisorWizard.js +0 -152
- package/src/cli/wizards/advisorWizard.tsx +0 -203
|
@@ -27,30 +27,38 @@ export const PRESETS = [
|
|
|
27
27
|
// model 字段大小写严格匹配('glm-5.3' 而非 'GLM-5.3')。
|
|
28
28
|
// ⚠️ 必须是 /api/coding/v3/(Coding Plan 折扣路由),不是 /api/v3/
|
|
29
29
|
// (官网原价路由)——控制台原文明确警告后者「会产生额外费用」。
|
|
30
|
-
// 2026-
|
|
31
|
-
// doubao-seed-code/glm-5.1/minimax-latest/deepseek-v3.2/kimi-k2.6)。
|
|
30
|
+
// 2026-11-20 按官方快速开始刷新;Auto 只能在控制台设置,ID 使用 ark-code-latest。
|
|
32
31
|
name: 'volces',
|
|
33
32
|
label: '火山方舟 Coding Plan (ARK)',
|
|
34
33
|
baseURL: 'https://ark.cn-beijing.volces.com/api/coding/v3/chat/completions',
|
|
35
34
|
models: [
|
|
36
|
-
'
|
|
35
|
+
'ark-code-latest',
|
|
37
36
|
'doubao-seed-evolving',
|
|
38
|
-
'doubao-seed-2.1-
|
|
39
|
-
'doubao-seed-2.
|
|
37
|
+
'doubao-seed-2.1-pro',
|
|
38
|
+
'doubao-seed-2.1-lite',
|
|
39
|
+
'doubao-seed-2.0-mini',
|
|
40
40
|
'glm-5.3-flash',
|
|
41
41
|
'glm-5.3',
|
|
42
42
|
'deepseek-v4-pro',
|
|
43
43
|
'deepseek-v4-flash',
|
|
44
|
-
'
|
|
45
|
-
'
|
|
44
|
+
'deepseek-v4.1-flash',
|
|
45
|
+
'deepseek-v4.1-flash-economy',
|
|
46
|
+
'kimi-k2.8-preview',
|
|
47
|
+
'kimi-k3',
|
|
48
|
+
'kimi-k3.1-pro',
|
|
46
49
|
],
|
|
47
50
|
contextWindow: 204_800,
|
|
48
51
|
modelContextWindows: {
|
|
49
|
-
//
|
|
52
|
+
// 使用保守的 1M 值(官方不同工具示例分别使用 1024000/1048576)。
|
|
50
53
|
'doubao-seed-evolving': 1_000_000,
|
|
51
54
|
'glm-5.3': 1_000_000,
|
|
52
55
|
'deepseek-v4-pro': 1_000_000,
|
|
53
|
-
'
|
|
56
|
+
'deepseek-v4-flash': 1_000_000,
|
|
57
|
+
'deepseek-v4.1-flash': 1_000_000,
|
|
58
|
+
'deepseek-v4.1-flash-economy': 1_000_000,
|
|
59
|
+
'glm-5.3-flash': 1_000_000,
|
|
60
|
+
'kimi-k2.8-preview': 1_000_000,
|
|
61
|
+
'kimi-k3.1-pro': 1_000_000,
|
|
54
62
|
},
|
|
55
63
|
},
|
|
56
64
|
{
|
|
@@ -78,7 +86,7 @@ export const PRESETS = [
|
|
|
78
86
|
name: 'openai-responses',
|
|
79
87
|
label: 'OpenAI(Responses API,推荐)',
|
|
80
88
|
baseURL: 'https://api.openai.com/v1/responses',
|
|
81
|
-
models: ['gpt-6.
|
|
89
|
+
models: ['gpt-6.2-sol', 'gpt-6.2-astra', 'gpt-6.1-terra', 'gpt-6-luna'],
|
|
82
90
|
contextWindow: 1_050_000,
|
|
83
91
|
apiFormat: 'openai-responses',
|
|
84
92
|
supportsReasoningEffort: true,
|
|
@@ -89,7 +97,8 @@ export const PRESETS = [
|
|
|
89
97
|
name: 'openai',
|
|
90
98
|
label: 'OpenAI(Chat Completions)',
|
|
91
99
|
baseURL: 'https://api.openai.com/v1/chat/completions',
|
|
92
|
-
|
|
100
|
+
// 6.2 的工具调用要求 Responses,不放进 Chat Completions Agent 预设。
|
|
101
|
+
models: ['gpt-6.1-terra', 'gpt-6.1-sol'],
|
|
93
102
|
contextWindow: 1_050_000,
|
|
94
103
|
supportsReasoningEffort: true,
|
|
95
104
|
},
|
|
@@ -97,12 +106,14 @@ export const PRESETS = [
|
|
|
97
106
|
name: 'openrouter',
|
|
98
107
|
label: 'OpenRouter',
|
|
99
108
|
baseURL: 'https://openrouter.ai/api/v1/chat/completions',
|
|
100
|
-
// 2026-
|
|
109
|
+
// 2026-11-20 核对 OpenRouter /api/v1/models;聚合服务的工具协议以其目录为准。
|
|
101
110
|
models: [
|
|
102
|
-
'openai/gpt-6.
|
|
111
|
+
'openai/gpt-6.2-sol',
|
|
112
|
+
'openai/gpt-6.2-astra',
|
|
113
|
+
'anthropic/claude-fable-5.2',
|
|
103
114
|
'anthropic/claude-sonnet-5.5',
|
|
104
115
|
'anthropic/claude-opus-5.5',
|
|
105
|
-
'google/gemini-
|
|
116
|
+
'google/gemini-4-neon',
|
|
106
117
|
'moonshotai/kimi-k3.1-pro',
|
|
107
118
|
'deepseek/deepseek-v4.1-flash',
|
|
108
119
|
'minimax/minimax-m3.1-flash',
|
|
@@ -56,30 +56,38 @@ export const PRESETS: ProviderPreset[] = [
|
|
|
56
56
|
// model 字段大小写严格匹配('glm-5.3' 而非 'GLM-5.3')。
|
|
57
57
|
// ⚠️ 必须是 /api/coding/v3/(Coding Plan 折扣路由),不是 /api/v3/
|
|
58
58
|
// (官网原价路由)——控制台原文明确警告后者「会产生额外费用」。
|
|
59
|
-
// 2026-
|
|
60
|
-
// doubao-seed-code/glm-5.1/minimax-latest/deepseek-v3.2/kimi-k2.6)。
|
|
59
|
+
// 2026-11-20 按官方快速开始刷新;Auto 只能在控制台设置,ID 使用 ark-code-latest。
|
|
61
60
|
name: 'volces',
|
|
62
61
|
label: '火山方舟 Coding Plan (ARK)',
|
|
63
62
|
baseURL: 'https://ark.cn-beijing.volces.com/api/coding/v3/chat/completions',
|
|
64
63
|
models: [
|
|
65
|
-
'
|
|
64
|
+
'ark-code-latest',
|
|
66
65
|
'doubao-seed-evolving',
|
|
67
|
-
'doubao-seed-2.1-
|
|
68
|
-
'doubao-seed-2.
|
|
66
|
+
'doubao-seed-2.1-pro',
|
|
67
|
+
'doubao-seed-2.1-lite',
|
|
68
|
+
'doubao-seed-2.0-mini',
|
|
69
69
|
'glm-5.3-flash',
|
|
70
70
|
'glm-5.3',
|
|
71
71
|
'deepseek-v4-pro',
|
|
72
72
|
'deepseek-v4-flash',
|
|
73
|
-
'
|
|
74
|
-
'
|
|
73
|
+
'deepseek-v4.1-flash',
|
|
74
|
+
'deepseek-v4.1-flash-economy',
|
|
75
|
+
'kimi-k2.8-preview',
|
|
76
|
+
'kimi-k3',
|
|
77
|
+
'kimi-k3.1-pro',
|
|
75
78
|
],
|
|
76
79
|
contextWindow: 204_800,
|
|
77
80
|
modelContextWindows: {
|
|
78
|
-
//
|
|
81
|
+
// 使用保守的 1M 值(官方不同工具示例分别使用 1024000/1048576)。
|
|
79
82
|
'doubao-seed-evolving': 1_000_000,
|
|
80
83
|
'glm-5.3': 1_000_000,
|
|
81
84
|
'deepseek-v4-pro': 1_000_000,
|
|
82
|
-
'
|
|
85
|
+
'deepseek-v4-flash': 1_000_000,
|
|
86
|
+
'deepseek-v4.1-flash': 1_000_000,
|
|
87
|
+
'deepseek-v4.1-flash-economy': 1_000_000,
|
|
88
|
+
'glm-5.3-flash': 1_000_000,
|
|
89
|
+
'kimi-k2.8-preview': 1_000_000,
|
|
90
|
+
'kimi-k3.1-pro': 1_000_000,
|
|
83
91
|
},
|
|
84
92
|
},
|
|
85
93
|
{
|
|
@@ -107,7 +115,7 @@ export const PRESETS: ProviderPreset[] = [
|
|
|
107
115
|
name: 'openai-responses',
|
|
108
116
|
label: 'OpenAI(Responses API,推荐)',
|
|
109
117
|
baseURL: 'https://api.openai.com/v1/responses',
|
|
110
|
-
models: ['gpt-6.
|
|
118
|
+
models: ['gpt-6.2-sol', 'gpt-6.2-astra', 'gpt-6.1-terra', 'gpt-6-luna'],
|
|
111
119
|
contextWindow: 1_050_000,
|
|
112
120
|
apiFormat: 'openai-responses',
|
|
113
121
|
supportsReasoningEffort: true,
|
|
@@ -118,7 +126,8 @@ export const PRESETS: ProviderPreset[] = [
|
|
|
118
126
|
name: 'openai',
|
|
119
127
|
label: 'OpenAI(Chat Completions)',
|
|
120
128
|
baseURL: 'https://api.openai.com/v1/chat/completions',
|
|
121
|
-
|
|
129
|
+
// 6.2 的工具调用要求 Responses,不放进 Chat Completions Agent 预设。
|
|
130
|
+
models: ['gpt-6.1-terra', 'gpt-6.1-sol'],
|
|
122
131
|
contextWindow: 1_050_000,
|
|
123
132
|
supportsReasoningEffort: true,
|
|
124
133
|
},
|
|
@@ -126,12 +135,14 @@ export const PRESETS: ProviderPreset[] = [
|
|
|
126
135
|
name: 'openrouter',
|
|
127
136
|
label: 'OpenRouter',
|
|
128
137
|
baseURL: 'https://openrouter.ai/api/v1/chat/completions',
|
|
129
|
-
// 2026-
|
|
138
|
+
// 2026-11-20 核对 OpenRouter /api/v1/models;聚合服务的工具协议以其目录为准。
|
|
130
139
|
models: [
|
|
131
|
-
'openai/gpt-6.
|
|
140
|
+
'openai/gpt-6.2-sol',
|
|
141
|
+
'openai/gpt-6.2-astra',
|
|
142
|
+
'anthropic/claude-fable-5.2',
|
|
132
143
|
'anthropic/claude-sonnet-5.5',
|
|
133
144
|
'anthropic/claude-opus-5.5',
|
|
134
|
-
'google/gemini-
|
|
145
|
+
'google/gemini-4-neon',
|
|
135
146
|
'moonshotai/kimi-k3.1-pro',
|
|
136
147
|
'deepseek/deepseek-v4.1-flash',
|
|
137
148
|
'minimax/minimax-m3.1-flash',
|
|
@@ -11,18 +11,23 @@ const numberValue = (value, fallback) => {
|
|
|
11
11
|
const parsed = Number(String(value ?? '').trim());
|
|
12
12
|
return Number.isFinite(parsed) ? parsed : fallback;
|
|
13
13
|
};
|
|
14
|
-
export function ProviderWizard({ existing, setAsBase = true, quick = false, onDone, onCancel, }) {
|
|
14
|
+
export function ProviderWizard({ existing: original, setAsBase = true, quick = false, onDone, onCancel, }) {
|
|
15
|
+
const initialPresetIndex = original
|
|
16
|
+
? PRESETS.findIndex(item => item.baseURL === original.baseURL)
|
|
17
|
+
: -1;
|
|
15
18
|
const [phase, setPhase] = useState('preset');
|
|
16
19
|
const [advanced, setAdvanced] = useState(false);
|
|
17
20
|
const [presetIndex, setPresetIndex] = useState(() => {
|
|
18
|
-
if (
|
|
19
|
-
const byUrl = PRESETS.findIndex((item) => item.baseURL ===
|
|
21
|
+
if (original) {
|
|
22
|
+
const byUrl = PRESETS.findIndex((item) => item.baseURL === original.baseURL);
|
|
20
23
|
if (byUrl >= 0)
|
|
21
24
|
return byUrl;
|
|
22
25
|
}
|
|
23
|
-
return findPresetIndex(
|
|
26
|
+
return findPresetIndex(original?.displayName);
|
|
24
27
|
});
|
|
25
28
|
const preset = PRESETS[presetIndex];
|
|
29
|
+
// A provider switch must not send the old provider's credential to a new host.
|
|
30
|
+
const existing = presetIndex === (initialPresetIndex >= 0 ? initialPresetIndex : findPresetIndex(original?.displayName)) ? original : undefined;
|
|
26
31
|
useInput((input, key) => {
|
|
27
32
|
if (phase === 'quick-choice') {
|
|
28
33
|
if (key.escape)
|
|
@@ -55,7 +60,7 @@ export function ProviderWizard({ existing, setAsBase = true, quick = false, onDo
|
|
|
55
60
|
// 协议:选了具体服务商就跟服务商走(编辑时换服务商可以顺带换协议);
|
|
56
61
|
// 「自定义」没有预设,沿用已有模型自己的协议,新建时在完整设置里让用户选。
|
|
57
62
|
const presetFormat = preset.name === 'custom' ? existing?.apiFormat : (preset.apiFormat ?? 'openai');
|
|
58
|
-
const askFormat = preset.name === 'custom'
|
|
63
|
+
const askFormat = preset.name === 'custom';
|
|
59
64
|
const knownFormat = presetFormat ?? 'openai';
|
|
60
65
|
// 推理强度是 OpenAI 系模型最常调的一项:快速配置也要问,不藏进高级里。
|
|
61
66
|
const showEffort = knownFormat !== 'anthropic' &&
|
|
@@ -122,7 +127,9 @@ export function ProviderWizard({ existing, setAsBase = true, quick = false, onDo
|
|
|
122
127
|
key: 'contextWindow',
|
|
123
128
|
label: '上下文窗口(Token)',
|
|
124
129
|
type: 'text',
|
|
125
|
-
default: String(defaultContext),
|
|
130
|
+
default: existing ? String(defaultContext) : '',
|
|
131
|
+
optional: true,
|
|
132
|
+
hint: '留空按最终填写的模型 ID 使用预设窗口;自定义模型请确认服务商实际限制。',
|
|
126
133
|
}, {
|
|
127
134
|
key: 'maxTokens',
|
|
128
135
|
label: '单次输出上限(留空使用推荐值)',
|
|
@@ -156,9 +163,18 @@ export function ProviderWizard({ existing, setAsBase = true, quick = false, onDo
|
|
|
156
163
|
const model = String(values.model ?? '').trim();
|
|
157
164
|
if (!baseURL || !apiKey || !model)
|
|
158
165
|
throw new Error('Base URL、API Key 和模型 ID 均不能为空');
|
|
166
|
+
if (original && apiKey === original.apiKey && new URL(baseURL).origin !== new URL(original.baseURL).origin)
|
|
167
|
+
throw new Error('端点已换到其他服务商,请显式填写新服务商的 API Key,不能复用旧凭据');
|
|
168
|
+
for (const key of ['contextWindow', 'maxTokens']) {
|
|
169
|
+
const raw = String(values[key] ?? '').trim();
|
|
170
|
+
if (raw && (!Number.isSafeInteger(Number(raw)) || Number(raw) <= 0))
|
|
171
|
+
throw new Error(`${key} 必须是正整数,或留空使用推荐值`);
|
|
172
|
+
}
|
|
159
173
|
const contextWindow = normalizeLimited(quick && !advanced
|
|
160
174
|
? resolveContextWindow(preset, model)
|
|
161
|
-
:
|
|
175
|
+
: String(values.contextWindow ?? '').trim()
|
|
176
|
+
? numberValue(values.contextWindow, defaultContext)
|
|
177
|
+
: resolveContextWindow(preset, model), CONFIG_LIMITS.modelContextWindow, defaultContext);
|
|
162
178
|
const rawMax = quick && !advanced ? '' : String(values.maxTokens ?? '').trim();
|
|
163
179
|
const maxTokens = rawMax
|
|
164
180
|
? normalizeLimited(numberValue(rawMax, defaultMaxTokens(contextWindow)), CONFIG_LIMITS.modelMaxTokens, defaultMaxTokens(contextWindow))
|
|
@@ -166,6 +182,8 @@ export function ProviderWizard({ existing, setAsBase = true, quick = false, onDo
|
|
|
166
182
|
const apiFormat = askFormat
|
|
167
183
|
? (API_FORMAT_CHOICES.find((item) => item === values.apiFormat) ?? knownFormat)
|
|
168
184
|
: knownFormat;
|
|
185
|
+
if (new URL(baseURL).hostname === 'api.openai.com' && model.startsWith('gpt-6.2') && apiFormat !== 'openai-responses')
|
|
186
|
+
throw new Error('OpenAI 6.2 的工具调用需要 Responses API,请选择 Responses 预设和 /v1/responses 端点');
|
|
169
187
|
const reasoningEffort = showEffort
|
|
170
188
|
? reasoningEffortFromChoice(values.reasoningEffort)
|
|
171
189
|
: existing?.reasoningEffort;
|
|
@@ -178,7 +196,7 @@ export function ProviderWizard({ existing, setAsBase = true, quick = false, onDo
|
|
|
178
196
|
apiKey,
|
|
179
197
|
model,
|
|
180
198
|
contextWindow,
|
|
181
|
-
|
|
199
|
+
maxTokens: maxTokens ?? defaultMaxTokens(contextWindow),
|
|
182
200
|
supportsVision: existing?.supportsVision !== false,
|
|
183
201
|
...(reasoningEffort ? { reasoningEffort } : {}),
|
|
184
202
|
reasoning: quick && !advanced
|
|
@@ -193,11 +211,11 @@ export function ProviderWizard({ existing, setAsBase = true, quick = false, onDo
|
|
|
193
211
|
const diagnostic = await testModelConnection(draft);
|
|
194
212
|
if (!diagnostic.ok)
|
|
195
213
|
throw new Error(diagnostic.message);
|
|
196
|
-
if (
|
|
214
|
+
if (original) {
|
|
197
215
|
await configService.savePatch({
|
|
198
216
|
// null = 清除之前设的强度(选了「不设置」);不带这个字段则保留旧值。
|
|
199
|
-
models: [{ op: 'update', id:
|
|
200
|
-
...(setAsBase ? { baseModelId:
|
|
217
|
+
models: [{ op: 'update', id: original.id, patch: { ...draft, reasoningEffort: reasoningEffort ?? null } }],
|
|
218
|
+
...(setAsBase ? { baseModelId: original.id } : {}),
|
|
201
219
|
});
|
|
202
220
|
}
|
|
203
221
|
else {
|
|
@@ -47,26 +47,31 @@ const numberValue = (value: unknown, fallback: number) => {
|
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
export function ProviderWizard({
|
|
50
|
-
existing,
|
|
50
|
+
existing: original,
|
|
51
51
|
setAsBase = true,
|
|
52
52
|
quick = false,
|
|
53
53
|
onDone,
|
|
54
54
|
onCancel,
|
|
55
55
|
}: Props): JSX.Element {
|
|
56
|
+
const initialPresetIndex = original
|
|
57
|
+
? PRESETS.findIndex(item => item.baseURL === original.baseURL)
|
|
58
|
+
: -1;
|
|
56
59
|
const [phase, setPhase] = useState<'preset' | 'quick-choice' | 'fields'>(
|
|
57
60
|
'preset',
|
|
58
61
|
);
|
|
59
62
|
const [advanced, setAdvanced] = useState(false);
|
|
60
63
|
const [presetIndex, setPresetIndex] = useState(() => {
|
|
61
|
-
if (
|
|
64
|
+
if (original) {
|
|
62
65
|
const byUrl = PRESETS.findIndex(
|
|
63
|
-
(item) => item.baseURL ===
|
|
66
|
+
(item) => item.baseURL === original.baseURL,
|
|
64
67
|
);
|
|
65
68
|
if (byUrl >= 0) return byUrl;
|
|
66
69
|
}
|
|
67
|
-
return findPresetIndex(
|
|
70
|
+
return findPresetIndex(original?.displayName);
|
|
68
71
|
});
|
|
69
72
|
const preset = PRESETS[presetIndex]!;
|
|
73
|
+
// A provider switch must not send the old provider's credential to a new host.
|
|
74
|
+
const existing = presetIndex === (initialPresetIndex >= 0 ? initialPresetIndex : findPresetIndex(original?.displayName)) ? original : undefined;
|
|
70
75
|
|
|
71
76
|
useInput((input, key) => {
|
|
72
77
|
if (phase === 'quick-choice') {
|
|
@@ -133,7 +138,7 @@ export function ProviderWizard({
|
|
|
133
138
|
// 「自定义」没有预设,沿用已有模型自己的协议,新建时在完整设置里让用户选。
|
|
134
139
|
const presetFormat: ApiFormat | undefined =
|
|
135
140
|
preset.name === 'custom' ? existing?.apiFormat : (preset.apiFormat ?? 'openai');
|
|
136
|
-
const askFormat = preset.name === 'custom'
|
|
141
|
+
const askFormat = preset.name === 'custom';
|
|
137
142
|
const knownFormat: ApiFormat = presetFormat ?? 'openai';
|
|
138
143
|
// 推理强度是 OpenAI 系模型最常调的一项:快速配置也要问,不藏进高级里。
|
|
139
144
|
const showEffort =
|
|
@@ -206,7 +211,9 @@ export function ProviderWizard({
|
|
|
206
211
|
key: 'contextWindow',
|
|
207
212
|
label: '上下文窗口(Token)',
|
|
208
213
|
type: 'text',
|
|
209
|
-
default: String(defaultContext),
|
|
214
|
+
default: existing ? String(defaultContext) : '',
|
|
215
|
+
optional: true,
|
|
216
|
+
hint: '留空按最终填写的模型 ID 使用预设窗口;自定义模型请确认服务商实际限制。',
|
|
210
217
|
},
|
|
211
218
|
{
|
|
212
219
|
key: 'maxTokens',
|
|
@@ -252,10 +259,19 @@ export function ProviderWizard({
|
|
|
252
259
|
const model = String(values.model ?? '').trim();
|
|
253
260
|
if (!baseURL || !apiKey || !model)
|
|
254
261
|
throw new Error('Base URL、API Key 和模型 ID 均不能为空');
|
|
262
|
+
if (original && apiKey === original.apiKey && new URL(baseURL).origin !== new URL(original.baseURL).origin)
|
|
263
|
+
throw new Error('端点已换到其他服务商,请显式填写新服务商的 API Key,不能复用旧凭据');
|
|
264
|
+
for (const key of ['contextWindow', 'maxTokens']) {
|
|
265
|
+
const raw = String(values[key] ?? '').trim();
|
|
266
|
+
if (raw && (!Number.isSafeInteger(Number(raw)) || Number(raw) <= 0))
|
|
267
|
+
throw new Error(`${key} 必须是正整数,或留空使用推荐值`);
|
|
268
|
+
}
|
|
255
269
|
const contextWindow = normalizeLimited(
|
|
256
270
|
quick && !advanced
|
|
257
271
|
? resolveContextWindow(preset, model)
|
|
258
|
-
:
|
|
272
|
+
: String(values.contextWindow ?? '').trim()
|
|
273
|
+
? numberValue(values.contextWindow, defaultContext)
|
|
274
|
+
: resolveContextWindow(preset, model),
|
|
259
275
|
CONFIG_LIMITS.modelContextWindow,
|
|
260
276
|
defaultContext,
|
|
261
277
|
);
|
|
@@ -271,6 +287,8 @@ export function ProviderWizard({
|
|
|
271
287
|
const apiFormat: ApiFormat = askFormat
|
|
272
288
|
? (API_FORMAT_CHOICES.find((item) => item === values.apiFormat) ?? knownFormat)
|
|
273
289
|
: knownFormat;
|
|
290
|
+
if (new URL(baseURL).hostname === 'api.openai.com' && model.startsWith('gpt-6.2') && apiFormat !== 'openai-responses')
|
|
291
|
+
throw new Error('OpenAI 6.2 的工具调用需要 Responses API,请选择 Responses 预设和 /v1/responses 端点');
|
|
274
292
|
const reasoningEffort = showEffort
|
|
275
293
|
? reasoningEffortFromChoice(values.reasoningEffort)
|
|
276
294
|
: existing?.reasoningEffort;
|
|
@@ -284,7 +302,7 @@ export function ProviderWizard({
|
|
|
284
302
|
apiKey,
|
|
285
303
|
model,
|
|
286
304
|
contextWindow,
|
|
287
|
-
|
|
305
|
+
maxTokens: maxTokens ?? defaultMaxTokens(contextWindow),
|
|
288
306
|
supportsVision: existing?.supportsVision !== false,
|
|
289
307
|
...(reasoningEffort ? { reasoningEffort } : {}),
|
|
290
308
|
reasoning:
|
|
@@ -300,11 +318,11 @@ export function ProviderWizard({
|
|
|
300
318
|
};
|
|
301
319
|
const diagnostic = await testModelConnection(draft);
|
|
302
320
|
if (!diagnostic.ok) throw new Error(diagnostic.message);
|
|
303
|
-
if (
|
|
321
|
+
if (original) {
|
|
304
322
|
await configService.savePatch({
|
|
305
323
|
// null = 清除之前设的强度(选了「不设置」);不带这个字段则保留旧值。
|
|
306
|
-
models: [{ op: 'update', id:
|
|
307
|
-
...(setAsBase ? { baseModelId:
|
|
324
|
+
models: [{ op: 'update', id: original.id, patch: { ...draft, reasoningEffort: reasoningEffort ?? null } }],
|
|
325
|
+
...(setAsBase ? { baseModelId: original.id } : {}),
|
|
308
326
|
});
|
|
309
327
|
} else {
|
|
310
328
|
const before = new Set(
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { completeGenerationTerminal } from '../harness/generationReceipt.js';
|
|
1
2
|
import { configService } from './configService.js';
|
|
2
3
|
function providerFromModel(model) {
|
|
3
4
|
return {
|
|
@@ -27,6 +28,7 @@ export async function testModelConnection(model, timeoutMs = 45_000) {
|
|
|
27
28
|
try {
|
|
28
29
|
const { chat } = await import('../llm/client.js');
|
|
29
30
|
let received = false;
|
|
31
|
+
let completed = false;
|
|
30
32
|
for await (const event of chat({
|
|
31
33
|
provider: providerFromModel(model),
|
|
32
34
|
messages: [{ role: 'user', content: '请只回复 OK' }],
|
|
@@ -35,18 +37,20 @@ export async function testModelConnection(model, timeoutMs = 45_000) {
|
|
|
35
37
|
})) {
|
|
36
38
|
if (event.type === 'text_delta' && event.delta.trim())
|
|
37
39
|
received = true;
|
|
40
|
+
if (event.type === 'done')
|
|
41
|
+
completed = completeGenerationTerminal(event.stopReason, false);
|
|
38
42
|
}
|
|
39
|
-
return received
|
|
43
|
+
return received && completed
|
|
40
44
|
? { ok: true, code: 'ok', message: '连接正常' }
|
|
41
45
|
: {
|
|
42
46
|
ok: false,
|
|
43
47
|
code: 'invalid-response',
|
|
44
|
-
message: '
|
|
48
|
+
message: '服务已响应,但没有返回完整文本和正常结束回执',
|
|
45
49
|
};
|
|
46
50
|
}
|
|
47
51
|
catch (error) {
|
|
48
52
|
if (error.name === 'AbortError')
|
|
49
|
-
return { ok: false, code: 'timeout', message:
|
|
53
|
+
return { ok: false, code: 'timeout', message: `连接测试超过 ${timeoutMs / 1000} 秒,未能完成` };
|
|
50
54
|
const detail = error.message || String(error);
|
|
51
55
|
return {
|
|
52
56
|
ok: false,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { LocalProvider } from '../types.js';
|
|
2
|
+
import { completeGenerationTerminal } from '../harness/generationReceipt.js';
|
|
2
3
|
import type { ModelConfig } from './configFile.js';
|
|
3
4
|
import { type ConfigService, configService } from './configService.js';
|
|
4
5
|
|
|
@@ -74,6 +75,7 @@ export async function testModelConnection(
|
|
|
74
75
|
try {
|
|
75
76
|
const { chat } = await import('../llm/client.js');
|
|
76
77
|
let received = false;
|
|
78
|
+
let completed = false;
|
|
77
79
|
for await (const event of chat({
|
|
78
80
|
provider: providerFromModel(model),
|
|
79
81
|
messages: [{ role: 'user', content: '请只回复 OK' }],
|
|
@@ -81,17 +83,18 @@ export async function testModelConnection(
|
|
|
81
83
|
signal: controller.signal,
|
|
82
84
|
})) {
|
|
83
85
|
if (event.type === 'text_delta' && event.delta.trim()) received = true;
|
|
86
|
+
if (event.type === 'done') completed = completeGenerationTerminal(event.stopReason, false);
|
|
84
87
|
}
|
|
85
|
-
return received
|
|
88
|
+
return received && completed
|
|
86
89
|
? { ok: true, code: 'ok', message: '连接正常' }
|
|
87
90
|
: {
|
|
88
91
|
ok: false,
|
|
89
92
|
code: 'invalid-response',
|
|
90
|
-
message: '
|
|
93
|
+
message: '服务已响应,但没有返回完整文本和正常结束回执',
|
|
91
94
|
};
|
|
92
95
|
} catch (error) {
|
|
93
96
|
if ((error as Error).name === 'AbortError')
|
|
94
|
-
return { ok: false, code: 'timeout', message:
|
|
97
|
+
return { ok: false, code: 'timeout', message: `连接测试超过 ${timeoutMs / 1000} 秒,未能完成` };
|
|
95
98
|
const detail = (error as Error).message || String(error);
|
|
96
99
|
return {
|
|
97
100
|
ok: false,
|
package/src/context/compact.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { preserveAdvisorHistory } from './advisorHistory.js';
|
|
2
|
+
import { isSystemEventMessage } from '../runtime/systemEvents.js';
|
|
3
|
+
import { compactSkillReferences } from './compactResources.js';
|
|
2
4
|
import { chat } from '../llm/client.js';
|
|
3
5
|
import { countMessagesTokens } from './tokenCounter.js';
|
|
4
6
|
const NO_TOOLS_PREAMBLE = `Respond with text only. Do not call tools. Return exactly one <summary>...</summary> block.
|
|
@@ -64,7 +66,7 @@ function userText(content) {
|
|
|
64
66
|
*/
|
|
65
67
|
export function buildUserMessageLedger(messages) {
|
|
66
68
|
const texts = messages
|
|
67
|
-
.filter((message) => message.role === 'user')
|
|
69
|
+
.filter((message) => message.role === 'user' && !isSystemEventMessage(message))
|
|
68
70
|
.map((message) => userText(message.content))
|
|
69
71
|
.filter((text) => text.length > 0
|
|
70
72
|
&& !text.startsWith(CONTINUATION_MARKER)
|
|
@@ -282,8 +284,31 @@ export async function autoCompactIfNeeded(messages, provider, opts) {
|
|
|
282
284
|
const after = countMessagesTokens(compacted.messages);
|
|
283
285
|
return { ...compacted, compacted: true, before, after };
|
|
284
286
|
}
|
|
287
|
+
/** User-requested cleanup is not an emergency. Never truncate on failure or
|
|
288
|
+
* replace history with a larger result. Hosts persist before publishing it. */
|
|
289
|
+
export async function manualCompact(messages, provider, signal, chatFn = chat, promptCache, options) {
|
|
290
|
+
signal?.throwIfAborted();
|
|
291
|
+
if (options?.customInstructions !== undefined && (typeof options.customInstructions !== 'string' || options.customInstructions.length > 8000))
|
|
292
|
+
throw new Error('压缩要求必须为不超过 8,000 字符的文本');
|
|
293
|
+
const before = countMessagesTokens(messages);
|
|
294
|
+
const unchanged = (unchangedReason) => ({
|
|
295
|
+
messages, before, after: before, mode: 'llm-summary', degraded: false,
|
|
296
|
+
messagesRemoved: 0, tokensFreed: 0, unchangedReason,
|
|
297
|
+
});
|
|
298
|
+
const content = messages.filter(message => message.role !== 'system');
|
|
299
|
+
if (findTailWithCompleteToolChains(content).length >= content.length)
|
|
300
|
+
return unchanged('too-short');
|
|
301
|
+
const result = await forceCompact(messages, provider, signal, chatFn, promptCache, { ...options, strict: true });
|
|
302
|
+
signal?.throwIfAborted();
|
|
303
|
+
return result.after < before ? result : unchanged('no-benefit');
|
|
304
|
+
}
|
|
305
|
+
export function manualCompactNotice(result) {
|
|
306
|
+
return result.unchangedReason === 'too-short' ? '可压缩历史较少,已保留原上下文,未请求模型。'
|
|
307
|
+
: result.unchangedReason === 'no-benefit' ? '摘要未减少上下文占用,已保留原上下文。'
|
|
308
|
+
: `压缩完成:${result.before} → ${result.after} tokens(估算)。`;
|
|
309
|
+
}
|
|
285
310
|
/**
|
|
286
|
-
*
|
|
311
|
+
* 不看阈值,直接执行一次压缩。应急路径允许截断降级;手动入口使用 manualCompact。
|
|
287
312
|
*
|
|
288
313
|
* 与 autoCompactIfNeeded 共用同一段 runCompaction 逻辑;区别仅在于此函数
|
|
289
314
|
* 永远跑压缩、不返回 `compacted` 字段(由调用方决定如何反馈)。
|
|
@@ -308,17 +333,17 @@ chatFn = chat, promptCache, options) {
|
|
|
308
333
|
*/
|
|
309
334
|
async function runCompaction(messages, provider, signal, chatFn = chat, promptCache, options) {
|
|
310
335
|
// 1. 找出原 system(保留它,避免 agent 失忆)
|
|
311
|
-
const
|
|
336
|
+
const systemMessages = messages.filter((m) => m.role === 'system' && !m._uiProgress);
|
|
312
337
|
const nonSystem = messages.filter((m) => m.role !== 'system');
|
|
313
338
|
// 2. 构造给"压缩用"的请求:完整历史 + 七段式续接摘要 prompt
|
|
314
339
|
// (即使最后 N 条会被原样保留在新历史里,也送给 LLM 看 —— 让它写得出
|
|
315
340
|
// 高质量的 "Context for Continuing Work" 节,知道当前停在哪儿。)
|
|
316
341
|
const compactRequest = [
|
|
317
|
-
...
|
|
342
|
+
...systemMessages,
|
|
318
343
|
...nonSystem,
|
|
319
344
|
{
|
|
320
345
|
role: 'user',
|
|
321
|
-
content: buildCompactPrompt(),
|
|
346
|
+
content: buildCompactPrompt(options?.customInstructions),
|
|
322
347
|
},
|
|
323
348
|
];
|
|
324
349
|
// 3. 调 LLM(用同一个 chat() 但不传工具,避免模型尝试调用工具)
|
|
@@ -356,9 +381,10 @@ async function runCompaction(messages, provider, signal, chatFn = chat, promptCa
|
|
|
356
381
|
const failureTail = findTailWithCompleteToolChains(nonSystem);
|
|
357
382
|
const failureLedger = buildUserMessageLedger(nonSystem.slice(0, nonSystem.length - failureTail.length));
|
|
358
383
|
const compactedMessages = [
|
|
359
|
-
...
|
|
384
|
+
...systemMessages,
|
|
360
385
|
{
|
|
361
386
|
role: 'user',
|
|
387
|
+
inputOrigin: 'compact-fallback',
|
|
362
388
|
// ⚠️ 这里**故意不带** provider 原始报错:本条消息会进 history,既落盘也会在
|
|
363
389
|
// 后续轮次重新发给模型,错误体里可能夹带 URL / 请求体 / 凭据。
|
|
364
390
|
// 排障线索走 `compact_failed` 事件(只到 stderr / UI,不进 history)。
|
|
@@ -383,7 +409,9 @@ async function runCompaction(messages, provider, signal, chatFn = chat, promptCa
|
|
|
383
409
|
};
|
|
384
410
|
}
|
|
385
411
|
const formattedSummary = formatCompactSummary(summary);
|
|
386
|
-
|
|
412
|
+
const summaryBody = formattedSummary.replace(/^##\s+(?:Goal|Constraints|Verified evidence|Changes|Verification|Pending|Next action)[ \t]*(?:—|-)?[ \t]*/gmi, '').trim();
|
|
413
|
+
if (options?.strict && (!validateCompactSummary(formattedSummary).valid
|
|
414
|
+
|| !summaryBody || /^(?:\s|Unknown[.!]?|未知[。]?)*$/i.test(summaryBody))) {
|
|
387
415
|
throw new Error('COMPACTION_INVALID_SUMMARY');
|
|
388
416
|
}
|
|
389
417
|
if (!formattedSummary.trim()) {
|
|
@@ -393,9 +421,10 @@ async function runCompaction(messages, provider, signal, chatFn = chat, promptCa
|
|
|
393
421
|
throw new Error('COMPACTION_INVALID_SUMMARY');
|
|
394
422
|
const failureLedger = buildUserMessageLedger(nonSystem.slice(0, messagesRemoved));
|
|
395
423
|
const compactedMessages = [
|
|
396
|
-
...
|
|
424
|
+
...systemMessages,
|
|
397
425
|
{
|
|
398
426
|
role: 'user',
|
|
427
|
+
inputOrigin: 'compact-fallback',
|
|
399
428
|
content: '(LLM 返回了无效摘要,已使用规则式截断继续会话)'
|
|
400
429
|
+ (failureLedger
|
|
401
430
|
? `\n\n<user_messages>\n以下是被截掉的那部分对话里**用户的原话**(程序逐字抽取)。摘要不存在,这里就是唯一残留的历史要求。\n${failureLedger}\n</user_messages>`
|
|
@@ -420,14 +449,15 @@ async function runCompaction(messages, provider, signal, chatFn = chat, promptCa
|
|
|
420
449
|
// 台账只覆盖**被丢弃的那一段**——recentTail 已经逐字保留,再抽一遍是重复烧 token。
|
|
421
450
|
const messagesRemoved = nonSystem.length - recentTail.length;
|
|
422
451
|
const compactedMessages = [
|
|
423
|
-
...
|
|
452
|
+
...systemMessages,
|
|
424
453
|
{
|
|
425
454
|
role: 'user',
|
|
455
|
+
inputOrigin: 'compact-summary',
|
|
426
456
|
content: buildContinuationUserMessage({
|
|
427
457
|
summary: cleanSummary,
|
|
428
458
|
recentMessagesPreserved: recentTail.length > 0,
|
|
429
459
|
userMessageLedger: buildUserMessageLedger(nonSystem.slice(0, messagesRemoved)),
|
|
430
|
-
}),
|
|
460
|
+
}) + compactSkillReferences(nonSystem),
|
|
431
461
|
},
|
|
432
462
|
...recentTail,
|
|
433
463
|
];
|