@vitral/chat 0.2.6 → 0.2.8
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/engine/index.d.ts +1 -0
- package/dist/engine/index.js +2 -1
- package/dist/engine/markdown.d.ts +49 -0
- package/dist/engine/markdown.js +178 -0
- package/dist/engine/markdown.js.map +1 -0
- package/dist/engine/types.d.ts +8 -0
- package/dist/index.js +2 -1
- package/dist/render/chat.js +43 -4
- package/dist/render/chat.js.map +1 -1
- package/package.json +6 -6
package/dist/engine/index.d.ts
CHANGED
package/dist/engine/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { announcementOf, formatSize, groupMessages, initialsOf, messageKeyTarget, showsAvatars, showsBubbles, sideOf } from "./state.js";
|
|
2
|
-
|
|
2
|
+
import { parseChatInline, parseChatMarkdown, safeChatHref } from "./markdown.js";
|
|
3
|
+
export { announcementOf, formatSize, groupMessages, initialsOf, messageKeyTarget, parseChatInline, parseChatMarkdown, safeChatHref, showsAvatars, showsBubbles, sideOf };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Markdown a chat answer is usually written in, read into a small tree a
|
|
3
|
+
* renderer draws as elements — never as HTML, so nothing in a message can run
|
|
4
|
+
* or restyle the page. It reads what answers use: paragraphs and line
|
|
5
|
+
* breaks, headings, lists, quotes, fenced code, bold, italic, inline code and
|
|
6
|
+
* links. What it does not recognise stays text. A message still arriving is
|
|
7
|
+
* read as it stands: an unclosed fence is a code block so far, an unclosed
|
|
8
|
+
* `**` is just stars.
|
|
9
|
+
*/
|
|
10
|
+
export type ChatInline = {
|
|
11
|
+
type: 'text';
|
|
12
|
+
text: string;
|
|
13
|
+
} | {
|
|
14
|
+
type: 'strong' | 'em';
|
|
15
|
+
children: ChatInline[];
|
|
16
|
+
} | {
|
|
17
|
+
type: 'code';
|
|
18
|
+
text: string;
|
|
19
|
+
} | {
|
|
20
|
+
type: 'link';
|
|
21
|
+
href: string;
|
|
22
|
+
children: ChatInline[];
|
|
23
|
+
} | {
|
|
24
|
+
type: 'br';
|
|
25
|
+
};
|
|
26
|
+
export type ChatBlock = {
|
|
27
|
+
type: 'paragraph';
|
|
28
|
+
children: ChatInline[];
|
|
29
|
+
} | {
|
|
30
|
+
type: 'heading';
|
|
31
|
+
level: number;
|
|
32
|
+
children: ChatInline[];
|
|
33
|
+
} | {
|
|
34
|
+
type: 'code';
|
|
35
|
+
language: string | null;
|
|
36
|
+
text: string;
|
|
37
|
+
} | {
|
|
38
|
+
type: 'quote';
|
|
39
|
+
children: ChatBlock[];
|
|
40
|
+
} | {
|
|
41
|
+
type: 'list';
|
|
42
|
+
ordered: boolean;
|
|
43
|
+
start: number;
|
|
44
|
+
items: ChatInline[][];
|
|
45
|
+
};
|
|
46
|
+
/** Only addresses that go somewhere a reader expects: the web and mail. */
|
|
47
|
+
export declare function safeChatHref(href: string): string | null;
|
|
48
|
+
export declare function parseChatInline(text: string): ChatInline[];
|
|
49
|
+
export declare function parseChatMarkdown(source: string): ChatBlock[];
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
//#region src/engine/markdown.ts
|
|
2
|
+
/** Only addresses that go somewhere a reader expects: the web and mail. */
|
|
3
|
+
function safeChatHref(href) {
|
|
4
|
+
const trimmed = href.trim();
|
|
5
|
+
return /^(https?:\/\/|mailto:)/i.test(trimmed) ? trimmed : null;
|
|
6
|
+
}
|
|
7
|
+
function parseChatInline(text) {
|
|
8
|
+
const out = [];
|
|
9
|
+
let buffer = "";
|
|
10
|
+
const flush = () => {
|
|
11
|
+
if (buffer) out.push({
|
|
12
|
+
type: "text",
|
|
13
|
+
text: buffer
|
|
14
|
+
});
|
|
15
|
+
buffer = "";
|
|
16
|
+
};
|
|
17
|
+
let i = 0;
|
|
18
|
+
while (i < text.length) {
|
|
19
|
+
const rest = text.slice(i);
|
|
20
|
+
if (rest[0] === "\\" && rest.length > 1 && /[\\`*_[\]()#>-]/.test(rest[1])) {
|
|
21
|
+
buffer += rest[1];
|
|
22
|
+
i += 2;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (rest[0] === "\n") {
|
|
26
|
+
flush();
|
|
27
|
+
out.push({ type: "br" });
|
|
28
|
+
i++;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const code = /^`([^`\n]+)`/.exec(rest);
|
|
32
|
+
if (code) {
|
|
33
|
+
flush();
|
|
34
|
+
out.push({
|
|
35
|
+
type: "code",
|
|
36
|
+
text: code[1]
|
|
37
|
+
});
|
|
38
|
+
i += code[0].length;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const strong = /^(\*\*|__)(?=\S)([\s\S]*?\S)\1/.exec(rest);
|
|
42
|
+
if (strong) {
|
|
43
|
+
flush();
|
|
44
|
+
out.push({
|
|
45
|
+
type: "strong",
|
|
46
|
+
children: parseChatInline(strong[2])
|
|
47
|
+
});
|
|
48
|
+
i += strong[0].length;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const em = /^(\*|_)(?=\S)([^*_\n]*?\S)\1(?![\w*])/.exec(rest);
|
|
52
|
+
if (em && !(em[1] === "_" && /\w/.test(text[i - 1] ?? ""))) {
|
|
53
|
+
flush();
|
|
54
|
+
out.push({
|
|
55
|
+
type: "em",
|
|
56
|
+
children: parseChatInline(em[2])
|
|
57
|
+
});
|
|
58
|
+
i += em[0].length;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const link = /^\[([^\]\n]+)\]\(([^)\s]+)\)/.exec(rest);
|
|
62
|
+
if (link) {
|
|
63
|
+
const href = safeChatHref(link[2]);
|
|
64
|
+
flush();
|
|
65
|
+
if (href) out.push({
|
|
66
|
+
type: "link",
|
|
67
|
+
href,
|
|
68
|
+
children: parseChatInline(link[1])
|
|
69
|
+
});
|
|
70
|
+
else out.push({
|
|
71
|
+
type: "text",
|
|
72
|
+
text: link[1]
|
|
73
|
+
});
|
|
74
|
+
i += link[0].length;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const bare = /^https?:\/\/[^\s<>)]+[^\s<>).,;:!?'"]/.exec(rest);
|
|
78
|
+
if (bare && !/\w/.test(text[i - 1] ?? "")) {
|
|
79
|
+
flush();
|
|
80
|
+
out.push({
|
|
81
|
+
type: "link",
|
|
82
|
+
href: bare[0],
|
|
83
|
+
children: [{
|
|
84
|
+
type: "text",
|
|
85
|
+
text: bare[0]
|
|
86
|
+
}]
|
|
87
|
+
});
|
|
88
|
+
i += bare[0].length;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
buffer += rest[0];
|
|
92
|
+
i++;
|
|
93
|
+
}
|
|
94
|
+
flush();
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
function parseChatMarkdown(source) {
|
|
98
|
+
const lines = source.replace(/\r\n?/g, "\n").split("\n");
|
|
99
|
+
const blocks = [];
|
|
100
|
+
let paragraph = [];
|
|
101
|
+
const endParagraph = () => {
|
|
102
|
+
if (paragraph.length) blocks.push({
|
|
103
|
+
type: "paragraph",
|
|
104
|
+
children: parseChatInline(paragraph.join("\n"))
|
|
105
|
+
});
|
|
106
|
+
paragraph = [];
|
|
107
|
+
};
|
|
108
|
+
for (let i = 0; i < lines.length; i++) {
|
|
109
|
+
const line = lines[i];
|
|
110
|
+
const fence = /^\s*(```|~~~)\s*([\w+#.-]*)\s*$/.exec(line);
|
|
111
|
+
if (fence) {
|
|
112
|
+
endParagraph();
|
|
113
|
+
const body = [];
|
|
114
|
+
let j = i + 1;
|
|
115
|
+
while (j < lines.length && !new RegExp(`^\\s*${fence[1]}\\s*$`).test(lines[j])) body.push(lines[j++]);
|
|
116
|
+
blocks.push({
|
|
117
|
+
type: "code",
|
|
118
|
+
language: fence[2] || null,
|
|
119
|
+
text: body.join("\n")
|
|
120
|
+
});
|
|
121
|
+
i = j;
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (!line.trim()) {
|
|
125
|
+
endParagraph();
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const heading = /^(#{1,6})\s+(.*)$/.exec(line);
|
|
129
|
+
if (heading) {
|
|
130
|
+
endParagraph();
|
|
131
|
+
blocks.push({
|
|
132
|
+
type: "heading",
|
|
133
|
+
level: heading[1].length,
|
|
134
|
+
children: parseChatInline(heading[2].replace(/\s+#+\s*$/, ""))
|
|
135
|
+
});
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (/^\s*>/.test(line)) {
|
|
139
|
+
endParagraph();
|
|
140
|
+
const quoted = [];
|
|
141
|
+
while (i < lines.length && /^\s*>/.test(lines[i])) quoted.push(lines[i++].replace(/^\s*>\s?/, ""));
|
|
142
|
+
i--;
|
|
143
|
+
blocks.push({
|
|
144
|
+
type: "quote",
|
|
145
|
+
children: parseChatMarkdown(quoted.join("\n"))
|
|
146
|
+
});
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const item = /^\s*([-*+]|(\d{1,9})[.)])\s+(.*)$/.exec(line);
|
|
150
|
+
if (item) {
|
|
151
|
+
endParagraph();
|
|
152
|
+
const ordered = !!item[2];
|
|
153
|
+
const start = ordered ? Number(item[2]) : 1;
|
|
154
|
+
const items = [];
|
|
155
|
+
while (i < lines.length) {
|
|
156
|
+
const m = /^\s*([-*+]|(\d{1,9})[.)])\s+(.*)$/.exec(lines[i]);
|
|
157
|
+
if (!m || !!m[2] !== ordered) break;
|
|
158
|
+
items.push(parseChatInline(m[3]));
|
|
159
|
+
i++;
|
|
160
|
+
}
|
|
161
|
+
i--;
|
|
162
|
+
blocks.push({
|
|
163
|
+
type: "list",
|
|
164
|
+
ordered,
|
|
165
|
+
start,
|
|
166
|
+
items
|
|
167
|
+
});
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
paragraph.push(line);
|
|
171
|
+
}
|
|
172
|
+
endParagraph();
|
|
173
|
+
return blocks;
|
|
174
|
+
}
|
|
175
|
+
//#endregion
|
|
176
|
+
export { parseChatInline, parseChatMarkdown, safeChatHref };
|
|
177
|
+
|
|
178
|
+
//# sourceMappingURL=markdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.js","names":[],"sources":["../../src/engine/markdown.ts"],"sourcesContent":["/**\n * The Markdown a chat answer is usually written in, read into a small tree a\n * renderer draws as elements — never as HTML, so nothing in a message can run\n * or restyle the page. It reads what answers use: paragraphs and line\n * breaks, headings, lists, quotes, fenced code, bold, italic, inline code and\n * links. What it does not recognise stays text. A message still arriving is\n * read as it stands: an unclosed fence is a code block so far, an unclosed\n * `**` is just stars.\n */\n\nexport type ChatInline =\n | { type: 'text'; text: string }\n | { type: 'strong' | 'em'; children: ChatInline[] }\n | { type: 'code'; text: string }\n | { type: 'link'; href: string; children: ChatInline[] }\n | { type: 'br' };\n\nexport type ChatBlock =\n | { type: 'paragraph'; children: ChatInline[] }\n | { type: 'heading'; level: number; children: ChatInline[] }\n | { type: 'code'; language: string | null; text: string }\n | { type: 'quote'; children: ChatBlock[] }\n | { type: 'list'; ordered: boolean; start: number; items: ChatInline[][] };\n\n/** Only addresses that go somewhere a reader expects: the web and mail. */\nexport function safeChatHref(href: string): string | null {\n const trimmed = href.trim();\n return /^(https?:\\/\\/|mailto:)/i.test(trimmed) ? trimmed : null;\n}\n\nexport function parseChatInline(text: string): ChatInline[] {\n const out: ChatInline[] = [];\n let buffer = '';\n const flush = () => {\n if (buffer) out.push({ type: 'text', text: buffer });\n buffer = '';\n };\n let i = 0;\n while (i < text.length) {\n const rest = text.slice(i);\n if (rest[0] === '\\\\' && rest.length > 1 && /[\\\\`*_[\\]()#>-]/.test(rest[1]!)) {\n buffer += rest[1];\n i += 2;\n continue;\n }\n if (rest[0] === '\\n') {\n flush();\n out.push({ type: 'br' });\n i++;\n continue;\n }\n const code = /^`([^`\\n]+)`/.exec(rest);\n if (code) {\n flush();\n out.push({ type: 'code', text: code[1]! });\n i += code[0].length;\n continue;\n }\n const strong = /^(\\*\\*|__)(?=\\S)([\\s\\S]*?\\S)\\1/.exec(rest);\n if (strong) {\n flush();\n out.push({ type: 'strong', children: parseChatInline(strong[2]!) });\n i += strong[0].length;\n continue;\n }\n const em = /^(\\*|_)(?=\\S)([^*_\\n]*?\\S)\\1(?![\\w*])/.exec(rest);\n // An underscore inside a word (snake_case) is not emphasis.\n if (em && !(em[1] === '_' && /\\w/.test(text[i - 1] ?? ''))) {\n flush();\n out.push({ type: 'em', children: parseChatInline(em[2]!) });\n i += em[0].length;\n continue;\n }\n const link = /^\\[([^\\]\\n]+)\\]\\(([^)\\s]+)\\)/.exec(rest);\n if (link) {\n const href = safeChatHref(link[2]!);\n flush();\n if (href) out.push({ type: 'link', href, children: parseChatInline(link[1]!) });\n else out.push({ type: 'text', text: link[1]! });\n i += link[0].length;\n continue;\n }\n const bare = /^https?:\\/\\/[^\\s<>)]+[^\\s<>).,;:!?'\"]/.exec(rest);\n if (bare && !/\\w/.test(text[i - 1] ?? '')) {\n flush();\n out.push({ type: 'link', href: bare[0], children: [{ type: 'text', text: bare[0] }] });\n i += bare[0].length;\n continue;\n }\n buffer += rest[0];\n i++;\n }\n flush();\n return out;\n}\n\nexport function parseChatMarkdown(source: string): ChatBlock[] {\n const lines = source.replace(/\\r\\n?/g, '\\n').split('\\n');\n const blocks: ChatBlock[] = [];\n let paragraph: string[] = [];\n const endParagraph = () => {\n if (paragraph.length) blocks.push({ type: 'paragraph', children: parseChatInline(paragraph.join('\\n')) });\n paragraph = [];\n };\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i]!;\n const fence = /^\\s*(```|~~~)\\s*([\\w+#.-]*)\\s*$/.exec(line);\n if (fence) {\n endParagraph();\n const body: string[] = [];\n let j = i + 1;\n while (j < lines.length && !new RegExp(`^\\\\s*${fence[1]}\\\\s*$`).test(lines[j]!)) body.push(lines[j++]!);\n blocks.push({ type: 'code', language: fence[2] || null, text: body.join('\\n') });\n i = j;\n continue;\n }\n if (!line.trim()) {\n endParagraph();\n continue;\n }\n const heading = /^(#{1,6})\\s+(.*)$/.exec(line);\n if (heading) {\n endParagraph();\n blocks.push({ type: 'heading', level: heading[1]!.length, children: parseChatInline(heading[2]!.replace(/\\s+#+\\s*$/, '')) });\n continue;\n }\n if (/^\\s*>/.test(line)) {\n endParagraph();\n const quoted: string[] = [];\n while (i < lines.length && /^\\s*>/.test(lines[i]!)) quoted.push(lines[i++]!.replace(/^\\s*>\\s?/, ''));\n i--;\n blocks.push({ type: 'quote', children: parseChatMarkdown(quoted.join('\\n')) });\n continue;\n }\n const item = /^\\s*([-*+]|(\\d{1,9})[.)])\\s+(.*)$/.exec(line);\n if (item) {\n endParagraph();\n const ordered = !!item[2];\n const start = ordered ? Number(item[2]) : 1;\n const items: ChatInline[][] = [];\n while (i < lines.length) {\n const m = /^\\s*([-*+]|(\\d{1,9})[.)])\\s+(.*)$/.exec(lines[i]!);\n if (!m || !!m[2] !== ordered) break;\n items.push(parseChatInline(m[3]!));\n i++;\n }\n i--;\n blocks.push({ type: 'list', ordered, start, items });\n continue;\n }\n paragraph.push(line);\n }\n endParagraph();\n return blocks;\n}\n"],"mappings":";;AAyBA,SAAgB,aAAa,MAA6B;CACtD,MAAM,UAAU,KAAK,KAAK;CAC1B,OAAO,0BAA0B,KAAK,OAAO,IAAI,UAAU;AAC/D;AAEA,SAAgB,gBAAgB,MAA4B;CACxD,MAAM,MAAoB,CAAC;CAC3B,IAAI,SAAS;CACb,MAAM,cAAc;EAChB,IAAI,QAAQ,IAAI,KAAK;GAAE,MAAM;GAAQ,MAAM;EAAO,CAAC;EACnD,SAAS;CACb;CACA,IAAI,IAAI;CACR,OAAO,IAAI,KAAK,QAAQ;EACpB,MAAM,OAAO,KAAK,MAAM,CAAC;EACzB,IAAI,KAAK,OAAO,QAAQ,KAAK,SAAS,KAAK,kBAAkB,KAAK,KAAK,EAAG,GAAG;GACzE,UAAU,KAAK;GACf,KAAK;GACL;EACJ;EACA,IAAI,KAAK,OAAO,MAAM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OAAO,KAAK,MAAM,IAAI,CAAE,QAAQ,YAAY,EAAE,CAAC;GACnG;GACA,OAAO,KAAK;IAAE,MAAM;IAAS,UAAU,kBAAkB,OAAO,KAAK,IAAI,CAAC;GAAE,CAAC;GAC7E;EACJ;EACA,MAAM,OAAO,oCAAoC,KAAK,IAAI;EAC1D,IAAI,MAAM;GACN,aAAa;GACb,MAAM,UAAU,CAAC,CAAC,KAAK;GACvB,MAAM,QAAQ,UAAU,OAAO,KAAK,EAAE,IAAI;GAC1C,MAAM,QAAwB,CAAC;GAC/B,OAAO,IAAI,MAAM,QAAQ;IACrB,MAAM,IAAI,oCAAoC,KAAK,MAAM,EAAG;IAC5D,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,SAAS;IAC9B,MAAM,KAAK,gBAAgB,EAAE,EAAG,CAAC;IACjC;GACJ;GACA;GACA,OAAO,KAAK;IAAE,MAAM;IAAQ;IAAS;IAAO;GAAM,CAAC;GACnD;EACJ;EACA,UAAU,KAAK,IAAI;CACvB;CACA,aAAa;CACb,OAAO;AACX"}
|
package/dist/engine/types.d.ts
CHANGED
|
@@ -63,6 +63,8 @@ export interface ChatMessage {
|
|
|
63
63
|
* token — a screen reader cannot follow a stream and should not try.
|
|
64
64
|
*/
|
|
65
65
|
streaming?: boolean;
|
|
66
|
+
/** Read `content` as Markdown, or as plain text; the chat's `markdown` decides when unset. */
|
|
67
|
+
markdown?: boolean;
|
|
66
68
|
/** What went wrong, shown in the message's place. */
|
|
67
69
|
error?: string;
|
|
68
70
|
/** The reader can ask for this one again. */
|
|
@@ -156,6 +158,12 @@ export interface ChatConfig {
|
|
|
156
158
|
* words to show instead ("Searching the docs…").
|
|
157
159
|
*/
|
|
158
160
|
typing?: boolean | string;
|
|
161
|
+
/**
|
|
162
|
+
* Read messages as Markdown: bold, italic, code, links, lists, quotes and
|
|
163
|
+
* headings. It is drawn as elements, never as HTML, and only web and mail
|
|
164
|
+
* links are followed. A message's own `markdown` wins.
|
|
165
|
+
*/
|
|
166
|
+
markdown?: boolean;
|
|
159
167
|
/** The composer is there but cannot be used. */
|
|
160
168
|
disabled?: boolean;
|
|
161
169
|
/** No composer at all: a transcript. */
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { announcementOf, formatSize, groupMessages, initialsOf, messageKeyTarget, showsAvatars, showsBubbles, sideOf } from "./engine/state.js";
|
|
2
|
+
import { parseChatInline, parseChatMarkdown, safeChatHref } from "./engine/markdown.js";
|
|
2
3
|
import { chatView } from "./render/chat.js";
|
|
3
4
|
import { createChat } from "./chat.js";
|
|
4
|
-
export { announcementOf, chatView, createChat, formatSize, groupMessages, initialsOf, messageKeyTarget, showsAvatars, showsBubbles, sideOf };
|
|
5
|
+
export { announcementOf, chatView, createChat, formatSize, groupMessages, initialsOf, messageKeyTarget, parseChatInline, parseChatMarkdown, safeChatHref, showsAvatars, showsBubbles, sideOf };
|
package/dist/render/chat.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { formatSize, groupMessages, initialsOf, showsAvatars, sideOf } from "../engine/state.js";
|
|
2
|
+
import { parseChatMarkdown } from "../engine/markdown.js";
|
|
2
3
|
import { formatMessage } from "@vitral/core";
|
|
3
4
|
import { h, iconNode, mergeAttrs } from "@vitral/dom";
|
|
4
5
|
import { getIcon } from "@vitral/icons";
|
|
@@ -94,6 +95,42 @@ function actionView(context, action, message) {
|
|
|
94
95
|
onClick: () => on.messageAction(action, message)
|
|
95
96
|
}), action.icon ? icon(copied ? "check" : action.icon) : null, action.showLabel || !action.icon ? label : null);
|
|
96
97
|
}
|
|
98
|
+
function inlineView(nodes) {
|
|
99
|
+
return nodes.map((node) => {
|
|
100
|
+
switch (node.type) {
|
|
101
|
+
case "text": return node.text;
|
|
102
|
+
case "br": return h("br");
|
|
103
|
+
case "code": return h("code", {}, node.text);
|
|
104
|
+
case "strong": return h("strong", {}, ...inlineView(node.children));
|
|
105
|
+
case "em": return h("em", {}, ...inlineView(node.children));
|
|
106
|
+
case "link": return h("a", {
|
|
107
|
+
href: node.href,
|
|
108
|
+
target: "_blank",
|
|
109
|
+
rel: "noopener noreferrer nofollow"
|
|
110
|
+
}, ...inlineView(node.children));
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The blocks as elements. The caret goes inside the last block that holds
|
|
116
|
+
* text, so it sits after the last word rather than on a line of its own.
|
|
117
|
+
*/
|
|
118
|
+
function markdownView(blocks, caret) {
|
|
119
|
+
const last = blocks.length - 1;
|
|
120
|
+
return blocks.map((block, i) => {
|
|
121
|
+
const tail = i === last ? caret : null;
|
|
122
|
+
switch (block.type) {
|
|
123
|
+
case "paragraph": return h("p", {}, ...inlineView(block.children), tail);
|
|
124
|
+
case "heading": return h("p", {
|
|
125
|
+
class: "vt-chat-heading",
|
|
126
|
+
"data-level": block.level
|
|
127
|
+
}, h("strong", {}, ...inlineView(block.children)), tail);
|
|
128
|
+
case "code": return h("pre", block.language ? { "data-language": block.language } : {}, h("code", {}, block.text), tail);
|
|
129
|
+
case "quote": return h("blockquote", {}, ...markdownView(block.children, tail));
|
|
130
|
+
case "list": return h(block.ordered ? "ol" : "ul", block.ordered && block.start !== 1 ? { start: block.start } : {}, ...block.items.map((item, j) => h("li", {}, ...inlineView(item), j === block.items.length - 1 ? tail : null)));
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
97
134
|
function messageView(context, message, index) {
|
|
98
135
|
const { part, locale, on, config, ids, tabIndex } = context;
|
|
99
136
|
const side = sideOf(message.role);
|
|
@@ -103,6 +140,11 @@ function messageView(context, message, index) {
|
|
|
103
140
|
});
|
|
104
141
|
const time = timeText(message.at, locale);
|
|
105
142
|
const body = message.error ?? message.content ?? "";
|
|
143
|
+
const markdown = !message.error && !!body && (message.markdown ?? config.markdown ?? false);
|
|
144
|
+
const caret = message.streaming ? h("span", mergeAttrs({
|
|
145
|
+
key: "caret",
|
|
146
|
+
"aria-hidden": "true"
|
|
147
|
+
}, part("caret"))) : null;
|
|
106
148
|
const actions = actionsFor(config, locale, message);
|
|
107
149
|
return h("div", mergeAttrs({
|
|
108
150
|
key: String(message.id),
|
|
@@ -118,10 +160,7 @@ function messageView(context, message, index) {
|
|
|
118
160
|
onFocus: () => on.focusMessage(index)
|
|
119
161
|
}), custom !== null && custom !== void 0 ? content(custom) : [
|
|
120
162
|
message.toolCalls?.length ? h("div", mergeAttrs({ key: "tools" }, part("tools")), ...message.toolCalls.map((tool, i) => toolView(context, tool, i))) : null,
|
|
121
|
-
body || message.streaming ? h("div", mergeAttrs({ key: "bubble" }, part("bubble")
|
|
122
|
-
key: "caret",
|
|
123
|
-
"aria-hidden": "true"
|
|
124
|
-
}, part("caret"))) : null) : null,
|
|
163
|
+
body || message.streaming ? h("div", mergeAttrs({ key: "bubble" }, part("bubble"), markdown ? part("markdown") : {}), ...markdown ? markdownView(parseChatMarkdown(body), caret) : [body, caret]) : null,
|
|
125
164
|
message.attachments?.length ? h("div", mergeAttrs({ key: "files" }, part("attachments")), ...message.attachments.map((a, i) => attachmentView(context, a, i, false))) : null,
|
|
126
165
|
message.citations?.length ? h("div", mergeAttrs({ key: "cites" }, part("citations")), ...message.citations.map((c, i) => c.url ? h("a", mergeAttrs({
|
|
127
166
|
key: `c${i}`,
|
package/dist/render/chat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.js","names":[],"sources":["../../src/render/chat.ts"],"sourcesContent":["import { formatMessage, type Locale } from '@vitral/core';\nimport { h, iconNode, mergeAttrs, type Child, type Props } from '@vitral/dom';\nimport { getIcon } from '@vitral/icons';\nimport { formatSize, groupMessages, initialsOf, showsAvatars, sideOf, type ChatGroup } from '../engine/state';\nimport type { ChatAttachment, ChatConfig, ChatMessage, ChatMessageAction, ChatToolCall, ChatVariant, Content } from '../engine/types';\n\n/**\n * The conversation as plain objects: a scrolling log of runs of messages and\n * the box that adds to it. What is drawn is decided here; what happens when it\n * is pressed is the handle's.\n */\n\nconst icon = (name: string, props?: Props): Child => iconNode(getIcon(name), props);\nconst content = (value: Content): Child => (value === null || value === undefined ? null : value);\n\nexport interface ChatActions {\n send: () => void;\n draft: (text: string) => void;\n inputKeydown: (event: KeyboardEvent) => void;\n logKeydown: (event: KeyboardEvent) => void;\n focusMessage: (index: number) => void;\n retry: (message: ChatMessage) => void;\n messageAction: (action: ChatMessageAction, message: ChatMessage) => void;\n suggest: (text: string) => void;\n pickFiles: () => void;\n filesPicked: (files: File[]) => void;\n detach: (attachment: ChatAttachment, index: number) => void;\n scrolled: (element: HTMLElement) => void;\n jump: () => void;\n toggleOpen: () => void;\n}\n\nexport interface ViewContext {\n config: ChatConfig;\n locale: Locale;\n variant: ChatVariant;\n messages: ChatMessage[];\n ids: { log: string; input: string; message: (index: number) => string };\n part: (name: string, state?: unknown) => Props;\n /** The message that holds the log's tab stop. */\n tabIndex: number;\n /** The reader has scrolled away from the newest message. */\n away: boolean;\n announcement: string;\n /** The message whose text was just copied, which shows a tick for a moment. */\n copied?: string | number | null;\n on: ChatActions;\n /** Keeps the log and the composer reachable from the handle. */\n refs: { log: (el: Element | null) => void; input: (el: Element | null) => void; file: (el: Element | null) => void };\n}\n\n/** The time a message carries, in the reader's own format. */\nfunction timeText(at: ChatMessage['at'], locale: Locale): string | undefined {\n if (at === undefined || at === null) return undefined;\n const date = at instanceof Date ? at : new Date(at);\n if (Number.isNaN(date.getTime())) return undefined;\n return new Intl.DateTimeFormat(locale.code, { hour: '2-digit', minute: '2-digit' }).format(date);\n}\n\nfunction attachmentView(context: ViewContext, attachment: ChatAttachment, index: number, removable: boolean): Child {\n const { part, on, locale } = context;\n const size = formatSize(attachment.size);\n const body: Child[] = [\n icon('paperclip'),\n h('span', part('attachmentName'), attachment.name),\n size ? h('span', part('attachmentSize'), size) : null,\n removable\n ? h(\n 'button',\n mergeAttrs({ type: 'button' }, part('attachmentRemove'), {\n 'aria-label': formatMessage(locale.chat.removeAttachment, { name: attachment.name }),\n onClick: () => on.detach(attachment, index)\n }),\n icon('close')\n )\n : null\n ];\n // A file that has somewhere to go is a link; one that has not is a chip.\n return attachment.url && !removable\n ? h('a', mergeAttrs({ key: `a${index}`, href: attachment.url, target: '_blank', rel: 'noreferrer' }, part('attachment')), ...body)\n : h('span', mergeAttrs({ key: `a${index}` }, part('attachment')), ...body);\n}\n\nfunction toolView(context: ViewContext, tool: ChatToolCall, index: number): Child {\n const { part, locale } = context;\n const status = tool.status ?? 'done';\n const words = status === 'running' ? locale.chat.toolRunning : status === 'error' ? locale.chat.toolFailed : locale.chat.toolDone;\n const detail = [tool.input, tool.output].filter(Boolean).join('\\n\\n');\n return h(\n 'details',\n mergeAttrs({ key: `t${index}` }, part('tool')),\n h(\n 'summary',\n part('toolSummary'),\n icon(status === 'running' ? 'spinner' : status === 'error' ? 'warning' : 'check', status === 'running' ? { spin: true } : undefined),\n h('span', part('toolName'), tool.name),\n h('span', part('toolStatus', { status }), words)\n ),\n detail ? h('pre', part('toolBody'), detail) : null\n );\n}\n\n/** The actions a message shows: the built-in ones filled in, and only those meant for its speaker. */\nexport function actionsFor(config: ChatConfig, locale: Locale, message: ChatMessage): ChatMessageAction[] {\n if (message.streaming || message.error) return [];\n return (config.messageActions ?? [])\n .map((action): ChatMessageAction => {\n const given = typeof action === 'string' ? { id: action } : action;\n if (given.id === 'copy') return { icon: 'copy', label: locale.chat.copy, ...given };\n if (given.id === 'regenerate') return { icon: 'refresh', label: locale.chat.regenerate, ...given };\n // A rating is a toggle, pressed while the message carries it as its feedback.\n if (given.id === 'like') return { icon: 'thumbsUp', label: locale.chat.like, pressed: (m: ChatMessage) => m.feedback === 'like', ...given };\n if (given.id === 'dislike') return { icon: 'thumbsDown', label: locale.chat.dislike, pressed: (m: ChatMessage) => m.feedback === 'dislike', ...given };\n return given;\n })\n .filter((action) => (action.roles ?? ['assistant']).includes(message.role) && (action.id !== 'copy' || !!message.content));\n}\n\nfunction actionView(context: ViewContext, action: ChatMessageAction, message: ChatMessage): Child {\n const { part, on, locale } = context;\n const copied = action.id === 'copy' && context.copied === message.id;\n const label = copied ? locale.chat.copied : (action.label ?? action.id);\n const pressed = typeof action.pressed === 'function' ? action.pressed(message) : action.pressed;\n return h(\n 'button',\n mergeAttrs({ key: `a-${action.id}`, type: 'button' }, part('messageAction', { pressed: !!pressed, copied }), {\n 'aria-label': action.showLabel ? undefined : label,\n title: action.showLabel ? undefined : label,\n 'aria-pressed': pressed === undefined ? undefined : pressed ? 'true' : 'false',\n onClick: () => on.messageAction(action, message)\n }),\n action.icon ? icon(copied ? 'check' : action.icon) : null,\n action.showLabel || !action.icon ? label : null\n );\n}\n\nfunction messageView(context: ViewContext, message: ChatMessage, index: number): Child {\n const { part, locale, on, config, ids, tabIndex } = context;\n const side = sideOf(message.role);\n const custom = config.slots?.message?.({ message, index });\n const time = timeText(message.at, locale);\n const body = message.error ?? message.content ?? '';\n const actions = actionsFor(config, locale, message);\n\n return h(\n 'div',\n mergeAttrs({ key: String(message.id), id: ids.message(index) }, part('message', { side, role: message.role, error: !!message.error, streaming: !!message.streaming }), {\n role: 'listitem',\n // One tab stop for the whole log; the arrows move within it, so a\n // long thread does not bury the composer behind a hundred tabs.\n tabindex: index === tabIndex ? 0 : -1,\n onFocus: () => on.focusMessage(index)\n }),\n custom !== null && custom !== undefined\n ? content(custom)\n : [\n message.toolCalls?.length ? h('div', mergeAttrs({ key: 'tools' }, part('tools')), ...message.toolCalls.map((tool, i) => toolView(context, tool, i))) : null,\n body || message.streaming\n ? h(\n 'div',\n mergeAttrs({ key: 'bubble' }, part('bubble')),\n body,\n // The caret follows the last character while the answer arrives.\n message.streaming ? h('span', mergeAttrs({ key: 'caret', 'aria-hidden': 'true' }, part('caret'))) : null\n )\n : null,\n message.attachments?.length\n ? h('div', mergeAttrs({ key: 'files' }, part('attachments')), ...message.attachments.map((a, i) => attachmentView(context, a, i, false)))\n : null,\n message.citations?.length\n ? h(\n 'div',\n mergeAttrs({ key: 'cites' }, part('citations')),\n ...message.citations.map((c, i) =>\n c.url\n ? h('a', mergeAttrs({ key: `c${i}`, href: c.url, target: '_blank', rel: 'noreferrer' }, part('citation')), `${i + 1}. ${c.title}`)\n : h('span', mergeAttrs({ key: `c${i}` }, part('citation')), `${i + 1}. ${c.title}`)\n )\n )\n : null,\n time || message.retryable || actions.length\n ? h(\n 'div',\n mergeAttrs({ key: 'meta' }, part('meta')),\n time ? h('time', mergeAttrs({ key: 'time' }, part('time')), time) : null,\n message.retryable\n ? h('button', mergeAttrs({ key: 'retry', type: 'button' }, part('retry'), { onClick: () => on.retry(message) }), icon('refresh'), locale.chat.retry)\n : null,\n actions.length ? h('span', mergeAttrs({ key: 'actions' }, part('messageActions')), ...actions.map((a) => actionView(context, a, message))) : null\n )\n : null\n ]\n );\n}\n\nfunction groupView(context: ViewContext, group: ChatGroup): Child {\n const { part, variant } = context;\n const first = group.messages[0]!;\n const side = sideOf(first.role);\n const withAvatar = showsAvatars(variant) && first.role !== 'system';\n const author = first.author ?? (first.role === 'assistant' ? context.config.ariaLabel : undefined);\n\n return h(\n 'div',\n mergeAttrs({ key: `g${group.start}` }, part('group', { side })),\n withAvatar\n ? h(\n 'span',\n mergeAttrs({ key: 'avatar', 'aria-hidden': 'true' }, part('avatar', {})),\n first.avatar ? h('img', { src: first.avatar, alt: '' }) : initialsOf(first)\n )\n : null,\n h(\n 'div',\n mergeAttrs({ key: 'stack' }, part('stack')),\n // The name goes once a run, not once a message: that is what makes\n // a thread read as speech instead of as a list.\n author && first.role !== 'system' ? h('span', mergeAttrs({ key: 'author' }, part('author')), author) : null,\n ...group.messages.map((message, i) => messageView(context, message, group.start + i))\n )\n );\n}\n\nfunction emptyView(context: ViewContext): Child {\n const { part, config, locale, on } = context;\n const custom = config.slots?.empty?.();\n if (custom !== null && custom !== undefined) return h('div', mergeAttrs({ key: 'empty' }, part('empty')), content(custom));\n const suggestions = config.suggestions ?? [];\n return h(\n 'div',\n mergeAttrs({ key: 'empty' }, part('empty')),\n h('p', { key: 'text' }, config.emptyMessage ?? locale.chat.empty),\n suggestions.length\n ? h(\n 'div',\n mergeAttrs({ key: 'suggestions' }, part('suggestions')),\n ...suggestions.map((text, i) => h('button', mergeAttrs({ key: `s${i}`, type: 'button' }, part('suggestion'), { onClick: () => on.suggest(text) }), text))\n )\n : null\n );\n}\n\nfunction typingView(context: ViewContext): Child {\n const { part, config, locale } = context;\n if (!config.typing) return null;\n const words = typeof config.typing === 'string' ? config.typing : locale.chat.typing;\n return h(\n 'div',\n mergeAttrs({ key: 'typing' }, part('typing')),\n h('span', mergeAttrs({ key: 'dots', 'aria-hidden': 'true' }, part('typingDots')), h('span'), h('span'), h('span')),\n words\n );\n}\n\nfunction composerView(context: ViewContext): Child {\n const { part, config, locale, on, ids, refs } = context;\n if (config.readonly) return null;\n const attachments = config.attachments ?? [];\n const empty = !(config.draft ?? '').trim() && attachments.length === 0;\n return h(\n 'div',\n mergeAttrs({ key: 'composer' }, part('composer')),\n attachments.length ? h('div', mergeAttrs({ key: 'staged' }, part('attachments')), ...attachments.map((a, i) => attachmentView(context, a, i, true))) : null,\n h(\n 'div',\n mergeAttrs({ key: 'row' }, part('composerRow')),\n config.allowAttachments\n ? [\n h('input', mergeAttrs({ key: 'file', type: 'file', multiple: true, accept: config.accept }, part('file'), {\n ref: refs.file,\n onChange: (event: Event) => on.filesPicked(Array.from((event.target as HTMLInputElement).files ?? []))\n })),\n h('button', mergeAttrs({ key: 'attach', type: 'button' }, part('attach'), { 'aria-label': locale.chat.attach, disabled: config.disabled, onClick: on.pickFiles }), icon('paperclip'))\n ]\n : null,\n h('textarea', mergeAttrs({ key: 'input', id: ids.input }, part('input'), {\n ref: refs.input,\n rows: 1,\n value: config.draft ?? '',\n placeholder: config.placeholder ?? locale.chat.placeholder,\n disabled: config.disabled,\n 'aria-label': locale.chat.message,\n 'aria-controls': ids.log,\n onInput: (event: Event) => on.draft((event.target as HTMLTextAreaElement).value),\n onKeydown: on.inputKeydown\n })),\n h('button', mergeAttrs({ key: 'send', type: 'button' }, part('send'), { 'aria-label': locale.chat.send, disabled: config.disabled || empty, onClick: on.send }), icon('send'))\n )\n );\n}\n\n/** The thread: the header, the log, the composer — everything but the widget's shell. */\nexport function chatView(context: ViewContext): Child[] {\n const { part, config, locale, messages, ids, on, refs, away, announcement } = context;\n const header = config.slots?.header?.();\n const footer = config.slots?.footer?.();\n const groups = groupMessages(messages);\n\n return [\n header !== null && header !== undefined ? h('div', mergeAttrs({ key: 'header' }, part('header')), content(header)) : null,\n h(\n 'div',\n mergeAttrs({ key: 'log', id: ids.log }, part('log'), {\n ref: refs.log,\n role: 'list',\n 'aria-label': config.ariaLabel ?? locale.chat.conversation,\n tabindex: messages.length ? -1 : 0,\n style: config.height ? { height: config.height } : undefined,\n onKeydown: on.logKeydown,\n onScroll: (event: Event) => on.scrolled(event.target as HTMLElement)\n }),\n messages.length ? groups.map((group) => groupView(context, group)) : emptyView(context),\n typingView(context)\n ),\n // Going back to the newest message when the reader has scrolled off it,\n // which is the one thing an auto-scrolling log must never do for them.\n away && messages.length\n ? h('button', mergeAttrs({ key: 'jump', type: 'button' }, part('jump'), { onClick: on.jump }), icon('chevronDown'), locale.chat.newest)\n : null,\n composerView(context),\n footer !== null && footer !== undefined ? h('div', mergeAttrs({ key: 'footer' }, part('footer')), content(footer)) : null,\n // A message is announced once it has settled: a live region that changes\n // on every token of a stream says nothing anyone can follow.\n h('div', mergeAttrs({ key: 'status', role: 'status', 'aria-live': 'polite' }, part('status')), announcement)\n ];\n}\n"],"mappings":";;;;;;;;;;AAYA,IAAM,QAAQ,MAAc,UAAyB,SAAS,QAAQ,IAAI,GAAG,KAAK;AAClF,IAAM,WAAW,UAA2B,UAAU,QAAQ,UAAU,KAAA,IAAY,OAAO;;AAuC3F,SAAS,SAAS,IAAuB,QAAoC;CACzE,IAAI,OAAO,KAAA,KAAa,OAAO,MAAM,OAAO,KAAA;CAC5C,MAAM,OAAO,cAAc,OAAO,KAAK,IAAI,KAAK,EAAE;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;GAAU,MAAM;GAAU,aAAa;EAAS,GAAG,KAAK,QAAQ,CAAC,GAAG,YAAY;CAC/G;AACJ"}
|
|
1
|
+
{"version":3,"file":"chat.js","names":[],"sources":["../../src/render/chat.ts"],"sourcesContent":["import { formatMessage, type Locale } from '@vitral/core';\nimport { h, iconNode, mergeAttrs, type Child, type Props } from '@vitral/dom';\nimport { getIcon } from '@vitral/icons';\nimport { parseChatMarkdown, type ChatBlock, type ChatInline } from '../engine/markdown';\nimport { formatSize, groupMessages, initialsOf, showsAvatars, sideOf, type ChatGroup } from '../engine/state';\nimport type { ChatAttachment, ChatConfig, ChatMessage, ChatMessageAction, ChatToolCall, ChatVariant, Content } from '../engine/types';\n\n/**\n * The conversation as plain objects: a scrolling log of runs of messages and\n * the box that adds to it. What is drawn is decided here; what happens when it\n * is pressed is the handle's.\n */\n\nconst icon = (name: string, props?: Props): Child => iconNode(getIcon(name), props);\nconst content = (value: Content): Child => (value === null || value === undefined ? null : value);\n\nexport interface ChatActions {\n send: () => void;\n draft: (text: string) => void;\n inputKeydown: (event: KeyboardEvent) => void;\n logKeydown: (event: KeyboardEvent) => void;\n focusMessage: (index: number) => void;\n retry: (message: ChatMessage) => void;\n messageAction: (action: ChatMessageAction, message: ChatMessage) => void;\n suggest: (text: string) => void;\n pickFiles: () => void;\n filesPicked: (files: File[]) => void;\n detach: (attachment: ChatAttachment, index: number) => void;\n scrolled: (element: HTMLElement) => void;\n jump: () => void;\n toggleOpen: () => void;\n}\n\nexport interface ViewContext {\n config: ChatConfig;\n locale: Locale;\n variant: ChatVariant;\n messages: ChatMessage[];\n ids: { log: string; input: string; message: (index: number) => string };\n part: (name: string, state?: unknown) => Props;\n /** The message that holds the log's tab stop. */\n tabIndex: number;\n /** The reader has scrolled away from the newest message. */\n away: boolean;\n announcement: string;\n /** The message whose text was just copied, which shows a tick for a moment. */\n copied?: string | number | null;\n on: ChatActions;\n /** Keeps the log and the composer reachable from the handle. */\n refs: { log: (el: Element | null) => void; input: (el: Element | null) => void; file: (el: Element | null) => void };\n}\n\n/** The time a message carries, in the reader's own format. */\nfunction timeText(at: ChatMessage['at'], locale: Locale): string | undefined {\n if (at === undefined || at === null) return undefined;\n const date = at instanceof Date ? at : new Date(at);\n if (Number.isNaN(date.getTime())) return undefined;\n return new Intl.DateTimeFormat(locale.code, { hour: '2-digit', minute: '2-digit' }).format(date);\n}\n\nfunction attachmentView(context: ViewContext, attachment: ChatAttachment, index: number, removable: boolean): Child {\n const { part, on, locale } = context;\n const size = formatSize(attachment.size);\n const body: Child[] = [\n icon('paperclip'),\n h('span', part('attachmentName'), attachment.name),\n size ? h('span', part('attachmentSize'), size) : null,\n removable\n ? h(\n 'button',\n mergeAttrs({ type: 'button' }, part('attachmentRemove'), {\n 'aria-label': formatMessage(locale.chat.removeAttachment, { name: attachment.name }),\n onClick: () => on.detach(attachment, index)\n }),\n icon('close')\n )\n : null\n ];\n // A file that has somewhere to go is a link; one that has not is a chip.\n return attachment.url && !removable\n ? h('a', mergeAttrs({ key: `a${index}`, href: attachment.url, target: '_blank', rel: 'noreferrer' }, part('attachment')), ...body)\n : h('span', mergeAttrs({ key: `a${index}` }, part('attachment')), ...body);\n}\n\nfunction toolView(context: ViewContext, tool: ChatToolCall, index: number): Child {\n const { part, locale } = context;\n const status = tool.status ?? 'done';\n const words = status === 'running' ? locale.chat.toolRunning : status === 'error' ? locale.chat.toolFailed : locale.chat.toolDone;\n const detail = [tool.input, tool.output].filter(Boolean).join('\\n\\n');\n return h(\n 'details',\n mergeAttrs({ key: `t${index}` }, part('tool')),\n h(\n 'summary',\n part('toolSummary'),\n icon(status === 'running' ? 'spinner' : status === 'error' ? 'warning' : 'check', status === 'running' ? { spin: true } : undefined),\n h('span', part('toolName'), tool.name),\n h('span', part('toolStatus', { status }), words)\n ),\n detail ? h('pre', part('toolBody'), detail) : null\n );\n}\n\n/** The actions a message shows: the built-in ones filled in, and only those meant for its speaker. */\nexport function actionsFor(config: ChatConfig, locale: Locale, message: ChatMessage): ChatMessageAction[] {\n if (message.streaming || message.error) return [];\n return (config.messageActions ?? [])\n .map((action): ChatMessageAction => {\n const given = typeof action === 'string' ? { id: action } : action;\n if (given.id === 'copy') return { icon: 'copy', label: locale.chat.copy, ...given };\n if (given.id === 'regenerate') return { icon: 'refresh', label: locale.chat.regenerate, ...given };\n // A rating is a toggle, pressed while the message carries it as its feedback.\n if (given.id === 'like') return { icon: 'thumbsUp', label: locale.chat.like, pressed: (m: ChatMessage) => m.feedback === 'like', ...given };\n if (given.id === 'dislike') return { icon: 'thumbsDown', label: locale.chat.dislike, pressed: (m: ChatMessage) => m.feedback === 'dislike', ...given };\n return given;\n })\n .filter((action) => (action.roles ?? ['assistant']).includes(message.role) && (action.id !== 'copy' || !!message.content));\n}\n\nfunction actionView(context: ViewContext, action: ChatMessageAction, message: ChatMessage): Child {\n const { part, on, locale } = context;\n const copied = action.id === 'copy' && context.copied === message.id;\n const label = copied ? locale.chat.copied : (action.label ?? action.id);\n const pressed = typeof action.pressed === 'function' ? action.pressed(message) : action.pressed;\n return h(\n 'button',\n mergeAttrs({ key: `a-${action.id}`, type: 'button' }, part('messageAction', { pressed: !!pressed, copied }), {\n 'aria-label': action.showLabel ? undefined : label,\n title: action.showLabel ? undefined : label,\n 'aria-pressed': pressed === undefined ? undefined : pressed ? 'true' : 'false',\n onClick: () => on.messageAction(action, message)\n }),\n action.icon ? icon(copied ? 'check' : action.icon) : null,\n action.showLabel || !action.icon ? label : null\n );\n}\n\nfunction inlineView(nodes: ChatInline[]): Child[] {\n return nodes.map((node) => {\n switch (node.type) {\n case 'text':\n return node.text;\n case 'br':\n return h('br');\n case 'code':\n return h('code', {}, node.text);\n case 'strong':\n return h('strong', {}, ...inlineView(node.children));\n case 'em':\n return h('em', {}, ...inlineView(node.children));\n case 'link':\n return h('a', { href: node.href, target: '_blank', rel: 'noopener noreferrer nofollow' }, ...inlineView(node.children));\n }\n });\n}\n\n/**\n * The blocks as elements. The caret goes inside the last block that holds\n * text, so it sits after the last word rather than on a line of its own.\n */\nfunction markdownView(blocks: ChatBlock[], caret: Child): Child[] {\n const last = blocks.length - 1;\n return blocks.map((block, i) => {\n const tail = i === last ? caret : null;\n switch (block.type) {\n case 'paragraph':\n return h('p', {}, ...inlineView(block.children), tail);\n case 'heading':\n // A heading inside a message must not outrank the page's own.\n return h('p', { class: 'vt-chat-heading', 'data-level': block.level }, h('strong', {}, ...inlineView(block.children)), tail);\n case 'code':\n return h('pre', block.language ? { 'data-language': block.language } : {}, h('code', {}, block.text), tail);\n case 'quote':\n return h('blockquote', {}, ...markdownView(block.children, tail));\n case 'list':\n return h(\n block.ordered ? 'ol' : 'ul',\n block.ordered && block.start !== 1 ? { start: block.start } : {},\n ...block.items.map((item, j) => h('li', {}, ...inlineView(item), j === block.items.length - 1 ? tail : null))\n );\n }\n });\n}\n\nfunction messageView(context: ViewContext, message: ChatMessage, index: number): Child {\n const { part, locale, on, config, ids, tabIndex } = context;\n const side = sideOf(message.role);\n const custom = config.slots?.message?.({ message, index });\n const time = timeText(message.at, locale);\n const body = message.error ?? message.content ?? '';\n const markdown = !message.error && !!body && (message.markdown ?? config.markdown ?? false);\n // The caret follows the last character while the answer arrives.\n const caret = message.streaming ? h('span', mergeAttrs({ key: 'caret', 'aria-hidden': 'true' }, part('caret'))) : null;\n const actions = actionsFor(config, locale, message);\n\n return h(\n 'div',\n mergeAttrs({ key: String(message.id), id: ids.message(index) }, part('message', { side, role: message.role, error: !!message.error, streaming: !!message.streaming }), {\n role: 'listitem',\n // One tab stop for the whole log; the arrows move within it, so a\n // long thread does not bury the composer behind a hundred tabs.\n tabindex: index === tabIndex ? 0 : -1,\n onFocus: () => on.focusMessage(index)\n }),\n custom !== null && custom !== undefined\n ? content(custom)\n : [\n message.toolCalls?.length ? h('div', mergeAttrs({ key: 'tools' }, part('tools')), ...message.toolCalls.map((tool, i) => toolView(context, tool, i))) : null,\n body || message.streaming\n ? h(\n 'div',\n mergeAttrs({ key: 'bubble' }, part('bubble'), markdown ? part('markdown') : {}),\n ...(markdown ? markdownView(parseChatMarkdown(body), caret) : [body, caret])\n )\n : null,\n message.attachments?.length\n ? h('div', mergeAttrs({ key: 'files' }, part('attachments')), ...message.attachments.map((a, i) => attachmentView(context, a, i, false)))\n : null,\n message.citations?.length\n ? h(\n 'div',\n mergeAttrs({ key: 'cites' }, part('citations')),\n ...message.citations.map((c, i) =>\n c.url\n ? h('a', mergeAttrs({ key: `c${i}`, href: c.url, target: '_blank', rel: 'noreferrer' }, part('citation')), `${i + 1}. ${c.title}`)\n : h('span', mergeAttrs({ key: `c${i}` }, part('citation')), `${i + 1}. ${c.title}`)\n )\n )\n : null,\n time || message.retryable || actions.length\n ? h(\n 'div',\n mergeAttrs({ key: 'meta' }, part('meta')),\n time ? h('time', mergeAttrs({ key: 'time' }, part('time')), time) : null,\n message.retryable\n ? h('button', mergeAttrs({ key: 'retry', type: 'button' }, part('retry'), { onClick: () => on.retry(message) }), icon('refresh'), locale.chat.retry)\n : null,\n actions.length ? h('span', mergeAttrs({ key: 'actions' }, part('messageActions')), ...actions.map((a) => actionView(context, a, message))) : null\n )\n : null\n ]\n );\n}\n\nfunction groupView(context: ViewContext, group: ChatGroup): Child {\n const { part, variant } = context;\n const first = group.messages[0]!;\n const side = sideOf(first.role);\n const withAvatar = showsAvatars(variant) && first.role !== 'system';\n const author = first.author ?? (first.role === 'assistant' ? context.config.ariaLabel : undefined);\n\n return h(\n 'div',\n mergeAttrs({ key: `g${group.start}` }, part('group', { side })),\n withAvatar\n ? h(\n 'span',\n mergeAttrs({ key: 'avatar', 'aria-hidden': 'true' }, part('avatar', {})),\n first.avatar ? h('img', { src: first.avatar, alt: '' }) : initialsOf(first)\n )\n : null,\n h(\n 'div',\n mergeAttrs({ key: 'stack' }, part('stack')),\n // The name goes once a run, not once a message: that is what makes\n // a thread read as speech instead of as a list.\n author && first.role !== 'system' ? h('span', mergeAttrs({ key: 'author' }, part('author')), author) : null,\n ...group.messages.map((message, i) => messageView(context, message, group.start + i))\n )\n );\n}\n\nfunction emptyView(context: ViewContext): Child {\n const { part, config, locale, on } = context;\n const custom = config.slots?.empty?.();\n if (custom !== null && custom !== undefined) return h('div', mergeAttrs({ key: 'empty' }, part('empty')), content(custom));\n const suggestions = config.suggestions ?? [];\n return h(\n 'div',\n mergeAttrs({ key: 'empty' }, part('empty')),\n h('p', { key: 'text' }, config.emptyMessage ?? locale.chat.empty),\n suggestions.length\n ? h(\n 'div',\n mergeAttrs({ key: 'suggestions' }, part('suggestions')),\n ...suggestions.map((text, i) => h('button', mergeAttrs({ key: `s${i}`, type: 'button' }, part('suggestion'), { onClick: () => on.suggest(text) }), text))\n )\n : null\n );\n}\n\nfunction typingView(context: ViewContext): Child {\n const { part, config, locale } = context;\n if (!config.typing) return null;\n const words = typeof config.typing === 'string' ? config.typing : locale.chat.typing;\n return h(\n 'div',\n mergeAttrs({ key: 'typing' }, part('typing')),\n h('span', mergeAttrs({ key: 'dots', 'aria-hidden': 'true' }, part('typingDots')), h('span'), h('span'), h('span')),\n words\n );\n}\n\nfunction composerView(context: ViewContext): Child {\n const { part, config, locale, on, ids, refs } = context;\n if (config.readonly) return null;\n const attachments = config.attachments ?? [];\n const empty = !(config.draft ?? '').trim() && attachments.length === 0;\n return h(\n 'div',\n mergeAttrs({ key: 'composer' }, part('composer')),\n attachments.length ? h('div', mergeAttrs({ key: 'staged' }, part('attachments')), ...attachments.map((a, i) => attachmentView(context, a, i, true))) : null,\n h(\n 'div',\n mergeAttrs({ key: 'row' }, part('composerRow')),\n config.allowAttachments\n ? [\n h('input', mergeAttrs({ key: 'file', type: 'file', multiple: true, accept: config.accept }, part('file'), {\n ref: refs.file,\n onChange: (event: Event) => on.filesPicked(Array.from((event.target as HTMLInputElement).files ?? []))\n })),\n h('button', mergeAttrs({ key: 'attach', type: 'button' }, part('attach'), { 'aria-label': locale.chat.attach, disabled: config.disabled, onClick: on.pickFiles }), icon('paperclip'))\n ]\n : null,\n h('textarea', mergeAttrs({ key: 'input', id: ids.input }, part('input'), {\n ref: refs.input,\n rows: 1,\n value: config.draft ?? '',\n placeholder: config.placeholder ?? locale.chat.placeholder,\n disabled: config.disabled,\n 'aria-label': locale.chat.message,\n 'aria-controls': ids.log,\n onInput: (event: Event) => on.draft((event.target as HTMLTextAreaElement).value),\n onKeydown: on.inputKeydown\n })),\n h('button', mergeAttrs({ key: 'send', type: 'button' }, part('send'), { 'aria-label': locale.chat.send, disabled: config.disabled || empty, onClick: on.send }), icon('send'))\n )\n );\n}\n\n/** The thread: the header, the log, the composer — everything but the widget's shell. */\nexport function chatView(context: ViewContext): Child[] {\n const { part, config, locale, messages, ids, on, refs, away, announcement } = context;\n const header = config.slots?.header?.();\n const footer = config.slots?.footer?.();\n const groups = groupMessages(messages);\n\n return [\n header !== null && header !== undefined ? h('div', mergeAttrs({ key: 'header' }, part('header')), content(header)) : null,\n h(\n 'div',\n mergeAttrs({ key: 'log', id: ids.log }, part('log'), {\n ref: refs.log,\n role: 'list',\n 'aria-label': config.ariaLabel ?? locale.chat.conversation,\n tabindex: messages.length ? -1 : 0,\n style: config.height ? { height: config.height } : undefined,\n onKeydown: on.logKeydown,\n onScroll: (event: Event) => on.scrolled(event.target as HTMLElement)\n }),\n messages.length ? groups.map((group) => groupView(context, group)) : emptyView(context),\n typingView(context)\n ),\n // Going back to the newest message when the reader has scrolled off it,\n // which is the one thing an auto-scrolling log must never do for them.\n away && messages.length\n ? h('button', mergeAttrs({ key: 'jump', type: 'button' }, part('jump'), { onClick: on.jump }), icon('chevronDown'), locale.chat.newest)\n : null,\n composerView(context),\n footer !== null && footer !== undefined ? h('div', mergeAttrs({ key: 'footer' }, part('footer')), content(footer)) : null,\n // A message is announced once it has settled: a live region that changes\n // on every token of a stream says nothing anyone can follow.\n h('div', mergeAttrs({ key: 'status', role: 'status', 'aria-live': 'polite' }, part('status')), announcement)\n ];\n}\n"],"mappings":";;;;;;;;;;;AAaA,IAAM,QAAQ,MAAc,UAAyB,SAAS,QAAQ,IAAI,GAAG,KA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K;GACjC,OAAO,OAAO,SAAS,EAAE,QAAQ,OAAO,OAAO,IAAI,KAAA;GACnD,WAAW,GAAG;GACd,WAAW,UAAiB,GAAG,SAAS,MAAM,MAAqB;EACvE,CAAC,GACD,SAAS,SAAS,OAAO,KAAK,UAAU,UAAU,SAAS,KAAK,CAAC,IAAI,UAAU,OAAO,GACtF,WAAW,OAAO,CACtB;EAGA,QAAQ,SAAS,SACX,EAAE,UAAU,WAAW;GAAE,KAAK;GAAQ,MAAM;EAAS,GAAG,KAAK,MAAM,GAAG,EAAE,SAAS,GAAG,KAAK,CAAC,GAAG,KAAK,aAAa,GAAG,OAAO,KAAK,MAAM,IACpI;EACN,aAAa,OAAO;EACpB,WAAW,QAAQ,WAAW,KAAA,IAAY,EAAE,OAAO,WAAW,EAAE,KAAK,SAAS,GAAG,KAAK,QAAQ,CAAC,GAAG,QAAQ,MAAM,CAAC,IAAI;EAGrH,EAAE,OAAO,WAAW;GAAE,KAAK;GAAU,MAAM;GAAU,aAAa;EAAS,GAAG,KAAK,QAAQ,CAAC,GAAG,YAAY;CAC/G;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitral/chat",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "Framework-free chat for Vitral: the engine (messages, grouping, streaming, the composer) and a DOM renderer with roving focus and live announcements, which the Vue, React and Angular components wrap.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vitral",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@vitral/controls": "0.2.
|
|
49
|
-
"@vitral/core": "0.2.
|
|
50
|
-
"@vitral/
|
|
51
|
-
"@vitral/
|
|
52
|
-
"@vitral/styles": "0.2.
|
|
48
|
+
"@vitral/controls": "0.2.8",
|
|
49
|
+
"@vitral/core": "0.2.8",
|
|
50
|
+
"@vitral/icons": "0.2.8",
|
|
51
|
+
"@vitral/dom": "0.2.8",
|
|
52
|
+
"@vitral/styles": "0.2.8"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "vite build && tsc -p tsconfig.build.json"
|