@alexsun-top/opencode-chat-room 0.8.1 → 0.8.2
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 -0
- package/README.md +10 -10
- package/README.zh-CN.md +10 -10
- package/dist/cli.js +544 -88
- package/package.json +4 -4
- package/packages/chat-room-channeld/README.md +17 -12
- package/packages/chat-room-channeld/src/adapter.ts +145 -7
- package/packages/chat-room-channeld/src/host.ts +24 -9
- package/packages/chat-room-channeld/src/inbound.ts +13 -4
- package/packages/chat-room-channeld/src/protocol.ts +52 -1
- package/packages/chat-room-channeld/src/rules.ts +7 -2
- package/plugin.ts +1 -1
- package/server/assets/base.css +8 -2
- package/server/assets/chat/admin.js +0 -2
- package/server/assets/chat/announcements.js +2 -4
- package/server/assets/chat/chat-background.js +177 -0
- package/server/assets/chat/confirm-dialog.js +0 -1
- package/server/assets/chat/create-room-dialog.js +0 -1
- package/server/assets/chat/diagram-viewer.js +7 -1
- package/server/assets/chat/doc-preview.js +71 -15
- package/server/assets/chat/events.js +13 -5
- package/server/assets/chat/files.js +10 -6
- package/server/assets/chat/image-zoom.js +8 -1
- package/server/assets/chat/index.js +4 -2
- package/server/assets/chat/integration-account-schema.js +99 -0
- package/server/assets/chat/integration-editor.js +1 -1
- package/server/assets/chat/integrations.js +207 -57
- package/server/assets/chat/locales/de.js +1 -1
- package/server/assets/chat/locales/es.js +1 -1
- package/server/assets/chat/locales/fr.js +1 -1
- package/server/assets/chat/locales/it.js +1 -1
- package/server/assets/chat/locales/ja.js +1 -1
- package/server/assets/chat/locales/ko.js +1 -1
- package/server/assets/chat/markdown-footnotes.js +1 -1
- package/server/assets/chat/markdown.js +23 -0
- package/server/assets/chat/messages.js +1 -0
- package/server/assets/chat/palette.js +6 -1
- package/server/assets/chat/panels.js +23 -3
- package/server/assets/chat/receipts.js +2 -3
- package/server/assets/chat/reminders.js +2 -4
- package/server/assets/chat/replies.js +0 -6
- package/server/assets/chat/rooms.js +1 -6
- package/server/assets/chat/settings.js +69 -3
- package/server/assets/chat/shortcuts.js +0 -3
- package/server/assets/chat/side-pane.js +33 -8
- package/server/assets/chat/state.js +48 -18
- package/server/assets/chat/system-events.js +29 -3
- package/server/assets/chat/system-messages.js +9 -0
- package/server/assets/chat/tasks.js +2 -8
- package/server/assets/chat/window-controls.js +37 -0
- package/server/assets/code-highlight.css +22 -6
- package/server/assets/conversation.css +55 -12
- package/server/assets/doc-preview.css +6 -1
- package/server/assets/files.css +3 -0
- package/server/assets/monaco/integration-rules.css +1 -1
- package/server/assets/monaco/integration-rules.js +841 -533
- package/server/assets/responsive.css +32 -2
- package/server/assets/settings.css +117 -13
- package/server/assets/window-controls.css +36 -0
- package/server/channel-attachments.ts +133 -0
- package/server/channel-integration.ts +79 -26
- package/server/channels.ts +15 -5
- package/server/chat.html +71 -37
- package/server/manifest.webmanifest +1 -0
- package/server/sw.js +1 -0
- package/src/center/center-client.ts +1 -1
- package/src/state/pg-database.ts +5 -5
- package/src/state/pg-migrate.ts +7 -7
- package/src/state/pg-worker.mjs +2 -17
- package/src/state/sqlite-database.ts +14 -5
- package/src/state/sqlite-rooms.ts +130 -23
- package/src/state/sqlite-state-store.ts +6 -5
- package/src/state/sqlite.ts +3 -3
- package/src/web/integration-rules-editor.ts +139 -5
- package/src/web/integration-rules.ts +6 -2
- package/src/web/integration-schema.ts +7 -6
- package/packages/chat-room-channeld/dist/feishu-adapter.js +0 -1262
- package/packages/chat-room-channeld/src/feishu-adapter.ts +0 -303
- package/packages/chat-room-channeld/src/feishu-card.ts +0 -27
- package/packages/chat-room-channeld/src/feishu-inbound.ts +0 -158
- package/packages/chat-room-channeld/src/feishu-live.ts +0 -355
- package/packages/chat-room-channeld/src/feishu-send.ts +0 -342
- package/packages/chat-room-channeld/src/feishu-ws-frames.ts +0 -173
- package/server/assets/chat/forward.js +0 -69
package/server/channels.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Channel D integration: opt-in forwarding from a room message to an external
|
|
2
2
|
// IM endpoint through the channeld relay host. The host keeps its own SQLite
|
|
3
3
|
// file, so disabling the feature (or deleting channeld.sqlite) is a full rollback.
|
|
4
|
-
import { mkdirSync, readFileSync } from "node:fs";
|
|
5
4
|
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { mkdirSync, readFileSync } from "node:fs";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { parse as parseYaml } from "yaml";
|
|
8
8
|
import type { ServerSettings } from "../src/config/file-config.ts";
|
|
@@ -26,6 +26,7 @@ import { validateTargets } from "../packages/chat-room-channeld/src/host-helpers
|
|
|
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
28
|
import { inboundRoomText, matchInboundRoutes } from "../packages/chat-room-channeld/src/inbound.ts";
|
|
29
|
+
import { forwardAttachments, inboundAttachments, prepareSendPayload } from "./channel-attachments.ts";
|
|
29
30
|
import {
|
|
30
31
|
isTerminalDeliveryState,
|
|
31
32
|
readChannelStats,
|
|
@@ -64,7 +65,7 @@ export type DeliveryResultCallback = (
|
|
|
64
65
|
receipt: ReceiptRow | undefined,
|
|
65
66
|
) => void;
|
|
66
67
|
|
|
67
|
-
const json = (body: unknown, status = 200) => Response.json(body, { status });
|
|
68
|
+
const json = (body: unknown, status = 200) => Response.json(body, { status, headers: { "Cache-Control": "no-store" } });
|
|
68
69
|
const IDENTIFIER = /^[A-Za-z0-9._-]{1,128}$/;
|
|
69
70
|
const MAX_SESSION = 128;
|
|
70
71
|
const MAX_REQUEST_ID = 200;
|
|
@@ -150,7 +151,12 @@ export function createInboundRelay(config: ChannelConfig): {
|
|
|
150
151
|
onIngestCommitted: async (event) => {
|
|
151
152
|
for (const route of matchInboundRoutes(config, event)) {
|
|
152
153
|
const text = inboundRoomText(event, route);
|
|
153
|
-
if (!text) continue;
|
|
154
|
+
if (!text && !event.content?.attachments?.length) continue;
|
|
155
|
+
// Resource uploads are idempotent per event, room, and index, so a
|
|
156
|
+
// retried event reuses the same rows instead of duplicating files.
|
|
157
|
+
const markers = await inboundAttachments(event, route.to.room);
|
|
158
|
+
const body = [text, ...markers].filter(Boolean).join("\n");
|
|
159
|
+
if (!body) continue;
|
|
154
160
|
await writeSqliteStateWithDatabase(databasePath(), (svc, _registry, db) => {
|
|
155
161
|
db.exec(
|
|
156
162
|
`CREATE TABLE IF NOT EXISTS channel_inbound_relays (
|
|
@@ -164,7 +170,7 @@ export function createInboundRelay(config: ChannelConfig): {
|
|
|
164
170
|
"INSERT OR IGNORE INTO channel_inbound_relays (event_id, room_id, relayed_at) VALUES (?, ?, ?)",
|
|
165
171
|
).run(event.eventId, route.to.room, Date.now());
|
|
166
172
|
if (Number(inserted.changes) === 0) return;
|
|
167
|
-
svc.addEvent(route.to.room,
|
|
173
|
+
svc.addEvent(route.to.room, body);
|
|
168
174
|
});
|
|
169
175
|
}
|
|
170
176
|
},
|
|
@@ -196,6 +202,7 @@ async function activateRuntime(
|
|
|
196
202
|
spawnAdapter: deps.spawnAdapter,
|
|
197
203
|
deliveryIntervalMs: deps.deliveryIntervalMs,
|
|
198
204
|
onDeliveryResult: createDeliveryResultHandler(),
|
|
205
|
+
prepareSendPayload,
|
|
199
206
|
...inbound,
|
|
200
207
|
});
|
|
201
208
|
try {
|
|
@@ -327,6 +334,7 @@ export function createChannelController(
|
|
|
327
334
|
|| url.pathname === "/channeld/enable"
|
|
328
335
|
|| url.pathname === "/channeld/disable";
|
|
329
336
|
const integrationPath = url.pathname === "/channeld/plugins"
|
|
337
|
+
|| url.pathname.startsWith("/channeld/plugins/")
|
|
330
338
|
|| url.pathname === "/channeld/integration";
|
|
331
339
|
if (!adminPath && !integrationPath) return channelRoutes(req, url, runtime);
|
|
332
340
|
if (env.CHATROOM_ALLOW_ADMIN !== "true") return undefined;
|
|
@@ -518,6 +526,8 @@ export async function channelRoutes(
|
|
|
518
526
|
return json({ error: "forward target is unavailable" }, 409);
|
|
519
527
|
}
|
|
520
528
|
|
|
529
|
+
const attachments = await forwardAttachments(roomId, message.text);
|
|
530
|
+
|
|
521
531
|
const source: Endpoint = { platform: "chatroom", accountId: "center", roomId };
|
|
522
532
|
const requestedTarget: Endpoint = { platform: target.platform, accountId: target.account, roomId: target.room };
|
|
523
533
|
// A room reply quotes its parent only when that parent already went to the
|
|
@@ -539,7 +549,7 @@ export async function channelRoutes(
|
|
|
539
549
|
...(parent ? { parent } : {}),
|
|
540
550
|
occurredAt: new Date(message.createdAt).toISOString(),
|
|
541
551
|
receivedAt: new Date().toISOString(),
|
|
542
|
-
content: { text: message.text },
|
|
552
|
+
content: { text: message.text, ...(attachments.length ? { attachments } : {}) },
|
|
543
553
|
};
|
|
544
554
|
const result = await runtime.host.ingest(event);
|
|
545
555
|
return json({ eventId: result.eventId ?? event.eventId }, 202);
|
package/server/chat.html
CHANGED
|
@@ -13,8 +13,20 @@
|
|
|
13
13
|
// Resolve the saved theme and outer window frame before the first paint.
|
|
14
14
|
try {
|
|
15
15
|
var savedTheme = localStorage.getItem("chat.theme");
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
var savedCustom = localStorage.getItem("chat.customTheme");
|
|
17
|
+
var customColor = /^#[0-9a-f]{6}$/i.test(savedCustom) ? savedCustom : "#22695c";
|
|
18
|
+
var customChannels = customColor.slice(1).match(/../g).map(function (part) {
|
|
19
|
+
var value = parseInt(part, 16) / 255;
|
|
20
|
+
return value <= 0.03928 ? value / 12.92 : Math.pow((value + 0.055) / 1.055, 2.4);
|
|
21
|
+
});
|
|
22
|
+
document.documentElement.style.setProperty("--custom-bg", customColor);
|
|
23
|
+
document.documentElement.dataset.customDark = (0.2126 * customChannels[0] + 0.7152 * customChannels[1] + 0.0722 * customChannels[2]) < 0.4 ? "true" : "false";
|
|
24
|
+
document.documentElement.dataset.theme = ["light", "dark", "forest", "sand", "custom"].includes(savedTheme) ? savedTheme : "system";
|
|
25
|
+
} catch {
|
|
26
|
+
document.documentElement.dataset.theme = "system";
|
|
27
|
+
document.documentElement.style.setProperty("--custom-bg", "#22695c");
|
|
28
|
+
document.documentElement.dataset.customDark = "true";
|
|
29
|
+
}
|
|
18
30
|
document.documentElement.dataset.windowFrame = "framed";
|
|
19
31
|
try {
|
|
20
32
|
if (localStorage.getItem("chat.windowFrame") === "borderless") document.documentElement.dataset.windowFrame = "borderless";
|
|
@@ -30,6 +42,7 @@
|
|
|
30
42
|
<link rel="stylesheet" href="/assets/recall.css?v={{version}}">
|
|
31
43
|
<link rel="stylesheet" href="/assets/attachments.css?v={{version}}">
|
|
32
44
|
<link rel="stylesheet" href="/assets/responsive.css?v={{version}}">
|
|
45
|
+
<link rel="stylesheet" href="/assets/window-controls.css?v={{version}}">
|
|
33
46
|
<link rel="stylesheet" href="/assets/code-highlight.css?v={{version}}">
|
|
34
47
|
<link rel="stylesheet" href="/assets/room-create.css?v={{version}}">
|
|
35
48
|
<link rel="stylesheet" href="/assets/edit-room.css?v={{version}}">
|
|
@@ -161,7 +174,7 @@
|
|
|
161
174
|
<span data-i18n="settingsIntegrations">Integrations</span>
|
|
162
175
|
</button>
|
|
163
176
|
<button id="settingsTabConnection" class="settings-tab" type="button" role="tab" aria-selected="false" aria-controls="settingsPanelConnection" tabindex="-1" data-settings-tab="connection">
|
|
164
|
-
<svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-
|
|
177
|
+
<svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-shield_checkmark-24"></use></svg>
|
|
165
178
|
<span data-i18n="settingsConnection">Connection</span>
|
|
166
179
|
</button>
|
|
167
180
|
</nav>
|
|
@@ -231,16 +244,46 @@
|
|
|
231
244
|
<span class="theme-preview" aria-hidden="true"></span>
|
|
232
245
|
<span class="theme-name" data-i18n="themeSand">Sand</span>
|
|
233
246
|
</label>
|
|
247
|
+
<label class="theme-option" data-theme-choice="custom">
|
|
248
|
+
<input type="radio" name="theme" value="custom">
|
|
249
|
+
<span class="theme-preview" aria-hidden="true"></span>
|
|
250
|
+
<span class="theme-name" data-i18n="themeCustom">Custom</span>
|
|
251
|
+
<input id="inCustomThemeColor" class="input theme-color-input" type="color" aria-label="Custom theme color" data-i18n-aria-label="themeCustomColor">
|
|
252
|
+
</label>
|
|
253
|
+
</div>
|
|
254
|
+
</fieldset>
|
|
255
|
+
<fieldset class="settings-block chat-background-block">
|
|
256
|
+
<legend class="settings-label"><svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-image-24"></use></svg><span data-i18n="chatBackgroundLabel">Chat background</span></legend>
|
|
257
|
+
<p class="settings-hint" data-i18n="chatBackgroundHint">Fills the browser window behind the app in this browser only. A lower opacity keeps text readable.</p>
|
|
258
|
+
<div class="chat-background-controls">
|
|
259
|
+
<label class="chat-background-field">
|
|
260
|
+
<span class="field-label" data-i18n="chatBackgroundMode">Mode</span>
|
|
261
|
+
<select id="inChatBackgroundMode" class="input settings-select">
|
|
262
|
+
<option value="default" data-i18n="chatBackgroundDefault">Default</option>
|
|
263
|
+
<option value="image" data-i18n="chatBackgroundImage">Image</option>
|
|
264
|
+
</select>
|
|
265
|
+
</label>
|
|
266
|
+
<label id="chatBackgroundOpacityField" class="chat-background-field" hidden>
|
|
267
|
+
<span class="field-label" data-i18n="chatBackgroundOpacity">Opacity</span>
|
|
268
|
+
<span class="settings-range chat-background-opacity"><input id="inChatBackgroundOpacity" type="range" min="0" max="100" step="5" value="35" aria-describedby="chatBackgroundHint"><output id="chatBackgroundOpacityValue" class="settings-range-value" for="inChatBackgroundOpacity">35%</output></span>
|
|
269
|
+
</label>
|
|
270
|
+
<label id="chatBackgroundImageField" class="chat-background-field chat-background-image-field" hidden>
|
|
271
|
+
<span class="field-label" data-i18n="chatBackgroundImage">Image</span>
|
|
272
|
+
<input id="inChatBackgroundImage" class="input" type="file" accept="image/*">
|
|
273
|
+
<img id="chatBackgroundPreview" class="chat-background-preview" alt="" hidden>
|
|
274
|
+
<span id="chatBackgroundFileName" class="chat-background-file-name" hidden></span>
|
|
275
|
+
</label>
|
|
234
276
|
</div>
|
|
277
|
+
<p id="chatBackgroundStatus" class="settings-hint chat-background-status" role="status" aria-live="polite" hidden></p>
|
|
235
278
|
</fieldset>
|
|
236
279
|
<div class="settings-row">
|
|
237
280
|
<div class="settings-copy">
|
|
238
|
-
<label class="settings-label" for="inWindowFrame"><svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-options-24"></use></svg><span data-i18n="windowFrameLabel">
|
|
239
|
-
<p id="windowFrameHint" class="settings-hint" data-i18n="windowFrameHint">
|
|
281
|
+
<label class="settings-label" for="inWindowFrame"><svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-options-24"></use></svg><span data-i18n="windowFrameLabel">Display mode</span></label>
|
|
282
|
+
<p id="windowFrameHint" class="settings-hint" data-i18n="windowFrameHint">Fill window uses the entire window; Window mode keeps the inset card border.</p>
|
|
240
283
|
</div>
|
|
241
284
|
<select id="inWindowFrame" class="input settings-select" aria-describedby="windowFrameHint">
|
|
242
|
-
<option value="framed" data-i18n="windowFrameFramed" selected>
|
|
243
|
-
<option value="borderless" data-i18n="windowFrameBorderless">
|
|
285
|
+
<option value="framed" data-i18n="windowFrameFramed" selected>Window mode</option>
|
|
286
|
+
<option value="borderless" data-i18n="windowFrameBorderless">Fill window</option>
|
|
244
287
|
</select>
|
|
245
288
|
</div>
|
|
246
289
|
<fieldset class="settings-block panel-mode-block">
|
|
@@ -265,10 +308,12 @@
|
|
|
265
308
|
<div class="settings-row integration-enable-row">
|
|
266
309
|
<div class="settings-copy">
|
|
267
310
|
<label class="settings-label" for="inIntegrationsEnabled"><svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-plug_connected-24"></use></svg><span data-i18n="integrationsEnable">Enable integrations</span></label>
|
|
268
|
-
<p class="settings-hint" data-i18n="integrationsEnableHint">
|
|
311
|
+
<p class="settings-hint" data-i18n="integrationsEnableHint">Changes apply when you save.</p>
|
|
269
312
|
</div>
|
|
270
313
|
<input id="inIntegrationsEnabled" class="settings-switch" type="checkbox" role="switch">
|
|
271
314
|
</div>
|
|
315
|
+
<p id="integrationDisabledHint" class="settings-hint" data-i18n="integrationsDisabledHint" hidden>Enable integrations and save to edit accounts, plugins, and rules.</p>
|
|
316
|
+
<div id="integrationBody" class="integration-body" hidden>
|
|
272
317
|
<section class="integration-section" aria-labelledby="integrationAccountsHeading">
|
|
273
318
|
<header class="integration-section-head">
|
|
274
319
|
<h3 id="integrationAccountsHeading" data-i18n="integrationsAccounts">Accounts</h3>
|
|
@@ -289,8 +334,8 @@
|
|
|
289
334
|
<header class="integration-section-head">
|
|
290
335
|
<h3 id="integrationRulesHeading" data-i18n="integrationsRules">Outbound rules</h3>
|
|
291
336
|
<div id="integrationRulesFormat" class="integration-format-toggle" role="group" aria-label="Rules format" data-i18n-aria-label="integrationsRulesFormat" hidden>
|
|
292
|
-
<button id="
|
|
293
|
-
<button id="
|
|
337
|
+
<button id="integrationRulesFormatYaml" class="integration-format-btn" type="button" data-format="yaml" aria-pressed="true">YAML</button>
|
|
338
|
+
<button id="integrationRulesFormatJson" class="integration-format-btn" type="button" data-format="json" aria-pressed="false">JSON</button>
|
|
294
339
|
</div>
|
|
295
340
|
</header>
|
|
296
341
|
<p class="settings-hint" data-i18n="integrationsRulesHint">Outbound rules forward room events to connected accounts. Use JSON or YAML; each target must use an existing account.</p>
|
|
@@ -304,8 +349,8 @@
|
|
|
304
349
|
<header class="integration-section-head">
|
|
305
350
|
<h3 id="integrationInboundHeading" data-i18n="integrationsInboundRules">Inbound routes</h3>
|
|
306
351
|
<div id="integrationInboundFormat" class="integration-format-toggle" role="group" aria-label="Rules format" data-i18n-aria-label="integrationsRulesFormat" hidden>
|
|
307
|
-
<button id="
|
|
308
|
-
<button id="
|
|
352
|
+
<button id="integrationInboundFormatYaml" class="integration-format-btn" type="button" data-format="yaml" aria-pressed="true">YAML</button>
|
|
353
|
+
<button id="integrationInboundFormatJson" class="integration-format-btn" type="button" data-format="json" aria-pressed="false">JSON</button>
|
|
309
354
|
</div>
|
|
310
355
|
</header>
|
|
311
356
|
<p class="settings-hint" data-i18n="integrationsInboundHint">Inbound routes bring external messages into a room. Each route needs a configured account and a room.</p>
|
|
@@ -315,6 +360,7 @@
|
|
|
315
360
|
<p id="integrationInboundError" class="hint integration-field-error" role="alert" hidden></p>
|
|
316
361
|
<ul id="integrationInboundErrorList" class="integration-rule-errors" aria-label="Inbound route errors" hidden></ul>
|
|
317
362
|
</section>
|
|
363
|
+
</div>
|
|
318
364
|
<div class="integration-actions">
|
|
319
365
|
<button id="btnSaveIntegrations" class="btn primary small" type="button" data-i18n="integrationsSave">Save integrations</button>
|
|
320
366
|
</div>
|
|
@@ -340,19 +386,22 @@
|
|
|
340
386
|
<header class="admin-dialog-head"><h2 id="integrationAccountHeading" data-i18n="integrationsAccountTitle">Integration account</h2><button id="btnCloseIntegrationAccount" class="reader-close" type="button" aria-label="Close" data-i18n-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></header>
|
|
341
387
|
<form id="integrationAccountForm" class="integration-form" novalidate>
|
|
342
388
|
<p id="integrationAccountError" class="alert integration-error" role="alert" hidden></p>
|
|
343
|
-
<label class="field"><span class="field-label" data-i18n="integrationsAccountId">Account ID</span><input id="integrationAccountId" class="input" maxlength="128" autocomplete="off"
|
|
389
|
+
<label class="field"><span class="field-label" data-i18n="integrationsAccountId">Account ID</span><input id="integrationAccountId" class="input" maxlength="128" autocomplete="off" placeholder="Leave blank to generate" data-i18n-placeholder="integrationsAccountIdHint"></label>
|
|
344
390
|
<label class="field"><span class="field-label" data-i18n="integrationsPlugin">Plugin</span><select id="integrationAccountPlugin" class="input" required></select></label>
|
|
345
|
-
<
|
|
346
|
-
|
|
347
|
-
<
|
|
391
|
+
<fieldset id="integrationAccountSchemaField" class="field integration-schema">
|
|
392
|
+
<legend class="field-label" data-i18n="integrationsAccountDetails">Account details</legend>
|
|
393
|
+
<div id="integrationAccountSchema"></div>
|
|
394
|
+
</fieldset>
|
|
395
|
+
<details id="integrationAccountAdvanced" class="field integration-advanced">
|
|
396
|
+
<summary class="field-label"><svg class="fluent-icon integration-advanced-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-chevron_down-24"></use></svg><span data-i18n="integrationsAdvanced">Advanced settings</span></summary>
|
|
348
397
|
<div id="integrationAccountEnv" class="integration-env-rows"></div>
|
|
349
398
|
<div class="integration-env-actions">
|
|
350
|
-
<button id="btnAddAccountEnv" class="btn ghost small" type="button" data-i18n="integrationsAddEnv"
|
|
399
|
+
<button id="btnAddAccountEnv" class="btn ghost small integration-env-add" type="button" aria-label="Add variable" data-i18n-aria-label="integrationsAddEnv"><svg class="fluent-icon" aria-hidden="true" viewBox="0 0 24 24"><use href="/assets/fluent-icons.svg#fluent-add-24"></use></svg></button>
|
|
351
400
|
<button id="btnClearAccountEnv" class="btn ghost small" type="button" data-i18n="integrationsClearEnv">Clear stored values</button>
|
|
352
401
|
</div>
|
|
353
402
|
<p id="integrationAccountEnvNote" class="hint integration-env-note" hidden></p>
|
|
354
403
|
<p class="hint" data-i18n="integrationsEnvHint">Leave all values blank to keep the stored set. Entering a value replaces it.</p>
|
|
355
|
-
</
|
|
404
|
+
</details>
|
|
356
405
|
<div class="announcement-actions">
|
|
357
406
|
<button id="btnSaveIntegrationAccount" class="btn primary small" type="submit" data-i18n="save">Save</button>
|
|
358
407
|
<button id="btnCancelIntegrationAccount" class="btn ghost small" type="button" data-i18n="cancel">Cancel</button>
|
|
@@ -363,15 +412,8 @@
|
|
|
363
412
|
<header class="admin-dialog-head"><h2 id="integrationPluginHeading" data-i18n="integrationsUploadPlugin">Upload plugin</h2><button id="btnCloseIntegrationPlugin" class="reader-close" type="button" aria-label="Close" data-i18n-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></header>
|
|
364
413
|
<form id="integrationPluginForm" class="integration-form" novalidate>
|
|
365
414
|
<p id="integrationPluginError" class="alert integration-error" role="alert" hidden></p>
|
|
366
|
-
<label class="field"><span class="field-label" data-i18n="integrationsPluginFile">Choose
|
|
367
|
-
<
|
|
368
|
-
<label class="field"><span class="field-label" data-i18n="integrationsPlatform">Platform</span><input id="integrationPluginPlatform" class="input" maxlength="128" autocomplete="off"></label>
|
|
369
|
-
<label class="field"><span class="field-label" data-i18n="integrationsPluginSource">JavaScript source</span><textarea id="integrationPluginSource" class="input integration-source" rows="8" spellcheck="false" placeholder="Paste plugin JavaScript (max 256 KiB)" data-i18n-placeholder="integrationsPluginPaste"></textarea></label>
|
|
370
|
-
<fieldset class="field integration-env-field">
|
|
371
|
-
<legend class="field-label" data-i18n="integrationsEnv">Environment values</legend>
|
|
372
|
-
<div id="integrationPluginEnv" class="integration-env-rows"></div>
|
|
373
|
-
<button id="btnAddPluginEnv" class="btn ghost small" type="button" data-i18n="integrationsAddEnv">Add variable</button>
|
|
374
|
-
</fieldset>
|
|
415
|
+
<label class="field"><span class="field-label" data-i18n="integrationsPluginFile">Choose an adapter file</span><input id="integrationPluginFile" class="input" type="file" accept=".js,.mjs,.cjs,.ts"></label>
|
|
416
|
+
<p class="hint" data-i18n="integrationsPluginHint">A valid adapter declares its platform and account fields from the initialize handshake. Upload does not start the account or require credentials.</p>
|
|
375
417
|
<div class="announcement-actions">
|
|
376
418
|
<button id="btnSaveIntegrationPlugin" class="btn primary small" type="submit" data-i18n="integrationsUpload">Upload plugin</button>
|
|
377
419
|
<button id="btnCancelIntegrationPlugin" class="btn ghost small" type="button" data-i18n="cancel">Cancel</button>
|
|
@@ -732,9 +774,9 @@
|
|
|
732
774
|
</button>
|
|
733
775
|
</div>
|
|
734
776
|
|
|
735
|
-
<aside id="readerPanel" class="reader-panel" role="dialog" aria-modal="false" aria-
|
|
777
|
+
<aside id="readerPanel" class="reader-panel" role="dialog" aria-modal="false" aria-label="Message readers" data-i18n-aria-label="readerPanelTitle" tabindex="-1" hidden>
|
|
736
778
|
<div class="reader-panel-head">
|
|
737
|
-
<
|
|
779
|
+
<p id="readerCount" class="hint"></p>
|
|
738
780
|
<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>
|
|
739
781
|
</div>
|
|
740
782
|
<ul id="readerList" class="receipt-reader-list" aria-label="Message readers" data-i18n-aria-label="readerPanelTitle"></ul>
|
|
@@ -838,14 +880,6 @@
|
|
|
838
880
|
</div>
|
|
839
881
|
</dialog>
|
|
840
882
|
|
|
841
|
-
<dialog id="forwardDialog" class="admin-dialog" aria-labelledby="forwardHeading">
|
|
842
|
-
<header class="admin-dialog-head"><h2 id="forwardHeading" data-i18n="forwardTitle">Forward message</h2><div class="admin-dialog-actions"><button id="btnCloseForward" class="reader-close" type="button" aria-label="Close" data-i18n-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></div></header>
|
|
843
|
-
<p class="hint" data-i18n="forwardHint">Choose where to forward this message.</p>
|
|
844
|
-
<div id="forwardTargets" class="forward-targets"></div>
|
|
845
|
-
<p id="forwardStatus" class="hint" role="status" aria-live="polite"></p>
|
|
846
|
-
<div class="announcement-actions"><button id="btnCancelForward" class="btn ghost small" type="button" data-i18n="cancel">Cancel</button></div>
|
|
847
|
-
</dialog>
|
|
848
|
-
|
|
849
883
|
<!-- Alt+Space: message search and common commands in one keyboard-first surface. -->
|
|
850
884
|
<dialog id="paletteDialog" class="admin-dialog palette-dialog" aria-labelledby="paletteHeading" aria-describedby="paletteHint">
|
|
851
885
|
<header class="palette-head">
|
package/server/sw.js
CHANGED
|
@@ -422,7 +422,7 @@ export async function centerAction(
|
|
|
422
422
|
const sentID = [...parsed.messages].reverse()
|
|
423
423
|
.find((message) => message.senderSessionID === sessionID && message.text === args.text!.trim())?.id
|
|
424
424
|
?? parsed.messages.at(-1)?.id;
|
|
425
|
-
return `sent: ${args.text.trim()}\n${sentID ? `
|
|
425
|
+
return `sent: ${args.text.trim()}\n${sentID ? `message_id=${sentID} room_id=${parsed.id}\n` : ""}${formatRoom(svcOf(room), parsed)}`;
|
|
426
426
|
}
|
|
427
427
|
case "recall": {
|
|
428
428
|
if (!args.roomId) return "error: roomId is required; use a room UUID from the room list, not the room name";
|
package/src/state/pg-database.ts
CHANGED
|
@@ -8,9 +8,9 @@ import type { QueryStatement, SQLQueryBindings, StateDatabase, Transaction } fro
|
|
|
8
8
|
// network I/O. The state layer is synchronous by design, so this preserves its
|
|
9
9
|
// transaction boundaries without turning 100+ call sites into async code.
|
|
10
10
|
//
|
|
11
|
-
// PostgreSQL support is experimental
|
|
12
|
-
//
|
|
13
|
-
//
|
|
11
|
+
// PostgreSQL support is experimental through the 0.8.2 multi-instance
|
|
12
|
+
// milestone. Writers serialize per transaction with an advisory xact lock;
|
|
13
|
+
// separate processes may share the database and apply disjoint diffs.
|
|
14
14
|
|
|
15
15
|
type Reply = {
|
|
16
16
|
id: number;
|
|
@@ -115,8 +115,8 @@ export class PgDatabase implements StateDatabase {
|
|
|
115
115
|
const signal = new SharedArrayBuffer(4);
|
|
116
116
|
try {
|
|
117
117
|
this.#port.postMessage({ type: "close", signal });
|
|
118
|
-
// Give client.end()
|
|
119
|
-
//
|
|
118
|
+
// Give client.end() time to flush before a caller opens the next
|
|
119
|
+
// connection (migration and restart tests rely on it).
|
|
120
120
|
Atomics.wait(new Int32Array(signal), 0, 0, 2_000);
|
|
121
121
|
} catch { /* worker already gone */ }
|
|
122
122
|
this.#port.close();
|
package/src/state/pg-migrate.ts
CHANGED
|
@@ -3,9 +3,9 @@ import { PgDatabase } from "./pg-database.ts";
|
|
|
3
3
|
import { Database, type SQLQueryBindings } from "./sqlite.ts";
|
|
4
4
|
import { closeStateDatabases, initializeAdminSchema, initializeReminderSchema, openStateDatabase } from "./sqlite-state.ts";
|
|
5
5
|
|
|
6
|
-
// One-shot SQLite -> PostgreSQL copy. PostgreSQL support is experimental
|
|
7
|
-
//
|
|
8
|
-
//
|
|
6
|
+
// One-shot SQLite -> PostgreSQL copy. PostgreSQL support is experimental through
|
|
7
|
+
// the 0.8.2 multi-instance milestone; nothing stops a running server from
|
|
8
|
+
// writing to the target, so the operator must stop it before migrating.
|
|
9
9
|
|
|
10
10
|
export type MigrationOptions = {
|
|
11
11
|
sourcePath: string;
|
|
@@ -20,9 +20,9 @@ const quote = (name: string) => `"${name.replace(/"/g, '""')}"`;
|
|
|
20
20
|
function backupGuidance(sourcePath: string): string[] {
|
|
21
21
|
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
22
22
|
return [
|
|
23
|
-
"PostgreSQL state is experimental
|
|
23
|
+
"PostgreSQL state is experimental (0.8.2 multi-instance milestone).",
|
|
24
24
|
"Stop the chat-room server before migrating; this command takes a SQLite write lock,",
|
|
25
|
-
"but
|
|
25
|
+
"but nothing blocks a running PostgreSQL writer. Only --yes confirms the server is stopped.",
|
|
26
26
|
"",
|
|
27
27
|
"Make a WAL-safe SQLite backup first (do not copy only chat-room.sqlite while WAL is active):",
|
|
28
28
|
` sqlite3 ${JSON.stringify(sourcePath)} ".backup '${sourcePath}.backup-${stamp}'"`,
|
|
@@ -102,8 +102,8 @@ export async function migrateToPostgres(options: MigrationOptions): Promise<Migr
|
|
|
102
102
|
probe.close();
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
//
|
|
106
|
-
//
|
|
105
|
+
// The target copy runs in one immediate transaction; a running server is
|
|
106
|
+
// not detected here, so operator confirmation is the only guard.
|
|
107
107
|
const target = await openStateDatabase(options.sourcePath);
|
|
108
108
|
await initializeAdminSchema(options.sourcePath);
|
|
109
109
|
await initializeReminderSchema(options.sourcePath);
|
package/src/state/pg-worker.mjs
CHANGED
|
@@ -2,19 +2,14 @@ import { parentPort } from "node:worker_threads";
|
|
|
2
2
|
import pg from "pg";
|
|
3
3
|
import { hasSql, translate } from "./pg-sql.mjs";
|
|
4
4
|
|
|
5
|
-
// One pg.Client per worker: transactions and
|
|
6
|
-
//
|
|
5
|
+
// One pg.Client per worker: transactions and their advisory locks belong to a
|
|
6
|
+
// single session, so a pool would be incorrect here.
|
|
7
7
|
//
|
|
8
8
|
// The worker deliberately starts with no workerData. Some Bun versions fail to
|
|
9
9
|
// load `pg` in a worker that received any workerData at startup. The main
|
|
10
10
|
// thread sends one init message over the default worker channel instead; that
|
|
11
11
|
// message also transfers the request MessagePort and the ready SharedArrayBuffer.
|
|
12
12
|
|
|
13
|
-
const SINGLE_INSTANCE_KEY = "opencode-chat-room:state-writer";
|
|
14
|
-
const SINGLE_INSTANCE_ERROR =
|
|
15
|
-
"PostgreSQL backend is experimental and single-instance: another chat-room process already holds the database writer lock. " +
|
|
16
|
-
"Multi-instance support is planned for 0.8.2. Stop the other process, or unset CHAT_ROOM_DATABASE_URL to return to SQLite.";
|
|
17
|
-
|
|
18
13
|
let client;
|
|
19
14
|
let port;
|
|
20
15
|
let readyFlag;
|
|
@@ -119,16 +114,6 @@ async function startup(connectionString, ready, timeout) {
|
|
|
119
114
|
statement_timeout: statementTimeout,
|
|
120
115
|
});
|
|
121
116
|
await client.connect();
|
|
122
|
-
const guard = await client.query(
|
|
123
|
-
"SELECT pg_try_advisory_lock(hashtext($1), 1) AS locked",
|
|
124
|
-
[SINGLE_INSTANCE_KEY],
|
|
125
|
-
);
|
|
126
|
-
if (!guard.rows[0]?.locked) {
|
|
127
|
-
port.postMessage({ type: "fatal", error: { code: "PG_SINGLE_INSTANCE", message: SINGLE_INSTANCE_ERROR } });
|
|
128
|
-
signalReady();
|
|
129
|
-
try { await client.end(); } catch { /* main will terminate this worker */ }
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
117
|
connected = true;
|
|
133
118
|
port.postMessage({ type: "ready" });
|
|
134
119
|
signalReady();
|
|
@@ -9,8 +9,8 @@ import { immediate, pause } from "./sqlite-transaction.ts";
|
|
|
9
9
|
const databases = new Map<string, Promise<StateDatabase>>();
|
|
10
10
|
|
|
11
11
|
// Set CHAT_ROOM_DATABASE_URL only on the server process. The PostgreSQL
|
|
12
|
-
// backend is experimental
|
|
13
|
-
//
|
|
12
|
+
// backend is experimental through the 0.8.2 multi-instance milestone; writers
|
|
13
|
+
// serialize per transaction with a transaction-scoped advisory lock.
|
|
14
14
|
function postgresURL(): string | undefined {
|
|
15
15
|
const value = process.env.CHAT_ROOM_DATABASE_URL?.trim();
|
|
16
16
|
return value || undefined;
|
|
@@ -27,8 +27,8 @@ export function openStateDatabase(file: string): Promise<StateDatabase> {
|
|
|
27
27
|
return pending;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
// Test and shutdown hook. PgDatabase.close() waits for client.end() so
|
|
31
|
-
//
|
|
30
|
+
// Test and shutdown hook. PgDatabase.close() waits for client.end() so a
|
|
31
|
+
// restart does not overlap the previous connection's shutdown.
|
|
32
32
|
export async function closeStateDatabases(): Promise<void> {
|
|
33
33
|
const pending = [...databases.values()];
|
|
34
34
|
databases.clear();
|
|
@@ -78,7 +78,16 @@ export async function initializeReminderSchema(file: string): Promise<void> {
|
|
|
78
78
|
async function initializePostgres(connectionString: string): Promise<StateDatabase> {
|
|
79
79
|
const db = new PgDatabase(connectionString);
|
|
80
80
|
try {
|
|
81
|
-
|
|
81
|
+
// Concurrent CREATE TABLE IF NOT EXISTS is not race-free in PostgreSQL:
|
|
82
|
+
// two instances can both try to create the same type and one gets a
|
|
83
|
+
// duplicate pg_type error. Serialize only the startup DDL with a
|
|
84
|
+
// session-scoped lock; the lock is released automatically if a process dies.
|
|
85
|
+
db.exec("SELECT pg_advisory_lock(hashtext('chat-room-schema'))");
|
|
86
|
+
try {
|
|
87
|
+
await initializeSchema(db);
|
|
88
|
+
} finally {
|
|
89
|
+
db.exec("SELECT pg_advisory_unlock(hashtext('chat-room-schema'))");
|
|
90
|
+
}
|
|
82
91
|
// Legacy rooms.json/registry.json migration is SQLite-only. The migrate
|
|
83
92
|
// command copies an existing SQLite state database into PostgreSQL.
|
|
84
93
|
return db;
|