@alexsun-top/opencode-chat-room 0.6.7 → 0.6.8
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 +15 -0
- package/README.md +6 -3
- package/README.zh-CN.md +7 -3
- package/docs/administrator-rooms.md +7 -2
- package/package.json +4 -1
- package/plugin.ts +38 -8
- package/server/assets/base.css +228 -28
- package/server/assets/chat/admin-badge.js +28 -6
- package/server/assets/chat/admin.js +7 -1
- package/server/assets/chat/attachment-store.js +106 -0
- package/server/assets/chat/attachments.js +201 -21
- package/server/assets/chat/events.js +28 -8
- package/server/assets/chat/image-zoom.js +86 -2
- package/server/assets/chat/index.js +8 -0
- package/server/assets/chat/install-prompt.js +82 -0
- package/server/assets/chat/join-requests.js +355 -0
- package/server/assets/chat/markdown.js +54 -6
- package/server/assets/chat/members.js +4 -2
- package/server/assets/chat/message-polling.js +24 -3
- package/server/assets/chat/messages.js +6 -4
- package/server/assets/chat/questions.js +10 -6
- package/server/assets/chat/recall.js +279 -0
- package/server/assets/chat/reminders.js +52 -8
- package/server/assets/chat/replies.js +1 -1
- package/server/assets/chat/room-list.js +14 -5
- package/server/assets/chat/room-watcher.js +5 -1
- package/server/assets/chat/rooms.js +16 -4
- package/server/assets/chat/shortcuts.js +254 -0
- package/server/assets/chat/state.js +73 -14
- package/server/assets/chat/system-messages.js +3 -0
- package/server/assets/conversation.css +2 -2
- package/server/assets/keyboard-hints.css +51 -0
- package/server/assets/recall.css +29 -0
- package/server/assets/responsive.css +38 -13
- package/server/chat-server.ts +55 -66
- package/server/chat.html +146 -16
- package/server/inbox.ts +1 -1
- package/server/join-requests.ts +106 -0
- package/server/message-recall-routes.ts +37 -0
- package/server/newrooms.ts +9 -0
- package/server/room-join.ts +59 -0
- package/server/room-owner.ts +3 -20
- package/server/room-payload.ts +2 -0
- package/server/sw.js +1 -0
- package/server/wake.ts +45 -16
- package/skills/chatroom/SKILL.md +32 -0
- package/src/README.md +5 -3
- package/src/agent/admin-client.ts +28 -4
- package/src/center/center-client.ts +81 -4
- package/src/center/center-inbox.ts +35 -10
- package/src/center/center-wake.ts +25 -12
- package/src/center/message-ids.ts +7 -0
- package/src/center/notification-budget.ts +16 -0
- package/src/center/queue.ts +14 -4
- package/src/rooms/room-service.ts +10 -1
- package/src/runtime/plugin-notifications.ts +37 -11
- package/src/runtime/v2-plugin.ts +1 -1
- package/src/state/roles.ts +34 -0
- package/src/state/sqlite-state.ts +196 -27
- package/src/state/store.ts +22 -3
- package/src/tests/announcement-board.ts +9 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/* Keyboard hints: a small badge over every visible control. */
|
|
2
|
+
.keys-overlay { position: fixed; inset: 0; z-index: 60; pointer-events: none; }
|
|
3
|
+
.keys-marks { position: absolute; inset: 0; }
|
|
4
|
+
.keys-badge {
|
|
5
|
+
position: absolute;
|
|
6
|
+
display: inline-flex;
|
|
7
|
+
align-items: center;
|
|
8
|
+
gap: 2px;
|
|
9
|
+
padding: 2px 4px;
|
|
10
|
+
border: 1px solid rgb(255 255 255 / .22);
|
|
11
|
+
border-radius: 6px;
|
|
12
|
+
color: #f6f8f4;
|
|
13
|
+
background: rgb(12 22 19 / .92);
|
|
14
|
+
box-shadow: 0 2px 8px rgb(0 0 0 / .28);
|
|
15
|
+
font: 600 9.5px/1 var(--font-mono);
|
|
16
|
+
white-space: nowrap;
|
|
17
|
+
}
|
|
18
|
+
.keys-badge.is-real { color: var(--accent-ink); background: var(--accent); border-color: color-mix(in srgb, var(--accent-ink) 35%, transparent); }
|
|
19
|
+
.keys-badge .keys-key { height: 15px; min-width: 15px; padding: 0 3px; border-width: 1px; border-bottom-width: 2px; border-radius: 4px; border-color: rgb(255 255 255 / .3); background: rgb(255 255 255 / .14); box-shadow: none; color: inherit; font-size: 9px; }
|
|
20
|
+
.keys-badge.is-real .keys-key { border-color: color-mix(in srgb, var(--accent-ink) 32%, transparent); background: color-mix(in srgb, var(--accent-ink) 14%, transparent); }
|
|
21
|
+
.keys-legend {
|
|
22
|
+
position: fixed;
|
|
23
|
+
left: 50%;
|
|
24
|
+
bottom: 18px;
|
|
25
|
+
transform: translateX(-50%);
|
|
26
|
+
display: flex;
|
|
27
|
+
flex-wrap: wrap;
|
|
28
|
+
align-items: center;
|
|
29
|
+
gap: 6px 14px;
|
|
30
|
+
width: min(460px, calc(100vw - 20px));
|
|
31
|
+
padding: 9px 10px 9px 14px;
|
|
32
|
+
border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line));
|
|
33
|
+
border-radius: 14px;
|
|
34
|
+
background: color-mix(in srgb, var(--surface) 94%, transparent);
|
|
35
|
+
box-shadow: var(--shadow);
|
|
36
|
+
backdrop-filter: blur(10px);
|
|
37
|
+
pointer-events: none;
|
|
38
|
+
}
|
|
39
|
+
.keys-legend-text { flex: 1 1 auto; min-width: 0; margin: 0; color: var(--ink-2); font-size: 12px; line-height: 1.45; }
|
|
40
|
+
.keys-legend-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }
|
|
41
|
+
.keys-legend-btn { min-height: 34px; padding: 6px 8px; border: 1px solid transparent; border-radius: 8px; color: var(--accent); background: transparent; font: inherit; font-size: 12px; font-weight: 650; cursor: pointer; }
|
|
42
|
+
.keys-legend-btn, .keys-legend-close { pointer-events: auto; }
|
|
43
|
+
.keys-legend-btn:hover { border-color: color-mix(in srgb, var(--accent) 30%, var(--line)); background: var(--accent-soft); }
|
|
44
|
+
.keys-legend-close { display: grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 1px solid transparent; border-radius: 9px; color: var(--ink-2); background: transparent; cursor: pointer; }
|
|
45
|
+
.keys-legend-close:hover { border-color: var(--line); color: var(--ink); background: var(--surface-2); }
|
|
46
|
+
.keys-legend-btn:focus-visible, .keys-legend-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
47
|
+
@media (max-width: 560px) {
|
|
48
|
+
.keys-legend { gap: 2px 8px; padding: 7px 8px 7px 11px; }
|
|
49
|
+
.keys-legend-text { font-size: 11px; }
|
|
50
|
+
}
|
|
51
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* Recall: the row-level action, the tombstone, and the reveal disclosure. */
|
|
2
|
+
.message-recall { display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 1px solid transparent; border-radius: 8px; color: var(--ink-3); background: transparent; cursor: pointer; }
|
|
3
|
+
.message-recall-icon { display: block; width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }
|
|
4
|
+
.message-recall:hover, .message-recall:focus-visible { border-color: color-mix(in srgb, var(--danger) 32%, var(--line)); color: var(--danger); background: var(--danger-soft); }
|
|
5
|
+
.message-recall:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
|
|
6
|
+
.msg-text.recalled { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; border-style: dashed; border-color: color-mix(in srgb, var(--ink) 18%, transparent); background: color-mix(in srgb, var(--surface-2) 62%, var(--surface)); box-shadow: none; color: var(--ink-2); font-size: 14.5px; }
|
|
7
|
+
.msg.own .msg-text.recalled { background: color-mix(in srgb, var(--surface-2) 78%, var(--surface)); border-color: color-mix(in srgb, var(--ink) 18%, transparent); }
|
|
8
|
+
.msg-text.recalled > :not(:first-child) { margin-top: 0; }
|
|
9
|
+
.recalled-note { display: flex; align-items: center; gap: 6px; margin: 0; color: var(--ink-2); font-weight: 550; }
|
|
10
|
+
.recalled-mark { display: inline-flex; color: var(--ink-3); }
|
|
11
|
+
.recalled-icon { display: block; width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }
|
|
12
|
+
.recalled-by { margin: 0; color: var(--ink-3); font-size: 12px; }
|
|
13
|
+
.recalled-reveal { min-height: 32px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink-2); background: var(--surface); font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; }
|
|
14
|
+
.recalled-reveal:hover, .recalled-reveal:focus-visible { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
|
|
15
|
+
.recalled-reveal:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
16
|
+
.recalled-reveal[disabled] { cursor: progress; opacity: .7; }
|
|
17
|
+
.recalled-body { width: 100%; padding-top: 7px; border-top: 1px solid var(--line); color: var(--ink); }
|
|
18
|
+
.recalled-body[hidden] { display: none; }
|
|
19
|
+
.msg.recalled-in .msg-text { animation: recall-in .18s ease both; }
|
|
20
|
+
@keyframes recall-in { from { opacity: .35; transform: translateY(-2px); } }
|
|
21
|
+
@media (prefers-reduced-motion: reduce) { .msg.recalled-in .msg-text { animation: none; } }
|
|
22
|
+
|
|
23
|
+
/* Room notices recall from the line itself. */
|
|
24
|
+
.sys.has-recall { padding-right: 36px; }
|
|
25
|
+
.sys .sys-recall { position: absolute; top: -6px; right: 4px; width: 32px; height: 32px; background: var(--surface); }
|
|
26
|
+
.sys-recalled { display: inline-flex; align-items: center; gap: 6px; }
|
|
27
|
+
.sys-recalled .recalled-icon { width: 14px; height: 14px; }
|
|
28
|
+
.sys .recalled-reveal { min-height: 30px; }
|
|
29
|
+
.sys .recalled-body { max-width: min(560px, 100%); padding-top: 0; border-top: 0; color: var(--ink-2); font-size: 12.5px; text-align: center; }
|
|
@@ -2,14 +2,23 @@
|
|
|
2
2
|
@media (max-width: 560px) {
|
|
3
3
|
#joinView { padding: 20px 14px; }
|
|
4
4
|
.entry-card { padding: 20px 18px 18px; }
|
|
5
|
+
.join-head { gap: 8px 16px; padding-bottom: 16px; }
|
|
5
6
|
.chat-head { padding: 12px 16px; }
|
|
6
7
|
.thread { padding: 16px 16px 4px; }
|
|
7
8
|
.jump { right: 12px; bottom: 10px; }
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
@media (max-width: 520px) {
|
|
11
|
+
.join-head { grid-template-columns: minmax(0, 1fr); }
|
|
12
|
+
.join-head .locale-control { grid-column: 1; grid-row: 2; justify-self: end; }
|
|
13
|
+
.join-head .tagline { grid-row: 3; }
|
|
14
|
+
}
|
|
15
|
+
/* The three setup cards stack below the masthead; rooms use two columns until phones. */
|
|
11
16
|
@media (max-width: 860px) {
|
|
12
|
-
.join-
|
|
17
|
+
.join-entries { grid-template-columns: minmax(0, 1fr); }
|
|
18
|
+
#roomList { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
19
|
+
}
|
|
20
|
+
@media (max-width: 560px) {
|
|
21
|
+
#roomList { grid-template-columns: minmax(0, 1fr); }
|
|
13
22
|
}
|
|
14
23
|
|
|
15
24
|
/* Room workspace */
|
|
@@ -58,8 +67,8 @@
|
|
|
58
67
|
.r-preview { overflow: hidden; color: var(--ink-3); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
|
|
59
68
|
.r-badge { position: absolute; top: 8px; right: 9px; 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; }
|
|
60
69
|
.r-badge-question { background: var(--warning); color: var(--warning-ink); font-size: 12px; }
|
|
61
|
-
/* The rail footer
|
|
62
|
-
|
|
70
|
+
/* The rail footer keeps the empty composer's height so the divider lines meet when
|
|
71
|
+
idle. Files or wrapped lines grow only the composer, never this footer. */
|
|
63
72
|
.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); }
|
|
64
73
|
.rail-foot .anchor { width: 100%; }
|
|
65
74
|
.user-menu-trigger { display: flex; align-items: center; gap: 10px; width: 100%; min-width: 0; padding: 7px; border: 1px solid transparent; border-radius: 12px; color: var(--ink); background: transparent; font: inherit; text-align: left; cursor: pointer; transition: border-color .16s, background .16s, box-shadow .16s; }
|
|
@@ -86,10 +95,14 @@
|
|
|
86
95
|
.admin-access summary { margin: 0 0 8px; font-size: 13px; font-weight: 600; cursor: pointer; }
|
|
87
96
|
.admin-badge, .admin-agent-badge { display: inline-flex; align-items: center; width: fit-content; border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line)); border-radius: 999px; color: var(--accent); background: var(--accent-soft); font-size: 10px; font-weight: 700; letter-spacing: .04em; line-height: 1.4; white-space: nowrap; }
|
|
88
97
|
.admin-badge { padding: 3px 8px; }
|
|
98
|
+
.admin-badge.owner-badge { border-color: color-mix(in srgb, var(--warning) 40%, var(--line)); color: var(--warning); background: color-mix(in srgb, var(--warning) 14%, var(--surface)); }
|
|
89
99
|
.admin-agent-badge { padding: 1px 6px; vertical-align: middle; }
|
|
90
100
|
.admin-scope-note { margin: 0 0 14px; padding: 10px 11px; border-left: 2px solid var(--accent); border-radius: 0 8px 8px 0; background: color-mix(in srgb, var(--accent-soft) 58%, transparent); line-height: 1.5; }
|
|
91
101
|
.admin-dialog { width: min(560px, calc(100vw - 32px)); max-width: none; max-height: 90dvh; overflow: auto; padding: 24px; color: var(--ink); background: linear-gradient(145deg, var(--surface), color-mix(in srgb, var(--accent-soft) 16%, var(--surface))); border: 1px solid color-mix(in srgb, var(--accent) 18%, var(--line)); border-radius: 20px; box-shadow: 0 24px 80px rgb(10 25 20 / .2); }
|
|
92
102
|
.admin-dialog::backdrop { background: rgb(9 22 18 / .52); backdrop-filter: blur(4px); }
|
|
103
|
+
/* Writing dialogs get desktop width; phones keep the same 16px gutter. */
|
|
104
|
+
#announcementDialog { width: min(880px, calc(100vw - 32px)); height: 88vh; height: min(88dvh, 780px); }
|
|
105
|
+
#reminderDialog { width: min(680px, calc(100vw - 32px)); }
|
|
93
106
|
.admin-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
|
|
94
107
|
.admin-dialog-actions { display: flex; align-items: center; gap: 10px; }
|
|
95
108
|
.admin-dialog-head h2 { min-width: 0; margin: 0; font-family: var(--font-display); font-size: 25px; font-weight: 600; letter-spacing: -.02em; overflow-wrap: anywhere; }
|
|
@@ -103,7 +116,7 @@
|
|
|
103
116
|
.admin-check span { min-width: 0; overflow-wrap: anywhere; }
|
|
104
117
|
.admin-check:hover { background: var(--surface-2); }
|
|
105
118
|
.admin-check input { flex: none; width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
|
|
106
|
-
.admin-dialog .admin-select { display: block; box-sizing: border-box; width: 100%; min-width: 0; min-height: 40px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: var(--surface); font: inherit; }
|
|
119
|
+
.admin-dialog .admin-select { display: block; box-sizing: border-box; width: 100%; min-width: 0; min-height: 40px; padding: 6px 32px 6px 10px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background-color: var(--surface); font: inherit; }
|
|
107
120
|
.admin-dialog .admin-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
108
121
|
.admin-enrollment { display: grid; gap: 8px; margin-top: 12px; padding: 12px; border-radius: 10px; background: var(--accent-soft); }
|
|
109
122
|
@media (max-width: 620px) { .admin-dialog { padding: 15px; } }
|
|
@@ -154,7 +167,11 @@
|
|
|
154
167
|
.room-rail { display: none; position: fixed; inset: 0 auto 0 0; z-index: 50; width: min(300px, 88vw); height: 100dvh; min-height: 0; padding: 20px 14px 0; background: var(--surface); border-right: 1px solid var(--line); box-shadow: var(--shadow); }
|
|
155
168
|
.room-rail.drawer-open { display: flex; }
|
|
156
169
|
.rail-brand { display: flex; margin-bottom: 22px; }
|
|
157
|
-
.rail-foot { display: flex; }
|
|
170
|
+
.rail-foot { display: flex; min-height: var(--composer-block, 93px); }
|
|
171
|
+
.rail-install { display: grid; gap: 6px; padding: 8px 4px 10px; border-top: 1px solid color-mix(in srgb, var(--line) 80%, transparent); }
|
|
172
|
+
.rail-install .rail-install-btn { width: 100%; min-height: 40px; }
|
|
173
|
+
.rail-install svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
|
|
174
|
+
.rail-install .hint { margin: 0; font-size: 11.5px; line-height: 1.45; }
|
|
158
175
|
.rail-label { margin: 0 8px 10px; font-size: 11px; }
|
|
159
176
|
.rail-composer { top: 32px; left: 12px; right: 12px; }
|
|
160
177
|
.rail-rooms { display: block; flex: 1; max-height: none; overflow: auto; }
|
|
@@ -162,14 +179,16 @@
|
|
|
162
179
|
#roomListChat .room-row { height: auto; padding: 10px 12px; }
|
|
163
180
|
#roomListChat .r-meta { font-size: 12px; }
|
|
164
181
|
#roomListChat .r-preview { display: block; }
|
|
165
|
-
#chatView > .chat-head { grid-column: 1; grid-row: 1; flex-wrap: wrap; align-items: center; padding:
|
|
182
|
+
#chatView > .chat-head { grid-column: 1; grid-row: 1; flex-wrap: wrap; align-items: center; padding: 6px 10px; gap: 4px 8px; }
|
|
166
183
|
#chatView > .conn-bar { grid-column: 1; grid-row: 2; }
|
|
167
184
|
#chatView > .msg-scroll { grid-column: 1; grid-row: 3; }
|
|
168
185
|
#chatView > .composer { grid-column: 1; grid-row: 4; }
|
|
169
|
-
.chat-head-actions { flex:
|
|
186
|
+
.chat-head-actions { flex: none; flex-wrap: nowrap; justify-content: flex-end; gap: 4px; margin-left: auto; }
|
|
170
187
|
.chat-head-actions > .locale-control { display: none; }
|
|
171
|
-
.chat-head-main { flex: 1 1
|
|
172
|
-
.room-title-row { gap: 6px; }
|
|
188
|
+
.chat-head-main { display: flex; flex: 1 1 200px; flex-wrap: wrap; align-items: center; gap: 2px 8px; min-width: 0; }
|
|
189
|
+
.room-title-row { flex: 1 1 0; gap: 6px; min-width: 0; }
|
|
190
|
+
.room-meta { flex: none; margin: 0; max-width: none; }
|
|
191
|
+
.room-description { flex: 1 1 100%; margin: 0; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
173
192
|
.chat-head-main h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 18px; }
|
|
174
193
|
.chat-head .chip { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; font-size: 0; }
|
|
175
194
|
#chatView > .chat-head .action-icon { display: block; }
|
|
@@ -184,13 +203,14 @@
|
|
|
184
203
|
#btnSend { padding: 12px 15px; }
|
|
185
204
|
}
|
|
186
205
|
@media (max-width: 480px) {
|
|
206
|
+
.chat-head-main { flex-basis: 100%; }
|
|
207
|
+
.chat-head-actions { flex-basis: 100%; margin-left: 0; }
|
|
187
208
|
#msgInput:placeholder-shown { min-height: calc(2.9em + 20px); }
|
|
188
209
|
}
|
|
189
210
|
@media (max-width: 420px) {
|
|
190
211
|
#chatView > .chat-head { align-items: center; }
|
|
191
|
-
.chat-head-actions { justify-content: flex-
|
|
212
|
+
.chat-head-actions { justify-content: flex-end; gap: 4px; }
|
|
192
213
|
.chat-head-actions .panel { max-height: min(70dvh, 520px); overflow: auto; }
|
|
193
|
-
.room-meta { max-width: 100px; overflow: hidden; }
|
|
194
214
|
}
|
|
195
215
|
@media (max-width: 300px) {
|
|
196
216
|
#chatView > .chat-head { padding: 8px; gap: 0; }
|
|
@@ -207,3 +227,8 @@
|
|
|
207
227
|
#btnRoomsDrawer { width: 28px; height: 28px; }
|
|
208
228
|
.room-title-row { gap: 3px; }
|
|
209
229
|
}
|
|
230
|
+
@media (max-width: 900px) {
|
|
231
|
+
#btnMembers { position: relative; }
|
|
232
|
+
#joinRequestBadge { position: absolute; top: -5px; right: -5px; margin: 0; font-size: 10px; }
|
|
233
|
+
.join-request-badge-word { display: none; }
|
|
234
|
+
}
|
package/server/chat-server.ts
CHANGED
|
@@ -9,7 +9,8 @@ import RoomService, {
|
|
|
9
9
|
type Message,
|
|
10
10
|
type Room,
|
|
11
11
|
} from "../src/rooms/room-service.ts";
|
|
12
|
-
import { acknowledgeQueued, answerQuestion, appendRoomMessage, sendReply, readQuestions, readState, writeState, type Registry, type RegistryEntry } from "../src/state/store.ts";
|
|
12
|
+
import { acknowledgeQueued, answerQuestion, appendRoomMessage, databasePath, sendReply, readQuestions, readState, writeState, type Registry, type RegistryEntry } from "../src/state/store.ts";
|
|
13
|
+
import { saveJoinRequest, writeSqliteStateWithDatabase } from "../src/state/sqlite-state.ts";
|
|
13
14
|
import {
|
|
14
15
|
admissionMatches,
|
|
15
16
|
clearPendingAdmission,
|
|
@@ -18,14 +19,17 @@ import { readInbox } from "./inbox";
|
|
|
18
19
|
import { isReceiverOwnerID } from "../src/state/receiver-owner.ts";
|
|
19
20
|
import { claimWake, touchActive, wakeMentionedSessions } from "./wake";
|
|
20
21
|
import { historyRoute } from "./history-route";
|
|
22
|
+
import { messageRecallRoutes } from "./message-recall-routes";
|
|
21
23
|
import { roomPayload } from "./room-payload";
|
|
22
|
-
import {
|
|
24
|
+
import { isUser, settleAdmins, settleOwner } from "./room-owner";
|
|
23
25
|
import { jsonObject } from "./json-body";
|
|
24
26
|
import { roomManagement } from "./newrooms";
|
|
25
27
|
import { memberRoutes } from "./member-routes";
|
|
26
28
|
import { resourceRoutes } from "./resource-routes";
|
|
27
29
|
import { maxResourceBytes } from "../src/rooms/resources.ts";
|
|
28
30
|
import { adminRoutes } from "./admin-routes";
|
|
31
|
+
import { joinRequestRoutes } from "./join-requests";
|
|
32
|
+
import { joinRoomMember } from "./room-join";
|
|
29
33
|
import { roomReminderRoutes, startRoomReminderScheduler } from "./room-reminders";
|
|
30
34
|
|
|
31
35
|
// The chat page shows this next to the app title; a missing package must not
|
|
@@ -148,6 +152,8 @@ async function handle(req: Request): Promise<Response> {
|
|
|
148
152
|
if (resource) return resource;
|
|
149
153
|
const history = await historyRoute(url);
|
|
150
154
|
if (history) return history;
|
|
155
|
+
const recall = await messageRecallRoutes(req, url);
|
|
156
|
+
if (recall) return recall;
|
|
151
157
|
if (req.method === "GET" && p === "/rooms/summary") {
|
|
152
158
|
// ponytail: 轻量房间摘要(不含消息)——wakeSessions 每 10s 用它计算
|
|
153
159
|
// latest,避免下载全部房间历史(orc-1 #5)
|
|
@@ -184,6 +190,8 @@ async function handle(req: Request): Promise<Response> {
|
|
|
184
190
|
}
|
|
185
191
|
const members = await memberRoutes(req, url);
|
|
186
192
|
if (members) return members;
|
|
193
|
+
const joinRequests = await joinRequestRoutes(req, url);
|
|
194
|
+
if (joinRequests) return joinRequests;
|
|
187
195
|
const management = await roomManagement(req, url);
|
|
188
196
|
if (management) return management;
|
|
189
197
|
if (req.method === "POST" && p === "/rooms") {
|
|
@@ -203,8 +211,12 @@ async function handle(req: Request): Promise<Response> {
|
|
|
203
211
|
if (owner.length > 64) {
|
|
204
212
|
return json({ error: "ownerId too long (max 64)" }, 400);
|
|
205
213
|
}
|
|
214
|
+
if (body.joinPolicy !== undefined && body.joinPolicy !== "open" && body.joinPolicy !== "approval") {
|
|
215
|
+
return json({ error: "joinPolicy must be open or approval" }, 400);
|
|
216
|
+
}
|
|
217
|
+
const joinPolicy = body.joinPolicy === "approval" ? "approval" : body.joinPolicy === "open" ? "open" : undefined;
|
|
206
218
|
const room = await mutate((svc, reg) => {
|
|
207
|
-
const created = svc.createRoom(name, owner);
|
|
219
|
+
const created = svc.createRoom(name, owner, joinPolicy);
|
|
208
220
|
if (body.sessionID) {
|
|
209
221
|
const regRoom = (reg[created.id] =
|
|
210
222
|
reg[created.id] ?? Object.create(null) as Record<string, RegistryEntry>);
|
|
@@ -236,6 +248,12 @@ async function handle(req: Request): Promise<Response> {
|
|
|
236
248
|
const roomFilter = url.searchParams.get("roomId");
|
|
237
249
|
const afterValue = url.searchParams.get("afterTs");
|
|
238
250
|
const afterTs = afterValue === null ? undefined : Number(afterValue);
|
|
251
|
+
const recallVersionValue = url.searchParams.get("recallVersion");
|
|
252
|
+
if (url.searchParams.has("recallVersion") && (recallVersionValue === "" || !/^\d+$/.test(recallVersionValue ?? "") ||
|
|
253
|
+
!Number.isSafeInteger(Number(recallVersionValue)))) {
|
|
254
|
+
return json({ error: "recallVersion must be a non-negative safe integer" }, 400);
|
|
255
|
+
}
|
|
256
|
+
const clientRecallVersion = recallVersionValue === null ? undefined : Number(recallVersionValue);
|
|
239
257
|
if (url.searchParams.has("afterTs") && (afterValue === "" || !/^\d+$/.test(afterValue ?? "") ||
|
|
240
258
|
!Number.isSafeInteger(afterTs) || afterTs! < 0 || !roomFilter || url.searchParams.get("excludeSelf") !== "0")) {
|
|
241
259
|
return json({ error: "afterTs requires a roomId and excludeSelf=0, with a non-negative safe integer value" }, 400);
|
|
@@ -252,7 +270,12 @@ async function handle(req: Request): Promise<Response> {
|
|
|
252
270
|
);
|
|
253
271
|
const deadline = Date.now() + timeout;
|
|
254
272
|
let result = await readInbox(sessionID, roomFilter, excludeSelf, afterTs);
|
|
255
|
-
|
|
273
|
+
// The client's rendered snapshot version is the baseline; using the first
|
|
274
|
+
// read instead would hide a recall that landed before this request started.
|
|
275
|
+
const initialRecallVersion = clientRecallVersion ?? result.recallVersion;
|
|
276
|
+
// A recall bumps the version without creating a message; wake the poll so
|
|
277
|
+
// the client can refetch the room snapshot (reliable version compare).
|
|
278
|
+
while (result.items.length === 0 && result.recallVersion === initialRecallVersion && Date.now() < deadline) {
|
|
256
279
|
// ponytail: 2s between disk scans (orc-1 #7) — 1s × 25 iterations
|
|
257
280
|
// doubles the file reads on shared-mount deployments
|
|
258
281
|
await sleep(Math.max(1, Math.min(2000, deadline - Date.now())));
|
|
@@ -324,71 +347,37 @@ async function handle(req: Request): Promise<Response> {
|
|
|
324
347
|
if (id.length > 64 || name.length > 64) {
|
|
325
348
|
return json({ error: "name too long (max 64)" }, 400);
|
|
326
349
|
}
|
|
327
|
-
const
|
|
350
|
+
const result = await writeSqliteStateWithDatabase(databasePath(), (svc, reg, db) => {
|
|
328
351
|
const currentRoom = svc.getRoom(roomId);
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
(
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
352
|
+
// A restricted room treats a new identity as a pending request; no
|
|
353
|
+
// participant or registry entry exists until a reviewer approves.
|
|
354
|
+
if (currentRoom.joinPolicy === "approval" && currentRoom.kind !== "direct" && !reg[roomId]?.[sessionID]) {
|
|
355
|
+
if (svc.containsParticipant(roomId, id)) return { status: 409 as const, error: "participant name is already in use in this room" };
|
|
356
|
+
const duplicate = db.query("SELECT 1 FROM room_join_requests WHERE room_id=? AND session_id<>? AND (participant_id=? OR name=?)").get(roomId, sessionID, id, name);
|
|
357
|
+
if (duplicate) return { status: 409 as const, error: "participant name is already in use in this room" };
|
|
358
|
+
saveJoinRequest(db, {
|
|
359
|
+
roomID: roomId, sessionID, participantId: id, name,
|
|
360
|
+
isAgent: Boolean(body.protocol || body.receiverOwnerID || body.host),
|
|
361
|
+
createdAt: Date.now(),
|
|
362
|
+
...(body.protocol === "v2" ? { protocol: "v2" as const } : {}),
|
|
363
|
+
...(body.protocol === "v2" && isReceiverOwnerID(body.receiverOwnerID) ? { receiverOwnerID: body.receiverOwnerID } : {}),
|
|
364
|
+
...(body.directory ? { directory: body.directory } : {}),
|
|
365
|
+
...(body.host ? { host: body.host } : {}),
|
|
366
|
+
});
|
|
367
|
+
return { pending: true as const };
|
|
342
368
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
// name from another session (closed tab / cleared localStorage) —
|
|
346
|
-
// but only when the identity is NOT already present, otherwise two
|
|
347
|
-
// live sessions sharing a nickname would evict each other forever
|
|
348
|
-
if (!already && currentRoom.kind !== "direct") {
|
|
349
|
-
for (const [sid, e] of Object.entries(regRoom)) {
|
|
350
|
-
if (sid !== sessionID && e.name === name) {
|
|
351
|
-
delete regRoom[sid];
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
svc.joinRoom(roomId, { id: participantId, name });
|
|
356
|
-
if (!already) {
|
|
357
|
-
svc.addEvent(roomId, `${name} joined the room`);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
const latestMessageTs =
|
|
361
|
-
svc.getMessages(roomId).at(-1)?.createdAt ?? 0;
|
|
362
|
-
regRoom[sessionID] = {
|
|
363
|
-
// ponytail: central mode self-pulls the inbox; no cross-host URL.
|
|
364
|
-
// Re-join must not rewind the read watermark (unread messages
|
|
365
|
-
// would be silently dropped); a first join starts at join time.
|
|
366
|
-
serverUrl: "",
|
|
367
|
-
apiPrefix: "/api",
|
|
369
|
+
return { room: joinRoomMember(svc, reg, roomId, {
|
|
370
|
+
sessionID, participantId: id, name,
|
|
368
371
|
...(body.protocol === "v2" ? { protocol: "v2" as const } : {}),
|
|
369
372
|
...(body.protocol === "v2" && isReceiverOwnerID(body.receiverOwnerID) ? { receiverOwnerID: body.receiverOwnerID } : {}),
|
|
370
|
-
|
|
371
|
-
membershipID: prevEntry?.membershipID ?? randomUUID(),
|
|
372
|
-
directory: body.directory || undefined,
|
|
373
|
-
// ora-1 #2: 归属主机——跨机 @-wake 只由所属机器执行
|
|
373
|
+
...(body.directory ? { directory: body.directory } : {}),
|
|
374
374
|
host: body.host ?? "",
|
|
375
|
-
|
|
376
|
-
lastReadTs:
|
|
377
|
-
regRoom[sessionID]?.lastReadTs ??
|
|
378
|
-
Math.max(Date.now(), latestMessageTs),
|
|
379
|
-
};
|
|
380
|
-
// An ownerless room is claimed by the first person who arrives; agents never are.
|
|
381
|
-
const joinedRoom = svc.getRoom(roomId);
|
|
382
|
-
if (!joinedRoom.ownerId && isUser(regRoom[sessionID])) {
|
|
383
|
-
joinedRoom.ownerId = name;
|
|
384
|
-
joinedRoom.ownerMembershipID = regRoom[sessionID]!.membershipID;
|
|
385
|
-
} else {
|
|
386
|
-
bindOwner(joinedRoom, regRoom);
|
|
387
|
-
}
|
|
388
|
-
return svc.getRoom(roomId);
|
|
375
|
+
}) };
|
|
389
376
|
});
|
|
377
|
+
if ("status" in result) return json({ error: result.error }, result.status);
|
|
378
|
+
if ("pending" in result) return json({ status: "pending" }, 202);
|
|
390
379
|
touchActive(sessionID); // join = active
|
|
391
|
-
return json(await roomPayload(room), 201);
|
|
380
|
+
return json(await roomPayload(result.room), 201);
|
|
392
381
|
}
|
|
393
382
|
if (req.method === "POST" && m[2] === "leave") {
|
|
394
383
|
await mutate((svc, reg) => {
|
|
@@ -437,8 +426,8 @@ async function handle(req: Request): Promise<Response> {
|
|
|
437
426
|
if (!text) {
|
|
438
427
|
return json({ error: "text is required" }, 400);
|
|
439
428
|
}
|
|
440
|
-
if (text.length >
|
|
441
|
-
return json({ error: "text too long (max
|
|
429
|
+
if (text.length > 5000) {
|
|
430
|
+
return json({ error: "text too long (max 5000)" }, 400);
|
|
442
431
|
}
|
|
443
432
|
const replyTo = (body as Record<string, unknown>).replyToMessageID;
|
|
444
433
|
if (replyTo !== undefined && (typeof replyTo !== "string" || !replyTo)) return json({ error: "replyToMessageID must be a non-empty message ID" }, 400);
|
|
@@ -479,9 +468,9 @@ async function handle(req: Request): Promise<Response> {
|
|
|
479
468
|
const roomId = decodeURIComponent(answer[1]!);
|
|
480
469
|
const questionID = decodeURIComponent(answer[2]!);
|
|
481
470
|
const body: unknown = await req.json();
|
|
482
|
-
if (!body || typeof body !== "object" || Array.isArray(body)) return json({ error: "sessionID and non-empty text (max
|
|
471
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) return json({ error: "sessionID and non-empty text (max 5000) are required" }, 400);
|
|
483
472
|
const input = body as Record<string, unknown>;
|
|
484
|
-
if (typeof input.sessionID !== "string" || !input.sessionID || typeof input.text !== "string" || !input.text.trim() || input.text.trim().length >
|
|
473
|
+
if (typeof input.sessionID !== "string" || !input.sessionID || typeof input.text !== "string" || !input.text.trim() || input.text.trim().length > 5000) return json({ error: "sessionID and non-empty text (max 5000) are required" }, 400);
|
|
485
474
|
const result = await answerQuestion(roomId, questionID, input.sessionID, input.text.trim());
|
|
486
475
|
if (result.status === "missing") return json({ error: "room not found" }, 404);
|
|
487
476
|
if (result.status === "question") return json({ error: "question not found" }, 404);
|