@alexsun-top/opencode-chat-room 0.8.0 → 0.8.1

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.
Files changed (161) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/LICENSE +2 -2
  3. package/README.md +38 -6
  4. package/README.zh-CN.md +38 -6
  5. package/cli.ts +27 -1
  6. package/dist/cli.js +5074 -3212
  7. package/package.json +23 -3
  8. package/packages/chat-room-channeld/README.md +98 -25
  9. package/packages/chat-room-channeld/dist/feishu-adapter.js +912 -149
  10. package/packages/chat-room-channeld/src/adapter.ts +36 -2
  11. package/packages/chat-room-channeld/src/config.ts +63 -1
  12. package/packages/chat-room-channeld/src/delivery.ts +6 -1
  13. package/packages/chat-room-channeld/src/feishu-adapter.ts +122 -292
  14. package/packages/chat-room-channeld/src/feishu-card.ts +27 -0
  15. package/packages/chat-room-channeld/src/feishu-inbound.ts +158 -0
  16. package/packages/chat-room-channeld/src/feishu-live.ts +355 -0
  17. package/packages/chat-room-channeld/src/feishu-send.ts +342 -0
  18. package/packages/chat-room-channeld/src/feishu-ws-frames.ts +173 -0
  19. package/packages/chat-room-channeld/src/host-helpers.ts +11 -0
  20. package/packages/chat-room-channeld/src/host.ts +120 -2
  21. package/packages/chat-room-channeld/src/inbound.ts +26 -0
  22. package/packages/chat-room-channeld/src/state.ts +17 -0
  23. package/packages/chat-room-channeld/src/stats.ts +43 -1
  24. package/server/admin-state.ts +13 -13
  25. package/server/app.ts +95 -0
  26. package/server/assets/NOTICE.txt +2 -1
  27. package/server/assets/base.css +15 -9
  28. package/server/assets/chat/announcements.js +70 -7
  29. package/server/assets/chat/doc-preview.js +184 -35
  30. package/server/assets/chat/events.js +3 -0
  31. package/server/assets/chat/files.js +46 -4
  32. package/server/assets/chat/index.js +2 -0
  33. package/server/assets/chat/integration-editor.js +163 -0
  34. package/server/assets/chat/integration-values.js +124 -0
  35. package/server/assets/chat/integrations.js +498 -0
  36. package/server/assets/chat/locales/de.js +40 -4
  37. package/server/assets/chat/locales/es.js +40 -4
  38. package/server/assets/chat/locales/fr.js +40 -4
  39. package/server/assets/chat/locales/it.js +40 -4
  40. package/server/assets/chat/locales/ja.js +40 -4
  41. package/server/assets/chat/locales/ko.js +40 -4
  42. package/server/assets/chat/markdown.js +22 -8
  43. package/server/assets/chat/messages.js +5 -5
  44. package/server/assets/chat/office-preview.js +69 -0
  45. package/server/assets/chat/panels.js +36 -0
  46. package/server/assets/chat/recall.js +58 -7
  47. package/server/assets/chat/receipts.js +15 -3
  48. package/server/assets/chat/reminders.js +69 -8
  49. package/server/assets/chat/resource-format.js +11 -0
  50. package/server/assets/chat/settings.js +30 -2
  51. package/server/assets/chat/side-pane.js +1 -2
  52. package/server/assets/chat/state.js +93 -10
  53. package/server/assets/chat/system-events.js +32 -0
  54. package/server/assets/chat/system-messages.js +23 -14
  55. package/server/assets/chat/task-row.js +0 -6
  56. package/server/assets/chat/tasks.js +121 -33
  57. package/server/assets/code-highlight.css +55 -32
  58. package/server/assets/conversation.css +123 -23
  59. package/server/assets/doc-preview.css +35 -3
  60. package/server/assets/files.css +5 -0
  61. package/server/assets/fluent-icons.svg +2 -0
  62. package/server/assets/monaco/LICENSE +21 -0
  63. package/server/assets/monaco/ThirdPartyNotices.txt +448 -0
  64. package/server/assets/monaco/codicon-jdswhhtn.ttf +0 -0
  65. package/server/assets/monaco/editor.worker.js +45 -0
  66. package/server/assets/monaco/integration-rules.css +1 -0
  67. package/server/assets/monaco/integration-rules.js +1297 -0
  68. package/server/assets/monaco/json.worker.js +77 -0
  69. package/server/assets/office/THIRD-PARTY-NOTICES.txt +11 -0
  70. package/server/assets/office/docx.bundle.js +33 -0
  71. package/server/assets/office/licenses/docx-preview-LICENSE.txt +201 -0
  72. package/server/assets/office/licenses/echarts-LICENSE.txt +222 -0
  73. package/server/assets/office/licenses/jszip-LICENSE.txt +651 -0
  74. package/server/assets/office/licenses/lodash-LICENSE.txt +47 -0
  75. package/server/assets/office/licenses/pptx-preview-LICENSE.txt +8 -0
  76. package/server/assets/office/licenses/tslib-LICENSE.txt +12 -0
  77. package/server/assets/office/licenses/uuid-LICENSE.txt +9 -0
  78. package/server/assets/office/licenses/xlsx-LICENSE.txt +201 -0
  79. package/server/assets/office/licenses/zrender-LICENSE.txt +29 -0
  80. package/server/assets/office/pptx.bundle.js +104 -0
  81. package/server/assets/office/xlsx.bundle.js +141 -0
  82. package/server/assets/recall.css +5 -4
  83. package/server/assets/responsive.css +50 -11
  84. package/server/assets/settings.css +73 -1
  85. package/server/assets/tasks.css +57 -7
  86. package/server/channel-integration.ts +519 -0
  87. package/server/channel-settings.ts +77 -0
  88. package/server/channels.ts +261 -18
  89. package/server/chat-server.ts +32 -580
  90. package/server/chat.html +187 -21
  91. package/server/http-server.ts +3 -182
  92. package/server/resource-routes.ts +16 -16
  93. package/server/routes/inbox.ts +100 -0
  94. package/server/routes/pages.ts +83 -0
  95. package/server/routes/questions.ts +39 -0
  96. package/server/routes/room-actions.ts +162 -0
  97. package/server/routes/rooms.ts +160 -0
  98. package/server/startup.ts +84 -0
  99. package/server/sw.js +4 -0
  100. package/server/task-routes.ts +1 -1
  101. package/src/center/center-client.ts +2 -10
  102. package/src/config/file-config.ts +7 -54
  103. package/src/platform/http-server.ts +182 -0
  104. package/src/protocol/addressing.ts +21 -0
  105. package/src/protocol/config.ts +58 -0
  106. package/src/protocol/room.ts +51 -0
  107. package/src/rooms/resources.ts +26 -16
  108. package/src/rooms/room-service.ts +2 -48
  109. package/src/rooms/storage.ts +329 -0
  110. package/src/rooms/tasks.ts +21 -5
  111. package/src/runtime/watch.ts +1 -1
  112. package/src/state/pg-database.ts +183 -0
  113. package/src/state/pg-migrate.ts +175 -0
  114. package/src/state/pg-sql.mjs +175 -0
  115. package/src/state/pg-worker.mjs +148 -0
  116. package/src/state/sqlite-announcements.ts +25 -0
  117. package/src/state/sqlite-database.ts +121 -0
  118. package/src/state/sqlite-legacy.ts +90 -0
  119. package/src/state/sqlite-members.ts +155 -0
  120. package/src/state/sqlite-messages.ts +288 -0
  121. package/src/state/sqlite-resources.ts +39 -0
  122. package/src/state/sqlite-rooms.ts +87 -0
  123. package/src/state/sqlite-schema.ts +80 -0
  124. package/src/state/sqlite-state-store.ts +33 -0
  125. package/src/state/sqlite-state.ts +15 -897
  126. package/src/state/sqlite-tasks.ts +65 -0
  127. package/src/state/sqlite-transaction.ts +13 -0
  128. package/src/state/sqlite.ts +21 -1
  129. package/src/state/store.ts +5 -1
  130. package/src/tui/app.mjs +32 -19
  131. package/src/tui/config.mjs +12 -4
  132. package/src/tui/i18n.mjs +38 -0
  133. package/src/tui/info-app.mjs +50 -51
  134. package/src/tui/info-content.mjs +79 -44
  135. package/src/tui/join-app.mjs +9 -9
  136. package/src/tui/locales/en.mjs +349 -0
  137. package/src/tui/locales/zh-CN.mjs +349 -0
  138. package/src/tui/main.mjs +85 -37
  139. package/src/tui/markdown.mjs +3 -2
  140. package/src/tui/mentions.mjs +3 -1
  141. package/src/tui/message-app.mjs +22 -21
  142. package/src/tui/message-view.mjs +2 -1
  143. package/src/tui/palette-app.mjs +9 -8
  144. package/src/tui/palette.mjs +30 -24
  145. package/src/tui/prefs.mjs +92 -0
  146. package/src/tui/reminder-app.mjs +18 -17
  147. package/src/tui/room-settings-app.mjs +30 -28
  148. package/src/tui/settings-app.mjs +153 -0
  149. package/src/tui/ui-content.mjs +65 -86
  150. package/src/tui/ui-help.mjs +73 -0
  151. package/src/tui/ui-overlay-view.mjs +23 -7
  152. package/src/tui/ui-suggest.mjs +6 -5
  153. package/src/tui/ui-theme.mjs +37 -33
  154. package/src/tui/ui-view.mjs +22 -7
  155. package/src/tui/ui.mjs +15 -3
  156. package/src/web/editor.worker.ts +1 -0
  157. package/src/web/integration-rules-editor.ts +439 -0
  158. package/src/web/integration-rules.ts +22 -0
  159. package/src/web/integration-schema.ts +228 -0
  160. package/src/web/json.worker.ts +1 -0
  161. package/src/web/office-viewer.ts +221 -0
@@ -4,8 +4,10 @@ import { applyReceipt, notifyDeliveryResult, type DeliveryResultHandler } from "
4
4
  import { parseTarget, startFailureReason, toEndpoint, validateTargets } from "./host-helpers.ts";
5
5
  import { IngestGate, type IngestResult } from "./ingest-gate.ts";
6
6
  import { log } from "./log.ts";
7
- import type { Endpoint, IngestEvent } from "./protocol.ts";
7
+ import type { Endpoint, IngestEvent, MessageRef } from "./protocol.ts";
8
8
  import { matchRules, planPayload, sameEndpoint, targetKey } from "./rules.ts";
9
+ import type { ChannelAccountRuntime } from "./stats.ts";
10
+ import { sanitizeAccountError } from "./stats.ts";
9
11
  import { openState, type ChannelState, type DeliveryRow } from "./state.ts";
10
12
 
11
13
  export type { IngestResult } from "./ingest-gate.ts";
@@ -26,6 +28,7 @@ export interface SpawnAdapterContext {
26
28
  onIngest(event: IngestEvent): Promise<{ duplicate: boolean; eventId?: string }>;
27
29
  onExit(code: number | null, signal: NodeJS.Signals | null): void;
28
30
  onUnavailable(reason: string): void;
31
+ onStatus(status: { inbound?: string; detail?: string }): void;
29
32
  }
30
33
 
31
34
  export type SpawnAdapter = (account: AccountConfig, context: SpawnAdapterContext) => AdapterHandle;
@@ -36,6 +39,16 @@ export interface HostDeps {
36
39
  now?: () => number;
37
40
  deliveryIntervalMs?: number;
38
41
  onDeliveryResult?: DeliveryResultHandler;
42
+ /**
43
+ * Called once for a newly committed ingest event, never for duplicates or
44
+ * echoes. The host awaits it before reporting success: for an inbound
45
+ * notification, a rejection rolls the event back and becomes an ingest error
46
+ * so the provider retries instead of ACKing a lost message. Duplicate/replay
47
+ * suppression is durable via the event dedup key.
48
+ */
49
+ onIngestCommitted?: (event: IngestEvent) => Promise<void> | void;
50
+ /** Events used as inbound room notifications must not match outbound rules. */
51
+ notificationOnly?: (event: IngestEvent) => boolean;
39
52
  }
40
53
 
41
54
  function defaultSpawnAdapter(account: AccountConfig, context: SpawnAdapterContext): AdapterHandle {
@@ -49,18 +62,22 @@ export class ChannelHost {
49
62
  readonly #now: () => number;
50
63
  readonly #deliveryIntervalMs: number;
51
64
  readonly #onDeliveryResult?: DeliveryResultHandler;
65
+ readonly #onIngestCommitted?: (event: IngestEvent) => Promise<void> | void;
66
+ readonly #notificationOnly?: (event: IngestEvent) => boolean;
52
67
  readonly #adapters = new Map<string, AdapterHandle>();
53
68
  readonly #timers = new Map<string, ReturnType<typeof setTimeout>>();
54
69
  readonly #inFlight = new Map<string, Set<string>>();
55
70
  readonly #notified = new Set<string>();
56
71
  readonly #active = new Set<Promise<void>>();
57
72
  readonly #disabled = new Set<string>();
73
+ readonly #accountStates = new Map<string, ChannelAccountRuntime>();
58
74
  readonly #gate = new IngestGate((accountId, _event, _error) => {
59
75
  this.#disableAccount(accountId, "ingest barrier limit reached");
60
76
  });
61
77
  #state?: ChannelState;
62
78
  #running = false;
63
79
  #starting = false;
80
+ #stopReason?: string;
64
81
  #idleTimer?: ReturnType<typeof setInterval>;
65
82
  #rejectionHandler?: (reason: unknown) => void;
66
83
 
@@ -71,6 +88,8 @@ export class ChannelHost {
71
88
  this.#now = deps.now ?? Date.now;
72
89
  this.#deliveryIntervalMs = deps.deliveryIntervalMs ?? 200;
73
90
  this.#onDeliveryResult = deps.onDeliveryResult;
91
+ this.#onIngestCommitted = deps.onIngestCommitted;
92
+ this.#notificationOnly = deps.notificationOnly;
74
93
  }
75
94
 
76
95
  /** Account ids whose adapter failed to start or exited; their queues stay paused. */
@@ -78,6 +97,11 @@ export class ChannelHost {
78
97
  return [...this.#disabled];
79
98
  }
80
99
 
100
+ /** Live per-account state keyed by `platform/account`, including startup failures. */
101
+ get accountRuntimeStates(): ReadonlyMap<string, ChannelAccountRuntime> {
102
+ return new Map(this.#accountStates);
103
+ }
104
+
81
105
  /** Read-only view for routes: unknown ids or platform mismatches are missing. */
82
106
  targetStatus(platform: string, accountId: string): "ready" | "disabled" | "missing" {
83
107
  const account = this.#config.accounts.find((item) => item.id === accountId);
@@ -85,6 +109,14 @@ export class ChannelHost {
85
109
  return this.#disabled.has(accountId) ? "disabled" : "ready";
86
110
  }
87
111
 
112
+ /** Latest provider message sent for a logical room message, for native replies. */
113
+ findProviderMessage(endpoint: Endpoint, logicalMessageId: string): MessageRef | undefined {
114
+ const state = this.#state;
115
+ if (!state || !logicalMessageId) return undefined;
116
+ const nativeMessageId = state.findProviderMessage(targetKey(endpoint), logicalMessageId);
117
+ return nativeMessageId ? { endpoint, nativeMessageId } : undefined;
118
+ }
119
+
88
120
  async start(): Promise<void> {
89
121
  if (this.#running) throw new Error("host is already running");
90
122
  validateTargets(this.#config);
@@ -115,13 +147,17 @@ export class ChannelHost {
115
147
  onIngest: (event) => this.ingest(event),
116
148
  onExit: (code, signal) => this.#handleExit(account.id, code, signal),
117
149
  onUnavailable: (reason) => this.#disableAccount(account.id, reason),
150
+ onStatus: (status) => this.#handleAdapterStatus(account.id, status),
118
151
  });
119
152
  this.#adapters.set(account.id, adapter);
120
153
  await adapter.start();
154
+ const current = this.#accountStates.get(`${account.platform}/${account.id}`);
155
+ this.#setAccountState(account, "started", current?.lastError);
121
156
  this.#schedule(account.id);
122
157
  return { id: account.id };
123
158
  } catch (error) {
124
159
  const reason = startFailureReason(account.id, error);
160
+ this.#setAccountState(account, "failed", reason);
125
161
  this.#disabled.add(account.id);
126
162
  log.error(`adapter ${account.id} failed to start: ${reason}`, { account: account.id });
127
163
  if (adapter) {
@@ -146,6 +182,7 @@ export class ChannelHost {
146
182
  } else {
147
183
  const reason = result.reason instanceof Error ? result.reason.message : String(result.reason);
148
184
  failures.push({ id: account.id, reason });
185
+ this.#setAccountState(account, "failed", reason);
149
186
  this.#disabled.add(account.id);
150
187
  log.error(`adapter ${account.id} failed to start: ${reason}`, { account: account.id });
151
188
  }
@@ -169,6 +206,7 @@ export class ChannelHost {
169
206
  state.close();
170
207
  this.#state = undefined;
171
208
  this.#disabled.clear();
209
+ this.#accountStates.clear();
172
210
  const detail = failures.map((failure) => `${failure.id}: ${failure.reason}`).join("; ");
173
211
  throw new Error(`no adapters started${detail ? `: ${detail}` : ""}`);
174
212
  }
@@ -207,6 +245,27 @@ export class ChannelHost {
207
245
  const stored: IngestEvent = { ...event, ingressSeq: result.ingressSeq };
208
246
  log.info(`ingested ${stored.kind}`, { event: stored.eventId });
209
247
 
248
+ if (this.#onIngestCommitted) {
249
+ try {
250
+ await this.#onIngestCommitted(stored);
251
+ } catch (error) {
252
+ const message = error instanceof Error ? error.message : String(error);
253
+ // An inbound notification owns the ACK: roll back and fail the ingest so
254
+ // Feishu retries. Other consumer failures stay contained as before.
255
+ if (this.#notificationOnly?.(stored)) {
256
+ state.deleteIngestEvent(stored.eventId);
257
+ log.error(`inbound commit rolled back: ${message}`, { event: stored.eventId });
258
+ throw error;
259
+ }
260
+ log.warn(`onIngestCommitted failed: ${message}`, { event: stored.eventId });
261
+ }
262
+ }
263
+
264
+ if (this.#notificationOnly?.(stored)) {
265
+ log.info("inbound notification only; outbound rules skipped", { event: stored.eventId });
266
+ return { duplicate: false, eventId: stored.eventId };
267
+ }
268
+
210
269
  if (stored.kind === "message.forward_requested") {
211
270
  const selected = stored.selectedMessage;
212
271
  const reason = !selected
@@ -256,7 +315,7 @@ export class ChannelHost {
256
315
  return { duplicate: false, eventId: stored.eventId };
257
316
  }
258
317
 
259
- async stop(): Promise<void> {
318
+ async stop(options: { abortInFlight?: boolean } = {}): Promise<void> {
260
319
  if (!this.#running && !this.#state) {
261
320
  this.#clearIdle();
262
321
  this.#removeRejectionGuard();
@@ -264,10 +323,17 @@ export class ChannelHost {
264
323
  }
265
324
  this.#running = false;
266
325
  this.#starting = false;
326
+ const stopReason = "relay runtime stopped";
327
+ this.#stopReason = stopReason;
267
328
  this.#clearIdle();
268
329
  for (const timer of this.#timers.values()) clearTimeout(timer);
269
330
  this.#timers.clear();
331
+ if (options.abortInFlight) {
332
+ this.#settleInFlightUnknown(stopReason);
333
+ await this.#stopAdapters();
334
+ }
270
335
  await Promise.allSettled([...this.#active]);
336
+ this.#settleInFlightUnknown(stopReason);
271
337
  await this.#stopAdapters();
272
338
  this.#state?.close();
273
339
  this.#state = undefined;
@@ -275,6 +341,7 @@ export class ChannelHost {
275
341
  this.#inFlight.clear();
276
342
  this.#notified.clear();
277
343
  this.#disabled.clear();
344
+ this.#accountStates.clear();
278
345
  this.#removeRejectionGuard();
279
346
  log.info("host stopped");
280
347
  }
@@ -356,6 +423,8 @@ export class ChannelHost {
356
423
  } finally {
357
424
  inFlight.delete(row.deliveryId);
358
425
  }
426
+ // A host stop wins over a late send result: reload must not auto-resend.
427
+ if (this.#stopReason) receipt = { state: "unknown", detail: this.#stopReason };
359
428
  applyReceipt(state, row, attemptId, accountId, receipt, this.#now());
360
429
  notifyDeliveryResult(state, row.deliveryId, this.#onDeliveryResult, { attemptId, notified: this.#notified });
361
430
  } finally {
@@ -366,6 +435,27 @@ export class ChannelHost {
366
435
  }
367
436
  }
368
437
 
438
+ /** Stop must never leave rows that the next host would auto-resend. */
439
+ #settleInFlightUnknown(reason: string): void {
440
+ const state = this.#state;
441
+ if (!state) return;
442
+ for (const [accountId, deliveryIds] of this.#inFlight) {
443
+ for (const deliveryId of deliveryIds) {
444
+ try {
445
+ state.markDelivery(deliveryId, "unknown", { lastError: reason });
446
+ notifyDeliveryResult(state, deliveryId, this.#onDeliveryResult, { notified: this.#notified });
447
+ } catch (error) {
448
+ this.#safeWarn(
449
+ `could not mark delivery unknown: ${error instanceof Error ? error.message : String(error)}`,
450
+ accountId,
451
+ deliveryId,
452
+ );
453
+ }
454
+ }
455
+ }
456
+ this.#inFlight.clear();
457
+ }
458
+
369
459
  #pauseAccountDeliveries(accountId: string, reason: string): void {
370
460
  const state = this.#state;
371
461
  const account = this.#config.accounts.find((item) => item.id === accountId);
@@ -383,9 +473,37 @@ export class ChannelHost {
383
473
  }
384
474
  }
385
475
 
476
+ /** Inbound health is advisory: failures must not disable a working outbound account. */
477
+ #handleAdapterStatus(accountId: string, status: { inbound?: string; detail?: string }): void {
478
+ if (this.#disabled.has(accountId)) return;
479
+ const account = this.#config.accounts.find((item) => item.id === accountId);
480
+ if (!account) return;
481
+ const key = `${account.platform}/${account.id}`;
482
+ if (status.inbound === "failed") {
483
+ const detail = sanitizeAccountError(`inbound failed: ${status.detail ?? "unknown"}`);
484
+ this.#accountStates.set(key, { state: "started", lastError: detail });
485
+ log.warn(detail, { account: accountId });
486
+ } else if (status.inbound === "ready") {
487
+ this.#accountStates.set(key, { state: "started" });
488
+ }
489
+ }
490
+
491
+ #setAccountState(
492
+ account: AccountConfig,
493
+ state: ChannelAccountRuntime["state"],
494
+ lastError?: string,
495
+ ): void {
496
+ this.#accountStates.set(
497
+ `${account.platform}/${account.id}`,
498
+ lastError ? { state, lastError } : { state },
499
+ );
500
+ }
501
+
386
502
  #disableAccount(accountId: string, reason: string): void {
387
503
  if (this.#disabled.has(accountId)) return;
388
504
  this.#disabled.add(accountId);
505
+ const account = this.#config.accounts.find((item) => item.id === accountId);
506
+ if (account) this.#setAccountState(account, "disabled", reason);
389
507
 
390
508
  const timer = this.#timers.get(accountId);
391
509
  if (timer) {
@@ -0,0 +1,26 @@
1
+ import type { ChannelConfig, InboundRoute } from "./config.ts";
2
+ import type { IngestEvent } from "./protocol.ts";
3
+
4
+ const MAX_RELAY_TEXT = 4000;
5
+
6
+ /** Inbound routes that turn one committed external event into a room notification. */
7
+ export function matchInboundRoutes(config: ChannelConfig, event: IngestEvent): InboundRoute[] {
8
+ return config.inbound.filter((route) =>
9
+ route.from.platform === event.source.platform
10
+ && route.from.account === event.source.accountId
11
+ && route.from.room === event.source.roomId
12
+ && (route.from.event === undefined || route.from.event === event.kind)
13
+ );
14
+ }
15
+
16
+ /**
17
+ * Room-notification text. The native user id is opaque but stable; the account
18
+ * label shows which Feishu bot and avoids exposing the chat id in room content.
19
+ */
20
+ export function inboundRoomText(event: IngestEvent, route: InboundRoute): string | undefined {
21
+ const text = event.content?.text?.trim();
22
+ if (!text) return undefined;
23
+ const actor = event.actor.nativeUserId || "unknown";
24
+ const body = text.length > MAX_RELAY_TEXT ? `${text.slice(0, MAX_RELAY_TEXT)}…` : text;
25
+ return `[Feishu ${route.from.account}] ${actor}: ${body}`;
26
+ }
@@ -92,6 +92,8 @@ export type CommitResult =
92
92
 
93
93
  export interface ChannelState {
94
94
  commitIngest(event: IngestEvent): CommitResult;
95
+ /** Remove a freshly committed event when a downstream consumer failed. */
96
+ deleteIngestEvent(eventId: string): void;
95
97
  enqueueDeliveries(
96
98
  triggerEventId: string,
97
99
  rule: RuleConfig,
@@ -110,6 +112,8 @@ export interface ChannelState {
110
112
  getPublishedResult(deliveryId: string): PublishedResultEvent | undefined;
111
113
  recordEcho(endpoint: string, nativeMessageId: string, logicalMessageId: string, deliveryId?: string): void;
112
114
  findEcho(endpoint: string, nativeMessageId: string): string | undefined;
115
+ /** Latest sent provider message for one logical message at one endpoint. */
116
+ findProviderMessage(endpoint: string, logicalMessageId: string): string | undefined;
113
117
  getDelivery(deliveryId: string): DeliveryRow | undefined;
114
118
  getEvent(eventId: string): IngestEvent | undefined;
115
119
  listDeliveries(): DeliveryRow[];
@@ -241,6 +245,10 @@ export function openState(path: string): ChannelState {
241
245
  });
242
246
  },
243
247
 
248
+ deleteIngestEvent(eventId) {
249
+ db.prepare("DELETE FROM channel_events WHERE event_id = ?").run(eventId);
250
+ },
251
+
244
252
  enqueueDeliveries(triggerEventId, rule, targets, payloads) {
245
253
  if (targets.length !== payloads.length) {
246
254
  throw new Error("enqueueDeliveries: targets and payloads must have the same length");
@@ -447,6 +455,15 @@ export function openState(path: string): ChannelState {
447
455
  return row ? String(row.logical_message_id) : undefined;
448
456
  },
449
457
 
458
+ findProviderMessage(endpoint, logicalMessageId) {
459
+ const row = db.prepare(
460
+ `SELECT native_message_id FROM channel_echoes
461
+ WHERE endpoint = ? AND logical_message_id = ? AND delivery_id IS NOT NULL
462
+ ORDER BY rowid DESC LIMIT 1`,
463
+ ).get(endpoint, logicalMessageId) as RawRow | undefined;
464
+ return row ? String(row.native_message_id) : undefined;
465
+ },
466
+
450
467
  getDelivery,
451
468
 
452
469
  getEvent(eventId) {
@@ -1,7 +1,17 @@
1
1
  import { DatabaseSync } from "node:sqlite";
2
2
 
3
+ export type ChannelAccountState = "started" | "failed" | "disabled" | "unknown";
4
+
5
+ /** Live state supplied by a running host; stats itself only reads SQLite. */
6
+ export interface ChannelAccountRuntime {
7
+ state: ChannelAccountState;
8
+ lastError?: string;
9
+ }
10
+
3
11
  export interface ChannelAccountStats {
4
12
  account: string;
13
+ state: ChannelAccountState;
14
+ lastError?: string;
5
15
  queueDepth: number;
6
16
  oldestBacklogAt: number | null;
7
17
  unknown: number;
@@ -35,9 +45,18 @@ export interface ChannelStats {
35
45
 
36
46
  const REQUIRED_TABLES = ["channel_events", "channel_deliveries", "channel_receipts"];
37
47
  const QUEUE_STATES = new Set(["pending", "retryable", "rate_limited"]);
48
+ const MAX_LAST_ERROR = 200;
38
49
 
39
50
  type Row = Record<string, unknown>;
40
51
 
52
+ /** Keep status details short and free of credential-shaped fragments. */
53
+ export function sanitizeAccountError(value: string): string {
54
+ const redacted = value
55
+ .replace(/\bBearer\s+\S+/gi, "Bearer [redacted]")
56
+ .replace(/\b(secret|token|password|passwd|authorization|api[_-]?key)\b\s*[:=]\s*\S+/gi, "$1=[redacted]");
57
+ return redacted.replace(/[\r\n\t]+/g, " ").replace(/\s+/g, " ").trim().slice(0, MAX_LAST_ERROR);
58
+ }
59
+
41
60
  function count(db: DatabaseSync, sql: string): number {
42
61
  const row = db.prepare(sql).get() as Row;
43
62
  return Number(row.count);
@@ -54,7 +73,11 @@ function accountKey(target: string): string {
54
73
  * Read queue and integrity counts without touching message content.
55
74
  * The database is opened read-only, so a missing state file is never created.
56
75
  */
57
- export function readChannelStats(path: string, now = Date.now()): ChannelStats {
76
+ export function readChannelStats(
77
+ path: string,
78
+ now = Date.now(),
79
+ runtime: ReadonlyMap<string, ChannelAccountRuntime> = new Map(),
80
+ ): ChannelStats {
58
81
  let db: DatabaseSync | undefined;
59
82
  try {
60
83
  db = new DatabaseSync(path, { readOnly: true });
@@ -83,6 +106,7 @@ export function readChannelStats(path: string, now = Date.now()): ChannelStats {
83
106
  if (!account) {
84
107
  account = {
85
108
  account: key,
109
+ state: "unknown",
86
110
  queueDepth: 0,
87
111
  oldestBacklogAt: null,
88
112
  unknown: 0,
@@ -106,6 +130,24 @@ export function readChannelStats(path: string, now = Date.now()): ChannelStats {
106
130
  }
107
131
  }
108
132
 
133
+ // Runtime entries add configured accounts without deliveries and override
134
+ // the SQLite-only default of "unknown" for a running host.
135
+ for (const [key, live] of runtime) {
136
+ const account = accounts.get(key) ?? {
137
+ account: key,
138
+ state: "unknown" as const,
139
+ queueDepth: 0,
140
+ oldestBacklogAt: null,
141
+ unknown: 0,
142
+ retryable: 0,
143
+ rateLimited: 0,
144
+ };
145
+ account.state = live.state;
146
+ const lastError = live.lastError ? sanitizeAccountError(live.lastError) : "";
147
+ if (lastError) account.lastError = lastError;
148
+ accounts.set(key, account);
149
+ }
150
+
109
151
  const pending = stateCounts.pending ?? 0;
110
152
  const retryable = stateCounts.retryable ?? 0;
111
153
  const rateLimited = stateCounts.rate_limited ?? 0;
@@ -1,14 +1,14 @@
1
1
  import { Buffer } from "node:buffer";
2
2
  import { createHash, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
3
- import type { Database, SQLQueryBindings } from "../src/state/sqlite.ts";
3
+ import type { SQLQueryBindings, StateDatabase } from "../src/state/sqlite.ts";
4
4
  import { databasePath } from "../src/state/store.ts";
5
5
  import { initializeAdminSchema, withStateTransaction } from "../src/state/sqlite-state.ts";
6
6
 
7
7
  const hash = (value: string) => createHash("sha256").update(value).digest("hex");
8
8
  const secret = () => randomBytes(32).toString("base64url");
9
- const row = <T>(db: Database, sql: string, ...args: SQLQueryBindings[]) => db.query(sql).get(...args) as T | null;
10
- const all = <T>(db: Database, sql: string, ...args: SQLQueryBindings[]) => db.query(sql).all(...args) as T[];
11
- const run = (db: Database, sql: string, ...args: SQLQueryBindings[]) => db.query(sql).run(...args);
9
+ const row = <T>(db: StateDatabase, sql: string, ...args: SQLQueryBindings[]) => db.query(sql).get(...args) as T | null;
10
+ const all = <T>(db: StateDatabase, sql: string, ...args: SQLQueryBindings[]) => db.query(sql).all(...args) as T[];
11
+ const run = (db: StateDatabase, sql: string, ...args: SQLQueryBindings[]) => db.query(sql).run(...args);
12
12
  export type AdminRoom = { roomId: string; targetRoomId: string; sessionID: string; receiverOwnerID: string; membershipID: string; generation: number; enrolled: boolean; createdAt: number };
13
13
  export type Binding = { room_id: string; target_room_id: string; session_id: string; receiver_owner_id: string; membership_id: string; generation: number; enrollment_hash: string; enrollment_expires: number; capability_hash: string | null; created_at: number };
14
14
  export const digest = hash;
@@ -36,19 +36,19 @@ export async function ensureAdminSchema() {
36
36
  db.query("INSERT INTO server_admin_migrations(version,applied_at) VALUES(1,?)").run(Date.now());
37
37
  });
38
38
  }
39
- export async function tx<T>(fn: (db: Database) => T) { await ensureAdminSchema(); return withStateTransaction(databasePath(), fn); }
39
+ export async function tx<T>(fn: (db: StateDatabase) => T) { await ensureAdminSchema(); return withStateTransaction(databasePath(), fn); }
40
40
  export function publicRoom(b: Binding): AdminRoom { return { roomId: b.room_id, targetRoomId: b.target_room_id, sessionID: b.session_id, receiverOwnerID: b.receiver_owner_id, membershipID: b.membership_id, generation: b.generation, enrolled: Boolean(b.capability_hash), createdAt: b.created_at }; }
41
- export function binding(db: Database, roomID: string) { return row<Binding>(db, "SELECT * FROM admin_rooms WHERE room_id=?", roomID); }
42
- export function currentMember(db: Database, b: Binding) {
41
+ export function binding(db: StateDatabase, roomID: string) { return row<Binding>(db, "SELECT * FROM admin_rooms WHERE room_id=?", roomID); }
42
+ export function currentMember(db: StateDatabase, b: Binding) {
43
43
  return row(db, `SELECT g.membership_id,g.receiver_owner_id,g.protocol,g.host,p.id AS participant_id
44
44
  FROM registry g JOIN participants p ON p.room_id=g.room_id AND p.id=CASE WHEN (SELECT kind FROM rooms WHERE id=g.room_id)='direct' THEN g.session_id ELSE g.name END
45
45
  WHERE g.room_id=? AND g.session_id=?`, b.target_room_id, b.session_id) as { membership_id: string; receiver_owner_id: string | null; protocol: string | null; host: string | null; participant_id: string } | null;
46
46
  }
47
- export function validCurrent(db: Database, b: Binding): boolean {
47
+ export function validCurrent(db: StateDatabase, b: Binding): boolean {
48
48
  const m = currentMember(db, b);
49
49
  return !!m && m.membership_id === b.membership_id && (m.receiver_owner_id ?? "") === b.receiver_owner_id && (m.protocol === "v1" || m.protocol === "v2" || Boolean(m.host));
50
50
  }
51
- export function enroll(db: Database, roomID: string, targetRoomID: string, sessionID: string, ownerID: string, membershipID: string, generation: number, createdAt = Date.now()) {
51
+ export function enroll(db: StateDatabase, roomID: string, targetRoomID: string, sessionID: string, ownerID: string, membershipID: string, generation: number, createdAt = Date.now()) {
52
52
  if (!row(db, "SELECT 1 FROM rooms WHERE id=? AND kind='group'", roomID) || !row(db, "SELECT 1 FROM rooms WHERE id=?", targetRoomID)) return undefined;
53
53
  const nextKey = secret(), expiresAt = Date.now() + 600_000;
54
54
  run(db, `INSERT INTO admin_rooms(room_id,target_room_id,session_id,receiver_owner_id,membership_id,generation,enrollment_hash,enrollment_expires,capability_hash,created_at)
@@ -56,18 +56,18 @@ export function enroll(db: Database, roomID: string, targetRoomID: string, sessi
56
56
  roomID, targetRoomID, sessionID, ownerID, membershipID, generation, hash(nextKey), expiresAt, createdAt);
57
57
  return { enrollmentKey: nextKey, expiresAt };
58
58
  }
59
- export function isAgentMember(db: Database, roomID: string, sessionID: string, ownerID: string, membershipID: string) {
59
+ export function isAgentMember(db: StateDatabase, roomID: string, sessionID: string, ownerID: string, membershipID: string) {
60
60
  const entry = row<{ membership_id: string; receiver_owner_id: string | null; protocol: string | null; host: string | null }>(db,
61
61
  `SELECT g.membership_id,g.receiver_owner_id,g.protocol,g.host FROM registry g JOIN participants p ON p.room_id=g.room_id AND p.id=CASE WHEN (SELECT kind FROM rooms WHERE id=g.room_id)='direct' THEN g.session_id ELSE g.name END WHERE g.room_id=? AND g.session_id=?`, roomID, sessionID);
62
62
  return !!entry && entry.membership_id === membershipID && (entry.receiver_owner_id ?? "") === ownerID && (entry.protocol === "v1" || entry.protocol === "v2" || Boolean(entry.host));
63
63
  }
64
64
  export type Recipient = { roomID: string; sessionID: string; ownerID: string; membershipID: string };
65
- export function queue(db: Database, b: Binding, kind: string, text: string, taskID: string | null = null, taskToken: string | null = null, recipient: Recipient = { roomID: b.target_room_id, sessionID: b.session_id, ownerID: b.receiver_owner_id, membershipID: b.membership_id }) {
65
+ export function queue(db: StateDatabase, b: Binding, kind: string, text: string, taskID: string | null = null, taskToken: string | null = null, recipient: Recipient = { roomID: b.target_room_id, sessionID: b.session_id, ownerID: b.receiver_owner_id, membershipID: b.membership_id }) {
66
66
  const id = randomUUID();
67
67
  run(db, `INSERT INTO admin_deliveries(id,admin_room_id,generation,recipient_room_id,session_id,owner_id,membership_id,kind,text,task_id,task_token,admission_id,created_at)
68
68
  VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?) ON CONFLICT(admin_room_id,kind,task_id) DO UPDATE SET text=excluded.text,task_token=excluded.task_token,generation=excluded.generation,recipient_room_id=excluded.recipient_room_id,session_id=excluded.session_id,owner_id=excluded.owner_id,membership_id=excluded.membership_id,created_at=excluded.created_at,acknowledged=0`,
69
69
  id,b.room_id,b.generation,recipient.roomID,recipient.sessionID,recipient.ownerID,recipient.membershipID,kind,text,taskID,taskToken,`msg_${id}`,Date.now());
70
70
  }
71
- export function one<T>(db: Database, sql: string, ...args: SQLQueryBindings[]) { return row<T>(db, sql, ...args); }
72
- export function many<T>(db: Database, sql: string, ...args: SQLQueryBindings[]) { return all<T>(db, sql, ...args); }
71
+ export function one<T>(db: StateDatabase, sql: string, ...args: SQLQueryBindings[]) { return row<T>(db, sql, ...args); }
72
+ export function many<T>(db: StateDatabase, sql: string, ...args: SQLQueryBindings[]) { return all<T>(db, sql, ...args); }
73
73
  export { run as exec, randomUUID };
package/server/app.ts ADDED
@@ -0,0 +1,95 @@
1
+ // Central-mode HTTP app: page serving, auth gate and ordered route wiring.
2
+ import { RoomError } from "../src/rooms/room-service.ts";
3
+ import { adminRoutes } from "./admin-routes.ts";
4
+ import { addressingRoutes } from "./addressing-routes.ts";
5
+ import type { ChannelController } from "./channels.ts";
6
+ import { historyRoute } from "./history-route.ts";
7
+ import { joinRequestRoutes } from "./join-requests.ts";
8
+ import { memberRoutes } from "./member-routes.ts";
9
+ import { messageRecallRoutes } from "./message-recall-routes.ts";
10
+ import { roomManagement } from "./newrooms.ts";
11
+ import { resourceRoutes } from "./resource-routes.ts";
12
+ import { roomReminderRoutes } from "./room-reminders.ts";
13
+ import { inboxRoutes } from "./routes/inbox.ts";
14
+ import { pageRoutes } from "./routes/pages.ts";
15
+ import { questionRoutes } from "./routes/questions.ts";
16
+ import { roomActionRoutes } from "./routes/room-actions.ts";
17
+ import { roomCreateRoute, roomDetailRoutes, roomListRoutes } from "./routes/rooms.ts";
18
+
19
+ export type AppOptions = {
20
+ here: string;
21
+ token?: string;
22
+ serveWakeUrl: string;
23
+ channeld: () => ChannelController | undefined;
24
+ };
25
+
26
+ const json = (body: unknown, status = 200) =>
27
+ new Response(JSON.stringify(body), {
28
+ status,
29
+ headers: { "Content-Type": "application/json" },
30
+ });
31
+
32
+ export function createApp(options: AppOptions): (req: Request) => Promise<Response> {
33
+ // Database callbacks finish synchronously before any HTTP or long-poll wait.
34
+ return async function handle(req: Request): Promise<Response> {
35
+ const url = new URL(req.url);
36
+ const p = url.pathname;
37
+ const page = await pageRoutes(req, url, options.here, options.channeld()?.enabled ?? false);
38
+ if (page) return page;
39
+ // ponytail: F1 — reject non-JSON POSTs; a text/plain simple request from a
40
+ // malicious page would otherwise mutate rooms cross-origin (no preflight)
41
+ if (
42
+ ["POST", "PUT", "PATCH", "DELETE"].includes(req.method) &&
43
+ !req.headers.get("content-type")?.includes("application/json") &&
44
+ !(/^\/rooms\/[^/]+\/resources$/.test(p) && req.method === "POST")
45
+ ) {
46
+ return json({ error: "content-type must be application/json" }, 415);
47
+ }
48
+ if (options.token && req.headers.get("authorization") !== `Bearer ${options.token}`) {
49
+ return json({ error: "unauthorized" }, 401);
50
+ }
51
+ try {
52
+ const reminders = await roomReminderRoutes(req, url);
53
+ if (reminders) return reminders;
54
+ const admin = await adminRoutes(req, url); if (admin) return admin;
55
+ const resource = await resourceRoutes(req, url);
56
+ if (resource) return resource;
57
+ const history = await historyRoute(url);
58
+ if (history) return history;
59
+ const addressing = await addressingRoutes(req, url);
60
+ if (addressing) return addressing;
61
+ const recall = await messageRecallRoutes(req, url);
62
+ if (recall) return recall;
63
+ const channel = await options.channeld()?.handle(req, url);
64
+ if (channel) return channel;
65
+ const listed = await roomListRoutes(req, url);
66
+ if (listed) return listed;
67
+ const members = await memberRoutes(req, url);
68
+ if (members) return members;
69
+ const joinRequests = await joinRequestRoutes(req, url);
70
+ if (joinRequests) return joinRequests;
71
+ const management = await roomManagement(req, url);
72
+ if (management) return management;
73
+ const created = await roomCreateRoute(req, url);
74
+ if (created) return created;
75
+ const inbox = await inboxRoutes(req, url);
76
+ if (inbox) return inbox;
77
+ const actions = await roomActionRoutes(req, url, options.serveWakeUrl);
78
+ if (actions) return actions;
79
+ const questions = await questionRoutes(req, url, options.serveWakeUrl);
80
+ if (questions) return questions;
81
+ const detail = await roomDetailRoutes(req, url);
82
+ if (detail) return detail;
83
+ return json({ error: "not found" }, 404);
84
+ } catch (err) {
85
+ if (err instanceof SyntaxError) return json({ error: "invalid JSON body" }, 400);
86
+ if (err instanceof RoomError) {
87
+ return json(
88
+ { error: err.message },
89
+ err.code === "ROOM_NOT_FOUND" ? 404 : err.code === "NOT_OWNER" ? 403 : 409,
90
+ );
91
+ }
92
+ return json({ error: err instanceof Error ? err.message : String(err) }, 500);
93
+ }
94
+ };
95
+ }
@@ -3,7 +3,8 @@ Browser vendors bundled locally; no external requests are made at runtime.
3
3
  marked 18.0.4 — MIT License, see MARKED-LICENSE.
4
4
  DOMPurify 3.4.7 — MPL 2.0 or Apache License 2.0, see DOMPURIFY-LICENSE.
5
5
  Mermaid 11.12.2 — MIT License, see MERMAID-LICENSE.
6
+ Monaco Editor 0.58.0 — MIT License, see monaco/LICENSE and monaco/ThirdPartyNotices.txt.
6
7
  Shiki 4.6.0 — MIT License, see SHIKI-LICENSE.
7
8
  Fluent System Icons (@fluentui/svg-icons 1.1.347) — MIT License, see FLUENT-ICONS-LICENSE.
8
9
 
9
- Sources: https://www.npmjs.com/package/marked, https://www.npmjs.com/package/dompurify, https://www.npmjs.com/package/mermaid, https://www.npmjs.com/package/shiki and https://github.com/microsoft/fluentui-system-icons
10
+ Sources: https://www.npmjs.com/package/marked, https://www.npmjs.com/package/dompurify, https://www.npmjs.com/package/mermaid, https://www.npmjs.com/package/shiki, https://www.npmjs.com/package/monaco-editor and https://github.com/microsoft/fluentui-system-icons
@@ -223,11 +223,16 @@
223
223
 
224
224
  .hint { margin: 8px 0 0; font-size: 12.5px; color: var(--ink-3); }
225
225
 
226
- .panel.announcement-panel { width: min(390px, calc(100vw - 32px)); max-height: min(65dvh, 560px); overflow: auto; }
227
- .announcement-head, .announcement-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
228
- .announcement-head h3 { margin: 0; font-size: 15px; }
229
- .announcement-tools { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
230
- .panel .announcement-tools .btn, .panel .reminder-tools .btn { margin: 0; padding: 6px 9px; font-size: 12px; }
226
+ .announcement-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
227
+ #announcementsDialog, #remindersDialog { width: min(600px, calc(100vw - 32px)); max-height: min(760px, 86dvh); padding: 0; overflow: hidden; }
228
+ #announcementsDialog[open], #remindersDialog[open] { display: flex; flex-direction: column; }
229
+ .announcements-dialog .admin-dialog-head, .reminders-dialog .admin-dialog-head { flex: none; flex-wrap: wrap; padding: 18px 20px 12px; }
230
+ .announcements-dialog .admin-dialog-actions { flex-wrap: wrap; justify-content: flex-end; }
231
+ .announcements-body, .reminders-body { flex: 1 1 auto; min-height: 0; padding: 0 20px 20px; overflow-y: auto; }
232
+ #announcementsDialog.is-pane .admin-dialog-head, #remindersDialog.is-pane .admin-dialog-head { padding: 16px 12px 10px 18px; }
233
+ #announcementsDialog.is-pane .announcements-body, #remindersDialog.is-pane .reminders-body { padding: 0 14px 18px 18px; }
234
+ .announcements-dialog .announcement-list { margin: 0; max-height: none; }
235
+ .reminders-dialog .reminder-list { margin: 0; }
231
236
  .announcement-list { list-style: none; padding: 0; margin: 10px 0; max-height: 150px; overflow: auto; }
232
237
  .announcement-list button { width: 100%; padding: 8px 10px; border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--ink); text-align: left; font: inherit; overflow-wrap: anywhere; cursor: pointer; }
233
238
  .announcement-list button:hover, .announcement-list button[aria-current="true"] { background: var(--accent-soft); border-color: var(--line); }
@@ -258,8 +263,6 @@
258
263
  .btn.danger:hover { filter: brightness(.94); }
259
264
  .announcement-content { white-space: pre-wrap; overflow-wrap: anywhere; }
260
265
 
261
- .panel.reminder-panel { width: min(410px, calc(100vw - 32px)); max-height: min(72dvh, 640px); overflow: auto; }
262
- .reminder-tools { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
263
266
  .reminder-form { border-top: 1px solid var(--line); padding-top: 10px; }
264
267
  #reminderDialog .reminder-form { border: 0; padding: 18px 20px; }
265
268
  #reminderDialog .reminder-form .field { margin-bottom: 12px; }
@@ -320,12 +323,15 @@
320
323
  .keys-section + .keys-section { margin-top: 16px; }
321
324
  .keys-section h3 { margin: 0 0 7px; color: var(--ink-3); font-size: 10.5px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
322
325
  .keys-list { display: grid; gap: 2px; list-style: none; margin: 0; padding: 0; }
323
- .keys-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 0; border-top: 1px solid color-mix(in srgb, var(--line) 72%, transparent); font-size: 13px; }
326
+ .keys-list li { display: grid; grid-template-columns: max-content minmax(0, 1fr); align-items: center; gap: 4px 16px; padding: 7px 0; border-top: 1px solid color-mix(in srgb, var(--line) 72%, transparent); font-size: 13px; }
324
327
  .keys-list li:first-child { border-top: 0; }
325
- .keys-list li > span:last-child { color: var(--ink-2); text-align: right; }
328
+ .keys-list li > span:last-child { color: var(--ink-2); }
329
+ .keys-group { display: inline-flex; align-items: center; gap: 6px; }
326
330
  @media (max-width: 560px) {
327
331
  .keys-dialog { padding: 18px; }
328
332
  .keys-dialog-head h2 { font-size: 21px; }
333
+ .keys-list li { grid-template-columns: minmax(0, max-content) minmax(0, 1fr); gap: 4px 10px; }
334
+ .keys-group { flex-wrap: wrap; }
329
335
  }
330
336
  .room-list { margin-top: 0; }
331
337
  .room-list h2 { margin: 0 0 8px; font-size: 13px; font-weight: 600; letter-spacing: .06em; color: var(--ink-2); }