dsh-vision-router 3.0.3 → 3.0.5
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 +183 -162
- package/README.zh.md +179 -158
- package/cordis.patch.yml +14 -10
- package/docs/architecture/dsh-0.2.1-alpha.2-compat.md +41 -0
- package/docs/development/dsh-alpha3-compatibility.md +36 -0
- package/docs/development/dsh-alpha4-adaptation.md +12 -0
- package/docs/development/dsh-alpha4-validation-evidence.md +29 -0
- package/docs/development/dsh-alpha5-adaptation.md +31 -0
- package/docs/development/dsh-rc1-adaptation.md +29 -0
- package/docs/development/dsh-rc2-adaptation.md +24 -0
- package/docs/development/v305-real-scenario-acceptance.md +34 -0
- package/docs/development/web-live-reload.md +157 -0
- package/docs/releases/v3.0.4.md +18 -0
- package/docs/releases/v3.0.5.md +31 -0
- package/docs/remote-settings.md +4 -0
- package/docs/v2-capability-routing.md +25 -9
- package/lib/adapter-update-coalescer.js +41 -8
- package/lib/client-presentation-boundary-main.js +41 -7
- package/lib/client.js +27 -23
- package/lib/core-primitives.js +6 -2
- package/lib/http-compat.js +33 -2
- package/lib/maintenance-routes.js +7 -1
- package/lib/session-message-source-compat.js +13 -4
- package/lib/sharp-runtime.js +0 -2
- package/lib/vision-backend-runtime-policy.js +3 -3
- package/lib/vision-background-benchmark.js +33 -5
- package/lib/vision-capability-benchmark-service.js +61 -23
- package/lib/vision-evidence-guidance.js +7 -1
- package/lib/vision-exact-check-client.js +24 -6
- package/lib/vision-image-input-verdict.js +5 -3
- package/lib/vision-toggle-root-hardening.js +20 -3
- package/lib/web-capability-boundary.js +164 -31
- package/package.json +6 -4
- package/presets/web-connection-ready/index.mjs +48 -0
- package/presets/web-connection-ready/package.json +6 -0
|
@@ -1170,6 +1170,13 @@ export const CLIENT_PRESENTATION_PRELUDE = String.raw`(function(){
|
|
|
1170
1170
|
var complete = usable && livePair.mode !== 'unavailable';
|
|
1171
1171
|
var settledMode = React.useRef(null);
|
|
1172
1172
|
var toggleTransition = React.useRef(null);
|
|
1173
|
+
// The Host may render a ready directory while the RPC that selected
|
|
1174
|
+
// it is still in flight. Keep only an in-flight transaction fence here,
|
|
1175
|
+
// never a second source of truth for Vision ON/OFF.
|
|
1176
|
+
var selectionTransaction = React.useRef(null);
|
|
1177
|
+
var refreshSelection = React.useState(0)[1];
|
|
1178
|
+
var selectionInFlight = !!(selectionTransaction.current &&
|
|
1179
|
+
selectionTransaction.current.directory === directory);
|
|
1173
1180
|
if (settledMode.current && settledMode.current.directory !== directory) settledMode.current = null;
|
|
1174
1181
|
if (toggleTransition.current && toggleTransition.current.directory !== directory) toggleTransition.current = null;
|
|
1175
1182
|
if (complete) settledMode.current = { directory: directory, mode: livePair.mode };
|
|
@@ -1194,14 +1201,25 @@ export const CLIENT_PRESENTATION_PRELUDE = String.raw`(function(){
|
|
|
1194
1201
|
var toastState = React.useState(null);
|
|
1195
1202
|
var toast = toastState[0];
|
|
1196
1203
|
var setToast = toastState[1];
|
|
1197
|
-
var busy = state.status === 'selecting';
|
|
1204
|
+
var busy = state.status === 'selecting' || selectionInFlight;
|
|
1198
1205
|
var loading = settling;
|
|
1206
|
+
// Host's model-catalog refresh retains the last good current/groups,
|
|
1207
|
+
// but briefly reports 'loading'. When that *complete* pair is still
|
|
1208
|
+
// present, its selection may be sent to Host for fresh validation;
|
|
1209
|
+
// don't flip the native HTML disabled bit in the middle of a user's
|
|
1210
|
+
// pointer gesture (Chromium drops the click even after re-enabling).
|
|
1211
|
+
// A cold load, reconnect, unavailable pair, or selection in flight
|
|
1212
|
+
// remains blocked. We never infer a new mode or optimistically commit.
|
|
1213
|
+
var refreshWithPair = state.status === 'loading' && complete &&
|
|
1214
|
+
!!livePair.target && state.pending == null && state.error == null &&
|
|
1215
|
+
state.routable !== false;
|
|
1216
|
+
var blockingLoad = loading && !refreshWithPair;
|
|
1199
1217
|
var removed = props.session && props.session.removed === true;
|
|
1200
|
-
var disabled = props.available !== true || removed || busy ||
|
|
1218
|
+
var disabled = props.available !== true || removed || busy || blockingLoad || livePair.mode === 'unavailable';
|
|
1201
1219
|
var t = typeof props.t === 'function' ? props.t : fallbackTranslate(active);
|
|
1202
1220
|
var title = busy || ownSettling
|
|
1203
1221
|
? t('switching')
|
|
1204
|
-
:
|
|
1222
|
+
: blockingLoad
|
|
1205
1223
|
? t('loading')
|
|
1206
1224
|
: livePair.mode === 'unavailable'
|
|
1207
1225
|
? t('unavailable')
|
|
@@ -1229,22 +1247,30 @@ export const CLIENT_PRESENTATION_PRELUDE = String.raw`(function(){
|
|
|
1229
1247
|
'data-vision-router-mode-toggle': 'true',
|
|
1230
1248
|
'aria-pressed': active,
|
|
1231
1249
|
'aria-label': title,
|
|
1232
|
-
'aria-busy': busy ||
|
|
1250
|
+
'aria-busy': busy || blockingLoad,
|
|
1233
1251
|
title: title,
|
|
1234
1252
|
disabled: disabled,
|
|
1235
1253
|
className: 'vr-vision-toggle',
|
|
1236
1254
|
'data-active': active ? 'true' : 'false',
|
|
1237
|
-
'data-dimmed': disabled && !ownSettling && (livePair.mode === 'unavailable' ||
|
|
1255
|
+
'data-dimmed': disabled && !ownSettling && (livePair.mode === 'unavailable' || blockingLoad) ? 'true' : 'false',
|
|
1238
1256
|
onClick: function() {
|
|
1239
|
-
if (disabled || !pair.target || typeof props.select !== 'function'
|
|
1257
|
+
if (disabled || !pair.target || typeof props.select !== 'function' ||
|
|
1258
|
+
(selectionTransaction.current && selectionTransaction.current.directory === directory)) return;
|
|
1240
1259
|
var target = pair.target;
|
|
1260
|
+
var ticket = { directory: directory, target: target };
|
|
1261
|
+
selectionTransaction.current = ticket;
|
|
1262
|
+
refreshSelection(function(revision){ return revision + 1; });
|
|
1241
1263
|
toggleTransition.current = {
|
|
1242
1264
|
directory: directory,
|
|
1243
1265
|
target: target,
|
|
1244
1266
|
seenSelecting: false
|
|
1245
1267
|
};
|
|
1246
1268
|
setToast(null);
|
|
1247
|
-
|
|
1269
|
+
var pending;
|
|
1270
|
+
try { pending = props.select(target); }
|
|
1271
|
+
catch (error) { pending = Promise.reject(error); }
|
|
1272
|
+
void Promise.resolve(pending).then(function(accepted){
|
|
1273
|
+
if (selectionTransaction.current !== ticket) return;
|
|
1248
1274
|
if (!accepted) {
|
|
1249
1275
|
toggleTransition.current = null;
|
|
1250
1276
|
announceRejectedSelection();
|
|
@@ -1255,6 +1281,14 @@ export const CLIENT_PRESENTATION_PRELUDE = String.raw`(function(){
|
|
|
1255
1281
|
if (!latest || (latest.status !== 'selecting' && latest.status !== 'idle' && latest.status !== 'loading')) {
|
|
1256
1282
|
toggleTransition.current = null;
|
|
1257
1283
|
}
|
|
1284
|
+
}, function(error){
|
|
1285
|
+
if (selectionTransaction.current !== ticket) return;
|
|
1286
|
+
toggleTransition.current = null;
|
|
1287
|
+
announceRejectedSelection();
|
|
1288
|
+
}).finally(function(){
|
|
1289
|
+
if (selectionTransaction.current !== ticket) return;
|
|
1290
|
+
selectionTransaction.current = null;
|
|
1291
|
+
refreshSelection(function(revision){ return revision + 1; });
|
|
1258
1292
|
});
|
|
1259
1293
|
}
|
|
1260
1294
|
},
|
package/lib/client.js
CHANGED
|
@@ -249,7 +249,7 @@ openLogFolder,
|
|
|
249
249
|
builtinFallbackLabel: '内置免费兜底(自动)',
|
|
250
250
|
builtinFallbackEnabled: '已启用',
|
|
251
251
|
builtinFallbackDisabled: '已关闭',
|
|
252
|
-
builtinFallbackBody: 'OVHcloud 匿名视觉链共 {count} 个模型,首选 {primary}。匿名限额为每 IP、每模型
|
|
252
|
+
builtinFallbackBody: 'OVHcloud 匿名视觉链共 {count} 个模型,首选 {primary}。匿名限额为每 IP、每模型 {perModelRpm} 次/分钟;{count} 个模型独立限额,理论合计约 {totalRpm} 次/分钟,实际以 OVH 限流为准。它固定在上面用户模型之后尝试,免注册、免 Key。',
|
|
253
253
|
chainLabel: '识图模型',
|
|
254
254
|
chainHint: '选择 Vision Router 用来读取图片的模型。将按从上到下的顺序尝试,失败时自动切换到下一个。',
|
|
255
255
|
addFallback: '+ 添加备用识图模型',
|
|
@@ -268,18 +268,18 @@ openLogFolder,
|
|
|
268
268
|
catalogFallback: '),模型字段已退回手动输入。',
|
|
269
269
|
catalogPartialFailure: '部分已配置供应商的模型目录加载失败:{detail}。这些供应商可能仍会显示在「设置 → 模型」中,但暂时不会出现在这里。',
|
|
270
270
|
visionCapsLoading: '正在读取模型图片能力声明(仅用于提示,不影响可选模型)…',
|
|
271
|
-
visionCapsError: '
|
|
272
|
-
visionCapsFiltered: '
|
|
273
|
-
visionCapabilityUndeclaredWarning: '
|
|
274
|
-
visionCapabilityTextOnlyWarning: '
|
|
275
|
-
visionCapabilityUnknownWarning: '
|
|
271
|
+
visionCapsError: '能力数据不可用,仍可选择模型;实际图片投递取决于Host声明及传输支持。',
|
|
272
|
+
visionCapsFiltered: '能力声明不限制后端选择;Host标为仅文本可能导致图片无法送达。',
|
|
273
|
+
visionCapabilityUndeclaredWarning: '图片能力未知:调用时尝试原生adapter,失败后尝试下一后端。',
|
|
274
|
+
visionCapabilityTextOnlyWarning: 'Host 将此模型标为仅文本,adapter 调用前会剥离图片;仅兼容的 HTTP Chat Completions 可桥接。若支持图片,在 DSH「设置 → 模型 → 输入类型」勾选图片;旧 Host 设 llm-pi-ai 的 input: [text, image] 或 llm-deepseek 的 inputModalities: [text, image] 后重载配置,否则跳过此后端。',
|
|
275
|
+
visionCapabilityUnknownWarning: '图片能力待验证;调用失败会尝试下一后端。',
|
|
276
276
|
visionCapsEmptyTitle: '没有可选的用户视觉模型',
|
|
277
277
|
visionCapsEmptyBody: '检测到 {count} 个用户模型,但它们都没有被 DSH 明确标记为支持图片,因此已被安全隐藏。',
|
|
278
278
|
visionCapsHiddenPrefix: '被隐藏的模型:',
|
|
279
279
|
visionCapsReasonMissingImage: '未声明 image',
|
|
280
280
|
visionCapsReasonUnverified: '无法验证图片能力',
|
|
281
281
|
visionCapsHiddenMore: '另有 {count} 个模型未显示',
|
|
282
|
-
visionCapsMissingImageHint: '
|
|
282
|
+
visionCapsMissingImageHint: '若模型确实支持图片,请到 DSH「设置 → 模型 → 输入类型」启用图片并保存;旧 Host 可在 profile 的 cordis.patch.yml 中声明正确的模型输入类型。仅添加额外视觉模型标记不能改变 Host 图片投递。',
|
|
283
283
|
visionCapsRetry: '重新检测模型',
|
|
284
284
|
chainInvalidCurrent: '当前保存的后端已不在可调用模型目录中,或属于非生成式/递归路由,运行时会跳过:',
|
|
285
285
|
retryCatalog: '重试加载目录',
|
|
@@ -301,7 +301,7 @@ openLogFolder,
|
|
|
301
301
|
extraVisionModelsHint:
|
|
302
302
|
'这个设置不再用于“解锁”下拉或允许调用;所有可调用生成式模型本来就能被选择。' +
|
|
303
303
|
'只有当你希望把某个未声明图片能力的模型明确标记为视觉模型时才需要填写。' +
|
|
304
|
-
'
|
|
304
|
+
'此标记不会更改 Host 输入声明。仅经验证的 HTTP Chat Completions 渠道可直接桥接;其他纯文本声明会被安全拒绝。',
|
|
305
305
|
groupRoutes: '路由名称',
|
|
306
306
|
groupProxy: '网络',
|
|
307
307
|
networkAuthorityHint: '默认不接管网络出口:Vision Router 沿用 DSH/Host 当前网络路径。下方代理只用于需要给视觉请求单独指定出口的高级覆盖。',
|
|
@@ -535,7 +535,7 @@ openLogFolder,
|
|
|
535
535
|
builtinFallbackLabel: 'Built-in free fallback (automatic)',
|
|
536
536
|
builtinFallbackEnabled: 'Enabled',
|
|
537
537
|
builtinFallbackDisabled: 'Disabled',
|
|
538
|
-
builtinFallbackBody: 'The anonymous OVHcloud vision chain contains {count} models, starting with {primary}. Anonymous limits are
|
|
538
|
+
builtinFallbackBody: 'The anonymous OVHcloud vision chain contains {count} models, starting with {primary}. Anonymous limits are {perModelRpm} requests/minute per IP per model; {count} independent model buckets are about {totalRpm} RPM in theory, subject to OVH rate limiting. It always runs after your user models and needs no signup or API key.',
|
|
539
539
|
chainLabel: 'Vision model',
|
|
540
540
|
chainHint: 'Choose the models Vision Router uses to read images. They are tried from top to bottom, with automatic failover.',
|
|
541
541
|
addFallback: '+ Add fallback vision model',
|
|
@@ -554,18 +554,18 @@ openLogFolder,
|
|
|
554
554
|
catalogFallback: '); model fields fell back to free-text input.',
|
|
555
555
|
catalogPartialFailure: 'Some configured providers failed to load their model catalog: {detail}. They may still appear in Settings → Models, but are temporarily unavailable here.',
|
|
556
556
|
visionCapsLoading: 'Reading model image-capability metadata (advisory only; it does not hide selectable models)…',
|
|
557
|
-
visionCapsError: '
|
|
558
|
-
visionCapsFiltered: '
|
|
559
|
-
visionCapabilityUndeclaredWarning: '
|
|
560
|
-
visionCapabilityTextOnlyWarning: '
|
|
561
|
-
visionCapabilityUnknownWarning: 'Image capability is
|
|
557
|
+
visionCapsError: 'Capabilities unavailable; models remain selectable, but image delivery depends on Host input declaration.',
|
|
558
|
+
visionCapsFiltered: 'Model capability labels do not restrict selection; a Host text-only label may block image delivery.',
|
|
559
|
+
visionCapabilityUndeclaredWarning: 'Image capability unknown; Vision Router tries the adapter and falls through on failure.',
|
|
560
|
+
visionCapabilityTextOnlyWarning: 'Host text-only strips images before adapter; only verified HTTP Chat Completions can bridge. If supported, enable Image in DSH Settings → Models → Input types. Older Hosts: llm-pi-ai input: [text, image]; llm-deepseek inputModalities: [text, image]. Otherwise skip this backend.',
|
|
561
|
+
visionCapabilityUnknownWarning: 'Image capability is checked at call time; failures fall through.',
|
|
562
562
|
visionCapsEmptyTitle: 'No selectable user vision models',
|
|
563
563
|
visionCapsEmptyBody: 'DSH reported {count} user models, but none are explicitly marked as accepting images, so Vision Router hid them safely.',
|
|
564
564
|
visionCapsHiddenPrefix: 'Hidden models:',
|
|
565
565
|
visionCapsReasonMissingImage: 'image input not declared',
|
|
566
566
|
visionCapsReasonUnverified: 'image capability could not be verified',
|
|
567
567
|
visionCapsHiddenMore: '{count} more models not shown',
|
|
568
|
-
visionCapsMissingImageHint: '
|
|
568
|
+
visionCapsMissingImageHint: 'For a model that truly accepts images, enable Image in DSH Settings → Models → Input types. Older Hosts: set the correct input field in your profile cordis.patch.yml. Extra vision labels cannot change Host pixel delivery.',
|
|
569
569
|
visionCapsRetry: 'Re-detect models',
|
|
570
570
|
chainInvalidCurrent: 'This saved backend is no longer callable, or is a non-generative/recursive route, so runtime will skip it: ',
|
|
571
571
|
retryCatalog: 'Retry catalog',
|
|
@@ -587,7 +587,7 @@ openLogFolder,
|
|
|
587
587
|
extraVisionModelsHint:
|
|
588
588
|
'This setting no longer unlocks the picker or admission: every callable generative model is selectable already. ' +
|
|
589
589
|
'Use it only when you want to explicitly label an undeclared model as visual. ' +
|
|
590
|
-
'
|
|
590
|
+
'This label does not change Host input declarations. Verified HTTP Chat Completions can bridge; other explicit text-only routes fail safely.',
|
|
591
591
|
groupRoutes: 'Route names',
|
|
592
592
|
groupProxy: 'Network',
|
|
593
593
|
networkAuthorityHint: 'Vision Router does not own egress by default: it follows the current DSH/Host network path. The proxy below is only an advanced vision-request override.',
|
|
@@ -845,11 +845,12 @@ openLogFolder,
|
|
|
845
845
|
function visionCapabilityWarningKey(capability, status) {
|
|
846
846
|
if (status === 'loading' || status === 'idle') return undefined
|
|
847
847
|
if (status === 'error' || !capability) return 'visionCapabilityUnknownWarning'
|
|
848
|
-
if (capability.attemptable === false
|
|
849
|
-
const
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
848
|
+
if (capability.attemptable === false) return undefined
|
|
849
|
+
const declared = Array.isArray(capability.hostInputModalities)
|
|
850
|
+
? capability.hostInputModalities : capability.inputModalities
|
|
851
|
+
const modalities = Array.isArray(declared) ? declared : []
|
|
852
|
+
if (modalities.length > 0 && !modalities.includes('image')) return 'visionCapabilityTextOnlyWarning'
|
|
853
|
+
return capability.image === true ? undefined : 'visionCapabilityUndeclaredWarning'
|
|
853
854
|
}
|
|
854
855
|
|
|
855
856
|
// ── field specs ──────────────────────────────────────────────────────────
|
|
@@ -3931,13 +3932,16 @@ openLogFolder,
|
|
|
3931
3932
|
const list = Array.isArray(visionCaps.builtinFallback) ? visionCaps.builtinFallback : []
|
|
3932
3933
|
const enabled = format('freeFallback') !== false
|
|
3933
3934
|
const primary = list[0] && list[0].model ? list[0].model : 'Qwen3.5-397B-A17B'
|
|
3934
|
-
const count = list.length > 0 ? list.length :
|
|
3935
|
+
const count = list.length > 0 ? list.length : 4
|
|
3936
|
+
const perModelRpm = Number.isFinite(visionCaps.anonymousRpmPerModel)
|
|
3937
|
+
? Math.max(0, visionCaps.anonymousRpmPerModel)
|
|
3938
|
+
: 2
|
|
3935
3939
|
return h('div', { className: 'vr-field' },
|
|
3936
3940
|
h('div', { className: 'vr-field-head' },
|
|
3937
3941
|
h('span', { className: 'vr-label' }, t('builtinFallbackLabel')),
|
|
3938
3942
|
h('span', { className: 'vr-badge' }, enabled ? t('builtinFallbackEnabled') : t('builtinFallbackDisabled')),
|
|
3939
3943
|
),
|
|
3940
|
-
h('p', { className: 'vr-hint' }, t('builtinFallbackBody', { count, primary })),
|
|
3944
|
+
h('p', { className: 'vr-hint' }, t('builtinFallbackBody', { count, primary, perModelRpm, totalRpm: count * perModelRpm })),
|
|
3941
3945
|
)
|
|
3942
3946
|
}
|
|
3943
3947
|
const textProviderEditor = () => {
|
package/lib/core-primitives.js
CHANGED
|
@@ -1778,12 +1778,12 @@ export async function downscaleImage(bytes, maxPixels, options = {}) {
|
|
|
1778
1778
|
*/
|
|
1779
1779
|
export const DEFAULT_HTTP_PROVIDERS = [
|
|
1780
1780
|
// OVHcloud anonymous quota is per IP AND per model. Keep the free chain
|
|
1781
|
-
// ordered
|
|
1781
|
+
// ordered by preferred quality so quality wins first. Retired models are
|
|
1782
|
+
// removed from this implicit chain; explicit user rows are never rewritten. A 429 on one model can
|
|
1782
1783
|
// immediately fall through to the next model's independent anonymous bucket.
|
|
1783
1784
|
{ name: 'ovh', baseURL: 'https://oai.endpoints.kepler.ai.cloud.ovh.net/v1', model: 'Qwen3.5-397B-A17B', apiKeyEnv: '', maxTokens: 4096 },
|
|
1784
1785
|
{ name: 'ovh', baseURL: 'https://oai.endpoints.kepler.ai.cloud.ovh.net/v1', model: 'Qwen2.5-VL-72B-Instruct', apiKeyEnv: '', maxTokens: 4096 },
|
|
1785
1786
|
{ name: 'ovh', baseURL: 'https://oai.endpoints.kepler.ai.cloud.ovh.net/v1', model: 'Qwen3.6-27B', apiKeyEnv: '', maxTokens: 4096 },
|
|
1786
|
-
{ name: 'ovh', baseURL: 'https://oai.endpoints.kepler.ai.cloud.ovh.net/v1', model: 'Mistral-Small-3.2-24B-Instruct-2506', apiKeyEnv: '', maxTokens: 4096 },
|
|
1787
1787
|
{ name: 'ovh', baseURL: 'https://oai.endpoints.kepler.ai.cloud.ovh.net/v1', model: 'Qwen3.5-9B', apiKeyEnv: '', maxTokens: 4096 },
|
|
1788
1788
|
]
|
|
1789
1789
|
|
|
@@ -2768,6 +2768,8 @@ export function decideVisionBackendCapability(info, provider, model, extraVision
|
|
|
2768
2768
|
image: true,
|
|
2769
2769
|
attemptable: true,
|
|
2770
2770
|
inputModalities: [...new Set([...inputModalities, 'image'])],
|
|
2771
|
+
...(inputModalities.length > 0 && !inputModalities.includes('image')
|
|
2772
|
+
? { hostInputModalities: [...inputModalities] } : {}),
|
|
2771
2773
|
inferred: 'override',
|
|
2772
2774
|
reason: undefined,
|
|
2773
2775
|
}
|
|
@@ -2789,6 +2791,8 @@ export function decideVisionBackendCapability(info, provider, model, extraVision
|
|
|
2789
2791
|
image: true,
|
|
2790
2792
|
attemptable: true,
|
|
2791
2793
|
inputModalities: [...new Set([...inputModalities, 'image'])],
|
|
2794
|
+
...(inputModalities.length > 0 && !inputModalities.includes('image')
|
|
2795
|
+
? { hostInputModalities: [...inputModalities] } : {}),
|
|
2792
2796
|
inferred: 'name',
|
|
2793
2797
|
reason: undefined,
|
|
2794
2798
|
}
|
package/lib/http-compat.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
|
|
2
2
|
const GLM_4V_FLASH = /^glm-4v-flash(?:$|[-_.])/i
|
|
3
3
|
export const DEFAULT_HTTP_ERROR_DETAIL_MAX_BYTES = 64 * 1024
|
|
4
|
+
// OVHcloud documents a 10 MB total request-body cap for VLM endpoints.
|
|
5
|
+
// Count actual serialized UTF-8 JSON, not image pixels or pre-base64 bytes.
|
|
6
|
+
export const OVH_VLM_MAX_JSON_BYTES = 10_000_000
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* Known OpenAI-compatible transport quirks. Rules are intentionally sparse:
|
|
@@ -110,6 +113,9 @@ export function parseMaxTokensLimit(detail) {
|
|
|
110
113
|
return undefined
|
|
111
114
|
}
|
|
112
115
|
const patterns = [
|
|
116
|
+
// Two-sided English ranges must use the upper bound, not the first number.
|
|
117
|
+
// The generic max_tokens fallback below would otherwise parse the lower bound.
|
|
118
|
+
/(?:max(?:_completion)?[_ -]?tokens?)[^\d\n]{0,48}(?:between|from|(?:in|within)(?:\s+the)?(?:\s+(?:valid|allowed))?(?:\s+range)?)[^\d\n]{0,12}\d+\s*(?:,|and|to|[-–—])\s*(\d+)/i,
|
|
113
119
|
/(?:限制数值范围|range)\s*[\[(]\s*\d+\s*,\s*(\d+)\s*[\])]/i,
|
|
114
120
|
/(?:less than or equal to|at most|maximum(?: allowed)?|max(?:imum)?(?: value)?|<=)\D{0,24}(\d+)/i,
|
|
115
121
|
/(?:上限|最大(?:值|输出)?)[^\d]{0,16}(\d+)/i,
|
|
@@ -306,7 +312,32 @@ export async function fetchWithOpenAICompatibility(fetchImpl, input, init, conte
|
|
|
306
312
|
prompt: context.prompt,
|
|
307
313
|
})
|
|
308
314
|
let requestBody = prepared.body
|
|
309
|
-
|
|
315
|
+
// The official OVH VLM API caps the *whole HTTP JSON body* at 10 MB.
|
|
316
|
+
// An image under downscaleMaxPixels can still exceed this after base64,
|
|
317
|
+
// and several smaller images can exceed it together. Refuse the doomed
|
|
318
|
+
// request before network egress; never silently degrade OCR quality or
|
|
319
|
+
// apply this vendor-specific limit to a user's other HTTP providers.
|
|
320
|
+
const ovhUrl = asUrl(url)
|
|
321
|
+
const isOfficialOvhVlm = ovhUrl?.protocol === 'https:' &&
|
|
322
|
+
ovhUrl.hostname === 'oai.endpoints.kepler.ai.cloud.ovh.net' &&
|
|
323
|
+
ovhUrl.port === ''
|
|
324
|
+
const serializeWireBody = (body) => {
|
|
325
|
+
const wire = JSON.stringify(body)
|
|
326
|
+
if (isOfficialOvhVlm && Array.isArray(body.messages) &&
|
|
327
|
+
body.messages.some((message) => Array.isArray(message?.content) &&
|
|
328
|
+
message.content.some((block) => block?.type === 'image_url'))) {
|
|
329
|
+
const bytes = Buffer.byteLength(wire, 'utf8')
|
|
330
|
+
if (bytes > OVH_VLM_MAX_JSON_BYTES) {
|
|
331
|
+
const error = new Error(
|
|
332
|
+
`OVHcloud VLM request is ${bytes} bytes, above its 10 MB JSON payload limit; reduce the image file size or image count before retrying`,
|
|
333
|
+
)
|
|
334
|
+
error.code = 'INVALID_REQUEST'
|
|
335
|
+
throw error
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return wire
|
|
339
|
+
}
|
|
340
|
+
let response = await requestFetch(input, { ...init, body: serializeWireBody(requestBody) })
|
|
310
341
|
|
|
311
342
|
for (let correction = 0; correction < 2; correction++) {
|
|
312
343
|
if (response.ok || (response.status !== 400 && response.status !== 422)) return response
|
|
@@ -323,7 +354,7 @@ export async function fetchWithOpenAICompatibility(fetchImpl, input, init, conte
|
|
|
323
354
|
}
|
|
324
355
|
|
|
325
356
|
requestBody = retryBody
|
|
326
|
-
response = await requestFetch(input, { ...init, body:
|
|
357
|
+
response = await requestFetch(input, { ...init, body: serializeWireBody(requestBody) })
|
|
327
358
|
}
|
|
328
359
|
|
|
329
360
|
return response
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto'
|
|
2
2
|
import { createCachedUpdateChecker } from './update-check.js'
|
|
3
|
+
import { isLocalUiRequest } from './web-capability-boundary.js'
|
|
3
4
|
import { detectDshSelfUpdatePlan, runDshPluginUpdate } from './self-update.js'
|
|
4
5
|
|
|
5
6
|
function json(res, status, body, headers = {}) {
|
|
@@ -66,7 +67,12 @@ export function installVisionMaintenanceRoutes(ctx, options = {}) {
|
|
|
66
67
|
res.end()
|
|
67
68
|
return
|
|
68
69
|
}
|
|
69
|
-
|
|
70
|
+
// Forced refresh causes outbound Host network traffic. Remote Web may
|
|
71
|
+
// read already-cached update status, but must never bypass the cache
|
|
72
|
+
// with ?force=1. Reuse the existing local-UI provenance boundary;
|
|
73
|
+
// do not trust the query string or caller-supplied proxy headers.
|
|
74
|
+
const requestedForce = /(?:[?&])force=1(?:&|$)/.test(String(req.url ?? ''))
|
|
75
|
+
const force = requestedForce && isLocalUiRequest(req)
|
|
70
76
|
const result = await updateChecker.check(force)
|
|
71
77
|
json(res, 200, updateResultForClient(result), { 'cache-control': 'no-store' })
|
|
72
78
|
},
|
|
@@ -23,12 +23,21 @@ export function normalizeVisionRouterMessageSource(message, session) {
|
|
|
23
23
|
if (!message || typeof message !== 'object' || Array.isArray(message)) return message
|
|
24
24
|
if (!isVisionRouterSource(message.source)) return message
|
|
25
25
|
const source = sourceKindForSession(session)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
// A DSH ContextFormed notice needs both form and summary. Keep those two
|
|
27
|
+
// protocol fields across Session V3/V4 attribution normalization, but do
|
|
28
|
+
// not forward arbitrary source properties from a malformed DVR message.
|
|
29
|
+
const notice = message.source.form === 'notice'
|
|
30
|
+
&& typeof message.source.summary === 'string'
|
|
31
|
+
&& message.source.summary.trim().length > 0
|
|
32
|
+
const normalized = {
|
|
33
|
+
...source,
|
|
34
|
+
...(notice ? { form: 'notice', summary: message.source.summary } : {}),
|
|
35
|
+
}
|
|
36
|
+
if (Object.keys(message.source).length === Object.keys(normalized).length
|
|
37
|
+
&& Object.entries(normalized).every(([key, value]) => message.source[key] === value)) {
|
|
29
38
|
return message
|
|
30
39
|
}
|
|
31
|
-
return { ...message, source:
|
|
40
|
+
return { ...message, source: normalized }
|
|
32
41
|
}
|
|
33
42
|
|
|
34
43
|
function normalizeMessageList(list, session) {
|
package/lib/sharp-runtime.js
CHANGED
|
@@ -2,8 +2,6 @@ import z from '@deepseek-ai/schemastery'
|
|
|
2
2
|
import { mkdir, writeFile, readFile, unlink } from 'node:fs/promises'
|
|
3
3
|
import path from 'node:path'
|
|
4
4
|
import { tmpdir } from 'node:os'
|
|
5
|
-
import { DeepSeekAdapter, resolveAdapterOptions } from '@deepseek-ai/dsh-llm-deepseek'
|
|
6
|
-
import { getOrCreateAnonymousUserId } from '@deepseek-ai/dsh-anonymous-user-id'
|
|
7
5
|
import { existsSync } from 'node:fs'
|
|
8
6
|
import { execFile } from 'node:child_process'
|
|
9
7
|
import { Worker } from 'node:worker_threads'
|
|
@@ -174,7 +174,7 @@ async function toOpenAIMessages(ctx, messages) {
|
|
|
174
174
|
return out
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
async function resolvedHostInfo(llm, call) {
|
|
177
|
+
export async function resolvedHostInfo(llm, call) {
|
|
178
178
|
if (typeof llm?.prepareCall === 'function') {
|
|
179
179
|
try {
|
|
180
180
|
const prepared = await llm.prepareCall(
|
|
@@ -195,7 +195,7 @@ async function resolvedHostInfo(llm, call) {
|
|
|
195
195
|
return undefined
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
function localOnlyVisionCallAllowed(core, config, provider, model) {
|
|
198
|
+
export function localOnlyVisionCallAllowed(core, config, provider, model) {
|
|
199
199
|
if (config?.localOnlyVision !== true) return true
|
|
200
200
|
if (provider !== 'vision-http') return false
|
|
201
201
|
const allowed = []
|
|
@@ -346,7 +346,7 @@ function llmWithRuntimePolicy(ctx, llm, options) {
|
|
|
346
346
|
plan.reason,
|
|
347
347
|
)
|
|
348
348
|
yield* failureStream(
|
|
349
|
-
`vision backend ${provider}/${model} is declared text-only by the Host
|
|
349
|
+
`vision backend ${provider}/${model} is declared text-only by the Host, which strips image pixels before the registered adapter runs; no safe HTTP image bridge is available. If this endpoint really supports images, enable Image under DSH Settings > Models > provider > Customized settings > Model options > Input types (when available); on older Hosts set the provider-specific model field (llm-pi-ai: input: [text, image]; llm-deepseek: inputModalities: [text, image]), then reload model configuration. Otherwise choose a declared image-capable backend. Direct bridging is supported only for verified HTTP OpenAI Chat Completions endpoints.`,
|
|
350
350
|
)
|
|
351
351
|
return
|
|
352
352
|
}
|
|
@@ -10,6 +10,7 @@ import { resolveVisionRoutingAuthority } from './vision-routing-authority.js'
|
|
|
10
10
|
import { redactDiagnosticText } from './diagnostic-redaction.js'
|
|
11
11
|
import { installVisionExactCheckClient } from './vision-exact-check-client.js'
|
|
12
12
|
import { createImageInputVerdictStore } from './vision-image-input-verdict.js'
|
|
13
|
+
import { hostImageDeliveryFromInfo, localOnlyVisionCallAllowed, resolvedHostInfo } from './vision-backend-runtime-policy.js'
|
|
13
14
|
import { createBackgroundBenchmarkStopStore } from './vision-background-stop-store.js'
|
|
14
15
|
import { backgroundFailurePolicy } from './vision-background-failure-policy.js'
|
|
15
16
|
import { isLocalUiRequest } from './web-capability-boundary.js'
|
|
@@ -288,9 +289,18 @@ function candidateBlockedByFailure(backoff, candidate, at) {
|
|
|
288
289
|
return false
|
|
289
290
|
}
|
|
290
291
|
|
|
291
|
-
async function
|
|
292
|
+
async function currentHostImageDelivery(ctx, provider, model) {
|
|
293
|
+
if (provider === 'vision-http') return 'native-image'
|
|
294
|
+
return hostImageDeliveryFromInfo(await resolvedHostInfo(ctx?.llm, { provider, model }))
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
async function imageVerdictFor(imageVerdictStore, candidate, ctx) {
|
|
292
298
|
if (!candidate?.endpointFingerprint || typeof imageVerdictStore?.get !== 'function') return undefined
|
|
293
|
-
try {
|
|
299
|
+
try {
|
|
300
|
+
const verdict = await imageVerdictStore.get(candidate.endpointFingerprint)
|
|
301
|
+
if (!verdict || verdict.hostMode !== 'native-image') return undefined
|
|
302
|
+
return await currentHostImageDelivery(ctx, candidate.provider, candidate.model) === 'native-image' ? verdict : undefined
|
|
303
|
+
} catch { return undefined }
|
|
294
304
|
}
|
|
295
305
|
|
|
296
306
|
async function chooseNextWork({ ctx, config, core, store, now, backoff, excluded, imageVerdictStore, backgroundStopStore }) {
|
|
@@ -302,7 +312,7 @@ async function chooseNextWork({ ctx, config, core, store, now, backoff, excluded
|
|
|
302
312
|
await restorePersistentStops(backoff, collected, backgroundStopStore, ctx, now)
|
|
303
313
|
const candidates = []
|
|
304
314
|
for (const candidate of collected) {
|
|
305
|
-
const verdict = await imageVerdictFor(imageVerdictStore, candidate)
|
|
315
|
+
const verdict = await imageVerdictFor(imageVerdictStore, candidate, ctx)
|
|
306
316
|
if (verdict?.state === 'unsupported') {
|
|
307
317
|
excluded.set(candidate.key, { key: candidate.key, reason: 'measured-text-only' })
|
|
308
318
|
continue
|
|
@@ -470,6 +480,13 @@ export async function runExactVisionCheck({ ctx, config, core, store, provider,
|
|
|
470
480
|
const wantedModel = typeof model === 'string' ? model.trim() : ''
|
|
471
481
|
if (!wantedProvider || !wantedModel) throw Object.assign(new Error('provider and model are required'), { code: 'VISION_CHECK_BACKEND_REQUIRED' })
|
|
472
482
|
const current = activeSettings(ctx, config)
|
|
483
|
+
if (!localOnlyVisionCallAllowed(core, current, wantedProvider, wantedModel)) {
|
|
484
|
+
const error = new Error('local-only vision policy prevents testing a nonlocal backend')
|
|
485
|
+
error.code = 'VISION_LOCAL_ONLY_POLICY'
|
|
486
|
+
error.benchmarkClass = 'host-configuration'
|
|
487
|
+
throw error
|
|
488
|
+
}
|
|
489
|
+
const declaredBefore = await currentHostImageDelivery(ctx, wantedProvider, wantedModel)
|
|
473
490
|
const candidates = await collectVisionRoutingCandidates(ctx, current, core, store)
|
|
474
491
|
const candidate = candidates.find((entry) => entry?.provider === wantedProvider && entry?.model === wantedModel)
|
|
475
492
|
?? exactAdapterCandidate(ctx, core, wantedProvider, wantedModel)
|
|
@@ -513,6 +530,12 @@ export async function runExactVisionCheck({ ctx, config, core, store, provider,
|
|
|
513
530
|
remaining(),
|
|
514
531
|
'exact image check timed out',
|
|
515
532
|
)
|
|
533
|
+
if (declaredBefore !== await currentHostImageDelivery(ctx, wantedProvider, wantedModel)) {
|
|
534
|
+
const error = new Error('Host image-input declaration changed during the test; retest the model')
|
|
535
|
+
error.code = 'VISION_CHECK_STALE_CONFIG'
|
|
536
|
+
error.benchmarkClass = 'host-configuration'
|
|
537
|
+
throw error
|
|
538
|
+
}
|
|
516
539
|
return {
|
|
517
540
|
ok: true,
|
|
518
541
|
key: candidate.key,
|
|
@@ -602,13 +625,15 @@ export function createBackgroundCapabilityProfiler({
|
|
|
602
625
|
excluded.set(candidate.key, { key: candidate.key, reason: 'measured-text-only' })
|
|
603
626
|
clearDeferredForCandidate(candidate)
|
|
604
627
|
await clearPersistentStopsForCandidate(candidate)
|
|
605
|
-
if (candidate.endpointFingerprint && typeof imageVerdictStore?.markUnsupported === 'function'
|
|
628
|
+
if (candidate.endpointFingerprint && typeof imageVerdictStore?.markUnsupported === 'function'
|
|
629
|
+
&& await currentHostImageDelivery(ctx, candidate.provider, candidate.model) === 'native-image') {
|
|
606
630
|
try {
|
|
607
631
|
await imageVerdictStore.markUnsupported({
|
|
608
632
|
fingerprint: candidate.endpointFingerprint,
|
|
609
633
|
key: candidate.key,
|
|
610
634
|
provider: candidate.provider,
|
|
611
635
|
model: candidate.model,
|
|
636
|
+
hostMode: 'native-image',
|
|
612
637
|
measuredAt: Number(now()),
|
|
613
638
|
})
|
|
614
639
|
} catch (error) {
|
|
@@ -1140,7 +1165,9 @@ export function installBackgroundCapabilityProfiling(ctx, config, core, store, o
|
|
|
1140
1165
|
const timedOut = error?.name === 'TimeoutError' || error?.name === 'AbortError' || /timed out|timeout|deadline/i.test(String(error?.message ?? ''))
|
|
1141
1166
|
const failureClass = error?.benchmarkClass ?? classifyCapabilityBenchmarkFailure(error)
|
|
1142
1167
|
const unsupportedImage = !timedOut && failureClass === 'unsupported-image'
|
|
1143
|
-
if (unsupportedImage
|
|
1168
|
+
if (unsupportedImage && await currentHostImageDelivery(ctx, body.provider, body.model) === 'native-image') {
|
|
1169
|
+
await profiler.recordImageUnsupported(body.provider, body.model)
|
|
1170
|
+
}
|
|
1144
1171
|
const code = timedOut
|
|
1145
1172
|
? 'VISION_CHECK_TIMEOUT'
|
|
1146
1173
|
: unsupportedImage
|
|
@@ -1151,6 +1178,7 @@ export function installBackgroundCapabilityProfiling(ctx, config, core, store, o
|
|
|
1151
1178
|
'VISION_CHECK_INVALID_JSON',
|
|
1152
1179
|
'VISION_CHECK_BACKEND_REQUIRED',
|
|
1153
1180
|
'VISION_CHECK_BACKEND_STALE',
|
|
1181
|
+
'VISION_CHECK_STALE_CONFIG',
|
|
1154
1182
|
]).has(code)
|
|
1155
1183
|
sendJson(res, unsupportedImage ? 422 : clientError ? 400 : 502, {
|
|
1156
1184
|
ok: false,
|