ework-web 0.5.1 → 0.6.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ework-web",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "description": "ework-web — standalone multi-project issue tracker. Local SQLite-backed, no external API dependency. Bun + TypeScript + SSR HTML.",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -82,10 +82,12 @@ import {
82
82
  setWebhookActive,
83
83
  getWebhook,
84
84
  listDeliveries,
85
+ listAllRecentDeliveries,
85
86
  type WebhookEventName,
86
87
  } from "./webhooks";
87
88
  import { classifyActor, type CommentView } from "./render/components";
88
89
  import { buildWebhooksPage } from "./views/webhooks";
90
+ import { buildWebhookDeliveriesPage } from "./views/webhookDeliveries";
89
91
  import { buildProjectMembersPage } from "./views/projectMembers";
90
92
  import { buildProjectUpstreamsPage, trySetUpstreamUrls } from "./views/projectUpstreams";
91
93
  import { buildProjectModelPage } from "./views/projectModel";
@@ -939,6 +941,11 @@ async function handle(req: Request, url: URL, ip: string, ctx: { authed: boolean
939
941
  return html(buildAdminTokensPage(ctx.user!, await listAllPatsWithUsers(), flash));
940
942
  }
941
943
 
944
+ if (url.pathname === "/admin/deliveries") {
945
+ const deliveries = await listAllRecentDeliveries(100);
946
+ return html(buildWebhookDeliveriesPage(ctx.user!, deliveries));
947
+ }
948
+
942
949
  const adminPatRevoke = url.pathname.match(/^\/admin\/tokens\/(\d+)\/revoke$/);
943
950
  if (adminPatRevoke && req.method === "POST") {
944
951
  const id = Number(adminPatRevoke[1]);
@@ -138,6 +138,7 @@ ${flashHtml}
138
138
  <div class="admin-nav">
139
139
  <a href="/admin/users">用户</a>
140
140
  <a href="/admin/tokens">所有 Token</a>
141
+ <a href="/admin/deliveries">Webhook 投递</a>
141
142
  </div>
142
143
 
143
144
  <form class="card" method="POST" action="/admin/users/create">
@@ -0,0 +1,92 @@
1
+ import { type DeliveryWithWebhookRow } from "../webhooks";
2
+ import { type UserRow } from "../store";
3
+ import { THEME_CSS, escapeHtml, escapeAttr, tabNavHTML } from "../render/layout";
4
+
5
+ function statusClass(status: number | null): string {
6
+ if (status === null) return "err";
7
+ if (status >= 200 && status < 300) return "ok";
8
+ if (status >= 400 && status < 500) return "warn";
9
+ return "err";
10
+ }
11
+
12
+ function deliveryRowHtml(d: DeliveryWithWebhookRow): string {
13
+ const status = d.response_status === null ? "—" : String(d.response_status);
14
+ const cls = statusClass(d.response_status);
15
+ const project = d.project_owner
16
+ ? `<a href="/${escapeAttr(d.project_owner)}/${escapeAttr(d.project_name ?? "")}">${escapeHtml(d.project_owner + "/" + (d.project_name ?? ""))}</a>`
17
+ : "<em>(deleted)</em>";
18
+ const url = d.webhook_url ? `<code class="url">${escapeHtml(d.webhook_url)}</code>` : "<em>(deleted)</em>";
19
+ const err = d.error ? `<div class="derr">${escapeHtml(d.error)}</div>` : "";
20
+ const body = d.response_body
21
+ ? `<details class="dbody"><summary>响应</summary><pre>${escapeHtml(d.response_body)}</pre></details>`
22
+ : "";
23
+ const payload = `<details class="dpl"><summary>payload</summary><pre>${escapeHtml(d.payload)}</pre></details>`;
24
+ return `<tr>
25
+ <td class="ts">${escapeHtml(d.created_at)}</td>
26
+ <td class="proj">${project}</td>
27
+ <td class="ev">${escapeHtml(d.event)}</td>
28
+ <td class="url">${url}</td>
29
+ <td class="st ${cls}">${status}</td>
30
+ <td class="ms">${d.duration_ms === null ? "—" : d.duration_ms + "ms"}</td>
31
+ <td class="act">${payload}${body}${err}</td>
32
+ </tr>`;
33
+ }
34
+
35
+ export function buildWebhookDeliveriesPage(viewer: UserRow, deliveries: DeliveryWithWebhookRow[]): string {
36
+ const rows = deliveries.length > 0
37
+ ? deliveries.map(deliveryRowHtml).join("")
38
+ : `<tr><td colspan="7" class="empty">暂无投递记录</td></tr>`;
39
+
40
+ const ok = deliveries.filter((d) => d.response_status !== null && d.response_status >= 200 && d.response_status < 300).length;
41
+ const fail = deliveries.filter((d) => d.response_status === null || d.response_status >= 400).length;
42
+ const summary = deliveries.length > 0
43
+ ? `<div class="summary"><span class="badge ok">${ok} 成功</span> <span class="badge ${fail > 0 ? "err" : ""}">${fail} 失败</span> <span class="muted">最近 ${deliveries.length} 条</span></div>`
44
+ : "";
45
+
46
+ return `<!doctype html>
47
+ <html lang="zh"><head><meta charset="utf-8">
48
+ <meta name="viewport" content="width=device-width,initial-scale=1">
49
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg">
50
+ <title>ework-web · Webhook 投递记录</title>
51
+ <style>${THEME_CSS}
52
+ .nav{display:flex;align-items:center;gap:.5rem;padding:.55rem 1rem;background:var(--header-bg);color:var(--header-text);font-size:13px}
53
+ .nav a{color:var(--header-text);opacity:.95}
54
+ .wrap{max-width:1100px;margin:0 auto;padding:1rem}
55
+ h1{font-size:18px;margin:0 0 .3rem}
56
+ .hint{color:var(--text-muted);font-size:13px;margin:0 0 1rem}
57
+ .summary{margin-bottom:.8rem;display:flex;gap:.5rem;align-items:center}
58
+ .badge{padding:2px 8px;border-radius:10px;font-size:12px;font-weight:600}
59
+ .badge.ok{background:#3fb95033;color:#3fb950}
60
+ .badge.err{background:#f8514933;color:#f85149}
61
+ .muted{color:var(--text-muted);font-size:12px}
62
+ .dtable{width:100%;border-collapse:collapse;font-size:12px}
63
+ .dtable th,.dtable td{border:1px solid var(--border);padding:.3rem .4rem;text-align:left;vertical-align:top}
64
+ .dtable th{background:var(--bg);color:var(--text-muted);font-weight:600;position:sticky;top:0}
65
+ .dtable .ts{white-space:nowrap;font-family:ui-monospace,monospace}
66
+ .dtable .proj{white-space:nowrap}
67
+ .dtable .proj a{color:var(--accent)}
68
+ .dtable .ev{white-space:nowrap;font-family:ui-monospace,monospace}
69
+ .dtable .url{max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
70
+ .dtable .url code{font-family:ui-monospace,monospace;font-size:11px;color:var(--text-muted)}
71
+ .dtable .st.ok{color:#3fb950;font-weight:600}
72
+ .dtable .st.warn{color:#d29922;font-weight:600}
73
+ .dtable .st.err{color:#f85149;font-weight:600}
74
+ .dtable .ms{color:var(--text-muted);white-space:nowrap}
75
+ .dbody pre,.dpl pre{font-size:11px;max-height:240px;overflow:auto;background:var(--bg);padding:.4rem;border-radius:5px;border:1px solid var(--border);white-space:pre-wrap;word-break:break-all}
76
+ .derr{color:#f85149;font-size:11px;margin-top:.2rem}
77
+ .empty{color:var(--text-muted);text-align:center;padding:.6rem}
78
+ .tabs{display:flex;gap:.3rem;padding:.5rem 1rem;border-bottom:1px solid var(--border);font-size:13px}
79
+ .tab{padding:.3rem .7rem;border-radius:6px 6px 0 0;text-decoration:none;color:var(--text-muted)}
80
+ .tab.active{background:var(--accent);color:#fff}
81
+ </style></head><body>
82
+ <header class="nav"><a href="/" style="color:var(--header-text)">🏠 ework-web</a></header>
83
+ ${tabNavHTML("projects", viewer)}
84
+ <main class="wrap">
85
+ <h1>Webhook 投递记录</h1>
86
+ <p class="hint">所有项目的 webhook 投递历史。用于排查 "AI 没回应" 类问题 — 如果投递失败(红色状态码),daemon 根本没收到事件。</p>
87
+ ${summary}
88
+ <table class="dtable"><thead><tr>
89
+ <th>时间</th><th>项目</th><th>事件</th><th>目标 URL</th><th>状态</th><th>耗时</th><th>详情</th>
90
+ </tr></thead><tbody>${rows}</tbody></table>
91
+ </main></body></html>`;
92
+ }
package/src/webhooks.ts CHANGED
@@ -177,6 +177,23 @@ export async function listDeliveries(webhookId: number, limit = 50): Promise<Web
177
177
  );
178
178
  }
179
179
 
180
+ export interface DeliveryWithWebhookRow extends WebhookDeliveryRow {
181
+ webhook_url: string;
182
+ project_owner: string;
183
+ project_name: string;
184
+ }
185
+
186
+ export async function listAllRecentDeliveries(limit = 100): Promise<DeliveryWithWebhookRow[]> {
187
+ return await getDB().all<DeliveryWithWebhookRow>(
188
+ `SELECT d.*, w.url AS webhook_url, p.owner AS project_owner, p.name AS project_name
189
+ FROM {{webhook_deliveries}} d
190
+ LEFT JOIN {{webhooks}} w ON w.id = d.webhook_id
191
+ LEFT JOIN {{projects}} p ON p.id = w.project_id
192
+ ORDER BY d.id DESC LIMIT ?`,
193
+ [limit]
194
+ );
195
+ }
196
+
180
197
  // ─── Payload builders (Gitea-compatible shape) ───────────────
181
198
  //
182
199
  // We populate the fields downstream consumers actually read (see Gitea's