@meetopenbot/slack 1.6.0 → 1.6.2

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/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { definePlugin } from "@meetopenbot/plugin-sdk";
2
2
  import { pluginConfigSchema, readSlackConfig, SLACK_BOT_SCOPES, slackCredentials, } from "./config.js";
3
3
  import { handleSlackInvoke } from "./invoke.js";
4
- import { addSlackReaction } from "./reactions.js";
5
4
  import { handleSlackWebhook } from "./webhook.js";
6
5
  export const plugin = definePlugin({
7
6
  name: "Slack",
@@ -33,16 +32,6 @@ export const plugin = definePlugin({
33
32
  return !!state && typeof state === "object" && Object.keys(state).length > 0;
34
33
  },
35
34
  storage: context.storage,
36
- acknowledge: (message) => {
37
- const credentials = slackCredentials(context);
38
- if (!credentials)
39
- return;
40
- void addSlackReaction({
41
- token: credentials.botToken,
42
- channel: message.channel,
43
- timestamp: message.ts,
44
- });
45
- },
46
35
  });
47
36
  },
48
37
  async *run({ event, handlerCtx, context }) {
package/dist/invoke.js CHANGED
@@ -5,14 +5,19 @@ import { resolveSlackSpace, updateSlackPluginConfig } from "./bindings.js";
5
5
  import { resolveSlackModel, ROUTING_AGENT_ID, SLACK_USER_DISPLAY_NAME, } from "./config.js";
6
6
  import { buildPromptWithSlackContext } from "./context.js";
7
7
  import { fetchSlackUserFlags, postSlackMessage } from "./post.js";
8
+ import { addSlackReaction } from "./reactions.js";
8
9
  import { ambiguousSpaceMessage, boundMessage, canRouteSlackChannel, findSpace, missingSpaceMessage, parseUseSpaceCommand, ROUTING_FORBIDDEN, ROUTING_HINT, ROUTING_UNNAMED_CHANNEL, withChannelBinding, withHintedChannel, } from "./routing.js";
9
- import { isInteractionEvent, slackNeedsInputNotice, SLACK_THREAD_STATE_KEY, } from "./needs-input.js";
10
+ import { slackNeedsInputNotice, SLACK_THREAD_STATE_KEY, } from "./needs-input.js";
10
11
  import { getSlackThreadMeta, isSlackWebhookIngress } from "./webhook.js";
11
12
  /**
12
13
  * The host connects Slack before `run`. A run without credentials means the host is too
13
14
  * old to know `oauthApp` connections.
14
15
  */
15
16
  export const SLACK_NEEDS_NEWER_RUNTIME = "Slack needs a newer OpenBot runtime to connect. Update the runtime and try again.";
17
+ /** Behalf's own answer, as opposed to what a specialist said inside it. */
18
+ function isCoordinatorReply(event) {
19
+ return event.type === "agent:output" && !event.meta?.parentToolCallId;
20
+ }
16
21
  async function* bridgeSystemAgentRun(args) {
17
22
  const runId = `slack_${randomUUID()}`;
18
23
  const slackMeta = getSlackThreadMeta(args.meta);
@@ -39,32 +44,32 @@ async function* bridgeSystemAgentRun(args) {
39
44
  meta: {
40
45
  channelId: args.channelId,
41
46
  threadId: args.threadId,
47
+ // The person's message is already in the thread; don't store it a second time.
48
+ alreadyStored: true,
42
49
  ...slackOrigin,
43
50
  userName: SLACK_USER_DISPLAY_NAME,
44
51
  ...(typeof args.meta?.userId === "string" ? { userId: args.meta.userId } : {}),
45
52
  },
46
53
  },
47
54
  onEvent: async (outEvent) => {
48
- if (outEvent.type === "agent:output" && !outEvent.meta?.parentToolCallId) {
49
- const output = outEvent;
55
+ // The run isn't stored here; the Slack run that wraps it stores what it yields. So pass
56
+ // on everything a normal Behalf run would show: replies, tool calls, and the cards a
57
+ // specialist (Linear, GitHub…) raises inside it. Without those cards a run waiting on
58
+ // one would sit on "Working…" with nothing to answer. Only this run's own start/end
59
+ // are left out; the Slack run has its own.
60
+ const isOwnLifecycle = (outEvent.type === "agent:run:start" || outEvent.type === "agent:run:end") &&
61
+ !outEvent.meta?.parentToolCallId;
62
+ if (!isOwnLifecycle) {
63
+ const isReply = isCoordinatorReply(outEvent);
50
64
  eventQueue.push({
51
- ...output,
65
+ ...outEvent,
52
66
  meta: {
53
- ...output.meta,
54
- agentId: ROUTING_AGENT_ID,
67
+ ...outEvent.meta,
55
68
  threadId: args.threadId,
56
- ...slackOrigin,
69
+ ...(isReply ? { agentId: ROUTING_AGENT_ID, ...slackOrigin } : {}),
57
70
  },
58
71
  });
59
72
  }
60
- else if (isInteractionEvent(outEvent) && !outEvent.meta?.parentToolCallId) {
61
- // The run isn't stored, so a card it waits on would never reach OpenBot and the
62
- // thread would sit on "Working…" with nothing to answer. Pass cards on to be stored.
63
- eventQueue.push({
64
- ...outEvent,
65
- meta: { ...outEvent.meta, threadId: args.threadId },
66
- });
67
- }
68
73
  if (resolveNext) {
69
74
  resolveNext();
70
75
  resolveNext = null;
@@ -180,6 +185,15 @@ export async function* handleSlackInvoke(args) {
180
185
  }
181
186
  const slackMeta = getSlackThreadMeta(args.event.meta);
182
187
  const slackChannelId = slackMeta?.channel;
188
+ // Show the person the bot has seen the message. The webhook handler has no Slack token
189
+ // (only a run is connected), so this is the earliest the reaction can be added.
190
+ if (slackChannelId && slackMeta?.ts) {
191
+ void addSlackReaction({
192
+ token: credentials.botToken,
193
+ channel: slackChannelId,
194
+ timestamp: slackMeta.ts,
195
+ });
196
+ }
183
197
  const postToSlack = async (text) => {
184
198
  if (!slackChannelId || !text.trim())
185
199
  return;
@@ -277,7 +291,7 @@ export async function* handleSlackInvoke(args) {
277
291
  publicBaseUrl: args.publicBaseUrl,
278
292
  })) {
279
293
  yield output;
280
- if (output.type === "agent:output")
294
+ if (isCoordinatorReply(output))
281
295
  await reply(output);
282
296
  else {
283
297
  const notice = slackNeedsInputNotice(output);
@@ -17,7 +17,9 @@ export function slackNeedsInputNotice(event) {
17
17
  return undefined;
18
18
  const hasInput = (Array.isArray(widget.actions) && widget.actions.length > 0) ||
19
19
  ("fields" in widget && Array.isArray(widget.fields) && widget.fields.length > 0);
20
- if (!hasInput)
20
+ // A connect card has a button in the app but carries no actions of its own.
21
+ const isConnect = widget.metadata?.type === "connection_request";
22
+ if (!hasInput && !isConnect)
21
23
  return undefined;
22
24
  const title = widget.title?.trim();
23
25
  return `I need your input to continue${title ? `: ${title}` : ""}. Open this conversation in OpenBot to answer, and I'll carry on from there.`;
package/dist/webhook.js CHANGED
@@ -95,9 +95,6 @@ export async function* handleSlackWebhook(args) {
95
95
  yield webhookHttpResponse({ status: 200, body: {} });
96
96
  return;
97
97
  }
98
- if (slackEvent.channel && slackEvent.ts) {
99
- args.acknowledge?.({ channel: slackEvent.channel, ts: slackEvent.ts });
100
- }
101
98
  args.ctx.state.threadId = threadId;
102
99
  const slackMeta = {
103
100
  teamId: payload.team_id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meetopenbot/slack",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "Slack Events API ingress, simple agent replies, and thread delivery for OpenBot",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",