dsh-mo-image 0.6.0 → 1.0.0

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.
@@ -251,7 +251,8 @@ function walkText(graph, startLink, pool) {
251
251
  if (!node) return;
252
252
  const ordered = [...inputEntries(node)].sort(([a], [b]) => rank(a) - rank(b));
253
253
  for (const [name, value] of ordered) {
254
- if (typeof value !== 'string' || value.trim() === '') continue;
254
+ // 空字符串也是字面量:导出和模板里的文本框默认就是空的,跳过它等于让整条角色参数消失。
255
+ if (typeof value !== 'string') continue;
255
256
  pool.push(makeCandidate(id, node, name, value));
256
257
  if (!primary && TEXTISH.test(name)) primary = { node: id, input: name };
257
258
  }
@@ -430,17 +431,20 @@ export function collectParams(graph, mapping, objectInfo) {
430
431
  return TUNABLE_PARAMS.filter((name) => found.has(name)).map((name) => found.get(name));
431
432
  }
432
433
 
433
- /** 默认对对话模型可见的参数:提示词、负面词和尺寸。种子和模型保持隐藏。 */
434
- export const DEFAULT_EXPOSED = new Set(['prompt', 'negative_prompt', 'width', 'height']);
434
+ /**
435
+ * 提示词与负面词不是「可调参数」:它们由工具调用自己的 prompt/negative_prompt
436
+ * 经映射直接写进工作流,始终生效,也不该出现在给模型看的 params 里。
437
+ */
438
+ export const PROMPT_ROLE_NAMES = new Set(['prompt', 'negative_prompt']);
435
439
 
436
440
  /**
437
- * 映射角色也当成参数:提示词、负面词、宽高、种子、模型。
438
- * 它们在工作流里已经有确定位置,和可调参数放进同一张表,但默认只有前四个暴露。
441
+ * 映射角色也当成参数:宽高、种子、模型。
442
+ * 它们在工作流里已经有确定位置,和可调参数放进同一张表,但默认只有能调的那几项需要显式打开。
439
443
  * 类型来自 object_info;值是连线时按输入名推断,避免把 ["19",0] 当成字符串。
440
444
  */
441
445
  export function collectRoleParams(graph, mapping, objectInfo) {
442
446
  const out = [];
443
- for (const key of ['prompt', 'negative_prompt', 'width', 'height', 'seed', 'model']) {
447
+ for (const key of ['width', 'height', 'seed', 'model']) {
444
448
  const target = mapping && mapping[key];
445
449
  if (!target) continue;
446
450
  const node = graph[target.node];
@@ -470,6 +474,75 @@ export function collectRoleParams(graph, mapping, objectInfo) {
470
474
  return out;
471
475
  }
472
476
 
477
+ /* ---------------------------------------------------------- 参数候选 */
478
+
479
+ /**
480
+ * 一行参数的类型推断:只看当前的原始值。
481
+ *
482
+ * API 格式的工作流里没有 widget 元数据(枚举清单、INT/FLOAT 之分都丢了),所以
483
+ * 只能按值来判。判不准时一律按文本处理——文本在注入时会原样写回,不会把数字变成字符串。
484
+ */
485
+ export function inferInputType(value) {
486
+ if (typeof value === 'boolean') return 'boolean';
487
+ if (typeof value === 'number') return 'number';
488
+ if (typeof value === 'string') return 'text';
489
+ return 'text';
490
+ }
491
+
492
+ /** 节点 id 的自然序:`9` 排在 `10` 前面,`18:2` 排在 `18:10` 前面。 */
493
+ function compareNodeIds(a, b) {
494
+ const left = String(a).split(/(\d+)/);
495
+ const right = String(b).split(/(\d+)/);
496
+ for (let i = 0; i < Math.min(left.length, right.length); i += 1) {
497
+ if (left[i] === right[i]) continue;
498
+ const l = /^\d+$/.test(left[i]) ? Number(left[i]) : left[i];
499
+ const r = /^\d+$/.test(right[i]) ? Number(right[i]) : right[i];
500
+ if (typeof l === 'number' && typeof r === 'number') return l - r;
501
+ return String(l) < String(r) ? -1 : 1;
502
+ }
503
+ return left.length - right.length;
504
+ }
505
+
506
+ /** 候选里的「当前值」:对象(少见)序列化成一行 JSON,其余原样。 */
507
+ function scalarOf(value) {
508
+ if (value === null) return '';
509
+ if (typeof value === 'object') {
510
+ try { return JSON.stringify(value); } catch (_error) { return ''; }
511
+ }
512
+ return value;
513
+ }
514
+
515
+ /**
516
+ * 把整张图里「输入是原始值」的项摊成可勾选候选。
517
+ *
518
+ * 连线(`["18:7", 0]`)不算:那是别的节点的输出,写进去会被 ComfyUI 当成坏连线。
519
+ * 每一项的形状就是离散参数表要的那一行(node / input / type / default / name),
520
+ * 勾中后直接进 `modelOptions[m].params`。
521
+ */
522
+ export function listWorkflowInputs(graph) {
523
+ const out = [];
524
+ for (const id of Object.keys(graph || {}).sort(compareNodeIds)) {
525
+ const node = graph[id];
526
+ if (!node || typeof node !== 'object' || !node.inputs) continue;
527
+ const classType = String(node.class_type || '');
528
+ for (const [input, value] of inputEntries(node).slice().sort(([a], [b]) => a.localeCompare(b))) {
529
+ if (isLink(value)) continue;
530
+ if (value === undefined) continue;
531
+ const raw = scalarOf(value);
532
+ out.push({
533
+ node: id,
534
+ input: input,
535
+ name: input,
536
+ classType: classType,
537
+ type: inferInputType(value),
538
+ value: raw,
539
+ display: summarize(raw)
540
+ });
541
+ }
542
+ }
543
+ return out;
544
+ }
545
+
473
546
  /** 同名输入的其它位置,给面板下拉用:多个采样器时可以换一个绑。 */
474
547
  function paramCandidates(graph, name) {
475
548
  const out = [];
@@ -502,14 +575,31 @@ function coerceParam(value, param, previous) {
502
575
  }
503
576
 
504
577
  /**
505
- * 把对话模型传来的参数写进图。不认识的键、解析不了的值都退回默认值并报告,
506
- * 让工具能告诉模型「这个参数被忽略了」。
578
+ * 把参数行写进图。两层:先写行里的默认值(设置页里可改,清空 = 不碰工作流里的原值),
579
+ * 再写这次调用显式传的值。
580
+ *
581
+ * 不认识的键、解析不了的值都退回原值并报告,让工具能告诉模型「这个参数被忽略了」。
582
+ * 默认值写进去的那些不算 applied——它们不是这次调用点名要的。
507
583
  */
508
584
  export function applyWorkflowParams(graph, params, overrides) {
509
- const byName = new Map((Array.isArray(params) ? params : []).map((param) => [param.name, param]));
585
+ const list = Array.isArray(params) ? params : [];
586
+ const byName = new Map(list.map((param) => [param.name, param]));
510
587
  const applied = [];
511
588
  const ignored = [];
512
- for (const [name, raw] of Object.entries(overrides || {})) {
589
+ const asked = overrides && typeof overrides === 'object' ? overrides : null;
590
+ for (const param of list) {
591
+ if (!param || !param.node || !param.input) continue;
592
+ const fallback = param.default;
593
+ if (fallback === undefined || fallback === null || String(fallback).trim() === '') continue;
594
+ if (asked && Object.prototype.hasOwnProperty.call(asked, param.name)) continue;
595
+ const node = graph[param.node];
596
+ if (!node) continue;
597
+ node.inputs = node.inputs || {};
598
+ const next = coerceParam(fallback, param, node.inputs[param.input]);
599
+ if (next === null) continue;
600
+ node.inputs[param.input] = next;
601
+ }
602
+ for (const [name, raw] of Object.entries(asked || {})) {
513
603
  const param = byName.get(name);
514
604
  if (!param) { ignored.push(name); continue; }
515
605
  const node = graph[param.node];