diff --git a/branding/apply-branding.mjs b/branding/apply-branding.mjs index ec20ea7..38d71c3 100644 --- a/branding/apply-branding.mjs +++ b/branding/apply-branding.mjs @@ -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); - } - 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)"); - } + 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); } + 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 }) => ( - - ) : undefined - } - {...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 }) => ( - - ) : undefined - } - {...props} - /> - ), - }, - ] - : []),`, + 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"), + } + : item + );`, }, { desc: "hide the unread badge on the account button for non-admins", diff --git a/branding/branding.config.json b/branding/branding.config.json index ef645bc..db6c40d 100644 --- a/branding/branding.config.json +++ b/branding/branding.config.json @@ -28,9 +28,8 @@ "$dictionaries_comment": "Client-editable source dictionaries. After the patch is applied, apply-branding.mjs copies dictionaries/.json over web/public/locales//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": { diff --git a/branding/smb/smb-ui.patch b/branding/smb/smb-ui.patch deleted file mode 100644 index 9018cf5..0000000 --- a/branding/smb/smb-ui.patch +++ /dev/null @@ -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 ( \ No newline at end of file