@minded-ai/mindedjs 1.0.31 → 1.0.33

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 (57) hide show
  1. package/dist/internalTools/appActionRunnerTool.d.ts +7 -0
  2. package/dist/internalTools/appActionRunnerTool.d.ts.map +1 -0
  3. package/dist/internalTools/appActionRunnerTool.js +49 -0
  4. package/dist/internalTools/appActionRunnerTool.js.map +1 -0
  5. package/dist/internalTools/utils.d.ts +2 -0
  6. package/dist/internalTools/utils.d.ts.map +1 -0
  7. package/dist/internalTools/utils.js +8 -0
  8. package/dist/internalTools/utils.js.map +1 -0
  9. package/dist/nodes/actionRunnerNode.d.ts +14 -0
  10. package/dist/nodes/actionRunnerNode.d.ts.map +1 -0
  11. package/dist/nodes/actionRunnerNode.js +100 -0
  12. package/dist/nodes/actionRunnerNode.js.map +1 -0
  13. package/dist/nodes/actionRunnerTool.d.ts +14 -0
  14. package/dist/nodes/actionRunnerTool.d.ts.map +1 -0
  15. package/dist/nodes/actionRunnerTool.js +101 -0
  16. package/dist/nodes/actionRunnerTool.js.map +1 -0
  17. package/dist/nodes/addAppTool.d.ts +8 -0
  18. package/dist/nodes/addAppTool.js +12 -0
  19. package/dist/nodes/addAppTool.js.map +1 -0
  20. package/dist/nodes/addAppToolNode.d.ts +9 -0
  21. package/dist/nodes/addAppToolNode.d.ts.map +1 -0
  22. package/dist/nodes/addAppToolNode.js +62 -0
  23. package/dist/nodes/addAppToolNode.js.map +1 -0
  24. package/dist/nodes/addPromptNode.d.ts.map +1 -1
  25. package/dist/nodes/addPromptNode.js +10 -24
  26. package/dist/nodes/addPromptNode.js.map +1 -1
  27. package/dist/nodes/addToolNode.d.ts +2 -2
  28. package/dist/nodes/addToolNode.d.ts.map +1 -1
  29. package/dist/nodes/addToolNode.js +24 -70
  30. package/dist/nodes/addToolNode.js.map +1 -1
  31. package/dist/nodes/callTool.d.ts +10 -0
  32. package/dist/nodes/callTool.js +57 -0
  33. package/dist/nodes/callTool.js.map +1 -0
  34. package/dist/nodes/nodeFactory.d.ts +2 -2
  35. package/dist/nodes/nodeFactory.d.ts.map +1 -1
  36. package/dist/nodes/nodeFactory.js.map +1 -1
  37. package/dist/nodes/toolNodeRunner.d.ts +15 -0
  38. package/dist/nodes/toolNodeRunner.js +79 -0
  39. package/dist/nodes/toolNodeRunner.js.map +1 -0
  40. package/dist/platform/mindedRequest.js +2 -2
  41. package/dist/platform/mindedRequest.js.map +1 -1
  42. package/dist/tools/appToolRunner.d.ts +30 -0
  43. package/dist/tools/appToolRunner.js +35 -0
  44. package/dist/tools/appToolRunner.js.map +1 -0
  45. package/dist/tools/parser.d.ts +14 -0
  46. package/dist/tools/parser.js +17 -0
  47. package/dist/tools/parser.js.map +1 -0
  48. package/dist/tools/triggerTypeToDefaultMessage.d.ts +3 -0
  49. package/dist/tools/triggerTypeToDefaultMessage.js +10 -0
  50. package/dist/tools/triggerTypeToDefaultMessage.js.map +1 -0
  51. package/package.json +2 -2
  52. package/src/nodes/addPromptNode.ts +13 -26
  53. package/src/nodes/addToolNode.ts +27 -84
  54. package/src/nodes/nodeFactory.ts +2 -1
  55. package/dist/types/Triggers.types.d.ts +0 -1
  56. package/dist/types/Triggers.types.js +0 -3
  57. package/dist/types/Triggers.types.js.map +0 -1
@@ -0,0 +1,7 @@
1
+ import { MindedConnectionSocketMessageType } from '../platform/mindedConnectionTypes';
2
+ import { ActionInputParam } from '../types/Flows.types';
3
+ import { Tool } from '../types/Tools.types';
4
+ declare const appActionRunnerToolCreator: (schema: ActionInputParam[], nodeTitle: string, awaitEmit: (event: MindedConnectionSocketMessageType, payload: any) => Promise<any>) => Tool<any, any>;
5
+ export declare const getAppActionRunnerTool: (nodeTitle: string) => Tool<any, any>;
6
+ export default appActionRunnerToolCreator;
7
+ //# sourceMappingURL=appActionRunnerTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appActionRunnerTool.d.ts","sourceRoot":"","sources":["../../src/internalTools/appActionRunnerTool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,mCAAmC,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAuB5C,QAAA,MAAM,0BAA0B,GAAI,QAAQ,gBAAgB,EAAE,EAAE,WAAW,MAAM,EAAE,WAAW,CAAC,KAAK,EAAE,iCAAiC,EAAE,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,KAAG,IAAI,CAAC,GAAG,EAAE,GAAG,CAwBrL,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAI,WAAW,MAAM,mBAEvD,CAAA;AAED,eAAe,0BAA0B,CAAC"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAppActionRunnerTool = void 0;
4
+ const mindedConnectionTypes_1 = require("../platform/mindedConnectionTypes");
5
+ const zod_1 = require("zod");
6
+ const typeToZodMap = {
7
+ string: zod_1.z.string(),
8
+ number: zod_1.z.number(),
9
+ boolean: zod_1.z.boolean(),
10
+ array: zod_1.z.array(zod_1.z.any()),
11
+ object: zod_1.z.record(zod_1.z.any()),
12
+ any: zod_1.z.any()
13
+ };
14
+ const convertToZodSchema = (schema) => {
15
+ var _a;
16
+ const zodSchema = {};
17
+ for (const [key, type] of Object.entries(schema)) {
18
+ const zodType = (_a = typeToZodMap[type.toLowerCase()]) !== null && _a !== void 0 ? _a : zod_1.z.string();
19
+ zodSchema[key] = zodType;
20
+ }
21
+ return zod_1.z.object(zodSchema);
22
+ };
23
+ const createdTools = {};
24
+ const appActionRunnerToolCreator = (schema, nodeTitle, awaitEmit) => {
25
+ const zodSchema = convertToZodSchema(schema.reduce((acc, param) => {
26
+ acc[param.name] = param.type;
27
+ return acc;
28
+ }, {}));
29
+ const tool = {
30
+ name: nodeTitle,
31
+ description: `Run ${nodeTitle} action from`,
32
+ input: zodSchema,
33
+ execute: async ({ input }) => {
34
+ const response = await awaitEmit(mindedConnectionTypes_1.MindedConnectionSocketMessageType.OnAppAction, {
35
+ nodeTitle,
36
+ actionInput: input,
37
+ });
38
+ return response;
39
+ },
40
+ };
41
+ createdTools[nodeTitle] = tool;
42
+ return tool;
43
+ };
44
+ const getAppActionRunnerTool = (nodeTitle) => {
45
+ return createdTools[nodeTitle];
46
+ };
47
+ exports.getAppActionRunnerTool = getAppActionRunnerTool;
48
+ exports.default = appActionRunnerToolCreator;
49
+ //# sourceMappingURL=appActionRunnerTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appActionRunnerTool.js","sourceRoot":"","sources":["../../src/internalTools/appActionRunnerTool.ts"],"names":[],"mappings":";;;AAAA,6EAAsF;AAGtF,6BAAwB;AAExB,MAAM,YAAY,GAAG;IACjB,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE;IAClB,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE;IAClB,OAAO,EAAE,OAAC,CAAC,OAAO,EAAE;IACpB,KAAK,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,GAAG,EAAE,CAAC;IACvB,MAAM,EAAE,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,GAAG,EAAE,CAAC;IACzB,GAAG,EAAE,OAAC,CAAC,GAAG,EAAE;CACN,CAAC;AAEX,MAAM,kBAAkB,GAAG,CAAC,MAA8B,EAAE,EAAE;;IAC1D,MAAM,SAAS,GAA8B,EAAE,CAAC;IAChD,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC/C,MAAM,OAAO,GAAG,MAAA,YAAY,CAAC,IAAI,CAAC,WAAW,EAA+B,CAAC,mCAAI,OAAC,CAAC,MAAM,EAAE,CAAC;QAC5F,SAAS,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;IAC7B,CAAC;IACD,OAAO,OAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AAC/B,CAAC,CAAC;AAEF,MAAM,YAAY,GAAmC,EAAE,CAAC;AAExD,MAAM,0BAA0B,GAAG,CAAC,MAA0B,EAAE,SAAiB,EAAE,SAAmF,EAAkB,EAAE;IACtL,MAAM,SAAS,GAAG,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAC9C,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QACX,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC;QAC7B,OAAO,GAAG,CAAC;IACf,CAAC,EACD,EAA4B,CAC/B,CAAC,CAAC;IAGH,MAAM,IAAI,GAAG;QACT,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,OAAO,SAAS,cAAc;QAC3C,KAAK,EAAE,SAAS;QAChB,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,EAAwB,EAAE,EAAE;YAC/C,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,yDAAiC,CAAC,WAAW,EAAE;gBAC5E,SAAS;gBACT,WAAW,EAAE,KAAK;aACrB,CAAC,CAAC;YACH,OAAO,QAAQ,CAAC;QACpB,CAAC;KACJ,CAAC;IACF,YAAY,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC;IAC/B,OAAO,IAAI,CAAC;AAChB,CAAC,CAAA;AAEM,MAAM,sBAAsB,GAAG,CAAC,SAAiB,EAAE,EAAE;IACxD,OAAO,YAAY,CAAC,SAAS,CAAC,CAAC;AACnC,CAAC,CAAA;AAFY,QAAA,sBAAsB,0BAElC;AAED,kBAAe,0BAA0B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const sanitizeName: (name: string) => string;
2
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/internalTools/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,KAAG,MAE3C,CAAC"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sanitizeName = void 0;
4
+ const sanitizeName = (name) => {
5
+ return name.replace(/[^a-zA-Z0-9_-]/g, '-');
6
+ };
7
+ exports.sanitizeName = sanitizeName;
8
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/internalTools/utils.ts"],"names":[],"mappings":";;;AAAO,MAAM,YAAY,GAAG,CAAC,IAAY,EAAU,EAAE;IACjD,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;AAChD,CAAC,CAAC;AAFW,QAAA,YAAY,gBAEvB"}
@@ -0,0 +1,14 @@
1
+ import { AppToolNode, ToolNode } from "../types/Flows.types";
2
+ import { stateAnnotation } from "../types/LangGraph.types";
3
+ import { Tool } from "../types/Tools.types";
4
+ import { BaseLanguageModel } from "@langchain/core/language_models/base";
5
+ import { BaseMessage, ToolMessage } from "@langchain/core/messages";
6
+ import { FlowHistory } from "../types/Agent.types";
7
+ declare const actionRunnerTool: <Memory>(matchedTool: Tool<any, Memory>, toolNode: ToolNode | AppToolNode, llm: BaseLanguageModel, addedPrompt?: string, history?: FlowHistory[]) => (state: typeof stateAnnotation.State) => Promise<{
8
+ memory: {};
9
+ messages: (BaseMessage | ToolMessage)[];
10
+ triggerInvocations: import("../types/Agent.types").TriggerInvocationHistory[];
11
+ history: FlowHistory[];
12
+ }>;
13
+ export default actionRunnerTool;
14
+ //# sourceMappingURL=actionRunnerNode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actionRunnerNode.d.ts","sourceRoot":"","sources":["../../src/nodes/actionRunnerNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAY,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAIzE,OAAO,EAAa,WAAW,EAAiB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAG9F,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,QAAA,MAAM,gBAAgB,GAAI,MAAM,EAAE,aAAa,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,UAAU,QAAQ,GAAG,WAAW,EAAE,KAAK,iBAAiB,EAAE,cAAc,MAAM,EAAE,UAAU,WAAW,EAAE,MACvJ,OAAO,OAAO,eAAe,CAAC,KAAK;;;;;EA2EpD,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const Flows_types_1 = require("../types/Flows.types");
4
+ const prebuilt_1 = require("@langchain/langgraph/prebuilt");
5
+ const langgraph_1 = require("@langchain/langgraph");
6
+ const messages_1 = require("@langchain/core/messages");
7
+ const uuid_1 = require("uuid");
8
+ const tools_1 = require("@langchain/core/tools");
9
+ const actionRunnerTool = (matchedTool, toolNode, llm, addedPrompt, history) => {
10
+ return async (state) => {
11
+ try {
12
+ console.log(`Executing tool node ${toolNode.name}`);
13
+ const executeWrapper = async (input) => {
14
+ try {
15
+ const response = await matchedTool.execute({ input, memory: state.memory, triggerInvocations: state.triggerInvocations });
16
+ console.log("response", response);
17
+ return response || {};
18
+ }
19
+ catch (error) {
20
+ console.error('Error executing tool', error);
21
+ throw error;
22
+ }
23
+ };
24
+ const tool = (0, tools_1.tool)(executeWrapper, {
25
+ name: matchedTool.name,
26
+ description: matchedTool.description,
27
+ schema: matchedTool.input,
28
+ });
29
+ let toolCallMessage;
30
+ let toolResponseMessage;
31
+ let attempts = 0;
32
+ const maxAttempts = 3;
33
+ while ((!toolCallMessage || !toolResponseMessage) && attempts < maxAttempts) {
34
+ const prompt = `
35
+ Context:
36
+ messages: ${JSON.stringify(state.messages)}
37
+ workflow memory: ${JSON.stringify(state.memory)}
38
+ Instructions:
39
+ Your ONLY task is to call the tool ${tool.name}(...) using the context above.
40
+ Do not engage in conversation or provide any other responses.
41
+ Just make the tool call immediately.
42
+ You MUST call the tool even if you are uncertain about some parameters - use your best judgment to fill in any missing values.
43
+ ${toolNode.prompt ? `Tool parameters guidance: ${toolNode.prompt}` : ''}
44
+ ${addedPrompt ? `Additional instructions: ${addedPrompt}` : ''}
45
+ ${attempts > 0
46
+ ? `Previous attempts failed. You MUST make a tool call now with your best guess at the parameters - this is your only job.`
47
+ : ''}
48
+ `;
49
+ const toolCallingAgent = (0, prebuilt_1.createReactAgent)({
50
+ checkpointer: new langgraph_1.MemorySaver(),
51
+ llm,
52
+ tools: [tool],
53
+ });
54
+ const response = await toolCallingAgent.invoke({ messages: [new messages_1.SystemMessage(prompt)] }, { configurable: { thread_id: (0, uuid_1.v4)() } });
55
+ toolCallMessage = getLastToolCallMessage(response.messages);
56
+ toolResponseMessage = getLastToolMessage(response.messages);
57
+ if (!toolCallMessage || !toolResponseMessage) {
58
+ response.messages.push(new messages_1.SystemMessage('No tool call was made. Please try again and make sure to call the tool.'));
59
+ attempts++;
60
+ }
61
+ }
62
+ if (!toolCallMessage || !toolResponseMessage) {
63
+ throw new Error('Failed to get tool call or response after multiple attempts');
64
+ }
65
+ let toolMemory = {};
66
+ if (toolNode.type === Flows_types_1.NodeType.APP_TOOL) {
67
+ toolMemory = extractToolMemoryResponse(toolResponseMessage);
68
+ }
69
+ return { memory: toolMemory, messages: [toolCallMessage, toolResponseMessage], triggerInvocations: state.triggerInvocations, history: history || [] };
70
+ }
71
+ catch (error) {
72
+ console.error('Error executing tool node', error);
73
+ throw error;
74
+ }
75
+ };
76
+ };
77
+ exports.default = actionRunnerTool;
78
+ const getLastToolCallMessage = (messages) => {
79
+ const toolCallMessages = messages.filter((message) => { var _a; return ((_a = message.tool_calls) === null || _a === void 0 ? void 0 : _a.length) || 0 > 0; });
80
+ const lastToolCallMessage = toolCallMessages[toolCallMessages.length - 1];
81
+ return lastToolCallMessage;
82
+ };
83
+ const getLastToolMessage = (messages) => {
84
+ const toolMessages = messages.filter((message) => message.getType() === 'tool');
85
+ const lastToolMessage = toolMessages[toolMessages.length - 1];
86
+ return lastToolMessage;
87
+ };
88
+ const extractToolMemoryResponse = (toolMessage) => {
89
+ try {
90
+ const parsed = JSON.parse(toolMessage.content);
91
+ if (typeof parsed === 'object' && parsed !== null && 'memory' in parsed) {
92
+ return parsed.memory;
93
+ }
94
+ }
95
+ catch (error) {
96
+ console.error('Error parsing tool memory response', error);
97
+ }
98
+ return {};
99
+ };
100
+ //# sourceMappingURL=actionRunnerNode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actionRunnerNode.js","sourceRoot":"","sources":["../../src/nodes/actionRunnerNode.ts"],"names":[],"mappings":";;AAAA,sDAAuE;AAIvE,4DAAiE;AACjE,oDAAmD;AAEnD,uDAA8F;AAC9F,+BAAoC;AACpC,iDAA8D;AAG9D,MAAM,gBAAgB,GAAG,CAAS,WAA8B,EAAE,QAAgC,EAAE,GAAsB,EAAE,WAAoB,EAAE,OAAuB,EAAE,EAAE;IACzK,OAAO,KAAK,EAAE,KAAmC,EAAE,EAAE;QACjD,IAAI,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,uBAAuB,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;YAEpD,MAAM,cAAc,GAAG,KAAK,EAAE,KAAwC,EAAE,EAAE;gBACtE,IAAI,CAAC;oBACD,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,CAAC,kBAAkB,EAAE,CAAC,CAAC;oBAC1H,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAA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EAAe,EAAE;IACpE,MAAM,gBAAgB,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,WAAC,OAAA,CAAA,MAAC,OAAqB,CAAC,UAAU,0CAAE,MAAM,KAAI,CAAC,GAAG,CAAC,CAAA,EAAA,CAAC,CAAC;IAC1G,MAAM,mBAAmB,GAAG,gBAAgB,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC1E,OAAO,mBAAmB,CAAC;AAC/B,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,QAAuB,EAAe,EAAE;IAChE,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,MAAM,CAAC,CAAC;IAChF,MAAM,eAAe,GAAG,YAAY,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC9D,OAAO,eAA8B,CAAC;AAC1C,CAAC,CAAC;AAEF,MAAM,yBAAyB,GAAG,CAAS,WAAwB,EAAmB,EAAE;IACpF,IAAI,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAiB,CAAC,CAAC;QACzD,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,QAAQ,IAAI,MAAM,EAAE,CAAC;YACtE,OAAO,MAAM,CAAC,MAAM,CAAC;QACzB,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,EAAE,CAAC;AACd,CAAC,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { AppToolNode, ToolNode } from "../types/Flows.types";
2
+ import { stateAnnotation } from "../types/LangGraph.types";
3
+ import { Tool } from "../types/Tools.types";
4
+ import { BaseLanguageModel } from "@langchain/core/language_models/base";
5
+ import { BaseMessage, ToolMessage } from "@langchain/core/messages";
6
+ import { FlowHistory } from "../types/Agent.types";
7
+ declare const actionRunnerTool: <Memory>(matchedTool: Tool<any, Memory>, toolNode: ToolNode | AppToolNode, llm: BaseLanguageModel, addedPrompt?: string, history?: FlowHistory[]) => (state: typeof stateAnnotation.State) => Promise<{
8
+ memory: {};
9
+ messages: (BaseMessage | ToolMessage)[];
10
+ triggerInvocations: import("../types/Agent.types").TriggerInvocationHistory[];
11
+ history: FlowHistory[];
12
+ }>;
13
+ export default actionRunnerTool;
14
+ //# sourceMappingURL=actionRunnerTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actionRunnerTool.d.ts","sourceRoot":"","sources":["../../src/nodes/actionRunnerTool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAY,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAIzE,OAAO,EAAa,WAAW,EAAiB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAG9F,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,QAAA,MAAM,gBAAgB,GAAI,MAAM,EAAE,aAAa,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,UAAU,QAAQ,GAAG,WAAW,EAAE,KAAK,iBAAiB,EAAE,cAAc,MAAM,EAAE,UAAU,WAAW,EAAE,MACvJ,OAAO,OAAO,eAAe,CAAC,KAAK;;;;;EA6EpD,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const Flows_types_1 = require("../types/Flows.types");
4
+ const prebuilt_1 = require("@langchain/langgraph/prebuilt");
5
+ const langgraph_1 = require("@langchain/langgraph");
6
+ const messages_1 = require("@langchain/core/messages");
7
+ const uuid_1 = require("uuid");
8
+ const tools_1 = require("@langchain/core/tools");
9
+ const actionRunnerTool = (matchedTool, toolNode, llm, addedPrompt, history) => {
10
+ return async (state) => {
11
+ try {
12
+ console.log(`Executing tool node ${toolNode.name}`);
13
+ const executeWrapper = async (input) => {
14
+ try {
15
+ const response = await matchedTool.execute({ input, memory: state.memory, triggerInvocations: state.triggerInvocations });
16
+ return response || {};
17
+ }
18
+ catch (error) {
19
+ console.error('Error executing tool', error);
20
+ throw error;
21
+ }
22
+ };
23
+ const tool = (0, tools_1.tool)(executeWrapper, {
24
+ name: matchedTool.name,
25
+ description: matchedTool.description,
26
+ schema: matchedTool.input,
27
+ });
28
+ let toolCallMessage;
29
+ let toolResponseMessage;
30
+ let attempts = 0;
31
+ const maxAttempts = 1;
32
+ // TODO : figure out why we added this while loop
33
+ if ((!toolCallMessage || !toolResponseMessage) && attempts < maxAttempts) {
34
+ console.log("asdasdasd");
35
+ const prompt = `
36
+ Context:
37
+ messages: ${JSON.stringify(state.messages)}
38
+ workflow memory: ${JSON.stringify(state.memory)}
39
+ Instructions:
40
+ Your ONLY task is to call the tool ${tool.name}(...) using the context above.
41
+ Do not engage in conversation or provide any other responses.
42
+ Just make the tool call immediately.
43
+ You MUST call the tool even if you are uncertain about some parameters - use your best judgment to fill in any missing values.
44
+ ${toolNode.prompt ? `Tool parameters guidance: ${toolNode.prompt}` : ''}
45
+ ${addedPrompt ? `Additional instructions: ${addedPrompt}` : ''}
46
+ ${attempts > 0
47
+ ? `Previous attempts failed. You MUST make a tool call now with your best guess at the parameters - this is your only job.`
48
+ : ''}
49
+ `;
50
+ const toolCallingAgent = (0, prebuilt_1.createReactAgent)({
51
+ checkpointer: new langgraph_1.MemorySaver(),
52
+ llm,
53
+ tools: [tool],
54
+ });
55
+ const response = await toolCallingAgent.invoke({ messages: [new messages_1.SystemMessage(prompt)] }, { configurable: { thread_id: (0, uuid_1.v4)() } });
56
+ toolCallMessage = getLastToolCallMessage(response.messages);
57
+ toolResponseMessage = getLastToolMessage(response.messages);
58
+ if (!toolCallMessage || !toolResponseMessage) {
59
+ response.messages.push(new messages_1.SystemMessage('No tool call was made. Please try again and make sure to call the tool.'));
60
+ attempts++;
61
+ }
62
+ }
63
+ if (!toolCallMessage || !toolResponseMessage) {
64
+ throw new Error('Failed to get tool call or response after multiple attempts');
65
+ }
66
+ let toolMemory = {};
67
+ if (toolNode.type === Flows_types_1.NodeType.APP_TOOL) {
68
+ toolMemory = extractToolMemoryResponse(toolResponseMessage);
69
+ }
70
+ return { memory: toolMemory, messages: [toolCallMessage, toolResponseMessage], triggerInvocations: state.triggerInvocations, history: history || [] };
71
+ }
72
+ catch (error) {
73
+ console.error('Error executing tool node', error);
74
+ throw error;
75
+ }
76
+ };
77
+ };
78
+ exports.default = actionRunnerTool;
79
+ const getLastToolCallMessage = (messages) => {
80
+ const toolCallMessages = messages.filter((message) => { var _a; return ((_a = message.tool_calls) === null || _a === void 0 ? void 0 : _a.length) || 0 > 0; });
81
+ const lastToolCallMessage = toolCallMessages[toolCallMessages.length - 1];
82
+ return lastToolCallMessage;
83
+ };
84
+ const getLastToolMessage = (messages) => {
85
+ const toolMessages = messages.filter((message) => message.getType() === 'tool');
86
+ const lastToolMessage = toolMessages[toolMessages.length - 1];
87
+ return lastToolMessage;
88
+ };
89
+ const extractToolMemoryResponse = (toolMessage) => {
90
+ try {
91
+ const parsed = JSON.parse(toolMessage.content);
92
+ if (typeof parsed === 'object' && parsed !== null && 'memory' in parsed) {
93
+ return parsed.memory;
94
+ }
95
+ }
96
+ catch (error) {
97
+ console.error('Error parsing tool memory response', error);
98
+ }
99
+ return {};
100
+ };
101
+ //# sourceMappingURL=actionRunnerTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actionRunnerTool.js","sourceRoot":"","sources":["../../src/nodes/actionRunnerTool.ts"],"names":[],"mappings":";;AAAA,sDAAuE;A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C,CAAC,CAAC;AAEF,MAAM,yBAAyB,GAAG,CAAS,WAAwB,EAAmB,EAAE;IACpF,IAAI,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAiB,CAAC,CAAC;QACzD,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,QAAQ,IAAI,MAAM,EAAE,CAAC;YACtE,OAAO,MAAM,CAAC,MAAM,CAAC;QACzB,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,EAAE,CAAC;AACd,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { AppToolNode } from '../types/Flows.types';
2
+ import { PreCompiledGraph } from "../types/LangGraph.types";
3
+ import { BaseLanguageModel } from "@langchain/core/language_models/base";
4
+ export declare const addAppToolNode: <Memory>({ graph, node, llm, }: {
5
+ graph: PreCompiledGraph;
6
+ node: AppToolNode;
7
+ llm: BaseLanguageModel;
8
+ }) => void;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addAppToolNode = void 0;
4
+ const appToolRunner_1 = require("../tools/appToolRunner");
5
+ const toolNodeRunner_1 = require("./toolNodeRunner");
6
+ const addAppToolNode = ({ graph, node, llm, }) => {
7
+ const toolNode = node;
8
+ const callback = (0, toolNodeRunner_1.getToolNodeRunner)(toolNode, appToolRunner_1.appToolRunnerTool, llm);
9
+ graph.addNode(node.name, callback);
10
+ };
11
+ exports.addAppToolNode = addAppToolNode;
12
+ //# sourceMappingURL=addAppTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addAppTool.js","sourceRoot":"","sources":["../../src/nodes/addAppTool.ts"],"names":[],"mappings":";;;AAGA,0DAA2D;AAC3D,qDAAqD;AAG9C,MAAM,cAAc,GAAG,CAAS,EACnC,KAAK,EACL,IAAI,EACJ,GAAG,GAKN,EAAE,EAAE;IACD,MAAM,QAAQ,GAAG,IAAmB,CAAC;IACrC,MAAM,QAAQ,GAAiB,IAAA,kCAAiB,EAAS,QAAQ,EAAE,iCAAiB,EAAE,GAAG,CAAC,CAAC;IAC3F,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACvC,CAAC,CAAC;AAZW,QAAA,cAAc,kBAYzB"}
@@ -0,0 +1,9 @@
1
+ import { AppToolNode } from '../types/Flows.types';
2
+ import { PreCompiledGraph } from '../types/LangGraph.types';
3
+ import { LLMProviders } from '../types/LLM.types';
4
+ export declare const addAppToolNode: ({ graph, node, llm, }: {
5
+ graph: PreCompiledGraph;
6
+ node: AppToolNode;
7
+ llm: (typeof LLMProviders)[keyof typeof LLMProviders];
8
+ }) => Promise<void>;
9
+ //# sourceMappingURL=addAppToolNode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addAppToolNode.d.ts","sourceRoot":"","sources":["../../src/nodes/addAppToolNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,gBAAgB,EAAmB,MAAM,0BAA0B,CAAC;AAK7E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,eAAO,MAAM,cAAc,GAAU,uBAIlC;IACC,KAAK,EAAE,gBAAgB,CAAC;IACxB,IAAI,EAAE,WAAW,CAAC;IAClB,GAAG,EAAE,CAAA,OAAO,YAAY,EAAC,MAAM,OAAO,YAAY,CAAC,CAAC;CACvD,kBAsDA,CAAC"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addAppToolNode = void 0;
4
+ const tools_1 = require("@langchain/core/tools");
5
+ const messages_1 = require("@langchain/core/messages");
6
+ const uuid_1 = require("uuid");
7
+ const appActionRunnerTool_1 = require("../internalTools/appActionRunnerTool");
8
+ const addAppToolNode = async ({ graph, node, llm, }) => {
9
+ const appRunnerTool = (0, appActionRunnerTool_1.getAppActionRunnerTool)(node.name);
10
+ const callback = async (state) => {
11
+ console.log(`Executing tool node ${appRunnerTool.name}`);
12
+ const executeWrapper = async (input) => {
13
+ try {
14
+ const response = await appRunnerTool.execute({ input, memory: state.memory, triggerInvocations: state.triggerInvocations });
15
+ return response || {};
16
+ }
17
+ catch (error) {
18
+ console.error('Error executing tool', error);
19
+ throw error;
20
+ }
21
+ };
22
+ const prompt = `
23
+ Context:
24
+ workflow memory: ${JSON.stringify(state.memory)}
25
+
26
+ Task:
27
+ Extract the necessary parameters for the tool "${appRunnerTool.name}" based on the context above and the previous messages.
28
+
29
+ ${node.prompt ? `Additional guidance for parameter extraction: ${node.prompt}` : ''}
30
+
31
+ Important:
32
+ - Extract ONLY the parameters that match the schema
33
+ - Use your best judgment to fill in any missing values
34
+ - Do not include any parameters not defined in the schema
35
+ - Return a valid JSON object matching the schema exactly
36
+ `;
37
+ const structuredLlm = llm.withStructuredOutput(appRunnerTool.input);
38
+ const validMessages = state.messages.filter((msg, index) => {
39
+ if (msg instanceof messages_1.ToolMessage) {
40
+ const prevMsg = state.messages[index - 1];
41
+ return prevMsg && 'tool_calls' in prevMsg;
42
+ }
43
+ return true;
44
+ });
45
+ const structuredResponse = await structuredLlm.invoke([...validMessages, new messages_1.SystemMessage(prompt)]);
46
+ const tool = (0, tools_1.tool)(executeWrapper, {
47
+ name: appRunnerTool.name,
48
+ description: appRunnerTool.description,
49
+ schema: appRunnerTool.input,
50
+ });
51
+ const response = await tool.invoke({
52
+ args: structuredResponse,
53
+ type: 'tool_call',
54
+ id: (0, uuid_1.v4)(),
55
+ name: appRunnerTool.name,
56
+ });
57
+ return { messages: [response] };
58
+ };
59
+ graph.addNode(node.name, callback);
60
+ };
61
+ exports.addAppToolNode = addAppToolNode;
62
+ //# sourceMappingURL=addAppToolNode.js.map
@@ -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AAO,MAAM,aAAa,GAAU,mCAAmC,mBAAmB,kBAuCzF,CAAC"}
@@ -1,14 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addPromptNode = void 0;
4
- const zod_1 = require("zod");
5
- const prebuilt_1 = require("@langchain/langgraph/prebuilt");
6
4
  const messages_1 = require("@langchain/core/messages");
7
5
  const tools_1 = require("@langchain/core/tools");
8
6
  const AgentEvents_1 = require("../events/AgentEvents");
9
7
  const createLlmInstance_1 = require("../llm/createLlmInstance");
10
- const langgraph_1 = require("@langchain/langgraph");
11
- const uuid_1 = require("uuid");
12
8
  const addPromptNode = async ({ graph, node, llm, tools, emit }) => {
13
9
  const callback = async (state, { configurable }) => {
14
10
  console.log(`Executing prompt node ${node.name}`);
@@ -20,34 +16,24 @@ const addPromptNode = async ({ graph, node, llm, tools, emit }) => {
20
16
  description: tool.description,
21
17
  schema: tool.input,
22
18
  }));
23
- const agent = (0, prebuilt_1.createReactAgent)({
24
- checkpointer: new langgraph_1.MemorySaver(),
25
- llm: llmToUse,
26
- tools: globalTools,
27
- responseFormat: zod_1.z.object({
28
- waitForUserResponse: zod_1.z.boolean(),
29
- done: zod_1.z.boolean(),
30
- }),
31
- });
32
19
  const message = `
33
- - This is a node in a workflow.
34
- - User instructions: ${node.prompt}
35
- - Workflow memory: ${JSON.stringify(state.memory)}
36
- - Conversation history: ${state.messages.map((message) => `${message.getType()}: ${message.content}`).join('\n')}
20
+ Additional context:
21
+ ${node.prompt ? `- User instructions: ${node.prompt}` : ''}
22
+ ${state.memory ? `- Workflow memory: ${JSON.stringify(state.memory)}` : ''}
37
23
  `;
38
- const result = await agent.invoke({
39
- messages: [new messages_1.SystemMessage(message)],
40
- }, { configurable: { thread_id: (0, uuid_1.v4)() } });
41
- const lastMessage = result.messages[result.messages.length - 1];
42
- if (lastMessage.getType() === 'ai') {
24
+ const result = await llmToUse.bindTools(globalTools).invoke([
25
+ ...state.messages,
26
+ new messages_1.SystemMessage(message)
27
+ ]);
28
+ if (result.getType() === 'ai') {
43
29
  await emit(AgentEvents_1.AgentEvents.AI_MESSAGE, {
44
- message: lastMessage.content,
30
+ message: result.content,
45
31
  memory: state.memory,
46
32
  sessionId: configurable.thread_id,
47
33
  });
48
34
  }
49
35
  return {
50
- messages: [lastMessage],
36
+ messages: [result],
51
37
  };
52
38
  };
53
39
  graph.addNode(node.name, callback);
@@ -1 +1 @@
1
- {"version":3,"file":"addPromptNode.js","sourceRoot":"","sources":["../../src/nodes/addPromptNode.ts"],"names":[],"mappings":";;;AAGA,6BAAwB;AAExB,4DAAiE;AACjE,uDAAyD;AAEzD,iDAA8D;AAC9D,uDAA+E;AAE/E,gEAA6D;AAC7D,oDAAmD;AACnD,+BAAoC;AAU7B,MAAM,aAAa,GAAG,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAuB,EAAE,EAAE;IAC5F,MAAM,QAAQ,GAAiB,KAAK,EAAE,KAAmC,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE;QAC7F,OAAO,CAAC,GAAG,CAAC,yBAAyB,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAClD,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAA,qCAAiB,EAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QAE1E,MAAM,WAAW,GAAG,KAAK;aACtB,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC;aAC/B,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACZ,IAAA,YAAa,EAAC,CAAC,KAAiC,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE;YAClG,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IA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wBAAwB,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE;MACxD,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,sBAAsB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;KACzE,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC;YAC1D,GAAG,KAAK,CAAC,QAAQ;YACjB,IAAI,wBAAa,CAAC,OAAO,CAAC;SAC3B,CAAC,CAAC;QAEH,IAAI,MAAM,CAAC,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC,yBAAW,CAAC,UAAU,EAAE;gBACjC,OAAO,EAAE,MAAM,CAAC,OAAiB;gBACjC,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,SAAS,EAAE,YAAY,CAAC,SAAS;aAClC,CAAC,CAAC;QACL,CAAC;QAED,OAAO;YACL,QAAQ,EAAE,CAAC,MAAM,CAAC;SACnB,CAAC;IACJ,CAAC,CAAC;IACF,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACrC,CAAC,CAAC;AAvCW,QAAA,aAAa,iBAuCxB"}
@@ -1,11 +1,11 @@
1
- import { BaseLanguageModel } from '@langchain/core/language_models/base';
2
1
  import { ToolNode } from '../types/Flows.types';
3
2
  import { Tool } from '../types/Tools.types';
4
3
  import { PreCompiledGraph } from '../types/LangGraph.types';
4
+ import { LLMProviders } from '../types/LLM.types';
5
5
  export declare const addToolNode: <Memory>({ graph, node, tools, llm, }: {
6
6
  graph: PreCompiledGraph;
7
7
  node: ToolNode;
8
8
  tools: Tool<any, any>[];
9
- llm: BaseLanguageModel;
9
+ llm: (typeof LLMProviders)[keyof typeof LLMProviders];
10
10
  }) => Promise<void>;
11
11
  //# sourceMappingURL=addToolNode.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"addToolNode.d.ts","sourceRoot":"","sources":["../../src/nodes/addToolNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C,OAAO,EAAE,gBAAgB,EAAmB,MAAM,0BAA0B,CAAC;AAQ7E,eAAO,MAAM,WAAW,GAAU,MAAM,EAAE,8BAKvC;IACD,KAAK,EAAE,gBAAgB,CAAC;IACxB,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;IACxB,GAAG,EAAE,iBAAiB,CAAC;CACxB,kBA8EA,CAAC"}
1
+ {"version":3,"file":"addToolNode.d.ts","sourceRoot":"","sources":["../../src/nodes/addToolNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C,OAAO,EAAE,gBAAgB,EAAmB,MAAM,0BAA0B,CAAC;AAI7E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,eAAO,MAAM,WAAW,GAAU,MAAM,EAAE,8BAKvC;IACD,KAAK,EAAE,gBAAgB,CAAC;IACxB,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;IACxB,GAAG,EAAE,CAAA,OAAO,YAAY,EAAC,MAAM,OAAO,YAAY,CAAC,CAAC;CACrD,kBAmCA,CAAC"}