@burdenoff/microfe-healthybowl 2026.627.1 → 2026.628.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,35 +1,32 @@
|
|
|
1
1
|
import { useTr as e } from "../../shared/hooks/useTr.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { sanitizeUrl as t } from "../../utils/sanitizeUrl.js";
|
|
3
|
+
import { useMemo as n, useState as r } from "react";
|
|
4
|
+
import { Check as i, Copy as a } from "lucide-react";
|
|
5
|
+
import { Fragment as o, jsx as s, jsxs as c } from "react/jsx-runtime";
|
|
5
6
|
//#region src/components/assistant/AssistantMarkdownRenderer.tsx
|
|
6
|
-
function
|
|
7
|
-
let
|
|
8
|
-
return
|
|
9
|
-
}
|
|
10
|
-
function l({ language: t, code: c }) {
|
|
11
|
-
let l = e(), [u, d] = n(!1);
|
|
12
|
-
return /* @__PURE__ */ s("div", {
|
|
7
|
+
function l({ language: t, code: n }) {
|
|
8
|
+
let l = e(), [u, d] = r(!1);
|
|
9
|
+
return /* @__PURE__ */ c("div", {
|
|
13
10
|
className: "group relative my-2 rounded-md bg-bg-sunken border border-border-default overflow-hidden",
|
|
14
|
-
children: [/* @__PURE__ */
|
|
11
|
+
children: [/* @__PURE__ */ c("div", {
|
|
15
12
|
className: "flex items-center justify-between px-3 py-1.5 bg-bg-elevated border-b border-border-default",
|
|
16
|
-
children: [/* @__PURE__ */
|
|
13
|
+
children: [/* @__PURE__ */ s("span", {
|
|
17
14
|
className: "text-[10px] font-mono text-text-muted uppercase tracking-wider",
|
|
18
15
|
children: t || "code"
|
|
19
|
-
}), /* @__PURE__ */
|
|
16
|
+
}), /* @__PURE__ */ s("button", {
|
|
20
17
|
type: "button",
|
|
21
18
|
onClick: () => {
|
|
22
|
-
navigator.clipboard.writeText(
|
|
19
|
+
navigator.clipboard.writeText(n), d(!0), setTimeout(() => d(!1), 2e3);
|
|
23
20
|
},
|
|
24
21
|
className: "flex items-center gap-1 px-1.5 py-0.5 text-[10px] text-text-secondary hover:text-text-primary hover:bg-bg-sunken rounded transition-colors",
|
|
25
22
|
"aria-label": l("healthybowl.assistant.markdown.copyCode", "Copy code"),
|
|
26
|
-
children: u ? /* @__PURE__ */
|
|
23
|
+
children: u ? /* @__PURE__ */ c(o, { children: [/* @__PURE__ */ s(i, { className: "size-3 text-status-success-text" }), /* @__PURE__ */ s("span", { children: l("healthybowl.assistant.markdown.copied", "Copied") })] }) : /* @__PURE__ */ c(o, { children: [/* @__PURE__ */ s(a, { className: "size-3" }), /* @__PURE__ */ s("span", { children: l("healthybowl.assistant.markdown.copy", "Copy") })] })
|
|
27
24
|
})]
|
|
28
|
-
}), /* @__PURE__ */
|
|
25
|
+
}), /* @__PURE__ */ s("pre", {
|
|
29
26
|
className: "p-3 overflow-x-auto text-xs leading-relaxed",
|
|
30
|
-
children: /* @__PURE__ */
|
|
27
|
+
children: /* @__PURE__ */ s("code", {
|
|
31
28
|
className: "font-mono text-text-primary",
|
|
32
|
-
children:
|
|
29
|
+
children: n
|
|
33
30
|
})
|
|
34
31
|
})]
|
|
35
32
|
});
|
|
@@ -70,97 +67,97 @@ function u(e) {
|
|
|
70
67
|
return t;
|
|
71
68
|
}
|
|
72
69
|
function d(e) {
|
|
73
|
-
let
|
|
74
|
-
for (;
|
|
75
|
-
let e =
|
|
70
|
+
let n = [], r = e, i = 0;
|
|
71
|
+
for (; r.length > 0;) {
|
|
72
|
+
let e = r.match(/\*\*(.+?)\*\*/), a = r.match(/`([^`]+)`/), o = r.match(/\[([^\]]+)\]\(([^)]+)\)/), c = r.match(/(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)/), l = [
|
|
76
73
|
e && {
|
|
77
74
|
type: "bold",
|
|
78
75
|
match: e,
|
|
79
76
|
index: e.index
|
|
80
77
|
},
|
|
81
|
-
i && {
|
|
82
|
-
type: "code",
|
|
83
|
-
match: i,
|
|
84
|
-
index: i.index
|
|
85
|
-
},
|
|
86
78
|
a && {
|
|
87
|
-
type: "
|
|
79
|
+
type: "code",
|
|
88
80
|
match: a,
|
|
89
81
|
index: a.index
|
|
90
82
|
},
|
|
91
|
-
|
|
83
|
+
o && {
|
|
84
|
+
type: "link",
|
|
85
|
+
match: o,
|
|
86
|
+
index: o.index
|
|
87
|
+
},
|
|
88
|
+
c && {
|
|
92
89
|
type: "italic",
|
|
93
|
-
match:
|
|
94
|
-
index:
|
|
90
|
+
match: c,
|
|
91
|
+
index: c.index
|
|
95
92
|
}
|
|
96
93
|
].filter(Boolean);
|
|
97
94
|
if (l.length === 0) {
|
|
98
|
-
|
|
95
|
+
n.push(r);
|
|
99
96
|
break;
|
|
100
97
|
}
|
|
101
98
|
l.sort((e, t) => e.index - t.index);
|
|
102
99
|
let u = l[0];
|
|
103
|
-
switch (u.index > 0 &&
|
|
100
|
+
switch (u.index > 0 && n.push(r.slice(0, u.index)), u.type) {
|
|
104
101
|
case "bold":
|
|
105
|
-
|
|
102
|
+
n.push(/* @__PURE__ */ s("strong", {
|
|
106
103
|
className: "font-semibold",
|
|
107
104
|
children: u.match[1]
|
|
108
|
-
},
|
|
105
|
+
}, i++)), r = r.slice(u.index + u.match[0].length);
|
|
109
106
|
break;
|
|
110
107
|
case "code":
|
|
111
|
-
|
|
108
|
+
n.push(/* @__PURE__ */ s("code", {
|
|
112
109
|
className: "px-1 py-0.5 bg-bg-sunken text-text-primary rounded text-[0.85em] font-mono",
|
|
113
110
|
children: u.match[1]
|
|
114
|
-
},
|
|
111
|
+
}, i++)), r = r.slice(u.index + u.match[0].length);
|
|
115
112
|
break;
|
|
116
113
|
case "link":
|
|
117
|
-
|
|
118
|
-
href:
|
|
114
|
+
n.push(/* @__PURE__ */ s("a", {
|
|
115
|
+
href: t(u.match[2]),
|
|
119
116
|
target: "_blank",
|
|
120
117
|
rel: "noopener noreferrer",
|
|
121
118
|
className: "text-action-primary-bg hover:underline",
|
|
122
119
|
children: u.match[1]
|
|
123
|
-
},
|
|
120
|
+
}, i++)), r = r.slice(u.index + u.match[0].length);
|
|
124
121
|
break;
|
|
125
122
|
case "italic":
|
|
126
|
-
|
|
123
|
+
n.push(/* @__PURE__ */ s("em", {
|
|
127
124
|
className: "italic",
|
|
128
125
|
children: u.match[1]
|
|
129
|
-
},
|
|
126
|
+
}, i++)), r = r.slice(u.index + u.match[0].length);
|
|
130
127
|
break;
|
|
131
128
|
}
|
|
132
129
|
}
|
|
133
|
-
return
|
|
130
|
+
return n;
|
|
134
131
|
}
|
|
135
132
|
function f({ content: e }) {
|
|
136
|
-
return /* @__PURE__ */ o
|
|
133
|
+
return /* @__PURE__ */ s(o, { children: e.split("\n").map((e, t) => {
|
|
137
134
|
let n = e.trimStart();
|
|
138
|
-
if (n.startsWith("### ")) return /* @__PURE__ */
|
|
135
|
+
if (n.startsWith("### ")) return /* @__PURE__ */ s("h4", {
|
|
139
136
|
className: "text-sm font-semibold text-text-primary mt-3 mb-1",
|
|
140
137
|
children: d(n.slice(4))
|
|
141
138
|
}, t);
|
|
142
|
-
if (n.startsWith("## ")) return /* @__PURE__ */
|
|
139
|
+
if (n.startsWith("## ")) return /* @__PURE__ */ s("h3", {
|
|
143
140
|
className: "text-sm font-bold text-text-primary mt-3 mb-1",
|
|
144
141
|
children: d(n.slice(3))
|
|
145
142
|
}, t);
|
|
146
|
-
if (n.startsWith("# ")) return /* @__PURE__ */
|
|
143
|
+
if (n.startsWith("# ")) return /* @__PURE__ */ s("h2", {
|
|
147
144
|
className: "text-base font-bold text-text-primary mt-3 mb-1",
|
|
148
145
|
children: d(n.slice(2))
|
|
149
146
|
}, t);
|
|
150
|
-
if (/^[-*_]{3,}$/.test(n)) return /* @__PURE__ */
|
|
151
|
-
if (n.startsWith("> ")) return /* @__PURE__ */
|
|
147
|
+
if (/^[-*_]{3,}$/.test(n)) return /* @__PURE__ */ s("hr", { className: "my-2 border-border-default" }, t);
|
|
148
|
+
if (n.startsWith("> ")) return /* @__PURE__ */ s("blockquote", {
|
|
152
149
|
className: "border-l-2 border-action-primary-bg pl-3 text-text-secondary italic my-1",
|
|
153
150
|
children: d(n.slice(2))
|
|
154
151
|
}, t);
|
|
155
|
-
if (/^[-*] /.test(n)) return /* @__PURE__ */
|
|
152
|
+
if (/^[-*] /.test(n)) return /* @__PURE__ */ s("li", {
|
|
156
153
|
className: "ml-4 list-disc text-text-primary",
|
|
157
154
|
children: d(n.slice(2))
|
|
158
155
|
}, t);
|
|
159
156
|
let r = n.match(/^(\d+)\.\s/);
|
|
160
|
-
return r ? /* @__PURE__ */
|
|
157
|
+
return r ? /* @__PURE__ */ s("li", {
|
|
161
158
|
className: "ml-4 list-decimal text-text-primary",
|
|
162
159
|
children: d(n.slice(r[0].length))
|
|
163
|
-
}, t) : n === "" ? /* @__PURE__ */
|
|
160
|
+
}, t) : n === "" ? /* @__PURE__ */ s("div", { className: "h-1.5" }, t) : /* @__PURE__ */ s("p", {
|
|
164
161
|
className: "text-text-primary leading-relaxed",
|
|
165
162
|
children: d(e)
|
|
166
163
|
}, t);
|
|
@@ -170,19 +167,19 @@ function p({ content: e }) {
|
|
|
170
167
|
let t = e.split("\n").filter(Boolean);
|
|
171
168
|
if (t.length < 2) return null;
|
|
172
169
|
let n = (e) => e.split("|").map((e) => e.trim()).filter(Boolean), r = n(t[0]), i = t.slice(2).map(n);
|
|
173
|
-
return /* @__PURE__ */
|
|
170
|
+
return /* @__PURE__ */ s("div", {
|
|
174
171
|
className: "my-2 overflow-x-auto",
|
|
175
|
-
children: /* @__PURE__ */
|
|
172
|
+
children: /* @__PURE__ */ c("table", {
|
|
176
173
|
className: "text-xs w-full border-collapse",
|
|
177
|
-
children: [/* @__PURE__ */
|
|
174
|
+
children: [/* @__PURE__ */ s("thead", { children: /* @__PURE__ */ s("tr", {
|
|
178
175
|
className: "border-b border-border-default",
|
|
179
|
-
children: r.map((e, t) => /* @__PURE__ */
|
|
176
|
+
children: r.map((e, t) => /* @__PURE__ */ s("th", {
|
|
180
177
|
className: "text-left px-2 py-1.5 font-semibold text-text-primary",
|
|
181
178
|
children: d(e)
|
|
182
179
|
}, t))
|
|
183
|
-
}) }), /* @__PURE__ */
|
|
180
|
+
}) }), /* @__PURE__ */ s("tbody", { children: i.map((e, t) => /* @__PURE__ */ s("tr", {
|
|
184
181
|
className: "border-b border-border-subtle",
|
|
185
|
-
children: e.map((e, t) => /* @__PURE__ */
|
|
182
|
+
children: e.map((e, t) => /* @__PURE__ */ s("td", {
|
|
186
183
|
className: "px-2 py-1.5 text-text-primary",
|
|
187
184
|
children: d(e)
|
|
188
185
|
}, t))
|
|
@@ -190,16 +187,16 @@ function p({ content: e }) {
|
|
|
190
187
|
})
|
|
191
188
|
});
|
|
192
189
|
}
|
|
193
|
-
var m = ({ content: e }) => /* @__PURE__ */
|
|
190
|
+
var m = ({ content: e }) => /* @__PURE__ */ s("div", {
|
|
194
191
|
className: "text-xs leading-relaxed space-y-0.5",
|
|
195
|
-
children:
|
|
192
|
+
children: n(() => u(e), [e]).map((e) => {
|
|
196
193
|
switch (e.type) {
|
|
197
|
-
case "code": return /* @__PURE__ */
|
|
194
|
+
case "code": return /* @__PURE__ */ s(l, {
|
|
198
195
|
language: e.language || "",
|
|
199
196
|
code: e.content
|
|
200
197
|
}, e.key);
|
|
201
|
-
case "table": return /* @__PURE__ */
|
|
202
|
-
default: return /* @__PURE__ */
|
|
198
|
+
case "table": return /* @__PURE__ */ s(p, { content: e.content }, e.key);
|
|
199
|
+
default: return /* @__PURE__ */ s(f, { content: e.content }, e.key);
|
|
203
200
|
}
|
|
204
201
|
})
|
|
205
202
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssistantMarkdownRenderer.js","names":[],"sources":["../../../src/components/assistant/AssistantMarkdownRenderer.tsx"],"sourcesContent":["/**\n * Lightweight markdown renderer for assistant messages.\n *\n * Handles: headings, bold, italic, code blocks, inline code, links,\n * lists, blockquotes, tables, and horizontal rules using regex parsing.\n * No external dependencies — avoids adding react-markdown to the MFE.\n */\n\nimport React, { useMemo, useState, type FC } from 'react';\nimport { Copy, Check } from 'lucide-react';\nimport { useTr } from '../../shared/hooks/useTr';\n\ninterface Props {\n content: string;\n}\n\n// Block executable URL schemes (javascript:, data:, vbscript:) in links rendered\n// from assistant output — a prompt-injected response could otherwise produce a\n// click-to-execute link. Browsers ignore whitespace/control chars inside a\n// scheme, so strip those before testing. Allow http(s)/mailto/tel + relative.\nfunction sanitizeUrl(url: string): string {\n const scheme = url.replace(/\\s+/g, '').toLowerCase();\n if (/^(?:javascript|data|vbscript):/.test(scheme)) return '#';\n return url.trim();\n}\n\nfunction CodeBlock({ language, code }: { language: string; code: string }) {\n const tr = useTr();\n const [copied, setCopied] = useState(false);\n\n const handleCopy = () => {\n navigator.clipboard.writeText(code);\n setCopied(true);\n setTimeout(() => setCopied(false), 2000);\n };\n\n return (\n <div className=\"group relative my-2 rounded-md bg-bg-sunken border border-border-default overflow-hidden\">\n <div className=\"flex items-center justify-between px-3 py-1.5 bg-bg-elevated border-b border-border-default\">\n <span className=\"text-[10px] font-mono text-text-muted uppercase tracking-wider\">{language || 'code'}</span>\n <button\n type=\"button\"\n onClick={handleCopy}\n className=\"flex items-center gap-1 px-1.5 py-0.5 text-[10px] text-text-secondary hover:text-text-primary hover:bg-bg-sunken rounded transition-colors\"\n aria-label={tr('healthybowl.assistant.markdown.copyCode', 'Copy code')}\n >\n {copied ? (\n <>\n <Check className=\"size-3 text-status-success-text\" />\n <span>{tr('healthybowl.assistant.markdown.copied', 'Copied')}</span>\n </>\n ) : (\n <>\n <Copy className=\"size-3\" />\n <span>{tr('healthybowl.assistant.markdown.copy', 'Copy')}</span>\n </>\n )}\n </button>\n </div>\n <pre className=\"p-3 overflow-x-auto text-xs leading-relaxed\">\n <code className=\"font-mono text-text-primary\">{code}</code>\n </pre>\n </div>\n );\n}\n\ninterface ParsedBlock {\n type: 'text' | 'code' | 'table';\n content: string;\n language?: string;\n key: number;\n}\n\nfunction parseBlocks(content: string): ParsedBlock[] {\n const blocks: ParsedBlock[] = [];\n let key = 0;\n\n // Split by code blocks first\n const parts = content.split(/(```[\\s\\S]*?```)/g);\n\n for (const part of parts) {\n const codeMatch = part.match(/^```(\\w*)\\n?([\\s\\S]*?)```$/);\n if (codeMatch) {\n blocks.push({\n type: 'code',\n language: codeMatch[1],\n content: codeMatch[2].trimEnd(),\n key: key++,\n });\n } else if (part.trim()) {\n // Check for tables\n const lines = part.split('\\n');\n let i = 0;\n let textBuffer = '';\n\n while (i < lines.length) {\n // Detect table: line with pipes followed by separator line\n if (lines[i].includes('|') && i + 1 < lines.length && /^\\|?[\\s-:|]+\\|/.test(lines[i + 1])) {\n if (textBuffer.trim()) {\n blocks.push({ type: 'text', content: textBuffer.trim(), key: key++ });\n textBuffer = '';\n }\n let tableContent = '';\n while (i < lines.length && lines[i].includes('|')) {\n tableContent += lines[i] + '\\n';\n i++;\n }\n blocks.push({ type: 'table', content: tableContent.trim(), key: key++ });\n } else {\n textBuffer += lines[i] + '\\n';\n i++;\n }\n }\n\n if (textBuffer.trim()) {\n blocks.push({ type: 'text', content: textBuffer.trim(), key: key++ });\n }\n }\n }\n\n return blocks;\n}\n\nfunction renderInlineMarkdown(text: string): (string | React.JSX.Element)[] {\n const result: (string | React.JSX.Element)[] = [];\n let remaining = text;\n let key = 0;\n\n while (remaining.length > 0) {\n // Bold\n const boldMatch = remaining.match(/\\*\\*(.+?)\\*\\*/);\n // Inline code\n const codeMatch = remaining.match(/`([^`]+)`/);\n // Link\n const linkMatch = remaining.match(/\\[([^\\]]+)\\]\\(([^)]+)\\)/);\n // Italic\n const italicMatch = remaining.match(/(?<!\\*)\\*(?!\\*)(.+?)(?<!\\*)\\*(?!\\*)/);\n\n // Find the earliest match\n const matches = [\n boldMatch && { type: 'bold', match: boldMatch, index: boldMatch.index! },\n codeMatch && { type: 'code', match: codeMatch, index: codeMatch.index! },\n linkMatch && { type: 'link', match: linkMatch, index: linkMatch.index! },\n italicMatch && { type: 'italic', match: italicMatch, index: italicMatch.index! },\n ].filter(Boolean) as Array<{ type: string; match: RegExpMatchArray; index: number }>;\n\n if (matches.length === 0) {\n result.push(remaining);\n break;\n }\n\n matches.sort((a, b) => a.index - b.index);\n const earliest = matches[0];\n\n // Add text before the match\n if (earliest.index > 0) {\n result.push(remaining.slice(0, earliest.index));\n }\n\n switch (earliest.type) {\n case 'bold':\n result.push(\n <strong key={key++} className=\"font-semibold\">\n {earliest.match[1]}\n </strong>\n );\n remaining = remaining.slice(earliest.index + earliest.match[0].length);\n break;\n case 'code':\n result.push(\n <code key={key++} className=\"px-1 py-0.5 bg-bg-sunken text-text-primary rounded text-[0.85em] font-mono\">\n {earliest.match[1]}\n </code>\n );\n remaining = remaining.slice(earliest.index + earliest.match[0].length);\n break;\n case 'link':\n result.push(\n <a\n key={key++}\n href={sanitizeUrl(earliest.match[2])}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"text-action-primary-bg hover:underline\"\n >\n {earliest.match[1]}\n </a>\n );\n remaining = remaining.slice(earliest.index + earliest.match[0].length);\n break;\n case 'italic':\n result.push(\n <em key={key++} className=\"italic\">\n {earliest.match[1]}\n </em>\n );\n remaining = remaining.slice(earliest.index + earliest.match[0].length);\n break;\n }\n }\n\n return result;\n}\n\nfunction TextBlock({ content }: { content: string }) {\n const lines = content.split('\\n');\n\n return (\n <>\n {lines.map((line, i) => {\n const trimmed = line.trimStart();\n\n // Headings\n if (trimmed.startsWith('### '))\n return (\n <h4 key={i} className=\"text-sm font-semibold text-text-primary mt-3 mb-1\">\n {renderInlineMarkdown(trimmed.slice(4))}\n </h4>\n );\n if (trimmed.startsWith('## '))\n return (\n <h3 key={i} className=\"text-sm font-bold text-text-primary mt-3 mb-1\">\n {renderInlineMarkdown(trimmed.slice(3))}\n </h3>\n );\n if (trimmed.startsWith('# '))\n return (\n <h2 key={i} className=\"text-base font-bold text-text-primary mt-3 mb-1\">\n {renderInlineMarkdown(trimmed.slice(2))}\n </h2>\n );\n\n // Horizontal rule\n if (/^[-*_]{3,}$/.test(trimmed)) return <hr key={i} className=\"my-2 border-border-default\" />;\n\n // Blockquote\n if (trimmed.startsWith('> '))\n return (\n <blockquote key={i} className=\"border-l-2 border-action-primary-bg pl-3 text-text-secondary italic my-1\">\n {renderInlineMarkdown(trimmed.slice(2))}\n </blockquote>\n );\n\n // Unordered list\n if (/^[-*] /.test(trimmed))\n return (\n <li key={i} className=\"ml-4 list-disc text-text-primary\">\n {renderInlineMarkdown(trimmed.slice(2))}\n </li>\n );\n\n // Ordered list\n const olMatch = trimmed.match(/^(\\d+)\\.\\s/);\n if (olMatch)\n return (\n <li key={i} className=\"ml-4 list-decimal text-text-primary\">\n {renderInlineMarkdown(trimmed.slice(olMatch[0].length))}\n </li>\n );\n\n // Empty line\n if (trimmed === '') return <div key={i} className=\"h-1.5\" />;\n\n // Regular paragraph\n return (\n <p key={i} className=\"text-text-primary leading-relaxed\">\n {renderInlineMarkdown(line)}\n </p>\n );\n })}\n </>\n );\n}\n\nfunction TableBlock({ content }: { content: string }) {\n const rows = content.split('\\n').filter(Boolean);\n if (rows.length < 2) return null;\n\n const parseRow = (row: string) =>\n row\n .split('|')\n .map((c) => c.trim())\n .filter(Boolean);\n\n const headers = parseRow(rows[0]);\n // Skip separator row (index 1)\n const bodyRows = rows.slice(2).map(parseRow);\n\n return (\n <div className=\"my-2 overflow-x-auto\">\n <table className=\"text-xs w-full border-collapse\">\n <thead>\n <tr className=\"border-b border-border-default\">\n {headers.map((h, i) => (\n <th key={i} className=\"text-left px-2 py-1.5 font-semibold text-text-primary\">\n {renderInlineMarkdown(h)}\n </th>\n ))}\n </tr>\n </thead>\n <tbody>\n {bodyRows.map((row, ri) => (\n <tr key={ri} className=\"border-b border-border-subtle\">\n {row.map((cell, ci) => (\n <td key={ci} className=\"px-2 py-1.5 text-text-primary\">\n {renderInlineMarkdown(cell)}\n </td>\n ))}\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n );\n}\n\nexport const AssistantMarkdownRenderer: FC<Props> = ({ content }) => {\n const blocks = useMemo(() => parseBlocks(content), [content]);\n\n return (\n <div className=\"text-xs leading-relaxed space-y-0.5\">\n {blocks.map((block) => {\n switch (block.type) {\n case 'code':\n return <CodeBlock key={block.key} language={block.language || ''} code={block.content} />;\n case 'table':\n return <TableBlock key={block.key} content={block.content} />;\n default:\n return <TextBlock key={block.key} content={block.content} />;\n }\n })}\n </div>\n );\n};\n"],"mappings":";;;;;AAoBA,SAAS,EAAY,GAAqB;CACxC,IAAM,IAAS,EAAI,QAAQ,QAAQ,GAAG,CAAC,aAAa;AAEpD,QADI,iCAAiC,KAAK,EAAO,GAAS,MACnD,EAAI,MAAM;;AAGnB,SAAS,EAAU,EAAE,aAAU,WAA4C;CACzE,IAAM,IAAK,GAAO,EACZ,CAAC,GAAQ,KAAa,EAAS,GAAM;AAQ3C,QACE,kBAAC,OAAD;EAAK,WAAU;YAAf,CACE,kBAAC,OAAD;GAAK,WAAU;aAAf,CACE,kBAAC,QAAD;IAAM,WAAU;cAAkE,KAAY;IAAc,CAAA,EAC5G,kBAAC,UAAD;IACE,MAAK;IACL,eAZiB;AAGvB,KAFA,UAAU,UAAU,UAAU,EAAK,EACnC,EAAU,GAAK,EACf,iBAAiB,EAAU,GAAM,EAAE,IAAK;;IAUlC,WAAU;IACV,cAAY,EAAG,2CAA2C,YAAY;cAErE,IACC,kBAAA,GAAA,EAAA,UAAA,CACE,kBAAC,GAAD,EAAO,WAAU,mCAAoC,CAAA,EACrD,kBAAC,QAAD,EAAA,UAAO,EAAG,yCAAyC,SAAS,EAAQ,CAAA,CACnE,EAAA,CAAA,GAEH,kBAAA,GAAA,EAAA,UAAA,CACE,kBAAC,GAAD,EAAM,WAAU,UAAW,CAAA,EAC3B,kBAAC,QAAD,EAAA,UAAO,EAAG,uCAAuC,OAAO,EAAQ,CAAA,CAC/D,EAAA,CAAA;IAEE,CAAA,CACL;MACN,kBAAC,OAAD;GAAK,WAAU;aACb,kBAAC,QAAD;IAAM,W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":"AssistantMarkdownRenderer.js","names":[],"sources":["../../../src/components/assistant/AssistantMarkdownRenderer.tsx"],"sourcesContent":["/**\n * Lightweight markdown renderer for assistant messages.\n *\n * Handles: headings, bold, italic, code blocks, inline code, links,\n * lists, blockquotes, tables, and horizontal rules using regex parsing.\n * No external dependencies — avoids adding react-markdown to the MFE.\n */\n\nimport React, { useMemo, useState, type FC } from 'react';\nimport { Copy, Check } from 'lucide-react';\nimport { useTr } from '../../shared/hooks/useTr';\nimport { sanitizeUrl } from '@/utils/sanitizeUrl';\n\ninterface Props {\n content: string;\n}\n\nfunction CodeBlock({ language, code }: { language: string; code: string }) {\n const tr = useTr();\n const [copied, setCopied] = useState(false);\n\n const handleCopy = () => {\n navigator.clipboard.writeText(code);\n setCopied(true);\n setTimeout(() => setCopied(false), 2000);\n };\n\n return (\n <div className=\"group relative my-2 rounded-md bg-bg-sunken border border-border-default overflow-hidden\">\n <div className=\"flex items-center justify-between px-3 py-1.5 bg-bg-elevated border-b border-border-default\">\n <span className=\"text-[10px] font-mono text-text-muted uppercase tracking-wider\">{language || 'code'}</span>\n <button\n type=\"button\"\n onClick={handleCopy}\n className=\"flex items-center gap-1 px-1.5 py-0.5 text-[10px] text-text-secondary hover:text-text-primary hover:bg-bg-sunken rounded transition-colors\"\n aria-label={tr('healthybowl.assistant.markdown.copyCode', 'Copy code')}\n >\n {copied ? (\n <>\n <Check className=\"size-3 text-status-success-text\" />\n <span>{tr('healthybowl.assistant.markdown.copied', 'Copied')}</span>\n </>\n ) : (\n <>\n <Copy className=\"size-3\" />\n <span>{tr('healthybowl.assistant.markdown.copy', 'Copy')}</span>\n </>\n )}\n </button>\n </div>\n <pre className=\"p-3 overflow-x-auto text-xs leading-relaxed\">\n <code className=\"font-mono text-text-primary\">{code}</code>\n </pre>\n </div>\n );\n}\n\ninterface ParsedBlock {\n type: 'text' | 'code' | 'table';\n content: string;\n language?: string;\n key: number;\n}\n\nfunction parseBlocks(content: string): ParsedBlock[] {\n const blocks: ParsedBlock[] = [];\n let key = 0;\n\n // Split by code blocks first\n const parts = content.split(/(```[\\s\\S]*?```)/g);\n\n for (const part of parts) {\n const codeMatch = part.match(/^```(\\w*)\\n?([\\s\\S]*?)```$/);\n if (codeMatch) {\n blocks.push({\n type: 'code',\n language: codeMatch[1],\n content: codeMatch[2].trimEnd(),\n key: key++,\n });\n } else if (part.trim()) {\n // Check for tables\n const lines = part.split('\\n');\n let i = 0;\n let textBuffer = '';\n\n while (i < lines.length) {\n // Detect table: line with pipes followed by separator line\n if (lines[i].includes('|') && i + 1 < lines.length && /^\\|?[\\s-:|]+\\|/.test(lines[i + 1])) {\n if (textBuffer.trim()) {\n blocks.push({ type: 'text', content: textBuffer.trim(), key: key++ });\n textBuffer = '';\n }\n let tableContent = '';\n while (i < lines.length && lines[i].includes('|')) {\n tableContent += lines[i] + '\\n';\n i++;\n }\n blocks.push({ type: 'table', content: tableContent.trim(), key: key++ });\n } else {\n textBuffer += lines[i] + '\\n';\n i++;\n }\n }\n\n if (textBuffer.trim()) {\n blocks.push({ type: 'text', content: textBuffer.trim(), key: key++ });\n }\n }\n }\n\n return blocks;\n}\n\nfunction renderInlineMarkdown(text: string): (string | React.JSX.Element)[] {\n const result: (string | React.JSX.Element)[] = [];\n let remaining = text;\n let key = 0;\n\n while (remaining.length > 0) {\n // Bold\n const boldMatch = remaining.match(/\\*\\*(.+?)\\*\\*/);\n // Inline code\n const codeMatch = remaining.match(/`([^`]+)`/);\n // Link\n const linkMatch = remaining.match(/\\[([^\\]]+)\\]\\(([^)]+)\\)/);\n // Italic\n const italicMatch = remaining.match(/(?<!\\*)\\*(?!\\*)(.+?)(?<!\\*)\\*(?!\\*)/);\n\n // Find the earliest match\n const matches = [\n boldMatch && { type: 'bold', match: boldMatch, index: boldMatch.index! },\n codeMatch && { type: 'code', match: codeMatch, index: codeMatch.index! },\n linkMatch && { type: 'link', match: linkMatch, index: linkMatch.index! },\n italicMatch && { type: 'italic', match: italicMatch, index: italicMatch.index! },\n ].filter(Boolean) as Array<{ type: string; match: RegExpMatchArray; index: number }>;\n\n if (matches.length === 0) {\n result.push(remaining);\n break;\n }\n\n matches.sort((a, b) => a.index - b.index);\n const earliest = matches[0];\n\n // Add text before the match\n if (earliest.index > 0) {\n result.push(remaining.slice(0, earliest.index));\n }\n\n switch (earliest.type) {\n case 'bold':\n result.push(\n <strong key={key++} className=\"font-semibold\">\n {earliest.match[1]}\n </strong>\n );\n remaining = remaining.slice(earliest.index + earliest.match[0].length);\n break;\n case 'code':\n result.push(\n <code key={key++} className=\"px-1 py-0.5 bg-bg-sunken text-text-primary rounded text-[0.85em] font-mono\">\n {earliest.match[1]}\n </code>\n );\n remaining = remaining.slice(earliest.index + earliest.match[0].length);\n break;\n case 'link':\n result.push(\n <a\n key={key++}\n href={sanitizeUrl(earliest.match[2])}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"text-action-primary-bg hover:underline\"\n >\n {earliest.match[1]}\n </a>\n );\n remaining = remaining.slice(earliest.index + earliest.match[0].length);\n break;\n case 'italic':\n result.push(\n <em key={key++} className=\"italic\">\n {earliest.match[1]}\n </em>\n );\n remaining = remaining.slice(earliest.index + earliest.match[0].length);\n break;\n }\n }\n\n return result;\n}\n\nfunction TextBlock({ content }: { content: string }) {\n const lines = content.split('\\n');\n\n return (\n <>\n {lines.map((line, i) => {\n const trimmed = line.trimStart();\n\n // Headings\n if (trimmed.startsWith('### '))\n return (\n <h4 key={i} className=\"text-sm font-semibold text-text-primary mt-3 mb-1\">\n {renderInlineMarkdown(trimmed.slice(4))}\n </h4>\n );\n if (trimmed.startsWith('## '))\n return (\n <h3 key={i} className=\"text-sm font-bold text-text-primary mt-3 mb-1\">\n {renderInlineMarkdown(trimmed.slice(3))}\n </h3>\n );\n if (trimmed.startsWith('# '))\n return (\n <h2 key={i} className=\"text-base font-bold text-text-primary mt-3 mb-1\">\n {renderInlineMarkdown(trimmed.slice(2))}\n </h2>\n );\n\n // Horizontal rule\n if (/^[-*_]{3,}$/.test(trimmed)) return <hr key={i} className=\"my-2 border-border-default\" />;\n\n // Blockquote\n if (trimmed.startsWith('> '))\n return (\n <blockquote key={i} className=\"border-l-2 border-action-primary-bg pl-3 text-text-secondary italic my-1\">\n {renderInlineMarkdown(trimmed.slice(2))}\n </blockquote>\n );\n\n // Unordered list\n if (/^[-*] /.test(trimmed))\n return (\n <li key={i} className=\"ml-4 list-disc text-text-primary\">\n {renderInlineMarkdown(trimmed.slice(2))}\n </li>\n );\n\n // Ordered list\n const olMatch = trimmed.match(/^(\\d+)\\.\\s/);\n if (olMatch)\n return (\n <li key={i} className=\"ml-4 list-decimal text-text-primary\">\n {renderInlineMarkdown(trimmed.slice(olMatch[0].length))}\n </li>\n );\n\n // Empty line\n if (trimmed === '') return <div key={i} className=\"h-1.5\" />;\n\n // Regular paragraph\n return (\n <p key={i} className=\"text-text-primary leading-relaxed\">\n {renderInlineMarkdown(line)}\n </p>\n );\n })}\n </>\n );\n}\n\nfunction TableBlock({ content }: { content: string }) {\n const rows = content.split('\\n').filter(Boolean);\n if (rows.length < 2) return null;\n\n const parseRow = (row: string) =>\n row\n .split('|')\n .map((c) => c.trim())\n .filter(Boolean);\n\n const headers = parseRow(rows[0]);\n // Skip separator row (index 1)\n const bodyRows = rows.slice(2).map(parseRow);\n\n return (\n <div className=\"my-2 overflow-x-auto\">\n <table className=\"text-xs w-full border-collapse\">\n <thead>\n <tr className=\"border-b border-border-default\">\n {headers.map((h, i) => (\n <th key={i} className=\"text-left px-2 py-1.5 font-semibold text-text-primary\">\n {renderInlineMarkdown(h)}\n </th>\n ))}\n </tr>\n </thead>\n <tbody>\n {bodyRows.map((row, ri) => (\n <tr key={ri} className=\"border-b border-border-subtle\">\n {row.map((cell, ci) => (\n <td key={ci} className=\"px-2 py-1.5 text-text-primary\">\n {renderInlineMarkdown(cell)}\n </td>\n ))}\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n );\n}\n\nexport const AssistantMarkdownRenderer: FC<Props> = ({ content }) => {\n const blocks = useMemo(() => parseBlocks(content), [content]);\n\n return (\n <div className=\"text-xs leading-relaxed space-y-0.5\">\n {blocks.map((block) => {\n switch (block.type) {\n case 'code':\n return <CodeBlock key={block.key} language={block.language || ''} code={block.content} />;\n case 'table':\n return <TableBlock key={block.key} content={block.content} />;\n default:\n return <TextBlock key={block.key} content={block.content} />;\n }\n })}\n </div>\n );\n};\n"],"mappings":";;;;;;AAiBA,SAAS,EAAU,EAAE,aAAU,WAA4C;CACzE,IAAM,IAAK,GAAO,EACZ,CAAC,GAAQ,KAAa,EAAS,GAAM;AAQ3C,QACE,kBAAC,OAAD;EAAK,WAAU;YAAf,CACE,kBAAC,OAAD;GAAK,WAAU;aAAf,CACE,kBAAC,QAAD;IAAM,WAAU;cAAkE,KAAY;IAAc,CAAA,EAC5G,kBAAC,UAAD;IACE,MAAK;IACL,eAZiB;AAGvB,KAFA,UAAU,UAAU,UAAU,EAAK,EACnC,EAAU,GAAK,EACf,iBAAiB,EAAU,GAAM,EAAE,IAAK;;IAUlC,WAAU;IACV,cAAY,EAAG,2CAA2C,YAAY;cAErE,IACC,kBAAA,GAAA,EAAA,UAAA,CACE,kBAAC,GAAD,EAAO,WAAU,mCAAoC,CAAA,EACrD,kBAAC,QAAD,EAAA,UAAO,EAAG,yCAAyC,SAAS,EAAQ,CAAA,CACnE,EAAA,CAAA,GAEH,kBAAA,GAAA,EAAA,UAAA,CACE,kBAAC,GAAD,EAAM,WAAU,UAAW,CAAA,EAC3B,kBAAC,QAAD,EAAA,UAAO,EAAG,uCAAuC,OAAO,EAAQ,CAAA,CAC/D,EAAA,CAAA;IAEE,CAAA,CACL;MACN,kBAAC,OAAD;GAAK,WAAU;aACb,kBAAC,QAAD;IAAM,WAAU;cAA+B;IAAY,CAAA;GACvD,CAAA,CACF;;;AAWV,SAAS,EAAY,GAAgC;CACnD,IAAM,IAAwB,EAAE,EAC5B,IAAM,GAGJ,IAAQ,EAAQ,MAAM,oBAAoB;AAEhD,MAAK,IAAM,KA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CACV,KAAK,MAAM,EAAE,MAAM,CAAC,CACpB,OAAO,QAAQ,EAEd,IAAU,EAAS,EAAK,GAAG,EAE3B,IAAW,EAAK,MAAM,EAAE,CAAC,IAAI,EAAS;AAE5C,QACE,kBAAC,OAAD;EAAK,WAAU;YACb,kBAAC,SAAD;GAAO,WAAU;aAAjB,CACE,kBAAC,SAAD,EAAA,UACE,kBAAC,MAAD;IAAI,WAAU;cACX,EAAQ,KAAK,GAAG,MACf,kBAAC,MAAD;KAAY,WAAU;eACnB,EAAqB,EAAE;KACrB,EAFI,EAEJ,CACL;IACC,CAAA,EACC,CAAA,EACR,kBAAC,SAAD,EAAA,UACG,EAAS,KAAK,GAAK,MAClB,kBAAC,MAAD;IAAa,WAAU;cACpB,EAAI,KAAK,GAAM,MACd,kBAAC,MAAD;KAAa,WAAU;eACpB,EAAqB,EAAK;KACxB,EAFI,EAEJ,CACL;IACC,EANI,EAMJ,CACL,EACI,CAAA,CACF;;EACJ,CAAA;;AAIV,IAAa,KAAwC,EAAE,iBAInD,kBAAC,OAAD;CAAK,WAAU;WAHF,QAAc,EAAY,EAAQ,EAAE,CAAC,EAAQ,CAAC,CAIjD,KAAK,MAAU;AACrB,UAAQ,EAAM,MAAd;GACE,KAAK,OACH,QAAO,kBAAC,GAAD;IAA2B,UAAU,EAAM,YAAY;IAAI,MAAM,EAAM;IAAW,EAAlE,EAAM,IAA4D;GAC3F,KAAK,QACH,QAAO,kBAAC,GAAD,EAA4B,SAAS,EAAM,SAAW,EAArC,EAAM,IAA+B;GAC/D,QACE,QAAO,kBAAC,GAAD,EAA2B,SAAS,EAAM,SAAW,EAArC,EAAM,IAA+B;;GAEhE;CACE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pageContext.js","names":[],"sources":["../../src/utils/pageContext.ts"],"sourcesContent":["/**\n * Page context gathering — captures the user's current browser context to send\n * alongside every assistant prompt so the agent is aware of where the user is.\n *\n * Only keys the ai-assistant agent's context-loader allow-lists are emitted\n * (currentUrl / currentPage / entityType / entityId / …); anything else is\n * dropped server-side. entityType/entityId are resolved from the HealthyBowl\n * route by matching the pathname SUFFIX, because the MFE mounts under a\n * host-controlled base path (…/healthybowl/…) rather than a fixed prefix.\n */\n\nexport interface PageContext {\n currentUrl: string;\n currentPage: string;\n platform: string;\n entityType?: string;\n entityId?: string;\n viewportSize: string;\n version: string;\n timestamp: string;\n}\n\n// HealthyBowl detail routes → entityType. Matched on the pathname SUFFIX, so the\n// host base path / workspace segment is irrelevant. Order: most specific first.\n// The single-segment matchers (crops/:id, marketplace/:id) negative-lookahead\n// their STATIC sibling list-routes (crops/{fields,planning,harvest} and\n// marketplace/{cart,wishlist,orders} — see HealthyBowlRoutes.tsx) so a list page\n// like /crops/fields isn't mis-tagged as a crop with a fabricated entityId\n// \"fields\". Keep the exclusions in sync if new static sub-routes are added under\n// those parents. (The 2-segment detail routes are unambiguous and need no guard.)\nconst HB_ENTITY_ROUTES: ReadonlyArray<readonly [RegExp, string]> = [\n [/\\/crops\\/fields\\/([^/]+)\\/?$/, 'HEALTHYBOWL_FIELD'],\n [/\\/crops\\/planning\\/([^/]+)\\/?$/, 'HEALTHYBOWL_PLAN'],\n [/\\/crops\\/harvest\\/([^/]+)\\/?$/, 'HEALTHYBOWL_HARVEST'],\n [/\\/crops\\/(?!fields\\/?$|planning\\/?$|harvest\\/?$)([^/]+)\\/?$/, 'HEALTHYBOWL_CROP'],\n [/\\/livestock\\/animals\\/([^/]+)\\/?$/, 'HEALTHYBOWL_ANIMAL'],\n [/\\/marketplace\\/(?!cart\\/?$|wishlist\\/?$|orders\\/?$)([^/]+)\\/?$/, 'HEALTHYBOWL_MARKETPLACE_PRODUCT'],\n [/\\/government-schemes\\/schemes\\/([^/]+)\\/?$/, 'HEALTHYBOWL_SCHEME'],\n [/\\/consultant\\/clients\\/([^/]+)\\/?$/, 'HEALTHYBOWL_CLIENT_WORKSPACE'],\n];\n\
|
|
1
|
+
{"version":3,"file":"pageContext.js","names":[],"sources":["../../src/utils/pageContext.ts"],"sourcesContent":["/**\n * Page context gathering — captures the user's current browser context to send\n * alongside every assistant prompt so the agent is aware of where the user is.\n *\n * Only keys the ai-assistant agent's context-loader allow-lists are emitted\n * (currentUrl / currentPage / entityType / entityId / …); anything else is\n * dropped server-side. entityType/entityId are resolved from the HealthyBowl\n * route by matching the pathname SUFFIX, because the MFE mounts under a\n * host-controlled base path (…/healthybowl/…) rather than a fixed prefix.\n */\n\nexport interface PageContext {\n currentUrl: string;\n currentPage: string;\n platform: string;\n entityType?: string;\n entityId?: string;\n viewportSize: string;\n version: string;\n timestamp: string;\n}\n\n// HealthyBowl detail routes → entityType. Matched on the pathname SUFFIX, so the\n// host base path / workspace segment is irrelevant. Order: most specific first.\n// The single-segment matchers (crops/:id, marketplace/:id) negative-lookahead\n// their STATIC sibling list-routes (crops/{fields,planning,harvest} and\n// marketplace/{cart,wishlist,orders} — see HealthyBowlRoutes.tsx) so a list page\n// like /crops/fields isn't mis-tagged as a crop with a fabricated entityId\n// \"fields\". Keep the exclusions in sync if new static sub-routes are added under\n// those parents. (The 2-segment detail routes are unambiguous and need no guard.)\nconst HB_ENTITY_ROUTES: ReadonlyArray<readonly [RegExp, string]> = [\n [/\\/crops\\/fields\\/([^/]+)\\/?$/, 'HEALTHYBOWL_FIELD'],\n [/\\/crops\\/planning\\/([^/]+)\\/?$/, 'HEALTHYBOWL_PLAN'],\n [/\\/crops\\/harvest\\/([^/]+)\\/?$/, 'HEALTHYBOWL_HARVEST'],\n [/\\/crops\\/(?!fields\\/?$|planning\\/?$|harvest\\/?$)([^/]+)\\/?$/, 'HEALTHYBOWL_CROP'],\n [/\\/livestock\\/animals\\/([^/]+)\\/?$/, 'HEALTHYBOWL_ANIMAL'],\n [/\\/marketplace\\/(?!cart\\/?$|wishlist\\/?$|orders\\/?$)([^/]+)\\/?$/, 'HEALTHYBOWL_MARKETPLACE_PRODUCT'],\n [/\\/government-schemes\\/schemes\\/([^/]+)\\/?$/, 'HEALTHYBOWL_SCHEME'],\n [/\\/consultant\\/clients\\/([^/]+)\\/?$/, 'HEALTHYBOWL_CLIENT_WORKSPACE'],\n];\n\nexport function resolveHealthyBowlEntity(pathname: string): {\n entityType?: string;\n entityId?: string;\n} {\n for (const [pattern, entityType] of HB_ENTITY_ROUTES) {\n const match = pathname.match(pattern);\n if (match) return { entityType, entityId: match[1] };\n }\n return {};\n}\n\nexport function gatherPageContext(): PageContext {\n const pathname = window.location.pathname;\n const pathSegments = pathname.split('/').filter(Boolean);\n // Human-readable page label: the portion of the path after the `healthybowl`\n // mount segment, falling back to the trailing segments.\n const hbIndex = pathSegments.indexOf('healthybowl');\n const currentPage =\n (hbIndex >= 0 ? pathSegments.slice(hbIndex + 1, hbIndex + 4) : pathSegments.slice(-3)).join('/') || 'home';\n\n return {\n currentUrl: window.location.href,\n currentPage,\n platform: 'healthybowl',\n ...resolveHealthyBowlEntity(pathname),\n viewportSize: `${window.innerWidth}x${window.innerHeight}`,\n version: import.meta.env.VITE_APP_VERSION ?? '2026.627.1',\n timestamp: new Date().toISOString(),\n };\n}\n"],"mappings":";AA8BA,IAAM,IAA6D;CACjE,CAAC,gCAAgC,oBAAoB;CACrD,CAAC,kCAAkC,mBAAmB;CACtD,CAAC,iCAAiC,sBAAsB;CACxD,CAAC,+DAA+D,mBAAmB;CACnF,CAAC,qCAAqC,qBAAqB;CAC3D,CAAC,kEAAkE,kCAAkC;CACrG,CAAC,8CAA8C,qBAAqB;CACpE,CAAC,sCAAsC,+BAA+B;CACvE;AAED,SAAgB,EAAyB,GAGvC;AACA,MAAK,IAAM,CAAC,GAAS,MAAe,GAAkB;EACpD,IAAM,IAAQ,EAAS,MAAM,EAAQ;AACrC,MAAI,EAAO,QAAO;GAAE;GAAY,UAAU,EAAM;GAAI;;AAEtD,QAAO,EAAE;;AAGX,SAAgB,IAAiC;CAC/C,IAAM,IAAW,OAAO,SAAS,UAC3B,IAAe,EAAS,MAAM,IAAI,CAAC,OAAO,QAAQ,EAGlD,IAAU,EAAa,QAAQ,cAAc,EAC7C,KACH,KAAW,IAAI,EAAa,MAAM,IAAU,GAAG,IAAU,EAAE,GAAG,EAAa,MAAM,GAAG,EAAE,KAAK,IAAI,IAAI;AAEtG,QAAO;EACL,YAAY,OAAO,SAAS;EAC5B;EACA,UAAU;EACV,GAAG,EAAyB,EAAS;EACrC,cAAc,GAAG,OAAO,WAAW,GAAG,OAAO;EAC7C,SAA6C;EAC7C,4BAAW,IAAI,MAAM,EAAC,aAAa;EACpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizeUrl.js","names":[],"sources":["../../src/utils/sanitizeUrl.ts"],"sourcesContent":["/**\n * Block executable URL schemes (javascript:, data:, vbscript:) in links rendered\n * from assistant output — a prompt-injected response could otherwise produce a\n * click-to-execute link. Browsers strip whitespace (tab/newline/CR) from a URL\n * before parsing its scheme, so strip the same before testing. Allow\n * http(s)/mailto/tel + relative/anchor links through unchanged.\n */\nexport function sanitizeUrl(url: string): string {\n const scheme = url.replace(/\\s+/g, '').toLowerCase();\n if (/^(?:javascript|data|vbscript):/.test(scheme)) return '#';\n return url.trim();\n}\n"],"mappings":";AAOA,SAAgB,EAAY,GAAqB;CAC/C,IAAM,IAAS,EAAI,QAAQ,QAAQ,GAAG,CAAC,aAAa;AAEpD,QADI,iCAAiC,KAAK,EAAO,GAAS,MACnD,EAAI,MAAM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@burdenoff/microfe-healthybowl",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.628.1",
|
|
4
4
|
"description": "Burdenoff HealthyBowl Microfrontend - Comprehensive organic farming and agro-foods management platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -30,7 +30,10 @@
|
|
|
30
30
|
"lint:sanity": "if [ \"${CI:-}\" = \"true\" ]; then bun run lint; else bun run lint -- --cache --cache-location .eslintcache; fi",
|
|
31
31
|
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
|
|
32
32
|
"type:check": "tsc --noEmit",
|
|
33
|
-
"
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"test:watch": "vitest",
|
|
35
|
+
"test:coverage": "vitest run --coverage",
|
|
36
|
+
"sanity": "bun run codegen && bun run lint:sanity && bun run format && bun run type:check && bun run test && bun run build",
|
|
34
37
|
"prepare": "lefthook install || true",
|
|
35
38
|
"switch:status": "bun scripts/deps-mode.ts status",
|
|
36
39
|
"switch:remote": "bun scripts/deps-mode.ts remote",
|
|
@@ -68,6 +71,7 @@
|
|
|
68
71
|
"@types/react": "^19.0.2",
|
|
69
72
|
"@types/react-dom": "^19.0.2",
|
|
70
73
|
"@vitejs/plugin-react": "^4.3.4",
|
|
74
|
+
"@vitest/coverage-v8": "3.2.4",
|
|
71
75
|
"autoprefixer": "^10.4.20",
|
|
72
76
|
"eslint": "^9.18.0",
|
|
73
77
|
"eslint-plugin-react": "^7.37.5",
|
|
@@ -79,7 +83,8 @@
|
|
|
79
83
|
"typescript": "^5.9.0",
|
|
80
84
|
"typescript-eslint": "^8.46.3",
|
|
81
85
|
"vite": "8.0.8",
|
|
82
|
-
"vite-plugin-dts": "3.9.1"
|
|
86
|
+
"vite-plugin-dts": "3.9.1",
|
|
87
|
+
"vitest": "3.2.4"
|
|
83
88
|
},
|
|
84
89
|
"peerDependencies": {
|
|
85
90
|
"@apollo/client": "^4.0.11",
|