@vellumai/credential-executor 0.11.9-staging.2 → 0.11.9
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.
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
CHANNEL_BOT_PROVIDER,
|
|
5
|
+
CHANNEL_IDS,
|
|
6
|
+
isChannelBotProvider,
|
|
7
|
+
isChannelUserIntegration,
|
|
8
|
+
isChannelId,
|
|
9
|
+
} from "../channels.js";
|
|
4
10
|
|
|
5
11
|
describe("isChannelId", () => {
|
|
6
12
|
test("accepts every canonical channel id", () => {
|
|
@@ -34,3 +40,36 @@ describe("isChannelId", () => {
|
|
|
34
40
|
expect(isChannelId(42)).toBe(false);
|
|
35
41
|
});
|
|
36
42
|
});
|
|
43
|
+
|
|
44
|
+
describe("isChannelUserIntegration", () => {
|
|
45
|
+
test("names the grant standing beside a bot of the same brand", () => {
|
|
46
|
+
expect(isChannelUserIntegration("slack")).toBe(true);
|
|
47
|
+
expect(isChannelUserIntegration("discord")).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("excludes a channel whose bot is its own key", () => {
|
|
51
|
+
// `telegram` names the bot, so no second provider carries the brand and
|
|
52
|
+
// there is nothing to mistake for it.
|
|
53
|
+
expect(isChannelUserIntegration("telegram")).toBe(false);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("excludes the bots themselves and unrelated providers", () => {
|
|
57
|
+
expect(isChannelUserIntegration("slack_channel")).toBe(false);
|
|
58
|
+
expect(isChannelUserIntegration("discord_channel")).toBe(false);
|
|
59
|
+
expect(isChannelUserIntegration("google")).toBe(false);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("is the complement of isChannelBotProvider over the map", () => {
|
|
63
|
+
// The two questions partition the brands that have both halves: a key is
|
|
64
|
+
// one or the other, never both, so a caller picking the wrong one gets an
|
|
65
|
+
// empty answer rather than a plausible wrong one.
|
|
66
|
+
for (const [channelId, botProviderKey] of Object.entries(
|
|
67
|
+
CHANNEL_BOT_PROVIDER,
|
|
68
|
+
)) {
|
|
69
|
+
expect(isChannelUserIntegration(channelId)).toBe(
|
|
70
|
+
channelId !== botProviderKey,
|
|
71
|
+
);
|
|
72
|
+
expect(isChannelBotProvider(botProviderKey)).toBe(true);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -97,3 +97,24 @@ export function isChannelBotProvider(providerKey: string): boolean {
|
|
|
97
97
|
providerKey,
|
|
98
98
|
);
|
|
99
99
|
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Whether a provider key names the user grant of a brand the assistant is
|
|
103
|
+
* reached through some other way: `slack` beside `slack_channel`, `discord`
|
|
104
|
+
* beside `discord_channel`. The other half of the question
|
|
105
|
+
* `isChannelBotProvider` asks.
|
|
106
|
+
*
|
|
107
|
+
* The two halves carry the same brand name, so the grant reads as the way to
|
|
108
|
+
* connect that brand when the bot is. A surface offering people a way to
|
|
109
|
+
* connect an assistant wants the bot, and wants this to say which keys it is
|
|
110
|
+
* answering for rather than naming them itself.
|
|
111
|
+
*
|
|
112
|
+
* A channel whose bot is its own key has no such pair: `telegram` names the
|
|
113
|
+
* bot, so nothing is standing beside it to be mistaken for.
|
|
114
|
+
*/
|
|
115
|
+
export function isChannelUserIntegration(providerKey: string): boolean {
|
|
116
|
+
return Object.entries(CHANNEL_BOT_PROVIDER).some(
|
|
117
|
+
([channelId, botProviderKey]) =>
|
|
118
|
+
channelId === providerKey && botProviderKey !== providerKey,
|
|
119
|
+
);
|
|
120
|
+
}
|