ework-web 0.10.27 → 0.10.29
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 +15 -0
- package/src/index.ts +31 -2
package/package.json
CHANGED
package/src/coordination.ts
CHANGED
|
@@ -103,3 +103,18 @@ export async function getSessionDaemonMap(): Promise<Map<string, SessionDaemonIn
|
|
|
103
103
|
return new Map();
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
+
|
|
107
|
+
export async function resolveDaemonEndpoint(daemonId: number): Promise<string | null> {
|
|
108
|
+
try {
|
|
109
|
+
const rows = await getDB().all<{ internal_endpoint: string | null }>(
|
|
110
|
+
`SELECT internal_endpoint FROM {{d_daemons}} WHERE id = ?`,
|
|
111
|
+
[daemonId],
|
|
112
|
+
);
|
|
113
|
+
const ep = rows[0]?.internal_endpoint;
|
|
114
|
+
if (!ep) return null;
|
|
115
|
+
return ep;
|
|
116
|
+
} catch (e) {
|
|
117
|
+
log.info(`coordination: resolve daemon ${daemonId} failed (${e instanceof Error ? e.message : String(e)})`);
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -6,10 +6,11 @@ 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, getSessionDaemonMap } from "./coordination";
|
|
9
|
+
import { getActiveDaemons, listAllDaemons, getSessionDaemonMap, resolveDaemonEndpoint } 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";
|
|
13
|
+
import { runAuthHook } from "./auth-hook";
|
|
13
14
|
import { OpencodeError, createOpencodeClient, MultiDaemonOpencodeClient, RemoteOpencodeClient, isLocalhost, type OpencodeClientInterface } from "./opencode";
|
|
14
15
|
import { renderMarkdown } from "./render/markdown";
|
|
15
16
|
import { log, uptimeSeconds, version } from "./logger";
|
|
@@ -495,6 +496,14 @@ async function handle(req: Request, url: URL, ip: string, ctx: { authed: boolean
|
|
|
495
496
|
if (u) resolvedLogin = u.login;
|
|
496
497
|
}
|
|
497
498
|
|
|
499
|
+
if (!resolvedLogin && token && cfg.userAuthHook) {
|
|
500
|
+
const hookReq = new Request(url, {
|
|
501
|
+
headers: { authorization: `Bearer ${token}` },
|
|
502
|
+
});
|
|
503
|
+
const user = await runAuthHook(cfg.userAuthHook, hookReq);
|
|
504
|
+
if (user) resolvedLogin = user.login;
|
|
505
|
+
}
|
|
506
|
+
|
|
498
507
|
if (resolvedLogin) {
|
|
499
508
|
const setCookie = await makeAuthCookieHeader(cfg, resolvedLogin);
|
|
500
509
|
return new Response(null, {
|
|
@@ -628,6 +637,18 @@ async function handle(req: Request, url: URL, ip: string, ctx: { authed: boolean
|
|
|
628
637
|
const all = url.searchParams.get("all") === "1";
|
|
629
638
|
const limit = Math.min(5000, Math.max(1, Number(url.searchParams.get("limit")) || 30));
|
|
630
639
|
const daemonEp = url.searchParams.get("daemon");
|
|
640
|
+
const daemonIdParam = url.searchParams.get("daemon_id");
|
|
641
|
+
if (!daemonEp && daemonIdParam) {
|
|
642
|
+
const id = Number(daemonIdParam);
|
|
643
|
+
if (Number.isFinite(id) && id > 0) {
|
|
644
|
+
const ep = await resolveDaemonEndpoint(id);
|
|
645
|
+
if (ep) {
|
|
646
|
+
const client = new RemoteOpencodeClient(ep);
|
|
647
|
+
const { html: body } = await buildSessionView(client, sid, desc, cfg.collapseLines, limit, all);
|
|
648
|
+
return html(body);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
631
652
|
const client = daemonEp ? new RemoteOpencodeClient(daemonEp) : opencode;
|
|
632
653
|
try {
|
|
633
654
|
const { html: body } = await buildSessionView(client, sid, desc, cfg.collapseLines, limit, all);
|
|
@@ -651,7 +672,15 @@ async function handle(req: Request, url: URL, ip: string, ctx: { authed: boolean
|
|
|
651
672
|
|
|
652
673
|
if (url.pathname === "/file") {
|
|
653
674
|
const rawPath = url.searchParams.get("path") ?? "";
|
|
654
|
-
|
|
675
|
+
let daemonParam = url.searchParams.get("daemon");
|
|
676
|
+
const daemonIdParam = url.searchParams.get("daemon_id");
|
|
677
|
+
if (!daemonParam && daemonIdParam) {
|
|
678
|
+
const id = Number(daemonIdParam);
|
|
679
|
+
if (Number.isFinite(id) && id > 0) {
|
|
680
|
+
const ep = await resolveDaemonEndpoint(id);
|
|
681
|
+
if (ep) daemonParam = ep;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
655
684
|
if (daemonParam && !isLocalhost(daemonParam)) {
|
|
656
685
|
try {
|
|
657
686
|
const mode = url.searchParams.get("mode") ?? "tail";
|