@meetopenbot/slack 1.6.0 → 1.6.1

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 (2) hide show
  1. package/dist/invoke.js +20 -16
  2. package/package.json +1 -1
package/dist/invoke.js CHANGED
@@ -6,13 +6,17 @@ import { resolveSlackModel, ROUTING_AGENT_ID, SLACK_USER_DISPLAY_NAME, } from ".
6
6
  import { buildPromptWithSlackContext } from "./context.js";
7
7
  import { fetchSlackUserFlags, postSlackMessage } from "./post.js";
8
8
  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";
9
+ import { slackNeedsInputNotice, SLACK_THREAD_STATE_KEY, } from "./needs-input.js";
10
10
  import { getSlackThreadMeta, isSlackWebhookIngress } from "./webhook.js";
11
11
  /**
12
12
  * The host connects Slack before `run`. A run without credentials means the host is too
13
13
  * old to know `oauthApp` connections.
14
14
  */
15
15
  export const SLACK_NEEDS_NEWER_RUNTIME = "Slack needs a newer OpenBot runtime to connect. Update the runtime and try again.";
16
+ /** Behalf's own answer, as opposed to what a specialist said inside it. */
17
+ function isCoordinatorReply(event) {
18
+ return event.type === "agent:output" && !event.meta?.parentToolCallId;
19
+ }
16
20
  async function* bridgeSystemAgentRun(args) {
17
21
  const runId = `slack_${randomUUID()}`;
18
22
  const slackMeta = getSlackThreadMeta(args.meta);
@@ -39,32 +43,32 @@ async function* bridgeSystemAgentRun(args) {
39
43
  meta: {
40
44
  channelId: args.channelId,
41
45
  threadId: args.threadId,
46
+ // The person's message is already in the thread; don't store it a second time.
47
+ alreadyStored: true,
42
48
  ...slackOrigin,
43
49
  userName: SLACK_USER_DISPLAY_NAME,
44
50
  ...(typeof args.meta?.userId === "string" ? { userId: args.meta.userId } : {}),
45
51
  },
46
52
  },
47
53
  onEvent: async (outEvent) => {
48
- if (outEvent.type === "agent:output" && !outEvent.meta?.parentToolCallId) {
49
- const output = outEvent;
54
+ // The run isn't stored here; the Slack run that wraps it stores what it yields. So pass
55
+ // on everything a normal Behalf run would show: replies, tool calls, and the cards a
56
+ // specialist (Linear, GitHub…) raises inside it. Without those cards a run waiting on
57
+ // one would sit on "Working…" with nothing to answer. Only this run's own start/end
58
+ // are left out; the Slack run has its own.
59
+ const isOwnLifecycle = (outEvent.type === "agent:run:start" || outEvent.type === "agent:run:end") &&
60
+ !outEvent.meta?.parentToolCallId;
61
+ if (!isOwnLifecycle) {
62
+ const isReply = isCoordinatorReply(outEvent);
50
63
  eventQueue.push({
51
- ...output,
64
+ ...outEvent,
52
65
  meta: {
53
- ...output.meta,
54
- agentId: ROUTING_AGENT_ID,
66
+ ...outEvent.meta,
55
67
  threadId: args.threadId,
56
- ...slackOrigin,
68
+ ...(isReply ? { agentId: ROUTING_AGENT_ID, ...slackOrigin } : {}),
57
69
  },
58
70
  });
59
71
  }
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
72
  if (resolveNext) {
69
73
  resolveNext();
70
74
  resolveNext = null;
@@ -277,7 +281,7 @@ export async function* handleSlackInvoke(args) {
277
281
  publicBaseUrl: args.publicBaseUrl,
278
282
  })) {
279
283
  yield output;
280
- if (output.type === "agent:output")
284
+ if (isCoordinatorReply(output))
281
285
  await reply(output);
282
286
  else {
283
287
  const notice = slackNeedsInputNotice(output);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meetopenbot/slack",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
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",