@ordewell/web 0.15.7 → 0.15.8
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 +131 -47
- package/dist/server/main.js.map +1 -1
- package/package.json +2 -2
package/dist/server/main.js
CHANGED
|
@@ -621,6 +621,14 @@ var SessionExistsError = class extends Error {
|
|
|
621
621
|
this.name = "SessionExistsError";
|
|
622
622
|
}
|
|
623
623
|
};
|
|
624
|
+
async function withinTime(work, ms) {
|
|
625
|
+
let timer;
|
|
626
|
+
const late = new Promise((resolve3) => {
|
|
627
|
+
timer = setTimeout(() => resolve3(void 0), ms);
|
|
628
|
+
});
|
|
629
|
+
work.catch(() => void 0);
|
|
630
|
+
return Promise.race([work, late]).finally(() => clearTimeout(timer));
|
|
631
|
+
}
|
|
624
632
|
var OrchestratorPool = class {
|
|
625
633
|
// A daemon serves several workspaces; login selection must never follow
|
|
626
634
|
// whichever session was opened most recently (ADR-0051).
|
|
@@ -1205,7 +1213,7 @@ var OrchestratorPool = class {
|
|
|
1205
1213
|
}
|
|
1206
1214
|
}),
|
|
1207
1215
|
catalogs: this.resolverFor(workspace),
|
|
1208
|
-
refuseBlockedRunner: (runner) => this.refuseBlockedRunner(runner, workspace)
|
|
1216
|
+
refuseBlockedRunner: (runner, askedSince) => this.refuseBlockedRunner(runner, workspace, askedSince)
|
|
1209
1217
|
};
|
|
1210
1218
|
}
|
|
1211
1219
|
/**
|
|
@@ -1296,20 +1304,29 @@ var OrchestratorPool = class {
|
|
|
1296
1304
|
* follows the `CLAUDE_CONFIG_DIR` that workspace's environment sets.
|
|
1297
1305
|
* Without a workspace the daemon's cwd stands in.
|
|
1298
1306
|
*
|
|
1307
|
+
* A list once discovered is held for the daemon's life, so `refresh`, the
|
|
1308
|
+
* user's own, asks every runner again.
|
|
1309
|
+
*
|
|
1299
1310
|
* `cached` answers from what discovery already holds, spawning no runner's
|
|
1300
1311
|
* CLI and fetching no catalog: a runner never discovered lists nothing. A
|
|
1301
1312
|
* read that only flags assignments asks this way, since one cold or broken
|
|
1302
1313
|
* CLI (an `opencode` that cannot start its service fails only after tens of
|
|
1303
1314
|
* seconds) would otherwise hold it up, as `SessionCatalog.scope()` is never
|
|
1304
1315
|
* held up either.
|
|
1316
|
+
*
|
|
1317
|
+
* `withinMs` bounds the wait for a client that gives up on its read: the
|
|
1318
|
+
* runners still being asked are named in `pendingRunners`, and their
|
|
1319
|
+
* discovery runs on for the next read to find.
|
|
1305
1320
|
*/
|
|
1306
|
-
async getProviderModels(workspace, { cached: cached2 = false } = {}) {
|
|
1321
|
+
async getProviderModels(workspace, { cached: cached2 = false, refresh = false, withinMs } = {}) {
|
|
1307
1322
|
const config = new WebConfig();
|
|
1308
1323
|
const resolver = this.resolverFor(workspace);
|
|
1324
|
+
if (refresh && !cached2) resolver.refreshRunnerModels();
|
|
1309
1325
|
const runnerIds = this.registry.list().map((p) => p.manifest.name);
|
|
1310
|
-
const { runnerModels, orchestratorModels } = cached2 ? { runnerModels: Object.fromEntries(runnerIds.map((id) => [id, resolver.getCachedRunnerModels(id)])), orchestratorModels: resolver.getCachedPickerOptions() } : await this.discoverProviderModels(resolver, runnerIds);
|
|
1326
|
+
const { runnerModels, orchestratorModels, pending } = cached2 ? { runnerModels: Object.fromEntries(runnerIds.map((id) => [id, resolver.getCachedRunnerModels(id)])), orchestratorModels: resolver.getCachedPickerOptions(), pending: [] } : await this.discoverProviderModels(resolver, runnerIds, withinMs);
|
|
1311
1327
|
const providerErrors = resolver.getDiscoveryErrors();
|
|
1312
1328
|
const runnerErrors = resolver.getRunnerDiscoveryErrors();
|
|
1329
|
+
const plannerErrors = resolver.getPlannerDiscoveryErrors();
|
|
1313
1330
|
const allModels = [];
|
|
1314
1331
|
const seen = /* @__PURE__ */ new Set();
|
|
1315
1332
|
const modelsByRunner = {};
|
|
@@ -1331,18 +1348,40 @@ var OrchestratorPool = class {
|
|
|
1331
1348
|
providers,
|
|
1332
1349
|
orchestratorModels,
|
|
1333
1350
|
providerErrors,
|
|
1334
|
-
runnerErrors
|
|
1351
|
+
runnerErrors: {
|
|
1352
|
+
...runnerErrors,
|
|
1353
|
+
// A runner not asked yet, the vendor catalogs still loading ahead of it, has said nothing of itself.
|
|
1354
|
+
...Object.fromEntries(pending.filter((id) => !runnerErrors[id] && modelsByRunner[id]?.length === 0).map((id) => [id, core.unlistedRunnerMessage(this.registry.getManifest(id)?.displayName ?? id, "pending")]))
|
|
1355
|
+
},
|
|
1356
|
+
...Object.keys(plannerErrors).length > 0 ? { plannerErrors } : {},
|
|
1357
|
+
...pending.length > 0 ? { pendingRunners: pending } : {}
|
|
1335
1358
|
};
|
|
1336
1359
|
}
|
|
1337
|
-
async discoverProviderModels(resolver, runnerIds) {
|
|
1360
|
+
async discoverProviderModels(resolver, runnerIds, withinMs) {
|
|
1338
1361
|
const sandbox = this.codexSandbox.ensure();
|
|
1339
1362
|
sandbox.catch(() => {
|
|
1340
1363
|
});
|
|
1341
|
-
const
|
|
1342
|
-
const
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1364
|
+
const answered = {};
|
|
1365
|
+
const discovery = (async () => {
|
|
1366
|
+
const providerLists = await resolver.refresh();
|
|
1367
|
+
const asks = withinMs === void 0 ? [runnerIds] : runnerIds.map((id) => [id]);
|
|
1368
|
+
await Promise.all([
|
|
1369
|
+
...asks.map(async (ids) => {
|
|
1370
|
+
const found = await resolver.modelsForRunners(ids);
|
|
1371
|
+
for (const id of ids) answered[id] = found[id] ?? [];
|
|
1372
|
+
}),
|
|
1373
|
+
sandbox
|
|
1374
|
+
]);
|
|
1375
|
+
const orchestratorModels2 = await resolver.pickerOptions();
|
|
1376
|
+
this.cachedProviderLists = providerLists;
|
|
1377
|
+
return orchestratorModels2;
|
|
1378
|
+
})();
|
|
1379
|
+
const orchestratorModels = withinMs === void 0 ? await discovery : await withinTime(discovery, withinMs);
|
|
1380
|
+
return {
|
|
1381
|
+
runnerModels: Object.fromEntries(runnerIds.map((id) => [id, answered[id] ?? resolver.getCachedRunnerModels(id)])),
|
|
1382
|
+
orchestratorModels: orchestratorModels ?? resolver.getCachedPickerOptions(),
|
|
1383
|
+
pending: runnerIds.filter((id) => answered[id] === void 0)
|
|
1384
|
+
};
|
|
1346
1385
|
}
|
|
1347
1386
|
getRunnerState(workspace) {
|
|
1348
1387
|
const config = this.plannerConfig(void 0, workspace);
|
|
@@ -1388,29 +1427,65 @@ var OrchestratorPool = class {
|
|
|
1388
1427
|
* runner can't be spawned. `workspace` names whose account the auth verdict
|
|
1389
1428
|
* is about; without it the daemon's cwd stands in.
|
|
1390
1429
|
*/
|
|
1391
|
-
async getInstalledRunners(workspace,
|
|
1392
|
-
|
|
1393
|
-
|
|
1430
|
+
async getInstalledRunners(workspace, options = {}) {
|
|
1431
|
+
return (await this.listRunners(workspace, options)).runners;
|
|
1432
|
+
}
|
|
1433
|
+
/**
|
|
1434
|
+
* The runner list as `GET /api/runners` answers it: the installed runners,
|
|
1435
|
+
* and the planner model judged against the catalog the settings read
|
|
1436
|
+
* consults ({@link discoverPlannerCatalogs}).
|
|
1437
|
+
*
|
|
1438
|
+
* `withinMs` bounds the wait for a surface that gives up on its read, as a
|
|
1439
|
+
* partial model catalog does: on a slow machine one CLI's `--version` or
|
|
1440
|
+
* sign-in can outlast it. The answer then lists every runner judged so far
|
|
1441
|
+
* and names the others in `pendingRunners`; their probes run on, into the
|
|
1442
|
+
* caches a `cached` read answers from, so the surface reads again rather
|
|
1443
|
+
* than the user pressing Retry.
|
|
1444
|
+
*/
|
|
1445
|
+
async getRunnerList(workspace, { withinMs, ...options } = {}) {
|
|
1446
|
+
const started = Date.now();
|
|
1447
|
+
const { runners, pending } = await this.listRunners(workspace, options, withinMs);
|
|
1448
|
+
const catalogs = this.discoverPlannerCatalogs(void 0, workspace);
|
|
1449
|
+
if (withinMs === void 0) await catalogs;
|
|
1450
|
+
else await withinTime(catalogs, Math.max(0, withinMs - (Date.now() - started)));
|
|
1451
|
+
return {
|
|
1452
|
+
runners,
|
|
1453
|
+
orchestratorModel: this.getRunnerState(workspace).orchestratorModel,
|
|
1454
|
+
...pending.length > 0 ? { pendingRunners: pending } : {}
|
|
1455
|
+
};
|
|
1456
|
+
}
|
|
1457
|
+
async listRunners(workspace, { recheck = [], cached: cached2 = false }, withinMs) {
|
|
1394
1458
|
const installation = this.installationFor(workspace);
|
|
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
1459
|
const runners = this.registry.list();
|
|
1401
|
-
const judged =
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1460
|
+
const judged = /* @__PURE__ */ new Map();
|
|
1461
|
+
const sweep = (async () => {
|
|
1462
|
+
const check = this.signInCheck(workspace);
|
|
1463
|
+
await Promise.all(recheck.filter((runner) => this.registry.getManifest(runner)).map((runner) => core.recheckRunnerSignIn(runner, check)));
|
|
1464
|
+
if (!cached2) {
|
|
1465
|
+
await this.codexSandbox.refresh();
|
|
1466
|
+
for (const probe of /* @__PURE__ */ new Set([installation, this.runnerInstallation])) probe.refresh?.();
|
|
1467
|
+
}
|
|
1468
|
+
const detected = cached2 ? core.installedPlannerDetected() : this.detectInstalledPlanner();
|
|
1469
|
+
const judging = Promise.all(runners.map(async (p) => {
|
|
1470
|
+
const id = p.manifest.name;
|
|
1471
|
+
const installed = (await installation.filterInstalled([id])).includes(id);
|
|
1472
|
+
judged.set(id, installed ? await installation.runnerUsability(id) : null);
|
|
1473
|
+
}));
|
|
1474
|
+
judging.catch(() => void 0);
|
|
1475
|
+
await detected;
|
|
1476
|
+
await judging;
|
|
1477
|
+
})();
|
|
1478
|
+
if (withinMs === void 0) await sweep;
|
|
1479
|
+
else await withinTime(sweep, withinMs);
|
|
1407
1480
|
const config = new WebConfig({ enabledRunners: this.enabledRunnerOverride() });
|
|
1408
1481
|
const enabled = new Set(config.enabledRunners);
|
|
1409
1482
|
const unlisted = this.resolverFor(workspace).getRunnerUnlisted();
|
|
1410
|
-
|
|
1483
|
+
const listed = runners.flatMap((p) => {
|
|
1484
|
+
const usability = judged.get(p.manifest.name);
|
|
1485
|
+
if (!usability) return [];
|
|
1411
1486
|
const { usable, reason, auth, version } = usability;
|
|
1412
1487
|
const provider = core.inProcessProvider(p.manifest);
|
|
1413
|
-
return {
|
|
1488
|
+
return [{
|
|
1414
1489
|
id: p.manifest.name,
|
|
1415
1490
|
name: p.manifest.displayName,
|
|
1416
1491
|
enabled: enabled.has(p.manifest.name),
|
|
@@ -1423,8 +1498,9 @@ var OrchestratorPool = class {
|
|
|
1423
1498
|
plans: core.runnerPlans(p.manifest.name),
|
|
1424
1499
|
...p.manifest.account ? { account: { runner: p.manifest.account.runner, id: p.manifest.account.id, runnerId: p.manifest.name, label: p.manifest.account.label } } : {},
|
|
1425
1500
|
...provider ? { provider } : {}
|
|
1426
|
-
};
|
|
1501
|
+
}];
|
|
1427
1502
|
});
|
|
1503
|
+
return { runners: listed, pending: runners.map((p) => p.manifest.name).filter((id) => !judged.has(id)) };
|
|
1428
1504
|
}
|
|
1429
1505
|
async generatePlan(sessionId, goal, runners, workspace, modelOverride) {
|
|
1430
1506
|
const opening = this.openPlanningSession(sessionId, runners, workspace, modelOverride);
|
|
@@ -1440,13 +1516,14 @@ var OrchestratorPool = class {
|
|
|
1440
1516
|
* the caller's to pass here, and an unusable runner is refused at its start,
|
|
1441
1517
|
* as before.
|
|
1442
1518
|
*/
|
|
1443
|
-
async refuseBlockedRunner(runner, workspace) {
|
|
1519
|
+
async refuseBlockedRunner(runner, workspace, askedSince) {
|
|
1444
1520
|
const manifest = this.registry.getManifest(runner);
|
|
1445
1521
|
if (!manifest) return;
|
|
1446
1522
|
const resolver = this.resolverFor(workspace);
|
|
1447
1523
|
await core.refuseBlockedPick(runner, manifest.displayName, {
|
|
1448
1524
|
...this.signInCheck(workspace),
|
|
1449
1525
|
...workspace !== void 0 ? { workspace } : {},
|
|
1526
|
+
...askedSince !== void 0 ? { askedSince } : {},
|
|
1450
1527
|
unlisted: () => resolver.getRunnerUnlisted()
|
|
1451
1528
|
});
|
|
1452
1529
|
}
|
|
@@ -2507,6 +2584,26 @@ function plansRoute(pool) {
|
|
|
2507
2584
|
});
|
|
2508
2585
|
return router;
|
|
2509
2586
|
}
|
|
2587
|
+
var PARTIAL_CATALOG_MS = 8e3;
|
|
2588
|
+
function modelsRoute(pool) {
|
|
2589
|
+
const router = new hono.Hono();
|
|
2590
|
+
router.get("/", async (c) => {
|
|
2591
|
+
try {
|
|
2592
|
+
const result = await pool.getProviderModels(c.req.query("workspace"), {
|
|
2593
|
+
cached: c.req.query("cached") === "1",
|
|
2594
|
+
...c.req.query("refresh") === "1" ? { refresh: true } : {},
|
|
2595
|
+
...c.req.query("partial") === "1" ? { withinMs: PARTIAL_CATALOG_MS } : {}
|
|
2596
|
+
});
|
|
2597
|
+
return c.json(result);
|
|
2598
|
+
} catch (err) {
|
|
2599
|
+
return failure(c, err, "list models");
|
|
2600
|
+
}
|
|
2601
|
+
});
|
|
2602
|
+
return router;
|
|
2603
|
+
}
|
|
2604
|
+
|
|
2605
|
+
// server/routes/runners.ts
|
|
2606
|
+
var PARTIAL_RUNNERS_MS = PARTIAL_CATALOG_MS;
|
|
2510
2607
|
function runnersRoute(pool) {
|
|
2511
2608
|
const router = new hono.Hono();
|
|
2512
2609
|
router.get("/", async (c) => {
|
|
@@ -2514,14 +2611,13 @@ function runnersRoute(pool) {
|
|
|
2514
2611
|
const workspace = c.req.query("workspace");
|
|
2515
2612
|
const recheck = c.req.query("recheck")?.split(",").filter(Boolean);
|
|
2516
2613
|
const cached2 = c.req.query("cached") === "1";
|
|
2517
|
-
const
|
|
2518
|
-
const
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
runners,
|
|
2523
|
-
orchestratorModel: state.orchestratorModel
|
|
2614
|
+
const partial = c.req.query("partial") === "1";
|
|
2615
|
+
const list = await pool.getRunnerList(workspace, {
|
|
2616
|
+
...recheck?.length ? { recheck } : {},
|
|
2617
|
+
...cached2 ? { cached: cached2 } : {},
|
|
2618
|
+
...partial ? { withinMs: PARTIAL_RUNNERS_MS } : {}
|
|
2524
2619
|
});
|
|
2620
|
+
return c.json(list);
|
|
2525
2621
|
} catch (err) {
|
|
2526
2622
|
return failure(c, err, "list runners");
|
|
2527
2623
|
}
|
|
@@ -2606,18 +2702,6 @@ function skillsRoute() {
|
|
|
2606
2702
|
});
|
|
2607
2703
|
return router;
|
|
2608
2704
|
}
|
|
2609
|
-
function modelsRoute(pool) {
|
|
2610
|
-
const router = new hono.Hono();
|
|
2611
|
-
router.get("/", async (c) => {
|
|
2612
|
-
try {
|
|
2613
|
-
const result = await pool.getProviderModels(c.req.query("workspace"), { cached: c.req.query("cached") === "1" });
|
|
2614
|
-
return c.json(result);
|
|
2615
|
-
} catch (err) {
|
|
2616
|
-
return failure(c, err, "list models");
|
|
2617
|
-
}
|
|
2618
|
-
});
|
|
2619
|
-
return router;
|
|
2620
|
-
}
|
|
2621
2705
|
function workspacesRoute(pool) {
|
|
2622
2706
|
const router = new hono.Hono();
|
|
2623
2707
|
router.get("/isolation-preview", async (c) => {
|