@cuylabs/channel-slack-agent-core 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/README.md +80 -0
- package/dist/adapter-Cmd2C90g.d.ts +31 -0
- package/dist/adapter.d.ts +23 -0
- package/dist/adapter.js +13 -0
- package/dist/app-surface.d.ts +71 -0
- package/dist/app-surface.js +12 -0
- package/dist/app.d.ts +54 -0
- package/dist/app.js +14 -0
- package/dist/assistant.d.ts +19 -0
- package/dist/assistant.js +16 -0
- package/dist/bolt.d.ts +8 -0
- package/dist/bolt.js +10 -0
- package/dist/chunk-2SUAW6MV.js +12 -0
- package/dist/chunk-645NNJIM.js +12 -0
- package/dist/chunk-ANIZ5NT4.js +12 -0
- package/dist/chunk-BFUPAJON.js +662 -0
- package/dist/chunk-CYEBGC6G.js +77 -0
- package/dist/chunk-DHPD4XH5.js +827 -0
- package/dist/chunk-FDRQOG7Q.js +471 -0
- package/dist/chunk-GNXWTKQ6.js +48 -0
- package/dist/chunk-HFT2FXJP.js +12 -0
- package/dist/chunk-I2KLQ2HA.js +22 -0
- package/dist/chunk-IWUYIAY5.js +69 -0
- package/dist/chunk-IXY3BXU5.js +689 -0
- package/dist/chunk-JMLB7A2V.js +85 -0
- package/dist/chunk-K2E6A377.js +12 -0
- package/dist/chunk-M64Z6TYL.js +198 -0
- package/dist/chunk-NDVXBI7Z.js +12 -0
- package/dist/chunk-NIPAN4KA.js +76 -0
- package/dist/chunk-PX4RGO3N.js +12 -0
- package/dist/chunk-RFHXERNL.js +27 -0
- package/dist/chunk-VHGV66M7.js +12 -0
- package/dist/chunk-WO4BJMF3.js +82 -0
- package/dist/diagnostics.d.ts +1 -0
- package/dist/diagnostics.js +10 -0
- package/dist/express-assistant.d.ts +102 -0
- package/dist/express-assistant.js +12 -0
- package/dist/express.d.ts +98 -0
- package/dist/express.js +11 -0
- package/dist/feedback.d.ts +1 -0
- package/dist/feedback.js +10 -0
- package/dist/history.d.ts +1 -0
- package/dist/history.js +10 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +202 -0
- package/dist/interactive-o_NZb-Xg.d.ts +47 -0
- package/dist/interactive.d.ts +30 -0
- package/dist/interactive.js +25 -0
- package/dist/mcp.d.ts +84 -0
- package/dist/mcp.js +9 -0
- package/dist/options-C7OYeNR-.d.ts +71 -0
- package/dist/options-Uf-qmQKN.d.ts +263 -0
- package/dist/policy.d.ts +1 -0
- package/dist/policy.js +10 -0
- package/dist/setup.d.ts +1 -0
- package/dist/setup.js +10 -0
- package/dist/shared.d.ts +129 -0
- package/dist/shared.js +20 -0
- package/dist/socket.d.ts +137 -0
- package/dist/socket.js +16 -0
- package/dist/targets.d.ts +1 -0
- package/dist/targets.js +10 -0
- package/dist/types-BqRzb_Cd.d.ts +346 -0
- package/dist/types-Crpil4kb.d.ts +136 -0
- package/dist/users.d.ts +1 -0
- package/dist/users.js +10 -0
- package/package.json +169 -0
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
import {
|
|
2
|
+
extractSlackAuthContext,
|
|
3
|
+
extractSlackUserIdentity,
|
|
4
|
+
isProcessableMessage,
|
|
5
|
+
parseSlackMentionActivity,
|
|
6
|
+
parseSlackMessageActivity,
|
|
7
|
+
resolveSlackMessageFormatter
|
|
8
|
+
} from "./chunk-GNXWTKQ6.js";
|
|
9
|
+
import {
|
|
10
|
+
UnsupportedSlackInteractiveRequestError,
|
|
11
|
+
bridgeAgentEventsToSlack,
|
|
12
|
+
resolveSlackEventBridgeOptions,
|
|
13
|
+
runWithSlackTurnContext
|
|
14
|
+
} from "./chunk-DHPD4XH5.js";
|
|
15
|
+
|
|
16
|
+
// src/shared/session.ts
|
|
17
|
+
import { resolveThreadAwareSlackSessionId } from "@cuylabs/channel-slack/core";
|
|
18
|
+
|
|
19
|
+
// src/adapter/session-map.ts
|
|
20
|
+
function createSlackSessionMap(options) {
|
|
21
|
+
const strategy = options.sessionStrategy ?? "thread-aware";
|
|
22
|
+
if (strategy === "custom") {
|
|
23
|
+
if (!options.resolveSessionId) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
"SlackChannelOptions.resolveSessionId is required when sessionStrategy is 'custom'"
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
const customResolve = options.resolveSessionId;
|
|
29
|
+
return {
|
|
30
|
+
resolve(info) {
|
|
31
|
+
return customResolve(info);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
if (strategy === "channel-id") {
|
|
36
|
+
return {
|
|
37
|
+
resolve(info) {
|
|
38
|
+
return info.channelId;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
if (strategy === "user-per-channel") {
|
|
43
|
+
return {
|
|
44
|
+
resolve(info) {
|
|
45
|
+
return `${info.channelId}:${info.userId}`;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (strategy === "user-per-thread") {
|
|
50
|
+
return {
|
|
51
|
+
resolve(info) {
|
|
52
|
+
if (info.channelType === "dm") {
|
|
53
|
+
return `${info.channelId}:${info.userId}`;
|
|
54
|
+
}
|
|
55
|
+
return `${info.channelId}:${info.threadTs ?? info.messageTs ?? info.channelId}:${info.userId}`;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
resolve: resolveThreadAwareSlackSessionId
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/adapter/adapter.ts
|
|
65
|
+
import { withinScope } from "@cuylabs/agent-core";
|
|
66
|
+
|
|
67
|
+
// src/adapter/sink.ts
|
|
68
|
+
function buildThreadPayload(info, respondInThread) {
|
|
69
|
+
if (!respondInThread || info.channelType === "dm") return {};
|
|
70
|
+
const threadTs = info.threadTs ?? info.messageTs;
|
|
71
|
+
return threadTs ? { thread_ts: threadTs } : {};
|
|
72
|
+
}
|
|
73
|
+
function buildResponseSink(say, client, info, respondInThread, chatStreamStartArgs, sayStream) {
|
|
74
|
+
const threadPayload = buildThreadPayload(info, respondInThread);
|
|
75
|
+
return {
|
|
76
|
+
async postMessage(text) {
|
|
77
|
+
const result = await say({ text, ...threadPayload });
|
|
78
|
+
const response = result;
|
|
79
|
+
const { channel, ts } = response;
|
|
80
|
+
if (!channel || !ts) {
|
|
81
|
+
throw new Error("Slack say() response did not include channel and ts.");
|
|
82
|
+
}
|
|
83
|
+
return { channel, ts };
|
|
84
|
+
},
|
|
85
|
+
async updateMessage(channel, ts, text) {
|
|
86
|
+
await client.chat.update({ channel, ts, text });
|
|
87
|
+
},
|
|
88
|
+
createChatStream({ bufferSize }) {
|
|
89
|
+
const threadTs = threadPayload.thread_ts ?? info.messageTs;
|
|
90
|
+
if (!threadTs) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
"Slack chat-stream mode requires a source message timestamp."
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
const streamArgs = {
|
|
96
|
+
...chatStreamStartArgs ?? {},
|
|
97
|
+
buffer_size: bufferSize
|
|
98
|
+
};
|
|
99
|
+
if (typeof sayStream === "function") {
|
|
100
|
+
return sayStream(streamArgs);
|
|
101
|
+
}
|
|
102
|
+
const streamer = client.chatStream({
|
|
103
|
+
channel: info.channelId,
|
|
104
|
+
thread_ts: threadTs,
|
|
105
|
+
...info.teamId ? { recipient_team_id: info.teamId } : {},
|
|
106
|
+
recipient_user_id: info.userId,
|
|
107
|
+
...streamArgs
|
|
108
|
+
});
|
|
109
|
+
return streamer;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function buildInteractiveResponder(say, client, info, respondInThread) {
|
|
114
|
+
const threadPayload = buildThreadPayload(info, respondInThread);
|
|
115
|
+
return {
|
|
116
|
+
async postMessage(message) {
|
|
117
|
+
const result = await say({
|
|
118
|
+
text: message.text,
|
|
119
|
+
...message.blocks ? { blocks: message.blocks } : {},
|
|
120
|
+
...threadPayload
|
|
121
|
+
});
|
|
122
|
+
const response = result;
|
|
123
|
+
const channel = response.channel ?? info.channelId;
|
|
124
|
+
const ts = response.ts;
|
|
125
|
+
if (!channel || !ts) {
|
|
126
|
+
throw new Error("Slack say() response did not include channel and ts.");
|
|
127
|
+
}
|
|
128
|
+
return { channel, ts };
|
|
129
|
+
},
|
|
130
|
+
async updateMessage(ref, message) {
|
|
131
|
+
await client.chat.update({
|
|
132
|
+
channel: ref.channel,
|
|
133
|
+
ts: ref.ts,
|
|
134
|
+
text: message.text,
|
|
135
|
+
...message.blocks ? { blocks: message.blocks } : {}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// src/adapter/scope-attributes.ts
|
|
142
|
+
function buildScopeAttributes(info, user, prep) {
|
|
143
|
+
return {
|
|
144
|
+
slackChannelId: info.channelId,
|
|
145
|
+
slackChannelType: info.channelType,
|
|
146
|
+
slackUserId: user.userId,
|
|
147
|
+
slackTeamId: user.teamId,
|
|
148
|
+
slackThreadTs: info.threadTs,
|
|
149
|
+
slackIsMention: info.isMention,
|
|
150
|
+
...prep.scopeAttributes ?? {}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// src/adapter/adapter.ts
|
|
155
|
+
var DEFAULT_CLASSIC_INITIAL_STATUS = {
|
|
156
|
+
status: "Thinking..."
|
|
157
|
+
};
|
|
158
|
+
function createSlackChannelAdapter(options) {
|
|
159
|
+
const source = resolveTurnSource(options);
|
|
160
|
+
const sessionMap = createSlackSessionMap(options);
|
|
161
|
+
const bridgeOptions = resolveSlackEventBridgeOptions(
|
|
162
|
+
{
|
|
163
|
+
showReasoning: options.showReasoning,
|
|
164
|
+
showToolUsage: options.showToolUsage,
|
|
165
|
+
showSubagentToolUsage: options.showSubagentToolUsage,
|
|
166
|
+
showSubagentResultInTask: options.showSubagentResultInTask,
|
|
167
|
+
formatToolTitle: options.formatToolTitle,
|
|
168
|
+
formatToolUpdate: options.formatToolUpdate,
|
|
169
|
+
formatToolDetails: options.formatToolDetails,
|
|
170
|
+
formatToolError: options.formatToolError,
|
|
171
|
+
formatReasoningUpdate: options.formatReasoningUpdate,
|
|
172
|
+
interactiveMode: options.interactiveMode,
|
|
173
|
+
formatApprovalRequired: options.formatApprovalRequired,
|
|
174
|
+
formatHumanInputRequired: options.formatHumanInputRequired,
|
|
175
|
+
formatMessageText: resolveSlackMessageFormatter(options),
|
|
176
|
+
streamingMode: options.streamingMode,
|
|
177
|
+
progressiveUpdateThreshold: options.progressiveUpdateThreshold,
|
|
178
|
+
progressiveUpdateIntervalMs: options.progressiveUpdateIntervalMs,
|
|
179
|
+
chatStreamBufferSize: options.chatStreamBufferSize,
|
|
180
|
+
maxTaskUpdates: options.maxTaskUpdates,
|
|
181
|
+
maxTaskUpdateTextChars: options.maxTaskUpdateTextChars,
|
|
182
|
+
maxTaskUpdateFieldChars: options.maxTaskUpdateFieldChars,
|
|
183
|
+
chatStreamFinalArgs: options.chatStreamFinalArgs
|
|
184
|
+
}
|
|
185
|
+
);
|
|
186
|
+
const timeout = options.timeout ?? 12e4;
|
|
187
|
+
const respondInThread = options.respondInThread ?? true;
|
|
188
|
+
const respondToMentions = options.respondToMentions ?? true;
|
|
189
|
+
const respondToMessages = options.respondToMessages ?? true;
|
|
190
|
+
const respondToChannelMessages = options.respondToChannelMessages ?? false;
|
|
191
|
+
async function processTurn(slackActivity, say, client, context, utilities = {}) {
|
|
192
|
+
const rawText = slackActivity.text.trim();
|
|
193
|
+
const userText = options.resolveMessage ? await options.resolveMessage(slackActivity) : rawText;
|
|
194
|
+
if (!userText) return;
|
|
195
|
+
const initialSessionId = await sessionMap.resolve(slackActivity);
|
|
196
|
+
const userIdentity = extractSlackUserIdentity(slackActivity);
|
|
197
|
+
const auth = extractSlackAuthContext(context, slackActivity.userId);
|
|
198
|
+
const hasSayStream = typeof utilities.sayStream === "function";
|
|
199
|
+
const hasSetStatus = typeof utilities.setStatus === "function";
|
|
200
|
+
options.logger?.debug?.("slack classic turn utilities", {
|
|
201
|
+
channelId: slackActivity.channelId,
|
|
202
|
+
channelType: slackActivity.channelType,
|
|
203
|
+
isMention: slackActivity.isMention,
|
|
204
|
+
threadTs: slackActivity.threadTs,
|
|
205
|
+
messageTs: slackActivity.messageTs,
|
|
206
|
+
hasSayStream,
|
|
207
|
+
hasSetStatus
|
|
208
|
+
});
|
|
209
|
+
const baseTurnRequest = {
|
|
210
|
+
slackActivity,
|
|
211
|
+
user: userIdentity,
|
|
212
|
+
sessionId: initialSessionId,
|
|
213
|
+
message: userText,
|
|
214
|
+
auth,
|
|
215
|
+
...utilities.setStatus ? { setStatus: utilities.setStatus } : {}
|
|
216
|
+
};
|
|
217
|
+
if (utilities.setStatus) {
|
|
218
|
+
const initialStatus = await resolveClassicInitialStatus(
|
|
219
|
+
options,
|
|
220
|
+
baseTurnRequest
|
|
221
|
+
);
|
|
222
|
+
if (initialStatus) {
|
|
223
|
+
try {
|
|
224
|
+
await utilities.setStatus(initialStatus);
|
|
225
|
+
} catch (error) {
|
|
226
|
+
options.logger?.warn?.("slack classic setStatus failed", {
|
|
227
|
+
error: formatErrorForLog(error)
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
const resolvedSessionId = await options.resolveSession?.(baseTurnRequest);
|
|
233
|
+
const sessionId = resolvedSessionId && resolvedSessionId.length > 0 ? resolvedSessionId : initialSessionId;
|
|
234
|
+
const turnRequest = {
|
|
235
|
+
...baseTurnRequest,
|
|
236
|
+
sessionId
|
|
237
|
+
};
|
|
238
|
+
const preparedTurn = await resolveTurnPreparation(
|
|
239
|
+
options,
|
|
240
|
+
turnRequest,
|
|
241
|
+
userIdentity
|
|
242
|
+
);
|
|
243
|
+
const finalSessionId = preparedTurn.sessionId && preparedTurn.sessionId.length > 0 ? preparedTurn.sessionId : sessionId;
|
|
244
|
+
const finalUserText = preparedTurn.message ?? userText;
|
|
245
|
+
const sink = buildResponseSink(
|
|
246
|
+
say,
|
|
247
|
+
client,
|
|
248
|
+
slackActivity,
|
|
249
|
+
respondInThread,
|
|
250
|
+
options.chatStreamStartArgs,
|
|
251
|
+
utilities.sayStream
|
|
252
|
+
);
|
|
253
|
+
const abortController = new AbortController();
|
|
254
|
+
const chatOptions = {
|
|
255
|
+
abort: abortController.signal
|
|
256
|
+
};
|
|
257
|
+
if (preparedTurn.system) {
|
|
258
|
+
chatOptions.system = preparedTurn.system;
|
|
259
|
+
}
|
|
260
|
+
const timeoutId = timeout > 0 ? setTimeout(() => abortController.abort(), timeout) : void 0;
|
|
261
|
+
try {
|
|
262
|
+
const scopeAttributes = buildScopeAttributes(
|
|
263
|
+
slackActivity,
|
|
264
|
+
userIdentity,
|
|
265
|
+
preparedTurn
|
|
266
|
+
);
|
|
267
|
+
await runWithSlackTurnContext(
|
|
268
|
+
{
|
|
269
|
+
...turnRequest,
|
|
270
|
+
sessionId: finalSessionId,
|
|
271
|
+
message: finalUserText,
|
|
272
|
+
...utilities.setStatus ? { setStatus: utilities.setStatus } : {},
|
|
273
|
+
...preparedTurn.context ? { context: preparedTurn.context } : {}
|
|
274
|
+
},
|
|
275
|
+
() => withinScope(
|
|
276
|
+
{
|
|
277
|
+
kind: "activity",
|
|
278
|
+
name: preparedTurn.scopeName?.trim() || "slack-activity",
|
|
279
|
+
sessionId: finalSessionId,
|
|
280
|
+
attributes: scopeAttributes
|
|
281
|
+
},
|
|
282
|
+
async () => {
|
|
283
|
+
const events = source.chat(
|
|
284
|
+
finalSessionId,
|
|
285
|
+
finalUserText,
|
|
286
|
+
chatOptions
|
|
287
|
+
);
|
|
288
|
+
const baseTurnBridgeOptions = options.handleInteractiveRequest ? {
|
|
289
|
+
...bridgeOptions,
|
|
290
|
+
handleInteractiveRequest: (interactive) => options.handleInteractiveRequest({
|
|
291
|
+
...interactive,
|
|
292
|
+
slackActivity,
|
|
293
|
+
user: userIdentity,
|
|
294
|
+
sessionId: finalSessionId,
|
|
295
|
+
message: finalUserText,
|
|
296
|
+
responder: buildInteractiveResponder(
|
|
297
|
+
say,
|
|
298
|
+
client,
|
|
299
|
+
slackActivity,
|
|
300
|
+
respondInThread
|
|
301
|
+
)
|
|
302
|
+
})
|
|
303
|
+
} : bridgeOptions;
|
|
304
|
+
const turnBridgeOptions = withClassicStatusUpdates(
|
|
305
|
+
baseTurnBridgeOptions,
|
|
306
|
+
utilities.setStatus
|
|
307
|
+
);
|
|
308
|
+
await bridgeAgentEventsToSlack(events, sink, turnBridgeOptions);
|
|
309
|
+
}
|
|
310
|
+
)
|
|
311
|
+
);
|
|
312
|
+
} catch (error) {
|
|
313
|
+
const errorInstance = error instanceof Error ? error : new Error(String(error));
|
|
314
|
+
if (!(errorInstance instanceof UnsupportedSlackInteractiveRequestError)) {
|
|
315
|
+
await say({
|
|
316
|
+
text: `I encountered an error while processing your request: ${errorInstance.message}`,
|
|
317
|
+
...buildThreadPayload(slackActivity, respondInThread)
|
|
318
|
+
}).catch(() => void 0);
|
|
319
|
+
}
|
|
320
|
+
if (options.onError) {
|
|
321
|
+
await options.onError(errorInstance, slackActivity);
|
|
322
|
+
}
|
|
323
|
+
} finally {
|
|
324
|
+
if (timeoutId) {
|
|
325
|
+
clearTimeout(timeoutId);
|
|
326
|
+
}
|
|
327
|
+
if (utilities.setStatus) {
|
|
328
|
+
await utilities.setStatus({ status: "" }).catch(
|
|
329
|
+
(error) => options.logger?.warn?.("slack classic clear status failed", {
|
|
330
|
+
error: formatErrorForLog(error)
|
|
331
|
+
})
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
function mount(app) {
|
|
337
|
+
if (respondToMessages) {
|
|
338
|
+
app.message(
|
|
339
|
+
async ({
|
|
340
|
+
message,
|
|
341
|
+
say,
|
|
342
|
+
client,
|
|
343
|
+
context,
|
|
344
|
+
sayStream,
|
|
345
|
+
setStatus
|
|
346
|
+
}) => {
|
|
347
|
+
const raw = message;
|
|
348
|
+
if (!isProcessableMessage(
|
|
349
|
+
raw
|
|
350
|
+
)) {
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
const info = parseSlackMessageActivity(
|
|
354
|
+
raw
|
|
355
|
+
);
|
|
356
|
+
if (info.channelType !== "dm" && !respondToChannelMessages) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
if (!info.text) return;
|
|
360
|
+
await processTurn(info, say, client, context, {
|
|
361
|
+
...typeof sayStream === "function" ? { sayStream } : {},
|
|
362
|
+
...typeof setStatus === "function" ? { setStatus } : {}
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
if (respondToMentions) {
|
|
368
|
+
app.event(
|
|
369
|
+
"app_mention",
|
|
370
|
+
async ({
|
|
371
|
+
event,
|
|
372
|
+
say,
|
|
373
|
+
client,
|
|
374
|
+
context,
|
|
375
|
+
sayStream,
|
|
376
|
+
setStatus
|
|
377
|
+
}) => {
|
|
378
|
+
const info = parseSlackMentionActivity(
|
|
379
|
+
event
|
|
380
|
+
);
|
|
381
|
+
if (!info.text) return;
|
|
382
|
+
await processTurn(info, say, client, context, {
|
|
383
|
+
...typeof sayStream === "function" ? { sayStream } : {},
|
|
384
|
+
...typeof setStatus === "function" ? { setStatus } : {}
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
if (options.welcomeMessage != null) {
|
|
390
|
+
app.event("member_joined_channel", async ({ event, client }) => {
|
|
391
|
+
const channelId = event.channel;
|
|
392
|
+
const userId = event.user;
|
|
393
|
+
const botInfo = await client.auth.test().catch(() => void 0);
|
|
394
|
+
if (botInfo?.user_id === userId) return;
|
|
395
|
+
await client.chat.postMessage({
|
|
396
|
+
channel: userId,
|
|
397
|
+
// DM the new member
|
|
398
|
+
text: options.welcomeMessage
|
|
399
|
+
}).catch(() => void 0);
|
|
400
|
+
await client.chat.postMessage({
|
|
401
|
+
channel: channelId,
|
|
402
|
+
text: options.welcomeMessage
|
|
403
|
+
}).catch(() => void 0);
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return {
|
|
408
|
+
mount,
|
|
409
|
+
getSessionId: (info) => sessionMap.resolve(info)
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
function formatClassicSlackStatusUpdate(status) {
|
|
413
|
+
return { status };
|
|
414
|
+
}
|
|
415
|
+
async function resolveClassicInitialStatus(options, request) {
|
|
416
|
+
if (options.initialStatus === void 0) {
|
|
417
|
+
return DEFAULT_CLASSIC_INITIAL_STATUS;
|
|
418
|
+
}
|
|
419
|
+
if (typeof options.initialStatus === "function") {
|
|
420
|
+
return await options.initialStatus(request) ?? void 0;
|
|
421
|
+
}
|
|
422
|
+
return options.initialStatus;
|
|
423
|
+
}
|
|
424
|
+
function withClassicStatusUpdates(options, setStatus) {
|
|
425
|
+
if (!setStatus) {
|
|
426
|
+
return options;
|
|
427
|
+
}
|
|
428
|
+
return {
|
|
429
|
+
...options,
|
|
430
|
+
onStatusChange: async (label, event) => {
|
|
431
|
+
await options.onStatusChange?.(label, event);
|
|
432
|
+
await setStatus(formatClassicSlackStatusUpdate(label));
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
function resolveTurnSource(options) {
|
|
437
|
+
const hasAgent = options.agent !== void 0;
|
|
438
|
+
const hasSource = options.source !== void 0;
|
|
439
|
+
if (hasAgent === hasSource) {
|
|
440
|
+
throw new Error(
|
|
441
|
+
"Provide exactly one of SlackChannelOptions.agent or SlackChannelOptions.source."
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
if (options.source) return options.source;
|
|
445
|
+
if (options.agent) return options.agent;
|
|
446
|
+
throw new Error(
|
|
447
|
+
"Provide exactly one of SlackChannelOptions.agent or SlackChannelOptions.source."
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
async function resolveTurnPreparation(options, request, user) {
|
|
451
|
+
if (options.prepareTurn) {
|
|
452
|
+
return await options.prepareTurn(request) ?? {};
|
|
453
|
+
}
|
|
454
|
+
if (options.resolveUserContext) {
|
|
455
|
+
const ctx = await options.resolveUserContext(user);
|
|
456
|
+
return ctx ?? {};
|
|
457
|
+
}
|
|
458
|
+
return {};
|
|
459
|
+
}
|
|
460
|
+
function formatErrorForLog(error) {
|
|
461
|
+
if (error instanceof Error) {
|
|
462
|
+
return error.stack ?? error.message;
|
|
463
|
+
}
|
|
464
|
+
return String(error);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
export {
|
|
468
|
+
resolveThreadAwareSlackSessionId,
|
|
469
|
+
createSlackSessionMap,
|
|
470
|
+
createSlackChannelAdapter
|
|
471
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// src/shared/formatting.ts
|
|
2
|
+
import {
|
|
3
|
+
markdownToSlackMrkdwn,
|
|
4
|
+
resolveSlackMessageFormatter
|
|
5
|
+
} from "@cuylabs/channel-slack/core";
|
|
6
|
+
|
|
7
|
+
// src/shared/activity/classify.ts
|
|
8
|
+
import {
|
|
9
|
+
isProcessableMessage,
|
|
10
|
+
resolveSlackChannelType,
|
|
11
|
+
stripLeadingMentions
|
|
12
|
+
} from "@cuylabs/channel-slack/core";
|
|
13
|
+
|
|
14
|
+
// src/shared/activity/identity.ts
|
|
15
|
+
import {
|
|
16
|
+
extractSlackAuthContext,
|
|
17
|
+
extractSlackUserIdentity
|
|
18
|
+
} from "@cuylabs/channel-slack/core";
|
|
19
|
+
|
|
20
|
+
// src/shared/activity/parse.ts
|
|
21
|
+
import {
|
|
22
|
+
extractSlackActionToken,
|
|
23
|
+
parseSlackMentionActivity,
|
|
24
|
+
parseSlackMessageActivity
|
|
25
|
+
} from "@cuylabs/channel-slack/core";
|
|
26
|
+
|
|
27
|
+
// src/shared/activity/text.ts
|
|
28
|
+
import {
|
|
29
|
+
extractSlackAttachmentsText,
|
|
30
|
+
extractSlackBlocksText,
|
|
31
|
+
extractSlackMessageText
|
|
32
|
+
} from "@cuylabs/channel-slack/core";
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
markdownToSlackMrkdwn,
|
|
36
|
+
resolveSlackMessageFormatter,
|
|
37
|
+
isProcessableMessage,
|
|
38
|
+
resolveSlackChannelType,
|
|
39
|
+
stripLeadingMentions,
|
|
40
|
+
extractSlackAuthContext,
|
|
41
|
+
extractSlackUserIdentity,
|
|
42
|
+
extractSlackActionToken,
|
|
43
|
+
parseSlackMentionActivity,
|
|
44
|
+
parseSlackMessageActivity,
|
|
45
|
+
extractSlackAttachmentsText,
|
|
46
|
+
extractSlackBlocksText,
|
|
47
|
+
extractSlackMessageText
|
|
48
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
__export,
|
|
21
|
+
__reExport
|
|
22
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
installSlackAgentAppSurface
|
|
3
|
+
} from "./chunk-M64Z6TYL.js";
|
|
4
|
+
import {
|
|
5
|
+
createSlackAssistantBridge
|
|
6
|
+
} from "./chunk-BFUPAJON.js";
|
|
7
|
+
import {
|
|
8
|
+
bolt_exports
|
|
9
|
+
} from "./chunk-ANIZ5NT4.js";
|
|
10
|
+
|
|
11
|
+
// src/socket.ts
|
|
12
|
+
async function mountSlackAssistantAgentSocket(options) {
|
|
13
|
+
const {
|
|
14
|
+
appToken: appTokenOption,
|
|
15
|
+
botToken: botTokenOption,
|
|
16
|
+
auth,
|
|
17
|
+
boltAppOptions,
|
|
18
|
+
socketModeReceiverOptions,
|
|
19
|
+
feedback: feedbackOption,
|
|
20
|
+
onFeedback,
|
|
21
|
+
start,
|
|
22
|
+
...bridgeOptions
|
|
23
|
+
} = options;
|
|
24
|
+
const { boltApp, authMode } = await (0, bolt_exports.createSlackSocketBoltApp)({
|
|
25
|
+
appToken: appTokenOption,
|
|
26
|
+
botToken: botTokenOption,
|
|
27
|
+
auth,
|
|
28
|
+
boltAppOptions,
|
|
29
|
+
socketModeReceiverOptions
|
|
30
|
+
});
|
|
31
|
+
const feedback = feedbackOption !== void 0 ? feedbackOption : onFeedback ? { onFeedback } : void 0;
|
|
32
|
+
const bridge = createSlackAssistantBridge({
|
|
33
|
+
...bridgeOptions,
|
|
34
|
+
...feedback !== void 0 ? { feedback } : {}
|
|
35
|
+
});
|
|
36
|
+
bridge.install(boltApp);
|
|
37
|
+
if (start !== false) {
|
|
38
|
+
await boltApp.start();
|
|
39
|
+
}
|
|
40
|
+
return { boltApp, bridge, authMode };
|
|
41
|
+
}
|
|
42
|
+
async function mountSlackAgentAppSocket(options) {
|
|
43
|
+
const {
|
|
44
|
+
appToken: appTokenOption,
|
|
45
|
+
botToken: botTokenOption,
|
|
46
|
+
auth,
|
|
47
|
+
boltAppOptions,
|
|
48
|
+
socketModeReceiverOptions,
|
|
49
|
+
start,
|
|
50
|
+
...surfaceOptions
|
|
51
|
+
} = options;
|
|
52
|
+
const { boltApp, authMode } = await (0, bolt_exports.createSlackSocketBoltApp)({
|
|
53
|
+
appToken: appTokenOption,
|
|
54
|
+
botToken: botTokenOption,
|
|
55
|
+
auth,
|
|
56
|
+
boltAppOptions,
|
|
57
|
+
socketModeReceiverOptions
|
|
58
|
+
});
|
|
59
|
+
const { bridge } = installSlackAgentAppSurface(boltApp, surfaceOptions);
|
|
60
|
+
if (start !== false) {
|
|
61
|
+
await boltApp.start();
|
|
62
|
+
}
|
|
63
|
+
return { boltApp, bridge, authMode };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export {
|
|
67
|
+
mountSlackAssistantAgentSocket,
|
|
68
|
+
mountSlackAgentAppSocket
|
|
69
|
+
};
|