@minded-ai/mindedjs 1.0.19

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 (183) hide show
  1. package/.github/workflows/CI.yml +34 -0
  2. package/.prettierrc +8 -0
  3. package/README.md +6 -0
  4. package/dist/agent.d.ts +36 -0
  5. package/dist/agent.js +199 -0
  6. package/dist/agent.js.map +1 -0
  7. package/dist/analytics.d.ts +6 -0
  8. package/dist/analytics.js +19 -0
  9. package/dist/analytics.js.map +1 -0
  10. package/dist/edges/createDirectEdge.d.ts +4 -0
  11. package/dist/edges/createDirectEdge.js +14 -0
  12. package/dist/edges/createDirectEdge.js.map +1 -0
  13. package/dist/edges/createLogicalRouter.d.ts +5 -0
  14. package/dist/edges/createLogicalRouter.js +18 -0
  15. package/dist/edges/createLogicalRouter.js.map +1 -0
  16. package/dist/edges/createPromptRouter.d.ts +7 -0
  17. package/dist/edges/createPromptRouter.js +54 -0
  18. package/dist/edges/createPromptRouter.js.map +1 -0
  19. package/dist/edges/edgeFactory.d.ts +9 -0
  20. package/dist/edges/edgeFactory.js +65 -0
  21. package/dist/edges/edgeFactory.js.map +1 -0
  22. package/dist/events/AgentEvents.d.ts +22 -0
  23. package/dist/events/AgentEvents.js +9 -0
  24. package/dist/events/AgentEvents.js.map +1 -0
  25. package/dist/events/index.d.ts +2 -0
  26. package/dist/events/index.js +5 -0
  27. package/dist/events/index.js.map +1 -0
  28. package/dist/index.d.ts +6 -0
  29. package/dist/index.js +15 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/infrastructure.ts/mindedRequest.d.ts +8 -0
  32. package/dist/infrastructure.ts/mindedRequest.js +22 -0
  33. package/dist/infrastructure.ts/mindedRequest.js.map +1 -0
  34. package/dist/llm/createLlmInstance.d.ts +2 -0
  35. package/dist/llm/createLlmInstance.js +14 -0
  36. package/dist/llm/createLlmInstance.js.map +1 -0
  37. package/dist/nodes/addHumanInTheLoopNode.d.ts +8 -0
  38. package/dist/nodes/addHumanInTheLoopNode.js +17 -0
  39. package/dist/nodes/addHumanInTheLoopNode.js.map +1 -0
  40. package/dist/nodes/addPromptNode.d.ts +15 -0
  41. package/dist/nodes/addPromptNode.js +52 -0
  42. package/dist/nodes/addPromptNode.js.map +1 -0
  43. package/dist/nodes/addToolNode.d.ts +10 -0
  44. package/dist/nodes/addToolNode.js +82 -0
  45. package/dist/nodes/addToolNode.js.map +1 -0
  46. package/dist/nodes/addTriggerNode.d.ts +6 -0
  47. package/dist/nodes/addTriggerNode.js +12 -0
  48. package/dist/nodes/addTriggerNode.js.map +1 -0
  49. package/dist/nodes/nodeFactory.d.ts +13 -0
  50. package/dist/nodes/nodeFactory.js +41 -0
  51. package/dist/nodes/nodeFactory.js.map +1 -0
  52. package/dist/platform/analytics.d.ts +6 -0
  53. package/dist/platform/analytics.js +19 -0
  54. package/dist/platform/analytics.js.map +1 -0
  55. package/dist/platform/mindedCheckpointSaver.d.ts +10 -0
  56. package/dist/platform/mindedCheckpointSaver.js +49 -0
  57. package/dist/platform/mindedCheckpointSaver.js.map +1 -0
  58. package/dist/platform/mindedConnection.d.ts +13 -0
  59. package/dist/platform/mindedConnection.js +117 -0
  60. package/dist/platform/mindedConnection.js.map +1 -0
  61. package/dist/platform/mindedConnectionTypes.d.ts +10 -0
  62. package/dist/platform/mindedConnectionTypes.js +8 -0
  63. package/dist/platform/mindedConnectionTypes.js.map +1 -0
  64. package/dist/platform/mindedRequest.d.ts +8 -0
  65. package/dist/platform/mindedRequest.js +22 -0
  66. package/dist/platform/mindedRequest.js.map +1 -0
  67. package/dist/types/Agent.types.d.ts +8 -0
  68. package/dist/types/Agent.types.js +3 -0
  69. package/dist/types/Agent.types.js.map +1 -0
  70. package/dist/types/Flows.types.d.ts +83 -0
  71. package/dist/types/Flows.types.js +24 -0
  72. package/dist/types/Flows.types.js.map +1 -0
  73. package/dist/types/LLM.types.d.ts +10 -0
  74. package/dist/types/LLM.types.js +9 -0
  75. package/dist/types/LLM.types.js.map +1 -0
  76. package/dist/types/LangGraph.types.d.ts +29 -0
  77. package/dist/types/LangGraph.types.js +20 -0
  78. package/dist/types/LangGraph.types.js.map +1 -0
  79. package/dist/types/Tools.types.d.ts +14 -0
  80. package/dist/types/Tools.types.js +3 -0
  81. package/dist/types/Tools.types.js.map +1 -0
  82. package/dist/types/Triggers.types.d.ts +1 -0
  83. package/dist/types/Triggers.types.js +3 -0
  84. package/dist/types/Triggers.types.js.map +1 -0
  85. package/docs/.gitbook/assets/image.png +0 -0
  86. package/docs/README.md +51 -0
  87. package/docs/SUMMARY.md +21 -0
  88. package/docs/api-reference/.nojekyll +1 -0
  89. package/docs/api-reference/assets/hierarchy.js +1 -0
  90. package/docs/api-reference/assets/highlight.css +120 -0
  91. package/docs/api-reference/assets/icons.js +18 -0
  92. package/docs/api-reference/assets/icons.svg +1 -0
  93. package/docs/api-reference/assets/main.js +60 -0
  94. package/docs/api-reference/assets/navigation.js +1 -0
  95. package/docs/api-reference/assets/search.js +1 -0
  96. package/docs/api-reference/assets/style.css +1640 -0
  97. package/docs/api-reference/classes/index.Agent.html +4 -0
  98. package/docs/api-reference/enums/index.EdgeType.html +4 -0
  99. package/docs/api-reference/enums/index.NodeType.html +6 -0
  100. package/docs/api-reference/enums/index.TriggerType.html +4 -0
  101. package/docs/api-reference/enums/index.events.html +3 -0
  102. package/docs/api-reference/hierarchy.html +1 -0
  103. package/docs/api-reference/index.html +310 -0
  104. package/docs/api-reference/interfaces/index.AppToolNode.html +5 -0
  105. package/docs/api-reference/interfaces/index.AppTriggerNode.html +6 -0
  106. package/docs/api-reference/interfaces/index.Flow.html +4 -0
  107. package/docs/api-reference/interfaces/index.JunctionNode.html +4 -0
  108. package/docs/api-reference/interfaces/index.LogicalConditionEdge.html +5 -0
  109. package/docs/api-reference/interfaces/index.ManualTriggerNode.html +5 -0
  110. package/docs/api-reference/interfaces/index.PromptConditionEdge.html +5 -0
  111. package/docs/api-reference/interfaces/index.PromptNode.html +6 -0
  112. package/docs/api-reference/interfaces/index.StepForwardEdge.html +4 -0
  113. package/docs/api-reference/interfaces/index.Tool.html +6 -0
  114. package/docs/api-reference/interfaces/index.ToolNode.html +5 -0
  115. package/docs/api-reference/modules/index-1.html +1 -0
  116. package/docs/api-reference/modules/index.html +1 -0
  117. package/docs/api-reference/modules.html +1 -0
  118. package/docs/api-reference/types/index.Edge.html +1 -0
  119. package/docs/api-reference/types/index.Node.html +1 -0
  120. package/docs/api-reference/types/index.TriggerNode.html +1 -0
  121. package/docs/core-concepts/edges.md +242 -0
  122. package/docs/core-concepts/events.md +161 -0
  123. package/docs/core-concepts/flows.md +74 -0
  124. package/docs/core-concepts/memory-types.md +208 -0
  125. package/docs/core-concepts/nodes.md +239 -0
  126. package/docs/core-concepts/tools.md +205 -0
  127. package/docs/examples/order-refund-flow.md +560 -0
  128. package/docs/getting-started/installation.md +34 -0
  129. package/docs/getting-started/quick-start.md +264 -0
  130. package/docs-structure.md +144 -0
  131. package/eslint.config.js +68 -0
  132. package/examples/orderRefundAgent/flows/orderRefundFlow.yaml +32 -0
  133. package/examples/orderRefundAgent/minded.json +14 -0
  134. package/examples/orderRefundAgent/orderRefundAgent.ts +58 -0
  135. package/examples/orderRefundAgent/schema.ts +7 -0
  136. package/examples/orderRefundAgent/tools/escalateConversation.ts +28 -0
  137. package/examples/orderRefundAgent/tools/index.ts +4 -0
  138. package/examples/orderRefundAgent/tools/refundOrder.ts +27 -0
  139. package/package.json +46 -0
  140. package/src/agent.ts +216 -0
  141. package/src/edges/createDirectEdge.ts +11 -0
  142. package/src/edges/createLogicalRouter.ts +16 -0
  143. package/src/edges/createPromptRouter.ts +52 -0
  144. package/src/edges/edgeFactory.ts +85 -0
  145. package/src/events/AgentEvents.ts +22 -0
  146. package/src/events/index.ts +3 -0
  147. package/src/index.ts +22 -0
  148. package/src/llm/createLlmInstance.ts +10 -0
  149. package/src/nodes/addHumanInTheLoopNode.ts +20 -0
  150. package/src/nodes/addPromptNode.ts +66 -0
  151. package/src/nodes/addToolNode.ts +95 -0
  152. package/src/nodes/addTriggerNode.ts +12 -0
  153. package/src/nodes/nodeFactory.ts +65 -0
  154. package/src/platform/analytics.ts +16 -0
  155. package/src/platform/mindedCheckpointSaver.ts +74 -0
  156. package/src/platform/mindedConnection.ts +106 -0
  157. package/src/platform/mindedConnectionTypes.ts +15 -0
  158. package/src/platform/mindedRequest.ts +28 -0
  159. package/src/types/Agent.types.ts +10 -0
  160. package/src/types/Flows.types.ts +103 -0
  161. package/src/types/LLM.types.ts +13 -0
  162. package/src/types/LangGraph.types.ts +25 -0
  163. package/src/types/Tools.types.ts +9 -0
  164. package/test/can-stay-on-node/can-stay-on-node.test.ts +148 -0
  165. package/test/can-stay-on-node/flows/test-flow.yaml +25 -0
  166. package/test/cannot-stay-on-node/cannot-stay-on-node.test.ts +201 -0
  167. package/test/cannot-stay-on-node/flows/test-flow.yaml +34 -0
  168. package/test/human-in-the-loop-node/flows/test-flow.yaml +23 -0
  169. package/test/human-in-the-loop-node/human-in-the-loop-node.test.ts +92 -0
  170. package/test/logical-edges/flows/logical-edge-test-flow.yaml +24 -0
  171. package/test/logical-edges/logical-edges.test.ts +66 -0
  172. package/test/no-human-in-the-loop-node/flows/test-flow.yaml +23 -0
  173. package/test/no-human-in-the-loop-node/no-human-in-the-loop-node.test.ts +80 -0
  174. package/test/prompt-edges/flows/test-flow.yaml +24 -0
  175. package/test/prompt-edges/prompt-edges.test.ts +90 -0
  176. package/test/prompt-node/flows/test-flow.yaml +24 -0
  177. package/test/prompt-node/prompt-node.test.ts +86 -0
  178. package/test/setup.ts +5 -0
  179. package/test/tool-node/flows/test-flow.yaml +14 -0
  180. package/test/tool-node/tool-node.test.ts +67 -0
  181. package/test/trigger/flows/test-flow.yaml +7 -0
  182. package/test/trigger/trigger.test.ts +57 -0
  183. package/tsconfig.json +17 -0
@@ -0,0 +1,205 @@
1
+ # Tools
2
+
3
+ Tools are reusable functions that agents can call to perform specific actions like processing payments, sending emails, or updating databases.
4
+
5
+ ## Tool Structure
6
+
7
+ Every tool must implement the `Tool` interface:
8
+
9
+ ```ts
10
+ interface Tool<Input extends z.ZodSchema, Memory> {
11
+ name: string; // Unique tool identifier
12
+ description: string; // What the tool does (used by LLM)
13
+ input: Input; // Zod schema for input validation
14
+ isGlobal?: boolean; // Optional: available across all nodes
15
+ execute: ({ input, memory }) => Promise<{ memory?, result? }>;
16
+ }
17
+ ```
18
+
19
+ ## Basic Tool Example
20
+
21
+ Here's a simple refund processing tool:
22
+
23
+ ```ts
24
+ import { z } from 'zod';
25
+ import { Tool } from 'mindedjs/src/types/Tools.types';
26
+ import memorySchema from '../schema';
27
+
28
+ type Memory = z.infer<typeof memorySchema>;
29
+
30
+ const schema = z.object({
31
+ orderId: z.string(),
32
+ customerName: z.string(),
33
+ });
34
+
35
+ const refundOrderTool: Tool<typeof schema, Memory> = {
36
+ name: 'refundOrder',
37
+ description: 'Process a customer refund for their order',
38
+ input: schema,
39
+ execute: async ({ input, memory }) => {
40
+ // Your business logic here
41
+ console.log(`Processing refund for order ${input.orderId}`);
42
+
43
+ // Call external API, update database, etc.
44
+ const refundAmount = await processRefundInSystem(input.orderId);
45
+
46
+ return {
47
+ memory: {
48
+ orderId: input.orderId,
49
+ customerName: input.customerName,
50
+ issue: `Refund processed: $${refundAmount}`,
51
+ },
52
+ };
53
+ },
54
+ };
55
+
56
+ export default refundOrderTool;
57
+ ```
58
+
59
+ ## Tool Registration
60
+
61
+ ### Global Tools
62
+
63
+ Mark tools as global if you want them to be available in all LLM calls.
64
+
65
+ ```ts
66
+ const auditLogTool: Tool<typeof auditSchema, Memory> = {
67
+ name: 'auditLog',
68
+ description: 'Log user action for compliance',
69
+ isGlobal: true, // Available in all flows
70
+ input: z.object({
71
+ action: z.string(),
72
+ details: z.string(),
73
+ }),
74
+ execute: async ({ input, memory }) => {
75
+ await auditService.log({
76
+ userId: memory.userId,
77
+ action: input.action,
78
+ details: input.details,
79
+ timestamp: new Date(),
80
+ });
81
+ },
82
+ };
83
+ ```
84
+
85
+ ## Memory Management
86
+
87
+ Tools can read and update memory state:
88
+
89
+ ```ts
90
+ const updateProfileTool: Tool<typeof profileSchema, Memory> = {
91
+ name: 'updateProfile',
92
+ description: 'Update customer profile information',
93
+ input: z.object({
94
+ field: z.string(),
95
+ value: z.string(),
96
+ }),
97
+ execute: async ({ input, memory }) => {
98
+ // Read current memory
99
+ console.log(`Current customer: ${memory.customerName}`);
100
+
101
+ // Update external system
102
+ await profileService.update(memory.customerId, {
103
+ [input.field]: input.value
104
+ });
105
+
106
+ // Return updated memory
107
+ return {
108
+ memory: {
109
+ ...memory,
110
+ [`${input.field}Updated`]: true,
111
+ },
112
+ };
113
+ },
114
+ };
115
+ ```
116
+
117
+ ## Error Handling
118
+
119
+ Handle errors gracefully in tools:
120
+
121
+ ```ts
122
+ const paymentTool: Tool<typeof paymentSchema, Memory> = {
123
+ name: 'processPayment',
124
+ description: 'Process customer payment',
125
+ input: z.object({
126
+ amount: z.number(),
127
+ cardToken: z.string(),
128
+ }),
129
+ execute: async ({ input, memory }) => {
130
+ try {
131
+ const result = await paymentService.charge({
132
+ amount: input.amount,
133
+ cardToken: input.cardToken,
134
+ customerId: memory.customerId,
135
+ });
136
+
137
+ return {
138
+ result: `Payment successful: ${result.transactionId}`,
139
+ memory: { lastPaymentId: result.transactionId },
140
+ };
141
+ } catch (error) {
142
+ console.error('Payment failed:', error);
143
+ return {
144
+ result: 'Payment failed. Please try again or contact support.',
145
+ memory: { paymentError: error.message },
146
+ };
147
+ }
148
+ },
149
+ };
150
+ ```
151
+
152
+ ## Best Practices
153
+
154
+ 1. **Clear Descriptions**: Write descriptions that help the LLM understand when to use the tool
155
+ 2. **Input Validation**: Use Zod schemas to validate all inputs
156
+ 3. **Memory Updates**: Update memory with relevant information for future tool calls
157
+ 4. **Error Handling**: Always handle errors gracefully and provide meaningful messages
158
+ 5. **Async Operations**: Use async/await for external API calls and database operations
159
+ 6. **Logging**: Log important actions for debugging and auditing
160
+
161
+ ## Tool Nodes
162
+
163
+ Tool nodes force execution of specific tools at defined points in your flow, bypassing LLM decision-making.
164
+
165
+ ### Configuration
166
+
167
+ ```yaml
168
+ nodes:
169
+ - name: 'Force Refund Processing'
170
+ type: 'tool'
171
+ toolName: 'refundOrder'
172
+ ```
173
+
174
+ ### Tool Node vs Automatic Tool Calls
175
+
176
+ | Feature | Tool Nodes | Automatic Tool Calls |
177
+ | ------------- | ------------------------------- | ----------------------------------- |
178
+ | **Execution** | Guaranteed when node is reached | Only when LLM decides to call |
179
+ | **Control** | Explicit flow control | LLM-driven decision |
180
+ | **Use Case** | Required business logic steps | Flexible, context-dependent actions |
181
+
182
+ ### Example
183
+
184
+ ```yaml
185
+ nodes:
186
+ - name: 'Customer Support Start'
187
+ type: 'prompt'
188
+ prompt: 'How can I help you today?'
189
+ - name: 'Log Interaction'
190
+ type: 'tool'
191
+ toolName: 'auditLog'
192
+
193
+ edges:
194
+ - source: 'Customer Support Start'
195
+ target: 'Log Interaction'
196
+ type: 'always'
197
+ ```
198
+
199
+ ### Best Practices
200
+
201
+ 1. **Strategic Placement**: Use for critical business logic that must always execute
202
+ 2. **Clear Context**: Ensure conversation provides context for parameter extraction
203
+ 3. **Error Handling**: Handle errors gracefully since they bypass LLM error recovery
204
+
205
+ Tool parameters are automatically extracted from conversation context and memory state using an internal LLM agent.