ework-web 0.10.21 → 0.10.23
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/package.json +1 -1
- package/src/coordination.ts +35 -0
- package/src/db.ts +31 -11
- package/src/index.ts +3 -2
- package/src/opencode.ts +1 -0
- package/src/views/sessionLog.ts +15 -1
package/package.json
CHANGED
package/src/coordination.ts
CHANGED
|
@@ -68,3 +68,38 @@ export async function listAllDaemons(): Promise<DaemonDetail[]> {
|
|
|
68
68
|
return [];
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
+
|
|
72
|
+
export interface SessionDaemonInfo {
|
|
73
|
+
daemonId: number;
|
|
74
|
+
displayName: string;
|
|
75
|
+
endpoint: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function getSessionDaemonMap(): Promise<Map<string, SessionDaemonInfo>> {
|
|
79
|
+
try {
|
|
80
|
+
const rows = await getDB().all<{
|
|
81
|
+
opencode_session_id: string;
|
|
82
|
+
daemon_id: number;
|
|
83
|
+
display_name: string | null;
|
|
84
|
+
internal_endpoint: string | null;
|
|
85
|
+
}>(
|
|
86
|
+
`SELECT s.opencode_session_id, d.id AS daemon_id, d.display_name, d.internal_endpoint
|
|
87
|
+
FROM {{d_op_sessions}} s
|
|
88
|
+
JOIN {{d_issues}} i ON i.uid = s.issue_id
|
|
89
|
+
LEFT JOIN {{d_daemons}} d ON d.id = i.owner_daemon_id
|
|
90
|
+
WHERE s.opencode_session_id IS NOT NULL AND s.opencode_session_id != ''`,
|
|
91
|
+
);
|
|
92
|
+
const map = new Map<string, SessionDaemonInfo>();
|
|
93
|
+
for (const r of rows) {
|
|
94
|
+
map.set(r.opencode_session_id, {
|
|
95
|
+
daemonId: r.daemon_id,
|
|
96
|
+
displayName: r.display_name ?? `daemon-${r.daemon_id}`,
|
|
97
|
+
endpoint: r.internal_endpoint ?? "",
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return map;
|
|
101
|
+
} catch (e) {
|
|
102
|
+
log.info(`coordination: session-daemon map failed (${e instanceof Error ? e.message : String(e)})`);
|
|
103
|
+
return new Map();
|
|
104
|
+
}
|
|
105
|
+
}
|
package/src/db.ts
CHANGED
|
@@ -375,7 +375,8 @@ class MysqlDriver implements AsyncDatabase {
|
|
|
375
375
|
try {
|
|
376
376
|
await pool.query(stmt);
|
|
377
377
|
} catch (e) {
|
|
378
|
-
|
|
378
|
+
const errno = (e as { errno?: number }).errno;
|
|
379
|
+
if (errno === 1061 || errno === 30000) continue;
|
|
379
380
|
throw e;
|
|
380
381
|
}
|
|
381
382
|
}
|
|
@@ -456,10 +457,17 @@ export function getDB(): AsyncDatabase {
|
|
|
456
457
|
export async function getConfigAll(): Promise<Record<string, string>> {
|
|
457
458
|
try {
|
|
458
459
|
const driver = getDB();
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
460
|
+
try {
|
|
461
|
+
const rows = await driver.all<{ akey: string; value: string }>("SELECT akey, value FROM {{config}}");
|
|
462
|
+
const out: Record<string, string> = {};
|
|
463
|
+
for (const r of rows) out[r.akey] = r.value;
|
|
464
|
+
return out;
|
|
465
|
+
} catch {
|
|
466
|
+
const rows = await driver.all<{ key: string; value: string }>("SELECT key, value FROM {{config}}");
|
|
467
|
+
const out: Record<string, string> = {};
|
|
468
|
+
for (const r of rows) out[r.key] = r.value;
|
|
469
|
+
return out;
|
|
470
|
+
}
|
|
463
471
|
} catch {
|
|
464
472
|
return {};
|
|
465
473
|
}
|
|
@@ -467,13 +475,25 @@ export async function getConfigAll(): Promise<Record<string, string>> {
|
|
|
467
475
|
|
|
468
476
|
export async function setConfig(key: string, value: string): Promise<void> {
|
|
469
477
|
const now = new Date().toISOString();
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
"
|
|
473
|
-
|
|
474
|
-
|
|
478
|
+
try {
|
|
479
|
+
await getDB().run(
|
|
480
|
+
"INSERT INTO {{config}} (akey, value, updated_at) VALUES (?, ?, ?) " +
|
|
481
|
+
"ON CONFLICT(akey) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at",
|
|
482
|
+
[key, value, now]
|
|
483
|
+
);
|
|
484
|
+
} catch {
|
|
485
|
+
await getDB().run(
|
|
486
|
+
"INSERT INTO {{config}} (key, value, updated_at) VALUES (?, ?, ?) " +
|
|
487
|
+
"ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at",
|
|
488
|
+
[key, value, now]
|
|
489
|
+
);
|
|
490
|
+
}
|
|
475
491
|
}
|
|
476
492
|
|
|
477
493
|
export async function deleteConfig(key: string): Promise<void> {
|
|
478
|
-
|
|
494
|
+
try {
|
|
495
|
+
await getDB().run("DELETE FROM {{config}} WHERE akey = ?", [key]);
|
|
496
|
+
} catch {
|
|
497
|
+
await getDB().run("DELETE FROM {{config}} WHERE key = ?", [key]);
|
|
498
|
+
}
|
|
479
499
|
}
|
package/src/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { homedir } from "os";
|
|
|
6
6
|
import { loadConfig, DB_OVERRIDABLE, parseOverride, resolveTtsBackend } from "./config";
|
|
7
7
|
import type { Config } from "./config";
|
|
8
8
|
import { setConfig, initDB, getDB } from "./db";
|
|
9
|
-
import { getActiveDaemons, listAllDaemons } from "./coordination";
|
|
9
|
+
import { getActiveDaemons, listAllDaemons, getSessionDaemonMap } from "./coordination";
|
|
10
10
|
import { testMysqlConnection, migrateSqliteToMysql, writeMysqlEnv, migrateMysqlToSqlite, writeSqliteEnv, migrateDaemonSqliteToMysql, generateMysqlDDL } from "./db-admin";
|
|
11
11
|
import type { MysqlTargetOpts } from "./db-admin";
|
|
12
12
|
import { checkAuth, makeAuthCookieHeader, clearAuthCookieHeader, loginHTML, sanitizeNext, ensureBootstrapAdmin, ensureBootstrapSystem, isReservedSystemLogin } from "./auth";
|
|
@@ -610,7 +610,8 @@ async function handle(req: Request, url: URL, ip: string, ctx: { authed: boolean
|
|
|
610
610
|
if (url.pathname.match(SESSIONS_RE)) {
|
|
611
611
|
const q = url.searchParams.get("q")?.trim() ?? "";
|
|
612
612
|
try {
|
|
613
|
-
const
|
|
613
|
+
const daemonMap = await getSessionDaemonMap();
|
|
614
|
+
const { html: body } = await buildSessionList(opencode, q, daemonMap);
|
|
614
615
|
return html(body);
|
|
615
616
|
} catch (e) {
|
|
616
617
|
return html(errorPage("加载失败", errMsg(e)), e instanceof OpencodeError ? e.status : 502);
|
package/src/opencode.ts
CHANGED
package/src/views/sessionLog.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { OpencodeClientInterface, SessionListItem, SessionExport, SessionMessage, MessagePart, ToolState } from "../opencode";
|
|
2
|
+
import type { SessionDaemonInfo } from "../coordination";
|
|
2
3
|
import { THEME_CSS, escapeHtml, escapeAttr, tabNavHTML } from "../render/layout";
|
|
3
4
|
import { renderMarkdown, linkifySessionIDs, linkifyAbsPaths } from "../render/markdown";
|
|
4
5
|
import { BUILD_ID } from "../build";
|
|
@@ -8,8 +9,19 @@ import { homedir } from "os";
|
|
|
8
9
|
|
|
9
10
|
const LIST_LIMIT = 100;
|
|
10
11
|
|
|
11
|
-
export async function buildSessionList(
|
|
12
|
+
export async function buildSessionList(
|
|
13
|
+
client: OpencodeClientInterface,
|
|
14
|
+
q: string,
|
|
15
|
+
daemonMap?: Map<string, SessionDaemonInfo>,
|
|
16
|
+
): Promise<{ html: string }> {
|
|
12
17
|
let sessions = await client.listSessions(LIST_LIMIT);
|
|
18
|
+
if (daemonMap) {
|
|
19
|
+
sessions = sessions.map((s) => {
|
|
20
|
+
const di = daemonMap.get(s.id);
|
|
21
|
+
if (di) return { ...s, daemon: { displayName: di.displayName, endpoint: di.endpoint } };
|
|
22
|
+
return s;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
13
25
|
const needle = q.trim().toLowerCase();
|
|
14
26
|
if (needle) {
|
|
15
27
|
sessions = sessions.filter((s) => s.title.toLowerCase().includes(needle) || s.id.toLowerCase().includes(needle));
|
|
@@ -32,6 +44,7 @@ export async function buildSessionList(client: OpencodeClientInterface, q: strin
|
|
|
32
44
|
.srow .st{font-weight:600;color:var(--text);font-size:15px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
33
45
|
.srow .sm{display:flex;gap:1rem;color:var(--text-muted);font-size:12px;margin-top:.25rem;flex-wrap:wrap}
|
|
34
46
|
.srow .sid{font-family:ui-monospace,SFMono-Regular,Menlo,monospace}
|
|
47
|
+
.sd-badge{background:var(--bg);border:1px solid var(--border);border-radius:4px;padding:0 .3rem;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11px}
|
|
35
48
|
.empty{padding:2rem;text-align:center;color:var(--text-muted)}
|
|
36
49
|
</style></head><body>
|
|
37
50
|
<header class="nav" style="display:flex;align-items:center;gap:.5rem;padding:.55rem 1rem;background:var(--header-bg);color:var(--header-text);font-size:13px"><a href="/" style="color:var(--header-text)">🏠 ework-web</a><span style="opacity:.8"> · OpenCode 会话 ${sessions.length}</span></header>
|
|
@@ -50,6 +63,7 @@ function sessionRow(s: SessionListItem): string {
|
|
|
50
63
|
const badges = [
|
|
51
64
|
s.peakTokens ? `<span>🧮 峰值 ${kfmt(s.peakTokens)}</span>` : "",
|
|
52
65
|
s.msgCount ? `<span>💬 ${s.msgCount}</span>` : "",
|
|
66
|
+
s.daemon ? `<span class="sd-badge" title="${escapeAttr(s.daemon.endpoint)}">🖥️ ${escapeHtml(s.daemon.displayName)} ${escapeHtml(s.daemon.endpoint)}</span>` : "",
|
|
53
67
|
].join("");
|
|
54
68
|
return `<a class="srow" href="${escapeAttr(href)}">
|
|
55
69
|
<div class="st">${escapeHtml(s.title)}</div>
|