PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.7
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.7
1.1.11 1.1.10 1.1.9 1.1.8 1.1.7 1.1.6 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.1 1.0.0 0.9.8 0.9.7 0.9.6 0.9.4 0.9.5 0.9.3 0.9.2 0.9.1 0.9.0 0.8.9 0.8.8 All 35 releases
desktop-mode / assets / js / ai-assistant.min.js

ai-assistant.min.js in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.1.7, at assets/js/ai-assistant.min.js

160 lines 46.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function(){"use strict";function D(){const n=window.wp?.hooks;if(!n)throw new Error("[openstation] `window.wp.hooks` is not available. The plugin declares `wp-hooks` as a script dependency; if you are seeing this error, verify the enqueue order.");return n}function x(n,e,...s){return D().applyFilters(n,e,...s)}function b(n,...e){D().doAction(n,...e)}const f={INIT:"os.init",WALLPAPERS:"os.wallpapers",GAMES:"os.games",UNFOCUS_EFFECTS:"os.unfocus-effects",WINDOW_REVEALS:"os.window-reveals",WALLPAPER_MOUNTING:"os.wallpaper.mounting",WALLPAPER_MOUNTED:"os.wallpaper.mounted",WALLPAPER_UNMOUNTING:"os.wallpaper.unmounting",WALLPAPER_MOUNT_FAILED:"os.wallpaper.mount-failed",WALLPAPER_VISIBILITY:"os.wallpaper.visibility",WALLPAPER_SUSPEND:"os.wallpaper.suspend",WALLPAPER_PREVIEW_PARAMS:"os.wallpaper.preview-params",WALLPAPER_SETTINGS_CHANGED:"os.wallpaper.settings-changed",IFRAME_READY:"os.iframe.ready",IFRAME_ERROR:"os.iframe.error",IFRAME_NETWORK_COMPLETED:"os.iframe.network-completed",SHELL_ERROR:"os.shell.error",BROADCAST:"os.broadcast",MONITOR_ENTRY:"os.monitor.entry",WALLPAPER_SURFACES:"os.wallpaper.surfaces",DESKTOP_THEME_CHANGED:"os.os-theme.changed",DESKTOP_THEME_ICON:"os.os-theme.icon",DESKTOP_THEME_ICON_COLOR:"os.os-theme.icon-color",WALLPAPERS_SERVER_CHANGED:"os.wallpapers.server-changed",EXTENDED_OPTIONS_CHANGED:"os.extended-options.changed",WINDOW_GEOMETRY:"os.window.geometry",WINDOW_OPENED:"os.window.opened",WINDOW_CONTENT_LOADING:"os.window.content-loading",WINDOW_CONTENT_LOADED:"os.window.content-loaded",WINDOW_LOADING_OVERLAY:"os.window.loading-overlay",WINDOW_REOPENED:"os.window.reopened",WINDOW_MENU_OPENED:"os.window.menu-opened",WINDOW_CLOSING:"os.window.closing",WINDOW_CLOSED:"os.window.closed",WINDOW_FOCUSED:"os.window.focused",WINDOW_BLURRED:"os.window.blurred",WINDOW_MINIMIZED:"os.window.minimized",WINDOW_RESTORED:"os.window.restored",WINDOW_CHILD_BLOCKED:"os.window.child-blocked",WINDOW_MAXIMIZED:"os.window.maximized",WINDOW_UNMAXIMIZED:"os.window.unmaximized",WINDOW_FULLSCREEN_ENTERED:"os.window.fullscreen-entered",WINDOW_FULLSCREEN_EXITED:"os.window.fullscreen-exited",WINDOW_AUTO_EXIT_FULLSCREEN:"os.window.auto-exit-fullscreen",WINDOW_FOCUS_ON_DRAG_HOVER:"os.window.focus-on-drag-hover",WINDOW_BOUNDS_CHANGED:"os.window.bounds-changed",WINDOW_MOVED:"os.window.moved",WINDOW_RESIZED:"os.window.resized",WINDOW_DRAG_START:"os.window.drag-start",WINDOW_DRAG_END:"os.window.drag-end",WINDOW_RESIZE_START:"os.window.resize-start",WINDOW_RESIZE_END:"os.window.resize-end",WINDOW_DETACHED:"os.window.detached",WINDOW_RELOADED:"os.window.reloaded",WINDOW_TITLE_CHANGED:"os.window.title-changed",WINDOW_HIGHLIGHT_CHANGED:"os.window.highlight-changed",WINDOW_BODY_RESIZED:"os.window.body-resized",NATIVE_WINDOW_BEFORE_RENDER:"os.native-window.before-render",NATIVE_WINDOW_AFTER_RENDER:"os.native-window.after-render",NATIVE_WINDOW_BEFORE_CLOSE:"os.native-window.before-close",WINDOW_CHROME_THEME:"os.window.chrome.theme",WINDOW_CHROME_CONTROLS:"os.window.chrome.controls",WINDOW_CHROME_SLOT:"os.window.chrome.slot",WINDOW_CHROME_RENDER:"os.window.chrome.render",WINDOW_CHROME_APPLIED:"os.window.chrome.applied",WINDOW_CHROME_THEME_CHANGED:"os.window.chrome.theme-changed",DESKTOP_ICON_CLICKED:"os.os-icon.clicked",DESKTOP_ICONS_RENDERED:"os.os-icons.rendered",ICON_BADGE_CHANGED:"os.icon.badge-changed",COMPONENTS_REGISTERED:"os.components.registered",DOCK_ITEM_APPENDED:"os.dock.item-appended",DOCK_ITEM_REMOVED:"os.dock.item-removed",DOCK_BEFORE_RENDER:"os.dock.before-render",DOCK_AFTER_RENDER:"os.dock.after-render",DOCK_REFRESH_ACTIVE:"os.dock.refresh-active",DOCK_TILE_CLASS:"os.dock.tile-class",DOCK_TILE_ELEMENT:"os.dock.tile-element",DOCK_TILE_RENDERED:"os.dock.tile-rendered",DOCK_TILE_TOOLTIP:"os.dock.tile-tooltip",DOCK_PEEK_CARD_CONTENT:"os.dock.peek-card-content",DOCK_PEEK_CARD_ELEMENT:"os.dock.peek-card-element",CONSTELLATION_PANEL:"os.constellation.panel",CONSTELLATION_OPENED:"os.constellation.opened",CONSTELLATION_CLOSED:"os.constellation.closed",OVERVIEW_ENTERING:"os.overview.entering",OVERVIEW_ENTERED:"os.overview.entered",OVERVIEW_EXITING:"os.overview.exiting",OVERVIEW_EXITED:"os.overview.exited",OVERVIEW_WINDOW_HOVER:"os.overview.window-hover",OVERVIEW_WINDOW_UNHOVER:"os.overview.window-unhover",OVERVIEW_WINDOW_CLICK:"os.overview.window-click",WORK_AREA_CHANGED:"os.work-area.changed",ARRANGE_CASCADE_STARTING:"os.arrange.cascade.starting",ARRANGE_CASCADE_APPLIED:"os.arrange.cascade.applied",ARRANGE_TILE_STARTING:"os.arrange.tile.starting",ARRANGE_TILE_APPLIED:"os.arrange.tile.applied",ARRANGE_TILE_DIMENSIONS:"os.arrange.tile.dimensions",ARRANGE_COLUMNS_STARTING:"os.arrange.columns.starting",ARRANGE_COLUMNS_APPLIED:"os.arrange.columns.applied",ARRANGE_FOCUS_SPLIT:"os.arrange.focus.split",ARRANGE_FOCUS_STARTING:"os.arrange.focus.starting",ARRANGE_FOCUS_APPLIED:"os.arrange.focus.applied",ARRANGE_SNAP_CHANGED:"os.arrange.snap.changed",ARRANGE_SNAP_CELL_SIZE:"os.arrange.snap.cell-size",ARRANGE_CUSTOM_ACTION:"os.arrange.custom-action",POINTER_SHAKE:"os.pointer.shake",GRID_SNAP_DIMENSIONS:"os.grid-snap.dimensions",GRID_SNAP_ARMED:"os.grid-snap.armed",GRID_SNAP_CHANGED:"os.grid-snap.changed",GRID_SNAP_ANCHOR_RESET:"os.grid-snap.anchor-reset",GRID_SNAP_CANCELED:"os.grid-snap.canceled",GRID_SNAP_COMMITTED:"os.grid-snap.committed",GRID_SNAP_REFLOWED:"os.grid-snap.reflowed",SNAP_ZONE_PENDING:"os.snap.zone-pending",SNAP_ZONE_CANCELED:"os.snap.zone-canceled",SNAP_ZONE_COMMITTED:"os.snap.zone-committed",SNAP_SPLIT_FILLED:"os.snap.split-filled",WIDGETS:"os.widgets",WIDGET_MOUNTING:"os.widget.mounting",WIDGET_MOUNTED:"os.widget.mounted",WIDGET_UNMOUNTING:"os.widget.unmounting",WIDGET_MOUNT_FAILED:"os.widget.mount-failed",WIDGET_ADDED:"os.widget.added",WIDGET_REMOVED:"os.widget.removed",DESKTOP_CREATED:"os.os.created",DESKTOP_CLOSED:"os.os.closed",DESKTOP_SWITCHED:"os.os.switched",DESKTOP_RENAMED:"os.os.renamed",WINDOW_DESKTOP_CHANGED:"os.os.window-moved",PRIMARY_DESKTOP_ID:"os.primary-desktop-id",WORKSPACE_PRESETS:"os.workspaces.presets",WORKSPACE_PROFILE:"os.workspaces.profile",WORKSPACE_UPDATED:"os.workspaces.updated",WORKSPACE_PROVISIONED:"os.workspaces.provisioned",WINDOWS_BEFORE_CLOSE_ALL:"os.windows.before-close-all",WINDOWS_CLOSE_ALL:"os.windows.close-all",WINDOWS_AFTER_CLOSE_ALL:"os.windows.after-close-all",COMMAND_BEFORE_RUN:"os.command.before-run",COMMAND_AFTER_RUN:"os.command.after-run",COMMAND_ERROR:"os.command.error",SHELL_RESIZED:"os.shell.resized",SHELL_VISIBILITY:"os.shell.visibility",CONNECTION_OPENED:"os.connection.opened",CONNECTION_CLOSED:"os.connection.closed",CONNECTION_MESSAGE:"os.connection.message",IFRAME_CONNECTION_REQUEST:"os.iframe.connection-request",WINDOW_CONTENT_CHANGED:"os.window-links.content-changed",WINDOW_LINK_GROUPS_CHANGED:"os.window-links.groups-changed",WINDOW_LINKS_CONTENT:"os.window-links.content",WINDOW_LINK_GROUPS:"os.window-links.groups",WINDOW_LINK_EDGES:"os.window-links.edges",RELATED_ENTITIES_ITEMS:"os.related-entities.items",WINDOW_LINK_RENDERERS:"os.window-links.renderers",WINDOW_LINK_RENDERER:"os.window-links.renderer",EDITOR_PREVIEW_WINDOW_CONFIG:"os.editor-preview.window-config",EDITOR_PREVIEW_LIVE:"os.editor-preview.live",EDITOR_PREVIEW_OPENED:"os.editor-preview.opened",EDITOR_PREVIEW_CLOSED:"os.editor-preview.closed",REVISIONS_WINDOW_CONFIG:"os.revisions.window-config",REVISIONS_OPENED:"os.revisions.opened",FILE_DROP_FILES_DETECTED:"os.drop.files-detected",FILE_DROP_FILES_REJECTED:"os.drop.files-rejected",FILE_DROP_DIALOG_FIELDS:"os.drop.dialog-fields",FILE_DROP_BEFORE_UPLOAD:"os.drop.before-upload",FILE_DROP_UPLOAD_STARTED:"os.drop.upload-started",FILE_DROP_UPLOAD_PROGRESS:"os.drop.upload-progress",FILE_DROP_AFTER_UPLOAD:"os.drop.after-upload",FILE_DROP_UPLOAD_FAILED:"os.drop.upload-failed",AUTH_LOST:"os.auth.lost",AUTH_RESTORED:"os.auth.restored",MODE_CHANGED:"os.mode.changed",SESSION_SNAPSHOT:"os.session.snapshot"},R="desktop-mode";function g(){return window.wp?.i18n}function l(n,e=R){return g()?.__(n,e)??n}function G(n,e,s=R){return g()?._x(n,e,s)??n}function h(n,...e){const s=g()?.sprintf;if(s)return s(n,...e);let t=0;return n.replace(/%(?:(\d+)\$)?[sd]/g,(o,i)=>{const r=i?Number.parseInt(i,10)-1:t++;return String(e[r]??"")})}let w=null;function v(){return!!window.openStationShellOverlays}function F(n){return new Promise((e,s)=>{const t=document.querySelector('script[data-os-shell-overlays="1"]'),o=()=>{if(v()){e();return}s(new Error("[openstation] shell-overlays bundle loaded but did not set `window.openStationShellOverlays`."))};if(t){v()?o():(t.addEventListener("load",o),t.addEventListener("error",()=>s(new Error("failed to load shell-overlays bundle"))));return}const i=document.createElement("script");i.src=n,i.async=!0,i.dataset.osShellOverlays="1",i.addEventListener("load",o),i.addEventListener("error",()=>s(new Error("failed to load shell-overlays bundle"))),document.head.appendChild(i)})}function U(n){return v()||!n?Promise.resolve():(w||(w=F(n)),w)}function V(){return window.openStationConfig?.shellOverlaysBundleUrl??""}async function K(n){return await U(V()),new Promise(e=>{const s=document.createElement("os-confirm-dialog");s.setAttribute("open",""),n.title&&s.setAttribute("title",n.title),s.setAttribute("message",n.message),n.confirmLabel&&s.setAttribute("confirm-label",n.confirmLabel),n.cancelLabel&&s.setAttribute("cancel-label",n.cancelLabel),n.danger&&s.setAttribute("danger",""),n.hideCancel&&s.setAttribute("hide-cancel",""),n.dismissable&&s.setAttribute("dismissable",""),n.rememberLabel&&s.setAttribute("remember-label",n.rememberLabel);const t=o=>{s.remove(),e(o)};s.addEventListener("os-confirm",o=>{n.onRemember?.(o.detail?.remember===!0),t(!0)}),s.addEventListener("os-cancel",()=>t(!1)),document.body.appendChild(s)})}const L="X-WP-Nonce";function q(n,e){const s=B();if(!s)return e;const t=Z(n);if(!t||!z(t))return e;const o=e?.headers??(typeof Request<"u"&&n instanceof Request?n.headers:void 0),i=new Headers(o??{});return i.has(L)?e:(i.set(L,s),{...e??{},headers:i})}function B(){if(typeof window>"u")return;const e=window.openStationConfig?.restNonce;return typeof e=="string"&&e.length>0?e:void 0}function Z(n){try{const e=typeof window<"u"&&window.location?window.location.href:void 0;return typeof n=="string"?new URL(n,e):n instanceof URL?n:typeof Request<"u"&&n instanceof Request?new URL(n.url,e):null}catch{return null}}function z(n){return typeof window>"u"||!window.location||n.origin!==window.location.origin?!1:!!(n.pathname.includes("/wp-json/")||n.searchParams.has("rest_route"))}function y(n,e,s={}){const t=window.wp?.os?.fetch;if(typeof t=="function")return t(n,e,s);const o=q(n,e);return fetch(n,o)}function j(n){const e=document.createElement("textarea");return e.innerHTML=n,e.value}const X='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M12 4c-4.4 0-8 3.6-8 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8Zm0 1.5c3.4 0 6.2 2.7 6.5 6l-1.2-.6-.8-.4c-.1 0-.2 0-.3-.1H16c-.1-.2-.4-.2-.7 0l-2.9 2.1L9 11.3h-.7L5.5 13v-1.1c0-3.6 2.9-6.5 6.5-6.5Zm0 13c-2.7 0-5-1.7-6-4l2.8-1.7 3.5 1.2h.4s.2 0 .4-.2l2.9-2.1.4.2c.6.3 1.4.7 2.1 1.1-.5 3.1-3.2 5.4-6.4 5.4Z"/></svg>',k={close:{a:'fill="currentColor"',b:'<path d="m13.06 12 6.47-6.47-1.06-1.06L12 10.94 5.53 4.47 4.47 5.53 10.94 12l-6.47 6.47 1.06 1.06L12 13.06l6.47 6.47 1.06-1.06L13.06 12Z" />'},check:{a:'fill="currentColor"',b:'<path d="M16.5 7.5 10 13.9l-2.5-2.4-1 1 3.5 3.6 7.5-7.6z" />'},"chevron-right":{a:'fill="currentColor"',b:'<path d="M10.6 6L9.4 7l4.6 5-4.6 5 1.2 1 5.4-6z" />'},"arrow-up-right":{a:'fill="currentColor"',b:'<path d="M10 6H18V14H16.5V8.5L7 18L6 17L15.5 7.5H10V6Z" />'},plus:{a:'fill="currentColor"',b:'<path d="M11 12.5V17.5H12.5V12.5H17.5V11H12.5V6H11V11H6V12.5H11Z" />'},search:{a:'fill="currentColor"',b:'<path d="M13 5c-3.3 0-6 2.7-6 6 0 1.4.5 2.7 1.3 3.7l-3.8 3.8 1.1 1.1 3.8-3.8c1 .8 2.3 1.3 3.7 1.3 3.3 0 6-2.7 6-6S16.3 5 13 5zm0 10.5c-2.5 0-4.5-2-4.5-4.5s2-4.5 4.5-4.5 4.5 2 4.5 4.5-2 4.5-4.5 4.5z" />'},pin:{a:'fill="currentColor"',b:'<path d="m21.5 9.1-6.6-6.6-4.2 5.6c-1.2-.1-2.4.1-3.6.7-.1 0-.1.1-.2.1-.5.3-.9.6-1.2.9l3.7 3.7-5.7 5.7v1.1h1.1l5.7-5.7 3.7 3.7c.4-.4.7-.8.9-1.2.1-.1.1-.2.2-.3.6-1.1.8-2.4.6-3.6l5.6-4.1zm-7.3 3.5.1.9c.1.9 0 1.8-.4 2.6l-6-6c.8-.4 1.7-.5 2.6-.4l.9.1L15 4.9 19.1 9l-4.9 3.6z" />'},trash:{a:'fill="currentColor"',b:'<path fill-rule="evenodd" clip-rule="evenodd" d="M12 5.5A2.25 2.25 0 0 0 9.878 7h4.244A2.251 2.251 0 0 0 12 5.5ZM12 4a3.751 3.751 0 0 0-3.675 3H5v1.5h1.27l.818 8.997a2.75 2.75 0 0 0 2.739 2.501h4.347a2.75 2.75 0 0 0 2.738-2.5L17.73 8.5H19V7h-3.325A3.751 3.751 0 0 0 12 4Zm4.224 4.5H7.776l.806 8.861a1.25 1.25 0 0 0 1.245 1.137h4.347a1.25 1.25 0 0 0 1.245-1.137l.805-8.861Z" />'},download:{a:'fill="currentColor"',b:'<path d="M18 11.3l-1-1.1-4 4V3h-1.5v11.3L7 10.2l-1 1.1 6.2 5.8 5.8-5.8zm.5 3.7v3.5h-13V15H4v5h16v-5h-1.5z" />'},settings:{a:'fill="currentColor"',b:'<path d="m19 7.5h-7.628c-.3089-.87389-1.1423-1.5-2.122-1.5-.97966 0-1.81309.62611-2.12197 1.5h-2.12803v1.5h2.12803c.30888.87389 1.14231 1.5 2.12197 1.5.9797 0 1.8131-.62611 2.122-1.5h7.628z" /><path d="m19 15h-2.128c-.3089-.8739-1.1423-1.5-2.122-1.5s-1.8131.6261-2.122 1.5h-7.628v1.5h7.628c.3089.8739 1.1423 1.5 2.122 1.5s1.8131-.6261 2.122-1.5h2.128z" />'},info:{a:'fill="currentColor"',b:'<path fill-rule="evenodd" clip-rule="evenodd" d="M5.5 12a6.5 6.5 0 1 0 13 0 6.5 6.5 0 0 0-13 0ZM12 4a8 8 0 1 0 0 16 8 8 0 0 0 0-16Zm.75 4v1.5h-1.5V8h1.5Zm0 8v-5h-1.5v5h1.5Z" />'},bell:{a:'fill="currentColor"',b:'<path fill-rule="evenodd" clip-rule="evenodd" d="M17 11.5c0 1.353.17 2.368.976 3 .266.209.602.376 1.024.5v1H5v-1c.422-.124.757-.291 1.024-.5.806-.632.976-1.647.976-3V9c0-2.8 2.2-5 5-5s5 2.2 5 5v2.5ZM15.5 9v2.5c0 .93.066 1.98.515 2.897l.053.103H7.932a4.018 4.018 0 0 0 .053-.103c.449-.917.515-1.967.515-2.897V9c0-1.972 1.528-3.5 3.5-3.5s3.5 1.528 3.5 3.5Zm-5.492 9.008c0-.176.023-.346.065-.508h3.854A1.996 1.996 0 0 1 12 20c-1.1 0-1.992-.892-1.992-1.992Z" />'},more:{a:'fill="currentColor"',b:'<path d="M11 13h2v-2h-2v2zm-6 0h2v-2H5v2zm12-2v2h2v-2h-2z" />'},maximize:{a:'fill="currentColor"',b:'<path d="M6 4a2 2 0 0 0-2 2v3h1.5V6a.5.5 0 0 1 .5-.5h3V4H6Zm3 14.5H6a.5.5 0 0 1-.5-.5v-3H4v3a2 2 0 0 0 2 2h3v-1.5Zm6 1.5v-1.5h3a.5.5 0 0 0 .5-.5v-3H20v3a2 2 0 0 1-2 2h-3Zm3-16a2 2 0 0 1 2 2v3h-1.5V6a.5.5 0 0 0-.5-.5h-3V4h3Z" />'},edit:{a:'fill="currentColor"',b:'<path d="m19 7-3-3-8.5 8.5-1 4 4-1L19 7Zm-7 11.5H5V20h7v-1.5Z" />'},color:{a:'fill="currentColor"',b:'<path d="M17.2 10.9c-.5-1-1.2-2.1-2.1-3.2-.6-.9-1.3-1.7-2.1-2.6L12 4l-1 1.1c-.6.9-1.3 1.7-2 2.6-.8 1.2-1.5 2.3-2 3.2-.6 1.2-1 2.2-1 3 0 3.4 2.7 6.1 6.1 6.1s6.1-2.7 6.1-6.1c0-.8-.3-1.8-1-3zm-5.1 7.6c-2.5 0-4.6-2.1-4.6-4.6 0-.3.1-1 .8-2.3.5-.9 1.1-1.9 2-3.1.7-.9 1.3-1.7 1.8-2.3.7.8 1.3 1.6 1.8 2.3.8 1.1 1.5 2.2 2 3.1.7 1.3.8 2 .8 2.3 0 2.5-2.1 4.6-4.6 4.6z" />'},wallpaper:{a:'fill="currentColor"',b:'<path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM5 4.5h14c.3 0 .5.2.5.5v8.4l-3-2.9c-.3-.3-.8-.3-1 0L11.9 14 9 12c-.3-.2-.6-.2-.8 0l-3.6 2.6V5c-.1-.3.1-.5.4-.5zm14 15H5c-.3 0-.5-.2-.5-.5v-2.4l4.1-3 3 1.9c.3.2.7.2.9-.1L16 12l3.5 3.4V19c0 .3-.2.5-.5.5z" />'},warning:{a:'fill="currentColor"',b:'<path fill-rule="evenodd" clip-rule="evenodd" d="M5.5 12a6.5 6.5 0 1 0 13 0 6.5 6.5 0 0 0-13 0ZM12 4a8 8 0 1 0 0 16 8 8 0 0 0 0-16Zm-.75 12v-1.5h1.5V16h-1.5Zm0-8v5h1.5V8h-1.5Z" />'},minimize:{a:'fill="currentColor"',b:'<path d="M5 11.25h14v1.5H5z" />'},window:{a:'fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"',b:'<rect x="4.125" y="5.4375" width="15.75" height="13.125" rx="1.75"/><path d="M4.125 9.8125h15.75"/><circle cx="7.275" cy="7.625" r="0.7438" fill="currentColor" stroke="none"/>'},windows:{a:'fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"',b:'<rect x="3.6875" y="8.5" width="11.375" height="10.0625" rx="1.75"/><path d="M3.6875 12h11.375"/><path d="M8.5 8.5V7.1875a1.75 1.75 0 0 1 1.75-1.75h7.875A1.75 1.75 0 0 1 19.875 7.1875v7a1.75 1.75 0 0 1-1.75 1.75h-3.0625"/>'},dock:{a:'fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"',b:'<rect x="3.25" y="8.5" width="17.5" height="7" rx="3.5"/><circle cx="7.625" cy="12" r="1.0062" fill="currentColor" stroke="none"/><circle cx="12" cy="12" r="1.0062" fill="currentColor" stroke="none"/><circle cx="16.375" cy="12" r="1.0062" fill="currentColor" stroke="none"/>'},spaces:{a:'fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"',b:'<rect x="3.6875" y="5.4375" width="7.4375" height="7.875" rx="1.75"/><rect x="12.875" y="5.4375" width="7.4375" height="7.875" rx="1.75"/><circle cx="9.375" cy="17.6875" r="0.7875" fill="currentColor" stroke="none"/><circle cx="12" cy="17.6875" r="0.7875" fill="currentColor" stroke="none"/><circle cx="14.625" cy="17.6875" r="0.7875" fill="currentColor" stroke="none"/>'},copilot:{a:'fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"',b:'<path d="M10 2.5Q10.9 8.5 17.5 10Q10.9 11.5 10 17.5Q9.1 11.5 2.5 10Q9.1 8.5 10 2.5Z" fill="currentColor" stroke="none"/><path d="M17.9 14Q18.35 17.1 21.5 17.6Q18.35 18.1 17.9 21.2Q17.45 18.1 14.3 17.6Q17.45 17.1 17.9 14Z" fill="currentColor" stroke="none"/>'},snap:{a:'fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"',b:'<rect x="3.6875" y="5.4375" width="16.625" height="13.125" rx="1.75"/><path d="M12 5.4375v13.125"/><path d="M12 12h8.3125"/>'},command:{a:'fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"',b:'<path d="M14.625 6.75v10.5a2.625 2.625 0 1 0 2.625-2.625H6.75a2.625 2.625 0 1 0 2.625 2.625V6.75a2.625 2.625 0 1 0-2.625 2.625h10.5a2.625 2.625 0 1 0-2.625-2.625"/>'},apps:{a:'fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"',b:'<rect x="4.125" y="4.125" width="6.5625" height="6.5625" rx="1.75"/><rect x="13.3125" y="4.125" width="6.5625" height="6.5625" rx="1.75"/><rect x="4.125" y="13.3125" width="6.5625" height="6.5625" rx="1.75"/><rect x="13.3125" y="13.3125" width="6.5625" height="6.5625" rx="1.75"/>'},widgets:{a:'fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"',b:'<rect x="3.6875" y="3.6875" width="9.625" height="9.625" rx="1.75"/><rect x="15.0625" y="3.6875" width="5.25" height="5.25" rx="1.75"/><rect x="15.0625" y="10.6875" width="5.25" height="9.625" rx="1.75"/><rect x="3.6875" y="15.0625" width="9.625" height="5.25" rx="1.75"/>'},user:{a:'fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"',b:'<circle cx="12" cy="8.9375" r="3.5"/><path d="M5.4375 19.4375a6.5625 6.5625 0 0 1 13.125 0"/>'},lock:{a:'fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"',b:'<rect x="5.4375" y="10.6875" width="13.125" height="8.75" rx="1.75"/><path d="M8.5 10.6875V8.0625a3.5 3.5 0 0 1 7 0v2.625"/>'}};function T(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function Q(n){return Object.prototype.hasOwnProperty.call(k,n)?k[n]:null}function p(n,e={}){const s=Q(n);if(!s)return"";const{size:t=24,className:o,title:i,rotate:r}=e,a=['xmlns="http://www.w3.org/2000/svg"','viewBox="0 0 24 24"'];t!=null&&a.push(`width="${t}"`,`height="${t}"`),a.push(s.a),o&&a.push(`class="${T(o)}"`),i?a.push('role="img"',`aria-label="${T(i)}"`):a.push('aria-hidden="true"','focusable="false"');const c=r?`<g transform="rotate(${r} 12 12)">${s.b}</g>`:s.b;return`<svg ${a.join(" ")}>${c}</svg>`}const W="__openStationSharedStores";function Y(){const n=window;let e=n[W];return e||(e=new Map,n[W]=e),e}function J(n,e){const s=Y();let t=s.get(n);t||(t={state:e(),listeners:new Set,rebuild:e},s.set(n,t));const o={get state(){return t.state},set state(i){t.state=i},getState(){return t.state},notify(){for(const i of Array.from(t.listeners))try{i(t.state)}catch(r){console.error(`[desktop-mode/shared-store:${n}] subscriber threw:`,r)}},subscribe(i){return t.listeners.add(i),()=>{t.listeners.delete(i)}},setState(i){const r=t.state;if(typeof r!="object"||r===null){console.warn(`[desktop-mode/shared-store:${n}] setState called on a primitive store; use the state setter instead.`);return}Object.assign(r,i),o.notify()},reset(){const i=t.rebuild(),r=t.state;if(typeof r=="object"&&r!==null&&typeof i=="object"&&i!==null){const a=r;for(const c of Object.keys(a))delete a[c];Object.assign(a,i)}else t.state=i;t.listeners.clear()}};return o}const M=J("desktop-mode/commands-registry",()=>({registry:new Map,listeners:new Set})),O=M.state.registry,P=M.state.listeners;function N(){return Array.from(O.values())}function E(){return Array.from(O.values()).filter(n=>n.eager===!0)}function S(n){return O.get(n.toLowerCase())??null}function $(n){const e=n.trim().toLowerCase();return e===""?N():N().filter(s=>s.slug.toLowerCase().startsWith(e)||s.label.toLowerCase().includes(e))}function ee(n){return P.add(n),()=>{P.delete(n)}}function m(n){if(!n.startsWith("/"))return{isCommand:!1,slug:"",args:"",hasArgsPart:!1};const e=n.slice(1),s=e.indexOf(" ");return s===-1?{isCommand:!0,slug:e,args:"",hasArgsPart:!1}:{isCommand:!0,slug:e.slice(0,s),args:e.slice(s+1),hasArgsPart:!0}}function se(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function C(n){return n.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(e,s,t)=>/^https?:\/\//i.test(t.trim())?`<a href="${t.trim()}" target="_blank" rel="noopener noreferrer">${s}</a>`:s).replace(/\*\*([^*\n]+?)\*\*/g,"<strong>$1</strong>").replace(/(?<![*\w])\*([^*\n]+?)\*(?![*\w])/g,"<em>$1</em>").replace(/(?<![_\w])_([^_\n]+?)_(?![_\w])/g,"<em>$1</em>").replace(/`([^`\n]+?)`/g,"<code>$1</code>")}function te(n){if(!n)return"";const e=se(n),s=[];let t=[],o=null;const i=()=>{t.length>0&&(s.push(`<p>${t.join("<br>")}</p>`),t=[])},r=()=>{o&&(s.push(`<${o.tag}>${o.items.join("")}</${o.tag}>`),o=null)};for(const a of e.split(/\n/)){const c=a.trim();if(c===""){i(),r();continue}const d=/^(#{1,6})\s+(.*)$/.exec(c);if(d){i(),r();const u=Math.min(6,d[1].length+2);s.push(`<h${u}>${C(d[2])}</h${u}>`);continue}if(/^(-{3,}|\*{3,}|_{3,})$/.test(c)){i(),r(),s.push("<hr>");continue}const _=/^[-*]\s+(.*)$/.exec(c),I=/^\d+\.\s+(.*)$/.exec(c);if(_||I){i();const u=_?"ul":"ol";(!o||o.tag!==u)&&(r(),o={tag:u,items:[]}),o.items.push(`<li>${C((_??I)[1])}</li>`);continue}r(),t.push(C(c))}return i(),r(),s.join("")}const A=p("copilot",{size:16}),ie=p("close",{size:16}),H=p("chevron-right",{size:16}),ne=p("search",{size:16}),oe=`<svg viewBox="0 0 16 16" width="13" height="13" aria-hidden="true" focusable="false" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
2 <polyline points="14,4 14,10 3,10"/>
3 <polyline points="6,7 3,10 6,13"/>
4 </svg>`,re=`<svg viewBox="0 0 20 20" width="16" height="16" aria-hidden="true" focusable="false" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" class="os-ai__spinner-icon">
5 <circle cx="10" cy="10" r="7" stroke-opacity="0.25"/>
6 <path d="M10 3 A7 7 0 0 1 17 10" stroke-opacity="1"/>
7 </svg>`,ae=X.replace("<svg ",'<svg width="18" height="18" aria-hidden="true" focusable="false" ');function le(){return[l("Find my post about…"),l("Where can I see categories?"),l("Do I have any spam comments?"),l("Take me to plugin settings")]}class ce{constructor(e){this._isOpen=!1,this._isSearching=!1,this._previousFocus=null,this._closeFadeCleanup=null,this._searchAbort=null,this._mode="commands",this._modeInput={commands:"",ai:""},this._lastAiResult=null,this._currentRemoteCommands=[],this._remoteSearchToken=0,this._selectedCommand=0,this._keyboardNav=!1,this._selectedSuggestion=0,this._currentSuggestions=[],this._suggestToken=0,this.ask=()=>{throw new Error("[openstation] wp.os.ai.ask called before the shell finished booting.")},this._aiSearchUrl=e.aiSearchUrl,this._restNonce=e.restNonce,this._adminUrl=e.adminUrl,this._isAiAvailable=e.isAiAvailable??(()=>!1),this._isOverrideEnabled=e.isOverrideEnabled??(()=>!1),this._el=this._buildDOM(),document.body.appendChild(this._el),this._input=this._el.querySelector(".os-ai__input"),this._submitBtn=this._el.querySelector(".os-ai__submit"),this._closeBtn=this._el.querySelector(".os-ai__close"),this._resultsEl=this._el.querySelector(".os-ai__results"),this._bindEvents(),this._renderSuggestions(),ee(()=>{this._isOpen&&this._renderForMode()})}open(){if(this._isOpen){this._input.focus(),this._input.select();return}this._isOpen=!0,this._previousFocus=this._el.ownerDocument.activeElement,this._input.value="",this._modeInput={commands:"",ai:""},this._lastAiResult=null,this._currentRemoteCommands=[],this._remoteSearchToken++,this._selectedCommand=0,this._submitBtn.classList.remove("has-value"),this._mode=this._defaultMode(),this._updateModeUI(),this._renderForMode(),this._closeFadeCleanup?.(),this._el.removeAttribute("hidden"),this._el.offsetHeight,this._el.classList.add("is-open"),this._el.setAttribute("aria-hidden","false"),document.dispatchEvent(new CustomEvent("os-palette-opened",{detail:{id:"desktop-mode-ai-assistant"}})),requestAnimationFrame(()=>this._input.focus())}close(){if(!this._isOpen)return;this._isOpen=!1,this._el.classList.remove("is-open"),this._el.setAttribute("aria-hidden","true"),this._abortSearch(),this._isSearching=!1,this._submitBtn.disabled=!1,this._input.disabled=!1,document.dispatchEvent(new CustomEvent("os-palette-closed",{detail:{id:"desktop-mode-ai-assistant"}})),this._closeFadeCleanup?.();const e=s=>{s.target!==this._el||s.propertyName!=="opacity"||(this._el.removeEventListener("transitionend",e),this._closeFadeCleanup=null,!this._isOpen&&(this._el.setAttribute("hidden",""),this._previousFocus instanceof HTMLElement&&this._previousFocus.focus()))};this._closeFadeCleanup=()=>{this._el.removeEventListener("transitionend",e),this._closeFadeCleanup=null},this._el.addEventListener("transitionend",e)}toggle(){this._isOpen?this.close():this.open()}get isOpen(){return this._isOpen}attachAsk(e){this.ask=e}_aiModeAllowed(){return this._isAiAvailable()&&this._isOverrideEnabled()}_defaultMode(){return this._aiModeAllowed()?"ai":"commands"}_setMode(e){const s=e==="ai"&&!this._aiModeAllowed()?"commands":e;s!==this._mode&&(this._modeInput[this._mode]=this._input.value,this._mode=s,this._input.value=this._modeInput[s],this._submitBtn.classList.toggle("has-value",this._input.value.trim().length>0)),this._selectedCommand=0,this._selectedSuggestion=0,this._updateModeUI(),this._mode==="ai"&&this._lastAiResult&&this._lastAiResult.query===this._input.value.trim()?this._showResult(this._lastAiResult.query,this._lastAiResult.data):this._renderForMode(),this._input.focus()}_updateModeUI(){const e=this._aiModeAllowed(),s=this._el.querySelector(".os-ai__modes");s&&(s.hidden=!e,s.querySelectorAll("[data-mode]").forEach(o=>{const i=o.dataset.mode===this._mode;o.classList.toggle("is-active",i),o.setAttribute("aria-pressed",String(i))})),this._input.placeholder=this._mode==="ai"?l("How can I help?"):l("Search commands…");const t=this._el.querySelector(".os-ai__input-icon");t&&(t.innerHTML=this._mode==="ai"?A:ne)}_isPickMode(e){return e.isCommand&&e.hasArgsPart?!1:e.isCommand||this._mode==="commands"?!0:this._input.value===""&&E().length>0}_commandMatches(){const e=m(this._input.value);if(e.isCommand)return this._sortCommands($(e.slug).filter(o=>o.eager!==!0));if(this._mode==="ai")return this._sortCommands(E());const s=this._input.value.trim();return[...this._sortCommands(s===""?N():$(s)),...this._currentRemoteCommands]}_pickCommand(e){if(typeof e.suggest=="function"){this._input.value=`/${e.slug} `,this._submitBtn.classList.add("has-value"),this._input.focus(),this._renderCommandMode();return}this._runCommand(e,"")}_renderForMode(){if(m(this._input.value).isCommand||this._mode==="commands"){this._renderCommandMode();return}const s=E().length>0;if(this._input.value.trim()===""){s?this._renderCommandMode():this._renderSuggestions();return}this._resultsEl.querySelector(".os-ai__bubble")||(s?this._renderCommandMode():this._resultsEl.querySelector(".os-ai__suggestions")&&(this._resultsEl.innerHTML="",this._resultsEl.hidden=!0))}_bindEvents(){this._el.addEventListener("keydown",e=>{e.key==="Escape"&&(e.stopPropagation(),this.close())}),this._el.addEventListener("mousedown",e=>{const s=e.target;(!(s instanceof Element)||!s.closest(".os-ai__panel"))&&this.close()}),this._el.addEventListener("keydown",e=>{if(e.key!=="Tab")return;const s=[this._closeBtn,this._input,this._submitBtn].filter(r=>!r.disabled),t=s[0],o=s[s.length-1],i=this._el.ownerDocument.activeElement;e.shiftKey&&i===t?(e.preventDefault(),o.focus()):!e.shiftKey&&i===o&&(e.preventDefault(),t.focus())}),document.addEventListener("os-open-ai",()=>this.open()),this._closeBtn.addEventListener("click",()=>this.close()),this._el.querySelectorAll(".os-ai__mode").forEach(e=>{e.addEventListener("click",()=>this._setMode(e.dataset.mode==="ai"?"ai":"commands"))}),this._submitBtn.addEventListener("click",()=>this._onSubmit()),this._input.addEventListener("keydown",e=>{const s=m(this._input.value);if(this._isPickMode(s)){const t=this._commandMatches();if(e.key==="ArrowDown"){e.preventDefault(),this._selectedCommand=Math.min(this._selectedCommand+1,Math.max(0,t.length-1)),this._keyboardNav=!0,this._paintCommandSelection();return}if(e.key==="ArrowUp"){e.preventDefault(),this._selectedCommand=Math.max(0,this._selectedCommand-1),this._keyboardNav=!0,this._paintCommandSelection();return}if(e.key==="Tab"&&t.length>0&&s.isCommand){e.preventDefault();const o=t[this._selectedCommand]??t[0];this._input.value=`/${o.slug} `,this._submitBtn.classList.add("has-value"),this._selectedSuggestion=0,this._renderCommandMode();return}if(e.key==="Enter"&&!e.shiftKey){if(e.preventDefault(),t.length===0){s.isCommand&&this._showError(h(l("Unknown command: /%s"),s.slug));return}const o=t[this._selectedCommand]??t[0];this._pickCommand(o);return}}if(s.isCommand&&s.hasArgsPart){const t=S(s.slug);if(!!t&&typeof t.suggest=="function"&&this._currentSuggestions.length>0){if(e.key==="ArrowDown"){e.preventDefault(),this._selectedSuggestion=Math.min(this._selectedSuggestion+1,this._currentSuggestions.length-1),this._paintSuggestionSelection();return}if(e.key==="ArrowUp"){e.preventDefault(),this._selectedSuggestion=Math.max(0,this._selectedSuggestion-1),this._paintSuggestionSelection();return}if(e.key==="Tab"){e.preventDefault();const i=this._currentSuggestions[this._selectedSuggestion];i&&(this._input.value=`/${s.slug} ${i.value}`);return}if(e.key==="Enter"&&!e.shiftKey&&t){e.preventDefault();const i=this._currentSuggestions[this._selectedSuggestion],r=i?i.value:s.args;this._runCommand(t,r);return}}}e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),this._onSubmit())}),this._input.addEventListener("input",()=>{const e=this._input.value.trim().length>0;this._submitBtn.classList.toggle("has-value",e),this._selectedCommand=0,this._selectedSuggestion=0;const s=m(this._input.value),t=this._input.value.trim();!s.isCommand&&this._mode==="commands"&&t.length>0?this._fetchRemoteCommands(t):(this._currentRemoteCommands=[],this._remoteSearchToken++),this._renderForMode()}),this._resultsEl.addEventListener("mousemove",()=>{if(this._keyboardNav){this._keyboardNav=!1;const e=this._resultsEl.querySelector(".os-ai__cmd-list");e&&e.classList.remove("os-ai__cmd-list--kb-nav")}})}async _onSubmit(){if(this._isSearching){this._warnBusy("submit");return}const e=m(this._input.value);if(this._isPickMode(e)){const t=this._commandMatches(),o=t[this._selectedCommand]??t[0];o&&this._pickCommand(o);return}const s=this._input.value.trim();if(s){if(e.isCommand){const t=S(e.slug);if(!t){this._showError(h(l("Unknown command: /%s"),e.slug));return}await this._runCommand(t,e.args);return}await this._runSearch(s,null,0)}}async _runCommand(e,s){if(this._isSearching){this._warnBusy(`run /${e.slug}`);return}const t=x(f.COMMAND_BEFORE_RUN,{proceed:!0,slug:e.slug,args:s,command:e});if(t&&t.proceed===!1){this._showError(t.reason??h(l("Command /%s was cancelled."),e.slug));return}this._isSearching=!0,this._submitBtn.disabled=!0,this._input.disabled=!0,this._showThinking(h(l("Running /%s…"),e.slug));const o={close:()=>{this._previousFocus=null,this.close()},openInWindow:(i,r,a)=>this._openInLegacyWindow(i,r,a),confirm:(i,r)=>this._confirm(i,r)};try{const i=await Promise.resolve(e.run(s,o));this._renderCommandResult(e,i),b(f.COMMAND_AFTER_RUN,{slug:e.slug,args:s,command:e,result:i})}catch(i){const r=i instanceof Error?i.message:String(i);this._showError(h(l("Command /%1$s failed: %2$s"),e.slug,r)),b(f.COMMAND_ERROR,{slug:e.slug,args:s,command:e,error:i})}finally{this._isSearching=!1,this._submitBtn.disabled=!1,this._input.disabled=!1,this._input.focus()}}_warnBusy(e){console.warn(`[openstation] command palette is busy — ignored: ${e}. A search or command is still running.`)}_confirm(e,s){return K({title:s?e:void 0,message:s??e})}_renderCommandResult(e,s){if(s==null){this._isOpen?this._renderForMode():(this._resultsEl.innerHTML="",this._resultsEl.hidden=!0);return}const t=typeof s=="string"?{answer_type:"chat",message:s,entity:null,admin_links:null,iterations:0,exhausted:!0,continue:null}:{answer_type:s.answer_type??"chat",message:s.message,entity:s.entity??null,admin_links:s.admin_links??null,iterations:0,exhausted:!0,continue:null};this._showResult("",t)}_runSearch(e,s,t){this._isSearching||(this._isSearching=!0,this._submitBtn.disabled=!0,this._input.disabled=!0,this._showThinking(l("Thinking…")),this._runSearchRequest(e,s,t))}_abortSearch(){this._searchAbort&&(this._searchAbort.abort(),this._searchAbort=null)}async _runSearchRequest(e,s,t){this._abortSearch();const o=new AbortController;this._searchAbort=o;try{const i={query:e};s&&(i.resume_tool=s,i.start_offset=t);const r=await y(this._aiSearchUrl,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":this._restNonce},body:JSON.stringify(i),signal:o.signal},{source:"desktop-mode/ai-search"});if(o.signal.aborted)return;if(!r.ok){const a=await r.json().catch(()=>({}));this._showError(a.message??h(l("Server returned %d"),r.status),a.data?.settings_tab);return}this._showResult(e,await r.json())}catch{o.signal.aborted||this._showError(l("Network error — please check your connection and try again."))}finally{this._searchAbort===o&&(this._searchAbort=null,this._isSearching=!1,this._submitBtn.disabled=!1,this._input.disabled=!1,this._input.focus())}}async _fetchRemoteCommands(e){const s=++this._remoteSearchToken;try{if(await new Promise(i=>setTimeout(i,200)),s!==this._remoteSearchToken)return;const t=await y(`/wp-json/wp/v2/search?search=${encodeURIComponent(e)}&subtype=post,page`,{headers:{"X-WP-Nonce":this._restNonce}},{silent:!0});if(!t.ok)return;const o=await t.json().catch(()=>[]);if(s!==this._remoteSearchToken)return;this._currentRemoteCommands=o.map(i=>{const r=i.subtype==="page",a=new URL("post.php",this._adminUrl);a.searchParams.set("post",String(i.id)),a.searchParams.set("action","edit");const c=a.toString(),d=j(i.title||l("(No title)")),_=r?"dashicons-admin-page":"dashicons-admin-post";return{slug:`post-${i.id}`,label:d,description:this._entityTypeLabel(r?"page":"post"),icon:_,eager:!1,run:(I,u)=>{u.openInWindow(c,d,_)}}}),this._isOpen&&this._renderForMode()}catch{}}_getDesktopShell(){return window.wp?.os??null}_openAssistantSettings(e){const s=this._getDesktopShell();this._previousFocus=null,this.close(),s?.openOsSettings?.({tabId:e})}_openInLegacyWindow(e,s,t){const o=this._getDesktopShell();if(!o||!o.windowManager){window.open(e,"_blank","noopener");return}const i=o.deriveWindowId?o.deriveWindowId(e,this._adminUrl):"os-ai-"+e.replace(/[^a-z0-9]+/gi,"-").slice(0,80);o.windowManager.open({id:i,url:e,title:s,icon:t??"dashicons-admin-generic"}),this.close()}_renderCommandMode(){this._resultsEl.hidden=!1;const e=m(this._input.value);if(e.hasArgsPart){const r=S(e.slug);if(r){this._renderArgsMode(r,e.args);return}}const s=this._commandMatches();if(s.length===0){const r=e.isCommand?`/${e.slug}`:this._input.value.trim(),a=h(l("No commands matching %s."),`<strong>${this._esc(r)}</strong>`);this._resultsEl.innerHTML=`
8 <div class="os-ai__state os-ai__state--empty">
9 <span>${a}</span>
10 </div>
11 `;return}this._selectedCommand>=s.length&&(this._selectedCommand=0);const t=this._isPickMode(e),o=s.map((r,a)=>{const c=t&&a===this._selectedCommand?" is-selected":"",d=this._isEntityResultCommand(r);return`
12 <button
13 type="button"
14 class="os-ai__cmd-item${c}${d?" is-entity-result":""}"
15 data-slug="${this._esc(r.slug)}"
16 data-index="${a}"
17 >
18 ${r.iconSvg?`<span class="os-ai__cmd-icon os-ai__cmd-icon--svg" aria-hidden="true">${r.iconSvg}</span>`:`<span class="os-ai__cmd-icon dashicons ${this._esc(r.icon??"dashicons-arrow-right-alt")}" aria-hidden="true"></span>`}
19 <span class="os-ai__cmd-body">
20 <span class="os-ai__cmd-title">
21 ${this._esc(r.label)}
22 ${r.hint?`<span class="os-ai__cmd-hint">${this._esc(r.hint)}</span>`:""}
23 </span>
24 ${r.description?`<span class="os-ai__cmd-desc">${this._esc(r.description)}</span>`:""}
25 </span>
26 </button>
27 `}).join(""),i=this._mode==="ai"&&E().length>0?`<p class="os-ai__suggestions-label">${this._esc(l("Suggested commands"))}</p>`:"";this._resultsEl.innerHTML=`
28 <div class="os-ai__cmd-list">
29 ${i}
30 ${o}
31 </div>
32 `,this._resultsEl.querySelectorAll(".os-ai__cmd-item").forEach(r=>{const a=parseInt(r.dataset.index??"",10),c=Number.isNaN(a)?void 0:s[a];r.addEventListener("click",()=>{c&&this._pickCommand(c)}),r.addEventListener("mouseenter",()=>{this._keyboardNav||Number.isNaN(a)||(this._selectedCommand=a,this._resultsEl.querySelectorAll(".os-ai__cmd-item").forEach((d,_)=>d.classList.toggle("is-selected",_===a)))})})}_renderArgsMode(e,s){if(typeof e.suggest!="function"){this._currentSuggestions=[],this._resultsEl.innerHTML=this._renderCommandHeader(e,!0);return}const t=++this._suggestToken,o={close:()=>this.close(),openInWindow:(a,c,d)=>this._openInLegacyWindow(a,c,d),confirm:(a,c)=>this._confirm(a,c)};let i;try{i=e.suggest(s,o)}catch{i=[]}const r=a=>{t===this._suggestToken&&(this._currentSuggestions=a,this._selectedSuggestion>=a.length&&(this._selectedSuggestion=0),this._resultsEl.innerHTML=this._renderCommandHeader(e,!1)+this._renderSuggestionList(a),this._resultsEl.querySelectorAll(".os-ai__cmd-suggest-item").forEach(c=>{c.addEventListener("click",()=>{const d=parseInt(c.dataset.index??"0",10),_=a[d];_&&(this._input.value=`/${e.slug} ${_.value}`,this._runCommand(e,_.value))}),c.addEventListener("mouseenter",()=>{const d=parseInt(c.dataset.index??"0",10);Number.isNaN(d)||(this._selectedSuggestion=d,this._paintSuggestionSelection())})}))};i&&typeof i.then=="function"?(this._resultsEl.innerHTML=this._renderCommandHeader(e,!1),i.then(a=>r(Array.isArray(a)?a:[])).catch(()=>r([]))):r(Array.isArray(i)?i:[])}_renderCommandHeader(e,s){return`
33 <div class="os-ai__cmd-active">
34 <span class="os-ai__cmd-icon dashicons ${this._esc(e.icon??"dashicons-arrow-right-alt")}" aria-hidden="true"></span>
35 <div class="os-ai__cmd-body">
36 <span class="os-ai__cmd-title">
37 /${this._esc(e.slug)}
38 ${e.hint?`<span class="os-ai__cmd-hint">${this._esc(e.hint)}</span>`:""}
39 </span>
40 ${e.description?`<span class="os-ai__cmd-desc">${this._esc(e.description)}</span>`:""}
41 ${s?`<span class="os-ai__cmd-enter-hint">${h(l("Press %s to run"),"<kbd>↵</kbd>")}</span>`:""}
42 </div>
43 </div>
44 `}_renderSuggestionList(e){return e.length===0?`
45 <div class="os-ai__state os-ai__state--empty">
46 <span>${h(l("No suggestions — press %s to run with the text you typed."),"<kbd>↵</kbd>")}</span>
47 </div>
48 `:`<div class="os-ai__cmd-suggest-list">${e.map((t,o)=>`
49 <button
50 type="button"
51 class="os-ai__cmd-suggest-item${o===this._selectedSuggestion?" is-selected":""}"
52 data-index="${o}"
53 >
54 <span class="os-ai__cmd-icon dashicons ${this._esc(t.icon??"dashicons-arrow-right-alt")}" aria-hidden="true"></span>
55 <span class="os-ai__cmd-body">
56 <span class="os-ai__cmd-suggest-label">${this._esc(t.label)}</span>
57 ${t.description?`<span class="os-ai__cmd-desc">${this._esc(t.description)}</span>`:""}
58 </span>
59 </button>
60 `).join("")}</div>`}_sortCommands(e){return e.slice().sort((s,t)=>{const o=typeof s.owner=="string"&&s.owner.startsWith("iframe:")?0:1,i=typeof t.owner=="string"&&t.owner.startsWith("iframe:")?0:1;return o-i})}_isEntityResultCommand(e){return this._currentRemoteCommands.includes(e)}_paintCommandSelection(){const e=this._resultsEl.querySelectorAll(".os-ai__cmd-item");e.forEach((o,i)=>{o.classList.toggle("is-selected",i===this._selectedCommand)});const s=this._resultsEl.querySelector(".os-ai__cmd-list");s&&s.classList.toggle("os-ai__cmd-list--kb-nav",this._keyboardNav);const t=e[this._selectedCommand];t&&typeof t.scrollIntoView=="function"&&t.scrollIntoView({block:"nearest"})}_paintSuggestionSelection(){this._resultsEl.querySelectorAll(".os-ai__cmd-suggest-item").forEach((e,s)=>{e.classList.toggle("is-selected",s===this._selectedSuggestion)})}_renderSuggestions(){this._resultsEl.hidden=!1,this._resultsEl.innerHTML=`
61 <div class="os-ai__suggestions">
62 <p class="os-ai__suggestions-label">${this._esc(l("Try asking"))}</p>
63 <div class="os-ai__suggestions-list">
64 ${le().map(e=>`<button type="button" class="os-ai__suggestion" data-prompt="${this._esc(e)}">
65 ${this._esc(e)}
66 </button>`).join("")}
67 </div>
68 </div>
69 `,this._resultsEl.querySelectorAll(".os-ai__suggestion").forEach(e=>{e.addEventListener("click",()=>{const s=e.dataset.prompt??"";this._input.value=s,this._submitBtn.classList.add("has-value"),this._input.focus()})})}_showThinking(e=l("Thinking…")){this._resultsEl.hidden=!1,this._resultsEl.innerHTML=`
70 <div class="os-ai__state os-ai__state--thinking">
71 ${re}
72 <span>${this._esc(e)}</span>
73 </div>
74 `}_showError(e,s){if(this._resultsEl.hidden=!1,s){const t=`<button type="button" class="os-ai__settings-link">${this._esc(l("Open Preferences"))}</button>`;this._resultsEl.innerHTML=`
75 <div class="os-ai__state os-ai__state--error">
76 <span>${this._esc(e)} ${t}</span>
77 </div>
78 `,this._resultsEl.querySelector(".os-ai__settings-link")?.addEventListener("click",()=>this._openAssistantSettings(s));return}this._resultsEl.innerHTML=`
79 <div class="os-ai__state os-ai__state--error">
80 <span>${this._esc(e)}</span>
81 </div>
82 `}_showResult(e,s){e!==""&&(this._lastAiResult={query:e,data:s}),this._resultsEl.hidden=!1;const t=`
83 <div class="os-ai__bubble">
84 <span class="os-ai__bubble-icon">${A}</span>
85 <div class="os-ai__bubble-text">${te(s.message||"")}</div>
86 </div>
87 `;let o="";s.answer_type==="entity"&&s.entity?o=this._renderEntityCard(s.entity):s.answer_type==="navigation"&&s.admin_links&&s.admin_links.length>0&&(o=this._renderAdminLinks(s.admin_links)),s.continue&&(o+=`
88 <button type="button" class="os-ai__continue-btn"
89 data-tool="${this._esc(s.continue.tool)}"
90 data-offset="${s.continue.offset}"
91 data-query="${this._esc(e)}">
92 ${this._esc(s.continue.label)}
93 </button>
94 `),this._resultsEl.innerHTML=t+o,this._resultsEl.querySelectorAll(".os-ai__entity-open").forEach(r=>{r.addEventListener("click",()=>{const a=r.dataset.url??"",c=r.dataset.title??"",d=r.dataset.icon??"dashicons-admin-generic";a&&this._openInLegacyWindow(a,c,d)})}),this._resultsEl.querySelectorAll(".os-ai__admin-link").forEach(r=>{r.addEventListener("click",()=>{const a=r.dataset.url??"",c=r.dataset.title??"",d=r.dataset.icon??"dashicons-admin-generic";a&&this._openInLegacyWindow(a,c,d)})});const i=this._resultsEl.querySelector(".os-ai__continue-btn");i&&i.addEventListener("click",()=>{const r=i.dataset.tool??null,a=parseInt(i.dataset.offset??"0",10),c=i.dataset.query??e;this._runSearch(c,r,a)})}_entityTypeLabel(e){switch(e){case"page":return l("Page");case"comment":return l("Comment");default:return l("Post")}}_entityOpenLabel(e){switch(e){case"page":return l("Open page in desktop");case"comment":return l("Open comment in desktop");default:return l("Open post in desktop")}}_renderEntityCard(e){const s=e.type==="comment",t=s?h(l("Comment on ā€œ%sā€"),this._esc(e.post_title??G("post","fallback name for the post a comment was left on"))):this._esc(e.title??l("Untitled")),o=this._esc(e.ai_summary||e.excerpt||""),i=this._entityTypeLabel(e.type),r=e.topic?`<span class="os-ai__entity-topic">${this._esc(e.topic)}</span>`:"";let a;return s?a="dashicons-admin-comments":e.type==="page"?a="dashicons-admin-page":a="dashicons-admin-post",`
95 <div class="os-ai__entity">
96 <div class="os-ai__entity-header">
97 ${r}
98 <span class="os-ai__entity-type">${this._esc(i)}</span>
99 </div>
100 <h3 class="os-ai__entity-title">${t}</h3>
101 <p class="os-ai__entity-summary">${o}</p>
102 <button type="button"
103 class="os-ai__entity-open"
104 data-url="${this._esc(e.edit_url)}"
105 data-title="${this._esc(e.title??e.post_title??i)}"
106 data-icon="${a}">
107 <span>${this._esc(this._entityOpenLabel(e.type))}</span>
108 ${H}
109 </button>
110 </div>
111 `}_renderAdminLinks(e){return`<div class="os-ai__admin-links">${e.map(t=>`
112 <button type="button"
113 class="os-ai__admin-link"
114 data-url="${this._esc(t.url)}"
115 data-title="${this._esc(t.title)}"
116 data-icon="${this._esc(t.icon)}">
117 <span class="os-ai__admin-link-icon dashicons ${this._esc(t.icon)}" aria-hidden="true"></span>
118 <span class="os-ai__admin-link-body">
119 <span class="os-ai__admin-link-title">${this._esc(t.title)}</span>
120 <span class="os-ai__admin-link-desc">${this._esc(t.description)}</span>
121 </span>
122 <span class="os-ai__admin-link-arrow">${H}</span>
123 </button>
124 `).join("")}</div>`}_esc(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}_buildDOM(){const e=document.createElement("div");return e.id="desktop-mode-ai-assistant",e.className="os-ai",e.setAttribute("role","dialog"),e.setAttribute("aria-modal","true"),e.setAttribute("aria-label",l("Site Assistant")),e.setAttribute("aria-hidden","true"),e.setAttribute("hidden",""),e.innerHTML=`
125 <div class="os-ai__backdrop" aria-hidden="true"></div>
126 <div class="os-ai__panel">
127 <div class="os-ai__header">
128 <span class="os-ai__header-icon">${ae}</span>
129 <span class="os-ai__header-label">${this._esc(l("Site Assistant"))}</span>
130 <div class="os-ai__modes" role="group" aria-label="${this._esc(l("Assistant mode"))}" hidden>
131 <button type="button" class="os-ai__mode" data-mode="ai" aria-pressed="false">${this._esc(l("Ask AI"))}</button>
132 <button type="button" class="os-ai__mode" data-mode="commands" aria-pressed="false">${this._esc(l("Commands"))}</button>
133 </div>
134 <button type="button" class="os-ai__close" aria-label="${this._esc(l("Close"))}">
135 ${ie}
136 </button>
137 </div>
138 <div class="os-ai__input-wrap">
139 <span class="os-ai__input-icon">${A}</span>
140 <input
141 class="os-ai__input"
142 type="text"
143 placeholder="${this._esc(l("How can I help?"))}"
144 autocomplete="off"
145 spellcheck="false"
146 aria-label="${this._esc(l("Ask the assistant"))}"
147 />
148 <button type="button" class="os-ai__submit" aria-label="${this._esc(l("Send"))}">
149 ${oe}
150 </button>
151 </div>
152 <div class="os-ai__results" hidden></div>
153 <div class="os-ai__footer">
154 <span class="os-ai__footer-hint">
155 ${this._esc(l("Your assistant to quickly navigate and manage your entire site."))}
156 </span>
157 </div>
158 </div>
159 `,e}}const de=n=>new ce(n);window.openStationCreateAiAssistant=de})();
160