Browse Source

句柄修改

feature/composer
TianYun 1 month ago
parent
commit
82e92b7a08
  1. 18
      src/components/nodes/SmartTextNode.tsx
  2. 41
      src/utils/nodeHandles.ts

18
src/components/nodes/SmartTextNode.tsx

@ -13,7 +13,7 @@ import { LLM_MODELS } from "@/lib/llmModels";
import { useWorkflowStore } from "@/store/workflowStore"; import { useWorkflowStore } from "@/store/workflowStore";
import { SmartTextNodeData } from "@/types"; import { SmartTextNodeData } from "@/types";
import { formatUserFacingError } from "@/utils/userFacingErrors"; import { formatUserFacingError } from "@/utils/userFacingErrors";
import { getSmartTextInputHandles, SINGLE_INPUT_HANDLE_ID, SINGLE_OUTPUT_HANDLE_ID, type NodeInputHandleDescriptor } from "@/utils/nodeHandles"; import { SINGLE_INPUT_HANDLE_ID, SINGLE_OUTPUT_HANDLE_ID } from "@/utils/nodeHandles";
import { deriveSmartTextMode } from "@/utils/smartTextMode"; import { deriveSmartTextMode } from "@/utils/smartTextMode";
import { editorHtmlToMarkdown, insertEditorDivider, markdownToEditorHtml } from "@/utils/markdownEditor"; import { editorHtmlToMarkdown, insertEditorDivider, markdownToEditorHtml } from "@/utils/markdownEditor";
import { readTextDocumentFile } from "@/utils/textDocumentImport"; import { readTextDocumentFile } from "@/utils/textDocumentImport";
@ -30,8 +30,7 @@ function getSmartTextManualTitle(id: string, data: SmartTextNodeData, textInputL
return match ? `${textInputLabel} ${match[1]}` : textInputLabel; return match ? `${textInputLabel} ${match[1]}` : textInputLabel;
} }
function SmartTextInputHandles({ handles, selected }: { handles: NodeInputHandleDescriptor[]; selected?: boolean }) { function SmartTextInputHandles({ selected }: { selected?: boolean }) {
void handles;
const showLabels = useShowHandleLabels(selected); const showLabels = useShowHandleLabels(selected);
return ( return (
@ -212,12 +211,10 @@ function SmartTextNeutralView({
id, id,
data, data,
selected, selected,
inputHandles,
}: { }: {
id: string; id: string;
data: SmartTextNodeData; data: SmartTextNodeData;
selected?: boolean; selected?: boolean;
inputHandles: NodeInputHandleDescriptor[];
}) { }) {
const { t } = useI18n(); const { t } = useI18n();
const updateNodeData = useWorkflowStore((state) => state.updateNodeData); const updateNodeData = useWorkflowStore((state) => state.updateNodeData);
@ -244,7 +241,7 @@ function SmartTextNeutralView({
minHeight={SMART_TEXT_MIN_DIMENSIONS.height} minHeight={SMART_TEXT_MIN_DIMENSIONS.height}
fullBleed fullBleed
> >
<SmartTextInputHandles handles={inputHandles} selected={selected} /> <SmartTextInputHandles selected={selected} />
<TextOutputHandle selected={selected} /> <TextOutputHandle selected={selected} />
<div className="flex h-full w-full flex-col bg-neutral-900/25 px-6 py-9"> <div className="flex h-full w-full flex-col bg-neutral-900/25 px-6 py-9">
<div className="flex justify-center"> <div className="flex justify-center">
@ -481,12 +478,10 @@ function SmartTextLlmView({
id, id,
data, data,
selected, selected,
inputHandles,
}: { }: {
id: string; id: string;
data: SmartTextNodeData; data: SmartTextNodeData;
selected?: boolean; selected?: boolean;
inputHandles: NodeInputHandleDescriptor[];
}) { }) {
const { t } = useI18n(); const { t } = useI18n();
const updateNodeData = useWorkflowStore((state) => state.updateNodeData); const updateNodeData = useWorkflowStore((state) => state.updateNodeData);
@ -504,7 +499,7 @@ function SmartTextLlmView({
minHeight={SMART_TEXT_MIN_DIMENSIONS.height} minHeight={SMART_TEXT_MIN_DIMENSIONS.height}
fullBleed fullBleed
> >
<SmartTextInputHandles handles={inputHandles} selected={selected} /> <SmartTextInputHandles selected={selected} />
<TextOutputHandle selected={selected} /> <TextOutputHandle selected={selected} />
{data.status === "loading" ? ( {data.status === "loading" ? (
<div <div
@ -540,15 +535,14 @@ function SmartTextLlmView({
export function SmartTextNode({ id, data, selected }: NodeProps<SmartTextNodeType>) { export function SmartTextNode({ id, data, selected }: NodeProps<SmartTextNodeType>) {
const edges = useWorkflowStore((state) => state.edges); const edges = useWorkflowStore((state) => state.edges);
const mode = deriveSmartTextMode(id, data, edges); const mode = deriveSmartTextMode(id, data, edges);
const inputHandles = getSmartTextInputHandles({ id, type: "smartText", data }, edges);
if (mode === "manualText") { if (mode === "manualText") {
return <SmartTextManualView id={id} data={data} selected={selected} />; return <SmartTextManualView id={id} data={data} selected={selected} />;
} }
if (mode === "llmGenerate") { if (mode === "llmGenerate") {
return <SmartTextLlmView id={id} data={data} selected={selected} inputHandles={inputHandles} />; return <SmartTextLlmView id={id} data={data} selected={selected} />;
} }
return <SmartTextNeutralView id={id} data={data} selected={selected} inputHandles={inputHandles} />; return <SmartTextNeutralView id={id} data={data} selected={selected} />;
} }

41
src/utils/nodeHandles.ts

@ -30,13 +30,6 @@ export type NodeConnectionCapability = {
} | null; } | null;
}; };
export type NodeInputHandleDescriptor = {
id: string;
type: "image" | "video" | "audio" | "text";
schemaName?: string;
topPercent: number;
};
type CapabilityNode = { type CapabilityNode = {
id: string; id: string;
type?: string; type?: string;
@ -242,37 +235,3 @@ export function getNodeHandleCapability(node: CapabilityNode, edges: WorkflowEdg
return getStaticNodeHandles(node.type || ""); return getStaticNodeHandles(node.type || "");
} }
export function getSmartImageInputHandles(node: CapabilityNode, edges: WorkflowEdge[]): NodeInputHandleDescriptor[] {
return getSmartMediaInputHandles(node, edges, ["image", "text"], [35, 65]);
}
export function getSmartVideoInputHandles(node: CapabilityNode, edges: WorkflowEdge[]): NodeInputHandleDescriptor[] {
return getSmartMediaInputHandles(node, edges, ["image", "video", "text"], [25, 50, 75]);
}
export function getSmartAudioInputHandles(node: CapabilityNode, edges: WorkflowEdge[]): NodeInputHandleDescriptor[] {
return getSmartMediaInputHandles(node, edges, ["text"], [50]);
}
export function getSmartTextInputHandles(node: CapabilityNode, edges: WorkflowEdge[]): NodeInputHandleDescriptor[] {
return getSmartMediaInputHandles(node, edges, ["image", "video", "text"], [28, 50, 72]);
}
function getSmartMediaInputHandles(
node: CapabilityNode,
edges: WorkflowEdge[],
defaultTypes: Array<"image" | "video" | "audio" | "text">,
defaultTopPercents: number[]
): NodeInputHandleDescriptor[] {
const capability = getNodeHandleCapability(node, edges);
if (capability.inputs.length === 0) return [];
return defaultTypes
.filter((type) => capability.inputs.includes(type))
.map((type, index) => ({
id: type,
type,
topPercent: defaultTopPercents[index] ?? ((index + 1) / (defaultTypes.length + 1)) * 100,
}));
}

Loading…
Cancel
Save