mirror of
https://github.com/bitbaum/chatkit.git
synced 2026-12-04 04:07:20 +01:00
* fix(styles): starters are one column at every width (0.31.3) The empty chat's starters wrapped into a row of pills. A row of choices is never wrapping pills (fleet AGENTS.md, "One shape per kind"; OrangeCat UX audit 2026-11-12, auth-firstrun#5). .ck-starters-list is now a column and each .ck-starter a full-width, left-aligned, 44px row. Checked in test/styles.test.js and test/browser-app.mjs at 390px and 1440px. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmvT2nQyPBK4EfWf3Rn * fix(messenger): a message's actions by keyboard; alone with an agent every message is for it, and its answer reads it - The actions button of a message was display:none until hovered, so Tab never reached it and Edit and Delete had no way in without a mouse. It is hidden by opacity now, takes focus, is 44px, and stays on the screen on a phone. Long press and right click are unchanged. - soleAgent(): one person and one agent. There the empty conversation says the agent answers every message, Ask <agent> is not offered, and a message starts the wait for a named agent without naming it. - receiptOf(): where only agents could read a message, it is read once an agent's own read mark is past it. A conversation with only an agent stayed at Sent for ever. - An awaited agent is not also shown typing. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmvT2nQyPBK4EfWf3Rn * chore(release): 0.35.0 Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmvT2nQyPBK4EfWf3Rn * test(app): a 44px control measured mid-slide is not a small target Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmvT2nQyPBK4EfWf3Rn * fix(messenger): the Agent mark only under an agent; a message is never drawn as nothing (0.37.0) Found on OrangeCat (owner's phone, 2026-11-15), a conversation with a person and the Cat: - The top bar drew "Agent · Cat is in this conversation" under the person's name, so it read as "Penguin is an agent". The mark is now drawn only where the title is an agent; with people here the line reads "@penguin · Cat is here". `agentHere` is now "{name} is here" (the old wording was cut off at 390px). - A message with no words, card or files was an empty row with a time and a tick. It now says "This message could not be shown." (`labels.emptyMessage`). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmvT2nQyPBK4EfWf3Rn * test: drop tests duplicated by the branch merge Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmvT2nQyPBK4EfWf3Rn --------- Co-authored-by: Claude <noreply@anthropic.com>
352 lines
12 KiB
JavaScript
352 lines
12 KiB
JavaScript
// The Messenger renders on the server, and its markup says what the screen
|
|
// must: who is an agent, whose message is whose, what was read. Rendered to a
|
|
// string; what needs a running browser is in test/browser-messenger.mjs.
|
|
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { createElement as h } from "react";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
import {
|
|
ConversationList,
|
|
MessageThread,
|
|
Messenger,
|
|
DEFAULT_MESSENGER_LABELS,
|
|
messengerLabels,
|
|
} from "../dist/react/messenger.js";
|
|
import { Composer } from "../dist/react/index.js";
|
|
import { AttachMenu } from "../dist/react/attach.js";
|
|
import { ATTACH_SOURCE_INPUT, MESSAGE_FILES_ACCEPT, acceptFamilies } from "../dist/index.js";
|
|
|
|
const START = new Date("2026-11-01T00:00:00Z");
|
|
const person = (actorId, name, extra = {}) => ({
|
|
actorId,
|
|
kind: "human",
|
|
name,
|
|
joinedAt: START,
|
|
visibleFrom: "thread-start",
|
|
...extra,
|
|
});
|
|
const CAT = { id: "cat", name: "Cat", mention: "@cat" };
|
|
const catSeat = {
|
|
actorId: "cat",
|
|
kind: "ai",
|
|
name: "Cat",
|
|
joinedAt: START,
|
|
visibleFrom: "thread-start",
|
|
};
|
|
const msg = (id, authorId, body, at, extra = {}) => ({
|
|
id,
|
|
threadId: "c1",
|
|
authorId,
|
|
body,
|
|
createdAt: new Date(at),
|
|
...extra,
|
|
});
|
|
|
|
const withCat = {
|
|
id: "c1",
|
|
createdAt: START,
|
|
participants: [
|
|
person("me", "Georgy"),
|
|
person("maya", "Maya Keller", { lastReadAt: new Date("2026-11-10T10:05:00Z") }),
|
|
catSeat,
|
|
],
|
|
};
|
|
const dm = {
|
|
id: "c1",
|
|
createdAt: START,
|
|
participants: [person("me", "Georgy"), person("maya", "Maya Keller")],
|
|
};
|
|
|
|
const thread = (conversation, messages, extra = {}) =>
|
|
renderToStaticMarkup(
|
|
h(MessageThread, {
|
|
conversation,
|
|
viewerId: "me",
|
|
messages,
|
|
agents: [CAT],
|
|
timeZone: "UTC",
|
|
locale: "en-GB",
|
|
...extra,
|
|
}),
|
|
);
|
|
|
|
test("an agent's message carries its name, the Agent mark and whom it answered for", () => {
|
|
const html = thread(withCat, [
|
|
msg("1", "me", "@cat who is right?", "2026-11-10T10:00:00Z"),
|
|
msg("2", "cat", "Maya is.", "2026-11-10T10:00:05Z", { onBehalfOf: "me" }),
|
|
]);
|
|
assert.match(html, /ck-msgr-from-agent/);
|
|
assert.match(
|
|
html,
|
|
/class="ck-speaker ck-speaker-agent">Cat<span class="ck-speaker-kind">Agent<\/span>/,
|
|
);
|
|
assert.match(html, /for Georgy/);
|
|
assert.match(html, /ck-msgr-avatar-agent/, "an agent's face has its own shape");
|
|
});
|
|
|
|
test("a person is never marked as an agent, and is named once an agent is in the room", () => {
|
|
const html = thread(withCat, [msg("1", "maya", "Penguins are fish.", "2026-11-10T10:00:00Z")]);
|
|
assert.match(html, /class="ck-speaker">Maya Keller<\/span>/);
|
|
assert.doesNotMatch(html, /ck-speaker-kind/);
|
|
assert.doesNotMatch(html, /ck-msgr-from-agent/);
|
|
});
|
|
|
|
test("between two people nobody needs naming", () => {
|
|
const html = thread(dm, [msg("1", "maya", "hello", "2026-11-10T10:00:00Z")]);
|
|
assert.doesNotMatch(html, /ck-speaker/);
|
|
});
|
|
|
|
test("an agent's words are markdown; a person's are exactly what was typed", () => {
|
|
const html = thread(withCat, [
|
|
msg("1", "cat", "They are **birds**.", "2026-11-10T10:00:00Z"),
|
|
msg("2", "maya", "They are **fish** <b>really</b>", "2026-11-10T10:10:00Z"),
|
|
]);
|
|
assert.match(html, /<strong>birds<\/strong>/);
|
|
assert.match(html, /They are \*\*fish\*\* <b>really<\/b>/);
|
|
});
|
|
|
|
test("a person's address is a link that opens elsewhere; a script address is not a link", () => {
|
|
const html = thread(dm, [
|
|
msg("1", "maya", "see https://example.org/x and javascript:alert(1)", "2026-11-10T10:00:00Z"),
|
|
]);
|
|
assert.match(html, /<a[^>]*href="https:\/\/example\.org\/x"/);
|
|
assert.doesNotMatch(html, /href="javascript:/);
|
|
});
|
|
|
|
test("the viewer's message says how far it got: sending, sent, read, not sent", () => {
|
|
const read = thread(withCat, [msg("1", "me", "hi", "2026-11-10T10:00:00Z")]);
|
|
assert.match(
|
|
read,
|
|
/aria-label="Read"/,
|
|
"the only other PERSON has read it; the agent is not waited for",
|
|
);
|
|
const sent = thread(withCat, [msg("1", "me", "hi", "2026-11-10T11:00:00Z")]);
|
|
assert.match(sent, /aria-label="Sent"/);
|
|
const sending = thread(dm, [
|
|
msg("t", "me", "hi", "2026-11-10T11:00:00Z", { clientId: "t", delivery: "sending" }),
|
|
]);
|
|
assert.match(sending, /aria-label="Sending"/);
|
|
const failed = thread(
|
|
dm,
|
|
[msg("t", "me", "hi", "2026-11-10T11:00:00Z", { clientId: "t", delivery: "failed" })],
|
|
{
|
|
onRetry: () => {},
|
|
onDiscard: () => {},
|
|
},
|
|
);
|
|
assert.match(failed, /Not sent\./);
|
|
assert.match(failed, />Try again<\/button>/);
|
|
assert.match(failed, />Delete<\/button>/);
|
|
});
|
|
|
|
test("pictures are tiles with their size known, a film is its still, a file is a download", () => {
|
|
const html = thread(dm, [
|
|
msg("1", "maya", "", "2026-11-10T10:00:00Z", {
|
|
attachments: [
|
|
{
|
|
id: "a",
|
|
kind: "image",
|
|
name: "cat.jpg",
|
|
mimeType: "image/jpeg",
|
|
bytes: 1000,
|
|
width: 1200,
|
|
height: 900,
|
|
url: "/a.jpg",
|
|
},
|
|
],
|
|
}),
|
|
msg("2", "maya", "", "2026-11-10T10:10:00Z", {
|
|
attachments: [
|
|
{
|
|
id: "b",
|
|
kind: "video",
|
|
name: "hike.mp4",
|
|
mimeType: "video/mp4",
|
|
bytes: 9_000_000,
|
|
durationMs: 42_000,
|
|
url: "/b.mp4",
|
|
posterUrl: "/b.jpg",
|
|
},
|
|
{
|
|
id: "c",
|
|
kind: "file",
|
|
name: "route.pdf",
|
|
mimeType: "application/pdf",
|
|
bytes: 184_320,
|
|
url: "/c.pdf",
|
|
},
|
|
],
|
|
}),
|
|
]);
|
|
assert.match(html, /<img src="\/a\.jpg"[^>]*width="288"[^>]*height="216"/);
|
|
assert.match(html, /<img src="\/b\.jpg"/, "the film's still is drawn");
|
|
assert.doesNotMatch(html, /<video/, "no film is loaded to draw a tile");
|
|
assert.match(html, /0:42/);
|
|
assert.match(html, /<a class="ck-msgr-file" href="\/c\.pdf" download="route\.pdf"/);
|
|
assert.match(html, /180 KB/);
|
|
});
|
|
|
|
test("an agent that was asked is shown thinking, and then as not having answered", () => {
|
|
const thinking = thread(withCat, [msg("1", "me", "@cat ?", "2026-11-10T10:00:00Z")], {
|
|
awaited: [{ agentId: "cat", state: "thinking" }],
|
|
});
|
|
assert.match(thinking, /Cat is thinking…/);
|
|
const quiet = thread(withCat, [msg("1", "me", "@cat ?", "2026-11-10T10:00:00Z")], {
|
|
awaited: [{ agentId: "cat", state: "quiet" }],
|
|
onDismissAgent: () => {},
|
|
});
|
|
assert.match(quiet, /Cat has not answered\. Ask again in a moment\./);
|
|
assert.match(quiet, />Dismiss<\/button>/);
|
|
});
|
|
|
|
test("an empty conversation says so, and how to bring the agent in", () => {
|
|
const html = thread(dm, []);
|
|
assert.match(html, /No messages yet\. Say hello\./);
|
|
assert.match(html, /Type @cat to bring Cat in\. Everyone here sees its answer\./);
|
|
});
|
|
|
|
test("alone with an agent: the empty conversation says it answers, and its answer makes a message read", () => {
|
|
const alone = (extra = {}) => ({
|
|
id: "c1",
|
|
createdAt: START,
|
|
participants: [person("me", "Georgy"), { ...catSeat, ...extra }],
|
|
});
|
|
const empty = thread(alone(), []);
|
|
assert.match(empty, /Cat answers every message here\./);
|
|
assert.doesNotMatch(empty, /Type @cat/, "there is nobody to bring in");
|
|
const sent = thread(alone(), [msg("1", "me", "hi", "2026-11-10T10:00:00Z")]);
|
|
assert.match(sent, /aria-label="Sent"/);
|
|
const read = thread(alone({ lastReadAt: new Date("2026-11-10T10:00:05Z") }), [
|
|
msg("1", "me", "hi", "2026-11-10T10:00:00Z"),
|
|
msg("2", "cat", "Hello.", "2026-11-10T10:00:05Z"),
|
|
]);
|
|
assert.match(read, /aria-label="Read"/);
|
|
});
|
|
|
|
test("an awaited agent is not also shown typing", () => {
|
|
const html = thread(withCat, [msg("1", "me", "@cat hi", "2026-11-10T10:00:00Z")], {
|
|
awaited: [{ agentId: "cat", state: "thinking" }],
|
|
typing: ["cat"],
|
|
});
|
|
assert.match(html, /Cat is thinking/);
|
|
assert.doesNotMatch(html, /is typing/);
|
|
});
|
|
|
|
test("the list: one row anatomy, an unread count a screen reader can hear, the agent on the face", () => {
|
|
const html = renderToStaticMarkup(
|
|
h(ConversationList, {
|
|
viewerId: "me",
|
|
agents: [CAT],
|
|
selectedId: "c1",
|
|
onSelect: () => {},
|
|
onNew: () => {},
|
|
timeZone: "UTC",
|
|
locale: "en-GB",
|
|
conversations: [
|
|
{
|
|
...withCat,
|
|
last: { body: "Maya is.", authorId: "cat", createdAt: new Date("2026-11-10T10:00:00Z") },
|
|
unread: 2,
|
|
},
|
|
],
|
|
}),
|
|
);
|
|
assert.match(html, /<h1 class="ck-msgr-list-title">Messages<\/h1>/);
|
|
assert.match(html, /aria-current="true"/);
|
|
assert.match(html, /Maya Keller/);
|
|
assert.match(html, /aria-label="2 unread"/);
|
|
assert.match(html, /ck-msgr-row-agent/);
|
|
assert.match(html, />New<\/button>/);
|
|
});
|
|
|
|
test("the whole Messenger renders without a browser", () => {
|
|
const transport = {
|
|
conversations: async () => [],
|
|
messages: async () => ({ messages: [], before: null }),
|
|
send: async () => {
|
|
throw new Error("not in this test");
|
|
},
|
|
};
|
|
const html = renderToStaticMarkup(h(Messenger, { viewer: { id: "me" }, transport }));
|
|
assert.match(html, /class="ck-msgr" data-pane="list"/);
|
|
assert.match(html, /Messages/);
|
|
assert.doesNotMatch(html, />New<\/button>/, "no people search, no New");
|
|
});
|
|
|
|
test("labels: a product overrides one word of a group and keeps the rest", () => {
|
|
const labels = messengerLabels({ title: "Nachrichten", preview: { photo: "Foto" } });
|
|
assert.equal(labels.title, "Nachrichten");
|
|
assert.equal(labels.preview.photo, "Foto");
|
|
assert.equal(labels.preview.video, DEFAULT_MESSENGER_LABELS.preview.video);
|
|
});
|
|
|
|
test("the inline composer is the same box with one more class; the default is unchanged", () => {
|
|
// Where the microphone sits needs a browser that has one: see
|
|
// test/browser-messenger.mjs.
|
|
const html = renderToStaticMarkup(
|
|
h(Composer, { onSend: () => {}, placeholder: "Message", layout: "inline" }),
|
|
);
|
|
assert.match(html, /class="ck-composer ck-composer-inline"/);
|
|
assert.match(html, /<textarea[^>]*class="ck-input"/);
|
|
const stacked = renderToStaticMarkup(h(Composer, { onSend: () => {}, placeholder: "Ask" }));
|
|
assert.match(stacked, /class="ck-composer"/);
|
|
assert.doesNotMatch(stacked, /ck-composer-inline/);
|
|
});
|
|
|
|
test("videos are their own source, and every source still asks for one family", () => {
|
|
const html = renderToStaticMarkup(
|
|
h(AttachMenu, {
|
|
onFiles: () => {},
|
|
sources: ["camera", "photos", "videos", "files"],
|
|
accept: { files: MESSAGE_FILES_ACCEPT },
|
|
}),
|
|
);
|
|
assert.match(
|
|
html,
|
|
/data-ck-source="videos"[^>]*accept="video\/\*"|accept="video\/\*"[^>]*data-ck-source="videos"/,
|
|
);
|
|
assert.match(html, />Videos</);
|
|
assert.deepEqual(acceptFamilies(ATTACH_SOURCE_INPUT.videos.accept), ["video"]);
|
|
assert.deepEqual(acceptFamilies(MESSAGE_FILES_ACCEPT), ["document"]);
|
|
assert.ok(
|
|
html.includes(MESSAGE_FILES_ACCEPT),
|
|
"the Files source asks for a messenger's documents",
|
|
);
|
|
});
|
|
|
|
test("an app that set its attach labels before Videos existed still gets a word for it", () => {
|
|
const html = renderToStaticMarkup(
|
|
h(AttachMenu, {
|
|
onFiles: () => {},
|
|
sources: ["videos"],
|
|
rows: [{ id: "x", label: "Extra", onPick: () => {} }],
|
|
labels: {
|
|
attach: "Anhängen",
|
|
title: "Hinzufügen",
|
|
close: "Schliessen",
|
|
sources: { camera: "Kamera", photos: "Fotos", files: "Dateien" },
|
|
},
|
|
}),
|
|
);
|
|
assert.match(html, />Videos</);
|
|
});
|
|
|
|
test("the messenger entry exports the type of an app's action", async () => {
|
|
const { readFile } = await import("node:fs/promises");
|
|
const types = await readFile(new URL("../dist/react/messenger.d.ts", import.meta.url), "utf8");
|
|
assert.match(types, /MessengerComposerAction/);
|
|
});
|
|
|
|
test("a message with nothing to draw says so, never an empty row with a time", () => {
|
|
const html = thread(dm, [msg("1", "me", "", "2026-11-10T10:00:00Z", { attachments: [] })]);
|
|
assert.match(html, /class="ck-msgr-empty-message">This message could not be shown\.<\/p>/);
|
|
const photo = thread(dm, [
|
|
msg("2", "me", "", "2026-11-10T10:00:00Z", {
|
|
attachments: [
|
|
{ id: "a", kind: "image", name: "a.jpg", mimeType: "image/jpeg", bytes: 1, url: "/a" },
|
|
],
|
|
}),
|
|
]);
|
|
assert.doesNotMatch(photo, /ck-msgr-empty-message/);
|
|
});
|