dsh-volcengine-provider 0.2.6 → 0.2.9
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 +6 -4
- package/docs/arkcli-contract.md +1 -1
- package/docs/changelog.md +16 -0
- package/docs/client-model-thinking-preview.png +0 -0
- package/docs/client-settings-preview-dark.png +0 -0
- package/docs/client-settings-preview-empty.png +0 -0
- package/docs/client-settings-preview-mobile-dark.png +0 -0
- package/docs/client-settings-preview-models.png +0 -0
- package/docs/client-settings-preview.png +0 -0
- package/docs/development.md +1 -0
- package/docs/model-capabilities.md +54 -14
- package/docs/model-management.md +6 -2
- package/docs/model-thinking-audit.md +54 -9
- package/docs/usage.md +8 -2
- package/docs/validation.md +22 -2
- package/lib/ark-adapter.mjs +26 -5
- package/lib/browser-bridge/win32/rundll32.exe +0 -0
- package/lib/catalog-snapshot.json +1 -1
- package/lib/catalog.mjs +72 -3
- package/lib/client.js +274 -133
- package/lib/consumption-rates.json +86 -0
- package/lib/messages-payload.mjs +15 -3
- package/lib/state.mjs +9 -1
- package/package.json +6 -6
package/lib/catalog.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { assertModelId, assertPlan, LABELS, ROUTES, BUDGET_THINKING_LEVELS } from './state.mjs';
|
|
3
3
|
export const snapshot = JSON.parse(await readFile(new URL('./catalog-snapshot.json', import.meta.url), 'utf8'));
|
|
4
|
+
export const consumptionRates = JSON.parse(await readFile(new URL('./consumption-rates.json', import.meta.url), 'utf8'));
|
|
4
5
|
const modelId = /^[A-Za-z0-9][A-Za-z0-9_.:/-]{0,199}$/;
|
|
5
6
|
function validateModelRows(rows) {
|
|
6
7
|
if (!Array.isArray(rows) || rows.length > 1000) throw new Error('本地模型缓存格式错误');
|
|
@@ -19,6 +20,33 @@ function snapshotModel(plan, id) {
|
|
|
19
20
|
if (typeof id !== 'string') return undefined;
|
|
20
21
|
return snapshot[plan].models.find(model => model.id === id || model.aliases?.includes(id));
|
|
21
22
|
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Resolve the official model deduction coefficient for display only.
|
|
26
|
+
* Discount windows are evaluated at read time so an expired promotion never
|
|
27
|
+
* remains presented as the current rate. Unknown and account-routed models
|
|
28
|
+
* deliberately return null instead of inheriting a target model's rate.
|
|
29
|
+
*/
|
|
30
|
+
export function resolveConsumption(plan, id, now = Date.now()) {
|
|
31
|
+
assertPlan(plan);
|
|
32
|
+
const pinned = snapshotModel(plan, id);
|
|
33
|
+
const candidates = new Set([id, pinned?.id, ...(pinned?.aliases ?? [])].filter(Boolean));
|
|
34
|
+
const entry = Object.values(consumptionRates.models).find(row => row.ids.some(value => candidates.has(value)));
|
|
35
|
+
if (!entry) return null;
|
|
36
|
+
const discount = entry.discount;
|
|
37
|
+
const startsAt = discount ? Date.parse(discount.startsAt) : NaN;
|
|
38
|
+
const endsAt = discount ? Date.parse(discount.endsAt) : NaN;
|
|
39
|
+
const discounted = Boolean(discount && Number.isFinite(startsAt) && Number.isFinite(endsAt)
|
|
40
|
+
&& Number.isFinite(now) && now >= startsAt && now <= endsAt);
|
|
41
|
+
return {
|
|
42
|
+
plan,
|
|
43
|
+
multiplier: discounted ? discount.multiplier : entry.multiplier,
|
|
44
|
+
regularMultiplier: entry.multiplier,
|
|
45
|
+
discounted,
|
|
46
|
+
...(discounted ? { discountEndsAt: discount.endsAt } : {})
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
22
50
|
function pinnedCapabilities(model) {
|
|
23
51
|
const { aliases: _aliases, ...capabilities } = structuredClone(model);
|
|
24
52
|
return capabilities;
|
|
@@ -33,12 +61,40 @@ function fallbackCapabilities(id) {
|
|
|
33
61
|
capabilityNote: dynamic ? '智能调度的能力随目标模型变化,未声明统一思考档位。' : '该精确版本尚无固化能力资料,采用保守配置。'
|
|
34
62
|
};
|
|
35
63
|
}
|
|
64
|
+
// Core 只支持文本与图片两种输入模态;目录声明的其它模态(含音视频)不被接受。
|
|
65
|
+
const CORE_INPUT_MODALITIES = ['text', 'image'];
|
|
66
|
+
// 目录没有声明输入模态时沿用既有 fallback:只接文本。
|
|
67
|
+
const FALLBACK_INPUT = ['text'];
|
|
68
|
+
/**
|
|
69
|
+
* 检查目录声明的输入模态。
|
|
70
|
+
* 缺失按既有 fallback 处理;非数组、含重复或含未支持模态一律判为无效:
|
|
71
|
+
* 不能悄悄退化成纯文本,否则损坏的目录会被伪装成可用路由。
|
|
72
|
+
* 调用方自行决定是报错(路由构建)还是只作提示(设置页)。
|
|
73
|
+
*/
|
|
74
|
+
function inspectInput(modalities) {
|
|
75
|
+
if (modalities === undefined) return { input: [...FALLBACK_INPUT] };
|
|
76
|
+
if (!Array.isArray(modalities) || !modalities.length) return { error: '模型目录的输入模态格式错误' };
|
|
77
|
+
const seen = new Set();
|
|
78
|
+
for (const value of modalities) {
|
|
79
|
+
if (typeof value !== 'string' || !CORE_INPUT_MODALITIES.includes(value)) return { error: '模型目录的输入模态不受支持' };
|
|
80
|
+
if (seen.has(value)) return { error: '模型目录的输入模态包含重复项' };
|
|
81
|
+
seen.add(value);
|
|
82
|
+
}
|
|
83
|
+
return { input: [...modalities] };
|
|
84
|
+
}
|
|
36
85
|
function coreCapabilities(model) {
|
|
37
86
|
const {
|
|
38
87
|
aliases: _aliases, capabilityUnverified: _unverified, defaultReasoning: _default,
|
|
39
88
|
messagesThinkingMode: _mode, canDisableThinking: _disable,
|
|
40
|
-
capabilityStatus: _status, capabilityNote: _note,
|
|
89
|
+
capabilityStatus: _status, capabilityNote: _note,
|
|
90
|
+
toolsEnabled: _tools, imageInput: _image, ...capabilities
|
|
41
91
|
} = model;
|
|
92
|
+
if ('input' in capabilities) {
|
|
93
|
+
const checked = inspectInput(capabilities.input);
|
|
94
|
+
// 路由构建阶段直接拒绝:坏目录不得被当成纯文本模型注册。
|
|
95
|
+
if (checked.error) throw new Error(`${checked.error}:${model.id ?? '未知模型'}`);
|
|
96
|
+
capabilities.input = checked.input;
|
|
97
|
+
}
|
|
42
98
|
return capabilities;
|
|
43
99
|
}
|
|
44
100
|
function displayName(id, candidate, pinned) {
|
|
@@ -114,7 +170,9 @@ export function modelDefaults(plan, model) {
|
|
|
114
170
|
const forceAdaptiveThinking = typeof model?.compat?.forceAdaptiveThinking === 'boolean'
|
|
115
171
|
? model.compat.forceAdaptiveThinking
|
|
116
172
|
: typeof base.compat?.forceAdaptiveThinking === 'boolean' ? base.compat.forceAdaptiveThinking : false;
|
|
117
|
-
|
|
173
|
+
// 图片输入取模型实际声明的模态;工具开关默认开启,保持既有工具行为不变。
|
|
174
|
+
const imageInput = Array.isArray(model?.input) && model.input.includes('image');
|
|
175
|
+
return { contextWindow, maxTokens, reasoningEfforts: efforts, defaultReasoning: defaultReasoningFor(efforts, model?.defaultReasoning), forceAdaptiveThinking, imageInput, toolsEnabled: true };
|
|
118
176
|
}
|
|
119
177
|
|
|
120
178
|
/** 目录默认与用户覆盖合并后的有效参数。 */
|
|
@@ -127,6 +185,8 @@ export function effectiveModel(defaults, settings = {}) {
|
|
|
127
185
|
if (settings.forceAdaptiveThinking !== undefined) effective.forceAdaptiveThinking = settings.forceAdaptiveThinking;
|
|
128
186
|
if (settings.forceAdaptiveThinking === false && settings.reasoningEfforts === undefined) effective.reasoningEfforts = inheritedBudgetMap(effective.reasoningEfforts);
|
|
129
187
|
if (settings.temperature !== undefined) effective.temperature = settings.temperature;
|
|
188
|
+
if (settings.imageInput !== undefined) effective.imageInput = settings.imageInput;
|
|
189
|
+
if (settings.toolsEnabled !== undefined) effective.toolsEnabled = settings.toolsEnabled;
|
|
130
190
|
effective.defaultReasoning = defaultReasoningFor(effective.reasoningEfforts, settings.defaultReasoning === undefined ? defaults.defaultReasoning : settings.defaultReasoning);
|
|
131
191
|
return effective;
|
|
132
192
|
}
|
|
@@ -165,6 +225,10 @@ export function getModelRows(state, accountId, plan) {
|
|
|
165
225
|
const defaults = modelDefaults(plan, model);
|
|
166
226
|
const effective = effectiveModel(defaults, settings);
|
|
167
227
|
const warnings = [];
|
|
228
|
+
// 目录声明的输入模态无效时设置页仍可读,但路由构建会拒绝该目录。
|
|
229
|
+
const declaredInput = inspectInput(model.input);
|
|
230
|
+
if (declaredInput.error) warnings.push(`${declaredInput.error}:该目录会导致路由更新失败;若已有可用路由会予以保留,请重新拉取模型目录。`);
|
|
231
|
+
if (settings.imageInput === true && defaults.imageInput === false) warnings.push('已强制开启图片输入:目录未声明该模型支持图片,请先确认服务端能力。');
|
|
168
232
|
if (model.canDisableThinking === false && effective.reasoningEfforts?.off === null) {
|
|
169
233
|
const { off: _off, ...levels } = effective.reasoningEfforts;
|
|
170
234
|
effective.reasoningEfforts = Object.keys(levels).length ? levels : false;
|
|
@@ -180,6 +244,7 @@ export function getModelRows(state, accountId, plan) {
|
|
|
180
244
|
return {
|
|
181
245
|
id: model.id,
|
|
182
246
|
name: typeof model.name === 'string' && model.name ? model.name : model.id,
|
|
247
|
+
consumption: resolveConsumption(plan, model.id),
|
|
183
248
|
enabled: settings.enabled !== false,
|
|
184
249
|
capabilityUnverified: model.capabilityUnverified === true,
|
|
185
250
|
messagesThinkingMode: model.messagesThinkingMode ?? 'server-default',
|
|
@@ -203,10 +268,14 @@ export function providerProfile(plan, models) {
|
|
|
203
268
|
|
|
204
269
|
/** 把有效参数写回 Core 的模型描述;只写 Core 认识的字段。 */
|
|
205
270
|
function coreModel(model, row) {
|
|
271
|
+
// 目录声明的输入模态在此之前已被校验;畸形目录不会走到这里。
|
|
206
272
|
if (!row) return coreCapabilities(model);
|
|
207
273
|
const compat = { ...(model.compat ?? {}) };
|
|
208
274
|
if (typeof row.effective.forceAdaptiveThinking === 'boolean') compat.forceAdaptiveThinking = row.effective.forceAdaptiveThinking;
|
|
209
|
-
|
|
275
|
+
// 目录声明有效时,Core 的输入模态由图片开关决定:text 或 text+image。
|
|
276
|
+
const input = row.effective.imageInput ? ['text', 'image'] : ['text'];
|
|
277
|
+
// 工具开关只经 factsByProvider 的行传给适配器,不作为 Core 字段下发。
|
|
278
|
+
return { ...coreCapabilities(model), input, contextWindow: row.effective.contextWindow, maxTokens: row.effective.maxTokens, reasoningEfforts: row.effective.reasoningEfforts, compat };
|
|
210
279
|
}
|
|
211
280
|
|
|
212
281
|
export function profilesFor(state) {
|