@try-works/dsh-minimal-router 0.2.8 → 0.2.10
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 +54 -12
- 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 ? "1dbd2458264821f73fdb071091ded379e8ee44725853e8bd4ca9d76816f7aaa0" : "";
|
|
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 = "1dbd2458264821f73fdb071091ded379e8ee44725853e8bd4ca9d76816f7aaa0"
|
package/lib/index.js
CHANGED
|
@@ -1485,23 +1485,65 @@ export function apply(ctx, config = {}) {
|
|
|
1485
1485
|
// the session header carries no title. Read it defensively and cache by
|
|
1486
1486
|
// mtime so the 5 s refresh does not re-parse unchanged files.
|
|
1487
1487
|
const titleCache = new Map()
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
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
|
+
// The live path first: DSH's own projection registry already holds the folded
|
|
1510
|
+
// title for an attached session, so it needs no file layout at all.
|
|
1511
|
+
const liveTitleOf = (sessionId) => {
|
|
1491
1512
|
try {
|
|
1492
|
-
const
|
|
1493
|
-
const
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
const
|
|
1497
|
-
const
|
|
1498
|
-
|
|
1499
|
-
titleCache.set(sessionId, { mtimeMs: stat.mtimeMs, title: title !== null && title.length > 0 ? title : null })
|
|
1500
|
-
return titleCache.get(sessionId).title
|
|
1513
|
+
const sessions = typeof ctx.get === "function" ? ctx.get("sessions") : undefined
|
|
1514
|
+
const projections = typeof ctx.get === "function" ? ctx.get("sessionProjections") : undefined
|
|
1515
|
+
const session = typeof sessions?.get === "function" ? sessions.get(sessionId) : undefined
|
|
1516
|
+
if (session === undefined || session === null || typeof projections?.stateOf !== "function") return null
|
|
1517
|
+
const state = projections.stateOf(session, "title")
|
|
1518
|
+
const text = typeof state === "string" ? state.trim().replace(/\s+/gu, " ") : ""
|
|
1519
|
+
return text.length === 0 ? null : text.length > 72 ? text.slice(0, 72).trimEnd() + "…" : text
|
|
1501
1520
|
} catch {
|
|
1502
1521
|
return null
|
|
1503
1522
|
}
|
|
1504
1523
|
}
|
|
1524
|
+
const titleOfSession = (sessionId) => {
|
|
1525
|
+
if (typeof sessionId !== "string" || sessionId.length === 0) return null
|
|
1526
|
+
const live = liveTitleOf(sessionId)
|
|
1527
|
+
if (live !== null) return live
|
|
1528
|
+
const tried = []
|
|
1529
|
+
for (const root of storageRoots()) {
|
|
1530
|
+
const file = path.join(root, "session_projcache", "sessions", sessionId + ".json")
|
|
1531
|
+
tried.push(file)
|
|
1532
|
+
try {
|
|
1533
|
+
const stat = fs.statSync(file)
|
|
1534
|
+
const cached = titleCache.get(sessionId)
|
|
1535
|
+
if (cached !== undefined && cached.mtimeMs === stat.mtimeMs) return cached.title
|
|
1536
|
+
const doc = JSON.parse(fs.readFileSync(file, "utf8"))
|
|
1537
|
+
const raw = doc?.record?.rows?.title?.val
|
|
1538
|
+
const full = typeof raw === "string" ? raw.trim().replace(/\s+/gu, " ") : null
|
|
1539
|
+
const title = full === null || full.length === 0 ? null : full.length > 72 ? full.slice(0, 72).trimEnd() + "…" : full
|
|
1540
|
+
titleCache.set(sessionId, { mtimeMs: stat.mtimeMs, title })
|
|
1541
|
+
return title
|
|
1542
|
+
} catch {}
|
|
1543
|
+
}
|
|
1544
|
+
noteTitleMiss(sessionId, tried)
|
|
1545
|
+
return null
|
|
1546
|
+
}
|
|
1505
1547
|
const recentSessionRouting = async () => {
|
|
1506
1548
|
const limit = 5
|
|
1507
1549
|
const entries = []
|
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.10",
|
|
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",
|