@locusai/sdk 0.3.1 ā 0.3.3
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/orchestrator.d.ts +4 -0
- package/dist/orchestrator.d.ts.map +1 -1
- package/dist/orchestrator.js +33 -7
- package/package.json +1 -1
- package/src/orchestrator.ts +43 -7
package/dist/orchestrator.d.ts
CHANGED
|
@@ -44,6 +44,10 @@ export declare class AgentOrchestrator extends EventEmitter {
|
|
|
44
44
|
* Main orchestration loop - runs 1 agent continuously
|
|
45
45
|
*/
|
|
46
46
|
private orchestrationLoop;
|
|
47
|
+
/**
|
|
48
|
+
* Find the package root by looking for package.json
|
|
49
|
+
*/
|
|
50
|
+
private findPackageRoot;
|
|
47
51
|
/**
|
|
48
52
|
* Spawn a single agent process
|
|
49
53
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../src/orchestrator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAS,MAAM,oBAAoB,CAAC;AAGzD,OAAO,EAAE,IAAI,EAA4B,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;IACpD,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,YAAY,CAAC;CACxB;AAED,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,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;;;IAeR,OAAO,CAAC,KAAK;CAGd"}
|
package/dist/orchestrator.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
4
|
import { TaskPriority, TaskStatus } from "@locusai/shared";
|
|
5
5
|
import { EventEmitter } from "events";
|
|
6
6
|
import { LocusClient } from "./index";
|
|
@@ -97,6 +97,20 @@ export class AgentOrchestrator extends EventEmitter {
|
|
|
97
97
|
}
|
|
98
98
|
console.log("\nā
Orchestrator finished");
|
|
99
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Find the package root by looking for package.json
|
|
102
|
+
*/
|
|
103
|
+
findPackageRoot(startPath) {
|
|
104
|
+
let currentDir = startPath;
|
|
105
|
+
while (currentDir !== "/") {
|
|
106
|
+
if (existsSync(join(currentDir, "package.json"))) {
|
|
107
|
+
return currentDir;
|
|
108
|
+
}
|
|
109
|
+
currentDir = dirname(currentDir);
|
|
110
|
+
}
|
|
111
|
+
// Fallback to startPath if not found
|
|
112
|
+
return startPath;
|
|
113
|
+
}
|
|
100
114
|
/**
|
|
101
115
|
* Spawn a single agent process
|
|
102
116
|
*/
|
|
@@ -115,16 +129,28 @@ export class AgentOrchestrator extends EventEmitter {
|
|
|
115
129
|
this.agents.set(agentId, agentState);
|
|
116
130
|
console.log(`š Agent started: ${agentId}\n`);
|
|
117
131
|
// Build arguments for agent worker
|
|
118
|
-
//
|
|
119
|
-
const potentialPaths = [
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
132
|
+
// Try multiple resolution strategies
|
|
133
|
+
const potentialPaths = [];
|
|
134
|
+
// Strategy 1: Use import.meta.resolve to find the installed SDK package
|
|
135
|
+
try {
|
|
136
|
+
// Resolve the SDK's index to find the package location
|
|
137
|
+
const sdkIndexPath = import.meta.resolve("@locusai/sdk");
|
|
138
|
+
const sdkDir = dirname(sdkIndexPath.replace("file://", ""));
|
|
139
|
+
// In production, files are in dist/; sdkDir points to dist/ or src/
|
|
140
|
+
const sdkRoot = this.findPackageRoot(sdkDir);
|
|
141
|
+
potentialPaths.push(join(sdkRoot, "dist", "agent", "worker.js"), join(sdkRoot, "src", "agent", "worker.ts"));
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
// import.meta.resolve failed, continue with fallback strategies
|
|
145
|
+
}
|
|
146
|
+
// Strategy 2: Find package root from __dirname (works in dev/local)
|
|
147
|
+
const packageRoot = this.findPackageRoot(__dirname);
|
|
148
|
+
potentialPaths.push(join(packageRoot, "dist", "agent", "worker.js"), join(packageRoot, "src", "agent", "worker.ts"), join(__dirname, "agent", "worker.ts"), join(__dirname, "agent", "worker.js"));
|
|
123
149
|
const workerPath = potentialPaths.find((p) => existsSync(p));
|
|
124
150
|
// Verify worker file exists
|
|
125
151
|
if (!workerPath) {
|
|
126
152
|
throw new Error(`Worker file not found. Checked: ${potentialPaths.join(", ")}. ` +
|
|
127
|
-
`Make sure the SDK is properly built
|
|
153
|
+
`Make sure the SDK is properly built and installed.`);
|
|
128
154
|
}
|
|
129
155
|
const workerArgs = [
|
|
130
156
|
"--agent-id",
|
package/package.json
CHANGED
package/src/orchestrator.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChildProcess, spawn } from "node:child_process";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
4
|
import { Task, TaskPriority, TaskStatus } from "@locusai/shared";
|
|
5
5
|
import { EventEmitter } from "events";
|
|
6
6
|
import { LocusClient } from "./index";
|
|
@@ -141,6 +141,21 @@ export class AgentOrchestrator extends EventEmitter {
|
|
|
141
141
|
console.log("\nā
Orchestrator finished");
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Find the package root by looking for package.json
|
|
146
|
+
*/
|
|
147
|
+
private findPackageRoot(startPath: string): string {
|
|
148
|
+
let currentDir = startPath;
|
|
149
|
+
while (currentDir !== "/") {
|
|
150
|
+
if (existsSync(join(currentDir, "package.json"))) {
|
|
151
|
+
return currentDir;
|
|
152
|
+
}
|
|
153
|
+
currentDir = dirname(currentDir);
|
|
154
|
+
}
|
|
155
|
+
// Fallback to startPath if not found
|
|
156
|
+
return startPath;
|
|
157
|
+
}
|
|
158
|
+
|
|
144
159
|
/**
|
|
145
160
|
* Spawn a single agent process
|
|
146
161
|
*/
|
|
@@ -163,11 +178,32 @@ export class AgentOrchestrator extends EventEmitter {
|
|
|
163
178
|
console.log(`š Agent started: ${agentId}\n`);
|
|
164
179
|
|
|
165
180
|
// Build arguments for agent worker
|
|
166
|
-
//
|
|
167
|
-
const potentialPaths = [
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
181
|
+
// Try multiple resolution strategies
|
|
182
|
+
const potentialPaths: string[] = [];
|
|
183
|
+
|
|
184
|
+
// Strategy 1: Use import.meta.resolve to find the installed SDK package
|
|
185
|
+
try {
|
|
186
|
+
// Resolve the SDK's index to find the package location
|
|
187
|
+
const sdkIndexPath = import.meta.resolve("@locusai/sdk");
|
|
188
|
+
const sdkDir = dirname(sdkIndexPath.replace("file://", ""));
|
|
189
|
+
// In production, files are in dist/; sdkDir points to dist/ or src/
|
|
190
|
+
const sdkRoot = this.findPackageRoot(sdkDir);
|
|
191
|
+
potentialPaths.push(
|
|
192
|
+
join(sdkRoot, "dist", "agent", "worker.js"),
|
|
193
|
+
join(sdkRoot, "src", "agent", "worker.ts")
|
|
194
|
+
);
|
|
195
|
+
} catch {
|
|
196
|
+
// import.meta.resolve failed, continue with fallback strategies
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Strategy 2: Find package root from __dirname (works in dev/local)
|
|
200
|
+
const packageRoot = this.findPackageRoot(__dirname);
|
|
201
|
+
potentialPaths.push(
|
|
202
|
+
join(packageRoot, "dist", "agent", "worker.js"),
|
|
203
|
+
join(packageRoot, "src", "agent", "worker.ts"),
|
|
204
|
+
join(__dirname, "agent", "worker.ts"),
|
|
205
|
+
join(__dirname, "agent", "worker.js")
|
|
206
|
+
);
|
|
171
207
|
|
|
172
208
|
const workerPath = potentialPaths.find((p) => existsSync(p));
|
|
173
209
|
|
|
@@ -175,7 +211,7 @@ export class AgentOrchestrator extends EventEmitter {
|
|
|
175
211
|
if (!workerPath) {
|
|
176
212
|
throw new Error(
|
|
177
213
|
`Worker file not found. Checked: ${potentialPaths.join(", ")}. ` +
|
|
178
|
-
`Make sure the SDK is properly built
|
|
214
|
+
`Make sure the SDK is properly built and installed.`
|
|
179
215
|
);
|
|
180
216
|
}
|
|
181
217
|
|