Skip to content

Commit

Permalink
add text template v2
Browse files Browse the repository at this point in the history
  • Loading branch information
au-re committed Oct 4, 2023
1 parent c7f077d commit b55a2f9
Show file tree
Hide file tree
Showing 13 changed files with 192 additions and 583 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ParamValue } from "@pufflig/ps-types";
import { Flow, NodeState, RunOptions } from "../../types";
import { applyDefaultInputs } from "./utils/utils";
import { identity } from "./constants";

/**
* This function updates the input state of a node without executing the chain.
Expand All @@ -21,19 +20,15 @@ export async function updateNodeInput(
const flowState: Record<string, NodeState> = { ...flow.state };
const nodeConfig = flow.definition.nodes[nodeId];
const nodeDefinition = flow.nodeTypes[nodeConfig?.type];
const mapInput = nodeDefinition?.mapInput || identity;

if (!nodeConfig || !nodeDefinition) {
throw new Error(`Definition for node ${nodeId} not found`);
}

// parse the input
// compile the new state of the node
const nodeState = flowState[nodeId];
const prevInput = nodeState?.input;
const parsedInput = await mapInput(input, { prevInput, globals: runOptions?.globals });

// compile the new state of the node
const newInput = { ...applyDefaultInputs(prevInput, nodeDefinition), ...parsedInput };
const newInput = { ...applyDefaultInputs(prevInput, nodeDefinition), ...input };
const newState: NodeState = { ...nodeState, input: newInput };

runOptions?.onNodeInputUpdate?.(nodeId, newState);
Expand Down
3 changes: 3 additions & 0 deletions packages/@pufflig/ps-nodes-config/src/modifiers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { addText, addTextNodeType } from "./add_text/add_text";
import { splitText, splitTextNodeType } from "./split_text/split_text";
import { templateChat, templateChatNodeType } from "./template/template_chat";
import { templateText, templateTextNodeType } from "./template/template_text";
import { templateTextNodeTypeV2, templateTextV2 } from "./template/template_text_v2";

export const modifierNodes = {
[addMessageNodeType]: addMessage,
[addTextNodeType]: addText,
[splitTextNodeType]: splitText,
[templateChatNodeType]: templateChat,
[templateTextNodeType]: templateText,
[templateTextNodeTypeV2]: templateTextV2,
};

export const modifierNodeTypes = {
Expand All @@ -18,4 +20,5 @@ export const modifierNodeTypes = {
splitTextNodeType,
templateChatNodeType,
templateTextNodeType,
templateTextNodeTypeV2,
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const templateText: NodeConfig = {
name: "Text Template",
description: "Using this template, you can insert variables into text.",
tags: ["modifier", "text"],
status: "stable",
status: "deprecated",
outputs: [
{
id: "text",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { NodeConfig } from "@pufflig/ps-types";

export const templateTextNodeTypeV2 = "modifier/template_text_v2" as const;

export const templateTextV2: NodeConfig = {
name: "Text Template",
description: "Write text with variables",
tags: ["modifier", "text"],
status: "stable",
customSchema: "input",
outputs: [
{
id: "text",
name: "Text",
description: "Text with variables filled in",
type: "text",
defaultValue: "",
},
],
inputs: [
{
id: "template",
name: "Template",
description: "Template to fill in",
type: "text",
defaultValue: "",
},
],
};
2 changes: 2 additions & 0 deletions packages/@pufflig/ps-nodes/src/modifiers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { addText } from "./add_text/add_text";
import { splitText } from "./split_text/split_text";
import { templateChat } from "./template/template_chat";
import { templateText } from "./template/template_text";
import { templateTextV2 } from "./template/template_text_v2";

export const modifierNodes = {
[nodeTypes.addMessageNodeType]: addMessage,
[nodeTypes.addTextNodeType]: addText,
[nodeTypes.splitTextNodeType]: splitText,
[nodeTypes.templateChatNodeType]: templateChat,
[nodeTypes.templateTextNodeType]: templateText,
[nodeTypes.templateTextNodeTypeV2]: templateTextV2,
};
Loading

0 comments on commit b55a2f9

Please sign in to comment.