chattercatcher 0.1.21 → 0.1.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/dist/cli.js CHANGED
@@ -8,7 +8,7 @@ import fs14 from "fs/promises";
8
8
  // package.json
9
9
  var package_default = {
10
10
  name: "chattercatcher",
11
- version: "0.1.21",
11
+ version: "0.1.23",
12
12
  description: "\u672C\u5730\u4F18\u5148\u7684\u98DE\u4E66/Lark \u5BB6\u5EAD\u7FA4\u77E5\u8BC6\u5E93\u673A\u5668\u4EBA",
13
13
  type: "module",
14
14
  main: "dist/index.js",
@@ -5360,6 +5360,7 @@ function buildHtml() {
5360
5360
  const gatewayClass = status.gateway.configured ? "status-ok" : "status-warn";
5361
5361
  metrics.innerHTML = [
5362
5362
  ["Gateway", formatGatewayValue(status.gateway), formatGatewayNote(status.gateway), gatewayClass],
5363
+ ["\u7248\u672C", status.version || "unknown", "\u5F53\u524D\u8FD0\u884C\u7248\u672C", ""],
5363
5364
  ["\u7FA4\u804A", status.data.chats, "\u672C\u5730\u7FA4\u804A\u6570", ""],
5364
5365
  ["\u6D88\u606F", status.data.messages, "\u5DF2\u5165\u5E93\u6D88\u606F", ""],
5365
5366
  ["\u4F1A\u8BDD\u8BB0\u5FC6", status.data.episodes, "\u5DF2\u751F\u6210\u6458\u8981", ""],
@@ -5539,45 +5540,53 @@ function buildHtml() {
5539
5540
  " <span>" + escapeHtml(item.status) + "</span>",
5540
5541
  " <span>" + escapeHtml(citationCount) + " \u6761\u5F15\u7528</span>",
5541
5542
  " </div>",
5542
- " <div class="message-body"><strong>\u95EE\uFF1A</strong>" + escapeHtml(item.question) + "</div>",
5543
- " <div class="message-body"><strong>\u7B54\uFF1A</strong>" + escapeHtml(item.answer) + "</div>",
5543
+ " <div class=\\"message-body\\"><strong>\u95EE\uFF1A</strong>" + escapeHtml(item.question) + "</div>",
5544
+ " <div class=\\"message-body\\"><strong>\u7B54\uFF1A</strong>" + escapeHtml(item.answer) + "</div>",
5544
5545
  "</article>",
5545
- ].join("
5546
- ");
5546
+ ].join("\\n");
5547
5547
  });
5548
5548
  qaLogs.innerHTML = [
5549
5549
  '<div class="message-list">',
5550
5550
  rows.join(""),
5551
5551
  "</div>",
5552
- ].join("
5553
- ");
5552
+ ].join("\\n");
5554
5553
  }
5555
5554
 
5556
- async function load() {
5555
+ async function fetchJson(path) {
5556
+ const response = await fetch(path);
5557
+ if (!response.ok) {
5558
+ const body = await response.text();
5559
+ throw new Error(path + " " + response.status + " " + body);
5560
+ }
5561
+ return response.json();
5562
+ }
5563
+
5564
+ function renderLoadError(element, error) {
5565
+ element.className = "empty";
5566
+ element.textContent = "\u52A0\u8F7D\u5931\u8D25\uFF1A" + (error instanceof Error ? error.message : String(error));
5567
+ }
5568
+
5569
+ async function loadSection(path, element, render) {
5557
5570
  try {
5558
- const [status, recent, episodeList, chatList, fileList, jobList, qaLogList, cronJobList] = await Promise.all([
5559
- fetch("/api/status").then((response) => response.json()),
5560
- fetch("/api/messages/recent?limit=20").then((response) => response.json()),
5561
- fetch("/api/episodes?limit=10").then((response) => response.json()),
5562
- fetch("/api/chats").then((response) => response.json()),
5563
- fetch("/api/files").then((response) => response.json()),
5564
- fetch("/api/file-jobs").then((response) => response.json()),
5565
- fetch("/api/qa-logs?limit=10").then((response) => response.json()),
5566
- fetch("/api/cron-jobs").then((response) => response.json()),
5567
- ]);
5568
- renderMetrics(status);
5569
- renderMessages(recent.items);
5570
- renderEpisodes(episodeList.items);
5571
- renderChats(chatList.items);
5572
- renderFiles(fileList.items);
5573
- renderFileJobs(jobList.items);
5574
- renderQaLogs(qaLogList.items);
5575
- renderCronJobs(cronJobList.items);
5571
+ render(await fetchJson(path));
5576
5572
  } catch (error) {
5577
- metrics.innerHTML = '<div class="empty">\u6570\u636E\u52A0\u8F7D\u5931\u8D25\uFF1A' + escapeHtml(error instanceof Error ? error.message : String(error)) + '</div>';
5573
+ renderLoadError(element, error);
5578
5574
  }
5579
5575
  }
5580
5576
 
5577
+ async function load() {
5578
+ await Promise.all([
5579
+ loadSection("/api/status", metrics, renderMetrics),
5580
+ loadSection("/api/messages/recent?limit=20", messages, (data) => renderMessages(data.items)),
5581
+ loadSection("/api/episodes?limit=10", episodes, (data) => renderEpisodes(data.items)),
5582
+ loadSection("/api/chats", chats, (data) => renderChats(data.items)),
5583
+ loadSection("/api/files", files, (data) => renderFiles(data.items)),
5584
+ loadSection("/api/file-jobs", fileJobs, (data) => renderFileJobs(data.items)),
5585
+ loadSection("/api/qa-logs?limit=10", qaLogs, (data) => renderQaLogs(data.items)),
5586
+ loadSection("/api/cron-jobs", cronJobs, (data) => renderCronJobs(data.items)),
5587
+ ]);
5588
+ }
5589
+
5581
5590
  async function processNow() {
5582
5591
  processMessages.disabled = true;
5583
5592
  actionStatus.textContent = "\u6B63\u5728\u5904\u7406\u6D88\u606F\u7D22\u5F15...";
@@ -5652,9 +5661,10 @@ function isAuthorizedWebAction(request, token) {
5652
5661
  const provided = readHeader(request.headers["x-chattercatcher-web-token"]);
5653
5662
  return provided === token;
5654
5663
  }
5655
- function createWebApp(config) {
5664
+ function createWebApp(config, options = {}) {
5656
5665
  const app = Fastify({ logger: false });
5657
5666
  const database = openDatabase(config);
5667
+ const version = options.version ?? "unknown";
5658
5668
  const messages = new MessageRepository(database);
5659
5669
  const episodes = new EpisodeRepository(database);
5660
5670
  const fileJobs = new FileJobRepository(database);
@@ -5676,6 +5686,7 @@ function createWebApp(config) {
5676
5686
  await tokenReady;
5677
5687
  return {
5678
5688
  app: "ChatterCatcher",
5689
+ version,
5679
5690
  gateway: getGatewayStatus(config),
5680
5691
  data: {
5681
5692
  chats: messages.getChatCount(),
@@ -5780,12 +5791,13 @@ function createWebApp(config) {
5780
5791
  });
5781
5792
  return app;
5782
5793
  }
5783
- async function startWebServer(config) {
5784
- const app = createWebApp(config);
5794
+ async function startWebServer(config, options = {}) {
5795
+ const app = createWebApp(config, options);
5785
5796
  await app.listen({ host: config.web.host, port: config.web.port });
5786
5797
  const address = app.server.address();
5787
5798
  const url = typeof address === "string" ? address : `http://${config.web.host}:${address?.port ?? config.web.port}`;
5788
- console.log(`ChatterCatcher Web UI: ${url}`);
5799
+ const versionText = options.version ? ` ${options.version}` : "";
5800
+ console.log(`ChatterCatcher Web UI${versionText}: ${url}`);
5789
5801
  }
5790
5802
 
5791
5803
  // src/cli.ts
@@ -5964,7 +5976,7 @@ async function startGatewayForegroundCommand() {
5964
5976
  });
5965
5977
  console.log(status.message);
5966
5978
  console.log("\u672C\u5730 Web UI \u4ECD\u4F1A\u542F\u52A8\uFF0C\u65B9\u4FBF\u7EE7\u7EED\u914D\u7F6E\u3002");
5967
- await startWebServer(config);
5979
+ await startWebServer(config, { version: package_default.version });
5968
5980
  return;
5969
5981
  }
5970
5982
  await tryEnsureFeishuBotOpenId(config, secrets);
@@ -6027,7 +6039,7 @@ async function startGatewayForegroundCommand() {
6027
6039
  console.log(status.message);
6028
6040
  try {
6029
6041
  await gatewayRuntime.start();
6030
- await startWebServer(config);
6042
+ await startWebServer(config, { version: package_default.version });
6031
6043
  } catch (error) {
6032
6044
  cleanup();
6033
6045
  throw error;
@@ -6066,7 +6078,7 @@ gateway.command("restart").description("\u91CD\u542F Gateway").action(async () =
6066
6078
  var web = program.command("web").description("\u7BA1\u7406\u672C\u5730 Web UI");
6067
6079
  web.command("start").description("\u542F\u52A8\u672C\u5730 Web UI").action(async () => {
6068
6080
  const config = await loadConfig();
6069
- await startWebServer(config);
6081
+ await startWebServer(config, { version: package_default.version });
6070
6082
  });
6071
6083
  var data = program.command("data").description("\u7BA1\u7406\u672C\u5730\u77E5\u8BC6\u5E93\u6570\u636E");
6072
6084
  async function deleteDataCommand(targetType, targetId, options) {