@open-everywhere/provider-discord 0.1.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/LICENSE +201 -0
- package/NOTICE +21 -0
- package/README.md +47 -0
- package/agent/access/discord-grant-click.ts +237 -0
- package/agent/approvals/discord-admin.ts +227 -0
- package/agent/approvals/discord-card.ts +248 -0
- package/agent/approvals/discord-flow.ts +469 -0
- package/agent/approvals/discord-scope-label.ts +27 -0
- package/agent/channels/discord-approval-card.ts +373 -0
- package/agent/channels/discord-backscroll.ts +593 -0
- package/agent/channels/discord-bot-name.ts +113 -0
- package/agent/channels/discord-channel-info.ts +83 -0
- package/agent/channels/discord-directory.ts +179 -0
- package/agent/channels/discord-dispatch-target.ts +103 -0
- package/agent/channels/discord-events.ts +175 -0
- package/agent/channels/discord-front.ts +355 -0
- package/agent/channels/discord-gateway.ts +3256 -0
- package/agent/channels/discord-identity.ts +269 -0
- package/agent/channels/discord-interaction-defer.ts +123 -0
- package/agent/channels/discord-message-ops.ts +127 -0
- package/agent/channels/discord-origin-codec.ts +105 -0
- package/agent/channels/discord-post-arm.ts +230 -0
- package/agent/channels/discord-post.ts +463 -0
- package/agent/channels/discord-read.ts +140 -0
- package/agent/channels/discord-rest.ts +85 -0
- package/agent/channels/discord.ts +244 -0
- package/agent/commands/discord-command-sync.ts +285 -0
- package/agent/commands/discord-commands.ts +291 -0
- package/agent/contributions.ts +31 -0
- package/agent/docs-generated.ts +15 -0
- package/agent/identity/discord-link-consent.ts +124 -0
- package/agent/ops.ts +14 -0
- package/agent/provider-events.ts +86 -0
- package/agent/register.ts +147 -0
- package/agent/surface-parity.ts +95 -0
- package/dist/agent/access/discord-grant-click.d.ts +25 -0
- package/dist/agent/access/discord-grant-click.d.ts.map +1 -0
- package/dist/agent/access/discord-grant-click.js +210 -0
- package/dist/agent/access/discord-grant-click.js.map +1 -0
- package/dist/agent/approvals/discord-admin.d.ts +63 -0
- package/dist/agent/approvals/discord-admin.d.ts.map +1 -0
- package/dist/agent/approvals/discord-admin.js +219 -0
- package/dist/agent/approvals/discord-admin.js.map +1 -0
- package/dist/agent/approvals/discord-card.d.ts +102 -0
- package/dist/agent/approvals/discord-card.d.ts.map +1 -0
- package/dist/agent/approvals/discord-card.js +217 -0
- package/dist/agent/approvals/discord-card.js.map +1 -0
- package/dist/agent/approvals/discord-flow.d.ts +109 -0
- package/dist/agent/approvals/discord-flow.d.ts.map +1 -0
- package/dist/agent/approvals/discord-flow.js +375 -0
- package/dist/agent/approvals/discord-flow.js.map +1 -0
- package/dist/agent/approvals/discord-scope-label.d.ts +3 -0
- package/dist/agent/approvals/discord-scope-label.d.ts.map +1 -0
- package/dist/agent/approvals/discord-scope-label.js +27 -0
- package/dist/agent/approvals/discord-scope-label.js.map +1 -0
- package/dist/agent/channels/discord-approval-card.d.ts +81 -0
- package/dist/agent/channels/discord-approval-card.d.ts.map +1 -0
- package/dist/agent/channels/discord-approval-card.js +303 -0
- package/dist/agent/channels/discord-approval-card.js.map +1 -0
- package/dist/agent/channels/discord-backscroll.d.ts +209 -0
- package/dist/agent/channels/discord-backscroll.d.ts.map +1 -0
- package/dist/agent/channels/discord-backscroll.js +505 -0
- package/dist/agent/channels/discord-backscroll.js.map +1 -0
- package/dist/agent/channels/discord-bot-name.d.ts +19 -0
- package/dist/agent/channels/discord-bot-name.d.ts.map +1 -0
- package/dist/agent/channels/discord-bot-name.js +98 -0
- package/dist/agent/channels/discord-bot-name.js.map +1 -0
- package/dist/agent/channels/discord-channel-info.d.ts +22 -0
- package/dist/agent/channels/discord-channel-info.d.ts.map +1 -0
- package/dist/agent/channels/discord-channel-info.js +65 -0
- package/dist/agent/channels/discord-channel-info.js.map +1 -0
- package/dist/agent/channels/discord-directory.d.ts +11 -0
- package/dist/agent/channels/discord-directory.d.ts.map +1 -0
- package/dist/agent/channels/discord-directory.js +170 -0
- package/dist/agent/channels/discord-directory.js.map +1 -0
- package/dist/agent/channels/discord-dispatch-target.d.ts +15 -0
- package/dist/agent/channels/discord-dispatch-target.d.ts.map +1 -0
- package/dist/agent/channels/discord-dispatch-target.js +99 -0
- package/dist/agent/channels/discord-dispatch-target.js.map +1 -0
- package/dist/agent/channels/discord-events.d.ts +58 -0
- package/dist/agent/channels/discord-events.d.ts.map +1 -0
- package/dist/agent/channels/discord-events.js +150 -0
- package/dist/agent/channels/discord-events.js.map +1 -0
- package/dist/agent/channels/discord-front.d.ts +115 -0
- package/dist/agent/channels/discord-front.d.ts.map +1 -0
- package/dist/agent/channels/discord-front.js +279 -0
- package/dist/agent/channels/discord-front.js.map +1 -0
- package/dist/agent/channels/discord-gateway.d.ts +783 -0
- package/dist/agent/channels/discord-gateway.d.ts.map +1 -0
- package/dist/agent/channels/discord-gateway.js +2591 -0
- package/dist/agent/channels/discord-gateway.js.map +1 -0
- package/dist/agent/channels/discord-identity.d.ts +110 -0
- package/dist/agent/channels/discord-identity.d.ts.map +1 -0
- package/dist/agent/channels/discord-identity.js +201 -0
- package/dist/agent/channels/discord-identity.js.map +1 -0
- package/dist/agent/channels/discord-interaction-defer.d.ts +33 -0
- package/dist/agent/channels/discord-interaction-defer.d.ts.map +1 -0
- package/dist/agent/channels/discord-interaction-defer.js +102 -0
- package/dist/agent/channels/discord-interaction-defer.js.map +1 -0
- package/dist/agent/channels/discord-message-ops.d.ts +3 -0
- package/dist/agent/channels/discord-message-ops.d.ts.map +1 -0
- package/dist/agent/channels/discord-message-ops.js +123 -0
- package/dist/agent/channels/discord-message-ops.js.map +1 -0
- package/dist/agent/channels/discord-origin-codec.d.ts +7 -0
- package/dist/agent/channels/discord-origin-codec.d.ts.map +1 -0
- package/dist/agent/channels/discord-origin-codec.js +98 -0
- package/dist/agent/channels/discord-origin-codec.js.map +1 -0
- package/dist/agent/channels/discord-post-arm.d.ts +3 -0
- package/dist/agent/channels/discord-post-arm.d.ts.map +1 -0
- package/dist/agent/channels/discord-post-arm.js +195 -0
- package/dist/agent/channels/discord-post-arm.js.map +1 -0
- package/dist/agent/channels/discord-post.d.ts +120 -0
- package/dist/agent/channels/discord-post.d.ts.map +1 -0
- package/dist/agent/channels/discord-post.js +426 -0
- package/dist/agent/channels/discord-post.js.map +1 -0
- package/dist/agent/channels/discord-read.d.ts +40 -0
- package/dist/agent/channels/discord-read.d.ts.map +1 -0
- package/dist/agent/channels/discord-read.js +128 -0
- package/dist/agent/channels/discord-read.js.map +1 -0
- package/dist/agent/channels/discord-rest.d.ts +33 -0
- package/dist/agent/channels/discord-rest.d.ts.map +1 -0
- package/dist/agent/channels/discord-rest.js +75 -0
- package/dist/agent/channels/discord-rest.js.map +1 -0
- package/dist/agent/channels/discord.d.ts +3 -0
- package/dist/agent/channels/discord.d.ts.map +1 -0
- package/dist/agent/channels/discord.js +230 -0
- package/dist/agent/channels/discord.js.map +1 -0
- package/dist/agent/commands/discord-command-sync.d.ts +66 -0
- package/dist/agent/commands/discord-command-sync.d.ts.map +1 -0
- package/dist/agent/commands/discord-command-sync.js +224 -0
- package/dist/agent/commands/discord-command-sync.js.map +1 -0
- package/dist/agent/commands/discord-commands.d.ts +45 -0
- package/dist/agent/commands/discord-commands.d.ts.map +1 -0
- package/dist/agent/commands/discord-commands.js +266 -0
- package/dist/agent/commands/discord-commands.js.map +1 -0
- package/dist/agent/contributions.d.ts +17 -0
- package/dist/agent/contributions.d.ts.map +1 -0
- package/dist/agent/contributions.js +31 -0
- package/dist/agent/contributions.js.map +1 -0
- package/dist/agent/docs-generated.d.ts +3 -0
- package/dist/agent/docs-generated.d.ts.map +1 -0
- package/dist/agent/docs-generated.js +13 -0
- package/dist/agent/docs-generated.js.map +1 -0
- package/dist/agent/identity/discord-link-consent.d.ts +13 -0
- package/dist/agent/identity/discord-link-consent.d.ts.map +1 -0
- package/dist/agent/identity/discord-link-consent.js +111 -0
- package/dist/agent/identity/discord-link-consent.js.map +1 -0
- package/dist/agent/ops.d.ts +2 -0
- package/dist/agent/ops.d.ts.map +1 -0
- package/dist/agent/ops.js +13 -0
- package/dist/agent/ops.js.map +1 -0
- package/dist/agent/provider-events.d.ts +3 -0
- package/dist/agent/provider-events.d.ts.map +1 -0
- package/dist/agent/provider-events.js +78 -0
- package/dist/agent/provider-events.js.map +1 -0
- package/dist/agent/register.d.ts +5 -0
- package/dist/agent/register.d.ts.map +1 -0
- package/dist/agent/register.js +125 -0
- package/dist/agent/register.js.map +1 -0
- package/dist/agent/surface-parity.d.ts +3 -0
- package/dist/agent/surface-parity.d.ts.map +1 -0
- package/dist/agent/surface-parity.js +90 -0
- package/dist/agent/surface-parity.js.map +1 -0
- package/package.json +185 -0
- package/tsconfig.build.json +22 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// DISCORD's event inventory (OPE-1612). See the core module's header
|
|
2
|
+
// (packages/core/agent/routines/provider-events.ts) for what the three routing states mean.
|
|
3
|
+
//
|
|
4
|
+
// π΄ DISCORD REGISTERS NO EVENT NORMALIZER, so every row is `routing: "none"` and the declaration
|
|
5
|
+
// names no `source`. The rows exist so the gap is legible: the normalizer registry can only
|
|
6
|
+
// enumerate what this deployment already routes, so the events nobody wired are exactly the ones it
|
|
7
|
+
// cannot mention.
|
|
8
|
+
//
|
|
9
|
+
// DISCORD'S TRANSPORT IS THE REASON, AND IT IS A REAL ONE. These are GATEWAY events β a websocket
|
|
10
|
+
// dispatch, not a signed HTTP delivery. The routing plane's ingress is a `TriggerDelivery` with
|
|
11
|
+
// headers and a body that a `WebhookVerifier` made trustworthy, and a gateway frame has neither: the
|
|
12
|
+
// trust comes from the session, not from a signature over the payload. Wiring Discord therefore
|
|
13
|
+
// means deciding what "the declared door with a declared verifier" means for a socket, which is a
|
|
14
|
+
// plane decision rather than a normalizer. The bundle's own gateway transport already carries the
|
|
15
|
+
// message legs it needs.
|
|
16
|
+
|
|
17
|
+
// π΄ THIS LIST IS REVIEWED, NOT EXHAUSTIVE. Discord's gateway dispatch table carries far more event
|
|
18
|
+
// names than the rows below β guild, voice, presence, scheduled-event and auto-moderation families
|
|
19
|
+
// among them. A row reaches this file when somebody read the event and decided what a routine could
|
|
20
|
+
// do with it, so an ABSENT event means "nobody has reviewed it here", never "the vendor does not
|
|
21
|
+
// send it".
|
|
22
|
+
|
|
23
|
+
import type { ProviderEventDeclaration } from "@open-everywhere/core/agent/adapter-api.js";
|
|
24
|
+
|
|
25
|
+
export const DISCORD_PROVIDER_EVENTS: ProviderEventDeclaration = {
|
|
26
|
+
// `source` is ABSENT, not empty β the bundle registers no normalizer, so there is no key to name.
|
|
27
|
+
doc: "https://discord.com/developers/docs/events/gateway-events",
|
|
28
|
+
events: [
|
|
29
|
+
{
|
|
30
|
+
event: "MESSAGE_CREATE",
|
|
31
|
+
routing: "none",
|
|
32
|
+
match: [],
|
|
33
|
+
scope: [],
|
|
34
|
+
note: "a message was sent in a channel; the bundle's own gateway transport reads it for the mention and ambient legs, never the routine plane",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
event: "MESSAGE_UPDATE",
|
|
38
|
+
routing: "none",
|
|
39
|
+
match: [],
|
|
40
|
+
scope: [],
|
|
41
|
+
note: "a message was edited; unwired",
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
event: "MESSAGE_DELETE",
|
|
45
|
+
routing: "none",
|
|
46
|
+
match: [],
|
|
47
|
+
scope: [],
|
|
48
|
+
note: "a message was deleted; unwired",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
event: "MESSAGE_REACTION_ADD",
|
|
52
|
+
routing: "none",
|
|
53
|
+
match: [],
|
|
54
|
+
scope: [],
|
|
55
|
+
note: "somebody reacted to a message; the reaction-feedback plane reads it, and a routine could not tell its own ack glyphs from a person's",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
event: "MESSAGE_REACTION_REMOVE",
|
|
59
|
+
routing: "none",
|
|
60
|
+
match: [],
|
|
61
|
+
scope: [],
|
|
62
|
+
note: "a reaction was taken off a message; unwired for the same reason as `MESSAGE_REACTION_ADD`",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
event: "THREAD_CREATE",
|
|
66
|
+
routing: "none",
|
|
67
|
+
match: [],
|
|
68
|
+
scope: [],
|
|
69
|
+
note: "a thread was started; unwired β a candidate trigger, since a new thread is work appearing rather than chatter",
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
event: "GUILD_MEMBER_ADD",
|
|
73
|
+
routing: "none",
|
|
74
|
+
match: [],
|
|
75
|
+
scope: [],
|
|
76
|
+
note: "somebody joined the guild; unwired β an onboarding routine would want this one",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
event: "INTERACTION_CREATE",
|
|
80
|
+
routing: "none",
|
|
81
|
+
match: [],
|
|
82
|
+
scope: [],
|
|
83
|
+
note: "a slash command or component interaction; unwired, and a poor routine trigger β an interaction owes Discord a reply within three seconds, which a fired seat cannot promise",
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// registerDiscordProvider β the ONE boot entry of @open-everywhere/provider-discord (OPE-114 stage 4,
|
|
2
|
+
// the second extracted provider bundle, and the deepest-integrated one β a custom gateway webhook
|
|
3
|
+
// transport, admin approval CARDS, a guild-admin spend bypass, and routine dispatch). The app's
|
|
4
|
+
// adapter-wiring module (agent/lib/register-adapters.ts) imports this STATICALLY and calls it once
|
|
5
|
+
// at boot; every seam the discord bundle implements registers here and nowhere else. Static imports
|
|
6
|
+
// only: eve bundles the agent definition and its whole import graph into one rolldown chunk β a
|
|
7
|
+
// literal dynamic import() code-splits and trips eve's "expected one authored module" invariant.
|
|
8
|
+
//
|
|
9
|
+
// What discord registers:
|
|
10
|
+
// β’ identity mapper β bindDiscord (guild=workspace, channel=surface; discord-identity.ts)
|
|
11
|
+
// β’ capability manifest β midTurnPost true (discord-post.ts create-message); reactions true
|
|
12
|
+
// (discord-post.ts discordAddReaction, OPE-987)
|
|
13
|
+
// β’ post arm β discordPostArm (mid-turn reply + unified reply + auto-thread + redrive
|
|
14
|
+
// + the 1:1 DM delivery arm, OPE-623)
|
|
15
|
+
// β’ account directory β the declared guilds' member search, for the identity-linking
|
|
16
|
+
// directory transport (OPE-623; channels/discord-directory.ts)
|
|
17
|
+
// β’ wake-origin codec β the stored-data discord arm (discord-origin-codec.ts)
|
|
18
|
+
// β’ read adapter β discordReadAdapter (GET /channels/{id}/messages)
|
|
19
|
+
// β’ reaction surface β membership only (discord relay reactions ride the gateway)
|
|
20
|
+
// β’ surface message ops β postText / editMessage / postFiles (post_file, notices)
|
|
21
|
+
// β’ approval-card poster β postDiscordApprovalCard (the REST create-message card, Discord components)
|
|
22
|
+
// β’ judge-lift notice poster β postDiscordJudgeLiftNotice (the room's trace of a judge lift, and
|
|
23
|
+
// the "This should not have run" contradict button, OPE-1103)
|
|
24
|
+
// β’ routine dispatch channel β the eve discord channel a cron fire receive()s into
|
|
25
|
+
// β’ native admin check β guild-ADMINISTRATOR REST verdict (the spend-cap bypass's native leg)
|
|
26
|
+
// β’ scope-label resolver β friendly `#channel` / `the <guild> server` approval-card labels
|
|
27
|
+
// β’ bot display-name arm β discordBotDisplayName (GET /users/@me, OPE-610; a HANDLE, not identity)
|
|
28
|
+
// β’ command reconciler β reconcileDiscordCommands (OPE-1687; the deployment registers its own
|
|
29
|
+
// "/oe" command at boot, into the guilds the app's config declares)
|
|
30
|
+
|
|
31
|
+
import {
|
|
32
|
+
registerIdentityMapper,
|
|
33
|
+
registerCapabilityManifest,
|
|
34
|
+
registerSurfaceParity,
|
|
35
|
+
registerProviderEvents,
|
|
36
|
+
registerPostArm,
|
|
37
|
+
registerWakeOriginCodec,
|
|
38
|
+
registerReadAdapter,
|
|
39
|
+
registerSeatCatchUp,
|
|
40
|
+
registerReactionSurface,
|
|
41
|
+
registerSurfaceMessageOps,
|
|
42
|
+
registerCardPoster,
|
|
43
|
+
registerJudgeLiftNoticePoster,
|
|
44
|
+
registerRoutineDispatch,
|
|
45
|
+
registerNativeAdminCheck,
|
|
46
|
+
registerNativeMemberCheck,
|
|
47
|
+
registerScopeLabelResolver,
|
|
48
|
+
registerBotDisplayName,
|
|
49
|
+
registerAccountDirectory,
|
|
50
|
+
registerProviderDocs,
|
|
51
|
+
registerSurfaceCommandReconciler,
|
|
52
|
+
} from "@open-everywhere/core/agent/adapter-api.js";
|
|
53
|
+
import { PROVIDER_DOCS } from "./docs-generated.js";
|
|
54
|
+
import { DISCORD_SURFACE_PARITY } from "./surface-parity.js";
|
|
55
|
+
import { DISCORD_PROVIDER_EVENTS } from "./provider-events.js";
|
|
56
|
+
import { registerDiscordOps } from "./ops.js";
|
|
57
|
+
import { resolveDiscordTarget, discordReportTargetFor } from "./channels/discord-dispatch-target.js";
|
|
58
|
+
import { bindDiscord } from "./channels/discord-identity.js";
|
|
59
|
+
import { discordPostArm } from "./channels/discord-post-arm.js";
|
|
60
|
+
import { discordWakeOriginCodec } from "./channels/discord-origin-codec.js";
|
|
61
|
+
import { discordReadAdapter } from "./channels/discord-read.js";
|
|
62
|
+
import { discordSeatCatchUpFetch, DISCORD_TIMESTAMP_PRECISION_MS } from "./channels/discord-backscroll.js";
|
|
63
|
+
import { discordMessageOps } from "./channels/discord-message-ops.js";
|
|
64
|
+
import { discordBotDisplayName } from "./channels/discord-bot-name.js";
|
|
65
|
+
import { fetchGuildDirectory } from "./channels/discord-directory.js";
|
|
66
|
+
import { postDiscordApprovalCard, postDiscordJudgeLiftNotice } from "./approvals/discord-flow.js";
|
|
67
|
+
import { discordScopeLabelResolver } from "./approvals/discord-scope-label.js";
|
|
68
|
+
import { guildIdFromScopeKey, isGuildAdminViaRest, isGuildMemberViaRest } from "./approvals/discord-admin.js";
|
|
69
|
+
import { reconcileDiscordCommands } from "./commands/discord-command-sync.js";
|
|
70
|
+
|
|
71
|
+
/** Perform ALL of the discord bundle's registrations. Idempotent (each register call replaces);
|
|
72
|
+
* cheap and side-effect-free beyond the registry writes (every REST call is lazy β the bot token
|
|
73
|
+
* resolves only when a real post/read/admin-check fires). */
|
|
74
|
+
export function registerDiscordProvider(): void {
|
|
75
|
+
registerIdentityMapper("discord", bindDiscord);
|
|
76
|
+
// POST messages wired (discord-post.ts); the model-callable react verb is wired too (OPE-987,
|
|
77
|
+
// discord-post-arm.ts resolveReactTarget/react, over discord-post.ts's discordAddReaction).
|
|
78
|
+
// closingProseDropped (OPE-2006): both Discord completion handlers β the Interactions channel and
|
|
79
|
+
// the gateway's guild path β DROP a turn's closing text and audit it. `reply` is the only route out.
|
|
80
|
+
registerCapabilityManifest("discord", { midTurnPost: true, reactions: true, closingProseDropped: true });
|
|
81
|
+
// The OPE-1499 parity ledger: every capability the chat-surface contract names, answered
|
|
82
|
+
// `supported` or `{ unsupported: "<reason>" }`. Gates nothing at runtime β `lint:surface-parity`
|
|
83
|
+
// reds on an unanswered row, and the contract's Β§7.1/Β§7.1.1/Β§7.2 tables are generated from it.
|
|
84
|
+
registerSurfaceParity("discord", DISCORD_SURFACE_PARITY);
|
|
85
|
+
// The OPE-1612 event inventory: every vendor event that could wake a routine, and how far the
|
|
86
|
+
// normalizer plane carries each one. Gates nothing at runtime β `lint:provider-events` reds a
|
|
87
|
+
// bundle that declares none or that promises a match key the normalizer does not declare, and
|
|
88
|
+
// the manual's inventory table is generated from it.
|
|
89
|
+
registerProviderEvents("discord", DISCORD_PROVIDER_EVENTS);
|
|
90
|
+
registerPostArm(discordPostArm);
|
|
91
|
+
registerWakeOriginCodec("discord", discordWakeOriginCodec);
|
|
92
|
+
registerReadAdapter(discordReadAdapter);
|
|
93
|
+
// THE SEAT CATCH-UP FETCH (OPE-1726): the seat's own channel (or thread) history since its
|
|
94
|
+
// last wake. Core's shared path applies the bounds, the domain's admission policy and the cap.
|
|
95
|
+
// The surface DECLARES the unit its own message stamps carry, and core widens both catch-up
|
|
96
|
+
// bounds by it (OPE-1847). A wrong or missing unit bounds the seat out of its own window.
|
|
97
|
+
registerSeatCatchUp("discord", discordSeatCatchUpFetch, { timestampPrecisionMs: DISCORD_TIMESTAMP_PRECISION_MS });
|
|
98
|
+
registerReactionSurface("discord");
|
|
99
|
+
registerSurfaceMessageOps(discordMessageOps);
|
|
100
|
+
registerCardPoster("discord", postDiscordApprovalCard);
|
|
101
|
+
// Judge-lift NOTICE poster (OPE-1103) β a SECOND, separate hook, never the card poster above. The
|
|
102
|
+
// card poster announces a PENDING action and its failure is fatal; this one reports an action that
|
|
103
|
+
// has already run and its failure is swallowed. Without this registration a judge lift on a
|
|
104
|
+
// Discord-bound domain leaves audit rows and nothing a person in the room can act on.
|
|
105
|
+
registerJudgeLiftNoticePoster("discord", postDiscordJudgeLiftNotice);
|
|
106
|
+
registerRoutineDispatch("discord", { resolveTarget: resolveDiscordTarget, reportTargetFor: discordReportTargetFor });
|
|
107
|
+
// Native admin leg for the spend-cap bypass (spend/bypass.ts): a guild ADMINISTRATOR, REST-verified.
|
|
108
|
+
registerNativeAdminCheck("discord", async (scopeKey, principalId) => {
|
|
109
|
+
const guildId = guildIdFromScopeKey(scopeKey);
|
|
110
|
+
return guildId ? isGuildAdminViaRest(guildId, principalId) : false;
|
|
111
|
+
});
|
|
112
|
+
// Native MEMBER leg for the approval clicker-floor gate (access/native-admin.ts, OPE-303): guild
|
|
113
|
+
// membership, REST-verified, bots excluded. Without it core's gate ends in a fail-closed `false`
|
|
114
|
+
// and a Discord float advertises an undo that can never fire.
|
|
115
|
+
registerNativeMemberCheck("discord", async (scopeKey, principalId) => {
|
|
116
|
+
const guildId = guildIdFromScopeKey(scopeKey);
|
|
117
|
+
return guildId ? isGuildMemberViaRest(guildId, principalId) : false;
|
|
118
|
+
});
|
|
119
|
+
registerScopeLabelResolver("discord", discordScopeLabelResolver);
|
|
120
|
+
// The bot's own Discord handle (OPE-610) β the arm the instruction assembler renders as a HANDLE
|
|
121
|
+
// line on a Discord-pinned session ("your mention/handle here appears as X"), never as identity β
|
|
122
|
+
// see channels/discord-bot-name.ts's header for the naming-model split. `discordBotDisplayName`
|
|
123
|
+
// memoises one `GET /users/@me` per instance, so the assembler pays no round trip per turn.
|
|
124
|
+
registerBotDisplayName("discord", discordBotDisplayName);
|
|
125
|
+
// The GUILD ACCOUNT DIRECTORY (OPE-623) β the lookup the reverse-initiated link uses to NAME the
|
|
126
|
+
// other account instead of posting a bearer code. Discord searches server-side
|
|
127
|
+
// (`GET /guilds/{id}/members/search`), so the arm makes one call per DECLARED guild and core does
|
|
128
|
+
// the ranking. It needs the privileged SERVER MEMBERS INTENT; without it the arm answers with
|
|
129
|
+
// nothing and linking falls back to the code flow. The other half of the transport is the post
|
|
130
|
+
// arm's `deliverDirectMessage` β core requires BOTH before it offers the directory transport.
|
|
131
|
+
registerAccountDirectory("discord", (query) => fetchGuildDirectory(query));
|
|
132
|
+
// Shipped-manual plane (OPE-138): this bundle's own setup runbook (docs/deploy/surfaces/discord.md,
|
|
133
|
+
// compiled into ./docs-generated.ts because docs/ is not on disk at runtime). De-select the bundle
|
|
134
|
+
// and the module leaves the import graph; registerProviderDocs re-checks the selection gate anyway.
|
|
135
|
+
registerProviderDocs("discord", PROVIDER_DOCS);
|
|
136
|
+
// Slash-command reconcile (OPE-1687): the vendor half of core's command plane. Registering it
|
|
137
|
+
// makes NO call β the plane runs it once, from the app's boot, and only for the guilds the app
|
|
138
|
+
// declared in `agent/commands/discord-commands.ts`. Without this row a declared "/oe" subcommand
|
|
139
|
+
// reaches Discord only when an operator runs `npm run register:discord-commands` by hand, which is
|
|
140
|
+
// a step nobody could take: the bot token lives with the deployment, not the operator.
|
|
141
|
+
registerSurfaceCommandReconciler("discord", (scope) => reconcileDiscordCommands(scope));
|
|
142
|
+
// Ops plane (OPE-495): the telemetry credential-presence probe. Split into ./ops.js so the
|
|
143
|
+
// STANDALONE ops MCP entry (repo-root scripts/ops-mcp.ts, which serves preflight/quickstart with
|
|
144
|
+
// no agent boot) registers it without pulling the whole channel graph β the same split slack and
|
|
145
|
+
// teams use.
|
|
146
|
+
registerDiscordOps();
|
|
147
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// DISCORD's surface-parity declaration (OPE-1499). See the core module's header
|
|
2
|
+
// (packages/core/agent/identity/surface-parity.ts) for what the three cell shapes mean.
|
|
3
|
+
//
|
|
4
|
+
// Discord is complete on the chat plane. Its one structural difference from Slack is the
|
|
5
|
+
// engagement seam's second step: it enrols conversations and honours the durable `stopped` flag,
|
|
6
|
+
// but gates delivery with its own gateway rule instead of core's `shouldDeliverReply`.
|
|
7
|
+
|
|
8
|
+
import type { SurfaceParityDeclaration } from "@open-everywhere/core/agent/adapter-api.js";
|
|
9
|
+
|
|
10
|
+
export const DISCORD_SURFACE_PARITY: SurfaceParityDeclaration = {
|
|
11
|
+
// registration seams (Β§7.1)
|
|
12
|
+
"identity-mapper": "supported",
|
|
13
|
+
"capability-manifest": "supported",
|
|
14
|
+
"post-arm": "supported",
|
|
15
|
+
"wake-origin-codec": "supported",
|
|
16
|
+
// The arm renders a Discord action row (`discord-post-arm.ts`), the front routes the tap back
|
|
17
|
+
// (`discord-front.ts` classifies the `oe_input:` custom_id, `discord-approval-card.ts` settles it),
|
|
18
|
+
// and the settle DELIVERS through core's `approvalCardRespondVia` β all three halves, as the row
|
|
19
|
+
// requires. The third is not a formality: this front bound its own `args.from(bareToken)` until
|
|
20
|
+
// OPE-1863, and that address is channel-local, so every tap threw and the approval stayed parked.
|
|
21
|
+
"unified-action-plane": "supported",
|
|
22
|
+
// `messageId` is the `message_reference` anchor and sits outside `threadRef`, which keys on the
|
|
23
|
+
// channel id alone β Slack's shape exactly. Both members are implemented; `autoThreadName` stays
|
|
24
|
+
// OUT of the axis because opening a thread MOVES a post rather than placing one.
|
|
25
|
+
"origin-placement-carry": "supported",
|
|
26
|
+
"read-adapter": "supported",
|
|
27
|
+
"reaction-feedback-ingest": "supported",
|
|
28
|
+
"ancillary-ops": "supported",
|
|
29
|
+
// Enrols (`markThreadEngaged`) and reads the `stopped` flag, but runs its own delivery gate in
|
|
30
|
+
// discord-gateway.ts rather than calling core's `shouldDeliverReply` β the seam is wired, and
|
|
31
|
+
// the trio is not called whole (Β§7.1's prose).
|
|
32
|
+
"ambient-engagement-seam": { supported: "enrols and honours `stopped`; gates delivery in its own gateway rule" },
|
|
33
|
+
// π΄ A SECOND HONEST SPELLING, NOT A MISSING MAPPING. Under standing seats a Discord auto-thread
|
|
34
|
+
// is a seated channel in its own right, so a plain follow-up in it diverts as THAT channel's own
|
|
35
|
+
// wake and `discord-gateway.ts` reports the classifier's word. `J-ENGAGED-discord` reads the pair
|
|
36
|
+
// `channel-watch` + `singleWindow: true` IN the follow-up's own room instead
|
|
37
|
+
// (`reportedSeatedChannelWatch`, packages/core/scripts/e2e/engaged-rows.ts). Promoting the value
|
|
38
|
+
// here would need the seated path to resolve the engagement registry it does not read.
|
|
39
|
+
"engaged-row-promotion": {
|
|
40
|
+
unsupported:
|
|
41
|
+
"the seated path reports the classifier's word β an auto-thread's follow-up diverts as that channel's own wake, and the journey reads `channel-watch` on a `singleWindow: true` row in that room instead",
|
|
42
|
+
},
|
|
43
|
+
// A Discord thread is its OWN channel id, so the stored origin could not tell a thread from a
|
|
44
|
+
// plain channel and the router had to read every Discord wake as top-level. The gateway now
|
|
45
|
+
// stamps `thread: true` at mint from the relay payload's channel type (OPE-1719), which is the
|
|
46
|
+
// positive signal the guard needs. The DM leg keeps the raw divert: a DM has no threads.
|
|
47
|
+
"owned-thread-ingress": { supported: "the guild leg only β a Discord DM carries no threads, so its divert never consults ownership" },
|
|
48
|
+
|
|
49
|
+
// wake legs and conversation shapes
|
|
50
|
+
"addressed-leg": "supported",
|
|
51
|
+
"ambient-leg": "supported",
|
|
52
|
+
// `discord-backscroll.ts discordSeatCatchUpFetch` pages `GET /channels/:id/messages` back to the
|
|
53
|
+
// seat's own `lastWakeAt` and hands the normalized window to core's shared catch-up path. A thread
|
|
54
|
+
// IS its own channel id on Discord, so one endpoint serves both the container and the conversation.
|
|
55
|
+
"seat-catch-up": "supported",
|
|
56
|
+
// BOTH hydration roads pour through one wrapper (`admitDiscordSeatLines`, discord-gateway.ts),
|
|
57
|
+
// which calls the core seam β never a per-bundle copy of the policy.
|
|
58
|
+
"seat-context-admission": "supported",
|
|
59
|
+
// The one registered `CardPoster` (approvals/discord-flow.ts, wired in register.ts): this bundle
|
|
60
|
+
// owns its own render AND the component route that brings the tap back.
|
|
61
|
+
"approval-card": "supported",
|
|
62
|
+
// The one registered `JudgeLiftNoticePoster` too (approvals/discord-flow.ts): the notice renders
|
|
63
|
+
// as this surface's own card with the overrule button, and the tap comes back the same route the
|
|
64
|
+
// Approve/Reject taps take.
|
|
65
|
+
"judge-lift-notice": "supported",
|
|
66
|
+
"name-drop-mention": "supported",
|
|
67
|
+
// π΄ THE EVENT NEVER LEAVES THE RELAY. `deploy/discord-relay/index.js` subscribes to
|
|
68
|
+
// `Events.MessageCreate` (plus the two reaction events) and nothing else, so an edit β Discord's
|
|
69
|
+
// `MessageUpdate` β is never forwarded and the ingestion channel has no edit to gate. The gap is
|
|
70
|
+
// in the relay's subscription set, not in `discord-gateway.ts`.
|
|
71
|
+
"message-edit-wake": { unsupported: "the gateway relay subscribes to MessageCreate only β an edit raises MessageUpdate, which nothing forwards" },
|
|
72
|
+
// A Discord thread IS a channel, so `read_thread` reads that thread channel (Β§4.6.1).
|
|
73
|
+
threads: { supported: "a thread is itself a channel" },
|
|
74
|
+
rooms: "supported",
|
|
75
|
+
dm: "supported",
|
|
76
|
+
mpim: "supported",
|
|
77
|
+
|
|
78
|
+
// core verbs (Β§7.2)
|
|
79
|
+
reply: "supported",
|
|
80
|
+
edit_reply: "supported",
|
|
81
|
+
// Message-level granularity since OPE-987 (discord-post-arm.ts `resolveReactTarget`/`react`).
|
|
82
|
+
react: "supported",
|
|
83
|
+
no_reply: "supported",
|
|
84
|
+
read_channel: "supported",
|
|
85
|
+
read_thread: "supported",
|
|
86
|
+
search: { unsupported: "no work-search adapter β Discord is a chat surface, not a work corpus (Β§4.7)" },
|
|
87
|
+
post_message: "supported",
|
|
88
|
+
dm_person: "supported",
|
|
89
|
+
set_dm_delivery: "supported",
|
|
90
|
+
stop: { supported: "β reaction, plus the `/oe stop` command" },
|
|
91
|
+
ack_stop_glyph: "supported",
|
|
92
|
+
ack_cancel_note: "supported",
|
|
93
|
+
stand_down: { supported: "marks the engagement row; refuses out loud when the registry holds none" },
|
|
94
|
+
post_file: "supported",
|
|
95
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type InteractionFollowUp } from "../channels/discord-interaction-defer.js";
|
|
2
|
+
/** The interaction response body this handler returns. Loosely typed, exactly as its two sibling
|
|
3
|
+
* handlers type theirs, so the front route can hold one seam type across all three. */
|
|
4
|
+
export type DiscordGrantClickResponse = Record<string, unknown>;
|
|
5
|
+
/** The host edges this door needs to defer. Both are injected so a test can drive the whole
|
|
6
|
+
* ack-then-edit sequence with no Discord and no host. */
|
|
7
|
+
export interface DiscordGrantClickDeps {
|
|
8
|
+
/** The route's own `waitUntil` β keeps the resolution alive past the interaction response on a
|
|
9
|
+
* serverless host. ABSENT β no defer (see the header): the handler awaits and answers as before. */
|
|
10
|
+
readonly waitUntil?: (p: Promise<unknown>) => void;
|
|
11
|
+
/** The follow-up edit. Live default is {@link editOriginalInteractionResponse}. */
|
|
12
|
+
readonly edit?: (followUp: InteractionFollowUp, content: string) => Promise<boolean>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Handle one verified `oe_grant:` component click.
|
|
16
|
+
*
|
|
17
|
+
* Returns the interaction response body to send, or `null` for anything that is NOT one of ours β
|
|
18
|
+
* the front route then forwards it, so a click is never silently swallowed. NEVER throws.
|
|
19
|
+
*
|
|
20
|
+
* π΄ ON THE RESOLUTION PATH IT RETURNS BEFORE THE DECISION IS MADE (OPE-1282). The body is a
|
|
21
|
+
* DEFERRED ephemeral ack; the decision runs under `deps.waitUntil` and edits that placeholder when
|
|
22
|
+
* it lands. See the header for why, and for the two cases that still answer synchronously.
|
|
23
|
+
*/
|
|
24
|
+
export declare function handleDiscordGrantCardInteraction(raw: unknown, deps?: DiscordGrantClickDeps): Promise<DiscordGrantClickResponse | null>;
|
|
25
|
+
//# sourceMappingURL=discord-grant-click.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discord-grant-click.d.ts","sourceRoot":"","sources":["../../../agent/access/discord-grant-click.ts"],"names":[],"mappings":"AAiFA,OAAO,EAAmF,KAAK,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAWrK;wFACwF;AACxF,MAAM,MAAM,yBAAyB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEhE;0DAC0D;AAC1D,MAAM,WAAW,qBAAqB;IACpC;yGACqG;IACrG,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;IACnD,mFAAmF;IACnF,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACtF;AA8BD;;;;;;;;;GASG;AACH,wBAAsB,iCAAiC,CACrD,GAAG,EAAE,OAAO,EACZ,IAAI,GAAE,qBAA0B,GAC/B,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC,CAyF3C"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// THE DISCORD HALF OF THE CREDENTIAL-GRANT CARD BUTTON (OPE-1260) β the sibling of
|
|
2
|
+
// identity/discord-link-consent.ts, funnelling through core's own `resolveGrantCardClick` exactly as
|
|
3
|
+
// that file funnels through `resolveLinkConsentClick`. Core decides; this file only reads Discord's
|
|
4
|
+
// envelope and writes Discord's answer.
|
|
5
|
+
//
|
|
6
|
+
// WHAT WAS WRONG BEFORE THIS FILE. The owner's grant card is delivered as a DM with an actions row,
|
|
7
|
+
// and the Discord DM arm renders those actions as real components (channels/discord-post-arm.ts). The
|
|
8
|
+
// front route classified only `oe-approval:` and `oe-link:`, so an `oe_grant:` tap FORWARDED to eve's
|
|
9
|
+
// HITL decoder, which no-ops it. The owner saw four buttons, tapped one, and nothing happened β
|
|
10
|
+
// no approval, no decline, no answer, and the ask then lapsed on its own.
|
|
11
|
+
//
|
|
12
|
+
// π΄ THE CLICKER IS READ FROM THE ENVELOPE, NEVER FROM A PAYLOAD FIELD. A grant answer is scoped to
|
|
13
|
+
// BEING the owner the card was sent to, so whose hand it was is the whole security content of this
|
|
14
|
+
// file. The front route has already verified Discord's Ed25519 signature over the RAW body, so every
|
|
15
|
+
// field read below is Discord's own statement. Core then compares that clicker to the ask row's
|
|
16
|
+
// `ownerPrincipalId`; an ask id names an ask, it never answers one.
|
|
17
|
+
//
|
|
18
|
+
// π΄ DM-ONLY, REFUSED RATHER THAN TOLERATED β the same rule, for the same reason, as the consent
|
|
19
|
+
// button. A grant card is only ever delivered through `deliverDirectMessage`, so it only ever lands
|
|
20
|
+
// in a 1:1. A guild click therefore cannot be a tap on a real card: the message was forwarded, or the
|
|
21
|
+
// id was guessed. `interaction.guild_id` present β refuse, and say so.
|
|
22
|
+
//
|
|
23
|
+
// WHERE THIS DIFFERS FROM THE SLACK DOOR, and why. Slack's `handleGrantCardClick` posts its private
|
|
24
|
+
// answer with a second API call (`chat.postEphemeral`), because a Slack interactivity POST answers
|
|
25
|
+
// with an empty 200. Discord's interaction response IS the private answer β `type 4` + `flags 64` β
|
|
26
|
+
// so the answer rides the click's own reply and no second call is made. The DECISION, the copy and
|
|
27
|
+
// the audit row are core's, identical on both surfaces.
|
|
28
|
+
//
|
|
29
|
+
// β οΈ THIS FILE NEVER TOUCHES THE CARD β CORE REWRITES IT AFTER THE DECISION (OPE-1278). The answer
|
|
30
|
+
// here is ephemeral, so the handler leaves the owner's message alone. Core's `rewriteGrantCard`
|
|
31
|
+
// (access/credential-grant-card.ts) rewrites that card to a terminal APPROVED or DECLINED body once
|
|
32
|
+
// the CAS has closed the ask, and the Discord edit arm's `components: []` takes the four buttons
|
|
33
|
+
// with it (channels/discord-message-ops.ts). THAT REWRITE IS BEST-EFFORT: an ask row with no pinned
|
|
34
|
+
// card locus, or an edit the surface refuses, still leaves live buttons over a closed request. The
|
|
35
|
+
// CAS is what makes that safe β core's approve is conjunct on `status = 'pending'`, so a second tap
|
|
36
|
+
// mints nothing and is answered "that request is no longer open", which is the truth.
|
|
37
|
+
//
|
|
38
|
+
// NEVER THROWS. Discord's interactions endpoint must answer within three seconds, and a throw there
|
|
39
|
+
// becomes a red "This interaction failed" the person cannot act on.
|
|
40
|
+
//
|
|
41
|
+
// π΄ THE RESOLUTION IS DEFERRED, BECAUSE IT IS NOT FAST AND DISCORD DOES NOT REDELIVER (OPE-1282).
|
|
42
|
+
// `resolveGrantCardClick` used to be awaited to completion before this returned. An APPROVE inside it
|
|
43
|
+
// reads the owner's own MCP connection before it CASes β a consent probe, a token mint, an MCP
|
|
44
|
+
// handshake and a `tools/list`, all four sharing one `BORROW_APPROVE_READ_BUDGET_MS` deadline (core
|
|
45
|
+
// connections/grant-mcp-borrow.ts, five seconds) β and then does the CAS, the grant insert, the audit rows
|
|
46
|
+
// and an AWAITED post into the requesting room. That can exceed Discord's three seconds.
|
|
47
|
+
//
|
|
48
|
+
// WHAT THAT COST, AND WHY IT WAS WORSE HERE THAN ON SLACK. Slack redelivers an interactivity payload
|
|
49
|
+
// it has not seen answered, so a slow approve there is retried (slack-front.ts's own note). Discord
|
|
50
|
+
// does NOT redeliver an expired interaction token: the owner saw a red "This interaction failed" and
|
|
51
|
+
// this handler's ephemeral answer was never rendered β while the grant really was minted and the
|
|
52
|
+
// requesting room really was told. A second tap then read "that request is no longer open", which is
|
|
53
|
+
// true and reads like a failure. It was never a correctness problem β the approve CAS still yields
|
|
54
|
+
// exactly one grant β but the owner believed their approval had failed while a conversation could
|
|
55
|
+
// already spend their credential.
|
|
56
|
+
//
|
|
57
|
+
// SO THIS DOOR IS NOW "ACK, THEN DECIDE, THEN EDIT": it answers with a DEFERRED ephemeral response
|
|
58
|
+
// (`type 5`, channels/discord-interaction-defer.ts), hands the resolution to the host's `waitUntil`,
|
|
59
|
+
// and edits the placeholder with core's own decision copy when it lands. The ephemeral flag rides
|
|
60
|
+
// the ACK β Discord fixes visibility at the first response β so the answer is still private.
|
|
61
|
+
//
|
|
62
|
+
// π΄ THE FAST REFUSALS DO NOT DEFER, and that is deliberate. A guild click, an unattributable
|
|
63
|
+
// clicker and an unreadable action id are all decided from the envelope alone, in no time at all.
|
|
64
|
+
// Deferring them would trade an instant answer for a placeholder plus a second round trip, and each
|
|
65
|
+
// one is a `type 4` today because that is the correct shape for an answer that is already known.
|
|
66
|
+
//
|
|
67
|
+
// π΄ NO `waitUntil` β NO DEFER. Without somewhere to run the work, a deferred ack would leave the
|
|
68
|
+
// owner on a permanent "thinkingβ¦" β strictly worse than the slow answer. The handler falls back to
|
|
69
|
+
// the original await-then-answer shape instead, and says so in the log.
|
|
70
|
+
//
|
|
71
|
+
// β οΈ approvals/discord-flow.ts IS ONLY HALF THIS SHAPE, and cannot take the other half as written
|
|
72
|
+
// (OPE-1407). Its `deliverDecisionFeedback` β the notice post and the decision wake β now runs under
|
|
73
|
+
// the route's `waitUntil` WHEN THE ROUTE SUPPLIES ONE, which takes that leg out of the three-second
|
|
74
|
+
// budget; a host that supplies none still awaits it inside the budget. Its `resolveApprovalClick`
|
|
75
|
+
// stays on the response path because that door answers with THREE response KINDS chosen by the
|
|
76
|
+
// resolution (`type 7` replaces the card, `type 6` acks silently, `type 4` sends an ephemeral), and
|
|
77
|
+
// Discord fixes a response's kind at the first response. This door answers with one `type 4` on
|
|
78
|
+
// every path, which is what lets it defer as `type 5` and say the same thing later. Closing the
|
|
79
|
+
// other half needs a follow-up MESSAGE rather than the `@original` edit this module provides.
|
|
80
|
+
import { OE_GRANT_ACTION_PREFIX, parseGrantCardActionId, resolveGrantCardClick, deploymentOrg } from "@open-everywhere/core/agent/adapter-api.js";
|
|
81
|
+
import { deferredEphemeralResponse, editOriginalInteractionResponse, interactionFollowUp } from "../channels/discord-interaction-defer.js";
|
|
82
|
+
function log(msg) {
|
|
83
|
+
console.log(`[open-everywhere:discord-grant] ${msg}`);
|
|
84
|
+
}
|
|
85
|
+
// Discord interaction-response wire constants, defined locally for the same reason
|
|
86
|
+
// identity/discord-link-consent.ts and approvals/discord-flow.ts define their own.
|
|
87
|
+
const RESPONSE_CHANNEL_MESSAGE = 4; // CHANNEL_MESSAGE_WITH_SOURCE
|
|
88
|
+
const EPHEMERAL = 64; // MessageFlags.EPHEMERAL β only the clicker sees it
|
|
89
|
+
function ephemeral(content) {
|
|
90
|
+
return { type: RESPONSE_CHANNEL_MESSAGE, data: { content, flags: EPHEMERAL } };
|
|
91
|
+
}
|
|
92
|
+
function isObject(v) {
|
|
93
|
+
return typeof v === "object" && v !== null;
|
|
94
|
+
}
|
|
95
|
+
/** The clicking user's Discord id, from the envelope's own fields. Discord puts the clicker at
|
|
96
|
+
* `interaction.user` in a DM and at `interaction.member.user` in a guild; both are read so the
|
|
97
|
+
* guild refusal below is a DELIBERATE refusal rather than an accident of which field was absent. */
|
|
98
|
+
function clickerIdOf(interaction) {
|
|
99
|
+
const direct = isObject(interaction["user"]) ? interaction["user"]["id"] : undefined;
|
|
100
|
+
if (typeof direct === "string" && direct.length > 0)
|
|
101
|
+
return direct;
|
|
102
|
+
const member = isObject(interaction["member"]) ? interaction["member"]["user"] : undefined;
|
|
103
|
+
const viaMember = isObject(member) ? member["id"] : undefined;
|
|
104
|
+
return typeof viaMember === "string" && viaMember.length > 0 ? viaMember : undefined;
|
|
105
|
+
}
|
|
106
|
+
/** The channel the click happened in β the audit row's `surface`. Absent on a body that carries
|
|
107
|
+
* none, which is a stamp we leave off rather than invent. */
|
|
108
|
+
function channelIdOf(interaction) {
|
|
109
|
+
const id = interaction["channel_id"];
|
|
110
|
+
if (typeof id === "string" && id.length > 0)
|
|
111
|
+
return id;
|
|
112
|
+
const channel = isObject(interaction["channel"]) ? interaction["channel"]["id"] : undefined;
|
|
113
|
+
return typeof channel === "string" && channel.length > 0 ? channel : undefined;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Handle one verified `oe_grant:` component click.
|
|
117
|
+
*
|
|
118
|
+
* Returns the interaction response body to send, or `null` for anything that is NOT one of ours β
|
|
119
|
+
* the front route then forwards it, so a click is never silently swallowed. NEVER throws.
|
|
120
|
+
*
|
|
121
|
+
* π΄ ON THE RESOLUTION PATH IT RETURNS BEFORE THE DECISION IS MADE (OPE-1282). The body is a
|
|
122
|
+
* DEFERRED ephemeral ack; the decision runs under `deps.waitUntil` and edits that placeholder when
|
|
123
|
+
* it lands. See the header for why, and for the two cases that still answer synchronously.
|
|
124
|
+
*/
|
|
125
|
+
export async function handleDiscordGrantCardInteraction(raw, deps = {}) {
|
|
126
|
+
try {
|
|
127
|
+
if (!isObject(raw))
|
|
128
|
+
return null;
|
|
129
|
+
const data = isObject(raw["data"]) ? raw["data"] : undefined;
|
|
130
|
+
const customId = typeof data?.["custom_id"] === "string" ? data["custom_id"] : undefined;
|
|
131
|
+
if (!customId?.startsWith(OE_GRANT_ACTION_PREFIX))
|
|
132
|
+
return null;
|
|
133
|
+
const parsed = parseGrantCardActionId(customId);
|
|
134
|
+
if (parsed === undefined) {
|
|
135
|
+
// Ours by prefix, unreadable by grammar. Returning null lets the front route forward it rather
|
|
136
|
+
// than swallow it β the same defensive shape both sibling handlers take.
|
|
137
|
+
log("grant card custom_id did not parse β forwarding");
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
if (typeof raw["guild_id"] === "string" && raw["guild_id"].length > 0) {
|
|
141
|
+
// See the header: a grant card only ever lands in a DM, so a guild click is not the owner
|
|
142
|
+
// answering their own card.
|
|
143
|
+
return ephemeral("I only take an answer to a credential request in our direct messages β this one came from a server. Open our DM and answer it there. Nothing was granted.");
|
|
144
|
+
}
|
|
145
|
+
const clicker = clickerIdOf(raw);
|
|
146
|
+
if (clicker === undefined) {
|
|
147
|
+
log("grant card click carried no attributable user β refusing");
|
|
148
|
+
return ephemeral("I could not tell who pressed that, so I did nothing and nothing was granted.");
|
|
149
|
+
}
|
|
150
|
+
const channelId = channelIdOf(raw);
|
|
151
|
+
const resolve = () => resolveGrantCardClick({
|
|
152
|
+
askId: parsed.askId,
|
|
153
|
+
answer: parsed.answer,
|
|
154
|
+
// π΄ NO TENANT RUNG, AND THAT IS THE CORRECT SPELLING RATHER THAN A GAP. Discord is not a
|
|
155
|
+
// tenant-scoped platform (identity/principal-key.ts), so the owner's key is `discord/<user-id>`
|
|
156
|
+
// β the exact string the ask row's `ownerPrincipalId` was minted as. Passing a guild here would
|
|
157
|
+
// compose a three-segment key that matches nobody and refuse every genuine owner.
|
|
158
|
+
clicker: { platform: "discord", nativeId: clicker },
|
|
159
|
+
// READ WHEN THE RESOLUTION RUNS, not when the ack is sent β it is the clock the ask's expiry
|
|
160
|
+
// is judged against, and the defer puts real time between the two.
|
|
161
|
+
nowMs: Date.now(),
|
|
162
|
+
// ONE deployment serves ONE org, and the ask row was written under that partition. Reading it
|
|
163
|
+
// from the deployment rather than the payload is what stops a forged body naming another
|
|
164
|
+
// tenant's asks β the same reason both sibling handlers read it this way.
|
|
165
|
+
org: deploymentOrg(),
|
|
166
|
+
platform: "discord",
|
|
167
|
+
// A DM has no guild, and the Discord identity mapper's own convention for that partition is the
|
|
168
|
+
// user's id in the `workspace` rung (channels/discord-identity.ts `guildId ?? userId`). Spelled
|
|
169
|
+
// the same way here so this audit row files where every other Discord DM row files.
|
|
170
|
+
workspace: clicker,
|
|
171
|
+
...(channelId === undefined ? {} : { surface: channelId }),
|
|
172
|
+
});
|
|
173
|
+
const followUp = interactionFollowUp(raw);
|
|
174
|
+
if (deps.waitUntil === undefined || followUp === undefined) {
|
|
175
|
+
// NO PLACE TO RUN THE WORK, OR NO ADDRESS TO ANSWER AT β the pre-OPE-1282 shape. Slow, and
|
|
176
|
+
// still correct: a deferred ack we could not follow up would leave a permanent "thinkingβ¦".
|
|
177
|
+
log(`grant card click answering synchronously (${deps.waitUntil === undefined ? "no waitUntil" : "no follow-up address"}) β a slow approve may outlive the interaction token`);
|
|
178
|
+
return ephemeral((await resolve()).text);
|
|
179
|
+
}
|
|
180
|
+
const edit = deps.edit ?? editOriginalInteractionResponse;
|
|
181
|
+
deps.waitUntil((async () => {
|
|
182
|
+
// TOTAL. This runs after the response has gone; a throw here reaches the host's unhandled
|
|
183
|
+
// rejection handler and tells the owner nothing. Core's resolver is already total, so the
|
|
184
|
+
// catch is for the edit's own transport and for an impossible throw above it.
|
|
185
|
+
let text;
|
|
186
|
+
try {
|
|
187
|
+
text = (await resolve()).text;
|
|
188
|
+
}
|
|
189
|
+
catch (err) {
|
|
190
|
+
log(`deferred grant card resolution failed: ${err?.message ?? String(err)}`);
|
|
191
|
+
text = "That could not be answered right now. Nothing changed, and nothing was granted. Try the button again.";
|
|
192
|
+
}
|
|
193
|
+
// π΄ A FAILED EDIT IS LOUD BUT NOT FATAL: the DECISION has already landed and been audited by
|
|
194
|
+
// core. What is lost is the owner's explanation, which is exactly what the pre-fix expired
|
|
195
|
+
// token lost β so this is never a regression, and it must be findable in the log.
|
|
196
|
+
const shown = await edit(followUp, text);
|
|
197
|
+
if (!shown)
|
|
198
|
+
log(`grant card answer could NOT be shown to the owner β the decision landed and is audited, the owner was not told`);
|
|
199
|
+
})());
|
|
200
|
+
return deferredEphemeralResponse();
|
|
201
|
+
}
|
|
202
|
+
catch (err) {
|
|
203
|
+
// A three-second endpoint: an unhandled throw is a red "interaction failed" the person cannot act
|
|
204
|
+
// on. Core's resolver is already total and guards every write, so an honest answer here costs the
|
|
205
|
+
// owner an explanation and never an outcome.
|
|
206
|
+
log(`grant card click failed: ${err?.message ?? String(err)}`);
|
|
207
|
+
return ephemeral("That could not be answered right now. Nothing changed, and nothing was granted. Try the button again.");
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=discord-grant-click.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discord-grant-click.js","sourceRoot":"","sources":["../../../agent/access/discord-grant-click.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,qGAAqG;AACrG,oGAAoG;AACpG,wCAAwC;AACxC,EAAE;AACF,oGAAoG;AACpG,sGAAsG;AACtG,sGAAsG;AACtG,gGAAgG;AAChG,0EAA0E;AAC1E,EAAE;AACF,oGAAoG;AACpG,mGAAmG;AACnG,qGAAqG;AACrG,gGAAgG;AAChG,oEAAoE;AACpE,EAAE;AACF,iGAAiG;AACjG,oGAAoG;AACpG,sGAAsG;AACtG,uEAAuE;AACvE,EAAE;AACF,oGAAoG;AACpG,mGAAmG;AACnG,oGAAoG;AACpG,mGAAmG;AACnG,wDAAwD;AACxD,EAAE;AACF,mGAAmG;AACnG,gGAAgG;AAChG,oGAAoG;AACpG,iGAAiG;AACjG,oGAAoG;AACpG,mGAAmG;AACnG,oGAAoG;AACpG,sFAAsF;AACtF,EAAE;AACF,oGAAoG;AACpG,oEAAoE;AACpE,EAAE;AACF,mGAAmG;AACnG,sGAAsG;AACtG,+FAA+F;AAC/F,oGAAoG;AACpG,2GAA2G;AAC3G,yFAAyF;AACzF,EAAE;AACF,qGAAqG;AACrG,oGAAoG;AACpG,qGAAqG;AACrG,iGAAiG;AACjG,qGAAqG;AACrG,mGAAmG;AACnG,kGAAkG;AAClG,kCAAkC;AAClC,EAAE;AACF,mGAAmG;AACnG,qGAAqG;AACrG,kGAAkG;AAClG,6FAA6F;AAC7F,EAAE;AACF,8FAA8F;AAC9F,kGAAkG;AAClG,oGAAoG;AACpG,iGAAiG;AACjG,EAAE;AACF,kGAAkG;AAClG,oGAAoG;AACpG,wEAAwE;AACxE,EAAE;AACF,kGAAkG;AAClG,qGAAqG;AACrG,oGAAoG;AACpG,kGAAkG;AAClG,+FAA+F;AAC/F,oGAAoG;AACpG,gGAAgG;AAChG,gGAAgG;AAChG,8FAA8F;AAE9F,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAC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