@vellumai/credential-executor 0.11.11-staging.1 → 0.11.11-staging.2

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
 
@@ -39,6 +41,12 @@ export const ReactionEmojiFieldsSchema = z.object({
39
41
  });
40
42
  export type ReactionEmojiFields = z.infer<typeof ReactionEmojiFieldsSchema>;
41
43
 
44
+ /** The typed fields with the kind and name known. */
45
+ export type ReactionEmojiIdentity = ReactionEmojiFields & {
46
+ emojiKind: ReactionEmojiKind;
47
+ emojiName: string;
48
+ };
49
+
42
50
  /**
43
51
  * The typed emoji fields a source actually carries, with undefined ones
44
52
  * omitted: an absent key and a present-but-undefined one serialize alike, but the
@@ -58,3 +66,75 @@ export function pickReactionEmojiFields(
58
66
  : {}),
59
67
  };
60
68
  }
69
+
70
+ /**
71
+ * Parse Discord's custom-emoji mention form. The form travels the wire as a
72
+ * reaction's spelling, so more than one package reads it: the daemon rebuilds
73
+ * a REST path from it when the assistant reacts, and a row carrying only the
74
+ * spelling recovers its kind from it. One parser, so the two cannot disagree
75
+ * about what counts as one.
76
+ *
77
+ * `animated` reports whether the spelling carries the `a` marker. Discord's
78
+ * normalizer never writes that marker, so it is read only from spellings that
79
+ * arrive from elsewhere: a row written by another producer, or a value the
80
+ * model hands back as it received it.
81
+ */
82
+ export function parseDiscordEmojiMention(
83
+ emoji: string,
84
+ ): { name: string; id: string; animated: boolean } | null {
85
+ const match = /^<(a?):([^:>]+):(\d+)>$/.exec(emoji);
86
+ return match
87
+ ? { name: match[2]!, id: match[3]!, animated: match[1] === "a" }
88
+ : null;
89
+ }
90
+
91
+ /**
92
+ * Recover an emoji's kind from its spelling alone. This is the one inference
93
+ * the design permits, reserved for a value that carries the string and no
94
+ * typed fields: a persisted row or a replayed retry payload. A value that
95
+ * declares its kind never reaches this; `reactionEmojiIdentity` makes that
96
+ * choice for every reader.
97
+ *
98
+ * A mention form is unambiguous. Past that the two remaining kinds are told
99
+ * apart by whether the string is a name at all: a channel's shortcode is
100
+ * ASCII word characters, optionally carrying Slack's `::skin-tone-N`
101
+ * suffix, and anything else is the character itself.
102
+ */
103
+ export function classifyReactionEmojiSpelling(
104
+ emoji: string,
105
+ ): ReactionEmojiIdentity {
106
+ const custom = parseDiscordEmojiMention(emoji);
107
+ if (custom) {
108
+ // The plain `<:name:id>` form says nothing about animation: the
109
+ // normalizer spells every custom emoji that way and reports animation
110
+ // in the typed field instead, so a spelling without the `a` marker is
111
+ // "unrecorded", not "not animated". Only the `<a:` form asserts it.
112
+ return {
113
+ emojiKind: "custom",
114
+ emojiName: custom.name,
115
+ emojiId: custom.id,
116
+ ...(custom.animated ? { emojiAnimated: true } : {}),
117
+ };
118
+ }
119
+ return /^[\w+-]+(::skin-tone-[2-6])?$/.test(emoji)
120
+ ? { emojiKind: "shortcode", emojiName: emoji }
121
+ : { emojiKind: "unicode", emojiName: emoji };
122
+ }
123
+
124
+ /**
125
+ * The typed identity of a reaction's emoji: the fields it declares when it
126
+ * declares a kind, otherwise the kind recovered from its spelling. Every
127
+ * reader that must know what an emoji is goes through this, so the wire
128
+ * contract and the web agree on when the spelling is consulted.
129
+ */
130
+ export function reactionEmojiIdentity(
131
+ reaction: { emoji: string } & ReactionEmojiFields,
132
+ ): ReactionEmojiIdentity {
133
+ return reaction.emojiKind !== undefined && reaction.emojiName !== undefined
134
+ ? {
135
+ ...pickReactionEmojiFields(reaction),
136
+ emojiKind: reaction.emojiKind,
137
+ emojiName: reaction.emojiName,
138
+ }
139
+ : classifyReactionEmojiSpelling(reaction.emoji);
140
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/credential-executor",
3
- "version": "0.11.11-staging.1",
3
+ "version": "0.11.11-staging.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {