@cboxdk/cbox-ui 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import { defineCboxAppSwitcher, subscribeKnownAppCatalog, readKnownAppCatalog, s
4
4
  export { authorizeHref, parseAppCatalog, readKnownAppCatalog, rememberAppCatalog, secureIconUrl, signInTarget } from './chunk-AJCYF7SS.js';
5
5
  import { createContext, forwardRef, Children, isValidElement, cloneElement, useContext, useMemo, useSyncExternalStore, useState, useId, useRef, useCallback, useEffect, createElement, useLayoutEffect, useImperativeHandle } from 'react';
6
6
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
7
- import { Zap, Webhook, Wallet, Users, Timer, Tag, Sparkles, ShieldCheck, Shield, Settings, Server, Send, Search, Rocket, Receipt, Plug, Percent, Package, Network, MessageSquare, Mail, Lock, List, LifeBuoy, Layers, LayoutGrid, LayoutDashboard, Key, Inbox, Home, HardDrive, Globe, GitBranch, Folder, FileText, Database, CreditCard, Code, Cloud, Clock, Calendar, Building2, Briefcase, Boxes, BookOpen, Bell, BarChart3, Activity, ChevronDown, Plus, PinOff, Pin, PanelLeftOpen, PanelLeftClose, ChevronsUpDown, CircleHelp, ArrowLeftRight, CornerDownLeft, ArrowRight, MoreHorizontal, ChevronLeft, X, ArrowUpRight, ArrowUp, CircleAlert, UserRound, Ticket, ChevronRight, ArrowLeft, Circle, Monitor, Sun, Moon, LogOut, Check } from 'lucide-react';
7
+ import { Zap, Webhook, Wallet, Users, Timer, Tag, Sparkles, ShieldCheck, Shield, Settings, Server, Send, Search, Rocket, Receipt, Plug, Percent, Package, Network, MessageSquare, Mail, Lock, List, LifeBuoy, Layers, LayoutGrid, LayoutDashboard, Key, Inbox, Home, HardDrive, Globe, GitBranch, Folder, FileText, Database, CreditCard, Code, Cloud, Clock, Calendar, Building2, Briefcase, Boxes, BookOpen, Bell, BarChart3, Activity, ChevronDown, Plus, PinOff, Pin, PanelLeftOpen, PanelLeftClose, ChevronsUpDown, CircleHelp, ArrowLeftRight, CornerDownLeft, ArrowRight, MoreHorizontal, CircleAlert, ChevronRight, Ticket, ArrowUpRight, UserRound, ChevronLeft, X, ArrowLeft, Circle, Monitor, Sun, Moon, LogOut, Check, ArrowUp } from 'lucide-react';
8
8
  import { createPortal } from 'react-dom';
9
9
 
10
10
  var CboxIdContext = createContext(null);
@@ -1743,10 +1743,10 @@ function Spinner({ className, label }) {
1743
1743
  function buttonClassName({ variant = "ghost", size = "md" } = {}) {
1744
1744
  return cn("cbx-ui-btn", `cbx-ui-btn--${variant}`, size !== "md" && `cbx-ui-btn--${size}`);
1745
1745
  }
1746
- var Button = forwardRef(function Button2({ variant = "ghost", size = "md", icon, loading = false, asChild = false, disabled, className, children, type, ...props }, ref) {
1746
+ var Button = forwardRef(function Button2({ variant = "ghost", size = "md", icon, loading: loading2 = false, asChild = false, disabled, className, children, type, ...props }, ref) {
1747
1747
  const classes = cn(buttonClassName({ variant, size }), className);
1748
- const glyph = loading ? /* @__PURE__ */ jsx(Spinner, {}) : icon !== void 0 && icon !== null ? /* @__PURE__ */ jsx("span", { className: "cbx-ui-btn-glyph", "aria-hidden": "true", children: icon }) : null;
1749
- const inactive = (disabled ?? false) || loading;
1748
+ const glyph = loading2 ? /* @__PURE__ */ jsx(Spinner, {}) : icon !== void 0 && icon !== null ? /* @__PURE__ */ jsx("span", { className: "cbx-ui-btn-glyph", "aria-hidden": "true", children: icon }) : null;
1749
+ const inactive = (disabled ?? false) || loading2;
1750
1750
  if (asChild) {
1751
1751
  const child = Children.only(children);
1752
1752
  if (!isValidElement(child)) return null;
@@ -1755,7 +1755,7 @@ var Button = forwardRef(function Button2({ variant = "ghost", size = "md", icon,
1755
1755
  ...props,
1756
1756
  ref,
1757
1757
  className: cn(classes, own.className),
1758
- "aria-busy": loading || void 0,
1758
+ "aria-busy": loading2 || void 0,
1759
1759
  "aria-disabled": inactive || void 0,
1760
1760
  // A disabled link keeps its focus (so it can be reached and explained) but goes nowhere.
1761
1761
  onClick: (event) => {
@@ -1779,7 +1779,7 @@ var Button = forwardRef(function Button2({ variant = "ghost", size = "md", icon,
1779
1779
  type: type ?? "button",
1780
1780
  className: classes,
1781
1781
  disabled: inactive,
1782
- "aria-busy": loading || void 0,
1782
+ "aria-busy": loading2 || void 0,
1783
1783
  ...props,
1784
1784
  children: [
1785
1785
  glyph,
@@ -2032,6 +2032,157 @@ function resolveIcon(name, extra = {}) {
2032
2032
  return extra[name] ?? SHELL_ICONS[name] ?? Circle;
2033
2033
  }
2034
2034
 
2035
+ // src/shell/help-api.ts
2036
+ var SESSION_FIELD = { search: "searchUrl", articles: "articlesUrl", article: "articleUrl", updates: "updatesUrl" };
2037
+ var EXPIRY_MARGIN_MS = 15e3;
2038
+ function ownUrl(help, endpoint) {
2039
+ if (endpoint === "search") return help.searchUrl;
2040
+ if (endpoint === "articles") return help.articlesUrl;
2041
+ if (endpoint === "updates") return help.updatesUrl;
2042
+ return void 0;
2043
+ }
2044
+ function helpSessionKey(shell) {
2045
+ const { help } = shell;
2046
+ if (!help.enabled || help.sessionUrl === void 0) return null;
2047
+ return `${help.sessionUrl}|${shell.context.levels[0]?.current.id ?? ""}`;
2048
+ }
2049
+ function endpointUrl(value) {
2050
+ if (typeof value !== "string" || value === "") return void 0;
2051
+ try {
2052
+ const url = new URL(value, typeof window === "undefined" ? "https://localhost" : window.location.href);
2053
+ const local = url.protocol === "http:" && (url.hostname === "localhost" || url.hostname === "127.0.0.1");
2054
+ return url.protocol === "https:" || local ? value : void 0;
2055
+ } catch {
2056
+ return void 0;
2057
+ }
2058
+ }
2059
+ function parseSession(key, body) {
2060
+ const row = typeof body === "object" && body !== null ? body : {};
2061
+ const session = { key, status: "ready" };
2062
+ if (typeof row.identity !== "string" || row.identity === "") return session;
2063
+ session.identity = row.identity;
2064
+ session.expiresAt = typeof row.expires_at === "number" ? row.expires_at * 1e3 : Date.now() + 12e4;
2065
+ const fields = { searchUrl: row.search_url, articlesUrl: row.topics_url, articleUrl: row.article_url, updatesUrl: row.updates_url };
2066
+ for (const [field, value] of Object.entries(fields)) {
2067
+ const url = endpointUrl(value);
2068
+ if (url !== void 0) session[field] = url;
2069
+ }
2070
+ return session;
2071
+ }
2072
+ var loading = /* @__PURE__ */ new WeakMap();
2073
+ function fresh(session, key) {
2074
+ return session !== null && session.key === key && session.status === "ready" && (session.expiresAt === void 0 || session.expiresAt - EXPIRY_MARGIN_MS > Date.now());
2075
+ }
2076
+ function loadHelpSession(store, help, key, force = false) {
2077
+ const current = store.get().session;
2078
+ if (!force && fresh(current, key)) return Promise.resolve(current);
2079
+ const pending = loading.get(store);
2080
+ if (pending !== void 0 && pending.key === key) return pending.promise;
2081
+ if (current === null || current.key !== key) store.set({ session: { key, status: "loading" } });
2082
+ const promise = requestJson(help.sessionUrl).then((body) => parseSession(key, body)).catch(() => ({ key, status: "ready" })).then((session) => {
2083
+ if (loading.get(store)?.promise === promise) loading.delete(store);
2084
+ const latest = store.get().session;
2085
+ if (latest === null || latest.key === key) store.set({ session });
2086
+ return session;
2087
+ });
2088
+ loading.set(store, { key, promise });
2089
+ return promise;
2090
+ }
2091
+ function helpEndpointState(help, session, key, endpoint) {
2092
+ if (!help.enabled) return "none";
2093
+ if (ownUrl(help, endpoint) !== void 0) return "ready";
2094
+ if (key === null) return "none";
2095
+ if (session === null || session.key !== key || session.status === "loading") return "pending";
2096
+ return session[SESSION_FIELD[endpoint]] !== void 0 ? "ready" : "none";
2097
+ }
2098
+ var HelpUnavailableError = class extends Error {
2099
+ constructor(endpoint) {
2100
+ super(`Help has no ${endpoint} endpoint here`);
2101
+ }
2102
+ };
2103
+ async function bearerJson(url, identity, init) {
2104
+ const response = await fetch(url, { method: init.method ?? "GET", credentials: "omit", headers: { Accept: "application/json", Authorization: `Bearer ${identity}` }, signal: init.signal });
2105
+ const text = await response.text();
2106
+ let body = null;
2107
+ try {
2108
+ body = text === "" ? null : JSON.parse(text);
2109
+ } catch {
2110
+ body = null;
2111
+ }
2112
+ if (!response.ok) throw new ShellRequestError(response.status, body);
2113
+ return body;
2114
+ }
2115
+ async function helpRequest(store, shell, endpoint, build, init = {}) {
2116
+ const { help } = shell;
2117
+ const own = help.enabled ? ownUrl(help, endpoint) : void 0;
2118
+ if (own !== void 0) return requestJson(build(own), init);
2119
+ const key = helpSessionKey(shell);
2120
+ if (key === null) throw new HelpUnavailableError(endpoint);
2121
+ const call = async (force) => {
2122
+ const session = await loadHelpSession(store, help, key, force);
2123
+ const url = session[SESSION_FIELD[endpoint]];
2124
+ if (url === void 0 || session.identity === void 0) throw new HelpUnavailableError(endpoint);
2125
+ return bearerJson(build(url), session.identity, init);
2126
+ };
2127
+ try {
2128
+ return await call(false);
2129
+ } catch (error) {
2130
+ if (error instanceof ShellRequestError && error.status === 401) return call(true);
2131
+ throw error;
2132
+ }
2133
+ }
2134
+ var BLOCKS = { h1: "h4", h2: "h4", h3: "h4", h4: "h5", h5: "h6", h6: "h6" };
2135
+ var KEPT = /* @__PURE__ */ new Set(["p", "br", "hr", "ul", "ol", "li", "strong", "b", "em", "i", "code", "pre", "blockquote", "kbd", "table", "thead", "tbody", "tr", "th", "td", "a", "img", "h4", "h5", "h6"]);
2136
+ var DROPPED = /* @__PURE__ */ new Set(["script", "style", "iframe", "object", "embed", "template", "noscript", "svg", "math", "form", "link", "meta", "base", "head", "title"]);
2137
+ function cleanArticleHtml(html) {
2138
+ if (typeof DOMParser === "undefined") return "";
2139
+ const source = new DOMParser().parseFromString(html, "text/html");
2140
+ const out = source.implementation.createHTMLDocument("");
2141
+ const copy = (from, into) => {
2142
+ for (const node of Array.from(from.childNodes)) {
2143
+ if (node.nodeType === 3) {
2144
+ into.appendChild(out.createTextNode(node.textContent ?? ""));
2145
+ continue;
2146
+ }
2147
+ if (node.nodeType !== 1) continue;
2148
+ const element = node;
2149
+ const name = element.tagName.toLowerCase();
2150
+ if (DROPPED.has(name)) continue;
2151
+ const tag = BLOCKS[name] ?? name;
2152
+ if (!KEPT.has(tag)) {
2153
+ copy(element, into);
2154
+ continue;
2155
+ }
2156
+ const made = out.createElement(tag);
2157
+ if (tag === "a") {
2158
+ const href = element.getAttribute("href")?.trim() ?? "";
2159
+ if (!/^(https?:\/\/|\/(?!\/)|#)/i.test(href)) {
2160
+ copy(element, into);
2161
+ continue;
2162
+ }
2163
+ made.setAttribute("href", href);
2164
+ if (/^https?:/i.test(href)) {
2165
+ made.setAttribute("target", "_blank");
2166
+ made.setAttribute("rel", "noopener noreferrer");
2167
+ }
2168
+ }
2169
+ if (tag === "img") {
2170
+ const src = element.getAttribute("src")?.trim() ?? "";
2171
+ if (!/^https:\/\//i.test(src)) continue;
2172
+ made.setAttribute("src", src);
2173
+ made.setAttribute("alt", element.getAttribute("alt") ?? "");
2174
+ made.setAttribute("loading", "lazy");
2175
+ made.setAttribute("referrerpolicy", "no-referrer");
2176
+ }
2177
+ if ((tag === "td" || tag === "th") && /^[1-9]\d?$/.test(element.getAttribute("colspan") ?? "")) made.setAttribute("colspan", element.getAttribute("colspan"));
2178
+ copy(element, made);
2179
+ into.appendChild(made);
2180
+ }
2181
+ };
2182
+ copy(source.body, out.body);
2183
+ return out.body.innerHTML;
2184
+ }
2185
+
2035
2186
  // src/shell/help-store.ts
2036
2187
  var INITIAL_HELP_STATE = {
2037
2188
  open: false,
@@ -2041,6 +2192,8 @@ var INITIAL_HELP_STATE = {
2041
2192
  updates: [],
2042
2193
  updatesStatus: "idle",
2043
2194
  pendingQuestion: null,
2195
+ chat: false,
2196
+ session: null,
2044
2197
  seeded: false,
2045
2198
  restored: false,
2046
2199
  updatesKey: null
@@ -2090,20 +2243,35 @@ function parseUpdates(body) {
2090
2243
  return [update];
2091
2244
  });
2092
2245
  }
2246
+ function parseArticle(value, source) {
2247
+ if (typeof value !== "object" || value === null) return null;
2248
+ const row = value;
2249
+ if (typeof row.id !== "string" && typeof row.id !== "number" || typeof row.title !== "string") return null;
2250
+ const article = { id: String(row.id), title: row.title };
2251
+ if (typeof row.excerpt === "string") article.excerpt = row.excerpt;
2252
+ if (typeof row.body === "string") article.body = row.body;
2253
+ if (typeof row.body_html === "string") article.bodyHtml = row.body_html;
2254
+ const url = safeUrl(row.url);
2255
+ if (url !== void 0) article.url = url;
2256
+ if (typeof row.source === "string") article.source = row.source;
2257
+ else if (source !== void 0) article.source = source;
2258
+ return article;
2259
+ }
2093
2260
  function parseArticles(body) {
2094
- const rows2 = Array.isArray(body) ? body : typeof body === "object" && body !== null && Array.isArray(body.data) ? body.data : [];
2095
- return rows2.flatMap((value) => {
2096
- if (typeof value !== "object" || value === null) return [];
2097
- const row = value;
2098
- if (typeof row.id !== "string" && typeof row.id !== "number" || typeof row.title !== "string") return [];
2099
- const article = { id: String(row.id), title: row.title };
2100
- if (typeof row.excerpt === "string") article.excerpt = row.excerpt;
2101
- if (typeof row.body === "string") article.body = row.body;
2102
- const url = safeUrl(row.url);
2103
- if (url !== void 0) article.url = url;
2104
- if (typeof row.source === "string") article.source = row.source;
2105
- return [article];
2106
- });
2261
+ const answer = typeof body === "object" && body !== null ? body : {};
2262
+ if (!Array.isArray(body) && !Array.isArray(answer.data) && Array.isArray(answer.groups)) {
2263
+ return answer.groups.flatMap((group) => {
2264
+ const rows3 = typeof group === "object" && group !== null ? group : {};
2265
+ const source = typeof rows3.source === "string" ? rows3.source : void 0;
2266
+ return (Array.isArray(rows3.data) ? rows3.data : []).flatMap((row) => parseArticle(row, source) ?? []);
2267
+ });
2268
+ }
2269
+ const rows2 = Array.isArray(body) ? body : Array.isArray(answer.data) ? answer.data : [];
2270
+ return rows2.flatMap((row) => parseArticle(row) ?? []);
2271
+ }
2272
+ function parseArticleBody(body) {
2273
+ const answer = typeof body === "object" && body !== null ? body : null;
2274
+ return parseArticle(answer !== null && typeof answer.data === "object" && answer.data !== null && !Array.isArray(answer.data) ? answer.data : body);
2107
2275
  }
2108
2276
  var DEFAULT_SUPPORT_SCRIPT = "/ai-assistant/support.js";
2109
2277
  var SUPPORT_TAG = "cbox-support";
@@ -2128,6 +2296,15 @@ function pageIntent(shell) {
2128
2296
  if (typeof window !== "undefined") intent.url = window.location.pathname;
2129
2297
  return intent;
2130
2298
  }
2299
+ function ownPath(url) {
2300
+ if (typeof url !== "string" || typeof window === "undefined") return null;
2301
+ try {
2302
+ const target = new URL(url, window.location.href);
2303
+ return target.origin === window.location.origin ? target.pathname + target.search + target.hash : null;
2304
+ } catch {
2305
+ return null;
2306
+ }
2307
+ }
2131
2308
  function ensureScript(src) {
2132
2309
  if (typeof document === "undefined" || customElements.get(SUPPORT_TAG) !== void 0) return;
2133
2310
  if (Array.from(document.scripts).some((script2) => script2.getAttribute("src") === src)) return;
@@ -2164,34 +2341,45 @@ function HelpColumn({ docked, mobile = false }) {
2164
2341
  const updates = useHelpState(store, (state) => state.updates);
2165
2342
  const updatesStatus = useHelpState(store, (state) => state.updatesStatus);
2166
2343
  const pendingQuestion = useHelpState(store, (state) => state.pendingQuestion);
2344
+ const chat = useHelpState(store, (state) => state.chat);
2345
+ const session = useHelpState(store, (state) => state.session);
2346
+ const [loadedArticle, setLoadedArticle] = useState(null);
2167
2347
  const [articles, setArticles] = useState({ topic: void 0, items: [], status: "loading" });
2168
2348
  const [results, setResults] = useState(null);
2169
- const [question, setQuestion] = useState("");
2170
2349
  const [chatProblem, setChatProblem] = useState(false);
2171
- const [asked, setAsked] = useState(false);
2172
2350
  const [followUp, setFollowUp] = useState("");
2173
2351
  const column = useRef(null);
2174
2352
  const body = useRef(null);
2175
2353
  const chatHost = useRef(null);
2176
- const searchField = useRef(null);
2354
+ const askField = useRef(null);
2177
2355
  const opener = useRef(null);
2178
2356
  const scrim = useRef(null);
2179
2357
  const { help } = shell;
2358
+ const latest = useRef({ shell, navigate, toggleHelp, docked });
2359
+ latest.current = { shell, navigate, toggleHelp, docked };
2360
+ const sessionKey = helpSessionKey(shell);
2361
+ const canSearch = helpEndpointState(help, session, sessionKey, "search") !== "none";
2362
+ const canLoadArticles = helpEndpointState(help, session, sessionKey, "articles") !== "none";
2363
+ const hasUpdates = helpEndpointState(help, session, sessionKey, "updates") !== "none";
2364
+ const sentArticles = (help.articles ?? []).slice(0, 4);
2365
+ const view = article !== null ? "article" : chat ? "chat" : "home";
2366
+ const [chatKnown, setChatKnown] = useState(false);
2367
+ useEffect(() => setChatKnown(knowsChat(sessionKey)), [sessionKey]);
2180
2368
  useScrollLock(mobile && open);
2181
2369
  const closeSheet = useCallback(() => toggleHelp(false), [toggleHelp]);
2182
2370
  useSheetDrag({ panel: column, scrim, size: "tall", onClose: closeSheet, enabled: mobile && open });
2183
2371
  const portal = help.portalUrl;
2184
- const updatesKey = help.enabled && help.updatesUrl !== void 0 ? `${help.updatesUrl}|${shell.context.levels[0]?.current.id ?? ""}` : null;
2372
+ const updatesKey = hasUpdates ? `${help.updatesUrl ?? help.sessionUrl}|${shell.context.levels[0]?.current.id ?? ""}` : null;
2185
2373
  const loadUpdates = useCallback(() => {
2186
- if (updatesKey === null || help.updatesUrl === void 0) return;
2374
+ if (updatesKey === null) return;
2187
2375
  const current = () => store.get().updatesKey === updatesKey;
2188
2376
  store.set({ updatesStatus: "loading", updatesKey });
2189
- requestJson(help.updatesUrl).then((answer) => {
2377
+ helpRequest(store, latest.current.shell, "updates", (url) => url).then((answer) => {
2190
2378
  if (current()) store.set({ updates: parseUpdates(answer), updatesStatus: "ready" });
2191
- }).catch(() => {
2192
- if (current()) store.set({ updatesStatus: "unavailable" });
2379
+ }).catch((error) => {
2380
+ if (current()) store.set(error instanceof HelpUnavailableError ? { updates: [], updatesStatus: "ready" } : { updatesStatus: "unavailable" });
2193
2381
  });
2194
- }, [updatesKey, help.updatesUrl, store]);
2382
+ }, [updatesKey, store]);
2195
2383
  useEffect(() => {
2196
2384
  const state = store.get();
2197
2385
  if (state.updatesKey !== updatesKey) {
@@ -2203,33 +2391,53 @@ function HelpColumn({ docked, mobile = false }) {
2203
2391
  if (open && store.get().updatesStatus !== "loading") loadUpdates();
2204
2392
  }, [open]);
2205
2393
  useEffect(() => {
2206
- if (!open || !help.enabled || help.articlesUrl === void 0 || help.topic === void 0) return;
2207
- if (articles.topic === help.topic && articles.status === "ready") return;
2394
+ const topic2 = help.topic;
2395
+ if (!open || !canLoadArticles || topic2 === void 0 || help.articlesUrl === void 0 && sentArticles.length > 0) return;
2396
+ if (articles.topic === topic2 && articles.status === "ready") return;
2208
2397
  const controller = new AbortController();
2209
- setArticles({ topic: help.topic, items: [], status: "loading" });
2210
- requestJson(help.articlesUrl.split("{topic}").join(encodeURIComponent(help.topic)), { signal: controller.signal }).then((answer) => setArticles({ topic: help.topic, items: parseArticles(answer).slice(0, 4), status: "ready" })).catch((error) => {
2211
- if (error?.name !== "AbortError") setArticles({ topic: help.topic, items: [], status: "unavailable" });
2398
+ setArticles({ topic: topic2, items: [], status: "loading" });
2399
+ helpRequest(store, latest.current.shell, "articles", (url) => url.split("{topic}").join(encodeURIComponent(topic2)), { signal: controller.signal }).then((answer) => setArticles({ topic: topic2, items: parseArticles(answer).slice(0, 4), status: "ready" })).catch((error) => {
2400
+ if (error?.name === "AbortError") return;
2401
+ setArticles({ topic: topic2, items: [], status: error instanceof HelpUnavailableError ? "ready" : "unavailable" });
2212
2402
  });
2213
2403
  return () => controller.abort();
2214
- }, [open, help.enabled, help.articlesUrl, help.topic]);
2404
+ }, [open, canLoadArticles, help.articlesUrl, help.topic, sessionKey]);
2215
2405
  useEffect(() => {
2216
2406
  const q = query2.trim();
2217
- if (!help.enabled || help.searchUrl === void 0 || q === "") {
2407
+ if (!canSearch || q === "") {
2218
2408
  setResults(null);
2219
2409
  return;
2220
2410
  }
2221
2411
  const controller = new AbortController();
2222
2412
  const timer = setTimeout(() => {
2223
2413
  setResults((current) => ({ q, items: current?.items ?? [], status: "loading" }));
2224
- requestJson(withQuery(help.searchUrl, { q, topic: help.topic }), { signal: controller.signal }).then((answer) => setResults({ q, items: parseArticles(answer), status: "ready" })).catch((error) => {
2225
- if (error?.name !== "AbortError") setResults({ q, items: [], status: "unavailable" });
2414
+ helpRequest(store, latest.current.shell, "search", (url) => withQuery(url, { q, topic: help.topic }), { signal: controller.signal }).then((answer) => setResults({ q, items: parseArticles(answer), status: "ready" })).catch((error) => {
2415
+ if (error?.name === "AbortError") return;
2416
+ setResults(error instanceof HelpUnavailableError ? null : { q, items: [], status: "unavailable" });
2226
2417
  });
2227
2418
  }, DEBOUNCE_MS);
2228
2419
  return () => {
2229
2420
  clearTimeout(timer);
2230
2421
  controller.abort();
2231
2422
  };
2232
- }, [query2, help.enabled, help.searchUrl, help.topic]);
2423
+ }, [query2, canSearch, help.searchUrl, help.topic, sessionKey, store]);
2424
+ const needsSession = help.enabled && sessionKey !== null && (help.searchUrl === void 0 || help.updatesUrl === void 0 || help.articlesUrl === void 0 && sentArticles.length === 0);
2425
+ useEffect(() => {
2426
+ if (open && needsSession && sessionKey !== null) void loadHelpSession(store, latest.current.shell.help, sessionKey);
2427
+ }, [open, needsSession, sessionKey, store]);
2428
+ const articleId = article?.id;
2429
+ const articleHasBody = article !== null && (article.body !== void 0 || article.bodyHtml !== void 0);
2430
+ useEffect(() => {
2431
+ if (articleId === void 0 || articleHasBody) return;
2432
+ const page = latest.current.shell;
2433
+ if (helpEndpointState(page.help, store.get().session, helpSessionKey(page), "article") === "none") return;
2434
+ const controller = new AbortController();
2435
+ setLoadedArticle({ id: articleId, html: null, status: "loading" });
2436
+ helpRequest(store, page, "article", (url) => url.split("{id}").join(encodeURIComponent(articleId)), { signal: controller.signal }).then((answer) => setLoadedArticle({ id: articleId, html: parseArticleBody(answer)?.bodyHtml ?? null, status: "ready" })).catch((error) => {
2437
+ if (error?.name !== "AbortError") setLoadedArticle({ id: articleId, html: null, status: "ready" });
2438
+ });
2439
+ return () => controller.abort();
2440
+ }, [articleId, articleHasBody, sessionKey, store]);
2233
2441
  useEffect(() => {
2234
2442
  if (open && help.enabled && help.sessionUrl !== void 0) ensureScript(help.scriptUrl ?? DEFAULT_SUPPORT_SCRIPT);
2235
2443
  }, [open, help.enabled, help.sessionUrl, help.scriptUrl]);
@@ -2244,30 +2452,82 @@ function HelpColumn({ docked, mobile = false }) {
2244
2452
  setChatProblem(false);
2245
2453
  if (help.sessionUrl === void 0) {
2246
2454
  setChatProblem(true);
2247
- return;
2455
+ return false;
2248
2456
  }
2249
2457
  ensureScript(help.scriptUrl ?? DEFAULT_SUPPORT_SCRIPT);
2250
2458
  const element = await whenSupportReady(chatHost.current);
2251
2459
  if (element === null) {
2252
2460
  setChatProblem(true);
2253
- return;
2461
+ return false;
2462
+ }
2463
+ const intent2 = JSON.parse(intentJson);
2464
+ element.intent = intent2;
2465
+ let opened;
2466
+ let handed = false;
2467
+ if (handover && typeof element.handover === "function") {
2468
+ opened = element.handover();
2469
+ handed = true;
2470
+ } else if (ask !== void 0 && ask !== "" && typeof element.ask === "function") {
2471
+ opened = element.ask(ask, intent2);
2472
+ handed = true;
2473
+ } else opened = element.open?.();
2474
+ if (await opened === false) {
2475
+ setChatProblem(true);
2476
+ return false;
2254
2477
  }
2255
- element.intent = JSON.parse(intentJson);
2256
- if (handover && typeof element.handover === "function") void element.handover();
2257
- else if (ask !== void 0 && ask !== "" && typeof element.ask === "function") void element.ask(ask, element.intent);
2258
- else void element.open?.();
2478
+ rememberChat(sessionKey);
2479
+ setChatKnown(true);
2480
+ return handed;
2481
+ },
2482
+ [help.sessionUrl, help.scriptUrl, intentJson, sessionKey]
2483
+ );
2484
+ const askCbox = useCallback(
2485
+ (text) => {
2486
+ void openChat(text).then((sent) => {
2487
+ if (sent) store.set((state) => state.query.trim() === text ? { query: "" } : {});
2488
+ });
2259
2489
  },
2260
- [help.sessionUrl, help.scriptUrl, intentJson]
2490
+ [openChat, store]
2261
2491
  );
2492
+ const closeChat = useCallback(() => {
2493
+ const element = chatHost.current?.querySelector(SUPPORT_TAG);
2494
+ if (typeof element?.close === "function") void element.close();
2495
+ store.set({ chat: false });
2496
+ }, [store]);
2262
2497
  useEffect(() => {
2263
2498
  if (pendingQuestion === null || !open) return;
2264
- store.set({ pendingQuestion: null });
2265
- setQuestion(pendingQuestion);
2266
- void openChat(pendingQuestion);
2267
- }, [pendingQuestion, open, openChat, store]);
2499
+ store.set({ pendingQuestion: null, query: pendingQuestion });
2500
+ askCbox(pendingQuestion);
2501
+ }, [pendingQuestion, open, askCbox, store]);
2502
+ useEffect(() => {
2503
+ const node = column.current;
2504
+ if (node === null) return;
2505
+ const onOpen = (event) => {
2506
+ if (event.detail?.inline === true) store.set({ chat: true });
2507
+ };
2508
+ const onClose = (event) => {
2509
+ store.set({ chat: false });
2510
+ if (event.detail?.reason === "unavailable") setChatProblem(true);
2511
+ };
2512
+ const onNavigate = (event) => {
2513
+ const path = ownPath(event.detail?.url);
2514
+ if (path === null) return;
2515
+ event.preventDefault();
2516
+ if (!latest.current.docked) latest.current.toggleHelp(false);
2517
+ latest.current.navigate(path);
2518
+ };
2519
+ node.addEventListener("cbox-support:open", onOpen);
2520
+ node.addEventListener("cbox-support:close", onClose);
2521
+ node.addEventListener("cbox-support:navigate", onNavigate);
2522
+ return () => {
2523
+ node.removeEventListener("cbox-support:open", onOpen);
2524
+ node.removeEventListener("cbox-support:close", onClose);
2525
+ node.removeEventListener("cbox-support:navigate", onNavigate);
2526
+ };
2527
+ }, [store]);
2268
2528
  useLayoutEffect(() => {
2269
2529
  if (open && body.current !== null) body.current.scrollTop = store.get().scrollTop;
2270
- }, [open, article, store]);
2530
+ }, [open, view, store]);
2271
2531
  const wasOpen = useRef(open);
2272
2532
  useEffect(() => {
2273
2533
  const opened = open && !wasOpen.current;
@@ -2276,8 +2536,8 @@ function HelpColumn({ docked, mobile = false }) {
2276
2536
  if (closed) {
2277
2537
  const active = document.activeElement;
2278
2538
  if (active === null || active === document.body || column.current?.contains(active)) {
2279
- const back = opener.current?.isConnected ? opener.current : document.querySelector('[aria-controls="cbx-help"]');
2280
- back?.focus({ preventScroll: true });
2539
+ const back2 = opener.current?.isConnected ? opener.current : document.querySelector('[aria-controls="cbx-help"]');
2540
+ back2?.focus({ preventScroll: true });
2281
2541
  }
2282
2542
  opener.current = null;
2283
2543
  return;
@@ -2287,13 +2547,13 @@ function HelpColumn({ docked, mobile = false }) {
2287
2547
  const active = document.activeElement;
2288
2548
  opener.current = active instanceof HTMLElement && active !== document.body && !column.current?.contains(active) ? active : null;
2289
2549
  }
2290
- if (opened && canAutofocus() && store.get().article === null) searchField.current?.focus();
2550
+ if (opened && canAutofocus() && store.get().article === null && !store.get().chat) askField.current?.focus();
2291
2551
  else if (!docked && !column.current?.contains(document.activeElement)) column.current?.focus();
2292
2552
  }, [open, docked, store]);
2293
2553
  const markRead = (update) => {
2294
2554
  if (!update.unread) return;
2295
2555
  store.set((state) => ({ updates: state.updates.map((item) => item.id === update.id ? { ...item, unread: false } : item) }));
2296
- if (help.updatesUrl !== void 0) requestJson(`${help.updatesUrl.replace(/\/$/, "")}/${encodeURIComponent(update.id)}/read`, { method: "POST" }).catch(() => void 0);
2556
+ helpRequest(store, latest.current.shell, "updates", (url) => `${url.replace(/\/$/, "")}/${encodeURIComponent(update.id)}/read`, { method: "POST" }).catch(() => void 0);
2297
2557
  };
2298
2558
  const openUpdate = (update) => {
2299
2559
  markRead(update);
@@ -2303,19 +2563,124 @@ function HelpColumn({ docked, mobile = false }) {
2303
2563
  };
2304
2564
  const unread = updates.filter((update) => update.unread);
2305
2565
  const unavailable = !help.enabled || updatesStatus === "unavailable" || articles.status === "unavailable" || results?.status === "unavailable";
2306
- const trail = contextTrail(shell);
2307
- const submit = (event) => {
2308
- event.preventDefault();
2309
- void openChat(question.trim());
2310
- if (question.trim() !== "") setAsked(true);
2566
+ const topic = helpTopicName(shell);
2567
+ const where = shell.context.levels.map((level) => level.current.name).join(" \xB7 ");
2568
+ const environment = environmentLevel(shell.context.levels)?.current;
2569
+ const chatReady = help.enabled && help.sessionUrl !== void 0;
2570
+ const close = () => toggleHelp(false);
2571
+ const back = () => view === "article" ? store.set({ article: null }) : closeChat();
2572
+ const pageArticles = help.articlesUrl === void 0 && sentArticles.length > 0 ? sentArticles : articles.items;
2573
+ const context = (strip) => /* @__PURE__ */ jsxs("p", { className: `cbx-ctxnote ${strip ? "is-strip" : ""}`, children: [
2574
+ environment !== void 0 && /* @__PURE__ */ jsx("span", { className: `cbx-tone cbx-tone-${environment.tone ?? "neutral"}`, "aria-hidden": "true" }),
2575
+ /* @__PURE__ */ jsx("span", { className: "cbx-truncate", title: t("Cbox sees this page: {page} in {where}", { page: topic, where }), children: t("Cbox sees this page: {page} in {where}", { page: topic, where }) })
2576
+ ] });
2577
+ const home = /* @__PURE__ */ jsxs(Fragment, { children: [
2578
+ unavailable && /* @__PURE__ */ jsxs("div", { className: "cbx-help-notice", role: "status", children: [
2579
+ /* @__PURE__ */ jsx(CircleAlert, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2580
+ /* @__PURE__ */ jsx("span", { children: help.enabled ? t("Help is not available right now. The rest of the app works as usual.") : t("Help is not available here yet.") }),
2581
+ help.enabled && /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-link", onClick: () => {
2582
+ loadUpdates();
2583
+ setArticles((current) => ({ ...current, status: "loading", topic: void 0 }));
2584
+ }, children: t("Try again") })
2585
+ ] }),
2586
+ (chatReady || canSearch) && /* @__PURE__ */ jsxs(Fragment, { children: [
2587
+ /* @__PURE__ */ jsx(
2588
+ AskField,
2589
+ {
2590
+ field: askField,
2591
+ value: query2,
2592
+ onChange: (value) => store.set({ query: value }),
2593
+ onSubmit: chatReady ? () => askCbox(query2.trim()) : void 0,
2594
+ placeholder: !chatReady ? t("Search docs and knowledge base") : canSearch ? t("Search or ask\u2026") : t("Ask about {page}\u2026", { page: topic }),
2595
+ label: !chatReady ? t("Search docs and knowledge base") : canSearch ? t("Search or ask\u2026") : t("Ask Cbox")
2596
+ }
2597
+ ),
2598
+ chatReady && context(false)
2599
+ ] }),
2600
+ chatProblem && /* @__PURE__ */ jsx("p", { className: "cbx-create-error", role: "alert", children: t("The chat could not be opened. Try again, or use the support portal.") }),
2601
+ results !== null ? /* @__PURE__ */ jsxs("section", { "aria-labelledby": "cbx-help-results", "aria-live": "polite", children: [
2602
+ /* @__PURE__ */ jsx("h3", { id: "cbx-help-results", className: "cbx-help-heading", children: t("Results") }),
2603
+ results.items.length > 0 && /* @__PURE__ */ jsx("div", { className: "cbx-group", children: results.items.map((item) => /* @__PURE__ */ jsx(ArticleRow, { article: item }, item.id)) }),
2604
+ results.status === "ready" && results.items.length === 0 && /* @__PURE__ */ jsx("p", { className: "cbx-list-note", children: chatReady ? t("No articles match. Send it to ask Cbox.") : t("Nothing matches \u201C{query}\u201D.", { query: results.q }) }),
2605
+ results.status === "loading" && results.items.length === 0 && /* @__PURE__ */ jsx("p", { className: "cbx-list-note", children: t("Searching\u2026") })
2606
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2607
+ chatKnown && chatReady && /* @__PURE__ */ jsx("div", { className: "cbx-group cbx-help-resume", children: /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-grow", onClick: () => void openChat(), children: [
2608
+ /* @__PURE__ */ jsx("span", { className: "cbx-tile is-accent", "aria-hidden": "true", children: /* @__PURE__ */ jsx(MessageSquare, { size: 16, strokeWidth: 1.8 }) }),
2609
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label cbx-grow-strong", children: t("Continue the conversation") }),
2610
+ /* @__PURE__ */ jsx(ChevronRight, { className: "cbx-grow-trail", size: 16, strokeWidth: 1.8, "aria-hidden": true })
2611
+ ] }) }),
2612
+ updates.length > 0 && /* @__PURE__ */ jsxs("section", { "aria-labelledby": "cbx-help-updates", children: [
2613
+ /* @__PURE__ */ jsxs("div", { className: "cbx-help-heading", children: [
2614
+ /* @__PURE__ */ jsx("h3", { id: "cbx-help-updates", children: t("Support updates") }),
2615
+ unread.length > 0 && /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-pane-all", onClick: () => unread.forEach(markRead), children: t("Mark all read") })
2616
+ ] }),
2617
+ /* @__PURE__ */ jsx("div", { className: "cbx-group", children: updates.map((update) => /* @__PURE__ */ jsxs("button", { type: "button", className: `cbx-grow is-tall ${update.unread ? "is-unread" : ""}`, onClick: () => openUpdate(update), children: [
2618
+ /* @__PURE__ */ jsx("span", { className: "cbx-tile is-plain", "aria-hidden": "true", children: update.kind === "chat" ? /* @__PURE__ */ jsx(MessageSquare, { size: 16, strokeWidth: 1.8 }) : /* @__PURE__ */ jsx(Ticket, { size: 16, strokeWidth: 1.8 }) }),
2619
+ /* @__PURE__ */ jsxs("span", { className: "cbx-grow-text", children: [
2620
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-strong cbx-truncate", title: update.title, children: update.title }),
2621
+ update.excerpt !== void 0 && /* @__PURE__ */ jsx("span", { className: "cbx-grow-sub cbx-truncate", children: update.excerpt })
2622
+ ] }),
2623
+ /* @__PURE__ */ jsxs("span", { className: "cbx-help-meta", children: [
2624
+ update.at !== void 0 && /* @__PURE__ */ jsx("time", { dateTime: update.at, children: formatDate(update.at) }),
2625
+ update.unread && /* @__PURE__ */ jsx("span", { className: "cbx-unread-dot", role: "img", "aria-label": t("Unread") })
2626
+ ] })
2627
+ ] }, update.id)) })
2628
+ ] }),
2629
+ pageArticles.length > 0 && /* @__PURE__ */ jsxs("section", { "aria-labelledby": "cbx-help-topic", children: [
2630
+ /* @__PURE__ */ jsx("h3", { id: "cbx-help-topic", className: "cbx-help-heading", children: t("For {page}", { page: topic }) }),
2631
+ /* @__PURE__ */ jsx("div", { className: "cbx-group", children: pageArticles.map((item) => /* @__PURE__ */ jsx(ArticleRow, { article: item }, item.id)) })
2632
+ ] })
2633
+ ] })
2634
+ ] });
2635
+ const reading = article !== null && /* @__PURE__ */ jsxs("article", { className: "cbx-help-article", children: [
2636
+ /* @__PURE__ */ jsx("h3", { className: "cbx-help-article-title", children: article.title }),
2637
+ /* @__PURE__ */ jsx(ArticleBody, { article, loaded: loadedArticle !== null && loadedArticle.id === article.id ? loadedArticle : null }),
2638
+ article.url !== void 0 && /* @__PURE__ */ jsxs("a", { className: "cbx-link", href: article.url, target: "_blank", rel: "noopener", children: [
2639
+ t("Open the full article"),
2640
+ " ",
2641
+ /* @__PURE__ */ jsx(ArrowUpRight, { size: 14, strokeWidth: 1.8, "aria-hidden": true })
2642
+ ] }),
2643
+ chatReady && /* @__PURE__ */ jsxs(Fragment, { children: [
2644
+ /* @__PURE__ */ jsx("h4", { className: "cbx-help-heading", children: t("Still stuck?") }),
2645
+ /* @__PURE__ */ jsx(
2646
+ AskField,
2647
+ {
2648
+ value: followUp,
2649
+ onChange: setFollowUp,
2650
+ onSubmit: () => {
2651
+ const text = followUp.trim();
2652
+ store.set({ article: null, query: text });
2653
+ setFollowUp("");
2654
+ askCbox(text);
2655
+ },
2656
+ placeholder: t("Ask a follow-up\u2026"),
2657
+ label: t("Ask a follow-up")
2658
+ }
2659
+ )
2660
+ ] })
2661
+ ] });
2662
+ const content = /* @__PURE__ */ jsxs(Fragment, { children: [
2663
+ view === "article" ? reading : view === "home" ? home : null,
2664
+ chatReady && /* @__PURE__ */ jsx("div", { ref: chatHost, className: `cbx-chat-host ${view === "chat" ? "is-open" : ""}`, "data-view": view, children: createElement(SUPPORT_TAG, { "session-url": help.sessionUrl, intent: intentJson, inline: mobile ? "sheet" : "column" }) })
2665
+ ] });
2666
+ const foot = view !== "chat" && (chatReady || portal !== void 0) && /* @__PURE__ */ jsxs("div", { className: "cbx-help-foot", children: [
2667
+ chatReady && /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-help-action", onClick: () => void openChat(t("I would like to talk to a person."), true), children: [
2668
+ /* @__PURE__ */ jsx(UserRound, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2669
+ " ",
2670
+ t("Talk to a person")
2671
+ ] }),
2672
+ portal !== void 0 && /* @__PURE__ */ jsxs("a", { className: "cbx-help-action", href: portal, target: "_blank", rel: "noopener", "aria-label": t("Support portal (opens in a new tab)"), children: [
2673
+ /* @__PURE__ */ jsx(BookOpen, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2674
+ " ",
2675
+ t("Support portal"),
2676
+ " ",
2677
+ /* @__PURE__ */ jsx(ArrowUpRight, { size: 14, strokeWidth: 1.8, "aria-hidden": true })
2678
+ ] })
2679
+ ] });
2680
+ const onScroll = (top) => {
2681
+ if (view !== "chat") store.set({ scrollTop: top });
2311
2682
  };
2312
- const pageArticles = help.articlesUrl !== void 0 ? articles.items : (help.articles ?? []).slice(0, 4);
2313
2683
  if (mobile) {
2314
- const topic = helpTopicName(shell);
2315
- const environment = environmentLevel(shell.context.levels)?.current;
2316
- const where = shell.context.levels.map((level) => level.current.name).join(" \xB7 ");
2317
- const chatReady = help.enabled && help.sessionUrl !== void 0;
2318
- const close = () => toggleHelp(false);
2319
2684
  return /* @__PURE__ */ jsx("div", { ref: scrim, className: "cbx-overlay cbx-sheet-backdrop", hidden: !open, ...scrimHandlers(close), children: /* @__PURE__ */ jsxs(
2320
2685
  "div",
2321
2686
  {
@@ -2335,89 +2700,14 @@ function HelpColumn({ docked, mobile = false }) {
2335
2700
  },
2336
2701
  children: [
2337
2702
  /* @__PURE__ */ jsx("div", { className: "cbx-sheet-handle cbx-sheet-grab", "aria-hidden": "true" }),
2338
- /* @__PURE__ */ jsxs("div", { className: `cbx-sheet-head cbx-sheet-grab ${article !== null ? "has-back" : ""}`, children: [
2339
- article !== null && /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-sheet-back", onClick: () => store.set({ article: null }), "aria-label": t("Back to Help"), children: /* @__PURE__ */ jsx(ChevronLeft, { size: 20, strokeWidth: 1.8, "aria-hidden": true }) }),
2340
- /* @__PURE__ */ jsx("strong", { className: "cbx-sheet-title cbx-truncate", children: article !== null ? t("Article") : t("Help with {page}", { page: topic }) }),
2703
+ /* @__PURE__ */ jsxs("div", { className: `cbx-sheet-head cbx-sheet-grab ${view !== "home" ? "has-back" : ""}`, children: [
2704
+ view !== "home" && /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-sheet-back", onClick: back, "aria-label": t("Back to Help"), children: /* @__PURE__ */ jsx(ChevronLeft, { size: 20, strokeWidth: 1.8, "aria-hidden": true }) }),
2705
+ /* @__PURE__ */ jsx("h2", { className: "cbx-sheet-title cbx-truncate", children: view === "article" ? t("Article") : view === "chat" ? t("Ask Cbox") : t("Help with {page}", { page: topic }) }),
2341
2706
  /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-icon-button", onClick: close, "aria-label": t("Close Help"), children: /* @__PURE__ */ jsx(X, { size: 18, strokeWidth: 1.8, "aria-hidden": true }) })
2342
2707
  ] }),
2343
- /* @__PURE__ */ jsxs("div", { ref: body, className: "cbx-sheet-body", "data-cbx-sheet-scroll": "", onScroll: (event) => store.set({ scrollTop: event.currentTarget.scrollTop }), children: [
2344
- article !== null ? /* @__PURE__ */ jsxs("article", { className: "cbx-help-article", children: [
2345
- /* @__PURE__ */ jsx("h2", { className: "cbx-help-article-title", children: article.title }),
2346
- (article.body ?? article.excerpt ?? "").split(/\n{2,}/).filter(Boolean).map((paragraph, index) => /* @__PURE__ */ jsx("p", { children: paragraph }, index)),
2347
- article.url !== void 0 && /* @__PURE__ */ jsxs("a", { className: "cbx-link", href: article.url, target: "_blank", rel: "noopener", children: [
2348
- t("Open the full article"),
2349
- " ",
2350
- /* @__PURE__ */ jsx(ArrowUpRight, { size: 14, strokeWidth: 1.8, "aria-hidden": true })
2351
- ] }),
2352
- /* @__PURE__ */ jsx("p", { className: "cbx-eyebrow", children: t("Still stuck?") }),
2353
- /* @__PURE__ */ jsxs(
2354
- "form",
2355
- {
2356
- className: "cbx-askbar",
2357
- onSubmit: (event) => {
2358
- event.preventDefault();
2359
- const text = followUp.trim();
2360
- if (text === "") return;
2361
- store.set({ article: null });
2362
- setQuestion(text);
2363
- setAsked(true);
2364
- void openChat(text);
2365
- },
2366
- children: [
2367
- /* @__PURE__ */ jsx("input", { type: "text", value: followUp, onChange: (event) => setFollowUp(event.target.value), placeholder: t("Ask a follow-up\u2026"), "aria-label": t("Ask a follow-up"), disabled: !chatReady }),
2368
- /* @__PURE__ */ jsx("button", { type: "submit", className: "cbx-askbar-send", "aria-label": t("Ask"), disabled: !chatReady, children: /* @__PURE__ */ jsx(ArrowUp, { size: 16, strokeWidth: 2.2, "aria-hidden": true }) })
2369
- ]
2370
- }
2371
- )
2372
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2373
- unavailable && /* @__PURE__ */ jsxs("div", { className: "cbx-help-notice", role: "status", children: [
2374
- /* @__PURE__ */ jsx(CircleAlert, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2375
- /* @__PURE__ */ jsx("span", { children: help.enabled ? t("Help is not available right now. The rest of the app works as usual.") : t("Help is not available here yet.") })
2376
- ] }),
2377
- /* @__PURE__ */ jsxs("form", { className: "cbx-askbar", onSubmit: submit, children: [
2378
- /* @__PURE__ */ jsx("input", { ref: searchField, type: "text", value: question, onChange: (event) => setQuestion(event.target.value), placeholder: t("Ask about {page}\u2026", { page: topic }), "aria-label": t("Ask Cbox"), disabled: !chatReady }),
2379
- /* @__PURE__ */ jsx("button", { type: "submit", className: "cbx-askbar-send", "aria-label": t("Ask"), disabled: !chatReady, children: /* @__PURE__ */ jsx(ArrowUp, { size: 16, strokeWidth: 2.2, "aria-hidden": true }) })
2380
- ] }),
2381
- /* @__PURE__ */ jsxs("p", { className: "cbx-ctxnote", children: [
2382
- environment !== void 0 && /* @__PURE__ */ jsx("span", { className: `cbx-tone cbx-tone-${environment.tone ?? "neutral"}`, "aria-hidden": "true" }),
2383
- t("Cbox sees this page: {page} in {where}", { page: topic, where })
2384
- ] }),
2385
- chatProblem && /* @__PURE__ */ jsx("p", { className: "cbx-create-error", role: "alert", children: t("The chat could not be opened. Try again, or use the support portal.") }),
2386
- asked && chatReady && /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-pbtn", onClick: () => void openChat(t("I would like to talk to a person."), true), children: [
2387
- /* @__PURE__ */ jsx(UserRound, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2388
- " ",
2389
- t("Talk to a person")
2390
- ] }),
2391
- updates.length > 0 && /* @__PURE__ */ jsxs("section", { "aria-labelledby": "cbx-help-threads", children: [
2392
- /* @__PURE__ */ jsx("h2", { id: "cbx-help-threads", className: "cbx-eyebrow", children: t("Your conversations") }),
2393
- /* @__PURE__ */ jsx("div", { className: "cbx-group", children: updates.map((update) => /* @__PURE__ */ jsxs("button", { type: "button", className: `cbx-grow is-tall ${update.unread ? "is-unread" : ""}`, onClick: () => openUpdate(update), children: [
2394
- /* @__PURE__ */ jsx("span", { className: "cbx-tile is-plain", "aria-hidden": "true", children: update.kind === "chat" ? /* @__PURE__ */ jsx(MessageSquare, { size: 16, strokeWidth: 1.8 }) : /* @__PURE__ */ jsx(Ticket, { size: 16, strokeWidth: 1.8 }) }),
2395
- /* @__PURE__ */ jsxs("span", { className: "cbx-grow-text", children: [
2396
- /* @__PURE__ */ jsx("span", { className: "cbx-grow-strong cbx-truncate", children: update.title }),
2397
- update.excerpt !== void 0 && /* @__PURE__ */ jsx("span", { className: "cbx-grow-sub cbx-truncate", children: update.excerpt })
2398
- ] }),
2399
- update.unread && /* @__PURE__ */ jsx("span", { className: "cbx-badge", children: t("{count} new", { count: 1 }) })
2400
- ] }, update.id)) })
2401
- ] }),
2402
- pageArticles.length > 0 && /* @__PURE__ */ jsxs("section", { "aria-labelledby": "cbx-help-for", children: [
2403
- /* @__PURE__ */ jsx("h2", { id: "cbx-help-for", className: "cbx-eyebrow", children: t("For {page}", { page: topic }) }),
2404
- /* @__PURE__ */ jsx("div", { className: "cbx-group", children: pageArticles.map((item) => /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-grow", onClick: () => store.set({ article: item }), children: [
2405
- /* @__PURE__ */ jsx(FileText, { className: "cbx-grow-icon", size: 18, strokeWidth: 1.7, "aria-hidden": true }),
2406
- /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: item.title }),
2407
- /* @__PURE__ */ jsx(ChevronRight, { className: "cbx-grow-trail", size: 16, strokeWidth: 1.8, "aria-hidden": true })
2408
- ] }, item.id)) })
2409
- ] }),
2410
- /* @__PURE__ */ jsxs("div", { className: "cbx-pbtns", children: [
2411
- /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-pbtn", onClick: () => void openChat(t("I would like to talk to a person."), true), disabled: !chatReady, children: t("Chat with support") }),
2412
- portal !== void 0 && /* @__PURE__ */ jsxs("a", { className: "cbx-pbtn", href: portal, target: "_blank", rel: "noopener", children: [
2413
- t("Help center"),
2414
- " ",
2415
- /* @__PURE__ */ jsx(ArrowUpRight, { size: 14, strokeWidth: 1.8, "aria-hidden": true })
2416
- ] })
2417
- ] })
2418
- ] }),
2419
- help.enabled && help.sessionUrl !== void 0 && /* @__PURE__ */ jsx("div", { ref: chatHost, className: "cbx-chat-host", "data-view": article !== null ? "article" : "home", children: createElement(SUPPORT_TAG, { "session-url": help.sessionUrl, intent: intentJson }) })
2420
- ] })
2708
+ view === "chat" && context(true),
2709
+ /* @__PURE__ */ jsx("div", { ref: body, className: `cbx-sheet-body ${view === "chat" ? "is-chat" : ""}`, "data-cbx-sheet-scroll": "", onScroll: (event) => onScroll(event.currentTarget.scrollTop), children: content }),
2710
+ foot
2421
2711
  ]
2422
2712
  }
2423
2713
  ) });
@@ -2437,126 +2727,82 @@ function HelpColumn({ docked, mobile = false }) {
2437
2727
  onKeyDown: (event) => {
2438
2728
  if (event.key === "Escape" && !event.defaultPrevented) {
2439
2729
  event.preventDefault();
2440
- toggleHelp(false);
2730
+ close();
2441
2731
  }
2442
2732
  if (!docked) trapTab(event, column.current);
2443
2733
  },
2444
2734
  children: [
2445
2735
  /* @__PURE__ */ jsxs("div", { className: "cbx-help-head", children: [
2446
- article !== null ? /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-icon-button", onClick: () => store.set({ article: null }), "aria-label": t("Back to Help"), children: /* @__PURE__ */ jsx(ArrowLeft, { size: 18, strokeWidth: 1.8, "aria-hidden": true }) }) : /* @__PURE__ */ jsx(LifeBuoy, { className: "cbx-help-mark", size: 18, strokeWidth: 1.8, "aria-hidden": true }),
2447
- /* @__PURE__ */ jsx("h2", { className: "cbx-help-title", children: t("Help") }),
2448
- portal !== void 0 && /* @__PURE__ */ jsx("a", { className: "cbx-icon-button", href: portal, target: "_blank", rel: "noopener", "aria-label": t("Support portal (opens in a new tab)"), title: t("Support portal"), children: /* @__PURE__ */ jsx(ArrowUpRight, { size: 18, strokeWidth: 1.8, "aria-hidden": true }) }),
2449
- /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-icon-button", onClick: () => toggleHelp(false), "aria-label": t("Close Help"), children: /* @__PURE__ */ jsx(X, { size: 18, strokeWidth: 1.8, "aria-hidden": true }) })
2736
+ view !== "home" ? /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-icon-button", onClick: back, "aria-label": t("Back to Help"), children: /* @__PURE__ */ jsx(ArrowLeft, { size: 18, strokeWidth: 1.8, "aria-hidden": true }) }) : /* @__PURE__ */ jsx(LifeBuoy, { className: "cbx-help-mark", size: 18, strokeWidth: 1.8, "aria-hidden": true }),
2737
+ /* @__PURE__ */ jsx("h2", { className: "cbx-help-title", children: view === "article" ? t("Article") : view === "chat" ? t("Ask Cbox") : t("Help") }),
2738
+ /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-icon-button", onClick: close, "aria-label": t("Close Help"), children: /* @__PURE__ */ jsx(X, { size: 18, strokeWidth: 1.8, "aria-hidden": true }) })
2450
2739
  ] }),
2451
- /* @__PURE__ */ jsxs("p", { className: "cbx-help-page", children: [
2452
- /* @__PURE__ */ jsx("span", { className: "cbx-help-page-label", children: t("On this page") }),
2453
- /* @__PURE__ */ jsxs("span", { className: "cbx-truncate", title: [shell.page?.title, trail].filter(Boolean).join(" \xB7 "), children: [
2454
- shell.page?.title !== void 0 && /* @__PURE__ */ jsx("strong", { children: shell.page.title }),
2455
- shell.page?.title !== void 0 && trail !== "" && " \xB7 ",
2456
- trail
2457
- ] })
2458
- ] }),
2459
- /* @__PURE__ */ jsxs("div", { ref: body, className: "cbx-help-body", onScroll: (event) => store.set({ scrollTop: event.currentTarget.scrollTop }), children: [
2460
- article !== null ? /* @__PURE__ */ jsxs("article", { className: "cbx-help-article", children: [
2461
- /* @__PURE__ */ jsx("h3", { children: article.title }),
2462
- (article.body ?? article.excerpt ?? "").split(/\n{2,}/).filter(Boolean).map((paragraph, index) => /* @__PURE__ */ jsx("p", { children: paragraph }, index)),
2463
- article.url !== void 0 && /* @__PURE__ */ jsxs("a", { className: "cbx-link", href: article.url, target: "_blank", rel: "noopener", children: [
2464
- t("Open the full article"),
2465
- " ",
2466
- /* @__PURE__ */ jsx(ArrowUpRight, { size: 14, strokeWidth: 1.8, "aria-hidden": true })
2467
- ] })
2468
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2469
- unavailable && /* @__PURE__ */ jsxs("div", { className: "cbx-help-notice", role: "status", children: [
2470
- /* @__PURE__ */ jsx(CircleAlert, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2471
- /* @__PURE__ */ jsx("span", { children: help.enabled ? t("Help is not available right now. The rest of the app works as usual.") : t("Help is not available here yet.") }),
2472
- help.enabled && /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-link", onClick: () => {
2473
- loadUpdates();
2474
- setArticles((current) => ({ ...current, status: "loading", topic: void 0 }));
2475
- }, children: t("Try again") })
2476
- ] }),
2477
- unread.length > 0 || updates.length > 0 ? /* @__PURE__ */ jsxs("section", { className: "cbx-help-section", "aria-labelledby": "cbx-help-updates", children: [
2478
- /* @__PURE__ */ jsxs("div", { className: "cbx-pane-heading", children: [
2479
- /* @__PURE__ */ jsx("span", { id: "cbx-help-updates", children: t("Support updates") }),
2480
- unread.length > 0 && /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-pane-all", onClick: () => unread.forEach(markRead), children: t("Mark all read") })
2481
- ] }),
2482
- /* @__PURE__ */ jsx("ul", { className: "cbx-list", role: "list", children: updates.map((update) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs("button", { type: "button", className: `cbx-update ${update.unread ? "is-unread" : ""}`, onClick: () => openUpdate(update), children: [
2483
- update.kind === "chat" ? /* @__PURE__ */ jsx(MessageSquare, { size: 16, strokeWidth: 1.8, "aria-hidden": true }) : /* @__PURE__ */ jsx(Ticket, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2484
- /* @__PURE__ */ jsxs("span", { className: "cbx-update-text", children: [
2485
- /* @__PURE__ */ jsx("span", { className: "cbx-update-title cbx-truncate", title: update.title, children: update.title }),
2486
- update.excerpt !== void 0 && /* @__PURE__ */ jsx("span", { className: "cbx-update-excerpt", children: update.excerpt })
2487
- ] }),
2488
- /* @__PURE__ */ jsxs("span", { className: "cbx-update-meta", children: [
2489
- update.at !== void 0 && /* @__PURE__ */ jsx("time", { dateTime: update.at, children: formatDate(update.at) }),
2490
- update.unread && /* @__PURE__ */ jsx("span", { className: "cbx-unread-dot", "aria-label": t("Unread") })
2491
- ] })
2492
- ] }) }, update.id)) })
2493
- ] }) : null,
2494
- /* @__PURE__ */ jsxs("section", { className: "cbx-help-section", "aria-label": t("Search docs and knowledge base"), children: [
2495
- /* @__PURE__ */ jsxs("div", { className: "cbx-help-search", children: [
2496
- /* @__PURE__ */ jsx(Search, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2497
- /* @__PURE__ */ jsx(
2498
- "input",
2499
- {
2500
- ref: searchField,
2501
- type: "search",
2502
- value: query2,
2503
- onChange: (event) => store.set({ query: event.target.value }),
2504
- placeholder: t("Search docs and knowledge base"),
2505
- "aria-label": t("Search docs and knowledge base"),
2506
- disabled: !help.enabled || help.searchUrl === void 0
2507
- }
2508
- )
2509
- ] }),
2510
- results !== null && /* @__PURE__ */ jsxs("ul", { className: "cbx-list", role: "list", "aria-live": "polite", children: [
2511
- results.items.map((item) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(ArticleRow, { article: item }) }, item.id)),
2512
- results.status === "ready" && results.items.length === 0 && /* @__PURE__ */ jsx("li", { className: "cbx-list-note", children: t("Nothing matches \u201C{query}\u201D.", { query: results.q }) }),
2513
- results.status === "loading" && results.items.length === 0 && /* @__PURE__ */ jsx("li", { className: "cbx-list-note", children: t("Searching\u2026") })
2514
- ] })
2515
- ] }),
2516
- help.topic !== void 0 && pageArticles.length > 0 && /* @__PURE__ */ jsxs("section", { className: "cbx-help-section", "aria-labelledby": "cbx-help-topic", children: [
2517
- /* @__PURE__ */ jsx("div", { className: "cbx-pane-heading", children: /* @__PURE__ */ jsx("span", { id: "cbx-help-topic", children: t("For this page") }) }),
2518
- /* @__PURE__ */ jsx("ul", { className: "cbx-list", role: "list", children: pageArticles.slice(0, 3).map((item) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(ArticleRow, { article: item }) }, item.id)) })
2519
- ] }),
2520
- /* @__PURE__ */ jsxs("section", { className: "cbx-help-section", "aria-labelledby": "cbx-help-ask", children: [
2521
- /* @__PURE__ */ jsx("div", { className: "cbx-pane-heading", children: /* @__PURE__ */ jsx("span", { id: "cbx-help-ask", children: t("Ask Cbox") }) }),
2522
- /* @__PURE__ */ jsxs("form", { className: "cbx-ask", onSubmit: submit, children: [
2523
- /* @__PURE__ */ jsx(
2524
- "textarea",
2525
- {
2526
- className: "cbx-input",
2527
- rows: 3,
2528
- value: question,
2529
- onChange: (event) => setQuestion(event.target.value),
2530
- placeholder: t("Ask about this page\u2026"),
2531
- "aria-label": t("Ask Cbox"),
2532
- disabled: !help.enabled || help.sessionUrl === void 0,
2533
- onKeyDown: (event) => {
2534
- if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) submit(event);
2535
- }
2536
- }
2537
- ),
2538
- /* @__PURE__ */ jsxs("button", { type: "submit", className: "cbx-button cbx-button-primary", disabled: !help.enabled || help.sessionUrl === void 0, children: [
2539
- /* @__PURE__ */ jsx(Sparkles, { size: 15, strokeWidth: 1.8, "aria-hidden": true }),
2540
- " ",
2541
- t("Ask")
2542
- ] })
2543
- ] }),
2544
- chatProblem && /* @__PURE__ */ jsx("p", { className: "cbx-create-error", role: "alert", children: t("The chat could not be opened. Try again, or use the support portal.") })
2545
- ] })
2546
- ] }),
2547
- help.enabled && help.sessionUrl !== void 0 && /* @__PURE__ */ jsx("div", { ref: chatHost, className: "cbx-chat-host", "data-view": article !== null ? "article" : "home", children: createElement(SUPPORT_TAG, { "session-url": help.sessionUrl, intent: intentJson }) })
2548
- ] }),
2549
- /* @__PURE__ */ jsxs("div", { className: "cbx-help-foot", children: [
2550
- /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-row cbx-row-action", onClick: () => void openChat(t("I would like to talk to a person."), true), disabled: !help.enabled || help.sessionUrl === void 0, children: [
2551
- /* @__PURE__ */ jsx(UserRound, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2552
- /* @__PURE__ */ jsx("span", { className: "cbx-row-name", children: t("Talk to a person") })
2553
- ] }),
2554
- portal !== void 0 && /* @__PURE__ */ jsxs("a", { className: "cbx-row cbx-row-action", href: portal, target: "_blank", rel: "noopener", children: [
2555
- /* @__PURE__ */ jsx(BookOpen, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2556
- /* @__PURE__ */ jsx("span", { className: "cbx-row-name", children: t("Support portal") }),
2557
- /* @__PURE__ */ jsx(ArrowUpRight, { className: "cbx-row-trail", size: 14, strokeWidth: 1.8, "aria-hidden": true })
2558
- ] })
2559
- ] })
2740
+ view === "chat" && context(true),
2741
+ /* @__PURE__ */ jsx("div", { ref: body, className: `cbx-help-body ${view === "chat" ? "is-chat" : ""}`, onScroll: (event) => onScroll(event.currentTarget.scrollTop), children: content }),
2742
+ foot
2743
+ ]
2744
+ }
2745
+ );
2746
+ }
2747
+ var CHAT_FLAG = "cbx-help-chat:";
2748
+ function knowsChat(key) {
2749
+ try {
2750
+ return key !== null && localStorage.getItem(CHAT_FLAG + key) === "1";
2751
+ } catch {
2752
+ return false;
2753
+ }
2754
+ }
2755
+ function rememberChat(key) {
2756
+ try {
2757
+ if (key !== null) localStorage.setItem(CHAT_FLAG + key, "1");
2758
+ } catch {
2759
+ }
2760
+ }
2761
+ function AskField({ value, onChange, onSubmit, placeholder, label, field }) {
2762
+ const { t } = useShell();
2763
+ const own = useRef(null);
2764
+ const fit = useCallback(() => {
2765
+ const element = own.current;
2766
+ if (element === null) return;
2767
+ element.style.height = "auto";
2768
+ element.style.height = element.scrollHeight > 0 ? `${Math.min(element.scrollHeight, 120)}px` : "";
2769
+ }, []);
2770
+ useLayoutEffect(fit, [value, fit]);
2771
+ const empty = value.trim() === "";
2772
+ const send = () => {
2773
+ if (!empty) onSubmit?.();
2774
+ };
2775
+ return /* @__PURE__ */ jsxs(
2776
+ "form",
2777
+ {
2778
+ className: "cbx-askfield",
2779
+ onSubmit: (event) => {
2780
+ event.preventDefault();
2781
+ send();
2782
+ },
2783
+ children: [
2784
+ /* @__PURE__ */ jsx(
2785
+ "textarea",
2786
+ {
2787
+ ref: (element) => {
2788
+ own.current = element;
2789
+ if (typeof field === "function") field(element);
2790
+ else if (field != null) field.current = element;
2791
+ },
2792
+ rows: 1,
2793
+ value,
2794
+ onChange: (event) => onChange(event.target.value),
2795
+ placeholder,
2796
+ "aria-label": label,
2797
+ onFocus: fit,
2798
+ onKeyDown: (event) => {
2799
+ if (event.key !== "Enter" || event.shiftKey || event.nativeEvent.isComposing || event.keyCode === 229) return;
2800
+ event.preventDefault();
2801
+ send();
2802
+ }
2803
+ }
2804
+ ),
2805
+ onSubmit !== void 0 && /* @__PURE__ */ jsx("button", { type: "submit", className: "cbx-askfield-send", "aria-label": t("Ask"), disabled: empty, children: /* @__PURE__ */ jsx(ArrowUp, { size: 16, strokeWidth: 2.2, "aria-hidden": true }) })
2560
2806
  ]
2561
2807
  }
2562
2808
  );
@@ -2575,14 +2821,25 @@ function useShortDate(locale, timeZone) {
2575
2821
  return Number.isNaN(date.getTime()) ? iso : format.format(date);
2576
2822
  }, [format]);
2577
2823
  }
2824
+ function ArticleBody({ article, loaded }) {
2825
+ const { t } = useShell();
2826
+ const html = article.bodyHtml ?? loaded?.html ?? null;
2827
+ const clean = useMemo(() => html === null ? "" : cleanArticleHtml(html), [html]);
2828
+ if (clean !== "") return /* @__PURE__ */ jsx("div", { className: "cbx-help-prose", dangerouslySetInnerHTML: { __html: clean } });
2829
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2830
+ (article.body ?? article.excerpt ?? "").split(/\n{2,}/).filter(Boolean).map((paragraph, index) => /* @__PURE__ */ jsx("p", { children: paragraph }, index)),
2831
+ loaded?.status === "loading" && /* @__PURE__ */ jsx("p", { className: "cbx-list-note", role: "status", children: t("Loading\u2026") })
2832
+ ] });
2833
+ }
2578
2834
  function ArticleRow({ article }) {
2579
2835
  const { openArticle } = useShell();
2580
- return /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-update", onClick: () => openArticle(article), children: [
2581
- /* @__PURE__ */ jsx(BookOpen, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2582
- /* @__PURE__ */ jsxs("span", { className: "cbx-update-text", children: [
2583
- /* @__PURE__ */ jsx("span", { className: "cbx-update-title cbx-truncate", title: article.title, children: article.title }),
2584
- article.excerpt !== void 0 && /* @__PURE__ */ jsx("span", { className: "cbx-update-excerpt", children: article.excerpt })
2585
- ] })
2836
+ return /* @__PURE__ */ jsxs("button", { type: "button", className: `cbx-grow ${article.excerpt !== void 0 ? "is-tall" : ""}`, onClick: () => openArticle(article), children: [
2837
+ /* @__PURE__ */ jsx("span", { className: "cbx-tile is-plain", "aria-hidden": "true", children: /* @__PURE__ */ jsx(BookOpen, { size: 16, strokeWidth: 1.8 }) }),
2838
+ /* @__PURE__ */ jsxs("span", { className: "cbx-grow-text", children: [
2839
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-strong cbx-truncate", title: article.title, children: article.title }),
2840
+ article.excerpt !== void 0 && /* @__PURE__ */ jsx("span", { className: "cbx-grow-sub cbx-truncate", children: article.excerpt })
2841
+ ] }),
2842
+ /* @__PURE__ */ jsx(ChevronRight, { className: "cbx-grow-trail", size: 16, strokeWidth: 1.8, "aria-hidden": true })
2586
2843
  ] });
2587
2844
  }
2588
2845
 
@@ -2691,7 +2948,7 @@ function rows(body, group) {
2691
2948
  return Array.isArray(data) ? data.filter((row) => typeof row === "object" && row !== null) : [];
2692
2949
  }
2693
2950
  function CommandPalette({ onClose }) {
2694
- const { shell, t, navigate, switchTo, openArticle, ask, mobile, openContext, openCreate, canCreate, searchRecords } = useShell();
2951
+ const { shell, t, help: helpStore, navigate, switchTo, openArticle, ask, mobile, openContext, openCreate, canCreate, searchRecords } = useShell();
2695
2952
  const [scope, setScope] = useState("all");
2696
2953
  const [input, setInput] = useState("");
2697
2954
  const [query2, setQuery] = useState("");
@@ -2809,10 +3066,15 @@ function CommandPalette({ onClose }) {
2809
3066
  if (settled.every((result) => result.status === "rejected") && settled.length > 0) throw new Error("unavailable");
2810
3067
  return settled.flatMap((result) => result.status === "fulfilled" ? result.value : []);
2811
3068
  });
2812
- if (shell.help.enabled && shell.help.searchUrl !== void 0) {
3069
+ if (helpEndpointState(shell.help, helpStore.get().session, helpSessionKey(shell), "search") !== "none") {
2813
3070
  run(
2814
3071
  "docs",
2815
- async () => parseArticles(await requestJson(withQuery(shell.help.searchUrl, { q: q2, topic: shell.help.topic }), { signal })).map((article) => ({
3072
+ async () => parseArticles(
3073
+ await helpRequest(helpStore, shell, "search", (url) => withQuery(url, { q: q2, topic: shell.help.topic }), { signal }).catch((error) => {
3074
+ if (error instanceof HelpUnavailableError) return [];
3075
+ throw error;
3076
+ })
3077
+ ).map((article) => ({
2816
3078
  id: `doc:${article.id}`,
2817
3079
  title: article.title,
2818
3080
  subtitle: article.excerpt,
@@ -3052,14 +3314,14 @@ function CommandPalette({ onClose }) {
3052
3314
  /* @__PURE__ */ jsx("div", { className: "cbx-scopes", role: "radiogroup", "aria-label": t("Scope"), children: scopes.map((item) => /* @__PURE__ */ jsx("button", { type: "button", role: "radio", "aria-checked": scope === item.value, className: `cbx-scope ${scope === item.value ? "is-on" : ""}`, onClick: () => setScope(item.value), children: item.label }, item.value)) }),
3053
3315
  /* @__PURE__ */ jsxs("div", { id: `${id}-list`, role: "listbox", "aria-label": t("Results"), className: "cbx-palette-list", "data-cbx-sheet-scroll": "", children: [
3054
3316
  rendered.map((section) => {
3055
- const loading = section.state.status === "loading" && section.state.items.length === 0;
3056
- if (section.count === 0 && !loading) return null;
3317
+ const loading2 = section.state.status === "loading" && section.state.items.length === 0;
3318
+ if (section.count === 0 && !loading2) return null;
3057
3319
  return /* @__PURE__ */ jsxs("div", { role: "group", "aria-labelledby": `${id}-${section.key}`, className: "cbx-palette-group", children: [
3058
3320
  /* @__PURE__ */ jsxs("div", { id: `${id}-${section.key}`, className: "cbx-pane-heading", role: "presentation", children: [
3059
3321
  /* @__PURE__ */ jsx("span", { children: section.label }),
3060
3322
  section.state.status === "loading" && /* @__PURE__ */ jsx("span", { className: "cbx-palette-busy", "aria-hidden": "true" })
3061
3323
  ] }),
3062
- loading && /* @__PURE__ */ jsx("div", { className: "cbx-list-note", "aria-live": "polite", children: t("Searching\u2026") }),
3324
+ loading2 && /* @__PURE__ */ jsx("div", { className: "cbx-list-note", "aria-live": "polite", children: t("Searching\u2026") }),
3063
3325
  section.count > 0 && /* @__PURE__ */ jsx("div", { className: "cbx-palette-rows", role: "presentation", children: options.slice(section.start, section.start + section.count).map((option, offset) => {
3064
3326
  const index = section.start + offset;
3065
3327
  const on = index === active;
@@ -5781,7 +6043,7 @@ function InboxSurface({ open, onClose }) {
5781
6043
  const transport = useTransport();
5782
6044
  const cboxId = useCboxIdOptional();
5783
6045
  const [inbox, setInbox] = useState(null);
5784
- const [loading, setLoading] = useState(false);
6046
+ const [loading2, setLoading] = useState(false);
5785
6047
  const [error, setError] = useState(null);
5786
6048
  const [filter, setFilter] = useState("all");
5787
6049
  const userId = cboxId?.user.id ?? null;
@@ -5892,7 +6154,7 @@ function InboxSurface({ open, onClose }) {
5892
6154
  children: error !== null ? /* @__PURE__ */ jsxs("div", { className: "px-5 py-8 text-center", children: [
5893
6155
  /* @__PURE__ */ jsx("p", { className: "text-sm font-medium text-destructive-text", children: t("Couldn't load inbox") }),
5894
6156
  /* @__PURE__ */ jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: error })
5895
- ] }) : loading && inbox === null ? /* @__PURE__ */ jsx("div", { className: "px-5 py-12 text-center text-sm text-muted-foreground", children: t("Loading\u2026") }) : filtered.length === 0 ? /* @__PURE__ */ jsx("div", { className: "px-5 py-12", children: /* @__PURE__ */ jsx(
6157
+ ] }) : loading2 && inbox === null ? /* @__PURE__ */ jsx("div", { className: "px-5 py-12 text-center text-sm text-muted-foreground", children: t("Loading\u2026") }) : filtered.length === 0 ? /* @__PURE__ */ jsx("div", { className: "px-5 py-12", children: /* @__PURE__ */ jsx(
5896
6158
  EmptyState,
5897
6159
  {
5898
6160
  title: filter === "unread" ? t("No unread notifications") : t("No notifications yet"),