From e1d6660ef417dd09c19299e1eb82ba1a8e6c2942 Mon Sep 17 00:00:00 2001 From: satoshi toyama Date: Fri, 25 Oct 2024 22:03:18 +0900 Subject: [PATCH] remove source --- .../giselle-node/components/panel/prompt.tsx | 15 +++---- .../graph/v2/composition/remove-source.ts | 39 +++++++++++++------ 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/app/(playground)/p/[agentId]/beta-proto/giselle-node/components/panel/prompt.tsx b/app/(playground)/p/[agentId]/beta-proto/giselle-node/components/panel/prompt.tsx index 2f59df27..aa245f6e 100644 --- a/app/(playground)/p/[agentId]/beta-proto/giselle-node/components/panel/prompt.tsx +++ b/app/(playground)/p/[agentId]/beta-proto/giselle-node/components/panel/prompt.tsx @@ -24,6 +24,7 @@ import { updateNodesUI, } from "../../../graph/actions"; import { type CompositeAction, useGraph } from "../../../graph/context"; +import { removeSource } from "../../../graph/v2/composition/remove-source"; import type { TextContent, TextContentReference, @@ -183,13 +184,13 @@ export const PromptPropertyPanel: FC = ({ node }) => { const artifactIds = sources.map(({ id }) => id); if (artifactIds.includes(artifact.id)) { dispatch( - removeSourceFromPromptNode({ - promptNode: { - id: node.id, - }, - source: { - id: artifact.id, - object: "artifact.reference", + removeSource({ + input: { + nodeId: node.id, + source: { + id: artifact.id, + object: "artifact.reference", + }, }, }), ); diff --git a/app/(playground)/p/[agentId]/beta-proto/graph/v2/composition/remove-source.ts b/app/(playground)/p/[agentId]/beta-proto/graph/v2/composition/remove-source.ts index 6f00a623..37e4424d 100644 --- a/app/(playground)/p/[agentId]/beta-proto/graph/v2/composition/remove-source.ts +++ b/app/(playground)/p/[agentId]/beta-proto/graph/v2/composition/remove-source.ts @@ -5,6 +5,7 @@ import type { TextContentReference } from "../../../text-content/types"; import type { WebSearch } from "../../../web-search/types"; import { removeParameterFromNode, updateNodeProperty } from "../../actions"; import type { CompositeAction } from "../../context"; +import { updateNode } from "./update-node"; export type Source = ArtifactReference | TextContentReference | WebSearch; type RemoveSourceInput = { @@ -29,12 +30,12 @@ export function removeSource({ throw new Error(`${node.id}'s sources property is not an array`); } dispatch( - updateNodeProperty({ - node: { - id: input.nodeId, - property: { - key: "sources", - value: currentSources.filter( + updateNode({ + input: { + nodeId: input.nodeId, + properties: { + ...node.properties, + sources: currentSources.filter( (currentSource) => typeof currentSource === "object" && currentSource !== null && @@ -74,13 +75,27 @@ export function removeSource({ `Source connector not found: ${sourceCreatorNodeId} -> ${relevantConnector.target}`, ); } + const relevantNode = getState().graph.nodes.find( + (node) => node.id === relevantConnector.target, + ); + if (relevantNode === undefined) { + throw new Error(`Node not found: ${relevantConnector.target}`); + } + if (relevantNode.parameters?.object !== "objectParameter") { + throw new Error( + `Node's parameters are not an object: ${relevantConnector.target}`, + ); + } + const { [relevantConnector.targetHandle]: _, ...properties } = + relevantNode.parameters.properties; dispatch( - removeParameterFromNode({ - node: { - id: relevantConnector.target, - }, - parameter: { - key: sourceConnector.targetHandle, + updateNode({ + input: { + nodeId: relevantConnector.target, + parameters: { + ...relevantNode.parameters, + properties, + }, }, }), );