@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,346 @@
|
|
|
1
|
+
import { Agent, AgentTurnSource, AgentEvent, ApprovalEvent, Logger } from '@cuylabs/agent-core';
|
|
2
|
+
import { SlackActivityInfo, SlackTurnRequestContext, SlackAssistantStatusUpdate, SlackChatStreamStartArgs, SlackUserIdentity, SlackTurnPreparation } from '@cuylabs/channel-slack/core';
|
|
3
|
+
import { h as SlackInteractiveRequestHandler } from './interactive-o_NZb-Xg.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Channel-options + adapter contract for the direct Slack adapter
|
|
7
|
+
* (`createSlackChannelAdapter`).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
type HumanInputEvent = Extract<AgentEvent, {
|
|
11
|
+
type: "human-input-request";
|
|
12
|
+
}>["request"];
|
|
13
|
+
type SlackToolStartEvent = Extract<AgentEvent, {
|
|
14
|
+
type: "tool-start";
|
|
15
|
+
}>;
|
|
16
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Session mapping strategy.
|
|
19
|
+
*
|
|
20
|
+
* - `"thread-aware"` *(default)* — Uses the Slack thread_ts as session ID
|
|
21
|
+
* when the message is inside a thread; falls back to the channel ID for
|
|
22
|
+
* DMs and top-level channel messages. Produces the most natural grouping.
|
|
23
|
+
*
|
|
24
|
+
* - `"channel-id"` — Uses the Slack channel / DM ID directly. Every
|
|
25
|
+
* message in the same channel/DM shares one session.
|
|
26
|
+
*
|
|
27
|
+
* - `"user-per-channel"` — Uses `${channelId}:${userId}`. Each user gets
|
|
28
|
+
* an isolated session per channel/DM. Useful for private-context bots.
|
|
29
|
+
*
|
|
30
|
+
* - `"user-per-thread"` — Uses `${channelId}:${threadTs}:${userId}` for
|
|
31
|
+
* threaded/channel messages and `${channelId}:${userId}` in DMs.
|
|
32
|
+
*
|
|
33
|
+
* - `"custom"` — Provide your own mapping via `resolveSessionId`.
|
|
34
|
+
*/
|
|
35
|
+
type SlackSessionStrategy = "thread-aware" | "channel-id" | "user-per-channel" | "user-per-thread" | "custom";
|
|
36
|
+
/**
|
|
37
|
+
* Controls how the bot posts responses to Slack.
|
|
38
|
+
*
|
|
39
|
+
* - `"progressive"` *(default)* — Posts a placeholder message immediately,
|
|
40
|
+
* then updates it as the agent emits text. Gives a typing-like experience.
|
|
41
|
+
* Uses `chat.update` for mid-stream updates.
|
|
42
|
+
*
|
|
43
|
+
* - `"accumulate"` — Waits for the full response before posting. Simpler,
|
|
44
|
+
* uses one API call, but the user sees nothing until the agent finishes.
|
|
45
|
+
*
|
|
46
|
+
* - `"chat-stream"` — Uses Slack's native `chat.startStream`,
|
|
47
|
+
* `chat.appendStream`, and `chat.stopStream` APIs through
|
|
48
|
+
* `WebClient.chatStream`. This is the Slack-native streaming path.
|
|
49
|
+
*/
|
|
50
|
+
type SlackStreamingMode = "progressive" | "accumulate" | "chat-stream";
|
|
51
|
+
/**
|
|
52
|
+
* Configuration for the Slack channel adapter.
|
|
53
|
+
*/
|
|
54
|
+
interface SlackChannelOptions {
|
|
55
|
+
/**
|
|
56
|
+
* The agent-core Agent instance to bridge.
|
|
57
|
+
*
|
|
58
|
+
* Use `source` instead when you want to bridge a runtime/server-backed chat
|
|
59
|
+
* adapter that is not a direct `Agent` instance.
|
|
60
|
+
*/
|
|
61
|
+
agent?: Agent;
|
|
62
|
+
/**
|
|
63
|
+
* Generic chat turn source understood by this package.
|
|
64
|
+
*
|
|
65
|
+
* Exactly one of `agent` or `source` must be provided.
|
|
66
|
+
*/
|
|
67
|
+
source?: AgentTurnSource;
|
|
68
|
+
/**
|
|
69
|
+
* How to map Slack conversations to agent-core session IDs.
|
|
70
|
+
* @default "thread-aware"
|
|
71
|
+
*/
|
|
72
|
+
sessionStrategy?: SlackSessionStrategy;
|
|
73
|
+
/**
|
|
74
|
+
* Custom session ID resolver. Required when `sessionStrategy` is `"custom"`.
|
|
75
|
+
*/
|
|
76
|
+
resolveSessionId?: (info: SlackActivityInfo) => string | Promise<string>;
|
|
77
|
+
/**
|
|
78
|
+
* Optional full-request session resolver. Returning `undefined` falls back
|
|
79
|
+
* to `sessionStrategy` / `resolveSessionId`.
|
|
80
|
+
*
|
|
81
|
+
* Prefer this over `resolveSessionId` when session routing needs auth,
|
|
82
|
+
* prepared text, or other request metadata.
|
|
83
|
+
*/
|
|
84
|
+
resolveSession?: (request: SlackTurnRequestContext) => string | undefined | Promise<string | undefined>;
|
|
85
|
+
/**
|
|
86
|
+
* Surface reasoning events as status updates in Slack.
|
|
87
|
+
* @default false
|
|
88
|
+
*/
|
|
89
|
+
showReasoning?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Surface tool usage as status updates (e.g. "Using tool: search...").
|
|
92
|
+
* This controls root-agent tool rows. Subagent child tool rows are controlled
|
|
93
|
+
* separately by `showSubagentToolUsage`.
|
|
94
|
+
* @default true
|
|
95
|
+
*/
|
|
96
|
+
showToolUsage?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Surface subagent child tool activity as Slack task rows. Disabled by
|
|
99
|
+
* default so delegated workers do not flood the parent turn timeline.
|
|
100
|
+
* Subagent start/complete/error lifecycle rows still render when
|
|
101
|
+
* `showToolUsage` is enabled.
|
|
102
|
+
* @default false
|
|
103
|
+
*/
|
|
104
|
+
showSubagentToolUsage?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Include the completed subagent output body in the subagent task row.
|
|
107
|
+
* Disabled by default because full child results should flow through
|
|
108
|
+
* `get_agent_results` and the root final answer, not the task timeline.
|
|
109
|
+
* @default false
|
|
110
|
+
*/
|
|
111
|
+
showSubagentResultInTask?: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Format the tool-start status text.
|
|
114
|
+
* @default (toolName) => `🔍 Using tool: ${toolName}...`
|
|
115
|
+
*/
|
|
116
|
+
formatToolUpdate?: (toolName: string) => string;
|
|
117
|
+
/**
|
|
118
|
+
* Format the title shown in Slack task cards for tool activity.
|
|
119
|
+
* @default (toolName) => toolName
|
|
120
|
+
*/
|
|
121
|
+
formatToolTitle?: (toolName: string) => string;
|
|
122
|
+
/**
|
|
123
|
+
* Format task-card details for a tool-start event. Use this to show safe,
|
|
124
|
+
* redacted tool arguments in Slack's task UI.
|
|
125
|
+
* @default details use the tool-start status text
|
|
126
|
+
*/
|
|
127
|
+
formatToolDetails?: (event: SlackToolStartEvent) => string | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* Format the tool-error status text.
|
|
130
|
+
* @default (toolName) => `⚠️ Tool ${toolName} encountered an error`
|
|
131
|
+
*/
|
|
132
|
+
formatToolError?: (toolName: string, error: string) => string;
|
|
133
|
+
/**
|
|
134
|
+
* Format the reasoning status text.
|
|
135
|
+
* @default () => "Thinking..."
|
|
136
|
+
*/
|
|
137
|
+
formatReasoningUpdate?: () => string;
|
|
138
|
+
/**
|
|
139
|
+
* Initial Slack thread status set before `prepareTurn` and `source.chat()`
|
|
140
|
+
* run, when Bolt provides `setStatus` for the classic message/app_mention
|
|
141
|
+
* listener. Use an object with `loading_messages` to enable Slack's rotating
|
|
142
|
+
* loading text.
|
|
143
|
+
*
|
|
144
|
+
* Return `undefined` from a function resolver to skip the initial status for
|
|
145
|
+
* a specific turn.
|
|
146
|
+
*
|
|
147
|
+
* @default { status: "Thinking..." }
|
|
148
|
+
*/
|
|
149
|
+
initialStatus?: SlackAssistantStatusUpdate | ((request: SlackTurnRequestContext) => MaybePromise<SlackAssistantStatusUpdate | undefined>);
|
|
150
|
+
/**
|
|
151
|
+
* How to handle approval / human-input requests that Slack cannot satisfy
|
|
152
|
+
* in-channel. When `handleInteractiveRequest` is configured, the handler is
|
|
153
|
+
* tried first; this fallback is only used when the handler declines.
|
|
154
|
+
* @default "message-and-error"
|
|
155
|
+
*/
|
|
156
|
+
interactiveMode?: "message-and-error" | "ignore";
|
|
157
|
+
/**
|
|
158
|
+
* Slack-native renderer/resolver hook for approval and human-input requests.
|
|
159
|
+
*
|
|
160
|
+
* The adapter provides the current Slack activity, resolved session, user,
|
|
161
|
+
* and a responder that can post/update Block Kit messages in the originating
|
|
162
|
+
* thread. Return `true` after rendering/recording the request to keep the
|
|
163
|
+
* agent turn alive while the request is resolved out-of-band.
|
|
164
|
+
*/
|
|
165
|
+
handleInteractiveRequest?: SlackInteractiveRequestHandler;
|
|
166
|
+
/**
|
|
167
|
+
* Format the fallback message shown when tool approval is required.
|
|
168
|
+
*/
|
|
169
|
+
formatApprovalRequired?: (request: ApprovalEvent) => string;
|
|
170
|
+
/**
|
|
171
|
+
* Format the fallback message shown when human input is required.
|
|
172
|
+
*/
|
|
173
|
+
formatHumanInputRequired?: (request: HumanInputEvent) => string;
|
|
174
|
+
/**
|
|
175
|
+
* How the bot posts responses.
|
|
176
|
+
* @default "progressive"
|
|
177
|
+
*/
|
|
178
|
+
streamingMode?: SlackStreamingMode;
|
|
179
|
+
/**
|
|
180
|
+
* Minimum number of accumulated characters before issuing a `chat.update`
|
|
181
|
+
* in progressive mode.
|
|
182
|
+
* @default 150
|
|
183
|
+
*/
|
|
184
|
+
progressiveUpdateThreshold?: number;
|
|
185
|
+
/**
|
|
186
|
+
* Minimum time between `chat.update` calls in progressive mode.
|
|
187
|
+
*
|
|
188
|
+
* Slack recommends waiting at least 3 seconds between updates to longer
|
|
189
|
+
* messages. Set to `0` to disable time throttling.
|
|
190
|
+
*
|
|
191
|
+
* @default 3000
|
|
192
|
+
*/
|
|
193
|
+
progressiveUpdateIntervalMs?: number;
|
|
194
|
+
/**
|
|
195
|
+
* Buffer size passed to Slack's `WebClient.chatStream` helper when
|
|
196
|
+
* `streamingMode` is `"chat-stream"`.
|
|
197
|
+
* @default 256
|
|
198
|
+
*/
|
|
199
|
+
chatStreamBufferSize?: number;
|
|
200
|
+
/**
|
|
201
|
+
* Maximum number of Slack task-update chunks the bridge will append to a
|
|
202
|
+
* single chat stream. Task rows are a bounded UI projection, not a durable
|
|
203
|
+
* event log.
|
|
204
|
+
*
|
|
205
|
+
* @default 200
|
|
206
|
+
*/
|
|
207
|
+
maxTaskUpdates?: number;
|
|
208
|
+
/**
|
|
209
|
+
* Maximum cumulative characters from task titles/details/output that the
|
|
210
|
+
* bridge will append to one chat stream.
|
|
211
|
+
*
|
|
212
|
+
* @default 20000
|
|
213
|
+
*/
|
|
214
|
+
maxTaskUpdateTextChars?: number;
|
|
215
|
+
/**
|
|
216
|
+
* Maximum characters for a single task details/output field.
|
|
217
|
+
*
|
|
218
|
+
* @default 500
|
|
219
|
+
*/
|
|
220
|
+
maxTaskUpdateFieldChars?: number;
|
|
221
|
+
/**
|
|
222
|
+
* Start arguments merged into Slack's native chat stream when
|
|
223
|
+
* `streamingMode` is `"chat-stream"`; useful for Slack-supported authorship
|
|
224
|
+
* fields such as `icon_emoji`, `icon_url`, and `username`.
|
|
225
|
+
*
|
|
226
|
+
* The adapter still owns `channel`, `thread_ts`, recipient ids, and
|
|
227
|
+
* `buffer_size`.
|
|
228
|
+
*/
|
|
229
|
+
chatStreamStartArgs?: SlackChatStreamStartArgs;
|
|
230
|
+
/**
|
|
231
|
+
* Final arguments merged into `chatStream.stop(...)` when
|
|
232
|
+
* `streamingMode` is `"chat-stream"`; useful for final blocks such as a
|
|
233
|
+
* feedback widget.
|
|
234
|
+
*/
|
|
235
|
+
chatStreamFinalArgs?: {
|
|
236
|
+
blocks?: unknown[];
|
|
237
|
+
} & Record<string, unknown>;
|
|
238
|
+
/**
|
|
239
|
+
* Convert common markdown constructs emitted by models into Slack mrkdwn.
|
|
240
|
+
*
|
|
241
|
+
* @default true
|
|
242
|
+
*/
|
|
243
|
+
formatChatMarkdown?: boolean;
|
|
244
|
+
/**
|
|
245
|
+
* Custom response text formatter. When provided, this takes precedence over
|
|
246
|
+
* the built-in markdown-to-mrkdwn conversion.
|
|
247
|
+
*/
|
|
248
|
+
formatMessageText?: (text: string) => string;
|
|
249
|
+
/**
|
|
250
|
+
* Maximum time (ms) to wait for the agent before aborting.
|
|
251
|
+
* @default 120_000
|
|
252
|
+
*/
|
|
253
|
+
timeout?: number;
|
|
254
|
+
/**
|
|
255
|
+
* When `true` (default), replies to channel messages are posted inside the
|
|
256
|
+
* originating thread. When `false`, replies are posted at channel level.
|
|
257
|
+
* Has no effect in DMs.
|
|
258
|
+
* @default true
|
|
259
|
+
*/
|
|
260
|
+
respondInThread?: boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Welcome message sent when the bot is added to a channel or DM.
|
|
263
|
+
* Set to `null` to disable.
|
|
264
|
+
*/
|
|
265
|
+
welcomeMessage?: string | null;
|
|
266
|
+
/**
|
|
267
|
+
* When `true` (default), `app.event('app_mention')` is registered so the
|
|
268
|
+
* bot responds to `@mentions` in channels.
|
|
269
|
+
* @default true
|
|
270
|
+
*/
|
|
271
|
+
respondToMentions?: boolean;
|
|
272
|
+
/**
|
|
273
|
+
* When `true` (default), `app.message()` is registered so the bot
|
|
274
|
+
* can respond to direct messages and, when enabled, plain channel messages.
|
|
275
|
+
*
|
|
276
|
+
* Set to `false` if you only want @mention-triggered responses.
|
|
277
|
+
* @default true
|
|
278
|
+
*/
|
|
279
|
+
respondToMessages?: boolean;
|
|
280
|
+
/**
|
|
281
|
+
* When `true`, plain channel/group/thread messages from `app.message()` are
|
|
282
|
+
* forwarded into the agent. Direct messages still work through
|
|
283
|
+
* `respondToMessages`.
|
|
284
|
+
*
|
|
285
|
+
* Keep this disabled unless your Slack app intentionally listens to every
|
|
286
|
+
* visible channel message. @mentions are handled separately by
|
|
287
|
+
* `respondToMentions`.
|
|
288
|
+
* @default false
|
|
289
|
+
*/
|
|
290
|
+
respondToChannelMessages?: boolean;
|
|
291
|
+
/**
|
|
292
|
+
* Resolve additional context to inject into the agent call.
|
|
293
|
+
*
|
|
294
|
+
* Use this to customize the system prompt per user, inject Slack identity,
|
|
295
|
+
* etc. Called before `source.chat()` on every message.
|
|
296
|
+
*/
|
|
297
|
+
resolveUserContext?: (user: SlackUserIdentity) => {
|
|
298
|
+
system?: string;
|
|
299
|
+
} | Promise<{
|
|
300
|
+
system?: string;
|
|
301
|
+
}>;
|
|
302
|
+
/**
|
|
303
|
+
* Prepare an agent turn from the full Slack request context.
|
|
304
|
+
*
|
|
305
|
+
* Prefer this over `resolveUserContext` when you need structured ambient
|
|
306
|
+
* context for tools/middleware or custom scope attributes.
|
|
307
|
+
*/
|
|
308
|
+
prepareTurn?: (request: SlackTurnRequestContext) => SlackTurnPreparation | Promise<SlackTurnPreparation>;
|
|
309
|
+
/**
|
|
310
|
+
* Resolve the text message forwarded to `source.chat()`.
|
|
311
|
+
*
|
|
312
|
+
* Useful when the message text needs normalisation beyond mention-stripping.
|
|
313
|
+
* Return `undefined` to skip processing this message.
|
|
314
|
+
*/
|
|
315
|
+
resolveMessage?: (info: SlackActivityInfo) => string | undefined | Promise<string | undefined>;
|
|
316
|
+
/**
|
|
317
|
+
* Called on unhandled errors during turn processing.
|
|
318
|
+
*/
|
|
319
|
+
onError?: (error: Error, info: SlackActivityInfo) => void | Promise<void>;
|
|
320
|
+
/**
|
|
321
|
+
* Optional diagnostics logger. Used for best-effort status/update failures
|
|
322
|
+
* and classic turn utility visibility.
|
|
323
|
+
*/
|
|
324
|
+
logger?: Logger;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Slack channel adapter returned by `createSlackChannelAdapter`.
|
|
328
|
+
*/
|
|
329
|
+
interface SlackChannelAdapter {
|
|
330
|
+
/**
|
|
331
|
+
* Register all message/event handlers on a Bolt `App`.
|
|
332
|
+
*
|
|
333
|
+
* ```ts
|
|
334
|
+
* const adapter = createSlackChannelAdapter({ agent });
|
|
335
|
+
* adapter.mount(boltApp);
|
|
336
|
+
* ```
|
|
337
|
+
*/
|
|
338
|
+
mount(app: {
|
|
339
|
+
message: (...args: any[]) => unknown;
|
|
340
|
+
event: (...args: any[]) => unknown;
|
|
341
|
+
}): void;
|
|
342
|
+
/** Resolve or look up the session ID for a given Slack activity. */
|
|
343
|
+
getSessionId(info: SlackActivityInfo): string | Promise<string>;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export type { SlackChannelAdapter as S, SlackChannelOptions as a, SlackSessionStrategy as b, SlackStreamingMode as c, SlackToolStartEvent as d };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { ApprovalAction, ApprovalRememberScope, HumanInputResponse, ApprovalRequest, HumanInputRequest, ApprovalResolution } from '@cuylabs/agent-core';
|
|
2
|
+
import { App } from '@slack/bolt';
|
|
3
|
+
import { S as SlackApprovalRequest, b as SlackHumanInputRequest, g as SlackInteractiveRequestContext, d as SlackInteractiveMessageRef } from './interactive-o_NZb-Xg.js';
|
|
4
|
+
|
|
5
|
+
type SlackInteractiveRequestStatus = "pending" | "resolved";
|
|
6
|
+
type SlackInteractiveApprovalRequest = ApprovalRequest | SlackApprovalRequest;
|
|
7
|
+
type SlackInteractiveHumanInputRequest = SlackHumanInputRequest & Partial<Pick<HumanInputRequest, "sessionId" | "timestamp" | "toolCallId">>;
|
|
8
|
+
type SlackInteractiveStoredRequest = SlackInteractiveApprovalRequest | SlackInteractiveHumanInputRequest;
|
|
9
|
+
type SlackInteractiveResolution = {
|
|
10
|
+
kind: "approval";
|
|
11
|
+
action: ApprovalAction;
|
|
12
|
+
feedback?: string;
|
|
13
|
+
rememberScope?: ApprovalRememberScope;
|
|
14
|
+
} | {
|
|
15
|
+
kind: "human-input";
|
|
16
|
+
response: HumanInputResponse;
|
|
17
|
+
};
|
|
18
|
+
interface SlackInteractiveMessageTarget {
|
|
19
|
+
channel: string;
|
|
20
|
+
ts: string;
|
|
21
|
+
threadTs?: string;
|
|
22
|
+
userId: string;
|
|
23
|
+
teamId?: string;
|
|
24
|
+
}
|
|
25
|
+
interface SlackInteractiveRequestRecord {
|
|
26
|
+
id: string;
|
|
27
|
+
kind: SlackInteractiveResolution["kind"];
|
|
28
|
+
request: SlackInteractiveStoredRequest;
|
|
29
|
+
status: SlackInteractiveRequestStatus;
|
|
30
|
+
createdAt: string;
|
|
31
|
+
updatedAt: string;
|
|
32
|
+
target?: SlackInteractiveMessageTarget;
|
|
33
|
+
resolution?: SlackInteractiveResolution;
|
|
34
|
+
}
|
|
35
|
+
interface SlackInteractiveRequestStore {
|
|
36
|
+
get(requestId: string): Promise<SlackInteractiveRequestRecord | undefined>;
|
|
37
|
+
upsert(record: SlackInteractiveRequestRecord): Promise<SlackInteractiveRequestRecord>;
|
|
38
|
+
/**
|
|
39
|
+
* Attach the Slack message target for an already-upserted request.
|
|
40
|
+
*
|
|
41
|
+
* Implementations should return `undefined` when the request does not exist;
|
|
42
|
+
* callers must upsert before attaching a target.
|
|
43
|
+
*/
|
|
44
|
+
attachTarget(requestId: string, target: SlackInteractiveMessageTarget): Promise<SlackInteractiveRequestRecord | undefined>;
|
|
45
|
+
/**
|
|
46
|
+
* Mark a request resolved. Implementations must be idempotent: resolving an
|
|
47
|
+
* already-resolved request should return the existing record without
|
|
48
|
+
* overwriting the original resolution.
|
|
49
|
+
*/
|
|
50
|
+
resolve(requestId: string, resolution: SlackInteractiveResolution): Promise<SlackInteractiveRequestRecord | undefined>;
|
|
51
|
+
delete(requestId: string): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
interface SlackInteractiveActionIds {
|
|
54
|
+
approvalAllow: string;
|
|
55
|
+
approvalDeny: string;
|
|
56
|
+
approvalRemember: string;
|
|
57
|
+
humanConfirm: string;
|
|
58
|
+
humanDeny: string;
|
|
59
|
+
humanOpen: string;
|
|
60
|
+
humanSubmit: string;
|
|
61
|
+
}
|
|
62
|
+
interface SlackInteractiveActor {
|
|
63
|
+
userId: string;
|
|
64
|
+
teamId?: string;
|
|
65
|
+
}
|
|
66
|
+
interface SlackInteractiveRequestWaitOptions {
|
|
67
|
+
/**
|
|
68
|
+
* Abort waiting for this request. The controller removes its local waiter and
|
|
69
|
+
* deletes the pending store record when the signal fires.
|
|
70
|
+
*/
|
|
71
|
+
signal?: AbortSignal;
|
|
72
|
+
/**
|
|
73
|
+
* Override the controller-level request timeout for this request. Use `0` to
|
|
74
|
+
* disable timeout cleanup for this request.
|
|
75
|
+
*/
|
|
76
|
+
timeoutMs?: number;
|
|
77
|
+
}
|
|
78
|
+
interface SlackInteractiveControllerOptions {
|
|
79
|
+
store?: SlackInteractiveRequestStore;
|
|
80
|
+
/**
|
|
81
|
+
* Stable namespace for default Slack action IDs. Use this when installing
|
|
82
|
+
* multiple interactive controllers in the same Slack app.
|
|
83
|
+
*
|
|
84
|
+
* @default "agent_slack"
|
|
85
|
+
*/
|
|
86
|
+
namespace?: string;
|
|
87
|
+
actionIds?: Partial<SlackInteractiveActionIds>;
|
|
88
|
+
/**
|
|
89
|
+
* Default timeout for local waiters and pending store records. This should
|
|
90
|
+
* usually match the agent-core approval/human-input timeout.
|
|
91
|
+
*
|
|
92
|
+
* @default 300000
|
|
93
|
+
*/
|
|
94
|
+
requestTimeoutMs?: number;
|
|
95
|
+
/**
|
|
96
|
+
* Called on every successful Slack resolution after the local waiter, if
|
|
97
|
+
* present, is resolved. Use this to fan out decisions to agent-server or
|
|
98
|
+
* another runtime that owns the turn.
|
|
99
|
+
*/
|
|
100
|
+
onResolve?: (requestId: string, resolution: SlackInteractiveResolution) => void | Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Authorization hook for approving/responding to pending requests.
|
|
103
|
+
*
|
|
104
|
+
* Defaults to the original Slack requester only. Return `true` for delegated
|
|
105
|
+
* approvers, channel owners, or admin policy checks.
|
|
106
|
+
*/
|
|
107
|
+
authorize?: (record: SlackInteractiveRequestRecord, actor: SlackInteractiveActor) => boolean | Promise<boolean>;
|
|
108
|
+
}
|
|
109
|
+
interface SlackInteractiveController {
|
|
110
|
+
readonly actionIds: SlackInteractiveActionIds;
|
|
111
|
+
readonly store: SlackInteractiveRequestStore;
|
|
112
|
+
approval: {
|
|
113
|
+
onRequest(request: ApprovalRequest, options?: SlackInteractiveRequestWaitOptions): Promise<ApprovalResolution>;
|
|
114
|
+
};
|
|
115
|
+
humanInput: {
|
|
116
|
+
onRequest(request: HumanInputRequest, options?: SlackInteractiveRequestWaitOptions): Promise<HumanInputResponse>;
|
|
117
|
+
};
|
|
118
|
+
/** Reject one pending in-process waiter and delete its pending store record. */
|
|
119
|
+
cancel(requestId: string, reason?: string): Promise<boolean>;
|
|
120
|
+
/** Shutdown helper: cancel every pending request created by this controller. */
|
|
121
|
+
cancelAll(reason?: string): Promise<void>;
|
|
122
|
+
handleInteractiveRequest(context: SlackInteractiveRequestContext): Promise<boolean>;
|
|
123
|
+
install(app: App): void;
|
|
124
|
+
}
|
|
125
|
+
type SlackInteractivePendingWaiter = {
|
|
126
|
+
resolve: (resolution: SlackInteractiveResolution) => void;
|
|
127
|
+
reject: (error: Error) => void;
|
|
128
|
+
cleanup: () => void;
|
|
129
|
+
};
|
|
130
|
+
interface SlackInteractivePostedMessage {
|
|
131
|
+
text: string;
|
|
132
|
+
blocks: unknown[];
|
|
133
|
+
ref: SlackInteractiveMessageRef;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export type { SlackInteractiveActionIds as S, SlackInteractiveActor as a, SlackInteractiveApprovalRequest as b, SlackInteractiveController as c, SlackInteractiveControllerOptions as d, SlackInteractiveHumanInputRequest as e, SlackInteractiveMessageTarget as f, SlackInteractivePendingWaiter as g, SlackInteractivePostedMessage as h, SlackInteractiveRequestRecord as i, SlackInteractiveRequestStatus as j, SlackInteractiveRequestStore as k, SlackInteractiveRequestWaitOptions as l, SlackInteractiveResolution as m, SlackInteractiveStoredRequest as n };
|
package/dist/users.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@cuylabs/channel-slack/users';
|
package/dist/users.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cuylabs/channel-slack-agent-core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Slack adapter for @cuylabs/agent-core built on @cuylabs/channel-slack",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./adapter": {
|
|
15
|
+
"types": "./dist/adapter.d.ts",
|
|
16
|
+
"import": "./dist/adapter.js",
|
|
17
|
+
"default": "./dist/adapter.js"
|
|
18
|
+
},
|
|
19
|
+
"./app": {
|
|
20
|
+
"types": "./dist/app.d.ts",
|
|
21
|
+
"import": "./dist/app.js",
|
|
22
|
+
"default": "./dist/app.js"
|
|
23
|
+
},
|
|
24
|
+
"./app-surface": {
|
|
25
|
+
"types": "./dist/app-surface.d.ts",
|
|
26
|
+
"import": "./dist/app-surface.js",
|
|
27
|
+
"default": "./dist/app-surface.js"
|
|
28
|
+
},
|
|
29
|
+
"./assistant": {
|
|
30
|
+
"types": "./dist/assistant.d.ts",
|
|
31
|
+
"import": "./dist/assistant.js",
|
|
32
|
+
"default": "./dist/assistant.js"
|
|
33
|
+
},
|
|
34
|
+
"./bolt": {
|
|
35
|
+
"types": "./dist/bolt.d.ts",
|
|
36
|
+
"import": "./dist/bolt.js",
|
|
37
|
+
"default": "./dist/bolt.js"
|
|
38
|
+
},
|
|
39
|
+
"./diagnostics": {
|
|
40
|
+
"types": "./dist/diagnostics.d.ts",
|
|
41
|
+
"import": "./dist/diagnostics.js",
|
|
42
|
+
"default": "./dist/diagnostics.js"
|
|
43
|
+
},
|
|
44
|
+
"./express": {
|
|
45
|
+
"types": "./dist/express.d.ts",
|
|
46
|
+
"import": "./dist/express.js",
|
|
47
|
+
"default": "./dist/express.js"
|
|
48
|
+
},
|
|
49
|
+
"./express-assistant": {
|
|
50
|
+
"types": "./dist/express-assistant.d.ts",
|
|
51
|
+
"import": "./dist/express-assistant.js",
|
|
52
|
+
"default": "./dist/express-assistant.js"
|
|
53
|
+
},
|
|
54
|
+
"./feedback": {
|
|
55
|
+
"types": "./dist/feedback.d.ts",
|
|
56
|
+
"import": "./dist/feedback.js",
|
|
57
|
+
"default": "./dist/feedback.js"
|
|
58
|
+
},
|
|
59
|
+
"./history": {
|
|
60
|
+
"types": "./dist/history.d.ts",
|
|
61
|
+
"import": "./dist/history.js",
|
|
62
|
+
"default": "./dist/history.js"
|
|
63
|
+
},
|
|
64
|
+
"./interactive": {
|
|
65
|
+
"types": "./dist/interactive.d.ts",
|
|
66
|
+
"import": "./dist/interactive.js",
|
|
67
|
+
"default": "./dist/interactive.js"
|
|
68
|
+
},
|
|
69
|
+
"./mcp": {
|
|
70
|
+
"types": "./dist/mcp.d.ts",
|
|
71
|
+
"import": "./dist/mcp.js",
|
|
72
|
+
"default": "./dist/mcp.js"
|
|
73
|
+
},
|
|
74
|
+
"./policy": {
|
|
75
|
+
"types": "./dist/policy.d.ts",
|
|
76
|
+
"import": "./dist/policy.js",
|
|
77
|
+
"default": "./dist/policy.js"
|
|
78
|
+
},
|
|
79
|
+
"./setup": {
|
|
80
|
+
"types": "./dist/setup.d.ts",
|
|
81
|
+
"import": "./dist/setup.js",
|
|
82
|
+
"default": "./dist/setup.js"
|
|
83
|
+
},
|
|
84
|
+
"./shared": {
|
|
85
|
+
"types": "./dist/shared.d.ts",
|
|
86
|
+
"import": "./dist/shared.js",
|
|
87
|
+
"default": "./dist/shared.js"
|
|
88
|
+
},
|
|
89
|
+
"./socket": {
|
|
90
|
+
"types": "./dist/socket.d.ts",
|
|
91
|
+
"import": "./dist/socket.js",
|
|
92
|
+
"default": "./dist/socket.js"
|
|
93
|
+
},
|
|
94
|
+
"./targets": {
|
|
95
|
+
"types": "./dist/targets.d.ts",
|
|
96
|
+
"import": "./dist/targets.js",
|
|
97
|
+
"default": "./dist/targets.js"
|
|
98
|
+
},
|
|
99
|
+
"./users": {
|
|
100
|
+
"types": "./dist/users.d.ts",
|
|
101
|
+
"import": "./dist/users.js",
|
|
102
|
+
"default": "./dist/users.js"
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
"files": [
|
|
106
|
+
"dist",
|
|
107
|
+
"README.md"
|
|
108
|
+
],
|
|
109
|
+
"dependencies": {
|
|
110
|
+
"@cuylabs/agent-core": "^7.2.0",
|
|
111
|
+
"@cuylabs/channel-slack": "^0.1.0"
|
|
112
|
+
},
|
|
113
|
+
"peerDependencies": {
|
|
114
|
+
"@slack/bolt": ">=4.7.3",
|
|
115
|
+
"@slack/types": ">=2.21.1",
|
|
116
|
+
"@slack/web-api": ">=7.16.0",
|
|
117
|
+
"express": ">=4.21.0 || >=5.0.0"
|
|
118
|
+
},
|
|
119
|
+
"peerDependenciesMeta": {
|
|
120
|
+
"@slack/bolt": {
|
|
121
|
+
"optional": true
|
|
122
|
+
},
|
|
123
|
+
"@slack/types": {
|
|
124
|
+
"optional": true
|
|
125
|
+
},
|
|
126
|
+
"@slack/web-api": {
|
|
127
|
+
"optional": true
|
|
128
|
+
},
|
|
129
|
+
"express": {
|
|
130
|
+
"optional": true
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
"devDependencies": {
|
|
134
|
+
"@slack/bolt": "^4.7.3",
|
|
135
|
+
"@slack/types": "^2.21.1",
|
|
136
|
+
"@slack/web-api": "^7.16.0",
|
|
137
|
+
"@types/express": "^5.0.0",
|
|
138
|
+
"@types/node": "^22.0.0",
|
|
139
|
+
"express": "^5.2.1",
|
|
140
|
+
"tsup": "^8.0.0",
|
|
141
|
+
"typescript": "^5.7.0",
|
|
142
|
+
"vitest": "^4.0.18"
|
|
143
|
+
},
|
|
144
|
+
"keywords": [
|
|
145
|
+
"ai",
|
|
146
|
+
"agent",
|
|
147
|
+
"slack",
|
|
148
|
+
"channel",
|
|
149
|
+
"adapter",
|
|
150
|
+
"agent-core",
|
|
151
|
+
"bolt"
|
|
152
|
+
],
|
|
153
|
+
"license": "Apache-2.0",
|
|
154
|
+
"publishConfig": {
|
|
155
|
+
"access": "public"
|
|
156
|
+
},
|
|
157
|
+
"engines": {
|
|
158
|
+
"node": ">=20"
|
|
159
|
+
},
|
|
160
|
+
"scripts": {
|
|
161
|
+
"build": "tsup src/index.ts src/shared.ts src/adapter.ts src/app.ts src/app-surface.ts src/assistant.ts src/bolt.ts src/diagnostics.ts src/express.ts src/express-assistant.ts src/feedback.ts src/history.ts src/interactive.ts src/mcp.ts src/policy.ts src/setup.ts src/socket.ts src/targets.ts src/users.ts --format esm --dts --clean",
|
|
162
|
+
"clean": "rm -rf dist",
|
|
163
|
+
"dev": "tsup src/index.ts src/shared.ts src/adapter.ts src/app.ts src/app-surface.ts src/assistant.ts src/bolt.ts src/diagnostics.ts src/express.ts src/express-assistant.ts src/feedback.ts src/history.ts src/interactive.ts src/mcp.ts src/policy.ts src/setup.ts src/socket.ts src/targets.ts src/users.ts --format esm --dts --watch",
|
|
164
|
+
"lint": "eslint \"src/**/*.{ts,tsx}\" \"tests/**/*.{ts,tsx}\" --max-warnings=0",
|
|
165
|
+
"test": "vitest run",
|
|
166
|
+
"test:watch": "vitest",
|
|
167
|
+
"typecheck": "tsc --noEmit"
|
|
168
|
+
}
|
|
169
|
+
}
|