@adroit-app/chat-ui 0.0.0-stage → 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/dist/read.js ADDED
@@ -0,0 +1,149 @@
1
+ /** highlight.js's names of languages, by a file's extension, lower case. */
2
+ const BY_EXTENSION = {
3
+ ts: "typescript",
4
+ tsx: "typescript",
5
+ mts: "typescript",
6
+ cts: "typescript",
7
+ js: "javascript",
8
+ jsx: "javascript",
9
+ mjs: "javascript",
10
+ cjs: "javascript",
11
+ rs: "rust",
12
+ py: "python",
13
+ rb: "ruby",
14
+ go: "go",
15
+ java: "java",
16
+ kt: "kotlin",
17
+ kts: "kotlin",
18
+ swift: "swift",
19
+ c: "c",
20
+ h: "c",
21
+ cc: "cpp",
22
+ cpp: "cpp",
23
+ cxx: "cpp",
24
+ hpp: "cpp",
25
+ hh: "cpp",
26
+ cs: "csharp",
27
+ php: "php",
28
+ pl: "perl",
29
+ lua: "lua",
30
+ r: "r",
31
+ sh: "bash",
32
+ bash: "bash",
33
+ zsh: "bash",
34
+ json: "json",
35
+ jsonc: "json",
36
+ yaml: "yaml",
37
+ yml: "yaml",
38
+ toml: "ini",
39
+ ini: "ini",
40
+ cfg: "ini",
41
+ xml: "xml",
42
+ svg: "xml",
43
+ html: "xml",
44
+ htm: "xml",
45
+ vue: "xml",
46
+ svelte: "xml",
47
+ css: "css",
48
+ scss: "scss",
49
+ less: "less",
50
+ sql: "sql",
51
+ graphql: "graphql",
52
+ gql: "graphql",
53
+ md: "markdown",
54
+ markdown: "markdown",
55
+ mdx: "markdown",
56
+ diff: "diff",
57
+ patch: "diff",
58
+ nix: "nix",
59
+ hs: "haskell",
60
+ ex: "elixir",
61
+ exs: "elixir",
62
+ erl: "erlang",
63
+ clj: "clojure",
64
+ scala: "scala",
65
+ dart: "dart",
66
+ proto: "protobuf",
67
+ vim: "vim",
68
+ };
69
+ /** highlight.js's names of languages, by a whole file name, for files named for their tool. */
70
+ const BY_NAME = {
71
+ dockerfile: "dockerfile",
72
+ makefile: "makefile",
73
+ gnumakefile: "makefile",
74
+ };
75
+ /** The file name at the end of `path`. */
76
+ export function fileName(path) {
77
+ return path.split(/[\\/]/).pop() ?? path;
78
+ }
79
+ /** The language highlight.js highlights the file at `path` as; null for a type it does not know. */
80
+ export function languageOfPath(path) {
81
+ const name = fileName(path).toLowerCase();
82
+ const byName = BY_NAME[name];
83
+ if (byName)
84
+ return byName;
85
+ const dot = name.lastIndexOf(".");
86
+ if (dot <= 0)
87
+ return null;
88
+ return BY_EXTENSION[name.slice(dot + 1)] ?? null;
89
+ }
90
+ const NUMBERED = /^ *(\d+)(?:\t|→)(.*)$/;
91
+ const REMINDER = /^\s*(?:<system-reminder>[\s\S]*?<\/system-reminder>\s*)*$/;
92
+ /**
93
+ * A file's text as a read tool gave it, `cat -n` style, without the number
94
+ * before each line: the number its first line has, and the text. The
95
+ * numbers must run on from line to line, so text that only looks numbered
96
+ * is left alone; reminders the tool adds after the file are not the file.
97
+ * Null when the text is not numbered so.
98
+ */
99
+ export function numberedLines(text) {
100
+ const lines = text.split("\n");
101
+ const kept = [];
102
+ let first = null;
103
+ let i = 0;
104
+ for (; i < lines.length; i++) {
105
+ const match = NUMBERED.exec(lines[i]);
106
+ if (!match)
107
+ break;
108
+ const n = Number(match[1]);
109
+ if (first === null)
110
+ first = n;
111
+ else if (n !== first + kept.length)
112
+ return null;
113
+ kept.push(match[2]);
114
+ }
115
+ if (first === null || !REMINDER.test(lines.slice(i).join("\n")))
116
+ return null;
117
+ return { first, text: kept.join("\n") };
118
+ }
119
+ /** The code of `text` when it is one fenced code block and nothing else; null otherwise. */
120
+ export function unfenced(text) {
121
+ const match = /^(`{3,})[^`\n]*\n([\s\S]*?)\n\1[ \t]*$/.exec(text.trim());
122
+ return match ? match[2] : null;
123
+ }
124
+ /**
125
+ * A read's raw output as blocks, in order: its text, and its images as ACP's
126
+ * image content or an image block as the Anthropic API spells it, which
127
+ * Claude Code's Read returns and acp-adapter passes on as the raw output.
128
+ */
129
+ export function readBlocks(raw) {
130
+ if (!Array.isArray(raw))
131
+ return [];
132
+ return raw.flatMap((block) => {
133
+ if (block === null || typeof block !== "object")
134
+ return [];
135
+ const b = block;
136
+ if (b.type === "text" && typeof b.text === "string")
137
+ return [{ type: "text", text: b.text }];
138
+ if (b.type !== "image")
139
+ return [];
140
+ if (typeof b.data === "string" && typeof b.mimeType === "string") {
141
+ return [{ type: "image", data: b.data, mimeType: b.mimeType }];
142
+ }
143
+ const source = b.source;
144
+ if (typeof source?.data === "string" && typeof source.media_type === "string") {
145
+ return [{ type: "image", data: source.data, mimeType: source.media_type }];
146
+ }
147
+ return [];
148
+ });
149
+ }
@@ -0,0 +1,7 @@
1
+ /** The CSS custom property the Chat's every length is scaled by. */
2
+ export declare const FONT_SCALE_PROPERTY = "--adroit-chat-font-scale";
3
+ /**
4
+ * What `--adroit-chat-font-scale` is set to for `scale`; null leaves it to
5
+ * the page, which may set it itself.
6
+ */
7
+ export declare function fontScaleProperty(scale: number | null | undefined): string | null;
package/dist/scale.js ADDED
@@ -0,0 +1,9 @@
1
+ /** The CSS custom property the Chat's every length is scaled by. */
2
+ export const FONT_SCALE_PROPERTY = "--adroit-chat-font-scale";
3
+ /**
4
+ * What `--adroit-chat-font-scale` is set to for `scale`; null leaves it to
5
+ * the page, which may set it itself.
6
+ */
7
+ export function fontScaleProperty(scale) {
8
+ return typeof scale === "number" && Number.isFinite(scale) && scale > 0 ? String(scale) : null;
9
+ }
@@ -0,0 +1,4 @@
1
+ export declare const tokens: import("lit").CSSResult;
2
+ /** Arto's document colours, taken from the Chat's as the desktop takes them from its theme. */
3
+ export declare const documentTokens: import("lit").CSSResult;
4
+ export declare const chatStyles: import("lit").CSSResult;