Browse Source

句柄修改

feature/composer
TianYun 4 weeks 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 { SmartTextNodeData } from "@/types";
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 { editorHtmlToMarkdown, insertEditorDivider, markdownToEditorHtml } from "@/utils/markdownEditor";
import { readTextDocumentFile } from "@/utils/textDocumentImport";
@ -30,8 +30,7 @@ function getSmartTextManualTitle(id: string, data: SmartTextNodeData, textInputL
return match ? `${textInputLabel} ${match[1]}` : textInputLabel;
}
function SmartTextInputHandles({ handles, selected }: { handles: NodeInputHandleDescriptor[]; selected?: boolean }) {
void handles;
function SmartTextInputHandles({ selected }: { selected?: boolean }) {
const showLabels = useShowHandleLabels(selected);
return (
@ -212,12 +211,10 @@ function SmartTextNeutralView({
id,
data,
selected,
inputHandles,
}: {
id: string;
data: SmartTextNodeData;
selected?: boolean;
inputHandles: NodeInputHandleDescriptor[];
}) {
const { t } = useI18n();
const updateNodeData = useWorkflowStore((state) => state.updateNodeData);
@ -244,7 +241,7 @@ function SmartTextNeutralView({
minHeight={SMART_TEXT_MIN_DIMENSIONS.height}
fullBleed
>
<SmartTextInputHandles handles={inputHandles} selected={selected} />
<SmartTextInputHandles 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 justify-center">
@ -481,12 +478,10 @@ function SmartTextLlmView({
id,
data,
selected,
inputHandles,
}: {
id: string;
data: SmartTextNodeData;
selected?: boolean;
inputHandles: NodeInputHandleDescriptor[];
}) {
const { t } = useI18n();
const updateNodeData = useWorkflowStore((state) => state.updateNodeData);
@ -504,7 +499,7 @@ function SmartTextLlmView({
minHeight={SMART_TEXT_MIN_DIMENSIONS.height}
fullBleed
>
<SmartTextInputHandles handles={inputHandles} selected={selected} />
<SmartTextInputHandles selected={selected} />
<TextOutputHandle selected={selected} />
{data.status === "loading" ? (
<div
@ -540,15 +535,14 @@ function SmartTextLlmView({
export function SmartTextNode({ id, data, selected }: NodeProps<SmartTextNodeType>) {
const edges = useWorkflowStore((state) => state.edges);
const mode = deriveSmartTextMode(id, data, edges);
const inputHandles = getSmartTextInputHandles({ id, type: "smartText", data }, edges);
if (mode === "manualText") {
return <SmartTextManualView id={id} data={data} selected={selected} />;
}
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;
};
export type NodeInputHandleDescriptor = {
id: string;
type: "image" | "video" | "audio" | "text";
schemaName?: string;
topPercent: number;
};
type CapabilityNode = {
id: string;
type?: string;
@ -242,37 +235,3 @@ export function getNodeHandleCapability(node: CapabilityNode, edges: WorkflowEdg
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