@locusai/sdk 0.3.1 → 0.3.2

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.
@@ -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,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qBAA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AAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC;IA4BhB;;OAEG;IACG,QAAQ,CACZ,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC;IAyBhB;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAM3B;;OAEG;YACW,OAAO;IAWrB;;OAEG;IACH,QAAQ;;;;;;IAeR,OAAO,CAAC,KAAK;CAGd"}
@@ -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
  */
@@ -116,15 +130,20 @@ export class AgentOrchestrator extends EventEmitter {
116
130
  console.log(`šŸš€ Agent started: ${agentId}\n`);
117
131
  // Build arguments for agent worker
118
132
  // Resolve path relative to this file's location (works in both dev and production)
133
+ // Find package root to correctly resolve worker path
134
+ const packageRoot = this.findPackageRoot(__dirname);
135
+ // Check possible locations for the worker file relative to package root
119
136
  const potentialPaths = [
120
- join(__dirname, "agent", "worker.ts"), // Try TS source first (dev)
121
- join(__dirname, "agent", "worker.js"), // Fallback to JS (prod/dist)
137
+ join(packageRoot, "dist", "agent", "worker.js"), // Production
138
+ join(packageRoot, "src", "agent", "worker.ts"), // Development
139
+ join(__dirname, "agent", "worker.ts"), // Fallback relative (dev)
140
+ join(__dirname, "agent", "worker.js"), // Fallback relative (prod)
122
141
  ];
123
142
  const workerPath = potentialPaths.find((p) => existsSync(p));
124
143
  // Verify worker file exists
125
144
  if (!workerPath) {
126
145
  throw new Error(`Worker file not found. Checked: ${potentialPaths.join(", ")}. ` +
127
- `Make sure the SDK is properly built. __dirname: ${__dirname}`);
146
+ `Make sure the SDK is properly built. __dirname: ${__dirname}, Package Root: ${packageRoot}`);
128
147
  }
129
148
  const workerArgs = [
130
149
  "--agent-id",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@locusai/sdk",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -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
  */
@@ -164,9 +179,15 @@ export class AgentOrchestrator extends EventEmitter {
164
179
 
165
180
  // Build arguments for agent worker
166
181
  // Resolve path relative to this file's location (works in both dev and production)
182
+ // Find package root to correctly resolve worker path
183
+ const packageRoot = this.findPackageRoot(__dirname);
184
+
185
+ // Check possible locations for the worker file relative to package root
167
186
  const potentialPaths = [
168
- join(__dirname, "agent", "worker.ts"), // Try TS source first (dev)
169
- join(__dirname, "agent", "worker.js"), // Fallback to JS (prod/dist)
187
+ join(packageRoot, "dist", "agent", "worker.js"), // Production
188
+ join(packageRoot, "src", "agent", "worker.ts"), // Development
189
+ join(__dirname, "agent", "worker.ts"), // Fallback relative (dev)
190
+ join(__dirname, "agent", "worker.js"), // Fallback relative (prod)
170
191
  ];
171
192
 
172
193
  const workerPath = potentialPaths.find((p) => existsSync(p));
@@ -175,7 +196,7 @@ export class AgentOrchestrator extends EventEmitter {
175
196
  if (!workerPath) {
176
197
  throw new Error(
177
198
  `Worker file not found. Checked: ${potentialPaths.join(", ")}. ` +
178
- `Make sure the SDK is properly built. __dirname: ${__dirname}`
199
+ `Make sure the SDK is properly built. __dirname: ${__dirname}, Package Root: ${packageRoot}`
179
200
  );
180
201
  }
181
202