@desplega.ai/agent-swarm 2.7.9 → 2.7.10
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/{acp-adapter-dn4gdsgr.js → acp-adapter-srfhs1s9.js} +5 -5
- package/dist/{actions-g563mbn2.js → actions-b8aqhrsg.js} +19 -18
- package/dist/{amp-adapter-q61w05eb.js → amp-adapter-4c165vgn.js} +1 -1
- package/dist/app-m9khefrh.js +20 -0
- package/dist/{assistant-p477rjwj.js → assistant-rh4v3ntz.js} +21 -20
- package/dist/{boot-args-schema-h4qj462e.js → boot-args-schema-hwkc8bzv.js} +1 -1
- package/dist/{boot-reembed-n1ehfbsw.js → boot-reembed-5y6yw9sj.js} +1 -1
- package/dist/{boot-reembed-qw4mc0pt.js → boot-reembed-fdyk55h4.js} +1 -1
- package/dist/{boot-scrub-sweep-9w9jp4sm.js → boot-scrub-sweep-r5r8kqsn.js} +3 -3
- package/dist/{boot-seeds-qdaf3sdy.js → boot-seeds-8f9zt5cm.js} +5 -5
- package/dist/{claude-adapter-348p5hx9.js → claude-adapter-s5df247c.js} +5 -5
- package/dist/{claude-managed-setup-7787fxtp.js → claude-managed-setup-9gsmwzyx.js} +1 -1
- package/dist/{claude-sdk-session-hbszbt8a.js → claude-sdk-session-dq1j4nz9.js} +5 -5
- package/dist/{cli-btf6fw39.js → cli-0m7rtm11.js} +1 -1
- package/dist/{cli-cseh6f8w.js → cli-16phend6.js} +1 -1
- package/dist/{cli-ms5m5r1y.js → cli-18qt3few.js} +1 -1
- package/dist/{cli-sgs5k6yd.js → cli-2tsfpc70.js} +1 -1
- package/dist/{cli-rwymrnaz.js → cli-36wdfzgn.js} +8 -8
- package/dist/{cli-qzt90yze.js → cli-38yww4e9.js} +8 -8
- package/dist/{cli-2a8py3sx.js → cli-3xddv0rk.js} +4 -4
- package/dist/{cli-p0m0p34z.js → cli-4vwxp550.js} +2 -2
- package/dist/{cli-bc779n4v.js → cli-55bkx8hh.js} +1 -1
- package/dist/{cli-21159vea.js → cli-5wfz00be.js} +2 -2
- package/dist/{cli-9aezs55w.js → cli-5xcb8gxq.js} +4 -4
- package/dist/{cli-12xyjhws.js → cli-6m6b4bep.js} +2 -2
- package/dist/{cli-fayav105.js → cli-7wz05bx3.js} +292 -83
- package/dist/{cli-y8nbefpb.js → cli-8ewkreqd.js} +9 -5
- package/dist/{cli-0whpms1z.js → cli-an1knn2k.js} +4 -4
- package/dist/{cli-qmd3mse0.js → cli-bxz823sz.js} +1 -1
- package/dist/{cli-a0657jmf.js → cli-bzvs88tv.js} +1 -1
- package/dist/{cli-agyaeef4.js → cli-cr14kftt.js} +2 -2
- package/dist/{cli-715t1gx6.js → cli-eb2azq8n.js} +3 -3
- package/dist/{cli-530hkwdy.js → cli-ed6yqpf1.js} +2 -2
- package/dist/{cli-k70e3x9e.js → cli-eqk5p56g.js} +3 -3
- package/dist/{cli-4t0fmf3z.js → cli-g1px1g2e.js} +1 -1
- package/dist/{cli-09kmfkmq.js → cli-h49ejvmc.js} +1 -1
- package/dist/{cli-cvs2r2vq.js → cli-hfkwwy1h.js} +39 -5
- package/dist/{cli-neyag5p6.js → cli-j7d73g1y.js} +371 -116
- package/dist/{cli-p17970qv.js → cli-jg24scat.js} +2 -2
- package/dist/{cli-varqt4d1.js → cli-kx4c8j05.js} +16 -13
- package/dist/{cli-jfx48xrj.js → cli-mp9aa8g5.js} +1 -1
- package/dist/{cli-605nn699.js → cli-mr97t7cc.js} +644 -225
- package/dist/{cli-v3cf1ts9.js → cli-n07eecjs.js} +3 -3
- package/dist/{cli-y5rbvxhc.js → cli-n515ex5z.js} +14 -14
- package/dist/{cli-3tqcamp6.js → cli-n9abj89w.js} +13 -12
- package/dist/{cli-ypff1qwp.js → cli-n9ftpys4.js} +7 -7
- package/dist/{cli-xk879m3k.js → cli-nj3x45rw.js} +27 -27
- package/dist/{cli-9r5gtwjr.js → cli-pyrxt9gw.js} +196 -1
- package/dist/{cli-mnrkgg60.js → cli-q581b386.js} +2 -2
- package/dist/{cli-hwprv9e4.js → cli-rjyghzg4.js} +2 -2
- package/dist/{cli-650zv9q9.js → cli-rt0ag4x1.js} +3 -3
- package/dist/{cli-vxh6acp7.js → cli-td33w98c.js} +2 -2
- package/dist/{cli-tqq0hspb.js → cli-tmft5dz2.js} +1 -1
- package/dist/{cli-q26b9wre.js → cli-tph5wt3y.js} +4 -4
- package/dist/{cli-qkdmz8c8.js → cli-ttbqe3q4.js} +1 -1
- package/dist/{cli-zgv8gxgs.js → cli-v2fwbnsk.js} +6 -6
- package/dist/{cli-b932gexn.js → cli-w3bk0dgv.js} +1 -1
- package/dist/{cli-serm8zrx.js → cli-x9exydey.js} +1 -1
- package/dist/{cli-hae9j8sv.js → cli-xbtq4d6s.js} +3 -3
- package/dist/{cli-587857ys.js → cli-xd5ebp64.js} +3 -3
- package/dist/{cli-ejkvvqbe.js → cli-xncjscpm.js} +10 -10
- package/dist/{cli-gce09r66.js → cli-xvymtmv4.js} +2 -2
- package/dist/{cli-btc9cb4c.js → cli-yz7v0sh4.js} +2 -2
- package/dist/{cli-sya22y84.js → cli-z9cs5m0w.js} +3 -3
- package/dist/{cli-2ccpqyyf.js → cli-zjphdj1a.js} +71 -10
- package/dist/cli.js +15 -15
- package/dist/{codex-adapter-ysq6bzha.js → codex-adapter-yr60sme6.js} +3 -3
- package/dist/{codex-session-runner-qakzfx93.js → codex-session-runner-pch8x584.js} +3 -3
- package/dist/{commands-rs7hkv9r.js → commands-phjfbkv0.js} +3 -3
- package/dist/{controller-r5x9bg6e.js → controller-jkx994pz.js} +2 -2
- package/dist/{controllers-connect-498hrxvk.js → controllers-connect-c4448kwa.js} +20 -19
- package/dist/{cursor-adapter-d46qszer.js → cursor-adapter-ndebqnm8.js} +1 -1
- package/dist/{db-pm96nhdb.js → db-ef32tbfc.js} +4 -2
- package/dist/{db-s13dqhr6.js → db-ez6egt6v.js} +3 -3
- package/dist/{dispatcher-j3h81t7m.js → dispatcher-g3tt9hs9.js} +18 -17
- package/dist/{dsh-adapter-rw0d5rc4.js → dsh-adapter-tcyn3099.js} +1 -1
- package/dist/{easter-egg-3d-qtgfxgze.js → easter-egg-3d-e36hk5td.js} +1 -1
- package/dist/{embedding-space-xh8p4q4x.js → embedding-space-4kyh5qqj.js} +6 -6
- package/dist/{embeddings-wp745m91.js → embeddings-6a8v4a6t.js} +1 -1
- package/dist/{execute-2fzb9z74.js → execute-3cbg0twf.js} +1 -1
- package/dist/{external-channel-ys21h3sy.js → external-channel-se646snz.js} +2 -2
- package/dist/{fx-adapter-vz0b9z3g.js → fx-adapter-yw795hqq.js} +6 -6
- package/dist/{google-generative-ai-ytpgncx9.js → google-generative-ai-h7s3e9kk.js} +1 -1
- package/dist/{google-vertex-tqhze5j7.js → google-vertex-fhxaafzw.js} +1 -1
- package/dist/{grok-adapter-spea7zkj.js → grok-adapter-ttmcss2j.js} +6 -6
- package/dist/handlers-17wha3ze.js +33 -0
- package/dist/{heartbeat-8phn1kdq.js → heartbeat-gwewgdms.js} +21 -20
- package/dist/{hook-amcj4s10.js → hook-g3nhexsy.js} +5 -5
- package/dist/{hook-bc6n49qn.js → hook-hq93y5ej.js} +4 -4
- package/dist/{http-7374brv5.js → http-5a9p4h6y.js} +210 -69
- package/dist/{index-pxn30mse.js → index-0eny15vj.js} +8 -8
- package/dist/{index-5a9jtqde.js → index-0rvk3vd4.js} +46 -46
- package/dist/{index-fvzke5kx.js → index-1qw6f2dc.js} +10 -10
- package/dist/{index-p4hjwbvw.js → index-3c5pxbge.js} +1 -1
- package/dist/{index-q5cmtbz5.js → index-6haqt3v5.js} +12296 -11042
- package/dist/index-8arwq8mw.js +34 -0
- package/dist/{index-h7f61sy9.js → index-e5pfbsys.js} +3 -3
- package/dist/{index-c9y31ytf.js → index-hgn3c961.js} +12 -11
- package/dist/{index-hsad2t3r.js → index-m5gx1xd6.js} +38 -38
- package/dist/{index-5fx3b3kw.js → index-rvccek1w.js} +9 -9
- package/dist/{index-w4m9z29z.js → index-s72rqgsx.js} +1 -1
- package/dist/index-tpw054az.js +38 -0
- package/dist/{index-514d9pf6.js → index-w7em4ktq.js} +8 -8
- package/dist/index-waq75j2j.js +31 -0
- package/dist/{keepalive-wy29kbrg.js → keepalive-1j4n4dmk.js} +3 -3
- package/dist/lead-re73kdgc.js +72 -0
- package/dist/{maintenance-h2ds9w6c.js → maintenance-dmghacy5.js} +1 -1
- package/dist/{oauth-refresh-sweep-q7mtbyp3.js → oauth-refresh-sweep-yy06c03c.js} +2 -2
- package/dist/{onboard-vw8r2fdw.js → onboard-52f9t5dm.js} +3 -3
- package/dist/{opencode-adapter-mtb0953j.js → opencode-adapter-krnh9jkn.js} +4 -4
- package/dist/{otel-impl-j42czw3r.js → otel-impl-xjqz6wjj.js} +1 -1
- package/dist/{pi-mono-adapter-zk8pg9jr.js → pi-mono-adapter-dbxyp0qv.js} +6 -6
- package/dist/{pricing-refresh-x7nhv23d.js → pricing-refresh-ctdr74pd.js} +3 -3
- package/dist/{rbac-roles-bzvee6cf.js → rbac-roles-ehv8s10n.js} +3 -3
- package/dist/{rbac-roles-9044425x.js → rbac-roles-q0gr8eyj.js} +2 -2
- package/dist/{render-v2-t7bn4skz.js → render-v2-5b6chvcq.js} +9 -4
- package/dist/{resume-x94gemep.js → resume-5a5d2845.js} +6 -6
- package/dist/{runtime-breq6fmv.js → runtime-khxszyfp.js} +1 -1
- package/dist/{session-access-q7dmqjvt.js → session-access-gj0bjhqg.js} +4 -4
- package/dist/{session-source-backfill-440ysamr.js → session-source-backfill-2sy0krfk.js} +2 -2
- package/dist/{setup-07n4727s.js → setup-7ssfakk1.js} +1 -1
- package/dist/{virtual-modules-z5h6mcyf.js → virtual-modules-pjj0knwf.js} +3 -3
- package/dist/{work-objects-pnq5y534.js → work-objects-bf3syvhq.js} +22 -21
- package/dist/{worker-follow-up-7z1gfkr8.js → worker-follow-up-38xevga6.js} +18 -17
- package/dist/worker-r8mz7a65.js +72 -0
- package/openapi.json +1 -1
- package/package.json +3 -3
- package/src/apps/catalog.generated.json +55 -0
- package/src/apps/page-validator.ts +19 -0
- package/src/assets/key.ts +77 -4
- package/src/be/db/session-labels.ts +57 -0
- package/src/be/db/session-tree.ts +51 -7
- package/src/be/db/slack-trees.ts +146 -0
- package/src/be/db/tasks/read.ts +102 -7
- package/src/be/db-client.ts +8 -2
- package/src/be/db.ts +95 -84
- package/src/be/event-loop-lag.ts +146 -0
- package/src/be/mcp-overflow-sweep.ts +2 -1
- package/src/be/memory/providers/sqlite-store.ts +39 -8
- package/src/be/migrations/278_slack_render_v2_reconcile.sql +108 -0
- package/src/be/swarm-config-guard.ts +2 -0
- package/src/commands/context-preamble.ts +258 -0
- package/src/commands/onboard/agent-fs-version.ts +1 -1
- package/src/extensions/catalog.generated.json +3 -3
- package/src/heartbeat/heartbeat.ts +5 -4
- package/src/http/core.ts +9 -3
- package/src/http/index.ts +10 -6
- package/src/http/memory.ts +9 -4
- package/src/http/sessions.ts +16 -3
- package/src/http/utils.ts +18 -0
- package/src/http/webhooks.ts +48 -0
- package/src/integrations/chat-sdk/commands.ts +167 -31
- package/src/integrations/chat-sdk/inbound.ts +10 -8
- package/src/integrations/chat-sdk/message-text.ts +117 -0
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/cursor-adapter.ts +1 -1
- package/src/providers/dsh-adapter.ts +1 -1
- package/src/scheduler/scheduler.ts +4 -1
- package/src/scripts-runtime/executors/quickjs-runner.ts +2 -0
- package/src/scripts-runtime/executors/quickjs-structured-clone.ts +180 -0
- package/src/scripts-runtime/quickjs-compat.ts +0 -1
- package/src/slack/app.ts +332 -10
- package/src/slack/handlers.ts +9 -2
- package/src/slack/index.ts +7 -1
- package/src/slack/lifecycle-lock.ts +29 -0
- package/src/slack/render-v2.ts +424 -212
- package/src/slack/socket-fence.ts +64 -0
- package/src/slack/watcher.ts +42 -8
- package/src/tests/apps-schema-form.test.ts +151 -0
- package/src/tests/chat-sdk-commands.test.ts +359 -2
- package/src/tests/chat-sdk-inbound.test.ts +20 -0
- package/src/tests/chat-sdk-slack.test.ts +189 -1
- package/src/tests/db-client-busy-retry.test.ts +69 -18
- package/src/tests/db-client.test.ts +26 -1
- package/src/tests/db-task-read-contract.test.ts +2 -0
- package/src/tests/db-task-write-contract.test.ts +1 -0
- package/src/tests/dsh-adapter.test.ts +1 -1
- package/src/tests/event-loop-lag.test.ts +184 -0
- package/src/tests/extensions-example-comms-adherence-gate.test.ts +115 -0
- package/src/tests/github-webhook-early-ack.test.ts +144 -0
- package/src/tests/http-api-integration.test.ts +2 -0
- package/src/tests/http-log-scrubbing.test.ts +68 -2
- package/src/tests/kv-storage.test.ts +92 -1
- package/src/tests/memory-key-paths.test.ts +57 -0
- package/src/tests/memory-retrieval-purge.test.ts +19 -0
- package/src/tests/quickjs-compat.test.ts +1 -1
- package/src/tests/runner-context-preamble.test.ts +552 -0
- package/src/tests/script-connections.test.ts +3 -0
- package/src/tests/script-executor-conformance.test.ts +188 -0
- package/src/tests/sessions-tree.test.ts +133 -2
- package/src/tests/slack-app-icon.test.ts +4 -0
- package/src/tests/slack-dm-implicit-mention.test.ts +236 -0
- package/src/tests/slack-file-tools-attachments.test.ts +1 -0
- package/src/tests/slack-read-boundaries.test.ts +4 -3
- package/src/tests/slack-render-v2-query-plans.test.ts +262 -3
- package/src/tests/slack-render-v2-reconcile.test.ts +201 -0
- package/src/tests/slack-socket-watchdog.test.ts +748 -0
- package/src/tests/vcs-identity-inheritance.test.ts +85 -0
- package/src/tools/utils.ts +16 -7
- package/templates/extensions/comms-adherence-gate/README.md +25 -0
- package/templates/extensions/comms-adherence-gate/hooks.ts +100 -11
- package/templates/extensions/comms-adherence-gate/manifest.json +1 -1
- package/templates/skills/apps/SKILL.md +7 -0
- package/templates/skills/apps/content.md +7 -0
- package/dist/app-a66ssc4k.js +0 -17
- package/dist/handlers-crckt5dq.js +0 -32
- package/dist/index-4x08sjtk.js +0 -30
- package/dist/index-8ybffts4.js +0 -37
- package/dist/index-nfy4kkg5.js +0 -33
- package/dist/lead-zdqxsvjn.js +0 -71
- package/dist/worker-y62rvvq3.js +0 -71
- package/dist/{cli-gxy8y1dt.js → cli-8bpgbr8k.js} +3 -3
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
|
2
2
|
import { unlink } from "node:fs/promises";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { Message, parseMarkdown, toPlainText } from "chat";
|
|
4
|
+
import {
|
|
5
|
+
closeDb,
|
|
6
|
+
createAgent,
|
|
7
|
+
createTaskExtended,
|
|
8
|
+
createUser,
|
|
9
|
+
getDbClient,
|
|
10
|
+
getTaskById,
|
|
11
|
+
initDb,
|
|
12
|
+
} from "../be/db";
|
|
13
|
+
import {
|
|
14
|
+
CHAT_COMMANDS,
|
|
15
|
+
getChatThreadResetAt,
|
|
16
|
+
runChatCommand,
|
|
17
|
+
} from "../integrations/chat-sdk/commands";
|
|
18
|
+
import { chatMessageText } from "../integrations/chat-sdk/message-text";
|
|
5
19
|
import { startChatSdk, stopChatSdk } from "../integrations/chat-sdk/runtime";
|
|
6
20
|
import { readPersistedThreadHistory } from "../integrations/chat-sdk/state";
|
|
7
21
|
import { chatSdkContextKey } from "../tasks/context-key";
|
|
@@ -201,3 +215,346 @@ describe("Chat SDK thread context across an adapter restart", () => {
|
|
|
201
215
|
expect(tasks[1]!.task).toContain("before the restart");
|
|
202
216
|
});
|
|
203
217
|
});
|
|
218
|
+
|
|
219
|
+
describe("Chat SDK commands on a channel-keyed platform (Discord)", () => {
|
|
220
|
+
// A Discord mention opens a thread: its tasks are keyed `guild:channel:thread`,
|
|
221
|
+
// while a slash command in the parent channel only knows `guild:channel`.
|
|
222
|
+
const channel = "discord:G1:C1";
|
|
223
|
+
const olderThread = "discord:G1:C1:T-old";
|
|
224
|
+
const newerThread = "discord:G1:C1:T-new";
|
|
225
|
+
let olderId: string;
|
|
226
|
+
let newerId: string;
|
|
227
|
+
/** Owns both threads. */
|
|
228
|
+
let ownerId: string;
|
|
229
|
+
/** Another member of the channel. */
|
|
230
|
+
let otherId: string;
|
|
231
|
+
const asOwner = (command: string, thread = channel) =>
|
|
232
|
+
runChatCommand(command, thread, "owner", ownerId);
|
|
233
|
+
const asOther = (command: string) => runChatCommand(command, channel, "other", otherId);
|
|
234
|
+
|
|
235
|
+
beforeAll(async () => {
|
|
236
|
+
ownerId = (await createUser({ name: "Owner" })).id;
|
|
237
|
+
otherId = (await createUser({ name: "Other" })).id;
|
|
238
|
+
const agent = await createAgent({
|
|
239
|
+
id: crypto.randomUUID(),
|
|
240
|
+
name: "DiscordCmdWorker",
|
|
241
|
+
isLead: false,
|
|
242
|
+
status: "idle",
|
|
243
|
+
});
|
|
244
|
+
const seed = async (thread: string, text: string) =>
|
|
245
|
+
(
|
|
246
|
+
await createTaskExtended(text, {
|
|
247
|
+
agentId: agent.id,
|
|
248
|
+
source: "chat",
|
|
249
|
+
contextKey: chatSdkContextKey(thread),
|
|
250
|
+
requestedByUserId: ownerId,
|
|
251
|
+
})
|
|
252
|
+
).id;
|
|
253
|
+
olderId = await seed(olderThread, "older thread ask");
|
|
254
|
+
await Bun.sleep(5);
|
|
255
|
+
newerId = await seed(newerThread, "newer thread ask");
|
|
256
|
+
// A task in another channel whose id merely starts with this channel's.
|
|
257
|
+
await seed("discord:G1:C10:T-x", "another channel");
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
test("/status in the channel reports the sender's most recent thread task", async () => {
|
|
261
|
+
const reply = await asOwner("/status");
|
|
262
|
+
expect(reply).toContain(newerId.slice(0, 8));
|
|
263
|
+
expect(reply).not.toContain("No task yet");
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
test("/status inside a thread reports that thread", async () => {
|
|
267
|
+
expect(await asOwner("/status", olderThread)).toContain(olderId.slice(0, 8));
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test("another user's channel-level commands never reach the owner's threads", async () => {
|
|
271
|
+
// The threads may be private: neither the task ids nor their state leak.
|
|
272
|
+
expect(await asOther("/status")).toContain("No task yet");
|
|
273
|
+
await asOther("/reset");
|
|
274
|
+
expect(await getChatThreadResetAt(newerThread)).toBeNull();
|
|
275
|
+
expect(await getChatThreadResetAt(olderThread)).toBeNull();
|
|
276
|
+
expect(await asOther("/cancel")).toContain("No running task");
|
|
277
|
+
// An unknown sender gets no cross-thread target either.
|
|
278
|
+
expect(await runChatCommand("/cancel", channel, "stranger")).toContain("No running task");
|
|
279
|
+
expect((await getTaskById(newerId))?.status).toBe("pending");
|
|
280
|
+
expect((await getTaskById(olderId))?.status).toBe("pending");
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
test("/cancel in the channel cancels the most recent running thread, one at a time", async () => {
|
|
284
|
+
expect(await asOwner("/cancel")).toContain(`Cancelled task ${newerId.slice(0, 8)}`);
|
|
285
|
+
expect((await getTaskById(olderId))?.status).toBe("pending");
|
|
286
|
+
expect(await asOwner("/cancel")).toContain(`Cancelled task ${olderId.slice(0, 8)}`);
|
|
287
|
+
// Neither the task of C10 nor any other channel counts.
|
|
288
|
+
expect(await asOwner("/cancel")).toContain("No running task");
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
describe.each([
|
|
293
|
+
{ name: "Discord", channel: "discord:G2:C2", thread: (id: string) => `discord:G2:C2:${id}` },
|
|
294
|
+
{ name: "Slack", channel: "slack:CSHARED", thread: (id: string) => `slack:CSHARED:${id}` },
|
|
295
|
+
])("Chat SDK channel-level commands are scoped to the sender ($name)", ({ channel, thread }) => {
|
|
296
|
+
let aliceId: string;
|
|
297
|
+
let bobId: string;
|
|
298
|
+
let agentId: string;
|
|
299
|
+
const alice = (command: string) => runChatCommand(command, channel, "alice", aliceId);
|
|
300
|
+
const bob = (command: string) => runChatCommand(command, channel, "bob", bobId);
|
|
301
|
+
const stranger = (command: string) => runChatCommand(command, channel, "stranger");
|
|
302
|
+
|
|
303
|
+
const seed = async (key: string, text: string, requestedByUserId?: string) => {
|
|
304
|
+
const task = await createTaskExtended(text, {
|
|
305
|
+
agentId,
|
|
306
|
+
source: "chat",
|
|
307
|
+
contextKey: chatSdkContextKey(key),
|
|
308
|
+
requestedByUserId,
|
|
309
|
+
});
|
|
310
|
+
await Bun.sleep(5);
|
|
311
|
+
return task.id;
|
|
312
|
+
};
|
|
313
|
+
const statusOf = async (id: string) => (await getTaskById(id))?.status;
|
|
314
|
+
|
|
315
|
+
beforeAll(async () => {
|
|
316
|
+
aliceId = (await createUser({ name: "Alice" })).id;
|
|
317
|
+
bobId = (await createUser({ name: "Bob" })).id;
|
|
318
|
+
agentId = (
|
|
319
|
+
await createAgent({
|
|
320
|
+
id: crypto.randomUUID(),
|
|
321
|
+
name: `ScopedCmdWorker-${channel}`,
|
|
322
|
+
isLead: false,
|
|
323
|
+
status: "idle",
|
|
324
|
+
})
|
|
325
|
+
).id;
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
test("one thread with a task each: /cancel and /status stay on the sender's own task", async () => {
|
|
329
|
+
const shared = thread("T-mixed");
|
|
330
|
+
const aliceTask = await seed(shared, "alice asks", aliceId);
|
|
331
|
+
const bobTask = await seed(shared, "bob asks", bobId);
|
|
332
|
+
const anonymousTask = await seed(shared, "an unmapped member asks");
|
|
333
|
+
|
|
334
|
+
const aliceStatus = await alice("/status");
|
|
335
|
+
expect(aliceStatus).toContain(aliceTask.slice(0, 8));
|
|
336
|
+
expect(aliceStatus).not.toContain(bobTask.slice(0, 8));
|
|
337
|
+
expect(aliceStatus).not.toContain(anonymousTask.slice(0, 8));
|
|
338
|
+
|
|
339
|
+
expect(await alice("/cancel")).toBe(`Cancelled task ${aliceTask.slice(0, 8)}.`);
|
|
340
|
+
expect(await statusOf(aliceTask)).toBe("cancelled");
|
|
341
|
+
expect(await statusOf(bobTask)).toBe("pending");
|
|
342
|
+
expect(await statusOf(anonymousTask)).toBe("pending");
|
|
343
|
+
expect(await alice("/cancel")).toContain("No running task");
|
|
344
|
+
|
|
345
|
+
expect(await bob("/cancel")).toBe(`Cancelled task ${bobTask.slice(0, 8)}.`);
|
|
346
|
+
expect(await statusOf(anonymousTask)).toBe("pending");
|
|
347
|
+
// Nobody can reach a task that has no requester from the channel.
|
|
348
|
+
expect(await stranger("/cancel")).toContain("No running task");
|
|
349
|
+
expect(await statusOf(anonymousTask)).toBe("pending");
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
test("/reset does not change a thread another user also asked in", async () => {
|
|
353
|
+
const shared = thread("T-reset-mixed");
|
|
354
|
+
await seed(shared, "alice asks", aliceId);
|
|
355
|
+
await seed(shared, "bob asks", bobId);
|
|
356
|
+
|
|
357
|
+
expect(await alice("/reset")).toContain("Nothing was reset");
|
|
358
|
+
expect(await getChatThreadResetAt(shared)).toBeNull();
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
test("/reset on the sender's own thread still works", async () => {
|
|
362
|
+
const own = thread("T-reset-own");
|
|
363
|
+
await seed(own, "alice asks alone", aliceId);
|
|
364
|
+
expect(await alice("/reset")).toContain("Context reset");
|
|
365
|
+
expect(await getChatThreadResetAt(own)).not.toBeNull();
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
test("a nonowner, mapped or unmapped, cannot reach the channel-keyed task", async () => {
|
|
369
|
+
// Discord falls back to the channel itself when it cannot open a thread.
|
|
370
|
+
const channelTask = await seed(channel, "asked in the channel itself", aliceId);
|
|
371
|
+
// Carol has no task of her own in this channel.
|
|
372
|
+
const carolId = (await createUser({ name: "Carol" })).id;
|
|
373
|
+
const carol = (command: string) => runChatCommand(command, channel, "carol", carolId);
|
|
374
|
+
|
|
375
|
+
for (const other of [carol, stranger]) {
|
|
376
|
+
expect(await other("/status")).toContain("No task yet");
|
|
377
|
+
expect(await other("/cancel")).toContain("No running task");
|
|
378
|
+
await other("/reset");
|
|
379
|
+
}
|
|
380
|
+
expect(await getChatThreadResetAt(channel)).toBeNull();
|
|
381
|
+
expect(await statusOf(channelTask)).toBe("pending");
|
|
382
|
+
|
|
383
|
+
expect(await alice("/status")).toContain(channelTask.slice(0, 8));
|
|
384
|
+
expect(await alice("/reset")).toContain("Context reset");
|
|
385
|
+
expect(await getChatThreadResetAt(channel)).not.toBeNull();
|
|
386
|
+
expect(await alice("/cancel")).toBe(`Cancelled task ${channelTask.slice(0, 8)}.`);
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
describe("Chat SDK commands that belong to one conversation stay unscoped", () => {
|
|
391
|
+
test("a Discord thread and a Discord DM answer any sender", async () => {
|
|
392
|
+
const agent = await createAgent({
|
|
393
|
+
id: crypto.randomUUID(),
|
|
394
|
+
name: "UnscopedCmdWorker",
|
|
395
|
+
isLead: false,
|
|
396
|
+
status: "idle",
|
|
397
|
+
});
|
|
398
|
+
const owner = (await createUser({ name: "ThreadOwner" })).id;
|
|
399
|
+
const seed = async (key: string, requestedByUserId?: string) =>
|
|
400
|
+
(
|
|
401
|
+
await createTaskExtended("ask", {
|
|
402
|
+
agentId: agent.id,
|
|
403
|
+
source: "chat",
|
|
404
|
+
contextKey: chatSdkContextKey(key),
|
|
405
|
+
requestedByUserId,
|
|
406
|
+
})
|
|
407
|
+
).id;
|
|
408
|
+
const inThread = await seed("discord:G3:C3:T1", owner);
|
|
409
|
+
const inDm = await seed("discord:@me:D9");
|
|
410
|
+
|
|
411
|
+
expect(await runChatCommand("/status", "discord:G3:C3:T1", "member")).toContain(
|
|
412
|
+
inThread.slice(0, 8),
|
|
413
|
+
);
|
|
414
|
+
expect(await runChatCommand("/cancel", "discord:G3:C3:T1", "member")).toContain(
|
|
415
|
+
`Cancelled task ${inThread.slice(0, 8)}`,
|
|
416
|
+
);
|
|
417
|
+
expect(await runChatCommand("/cancel", "discord:@me:D9", "dm-user")).toContain(
|
|
418
|
+
`Cancelled task ${inDm.slice(0, 8)}`,
|
|
419
|
+
);
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
describe("Chat SDK commands in a Slack DM channel", () => {
|
|
424
|
+
// A slash command reports the DM as `slack:<D id>`. The adapter keys the DM
|
|
425
|
+
// conversation `slack:<D id>:` (empty thread ts) or, per message, `slack:<D id>:<ts>`.
|
|
426
|
+
let agentId: string;
|
|
427
|
+
let userId: string;
|
|
428
|
+
const seed = async (key: string, requestedByUserId?: string) => {
|
|
429
|
+
const task = await createTaskExtended("dm ask", {
|
|
430
|
+
agentId,
|
|
431
|
+
source: "chat",
|
|
432
|
+
contextKey: chatSdkContextKey(key),
|
|
433
|
+
requestedByUserId,
|
|
434
|
+
});
|
|
435
|
+
await Bun.sleep(5);
|
|
436
|
+
return task.id;
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
beforeAll(async () => {
|
|
440
|
+
agentId = (
|
|
441
|
+
await createAgent({
|
|
442
|
+
id: crypto.randomUUID(),
|
|
443
|
+
name: "SlackDmCmdWorker",
|
|
444
|
+
isLead: false,
|
|
445
|
+
status: "idle",
|
|
446
|
+
})
|
|
447
|
+
).id;
|
|
448
|
+
userId = (await createUser({ name: "DmOwner" })).id;
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
test("finds the empty-ts DM conversation for a mapped, an unmapped and an unknown sender", async () => {
|
|
452
|
+
const taskId = await seed("slack:DEMPTY:", userId);
|
|
453
|
+
for (const sender of [userId, "someone-else", undefined]) {
|
|
454
|
+
expect(await runChatCommand("/status", "slack:DEMPTY", "dm-user", sender)).toContain(
|
|
455
|
+
taskId.slice(0, 8),
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
expect(await runChatCommand("/cancel", "slack:DEMPTY", "dm-user")).toBe(
|
|
459
|
+
`Cancelled task ${taskId.slice(0, 8)}.`,
|
|
460
|
+
);
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
test("a task without a requester is reachable from its DM", async () => {
|
|
464
|
+
const taskId = await seed("slack:DNOREQ:");
|
|
465
|
+
expect(await runChatCommand("/status", "slack:DNOREQ", "dm-user", userId)).toContain(
|
|
466
|
+
taskId.slice(0, 8),
|
|
467
|
+
);
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
test("acts on the latest per-message DM thread and resets that thread", async () => {
|
|
471
|
+
await seed("slack:DTHREADS:1700000000.000100", userId);
|
|
472
|
+
const latest = await seed("slack:DTHREADS:1700000000.000200", userId);
|
|
473
|
+
expect(await runChatCommand("/status", "slack:DTHREADS", "dm-user", userId)).toContain(
|
|
474
|
+
latest.slice(0, 8),
|
|
475
|
+
);
|
|
476
|
+
expect(await runChatCommand("/reset", "slack:DTHREADS", "dm-user", userId)).toContain(
|
|
477
|
+
"Context reset",
|
|
478
|
+
);
|
|
479
|
+
expect(await getChatThreadResetAt("slack:DTHREADS:1700000000.000200")).not.toBeNull();
|
|
480
|
+
expect(await runChatCommand("/cancel", "slack:DTHREADS", "dm-user", userId)).toContain(
|
|
481
|
+
`Cancelled task ${latest.slice(0, 8)}`,
|
|
482
|
+
);
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
test("/reset before the first message marks the conversation the first message lands in", async () => {
|
|
486
|
+
expect(await runChatCommand("/reset", "slack:DFRESH", "dm-user")).toContain("Context reset");
|
|
487
|
+
expect(await getChatThreadResetAt("slack:DFRESH:")).not.toBeNull();
|
|
488
|
+
expect(await runChatCommand("/status", "slack:DFRESH", "dm-user")).toContain("No task yet");
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
test("a DM does not reach the tasks of another DM or of a channel", async () => {
|
|
492
|
+
await seed("slack:DOTHER:", userId);
|
|
493
|
+
await seed("slack:COTHER:1700000000.000300", userId);
|
|
494
|
+
expect(await runChatCommand("/status", "slack:DFRESH2", "dm-user", userId)).toContain(
|
|
495
|
+
"No task yet",
|
|
496
|
+
);
|
|
497
|
+
});
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
describe("chatMessageText", () => {
|
|
501
|
+
const message = (markdown: string) => {
|
|
502
|
+
const formatted = parseMarkdown(markdown);
|
|
503
|
+
return new Message({
|
|
504
|
+
id: "m1",
|
|
505
|
+
threadId: "discord:G1:C1",
|
|
506
|
+
text: toPlainText(formatted),
|
|
507
|
+
formatted,
|
|
508
|
+
raw: {},
|
|
509
|
+
author: { userId: "u1", userName: "u", fullName: "U", isBot: false, isMe: false },
|
|
510
|
+
metadata: { dateSent: new Date(), edited: false },
|
|
511
|
+
attachments: [],
|
|
512
|
+
});
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
test("keeps link URLs, code and emphasis that the plain text drops", () => {
|
|
516
|
+
const m = message(
|
|
517
|
+
"see [docs](https://example.com/a?b=1) and `bun test`\n\n```ts\nlet x = 1;\n```",
|
|
518
|
+
);
|
|
519
|
+
expect(m.text).not.toContain("https://example.com");
|
|
520
|
+
const text = chatMessageText(m);
|
|
521
|
+
expect(text).toContain("[docs](https://example.com/a?b=1)");
|
|
522
|
+
expect(text).toContain("`bun test`");
|
|
523
|
+
expect(text).toContain("```ts\nlet x = 1;\n```");
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
test("plain text stays as typed", () => {
|
|
527
|
+
expect(chatMessageText(message("just a plain request"))).toBe("just a plain request");
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
test("falls back to the plain text when there is no AST", () => {
|
|
531
|
+
expect(chatMessageText({ text: "fallback text", formatted: undefined as never })).toBe(
|
|
532
|
+
"fallback text",
|
|
533
|
+
);
|
|
534
|
+
});
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
describe("chatMessageText fidelity", () => {
|
|
538
|
+
const textOf = (markdown: string) => {
|
|
539
|
+
const formatted = parseMarkdown(markdown);
|
|
540
|
+
return chatMessageText({ text: toPlainText(formatted), formatted });
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
test("does not escape underscores, brackets or mention names", () => {
|
|
544
|
+
expect(textOf("@swarm_test_bot !now fix snake_case_name in [x]")).toBe(
|
|
545
|
+
"@swarm_test_bot !now fix snake_case_name in [x]",
|
|
546
|
+
);
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
test("keeps emphasis, lists, quotes and a code span with a backtick", () => {
|
|
550
|
+
const text = textOf("**bold** and _soft_\n\n- one\n- two\n - nested\n\n> quoted\n\n``a`b``");
|
|
551
|
+
expect(text).toContain("**bold** and _soft_");
|
|
552
|
+
expect(text).toContain("- one\n- two\n - nested");
|
|
553
|
+
expect(text).toContain("> quoted");
|
|
554
|
+
expect(text).toContain("``a`b``");
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
test("an autolink stays a bare URL", () => {
|
|
558
|
+
expect(textOf("see https://example.com/x now")).toBe("see https://example.com/x now");
|
|
559
|
+
});
|
|
560
|
+
});
|
|
@@ -189,6 +189,26 @@ describe("Chat SDK inbound pipeline", () => {
|
|
|
189
189
|
expect(skippedCounts.every((count) => count === 0)).toBe(true);
|
|
190
190
|
});
|
|
191
191
|
|
|
192
|
+
test("link URLs, inline code and code blocks reach the task text", async () => {
|
|
193
|
+
const text = "see the docs then run bun test\nfn main() {}";
|
|
194
|
+
const at = (needle: string) => ({ offset: text.indexOf(needle), length: needle.length });
|
|
195
|
+
await postTelegramUpdate(
|
|
196
|
+
telegramUpdate(dm(2090), text, {
|
|
197
|
+
entities: [
|
|
198
|
+
{ type: "text_link", url: "https://example.com/docs?a=1", ...at("the docs") },
|
|
199
|
+
{ type: "code", ...at("bun test") },
|
|
200
|
+
{ type: "pre", ...at("fn main() {}") },
|
|
201
|
+
],
|
|
202
|
+
}),
|
|
203
|
+
);
|
|
204
|
+
await flushChatBuffers();
|
|
205
|
+
const [task] = await chatTasks(2090);
|
|
206
|
+
expect(task!.task).toContain("[the docs](https://example.com/docs?a=1)");
|
|
207
|
+
expect(task!.task).toContain("`bun test`");
|
|
208
|
+
expect(task!.task).toContain("fn main() {}");
|
|
209
|
+
expect(task!.task).toMatch(/```[a-z]*\nfn main\(\) \{\}\n```/);
|
|
210
|
+
});
|
|
211
|
+
|
|
192
212
|
test("!now flushes the thread at once", async () => {
|
|
193
213
|
await postTelegramUpdate(telegramUpdate(dm(2002), "!now ship the hotfix"));
|
|
194
214
|
const tasks = await chatTasks(2002);
|
|
@@ -3,9 +3,19 @@ import { createHmac } from "node:crypto";
|
|
|
3
3
|
import { EventEmitter } from "node:events";
|
|
4
4
|
import { unlink } from "node:fs/promises";
|
|
5
5
|
import { SlackMock } from "@desplega.ai/slack-mock";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
closeDb,
|
|
8
|
+
completeTask,
|
|
9
|
+
createAgent,
|
|
10
|
+
createUser,
|
|
11
|
+
getDbClient,
|
|
12
|
+
getTaskById,
|
|
13
|
+
initDb,
|
|
14
|
+
} from "../be/db";
|
|
15
|
+
import { linkIdentity } from "../be/users";
|
|
7
16
|
import { watchSocketConnection } from "../integrations/chat-sdk/adapters";
|
|
8
17
|
import { drainBackground } from "../integrations/chat-sdk/background";
|
|
18
|
+
import { getChatThreadResetAt, runChatCommand } from "../integrations/chat-sdk/commands";
|
|
9
19
|
import { createScrubbingLogger } from "../integrations/chat-sdk/logger";
|
|
10
20
|
import { processPendingChatRelays, stopChatRelayWatcher } from "../integrations/chat-sdk/relay";
|
|
11
21
|
import { getChatSdkHealth, startChatSdk, stopChatSdk } from "../integrations/chat-sdk/runtime";
|
|
@@ -20,6 +30,8 @@ const CHANNEL_ID = "C0GENERAL0";
|
|
|
20
30
|
|
|
21
31
|
let slack: SlackMock;
|
|
22
32
|
let leadId: string;
|
|
33
|
+
/** Alice is a known user; Bob stays unmapped. */
|
|
34
|
+
let aliceUserId: string;
|
|
23
35
|
const restoreEnv = snapshotChatSdkEnv();
|
|
24
36
|
|
|
25
37
|
type TaskRow = {
|
|
@@ -102,6 +114,11 @@ beforeAll(async () => {
|
|
|
102
114
|
});
|
|
103
115
|
process.env.SLACK_DISABLE = "true";
|
|
104
116
|
process.env.CHAT_SDK_BUFFER_MS = "60000";
|
|
117
|
+
aliceUserId = (await createUser({ name: "Alice", timezone: "Europe/Madrid" })).id;
|
|
118
|
+
await linkIdentity(aliceUserId, "slack", slack.user("alice").id, {
|
|
119
|
+
kind: "system",
|
|
120
|
+
id: "chat-sdk-slack-test",
|
|
121
|
+
});
|
|
105
122
|
});
|
|
106
123
|
|
|
107
124
|
afterAll(async () => {
|
|
@@ -203,6 +220,44 @@ describe("Chat SDK Slack adapter, socket mode", () => {
|
|
|
203
220
|
expect(JSON.parse(followUp.dependsOn ?? "[]")).toEqual([firstTaskId]);
|
|
204
221
|
});
|
|
205
222
|
|
|
223
|
+
test("/agent-swarm-status in the channel reports the thread of the sender's task", async () => {
|
|
224
|
+
const seen = new Set(slack.messages("general").map((m) => m.ts));
|
|
225
|
+
await slack.slashCommand({ command: "/agent-swarm-status", channel: "general", user: "alice" });
|
|
226
|
+
const reply = await slack.waitForMessage(
|
|
227
|
+
(m) => !seen.has(m.ts) && m.text.includes("Latest task"),
|
|
228
|
+
{ timeoutMs: 5_000 },
|
|
229
|
+
);
|
|
230
|
+
// Alice's task picks the thread; Bob's later follow-up there is not hers to read.
|
|
231
|
+
const [alicesTask, bobsFollowUp] = await chatTasks(contextKey);
|
|
232
|
+
expect(reply.text).toContain(alicesTask!.id.slice(0, 8));
|
|
233
|
+
expect(reply.text).not.toContain(bobsFollowUp!.id.slice(0, 8));
|
|
234
|
+
expect(reply.text).toContain("pending");
|
|
235
|
+
expect(reply.text).not.toContain("Unknown command");
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
test("/agent-swarm-status from an unmapped sender reaches no thread task", async () => {
|
|
239
|
+
const seen = new Set(slack.messages("general").map((m) => m.ts));
|
|
240
|
+
await slack.slashCommand({ command: "/agent-swarm-status", channel: "general", user: "bob" });
|
|
241
|
+
const reply = await slack.waitForMessage(
|
|
242
|
+
(m) => !seen.has(m.ts) && m.text.includes("No task yet"),
|
|
243
|
+
{ timeoutMs: 5_000 },
|
|
244
|
+
);
|
|
245
|
+
expect(reply.text).not.toContain(firstTaskId.slice(0, 8));
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
test("/agent-swarm-help answers with the command list", async () => {
|
|
249
|
+
const seen = new Set(slack.messages("general").map((m) => m.ts));
|
|
250
|
+
await slack.slashCommand({ command: "/agent-swarm-help", channel: "general", user: "alice" });
|
|
251
|
+
const reply = await slack.waitForMessage(
|
|
252
|
+
(m) => !seen.has(m.ts) && m.text.includes("Commands:"),
|
|
253
|
+
{
|
|
254
|
+
timeoutMs: 5_000,
|
|
255
|
+
},
|
|
256
|
+
);
|
|
257
|
+
expect(reply.text).toContain("/cancel");
|
|
258
|
+
expect(reply.text).not.toContain("Unknown command");
|
|
259
|
+
});
|
|
260
|
+
|
|
206
261
|
test("completing the task posts its output in the Slack thread", async () => {
|
|
207
262
|
await completeTask(firstTaskId, "Three tasks are open.");
|
|
208
263
|
await processPendingChatRelays();
|
|
@@ -214,6 +269,139 @@ describe("Chat SDK Slack adapter, socket mode", () => {
|
|
|
214
269
|
});
|
|
215
270
|
});
|
|
216
271
|
|
|
272
|
+
describe("Chat SDK Slack adapter, channel-level commands and inbound text", () => {
|
|
273
|
+
const channelThread = `slack:${CHANNEL_ID}`;
|
|
274
|
+
let askTs: string;
|
|
275
|
+
let taskKey: string;
|
|
276
|
+
|
|
277
|
+
beforeAll(async () => {
|
|
278
|
+
await startSlackAdapter("socket");
|
|
279
|
+
await slack.waitForConnection();
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
afterAll(async () => {
|
|
283
|
+
await stopChatSdk();
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
test("a mention keeps link URLs, code fences and inline code in the task text", async () => {
|
|
287
|
+
const ask = await slack.postMessage({
|
|
288
|
+
channel: "general",
|
|
289
|
+
user: "alice",
|
|
290
|
+
text: [
|
|
291
|
+
`<@${slack.bot.userId}> read <https://example.com/docs?a=1|the docs> and <https://example.com/bare>`,
|
|
292
|
+
"```",
|
|
293
|
+
"bun test --bail",
|
|
294
|
+
"```",
|
|
295
|
+
"then run `bun run lint`",
|
|
296
|
+
].join("\n"),
|
|
297
|
+
});
|
|
298
|
+
askTs = ask.ts;
|
|
299
|
+
const threadId = `slack:${CHANNEL_ID}:${askTs}`;
|
|
300
|
+
taskKey = chatSdkContextKey(threadId);
|
|
301
|
+
await waitForBuffered(threadId);
|
|
302
|
+
await flushChatBuffers();
|
|
303
|
+
|
|
304
|
+
const [task] = await chatTasks(taskKey);
|
|
305
|
+
expect(task).toBeDefined();
|
|
306
|
+
expect(task!.task).toContain("[the docs](https://example.com/docs?a=1)");
|
|
307
|
+
expect(task!.task).toContain("https://example.com/bare");
|
|
308
|
+
expect(task!.task).toContain("```\nbun test --bail\n```");
|
|
309
|
+
expect(task!.task).toContain("`bun run lint`");
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
test("/status, /reset and /cancel at channel level never reach another user's thread", async () => {
|
|
313
|
+
const [task] = await chatTasks(taskKey);
|
|
314
|
+
const aliceThread = `slack:${CHANNEL_ID}:${askTs}`;
|
|
315
|
+
|
|
316
|
+
expect(await runChatCommand("/status", channelThread, "bob")).toContain("No task yet");
|
|
317
|
+
await runChatCommand("/reset", channelThread, "bob");
|
|
318
|
+
expect(await getChatThreadResetAt(aliceThread)).toBeNull();
|
|
319
|
+
expect(await runChatCommand("/cancel", channelThread, "bob")).toContain("No running task");
|
|
320
|
+
expect((await getTaskById(task!.id))?.status).toBe("pending");
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
test("/status, /reset and /cancel at channel level act on the sender's thread task", async () => {
|
|
324
|
+
const [task] = await chatTasks(taskKey);
|
|
325
|
+
const short = task!.id.slice(0, 8);
|
|
326
|
+
const ask = (s: string) => runChatCommand(s, channelThread, "alice", aliceUserId);
|
|
327
|
+
|
|
328
|
+
expect(await ask("/status")).toContain(short);
|
|
329
|
+
|
|
330
|
+
// Slack slash commands carry no thread: /cancel takes the sender's most recent running task.
|
|
331
|
+
const reset = await ask("/reset");
|
|
332
|
+
expect(reset).toContain("Context reset");
|
|
333
|
+
expect(reset).toContain("still running");
|
|
334
|
+
expect(await getChatThreadResetAt(`slack:${CHANNEL_ID}:${askTs}`)).not.toBeNull();
|
|
335
|
+
|
|
336
|
+
expect(await ask("/cancel")).toContain(`Cancelled task ${short}`);
|
|
337
|
+
expect((await getTaskById(task!.id))?.status).toBe("cancelled");
|
|
338
|
+
// Bob's follow-up in the earlier thread is still running, but it is not Alice's.
|
|
339
|
+
expect(await ask("/cancel")).toContain("No running task");
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
describe("Chat SDK Slack adapter, DM slash commands", () => {
|
|
344
|
+
let dmChannel: string;
|
|
345
|
+
let dmThread: string;
|
|
346
|
+
let taskId: string;
|
|
347
|
+
|
|
348
|
+
beforeAll(async () => {
|
|
349
|
+
await startSlackAdapter("socket");
|
|
350
|
+
await slack.waitForConnection();
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
afterAll(async () => {
|
|
354
|
+
await stopChatSdk();
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
/** Run a slash command in the DM through the adapter and return the bot's reply. */
|
|
358
|
+
async function dmCommand(command: string, user = "alice"): Promise<string> {
|
|
359
|
+
const seen = new Set(slack.messages(dmChannel).map((m) => m.ts));
|
|
360
|
+
await slack.slashCommand({ command, channel: dmChannel, user });
|
|
361
|
+
const reply = await slack.waitForMessage(
|
|
362
|
+
(m) => m.channel === dmChannel && !seen.has(m.ts) && m.user !== slack.user(user).id,
|
|
363
|
+
{ timeoutMs: 5_000 },
|
|
364
|
+
);
|
|
365
|
+
return reply.text;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
test("a DM message creates a chat task", async () => {
|
|
369
|
+
dmChannel = slack.openDm(slack.user("alice").id).id;
|
|
370
|
+
expect(dmChannel.startsWith("D")).toBe(true);
|
|
371
|
+
await slack.postMessage({ channel: dmChannel, user: "alice", text: "what is in the queue?" });
|
|
372
|
+
// The adapter keys a DM by the channel and an empty thread ts.
|
|
373
|
+
dmThread = `slack:${dmChannel}:`;
|
|
374
|
+
await waitForBuffered(dmThread);
|
|
375
|
+
await flushChatBuffers();
|
|
376
|
+
const [task] = await chatTasks(chatSdkContextKey(dmThread));
|
|
377
|
+
expect(task).toBeDefined();
|
|
378
|
+
taskId = task!.id;
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
test("/agent-swarm-status in the DM finds the DM task", async () => {
|
|
382
|
+
const reply = await dmCommand("/agent-swarm-status");
|
|
383
|
+
expect(reply).toContain(taskId.slice(0, 8));
|
|
384
|
+
expect(reply).not.toContain("No task yet");
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
// The shipped manifest declares only /agent-swarm-status and /agent-swarm-help,
|
|
388
|
+
// so the mock cannot send the other two: they run through the command runner
|
|
389
|
+
// with the channel id the adapter reports for a DM.
|
|
390
|
+
test("/reset in the DM channel marks the DM conversation, for any sender", async () => {
|
|
391
|
+
expect(await runChatCommand("/reset", `slack:${dmChannel}`, "alice")).toContain(
|
|
392
|
+
"Context reset",
|
|
393
|
+
);
|
|
394
|
+
expect(await getChatThreadResetAt(dmThread)).not.toBeNull();
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
test("/cancel in the DM channel cancels the DM task, for any sender", async () => {
|
|
398
|
+
expect(await runChatCommand("/cancel", `slack:${dmChannel}`, "alice")).toContain(
|
|
399
|
+
`Cancelled task ${taskId.slice(0, 8)}`,
|
|
400
|
+
);
|
|
401
|
+
expect((await getTaskById(taskId))?.status).toBe("cancelled");
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
|
|
217
405
|
describe("Chat SDK Slack adapter, webhook mode", () => {
|
|
218
406
|
beforeAll(async () => {
|
|
219
407
|
await startSlackAdapter("webhook");
|