dsh-mo-image 0.7.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.
@@ -432,19 +432,19 @@ export function collectParams(graph, mapping, objectInfo) {
432
432
  }
433
433
 
434
434
  /**
435
- * 默认对对话模型可见的参数:只有提示词和负面词。
436
- * 宽高、种子、模型都由选择器或插件决定,暴露出去只会多一条绕过选择器的后门。
435
+ * 提示词与负面词不是「可调参数」:它们由工具调用自己的 prompt/negative_prompt
436
+ * 经映射直接写进工作流,始终生效,也不该出现在给模型看的 params 里。
437
437
  */
438
- export const DEFAULT_EXPOSED = new Set(['prompt', 'negative_prompt']);
438
+ export const PROMPT_ROLE_NAMES = new Set(['prompt', 'negative_prompt']);
439
439
 
440
440
  /**
441
- * 映射角色也当成参数:提示词、负面词、宽高、种子、模型。
442
- * 它们在工作流里已经有确定位置,和可调参数放进同一张表,但默认只有前四个暴露。
441
+ * 映射角色也当成参数:宽高、种子、模型。
442
+ * 它们在工作流里已经有确定位置,和可调参数放进同一张表,但默认只有能调的那几项需要显式打开。
443
443
  * 类型来自 object_info;值是连线时按输入名推断,避免把 ["19",0] 当成字符串。
444
444
  */
445
445
  export function collectRoleParams(graph, mapping, objectInfo) {
446
446
  const out = [];
447
- for (const key of ['prompt', 'negative_prompt', 'width', 'height', 'seed', 'model']) {
447
+ for (const key of ['width', 'height', 'seed', 'model']) {
448
448
  const target = mapping && mapping[key];
449
449
  if (!target) continue;
450
450
  const node = graph[target.node];
@@ -474,6 +474,75 @@ export function collectRoleParams(graph, mapping, objectInfo) {
474
474
  return out;
475
475
  }
476
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
+
477
546
  /** 同名输入的其它位置,给面板下拉用:多个采样器时可以换一个绑。 */
478
547
  function paramCandidates(graph, name) {
479
548
  const out = [];
@@ -506,14 +575,31 @@ function coerceParam(value, param, previous) {
506
575
  }
507
576
 
508
577
  /**
509
- * 把对话模型传来的参数写进图。不认识的键、解析不了的值都退回默认值并报告,
510
- * 让工具能告诉模型「这个参数被忽略了」。
578
+ * 把参数行写进图。两层:先写行里的默认值(设置页里可改,清空 = 不碰工作流里的原值),
579
+ * 再写这次调用显式传的值。
580
+ *
581
+ * 不认识的键、解析不了的值都退回原值并报告,让工具能告诉模型「这个参数被忽略了」。
582
+ * 默认值写进去的那些不算 applied——它们不是这次调用点名要的。
511
583
  */
512
584
  export function applyWorkflowParams(graph, params, overrides) {
513
- 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]));
514
587
  const applied = [];
515
588
  const ignored = [];
516
- 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 || {})) {
517
603
  const param = byName.get(name);
518
604
  if (!param) { ignored.push(name); continue; }
519
605
  const node = graph[param.node];