@scalio-cloud/ui 0.72.0 → 0.73.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/README.md +13 -0
- package/nav.css +6 -2
- package/package.json +1 -1
- package/react/ai.js +27 -7
- package/react/markdown.js +23 -7
package/README.md
CHANGED
|
@@ -670,6 +670,16 @@ shows `AiCredits` (bar, warning from 80 %, note at 100 %). `AiHelp` is «Frag Sc
|
|
|
670
670
|
whose `onAsk` returns `{text, sources: [{title, source, url}]}`; `AiPanel` shows such sources too. Test IDs
|
|
671
671
|
`ai-scalio`, `ai-credits`, `ai-credits-text`, `ai-credits-note`, `ai-help`, `ai-help-sources-<n>`.
|
|
672
672
|
|
|
673
|
+
Since 0.73.0 (BL-332, scalio-infra #757) `AiSuggestion` (the `text`) and `AiPanel`/`AiHelp` (the answers) show
|
|
674
|
+
AI text as safe Markdown, no longer as raw text with `##`, `**` and backticks: headings, bold, italic, lists, inline
|
|
675
|
+
code and code blocks, paragraphs, tables and callouts. The text is parsed into React elements (the `Markdown` block
|
|
676
|
+
with `links="https"` and `anchors={false}`), never HTML: `<script>`, `<img onerror>` and other HTML stay visible as
|
|
677
|
+
text; links work only with `https://` (no `javascript:`, `data:`, `http:`, `mailto:` or relative addresses); images
|
|
678
|
+
stay text; headings get no id. Questions and error messages stay plain text. `format="text"` on `AiSuggestion` or
|
|
679
|
+
`AiPanel` keeps the old display (text as it is, line breaks kept). `AiText` shows any AI text the same way:
|
|
680
|
+
`<AiText text={answer} lang={lang} testId="explain-text" />` (`format`, `className`). Source links (`sources[].url`)
|
|
681
|
+
work only with https or a path of the app (`/help/...`), else only the title is shown.
|
|
682
|
+
|
|
673
683
|
## Benachrichtigungen: E-Mail-Versand und E-Mail-Vorlagen (React)
|
|
674
684
|
|
|
675
685
|
Since 0.29.0 (ADR 0069 W5) every app sends mail the same way. The server side is scalio-platform 0.8.0 `mail`
|
|
@@ -749,6 +759,9 @@ markdownOutline(page.body) // [{ level, text, id }] for a table of contents; h
|
|
|
749
759
|
`labels` overrides the callout titles (`{ note, tip, important, warning, caution }`). Also exported:
|
|
750
760
|
`parseMarkdownBlocks`, `parseMarkdownInline`, `markdownHeadingId`, `safeHref`. Test IDs: `callout-<kind>`.
|
|
751
761
|
|
|
762
|
+
From 0.73.0: `links="https"` makes only https addresses links (images stay text) and `anchors={false}` leaves the
|
|
763
|
+
headings without an id; `AiText` uses both for AI text. Also exported: `safeHttpsHref`.
|
|
764
|
+
|
|
752
765
|
From 0.70.0: `pageLinks` reads `[[Title]]`, `[[KEY:Title]]` and `[[Title|text]]` as page links (shown as text with a
|
|
753
766
|
dotted line, `.scalio-md-pagelink`, unless the app renders them). `render={{ image, link, pagelink }}` puts the app's
|
|
754
767
|
own elements in: `image(node, key)`, `link(node, key, children)`, `pagelink(node, key)`; a function that returns
|
package/nav.css
CHANGED
|
@@ -910,7 +910,11 @@ ul.scalio-notice { flex-direction: column; gap: 0.25rem; padding-left: 2rem; lis
|
|
|
910
910
|
.dark .scalio-ai-badge, .dark .scalio-ai-btn .scalio-icon { color: #8ba6f7; }
|
|
911
911
|
.scalio-ai-suggestion { display: flex; flex-direction: column; gap: 0.5rem; padding: 0.875rem 1rem; border: 1px solid hsl(var(--primary) / 0.3); border-left-width: 3px; border-radius: var(--radius, 4px); background: hsl(var(--card)); }
|
|
912
912
|
.scalio-ai-suggestion-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
|
|
913
|
-
.scalio-ai-suggestion-text {
|
|
913
|
+
.scalio-ai-suggestion-text { font-size: 0.875rem; }
|
|
914
|
+
.scalio-ai-text.is-plain { white-space: pre-wrap; }
|
|
915
|
+
.scalio-ai-text.scalio-md > * + * { margin-top: 0.5rem; }
|
|
916
|
+
.scalio-ai-text .scalio-md-h1, .scalio-ai-text .scalio-md-h2 { font-size: 1rem; line-height: 1.5rem; padding-top: 0.25rem; }
|
|
917
|
+
.scalio-ai-text .scalio-md-h3, .scalio-ai-text .scalio-md-h4 { font-size: 0.875rem; padding-top: 0; }
|
|
914
918
|
.scalio-ai-suggestion-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
|
|
915
919
|
.scalio-ai-feature { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.5rem 0; }
|
|
916
920
|
.scalio-ai-feature + .scalio-ai-feature { border-top: 1px solid hsl(var(--border)); }
|
|
@@ -932,7 +936,7 @@ ul.scalio-notice { flex-direction: column; gap: 0.25rem; padding-left: 2rem; lis
|
|
|
932
936
|
.scalio-ai-turn { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.875rem; }
|
|
933
937
|
.scalio-ai-turn.is-user { align-self: flex-end; max-width: 85%; padding: 0.5rem 0.75rem; border-radius: var(--radius, 4px); background: hsl(var(--muted)); }
|
|
934
938
|
.scalio-ai-turn.is-error .scalio-ai-turn-text { color: hsl(var(--destructive)); }
|
|
935
|
-
.scalio-ai-turn-text { white-space: pre-wrap; }
|
|
939
|
+
.scalio-ai-turn-text:not(.scalio-md) { white-space: pre-wrap; }
|
|
936
940
|
.scalio-ai-panel-form { display: flex; gap: 0.5rem; align-items: flex-end; }
|
|
937
941
|
.scalio-ai-panel-form textarea { flex: 1; resize: vertical; }
|
|
938
942
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scalio-cloud/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.73.0",
|
|
4
4
|
"description": "Scalio Control Room design tokens, Tailwind preset, self-hosted fonts, the shared app header, sign-in layout, sidebar and page blocks",
|
|
5
5
|
"license": "SEE LICENSE IN README.md",
|
|
6
6
|
"private": false,
|
package/react/ai.js
CHANGED
|
@@ -6,11 +6,13 @@
|
|
|
6
6
|
// - AiBadge: marks text the AI wrote
|
|
7
7
|
// - AiSuggestion: a proposal with reason and source; «Übernehmen», «Bearbeiten», «Verwerfen» (never runs by itself)
|
|
8
8
|
// - AiPanel: side panel «Assistent» with the context of the open page
|
|
9
|
+
// - AiText: a text of the AI as safe Markdown (React elements, never HTML; links only https); format="text" as is
|
|
9
10
|
const React = require("react");
|
|
10
11
|
const h = React.createElement;
|
|
11
12
|
const Icons = require("./icons");
|
|
12
13
|
const { SettingsSection, SettingsField: Field, SettingsRow } = require("./settings");
|
|
13
14
|
const { askConfirm } = require("./dialog");
|
|
15
|
+
const { Markdown, safeHref } = require("./markdown");
|
|
14
16
|
|
|
15
17
|
const PROVIDERS = ["scalio", "openai", "anthropic", "gemini", "ollama"];
|
|
16
18
|
const KEY_PROVIDERS = ["openai", "anthropic", "gemini"];
|
|
@@ -381,7 +383,23 @@ function AiBadge(props) {
|
|
|
381
383
|
h(Icons.Sparkles, { className: "scalio-icon" }), L.badge);
|
|
382
384
|
}
|
|
383
385
|
|
|
384
|
-
//
|
|
386
|
+
// Text the AI wrote: Markdown with headings, bold, italic, lists, code and https links (BL-332, scalio-infra #757);
|
|
387
|
+
// no HTML from the text, no other links, no images, headings without an id. format="text": the text as it is.
|
|
388
|
+
function AiText(props) {
|
|
389
|
+
const cls = props.className ? ` ${props.className}` : "";
|
|
390
|
+
if (props.format === "text") return h("div", { className: `scalio-ai-text is-plain${cls}`, "data-testid": props.testId }, String(props.text ?? ""));
|
|
391
|
+
return h(Markdown, { text: String(props.text ?? ""), lang: props.lang, links: "https", anchors: false,
|
|
392
|
+
className: `scalio-ai-text${cls}`, testId: props.testId });
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// A source link of an answer: https or a path of the app, else only its title.
|
|
396
|
+
function sourceHref(url) {
|
|
397
|
+
const href = safeHref(url);
|
|
398
|
+
return href && (/^https:\/\//i.test(href) || href.startsWith("/")) ? href : null;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// Props: suggestion ({title, text, reason, risk, source}), onAccept, onEdit, onReject (each optional), busy, lang, labels, testId,
|
|
402
|
+
// format ("markdown", default, or "text").
|
|
385
403
|
// The app runs its normal action in onAccept, with the person's rights and an audit entry (ADR 0111 K3).
|
|
386
404
|
function AiSuggestion(props) {
|
|
387
405
|
const L = labels(props.lang, props.labels);
|
|
@@ -394,7 +412,7 @@ function AiSuggestion(props) {
|
|
|
394
412
|
h("div", { className: "scalio-ai-suggestion-head" }, h(AiBadge, { lang: props.lang, labels: props.labels, testId: `${tid}-badge` }),
|
|
395
413
|
s.title ? h("strong", null, s.title) : null,
|
|
396
414
|
risk ? h("span", { className: `scalio-badge ${risk === "high" ? "is-error" : risk === "medium" ? "is-warn" : "is-ok"}`, "data-testid": `${tid}-risk` }, L.risk[risk]) : null),
|
|
397
|
-
s.text ? h(
|
|
415
|
+
s.text ? h(AiText, { text: s.text, format: props.format, lang: props.lang, className: "scalio-ai-suggestion-text", testId: `${tid}-text` }) : null,
|
|
398
416
|
s.reason ? h("div", { className: "scalio-settings-help" }, `${L.reason}: ${s.reason}`) : null,
|
|
399
417
|
s.source ? h("div", { className: "scalio-settings-help", "data-testid": `${tid}-source` }, `${L.source}: ${s.source}`) : null,
|
|
400
418
|
h("div", { className: "scalio-ai-suggestion-actions" },
|
|
@@ -402,7 +420,7 @@ function AiSuggestion(props) {
|
|
|
402
420
|
}
|
|
403
421
|
|
|
404
422
|
// Props: open, onClose, context (name of the open page or object), onAsk(question, history) -> Promise<string>,
|
|
405
|
-
// lang, labels, testId. History is kept while the panel lives; nothing is stored.
|
|
423
|
+
// lang, labels, testId, format ("markdown", default, or "text" for the answers). History is kept while the panel lives; nothing is stored.
|
|
406
424
|
function AiPanel(props) {
|
|
407
425
|
const L = labels(props.lang, props.labels);
|
|
408
426
|
const [turns, setTurns] = React.useState([]);
|
|
@@ -442,11 +460,13 @@ function AiPanel(props) {
|
|
|
442
460
|
h("div", { className: "scalio-ai-panel-turns", "aria-live": "polite", "data-testid": `${tid}-turns` },
|
|
443
461
|
turns.length ? turns.map((t, i) => h("div", { key: i, className: `scalio-ai-turn is-${t.role}${t.error ? " is-error" : ""}` },
|
|
444
462
|
t.role === "assistant" && !t.error ? h(AiBadge, { lang: props.lang, labels: props.labels, testId: `${tid}-badge-${i}` }) : null,
|
|
445
|
-
|
|
463
|
+
t.role === "assistant" && !t.error
|
|
464
|
+
? h(AiText, { text: t.content, format: props.format, lang: props.lang, className: "scalio-ai-turn-text" })
|
|
465
|
+
: h("div", { className: "scalio-ai-turn-text" }, t.content),
|
|
446
466
|
t.sources && t.sources.length ? h("div", { className: "scalio-ai-sources", "data-testid": `${tid}-sources-${i}` },
|
|
447
467
|
h("span", null, `${L.helpSources}: `),
|
|
448
|
-
t.sources.map((src, j) => h("span", { key: j, className: "scalio-ai-source" }, src.url
|
|
449
|
-
? h("a", { href: src.url, target: "_blank", rel: "noreferrer" }, src.title || src.source) : (src.title || src.source)))) : null))
|
|
468
|
+
t.sources.map((src, j) => h("span", { key: j, className: "scalio-ai-source" }, sourceHref(src.url)
|
|
469
|
+
? h("a", { href: sourceHref(src.url), target: "_blank", rel: "noopener noreferrer" }, src.title || src.source) : (src.title || src.source)))) : null))
|
|
450
470
|
: h("p", { className: "scalio-settings-help" }, props.emptyText || L.panelEmpty),
|
|
451
471
|
busy ? h("div", { className: "scalio-ai-turn is-assistant", "data-testid": `${tid}-busy` }, h("span", { className: "scalio-spinner", "aria-hidden": "true" }), L.working) : null),
|
|
452
472
|
h("form", { className: "scalio-ai-panel-form", onSubmit: ask },
|
|
@@ -462,4 +482,4 @@ function AiHelp(props) {
|
|
|
462
482
|
return h(AiPanel, Object.assign({ testId: "ai-help", title: L.helpTitle, emptyText: L.helpEmpty }, props));
|
|
463
483
|
}
|
|
464
484
|
|
|
465
|
-
module.exports = { AiSettingsPanel, AiHelp, AiCredits, AiButton, AiBadge, AiSuggestion, AiPanel, aiApi, aiForm, aiPatch, AI_LABELS: LABELS, AI_LEVELS: LEVELS };
|
|
485
|
+
module.exports = { AiSettingsPanel, AiHelp, AiCredits, AiButton, AiBadge, AiSuggestion, AiPanel, AiText, aiApi, aiForm, aiPatch, AI_LABELS: LABELS, AI_LEVELS: LEVELS };
|
package/react/markdown.js
CHANGED
|
@@ -19,6 +19,12 @@ function safeHref(href) {
|
|
|
19
19
|
return h || null;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
// AI texts (links="https"): only https addresses become links.
|
|
23
|
+
function safeHttpsHref(href) {
|
|
24
|
+
const h = String(href || "").trim();
|
|
25
|
+
return /^https:\/\/[^\s/]/i.test(h) ? h : null;
|
|
26
|
+
}
|
|
27
|
+
|
|
22
28
|
function splitRow(line) {
|
|
23
29
|
let s = line.trim();
|
|
24
30
|
if (s.startsWith("|")) s = s.slice(1);
|
|
@@ -143,8 +149,11 @@ const INLINE = new RegExp(INLINE_SRC, "g");
|
|
|
143
149
|
const INLINE_PAGES = new RegExp(INLINE_SRC + "|\\[\\[([^[\\]\\n]+)\\]\\]", "g");
|
|
144
150
|
|
|
145
151
|
// opts.pageLinks: [[...]] becomes {type: "pagelink", space, title, label} (else it stays text).
|
|
152
|
+
// opts.httpsOnly (AI texts): links only with https, images stay text.
|
|
146
153
|
function parseInline(src, opts) {
|
|
147
154
|
const pages = !!(opts && opts.pageLinks);
|
|
155
|
+
const httpsOnly = !!(opts && opts.httpsOnly);
|
|
156
|
+
const linkHref = httpsOnly ? safeHttpsHref : safeHref;
|
|
148
157
|
const out = [];
|
|
149
158
|
const text = String(src || "");
|
|
150
159
|
let last = 0;
|
|
@@ -152,14 +161,15 @@ function parseInline(src, opts) {
|
|
|
152
161
|
if (m.index > last) out.push({ type: "text", text: text.slice(last, m.index) });
|
|
153
162
|
if (m[1]) out.push({ type: "code", text: m[2].trim() ? m[2].replace(/^ (.*) $/, "$1") : m[2] });
|
|
154
163
|
else if (m[4] !== undefined) {
|
|
155
|
-
const href = safeHref(m[4]);
|
|
164
|
+
const href = httpsOnly ? null : safeHref(m[4]);
|
|
156
165
|
out.push(href ? { type: "image", alt: m[3], href } : { type: "text", text: m[0] });
|
|
157
166
|
} else if (m[6] !== undefined) {
|
|
158
|
-
const href =
|
|
167
|
+
const href = linkHref(m[6]);
|
|
159
168
|
out.push(href ? { type: "link", href, children: parseInline(m[5], opts) } : { type: "text", text: m[5] });
|
|
160
169
|
} else if (m[7] !== undefined || m[8] !== undefined) out.push({ type: "bold", children: parseInline(m[7] ?? m[8], opts) });
|
|
161
170
|
else if (m[9] !== undefined) out.push({ type: "strike", children: parseInline(m[9], opts) });
|
|
162
171
|
else if (m[10] !== undefined || m[11] !== undefined) out.push({ type: "italic", children: parseInline(m[10] ?? m[11], opts) });
|
|
172
|
+
else if (m[12] && httpsOnly && !safeHttpsHref(m[12])) out.push({ type: "text", text: m[12] });
|
|
163
173
|
else if (m[12]) out.push({ type: "link", href: m[12], children: [{ type: "text", text: m[12] }] });
|
|
164
174
|
else if (m[13] !== undefined) {
|
|
165
175
|
const link = parsePageLink(m[13]);
|
|
@@ -204,7 +214,7 @@ function pageLinks(src) {
|
|
|
204
214
|
|
|
205
215
|
// The app's own elements (props.render): image(node, key), link(node, key, children), pagelink(node, key). A function
|
|
206
216
|
// that returns undefined leaves the building block's own element.
|
|
207
|
-
const Ctx = React.createContext({ render: {}, opts: null });
|
|
217
|
+
const Ctx = React.createContext({ render: {}, opts: null, anchors: true });
|
|
208
218
|
|
|
209
219
|
function own(ctx, kind, args) {
|
|
210
220
|
const fn = ctx.render && ctx.render[kind];
|
|
@@ -266,8 +276,9 @@ const CALLOUT_ICON = { note: "Info", tip: "Info", important: "Info", warning: "A
|
|
|
266
276
|
|
|
267
277
|
function Blocks(props) {
|
|
268
278
|
const L = props.labels;
|
|
279
|
+
const anchors = React.useContext(Ctx).anchors;
|
|
269
280
|
return h(React.Fragment, null, props.blocks.map((b, i) => {
|
|
270
|
-
if (b.type === "heading") return h("h" + b.level, { key: i, id: headingId(b.text), className: "scalio-md-h" + b.level }, inline(b.text));
|
|
281
|
+
if (b.type === "heading") return h("h" + b.level, { key: i, id: anchors ? headingId(b.text) : undefined, className: "scalio-md-h" + b.level }, inline(b.text));
|
|
271
282
|
if (b.type === "code") return h("pre", { key: i, "data-lang": b.lang || undefined, className: "scalio-md-pre" }, b.text);
|
|
272
283
|
if (b.type === "rule") return h("hr", { key: i, className: "scalio-md-rule" });
|
|
273
284
|
if (b.type === "list") return h(List, { key: i, list: b });
|
|
@@ -290,11 +301,15 @@ function Blocks(props) {
|
|
|
290
301
|
|
|
291
302
|
// <Markdown text="..." lang="de" /> shows the text; labels.markdown overrides the callout titles. pageLinks reads
|
|
292
303
|
// [[...]] as page links; render = {image, link, pagelink} puts the app's own elements in (Folio: images of the space,
|
|
293
|
-
// router links, resolved page links).
|
|
304
|
+
// router links, resolved page links). links="https" (AI texts): only https links, images stay text; anchors={false}:
|
|
305
|
+
// headings without an id (several answers on one page).
|
|
294
306
|
function Markdown(props) {
|
|
295
307
|
const L = Object.assign({}, labelsFor(props.lang).markdown, props.labels);
|
|
296
|
-
const
|
|
297
|
-
|
|
308
|
+
const httpsOnly = props.links === "https";
|
|
309
|
+
const ctx = React.useMemo(() => {
|
|
310
|
+
const opts = props.pageLinks || httpsOnly ? { pageLinks: !!props.pageLinks, httpsOnly } : null;
|
|
311
|
+
return { render: props.render || {}, opts, anchors: props.anchors !== false };
|
|
312
|
+
}, [props.render, props.pageLinks, httpsOnly, props.anchors]);
|
|
298
313
|
return h(Ctx.Provider, { value: ctx },
|
|
299
314
|
h("div", { className: "scalio-md" + (props.className ? " " + props.className : ""), "data-testid": props.testId },
|
|
300
315
|
h(Blocks, { blocks: parseBlocks(props.text), labels: L })));
|
|
@@ -310,4 +325,5 @@ module.exports = {
|
|
|
310
325
|
markdownPageLinkKey: pageLinkKey,
|
|
311
326
|
parseMarkdownPageLink: parsePageLink,
|
|
312
327
|
safeHref,
|
|
328
|
+
safeHttpsHref,
|
|
313
329
|
};
|