@cuylabs/channel-slack 0.10.0 → 0.11.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/README.md +15 -2
- package/dist/adapter/index.d.ts +53 -0
- package/dist/adapter/index.js +13 -0
- package/dist/app-surface.d.ts +86 -0
- package/dist/app-surface.js +15 -0
- package/dist/app.d.ts +58 -0
- package/dist/app.js +86 -0
- package/dist/artifacts/index.d.ts +57 -3
- package/dist/artifacts/index.js +88 -0
- package/dist/assistant/index.d.ts +18 -53
- package/dist/assistant/index.js +15 -184
- package/dist/bolt-app-BM0tiL7c.d.ts +49 -0
- package/dist/{chunk-TWJGVDA2.js → chunk-37RN2YUI.js} +88 -1
- package/dist/chunk-LFQCINHI.js +187 -0
- package/dist/chunk-Q6YX7HHK.js +1062 -0
- package/dist/chunk-RHOIVQLD.js +127 -0
- package/dist/chunk-RTDLIYEE.js +446 -0
- package/dist/core.d.ts +5 -201
- package/dist/core.js +10 -12
- package/dist/feedback/index.d.ts +2 -2
- package/dist/feedback/index.js +5 -120
- package/dist/formatting-C-kwQseI.d.ts +25 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.js +10 -12
- package/dist/options-B0xQCaez.d.ts +221 -0
- package/dist/options-DQacQDmD.d.ts +368 -0
- package/dist/runtime/index.d.ts +6 -220
- package/dist/socket.d.ts +142 -0
- package/dist/socket.js +77 -0
- package/dist/transports/index.d.ts +2 -1
- package/dist/transports/socket/index.d.ts +4 -49
- package/dist/turn-BGAXddH_.d.ts +178 -0
- package/dist/types-wLZzyI9r.d.ts +375 -0
- package/docs/reference/exports.md +5 -1
- package/package.json +23 -3
- package/dist/chunk-ISOMBQXE.js +0 -89
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { S as SlackActivityInfo, b as SlackUserIdentity } from './activity-ByrD9Ftr.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Slack auth context — credentials and identifiers resolved from the inbound
|
|
5
|
+
* request. **Sensitive**: see security note on `SlackAuthContext`.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Slack credentials and identifiers resolved from the inbound request.
|
|
9
|
+
*
|
|
10
|
+
* Surfaced to `prepareTurn`, the ambient `currentSlackTurnContext()`, and the
|
|
11
|
+
* assistant message context so tools and middleware can call the Slack Web
|
|
12
|
+
* API or attach per-user OAuth tokens to MCP servers (see
|
|
13
|
+
* `createSlackMcpServerConfig`).
|
|
14
|
+
*
|
|
15
|
+
* Security: `botToken` and `userToken` are secrets. Do not include this auth
|
|
16
|
+
* bag in logs, telemetry attributes, baggage, tool results, message history,
|
|
17
|
+
* or model-visible prompts. Pass only the exact token needed to a trusted
|
|
18
|
+
* Slack API/MCP client.
|
|
19
|
+
*
|
|
20
|
+
* Most fields come from Bolt's enriched `args.context`. They are all optional
|
|
21
|
+
* because availability depends on the auth mode (single-workspace vs OAuth)
|
|
22
|
+
* and on whether the installer granted user scopes.
|
|
23
|
+
*/
|
|
24
|
+
interface SlackAuthContext {
|
|
25
|
+
/** Workspace bot token (`xoxb-...`). */
|
|
26
|
+
botToken?: string;
|
|
27
|
+
/** End-user OAuth token (`xoxp-...`) when user scopes were granted. */
|
|
28
|
+
userToken?: string;
|
|
29
|
+
/** Workspace ID (`T...`). */
|
|
30
|
+
teamId?: string;
|
|
31
|
+
/** Enterprise grid ID (`E...`) when applicable. */
|
|
32
|
+
enterpriseId?: string;
|
|
33
|
+
/** Bot user ID (`U...`) — useful for distinguishing bot self-mentions. */
|
|
34
|
+
botUserId?: string;
|
|
35
|
+
/** Internal Slack bot ID (`B...`). */
|
|
36
|
+
botId?: string;
|
|
37
|
+
/** Slack user ID (`U...`) of the human author of the inbound event. */
|
|
38
|
+
userId?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Slack assistant lifecycle types — status updates, suggested prompts, thread
|
|
43
|
+
* context, and the channel-neutral `SlackAssistantUtilities` interface that
|
|
44
|
+
* the assistant bridge surfaces ambiently for tools and middleware.
|
|
45
|
+
*/
|
|
46
|
+
/**
|
|
47
|
+
* Slack assistant thread context — the channel of origin metadata Slack tracks
|
|
48
|
+
* while a user navigates the workspace. Surfaces the same fields Bolt's
|
|
49
|
+
* `AssistantThreadContextStore` returns.
|
|
50
|
+
*
|
|
51
|
+
* @see https://docs.slack.dev/reference/events/assistant_thread_context_changed
|
|
52
|
+
*/
|
|
53
|
+
interface SlackAssistantThreadContext {
|
|
54
|
+
channel_id?: string;
|
|
55
|
+
team_id?: string;
|
|
56
|
+
enterprise_id?: string | null;
|
|
57
|
+
}
|
|
58
|
+
/** Display mode passed to `client.chatStream`. */
|
|
59
|
+
type SlackAssistantTaskDisplayMode = "plan" | "timeline";
|
|
60
|
+
/**
|
|
61
|
+
* Slack message authorship fields supported by AI assistant status updates
|
|
62
|
+
* and native chat stream start calls.
|
|
63
|
+
*/
|
|
64
|
+
interface SlackMessageAuthorshipOptions {
|
|
65
|
+
/** Emoji shown as the message/status icon, e.g. `":robot_face:"`. */
|
|
66
|
+
icon_emoji?: string;
|
|
67
|
+
/** Image URL shown as the message/status icon. */
|
|
68
|
+
icon_url?: string;
|
|
69
|
+
/** Display name shown for the message/status. */
|
|
70
|
+
username?: string;
|
|
71
|
+
}
|
|
72
|
+
/** Optional passthrough fields for Slack's native `chat.startStream`. */
|
|
73
|
+
type SlackChatStreamStartArgs = SlackMessageAuthorshipOptions & {
|
|
74
|
+
/**
|
|
75
|
+
* Slack task display mode for streamed tool/task chunks. `timeline` shows
|
|
76
|
+
* individual task cards; `plan` groups task cards together.
|
|
77
|
+
*/
|
|
78
|
+
task_display_mode?: SlackAssistantTaskDisplayMode;
|
|
79
|
+
};
|
|
80
|
+
/** A single suggested prompt chip shown in the assistant pane. */
|
|
81
|
+
interface SlackAssistantSuggestedPrompt {
|
|
82
|
+
title: string;
|
|
83
|
+
message: string;
|
|
84
|
+
}
|
|
85
|
+
/** Suggested prompts payload for `assistant.threads.setSuggestedPrompts`. */
|
|
86
|
+
interface SlackAssistantSuggestedPrompts {
|
|
87
|
+
/** Title shown above the chips. Defaults to Slack's "Try these prompts:". */
|
|
88
|
+
title?: string;
|
|
89
|
+
prompts: SlackAssistantSuggestedPrompt[];
|
|
90
|
+
}
|
|
91
|
+
/** Status payload accepted by Bolt's assistant `setStatus`. */
|
|
92
|
+
interface SlackAssistantStatusUpdate extends SlackMessageAuthorshipOptions {
|
|
93
|
+
status: string;
|
|
94
|
+
loading_messages?: string[];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Assistant pane utilities surfaced ambiently so tools/middleware can call
|
|
98
|
+
* them mid-turn without wiring the raw Bolt args through.
|
|
99
|
+
*
|
|
100
|
+
* Only present when the turn is running through the assistant bridge.
|
|
101
|
+
*/
|
|
102
|
+
interface SlackAssistantUtilities {
|
|
103
|
+
setStatus: (update: SlackAssistantStatusUpdate) => Promise<void>;
|
|
104
|
+
setSuggestedPrompts: (prompts: SlackAssistantSuggestedPrompts) => Promise<void>;
|
|
105
|
+
setTitle: (title: string) => Promise<void>;
|
|
106
|
+
getThreadContext: () => Promise<SlackAssistantThreadContext>;
|
|
107
|
+
saveThreadContext: () => Promise<void>;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Status utility exposed by Bolt for any message/app_mention event with a
|
|
111
|
+
* channel + thread timestamp. It calls Slack's assistant thread status API,
|
|
112
|
+
* but unlike the full Assistant surface it does not imply suggested prompts,
|
|
113
|
+
* thread titles, or origin-channel context.
|
|
114
|
+
*/
|
|
115
|
+
type SlackThreadStatusSetter = (update: SlackAssistantStatusUpdate) => Promise<void>;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Slack turn-request and turn-preparation contracts shared by Slack transport
|
|
119
|
+
* packages. Direct Slack fills these from Bolt events; M365-backed Slack fills
|
|
120
|
+
* the same shape from Bot Framework activities.
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Context available while preparing a Slack turn.
|
|
125
|
+
*/
|
|
126
|
+
interface SlackTurnRequestContext {
|
|
127
|
+
/** Parsed Slack activity metadata */
|
|
128
|
+
slackActivity: SlackActivityInfo;
|
|
129
|
+
/** Extracted Slack user identity */
|
|
130
|
+
user: SlackUserIdentity;
|
|
131
|
+
/** Resolved runtime session ID for this conversation */
|
|
132
|
+
sessionId: string;
|
|
133
|
+
/** Plain-text message forwarded to the host application */
|
|
134
|
+
message: string;
|
|
135
|
+
/**
|
|
136
|
+
* Slack auth + identity resolved from the inbound request.
|
|
137
|
+
*
|
|
138
|
+
* Includes the bot token, optional end-user OAuth token, team/enterprise
|
|
139
|
+
* IDs, and bot user ID. Tools and `prepareTurn` callers can use these to
|
|
140
|
+
* call the Slack Web API or attach the user token to MCP servers.
|
|
141
|
+
*/
|
|
142
|
+
auth?: SlackAuthContext;
|
|
143
|
+
/**
|
|
144
|
+
* Assistant thread context resolved by Bolt for assistant-pane turns.
|
|
145
|
+
*
|
|
146
|
+
* Tells the runtime which channel/workspace the user is currently viewing
|
|
147
|
+
* while talking to the assistant — useful for context-aware system prompts
|
|
148
|
+
* and for resolving relative references like "this channel".
|
|
149
|
+
*
|
|
150
|
+
* `undefined` when the turn was not routed through the assistant bridge.
|
|
151
|
+
*/
|
|
152
|
+
threadContext?: SlackAssistantThreadContext;
|
|
153
|
+
/**
|
|
154
|
+
* Slack thread status setter available when Bolt provides `setStatus` for
|
|
155
|
+
* the inbound event. This can be present on classic `app_mention` /
|
|
156
|
+
* `message` turns as well as full Assistant-pane turns.
|
|
157
|
+
*/
|
|
158
|
+
setStatus?: SlackThreadStatusSetter;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Optional turn preparation result for a Slack turn.
|
|
162
|
+
*/
|
|
163
|
+
interface SlackTurnPreparation {
|
|
164
|
+
/** Optional system override for the host application */
|
|
165
|
+
system?: string;
|
|
166
|
+
/** Optional message override for the host application. */
|
|
167
|
+
message?: string;
|
|
168
|
+
/** Optional session override for this turn. */
|
|
169
|
+
sessionId?: string;
|
|
170
|
+
/** Optional custom scope name for the activity */
|
|
171
|
+
scopeName?: string;
|
|
172
|
+
/** Additional scalar attributes merged into the activity scope */
|
|
173
|
+
scopeAttributes?: Record<string, string | number | boolean | null | undefined>;
|
|
174
|
+
/** Arbitrary app-specific per-turn context exposed via AsyncLocalStorage */
|
|
175
|
+
context?: Record<string, unknown>;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export type { SlackAssistantStatusUpdate as S, SlackAssistantSuggestedPrompt as a, SlackAssistantSuggestedPrompts as b, SlackAssistantTaskDisplayMode as c, SlackAssistantThreadContext as d, SlackAssistantUtilities as e, SlackAuthContext as f, SlackChatStreamStartArgs as g, SlackMessageAuthorshipOptions as h, SlackThreadStatusSetter as i, SlackTurnPreparation as j, SlackTurnRequestContext as k };
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import { S as SlackActivityInfo, b as SlackUserIdentity } from './activity-ByrD9Ftr.js';
|
|
2
|
+
import { k as SlackTurnRequestContext, S as SlackAssistantStatusUpdate, g as SlackChatStreamStartArgs, j as SlackTurnPreparation } from './turn-BGAXddH_.js';
|
|
3
|
+
import { h as SlackInteractiveRequestHandler } from './interactive-CbKYkkc_.js';
|
|
4
|
+
import { o as SlackTurnSource, i as SlackTurnEvent, S as SlackEventBridgeOptions } from './options-B0xQCaez.js';
|
|
5
|
+
import { L as Logger } from './logging-Bl3HfcC8.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Channel-options + adapter contract for the direct Slack adapter
|
|
9
|
+
* (`createSlackChannelAdapter`).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
type HumanInputEvent = Extract<SlackTurnEvent, {
|
|
13
|
+
type: "human-input-request";
|
|
14
|
+
}>["request"];
|
|
15
|
+
type SlackToolStartEvent = Extract<SlackTurnEvent, {
|
|
16
|
+
type: "tool-start";
|
|
17
|
+
}>;
|
|
18
|
+
type SlackToolResultEvent = Extract<SlackTurnEvent, {
|
|
19
|
+
type: "tool-result";
|
|
20
|
+
}>;
|
|
21
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
22
|
+
/**
|
|
23
|
+
* Session mapping strategy.
|
|
24
|
+
*
|
|
25
|
+
* - `"thread-aware"` *(default)* — Uses the Slack thread_ts as session ID
|
|
26
|
+
* when the message is inside a thread; falls back to the channel ID for
|
|
27
|
+
* DMs and top-level channel messages. Produces the most natural grouping.
|
|
28
|
+
*
|
|
29
|
+
* - `"channel-id"` — Uses the Slack channel / DM ID directly. Every
|
|
30
|
+
* message in the same channel/DM shares one session.
|
|
31
|
+
*
|
|
32
|
+
* - `"user-per-channel"` — Uses `${channelId}:${userId}`. Each user gets
|
|
33
|
+
* an isolated session per channel/DM. Useful for private-context bots.
|
|
34
|
+
*
|
|
35
|
+
* - `"user-per-thread"` — Uses `${channelId}:${threadTs}:${userId}` for
|
|
36
|
+
* threaded/channel messages and `${channelId}:${userId}` in DMs.
|
|
37
|
+
*
|
|
38
|
+
* - `"custom"` — Provide your own mapping via `resolveSessionId`.
|
|
39
|
+
*/
|
|
40
|
+
type SlackSessionStrategy = "thread-aware" | "channel-id" | "user-per-channel" | "user-per-thread" | "custom";
|
|
41
|
+
/**
|
|
42
|
+
* Controls how the bot posts responses to Slack.
|
|
43
|
+
*
|
|
44
|
+
* - `"progressive"` *(default)* — Posts a placeholder message immediately,
|
|
45
|
+
* then updates it as the agent emits text. Gives a typing-like experience.
|
|
46
|
+
* Uses `chat.update` for mid-stream updates.
|
|
47
|
+
*
|
|
48
|
+
* - `"accumulate"` — Waits for the full response before posting. Simpler,
|
|
49
|
+
* uses one API call, but the user sees nothing until the agent finishes.
|
|
50
|
+
*
|
|
51
|
+
* - `"chat-stream"` — Uses Slack's native `chat.startStream`,
|
|
52
|
+
* `chat.appendStream`, and `chat.stopStream` APIs through
|
|
53
|
+
* `WebClient.chatStream`. This is the Slack-native streaming path.
|
|
54
|
+
*/
|
|
55
|
+
type SlackStreamingMode = "progressive" | "accumulate" | "chat-stream";
|
|
56
|
+
/**
|
|
57
|
+
* Configuration for the Slack channel adapter.
|
|
58
|
+
*/
|
|
59
|
+
interface SlackChannelOptions {
|
|
60
|
+
/**
|
|
61
|
+
* Generic chat turn source understood by this package.
|
|
62
|
+
*/
|
|
63
|
+
source: SlackTurnSource;
|
|
64
|
+
/**
|
|
65
|
+
* How to map Slack conversations to runtime session IDs.
|
|
66
|
+
* @default "thread-aware"
|
|
67
|
+
*/
|
|
68
|
+
sessionStrategy?: SlackSessionStrategy;
|
|
69
|
+
/**
|
|
70
|
+
* Custom session ID resolver. Required when `sessionStrategy` is `"custom"`.
|
|
71
|
+
*/
|
|
72
|
+
resolveSessionId?: (info: SlackActivityInfo) => string | Promise<string>;
|
|
73
|
+
/**
|
|
74
|
+
* Optional full-request session resolver. Returning `undefined` falls back
|
|
75
|
+
* to `sessionStrategy` / `resolveSessionId`.
|
|
76
|
+
*
|
|
77
|
+
* Prefer this over `resolveSessionId` when session routing needs auth,
|
|
78
|
+
* prepared text, or other request metadata.
|
|
79
|
+
*/
|
|
80
|
+
resolveSession?: (request: SlackTurnRequestContext) => string | undefined | Promise<string | undefined>;
|
|
81
|
+
/**
|
|
82
|
+
* Surface reasoning events as status updates in Slack.
|
|
83
|
+
* @default false
|
|
84
|
+
*/
|
|
85
|
+
showReasoning?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Surface tool usage as status updates (e.g. "Using tool: search...").
|
|
88
|
+
* This controls root-agent tool rows. Subagent child tool rows are controlled
|
|
89
|
+
* separately by `showSubagentToolUsage`.
|
|
90
|
+
* @default true
|
|
91
|
+
*/
|
|
92
|
+
showToolUsage?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Surface subagent child tool activity as Slack task rows. Disabled by
|
|
95
|
+
* default so delegated workers do not flood the parent turn timeline.
|
|
96
|
+
* Subagent start/complete/error lifecycle rows still render when
|
|
97
|
+
* `showToolUsage` is enabled.
|
|
98
|
+
* @default false
|
|
99
|
+
*/
|
|
100
|
+
showSubagentToolUsage?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Include the completed subagent output body in the subagent task row.
|
|
103
|
+
* Disabled by default because full child results should flow through
|
|
104
|
+
* `get_agent_results` and the root final answer, not the task timeline.
|
|
105
|
+
* @default false
|
|
106
|
+
*/
|
|
107
|
+
showSubagentResultInTask?: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Format the tool-start status text.
|
|
110
|
+
* @default (toolName) => `🔍 Using tool: ${toolName}...`
|
|
111
|
+
*/
|
|
112
|
+
formatToolUpdate?: (toolName: string) => string;
|
|
113
|
+
/**
|
|
114
|
+
* Format the title shown in Slack task cards for tool activity.
|
|
115
|
+
* @default (toolName) => toolName
|
|
116
|
+
*/
|
|
117
|
+
formatToolTitle?: (toolName: string) => string;
|
|
118
|
+
/**
|
|
119
|
+
* Format task-card details for a tool-start event. Use this to show safe,
|
|
120
|
+
* redacted tool arguments in Slack's task UI.
|
|
121
|
+
* @default details use the tool-start status text
|
|
122
|
+
*/
|
|
123
|
+
formatToolDetails?: (event: SlackToolStartEvent) => string | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* Format completed tool output shown in Slack task cards.
|
|
126
|
+
*
|
|
127
|
+
* Return `undefined` to use the default generic formatter. Return `null` to
|
|
128
|
+
* intentionally omit output for this result.
|
|
129
|
+
*/
|
|
130
|
+
formatToolResultOutput?: (event: SlackToolResultEvent) => string | null | undefined;
|
|
131
|
+
/**
|
|
132
|
+
* Format the tool-error status text.
|
|
133
|
+
* @default (toolName) => `⚠️ Tool ${toolName} encountered an error`
|
|
134
|
+
*/
|
|
135
|
+
formatToolError?: (toolName: string, error: string) => string;
|
|
136
|
+
/**
|
|
137
|
+
* Format the reasoning status text.
|
|
138
|
+
* @default () => "Thinking..."
|
|
139
|
+
*/
|
|
140
|
+
formatReasoningUpdate?: () => string;
|
|
141
|
+
/**
|
|
142
|
+
* Initial Slack thread status set before `prepareTurn` and `source.chat()`
|
|
143
|
+
* run, when Bolt provides `setStatus` for the classic message/app_mention
|
|
144
|
+
* listener. Use an object with `loading_messages` to enable Slack's rotating
|
|
145
|
+
* loading text.
|
|
146
|
+
*
|
|
147
|
+
* Return `undefined` from a function resolver to skip the initial status for
|
|
148
|
+
* a specific turn.
|
|
149
|
+
*
|
|
150
|
+
* @default { status: "Thinking..." }
|
|
151
|
+
*/
|
|
152
|
+
initialStatus?: SlackAssistantStatusUpdate | ((request: SlackTurnRequestContext) => MaybePromise<SlackAssistantStatusUpdate | undefined>);
|
|
153
|
+
/**
|
|
154
|
+
* How to handle approval / human-input requests that Slack cannot satisfy
|
|
155
|
+
* in-channel. When `handleInteractiveRequest` is configured, the handler is
|
|
156
|
+
* tried first; this fallback is only used when the handler declines.
|
|
157
|
+
* @default "message-and-error"
|
|
158
|
+
*/
|
|
159
|
+
interactiveMode?: "message-and-error" | "ignore";
|
|
160
|
+
/**
|
|
161
|
+
* Slack-native renderer/resolver hook for approval and human-input requests.
|
|
162
|
+
*
|
|
163
|
+
* The adapter provides the current Slack activity, resolved session, user,
|
|
164
|
+
* and a responder that can post/update Block Kit messages in the originating
|
|
165
|
+
* thread. Return `true` after rendering/recording the request to keep the
|
|
166
|
+
* Slack turn alive while the request is resolved out-of-band.
|
|
167
|
+
*/
|
|
168
|
+
handleInteractiveRequest?: SlackInteractiveRequestHandler;
|
|
169
|
+
/**
|
|
170
|
+
* Format the fallback message shown when tool approval is required.
|
|
171
|
+
*/
|
|
172
|
+
formatApprovalRequired?: (request: Extract<SlackTurnEvent, {
|
|
173
|
+
type: "approval-request";
|
|
174
|
+
}>["request"]) => string;
|
|
175
|
+
/**
|
|
176
|
+
* Format the fallback message shown when human input is required.
|
|
177
|
+
*/
|
|
178
|
+
formatHumanInputRequired?: (request: HumanInputEvent) => string;
|
|
179
|
+
/**
|
|
180
|
+
* How the bot posts responses.
|
|
181
|
+
* @default "progressive"
|
|
182
|
+
*/
|
|
183
|
+
streamingMode?: SlackStreamingMode;
|
|
184
|
+
/**
|
|
185
|
+
* Minimum number of accumulated characters before issuing a `chat.update`
|
|
186
|
+
* in progressive mode.
|
|
187
|
+
* @default 150
|
|
188
|
+
*/
|
|
189
|
+
progressiveUpdateThreshold?: number;
|
|
190
|
+
/**
|
|
191
|
+
* Minimum time between `chat.update` calls in progressive mode.
|
|
192
|
+
*
|
|
193
|
+
* Slack recommends waiting at least 3 seconds between updates to longer
|
|
194
|
+
* messages. Set to `0` to disable time throttling.
|
|
195
|
+
*
|
|
196
|
+
* @default 3000
|
|
197
|
+
*/
|
|
198
|
+
progressiveUpdateIntervalMs?: number;
|
|
199
|
+
/**
|
|
200
|
+
* Buffer size passed to Slack's `WebClient.chatStream` helper when
|
|
201
|
+
* `streamingMode` is `"chat-stream"`.
|
|
202
|
+
* @default 256
|
|
203
|
+
*/
|
|
204
|
+
chatStreamBufferSize?: number;
|
|
205
|
+
/**
|
|
206
|
+
* Maximum number of Slack task-update chunks the bridge will append to a
|
|
207
|
+
* single chat stream. Task rows are a bounded UI projection, not a durable
|
|
208
|
+
* event log.
|
|
209
|
+
*
|
|
210
|
+
* @default 200
|
|
211
|
+
*/
|
|
212
|
+
maxTaskUpdates?: number;
|
|
213
|
+
/**
|
|
214
|
+
* Maximum cumulative characters from task titles/details/output that the
|
|
215
|
+
* bridge will append to one chat stream.
|
|
216
|
+
*
|
|
217
|
+
* @default 20000
|
|
218
|
+
*/
|
|
219
|
+
maxTaskUpdateTextChars?: number;
|
|
220
|
+
/**
|
|
221
|
+
* Maximum characters for a single task details/output field.
|
|
222
|
+
*
|
|
223
|
+
* @default 500
|
|
224
|
+
*/
|
|
225
|
+
maxTaskUpdateFieldChars?: number;
|
|
226
|
+
/**
|
|
227
|
+
* Start arguments merged into Slack's native chat stream when
|
|
228
|
+
* `streamingMode` is `"chat-stream"`; useful for Slack-supported authorship
|
|
229
|
+
* fields such as `icon_emoji`, `icon_url`, and `username`.
|
|
230
|
+
*
|
|
231
|
+
* The adapter still owns `channel`, `thread_ts`, recipient ids, and
|
|
232
|
+
* `buffer_size`.
|
|
233
|
+
*/
|
|
234
|
+
chatStreamStartArgs?: SlackChatStreamStartArgs;
|
|
235
|
+
/**
|
|
236
|
+
* Final arguments merged into `chatStream.stop(...)` when
|
|
237
|
+
* `streamingMode` is `"chat-stream"`; useful for final blocks such as a
|
|
238
|
+
* feedback widget.
|
|
239
|
+
*/
|
|
240
|
+
chatStreamFinalArgs?: {
|
|
241
|
+
blocks?: unknown[];
|
|
242
|
+
} & Record<string, unknown>;
|
|
243
|
+
/**
|
|
244
|
+
* Optional publisher for rich artifacts derived from the final accumulated
|
|
245
|
+
* answer, such as creating a Slack Canvas for long responses.
|
|
246
|
+
*/
|
|
247
|
+
publishFinalResponseArtifact?: SlackEventBridgeOptions["publishFinalResponseArtifact"];
|
|
248
|
+
/**
|
|
249
|
+
* Controls whether final-response artifacts are supplemental or replace long
|
|
250
|
+
* Slack text with a compact artifact pointer.
|
|
251
|
+
*
|
|
252
|
+
* @default "supplemental"
|
|
253
|
+
*/
|
|
254
|
+
finalResponseArtifactMode?: SlackEventBridgeOptions["finalResponseArtifactMode"];
|
|
255
|
+
/**
|
|
256
|
+
* Raw-character threshold for replacement-mode streaming suppression.
|
|
257
|
+
*
|
|
258
|
+
* @default 4000
|
|
259
|
+
*/
|
|
260
|
+
finalResponseArtifactStreamThreshold?: SlackEventBridgeOptions["finalResponseArtifactStreamThreshold"];
|
|
261
|
+
/** Notice emitted when replacement mode moves the remaining response to an artifact. */
|
|
262
|
+
formatFinalResponseArtifactContinuationNotice?: SlackEventBridgeOptions["formatFinalResponseArtifactContinuationNotice"];
|
|
263
|
+
/** Compact final Slack message emitted after artifact publication succeeds. */
|
|
264
|
+
formatFinalResponseArtifactMessage?: SlackEventBridgeOptions["formatFinalResponseArtifactMessage"];
|
|
265
|
+
/** Diagnostics hook for final-response artifact publishing failures. */
|
|
266
|
+
onFinalResponseArtifactError?: SlackEventBridgeOptions["onFinalResponseArtifactError"];
|
|
267
|
+
/**
|
|
268
|
+
* Convert common markdown constructs emitted by models into Slack mrkdwn.
|
|
269
|
+
*
|
|
270
|
+
* @default true
|
|
271
|
+
*/
|
|
272
|
+
formatChatMarkdown?: boolean;
|
|
273
|
+
/**
|
|
274
|
+
* Custom response text formatter. When provided, this takes precedence over
|
|
275
|
+
* the built-in markdown-to-mrkdwn conversion.
|
|
276
|
+
*/
|
|
277
|
+
formatMessageText?: (text: string) => string;
|
|
278
|
+
/**
|
|
279
|
+
* Maximum time (ms) to wait for the agent before aborting.
|
|
280
|
+
* @default 120_000
|
|
281
|
+
*/
|
|
282
|
+
timeout?: number;
|
|
283
|
+
/**
|
|
284
|
+
* When `true` (default), replies to channel messages are posted inside the
|
|
285
|
+
* originating thread. When `false`, replies are posted at channel level.
|
|
286
|
+
* Has no effect in DMs.
|
|
287
|
+
* @default true
|
|
288
|
+
*/
|
|
289
|
+
respondInThread?: boolean;
|
|
290
|
+
/**
|
|
291
|
+
* Welcome message sent when the bot is added to a channel or DM.
|
|
292
|
+
* Set to `null` to disable.
|
|
293
|
+
*/
|
|
294
|
+
welcomeMessage?: string | null;
|
|
295
|
+
/**
|
|
296
|
+
* When `true` (default), `app.event('app_mention')` is registered so the
|
|
297
|
+
* bot responds to `@mentions` in channels.
|
|
298
|
+
* @default true
|
|
299
|
+
*/
|
|
300
|
+
respondToMentions?: boolean;
|
|
301
|
+
/**
|
|
302
|
+
* When `true` (default), `app.message()` is registered so the bot
|
|
303
|
+
* can respond to direct messages and, when enabled, plain channel messages.
|
|
304
|
+
*
|
|
305
|
+
* Set to `false` if you only want @mention-triggered responses.
|
|
306
|
+
* @default true
|
|
307
|
+
*/
|
|
308
|
+
respondToMessages?: boolean;
|
|
309
|
+
/**
|
|
310
|
+
* When `true`, plain channel/group/thread messages from `app.message()` are
|
|
311
|
+
* forwarded into the agent. Direct messages still work through
|
|
312
|
+
* `respondToMessages`.
|
|
313
|
+
*
|
|
314
|
+
* Keep this disabled unless your Slack app intentionally listens to every
|
|
315
|
+
* visible channel message. @mentions are handled separately by
|
|
316
|
+
* `respondToMentions`.
|
|
317
|
+
* @default false
|
|
318
|
+
*/
|
|
319
|
+
respondToChannelMessages?: boolean;
|
|
320
|
+
/**
|
|
321
|
+
* Resolve additional context to inject into the agent call.
|
|
322
|
+
*
|
|
323
|
+
* Use this to customize the system prompt per user, inject Slack identity,
|
|
324
|
+
* etc. Called before `source.chat()` on every message.
|
|
325
|
+
*/
|
|
326
|
+
resolveUserContext?: (user: SlackUserIdentity) => {
|
|
327
|
+
system?: string;
|
|
328
|
+
} | Promise<{
|
|
329
|
+
system?: string;
|
|
330
|
+
}>;
|
|
331
|
+
/**
|
|
332
|
+
* Prepare an Slack turn from the full Slack request context.
|
|
333
|
+
*
|
|
334
|
+
* Prefer this over `resolveUserContext` when you need structured ambient
|
|
335
|
+
* context for tools/middleware or custom scope attributes.
|
|
336
|
+
*/
|
|
337
|
+
prepareTurn?: (request: SlackTurnRequestContext) => SlackTurnPreparation | Promise<SlackTurnPreparation>;
|
|
338
|
+
/**
|
|
339
|
+
* Resolve the text message forwarded to `source.chat()`.
|
|
340
|
+
*
|
|
341
|
+
* Useful when the message text needs normalisation beyond mention-stripping.
|
|
342
|
+
* Return `undefined` to skip processing this message.
|
|
343
|
+
*/
|
|
344
|
+
resolveMessage?: (info: SlackActivityInfo) => string | undefined | Promise<string | undefined>;
|
|
345
|
+
/**
|
|
346
|
+
* Called on unhandled errors during turn processing.
|
|
347
|
+
*/
|
|
348
|
+
onError?: (error: Error, info: SlackActivityInfo) => void | Promise<void>;
|
|
349
|
+
/**
|
|
350
|
+
* Optional diagnostics logger. Used for best-effort status/update failures
|
|
351
|
+
* and classic turn utility visibility.
|
|
352
|
+
*/
|
|
353
|
+
logger?: Logger;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Slack channel adapter returned by `createSlackChannelAdapter`.
|
|
357
|
+
*/
|
|
358
|
+
interface SlackChannelAdapter {
|
|
359
|
+
/**
|
|
360
|
+
* Register all message/event handlers on a Bolt `App`.
|
|
361
|
+
*
|
|
362
|
+
* ```ts
|
|
363
|
+
* const adapter = createSlackChannelAdapter({ source });
|
|
364
|
+
* adapter.mount(boltApp);
|
|
365
|
+
* ```
|
|
366
|
+
*/
|
|
367
|
+
mount(app: {
|
|
368
|
+
message: (...args: any[]) => unknown;
|
|
369
|
+
event: (...args: any[]) => unknown;
|
|
370
|
+
}): void;
|
|
371
|
+
/** Resolve or look up the session ID for a given Slack activity. */
|
|
372
|
+
getSessionId(info: SlackActivityInfo): string | Promise<string>;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export type { SlackChannelAdapter as S, SlackChannelOptions as a, SlackSessionStrategy as b, SlackStreamingMode as c, SlackToolStartEvent as d };
|
|
@@ -5,12 +5,16 @@ keep application code close to the package boundary it uses.
|
|
|
5
5
|
|
|
6
6
|
| Export | Depends on | Notes |
|
|
7
7
|
| ------------------------------------------ | ------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
|
|
8
|
+
| `@cuylabs/channel-slack/app` | `@slack/bolt`, `express` | Runtime-neutral HTTP Events API mount for Slack surfaces |
|
|
9
|
+
| `@cuylabs/channel-slack/app-surface` | `@slack/bolt`, `@slack/web-api` types | Runtime-neutral Assistant, mention, DM, feedback, and interactive mount |
|
|
10
|
+
| `@cuylabs/channel-slack/socket` | `@slack/bolt` | Runtime-neutral Socket Mode mount for Slack surfaces |
|
|
11
|
+
| `@cuylabs/channel-slack/adapter` | `@slack/bolt`, `@slack/web-api` types | Runtime-neutral classic app mention, DM, and channel-message adapter |
|
|
8
12
|
| `@cuylabs/channel-slack/core` | no Slack SDK runtime imports | Transport-neutral parsing, formatting, types, sessions, turn context |
|
|
9
13
|
| `@cuylabs/channel-slack/policy` | `pg` only when using connection-string Postgres state | Message admission and in-memory/Postgres policy state |
|
|
10
14
|
| `@cuylabs/channel-slack/history` | `@slack/web-api` types | History reader accepts a Slack WebClient or minimal conversations client |
|
|
11
15
|
| `@cuylabs/channel-slack/interactive` | `@slack/types`; `pg` only when using connection-string Postgres storage | Slack interactive Block Kit/modal builders and request stores |
|
|
12
16
|
| `@cuylabs/channel-slack/app-home` | `@slack/bolt`, `@slack/types` | Slack App Home registration helper |
|
|
13
|
-
| `@cuylabs/channel-slack/artifacts` | no Slack SDK runtime imports; requires a Web API-like client at call time | Text, file, image, link, and
|
|
17
|
+
| `@cuylabs/channel-slack/artifacts` | no Slack SDK runtime imports; requires a Web API-like client at call time | Text, file, image, link, Canvas, and final-response artifact publishing |
|
|
14
18
|
| `@cuylabs/channel-slack/auth` | no Slack SDK runtime imports; `pg` is not required | Auth option types, auth resolution, OAuth installation stores |
|
|
15
19
|
| `@cuylabs/channel-slack/responses` | no Slack SDK runtime imports | Slack response sink and chat stream contracts for runtime adapters |
|
|
16
20
|
| `@cuylabs/channel-slack/transports` | `@slack/bolt`, `express`; `pg` only when using connection-string Postgres locks | HTTP and Socket Mode transport helpers |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cuylabs/channel-slack",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Agent-runtime-agnostic Slack channel primitives for AI agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,6 +21,21 @@
|
|
|
21
21
|
"import": "./dist/app-home.js",
|
|
22
22
|
"default": "./dist/app-home.js"
|
|
23
23
|
},
|
|
24
|
+
"./adapter": {
|
|
25
|
+
"types": "./dist/adapter/index.d.ts",
|
|
26
|
+
"import": "./dist/adapter/index.js",
|
|
27
|
+
"default": "./dist/adapter/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./app": {
|
|
30
|
+
"types": "./dist/app.d.ts",
|
|
31
|
+
"import": "./dist/app.js",
|
|
32
|
+
"default": "./dist/app.js"
|
|
33
|
+
},
|
|
34
|
+
"./app-surface": {
|
|
35
|
+
"types": "./dist/app-surface.d.ts",
|
|
36
|
+
"import": "./dist/app-surface.js",
|
|
37
|
+
"default": "./dist/app-surface.js"
|
|
38
|
+
},
|
|
24
39
|
"./artifacts": {
|
|
25
40
|
"types": "./dist/artifacts/index.d.ts",
|
|
26
41
|
"import": "./dist/artifacts/index.js",
|
|
@@ -81,6 +96,11 @@
|
|
|
81
96
|
"import": "./dist/setup/index.js",
|
|
82
97
|
"default": "./dist/setup/index.js"
|
|
83
98
|
},
|
|
99
|
+
"./socket": {
|
|
100
|
+
"types": "./dist/socket.d.ts",
|
|
101
|
+
"import": "./dist/socket.js",
|
|
102
|
+
"default": "./dist/socket.js"
|
|
103
|
+
},
|
|
84
104
|
"./targets": {
|
|
85
105
|
"types": "./dist/targets/index.d.ts",
|
|
86
106
|
"import": "./dist/targets/index.js",
|
|
@@ -168,9 +188,9 @@
|
|
|
168
188
|
"node": ">=20"
|
|
169
189
|
},
|
|
170
190
|
"scripts": {
|
|
171
|
-
"build": "tsup src/index.ts src/app-home.ts src/artifacts/index.ts src/core.ts src/assistant/index.ts src/auth/index.ts src/diagnostics/index.ts src/entrypoints/index.ts src/feedback/index.ts src/history/index.ts src/interactive/index.ts src/policy/index.ts src/responses/index.ts src/runtime/index.ts src/setup/index.ts src/targets/index.ts src/turn-controls/index.ts src/transports/index.ts src/transports/http/index.ts src/transports/socket/index.ts src/users/index.ts src/views/index.ts --format esm --dts --clean",
|
|
191
|
+
"build": "tsup src/index.ts src/adapter/index.ts src/app.ts src/app-home.ts src/app-surface.ts src/artifacts/index.ts src/core.ts src/assistant/index.ts src/auth/index.ts src/diagnostics/index.ts src/entrypoints/index.ts src/feedback/index.ts src/history/index.ts src/interactive/index.ts src/policy/index.ts src/responses/index.ts src/runtime/index.ts src/setup/index.ts src/socket.ts src/targets/index.ts src/turn-controls/index.ts src/transports/index.ts src/transports/http/index.ts src/transports/socket/index.ts src/users/index.ts src/views/index.ts --format esm --dts --clean",
|
|
172
192
|
"clean": "rm -rf dist",
|
|
173
|
-
"dev": "tsup src/index.ts src/app-home.ts src/artifacts/index.ts src/core.ts src/assistant/index.ts src/auth/index.ts src/diagnostics/index.ts src/entrypoints/index.ts src/feedback/index.ts src/history/index.ts src/interactive/index.ts src/policy/index.ts src/responses/index.ts src/runtime/index.ts src/setup/index.ts src/targets/index.ts src/turn-controls/index.ts src/transports/index.ts src/transports/http/index.ts src/transports/socket/index.ts src/users/index.ts src/views/index.ts --format esm --dts --watch",
|
|
193
|
+
"dev": "tsup src/index.ts src/adapter/index.ts src/app.ts src/app-home.ts src/app-surface.ts src/artifacts/index.ts src/core.ts src/assistant/index.ts src/auth/index.ts src/diagnostics/index.ts src/entrypoints/index.ts src/feedback/index.ts src/history/index.ts src/interactive/index.ts src/policy/index.ts src/responses/index.ts src/runtime/index.ts src/setup/index.ts src/socket.ts src/targets/index.ts src/turn-controls/index.ts src/transports/index.ts src/transports/http/index.ts src/transports/socket/index.ts src/users/index.ts src/views/index.ts --format esm --dts --watch",
|
|
174
194
|
"lint": "eslint \"src/**/*.{ts,tsx}\" \"tests/**/*.{ts,tsx}\" --max-warnings=0",
|
|
175
195
|
"test": "vitest run",
|
|
176
196
|
"test:watch": "vitest",
|