Some checks failed
Python Linting / Run Ruff (push) Has been cancelled
Python Linting / Run Pylint (push) Has been cancelled
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.10, [self-hosted Linux], stable) (push) Has been cancelled
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.11, [self-hosted Linux], stable) (push) Has been cancelled
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.12, [self-hosted Linux], stable) (push) Has been cancelled
Full Comfy CI Workflow Runs / test-unix-nightly (12.1, , linux, 3.11, [self-hosted Linux], nightly) (push) Has been cancelled
Execution Tests / test (macos-latest) (push) Has been cancelled
Execution Tests / test (ubuntu-latest) (push) Has been cancelled
Execution Tests / test (windows-latest) (push) Has been cancelled
Test server launches without errors / test (push) Has been cancelled
Unit Tests / test (macos-latest) (push) Has been cancelled
Unit Tests / test (ubuntu-latest) (push) Has been cancelled
Unit Tests / test (windows-2022) (push) Has been cancelled
Includes 30 custom nodes committed directly, 7 Civitai-exclusive loras stored via Git LFS, and a setup script that installs all dependencies and downloads HuggingFace-hosted models on vast.ai. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
75 lines
2.0 KiB
TypeScript
75 lines
2.0 KiB
TypeScript
import type {DynamicContextNodeBase} from "../dynamic_context_base.js";
|
|
|
|
import {NodeTypesString} from "../constants.js";
|
|
import {getConnectedOutputNodesAndFilterPassThroughs} from "../utils.js";
|
|
import {INodeInputSlot, INodeOutputSlot, INodeSlot, LGraphNode} from "@comfyorg/frontend";
|
|
|
|
export let SERVICE: ContextService;
|
|
|
|
const OWNED_PREFIX = "+";
|
|
const REGEX_PREFIX = /^[\+⚠️]\s*/;
|
|
const REGEX_EMPTY_INPUT = /^\+\s*$/;
|
|
|
|
export function stripContextInputPrefixes(name: string) {
|
|
return name.replace(REGEX_PREFIX, "");
|
|
}
|
|
|
|
export function getContextOutputName(inputName: string) {
|
|
if (inputName === "base_ctx") return "CONTEXT";
|
|
return stripContextInputPrefixes(inputName).toUpperCase();
|
|
}
|
|
|
|
export enum InputMutationOperation {
|
|
"UNKNOWN",
|
|
"ADDED",
|
|
"REMOVED",
|
|
"RENAMED",
|
|
}
|
|
|
|
export type InputMutation = {
|
|
operation: InputMutationOperation;
|
|
node: DynamicContextNodeBase;
|
|
slotIndex: number;
|
|
slot: INodeSlot;
|
|
};
|
|
|
|
export class ContextService {
|
|
constructor() {
|
|
if (SERVICE) {
|
|
throw new Error("ContextService was already instantiated.");
|
|
}
|
|
}
|
|
|
|
onInputChanges(node: any, mutation: InputMutation) {
|
|
const childCtxs = getConnectedOutputNodesAndFilterPassThroughs(
|
|
node,
|
|
node,
|
|
0,
|
|
) as DynamicContextNodeBase[];
|
|
for (const childCtx of childCtxs) {
|
|
childCtx.handleUpstreamMutation(mutation);
|
|
}
|
|
}
|
|
|
|
getDynamicContextInputsData(node: DynamicContextNodeBase) {
|
|
return node
|
|
.getContextInputsList()
|
|
.map((input: INodeInputSlot, index: number) => ({
|
|
name: stripContextInputPrefixes(input.name),
|
|
type: String(input.type),
|
|
index,
|
|
}))
|
|
.filter((i) => i.type !== "*");
|
|
}
|
|
|
|
getDynamicContextOutputsData(node: LGraphNode) {
|
|
return node.outputs.map((output: INodeOutputSlot, index: number) => ({
|
|
name: stripContextInputPrefixes(output.name),
|
|
type: String(output.type),
|
|
index,
|
|
}));
|
|
}
|
|
}
|
|
|
|
SERVICE = new ContextService();
|