Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.
Rust ai-agentsai-assistantai-botautomationbotbots-teamchatbotclaude-duetgrokgrok-botgrok-bot-alternativeharnessllmmulti-agentopenai-dotsopenbotpersonal-agentrustself-hostedselfhosted-ai
Smart Results client: findings with empty detail, and the files block on shared-file cards (#237)
Oleksandr Ivanchenkoa0aac947151b
diff --git a/frontend/src/components/ChatView.tsx b/frontend/src/components/ChatView.tsxindex 2206af0d..94bf10f3 100644--- a/frontend/src/components/ChatView.tsx+++ b/frontend/src/components/ChatView.tsx@@ -48,6 +48,7 @@ import { DecidingLine, DecisionChips, WorkAheadBody } from './Proactive';import { RouteChoiceMeta, parseRouteChoiceMeta, questionsOfReplies } from '../routeChoice';import { SmartActionsSlot } from './results/SmartActions';import { COMPOSE_PREFILL_EVENT } from './results/SmartResult';+import { FilesPreviewOnly } from './results/Files';/** A swipeable chip row whose right fade edge (phones only, see .kw-scroll-row) goes away once* it is scrolled to the end, or when everything already fits. */@@ -1138,6 +1139,12 @@ export const ChatView: React.FC<ChatViewProps> = ({</div>)}{files.length > 0 && <FileTiles files={files} align={isUser ? 'end' : 'start'} />}+ {/* A shared-file card has no bubble, so the files block (the table or text preview) is mounted here, after the tiles. */}+ {filesOnly && !isUser && msg.results != null && (+ <FilesPreviewOnly.Provider value={true}>+ <MarkdownRenderer content="" results={msg.results} messageId={msg.id} />+ </FilesPreviewOnly.Provider>+ )}{decisions.length > 0 && (<DecisionChipsdiff --git a/frontend/src/components/results/Files.tsx b/frontend/src/components/results/Files.tsxindex 4e75708c..e0cba441 100644--- a/frontend/src/components/results/Files.tsx+++ b/frontend/src/components/results/Files.tsx@@ -134,26 +134,53 @@ const FilePreviewView: React.FC<{ item: FileItem }> = ({ item }) => {);};+/**+ * Set by a "Shared a file" card, which already shows each file as a tile with its Download button:+ * the block then adds only the previews (table or text), so no file is drawn twice.+ */+export const FilesPreviewOnly = React.createContext(false);+/** Attached files: name, type, size, and a preview of the data itself when one is available. */-export const Files: React.FC<RendererProps<FilesBlock>> = ({ block }) => (- <div data-smart-result="files" data-block-id={block.id}>- <ul role="list" className="my-3.5 space-y-2">- {block.items.map((item) => (- <li key={item.id} className="rounded-xl border border-zinc-800 bg-zinc-950/70 p-3 shadow-sm">- <div className="flex items-start gap-2">- <FileIcon size={14} className="mt-0.5 shrink-0 text-zinc-500" aria-hidden="true" />- <div className="min-w-0 flex-1">- <div className="truncate text-xs font-medium text-zinc-200" title={item.name}>- {item.name}- </div>- <div className="mt-0.5 text-[11px] text-zinc-500">- {item.mime} · {humanSize(item.size_bytes)}+export const Files: React.FC<RendererProps<FilesBlock>> = ({ block }) => {+ const previewOnly = React.useContext(FilesPreviewOnly);+ if (previewOnly) {+ const shown = block.items.filter((i) => i.preview && i.preview.kind !== 'image');+ if (shown.length === 0) return null;+ return (+ <div data-smart-result="files" data-block-id={block.id} data-preview-only="">+ <ul role="list" className="mt-2 space-y-2">+ {shown.map((item) => (+ <li key={item.id} aria-label={`Preview of ${item.name}`} className="min-w-0">+ <div className="truncate text-[11px] text-zinc-500" title={item.name}>+ Preview of {item.name}</div><FilePreviewView item={item} />+ </li>+ ))}+ </ul>+ </div>+ );+ }+ return (+ <div data-smart-result="files" data-block-id={block.id}>+ <ul role="list" className="my-3.5 space-y-2">+ {block.items.map((item) => (+ <li key={item.id} className="rounded-xl border border-zinc-800 bg-zinc-950/70 p-3 shadow-sm">+ <div className="flex items-start gap-2">+ <FileIcon size={14} className="mt-0.5 shrink-0 text-zinc-500" aria-hidden="true" />+ <div className="min-w-0 flex-1">+ <div className="truncate text-xs font-medium text-zinc-200" title={item.name}>+ {item.name}+ </div>+ <div className="mt-0.5 text-[11px] text-zinc-500">+ {item.mime} · {humanSize(item.size_bytes)}+ </div>+ <FilePreviewView item={item} />+ </div></div>- </div>- </li>- ))}- </ul>- </div>-);+ </li>+ ))}+ </ul>+ </div>+ );+};diff --git a/frontend/src/components/results/Findings.tsx b/frontend/src/components/results/Findings.tsxindex 594b3db9..801d3a2b 100644--- a/frontend/src/components/results/Findings.tsx+++ b/frontend/src/components/results/Findings.tsx@@ -12,7 +12,8 @@ export function validFindings(raw: unknown): FindingsBlock | null {const items: FindingItem[] = [];for (const it of b.items as Record<string, unknown>[]) {if (!SEVERITIES.includes(it.severity as Severity) || !isText(it.severity_text, 40)) return null;- if (!isText(it.title) || !isText(it.detail, 2000)) return null;+ // The server sends detail "" for a bullet with no " — detail" part (its own check allows that), so blank is valid here; title stays required.+ if (!isText(it.title) || !(it.detail === undefined || it.detail === null || isText(it.detail, 2000, true))) return null;if (!Array.isArray(it.refs)) return null;const refs: FindingRef[] = [];for (const r of it.refs) {@@ -20,7 +21,7 @@ export function validFindings(raw: unknown): FindingsBlock | null {if (r.line !== null && r.line !== undefined && !isIndex(r.line)) return null;refs.push({ path: r.path, line: r.line === undefined ? null : (r.line as number | null) });}- items.push({ id: it.id as string, severity: it.severity as Severity, severity_text: it.severity_text, title: it.title, detail: it.detail, refs });+ items.push({ id: it.id as string, severity: it.severity as Severity, severity_text: it.severity_text, title: it.title, detail: typeof it.detail === 'string' ? it.detail : '', refs });}return { id: b.id, type: 'findings', title: b.title, source: b.source, provenance: b.provenance, items };}@@ -60,7 +61,7 @@ export const Findings: React.FC<RendererProps<FindingsBlock>> = ({ block }) => {{g.items.map((item) => (<li key={item.id} className="rounded-xl border border-zinc-800 bg-zinc-950/70 p-3 text-xs shadow-sm"><div className="font-semibold leading-snug text-zinc-100 [overflow-wrap:anywhere]">{item.title}</div>- <p className="mt-1 leading-relaxed text-zinc-400 [overflow-wrap:anywhere]">{item.detail}</p>+ {item.detail.trim() !== '' && <p className="mt-1 leading-relaxed text-zinc-400 [overflow-wrap:anywhere]">{item.detail}</p>}{item.refs.length > 0 && (<div className="mt-1.5 flex flex-wrap gap-1.5">{item.refs.map((r, i) => (diff --git a/frontend/tests/smartResultsClientFixes.test.mjs b/frontend/tests/smartResultsClientFixes.test.mjsnew file mode 100644index 00000000..8373706d--- /dev/null+++ b/frontend/tests/smartResultsClientFixes.test.mjs@@ -0,0 +1,144 @@+// Two contract fixes between the server's Smart Results blocks and the chat:+// 1. a findings block with detail "" (what the server writes for a bullet with no " — detail" part,+// src/server/smart_results/items.rs `findings`) must validate and draw;+// 2. a "Shared a file" card (meta.kind "file") must draw its files block, without a second file card.+import assert from 'node:assert/strict';+import test from 'node:test';+import { loadBundled } from './bundle.mjs';++globalThis.localStorage ??= { getItem: () => null, setItem: () => {}, removeItem: () => {} };++const m = await loadBundled(`+ import React from 'react';+ import { renderToStaticMarkup } from 'react-dom/server.browser';+ import { ChatView } from './src/components/ChatView';+ import { MarkdownRenderer } from './src/components/MarkdownRenderer';+ export { validFindings } from './src/components/results/Findings';+ export { validFiles } from './src/components/results/Files';+ export const chat = (props) => renderToStaticMarkup(React.createElement(ChatView, props));+ export const md = (props) => renderToStaticMarkup(React.createElement(MarkdownRenderer, props));+`);++// The block the real server stored for this reply (shape per items.rs: id "b0", ids x0..xN, the whole+// bullet text as title and detail "" when there is no " — "; refs lifted from the backticked path:line).+const REPLY = [+ 'Review of the db layer:',+ '',+ '- **High:** SQL built by string concat in `src/db.rs:42`, use a bound parameter',+ '- **Low:** typo in the log line in `src/log.rs:7`',+].join('\n');+const serverFindings = () => ({+ version: 1,+ blocks: [+ {+ id: 'b0',+ type: 'findings',+ title: null,+ source: { kind: 'markdown_list', index: 0, ordered: false },+ provenance: { kind: 'reply_text' },+ items: [+ { id: 'x0', severity: 'high', severity_text: 'High', title: 'SQL built by string concat in `src/db.rs:42`, use a bound parameter', detail: '', refs: [{ path: 'src/db.rs', line: 42 }] },+ { id: 'x1', severity: 'low', severity_text: 'Low', title: 'typo in the log line in `src/log.rs:7`', detail: '', refs: [{ path: 'src/log.rs', line: 7 }] },+ ],+ },+ ],+});++test('findings: the server’s empty detail validates; title and severity stay required', () => {+ const b = serverFindings().blocks[0];+ const ok = m.validFindings(b);+ assert.ok(ok, 'detail "" is valid');+ assert.equal(ok.items[0].detail, '');+ assert.equal(ok.items.length, 2);+ // A missing detail is read as empty, never as undefined.+ const noDetail = { ...b, items: b.items.map(({ detail, ...rest }) => rest) };+ assert.equal(m.validFindings(noDetail)?.items[0].detail, '');+ assert.equal(m.validFindings({ ...b, items: b.items.map((i) => ({ ...i, title: '' })) }), null, 'blank title is still invalid');+ assert.equal(m.validFindings({ ...b, items: b.items.map((i) => ({ ...i, severity: 'urgent' })) }), null, 'severity stays an enum');+ assert.equal(m.validFindings({ ...b, items: b.items.map((i) => ({ ...i, detail: '<b>x</b>' })) }), null, 'HTML in detail is still refused');+ assert.equal(m.validFindings({ ...b, items: b.items.map((i) => ({ ...i, detail: 5 })) }), null, 'a non-string detail is invalid');+});++test('findings: server output round-trips through the renderer, with no empty detail line', () => {+ const html = m.md({ content: REPLY, results: serverFindings(), messageId: 'm1' });+ assert.match(html, /data-smart-result="findings"/, 'the block is drawn, not the markdown fallback');+ assert.match(html, /SQL built by string concat/);+ assert.match(html, /src\/db\.rs:42/);+ assert.doesNotMatch(html, /<p[^>]*text-zinc-400[^>]*><\/p>/, 'no empty paragraph for a blank detail');+});++const ATT = '3f0c1b8e-7d8a-4f6e-9a55-2d1d0c3c9a01';+const fileCard = (over = {}) => ({+ id: 'f1',+ sender_role: 'kwant',+ sender_id: 'Writer',+ text: 'Shared a file: sales.csv',+ meta: JSON.stringify({ kind: 'file', attachments: [{ id: ATT, name: 'sales.csv', mime: 'text/csv', size: 357 }] }),+ results: {+ version: 1,+ blocks: [+ {+ id: 'b0',+ type: 'files',+ title: null,+ source: { kind: 'slot' },+ provenance: { kind: 'kwant_data', ref: `attachment:${ATT}` },+ items: [+ {+ id: 'a0',+ attachment_id: ATT,+ name: 'sales.csv',+ mime: 'text/csv',+ size_bytes: 357,+ preview: { kind: 'table', columns: ['month', 'total'], rows: [['Jan', '12'], ['Feb', '15']], truncated: true, total_rows: 21 },+ },+ ],+ },+ ],+ },+ ...over,+});+const chatProps = (messages) => ({+ title: 'Writer', subtitle: 'Writer', messages, streamingText: '', streamingThinking: '', isStreaming: false,+ pendingApprovals: [], onSendMessage: () => {}, onResolveApproval: () => {}, kwants: [], teams: [],+});+const count = (html, re) => (html.match(re) ?? []).length;++test('a shared-file card draws the table preview and its cut note, once', () => {+ assert.ok(m.validFiles(fileCard().results.blocks[0]), 'the fixture is a valid files block');+ const html = m.chat(chatProps([fileCard()]));+ assert.match(html, /data-smart-result="files"/, 'the files block is mounted');+ assert.match(html, /<th[^>]*>month<\/th>/);+ assert.match(html, /<td[^>]*>Feb<\/td>/);+ assert.match(html, /data-preview-note/, 'the cut note shows');+ assert.equal(count(html, /aria-label="Download sales\.csv"/g), 1, 'one file tile with one Download button');+ assert.equal(count(html, /sales\.csv/g) >= 1, true);+ // No second file card: the block adds only "Preview of ..." under the tile.+ assert.equal(count(html, /text\/csv ·/g), 0, 'the block does not repeat the type and size line');+ assert.match(html, /Preview of sales\.csv/);+});++test('a shared-file card without a files block, or with an invalid one, is the plain tile as before', () => {+ const plain = m.chat(chatProps([fileCard({ results: undefined })]));+ assert.doesNotMatch(plain, /data-smart-result/);+ assert.equal(count(plain, /aria-label="Download sales\.csv"/g), 1);+ const bad = fileCard();+ bad.results.blocks[0].items[0].preview = { kind: 'table', columns: ['a'], rows: [['x', 'y']] };+ const html = m.chat(chatProps([bad]));+ assert.doesNotMatch(html, /data-smart-result="files"/, 'an invalid block draws nothing');+ assert.equal(count(html, /aria-label="Download sales\.csv"/g), 1, 'the tile is still there');+});++test('a file with no table or text preview adds nothing under its tile', () => {+ const card = fileCard();+ card.results.blocks[0].items[0].preview = null;+ const html = m.chat(chatProps([card]));+ assert.doesNotMatch(html, /data-smart-result="files"/);+ assert.equal(count(html, /aria-label="Download sales\.csv"/g), 1);+});++test('a files block on an ordinary reply is still drawn as full cards (no preview-only mode)', () => {+ const html = m.md({ content: 'Here you go.', results: fileCard().results, messageId: 'm2' });+ assert.match(html, /text\/csv · 357 B/);+ assert.doesNotMatch(html, /data-preview-only/);+});