@ninkch/dsh-infinite-canvas 0.19.12 → 0.19.14

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 +74 -22
  2. package/package.json +1 -1
package/client.js CHANGED
@@ -5979,6 +5979,7 @@ function queueThumb(assetId) {
5979
5979
  j.video && j.video.url,
5980
5980
  j.output && (j.output.url || j.output.video_url),
5981
5981
  j.result && (j.result.url || j.result.video_url),
5982
+ j.data && j.data.result_url,
5982
5983
  // OpenAI 风格视频任务(如 JUAI):完成响应把结果放在 metadata.url
5983
5984
  j.metadata && (j.metadata.url || j.metadata.video_url),
5984
5985
  Array.isArray(j.data) && j.data[0] && (j.data[0].url || j.data[0].video_url),
@@ -6263,22 +6264,12 @@ function queueThumb(assetId) {
6263
6264
  }
6264
6265
  function detectVideoVendor(s) {
6265
6266
  if (!s) return 'openai';
6267
+ // 厂商格式(设置下拉)= 唯一权威路由:选了什么就用什么,模型名绝不参与。
6268
+ // 曾经按模型名猜(wan3.0-video → 误走 DashScope 官方格式),中转站收不到认识的字段直接 502。
6266
6269
  if (s.vendor) return s.vendor;
6267
6270
  const url = String(s.url || '').toLowerCase();
6268
- const model = String(s.model || '').toLowerCase();
6269
- // 模型名优先:第三方网关(relayrouter 等)的 URL 看不出真实厂商,只有模型名能说明
6270
- if (/wanx|万相|(^|[^a-z])wan(\d|[-_]\d|x)/.test(model)) return 'wan';
6271
- if (/minimax-?h3|hailuo-?03/.test(model)) return 'minimaxv2'; // H3 走 V2 协议(必须先于 V1 minimax 判定)
6272
- if (/(^|[^a-z])kling/.test(model)) return 'kling';
6273
- if (/minimax|hailuo/.test(model)) return 'minimax';
6274
- if (/vidu/.test(model)) return 'vidu';
6275
- if (/runway/.test(model)) return 'runway';
6276
- if (/(^|[^a-z])veo/.test(model)) return 'veo';
6277
- if (/luma|ray[-_]?[12]/.test(model)) return 'luma';
6278
- if (/pixverse/.test(model)) return 'pixverse';
6279
- if (/stable-?video|(^|[^a-z])svd/.test(model)) return 'stability';
6280
- if (/seedance/.test(model)) return 'seedance';
6281
- // URL 兜底识别
6271
+ // URL 特征兜底:URL 也是用户显式配置的一部分(旧配置 vendor 字段为空时走这里,
6272
+ // 设置卡片渲染时会按此回填 vendor,之后恒走显式值)。
6282
6273
  if (url.includes('dashscope')) return 'wan';
6283
6274
  if (url.includes('klingai')) return 'kling';
6284
6275
  if (url.includes('minimax')) return 'minimax';
@@ -6766,6 +6757,16 @@ function queueThumb(assetId) {
6766
6757
  if (!base.replace(/^https?:\/\//i, '').includes('/')) base = base + '/v1';
6767
6758
  else if (/\/v1$/.test(base)) base = base + '/video/generations';
6768
6759
  const isOpenaiVideo = /\/video\/generations$/.test(base);
6760
+ // moyu 类中转站:OpenAI 风格但图片字段用 input_reference / images:string[](dataURL 直接放),
6761
+ // 不收 [{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
+ };
6769
6770
  const headers = { 'Content-Type': 'application/json', ...(s.apiKey ? { Authorization: 'Bearer ' + s.apiKey } : {}) };
6770
6771
  // 尾帧+参考图同连(跨镜衔接)→ 尾帧降级为第一张衔接参考图(first_frame/reference_image 互斥),标注写在提示词里
6771
6772
  const vRefs = o.hardFrame ? [] : (o.refs || []).slice(0, 8);
@@ -6774,24 +6775,30 @@ function queueThumb(assetId) {
6774
6775
  const body = {
6775
6776
  ...(s.model ? { model: s.model } : {}),
6776
6777
  prompt,
6777
- duration: Number(o.duration) || 5,
6778
+ duration: Math.min(30, Math.max(2, Number(o.duration) || 5)),
6778
6779
  // 分辨率一律小写(Seedance 系为 '720p'/'1080p';'720P' 会被部分网关判为不支持)
6779
6780
  resolution: (o.resolution || '720p').toLowerCase(),
6780
6781
  ratio: o.ratio || '16:9',
6781
6782
  };
6783
+ if (isMoyuFlavor) body.resolution = String(o.resolution || '1080P').toUpperCase(); // moyu 枚举 480P/720P/1080P
6782
6784
  // 首帧图生视频:构图以首帧为准——Seedance 系要求首帧模式必须 ratio=adaptive(仅纯首帧模式)
6783
6785
  if (frameBlob && !downgrade) {
6784
6786
  body.ratio = 'adaptive';
6785
- try { body.image = await blobToDataUrlScaled(frameBlob); } catch { /* 忽略首帧编码失败 */ }
6787
+ if (isMoyuFlavor) body.input_reference = moyuImagePayload(await blobToDataUrlScaled(frameBlob));
6788
+ else try { body.image = await blobToDataUrlScaled(frameBlob); } catch { /* 忽略首帧编码失败 */ }
6786
6789
  } else if (vRefs.length) {
6787
6790
  const imgs = downgrade ? [frameBlob].concat(vRefs) : vRefs;
6788
- body.images = isOpenaiVideo
6789
- ? await Promise.all(imgs.map(async (b) => ({ url: await blobToDataUrlScaled(b), role: 'reference_image' })))
6790
- : await Promise.all(imgs.map((b) => blobToDataUrlScaled(b)));
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)));
6791
6796
  }
6792
6797
  // 可选参数:勾选才发送 generate_audio;output_format 留空不发送
6793
- if (s.generateAudio === true) body.generate_audio = true;
6794
- if (String(s.outputFormat || '').trim()) body.output_format = String(s.outputFormat).trim();
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
+ }
6795
6802
  // 角色声音参考(@引用实体名下的音频资产)→ audios[]:模型生成的对白/声音向参考音色对齐;
6796
6803
  // 带声音参考时强制开启同步音频(否则参考无意义)
6797
6804
  if (o.audioRefs && o.audioRefs.length) {
@@ -6869,7 +6876,7 @@ function queueThumb(assetId) {
6869
6876
  const DONE = ['succeeded', 'success', 'completed', 'complete', 'done', 'finished'];
6870
6877
  if (status && FAIL.includes(status)) {
6871
6878
  const msg = (st.error && (st.error.message || st.error.msg)) || st.message || st.msg || st.reason
6872
- || (st.data && st.data.error && (st.data.error.message || st.data.error)) || status;
6879
+ || (st.data && (st.data.fail_reason || (st.data.error && (st.data.error.message || st.data.error)))) || status;
6873
6880
  return String(msg).slice(0, 300);
6874
6881
  }
6875
6882
  if (status && DONE.includes(status)) return null; // 成功但没解析出地址:交给调用方超时/后续处理
@@ -9165,7 +9172,46 @@ function queueThumb(assetId) {
9165
9172
  data,
9166
9173
  };
9167
9174
  }
9175
+ /**
9176
+ * 客户端建点布局(与 Host nextNodePos 同一套算法,代码级强控制):
9177
+ * ① 一类型一列:同类型已有节点 → x 对齐该列(取最小 x),y 追加到列尾(最大 bottom + 40);
9178
+ * ② 该类型第一个节点 → 用调用者给的 pos 起新列;
9179
+ * ③ 碰撞下移:候选框(含 28px 最小间距)与任何节点相交 → 自动下移到相交节点下方,绝不重叠;
9180
+ * ④ 上限 80 轮防死循环。
9181
+ * 调用者传入的 pos 只用于"起新列",不用于自由摆放——布局纪律由代码保证,
9182
+ * 不依赖调用者(对话框/工具条/快捷键)自觉。
9183
+ */
9184
+ function nextNodePosClient(type, pos, size) {
9185
+ const GAP_X = 60, GAP_Y = 40, MIN_GAP = 28;
9186
+ const H = (n) => Number(n && n.h) || 160;
9187
+ const W = (n) => Number(n && n.w) || 280;
9188
+ const nodes = Object.values(S.graph.nodes);
9189
+ const estH = (size && Number(size.h)) || 360;
9190
+ const estW = (size && Number(size.w)) || 360;
9191
+ const same = nodes.filter((n) => n.type === type && n.type !== 'group');
9192
+ let x = Math.round((pos && pos.x) || 80);
9193
+ let y = Math.round((pos && pos.y) || 40);
9194
+ if (same.length) {
9195
+ x = Math.min(...same.map((n) => n.x || 0));
9196
+ y = Math.max(...same.map((n) => (n.y || 0) + H(n))) + GAP_Y;
9197
+ }
9198
+ const hit = (yy) => nodes.find((n) => n.type !== 'group' && !((n.data && n.data.hidden))
9199
+ && (n.x || 0) < x + estW + MIN_GAP && (n.x || 0) + W(n) + MIN_GAP > x
9200
+ && (n.y || 0) < yy + estH + MIN_GAP && (n.y || 0) + H(n) + MIN_GAP > yy);
9201
+ let blocker = hit(y);
9202
+ let guard = 0;
9203
+ while (blocker && guard++ < 80) { y = (blocker.y || 0) + H(blocker) + MIN_GAP; blocker = hit(y); }
9204
+ return { x, y };
9205
+ }
9206
+
9168
9207
  function addNodeAt(type, pos) {
9208
+ // 代码级强控制:建点坐标由布局引擎决定(一类型一列 + 碰撞下移),不信任调用者的自由坐标。
9209
+ // 媒体节点外框按比例(与 Host nextNodePos 同口径),其余 360×360。
9210
+ const t2 = normalizeNodeType(type);
9211
+ const sz = (t2 === 'image' || t2 === 'video')
9212
+ ? nodeSizeForRatio((pos && pos.ratio) || '16:9', { hasFooter: false })
9213
+ : null;
9214
+ pos = nextNodePosClient(t2, pos, sz);
9169
9215
  const n = newNode(type, pos);
9170
9216
  update((s) => { s.graph.nodes[n.id] = n; s.sel = new Set([n.id]); s.selEdge = null; });
9171
9217
  pushHistory();
@@ -17975,6 +18021,8 @@ const DIRECTOR_KEY_HELP = [
17975
18021
  kind === 'video' ? h('div', { key: 'vendor', className: 'dshic-field' },
17976
18022
  h('div', { className: 'dshic-row' },
17977
18023
  h('span', { className: 'dshic-field-label' }, T('vendorLabel')),
18024
+ // 旧配置迁移:vendor 字段后加,早期供应商为空 → 按 URL 特征回填一次(此后恒走显式值)
18025
+ (() => { if (!p.vendor) { const d = detectVideoVendor(p); patchProvider(p.id, 'vendor', d); p.vendor = d; } return null; })(),
17978
18026
  InfoTip((VIDEO_VENDORS[detectVideoVendor(p)] || {}).note || '')),
17979
18027
  h('select', {
17980
18028
  className: 'dshic-select', value: detectVideoVendor(p),
@@ -20010,6 +20058,10 @@ const DIRECTOR_KEY_HELP = [
20010
20058
  ratioIsValid, ratioAspect, ratioFromDims, mediaRatioOf, mediaAspectOf, mediaRatioForDims,
20011
20059
  normalizeMediaNodeSize, normalizeGraphDoc, resizeBoxFor, composerWidthFor,
20012
20060
  wheelScrollTarget,
20061
+ // 建点布局强控制(一类型一列 + 碰撞下移):addNodeAt 收口 + 纯函数,供回归测试直接驱动
20062
+ nextNodePosClient, addNodeAt,
20063
+ graph: () => JSON.parse(JSON.stringify(S.graph)), // 建点结果断言用(与 SYNC.graph 同口径)
20064
+ addGraphNodes: (list) => { for (const n of (list || [])) S.graph.nodes[n.id] = n; }, // 测试播种(写入活状态)
20013
20065
  // 下拉自定义数值的纯函数:范围夹取 / 整数与小数口径(分镜数、单段上限共用)
20014
20066
  clampCustomNumber,
20015
20067
  // 视频请求时长策略:手动秒数 vs 分镜节拍(供面板禁用态与请求侧共用)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ninkch/dsh-infinite-canvas",
3
- "version": "0.19.12",
3
+ "version": "0.19.14",
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",