@alexsun-top/opencode-chat-room 0.8.4 → 0.8.6
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/CHANGELOG.md +17 -3
- package/README.md +5 -5
- package/README.zh-CN.md +5 -5
- package/cli.ts +20 -1
- package/dist/cli.js +3785 -1462
- package/package.json +19 -11
- package/packages/chat-room-channeld/README.md +16 -10
- package/packages/chat-room-channeld/src/delivery.ts +0 -4
- package/packages/chat-room-channeld/src/host.ts +48 -37
- package/packages/chat-room-channeld/src/inbound.ts +3 -6
- package/packages/chat-room-channeld/src/pg/database.ts +141 -49
- package/packages/chat-room-channeld/src/pg/sql.mjs +157 -142
- package/packages/chat-room-channeld/src/pg/sql.mts +175 -0
- package/packages/chat-room-channeld/src/pg/worker.mjs +148 -99
- package/packages/chat-room-channeld/src/pg/worker.mts +201 -0
- package/packages/chat-room-channeld/src/state-rows.ts +132 -0
- package/packages/chat-room-channeld/src/state.ts +129 -157
- package/plugin.ts +21 -5
- package/server/app.ts +9 -0
- package/server/assets/base.css +22 -2
- package/server/assets/chat/admin.js +17 -1
- package/server/assets/chat/announcements.js +79 -34
- package/server/assets/chat/attachments.js +3 -3
- package/server/assets/chat/clipboard.js +1 -1
- package/server/assets/chat/confirm-dialog.js +3 -0
- package/server/assets/chat/copy-action.js +1 -1
- package/server/assets/chat/create-room-dialog.js +7 -0
- package/server/assets/chat/diagram-viewer.js +4 -8
- package/server/assets/chat/doc-preview.js +71 -31
- package/server/assets/chat/editor.js +49 -10
- package/server/assets/chat/events.js +13 -6
- package/server/assets/chat/files.js +33 -27
- package/server/assets/chat/history-loader.js +31 -15
- package/server/assets/chat/integration-editor.js +27 -1
- package/server/assets/chat/integrations.js +108 -16
- package/server/assets/chat/join-requests.js +40 -2
- package/server/assets/chat/locales/de.js +5 -3
- package/server/assets/chat/locales/es.js +5 -3
- package/server/assets/chat/locales/fr.js +5 -3
- package/server/assets/chat/locales/it.js +5 -3
- package/server/assets/chat/locales/ja.js +5 -3
- package/server/assets/chat/locales/ko.js +5 -3
- package/server/assets/chat/markdown-footnotes.js +27 -15
- package/server/assets/chat/markdown.js +6 -12
- package/server/assets/chat/members.js +34 -22
- package/server/assets/chat/mentions.js +8 -5
- package/server/assets/chat/message-cache.js +9 -3
- package/server/assets/chat/message-polling.js +10 -4
- package/server/assets/chat/message-window.js +58 -1
- package/server/assets/chat/messages.js +90 -37
- package/server/assets/chat/office-preview.js +3 -3
- package/server/assets/chat/operator.js +624 -0
- package/server/assets/chat/palette.js +7 -10
- package/server/assets/chat/panels.js +42 -0
- package/server/assets/chat/questions.js +75 -58
- package/server/assets/chat/recall.js +14 -5
- package/server/assets/chat/receipts.js +63 -7
- package/server/assets/chat/refresh-timing.js +6 -0
- package/server/assets/chat/reminders.js +47 -13
- package/server/assets/chat/replies.js +39 -25
- package/server/assets/chat/resource-format.js +6 -3
- package/server/assets/chat/room-list.js +202 -3
- package/server/assets/chat/room-watcher.js +3 -1
- package/server/assets/chat/rooms.js +29 -7
- package/server/assets/chat/settings.js +37 -6
- package/server/assets/chat/shortcuts.js +3 -1
- package/server/assets/chat/side-pane.js +1 -1
- package/server/assets/chat/state.js +51 -18
- package/server/assets/chat/system-events.js +3 -2
- package/server/assets/chat/system-messages.js +15 -15
- package/server/assets/chat/tasks.js +37 -14
- package/server/assets/chat/window-controls.js +25 -15
- package/server/assets/code-highlight.css +0 -13
- package/server/assets/conversation.css +45 -5
- package/server/assets/doc-preview.css +9 -0
- package/server/assets/files.css +4 -0
- package/server/assets/monaco/integration-rules.js +1 -1
- package/server/assets/office/THIRD-PARTY-NOTICES.txt +23 -1
- package/server/assets/office/licenses/docx-preview-HEADER.txt +6 -0
- package/server/assets/office/licenses/echarts-LICENSE-d3.txt +27 -0
- package/server/assets/office/licenses/echarts-NOTICE.txt +5 -0
- package/server/assets/office/licenses/immediate-LICENSE.txt +20 -0
- package/server/assets/office/licenses/lie-LICENSE.txt +7 -0
- package/server/assets/office/licenses/pako-LICENSE.txt +21 -0
- package/server/assets/office/licenses/pako-ZLIB.txt +18 -0
- package/server/assets/office/licenses/setimmediate-LICENSE.txt +20 -0
- package/server/assets/responsive.css +12 -2
- package/server/assets/settings.css +3 -1
- package/server/assets/tasks.css +6 -1
- package/server/assets/window-controls.css +3 -1
- package/server/channels.ts +3 -2
- package/server/chat.html +7 -2
- package/server/inbox.ts +3 -1
- package/server/join-requests.ts +8 -1
- package/server/member-routes.ts +16 -2
- package/server/newrooms.ts +2 -13
- package/server/operator-auth.ts +21 -0
- package/server/operator-routes.ts +150 -0
- package/server/operator-state.ts +64 -0
- package/server/operator.css +139 -0
- package/server/room-owner.ts +17 -0
- package/server/routes/inbox.ts +15 -5
- package/server/routes/pages.ts +12 -2
- package/server/routes/room-actions.ts +4 -3
- package/server/sw.js +3 -1
- package/server/system.html +109 -0
- package/server/wake.ts +1 -1
- package/skills/chatroom/SKILL.md +9 -0
- package/src/README.md +1 -1
- package/src/acp/client.ts +254 -0
- package/src/acp/protocol.ts +300 -0
- package/src/acp/watch.ts +498 -0
- package/src/agent/agent-receipts.ts +98 -8
- package/src/center/center-client.ts +6 -1
- package/src/center/center-inbox.ts +54 -7
- package/src/center/center-wake.ts +57 -3
- package/src/center/forward-client.ts +48 -0
- package/src/center/mentions.ts +16 -3
- package/src/center/notification-delay.ts +139 -0
- package/src/center/queue.ts +3 -0
- package/src/config/file-config.ts +25 -0
- package/src/mcp/server.ts +389 -0
- package/src/protocol/config.ts +7 -0
- package/src/runtime/plugin-notifications.ts +43 -9
- package/src/runtime/v2-plugin.ts +14 -3
- package/src/runtime/v2-receiver.ts +10 -2
- package/src/runtime/watch.ts +5 -1
- package/src/state/pg-database.ts +133 -49
- package/src/state/pg-sql.mjs +157 -142
- package/src/state/pg-sql.mts +175 -0
- package/src/state/pg-worker.mjs +148 -99
- package/src/state/pg-worker.mts +201 -0
- package/src/state/receiver-state.ts +47 -0
- package/src/state/sqlite-database.ts +6 -2
- package/src/state/sqlite-members.ts +48 -4
- package/src/state/sqlite-messages.ts +25 -12
- package/src/state/sqlite-schema.ts +4 -1
- package/src/state/sqlite-state.ts +1 -1
- package/src/state/store.ts +31 -11
- package/src/tui/app-types.mjs +1 -0
- package/src/tui/app-types.mts +175 -0
- package/src/tui/app.mjs +473 -423
- package/src/tui/app.mts +543 -0
- package/src/tui/config.mjs +166 -158
- package/src/tui/config.mts +247 -0
- package/src/tui/http.mjs +239 -206
- package/src/tui/http.mts +412 -0
- package/src/tui/i18n.mjs +17 -20
- package/src/tui/i18n.mts +42 -0
- package/src/tui/info-app.mjs +431 -427
- package/src/tui/info-app.mts +500 -0
- package/src/tui/info-content.mjs +205 -199
- package/src/tui/info-content.mts +341 -0
- package/src/tui/join-app.mjs +75 -64
- package/src/tui/join-app.mts +99 -0
- package/src/tui/locales/en.mjs +302 -320
- package/src/tui/locales/en.mts +349 -0
- package/src/tui/locales/zh-CN.mjs +302 -320
- package/src/tui/locales/zh-CN.mts +349 -0
- package/src/tui/main.mjs +219 -213
- package/src/tui/main.mts +255 -0
- package/src/tui/markdown.mjs +128 -272
- package/src/tui/markdown.mts +152 -0
- package/src/tui/mentions.mjs +181 -184
- package/src/tui/mentions.mts +251 -0
- package/src/tui/message-app.mjs +181 -173
- package/src/tui/message-app.mts +213 -0
- package/src/tui/message-view.mjs +90 -111
- package/src/tui/message-view.mts +151 -0
- package/src/tui/messages.mjs +55 -49
- package/src/tui/messages.mts +106 -0
- package/src/tui/palette-app.mjs +364 -344
- package/src/tui/palette-app.mts +388 -0
- package/src/tui/palette.mjs +100 -98
- package/src/tui/palette.mts +176 -0
- package/src/tui/prefs.mjs +56 -63
- package/src/tui/prefs.mts +126 -0
- package/src/tui/reminder-app.mjs +191 -181
- package/src/tui/reminder-app.mts +228 -0
- package/src/tui/room-settings-app.mjs +275 -242
- package/src/tui/room-settings-app.mts +318 -0
- package/src/tui/session.mjs +30 -29
- package/src/tui/session.mts +51 -0
- package/src/tui/settings-app.mjs +151 -138
- package/src/tui/settings-app.mts +179 -0
- package/src/tui/ui-content.mjs +426 -421
- package/src/tui/ui-content.mts +499 -0
- package/src/tui/ui-help.mjs +58 -67
- package/src/tui/ui-help.mts +87 -0
- package/src/tui/ui-mentions.mjs +34 -36
- package/src/tui/ui-mentions.mts +60 -0
- package/src/tui/ui-overlay-view.mjs +259 -267
- package/src/tui/ui-overlay-view.mts +322 -0
- package/src/tui/ui-suggest-view.mjs +54 -57
- package/src/tui/ui-suggest-view.mts +78 -0
- package/src/tui/ui-suggest.mjs +164 -167
- package/src/tui/ui-suggest.mts +248 -0
- package/src/tui/ui-theme.mjs +52 -57
- package/src/tui/ui-theme.mts +98 -0
- package/src/tui/ui-view.mjs +267 -275
- package/src/tui/ui-view.mts +308 -0
- package/src/tui/ui.mjs +372 -359
- package/src/tui/ui.mts +440 -0
- package/src/tui/wire.mjs +215 -0
- package/src/tui/wire.mts +383 -0
- package/src/web/integration-rules-editor.ts +25 -2
|
@@ -6,6 +6,23 @@ import { Database, type StateDatabase } from "./pg/sqlite.ts";
|
|
|
6
6
|
import type { IngestEvent } from "./protocol.ts";
|
|
7
7
|
import { buildPublishedResult, PUBLISHED_RESULT_PREFIX, type PublishedResultEvent } from "./published.ts";
|
|
8
8
|
import { accountKey } from "./stats.ts";
|
|
9
|
+
import {
|
|
10
|
+
DELIVERY_STATES,
|
|
11
|
+
TERMINAL_DELIVERY_STATES,
|
|
12
|
+
isTerminalDeliveryState,
|
|
13
|
+
toDelivery,
|
|
14
|
+
toReceipt,
|
|
15
|
+
type CommitResult,
|
|
16
|
+
type CreatedDelivery,
|
|
17
|
+
type DeliveryPatch,
|
|
18
|
+
type DeliveryRow,
|
|
19
|
+
type DeliveryState,
|
|
20
|
+
type PlannedDelivery,
|
|
21
|
+
type RawRow,
|
|
22
|
+
type ReceiptInput,
|
|
23
|
+
type ReceiptRow,
|
|
24
|
+
type SentRecordInput,
|
|
25
|
+
} from "./state-rows.ts";
|
|
9
26
|
|
|
10
27
|
export {
|
|
11
28
|
readChannelStats,
|
|
@@ -14,92 +31,34 @@ export {
|
|
|
14
31
|
type ChannelStats,
|
|
15
32
|
} from "./stats.ts";
|
|
16
33
|
export type { PublishedResultEvent } from "./published.ts";
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
export const TERMINAL_DELIVERY_STATES: readonly DeliveryState[] = [
|
|
34
|
-
"sent",
|
|
35
|
-
"permanent",
|
|
36
|
-
"unsupported",
|
|
37
|
-
"exhausted",
|
|
38
|
-
"unknown",
|
|
39
|
-
];
|
|
40
|
-
|
|
41
|
-
export function isTerminalDeliveryState(state: DeliveryState): boolean {
|
|
42
|
-
return TERMINAL_DELIVERY_STATES.includes(state);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface DeliveryPatch {
|
|
46
|
-
attemptCount?: number;
|
|
47
|
-
nextAttemptAt?: number | null;
|
|
48
|
-
lastError?: string | null;
|
|
49
|
-
providerMessage?: string | null;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface DeliveryRow {
|
|
53
|
-
deliveryId: string;
|
|
54
|
-
eventId: string;
|
|
55
|
-
ruleId: string;
|
|
56
|
-
ruleVersion: number;
|
|
57
|
-
target: string;
|
|
58
|
-
idempotencyKey: string;
|
|
59
|
-
payload: string;
|
|
60
|
-
state: DeliveryState;
|
|
61
|
-
attemptCount: number;
|
|
62
|
-
nextAttemptAt: number | null;
|
|
63
|
-
lastError: string | null;
|
|
64
|
-
providerMessage: string | null;
|
|
65
|
-
createdAt: number;
|
|
66
|
-
updatedAt: number;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export interface ReceiptRow {
|
|
70
|
-
receiptId: string;
|
|
71
|
-
deliveryId: string;
|
|
72
|
-
attemptId: string;
|
|
73
|
-
state: string;
|
|
74
|
-
providerMessage: string | null;
|
|
75
|
-
detail: string | null;
|
|
76
|
-
observedAt: number;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export interface SentRecordInput {
|
|
80
|
-
deliveryId: string;
|
|
81
|
-
attemptId: string;
|
|
82
|
-
providerMessage: string | null;
|
|
83
|
-
detail?: string | null;
|
|
84
|
-
observedAt?: number;
|
|
85
|
-
echo?: { endpoint: string; nativeMessageId: string; logicalMessageId: string };
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export interface ReceiptInput {
|
|
89
|
-
deliveryId: string;
|
|
90
|
-
attemptId: string;
|
|
91
|
-
state: string;
|
|
92
|
-
providerMessage?: string | null;
|
|
93
|
-
detail?: string | null;
|
|
94
|
-
observedAt?: number;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export type CommitResult =
|
|
98
|
-
| { duplicate: true; existingEventId: string }
|
|
99
|
-
| { duplicate: false; eventId: string; ingressSeq: number };
|
|
34
|
+
export {
|
|
35
|
+
DELIVERY_STATES,
|
|
36
|
+
TERMINAL_DELIVERY_STATES,
|
|
37
|
+
isTerminalDeliveryState,
|
|
38
|
+
};
|
|
39
|
+
export type {
|
|
40
|
+
CommitResult,
|
|
41
|
+
CreatedDelivery,
|
|
42
|
+
DeliveryPatch,
|
|
43
|
+
DeliveryRow,
|
|
44
|
+
DeliveryState,
|
|
45
|
+
PlannedDelivery,
|
|
46
|
+
ReceiptInput,
|
|
47
|
+
ReceiptRow,
|
|
48
|
+
SentRecordInput,
|
|
49
|
+
};
|
|
100
50
|
|
|
101
51
|
export interface ChannelState {
|
|
102
52
|
commitIngest(event: IngestEvent): CommitResult;
|
|
53
|
+
/**
|
|
54
|
+
* Commit the event and its outbound plan in one transaction. The plan callback
|
|
55
|
+
* runs only for a new event and receives the stored event with its ingressSeq,
|
|
56
|
+
* so a duplicate never re-plans against changed config.
|
|
57
|
+
*/
|
|
58
|
+
commitIngestWithPlan(
|
|
59
|
+
event: IngestEvent,
|
|
60
|
+
plan: (stored: IngestEvent) => PlannedDelivery[],
|
|
61
|
+
): { result: CommitResult; created: CreatedDelivery[] };
|
|
103
62
|
/** Remove a freshly committed event when a downstream consumer failed. */
|
|
104
63
|
deleteIngestEvent(eventId: string): void;
|
|
105
64
|
enqueueDeliveries(
|
|
@@ -107,7 +66,7 @@ export interface ChannelState {
|
|
|
107
66
|
rule: RuleConfig,
|
|
108
67
|
targets: RuleTarget[],
|
|
109
68
|
payloads: string[],
|
|
110
|
-
):
|
|
69
|
+
): CreatedDelivery[];
|
|
111
70
|
nextPendingDelivery(accountKey: string, now: number): DeliveryRow | undefined;
|
|
112
71
|
markDelivery(deliveryId: string, state: DeliveryState, patch?: DeliveryPatch): void;
|
|
113
72
|
recordSent(input: SentRecordInput): string;
|
|
@@ -130,8 +89,6 @@ export interface ChannelState {
|
|
|
130
89
|
close(): void;
|
|
131
90
|
}
|
|
132
91
|
|
|
133
|
-
type RawRow = Record<string, unknown>;
|
|
134
|
-
|
|
135
92
|
function transaction<T>(db: StateDatabase, fn: () => T): T {
|
|
136
93
|
return db.transaction(fn).immediate();
|
|
137
94
|
}
|
|
@@ -141,37 +98,6 @@ function likePrefix(value: string): string {
|
|
|
141
98
|
return `${value.replace(/[\\%_]/g, (ch) => `\\${ch}`)}%`;
|
|
142
99
|
}
|
|
143
100
|
|
|
144
|
-
function toDelivery(row: RawRow): DeliveryRow {
|
|
145
|
-
return {
|
|
146
|
-
deliveryId: String(row.delivery_id),
|
|
147
|
-
eventId: String(row.event_id),
|
|
148
|
-
ruleId: String(row.rule_id),
|
|
149
|
-
ruleVersion: Number(row.rule_version),
|
|
150
|
-
target: String(row.target),
|
|
151
|
-
idempotencyKey: String(row.idempotency_key),
|
|
152
|
-
payload: String(row.payload),
|
|
153
|
-
state: String(row.state) as DeliveryState,
|
|
154
|
-
attemptCount: Number(row.attempt_count),
|
|
155
|
-
nextAttemptAt: row.next_attempt_at === null ? null : Number(row.next_attempt_at),
|
|
156
|
-
lastError: row.last_error === null ? null : String(row.last_error),
|
|
157
|
-
providerMessage: row.provider_message === null ? null : String(row.provider_message),
|
|
158
|
-
createdAt: Number(row.created_at),
|
|
159
|
-
updatedAt: Number(row.updated_at),
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function toReceipt(row: RawRow): ReceiptRow {
|
|
164
|
-
return {
|
|
165
|
-
receiptId: String(row.receipt_id),
|
|
166
|
-
deliveryId: String(row.delivery_id),
|
|
167
|
-
attemptId: String(row.attempt_id),
|
|
168
|
-
state: String(row.state),
|
|
169
|
-
providerMessage: row.provider_message === null ? null : String(row.provider_message),
|
|
170
|
-
detail: row.detail === null ? null : String(row.detail),
|
|
171
|
-
observedAt: Number(row.observed_at),
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
101
|
export function openState(path: string): ChannelState {
|
|
176
102
|
const url = process.env.CHAT_ROOM_DATABASE_URL?.trim();
|
|
177
103
|
return createChannelState(url ? new PgDatabase(url) : new Database(path));
|
|
@@ -189,24 +115,78 @@ export function createChannelState(db: StateDatabase): ChannelState {
|
|
|
189
115
|
return row ? toDelivery(row) : undefined;
|
|
190
116
|
}
|
|
191
117
|
|
|
118
|
+
function insertDeliveries(
|
|
119
|
+
triggerEventId: string,
|
|
120
|
+
entries: PlannedDelivery[],
|
|
121
|
+
now: number,
|
|
122
|
+
): CreatedDelivery[] {
|
|
123
|
+
const created: CreatedDelivery[] = [];
|
|
124
|
+
const insert = db.prepare(
|
|
125
|
+
`INSERT OR IGNORE INTO channel_deliveries
|
|
126
|
+
(delivery_id, event_id, rule_id, rule_version, target, idempotency_key, payload, state, created_at, updated_at)
|
|
127
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, 'pending', ?, ?)`,
|
|
128
|
+
);
|
|
129
|
+
for (const entry of entries) {
|
|
130
|
+
const idempotencyKey = `${triggerEventId}:${entry.ruleId}:${entry.ruleVersion}:0:${entry.target}`;
|
|
131
|
+
const deliveryId = `dlv-${randomUUID()}`;
|
|
132
|
+
const result = insert.run(
|
|
133
|
+
deliveryId,
|
|
134
|
+
triggerEventId,
|
|
135
|
+
entry.ruleId,
|
|
136
|
+
entry.ruleVersion,
|
|
137
|
+
entry.target,
|
|
138
|
+
idempotencyKey,
|
|
139
|
+
entry.payload,
|
|
140
|
+
now,
|
|
141
|
+
now,
|
|
142
|
+
);
|
|
143
|
+
if (Number(result.changes) > 0) {
|
|
144
|
+
created.push({
|
|
145
|
+
deliveryId,
|
|
146
|
+
target: entry.target,
|
|
147
|
+
ruleId: entry.ruleId,
|
|
148
|
+
ruleVersion: entry.ruleVersion,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return created;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function commitWithPlan(
|
|
156
|
+
event: IngestEvent,
|
|
157
|
+
plan: (stored: IngestEvent) => PlannedDelivery[],
|
|
158
|
+
): { result: CommitResult; created: CreatedDelivery[] } {
|
|
159
|
+
return transaction(db, () => {
|
|
160
|
+
const existing = db.prepare("SELECT event_id FROM channel_events WHERE dedup_key = ?").get(
|
|
161
|
+
event.sourceDedupKey,
|
|
162
|
+
) as RawRow | undefined;
|
|
163
|
+
if (existing) {
|
|
164
|
+
return {
|
|
165
|
+
result: { duplicate: true, existingEventId: String(existing.event_id) } as CommitResult,
|
|
166
|
+
created: [] as CreatedDelivery[],
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
const max = db.prepare("SELECT COALESCE(MAX(ingress_seq), 0) AS seq FROM channel_events").get() as RawRow;
|
|
170
|
+
const ingressSeq = event.ingressSeq ?? Number(max.seq) + 1;
|
|
171
|
+
const stored = { ...event, ingressSeq };
|
|
172
|
+
db.prepare(
|
|
173
|
+
`INSERT INTO channel_events (event_id, dedup_key, payload, ingress_seq, committed_at)
|
|
174
|
+
VALUES (?, ?, ?, ?, ?)`,
|
|
175
|
+
).run(event.eventId, event.sourceDedupKey, JSON.stringify(stored), ingressSeq, Date.now());
|
|
176
|
+
return {
|
|
177
|
+
result: { duplicate: false, eventId: event.eventId, ingressSeq } as CommitResult,
|
|
178
|
+
created: insertDeliveries(event.eventId, plan(stored), Date.now()),
|
|
179
|
+
};
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
192
183
|
return {
|
|
193
184
|
commitIngest(event: IngestEvent): CommitResult {
|
|
194
|
-
return
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
return { duplicate: true, existingEventId: String(existing.event_id) };
|
|
200
|
-
}
|
|
201
|
-
const max = db.prepare("SELECT COALESCE(MAX(ingress_seq), 0) AS seq FROM channel_events").get() as RawRow;
|
|
202
|
-
const ingressSeq = event.ingressSeq ?? Number(max.seq) + 1;
|
|
203
|
-
const stored = { ...event, ingressSeq };
|
|
204
|
-
db.prepare(
|
|
205
|
-
`INSERT INTO channel_events (event_id, dedup_key, payload, ingress_seq, committed_at)
|
|
206
|
-
VALUES (?, ?, ?, ?, ?)`,
|
|
207
|
-
).run(event.eventId, event.sourceDedupKey, JSON.stringify(stored), ingressSeq, Date.now());
|
|
208
|
-
return { duplicate: false, eventId: event.eventId, ingressSeq };
|
|
209
|
-
});
|
|
185
|
+
return commitWithPlan(event, () => []).result;
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
commitIngestWithPlan(event, plan) {
|
|
189
|
+
return commitWithPlan(event, plan);
|
|
210
190
|
},
|
|
211
191
|
|
|
212
192
|
deleteIngestEvent(eventId) {
|
|
@@ -217,31 +197,15 @@ export function createChannelState(db: StateDatabase): ChannelState {
|
|
|
217
197
|
if (targets.length !== payloads.length) {
|
|
218
198
|
throw new Error("enqueueDeliveries: targets and payloads must have the same length");
|
|
219
199
|
}
|
|
220
|
-
const
|
|
221
|
-
|
|
200
|
+
const entries: PlannedDelivery[] = targets.map((target, index) => ({
|
|
201
|
+
ruleId: rule.id,
|
|
202
|
+
ruleVersion: rule.version,
|
|
203
|
+
target: `${target.platform}/${target.account}/${target.room}`,
|
|
204
|
+
payload: payloads[index] ?? "",
|
|
205
|
+
}));
|
|
206
|
+
let created: CreatedDelivery[] = [];
|
|
222
207
|
transaction(db, () => {
|
|
223
|
-
|
|
224
|
-
`INSERT OR IGNORE INTO channel_deliveries
|
|
225
|
-
(delivery_id, event_id, rule_id, rule_version, target, idempotency_key, payload, state, created_at, updated_at)
|
|
226
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, 'pending', ?, ?)`,
|
|
227
|
-
);
|
|
228
|
-
targets.forEach((target, index) => {
|
|
229
|
-
const key = `${target.platform}/${target.account}/${target.room}`;
|
|
230
|
-
const idempotencyKey = `${triggerEventId}:${rule.id}:${rule.version}:0:${key}`;
|
|
231
|
-
const deliveryId = `dlv-${randomUUID()}`;
|
|
232
|
-
const result = insert.run(
|
|
233
|
-
deliveryId,
|
|
234
|
-
triggerEventId,
|
|
235
|
-
rule.id,
|
|
236
|
-
rule.version,
|
|
237
|
-
key,
|
|
238
|
-
idempotencyKey,
|
|
239
|
-
payloads[index] ?? "",
|
|
240
|
-
now,
|
|
241
|
-
now,
|
|
242
|
-
);
|
|
243
|
-
if (Number(result.changes) > 0) created.push({ deliveryId, target: key });
|
|
244
|
-
});
|
|
208
|
+
created = insertDeliveries(triggerEventId, entries, Date.now());
|
|
245
209
|
});
|
|
246
210
|
return created;
|
|
247
211
|
},
|
|
@@ -286,6 +250,14 @@ export function createChannelState(db: StateDatabase): ChannelState {
|
|
|
286
250
|
const receiptId = `rcp-${randomUUID()}`;
|
|
287
251
|
const observedAt = input.observedAt ?? Date.now();
|
|
288
252
|
transaction(db, () => {
|
|
253
|
+
// The provider already accepted: mark sent, receipt and echo in one
|
|
254
|
+
// transaction. A DB failure leaves the row in_flight, never re-sent here.
|
|
255
|
+
const updated = db.prepare(
|
|
256
|
+
`UPDATE channel_deliveries
|
|
257
|
+
SET state = 'sent', next_attempt_at = NULL, last_error = NULL, provider_message = ?, updated_at = ?
|
|
258
|
+
WHERE delivery_id = ?`,
|
|
259
|
+
).run(input.providerMessage, observedAt, input.deliveryId);
|
|
260
|
+
if (Number(updated.changes) === 0) throw new Error(`delivery not found: ${input.deliveryId}`);
|
|
289
261
|
db.prepare(
|
|
290
262
|
`INSERT INTO channel_receipts
|
|
291
263
|
(receipt_id, delivery_id, attempt_id, state, provider_message, detail, observed_at)
|
package/plugin.ts
CHANGED
|
@@ -36,10 +36,12 @@ import { readAgentResource, resourceReadFailure } from "./src/rooms/resource-rea
|
|
|
36
36
|
import { adminTool, adminToolDescription, adminToolSchema } from "./src/agent/admin-client.ts";
|
|
37
37
|
import { runReminderTool } from "./src/center/reminder-client.ts";
|
|
38
38
|
import { loadRoomConfig, resolveClientSettings } from "./src/config/file-config.ts";
|
|
39
|
+
import { configureNotificationDelay } from "./src/center/notification-delay.ts";
|
|
39
40
|
// ponytail: CHAT_ROOM_SERVER_URL switches to central mode (all state on a
|
|
40
41
|
// central server); unset = standalone local-file mode. A chatroom.json(c)/yaml
|
|
41
42
|
// file is the shared fallback; environment variables still override it.
|
|
42
43
|
const connection = resolveClientSettings(loadRoomConfig());
|
|
44
|
+
configureNotificationDelay(connection);
|
|
43
45
|
const centerUrl = connection.url;
|
|
44
46
|
const centerToken = connection.token;
|
|
45
47
|
// A configured OpenCode serve URL is required to wake exited sessions.
|
|
@@ -271,10 +273,15 @@ function actionableError(error: unknown): string {
|
|
|
271
273
|
}
|
|
272
274
|
|
|
273
275
|
export const roomArgs = z.object({
|
|
274
|
-
action: z.enum(["create", "join", "join_status", "leave", "list", "send", "poll", "recall", "get_message", "catch_up", "members", "upload_resource", "read_resource", "delete_resource", "announcement_list", "announcement_read", "announcement_write", "announcement_delete", "reminder_list", "reminder_create", "reminder_update", "reminder_delete", "task_list", "task_create", "task_update", "task_delete"]),
|
|
276
|
+
action: z.enum(["create", "join", "join_status", "leave", "list", "send", "poll", "recall", "get_message", "catch_up", "members", "forward_targets", "forward", "upload_resource", "read_resource", "delete_resource", "announcement_list", "announcement_read", "announcement_write", "announcement_delete", "reminder_list", "reminder_create", "reminder_update", "reminder_delete", "task_list", "task_create", "task_update", "task_delete"]),
|
|
275
277
|
name: z.string().max(64).optional().describe("For join: your own participant display name, NOT the room name (required). For create: the new room name."),
|
|
276
278
|
roomId: z.string().optional().describe("Room UUID, not the room name. Required for resource actions and every room-scoped action."),
|
|
277
|
-
messageId: z.string().optional().describe("For recall and
|
|
279
|
+
messageId: z.string().optional().describe("For recall, get_message and forward: the full message ID returned by send, poll, or catch_up."),
|
|
280
|
+
target: z.object({
|
|
281
|
+
platform: z.string().regex(/^[A-Za-z0-9._-]{1,128}$/).describe("Target platform identifier from forward_targets."),
|
|
282
|
+
account: z.string().regex(/^[A-Za-z0-9._-]{1,128}$/).describe("Target account identifier from forward_targets."),
|
|
283
|
+
room: z.string().regex(/^[A-Za-z0-9._-]{1,128}$/).describe("Target room identifier from forward_targets."),
|
|
284
|
+
}).optional().describe("For forward: one exact ready target from forward_targets; tool arguments cannot choose credentials."),
|
|
278
285
|
resourceId: z.string().optional().describe("Resource UUID returned by upload_resource. read_resource and delete_resource also require roomId."),
|
|
279
286
|
filePath: z.string().optional().describe("Absolute path to a regular local file to upload; central mode only; requires host read permission."),
|
|
280
287
|
text: z.string().max(5000).optional().describe("Message text, at most 5000 characters; required for send."),
|
|
@@ -303,6 +310,12 @@ export const roomArgs = z.object({
|
|
|
303
310
|
if (args.action === "join" && !args.name?.trim()) {
|
|
304
311
|
ctx.addIssue({ code: "custom", path: ["name"], message: "name is required to join a room; pass your participant display name" });
|
|
305
312
|
}
|
|
313
|
+
if (args.action === "forward" && !args.messageId) {
|
|
314
|
+
ctx.addIssue({ code: "custom", path: ["messageId"], message: "messageId is required to forward; send the reply first" });
|
|
315
|
+
}
|
|
316
|
+
if (args.action === "forward" && !args.target) {
|
|
317
|
+
ctx.addIssue({ code: "custom", path: ["target"], message: "target is required for forward; run forward_targets first" });
|
|
318
|
+
}
|
|
306
319
|
});
|
|
307
320
|
type RoomArguments = z.infer<typeof roomArgs>;
|
|
308
321
|
|
|
@@ -334,7 +347,7 @@ const roomExecute = async (
|
|
|
334
347
|
// (skipped for poll: poll itself pulls the inbox, so racing the
|
|
335
348
|
// fire-and-forget check would read the position it just advanced;
|
|
336
349
|
// get_message and catch_up stay read-only: no delivery, ack or wake)
|
|
337
|
-
if (args.action !== "poll" && args.action !== "get_message" && args.action !== "catch_up") {
|
|
350
|
+
if (args.action !== "poll" && args.action !== "get_message" && args.action !== "catch_up" && args.action !== "forward_targets") {
|
|
338
351
|
void checkCenterInbox(runtime.center, context.sessionID, runtime.transport);
|
|
339
352
|
}
|
|
340
353
|
return await centerAction(runtime.center, {
|
|
@@ -361,6 +374,9 @@ const roomExecute = async (
|
|
|
361
374
|
if (announcementResult !== undefined) return announcementResult;
|
|
362
375
|
const taskResult = await runTaskTool(args, context.sessionID);
|
|
363
376
|
if (taskResult !== undefined) return taskResult;
|
|
377
|
+
if (args.action === "forward_targets" || args.action === "forward") {
|
|
378
|
+
return `error: ${args.action} requires central server mode (CHAT_ROOM_SERVER_URL)`;
|
|
379
|
+
}
|
|
364
380
|
// ponytail: act as the identity this session registered with on join
|
|
365
381
|
let selfName = identity();
|
|
366
382
|
let joinPrevName: string | undefined;
|
|
@@ -501,7 +517,7 @@ const roomExecute = async (
|
|
|
501
517
|
);
|
|
502
518
|
const room = svc.getRoom(args.roomId);
|
|
503
519
|
notifications.push({ roomId: args.roomId, roomName: room.name, messages: [...room.messages] });
|
|
504
|
-
return `sent
|
|
520
|
+
return `sent message_id=${msg.id} room_id=${room.id}`;
|
|
505
521
|
}
|
|
506
522
|
case "poll": {
|
|
507
523
|
if (!args.roomId) {
|
|
@@ -554,7 +570,7 @@ const roomExecute = async (
|
|
|
554
570
|
}
|
|
555
571
|
};
|
|
556
572
|
const room = tool({
|
|
557
|
-
description: "Chat room operations: create, join, leave and list rooms; send, poll and recall messages; get_message fetches one message by ID (recalled messages come back as tombstones); catch_up pages messages after a seq cursor and is read-only (no read receipt or wake). Send accepts parentMessageId to reply to a message. List members, announcements and tasks; create, update and delete room tasks; manage reminders. Sent and polled messages carry full message IDs; recall takes roomId plus messageId and withdraws the message for everyone (agents their own, room admins any). Reminder schedules use the server timezone unless an IANA timezone is provided; once schedules require an ISO datetime. Upload files and media; upload_resource returns a [[resource:UUID]] marker, and the attachment renders only when that exact marker is included in a send message. Resource actions need both roomId (the room UUID) and resourceId (the UUID in the marker); the marker alone does not identify the room. read_resource saves files to a private temporary path and leaves them there until removed or system cleanup. delete_resource removes an uploaded file; servers allow human room administrators any resource and agents only their own uploads. Room joinPolicy \"approval\" makes join a pending request: you are not a member while pending, never claim otherwise, and use join_status to check whether a human administrator approved it.",
|
|
573
|
+
description: "Chat room operations: create, join, leave and list rooms; send, poll and recall messages; get_message fetches one message by ID (recalled messages come back as tombstones); catch_up pages messages after a seq cursor and is read-only (no read receipt or wake). Send accepts parentMessageId to reply to a message. forward_targets lists the exact ready relay targets for this room; forward queues one already-sent reply to one listed target and reports queued, never delivered. List members, announcements and tasks; create, update and delete room tasks; manage reminders. Sent and polled messages carry full message IDs; recall takes roomId plus messageId and withdraws the message for everyone (agents their own, room admins any). Reminder schedules use the server timezone unless an IANA timezone is provided; once schedules require an ISO datetime. Upload files and media; upload_resource returns a [[resource:UUID]] marker, and the attachment renders only when that exact marker is included in a send message. Resource actions need both roomId (the room UUID) and resourceId (the UUID in the marker); the marker alone does not identify the room. read_resource saves files to a private temporary path and leaves them there until removed or system cleanup. delete_resource removes an uploaded file; servers allow human room administrators any resource and agents only their own uploads. Room joinPolicy \"approval\" makes join a pending request: you are not a member while pending, never claim otherwise, and use join_status to check whether a human administrator approved it.",
|
|
558
574
|
args: roomArgs.shape,
|
|
559
575
|
execute: roomExecute,
|
|
560
576
|
});
|
package/server/app.ts
CHANGED
|
@@ -8,6 +8,8 @@ import { joinRequestRoutes } from "./join-requests.ts";
|
|
|
8
8
|
import { memberRoutes } from "./member-routes.ts";
|
|
9
9
|
import { messageRecallRoutes } from "./message-recall-routes.ts";
|
|
10
10
|
import { roomManagement } from "./newrooms.ts";
|
|
11
|
+
import { operatorRoutes } from "./operator-routes.ts";
|
|
12
|
+
import { resolveOperatorToken } from "./operator-auth.ts";
|
|
11
13
|
import { resourceRoutes } from "./resource-routes.ts";
|
|
12
14
|
import { roomReminderRoutes } from "./room-reminders.ts";
|
|
13
15
|
import { inboxRoutes } from "./routes/inbox.ts";
|
|
@@ -19,6 +21,7 @@ import { roomCreateRoute, roomDetailRoutes, roomListRoutes } from "./routes/room
|
|
|
19
21
|
export type AppOptions = {
|
|
20
22
|
here: string;
|
|
21
23
|
token?: string;
|
|
24
|
+
operatorToken?: string;
|
|
22
25
|
serveWakeUrl: string;
|
|
23
26
|
channeld: () => ChannelController | undefined;
|
|
24
27
|
};
|
|
@@ -30,10 +33,16 @@ const json = (body: unknown, status = 200) =>
|
|
|
30
33
|
});
|
|
31
34
|
|
|
32
35
|
export function createApp(options: AppOptions): (req: Request) => Promise<Response> {
|
|
36
|
+
// Resolve the opt-in operator token once; identity can change here only.
|
|
37
|
+
const operatorToken = resolveOperatorToken(options.operatorToken, options.token);
|
|
33
38
|
// Database callbacks finish synchronously before any HTTP or long-poll wait.
|
|
34
39
|
return async function handle(req: Request): Promise<Response> {
|
|
35
40
|
const url = new URL(req.url);
|
|
36
41
|
const p = url.pathname;
|
|
42
|
+
// The operator panel owns /system before any page, asset or shared-token path.
|
|
43
|
+
if (p === "/system" || p.startsWith("/system/")) {
|
|
44
|
+
return operatorRoutes(req, url, { here: options.here, token: operatorToken });
|
|
45
|
+
}
|
|
37
46
|
const page = await pageRoutes(req, url, options.here, options.channeld()?.enabled ?? false);
|
|
38
47
|
if (page) return page;
|
|
39
48
|
// ponytail: F1 — reject non-JSON POSTs; a text/plain simple request from a
|
package/server/assets/base.css
CHANGED
|
@@ -155,6 +155,11 @@
|
|
|
155
155
|
.version-tag { font: 600 10px/1 var(--font-mono); color: var(--ink-3); background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px 7px; white-space: nowrap; }
|
|
156
156
|
.version-tag:empty { display: none; }
|
|
157
157
|
.rail-brand .version-tag { align-self: center; }
|
|
158
|
+
/* The rail keeps the mark and the name intact; a long release tag clips itself. */
|
|
159
|
+
.brand-mark { flex: none; }
|
|
160
|
+
.rail-brand { min-width: 0; }
|
|
161
|
+
.rail-brand .brand-name { white-space: nowrap; }
|
|
162
|
+
.rail-brand .version-tag { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
|
158
163
|
.tagline { margin: 8px 0 26px; font-size: 13.5px; color: var(--ink-2); }
|
|
159
164
|
|
|
160
165
|
.field { display: block; margin-bottom: 14px; }
|
|
@@ -237,7 +242,11 @@
|
|
|
237
242
|
#announcementsDialog.is-pane .announcements-body, #remindersDialog.is-pane .reminders-body { padding: 0 14px 18px 18px; }
|
|
238
243
|
.announcements-dialog .announcement-list { margin: 0; max-height: none; }
|
|
239
244
|
.reminders-dialog .reminder-list { margin: 0; }
|
|
240
|
-
|
|
245
|
+
/* A fixed line box keeps the loading text from growing the centered dialog. */
|
|
246
|
+
#announcementStatus { position: relative; min-height: 1.4em; line-height: 1.4em; }
|
|
247
|
+
#announcementStatus.is-loading { padding-left: 1.3em; }
|
|
248
|
+
#announcementStatus.is-loading::before { content: ""; position: absolute; left: 0; top: .3em; width: .8em; height: .8em; box-sizing: border-box; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
|
|
249
|
+
@media (prefers-reduced-motion: reduce) { #announcementStatus.is-loading::before { animation: none; opacity: .7; } }
|
|
241
250
|
.announcement-list { list-style: none; padding: 0; margin: 10px 0; min-height: 120px; max-height: 150px; overflow: auto; }
|
|
242
251
|
.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; }
|
|
243
252
|
.announcement-list button:hover, .announcement-list button[aria-current="true"] { background: var(--accent-soft); border-color: var(--line); }
|
|
@@ -276,7 +285,18 @@
|
|
|
276
285
|
#reminderDialog .reminder-form .announcement-actions { margin-top: 2px; }
|
|
277
286
|
.reminder-form .field { margin: 0 0 9px; }
|
|
278
287
|
.reminder-form textarea { resize: vertical; min-height: clamp(110px, 16dvh, 190px); max-height: 30dvh; line-height: 1.6; }
|
|
279
|
-
|
|
288
|
+
/* A fixed line box keeps the loading text from moving the reminder list. */
|
|
289
|
+
#reminderStatus { min-height: 1.4em; line-height: 1.4em; }
|
|
290
|
+
/* Refresh buttons spin in place: the ring overlays the label, so no row or header box moves. */
|
|
291
|
+
#btnRefreshReminders, #btnRefreshQuestions, #btnRefreshIntegrations { position: relative; }
|
|
292
|
+
#btnRefreshReminders[aria-busy="true"], #btnRefreshQuestions[aria-busy="true"], #btnRefreshIntegrations[aria-busy="true"] { color: transparent; }
|
|
293
|
+
#btnRefreshReminders[aria-busy="true"]::before, #btnRefreshQuestions[aria-busy="true"]::before, #btnRefreshIntegrations[aria-busy="true"]::before {
|
|
294
|
+
content: ""; position: absolute; left: 50%; top: 50%; width: .85em; height: .85em; margin: -.425em 0 0 -.425em;
|
|
295
|
+
box-sizing: border-box; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite;
|
|
296
|
+
}
|
|
297
|
+
@media (prefers-reduced-motion: reduce) {
|
|
298
|
+
#btnRefreshReminders[aria-busy="true"]::before, #btnRefreshQuestions[aria-busy="true"]::before, #btnRefreshIntegrations[aria-busy="true"]::before { animation: none; opacity: .7; }
|
|
299
|
+
}
|
|
280
300
|
.reminder-list { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 8px; min-height: 96px; }
|
|
281
301
|
.reminder-list li { padding: 9px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
|
|
282
302
|
.reminder-list li.is-disabled { color: var(--ink-3); background: color-mix(in srgb, var(--surface) 70%, var(--line)); opacity: .62; }
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { LS } from "./state.js";
|
|
2
2
|
import { isRoomAdmin } from "./admin-badge.js";
|
|
3
|
+
import { closeOnBackdrop } from "./panels.js";
|
|
3
4
|
const errorMessage = (error) => error instanceof Error ? error.message : String(error);
|
|
4
5
|
// Owners and delegated humans manage settings; the agent designation comes from
|
|
5
6
|
// the room payload and room owners manage it here instead of an operator token.
|
|
@@ -8,6 +9,9 @@ export function initAdmin(app) {
|
|
|
8
9
|
const $ = (selector) => app.$(selector);
|
|
9
10
|
const dialog = $("#editRoomDialog");
|
|
10
11
|
let agents = [], people = [], generation = 0, agentsReady = false, rosterReady = false, opener = null;
|
|
12
|
+
// Only a real input marks the form dirty; the registry fills controls without events,
|
|
13
|
+
// so a late GET can never make a draft typed during it look untouched.
|
|
14
|
+
let dirty = false;
|
|
11
15
|
const tabs = [...dialog.querySelectorAll('[role="tab"]')];
|
|
12
16
|
// One tab stop for the visible tabs; arrow keys move selection like a native tab widget.
|
|
13
17
|
const activateTab = (name, { focus = false } = {}) => {
|
|
@@ -31,7 +35,7 @@ export function initAdmin(app) {
|
|
|
31
35
|
if (target < 0)
|
|
32
36
|
return;
|
|
33
37
|
event.preventDefault();
|
|
34
|
-
activateTab(items[target]
|
|
38
|
+
activateTab(items[target]?.dataset.editRoomTab, { focus: true });
|
|
35
39
|
};
|
|
36
40
|
for (const tab of tabs) {
|
|
37
41
|
tab.addEventListener("click", () => activateTab(tab.dataset.editRoomTab));
|
|
@@ -101,6 +105,7 @@ export function initAdmin(app) {
|
|
|
101
105
|
const room = app.state.room;
|
|
102
106
|
if (!room)
|
|
103
107
|
return;
|
|
108
|
+
dirty = false;
|
|
104
109
|
$("#editRoomName").value = room.name;
|
|
105
110
|
$("#editRoomDescription").value = room.description || "";
|
|
106
111
|
$("#editRoomJoinPolicy").checked = room.joinPolicy === "approval";
|
|
@@ -141,8 +146,19 @@ export function initAdmin(app) {
|
|
|
141
146
|
});
|
|
142
147
|
$("#btnCloseOwnerOnly").addEventListener("click", () => ownerDialog.close());
|
|
143
148
|
$("#btnOwnerOnlyOk").addEventListener("click", () => ownerDialog.close());
|
|
149
|
+
// A plain explanation, not a form: a backdrop click dismisses it.
|
|
150
|
+
closeOnBackdrop(ownerDialog, () => ownerDialog.close());
|
|
144
151
|
$("#btnCloseEditRoom").addEventListener("click", () => dialog.close());
|
|
145
152
|
$("#btnCancelEditRoom").addEventListener("click", () => dialog.close());
|
|
153
|
+
// A backdrop click closes an untouched form; edits and a save in flight hold it.
|
|
154
|
+
closeOnBackdrop(dialog, () => {
|
|
155
|
+
if (dirty || $("#editRoomForm button[type=submit]").disabled)
|
|
156
|
+
return;
|
|
157
|
+
dialog.close();
|
|
158
|
+
});
|
|
159
|
+
for (const type of ["input", "change"]) {
|
|
160
|
+
$("#editRoomForm").addEventListener(type, () => { dirty = true; });
|
|
161
|
+
}
|
|
146
162
|
dialog.addEventListener("close", () => {
|
|
147
163
|
const target = opener;
|
|
148
164
|
opener = null;
|