@minded-ai/mindedjs 2.0.14 → 2.0.15-beta-1
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.
- package/dist/browserTask/README.md +419 -0
- package/dist/browserTask/browserAgent.py +632 -0
- package/dist/browserTask/captcha_isolated.png +0 -0
- package/dist/browserTask/executeBrowserTask.ts +79 -0
- package/dist/browserTask/requirements.txt +8 -0
- package/dist/browserTask/setup.sh +144 -0
- package/dist/cli/index.js +0 -0
- package/dist/internalTools/retell.d.ts +12 -0
- package/dist/internalTools/retell.d.ts.map +1 -0
- package/dist/internalTools/retell.js +54 -0
- package/dist/internalTools/retell.js.map +1 -0
- package/dist/internalTools/sendPlaceholderMessage.d.ts +14 -0
- package/dist/internalTools/sendPlaceholderMessage.d.ts.map +1 -0
- package/dist/internalTools/sendPlaceholderMessage.js +61 -0
- package/dist/internalTools/sendPlaceholderMessage.js.map +1 -0
- package/dist/nodes/addRpaNode.d.ts.map +1 -1
- package/dist/nodes/addRpaNode.js +12 -1
- package/dist/nodes/addRpaNode.js.map +1 -1
- package/dist/toolsLibrary/classifier.d.ts +12 -20
- package/dist/toolsLibrary/classifier.d.ts.map +1 -1
- package/dist/toolsLibrary/classifier.js +106 -74
- package/dist/toolsLibrary/classifier.js.map +1 -1
- package/dist/utils/extractStateMemoryResponse.d.ts +5 -0
- package/dist/utils/extractStateMemoryResponse.d.ts.map +1 -0
- package/dist/utils/extractStateMemoryResponse.js +91 -0
- package/dist/utils/extractStateMemoryResponse.js.map +1 -0
- package/package.json +1 -1
- package/src/nodes/addRpaNode.ts +13 -2
- package/src/toolsLibrary/classifier.ts +136 -86
|
@@ -6,15 +6,25 @@ exports.createClassifier = createClassifier;
|
|
|
6
6
|
exports.multiClassify = multiClassify;
|
|
7
7
|
const zod_1 = require("zod");
|
|
8
8
|
const logger_1 = require("../utils/logger");
|
|
9
|
-
const output_parsers_1 = require("@langchain/core/output_parsers");
|
|
10
9
|
const messages_1 = require("@langchain/core/messages");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
function supportsStructuredOutput(llm) {
|
|
11
|
+
return 'withStructuredOutput' in llm && typeof llm.withStructuredOutput === 'function';
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create a dynamic Zod schema for classification result based on valid classes
|
|
15
|
+
*/
|
|
16
|
+
function createClassificationSchema(config) {
|
|
17
|
+
const validClassNames = config.classes.map((c) => c.name);
|
|
18
|
+
// Create a union type for valid class names
|
|
19
|
+
const classEnum = zod_1.z.enum(validClassNames);
|
|
20
|
+
// Build the schema - always include all fields
|
|
21
|
+
const schemaShape = {
|
|
22
|
+
class: classEnum.describe('The selected classification category'),
|
|
23
|
+
reason: zod_1.z.string().describe('Explanation for the classification'),
|
|
24
|
+
confidence: zod_1.z.number().min(0).max(1).describe('Confidence score between 0 and 1'),
|
|
25
|
+
};
|
|
26
|
+
return zod_1.z.object(schemaShape);
|
|
27
|
+
}
|
|
18
28
|
/**
|
|
19
29
|
* Generic classifier utility that can be used standalone
|
|
20
30
|
* @param content The content to classify
|
|
@@ -23,49 +33,73 @@ const DEFAULT_CONFIG = {
|
|
|
23
33
|
* @returns The classification result
|
|
24
34
|
*/
|
|
25
35
|
async function classify(content, config, llm) {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
36
|
+
const MAX_RETRIES = 3;
|
|
37
|
+
let lastError = null;
|
|
38
|
+
// Check if LLM supports structured output upfront
|
|
39
|
+
if (!supportsStructuredOutput(llm)) {
|
|
40
|
+
throw new Error('LLM does not support structured output, which is required for classification');
|
|
41
|
+
}
|
|
42
|
+
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
43
|
+
try {
|
|
44
|
+
// Build the classification prompt
|
|
45
|
+
const classesDescription = config.classes.map((c) => `${c.name}: ${c.description}`).join('\n');
|
|
46
|
+
const basePrompt = config.systemPrompt || 'You are a classifier. Your task is to classify the given content into one of the following categories:';
|
|
47
|
+
let prompt = `${basePrompt}\n\n${classesDescription}\n\n`;
|
|
48
|
+
// Add retry feedback if this is not the first attempt
|
|
49
|
+
if (attempt > 1) {
|
|
50
|
+
const validClassNames = config.classes.map((c) => c.name);
|
|
51
|
+
prompt += `\n⚠️ IMPORTANT: Your previous classification attempt failed. `;
|
|
52
|
+
prompt += `You MUST select ONLY from these valid classes:\n${validClassNames.join(', ')}\n\n`;
|
|
53
|
+
}
|
|
54
|
+
// Create dynamic schema based on valid classes
|
|
55
|
+
const classificationSchema = createClassificationSchema(config);
|
|
56
|
+
// Add content to classify to the prompt
|
|
57
|
+
prompt += `\n\nContent to classify:\n${content}`;
|
|
58
|
+
// Use structured output for guaranteed compliance
|
|
59
|
+
const structuredLLM = llm.withStructuredOutput(classificationSchema);
|
|
60
|
+
const messages = [new messages_1.SystemMessage(prompt)];
|
|
61
|
+
const result = (await structuredLLM.invoke(messages));
|
|
62
|
+
// The result is already validated by withStructuredOutput
|
|
63
|
+
logger_1.logger.debug({
|
|
64
|
+
message: 'Classification successful with structured output',
|
|
65
|
+
attempt,
|
|
66
|
+
class: result.class,
|
|
67
|
+
});
|
|
47
68
|
return result;
|
|
48
69
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
70
|
+
catch (err) {
|
|
71
|
+
lastError = err;
|
|
72
|
+
logger_1.logger.warn({
|
|
73
|
+
message: `Classification attempt ${attempt} failed`,
|
|
74
|
+
attempt,
|
|
75
|
+
maxRetries: MAX_RETRIES,
|
|
76
|
+
error: lastError.message,
|
|
77
|
+
});
|
|
78
|
+
// If this is not the last attempt, continue to retry
|
|
79
|
+
if (attempt < MAX_RETRIES) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
53
82
|
}
|
|
54
83
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
84
|
+
// All retries exhausted - fallback to default
|
|
85
|
+
logger_1.logger.warn({
|
|
86
|
+
message: 'Classification failed after max retries, using default class',
|
|
87
|
+
maxRetries: MAX_RETRIES,
|
|
88
|
+
lastError: lastError === null || lastError === void 0 ? void 0 : lastError.message,
|
|
89
|
+
defaultClass: config.defaultClass,
|
|
90
|
+
defaultReason: config.defaultReason,
|
|
91
|
+
});
|
|
92
|
+
// Return default classification
|
|
93
|
+
return {
|
|
94
|
+
class: config.defaultClass,
|
|
95
|
+
reason: config.defaultReason,
|
|
96
|
+
confidence: 0,
|
|
97
|
+
};
|
|
64
98
|
}
|
|
65
99
|
/**
|
|
66
100
|
* Create a classifier from a simple class list
|
|
67
101
|
* @param classes Array of class names or [name, description] tuples
|
|
68
|
-
* @param options
|
|
102
|
+
* @param options Configuration options (includeReason, defaultClass, defaultReason are required)
|
|
69
103
|
* @returns A configured classify function
|
|
70
104
|
*/
|
|
71
105
|
function createClassifier(classes, options) {
|
|
@@ -96,19 +130,17 @@ exports.schema = zod_1.z.object({
|
|
|
96
130
|
.optional()
|
|
97
131
|
.describe('Classes to classify into. Can be strings, [name, description] tuples, or objects with name and description'),
|
|
98
132
|
systemPrompt: zod_1.z.string().optional().describe('Custom system prompt for classification'),
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
defaultClass: zod_1.z.string().optional().describe('Default class to use if classification fails'),
|
|
102
|
-
defaultReason: zod_1.z.string().optional().describe('Default reason to use if classification fails'),
|
|
133
|
+
defaultClass: zod_1.z.string().describe('Default class to use if classification fails'),
|
|
134
|
+
defaultReason: zod_1.z.string().describe('Default reason to use if classification fails'),
|
|
103
135
|
});
|
|
104
136
|
const classifierTool = {
|
|
105
137
|
name: 'minded-classifier',
|
|
106
|
-
description: 'Classify content into predefined categories using AI. Supports custom classes
|
|
138
|
+
description: 'Classify content into predefined categories using AI. Supports custom classes and system prompts. Uses structured output for guaranteed schema compliance. Requires default fallback values.',
|
|
107
139
|
input: exports.schema,
|
|
108
140
|
isGlobal: false,
|
|
109
141
|
execute: async ({ input, state, agent }) => {
|
|
110
142
|
var _a, _b;
|
|
111
|
-
const { content, classes, systemPrompt,
|
|
143
|
+
const { content, classes, systemPrompt, defaultClass, defaultReason } = input;
|
|
112
144
|
logger_1.logger.info({
|
|
113
145
|
message: 'Classifying content',
|
|
114
146
|
sessionId: state.sessionId,
|
|
@@ -140,8 +172,6 @@ const classifierTool = {
|
|
|
140
172
|
const config = {
|
|
141
173
|
classes: classDefinitions,
|
|
142
174
|
systemPrompt,
|
|
143
|
-
includeReason,
|
|
144
|
-
outputFormat,
|
|
145
175
|
defaultClass,
|
|
146
176
|
defaultReason,
|
|
147
177
|
};
|
|
@@ -175,39 +205,41 @@ const classifierTool = {
|
|
|
175
205
|
exports.default = classifierTool;
|
|
176
206
|
// Export utility for multi-label classification
|
|
177
207
|
async function multiClassify(content, config, llm) {
|
|
178
|
-
const
|
|
179
|
-
|
|
208
|
+
const maxClasses = config.maxClasses || 3;
|
|
209
|
+
// Check if LLM supports structured output
|
|
210
|
+
if (!supportsStructuredOutput(llm)) {
|
|
211
|
+
throw new Error('LLM does not support structured output, which is required for multi-classification');
|
|
212
|
+
}
|
|
180
213
|
try {
|
|
181
|
-
const classesDescription =
|
|
182
|
-
const
|
|
214
|
+
const classesDescription = config.classes.map((c) => `${c.name}: ${c.description}`).join('\n');
|
|
215
|
+
const validClassNames = config.classes.map((c) => c.name);
|
|
216
|
+
const basePrompt = config.systemPrompt || 'You are a multi-label classifier. Select all applicable categories for the given content:';
|
|
183
217
|
const prompt = `${basePrompt}\n\n${classesDescription}\n\n
|
|
184
|
-
|
|
185
|
-
[
|
|
186
|
-
{
|
|
187
|
-
"class": "<class name>",
|
|
188
|
-
${mergedConfig.includeReason ? '"reason": "<explanation>",' : ''}
|
|
189
|
-
"confidence": <confidence score between 0 and 1>
|
|
190
|
-
},
|
|
191
|
-
...
|
|
192
|
-
]
|
|
193
|
-
Return JSON and nothing more.
|
|
218
|
+
Select up to ${maxClasses} classifications, ordered by relevance.
|
|
194
219
|
|
|
195
220
|
Content to classify:
|
|
196
221
|
${content}`;
|
|
197
|
-
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
222
|
+
// Create schema for array of classifications
|
|
223
|
+
const classEnum = zod_1.z.enum(validClassNames);
|
|
224
|
+
const multiClassSchema = zod_1.z
|
|
225
|
+
.array(zod_1.z.object({
|
|
226
|
+
class: classEnum.describe('The selected classification category'),
|
|
227
|
+
reason: zod_1.z.string().describe('Explanation for the classification'),
|
|
228
|
+
confidence: zod_1.z.number().min(0).max(1).describe('Confidence score between 0 and 1'),
|
|
229
|
+
}))
|
|
230
|
+
.min(1)
|
|
231
|
+
.max(maxClasses);
|
|
232
|
+
const structuredLLM = llm.withStructuredOutput(multiClassSchema);
|
|
233
|
+
const messages = [new messages_1.SystemMessage(prompt)];
|
|
234
|
+
const result = (await structuredLLM.invoke(messages));
|
|
235
|
+
return result;
|
|
204
236
|
}
|
|
205
237
|
catch (err) {
|
|
206
238
|
logger_1.logger.error({ message: 'Multi-classification failed', err });
|
|
207
239
|
return [
|
|
208
240
|
{
|
|
209
|
-
class:
|
|
210
|
-
reason:
|
|
241
|
+
class: config.defaultClass,
|
|
242
|
+
reason: config.defaultReason,
|
|
211
243
|
confidence: 0,
|
|
212
244
|
},
|
|
213
245
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"classifier.js","sourceRoot":"","sources":["../../src/toolsLibrary/classifier.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3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C,KAAK,CAAC,EAAE,OAAO,EAAE,6BAA6B,EAAE,GAAG,EAAE,CAAC,CAAC;QAE9D,OAAO;YACL;gBACE,KAAK,EAAE,MAAM,CAAC,YAAY;gBAC1B,MAAM,EAAE,MAAM,CAAC,aAAa;gBAC5B,UAAU,EAAE,CAAC;aACd;SACF,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ToolMessage } from '@langchain/core/messages';
|
|
2
|
+
import { State } from '../types/LangGraph.types';
|
|
3
|
+
declare const extractToolStateResponse: (toolMessage: ToolMessage) => Partial<State>;
|
|
4
|
+
export default extractToolStateResponse;
|
|
5
|
+
//# sourceMappingURL=extractStateMemoryResponse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractStateMemoryResponse.d.ts","sourceRoot":"","sources":["../../src/utils/extractStateMemoryResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,WAAW,EAA0C,MAAM,0BAA0B,CAAC;AAE5G,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAEjD,QAAA,MAAM,wBAAwB,gBAAiB,WAAW,KAAG,OAAO,CAAC,KAAK,CAazE,CAAC;AA4EF,eAAe,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const messages_1 = require("@langchain/core/messages");
|
|
4
|
+
const logger_1 = require("./logger");
|
|
5
|
+
const extractToolStateResponse = (toolMessage) => {
|
|
6
|
+
try {
|
|
7
|
+
const parsed = JSON.parse(toolMessage.content);
|
|
8
|
+
if (typeof parsed === 'object' && parsed !== null && 'state' in parsed) {
|
|
9
|
+
if (parsed.state.messages) {
|
|
10
|
+
parsed.state.messages = constructMessagesFromToolMessage(parsed.state.messages);
|
|
11
|
+
}
|
|
12
|
+
return parsed.state;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
logger_1.logger.error({ message: 'Error parsing tool state response', err });
|
|
17
|
+
}
|
|
18
|
+
return {};
|
|
19
|
+
};
|
|
20
|
+
const constructMessagesFromToolMessage = (messages) => {
|
|
21
|
+
if (!Array.isArray(messages)) {
|
|
22
|
+
logger_1.logger.error({ msg: 'Expected messages to be an array', messages });
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
return messages
|
|
26
|
+
.map((messageObj) => {
|
|
27
|
+
try {
|
|
28
|
+
// Handle case where message is already a BaseMessage instance
|
|
29
|
+
if (messageObj instanceof messages_1.BaseMessage) {
|
|
30
|
+
return messageObj;
|
|
31
|
+
}
|
|
32
|
+
// Handle case where message is a plain object that needs reconstruction
|
|
33
|
+
const messageType = messageObj.id[2];
|
|
34
|
+
const content = messageObj.kwargs.content || '';
|
|
35
|
+
const id = messageObj.kwargs.id;
|
|
36
|
+
const additionalKwargs = messageObj.additional_kwargs || {};
|
|
37
|
+
switch (messageType) {
|
|
38
|
+
case 'AIMessage':
|
|
39
|
+
return new messages_1.AIMessage({
|
|
40
|
+
content,
|
|
41
|
+
id,
|
|
42
|
+
additional_kwargs: additionalKwargs,
|
|
43
|
+
tool_calls: messageObj.tool_calls || [],
|
|
44
|
+
invalid_tool_calls: messageObj.invalid_tool_calls || [],
|
|
45
|
+
});
|
|
46
|
+
case 'HumanMessage':
|
|
47
|
+
return new messages_1.HumanMessage({
|
|
48
|
+
content,
|
|
49
|
+
id,
|
|
50
|
+
additional_kwargs: additionalKwargs,
|
|
51
|
+
});
|
|
52
|
+
case 'SystemMessage':
|
|
53
|
+
return new messages_1.SystemMessage({
|
|
54
|
+
content,
|
|
55
|
+
id,
|
|
56
|
+
additional_kwargs: additionalKwargs,
|
|
57
|
+
});
|
|
58
|
+
case 'ToolMessage':
|
|
59
|
+
return new messages_1.ToolMessage({
|
|
60
|
+
content,
|
|
61
|
+
id,
|
|
62
|
+
additional_kwargs: additionalKwargs,
|
|
63
|
+
tool_call_id: messageObj.tool_call_id || '',
|
|
64
|
+
});
|
|
65
|
+
default:
|
|
66
|
+
// Default to HumanMessage for unknown types
|
|
67
|
+
logger_1.logger.warn({
|
|
68
|
+
msg: 'Unknown message type, defaulting to HumanMessage',
|
|
69
|
+
messageType,
|
|
70
|
+
messageObj,
|
|
71
|
+
});
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
logger_1.logger.error({
|
|
77
|
+
msg: 'Error reconstructing message',
|
|
78
|
+
err,
|
|
79
|
+
messageObj,
|
|
80
|
+
});
|
|
81
|
+
// Return a fallback HumanMessage in case of error
|
|
82
|
+
return new messages_1.HumanMessage({
|
|
83
|
+
content: messageObj.content || 'Error reconstructing message',
|
|
84
|
+
id: messageObj.id,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
.filter(Boolean);
|
|
89
|
+
};
|
|
90
|
+
exports.default = extractToolStateResponse;
|
|
91
|
+
//# sourceMappingURL=extractStateMemoryResponse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractStateMemoryResponse.js","sourceRoot":"","sources":["../../src/utils/extractStateMemoryResponse.ts"],"names":[],"mappings":";;AAAA,uDAA4G;AAC5G,qCAAkC;AAGlC,MAAM,wBAAwB,GAAG,CAAC,WAAwB,EAAkB,EAAE;IAC5E,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAiB,CAAC,CAAC;QACzD,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,IAAI,MAAM,EAAE,CAAC;YACvE,IAAI,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;gBAC1B,MAAM,CAAC,KAAK,CAAC,QAAQ,GAAG,gCAAgC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;Y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AAY,CAAC;wBACtB,OAAO;wBACP,EAAE;wBACF,iBAAiB,EAAE,gBAAgB;qBACpC,CAAC,CAAC;gBACL,KAAK,eAAe;oBAClB,OAAO,IAAI,wBAAa,CAAC;wBACvB,OAAO;wBACP,EAAE;wBACF,iBAAiB,EAAE,gBAAgB;qBACpC,CAAC,CAAC;gBACL,KAAK,aAAa;oBAChB,OAAO,IAAI,sBAAW,CAAC;wBACrB,OAAO;wBACP,EAAE;wBACF,iBAAiB,EAAE,gBAAgB;wBACnC,YAAY,EAAE,UAAU,CAAC,YAAY,IAAI,EAAE;qBAC5C,CAAC,CAAC;gBAEL;oBACE,4CAA4C;oBAC5C,eAAM,CAAC,IAAI,CAAC;wBACV,GAAG,EAAE,kDAAkD;wBACvD,WAAW;wBACX,UAAU;qBACX,CAAC,CAAC;oBACH,OAAO,IAAI,CAAC;YAChB,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,eAAM,CAAC,KAAK,CAAC;gBACX,GAAG,EAAE,8BAA8B;gBACnC,GAAG;gBACH,UAAU;aACX,CAAC,CAAC;YACH,kDAAkD;YAClD,OAAO,IAAI,uBAAY,CAAC;gBACtB,OAAO,EAAE,UAAU,CAAC,OAAO,IAAI,8BAA8B;gBAC7D,EAAE,EAAE,UAAU,CAAC,EAAE;aAClB,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;SACD,MAAM,CAAC,OAAO,CAAkB,CAAC;AACtC,CAAC,CAAC;AAEF,kBAAe,wBAAwB,CAAC"}
|
package/package.json
CHANGED
package/src/nodes/addRpaNode.ts
CHANGED
|
@@ -12,6 +12,8 @@ import { LLMProviders } from '../types/LLM.types';
|
|
|
12
12
|
import { AIMessage, ToolMessage } from '@langchain/core/messages';
|
|
13
13
|
import { v4 as uuidv4 } from 'uuid';
|
|
14
14
|
import { executeRpaStep } from './rpaStepsExecutor';
|
|
15
|
+
import { createBrowserSession } from '../browserTask/executeBrowserTask';
|
|
16
|
+
import { getConfig } from '../platform/config';
|
|
15
17
|
|
|
16
18
|
type AddRpaNodeParams = {
|
|
17
19
|
graph: PreCompiledGraph;
|
|
@@ -29,13 +31,22 @@ export const addRpaNode = async ({ graph, node, agent, llm }: AddRpaNodeParams)
|
|
|
29
31
|
|
|
30
32
|
let browser: Browser | null = null;
|
|
31
33
|
let page: Page | null = null;
|
|
34
|
+
const { browserTaskMode } = getConfig();
|
|
32
35
|
|
|
36
|
+
const session = await createBrowserSession({
|
|
37
|
+
sessionId: state.sessionId,
|
|
38
|
+
browserTaskMode,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if (!session.sessionId || !session.cdpUrl) {
|
|
42
|
+
throw new Error('Failed to create browser session: missing session details');
|
|
43
|
+
}
|
|
33
44
|
// Create tool call for RPA execution
|
|
34
45
|
const toolCallId = uuidv4();
|
|
35
46
|
const aiMessageId = uuidv4();
|
|
36
|
-
|
|
47
|
+
state.cdpUrl = session.cdpUrl;
|
|
37
48
|
// Get CDP URL from state
|
|
38
|
-
const cdpUrl =
|
|
49
|
+
const cdpUrl = session.cdpUrl;
|
|
39
50
|
|
|
40
51
|
const toolCall = {
|
|
41
52
|
id: toolCallId,
|