@minded-ai/mindedjs 2.0.8 → 2.0.9-beta.0.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/agent.js +1 -1
- package/dist/agent.js.map +1 -1
- package/dist/browserTask/cdp.d.ts +23 -0
- package/dist/browserTask/cdp.d.ts.map +1 -0
- package/dist/browserTask/cdp.js +162 -0
- package/dist/browserTask/cdp.js.map +1 -0
- package/dist/browserTask/executeBrowserTask.d.ts.map +1 -1
- package/dist/browserTask/executeBrowserTask.js +25 -6
- package/dist/browserTask/executeBrowserTask.js.map +1 -1
- package/dist/browserTask/executeBrowserTask.py +54 -6
- package/dist/browserTask/localBrowserTask.d.ts.map +1 -1
- package/dist/browserTask/localBrowserTask.js +35 -95
- package/dist/browserTask/localBrowserTask.js.map +1 -1
- package/dist/cli/index.js +0 -0
- package/dist/edges/createPromptRouter.d.ts.map +1 -1
- package/dist/edges/createPromptRouter.js +1 -0
- package/dist/edges/createPromptRouter.js.map +1 -1
- package/dist/guidelines/guidelinesManager.d.ts +37 -0
- package/dist/guidelines/guidelinesManager.d.ts.map +1 -0
- package/dist/guidelines/guidelinesManager.js +172 -0
- package/dist/guidelines/guidelinesManager.js.map +1 -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/addAppToolNode.js +1 -1
- package/dist/nodes/addAppToolNode.js.map +1 -1
- package/dist/nodes/addBrowserTaskNode.d.ts.map +1 -1
- package/dist/nodes/addBrowserTaskNode.js +3 -2
- package/dist/nodes/addBrowserTaskNode.js.map +1 -1
- package/dist/nodes/addPromptNode.js +1 -1
- package/dist/nodes/addPromptNode.js.map +1 -1
- package/dist/nodes/addToolNode.js +1 -1
- package/dist/nodes/addToolNode.js.map +1 -1
- package/dist/platform/mindedChatOpenAI.d.ts +5 -0
- package/dist/platform/mindedChatOpenAI.d.ts.map +1 -0
- package/dist/platform/mindedChatOpenAI.js +23 -0
- package/dist/platform/mindedChatOpenAI.js.map +1 -0
- 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/dist/utils/extractToolMemoryResponse.d.ts +4 -0
- package/dist/utils/extractToolMemoryResponse.d.ts.map +1 -0
- package/dist/utils/extractToolMemoryResponse.js +16 -0
- package/dist/utils/extractToolMemoryResponse.js.map +1 -0
- package/package.json +2 -2
- package/src/agent.ts +1 -1
- package/src/browserTask/executeBrowserTask.py +54 -6
- package/src/browserTask/executeBrowserTask.ts +33 -7
- package/src/browserTask/localBrowserTask.ts +36 -109
- package/src/edges/createPromptRouter.ts +1 -0
- package/src/nodes/addAppToolNode.ts +1 -1
- package/src/nodes/addBrowserTaskNode.ts +3 -2
- package/src/nodes/addPromptNode.ts +1 -1
- package/src/nodes/addToolNode.ts +2 -2
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
// getOrStartLocalCDP.ts
|
|
2
2
|
import { spawn, ChildProcess } from "child_process";
|
|
3
3
|
import * as fs from "fs/promises";
|
|
4
|
-
import * as fscb from "fs";
|
|
5
4
|
import * as path from "path";
|
|
6
|
-
import * as http from "http";
|
|
7
5
|
import { chromium } from "playwright";
|
|
8
6
|
import { logger } from "../utils/logger";
|
|
7
|
+
import { wait } from "../utils/wait";
|
|
9
8
|
|
|
10
9
|
let localBrowserTask: {
|
|
11
10
|
cdpUrl: string;
|
|
12
11
|
proc: ChildProcess;
|
|
13
12
|
} | null = null;
|
|
14
13
|
|
|
14
|
+
const port = 9222;
|
|
15
|
+
|
|
15
16
|
export type StartChromiumOptions = {
|
|
16
17
|
/** Headless by default. Set to false to see a window. */
|
|
17
18
|
headless?: boolean;
|
|
@@ -39,10 +40,7 @@ export async function getOrStartLocalCDP(
|
|
|
39
40
|
};
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
const {
|
|
43
|
-
env,
|
|
44
|
-
timeoutMs = 10_000,
|
|
45
|
-
} = opts;
|
|
43
|
+
const { env } = opts;
|
|
46
44
|
|
|
47
45
|
const executablePath = chromium.executablePath();
|
|
48
46
|
|
|
@@ -116,7 +114,7 @@ export async function getOrStartLocalCDP(
|
|
|
116
114
|
"--enable-extensions",
|
|
117
115
|
"--disable-extensions-file-access-check",
|
|
118
116
|
"--enable-extension-activity-logging",
|
|
119
|
-
`--remote-debugging-port
|
|
117
|
+
`--remote-debugging-port=${port}`,
|
|
120
118
|
"--remote-debugging-address=0.0.0.0",
|
|
121
119
|
"about:blank",
|
|
122
120
|
];
|
|
@@ -126,125 +124,54 @@ export async function getOrStartLocalCDP(
|
|
|
126
124
|
env: { ...process.env, ...env },
|
|
127
125
|
});
|
|
128
126
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
proc.once("exit", (code, signal) => {
|
|
132
|
-
reject(
|
|
133
|
-
new Error(`Chromium exited prematurely (code=${code}, signal=${signal}).`)
|
|
134
|
-
);
|
|
135
|
-
});
|
|
127
|
+
proc.on("error", (error) => {
|
|
128
|
+
logger.error({ message: 'Chromium error', error });
|
|
136
129
|
});
|
|
137
130
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const whenReady = (async () => {
|
|
142
|
-
const startedAt = Date.now();
|
|
143
|
-
while (Date.now() - startedAt < timeoutMs) {
|
|
144
|
-
try {
|
|
145
|
-
// Access succeeds once the file is written.
|
|
146
|
-
await fs.access(devtoolsPortFile, fscb.constants.F_OK);
|
|
147
|
-
break;
|
|
148
|
-
} catch {
|
|
149
|
-
await delay(50);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
// If still not there, bail.
|
|
153
|
-
await fs.access(devtoolsPortFile, fscb.constants.F_OK).catch(() => {
|
|
154
|
-
throw new Error(
|
|
155
|
-
`Timed out after ${timeoutMs}ms waiting for DevToolsActivePort at ${devtoolsPortFile}`
|
|
156
|
-
);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
const raw = await fs.readFile(devtoolsPortFile, "utf8");
|
|
160
|
-
const [portLine] = raw.trim().split(/\r?\n/);
|
|
161
|
-
const port = Number(portLine);
|
|
162
|
-
if (!Number.isFinite(port)) {
|
|
163
|
-
throw new Error(`Invalid DevTools port read from file: "${portLine}"`);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// Optional: ping /json/version to ensure the endpoint is responsive.
|
|
167
|
-
await waitForHttpOk(`http://127.0.0.1:${port}/json/version`, timeoutMs);
|
|
168
|
-
|
|
169
|
-
const cdpUrl = await fetchWsFromVersionEndpoint(port, timeoutMs);
|
|
131
|
+
proc.on("exit", (code, signal) => {
|
|
132
|
+
logger.error({ message: 'Chromium exited', code, signal });
|
|
133
|
+
});
|
|
170
134
|
|
|
171
|
-
|
|
172
|
-
cdpUrl,
|
|
173
|
-
proc,
|
|
174
|
-
};
|
|
135
|
+
await waitForCdpEndpoint(port, 30);
|
|
175
136
|
|
|
176
|
-
|
|
177
|
-
})();
|
|
137
|
+
const cdpUrl = `http://127.0.0.1:${port}`;
|
|
178
138
|
|
|
179
|
-
|
|
139
|
+
localBrowserTask = {
|
|
140
|
+
cdpUrl,
|
|
141
|
+
proc,
|
|
142
|
+
};
|
|
180
143
|
|
|
181
144
|
logger.info({ message: 'Local browser task started', cdpUrl });
|
|
182
145
|
|
|
183
146
|
return { cdpUrl };
|
|
184
147
|
}
|
|
185
148
|
|
|
186
|
-
//
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
// Drain data to allow socket reuse.
|
|
205
|
-
res.resume();
|
|
206
|
-
resolve(res.statusCode === 200);
|
|
207
|
-
});
|
|
208
|
-
req.on("error", reject);
|
|
209
|
-
req.setTimeout(3000, () => {
|
|
210
|
-
req.destroy(new Error("HTTP timeout"));
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
async function fetchWsFromVersionEndpoint(
|
|
216
|
-
port: number,
|
|
217
|
-
timeoutMs: number
|
|
218
|
-
): Promise<string> {
|
|
219
|
-
const urlStr = `http://127.0.0.1:${port}/json/version`;
|
|
220
|
-
const body = await httpGetBody(urlStr, timeoutMs);
|
|
221
|
-
const parsed = JSON.parse(body);
|
|
222
|
-
if (!parsed.webSocketDebuggerUrl) {
|
|
223
|
-
throw new Error(`No webSocketDebuggerUrl in ${urlStr} response`);
|
|
149
|
+
// Legacy HTTP polling helpers removed in favor of waitForCdpEndpoint
|
|
150
|
+
|
|
151
|
+
async function waitForCdpEndpoint(port: number, maxAttempts: number): Promise<void> {
|
|
152
|
+
logger.info({ message: `Waiting for CDP endpoint on port ${port}...` });
|
|
153
|
+
for (let attemptIndex = 0; attemptIndex < maxAttempts; attemptIndex++) {
|
|
154
|
+
try {
|
|
155
|
+
const response = await fetch(`http://127.0.0.1:${port}/json/version`);
|
|
156
|
+
if (response.ok) {
|
|
157
|
+
const version = await response.json();
|
|
158
|
+
logger.info({ message: `CDP endpoint ready on port ${port}`, version: version["Browser"] });
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
} catch (error) {
|
|
162
|
+
if (attemptIndex % 5 === 0) {
|
|
163
|
+
logger.debug({ message: `CDP endpoint not ready yet, attempt ${attemptIndex + 1}/${maxAttempts}`, error });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
await wait(1000);
|
|
224
167
|
}
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
function httpGetBody(urlStr: string, timeoutMs: number): Promise<string> {
|
|
229
|
-
return new Promise((resolve, reject) => {
|
|
230
|
-
const req = http.get(urlStr, (res) => {
|
|
231
|
-
let data = "";
|
|
232
|
-
res.setEncoding("utf8");
|
|
233
|
-
res.on("data", (chunk) => (data += chunk));
|
|
234
|
-
res.on("end", () => {
|
|
235
|
-
if (res.statusCode === 200) resolve(data);
|
|
236
|
-
else reject(new Error(`HTTP ${res.statusCode}: ${data}`));
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
req.on("error", reject);
|
|
240
|
-
req.setTimeout(timeoutMs, () => req.destroy(new Error("HTTP timeout")));
|
|
241
|
-
});
|
|
168
|
+
throw new Error(`CDP endpoint not available on port ${port} after ${maxAttempts} attempts`);
|
|
242
169
|
}
|
|
243
170
|
|
|
244
171
|
export async function kill() {
|
|
245
172
|
if (localBrowserTask) {
|
|
246
173
|
localBrowserTask.proc.kill("SIGTERM");
|
|
247
|
-
await
|
|
174
|
+
await wait(300);
|
|
248
175
|
localBrowserTask.proc.kill("SIGKILL");
|
|
249
176
|
}
|
|
250
177
|
}
|
|
@@ -70,7 +70,7 @@ export const addAppToolNode = async ({
|
|
|
70
70
|
User instructions for choosing tool parameters are:
|
|
71
71
|
${node.prompt ? `${node.prompt}` : 'no instructions set by the user'}`;
|
|
72
72
|
|
|
73
|
-
const compiledPrompt = compilePrompt(message, { memory: state.memory });
|
|
73
|
+
const compiledPrompt = compilePrompt(message, { memory: state.memory, env: process.env });
|
|
74
74
|
const systemMessage = new SystemMessage(compiledPrompt);
|
|
75
75
|
if (state.messages.length === 0 || state.messages[0].getType() === 'system') {
|
|
76
76
|
state.messages[0] = systemMessage;
|
|
@@ -62,7 +62,7 @@ export const addBrowserTaskNode = async ({ graph, node, agent, llm }: AddBrowser
|
|
|
62
62
|
|
|
63
63
|
const combinedPlaybooks = combinePlaybooks(agent.playbooks);
|
|
64
64
|
if (combinedPlaybooks) {
|
|
65
|
-
const compiledPrompt = compilePrompt(combinedPlaybooks, { memory: state.memory });
|
|
65
|
+
const compiledPrompt = compilePrompt(combinedPlaybooks, { memory: state.memory, env: process.env });
|
|
66
66
|
const systemMessage = new SystemMessage(compiledPrompt);
|
|
67
67
|
if (state.messages.length === 0 || state.messages[0].getType() === 'system') {
|
|
68
68
|
state.messages[0] = systemMessage;
|
|
@@ -90,7 +90,7 @@ export const addBrowserTaskNode = async ({ graph, node, agent, llm }: AddBrowser
|
|
|
90
90
|
};
|
|
91
91
|
|
|
92
92
|
// Compile the prompt with parameters
|
|
93
|
-
const compiledPrompt = compilePrompt(node.prompt, promptParams);
|
|
93
|
+
const compiledPrompt = compilePrompt(node.prompt, { ...promptParams, env: process.env });
|
|
94
94
|
|
|
95
95
|
// Build the full prompt with compiled content
|
|
96
96
|
const fullPrompt = `
|
|
@@ -151,6 +151,7 @@ ${Object.keys(inputParams).length > 0 ? `# Input parameters:\n${JSON.stringify(i
|
|
|
151
151
|
});
|
|
152
152
|
|
|
153
153
|
state.messages.push(toolCallingMessage);
|
|
154
|
+
state.cdpUrl = session.cdpUrl;
|
|
154
155
|
state.history.push(
|
|
155
156
|
createHistoryStep<HistoryStep>(state.history, {
|
|
156
157
|
type: NodeType.BROWSER_TASK,
|
|
@@ -51,7 +51,7 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
|
|
|
51
51
|
if (combinedPlaybooks) {
|
|
52
52
|
finalMessage = combinedPlaybooks + '\n\n' + currentPromptNode;
|
|
53
53
|
}
|
|
54
|
-
const compiledPrompt = compilePrompt(finalMessage, { memory: state.memory });
|
|
54
|
+
const compiledPrompt = compilePrompt(finalMessage, { memory: state.memory, env: process.env });
|
|
55
55
|
const systemMessage = new SystemMessage(compiledPrompt);
|
|
56
56
|
if (state.messages.length === 0 || state.messages[0].getType() === 'system') {
|
|
57
57
|
state.messages[0] = systemMessage;
|
package/src/nodes/addToolNode.ts
CHANGED
|
@@ -34,7 +34,7 @@ export const addToolNode = async ({
|
|
|
34
34
|
await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId);
|
|
35
35
|
logger.debug({ msg: `[Node] Executing tool node`, node: toolNode.displayName });
|
|
36
36
|
|
|
37
|
-
const tool = langchainTool(() => {}, {
|
|
37
|
+
const tool = langchainTool(() => { }, {
|
|
38
38
|
name: matchedTool.name,
|
|
39
39
|
description: matchedTool.description,
|
|
40
40
|
schema: matchedTool.input,
|
|
@@ -52,7 +52,7 @@ export const addToolNode = async ({
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
if (finalMessage) {
|
|
55
|
-
const compiledPrompt = compilePrompt(finalMessage, { memory: state.memory });
|
|
55
|
+
const compiledPrompt = compilePrompt(finalMessage, { memory: state.memory, env: process.env });
|
|
56
56
|
const systemMessage = new SystemMessage(compiledPrompt);
|
|
57
57
|
if (state.messages.length === 0 || state.messages[0].getType() === 'system') {
|
|
58
58
|
state.messages[0] = systemMessage;
|