@capybara-hq/plugin-slack 0.1.0-rc.5 → 0.1.0-rc.7

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "name": "slack",
4
- "version": "0.1.0-rc.5",
4
+ "version": "0.1.0-rc.7",
5
5
  "publisher": "Capybara",
6
6
  "description": "Slack (channel@1 bot over Socket Mode with Block Kit cards, identity-source@1 Sign in with Slack, directory@1)",
7
7
  "displayName": {
@@ -31,7 +31,7 @@
31
31
  "entry": "./dist/index.mjs",
32
32
  "manifest": {
33
33
  "name": "slack",
34
- "version": "0.1.0-rc.5",
34
+ "version": "0.1.0-rc.7",
35
35
  "sdk": "^0.1.0-rc.0",
36
36
  "provides": [
37
37
  "channel@1",
package/dist/index.mjs CHANGED
@@ -7355,15 +7355,15 @@ var require_infra = __commonJS({
7355
7355
  return removeChars(str6, leading, trailing, isASCIIWhitespace);
7356
7356
  }
7357
7357
  function removeChars(str6, leading, trailing, predicate) {
7358
- let lead = 0;
7358
+ let lead2 = 0;
7359
7359
  let trail = str6.length - 1;
7360
7360
  if (leading) {
7361
- while (lead < str6.length && predicate(str6.charCodeAt(lead))) lead++;
7361
+ while (lead2 < str6.length && predicate(str6.charCodeAt(lead2))) lead2++;
7362
7362
  }
7363
7363
  if (trailing) {
7364
- while (trail >= lead && predicate(str6.charCodeAt(trail))) trail--;
7364
+ while (trail >= lead2 && predicate(str6.charCodeAt(trail))) trail--;
7365
7365
  }
7366
- return lead === 0 && trail === str6.length - 1 ? str6 : str6.slice(lead, trail + 1);
7366
+ return lead2 === 0 && trail === str6.length - 1 ? str6 : str6.slice(lead2, trail + 1);
7367
7367
  }
7368
7368
  function serializeJavascriptValueToJSONString(value) {
7369
7369
  const result = JSON.stringify(value);
@@ -13737,15 +13737,15 @@ var require_formdata_parser = __commonJS({
13737
13737
  return input.subarray(position.position, position.position = start);
13738
13738
  }
13739
13739
  function removeChars(buf, leading, trailing, predicate) {
13740
- let lead = 0;
13740
+ let lead2 = 0;
13741
13741
  let trail = buf.length - 1;
13742
13742
  if (leading) {
13743
- while (lead < buf.length && predicate(buf[lead])) lead++;
13743
+ while (lead2 < buf.length && predicate(buf[lead2])) lead2++;
13744
13744
  }
13745
13745
  if (trailing) {
13746
13746
  while (trail > 0 && predicate(buf[trail])) trail--;
13747
13747
  }
13748
- return lead === 0 && trail === buf.length - 1 ? buf : buf.subarray(lead, trail + 1);
13748
+ return lead2 === 0 && trail === buf.length - 1 ? buf : buf.subarray(lead2, trail + 1);
13749
13749
  }
13750
13750
  function bufferStartsWith(buffer, start, position) {
13751
13751
  if (buffer.length < start.length) {
@@ -28418,9 +28418,9 @@ var require_sqlite_cache_store = __commonJS({
28418
28418
  let compressed = null;
28419
28419
  let storedBody = body;
28420
28420
  if (body && hasZstd && (size > this.#compressThreshold || isCompressibleContentType(getContentType(value.headers)))) {
28421
- const candidate = zstdCompressSync(body);
28422
- if (candidate.byteLength < body.byteLength) {
28423
- storedBody = candidate;
28421
+ const candidate2 = zstdCompressSync(body);
28422
+ if (candidate2.byteLength < body.byteLength) {
28423
+ storedBody = candidate2;
28424
28424
  compressed = "zstd";
28425
28425
  }
28426
28426
  }
@@ -32641,7 +32641,7 @@ var require_cookies = __commonJS({
32641
32641
  if (!cookies) {
32642
32642
  return [];
32643
32643
  }
32644
- return cookies.map((pair) => parseSetCookie(pair));
32644
+ return cookies.map((pair2) => parseSetCookie(pair2));
32645
32645
  }
32646
32646
  function parseCookie(cookie) {
32647
32647
  cookie = webidl.converters.DOMString(cookie);
@@ -33157,8 +33157,8 @@ var require_util5 = __commonJS({
33157
33157
  const position = { position: 0 };
33158
33158
  const extensionList = /* @__PURE__ */ new Map();
33159
33159
  while (position.position < extensions.length) {
33160
- const pair = collectASequenceOfCodePointsFast(";", extensions, position);
33161
- const [name, value = ""] = pair.split("=", 2);
33160
+ const pair2 = collectASequenceOfCodePointsFast(";", extensions, position);
33161
+ const [name, value = ""] = pair2.split("=", 2);
33162
33162
  extensionList.set(
33163
33163
  removeHTTPWhitespace(name, true, false),
33164
33164
  removeHTTPWhitespace(value, false, true)
@@ -36951,6 +36951,101 @@ import {
36951
36951
  renderCardAsText
36952
36952
  } from "@capybara-hq/plugin-sdk";
36953
36953
 
36954
+ // src/tables.ts
36955
+ var FENCE = /^\s*(```|~~~)/;
36956
+ var DELIM_CELL = /^:?-+:?$/;
36957
+ function splitRow(line) {
36958
+ let s = line.trim();
36959
+ if (!/(^|[^\\])\|/.test(s)) return void 0;
36960
+ if (s.startsWith("|")) s = s.slice(1);
36961
+ if (s.endsWith("|") && !s.endsWith("\\|")) s = s.slice(0, -1);
36962
+ const cells = [];
36963
+ let cur = "";
36964
+ for (let i = 0; i < s.length; i++) {
36965
+ const c = s[i];
36966
+ if (c === "\\" && s[i + 1] === "|") {
36967
+ cur += "|";
36968
+ i++;
36969
+ } else if (c === "|") {
36970
+ cells.push(cur.trim());
36971
+ cur = "";
36972
+ } else cur += c;
36973
+ }
36974
+ cells.push(cur.trim());
36975
+ return cells;
36976
+ }
36977
+ var candidate = (line) => !/^\s{4,}/.test(line) && !/^\s*>/.test(line);
36978
+ function delimiterRow(line, width) {
36979
+ if (line === void 0 || !candidate(line)) return false;
36980
+ const cells = splitRow(line);
36981
+ return cells !== void 0 && cells.length === width && cells.every((c) => DELIM_CELL.test(c));
36982
+ }
36983
+ var fit = (cells, width) => Array.from({ length: width }, (_, i) => cells[i] ?? "");
36984
+ function segmentTables(md2) {
36985
+ const lines = md2.replace(/\r\n?/g, "\n").split("\n");
36986
+ const out = [];
36987
+ let text = [];
36988
+ const flushText = () => {
36989
+ if (text.length > 0) out.push({ kind: "text", lines: text });
36990
+ text = [];
36991
+ };
36992
+ let inFence = false;
36993
+ for (let i = 0; i < lines.length; i++) {
36994
+ const line = lines[i];
36995
+ if (FENCE.test(line)) {
36996
+ inFence = !inFence;
36997
+ text.push(line);
36998
+ continue;
36999
+ }
37000
+ const header = !inFence && candidate(line) ? splitRow(line) : void 0;
37001
+ if (!header || !delimiterRow(lines[i + 1], header.length)) {
37002
+ text.push(line);
37003
+ continue;
37004
+ }
37005
+ const rows = [];
37006
+ let j = i + 2;
37007
+ for (; j < lines.length; j++) {
37008
+ const l = lines[j];
37009
+ if (l.trim() === "" || FENCE.test(l) || !candidate(l)) break;
37010
+ const cells = splitRow(l);
37011
+ if (!cells) break;
37012
+ rows.push(fit(cells, header.length));
37013
+ }
37014
+ flushText();
37015
+ out.push({ kind: "table", table: { header, rows } });
37016
+ i = j - 1;
37017
+ }
37018
+ flushText();
37019
+ return out;
37020
+ }
37021
+ var BR = /<br\s*\/?>/gi;
37022
+ var CJK_END = /[⺀-鿿가-힯豈-﫿＀-￯]$/u;
37023
+ var INDENT = " ";
37024
+ var pair = (h, v) => h === "" ? v : `${h}${CJK_END.test(h) ? ":" : ": "}${v}`;
37025
+ var lead = (cell2) => /`|\*\*|__/.test(cell2) ? cell2 : `**${cell2}**`;
37026
+ function tableToListMarkdown(t) {
37027
+ const clean = (s) => s.replace(BR, " / ").trim();
37028
+ const header = t.header.map(clean);
37029
+ if (t.rows.length === 0) return [header.filter((h) => h !== "").join(" · ")];
37030
+ const out = [];
37031
+ for (const raw of t.rows) {
37032
+ const [first = "", ...rest] = raw.map(clean);
37033
+ const head = first === "" ? "" : lead(first);
37034
+ const items = rest.flatMap((v, i) => v === "" ? [] : [pair(header[i + 1] ?? "", v)]);
37035
+ if (head === "" && items.length === 0) continue;
37036
+ if (header.length === 2) {
37037
+ out.push(`- ${[head, rest[0] ?? ""].filter((s) => s !== "").join(" — ")}`);
37038
+ continue;
37039
+ }
37040
+ out.push(`- ${head === "" ? items.shift() ?? "" : head}`);
37041
+ for (const it of items) out.push(`${INDENT}${it}`);
37042
+ }
37043
+ return out;
37044
+ }
37045
+ function tablesToLists(md2) {
37046
+ return segmentTables(md2).flatMap((s) => s.kind === "text" ? s.lines : tableToListMarkdown(s.table)).join("\n");
37047
+ }
37048
+
36954
37049
  // src/mrkdwn.ts
36955
37050
  var esc = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
36956
37051
  var safeUrl = (url) => url.replace(/&/g, "&amp;").replace(/</g, "%3C").replace(/>/g, "%3E").replace(/\|/g, "%7C");
@@ -36996,7 +37091,7 @@ function convertLine(line) {
36996
37091
  function markdownToMrkdwn(md2) {
36997
37092
  const out = [];
36998
37093
  let inFence = false;
36999
- for (const line of md2.replace(/\r\n?/g, "\n").split("\n")) {
37094
+ for (const line of tablesToLists(md2).split("\n")) {
37000
37095
  if (/^\s*(```|~~~)/.test(line)) {
37001
37096
  out.push("```");
37002
37097
  inFence = !inFence;
@@ -37066,6 +37161,103 @@ function splitMrkdwn(text, limit) {
37066
37161
  return out;
37067
37162
  }
37068
37163
 
37164
+ // src/table-block.ts
37165
+ var TABLE_MAX_ROWS = 100;
37166
+ var TABLE_MAX_COLUMNS = 20;
37167
+ var TABLE_MAX_CHARS = 1e4;
37168
+ var EMPTY = " ";
37169
+ function withStyle(e, style) {
37170
+ return Object.keys(style).length === 0 ? e : { ...e, style: { ...e.style, ...style } };
37171
+ }
37172
+ var EMPHASIS = /\*\*\*(\S(?:.*?\S)?)\*\*\*|\*\*(\S(?:.*?\S)?)\*\*|(?<!\w)__(\S(?:.*?\S)?)__(?!\w)|(?<![\w*])\*(?=[^\s*])([^*]*?[^\s*])\*(?![\w*])|(?<![\w_])_(?=[^\s_])([^_]*?[^\s_])_(?![\w_])|~~(\S(?:.*?\S)?)~~/;
37173
+ function emphasis(s, style) {
37174
+ const out = [];
37175
+ let rest = s;
37176
+ while (rest !== "") {
37177
+ const m = EMPHASIS.exec(rest);
37178
+ if (!m) break;
37179
+ if (m.index > 0)
37180
+ out.push(withStyle({ type: "text", text: rest.slice(0, m.index) }, style));
37181
+ const [, bi, b, b2, i, i2, st] = m;
37182
+ if (bi !== void 0) out.push(...emphasis(bi, { ...style, bold: true, italic: true }));
37183
+ else if (b !== void 0 || b2 !== void 0)
37184
+ out.push(...emphasis(b ?? b2, { ...style, bold: true }));
37185
+ else if (i !== void 0 || i2 !== void 0)
37186
+ out.push(...emphasis(i ?? i2, { ...style, italic: true }));
37187
+ else out.push(...emphasis(st, { ...style, strike: true }));
37188
+ rest = rest.slice(m.index + m[0].length);
37189
+ }
37190
+ if (rest !== "") out.push(withStyle({ type: "text", text: rest }, style));
37191
+ return out;
37192
+ }
37193
+ var LINK = /\[([^\]\n]+)\]\(((?:https?:\/\/|mailto:)[^\s)]+)\)|<((?:https?:\/\/|mailto:)[^>\s]+)>/;
37194
+ function links(s) {
37195
+ const out = [];
37196
+ let rest = s;
37197
+ for (let m = LINK.exec(rest); m; m = LINK.exec(rest)) {
37198
+ out.push(...emphasis(rest.slice(0, m.index), {}));
37199
+ const url = m[2] ?? m[3];
37200
+ if (m[1] === void 0) out.push({ type: "link", url, text: url });
37201
+ else
37202
+ for (const e of emphasis(m[1], {})) {
37203
+ const { code: _code, ...style } = e.style ?? {};
37204
+ out.push(withStyle({ type: "link", url, text: e.text }, style));
37205
+ }
37206
+ rest = rest.slice(m.index + m[0].length);
37207
+ }
37208
+ out.push(...emphasis(rest, {}));
37209
+ return out;
37210
+ }
37211
+ function cellElements(md2) {
37212
+ const out = [];
37213
+ let last = 0;
37214
+ for (const m of md2.matchAll(/`([^`\n]+)`/g)) {
37215
+ out.push(...links(md2.slice(last, m.index)));
37216
+ out.push({ type: "text", text: m[1], style: { code: true } });
37217
+ last = m.index + m[0].length;
37218
+ }
37219
+ out.push(...links(md2.slice(last)));
37220
+ return out.filter((e) => e.text !== "");
37221
+ }
37222
+ var cellText = (md2) => cellElements(md2.replace(/<br\s*\/?>/gi, "\n")).map((e) => e.text).join("");
37223
+ function cell(md2, header) {
37224
+ const els = cellElements(md2.replace(/<br\s*\/?>/gi, "\n")).map(
37225
+ (e) => header ? withStyle(e, { bold: true }) : e
37226
+ );
37227
+ if (els.length === 0) return { type: "raw_text", text: EMPTY };
37228
+ if (els.every((e) => e.type === "text" && e.style === void 0)) {
37229
+ return { type: "raw_text", text: els.map((e) => e.text).join("") };
37230
+ }
37231
+ return { type: "rich_text", elements: [{ type: "rich_text_section", elements: els }] };
37232
+ }
37233
+ var rowChars = (row) => row.reduce((n, c) => n + Math.max(cellText(c).length, 1), 0);
37234
+ function tableBlocks(t) {
37235
+ const width = t.header.length;
37236
+ if (width > TABLE_MAX_COLUMNS || t.rows.length === 0) return void 0;
37237
+ const headChars = rowChars(t.header);
37238
+ const groups = [];
37239
+ let cur = [];
37240
+ let chars = headChars;
37241
+ for (const row of t.rows) {
37242
+ const n = rowChars(row);
37243
+ if (headChars + n > TABLE_MAX_CHARS) return void 0;
37244
+ if (cur.length > 0 && (cur.length + 1 >= TABLE_MAX_ROWS || chars + n > TABLE_MAX_CHARS)) {
37245
+ groups.push(cur);
37246
+ cur = [];
37247
+ chars = headChars;
37248
+ }
37249
+ cur.push(row);
37250
+ chars += n;
37251
+ }
37252
+ groups.push(cur);
37253
+ const column_settings = Array.from({ length: width }, () => ({ is_wrapped: true }));
37254
+ return groups.map((rows) => ({
37255
+ type: "table",
37256
+ column_settings,
37257
+ rows: [t.header.map((c) => cell(c, true)), ...rows.map((r) => r.map((c) => cell(c, false)))]
37258
+ }));
37259
+ }
37260
+
37069
37261
  // src/blocks.ts
37070
37262
  var TEXT_LIMIT = 4e3;
37071
37263
  var SECTION_TEXT_LIMIT = 3e3;
@@ -37363,16 +37555,50 @@ function cardHeadline(card, locale) {
37363
37555
  }
37364
37556
  }
37365
37557
  function renderSend(message2, locale) {
37366
- const mrkdwn = markdownToMrkdwn(message2.text);
37367
- const cards = message2.cards ?? [];
37558
+ const posts = [];
37559
+ let pending = [];
37560
+ for (const seg of segmentTables(message2.text)) {
37561
+ const tables = seg.kind === "table" ? tableBlocks(seg.table) : void 0;
37562
+ if (seg.kind === "text" || !tables) {
37563
+ pending.push(...seg.kind === "text" ? seg.lines : tableToListMarkdown(seg.table));
37564
+ continue;
37565
+ }
37566
+ const list = markdownToMrkdwn(tableToListMarkdown(seg.table).join("\n"));
37567
+ tables.forEach((table2, i) => {
37568
+ const lead2 = i === 0 ? markdownToMrkdwn(trimBlank(pending).join("\n")) : "";
37569
+ const chunks = lead2.trim() === "" ? [] : splitMrkdwn(lead2, SECTION_TEXT_LIMIT);
37570
+ const last = chunks.pop();
37571
+ posts.push(...chunks.map((text) => ({ text })));
37572
+ const full = [last, list].filter((t) => t !== void 0 && t.trim() !== "").join("\n\n");
37573
+ posts.push({
37574
+ text: trunc(full, TEXT_LIMIT),
37575
+ blocks: [...last !== void 0 ? [section(last)] : [], table2],
37576
+ fallback: splitMrkdwn(full, TEXT_LIMIT).map((text) => ({ text }))
37577
+ });
37578
+ });
37579
+ pending = [];
37580
+ }
37581
+ const rest = (posts.length > 0 ? trimBlank(pending) : pending).join("\n");
37582
+ const trailing = posts.length > 0 ? rest : message2.text;
37583
+ return [...posts, ...renderText(rest, trailing, message2.cards ?? [], locale, posts.length > 0)];
37584
+ }
37585
+ function trimBlank(lines) {
37586
+ let a = 0;
37587
+ let b = lines.length;
37588
+ while (a < b && (lines[a] ?? "").trim() === "") a++;
37589
+ while (b > a && (lines[b - 1] ?? "").trim() === "") b--;
37590
+ return lines.slice(a, b);
37591
+ }
37592
+ function renderText(md2, headlineText, cards, locale, afterTable) {
37593
+ const mrkdwn = markdownToMrkdwn(md2);
37368
37594
  if (cards.length === 0) {
37369
- if (mrkdwn.trim() === "") return [{ text: "…" }];
37595
+ if (mrkdwn.trim() === "") return afterTable ? [] : [{ text: "…" }];
37370
37596
  return splitMrkdwn(mrkdwn, TEXT_LIMIT).map((text) => ({ text }));
37371
37597
  }
37372
37598
  const chunks = mrkdwn.trim() === "" ? [] : splitMrkdwn(mrkdwn, SECTION_TEXT_LIMIT);
37373
37599
  const last = chunks.pop();
37374
37600
  const posts = chunks.map((text) => ({ text }));
37375
- const dup = cards.some((c) => cardHeadline(c, locale)?.trim() === message2.text.trim());
37601
+ const dup = cards.some((c) => cardHeadline(c, locale)?.trim() === headlineText.trim());
37376
37602
  const blocks = last !== void 0 && !dup ? [section(last)] : [];
37377
37603
  cards.forEach((c, i) => {
37378
37604
  if (i > 0) blocks.push({ type: "divider" });
@@ -37551,6 +37777,11 @@ function toChannelSendError(e) {
37551
37777
  return new ChannelSendError2("Slack API call failed", { retryable: true, cause: e });
37552
37778
  }
37553
37779
  }
37780
+ function blocksRejected(e) {
37781
+ const cause = e instanceof ChannelSendError2 ? e.cause : e;
37782
+ const code = platformErrorCode(cause);
37783
+ return code === "invalid_blocks" || code === "invalid_blocks_format" || code === "invalid_attachments";
37784
+ }
37554
37785
 
37555
37786
  // src/inbound.ts
37556
37787
  var obj2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v) ? v : void 0;
@@ -37738,7 +37969,8 @@ var SlackConnection = z2.object({
37738
37969
  zh: "xapp-…,Socket Mode 必填(Basic Information → App-Level Tokens,权限 connections:write)。",
37739
37970
  en: "xapp-…, required for Socket Mode (Basic Information → App-Level Tokens, scope connections:write)."
37740
37971
  },
37741
- placeholder: "xapp-…"
37972
+ placeholder: "xapp-…",
37973
+ inboundModes: ["long_connection"]
37742
37974
  }
37743
37975
  ),
37744
37976
  botToken: ui2(secret2(z2.string().regex(/^xoxb-/, "must be a bot token starting with xoxb-")), {
@@ -37752,9 +37984,10 @@ var SlackConnection = z2.object({
37752
37984
  signingSecret: ui2(secret2(z2.string().min(1).optional()), {
37753
37985
  label: { zh: "签名密钥", en: "Signing secret" },
37754
37986
  help: {
37755
- zh: "仅 webhook 模式需要;Socket Mode 留空。",
37756
- en: "Only needed in webhook mode; leave empty for Socket Mode."
37757
- }
37987
+ zh: "Basic Information → App Credentials → Signing Secret,用来校验 Slack 发来的每个请求。",
37988
+ en: "Basic Information → App Credentials → Signing Secret; every request from Slack is verified with it."
37989
+ },
37990
+ inboundModes: ["webhook"]
37758
37991
  })
37759
37992
  });
37760
37993
  var SOCKET_MODE_NEEDS_APP_TOKEN = "Socket Mode needs an app-level token (xapp-…); set one or switch this connection to webhook mode";
@@ -38187,10 +38420,9 @@ function createSlackChannel(opts) {
38187
38420
  const client = web(c.botToken, signal);
38188
38421
  const threadTs = threadTsOf(target);
38189
38422
  let last;
38190
- for (const p of renderSend(message2, locale)) {
38191
- let r;
38423
+ const post = async (p) => {
38192
38424
  try {
38193
- r = await client.apiCall("chat.postMessage", {
38425
+ return await client.apiCall("chat.postMessage", {
38194
38426
  channel: target.chatId,
38195
38427
  text: p.text,
38196
38428
  ...p.blocks !== void 0 && { blocks: p.blocks },
@@ -38199,13 +38431,27 @@ function createSlackChannel(opts) {
38199
38431
  } catch (e) {
38200
38432
  throw toChannelSendError(e);
38201
38433
  }
38202
- if (!r.ts) {
38203
- throw new ChannelSendError3("Slack returned no message ts", {
38204
- retryable: false,
38205
- reason: "rejected"
38434
+ };
38435
+ for (const p of renderSend(message2, locale)) {
38436
+ const sent = [];
38437
+ try {
38438
+ sent.push(await post(p));
38439
+ } catch (e) {
38440
+ if (!p.fallback || !blocksRejected(e)) throw e;
38441
+ log.warn("slack: Slack rejected a table block; the table is sent as a list", {
38442
+ error: e instanceof Error ? e.message : String(e)
38206
38443
  });
38444
+ for (const f of p.fallback) sent.push(await post(f));
38445
+ }
38446
+ for (const r of sent) {
38447
+ if (!r.ts) {
38448
+ throw new ChannelSendError3("Slack returned no message ts", {
38449
+ retryable: false,
38450
+ reason: "rejected"
38451
+ });
38452
+ }
38453
+ last = `${r.channel ?? target.chatId}:${r.ts}`;
38207
38454
  }
38208
- last = `${r.channel ?? target.chatId}:${r.ts}`;
38209
38455
  }
38210
38456
  if (last === void 0) throw new ChannelSendError3("nothing to send", { retryable: false });
38211
38457
  return { messageId: last };
@@ -38214,15 +38460,33 @@ function createSlackChannel(opts) {
38214
38460
  const p = renderUpdate(message2, locale);
38215
38461
  const { channel, ts } = parseMessageId(messageId);
38216
38462
  const c = parse(config);
38463
+ const edit = async (q) => {
38464
+ try {
38465
+ await web(c.botToken, signal).apiCall("chat.update", {
38466
+ channel,
38467
+ ts,
38468
+ text: q.text,
38469
+ ...q.blocks !== void 0 && { blocks: q.blocks }
38470
+ });
38471
+ } catch (e) {
38472
+ throw toChannelSendError(e);
38473
+ }
38474
+ };
38217
38475
  try {
38218
- await web(c.botToken, signal).apiCall("chat.update", {
38219
- channel,
38220
- ts,
38221
- text: p.text,
38222
- ...p.blocks !== void 0 && { blocks: p.blocks }
38223
- });
38476
+ await edit(p);
38224
38477
  } catch (e) {
38225
- throw toChannelSendError(e);
38478
+ if (!p.fallback || !blocksRejected(e)) throw e;
38479
+ const only = p.fallback.length === 1 ? p.fallback[0] : void 0;
38480
+ if (!only) {
38481
+ throw new ChannelSendError3("message too long for a single Slack message", {
38482
+ retryable: false,
38483
+ reason: "too_large"
38484
+ });
38485
+ }
38486
+ log.warn("slack: Slack rejected a table block; the table is sent as a list", {
38487
+ error: e instanceof Error ? e.message : String(e)
38488
+ });
38489
+ await edit(only);
38226
38490
  }
38227
38491
  }
38228
38492
  };
@@ -39511,7 +39775,7 @@ function appTokenCheck(opts) {
39511
39775
  // src/index.ts
39512
39776
  var index_default = defineExtension({
39513
39777
  name: "slack",
39514
- version: "0.1.0-rc.5",
39778
+ version: "0.1.0-rc.7",
39515
39779
  sdk: "^0.1.0-rc.0",
39516
39780
  provides: [CHANNEL_EXTENSION_POINT, IDENTITY_SOURCE_EXTENSION_POINT, DIRECTORY_EXTENSION_POINT],
39517
39781
  permissions: {
@@ -8,11 +8,11 @@ app after step 2).
8
8
  ## 1. Create the app from the manifest
9
9
 
10
10
  Open <https://api.slack.com/apps>, choose **Create New App → From a manifest**, pick your
11
- workspace and paste the manifest below. It registers the bot scopes, the events and the slash
12
- commands the plugin needs.
11
+ workspace and paste the manifest below.
13
12
 
14
13
  ::: mode long_connection
15
- Socket Mode needs no public address: Slack keeps a connection open to Capybara.
14
+ Socket Mode needs no public address: Slack keeps a connection open to Capybara. The manifest
15
+ registers the bot scopes, the events and the slash commands the plugin needs.
16
16
 
17
17
  ```yaml title="App manifest (Socket Mode)"
18
18
  # Slack app manifest for the Capybara Slack plugin, Socket Mode (long connection).
@@ -28,7 +28,7 @@ features:
28
28
  messages_tab_enabled: true
29
29
  messages_tab_read_only_enabled: false
30
30
  bot_user:
31
- display_name: capybara
31
+ display_name: Capybara
32
32
  always_online: true
33
33
  slash_commands:
34
34
  - command: /new
@@ -72,7 +72,53 @@ settings:
72
72
  org_deploy_enabled: false
73
73
  token_rotation_enabled: false
74
74
  ```
75
+ :::
76
+
77
+ ::: mode webhook
78
+ In webhook mode Slack posts events, card clicks and slash commands to this connection's address,
79
+ which exists only once the connection is saved. Start with this basic manifest: it registers the
80
+ bot and its scopes, without any address. Step 5 adds the addresses after saving.
75
81
 
82
+ ```yaml title="Basic app manifest (webhook)"
83
+ # Slack app manifest for the Capybara Slack plugin, webhook inbound mode, first step: no
84
+ # addresses yet. Step 5 replaces it with the full manifest once the connection is saved.
85
+ # Reference: https://docs.slack.dev/reference/app-manifest (checked 2026-11-09).
86
+ display_information:
87
+ # Slack caps app names at 35 characters; shorten it in the app settings if it is longer.
88
+ name: "{{connectionName}}"
89
+ description: Chat with your organization's Capybara agents.
90
+ background_color: "#3d2f24"
91
+ features:
92
+ app_home:
93
+ home_tab_enabled: false
94
+ messages_tab_enabled: true
95
+ messages_tab_read_only_enabled: false
96
+ bot_user:
97
+ display_name: Capybara
98
+ always_online: true
99
+ oauth_config:
100
+ # Sign in with Slack (identity-source@1).
101
+ redirect_urls:
102
+ - "{{signInCallbackUrl}}"
103
+ scopes:
104
+ bot:
105
+ - chat:write # post and update replies and cards
106
+ - commands # slash commands /new, /env, /capybara
107
+ - im:write # conversations.open: tell the bot's own DM from other DMs
108
+ - im:history # message.im: direct messages to the bot
109
+ - app_mentions:read # app_mention: @capybara in channels
110
+ - channels:history # message.channels: thread replies in public channels
111
+ - groups:history # message.groups: thread replies in private channels
112
+ - users:read # users.info; team_join / user_change; users.list
113
+ - users:read.email # directory@1: email addresses in users.list
114
+ settings:
115
+ socket_mode_enabled: false
116
+ org_deploy_enabled: false
117
+ token_rotation_enabled: false
118
+ ```
119
+ :::
120
+
121
+ ::: mode long_connection
76
122
  ## 2. Create the app-level token
77
123
 
78
124
  Under **Basic Information → App-Level Tokens** choose **Generate Token and Scopes**, add the scope
@@ -82,8 +128,32 @@ Under **Basic Information → App-Level Tokens** choose **Generate Token and Sco
82
128
  :::
83
129
 
84
130
  ::: mode webhook
85
- In webhook mode Slack posts events, card clicks and slash commands to this connection's address
86
- and checks it when you save.
131
+ ## 2. Copy the signing secret
132
+
133
+ Copy **Basic Information → App Credentials → Signing Secret** into the **Signing secret** field
134
+ below. Every webhook request is verified with it; without it every request is refused.
135
+ :::
136
+
137
+ ## 3. Install the app and copy the bot token
138
+
139
+ Choose **Install App → Install to Workspace** and copy the **Bot User OAuth Token** (`xoxb-…`)
140
+ into the **Bot token** field below.
141
+
142
+ ::check bot-token Bot token works
143
+ ::check bot-scopes The app has every scope in the manifest
144
+
145
+ ## 4. Save the channel
146
+
147
+ Fill in the remaining fields on this page and save. Capybara verifies the bot token when you save.
148
+ With Socket Mode that is all: the bot connects and is ready for messages.
149
+
150
+ ::: mode webhook
151
+ ## 5. Point Slack at this connection
152
+
153
+ After saving, the manifest below carries this connection's address `{{webhookUrl}}` (before saving
154
+ it is shown as written). In the app open **App Manifest**, replace the manifest with this one and
155
+ save. It adds the slash commands, the event subscriptions and interactivity, all sent to this
156
+ address.
87
157
 
88
158
  ```yaml title="App manifest (webhook)"
89
159
  # Slack app manifest for the Capybara Slack plugin, webhook inbound mode.
@@ -99,7 +169,7 @@ features:
99
169
  messages_tab_enabled: true
100
170
  messages_tab_read_only_enabled: false
101
171
  bot_user:
102
- display_name: capybara
172
+ display_name: Capybara
103
173
  always_online: true
104
174
  slash_commands:
105
175
  - command: /new
@@ -149,27 +219,14 @@ settings:
149
219
  token_rotation_enabled: false
150
220
  ```
151
221
 
152
- Slack checks the Request URL `{{webhookUrl}}` when you create the app or save **Event
153
- Subscriptions**, and Capybara answers the check, so the channel connection must be saved first.
154
- If Slack reports the URL unverified, save the connection here, then retry under **Event
155
- Subscriptions**.
156
-
157
- ## 2. Copy the signing secret
158
-
159
- Copy **Basic Information → App Credentials → Signing Secret** into the **Signing secret** field
160
- below. Every webhook request is verified with it; without it every request is refused.
222
+ Slack verifies the Request URL when you save, and Capybara answers because the connection now
223
+ exists. Reinstall the app if Slack asks.
161
224
 
162
225
  ::check capybara:webhook-public Webhook address is reachable from the internet
163
226
  ::check capybara:webhook-received Slack has delivered a signed request
164
227
  :::
165
228
 
166
- ## 3. Install the app and copy the bot token
167
-
168
- Choose **Install App → Install to Workspace** and copy the **Bot User OAuth Token** (`xoxb-…`)
169
- into the **Bot token** field below.
170
-
171
- ::check bot-token Bot token works
172
- ::check bot-scopes The app has every scope in the manifest
229
+ ---
173
230
 
174
231
  ## Sign in with Slack
175
232
 
@@ -7,10 +7,11 @@
7
7
  ## 1. 用 manifest 创建应用
8
8
 
9
9
  打开 <https://api.slack.com/apps>,选择 **Create New App → From a manifest**,选中你的工作区,
10
- 粘贴下面的 manifest。它会登记插件需要的机器人权限、事件和斜杠命令。
10
+ 粘贴下面的 manifest。
11
11
 
12
12
  ::: mode long_connection
13
- Socket Mode 不需要公网地址:由 Slack 与 Capybara 之间保持一条长连接。
13
+ Socket Mode 不需要公网地址:由 Slack 与 Capybara 之间保持一条长连接。这份 manifest 会登记插件需要的
14
+ 机器人权限、事件和斜杠命令。
14
15
 
15
16
  ```yaml title="应用 manifest(Socket Mode)"
16
17
  # Slack app manifest for the Capybara Slack plugin, Socket Mode (long connection).
@@ -26,7 +27,7 @@ features:
26
27
  messages_tab_enabled: true
27
28
  messages_tab_read_only_enabled: false
28
29
  bot_user:
29
- display_name: capybara
30
+ display_name: Capybara
30
31
  always_online: true
31
32
  slash_commands:
32
33
  - command: /new
@@ -70,7 +71,52 @@ settings:
70
71
  org_deploy_enabled: false
71
72
  token_rotation_enabled: false
72
73
  ```
74
+ :::
75
+
76
+ ::: mode webhook
77
+ Webhook 模式下,Slack 把事件、卡片点击和斜杠命令发到这个渠道连接的地址,而这个地址要等连接保存后
78
+ 才存在。先用这份基础 manifest:它只登记机器人和权限,不含任何地址。保存之后,第 5 步再补上地址。
73
79
 
80
+ ```yaml title="基础应用 manifest(Webhook)"
81
+ # Slack app manifest for the Capybara Slack plugin, webhook inbound mode, first step: no
82
+ # addresses yet. Step 5 replaces it with the full manifest once the connection is saved.
83
+ # Reference: https://docs.slack.dev/reference/app-manifest (checked 2026-11-09).
84
+ display_information:
85
+ # Slack caps app names at 35 characters; shorten it in the app settings if it is longer.
86
+ name: "{{connectionName}}"
87
+ description: Chat with your organization's Capybara agents.
88
+ background_color: "#3d2f24"
89
+ features:
90
+ app_home:
91
+ home_tab_enabled: false
92
+ messages_tab_enabled: true
93
+ messages_tab_read_only_enabled: false
94
+ bot_user:
95
+ display_name: Capybara
96
+ always_online: true
97
+ oauth_config:
98
+ # Sign in with Slack (identity-source@1).
99
+ redirect_urls:
100
+ - "{{signInCallbackUrl}}"
101
+ scopes:
102
+ bot:
103
+ - chat:write # post and update replies and cards
104
+ - commands # slash commands /new, /env, /capybara
105
+ - im:write # conversations.open: tell the bot's own DM from other DMs
106
+ - im:history # message.im: direct messages to the bot
107
+ - app_mentions:read # app_mention: @capybara in channels
108
+ - channels:history # message.channels: thread replies in public channels
109
+ - groups:history # message.groups: thread replies in private channels
110
+ - users:read # users.info; team_join / user_change; users.list
111
+ - users:read.email # directory@1: email addresses in users.list
112
+ settings:
113
+ socket_mode_enabled: false
114
+ org_deploy_enabled: false
115
+ token_rotation_enabled: false
116
+ ```
117
+ :::
118
+
119
+ ::: mode long_connection
74
120
  ## 2. 创建应用级令牌
75
121
 
76
122
  在 **Basic Information → App-Level Tokens** 选择 **Generate Token and Scopes**,添加权限
@@ -80,7 +126,30 @@ settings:
80
126
  :::
81
127
 
82
128
  ::: mode webhook
83
- Webhook 模式下,Slack 把事件、卡片点击和斜杠命令发到这个渠道连接的地址,并在保存时校验该地址。
129
+ ## 2. 复制签名密钥
130
+
131
+ 把 **Basic Information → App Credentials → Signing Secret** 填进下方的 **签名密钥**。每个 webhook
132
+ 请求都用它校验;不填则所有请求都会被拒绝。
133
+ :::
134
+
135
+ ## 3. 安装应用并复制机器人令牌
136
+
137
+ 选择 **Install App → Install to Workspace**,把 **Bot User OAuth Token**(`xoxb-…`)填进下方的
138
+ **机器人令牌**。
139
+
140
+ ::check bot-token 机器人令牌可用
141
+ ::check bot-scopes 应用具备 manifest 中的全部权限
142
+
143
+ ## 4. 保存渠道
144
+
145
+ 填好本页其余字段并保存,保存时 Capybara 会校验机器人令牌。使用 Socket Mode 时到这里就完成了:机器人
146
+ 会自动连上,可以开始收消息。
147
+
148
+ ::: mode webhook
149
+ ## 5. 让 Slack 指向这个连接
150
+
151
+ 保存之后,下面的 manifest 会带上这个连接的地址 `{{webhookUrl}}`(保存前按原样显示)。在应用里打开
152
+ **App Manifest**,用这份 manifest 整体替换并保存。它会加上斜杠命令、事件订阅和交互,全部发往这个地址。
84
153
 
85
154
  ```yaml title="应用 manifest(Webhook)"
86
155
  # Slack app manifest for the Capybara Slack plugin, webhook inbound mode.
@@ -96,7 +165,7 @@ features:
96
165
  messages_tab_enabled: true
97
166
  messages_tab_read_only_enabled: false
98
167
  bot_user:
99
- display_name: capybara
168
+ display_name: Capybara
100
169
  always_online: true
101
170
  slash_commands:
102
171
  - command: /new
@@ -146,26 +215,13 @@ settings:
146
215
  token_rotation_enabled: false
147
216
  ```
148
217
 
149
- 创建应用或保存 **Event Subscriptions** 时,Slack 会校验 Request URL `{{webhookUrl}}`,由 Capybara
150
- 应答校验,所以要先保存渠道连接。若 Slack 提示地址未通过校验,先在这里保存连接,再到
151
- **Event Subscriptions** 重试。
152
-
153
- ## 2. 复制签名密钥
154
-
155
- 把 **Basic Information → App Credentials → Signing Secret** 填进下方的 **签名密钥**。每个 webhook
156
- 请求都用它校验;不填则所有请求都会被拒绝。
218
+ 保存时 Slack 会校验 Request URL;连接已经存在,Capybara 会应答校验。Slack 要求时重新安装应用。
157
219
 
158
220
  ::check capybara:webhook-public Webhook 地址可从公网访问
159
221
  ::check capybara:webhook-received Slack 已送达一个签名有效的请求
160
222
  :::
161
223
 
162
- ## 3. 安装应用并复制机器人令牌
163
-
164
- 选择 **Install App → Install to Workspace**,把 **Bot User OAuth Token**(`xoxb-…`)填进下方的
165
- **机器人令牌**。
166
-
167
- ::check bot-token 机器人令牌可用
168
- ::check bot-scopes 应用具备 manifest 中的全部权限
224
+ ---
169
225
 
170
226
  ## Slack 登录
171
227
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-slack",
3
- "version": "0.1.0-rc.5",
3
+ "version": "0.1.0-rc.7",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "description": "Slack (channel@1 bot over Socket Mode with Block Kit cards, identity-source@1 Sign in with Slack, directory@1)",