@desplega.ai/slack-mock 0.3.0 → 0.4.0
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/README.md +19 -2
- package/dist/cli.js +2 -2
- package/dist/index-xs37gskt.js +156 -0
- package/dist/{index-fhjq5qns.js → index-y82vvfa1.js} +255 -44
- package/dist/index.js +2 -2
- package/dist/screenshot.js +1 -1
- package/dist/server.d.ts +11 -4
- package/dist/store.d.ts +1 -0
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/render/index.ts +269 -44
- package/src/screenshot.ts +116 -1
- package/src/server.ts +29 -6
- package/src/store.ts +2 -0
- package/src/types.ts +1 -0
- package/dist/index-v2hesj4s.js +0 -52
package/README.md
CHANGED
|
@@ -42,6 +42,23 @@ open http://127.0.0.1:4040/c/general # live view: new messages arrive
|
|
|
42
42
|
bun src/cli.ts screenshot http://127.0.0.1:4040/c/general --out general.png
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
+
## UI
|
|
46
|
+
|
|
47
|
+
Use the avatar and name chip to choose who posts from every composer.
|
|
48
|
+
The browser remembers your choice across channels and threads.
|
|
49
|
+
Open `/c/support?as=taras` to select Taras. The page removes `as` from the URL after selection.
|
|
50
|
+
Public workspaces show the chip after presenter sign-in.
|
|
51
|
+
Optional user status text appears beside names in the users table and the chip's user list.
|
|
52
|
+
Each message offers reaction and thread icons, including messages without replies.
|
|
53
|
+
The thread icon opens the thread without focusing the composer.
|
|
54
|
+
Icons stay visible on phones and touch screens. Desktop shows them on hover or keyboard focus.
|
|
55
|
+
Choose an emoji from the picker beside the message, or select an existing reaction to add or remove your own.
|
|
56
|
+
Reactions use the identity in the chip and require presenter sign-in in public workspaces.
|
|
57
|
+
Below 700px, the sidebar becomes a top bar with a channel switcher.
|
|
58
|
+
Threads fill the phone width. The composer follows the visible viewport and includes padding for the iOS home bar.
|
|
59
|
+
Capture the phone layout with `bun test test/phone-ui.test.ts` (requires Chrome).
|
|
60
|
+
The PNG is saved to `test/artifacts/phone-support-thread.png` at 390 x 844.
|
|
61
|
+
|
|
45
62
|
## In tests
|
|
46
63
|
|
|
47
64
|
```ts
|
|
@@ -64,7 +81,7 @@ const reply = await slack.waitForMessage({ channel: "general", thread_ts: ask.ts
|
|
|
64
81
|
|
|
65
82
|
What tests can do:
|
|
66
83
|
|
|
67
|
-
| humans do | `postMessage` (text, thread, files), `editMessage`, `deleteMessage`, `addReaction`, `slashCommand`, `clickButton`, `submitView`, `startAssistantThread`, `changeAssistantContext`, `addUser`, `addChannel`, `openDm`, `invite` |
|
|
84
|
+
| humans do | `postMessage` (text, thread, files), `editMessage`, `deleteMessage`, `addReaction`, `removeReaction`, `slashCommand`, `clickButton`, `submitView`, `startAssistantThread`, `changeAssistantContext`, `addUser`, `addChannel`, `openDm`, `invite` |
|
|
68
85
|
|---|---|
|
|
69
86
|
| observe | `messages`, `thread`, `ephemeralMessages`, `findMessages`, `waitForMessage`, `apiCalls`, `waitForApiCall`, `deliveries` (every envelope and its ack), `assistantThread` |
|
|
70
87
|
| break things | `injectFault({ method, error, httpStatus, retryAfterSec, extra })`, `disconnectSockets("refresh_requested")`, options `ackTimeoutMs`, `maxRetries`, `triggerIdTtlMs`, `echoBotMessages`, `subscribedEvents` |
|
|
@@ -163,7 +180,7 @@ that possible, all read by `scripts/demo-server.ts`:
|
|
|
163
180
|
| `APP_NAME` | Bot display name (`appName`). |
|
|
164
181
|
| `SEED_FILE` | JSON with `users`, `channels`, `messages` and `driver.prompts` (`scripts/seed.ts`); replaces the built-in `#general` and is applied whenever the journal has no channels, so the workspace comes back after every reset. `seeds/agent-swarm-demo.json` is the shipped example. |
|
|
165
182
|
| `UI_PUBLIC=true` | Keep `/` and `/c/...` readable without credentials while `ADMIN_AUTH` still gates `/mock/*` (`publicUi` option). The composer then shows a sign-in instead of the browser's basic-auth prompt. |
|
|
166
|
-
| `PRESENTER_AUTH` | `user:password` that
|
|
183
|
+
| `PRESENTER_AUTH` | `user:password` that permits `POST /mock/messages`, `POST /mock/reactions`, and `GET /mock/presenter` (`presenterAuth` option). A presenter can post messages and manage reactions without the admin credential. Opening `/c/<channel>#presenter=user:password` signs that browser in. |
|
|
167
184
|
| `DRIVER_INTERVAL_MINUTES` | Every N minutes post the next `driver.prompts` entry as that user, mentioning the bot, while an app is connected (`scripts/driver.ts`). `0` disables it. |
|
|
168
185
|
|
|
169
186
|
## Docs
|
package/dist/cli.js
CHANGED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/screenshot.ts
|
|
3
|
+
import { existsSync } from "fs";
|
|
4
|
+
var CHROME_CANDIDATES = [
|
|
5
|
+
process.env.SLACK_MOCK_CHROME,
|
|
6
|
+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
7
|
+
"/Applications/Chromium.app/Contents/MacOS/Chromium",
|
|
8
|
+
"/usr/bin/google-chrome",
|
|
9
|
+
"/usr/bin/google-chrome-stable",
|
|
10
|
+
"/usr/bin/chromium",
|
|
11
|
+
"/usr/bin/chromium-browser"
|
|
12
|
+
];
|
|
13
|
+
function findChrome2() {
|
|
14
|
+
for (const c of CHROME_CANDIDATES)
|
|
15
|
+
if (c && existsSync(c))
|
|
16
|
+
return c;
|
|
17
|
+
const fromPath = Bun.which("google-chrome") ?? Bun.which("chromium") ?? Bun.which("chrome");
|
|
18
|
+
return fromPath ?? undefined;
|
|
19
|
+
}
|
|
20
|
+
function requireChrome2() {
|
|
21
|
+
const chrome = findChrome2();
|
|
22
|
+
if (!chrome)
|
|
23
|
+
throw new Error("no Chrome/Chromium binary found; set SLACK_MOCK_CHROME=/path/to/chrome");
|
|
24
|
+
return chrome;
|
|
25
|
+
}
|
|
26
|
+
async function screenshotWithCdp(chrome, target, opts, width, height) {
|
|
27
|
+
const proc = Bun.spawn([
|
|
28
|
+
chrome,
|
|
29
|
+
"--headless=new",
|
|
30
|
+
"--disable-gpu",
|
|
31
|
+
"--hide-scrollbars",
|
|
32
|
+
"--no-first-run",
|
|
33
|
+
"--no-default-browser-check",
|
|
34
|
+
"--remote-debugging-port=0",
|
|
35
|
+
"about:blank"
|
|
36
|
+
], { stdout: "ignore", stderr: "pipe" });
|
|
37
|
+
const timer = setTimeout(() => proc.kill(), opts.timeoutMs ?? 30000);
|
|
38
|
+
let socket;
|
|
39
|
+
const reader = proc.stderr.getReader();
|
|
40
|
+
try {
|
|
41
|
+
const decoder = new TextDecoder;
|
|
42
|
+
let stderr = "";
|
|
43
|
+
let endpoint = null;
|
|
44
|
+
while (!endpoint) {
|
|
45
|
+
const { value, done } = await reader.read();
|
|
46
|
+
if (done)
|
|
47
|
+
throw new Error("Chrome closed before opening DevTools");
|
|
48
|
+
stderr += decoder.decode(value, { stream: true });
|
|
49
|
+
endpoint = /DevTools listening on (ws:\/\/[^\s]+)/.exec(stderr);
|
|
50
|
+
}
|
|
51
|
+
socket = new WebSocket(endpoint[1]);
|
|
52
|
+
await new Promise((resolve, reject) => {
|
|
53
|
+
socket.addEventListener("open", () => resolve(), { once: true });
|
|
54
|
+
socket.addEventListener("error", () => reject(new Error("Cannot connect to Chrome DevTools")), { once: true });
|
|
55
|
+
socket.addEventListener("close", () => reject(new Error("Chrome DevTools closed")), {
|
|
56
|
+
once: true
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
let nextId = 0;
|
|
60
|
+
let sessionId;
|
|
61
|
+
const pending = new Map;
|
|
62
|
+
let pageLoaded = () => {};
|
|
63
|
+
let loadFailed = (_error) => {};
|
|
64
|
+
socket.onmessage = (event) => {
|
|
65
|
+
const message = JSON.parse(String(event.data));
|
|
66
|
+
if (message.method === "Page.loadEventFired" && message.sessionId === sessionId)
|
|
67
|
+
pageLoaded();
|
|
68
|
+
const request = pending.get(message.id);
|
|
69
|
+
if (!request)
|
|
70
|
+
return;
|
|
71
|
+
pending.delete(message.id);
|
|
72
|
+
if (message.error)
|
|
73
|
+
request.reject(new Error(message.error.message));
|
|
74
|
+
else
|
|
75
|
+
request.resolve(message.result ?? {});
|
|
76
|
+
};
|
|
77
|
+
socket.onclose = socket.onerror = () => {
|
|
78
|
+
const error = new Error("Chrome DevTools closed before capture completed");
|
|
79
|
+
for (const request of pending.values())
|
|
80
|
+
request.reject(error);
|
|
81
|
+
pending.clear();
|
|
82
|
+
loadFailed(error);
|
|
83
|
+
};
|
|
84
|
+
const command = (method, params = {}) => {
|
|
85
|
+
const id = ++nextId;
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
pending.set(id, { resolve, reject });
|
|
88
|
+
socket.send(JSON.stringify({ id, method, params, sessionId }));
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
const { targetId } = await command("Target.createTarget", { url: "about:blank" });
|
|
92
|
+
const attached = await command("Target.attachToTarget", { targetId, flatten: true });
|
|
93
|
+
if (typeof attached.sessionId !== "string")
|
|
94
|
+
throw new Error("Chrome returned no page session");
|
|
95
|
+
sessionId = attached.sessionId;
|
|
96
|
+
await command("Page.enable");
|
|
97
|
+
await command("Emulation.setDeviceMetricsOverride", {
|
|
98
|
+
width,
|
|
99
|
+
height,
|
|
100
|
+
deviceScaleFactor: 1,
|
|
101
|
+
mobile: false
|
|
102
|
+
});
|
|
103
|
+
const loaded = new Promise((resolve, reject) => {
|
|
104
|
+
pageLoaded = resolve;
|
|
105
|
+
loadFailed = reject;
|
|
106
|
+
});
|
|
107
|
+
await Promise.all([command("Page.navigate", { url: target.toString() }), loaded]);
|
|
108
|
+
await command("Runtime.evaluate", { expression: "document.fonts.ready", awaitPromise: true });
|
|
109
|
+
const { data } = await command("Page.captureScreenshot", {
|
|
110
|
+
format: "png",
|
|
111
|
+
captureBeyondViewport: false
|
|
112
|
+
});
|
|
113
|
+
if (typeof data !== "string")
|
|
114
|
+
throw new Error("Chrome returned no screenshot data");
|
|
115
|
+
await Bun.write(opts.out, Buffer.from(data, "base64"));
|
|
116
|
+
return opts.out;
|
|
117
|
+
} finally {
|
|
118
|
+
socket?.close();
|
|
119
|
+
clearTimeout(timer);
|
|
120
|
+
reader.releaseLock();
|
|
121
|
+
if (proc.exitCode === null)
|
|
122
|
+
proc.kill();
|
|
123
|
+
await proc.exited;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async function screenshot2(url, opts) {
|
|
127
|
+
const chrome = requireChrome2();
|
|
128
|
+
const target = new URL(url);
|
|
129
|
+
if (!target.searchParams.has("screenshot"))
|
|
130
|
+
target.searchParams.set("screenshot", "1");
|
|
131
|
+
const width = opts.width ?? 800;
|
|
132
|
+
const height = opts.height ?? 1000;
|
|
133
|
+
if (width < 500)
|
|
134
|
+
return screenshotWithCdp(chrome, target, opts, width, height);
|
|
135
|
+
const proc = Bun.spawn([
|
|
136
|
+
chrome,
|
|
137
|
+
"--headless=new",
|
|
138
|
+
"--disable-gpu",
|
|
139
|
+
"--hide-scrollbars",
|
|
140
|
+
"--no-first-run",
|
|
141
|
+
"--no-default-browser-check",
|
|
142
|
+
`--window-size=${width},${height}`,
|
|
143
|
+
`--screenshot=${opts.out}`,
|
|
144
|
+
target.toString()
|
|
145
|
+
], { stdout: "ignore", stderr: "pipe" });
|
|
146
|
+
const timer = setTimeout(() => proc.kill(), opts.timeoutMs ?? 30000);
|
|
147
|
+
const code = await proc.exited;
|
|
148
|
+
clearTimeout(timer);
|
|
149
|
+
if (code !== 0 || !existsSync(opts.out)) {
|
|
150
|
+
const err = await new Response(proc.stderr).text();
|
|
151
|
+
throw new Error(`chrome exited with ${code}: ${err.slice(-500)}`);
|
|
152
|
+
}
|
|
153
|
+
return opts.out;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export { findChrome2, requireChrome2, screenshot2 };
|