opencara 0.13.0 → 0.14.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/index.js +37 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -262,6 +262,7 @@ function loadConfig() {
|
|
|
262
262
|
const envPlatformUrl = process.env.OPENCARA_PLATFORM_URL?.trim() || null;
|
|
263
263
|
const defaults = {
|
|
264
264
|
platformUrl: envPlatformUrl || DEFAULT_PLATFORM_URL,
|
|
265
|
+
apiKey: null,
|
|
265
266
|
maxDiffSizeKb: DEFAULT_MAX_DIFF_SIZE_KB,
|
|
266
267
|
maxConsecutiveErrors: DEFAULT_MAX_CONSECUTIVE_ERRORS,
|
|
267
268
|
githubToken: null,
|
|
@@ -281,6 +282,7 @@ function loadConfig() {
|
|
|
281
282
|
const overrides = validateConfigData(data, envPlatformUrl);
|
|
282
283
|
return {
|
|
283
284
|
platformUrl: envPlatformUrl || (typeof data.platform_url === "string" ? data.platform_url : DEFAULT_PLATFORM_URL),
|
|
285
|
+
apiKey: typeof data.api_key === "string" ? data.api_key.trim() || null : null,
|
|
284
286
|
maxDiffSizeKb: overrides.maxDiffSizeKb ?? (typeof data.max_diff_size_kb === "number" ? data.max_diff_size_kb : DEFAULT_MAX_DIFF_SIZE_KB),
|
|
285
287
|
maxConsecutiveErrors: overrides.maxConsecutiveErrors ?? (typeof data.max_consecutive_errors === "number" ? data.max_consecutive_errors : DEFAULT_MAX_CONSECUTIVE_ERRORS),
|
|
286
288
|
githubToken: typeof data.github_token === "string" ? data.github_token : null,
|
|
@@ -439,18 +441,29 @@ var HttpError = class extends Error {
|
|
|
439
441
|
}
|
|
440
442
|
};
|
|
441
443
|
var ApiClient = class {
|
|
442
|
-
constructor(baseUrl,
|
|
444
|
+
constructor(baseUrl, debugOrOptions) {
|
|
443
445
|
this.baseUrl = baseUrl;
|
|
444
|
-
|
|
446
|
+
if (typeof debugOrOptions === "object" && debugOrOptions !== null) {
|
|
447
|
+
this.debug = debugOrOptions.debug ?? process.env.OPENCARA_DEBUG === "1";
|
|
448
|
+
this.apiKey = debugOrOptions.apiKey ?? null;
|
|
449
|
+
} else {
|
|
450
|
+
this.debug = debugOrOptions ?? process.env.OPENCARA_DEBUG === "1";
|
|
451
|
+
this.apiKey = null;
|
|
452
|
+
}
|
|
445
453
|
}
|
|
446
454
|
debug;
|
|
455
|
+
apiKey;
|
|
447
456
|
log(msg) {
|
|
448
457
|
if (this.debug) console.debug(`[ApiClient] ${msg}`);
|
|
449
458
|
}
|
|
450
459
|
headers() {
|
|
451
|
-
|
|
460
|
+
const h = {
|
|
452
461
|
"Content-Type": "application/json"
|
|
453
462
|
};
|
|
463
|
+
if (this.apiKey) {
|
|
464
|
+
h["Authorization"] = `Bearer ${this.apiKey}`;
|
|
465
|
+
}
|
|
466
|
+
return h;
|
|
454
467
|
}
|
|
455
468
|
async get(path5) {
|
|
456
469
|
this.log(`GET ${path5}`);
|
|
@@ -548,6 +561,7 @@ var ToolTimeoutError = class extends Error {
|
|
|
548
561
|
this.name = "ToolTimeoutError";
|
|
549
562
|
}
|
|
550
563
|
};
|
|
564
|
+
var SIGKILL_GRACE_MS = 5e3;
|
|
551
565
|
var MIN_PARTIAL_RESULT_LENGTH = 50;
|
|
552
566
|
var MAX_STDERR_LENGTH = 1e3;
|
|
553
567
|
function validateCommandBinary(commandTemplate) {
|
|
@@ -647,9 +661,17 @@ function executeTool(commandTemplate, prompt, timeoutMs, signal, vars, cwd) {
|
|
|
647
661
|
let stdout = "";
|
|
648
662
|
let stderr = "";
|
|
649
663
|
let settled = false;
|
|
650
|
-
|
|
664
|
+
let sigkillTimer;
|
|
665
|
+
function scheduleKillEscalation() {
|
|
651
666
|
child.kill("SIGTERM");
|
|
652
|
-
|
|
667
|
+
if (sigkillTimer) clearTimeout(sigkillTimer);
|
|
668
|
+
sigkillTimer = setTimeout(() => {
|
|
669
|
+
if (!settled) {
|
|
670
|
+
child.kill("SIGKILL");
|
|
671
|
+
}
|
|
672
|
+
}, SIGKILL_GRACE_MS);
|
|
673
|
+
}
|
|
674
|
+
const timer = setTimeout(scheduleKillEscalation, timeoutMs);
|
|
653
675
|
child.stdout?.on("data", (chunk) => {
|
|
654
676
|
stdout += chunk.toString();
|
|
655
677
|
});
|
|
@@ -662,13 +684,12 @@ function executeTool(commandTemplate, prompt, timeoutMs, signal, vars, cwd) {
|
|
|
662
684
|
child.stdin?.end();
|
|
663
685
|
let onAbort;
|
|
664
686
|
if (signal) {
|
|
665
|
-
onAbort =
|
|
666
|
-
child.kill();
|
|
667
|
-
};
|
|
687
|
+
onAbort = scheduleKillEscalation;
|
|
668
688
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
669
689
|
}
|
|
670
690
|
function cleanup() {
|
|
671
691
|
clearTimeout(timer);
|
|
692
|
+
if (sigkillTimer) clearTimeout(sigkillTimer);
|
|
672
693
|
if (onAbort && signal) {
|
|
673
694
|
signal.removeEventListener("abort", onAbort);
|
|
674
695
|
}
|
|
@@ -1403,6 +1424,8 @@ async function pollLoop(client, agentId, reviewDeps, consumptionDeps, agentInfo,
|
|
|
1403
1424
|
pollBody.repos = repoConfig.list;
|
|
1404
1425
|
}
|
|
1405
1426
|
if (synthesizeRepos) pollBody.synthesize_repos = synthesizeRepos;
|
|
1427
|
+
if (agentInfo.model) pollBody.model = agentInfo.model;
|
|
1428
|
+
if (agentInfo.tool) pollBody.tool = agentInfo.tool;
|
|
1406
1429
|
const pollResponse = await client.post("/api/tasks/poll", pollBody);
|
|
1407
1430
|
consecutiveAuthErrors = 0;
|
|
1408
1431
|
consecutiveErrors = 0;
|
|
@@ -1859,7 +1882,7 @@ function sleep2(ms, signal) {
|
|
|
1859
1882
|
});
|
|
1860
1883
|
}
|
|
1861
1884
|
async function startAgent(agentId, platformUrl, agentInfo, reviewDeps, consumptionDeps, options) {
|
|
1862
|
-
const client = new ApiClient(platformUrl);
|
|
1885
|
+
const client = new ApiClient(platformUrl, { apiKey: options?.apiKey });
|
|
1863
1886
|
const session = consumptionDeps?.session ?? createSessionTracker();
|
|
1864
1887
|
const deps = consumptionDeps ?? { agentId, session };
|
|
1865
1888
|
const logger = createLogger(options?.label);
|
|
@@ -1950,7 +1973,8 @@ async function startAgentRouter() {
|
|
|
1950
1973
|
roles,
|
|
1951
1974
|
synthesizeRepos: agentConfig?.synthesize_repos,
|
|
1952
1975
|
githubUsername,
|
|
1953
|
-
label
|
|
1976
|
+
label,
|
|
1977
|
+
apiKey: config.apiKey
|
|
1954
1978
|
}
|
|
1955
1979
|
);
|
|
1956
1980
|
router.stop();
|
|
@@ -2015,7 +2039,8 @@ function startAgentByIndex(config, agentIndex, pollIntervalMs, auth, githubUsern
|
|
|
2015
2039
|
roles,
|
|
2016
2040
|
synthesizeRepos: agentConfig?.synthesize_repos,
|
|
2017
2041
|
githubUsername,
|
|
2018
|
-
label
|
|
2042
|
+
label,
|
|
2043
|
+
apiKey: config.apiKey
|
|
2019
2044
|
}
|
|
2020
2045
|
).finally(() => {
|
|
2021
2046
|
routerRelay?.stop();
|
|
@@ -2090,7 +2115,7 @@ agentCommand.command("start").description("Start agents in polling mode").option
|
|
|
2090
2115
|
});
|
|
2091
2116
|
|
|
2092
2117
|
// src/index.ts
|
|
2093
|
-
var program = new Command2().name("opencara").description("OpenCara \u2014 distributed AI code review agent").version("0.
|
|
2118
|
+
var program = new Command2().name("opencara").description("OpenCara \u2014 distributed AI code review agent").version("0.14.1");
|
|
2094
2119
|
program.addCommand(agentCommand);
|
|
2095
2120
|
program.action(() => {
|
|
2096
2121
|
startAgentRouter();
|