@fractal-solutions/qflow 1.0.16 → 1.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +73 -2
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -589,7 +589,8 @@ import {
589
589
  UserInputNode,
590
590
  AgentNode,
591
591
  CodeInterpreterNode,
592
- MemoryNode
592
+ MemoryNode,
593
+ TransformNode
593
594
  } from '@fractal-solutions/qflow/nodes';
594
595
 
595
596
  // Ensure your DeepSeek API Key is set as an environment variable
@@ -621,6 +622,7 @@ const DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY;
621
622
  const userInput = new UserInputNode(); // Agent can also ask for user input
622
623
  const codeInterpreter = new CodeInterpreterNode(); // Agent can execute code
623
624
  const memoryNode = new MemoryNode(); // Agent can store and retrieve memories
625
+ const transformNode = new TransformNode(); // Agent can transform data
624
626
 
625
627
  // Map tool names to their instances
626
628
  const availableTools = {
@@ -633,6 +635,7 @@ const DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY;
633
635
  user_input: userInput,
634
636
  code_interpreter: codeInterpreter,
635
637
  memory_node: memoryNode,
638
+ transform_node: transformNode,
636
639
  // Add other tools as needed
637
640
  };
638
641
 
@@ -869,7 +872,74 @@ const DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY;
869
872
 
870
873
  console.log('\n--- MemoryNode RAG Example Finished ---');
871
874
  })();
872
- `````
875
+ ```
876
+
877
+ ### 16. Transform Node
878
+
879
+ Dynamically transforming data using custom JavaScript functions.
880
+
881
+ ```javascript
882
+ import { AsyncFlow } from '@fractal-solutions/qflow';
883
+ import { TransformNode } from '@fractal-solutions/qflow/nodes';
884
+
885
+ (async () => {
886
+ console.log('--- Running TransformNode Example ---');
887
+
888
+ // Example 1: Map an array of numbers
889
+ const numbers = [1, 2, 3];
890
+ const doubleNumbers = new TransformNode();
891
+ doubleNumbers.setParams({
892
+ input: numbers,
893
+ transformFunction: '(data) => data.map(x => x * 2)'
894
+ });
895
+
896
+ const flow1 = new AsyncFlow(doubleNumbers);
897
+ try {
898
+ const result = await flow1.runAsync({});
899
+ console.log('Doubled Numbers:', result); // Expected: [2, 4, 6]
900
+ } catch (error) {
901
+ console.error('Transform Flow 1 Failed:', error);
902
+ }
903
+
904
+ // Example 2: Filter an array of objects
905
+ const users = [
906
+ { name: 'Alice', active: true },
907
+ { name: 'Bob', active: false },
908
+ { name: 'Charlie', active: true }
909
+ ];
910
+ const activeUsers = new TransformNode();
911
+ activeUsers.setParams({
912
+ input: users,
913
+ transformFunction: '(data) => data.filter(user => user.active)'
914
+ });
915
+
916
+ const flow2 = new AsyncFlow(activeUsers);
917
+ try {
918
+ const result = await flow2.runAsync({});
919
+ console.log('Active Users:', result); // Expected: [{ name: 'Alice', active: true }, { name: 'Charlie', active: true }]
920
+ } catch (error) {
921
+ console.error('Transform Flow 2 Failed:', error);
922
+ }
923
+
924
+ // Example 3: Extract a specific property from an object
925
+ const product = { id: 1, name: 'Laptop', price: 1200 };
926
+ const productName = new TransformNode();
927
+ productName.setParams({
928
+ input: product,
929
+ transformFunction: '(data) => data.name'
930
+ });
931
+
932
+ const flow3 = new AsyncFlow(productName);
933
+ try {
934
+ const result = await flow3.runAsync({});
935
+ console.log('Product Name:', result); // Expected: 'Laptop'
936
+ } catch (error) {
937
+ console.error('Transform Flow 3 Failed:', error);
938
+ }
939
+
940
+ console.log('\n--- TransformNode Example Finished ---');
941
+ })();
942
+ ```
873
943
 
874
944
  ## Exploring More Examples
875
945
 
@@ -879,6 +949,7 @@ The examples above cover the core functionalities of `qflow`. For more advanced
879
949
  * **LLMs (DeepSeek, OpenAI, Gemini, Ollama):** The core of agentic behavior.
880
950
  * For agents, use specialized LLM nodes like `AgentDeepSeekLLMNode`, `AgentOpenAILLMNode`, `AgentOllamaLLMNode`.
881
951
  * **Agent:** Orchestrating tools and LLM reasoning to achieve complex goals.
952
+ * **Transform:** For dynamic data manipulation and reformatting.
882
953
  * **Memory:** For lightweight, keyword-based long-term memory and RAG.
883
954
  * **CodeInterpreter:** For executing dynamic code (e.g., Python) within the workflow.
884
955
  * **Interactive Agent:** An agent that takes a goal from user input and uses its tools to achieve it.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fractal-solutions/qflow",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "A lightweight and flexible JavaScript library for creating and managing workflows and agents.",
5
5
  "main": "dist/qflow.js",
6
6
  "types": "dist/qflow.d.ts",