@ninkch/dsh-infinite-canvas 0.19.13 → 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.
- package/client.js +115 -17
- 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,8 +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
|
-
|
|
6763
|
-
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 } : {}) };
|
|
6764
6797
|
// 尾帧+参考图同连(跨镜衔接)→ 尾帧降级为第一张衔接参考图(first_frame/reference_image 互斥),标注写在提示词里
|
|
6765
6798
|
const vRefs = o.hardFrame ? [] : (o.refs || []).slice(0, 8);
|
|
6766
6799
|
const downgrade = Boolean(frameBlob && vRefs.length);
|
|
@@ -6768,30 +6801,22 @@ function queueThumb(assetId) {
|
|
|
6768
6801
|
const body = {
|
|
6769
6802
|
...(s.model ? { model: s.model } : {}),
|
|
6770
6803
|
prompt,
|
|
6771
|
-
duration:
|
|
6804
|
+
duration: Number(o.duration) || 5,
|
|
6772
6805
|
// 分辨率一律小写(Seedance 系为 '720p'/'1080p';'720P' 会被部分网关判为不支持)
|
|
6773
6806
|
resolution: (o.resolution || '720p').toLowerCase(),
|
|
6774
6807
|
ratio: o.ratio || '16:9',
|
|
6775
6808
|
};
|
|
6776
|
-
if (isMoyuFlavor) body.resolution = String(o.resolution || '1080P').toUpperCase(); // moyu 枚举 480P/720P/1080P
|
|
6777
6809
|
// 首帧图生视频:构图以首帧为准——Seedance 系要求首帧模式必须 ratio=adaptive(仅纯首帧模式)
|
|
6778
6810
|
if (frameBlob && !downgrade) {
|
|
6779
6811
|
body.ratio = 'adaptive';
|
|
6780
|
-
|
|
6781
|
-
else try { body.image = await blobToDataUrlScaled(frameBlob); } catch { /* 忽略首帧编码失败 */ }
|
|
6812
|
+
try { body.image = await blobToDataUrlScaled(frameBlob); } catch { /* 忽略首帧编码失败 */ }
|
|
6782
6813
|
} else if (vRefs.length) {
|
|
6783
6814
|
const imgs = downgrade ? [frameBlob].concat(vRefs) : vRefs;
|
|
6784
|
-
body.images =
|
|
6785
|
-
? await Promise.all(imgs.map((b) => blobToDataUrlScaled(b)))
|
|
6786
|
-
: isOpenaiVideo
|
|
6787
|
-
? await Promise.all(imgs.map(async (b) => ({ url: await blobToDataUrlScaled(b), role: 'reference_image' })))
|
|
6788
|
-
: 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' })));
|
|
6789
6816
|
}
|
|
6790
6817
|
// 可选参数:勾选才发送 generate_audio;output_format 留空不发送
|
|
6791
|
-
if (
|
|
6792
|
-
|
|
6793
|
-
if (String(s.outputFormat || '').trim()) body.output_format = String(s.outputFormat).trim();
|
|
6794
|
-
}
|
|
6818
|
+
if (s.generateAudio === true) body.generate_audio = true;
|
|
6819
|
+
if (String(s.outputFormat || '').trim()) body.output_format = String(s.outputFormat).trim();
|
|
6795
6820
|
// 角色声音参考(@引用实体名下的音频资产)→ audios[]:模型生成的对白/声音向参考音色对齐;
|
|
6796
6821
|
// 带声音参考时强制开启同步音频(否则参考无意义)
|
|
6797
6822
|
if (o.audioRefs && o.audioRefs.length) {
|
|
@@ -6803,7 +6828,37 @@ function queueThumb(assetId) {
|
|
|
6803
6828
|
const extra = parseExtraParams(s.extra);
|
|
6804
6829
|
if (extra) Object.assign(body, extra);
|
|
6805
6830
|
} catch (e) { throw new Error('视频 API 扩展参数配置有误:' + ((e && e.message) || e)); }
|
|
6806
|
-
const
|
|
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
|
+
}
|
|
6807
6862
|
if (!res.ok) {
|
|
6808
6863
|
if (isOpenaiVideo) {
|
|
6809
6864
|
// 降级链:① Seedance 原生 content[] 格式(RelayRouter 等,轮询 /v1/video/query)
|
|
@@ -9165,7 +9220,46 @@ function queueThumb(assetId) {
|
|
|
9165
9220
|
data,
|
|
9166
9221
|
};
|
|
9167
9222
|
}
|
|
9223
|
+
/**
|
|
9224
|
+
* 客户端建点布局(与 Host nextNodePos 同一套算法,代码级强控制):
|
|
9225
|
+
* ① 一类型一列:同类型已有节点 → x 对齐该列(取最小 x),y 追加到列尾(最大 bottom + 40);
|
|
9226
|
+
* ② 该类型第一个节点 → 用调用者给的 pos 起新列;
|
|
9227
|
+
* ③ 碰撞下移:候选框(含 28px 最小间距)与任何节点相交 → 自动下移到相交节点下方,绝不重叠;
|
|
9228
|
+
* ④ 上限 80 轮防死循环。
|
|
9229
|
+
* 调用者传入的 pos 只用于"起新列",不用于自由摆放——布局纪律由代码保证,
|
|
9230
|
+
* 不依赖调用者(对话框/工具条/快捷键)自觉。
|
|
9231
|
+
*/
|
|
9232
|
+
function nextNodePosClient(type, pos, size) {
|
|
9233
|
+
const GAP_X = 60, GAP_Y = 40, MIN_GAP = 28;
|
|
9234
|
+
const H = (n) => Number(n && n.h) || 160;
|
|
9235
|
+
const W = (n) => Number(n && n.w) || 280;
|
|
9236
|
+
const nodes = Object.values(S.graph.nodes);
|
|
9237
|
+
const estH = (size && Number(size.h)) || 360;
|
|
9238
|
+
const estW = (size && Number(size.w)) || 360;
|
|
9239
|
+
const same = nodes.filter((n) => n.type === type && n.type !== 'group');
|
|
9240
|
+
let x = Math.round((pos && pos.x) || 80);
|
|
9241
|
+
let y = Math.round((pos && pos.y) || 40);
|
|
9242
|
+
if (same.length) {
|
|
9243
|
+
x = Math.min(...same.map((n) => n.x || 0));
|
|
9244
|
+
y = Math.max(...same.map((n) => (n.y || 0) + H(n))) + GAP_Y;
|
|
9245
|
+
}
|
|
9246
|
+
const hit = (yy) => nodes.find((n) => n.type !== 'group' && !((n.data && n.data.hidden))
|
|
9247
|
+
&& (n.x || 0) < x + estW + MIN_GAP && (n.x || 0) + W(n) + MIN_GAP > x
|
|
9248
|
+
&& (n.y || 0) < yy + estH + MIN_GAP && (n.y || 0) + H(n) + MIN_GAP > yy);
|
|
9249
|
+
let blocker = hit(y);
|
|
9250
|
+
let guard = 0;
|
|
9251
|
+
while (blocker && guard++ < 80) { y = (blocker.y || 0) + H(blocker) + MIN_GAP; blocker = hit(y); }
|
|
9252
|
+
return { x, y };
|
|
9253
|
+
}
|
|
9254
|
+
|
|
9168
9255
|
function addNodeAt(type, pos) {
|
|
9256
|
+
// 代码级强控制:建点坐标由布局引擎决定(一类型一列 + 碰撞下移),不信任调用者的自由坐标。
|
|
9257
|
+
// 媒体节点外框按比例(与 Host nextNodePos 同口径),其余 360×360。
|
|
9258
|
+
const t2 = normalizeNodeType(type);
|
|
9259
|
+
const sz = (t2 === 'image' || t2 === 'video')
|
|
9260
|
+
? nodeSizeForRatio((pos && pos.ratio) || '16:9', { hasFooter: false })
|
|
9261
|
+
: null;
|
|
9262
|
+
pos = nextNodePosClient(t2, pos, sz);
|
|
9169
9263
|
const n = newNode(type, pos);
|
|
9170
9264
|
update((s) => { s.graph.nodes[n.id] = n; s.sel = new Set([n.id]); s.selEdge = null; });
|
|
9171
9265
|
pushHistory();
|
|
@@ -20012,6 +20106,10 @@ const DIRECTOR_KEY_HELP = [
|
|
|
20012
20106
|
ratioIsValid, ratioAspect, ratioFromDims, mediaRatioOf, mediaAspectOf, mediaRatioForDims,
|
|
20013
20107
|
normalizeMediaNodeSize, normalizeGraphDoc, resizeBoxFor, composerWidthFor,
|
|
20014
20108
|
wheelScrollTarget,
|
|
20109
|
+
// 建点布局强控制(一类型一列 + 碰撞下移):addNodeAt 收口 + 纯函数,供回归测试直接驱动
|
|
20110
|
+
nextNodePosClient, addNodeAt,
|
|
20111
|
+
graph: () => JSON.parse(JSON.stringify(S.graph)), // 建点结果断言用(与 SYNC.graph 同口径)
|
|
20112
|
+
addGraphNodes: (list) => { for (const n of (list || [])) S.graph.nodes[n.id] = n; }, // 测试播种(写入活状态)
|
|
20015
20113
|
// 下拉自定义数值的纯函数:范围夹取 / 整数与小数口径(分镜数、单段上限共用)
|
|
20016
20114
|
clampCustomNumber,
|
|
20017
20115
|
// 视频请求时长策略:手动秒数 vs 分镜节拍(供面板禁用态与请求侧共用)
|
|
@@ -20055,7 +20153,7 @@ const DIRECTOR_KEY_HELP = [
|
|
|
20055
20153
|
// IC-04:参考图上传三件套的纯函数出口(供 scripts/test-image-upload.mjs 直接断言)
|
|
20056
20154
|
window.__DSH_IC_IMGREF__ = { rawImageDims, sniffImageEncoding, registerReferenceAsset };
|
|
20057
20155
|
// IC-03:视频厂商识别/前缀归一化的纯函数出口(供 scripts/test-vendor-detect.mjs 直接断言)
|
|
20058
|
-
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 };
|
|
20059
20157
|
// 按镜头切段(分段生成本身就是最容易出错的地方):规划器 + 强弱模型分流 + 节点段区间解析
|
|
20060
20158
|
// 供 scripts/test-segment-plan.mjs 直接断言
|
|
20061
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.
|
|
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",
|