@adroit-app/chat-ui 0.0.0 → 0.1.0
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/LICENSE +21 -0
- package/README.md +151 -2
- package/dist/attach.d.ts +18 -0
- package/dist/attach.js +52 -0
- package/dist/chat.d.ts +330 -0
- package/dist/chat.js +2090 -0
- package/dist/composer.d.ts +27 -0
- package/dist/composer.js +46 -0
- package/dist/follow.d.ts +12 -0
- package/dist/follow.js +91 -0
- package/dist/form.d.ts +12 -0
- package/dist/form.js +15 -0
- package/dist/icons.d.ts +56 -0
- package/dist/icons.js +128 -0
- package/dist/image-actions.d.ts +33 -0
- package/dist/image-actions.js +10 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +10 -0
- package/dist/keymap.d.ts +29 -0
- package/dist/keymap.js +69 -0
- package/dist/markdown/frontend.d.ts +6 -0
- package/dist/markdown/frontend.js +103 -0
- package/dist/markdown/picture.d.ts +22 -0
- package/dist/markdown/picture.js +57 -0
- package/dist/markdown/render.d.ts +71 -0
- package/dist/markdown/render.js +183 -0
- package/dist/markdown/view.d.ts +28 -0
- package/dist/markdown/view.js +39 -0
- package/dist/read.d.ts +32 -0
- package/dist/read.js +149 -0
- package/dist/scale.d.ts +7 -0
- package/dist/scale.js +9 -0
- package/dist/styles.d.ts +4 -0
- package/dist/styles.js +2166 -0
- package/dist/tools.d.ts +175 -0
- package/dist/tools.js +487 -0
- package/dist/view.d.ts +33 -0
- package/dist/view.js +37 -0
- package/dist/viewer.d.ts +78 -0
- package/dist/viewer.js +496 -0
- package/package.json +22 -3
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** How a prompt sent from the composer is delivered. */
|
|
2
|
+
export type Delivery = "after" | "steer";
|
|
3
|
+
/** What the composer's empty text area says, by whether the agent works and what completes. */
|
|
4
|
+
export declare function placeholderOf(working: boolean, triggers: Array<string | RegExp>): string;
|
|
5
|
+
/** The delivery the send key sends with: the one chosen, while there is a turn it can steer. */
|
|
6
|
+
export declare function deliveryOf(chosen: Delivery, input: {
|
|
7
|
+
working: boolean;
|
|
8
|
+
canSteer: boolean;
|
|
9
|
+
}): Delivery;
|
|
10
|
+
/**
|
|
11
|
+
* What an empty completion list says: still looking; for the agent's `/`
|
|
12
|
+
* commands, whether it sent none at all or none match; otherwise no matches.
|
|
13
|
+
*/
|
|
14
|
+
export declare function emptyCompletionText(state: {
|
|
15
|
+
loading: boolean;
|
|
16
|
+
commands: boolean;
|
|
17
|
+
reported: boolean;
|
|
18
|
+
}): string;
|
|
19
|
+
/**
|
|
20
|
+
* Where a key moves the selection in a completion list of `count` items:
|
|
21
|
+
* the arrows and Ctrl+N and Ctrl+P go round, a page stops at the ends, Home
|
|
22
|
+
* and End go to them. Null for a key that does not move it.
|
|
23
|
+
*/
|
|
24
|
+
export declare function movedSelection(selected: number, count: number, e: {
|
|
25
|
+
key: string;
|
|
26
|
+
ctrlKey: boolean;
|
|
27
|
+
}): number | null;
|
package/dist/composer.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** What the composer's empty text area says, by whether the agent works and what completes. */
|
|
2
|
+
export function placeholderOf(working, triggers) {
|
|
3
|
+
if (working)
|
|
4
|
+
return "Write on; the agent takes it in when it can";
|
|
5
|
+
const files = triggers.some((t) => t === "@") ? ", @ for files" : "";
|
|
6
|
+
return `Ask anything, / for commands${files}`;
|
|
7
|
+
}
|
|
8
|
+
/** The delivery the send key sends with: the one chosen, while there is a turn it can steer. */
|
|
9
|
+
export function deliveryOf(chosen, input) {
|
|
10
|
+
return chosen === "steer" && input.working && input.canSteer ? "steer" : "after";
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* What an empty completion list says: still looking; for the agent's `/`
|
|
14
|
+
* commands, whether it sent none at all or none match; otherwise no matches.
|
|
15
|
+
*/
|
|
16
|
+
export function emptyCompletionText(state) {
|
|
17
|
+
if (state.loading)
|
|
18
|
+
return "Looking…";
|
|
19
|
+
if (!state.commands)
|
|
20
|
+
return "No matches";
|
|
21
|
+
return state.reported ? "No matching commands" : "No commands from the agent yet";
|
|
22
|
+
}
|
|
23
|
+
/** How many items a page key moves a completion list by. */
|
|
24
|
+
const PAGE = 8;
|
|
25
|
+
/**
|
|
26
|
+
* Where a key moves the selection in a completion list of `count` items:
|
|
27
|
+
* the arrows and Ctrl+N and Ctrl+P go round, a page stops at the ends, Home
|
|
28
|
+
* and End go to them. Null for a key that does not move it.
|
|
29
|
+
*/
|
|
30
|
+
export function movedSelection(selected, count, e) {
|
|
31
|
+
if (count === 0)
|
|
32
|
+
return null;
|
|
33
|
+
if (e.key === "ArrowDown" || (e.ctrlKey && e.key === "n"))
|
|
34
|
+
return (selected + 1) % count;
|
|
35
|
+
if (e.key === "ArrowUp" || (e.ctrlKey && e.key === "p"))
|
|
36
|
+
return (selected + count - 1) % count;
|
|
37
|
+
if (e.key === "PageDown")
|
|
38
|
+
return Math.min(count - 1, selected + PAGE);
|
|
39
|
+
if (e.key === "PageUp")
|
|
40
|
+
return Math.max(0, selected - PAGE);
|
|
41
|
+
if (e.key === "Home")
|
|
42
|
+
return 0;
|
|
43
|
+
if (e.key === "End")
|
|
44
|
+
return count - 1;
|
|
45
|
+
return null;
|
|
46
|
+
}
|
package/dist/follow.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keeps a transcript at its newest output while it is read there; marks
|
|
3
|
+
* where output came in while it is read further up, and shows the way back
|
|
4
|
+
* down. A part opened by a click grows the view without moving it.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Follower {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(scroller: HTMLElement, inner: HTMLElement, jump: HTMLElement | null);
|
|
9
|
+
/** Goes to the newest output. */
|
|
10
|
+
toEnd(smooth?: boolean): void;
|
|
11
|
+
dispose(): void;
|
|
12
|
+
}
|
package/dist/follow.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/** How close to its end, in pixels, a view still counts as at its end. */
|
|
2
|
+
const NEAR = 32;
|
|
3
|
+
/** How long after a click a growing view counts as opened by it, in milliseconds. */
|
|
4
|
+
const CLICK_GRACE = 400;
|
|
5
|
+
/**
|
|
6
|
+
* Keeps a transcript at its newest output while it is read there; marks
|
|
7
|
+
* where output came in while it is read further up, and shows the way back
|
|
8
|
+
* down. A part opened by a click grows the view without moving it.
|
|
9
|
+
*/
|
|
10
|
+
export class Follower {
|
|
11
|
+
#scroller;
|
|
12
|
+
#inner;
|
|
13
|
+
#jump;
|
|
14
|
+
#observer;
|
|
15
|
+
#height;
|
|
16
|
+
#count;
|
|
17
|
+
#away = false;
|
|
18
|
+
#from = null;
|
|
19
|
+
#clicked = -Infinity;
|
|
20
|
+
constructor(scroller, inner, jump) {
|
|
21
|
+
this.#scroller = scroller;
|
|
22
|
+
this.#inner = inner;
|
|
23
|
+
this.#jump = jump;
|
|
24
|
+
this.#height = scroller.scrollHeight;
|
|
25
|
+
this.#count = this.#parts().length;
|
|
26
|
+
scroller.addEventListener("scroll", this.#onScroll, { passive: true });
|
|
27
|
+
scroller.addEventListener("click", this.#onClick, true);
|
|
28
|
+
jump?.addEventListener("mousedown", (e) => e.preventDefault());
|
|
29
|
+
jump?.addEventListener("click", () => this.toEnd(true));
|
|
30
|
+
this.#observer = new ResizeObserver(() => this.#grown());
|
|
31
|
+
this.#observer.observe(inner);
|
|
32
|
+
scroller.scrollTop = scroller.scrollHeight;
|
|
33
|
+
}
|
|
34
|
+
/** Goes to the newest output. */
|
|
35
|
+
toEnd(smooth = false) {
|
|
36
|
+
this.#scroller.scrollTo({
|
|
37
|
+
top: this.#scroller.scrollHeight,
|
|
38
|
+
behavior: smooth ? "smooth" : "auto",
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
dispose() {
|
|
42
|
+
this.#observer.disconnect();
|
|
43
|
+
this.#scroller.removeEventListener("scroll", this.#onScroll);
|
|
44
|
+
this.#scroller.removeEventListener("click", this.#onClick, true);
|
|
45
|
+
}
|
|
46
|
+
#parts() {
|
|
47
|
+
return this.#inner.querySelectorAll(":scope > .part");
|
|
48
|
+
}
|
|
49
|
+
#atEnd(height) {
|
|
50
|
+
return this.#scroller.scrollTop + this.#scroller.clientHeight >= height - NEAR;
|
|
51
|
+
}
|
|
52
|
+
#show() {
|
|
53
|
+
this.#jump?.classList.toggle("on", this.#away);
|
|
54
|
+
}
|
|
55
|
+
// Back at the end, what came in has been seen; the mark stays until the
|
|
56
|
+
// view next leaves, so what came in stays told apart.
|
|
57
|
+
#onScroll = () => {
|
|
58
|
+
if (this.#away && this.#atEnd(this.#scroller.scrollHeight)) {
|
|
59
|
+
this.#away = false;
|
|
60
|
+
this.#show();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
#onClick = () => {
|
|
64
|
+
this.#clicked = performance.now();
|
|
65
|
+
};
|
|
66
|
+
#grown() {
|
|
67
|
+
const height = this.#scroller.scrollHeight;
|
|
68
|
+
if (performance.now() - this.#clicked < CLICK_GRACE) {
|
|
69
|
+
// Opened by a click: left where it was opened to be read.
|
|
70
|
+
}
|
|
71
|
+
else if (this.#atEnd(this.#height)) {
|
|
72
|
+
this.#scroller.scrollTop = height;
|
|
73
|
+
}
|
|
74
|
+
else if (height > this.#height) {
|
|
75
|
+
const parts = this.#parts();
|
|
76
|
+
if (!this.#away) {
|
|
77
|
+
this.#away = true;
|
|
78
|
+
for (const p of this.#inner.querySelectorAll("[data-new-from]")) {
|
|
79
|
+
p.removeAttribute("data-new-from");
|
|
80
|
+
}
|
|
81
|
+
// The first part that came, or else the one written into.
|
|
82
|
+
this.#from = parts.length > this.#count ? this.#count : Math.max(this.#count - 1, 0);
|
|
83
|
+
}
|
|
84
|
+
const first = this.#from === null ? undefined : parts[this.#from];
|
|
85
|
+
first?.setAttribute("data-new-from", "");
|
|
86
|
+
this.#show();
|
|
87
|
+
}
|
|
88
|
+
this.#height = height;
|
|
89
|
+
this.#count = this.#parts().length;
|
|
90
|
+
}
|
|
91
|
+
}
|
package/dist/form.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** What a form's number field takes, as the attributes of its `<input type="number">`. */
|
|
2
|
+
export interface NumberInput {
|
|
3
|
+
step: string;
|
|
4
|
+
min?: string;
|
|
5
|
+
max?: string;
|
|
6
|
+
}
|
|
7
|
+
/** The input attributes for an elicitation's `number` or `integer` field. */
|
|
8
|
+
export declare function numberInput(field: {
|
|
9
|
+
type: string;
|
|
10
|
+
minimum?: unknown;
|
|
11
|
+
maximum?: unknown;
|
|
12
|
+
}): NumberInput;
|
package/dist/form.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** The input attributes for an elicitation's `number` or `integer` field. */
|
|
2
|
+
export function numberInput(field) {
|
|
3
|
+
const integer = field.type === "integer";
|
|
4
|
+
// The browser counts an integer's steps from `min`, so a fractional one
|
|
5
|
+
// would shift them off the whole numbers.
|
|
6
|
+
const min = typeof field.minimum === "number" ? field.minimum : null;
|
|
7
|
+
const max = typeof field.maximum === "number" ? field.maximum : null;
|
|
8
|
+
const inMin = min !== null && integer ? Math.ceil(min) : min;
|
|
9
|
+
const inMax = max !== null && integer ? Math.floor(max) : max;
|
|
10
|
+
return {
|
|
11
|
+
step: integer ? "1" : "any",
|
|
12
|
+
...(inMin === null ? {} : { min: String(inMin) }),
|
|
13
|
+
...(inMax === null ? {} : { max: String(inMax) }),
|
|
14
|
+
};
|
|
15
|
+
}
|
package/dist/icons.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type TemplateResult } from "lit";
|
|
2
|
+
/** Tabler Icons, outline style, as Adroit Desktop draws them. */
|
|
3
|
+
declare const ICONS: {
|
|
4
|
+
readonly alertCircle: string;
|
|
5
|
+
readonly alertTriangle: string;
|
|
6
|
+
readonly appWindow: string;
|
|
7
|
+
readonly arrowBarToDown: string;
|
|
8
|
+
readonly arrowUp: string;
|
|
9
|
+
readonly arrowsRightLeft: string;
|
|
10
|
+
readonly ban: string;
|
|
11
|
+
readonly brain: string;
|
|
12
|
+
readonly check: string;
|
|
13
|
+
readonly chevronLeft: string;
|
|
14
|
+
readonly chevronRight: string;
|
|
15
|
+
readonly code: string;
|
|
16
|
+
readonly dots: string;
|
|
17
|
+
readonly copy: string;
|
|
18
|
+
readonly file: string;
|
|
19
|
+
readonly slash: string;
|
|
20
|
+
readonly sparkles: string;
|
|
21
|
+
readonly folder: string;
|
|
22
|
+
readonly textWrap: string;
|
|
23
|
+
readonly arrowsHorizontal: string;
|
|
24
|
+
readonly filePencil: string;
|
|
25
|
+
readonly fold: string;
|
|
26
|
+
readonly infoCircle: string;
|
|
27
|
+
readonly lock: string;
|
|
28
|
+
readonly listCheck: string;
|
|
29
|
+
readonly loader: string;
|
|
30
|
+
readonly messageUp: string;
|
|
31
|
+
readonly notes: string;
|
|
32
|
+
readonly photo: string;
|
|
33
|
+
readonly playerPause: string;
|
|
34
|
+
readonly playerStop: string;
|
|
35
|
+
readonly progress: string;
|
|
36
|
+
readonly refresh: string;
|
|
37
|
+
readonly search: string;
|
|
38
|
+
readonly terminal: string;
|
|
39
|
+
readonly toggleLeft: string;
|
|
40
|
+
readonly trash: string;
|
|
41
|
+
readonly usersGroup: string;
|
|
42
|
+
readonly worldDownload: string;
|
|
43
|
+
readonly x: string;
|
|
44
|
+
readonly externalLink: string;
|
|
45
|
+
readonly folderOpen: string;
|
|
46
|
+
readonly link: string;
|
|
47
|
+
readonly share: string;
|
|
48
|
+
readonly zoomIn: string;
|
|
49
|
+
readonly zoomOut: string;
|
|
50
|
+
};
|
|
51
|
+
export type IconName = keyof typeof ICONS;
|
|
52
|
+
/** `name` drawn in the text's colour, `size` pixels square. */
|
|
53
|
+
export declare function icon(name: IconName, size?: number): TemplateResult;
|
|
54
|
+
/** The icon a tool goes by, from the kind the agent gave it. */
|
|
55
|
+
export declare function kindIcon(kind: string): IconName;
|
|
56
|
+
export {};
|
package/dist/icons.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import alertCircle from "@tabler/icons/outline/alert-circle.svg?raw";
|
|
2
|
+
import alertTriangle from "@tabler/icons/outline/alert-triangle.svg?raw";
|
|
3
|
+
import appWindow from "@tabler/icons/outline/app-window.svg?raw";
|
|
4
|
+
import arrowBarToDown from "@tabler/icons/outline/arrow-bar-to-down.svg?raw";
|
|
5
|
+
import arrowUp from "@tabler/icons/outline/arrow-up.svg?raw";
|
|
6
|
+
import arrowsRightLeft from "@tabler/icons/outline/arrows-right-left.svg?raw";
|
|
7
|
+
import ban from "@tabler/icons/outline/ban.svg?raw";
|
|
8
|
+
import brain from "@tabler/icons/outline/brain.svg?raw";
|
|
9
|
+
import check from "@tabler/icons/outline/check.svg?raw";
|
|
10
|
+
import chevronLeft from "@tabler/icons/outline/chevron-left.svg?raw";
|
|
11
|
+
import chevronRight from "@tabler/icons/outline/chevron-right.svg?raw";
|
|
12
|
+
import code from "@tabler/icons/outline/code.svg?raw";
|
|
13
|
+
import copy from "@tabler/icons/outline/copy.svg?raw";
|
|
14
|
+
import file from "@tabler/icons/outline/file.svg?raw";
|
|
15
|
+
import folder from "@tabler/icons/outline/folder.svg?raw";
|
|
16
|
+
import textWrap from "@tabler/icons/outline/text-wrap.svg?raw";
|
|
17
|
+
import arrowsHorizontal from "@tabler/icons/outline/arrows-horizontal.svg?raw";
|
|
18
|
+
import slash from "@tabler/icons/outline/slash.svg?raw";
|
|
19
|
+
import sparkles from "@tabler/icons/outline/sparkles.svg?raw";
|
|
20
|
+
import filePencil from "@tabler/icons/outline/file-pencil.svg?raw";
|
|
21
|
+
import fold from "@tabler/icons/outline/fold.svg?raw";
|
|
22
|
+
import infoCircle from "@tabler/icons/outline/info-circle.svg?raw";
|
|
23
|
+
import lock from "@tabler/icons/outline/lock.svg?raw";
|
|
24
|
+
import listCheck from "@tabler/icons/outline/list-check.svg?raw";
|
|
25
|
+
import loader from "@tabler/icons/outline/loader-2.svg?raw";
|
|
26
|
+
import messageUp from "@tabler/icons/outline/message-up.svg?raw";
|
|
27
|
+
import notes from "@tabler/icons/outline/notes.svg?raw";
|
|
28
|
+
import photo from "@tabler/icons/outline/photo.svg?raw";
|
|
29
|
+
import playerPause from "@tabler/icons/outline/player-pause.svg?raw";
|
|
30
|
+
import playerStop from "@tabler/icons/outline/player-stop.svg?raw";
|
|
31
|
+
import progress from "@tabler/icons/outline/progress.svg?raw";
|
|
32
|
+
import refresh from "@tabler/icons/outline/refresh.svg?raw";
|
|
33
|
+
import search from "@tabler/icons/outline/search.svg?raw";
|
|
34
|
+
import toggleLeft from "@tabler/icons/outline/toggle-left.svg?raw";
|
|
35
|
+
import trash from "@tabler/icons/outline/trash.svg?raw";
|
|
36
|
+
import usersGroup from "@tabler/icons/outline/users-group.svg?raw";
|
|
37
|
+
import worldDownload from "@tabler/icons/outline/world-download.svg?raw";
|
|
38
|
+
import terminal from "@tabler/icons/outline/terminal-2.svg?raw";
|
|
39
|
+
import x from "@tabler/icons/outline/x.svg?raw";
|
|
40
|
+
import externalLink from "@tabler/icons/outline/external-link.svg?raw";
|
|
41
|
+
import folderOpen from "@tabler/icons/outline/folder-open.svg?raw";
|
|
42
|
+
import link from "@tabler/icons/outline/link.svg?raw";
|
|
43
|
+
import dots from "@tabler/icons/outline/dots.svg?raw";
|
|
44
|
+
import share from "@tabler/icons/outline/share-2.svg?raw";
|
|
45
|
+
import zoomIn from "@tabler/icons/outline/zoom-in.svg?raw";
|
|
46
|
+
import zoomOut from "@tabler/icons/outline/zoom-out.svg?raw";
|
|
47
|
+
import { html } from "lit";
|
|
48
|
+
import { unsafeHTML } from "lit/directives/unsafe-html.js";
|
|
49
|
+
/** Tabler Icons, outline style, as Adroit Desktop draws them. */
|
|
50
|
+
const ICONS = {
|
|
51
|
+
alertCircle,
|
|
52
|
+
alertTriangle,
|
|
53
|
+
appWindow,
|
|
54
|
+
arrowBarToDown,
|
|
55
|
+
arrowUp,
|
|
56
|
+
arrowsRightLeft,
|
|
57
|
+
ban,
|
|
58
|
+
brain,
|
|
59
|
+
check,
|
|
60
|
+
chevronLeft,
|
|
61
|
+
chevronRight,
|
|
62
|
+
code,
|
|
63
|
+
dots,
|
|
64
|
+
copy,
|
|
65
|
+
file,
|
|
66
|
+
slash,
|
|
67
|
+
sparkles,
|
|
68
|
+
folder,
|
|
69
|
+
textWrap,
|
|
70
|
+
arrowsHorizontal,
|
|
71
|
+
filePencil,
|
|
72
|
+
fold,
|
|
73
|
+
infoCircle,
|
|
74
|
+
lock,
|
|
75
|
+
listCheck,
|
|
76
|
+
loader,
|
|
77
|
+
messageUp,
|
|
78
|
+
notes,
|
|
79
|
+
photo,
|
|
80
|
+
playerPause,
|
|
81
|
+
playerStop,
|
|
82
|
+
progress,
|
|
83
|
+
refresh,
|
|
84
|
+
search,
|
|
85
|
+
terminal,
|
|
86
|
+
toggleLeft,
|
|
87
|
+
trash,
|
|
88
|
+
usersGroup,
|
|
89
|
+
worldDownload,
|
|
90
|
+
x,
|
|
91
|
+
externalLink,
|
|
92
|
+
folderOpen,
|
|
93
|
+
link,
|
|
94
|
+
share,
|
|
95
|
+
zoomIn,
|
|
96
|
+
zoomOut,
|
|
97
|
+
};
|
|
98
|
+
/** `name` drawn in the text's colour, `size` pixels square. */
|
|
99
|
+
export function icon(name, size = 14) {
|
|
100
|
+
return html `<span class="icon" style="--icon:calc(${size} * var(--px))" aria-hidden="true"
|
|
101
|
+
>${unsafeHTML(ICONS[name])}</span
|
|
102
|
+
>`;
|
|
103
|
+
}
|
|
104
|
+
/** The icon a tool goes by, from the kind the agent gave it. */
|
|
105
|
+
export function kindIcon(kind) {
|
|
106
|
+
switch (kind) {
|
|
107
|
+
case "read":
|
|
108
|
+
return "file";
|
|
109
|
+
case "edit":
|
|
110
|
+
return "filePencil";
|
|
111
|
+
case "delete":
|
|
112
|
+
return "trash";
|
|
113
|
+
case "move":
|
|
114
|
+
return "arrowsRightLeft";
|
|
115
|
+
case "search":
|
|
116
|
+
return "search";
|
|
117
|
+
case "execute":
|
|
118
|
+
return "terminal";
|
|
119
|
+
case "think":
|
|
120
|
+
return "brain";
|
|
121
|
+
case "fetch":
|
|
122
|
+
return "worldDownload";
|
|
123
|
+
case "switch_mode":
|
|
124
|
+
return "toggleLeft";
|
|
125
|
+
default:
|
|
126
|
+
return "code";
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { OpenImage } from "@adroit-app/chat-core";
|
|
2
|
+
/** An image's pixels, as a canvas reads them: rows of RGBA, top first. */
|
|
3
|
+
export interface ImagePixels {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
rgba: Uint8ClampedArray;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* What a host does with an image shown on its own, beyond what a page can:
|
|
10
|
+
* each one it leaves out is not offered. An image with no file of its own
|
|
11
|
+
* (one the agent sent, a diagram) is the host's to keep somewhere first.
|
|
12
|
+
*/
|
|
13
|
+
export interface ImageActions {
|
|
14
|
+
/** Puts the image on the clipboard; without it the page's clipboard is used. */
|
|
15
|
+
copyImage?(pixels: ImagePixels): Promise<void>;
|
|
16
|
+
/** Puts text on the clipboard; without it the page's clipboard is used. */
|
|
17
|
+
copyText?(text: string): Promise<void>;
|
|
18
|
+
/** Opens the image in the system's app for its type. */
|
|
19
|
+
openWithApp?(image: OpenImage): Promise<void>;
|
|
20
|
+
/** Shows the image's file in the system's file manager. */
|
|
21
|
+
reveal?(image: OpenImage): Promise<void>;
|
|
22
|
+
/** Offers the image to the system's share sheet, next to `anchor` (in the window's CSS pixels). */
|
|
23
|
+
share?(image: OpenImage, anchor: DOMRect): Promise<void>;
|
|
24
|
+
/** Moves an image the Chat shows over itself to a window of its own. */
|
|
25
|
+
openInWindow?(image: OpenImage): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
/** An item of the share menu. */
|
|
28
|
+
export interface ShareItem {
|
|
29
|
+
id: "open" | "reveal" | "copy-path" | "share";
|
|
30
|
+
label: string;
|
|
31
|
+
}
|
|
32
|
+
/** The share menu for `image`, as far as `actions` go. */
|
|
33
|
+
export declare function shareItems(actions: ImageActions | null, image: OpenImage): ShareItem[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The share menu for `image`, as far as `actions` go. */
|
|
2
|
+
export function shareItems(actions, image) {
|
|
3
|
+
const items = [
|
|
4
|
+
actions?.openWithApp ? { id: "open", label: "Open with the default app" } : null,
|
|
5
|
+
actions?.reveal ? { id: "reveal", label: "Show in folder" } : null,
|
|
6
|
+
image.path ? { id: "copy-path", label: "Copy path" } : null,
|
|
7
|
+
actions?.share ? { id: "share", label: "Share…" } : null,
|
|
8
|
+
];
|
|
9
|
+
return items.filter((item) => item !== null);
|
|
10
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./chat.ts";
|
|
2
|
+
export * from "./keymap.ts";
|
|
3
|
+
export type { MarkdownHost, MarkdownPolicy } from "./markdown/render.ts";
|
|
4
|
+
export { SAFE_MARKDOWN } from "./markdown/render.ts";
|
|
5
|
+
export * from "./tools.ts";
|
|
6
|
+
export * from "./scale.ts";
|
|
7
|
+
export { tokens as chatTokens } from "./styles.ts";
|
|
8
|
+
export * from "./attach.ts";
|
|
9
|
+
export * from "./view.ts";
|
|
10
|
+
export * from "./viewer.ts";
|
|
11
|
+
export * from "./image-actions.ts";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./chat.js";
|
|
2
|
+
export * from "./keymap.js";
|
|
3
|
+
export { SAFE_MARKDOWN } from "./markdown/render.js";
|
|
4
|
+
export * from "./tools.js";
|
|
5
|
+
export * from "./scale.js";
|
|
6
|
+
export { tokens as chatTokens } from "./styles.js";
|
|
7
|
+
export * from "./attach.js";
|
|
8
|
+
export * from "./view.js";
|
|
9
|
+
export * from "./viewer.js";
|
|
10
|
+
export * from "./image-actions.js";
|
package/dist/keymap.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** What a key in the composer does. */
|
|
2
|
+
export type KeyAction = "send" | "newline" | "steer" | "stop";
|
|
3
|
+
/**
|
|
4
|
+
* The keys of each action, as chords such as `Ctrl+Enter`: modifiers
|
|
5
|
+
* (`Ctrl`, `Shift`, `Alt`, `Meta` or `Cmd`) joined by `+` to a key as
|
|
6
|
+
* `KeyboardEvent.key` names it. `keymapOf` also reads `Mod`: Cmd on macOS,
|
|
7
|
+
* Ctrl elsewhere.
|
|
8
|
+
*/
|
|
9
|
+
export type Keymap = Record<KeyAction, string[]>;
|
|
10
|
+
/** What a keymap is matched against: a keydown's key and modifiers. */
|
|
11
|
+
export interface KeyLike {
|
|
12
|
+
key: string;
|
|
13
|
+
ctrlKey: boolean;
|
|
14
|
+
metaKey: boolean;
|
|
15
|
+
shiftKey: boolean;
|
|
16
|
+
altKey: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** Whether the platform is Apple's, where Cmd takes Ctrl's place. */
|
|
19
|
+
export declare const isMac: boolean;
|
|
20
|
+
/** Enter writes a new line, Ctrl+Enter sends, Ctrl+Shift+Enter sends now, Ctrl+C stops; Cmd too on macOS for sending. */
|
|
21
|
+
export declare function defaultKeymap(mac?: boolean): Keymap;
|
|
22
|
+
/** `chosen` over the default keymap: each action it names takes its keys from it. */
|
|
23
|
+
export declare function keymapOf(chosen: Partial<Keymap> | null | undefined, mac?: boolean): Keymap;
|
|
24
|
+
/** The action `e` is bound to in `keymap`; none when it is bound to nothing. */
|
|
25
|
+
export declare function actionOf(e: KeyLike, keymap: Keymap): KeyAction | null;
|
|
26
|
+
/** How `chord` is written in a hint: every key a word, joined by `+`; Meta is Cmd on macOS. */
|
|
27
|
+
export declare function chordLabel(chord: string, mac?: boolean): string;
|
|
28
|
+
/** The chord `e` is, as a keymap is written: what a key field records. None for a modifier alone. */
|
|
29
|
+
export declare function chordOf(e: KeyLike): string | null;
|
package/dist/keymap.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/** Whether the platform is Apple's, where Cmd takes Ctrl's place. */
|
|
2
|
+
export const isMac = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform);
|
|
3
|
+
/** Enter writes a new line, Ctrl+Enter sends, Ctrl+Shift+Enter sends now, Ctrl+C stops; Cmd too on macOS for sending. */
|
|
4
|
+
export function defaultKeymap(mac = isMac) {
|
|
5
|
+
return {
|
|
6
|
+
send: mac ? ["Meta+Enter", "Ctrl+Enter"] : ["Ctrl+Enter"],
|
|
7
|
+
newline: ["Enter", "Shift+Enter"],
|
|
8
|
+
steer: mac ? ["Meta+Shift+Enter", "Ctrl+Shift+Enter"] : ["Ctrl+Shift+Enter"],
|
|
9
|
+
stop: ["Ctrl+c"],
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/** `chosen` over the default keymap: each action it names takes its keys from it. */
|
|
13
|
+
export function keymapOf(chosen, mac = isMac) {
|
|
14
|
+
const keymap = { ...defaultKeymap(mac), ...chosen };
|
|
15
|
+
const own = (chord) => chord.replace(/\bmod\+/gi, mac ? "Meta+" : "Ctrl+");
|
|
16
|
+
return {
|
|
17
|
+
send: keymap.send.map(own),
|
|
18
|
+
newline: keymap.newline.map(own),
|
|
19
|
+
steer: keymap.steer.map(own),
|
|
20
|
+
stop: keymap.stop.map(own),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function parse(chord) {
|
|
24
|
+
const parts = chord.split("+").map((p) => p.trim());
|
|
25
|
+
// A chord ending in "+" names the plus key: "Ctrl++".
|
|
26
|
+
const key = chord.endsWith("++") ? "+" : (parts.pop() ?? "");
|
|
27
|
+
const mods = new Set(parts.filter((p) => p !== "").map((p) => p.toLowerCase()));
|
|
28
|
+
return {
|
|
29
|
+
key: key.toLowerCase(),
|
|
30
|
+
ctrl: mods.has("ctrl") || mods.has("control"),
|
|
31
|
+
meta: mods.has("meta") || mods.has("cmd") || mods.has("command"),
|
|
32
|
+
shift: mods.has("shift"),
|
|
33
|
+
alt: mods.has("alt") || mods.has("option"),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function matches(e, chord) {
|
|
37
|
+
return (e.key.toLowerCase() === chord.key &&
|
|
38
|
+
e.ctrlKey === chord.ctrl &&
|
|
39
|
+
e.metaKey === chord.meta &&
|
|
40
|
+
e.shiftKey === chord.shift &&
|
|
41
|
+
e.altKey === chord.alt);
|
|
42
|
+
}
|
|
43
|
+
const ORDER = ["steer", "send", "stop", "newline"];
|
|
44
|
+
/** The action `e` is bound to in `keymap`; none when it is bound to nothing. */
|
|
45
|
+
export function actionOf(e, keymap) {
|
|
46
|
+
return ORDER.find((action) => keymap[action].some((c) => matches(e, parse(c)))) ?? null;
|
|
47
|
+
}
|
|
48
|
+
/** How `chord` is written in a hint: every key a word, joined by `+`; Meta is Cmd on macOS. */
|
|
49
|
+
export function chordLabel(chord, mac = isMac) {
|
|
50
|
+
const c = parse(chord);
|
|
51
|
+
const original = chord.endsWith("++") ? "+" : (chord.split("+").pop()?.trim() ?? "");
|
|
52
|
+
const key = c.key === "escape" ? "Esc" : original.length === 1 ? original.toUpperCase() : original;
|
|
53
|
+
const mods = [
|
|
54
|
+
c.ctrl && "Ctrl",
|
|
55
|
+
c.meta && (mac ? "Cmd" : "Meta"),
|
|
56
|
+
c.alt && "Alt",
|
|
57
|
+
c.shift && "Shift",
|
|
58
|
+
];
|
|
59
|
+
return [...mods.filter((m) => typeof m === "string"), key].join("+");
|
|
60
|
+
}
|
|
61
|
+
const MODIFIERS = new Set(["Control", "Shift", "Alt", "Meta", "OS", "AltGraph", "CapsLock"]);
|
|
62
|
+
/** The chord `e` is, as a keymap is written: what a key field records. None for a modifier alone. */
|
|
63
|
+
export function chordOf(e) {
|
|
64
|
+
if (MODIFIERS.has(e.key) || e.key === "Dead" || e.key === "Unidentified")
|
|
65
|
+
return null;
|
|
66
|
+
const key = e.key.length === 1 ? e.key.toLowerCase() : e.key;
|
|
67
|
+
const mods = [e.ctrlKey && "Ctrl", e.metaKey && "Meta", e.altKey && "Alt", e.shiftKey && "Shift"];
|
|
68
|
+
return [...mods.filter((m) => typeof m === "string"), key].join("+");
|
|
69
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Library } from "@arto-app/markdown/wasm";
|
|
2
|
+
import { type MarkdownHost, type MarkdownPolicy, type Rendered } from "./render.ts";
|
|
3
|
+
export declare function render(markdown: string, policy: MarkdownPolicy, host: MarkdownHost): Rendered;
|
|
4
|
+
/** Arto's stylesheet, one sheet for every Chat on the page. */
|
|
5
|
+
export declare function markdownSheet(): CSSStyleSheet;
|
|
6
|
+
export declare function draw(viewer: HTMLElement, libraries: readonly Library[], theme: "light" | "dark", highlight: boolean): Promise<void>;
|