@try-works/dsh-minimal-router 0.2.7 → 0.2.9
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/client/index.js +1 -1
- package/lib/build-id.js +1 -1
- package/lib/index.js +55 -3
- package/package.json +1 -1
package/client/index.js
CHANGED
|
@@ -66593,7 +66593,7 @@ if (typeof document !== "undefined" && document.head !== null) {
|
|
|
66593
66593
|
}
|
|
66594
66594
|
|
|
66595
66595
|
// packages/plugin/client/build-id.ts
|
|
66596
|
-
var clientBuildId = true ? "
|
|
66596
|
+
var clientBuildId = true ? "4a126a53d02583520651b76b4b49b45e5134698c4a06c6bba43972cb6e7cde36" : "";
|
|
66597
66597
|
var compareBuildIds = (hostId, clientId) => {
|
|
66598
66598
|
const host = typeof hostId === "string" && hostId.length > 0 ? hostId : null;
|
|
66599
66599
|
const client = typeof clientId === "string" && clientId.length > 0 ? clientId : null;
|
package/lib/build-id.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// GENERATED by scripts/build-id.mjs - do not edit by hand.
|
|
2
2
|
// sha256 over the canonical 19-file list (11 plugin lib + 8 domain contract
|
|
3
3
|
// sources), so a domain-contract change moves the id too (DEC-30-01).
|
|
4
|
-
export const buildId = "
|
|
4
|
+
export const buildId = "4a126a53d02583520651b76b4b49b45e5134698c4a06c6bba43972cb6e7cde36"
|
package/lib/index.js
CHANGED
|
@@ -1479,6 +1479,54 @@ export function apply(ctx, config = {}) {
|
|
|
1479
1479
|
}
|
|
1480
1480
|
void refreshRecentSessions()
|
|
1481
1481
|
}
|
|
1482
|
+
// F-37-52 (Owner): a session row shows the session's TITLE, not its backend
|
|
1483
|
+
// id. DSH keeps the generated title in its session projection cache
|
|
1484
|
+
// (<storages>/session_projcache/sessions/<id>.json -> record.rows.title.val);
|
|
1485
|
+
// the session header carries no title. Read it defensively and cache by
|
|
1486
|
+
// mtime so the 5 s refresh does not re-parse unchanged files.
|
|
1487
|
+
const titleCache = new Map()
|
|
1488
|
+
// Try every storage root DSH may use; whichever holds the session's projection
|
|
1489
|
+
// cache file answers. Misses are recorded so a runtime path/version difference
|
|
1490
|
+
// is measurable instead of guessable.
|
|
1491
|
+
const storageRoots = () => {
|
|
1492
|
+
const roots = [path.dirname(dataDir)]
|
|
1493
|
+
const env = process.env.DSH_STORAGE_DIR
|
|
1494
|
+
if (typeof env === "string" && env.length > 0) roots.push(env)
|
|
1495
|
+
roots.push(path.join(os.homedir(), ".dsh", "storages"))
|
|
1496
|
+
return [...new Set(roots)]
|
|
1497
|
+
}
|
|
1498
|
+
const noteTitleMiss = (sessionId, tried) => {
|
|
1499
|
+
try {
|
|
1500
|
+
const file = path.join(dataDir, "title-misses.jsonl")
|
|
1501
|
+
const size = fs.existsSync(file) ? fs.statSync(file).size : 0
|
|
1502
|
+
if (size > 64 * 1024) return
|
|
1503
|
+
fs.appendFileSync(
|
|
1504
|
+
file,
|
|
1505
|
+
JSON.stringify({ at: new Date().toISOString(), id: sessionId, tried }) + "\n"
|
|
1506
|
+
)
|
|
1507
|
+
} catch {}
|
|
1508
|
+
}
|
|
1509
|
+
const titleOfSession = (sessionId) => {
|
|
1510
|
+
if (typeof sessionId !== "string" || sessionId.length === 0) return null
|
|
1511
|
+
const tried = []
|
|
1512
|
+
for (const root of storageRoots()) {
|
|
1513
|
+
const file = path.join(root, "session_projcache", "sessions", sessionId + ".json")
|
|
1514
|
+
tried.push(file)
|
|
1515
|
+
try {
|
|
1516
|
+
const stat = fs.statSync(file)
|
|
1517
|
+
const cached = titleCache.get(sessionId)
|
|
1518
|
+
if (cached !== undefined && cached.mtimeMs === stat.mtimeMs) return cached.title
|
|
1519
|
+
const doc = JSON.parse(fs.readFileSync(file, "utf8"))
|
|
1520
|
+
const raw = doc?.record?.rows?.title?.val
|
|
1521
|
+
const full = typeof raw === "string" ? raw.trim().replace(/\s+/gu, " ") : null
|
|
1522
|
+
const title = full === null || full.length === 0 ? null : full.length > 72 ? full.slice(0, 72).trimEnd() + "…" : full
|
|
1523
|
+
titleCache.set(sessionId, { mtimeMs: stat.mtimeMs, title })
|
|
1524
|
+
return title
|
|
1525
|
+
} catch {}
|
|
1526
|
+
}
|
|
1527
|
+
noteTitleMiss(sessionId, tried)
|
|
1528
|
+
return null
|
|
1529
|
+
}
|
|
1482
1530
|
const recentSessionRouting = async () => {
|
|
1483
1531
|
const limit = 5
|
|
1484
1532
|
const entries = []
|
|
@@ -1501,7 +1549,8 @@ export function apply(ctx, config = {}) {
|
|
|
1501
1549
|
for (const record of Array.isArray(records) ? records : []) {
|
|
1502
1550
|
const header = record?.header ?? {}
|
|
1503
1551
|
const at = Number.isFinite(header.updatedAt) ? header.updatedAt : header.createdAt
|
|
1504
|
-
|
|
1552
|
+
const headerTitle = typeof header.title === "string" && header.title.length > 0 ? header.title : null
|
|
1553
|
+
push(header.id, headerTitle ?? titleOfSession(header.id), at, record?.live === true)
|
|
1505
1554
|
if (entries.length >= limit) break
|
|
1506
1555
|
}
|
|
1507
1556
|
}
|
|
@@ -1510,7 +1559,7 @@ export function apply(ctx, config = {}) {
|
|
|
1510
1559
|
try {
|
|
1511
1560
|
for (const row of ledgerRows()) {
|
|
1512
1561
|
if (typeof row?.sessionId !== "string") continue
|
|
1513
|
-
push(row.sessionId,
|
|
1562
|
+
push(row.sessionId, titleOfSession(row.sessionId), Date.parse(row.at), false)
|
|
1514
1563
|
if (entries.length >= limit) break
|
|
1515
1564
|
}
|
|
1516
1565
|
} catch {}
|
|
@@ -1532,7 +1581,10 @@ export function apply(ctx, config = {}) {
|
|
|
1532
1581
|
// Owner toggle any of them. The toggle is the same store the model picker
|
|
1533
1582
|
// writes, so the two cannot disagree.
|
|
1534
1583
|
if (typeof sessionId !== "string" || sessionId.length === 0) {
|
|
1535
|
-
|
|
1584
|
+
// Compute on read: the overview reads the cache, but the API is always
|
|
1585
|
+
// current (F-37-52 - a title must not lag a boot by one timer tick).
|
|
1586
|
+
recentSessionsCache = await recentSessionRouting()
|
|
1587
|
+
respondJson(res, 200, { sessions: recentSessionsCache })
|
|
1536
1588
|
return
|
|
1537
1589
|
}
|
|
1538
1590
|
const entry = sessionRouting.get(sessionId)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@try-works/dsh-minimal-router",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"description": "DSH local router plugin: per-session auto-routing between a local engine and remote models, evidence pages, and a plugin-owned engine provider.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "UNLICENSED",
|