@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,85 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSlackAssistantBridge
|
|
3
|
+
} from "./chunk-BFUPAJON.js";
|
|
4
|
+
import {
|
|
5
|
+
bolt_exports
|
|
6
|
+
} from "./chunk-ANIZ5NT4.js";
|
|
7
|
+
|
|
8
|
+
// src/express-assistant.ts
|
|
9
|
+
async function mountSlackAssistantAgent(options) {
|
|
10
|
+
const {
|
|
11
|
+
botToken,
|
|
12
|
+
signingSecret,
|
|
13
|
+
auth,
|
|
14
|
+
path,
|
|
15
|
+
processBeforeResponse,
|
|
16
|
+
signatureVerification,
|
|
17
|
+
boltAppOptions,
|
|
18
|
+
receiverOptions,
|
|
19
|
+
port: portOption,
|
|
20
|
+
host,
|
|
21
|
+
app: providedApp,
|
|
22
|
+
feedback: feedbackOption,
|
|
23
|
+
onFeedback,
|
|
24
|
+
...bridgeOptions
|
|
25
|
+
} = options;
|
|
26
|
+
const {
|
|
27
|
+
boltApp,
|
|
28
|
+
receiver,
|
|
29
|
+
app: expressApp,
|
|
30
|
+
authMode,
|
|
31
|
+
routePath
|
|
32
|
+
} = await (0, bolt_exports.createSlackBoltApp)({
|
|
33
|
+
signingSecret,
|
|
34
|
+
path,
|
|
35
|
+
botToken,
|
|
36
|
+
auth,
|
|
37
|
+
app: providedApp,
|
|
38
|
+
processBeforeResponse,
|
|
39
|
+
signatureVerification,
|
|
40
|
+
boltAppOptions,
|
|
41
|
+
receiverOptions
|
|
42
|
+
});
|
|
43
|
+
const feedback = feedbackOption !== void 0 ? feedbackOption : onFeedback ? { onFeedback } : void 0;
|
|
44
|
+
const bridge = createSlackAssistantBridge({
|
|
45
|
+
...bridgeOptions,
|
|
46
|
+
...feedback !== void 0 ? { feedback } : {}
|
|
47
|
+
});
|
|
48
|
+
bridge.install(boltApp);
|
|
49
|
+
mountReceiverRouter(expressApp, receiver);
|
|
50
|
+
const port = portOption === void 0 ? resolvePort(process.env.PORT) : portOption;
|
|
51
|
+
let server;
|
|
52
|
+
if (!providedApp && port !== null) {
|
|
53
|
+
const onListen = () => {
|
|
54
|
+
process.stdout.write(
|
|
55
|
+
`Slack assistant listening on port ${port} at ${routePath}
|
|
56
|
+
`
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
server = host ? expressApp.listen(port, host, onListen) : expressApp.listen(port, onListen);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
app: expressApp,
|
|
63
|
+
boltApp,
|
|
64
|
+
receiver,
|
|
65
|
+
authMode,
|
|
66
|
+
routePath,
|
|
67
|
+
bridge,
|
|
68
|
+
...server ? { server } : {}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function resolvePort(port) {
|
|
72
|
+
if (!port) return 3e3;
|
|
73
|
+
const parsed = Number(port);
|
|
74
|
+
if (!Number.isInteger(parsed) || parsed < 0) {
|
|
75
|
+
throw new Error(`Invalid PORT value: ${port}`);
|
|
76
|
+
}
|
|
77
|
+
return parsed;
|
|
78
|
+
}
|
|
79
|
+
function mountReceiverRouter(app, receiver) {
|
|
80
|
+
app.use(receiver.router);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export {
|
|
84
|
+
mountSlackAssistantAgent
|
|
85
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__reExport
|
|
3
|
+
} from "./chunk-I2KLQ2HA.js";
|
|
4
|
+
|
|
5
|
+
// src/targets/index.ts
|
|
6
|
+
var targets_exports = {};
|
|
7
|
+
__reExport(targets_exports, targets_star);
|
|
8
|
+
import * as targets_star from "@cuylabs/channel-slack/targets";
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
targets_exports
|
|
12
|
+
};
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSlackAssistantBridge
|
|
3
|
+
} from "./chunk-BFUPAJON.js";
|
|
4
|
+
import {
|
|
5
|
+
feedback_exports
|
|
6
|
+
} from "./chunk-VHGV66M7.js";
|
|
7
|
+
import {
|
|
8
|
+
createSlackChannelAdapter
|
|
9
|
+
} from "./chunk-FDRQOG7Q.js";
|
|
10
|
+
|
|
11
|
+
// src/app-surface.ts
|
|
12
|
+
var DEFAULT_TIMEOUT_MS = 12e4;
|
|
13
|
+
var DEFAULT_STREAM_ERROR_MESSAGE = "I ran into an error while preparing this answer. Please try again.";
|
|
14
|
+
function installSlackAgentAppSurface(boltApp, options) {
|
|
15
|
+
const {
|
|
16
|
+
respondToMentions,
|
|
17
|
+
respondToMessages,
|
|
18
|
+
respondToChannelMessages,
|
|
19
|
+
resolveMessage,
|
|
20
|
+
feedback: feedbackOption,
|
|
21
|
+
onFeedback,
|
|
22
|
+
timeoutMs,
|
|
23
|
+
logger,
|
|
24
|
+
source,
|
|
25
|
+
prepareTurn,
|
|
26
|
+
resolveSession,
|
|
27
|
+
interactive,
|
|
28
|
+
...assistantBridgeOptions
|
|
29
|
+
} = options;
|
|
30
|
+
const feedbackConfig = feedbackOption === false ? void 0 : feedbackOption ?? (onFeedback ? { onFeedback } : {});
|
|
31
|
+
const assistantFeedback = feedbackOption === false ? false : feedbackConfig;
|
|
32
|
+
const feedbackBlock = feedbackConfig ? (0, feedback_exports.createSlackFeedbackBlock)(feedbackConfig) : void 0;
|
|
33
|
+
const formatStreamError = assistantBridgeOptions.formatStreamError ?? (() => DEFAULT_STREAM_ERROR_MESSAGE);
|
|
34
|
+
const formatting = assistantBridgeOptions.formatChatMarkdown;
|
|
35
|
+
const channelSource = createErrorTranslatingSource(source, formatStreamError);
|
|
36
|
+
const channelFinalArgs = mergeChatStreamFinalArgs(
|
|
37
|
+
assistantBridgeOptions.chatStreamFinalArgs,
|
|
38
|
+
feedbackBlock
|
|
39
|
+
);
|
|
40
|
+
const bridge = createSlackAssistantBridge({
|
|
41
|
+
...assistantBridgeOptions,
|
|
42
|
+
source,
|
|
43
|
+
...assistantFeedback !== void 0 ? { feedback: assistantFeedback } : {},
|
|
44
|
+
...timeoutMs !== void 0 ? { timeoutMs } : {},
|
|
45
|
+
...logger ? { logger } : {},
|
|
46
|
+
...prepareTurn ? { prepareTurn: toAssistantPrepareTurn(prepareTurn) } : {},
|
|
47
|
+
...resolveSession ? { resolveSession: toAssistantResolveSession(resolveSession) } : {},
|
|
48
|
+
...interactive ? { handleInteractiveRequest: interactive.handleInteractiveRequest } : {}
|
|
49
|
+
});
|
|
50
|
+
boltApp.assistant(bridge.assistant);
|
|
51
|
+
const channelAdapter = createSlackChannelAdapter({
|
|
52
|
+
source: channelSource,
|
|
53
|
+
sessionStrategy: assistantBridgeOptions.sessionStrategy,
|
|
54
|
+
...resolveSession ? { resolveSession } : {},
|
|
55
|
+
...prepareTurn ? { prepareTurn } : {},
|
|
56
|
+
...interactive ? { handleInteractiveRequest: interactive.handleInteractiveRequest } : {},
|
|
57
|
+
streamingMode: "chat-stream",
|
|
58
|
+
showReasoning: assistantBridgeOptions.showReasoning,
|
|
59
|
+
showToolUsage: assistantBridgeOptions.showToolUsage,
|
|
60
|
+
showSubagentToolUsage: assistantBridgeOptions.showSubagentToolUsage,
|
|
61
|
+
showSubagentResultInTask: assistantBridgeOptions.showSubagentResultInTask,
|
|
62
|
+
formatToolTitle: assistantBridgeOptions.formatToolTitle,
|
|
63
|
+
formatToolUpdate: assistantBridgeOptions.formatToolUpdate,
|
|
64
|
+
formatToolDetails: assistantBridgeOptions.formatToolDetails,
|
|
65
|
+
formatToolError: assistantBridgeOptions.formatToolError,
|
|
66
|
+
formatReasoningUpdate: assistantBridgeOptions.formatReasoningUpdate,
|
|
67
|
+
chatStreamBufferSize: assistantBridgeOptions.chatStreamBufferSize,
|
|
68
|
+
chatStreamStartArgs: {
|
|
69
|
+
...assistantBridgeOptions.chatStreamStartArgs ?? {},
|
|
70
|
+
task_display_mode: assistantBridgeOptions.taskDisplayMode ?? "timeline"
|
|
71
|
+
},
|
|
72
|
+
...typeof assistantBridgeOptions.initialStatus === "object" && assistantBridgeOptions.initialStatus !== null ? { initialStatus: assistantBridgeOptions.initialStatus } : {},
|
|
73
|
+
...formatting?.formatChatMarkdown !== void 0 ? { formatChatMarkdown: formatting.formatChatMarkdown } : {},
|
|
74
|
+
...formatting?.formatMessageText ? { formatMessageText: formatting.formatMessageText } : {},
|
|
75
|
+
timeout: timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
76
|
+
respondToMentions: respondToMentions !== false,
|
|
77
|
+
respondToMessages: respondToMessages !== false,
|
|
78
|
+
respondToChannelMessages: respondToChannelMessages === true,
|
|
79
|
+
...resolveMessage ? { resolveMessage } : {},
|
|
80
|
+
chatStreamFinalArgs: channelFinalArgs,
|
|
81
|
+
...logger ? { logger } : {},
|
|
82
|
+
...logger ? {
|
|
83
|
+
onError: async (error, info) => {
|
|
84
|
+
logger.warn?.("slack channel turn failed", {
|
|
85
|
+
error: formatErrorForLog(error),
|
|
86
|
+
channelId: info.channelId,
|
|
87
|
+
userId: info.userId
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
} : {}
|
|
91
|
+
});
|
|
92
|
+
channelAdapter.mount(boltApp);
|
|
93
|
+
if (feedbackConfig) {
|
|
94
|
+
const feedbackSessionStrategy = assistantBridgeOptions.sessionStrategy ?? "thread-aware";
|
|
95
|
+
(0, feedback_exports.registerSlackFeedbackAction)(boltApp, {
|
|
96
|
+
...feedbackConfig,
|
|
97
|
+
resolveSessionId: (ctx) => resolveFeedbackSessionId(ctx, feedbackSessionStrategy),
|
|
98
|
+
onFeedback: feedbackConfig.onFeedback ?? (async (_ctx) => {
|
|
99
|
+
})
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
interactive?.install(boltApp);
|
|
103
|
+
return { bridge };
|
|
104
|
+
}
|
|
105
|
+
function mergeChatStreamFinalArgs(base, feedbackBlock) {
|
|
106
|
+
if (!base && !feedbackBlock) {
|
|
107
|
+
return void 0;
|
|
108
|
+
}
|
|
109
|
+
const configuredBlocks = Array.isArray(base?.blocks) ? base.blocks : [];
|
|
110
|
+
const blocks = feedbackBlock ? [...configuredBlocks, feedbackBlock] : configuredBlocks;
|
|
111
|
+
return {
|
|
112
|
+
...base ?? {},
|
|
113
|
+
...blocks.length > 0 ? { blocks } : {}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function toAssistantPrepareTurn(prepareTurn) {
|
|
117
|
+
return (request) => prepareTurn(toAppTurnRequest(request));
|
|
118
|
+
}
|
|
119
|
+
function toAssistantResolveSession(resolveSession) {
|
|
120
|
+
return (request) => resolveSession(toAppTurnRequest(request));
|
|
121
|
+
}
|
|
122
|
+
function toAppTurnRequest(request) {
|
|
123
|
+
const user = {
|
|
124
|
+
userId: request.message.userId,
|
|
125
|
+
channelId: request.message.channelId,
|
|
126
|
+
teamId: request.message.teamId ?? request.auth.teamId,
|
|
127
|
+
threadTs: request.message.threadTs,
|
|
128
|
+
messageTs: request.message.messageTs
|
|
129
|
+
};
|
|
130
|
+
return {
|
|
131
|
+
slackActivity: request.message,
|
|
132
|
+
user,
|
|
133
|
+
sessionId: request.sessionId,
|
|
134
|
+
message: request.message.text,
|
|
135
|
+
auth: request.auth,
|
|
136
|
+
threadContext: request.threadContext,
|
|
137
|
+
assistant: request.assistant,
|
|
138
|
+
client: request.client,
|
|
139
|
+
rawArgs: request.rawArgs
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function createErrorTranslatingSource(source, formatStreamError) {
|
|
143
|
+
return {
|
|
144
|
+
chat(sessionId, message, options) {
|
|
145
|
+
const events = source.chat(sessionId, message, options);
|
|
146
|
+
return translateErrors(events, formatStreamError);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
async function* translateErrors(events, formatStreamError) {
|
|
151
|
+
try {
|
|
152
|
+
for await (const event of events) {
|
|
153
|
+
if (event.type === "error") {
|
|
154
|
+
yield {
|
|
155
|
+
type: "text-delta",
|
|
156
|
+
text: `
|
|
157
|
+
|
|
158
|
+
${formatStreamError(toError(event.error))}`
|
|
159
|
+
};
|
|
160
|
+
yield { type: "complete" };
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
yield event;
|
|
164
|
+
}
|
|
165
|
+
} catch (error) {
|
|
166
|
+
yield {
|
|
167
|
+
type: "text-delta",
|
|
168
|
+
text: `
|
|
169
|
+
|
|
170
|
+
${formatStreamError(toError(error))}`
|
|
171
|
+
};
|
|
172
|
+
yield { type: "complete" };
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function toError(value) {
|
|
176
|
+
return value instanceof Error ? value : new Error(String(value));
|
|
177
|
+
}
|
|
178
|
+
function formatErrorForLog(error) {
|
|
179
|
+
if (error instanceof Error) {
|
|
180
|
+
return error.stack ?? error.message;
|
|
181
|
+
}
|
|
182
|
+
return String(error);
|
|
183
|
+
}
|
|
184
|
+
function resolveFeedbackSessionId(context, strategy) {
|
|
185
|
+
const threadTs = context.threadTs ?? context.messageTs;
|
|
186
|
+
switch (strategy) {
|
|
187
|
+
case "channel-id":
|
|
188
|
+
return context.channelId;
|
|
189
|
+
case "user-per-thread":
|
|
190
|
+
return `${context.channelId}:${threadTs}:${context.userId}`;
|
|
191
|
+
default:
|
|
192
|
+
return `${context.channelId}:${threadTs}`;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export {
|
|
197
|
+
installSlackAgentAppSurface
|
|
198
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__reExport
|
|
3
|
+
} from "./chunk-I2KLQ2HA.js";
|
|
4
|
+
|
|
5
|
+
// src/diagnostics/index.ts
|
|
6
|
+
var diagnostics_exports = {};
|
|
7
|
+
__reExport(diagnostics_exports, diagnostics_star);
|
|
8
|
+
import * as diagnostics_star from "@cuylabs/channel-slack/diagnostics";
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
diagnostics_exports
|
|
12
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {
|
|
2
|
+
currentSlackTurnContext
|
|
3
|
+
} from "./chunk-DHPD4XH5.js";
|
|
4
|
+
|
|
5
|
+
// src/shared/context-fragments.ts
|
|
6
|
+
var DEFAULT_SLACK_CONTEXT_FRAGMENT_KEY = "slackContextFragment";
|
|
7
|
+
function isRecord(value) {
|
|
8
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
9
|
+
}
|
|
10
|
+
function isPayload(value) {
|
|
11
|
+
return isRecord(value) && typeof value.content === "string";
|
|
12
|
+
}
|
|
13
|
+
function resolveContextBagValue(slack, key) {
|
|
14
|
+
const value = slack.context?.[key];
|
|
15
|
+
if (typeof value === "string") {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
if (isPayload(value)) {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
return void 0;
|
|
22
|
+
}
|
|
23
|
+
function resolveDedupeKey(options, context) {
|
|
24
|
+
return typeof options.dedupeKey === "function" ? options.dedupeKey(context) : options.dedupeKey;
|
|
25
|
+
}
|
|
26
|
+
function resolveMetadata(options, context) {
|
|
27
|
+
return typeof options.metadata === "function" ? options.metadata(context) : options.metadata;
|
|
28
|
+
}
|
|
29
|
+
function normalizeFragment(resolved, options, context) {
|
|
30
|
+
const payload = typeof resolved === "string" ? { content: resolved } : isPayload(resolved) ? resolved : void 0;
|
|
31
|
+
if (!payload) {
|
|
32
|
+
return resolved;
|
|
33
|
+
}
|
|
34
|
+
if (payload.content.trim().length === 0) {
|
|
35
|
+
return void 0;
|
|
36
|
+
}
|
|
37
|
+
const dedupeKey = payload.dedupeKey ?? resolveDedupeKey(options, context);
|
|
38
|
+
const metadata = payload.metadata ?? resolveMetadata(options, context);
|
|
39
|
+
const maxChars = payload.maxChars ?? options.maxChars;
|
|
40
|
+
return {
|
|
41
|
+
kind: payload.kind ?? options.kind ?? "slack-context",
|
|
42
|
+
content: payload.content,
|
|
43
|
+
role: payload.role ?? options.role ?? "user",
|
|
44
|
+
placement: payload.placement ?? options.placement ?? "after-latest-user",
|
|
45
|
+
lifetime: payload.lifetime ?? options.lifetime ?? "turn",
|
|
46
|
+
source: payload.source ?? options.source ?? "slack",
|
|
47
|
+
title: payload.title ?? options.title ?? "Slack Context",
|
|
48
|
+
budgetBehavior: payload.budgetBehavior ?? options.budgetBehavior ?? "droppable",
|
|
49
|
+
...maxChars !== void 0 ? { maxChars } : {},
|
|
50
|
+
...dedupeKey ? { dedupeKey } : {},
|
|
51
|
+
...metadata ? { metadata } : {}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function createSlackContextFragmentMiddleware(options = {}) {
|
|
55
|
+
const contextKey = options.contextKey ?? DEFAULT_SLACK_CONTEXT_FRAGMENT_KEY;
|
|
56
|
+
return {
|
|
57
|
+
name: options.name ?? "slack-context-fragment",
|
|
58
|
+
async contextFragments(step) {
|
|
59
|
+
const slack = currentSlackTurnContext();
|
|
60
|
+
if (!slack) {
|
|
61
|
+
return void 0;
|
|
62
|
+
}
|
|
63
|
+
const context = { slack, step };
|
|
64
|
+
const resolved = options.resolve ? await options.resolve(context) : resolveContextBagValue(slack, contextKey);
|
|
65
|
+
if (resolved === void 0) {
|
|
66
|
+
return void 0;
|
|
67
|
+
}
|
|
68
|
+
return normalizeFragment(resolved, options, context);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export {
|
|
74
|
+
DEFAULT_SLACK_CONTEXT_FRAGMENT_KEY,
|
|
75
|
+
createSlackContextFragmentMiddleware
|
|
76
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__reExport
|
|
3
|
+
} from "./chunk-I2KLQ2HA.js";
|
|
4
|
+
|
|
5
|
+
// src/history/index.ts
|
|
6
|
+
var history_exports = {};
|
|
7
|
+
__reExport(history_exports, history_star);
|
|
8
|
+
import * as history_star from "@cuylabs/channel-slack/history";
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
history_exports
|
|
12
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/mcp.ts
|
|
2
|
+
var SLACK_MCP_URL = "https://mcp.slack.com/mcp";
|
|
3
|
+
function createSlackMcpServerConfig(options) {
|
|
4
|
+
const userToken = options.userToken.trim();
|
|
5
|
+
if (!userToken) {
|
|
6
|
+
throw new Error(
|
|
7
|
+
"createSlackMcpServerConfig: userToken is required (Slack user OAuth token)."
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
const headers = {
|
|
11
|
+
...options.headers ?? {},
|
|
12
|
+
Authorization: `Bearer ${userToken}`
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
transport: "http",
|
|
16
|
+
url: options.url ?? SLACK_MCP_URL,
|
|
17
|
+
headers,
|
|
18
|
+
...options.timeout !== void 0 ? { timeout: options.timeout } : {},
|
|
19
|
+
...options.enabled !== void 0 ? { enabled: options.enabled } : {},
|
|
20
|
+
...options.name !== void 0 ? { name: options.name } : {}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
SLACK_MCP_URL,
|
|
26
|
+
createSlackMcpServerConfig
|
|
27
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__reExport
|
|
3
|
+
} from "./chunk-I2KLQ2HA.js";
|
|
4
|
+
|
|
5
|
+
// src/feedback/index.ts
|
|
6
|
+
var feedback_exports = {};
|
|
7
|
+
__reExport(feedback_exports, feedback_star);
|
|
8
|
+
import * as feedback_star from "@cuylabs/channel-slack/feedback";
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
feedback_exports
|
|
12
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSlackChannelAdapter
|
|
3
|
+
} from "./chunk-FDRQOG7Q.js";
|
|
4
|
+
import {
|
|
5
|
+
bolt_exports
|
|
6
|
+
} from "./chunk-ANIZ5NT4.js";
|
|
7
|
+
|
|
8
|
+
// src/express.ts
|
|
9
|
+
async function mountSlackAgent(source, options = {}) {
|
|
10
|
+
const {
|
|
11
|
+
botToken: providedToken,
|
|
12
|
+
signingSecret,
|
|
13
|
+
auth,
|
|
14
|
+
path,
|
|
15
|
+
processBeforeResponse,
|
|
16
|
+
signatureVerification,
|
|
17
|
+
boltAppOptions,
|
|
18
|
+
receiverOptions,
|
|
19
|
+
port: portOption,
|
|
20
|
+
host,
|
|
21
|
+
app: providedApp,
|
|
22
|
+
...adapterOptions
|
|
23
|
+
} = options;
|
|
24
|
+
const {
|
|
25
|
+
boltApp,
|
|
26
|
+
receiver,
|
|
27
|
+
app: expressApp,
|
|
28
|
+
authMode,
|
|
29
|
+
routePath
|
|
30
|
+
} = await (0, bolt_exports.createSlackBoltApp)({
|
|
31
|
+
signingSecret,
|
|
32
|
+
path,
|
|
33
|
+
botToken: providedToken,
|
|
34
|
+
auth,
|
|
35
|
+
app: providedApp,
|
|
36
|
+
processBeforeResponse,
|
|
37
|
+
signatureVerification,
|
|
38
|
+
boltAppOptions,
|
|
39
|
+
receiverOptions
|
|
40
|
+
});
|
|
41
|
+
const channelAdapter = createSlackChannelAdapter({
|
|
42
|
+
source,
|
|
43
|
+
...adapterOptions
|
|
44
|
+
});
|
|
45
|
+
channelAdapter.mount(boltApp);
|
|
46
|
+
mountReceiverRouter(expressApp, receiver);
|
|
47
|
+
const port = portOption === void 0 ? resolvePort(process.env.PORT) : portOption;
|
|
48
|
+
let server;
|
|
49
|
+
if (!providedApp && port !== null) {
|
|
50
|
+
const onListen = () => {
|
|
51
|
+
process.stdout.write(
|
|
52
|
+
`Slack bot listening on port ${port} at ${routePath}
|
|
53
|
+
`
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
server = host ? expressApp.listen(port, host, onListen) : expressApp.listen(port, onListen);
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
app: expressApp,
|
|
60
|
+
boltApp,
|
|
61
|
+
receiver,
|
|
62
|
+
authMode,
|
|
63
|
+
routePath,
|
|
64
|
+
channelAdapter,
|
|
65
|
+
server
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function resolvePort(port) {
|
|
69
|
+
if (!port) return 3e3;
|
|
70
|
+
const parsed = Number(port);
|
|
71
|
+
if (!Number.isInteger(parsed) || parsed < 0) {
|
|
72
|
+
throw new Error(`Invalid PORT value: ${port}`);
|
|
73
|
+
}
|
|
74
|
+
return parsed;
|
|
75
|
+
}
|
|
76
|
+
function mountReceiverRouter(app, receiver) {
|
|
77
|
+
app.use(receiver.router);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export {
|
|
81
|
+
mountSlackAgent
|
|
82
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@cuylabs/channel-slack/diagnostics';
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Server } from 'node:http';
|
|
2
|
+
import { Application } from 'express';
|
|
3
|
+
import { App, ExpressReceiver } from '@slack/bolt';
|
|
4
|
+
import { CreateSlackBoltAppOptions, SlackDirectAuthOptions, SlackDirectAuthMode } from '@cuylabs/channel-slack/bolt';
|
|
5
|
+
import { C as CreateSlackAssistantBridgeOptions, b as SlackAssistantFeedbackConfig, S as SlackAssistantBridge } from './options-Uf-qmQKN.js';
|
|
6
|
+
import { SlackFeedbackHandler } from '@cuylabs/channel-slack/feedback';
|
|
7
|
+
import '@cuylabs/agent-core';
|
|
8
|
+
import '@slack/web-api';
|
|
9
|
+
import '@cuylabs/channel-slack/core';
|
|
10
|
+
import './interactive-o_NZb-Xg.js';
|
|
11
|
+
import './options-C7OYeNR-.js';
|
|
12
|
+
import '@cuylabs/channel-slack/assistant';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Express helper for mounting the Slack assistant bridge.
|
|
16
|
+
*
|
|
17
|
+
* Companion to `mountSlackAgent` (which wires the classic
|
|
18
|
+
* `app.message`/`app.event` listeners). This one uses
|
|
19
|
+
* `createSlackAssistantBridge` so the bot uses Bolt's
|
|
20
|
+
* `app.assistant(new Assistant({...}))` lifecycle — `setStatus`,
|
|
21
|
+
* `setSuggestedPrompts`, `chatStream`, feedback buttons.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { mountSlackAssistantAgent } from "@cuylabs/channel-slack-agent-core";
|
|
26
|
+
*
|
|
27
|
+
* await mountSlackAssistantAgent(agent, {
|
|
28
|
+
* getSuggestedPrompts: () => ({
|
|
29
|
+
* title: "Try one of these:",
|
|
30
|
+
* prompts: [
|
|
31
|
+
* { title: "Roll some dice", message: "Roll 2d20" },
|
|
32
|
+
* { title: "Summarize this thread", message: "Summarize the last 20 messages" },
|
|
33
|
+
* ],
|
|
34
|
+
* }),
|
|
35
|
+
* onFeedback: ({ verdict, sessionId }) => {
|
|
36
|
+
* metrics.increment(`feedback.${verdict}`, { sessionId });
|
|
37
|
+
* },
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
interface MountSlackAssistantAgentOptions extends Omit<CreateSlackAssistantBridgeOptions, "feedback">, Omit<CreateSlackBoltAppOptions, "app" | "path" | "botToken" | "signingSecret" | "auth"> {
|
|
43
|
+
/**
|
|
44
|
+
* Slack bot token (`xoxb-...`).
|
|
45
|
+
* @default process.env.SLACK_BOT_TOKEN
|
|
46
|
+
*/
|
|
47
|
+
botToken?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Slack signing secret used to verify incoming webhook requests.
|
|
50
|
+
* @default process.env.SLACK_SIGNING_SECRET
|
|
51
|
+
*/
|
|
52
|
+
signingSecret?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Structured direct-mode auth config (single-workspace, OAuth, custom).
|
|
55
|
+
* Defaults to `botToken` / `SLACK_BOT_TOKEN` single-workspace mode.
|
|
56
|
+
*/
|
|
57
|
+
auth?: SlackDirectAuthOptions;
|
|
58
|
+
/**
|
|
59
|
+
* Slack Events API callback path handled by Bolt.
|
|
60
|
+
*
|
|
61
|
+
* @default "/slack/events"
|
|
62
|
+
*/
|
|
63
|
+
path?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Port to listen on. Set to `null` to skip `app.listen()` — caller manages
|
|
66
|
+
* the server.
|
|
67
|
+
*
|
|
68
|
+
* @default process.env.PORT || 3000
|
|
69
|
+
*/
|
|
70
|
+
port?: number | null;
|
|
71
|
+
/** Optional host passed to `app.listen(port, host)`. */
|
|
72
|
+
host?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Pre-existing Express app. If not provided, a new one is created and the
|
|
75
|
+
* helper calls `app.listen()` itself.
|
|
76
|
+
*/
|
|
77
|
+
app?: Application;
|
|
78
|
+
/**
|
|
79
|
+
* Feedback config — block + handler. Pass `false` to omit feedback buttons
|
|
80
|
+
* entirely. Pass an object to override action ids, button labels, or the
|
|
81
|
+
* feedback handler. Pass a function as `onFeedback` for the most common
|
|
82
|
+
* case where only the handler differs.
|
|
83
|
+
*/
|
|
84
|
+
feedback?: SlackAssistantFeedbackConfig | false;
|
|
85
|
+
/**
|
|
86
|
+
* Convenience shorthand: `onFeedback: handler` is equivalent to
|
|
87
|
+
* `feedback: { onFeedback: handler }`. Ignored if `feedback` is set.
|
|
88
|
+
*/
|
|
89
|
+
onFeedback?: SlackFeedbackHandler;
|
|
90
|
+
}
|
|
91
|
+
interface MountSlackAssistantAgentResult {
|
|
92
|
+
app: Application;
|
|
93
|
+
boltApp: App;
|
|
94
|
+
receiver: ExpressReceiver;
|
|
95
|
+
authMode: SlackDirectAuthMode;
|
|
96
|
+
routePath: string;
|
|
97
|
+
bridge: SlackAssistantBridge;
|
|
98
|
+
server?: Server;
|
|
99
|
+
}
|
|
100
|
+
declare function mountSlackAssistantAgent(options: MountSlackAssistantAgentOptions): Promise<MountSlackAssistantAgentResult>;
|
|
101
|
+
|
|
102
|
+
export { type MountSlackAssistantAgentOptions, type MountSlackAssistantAgentResult, mountSlackAssistantAgent };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mountSlackAssistantAgent
|
|
3
|
+
} from "./chunk-JMLB7A2V.js";
|
|
4
|
+
import "./chunk-BFUPAJON.js";
|
|
5
|
+
import "./chunk-VHGV66M7.js";
|
|
6
|
+
import "./chunk-GNXWTKQ6.js";
|
|
7
|
+
import "./chunk-DHPD4XH5.js";
|
|
8
|
+
import "./chunk-ANIZ5NT4.js";
|
|
9
|
+
import "./chunk-I2KLQ2HA.js";
|
|
10
|
+
export {
|
|
11
|
+
mountSlackAssistantAgent
|
|
12
|
+
};
|