@desplega.ai/slack-mock 0.1.1 → 0.2.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 CHANGED
@@ -72,6 +72,39 @@ What tests can do:
72
72
  The same operations exist over HTTP under `/mock/*` for use from another
73
73
  process (see `docs/design.md`).
74
74
 
75
+ ## Frames from a journal
76
+
77
+ A run recorded with `dataFile` can be replayed into one PNG per event that touched a
78
+ thread (or, without a thread, a channel): the view after each `message.add`,
79
+ `message.update`, `message.delete`, `reaction.add` and `reaction.remove` line, in journal
80
+ order, plus `final-thread.png` (a copy of the last frame) and `final-desktop.png` (the full
81
+ UI with the thread panel, 1280x900). Nothing is served: the journal is replayed in memory and
82
+ each page is screenshotted from a temp file by the same headless Chrome helper as
83
+ `screenshot`. A `file.add` line carries no message, so a shared file first appears in the
84
+ frame of the message that shares it.
85
+
86
+ ```bash
87
+ slack-mock frames --journal run.jsonl --channel C0GENERAL0 --thread 1788518410.672000 --out ./frames
88
+ # 5 message.add /abs/frames/01-message.add.png
89
+ # 6 reaction.add /abs/frames/02-reaction.add.png
90
+ # ...
91
+ # final-thread=/abs/frames/final-thread.png
92
+ # final-desktop=/abs/frames/final-desktop.png
93
+ ```
94
+
95
+ Leave out `--thread` for the channel view. `--manifest app.json` (bot display name),
96
+ `--width`, `--height` and `--no-desktop` are optional. The same from code:
97
+
98
+ ```ts
99
+ import { frames } from "@desplega.ai/slack-mock";
100
+
101
+ const result = await frames({ journal: "run.jsonl", channel: "general", thread: ask.ts, out: "./frames" });
102
+ // result.frames[1] = { index: 6, kind: "reaction.add", path: "/abs/frames/02-reaction.add.png" }
103
+ // result.finalThread, result.finalDesktop
104
+ ```
105
+
106
+ Stitch the PNGs into a GIF with ffmpeg if you want motion; the mock only produces frames.
107
+
75
108
  ## Slack behaviour that is modelled
76
109
 
77
110
  - Socket Mode: `apps.connections.open`, `hello`, envelopes for `events_api`,
package/dist/cli.js CHANGED
@@ -1,11 +1,12 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
3
  import {
4
- SlackMock
5
- } from "./index-eyfkn32t.js";
4
+ SlackMock2,
5
+ frames2
6
+ } from "./index-6c88z809.js";
6
7
  import {
7
- screenshot
8
- } from "./index-v7mbr1cx.js";
8
+ screenshot2
9
+ } from "./index-v2hesj4s.js";
9
10
 
10
11
  // src/cli.ts
11
12
  import { parseArgs } from "util";
@@ -15,6 +16,11 @@ Usage:
15
16
  slack-mock serve [--port 4040] [--host 127.0.0.1] [--data ./data/slack.jsonl] [--manifest app.json]
16
17
  [--no-seed] [--quiet] [--panel 50] [--auth user:pass] [--public-url https://mock.example.com]
17
18
  slack-mock screenshot <url> --out shot.png [--width 800] [--height 1000]
19
+ slack-mock frames --journal data.jsonl --channel C0GENERAL0 [--thread 1788516626.286000] --out ./frames
20
+ [--manifest app.json] [--width 800] [--height 700] [--no-desktop]
21
+
22
+ frames renders the thread (or, without --thread, the channel) as it looked after every journal
23
+ line that touched it: one PNG per line, then final-thread.png and final-desktop.png.
18
24
 
19
25
  serve prints the env vars to give your bot (SLACK_BOT_TOKEN, SLACK_APP_TOKEN, SLACK_API_URL)
20
26
  and the URLs of the HTML views. Inject messages with the admin API, e.g.
@@ -38,7 +44,7 @@ async function main(argv) {
38
44
  "public-url": { type: "string" }
39
45
  }
40
46
  });
41
- const mock = await SlackMock.start({
47
+ const mock = await SlackMock2.start({
42
48
  panelWidth: values.panel,
43
49
  adminAuth: values.auth,
44
50
  publicUrl: values["public-url"],
@@ -81,7 +87,7 @@ async function main(argv) {
81
87
  const url = positionals[0];
82
88
  if (!url)
83
89
  throw new Error("screenshot needs a URL");
84
- const out = await screenshot(url, {
90
+ const out = await screenshot2(url, {
85
91
  out: values.out,
86
92
  width: Number(values.width),
87
93
  height: Number(values.height)
@@ -89,6 +95,39 @@ async function main(argv) {
89
95
  console.log(out);
90
96
  return;
91
97
  }
98
+ if (command === "frames") {
99
+ const { values } = parseArgs({
100
+ args: rest,
101
+ options: {
102
+ journal: { type: "string" },
103
+ channel: { type: "string" },
104
+ thread: { type: "string" },
105
+ out: { type: "string" },
106
+ manifest: { type: "string" },
107
+ width: { type: "string", default: "800" },
108
+ height: { type: "string", default: "700" },
109
+ "no-desktop": { type: "boolean", default: false }
110
+ }
111
+ });
112
+ if (!values.journal || !values.channel || !values.out)
113
+ throw new Error("frames needs --journal, --channel and --out");
114
+ const result = await frames2({
115
+ journal: values.journal,
116
+ channel: values.channel,
117
+ thread: values.thread,
118
+ out: values.out,
119
+ manifest: values.manifest,
120
+ width: Number(values.width),
121
+ height: Number(values.height),
122
+ desktop: !values["no-desktop"]
123
+ });
124
+ for (const f of result.frames)
125
+ console.log(`${f.index} ${f.kind} ${f.path}`);
126
+ console.log(`final-thread=${result.finalThread}`);
127
+ if (result.finalDesktop)
128
+ console.log(`final-desktop=${result.finalDesktop}`);
129
+ return;
130
+ }
92
131
  console.log(USAGE);
93
132
  if (command && command !== "help" && command !== "--help")
94
133
  process.exit(1);
@@ -0,0 +1,41 @@
1
+ import { type SlackManifest } from "./server.ts";
2
+ import { type JournalEntry } from "./store.ts";
3
+ export interface FramesOptions {
4
+ /** Path to a JSONL journal written by `dataFile`. */
5
+ journal: string;
6
+ /** Channel id or name. */
7
+ channel: string;
8
+ /** Thread root ts. When absent, render the channel view instead of the thread view. */
9
+ thread?: string;
10
+ /** Output directory. Created when missing. */
11
+ out: string;
12
+ /** Slack app manifest path or object, same as `SlackMockOptions.manifest`. */
13
+ manifest?: string | SlackManifest;
14
+ /** Viewport width in px. Default 800. */
15
+ width?: number;
16
+ /** Viewport height in px. Default 700. */
17
+ height?: number;
18
+ /** Also render `final-desktop.png` (`?screenshot=0`, 1280x900). Default true. */
19
+ desktop?: boolean;
20
+ }
21
+ export interface Frame {
22
+ /** 1-based journal line number the frame was rendered after. */
23
+ index: number;
24
+ /** Journal `kind` of that line. */
25
+ kind: string;
26
+ /** Absolute PNG path. */
27
+ path: string;
28
+ }
29
+ export interface FramesResult {
30
+ frames: Frame[];
31
+ /** Copy of the last frame. */
32
+ finalThread: string;
33
+ /** Present when `desktop` is true. */
34
+ finalDesktop?: string;
35
+ }
36
+ /**
37
+ * Journal entries that change what the thread (or, without `thread`, the channel) shows.
38
+ * `file.add` carries no message, so a file only shows up with the message that shares it.
39
+ */
40
+ export declare function selectFrames(entries: JournalEntry[], channel: string, thread?: string): JournalEntry[];
41
+ export declare function frames(opts: FramesOptions): Promise<FramesResult>;