@alexsun-top/opencode-chat-room 0.8.5 → 0.8.7
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 +23 -2
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/cli.ts +19 -0
- package/dist/cli.js +4058 -1531
- package/package.json +7 -1
- package/packages/chat-room-channeld/README.md +13 -8
- package/packages/chat-room-channeld/src/adapter.ts +52 -0
- package/packages/chat-room-channeld/src/config.ts +6 -1
- package/packages/chat-room-channeld/src/delivery.ts +0 -4
- package/packages/chat-room-channeld/src/host.ts +66 -44
- package/packages/chat-room-channeld/src/inbound.ts +14 -1
- 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/protocol.ts +38 -1
- package/packages/chat-room-channeld/src/state-rows.ts +132 -0
- package/packages/chat-room-channeld/src/state.ts +129 -157
- package/packages/chat-room-channeld/src/stats.ts +4 -0
- package/plugin.ts +26 -5
- package/server/app.ts +15 -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 +11 -2
- 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 +30 -2
- 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 +24 -6
- package/server/chat-server.ts +4 -0
- package/server/chat.html +7 -2
- package/server/inbox.ts +3 -1
- package/server/join-requests.ts +8 -1
- package/server/mcp-http.ts +88 -0
- 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 +19 -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 +18 -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 +407 -0
- package/src/protocol/config.ts +7 -0
- package/src/runtime/plugin-notifications.ts +43 -9
- package/src/runtime/v2-plugin.ts +20 -4
- 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); }
|
|
@@ -345,6 +350,7 @@
|
|
|
345
350
|
.message-readers[data-reader-state="empty"], .message-readers[data-reader-state="unknown"] { background: var(--surface-2); }
|
|
346
351
|
.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
352
|
.message-read-check { display: block; width: 14px; height: 14px; }
|
|
353
|
+
.reader-delivered { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
|
|
348
354
|
.message-readers:hover, .message-readers[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }
|
|
349
355
|
.message-readers:focus-visible, .reader-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
350
356
|
.receipt-reader-list { margin: 0; padding: 0; list-style: none; }
|
|
@@ -705,3 +711,25 @@
|
|
|
705
711
|
#msgList.room-content-out-prev { animation: room-content-out-prev .14s ease-in both; }
|
|
706
712
|
#msgList.room-content-in-next { animation: room-content-in-next .2s ease-out both; }
|
|
707
713
|
#msgList.room-content-in-prev { animation: room-content-in-prev .2s ease-out both; }
|
|
714
|
+
|
|
715
|
+
/* Room reordering: native drag on pointer devices, move buttons where dragging is unavailable. */
|
|
716
|
+
#roomList > li, #roomListChat > li { display: flex; align-items: center; }
|
|
717
|
+
#roomList > li > .room-row, #roomListChat > li > .room-row { flex: 1; min-width: 0; }
|
|
718
|
+
.room-row[draggable="true"] { cursor: grab; }
|
|
719
|
+
.room-row.dragging { opacity: .45; }
|
|
720
|
+
.room-row.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
|
|
721
|
+
.room-row.drop-after { box-shadow: inset 0 -2px 0 var(--accent); }
|
|
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
|
@@ -25,7 +25,7 @@ import { createHost, type ChannelHost, type SpawnAdapter } from "../packages/cha
|
|
|
25
25
|
import { validateTargets } from "../packages/chat-room-channeld/src/host-helpers.ts";
|
|
26
26
|
import { EVENT_SCHEMA_VERSION, type Endpoint, type IngestEvent } from "../packages/chat-room-channeld/src/protocol.ts";
|
|
27
27
|
import { matchRules, targetKey } from "../packages/chat-room-channeld/src/rules.ts";
|
|
28
|
-
import { inboundRoomText,
|
|
28
|
+
import { inboundRoomText, inboundRoutes } from "../packages/chat-room-channeld/src/inbound.ts";
|
|
29
29
|
import { forwardAttachments, inboundAttachments, prepareSendPayload } from "./channel-attachments.ts";
|
|
30
30
|
import {
|
|
31
31
|
isTerminalDeliveryState,
|
|
@@ -147,9 +147,9 @@ export function createInboundRelay(config: ChannelConfig): {
|
|
|
147
147
|
notificationOnly: (event: IngestEvent) => boolean;
|
|
148
148
|
} {
|
|
149
149
|
return {
|
|
150
|
-
notificationOnly: (event) =>
|
|
150
|
+
notificationOnly: (event) => inboundRoutes(config, event).length > 0,
|
|
151
151
|
onIngestCommitted: async (event) => {
|
|
152
|
-
for (const route of
|
|
152
|
+
for (const route of inboundRoutes(config, event)) {
|
|
153
153
|
const text = inboundRoomText(event, route);
|
|
154
154
|
if (!text && !event.content?.attachments?.length) continue;
|
|
155
155
|
// Resource uploads are idempotent per event, room, and index, so a
|
|
@@ -332,7 +332,8 @@ export function createChannelController(
|
|
|
332
332
|
const handle = async (req: Request, url: URL): Promise<Response | undefined> => {
|
|
333
333
|
const adminPath = url.pathname === "/channeld/reload"
|
|
334
334
|
|| url.pathname === "/channeld/enable"
|
|
335
|
-
|| url.pathname === "/channeld/disable"
|
|
335
|
+
|| url.pathname === "/channeld/disable"
|
|
336
|
+
|| url.pathname === "/channeld/op";
|
|
336
337
|
const integrationPath = url.pathname === "/channeld/plugins"
|
|
337
338
|
|| url.pathname.startsWith("/channeld/plugins/")
|
|
338
339
|
|| url.pathname === "/channeld/integration";
|
|
@@ -350,6 +351,22 @@ export function createChannelController(
|
|
|
350
351
|
|
|
351
352
|
if (url.pathname === "/channeld/disable") return serial(disableCore);
|
|
352
353
|
|
|
354
|
+
if (url.pathname === "/channeld/op") {
|
|
355
|
+
if (!runtime) return json({ error: "relay is disabled; enable it first" }, 409);
|
|
356
|
+
const raw = await req.json().catch(() => undefined) as Record<string, unknown> | undefined;
|
|
357
|
+
const account = typeof raw?.account === "string" ? raw.account.trim() : "";
|
|
358
|
+
const op = typeof raw?.op === "string" ? raw.op.trim() : "";
|
|
359
|
+
if (!account || !op) return json({ error: "account and op are required" }, 400);
|
|
360
|
+
const params = raw?.params && typeof raw.params === "object" && !Array.isArray(raw.params)
|
|
361
|
+
? raw.params as Record<string, unknown>
|
|
362
|
+
: {};
|
|
363
|
+
try {
|
|
364
|
+
return json({ ok: true, result: await runtime.host.runOp(account, op, params) });
|
|
365
|
+
} catch (error) {
|
|
366
|
+
return json({ error: error instanceof Error ? error.message : String(error) }, 502);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
353
370
|
const body = await readAdminBody(req);
|
|
354
371
|
if (!body.ok) return json({ error: "invalid request body" }, 400);
|
|
355
372
|
const configPath = body.config ?? settings.channeld.config;
|
|
@@ -522,7 +539,8 @@ export async function channelRoutes(
|
|
|
522
539
|
|
|
523
540
|
const message = await readForwardableMessage(roomId, messageId, sessionID);
|
|
524
541
|
if (!message) return json({ error: "message not found" }, 404);
|
|
525
|
-
if (runtime
|
|
542
|
+
if (!forwardTargets(runtime, roomId).some((candidate) =>
|
|
543
|
+
candidate.platform === target.platform && candidate.account === target.account && candidate.room === target.room)) {
|
|
526
544
|
return json({ error: "forward target is unavailable" }, 409);
|
|
527
545
|
}
|
|
528
546
|
|
|
@@ -564,4 +582,4 @@ export async function channelRoutes(
|
|
|
564
582
|
if (!sessionID || sessionID.length > MAX_SESSION) return json({ error: "sessionID is required" }, 400);
|
|
565
583
|
if (!await isRoomMember(roomId, sessionID)) return json({ error: "room not found" }, 404);
|
|
566
584
|
return json({ targets: forwardTargets(runtime, roomId) });
|
|
567
|
-
}
|
|
585
|
+
}
|
package/server/chat-server.ts
CHANGED
|
@@ -17,6 +17,10 @@ const serve = createApp({
|
|
|
17
17
|
token: bootstrap.token,
|
|
18
18
|
serveWakeUrl: bootstrap.serveWakeUrl,
|
|
19
19
|
channeld: () => channels,
|
|
20
|
+
mcp: {
|
|
21
|
+
center: `http://127.0.0.1:${bootstrap.port}`,
|
|
22
|
+
sessionID: process.env.CHAT_ROOM_MCP_SESSION ?? "ses_mcp_http",
|
|
23
|
+
},
|
|
20
24
|
});
|
|
21
25
|
// Test-only request accounting: asset hits prove whether a warm open re-downloaded.
|
|
22
26
|
const handle: typeof serve = process.env.CHAT_ROOM_TEST_ACCESS_LOG === "1"
|
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
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Streamable HTTP transport for the MCP room tool (MCP 2025-03-26).
|
|
2
|
+
// Stateless: every POST carries one JSON-RPC message or a batch; SSE is not
|
|
3
|
+
// offered, so requests answer with application/json and notifications get 202.
|
|
4
|
+
import { randomUUID, timingSafeEqual } from "node:crypto";
|
|
5
|
+
|
|
6
|
+
import { createMcpHandler } from "../src/mcp/server.ts";
|
|
7
|
+
|
|
8
|
+
const MAX_BODY_BYTES = 1_048_576;
|
|
9
|
+
|
|
10
|
+
export type McpHttpOptions = {
|
|
11
|
+
sessionID: string;
|
|
12
|
+
center: string;
|
|
13
|
+
token?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function json(body: unknown, status = 200, headers: Record<string, string> = {}): Response {
|
|
17
|
+
return new Response(JSON.stringify(body), {
|
|
18
|
+
status,
|
|
19
|
+
headers: { "content-type": "application/json", ...headers },
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function sameSecret(given: string, secret: string): boolean {
|
|
24
|
+
const a = Buffer.from(given);
|
|
25
|
+
const b = Buffer.from(secret);
|
|
26
|
+
return a.length === b.length && timingSafeEqual(a, b);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function bearer(req: Request, token: string): boolean {
|
|
30
|
+
const header = req.headers.get("authorization") ?? "";
|
|
31
|
+
return header.startsWith("Bearer ") && sameSecret(header.slice("Bearer ".length), token);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function allowed(req: Request, url: URL, token: string | undefined): boolean {
|
|
35
|
+
if (url.pathname === "/mcp") return !token || bearer(req, token);
|
|
36
|
+
// A secret path lets clients that only offer "no authentication" connect.
|
|
37
|
+
const secret = url.pathname.slice("/mcp/".length);
|
|
38
|
+
return Boolean(token) && !secret.includes("/") && sameSecret(secret, token!);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function notify(): Response {
|
|
42
|
+
return new Response(null, { status: 202 });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function mcpHttpRoutes(
|
|
46
|
+
req: Request,
|
|
47
|
+
url: URL,
|
|
48
|
+
options: McpHttpOptions,
|
|
49
|
+
): Promise<Response | undefined> {
|
|
50
|
+
if (url.pathname !== "/mcp" && !url.pathname.startsWith("/mcp/")) return undefined;
|
|
51
|
+
if (!allowed(req, url, options.token)) return json({ error: "unauthorized" }, 401);
|
|
52
|
+
if (req.method === "GET") {
|
|
53
|
+
return new Response("SSE stream not supported; use POST", { status: 405, headers: { allow: "POST, DELETE" } });
|
|
54
|
+
}
|
|
55
|
+
if (req.method === "DELETE") return new Response(null, { status: 204 });
|
|
56
|
+
if (req.method !== "POST") {
|
|
57
|
+
return new Response(null, { status: 405, headers: { allow: "POST, DELETE" } });
|
|
58
|
+
}
|
|
59
|
+
if (!req.headers.get("content-type")?.includes("application/json")) {
|
|
60
|
+
return json({ error: "content-type must be application/json" }, 415);
|
|
61
|
+
}
|
|
62
|
+
const body = await req.text();
|
|
63
|
+
if (Buffer.byteLength(body) > MAX_BODY_BYTES) return json({ error: "request body too large" }, 413);
|
|
64
|
+
let message: unknown;
|
|
65
|
+
try {
|
|
66
|
+
message = JSON.parse(body);
|
|
67
|
+
} catch {
|
|
68
|
+
return json({ jsonrpc: "2.0", id: null, error: { code: -32700, message: "parse error" } }, 400);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const handler = createMcpHandler(options.center, options.sessionID, options.token);
|
|
72
|
+
const initialize = !Array.isArray(message) && Boolean(message) && typeof message === "object" &&
|
|
73
|
+
(message as { method?: unknown }).method === "initialize";
|
|
74
|
+
const headers: Record<string, string> = initialize ? { "mcp-session-id": randomUUID() } : {};
|
|
75
|
+
|
|
76
|
+
if (Array.isArray(message)) {
|
|
77
|
+
if (!message.length) return notify();
|
|
78
|
+
const responses: unknown[] = [];
|
|
79
|
+
for (const item of message) {
|
|
80
|
+
const response = await handler(item);
|
|
81
|
+
if (response) responses.push(response);
|
|
82
|
+
}
|
|
83
|
+
return responses.length ? json(responses, 200, headers) : notify();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const response = await handler(message);
|
|
87
|
+
return response ? json(response, 200, headers) : notify();
|
|
88
|
+
}
|