@cuylabs/channel-slack-agent-core 0.8.0 → 0.9.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 (43) hide show
  1. package/README.md +4 -2
  2. package/dist/adapter/index.d.ts +6 -5
  3. package/dist/adapter/index.js +2 -2
  4. package/dist/{adapter-B3CI611y.d.ts → adapter-vbqtraAr.d.ts} +1 -1
  5. package/dist/app-surface.d.ts +6 -5
  6. package/dist/app-surface.js +4 -4
  7. package/dist/app.d.ts +6 -5
  8. package/dist/app.js +5 -5
  9. package/dist/assistant/index.d.ts +5 -4
  10. package/dist/assistant/index.js +2 -2
  11. package/dist/{chunk-TCNJY7QA.js → chunk-D4CSEAIF.js} +1 -1
  12. package/dist/{chunk-7YZWCSML.js → chunk-FJP6ZFUB.js} +1 -1
  13. package/dist/{chunk-6T6N4MRK.js → chunk-GKZRDNEB.js} +2 -2
  14. package/dist/{chunk-YSDFYHPC.js → chunk-HHXAXSG6.js} +2 -2
  15. package/dist/{chunk-2R7B7NJR.js → chunk-JU5R6JZG.js} +1 -1
  16. package/dist/{chunk-236WN6JD.js → chunk-KAEZPS3U.js} +1 -1
  17. package/dist/chunk-OP27SSZU.js +409 -0
  18. package/dist/{chunk-FQWFB54C.js → chunk-XA7U3GRN.js} +1 -1
  19. package/dist/express-assistant.d.ts +4 -3
  20. package/dist/express-assistant.js +3 -3
  21. package/dist/express.d.ts +5 -4
  22. package/dist/express.js +3 -3
  23. package/dist/history/index.d.ts +6 -5
  24. package/dist/index.d.ts +11 -10
  25. package/dist/index.js +10 -34
  26. package/dist/interactive/index.d.ts +5 -65
  27. package/dist/interactive/index.js +3 -27
  28. package/dist/interactive-BigrPKnu.d.ts +30 -0
  29. package/dist/{options-C7-VXmhD.d.ts → options-ByNm2o89.d.ts} +2 -2
  30. package/dist/{options-BcDReOJv.d.ts → options-CGUfVStV.d.ts} +1 -1
  31. package/dist/shared/index.d.ts +7 -76
  32. package/dist/shared/index.js +1 -1
  33. package/dist/socket.d.ts +6 -5
  34. package/dist/socket.js +5 -5
  35. package/dist/{types-CRWzJB5G.d.ts → types-BeGPexio.d.ts} +2 -2
  36. package/dist/{types-Crpil4kb.d.ts → types-Bz4OYEAV.d.ts} +6 -55
  37. package/docs/concepts/interactive-requests.md +7 -7
  38. package/docs/reference/boundary.md +5 -3
  39. package/docs/reference/exports.md +18 -18
  40. package/package.json +2 -2
  41. package/dist/chunk-X7ILLZZP.js +0 -1046
  42. package/dist/interactive-o_NZb-Xg.d.ts +0 -47
  43. /package/dist/{chunk-TMADMHBN.js → chunk-VBGQD6JT.js} +0 -0
package/README.md CHANGED
@@ -8,7 +8,8 @@ surfaces for Express Events API, Socket Mode, Slack Assistant, app mentions,
8
8
  DMs, feedback, approvals, or human input.
9
9
 
10
10
  Generic Slack mechanics such as parsing, policy, history, setup, auth, targets,
11
- users, entrypoints, artifacts, and transports live in `@cuylabs/channel-slack`.
11
+ users, entrypoints, artifacts, interactive stores/builders, response sinks, and
12
+ transports live in `@cuylabs/channel-slack`.
12
13
 
13
14
  ## Install
14
15
 
@@ -22,7 +23,8 @@ Install Slack peer dependencies for the surfaces you use:
22
23
  npm install @slack/bolt @slack/web-api express
23
24
  ```
24
25
 
25
- Postgres-backed interactive request storage lazy-loads `pg` when you pass a
26
+ Postgres-backed interactive request storage lives in
27
+ `@cuylabs/channel-slack/interactive` and lazy-loads `pg` when you pass a
26
28
  connection string. Install `pg` only when your application uses that helper
27
29
  without injecting its own client.
28
30
 
@@ -1,12 +1,13 @@
1
- export { c as createSlackChannelAdapter } from '../adapter-B3CI611y.js';
2
- import { a as SlackChannelOptions } from '../types-CRWzJB5G.js';
3
- export { S as SlackChannelAdapter, b as SlackSessionStrategy, c as SlackStreamingMode, d as SlackToolStartEvent } from '../types-CRWzJB5G.js';
1
+ export { c as createSlackChannelAdapter } from '../adapter-vbqtraAr.js';
2
+ import { a as SlackChannelOptions } from '../types-BeGPexio.js';
3
+ export { S as SlackChannelAdapter, b as SlackSessionStrategy, c as SlackStreamingMode, d as SlackToolStartEvent } from '../types-BeGPexio.js';
4
4
  import { SlackActivityInfo } from '@cuylabs/channel-slack/core';
5
5
  import '@cuylabs/agent-core';
6
- import '../options-BcDReOJv.js';
6
+ import '../options-CGUfVStV.js';
7
7
  import '../artifacts/index.js';
8
8
  import '@cuylabs/channel-slack/artifacts';
9
- import '../interactive-o_NZb-Xg.js';
9
+ import '../interactive-BigrPKnu.js';
10
+ import '@cuylabs/channel-slack/interactive';
10
11
 
11
12
  /**
12
13
  * Session mapping — Slack activity info to agent-core session IDs.
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  createSlackChannelAdapter,
3
3
  createSlackSessionMap
4
- } from "../chunk-FQWFB54C.js";
5
- import "../chunk-TMADMHBN.js";
4
+ } from "../chunk-XA7U3GRN.js";
5
+ import "../chunk-VBGQD6JT.js";
6
6
  export {
7
7
  createSlackChannelAdapter,
8
8
  createSlackSessionMap
@@ -1,4 +1,4 @@
1
- import { a as SlackChannelOptions, S as SlackChannelAdapter } from './types-CRWzJB5G.js';
1
+ import { a as SlackChannelOptions, S as SlackChannelAdapter } from './types-BeGPexio.js';
2
2
 
3
3
  /**
4
4
  * Slack Channel Adapter
@@ -1,14 +1,15 @@
1
1
  import { AgentTurnSource, Logger } from '@cuylabs/agent-core';
2
2
  import { App } from '@slack/bolt';
3
3
  import { WebClient } from '@slack/web-api';
4
- import { C as CreateSlackAssistantBridgeOptions, d as SlackAssistantFeedbackConfig, S as SlackAssistantBridge } from './options-C7-VXmhD.js';
5
- import { a as SlackChannelOptions } from './types-CRWzJB5G.js';
4
+ import { C as CreateSlackAssistantBridgeOptions, d as SlackAssistantFeedbackConfig, S as SlackAssistantBridge } from './options-ByNm2o89.js';
5
+ import { a as SlackChannelOptions } from './types-BeGPexio.js';
6
6
  import { SlackTurnRequestContext, SlackAssistantUtilities, SlackTurnPreparation } from '@cuylabs/channel-slack/core';
7
7
  import { SlackFeedbackHandler } from '@cuylabs/channel-slack/feedback';
8
- import { c as SlackInteractiveController } from './types-Crpil4kb.js';
8
+ import { a as SlackInteractiveController } from './types-Bz4OYEAV.js';
9
9
  import { d as SlackAgentViewWorkflowController } from './types-CiwGU6zC.js';
10
- import './interactive-o_NZb-Xg.js';
11
- import './options-BcDReOJv.js';
10
+ import './interactive-BigrPKnu.js';
11
+ import '@cuylabs/channel-slack/interactive';
12
+ import './options-CGUfVStV.js';
12
13
  import './artifacts/index.js';
13
14
  import '@cuylabs/channel-slack/artifacts';
14
15
  import '@cuylabs/channel-slack/assistant';
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  installSlackAgentAppSurface
3
- } from "./chunk-6T6N4MRK.js";
4
- import "./chunk-7YZWCSML.js";
3
+ } from "./chunk-GKZRDNEB.js";
4
+ import "./chunk-FJP6ZFUB.js";
5
5
  import "./chunk-ELR6MQD7.js";
6
- import "./chunk-FQWFB54C.js";
7
- import "./chunk-TMADMHBN.js";
6
+ import "./chunk-XA7U3GRN.js";
7
+ import "./chunk-VBGQD6JT.js";
8
8
  export {
9
9
  installSlackAgentAppSurface
10
10
  };
package/dist/app.d.ts CHANGED
@@ -5,17 +5,18 @@ import { CreateSlackBoltAppOptions } from '@cuylabs/channel-slack/transports/htt
5
5
  import { SlackDirectAuthOptions, SlackDirectAuthMode } from '@cuylabs/channel-slack/auth';
6
6
  import { SlackAgentAppSurfaceOptions } from './app-surface.js';
7
7
  export { MountSlackAgentAppTurnRequestContext } from './app-surface.js';
8
- import { S as SlackAssistantBridge } from './options-C7-VXmhD.js';
8
+ import { S as SlackAssistantBridge } from './options-ByNm2o89.js';
9
9
  import '@cuylabs/agent-core';
10
10
  import '@slack/web-api';
11
- import './types-CRWzJB5G.js';
11
+ import './types-BeGPexio.js';
12
12
  import '@cuylabs/channel-slack/core';
13
- import './options-BcDReOJv.js';
13
+ import './options-CGUfVStV.js';
14
14
  import './artifacts/index.js';
15
15
  import '@cuylabs/channel-slack/artifacts';
16
- import './interactive-o_NZb-Xg.js';
16
+ import './interactive-BigrPKnu.js';
17
+ import '@cuylabs/channel-slack/interactive';
17
18
  import '@cuylabs/channel-slack/feedback';
18
- import './types-Crpil4kb.js';
19
+ import './types-Bz4OYEAV.js';
19
20
  import './types-CiwGU6zC.js';
20
21
  import '@cuylabs/channel-slack/views';
21
22
  import '@cuylabs/channel-slack/assistant';
package/dist/app.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  mountSlackAgentApp
3
- } from "./chunk-236WN6JD.js";
4
- import "./chunk-6T6N4MRK.js";
5
- import "./chunk-7YZWCSML.js";
3
+ } from "./chunk-KAEZPS3U.js";
4
+ import "./chunk-GKZRDNEB.js";
5
+ import "./chunk-FJP6ZFUB.js";
6
6
  import "./chunk-ELR6MQD7.js";
7
- import "./chunk-FQWFB54C.js";
8
- import "./chunk-TMADMHBN.js";
7
+ import "./chunk-XA7U3GRN.js";
8
+ import "./chunk-VBGQD6JT.js";
9
9
  export {
10
10
  mountSlackAgentApp
11
11
  };
@@ -1,12 +1,13 @@
1
- import { C as CreateSlackAssistantBridgeOptions, S as SlackAssistantBridge } from '../options-C7-VXmhD.js';
2
- export { A as AssistantLifecycleArgs, a as AssistantThreadStartedArgs, M as MaybePromise, b as SlackAssistantCancelControlOptions, c as SlackAssistantCancelControlVisibleWhen, d as SlackAssistantFeedbackConfig, e as SlackAssistantSessionStrategy, f as SlackAssistantStatusContext, g as SlackAssistantThreadContextStoreLike, h as SlackAssistantThreadStartedContext, i as SlackAssistantTurnCancelContext, j as SlackAssistantTurnControlsOptions, k as SlackAssistantTurnPreparation, l as SlackAssistantUserMessageContext, r as resolveAssistantSessionId } from '../options-C7-VXmhD.js';
1
+ import { C as CreateSlackAssistantBridgeOptions, S as SlackAssistantBridge } from '../options-ByNm2o89.js';
2
+ export { A as AssistantLifecycleArgs, a as AssistantThreadStartedArgs, M as MaybePromise, b as SlackAssistantCancelControlOptions, c as SlackAssistantCancelControlVisibleWhen, d as SlackAssistantFeedbackConfig, e as SlackAssistantSessionStrategy, f as SlackAssistantStatusContext, g as SlackAssistantThreadContextStoreLike, h as SlackAssistantThreadStartedContext, i as SlackAssistantTurnCancelContext, j as SlackAssistantTurnControlsOptions, k as SlackAssistantTurnPreparation, l as SlackAssistantUserMessageContext, r as resolveAssistantSessionId } from '../options-ByNm2o89.js';
3
3
  export { ParsedAssistantUserMessage, createSlackAssistantThreadContextStore, parseSlackMessageActivityFromMessageEvent } from '@cuylabs/channel-slack/assistant';
4
4
  import '@cuylabs/agent-core';
5
5
  import '@slack/bolt';
6
6
  import '@slack/web-api';
7
7
  import '@cuylabs/channel-slack/core';
8
- import '../interactive-o_NZb-Xg.js';
9
- import '../options-BcDReOJv.js';
8
+ import '../interactive-BigrPKnu.js';
9
+ import '@cuylabs/channel-slack/interactive';
10
+ import '../options-CGUfVStV.js';
10
11
  import '../artifacts/index.js';
11
12
  import '@cuylabs/channel-slack/artifacts';
12
13
  import '@cuylabs/channel-slack/feedback';
@@ -3,9 +3,9 @@ import {
3
3
  createSlackAssistantThreadContextStore,
4
4
  parseSlackMessageActivityFromMessageEvent,
5
5
  resolveAssistantSessionId
6
- } from "../chunk-7YZWCSML.js";
6
+ } from "../chunk-FJP6ZFUB.js";
7
7
  import "../chunk-ELR6MQD7.js";
8
- import "../chunk-TMADMHBN.js";
8
+ import "../chunk-VBGQD6JT.js";
9
9
  export {
10
10
  createSlackAssistantBridge,
11
11
  createSlackAssistantThreadContextStore,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createSlackChannelAdapter
3
- } from "./chunk-FQWFB54C.js";
3
+ } from "./chunk-XA7U3GRN.js";
4
4
 
5
5
  // src/express.ts
6
6
  import {
@@ -7,7 +7,7 @@ import {
7
7
  UnsupportedSlackInteractiveRequestError,
8
8
  bridgeAgentEventsToSlack,
9
9
  resolveSlackEventBridgeOptions
10
- } from "./chunk-TMADMHBN.js";
10
+ } from "./chunk-VBGQD6JT.js";
11
11
 
12
12
  // src/assistant/bridge.ts
13
13
  import { Assistant } from "@slack/bolt";
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  createSlackAssistantBridge
3
- } from "./chunk-7YZWCSML.js";
3
+ } from "./chunk-FJP6ZFUB.js";
4
4
  import {
5
5
  createSlackFeedbackBlock
6
6
  } from "./chunk-ELR6MQD7.js";
7
7
  import {
8
8
  createSlackChannelAdapter
9
- } from "./chunk-FQWFB54C.js";
9
+ } from "./chunk-XA7U3GRN.js";
10
10
 
11
11
  // src/app-surface.ts
12
12
  var DEFAULT_TIMEOUT_MS = 12e4;
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  installSlackAgentAppSurface
3
- } from "./chunk-6T6N4MRK.js";
3
+ } from "./chunk-GKZRDNEB.js";
4
4
  import {
5
5
  createSlackAssistantBridge
6
- } from "./chunk-7YZWCSML.js";
6
+ } from "./chunk-FJP6ZFUB.js";
7
7
 
8
8
  // src/socket.ts
9
9
  import { createSlackSocketBoltApp } from "@cuylabs/channel-slack/transports/socket";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createSlackAssistantBridge
3
- } from "./chunk-7YZWCSML.js";
3
+ } from "./chunk-FJP6ZFUB.js";
4
4
 
5
5
  // src/express-assistant.ts
6
6
  import {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  installSlackAgentAppSurface
3
- } from "./chunk-6T6N4MRK.js";
3
+ } from "./chunk-GKZRDNEB.js";
4
4
 
5
5
  // src/app.ts
6
6
  import {
@@ -0,0 +1,409 @@
1
+ // src/interactive/controller.ts
2
+ import {
3
+ buildApprovalRequestMessage,
4
+ buildHumanInputModal,
5
+ buildHumanInputRequestMessage,
6
+ buildResolvedMessage,
7
+ createInMemorySlackInteractiveRequestStore,
8
+ decodeActionValue,
9
+ nowIso
10
+ } from "@cuylabs/channel-slack/interactive";
11
+ import { openSlackModal } from "@cuylabs/channel-slack/views";
12
+ var DEFAULT_NAMESPACE = "agent_slack";
13
+ var DEFAULT_REQUEST_TIMEOUT_MS = 5 * 60 * 1e3;
14
+ var installedActionIds = /* @__PURE__ */ new WeakMap();
15
+ function createSlackInteractiveController(options = {}) {
16
+ const store = options.store ?? createInMemorySlackInteractiveRequestStore();
17
+ const actionIds = resolveActionIds(
18
+ options.namespace ?? DEFAULT_NAMESPACE,
19
+ options.actionIds
20
+ );
21
+ const requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
22
+ const waiters = /* @__PURE__ */ new Map();
23
+ const pendingIds = /* @__PURE__ */ new Set();
24
+ async function ensurePending(kind, request) {
25
+ const existing = await store.get(request.id);
26
+ if (existing) {
27
+ pendingIds.add(request.id);
28
+ return existing;
29
+ }
30
+ const createdAt = nowIso();
31
+ const record = await store.upsert({
32
+ id: request.id,
33
+ kind,
34
+ request,
35
+ status: "pending",
36
+ createdAt,
37
+ updatedAt: createdAt
38
+ });
39
+ pendingIds.add(request.id);
40
+ return record;
41
+ }
42
+ async function waitForResolution(kind, request, waitOptions = {}) {
43
+ const existing = await ensurePending(kind, request);
44
+ if (existing.status === "resolved" && existing.resolution) {
45
+ return toAgentCoreResolution(existing.resolution);
46
+ }
47
+ if (waiters.has(request.id)) {
48
+ throw new Error(
49
+ `Slack interactive request is already waiting: ${request.id}. Resolve or cancel the in-flight request before requesting again.`
50
+ );
51
+ }
52
+ return await new Promise((resolve, reject) => {
53
+ const cleanupCallbacks = [];
54
+ const timeoutMs = waitOptions.timeoutMs ?? requestTimeoutMs;
55
+ if (timeoutMs > 0) {
56
+ const timeoutId = setTimeout(() => {
57
+ void cancel(request.id, "Slack interactive request timed out.");
58
+ }, timeoutMs);
59
+ cleanupCallbacks.push(() => clearTimeout(timeoutId));
60
+ }
61
+ let abortImmediately = false;
62
+ if (waitOptions.signal) {
63
+ const onAbort = () => {
64
+ void cancel(request.id, "Slack interactive request aborted.");
65
+ };
66
+ if (waitOptions.signal.aborted) {
67
+ abortImmediately = true;
68
+ } else {
69
+ waitOptions.signal.addEventListener("abort", onAbort, {
70
+ once: true
71
+ });
72
+ cleanupCallbacks.push(
73
+ () => waitOptions.signal?.removeEventListener("abort", onAbort)
74
+ );
75
+ }
76
+ }
77
+ waiters.set(request.id, {
78
+ resolve,
79
+ reject,
80
+ cleanup: () => {
81
+ for (const cleanup of cleanupCallbacks.splice(0)) {
82
+ cleanup();
83
+ }
84
+ }
85
+ });
86
+ if (abortImmediately) {
87
+ void cancel(request.id, "Slack interactive request aborted.");
88
+ }
89
+ });
90
+ }
91
+ async function resolveRequest(requestId, resolution) {
92
+ const record = await store.resolve(requestId, resolution);
93
+ const waiter = waiters.get(requestId);
94
+ if (waiter) {
95
+ waiters.delete(requestId);
96
+ waiter.cleanup();
97
+ waiter.resolve(resolution);
98
+ }
99
+ if (record) {
100
+ pendingIds.delete(requestId);
101
+ await options.onResolve?.(requestId, resolution);
102
+ }
103
+ return record;
104
+ }
105
+ async function cancel(requestId, reason = "Cancelled") {
106
+ const waiter = waiters.get(requestId);
107
+ if (waiter) {
108
+ waiters.delete(requestId);
109
+ waiter.cleanup();
110
+ waiter.reject(new Error(reason));
111
+ }
112
+ const existing = await store.get(requestId);
113
+ if (existing?.status === "pending") {
114
+ await store.delete(requestId);
115
+ pendingIds.delete(requestId);
116
+ return true;
117
+ }
118
+ pendingIds.delete(requestId);
119
+ return Boolean(waiter);
120
+ }
121
+ async function cancelAll(reason = "Cancelled") {
122
+ await Promise.all(
123
+ [...pendingIds].map((requestId) => cancel(requestId, reason))
124
+ );
125
+ }
126
+ async function handleInteractiveRequest(context) {
127
+ const request = context.request;
128
+ const record = await ensurePending(context.kind, request);
129
+ if (record.target) {
130
+ return true;
131
+ }
132
+ const message = context.kind === "approval" ? buildApprovalRequestMessage(
133
+ request,
134
+ actionIds
135
+ ) : buildHumanInputRequestMessage(
136
+ request,
137
+ actionIds
138
+ );
139
+ const ref = await context.responder.postMessage(message);
140
+ await store.attachTarget(request.id, {
141
+ channel: ref.channel,
142
+ ts: ref.ts,
143
+ userId: context.user.userId,
144
+ teamId: context.user.teamId,
145
+ ...context.slackActivity.threadTs ? { threadTs: context.slackActivity.threadTs } : {}
146
+ });
147
+ return true;
148
+ }
149
+ function install(app) {
150
+ assertActionIdsCanInstall(app, actionIds);
151
+ app.action(actionIds.approvalAllow, async (args) => {
152
+ await handleAction(args, {
153
+ kind: "approval",
154
+ action: "allow"
155
+ });
156
+ });
157
+ app.action(actionIds.approvalDeny, async (args) => {
158
+ await handleAction(args, {
159
+ kind: "approval",
160
+ action: "deny"
161
+ });
162
+ });
163
+ app.action(actionIds.approvalRemember, async (args) => {
164
+ const value = firstActionValue(args);
165
+ const rememberScope = typeof value.rememberScope === "string" ? value.rememberScope : void 0;
166
+ await handleAction(args, {
167
+ kind: "approval",
168
+ action: "remember",
169
+ ...rememberScope ? { rememberScope } : {}
170
+ });
171
+ });
172
+ app.action(actionIds.humanConfirm, async (args) => {
173
+ await handleAction(args, {
174
+ kind: "human-input",
175
+ response: { kind: "confirm", confirmed: true, text: "Confirmed" }
176
+ });
177
+ });
178
+ app.action(actionIds.humanDeny, async (args) => {
179
+ await handleAction(args, {
180
+ kind: "human-input",
181
+ response: { kind: "confirm", confirmed: false, text: "Cancelled" }
182
+ });
183
+ });
184
+ app.action(actionIds.humanOpen, async (args) => {
185
+ await openHumanInputModal(args);
186
+ });
187
+ app.view(actionIds.humanSubmit, async (args) => {
188
+ await submitHumanInputModal(args);
189
+ });
190
+ }
191
+ async function handleAction(args, resolutionInput) {
192
+ const actionArgs = args;
193
+ await actionArgs.ack();
194
+ const requestId = extractRequestId(firstActionValue(args));
195
+ if (!requestId) return;
196
+ const record = await store.get(requestId);
197
+ if (!record || record.status === "resolved") {
198
+ return;
199
+ }
200
+ const actor = extractActor(actionArgs.body);
201
+ if (!await isAuthorized(record, actor)) {
202
+ await postEphemeral(
203
+ actionArgs,
204
+ "Only the original requester can resolve this request."
205
+ );
206
+ return;
207
+ }
208
+ const resolution = resolutionInput;
209
+ const resolved = await resolveRequest(requestId, resolution);
210
+ if (resolved?.target) {
211
+ await updateOriginalMessage(actionArgs, resolved, resolution);
212
+ }
213
+ }
214
+ async function openHumanInputModal(args) {
215
+ const actionArgs = args;
216
+ await actionArgs.ack();
217
+ const requestId = extractRequestId(firstActionValue(args));
218
+ if (!requestId || !actionArgs.body.trigger_id) return;
219
+ const record = await store.get(requestId);
220
+ if (!record || record.kind !== "human-input") return;
221
+ const actor = extractActor(actionArgs.body);
222
+ if (!await isAuthorized(record, actor)) {
223
+ await postEphemeral(
224
+ actionArgs,
225
+ "Only the original requester can answer this request."
226
+ );
227
+ return;
228
+ }
229
+ await openSlackModal({
230
+ client: actionArgs.client,
231
+ triggerId: actionArgs.body.trigger_id,
232
+ view: buildHumanInputModal(
233
+ record.request,
234
+ actionIds
235
+ )
236
+ });
237
+ }
238
+ async function submitHumanInputModal(args) {
239
+ const viewArgs = args;
240
+ await viewArgs.ack();
241
+ const requestId = extractRequestIdFromView(viewArgs.view);
242
+ if (!requestId) return;
243
+ const record = await store.get(requestId);
244
+ if (!record || record.kind !== "human-input" || record.status === "resolved") {
245
+ return;
246
+ }
247
+ const actor = extractActor(viewArgs.body);
248
+ if (!await isAuthorized(record, actor)) {
249
+ return;
250
+ }
251
+ const response = responseFromView(
252
+ record.request,
253
+ viewArgs.view
254
+ );
255
+ const resolution = {
256
+ kind: "human-input",
257
+ response
258
+ };
259
+ const resolved = await resolveRequest(requestId, resolution);
260
+ if (resolved?.target) {
261
+ await viewArgs.client.chat.update({
262
+ channel: resolved.target.channel,
263
+ ts: resolved.target.ts,
264
+ ...buildResolvedMessage("Slack response received.", resolution)
265
+ });
266
+ }
267
+ }
268
+ async function isAuthorized(record, actor) {
269
+ if (options.authorize) {
270
+ return await options.authorize(record, actor);
271
+ }
272
+ return record.target?.userId === actor.userId;
273
+ }
274
+ async function updateOriginalMessage(args, record, resolution) {
275
+ const target = record.target;
276
+ if (!target) return;
277
+ const label = resolution.kind === "approval" ? `${resolution.action} selected.` : resolution.response.text;
278
+ await args.client.chat.update({
279
+ channel: target.channel,
280
+ ts: target.ts,
281
+ ...buildResolvedMessage(label, resolution)
282
+ });
283
+ }
284
+ return {
285
+ actionIds,
286
+ store,
287
+ approval: {
288
+ async onRequest(request, options2) {
289
+ const resolution = await waitForResolution(
290
+ "approval",
291
+ request,
292
+ options2
293
+ );
294
+ if (resolution.kind !== "approval") {
295
+ throw new Error(
296
+ `Unexpected human-input resolution for ${request.id}.`
297
+ );
298
+ }
299
+ return {
300
+ action: resolution.action,
301
+ ...resolution.feedback ? { feedback: resolution.feedback } : {},
302
+ ...resolution.rememberScope ? { rememberScope: resolution.rememberScope } : {}
303
+ };
304
+ }
305
+ },
306
+ humanInput: {
307
+ async onRequest(request, options2) {
308
+ const resolution = await waitForResolution(
309
+ "human-input",
310
+ request,
311
+ options2
312
+ );
313
+ if (resolution.kind !== "human-input") {
314
+ throw new Error(`Unexpected approval resolution for ${request.id}.`);
315
+ }
316
+ return resolution.response;
317
+ }
318
+ },
319
+ cancel,
320
+ cancelAll,
321
+ handleInteractiveRequest,
322
+ install
323
+ };
324
+ }
325
+ function toAgentCoreResolution(resolution) {
326
+ return resolution;
327
+ }
328
+ function resolveActionIds(namespace, overrides) {
329
+ const prefix = normalizeActionIdNamespace(namespace);
330
+ return {
331
+ approvalAllow: `${prefix}_approval_allow`,
332
+ approvalDeny: `${prefix}_approval_deny`,
333
+ approvalRemember: `${prefix}_approval_remember`,
334
+ humanConfirm: `${prefix}_human_confirm`,
335
+ humanDeny: `${prefix}_human_deny`,
336
+ humanOpen: `${prefix}_human_open`,
337
+ humanSubmit: `${prefix}_human_submit`,
338
+ ...overrides ?? {}
339
+ };
340
+ }
341
+ function normalizeActionIdNamespace(namespace) {
342
+ const trimmed = namespace.trim();
343
+ if (!trimmed) {
344
+ throw new Error("Slack interactive action namespace cannot be empty.");
345
+ }
346
+ return trimmed;
347
+ }
348
+ function assertActionIdsCanInstall(app, actionIds) {
349
+ const ids = Object.values(actionIds);
350
+ const duplicateWithinController = ids.find(
351
+ (id, index) => ids.indexOf(id) !== index
352
+ );
353
+ if (duplicateWithinController) {
354
+ throw new Error(
355
+ `Duplicate Slack interactive action id configured: ${duplicateWithinController}`
356
+ );
357
+ }
358
+ const appKey = app;
359
+ const installed = installedActionIds.get(appKey) ?? /* @__PURE__ */ new Set();
360
+ const duplicate = ids.find((id) => installed.has(id));
361
+ if (duplicate) {
362
+ throw new Error(
363
+ `Slack interactive action id '${duplicate}' is already installed on this Bolt app. Provide a unique createSlackInteractiveController({ namespace }) or actionIds config.`
364
+ );
365
+ }
366
+ for (const id of ids) {
367
+ installed.add(id);
368
+ }
369
+ installedActionIds.set(appKey, installed);
370
+ }
371
+ function firstActionValue(args) {
372
+ const body = args.body;
373
+ return decodeActionValue(body.actions?.[0]?.value);
374
+ }
375
+ function extractRequestId(value) {
376
+ return typeof value.requestId === "string" && value.requestId.length > 0 ? value.requestId : void 0;
377
+ }
378
+ function extractRequestIdFromView(view) {
379
+ return extractRequestId(decodeActionValue(view.private_metadata));
380
+ }
381
+ function extractActor(body) {
382
+ return {
383
+ userId: body.user?.id ?? "unknown",
384
+ ...body.user?.team_id ?? body.team?.id ? { teamId: body.user?.team_id ?? body.team?.id } : {}
385
+ };
386
+ }
387
+ async function postEphemeral(args, text) {
388
+ const channel = args.body.channel?.id;
389
+ const user = args.body.user?.id;
390
+ if (!channel || !user || !args.client.chat.postEphemeral) return;
391
+ await args.client.chat.postEphemeral({ channel, user, text });
392
+ }
393
+ function responseFromView(request, view) {
394
+ const input = view.state?.values?.input?.value;
395
+ if (request.kind === "choice") {
396
+ const selected = input?.selected_options?.map((option) => option.value ?? "").filter(Boolean) ?? (input?.selected_option?.value ? [input.selected_option.value] : []);
397
+ return {
398
+ kind: "choice",
399
+ selected,
400
+ text: selected.join(", ")
401
+ };
402
+ }
403
+ const text = input?.value ?? "";
404
+ return { kind: "text", text };
405
+ }
406
+
407
+ export {
408
+ createSlackInteractiveController
409
+ };
@@ -2,7 +2,7 @@ import {
2
2
  UnsupportedSlackInteractiveRequestError,
3
3
  bridgeAgentEventsToSlack,
4
4
  resolveSlackEventBridgeOptions
5
- } from "./chunk-TMADMHBN.js";
5
+ } from "./chunk-VBGQD6JT.js";
6
6
 
7
7
  // src/adapter/adapter.ts
8
8
  import { withinScope } from "@cuylabs/agent-core";
@@ -3,13 +3,14 @@ import { Application } from 'express';
3
3
  import { App, ExpressReceiver } from '@slack/bolt';
4
4
  import { CreateSlackBoltAppOptions } from '@cuylabs/channel-slack/transports/http';
5
5
  import { SlackDirectAuthOptions, SlackDirectAuthMode } from '@cuylabs/channel-slack/auth';
6
- import { C as CreateSlackAssistantBridgeOptions, d as SlackAssistantFeedbackConfig, S as SlackAssistantBridge } from './options-C7-VXmhD.js';
6
+ import { C as CreateSlackAssistantBridgeOptions, d as SlackAssistantFeedbackConfig, S as SlackAssistantBridge } from './options-ByNm2o89.js';
7
7
  import { SlackFeedbackHandler } from '@cuylabs/channel-slack/feedback';
8
8
  import '@cuylabs/agent-core';
9
9
  import '@slack/web-api';
10
10
  import '@cuylabs/channel-slack/core';
11
- import './interactive-o_NZb-Xg.js';
12
- import './options-BcDReOJv.js';
11
+ import './interactive-BigrPKnu.js';
12
+ import '@cuylabs/channel-slack/interactive';
13
+ import './options-CGUfVStV.js';
13
14
  import './artifacts/index.js';
14
15
  import '@cuylabs/channel-slack/artifacts';
15
16
  import '@cuylabs/channel-slack/assistant';