omp-superagent 0.1.15 → 0.1.17

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.
@@ -0,0 +1,36 @@
1
+ import { authorizeRoute, type Config } from "../config/config";
2
+ import { routeKey, type Route, type StorePort } from "../contracts";
3
+ import { groupRoom } from "../group/group-policy";
4
+
5
+ export function guildThreadParent(config: Config, source: Route, parent: Route): boolean {
6
+ return config.discord?.allowCrossChannelThreads === true && config.discord.crossChannelThreadScope === "guild"
7
+ && source.platform === "discord" && parent.platform === "discord" && source.guildId !== null
8
+ && source.guildId === parent.guildId && source.accountId === parent.accountId && source.authorityId === parent.authorityId
9
+ && source.channelId !== parent.channelId && parent.threadId === null && parent.topicId === undefined
10
+ && authorizeRoute(config, source) && !groupRoom(config, parent);
11
+ }
12
+
13
+ export function discordWorkThreadKey(threadId: string): string {
14
+ // Gateway reads the same exact source and thread receipt from SQLite.
15
+ return `discord:work-thread:${threadId}`;
16
+ }
17
+
18
+ export function discordWorkThreadOwnerKey(inputId: string): string {
19
+ return `discord:work-thread-owner:${inputId}`;
20
+ }
21
+
22
+ /** Read the exact placement receipt without making it current authorization. */
23
+ export function recordedDiscordWorkThreadSource(store: Pick<StorePort, "getMeta">, route: Route): Route | null {
24
+ if (route.platform !== "discord" || !route.threadId || route.topicId !== undefined) return null;
25
+ const saved = store.getMeta(discordWorkThreadKey(route.threadId));
26
+ if (!saved) return null;
27
+ const binding: { source: Route; route: Route } = JSON.parse(saved);
28
+ return routeKey(binding.route) === routeKey(route) ? binding.source : null;
29
+ }
30
+
31
+ /** Delivery authority for a confirmed native lane thread, never request ingress. */
32
+ export function discordWorkThreadSource(config: Config, store: Pick<StorePort, "getMeta">, route: Route): Route | null {
33
+ if (config.discord?.crossChannelThreadScope !== "guild" || config.discord.allowCrossChannelThreads !== true) return null;
34
+ const source = recordedDiscordWorkThreadSource(store, route);
35
+ return source && guildThreadParent(config, source, { ...route, threadId: null }) ? source : null;
36
+ }