@must-b/must-b 1.0.0 → 1.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/bin/must-b.cjs +41 -27
- package/dist/BUILD.json +3 -3
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/bin/must-b.cjs
CHANGED
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Must-b cross-platform entry wrapper.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* This eliminates ANY reliance on tsx.exe / tsx.cmd / tsx shell scripts.
|
|
5
|
+
* Production (global install): runs dist/index.js directly with Node.
|
|
6
|
+
* Development (local clone): falls back to tsx + src/index.ts.
|
|
8
7
|
*
|
|
9
|
-
* Works on Windows, Linux, macOS after `npm install`.
|
|
8
|
+
* Works on Windows, Linux, macOS after `npm install -g @must-b/must-b`.
|
|
10
9
|
*/
|
|
11
10
|
'use strict';
|
|
12
11
|
const { spawnSync } = require('child_process');
|
|
@@ -15,63 +14,78 @@ const fs = require('fs');
|
|
|
15
14
|
const { createRequire } = require('module');
|
|
16
15
|
const { pathToFileURL } = require('url');
|
|
17
16
|
|
|
18
|
-
// ── 1. Resolve real
|
|
17
|
+
// ── 1. Resolve real package root (follows symlinks — handles npm link / global) ─
|
|
19
18
|
function findRoot() {
|
|
20
19
|
try {
|
|
21
20
|
let dir = fs.realpathSync(__dirname);
|
|
22
21
|
while (dir !== path.parse(dir).root) {
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
if (fs.existsSync(path.join(dir, 'package.json'))) {
|
|
23
|
+
// Accept if we have a built dist OR a dev src tree
|
|
24
|
+
if (
|
|
25
|
+
fs.existsSync(path.join(dir, 'dist', 'index.js')) ||
|
|
26
|
+
fs.existsSync(path.join(dir, 'src', 'index.ts'))
|
|
27
|
+
) return dir;
|
|
28
|
+
}
|
|
27
29
|
dir = path.dirname(dir);
|
|
28
30
|
}
|
|
29
31
|
} catch { /* fallthrough */ }
|
|
30
32
|
return path.resolve(__dirname, '..');
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
const root
|
|
34
|
-
const entry = path.join(root, 'src', 'index.ts');
|
|
35
|
+
const root = findRoot();
|
|
35
36
|
const args = process.argv.slice(2);
|
|
36
37
|
const env = { ...process.env, MUSTB_ROOT: root };
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
const distEntry = path.join(root, 'dist', 'index.js');
|
|
40
|
+
const srcEntry = path.join(root, 'src', 'index.ts');
|
|
41
|
+
|
|
42
|
+
// ── 2. Production path: dist/index.js exists → run directly with Node ────────
|
|
43
|
+
if (fs.existsSync(distEntry)) {
|
|
44
|
+
const result = spawnSync(
|
|
45
|
+
process.execPath,
|
|
46
|
+
['--no-warnings', distEntry, ...args],
|
|
47
|
+
{ stdio: 'inherit', cwd: root, env }
|
|
48
|
+
);
|
|
49
|
+
process.exit(result.status ?? 1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ── 3. Dev path: no dist → require tsx to transpile src/index.ts ─────────────
|
|
53
|
+
if (!fs.existsSync(srcEntry)) {
|
|
40
54
|
console.error(
|
|
41
|
-
'\n[must-b]
|
|
55
|
+
'\n[must-b] Installation appears incomplete.\n' +
|
|
56
|
+
' Expected: ' + distEntry + '\n' +
|
|
57
|
+
' Run: npm run build:prod (or reinstall via npm install -g @must-b/must-b)\n'
|
|
58
|
+
);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const tsxDir = path.join(root, 'node_modules', 'tsx');
|
|
63
|
+
if (!fs.existsSync(tsxDir)) {
|
|
64
|
+
console.error(
|
|
65
|
+
'\n[must-b] Dev dependencies not installed.\n' +
|
|
42
66
|
' Run: npm install\n' +
|
|
43
67
|
' in: ' + root + '\n'
|
|
44
68
|
);
|
|
45
69
|
process.exit(1);
|
|
46
70
|
}
|
|
47
71
|
|
|
48
|
-
// ── 3. Resolve tsx loader path (absolute — no global lookup needed) ────────
|
|
49
72
|
const rootRequire = createRequire(path.join(root, 'package.json'));
|
|
50
73
|
let loaderPath;
|
|
51
74
|
try {
|
|
52
|
-
// tsx v4 exports 'tsx/esm' as the ESM/CJS hook
|
|
53
75
|
loaderPath = rootRequire.resolve('tsx/esm');
|
|
54
76
|
} catch {
|
|
55
|
-
// Fallback to tsx package main if export map differs
|
|
56
77
|
loaderPath = rootRequire.resolve('tsx');
|
|
57
78
|
}
|
|
58
79
|
|
|
59
|
-
// ── 4. Pick the right hook flag for this Node version ─────────────────────
|
|
60
|
-
// Node 20.6+: --import (stable, requires file:// URL on Windows)
|
|
61
|
-
// Node 18/19: --loader (experimental but fully functional)
|
|
62
80
|
const nodeMajor = parseInt(process.versions.node.split('.')[0], 10);
|
|
63
|
-
const hookFlag
|
|
64
|
-
|
|
65
|
-
// --import requires a file:// URL on Windows; --loader accepts bare paths
|
|
66
|
-
const hookArg = hookFlag === '--import'
|
|
81
|
+
const hookFlag = nodeMajor >= 20 ? '--import' : '--loader';
|
|
82
|
+
const hookArg = hookFlag === '--import'
|
|
67
83
|
? pathToFileURL(loaderPath).href
|
|
68
84
|
: loaderPath;
|
|
69
85
|
|
|
70
|
-
// ── 5. Spawn Node itself with tsx hook — no tsx binary required ────────────
|
|
71
86
|
const result = spawnSync(
|
|
72
87
|
process.execPath,
|
|
73
|
-
[hookFlag, hookArg, '--no-warnings',
|
|
88
|
+
[hookFlag, hookArg, '--no-warnings', srcEntry, ...args],
|
|
74
89
|
{ stdio: 'inherit', cwd: root, env }
|
|
75
90
|
);
|
|
76
|
-
|
|
77
91
|
process.exit(result.status ?? 1);
|
package/dist/BUILD.json
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -16528,7 +16528,7 @@ ${B}${m}`+p.repeat(d)+`${B}`,Q}function l(d,E,g,B){return`${E}${B}`+g.repeat(d)+
|
|
|
16528
16528
|
\u2588\u2588\u2554\u2588\u2588\u2588\u2588\u2554\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D
|
|
16529
16529
|
\u2588\u2588\u2551\u255A\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2550\u2550\u2550\u2550\u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2550\u2550\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557
|
|
16530
16530
|
\u2588\u2588\u2551 \u255A\u2550\u255D \u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D
|
|
16531
|
-
\u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D `;function xht(){try{return"1.0.
|
|
16531
|
+
\u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D `;function xht(){try{return"1.0.1"}catch{return"1.0.0"}}function Hht(){try{return"1c9f915"}catch{return""}}function XB(e,A=58){let t=e.replace(/\x1b\[[0-9;]*m/g,""),r=Math.max(0,Math.floor((A-t.length)/2));return" ".repeat(r)+e}function ExA(e="\u2500",A=58){return Bc(" "+e.repeat(A))}function uI(e,A){let t=xht(),r=Hht();console.log(dxA(Mht)),console.log(""),console.log(XB(kht(Oht("Must-b"))+" "+hxA("v"+t))),console.log(XB(Bc("Professional AI Operating System"))),console.log(""),console.log(XB(dxA("\u26A1 Autonomous \xB7 Precise \xB7 Always On"))),console.log(XB(Bc("Vision")+Bc(" \xB7 ")+Bc("Voice")+Bc(" \xB7 ")+Bc("OS Control")+Bc(" \xB7 ")+Bc("Multi-Agent Hierarchy"))),console.log(""),console.log(ExA()),console.log("");let i=[`Node ${process.version}`,`Mode: ${e.toUpperCase()}`,`PID ${process.pid}`,r?`#${r}`:null].filter(Boolean).join(Bc(" \xB7 "));console.log(XB(Bc(i))),e==="web"&&(console.log(""),console.log(XB(_ht("\u25B6 ")+hxA(`http://localhost:${A}`))),console.log(XB(Bc("Dashboard is live \u2014 open in your browser")))),console.log(""),console.log(ExA()),console.log(XB(Bc("Built by Auto Step \xB7 https://must-b.com"))),console.log("")}var pxA=require("events"),QxA=require("module"),mxA=Te(require("path"),1),Fht={};function Sht(e){let A=e.toLowerCase();return A.includes("401")||A.includes("unauthorized")||A.includes("api key")||A.includes("invalid key")?"auth":A.includes("429")||A.includes("rate limit")||A.includes("too many requests")?"ratelimit":A.includes("econnrefused")||A.includes("enotfound")||A.includes("fetch failed")||A.includes("network")?"network":"unknown"}async function Rht(){try{let A=(0,QxA.createRequire)(Fht.url)("dotenv"),t=mxA.default.join(process.cwd(),".env");A.config({path:t,override:!0})}catch{}}function gxA(e){let A=["OPENROUTER_API_KEY","OPENAI_API_KEY","ANTHROPIC_API_KEY","OPENROUTER_API_KEY_2","OPENROUTER_API_KEY_3","OPENAI_API_KEY_2","ANTHROPIC_API_KEY_2"],t=process.env.OPENROUTER_API_KEY??process.env.OPENAI_API_KEY??process.env.ANTHROPIC_API_KEY??"";for(let r of A){let i=process.env[r];if(i&&i!==t&&i.length>8)return r.startsWith("OPENROUTER")||r.includes("OPENROUTER_API_KEY")?process.env.OPENROUTER_API_KEY=i:r.startsWith("OPENAI")?process.env.OPENAI_API_KEY=i:r.startsWith("ANTHROPIC")&&(process.env.ANTHROPIC_API_KEY=i),e.info(`Orchestrator: Rotated to backup API key (${r}).`),!0}return!1}function BxA(e){return Math.min(1e3*Math.pow(2,e-1),3e4)}var Mx=class extends pxA.EventEmitter{constructor(t,r,i){super();this.MAX_REVISIONS=3;this._busy=!1;this._errorSignatures=new Map;this.logger=t,this.planner=r,this.executor=i,this.logger.info("Orchestrator: Initialized.")}get busy(){return this._busy}async run(t){this._busy=!0,this.logger.info(`Orchestrator: Goal received \u2014 "${t}"`),this.emit("planStart",{goal:t,timestamp:Date.now()});let r=0,i=t;for(;r<=this.MAX_REVISIONS;)try{let n=await this.planner.plan(i);if(this.emit("planGenerated",{goal:i,steps:n,timestamp:Date.now()}),!n.length){this.emit("planFinish",{goal:t,status:"empty",timestamp:Date.now()});break}let a=[];for(let o of n){this.emit("stepStart",{step:o,timestamp:Date.now()});let l=await this.executor.executeStep(o);a.push({description:o.description,result:l}),this.emit("stepFinish",{step:o,status:"success",result:l,timestamp:Date.now()})}let s=await this.planner.synthesize(t,a);this.emit("finalAnswer",{goal:t,answer:s,timestamp:Date.now()}),this._errorSignatures.clear(),this.logger.info(`Orchestrator: Goal completed \u2014 "${t}"`),this.emit("planFinish",{goal:t,status:"completed",answer:s,steps:n.map(o=>({description:o.description,tool:o.tool})),timestamp:Date.now()});break}catch(n){r++;let a=n?.message??String(n),s=Sht(a);if(this.logger.warn(`Orchestrator: Step failed [${s}] (revision ${r}/${this.MAX_REVISIONS}) \u2014 ${a}`),this.emit("stepFinish",{status:"error",error:a,errorKind:s,timestamp:Date.now()}),r>this.MAX_REVISIONS){this.logger.error(`Orchestrator: Max revisions hit. Aborting goal "${t}".`),this.emit("planFinish",{goal:t,status:"failed",error:a,timestamp:Date.now()});break}if(s==="auth"){this.logger.info("Orchestrator: Auth error \u2014 reloading .env and attempting key rotation."),await Rht();let c=gxA(this.logger);this.emit("agentRepair",{action:c?"key_rotation":"reload_env",reason:a,timestamp:Date.now()});continue}if(s==="ratelimit"){let c=BxA(r);this.logger.info(`Orchestrator: Rate-limit \u2014 waiting ${c}ms, then trying key rotation.`),await new Promise(u=>setTimeout(u,c)),gxA(this.logger),this.emit("agentRepair",{action:"backoff+rotation",waitMs:c,reason:a,timestamp:Date.now()});continue}if(s==="network"){let c=BxA(r);this.logger.info(`Orchestrator: Network error \u2014 waiting ${c}ms then re-planning.`),this.emit("agentRepair",{action:"backoff",waitMs:c,reason:a,timestamp:Date.now()}),await new Promise(u=>setTimeout(u,c))}let o=a.slice(0,120),l=(this._errorSignatures.get(o)??0)+1;this._errorSignatures.set(o,l),l>=2?(this.logger.warn(`Orchestrator: Recurring error (\xD7${l}) \u2014 injecting auto-repair context.`),this.emit("agentRepair",{action:"auto_repair",errorSignature:o,occurrences:l,timestamp:Date.now()}),i=[`Auto-repair attempt for: "${t}"`,`Recurring error (\xD7${l}): ${a}`,"Diagnose the root cause, attempt a different approach or skip the failing step, and complete the original goal."].join(" \u2014 ")):i=`Revised: "${t}" \u2014 previous attempt failed: ${a}`}this._busy=!1}};var gq=Te(cI(),1);gq.default.config({override:!0});var xx=class{constructor(A){this.logger=A,this.model=process.env.OPENROUTER_MODEL||"openai/gpt-3.5-turbo",this.baseUrl="https://openrouter.ai/api/v1"}async generateJson(A){let t=await this.chat(A,{jsonMode:!0});try{let r=t.replace(/```json\n|\n```/g,"").trim();return JSON.parse(r)}catch(r){throw this.logger.error(`Provider: Failed to parse JSON response: ${r.message}`),this.logger.debug(`Raw response: ${t}`),new Error("LLM failed to produce valid JSON")}}async chat(A,t={}){gq.default.config({override:!0});let r=process.env.OPENROUTER_API_KEY||"";r||this.logger.warn("Provider: OPENROUTER_API_KEY is not set. LLM calls will fail."),this.logger.info(`Provider: Sending request to ${this.model}...`);try{let i={Authorization:`Bearer ${r}`,"Content-Type":"application/json","HTTP-Referer":"https://must-b.ai","X-Title":"Must-b Agent"},n={model:this.model,messages:A,temperature:.1};t.jsonMode&&(n.response_format={type:"json_object"});let a=await fetch(`${this.baseUrl}/chat/completions`,{method:"POST",headers:i,body:JSON.stringify(n)});if(!a.ok){let l=await a.text();throw new Error(`OpenRouter API Error: ${a.status} - ${l}`)}let o=(await a.json()).choices[0]?.message?.content;if(!o)throw new Error("Provider: Received empty response from LLM.");return o}catch(i){throw this.logger.error(`Provider: LLM Request Failed - ${i.message}`),i}}};var Hx=class{constructor(A){this.logger=A,this.provider=new xx(A)}async plan(A){this.logger.info(`Planner: Generating plan for goal: "${A}"`);let r=[{role:"system",content:`You are the Planner for Must-b, an autonomous AI agent with full browser, filesystem, terminal, and memory capabilities.
|
|
16532
16532
|
Your job is to break down a high-level user Goal into a precise, executable sequence of steps.
|
|
16533
16533
|
|
|
16534
16534
|
Available Tools:
|
package/dist/index.js
CHANGED
|
@@ -16528,7 +16528,7 @@ ${B}${m}`+p.repeat(d)+`${B}`,Q}function l(d,E,g,B){return`${E}${B}`+g.repeat(d)+
|
|
|
16528
16528
|
\u2588\u2588\u2554\u2588\u2588\u2588\u2588\u2554\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D
|
|
16529
16529
|
\u2588\u2588\u2551\u255A\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2550\u2550\u2550\u2550\u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2550\u2550\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557
|
|
16530
16530
|
\u2588\u2588\u2551 \u255A\u2550\u255D \u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D
|
|
16531
|
-
\u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D `;function qdt(){try{return"1.0.
|
|
16531
|
+
\u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D `;function qdt(){try{return"1.0.1"}catch{return"1.0.0"}}function Kdt(){try{return"1c9f915"}catch{return""}}function KB(e,A=58){let t=e.replace(/\x1b\[[0-9;]*m/g,""),r=Math.max(0,Math.floor((A-t.length)/2));return" ".repeat(r)+e}function ixA(e="\u2500",A=58){return Bc(" "+e.repeat(A))}function rI(e,A){let t=qdt(),r=Kdt();console.log(txA(Vdt)),console.log(""),console.log(KB(zdt(jdt("Must-b"))+" "+rxA("v"+t))),console.log(KB(Bc("Professional AI Operating System"))),console.log(""),console.log(KB(txA("\u26A1 Autonomous \xB7 Precise \xB7 Always On"))),console.log(KB(Bc("Vision")+Bc(" \xB7 ")+Bc("Voice")+Bc(" \xB7 ")+Bc("OS Control")+Bc(" \xB7 ")+Bc("Multi-Agent Hierarchy"))),console.log(""),console.log(ixA()),console.log("");let i=[`Node ${process.version}`,`Mode: ${e.toUpperCase()}`,`PID ${process.pid}`,r?`#${r}`:null].filter(Boolean).join(Bc(" \xB7 "));console.log(KB(Bc(i))),e==="web"&&(console.log(""),console.log(KB(Wdt("\u25B6 ")+rxA(`http://localhost:${A}`))),console.log(KB(Bc("Dashboard is live \u2014 open in your browser")))),console.log(""),console.log(ixA()),console.log(KB(Bc("Built by Auto Step \xB7 https://must-b.com"))),console.log("")}import{EventEmitter as Jdt}from"events";import{createRequire as Zdt}from"module";import Xdt from"path";function $dt(e){let A=e.toLowerCase();return A.includes("401")||A.includes("unauthorized")||A.includes("api key")||A.includes("invalid key")?"auth":A.includes("429")||A.includes("rate limit")||A.includes("too many requests")?"ratelimit":A.includes("econnrefused")||A.includes("enotfound")||A.includes("fetch failed")||A.includes("network")?"network":"unknown"}async function Aht(){try{let A=Zdt(import.meta.url)("dotenv"),t=Xdt.join(process.cwd(),".env");A.config({path:t,override:!0})}catch{}}function nxA(e){let A=["OPENROUTER_API_KEY","OPENAI_API_KEY","ANTHROPIC_API_KEY","OPENROUTER_API_KEY_2","OPENROUTER_API_KEY_3","OPENAI_API_KEY_2","ANTHROPIC_API_KEY_2"],t=process.env.OPENROUTER_API_KEY??process.env.OPENAI_API_KEY??process.env.ANTHROPIC_API_KEY??"";for(let r of A){let i=process.env[r];if(i&&i!==t&&i.length>8)return r.startsWith("OPENROUTER")||r.includes("OPENROUTER_API_KEY")?process.env.OPENROUTER_API_KEY=i:r.startsWith("OPENAI")?process.env.OPENAI_API_KEY=i:r.startsWith("ANTHROPIC")&&(process.env.ANTHROPIC_API_KEY=i),e.info(`Orchestrator: Rotated to backup API key (${r}).`),!0}return!1}function axA(e){return Math.min(1e3*Math.pow(2,e-1),3e4)}var Cx=class extends Jdt{constructor(t,r,i){super();this.MAX_REVISIONS=3;this._busy=!1;this._errorSignatures=new Map;this.logger=t,this.planner=r,this.executor=i,this.logger.info("Orchestrator: Initialized.")}get busy(){return this._busy}async run(t){this._busy=!0,this.logger.info(`Orchestrator: Goal received \u2014 "${t}"`),this.emit("planStart",{goal:t,timestamp:Date.now()});let r=0,i=t;for(;r<=this.MAX_REVISIONS;)try{let n=await this.planner.plan(i);if(this.emit("planGenerated",{goal:i,steps:n,timestamp:Date.now()}),!n.length){this.emit("planFinish",{goal:t,status:"empty",timestamp:Date.now()});break}let a=[];for(let o of n){this.emit("stepStart",{step:o,timestamp:Date.now()});let l=await this.executor.executeStep(o);a.push({description:o.description,result:l}),this.emit("stepFinish",{step:o,status:"success",result:l,timestamp:Date.now()})}let s=await this.planner.synthesize(t,a);this.emit("finalAnswer",{goal:t,answer:s,timestamp:Date.now()}),this._errorSignatures.clear(),this.logger.info(`Orchestrator: Goal completed \u2014 "${t}"`),this.emit("planFinish",{goal:t,status:"completed",answer:s,steps:n.map(o=>({description:o.description,tool:o.tool})),timestamp:Date.now()});break}catch(n){r++;let a=n?.message??String(n),s=$dt(a);if(this.logger.warn(`Orchestrator: Step failed [${s}] (revision ${r}/${this.MAX_REVISIONS}) \u2014 ${a}`),this.emit("stepFinish",{status:"error",error:a,errorKind:s,timestamp:Date.now()}),r>this.MAX_REVISIONS){this.logger.error(`Orchestrator: Max revisions hit. Aborting goal "${t}".`),this.emit("planFinish",{goal:t,status:"failed",error:a,timestamp:Date.now()});break}if(s==="auth"){this.logger.info("Orchestrator: Auth error \u2014 reloading .env and attempting key rotation."),await Aht();let c=nxA(this.logger);this.emit("agentRepair",{action:c?"key_rotation":"reload_env",reason:a,timestamp:Date.now()});continue}if(s==="ratelimit"){let c=axA(r);this.logger.info(`Orchestrator: Rate-limit \u2014 waiting ${c}ms, then trying key rotation.`),await new Promise(u=>setTimeout(u,c)),nxA(this.logger),this.emit("agentRepair",{action:"backoff+rotation",waitMs:c,reason:a,timestamp:Date.now()});continue}if(s==="network"){let c=axA(r);this.logger.info(`Orchestrator: Network error \u2014 waiting ${c}ms then re-planning.`),this.emit("agentRepair",{action:"backoff",waitMs:c,reason:a,timestamp:Date.now()}),await new Promise(u=>setTimeout(u,c))}let o=a.slice(0,120),l=(this._errorSignatures.get(o)??0)+1;this._errorSignatures.set(o,l),l>=2?(this.logger.warn(`Orchestrator: Recurring error (\xD7${l}) \u2014 injecting auto-repair context.`),this.emit("agentRepair",{action:"auto_repair",errorSignature:o,occurrences:l,timestamp:Date.now()}),i=[`Auto-repair attempt for: "${t}"`,`Recurring error (\xD7${l}): ${a}`,"Diagnose the root cause, attempt a different approach or skip the failing step, and complete the original goal."].join(" \u2014 ")):i=`Revised: "${t}" \u2014 previous attempt failed: ${a}`}this._busy=!1}};var eq=sg(tI(),1);eq.default.config({override:!0});var Ix=class{constructor(A){this.logger=A,this.model=process.env.OPENROUTER_MODEL||"openai/gpt-3.5-turbo",this.baseUrl="https://openrouter.ai/api/v1"}async generateJson(A){let t=await this.chat(A,{jsonMode:!0});try{let r=t.replace(/```json\n|\n```/g,"").trim();return JSON.parse(r)}catch(r){throw this.logger.error(`Provider: Failed to parse JSON response: ${r.message}`),this.logger.debug(`Raw response: ${t}`),new Error("LLM failed to produce valid JSON")}}async chat(A,t={}){eq.default.config({override:!0});let r=process.env.OPENROUTER_API_KEY||"";r||this.logger.warn("Provider: OPENROUTER_API_KEY is not set. LLM calls will fail."),this.logger.info(`Provider: Sending request to ${this.model}...`);try{let i={Authorization:`Bearer ${r}`,"Content-Type":"application/json","HTTP-Referer":"https://must-b.ai","X-Title":"Must-b Agent"},n={model:this.model,messages:A,temperature:.1};t.jsonMode&&(n.response_format={type:"json_object"});let a=await fetch(`${this.baseUrl}/chat/completions`,{method:"POST",headers:i,body:JSON.stringify(n)});if(!a.ok){let l=await a.text();throw new Error(`OpenRouter API Error: ${a.status} - ${l}`)}let o=(await a.json()).choices[0]?.message?.content;if(!o)throw new Error("Provider: Received empty response from LLM.");return o}catch(i){throw this.logger.error(`Provider: LLM Request Failed - ${i.message}`),i}}};var vx=class{constructor(A){this.logger=A,this.provider=new Ix(A)}async plan(A){this.logger.info(`Planner: Generating plan for goal: "${A}"`);let r=[{role:"system",content:`You are the Planner for Must-b, an autonomous AI agent with full browser, filesystem, terminal, and memory capabilities.
|
|
16532
16532
|
Your job is to break down a high-level user Goal into a precise, executable sequence of steps.
|
|
16533
16533
|
|
|
16534
16534
|
Available Tools:
|