@alexsun-top/opencode-chat-room 0.8.0 → 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 +52 -0
- package/LICENSE +2 -2
- package/README.md +40 -8
- package/README.zh-CN.md +40 -8
- package/cli.ts +27 -1
- package/dist/cli.js +5406 -3088
- package/package.json +25 -5
- package/packages/chat-room-channeld/README.md +111 -33
- package/packages/chat-room-channeld/src/adapter.ts +179 -7
- package/packages/chat-room-channeld/src/config.ts +63 -1
- package/packages/chat-room-channeld/src/delivery.ts +6 -1
- package/packages/chat-room-channeld/src/host-helpers.ts +11 -0
- package/packages/chat-room-channeld/src/host.ts +142 -9
- package/packages/chat-room-channeld/src/inbound.ts +35 -0
- package/packages/chat-room-channeld/src/protocol.ts +52 -1
- package/packages/chat-room-channeld/src/rules.ts +7 -2
- package/packages/chat-room-channeld/src/state.ts +17 -0
- package/packages/chat-room-channeld/src/stats.ts +43 -1
- package/plugin.ts +1 -1
- package/server/admin-state.ts +13 -13
- package/server/app.ts +95 -0
- package/server/assets/NOTICE.txt +2 -1
- package/server/assets/base.css +21 -9
- package/server/assets/chat/admin.js +0 -2
- package/server/assets/chat/announcements.js +69 -8
- 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 +251 -46
- package/server/assets/chat/events.js +16 -5
- package/server/assets/chat/files.js +53 -7
- package/server/assets/chat/image-zoom.js +8 -1
- package/server/assets/chat/index.js +6 -2
- package/server/assets/chat/integration-account-schema.js +99 -0
- package/server/assets/chat/integration-editor.js +163 -0
- package/server/assets/chat/integration-values.js +124 -0
- package/server/assets/chat/integrations.js +648 -0
- package/server/assets/chat/locales/de.js +40 -4
- package/server/assets/chat/locales/es.js +40 -4
- package/server/assets/chat/locales/fr.js +40 -4
- package/server/assets/chat/locales/it.js +40 -4
- package/server/assets/chat/locales/ja.js +40 -4
- package/server/assets/chat/locales/ko.js +40 -4
- package/server/assets/chat/markdown-footnotes.js +1 -1
- package/server/assets/chat/markdown.js +45 -8
- package/server/assets/chat/messages.js +6 -5
- package/server/assets/chat/office-preview.js +69 -0
- package/server/assets/chat/palette.js +6 -1
- package/server/assets/chat/panels.js +56 -0
- package/server/assets/chat/recall.js +58 -7
- package/server/assets/chat/receipts.js +17 -6
- package/server/assets/chat/reminders.js +68 -9
- package/server/assets/chat/replies.js +0 -6
- package/server/assets/chat/resource-format.js +11 -0
- package/server/assets/chat/rooms.js +1 -6
- package/server/assets/chat/settings.js +98 -4
- package/server/assets/chat/shortcuts.js +0 -3
- package/server/assets/chat/side-pane.js +34 -10
- package/server/assets/chat/state.js +125 -12
- package/server/assets/chat/system-events.js +58 -0
- package/server/assets/chat/system-messages.js +32 -14
- package/server/assets/chat/task-row.js +0 -6
- package/server/assets/chat/tasks.js +119 -37
- package/server/assets/chat/window-controls.js +37 -0
- package/server/assets/code-highlight.css +71 -32
- package/server/assets/conversation.css +174 -31
- package/server/assets/doc-preview.css +40 -3
- package/server/assets/files.css +8 -0
- package/server/assets/fluent-icons.svg +2 -0
- package/server/assets/monaco/LICENSE +21 -0
- package/server/assets/monaco/ThirdPartyNotices.txt +448 -0
- package/server/assets/monaco/codicon-jdswhhtn.ttf +0 -0
- package/server/assets/monaco/editor.worker.js +45 -0
- package/server/assets/monaco/integration-rules.css +1 -0
- package/server/assets/monaco/integration-rules.js +1605 -0
- package/server/assets/monaco/json.worker.js +77 -0
- package/server/assets/office/THIRD-PARTY-NOTICES.txt +11 -0
- package/server/assets/office/docx.bundle.js +33 -0
- package/server/assets/office/licenses/docx-preview-LICENSE.txt +201 -0
- package/server/assets/office/licenses/echarts-LICENSE.txt +222 -0
- package/server/assets/office/licenses/jszip-LICENSE.txt +651 -0
- package/server/assets/office/licenses/lodash-LICENSE.txt +47 -0
- package/server/assets/office/licenses/pptx-preview-LICENSE.txt +8 -0
- package/server/assets/office/licenses/tslib-LICENSE.txt +12 -0
- package/server/assets/office/licenses/uuid-LICENSE.txt +9 -0
- package/server/assets/office/licenses/xlsx-LICENSE.txt +201 -0
- package/server/assets/office/licenses/zrender-LICENSE.txt +29 -0
- package/server/assets/office/pptx.bundle.js +104 -0
- package/server/assets/office/xlsx.bundle.js +141 -0
- package/server/assets/recall.css +5 -4
- package/server/assets/responsive.css +80 -11
- package/server/assets/settings.css +185 -9
- package/server/assets/tasks.css +57 -7
- package/server/assets/window-controls.css +36 -0
- package/server/channel-attachments.ts +133 -0
- package/server/channel-integration.ts +572 -0
- package/server/channel-settings.ts +77 -0
- package/server/channels.ts +274 -21
- package/server/chat-server.ts +32 -580
- package/server/chat.html +234 -34
- package/server/http-server.ts +3 -182
- package/server/manifest.webmanifest +1 -0
- package/server/resource-routes.ts +16 -16
- package/server/routes/inbox.ts +100 -0
- package/server/routes/pages.ts +83 -0
- package/server/routes/questions.ts +39 -0
- package/server/routes/room-actions.ts +162 -0
- package/server/routes/rooms.ts +160 -0
- package/server/startup.ts +84 -0
- package/server/sw.js +5 -0
- package/server/task-routes.ts +1 -1
- package/src/center/center-client.ts +3 -11
- package/src/config/file-config.ts +7 -54
- package/src/platform/http-server.ts +182 -0
- package/src/protocol/addressing.ts +21 -0
- package/src/protocol/config.ts +58 -0
- package/src/protocol/room.ts +51 -0
- package/src/rooms/resources.ts +26 -16
- package/src/rooms/room-service.ts +2 -48
- package/src/rooms/storage.ts +329 -0
- package/src/rooms/tasks.ts +21 -5
- package/src/runtime/watch.ts +1 -1
- package/src/state/pg-database.ts +183 -0
- package/src/state/pg-migrate.ts +175 -0
- package/src/state/pg-sql.mjs +175 -0
- package/src/state/pg-worker.mjs +133 -0
- package/src/state/sqlite-announcements.ts +25 -0
- package/src/state/sqlite-database.ts +130 -0
- package/src/state/sqlite-legacy.ts +90 -0
- package/src/state/sqlite-members.ts +155 -0
- package/src/state/sqlite-messages.ts +288 -0
- package/src/state/sqlite-resources.ts +39 -0
- package/src/state/sqlite-rooms.ts +194 -0
- package/src/state/sqlite-schema.ts +80 -0
- package/src/state/sqlite-state-store.ts +34 -0
- package/src/state/sqlite-state.ts +15 -897
- package/src/state/sqlite-tasks.ts +65 -0
- package/src/state/sqlite-transaction.ts +13 -0
- package/src/state/sqlite.ts +21 -1
- package/src/state/store.ts +5 -1
- package/src/tui/app.mjs +32 -19
- package/src/tui/config.mjs +12 -4
- package/src/tui/i18n.mjs +38 -0
- package/src/tui/info-app.mjs +50 -51
- package/src/tui/info-content.mjs +79 -44
- package/src/tui/join-app.mjs +9 -9
- package/src/tui/locales/en.mjs +349 -0
- package/src/tui/locales/zh-CN.mjs +349 -0
- package/src/tui/main.mjs +85 -37
- package/src/tui/markdown.mjs +3 -2
- package/src/tui/mentions.mjs +3 -1
- package/src/tui/message-app.mjs +22 -21
- package/src/tui/message-view.mjs +2 -1
- package/src/tui/palette-app.mjs +9 -8
- package/src/tui/palette.mjs +30 -24
- package/src/tui/prefs.mjs +92 -0
- package/src/tui/reminder-app.mjs +18 -17
- package/src/tui/room-settings-app.mjs +30 -28
- package/src/tui/settings-app.mjs +153 -0
- package/src/tui/ui-content.mjs +65 -86
- package/src/tui/ui-help.mjs +73 -0
- package/src/tui/ui-overlay-view.mjs +23 -7
- package/src/tui/ui-suggest.mjs +6 -5
- package/src/tui/ui-theme.mjs +37 -33
- package/src/tui/ui-view.mjs +22 -7
- package/src/tui/ui.mjs +15 -3
- package/src/web/editor.worker.ts +1 -0
- package/src/web/integration-rules-editor.ts +573 -0
- package/src/web/integration-rules.ts +26 -0
- package/src/web/integration-schema.ts +229 -0
- package/src/web/json.worker.ts +1 -0
- package/src/web/office-viewer.ts +221 -0
- package/packages/chat-room-channeld/dist/feishu-adapter.js +0 -499
- package/packages/chat-room-channeld/src/feishu-adapter.ts +0 -473
- package/server/assets/chat/forward.js +0 -69
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// Channel D attachments: chatroom resources become local files for the adapter,
|
|
2
|
+
// and adapter-downloaded files become chatroom resources for the room.
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { createReadStream, createWriteStream } from "node:fs";
|
|
5
|
+
import { promises as fs } from "node:fs";
|
|
6
|
+
import os from "node:os";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { Readable } from "node:stream";
|
|
9
|
+
import { pipeline } from "node:stream/promises";
|
|
10
|
+
import type { AdapterCapabilities, AttachmentRef, IngestEvent } from "../packages/chat-room-channeld/src/protocol.ts";
|
|
11
|
+
import { platformLabel } from "../packages/chat-room-channeld/src/inbound.ts";
|
|
12
|
+
import { findResource, maxResourceBytes, openResource, uploadResource } from "../src/rooms/resources.ts";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Resources referenced by a room message marker. The message text stays the
|
|
16
|
+
* source of truth: an attachment that was uploaded but never mentioned is not
|
|
17
|
+
* forwarded.
|
|
18
|
+
*/
|
|
19
|
+
export async function forwardAttachments(roomId: string, text: string): Promise<AttachmentRef[]> {
|
|
20
|
+
const ids = [...text.matchAll(/\[\[resource:([0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})\]\]/gi)]
|
|
21
|
+
.map((match) => match[1]!)
|
|
22
|
+
.filter((id, index, all) => all.indexOf(id) === index);
|
|
23
|
+
const attachments: AttachmentRef[] = [];
|
|
24
|
+
for (const id of ids) {
|
|
25
|
+
const resource = await findResource(roomId, id).catch(() => undefined);
|
|
26
|
+
if (!resource) {
|
|
27
|
+
attachments.push({ kind: "file", name: "attachment", error: "resource unavailable" });
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
attachments.push({
|
|
31
|
+
kind: resource.mimeType.startsWith("image/") ? "image" : "file",
|
|
32
|
+
name: resource.name,
|
|
33
|
+
mimeType: resource.mimeType,
|
|
34
|
+
size: resource.size,
|
|
35
|
+
resourceId: resource.id,
|
|
36
|
+
roomId,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return attachments;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Turn chatroom resource ids into local files for the adapter. Channel D runs
|
|
44
|
+
* adapters as child processes on the same host, so a path is cheaper and less
|
|
45
|
+
* fragile than moving megabytes through the JSON frame.
|
|
46
|
+
*/
|
|
47
|
+
export async function prepareSendPayload(
|
|
48
|
+
payload: unknown,
|
|
49
|
+
capabilities?: AdapterCapabilities,
|
|
50
|
+
): Promise<{ payload: unknown; cleanup?: () => Promise<void> }> {
|
|
51
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) return { payload };
|
|
52
|
+
const attachments = (payload as { attachments?: unknown }).attachments;
|
|
53
|
+
if (!Array.isArray(attachments) || attachments.length === 0) return { payload };
|
|
54
|
+
|
|
55
|
+
const directory = await fs.mkdtemp(path.join(os.tmpdir(), "chat-room-outbound-"));
|
|
56
|
+
const files: AttachmentRef[] = [];
|
|
57
|
+
for (const raw of attachments) {
|
|
58
|
+
if (!raw || typeof raw !== "object") continue;
|
|
59
|
+
const attachment = raw as AttachmentRef;
|
|
60
|
+
if (!attachment.resourceId || !attachment.roomId) {
|
|
61
|
+
files.push(attachment);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const resource = await findResource(attachment.roomId, attachment.resourceId);
|
|
66
|
+
if (!resource) throw new Error("resource not found");
|
|
67
|
+
const limit = resource.mimeType.startsWith("image/")
|
|
68
|
+
? capabilities?.attachments?.imageMaxBytes
|
|
69
|
+
: capabilities?.attachments?.fileMaxBytes;
|
|
70
|
+
if (limit !== undefined && resource.size > limit) throw new Error(`exceeds adapter attachment limit (${limit} bytes)`);
|
|
71
|
+
const opened = await openResource(resource);
|
|
72
|
+
if (!opened) throw new Error("resource content is missing");
|
|
73
|
+
const extension = path.extname(resource.name).toLowerCase();
|
|
74
|
+
const file = path.join(directory, `${resource.id}${/^\.[a-z0-9]{1,10}$/.test(extension) ? extension : ".bin"}`);
|
|
75
|
+
await pipeline(Readable.fromWeb(opened.stream as unknown as import("node:stream/web").ReadableStream), createWriteStream(file, { mode: 0o600 }));
|
|
76
|
+
files.push({ ...attachment, name: resource.name, mimeType: resource.mimeType, size: resource.size, path: file });
|
|
77
|
+
} catch (error) {
|
|
78
|
+
files.push({ ...attachment, error: error instanceof Error ? error.message : String(error) });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
payload: { ...(payload as Record<string, unknown>), attachments: files },
|
|
83
|
+
cleanup: () => fs.rm(directory, { recursive: true, force: true }),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Reuse one resource id per event, room, and attachment so a retry cannot duplicate it. */
|
|
88
|
+
function stableResourceID(eventId: string, roomId: string, index: number): string {
|
|
89
|
+
const hex = createHash("sha256").update(`${eventId}:${roomId}:${index}`).digest("hex");
|
|
90
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-5${hex.slice(13, 16)}-a${hex.slice(17, 20)}-${hex.slice(20, 32)}`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Adapter downloads live in a private temp directory. Only accept that shape so
|
|
95
|
+
* an adapter cannot ask the server to import an arbitrary local file.
|
|
96
|
+
*/
|
|
97
|
+
function readableAdapterFile(value: unknown): string | undefined {
|
|
98
|
+
if (typeof value !== "string" || !path.isAbsolute(value)) return undefined;
|
|
99
|
+
const prefix = path.join(os.tmpdir(), "chat-room-channeld-");
|
|
100
|
+
return path.resolve(value).startsWith(prefix) ? path.resolve(value) : undefined;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export async function inboundAttachments(event: IngestEvent, roomId: string): Promise<string[]> {
|
|
104
|
+
const attachments = event.content?.attachments ?? [];
|
|
105
|
+
const markers: string[] = [];
|
|
106
|
+
for (const [index, attachment] of attachments.entries()) {
|
|
107
|
+
if (attachment.error) {
|
|
108
|
+
markers.push(`[attachment unavailable: ${attachment.error}]`);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const file = readableAdapterFile(attachment.path);
|
|
112
|
+
if (!file) {
|
|
113
|
+
markers.push("[attachment unavailable: no local file]");
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
const info = await fs.stat(file);
|
|
118
|
+
if (!info.isFile() || info.size > maxResourceBytes()) throw new Error("file is not a regular file within the upload limit");
|
|
119
|
+
const resource = await uploadResource(
|
|
120
|
+
roomId,
|
|
121
|
+
attachment.name || `${attachment.kind}-${index + 1}`,
|
|
122
|
+
Readable.toWeb(createReadStream(file)) as unknown as ReadableStream<Uint8Array>,
|
|
123
|
+
maxResourceBytes(),
|
|
124
|
+
{ sessionID: `channel:${event.source.accountId}`, name: `${platformLabel(event.source.platform)} ${event.source.accountId}` },
|
|
125
|
+
stableResourceID(event.eventId, roomId, index),
|
|
126
|
+
);
|
|
127
|
+
markers.push(`[[resource:${resource.id}]]`);
|
|
128
|
+
} catch (error) {
|
|
129
|
+
markers.push(`[attachment upload failed: ${error instanceof Error ? error.message : String(error)}]`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return markers;
|
|
133
|
+
}
|