@vellumai/credential-executor 0.11.10-dev.202609092016.c7aa45c → 0.11.10-dev.202609092055.8ea00ad

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.
@@ -7,11 +7,13 @@
7
7
  * is spelled. Modelled on Zulip's `reaction_type`, the one surveyed system
8
8
  * that separates the namespace from the name.
9
9
  *
10
- * `shortcode` is a name in a channel's own namespace whose kind the channel
11
- * does not disclose: Slack sends `+1` for the standard emoji and `blob_wave`
12
- * for a workspace upload with nothing to tell them apart, and only the
13
- * workspace token can resolve the second. It is a distinct kind from
14
- * `unicode`, not a stand-in for an unknown one.
10
+ * `shortcode` is a name in a channel's own namespace that the channel's
11
+ * adapter could not place among the standard emoji. Slack sends `+1` and
12
+ * `blob_wave` alike, as names; its normalizer resolves the standard ones to
13
+ * `unicode` from Slack's own list, and what remains is a workspace upload
14
+ * only the workspace can render. It is a distinct kind from `unicode`, not
15
+ * a stand-in for an unknown one, and nothing past an adapter needs a
16
+ * channel's naming to read it.
15
17
  */
16
18
  import { z } from "zod";
17
19
 
@@ -58,3 +60,75 @@ export function pickReactionEmojiFields(
58
60
  : {}),
59
61
  };
60
62
  }
63
+
64
+ /**
65
+ * Parse Discord's custom-emoji mention form. The form travels the wire as a
66
+ * reaction's spelling, so more than one package reads it: the daemon rebuilds
67
+ * a REST path from it when the assistant reacts, and a row carrying only the
68
+ * spelling recovers its kind from it. One parser, so the two cannot disagree
69
+ * about what counts as one.
70
+ *
71
+ * `animated` reports whether the spelling carries the `a` marker. Discord's
72
+ * normalizer never writes that marker, so it is read only from spellings that
73
+ * arrive from elsewhere: a row written by another producer, or a value the
74
+ * model hands back as it received it.
75
+ */
76
+ export function parseDiscordEmojiMention(
77
+ emoji: string,
78
+ ): { name: string; id: string; animated: boolean } | null {
79
+ const match = /^<(a?):([^:>]+):(\d+)>$/.exec(emoji);
80
+ return match
81
+ ? { name: match[2]!, id: match[3]!, animated: match[1] === "a" }
82
+ : null;
83
+ }
84
+
85
+ /**
86
+ * Recover an emoji's kind from its spelling alone. This is the one inference
87
+ * the design permits, reserved for a value that carries the string and no
88
+ * typed fields: a persisted row or a replayed retry payload. A value that
89
+ * declares its kind never reaches this; `reactionEmojiIdentity` makes that
90
+ * choice for every reader.
91
+ *
92
+ * A mention form is unambiguous. Past that the two remaining kinds are told
93
+ * apart by whether the string is a name at all: a channel's shortcode is
94
+ * ASCII word characters, optionally carrying Slack's `::skin-tone-N`
95
+ * suffix, and anything else is the character itself.
96
+ */
97
+ export function classifyReactionEmojiSpelling(
98
+ emoji: string,
99
+ ): ReactionEmojiFields & { emojiKind: ReactionEmojiKind; emojiName: string } {
100
+ const custom = parseDiscordEmojiMention(emoji);
101
+ if (custom) {
102
+ // The plain `<:name:id>` form says nothing about animation: the
103
+ // normalizer spells every custom emoji that way and reports animation
104
+ // in the typed field instead, so a spelling without the `a` marker is
105
+ // "unrecorded", not "not animated". Only the `<a:` form asserts it.
106
+ return {
107
+ emojiKind: "custom",
108
+ emojiName: custom.name,
109
+ emojiId: custom.id,
110
+ ...(custom.animated ? { emojiAnimated: true } : {}),
111
+ };
112
+ }
113
+ return /^[\w+-]+(::skin-tone-[2-6])?$/.test(emoji)
114
+ ? { emojiKind: "shortcode", emojiName: emoji }
115
+ : { emojiKind: "unicode", emojiName: emoji };
116
+ }
117
+
118
+ /**
119
+ * The typed identity of a reaction's emoji: the fields it declares when it
120
+ * declares a kind, otherwise the kind recovered from its spelling. Every
121
+ * reader that must know what an emoji is goes through this, so the wire
122
+ * contract and the web agree on when the spelling is consulted.
123
+ */
124
+ export function reactionEmojiIdentity(
125
+ reaction: { emoji: string } & ReactionEmojiFields,
126
+ ): ReactionEmojiFields & { emojiKind: ReactionEmojiKind; emojiName: string } {
127
+ return reaction.emojiKind !== undefined && reaction.emojiName !== undefined
128
+ ? {
129
+ ...pickReactionEmojiFields(reaction),
130
+ emojiKind: reaction.emojiKind,
131
+ emojiName: reaction.emojiName,
132
+ }
133
+ : classifyReactionEmojiSpelling(reaction.emoji);
134
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/credential-executor",
3
- "version": "0.11.10-dev.202609092016.c7aa45c",
3
+ "version": "0.11.10-dev.202609092055.8ea00ad",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {