Knowledge sources
The files, sites and folders the agent knows, and how far each is indexed. Free and MIT licensed, as HTML, a typed React component or an Astro component, in three styles with light and dark mode.
Need this designed into your product? Book a call
Install
Add it to your project with the CLI.
HTML, CSS and JS
npx designme add knowledge-sourcesReact
npx designme add knowledge-sources --reactAstro
npx designme add knowledge-sources --astroshadcn, React
npx shadcn@latest add https://designme.dev/r/shadcn/knowledge-sources.json shadcn, Astro
npx shadcn@latest add https://designme.dev/r/shadcn/astro/knowledge-sources.json The CLI copies the source into your project, so you own it and can change anything. Where each version lands, what it needs and the shadcn theme bridge: Installation.
About
What it is for and what it does.
A list of what an agent knows: uploaded files, websites it crawls and connected folders of docs, each with how far it has been indexed. A source is queued, indexing with a progress bar and a count, ready with when it last synced, or failed with the reason. A failed source can offer a fix, like reading a scanned PDF with OCR, and every source has Re-sync and Remove. It answers the question "what does this agent know, and is it up to date?"
- When people give an agent its own knowledge, like help docs, a product site or a shared drive, and need to see what it has read.
- When indexing takes a while and people should see it progress instead of waiting on a blank list.
- When a source can fail for a reason people can act on, like a scanned PDF or a site that blocks crawlers.
- In an agent's settings, next to its tools and memory.
- Each source in
sourcesshows its type's icon on a vivid tile (kindoffiles,weborfolder), itsname, and a line under it that follows itsstate. In Studio the tiles are one neutral grey. - The line leads with its state's mark: a green tick once
ready, a clock whilequeued, and a red sign whenfailed. - While indexing, the line becomes a progress bar and a count that shimmers, like "64 of 142 pages", from
doneandcount;unitswitches pages to files. - A ready source reads like "142 pages · Synced 2m ago" from its
synced; a queued one reads "Queued", or your ownnote. - A failed source shows its
errorin red, with a button labelled with itsfixthat callsonFix, and a Remove button when you passonRemove. - Each row has a menu with Re-sync (
onResync, unavailable while the source waits or indexes) and Remove (onRemove). - Add source opens a menu with an option for each handler you pass: Upload files opens the file picker and calls
onUploadwith the files; Add a website asks for an address and callsonAddWebsitewith it, without http(s)://; Connect a folder listsfoldersand callsonConnectFolder. The menu opens under the button, or above it when there is no room below. Its rows settle in one after another as it opens, and again as it moves to its next step. - With no sources it shows an empty state: a small sketch of the list, "No sources yet", one line, and Add source.
- The line under the title adds up the sources'
chunks, like "1,204 chunks indexed", or shows your ownstatus. - The card grows and shrinks with its rows, eased, and keeps no room for a state still to come.
- The sources form a list, and each row's menu button is named for its source, like "Actions for Product docs".
- An indexing source's bar is a progressbar with its count as its value.
- The menus have role="menu"; their buttons expose aria-expanded and aria-haspopup, and Escape closes a menu and gives the focus back to its button.
- From the keyboard, Enter, Space or the down arrow opens a menu with the focus on its picked item, or its first (the up arrow, on its last); the arrow keys move through it and wrap, Home and End jump to the ends, Tab closes it and moves on, and closing it gives the focus back to its button.
- The line under the title is announced politely when it changes.
- With reduced motion, rows appear without their entrance and text changes without the crossfade.
Usage
Import it in React and drive it from your own state, or place it in an Astro page.
React
import { KnowledgeSources } from '@/components/designme/knowledge-sources/KnowledgeSources';React example
The demo above as a React component, 72 lines you can copy.
'use client';
// The animated preview from designme.dev, rebuilt from the React component: an example of driving it from your own state.
import { useEffect, useRef, useState } from 'react';
import { useStory } from '../lib/useScript';
import { KnowledgeSources, type KnowledgeSource, type KnowledgeSourcesFolder } from './KnowledgeSources';
/* ---------- Knowledge sources: a website is added and waits its turn; a scanned PDF fails, is read again with OCR, and everything ends indexed ---------- */
type Src = KnowledgeSource & { ms: number; total: number; scan?: boolean };
const START: Src[] = [
{ key: 'docs', kind: 'folder', name: 'Product docs', count: 86, state: 'ready', synced: '2m ago', chunks: 642, total: 642, ms: 2500 },
{ key: 'play', kind: 'files', name: 'Sales playbooks', count: 18, unit: 'files', state: 'ready', synced: '1h ago', chunks: 318, total: 318, ms: 2500 },
{ key: 'pdf', kind: 'files', name: 'Brand book 2024.pdf', count: 24, state: 'queued', total: 48, ms: 19000, scan: true }
];
const FOLDERS: KnowledgeSourcesFolder[] = [{ key: 'specs', name: 'Design specs', detail: 'Google Drive' }, { key: 'research', name: 'Research notes', detail: 'Notion' }];
const SIZE: Record<string, [number, number]> = { specs: [57, 230], research: [31, 124] };
export default function KnowledgeSourcesDemo() {
const ref = useRef<HTMLDivElement>(null);
const [sources, setSources] = useState<Src[]>(START);
const [folders, setFolders] = useState(FOLDERS);
const [address, setAddress] = useState('');
const patch = (key: string, p: Partial<Src>) => setSources(ss => ss.map(s => s.key === key ? { ...s, ...p } : s));
const add = (s: Omit<Src, 'state'>) => setSources(ss => [...ss.filter(x => x.key !== s.key), { ...s, state: 'queued' }]);
// one source indexes at a time and the rest wait in line; a scanned PDF stops where its text runs out until it is read with OCR
useEffect(() => {
const id = setInterval(() => setSources(ss => {
let i = ss.findIndex(s => s.state === 'indexing');
if (i < 0) { i = ss.findIndex(s => s.state === 'queued'); if (i < 0) return ss; return ss.map((s, k) => k === i ? { ...s, state: 'indexing', done: 0 } : s); }
const s = ss[i], done = Math.min(s.count, (s.done ?? 0) + s.count * 100 / s.ms);
const next: Src = s.scan && done >= 9 ? { ...s, state: 'failed', done: 9, error: 'Scanned PDF, no text found', fix: 'Retry with OCR' }
: done >= s.count ? { ...s, state: 'ready', done, synced: 'just now', chunks: s.total } : { ...s, done };
return ss.map((x, k) => k === i ? next : x);
}), 100);
return () => clearInterval(id);
}, []);
// the preview's story: add the docs site, which waits its turn, then read the scanned PDF again with OCR. Indexing at work
// keeps going under the pointer, as designme.dev's does
useStory(ref, async ({ wait, press, taken }) => {
await wait(1500); press('.dm-ksx-add');
await wait(1000); press('.dm-ksx-pop .dm-mi:nth-child(2)');
await wait(500);
const url = 'designme.dev/docs';
// taking over while it types takes the letters back
let typing = true;
taken(() => { if (typing) setAddress(''); });
for (let k = 1; k <= url.length; k++) { setAddress(url.slice(0, k)); await wait(50); }
typing = false;
await wait(500); press('.dm-ksx-pop button[type="submit"]');
const failed = () => ref.current?.querySelector('.dm-ksx-s[data-st="failed"]');
for (let k = 0; k < 150 && !failed(); k++) await wait(100);
await wait(1000); press('.dm-ksx-s[data-st="failed"] .dm-ksx-fx .dm-accent');
}, { hold: false });
return (
<div ref={ref} style={{ width: '100%' }}>
<KnowledgeSources
sources={sources}
address={address} onAddressChange={setAddress}
onAddWebsite={a => add({ key: 'web:' + a, kind: 'web', name: a, count: 142, total: 196, ms: 4500 })}
onUpload={fs => add({ key: 'up:' + fs.map(f => f.name).join(), kind: 'files', name: fs.length === 1 ? fs[0].name : fs.length + ' files', count: fs.length, unit: 'files', total: fs.length * 12, ms: 1500 })}
folders={folders}
onConnectFolder={k => { const f = folders.find(x => x.key === k)!; setFolders(fs => fs.filter(x => x.key !== k)); add({ key: k, kind: 'folder', name: f.name, count: SIZE[k][0], total: SIZE[k][1], ms: 3000 }); }}
onFix={k => patch(k, { state: 'queued', scan: false, ms: 3000, note: 'Queued to read with OCR', error: undefined, fix: undefined })}
onResync={k => patch(k, { state: 'queued', note: undefined })}
onRemove={k => setSources(ss => ss.filter(s => s.key !== k))}
/>
</div>
);
}
Astro
In a page in src/pages. It plays the demo above; change its knowledge-sources.js to show your own data. Attributes like class go on its root element.
---
import KnowledgeSources from '../components/designme/knowledge-sources/KnowledgeSources.astro';
---
<KnowledgeSources />
<KnowledgeSources data-style="soft" class="my-class" />Props
Everything KnowledgeSources takes.
| Prop | Type | What it does |
|---|---|---|
sourcesrequired | KnowledgeSource[] | |
onUpload | (files: File[]) => void | Adds Upload files to the Add source menu; it opens the file picker and hands you what was picked |
onAddWebsite | (address: string) => void | Adds Add a website to the Add source menu; it asks for an address and hands it over without http(s):// |
address | string | The address being typed. Leave it out to let the field keep its own |
defaultAddress | string | |
onAddressChange | (address: string) => void | |
folders | KnowledgeSourcesFolder[] | Adds Connect a folder to the Add source menu, listing these |
onConnectFolder | (key: string) => void | |
onResync | (key: string) => void | Adds Re-sync to each source's menu. It is unavailable while the source waits or indexes |
onRemove | (key: string) => void | Adds Remove to each source's menu, and beside the fix of a failed one |
onFix | (key: string) => void | Called by the fix button of a failed source |
title | string | Defaults to "Knowledge sources" |
status | string | The line under the title. Defaults to how many chunks are indexed, like "1,204 chunks indexed" |
className | string |
Code
The full source, as the CLI installs it.
KnowledgeSources.tsxReact · 198 lines
'use client';
import { useRef, useState, type CSSProperties, type FormEvent } from 'react';
import { cx } from '../lib/cx';
import { useControllable, useIsoLayoutEffect } from '../lib/hooks';
import { Icon, type IconName } from '../lib/icons';
import { enter, Fold, Swap, Tip, useGrow } from '../lib/motion';
import { useHoverGlide } from '../lib/glide';
import { usePopover } from '../lib/popover';
import '../designme.css';
// its menus' rows glide in Studio
import '../lib/glide';
import './knowledge-sources.css';
/** files: uploaded files, web: a website the agent crawls, folder: a connected folder of docs (Notion, Drive and the like) */
export type KnowledgeSourceKind = 'files' | 'web' | 'folder';
/** queued: waiting its turn, indexing: being read (with a progress bar), ready: indexed, failed: stopped, with a reason */
export type KnowledgeSourceState = 'queued' | 'indexing' | 'ready' | 'failed';
/** A file, site or folder the agent knows */
export interface KnowledgeSource {
key: string;
/** Like "Product docs" or "designme.dev/docs" */
name: string;
kind: KnowledgeSourceKind;
/** How many pages or files it holds, like 142 */
count: number;
/** Defaults to pages */
unit?: 'pages' | 'files';
state: KnowledgeSourceState;
/** While indexing: how many of `count` are done. The bar and "64 of 142 pages" follow it */
done?: number;
/** When ready: when it was last synced, like "2m ago", shown as "Synced 2m ago" */
synced?: string;
/** When failed: why, like "Scanned PDF, no text found" */
error?: string;
/** When failed: the label of a button that fixes it, like "Retry with OCR". It calls `onFix` */
fix?: string;
/** Replaces "Queued" while it waits, like "Queued to read with OCR" */
note?: string;
/** The chunks it adds to the index, counted in the line under the title. Leave it out until it has been indexed */
chunks?: number;
}
/** A folder offered under Connect a folder */
export interface KnowledgeSourcesFolder {
key: string;
name: string;
/** Where it lives, like "Google Drive" */
detail?: string;
}
export interface KnowledgeSourcesProps {
sources: KnowledgeSource[];
/** Adds Upload files to the Add source menu; it opens the file picker and hands you what was picked */
onUpload?: (files: File[]) => void;
/** Adds Add a website to the Add source menu; it asks for an address and hands it over without http(s):// */
onAddWebsite?: (address: string) => void;
/** The address being typed. Leave it out to let the field keep its own */
address?: string;
defaultAddress?: string;
onAddressChange?: (address: string) => void;
/** Adds Connect a folder to the Add source menu, listing these */
folders?: KnowledgeSourcesFolder[];
onConnectFolder?: (key: string) => void;
/** Adds Re-sync to each source's menu. It is unavailable while the source waits or indexes */
onResync?: (key: string) => void;
/** Adds Remove to each source's menu, and beside the fix of a failed one */
onRemove?: (key: string) => void;
/** Called by the fix button of a failed source */
onFix?: (key: string) => void;
/** Defaults to "Knowledge sources" */
title?: string;
/** The line under the title. Defaults to how many chunks are indexed, like "1,204 chunks indexed" */
status?: string;
className?: string;
}
/* a type's icon on a vivid tile of its colour, with the colour's own ink */
const KIND: Record<KnowledgeSourceKind, [IconName, string]> = { files: ['file-text', 'p'], web: ['globe', 'b'], folder: ['folder', 'm'] };
const fmt = (n: number) => n.toLocaleString('en-US');
const of = (n: number, unit: string) => `${fmt(n)} ${n === 1 ? unit.slice(0, -1) : unit}`;
const line = (s: KnowledgeSource) => s.state === 'queued' ? s.note ?? 'Queued' : s.state === 'failed' ? s.error ?? 'Failed'
: of(s.count, s.unit ?? 'pages') + (s.synced ? ' · Synced ' + s.synced : '');
/* the line's mark: a tick once indexed, a clock while it waits, a sign when it failed */
const MARK: Record<Exclude<KnowledgeSourceState, 'indexing'>, IconName> = { ready: 'ok', queued: 'clock', failed: 'alert' };
/** One source: its type, name and state, and a menu with Re-sync and Remove */
function Row({ s, delay, onResync, onRemove, onFix }: { s: KnowledgeSource; delay: number } & Pick<KnowledgeSourcesProps, 'onResync' | 'onRemove' | 'onFix'>) {
const menu = usePopover({ align: 'end' });
const [icon, k] = KIND[s.kind];
const motion = enter(delay), unit = s.unit ?? 'pages', done = Math.min(s.count, Math.max(0, Math.floor(s.done ?? 0)));
const busy = s.state === 'queued' || s.state === 'indexing';
const act = (f?: (key: string) => void) => { menu.closeSoon(); f?.(s.key); };
return (
<div className={cx('dm-ksx-s', motion.className)} style={motion.style} role="listitem" data-st={s.state}>
<span className="dm-ic" style={{ background: `var(--dm-av-${k})`, color: `var(--dm-av-${k}-ink)` }} aria-hidden="true"><Icon name={icon} size="xs" /></span>
<span className="dm-t">
<span className="dm-nm">{s.name}</span>
<span className="dm-d">
{s.state === 'indexing'
? <><span className="dm-ksx-bar" role="progressbar" aria-label={'Indexing ' + s.name} aria-valuemin={0} aria-valuemax={s.count} aria-valuenow={done}><i style={{ width: done / (s.count || 1) * 100 + '%' }} /></span><span className="dm-num dm-shim">{fmt(done)} of {of(s.count, unit)}</span></>
: <><Icon name={MARK[s.state]} size="xs" /><Swap>{line(s)}</Swap></>}
</span>
</span>
{(onResync || onRemove)
? <Tip label="More" off={menu.open}><button type="button" className="dm-ib dm-ksx-more dm-mx-press" aria-label={'Actions for ' + s.name} {...menu.trigger}><Icon name="more" /></button></Tip>
: <span />}
{(onResync || onRemove) && (
<div {...menu.pop} className={cx(menu.pop.className, 'dm-ksx-mpop dm-mx-pop dm-mx-rows dm-mx-glide')} role="menu">
{onResync && <button type="button" className="dm-mi dm-mx-press" role="menuitem" disabled={busy} onClick={() => act(onResync)}><Icon name="refresh" size="xs" />Re-sync</button>}
{onResync && onRemove && <div className="dm-sep" />}
{onRemove && <button type="button" className="dm-mi dm-del dm-mx-press" role="menuitem" onClick={() => act(onRemove)}><Icon name="trash" size="xs" />Remove</button>}
</div>
)}
<Fold open={s.state === 'failed' && !!(s.fix || onRemove)} className="dm-ksx-fx">
<div>
{s.fix && <button type="button" className="dm-pill dm-accent dm-sm" onClick={() => onFix?.(s.key)}>{s.fix}</button>}
{onRemove && <button type="button" className="dm-pill dm-ghost dm-sm dm-mx-press" onClick={() => onRemove(s.key)}>Remove</button>}
</div>
</Fold>
</div>
);
}
/** What the agent knows: files, websites and connected folders, each with how far it is indexed. One that failed says why
and can offer a fix; Add source uploads files, adds a website or connects a folder. */
export function KnowledgeSources({ sources, onUpload, onAddWebsite, address, defaultAddress = '', onAddressChange, folders = [], onConnectFolder,
onResync, onRemove, onFix, title = 'Knowledge sources', status, className }: KnowledgeSourcesProps) {
const file = useRef<HTMLInputElement>(null);
// Studio's one hover: a highlight that glides from source to source
const listRef = useRef<HTMLDivElement>(null);
useHoverGlide(listRef, '.dm-ksx-s');
const field = useRef<HTMLInputElement>(null);
// a menu opens under its button, or above it when there is no room
const menu = usePopover();
// the card grows with its rows and shrinks as they go, eased (as grow() on the site)
const [root, inner] = useGrow();
const [view, setView] = useState<'main' | 'web' | 'folder'>('main');
const [url, setUrl] = useControllable(address, defaultAddress, onAddressChange);
// a menu that opened above Add source grows upwards whichever step it shows, so it is held by its bottom edge
const [bottom, setBottom] = useState<CSSProperties>({});
const up = String((menu.pop.style as Record<string, unknown>)['--dm-origin'] ?? '').startsWith('bottom');
useIsoLayoutEffect(() => {
const b = root.current?.querySelector<HTMLElement>('.dm-ksx-add,.dm-ksx-em .dm-pill'), r = b?.getBoundingClientRect(), h = root.current?.getBoundingClientRect();
setBottom(menu.open && up && r && h ? { top: 'auto', bottom: h.bottom - r.top + 6 } : {});
}, [menu.open, view, up]);
// rows there from the start come in one after another; a row added later comes in on its own
const [first] = useState(() => sources.map(s => s.key));
const total = status ?? `${fmt(sources.reduce((a, s) => a + (s.chunks ?? 0), 0))} chunks indexed`;
const canAdd = !!(onUpload || onAddWebsite || onConnectFolder);
const submit = (e: FormEvent) => {
e.preventDefault();
const v = url.trim().replace(/^https?:\/\//, '').replace(/\/$/, '');
if (!v) { field.current?.focus(); return; }
menu.close(); setUrl(''); onAddWebsite?.(v);
};
return (
<div data-dm="" ref={root} className={cx('dm-ksx dm-panel dm-growing dm-mx-grow', className)}>
<div ref={inner} className="dm-grow">
<div className="dm-ksx-h"><span className="dm-ksx-hi" aria-hidden="true"><Icon name="book" size="xs" /></span><div><b>{title}</b><Swap className="dm-muted dm-ksx-st">{total}</Swap></div></div>
<div ref={listRef} className="dm-ksx-list dm-mx-glide" role="list" aria-label="Sources">
{sources.map(s => { const at = first.indexOf(s.key); return <Row key={s.key} s={s} delay={at >= 0 ? at * 50 : 0} onResync={onResync} onRemove={onRemove} onFix={onFix} />; })}
</div>
{/* nothing left: the empty state, with Add source as an outline button */}
{!sources.length && (
<div className="dm-ksx-em"><span className="dm-ksx-em-art" aria-hidden="true" /><b>No sources yet</b><span>Add files, a website or a folder, and the agent reads them.</span>
{canAdd && <button type="button" className="dm-pill dm-line dm-sm dm-mx-press" {...menu.trigger} onClick={e => { if (!menu.open) setView('main'); menu.trigger.onClick(e); }}><Icon name="plus" size="xs" />Add source</button>}
</div>
)}
{canAdd && <>
{sources.length > 0 && <div className="dm-ksx-ft"><button type="button" className="dm-ksx-add dm-mx-press" {...menu.trigger} onClick={e => { if (!menu.open) setView('main'); menu.trigger.onClick(e); }}><Icon name="plus" size="xs" />Add source</button></div>}
<div {...menu.pop} style={{ ...menu.pop.style, ...bottom }} className={cx(menu.pop.className, 'dm-ksx-pop dm-mx-pop dm-mx-rows dm-mx-glide', view !== 'main' && 'dm-mx-sw')} role="menu" aria-label="Add source">
{view === 'main' && <>
{onUpload && <button type="button" className="dm-mi dm-mx-press" role="menuitem" onClick={() => { menu.closeSoon(); file.current?.click(); }}><Icon name="upload" size="xs" /><span>Upload files</span></button>}
{onAddWebsite && <button type="button" className="dm-mi dm-mx-press" role="menuitem" onClick={() => { setView('web'); requestAnimationFrame(() => field.current?.focus({ preventScroll: true })); }}><Icon name="globe" size="xs" /><span>Add a website</span></button>}
{onConnectFolder && <button type="button" className="dm-mi dm-mx-press" role="menuitem" onClick={() => setView('folder')}><Icon name="folder" size="xs" /><span>Connect a folder</span></button>}
</>}
{view === 'web' && (
<form className="dm-ksx-web" onSubmit={submit}>
<div className="dm-ph">Add a website</div>
<div className="dm-ksx-in"><Icon name="globe" size="xs" /><input ref={field} value={url} onChange={e => setUrl(e.target.value)} placeholder="example.com/docs" aria-label="Website address" spellCheck={false} autoComplete="off" /><button type="submit" className="dm-pill dm-accent dm-sm">Add</button></div>
</form>
)}
{view === 'folder' && <>
<div className="dm-ph">Connect a folder</div>
{folders.length
? folders.map(f => <button type="button" key={f.key} className="dm-mi dm-mx-press" role="menuitem" onClick={() => { menu.closeSoon(); onConnectFolder?.(f.key); }}><Icon name="folder" size="xs" /><span>{f.name}{f.detail && <span className="dm-d">{f.detail}</span>}</span></button>)
: <div className="dm-ph">All folders connected</div>}
</>}
</div>
{onUpload && <input ref={file} type="file" multiple hidden title="" onChange={e => { const fs = [...(e.target.files ?? [])]; e.target.value = ''; if (fs.length) onUpload(fs); }} />}
</>}
</div>
</div>
);
}
knowledge-sources.cssReact · 110 lines
/* Generated from designme.dev by scripts/sync.mjs. Edit the site, then sync. */
/* ---------- Knowledge sources ---------- */
/* what the agent knows: each source with its type, its size and how far it is indexed. The card sits on two columns (owner,
18 Nov), its content 16px from every edge: the head's neutral mark in a 28px column with each source's mark under it, and
the title and each source's words 12px after it; the menu buttons' glyphs end on the content's right edge. A row is not a
button, so it has no hover fill. The line under a source's name is its state, led by its mark (beside it, never over the
source's own): a green tick and what it holds once it is indexed, a clock while it waits, a bar and a count that shimmers
while it is read, and a red sign with the reason once it has failed, with a fix under it. A type's mark is a vivid tile of
its colour with white or the colour's own ink on it. The card grows and shrinks with its rows (grow()) */
.dm-ksx{padding:var(--dm-s-4);display:flex;flex-direction:column}
.dm-ksx.dm-growing:has(.dm-pop.dm-open){overflow:visible}
.dm-ksx-h{display:flex;align-items:center;gap:var(--dm-s-3);padding-bottom:var(--dm-s-2)}
.dm-ksx-hi{width:28px;height:28px;display:grid;place-items:center;flex:none;border-radius:calc(8px * var(--dm-rk-m,var(--dm-rk)));color:var(--dm-fg2);background:var(--dm-chip)}
.dm-ksx-h>div{flex:1;display:flex;flex-direction:column;min-width:0}
.dm-ksx-h b{font-weight:500;font-size:14px;line-height:20px}
.dm-ksx-st{font-size:12px;line-height:18px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.dm-ksx-list{display:flex;flex-direction:column;margin-inline:calc(-1 * var(--dm-s-2))}
/* a source's hover fill reaches 8px out round its row, with the rows' corners, while its tile and words stay on the card's
16px column (owner, 26 Nov: "highlight here doesn't work for studio") */
.dm-ksx-s{display:grid;grid-template-columns:28px minmax(0,1fr) auto;align-items:center;column-gap:var(--dm-s-3);padding:var(--dm-s-2);border-radius:var(--dm-r-in);font-size:13px}
.dm-ksx-s .dm-ic{width:28px;height:28px;border-radius:calc(8px * var(--dm-rk-m,var(--dm-rk)));display:grid;place-items:center}
.dm-ksx-s .dm-t{min-width:0;display:flex;flex-direction:column}
.dm-ksx-s .dm-nm{line-height:20px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.dm-ksx-s .dm-d{display:flex;align-items:center;gap:5px;min-width:0;height:18px;font-size:12px;color:var(--dm-muted)}
.dm-ksx-s .dm-d>span:last-child{min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.dm-ksx-s .dm-d>.dm-i{flex:none;color:var(--dm-muted)}
.dm-ksx-s[data-st="ready"] .dm-d>.dm-i{color:var(--dm-ok-mark)}
.dm-ksx-s[data-st="failed"] .dm-d{color:var(--dm-bad)}
/* why it failed is never cut short: on a narrow card it wraps, its sign on the first line */
.dm-ksx-s[data-st="failed"] .dm-d{height:auto;min-height:18px;align-items:flex-start;line-height:18px}
.dm-ksx-s[data-st="failed"] .dm-d>.dm-i{margin-top:3px}
.dm-ksx-s[data-st="failed"] .dm-d>span:last-child{white-space:normal;text-wrap:pretty}
.dm-ksx-s[data-st="failed"] .dm-d>.dm-i{color:var(--dm-bad-mark)}
.dm-ksx-s .dm-d .dm-shim{font-size:inherit}
.dm-ksx-s[data-st="indexing"] .dm-d{gap:var(--dm-s-2)}
.dm-ksx-bar{width:56px;height:4px;border-radius:var(--dm-r-tiny,2px);background:var(--dm-line);overflow:hidden;flex:none}
.dm-ksx-bar i{display:block;height:100%;border-radius:inherit;background:var(--dm-accent-mark,var(--dm-accent));transition:width .2s linear}
/* the menu button: its hover circle ends on the content's right edge (a box that fills keeps the card's 16px) */
.dm-ksx-more{width:28px;height:28px}
.dm-ksx-s .dm-ksx-fx{grid-column:2/-1}
.dm-ksx-fx>div{overflow-clip-margin:0px}
.dm-ksx-fx>div>div{display:flex;flex-wrap:wrap;gap:6px;padding-top:var(--dm-s-2)}
/* Add source: its + centred in the marks' column and its words on the title's; the hover box starts on the content's edge */
.dm-ksx-add{display:flex;align-items:center;gap:var(--dm-s-3);align-self:flex-start;height:32px;margin-top:var(--dm-s-1);padding:0 var(--dm-s-3) 0 0;font-size:13px;color:var(--dm-fg2);border-radius:calc(8px * var(--dm-rk-m,var(--dm-rk)));transition:background-color var(--dm-t-fast) var(--dm-ease),color var(--dm-t-fast) var(--dm-ease)}
.dm-ksx-add>.dm-i{width:28px;padding:0 8px;box-sizing:border-box}
.dm-ksx-add[aria-expanded="true"]{color:var(--dm-fg);background:var(--dm-row)}
@media (hover:hover) and (pointer:fine){.dm-ksx-add:hover{color:var(--dm-fg);background:var(--dm-row)}}
.dm-ksx-pop{width:248px}
/* switching the open menu to another view (a website, a folder) shows its first line at once and settles the rest after it, so
the menu never shows empty for a moment (the 40ms lead of .mx-rows is for a menu opening from its button) */
.dm-ksx-pop.dm-mx-sw>:first-child{animation:none}
.dm-ksx-pop.dm-mx-sw>*{animation-delay:calc((var(--dm-mx-i,0) - 1) * var(--dm-mx-step))}
/* its motion (the core's motion pieces, owner, 26 Nov): its menus grow out of their buttons and go back quicker, their rows
settle one after another (a menu's next step too) and one highlight glides between them; one highlight glides from source to
source in every style (.mx-glide); a press shows at once (.mx-press); the card grows on the spring (.mx-grow) */
.dm-ksx-mpop{min-width:160px}
.dm-ksx-mpop .dm-mi.dm-del,.dm-ksx-mpop .dm-mi.dm-del .dm-i{color:var(--dm-bad)}
@media (hover:hover) and (pointer:fine){.dm-ksx-mpop .dm-mi.dm-del:hover{background:var(--dm-bad-bg)}}
.dm-ksx-mpop .dm-mi[disabled],.dm-ksx-mpop .dm-mi[disabled] .dm-i{opacity:1;cursor:not-allowed;background:none;color:var(--dm-dis)}
.dm-ksx-web{display:flex;flex-direction:column;gap:var(--dm-s-1)}
/* (the field holds the site's small button, 28px, with 4px round it) */
.dm-ksx-in{display:flex;align-items:center;gap:var(--dm-s-2);height:36px;margin:0 2px 2px;padding:0 var(--dm-s-1) 0 10px;border-radius:var(--dm-r-field);background:var(--dm-surface);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-field-line) 50%,transparent);color:var(--dm-muted);transition:box-shadow var(--dm-t-fast)}
@supports (corner-shape:squircle){.dm-ksx-in{corner-shape:squircle;border-radius:var(--dm-r-field-sq)}}
.dm-ksx-in:has(input:focus){box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-field-line-strong) 50%,transparent)}
.dm-ksx-in input{flex:1;min-width:0;height:100%;border:0;outline:0;background:transparent;font:inherit;font-size:13px;color:var(--dm-fg)}
.dm-ksx-in input::placeholder{color:var(--dm-muted)}
/* nothing left: the empty state (the lab's): a small sketch of the list on a white card, a title, one muted line
and Add source as an outline button */
.dm-ksx-em{display:flex;flex-direction:column;align-items:center;gap:4px;padding:16px 16px 20px;text-align:center}
.dm-ksx-em b{font-size:13.5px;line-height:18px;font-weight:500;color:var(--dm-fg)}
.dm-ksx-em>span:not(.dm-ksx-em-art){max-width:290px;font-size:12.5px;line-height:1.5;color:var(--dm-muted)}
.dm-ksx-em .dm-pill{margin-top:12px}
.dm-ksx-em-art{position:relative;display:block;width:136px;height:70px;margin:0 0 16px;border-radius:calc(10px * var(--dm-rk-l,var(--dm-rk)));background:var(--dm-surface);box-shadow:var(--dm-shadow)}
.dm-ksx-em-art::before{content:"";position:absolute;left:14px;top:13px;width:12px;height:12px;border-radius:4px;background:var(--dm-ghost,var(--dm-chip));box-shadow:0 16px 0 var(--dm-ghost,var(--dm-chip)),0 32px 0 var(--dm-ghost-2,var(--dm-wash))}
.dm-ksx-em-art::after{content:"";position:absolute;left:34px;top:16px;width:58px;height:6px;border-radius:3px;background:var(--dm-ghost,var(--dm-chip));box-shadow:0 16px 0 var(--dm-ghost,var(--dm-chip)),0 32px 0 var(--dm-ghost-2,var(--dm-wash))}
.dm-ksx-list:not(:empty)~.dm-ksx-em,.dm-ksx-list:empty~.dm-ksx-ft{display:none}
/* the foot sits under a hairline in Soft and Blueprint (owner, 21 Nov), its button's words 16px from the hairline and 16px from
the card's bottom edge (owner, 23 Nov): the ghost button's 32px box reaches 6px round its words, so the foot has 10px above it
and reaches 6px into the card's bottom padding. Studio's is a foot strip */
.dm-ksx-ft{margin-bottom:-6px;padding-top:10px;border-top:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent)}
.dm-ksx-ft .dm-ksx-add{margin-top:0}
:root:not([data-style="soft"],[data-style="studio"]) .dm-ksx-em-art:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){box-shadow:0 0 0 1px color-mix(in srgb,var(--dm-rail) 60%,transparent)}
:root:not([data-style="soft"],[data-style="studio"]) :is(.dm-ksx-em-art::before,.dm-ksx-em-art::after):not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){border-radius:0}
/* nothing in it grows or shrinks when it is pressed (owner, 18 Nov); Studio's ink primary alone presses */
.dm-ksx :is(.dm-ib,.dm-pill):active,:root[data-style="studio"] .dm-ksx .dm-ib:active,:root [data-style="studio"] .dm-ksx .dm-ib:active,:root [data-style="studio"].dm-ksx .dm-ib:active{transform:none}
/* Studio (owner, 17 and 18 Nov): the head an off-white strip with a hairline under it; the sources' marks one neutral grey
with a hairline; Add source a flat secondary button on an off-white foot strip, 16px from the card's edges and the
strip's hairline (owner, 23 Nov); the content 16px
in from each edge and 16px from each strip; menus scale and fade from their button, with the card's corners */
:root[data-style="studio"] .dm-ksx.dm-panel,:root [data-style="studio"] .dm-ksx.dm-panel,:root [data-style="studio"].dm-ksx.dm-panel{padding:0}
:root[data-style="studio"] .dm-ksx-h,:root [data-style="studio"] .dm-ksx-h,:root [data-style="studio"].dm-ksx-h{min-height:calc(28px + 2 * var(--dm-strip-y) + 1px);padding:var(--dm-strip-y) 16px;background:var(--dm-strip);border-bottom:1px solid var(--dm-line);border-radius:var(--dm-r-card) var(--dm-r-card) 0 0}
:root[data-style="studio"] .dm-ksx-hi,:root [data-style="studio"] .dm-ksx-hi,:root [data-style="studio"].dm-ksx-hi{background:var(--dm-surface);box-shadow:inset 0 0 0 1px var(--dm-hair);border-radius:10px}
:root[data-style="studio"] .dm-ksx-list,:root [data-style="studio"] .dm-ksx-list,:root [data-style="studio"].dm-ksx-list{margin-inline:0;padding:var(--dm-s-2)}
:root[data-style="studio"] .dm-ksx-list:empty,:root [data-style="studio"] .dm-ksx-list:empty,:root [data-style="studio"].dm-ksx-list:empty{padding:0}
:root[data-style="studio"] .dm-ksx-s .dm-ic,:root [data-style="studio"] .dm-ksx-s .dm-ic,:root [data-style="studio"].dm-ksx-s .dm-ic{background:var(--dm-surface)!important;color:var(--dm-fg2)!important;box-shadow:inset 0 0 0 1px var(--dm-hair);border-radius:10px}
:root[data-style="studio"] .dm-ksx-s[data-st="ready"] .dm-d>.dm-i,:root [data-style="studio"] .dm-ksx-s[data-st="ready"] .dm-d>.dm-i,:root [data-style="studio"].dm-ksx-s[data-st="ready"] .dm-d>.dm-i{color:color-mix(in srgb,var(--dm-ok-mark) 80%,var(--dm-ok))}
:root[data-style="studio"] .dm-ksx-ft,:root [data-style="studio"] .dm-ksx-ft,:root [data-style="studio"].dm-ksx-ft{margin-bottom:0;padding:var(--dm-strip-y) var(--dm-s-4);background:var(--dm-strip);border-top:1px solid var(--dm-line);border-radius:0 0 var(--dm-r-card) var(--dm-r-card)}
:root[data-style="studio"] .dm-ksx-add,:root [data-style="studio"] .dm-ksx-add,:root [data-style="studio"].dm-ksx-add{gap:6px;height:28px;margin:0;padding:0 12px 0 10px;border-radius:var(--dm-r-pill);font-weight:500;color:var(--dm-fg);background:linear-gradient(180deg,var(--dm-btn2-1),var(--dm-btn2-2));box-shadow:var(--dm-btn2-depth);transition:box-shadow var(--dm-t-fast) var(--dm-ease)}
:root[data-style="studio"] .dm-ksx-add>.dm-i,:root [data-style="studio"] .dm-ksx-add>.dm-i,:root [data-style="studio"].dm-ksx-add>.dm-i{width:12px;padding:0}
@media (hover:hover) and (pointer:fine){:root[data-style="studio"] :is(.dm-ksx-add:hover,.dm-ksx-add[aria-expanded="true"]),:root [data-style="studio"] :is(.dm-ksx-add:hover,.dm-ksx-add[aria-expanded="true"]),:root [data-style="studio"]:is(.dm-ksx-add:hover,.dm-ksx-add[aria-expanded="true"]){background:linear-gradient(180deg,var(--dm-btn2-1),var(--dm-btn2-2));box-shadow:var(--dm-btn2-hover)}}
:root[data-style="studio"] .dm-ksx-add:active,:root [data-style="studio"] .dm-ksx-add:active,:root [data-style="studio"].dm-ksx-add:active{box-shadow:var(--dm-btn2-press)}
:root[data-style="studio"] .dm-ksx .dm-pill.dm-ghost:not([disabled]),:root [data-style="studio"] .dm-ksx .dm-pill.dm-ghost:not([disabled]),:root [data-style="studio"].dm-ksx .dm-pill.dm-ghost:not([disabled]){color:var(--dm-fg);background:linear-gradient(180deg,var(--dm-btn2-1),var(--dm-btn2-2));box-shadow:var(--dm-btn2-depth)}
@media (hover:hover) and (pointer:fine){:root[data-style="studio"] .dm-ksx .dm-pill.dm-ghost:not([disabled]):hover,:root [data-style="studio"] .dm-ksx .dm-pill.dm-ghost:not([disabled]):hover,:root [data-style="studio"].dm-ksx .dm-pill.dm-ghost:not([disabled]):hover{background:linear-gradient(180deg,var(--dm-btn2-1),var(--dm-btn2-2));box-shadow:var(--dm-btn2-hover)}}
:root[data-style="studio"] .dm-ksx .dm-pill.dm-ghost:not([disabled]):active,:root [data-style="studio"] .dm-ksx .dm-pill.dm-ghost:not([disabled]):active,:root [data-style="studio"].dm-ksx .dm-pill.dm-ghost:not([disabled]):active{box-shadow:var(--dm-btn2-press)}
:root[data-style="studio"] :is(.dm-ksx-pop,.dm-ksx-mpop),:root [data-style="studio"] :is(.dm-ksx-pop,.dm-ksx-mpop),:root [data-style="studio"]:is(.dm-ksx-pop,.dm-ksx-mpop){padding:6px;border-radius:var(--dm-r-card)}
:root[data-style="studio"] :is(.dm-ksx-pop,.dm-ksx-mpop) .dm-mi,:root [data-style="studio"] :is(.dm-ksx-pop,.dm-ksx-mpop) .dm-mi,:root [data-style="studio"]:is(.dm-ksx-pop,.dm-ksx-mpop) .dm-mi{border-radius:calc(var(--dm-r-card) - 6px)}
:root[data-style="studio"] .dm-ksx-pop .dm-ph,:root [data-style="studio"] .dm-ksx-pop .dm-ph,:root [data-style="studio"].dm-ksx-pop .dm-ph{padding-inline:10px}
:root[data-style="studio"] .dm-ksx-in,:root [data-style="studio"] .dm-ksx-in,:root [data-style="studio"].dm-ksx-in{margin:0;padding-right:var(--dm-s-1);border-radius:calc(var(--dm-r-card) - 6px)}
:root[data-style="studio"] .dm-ksx-em,:root [data-style="studio"] .dm-ksx-em,:root [data-style="studio"].dm-ksx-em{padding:28px 16px 30px}
KnowledgeSources.astroAstro · 32 lines
---
// Generated from designme.dev by scripts/sync.mjs. Edit the site, then sync.
// Knowledge sources: The files, sites and folders the agent knows, and how far each is indexed.
// The markup, CSS and script are designme.dev's own, run by the shared core in ../core, which mounts the component when it scrolls
// into view and plays its demo. To show your own data, change knowledge-sources.js. The markup is kept exactly as it is (is:raw).
import type { HTMLAttributes } from 'astro/types';
import '../core/designme.css';
import './knowledge-sources.css';
export interface Props extends HTMLAttributes<'div'> {
/** "soft" or "studio" draws it in that style. Leave it out for Blueprint, or for the style set on <html> (data-style="soft" or "studio") */
'data-style'?: 'soft' | 'studio';
}
const { class: className, ...rest } = Astro.props;
---
<div class:list={['card', className]} data-c="knowledge-sources" {...rest}>
<div class="stage-in"><Fragment is:raw>
<div class="ksx panel mx-grow" data-reveal="flat">
<div class="ksx-h"><span class="ksx-hi" aria-hidden="true"><svg class="i xs"><use href="#i-book"/></svg></span><div><b>Knowledge sources</b><span class="muted ksx-st" aria-live="polite"></span></div></div>
<div class="ksx-list mx-glide" role="list" aria-label="Sources"></div>
<div class="ksx-em"><span class="ksx-em-art" aria-hidden="true"></span><b>No sources yet</b><span>Add files, a website or a folder, and the agent reads them.</span><button class="pill line sm ksx-add2 mx-press" data-pop=".ksx-pop" aria-haspopup="menu" aria-expanded="false"><svg class="i xs"><use href="#i-plus"/></svg>Add source</button></div>
<div class="ksx-ft"><button class="ksx-add mx-press" data-pop=".ksx-pop" aria-haspopup="menu" aria-expanded="false"><svg class="i xs"><use href="#i-plus"/></svg>Add source</button></div>
<div class="pop ksx-pop mx-pop mx-rows mx-glide" role="menu" aria-label="Add source"></div>
<div class="pop ksx-mpop mx-pop mx-rows mx-glide" role="menu" aria-label="Source actions"><button class="mi ksx-rs mx-press" role="menuitem" data-close><svg class="i xs"><use href="#i-refresh"/></svg>Re-sync</button><div class="sep"></div><button class="mi del ksx-rm mx-press" role="menuitem" data-close><svg class="i xs"><use href="#i-trash"/></svg>Remove</button></div>
<input class="ksx-file" type="file" multiple hidden>
</div>
</Fragment></div>
</div>
<script>
import './knowledge-sources.js';
</script>
knowledge-sources.htmlHTML · 14 lines
<div class="card" data-c="knowledge-sources">
<div class="stage-in">
<div class="ksx panel mx-grow" data-reveal="flat">
<div class="ksx-h"><span class="ksx-hi" aria-hidden="true"><svg class="i xs"><use href="#i-book"/></svg></span><div><b>Knowledge sources</b><span class="muted ksx-st" aria-live="polite"></span></div></div>
<div class="ksx-list mx-glide" role="list" aria-label="Sources"></div>
<div class="ksx-em"><span class="ksx-em-art" aria-hidden="true"></span><b>No sources yet</b><span>Add files, a website or a folder, and the agent reads them.</span><button class="pill line sm ksx-add2 mx-press" data-pop=".ksx-pop" aria-haspopup="menu" aria-expanded="false"><svg class="i xs"><use href="#i-plus"/></svg>Add source</button></div>
<div class="ksx-ft"><button class="ksx-add mx-press" data-pop=".ksx-pop" aria-haspopup="menu" aria-expanded="false"><svg class="i xs"><use href="#i-plus"/></svg>Add source</button></div>
<div class="pop ksx-pop mx-pop mx-rows mx-glide" role="menu" aria-label="Add source"></div>
<div class="pop ksx-mpop mx-pop mx-rows mx-glide" role="menu" aria-label="Source actions"><button class="mi ksx-rs mx-press" role="menuitem" data-close><svg class="i xs"><use href="#i-refresh"/></svg>Re-sync</button><div class="sep"></div><button class="mi del ksx-rm mx-press" role="menuitem" data-close><svg class="i xs"><use href="#i-trash"/></svg>Remove</button></div>
<input class="ksx-file" type="file" multiple hidden>
</div>
</div>
</div>
knowledge-sources.cssHTML · 109 lines
/* ---------- Knowledge sources ---------- */
/* what the agent knows: each source with its type, its size and how far it is indexed. The card sits on two columns (owner,
18 Nov), its content 16px from every edge: the head's neutral mark in a 28px column with each source's mark under it, and
the title and each source's words 12px after it; the menu buttons' glyphs end on the content's right edge. A row is not a
button, so it has no hover fill. The line under a source's name is its state, led by its mark (beside it, never over the
source's own): a green tick and what it holds once it is indexed, a clock while it waits, a bar and a count that shimmers
while it is read, and a red sign with the reason once it has failed, with a fix under it. A type's mark is a vivid tile of
its colour with white or the colour's own ink on it. The card grows and shrinks with its rows (grow()) */
.ksx{padding:var(--dm-s-4);display:flex;flex-direction:column}
.ksx.growing:has(.pop.open){overflow:visible}
.ksx-h{display:flex;align-items:center;gap:var(--dm-s-3);padding-bottom:var(--dm-s-2)}
.ksx-hi{width:28px;height:28px;display:grid;place-items:center;flex:none;border-radius:calc(8px * var(--dm-rk-m,var(--dm-rk)));color:var(--dm-fg2);background:var(--dm-chip)}
.ksx-h>div{flex:1;display:flex;flex-direction:column;min-width:0}
.ksx-h b{font-weight:500;font-size:14px;line-height:20px}
.ksx-st{font-size:12px;line-height:18px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.ksx-list{display:flex;flex-direction:column;margin-inline:calc(-1 * var(--dm-s-2))}
/* a source's hover fill reaches 8px out round its row, with the rows' corners, while its tile and words stay on the card's
16px column (owner, 26 Nov: "highlight here doesn't work for studio") */
.ksx-s{display:grid;grid-template-columns:28px minmax(0,1fr) auto;align-items:center;column-gap:var(--dm-s-3);padding:var(--dm-s-2);border-radius:var(--dm-r-in);font-size:13px}
.ksx-s .ic{width:28px;height:28px;border-radius:calc(8px * var(--dm-rk-m,var(--dm-rk)));display:grid;place-items:center}
.ksx-s .t{min-width:0;display:flex;flex-direction:column}
.ksx-s .nm{line-height:20px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.ksx-s .d{display:flex;align-items:center;gap:5px;min-width:0;height:18px;font-size:12px;color:var(--dm-muted)}
.ksx-s .d>span:last-child{min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.ksx-s .d>.i{flex:none;color:var(--dm-muted)}
.ksx-s[data-st="ready"] .d>.i{color:var(--dm-ok-mark)}
.ksx-s[data-st="failed"] .d{color:var(--dm-bad)}
/* why it failed is never cut short: on a narrow card it wraps, its sign on the first line */
.ksx-s[data-st="failed"] .d{height:auto;min-height:18px;align-items:flex-start;line-height:18px}
.ksx-s[data-st="failed"] .d>.i{margin-top:3px}
.ksx-s[data-st="failed"] .d>span:last-child{white-space:normal;text-wrap:pretty}
.ksx-s[data-st="failed"] .d>.i{color:var(--dm-bad-mark)}
.ksx-s .d .shim{font-size:inherit}
.ksx-s[data-st="indexing"] .d{gap:var(--dm-s-2)}
.ksx-bar{width:56px;height:4px;border-radius:var(--dm-r-tiny,2px);background:var(--dm-line);overflow:hidden;flex:none}
.ksx-bar i{display:block;height:100%;border-radius:inherit;background:var(--dm-accent-mark,var(--dm-accent));transition:width .2s linear}
/* the menu button: its hover circle ends on the content's right edge (a box that fills keeps the card's 16px) */
.ksx-more{width:28px;height:28px}
.ksx-s .ksx-fx{grid-column:2/-1}
.ksx-fx>div{overflow-clip-margin:0px}
.ksx-fx>div>div{display:flex;flex-wrap:wrap;gap:6px;padding-top:var(--dm-s-2)}
/* Add source: its + centred in the marks' column and its words on the title's; the hover box starts on the content's edge */
.ksx-add{display:flex;align-items:center;gap:var(--dm-s-3);align-self:flex-start;height:32px;margin-top:var(--dm-s-1);padding:0 var(--dm-s-3) 0 0;font-size:13px;color:var(--dm-fg2);border-radius:calc(8px * var(--dm-rk-m,var(--dm-rk)));transition:background-color var(--dm-t-fast) var(--dm-ease),color var(--dm-t-fast) var(--dm-ease)}
.ksx-add>.i{width:28px;padding:0 8px;box-sizing:border-box}
.ksx-add[aria-expanded="true"]{color:var(--dm-fg);background:var(--dm-row)}
@media (hover:hover) and (pointer:fine){.ksx-add:hover{color:var(--dm-fg);background:var(--dm-row)}}
.ksx-pop{width:248px}
/* switching the open menu to another view (a website, a folder) shows its first line at once and settles the rest after it, so
the menu never shows empty for a moment (the 40ms lead of .mx-rows is for a menu opening from its button) */
.ksx-pop.mx-sw>:first-child{animation:none}
.ksx-pop.mx-sw>*{animation-delay:calc((var(--dm-mx-i,0) - 1) * var(--dm-mx-step))}
/* its motion (the core's motion pieces, owner, 26 Nov): its menus grow out of their buttons and go back quicker, their rows
settle one after another (a menu's next step too) and one highlight glides between them; one highlight glides from source to
source in every style (.mx-glide); a press shows at once (.mx-press); the card grows on the spring (.mx-grow) */
.ksx-mpop{min-width:160px}
.ksx-mpop .mi.del,.ksx-mpop .mi.del .i{color:var(--dm-bad)}
@media (hover:hover) and (pointer:fine){.ksx-mpop .mi.del:hover{background:var(--dm-bad-bg)}}
.ksx-mpop .mi[disabled],.ksx-mpop .mi[disabled] .i{opacity:1;cursor:not-allowed;background:none;color:var(--dm-dis)}
.ksx-web{display:flex;flex-direction:column;gap:var(--dm-s-1)}
/* (the field holds the site's small button, 28px, with 4px round it) */
.ksx-in{display:flex;align-items:center;gap:var(--dm-s-2);height:36px;margin:0 2px 2px;padding:0 var(--dm-s-1) 0 10px;border-radius:var(--dm-r-field);background:var(--dm-surface);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-field-line) 50%,transparent);color:var(--dm-muted);transition:box-shadow var(--dm-t-fast)}
@supports (corner-shape:squircle){.ksx-in{corner-shape:squircle;border-radius:var(--dm-r-field-sq)}}
.ksx-in:has(input:focus){box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-field-line-strong) 50%,transparent)}
.ksx-in input{flex:1;min-width:0;height:100%;border:0;outline:0;background:transparent;font:inherit;font-size:13px;color:var(--dm-fg)}
.ksx-in input::placeholder{color:var(--dm-muted)}
/* nothing left: the empty state (the lab's): a small sketch of the list on a white card, a title, one muted line
and Add source as an outline button */
.ksx-em{display:flex;flex-direction:column;align-items:center;gap:4px;padding:16px 16px 20px;text-align:center}
.ksx-em b{font-size:13.5px;line-height:18px;font-weight:500;color:var(--dm-fg)}
.ksx-em>span:not(.ksx-em-art){max-width:290px;font-size:12.5px;line-height:1.5;color:var(--dm-muted)}
.ksx-em .pill{margin-top:12px}
.ksx-em-art{position:relative;display:block;width:136px;height:70px;margin:0 0 16px;border-radius:calc(10px * var(--dm-rk-l,var(--dm-rk)));background:var(--dm-surface);box-shadow:var(--dm-shadow)}
.ksx-em-art::before{content:"";position:absolute;left:14px;top:13px;width:12px;height:12px;border-radius:4px;background:var(--dm-ghost,var(--dm-chip));box-shadow:0 16px 0 var(--dm-ghost,var(--dm-chip)),0 32px 0 var(--dm-ghost-2,var(--dm-wash))}
.ksx-em-art::after{content:"";position:absolute;left:34px;top:16px;width:58px;height:6px;border-radius:3px;background:var(--dm-ghost,var(--dm-chip));box-shadow:0 16px 0 var(--dm-ghost,var(--dm-chip)),0 32px 0 var(--dm-ghost-2,var(--dm-wash))}
.ksx-list:not(:empty)~.ksx-em,.ksx-list:empty~.ksx-ft{display:none}
/* the foot sits under a hairline in Soft and Blueprint (owner, 21 Nov), its button's words 16px from the hairline and 16px from
the card's bottom edge (owner, 23 Nov): the ghost button's 32px box reaches 6px round its words, so the foot has 10px above it
and reaches 6px into the card's bottom padding. Studio's is a foot strip */
.ksx-ft{margin-bottom:-6px;padding-top:10px;border-top:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent)}
.ksx-ft .ksx-add{margin-top:0}
:root:not([data-style="soft"],[data-style="studio"]) .ksx-em-art:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){box-shadow:0 0 0 1px color-mix(in srgb,var(--dm-rail) 60%,transparent)}
:root:not([data-style="soft"],[data-style="studio"]) :is(.ksx-em-art::before,.ksx-em-art::after):not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){border-radius:0}
/* nothing in it grows or shrinks when it is pressed (owner, 18 Nov); Studio's ink primary alone presses */
.ksx :is(.ib,.pill):active,:root[data-style="studio"] .ksx .ib:active,:root [data-style="studio"] .ksx .ib:active,:root [data-style="studio"].ksx .ib:active{transform:none}
/* Studio (owner, 17 and 18 Nov): the head an off-white strip with a hairline under it; the sources' marks one neutral grey
with a hairline; Add source a flat secondary button on an off-white foot strip, 16px from the card's edges and the
strip's hairline (owner, 23 Nov); the content 16px
in from each edge and 16px from each strip; menus scale and fade from their button, with the card's corners */
:root[data-style="studio"] .ksx.panel,:root [data-style="studio"] .ksx.panel,:root [data-style="studio"].ksx.panel{padding:0}
:root[data-style="studio"] .ksx-h,:root [data-style="studio"] .ksx-h,:root [data-style="studio"].ksx-h{min-height:calc(28px + 2 * var(--dm-strip-y) + 1px);padding:var(--dm-strip-y) 16px;background:var(--dm-strip);border-bottom:1px solid var(--dm-line);border-radius:var(--dm-r-card) var(--dm-r-card) 0 0}
:root[data-style="studio"] .ksx-hi,:root [data-style="studio"] .ksx-hi,:root [data-style="studio"].ksx-hi{background:var(--dm-surface);box-shadow:inset 0 0 0 1px var(--dm-hair);border-radius:10px}
:root[data-style="studio"] .ksx-list,:root [data-style="studio"] .ksx-list,:root [data-style="studio"].ksx-list{margin-inline:0;padding:var(--dm-s-2)}
:root[data-style="studio"] .ksx-list:empty,:root [data-style="studio"] .ksx-list:empty,:root [data-style="studio"].ksx-list:empty{padding:0}
:root[data-style="studio"] .ksx-s .ic,:root [data-style="studio"] .ksx-s .ic,:root [data-style="studio"].ksx-s .ic{background:var(--dm-surface)!important;color:var(--dm-fg2)!important;box-shadow:inset 0 0 0 1px var(--dm-hair);border-radius:10px}
:root[data-style="studio"] .ksx-s[data-st="ready"] .d>.i,:root [data-style="studio"] .ksx-s[data-st="ready"] .d>.i,:root [data-style="studio"].ksx-s[data-st="ready"] .d>.i{color:color-mix(in srgb,var(--dm-ok-mark) 80%,var(--dm-ok))}
:root[data-style="studio"] .ksx-ft,:root [data-style="studio"] .ksx-ft,:root [data-style="studio"].ksx-ft{margin-bottom:0;padding:var(--dm-strip-y) var(--dm-s-4);background:var(--dm-strip);border-top:1px solid var(--dm-line);border-radius:0 0 var(--dm-r-card) var(--dm-r-card)}
:root[data-style="studio"] .ksx-add,:root [data-style="studio"] .ksx-add,:root [data-style="studio"].ksx-add{gap:6px;height:28px;margin:0;padding:0 12px 0 10px;border-radius:var(--dm-r-pill);font-weight:500;color:var(--dm-fg);background:linear-gradient(180deg,var(--dm-btn2-1),var(--dm-btn2-2));box-shadow:var(--dm-btn2-depth);transition:box-shadow var(--dm-t-fast) var(--dm-ease)}
:root[data-style="studio"] .ksx-add>.i,:root [data-style="studio"] .ksx-add>.i,:root [data-style="studio"].ksx-add>.i{width:12px;padding:0}
@media (hover:hover) and (pointer:fine){:root[data-style="studio"] :is(.ksx-add:hover,.ksx-add[aria-expanded="true"]),:root [data-style="studio"] :is(.ksx-add:hover,.ksx-add[aria-expanded="true"]),:root [data-style="studio"]:is(.ksx-add:hover,.ksx-add[aria-expanded="true"]){background:linear-gradient(180deg,var(--dm-btn2-1),var(--dm-btn2-2));box-shadow:var(--dm-btn2-hover)}}
:root[data-style="studio"] .ksx-add:active,:root [data-style="studio"] .ksx-add:active,:root [data-style="studio"].ksx-add:active{box-shadow:var(--dm-btn2-press)}
:root[data-style="studio"] .ksx .pill.ghost:not([disabled]),:root [data-style="studio"] .ksx .pill.ghost:not([disabled]),:root [data-style="studio"].ksx .pill.ghost:not([disabled]){color:var(--dm-fg);background:linear-gradient(180deg,var(--dm-btn2-1),var(--dm-btn2-2));box-shadow:var(--dm-btn2-depth)}
@media (hover:hover) and (pointer:fine){:root[data-style="studio"] .ksx .pill.ghost:not([disabled]):hover,:root [data-style="studio"] .ksx .pill.ghost:not([disabled]):hover,:root [data-style="studio"].ksx .pill.ghost:not([disabled]):hover{background:linear-gradient(180deg,var(--dm-btn2-1),var(--dm-btn2-2));box-shadow:var(--dm-btn2-hover)}}
:root[data-style="studio"] .ksx .pill.ghost:not([disabled]):active,:root [data-style="studio"] .ksx .pill.ghost:not([disabled]):active,:root [data-style="studio"].ksx .pill.ghost:not([disabled]):active{box-shadow:var(--dm-btn2-press)}
:root[data-style="studio"] :is(.ksx-pop,.ksx-mpop),:root [data-style="studio"] :is(.ksx-pop,.ksx-mpop),:root [data-style="studio"]:is(.ksx-pop,.ksx-mpop){padding:6px;border-radius:var(--dm-r-card)}
:root[data-style="studio"] :is(.ksx-pop,.ksx-mpop) .mi,:root [data-style="studio"] :is(.ksx-pop,.ksx-mpop) .mi,:root [data-style="studio"]:is(.ksx-pop,.ksx-mpop) .mi{border-radius:calc(var(--dm-r-card) - 6px)}
:root[data-style="studio"] .ksx-pop .ph,:root [data-style="studio"] .ksx-pop .ph,:root [data-style="studio"].ksx-pop .ph{padding-inline:10px}
:root[data-style="studio"] .ksx-in,:root [data-style="studio"] .ksx-in,:root [data-style="studio"].ksx-in{margin:0;padding-right:var(--dm-s-1);border-radius:calc(var(--dm-r-card) - 6px)}
:root[data-style="studio"] .ksx-em,:root [data-style="studio"] .ksx-em,:root [data-style="studio"].ksx-em{padding:28px 16px 30px}
knowledge-sources.jsHTML · 125 lines
DM.def('knowledge-sources', (r, c) => {
r.innerHTML = r.innerHTML.replace(/\{plus\}/g, I('plus','xs')).replace('{refresh}', I('refresh','xs')).replace('{trash}', I('trash','xs')).replace('{book}', I('book','xs'));
// Studio's one hover: a highlight that glides from row to row (hoverGlide)
c.offs.push(hoverGlide($('.ksx-list', r), '.ksx-s'));
// a source's type gives it its icon, on a vivid tile of its colour: uploaded files, a website the agent crawls, or a
// connected folder of docs
const KIND = { files:['file-text','p'], web:['globe','b'], folder:['folder','m'] };
// a connected folder and a set of uploads are ready, and a PDF is being read. One source indexes at a time and the rest
// wait in line; a source's chunks count once it has been indexed. `ms` is how long a full pass takes in this preview
const S = [
{ kind:'folder', name:'Product docs', n:86, unit:'pages', chunks:642, st:'ready', ago:'2m ago', had:true, ms:2500 },
{ kind:'files', name:'Sales playbooks', n:18, unit:'files', chunks:318, st:'ready', ago:'1h ago', had:true, ms:2500 },
{ kind:'files', name:'Brand book 2024.pdf', n:24, unit:'pages', chunks:48, st:'queued', ms:19000, fail:{ at:9, why:'Scanned PDF, no text found', fix:'Retry with OCR' } }
];
const FOLDERS = [['Design specs', 'Google Drive', 57, 230], ['Research notes', 'Notion', 31, 124]];
const root = $('.ksx', r) || r, list = $('.ksx-list', r), st = $('.ksx-st', r), pop = $('.ksx-pop', r), mpop = $('.ksx-mpop', r), file = $('.ksx-file', r);
// Add source sits under the list, and in the empty state once every source is gone; both open the same menu
const add = $('.ksx-add', r), adds = $$('.ksx-add,.ksx-add2', r); let from = add;
const fmt = n => n.toLocaleString('en-US');
const of = (n, unit) => fmt(n) + ' ' + (n === 1 ? unit.slice(0, -1) : unit);
const esc = t => t.replace(/&/g, '&').replace(/</g, '<');
// the line under a source's name, led by its state's mark: a tick once indexed, a clock while it waits, a sign when it failed
const line = x => x.st === 'queued' ? I('clock','xs') + `<span>${x.ocr ? 'Queued to read with OCR' : 'Queued'}</span>`
: x.st === 'failed' ? I('alert','xs') + `<span>${esc(x.fail.why)}</span>` : I('ok','xs') + `<span>${of(x.n, x.unit)} · Synced ${x.ago}</span>`;
function row(x){
const [ic, k] = KIND[x.kind];
x.el = html(`<div class="ksx-s" role="listitem"><span class="ic" style="background:var(--dm-av-${k});color:var(--dm-av-${k}-ink)" aria-hidden="true">${I(ic,'xs')}</span><span class="t"><span class="nm"></span><span class="d"></span></span><button class="ib ksx-more mx-press" aria-haspopup="menu" aria-expanded="false" data-tip="More" data-pop=".ksx-mpop" data-pop-align="end">${I('more')}</button><div class="ksx-fx fold shut" inert><div><div><button class="pill accent sm ksx-fix"></button><button class="pill ghost sm ksx-del mx-press">Remove</button></div></div></div></div>`);
$('.nm', x.el).textContent = x.name; $('.ksx-more', x.el).setAttribute('aria-label', 'Actions for ' + x.name);
$('.ksx-fix', x.el).onclick = () => { x.ocr = true; x.st = 'queued'; x.ms = 3000; paint(x); next(); };
$('.ksx-del', x.el).onclick = () => remove(x);
paint(x, true); return x.el;
}
// the progress bar and its count, while a source is being indexed; the count shimmers, as every line of a process at work
function prog(x){
const bar = $('.ksx-bar', x.el); if (!bar) return; const k = Math.floor(x.done);
$('i', bar).style.width = k / x.n * 100 + '%'; bar.setAttribute('aria-valuenow', k);
$('.num', x.el).textContent = fmt(k) + ' of ' + of(x.n, x.unit);
}
function paint(x, now){
const d = $('.d', x.el); x.el.dataset.st = x.st;
// the bar goes through the same swap as the line before it, so a line still swapping in can't land on top of it
if (x.st === 'indexing'){ const bar = `<span class="ksx-bar" role="progressbar" aria-label="Indexing ${x.name.replace(/[<&"]/g, '')}" aria-valuemin="0" aria-valuemax="${x.n}"><i style="width:0"></i></span><span class="num shim"></span>`; if (now){ d.innerHTML = bar; prog(x); } else swap(d, bar, true); }
else if (now) d.innerHTML = line(x); else swap(d, line(x), true);
const fx = $('.ksx-fx', x.el), on = x.st === 'failed';
if (on) $('.ksx-fix', x.el).textContent = x.fail.fix;
fx.classList.toggle('shut', !on); fx.inert = !on;
}
// the line under the title says what the list doesn't: how much of it the agent can search, once it is indexed
const total = () => `${fmt(S.reduce((a, x) => a + (x.had ? x.chunks : 0), 0))} chunks indexed`;
const counts = now => { if (now) st.textContent = total(); else swap(st, total()); };
// the one being indexed moves on every tick; a scanned PDF stops where its text runs out, until it is read with OCR
function next(){
if (S.some(x => x.st === 'indexing')) return;
const x = S.find(y => y.st === 'queued'); if (!x) return;
x.st = 'indexing'; x.done = 0; paint(x);
}
c.every(100, () => {
const x = S.find(y => y.st === 'indexing'); if (!x) return;
x.done = Math.min(x.n, x.done + x.n * 100 / x.ms);
if (x.fail && !x.ocr && x.done >= x.fail.at){ x.st = 'failed'; paint(x); counts(); return next(); }
prog(x);
if (x.done >= x.n){ x.st = 'ready'; x.ago = 'just now'; x.had = true; paint(x); counts(); next(); }
});
function addSource(x){ x.st = 'queued'; S.push(x); list.appendChild(row(x)); enter(x.el); counts(); next(); }
function remove(x){
const i = S.indexOf(x); if (i < 0) return; S.splice(i, 1); counts(); next();
x.el.classList.add('leave'); c.later(REDUCE ? 0 : 340, () => x.el.remove());
}
S.forEach(x => list.appendChild(row(x))); stagger([...list.children], 50); counts(true); next();
// Re-sync and Remove act on the row whose button opened the menu; a source still waiting or indexing can't be re-synced yet
let cur = null;
c.on(list, 'click', e => { const b = e.target.closest('.ksx-more'); if (!b) return; cur = S.find(x => x.el.contains(b)); $('.ksx-rs', mpop).disabled = !cur || cur.st === 'queued' || cur.st === 'indexing'; if (!mpop.classList.contains('open')) side(b, mpop); });
$('.ksx-rs', mpop).onclick = () => { if (!cur || !S.includes(cur)) return; cur.st = 'queued'; cur.ms = cur.ocr ? 3000 : cur.fail ? 19000 : 2500; paint(cur); next(); };
$('.ksx-rm', mpop).onclick = () => cur && remove(cur);
// Add source: upload files (the file picker), add a website (its address), or connect a folder (from the ones offered)
function view(v){
pop.classList.toggle('mx-sw', pop.classList.contains('open'));
if (v === 'web') pop.innerHTML = `<form class="ksx-web"><div class="ph">Add a website</div><div class="ksx-in">${I('globe','xs')}<input placeholder="example.com/docs" aria-label="Website address" spellcheck="false" autocomplete="off"><button class="pill accent sm" type="submit">Add</button></div></form>`;
else if (v === 'folder') pop.innerHTML = '<div class="ph">Connect a folder</div>' + (FOLDERS.length ? FOLDERS.map((f, i) => `<button class="mi mx-press" role="menuitem" data-close data-i="${i}">${I('folder','xs')}<span>${f[0]}<span class="d">${f[1]}</span></span></button>`).join('') : '<div class="ph">All folders connected</div>');
else pop.innerHTML = [['upload', 'Upload files', 'files'], ['globe', 'Add a website', 'web'], ['folder', 'Connect a folder', 'folder']].map(([ic, t, k]) => `<button class="mi mx-press" role="menuitem" data-v="${k}"${k === 'files' ? ' data-close' : ''}>${I(ic,'xs')}<span>${t}</span></button>`).join('');
}
view('main');
// a menu opens over the card from its button: down when it fits below, up when it doesn't and fits above or has more room
// there (as placePop), within the stage's room, so it never spills over the card's caption under the stage (as Artifact
// card's version menu). The side is set on the button just before the menu is placed
const side = (btn, pop) => { const room = popRoom(btn), st = btn.closest('.stage-inner') || btn.closest('.stage');
if (st){ const sr = st.getBoundingClientRect(), cs = getComputedStyle(st); room.top = Math.max(room.top, sr.top + parseFloat(cs.paddingTop)); room.bottom = Math.min(room.bottom, sr.bottom - parseFloat(cs.paddingBottom)); }
const br = btn.getBoundingClientRect(), need = pop.offsetHeight + 12, below = room.bottom - br.bottom, above = br.top - room.top;
btn.dataset.popPos = below < need && (above >= need || above > below) ? 'up' : 'down'; };
adds.forEach(b => c.on(b, 'click', () => { from = b; if (!pop.classList.contains('open')){ view('main'); side(b, pop); } }));
// a step inside the menu swaps its content after the click has been handled, so the click still counts as inside it. The
// menu keeps the side it opened on: one that opened upwards grows upwards, held by its bottom edge
const replace = () => { if (!(pop.style.getPropertyValue('--dm-origin') || '').startsWith('bottom')) side(from, pop); placePop(from, pop); };
c.on(pop, 'click', e => {
const m = e.target.closest('.mi'); if (!m) return;
if (m.dataset.v === 'files') return file.click();
if (m.dataset.v){ const v = m.dataset.v, mine = e.isTrusted; c.later(0, () => { view(v); replace(); if (mine && v === 'web') $('input', pop).focus({ preventScroll:true }); }); return; }
if (m.dataset.i){ const f = FOLDERS.splice(+m.dataset.i, 1)[0]; addSource({ kind:'folder', name:f[0], n:f[2], unit:'pages', chunks:f[3], ms:3000 }); }
});
c.on(pop, 'submit', e => {
e.preventDefault(); const inp = $('input', pop), v = inp.value.trim().replace(/^https?:\/\//, '').replace(/\/$/, '');
if (!v) return inp.focus();
closePops(); addSource({ kind:'web', name:v, n:142, unit:'pages', chunks:196, ms:4500 });
});
file.onchange = () => { const fs = [...file.files]; if (!fs.length) return;
addSource({ kind:'files', name:fs.length === 1 ? fs[0].name : fs.length + ' files', n:fs.length, unit:'files', chunks:fs.length * 12, ms:1500 }); file.value = ''; };
// the card grows with its rows and shrinks as they go (owner, 17 Nov: no room kept for a later state)
c.offs.push(grow(root));
// the preview's story: add the docs site, which waits its turn; the PDF turns out to be a scan, so read it with OCR, and
// everything ends up indexed
c.story(async s => {
const pdf = S[2];
await s.beat(3);
await s.tap(add); await s.beat(2);
await s.tap($('.mi[data-v="web"]', pop)); await s.beat(1);
const inp = $('input', pop);
await s.type(inp, 'designme.dev/docs', { n:.1, keep:true });
await s.beat(1);
await s.tap($('button[type="submit"]', pop)); s.away();
await s.until(() => pdf.st === 'failed'); await s.beat(2);
await s.tap($('.ksx-fix', pdf.el)); s.away();
await s.until(() => S.every(x => x.st === 'ready')); await s.beat(1);
});
});
Questions
What people ask about it.
- Does the component index anything?
- No. It shows what you tell it. Run the indexing in your own code and update each source's
stateanddoneas it goes; the bar and count follow. - How do I show the website being added?
- Handle
onAddWebsite: add a source withkind: 'web'andstate: 'queued', then move it toindexingandreadyas your crawler works. PassaddressandonAddressChangeif you want to fill in the field yourself. - Why doesn't the chunk count include a source that is still indexing?
- The total adds up
chunks, so leave a source'schunksout until it has been indexed. Keep it while a source re-syncs if its old index still answers questions. - Can a failed source offer something other than OCR?
- Yes.
fixis any label, like "Sign in again" or "Try a smaller file", andonFixgets the source's key.
More in Workspace
Navigation, search, settings, models and automations around the agent.