diff --git a/api/asyncapi.yaml b/api/asyncapi.yaml index 2a8ccd1bf1..6a65b2ff3a 100644 --- a/api/asyncapi.yaml +++ b/api/asyncapi.yaml @@ -1347,6 +1347,21 @@ components: - string - "null" description: The Bot that wrote the newest message, or null when a person did. + lastTurnInitiator: + type: + - string + - "null" + x-extensible-enum: + - person + - routine + - task + description: >- + Who started the turn the newest message belongs to: the person + (person), a routine, check-in or goal (routine), or a task a Bot + handed the work to (task), as the conversation's lastTurnInitiator + in the list says it. Null when the server can't say. Absent from a + server older than this, and then the client knows nothing of who + started it. firstLine: type: string description: A Bot's reply, its first line as plain text. Only on a Bot's message. diff --git a/api/openapi.yaml b/api/openapi.yaml index 7b7766c8b8..1c5c3e4bf7 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -34646,6 +34646,15 @@ components: - string - 'null' description: The Bot that said it, or null when a person did. + lastTurnInitiator: + type: + - string + - 'null' + x-extensible-enum: + - person + - routine + - task + description: 'Who started the turn the last thing said in it belongs to: the person (person), a routine, check-in or goal (routine), or a task a Bot handed the work to (task). With a Bot''s message last, routine means a routine spoke last and nobody has written since. Null when nothing has been said, or when the last message is older than the server''s keeping it. Absent from a server that predates it. An app reads null, absence and a value it doesn''t know alike: as nothing known about who started it.' createdAt: type: string format: date-time diff --git a/api/openapi/conversations.yaml b/api/openapi/conversations.yaml index c7ed809496..ba114c2889 100644 --- a/api/openapi/conversations.yaml +++ b/api/openapi/conversations.yaml @@ -2911,6 +2911,18 @@ components: - string - 'null' description: The Bot that said it, or null when a person did. + lastTurnInitiator: + type: [string, 'null'] + x-extensible-enum: [person, routine, task] + description: >- + Who started the turn the last thing said in it belongs to: the + person (person), a routine, check-in or goal (routine), or a task a + Bot handed the work to (task). With a Bot's message last, routine + means a routine spoke last and nobody has written since. Null when + nothing has been said, or when the last message is older than the + server's keeping it. Absent from a server that predates it. An app + reads null, absence and a value it doesn't know alike: as nothing + known about who started it. createdAt: type: string format: date-time diff --git a/app/src/components/agents/bot-orb.tsx b/app/src/components/agents/bot-orb.tsx index 05a6f0c6fe..92234db09b 100644 --- a/app/src/components/agents/bot-orb.tsx +++ b/app/src/components/agents/bot-orb.tsx @@ -269,6 +269,18 @@ export function BotOrbArt({ */ export type BotOrbState = "idle" | "working" | "waiting"; +/** + * What started what the orb's Bot said last, when that is worth showing, drawn inside the orb + * (styles.css, `.bot-orb[data-started-by]`) beside whatever its state draws around it. + * + * - `routine`: a routine (a schedule, a check-in, a goal) spoke last, and nobody has written since. + * A small clock inside the orb: a pale, soft dial and one slim hand at one o'clock, a shade deeper + * than the orb, so a routine's conversation reads apart from the person's own. + * + * A trigger's run can be one more name here, or wear the same clock. + */ +export type BotOrbStartedBy = "routine"; + /** * The one color an orb reads as from a step back: halfway between its ground's two colors, the * sweep from the top left to the foot that the rest of the drawing lights. What a state draws in the @@ -284,19 +296,22 @@ export function orbColor({ silk: { from, to } }: OrbLook): string { * color. One drawing at every size, folds and all, so a Bot is the same in the sidebar, at the top * of its page and at the top of a conversation. * - * Its `state` is drawn around it (`BotOrbState`). The orb names the Bot alone: what a state means - * in words is the caller's to say, where it says the rest. Nothing moves under reduced motion. + * Its `state` is drawn around it (`BotOrbState`), and what started what it said last inside it + * (`startedBy`). The orb names the Bot alone: what either means in words is the caller's to say, + * where it says the rest. Nothing moves under reduced motion. */ export function BotOrb({ seed, name, size = 32, state = "idle", + startedBy, }: { seed: string; name: string; size?: number; state?: BotOrbState; + startedBy?: BotOrbStartedBy; }) { const look = orbLook(seed); return ( @@ -304,6 +319,7 @@ export function BotOrb({ aria-label={name} className="bot-orb inline-block shrink-0 rounded-full" data-palette={look.name} + data-started-by={startedBy} data-state={state} data-variant={state === "working" ? "live" : "static"} role="img" diff --git a/app/src/components/app-sidebar/channel-item-content.tsx b/app/src/components/app-sidebar/channel-item-content.tsx index 6e1fccd4ee..e82a5a3795 100644 --- a/app/src/components/app-sidebar/channel-item-content.tsx +++ b/app/src/components/app-sidebar/channel-item-content.tsx @@ -19,6 +19,10 @@ import type { MessageListEmphasis } from "@/lib/settings/message-list"; * age line up before it. The pin used to come after the dot, and on a pinned row pushed it out of * the column. A row whose orb says it keeps no place for a dot. * + * A conversation a routine spoke in last, with nothing written since (`routine`), has a small clock + * drawn inside its Bot's orb (`BotOrb`'s `startedBy`), so a routine's conversations read apart from + * the person's own at a glance. Like the arcs it needs a lone orb, and draws nothing elsewhere. + * * While its Bot works, the row says what the Bot is doing at the right, in place of the age and in * the age's muted style: `status`, or "Working" while `busy`. No line is added, so a row keeps its * height when a Bot starts or stops and the rows under it don't move. @@ -37,6 +41,7 @@ export function ChannelItemContent({ busy = false, status, unread = false, + routine = false, pinned = false, revealing = false, view = "detailed", @@ -52,6 +57,8 @@ export function ChannelItemContent({ /** What the Bot is doing, said in place of the age. "Working" while `busy` if not given. */ status?: string; unread?: boolean; + /** Whether a routine spoke last and nobody has written since: a clock in the orb. */ + routine?: boolean; pinned?: boolean; revealing?: boolean; view?: ConversationView; @@ -118,6 +125,7 @@ export function ChannelItemContent({
) : ( @@ -124,10 +132,12 @@ function OrbFace({ id, size, state = "idle", + startedBy, }: { id: string; size: number; state?: BotOrbState; + startedBy?: BotOrbStartedBy; }) { const { data: bot } = useQuery({ ...agentListQueryOptions(), @@ -139,6 +149,7 @@ function OrbFace({ name={bot?.name ?? ""} seed={bot?.avatarSeed ?? id} size={size} + startedBy={startedBy} state={state} /> diff --git a/app/src/lib/api/generated/conversations/conversations.zod.ts b/app/src/lib/api/generated/conversations/conversations.zod.ts index 75ffb87fca..aa479efdfa 100644 --- a/app/src/lib/api/generated/conversations/conversations.zod.ts +++ b/app/src/lib/api/generated/conversations/conversations.zod.ts @@ -224,6 +224,12 @@ export const ListConversationsResponse = zod.object({ .string() .nullable() .describe("The Bot that said it, or null when a person did."), + lastTurnInitiator: zod + .string() + .nullish() + .describe( + "Who started the turn the last thing said in it belongs to: the person (person), a routine, check-in or goal (routine), or a task a Bot handed the work to (task). With a Bot's message last, routine means a routine spoke last and nobody has written since. Null when nothing has been said, or when the last message is older than the server's keeping it. Absent from a server that predates it. An app reads null, absence and a value it doesn't know alike: as nothing known about who started it.", + ), createdAt: zod.iso .datetime({ offset: true }) .describe("When it was started."), diff --git a/app/src/lib/api/generated/model/conversationSummary.ts b/app/src/lib/api/generated/model/conversationSummary.ts index 2784552b3b..48adad9800 100644 --- a/app/src/lib/api/generated/model/conversationSummary.ts +++ b/app/src/lib/api/generated/model/conversationSummary.ts @@ -42,6 +42,11 @@ export interface ConversationSummary { * @nullable */ lastMessageBotId: string | null; + /** + * Who started the turn the last thing said in it belongs to: the person (person), a routine, check-in or goal (routine), or a task a Bot handed the work to (task). With a Bot's message last, routine means a routine spoke last and nobody has written since. Null when nothing has been said, or when the last message is older than the server's keeping it. Absent from a server that predates it. An app reads null, absence and a value it doesn't know alike: as nothing known about who started it. + * @nullable + */ + lastTurnInitiator?: string | null; /** When it was started. */ createdAt: string; /** Whether the caller pinned it. */ diff --git a/app/src/lib/channels/queries.ts b/app/src/lib/channels/queries.ts index cabc47bd95..aa077f6c5d 100644 --- a/app/src/lib/channels/queries.ts +++ b/app/src/lib/channels/queries.ts @@ -95,6 +95,12 @@ export type ChannelSummary = AgentChannel & { opening?: string | null; lastMessage: string | null; lastMessageAgentId: string | null; + /** + * Who started the turn the last message belongs to: `person`, `routine` (a routine, check-in or + * goal) or `task`, or another the server adds later. Null or absent when the server can't say, or + * predates saying it (`routineSpokeLast`). + */ + lastTurnInitiator?: string | null; /** ISO-8601. Ordering falls back to this, so a channel just created sorts to the top. */ createdAt: string; /** Whether this member pinned the channel. Pinned channels sort first in the roster. */ @@ -346,6 +352,21 @@ export function listedChannel( .find((one) => one.id === channelId); } +/** + * Whether a routine spoke last in a conversation and nobody has written since: the last message is a + * Bot's, in a turn a routine started. A person's message starts a turn of their own, so it ends + * this. Read only from what the server says; one that says nothing of who started the turn shows + * none. + */ +export function routineSpokeLast( + channel: Pick, +): boolean { + return ( + channel.lastTurnInitiator === "routine" && + channel.lastMessageAgentId !== null + ); +} + /** * A conversation as the API answers it, in the names the app's screens and its socket events use: * the API calls a conversation's Bots `botIds`. diff --git a/app/src/lib/channels/use-channel-events.ts b/app/src/lib/channels/use-channel-events.ts index 3519bf75b3..8f92e45cef 100644 --- a/app/src/lib/channels/use-channel-events.ts +++ b/app/src/lib/channels/use-channel-events.ts @@ -136,6 +136,11 @@ export type ChannelActivityEvent = { lastMessage: string | null; lastMessageAt: string | null; lastMessageAgentId: string | null; + /** + * Who started the turn the newest message belongs to, as the list's `lastTurnInitiator`. Absent + * from a server older than this, and then the row knows nothing of it (`applyChannelEvent`). + */ + lastTurnInitiator?: string | null; /** * A Bot's reply, its first line as plain text, for the notice a reply raises while OpenBot is out * of sight. `lastMessage` runs every line into one. Only on a Bot's message, and absent from a @@ -294,7 +299,16 @@ export function applyChannelEvent( // Preserve object identity for unchanged rows so memoized rows do not re-render. const next = page.channels.slice(); - next[index] = { ...previous, ...activity }; + /* + * Who started the turn goes with the message it is about. An event that says nothing of it, from + * a server older than `lastTurnInitiator`, leaves the row saying nothing either: the old message's + * would be wrong for the new one. + */ + const { lastTurnInitiator: _, ...unsaid } = previous; + next[index] = { + ...(activity.lastTurnInitiator === undefined ? unsaid : previous), + ...activity, + }; next.sort(byRecency); // An event that changes nothing visible, a duplicate, or a report the server ignored as stale, diff --git a/app/src/styles.css b/app/src/styles.css index 1dc19134f3..bcfcc95618 100644 --- a/app/src/styles.css +++ b/app/src/styles.css @@ -825,6 +825,85 @@ } } +/* + * A Bot whose routine spoke last (`BotOrb`'s `startedBy` "routine"): a small clock inside its orb, + * so a routine's conversation reads apart from the person's own. A pale, soft-edged dial breathed + * into the middle of the orb, and one slim hand on a small pivot pointing at one o'clock, just past + * the hour, the moment a scheduled run has fired. + * + * The dial is no drawn line: a disc of white light at under a third of its strength, a little + * brighter just inside its edge and fading out by three quarters of the orb's radius, so the middle + * reads as a glassy face with no outline. On it, one hand tapering from its pivot to a round tip, in + * the orb's own color (`--bot-orb-color`, set on the orb) pressed a fifth deeper: a shade, not ink. + * `black` there is only the mixing partner for that depth, and in the masks only alpha; the white + * in the paint is literal because a data URI can't read a variable. + * + * All of it is on `::after`, `inset: 0`, inside the circle, so it never meets the waiting arcs + * (`::before`, outside at the upper right). The hand is drawn in the orb's 24 units and the face in + * fractions of its radius, so it is the same mark at 20, 24 and 32px. The orb's own drawing is + * untouched. + * + * It fades in once, with the app's entrance (200ms, lib/motion.ts); under reduced motion it is + * simply there. + */ +.bot-orb[data-started-by="routine"] { + --bot-orb-hand: color-mix(in oklab, var(--bot-orb-color) 80%, black); +} + +.bot-orb[data-started-by="routine"]::after { + content: ""; + position: absolute; + inset: 0; + border-radius: 50%; + pointer-events: none; + /* + * Paint: white everywhere except where the hand is (an SVG, `white` because a data URI cannot read + * a variable), over the hand's color, which shows through only there. The mask decides how much + * of each is seen. + */ + background: + url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3E%3Cdefs%3E%3Cmask%20id='k'%3E%3Crect%20width='24'%20height='24'%20fill='white'/%3E%3Cg%20stroke='black'%20fill='black'%20stroke-linecap='round'%3E%3Cpath%20d='M12.76%2012.44L15.61%206.69L14.79%206.22L11.24%2011.56Z'%20stroke='none'/%3E%3Ccircle%20cx='15.20'%20cy='6.46'%20r='0.47'%20stroke='none'/%3E%3Ccircle%20cx='12'%20cy='12'%20r='1.2'%20stroke='none'/%3E%3C/g%3E%3C/mask%3E%3C/defs%3E%3Crect%20width='24'%20height='24'%20fill='white'%20mask='url%28%23k%29'/%3E%3C/svg%3E") + center / 100% 100% no-repeat, + var(--bot-orb-hand); + /* + * Alpha only (black in the SVG is alpha): the hand at full strength, over the face, a disc at 30% + * out to 53% of the orb's radius, rising to 44% (4/9) at 65% and gone by 75% (9 of 12 units). + */ + -webkit-mask-image: + url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3E%3Cg%20stroke='black'%20fill='black'%20stroke-linecap='round'%3E%3Cpath%20d='M12.76%2012.44L15.61%206.69L14.79%206.22L11.24%2011.56Z'%20stroke='none'/%3E%3Ccircle%20cx='15.20'%20cy='6.46'%20r='0.47'%20stroke='none'/%3E%3Ccircle%20cx='12'%20cy='12'%20r='1.2'%20stroke='none'/%3E%3C/g%3E%3C/svg%3E"), + radial-gradient( + circle closest-side, + rgb(0 0 0 / 0.3) 0, + rgb(0 0 0 / 0.3) 53%, + rgb(0 0 0 / 0.44) 65%, + transparent 75% + ); + mask-image: + url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3E%3Cg%20stroke='black'%20fill='black'%20stroke-linecap='round'%3E%3Cpath%20d='M12.76%2012.44L15.61%206.69L14.79%206.22L11.24%2011.56Z'%20stroke='none'/%3E%3Ccircle%20cx='15.20'%20cy='6.46'%20r='0.47'%20stroke='none'/%3E%3Ccircle%20cx='12'%20cy='12'%20r='1.2'%20stroke='none'/%3E%3C/g%3E%3C/svg%3E"), + radial-gradient( + circle closest-side, + rgb(0 0 0 / 0.3) 0, + rgb(0 0 0 / 0.3) 53%, + rgb(0 0 0 / 0.44) 65%, + transparent 75% + ); + -webkit-mask-size: 100% 100%; + mask-size: 100% 100%; + -webkit-mask-repeat: no-repeat; + mask-repeat: no-repeat; +} + +@media (prefers-reduced-motion: no-preference) { + .bot-orb[data-started-by="routine"]::after { + transition: opacity 200ms cubic-bezier(0.23, 1, 0.32, 1); + } + @starting-style { + .bot-orb[data-started-by="routine"]::after { + opacity: 0; + } + } +} + /* * The field behind the OpenBot for Business orb (components/edition/business-orb.tsx): a tile of * orbs repeated, one tile taller than its box. It drifts up by exactly one tile per loop, so it diff --git a/app/tests/bot-orb.test.tsx b/app/tests/bot-orb.test.tsx index 2b79db11d6..19723844ae 100644 --- a/app/tests/bot-orb.test.tsx +++ b/app/tests/bot-orb.test.tsx @@ -64,6 +64,19 @@ test("an orb hands its size to what its state draws around it, so its arcs scale ); }); +test("an orb whose routine spoke last says so for its clock to be drawn by; others say nothing", () => { + const view = render( + <> + + + , + ); + const [routine, own] = view.getAllByRole("img"); + expect(routine?.dataset.startedBy).toBe("routine"); + expect(routine?.getAttribute("aria-label")).toBe("Digest"); + expect(own?.dataset.startedBy).toBeUndefined(); +}); + test("a working orb is live at any size", () => { const view = render( , diff --git a/app/tests/bots-panel-waiting-arcs.test.tsx b/app/tests/bots-panel-waiting-arcs.test.tsx index 7efd50b450..b5106f4423 100644 --- a/app/tests/bots-panel-waiting-arcs.test.tsx +++ b/app/tests/bots-panel-waiting-arcs.test.tsx @@ -19,7 +19,8 @@ import { test } from "./renderer-crash"; * A Bot that waits on the person says so with its orb in the Bots panel: two short arcs of the * orb's own color at its upper right, like a phone ringing. It was an orange dot at the end of the * Bot's row. In the Conversations panel a conversation with something new in it says so the same - * way, on its Bot's smaller orb, where it was a dot too. + * way, on its Bot's smaller orb, where it was a dot too. And one a routine spoke in last has a small + * clock drawn inside its orb, and nothing outside it. * * Rendered in a real browser, because what matters is what a person sees: that the arcs are drawn * where they should be, clear of the orb and never over it, with the surface between them and @@ -110,13 +111,27 @@ const READ = { lastReadAt: "2026-11-20T08:00:00.000Z", }; +/** Travel's conversation, where its routine spoke last, and unread. */ +const ROUTINE = { + ...CONVERSATION, + id: "c-3", + agentIds: ["travel"], + threadId: "t-c-3", + lastMessageAt: "2026-11-20T09:30:00.000Z", + summary: "Flights for next week", + lastMessage: "Flights for next week", + lastMessageAgentId: "travel", + lastTurnInitiator: "routine", + lastReadAt: "2026-11-20T09:00:00.000Z", +}; + /** What the server answers: a person of a company's own OpenBot with the Bots above. */ function answer(path: string, search: URLSearchParams): unknown { switch (path) { case `${ORGANIZATION}/conversations`: { const botId = search.get("botId"); return conversationPage( - [CONVERSATION, READ].filter( + [CONVERSATION, ROUTINE, READ].filter( (each) => !botId || each.agentIds.includes(botId), ), ); @@ -695,6 +710,135 @@ describe.skipIf(!asked)( } }, 120_000); + /* + * A conversation a routine spoke in last wears a small clock inside its Bot's orb. Drawn with + * the clock and again without it, the orb differs inside and not a pixel outside: not past its + * edge, and not in the waiting arcs beside it, since this one is unread too. + */ + test("in the Conversations panel, a conversation a routine spoke in last has a clock inside its orb and nothing outside, in light and dark", async () => { + for (const [engine, browser] of engines) { + for (const theme of THEMES) { + const page = await open(browser, { theme }); + try { + await page.getByRole("button", { name: /^Chats/ }).click(); + const conversations = page.locator('[data-slot="section-panel"]', { + has: page.getByRole("heading", { + level: 2, + name: "Conversations", + }), + }); + const row = (title: string) => + conversations.locator("a", { hasText: title }); + await row("Flights for next week").waitFor(); + await page.mouse.move(900, 600); + await still(page); + const routine = row("Flights for next week").locator(".bot-orb"); + expect({ + engine, + theme, + startedBy: await routine.getAttribute("data-started-by"), + state: await routine.getAttribute("data-state"), + others: await conversations + .locator(".bot-orb[data-started-by]") + .count(), + }).toEqual({ + engine, + theme, + startedBy: "routine", + state: "waiting", + others: 1, + }); + const box = await routine.boundingBox(); + if (!box) throw new Error("no orb"); + const clip = { + x: box.x - MARGIN, + y: box.y - MARGIN, + width: box.width + 2 * MARGIN, + height: box.height + 2 * MARGIN, + }; + // Every entrance on the orb done first, the arcs' and the clock's, so the two pictures + // differ by the clock alone. + const settled = () => + routine.evaluate((element) => + Promise.all( + element + .getAnimations({ subtree: true }) + .map((animation) => animation.finished), + ).then(() => undefined), + ); + await settled(); + const withClock = await page.screenshot({ clip }); + await routine.evaluate((element) => { + delete (element as HTMLElement).dataset.startedBy; + }); + await still(page); + await settled(); + const without = await page.screenshot({ clip }); + const seen = await page.evaluate( + async ({ a, b, margin, size }) => { + const decode = async (base64: string) => { + const image = new Image(); + image.src = `data:image/png;base64,${base64}`; + await image.decode(); + const canvas = document.createElement("canvas"); + canvas.width = image.naturalWidth; + canvas.height = image.naturalHeight; + const context = canvas.getContext("2d"); + if (!context) throw new Error("no 2d context"); + context.drawImage(image, 0, 0); + return context.getImageData( + 0, + 0, + canvas.width, + canvas.height, + ); + }; + const [one, two] = [await decode(a), await decode(b)]; + const scale = one.width / (size + 2 * margin); + const middle = (margin + size / 2) * scale; + let inside = 0; + let outside = 0; + for (let y = 0; y < one.height; y++) + for (let x = 0; x < one.width; x++) { + const at = (y * one.width + x) * 4; + const differs = Math.max( + Math.abs((one.data[at] ?? 0) - (two.data[at] ?? 0)), + Math.abs( + (one.data[at + 1] ?? 0) - (two.data[at + 1] ?? 0), + ), + Math.abs( + (one.data[at + 2] ?? 0) - (two.data[at + 2] ?? 0), + ), + ); + const reach = + Math.hypot(x + 0.5 - middle, y + 0.5 - middle) / scale; + if (reach < size / 2 - 1) + inside = Math.max(inside, differs); + else if (reach > size / 2 + 0.5) + outside = Math.max(outside, differs); + } + return { inside, outside }; + }, + { + a: withClock.toString("base64"), + b: without.toString("base64"), + margin: MARGIN, + size: box.width, + }, + ); + expect({ + engine, + theme, + drawnInside: seen.inside >= 48, + outside: seen.outside, + }).toEqual({ engine, theme, drawnInside: true, outside: 0 }); + } finally { + await page.close(); + } + } + } + }, 120_000); + /* The arcs come in once, as the state comes, and nothing about them repeats. */ test("the arcs arrive once, fading in and settling out from the orb; under reduced motion they only fade; nothing about them loops", async () => { for (const [engine, browser] of engines) { diff --git a/app/tests/channel-event-patch.test.ts b/app/tests/channel-event-patch.test.ts index 1c4dad71bb..2c93043a91 100644 --- a/app/tests/channel-event-patch.test.ts +++ b/app/tests/channel-event-patch.test.ts @@ -1,8 +1,9 @@ import { describe, expect, test } from "bun:test"; -import type { - AgentChannel, - ChannelPage, - ChannelSummary, +import { + type AgentChannel, + type ChannelPage, + type ChannelSummary, + routineSpokeLast, } from "../src/lib/channels/queries"; import { applyChannelEvent, @@ -87,6 +88,121 @@ describe("an ordinary activity event", () => { * The tab that issued the delete moves itself; every other tab only ever hears about it here, so * without this the row stays on their roster until something else makes them refetch. */ +/* + * Who started the turn goes with the message it is about: a routine's clock in the roster + * (`routineSpokeLast`) must never outlive the routine's message. + */ +describe("who started the newest message's turn", () => { + test("rides on the message: a routine's turn marks the row, and a person's next message clears it", () => { + const data = cache([channel("a")]); + const routine = applyChannelEvent( + data, + event({ + channelId: "a", + lastMessage: "Your morning digest.", + lastMessageAt: "2024-04-01T00:00:00.000Z", + lastMessageAgentId: "digest-bot", + lastTurnInitiator: "routine", + }), + ); + if (routine === "unknown") throw new Error("unknown"); + const row = routine.pages[0]?.channels[0] as ChannelSummary; + expect(row.lastTurnInitiator).toBe("routine"); + expect(routineSpokeLast(row)).toBe(true); + + const person = applyChannelEvent( + routine, + event({ + channelId: "a", + lastMessage: "Thanks, and the afternoon?", + lastMessageAt: "2024-04-01T00:05:00.000Z", + lastMessageAgentId: null, + lastTurnInitiator: "person", + }), + ); + if (person === "unknown") throw new Error("unknown"); + expect( + routineSpokeLast(person.pages[0]?.channels[0] as ChannelSummary), + ).toBe(false); + }); + + test("a message that says nothing of it, from an older server, leaves the row saying nothing either", () => { + const data = cache([ + channel("a", { + lastMessage: "Your morning digest.", + lastMessageAt: "2024-04-01T00:00:00.000Z", + lastMessageAgentId: "digest-bot", + lastTurnInitiator: "routine", + }), + ]); + const patched = applyChannelEvent( + data, + event({ + channelId: "a", + lastMessage: "Here is the afternoon too.", + lastMessageAt: "2024-04-01T00:10:00.000Z", + lastMessageAgentId: "digest-bot", + }), + ); + if (patched === "unknown") throw new Error("unknown"); + const row = patched.pages[0]?.channels[0] as ChannelSummary; + expect(row.lastTurnInitiator).toBeUndefined(); + expect(routineSpokeLast(row)).toBe(false); + }); + + test("a pin, a name or a busy signal leaves it as it was", () => { + const data = cache([ + channel("a", { + lastMessageAgentId: "digest-bot", + lastTurnInitiator: "routine", + }), + ]); + for (const extra of [ + { pinned: true }, + { summary: "Morning digest" }, + { busy: true }, + ]) { + const patched = applyChannelEvent( + data, + event({ channelId: "a", ...extra }), + ); + if (patched === "unknown") throw new Error("unknown"); + expect(patched.pages[0]?.channels[0]?.lastTurnInitiator).toBe("routine"); + } + }); +}); + +describe("a routine spoke last", () => { + test("only with a Bot's message last, in a turn a routine started", () => { + expect( + routineSpokeLast({ + lastTurnInitiator: "routine", + lastMessageAgentId: "digest-bot", + }), + ).toBe(true); + // A person's message last, whatever the turn. + expect( + routineSpokeLast({ + lastTurnInitiator: "routine", + lastMessageAgentId: null, + }), + ).toBe(false); + for (const lastTurnInitiator of [ + "person", + "task", + "trigger", + null, + undefined, + ]) + expect( + routineSpokeLast({ + lastTurnInitiator, + lastMessageAgentId: "digest-bot", + }), + ).toBe(false); + }); +}); + describe("a deleted channel", () => { test("is removed from the page that held it", () => { const data = cache([channel("a"), channel("b")], [channel("c")]); diff --git a/app/tests/compact-conversations.test.tsx b/app/tests/compact-conversations.test.tsx index a2da5c2651..e151b30bd5 100644 --- a/app/tests/compact-conversations.test.tsx +++ b/app/tests/compact-conversations.test.tsx @@ -220,6 +220,45 @@ test("where there is no lone orb to wear the arcs, an unread row keeps its dot", expect(face.container.querySelector("[data-slot=unread-dot]")).not.toBeNull(); }); +/* + * A conversation a routine spoke in last has a small clock inside its Bot's orb, compact or + * detailed, beside the arcs when it is unread too. Like the arcs it needs a lone orb: a group, a face + * and a row under its Bot draw no clock. + */ +test("where Bots are orbs, a conversation a routine spoke in last has the routine's clock in its orb", () => { + for (const view of ["compact", "detailed"] as const) { + const both = compactRow({ routine: true, unread: true, view }, "orb"); + const orb = both.container.querySelector(".bot-orb") as HTMLElement; + expect({ + view, + startedBy: orb.dataset.startedBy, + state: orb.dataset.state, + }).toEqual({ view, startedBy: "routine", state: "waiting" }); + both.unmount(); + + const own = compactRow({ routine: false, view }, "orb"); + expect( + (own.container.querySelector(".bot-orb") as HTMLElement).dataset + .startedBy, + ).toBeUndefined(); + own.unmount(); + } +}); + +test("where there is no lone orb, a routine's conversation draws no clock", () => { + const group = compactRow( + { routine: true, participantIds: ["bot-1", "bot-2"] }, + "orb", + ); + expect(group.container.querySelector("[data-started-by]")).toBeNull(); + group.unmount(); + const face = compactRow({ routine: true }, "face"); + expect(face.container.querySelector("[data-started-by]")).toBeNull(); + face.unmount(); + const underItsBot = compactRow({ routine: true, avatar: false }, "orb"); + expect(underItsBot.container.querySelector("[data-started-by]")).toBeNull(); +}); + test("the view this browser remembers, Compact unless Detailed was chosen", () => { expect(readConversationView(null)).toBe("compact"); expect(readConversationView("detailed")).toBe("detailed"); diff --git a/mobile/src/api/generated/model/conversationSummary.ts b/mobile/src/api/generated/model/conversationSummary.ts index 2784552b3b..48adad9800 100644 --- a/mobile/src/api/generated/model/conversationSummary.ts +++ b/mobile/src/api/generated/model/conversationSummary.ts @@ -42,6 +42,11 @@ export interface ConversationSummary { * @nullable */ lastMessageBotId: string | null; + /** + * Who started the turn the last thing said in it belongs to: the person (person), a routine, check-in or goal (routine), or a task a Bot handed the work to (task). With a Bot's message last, routine means a routine spoke last and nobody has written since. Null when nothing has been said, or when the last message is older than the server's keeping it. Absent from a server that predates it. An app reads null, absence and a value it doesn't know alike: as nothing known about who started it. + * @nullable + */ + lastTurnInitiator?: string | null; /** When it was started. */ createdAt: string; /** Whether the caller pinned it. */