@ninkch/dsh-infinite-canvas 0.20.1 → 0.20.2

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 (4) hide show
  1. package/client.js +563 -137
  2. package/index.js +548 -93
  3. package/package.json +1 -1
  4. package/production.js +83 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ninkch/dsh-infinite-canvas",
3
- "version": "0.20.1",
3
+ "version": "0.20.2",
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",
package/production.js CHANGED
@@ -20,6 +20,8 @@
20
20
 
21
21
  import { existsSync, readFileSync, mkdirSync, copyFileSync, writeFileSync, renameSync } from 'node:fs';
22
22
  import path from 'node:path';
23
+ // 按镜头切段(client.js planShotSegments 的逐字移植):预算单的 videoCalls 口径与客户端执行同源
24
+ import { planShotSegments } from './shot-segments.js';
23
25
 
24
26
  /** 阶段枚举(顺序即优先级,index 越大越靠后)。 */
25
27
  export const PRODUCTION_STAGES = ['brief', 'bible', 'assets', 'script', 'storyboard', 'shots_ready', 'generating', 'qc', 'post', 'delivered'];
@@ -190,8 +192,53 @@ export function createProduction(deps) {
190
192
  return 'q' + h.toString(36) + '-' + s.length.toString(36);
191
193
  }
192
194
 
195
+ // ── T8(0.20.2 #6/#7):参考图实体收集与「已有参考资产」判定 ──────────────────────────
196
+
197
+ /** 从 shots 收集 角色/场景/道具 实体(trim、去重、保序)。
198
+ * 预算单行项与付费段执行(index.js autoPaid)共用这一份口径——两边各写一份必然漂移,
199
+ * 「预算 N 张 / 实际 M 张」的对照关系靠同构保证。 */
200
+ function collectShotEntities(shots) {
201
+ const out = [];
202
+ const seen = new Set();
203
+ const add = (kind, name) => {
204
+ const nm = String(name || '').trim();
205
+ if (!nm) return;
206
+ const key = kind + '|' + nm;
207
+ if (seen.has(key)) return;
208
+ seen.add(key);
209
+ out.push({ kind, name: nm, key });
210
+ };
211
+ for (const sh of (Array.isArray(shots) ? shots : [])) {
212
+ const chars = Array.isArray(sh && sh.characters) ? sh.characters : [];
213
+ const props = Array.isArray(sh && sh.props) ? sh.props : [];
214
+ for (const nm of chars) add('角色', nm);
215
+ add('场景', sh && sh.scene);
216
+ for (const nm of props) add('道具', nm);
217
+ }
218
+ return out;
219
+ }
220
+
221
+ /** 实体是否已有参考资产:资产名 = 「<品类>-<名>…」且名称后必须是边界(client.js
222
+ * assetBelongsToEntity 同款语义——rest 为空或首字符不是字母/数字,防「张山/张山峰」混淆:
223
+ * 「角色-陈拾 多视图」「角色-陈拾 设定图」算,「角色-陈拾设定图」「角色-陈拾峰」不算)。 */
224
+ function hasRefAssetName(assetNames, kindLabel, name) {
225
+ const pref = kindLabel + '-' + String(name || '').trim();
226
+ return (Array.isArray(assetNames) ? assetNames : []).some((raw) => {
227
+ const nm = String(raw || '').trim();
228
+ if (!nm.startsWith(pref)) return false;
229
+ const rest = nm.slice(pref.length);
230
+ return rest === '' || !/[\p{L}\p{N}]/u.test(rest[0]);
231
+ });
232
+ }
233
+
193
234
  /**
194
- * 预算单(免费段终点):只统计"将要花钱"的东西——每个分镜表一次视频调用、总秒数、场/镜数。
235
+ * 预算单(免费段终点):只统计"将要花钱"的东西——每个分镜表按真实镜头边界切成生成段,
236
+ * 每段一次视频调用(一个分镜表 ≠ 一次生成);总秒数、场/镜数照旧。
237
+ * 0.20.2 T8(#6/#7):每个待生成分镜表加参考图行项 refImages(该场缺失参考资产的
238
+ * 角色/场景/道具 实体数),顶层 refImagesTotal;跨场共享实体只计一次(与执行侧
239
+ * run 级 Map 同序先到先得,归属第一场)。已有参考资产(readAssetIndexNames 边界匹配)的不计。
240
+ * 切段口径与客户端执行完全同源:同一个 planShotSegments(shot-segments.js,client.js 的逐字移植),
241
+ * maxSeconds 同样取分镜表节点 data.segMaxSeconds(缺省 15,client.js L13883 同式)。
195
242
  * 单价由调用方传入(画布设置里的单价,未配置则不给金额,只给调用次数与秒数)。
196
243
  */
197
244
  function quote(pid, cid, unitPricePerSecond) {
@@ -200,33 +247,62 @@ export function createProduction(deps) {
200
247
  const nodes = Object.values(doc.nodes || {});
201
248
  const sbs = nodes.filter((n) => n.type === 'storyboard' && Array.isArray(n.data && n.data.shots) && n.data.shots.length);
202
249
  const videoNodes = nodes.filter((n) => n.type === 'video');
250
+ // 项目资产名(SQL/JSON 双模由宿主 readAssetIndexNames 决定);读失败视为无资产 → 全部计缺(诚实从宽)
251
+ let assetNames = [];
252
+ try { assetNames = (deps.readAssetIndexNames ? (deps.readAssetIndexNames(pid) || []) : []).map((n) => String(n || '').trim()).filter(Boolean); } catch { assetNames = []; }
253
+ const claimed = new Set();
254
+ let refImagesTotal = 0;
203
255
  let totalSeconds = 0;
204
256
  const scenes = sbs.map((n, i) => {
205
257
  const shots = n.data.shots || [];
206
258
  const secs = shots.reduce((a, s) => a + (Number(s && s.duration) || 0), 0);
207
259
  totalSeconds += secs;
260
+ const hasVideo = videoNodes.some((v) => (doc.edges || []).some((e) => e.fromNode === n.id && e.toNode === v.id));
261
+ const maxSeconds = Number(n.data.segMaxSeconds) || 15;
262
+ // 已有视频的表不产生新调用;待生成的表按切段算法数段(与客户端 expandStoryboard 同式同默认)
263
+ let calls = 0;
264
+ let refImages = 0;
265
+ if (!hasVideo) {
266
+ const plan = planShotSegments(shots, { maxSeconds });
267
+ // 客户端兜底同款(L13884):切段结果为空但表里有镜头时,客户端会整表按一段生成——估算按 1 次算
268
+ calls = plan.segments.length ? plan.segments.length : 1;
269
+ // T8 参考图行项:该场缺失参考资产的实体数(跨场共享只计一次)
270
+ for (const ent of collectShotEntities(shots)) {
271
+ if (claimed.has(ent.key)) continue;
272
+ claimed.add(ent.key);
273
+ if (!hasRefAssetName(assetNames, ent.kind, ent.name)) refImages++;
274
+ }
275
+ }
276
+ refImagesTotal += refImages;
208
277
  return {
209
278
  scene: i + 1,
210
279
  storyboardId: n.id,
211
280
  name: String((n.data && n.data.label) || n.id),
212
281
  shots: shots.length,
213
282
  seconds: Math.round(secs * 10) / 10,
214
- hasVideo: videoNodes.some((v) => (doc.edges || []).some((e) => e.fromNode === n.id && e.toNode === v.id)),
283
+ hasVideo,
284
+ maxSeconds,
285
+ videoCalls: calls,
286
+ refImages,
215
287
  };
216
288
  });
217
- const pending = scenes.filter((s) => !s.hasVideo).length;
289
+ const videoCalls = scenes.reduce((a, s) => a + s.videoCalls, 0);
218
290
  const price = Number(unitPricePerSecond);
219
- const payload = { pid, cid: keyOf(cid), scenes: scenes.map((s) => [s.storyboardId, s.shots, s.seconds]), pending };
291
+ // 指纹吃切段结果与每场上限:段数/上限变了 → 旧批准自动失效 → 用户重新复核预算(预期行为,无兼容垫片)
292
+ // T8:参考图行项一并进指纹——缺失实体集合变了(设定集/资产中途变化)同样要求重新复核
293
+ const payload = { pid, cid: keyOf(cid), scenes: scenes.map((s) => [s.storyboardId, s.shots, s.seconds, s.videoCalls, s.maxSeconds, s.refImages]), pending: videoCalls, refImages: refImagesTotal };
294
+ const baseNote = videoCalls === 0 ? '全部分镜表都已有视频节点:本次只做重生成,不产生新调用' : '批准后按镜头切段逐段调用视频接口(按秒计费)';
220
295
  return {
221
296
  ok: true, quoteId: fingerprint(payload),
222
297
  projectId: pid, canvasId: keyOf(cid) === 'default' ? null : keyOf(cid),
223
298
  stage: st.stage,
224
299
  scenes, sceneCount: scenes.length, shotCount: scenes.reduce((a, s) => a + s.shots, 0),
225
300
  totalSeconds: Math.round(totalSeconds * 10) / 10,
226
- videoCalls: pending,
301
+ videoCalls,
302
+ refImagesTotal,
227
303
  unitPricePerSecond: Number.isFinite(price) && price > 0 ? price : null,
228
304
  estimatedCost: Number.isFinite(price) && price > 0 ? Math.round(price * totalSeconds * 100) / 100 : null,
229
- note: pending === 0 ? '全部分镜表都已有视频节点:本次只做重生成,不产生新调用' : '批准后只按差分镜表各调用一次视频接口(按秒计费)',
305
+ note: refImagesTotal > 0 ? baseNote + ';含参考图 ' + refImagesTotal + ' 张(未登记/未生成参考资产的实体)' : baseNote,
230
306
  };
231
307
  }
232
308
 
@@ -422,6 +498,7 @@ export function createProduction(deps) {
422
498
  readState, writeState, inferStage, stageOf, noteStage, advance, recordOverride, status,
423
499
  gateBible, gateStoryboard, gateStage, gateShotNodeName, gateOneVideoPerStoryboard,
424
500
  quote, approve, approvalOf,
501
+ collectShotEntities, hasRefAssetName,
425
502
  stageIndex: (name) => STAGE_INDEX[name], stageName: (idx) => PRODUCTION_STAGES[idx] || null,
426
503
  };
427
504
  }