@shipfox/api-integration-slack 10.2.0 → 12.0.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +38 -0
- package/dist/core/agent-tools-provider.d.ts +41 -13
- package/dist/core/agent-tools-provider.d.ts.map +1 -1
- package/dist/core/agent-tools-provider.js +16 -8
- package/dist/core/agent-tools-provider.js.map +1 -1
- package/dist/core/agent-tools.d.ts +154 -21
- package/dist/core/agent-tools.d.ts.map +1 -1
- package/dist/core/agent-tools.js +317 -76
- package/dist/core/agent-tools.js.map +1 -1
- package/dist/core/scopes.d.ts.map +1 -1
- package/dist/core/scopes.js +4 -0
- package/dist/core/scopes.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.test.tsbuildinfo +1 -1
- package/package.json +13 -9
- package/src/core/agent-tools-provider.test.ts +77 -30
- package/src/core/agent-tools-provider.ts +15 -8
- package/src/core/agent-tools.test.ts +204 -33
- package/src/core/agent-tools.ts +355 -62
- package/src/core/install.test.ts +9 -1
- package/src/core/scopes.ts +4 -0
- package/src/index.ts +1 -5
- package/src/presentation/routes/install.test.ts +7 -3
- package/tsconfig.build.tsbuildinfo +1 -1
package/src/core/agent-tools.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
AgentToolSelectionCatalog,
|
|
5
5
|
AgentToolSelector,
|
|
6
6
|
} from '@shipfox/api-integration-spi';
|
|
7
|
+
import type {SlackWebApiResponse} from '#api/client.js';
|
|
7
8
|
|
|
8
9
|
export type SlackAgentToolRequiredScope = 'read' | 'write';
|
|
9
10
|
export type SlackAgentToolCatalogEntry = AgentToolCatalogEntry<SlackAgentToolRequiredScope>;
|
|
@@ -17,130 +18,426 @@ interface SlackAgentToolCatalogInput {
|
|
|
17
18
|
inputSchema: AgentToolJsonSchema;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
const whitespacePattern = /\s+/;
|
|
22
|
+
|
|
23
|
+
// Slack caps the cumulative text across all Markdown blocks in one payload at 12,000 characters;
|
|
24
|
+
// content over that limit is rejected with invalid_blocks rather than truncated. Each tool here
|
|
25
|
+
// sends exactly one Markdown block, so the cap applies to that single block's text.
|
|
26
|
+
const SLACK_MARKDOWN_BLOCK_MAX_LENGTH = 12_000;
|
|
27
|
+
|
|
28
|
+
// Only the chat.* methods resolve a user ID into a direct message; conversations.* and reactions.*
|
|
29
|
+
// need the conversation ID itself, so the two targets are described separately.
|
|
30
|
+
const conversationIdSchema = stringSchema(
|
|
31
|
+
'Channel, private group, or direct message conversation ID, such as C0ABC12345 or D0ABC12345. A user ID is not accepted here',
|
|
32
|
+
);
|
|
33
|
+
const messageTargetSchema = stringSchema(
|
|
34
|
+
'Channel, private group, or direct message conversation ID. Pass a user ID to open a direct message with that user',
|
|
35
|
+
);
|
|
36
|
+
const cursorSchema = stringSchema('Pagination cursor from a previous request');
|
|
37
|
+
const messageSchema = {
|
|
38
|
+
...stringSchema('Message content, written as standard Markdown'),
|
|
39
|
+
maxLength: SLACK_MARKDOWN_BLOCK_MAX_LENGTH,
|
|
40
|
+
};
|
|
41
|
+
const threadTsSchema = stringSchema('Timestamp of the parent message to reply in its thread');
|
|
42
|
+
const replyBroadcastSchema = booleanSchema('Also send the thread reply to the channel');
|
|
23
43
|
|
|
24
44
|
export const slackAgentToolCatalog = [
|
|
25
45
|
tool({
|
|
26
|
-
id: '
|
|
27
|
-
description:
|
|
46
|
+
id: 'read_channel',
|
|
47
|
+
description:
|
|
48
|
+
'Read messages from a Slack channel in reverse chronological order (newest first). Reading direct message history needs the ID of that conversation, not the ID of the user on the other side.',
|
|
28
49
|
sensitivity: 'read',
|
|
29
50
|
sensitive: false,
|
|
30
51
|
requiredScope: 'read',
|
|
31
52
|
inputSchema: objectSchema(
|
|
32
53
|
{
|
|
33
|
-
|
|
54
|
+
channel_id: conversationIdSchema,
|
|
55
|
+
oldest: stringSchema('Start of the time range, as a Slack timestamp'),
|
|
56
|
+
latest: stringSchema('End of the time range, as a Slack timestamp'),
|
|
57
|
+
limit: integerSchema('Messages to return, 1 to 100 (default 100)'),
|
|
34
58
|
cursor: cursorSchema,
|
|
35
|
-
limit: limitSchema,
|
|
36
|
-
oldest: stringSchema('Only messages after this Slack timestamp'),
|
|
37
|
-
latest: stringSchema('Only messages before this Slack timestamp'),
|
|
38
|
-
inclusive: booleanSchema('Include messages at the oldest or latest timestamp'),
|
|
39
59
|
},
|
|
40
|
-
['
|
|
60
|
+
['channel_id'],
|
|
41
61
|
),
|
|
42
62
|
}),
|
|
43
63
|
tool({
|
|
44
|
-
id: '
|
|
45
|
-
description:
|
|
64
|
+
id: 'read_thread',
|
|
65
|
+
description:
|
|
66
|
+
'Read a Slack thread: the parent message and all of its replies. Requires the channel ID and the timestamp of the parent message.',
|
|
46
67
|
sensitivity: 'read',
|
|
47
68
|
sensitive: false,
|
|
48
69
|
requiredScope: 'read',
|
|
49
70
|
inputSchema: objectSchema(
|
|
50
71
|
{
|
|
51
|
-
|
|
52
|
-
|
|
72
|
+
channel_id: conversationIdSchema,
|
|
73
|
+
message_ts: stringSchema('Timestamp of the parent message, such as 1234567890.123456'),
|
|
74
|
+
oldest: stringSchema('Start of the time range, as a Slack timestamp'),
|
|
75
|
+
latest: stringSchema('End of the time range, as a Slack timestamp'),
|
|
76
|
+
limit: integerSchema('Messages to return, 1 to 1000 (default 100)'),
|
|
53
77
|
cursor: cursorSchema,
|
|
54
|
-
limit: limitSchema,
|
|
55
78
|
},
|
|
56
|
-
['
|
|
79
|
+
['channel_id', 'message_ts'],
|
|
57
80
|
),
|
|
58
81
|
}),
|
|
59
82
|
tool({
|
|
60
|
-
id: '
|
|
61
|
-
description:
|
|
83
|
+
id: 'read_channel_info',
|
|
84
|
+
description:
|
|
85
|
+
'Retrieve metadata for a single Slack channel by ID: name, topic, purpose, privacy, and archive status. Use this to learn what a channel is for before reading or posting. To read its messages, use read_channel instead.',
|
|
62
86
|
sensitivity: 'read',
|
|
63
87
|
sensitive: false,
|
|
64
88
|
requiredScope: 'read',
|
|
65
|
-
inputSchema: objectSchema(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
89
|
+
inputSchema: objectSchema(
|
|
90
|
+
{
|
|
91
|
+
channel_id: conversationIdSchema,
|
|
92
|
+
include_num_members: booleanSchema('Include the channel member count (default false)'),
|
|
93
|
+
},
|
|
94
|
+
['channel_id'],
|
|
95
|
+
),
|
|
96
|
+
}),
|
|
97
|
+
tool({
|
|
98
|
+
id: 'read_channel_members',
|
|
99
|
+
description:
|
|
100
|
+
'List the user IDs of the members of a Slack channel. Pair it with read_user_profile to resolve a member to a name.',
|
|
101
|
+
sensitivity: 'read',
|
|
102
|
+
sensitive: false,
|
|
103
|
+
requiredScope: 'read',
|
|
104
|
+
inputSchema: objectSchema(
|
|
105
|
+
{
|
|
106
|
+
channel_id: conversationIdSchema,
|
|
107
|
+
limit: integerSchema('Members to return per page (default 100)'),
|
|
108
|
+
cursor: cursorSchema,
|
|
109
|
+
},
|
|
110
|
+
['channel_id'],
|
|
111
|
+
),
|
|
71
112
|
}),
|
|
72
113
|
tool({
|
|
73
|
-
id: '
|
|
74
|
-
description:
|
|
114
|
+
id: 'read_user_profile',
|
|
115
|
+
description:
|
|
116
|
+
'Retrieve profile information for a Slack user, including contact details, status, timezone, and role.',
|
|
75
117
|
sensitivity: 'read',
|
|
76
118
|
sensitive: false,
|
|
77
119
|
requiredScope: 'read',
|
|
78
|
-
inputSchema: objectSchema(
|
|
120
|
+
inputSchema: objectSchema(
|
|
121
|
+
{
|
|
122
|
+
user_id: stringSchema('Slack user ID, such as U0ABC12345'),
|
|
123
|
+
include_locale: booleanSchema("Include the user's locale information (default false)"),
|
|
124
|
+
},
|
|
125
|
+
['user_id'],
|
|
126
|
+
),
|
|
127
|
+
}),
|
|
128
|
+
tool({
|
|
129
|
+
id: 'search_channels',
|
|
130
|
+
description:
|
|
131
|
+
'Search the channels this integration can see, by name, topic, or purpose. Returns channel names, IDs, topics, purposes, and archive status. Names are typically lowercase with hyphens. Space-separated terms all have to match. Only the requested page is searched, so page through with the returned cursor when a channel is missing.',
|
|
132
|
+
sensitivity: 'read',
|
|
133
|
+
sensitive: false,
|
|
134
|
+
requiredScope: 'read',
|
|
135
|
+
inputSchema: objectSchema(
|
|
136
|
+
{
|
|
137
|
+
query: stringSchema('Search query for finding channels'),
|
|
138
|
+
channel_types: stringSchema(
|
|
139
|
+
'Comma-separated channel types: public_channel, private_channel. Defaults to public_channel',
|
|
140
|
+
),
|
|
141
|
+
include_archived: booleanSchema('Include archived channels in the results'),
|
|
142
|
+
limit: integerSchema('Channels to scan per page (default 100)'),
|
|
143
|
+
cursor: cursorSchema,
|
|
144
|
+
},
|
|
145
|
+
['query'],
|
|
146
|
+
),
|
|
147
|
+
}),
|
|
148
|
+
tool({
|
|
149
|
+
id: 'send_message',
|
|
150
|
+
description:
|
|
151
|
+
'Send a message to a Slack channel or user. To send a direct message, pass the user ID as the channel ID. Supports standard Markdown: bold, italic, strikethrough, links, lists, blockquotes, inline code, and code blocks. Returns the posted message timestamp.',
|
|
152
|
+
sensitivity: 'write',
|
|
153
|
+
sensitive: false,
|
|
154
|
+
requiredScope: 'write',
|
|
155
|
+
inputSchema: objectSchema(
|
|
156
|
+
{
|
|
157
|
+
channel_id: messageTargetSchema,
|
|
158
|
+
message: messageSchema,
|
|
159
|
+
thread_ts: threadTsSchema,
|
|
160
|
+
reply_broadcast: replyBroadcastSchema,
|
|
161
|
+
},
|
|
162
|
+
['channel_id', 'message'],
|
|
163
|
+
),
|
|
79
164
|
}),
|
|
80
165
|
tool({
|
|
81
|
-
id: '
|
|
82
|
-
description:
|
|
166
|
+
id: 'schedule_message',
|
|
167
|
+
description:
|
|
168
|
+
'Schedule a message for future delivery to a Slack channel. Does not send immediately. post_at has to be at least 2 minutes in the future and at most 120 days out. Once scheduled, the message cannot be edited.',
|
|
83
169
|
sensitivity: 'write',
|
|
84
170
|
sensitive: false,
|
|
85
171
|
requiredScope: 'write',
|
|
86
172
|
inputSchema: objectSchema(
|
|
87
173
|
{
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
174
|
+
channel_id: messageTargetSchema,
|
|
175
|
+
message: messageSchema,
|
|
176
|
+
post_at: integerSchema('Unix timestamp at which to send the message'),
|
|
177
|
+
thread_ts: threadTsSchema,
|
|
178
|
+
reply_broadcast: replyBroadcastSchema,
|
|
92
179
|
},
|
|
93
|
-
['
|
|
180
|
+
['channel_id', 'message', 'post_at'],
|
|
94
181
|
),
|
|
95
182
|
}),
|
|
96
183
|
tool({
|
|
97
|
-
id: '
|
|
98
|
-
description:
|
|
184
|
+
id: 'update_message',
|
|
185
|
+
description:
|
|
186
|
+
'Update an already posted Slack message, replacing its content. Supports the same standard Markdown as send_message.',
|
|
99
187
|
sensitivity: 'write',
|
|
100
188
|
sensitive: false,
|
|
101
189
|
requiredScope: 'write',
|
|
102
190
|
inputSchema: objectSchema(
|
|
103
191
|
{
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
blocks: arraySchema({type: 'object'}),
|
|
192
|
+
channel_id: conversationIdSchema,
|
|
193
|
+
message_ts: stringSchema('Timestamp of the message to update'),
|
|
194
|
+
message: messageSchema,
|
|
108
195
|
},
|
|
109
|
-
['
|
|
196
|
+
['channel_id', 'message_ts', 'message'],
|
|
110
197
|
),
|
|
111
198
|
}),
|
|
112
199
|
tool({
|
|
113
|
-
id: '
|
|
200
|
+
id: 'add_reaction',
|
|
114
201
|
description: 'Add an emoji reaction to a Slack message.',
|
|
115
202
|
sensitivity: 'write',
|
|
116
203
|
sensitive: false,
|
|
117
204
|
requiredScope: 'write',
|
|
118
205
|
inputSchema: objectSchema(
|
|
119
206
|
{
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
207
|
+
channel_id: conversationIdSchema,
|
|
208
|
+
message_ts: stringSchema('Timestamp of the message to react to'),
|
|
209
|
+
emoji: stringSchema('Emoji name without the surrounding colons, such as white_check_mark'),
|
|
210
|
+
},
|
|
211
|
+
['channel_id', 'message_ts', 'emoji'],
|
|
212
|
+
),
|
|
213
|
+
}),
|
|
214
|
+
tool({
|
|
215
|
+
id: 'create_canvas',
|
|
216
|
+
description:
|
|
217
|
+
'Create a standalone Slack canvas from Markdown and return its ID. Not available on free teams.',
|
|
218
|
+
sensitivity: 'write',
|
|
219
|
+
sensitive: false,
|
|
220
|
+
requiredScope: 'write',
|
|
221
|
+
inputSchema: objectSchema(
|
|
222
|
+
{
|
|
223
|
+
title: stringSchema('Concise, descriptive canvas name. Do not repeat it in the content'),
|
|
224
|
+
content: stringSchema('Canvas body, written as standard Markdown'),
|
|
123
225
|
},
|
|
124
|
-
['
|
|
226
|
+
['title', 'content'],
|
|
125
227
|
),
|
|
126
228
|
}),
|
|
127
229
|
] as const satisfies readonly SlackAgentToolCatalogEntry[];
|
|
128
230
|
|
|
129
231
|
export type SlackAgentToolId = (typeof slackAgentToolCatalog)[number]['id'];
|
|
130
232
|
|
|
131
|
-
export
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
233
|
+
export interface SlackToolOperation {
|
|
234
|
+
method: string;
|
|
235
|
+
mapArguments: (args: Record<string, unknown>) => Record<string, unknown>;
|
|
236
|
+
mapOutput?: (body: SlackWebApiResponse, args: Record<string, unknown>) => SlackWebApiResponse;
|
|
237
|
+
validate?: (args: Record<string, unknown>) => SlackToolValidationError | undefined;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export interface SlackToolValidationError {
|
|
241
|
+
message: string;
|
|
242
|
+
code?: string | undefined;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Tool inputs follow the Slack MCP server's naming so agent prompts port across both, which means
|
|
246
|
+
// every call is translated to the Web API's own parameter names before it is sent.
|
|
247
|
+
export const SLACK_TOOL_OPERATIONS = {
|
|
248
|
+
read_channel: {
|
|
249
|
+
method: 'conversations.history',
|
|
250
|
+
mapArguments: ({channel_id, oldest, latest, limit, cursor}) => ({
|
|
251
|
+
channel: channel_id,
|
|
252
|
+
oldest,
|
|
253
|
+
latest,
|
|
254
|
+
limit,
|
|
255
|
+
cursor,
|
|
256
|
+
}),
|
|
257
|
+
},
|
|
258
|
+
read_thread: {
|
|
259
|
+
method: 'conversations.replies',
|
|
260
|
+
mapArguments: ({channel_id, message_ts, oldest, latest, limit, cursor}) => ({
|
|
261
|
+
channel: channel_id,
|
|
262
|
+
ts: message_ts,
|
|
263
|
+
oldest,
|
|
264
|
+
latest,
|
|
265
|
+
limit,
|
|
266
|
+
cursor,
|
|
267
|
+
}),
|
|
268
|
+
},
|
|
269
|
+
read_channel_info: {
|
|
270
|
+
method: 'conversations.info',
|
|
271
|
+
mapArguments: ({channel_id, include_num_members}) => ({
|
|
272
|
+
channel: channel_id,
|
|
273
|
+
include_num_members,
|
|
274
|
+
}),
|
|
275
|
+
},
|
|
276
|
+
read_channel_members: {
|
|
277
|
+
method: 'conversations.members',
|
|
278
|
+
mapArguments: ({channel_id, limit, cursor}) => ({channel: channel_id, limit, cursor}),
|
|
279
|
+
},
|
|
280
|
+
read_user_profile: {
|
|
281
|
+
method: 'users.info',
|
|
282
|
+
mapArguments: ({user_id, include_locale}) => ({user: user_id, include_locale}),
|
|
283
|
+
},
|
|
284
|
+
search_channels: {
|
|
285
|
+
method: 'conversations.list',
|
|
286
|
+
mapArguments: ({channel_types, include_archived, limit, cursor}) => ({
|
|
287
|
+
types: channel_types,
|
|
288
|
+
exclude_archived: include_archived !== true,
|
|
289
|
+
limit,
|
|
290
|
+
cursor,
|
|
291
|
+
}),
|
|
292
|
+
mapOutput: matchingChannels,
|
|
293
|
+
},
|
|
294
|
+
send_message: {
|
|
295
|
+
method: 'chat.postMessage',
|
|
296
|
+
mapArguments: ({channel_id, message, thread_ts, reply_broadcast}) => ({
|
|
297
|
+
channel: channel_id,
|
|
298
|
+
...markdownMessage(message),
|
|
299
|
+
thread_ts,
|
|
300
|
+
reply_broadcast,
|
|
301
|
+
}),
|
|
302
|
+
validate: validateMessageLength,
|
|
303
|
+
},
|
|
304
|
+
schedule_message: {
|
|
305
|
+
method: 'chat.scheduleMessage',
|
|
306
|
+
mapArguments: ({channel_id, message, post_at, thread_ts, reply_broadcast}) => ({
|
|
307
|
+
channel: channel_id,
|
|
308
|
+
...markdownMessage(message),
|
|
309
|
+
post_at,
|
|
310
|
+
thread_ts,
|
|
311
|
+
reply_broadcast,
|
|
312
|
+
}),
|
|
313
|
+
validate: validateMessageLength,
|
|
314
|
+
},
|
|
315
|
+
update_message: {
|
|
316
|
+
method: 'chat.update',
|
|
317
|
+
mapArguments: ({channel_id, message_ts, message}) => ({
|
|
318
|
+
channel: channel_id,
|
|
319
|
+
ts: message_ts,
|
|
320
|
+
...markdownMessage(message),
|
|
321
|
+
}),
|
|
322
|
+
validate: validateMessageLength,
|
|
323
|
+
},
|
|
324
|
+
add_reaction: {
|
|
325
|
+
method: 'reactions.add',
|
|
326
|
+
mapArguments: ({channel_id, message_ts, emoji}) => ({
|
|
327
|
+
channel: channel_id,
|
|
328
|
+
timestamp: message_ts,
|
|
329
|
+
name: emoji,
|
|
330
|
+
}),
|
|
331
|
+
},
|
|
332
|
+
create_canvas: {
|
|
333
|
+
method: 'canvases.create',
|
|
334
|
+
mapArguments: ({title, content}) => ({
|
|
335
|
+
title,
|
|
336
|
+
document_content: {type: 'markdown', markdown: content},
|
|
337
|
+
}),
|
|
338
|
+
},
|
|
339
|
+
} as const satisfies Record<SlackAgentToolId, SlackToolOperation>;
|
|
140
340
|
|
|
141
341
|
export const slackAgentToolSelectionCatalog =
|
|
142
342
|
buildSlackAgentToolSelectionCatalog(slackAgentToolCatalog);
|
|
143
343
|
|
|
344
|
+
// A Markdown block renders standard Markdown, which the plain text field does not; text is kept as
|
|
345
|
+
// the notification fallback, so its Markdown syntax is stripped rather than shown literally.
|
|
346
|
+
function markdownMessage(message: unknown): Record<string, unknown> {
|
|
347
|
+
if (typeof message !== 'string') return {};
|
|
348
|
+
return {text: stripMarkdownForFallback(message), blocks: [{type: 'markdown', text: message}]};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const codeBlockPattern = /```[^\n]*\n?([\s\S]*?)\n?```/g;
|
|
352
|
+
const inlineCodePattern = /`([^`]+)`/g;
|
|
353
|
+
const linkPattern = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
354
|
+
const boldPattern = /\*\*([^*]+)\*\*|__([^_]+)__/g;
|
|
355
|
+
const strikethroughPattern = /~~([^~]+)~~/g;
|
|
356
|
+
const italicPattern = /\*([^*]+)\*|_([^_]+)_/g;
|
|
357
|
+
const blockquotePattern = /^>\s?/gm;
|
|
358
|
+
// Reserved code spans are wrapped in a delimiter built at runtime (String.fromCharCode) rather than
|
|
359
|
+
// a literal escape in source. A real chat message is vanishingly unlikely to contain a NUL byte, but
|
|
360
|
+
// isn't guaranteed not to, so any that do appear are stripped from the input first. After that, the
|
|
361
|
+
// only NUL bytes left are the ones this function inserts, so restoration can't misfire on user text.
|
|
362
|
+
const codePlaceholderDelimiter = String.fromCharCode(0);
|
|
363
|
+
const codePlaceholderPattern = new RegExp(
|
|
364
|
+
`${codePlaceholderDelimiter}(\\d+)${codePlaceholderDelimiter}`,
|
|
365
|
+
'g',
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
// Best-effort plain-text rendering of the Markdown syntax the tool description promises (bold,
|
|
369
|
+
// italic, strikethrough, links, lists, blockquotes, inline code, code blocks); lists are left as-is
|
|
370
|
+
// since "- item" and "1. item" already read fine as plain text. Code spans are pulled out behind a
|
|
371
|
+
// placeholder first so their own *, _, ~, and [] characters survive the other replacements intact.
|
|
372
|
+
function stripMarkdownForFallback(message: string): string {
|
|
373
|
+
const codeSpans: string[] = [];
|
|
374
|
+
const reserveCodeSpan = (_match: string, code: string): string =>
|
|
375
|
+
`${codePlaceholderDelimiter}${codeSpans.push(code) - 1}${codePlaceholderDelimiter}`;
|
|
376
|
+
|
|
377
|
+
return message
|
|
378
|
+
.replaceAll(codePlaceholderDelimiter, '')
|
|
379
|
+
.replace(codeBlockPattern, reserveCodeSpan)
|
|
380
|
+
.replace(inlineCodePattern, reserveCodeSpan)
|
|
381
|
+
.replace(linkPattern, (_match, text: string, url: string) => `${text} (${url})`)
|
|
382
|
+
.replace(
|
|
383
|
+
boldPattern,
|
|
384
|
+
(_match, asterisk?: string, underscore?: string) => asterisk ?? underscore ?? '',
|
|
385
|
+
)
|
|
386
|
+
.replace(strikethroughPattern, (_match, text: string) => text)
|
|
387
|
+
.replace(
|
|
388
|
+
italicPattern,
|
|
389
|
+
(_match, asterisk?: string, underscore?: string) => asterisk ?? underscore ?? '',
|
|
390
|
+
)
|
|
391
|
+
.replace(blockquotePattern, '')
|
|
392
|
+
.replace(codePlaceholderPattern, (_match, index: string) => codeSpans[Number(index)] ?? '');
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function validateMessageLength(
|
|
396
|
+
args: Record<string, unknown>,
|
|
397
|
+
): SlackToolValidationError | undefined {
|
|
398
|
+
const {message} = args;
|
|
399
|
+
if (typeof message !== 'string') return undefined;
|
|
400
|
+
// .length counts UTF-16 code units, so astral-plane characters (most emoji) count twice and
|
|
401
|
+
// would reject messages the 12,000-character schema limit still allows; the spread operator
|
|
402
|
+
// iterates by Unicode code point instead.
|
|
403
|
+
const length = [...message].length;
|
|
404
|
+
if (length > SLACK_MARKDOWN_BLOCK_MAX_LENGTH) {
|
|
405
|
+
return {
|
|
406
|
+
message: `Message is ${length.toLocaleString('en-US')} characters, which exceeds Slack's ${SLACK_MARKDOWN_BLOCK_MAX_LENGTH.toLocaleString('en-US')}-character Markdown block limit. Shorten it or split it into multiple messages.`,
|
|
407
|
+
code: 'content-too-large',
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
return undefined;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// Slack has no channel search method for bot tokens, so the requested page is matched locally.
|
|
414
|
+
function matchingChannels(
|
|
415
|
+
body: SlackWebApiResponse,
|
|
416
|
+
args: Record<string, unknown>,
|
|
417
|
+
): SlackWebApiResponse {
|
|
418
|
+
const {query} = args;
|
|
419
|
+
const {channels} = body;
|
|
420
|
+
if (typeof query !== 'string' || !Array.isArray(channels)) return body;
|
|
421
|
+
const terms = query.toLowerCase().split(whitespacePattern).filter(Boolean);
|
|
422
|
+
if (terms.length === 0) return body;
|
|
423
|
+
return {...body, channels: channels.filter((channel) => matchesTerms(channel, terms))};
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function matchesTerms(channel: unknown, terms: string[]): boolean {
|
|
427
|
+
if (typeof channel !== 'object' || channel === null) return false;
|
|
428
|
+
const {name, topic, purpose} = channel as Record<string, unknown>;
|
|
429
|
+
const haystack = [name, textValue(topic), textValue(purpose)]
|
|
430
|
+
.filter((value): value is string => typeof value === 'string')
|
|
431
|
+
.join(' ')
|
|
432
|
+
.toLowerCase();
|
|
433
|
+
return terms.every((term) => haystack.includes(term));
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function textValue(field: unknown): unknown {
|
|
437
|
+
if (typeof field !== 'object' || field === null) return undefined;
|
|
438
|
+
return (field as Record<string, unknown>).value;
|
|
439
|
+
}
|
|
440
|
+
|
|
144
441
|
function buildSlackAgentToolSelectionCatalog(
|
|
145
442
|
catalog: readonly SlackAgentToolCatalogEntry[],
|
|
146
443
|
): AgentToolSelectionCatalog {
|
|
@@ -176,14 +473,10 @@ function stringSchema(description?: string): AgentToolJsonSchema {
|
|
|
176
473
|
return {type: 'string', ...(description ? {description} : {})};
|
|
177
474
|
}
|
|
178
475
|
|
|
179
|
-
function
|
|
180
|
-
return {type: '
|
|
476
|
+
function integerSchema(description: string): AgentToolJsonSchema {
|
|
477
|
+
return {type: 'integer', description};
|
|
181
478
|
}
|
|
182
479
|
|
|
183
480
|
function booleanSchema(description: string): AgentToolJsonSchema {
|
|
184
481
|
return {type: 'boolean', description};
|
|
185
482
|
}
|
|
186
|
-
|
|
187
|
-
function arraySchema(items: AgentToolJsonSchema): AgentToolJsonSchema {
|
|
188
|
-
return {type: 'array', items};
|
|
189
|
-
}
|
package/src/core/install.test.ts
CHANGED
|
@@ -15,6 +15,9 @@ function authorization(overrides: Record<string, unknown> = {}) {
|
|
|
15
15
|
scopes: [
|
|
16
16
|
'app_mentions:read',
|
|
17
17
|
'im:history',
|
|
18
|
+
'im:read',
|
|
19
|
+
'mpim:history',
|
|
20
|
+
'mpim:read',
|
|
18
21
|
'chat:write',
|
|
19
22
|
'channels:history',
|
|
20
23
|
'groups:history',
|
|
@@ -23,6 +26,7 @@ function authorization(overrides: Record<string, unknown> = {}) {
|
|
|
23
26
|
'users:read',
|
|
24
27
|
'reactions:read',
|
|
25
28
|
'reactions:write',
|
|
29
|
+
'canvases:write',
|
|
26
30
|
'commands',
|
|
27
31
|
],
|
|
28
32
|
...overrides,
|
|
@@ -62,7 +66,11 @@ function callbackParams(
|
|
|
62
66
|
}),
|
|
63
67
|
sessionUserId: 'user-1',
|
|
64
68
|
sessionMemberships: [
|
|
65
|
-
{
|
|
69
|
+
{
|
|
70
|
+
workspaceId: '00000000-0000-4000-8000-000000000002',
|
|
71
|
+
role: 'admin',
|
|
72
|
+
workspaceStatus: 'active',
|
|
73
|
+
},
|
|
66
74
|
] satisfies UserContextMembership[],
|
|
67
75
|
requireWorkspaceMembership: vi.fn(() => Promise.resolve()),
|
|
68
76
|
getExistingSlackConnection: vi.fn(() => Promise.resolve(undefined)),
|
package/src/core/scopes.ts
CHANGED
|
@@ -3,6 +3,9 @@ import {SlackAuthorizationScopeMismatchError} from './errors.js';
|
|
|
3
3
|
export const SLACK_BOT_SCOPES = Object.freeze([
|
|
4
4
|
'app_mentions:read',
|
|
5
5
|
'im:history',
|
|
6
|
+
'im:read',
|
|
7
|
+
'mpim:history',
|
|
8
|
+
'mpim:read',
|
|
6
9
|
'chat:write',
|
|
7
10
|
'channels:history',
|
|
8
11
|
'groups:history',
|
|
@@ -11,6 +14,7 @@ export const SLACK_BOT_SCOPES = Object.freeze([
|
|
|
11
14
|
'users:read',
|
|
12
15
|
'reactions:read',
|
|
13
16
|
'reactions:write',
|
|
17
|
+
'canvases:write',
|
|
14
18
|
'commands',
|
|
15
19
|
]);
|
|
16
20
|
|
package/src/index.ts
CHANGED
|
@@ -32,11 +32,7 @@ export type {
|
|
|
32
32
|
SlackAgentToolId,
|
|
33
33
|
SlackAgentToolRequiredScope,
|
|
34
34
|
} from '#core/agent-tools.js';
|
|
35
|
-
export {
|
|
36
|
-
SLACK_TOOL_METHODS,
|
|
37
|
-
slackAgentToolCatalog,
|
|
38
|
-
slackAgentToolSelectionCatalog,
|
|
39
|
-
} from '#core/agent-tools.js';
|
|
35
|
+
export {slackAgentToolCatalog, slackAgentToolSelectionCatalog} from '#core/agent-tools.js';
|
|
40
36
|
export type {
|
|
41
37
|
SlackAgentToolsProviderOptions,
|
|
42
38
|
SlackToolCallResult,
|
|
@@ -47,6 +47,9 @@ function slackClient(overrides: Partial<SlackApiClient> = {}): SlackApiClient {
|
|
|
47
47
|
scopes: [
|
|
48
48
|
'app_mentions:read',
|
|
49
49
|
'im:history',
|
|
50
|
+
'im:read',
|
|
51
|
+
'mpim:history',
|
|
52
|
+
'mpim:read',
|
|
50
53
|
'chat:write',
|
|
51
54
|
'channels:history',
|
|
52
55
|
'groups:history',
|
|
@@ -55,6 +58,7 @@ function slackClient(overrides: Partial<SlackApiClient> = {}): SlackApiClient {
|
|
|
55
58
|
'users:read',
|
|
56
59
|
'reactions:read',
|
|
57
60
|
'reactions:write',
|
|
61
|
+
'canvases:write',
|
|
58
62
|
'commands',
|
|
59
63
|
],
|
|
60
64
|
}),
|
|
@@ -123,7 +127,7 @@ describe('Slack integration routes', () => {
|
|
|
123
127
|
it('returns Slack’s bot-only OAuth URL with signed workspace state', async () => {
|
|
124
128
|
const app = await createTestApp();
|
|
125
129
|
const workspaceId = '00000000-0000-4000-8000-000000000002';
|
|
126
|
-
authenticatedMemberships = [{workspaceId, role: 'admin'}];
|
|
130
|
+
authenticatedMemberships = [{workspaceId, role: 'admin', workspaceStatus: 'active'}];
|
|
127
131
|
|
|
128
132
|
const res = await app.inject({
|
|
129
133
|
method: 'POST',
|
|
@@ -172,7 +176,7 @@ describe('Slack integration routes', () => {
|
|
|
172
176
|
const tokenStore = {storeTokens: vi.fn(() => Promise.resolve())};
|
|
173
177
|
const app = await createTestApp({tokenStore, agentTools});
|
|
174
178
|
const workspaceId = '00000000-0000-4000-8000-000000000002';
|
|
175
|
-
authenticatedMemberships = [{workspaceId, role: 'admin'}];
|
|
179
|
+
authenticatedMemberships = [{workspaceId, role: 'admin', workspaceStatus: 'active'}];
|
|
176
180
|
const install = await app.inject({
|
|
177
181
|
method: 'POST',
|
|
178
182
|
url: '/integrations/slack/install',
|
|
@@ -205,7 +209,7 @@ describe('Slack integration routes', () => {
|
|
|
205
209
|
});
|
|
206
210
|
const app = await createTestApp({slack, tokenStore});
|
|
207
211
|
const workspaceId = '00000000-0000-4000-8000-000000000002';
|
|
208
|
-
authenticatedMemberships = [{workspaceId, role: 'admin'}];
|
|
212
|
+
authenticatedMemberships = [{workspaceId, role: 'admin', workspaceStatus: 'active'}];
|
|
209
213
|
const install = await app.inject({
|
|
210
214
|
method: 'POST',
|
|
211
215
|
url: '/integrations/slack/install',
|