@ninkch/dsh-infinite-canvas 0.19.14 → 0.19.15

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.
Files changed (2) hide show
  1. package/client.js +72 -24
  2. package/package.json +1 -1
package/client.js CHANGED
@@ -5992,6 +5992,40 @@ function queueThumb(assetId) {
5992
5992
  ?? (j.data && (j.data.task_id ?? j.data.id ?? j.data.taskId))
5993
5993
  ?? (j.output && (j.output.task_id ?? j.output.id));
5994
5994
  }
5995
+ /** 中转站常见的一类 5xx:图片被交给内部图片代理后,代理只认 http(s) URL。
5996
+ * 文档与实测表明同一网关支持 dataURL,只是字段形态不同(input_reference / images:string[])。
5997
+ * 只识别这一类错误,鉴权/限流/内容安全等错误绝不重试。 */
5998
+ function needsSimpleMediaRetry(errText) {
5999
+ const t = String(errText || '');
6000
+ return /图片接口代理请求失败|需要\s*https?(?:\(s\))?\s*接口\s*url|image\s+(?:proxy|api).*?\burl\b/i.test(t);
6001
+ }
6002
+ /** 通用简化媒体请求体:不绑定任何厂商;首帧用 input_reference,参考图用字符串 dataURL 数组。
6003
+ * 带参考音频时统一走 media[](reference_image / reference_audio),首帧同时存在也降级为参考图,
6004
+ * 避免 first_frame 与 reference_* 互斥。 */
6005
+ function buildSimpleMediaRetryBody(base, media) {
6006
+ const b = base || {};
6007
+ const m = media || {};
6008
+ const frame = String(m.frameDataUrl || '');
6009
+ const refs = (Array.isArray(m.refDataUrls) ? m.refDataUrls : []).map(String).filter(Boolean);
6010
+ const audios = (Array.isArray(m.audioDataUrls) ? m.audioDataUrls : []).map(String).filter(Boolean);
6011
+ const out = {
6012
+ ...(b.model ? { model: b.model } : {}),
6013
+ prompt: String(b.prompt || ''),
6014
+ duration: Math.max(2, Math.min(30, Math.round(Number(b.duration) || 5))),
6015
+ resolution: String(b.resolution || '720P').toUpperCase(),
6016
+ ratio: String(b.ratio || '16:9'),
6017
+ };
6018
+ const images = (frame ? [frame] : []).concat(refs);
6019
+ if (audios.length) {
6020
+ out.media = images.map((url) => ({ type: 'reference_image', url }))
6021
+ .concat(audios.map((url) => ({ type: 'reference_audio', url })));
6022
+ } else if (frame && !refs.length) {
6023
+ out.input_reference = frame;
6024
+ } else if (images.length) {
6025
+ out.images = images;
6026
+ }
6027
+ return out;
6028
+ }
5995
6029
  async function downloadVideo(url, headers, authFallback) {
5996
6030
  // 经 Host 代理:签名下载直连同样会被 CORS 拦
5997
6031
  let r = await fetchViaProxy(url, { method: 'GET', headers: headers || {}, timeoutMs: 300000, label: '下载视频' });
@@ -6759,15 +6793,7 @@ function queueThumb(assetId) {
6759
6793
  const isOpenaiVideo = /\/video\/generations$/.test(base);
6760
6794
  // moyu 类中转站:OpenAI 风格但图片字段用 input_reference / images:string[](dataURL 直接放),
6761
6795
  // 不收 [{url,role}] 对象数组;resolution 用大写枚举;无 generate_audio/output_format 参数。
6762
- const isMoyuFlavor = /moyu\.info/i.test(base);
6763
- // moyu 的图片代理接受「裸 base64」或「http(s) URL」,但【不认 data: 前缀】——
6764
- // dataURL 的前缀会让它的 URL 校验失败(0.19.13 实测 502「需要 http(s) 接口 url」)。
6765
- const moyuImagePayload = (dataUrl) => {
6766
- const t = String(dataUrl || '');
6767
- const m = /^data:[^;]+;base64,(.+)$/.exec(t);
6768
- return m ? m[1] : t;
6769
- };
6770
- const headers = { 'Content-Type': 'application/json', ...(s.apiKey ? { Authorization: 'Bearer ' + s.apiKey } : {}) };
6796
+ const headers = { 'Content-Type': 'application/json', ...(s.apiKey ? { Authorization: 'Bearer ' + s.apiKey } : {}) };
6771
6797
  // 尾帧+参考图同连(跨镜衔接)→ 尾帧降级为第一张衔接参考图(first_frame/reference_image 互斥),标注写在提示词里
6772
6798
  const vRefs = o.hardFrame ? [] : (o.refs || []).slice(0, 8);
6773
6799
  const downgrade = Boolean(frameBlob && vRefs.length);
@@ -6775,30 +6801,22 @@ function queueThumb(assetId) {
6775
6801
  const body = {
6776
6802
  ...(s.model ? { model: s.model } : {}),
6777
6803
  prompt,
6778
- duration: Math.min(30, Math.max(2, Number(o.duration) || 5)),
6804
+ duration: Number(o.duration) || 5,
6779
6805
  // 分辨率一律小写(Seedance 系为 '720p'/'1080p';'720P' 会被部分网关判为不支持)
6780
6806
  resolution: (o.resolution || '720p').toLowerCase(),
6781
6807
  ratio: o.ratio || '16:9',
6782
6808
  };
6783
- if (isMoyuFlavor) body.resolution = String(o.resolution || '1080P').toUpperCase(); // moyu 枚举 480P/720P/1080P
6784
6809
  // 首帧图生视频:构图以首帧为准——Seedance 系要求首帧模式必须 ratio=adaptive(仅纯首帧模式)
6785
6810
  if (frameBlob && !downgrade) {
6786
6811
  body.ratio = 'adaptive';
6787
- if (isMoyuFlavor) body.input_reference = moyuImagePayload(await blobToDataUrlScaled(frameBlob));
6788
- else try { body.image = await blobToDataUrlScaled(frameBlob); } catch { /* 忽略首帧编码失败 */ }
6812
+ try { body.image = await blobToDataUrlScaled(frameBlob); } catch { /* 忽略首帧编码失败 */ }
6789
6813
  } else if (vRefs.length) {
6790
6814
  const imgs = downgrade ? [frameBlob].concat(vRefs) : vRefs;
6791
- body.images = isMoyuFlavor
6792
- ? await Promise.all(imgs.map(async (b) => moyuImagePayload(await blobToDataUrlScaled(b))))
6793
- : isOpenaiVideo
6794
- ? await Promise.all(imgs.map(async (b) => ({ url: await blobToDataUrlScaled(b), role: 'reference_image' })))
6795
- : await Promise.all(imgs.map((b) => blobToDataUrlScaled(b)));
6815
+ body.images = await Promise.all(imgs.map(async (b) => ({ url: await blobToDataUrlScaled(b), role: 'reference_image' })));
6796
6816
  }
6797
6817
  // 可选参数:勾选才发送 generate_audio;output_format 留空不发送
6798
- if (!isMoyuFlavor) {
6799
- if (s.generateAudio === true) body.generate_audio = true;
6800
- if (String(s.outputFormat || '').trim()) body.output_format = String(s.outputFormat).trim();
6801
- }
6818
+ if (s.generateAudio === true) body.generate_audio = true;
6819
+ if (String(s.outputFormat || '').trim()) body.output_format = String(s.outputFormat).trim();
6802
6820
  // 角色声音参考(@引用实体名下的音频资产)→ audios[]:模型生成的对白/声音向参考音色对齐;
6803
6821
  // 带声音参考时强制开启同步音频(否则参考无意义)
6804
6822
  if (o.audioRefs && o.audioRefs.length) {
@@ -6810,7 +6828,37 @@ function queueThumb(assetId) {
6810
6828
  const extra = parseExtraParams(s.extra);
6811
6829
  if (extra) Object.assign(body, extra);
6812
6830
  } catch (e) { throw new Error('视频 API 扩展参数配置有误:' + ((e && e.message) || e)); }
6813
- const res = await fetchViaProxy(base, { headers, body, timeoutMs: Number(s.timeoutMs) > 0 ? Number(s.timeoutMs) : 120000, label: '视频 API' });
6831
+ const res0 = await fetchViaProxy(base, { headers, body, timeoutMs: Number(s.timeoutMs) > 0 ? Number(s.timeoutMs) : 120000, label: '视频 API' });
6832
+ let res = res0;
6833
+ // 通用兜底:不新增厂商。首帧/image/images 对象被中转站内部图片代理拒绝时,
6834
+ // 只把参考素材改成文档支持的简单字段再试一次:首帧→input_reference,
6835
+ // 参考图→images 字符串数组(带音频时→media[])。
6836
+ if (!res.ok && needsSimpleMediaRetry(res.text) && (frameBlob || vRefs.length)) {
6837
+ const frameDataUrl = frameBlob ? await blobToDataUrlScaled(frameBlob) : '';
6838
+ const refDataUrls = await Promise.all(vRefs.map((b) => blobToDataUrlScaled(b)));
6839
+ const audioDataUrls = await Promise.all((o.audioRefs || []).map((b) => blobToDataUrl(b)));
6840
+ const simpleBody = buildSimpleMediaRetryBody({
6841
+ model: s.model || '',
6842
+ prompt,
6843
+ duration: Number(o.duration) || 5,
6844
+ resolution: o.resolution || '720P',
6845
+ ratio: body.ratio || o.ratio || '16:9',
6846
+ }, { frameDataUrl, refDataUrls, audioDataUrls });
6847
+ // 扩展参数仍然优先,允许中转站在兜底请求上继续覆盖字段
6848
+ try {
6849
+ const extra = parseExtraParams(s.extra);
6850
+ if (extra) Object.assign(simpleBody, extra);
6851
+ } catch { /* 主请求已校验过,不因兜底阻断 */ }
6852
+ try {
6853
+ res = await fetchViaProxy(base, { headers, body: simpleBody, timeoutMs: Number(s.timeoutMs) > 0 ? Number(s.timeoutMs) : 120000, label: '视频 API(简化参考字段重试)' });
6854
+ } catch (e) {
6855
+ throw new Error('视频 API 请求失败,简化参考字段重试也失败:' + ((e && e.message) || e));
6856
+ }
6857
+ if (!res.ok) {
6858
+ throw new Error('视频 API HTTP ' + res0.status + ' @ ' + base + ':' + res0.text.slice(0, 160)
6859
+ + ';[简化参考字段重试] HTTP ' + res.status + ':' + res.text.slice(0, 200));
6860
+ }
6861
+ }
6814
6862
  if (!res.ok) {
6815
6863
  if (isOpenaiVideo) {
6816
6864
  // 降级链:① Seedance 原生 content[] 格式(RelayRouter 等,轮询 /v1/video/query)
@@ -20105,7 +20153,7 @@ const DIRECTOR_KEY_HELP = [
20105
20153
  // IC-04:参考图上传三件套的纯函数出口(供 scripts/test-image-upload.mjs 直接断言)
20106
20154
  window.__DSH_IC_IMGREF__ = { rawImageDims, sniffImageEncoding, registerReferenceAsset };
20107
20155
  // IC-03:视频厂商识别/前缀归一化的纯函数出口(供 scripts/test-vendor-detect.mjs 直接断言)
20108
- window.__DSH_IC_VENDOR__ = { detectVideoVendor, gatewayPrefixFor, wanEndpoints, vendorBase, VIDEO_REF_CAPS };
20156
+ window.__DSH_IC_VENDOR__ = { detectVideoVendor, gatewayPrefixFor, wanEndpoints, vendorBase, VIDEO_REF_CAPS, needsSimpleMediaRetry, buildSimpleMediaRetryBody };
20109
20157
  // 按镜头切段(分段生成本身就是最容易出错的地方):规划器 + 强弱模型分流 + 节点段区间解析
20110
20158
  // 供 scripts/test-segment-plan.mjs 直接断言
20111
20159
  window.__DSH_IC_SEGMENT__ = { planShotSegments, isCutPoint, segmentNeedsHardFrame, videoSegmentOf, shotContinuityPlan };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ninkch/dsh-infinite-canvas",
3
- "version": "0.19.14",
3
+ "version": "0.19.15",
4
4
  "description": "无限画布(Infinite Canvas)for DeepSeek Harness:节点式创作工作室(剧本/分镜/生成/成片),内置「媒体创作」预设模式(导演第一视角 + 引导工作坊)。Version-agnostic: reads the live catalog from the installed package at load time.",
5
5
  "keywords": [
6
6
  "dsh",