agent-slack 0.9.0 → 0.9.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
@@ -2129,9 +2129,13 @@ async function assertWorkspaceSpecifiedForChannelNames(input) {
2129
2129
  if ((creds.workspaces?.length ?? 0) <= 1) {
2130
2130
  return;
2131
2131
  }
2132
- if (!input.workspaceUrl) {
2133
- throw new Error('Ambiguous channel name across multiple workspaces. Pass --workspace "<url-or-unique-substring>" (or set SLACK_WORKSPACE_URL).');
2132
+ if (input.workspaceUrl) {
2133
+ return;
2134
2134
  }
2135
+ if (creds.default_workspace_url) {
2136
+ return;
2137
+ }
2138
+ throw new Error('Ambiguous channel name across multiple workspaces. Pass --workspace "<url-or-unique-substring>" (or set SLACK_WORKSPACE_URL, or run "agent-slack auth set-default <url>").');
2135
2139
  }
2136
2140
  function isAuthErrorMessage(message) {
2137
2141
  return /(?:^|[^a-z])(invalid_auth|token_expired)(?:$|[^a-z])/i.test(message);
@@ -3589,14 +3593,32 @@ var CODE_BLOCK_START = /^```/;
3589
3593
  var BLOCKQUOTE_RE = /^> (.*)$/;
3590
3594
  function parseInlineElements(text) {
3591
3595
  const elements = [];
3592
- const re = /`([^`]+)`|\*([^*]+)\*|_([^_]+)_|~([^~]+)~|<([^>|]+)\|([^>]+)>|<([^>|]+)>/g;
3596
+ const re = /`([^`]+)`|\*([^*]+)\*|_([^_]+)_|~([^~]+)~|<@([UWB][A-Z0-9]+)(?:\|[^>]*)?>|<!(here|channel|everyone)(?:\|[^>]*)?>|<([^>|]+)\|([^>]+)>|<([^>|]+)>|(?:^|(?<=[^A-Za-z0-9_]))@([UWB][A-Z0-9]{6,})\b|(?:^|(?<=[^A-Za-z0-9_]))@(here|channel|everyone)\b/g;
3593
3597
  let lastIndex = 0;
3594
3598
  let match;
3599
+ const pushText = (slice) => {
3600
+ if (slice) {
3601
+ elements.push({ type: "text", text: slice });
3602
+ }
3603
+ };
3595
3604
  while ((match = re.exec(text)) !== null) {
3596
3605
  if (match.index > lastIndex) {
3597
- elements.push({ type: "text", text: text.slice(lastIndex, match.index) });
3598
- }
3599
- const [, code, bold, italic, strike, linkUrl, linkText, bareUrl] = match;
3606
+ pushText(text.slice(lastIndex, match.index));
3607
+ }
3608
+ const [
3609
+ ,
3610
+ code,
3611
+ bold,
3612
+ italic,
3613
+ strike,
3614
+ userToken,
3615
+ broadcastToken,
3616
+ linkUrl,
3617
+ linkText,
3618
+ bareUrl,
3619
+ bareUserId,
3620
+ bareBroadcast
3621
+ ] = match;
3600
3622
  if (code != null) {
3601
3623
  elements.push({ type: "text", text: code, style: { code: true } });
3602
3624
  } else if (bold != null) {
@@ -3605,15 +3627,29 @@ function parseInlineElements(text) {
3605
3627
  elements.push({ type: "text", text: italic, style: { italic: true } });
3606
3628
  } else if (strike != null) {
3607
3629
  elements.push({ type: "text", text: strike, style: { strike: true } });
3630
+ } else if (userToken != null) {
3631
+ elements.push({ type: "user", user_id: userToken });
3632
+ } else if (broadcastToken != null) {
3633
+ elements.push({
3634
+ type: "broadcast",
3635
+ range: broadcastToken
3636
+ });
3608
3637
  } else if (linkUrl != null && linkText != null) {
3609
3638
  elements.push({ type: "link", url: linkUrl, text: linkText });
3610
3639
  } else if (bareUrl != null) {
3611
3640
  elements.push({ type: "link", url: bareUrl });
3641
+ } else if (bareUserId != null) {
3642
+ elements.push({ type: "user", user_id: bareUserId });
3643
+ } else if (bareBroadcast != null) {
3644
+ elements.push({
3645
+ type: "broadcast",
3646
+ range: bareBroadcast
3647
+ });
3612
3648
  }
3613
3649
  lastIndex = match.index + match[0].length;
3614
3650
  }
3615
3651
  if (lastIndex < text.length) {
3616
- elements.push({ type: "text", text: text.slice(lastIndex) });
3652
+ pushText(text.slice(lastIndex));
3617
3653
  }
3618
3654
  return elements.length > 0 ? elements : [{ type: "text", text }];
3619
3655
  }
@@ -3736,6 +3772,23 @@ function collectList(input) {
3736
3772
  return idx;
3737
3773
  }
3738
3774
 
3775
+ // src/slack/format-outbound.ts
3776
+ function formatOutboundSlackText(text) {
3777
+ if (!text) {
3778
+ return "";
3779
+ }
3780
+ const stash = [];
3781
+ let out = text.replace(/<(?:@[UWB][A-Z0-9]+(?:\|[^>]*)?|#[CG][A-Z0-9]+(?:\|[^>]*)?|![a-zA-Z]+(?:\|[^>]*)?|https?:\/\/[^>]+)>/g, (m) => {
3782
+ stash.push(m);
3783
+ return `\x00${stash.length - 1}\x00`;
3784
+ });
3785
+ out = out.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
3786
+ out = out.replace(/(^|[^A-Za-z0-9_])@([UWB][A-Z0-9]{6,})\b/g, (_m, pre, id) => `${pre}<@${id}>`);
3787
+ out = out.replace(/(^|[^A-Za-z0-9_])@(here|channel|everyone)\b/g, (_m, pre, name) => `${pre}<!${name}>`);
3788
+ out = out.replace(/\u0000(\d+)\u0000/g, (_m, idx) => stash[Number(idx)]);
3789
+ return out;
3790
+ }
3791
+
3739
3792
  // src/slack/upload.ts
3740
3793
  import { readFile as readFile5, stat, realpath } from "node:fs/promises";
3741
3794
  import { basename as basename2 } from "node:path";
@@ -4595,6 +4648,7 @@ function requireOldestWhenReactionFiltersUsed(input) {
4595
4648
  }
4596
4649
  async function sendMessage(input) {
4597
4650
  const target = parseMsgTarget(String(input.targetInput));
4651
+ const formattedText = formatOutboundSlackText(input.text);
4598
4652
  const blocks = input.text ? textToRichTextBlocks(input.text) : null;
4599
4653
  const attachPaths = normalizeAttachPaths(input.options.attach);
4600
4654
  if (target.kind === "url") {
@@ -4610,7 +4664,7 @@ async function sendMessage(input) {
4610
4664
  client,
4611
4665
  workspaceUrl: workspace_url ?? ref.workspace_url,
4612
4666
  channelId: ref.channel_id,
4613
- text: input.text,
4667
+ text: formattedText,
4614
4668
  blocks,
4615
4669
  threadTs,
4616
4670
  attachPaths
@@ -4629,7 +4683,7 @@ async function sendMessage(input) {
4629
4683
  client,
4630
4684
  workspaceUrl: workspace_url ?? workspaceUrl2,
4631
4685
  channelId: dmChannelId,
4632
- text: input.text,
4686
+ text: formattedText,
4633
4687
  blocks,
4634
4688
  attachPaths
4635
4689
  });
@@ -4650,7 +4704,7 @@ async function sendMessage(input) {
4650
4704
  client,
4651
4705
  workspaceUrl: workspace_url ?? workspaceUrl,
4652
4706
  channelId,
4653
- text: input.text,
4707
+ text: formattedText,
4654
4708
  blocks,
4655
4709
  threadTs: input.options.threadTs ? String(input.options.threadTs) : undefined,
4656
4710
  attachPaths
@@ -4721,6 +4775,7 @@ async function editMessage(input) {
4721
4775
  throw new Error("message edit does not support user ID targets. Use a channel name, channel ID, or message URL.");
4722
4776
  }
4723
4777
  const workspaceUrl = input.ctx.effectiveWorkspaceUrl(input.options.workspace);
4778
+ const formattedText = formatOutboundSlackText(input.text);
4724
4779
  await input.ctx.withAutoRefresh({
4725
4780
  workspaceUrl: target.kind === "url" ? target.ref.workspace_url : workspaceUrl,
4726
4781
  work: async () => {
@@ -4731,7 +4786,7 @@ async function editMessage(input) {
4731
4786
  await client2.api("chat.update", {
4732
4787
  channel: ref.channel_id,
4733
4788
  ts: ref.message_ts,
4734
- text: input.text
4789
+ text: formattedText
4735
4790
  });
4736
4791
  return;
4737
4792
  }
@@ -4745,7 +4800,7 @@ async function editMessage(input) {
4745
4800
  await client.api("chat.update", {
4746
4801
  channel: channelId,
4747
4802
  ts,
4748
- text: input.text
4803
+ text: formattedText
4749
4804
  });
4750
4805
  }
4751
4806
  });
@@ -9185,5 +9240,5 @@ if (subcommand && subcommand !== "update") {
9185
9240
  backgroundUpdateCheck();
9186
9241
  }
9187
9242
 
9188
- //# debugId=5E5A3A0EB875DD7164756E2164756E21
9243
+ //# debugId=DD9BCA0CC3C3B8BA64756E2164756E21
9189
9244
  //# sourceMappingURL=index.js.map