@voltro/plugin-chat 0.89.2 → 0.90.0
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 +1822 -0
- package/README.md +16 -507
- package/THIRD-PARTY-NOTICES.md +2 -2
- package/dist/components.js +160 -149
- package/dist/index.d.ts +66 -1
- package/dist/index.js +93 -66
- package/dist/inspect.js +25 -24
- package/dist/messageLinks.js +29 -0
- package/dist/rpc.d.ts +14 -0
- package/dist/rpc.js +22 -2
- package/dist/server.d.ts +3 -0
- package/dist/server.js +6 -5
- package/dist/service.js +596 -509
- package/dist/strategies.d.ts +34 -0
- package/dist/voice.js +76 -0
- package/dist/web.d.ts +49 -4
- package/dist/web.js +11 -10
- package/package.json +17 -17
package/dist/strategies.d.ts
CHANGED
|
@@ -84,6 +84,8 @@ export declare interface ChatOptions {
|
|
|
84
84
|
readonly mediaUrlTtlSec?: number;
|
|
85
85
|
readonly rateLimit?: RedisStoreOptions;
|
|
86
86
|
readonly now?: () => number;
|
|
87
|
+
/** Voice chat signalling for a third-party SFU (`liveKitVoiceProvider`, `devVoiceProvider`). */
|
|
88
|
+
readonly voice?: ChatVoiceOptions;
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
export declare interface ChatRateInput {
|
|
@@ -100,6 +102,38 @@ export declare interface ChatStrategies {
|
|
|
100
102
|
readonly moderateMedia: typeof typedChatMedia;
|
|
101
103
|
}
|
|
102
104
|
|
|
105
|
+
declare interface ChatVoiceGrant {
|
|
106
|
+
/** The provider's room name for this channel. */
|
|
107
|
+
readonly room: string;
|
|
108
|
+
/** The player's identity in the voice room (their subject ID). */
|
|
109
|
+
readonly identity: string;
|
|
110
|
+
readonly canPublish: boolean;
|
|
111
|
+
readonly ttlSeconds: number;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
declare interface ChatVoiceOptions {
|
|
115
|
+
readonly provider: ChatVoiceProvider;
|
|
116
|
+
/** Token lifetime (default 600 s, 30 to 3600). The client asks again to stay longer. */
|
|
117
|
+
readonly ttlSeconds?: number | undefined;
|
|
118
|
+
/** The provider room for a channel (default `<tenantId>:<channelId>`). */
|
|
119
|
+
readonly room?: ((input: {
|
|
120
|
+
readonly tenantId: string;
|
|
121
|
+
readonly channelId: string;
|
|
122
|
+
}) => string) | undefined;
|
|
123
|
+
readonly now?: (() => number) | undefined;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
declare interface ChatVoiceProvider {
|
|
127
|
+
readonly name: string;
|
|
128
|
+
readonly mint: (grant: ChatVoiceGrant) => Effect.Effect<ChatVoiceTicket, unknown>;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
declare interface ChatVoiceTicket {
|
|
132
|
+
readonly url: string;
|
|
133
|
+
readonly token: string;
|
|
134
|
+
readonly expiresAt: number;
|
|
135
|
+
}
|
|
136
|
+
|
|
103
137
|
export declare const defaultChatStrategies: ChatStrategies;
|
|
104
138
|
|
|
105
139
|
export declare const fixedChatRateBudgets: (input: ChatRateInput) => {
|
package/dist/voice.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { chatError as e } from "./errors.js";
|
|
2
|
+
import { Effect as t } from "effect";
|
|
3
|
+
import { createHmac as n } from "node:crypto";
|
|
4
|
+
// src/voice.ts
|
|
5
|
+
var r = (e) => Buffer.from(e).toString("base64url"), i = (i) => {
|
|
6
|
+
if (!i || !/^wss?:\/\//.test(i.url ?? "") || typeof i.apiKey != "string" || !i.apiKey || typeof i.apiSecret != "string" || i.apiSecret.length < 32) throw e("invalid_input");
|
|
7
|
+
let a = i.now ?? Date.now, o = r(JSON.stringify({
|
|
8
|
+
alg: "HS256",
|
|
9
|
+
typ: "JWT"
|
|
10
|
+
}));
|
|
11
|
+
return Object.freeze({
|
|
12
|
+
name: "livekit",
|
|
13
|
+
mint: (e) => t.sync(() => {
|
|
14
|
+
let t = Math.floor(a() / 1e3), s = t + e.ttlSeconds, c = r(JSON.stringify({
|
|
15
|
+
iss: i.apiKey,
|
|
16
|
+
sub: e.identity,
|
|
17
|
+
nbf: t,
|
|
18
|
+
exp: s,
|
|
19
|
+
video: {
|
|
20
|
+
room: e.room,
|
|
21
|
+
roomJoin: !0,
|
|
22
|
+
canPublish: e.canPublish,
|
|
23
|
+
canSubscribe: !0,
|
|
24
|
+
canPublishData: e.canPublish
|
|
25
|
+
}
|
|
26
|
+
})), l = n("sha256", i.apiSecret).update(o + "." + c).digest("base64url");
|
|
27
|
+
return Object.freeze({
|
|
28
|
+
url: i.url,
|
|
29
|
+
token: o + "." + c + "." + l,
|
|
30
|
+
expiresAt: s * 1e3
|
|
31
|
+
});
|
|
32
|
+
})
|
|
33
|
+
});
|
|
34
|
+
}, a = (e = {}) => {
|
|
35
|
+
let n = e.now ?? Date.now, i = e.url ?? "ws://localhost:7880";
|
|
36
|
+
return Object.freeze({
|
|
37
|
+
name: "dev",
|
|
38
|
+
mint: (e) => t.sync(() => Object.freeze({
|
|
39
|
+
url: i,
|
|
40
|
+
expiresAt: n() + e.ttlSeconds * 1e3,
|
|
41
|
+
token: "dev." + r(JSON.stringify({
|
|
42
|
+
room: e.room,
|
|
43
|
+
identity: e.identity,
|
|
44
|
+
canPublish: e.canPublish
|
|
45
|
+
}))
|
|
46
|
+
}))
|
|
47
|
+
});
|
|
48
|
+
}, o = (n) => {
|
|
49
|
+
if (!n || typeof n.provider?.mint != "function" || typeof n.provider.name != "string" || !n.provider.name) throw e("invalid_input");
|
|
50
|
+
let r = n.ttlSeconds ?? 600, i = n.room ?? (({ tenantId: e, channelId: t }) => e + ":" + t), a = n.now ?? Date.now;
|
|
51
|
+
if (!Number.isSafeInteger(r) || r < 30 || r > 3600 || typeof i != "function") throw e("invalid_input");
|
|
52
|
+
let o = n.provider;
|
|
53
|
+
return Object.freeze({ join: (n, s) => t.suspend(() => {
|
|
54
|
+
if (s.subjectId !== n.subjectId || s.channelId !== n.channelId) return t.fail(e("forbidden"));
|
|
55
|
+
let c = i({
|
|
56
|
+
tenantId: n.tenantId,
|
|
57
|
+
channelId: n.channelId
|
|
58
|
+
});
|
|
59
|
+
if (typeof c != "string" || !c || c.length > 256) return t.fail(e("unavailable"));
|
|
60
|
+
let l = s.mutedUntil === null || s.mutedUntil <= a();
|
|
61
|
+
return t.suspend(() => o.mint({
|
|
62
|
+
room: c,
|
|
63
|
+
identity: n.subjectId,
|
|
64
|
+
canPublish: l,
|
|
65
|
+
ttlSeconds: r
|
|
66
|
+
})).pipe(t.mapError(() => e("unavailable")), t.flatMap((n) => typeof n?.url == "string" && typeof n.token == "string" && Number.isSafeInteger(n.expiresAt) ? t.succeed(Object.freeze({
|
|
67
|
+
provider: o.name,
|
|
68
|
+
room: c,
|
|
69
|
+
canPublish: l,
|
|
70
|
+
url: n.url,
|
|
71
|
+
token: n.token,
|
|
72
|
+
expiresAt: n.expiresAt
|
|
73
|
+
})) : t.fail(e("unavailable"))));
|
|
74
|
+
}) });
|
|
75
|
+
};
|
|
76
|
+
export { a as devVoiceProvider, i as liveKitVoiceProvider, o as resolveChatVoice };
|
package/dist/web.d.ts
CHANGED
|
@@ -98,7 +98,18 @@ declare const ChatMessageSchema: Schema.Struct<{
|
|
|
98
98
|
readonly metadata: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
99
99
|
}>;
|
|
100
100
|
|
|
101
|
-
export declare
|
|
101
|
+
export declare type ChatMessageSegment = {
|
|
102
|
+
readonly kind: 'text';
|
|
103
|
+
readonly text: string;
|
|
104
|
+
} | {
|
|
105
|
+
readonly kind: 'link';
|
|
106
|
+
readonly text: string;
|
|
107
|
+
readonly href: string;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export declare const chatMessageSegments: (body: string, maxLinks?: number) => ReadonlyArray<ChatMessageSegment>;
|
|
111
|
+
|
|
112
|
+
export declare const ChatPanel: ({ scopeKey, dataScopeKey, channelId, messages, authors, labels, locale, loading, onReport, onOpenMedia, selfId, canLoadOlder, onLoadOlder, typing, typingLabels, ...composer }: ChatPanelProps) => ReactNode;
|
|
102
113
|
|
|
103
114
|
export declare interface ChatPanelProps extends MessageListProps, ComposerProps {
|
|
104
115
|
readonly scopeKey: string;
|
|
@@ -168,7 +179,7 @@ declare interface EditChatInput {
|
|
|
168
179
|
}
|
|
169
180
|
|
|
170
181
|
/** Variable-height windowing preserves a focused row and does not move the reader on live updates. */
|
|
171
|
-
export declare const MessageList: ({ messages, authors, labels, locale, loading, onReport, onOpenMedia }: MessageListProps) => ReactNode;
|
|
182
|
+
export declare const MessageList: ({ messages, authors, labels, locale, loading, onReport, onOpenMedia, selfId }: MessageListProps) => ReactNode;
|
|
172
183
|
|
|
173
184
|
export declare interface MessageListProps {
|
|
174
185
|
readonly messages: ReadonlyArray<ChatMessage>;
|
|
@@ -177,6 +188,8 @@ export declare interface MessageListProps {
|
|
|
177
188
|
readonly locale?: string | undefined;
|
|
178
189
|
readonly loading?: boolean | undefined;
|
|
179
190
|
readonly onReport?: ((messageId: string) => void) | undefined;
|
|
191
|
+
/** The viewer's subject ID: their own messages offer no report button. */
|
|
192
|
+
readonly selfId?: string | undefined;
|
|
180
193
|
/** Called for a visible media message; resolve its URL with `chat.mediaUrl` and show it. */
|
|
181
194
|
readonly onOpenMedia?: ((messageId: string) => void) | undefined;
|
|
182
195
|
}
|
|
@@ -246,6 +259,24 @@ export declare const useChatAuthors: (channelId: string, subjectIds: ReadonlyArr
|
|
|
246
259
|
readonly avatar: string | null;
|
|
247
260
|
}[]>;
|
|
248
261
|
|
|
262
|
+
/** Opens (or returns) the direct-message channel with another player; refused when either blocks the other. */
|
|
263
|
+
export declare const useChatDm: (apiName?: string) => ActionState<{
|
|
264
|
+
otherId: string;
|
|
265
|
+
}, {
|
|
266
|
+
readonly id: string;
|
|
267
|
+
readonly kind: "custom" | "match" | "global" | "lobby" | "party" | "guild" | "dm";
|
|
268
|
+
readonly refId: string;
|
|
269
|
+
readonly name: string;
|
|
270
|
+
readonly slowModeMs: number;
|
|
271
|
+
readonly retentionMs: number | null;
|
|
272
|
+
readonly maxMembers: number;
|
|
273
|
+
readonly frozen: boolean;
|
|
274
|
+
readonly createdAt: number;
|
|
275
|
+
readonly metadata: {
|
|
276
|
+
readonly [x: string]: unknown;
|
|
277
|
+
};
|
|
278
|
+
}>;
|
|
279
|
+
|
|
249
280
|
export declare const useChatEdit: (apiName?: string) => ActionState<EditChatInput, unknown>;
|
|
250
281
|
|
|
251
282
|
export declare const useChatJoin: (apiName?: string) => ActionState<{
|
|
@@ -254,7 +285,7 @@ export declare const useChatJoin: (apiName?: string) => ActionState<{
|
|
|
254
285
|
readonly id: string;
|
|
255
286
|
readonly channelId: string;
|
|
256
287
|
readonly subjectId: string;
|
|
257
|
-
readonly role: "
|
|
288
|
+
readonly role: "owner" | "member" | "mod";
|
|
258
289
|
readonly mutedUntil: number | null;
|
|
259
290
|
readonly lastReadAt: number;
|
|
260
291
|
readonly lastReadId: string | null;
|
|
@@ -277,7 +308,7 @@ export declare const useChatMembership: (channelId: string, apiName?: string) =>
|
|
|
277
308
|
readonly id: string;
|
|
278
309
|
readonly channelId: string;
|
|
279
310
|
readonly subjectId: string;
|
|
280
|
-
readonly role: "
|
|
311
|
+
readonly role: "owner" | "member" | "mod";
|
|
281
312
|
readonly mutedUntil: number | null;
|
|
282
313
|
readonly lastReadAt: number;
|
|
283
314
|
readonly lastReadId: string | null;
|
|
@@ -342,6 +373,20 @@ export declare const useChatTransferOwnership: (apiName?: string) => ActionState
|
|
|
342
373
|
|
|
343
374
|
export declare const useChatTypingPublisher: (channelId: string | null, apiName?: string) => ChatTypingPublisherState;
|
|
344
375
|
|
|
376
|
+
/** Voice chat (`chatPlugin({ voice })`): `run({ channelId })` returns the SFU url and a short-lived
|
|
377
|
+
* token for that channel's voice room; connect your SFU client with them. A muted member gets
|
|
378
|
+
* `canPublish: false`. */
|
|
379
|
+
export declare const useChatVoiceJoin: (apiName?: string) => ActionState<{
|
|
380
|
+
readonly channelId: string;
|
|
381
|
+
}, {
|
|
382
|
+
readonly provider: string;
|
|
383
|
+
readonly room: string;
|
|
384
|
+
readonly canPublish: boolean;
|
|
385
|
+
readonly url: string;
|
|
386
|
+
readonly token: string;
|
|
387
|
+
readonly expiresAt: number;
|
|
388
|
+
}>;
|
|
389
|
+
|
|
345
390
|
/** Private hints expire within five local monotonic seconds; never persisted. */
|
|
346
391
|
export declare const useTyping: (channelId: string | null, apiName?: string) => ChatTypingState;
|
|
347
392
|
|
package/dist/web.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { BASE_NAME as e } from "./rpc.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { chatMessageSegments as t } from "./messageLinks.js";
|
|
3
|
+
import { ChannelTabs as n, ChatPanel as r, Composer as i, MessageList as a, TypingIndicator as o, chatLabels as s, chatMentionLabels as c, chatTypingLabels as l } from "./components.js";
|
|
4
|
+
import { useTyping as u } from "./useTyping.js";
|
|
5
|
+
import { useChatTypingPublisher as d } from "./useChatTypingPublisher.js";
|
|
6
|
+
import { pluginTag as f } from "@voltro/protocol";
|
|
7
|
+
import { useAction as p, useSubscription as m } from "@voltro/client";
|
|
7
8
|
// src/web.ts
|
|
8
|
-
var
|
|
9
|
+
var h = (t, n, r = "app") => m(r, f(e, "mentionCandidates"), {
|
|
9
10
|
channelId: t,
|
|
10
11
|
...n === void 0 ? {} : { after: n }
|
|
11
|
-
}),
|
|
12
|
+
}), g = (t, n, r = "app") => m(r, f(e, "authors"), {
|
|
12
13
|
channelId: t,
|
|
13
14
|
subjectIds: n
|
|
14
|
-
}),
|
|
15
|
+
}), _ = (t, n = "app") => m(n, f(e, "channel"), { channelId: t }), v = (t, n = "app") => m(n, f(e, "membership"), { channelId: t }), y = (t = "app") => m(t, f(e, "channels"), {}), b = (t, n, r = "app") => m(r, f(e, "messages"), {
|
|
15
16
|
channelId: t,
|
|
16
17
|
...n === void 0 ? {} : { before: n }
|
|
17
|
-
}),
|
|
18
|
-
export {
|
|
18
|
+
}), x = (t = "app") => p(t, f(e, "send")), S = (t = "app") => p(t, f(e, "edit")), C = (t = "app") => p(t, f(e, "remove")), w = (t = "app") => m(t, f(e, "unread"), {}), T = (t = "app") => p(t, f(e, "markRead")), E = (t = "app") => p(t, f(e, "original")), D = (t = "app") => p(t, f(e, "join")), O = (t = "app") => p(t, f(e, "dm")), k = (t = "app") => p(t, f(e, "leave")), A = (t = "app") => p(t, f(e, "transferOwnership")), j = (t = "app") => p(t, f(e, "setTyping")), M = (t = "app") => p(t, f(e, "voice.join"));
|
|
19
|
+
export { n as ChannelTabs, r as ChatPanel, i as Composer, a as MessageList, o as TypingIndicator, s as chatLabels, c as chatMentionLabels, t as chatMessageSegments, l as chatTypingLabels, _ as useChannel, y as useChannelList, g as useChatAuthors, O as useChatDm, S as useChatEdit, D as useChatJoin, k as useChatLeave, T as useChatMarkRead, v as useChatMembership, h as useChatMentionCandidates, b as useChatMessages, E as useChatOriginal, C as useChatRemove, x as useChatSend, j as useChatSetTyping, A as useChatTransferOwnership, d as useChatTypingPublisher, M as useChatVoiceJoin, u as useTyping, w as useUnread };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltro/plugin-chat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.90.0",
|
|
4
4
|
"description": "Membership-filtered durable chat with configurable moderation, rate and retention strategies",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"voltro",
|
|
@@ -73,22 +73,22 @@
|
|
|
73
73
|
"node": ">=24.0.0"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@voltro/protocol": "0.
|
|
77
|
-
"@voltro/database": "0.
|
|
78
|
-
"@voltro/client": "0.
|
|
79
|
-
"@voltro/runtime": "0.
|
|
80
|
-
"@voltro/plugin-ratelimit": "0.
|
|
81
|
-
"@voltro/plugin-moderation": "0.
|
|
82
|
-
"@voltro/plugin-social": "0.
|
|
83
|
-
"@voltro/plugin-players": "0.
|
|
84
|
-
"@voltro/plugin-notifications": "0.
|
|
85
|
-
"@voltro/kv": "0.
|
|
86
|
-
"@voltro/ui-shadcn": "0.
|
|
87
|
-
"@voltro/plugin-sanctions": "0.
|
|
88
|
-
"@voltro/plugin-licensing": "0.
|
|
89
|
-
"@voltro/plugin-storage": "0.
|
|
90
|
-
"@voltro/plugin-guilds": "0.
|
|
91
|
-
"@voltro/plugin-matchmaking": "0.
|
|
76
|
+
"@voltro/protocol": "0.90.0",
|
|
77
|
+
"@voltro/database": "0.90.0",
|
|
78
|
+
"@voltro/client": "0.90.0",
|
|
79
|
+
"@voltro/runtime": "0.90.0",
|
|
80
|
+
"@voltro/plugin-ratelimit": "0.90.0",
|
|
81
|
+
"@voltro/plugin-moderation": "0.90.0",
|
|
82
|
+
"@voltro/plugin-social": "0.90.0",
|
|
83
|
+
"@voltro/plugin-players": "0.90.0",
|
|
84
|
+
"@voltro/plugin-notifications": "0.90.0",
|
|
85
|
+
"@voltro/kv": "0.90.0",
|
|
86
|
+
"@voltro/ui-shadcn": "0.90.0",
|
|
87
|
+
"@voltro/plugin-sanctions": "0.90.0",
|
|
88
|
+
"@voltro/plugin-licensing": "0.90.0",
|
|
89
|
+
"@voltro/plugin-storage": "0.90.0",
|
|
90
|
+
"@voltro/plugin-guilds": "0.90.0",
|
|
91
|
+
"@voltro/plugin-matchmaking": "0.90.0"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
94
|
"effect": "4.1.2",
|