your-attention 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/bin/your-attention.js +6 -2
- package/dist/src/adapters/files.js +66 -0
- package/dist/src/adapters/mdns.js +53 -0
- package/dist/src/adapters/mermaid.js +50 -0
- package/dist/src/adapters/openui-body.js +40 -0
- package/dist/src/adapters/openui-library.js +3 -0
- package/dist/src/adapters/sqlite.js +68 -0
- package/dist/src/cli.js +814 -0
- package/dist/src/client.js +459 -0
- package/dist/src/cloudflare/collector.js +53 -0
- package/dist/src/cloudflare/inbox-object.js +338 -0
- package/dist/src/cloudflare/storage.js +151 -0
- package/dist/src/cloudflare/worker.js +189 -0
- package/dist/src/core/crypto.js +23 -0
- package/dist/src/core/diagrams.js +225 -0
- package/dist/src/core/expr.js +125 -0
- package/dist/src/core/file-links.js +48 -0
- package/dist/src/core/hooks.js +74 -0
- package/dist/src/core/http.js +651 -0
- package/dist/src/core/inbox.js +2463 -0
- package/dist/src/core/pin.js +234 -0
- package/dist/src/core/sealed.js +167 -0
- package/dist/src/core/session-link.js +13 -0
- package/dist/src/core/socket.js +88 -0
- package/dist/src/core/storage.js +102 -0
- package/dist/src/core/summary.js +149 -0
- package/dist/src/core/telemetry.js +221 -0
- package/dist/src/core/types.js +470 -0
- package/dist/src/core/version.js +2 -0
- package/dist/src/core/widgets.js +128 -0
- package/dist/src/extensions/triage.js +232 -0
- package/dist/src/integrations/claude/ask-hook.js +84 -0
- package/dist/src/integrations/claude/channel-flag.js +102 -0
- package/dist/src/integrations/claude/channel.js +276 -0
- package/dist/src/integrations/claude/session-name.js +32 -0
- package/dist/src/integrations/claude/turn-end-hook.js +84 -0
- package/dist/src/integrations/herdr/approve.js +71 -0
- package/dist/src/integrations/herdr/blocked.js +210 -0
- package/dist/src/integrations/herdr/dialog.js +64 -0
- package/dist/src/integrations/herdr/focus.js +31 -0
- package/dist/src/integrations/herdr/place.js +22 -0
- package/dist/src/integrations/images.js +43 -0
- package/dist/src/integrations/opencode/install.js +24 -0
- package/dist/src/integrations/opencode/plugin.js +157 -0
- package/dist/src/integrations/pi/extension.js +166 -0
- package/dist/src/integrations/run-tool.js +157 -0
- package/dist/src/integrations/secrets.js +63 -0
- package/dist/src/integrations/tags.js +27 -0
- package/dist/src/integrations/tools.js +147 -0
- package/dist/src/node/home.js +20 -0
- package/dist/src/node/install.js +225 -0
- package/dist/src/node/links.js +249 -0
- package/dist/src/node/pin-prompt.js +125 -0
- package/dist/src/node/server.js +320 -0
- package/dist/src/node/service.js +74 -0
- package/dist/src/node/telemetry.js +127 -0
- package/dist/src/owner-watch.js +49 -0
- package/dist/src/tui/api.js +203 -0
- package/dist/src/tui/app.js +586 -0
- package/dist/src/tui/body.js +727 -0
- package/dist/src/tui/cardview.js +453 -0
- package/dist/src/tui/doc.js +157 -0
- package/dist/src/tui/edit.js +119 -0
- package/dist/src/tui/input.js +192 -0
- package/dist/src/tui/md.js +196 -0
- package/dist/src/tui/screen.js +225 -0
- package/dist/src/tui/terminal.js +130 -0
- package/dist/src/tui/text.js +103 -0
- package/dist/src/tui/theme.js +105 -0
- package/dist/src/tui/view.js +314 -0
- package/dist/src/watch.js +104 -0
- package/dist/web/age.js +16 -0
- package/dist/web/answers.js +485 -0
- package/dist/web/app.js +739 -0
- package/dist/web/body-faults.js +69 -0
- package/dist/web/components.js +923 -0
- package/dist/web/copy.js +118 -0
- package/dist/web/details.js +59 -0
- package/dist/web/env.js +97 -0
- package/dist/web/favicon-waiting.svg +1 -0
- package/dist/web/favicon.svg +1 -0
- package/dist/web/index.html +16 -0
- package/dist/web/library-spec.js +33 -0
- package/dist/web/markdown.js +142 -0
- package/dist/web/paste-images.js +193 -0
- package/dist/web/pin-key.js +125 -0
- package/dist/web/pin.js +126 -0
- package/dist/web/queue.js +97 -0
- package/dist/web/sealed.js +13 -0
- package/dist/web/search.js +70 -0
- package/dist/web/stories/cards.stories.js +144 -0
- package/dist/web/stories/page.stories.js +54 -0
- package/dist/web/stories/render.js +16 -0
- package/dist/web/style.css +417 -0
- package/package.json +4 -2
- package/src/core/version.ts +1 -1
package/dist/web/copy.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Code on the page copies with a click. A block copies through its Copy button, and inline code copies when clicked,
|
|
2
|
+
// except inside a link, where the click follows the link. One listener on the document handles both, so code that
|
|
3
|
+
// OpenUI draws copies the same as code the page draws. web/markdown.js draws the page's Copy buttons.
|
|
4
|
+
const FEEDBACK_MS = 1500;
|
|
5
|
+
const BLOCK = '.code-block, .openui-code-block-wrapper';
|
|
6
|
+
const BUTTON = '.copy-button, .openui-code-block-copy-button';
|
|
7
|
+
|
|
8
|
+
/** Copy through a hidden text area. A page that is not secure, such as one on a LAN address, has no navigator.clipboard. */
|
|
9
|
+
function copyByCommand(text) {
|
|
10
|
+
const before = document.activeElement;
|
|
11
|
+
const area = document.createElement('textarea');
|
|
12
|
+
area.value = text;
|
|
13
|
+
area.readOnly = true;
|
|
14
|
+
area.setAttribute('aria-hidden', 'true');
|
|
15
|
+
area.style.cssText = 'position:fixed;top:0;left:0;width:1px;height:1px;opacity:0;pointer-events:none';
|
|
16
|
+
document.body.append(area);
|
|
17
|
+
area.select();
|
|
18
|
+
let ok = false;
|
|
19
|
+
try { ok = document.execCommand('copy'); } catch {}
|
|
20
|
+
area.remove();
|
|
21
|
+
if (before instanceof HTMLElement) before.focus({ preventScroll: true });
|
|
22
|
+
return ok;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Put `text` on the clipboard, exactly as given. True when it copied. */
|
|
26
|
+
export async function copyText(text) {
|
|
27
|
+
try {
|
|
28
|
+
if (navigator.clipboard && navigator.clipboard.writeText) { await navigator.clipboard.writeText(text); return true; }
|
|
29
|
+
} catch {}
|
|
30
|
+
return copyByCommand(text);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const timers = new WeakMap();
|
|
34
|
+
let toast = null;
|
|
35
|
+
/** The word over inline code, at the code. It floats on the page, since the code may clip what overflows it. */
|
|
36
|
+
function showToast(el, word) {
|
|
37
|
+
const r = el.getBoundingClientRect();
|
|
38
|
+
toast.textContent = word;
|
|
39
|
+
toast.dataset.tone = word === 'Copied' ? 'ok' : 'bad';
|
|
40
|
+
toast.style.left = `${r.left + r.width / 2}px`;
|
|
41
|
+
toast.style.top = `${r.top}px`;
|
|
42
|
+
toast.dataset.show = '';
|
|
43
|
+
toast.owner = el;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Show "Copied", or "Copy failed", on the element for a moment. A button says it in its accessible name too. */
|
|
47
|
+
function feedback(el, ok) {
|
|
48
|
+
const word = ok ? 'Copied' : 'Copy failed';
|
|
49
|
+
const button = el.matches(BUTTON);
|
|
50
|
+
clearTimeout(timers.get(el));
|
|
51
|
+
el.dataset.copied = word;
|
|
52
|
+
if (button) el.setAttribute('aria-label', word);
|
|
53
|
+
else showToast(el, word);
|
|
54
|
+
timers.set(el, setTimeout(() => {
|
|
55
|
+
delete el.dataset.copied;
|
|
56
|
+
if (button) el.setAttribute('aria-label', 'Copy');
|
|
57
|
+
else if (toast && toast.owner === el) { delete toast.dataset.show; toast.textContent = ''; }
|
|
58
|
+
}, FEEDBACK_MS));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The text of the block a Copy button belongs to. OpenUI draws the code in its own element, with no code tag around it. */
|
|
62
|
+
function blockText(button) {
|
|
63
|
+
const block = button.closest(BLOCK);
|
|
64
|
+
const code = block && (block.querySelector('pre code') || block.querySelector('.openui-code-block-syntax-highlighter'));
|
|
65
|
+
return code ? code.textContent : '';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Inline code that copies on a click: not in a block, and not in a link. */
|
|
69
|
+
function inlineCode(target) {
|
|
70
|
+
const code = target instanceof Element ? target.closest('code') : null;
|
|
71
|
+
return code && !code.closest(`pre, a, ${BLOCK}`) ? code : null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let installed = false;
|
|
75
|
+
/** Listen on the document for clicks on code. Calling it again does nothing. */
|
|
76
|
+
export function installCopy() {
|
|
77
|
+
if (installed) return;
|
|
78
|
+
installed = true;
|
|
79
|
+
// A live region on the page from the start, empty and clear until a copy, so a screen reader reads each word put in it.
|
|
80
|
+
// It has no status role, which the page gives only to the message it shows, such as the PIN check.
|
|
81
|
+
toast = document.createElement('div');
|
|
82
|
+
toast.className = 'copy-toast';
|
|
83
|
+
toast.setAttribute('aria-live', 'polite');
|
|
84
|
+
document.body.append(toast);
|
|
85
|
+
// OpenUI's own button copies only on a secure page and says "Copy code". The capture phase takes its click first.
|
|
86
|
+
document.addEventListener('click', (e) => {
|
|
87
|
+
const button = e.target instanceof Element ? e.target.closest(BUTTON) : null;
|
|
88
|
+
if (button) {
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
e.stopPropagation();
|
|
91
|
+
void copyText(blockText(button)).then((ok) => feedback(button, ok));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const code = inlineCode(e.target);
|
|
95
|
+
if (!code) return;
|
|
96
|
+
// A person who selected part of the code wants that part, so the click leaves the selection alone.
|
|
97
|
+
const sel = window.getSelection();
|
|
98
|
+
if (sel && !sel.isCollapsed && code.contains(sel.anchorNode)) return;
|
|
99
|
+
void copyText(code.textContent).then((ok) => feedback(code, ok));
|
|
100
|
+
}, true);
|
|
101
|
+
// The hint goes on when the pointer arrives, so code that OpenUI draws gets it too.
|
|
102
|
+
document.addEventListener('pointerover', (e) => {
|
|
103
|
+
const code = inlineCode(e.target);
|
|
104
|
+
if (code && !code.title) code.title = 'Click to copy';
|
|
105
|
+
});
|
|
106
|
+
// OpenUI's button is named "Copy code". It gets the page's name as it appears, and keeps it, since OpenUI never
|
|
107
|
+
// draws the button again once the page takes its clicks.
|
|
108
|
+
const rename = (root) => {
|
|
109
|
+
for (const b of root.matches?.('.openui-code-block-copy-button') ? [root] : root.querySelectorAll?.('.openui-code-block-copy-button') ?? []) {
|
|
110
|
+
if (b.dataset.copied) continue;
|
|
111
|
+
b.setAttribute('aria-label', 'Copy');
|
|
112
|
+
b.title = 'Copy';
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
rename(document.body);
|
|
116
|
+
new MutationObserver((records) => { for (const r of records) for (const n of r.addedNodes) if (n.nodeType === 1) rename(n); })
|
|
117
|
+
.observe(document.body, { childList: true, subtree: true });
|
|
118
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// The whole cards a client shows. GET /v1/state sends a summary of each card, and the page and the terminal client fetch
|
|
2
|
+
// the whole card from GET /v1/cards/<id> when it opens, with the card after it, so moving on stays instant. A copy is
|
|
3
|
+
// current while its rev matches the summary's. A copy that is out of date stays on screen until the new one arrives.
|
|
4
|
+
// The page and the terminal client share this file, so both fetch the same way.
|
|
5
|
+
|
|
6
|
+
/** `load(id)` resolves to `{card, answer, state, rev}`. `changed()` runs when a fetch ends. */
|
|
7
|
+
export function cardDetails(load, changed) {
|
|
8
|
+
const copies = new Map();
|
|
9
|
+
const loading = new Map();
|
|
10
|
+
return {
|
|
11
|
+
/** The copy of a card, current or not, or undefined before the first fetch ends. */
|
|
12
|
+
get(summary) {
|
|
13
|
+
const copy = summary ? copies.get(summary.id) : undefined;
|
|
14
|
+
return copy ? copy.detail : undefined;
|
|
15
|
+
},
|
|
16
|
+
/** Fetch each card whose copy is missing or older than its summary. */
|
|
17
|
+
want(summaries) {
|
|
18
|
+
for (const s of summaries) {
|
|
19
|
+
if (!s) continue;
|
|
20
|
+
const copy = copies.get(s.id);
|
|
21
|
+
if ((copy && copy.rev === s.rev) || loading.get(s.id) === s.rev) continue;
|
|
22
|
+
loading.set(s.id, s.rev);
|
|
23
|
+
Promise.resolve().then(() => load(s.id)).then(
|
|
24
|
+
(detail) => { copies.set(s.id, { rev: detail.rev ?? s.rev, detail }); },
|
|
25
|
+
// A card that is gone keeps no copy, and the next summary of it fetches again.
|
|
26
|
+
() => { if (!copies.has(s.id)) copies.set(s.id, { rev: s.rev, detail: undefined }); },
|
|
27
|
+
).finally(() => { if (loading.get(s.id) === s.rev) loading.delete(s.id); changed(); });
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
/** Forget the cards the state no longer shows. */
|
|
31
|
+
keep(ids) {
|
|
32
|
+
for (const id of copies.keys()) if (!ids.has(id)) copies.delete(id);
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The ids a text links to with [[card-id]], as the inbox reads them for a summary's `links`. */
|
|
38
|
+
export const linkIds = (...texts) => [...new Set(texts.filter(Boolean).flatMap((t) => [...String(t).matchAll(/\[\[([\w.:-]{1,80})\]\]/g)].map((m) => m[1])))];
|
|
39
|
+
|
|
40
|
+
/** Cards a text links to that the state leaves out, such as a card the person cleared. `want(ids)` asks the inbox for every
|
|
41
|
+
* id it has not asked about yet in one request, GET /v1/cards?ids=. `get(id)` is the card's `{title, preview, archivedAt}`,
|
|
42
|
+
* null when the inbox does not store it, or undefined before the answer arrives. */
|
|
43
|
+
export function linkLookup(load, changed) {
|
|
44
|
+
const found = new Map();
|
|
45
|
+
return {
|
|
46
|
+
get: (id) => found.get(id),
|
|
47
|
+
want(ids) {
|
|
48
|
+
const ask = ids.filter((id) => !found.has(id)).slice(0, 20);
|
|
49
|
+
if (!ask.length) return;
|
|
50
|
+
// Asked once: an id stays pending until the answer, so the next draw asks for nothing again.
|
|
51
|
+
for (const id of ask) found.set(id, undefined);
|
|
52
|
+
Promise.resolve().then(() => load(ask)).then(
|
|
53
|
+
(cards) => { for (const id of ask) found.set(id, Object.hasOwn(cards, id) ? cards[id] : null); },
|
|
54
|
+
// A failed request is not asked again until the page reloads, so a broken lookup cannot loop; the links show their ids.
|
|
55
|
+
() => { for (const id of ask) found.set(id, null); },
|
|
56
|
+
).finally(changed);
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
package/dist/web/env.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Shared by the page and its stories: addresses, storage, presence reports, labels and icons.
|
|
2
|
+
const { React } = window.__OpenUI;
|
|
3
|
+
export const h = React.createElement;
|
|
4
|
+
// The page may sit under a path, such as /i/<inbox id>/ on the hosted service, so every address is relative to it.
|
|
5
|
+
export const BASE = location.pathname.replace(/[^/]*$/, '');
|
|
6
|
+
export { CLOSED_LABEL, STATE_LABEL } from './queue.js';
|
|
7
|
+
export const J = JSON.stringify;
|
|
8
|
+
|
|
9
|
+
// This tab's unlock token, from POST /v1/unlock. It lives in session storage, so closing the tab locks the inbox again.
|
|
10
|
+
// The hosted service serves every inbox on one origin, so the key carries the inbox's own address.
|
|
11
|
+
const UNLOCK_KEY = `ya-unlock:${BASE}`;
|
|
12
|
+
export const unlockToken = {
|
|
13
|
+
get() { try { return sessionStorage.getItem(UNLOCK_KEY); } catch { return null; } },
|
|
14
|
+
set(v) { try { sessionStorage.setItem(UNLOCK_KEY, v); } catch {} },
|
|
15
|
+
del() { try { sessionStorage.removeItem(UNLOCK_KEY); } catch {} },
|
|
16
|
+
};
|
|
17
|
+
// Every call this page makes to its inbox carries the unlock token in a header.
|
|
18
|
+
const plainFetch = window.fetch.bind(window);
|
|
19
|
+
window.fetch = (input, init) => {
|
|
20
|
+
const token = unlockToken.get();
|
|
21
|
+
const url = new URL(typeof input === 'string' ? input : input instanceof URL ? input.href : input.url, location.href);
|
|
22
|
+
if (!token || url.origin !== location.origin || !url.pathname.startsWith(`${BASE}v1/`)) return plainFetch(input, init);
|
|
23
|
+
const headers = new Headers((init && init.headers) || (input instanceof Request ? input.headers : undefined));
|
|
24
|
+
headers.set('x-your-attention-unlock', token);
|
|
25
|
+
return plainFetch(input, { ...init, headers });
|
|
26
|
+
};
|
|
27
|
+
/** The address of the page socket or event stream, which carry the unlock token in the address: they cannot send headers. */
|
|
28
|
+
export const withUnlock = (address) => {
|
|
29
|
+
const token = unlockToken.get();
|
|
30
|
+
return token ? `${address}&unlock=${encodeURIComponent(token)}` : address;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const store = {
|
|
34
|
+
get(k) { try { return JSON.parse(localStorage.getItem(k)); } catch { return null; } },
|
|
35
|
+
set(k, v) { try { localStorage.setItem(k, JSON.stringify(v)); } catch {} },
|
|
36
|
+
del(k) { try { localStorage.removeItem(k); } catch {} },
|
|
37
|
+
};
|
|
38
|
+
export const api = (path, body, method = 'POST') => fetch(path, body === undefined ? {} : { method, headers: { 'content-type': 'application/json', 'x-your-attention': '1' }, body: J(body) });
|
|
39
|
+
export const time = (t) => new Date(t).toLocaleTimeString();
|
|
40
|
+
|
|
41
|
+
// This tab's id for presence reports. Two tabs, or two people, count as two pages.
|
|
42
|
+
export const VIEWER = (() => {
|
|
43
|
+
try {
|
|
44
|
+
const id = sessionStorage.getItem('viewer') || `v-${crypto.getRandomValues(new Uint32Array(2)).join('')}`;
|
|
45
|
+
sessionStorage.setItem('viewer', id);
|
|
46
|
+
return id;
|
|
47
|
+
} catch { return `v-${Math.random().toString(36).slice(2)}`; }
|
|
48
|
+
})();
|
|
49
|
+
let lastReport = 0;
|
|
50
|
+
export function report(fields) {
|
|
51
|
+
const now = Date.now();
|
|
52
|
+
if (!('visible' in fields) && !('focus' in fields) && now - lastReport < 20000) return;
|
|
53
|
+
lastReport = now;
|
|
54
|
+
fetch(`${BASE}v1/person/${VIEWER}`, { method: 'POST', headers: { 'content-type': 'application/json', 'x-your-attention': '1' }, body: J(fields) }).catch(() => {});
|
|
55
|
+
}
|
|
56
|
+
document.addEventListener('visibilitychange', () => report({ visible: document.visibilityState === 'visible', active: true }));
|
|
57
|
+
for (const ev of ['keydown', 'pointerdown', 'scroll']) window.addEventListener(ev, () => report({ active: true }), { passive: true });
|
|
58
|
+
|
|
59
|
+
// Browser notifications, only after you turn them on.
|
|
60
|
+
export const notifyOn = () => store.get('notify:on') === true && 'Notification' in window && Notification.permission === 'granted';
|
|
61
|
+
export function notify(title, body) {
|
|
62
|
+
if (!notifyOn()) return;
|
|
63
|
+
try { new Notification(title, { body, tag: `card:${body}` }); } catch {}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const ICONS = {
|
|
67
|
+
// Lucide's key: a secret field shows it at its left.
|
|
68
|
+
key: ['m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4', 'm21 2-9.6 9.6', 'M13 15.5a5.5 5.5 0 1 1-11 0a5.5 5.5 0 1 1 11 0'],
|
|
69
|
+
// Lucide's brush-cleaning.
|
|
70
|
+
broom: ['m16 22-1-4', 'M19 13.99a1 1 0 0 0 1-1V12a2 2 0 0 0-2-2h-3a1 1 0 0 1-1-1V4a2 2 0 0 0-4 0v5a1 1 0 0 1-1 1H6a2 2 0 0 0-2 2v.99a1 1 0 0 0 1 1', 'M5 14h14l1.973 6.767A1 1 0 0 1 20 22H4a1 1 0 0 1-.973-1.233z', 'm8 22 1-4'],
|
|
71
|
+
// Lucide's hand: a card that waits for you raises its hand.
|
|
72
|
+
open: ['M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2', 'M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2', 'M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8', 'M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15'],
|
|
73
|
+
// The raised hand, filled, for the card on screen. Lines in the row's color mark the fingers.
|
|
74
|
+
'open-filled': [{ d: 'M6 14V6a2 2 0 0 1 4 0V4a2 2 0 0 1 4 0v2a2 2 0 0 1 4 0v2a2 2 0 0 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15Z', cls: 'fill' },
|
|
75
|
+
{ d: 'M10 6.5V10.5', cls: 'gap' }, { d: 'M14 6V10', cls: 'gap' }, { d: 'M18 8V11', cls: 'gap' }],
|
|
76
|
+
circle: ['M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18'],
|
|
77
|
+
// Lucide's pin: a tag value pinned to the top of the queue.
|
|
78
|
+
pin: ['M12 17v5', 'M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z'],
|
|
79
|
+
answered: ['M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z', 'M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7', 'M7 3v4a1 1 0 0 0 1 1h7'],
|
|
80
|
+
delivered: ['M14.5 21.7a.5.5 0 0 0 .9 0l6.5-19a.5.5 0 0 0-.6-.6l-19 6.5a.5.5 0 0 0 0 .9l7.9 3.2a2 2 0 0 1 1.1 1.1z', 'm21.9 2.1-10.9 10.9'],
|
|
81
|
+
read: ['M18 6 7 17l-5-5', 'm22 10-7.5 7.5L13 16'],
|
|
82
|
+
// Lucide's eye-off: the person dismissed the card, and the agent was not told.
|
|
83
|
+
dismissed: ['M9.88 9.88a3 3 0 1 0 4.24 4.24', 'M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68', 'M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61', 'm2 2 20 20'],
|
|
84
|
+
retracted: ['M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18', 'm15 9-6 6', 'm9 9 6 6'],
|
|
85
|
+
'self-answered': ['M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18', 'm9 12 2 2 4-4'],
|
|
86
|
+
'answered-in-terminal': ['M4 17l6-6-6-6', 'M12 19h8'],
|
|
87
|
+
resolved: ['M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18', 'm9 12 2 2 4-4'],
|
|
88
|
+
// Lucide's file icons, for a file chip by the file's type, and its copy icon.
|
|
89
|
+
file: ['M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z', 'M14 2v4a2 2 0 0 0 2 2h4'],
|
|
90
|
+
'file-code': ['M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z', 'M14 2v4a2 2 0 0 0 2 2h4', 'm10 13-2 2 2 2', 'm14 17 2-2-2-2'],
|
|
91
|
+
'file-image': ['M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z', 'M14 2v4a2 2 0 0 0 2 2h4', 'M10 11a2 2 0 1 0 0 4a2 2 0 1 0 0-4', 'm20 17-1.3-1.3a2.4 2.4 0 0 0-3.4 0L9 22'],
|
|
92
|
+
'file-text': ['M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z', 'M14 2v4a2 2 0 0 0 2 2h4', 'M10 9H8', 'M16 13H8', 'M16 17H8'],
|
|
93
|
+
copy: ['M10 8h10a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H10a2 2 0 0 1-2-2V10a2 2 0 0 1 2-2z', 'M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2'],
|
|
94
|
+
};
|
|
95
|
+
export const Icon = ({ name, tip, cls = '', dim = false, color }) => h('span', { className: `ico ${cls} ${dim ? 'dim' : ''}`, style: color ? { color } : undefined, 'data-tip': tip, role: 'img', 'aria-label': tip, tabIndex: 0 },
|
|
96
|
+
h('svg', { viewBox: '0 0 24 24', 'aria-hidden': 'true' }, (ICONS[name] || ICONS.circle).map((p) => (typeof p === 'string' ? h('path', { key: p, d: p }) : h('path', { key: p.d, d: p.d, className: p.cls })))));
|
|
97
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><text x="32" y="54" font-size="54" text-anchor="middle">✋</text><circle cx="52" cy="13" r="10" fill="#e5484d" stroke="#fff" stroke-width="3"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><text x="32" y="54" font-size="54" text-anchor="middle">✋</text></svg>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>Your Attention</title>
|
|
7
|
+
<link rel="icon" type="image/svg+xml" href="favicon.svg">
|
|
8
|
+
<link rel="stylesheet" href="vendor/openui-styles.css">
|
|
9
|
+
<link rel="stylesheet" href="style.css">
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<div id="app"></div>
|
|
13
|
+
<script src="vendor/openui-bundle.min.js"></script>
|
|
14
|
+
<script type="module" src="app.js"></script>
|
|
15
|
+
</body>
|
|
16
|
+
</html>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// The components the page adds to OpenUI's chat library, and the ones it changes.
|
|
2
|
+
// scripts/openui-library.ts writes the same list for the inbox, so the inbox refuses a body the page cannot draw.
|
|
3
|
+
// This module reads no browser globals, so Node can load it.
|
|
4
|
+
|
|
5
|
+
/** `base` extended with the page's components. `draw` holds how the page draws each one; without it, they draw nothing. */
|
|
6
|
+
export function extendLibrary(base, draw = {}) {
|
|
7
|
+
const { FormControl, AccordionItem, CodeBlock, Input, OptionCards, IconButton, Table } = base.components;
|
|
8
|
+
const nothing = () => null;
|
|
9
|
+
const mermaidProps = FormControl.props.pick({}).extend({ source: CodeBlock.props.shape.codeString });
|
|
10
|
+
const secretInputProps = Input.props.pick({ name: true }).extend({ publicKey: Input.props.shape.name });
|
|
11
|
+
const checkWithTextProps = FormControl.props.pick({ label: true }).extend({ check: FormControl.props.shape.input, content: AccordionItem.props.shape.content });
|
|
12
|
+
return base.extend({ components: {
|
|
13
|
+
add: [{
|
|
14
|
+
component: { name: 'CheckWithText', props: checkWithTextProps, ref: checkWithTextProps, description: 'A check box with a label that shows editable content when clicked.', component: draw.CheckWithText ?? nothing },
|
|
15
|
+
slots: ['Card.children', 'FormControl.input'],
|
|
16
|
+
}, {
|
|
17
|
+
component: { name: 'Mermaid', props: mermaidProps, ref: mermaidProps, description: 'A diagram drawn from Mermaid source.', component: draw.Mermaid ?? nothing },
|
|
18
|
+
// Wherever a CodeBlock can go.
|
|
19
|
+
slots: ['Card.children', 'SectionItem.content', 'TabItem.content', 'AccordionItem.content', 'Carousel.children'],
|
|
20
|
+
}, {
|
|
21
|
+
component: { name: 'SecretInput', props: secretInputProps, ref: secretInputProps, description: 'A secret field: the page seals the value with the public key, a JSON Web Key as text.', component: draw.SecretInput ?? nothing },
|
|
22
|
+
slots: ['FormControl.input'],
|
|
23
|
+
}],
|
|
24
|
+
override: [
|
|
25
|
+
{ ...FormControl, component: draw.FormControl ?? FormControl.component },
|
|
26
|
+
{ ...OptionCards, component: draw.OptionCards ?? OptionCards.component },
|
|
27
|
+
// The page shows an icon button's name as a tooltip too; the inbox needs only the same props.
|
|
28
|
+
{ ...IconButton, component: draw.IconButton ?? IconButton.component },
|
|
29
|
+
// The page draws each text cell as inline Markdown; the inbox needs only the same props.
|
|
30
|
+
{ ...Table, component: draw.Table ?? Table.component },
|
|
31
|
+
],
|
|
32
|
+
} });
|
|
33
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// A small Markdown renderer that builds React elements and never sets HTML.
|
|
2
|
+
// It covers headings, paragraphs, lists, block quotes, fenced code, tables,
|
|
3
|
+
// inline code, bold, italic, links to http, https and mailto addresses, and bare
|
|
4
|
+
// http and https addresses. With a cardLink option, [[card-id]] becomes what it returns.
|
|
5
|
+
// A file: address on this machine becomes what the fileLink option returns, or code with its path. src/core/file-links.ts
|
|
6
|
+
// finds the same addresses, since the inbox serves a file only when its card names it.
|
|
7
|
+
// A herdr link, https://herdr.invalid/v1/..., is a session link: the page opens it in herdr.
|
|
8
|
+
// With a diagram option, a ```mermaid block becomes what it returns. src/core/diagrams.ts finds the same blocks to check them.
|
|
9
|
+
// A fenced block gets a Copy button, which web/copy.js handles.
|
|
10
|
+
export const MERMAID_FENCE = /^```\s*mermaid(\s|$)/i;
|
|
11
|
+
export const SESSION_LINK = /^https:\/\/herdr\.invalid\/v1\//;
|
|
12
|
+
const URL_TAIL = /[.,;:!?'"*_]+$/;
|
|
13
|
+
const WORD_CHAR = /[\p{L}\p{N}]/u;
|
|
14
|
+
|
|
15
|
+
/** The decoded path of a file: address on this machine, or undefined for another host or an address that is not one. */
|
|
16
|
+
function filePath(url) {
|
|
17
|
+
if (!/^file:\/\//.test(url)) return undefined;
|
|
18
|
+
try {
|
|
19
|
+
const u = new URL(url);
|
|
20
|
+
return u.host ? undefined : decodeURIComponent(u.pathname);
|
|
21
|
+
} catch {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* As in CommonMark, an underscore next to a letter or digit on its outer side never opens or closes emphasis,
|
|
27
|
+
* so MY_SERVICE_API_KEY stays one word, and the text inside must not start or end with a space. Stars have no
|
|
28
|
+
* such rule, so un*frigging*believable keeps its emphasis. A check in code, since some phone browsers lack regex lookbehind.
|
|
29
|
+
*/
|
|
30
|
+
function underscoreEmphasis(text, at, match) {
|
|
31
|
+
const before = text[at - 1] || '';
|
|
32
|
+
const after = text[at + match.length] || '';
|
|
33
|
+
return !WORD_CHAR.test(before) && !WORD_CHAR.test(after) && !/^\s|\s$/.test(match.slice(1, -1));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Lucide's copy and check icons. The stylesheet shows the check while the button says Copied.
|
|
37
|
+
const COPY_ICON = ['M10 8h10a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H10a2 2 0 0 1-2-2V10a2 2 0 0 1 2-2z', 'M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2'];
|
|
38
|
+
const CHECK_ICON = ['M20 6 9 17l-5-5'];
|
|
39
|
+
const icon = (h, cls, paths) => h('svg', { className: cls, viewBox: '0 0 24 24', 'aria-hidden': 'true' }, paths.map((d) => h('path', { key: d, d })));
|
|
40
|
+
|
|
41
|
+
/** A block of code with a Copy button at its top right. `preProps` go on the pre, such as a class. */
|
|
42
|
+
export function codeBlock(h, text, key, preProps = null) {
|
|
43
|
+
return h('div', { key, className: 'code-block' },
|
|
44
|
+
h('button', { type: 'button', className: 'copy-button', 'aria-label': 'Copy', title: 'Copy' }, icon(h, 'copy-icon', COPY_ICON), icon(h, 'check-icon', CHECK_ICON)),
|
|
45
|
+
h('pre', preProps, h('code', null, text)));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function inline(h, text, key, opts = {}) {
|
|
49
|
+
const out = [];
|
|
50
|
+
const re = /(`[^`]+`)|(\*\*[^*]+\*\*)|(\*[^*]+\*|_[^_]+_)|\[\[([\w.:-]+)\]\]|\[([^\]]+)\]\(([^)\s]+)\)|(https?:\/\/[^\s<>()[\]]+)|(file:\/\/[^\s<>()[\]`]+)/g;
|
|
51
|
+
let last = 0;
|
|
52
|
+
let m;
|
|
53
|
+
let n = 0;
|
|
54
|
+
while ((m = re.exec(text))) {
|
|
55
|
+
// An underscore pair that is not emphasis stays text, and the scan resumes one character later.
|
|
56
|
+
if (m[3] && m[3][0] === '_' && !underscoreEmphasis(text, m.index, m[3])) { re.lastIndex = m.index + 1; continue; }
|
|
57
|
+
if (m.index > last) out.push(text.slice(last, m.index));
|
|
58
|
+
const k = `${key}.${n++}`;
|
|
59
|
+
// A session link opens another agent's session in herdr, through the page, so it gets no new tab. A renderer can
|
|
60
|
+
// take a link over, such as the page opening its own card links in place.
|
|
61
|
+
const a = (href, label) => opts.link?.(href, label, k) ?? (SESSION_LINK.test(href)
|
|
62
|
+
? h('a', { key: k, href, className: 'session-link', title: 'Open this session in herdr' }, label)
|
|
63
|
+
: h('a', { key: k, href, target: '_blank', rel: 'noopener noreferrer' }, label));
|
|
64
|
+
const file = (path, label) => (opts.fileLink ? opts.fileLink(path, label, k) : h('code', { key: k }, path));
|
|
65
|
+
if (m[1]) out.push(h('code', { key: k }, m[1].slice(1, -1)));
|
|
66
|
+
else if (m[2]) out.push(h('strong', { key: k }, inline(h, m[2].slice(2, -2), k, opts)));
|
|
67
|
+
else if (m[3]) out.push(h('em', { key: k }, inline(h, m[3].slice(1, -1), k, opts)));
|
|
68
|
+
else if (m[4]) out.push(opts.cardLink ? opts.cardLink(m[4], k) : m[0]);
|
|
69
|
+
else if (m[5]) {
|
|
70
|
+
const path = filePath(m[6]);
|
|
71
|
+
out.push(path !== undefined ? file(path, m[5]) : /^(https?:|mailto:)/i.test(m[6]) ? a(m[6], m[5]) : m[5]);
|
|
72
|
+
} else if (m[8]) {
|
|
73
|
+
const url = m[8].replace(URL_TAIL, '');
|
|
74
|
+
const path = filePath(url);
|
|
75
|
+
out.push(path !== undefined ? file(path, path) : url);
|
|
76
|
+
re.lastIndex = m.index + url.length;
|
|
77
|
+
} else {
|
|
78
|
+
// A sentence's closing period is not part of the address before it.
|
|
79
|
+
const url = m[7].replace(URL_TAIL, '');
|
|
80
|
+
out.push(a(url, url));
|
|
81
|
+
re.lastIndex = m.index + url.length;
|
|
82
|
+
}
|
|
83
|
+
last = re.lastIndex;
|
|
84
|
+
}
|
|
85
|
+
if (last < text.length) out.push(text.slice(last));
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// With breaks, a line break inside a paragraph stays a line break, as in a chat message.
|
|
90
|
+
/** One line of inline Markdown, such as a field label: links, code, bold and italic, with no paragraph around it. */
|
|
91
|
+
export function renderInline(h, text, opts = {}) {
|
|
92
|
+
return inline(h, String(text ?? ''), 'i', opts);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function renderMarkdown(h, src, opts = {}) {
|
|
96
|
+
const ins = (text, k) => inline(h, text, k, opts);
|
|
97
|
+
const lines = String(src).replace(/\r\n/g, '\n').split('\n');
|
|
98
|
+
const blocks = [];
|
|
99
|
+
let i = 0;
|
|
100
|
+
const key = () => `b${blocks.length}`;
|
|
101
|
+
// A table starts with a row of cells and a row of dashes. It can follow a line of text with no blank line between.
|
|
102
|
+
const tableAt = (n) => /^\|.*\|\s*$/.test(lines[n] || '') && /^\|[\s:|-]+\|\s*$/.test(lines[n + 1] || '');
|
|
103
|
+
while (i < lines.length) {
|
|
104
|
+
const line = lines[i];
|
|
105
|
+
if (/^```/.test(line)) {
|
|
106
|
+
const code = [];
|
|
107
|
+
for (i++; i < lines.length && !/^```/.test(lines[i]); i++) code.push(lines[i]);
|
|
108
|
+
i++;
|
|
109
|
+
if (opts.diagram && MERMAID_FENCE.test(line)) blocks.push(opts.diagram(code.join('\n'), key()));
|
|
110
|
+
else blocks.push(codeBlock(h, code.join('\n'), key()));
|
|
111
|
+
} else if (/^#{1,6}\s/.test(line)) {
|
|
112
|
+
const level = /^#+/.exec(line)[0].length;
|
|
113
|
+
blocks.push(h(`h${Math.min(level + 2, 6)}`, { key: key() }, ins(line.replace(/^#+\s*/, ''), key())));
|
|
114
|
+
i++;
|
|
115
|
+
} else if (/^\s*([-*+]|\d+\.)\s/.test(line)) {
|
|
116
|
+
const ordered = /^\s*\d+\./.test(line);
|
|
117
|
+
const items = [];
|
|
118
|
+
for (; i < lines.length && /^\s*([-*+]|\d+\.)\s/.test(lines[i]); i++) items.push(lines[i].replace(/^\s*([-*+]|\d+\.)\s/, ''));
|
|
119
|
+
blocks.push(h(ordered ? 'ol' : 'ul', { key: key() }, items.map((t, j) => h('li', { key: j }, ins(t, `${key()}.${j}`)))));
|
|
120
|
+
} else if (/^>\s?/.test(line)) {
|
|
121
|
+
const quote = [];
|
|
122
|
+
for (; i < lines.length && /^>\s?/.test(lines[i]); i++) quote.push(lines[i].replace(/^>\s?/, ''));
|
|
123
|
+
blocks.push(h('blockquote', { key: key() }, ins(quote.join(' '), key())));
|
|
124
|
+
} else if (tableAt(i)) {
|
|
125
|
+
const cells = (l) => l.trim().replace(/^\||\|$/g, '').split('|').map((c) => c.trim());
|
|
126
|
+
const head = cells(line);
|
|
127
|
+
const rows = [];
|
|
128
|
+
for (i += 2; i < lines.length && /^\|.*\|\s*$/.test(lines[i]); i++) rows.push(cells(lines[i]));
|
|
129
|
+
blocks.push(h('table', { key: key() },
|
|
130
|
+
h('thead', null, h('tr', null, head.map((c, j) => h('th', { key: j }, ins(c, `${key()}h${j}`))))),
|
|
131
|
+
h('tbody', null, rows.map((r, j) => h('tr', { key: j }, r.map((c, k) => h('td', { key: k }, ins(c, `${key()}r${j}.${k}`))))))));
|
|
132
|
+
} else if (!line.trim()) {
|
|
133
|
+
i++;
|
|
134
|
+
} else {
|
|
135
|
+
const para = [];
|
|
136
|
+
for (; i < lines.length && lines[i].trim() && !/^(```|#{1,6}\s|>|\s*([-*+]|\d+\.)\s)/.test(lines[i]) && !tableAt(i); i++) para.push(lines[i]);
|
|
137
|
+
blocks.push(h('p', { key: key() }, ins(para.join(opts.breaks ? '\n' : ' '), key())));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return blocks;
|
|
141
|
+
}
|
|
142
|
+
|