@alexsun-top/opencode-chat-room 0.6.6 → 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 +28 -0
- package/README.md +6 -3
- package/README.zh-CN.md +7 -3
- package/cli.ts +1 -1
- package/docs/administrator-rooms.md +11 -5
- package/index.ts +2 -2
- package/package.json +6 -2
- package/plugin.ts +57 -26
- package/server/admin-routes.ts +15 -7
- package/server/admin-state.ts +2 -2
- package/server/announcement-routes.ts +2 -2
- package/server/assets/attachments.css +25 -0
- package/server/assets/base.css +251 -39
- package/server/assets/chat/admin-badge.js +49 -0
- package/server/assets/chat/admin.js +77 -24
- package/server/assets/chat/announcements.js +27 -11
- package/server/assets/chat/attachment-store.js +106 -0
- package/server/assets/chat/attachments.js +245 -25
- package/server/assets/chat/events.js +56 -12
- package/server/assets/chat/image-zoom.js +141 -0
- package/server/assets/chat/index.js +10 -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 +82 -5
- package/server/assets/chat/members.js +16 -6
- package/server/assets/chat/message-polling.js +158 -0
- package/server/assets/chat/message-window.js +14 -0
- package/server/assets/chat/messages.js +12 -132
- package/server/assets/chat/panels.js +37 -0
- package/server/assets/chat/questions.js +10 -6
- package/server/assets/chat/recall.js +279 -0
- package/server/assets/chat/receipts.js +3 -1
- package/server/assets/chat/reminders.js +67 -9
- package/server/assets/chat/replies.js +1 -1
- package/server/assets/chat/room-list.js +60 -0
- package/server/assets/chat/room-watcher.js +5 -1
- package/server/assets/chat/rooms.js +36 -84
- package/server/assets/chat/shortcuts.js +254 -0
- package/server/assets/chat/state.js +97 -24
- package/server/assets/chat/system-messages.js +28 -7
- package/server/assets/conversation.css +18 -26
- package/server/assets/keyboard-hints.css +51 -0
- package/server/assets/recall.css +29 -0
- package/server/assets/responsive.css +58 -16
- package/server/chat-server.ts +81 -62
- package/server/chat.html +238 -72
- package/server/history-route.ts +1 -1
- package/server/inbox.ts +3 -3
- package/server/join-requests.ts +106 -0
- package/server/member-routes.ts +4 -4
- package/server/message-recall-routes.ts +37 -0
- package/server/newrooms.ts +105 -13
- package/server/resource-routes.ts +19 -5
- package/server/room-join.ts +59 -0
- package/server/room-owner.ts +72 -0
- package/server/room-payload.ts +6 -2
- package/server/room-reminders.ts +3 -3
- package/server/sw.js +2 -0
- package/server/wake.ts +48 -19
- package/skills/chatroom/SKILL.md +35 -1
- package/src/README.md +22 -0
- package/src/{admin-client.ts → agent/admin-client.ts} +39 -9
- package/src/{admin-credentials.ts → agent/admin-credentials.ts} +1 -1
- package/src/{agent-presence.ts → agent/agent-presence.ts} +2 -2
- package/src/{agent-receipts.ts → agent/agent-receipts.ts} +2 -2
- package/src/{announcement-tool.ts → agent/announcement-tool.ts} +2 -2
- package/src/{chatroom-skill.ts → agent/chatroom-skill.ts} +1 -1
- package/src/{center-client.ts → center/center-client.ts} +103 -13
- package/src/{center-inbox.ts → center/center-inbox.ts} +44 -19
- package/src/{center-wake.ts → center/center-wake.ts} +31 -18
- package/src/{mentions.ts → center/mentions.ts} +1 -1
- package/src/center/message-ids.ts +7 -0
- package/src/center/notification-budget.ts +16 -0
- package/src/{queue-transport.ts → center/queue-transport.ts} +3 -3
- package/src/{queue.ts → center/queue.ts} +16 -6
- package/src/{reminder-client.ts → center/reminder-client.ts} +1 -1
- package/src/{session-delivery.ts → center/session-delivery.ts} +1 -1
- package/src/{announcements.ts → rooms/announcements.ts} +2 -2
- package/src/{resource-upload.ts → rooms/resource-upload.ts} +1 -1
- package/src/{resources.ts → rooms/resources.ts} +55 -9
- package/src/{room-service.ts → rooms/room-service.ts} +22 -2
- package/src/{background.ts → runtime/background.ts} +3 -3
- package/src/{plugin-notifications.ts → runtime/plugin-notifications.ts} +45 -19
- package/src/{v1-plugin.ts → runtime/v1-plugin.ts} +4 -4
- package/src/{v2-plugin.ts → runtime/v2-plugin.ts} +10 -10
- package/src/{v2-receiver.ts → runtime/v2-receiver.ts} +7 -7
- package/src/{watch.ts → runtime/watch.ts} +12 -12
- package/src/{member-state.ts → state/member-state.ts} +2 -2
- package/src/state/roles.ts +34 -0
- package/src/{sqlite-state.ts → state/sqlite-state.ts} +226 -37
- package/src/{store.ts → state/store.ts} +23 -4
- package/src/tests/announcement-board.ts +185 -0
- /package/src/{resource-read.ts → rooms/resource-read.ts} +0 -0
- /package/src/{receiver-owner.ts → state/receiver-owner.ts} +0 -0
- /package/src/{receiver-state.ts → state/receiver-state.ts} +0 -0
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { promises as fs } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import type { Message } from "
|
|
3
|
+
import type { Message } from "../rooms/room-service.ts";
|
|
4
4
|
import {
|
|
5
5
|
formatNotificationLines,
|
|
6
6
|
loadRegistry,
|
|
7
7
|
loadRooms,
|
|
8
8
|
readQuestionExcerpt,
|
|
9
|
+
recalledMessageIDs,
|
|
9
10
|
statePath,
|
|
10
11
|
timeOf,
|
|
11
|
-
} from "
|
|
12
|
-
import { backgroundResult, backgroundServiceKey, sendAsyncNotification, sendQueue, type BackgroundResult, type QueueTransport } from "
|
|
13
|
-
import { explicitlyAddresses } from "
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
12
|
+
} from "../state/store.ts";
|
|
13
|
+
import { backgroundResult, backgroundServiceKey, sendAsyncNotification, sendQueue, type BackgroundResult, type QueueTransport } from "../center/queue-transport.ts";
|
|
14
|
+
import { explicitlyAddresses } from "../center/mentions.ts";
|
|
15
|
+
import { withMessageIds } from "../center/message-ids.ts";
|
|
16
|
+
import { notificationPrefix } from "../center/notification-budget.ts";
|
|
17
|
+
import { claimBackgroundAttempt } from "../state/receiver-state.ts";
|
|
18
|
+
import { serializeSessionPush } from "../center/center-inbox.ts";
|
|
19
|
+
import { prepareReceiptCandidate, receiptDestination } from "../agent/agent-receipts.ts";
|
|
17
20
|
import {
|
|
18
21
|
getOrCreatePendingAdmission,
|
|
19
22
|
clearPendingAdmission,
|
|
@@ -22,7 +25,7 @@ import {
|
|
|
22
25
|
rejectPendingAdmission,
|
|
23
26
|
prunePendingAdmission,
|
|
24
27
|
type QueueItem,
|
|
25
|
-
} from "
|
|
28
|
+
} from "../center/queue.ts";
|
|
26
29
|
|
|
27
30
|
type NotifyBatch = { roomId: string; roomName: string; roomKind?: "group" | "direct"; messages: Message[] };
|
|
28
31
|
type NotifyAttempt = { url: string; status: number };
|
|
@@ -75,10 +78,13 @@ export function createNotifier(deps: {
|
|
|
75
78
|
batch: NotifyBatch,
|
|
76
79
|
transport: QueueTransport,
|
|
77
80
|
): Promise<NotifyAttempt | undefined> {
|
|
78
|
-
batch = { ...batch, messages: await Promise.all(batch.messages.map(async (message) => message.answerToMessageID
|
|
79
|
-
? { ...message, answerQuestionExcerpt: await readQuestionExcerpt(batch.roomId, message.answerToMessageID) }
|
|
80
|
-
: message)) };
|
|
81
81
|
const [registry, rooms] = await Promise.all([loadRegistry(), loadRooms()]);
|
|
82
|
+
// Recheck against the current room snapshot: a recall may land after the
|
|
83
|
+
// notifier batch was captured but before this delivery attempt.
|
|
84
|
+
const fresh = new Map((rooms.find((room) => room.id === batch.roomId)?.messages ?? []).map((message) => [message.id, message]));
|
|
85
|
+
batch = { ...batch, messages: (await Promise.all(batch.messages.map(async (message) => message.answerToMessageID
|
|
86
|
+
? { ...message, answerQuestionExcerpt: await readQuestionExcerpt(batch.roomId, message.answerToMessageID) }
|
|
87
|
+
: message))).filter((message) => !message.recalledAt && !fresh.get(message.id)?.recalledAt) };
|
|
82
88
|
const entry = registry[batch.roomId]?.[sessionID];
|
|
83
89
|
const roomKind = batch.roomKind ?? rooms.find((room) => room.id === batch.roomId)?.kind ?? "group";
|
|
84
90
|
if (!entry || (entry.protocol !== "v2" && !entry.serverUrl)) return undefined;
|
|
@@ -95,7 +101,14 @@ export function createNotifier(deps: {
|
|
|
95
101
|
};
|
|
96
102
|
const service = backgroundServiceKey(targetTransport);
|
|
97
103
|
const cutoff = Math.max(entry.lastReadTs ?? 0, entry.lastQueuedTs ?? 0);
|
|
98
|
-
|
|
104
|
+
// The room snapshot is the recall authority. A trigger batch may be only a
|
|
105
|
+
// small delta, so an ID missing from it does not mean the message is gone.
|
|
106
|
+
// The snapshot window is bounded, so ask the store for older pending IDs.
|
|
107
|
+
const missingIDs = (pendingAdmission(sessionID, batch.roomId)?.items ?? [])
|
|
108
|
+
.map((item) => item.id).filter((id): id is string => !!id && !fresh.has(id));
|
|
109
|
+
const recalledIDs = missingIDs.length ? await recalledMessageIDs(batch.roomId, missingIDs) : new Set<string>();
|
|
110
|
+
prunePendingAdmission(sessionID, batch.roomId, cutoff, (items) => render(batch, entry.name, roomKind, items),
|
|
111
|
+
(item) => !item.id || (!fresh.get(item.id)?.recalledAt && !recalledIDs.has(item.id)));
|
|
99
112
|
const unreadAll = batch.messages.filter((m) =>
|
|
100
113
|
m.createdAt > cutoff &&
|
|
101
114
|
(m.senderSessionID !== undefined ? m.senderSessionID !== sessionID : m.senderId !== (roomKind === "direct" ? sessionID : entry.name)),
|
|
@@ -103,9 +116,11 @@ export function createNotifier(deps: {
|
|
|
103
116
|
const unread = unreadAll.slice(-20).map((item) => ({ ...item, roomKind }));
|
|
104
117
|
const existing = pendingAdmission(sessionID, batch.roomId);
|
|
105
118
|
if (!unread.length && existing?.state !== "pending") return undefined;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
119
|
+
// An admitted prompt only covers the items it carried; older unread items
|
|
120
|
+
// that surface later still need delivery, below its watermark or not.
|
|
121
|
+
const deliveredIDs = new Set(existing?.state === "admitted" ? existing.items.map((item) => item.id) : []);
|
|
122
|
+
const delta = existing?.state === "admitted"
|
|
123
|
+
? unread.filter((message) => message.createdAt > existing.maxTs || !deliveredIDs.has(message.id))
|
|
109
124
|
: unread;
|
|
110
125
|
const eligibleItems = existing?.state === "pending" ? existing.items : delta.slice(-20);
|
|
111
126
|
if (mentionOnly && !eligibleItems.some((message) => explicitlyAddresses(message, entry.name, sessionID, roomKind)) &&
|
|
@@ -115,14 +130,25 @@ export function createNotifier(deps: {
|
|
|
115
130
|
const endpoint = entry.protocol === "v2" ? "prompt" : "prompt_async";
|
|
116
131
|
const path = `${prefix ? `/${prefix}` : ""}/session/${encodeURIComponent(sessionID)}/${endpoint}`;
|
|
117
132
|
const url = base ? `${base.origin}${path}` : `opencode://session/${sessionID}/${endpoint}`;
|
|
118
|
-
if (existing?.state === "admitted" &&
|
|
133
|
+
if (existing?.state === "admitted" && !delta.length) {
|
|
119
134
|
if (existing.maxTs > 0) await deps.bumpQueued(batch.roomId, sessionID, existing.maxTs);
|
|
120
135
|
return { url, status: entry.protocol === "v2" ? 200 : 204 };
|
|
121
136
|
}
|
|
122
|
-
|
|
123
|
-
|
|
137
|
+
// Keep an undelivered admission intact when a later trigger carries only
|
|
138
|
+
// newer messages; the retry goes out first and the new delta follows.
|
|
139
|
+
const carried = existing?.state === "pending" ? existing.items : [];
|
|
140
|
+
const carriedIDs = new Set(carried.map((item) => item.id));
|
|
141
|
+
const merged = carried.length
|
|
142
|
+
? [...carried, ...delta.filter((item) => !carriedIDs.has(item.id)).slice(0, Math.max(0, 20 - carried.length))]
|
|
143
|
+
: delta;
|
|
144
|
+
// Only the oldest fitting prefix may move the watermark; anything beyond
|
|
145
|
+
// the line budget stays unread for the next sweep.
|
|
146
|
+
const deliverable = notificationPrefix(merged);
|
|
147
|
+
const displayDelta = withMessageIds(deliverable);
|
|
148
|
+
const { prompt, capped } = render(batch, entry.name, roomKind, displayDelta);
|
|
149
|
+
const deltaTs = deliverable.reduce((max, m) => Math.max(max, m.createdAt), 0);
|
|
124
150
|
const admission = getOrCreatePendingAdmission(
|
|
125
|
-
sessionID, batch.roomId,
|
|
151
|
+
sessionID, batch.roomId, displayDelta, prompt, deltaTs, capped,
|
|
126
152
|
);
|
|
127
153
|
if (admission.state === "admitted" && deltaTs <= admission.maxTs) {
|
|
128
154
|
await deps.bumpQueued(batch.roomId, sessionID, admission.maxTs);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Config, Plugin, PluginInput, ToolDefinition } from "@opencode-ai/plugin";
|
|
2
|
-
import type { V2Runtime } from "./v2-plugin";
|
|
3
|
-
import type { QueueTransport } from "
|
|
2
|
+
import type { V2Runtime } from "./v2-plugin.ts";
|
|
3
|
+
import type { QueueTransport } from "../center/queue-transport.ts";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { request } from "
|
|
5
|
+
import { request } from "../center/center-client.ts";
|
|
6
6
|
|
|
7
|
-
const bundledSkillsPath = fileURLToPath(new URL("
|
|
7
|
+
const bundledSkillsPath = fileURLToPath(new URL("../../skills", import.meta.url));
|
|
8
8
|
|
|
9
9
|
export function createV1Server(deps: {
|
|
10
10
|
runtime(input: PluginInput, transport: QueueTransport): V2Runtime;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Skill, Plugin } from "@opencode/plugin";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import type { QueueTransport } from "
|
|
4
|
-
import { backgroundOwnSession, discoverVerifiedHost, verifyHostSession } from "./background";
|
|
5
|
-
import { receiverOwnerID } from "
|
|
6
|
-
import { attachV2Receiver } from "./v2-receiver";
|
|
7
|
-
import { observeReceiptContext, receiptDestination } from "
|
|
8
|
-
import { chatroomSkill } from "
|
|
9
|
-
import { adminToolDescription, adminToolSchema } from "
|
|
3
|
+
import type { QueueTransport } from "../center/center-client.ts";
|
|
4
|
+
import { backgroundOwnSession, discoverVerifiedHost, verifyHostSession } from "./background.ts";
|
|
5
|
+
import { receiverOwnerID } from "../state/receiver-owner.ts";
|
|
6
|
+
import { attachV2Receiver } from "./v2-receiver.ts";
|
|
7
|
+
import { observeReceiptContext, receiptDestination } from "../agent/agent-receipts.ts";
|
|
8
|
+
import { chatroomSkill } from "../agent/chatroom-skill.ts";
|
|
9
|
+
import { adminToolDescription, adminToolSchema } from "../agent/admin-client.ts";
|
|
10
10
|
|
|
11
11
|
type CenterOptions = { center: string; token: string; directory?: string };
|
|
12
12
|
export type V2Runtime = {
|
|
@@ -81,7 +81,7 @@ export function createV2Setup(deps: {
|
|
|
81
81
|
});
|
|
82
82
|
toolRegistration = await context.tool.transform((editor) => editor.add({
|
|
83
83
|
name: "room",
|
|
84
|
-
description: "Chat room operations: create, join, leave and list rooms; send and poll messages; list members and announcements; manage reminders. Reminder schedules use the server timezone unless an IANA timezone is provided; once schedules require an ISO datetime. Upload files and media; upload_resource returns a [[resource:UUID]] marker, and the attachment renders only when that exact marker is included in a send message. read_resource saves files to a private temporary path and leaves them there until removed or system cleanup.",
|
|
84
|
+
description: "Chat room operations: create, join, leave and list rooms; send and poll messages; list members and announcements; manage reminders. Reminder schedules use the server timezone unless an IANA timezone is provided; once schedules require an ISO datetime. Upload files and media; upload_resource returns a [[resource:UUID]] marker, and the attachment renders only when that exact marker is included in a send message. read_resource saves files to a private temporary path and leaves them there until removed or system cleanup. delete_resource removes an uploaded file; servers allow human room administrators any resource and agents only their own uploads.",
|
|
85
85
|
options: { codemode: false },
|
|
86
86
|
input: roomSchema(),
|
|
87
87
|
execute: async (args, toolContext) => {
|
|
@@ -169,12 +169,12 @@ export function createV2Setup(deps: {
|
|
|
169
169
|
|
|
170
170
|
export function roomSchema() {
|
|
171
171
|
return z.object({
|
|
172
|
-
action: z.enum(["create", "join", "leave", "list", "send", "poll", "members", "upload_resource", "read_resource", "announcement_list", "announcement_read", "announcement_write", "announcement_delete", "reminder_list", "reminder_create", "reminder_update", "reminder_delete"]),
|
|
172
|
+
action: z.enum(["create", "join", "leave", "list", "send", "poll", "members", "upload_resource", "read_resource", "delete_resource", "announcement_list", "announcement_read", "announcement_write", "announcement_delete", "reminder_list", "reminder_create", "reminder_update", "reminder_delete"]),
|
|
173
173
|
name: z.string().max(64).optional().describe("For join: your own participant display name, NOT the room name (required). For create: the new room name."),
|
|
174
174
|
roomId: z.string().optional(),
|
|
175
175
|
resourceId: z.string().optional(),
|
|
176
176
|
filePath: z.string().optional().describe("Local regular file to upload; central mode only; requires host read permission."),
|
|
177
|
-
text: z.string().max(
|
|
177
|
+
text: z.string().max(5000).optional(),
|
|
178
178
|
isQuestion: z.boolean().optional(),
|
|
179
179
|
announcementName: z.string().optional().describe("Name of a room announcement; distinct from participant or room name."),
|
|
180
180
|
content: z.string().optional().describe("Announcement content, at most 5000 Unicode characters."),
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { backgroundOwnSession, discoverVerifiedHost } from "./background";
|
|
1
|
+
import { backgroundOwnSession, discoverVerifiedHost } from "./background.ts";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
|
-
import { receiverOwnerID } from "
|
|
4
|
-
import { loadRegistry } from "
|
|
5
|
-
import { request, type CenterOpts } from "
|
|
6
|
-
import type { QueueTransport } from "
|
|
7
|
-
import { locallyOwnedSessions, reportAgentPresence } from "
|
|
8
|
-
import { flushReceiptCandidates, receiptDestination } from "
|
|
3
|
+
import { receiverOwnerID } from "../state/receiver-owner.ts";
|
|
4
|
+
import { loadRegistry } from "../state/store.ts";
|
|
5
|
+
import { request, type CenterOpts } from "../center/center-client.ts";
|
|
6
|
+
import type { QueueTransport } from "../center/queue-transport.ts";
|
|
7
|
+
import { locallyOwnedSessions, reportAgentPresence } from "../agent/agent-presence.ts";
|
|
8
|
+
import { flushReceiptCandidates, receiptDestination } from "../agent/agent-receipts.ts";
|
|
9
9
|
|
|
10
10
|
export type Attachment = {
|
|
11
11
|
sessions: ReadonlySet<string>;
|
|
@@ -5,17 +5,17 @@ import { spawn } from "node:child_process";
|
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import os from "node:os";
|
|
7
7
|
import path from "node:path";
|
|
8
|
-
import { backgroundAtCompatibleRegisteredHost, discoverCompatibleRegisteredHost } from "./background";
|
|
9
|
-
import { receiverOwnerID } from "
|
|
10
|
-
import { claimWatcher, closeReceiverState, releaseWatcherClaim, receiverStateDirectory, watcherProcessMayExist } from "
|
|
11
|
-
import { databasePath, loadRegistry } from "
|
|
12
|
-
import { request, type CenterOpts } from "
|
|
13
|
-
import { assertDeliveryLease } from "
|
|
14
|
-
import type { QueueTransport } from "
|
|
15
|
-
import { pollOwnedSessions } from "./v2-receiver";
|
|
16
|
-
import { pollKnownSessions } from "
|
|
17
|
-
import { locallyOwnedSessions, reportAgentPresence } from "
|
|
18
|
-
import { flushReceiptCandidates, receiptDestination } from "
|
|
8
|
+
import { backgroundAtCompatibleRegisteredHost, discoverCompatibleRegisteredHost } from "./background.ts";
|
|
9
|
+
import { receiverOwnerID } from "../state/receiver-owner.ts";
|
|
10
|
+
import { claimWatcher, closeReceiverState, releaseWatcherClaim, receiverStateDirectory, watcherProcessMayExist } from "../state/receiver-state.ts";
|
|
11
|
+
import { databasePath, loadRegistry } from "../state/store.ts";
|
|
12
|
+
import { request, type CenterOpts } from "../center/center-client.ts";
|
|
13
|
+
import { assertDeliveryLease } from "../center/session-delivery.ts";
|
|
14
|
+
import type { QueueTransport } from "../center/queue-transport.ts";
|
|
15
|
+
import { pollOwnedSessions } from "./v2-receiver.ts";
|
|
16
|
+
import { pollKnownSessions } from "../../plugin";
|
|
17
|
+
import { locallyOwnedSessions, reportAgentPresence } from "../agent/agent-presence.ts";
|
|
18
|
+
import { flushReceiptCandidates, receiptDestination } from "../agent/agent-receipts.ts";
|
|
19
19
|
|
|
20
20
|
type WatchRecord = { phase: "starting" | "running"; token: string; nonce: string; instanceID: string; pid: number; port?: number; createdAt?: number };
|
|
21
21
|
function canonicalPath(value: string): string {
|
|
@@ -236,7 +236,7 @@ export async function startWatcher(beforePublish?: () => Promise<void>): Promise
|
|
|
236
236
|
}
|
|
237
237
|
throw new Error("watcher state exists or is starting; no process was signaled");
|
|
238
238
|
}
|
|
239
|
-
const cli = fileURLToPath(new URL("
|
|
239
|
+
const cli = fileURLToPath(new URL("../../cli.ts", import.meta.url));
|
|
240
240
|
let childError: Error | undefined;
|
|
241
241
|
const child = spawn(process.execPath, [path.resolve(cli), "watch", "run"], {
|
|
242
242
|
detached: true, stdio: "ignore",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { RegistryEntry, WorkState } from "./store";
|
|
1
|
+
import type { RegistryEntry, WorkState } from "./store.ts";
|
|
2
2
|
|
|
3
|
-
export type { WorkState } from "./store";
|
|
3
|
+
export type { WorkState } from "./store.ts";
|
|
4
4
|
export type ActivityState = WorkState | "offline";
|
|
5
5
|
export const PRESENCE_TTL_MS = 60_000;
|
|
6
6
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type RoleRoom = {
|
|
2
|
+
ownerId: string;
|
|
3
|
+
ownerMembershipID?: string;
|
|
4
|
+
adminIds?: string[];
|
|
5
|
+
adminMembershipIDs?: string[];
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type RoleEntry = {
|
|
9
|
+
name?: string | null;
|
|
10
|
+
protocol?: string | null;
|
|
11
|
+
host?: string | null;
|
|
12
|
+
receiverOwnerID?: string | null;
|
|
13
|
+
membershipID?: string | null;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// Agents carry a protocol (v1/v2), a host, or a receiver binding; only a person may
|
|
17
|
+
// own a room, so any of those fields marks an entry that must never be promoted.
|
|
18
|
+
export function isUser(entry: RoleEntry | undefined | null): boolean {
|
|
19
|
+
return Boolean(entry?.name) && !entry!.protocol && !entry!.host && !entry!.receiverOwnerID;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// The owner is a person bound to a server-issued membership. The display name is
|
|
23
|
+
// only for presentation: a new session that reuses the name must not inherit the room.
|
|
24
|
+
export function isOwnerEntry(room: RoleRoom, entry: RoleEntry | null | undefined): boolean {
|
|
25
|
+
return isUser(entry) && entry!.name === room.ownerId &&
|
|
26
|
+
(!room.ownerMembershipID || entry!.membershipID === room.ownerMembershipID);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function isRoomAdmin(room: RoleRoom, entry: RoleEntry | null | undefined): boolean {
|
|
30
|
+
if (isOwnerEntry(room, entry)) return true;
|
|
31
|
+
if (!isUser(entry) || !(room.adminIds ?? []).includes(entry!.name!)) return false;
|
|
32
|
+
if (!room.adminMembershipIDs?.length) return true;
|
|
33
|
+
return !entry!.membershipID || room.adminMembershipIDs.includes(entry!.membershipID);
|
|
34
|
+
}
|