Skip to content

Commit

Permalink
remove source
Browse files Browse the repository at this point in the history
  • Loading branch information
toyamarinyon committed Oct 25, 2024
1 parent eebb7e5 commit e1d6660
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -183,13 +184,13 @@ export const PromptPropertyPanel: FC<PromptPropertyPanelProps> = ({ 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",
},
},
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 &&
Expand Down Expand Up @@ -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,
},
},
}),
);
Expand Down

0 comments on commit e1d6660

Please sign in to comment.