@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
|
@@ -1,51 +1,158 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import type { Message, Participant, Room } from "../rooms/room-service.ts";
|
|
3
3
|
import type { Registry, RegistryEntry } from "./store.ts";
|
|
4
|
-
import { type StateDatabase } from "./sqlite.ts";
|
|
4
|
+
import { type SQLQueryBindings, type StateDatabase } from "./sqlite.ts";
|
|
5
5
|
|
|
6
6
|
export type State = { rooms: Room[]; registry: Registry };
|
|
7
7
|
|
|
8
|
+
const ROOM_COLUMNS = "name,owner_id,created_at,kind,direct_sessions,direct_pair,description,admin_names,admin_membership_ids,owner_membership_id,successor_name,successor_membership_id,join_policy";
|
|
9
|
+
const ROOM_FIELDS = ROOM_COLUMNS.split(",");
|
|
10
|
+
const ROOM_INSERT = `INSERT INTO rooms(id,${ROOM_COLUMNS}) VALUES(?,${ROOM_FIELDS.map(() => "?").join(",")})`;
|
|
11
|
+
const MESSAGE_COLUMNS = "id,room_id,sender_id,sender_session_id,text,created_at,is_question,answer_to,answered_by,recalled_at,recalled_by";
|
|
12
|
+
const MESSAGE_FIELDS = MESSAGE_COLUMNS.split(",");
|
|
13
|
+
const MESSAGE_INSERT = `INSERT INTO messages(${MESSAGE_COLUMNS}) VALUES(${MESSAGE_FIELDS.map(() => "?").join(",")})`;
|
|
14
|
+
const MESSAGE_UPSERT = `${MESSAGE_INSERT} ON CONFLICT(id) DO UPDATE SET is_question=excluded.is_question,answer_to=excluded.answer_to,answered_by=excluded.answered_by,recalled_at=excluded.recalled_at,recalled_by=excluded.recalled_by`;
|
|
15
|
+
const MESSAGE_MUTABLE_FIELDS = ["is_question", "answer_to", "answered_by", "recalled_at", "recalled_by"];
|
|
16
|
+
const REGISTRY_COLUMNS = "server_url,api_prefix,protocol,name,last_read_ts,last_queued_ts,directory,host,receiver_owner_id,membership_id,work_state,last_seen_at";
|
|
17
|
+
const REGISTRY_FIELDS = REGISTRY_COLUMNS.split(",");
|
|
18
|
+
const REGISTRY_INSERT = `INSERT INTO registry(room_id,session_id,${REGISTRY_COLUMNS}) VALUES(?,?,${REGISTRY_FIELDS.map(() => "?").join(",")})`;
|
|
19
|
+
|
|
8
20
|
function roomColumns(room: Room): string | null {
|
|
9
21
|
return room.adminIds?.length ? JSON.stringify([...new Set(room.adminIds)]) : null;
|
|
10
22
|
}
|
|
11
23
|
const adminBindings = (room: Room) => room.adminMembershipIDs?.length ? JSON.stringify([...new Set(room.adminMembershipIDs)]) : null;
|
|
12
|
-
|
|
24
|
+
|
|
25
|
+
function roomValues(room: Room): SQLQueryBindings[] {
|
|
26
|
+
return [room.name, room.ownerId, room.createdAt, room.kind ?? "group",
|
|
27
|
+
room.directSessionIDs ? JSON.stringify(room.directSessionIDs) : null, room.directPair ?? null,
|
|
28
|
+
room.description ?? null, roomColumns(room), adminBindings(room),
|
|
29
|
+
room.ownerMembershipID ?? null, room.successorId ?? null, room.successorMembershipID ?? null,
|
|
30
|
+
room.joinPolicy ?? null];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function messageValues(message: Message): SQLQueryBindings[] {
|
|
34
|
+
return [message.id, message.roomId, message.senderId, message.senderSessionID ?? null, message.text,
|
|
35
|
+
message.createdAt, message.isQuestion ? 1 : 0, message.answerToMessageID ?? null,
|
|
36
|
+
message.answeredByMessageID ?? null, message.recalledAt ?? null, message.recalledBy ?? null];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function mutableMessageValues(message: Message): SQLQueryBindings[] {
|
|
40
|
+
return [message.isQuestion ? 1 : 0, message.answerToMessageID ?? null, message.answeredByMessageID ?? null,
|
|
41
|
+
message.recalledAt ?? null, message.recalledBy ?? null];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function registryValues(entry: RegistryEntry): SQLQueryBindings[] {
|
|
45
|
+
return [entry.serverUrl, entry.apiPrefix, entry.protocol ?? null, entry.name,
|
|
46
|
+
entry.lastReadTs ?? null, entry.lastQueuedTs ?? null, entry.directory ?? null, entry.host ?? null,
|
|
47
|
+
entry.receiverOwnerID ?? null, entry.membershipID ?? null, entry.workState ?? null, entry.lastSeenAt ?? null];
|
|
48
|
+
}
|
|
13
49
|
|
|
14
50
|
export function insertRoom(db: StateDatabase, room: Room): void {
|
|
15
|
-
db.query(
|
|
51
|
+
db.query(ROOM_INSERT).run(room.id, ...roomValues(room));
|
|
16
52
|
const participant = db.query("INSERT INTO participants VALUES(?,?,?,?)");
|
|
17
53
|
for (const p of room.participants.values()) participant.run(room.id, p.id, p.name, p.joinedAt);
|
|
18
|
-
const message = db.query(
|
|
19
|
-
for (const m of room.messages) message.run(m
|
|
54
|
+
const message = db.query(MESSAGE_INSERT);
|
|
55
|
+
for (const m of room.messages) message.run(...messageValues(m));
|
|
20
56
|
}
|
|
21
57
|
|
|
22
58
|
export function replaceRegistry(db: StateDatabase, registry: Registry): void {
|
|
23
59
|
db.exec("DELETE FROM registry");
|
|
24
|
-
const insert = db.query(
|
|
60
|
+
const insert = db.query(REGISTRY_INSERT);
|
|
25
61
|
for (const [roomID, members] of Object.entries(registry)) for (const [sessionID, r] of Object.entries(members)) {
|
|
26
62
|
r.membershipID ||= randomUUID();
|
|
27
|
-
insert.run(roomID, sessionID, r
|
|
28
|
-
r.lastReadTs ?? null, r.lastQueuedTs ?? null, r.directory ?? null, r.host ?? null, r.receiverOwnerID ?? null,
|
|
29
|
-
r.membershipID, r.workState ?? null, r.lastSeenAt ?? null);
|
|
63
|
+
insert.run(roomID, sessionID, ...registryValues(r));
|
|
30
64
|
}
|
|
31
65
|
}
|
|
32
66
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const existing = db.query("SELECT id FROM rooms").all() as Array<{ id: string }>;
|
|
67
|
+
// Apply only the rows that differ between the snapshot read before a write
|
|
68
|
+
// callback and the state the callback produced. Untouched rows are never
|
|
69
|
+
// deleted or rewritten, so another process's committed changes survive.
|
|
70
|
+
export function persistStateDiff(db: StateDatabase, before: State, after: State): void {
|
|
71
|
+
const beforeRooms = new Map(before.rooms.map((room) => [room.id, room]));
|
|
72
|
+
const afterRooms = new Map(after.rooms.map((room) => [room.id, room]));
|
|
40
73
|
const deleteRoom = db.query("DELETE FROM rooms WHERE id=?");
|
|
41
|
-
for (const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
74
|
+
for (const room of before.rooms) if (!afterRooms.has(room.id)) deleteRoom.run(room.id);
|
|
75
|
+
|
|
76
|
+
const insertRoomRow = db.query(ROOM_INSERT);
|
|
77
|
+
const insertParticipant = db.query("INSERT INTO participants VALUES(?,?,?,?)");
|
|
78
|
+
const updateParticipant = db.query("UPDATE participants SET name=?,joined_at=? WHERE room_id=? AND id=?");
|
|
79
|
+
const deleteParticipant = db.query("DELETE FROM participants WHERE room_id=? AND id=?");
|
|
80
|
+
const message = db.query(MESSAGE_UPSERT);
|
|
81
|
+
|
|
82
|
+
for (const room of after.rooms) {
|
|
83
|
+
const previous = beforeRooms.get(room.id);
|
|
84
|
+
if (!previous) {
|
|
85
|
+
insertRoomRow.run(room.id, ...roomValues(room));
|
|
86
|
+
for (const p of room.participants.values()) insertParticipant.run(room.id, p.id, p.name, p.joinedAt);
|
|
87
|
+
for (const m of room.messages) message.run(...messageValues(m));
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
updateChanged(db, "rooms", ROOM_FIELDS, roomValues(previous), roomValues(room), "id=?", [room.id]);
|
|
91
|
+
for (const [id, participant] of room.participants) {
|
|
92
|
+
const prior = previous.participants.get(id);
|
|
93
|
+
if (!prior) insertParticipant.run(room.id, id, participant.name, participant.joinedAt);
|
|
94
|
+
else if (prior.name !== participant.name || prior.joinedAt !== participant.joinedAt) {
|
|
95
|
+
updateParticipant.run(participant.name, participant.joinedAt, room.id, id);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
for (const id of previous.participants.keys()) if (!room.participants.has(id)) deleteParticipant.run(room.id, id);
|
|
99
|
+
const previousMessages = new Map(previous.messages.map((item) => [item.id, item]));
|
|
100
|
+
for (const item of room.messages) {
|
|
101
|
+
const prior = previousMessages.get(item.id);
|
|
102
|
+
if (!prior) message.run(...messageValues(item));
|
|
103
|
+
else updateChanged(db, "messages", MESSAGE_MUTABLE_FIELDS, mutableMessageValues(prior), mutableMessageValues(item), "id=?", [item.id]);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
for (const members of Object.values(after.registry)) for (const entry of Object.values(members)) entry.membershipID ||= randomUUID();
|
|
108
|
+
const insertRegistry = db.query(REGISTRY_INSERT);
|
|
109
|
+
for (const [roomID, members] of Object.entries(after.registry)) {
|
|
110
|
+
for (const [sessionID, entry] of Object.entries(members)) {
|
|
111
|
+
const previous = before.registry[roomID]?.[sessionID];
|
|
112
|
+
if (!previous) insertRegistry.run(roomID, sessionID, ...registryValues(entry));
|
|
113
|
+
else updateChanged(db, "registry", REGISTRY_FIELDS, registryValues(previous), registryValues(entry), "room_id=? AND session_id=?", [roomID, sessionID]);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const deleteRegistry = db.query("DELETE FROM registry WHERE room_id=? AND session_id=?");
|
|
117
|
+
for (const [roomID, members] of Object.entries(before.registry)) {
|
|
118
|
+
for (const sessionID of Object.keys(members)) {
|
|
119
|
+
if (!after.registry[roomID]?.[sessionID]) deleteRegistry.run(roomID, sessionID);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function updateChanged(db: StateDatabase, table: string, fields: string[], before: SQLQueryBindings[], after: SQLQueryBindings[], where: string, key: SQLQueryBindings[]): void {
|
|
125
|
+
const changed: Array<{ field: string; value: SQLQueryBindings }> = [];
|
|
126
|
+
for (let index = 0; index < fields.length; index++) {
|
|
127
|
+
if (before[index] === after[index]) continue;
|
|
128
|
+
changed.push({ field: fields[index]!, value: after[index] });
|
|
129
|
+
}
|
|
130
|
+
if (!changed.length) return;
|
|
131
|
+
db.query(`UPDATE ${table} SET ${changed.map(({ field }) => `${field}=?`).join(",")} WHERE ${where}`)
|
|
132
|
+
.run(...changed.map(({ value }) => value), ...key);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function cloneRoom(room: Room): Room {
|
|
136
|
+
return {
|
|
137
|
+
...room,
|
|
138
|
+
...(room.adminIds ? { adminIds: [...room.adminIds] } : {}),
|
|
139
|
+
...(room.adminMembershipIDs ? { adminMembershipIDs: [...room.adminMembershipIDs] } : {}),
|
|
140
|
+
...(room.directSessionIDs ? { directSessionIDs: [...room.directSessionIDs] } : {}),
|
|
141
|
+
participants: new Map([...room.participants].map(([id, p]) => [id, { ...p }])),
|
|
142
|
+
messages: room.messages.map((message) => ({ ...message })),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// The write path hydrates this copy so the pre-callback snapshot stays
|
|
147
|
+
// untouched for diffing. Registry entries are copied too: callbacks mutate them
|
|
148
|
+
// in place.
|
|
149
|
+
export function cloneState(state: State): State {
|
|
150
|
+
const registry: Registry = Object.create(null);
|
|
151
|
+
for (const [roomID, members] of Object.entries(state.registry)) {
|
|
152
|
+
registry[roomID] = Object.create(null);
|
|
153
|
+
for (const [sessionID, entry] of Object.entries(members)) registry[roomID]![sessionID] = { ...entry };
|
|
47
154
|
}
|
|
48
|
-
|
|
155
|
+
return { rooms: state.rooms.map(cloneRoom), registry };
|
|
49
156
|
}
|
|
50
157
|
|
|
51
158
|
export type RoomSummary = { id: string; name: string; latestMsgTs: number };
|
|
@@ -3,7 +3,7 @@ import type { Registry } from "./store.ts";
|
|
|
3
3
|
import { type StateDatabase } from "./sqlite.ts";
|
|
4
4
|
import { openStateDatabase } from "./sqlite-database.ts";
|
|
5
5
|
import { immediate } from "./sqlite-transaction.ts";
|
|
6
|
-
import {
|
|
6
|
+
import { cloneState, persistStateDiff, readRoomSummaries, readState, type RoomSummary, type State } from "./sqlite-rooms.ts";
|
|
7
7
|
|
|
8
8
|
export async function writeSqliteState<T>(file: string, callback: (service: RoomService, registry: Registry) => T): Promise<T> {
|
|
9
9
|
return writeSqliteStateWithDatabase(file, (service, registry) => callback(service, registry));
|
|
@@ -12,12 +12,13 @@ export async function writeSqliteState<T>(file: string, callback: (service: Room
|
|
|
12
12
|
export async function writeSqliteStateWithDatabase<T>(file: string, callback: (service: RoomService, registry: Registry, db: StateDatabase) => T): Promise<T> {
|
|
13
13
|
const db = await openStateDatabase(file);
|
|
14
14
|
return immediate(db, () => {
|
|
15
|
-
const
|
|
15
|
+
const before = readState(db);
|
|
16
|
+
const working = cloneState(before);
|
|
16
17
|
const service = new RoomService();
|
|
17
|
-
service.hydrate(
|
|
18
|
-
const result = callback(service,
|
|
18
|
+
service.hydrate(working.rooms);
|
|
19
|
+
const result = callback(service, working.registry, db);
|
|
19
20
|
if (result && typeof (result as { then?: unknown }).then === "function") throw new Error("writeState callback must be synchronous");
|
|
20
|
-
|
|
21
|
+
persistStateDiff(db, before, { rooms: service.listRooms(), registry: working.registry });
|
|
21
22
|
return result;
|
|
22
23
|
});
|
|
23
24
|
}
|
package/src/state/sqlite.ts
CHANGED
|
@@ -92,9 +92,9 @@ export class Database implements StateDatabase {
|
|
|
92
92
|
export function isBusyError(error: unknown): boolean {
|
|
93
93
|
const err = error as { code?: string; errcode?: number; message?: string } | null;
|
|
94
94
|
if (!err) return false;
|
|
95
|
-
// PostgreSQL serialization failure and
|
|
96
|
-
// immediate() retry loop treats these like SQLITE_BUSY/SQLITE_LOCKED.
|
|
97
|
-
if (err.code === "40001" || err.code === "40P01") return true;
|
|
95
|
+
// PostgreSQL serialization failure, deadlock, and advisory-lock timeout. The
|
|
96
|
+
// existing immediate() retry loop treats these like SQLITE_BUSY/SQLITE_LOCKED.
|
|
97
|
+
if (err.code === "40001" || err.code === "40P01" || err.code === "55P03") return true;
|
|
98
98
|
if (typeof err.errcode === "number" && ((err.errcode & 0xff) === 5 || (err.errcode & 0xff) === 6)) return true;
|
|
99
99
|
return /SQLITE_(BUSY|LOCKED)/.test(err.code ?? "") || /database (?:is|table is) locked/i.test(err.message ?? "");
|
|
100
100
|
}
|
|
@@ -49,8 +49,10 @@ type Options = {
|
|
|
49
49
|
type RegistryEntry = { kind: RulesKind; uri: string; schema: JsonSchema; modelUri: string };
|
|
50
50
|
const registry = new Map<RulesKind, RegistryEntry>();
|
|
51
51
|
let completionRegistered = false;
|
|
52
|
+
let hoverRegistered = false;
|
|
52
53
|
let themeObserver: MutationObserver | null = null;
|
|
53
54
|
let themeMedia: MediaQueryList | null = null;
|
|
55
|
+
let previewCount = 0;
|
|
54
56
|
|
|
55
57
|
const scope = globalThis as typeof globalThis & { MonacoEnvironment?: { getWorker?: (workerId: string, label: string) => Worker } };
|
|
56
58
|
scope.MonacoEnvironment = {
|
|
@@ -61,13 +63,28 @@ scope.MonacoEnvironment = {
|
|
|
61
63
|
|
|
62
64
|
function isDarkTheme(): boolean {
|
|
63
65
|
const theme = document.documentElement.dataset.theme;
|
|
66
|
+
if (theme === "custom") return document.documentElement.dataset.customDark === "true";
|
|
64
67
|
if (theme === "dark") return true;
|
|
65
68
|
return theme !== "light" && theme !== "forest" && theme !== "sand" && matchMedia("(prefers-color-scheme: dark)").matches;
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
function applyTheme() {
|
|
69
|
-
const
|
|
70
|
-
|
|
72
|
+
const read = (name: string, fallback: string) => {
|
|
73
|
+
// Monaco only accepts hex token colors. Resolve the CSS variable to a
|
|
74
|
+
// concrete color first, then normalize rgb()/color() through a canvas.
|
|
75
|
+
const probe = document.createElement("span");
|
|
76
|
+
probe.style.position = "absolute";
|
|
77
|
+
probe.style.visibility = "hidden";
|
|
78
|
+
probe.style.background = `var(${name})`;
|
|
79
|
+
document.documentElement.append(probe);
|
|
80
|
+
const resolved = getComputedStyle(probe).backgroundColor;
|
|
81
|
+
probe.remove();
|
|
82
|
+
const canvas = document.createElement("canvas").getContext("2d");
|
|
83
|
+
if (!canvas || !resolved) return fallback;
|
|
84
|
+
canvas.fillStyle = "#000000";
|
|
85
|
+
canvas.fillStyle = resolved;
|
|
86
|
+
return /^#[0-9a-f]{6}$/i.test(canvas.fillStyle) ? canvas.fillStyle : fallback;
|
|
87
|
+
};
|
|
71
88
|
monaco.editor.defineTheme("chatroom-light", {
|
|
72
89
|
base: "vs",
|
|
73
90
|
inherit: true,
|
|
@@ -77,13 +94,31 @@ function applyTheme() {
|
|
|
77
94
|
"editorGutter.background": read("--surface", "#fffefa"),
|
|
78
95
|
"editor.lineHighlightBackground": read("--surface-2", "#f2f0e8"),
|
|
79
96
|
"editorLineNumber.foreground": read("--ink-3", "#63716b"),
|
|
97
|
+
"menu.background": read("--surface", "#fffefa"),
|
|
98
|
+
"menu.foreground": read("--ink", "#1e2c29"),
|
|
99
|
+
"menu.selectionBackground": read("--surface-2", "#f2f0e8"),
|
|
100
|
+
"menu.selectionForeground": read("--ink", "#1e2c29"),
|
|
101
|
+
"menu.border": read("--line", "#dcded4"),
|
|
102
|
+
"editorWidget.background": read("--surface", "#fffefa"),
|
|
103
|
+
"editorWidget.foreground": read("--ink", "#1e2c29"),
|
|
104
|
+
"editorWidget.border": read("--line", "#dcded4"),
|
|
80
105
|
},
|
|
81
106
|
});
|
|
82
107
|
monaco.editor.defineTheme("chatroom-dark", {
|
|
83
108
|
base: "vs-dark",
|
|
84
109
|
inherit: true,
|
|
85
110
|
rules: [],
|
|
86
|
-
colors: {
|
|
111
|
+
colors: {
|
|
112
|
+
"editor.background": read("--surface", "#182522"),
|
|
113
|
+
"menu.background": read("--surface", "#182522"),
|
|
114
|
+
"menu.foreground": read("--ink", "#e6efe9"),
|
|
115
|
+
"menu.selectionBackground": read("--surface-2", "#22322e"),
|
|
116
|
+
"menu.selectionForeground": read("--ink", "#e6efe9"),
|
|
117
|
+
"menu.border": read("--line", "#31433d"),
|
|
118
|
+
"editorWidget.background": read("--surface", "#182522"),
|
|
119
|
+
"editorWidget.foreground": read("--ink", "#e6efe9"),
|
|
120
|
+
"editorWidget.border": read("--line", "#31433d"),
|
|
121
|
+
},
|
|
87
122
|
});
|
|
88
123
|
monaco.editor.setTheme(isDarkTheme() ? "chatroom-dark" : "chatroom-light");
|
|
89
124
|
}
|
|
@@ -92,7 +127,7 @@ function watchTheme() {
|
|
|
92
127
|
applyTheme();
|
|
93
128
|
if (themeObserver) return;
|
|
94
129
|
themeObserver = new MutationObserver(applyTheme);
|
|
95
|
-
themeObserver.observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] });
|
|
130
|
+
themeObserver.observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme", "data-custom-dark"] });
|
|
96
131
|
themeMedia = matchMedia("(prefers-color-scheme: dark)");
|
|
97
132
|
themeMedia.addEventListener("change", applyTheme);
|
|
98
133
|
}
|
|
@@ -222,6 +257,48 @@ function ensureYamlCompletion() {
|
|
|
222
257
|
});
|
|
223
258
|
}
|
|
224
259
|
|
|
260
|
+
function ensureYamlHover() {
|
|
261
|
+
if (hoverRegistered) return;
|
|
262
|
+
hoverRegistered = true;
|
|
263
|
+
monaco.languages.registerHoverProvider("yaml", {
|
|
264
|
+
provideHover(model, position) {
|
|
265
|
+
const entry = [...registry.values()].find((item) => item.modelUri === model.uri.toString());
|
|
266
|
+
if (!entry) return null;
|
|
267
|
+
let doc: any;
|
|
268
|
+
try { doc = parseDocument(model.getValue()); } catch { return null; }
|
|
269
|
+
const root = doc.contents;
|
|
270
|
+
const path = pathAtOffset(root, model.getOffsetAt(position));
|
|
271
|
+
if (!path) return null;
|
|
272
|
+
const line = model.getLineContent(position.lineNumber);
|
|
273
|
+
const match = /^\s*(?:-\s*)?["']?([A-Za-z0-9_.-]+)["']?\s*:/.exec(line);
|
|
274
|
+
let schema: JsonSchema | undefined;
|
|
275
|
+
let label = "";
|
|
276
|
+
if (match) {
|
|
277
|
+
const key = match[1]!;
|
|
278
|
+
const container = path[path.length - 1] === key ? path.slice(0, -1) : path;
|
|
279
|
+
schema = schemaAtPath(entry.schema, container, key);
|
|
280
|
+
label = key;
|
|
281
|
+
} else {
|
|
282
|
+
schema = schemaAtPath(entry.schema, path);
|
|
283
|
+
label = String(path[path.length - 1] ?? "");
|
|
284
|
+
}
|
|
285
|
+
if (!schema?.description) return null;
|
|
286
|
+
const word = model.getWordAtPosition(position);
|
|
287
|
+
const range = word
|
|
288
|
+
? new monaco.Range(position.lineNumber, word.startColumn, position.lineNumber, word.endColumn)
|
|
289
|
+
: undefined;
|
|
290
|
+
const type = schema.type ? ` (${String(schema.type)})` : "";
|
|
291
|
+
return {
|
|
292
|
+
range,
|
|
293
|
+
contents: [
|
|
294
|
+
{ value: `**${label}**` },
|
|
295
|
+
{ value: `${type.trim()}${type ? " " : ""}${schema.description}` },
|
|
296
|
+
],
|
|
297
|
+
};
|
|
298
|
+
},
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
|
|
225
302
|
type ParseResult = {
|
|
226
303
|
value?: unknown;
|
|
227
304
|
doc?: any;
|
|
@@ -312,7 +389,7 @@ function formatLabel(format: RulesFormat): string {
|
|
|
312
389
|
|
|
313
390
|
export function createIntegrationRulesEditor(options: Options): IntegrationRulesEditor {
|
|
314
391
|
const kind = options.kind;
|
|
315
|
-
let format: RulesFormat = options.format ?? "
|
|
392
|
+
let format: RulesFormat = options.format ?? "yaml";
|
|
316
393
|
let accounts = options.accounts;
|
|
317
394
|
let schema = kind === "inbound" ? buildInboundSchema(accounts) : buildRulesSchema(accounts);
|
|
318
395
|
const entry: RegistryEntry = {
|
|
@@ -324,6 +401,7 @@ export function createIntegrationRulesEditor(options: Options): IntegrationRules
|
|
|
324
401
|
registry.set(kind, entry);
|
|
325
402
|
publishJsonSchemas();
|
|
326
403
|
ensureYamlCompletion();
|
|
404
|
+
ensureYamlHover();
|
|
327
405
|
watchTheme();
|
|
328
406
|
|
|
329
407
|
const text = stringifyValue(options.value ?? [], format);
|
|
@@ -352,6 +430,29 @@ export function createIntegrationRulesEditor(options: Options): IntegrationRules
|
|
|
352
430
|
suggest: { showWords: false },
|
|
353
431
|
});
|
|
354
432
|
|
|
433
|
+
const onWheel = (event: WheelEvent) => {
|
|
434
|
+
// Modifiers belong to Monaco: Ctrl/Cmd zooms, Shift scrolls horizontally.
|
|
435
|
+
if (event.ctrlKey || event.metaKey || event.altKey || event.shiftKey) return;
|
|
436
|
+
const max = Math.max(0, editor.getScrollHeight() - editor.getLayoutInfo().height);
|
|
437
|
+
const top = editor.getScrollTop();
|
|
438
|
+
const atTop = event.deltaY < 0 && top <= 0;
|
|
439
|
+
const atBottom = event.deltaY > 0 && top >= max - 1;
|
|
440
|
+
if (!atTop && !atBottom) return;
|
|
441
|
+
// Hand the wheel to the page once the editor cannot scroll further.
|
|
442
|
+
let node = options.container.parentElement;
|
|
443
|
+
while (node) {
|
|
444
|
+
const style = getComputedStyle(node);
|
|
445
|
+
if (/(auto|scroll)/.test(style.overflowY) && node.scrollHeight > node.clientHeight + 1) {
|
|
446
|
+
node.scrollTop += event.deltaY;
|
|
447
|
+
event.preventDefault();
|
|
448
|
+
event.stopPropagation();
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
node = node.parentElement;
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
options.container.addEventListener("wheel", onWheel, { capture: true, passive: false });
|
|
455
|
+
|
|
355
456
|
const validate = (): EditorValidation => {
|
|
356
457
|
const current = model.getValue();
|
|
357
458
|
const parsed = format === "yaml" ? parseYaml(current) : parseJson(current);
|
|
@@ -429,6 +530,7 @@ export function createIntegrationRulesEditor(options: Options): IntegrationRules
|
|
|
429
530
|
setReadOnly: (readOnly) => editor.updateOptions({ readOnly }),
|
|
430
531
|
focus: () => editor.focus(),
|
|
431
532
|
dispose: () => {
|
|
533
|
+
options.container.removeEventListener("wheel", onWheel, true);
|
|
432
534
|
change.dispose();
|
|
433
535
|
editor.dispose();
|
|
434
536
|
model.dispose();
|
|
@@ -436,4 +538,36 @@ export function createIntegrationRulesEditor(options: Options): IntegrationRules
|
|
|
436
538
|
publishJsonSchemas();
|
|
437
539
|
},
|
|
438
540
|
};
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
export type CodePreviewOptions = { container: HTMLElement; value: string; language?: string };
|
|
544
|
+
|
|
545
|
+
export function createCodePreviewEditor(options: CodePreviewOptions): { dispose: () => void } {
|
|
546
|
+
watchTheme();
|
|
547
|
+
const language = options.language || "plaintext";
|
|
548
|
+
const model = monaco.editor.createModel(
|
|
549
|
+
options.value,
|
|
550
|
+
language,
|
|
551
|
+
monaco.Uri.parse(`inmemory://chat/code-preview-${++previewCount}.${language}`),
|
|
552
|
+
);
|
|
553
|
+
const editor = monaco.editor.create(options.container, {
|
|
554
|
+
model,
|
|
555
|
+
theme: isDarkTheme() ? "chatroom-dark" : "chatroom-light",
|
|
556
|
+
readOnly: true,
|
|
557
|
+
automaticLayout: true,
|
|
558
|
+
minimap: { enabled: false },
|
|
559
|
+
scrollBeyondLastLine: false,
|
|
560
|
+
fontSize: 12,
|
|
561
|
+
lineNumbers: "on",
|
|
562
|
+
wordWrap: "off",
|
|
563
|
+
renderLineHighlight: "none",
|
|
564
|
+
overviewRulerLanes: 0,
|
|
565
|
+
hideCursorInOverviewRuler: true,
|
|
566
|
+
folding: true,
|
|
567
|
+
padding: { top: 10, bottom: 10 },
|
|
568
|
+
scrollbar: { verticalScrollbarSize: 8, horizontalScrollbarSize: 8, useShadows: false },
|
|
569
|
+
contextmenu: true,
|
|
570
|
+
ariaLabel: "Code preview",
|
|
571
|
+
});
|
|
572
|
+
return { dispose: () => { editor.dispose(); model.dispose(); } };
|
|
439
573
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Build entry for the lazy integration rules editor. Keeping Monaco contributions out
|
|
2
2
|
// of integrations.js means the editor bundle is fetched only when the panel opens.
|
|
3
|
+
import "monaco-editor/basic-languages/monaco.contribution";
|
|
3
4
|
import "monaco-editor/editor/contrib/bracketMatching/browser/bracketMatching";
|
|
4
5
|
import "monaco-editor/editor/contrib/clipboard/browser/clipboard";
|
|
5
6
|
import "monaco-editor/editor/contrib/codeAction/browser/codeActionContributions";
|
|
@@ -16,7 +17,10 @@ import "monaco-editor/editor/contrib/snippet/browser/snippetController2";
|
|
|
16
17
|
import "monaco-editor/editor/contrib/suggest/browser/suggestController";
|
|
17
18
|
import "monaco-editor/editor/contrib/wordHighlighter/browser/wordHighlighter";
|
|
18
19
|
import "monaco-editor/editor/contrib/wordOperations/browser/wordOperations";
|
|
20
|
+
import "monaco-editor/editor/contrib/codelens/browser/codeLensCache";
|
|
21
|
+
import "monaco-editor/editor/contrib/codelens/browser/codelensController";
|
|
22
|
+
import "monaco-editor/editor/common/services/treeViewsDndService";
|
|
19
23
|
import "monaco-editor/editor/browser/coreCommands";
|
|
20
24
|
|
|
21
|
-
export { createIntegrationRulesEditor } from "./integration-rules-editor";
|
|
22
|
-
export type { IntegrationRulesEditor, EditorValidation, RulesFormat, RulesKind } from "./integration-rules-editor";
|
|
25
|
+
export { createCodePreviewEditor, createIntegrationRulesEditor } from "./integration-rules-editor";
|
|
26
|
+
export type { CodePreviewOptions, IntegrationRulesEditor, EditorValidation, RulesFormat, RulesKind } from "./integration-rules-editor";
|
|
@@ -88,11 +88,12 @@ export function buildRulesSchema(accounts: RuleAccount[]): JsonSchema {
|
|
|
88
88
|
version: { type: "integer", minimum: 1, description: "Bump the version to replace this rule." },
|
|
89
89
|
from: {
|
|
90
90
|
type: "object",
|
|
91
|
+
description: "Where the rule reads events from.",
|
|
91
92
|
additionalProperties: false,
|
|
92
93
|
required: ["platform", "account", "room"],
|
|
93
94
|
properties: {
|
|
94
|
-
platform: { const: "chatroom", errorMessage: "The source platform must be chatroom." },
|
|
95
|
-
account: { const: "center", errorMessage: "The source account must be center." },
|
|
95
|
+
platform: { const: "chatroom", description: "Source platform; room messages always use chatroom.", errorMessage: "The source platform must be chatroom." },
|
|
96
|
+
account: { const: "center", description: "Source account; room messages always use center.", errorMessage: "The source account must be center." },
|
|
96
97
|
room: { type: "string", minLength: 1, description: "Room ID to watch." },
|
|
97
98
|
event: {
|
|
98
99
|
enum: ["message.created", "message.forward_requested"],
|
|
@@ -100,10 +101,10 @@ export function buildRulesSchema(accounts: RuleAccount[]): JsonSchema {
|
|
|
100
101
|
},
|
|
101
102
|
},
|
|
102
103
|
},
|
|
103
|
-
transforms: { type: "array", items: transformSchema },
|
|
104
|
-
to: { type: "array", minItems: 1, items: target(accounts) },
|
|
105
|
-
onMissingParent: { enum: ["quote_or_unthreaded", "drop"] },
|
|
106
|
-
onUnsupported: { enum: ["text_with_notice", "drop"] },
|
|
104
|
+
transforms: { type: "array", description: "Transformations applied to the message before delivery.", items: transformSchema },
|
|
105
|
+
to: { type: "array", description: "External accounts and rooms that receive matching messages.", minItems: 1, items: target(accounts) },
|
|
106
|
+
onMissingParent: { enum: ["quote_or_unthreaded", "drop"], description: "What to do when the replied-to parent message is unavailable on the target." },
|
|
107
|
+
onUnsupported: { enum: ["text_with_notice", "drop"], description: "What to do when the target cannot render the message content." },
|
|
107
108
|
},
|
|
108
109
|
},
|
|
109
110
|
} as JsonSchema;
|