@ordewell/web 0.15.5 → 0.15.7
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/server/main.js +66 -37
- package/dist/server/main.js.map +1 -1
- package/package.json +2 -2
package/dist/server/main.js
CHANGED
|
@@ -311,6 +311,18 @@ function loadSavedCredentials(env = process.env, file = core.globalEnvFile()) {
|
|
|
311
311
|
if (isSavedCredential(key) && env[key] === void 0) env[key] = value;
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
|
+
function loadSavedPlannerChoice(env = process.env, file = core.globalEnvFile()) {
|
|
315
|
+
let saved;
|
|
316
|
+
try {
|
|
317
|
+
saved = core.readEnvFile(file);
|
|
318
|
+
} catch (err) {
|
|
319
|
+
console.error(`[web] could not read the saved planner choice from ${file}: ${err instanceof Error ? err.message : String(err)}`);
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
for (const key of PLANNER_CHOICE_ENV) {
|
|
323
|
+
if (saved[key] !== void 0 && env[key] === void 0) env[key] = saved[key];
|
|
324
|
+
}
|
|
325
|
+
}
|
|
314
326
|
var MAX_OUTPUT_BYTES = 4 * 1024 * 1024;
|
|
315
327
|
var SEALED_OUTPUT_GRACE_MS = 1e3;
|
|
316
328
|
function run(file, args, opts) {
|
|
@@ -603,6 +615,12 @@ var SessionOpenElsewhereError = class extends Error {
|
|
|
603
615
|
this.name = "SessionOpenElsewhereError";
|
|
604
616
|
}
|
|
605
617
|
};
|
|
618
|
+
var SessionExistsError = class extends Error {
|
|
619
|
+
constructor(sessionId) {
|
|
620
|
+
super(`Session "${sessionId}" is saved already. Open it to continue it.`);
|
|
621
|
+
this.name = "SessionExistsError";
|
|
622
|
+
}
|
|
623
|
+
};
|
|
606
624
|
var OrchestratorPool = class {
|
|
607
625
|
// A daemon serves several workspaces; login selection must never follow
|
|
608
626
|
// whichever session was opened most recently (ADR-0051).
|
|
@@ -668,7 +686,8 @@ var OrchestratorPool = class {
|
|
|
668
686
|
this.runner = deps.runner ?? new core.StructuredRunner();
|
|
669
687
|
this.suppliedRunnerInstallation = deps.runnerInstallation;
|
|
670
688
|
this.runnerInstallation = deps.runnerInstallation ?? new core.RunnerInstallation(this.registry, void 0, void 0, {
|
|
671
|
-
|
|
689
|
+
// A workspace's view (installationFor) asks this for its own env.
|
|
690
|
+
env: (workspace) => core.workspaceEnvOf(workspace ?? process.cwd()),
|
|
672
691
|
workspace: () => process.cwd()
|
|
673
692
|
});
|
|
674
693
|
this.suppliedModelResolver = deps.modelResolver !== void 0;
|
|
@@ -1342,9 +1361,11 @@ var OrchestratorPool = class {
|
|
|
1342
1361
|
return this.modelResolver.withRunnerEnv(key, async () => ({ ...process.env, ...await core.workspaceEnvOf(key) }));
|
|
1343
1362
|
}
|
|
1344
1363
|
/**
|
|
1345
|
-
* The probe that judges a login for `workspace`, cached so its
|
|
1346
|
-
*
|
|
1347
|
-
*
|
|
1364
|
+
* The probe that judges a login for `workspace`, cached so its auth
|
|
1365
|
+
* verdicts survive between runner-list refreshes. Without a workspace the
|
|
1366
|
+
* daemon's cwd is what the request would plan with anyway. A view of the
|
|
1367
|
+
* daemon's own probe: whether a CLI is installed is the host's, so one
|
|
1368
|
+
* `--version` answers detection and every workspace's list alike.
|
|
1348
1369
|
*/
|
|
1349
1370
|
installationFor(workspace) {
|
|
1350
1371
|
if (this.suppliedRunnerInstallation) return this.suppliedRunnerInstallation;
|
|
@@ -1352,7 +1373,8 @@ var OrchestratorPool = class {
|
|
|
1352
1373
|
const key = path.resolve(workspace);
|
|
1353
1374
|
let installation = this.workspaceInstallations.get(key);
|
|
1354
1375
|
if (!installation) {
|
|
1355
|
-
|
|
1376
|
+
const host = this.runnerInstallation;
|
|
1377
|
+
installation = host instanceof core.RunnerInstallation ? host.at(key) : new core.RunnerInstallation(this.registry, void 0, void 0, {
|
|
1356
1378
|
env: () => core.workspaceEnvOf(key),
|
|
1357
1379
|
workspace: () => key
|
|
1358
1380
|
});
|
|
@@ -1366,41 +1388,43 @@ var OrchestratorPool = class {
|
|
|
1366
1388
|
* runner can't be spawned. `workspace` names whose account the auth verdict
|
|
1367
1389
|
* is about; without it the daemon's cwd stands in.
|
|
1368
1390
|
*/
|
|
1369
|
-
async getInstalledRunners(workspace, { recheck = [] } = {}) {
|
|
1391
|
+
async getInstalledRunners(workspace, { recheck = [], cached: cached2 = false } = {}) {
|
|
1370
1392
|
const check = this.signInCheck(workspace);
|
|
1371
1393
|
await Promise.all(recheck.filter((runner) => this.registry.getManifest(runner)).map((runner) => core.recheckRunnerSignIn(runner, check)));
|
|
1372
|
-
await this.codexSandbox.refresh();
|
|
1373
1394
|
const installation = this.installationFor(workspace);
|
|
1374
|
-
|
|
1375
|
-
|
|
1395
|
+
if (!cached2) {
|
|
1396
|
+
await this.codexSandbox.refresh();
|
|
1397
|
+
for (const probe of /* @__PURE__ */ new Set([installation, this.runnerInstallation])) probe.refresh?.();
|
|
1398
|
+
}
|
|
1399
|
+
const detected = cached2 ? core.installedPlannerDetected() : this.detectInstalledPlanner();
|
|
1400
|
+
const runners = this.registry.list();
|
|
1401
|
+
const judged = installation.filterInstalled(runners.map((p) => p.manifest.name)).then((installed) => {
|
|
1402
|
+
const installedIds = new Set(installed);
|
|
1403
|
+
return Promise.all(runners.filter((p) => installedIds.has(p.manifest.name)).map(async (p) => ({ p, usability: await installation.runnerUsability(p.manifest.name) })));
|
|
1404
|
+
});
|
|
1405
|
+
judged.catch(() => void 0);
|
|
1406
|
+
await detected;
|
|
1376
1407
|
const config = new WebConfig({ enabledRunners: this.enabledRunnerOverride() });
|
|
1377
1408
|
const enabled = new Set(config.enabledRunners);
|
|
1378
1409
|
const unlisted = this.resolverFor(workspace).getRunnerUnlisted();
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
readiness: core.runnerReadiness(usability, unlisted[p.manifest.name]),
|
|
1398
|
-
plans: core.runnerPlans(p.manifest.name),
|
|
1399
|
-
...p.manifest.account ? { account: { runner: p.manifest.account.runner, id: p.manifest.account.id, runnerId: p.manifest.name, label: p.manifest.account.label } } : {},
|
|
1400
|
-
...provider ? { provider } : {}
|
|
1401
|
-
};
|
|
1402
|
-
})
|
|
1403
|
-
);
|
|
1410
|
+
return (await judged).map(({ p, usability }) => {
|
|
1411
|
+
const { usable, reason, auth, version } = usability;
|
|
1412
|
+
const provider = core.inProcessProvider(p.manifest);
|
|
1413
|
+
return {
|
|
1414
|
+
id: p.manifest.name,
|
|
1415
|
+
name: p.manifest.displayName,
|
|
1416
|
+
enabled: enabled.has(p.manifest.name),
|
|
1417
|
+
...usable ? {} : { usable: false, ...reason ? { reason } : {} },
|
|
1418
|
+
...auth ? { auth } : {},
|
|
1419
|
+
...version ? { version } : {},
|
|
1420
|
+
// Read from the same record and discovery answer the write checks
|
|
1421
|
+
// read (`refuseBlockedRunner`), so the list and the refusal agree.
|
|
1422
|
+
readiness: core.runnerReadiness(usability, unlisted[p.manifest.name]),
|
|
1423
|
+
plans: core.runnerPlans(p.manifest.name),
|
|
1424
|
+
...p.manifest.account ? { account: { runner: p.manifest.account.runner, id: p.manifest.account.id, runnerId: p.manifest.name, label: p.manifest.account.label } } : {},
|
|
1425
|
+
...provider ? { provider } : {}
|
|
1426
|
+
};
|
|
1427
|
+
});
|
|
1404
1428
|
}
|
|
1405
1429
|
async generatePlan(sessionId, goal, runners, workspace, modelOverride) {
|
|
1406
1430
|
const opening = this.openPlanningSession(sessionId, runners, workspace, modelOverride);
|
|
@@ -1511,6 +1535,7 @@ var OrchestratorPool = class {
|
|
|
1511
1535
|
}
|
|
1512
1536
|
}
|
|
1513
1537
|
async enableRunner(id, enabled, workspace) {
|
|
1538
|
+
if (this.enabledRunnerOverride() === void 0) await core.installedPlannerDetected();
|
|
1514
1539
|
const on = new WebConfig({ enabledRunners: this.enabledRunnerOverride() }).enabledRunners.includes(id);
|
|
1515
1540
|
if (enabled && !on) await this.refuseBlockedRunner(id, workspace);
|
|
1516
1541
|
this.setRunnerEnabled(id, enabled);
|
|
@@ -1568,6 +1593,7 @@ var OrchestratorPool = class {
|
|
|
1568
1593
|
* assistant message lives in conversationHistory).
|
|
1569
1594
|
*/
|
|
1570
1595
|
async startPlanning(sessionId, goal, runners, workspace, modelOverride, options) {
|
|
1596
|
+
if (!this.live(sessionId, workspace) && core.hasSavedSession(sessionId, workspace)) throw new SessionExistsError(sessionId);
|
|
1571
1597
|
const opening = this.openPlanningSession(sessionId, runners, workspace, modelOverride);
|
|
1572
1598
|
const session = opening instanceof Promise ? await opening : opening;
|
|
1573
1599
|
return this.firstTurn(sessionId, session, () => session.startPlanning(goal, runners, options));
|
|
@@ -1846,6 +1872,7 @@ function classify(err) {
|
|
|
1846
1872
|
if (err instanceof ChildNotFoundError) return { status: 404, code: "child_not_found" };
|
|
1847
1873
|
if (err instanceof core.SessionHeldError) return { status: 409, code: "session_held" };
|
|
1848
1874
|
if (err instanceof SessionOpenElsewhereError) return { status: 409, code: "refused" };
|
|
1875
|
+
if (err instanceof SessionExistsError) return { status: 409, code: "session_exists" };
|
|
1849
1876
|
if (err instanceof core.RunnerAccountError) return { status: err.status, code: err.status === 404 ? "account_not_found" : "refused" };
|
|
1850
1877
|
if (err instanceof core.NoPlanError) return { status: 400, code: "no_plan" };
|
|
1851
1878
|
if (err instanceof core.AlreadyExecutingError) return { status: 409, code: "already_executing" };
|
|
@@ -2486,7 +2513,9 @@ function runnersRoute(pool) {
|
|
|
2486
2513
|
try {
|
|
2487
2514
|
const workspace = c.req.query("workspace");
|
|
2488
2515
|
const recheck = c.req.query("recheck")?.split(",").filter(Boolean);
|
|
2489
|
-
const
|
|
2516
|
+
const cached2 = c.req.query("cached") === "1";
|
|
2517
|
+
const options = { ...recheck?.length ? { recheck } : {}, ...cached2 ? { cached: cached2 } : {} };
|
|
2518
|
+
const runners = await pool.getInstalledRunners(workspace, ...Object.keys(options).length ? [options] : []);
|
|
2490
2519
|
await pool.discoverPlannerCatalogs(void 0, workspace);
|
|
2491
2520
|
const state = pool.getRunnerState(workspace);
|
|
2492
2521
|
return c.json({
|
|
@@ -2499,7 +2528,6 @@ function runnersRoute(pool) {
|
|
|
2499
2528
|
});
|
|
2500
2529
|
router.put("/:id", async (c) => {
|
|
2501
2530
|
try {
|
|
2502
|
-
await core.installedPlannerDetected();
|
|
2503
2531
|
const id = c.req.param("id");
|
|
2504
2532
|
const { enabled } = await jsonObject(c);
|
|
2505
2533
|
if (typeof enabled !== "boolean") return refuse(c, 400, "enabled must be true or false");
|
|
@@ -2693,7 +2721,7 @@ function settingsRoute(pool) {
|
|
|
2693
2721
|
});
|
|
2694
2722
|
router.get("/", async (c) => {
|
|
2695
2723
|
try {
|
|
2696
|
-
await core.installedPlannerDetected();
|
|
2724
|
+
if (!core.isPlannerBackend(process.env.AI_PROVIDER ?? "")) await core.installedPlannerDetected();
|
|
2697
2725
|
const sessionId = c.req.query("sessionId") || void 0;
|
|
2698
2726
|
const workspace = c.req.query("workspace") || void 0;
|
|
2699
2727
|
await pool.discoverPlannerCatalogs(sessionId, workspace);
|
|
@@ -3314,6 +3342,7 @@ function runDaemon(args) {
|
|
|
3314
3342
|
let ownsPidFile = false;
|
|
3315
3343
|
core.processLeaseHost().describe(daemonHostKind(args, port));
|
|
3316
3344
|
loadSavedCredentials();
|
|
3345
|
+
loadSavedPlannerChoice();
|
|
3317
3346
|
const pool = new OrchestratorPool({ runner: new core.StructuredRunner() });
|
|
3318
3347
|
void pool.detectInstalledPlanner();
|
|
3319
3348
|
const server = http.createServer();
|