@alexsun-top/opencode-chat-room 0.8.5 → 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 +12 -2
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/cli.ts +19 -0
- package/dist/cli.js +3747 -1443
- package/package.json +6 -1
- package/packages/chat-room-channeld/README.md +13 -8
- 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/pg/database.ts +141 -49
- package/packages/chat-room-channeld/src/pg/worker.mjs +46 -5
- package/packages/chat-room-channeld/src/pg/worker.mts +41 -6
- package/packages/chat-room-channeld/src/state-rows.ts +132 -0
- package/packages/chat-room-channeld/src/state.ts +129 -157
- package/plugin.ts +20 -4
- package/server/app.ts +9 -0
- package/server/assets/base.css +22 -2
- package/server/assets/chat/admin.js +13 -0
- package/server/assets/chat/announcements.js +76 -34
- package/server/assets/chat/confirm-dialog.js +3 -0
- 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 +70 -30
- package/server/assets/chat/editor.js +38 -3
- package/server/assets/chat/events.js +6 -1
- package/server/assets/chat/files.js +28 -26
- package/server/assets/chat/history-loader.js +31 -15
- package/server/assets/chat/integration-editor.js +25 -1
- package/server/assets/chat/integrations.js +107 -15
- package/server/assets/chat/join-requests.js +39 -1
- 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 +19 -8
- package/server/assets/chat/markdown.js +0 -7
- package/server/assets/chat/members.js +31 -19
- package/server/assets/chat/message-cache.js +8 -2
- package/server/assets/chat/message-polling.js +8 -2
- package/server/assets/chat/message-window.js +57 -0
- package/server/assets/chat/messages.js +79 -40
- package/server/assets/chat/operator.js +624 -0
- package/server/assets/chat/palette.js +2 -7
- package/server/assets/chat/panels.js +31 -8
- package/server/assets/chat/questions.js +72 -56
- 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 +44 -13
- package/server/assets/chat/replies.js +33 -22
- package/server/assets/chat/resource-format.js +4 -1
- package/server/assets/chat/room-list.js +202 -3
- package/server/assets/chat/room-watcher.js +3 -1
- package/server/assets/chat/rooms.js +22 -3
- package/server/assets/chat/settings.js +33 -3
- package/server/assets/chat/state.js +21 -7
- package/server/assets/chat/tasks.js +33 -11
- package/server/assets/chat/window-controls.js +25 -16
- package/server/assets/code-highlight.css +0 -13
- package/server/assets/conversation.css +31 -3
- package/server/assets/doc-preview.css +3 -0
- package/server/assets/files.css +4 -0
- package/server/assets/monaco/integration-rules.js +1 -1
- 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/system.html +109 -0
- package/server/wake.ts +1 -1
- package/skills/chatroom/SKILL.md +3 -3
- 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 +87 -5
- package/src/center/center-client.ts +5 -0
- 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-worker.mjs +46 -5
- package/src/state/pg-worker.mts +41 -6
- 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 +10 -4
- package/src/tui/app.mjs +57 -10
- package/src/tui/app.mts +54 -11
- package/src/tui/room-settings-app.mjs +27 -9
- package/src/tui/room-settings-app.mts +26 -9
- package/src/web/integration-rules-editor.ts +25 -2
|
@@ -2,35 +2,44 @@
|
|
|
2
2
|
// visible overlay gets the drag strip and titlebar inset; every other surface keeps
|
|
3
3
|
// its normal layout with no dead drag area.
|
|
4
4
|
const PROPS = ["top", "left", "width", "height"];
|
|
5
|
+
export const WCO_VISIBILITY_CHANGE = "wco-visibilitychange";
|
|
5
6
|
export function initWindowControls() {
|
|
6
7
|
const overlay = navigator.windowControlsOverlay;
|
|
7
8
|
if (!overlay)
|
|
8
9
|
return;
|
|
9
10
|
const root = document.documentElement;
|
|
10
11
|
let drag = null;
|
|
12
|
+
let visible = false;
|
|
11
13
|
const sync = () => {
|
|
12
|
-
|
|
14
|
+
const next = overlay.visible === true;
|
|
15
|
+
if (next) {
|
|
16
|
+
// Real browsers resolve env(titlebar-area-*) first; the variables are a fallback
|
|
17
|
+
// for browsers that expose the overlay without the CSS environment values.
|
|
18
|
+
const rect = overlay.getTitlebarAreaRect?.();
|
|
19
|
+
if (rect) {
|
|
20
|
+
const area = { top: rect.y, left: rect.x, width: rect.width, height: rect.height };
|
|
21
|
+
for (const name of PROPS)
|
|
22
|
+
root.style.setProperty(`--wco-${name}`, `${area[name]}px`);
|
|
23
|
+
}
|
|
24
|
+
root.dataset.wco = "true";
|
|
25
|
+
if (!drag) {
|
|
26
|
+
drag = document.createElement("div");
|
|
27
|
+
drag.className = "wco-drag";
|
|
28
|
+
drag.setAttribute("aria-hidden", "true");
|
|
29
|
+
document.body.append(drag);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
13
33
|
delete root.dataset.wco;
|
|
14
34
|
for (const name of PROPS)
|
|
15
35
|
root.style.removeProperty(`--wco-${name}`);
|
|
16
36
|
drag?.remove();
|
|
17
37
|
drag = null;
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
// Real browsers resolve env(titlebar-area-*) first; the variables are a fallback
|
|
21
|
-
// for browsers that expose the overlay without the CSS environment values.
|
|
22
|
-
const rect = overlay.getTitlebarAreaRect?.();
|
|
23
|
-
if (rect) {
|
|
24
|
-
const area = { top: rect.y, left: rect.x, width: rect.width, height: rect.height };
|
|
25
|
-
for (const name of PROPS)
|
|
26
|
-
root.style.setProperty(`--wco-${name}`, `${area[name]}px`);
|
|
27
38
|
}
|
|
28
|
-
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
drag.setAttribute("aria-hidden", "true");
|
|
33
|
-
document.body.append(drag);
|
|
39
|
+
// Only a visibility flip changes the native caption color; a resize keeps it.
|
|
40
|
+
if (next !== visible) {
|
|
41
|
+
visible = next;
|
|
42
|
+
root.dispatchEvent(new Event(WCO_VISIBILITY_CHANGE));
|
|
34
43
|
}
|
|
35
44
|
};
|
|
36
45
|
overlay.addEventListener("geometrychange", sync);
|
|
@@ -90,19 +90,6 @@
|
|
|
90
90
|
.code-block.is-wrapped pre { overflow-x: hidden; }
|
|
91
91
|
.code-block.is-wrapped pre code { white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
92
92
|
|
|
93
|
-
.code-language {
|
|
94
|
-
min-width: 0;
|
|
95
|
-
overflow: hidden;
|
|
96
|
-
text-overflow: ellipsis;
|
|
97
|
-
white-space: nowrap;
|
|
98
|
-
color: var(--ink-3);
|
|
99
|
-
font: 600 10.5px/1.5 var(--font-mono);
|
|
100
|
-
letter-spacing: .07em;
|
|
101
|
-
text-transform: uppercase;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
.code-block:hover .code-language { color: var(--ink-2); }
|
|
105
|
-
|
|
106
93
|
.code-toolbar {
|
|
107
94
|
display: flex;
|
|
108
95
|
flex: none;
|
|
@@ -209,6 +209,10 @@
|
|
|
209
209
|
.jump .fluent-icon { width: 18px; height: 18px; }
|
|
210
210
|
.jump:hover { filter: brightness(1.07); }
|
|
211
211
|
.jump:active { transform: translateY(1px); }
|
|
212
|
+
/* The resize hold already waited out the gesture, so the settle shows without a pop. */
|
|
213
|
+
.jump.is-settling { animation: jump-fade-in .18s ease-out; }
|
|
214
|
+
@keyframes jump-fade-in { from { opacity: 0; transform: translateY(4px); } }
|
|
215
|
+
@media (prefers-reduced-motion: reduce) { .jump.is-settling { animation: none; } }
|
|
212
216
|
.jump .badge {
|
|
213
217
|
position: absolute;
|
|
214
218
|
top: -6px;
|
|
@@ -278,19 +282,20 @@
|
|
|
278
282
|
display: inline-block;
|
|
279
283
|
width: max-content;
|
|
280
284
|
max-width: min(86%, 540px);
|
|
285
|
+
/* Confirming a send only lifts the pending dimming, so fade it instead of snapping. */
|
|
286
|
+
transition: opacity .16s ease;
|
|
281
287
|
padding: 9px 13px;
|
|
282
288
|
border: 1px solid color-mix(in srgb, var(--ink) 5%, transparent);
|
|
283
289
|
border-radius: 16px;
|
|
284
290
|
box-shadow: 0 1px 2px rgb(20 40 32 / .035);
|
|
285
291
|
background: var(--surface-2);
|
|
286
|
-
border-bottom-left-radius: 4px;
|
|
287
292
|
font-size: 16px;
|
|
288
293
|
line-height: 1.6;
|
|
289
294
|
white-space: normal;
|
|
290
295
|
overflow-wrap: anywhere;
|
|
291
296
|
}
|
|
292
297
|
.msg-text::selection, .msg-text *::selection { color: var(--accent-ink); background: var(--accent); }
|
|
293
|
-
.msg.own .msg-text { background: linear-gradient(145deg, color-mix(in srgb, var(--accent-soft) 86%, var(--surface)), var(--accent-soft)); border-color: color-mix(in srgb, var(--accent) 12%, transparent);
|
|
298
|
+
.msg.own .msg-text { background: linear-gradient(145deg, color-mix(in srgb, var(--accent-soft) 86%, var(--surface)), var(--accent-soft)); border-color: color-mix(in srgb, var(--accent) 12%, transparent); }
|
|
294
299
|
.msg.jump-flash .msg-text { animation: jump-flash .4s ease-in-out 2; }
|
|
295
300
|
@keyframes jump-flash {
|
|
296
301
|
0%, 100% { box-shadow: 0 1px 2px rgb(20 40 32 / .035); }
|
|
@@ -343,8 +348,10 @@
|
|
|
343
348
|
the all-read icon without depending on font metrics. */
|
|
344
349
|
.message-readers { flex: 0 0 24px; align-self: flex-end; display: grid; place-items: center; margin: 0; padding: 0; width: 24px; height: 24px; border: 1px solid var(--line); border-radius: 50%; color: var(--ink-3); background: var(--surface); font: inherit; font-size: 10px; line-height: 1; cursor: pointer; box-shadow: 0 1px 3px rgb(20 40 32 / .06); }
|
|
345
350
|
.message-readers[data-reader-state="empty"], .message-readers[data-reader-state="unknown"] { background: var(--surface-2); }
|
|
351
|
+
.message-readers[data-reader-state="delivered"] { color: var(--ink-2); background: var(--surface-2); }
|
|
346
352
|
.message-readers[data-reader-state="all"] { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); color: var(--accent); background: var(--accent-soft); }
|
|
347
|
-
.message-read-check { display: block; width: 14px; height: 14px; }
|
|
353
|
+
.message-read-check, .message-delivered-icon { display: block; width: 14px; height: 14px; }
|
|
354
|
+
.reader-delivered { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
|
|
348
355
|
.message-readers:hover, .message-readers[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }
|
|
349
356
|
.message-readers:focus-visible, .reader-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
350
357
|
.receipt-reader-list { margin: 0; padding: 0; list-style: none; }
|
|
@@ -705,3 +712,24 @@
|
|
|
705
712
|
#msgList.room-content-out-prev { animation: room-content-out-prev .14s ease-in both; }
|
|
706
713
|
#msgList.room-content-in-next { animation: room-content-in-next .2s ease-out both; }
|
|
707
714
|
#msgList.room-content-in-prev { animation: room-content-in-prev .2s ease-out both; }
|
|
715
|
+
|
|
716
|
+
/* Room reordering: native drag on pointer devices, move buttons where dragging is unavailable. */
|
|
717
|
+
#roomList > li, #roomListChat > li { display: flex; align-items: center; }
|
|
718
|
+
#roomList > li > .room-row, #roomListChat > li > .room-row { flex: 1; min-width: 0; }
|
|
719
|
+
.room-row[draggable="true"] { cursor: grab; }
|
|
720
|
+
.room-row.dragging { opacity: .45; }
|
|
721
|
+
.room-row.drop-target { outline: 2px dashed var(--accent); outline-offset: 2px; }
|
|
722
|
+
.room-move { display: none; flex-direction: column; gap: 2px; margin-left: 2px; }
|
|
723
|
+
.room-move-btn { display: grid; place-items: center; width: 26px; height: 24px; padding: 0; border: 1px solid transparent; border-radius: 7px; color: var(--ink-3); background: transparent; cursor: pointer; }
|
|
724
|
+
.room-move-btn:hover { color: var(--accent); border-color: var(--line); background: var(--surface); }
|
|
725
|
+
.room-move-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
726
|
+
.room-move-btn:disabled { opacity: .3; cursor: default; }
|
|
727
|
+
.room-move-btn svg { width: 14px; height: 14px; }
|
|
728
|
+
@media (hover: none), (pointer: coarse) {
|
|
729
|
+
.room-move { display: flex; }
|
|
730
|
+
.room-row[draggable="true"] { cursor: pointer; }
|
|
731
|
+
}
|
|
732
|
+
#roomList[aria-busy="true"], #roomListChat[aria-busy="true"] { opacity: .6; transition: opacity .15s ease; }
|
|
733
|
+
#btnRefreshRooms.is-refreshing svg { animation: spin .8s linear infinite; }
|
|
734
|
+
@media (prefers-reduced-motion: reduce) { #btnRefreshRooms.is-refreshing svg { animation: none; opacity: .6; } }
|
|
735
|
+
.room-order-status { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
|
|
@@ -163,6 +163,9 @@ pre.doc-code code { padding: 0; font-family: var(--font-mono); font-size: 12.5px
|
|
|
163
163
|
.doc-preview.is-pdf .doc-preview-empty { display: none; }
|
|
164
164
|
.doc-pdf-frame { flex: 1 1 auto; width: 100%; height: 100%; min-height: 0; border: 0; background: var(--surface-2); }
|
|
165
165
|
|
|
166
|
+
/* SVG previews decode through an <img>, so the markup stays inert. */
|
|
167
|
+
.doc-svg-image { display: block; max-width: 100%; height: auto; margin: 0 auto; }
|
|
168
|
+
|
|
166
169
|
/* Code files fill the reading surface with a read-only Monaco editor. */
|
|
167
170
|
.doc-preview.is-code .doc-preview-scroll { display: flex; padding: 0; overflow: hidden; }
|
|
168
171
|
.doc-preview.is-code .doc-preview-body { flex: 1 1 auto; min-height: 0; }
|
package/server/assets/files.css
CHANGED
|
@@ -71,6 +71,9 @@
|
|
|
71
71
|
font-size: 12px;
|
|
72
72
|
}
|
|
73
73
|
.files-summary { margin: 0 0 0 auto; color: var(--ink-3); font-size: 11.5px; line-height: 1.4; }
|
|
74
|
+
/* A refresh spins the reload glyph in place, so the rows and the toolbar hold
|
|
75
|
+
their geometry while the request is in flight. */
|
|
76
|
+
#btnRefreshFiles.is-refreshing svg { animation: spin .8s linear infinite; }
|
|
74
77
|
|
|
75
78
|
.files-error { margin: 0 20px 8px; }
|
|
76
79
|
.files-scroll {
|
|
@@ -227,4 +230,5 @@
|
|
|
227
230
|
|
|
228
231
|
@media (prefers-reduced-motion: reduce) {
|
|
229
232
|
#filesDialog[open], .file-row { animation: none; }
|
|
233
|
+
#btnRefreshFiles.is-refreshing svg { animation: none; opacity: .7; }
|
|
230
234
|
}
|
|
@@ -1602,4 +1602,4 @@ ${t.comment}`:t.comment}this.doc.range[2]=t.offset;break}default:this.errors.pus
|
|
|
1602
1602
|
`,t)+1}yield*this.pop();break;default:yield*this.pop(),yield*this.step()}}*blockMap(e){let t=e.items[e.items.length-1];switch(this.type){case"newline":if(this.onKeyLine=!1,t.value){let i="end"in t.value?t.value.end:void 0;if((Array.isArray(i)?i[i.length-1]:void 0)?.type==="comment")i?.push(this.sourceToken);else e.items.push({start:[this.sourceToken]})}else if(t.sep)t.sep.push(this.sourceToken);else t.start.push(this.sourceToken);return;case"space":case"comment":if(t.value)e.items.push({start:[this.sourceToken]});else if(t.sep)t.sep.push(this.sourceToken);else{if(this.atIndentedComment(t.start,e.indent)){let n=e.items[e.items.length-2]?.value?.end;if(Array.isArray(n)){C$(n,t.start),n.push(this.sourceToken),e.items.pop();return}}t.start.push(this.sourceToken)}return}if(this.indent>=e.indent){let i=!this.onKeyLine&&this.indent===e.indent,n=i&&(t.sep||t.explicitKey)&&this.type!=="seq-item-ind",o=[];if(n&&t.sep&&!t.value){let s=[];for(let r=0;r<t.sep.length;++r){let a=t.sep[r];switch(a.type){case"newline":s.push(r);break;case"space":break;case"comment":if(a.indent>e.indent)s.length=0;break;default:s.length=0}}if(s.length>=2)o=t.sep.splice(s[1])}switch(this.type){case"anchor":case"tag":if(n||t.value)o.push(this.sourceToken),e.items.push({start:o}),this.onKeyLine=!0;else if(t.sep)t.sep.push(this.sourceToken);else t.start.push(this.sourceToken);return;case"explicit-key-ind":if(!t.sep&&!t.explicitKey)t.start.push(this.sourceToken),t.explicitKey=!0;else if(n||t.value)o.push(this.sourceToken),e.items.push({start:o,explicitKey:!0});else this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken],explicitKey:!0}]});this.onKeyLine=!0;return;case"map-value-ind":if(t.explicitKey)if(!t.sep)if(gy(t.start,"newline"))Object.assign(t,{key:null,sep:[this.sourceToken]});else{let s=ZT(t.start);this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:s,key:null,sep:[this.sourceToken]}]})}else if(t.value)e.items.push({start:[],key:null,sep:[this.sourceToken]});else if(gy(t.sep,"map-value-ind"))this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:o,key:null,sep:[this.sourceToken]}]});else if(Oqe(t.key)&&!gy(t.sep,"newline")){let s=ZT(t.start),{key:r,sep:a}=t;a.push(this.sourceToken),delete t.key,delete t.sep,this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:s,key:r,sep:a}]})}else if(o.length>0)t.sep=t.sep.concat(o,this.sourceToken);else t.sep.push(this.sourceToken);else if(!t.sep)Object.assign(t,{key:null,sep:[this.sourceToken]});else if(t.value||n)e.items.push({start:o,key:null,sep:[this.sourceToken]});else if(gy(t.sep,"map-value-ind"))this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:[],key:null,sep:[this.sourceToken]}]});else t.sep.push(this.sourceToken);this.onKeyLine=!0;return;case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":{let s=this.flowScalar(this.type);if(n||t.value)e.items.push({start:o,key:s,sep:[]}),this.onKeyLine=!0;else if(t.sep)this.stack.push(s);else Object.assign(t,{key:s,sep:[]}),this.onKeyLine=!0;return}default:{let s=this.startBlockValue(e);if(s){if(s.type==="block-seq"){if(!t.explicitKey&&t.sep&&!gy(t.sep,"newline")){yield*this.pop({type:"error",offset:this.offset,message:"Unexpected block-seq-ind on same line with key",source:this.source});return}}else if(i)e.items.push({start:o});this.stack.push(s);return}}}}yield*this.pop(),yield*this.step()}*blockSequence(e){let t=e.items[e.items.length-1];switch(this.type){case"newline":if(t.value){let i="end"in t.value?t.value.end:void 0;if((Array.isArray(i)?i[i.length-1]:void 0)?.type==="comment")i?.push(this.sourceToken);else e.items.push({start:[this.sourceToken]})}else t.start.push(this.sourceToken);return;case"space":case"comment":if(t.value)e.items.push({start:[this.sourceToken]});else{if(this.atIndentedComment(t.start,e.indent)){let n=e.items[e.items.length-2]?.value?.end;if(Array.isArray(n)){C$(n,t.start),n.push(this.sourceToken),e.items.pop();return}}t.start.push(this.sourceToken)}return;case"anchor":case"tag":if(t.value||this.indent<=e.indent)break;t.start.push(this.sourceToken);return;case"seq-item-ind":if(this.indent!==e.indent)break;if(t.value||gy(t.start,"seq-item-ind"))e.items.push({start:[this.sourceToken]});else t.start.push(this.sourceToken);return}if(this.indent>e.indent){let i=this.startBlockValue(e);if(i){this.stack.push(i);return}}yield*this.pop(),yield*this.step()}*flowCollection(e){let t=e.items[e.items.length-1];if(this.type==="flow-error-end"){let i;do yield*this.pop(),i=this.peek(1);while(i?.type==="flow-collection")}else if(e.end.length===0){switch(this.type){case"comma":case"explicit-key-ind":if(!t||t.sep)e.items.push({start:[this.sourceToken]});else t.start.push(this.sourceToken);return;case"map-value-ind":if(!t||t.value)e.items.push({start:[],key:null,sep:[this.sourceToken]});else if(t.sep)t.sep.push(this.sourceToken);else Object.assign(t,{key:null,sep:[this.sourceToken]});return;case"space":case"comment":case"newline":case"anchor":case"tag":if(!t||t.value)e.items.push({start:[this.sourceToken]});else if(t.sep)t.sep.push(this.sourceToken);else t.start.push(this.sourceToken);return;case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":{let n=this.flowScalar(this.type);if(!t||t.value)e.items.push({start:[],key:n,sep:[]});else if(t.sep)this.stack.push(n);else Object.assign(t,{key:n,sep:[]});return}case"flow-map-end":case"flow-seq-end":e.end.push(this.sourceToken);return}let i=this.startBlockValue(e);if(i)this.stack.push(i);else yield*this.pop(),yield*this.step()}else{let i=this.peek(2);if(i.type==="block-map"&&(this.type==="map-value-ind"&&i.indent===e.indent||this.type==="newline"&&!i.items[i.items.length-1].sep))yield*this.pop(),yield*this.step();else if(this.type==="map-value-ind"&&i.type!=="flow-collection"){let n=w$(i),o=ZT(n);Mqe(e);let s=e.end.splice(1,e.end.length);s.push(this.sourceToken);let r={type:"block-map",offset:e.offset,indent:e.indent,items:[{start:o,key:e,sep:s}]};this.onKeyLine=!0,this.stack[this.stack.length-1]=r}else yield*this.lineEnd(e)}}flowScalar(e){if(this.onNewLine){let t=this.source.indexOf(`
|
|
1603
1603
|
`)+1;while(t!==0)this.onNewLine(this.offset+t),t=this.source.indexOf(`
|
|
1604
1604
|
`,t)+1}return{type:e,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(e){switch(this.type){case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":return this.flowScalar(this.type);case"block-scalar-header":return{type:"block-scalar",offset:this.offset,indent:this.indent,props:[this.sourceToken],source:""};case"flow-map-start":case"flow-seq-start":return{type:"flow-collection",offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case"seq-item-ind":return{type:"block-seq",offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case"explicit-key-ind":{this.onKeyLine=!0;let t=w$(e),i=ZT(t);return i.push(this.sourceToken),{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:i,explicitKey:!0}]}}case"map-value-ind":{this.onKeyLine=!0;let t=w$(e),i=ZT(t);return{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:i,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(e,t){if(this.type!=="comment")return!1;if(this.indent<=t)return!1;return e.every((i)=>i.type==="newline"||i.type==="space")}*documentEnd(e){if(this.type!=="doc-mode"){if(e.end)e.end.push(this.sourceToken);else e.end=[this.sourceToken];if(this.type==="newline")yield*this.pop()}}*lineEnd(e){switch(this.type){case"comma":case"doc-start":case"doc-end":case"flow-seq-end":case"flow-map-end":case"map-value-ind":yield*this.pop(),yield*this.step();break;case"newline":this.onKeyLine=!1;case"space":case"comment":default:if(e.end)e.end.push(this.sourceToken);else e.end=[this.sourceToken];if(this.type==="newline")yield*this.pop()}}}function N_t(e){let t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new v$||null,prettyErrors:t}}function XT(e,t={}){let{lineCounter:i,prettyErrors:n}=N_t(t),o=new y$(i?.addNewLine),s=new g$(t),r=null;for(let a of s.compose(o.parse(e),!0,e.length))if(!r)r=a;else if(r.options.logLevel!=="silent"){r.errors.push(new Op(a.range.slice(0,2),"MULTIPLE_DOCS","Source contains multiple documents; please use YAML.parseAllDocuments()"));break}if(n&&i)r.errors.forEach(pue(e,i)),r.warnings.forEach(pue(e,i));return r}function Tue(e,t,i){let n=null;if(typeof t==="function"||Array.isArray(t))n=t;else if(i===void 0&&t)i=t;if(typeof i==="string")i=i.length;if(typeof i==="number"){let o=Math.round(i);i=o<1?void 0:o>8?{indent:8}:{indent:o}}if(e===void 0){let{keepUndefined:o}=i??t??{};if(!o)return}if(Mm(e)&&!n)return e.toString(i);return new iv(e,n,i).toString(i)}var Fqe=(e)=>Boolean(e)&&typeof e==="object"&&!Array.isArray(e),Bqe=(e)=>({type:"string",enum:e.map((t)=>t.id),errorMessage:e.length?"Account does not exist. Add it under Accounts first.":"Add an account under Accounts first."}),Wqe=(e)=>({type:"string",enum:[...new Set(e.map((t)=>t.platform))],errorMessage:"Use the platform of the selected account."});function A_t(e){return{type:"object",additionalProperties:!1,required:["platform","account","room"],properties:{platform:Wqe(e),account:Bqe(e),room:{type:"string",minLength:1,description:"Target room ID."}},allOf:e.map((t)=>({if:{required:["account"],properties:{account:{const:t.id}}},then:{properties:{platform:{const:t.platform,errorMessage:`Account "${t.id}" uses platform "${t.platform}".`}}}}))}}var M_t={anyOf:[{type:"object",additionalProperties:!1,required:["op"],properties:{op:{const:"prefix-source"}}},{type:"object",additionalProperties:!1,required:["op"],properties:{op:{const:"trim"}}},{type:"object",additionalProperties:!1,required:["op"],properties:{op:{const:"quote-preview"}}},{type:"object",additionalProperties:!1,required:["op","max"],properties:{op:{const:"truncate"},max:{type:"integer",minimum:1}}}]};function Due(e){return{$schema:"http://json-schema.org/draft-07/schema#",title:"Integration rules",type:"array",items:{type:"object",additionalProperties:!1,required:["id","version","from","to"],properties:{id:{type:"string",minLength:1,description:"Rule name, unique with its version."},version:{type:"integer",minimum:1,description:"Bump the version to replace this rule."},from:{type:"object",description:"Where the rule reads events from.",additionalProperties:!1,required:["platform","account","room"],properties:{platform:{const:"chatroom",description:"Source platform; room messages always use chatroom.",errorMessage:"The source platform must be chatroom."},account:{const:"center",description:"Source account; room messages always use center.",errorMessage:"The source account must be center."},room:{type:"string",minLength:1,description:"Room ID to watch."},event:{enum:["message.created","message.forward_requested"],description:"Event to match; all supported events when omitted."}}},transforms:{type:"array",description:"Transformations applied to the message before delivery.",items:M_t},to:{type:"array",description:"External accounts and rooms that receive matching messages.",minItems:1,items:A_t(e)},onMissingParent:{enum:["quote_or_unthreaded","drop"],description:"What to do when the replied-to parent message is unavailable on the target."},onUnsupported:{enum:["text_with_notice","drop"],description:"What to do when the target cannot render the message content."}}}}}function Nue(e){return{$schema:"http://json-schema.org/draft-07/schema#",title:"Inbound routes",type:"array",items:{type:"object",required:["from","to"],properties:{from:{type:"object",required:["platform","account","room"],properties:{platform:Wqe(e),account:Bqe(e),room:{type:"string",minLength:1,description:"Room ID on the external platform."},event:{type:"string",description:"Optional external event filter."}},allOf:e.map((t)=>({if:{required:["account"],properties:{account:{const:t.id}}},then:{properties:{platform:{const:t.platform,errorMessage:`Account "${t.id}" uses platform "${t.platform}".`}}}}))},to:{type:"object",required:["room"],properties:{room:{type:"string",minLength:1,description:"Chat room ID that receives the message."}}}}}}}function O_t(e,t){switch(t){case void 0:return!0;case"object":return Fqe(e);case"array":return Array.isArray(e);case"string":return typeof e==="string";case"integer":return typeof e==="number"&&Number.isInteger(e);case"number":return typeof e==="number"&&Number.isFinite(e);case"boolean":return typeof e==="boolean"}}function Pqe(e,t){return Object.is(e,t)}function py(e,t,i=[],n=[]){let o=(s,r,a=i)=>{n.push({path:a,message:t.errorMessage||s,keyword:r})};if(!O_t(e,t.type))return o(`Expected ${t.type??"a supported value"}.`,"type"),n;if(t.const!==void 0&&!Pqe(e,t.const))o(`Must be ${JSON.stringify(t.const)}.`,"const");if(t.enum&&!t.enum.some((s)=>Pqe(s,e)))o(`Must be one of: ${t.enum.map((s)=>JSON.stringify(s)).join(", ")}.`,"enum");if(typeof e==="string"&&t.minLength!==void 0&&e.length<t.minLength)o("Must not be empty.","minLength");if(typeof e==="number"&&t.minimum!==void 0&&e<t.minimum)o(`Must be at least ${t.minimum}.`,"minimum");if(Array.isArray(e)){if(t.minItems!==void 0&&e.length<t.minItems)o(`Add at least ${t.minItems} item.`,"minItems");if(t.items)e.forEach((s,r)=>py(s,t.items,[...i,r],n))}if(Fqe(e)){for(let s of t.required??[])if(!Object.hasOwn(e,s))o(`Missing required field "${s}".`,"required",[...i,s]);for(let[s,r]of Object.entries(e)){let a=t.properties?.[s];if(a)py(r,a,[...i,s],n);else if(t.additionalProperties===!1)o(`Unknown field "${s}".`,"additionalProperties",[...i,s])}}for(let s of t.allOf??[])py(e,s,i,n);if(t.if&&t.then&&py(e,t.if,i,[]).length===0)py(e,t.then,i,n);for(let s of["anyOf","oneOf"]){let r=t[s];if(!r?.length)continue;let a=r.map((c)=>py(e,c,i,[])),l=a.filter((c)=>c.length===0).length;if(s==="anyOf"?l===0:l!==1)if(s==="oneOf"&&l>1)o("Matches more than one allowed shape.",s);else{let c=a.filter((d)=>d.length>0).sort((d,h)=>d.length-h.length)[0];if(c)n.push(...c);else o("Does not match any allowed shape.",s)}}return n}function Hqe(e,t){let i=e;for(let n of t)i+=typeof n==="number"?`[${n}]`:`.${n}`;return i}var TP=new Map,Vqe=!1,zqe=!1,Rue=null,Uqe=null,P_t=0,F_t=globalThis;F_t.MonacoEnvironment={getWorker(e,t){return new Worker(`/assets/monaco/${t==="json"?"json":"editor"}.worker.js`)}};function Pue(){let e=document.documentElement.dataset.theme;if(e==="custom")return document.documentElement.dataset.customDark==="true";if(e==="dark")return!0;return e!=="light"&&e!=="forest"&&e!=="sand"&&matchMedia("(prefers-color-scheme: dark)").matches}function Aue(){let e=(t,i)=>{let n=document.createElement("span");n.style.position="absolute",n.style.visibility="hidden",n.style.background=`var(${t})`,document.documentElement.append(n);let o=getComputedStyle(n).backgroundColor;n.remove();let s=document.createElement("canvas").getContext("2d");if(!s||!o)return i;return s.fillStyle="#000000",s.fillStyle=o,/^#[0-9a-f]{6}$/i.test(s.fillStyle)?s.fillStyle:i};Us.defineTheme("chatroom-light",{base:"vs",inherit:!0,rules:[],colors:{"editor.background":e("--surface","#fffefa"),"editorGutter.background":e("--surface","#fffefa"),"editor.lineHighlightBackground":e("--surface-2","#f2f0e8"),"editorLineNumber.foreground":e("--ink-3","#63716b"),"menu.background":e("--surface","#fffefa"),"menu.foreground":e("--ink","#1e2c29"),"menu.selectionBackground":e("--surface-2","#f2f0e8"),"menu.selectionForeground":e("--ink","#1e2c29"),"menu.border":e("--line","#dcded4"),"editorWidget.background":e("--surface","#fffefa"),"editorWidget.foreground":e("--ink","#1e2c29"),"editorWidget.border":e("--line","#dcded4")}}),Us.defineTheme("chatroom-dark",{base:"vs-dark",inherit:!0,rules:[],colors:{"editor.background":e("--surface","#182522"),"menu.background":e("--surface","#182522"),"menu.foreground":e("--ink","#e6efe9"),"menu.selectionBackground":e("--surface-2","#22322e"),"menu.selectionForeground":e("--ink","#e6efe9"),"menu.border":e("--line","#31433d"),"editorWidget.background":e("--surface","#182522"),"editorWidget.foreground":e("--ink","#e6efe9"),"editorWidget.border":e("--line","#31433d")}}),Us.setTheme(Pue()?"chatroom-dark":"chatroom-light")}function jqe(){if(Aue(),Rue)return;Rue=new MutationObserver(Aue),Rue.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme","data-custom-dark"]}),Uqe=matchMedia("(prefers-color-scheme: dark)"),Uqe.addEventListener("change",Aue)}function Mue(){Qhe.setDiagnosticsOptions({validate:!1,allowComments:!1,enableSchemaRequest:!1,schemas:[...TP.values()].map((e)=>({uri:e.uri,fileMatch:[`*integration-${e.kind}*`],schema:e.schema}))})}function S$(e,t,i){let n=e;for(let o of t){if(!n)return;if(typeof o==="number")n=n.items;else n=n.properties?.[o]}return i?n?.properties?.[i]:n}function Gqe(e,t){let i=e;for(let n of t){if(!i)return i;if(typeof n==="number"){if(!xh(i))return i;i=i.items[n]}else{if(!kd(i))return i;let o=i.items.find((s)=>ji(s.key)&&s.key.value===n);if(!o)return i;i=o.value}}return i}function x$(e,t,i=[]){let n=e?.range;if(!Array.isArray(n)||t<n[0]||t>n[2])return null;if(xh(e))for(let o=0;o<e.items.length;o++){let s=x$(e.items[o],t,[...i,o]);if(s)return s}else if(kd(e))for(let o of e.items){if(!ji(o.key)||typeof o.key.value!=="string")continue;let s=x$(o.value,t,[...i,o.key.value]);if(s)return s}return i}function B_t(e,t,i){let n=e.const!==void 0?[e.const]:e.enum;if(!n)return[];let o=t.getWordUntilPosition(i),s=ux.fromPositions(new QA(i.lineNumber,o.startColumn),new QA(i.lineNumber,o.endColumn));return n.map((r)=>({label:String(r),kind:Lt.CompletionItemKind.Value,insertText:String(r),range:s,detail:e.description}))}function W_t(){if(Vqe)return;Vqe=!0,Lt.registerCompletionItemProvider("yaml",{triggerCharacters:[":"," ","-"],provideCompletionItems(e,t){let i=[...TP.values()].find((g)=>g.modelUri===e.uri.toString());if(!i)return{suggestions:[]};let n;try{n=XT(e.getValue())}catch{return{suggestions:[]}}let o=n.contents,s=e.getOffsetAt(t),r=x$(o,s)??[],a=e.getLineContent(t.lineNumber).slice(0,t.column-1),l=/^\s*(?:-\s*)?["']?([A-Za-z0-9_.-]+)["']?\s*:\s*(.*)$/.exec(a);if(l){let g=l[1],_=r[r.length-1]===g?r.slice(0,-1):r,b=S$(i.schema,_,g);return{suggestions:b?B_t(b,e,t):[]}}let d=S$(i.schema,r)?.properties;if(!d)return{suggestions:[]};let h=new Set,u=Gqe(o,r);if(kd(u)){for(let g of u.items)if(ji(g.key)&&typeof g.key.value==="string")h.add(g.key.value)}let f=e.getWordUntilPosition(t),m=ux.fromPositions(new QA(t.lineNumber,f.startColumn),new QA(t.lineNumber,f.endColumn));return{suggestions:Object.entries(d).filter(([g])=>!h.has(g)).map(([g,_])=>({label:g,kind:Lt.CompletionItemKind.Property,insertText:`${g}: `,range:m,detail:_.type,documentation:_.description}))}}})}function H_t(){if(zqe)return;zqe=!0,Lt.registerHoverProvider("yaml",{provideHover(e,t){let i=[...TP.values()].find((f)=>f.modelUri===e.uri.toString());if(!i)return null;let n;try{n=XT(e.getValue())}catch{return null}let o=n.contents,s=x$(o,e.getOffsetAt(t));if(!s)return null;let r=e.getLineContent(t.lineNumber),a=/^\s*(?:-\s*)?["']?([A-Za-z0-9_.-]+)["']?\s*:/.exec(r),l,c="";if(a){let f=a[1],m=s[s.length-1]===f?s.slice(0,-1):s;l=S$(i.schema,m,f),c=f}else l=S$(i.schema,s),c=String(s[s.length-1]??"");if(!l?.description)return null;let d=e.getWordAtPosition(t),h=d?new ux(t.lineNumber,d.startColumn,t.lineNumber,d.endColumn):void 0,u=l.type?` (${String(l.type)})`:"";return{range:h,contents:[{value:`**${c}**`},{value:`${u.trim()}${u?" ":""}${l.description}`}]}}})}function Fue(e){let t=[0];for(let i=0;i<e.length;i++)if(e[i]===`
|
|
1605
|
-
`)t.push(i+1);return t}function Bue(e,t){let i=0,n=e.length-1;while(i<n){let o=Math.ceil((i+n)/2);if((e[o]??0)<=t)i=o;else n=o-1}return{line:i+1,column:t-(e[i]??0)+1}}function Yqe(e){return e.replace(/ in JSON at position \d+.*$/i,"").replace(/\s*\(line \d+ column \d+\)$/i,"").replace(/\s+at line \d+, column \d+.*$/i,"").trim()}function $qe(e){if(!e.trim())return{failure:{line:1,column:1,message:"Rules cannot be empty."}};try{let t=JSON.parse(e),i;try{i=XT(e)}catch{i=void 0}return{value:t,doc:i}}catch(t){let i=String(t.message||t),n=Fue(e),o=Number(/position (\d+)/.exec(i)?.[1]??0);return{failure:{...Bue(n,o),message:Yqe(i)||"Invalid JSON."}}}}function qqe(e){if(!e.trim())return{failure:{line:1,column:1,message:"Rules cannot be empty."}};let t=XT(e,{prettyErrors:!0});if(t.errors.length){let i=t.errors[0],n=Fue(e),o=Number(i.pos?.[0]??0),s=Bue(n,o),r=i.linePos?.[0]?.line??s.line,a=i.linePos?.[0]?.col??s.column;return{failure:{line:r,column:a,message:Yqe(i.message)||"Invalid YAML."}}}try{return{value:t.toJS(),doc:t}}catch(i){return{failure:{line:1,column:1,message:String(i.message||i)}}}}function V_t(e,t,i,n){let o=Hqe(n==="inbound"?"inbound":"rules",e.path);if(t){let r=Gqe(t.contents,e.path)?.range;if(Array.isArray(r)){let a=Fue(i);return{...Bue(a,r[0]),path:o,message:e.message}}}return{line:1,column:1,path:o,message:e.message}}function Oue(e,t){if(t==="yaml")return Tue(e,{indent:2,lineWidth:0});return JSON.stringify(e,null,2)}function Kqe(e){return e==="yaml"?"YAML":"JSON"}function z_t(e){let t=e.kind,i=e.format??"yaml",n=e.accounts,o=t==="inbound"?Nue(n):Due(n),s={kind:t,uri:`inmemory://chat/integration-${t}.schema.json`,schema:o,modelUri:`inmemory://chat/integration-${t}.json`};TP.set(t,s),Mue(),W_t(),H_t(),jqe();let r=Oue(e.value??[],i),a=Us.createModel(r,Kqe(i).toLowerCase(),eE.parse(s.modelUri)),l=Us.create(e.container,{model:a,theme:Pue()?"chatroom-dark":"chatroom-light",automaticLayout:!0,ariaLabel:t==="inbound"?"Inbound routes":"Integration rules",minimap:{enabled:!1},scrollBeyondLastLine:!1,fontSize:12,lineNumbersMinChars:3,tabSize:2,insertSpaces:!0,autoIndent:"none",autoClosingBrackets:"never",autoClosingQuotes:"never",wordWrap:"on",fixedOverflowWidgets:!0,renderLineHighlight:"line",overviewRulerLanes:0,hideCursorInOverviewRuler:!0,padding:{top:8,bottom:8},scrollbar:{verticalScrollbarSize:8,horizontalScrollbarSize:8},suggest:{showWords:!1}}),c=(_)=>{if(_.ctrlKey||_.metaKey||_.altKey||_.shiftKey)return;let b=Math.max(0,l.getScrollHeight()-l.getLayoutInfo().height),v=l.getScrollTop(),y=_.deltaY<0&&v<=0,C=_.deltaY>0&&v>=b-1;if(!y&&!C)return;let x=e.container.parentElement;while(x){let S=getComputedStyle(x);if(/(auto|scroll)/.test(S.overflowY)&&x.scrollHeight>x.clientHeight+1){x.scrollTop+=_.deltaY,_.preventDefault(),_.stopPropagation();return}x=x.parentElement}};e.container.addEventListener("wheel",c,{capture:!0,passive:!1});let d=()=>{let _=a.getValue(),b=i==="yaml"?qqe(_):$qe(_),v=[];if(b.failure)v.push({line:b.failure.line,column:b.failure.column,path:"",message:b.failure.message});else for(let y of py(b.value,o))v.push(V_t(y,b.doc,_,t));return v.sort((y,C)=>y.line-C.line||y.column-C.column),Us.setModelMarkers(a,"integration-rules",v.map((y)=>{let C=a.getLineMaxColumn(Math.min(y.line,a.getLineCount()));return{severity:SC.Error,message:y.message,startLineNumber:y.line,startColumn:y.column,endLineNumber:y.line,endColumn:Math.max(y.column+1,Math.min(C,y.column+80))}})),{kind:t,format:i,text:_,value:b.value,valid:v.length===0,errors:v}},h=()=>{let _=d();return e.onChange?.(_),_},u=(_)=>{let b=Oue(_??[],i);if(b===a.getValue())h();else a.setValue(b)},f=(_)=>{if(_===i)return;let b=i==="yaml"?qqe(a.getValue()):$qe(a.getValue());if(i=_,Us.setModelLanguage(a,Kqe(i).toLowerCase()),!b.failure){let v=Oue(b.value,i);if(v!==a.getValue())a.setValue(v);else h()}else h()},m=(_)=>{n=_,o=t==="inbound"?Nue(n):Due(n),s.schema=o,Mue(),h()},g=a.onDidChangeContent(()=>{h()});return{getKind:()=>t,getFormat:()=>i,setFormat:f,setValue:u,setAccounts:m,validate:d,reveal:(_,b)=>{let v={lineNumber:Math.max(1,_),column:Math.max(1,b)};l.revealPositionInCenter(v),l.setPosition(v),l.focus()},setReadOnly:(_)=>l.updateOptions({readOnly:_}),focus:()=>l.focus(),dispose:()=>{e.container.removeEventListener("wheel",c,!0),g.dispose(),l.dispose(),a.dispose(),TP.delete(t),Mue()}}}function U_t(e){jqe();let t=e.language||"plaintext",i=Us.createModel(e.value,t,eE.parse(`inmemory://chat/code-preview-${++P_t}.${t}`)),n=Us.create(e.container,{model:i,theme:Pue()?"chatroom-dark":"chatroom-light",readOnly:!0,automaticLayout:!0,minimap:{enabled:!1},scrollBeyondLastLine:!1,fontSize:12,lineNumbers:"on",wordWrap:"off",renderLineHighlight:"none",overviewRulerLanes:0,hideCursorInOverviewRuler:!0,folding:!0,padding:{top:10,bottom:10},scrollbar:{verticalScrollbarSize:8,horizontalScrollbarSize:8,useShadows:!1},contextmenu:!0,ariaLabel:"Code preview"});return{dispose:()=>{n.dispose(),i.dispose()}}}export{U_t as createCodePreviewEditor,z_t as createIntegrationRulesEditor};
|
|
1605
|
+
`)t.push(i+1);return t}function Bue(e,t){let i=0,n=e.length-1;while(i<n){let o=Math.ceil((i+n)/2);if((e[o]??0)<=t)i=o;else n=o-1}return{line:i+1,column:t-(e[i]??0)+1}}function Yqe(e){return e.replace(/ in JSON at position \d+.*$/i,"").replace(/\s*\(line \d+ column \d+\)$/i,"").replace(/\s+at line \d+, column \d+.*$/i,"").trim()}function $qe(e){if(!e.trim())return{failure:{line:1,column:1,message:"Rules cannot be empty."}};try{let t=JSON.parse(e),i;try{i=XT(e)}catch{i=void 0}return{value:t,doc:i}}catch(t){let i=String(t.message||t),n=Fue(e),o=Number(/position (\d+)/.exec(i)?.[1]??0);return{failure:{...Bue(n,o),message:Yqe(i)||"Invalid JSON."}}}}function qqe(e){if(!e.trim())return{failure:{line:1,column:1,message:"Rules cannot be empty."}};let t=XT(e,{prettyErrors:!0});if(t.errors.length){let i=t.errors[0],n=Fue(e),o=Number(i.pos?.[0]??0),s=Bue(n,o),r=i.linePos?.[0]?.line??s.line,a=i.linePos?.[0]?.col??s.column;return{failure:{line:r,column:a,message:Yqe(i.message)||"Invalid YAML."}}}try{return{value:t.toJS(),doc:t}}catch(i){return{failure:{line:1,column:1,message:String(i.message||i)}}}}function V_t(e,t,i,n){let o=Hqe(n==="inbound"?"inbound":"rules",e.path);if(t){let r=Gqe(t.contents,e.path)?.range;if(Array.isArray(r)){let a=Fue(i);return{...Bue(a,r[0]),path:o,message:e.message}}}return{line:1,column:1,path:o,message:e.message}}function Oue(e,t){if(t==="yaml")return Tue(e,{indent:2,lineWidth:0});return JSON.stringify(e,null,2)}function Kqe(e){return e==="yaml"?"YAML":"JSON"}function z_t(e){let t=e.kind,i=e.format??"yaml",n=e.accounts,o=t==="inbound"?Nue(n):Due(n),s={kind:t,uri:`inmemory://chat/integration-${t}.schema.json`,schema:o,modelUri:`inmemory://chat/integration-${t}.json`};TP.set(t,s),Mue(),W_t(),H_t(),jqe();let r=Oue(e.value??[],i),a=Us.createModel(r,Kqe(i).toLowerCase(),eE.parse(s.modelUri)),l=Us.create(e.container,{model:a,theme:Pue()?"chatroom-dark":"chatroom-light",automaticLayout:!0,ariaLabel:t==="inbound"?"Inbound routes":"Integration rules",minimap:{enabled:!1},scrollBeyondLastLine:!1,fontSize:12,lineNumbersMinChars:3,tabSize:2,insertSpaces:!0,autoIndent:"none",autoClosingBrackets:"never",autoClosingQuotes:"never",wordWrap:"on",fixedOverflowWidgets:!0,useShadowDOM:!1,renderLineHighlight:"line",overviewRulerLanes:0,hideCursorInOverviewRuler:!0,padding:{top:8,bottom:8},scrollbar:{verticalScrollbarSize:8,horizontalScrollbarSize:8},suggest:{showWords:!1}}),c=(_)=>{if(_.ctrlKey||_.metaKey||_.altKey||_.shiftKey)return;let b=Math.max(0,l.getScrollHeight()-l.getLayoutInfo().height),v=l.getScrollTop(),y=_.deltaY<0&&v<=0,C=_.deltaY>0&&v>=b-1;if(!y&&!C)return;let x=e.container.parentElement;while(x){let S=getComputedStyle(x);if(/(auto|scroll)/.test(S.overflowY)&&x.scrollHeight>x.clientHeight+1){x.scrollTop+=_.deltaY,_.preventDefault(),_.stopPropagation();return}x=x.parentElement}};e.container.addEventListener("wheel",c,{capture:!0,passive:!1});let d=()=>{let _=a.getValue(),b=i==="yaml"?qqe(_):$qe(_),v=[];if(b.failure)v.push({line:b.failure.line,column:b.failure.column,path:"",message:b.failure.message});else for(let y of py(b.value,o))v.push(V_t(y,b.doc,_,t));return v.sort((y,C)=>y.line-C.line||y.column-C.column),Us.setModelMarkers(a,"integration-rules",v.map((y)=>{let C=a.getLineMaxColumn(Math.min(y.line,a.getLineCount()));return{severity:SC.Error,message:y.message,startLineNumber:y.line,startColumn:y.column,endLineNumber:y.line,endColumn:Math.max(y.column+1,Math.min(C,y.column+80))}})),{kind:t,format:i,text:_,value:b.value,valid:v.length===0,errors:v}},h=()=>{let _=d();return e.onChange?.(_),_},u=(_)=>{let b=Oue(_??[],i);if(b===a.getValue())h();else a.setValue(b)},f=(_)=>{if(_===i)return;let b=i==="yaml"?qqe(a.getValue()):$qe(a.getValue());if(i=_,Us.setModelLanguage(a,Kqe(i).toLowerCase()),!b.failure){let v=Oue(b.value,i);if(v!==a.getValue())a.setValue(v);else h()}else h()},m=(_)=>{n=_,o=t==="inbound"?Nue(n):Due(n),s.schema=o,Mue(),h()},g=a.onDidChangeContent(()=>{h()});return{getKind:()=>t,getFormat:()=>i,setFormat:f,setValue:u,setAccounts:m,validate:d,reveal:(_,b)=>{let v={lineNumber:Math.max(1,_),column:Math.max(1,b)};l.revealPositionInCenter(v),l.setPosition(v),l.focus()},setReadOnly:(_)=>l.updateOptions({readOnly:_}),focus:()=>l.focus(),dispose:()=>{e.container.removeEventListener("wheel",c,!0),g.dispose(),l.dispose(),a.dispose(),TP.delete(t),Mue()}}}function U_t(e){jqe();let t=e.language||"plaintext",i=Us.createModel(e.value,t,eE.parse(`inmemory://chat/code-preview-${++P_t}.${t}`)),n=Us.create(e.container,{model:i,theme:Pue()?"chatroom-dark":"chatroom-light",readOnly:!0,automaticLayout:!0,minimap:{enabled:!1},scrollBeyondLastLine:!1,fontSize:12,lineNumbers:"on",wordWrap:"off",renderLineHighlight:"none",overviewRulerLanes:0,hideCursorInOverviewRuler:!0,folding:!0,padding:{top:10,bottom:10},scrollbar:{verticalScrollbarSize:8,horizontalScrollbarSize:8,useShadows:!1},contextmenu:!0,useShadowDOM:!1,ariaLabel:"Code preview"}),o=!1,s=(r)=>{if(!r.altKey||r.ctrlKey||r.metaKey||r.shiftKey||r.code!=="KeyZ")return;if(r.preventDefault(),r.stopPropagation(),r.repeat)return;o=!o,n.updateOptions({wordWrap:o?"on":"off"})};return e.container.addEventListener("keydown",s,!0),{dispose:()=>{e.container.removeEventListener("keydown",s,!0),n.dispose(),i.dispose()}}}export{U_t as createCodePreviewEditor,z_t as createIntegrationRulesEditor};
|
|
@@ -140,7 +140,9 @@
|
|
|
140
140
|
.rail-composer .field { margin-bottom: 8px; }
|
|
141
141
|
.rail-composer .btn { width: 100%; }
|
|
142
142
|
.mobile-locale { display: none; }
|
|
143
|
-
|
|
143
|
+
/* The scroller reaches the rail divider so its scrollbar hugs the edge; the
|
|
144
|
+
padding keeps the rows on the rail's 14px inset. */
|
|
145
|
+
.rail-rooms { flex: 1; min-height: 0; overflow: auto; list-style: none; margin: 0 -14px 0 0; padding: 0 14px 0 0; }
|
|
144
146
|
#roomListChat .room-row { padding: 11px 12px; border-color: transparent; border-radius: 12px; }
|
|
145
147
|
#roomListChat .room-row::before {
|
|
146
148
|
content: "";
|
|
@@ -171,8 +173,10 @@
|
|
|
171
173
|
.r-kind { color: var(--accent); font-size: 11px; font-weight: 700; }
|
|
172
174
|
.r-status { color: var(--accent); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
|
|
173
175
|
.r-preview { overflow: hidden; color: var(--ink-3); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
|
|
174
|
-
.r-
|
|
176
|
+
.r-badges { position: absolute; top: 8px; right: 9px; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
|
|
177
|
+
.r-badge { display: grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 10px; font-weight: 700; }
|
|
175
178
|
.r-badge-question { background: var(--warning); color: var(--warning-ink); font-size: 12px; }
|
|
179
|
+
.r-badge-requests { background: var(--warning); color: var(--warning-ink); font-size: 12px; }
|
|
176
180
|
/* The rail footer keeps the empty composer's height so the divider lines meet when
|
|
177
181
|
idle. Files or wrapped lines grow only the composer, never this footer. */
|
|
178
182
|
.rail-foot { display: flex; flex-direction: column; justify-content: center; align-items: stretch; gap: 8px; margin-top: auto; min-height: var(--composer-block, 104px); padding: 12px 4px 14px; border-top: 1px solid color-mix(in srgb, var(--line) 80%, transparent); font-size: 12px; color: var(--ink-3); }
|
|
@@ -183,6 +187,12 @@
|
|
|
183
187
|
#roomRail .rail-label { margin-bottom: 6px; }
|
|
184
188
|
#roomListChat .room-row { gap: 1px; padding: 5px 9px; }
|
|
185
189
|
#roomListChat .r-kind:empty, #roomListChat .r-meta, #roomListChat .r-preview { display: none; }
|
|
190
|
+
/* Collapsed rows are too short for two stacked badges; sit them side by side
|
|
191
|
+
and reserve their width so the name truncates instead of running under them. */
|
|
192
|
+
.r-badges { top: 5px; flex-direction: row-reverse; gap: 1px; }
|
|
193
|
+
#roomListChat .room-row:has(.r-badges) { padding-right: 44px; }
|
|
194
|
+
.r-badge { min-width: 16px; height: 16px; padding: 0 4px; font-size: 9px; }
|
|
195
|
+
.r-badge-question, .r-badge-requests { font-size: 10px; }
|
|
186
196
|
}
|
|
187
197
|
@media (max-height: 400px) {
|
|
188
198
|
#chatView { margin: 10px auto; height: calc(100% - 20px); }
|
|
@@ -258,7 +258,9 @@
|
|
|
258
258
|
.integration-rule-error:hover { text-decoration: underline; }
|
|
259
259
|
.integration-rule-error:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
260
260
|
.integration-field-error { margin: 0; color: var(--danger); font-size: 12px; line-height: 1.45; white-space: pre-wrap; }
|
|
261
|
-
|
|
261
|
+
/* No trailing panel padding: it would un-stick the save row for its last pixels of scroll. */
|
|
262
|
+
.settings-panel.integration-panel { padding-bottom: 0; }
|
|
263
|
+
.integration-actions { position: sticky; bottom: 0; z-index: 1; display: flex; justify-content: flex-end; padding: 10px 0 14px; border-top: 1px solid color-mix(in srgb, var(--line) 72%, transparent); background: var(--surface); }
|
|
262
264
|
.integration-dialog { width: min(620px, calc(100vw - 24px)); max-height: min(820px, 90dvh); }
|
|
263
265
|
.integration-dialog[open] { display: flex; flex-direction: column; overflow: hidden; }
|
|
264
266
|
.integration-form { display: grid; gap: 10px; min-height: 0; padding: 0 20px 20px; overflow-y: auto; }
|
package/server/assets/tasks.css
CHANGED
|
@@ -127,7 +127,11 @@
|
|
|
127
127
|
padding: 4px 28px 4px 9px;
|
|
128
128
|
font-size: 12px;
|
|
129
129
|
}
|
|
130
|
-
|
|
130
|
+
/* The fixed line box keeps an empty summary from shrinking the toolbar. */
|
|
131
|
+
.tasks-summary { min-height: 1.4em; margin: 0 0 0 auto; color: var(--ink-3); font-size: 11.5px; line-height: 1.4; }
|
|
132
|
+
/* A reload spins the reload glyph in place, so the rows and the toolbar hold
|
|
133
|
+
their geometry while the request is in flight. */
|
|
134
|
+
#btnRefreshTasks.is-refreshing svg { animation: spin .8s linear infinite; }
|
|
131
135
|
|
|
132
136
|
.tasks-error {
|
|
133
137
|
display: flex;
|
|
@@ -466,4 +470,5 @@
|
|
|
466
470
|
|
|
467
471
|
@media (prefers-reduced-motion: reduce) {
|
|
468
472
|
#tasksDialog[open], #taskEditDialog[open], .task-row { animation: none; }
|
|
473
|
+
#btnRefreshTasks.is-refreshing svg { animation: none; opacity: .7; }
|
|
469
474
|
}
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
html[data-wco="true"] body {
|
|
5
5
|
display: grid;
|
|
6
6
|
grid-template-rows: calc(env(titlebar-area-y, var(--wco-top, 0px)) + env(titlebar-area-height, var(--wco-height, 0px))) minmax(0, 1fr);
|
|
7
|
-
|
|
7
|
+
/* Chrome reads a step deeper than the page backdrop, so the strip and the
|
|
8
|
+
room header under it stay apart in both schemes. */
|
|
9
|
+
background: color-mix(in srgb, var(--bg) 94%, #000);
|
|
8
10
|
}
|
|
9
11
|
html[data-wco="true"] #app {
|
|
10
12
|
grid-row: 2;
|
package/server/channels.ts
CHANGED
|
@@ -522,7 +522,8 @@ export async function channelRoutes(
|
|
|
522
522
|
|
|
523
523
|
const message = await readForwardableMessage(roomId, messageId, sessionID);
|
|
524
524
|
if (!message) return json({ error: "message not found" }, 404);
|
|
525
|
-
if (runtime
|
|
525
|
+
if (!forwardTargets(runtime, roomId).some((candidate) =>
|
|
526
|
+
candidate.platform === target.platform && candidate.account === target.account && candidate.room === target.room)) {
|
|
526
527
|
return json({ error: "forward target is unavailable" }, 409);
|
|
527
528
|
}
|
|
528
529
|
|
|
@@ -564,4 +565,4 @@ export async function channelRoutes(
|
|
|
564
565
|
if (!sessionID || sessionID.length > MAX_SESSION) return json({ error: "sessionID is required" }, 400);
|
|
565
566
|
if (!await isRoomMember(roomId, sessionID)) return json({ error: "room not found" }, 404);
|
|
566
567
|
return json({ targets: forwardTargets(runtime, roomId) });
|
|
567
|
-
}
|
|
568
|
+
}
|
package/server/chat.html
CHANGED
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
<section id="joinView" class="view" hidden>
|
|
67
67
|
<div class="join-shell">
|
|
68
68
|
<header class="join-head">
|
|
69
|
-
<div class="wordmark-row"><span class="brand-mark" aria-hidden="true">OC</span><p class="wordmark" data-i18n="brand">OC Chat</p><span class="version-tag"
|
|
69
|
+
<div class="wordmark-row"><span class="brand-mark" aria-hidden="true">OC</span><p class="wordmark" data-i18n="brand">OC Chat</p><span class="version-tag" title="{{version}}">{{versionLabel}}</span></div>
|
|
70
70
|
<button id="btnJoinSettings" class="join-settings" type="button" aria-haspopup="dialog" aria-controls="chatSettings" aria-expanded="false">
|
|
71
71
|
<svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-options-24"></use></svg>
|
|
72
72
|
<span data-i18n="settings">Settings</span>
|
|
@@ -425,7 +425,7 @@
|
|
|
425
425
|
<!-- Shared room workspace. -->
|
|
426
426
|
<section id="chatView" class="view" hidden>
|
|
427
427
|
<aside id="roomRail" class="room-rail" aria-label="Rooms" data-i18n-aria-label="roomsLabel">
|
|
428
|
-
<div class="rail-brand"><span class="brand-mark">OC</span><span data-i18n="brand">OC Chat</span><span class="version-tag"
|
|
428
|
+
<div class="rail-brand"><span class="brand-mark">OC</span><span class="brand-name" data-i18n="brand">OC Chat</span><span class="version-tag" title="{{version}}">{{versionLabel}}</span></div>
|
|
429
429
|
<div class="rail-label"><span data-i18n="existingRooms">Rooms</span><span class="rail-tools"><button id="btnNewRoom" class="icon-btn" type="button" aria-label="Create a room" data-i18n-aria-label="newRoom" aria-haspopup="dialog" aria-controls="createRoomDialog" aria-expanded="false"><svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-add-24"></use></svg></button><button id="btnRefreshRooms" class="icon-btn" type="button" aria-label="Refresh rooms" data-i18n-aria-label="refreshRooms"><svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-arrow_sync-24"></use></svg></button></span></div>
|
|
430
430
|
<ul id="roomListChat" class="rail-rooms"></ul>
|
|
431
431
|
<p id="roomListChatEmpty" class="hint" data-i18n="noRooms" hidden></p>
|
|
@@ -781,6 +781,10 @@
|
|
|
781
781
|
<button type="button" id="btnCloseReaders" class="reader-close" data-i18n-aria-label="close" aria-label="Close"><svg class="fluent-icon close-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-dismiss-24"></use></svg></button>
|
|
782
782
|
</div>
|
|
783
783
|
<ul id="readerList" class="receipt-reader-list" aria-label="Message readers" data-i18n-aria-label="readerPanelTitle"></ul>
|
|
784
|
+
<section id="deliveredGroup" class="reader-delivered" hidden>
|
|
785
|
+
<p id="deliveredCount" class="hint"></p>
|
|
786
|
+
<ul id="deliveredList" class="receipt-reader-list"></ul>
|
|
787
|
+
</section>
|
|
784
788
|
</aside>
|
|
785
789
|
|
|
786
790
|
<footer class="composer">
|
|
@@ -936,6 +940,7 @@
|
|
|
936
940
|
<ul class="keys-list">
|
|
937
941
|
<li><span class="keys-combo"><kbd class="keys-key shortcut-mod">Alt</kbd><span class="keys-sep">+</span><kbd class="keys-key">↑</kbd><span class="keys-sep">/</span><kbd class="keys-key">↓</kbd></span><span data-i18n="shortcutsSwitchRoom">Switch to the previous or next room</span></li>
|
|
938
942
|
<li><span class="keys-combo"><kbd class="keys-key shortcut-mod">Alt</kbd><span class="keys-sep">+</span><kbd class="keys-key">1–9</kbd></span><span data-i18n="shortcutsNumberRoom">Switch to a joined room by number</span></li>
|
|
943
|
+
<li><span class="keys-combo"><kbd class="keys-key shortcut-mod">Alt</kbd><span class="keys-sep">+</span><kbd class="keys-key">Shift</kbd><span class="keys-sep">+</span><kbd class="keys-key">↑</kbd><span class="keys-sep">/</span><kbd class="keys-key">↓</kbd></span><span data-i18n="shortcutsMoveRoom">Move the focused room up or down</span></li>
|
|
939
944
|
</ul>
|
|
940
945
|
</section>
|
|
941
946
|
<section class="keys-section">
|
package/server/inbox.ts
CHANGED
|
@@ -5,8 +5,10 @@ export type InboxItem = Pick<Message, "id" | "roomId" | "senderId" | "senderSess
|
|
|
5
5
|
roomName: string;
|
|
6
6
|
roomKind?: "group" | "direct";
|
|
7
7
|
answerQuestionExcerpt?: string;
|
|
8
|
+
// Only on the sender's own message in an incremental, room-scoped poll.
|
|
9
|
+
clientMessageID?: string;
|
|
8
10
|
};
|
|
9
|
-
export type InboxResult = { member: boolean; items: InboxItem[]; queuedTs: Record<string, number>; hasMore: boolean; recallVersion: number };
|
|
11
|
+
export type InboxResult = { member: boolean; items: InboxItem[]; queuedTs: Record<string, number>; hasMore: boolean; recallVersion: number; membershipID?: string };
|
|
10
12
|
|
|
11
13
|
export async function readInbox(sessionID: string, roomFilter: string | null, excludeSelf: boolean, afterTs?: number): Promise<InboxResult> {
|
|
12
14
|
return readInboxMessages(sessionID, roomFilter, excludeSelf, excludeSelf ? 20 : 100, afterTs);
|
package/server/join-requests.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { databasePath, listJoinRequests, readJoinRequest, readState } from "../src/state/store.ts";
|
|
2
2
|
import { findJoinRequest, removeJoinRequest, writeSqliteStateWithDatabase } from "../src/state/sqlite-state.ts";
|
|
3
|
+
import { pendingJoinRequestRoomIDs } from "../src/state/sqlite-members.ts";
|
|
3
4
|
import { binding, tx, validCurrent } from "./admin-state.ts";
|
|
4
5
|
import { hasAdminCapability } from "./admin-auth.ts";
|
|
5
6
|
import { isRoomAdmin } from "./room-owner.ts";
|
|
@@ -28,6 +29,12 @@ function bounded(value: unknown): value is string {
|
|
|
28
29
|
// Approval-protected joins: requests stay in SQLite until a reviewer consumes
|
|
29
30
|
// them; denial removes the row so the requester can try again.
|
|
30
31
|
export async function joinRequestRoutes(req: Request, url: URL): Promise<Response | undefined> {
|
|
32
|
+
if (url.pathname === "/rooms/pending-join-requests") {
|
|
33
|
+
if (req.method !== "GET") return json({ error: "method not allowed" }, 405);
|
|
34
|
+
const sessionID = url.searchParams.get("sessionID");
|
|
35
|
+
if (!bounded(sessionID)) return json({ error: "sessionID is required" }, 400);
|
|
36
|
+
return json({ roomIDs: await pendingJoinRequestRoomIDs(databasePath(), sessionID) });
|
|
37
|
+
}
|
|
31
38
|
const status = url.pathname.match(/^\/rooms\/([^/]+)\/join-requests\/status$/);
|
|
32
39
|
const list = url.pathname.match(/^\/rooms\/([^/]+)\/join-requests$/);
|
|
33
40
|
const action = url.pathname.match(/^\/rooms\/([^/]+)\/join-requests\/([^/]+)\/(approve|deny)$/);
|
|
@@ -115,4 +122,4 @@ export async function joinRequestRoutes(req: Request, url: URL): Promise<Respons
|
|
|
115
122
|
}
|
|
116
123
|
|
|
117
124
|
return json({ error: "method not allowed" }, 405);
|
|
118
|
-
}
|
|
125
|
+
}
|
package/server/member-routes.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { memberActivity, type WorkState } from "../src/state/member-state.ts";
|
|
2
|
-
import { acknowledgeRead, acknowledgeReadWithReceipts, readReceipts, readState, recordMessageReceipts, reportPresence, type ReceiptEvidence, type ReceiptIdentity } from "../src/state/store.ts";
|
|
2
|
+
import { acknowledgeRead, acknowledgeReadWithReceipts, readReceipts, readState, recordMessageDeliveries, recordMessageReceipts, reportPresence, type ReceiptEvidence, type ReceiptIdentity } from "../src/state/store.ts";
|
|
3
3
|
import { isReceiverOwnerID } from "../src/state/receiver-owner.ts";
|
|
4
4
|
import { clearPendingAdmission } from "../src/center/queue.ts";
|
|
5
5
|
import { touchActive } from "./wake.ts";
|
|
@@ -79,6 +79,20 @@ export async function memberRoutes(req: Request, url: URL): Promise<Response | u
|
|
|
79
79
|
if (result.status === "messageIDs") return json({ error: "message IDs do not belong to this room" }, 400);
|
|
80
80
|
return json({ acceptedIDs: result.acceptedIDs });
|
|
81
81
|
}
|
|
82
|
+
const deliveryRoute = url.pathname.match(/^\/rooms\/([^/]+)\/deliveries$/);
|
|
83
|
+
if (req.method === "POST" && deliveryRoute) {
|
|
84
|
+
const body: unknown = await req.json();
|
|
85
|
+
if (!object(body)) return json({ error: "JSON object body is required" }, 400);
|
|
86
|
+
const sessionID = body.sessionID, membershipID = body.membershipID, ownerID = body.receiverOwnerID, ids = body.messageIDs;
|
|
87
|
+
if (typeof sessionID !== "string" || !sessionID || sessionID.length > 128 ||
|
|
88
|
+
typeof membershipID !== "string" || !membershipID || membershipID.length > 128 ||
|
|
89
|
+
!Array.isArray(ids) || !ids.length || ids.length > 500 || ids.some((id) => typeof id !== "string" || !id || id.length > 128) ||
|
|
90
|
+
!isReceiverOwnerID(ownerID)) return json({ error: "invalid message delivery" }, 400);
|
|
91
|
+
const result = await recordMessageDeliveries(decodeURIComponent(deliveryRoute[1]!), sessionID, ids as string[], { membershipID, receiverOwnerID: ownerID });
|
|
92
|
+
if (result.status === "membership") return json({ error: "membership generation mismatch" }, 409);
|
|
93
|
+
if (result.status === "messageIDs") return json({ error: "message IDs do not belong to this room" }, 400);
|
|
94
|
+
return json({ acceptedIDs: result.acceptedIDs });
|
|
95
|
+
}
|
|
82
96
|
const match = url.pathname.match(/^\/rooms\/([^/]+)\/(members|receipts)$/);
|
|
83
97
|
if (req.method === "GET" && match) {
|
|
84
98
|
const roomID = decodeURIComponent(match[1]!);
|
|
@@ -97,7 +111,7 @@ export async function memberRoutes(req: Request, url: URL): Promise<Response | u
|
|
|
97
111
|
if (ids && (!ids.length || ids.length > 500 || ids.some((id) => !id || id.length > 128))) return json({ error: "invalid message IDs" }, 400);
|
|
98
112
|
const receipts = await readReceipts(roomID, ids);
|
|
99
113
|
if (!receipts) return json({ error: "message IDs do not belong to this room" }, 400);
|
|
100
|
-
return json({ receipts: receipts.map((item) => ({ messageID: item.messageID, readers: item.readers.map((reader) => ({ ...reader, currentMember: Boolean(registry[reader.sessionID]) })) })), semantics: "per-message" });
|
|
114
|
+
return json({ receipts: receipts.map((item) => ({ messageID: item.messageID, readers: item.readers.map((reader) => ({ ...reader, currentMember: Boolean(registry[reader.sessionID]) })), ...(item.deliveredTo?.length ? { deliveredTo: item.deliveredTo } : {}) })), semantics: "per-message" });
|
|
101
115
|
}
|
|
102
116
|
if (req.method !== "POST" || url.pathname !== "/presence") return undefined;
|
|
103
117
|
const body: unknown = await req.json();
|
package/server/newrooms.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { hasAdminCapability } from "./admin-auth.ts";
|
|
|
6
6
|
import { roomPayload } from "./room-payload.ts";
|
|
7
7
|
import { clearPendingAdmission } from "../src/center/queue.ts";
|
|
8
8
|
import { removeRoomResources } from "../src/rooms/resources.ts";
|
|
9
|
-
import { isOwnerEntry, isRoomAdmin, isUser } from "./room-owner.ts";
|
|
9
|
+
import { applyOwnerTransfer, isOwnerEntry, isRoomAdmin, isUser } from "./room-owner.ts";
|
|
10
10
|
|
|
11
11
|
const json = (body: unknown, status = 200) => Response.json(body, { status });
|
|
12
12
|
const mutate = <T>(fn: (service: RoomService, registry: import("../src/state/store.ts").Registry) => T) => writeState(fn);
|
|
@@ -178,18 +178,7 @@ export async function roomManagement(req: Request, url: URL): Promise<Response |
|
|
|
178
178
|
const target = Object.values(registry[roomId] ?? {}).find((entry) => entry.name === nextOwner && isUser(entry));
|
|
179
179
|
if (!target) return { status: 409 as const, error: "the new owner must be a person in this room" };
|
|
180
180
|
changes.push(`${actor.name} handed the room to ${nextOwner}`);
|
|
181
|
-
room
|
|
182
|
-
if (target.membershipID) room.ownerMembershipID = target.membershipID; else delete room.ownerMembershipID;
|
|
183
|
-
delete room.successorId;
|
|
184
|
-
delete room.successorMembershipID;
|
|
185
|
-
if (room.adminIds) {
|
|
186
|
-
const remaining = room.adminIds.filter((name) => name !== nextOwner);
|
|
187
|
-
if (remaining.length) room.adminIds = remaining; else delete room.adminIds;
|
|
188
|
-
}
|
|
189
|
-
if (target.membershipID && room.adminMembershipIDs?.length) {
|
|
190
|
-
const remaining = room.adminMembershipIDs.filter((id) => id !== target.membershipID);
|
|
191
|
-
if (remaining.length) room.adminMembershipIDs = remaining; else delete room.adminMembershipIDs;
|
|
192
|
-
}
|
|
181
|
+
applyOwnerTransfer(room, target);
|
|
193
182
|
}
|
|
194
183
|
if (changes.length) svc.addEvent(roomId, changes.join("; "));
|
|
195
184
|
return { room };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { safeEqual } from "./admin-state.ts";
|
|
2
|
+
|
|
3
|
+
// The operator panel is opt-in and separate from the shared room bearer. A
|
|
4
|
+
// short or malformed value, or the same value as the shared bearer, disables it.
|
|
5
|
+
const OPERATOR_TOKEN = /^[A-Za-z0-9_-]{43,128}$/;
|
|
6
|
+
|
|
7
|
+
// Resolve once per app. A future identity provider only replaces this function.
|
|
8
|
+
export function resolveOperatorToken(option: string | undefined, sharedToken: string | undefined): string | undefined {
|
|
9
|
+
const token = option ?? process.env.CHAT_ROOM_OPERATOR_TOKEN;
|
|
10
|
+
if (!token || !OPERATOR_TOKEN.test(token)) return undefined;
|
|
11
|
+
if (sharedToken && token === sharedToken) return undefined;
|
|
12
|
+
return token;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// One place to verify the operator bearer; request paths and DB never run first.
|
|
16
|
+
export function operatorAuthorized(request: Request, token: string | undefined): boolean {
|
|
17
|
+
if (!token) return false;
|
|
18
|
+
const header = request.headers.get("authorization");
|
|
19
|
+
if (!header?.startsWith("Bearer ")) return false;
|
|
20
|
+
return safeEqual(header.slice("Bearer ".length), token);
|
|
21
|
+
}
|