shadok-ai 0.19.27 β†’ 0.19.29

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
@@ -345,13 +345,14 @@ Enter to skip; you can add it later from the web UI).
345
345
  conversation is a real agent that stays resident, and they all draw on **your**
346
346
  Claude subscription, so there is no cap and no queue by design. Go back to
347
347
  **Board group** and every such conversation is closed at once.
348
- - **Link to a message** β€” every message (yours and the agent's) has a πŸ”— link
349
- button beside copy. It copies a URL like `…/#agent=<session>&msg=<id>`;
350
- whoever opens it β€” someone who already has access to this cockpit, after the
351
- usual sign-in β€” lands on that agent, scrolled to that message, highlighted.
352
- The link lives in the URL's `#` part, so it never reaches the server or a
353
- proxy log. A message older than the history shown (the last 100 turns), or an
354
- agent that was closed, says so instead of opening somewhere else.
348
+ - **Link to a message** β€” every message (yours and the agent's, and a **room**'s
349
+ too) has a πŸ”— link button beside copy. It copies a URL like
350
+ `…/#agent=<session>&msg=<id>` for an agent, `…/#room=<room>&msg=<id>` for a
351
+ room; whoever opens it β€” someone who already has access to this cockpit, after
352
+ the usual sign-in β€” lands on that conversation, scrolled to that message,
353
+ highlighted. The link lives in the URL's `#` part, so it never reaches the
354
+ server or a proxy log. A message older than the history shown, or a
355
+ conversation that was closed, says so instead of opening somewhere else.
355
356
  - **Run the command an agent asks you to** β€” when an agent writes `! cmd` for
356
357
  you to run (typically because it cannot), a β–Ά run button sits right on that
357
358
  command's code block, beside its copy button β€” so it runs where it was
@@ -532,11 +533,18 @@ Enter to skip; you can add it later from the web UI).
532
533
  rename, change profile, mirror to Telegram, close β€” and closing it brings the
533
534
  card back. Desktop only: the agents column is hidden on phones.
534
535
  - **Guided tour** β€” on a browser's first visit, a welcome card explains what
535
- shadok-ai is, then a spotlight walks the real controls: the agents list, an
536
- agent's β‹― menu, scheduled prompts, the toolbar, the quota bars. Skip and
536
+ shadok-ai is, then a spotlight walks the real controls, in up to eleven stops:
537
+ the groups column, the agents list (and rooms), an agent's own bar (gallery,
538
+ about, terminal), its β‹― menu, schedules and webhooks, the composer (attach, add
539
+ a skill, dictate), the toolbar (secrets, ledger, Skill Factory, profiles,
540
+ Telegram, sound, and what the β‹― holds), the people buttons (Users, Reports,
541
+ Security), the quota bars, and the cockpit's name and settings menu. Skip and
537
542
  Escape end it at any point; β‹― β†’ *Guided tour* replays it. A step whose target
538
543
  isn't on screen is **dropped rather than faked** β€” an empty cockpit has no
539
- agent menu, so it gets a shorter tour instead of a spotlight on nothing. The
544
+ agent menu, a cockpit with no group has no groups column, a member has no
545
+ Reports button β€” so it gets a shorter tour instead of a spotlight on nothing.
546
+ The bubble sits below its target, above it, or **beside** it when the target
547
+ is a full-height column, so it never covers what it describes. The
540
548
  **phone gets the whole tour**, because a step can name the landmark on either
541
549
  layout (the agents column *or* the channel picker) and is framed on whichever
542
550
  one is rendered. On a brand-new instance it comes **before** the sign-in card
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shadok-ai",
3
- "version": "0.19.27",
3
+ "version": "0.19.29",
4
4
  "main": "dist/session.js",
5
5
  "scripts": {
6
6
  "test": "node --import tsx --test --test-timeout=120000 test/*.ts context/*/test/*.test.mjs",
@@ -1,26 +1,41 @@
1
1
  /**
2
- * A link to ONE message of an agent's conversation, for someone who already has
3
- * access to this cockpit. Pure, so the browser and test/deep-link.test.ts share
4
- * it. Design: docs/superpowers/specs/2026-10-21-message-deep-link-design.md.
2
+ * A link to ONE message of a conversation β€” an agent's or a room's β€” for someone
3
+ * who already has access to this cockpit. Pure, so the browser and
4
+ * test/deep-link.test.ts share it. Design:
5
+ * docs/superpowers/specs/2026-10-21-message-deep-link-design.md.
5
6
  *
6
7
  * The state rides in the HASH, never the query: a fragment never reaches the
7
- * server, a proxy or its logs. The agent is named by its FULL session id β€” a
8
- * shortened one is not an id (invariant 36) β€” and the message by its transcript
9
- * uuid.
8
+ * server, a proxy or its logs. The conversation is named by its FULL id β€” an
9
+ * agent by its session uuid (a shortened one is not an id, invariant 36), a room
10
+ * by its `r_…` id β€” and the message by its uuid (a transcript uuid for an agent,
11
+ * the message's own uuid for a room).
10
12
  */
11
13
 
12
- // A session id and a transcript uuid are both UUIDs; anything else is refused
14
+ // A session id and a message uuid are both UUIDs; anything else is refused
13
15
  // rather than half-trusted, since the parsed values end up in a CSS selector.
14
16
  const ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
17
+ // A room id (ROOM_ID_RE in src/rooms.ts): `r_` + 16 hex, never UUID-shaped, so
18
+ // `agent=` and `room=` can never be confused for one another.
19
+ const ROOM = /^r_[0-9a-f]{16}$/i;
15
20
 
16
- /** `base` is origin + path (no hash); returns the shareable URL. */
21
+ /** `base` is origin + path (no hash); returns the shareable URL to an AGENT's
22
+ * message, or null. */
17
23
  export function buildMessageLink(base, sessionId, msgId) {
18
24
  if (!ID.test(String(sessionId ?? "")) || !ID.test(String(msgId ?? ""))) return null;
19
25
  const at = String(base ?? "").split("#")[0];
20
26
  return `${at}#agent=${sessionId.toLowerCase()}&msg=${msgId.toLowerCase()}`;
21
27
  }
22
28
 
23
- /** `location.hash` β†’ `{ agent, msg }`, or null for anything else. Never throws. */
29
+ /** `base` is origin + path (no hash); returns the shareable URL to a ROOM's
30
+ * message, or null. */
31
+ export function buildRoomMessageLink(base, roomId, msgId) {
32
+ if (!ROOM.test(String(roomId ?? "")) || !ID.test(String(msgId ?? ""))) return null;
33
+ const at = String(base ?? "").split("#")[0];
34
+ return `${at}#room=${roomId.toLowerCase()}&msg=${msgId.toLowerCase()}`;
35
+ }
36
+
37
+ /** `location.hash` β†’ `{ agent, msg }` or `{ room, msg }`, or null for anything
38
+ * else. Never throws. `agent=` wins if both are somehow present. */
24
39
  export function parseMessageLink(hash) {
25
40
  const raw = String(hash ?? "").replace(/^#/, "");
26
41
  if (!raw) return null;
@@ -31,9 +46,12 @@ export function parseMessageLink(hash) {
31
46
  return null;
32
47
  }
33
48
  const agent = params.get("agent") ?? "";
49
+ const room = params.get("room") ?? "";
34
50
  const msg = params.get("msg") ?? "";
35
- if (!ID.test(agent) || !ID.test(msg)) return null;
36
- return { agent: agent.toLowerCase(), msg: msg.toLowerCase() };
51
+ if (!ID.test(msg)) return null;
52
+ if (ID.test(agent)) return { agent: agent.toLowerCase(), msg: msg.toLowerCase() };
53
+ if (ROOM.test(room)) return { room: room.toLowerCase(), msg: msg.toLowerCase() };
54
+ return null;
37
55
  }
38
56
 
39
57
  /** Does a prompt the transcript recorded match the bubble the client echoed?
package/public/index.html CHANGED
@@ -4595,8 +4595,9 @@
4595
4595
  import { connectCardPlan, sameConnectTarget } from "/connect-card.js?v=__ASSET_V__";
4596
4596
  window.connectCardPlan = connectCardPlan;
4597
4597
  window.sameConnectTarget = sameConnectTarget;
4598
- import { buildMessageLink, parseMessageLink, samePrompt } from "/deep-link.js?v=__ASSET_V__";
4598
+ import { buildMessageLink, buildRoomMessageLink, parseMessageLink, samePrompt } from "/deep-link.js?v=__ASSET_V__";
4599
4599
  window.buildMessageLink = buildMessageLink;
4600
+ window.buildRoomMessageLink = buildRoomMessageLink;
4600
4601
  window.parseMessageLink = parseMessageLink;
4601
4602
  window.samePrompt = samePrompt;
4602
4603
  import { GROUP_ICONS, UNGROUPED, randomGroupIcon, resolveGroupView, groupMood, cleanGroupIcon, reconcileTabGroup, groupIsDirty, focusTarget, groupMoveRefusal } from "/group-nav.js?v=__ASSET_V__";
@@ -4805,6 +4806,7 @@
4805
4806
  // No module β†’ no link button, and a link opened before it lands is read
4806
4807
  // again on `shadok-bridge-ready`.
4807
4808
  buildMessageLink: () => null,
4809
+ buildRoomMessageLink: () => null,
4808
4810
  parseMessageLink: () => null,
4809
4811
  samePrompt: () => false,
4810
4812
  // The rail must paint even before the module lands: a plain folder icon, the
@@ -8527,10 +8529,11 @@
8527
8529
  }
8528
8530
 
8529
8531
  /**
8530
- * Give a bubble its transcript ids and a "link" button. The link names the
8531
- * FIRST id; the lookup is by membership (`[data-msg-ids~=…]`), because live
8532
- * every text block is its own bubble while the replay merges them β€” so a link
8533
- * made on either side finds its message on the other.
8532
+ * Give a bubble its message ids and a "link" button. The link names the FIRST
8533
+ * id; the lookup is by membership (`[data-msg-ids~=…]`), because live every
8534
+ * text block is its own bubble while the replay merges them β€” so a link made on
8535
+ * either side finds its message on the other. Works for an agent (by session
8536
+ * id) and a room (by room id); a room message carries a single uuid.
8534
8537
  */
8535
8538
  function stampMsgIds(tab, turn, ids) {
8536
8539
  if (!turn || !Array.isArray(ids) || !ids.length || turn.dataset.msgIds) return;
@@ -8544,7 +8547,10 @@
8544
8547
  b.title = "Copy a link to this message (for someone with access to this cockpit)";
8545
8548
  b.addEventListener("click", async (e) => {
8546
8549
  e.stopPropagation();
8547
- const url = window.buildMessageLink(location.origin + location.pathname, tab.sessionId, ids[0]);
8550
+ const base = location.origin + location.pathname;
8551
+ const url = tab.roomId
8552
+ ? window.buildRoomMessageLink(base, tab.roomId, ids[0])
8553
+ : window.buildMessageLink(base, tab.sessionId, ids[0]);
8548
8554
  const ok = !!url && (await copyText(url));
8549
8555
  b.textContent = ok ? "βœ“ link copied" : "⚠ failed";
8550
8556
  b.classList.toggle("done", ok);
@@ -8602,10 +8608,12 @@
8602
8608
  const link = window.parseMessageLink(location.hash);
8603
8609
  if (!link) return;
8604
8610
  if (restoring) { deepLinkTimer = setTimeout(followDeepLink, 200); return; }
8605
- const tab = tabs.find((t) => t.sessionId === link.agent);
8611
+ const tab = link.room
8612
+ ? tabs.find((t) => t.roomId === link.room)
8613
+ : tabs.find((t) => t.sessionId === link.agent);
8606
8614
  if (!tab) {
8607
8615
  clearDeepLinkHash();
8608
- deepLinkNote("This link points to an agent that is not on this cockpit (closed, or another instance).");
8616
+ deepLinkNote("This link points to a conversation that is not on this cockpit (closed, or another instance).");
8609
8617
  return;
8610
8618
  }
8611
8619
  pendingDeepLink = { tab, msg: link.msg, until: Date.now() + 20000 };
@@ -8627,7 +8635,7 @@
8627
8635
  if (Date.now() > until) {
8628
8636
  pendingDeepLink = null;
8629
8637
  clearDeepLinkHash();
8630
- deepLinkNote("This message is older than the history shown for this agent.");
8638
+ deepLinkNote("This message is older than the history shown for this conversation.");
8631
8639
  return;
8632
8640
  }
8633
8641
  deepLinkTimer = setTimeout(followDeepLink, 300);
@@ -11491,7 +11499,9 @@
11491
11499
  const label = own ? "you" : echoAuthorLabel({ from: m.author, origin: m.origin });
11492
11500
  const b = addTurn(tab, "user", label, m.text, null, m.ts);
11493
11501
  markPromptSide(b, { from: m.account || m.author, origin: m.origin });
11494
- b.parentElement.dataset.roomMsg = m.id;
11502
+ // A room message's uuid is its own id (randomUUID, server-side): it doubles
11503
+ // as the deep-link anchor, like an agent bubble's transcript id.
11504
+ stampMsgIds(tab, b.parentElement, [m.id]);
11495
11505
  tab.lastRoomTs = Math.max(tab.lastRoomTs || 0, m.ts);
11496
11506
  return b;
11497
11507
  }
@@ -8,8 +8,16 @@
8
8
  // See docs/superpowers/specs/2026-08-11-guided-tour-design.md.
9
9
 
10
10
  /**
11
- * The tour, grouped on purpose: a spotlight frames a REGION, so nine landmarks
12
- * fit in four stops. A step per button is a tour people abandon.
11
+ * The tour, grouped on purpose: a spotlight frames a REGION, so some thirty
12
+ * controls fit in ten stops. A step per button is a tour people abandon.
13
+ *
14
+ * It is also a set of CLAIMS about the page, and the page moves faster than
15
+ * this file: it sat at six steps while the cockpit gained groups, rooms, the
16
+ * Skill Factory, webhooks, a composer with three buttons, accounts and a
17
+ * settings menu β€” none of which a first-time visitor was shown. So when a
18
+ * landmark is added to the page, it is added to a step here (or gets its own),
19
+ * in the same change. `test/tour-steps.test.ts` holds the list of what must be
20
+ * named; it cannot notice a landmark nobody told it about.
13
21
  *
14
22
  * `target` is a CSS selector, an array of them (framed as one rectangle), or
15
23
  * null for the centred welcome card.
@@ -31,13 +39,30 @@ export const TOUR_STEPS = [
31
39
  "You drive them from this page β€” or from Telegram, where one topic is one agent.",
32
40
  target: null,
33
41
  },
42
+ {
43
+ id: "groups",
44
+ title: "Groups sort the work",
45
+ // Says "can also be a wall" rather than listing private/restricted as
46
+ // things to click: a single-tenant instance (the `npx` default) refuses to
47
+ // create either, and a tour promising a control that answers "not here" is
48
+ // the copy twin of a spotlight on empty space.
49
+ body:
50
+ "Agents are filed into groups β€” one per project, team or subject. Pick a group to " +
51
+ "narrow the list to it. On a cockpit set up for several people a group can also be a " +
52
+ "wall: restricted to a team or private to you, with its own secrets, and agents that " +
53
+ "run apart from everyone else's.",
54
+ // The rail is hidden when there is nothing to show in it, and a phone lists
55
+ // the groups inside the closed agents sheet β€” both drop this step honestly.
56
+ target: "#groupRail",
57
+ },
34
58
  {
35
59
  id: "agents",
36
60
  title: "Your agents live here",
37
61
  body:
38
62
  "Every agent gets its own git worktree and branch, so several never collide. " +
39
63
  "Pick one here to follow it, and β€œοΌ‹ New agent” starts another. One of them is this " +
40
- "cockpit's home agent: the only one that cannot be closed.",
64
+ "cockpit's home agent: the only one that cannot be closed. A room is the exception: " +
65
+ "a conversation between people, with no agent behind it and no quota spent.",
41
66
  // The column on desktop, the agents-picker button on a phone β€” never both at
42
67
  // once. The phone's `#chanPicker` opens the SAME column as a bottom sheet, so
43
68
  // "οΌ‹ New agent" and Tweak are reachable there too now β€” but the spotlight
@@ -47,12 +72,26 @@ export const TOUR_STEPS = [
47
72
  // moment of the spotlight is the same failure as a spotlight on empty space.
48
73
  target: ["#tabbar", "#chanPicker"],
49
74
  },
75
+ {
76
+ id: "bar",
77
+ title: "Look inside an agent",
78
+ // A list of functions, not of icons in a row β€” see the toolbar step for
79
+ // what "left to right" cost. Schedule and webhooks sit inside this frame
80
+ // too and are deliberately NOT described here: they get their own stop.
81
+ body:
82
+ "The bar above the conversation is about the agent on screen. The gallery gathers " +
83
+ "every photo and video exchanged with it, β€œAbout” lists the skills it uses and its " +
84
+ "schedules, and the terminal shows the raw Claude Code screen β€” for the rare moment " +
85
+ "the chat is not enough.",
86
+ target: ["#chanGallery", "#chanCron", "#chanWebhooks", "#chanInfo", "#chanTerm"],
87
+ },
50
88
  {
51
89
  id: "tab",
52
90
  title: "Each agent has its own menu",
53
91
  body:
54
- "This β‹― holds an agent's controls: mute, reload, rename, change its profile, mirror it " +
55
- "to a Telegram topic, or have it report to another agent when it finishes. " +
92
+ "This β‹― holds an agent's controls: mute, reload, rename, change its profile, its model " +
93
+ "or how hard it thinks, read its token stats, mirror it to a Telegram topic, or have " +
94
+ "it report to another agent when it finishes. " +
56
95
  "β€œContext sent” shows exactly what shadok told it at spawn β€” and, except for the home " +
57
96
  "agent, this is where you close it.",
58
97
  // `#chanMenu`, NOT `.tab.active`. Two reasons, and the second is why it
@@ -70,11 +109,26 @@ export const TOUR_STEPS = [
70
109
  // prominent thing in the tour, and a first-time visitor never met it.
71
110
  id: "schedule",
72
111
  title: "They can work while you're away",
112
+ // It said "in that same β‹― menu" and pointed at the menu, which stayed true
113
+ // (the entries are still there) while the bar grew a button for each β€” so
114
+ // the tour described a detour past the control in plain sight. It frames
115
+ // the two buttons now, and the menu remains the fallback target for a
116
+ // layout that would not render them.
73
117
  body:
74
- "β€œSchedule”, in that same β‹― menu, pairs a recurring prompt with a shell check that runs " +
75
- "without the model. Silent check β†’ nothing happened, the agent stays asleep at zero " +
76
- "tokens. Otherwise it wakes up holding the finding, and tells you here or on Telegram.",
77
- target: "#chanMenu",
118
+ "A schedule pairs a recurring prompt with a shell check that runs without the model. " +
119
+ "Silent check β†’ nothing happened, the agent stays asleep at zero tokens. Otherwise it " +
120
+ "wakes up holding the finding, and tells you here or on Telegram. A webhook is the " +
121
+ "same idea from outside: an HTTP call from another system wakes the agent.",
122
+ target: ["#chanCron", "#chanWebhooks"],
123
+ },
124
+ {
125
+ id: "composer",
126
+ title: "Talk to it β€” with more than text",
127
+ body:
128
+ "Write to the agent here. Attach a file, or paste or drop one in; add one of its " +
129
+ "skills to the prompt; or dictate instead of typing. It works the other way too: " +
130
+ "when an agent's result is a file, it arrives in the conversation as a download.",
131
+ target: "#composer",
78
132
  },
79
133
  {
80
134
  id: "tools",
@@ -90,9 +144,10 @@ export const TOUR_STEPS = [
90
144
  // no test here can hold; a list of functions is not.
91
145
  body:
92
146
  "The secret vault injected into agents that need it, the shared ledger of what your " +
93
- "agents have already resolved, profiles (role, guardrails, model), Telegram, and the " +
94
- "notification sound. On a narrow screen they fold into the β‹― β€” which also holds the " +
95
- "diff of an agent's work, the palette, and replays this tour.",
147
+ "agents have already resolved, the Skill Factory where skills are written, released " +
148
+ "and shared, profiles (role, guardrails, model), Telegram, and the notification sound. " +
149
+ "On a narrow screen they fold into the β‹― β€” which also holds the diff of an agent's " +
150
+ "work, the whole instance's stats, light or dark mode, the palette, and this tour.",
96
151
  // NOT `.hdr-tools`, which is `display: contents` on desktop and therefore
97
152
  // generates no box at all β€” its rect is all zeros, so the step would have
98
153
  // been dropped as "not visible" on the very layout where the toolbar is
@@ -107,23 +162,58 @@ export const TOUR_STEPS = [
107
162
  "#usersBtn",
108
163
  "#secretsBtn",
109
164
  "#ledgerBtn",
165
+ "#factoryBtn",
110
166
  "#profilesBtn",
167
+ "#securityBtn",
168
+ "#reportsBtn",
111
169
  "#telegramBtn",
112
170
  "#muteNotif",
113
171
  "#moreBtn",
114
172
  "#starBtn",
115
173
  ],
116
174
  },
175
+ {
176
+ id: "people",
177
+ title: "People, not only agents",
178
+ // Its own step BECAUSE it is conditional: all three buttons start `hidden`
179
+ // and which ones show depends on the role (`loadMe`). Folded into the
180
+ // toolbar body they would be named to people who do not have them. Here the
181
+ // step is dropped when none is rendered β€” the tour's one rule β€” and the
182
+ // body says "depends on your role" for the partial case.
183
+ //
184
+ // It does NOT say "this instance has accounts": the lone admin of a
185
+ // no-password instance sees all three, and has none.
186
+ body:
187
+ "A few buttons are about people rather than agents β€” which ones you see depends on " +
188
+ "your role. Users is where people are invited and where you add a passkey for " +
189
+ "two-factor sign-in, Reports is where a stuck agent asks an admin for help, and " +
190
+ "Security shows what happened to your own account.",
191
+ target: ["#securityBtn", "#reportsBtn", "#usersBtn"],
192
+ },
117
193
  {
118
194
  id: "quota",
119
195
  title: "Watch your quota",
120
196
  body:
121
197
  "Your 5h and 7d subscription usage. Each bar fills with what you've spent, and the " +
122
198
  "white marker is the pace that would spend the window exactly on time β€” a fill past " +
123
- "the marker means you're burning faster. To the left, the cockpit's name is yours to " +
124
- "change, and the version beside it opens updates and the permission mode.",
199
+ "the marker means you're burning faster. Past the pace, a new prompt is held back " +
200
+ "unless you choose to send it anyway.",
125
201
  target: ["#quota5h", "#quota7d"],
126
202
  },
203
+ {
204
+ id: "settings",
205
+ title: "The cockpit's own settings",
206
+ // Was one trailing sentence of the quota step ("to the left… the version
207
+ // beside it"), i.e. a position, on a control the spotlight was not on. The
208
+ // menu behind the version has since become where an instance is configured,
209
+ // which a clause could no longer carry.
210
+ body:
211
+ "The name tells this cockpit apart when you run several; an admin can change it. The " +
212
+ "version opens this instance's settings, most of them an admin's: the Claude account " +
213
+ "and when its sign-in expires, updates and their channel, the permission mode and " +
214
+ "default model for new agents, and the instance context every agent here receives.",
215
+ target: ["#brandName", "#verView", "#verChan"],
216
+ },
127
217
  ];
128
218
 
129
219
  /** Pure: the steps whose target is on screen, in order. */
@@ -167,12 +257,34 @@ const clamp = (v, lo, hi) => Math.max(lo, Math.min(v, hi));
167
257
  *
168
258
  * Below by default, flipped above when it would overflow the bottom, and
169
259
  * clamped to the viewport on both axes so it is never partly off screen.
260
+ *
261
+ * BESIDE when neither fits, which is every full-height column. Flipping above
262
+ * a target that starts near the top has nowhere to go, so the clamp dropped
263
+ * the bubble ON the column it was describing: the groups step hid the very
264
+ * group names it was pointing at, under a card explaining what groups are.
265
+ * Clamped is "on screen", not "out of the way" β€” only a side placement is
266
+ * both. When no side has room either (a phone), the old clamp still applies:
267
+ * covering part of the target beats leaving the viewport.
170
268
  */
171
269
  export function bubblePlacement({ target, bubble, viewport, gap = 12 }) {
172
270
  const below = target.top + target.height + gap;
173
271
  const fitsBelow = below + bubble.height + gap <= viewport.height;
272
+ const above = target.top - bubble.height - gap;
273
+ if (!fitsBelow && above < gap) {
274
+ const right = target.left + target.width + gap;
275
+ const left = target.left - bubble.width - gap;
276
+ const beside =
277
+ right + bubble.width + gap <= viewport.width ? right : left >= gap ? left : null;
278
+ if (beside !== null) {
279
+ return {
280
+ side: beside === right ? "right" : "left",
281
+ top: clamp(target.top, gap, viewport.height - bubble.height - gap),
282
+ left: beside,
283
+ };
284
+ }
285
+ }
174
286
  const side = fitsBelow ? "below" : "above";
175
- const rawTop = fitsBelow ? below : target.top - bubble.height - gap;
287
+ const rawTop = fitsBelow ? below : above;
176
288
  const rawLeft = target.left + target.width / 2 - bubble.width / 2;
177
289
  return {
178
290
  side,