@ordewell/web 0.15.6 → 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 +139 -47
- package/dist/server/main.js.map +1 -1
- package/package.json +2 -2
package/dist/server/main.js
CHANGED
|
@@ -615,6 +615,20 @@ var SessionOpenElsewhereError = class extends Error {
|
|
|
615
615
|
this.name = "SessionOpenElsewhereError";
|
|
616
616
|
}
|
|
617
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
|
+
};
|
|
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
|
+
}
|
|
618
632
|
var OrchestratorPool = class {
|
|
619
633
|
// A daemon serves several workspaces; login selection must never follow
|
|
620
634
|
// whichever session was opened most recently (ADR-0051).
|
|
@@ -1199,7 +1213,7 @@ var OrchestratorPool = class {
|
|
|
1199
1213
|
}
|
|
1200
1214
|
}),
|
|
1201
1215
|
catalogs: this.resolverFor(workspace),
|
|
1202
|
-
refuseBlockedRunner: (runner) => this.refuseBlockedRunner(runner, workspace)
|
|
1216
|
+
refuseBlockedRunner: (runner, askedSince) => this.refuseBlockedRunner(runner, workspace, askedSince)
|
|
1203
1217
|
};
|
|
1204
1218
|
}
|
|
1205
1219
|
/**
|
|
@@ -1290,20 +1304,29 @@ var OrchestratorPool = class {
|
|
|
1290
1304
|
* follows the `CLAUDE_CONFIG_DIR` that workspace's environment sets.
|
|
1291
1305
|
* Without a workspace the daemon's cwd stands in.
|
|
1292
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
|
+
*
|
|
1293
1310
|
* `cached` answers from what discovery already holds, spawning no runner's
|
|
1294
1311
|
* CLI and fetching no catalog: a runner never discovered lists nothing. A
|
|
1295
1312
|
* read that only flags assignments asks this way, since one cold or broken
|
|
1296
1313
|
* CLI (an `opencode` that cannot start its service fails only after tens of
|
|
1297
1314
|
* seconds) would otherwise hold it up, as `SessionCatalog.scope()` is never
|
|
1298
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.
|
|
1299
1320
|
*/
|
|
1300
|
-
async getProviderModels(workspace, { cached: cached2 = false } = {}) {
|
|
1321
|
+
async getProviderModels(workspace, { cached: cached2 = false, refresh = false, withinMs } = {}) {
|
|
1301
1322
|
const config = new WebConfig();
|
|
1302
1323
|
const resolver = this.resolverFor(workspace);
|
|
1324
|
+
if (refresh && !cached2) resolver.refreshRunnerModels();
|
|
1303
1325
|
const runnerIds = this.registry.list().map((p) => p.manifest.name);
|
|
1304
|
-
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);
|
|
1305
1327
|
const providerErrors = resolver.getDiscoveryErrors();
|
|
1306
1328
|
const runnerErrors = resolver.getRunnerDiscoveryErrors();
|
|
1329
|
+
const plannerErrors = resolver.getPlannerDiscoveryErrors();
|
|
1307
1330
|
const allModels = [];
|
|
1308
1331
|
const seen = /* @__PURE__ */ new Set();
|
|
1309
1332
|
const modelsByRunner = {};
|
|
@@ -1325,18 +1348,40 @@ var OrchestratorPool = class {
|
|
|
1325
1348
|
providers,
|
|
1326
1349
|
orchestratorModels,
|
|
1327
1350
|
providerErrors,
|
|
1328
|
-
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 } : {}
|
|
1329
1358
|
};
|
|
1330
1359
|
}
|
|
1331
|
-
async discoverProviderModels(resolver, runnerIds) {
|
|
1360
|
+
async discoverProviderModels(resolver, runnerIds, withinMs) {
|
|
1332
1361
|
const sandbox = this.codexSandbox.ensure();
|
|
1333
1362
|
sandbox.catch(() => {
|
|
1334
1363
|
});
|
|
1335
|
-
const
|
|
1336
|
-
const
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
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
|
+
};
|
|
1340
1385
|
}
|
|
1341
1386
|
getRunnerState(workspace) {
|
|
1342
1387
|
const config = this.plannerConfig(void 0, workspace);
|
|
@@ -1382,29 +1427,65 @@ var OrchestratorPool = class {
|
|
|
1382
1427
|
* runner can't be spawned. `workspace` names whose account the auth verdict
|
|
1383
1428
|
* is about; without it the daemon's cwd stands in.
|
|
1384
1429
|
*/
|
|
1385
|
-
async getInstalledRunners(workspace,
|
|
1386
|
-
|
|
1387
|
-
|
|
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) {
|
|
1388
1458
|
const installation = this.installationFor(workspace);
|
|
1389
|
-
if (!cached2) {
|
|
1390
|
-
await this.codexSandbox.refresh();
|
|
1391
|
-
for (const probe of /* @__PURE__ */ new Set([installation, this.runnerInstallation])) probe.refresh?.();
|
|
1392
|
-
}
|
|
1393
|
-
const detected = cached2 ? core.installedPlannerDetected() : this.detectInstalledPlanner();
|
|
1394
1459
|
const runners = this.registry.list();
|
|
1395
|
-
const judged =
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
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);
|
|
1401
1480
|
const config = new WebConfig({ enabledRunners: this.enabledRunnerOverride() });
|
|
1402
1481
|
const enabled = new Set(config.enabledRunners);
|
|
1403
1482
|
const unlisted = this.resolverFor(workspace).getRunnerUnlisted();
|
|
1404
|
-
|
|
1483
|
+
const listed = runners.flatMap((p) => {
|
|
1484
|
+
const usability = judged.get(p.manifest.name);
|
|
1485
|
+
if (!usability) return [];
|
|
1405
1486
|
const { usable, reason, auth, version } = usability;
|
|
1406
1487
|
const provider = core.inProcessProvider(p.manifest);
|
|
1407
|
-
return {
|
|
1488
|
+
return [{
|
|
1408
1489
|
id: p.manifest.name,
|
|
1409
1490
|
name: p.manifest.displayName,
|
|
1410
1491
|
enabled: enabled.has(p.manifest.name),
|
|
@@ -1417,8 +1498,9 @@ var OrchestratorPool = class {
|
|
|
1417
1498
|
plans: core.runnerPlans(p.manifest.name),
|
|
1418
1499
|
...p.manifest.account ? { account: { runner: p.manifest.account.runner, id: p.manifest.account.id, runnerId: p.manifest.name, label: p.manifest.account.label } } : {},
|
|
1419
1500
|
...provider ? { provider } : {}
|
|
1420
|
-
};
|
|
1501
|
+
}];
|
|
1421
1502
|
});
|
|
1503
|
+
return { runners: listed, pending: runners.map((p) => p.manifest.name).filter((id) => !judged.has(id)) };
|
|
1422
1504
|
}
|
|
1423
1505
|
async generatePlan(sessionId, goal, runners, workspace, modelOverride) {
|
|
1424
1506
|
const opening = this.openPlanningSession(sessionId, runners, workspace, modelOverride);
|
|
@@ -1434,13 +1516,14 @@ var OrchestratorPool = class {
|
|
|
1434
1516
|
* the caller's to pass here, and an unusable runner is refused at its start,
|
|
1435
1517
|
* as before.
|
|
1436
1518
|
*/
|
|
1437
|
-
async refuseBlockedRunner(runner, workspace) {
|
|
1519
|
+
async refuseBlockedRunner(runner, workspace, askedSince) {
|
|
1438
1520
|
const manifest = this.registry.getManifest(runner);
|
|
1439
1521
|
if (!manifest) return;
|
|
1440
1522
|
const resolver = this.resolverFor(workspace);
|
|
1441
1523
|
await core.refuseBlockedPick(runner, manifest.displayName, {
|
|
1442
1524
|
...this.signInCheck(workspace),
|
|
1443
1525
|
...workspace !== void 0 ? { workspace } : {},
|
|
1526
|
+
...askedSince !== void 0 ? { askedSince } : {},
|
|
1444
1527
|
unlisted: () => resolver.getRunnerUnlisted()
|
|
1445
1528
|
});
|
|
1446
1529
|
}
|
|
@@ -1587,6 +1670,7 @@ var OrchestratorPool = class {
|
|
|
1587
1670
|
* assistant message lives in conversationHistory).
|
|
1588
1671
|
*/
|
|
1589
1672
|
async startPlanning(sessionId, goal, runners, workspace, modelOverride, options) {
|
|
1673
|
+
if (!this.live(sessionId, workspace) && core.hasSavedSession(sessionId, workspace)) throw new SessionExistsError(sessionId);
|
|
1590
1674
|
const opening = this.openPlanningSession(sessionId, runners, workspace, modelOverride);
|
|
1591
1675
|
const session = opening instanceof Promise ? await opening : opening;
|
|
1592
1676
|
return this.firstTurn(sessionId, session, () => session.startPlanning(goal, runners, options));
|
|
@@ -1865,6 +1949,7 @@ function classify(err) {
|
|
|
1865
1949
|
if (err instanceof ChildNotFoundError) return { status: 404, code: "child_not_found" };
|
|
1866
1950
|
if (err instanceof core.SessionHeldError) return { status: 409, code: "session_held" };
|
|
1867
1951
|
if (err instanceof SessionOpenElsewhereError) return { status: 409, code: "refused" };
|
|
1952
|
+
if (err instanceof SessionExistsError) return { status: 409, code: "session_exists" };
|
|
1868
1953
|
if (err instanceof core.RunnerAccountError) return { status: err.status, code: err.status === 404 ? "account_not_found" : "refused" };
|
|
1869
1954
|
if (err instanceof core.NoPlanError) return { status: 400, code: "no_plan" };
|
|
1870
1955
|
if (err instanceof core.AlreadyExecutingError) return { status: 409, code: "already_executing" };
|
|
@@ -2499,6 +2584,26 @@ function plansRoute(pool) {
|
|
|
2499
2584
|
});
|
|
2500
2585
|
return router;
|
|
2501
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;
|
|
2502
2607
|
function runnersRoute(pool) {
|
|
2503
2608
|
const router = new hono.Hono();
|
|
2504
2609
|
router.get("/", async (c) => {
|
|
@@ -2506,14 +2611,13 @@ function runnersRoute(pool) {
|
|
|
2506
2611
|
const workspace = c.req.query("workspace");
|
|
2507
2612
|
const recheck = c.req.query("recheck")?.split(",").filter(Boolean);
|
|
2508
2613
|
const cached2 = c.req.query("cached") === "1";
|
|
2509
|
-
const
|
|
2510
|
-
const
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
runners,
|
|
2515
|
-
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 } : {}
|
|
2516
2619
|
});
|
|
2620
|
+
return c.json(list);
|
|
2517
2621
|
} catch (err) {
|
|
2518
2622
|
return failure(c, err, "list runners");
|
|
2519
2623
|
}
|
|
@@ -2598,18 +2702,6 @@ function skillsRoute() {
|
|
|
2598
2702
|
});
|
|
2599
2703
|
return router;
|
|
2600
2704
|
}
|
|
2601
|
-
function modelsRoute(pool) {
|
|
2602
|
-
const router = new hono.Hono();
|
|
2603
|
-
router.get("/", async (c) => {
|
|
2604
|
-
try {
|
|
2605
|
-
const result = await pool.getProviderModels(c.req.query("workspace"), { cached: c.req.query("cached") === "1" });
|
|
2606
|
-
return c.json(result);
|
|
2607
|
-
} catch (err) {
|
|
2608
|
-
return failure(c, err, "list models");
|
|
2609
|
-
}
|
|
2610
|
-
});
|
|
2611
|
-
return router;
|
|
2612
|
-
}
|
|
2613
2705
|
function workspacesRoute(pool) {
|
|
2614
2706
|
const router = new hono.Hono();
|
|
2615
2707
|
router.get("/isolation-preview", async (c) => {
|