@cuylabs/channel-slack-agent-core 0.9.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.
Files changed (52) hide show
  1. package/README.md +13 -10
  2. package/dist/chunk-U6RC4SXN.js +331 -0
  3. package/dist/history/index.d.ts +7 -17
  4. package/dist/index.d.ts +5 -28
  5. package/dist/index.js +14 -58
  6. package/dist/interactive/index.d.ts +86 -7
  7. package/dist/shared/index.d.ts +144 -19
  8. package/dist/shared/index.js +8 -4
  9. package/docs/README.md +0 -1
  10. package/docs/concepts/final-response-artifacts.md +9 -7
  11. package/docs/concepts/tool-task-rendering.md +2 -0
  12. package/docs/reference/exports.md +10 -20
  13. package/package.json +4 -54
  14. package/dist/adapter/index.d.ts +0 -26
  15. package/dist/adapter/index.js +0 -9
  16. package/dist/adapter-vbqtraAr.d.ts +0 -31
  17. package/dist/app-surface.d.ts +0 -82
  18. package/dist/app-surface.js +0 -10
  19. package/dist/app.d.ts +0 -60
  20. package/dist/app.js +0 -11
  21. package/dist/artifacts/index.d.ts +0 -57
  22. package/dist/artifacts/index.js +0 -6
  23. package/dist/assistant/index.d.ts +0 -22
  24. package/dist/assistant/index.js +0 -14
  25. package/dist/chunk-A2PLAVW6.js +0 -75
  26. package/dist/chunk-C7CHMYV6.js +0 -226
  27. package/dist/chunk-D4CSEAIF.js +0 -82
  28. package/dist/chunk-ELR6MQD7.js +0 -12
  29. package/dist/chunk-FJP6ZFUB.js +0 -921
  30. package/dist/chunk-GKZRDNEB.js +0 -187
  31. package/dist/chunk-HHXAXSG6.js +0 -67
  32. package/dist/chunk-JU5R6JZG.js +0 -85
  33. package/dist/chunk-KAEZPS3U.js +0 -77
  34. package/dist/chunk-NNCVHQC4.js +0 -94
  35. package/dist/chunk-VBGQD6JT.js +0 -1008
  36. package/dist/chunk-XA7U3GRN.js +0 -482
  37. package/dist/express-assistant.d.ts +0 -106
  38. package/dist/express-assistant.js +0 -9
  39. package/dist/express.d.ts +0 -103
  40. package/dist/express.js +0 -8
  41. package/dist/feedback/index.d.ts +0 -1
  42. package/dist/feedback/index.js +0 -10
  43. package/dist/options-ByNm2o89.d.ts +0 -323
  44. package/dist/options-CGUfVStV.d.ts +0 -119
  45. package/dist/socket.d.ts +0 -143
  46. package/dist/socket.js +0 -13
  47. package/dist/types-BeGPexio.d.ts +0 -381
  48. package/dist/types-Bz4OYEAV.d.ts +0 -87
  49. package/dist/types-CiwGU6zC.d.ts +0 -56
  50. package/dist/views/index.d.ts +0 -8
  51. package/dist/views/index.js +0 -10
  52. package/docs/concepts/view-workflows.md +0 -52
@@ -1,381 +0,0 @@
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 { S as SlackEventBridgeOptions } from './options-CGUfVStV.js';
4
- import { f as SlackInteractiveRequestHandler } from './interactive-BigrPKnu.js';
5
-
6
- /**
7
- * Channel-options + adapter contract for the direct Slack adapter
8
- * (`createSlackChannelAdapter`).
9
- */
10
-
11
- type HumanInputEvent = Extract<AgentEvent, {
12
- type: "human-input-request";
13
- }>["request"];
14
- type SlackToolStartEvent = Extract<AgentEvent, {
15
- type: "tool-start";
16
- }>;
17
- type SlackToolResultEvent = Extract<AgentEvent, {
18
- type: "tool-result";
19
- }>;
20
- type MaybePromise<T> = T | Promise<T>;
21
- /**
22
- * Session mapping strategy.
23
- *
24
- * - `"thread-aware"` *(default)* — Uses the Slack thread_ts as session ID
25
- * when the message is inside a thread; falls back to the channel ID for
26
- * DMs and top-level channel messages. Produces the most natural grouping.
27
- *
28
- * - `"channel-id"` — Uses the Slack channel / DM ID directly. Every
29
- * message in the same channel/DM shares one session.
30
- *
31
- * - `"user-per-channel"` — Uses `${channelId}:${userId}`. Each user gets
32
- * an isolated session per channel/DM. Useful for private-context bots.
33
- *
34
- * - `"user-per-thread"` — Uses `${channelId}:${threadTs}:${userId}` for
35
- * threaded/channel messages and `${channelId}:${userId}` in DMs.
36
- *
37
- * - `"custom"` — Provide your own mapping via `resolveSessionId`.
38
- */
39
- type SlackSessionStrategy = "thread-aware" | "channel-id" | "user-per-channel" | "user-per-thread" | "custom";
40
- /**
41
- * Controls how the bot posts responses to Slack.
42
- *
43
- * - `"progressive"` *(default)* — Posts a placeholder message immediately,
44
- * then updates it as the agent emits text. Gives a typing-like experience.
45
- * Uses `chat.update` for mid-stream updates.
46
- *
47
- * - `"accumulate"` — Waits for the full response before posting. Simpler,
48
- * uses one API call, but the user sees nothing until the agent finishes.
49
- *
50
- * - `"chat-stream"` — Uses Slack's native `chat.startStream`,
51
- * `chat.appendStream`, and `chat.stopStream` APIs through
52
- * `WebClient.chatStream`. This is the Slack-native streaming path.
53
- */
54
- type SlackStreamingMode = "progressive" | "accumulate" | "chat-stream";
55
- /**
56
- * Configuration for the Slack channel adapter.
57
- */
58
- interface SlackChannelOptions {
59
- /**
60
- * The agent-core Agent instance to bridge.
61
- *
62
- * Use `source` instead when you want to bridge a runtime/server-backed chat
63
- * adapter that is not a direct `Agent` instance.
64
- */
65
- agent?: Agent;
66
- /**
67
- * Generic chat turn source understood by this package.
68
- *
69
- * Exactly one of `agent` or `source` must be provided.
70
- */
71
- source?: AgentTurnSource;
72
- /**
73
- * How to map Slack conversations to agent-core session IDs.
74
- * @default "thread-aware"
75
- */
76
- sessionStrategy?: SlackSessionStrategy;
77
- /**
78
- * Custom session ID resolver. Required when `sessionStrategy` is `"custom"`.
79
- */
80
- resolveSessionId?: (info: SlackActivityInfo) => string | Promise<string>;
81
- /**
82
- * Optional full-request session resolver. Returning `undefined` falls back
83
- * to `sessionStrategy` / `resolveSessionId`.
84
- *
85
- * Prefer this over `resolveSessionId` when session routing needs auth,
86
- * prepared text, or other request metadata.
87
- */
88
- resolveSession?: (request: SlackTurnRequestContext) => string | undefined | Promise<string | undefined>;
89
- /**
90
- * Surface reasoning events as status updates in Slack.
91
- * @default false
92
- */
93
- showReasoning?: boolean;
94
- /**
95
- * Surface tool usage as status updates (e.g. "Using tool: search...").
96
- * This controls root-agent tool rows. Subagent child tool rows are controlled
97
- * separately by `showSubagentToolUsage`.
98
- * @default true
99
- */
100
- showToolUsage?: boolean;
101
- /**
102
- * Surface subagent child tool activity as Slack task rows. Disabled by
103
- * default so delegated workers do not flood the parent turn timeline.
104
- * Subagent start/complete/error lifecycle rows still render when
105
- * `showToolUsage` is enabled.
106
- * @default false
107
- */
108
- showSubagentToolUsage?: boolean;
109
- /**
110
- * Include the completed subagent output body in the subagent task row.
111
- * Disabled by default because full child results should flow through
112
- * `get_agent_results` and the root final answer, not the task timeline.
113
- * @default false
114
- */
115
- showSubagentResultInTask?: boolean;
116
- /**
117
- * Format the tool-start status text.
118
- * @default (toolName) => `🔍 Using tool: ${toolName}...`
119
- */
120
- formatToolUpdate?: (toolName: string) => string;
121
- /**
122
- * Format the title shown in Slack task cards for tool activity.
123
- * @default (toolName) => toolName
124
- */
125
- formatToolTitle?: (toolName: string) => string;
126
- /**
127
- * Format task-card details for a tool-start event. Use this to show safe,
128
- * redacted tool arguments in Slack's task UI.
129
- * @default details use the tool-start status text
130
- */
131
- formatToolDetails?: (event: SlackToolStartEvent) => string | undefined;
132
- /**
133
- * Format completed tool output shown in Slack task cards.
134
- *
135
- * Return `undefined` to use the default generic formatter. Return `null` to
136
- * intentionally omit output for this result.
137
- */
138
- formatToolResultOutput?: (event: SlackToolResultEvent) => string | null | undefined;
139
- /**
140
- * Format the tool-error status text.
141
- * @default (toolName) => `⚠️ Tool ${toolName} encountered an error`
142
- */
143
- formatToolError?: (toolName: string, error: string) => string;
144
- /**
145
- * Format the reasoning status text.
146
- * @default () => "Thinking..."
147
- */
148
- formatReasoningUpdate?: () => string;
149
- /**
150
- * Initial Slack thread status set before `prepareTurn` and `source.chat()`
151
- * run, when Bolt provides `setStatus` for the classic message/app_mention
152
- * listener. Use an object with `loading_messages` to enable Slack's rotating
153
- * loading text.
154
- *
155
- * Return `undefined` from a function resolver to skip the initial status for
156
- * a specific turn.
157
- *
158
- * @default { status: "Thinking..." }
159
- */
160
- initialStatus?: SlackAssistantStatusUpdate | ((request: SlackTurnRequestContext) => MaybePromise<SlackAssistantStatusUpdate | undefined>);
161
- /**
162
- * How to handle approval / human-input requests that Slack cannot satisfy
163
- * in-channel. When `handleInteractiveRequest` is configured, the handler is
164
- * tried first; this fallback is only used when the handler declines.
165
- * @default "message-and-error"
166
- */
167
- interactiveMode?: "message-and-error" | "ignore";
168
- /**
169
- * Slack-native renderer/resolver hook for approval and human-input requests.
170
- *
171
- * The adapter provides the current Slack activity, resolved session, user,
172
- * and a responder that can post/update Block Kit messages in the originating
173
- * thread. Return `true` after rendering/recording the request to keep the
174
- * agent turn alive while the request is resolved out-of-band.
175
- */
176
- handleInteractiveRequest?: SlackInteractiveRequestHandler;
177
- /**
178
- * Format the fallback message shown when tool approval is required.
179
- */
180
- formatApprovalRequired?: (request: ApprovalEvent) => string;
181
- /**
182
- * Format the fallback message shown when human input is required.
183
- */
184
- formatHumanInputRequired?: (request: HumanInputEvent) => string;
185
- /**
186
- * How the bot posts responses.
187
- * @default "progressive"
188
- */
189
- streamingMode?: SlackStreamingMode;
190
- /**
191
- * Minimum number of accumulated characters before issuing a `chat.update`
192
- * in progressive mode.
193
- * @default 150
194
- */
195
- progressiveUpdateThreshold?: number;
196
- /**
197
- * Minimum time between `chat.update` calls in progressive mode.
198
- *
199
- * Slack recommends waiting at least 3 seconds between updates to longer
200
- * messages. Set to `0` to disable time throttling.
201
- *
202
- * @default 3000
203
- */
204
- progressiveUpdateIntervalMs?: number;
205
- /**
206
- * Buffer size passed to Slack's `WebClient.chatStream` helper when
207
- * `streamingMode` is `"chat-stream"`.
208
- * @default 256
209
- */
210
- chatStreamBufferSize?: number;
211
- /**
212
- * Maximum number of Slack task-update chunks the bridge will append to a
213
- * single chat stream. Task rows are a bounded UI projection, not a durable
214
- * event log.
215
- *
216
- * @default 200
217
- */
218
- maxTaskUpdates?: number;
219
- /**
220
- * Maximum cumulative characters from task titles/details/output that the
221
- * bridge will append to one chat stream.
222
- *
223
- * @default 20000
224
- */
225
- maxTaskUpdateTextChars?: number;
226
- /**
227
- * Maximum characters for a single task details/output field.
228
- *
229
- * @default 500
230
- */
231
- maxTaskUpdateFieldChars?: number;
232
- /**
233
- * Start arguments merged into Slack's native chat stream when
234
- * `streamingMode` is `"chat-stream"`; useful for Slack-supported authorship
235
- * fields such as `icon_emoji`, `icon_url`, and `username`.
236
- *
237
- * The adapter still owns `channel`, `thread_ts`, recipient ids, and
238
- * `buffer_size`.
239
- */
240
- chatStreamStartArgs?: SlackChatStreamStartArgs;
241
- /**
242
- * Final arguments merged into `chatStream.stop(...)` when
243
- * `streamingMode` is `"chat-stream"`; useful for final blocks such as a
244
- * feedback widget.
245
- */
246
- chatStreamFinalArgs?: {
247
- blocks?: unknown[];
248
- } & Record<string, unknown>;
249
- /**
250
- * Optional publisher for rich artifacts derived from the final accumulated
251
- * answer, such as creating a Slack Canvas for long responses.
252
- */
253
- publishFinalResponseArtifact?: SlackEventBridgeOptions["publishFinalResponseArtifact"];
254
- /**
255
- * Controls whether final-response artifacts are supplemental or replace long
256
- * Slack text with a compact artifact pointer.
257
- *
258
- * @default "supplemental"
259
- */
260
- finalResponseArtifactMode?: SlackEventBridgeOptions["finalResponseArtifactMode"];
261
- /**
262
- * Raw-character threshold for replacement-mode streaming suppression.
263
- *
264
- * @default 4000
265
- */
266
- finalResponseArtifactStreamThreshold?: SlackEventBridgeOptions["finalResponseArtifactStreamThreshold"];
267
- /** Notice emitted when replacement mode moves the remaining response to an artifact. */
268
- formatFinalResponseArtifactContinuationNotice?: SlackEventBridgeOptions["formatFinalResponseArtifactContinuationNotice"];
269
- /** Compact final Slack message emitted after artifact publication succeeds. */
270
- formatFinalResponseArtifactMessage?: SlackEventBridgeOptions["formatFinalResponseArtifactMessage"];
271
- /** Diagnostics hook for final-response artifact publishing failures. */
272
- onFinalResponseArtifactError?: SlackEventBridgeOptions["onFinalResponseArtifactError"];
273
- /**
274
- * Convert common markdown constructs emitted by models into Slack mrkdwn.
275
- *
276
- * @default true
277
- */
278
- formatChatMarkdown?: boolean;
279
- /**
280
- * Custom response text formatter. When provided, this takes precedence over
281
- * the built-in markdown-to-mrkdwn conversion.
282
- */
283
- formatMessageText?: (text: string) => string;
284
- /**
285
- * Maximum time (ms) to wait for the agent before aborting.
286
- * @default 120_000
287
- */
288
- timeout?: number;
289
- /**
290
- * When `true` (default), replies to channel messages are posted inside the
291
- * originating thread. When `false`, replies are posted at channel level.
292
- * Has no effect in DMs.
293
- * @default true
294
- */
295
- respondInThread?: boolean;
296
- /**
297
- * Welcome message sent when the bot is added to a channel or DM.
298
- * Set to `null` to disable.
299
- */
300
- welcomeMessage?: string | null;
301
- /**
302
- * When `true` (default), `app.event('app_mention')` is registered so the
303
- * bot responds to `@mentions` in channels.
304
- * @default true
305
- */
306
- respondToMentions?: boolean;
307
- /**
308
- * When `true` (default), `app.message()` is registered so the bot
309
- * can respond to direct messages and, when enabled, plain channel messages.
310
- *
311
- * Set to `false` if you only want @mention-triggered responses.
312
- * @default true
313
- */
314
- respondToMessages?: boolean;
315
- /**
316
- * When `true`, plain channel/group/thread messages from `app.message()` are
317
- * forwarded into the agent. Direct messages still work through
318
- * `respondToMessages`.
319
- *
320
- * Keep this disabled unless your Slack app intentionally listens to every
321
- * visible channel message. @mentions are handled separately by
322
- * `respondToMentions`.
323
- * @default false
324
- */
325
- respondToChannelMessages?: boolean;
326
- /**
327
- * Resolve additional context to inject into the agent call.
328
- *
329
- * Use this to customize the system prompt per user, inject Slack identity,
330
- * etc. Called before `source.chat()` on every message.
331
- */
332
- resolveUserContext?: (user: SlackUserIdentity) => {
333
- system?: string;
334
- } | Promise<{
335
- system?: string;
336
- }>;
337
- /**
338
- * Prepare an agent turn from the full Slack request context.
339
- *
340
- * Prefer this over `resolveUserContext` when you need structured ambient
341
- * context for tools/middleware or custom scope attributes.
342
- */
343
- prepareTurn?: (request: SlackTurnRequestContext) => SlackTurnPreparation | Promise<SlackTurnPreparation>;
344
- /**
345
- * Resolve the text message forwarded to `source.chat()`.
346
- *
347
- * Useful when the message text needs normalisation beyond mention-stripping.
348
- * Return `undefined` to skip processing this message.
349
- */
350
- resolveMessage?: (info: SlackActivityInfo) => string | undefined | Promise<string | undefined>;
351
- /**
352
- * Called on unhandled errors during turn processing.
353
- */
354
- onError?: (error: Error, info: SlackActivityInfo) => void | Promise<void>;
355
- /**
356
- * Optional diagnostics logger. Used for best-effort status/update failures
357
- * and classic turn utility visibility.
358
- */
359
- logger?: Logger;
360
- }
361
- /**
362
- * Slack channel adapter returned by `createSlackChannelAdapter`.
363
- */
364
- interface SlackChannelAdapter {
365
- /**
366
- * Register all message/event handlers on a Bolt `App`.
367
- *
368
- * ```ts
369
- * const adapter = createSlackChannelAdapter({ agent });
370
- * adapter.mount(boltApp);
371
- * ```
372
- */
373
- mount(app: {
374
- message: (...args: any[]) => unknown;
375
- event: (...args: any[]) => unknown;
376
- }): void;
377
- /** Resolve or look up the session ID for a given Slack activity. */
378
- getSessionId(info: SlackActivityInfo): string | Promise<string>;
379
- }
380
-
381
- export type { SlackChannelAdapter as S, SlackChannelOptions as a, SlackSessionStrategy as b, SlackStreamingMode as c, SlackToolStartEvent as d };
@@ -1,87 +0,0 @@
1
- import { ApprovalRequest, ApprovalResolution, HumanInputRequest, HumanInputResponse, ApprovalAction, ApprovalRememberScope } from '@cuylabs/agent-core';
2
- import { SlackInteractiveActionIds, SlackInteractiveRequestStore, SlackInteractiveRequestRecord, SlackInteractiveActor, SlackInteractiveHumanInputRequest as SlackInteractiveHumanInputRequest$1, SlackInteractiveMessageRef } from '@cuylabs/channel-slack/interactive';
3
- import { App } from '@slack/bolt';
4
- import { e as SlackInteractiveRequestContext } from './interactive-BigrPKnu.js';
5
-
6
- type SlackInteractiveApprovalRequest = ApprovalRequest;
7
- type SlackInteractiveHumanInputRequest = SlackInteractiveHumanInputRequest$1 & Partial<Pick<HumanInputRequest, "sessionId" | "timestamp" | "toolCallId">>;
8
- type SlackInteractiveResolution = {
9
- kind: "approval";
10
- action: ApprovalAction;
11
- feedback?: string;
12
- rememberScope?: ApprovalRememberScope;
13
- } | {
14
- kind: "human-input";
15
- response: HumanInputResponse;
16
- };
17
- interface SlackInteractiveRequestWaitOptions {
18
- /**
19
- * Abort waiting for this request. The controller removes its local waiter and
20
- * deletes the pending store record when the signal fires.
21
- */
22
- signal?: AbortSignal;
23
- /**
24
- * Override the controller-level request timeout for this request. Use `0` to
25
- * disable timeout cleanup for this request.
26
- */
27
- timeoutMs?: number;
28
- }
29
- interface SlackInteractiveControllerOptions {
30
- store?: SlackInteractiveRequestStore;
31
- /**
32
- * Stable namespace for default Slack action IDs. Use this when installing
33
- * multiple interactive controllers in the same Slack app.
34
- *
35
- * @default "agent_slack"
36
- */
37
- namespace?: string;
38
- actionIds?: Partial<SlackInteractiveActionIds>;
39
- /**
40
- * Default timeout for local waiters and pending store records. This should
41
- * usually match the agent-core approval/human-input timeout.
42
- *
43
- * @default 300000
44
- */
45
- requestTimeoutMs?: number;
46
- /**
47
- * Called on every successful Slack resolution after the local waiter, if
48
- * present, is resolved. Use this to fan out decisions to agent-server or
49
- * another runtime that owns the turn.
50
- */
51
- onResolve?: (requestId: string, resolution: SlackInteractiveResolution) => void | Promise<void>;
52
- /**
53
- * Authorization hook for approving/responding to pending requests.
54
- *
55
- * Defaults to the original Slack requester only. Return `true` for delegated
56
- * approvers, channel owners, or admin policy checks.
57
- */
58
- authorize?: (record: SlackInteractiveRequestRecord, actor: SlackInteractiveActor) => boolean | Promise<boolean>;
59
- }
60
- interface SlackInteractiveController {
61
- readonly actionIds: SlackInteractiveActionIds;
62
- readonly store: SlackInteractiveRequestStore;
63
- approval: {
64
- onRequest(request: ApprovalRequest, options?: SlackInteractiveRequestWaitOptions): Promise<ApprovalResolution>;
65
- };
66
- humanInput: {
67
- onRequest(request: HumanInputRequest, options?: SlackInteractiveRequestWaitOptions): Promise<HumanInputResponse>;
68
- };
69
- /** Reject one pending in-process waiter and delete its pending store record. */
70
- cancel(requestId: string, reason?: string): Promise<boolean>;
71
- /** Shutdown helper: cancel every pending request created by this controller. */
72
- cancelAll(reason?: string): Promise<void>;
73
- handleInteractiveRequest(context: SlackInteractiveRequestContext): Promise<boolean>;
74
- install(app: App): void;
75
- }
76
- type SlackInteractivePendingWaiter = {
77
- resolve: (resolution: SlackInteractiveResolution) => void;
78
- reject: (error: Error) => void;
79
- cleanup: () => void;
80
- };
81
- interface SlackInteractivePostedMessage {
82
- text: string;
83
- blocks: unknown[];
84
- ref: SlackInteractiveMessageRef;
85
- }
86
-
87
- export type { SlackInteractiveApprovalRequest as S, SlackInteractiveController as a, SlackInteractiveControllerOptions as b, SlackInteractiveHumanInputRequest as c, SlackInteractivePendingWaiter as d, SlackInteractivePostedMessage as e, SlackInteractiveRequestWaitOptions as f, SlackInteractiveResolution as g };
@@ -1,56 +0,0 @@
1
- import { App } from '@slack/bolt';
2
- import { SlackViewPayload, RegisterSlackViewWorkflowOptions, SlackViewWorkflowContext, SlackViewSubmissionAckResponse } from '@cuylabs/channel-slack/views';
3
-
4
- type SlackAgentViewStateValue = string | string[] | boolean | number | Record<string, unknown> | undefined;
5
- type SlackAgentViewStateValues = Record<string, Record<string, SlackAgentViewStateValue>>;
6
- declare function extractSlackAgentViewStateValues(viewOrState: SlackViewPayload | unknown): SlackAgentViewStateValues;
7
- declare function readSlackAgentViewStateValue(valuesOrView: SlackAgentViewStateValues | SlackViewPayload | unknown, blockId: string, actionId: string): SlackAgentViewStateValue;
8
-
9
- interface SlackAgentViewWorkflow {
10
- id: string;
11
- callbackId: string;
12
- }
13
- interface SlackAgentViewWorkflowContext<TMetadata = unknown> extends SlackViewWorkflowContext<TMetadata> {
14
- workflow: SlackAgentViewWorkflow;
15
- stateValues: SlackAgentViewStateValues;
16
- getStateValue(blockId: string, actionId: string): SlackAgentViewStateValue;
17
- }
18
- interface SlackAgentViewWorkflowDefinition<TMetadata = unknown> {
19
- /**
20
- * Stable product/agent workflow id. Used to derive the default Slack
21
- * callback id as `${namespace}_${id}`.
22
- */
23
- id: string;
24
- /**
25
- * Explicit Slack view callback id. Prefer this only when integrating with an
26
- * existing Slack app surface.
27
- */
28
- callbackId?: string;
29
- decodePrivateMetadata?: RegisterSlackViewWorkflowOptions<TMetadata>["decodePrivateMetadata"];
30
- onSubmission?: (context: SlackAgentViewWorkflowContext<TMetadata>) => SlackViewSubmissionAckResponse | void | Promise<SlackViewSubmissionAckResponse | void>;
31
- onClose?: (context: SlackAgentViewWorkflowContext<TMetadata>) => void | Promise<void>;
32
- onError?: (error: unknown, context: Omit<SlackAgentViewWorkflowContext<TMetadata>, "metadata"> & {
33
- metadata?: TMetadata | undefined;
34
- }) => void | Promise<void>;
35
- }
36
- interface CreateSlackAgentViewWorkflowControllerOptions {
37
- /**
38
- * Namespace for derived Slack callback ids.
39
- *
40
- * @default "agent_slack_view"
41
- */
42
- namespace?: string;
43
- workflows?: readonly SlackAgentViewWorkflowDefinition[];
44
- onError?: (error: unknown, context: Omit<SlackAgentViewWorkflowContext, "metadata"> & {
45
- metadata?: unknown;
46
- }) => void | Promise<void>;
47
- }
48
- interface SlackAgentViewWorkflowController {
49
- readonly namespace: string;
50
- register<TMetadata = unknown>(workflow: SlackAgentViewWorkflowDefinition<TMetadata>): string;
51
- callbackIdFor(workflowId: string): string;
52
- list(): SlackAgentViewWorkflow[];
53
- install(app: App): void;
54
- }
55
-
56
- export { type CreateSlackAgentViewWorkflowControllerOptions as C, type SlackAgentViewStateValue as S, type SlackAgentViewStateValues as a, type SlackAgentViewWorkflow as b, type SlackAgentViewWorkflowContext as c, type SlackAgentViewWorkflowController as d, type SlackAgentViewWorkflowDefinition as e, extractSlackAgentViewStateValues as f, readSlackAgentViewStateValue as r };
@@ -1,8 +0,0 @@
1
- import { C as CreateSlackAgentViewWorkflowControllerOptions, d as SlackAgentViewWorkflowController } from '../types-CiwGU6zC.js';
2
- export { S as SlackAgentViewStateValue, a as SlackAgentViewStateValues, b as SlackAgentViewWorkflow, c as SlackAgentViewWorkflowContext, e as SlackAgentViewWorkflowDefinition, f as extractSlackAgentViewStateValues, r as readSlackAgentViewStateValue } from '../types-CiwGU6zC.js';
3
- import '@slack/bolt';
4
- import '@cuylabs/channel-slack/views';
5
-
6
- declare function createSlackAgentViewWorkflowController({ namespace, workflows, onError, }?: CreateSlackAgentViewWorkflowControllerOptions): SlackAgentViewWorkflowController;
7
-
8
- export { CreateSlackAgentViewWorkflowControllerOptions, SlackAgentViewWorkflowController, createSlackAgentViewWorkflowController };
@@ -1,10 +0,0 @@
1
- import {
2
- createSlackAgentViewWorkflowController,
3
- extractSlackAgentViewStateValues,
4
- readSlackAgentViewStateValue
5
- } from "../chunk-C7CHMYV6.js";
6
- export {
7
- createSlackAgentViewWorkflowController,
8
- extractSlackAgentViewStateValues,
9
- readSlackAgentViewStateValue
10
- };
@@ -1,52 +0,0 @@
1
- # View Workflows
2
-
3
- Agent view workflows connect Slack modal submissions to agent or product logic.
4
- They sit above `@cuylabs/channel-slack/views`: the lower package owns Slack Web
5
- API/Bolt mechanics, while this package adds namespaced callback ids, decoded
6
- metadata, submitted state values, and app-surface mounting.
7
-
8
- ```typescript
9
- import {
10
- encodeSlackViewPrivateMetadata,
11
- openSlackModal,
12
- } from "@cuylabs/channel-slack/views";
13
- import { createSlackAgentViewWorkflowController } from "@cuylabs/channel-slack-agent-core/views";
14
-
15
- const viewWorkflows = createSlackAgentViewWorkflowController({
16
- namespace: "cdo",
17
- workflows: [
18
- {
19
- id: "incident_triage",
20
- onSubmission: async ({ metadata, stateValues, getStateValue, actor }) => {
21
- const severity = getStateValue("severity", "value");
22
- // Load product-owned workflow state by metadata.workflowId, validate the
23
- // submitted values, then continue an agent turn or product workflow.
24
- return { response_action: "clear" };
25
- },
26
- },
27
- ],
28
- });
29
-
30
- await openSlackModal({
31
- client,
32
- triggerId,
33
- view: {
34
- type: "modal",
35
- callback_id: viewWorkflows.callbackIdFor("incident_triage"),
36
- private_metadata: encodeSlackViewPrivateMetadata({
37
- workflowId: "triage-123",
38
- }),
39
- title: { type: "plain_text", text: "Triage incident" },
40
- submit: { type: "plain_text", text: "Continue" },
41
- blocks: [],
42
- },
43
- });
44
- ```
45
-
46
- Pass the controller to `mountSlackAgentApp` / `installSlackAgentAppSurface` as
47
- `viewWorkflows`. The controller installs `view_submission` and `view_closed`
48
- handlers on the underlying Bolt app.
49
-
50
- Keep `private_metadata` compact. Store durable workflow state in an application
51
- database or existing request store and put only routing keys, such as
52
- `workflowId`, `requestId`, or `sessionId`, into the modal.