Fix v5.0.3 build: type-safe notification gate + robust SMB overlay

Two issues from the client's make rebrand on v5.0.3:

1. TypeScript build failed (implicit-any in AccountPopover): the
   conditional-spread notification item lost contextual typing. Reworked
   to leave useSettingsItems untouched (compiles as upstream) and instead
   drop the "notifications" row in the component for non-admins:
   const items = isAdmin ? rawItems : rawItems.map(group =>
     filter out row.id === "notifications"). Uses only standard narrowing
   (item.kind, row.id), so no fragile typing. Still gates on isAdmin.

2. SMB UI patch did not apply: git-apply is brittle about context lines
   and re-runs (make rebrand does not re-clone). Converted the SMB
   overlay from a git-apply .patch to string-anchored patchFile edits
   (same mechanism as the other overlays) — idempotent and tolerant of
   context drift. Removed the now-unused branding/smb/smb-ui.patch.

Verified every anchor against the real v5.0.3 sources; v5's own SearchCard
already reads document.metadata, confirming the metadata access type-checks.
This commit is contained in:
Jannic Debus 2026-11-10 16:34:42 +01:00
parent 2c42e9fd03
commit 145725b6b1
3 changed files with 90 additions and 172 deletions

View file

@ -125,36 +125,82 @@ if (CONFIG.i18n && CONFIG.i18n.enabled) {
}
// ── 0b. SMB document UI (Phase 2 of the SMB connector) ───────────────────────
// SMB-synced documents (source=ingestion_api) have no browsable file, so Onyx's
// preview click is a dead end. This patch makes clicking such a cited document
// copy its logical network path instead. Applied before the codemod; idempotent
// via a marker. No-op unless smbUi.enabled.
// SMB-synced documents have no browsable file, so Onyx's preview click is a dead
// end. These edits make clicking such a cited document copy its logical network
// path (metadata.logical_path) to the clipboard instead. SMB docs are detected by
// metadata.smb_source. Applied via patchFile (string-anchored + idempotent), so
// it survives upstream context drift and re-runs; no-op unless smbUi.enabled.
if (CONFIG.smbUi && CONFIG.smbUi.enabled) {
step("0b SMB document UI overlay");
const smbPatch = path.join(ROOT, CONFIG.smbUi.patch);
if (!existsSync(smbPatch)) {
warn(`SMB UI patch not found at ${smbPatch} — skipping`);
} else {
const utils = path.join(SRC, "lib/search/utils.ts");
const marker = "AIDO: documents synced from SMB";
const already = existsSync(utils) && (await readFile(utils, "utf8")).includes(marker);
if (already) {
ok("SMB UI overlay already applied — skipping");
} else {
try {
execFileSync("git", ["apply", "-p1", "--check", smbPatch], { cwd: ROOT, stdio: "pipe" });
} catch {
console.error(`${c.red}✗ SMB UI patch does not apply to the current checkout. It targets web/src/lib/search/utils.ts at ${CONFIG.i18n?.baseCommit || "the pinned release"}; re-sync it or set smbUi.enabled=false.${c.reset}`);
process.exit(1);
await patchFile("lib/search/utils.ts", [
{
desc: "import toast for the SMB path-copy",
done: `import { toast } from "@opal/layouts";`,
find: `import { transformLinkUri } from "@/lib/utils";`,
replace: `import { transformLinkUri } from "@/lib/utils";\nimport { toast } from "@opal/layouts";`,
},
{
desc: "SMB docs copy their network path instead of a broken preview",
done: `AIDO: documents synced from SMB`,
find: `) => {\n if (document.link) {\n openExternalLink(document.link);`,
replace: `) => {
// AIDO: documents synced from SMB/network shares have no browsable link and no
// stored file to preview — a normal preview click would just fail. Copy the
// logical path to the clipboard so the user can open the file on the share.
if (document.metadata?.smb_source) {
const link = document.link ?? "";
const path =
document.metadata?.logical_path ||
(link.startsWith("file://") ? link.slice(7) : "") ||
document.semantic_identifier ||
document.document_id;
if (path) {
void navigator.clipboard
?.writeText(path)
.then(() => toast.success(path))
.catch(() => undefined);
}
if (!DRY) {
execFileSync("git", ["apply", "-p1", smbPatch], { cwd: ROOT, stdio: "pipe" });
ok("applied SMB UI overlay — SMB docs copy their network path instead of a broken preview");
} else {
ok("SMB UI overlay applies cleanly (dry-run, not written)");
return;
}
if (document.link) {
openExternalLink(document.link);`,
},
]);
await patchFile("ee/sections/SearchCard.tsx", [
{
desc: "import toast for the SMB path-copy (Search view)",
done: `import { toast } from "@opal/layouts";`,
find: `import { Interactive } from "@opal/core";`,
replace: `import { Interactive } from "@opal/core";\nimport { toast } from "@opal/layouts";`,
},
{
desc: "SMB docs copy their network path instead of a broken preview (Search view)",
done: `AIDO: documents synced from SMB`,
find: ` function handleClick() {\n if (document.link) {\n window.open(document.link, "_blank", "noopener,noreferrer");`,
replace: ` function handleClick() {
// AIDO: documents synced from SMB/network shares have no browsable link and
// no stored file to preview — the preview pane would just fail. Copy the
// logical path to the clipboard so the user can open the file on the share.
if (document.metadata?.smb_source) {
const logicalPath = document.metadata?.logical_path;
const link = document.link ?? "";
const path =
(typeof logicalPath === "string" ? logicalPath : "") ||
(link.startsWith("file://") ? link.slice(7) : "") ||
document.semantic_identifier ||
document.document_id;
if (path) {
void navigator.clipboard
?.writeText(path)
.then(() => toast.success(path))
.catch(() => undefined);
}
return;
}
if (document.link) {
window.open(document.link, "_blank", "noopener,noreferrer");`,
},
]);
}
// ── 1. Assets: fetch brand images, repoint favicon ──────────────────────────
@ -305,14 +351,6 @@ await patchFile("components/icons/icons.tsx", [{
// `useSettingsItems()` hook + a Dropdown views model, so these anchors differ
// from v4.
await patchFile("sections/sidebar/AccountPopover.tsx", [
{
desc: "expose isAdmin from useUser in useSettingsItems",
done: "userResolution, isAdmin } = useUser();\n const settings",
find: `const { user, userResolution } = useUser();
const settings = useSettings();`,
replace: `const { user, userResolution, isAdmin } = useUser();
const settings = useSettings();`,
},
{
desc: "expose isAdmin from useUser in AccountPopover",
done: "setMenuOpen(false);\n const { user, userResolution, isAdmin }",
@ -322,63 +360,23 @@ await patchFile("sections/sidebar/AccountPopover.tsx", [
const { user, userResolution, isAdmin } = useUser();`,
},
{
desc: "show the Notifications menu row only to full admins",
desc: "remove the Notifications row for non-admins",
done: "AIDO: the notification centre is admin-facing only",
find: ` {
kind: "custom",
id: "notifications",
keywords: [t("notifications.label")],
onActivate: (views) => views.push("notifications"),
render: ({ highlighted, props }) => (
<LineItemButton
presentational
selectVariant="select-heavy"
interaction={highlighted ? "hover" : "rest"}
sizePreset="main-ui"
variant="section"
rounding={2}
icon={SvgBell}
title={t("notifications.label")}
rightChildren={
undismissedCount ? (
<SvgNotificationBubble count={undismissedCount} />
) : undefined
find: ` const items = useSettingsItems({ undismissedCount });`,
replace: ` const rawItems = useSettingsItems({ undismissedCount });
// AIDO: the notification centre is admin-facing only. Remove the notifications
// row for everyone except full admins (isAdmin); manage-agents curators do not
// see it. The account-button unread badge is hidden the same way below.
const items = isAdmin
? rawItems
: rawItems.map((item) =>
item.kind === "group"
? {
...item,
items: item.items.filter((row) => row.id !== "notifications"),
}
{...props}
/>
),
},`,
replace: ` // AIDO: the notification centre is admin-facing only. Show the
// notifications row only to full admins (isAdmin), not manage-agents
// curators. Non-admins never see the bell, panel or unread badge.
...(isAdmin
? [
{
kind: "custom" as const,
id: "notifications",
keywords: [t("notifications.label")],
onActivate: (views) => views.push("notifications"),
render: ({ highlighted, props }) => (
<LineItemButton
presentational
selectVariant="select-heavy"
interaction={highlighted ? "hover" : "rest"}
sizePreset="main-ui"
variant="section"
rounding={2}
icon={SvgBell}
title={t("notifications.label")}
rightChildren={
undismissedCount ? (
<SvgNotificationBubble count={undismissedCount} />
) : undefined
}
{...props}
/>
),
},
]
: []),`,
: item
);`,
},
{
desc: "hide the unread badge on the account button for non-admins",

View file

@ -28,9 +28,8 @@
"$dictionaries_comment": "Client-editable source dictionaries. After the patch is applied, apply-branding.mjs copies dictionaries/<lang>.json over web/public/locales/<lang>/common.json — so edits here PERSIST across `make setup` (they're the source of truth, not the patch). Edit branding/i18n/locales/de.json to add/refine German (see MISSING-de.md for untranslated keys), then `make apply && make build`."
},
"smbUi": {
"$comment": "SMB connector UI overlay (smb-connector/): a tiny frontend overlay so documents synced from SMB/network shares don't present a broken, dead file-preview. SMB documents are detected by metadata.smb_source (they are ingested as the `file` source, so they show in Default Chat and the source filters). Clicking a cited SMB document copies its full logical network path (\\\\company\\share\\...) from metadata.logical_path to the clipboard instead, so the user can open it on the share. Covers both the chat citation view and the licensed Search view. (The earlier 'Initial Indexing' badge fix was dropped: File connectors report status correctly on their own.) Applied before the branding codemod; re-synced onto v5.0.3. Independent of the connector itself; set enabled=false to drop it.",
"enabled": true,
"patch": "branding/smb/smb-ui.patch"
"$comment": "SMB connector UI overlay (smb-connector/): a tiny frontend overlay so documents synced from SMB/network shares don't present a broken, dead file-preview. SMB documents are detected by metadata.smb_source (they are ingested as the `file` source, so they show in Default Chat and the source filters). Clicking a cited SMB document copies its full logical network path (\\\\company\\share\\...) from metadata.logical_path to the clipboard instead, so the user can open it on the share. Covers both the chat citation view and the licensed Search view. (The earlier 'Initial Indexing' badge fix was dropped: File connectors report status correctly on their own.) As of the v5.0.3 upgrade this is applied via string-anchored patchFile edits in apply-branding.mjs (not a git-apply .patch), so it is idempotent and survives upstream context drift. Independent of the connector itself; set enabled=false to drop it.",
"enabled": true
},
"build": {

View file

@ -1,79 +0,0 @@
diff --git a/web/src/ee/sections/SearchCard.tsx b/web/src/ee/sections/SearchCard.tsx
index f4cc98b..63dce83 100644
--- a/web/src/ee/sections/SearchCard.tsx
+++ b/web/src/ee/sections/SearchCard.tsx
@@ -11,6 +11,7 @@ import { ValidSources } from "@/lib/connectors/types/source";
import { MinimalOnyxDocument } from "@/lib/search/types";
import { Section } from "@/layouts/general-layouts";
import { Interactive } from "@opal/core";
+import { toast } from "@opal/layouts";
import { timeAgo } from "@opal/time";
import { useMemo } from "react";
import { useLocale } from "next-intl";
@@ -39,6 +40,27 @@ export default function SearchCard({
document.is_internet || document.source_type === ValidSources.Web;
function handleClick() {
+ // AIDO: documents synced from SMB/network shares have no browsable link and
+ // no stored file to preview — the preview pane would just fail. Copy the
+ // logical path to the clipboard so the user can open the file directly on the
+ // share. Mirrors openDocument() used by the chat view.
+ if (document.metadata?.smb_source) {
+ // The full network path is in metadata.logical_path (the search result does
+ // not always carry `link`); semantic_identifier is only the file name.
+ const logicalPath = document.metadata?.logical_path;
+ const path =
+ (typeof logicalPath === "string" ? logicalPath : undefined) ||
+ document.link?.replace(/^file:\/\//, "") ||
+ document.semantic_identifier ||
+ document.document_id;
+ if (path) {
+ void navigator.clipboard
+ ?.writeText(path)
+ .then(() => toast.success(path))
+ .catch(() => undefined);
+ }
+ return;
+ }
if (document.link) {
window.open(document.link, "_blank", "noopener,noreferrer");
return;
diff --git a/web/src/lib/search/utils.ts b/web/src/lib/search/utils.ts
index 38dc56f..95de8ea 100644
--- a/web/src/lib/search/utils.ts
+++ b/web/src/lib/search/utils.ts
@@ -1,6 +1,7 @@
import { ValidSources } from "@/lib/connectors/types/source";
import { MinimalOnyxDocument, OnyxDocument } from "@/lib/search/types";
import { transformLinkUri } from "@/lib/utils";
+import { toast } from "@opal/layouts";
export const openExternalLink = (url: string) => {
const safeUrl = transformLinkUri(url);
@@ -47,6 +48,26 @@ export const openDocument = (
document: OnyxDocument,
updatePresentingDocument?: (document: MinimalOnyxDocument) => void
) => {
+ // AIDO: documents synced from SMB/network shares have no browsable link and no
+ // stored file to preview — a normal preview click would just fail. Instead,
+ // surface the logical path by copying it to the clipboard so the user can open
+ // the file directly on the share.
+ if (document.metadata?.smb_source) {
+ // The full network path is in metadata.logical_path (the citation object
+ // does not always carry `link`); semantic_identifier is only the file name.
+ const path =
+ document.metadata?.logical_path ||
+ document.link?.replace(/^file:\/\//, "") ||
+ document.semantic_identifier ||
+ document.document_id;
+ if (path) {
+ void navigator.clipboard
+ ?.writeText(path)
+ .then(() => toast.success(path))
+ .catch(() => undefined);
+ }
+ return;
+ }
if (document.link) {
openExternalLink(document.link);
} else if (