@minded-ai/mindedjs 1.0.53 → 1.0.54

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 (87) hide show
  1. package/dist/agent.d.ts +3 -0
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +18 -4
  4. package/dist/agent.js.map +1 -1
  5. package/dist/edges/edgeFactory.d.ts +3 -1
  6. package/dist/edges/edgeFactory.d.ts.map +1 -1
  7. package/dist/edges/edgeFactory.js +2 -2
  8. package/dist/edges/edgeFactory.js.map +1 -1
  9. package/dist/index.d.ts +3 -2
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/internalTools/appActionRunnerTool.d.ts.map +1 -1
  13. package/dist/internalTools/appActionRunnerTool.js +1 -1
  14. package/dist/internalTools/appActionRunnerTool.js.map +1 -1
  15. package/dist/nodes/addAppToolNode.d.ts +3 -1
  16. package/dist/nodes/addAppToolNode.d.ts.map +1 -1
  17. package/dist/nodes/addAppToolNode.js +2 -2
  18. package/dist/nodes/addAppToolNode.js.map +1 -1
  19. package/dist/nodes/addPromptNode.d.ts +3 -1
  20. package/dist/nodes/addPromptNode.d.ts.map +1 -1
  21. package/dist/nodes/addPromptNode.js +2 -2
  22. package/dist/nodes/addPromptNode.js.map +1 -1
  23. package/dist/nodes/addToolRunNode.d.ts +3 -1
  24. package/dist/nodes/addToolRunNode.d.ts.map +1 -1
  25. package/dist/nodes/addToolRunNode.js +2 -2
  26. package/dist/nodes/addToolRunNode.js.map +1 -1
  27. package/dist/nodes/nodeFactory.d.ts +3 -1
  28. package/dist/nodes/nodeFactory.d.ts.map +1 -1
  29. package/dist/nodes/nodeFactory.js +3 -3
  30. package/dist/nodes/nodeFactory.js.map +1 -1
  31. package/dist/pii-gateway/gateway.d.ts +17 -0
  32. package/dist/pii-gateway/gateway.d.ts.map +1 -0
  33. package/dist/pii-gateway/gateway.js +77 -0
  34. package/dist/pii-gateway/gateway.js.map +1 -0
  35. package/dist/pii-gateway/index.d.ts +4 -0
  36. package/dist/pii-gateway/index.d.ts.map +1 -0
  37. package/dist/pii-gateway/index.js +14 -0
  38. package/dist/pii-gateway/index.js.map +1 -0
  39. package/dist/pii-gateway/proxy.d.ts +80 -0
  40. package/dist/pii-gateway/proxy.d.ts.map +1 -0
  41. package/dist/pii-gateway/proxy.js +106 -0
  42. package/dist/pii-gateway/proxy.js.map +1 -0
  43. package/dist/pii-gateway/types.d.ts +27 -0
  44. package/dist/pii-gateway/types.d.ts.map +1 -0
  45. package/dist/pii-gateway/types.js +3 -0
  46. package/dist/pii-gateway/types.js.map +1 -0
  47. package/dist/platform/mindedConnectionTypes.d.ts +18 -1
  48. package/dist/platform/mindedConnectionTypes.d.ts.map +1 -1
  49. package/dist/platform/mindedConnectionTypes.js +1 -0
  50. package/dist/platform/mindedConnectionTypes.js.map +1 -1
  51. package/dist/platform/piiGateway/gateway.d.ts +16 -0
  52. package/dist/platform/piiGateway/gateway.d.ts.map +1 -0
  53. package/dist/platform/piiGateway/gateway.js +76 -0
  54. package/dist/platform/piiGateway/gateway.js.map +1 -0
  55. package/dist/platform/piiGateway/index.d.ts +3 -0
  56. package/dist/platform/piiGateway/index.d.ts.map +1 -0
  57. package/dist/platform/piiGateway/index.js +7 -0
  58. package/dist/platform/piiGateway/index.js.map +1 -0
  59. package/dist/platform/piiGateway/proxy.d.ts +20 -0
  60. package/dist/platform/piiGateway/proxy.d.ts.map +1 -0
  61. package/dist/platform/piiGateway/proxy.js +24 -0
  62. package/dist/platform/piiGateway/proxy.js.map +1 -0
  63. package/dist/platform/piiGateway/types.d.ts +27 -0
  64. package/dist/platform/piiGateway/types.d.ts.map +1 -0
  65. package/dist/platform/piiGateway/types.js +3 -0
  66. package/dist/platform/piiGateway/types.js.map +1 -0
  67. package/dist/types/LangGraph.types.d.ts +1 -0
  68. package/dist/types/LangGraph.types.d.ts.map +1 -1
  69. package/dist/types/LangGraph.types.js +1 -0
  70. package/dist/types/LangGraph.types.js.map +1 -1
  71. package/dist/types/Tools.types.d.ts +8 -6
  72. package/dist/types/Tools.types.d.ts.map +1 -1
  73. package/package.json +2 -2
  74. package/src/agent.ts +27 -5
  75. package/src/edges/edgeFactory.ts +4 -1
  76. package/src/index.ts +14 -3
  77. package/src/internalTools/appActionRunnerTool.ts +53 -50
  78. package/src/nodes/addAppToolNode.ts +4 -1
  79. package/src/nodes/addPromptNode.ts +5 -3
  80. package/src/nodes/addToolRunNode.ts +4 -2
  81. package/src/nodes/nodeFactory.ts +7 -4
  82. package/src/platform/mindedConnectionTypes.ts +19 -0
  83. package/src/platform/piiGateway/gateway.ts +97 -0
  84. package/src/platform/piiGateway/index.ts +5 -0
  85. package/src/platform/piiGateway/types.ts +29 -0
  86. package/src/types/LangGraph.types.ts +1 -0
  87. package/src/types/Tools.types.ts +9 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/platform/piiGateway/types.ts"],"names":[],"mappings":""}
@@ -26,6 +26,7 @@ export declare const stateAnnotation: import("@langchain/langgraph").AnnotationR
26
26
  Root: <S extends import("@langchain/langgraph").StateDefinition>(sd: S) => import("@langchain/langgraph").AnnotationRoot<S>;
27
27
  };
28
28
  history: import("@langchain/langgraph").BinaryOperatorAggregate<FlowHistory[], FlowHistory[]>;
29
+ sessionId: import("@langchain/langgraph").LastValue<string>;
29
30
  }>;
30
31
  export type CompiledGraph = CompiledStateGraph<any, any, string>;
31
32
  export type PreCompiledGraph = StateGraph<any, any, string>;
@@ -1 +1 @@
1
- {"version":3,"file":"LangGraph.types.d.ts","sourceRoot":"","sources":["../../src/types/LangGraph.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAc,kBAAkB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAEtE,eAAO,MAAM,eAAe;;;;;;kBAclB,MAAM;yBACC,GAAG;;;kBADV,MAAM;yBACC,GAAG;;kBADV,MAAM;yBACC,GAAG;;kBADV,MAAM;yBACC,GAAG;;kBADV,MAAM;yBACC,GAAG;;;;;EAMlB,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;AACjE,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC"}
1
+ {"version":3,"file":"LangGraph.types.d.ts","sourceRoot":"","sources":["../../src/types/LangGraph.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAc,kBAAkB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAEtE,eAAO,MAAM,eAAe;;;;;;kBAclB,MAAM;yBACC,GAAG;;;kBADV,MAAM;yBACC,GAAG;;kBADV,MAAM;yBACC,GAAG;;kBADV,MAAM;yBACC,GAAG;;kBADV,MAAM;yBACC,GAAG;;;;;;EAOlB,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;AACjE,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC"}
@@ -20,5 +20,6 @@ exports.stateAnnotation = langgraph_1.Annotation.Root({
20
20
  default: () => [],
21
21
  reducer: (a, b) => a.concat(b),
22
22
  }),
23
+ sessionId: (0, langgraph_1.Annotation)(),
23
24
  });
24
25
  //# sourceMappingURL=LangGraph.types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"LangGraph.types.js","sourceRoot":"","sources":["../../src/types/LangGraph.types.ts"],"names":[],"mappings":";;;AACA,oDAAkF;AAGrE,QAAA,eAAe,GAAG,sBAAU,CAAC,IAAI,CAAC;IAC7C,QAAQ,EAAE,IAAA,sBAAU,EAAqB;QACvC,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE;QACjB,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;KAC/B,CAAC;IACF,MAAM,EAAE,IAAA,sBAAU,EAAM;QACtB,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;QACnB,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;KACpC,CAAC;IACF,kBAAkB,EAAE,IAAA,sBAAU,EAAkC;QAC9D,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE;QACjB,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;KAC/B,CAAC;IACF,eAAe,EAAE,CAAA,sBAGR,CAAA;IACT,OAAO,EAAE,IAAA,sBAAU,EAAqB;QACtC,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE;QACjB,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;KAC/B,CAAC;CACH,CAAC,CAAC"}
1
+ {"version":3,"file":"LangGraph.types.js","sourceRoot":"","sources":["../../src/types/LangGraph.types.ts"],"names":[],"mappings":";;;AACA,oDAAkF;AAGrE,QAAA,eAAe,GAAG,sBAAU,CAAC,IAAI,CAAC;IAC7C,QAAQ,EAAE,IAAA,sBAAU,EAAqB;QACvC,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE;QACjB,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;KAC/B,CAAC;IACF,MAAM,EAAE,IAAA,sBAAU,EAAM;QACtB,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;QACnB,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;KACpC,CAAC;IACF,kBAAkB,EAAE,IAAA,sBAAU,EAAkC;QAC9D,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE;QACjB,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;KAC/B,CAAC;IACF,eAAe,EAAE,CAAA,sBAGR,CAAA;IACT,OAAO,EAAE,IAAA,sBAAU,EAAqB;QACtC,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE;QACjB,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;KAC/B,CAAC;IACF,SAAS,EAAE,IAAA,sBAAU,GAAU;CAChC,CAAC,CAAC"}
@@ -1,19 +1,21 @@
1
1
  import { z } from 'zod';
2
- import { FlowHistory } from './Agent.types';
2
+ import { Agent } from '../';
3
+ import { stateAnnotation } from './LangGraph.types';
3
4
  export interface Tool<Input extends z.ZodSchema, Memory> {
4
5
  name: string;
5
6
  description: string;
6
7
  input: Input;
7
8
  isGlobal?: boolean;
8
- execute: ({ input, memory, triggerInvocations }: {
9
- input: z.infer<Input>;
10
- memory: Memory;
11
- triggerInvocations?: Array<FlowHistory>;
12
- }) => Promise<{
9
+ execute: (input: ToolExecuteInput<Input>) => Promise<{
13
10
  memory?: Partial<Memory>;
14
11
  result?: any;
15
12
  } | void>;
16
13
  }
14
+ export interface ToolExecuteInput<Input extends z.ZodSchema> {
15
+ input: z.infer<Input>;
16
+ state: typeof stateAnnotation.State;
17
+ agent: Agent;
18
+ }
17
19
  export interface AppActionRunnerInput {
18
20
  appName: string;
19
21
  actionName: string;
@@ -1 +1 @@
1
- {"version":3,"file":"Tools.types.d.ts","sourceRoot":"","sources":["../../src/types/Tools.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,WAAW,IAAI,CAAC,KAAK,SAAS,CAAC,CAAC,SAAS,EAAE,MAAM;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,EAAE;QAAE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,kBAAkB,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,CAAA;KAAE,KAAK,OAAO,CAAC;QAAE,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QAAC,MAAM,CAAC,EAAE,GAAG,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;CACpM;AAGD,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB"}
1
+ {"version":3,"file":"Tools.types.d.ts","sourceRoot":"","sources":["../../src/types/Tools.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,WAAW,IAAI,CAAC,KAAK,SAAS,CAAC,CAAC,SAAS,EAAE,MAAM;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,CAAC,KAAK,EAAE,gBAAgB,CAAC,KAAK,CAAC,KAAK,OAAO,CAAC;QAAE,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QAAC,MAAM,CAAC,EAAE,GAAG,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;CACzG;AAED,MAAM,WAAW,gBAAgB,CAAC,KAAK,SAAS,CAAC,CAAC,SAAS;IACzD,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACtB,KAAK,EAAE,OAAO,eAAe,CAAC,KAAK,CAAC;IACpC,KAAK,EAAE,KAAK,CAAC;CACd;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minded-ai/mindedjs",
3
- "version": "1.0.53",
3
+ "version": "1.0.54",
4
4
  "description": "MindedJS is a TypeScript library for building agents.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -53,4 +53,4 @@
53
53
  "uuid": "^11.1.0",
54
54
  "zod": "^3.24.4"
55
55
  }
56
- }
56
+ }
package/src/agent.ts CHANGED
@@ -23,6 +23,7 @@ import { BaseMessage, HumanMessage } from '@langchain/core/messages';
23
23
  import triggerTypeToDefaultMessage from './triggers/triggerTypeToDefaultMessage';
24
24
  import appActionRunnerToolCreator from './internalTools/appActionRunnerTool';
25
25
  import { wait } from './utils/wait';
26
+ import { PIIGateway, PIIGatewayInstance } from './platform/piiGateway';
26
27
 
27
28
  type CreateAgentParams<Memory> = {
28
29
  memorySchema: z.ZodSchema;
@@ -63,6 +64,17 @@ export class Agent {
63
64
  // Cache for secrets to avoid repeated API calls
64
65
  private secretsCache: Record<string, string> | null = null;
65
66
 
67
+ // PII gateway instance
68
+ private _piiGateway: PIIGatewayInstance | null = null;
69
+
70
+ // PII gateway instance getter
71
+ public get piiGateway(): PIIGatewayInstance {
72
+ if (!this._piiGateway) {
73
+ throw new Error('Minded connection is not established when trying to get PII gateway');
74
+ }
75
+ return this._piiGateway;
76
+ }
77
+
66
78
  // Event handlers storage keyed by event name. Handlers can optionally return a value.
67
79
  private eventHandlers: {
68
80
  [K in keyof AgentEventRequestPayloads<z.infer<typeof this.memorySchema>>]?: Array<
@@ -118,6 +130,9 @@ export class Agent {
118
130
  this.mindedConnection = new MindedConnection();
119
131
  await this.mindedConnection.start();
120
132
 
133
+ // Initialize PII gateway
134
+ this._piiGateway = new PIIGateway(this.mindedConnection);
135
+
121
136
  this.mindedConnection.on(MindedConnectionSocketMessageType.OnAppTrigger, async (message: BaseMindedConnectionSocketMessage) => {
122
137
  const trigger = message as OnAppTrigger;
123
138
  await this.invoke({
@@ -241,6 +256,7 @@ export class Agent {
241
256
  tools: this.tools,
242
257
  llm: this.llm,
243
258
  emit: this.emit.bind(this),
259
+ agent: this,
244
260
  });
245
261
  });
246
262
 
@@ -269,19 +285,20 @@ export class Agent {
269
285
  });
270
286
 
271
287
  // Add edges
272
- edgeFactory({ graph, edges, nodes: nodesObject, tools: this.tools, llm: this.llm });
288
+ edgeFactory({ graph, edges, nodes: nodesObject, tools: this.tools, llm: this.llm, agent: this });
273
289
 
274
290
  // Compile the graph
275
291
  return graph.compile({ checkpointer: this.checkpointer }) as CompiledGraph;
276
292
  }
277
293
 
278
- private initGraphState(): typeof stateAnnotation.State {
294
+ private initGraphState(state: typeof stateAnnotation.State): typeof stateAnnotation.State {
279
295
  return {
280
296
  messages: [],
281
297
  memory: {} as z.infer<typeof this.memorySchema>,
282
298
  triggerMetadata: null,
283
299
  history: [],
284
300
  triggerInvocations: [] as Array<TriggerInvocationHistory>,
301
+ sessionId: state.sessionId || uuidv4(), // Preserve existing sessionId or generate new one
285
302
  };
286
303
  }
287
304
 
@@ -327,6 +344,7 @@ export class Agent {
327
344
  await this.waitForInitialization();
328
345
  let messages: Array<BaseMessage> = [];
329
346
  let memoryUpdate = {};
347
+ sessionId = sessionId ?? uuidv4();
330
348
  if (triggerName === KnownTriggerNames.DASHBOARD_MESSAGE) {
331
349
  messages.push(new HumanMessage(triggerBody.content));
332
350
  } else {
@@ -354,6 +372,7 @@ export class Agent {
354
372
  }
355
373
  }
356
374
  }
375
+
357
376
  const triggerInvocation = { appName, triggerName, triggerBody };
358
377
  const history = [
359
378
  {
@@ -362,23 +381,26 @@ export class Agent {
362
381
  },
363
382
  ];
364
383
  console.log(`Invoking trigger ${triggerName} with session ${sessionId}`);
365
- const config = { configurable: { thread_id: sessionId || uuidv4(), recursionLimit: 3 } };
384
+ const config = { configurable: { thread_id: sessionId, recursionLimit: 3 } };
385
+
366
386
  const state = await this.compiledGraph.getState(config);
367
387
  // Resume interruption
368
388
  if (state.tasks?.[0]?.interrupts?.length > 0) {
369
389
  console.log('Resuming interruption');
370
390
  const res = await this.compiledGraph.invoke(
371
391
  new Command({
372
- resume: { memory: memoryUpdate, messages, history, triggerInvocations: [triggerInvocation] },
392
+ resume: { memory: memoryUpdate, messages, history, triggerInvocations: [triggerInvocation], sessionId },
373
393
  }),
374
394
  config,
375
395
  );
396
+
376
397
  return res;
377
398
  } else {
378
399
  const res = await this.compiledGraph.invoke(
379
- { messages, memory: memoryUpdate, history, triggerInvocations: [triggerInvocation] },
400
+ { messages, memory: memoryUpdate, history, triggerInvocations: [triggerInvocation], sessionId },
380
401
  config,
381
402
  );
403
+
382
404
  return res;
383
405
  }
384
406
  }
@@ -7,6 +7,7 @@ import { createDirectEdge } from './createDirectEdge';
7
7
  import { addHumanInTheLoopNode, buildHumanInTheLoopNodeName } from '../nodes/addHumanInTheLoopNode';
8
8
  import { addToolRunNode, buildToolRunNodeName } from '../nodes/addToolRunNode';
9
9
  import { Tool } from '../types/Tools.types';
10
+ import { Agent } from '../agent';
10
11
 
11
12
  type EdgesBySource = {
12
13
  stepForward?: StepForwardEdge;
@@ -20,12 +21,14 @@ export const edgeFactory = ({
20
21
  nodes,
21
22
  tools,
22
23
  llm,
24
+ agent,
23
25
  }: {
24
26
  graph: PreCompiledGraph;
25
27
  edges: Edge[];
26
28
  nodes: Record<string, Node>;
27
29
  tools: Tool<any, any>[];
28
30
  llm: BaseLanguageModel;
31
+ agent: Agent;
29
32
  }) => {
30
33
  /**
31
34
  * Creates a combined router that handles edge priority: step forward > logical > prompt
@@ -71,7 +74,7 @@ export const edgeFactory = ({
71
74
  }
72
75
 
73
76
  if (nodes[source]?.type === NodeType.TOOL) {
74
- addToolRunNode({ graph, tools, llm, toolNode: nodes[source] as ToolNode, attachedToNodeName: source });
77
+ addToolRunNode({ graph, tools, llm, toolNode: nodes[source] as ToolNode, attachedToNodeName: source, agent });
75
78
  effectiveSource = buildToolRunNodeName(source);
76
79
  }
77
80
 
package/src/index.ts CHANGED
@@ -3,6 +3,9 @@ import events from './events';
3
3
 
4
4
  export { Agent, events };
5
5
 
6
+ // HTTP module for PII masking - only public API
7
+ export type { PIIGatewayInstance, HttpRequestConfig, HttpResponse } from './platform/piiGateway';
8
+
6
9
  export type {
7
10
  Flow,
8
11
  Node,
@@ -18,7 +21,15 @@ export type {
18
21
  ToolNode,
19
22
  AppToolNode,
20
23
  } from './types/Flows.types';
21
- export { NodeType, TriggerType, EdgeType, AppNodeMetadata, AppNodeMetadataType, NodeMetadata, KnownTriggerNames } from './types/Flows.types';
22
- export type { Tool } from './types/Tools.types';
24
+ export {
25
+ NodeType,
26
+ TriggerType,
27
+ EdgeType,
28
+ AppNodeMetadata,
29
+ AppNodeMetadataType,
30
+ NodeMetadata,
31
+ KnownTriggerNames,
32
+ } from './types/Flows.types';
33
+ export type { Tool, ToolExecuteInput } from './types/Tools.types';
23
34
  export { FlowHistoryType, FlowHistory, TriggerInvocationHistory, AppActionInvocationHistory } from './types/Agent.types';
24
- export type { Environment } from './types/Platform.types';
35
+ export type { Environment } from './types/Platform.types';
@@ -5,66 +5,69 @@ import { Tool } from '../types/Tools.types';
5
5
  import { z } from 'zod';
6
6
 
7
7
  const typeToZodMap = {
8
- string: z.string(),
9
- number: z.number(),
10
- boolean: z.boolean(),
11
- array: z.array(z.any()),
12
- object: z.record(z.any()),
13
- any: z.any()
8
+ string: z.string(),
9
+ number: z.number(),
10
+ boolean: z.boolean(),
11
+ array: z.array(z.any()),
12
+ object: z.record(z.any()),
13
+ any: z.any(),
14
14
  } as const;
15
15
 
16
16
  const convertToZodSchema = (schema: Record<string, { type: string; example?: any }>) => {
17
- const zodSchema: Record<string, z.ZodType> = {};
18
- for (const [key, { type }] of Object.entries(schema)) {
19
- const zodType = typeToZodMap[type.toLowerCase() as keyof typeof typeToZodMap] ?? z.string();
20
- zodSchema[key] = zodType;
21
- }
22
- return z.object(zodSchema);
17
+ const zodSchema: Record<string, z.ZodType> = {};
18
+ for (const [key, { type }] of Object.entries(schema)) {
19
+ const zodType = typeToZodMap[type.toLowerCase() as keyof typeof typeToZodMap] ?? z.string();
20
+ zodSchema[key] = zodType;
21
+ }
22
+ return z.object(zodSchema);
23
23
  };
24
24
 
25
25
  const createdTools: Record<string, Tool<any, any>> = {};
26
26
 
27
27
  const appActionRunnerToolCreator = (schema: ActionInputParam[], nodeTitle: string, mindedConnection: MindedConnection): Tool<any, any> => {
28
- const zodSchema = convertToZodSchema(schema.reduce(
29
- (acc, param) => {
30
- if (param.required) {
31
- acc[param.name] = { type: param.type, example: param.example };
32
- }
33
- return acc;
34
- },
35
- {} as Record<string, { type: string; example?: any }>,
36
- ));
37
- type InputType = z.infer<typeof zodSchema>;
38
- // Create a description that includes examples
39
- const description = `Run ${nodeTitle} action. Example input: ${JSON.stringify(
40
- schema.reduce((acc, param) => {
41
- if (param.example !== undefined) {
42
- acc[param.name] = param.example;
43
- }
44
- return acc;
45
- }, {} as Record<string, any>),
46
- null,
47
- 2
48
- )}`;
28
+ const zodSchema = convertToZodSchema(
29
+ schema.reduce((acc, param) => {
30
+ if (param.required) {
31
+ acc[param.name] = { type: param.type, example: param.example };
32
+ }
33
+ return acc;
34
+ }, {} as Record<string, { type: string; example?: any }>),
35
+ );
36
+ type InputType = z.infer<typeof zodSchema>;
37
+ // Create a description that includes examples
38
+ const description = `Run ${nodeTitle} action. Example input: ${JSON.stringify(
39
+ schema.reduce((acc, param) => {
40
+ if (param.example !== undefined) {
41
+ acc[param.name] = param.example;
42
+ }
43
+ return acc;
44
+ }, {} as Record<string, any>),
45
+ null,
46
+ 2,
47
+ )}`;
49
48
 
50
- const tool = {
51
- name: nodeTitle,
52
- description,
53
- input: zodSchema,
54
- execute: async ({ input }: { input: InputType }) => {
55
- const response = await mindedConnection.awaitEmit(MindedConnectionSocketMessageType.OnAppAction, {
56
- nodeTitle,
57
- actionInput: input,
58
- }, 20000);
59
- return response as { result?: any };
49
+ const tool = {
50
+ name: nodeTitle,
51
+ description,
52
+ input: zodSchema,
53
+ execute: async ({ input }: { input: InputType }) => {
54
+ const response = await mindedConnection.awaitEmit(
55
+ MindedConnectionSocketMessageType.OnAppAction,
56
+ {
57
+ nodeTitle,
58
+ actionInput: input,
60
59
  },
61
- };
62
- createdTools[nodeTitle] = tool;
63
- return tool;
64
- }
60
+ 20000,
61
+ );
62
+ return response as { result?: any };
63
+ },
64
+ };
65
+ createdTools[nodeTitle] = tool;
66
+ return tool;
67
+ };
65
68
 
66
69
  export const getAppActionRunnerTool = (nodeTitle: string) => {
67
- return createdTools[nodeTitle];
68
- }
70
+ return createdTools[nodeTitle];
71
+ };
69
72
 
70
- export default appActionRunnerToolCreator;
73
+ export default appActionRunnerToolCreator;
@@ -7,15 +7,18 @@ import { z } from 'zod';
7
7
  import { LLMProviders } from '../types/LLM.types';
8
8
  import { getAppActionRunnerTool } from '../internalTools/appActionRunnerTool';
9
9
  import { FlowHistoryType } from '../types/Agent.types';
10
+ import { Agent } from '../agent';
10
11
 
11
12
  export const addAppToolNode = async ({
12
13
  graph,
13
14
  node,
14
15
  llm,
16
+ agent,
15
17
  }: {
16
18
  graph: PreCompiledGraph;
17
19
  node: AppToolNode;
18
20
  llm: (typeof LLMProviders)[keyof typeof LLMProviders];
21
+ agent: Agent;
19
22
  }) => {
20
23
  const appRunnerTool = getAppActionRunnerTool(node.name);
21
24
  const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
@@ -23,7 +26,7 @@ export const addAppToolNode = async ({
23
26
 
24
27
  const executeWrapper = async (input: z.infer<typeof appRunnerTool.input>) => {
25
28
  try {
26
- const response = await appRunnerTool.execute({ input, memory: state.memory, triggerInvocations: state.triggerInvocations });
29
+ const response = await appRunnerTool.execute({ input, state, agent });
27
30
  return response || {};
28
31
  } catch (error) {
29
32
  console.error('Error executing tool', error);
@@ -10,6 +10,7 @@ import { AgentEventRequestPayloads, AgentEvents } from '../events/AgentEvents';
10
10
  import { EmitSignature } from '../types/Agent.types';
11
11
  import { createLlmInstance } from '../llm/createLlmInstance';
12
12
  import extractToolMemoryResponse from '../utils/extractToolMemoryResponse';
13
+ import { Agent } from '../agent';
13
14
 
14
15
  type AddPromptNodeParams = {
15
16
  graph: PreCompiledGraph;
@@ -17,9 +18,10 @@ type AddPromptNodeParams = {
17
18
  llm: BaseLanguageModel;
18
19
  tools: Tool<any, any>[];
19
20
  emit: EmitSignature<any, keyof AgentEventRequestPayloads<any>>;
21
+ agent: Agent;
20
22
  };
21
23
 
22
- export const addPromptNode = async ({ graph, node, llm, tools, emit }: AddPromptNodeParams) => {
24
+ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: AddPromptNodeParams) => {
23
25
  const callback: RunnableLike = async (state: typeof stateAnnotation.State, { configurable }) => {
24
26
  console.log(`Executing prompt node ${node.name}`);
25
27
  const llmToUse = node.llmConfig ? createLlmInstance(node.llmConfig) : llm;
@@ -27,7 +29,7 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit }: AddPrompt
27
29
  const globalTools = tools
28
30
  .filter((tool) => tool.isGlobal)
29
31
  .map((tool) =>
30
- langchainTool((input: z.infer<typeof tool.input>) => tool.execute({ input, memory: state.memory }), {
32
+ langchainTool((input: z.infer<typeof tool.input>) => tool.execute({ input, state, agent }), {
31
33
  name: tool.name,
32
34
  description: tool.description,
33
35
  schema: tool.input,
@@ -88,4 +90,4 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit }: AddPrompt
88
90
  };
89
91
  };
90
92
  graph.addNode(node.name, callback);
91
- };
93
+ };
@@ -7,6 +7,7 @@ import { tool as langchainTool } from '@langchain/core/tools';
7
7
  import { ToolMessage } from '@langchain/core/messages';
8
8
  import { z } from 'zod';
9
9
  import extractToolMemoryResponse from '../utils/extractToolMemoryResponse';
10
+ import { Agent } from '../agent';
10
11
 
11
12
  type AddToolRunNodeParams = {
12
13
  graph: PreCompiledGraph;
@@ -14,11 +15,12 @@ type AddToolRunNodeParams = {
14
15
  llm: (typeof LLMProviders)[keyof typeof LLMProviders];
15
16
  toolNode: ToolNode;
16
17
  attachedToNodeName: string;
18
+ agent: Agent;
17
19
  };
18
20
 
19
21
  export const buildToolRunNodeName = (nodeName: string) => `${nodeName}_toolRun`;
20
22
 
21
- export const addToolRunNode = async ({ graph, tools, toolNode, attachedToNodeName }: AddToolRunNodeParams) => {
23
+ export const addToolRunNode = async ({ graph, tools, toolNode, attachedToNodeName, agent }: AddToolRunNodeParams) => {
22
24
  const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
23
25
  const matchedTool = tools.find((tool) => tool.name === toolNode.toolName);
24
26
  if (!matchedTool) {
@@ -27,7 +29,7 @@ export const addToolRunNode = async ({ graph, tools, toolNode, attachedToNodeNam
27
29
 
28
30
  const executeWrapper = async (input: z.infer<typeof matchedTool.input>) => {
29
31
  try {
30
- const response = await matchedTool.execute({ input, memory: state.memory, triggerInvocations: state.triggerInvocations });
32
+ const response = await matchedTool.execute({ input, state, agent });
31
33
  return response || {};
32
34
  } catch (error) {
33
35
  console.error('Error executing tool', error);
@@ -9,9 +9,10 @@ import { EmitSignature } from '../types/Agent.types';
9
9
  import { addAppToolNode } from './addAppToolNode';
10
10
  import { addTriggerNode } from './addTriggerNode';
11
11
  import { LLMProviders } from '../types/LLM.types';
12
+ import { Agent } from '../agent';
12
13
 
13
14
  const addJunctionNode = ({ graph, node }: { graph: PreCompiledGraph; node: JunctionNode }) => {
14
- const callback: RunnableLike = async () => { };
15
+ const callback: RunnableLike = async () => {};
15
16
  graph.addNode(node.name, callback);
16
17
  };
17
18
 
@@ -21,12 +22,14 @@ export const nodeFactory = ({
21
22
  tools,
22
23
  llm,
23
24
  emit,
25
+ agent,
24
26
  }: {
25
27
  graph: PreCompiledGraph;
26
28
  node: Node;
27
29
  tools: Tool<any, any>[];
28
- llm: typeof LLMProviders[keyof typeof LLMProviders];
30
+ llm: (typeof LLMProviders)[keyof typeof LLMProviders];
29
31
  emit: EmitSignature<any, keyof AgentEventRequestPayloads<any>>;
32
+ agent: Agent;
30
33
  }) => {
31
34
  const nodeType = node.type;
32
35
  switch (nodeType) {
@@ -40,10 +43,10 @@ export const nodeFactory = ({
40
43
  addJunctionNode({ graph, node });
41
44
  break;
42
45
  case NodeType.APP_TOOL:
43
- addAppToolNode({ graph, node, llm });
46
+ addAppToolNode({ graph, node, llm, agent });
44
47
  break;
45
48
  case NodeType.PROMPT_NODE:
46
- addPromptNode({ graph, node, tools, llm, emit });
49
+ addPromptNode({ graph, node, tools, llm, emit, agent });
47
50
  break;
48
51
  default:
49
52
  throw new Error(`Unsupported node type: ${nodeType}`);
@@ -17,6 +17,7 @@ export enum MindedConnectionSocketMessageType {
17
17
  CHECKPOINT_PUT_WRITES = 'checkpoint-put-writes',
18
18
  GET_SECRETS = 'get-secrets',
19
19
  GET_FLOWS = 'get-flows',
20
+ PII_HTTP_REQUEST = 'pii-http-request',
20
21
  }
21
22
 
22
23
  export interface BaseMindedConnectionSocketMessage {
@@ -66,3 +67,21 @@ export interface OnCheckpointList extends BaseMindedConnectionSocketMessage {
66
67
  export interface OnCheckpointListResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
67
68
  checkpoints?: CheckpointTuple[];
68
69
  }
70
+
71
+ export interface OnPiiHttpRequest extends BaseMindedConnectionSocketMessage {
72
+ sessionId: string;
73
+ requestId: string;
74
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
75
+ url: string;
76
+ headers?: Record<string, string>;
77
+ params?: Record<string, any>;
78
+ data?: any;
79
+ }
80
+
81
+ export interface OnPiiHttpResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
82
+ requestId: string;
83
+ data?: any;
84
+ status?: number;
85
+ statusText?: string;
86
+ headers?: Record<string, string>;
87
+ }
@@ -0,0 +1,97 @@
1
+ import { v4 as uuidv4 } from 'uuid';
2
+ import { MindedConnection } from '../mindedConnection';
3
+ import { MindedConnectionSocketMessageType, OnPiiHttpRequest, OnPiiHttpResponse } from '../mindedConnectionTypes';
4
+ import { HttpRequestConfig, HttpResponse, PIIGatewayInstance } from './types';
5
+
6
+ export class PIIGateway implements PIIGatewayInstance {
7
+ private mindedConnection: MindedConnection;
8
+
9
+ constructor(mindedConnection: MindedConnection) {
10
+ this.mindedConnection = mindedConnection;
11
+ }
12
+
13
+ private async makeRequest<T = any>(
14
+ sessionId: string,
15
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS',
16
+ url: string,
17
+ data?: any,
18
+ config?: HttpRequestConfig,
19
+ ): Promise<HttpResponse<T>> {
20
+ if (!this.mindedConnection?.isConnected) {
21
+ throw new Error('Minded connection is not established. PII-secured HTTP requests require a connection to the Minded platform.');
22
+ }
23
+
24
+ try {
25
+ const requestId = uuidv4();
26
+ const requestPayload: OnPiiHttpRequest = {
27
+ type: MindedConnectionSocketMessageType.PII_HTTP_REQUEST,
28
+ requestId,
29
+ method,
30
+ url,
31
+ headers: config?.headers as Record<string, string>,
32
+ params: config?.params,
33
+ data,
34
+ sessionId,
35
+ };
36
+
37
+ const response = await this.mindedConnection.awaitEmit<OnPiiHttpRequest, OnPiiHttpResponse>(
38
+ MindedConnectionSocketMessageType.PII_HTTP_REQUEST,
39
+ requestPayload,
40
+ 30000, // 30 second timeout for HTTP requests
41
+ );
42
+
43
+ if (response.error) {
44
+ throw new Error(`HTTP request failed: ${response.error}`);
45
+ }
46
+
47
+ // Verify that the response requestId matches our request
48
+ if (response.requestId && response.requestId !== requestId) {
49
+ console.warn(`Response requestId (${response.requestId}) does not match request requestId (${requestId})`);
50
+ }
51
+
52
+ // Return generic HttpResponse format
53
+ return {
54
+ data: response.data,
55
+ status: response.status || 200,
56
+ statusText: response.statusText || 'OK',
57
+ headers: response.headers || {},
58
+ config: config || {},
59
+ };
60
+ } catch (error) {
61
+ throw new Error(`Secure HTTP request failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
62
+ }
63
+ }
64
+
65
+ async get<T = any>(sessionId: string, url: string, config?: HttpRequestConfig): Promise<HttpResponse<T>> {
66
+ return this.makeRequest<T>(sessionId, 'GET', url, undefined, config);
67
+ }
68
+
69
+ async post<T = any>(sessionId: string, url: string, data?: any, config?: HttpRequestConfig): Promise<HttpResponse<T>> {
70
+ return this.makeRequest<T>(sessionId, 'POST', url, data, config);
71
+ }
72
+
73
+ async put<T = any>(sessionId: string, url: string, data?: any, config?: HttpRequestConfig): Promise<HttpResponse<T>> {
74
+ return this.makeRequest<T>(sessionId, 'PUT', url, data, config);
75
+ }
76
+
77
+ async delete<T = any>(sessionId: string, url: string, config?: HttpRequestConfig): Promise<HttpResponse<T>> {
78
+ return this.makeRequest<T>(sessionId, 'DELETE', url, undefined, config);
79
+ }
80
+
81
+ async patch<T = any>(sessionId: string, url: string, data?: any, config?: HttpRequestConfig): Promise<HttpResponse<T>> {
82
+ return this.makeRequest<T>(sessionId, 'PATCH', url, data, config);
83
+ }
84
+
85
+ async head<T = any>(sessionId: string, url: string, config?: HttpRequestConfig): Promise<HttpResponse<T>> {
86
+ return this.makeRequest<T>(sessionId, 'HEAD', url, undefined, config);
87
+ }
88
+
89
+ async options<T = any>(sessionId: string, url: string, config?: HttpRequestConfig): Promise<HttpResponse<T>> {
90
+ return this.makeRequest<T>(sessionId, 'OPTIONS', url, undefined, config);
91
+ }
92
+
93
+ async request<T = any>(sessionId: string, config: HttpRequestConfig): Promise<HttpResponse<T>> {
94
+ const method = (config.method?.toUpperCase() || 'GET') as any;
95
+ return this.makeRequest<T>(sessionId, method, config.url || '', config.data, config);
96
+ }
97
+ }
@@ -0,0 +1,5 @@
1
+ // Export types
2
+ export type { HttpRequestConfig, HttpResponse, PIIGatewayInstance } from './types';
3
+
4
+ // Export core gateway class and creation function
5
+ export { PIIGateway } from './gateway';