@openhands/agent-canvas 1.0.0-alpha.6 → 1.0.0-alpha.7

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.
Files changed (68) hide show
  1. package/README.md +41 -7
  2. package/bin/agent-canvas.mjs +9 -2
  3. package/build/assets/automation-detail-D7GEU0vR.js +1 -0
  4. package/build/assets/automations-list-CkVNsgzm.js +1 -0
  5. package/build/assets/conversation-COZAKz_K.js +1 -0
  6. package/build/assets/{conversation-D8scXOe7.js → conversation-DWcvnmds.js} +3 -1
  7. package/build/assets/conversation-panel-CZDStT0b.js +1 -0
  8. package/build/assets/conversation-websocket-context-DulnrIHh.js +3 -0
  9. package/build/assets/edit-automation-modal-C3bFxS2f.js +1 -0
  10. package/build/assets/git-control-bar-branch-button-Bm6rzSpo.js +27 -0
  11. package/build/assets/{home-D9fJfhQA.js → home-DR11ejqB.js} +1 -1
  12. package/build/assets/{manifest-6400820c.js → manifest-f041e61a.js} +1 -1
  13. package/build/assets/{messages-BfaEAG2q.js → messages-v-q35ObG.js} +1 -1
  14. package/build/assets/{root-6AdVEJBT.js → root-D2PVd51i.js} +1 -1
  15. package/build/assets/root-layout-B4QioBS6.js +2 -0
  16. package/build/assets/{shared-conversation-BfZNCsvo.js → shared-conversation-DQlzwdpo.js} +1 -1
  17. package/build/index.html +3 -3
  18. package/dist/components/features/backends/backend-selector.cjs +1 -1
  19. package/dist/components/features/backends/backend-selector.cjs.map +1 -1
  20. package/dist/components/features/backends/backend-selector.js +95 -95
  21. package/dist/components/features/backends/backend-selector.js.map +1 -1
  22. package/dist/components/features/chat/components/chat-input-actions.cjs +1 -1
  23. package/dist/components/features/chat/components/chat-input-actions.cjs.map +1 -1
  24. package/dist/components/features/chat/components/chat-input-actions.js +118 -118
  25. package/dist/components/features/chat/components/chat-input-actions.js.map +1 -1
  26. package/dist/components/features/chat/components/slash-command-menu.cjs +1 -1
  27. package/dist/components/features/chat/components/slash-command-menu.cjs.map +1 -1
  28. package/dist/components/features/chat/components/slash-command-menu.js +1 -1
  29. package/dist/components/features/chat/components/slash-command-menu.js.map +1 -1
  30. package/dist/components/features/sidebar/sidebar-rail-body.cjs +1 -1
  31. package/dist/components/features/sidebar/sidebar-rail-body.cjs.map +1 -1
  32. package/dist/components/features/sidebar/sidebar-rail-body.d.ts +1 -2
  33. package/dist/components/features/sidebar/sidebar-rail-body.js +104 -104
  34. package/dist/components/features/sidebar/sidebar-rail-body.js.map +1 -1
  35. package/dist/components/features/sidebar/sidebar.cjs +1 -1
  36. package/dist/components/features/sidebar/sidebar.cjs.map +1 -1
  37. package/dist/components/features/sidebar/sidebar.js +82 -83
  38. package/dist/components/features/sidebar/sidebar.js.map +1 -1
  39. package/dist/contexts/conversation-websocket-context.cjs +3 -3
  40. package/dist/contexts/conversation-websocket-context.cjs.map +1 -1
  41. package/dist/contexts/conversation-websocket-context.js +36 -36
  42. package/dist/contexts/conversation-websocket-context.js.map +1 -1
  43. package/dist/hooks/query/use-local-git-info.cjs +3 -1
  44. package/dist/hooks/query/use-local-git-info.cjs.map +1 -1
  45. package/dist/hooks/query/use-local-git-info.d.ts +2 -2
  46. package/dist/hooks/query/use-local-git-info.js +27 -24
  47. package/dist/hooks/query/use-local-git-info.js.map +1 -1
  48. package/dist/package.cjs +1 -1
  49. package/dist/package.cjs.map +1 -1
  50. package/dist/package.js +1 -1
  51. package/dist/package.js.map +1 -1
  52. package/dist/stores/error-message-store.cjs +1 -1
  53. package/dist/stores/error-message-store.cjs.map +1 -1
  54. package/dist/stores/error-message-store.d.ts +10 -1
  55. package/dist/stores/error-message-store.js +16 -3
  56. package/dist/stores/error-message-store.js.map +1 -1
  57. package/package.json +1 -1
  58. package/scripts/dev-static.mjs +6 -0
  59. package/scripts/dev-with-automation.mjs +6 -0
  60. package/scripts/static-server.mjs +85 -4
  61. package/build/assets/automation-detail-CQrtk33s.js +0 -1
  62. package/build/assets/automations-list-COmogz0S.js +0 -1
  63. package/build/assets/conversation-CeGMBOyB.js +0 -1
  64. package/build/assets/conversation-panel-DMz46ji-.js +0 -1
  65. package/build/assets/conversation-websocket-context-B0Gd3yiT.js +0 -3
  66. package/build/assets/edit-automation-modal-DnTHJrf1.js +0 -1
  67. package/build/assets/git-control-bar-branch-button-DhpPgadK.js +0 -27
  68. package/build/assets/root-layout-DvYGxAnr.js +0 -2
@@ -1 +1 @@
1
- {"version":3,"file":"backend-selector.cjs","names":[],"sources":["../../../../src/components/features/backends/backend-selector.tsx"],"sourcesContent":["import React from \"react\";\nimport { useTranslation } from \"react-i18next\";\nimport { useMatch, useNavigate } from \"react-router\";\nimport { Plus, Settings } from \"lucide-react\";\nimport { Dropdown } from \"#/ui/dropdown/dropdown\";\nimport { DropdownOption } from \"#/ui/dropdown/types\";\nimport { useActiveBackendContext } from \"#/contexts/active-backend-context\";\nimport { useAllCloudOrganizations } from \"#/hooks/query/use-cloud-organizations\";\nimport { useCloudCurrentUserId } from \"#/hooks/query/use-cloud-current-user-id\";\nimport {\n useBackendsHealth,\n type BackendHealth,\n} from \"#/hooks/query/use-backends-health\";\nimport { I18nKey } from \"#/i18n/declaration\";\nimport type { Backend } from \"#/api/backend-registry/types\";\n// Import the trigger helpers from the lightweight store, not the overlay\n// component, so the eagerly-mounted sidebar/backend-selector graph does not\n// pull in the overlay's render code (the overlay is lazy-loaded from\n// `routes/root-layout.tsx`).\nimport {\n ENVIRONMENT_SWITCH_SETACTIVE_DELAY_MS,\n triggerEnvironmentSwitch,\n} from \"#/components/features/backends/environment-switch-store\";\nimport { StyledTooltip } from \"#/components/shared/buttons/styled-tooltip\";\nimport { useConversationStore } from \"#/stores/conversation-store\";\nimport { AddBackendModal } from \"./add-backend-modal\";\nimport { BackendStatusDot } from \"./backend-status-dot\";\nimport { ManageBackendsModal } from \"./manage-backends-modal\";\nimport { cn } from \"#/utils/utils\";\nimport { formControlTransitionClassName } from \"#/utils/form-control-classes\";\n\nconst VALUE_SEPARATOR = \"::\";\n\nfunction makeOptionValue(backendId: string, orgId: string | null): string {\n return orgId ? `${backendId}${VALUE_SEPARATOR}${orgId}` : backendId;\n}\n\nfunction parseOptionValue(value: string): {\n backendId: string;\n orgId: string | null;\n} {\n const [backendId, orgId] = value.split(VALUE_SEPARATOR);\n return { backendId, orgId: orgId ?? null };\n}\n\nfunction buildStatusPrefix(health: BackendHealth | undefined) {\n return <BackendStatusDot isConnected={health?.isConnected ?? null} />;\n}\n\nfunction buildOptions(\n registered: Backend[],\n personalWorkspaceLabel: string,\n cloudOrgs: ReturnType<typeof useAllCloudOrganizations>,\n currentUserIds: ReturnType<typeof useCloudCurrentUserId>,\n healthByBackendId: Record<string, BackendHealth>,\n): DropdownOption[] {\n const options: DropdownOption[] = [];\n\n const locals = registered.filter((b) => b.kind === \"local\");\n const clouds = registered.filter((b) => b.kind === \"cloud\");\n\n for (const b of locals) {\n options.push({\n value: makeOptionValue(b.id, null),\n label: b.name,\n prefix: buildStatusPrefix(healthByBackendId[b.id]),\n });\n }\n\n for (const b of clouds) {\n const entry = cloudOrgs[b.id];\n const prefix = buildStatusPrefix(healthByBackendId[b.id]);\n if (!entry || entry.orgs.length === 0) {\n options.push({\n value: makeOptionValue(b.id, null),\n label: b.name,\n prefix,\n });\n } else {\n // Personal-workspace rule (per the cloud contract): the org whose\n // id matches the calling user's id is the user's personal\n // workspace. We resolve `user_id` once per backend (via /me on any\n // one org) and apply it across all orgs of that backend.\n const userIdForBackend = currentUserIds[b.id]?.userId ?? null;\n\n for (const org of entry.orgs) {\n const isPersonal = !!userIdForBackend && userIdForBackend === org.id;\n const orgLabel = isPersonal ? personalWorkspaceLabel : org.name;\n options.push({\n value: makeOptionValue(b.id, org.id),\n label: `${b.name} – ${orgLabel}`,\n // All org rows for the same cloud backend share that backend's\n // single connectivity verdict — there is no per-org probe.\n prefix,\n });\n }\n }\n }\n\n return options;\n}\n\ninterface BackendSelectorProps {\n /** Render the menu above the trigger (e.g. when pinned to bottom of sidebar). */\n openUpward?: boolean;\n /** Hide the selector input trigger and only render the dropdown menu. */\n hideTrigger?: boolean;\n /** Whether the dropdown menu should start open on mount. */\n defaultOpen?: boolean;\n /** Callback fired after selecting a backend/org option. */\n onSelectOption?: () => void;\n /**\n * Override the internal Add Backend modal handling. When provided,\n * clicking \"Add Backend\" calls this instead of opening BackendSelector's\n * own modal. Useful when the selector is mounted inside an ephemeral\n * container (e.g. the collapsed-sidebar popover) and the modal must\n * survive the parent unmounting.\n */\n onOpenAddBackend?: () => void;\n /** Same as onOpenAddBackend but for the Manage Backends modal. */\n onOpenManageBackends?: () => void;\n /**\n * Whether the surrounding sidebar rail is in its collapsed variant. Passed\n * down from `SidebarRailBody` so the mobile drawer (which always renders\n * the expanded rail) can override the persisted desktop value.\n */\n sidebarCollapsed?: boolean;\n}\n\nexport function BackendSelector({\n openUpward = false,\n hideTrigger = false,\n defaultOpen = false,\n onSelectOption,\n onOpenAddBackend,\n onOpenManageBackends,\n sidebarCollapsed = false,\n}: BackendSelectorProps = {}) {\n const { t } = useTranslation(\"openhands\");\n const { backends, active, setActive } = useActiveBackendContext();\n const cloudOrgs = useAllCloudOrganizations();\n const currentUserIds = useCloudCurrentUserId();\n // Probe each registered backend every 10s.\n const healthByBackendId = useBackendsHealth(backends);\n const navigate = useNavigate();\n const settingsMatch = useMatch(\"/settings\");\n const settingsSubrouteMatch = useMatch(\"/settings/*\");\n const conversationMatch = useMatch(\"/conversations/:conversationId\");\n const automationDetailMatch = useMatch(\"/automations/:automationId\");\n const [addBackendModalOpen, setAddBackendModalOpen] = React.useState(false);\n const [manageBackendsModalOpen, setManageBackendsModalOpen] =\n React.useState(false);\n\n const personalWorkspaceLabel = t(I18nKey.BACKEND$PERSONAL_WORKSPACE);\n\n const options = React.useMemo(\n () =>\n buildOptions(\n backends,\n personalWorkspaceLabel,\n cloudOrgs,\n currentUserIds,\n healthByBackendId,\n ),\n [\n backends,\n personalWorkspaceLabel,\n cloudOrgs,\n currentUserIds,\n healthByBackendId,\n ],\n );\n\n const activeValue = makeOptionValue(active.backend.id, active.orgId);\n const activeOption = options.find((o) => o.value === activeValue);\n const isSettingsActive = Boolean(settingsMatch || settingsSubrouteMatch);\n const settingsLabel = t(I18nKey.SIDEBAR$SETTINGS);\n const isRightPanelShown = useConversationStore(\n (state) => state.isRightPanelShown,\n );\n // When the sidebar rail is expanded, `placement=\"left\"` hugs the main\n // canvas and reads awkwardly; prefer above the control. When the rail is\n // collapsed, keep left except on active conversation + open right drawer.\n const settingsTooltipPlacement =\n !sidebarCollapsed || (conversationMatch && isRightPanelShown)\n ? \"top\"\n : \"left\";\n\n const someCloudLoading = Object.values(cloudOrgs).some((c) => c.isLoading);\n\n // Self-heal a malformed `(cloudBackendId, null)` selection.\n //\n // Once a cloud backend's orgs resolve, the dropdown only renders\n // per-org rows for it — the `(backendId, null)` row disappears, so\n // selecting that shape would drift from what the dropdown can render\n // (UI says \"Local\", APIs hit cloud). When we detect the drift, snap\n // the selection onto the personal-workspace org (or, lacking a /me\n // result, the first org). The selection is recorded locally only;\n // the cloud request scope follows from the API key's bound org and the\n // X-Org-Id header sent by `callCloudProxy`, so the cloud UI's\n // org choice is never mutated as a side effect.\n React.useEffect(() => {\n if (active.backend.kind !== \"cloud\" || active.orgId) return;\n const { backend } = active;\n const entry = cloudOrgs[backend.id];\n if (!entry || entry.orgs.length === 0) return;\n\n const userId = currentUserIds[backend.id]?.userId ?? null;\n const personal = userId\n ? entry.orgs.find((o) => o.id === userId)\n : undefined;\n const target = personal ?? entry.orgs[0];\n if (target) {\n setActive(backend.id, target.id);\n }\n }, [active, cloudOrgs, currentUserIds, setActive]);\n\n const openAddBackendModal = React.useCallback(() => {\n if (onOpenAddBackend) {\n onOpenAddBackend();\n onSelectOption?.();\n return;\n }\n setAddBackendModalOpen(true);\n }, [onOpenAddBackend, onSelectOption]);\n\n const openManageBackendsModal = React.useCallback(() => {\n if (onOpenManageBackends) {\n onOpenManageBackends();\n onSelectOption?.();\n return;\n }\n setManageBackendsModalOpen(true);\n }, [onOpenManageBackends, onSelectOption]);\n\n const preventDropdownMenuClose = React.useCallback(\n (event: React.MouseEvent<HTMLButtonElement>) => {\n event.preventDefault();\n event.stopPropagation();\n },\n [],\n );\n\n const addBackendFooter = (\n <div className=\"flex flex-col\">\n <button\n type=\"button\"\n data-testid=\"add-backend-menu-item\"\n onMouseDown={preventDropdownMenuClose}\n onClick={openAddBackendModal}\n className=\"flex w-full items-center gap-2 px-2 py-2 rounded-md text-sm cursor-pointer text-white hover:bg-[var(--oh-interactive-hover)]\"\n >\n <Plus width={16} height={16} className=\"text-white shrink-0\" />\n {t(I18nKey.BACKEND$ADD)}\n </button>\n <button\n type=\"button\"\n data-testid=\"manage-backends-menu-item\"\n onMouseDown={preventDropdownMenuClose}\n onClick={openManageBackendsModal}\n className=\"flex w-full items-center gap-2 px-2 py-2 rounded-md text-sm cursor-pointer text-white hover:bg-[var(--oh-interactive-hover)]\"\n >\n <Settings width={16} height={16} className=\"text-white shrink-0\" />\n {t(I18nKey.BACKEND$MANAGE)}\n </button>\n </div>\n );\n\n const handleSelectBackend = React.useCallback(\n async (value: string) => {\n if (value === activeValue) return;\n\n const { backendId, orgId } = parseOptionValue(value);\n const target = backends.find((b) => b.id === backendId);\n if (!target) return;\n\n triggerEnvironmentSwitch(\n options.find((option) => option.value === value)?.label ?? target.name,\n );\n await new Promise<void>((resolve) => {\n setTimeout(resolve, ENVIRONMENT_SWITCH_SETACTIVE_DELAY_MS);\n });\n\n // @spec BM-002 — Switching backends keeps the user on the same page\n if (conversationMatch) navigate(\"/conversations\");\n else if (automationDetailMatch) navigate(\"/automations\");\n\n setActive(target.id, orgId);\n onSelectOption?.();\n },\n [\n activeValue,\n backends,\n conversationMatch,\n automationDetailMatch,\n navigate,\n options,\n setActive,\n t,\n onSelectOption,\n ],\n );\n\n return (\n <>\n <div className=\"flex items-center gap-2 w-full\">\n <div className=\"flex-1 min-w-0\">\n <Dropdown\n testId=\"backend-selector\"\n key={`${activeValue}-${activeOption?.label ?? \"\"}`}\n defaultValue={\n activeOption ?? {\n value: activeValue,\n label: active.backend.name,\n prefix: buildStatusPrefix(healthByBackendId[active.backend.id]),\n }\n }\n footer={addBackendFooter}\n openUpward={openUpward}\n hideTrigger={hideTrigger}\n defaultOpen={defaultOpen}\n openOnHover={!hideTrigger}\n onChange={(item) => {\n if (!item) return;\n void handleSelectBackend(item.value);\n }}\n placeholder={active.backend.name}\n loading={someCloudLoading}\n options={options}\n className=\"h-10 px-2 py-0 bg-transparent border-transparent hover:bg-[var(--oh-surface-raised)] focus-within:bg-[var(--oh-surface-raised)] focus-within:border-transparent focus-within:ring-0\"\n />\n </div>\n {!hideTrigger ? (\n <StyledTooltip\n content={settingsLabel}\n placement={settingsTooltipPlacement}\n offset={10}\n >\n <button\n type=\"button\"\n data-testid=\"backend-selector-settings-link\"\n data-active={isSettingsActive}\n aria-label={settingsLabel}\n onClick={() => navigate(\"/settings\")}\n className={\n isSettingsActive\n ? cn(\n \"inline-flex items-center justify-center shrink-0 w-9 h-9 rounded-md bg-tertiary text-white font-normal cursor-pointer\",\n formControlTransitionClassName,\n )\n : cn(\n \"inline-flex items-center justify-center shrink-0 w-9 h-9 rounded-md text-[var(--oh-muted)] hover:text-white hover:bg-[var(--oh-surface-raised)] cursor-pointer\",\n formControlTransitionClassName,\n )\n }\n >\n <Settings width={16} height={16} />\n </button>\n </StyledTooltip>\n ) : null}\n </div>\n {addBackendModalOpen ? (\n <AddBackendModal onClose={() => setAddBackendModalOpen(false)} />\n ) : null}\n {manageBackendsModalOpen ? (\n <ManageBackendsModal\n onClose={() => setManageBackendsModalOpen(false)}\n />\n ) : null}\n </>\n );\n}\n"],"mappings":"gjCA+BA,IAAM,EAAkB,KAExB,SAAS,EAAgB,EAAmB,EAA8B,CACxE,OAAO,EAAQ,GAAG,IAAY,IAAkB,IAAU,EAG5D,SAAS,EAAiB,EAGxB,CACA,GAAM,CAAC,EAAW,GAAS,EAAM,MAAM,EAAgB,CACvD,MAAO,CAAE,YAAW,MAAO,GAAS,KAAM,C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ACA,EACA,EACD,CACF,CAED,OACE,EAAA,EAAA,MAAA,EAAA,SAAA,CAAA,SAAA,EACE,EAAA,EAAA,MAAC,MAAD,CAAK,UAAU,0CAAf,EACE,EAAA,EAAA,KAAC,MAAD,CAAK,UAAU,2BACb,EAAA,EAAA,KAAC,EAAA,SAAD,CACE,OAAO,mBAEP,aACE,GAAgB,CACd,MAAO,EACP,MAAO,EAAO,QAAQ,KACtB,OAAQ,EAAkB,EAAkB,EAAO,QAAQ,IAAI,CAChE,CAEH,OAAQ,GACI,aACC,cACA,cACb,YAAa,CAAC,EACd,SAAW,GAAS,CACb,GACA,GAAoB,EAAK,MAAM,EAEtC,YAAa,EAAO,QAAQ,KAC5B,QAAS,GACA,UACT,UAAU,sLACV,CArBK,GAAG,EAAY,GAAG,GAAc,OAAS,KAqB9C,CACE,CAAA,CACJ,EA2BE,MA1BF,EAAA,EAAA,KAAC,EAAA,cAAD,CACE,QAAS,EACT,UAAW,GACX,OAAQ,aAER,EAAA,EAAA,KAAC,SAAD,CACE,KAAK,SACL,cAAY,iCACZ,cAAa,EACb,aAAY,EACZ,YAAe,EAAS,YAAY,CACpC,UACE,EACI,EAAA,GACE,wHACA,EAAA,+BACD,CACD,EAAA,GACE,iKACA,EAAA,+BACD,WAGP,EAAA,EAAA,KAAC,EAAA,SAAD,CAAU,MAAO,GAAI,OAAQ,GAAM,CAAA,CAC5B,CAAA,CACK,CAAA,CAEd,GACL,GACC,EAAA,EAAA,KAAC,EAAA,gBAAD,CAAiB,YAAe,EAAuB,GAAM,CAAI,CAAA,CAC/D,KACH,GACC,EAAA,EAAA,KAAC,EAAA,oBAAD,CACE,YAAe,EAA2B,GAAM,CAChD,CAAA,CACA,KACH,CAAA,CAAA"}
1
+ {"version":3,"file":"backend-selector.cjs","names":[],"sources":["../../../../src/components/features/backends/backend-selector.tsx"],"sourcesContent":["import React from \"react\";\nimport { useTranslation } from \"react-i18next\";\nimport { useMatch, useNavigate } from \"react-router\";\nimport { Plus, Settings } from \"lucide-react\";\nimport { Dropdown } from \"#/ui/dropdown/dropdown\";\nimport { DropdownOption } from \"#/ui/dropdown/types\";\nimport { useActiveBackendContext } from \"#/contexts/active-backend-context\";\nimport { useAllCloudOrganizations } from \"#/hooks/query/use-cloud-organizations\";\nimport { useCloudCurrentUserId } from \"#/hooks/query/use-cloud-current-user-id\";\nimport {\n useBackendsHealth,\n type BackendHealth,\n} from \"#/hooks/query/use-backends-health\";\nimport { I18nKey } from \"#/i18n/declaration\";\nimport type { Backend } from \"#/api/backend-registry/types\";\n// Import the trigger helpers from the lightweight store, not the overlay\n// component, so the eagerly-mounted sidebar/backend-selector graph does not\n// pull in the overlay's render code (the overlay is lazy-loaded from\n// `routes/root-layout.tsx`).\nimport {\n ENVIRONMENT_SWITCH_SETACTIVE_DELAY_MS,\n triggerEnvironmentSwitch,\n} from \"#/components/features/backends/environment-switch-store\";\nimport { NavigationLink } from \"#/components/shared/navigation-link\";\nimport { StyledTooltip } from \"#/components/shared/buttons/styled-tooltip\";\nimport { useConversationStore } from \"#/stores/conversation-store\";\nimport { AddBackendModal } from \"./add-backend-modal\";\nimport { BackendStatusDot } from \"./backend-status-dot\";\nimport { ManageBackendsModal } from \"./manage-backends-modal\";\nimport { cn } from \"#/utils/utils\";\nimport { formControlTransitionClassName } from \"#/utils/form-control-classes\";\n\nconst VALUE_SEPARATOR = \"::\";\n\nfunction makeOptionValue(backendId: string, orgId: string | null): string {\n return orgId ? `${backendId}${VALUE_SEPARATOR}${orgId}` : backendId;\n}\n\nfunction parseOptionValue(value: string): {\n backendId: string;\n orgId: string | null;\n} {\n const [backendId, orgId] = value.split(VALUE_SEPARATOR);\n return { backendId, orgId: orgId ?? null };\n}\n\nfunction buildStatusPrefix(health: BackendHealth | undefined) {\n return <BackendStatusDot isConnected={health?.isConnected ?? null} />;\n}\n\nfunction buildOptions(\n registered: Backend[],\n personalWorkspaceLabel: string,\n cloudOrgs: ReturnType<typeof useAllCloudOrganizations>,\n currentUserIds: ReturnType<typeof useCloudCurrentUserId>,\n healthByBackendId: Record<string, BackendHealth>,\n): DropdownOption[] {\n const options: DropdownOption[] = [];\n\n const locals = registered.filter((b) => b.kind === \"local\");\n const clouds = registered.filter((b) => b.kind === \"cloud\");\n\n for (const b of locals) {\n options.push({\n value: makeOptionValue(b.id, null),\n label: b.name,\n prefix: buildStatusPrefix(healthByBackendId[b.id]),\n });\n }\n\n for (const b of clouds) {\n const entry = cloudOrgs[b.id];\n const prefix = buildStatusPrefix(healthByBackendId[b.id]);\n if (!entry || entry.orgs.length === 0) {\n options.push({\n value: makeOptionValue(b.id, null),\n label: b.name,\n prefix,\n });\n } else {\n // Personal-workspace rule (per the cloud contract): the org whose\n // id matches the calling user's id is the user's personal\n // workspace. We resolve `user_id` once per backend (via /me on any\n // one org) and apply it across all orgs of that backend.\n const userIdForBackend = currentUserIds[b.id]?.userId ?? null;\n\n for (const org of entry.orgs) {\n const isPersonal = !!userIdForBackend && userIdForBackend === org.id;\n const orgLabel = isPersonal ? personalWorkspaceLabel : org.name;\n options.push({\n value: makeOptionValue(b.id, org.id),\n label: `${b.name} – ${orgLabel}`,\n // All org rows for the same cloud backend share that backend's\n // single connectivity verdict — there is no per-org probe.\n prefix,\n });\n }\n }\n }\n\n return options;\n}\n\ninterface BackendSelectorProps {\n /** Render the menu above the trigger (e.g. when pinned to bottom of sidebar). */\n openUpward?: boolean;\n /** Hide the selector input trigger and only render the dropdown menu. */\n hideTrigger?: boolean;\n /** Whether the dropdown menu should start open on mount. */\n defaultOpen?: boolean;\n /** Callback fired after selecting a backend/org option. */\n onSelectOption?: () => void;\n /**\n * Override the internal Add Backend modal handling. When provided,\n * clicking \"Add Backend\" calls this instead of opening BackendSelector's\n * own modal. Useful when the selector is mounted inside an ephemeral\n * container (e.g. the collapsed-sidebar popover) and the modal must\n * survive the parent unmounting.\n */\n onOpenAddBackend?: () => void;\n /** Same as onOpenAddBackend but for the Manage Backends modal. */\n onOpenManageBackends?: () => void;\n /**\n * Whether the surrounding sidebar rail is in its collapsed variant. Passed\n * down from `SidebarRailBody` so the mobile drawer (which always renders\n * the expanded rail) can override the persisted desktop value.\n */\n sidebarCollapsed?: boolean;\n}\n\nexport function BackendSelector({\n openUpward = false,\n hideTrigger = false,\n defaultOpen = false,\n onSelectOption,\n onOpenAddBackend,\n onOpenManageBackends,\n sidebarCollapsed = false,\n}: BackendSelectorProps = {}) {\n const { t } = useTranslation(\"openhands\");\n const { backends, active, setActive } = useActiveBackendContext();\n const cloudOrgs = useAllCloudOrganizations();\n const currentUserIds = useCloudCurrentUserId();\n // Probe each registered backend every 10s.\n const healthByBackendId = useBackendsHealth(backends);\n const navigate = useNavigate();\n const settingsMatch = useMatch(\"/settings\");\n const settingsSubrouteMatch = useMatch(\"/settings/*\");\n const conversationMatch = useMatch(\"/conversations/:conversationId\");\n const automationDetailMatch = useMatch(\"/automations/:automationId\");\n const [addBackendModalOpen, setAddBackendModalOpen] = React.useState(false);\n const [manageBackendsModalOpen, setManageBackendsModalOpen] =\n React.useState(false);\n\n const personalWorkspaceLabel = t(I18nKey.BACKEND$PERSONAL_WORKSPACE);\n\n const options = React.useMemo(\n () =>\n buildOptions(\n backends,\n personalWorkspaceLabel,\n cloudOrgs,\n currentUserIds,\n healthByBackendId,\n ),\n [\n backends,\n personalWorkspaceLabel,\n cloudOrgs,\n currentUserIds,\n healthByBackendId,\n ],\n );\n\n const activeValue = makeOptionValue(active.backend.id, active.orgId);\n const activeOption = options.find((o) => o.value === activeValue);\n const isSettingsActive = Boolean(settingsMatch || settingsSubrouteMatch);\n const settingsLabel = t(I18nKey.SIDEBAR$SETTINGS);\n const isRightPanelShown = useConversationStore(\n (state) => state.isRightPanelShown,\n );\n // When the sidebar rail is expanded, `placement=\"left\"` hugs the main\n // canvas and reads awkwardly; prefer above the control. When the rail is\n // collapsed, keep left except on active conversation + open right drawer.\n const settingsTooltipPlacement =\n !sidebarCollapsed || (conversationMatch && isRightPanelShown)\n ? \"top\"\n : \"left\";\n\n const someCloudLoading = Object.values(cloudOrgs).some((c) => c.isLoading);\n\n // Self-heal a malformed `(cloudBackendId, null)` selection.\n //\n // Once a cloud backend's orgs resolve, the dropdown only renders\n // per-org rows for it — the `(backendId, null)` row disappears, so\n // selecting that shape would drift from what the dropdown can render\n // (UI says \"Local\", APIs hit cloud). When we detect the drift, snap\n // the selection onto the personal-workspace org (or, lacking a /me\n // result, the first org). The selection is recorded locally only;\n // the cloud request scope follows from the API key's bound org and the\n // X-Org-Id header sent by `callCloudProxy`, so the cloud UI's\n // org choice is never mutated as a side effect.\n React.useEffect(() => {\n if (active.backend.kind !== \"cloud\" || active.orgId) return;\n const { backend } = active;\n const entry = cloudOrgs[backend.id];\n if (!entry || entry.orgs.length === 0) return;\n\n const userId = currentUserIds[backend.id]?.userId ?? null;\n const personal = userId\n ? entry.orgs.find((o) => o.id === userId)\n : undefined;\n const target = personal ?? entry.orgs[0];\n if (target) {\n setActive(backend.id, target.id);\n }\n }, [active, cloudOrgs, currentUserIds, setActive]);\n\n const openAddBackendModal = React.useCallback(() => {\n if (onOpenAddBackend) {\n onOpenAddBackend();\n onSelectOption?.();\n return;\n }\n setAddBackendModalOpen(true);\n }, [onOpenAddBackend, onSelectOption]);\n\n const openManageBackendsModal = React.useCallback(() => {\n if (onOpenManageBackends) {\n onOpenManageBackends();\n onSelectOption?.();\n return;\n }\n setManageBackendsModalOpen(true);\n }, [onOpenManageBackends, onSelectOption]);\n\n const preventDropdownMenuClose = React.useCallback(\n (event: React.MouseEvent<HTMLButtonElement>) => {\n event.preventDefault();\n event.stopPropagation();\n },\n [],\n );\n\n const addBackendFooter = (\n <div className=\"flex flex-col\">\n <button\n type=\"button\"\n data-testid=\"add-backend-menu-item\"\n onMouseDown={preventDropdownMenuClose}\n onClick={openAddBackendModal}\n className=\"flex w-full items-center gap-2 px-2 py-2 rounded-md text-sm cursor-pointer text-white hover:bg-[var(--oh-interactive-hover)]\"\n >\n <Plus width={16} height={16} className=\"text-white shrink-0\" />\n {t(I18nKey.BACKEND$ADD)}\n </button>\n <button\n type=\"button\"\n data-testid=\"manage-backends-menu-item\"\n onMouseDown={preventDropdownMenuClose}\n onClick={openManageBackendsModal}\n className=\"flex w-full items-center gap-2 px-2 py-2 rounded-md text-sm cursor-pointer text-white hover:bg-[var(--oh-interactive-hover)]\"\n >\n <Settings width={16} height={16} className=\"text-white shrink-0\" />\n {t(I18nKey.BACKEND$MANAGE)}\n </button>\n </div>\n );\n\n const handleSelectBackend = React.useCallback(\n async (value: string) => {\n if (value === activeValue) return;\n\n const { backendId, orgId } = parseOptionValue(value);\n const target = backends.find((b) => b.id === backendId);\n if (!target) return;\n\n triggerEnvironmentSwitch(\n options.find((option) => option.value === value)?.label ?? target.name,\n );\n await new Promise<void>((resolve) => {\n setTimeout(resolve, ENVIRONMENT_SWITCH_SETACTIVE_DELAY_MS);\n });\n\n // @spec BM-002 — Switching backends keeps the user on the same page\n if (conversationMatch) navigate(\"/conversations\");\n else if (automationDetailMatch) navigate(\"/automations\");\n\n setActive(target.id, orgId);\n onSelectOption?.();\n },\n [\n activeValue,\n backends,\n conversationMatch,\n automationDetailMatch,\n navigate,\n options,\n setActive,\n t,\n onSelectOption,\n ],\n );\n\n return (\n <>\n <div className=\"flex items-center gap-2 w-full\">\n <div className=\"flex-1 min-w-0\">\n <Dropdown\n testId=\"backend-selector\"\n key={`${activeValue}-${activeOption?.label ?? \"\"}`}\n defaultValue={\n activeOption ?? {\n value: activeValue,\n label: active.backend.name,\n prefix: buildStatusPrefix(healthByBackendId[active.backend.id]),\n }\n }\n footer={addBackendFooter}\n openUpward={openUpward}\n hideTrigger={hideTrigger}\n defaultOpen={defaultOpen}\n openOnHover={!hideTrigger}\n onChange={(item) => {\n if (!item) return;\n void handleSelectBackend(item.value);\n }}\n placeholder={active.backend.name}\n loading={someCloudLoading}\n options={options}\n className=\"h-10 px-2 py-0 bg-transparent border-transparent hover:bg-[var(--oh-surface-raised)] focus-within:bg-[var(--oh-surface-raised)] focus-within:border-transparent focus-within:ring-0\"\n />\n </div>\n {!hideTrigger ? (\n <StyledTooltip\n content={settingsLabel}\n placement={settingsTooltipPlacement}\n offset={10}\n >\n <NavigationLink\n to=\"/settings\"\n data-testid=\"backend-selector-settings-link\"\n data-active={isSettingsActive}\n aria-label={settingsLabel}\n className={\n isSettingsActive\n ? cn(\n \"inline-flex items-center justify-center shrink-0 w-9 h-9 rounded-md bg-tertiary text-white font-normal cursor-pointer\",\n formControlTransitionClassName,\n )\n : cn(\n \"inline-flex items-center justify-center shrink-0 w-9 h-9 rounded-md text-[var(--oh-muted)] hover:text-white hover:bg-[var(--oh-surface-raised)] cursor-pointer\",\n formControlTransitionClassName,\n )\n }\n >\n <Settings width={16} height={16} />\n </NavigationLink>\n </StyledTooltip>\n ) : null}\n </div>\n {addBackendModalOpen ? (\n <AddBackendModal onClose={() => setAddBackendModalOpen(false)} />\n ) : null}\n {manageBackendsModalOpen ? (\n <ManageBackendsModal\n onClose={() => setManageBackendsModalOpen(false)}\n />\n ) : null}\n </>\n );\n}\n"],"mappings":"8lCAgCA,IAAM,EAAkB,KAExB,SAAS,EAAgB,EAAmB,EAA8B,CACxE,OAAO,EAAQ,GAAG,IAAY,IAAkB,IAAU,EAG5D,SAAS,EAAiB,EAGxB,CACA,GAAM,CAAC,EAAW,GAAS,EAAM,MAAM,EAAgB,CACvD,MAAO,CAAE,YAAW,MAAO,GAAS,KAAM,CAG5C,SAAS,EAAkB,EAAmC,CAC5D,OAAO,EAAA,EAAA,KAAC,EAAA,iBAAD,CAAkB,YAAa,GAAQ,aAAe,KAAQ,CAAA,CAGvE,SAAS,EACP,EACA,EACA,EACA,EACA,EACkB,CAClB,IAAM,EAA4B,EAAE,CAE9B,EAAS,EAAW,OAAQ,GAAM,EAAE,OAAS,QAAQ,CACrD,EAAS,EAAW,OAAQ,GAAM,EAAE,OAAS,QAAQ,CAE3D,IAAK,IAAM,KAAK,EACd,EAAQ,KAAK,CACX,MAAO,EAAgB,EAAE,GAAI,KAAK,CAClC,MA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AAS,CACb,GACA,GAAoB,EAAK,MAAM,EAEtC,YAAa,EAAO,QAAQ,KAC5B,QAAS,GACA,UACT,UAAU,sLACV,CArBK,GAAG,EAAY,GAAG,GAAc,OAAS,KAqB9C,CACE,CAAA,CACJ,EA0BE,MAzBF,EAAA,EAAA,KAAC,EAAA,cAAD,CACE,QAAS,EACT,UAAW,GACX,OAAQ,aAER,EAAA,EAAA,KAAC,EAAA,eAAD,CACE,GAAG,YACH,cAAY,iCACZ,cAAa,EACb,aAAY,EACZ,UACE,EACI,EAAA,GACE,wHACA,EAAA,+BACD,CACD,EAAA,GACE,iKACA,EAAA,+BACD,WAGP,EAAA,EAAA,KAAC,EAAA,SAAD,CAAU,MAAO,GAAI,OAAQ,GAAM,CAAA,CACpB,CAAA,CACH,CAAA,CAEd,GACL,GACC,EAAA,EAAA,KAAC,EAAA,gBAAD,CAAiB,YAAe,EAAuB,GAAM,CAAI,CAAA,CAC/D,KACH,GACC,EAAA,EAAA,KAAC,EAAA,oBAAD,CACE,YAAe,EAA2B,GAAM,CAChD,CAAA,CACA,KACH,CAAA,CAAA"}
@@ -6,44 +6,45 @@ import { useActiveBackendContext as i } from "../../../contexts/active-backend-c
6
6
  import { Plus as a } from "../../../node_modules/lucide-react/dist/esm/icons/plus.js";
7
7
  import { Settings as o } from "../../../node_modules/lucide-react/dist/esm/icons/settings.js";
8
8
  import { formControlTransitionClassName as s } from "../../../utils/form-control-classes.js";
9
- import { StyledTooltip as c } from "../../shared/buttons/styled-tooltip.js";
10
- import { useAllCloudOrganizations as l } from "../../../hooks/query/use-cloud-organizations.js";
11
- import { useCloudCurrentUserId as u } from "../../../hooks/query/use-cloud-current-user-id.js";
12
- import { Dropdown as d } from "../../../ui/dropdown/dropdown.js";
13
- import { useBackendsHealth as f } from "../../../hooks/query/use-backends-health.js";
14
- import { triggerEnvironmentSwitch as ee } from "./environment-switch-store.js";
9
+ import { StyledTooltip as ee } from "../../shared/buttons/styled-tooltip.js";
10
+ import { NavigationLink as te } from "../../shared/navigation-link.js";
11
+ import { useAllCloudOrganizations as c } from "../../../hooks/query/use-cloud-organizations.js";
12
+ import { useCloudCurrentUserId as l } from "../../../hooks/query/use-cloud-current-user-id.js";
13
+ import { Dropdown as u } from "../../../ui/dropdown/dropdown.js";
14
+ import { useBackendsHealth as d } from "../../../hooks/query/use-backends-health.js";
15
+ import { triggerEnvironmentSwitch as f } from "./environment-switch-store.js";
15
16
  import { BackendStatusDot as p } from "./backend-status-dot.js";
16
17
  import { AddBackendModal as m } from "./add-backend-modal.js";
17
- import { ManageBackendsModal as te } from "./manage-backends-modal.js";
18
- import h from "react";
19
- import { Fragment as g, jsx as _, jsxs as v } from "react/jsx-runtime";
20
- import { useMatch as y, useNavigate as b } from "react-router";
18
+ import { ManageBackendsModal as h } from "./manage-backends-modal.js";
19
+ import g from "react";
20
+ import { Fragment as _, jsx as v, jsxs as y } from "react/jsx-runtime";
21
+ import { useMatch as b, useNavigate as x } from "react-router";
21
22
  //#region src/components/features/backends/backend-selector.tsx
22
- var x = "::";
23
- function S(e, t) {
24
- return t ? `${e}${x}${t}` : e;
23
+ var S = "::";
24
+ function C(e, t) {
25
+ return t ? `${e}${S}${t}` : e;
25
26
  }
26
27
  function ne(e) {
27
- let [t, n] = e.split(x);
28
+ let [t, n] = e.split(S);
28
29
  return {
29
30
  backendId: t,
30
31
  orgId: n ?? null
31
32
  };
32
33
  }
33
- function C(e) {
34
- return /* @__PURE__ */ _(p, { isConnected: e?.isConnected ?? null });
34
+ function w(e) {
35
+ return /* @__PURE__ */ v(p, { isConnected: e?.isConnected ?? null });
35
36
  }
36
- function w(e, t, n, r, i) {
37
+ function T(e, t, n, r, i) {
37
38
  let a = [], o = e.filter((e) => e.kind === "local"), s = e.filter((e) => e.kind === "cloud");
38
39
  for (let e of o) a.push({
39
- value: S(e.id, null),
40
+ value: C(e.id, null),
40
41
  label: e.name,
41
- prefix: C(i[e.id])
42
+ prefix: w(i[e.id])
42
43
  });
43
44
  for (let e of s) {
44
- let o = n[e.id], s = C(i[e.id]);
45
+ let o = n[e.id], s = w(i[e.id]);
45
46
  if (!o || o.orgs.length === 0) a.push({
46
- value: S(e.id, null),
47
+ value: C(e.id, null),
47
48
  label: e.name,
48
49
  prefix: s
49
50
  });
@@ -52,7 +53,7 @@ function w(e, t, n, r, i) {
52
53
  for (let r of o.orgs) {
53
54
  let i = n && n === r.id ? t : r.name;
54
55
  a.push({
55
- value: S(e.id, r.id),
56
+ value: C(e.id, r.id),
56
57
  label: `${e.name} – ${i}`,
57
58
  prefix: s
58
59
  });
@@ -61,130 +62,129 @@ function w(e, t, n, r, i) {
61
62
  }
62
63
  return a;
63
64
  }
64
- function T({ openUpward: p = !1, hideTrigger: x = !1, defaultOpen: T = !1, onSelectOption: E, onOpenAddBackend: D, onOpenManageBackends: O, sidebarCollapsed: k = !1 } = {}) {
65
- let { t: A } = e("openhands"), { backends: j, active: M, setActive: N } = i(), P = l(), F = u(), I = f(j), L = b(), R = y("/settings"), z = y("/settings/*"), B = y("/conversations/:conversationId"), V = y("/automations/:automationId"), [H, U] = h.useState(!1), [W, G] = h.useState(!1), K = A(t.BACKEND$PERSONAL_WORKSPACE), q = h.useMemo(() => w(j, K, P, F, I), [
66
- j,
67
- K,
68
- P,
65
+ function E({ openUpward: p = !1, hideTrigger: S = !1, defaultOpen: E = !1, onSelectOption: D, onOpenAddBackend: O, onOpenManageBackends: k, sidebarCollapsed: A = !1 } = {}) {
66
+ let { t: j } = e("openhands"), { backends: M, active: N, setActive: P } = i(), F = c(), I = l(), L = d(M), R = x(), z = b("/settings"), B = b("/settings/*"), V = b("/conversations/:conversationId"), H = b("/automations/:automationId"), [U, W] = g.useState(!1), [G, K] = g.useState(!1), q = j(t.BACKEND$PERSONAL_WORKSPACE), J = g.useMemo(() => T(M, q, F, I, L), [
67
+ M,
68
+ q,
69
69
  F,
70
- I
71
- ]), J = S(M.backend.id, M.orgId), Y = q.find((e) => e.value === J), X = !!(R || z), Z = A(t.SIDEBAR$SETTINGS), re = r((e) => e.isRightPanelShown), ie = !k || B && re ? "top" : "left", ae = Object.values(P).some((e) => e.isLoading);
72
- h.useEffect(() => {
73
- if (M.backend.kind !== "cloud" || M.orgId) return;
74
- let { backend: e } = M, t = P[e.id];
70
+ I,
71
+ L
72
+ ]), Y = C(N.backend.id, N.orgId), X = J.find((e) => e.value === Y), Z = !!(z || B), Q = j(t.SIDEBAR$SETTINGS), re = r((e) => e.isRightPanelShown), ie = !A || V && re ? "top" : "left", ae = Object.values(F).some((e) => e.isLoading);
73
+ g.useEffect(() => {
74
+ if (N.backend.kind !== "cloud" || N.orgId) return;
75
+ let { backend: e } = N, t = F[e.id];
75
76
  if (!t || t.orgs.length === 0) return;
76
- let n = F[e.id]?.userId ?? null, r = (n ? t.orgs.find((e) => e.id === n) : void 0) ?? t.orgs[0];
77
- r && N(e.id, r.id);
77
+ let n = I[e.id]?.userId ?? null, r = (n ? t.orgs.find((e) => e.id === n) : void 0) ?? t.orgs[0];
78
+ r && P(e.id, r.id);
78
79
  }, [
79
- M,
80
- P,
80
+ N,
81
81
  F,
82
- N
82
+ I,
83
+ P
83
84
  ]);
84
- let Q = h.useCallback(() => {
85
- if (D) {
86
- D(), E?.();
85
+ let oe = g.useCallback(() => {
86
+ if (O) {
87
+ O(), D?.();
87
88
  return;
88
89
  }
89
- U(!0);
90
- }, [D, E]), oe = h.useCallback(() => {
91
- if (O) {
92
- O(), E?.();
90
+ W(!0);
91
+ }, [O, D]), se = g.useCallback(() => {
92
+ if (k) {
93
+ k(), D?.();
93
94
  return;
94
95
  }
95
- G(!0);
96
- }, [O, E]), $ = h.useCallback((e) => {
96
+ K(!0);
97
+ }, [k, D]), $ = g.useCallback((e) => {
97
98
  e.preventDefault(), e.stopPropagation();
98
- }, []), se = /* @__PURE__ */ v("div", {
99
+ }, []), ce = /* @__PURE__ */ y("div", {
99
100
  className: "flex flex-col",
100
- children: [/* @__PURE__ */ v("button", {
101
+ children: [/* @__PURE__ */ y("button", {
101
102
  type: "button",
102
103
  "data-testid": "add-backend-menu-item",
103
104
  onMouseDown: $,
104
- onClick: Q,
105
+ onClick: oe,
105
106
  className: "flex w-full items-center gap-2 px-2 py-2 rounded-md text-sm cursor-pointer text-white hover:bg-[var(--oh-interactive-hover)]",
106
- children: [/* @__PURE__ */ _(a, {
107
+ children: [/* @__PURE__ */ v(a, {
107
108
  width: 16,
108
109
  height: 16,
109
110
  className: "text-white shrink-0"
110
- }), A(t.BACKEND$ADD)]
111
- }), /* @__PURE__ */ v("button", {
111
+ }), j(t.BACKEND$ADD)]
112
+ }), /* @__PURE__ */ y("button", {
112
113
  type: "button",
113
114
  "data-testid": "manage-backends-menu-item",
114
115
  onMouseDown: $,
115
- onClick: oe,
116
+ onClick: se,
116
117
  className: "flex w-full items-center gap-2 px-2 py-2 rounded-md text-sm cursor-pointer text-white hover:bg-[var(--oh-interactive-hover)]",
117
- children: [/* @__PURE__ */ _(o, {
118
+ children: [/* @__PURE__ */ v(o, {
118
119
  width: 16,
119
120
  height: 16,
120
121
  className: "text-white shrink-0"
121
- }), A(t.BACKEND$MANAGE)]
122
+ }), j(t.BACKEND$MANAGE)]
122
123
  })]
123
- }), ce = h.useCallback(async (e) => {
124
- if (e === J) return;
125
- let { backendId: t, orgId: n } = ne(e), r = j.find((e) => e.id === t);
126
- r && (ee(q.find((t) => t.value === e)?.label ?? r.name), await new Promise((e) => {
124
+ }), le = g.useCallback(async (e) => {
125
+ if (e === Y) return;
126
+ let { backendId: t, orgId: n } = ne(e), r = M.find((e) => e.id === t);
127
+ r && (f(J.find((t) => t.value === e)?.label ?? r.name), await new Promise((e) => {
127
128
  setTimeout(e, 400);
128
- }), B ? L("/conversations") : V && L("/automations"), N(r.id, n), E?.());
129
+ }), V ? R("/conversations") : H && R("/automations"), P(r.id, n), D?.());
129
130
  }, [
131
+ Y,
132
+ M,
133
+ V,
134
+ H,
135
+ R,
130
136
  J,
137
+ P,
131
138
  j,
132
- B,
133
- V,
134
- L,
135
- q,
136
- N,
137
- A,
138
- E
139
+ D
139
140
  ]);
140
- return /* @__PURE__ */ v(g, { children: [
141
- /* @__PURE__ */ v("div", {
141
+ return /* @__PURE__ */ y(_, { children: [
142
+ /* @__PURE__ */ y("div", {
142
143
  className: "flex items-center gap-2 w-full",
143
- children: [/* @__PURE__ */ _("div", {
144
+ children: [/* @__PURE__ */ v("div", {
144
145
  className: "flex-1 min-w-0",
145
- children: /* @__PURE__ */ _(d, {
146
+ children: /* @__PURE__ */ v(u, {
146
147
  testId: "backend-selector",
147
- defaultValue: Y ?? {
148
- value: J,
149
- label: M.backend.name,
150
- prefix: C(I[M.backend.id])
148
+ defaultValue: X ?? {
149
+ value: Y,
150
+ label: N.backend.name,
151
+ prefix: w(L[N.backend.id])
151
152
  },
152
- footer: se,
153
+ footer: ce,
153
154
  openUpward: p,
154
- hideTrigger: x,
155
- defaultOpen: T,
156
- openOnHover: !x,
155
+ hideTrigger: S,
156
+ defaultOpen: E,
157
+ openOnHover: !S,
157
158
  onChange: (e) => {
158
- e && ce(e.value);
159
+ e && le(e.value);
159
160
  },
160
- placeholder: M.backend.name,
161
+ placeholder: N.backend.name,
161
162
  loading: ae,
162
- options: q,
163
+ options: J,
163
164
  className: "h-10 px-2 py-0 bg-transparent border-transparent hover:bg-[var(--oh-surface-raised)] focus-within:bg-[var(--oh-surface-raised)] focus-within:border-transparent focus-within:ring-0"
164
- }, `${J}-${Y?.label ?? ""}`)
165
- }), x ? null : /* @__PURE__ */ _(c, {
166
- content: Z,
165
+ }, `${Y}-${X?.label ?? ""}`)
166
+ }), S ? null : /* @__PURE__ */ v(ee, {
167
+ content: Q,
167
168
  placement: ie,
168
169
  offset: 10,
169
- children: /* @__PURE__ */ _("button", {
170
- type: "button",
170
+ children: /* @__PURE__ */ v(te, {
171
+ to: "/settings",
171
172
  "data-testid": "backend-selector-settings-link",
172
- "data-active": X,
173
- "aria-label": Z,
174
- onClick: () => L("/settings"),
175
- className: n(X ? "inline-flex items-center justify-center shrink-0 w-9 h-9 rounded-md bg-tertiary text-white font-normal cursor-pointer" : "inline-flex items-center justify-center shrink-0 w-9 h-9 rounded-md text-[var(--oh-muted)] hover:text-white hover:bg-[var(--oh-surface-raised)] cursor-pointer", s),
176
- children: /* @__PURE__ */ _(o, {
173
+ "data-active": Z,
174
+ "aria-label": Q,
175
+ className: n(Z ? "inline-flex items-center justify-center shrink-0 w-9 h-9 rounded-md bg-tertiary text-white font-normal cursor-pointer" : "inline-flex items-center justify-center shrink-0 w-9 h-9 rounded-md text-[var(--oh-muted)] hover:text-white hover:bg-[var(--oh-surface-raised)] cursor-pointer", s),
176
+ children: /* @__PURE__ */ v(o, {
177
177
  width: 16,
178
178
  height: 16
179
179
  })
180
180
  })
181
181
  })]
182
182
  }),
183
- H ? /* @__PURE__ */ _(m, { onClose: () => U(!1) }) : null,
184
- W ? /* @__PURE__ */ _(te, { onClose: () => G(!1) }) : null
183
+ U ? /* @__PURE__ */ v(m, { onClose: () => W(!1) }) : null,
184
+ G ? /* @__PURE__ */ v(h, { onClose: () => K(!1) }) : null
185
185
  ] });
186
186
  }
187
187
  //#endregion
188
- export { T as BackendSelector };
188
+ export { E as BackendSelector };
189
189
 
190
190
  //# sourceMappingURL=backend-selector.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"backend-selector.js","names":[],"sources":["../../../../src/components/features/backends/backend-selector.tsx"],"sourcesContent":["import React from \"react\";\nimport { useTranslation } from \"react-i18next\";\nimport { useMatch, useNavigate } from \"react-router\";\nimport { Plus, Settings } from \"lucide-react\";\nimport { Dropdown } from \"#/ui/dropdown/dropdown\";\nimport { DropdownOption } from \"#/ui/dropdown/types\";\nimport { useActiveBackendContext } from \"#/contexts/active-backend-context\";\nimport { useAllCloudOrganizations } from \"#/hooks/query/use-cloud-organizations\";\nimport { useCloudCurrentUserId } from \"#/hooks/query/use-cloud-current-user-id\";\nimport {\n useBackendsHealth,\n type BackendHealth,\n} from \"#/hooks/query/use-backends-health\";\nimport { I18nKey } from \"#/i18n/declaration\";\nimport type { Backend } from \"#/api/backend-registry/types\";\n// Import the trigger helpers from the lightweight store, not the overlay\n// component, so the eagerly-mounted sidebar/backend-selector graph does not\n// pull in the overlay's render code (the overlay is lazy-loaded from\n// `routes/root-layout.tsx`).\nimport {\n ENVIRONMENT_SWITCH_SETACTIVE_DELAY_MS,\n triggerEnvironmentSwitch,\n} from \"#/components/features/backends/environment-switch-store\";\nimport { StyledTooltip } from \"#/components/shared/buttons/styled-tooltip\";\nimport { useConversationStore } from \"#/stores/conversation-store\";\nimport { AddBackendModal } from \"./add-backend-modal\";\nimport { BackendStatusDot } from \"./backend-status-dot\";\nimport { ManageBackendsModal } from \"./manage-backends-modal\";\nimport { cn } from \"#/utils/utils\";\nimport { formControlTransitionClassName } from \"#/utils/form-control-classes\";\n\nconst VALUE_SEPARATOR = \"::\";\n\nfunction makeOptionValue(backendId: string, orgId: string | null): string {\n return orgId ? `${backendId}${VALUE_SEPARATOR}${orgId}` : backendId;\n}\n\nfunction parseOptionValue(value: string): {\n backendId: string;\n orgId: string | null;\n} {\n const [backendId, orgId] = value.split(VALUE_SEPARATOR);\n return { backendId, orgId: orgId ?? null };\n}\n\nfunction buildStatusPrefix(health: BackendHealth | undefined) {\n return <BackendStatusDot isConnected={health?.isConnected ?? null} />;\n}\n\nfunction buildOptions(\n registered: Backend[],\n personalWorkspaceLabel: string,\n cloudOrgs: ReturnType<typeof useAllCloudOrganizations>,\n currentUserIds: ReturnType<typeof useCloudCurrentUserId>,\n healthByBackendId: Record<string, BackendHealth>,\n): DropdownOption[] {\n const options: DropdownOption[] = [];\n\n const locals = registered.filter((b) => b.kind === \"local\");\n const clouds = registered.filter((b) => b.kind === \"cloud\");\n\n for (const b of locals) {\n options.push({\n value: makeOptionValue(b.id, null),\n label: b.name,\n prefix: buildStatusPrefix(healthByBackendId[b.id]),\n });\n }\n\n for (const b of clouds) {\n const entry = cloudOrgs[b.id];\n const prefix = buildStatusPrefix(healthByBackendId[b.id]);\n if (!entry || entry.orgs.length === 0) {\n options.push({\n value: makeOptionValue(b.id, null),\n label: b.name,\n prefix,\n });\n } else {\n // Personal-workspace rule (per the cloud contract): the org whose\n // id matches the calling user's id is the user's personal\n // workspace. We resolve `user_id` once per backend (via /me on any\n // one org) and apply it across all orgs of that backend.\n const userIdForBackend = currentUserIds[b.id]?.userId ?? null;\n\n for (const org of entry.orgs) {\n const isPersonal = !!userIdForBackend && userIdForBackend === org.id;\n const orgLabel = isPersonal ? personalWorkspaceLabel : org.name;\n options.push({\n value: makeOptionValue(b.id, org.id),\n label: `${b.name} – ${orgLabel}`,\n // All org rows for the same cloud backend share that backend's\n // single connectivity verdict — there is no per-org probe.\n prefix,\n });\n }\n }\n }\n\n return options;\n}\n\ninterface BackendSelectorProps {\n /** Render the menu above the trigger (e.g. when pinned to bottom of sidebar). */\n openUpward?: boolean;\n /** Hide the selector input trigger and only render the dropdown menu. */\n hideTrigger?: boolean;\n /** Whether the dropdown menu should start open on mount. */\n defaultOpen?: boolean;\n /** Callback fired after selecting a backend/org option. */\n onSelectOption?: () => void;\n /**\n * Override the internal Add Backend modal handling. When provided,\n * clicking \"Add Backend\" calls this instead of opening BackendSelector's\n * own modal. Useful when the selector is mounted inside an ephemeral\n * container (e.g. the collapsed-sidebar popover) and the modal must\n * survive the parent unmounting.\n */\n onOpenAddBackend?: () => void;\n /** Same as onOpenAddBackend but for the Manage Backends modal. */\n onOpenManageBackends?: () => void;\n /**\n * Whether the surrounding sidebar rail is in its collapsed variant. Passed\n * down from `SidebarRailBody` so the mobile drawer (which always renders\n * the expanded rail) can override the persisted desktop value.\n */\n sidebarCollapsed?: boolean;\n}\n\nexport function BackendSelector({\n openUpward = false,\n hideTrigger = false,\n defaultOpen = false,\n onSelectOption,\n onOpenAddBackend,\n onOpenManageBackends,\n sidebarCollapsed = false,\n}: BackendSelectorProps = {}) {\n const { t } = useTranslation(\"openhands\");\n const { backends, active, setActive } = useActiveBackendContext();\n const cloudOrgs = useAllCloudOrganizations();\n const currentUserIds = useCloudCurrentUserId();\n // Probe each registered backend every 10s.\n const healthByBackendId = useBackendsHealth(backends);\n const navigate = useNavigate();\n const settingsMatch = useMatch(\"/settings\");\n const settingsSubrouteMatch = useMatch(\"/settings/*\");\n const conversationMatch = useMatch(\"/conversations/:conversationId\");\n const automationDetailMatch = useMatch(\"/automations/:automationId\");\n const [addBackendModalOpen, setAddBackendModalOpen] = React.useState(false);\n const [manageBackendsModalOpen, setManageBackendsModalOpen] =\n React.useState(false);\n\n const personalWorkspaceLabel = t(I18nKey.BACKEND$PERSONAL_WORKSPACE);\n\n const options = React.useMemo(\n () =>\n buildOptions(\n backends,\n personalWorkspaceLabel,\n cloudOrgs,\n currentUserIds,\n healthByBackendId,\n ),\n [\n backends,\n personalWorkspaceLabel,\n cloudOrgs,\n currentUserIds,\n healthByBackendId,\n ],\n );\n\n const activeValue = makeOptionValue(active.backend.id, active.orgId);\n const activeOption = options.find((o) => o.value === activeValue);\n const isSettingsActive = Boolean(settingsMatch || settingsSubrouteMatch);\n const settingsLabel = t(I18nKey.SIDEBAR$SETTINGS);\n const isRightPanelShown = useConversationStore(\n (state) => state.isRightPanelShown,\n );\n // When the sidebar rail is expanded, `placement=\"left\"` hugs the main\n // canvas and reads awkwardly; prefer above the control. When the rail is\n // collapsed, keep left except on active conversation + open right drawer.\n const settingsTooltipPlacement =\n !sidebarCollapsed || (conversationMatch && isRightPanelShown)\n ? \"top\"\n : \"left\";\n\n const someCloudLoading = Object.values(cloudOrgs).some((c) => c.isLoading);\n\n // Self-heal a malformed `(cloudBackendId, null)` selection.\n //\n // Once a cloud backend's orgs resolve, the dropdown only renders\n // per-org rows for it — the `(backendId, null)` row disappears, so\n // selecting that shape would drift from what the dropdown can render\n // (UI says \"Local\", APIs hit cloud). When we detect the drift, snap\n // the selection onto the personal-workspace org (or, lacking a /me\n // result, the first org). The selection is recorded locally only;\n // the cloud request scope follows from the API key's bound org and the\n // X-Org-Id header sent by `callCloudProxy`, so the cloud UI's\n // org choice is never mutated as a side effect.\n React.useEffect(() => {\n if (active.backend.kind !== \"cloud\" || active.orgId) return;\n const { backend } = active;\n const entry = cloudOrgs[backend.id];\n if (!entry || entry.orgs.length === 0) return;\n\n const userId = currentUserIds[backend.id]?.userId ?? null;\n const personal = userId\n ? entry.orgs.find((o) => o.id === userId)\n : undefined;\n const target = personal ?? entry.orgs[0];\n if (target) {\n setActive(backend.id, target.id);\n }\n }, [active, cloudOrgs, currentUserIds, setActive]);\n\n const openAddBackendModal = React.useCallback(() => {\n if (onOpenAddBackend) {\n onOpenAddBackend();\n onSelectOption?.();\n return;\n }\n setAddBackendModalOpen(true);\n }, [onOpenAddBackend, onSelectOption]);\n\n const openManageBackendsModal = React.useCallback(() => {\n if (onOpenManageBackends) {\n onOpenManageBackends();\n onSelectOption?.();\n return;\n }\n setManageBackendsModalOpen(true);\n }, [onOpenManageBackends, onSelectOption]);\n\n const preventDropdownMenuClose = React.useCallback(\n (event: React.MouseEvent<HTMLButtonElement>) => {\n event.preventDefault();\n event.stopPropagation();\n },\n [],\n );\n\n const addBackendFooter = (\n <div className=\"flex flex-col\">\n <button\n type=\"button\"\n data-testid=\"add-backend-menu-item\"\n onMouseDown={preventDropdownMenuClose}\n onClick={openAddBackendModal}\n className=\"flex w-full items-center gap-2 px-2 py-2 rounded-md text-sm cursor-pointer text-white hover:bg-[var(--oh-interactive-hover)]\"\n >\n <Plus width={16} height={16} className=\"text-white shrink-0\" />\n {t(I18nKey.BACKEND$ADD)}\n </button>\n <button\n type=\"button\"\n data-testid=\"manage-backends-menu-item\"\n onMouseDown={preventDropdownMenuClose}\n onClick={openManageBackendsModal}\n className=\"flex w-full items-center gap-2 px-2 py-2 rounded-md text-sm cursor-pointer text-white hover:bg-[var(--oh-interactive-hover)]\"\n >\n <Settings width={16} height={16} className=\"text-white shrink-0\" />\n {t(I18nKey.BACKEND$MANAGE)}\n </button>\n </div>\n );\n\n const handleSelectBackend = React.useCallback(\n async (value: string) => {\n if (value === activeValue) return;\n\n const { backendId, orgId } = parseOptionValue(value);\n const target = backends.find((b) => b.id === backendId);\n if (!target) return;\n\n triggerEnvironmentSwitch(\n options.find((option) => option.value === value)?.label ?? target.name,\n );\n await new Promise<void>((resolve) => {\n setTimeout(resolve, ENVIRONMENT_SWITCH_SETACTIVE_DELAY_MS);\n });\n\n // @spec BM-002 — Switching backends keeps the user on the same page\n if (conversationMatch) navigate(\"/conversations\");\n else if (automationDetailMatch) navigate(\"/automations\");\n\n setActive(target.id, orgId);\n onSelectOption?.();\n },\n [\n activeValue,\n backends,\n conversationMatch,\n automationDetailMatch,\n navigate,\n options,\n setActive,\n t,\n onSelectOption,\n ],\n );\n\n return (\n <>\n <div className=\"flex items-center gap-2 w-full\">\n <div className=\"flex-1 min-w-0\">\n <Dropdown\n testId=\"backend-selector\"\n key={`${activeValue}-${activeOption?.label ?? \"\"}`}\n defaultValue={\n activeOption ?? {\n value: activeValue,\n label: active.backend.name,\n prefix: buildStatusPrefix(healthByBackendId[active.backend.id]),\n }\n }\n footer={addBackendFooter}\n openUpward={openUpward}\n hideTrigger={hideTrigger}\n defaultOpen={defaultOpen}\n openOnHover={!hideTrigger}\n onChange={(item) => {\n if (!item) return;\n void handleSelectBackend(item.value);\n }}\n placeholder={active.backend.name}\n loading={someCloudLoading}\n options={options}\n className=\"h-10 px-2 py-0 bg-transparent border-transparent hover:bg-[var(--oh-surface-raised)] focus-within:bg-[var(--oh-surface-raised)] focus-within:border-transparent focus-within:ring-0\"\n />\n </div>\n {!hideTrigger ? (\n <StyledTooltip\n content={settingsLabel}\n placement={settingsTooltipPlacement}\n offset={10}\n >\n <button\n type=\"button\"\n data-testid=\"backend-selector-settings-link\"\n data-active={isSettingsActive}\n aria-label={settingsLabel}\n onClick={() => navigate(\"/settings\")}\n className={\n isSettingsActive\n ? cn(\n \"inline-flex items-center justify-center shrink-0 w-9 h-9 rounded-md bg-tertiary text-white font-normal cursor-pointer\",\n formControlTransitionClassName,\n )\n : cn(\n \"inline-flex items-center justify-center shrink-0 w-9 h-9 rounded-md text-[var(--oh-muted)] hover:text-white hover:bg-[var(--oh-surface-raised)] cursor-pointer\",\n formControlTransitionClassName,\n )\n }\n >\n <Settings width={16} height={16} />\n </button>\n </StyledTooltip>\n ) : null}\n </div>\n {addBackendModalOpen ? (\n <AddBackendModal onClose={() => setAddBackendModalOpen(false)} />\n ) : null}\n {manageBackendsModalOpen ? (\n <ManageBackendsModal\n onClose={() => setManageBackendsModalOpen(false)}\n />\n ) : null}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA+BA,IAAM,IAAkB;AAExB,SAAS,EAAgB,GAAmB,GAA8B;AACxE,QAAO,IAAQ,GAAG,IAAY,IAAkB,MAAU;;AAG5D,SAAS,GAAiB,GAGxB;CACA,IAAM,CAAC,GAAW,KAAS,EAAM,MAAM,EAAgB;AACvD,QAAO;EAAE;EAAW,OAAO,KAAS;EAAM;;AAG5C,SAAS,EAAkB,GAAmC;AAC5D,QAAO,kBAAC,GAAD,EAAkB,aAAa,GAAQ,eAAe,MAAQ,CAAA;;AAGvE,SAAS,EACP,GACA,GACA,GACA,GACA,GACkB;CAClB,IAAM,IAA4B,EAAE,EAE9B,IAAS,EAAW,QAAQ,MAAM,EAAE,SAAS,QAAQ,EACrD,IAAS,EAAW,QAAQ,MAAM,EAAE,SAAS,QAAQ;AAE3D,MAAK,IAAM,KAAK,EACd,GAAQ,KAAK;EACX,OAAO,EAAgB,EAAE,IAAI,KAAK;EAClC,OAAO,EAAE;EACT,QAAQ,EAAkB,EAAkB,EAAE,IAAI;EACnD,CAAC;AAGJ,MAAK,IAAM,KAAK,GAAQ;EACtB,IAAM,IAAQ,EAAU,EAAE,KACpB,IAAS,EAAkB,EAAkB,EAAE,IAAI;AACzD,MAAI,CAAC,KAAS,EAAM,KAAK,WAAW,EAClC,GAAQ,KAAK;GACX,OAAO,EAAgB,EAAE,IAAI,KAAK;GAClC,OAAO,EAAE;GACT;GACD,CAAC;OACG;GAKL,IAAM,IAAmB,EAAe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"backend-selector.js","names":[],"sources":["../../../../src/components/features/backends/backend-selector.tsx"],"sourcesContent":["import React from \"react\";\nimport { useTranslation } from \"react-i18next\";\nimport { useMatch, useNavigate } from \"react-router\";\nimport { Plus, Settings } from \"lucide-react\";\nimport { Dropdown } from \"#/ui/dropdown/dropdown\";\nimport { DropdownOption } from \"#/ui/dropdown/types\";\nimport { useActiveBackendContext } from \"#/contexts/active-backend-context\";\nimport { useAllCloudOrganizations } from \"#/hooks/query/use-cloud-organizations\";\nimport { useCloudCurrentUserId } from \"#/hooks/query/use-cloud-current-user-id\";\nimport {\n useBackendsHealth,\n type BackendHealth,\n} from \"#/hooks/query/use-backends-health\";\nimport { I18nKey } from \"#/i18n/declaration\";\nimport type { Backend } from \"#/api/backend-registry/types\";\n// Import the trigger helpers from the lightweight store, not the overlay\n// component, so the eagerly-mounted sidebar/backend-selector graph does not\n// pull in the overlay's render code (the overlay is lazy-loaded from\n// `routes/root-layout.tsx`).\nimport {\n ENVIRONMENT_SWITCH_SETACTIVE_DELAY_MS,\n triggerEnvironmentSwitch,\n} from \"#/components/features/backends/environment-switch-store\";\nimport { NavigationLink } from \"#/components/shared/navigation-link\";\nimport { StyledTooltip } from \"#/components/shared/buttons/styled-tooltip\";\nimport { useConversationStore } from \"#/stores/conversation-store\";\nimport { AddBackendModal } from \"./add-backend-modal\";\nimport { BackendStatusDot } from \"./backend-status-dot\";\nimport { ManageBackendsModal } from \"./manage-backends-modal\";\nimport { cn } from \"#/utils/utils\";\nimport { formControlTransitionClassName } from \"#/utils/form-control-classes\";\n\nconst VALUE_SEPARATOR = \"::\";\n\nfunction makeOptionValue(backendId: string, orgId: string | null): string {\n return orgId ? `${backendId}${VALUE_SEPARATOR}${orgId}` : backendId;\n}\n\nfunction parseOptionValue(value: string): {\n backendId: string;\n orgId: string | null;\n} {\n const [backendId, orgId] = value.split(VALUE_SEPARATOR);\n return { backendId, orgId: orgId ?? null };\n}\n\nfunction buildStatusPrefix(health: BackendHealth | undefined) {\n return <BackendStatusDot isConnected={health?.isConnected ?? null} />;\n}\n\nfunction buildOptions(\n registered: Backend[],\n personalWorkspaceLabel: string,\n cloudOrgs: ReturnType<typeof useAllCloudOrganizations>,\n currentUserIds: ReturnType<typeof useCloudCurrentUserId>,\n healthByBackendId: Record<string, BackendHealth>,\n): DropdownOption[] {\n const options: DropdownOption[] = [];\n\n const locals = registered.filter((b) => b.kind === \"local\");\n const clouds = registered.filter((b) => b.kind === \"cloud\");\n\n for (const b of locals) {\n options.push({\n value: makeOptionValue(b.id, null),\n label: b.name,\n prefix: buildStatusPrefix(healthByBackendId[b.id]),\n });\n }\n\n for (const b of clouds) {\n const entry = cloudOrgs[b.id];\n const prefix = buildStatusPrefix(healthByBackendId[b.id]);\n if (!entry || entry.orgs.length === 0) {\n options.push({\n value: makeOptionValue(b.id, null),\n label: b.name,\n prefix,\n });\n } else {\n // Personal-workspace rule (per the cloud contract): the org whose\n // id matches the calling user's id is the user's personal\n // workspace. We resolve `user_id` once per backend (via /me on any\n // one org) and apply it across all orgs of that backend.\n const userIdForBackend = currentUserIds[b.id]?.userId ?? null;\n\n for (const org of entry.orgs) {\n const isPersonal = !!userIdForBackend && userIdForBackend === org.id;\n const orgLabel = isPersonal ? personalWorkspaceLabel : org.name;\n options.push({\n value: makeOptionValue(b.id, org.id),\n label: `${b.name} – ${orgLabel}`,\n // All org rows for the same cloud backend share that backend's\n // single connectivity verdict — there is no per-org probe.\n prefix,\n });\n }\n }\n }\n\n return options;\n}\n\ninterface BackendSelectorProps {\n /** Render the menu above the trigger (e.g. when pinned to bottom of sidebar). */\n openUpward?: boolean;\n /** Hide the selector input trigger and only render the dropdown menu. */\n hideTrigger?: boolean;\n /** Whether the dropdown menu should start open on mount. */\n defaultOpen?: boolean;\n /** Callback fired after selecting a backend/org option. */\n onSelectOption?: () => void;\n /**\n * Override the internal Add Backend modal handling. When provided,\n * clicking \"Add Backend\" calls this instead of opening BackendSelector's\n * own modal. Useful when the selector is mounted inside an ephemeral\n * container (e.g. the collapsed-sidebar popover) and the modal must\n * survive the parent unmounting.\n */\n onOpenAddBackend?: () => void;\n /** Same as onOpenAddBackend but for the Manage Backends modal. */\n onOpenManageBackends?: () => void;\n /**\n * Whether the surrounding sidebar rail is in its collapsed variant. Passed\n * down from `SidebarRailBody` so the mobile drawer (which always renders\n * the expanded rail) can override the persisted desktop value.\n */\n sidebarCollapsed?: boolean;\n}\n\nexport function BackendSelector({\n openUpward = false,\n hideTrigger = false,\n defaultOpen = false,\n onSelectOption,\n onOpenAddBackend,\n onOpenManageBackends,\n sidebarCollapsed = false,\n}: BackendSelectorProps = {}) {\n const { t } = useTranslation(\"openhands\");\n const { backends, active, setActive } = useActiveBackendContext();\n const cloudOrgs = useAllCloudOrganizations();\n const currentUserIds = useCloudCurrentUserId();\n // Probe each registered backend every 10s.\n const healthByBackendId = useBackendsHealth(backends);\n const navigate = useNavigate();\n const settingsMatch = useMatch(\"/settings\");\n const settingsSubrouteMatch = useMatch(\"/settings/*\");\n const conversationMatch = useMatch(\"/conversations/:conversationId\");\n const automationDetailMatch = useMatch(\"/automations/:automationId\");\n const [addBackendModalOpen, setAddBackendModalOpen] = React.useState(false);\n const [manageBackendsModalOpen, setManageBackendsModalOpen] =\n React.useState(false);\n\n const personalWorkspaceLabel = t(I18nKey.BACKEND$PERSONAL_WORKSPACE);\n\n const options = React.useMemo(\n () =>\n buildOptions(\n backends,\n personalWorkspaceLabel,\n cloudOrgs,\n currentUserIds,\n healthByBackendId,\n ),\n [\n backends,\n personalWorkspaceLabel,\n cloudOrgs,\n currentUserIds,\n healthByBackendId,\n ],\n );\n\n const activeValue = makeOptionValue(active.backend.id, active.orgId);\n const activeOption = options.find((o) => o.value === activeValue);\n const isSettingsActive = Boolean(settingsMatch || settingsSubrouteMatch);\n const settingsLabel = t(I18nKey.SIDEBAR$SETTINGS);\n const isRightPanelShown = useConversationStore(\n (state) => state.isRightPanelShown,\n );\n // When the sidebar rail is expanded, `placement=\"left\"` hugs the main\n // canvas and reads awkwardly; prefer above the control. When the rail is\n // collapsed, keep left except on active conversation + open right drawer.\n const settingsTooltipPlacement =\n !sidebarCollapsed || (conversationMatch && isRightPanelShown)\n ? \"top\"\n : \"left\";\n\n const someCloudLoading = Object.values(cloudOrgs).some((c) => c.isLoading);\n\n // Self-heal a malformed `(cloudBackendId, null)` selection.\n //\n // Once a cloud backend's orgs resolve, the dropdown only renders\n // per-org rows for it — the `(backendId, null)` row disappears, so\n // selecting that shape would drift from what the dropdown can render\n // (UI says \"Local\", APIs hit cloud). When we detect the drift, snap\n // the selection onto the personal-workspace org (or, lacking a /me\n // result, the first org). The selection is recorded locally only;\n // the cloud request scope follows from the API key's bound org and the\n // X-Org-Id header sent by `callCloudProxy`, so the cloud UI's\n // org choice is never mutated as a side effect.\n React.useEffect(() => {\n if (active.backend.kind !== \"cloud\" || active.orgId) return;\n const { backend } = active;\n const entry = cloudOrgs[backend.id];\n if (!entry || entry.orgs.length === 0) return;\n\n const userId = currentUserIds[backend.id]?.userId ?? null;\n const personal = userId\n ? entry.orgs.find((o) => o.id === userId)\n : undefined;\n const target = personal ?? entry.orgs[0];\n if (target) {\n setActive(backend.id, target.id);\n }\n }, [active, cloudOrgs, currentUserIds, setActive]);\n\n const openAddBackendModal = React.useCallback(() => {\n if (onOpenAddBackend) {\n onOpenAddBackend();\n onSelectOption?.();\n return;\n }\n setAddBackendModalOpen(true);\n }, [onOpenAddBackend, onSelectOption]);\n\n const openManageBackendsModal = React.useCallback(() => {\n if (onOpenManageBackends) {\n onOpenManageBackends();\n onSelectOption?.();\n return;\n }\n setManageBackendsModalOpen(true);\n }, [onOpenManageBackends, onSelectOption]);\n\n const preventDropdownMenuClose = React.useCallback(\n (event: React.MouseEvent<HTMLButtonElement>) => {\n event.preventDefault();\n event.stopPropagation();\n },\n [],\n );\n\n const addBackendFooter = (\n <div className=\"flex flex-col\">\n <button\n type=\"button\"\n data-testid=\"add-backend-menu-item\"\n onMouseDown={preventDropdownMenuClose}\n onClick={openAddBackendModal}\n className=\"flex w-full items-center gap-2 px-2 py-2 rounded-md text-sm cursor-pointer text-white hover:bg-[var(--oh-interactive-hover)]\"\n >\n <Plus width={16} height={16} className=\"text-white shrink-0\" />\n {t(I18nKey.BACKEND$ADD)}\n </button>\n <button\n type=\"button\"\n data-testid=\"manage-backends-menu-item\"\n onMouseDown={preventDropdownMenuClose}\n onClick={openManageBackendsModal}\n className=\"flex w-full items-center gap-2 px-2 py-2 rounded-md text-sm cursor-pointer text-white hover:bg-[var(--oh-interactive-hover)]\"\n >\n <Settings width={16} height={16} className=\"text-white shrink-0\" />\n {t(I18nKey.BACKEND$MANAGE)}\n </button>\n </div>\n );\n\n const handleSelectBackend = React.useCallback(\n async (value: string) => {\n if (value === activeValue) return;\n\n const { backendId, orgId } = parseOptionValue(value);\n const target = backends.find((b) => b.id === backendId);\n if (!target) return;\n\n triggerEnvironmentSwitch(\n options.find((option) => option.value === value)?.label ?? target.name,\n );\n await new Promise<void>((resolve) => {\n setTimeout(resolve, ENVIRONMENT_SWITCH_SETACTIVE_DELAY_MS);\n });\n\n // @spec BM-002 — Switching backends keeps the user on the same page\n if (conversationMatch) navigate(\"/conversations\");\n else if (automationDetailMatch) navigate(\"/automations\");\n\n setActive(target.id, orgId);\n onSelectOption?.();\n },\n [\n activeValue,\n backends,\n conversationMatch,\n automationDetailMatch,\n navigate,\n options,\n setActive,\n t,\n onSelectOption,\n ],\n );\n\n return (\n <>\n <div className=\"flex items-center gap-2 w-full\">\n <div className=\"flex-1 min-w-0\">\n <Dropdown\n testId=\"backend-selector\"\n key={`${activeValue}-${activeOption?.label ?? \"\"}`}\n defaultValue={\n activeOption ?? {\n value: activeValue,\n label: active.backend.name,\n prefix: buildStatusPrefix(healthByBackendId[active.backend.id]),\n }\n }\n footer={addBackendFooter}\n openUpward={openUpward}\n hideTrigger={hideTrigger}\n defaultOpen={defaultOpen}\n openOnHover={!hideTrigger}\n onChange={(item) => {\n if (!item) return;\n void handleSelectBackend(item.value);\n }}\n placeholder={active.backend.name}\n loading={someCloudLoading}\n options={options}\n className=\"h-10 px-2 py-0 bg-transparent border-transparent hover:bg-[var(--oh-surface-raised)] focus-within:bg-[var(--oh-surface-raised)] focus-within:border-transparent focus-within:ring-0\"\n />\n </div>\n {!hideTrigger ? (\n <StyledTooltip\n content={settingsLabel}\n placement={settingsTooltipPlacement}\n offset={10}\n >\n <NavigationLink\n to=\"/settings\"\n data-testid=\"backend-selector-settings-link\"\n data-active={isSettingsActive}\n aria-label={settingsLabel}\n className={\n isSettingsActive\n ? cn(\n \"inline-flex items-center justify-center shrink-0 w-9 h-9 rounded-md bg-tertiary text-white font-normal cursor-pointer\",\n formControlTransitionClassName,\n )\n : cn(\n \"inline-flex items-center justify-center shrink-0 w-9 h-9 rounded-md text-[var(--oh-muted)] hover:text-white hover:bg-[var(--oh-surface-raised)] cursor-pointer\",\n formControlTransitionClassName,\n )\n }\n >\n <Settings width={16} height={16} />\n </NavigationLink>\n </StyledTooltip>\n ) : null}\n </div>\n {addBackendModalOpen ? (\n <AddBackendModal onClose={() => setAddBackendModalOpen(false)} />\n ) : null}\n {manageBackendsModalOpen ? (\n <ManageBackendsModal\n onClose={() => setManageBackendsModalOpen(false)}\n />\n ) : null}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAM,IAAkB;AAExB,SAAS,EAAgB,GAAmB,GAA8B;AACxE,QAAO,IAAQ,GAAG,IAAY,IAAkB,MAAU;;AAG5D,SAAS,GAAiB,GAGxB;CACA,IAAM,CAAC,GAAW,KAAS,EAAM,MAAM,EAAgB;AACvD,QAAO;EAAE;EAAW,OAAO,KAAS;EAAM;;AAG5C,SAAS,EAAkB,GAAmC;AAC5D,QAAO,kBAAC,GAAD,EAAkB,aAAa,GAAQ,eAAe,MAAQ,CAAA;;AAGvE,SAAS,EACP,GACA,GACA,GACA,GACA,GACkB;CAClB,IAAM,IAA4B,EAAE,EAE9B,IAAS,EAAW,QAAQ,MAAM,EAAE,S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KAqB9C;IACE,CAAA,EACJ,IA0BE,OAzBF,kBAAC,IAAD;IACE,SAAS;IACT,WAAW;IACX,QAAQ;cAER,kBAAC,IAAD;KACE,IAAG;KACH,eAAY;KACZ,eAAa;KACb,cAAY;KACZ,WAEM,EADJ,IAEM,0HAIA,kKAHA,EAKD;eAGP,kBAAC,GAAD;MAAU,OAAO;MAAI,QAAQ;MAAM,CAAA;KACpB,CAAA;IACH,CAAA,CAEd;;EACL,IACC,kBAAC,GAAD,EAAiB,eAAe,EAAuB,GAAM,EAAI,CAAA,GAC/D;EACH,IACC,kBAAC,GAAD,EACE,eAAe,EAA2B,GAAM,EAChD,CAAA,GACA;EACH,EAAA,CAAA"}
@@ -1,2 +1,2 @@
1
- const e=require(`../../../../_virtual/_rolldown/runtime.cjs`),t=require(`../../../../node_modules/react-i18next/dist/es/useTranslation.cjs`),n=require(`../../../../i18n/declaration.cjs`),r=require(`../../../../types/agent-state.cjs`),i=require(`../../../../utils/utils.cjs`),a=require(`../../../../hooks/use-conversation-id.cjs`),o=require(`../../../../stores/conversation-store.cjs`),s=require(`../../../../contexts/active-backend-context.cjs`),c=require(`../../../../node_modules/lucide-react/dist/esm/icons/cpu.cjs`),ee=require(`../../../../constants/acp-providers.cjs`),te=require(`../../../../hooks/query/use-active-conversation.cjs`),ne=require(`../../../../hooks/use-agent-state.cjs`);require(`../../../../utils/form-control-classes.cjs`);const re=require(`../../../../hooks/use-unified-websocket-status.cjs`),l=require(`../../controls/agent-status.cjs`),ie=require(`../../../../icons/lesson-plan.cjs`),u=require(`../../../../icons/code-pill.cjs`),d=require(`../../../../ui/context-menu.cjs`),f=require(`../../context-menu/context-menu-list-item.cjs`),ae=require(`../../../../hooks/use-click-outside-element.cjs`),oe=require(`../../../../hooks/use-handle-plan-click.cjs`),se=require(`../change-agent-button.cjs`),ce=require(`../../../../hooks/use-acp-model-context.cjs`),le=require(`../../../../icons/settings-gear.cjs`),p=require(`../../../shared/navigation-link.cjs`),ue=require(`../../../../ui/divider.cjs`),de=require(`./chat-input-model.cjs`),fe=require(`../switch-profile-button.cjs`),pe=require(`../../../../hooks/mutation/use-unified-stop-conversation.cjs`),m=require(`../../../../icons/carret-right-fill.cjs`),h=require(`../../controls/tools-context-menu-icon-text.cjs`),me=require(`../chat-add-file-button.cjs`),he=require(`../chat-send-button.cjs`),ge=require(`../../../../icons/three-dots-vertical.cjs`),_e=require(`../../../../hooks/mutation/use-pause-conversation.cjs`),g=require(`../../../../hooks/mutation/use-resume-conversation.cjs`);let _=require(`react`);_=e.__toESM(_,1);let v=require(`react/jsx-runtime`),y=require(`react-dom`);y=e.__toESM(y,1);function b({disabled:e,canSubmit:b=!0,onAddFileClick:ve=()=>{},showButton:ye=!0,buttonClassName:be=``,handleSubmit:xe=()=>{}}){let{t:x}=t.useTranslation(`openhands`),Se=pe.useUnifiedPauseConversation(),S=_e.usePauseConversation(),Ce=g.useResumeConversation(),{conversationId:C}=a.useOptionalConversationId(),{data:w}=te.useActiveConversation(),{backend:T}=s.useActiveBackend(),E=T.kind===`cloud`,{isAcpContext:D,destinationPath:O,destinationLabel:k}=ce.useAcpModelContext(),A=D?ee.labelForAcpModel(w?.acp_server,w?.llm_model)??w?.llm_model:w?.llm_model,we=re.useUnifiedWebSocketStatus(),{curAgentState:Te}=ne.useAgentState(),{conversationMode:Ee,setConversationMode:De}=o.useConversationStore(),{handlePlanClick:Oe,isCreatingConversation:ke}=oe.useHandlePlanClick(),j=_.default.useRef(null),M=_.default.useRef(null),N=_.default.useRef(null),P=_.default.useRef(null),F=_.default.useRef(null),I=_.default.useRef(null),[L,Ae]=_.default.useState(1/0),[je,Me]=_.default.useState(0),[Ne,Pe]=_.default.useState(32),[R,Fe]=_.default.useState(96),[z,Ie]=_.default.useState(120),[B,V]=_.default.useState(!1),[H,U]=_.default.useState(null),[W,Le]=_.default.useState();_.default.useEffect(()=>{let e=j.current,t=M.current,n=N.current,r=P.current,i=F.current;if(!e||!t||!n||!i||E&&!r||typeof ResizeObserver>`u`)return;let a=()=>{let a=e.getBoundingClientRect().width,o=t.getBoundingClientRect().width,s=n.getBoundingClientRect().width,c=i.getBoundingClientRect().width;if(a>0&&Ae(a),o>0&&Me(o),s>0&&Pe(s),c>0&&Ie(c),r){let e=r.getBoundingClientRect().width;e>0&&Fe(e)}},o=new ResizeObserver(()=>{a()});return o.observe(e),o.observe(t),o.observe(n),o.observe(i),r&&o.observe(r),a(),()=>o.disconnect()},[E]);let Re=()=>{C&&S.mutate({conversationId:C})},ze=()=>{C&&Ce.mutate({conversationId:C})},Be=Se.isPending||S.isPending,G=_.default.useCallback(e=>{let t=e,n={showCodeInline:!1,showModelInline:!1};return E&&t>=R&&(n.showCodeInline=!0,t-=R+12),t>=z&&(n.showModelInline=!0),n},[E,R,z]),K=L-je-8-Ne-12,q=G(K),J=(!E||q.showCodeInline)&&q.showModelInline?q:G(K-28-12),Y=E?J.showCodeInline:!1,X=J.showModelInline,Ve=L>=360,Z=E&&!Y||!X;_.default.useEffect(()=>{Z||(V(!1),U(null))},[Z]);let He=ae.useClickOutsideElement(()=>{V(!1),U(null)}),Q=Te===r.AgentState.RUNNING||ke||we!==`OPEN`,$=()=>{U(null),V(!1)};_.default.useLayoutEffect(()=>{if(!B||!I.current)return;let e=I.current,t=()=>{let t=e.getBoundingClientRect();Le({position:`fixed`,top:t.top-8,left:t.left,transform:`translateY(-100%)`,zIndex:9999})};return t(),window.addEventListener(`resize`,t),window.addEventListener(`scroll`,t,!0),()=>{window.removeEventListener(`resize`,t),window.removeEventListener(`scroll`,t,!0)}},[B]);let Ue=(0,v.jsxs)(d.ContextMenu,{ref:He,testId:`chat-input-overflow-menu`,position:`top`,alignment:`left`,className:`!static !top-auto !bottom-auto !left-auto !right-auto !mt-0 overflow-visible min-w-[200px]`,children:[E&&!Y&&(0,v.jsxs)(`div`,{className:`relative group/overflow-agent`,children:[(0,v.jsx)(f.ContextMenuListItem,{testId:`overflow-agent-button`,onClick:()=>U(e=>e===`agent`?null:`agent`),isDisabled:Q,children:(0,v.jsx)(h.ToolsContextMenuIconText,{icon:(0,v.jsx)(u.CodePillIcon,{className:`h-[11px] w-[11px]`}),text:x(Ee===`code`?n.I18nKey.COMMON$CODE:n.I18nKey.COMMON$PLAN),rightIcon:(0,v.jsx)(m.default,{width:10,height:10})})}),!Q&&(0,v.jsx)(`div`,{className:i.cn(`absolute left-full top-[-4px] z-60 opacity-0 invisible pointer-events-none transition-all duration-200 ml-[1px]`,`group-hover/overflow-agent:opacity-100 group-hover/overflow-agent:visible group-hover/overflow-agent:pointer-events-auto`,`hover:opacity-100 hover:visible hover:pointer-events-auto`,H===`agent`&&`opacity-100 visible pointer-events-auto`),children:(0,v.jsxs)(d.ContextMenu,{testId:`overflow-agent-submenu`,className:`overflow-visible min-w-[195px] gap-0`,children:[(0,v.jsx)(f.ContextMenuListItem,{testId:`overflow-agent-code`,onClick:e=>{e.preventDefault(),e.stopPropagation(),De(`code`),$()},children:(0,v.jsx)(h.ToolsContextMenuIconText,{icon:(0,v.jsx)(u.CodePillIcon,{className:`h-[11px] w-[11px]`}),text:x(n.I18nKey.COMMON$CODE)})}),(0,v.jsx)(f.ContextMenuListItem,{testId:`overflow-agent-plan`,onClick:e=>{Oe(e),$()},children:(0,v.jsx)(h.ToolsContextMenuIconText,{icon:(0,v.jsx)(ie.default,{width:16,height:16,color:`currentColor`}),text:x(n.I18nKey.COMMON$PLAN)})})]})})]}),!X&&(0,v.jsxs)(`div`,{className:`relative group/overflow-model`,children:[(0,v.jsx)(f.ContextMenuListItem,{testId:`overflow-model-button`,onClick:()=>U(e=>e===`model`?null:`model`),children:(0,v.jsx)(h.ToolsContextMenuIconText,{icon:(0,v.jsx)(c.Cpu,{width:16,height:16,strokeWidth:2,"aria-hidden":!0}),text:`Model`,rightIcon:(0,v.jsx)(m.default,{width:10,height:10})})}),(0,v.jsx)(`div`,{className:i.cn(`absolute left-full top-[-4px] z-60 opacity-0 invisible pointer-events-none transition-all duration-200 ml-[1px]`,`group-hover/overflow-model:opacity-100 group-hover/overflow-model:visible group-hover/overflow-model:pointer-events-auto`,`hover:opacity-100 hover:visible hover:pointer-events-auto`,H===`model`&&`opacity-100 visible pointer-events-auto`),children:(0,v.jsxs)(d.ContextMenu,{testId:`overflow-model-submenu`,className:`overflow-visible min-w-[220px] max-w-[320px] gap-0`,children:[(0,v.jsx)(`li`,{className:`text-sm`,children:(0,v.jsx)(`div`,{className:`p-2 leading-5 text-[var(--oh-foreground)] break-all`,children:A})}),(0,v.jsx)(ue.Divider,{inset:`menu`}),(0,v.jsx)(`li`,{className:`text-sm`,children:(0,v.jsxs)(p.NavigationLink,{to:O,onClick:$,className:i.cn(`group flex h-[30px] items-center gap-2 rounded p-2 leading-5 text-[var(--oh-foreground)] hover:bg-[var(--oh-interactive-hover)]`,`transition-[background-color,border-color,box-shadow,opacity] duration-150 motion-reduce:transition-none`),children:[(0,v.jsx)(le.default,{width:16,height:16,className:i.cn(`shrink-0 text-[var(--oh-muted)] group-hover:text-[var(--oh-foreground)]`,`transition-[background-color,border-color,box-shadow,opacity] duration-150 motion-reduce:transition-none`),"aria-hidden":!0}),(0,v.jsx)(`span`,{children:k})]})})]})})]})]});return(0,v.jsxs)(`div`,{ref:j,className:`w-full min-w-0 flex items-center justify-between gap-2`,children:[(0,v.jsx)(`div`,{className:`flex min-w-0 items-center gap-1`,children:(0,v.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,v.jsx)(`div`,{ref:N,className:i.cn(!1),children:(0,v.jsx)(me.ChatAddFileButton,{disabled:e,handleFileIconClick:ve})}),E&&(0,v.jsx)(`div`,{ref:P,className:i.cn(!Y&&`hidden`),children:(0,v.jsx)(se.ChangeAgentButton,{})}),(0,v.jsx)(`div`,{ref:F,className:i.cn(!X&&`hidden`),children:E||D?(0,v.jsx)(de.ChatInputModel,{}):(0,v.jsx)(fe.SwitchProfileButton,{})}),Z&&(0,v.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,v.jsx)(`button`,{ref:I,type:`button`,className:i.cn(`flex size-6 items-center justify-center rounded-full text-[var(--oh-muted)]`,`transition-[background-color,border-color,box-shadow,opacity] duration-150 motion-reduce:transition-none`,`hover:bg-white/10 hover:text-white cursor-pointer`),"aria-label":`More input actions`,"aria-expanded":B,"aria-haspopup":`menu`,onClick:e=>{e.preventDefault(),e.stopPropagation(),V(e=>!e)},children:(0,v.jsx)(ge.default,{width:16,height:16,color:`currentColor`})}),B&&typeof document<`u`&&W&&y.default.createPortal((0,v.jsx)(`div`,{style:W,children:Ue}),document.body)]})]})}),(0,v.jsxs)(`div`,{ref:M,className:`ml-auto flex shrink-0 items-center gap-2`,children:[Ve&&C&&(0,v.jsx)(l.default,{handleStop:Re,handleResumeAgent:ze,disabled:e,isPausing:Be}),ye&&(0,v.jsx)(he.ChatSendButton,{buttonClassName:be,handleSubmit:xe,disabled:e||!b})]})]})}exports.ChatInputActions=b;
1
+ const e=require(`../../../../_virtual/_rolldown/runtime.cjs`),t=require(`../../../../node_modules/react-i18next/dist/es/useTranslation.cjs`),n=require(`../../../../i18n/declaration.cjs`),r=require(`../../../../types/agent-state.cjs`),i=require(`../../../../utils/utils.cjs`),a=require(`../../../../hooks/use-conversation-id.cjs`),o=require(`../../../../stores/conversation-store.cjs`),s=require(`../../../../contexts/active-backend-context.cjs`),c=require(`../../../../node_modules/lucide-react/dist/esm/icons/cpu.cjs`),ee=require(`../../../../constants/acp-providers.cjs`),te=require(`../../../../hooks/query/use-active-conversation.cjs`),ne=require(`../../../../hooks/use-agent-state.cjs`);require(`../../../../utils/form-control-classes.cjs`);const re=require(`../../../../hooks/use-unified-websocket-status.cjs`),ie=require(`../../controls/agent-status.cjs`),ae=require(`../../../../icons/lesson-plan.cjs`),l=require(`../../../../icons/code-pill.cjs`),u=require(`../../../../ui/context-menu.cjs`),d=require(`../../context-menu/context-menu-list-item.cjs`),oe=require(`../../../../hooks/use-click-outside-element.cjs`),se=require(`../../../../hooks/use-handle-plan-click.cjs`),ce=require(`../change-agent-button.cjs`),le=require(`../../../../hooks/use-acp-model-context.cjs`),ue=require(`../../../../icons/settings-gear.cjs`),de=require(`../../../shared/navigation-link.cjs`),fe=require(`../../../../ui/divider.cjs`),pe=require(`./chat-input-model.cjs`),f=require(`../switch-profile-button.cjs`),p=require(`../../../../hooks/mutation/use-unified-stop-conversation.cjs`),m=require(`../../../../icons/carret-right-fill.cjs`),h=require(`../../controls/tools-context-menu-icon-text.cjs`),me=require(`../chat-add-file-button.cjs`),he=require(`../chat-send-button.cjs`),ge=require(`../../../../icons/three-dots-vertical.cjs`),_e=require(`../../../../hooks/mutation/use-pause-conversation.cjs`),ve=require(`../../../../hooks/mutation/use-resume-conversation.cjs`);let g=require(`react`);g=e.__toESM(g,1);let _=require(`react/jsx-runtime`),v=require(`react-dom`);v=e.__toESM(v,1);function y({disabled:e,canSubmit:y=!0,onAddFileClick:ye=()=>{},showButton:be=!0,buttonClassName:xe=``,handleSubmit:Se=()=>{}}){let{t:b}=t.useTranslation(`openhands`),Ce=p.useUnifiedPauseConversation(),x=_e.usePauseConversation(),we=ve.useResumeConversation(),{conversationId:S}=a.useOptionalConversationId(),{data:C}=te.useActiveConversation(),{backend:Te}=s.useActiveBackend(),w=Te.kind===`cloud`,{isAcpContext:T,destinationPath:E,destinationLabel:D}=le.useAcpModelContext(),O=T?ee.labelForAcpModel(C?.acp_server,C?.llm_model)??C?.llm_model:C?.llm_model,k=w&&!!S,Ee=re.useUnifiedWebSocketStatus(),{curAgentState:A}=ne.useAgentState(),{conversationMode:De,setConversationMode:Oe}=o.useConversationStore(),{handlePlanClick:ke,isCreatingConversation:Ae}=se.useHandlePlanClick(),j=g.default.useRef(null),M=g.default.useRef(null),N=g.default.useRef(null),P=g.default.useRef(null),F=g.default.useRef(null),I=g.default.useRef(null),[L,je]=g.default.useState(1/0),[Me,Ne]=g.default.useState(0),[Pe,Fe]=g.default.useState(32),[R,Ie]=g.default.useState(96),[z,Le]=g.default.useState(120),[B,V]=g.default.useState(!1),[H,U]=g.default.useState(null),[W,Re]=g.default.useState();g.default.useEffect(()=>{let e=j.current,t=M.current,n=N.current,r=P.current,i=F.current;if(!e||!t||!n||!i||k&&!r||typeof ResizeObserver>`u`)return;let a=()=>{let a=e.getBoundingClientRect().width,o=t.getBoundingClientRect().width,s=n.getBoundingClientRect().width,c=i.getBoundingClientRect().width;if(a>0&&je(a),o>0&&Ne(o),s>0&&Fe(s),c>0&&Le(c),r){let e=r.getBoundingClientRect().width;e>0&&Ie(e)}},o=new ResizeObserver(()=>{a()});return o.observe(e),o.observe(t),o.observe(n),o.observe(i),r&&o.observe(r),a(),()=>o.disconnect()},[k]);let ze=()=>{S&&x.mutate({conversationId:S})},Be=()=>{S&&we.mutate({conversationId:S})},Ve=Ce.isPending||x.isPending,G=g.default.useCallback(e=>{let t=e,n={showCodeInline:!1,showModelInline:!1};return k&&t>=R&&(n.showCodeInline=!0,t-=R+12),t>=z&&(n.showModelInline=!0),n},[k,R,z]),K=L-Me-8-Pe-12,q=G(K),J=(!k||q.showCodeInline)&&q.showModelInline?q:G(K-28-12),Y=k?J.showCodeInline:!1,X=J.showModelInline,He=L>=360,Z=k&&!Y||!X;g.default.useEffect(()=>{Z||(V(!1),U(null))},[Z]);let Ue=oe.useClickOutsideElement(()=>{V(!1),U(null)}),Q=A===r.AgentState.RUNNING||Ae||Ee!==`OPEN`,$=()=>{U(null),V(!1)};g.default.useLayoutEffect(()=>{if(!B||!I.current)return;let e=I.current,t=()=>{let t=e.getBoundingClientRect();Re({position:`fixed`,top:t.top-8,left:t.left,transform:`translateY(-100%)`,zIndex:9999})};return t(),window.addEventListener(`resize`,t),window.addEventListener(`scroll`,t,!0),()=>{window.removeEventListener(`resize`,t),window.removeEventListener(`scroll`,t,!0)}},[B]);let We=(0,_.jsxs)(u.ContextMenu,{ref:Ue,testId:`chat-input-overflow-menu`,position:`top`,alignment:`left`,className:`!static !top-auto !bottom-auto !left-auto !right-auto !mt-0 overflow-visible min-w-[200px]`,children:[k&&!Y&&(0,_.jsxs)(`div`,{className:`relative group/overflow-agent`,children:[(0,_.jsx)(d.ContextMenuListItem,{testId:`overflow-agent-button`,onClick:()=>U(e=>e===`agent`?null:`agent`),isDisabled:Q,children:(0,_.jsx)(h.ToolsContextMenuIconText,{icon:(0,_.jsx)(l.CodePillIcon,{className:`h-[11px] w-[11px]`}),text:b(De===`code`?n.I18nKey.COMMON$CODE:n.I18nKey.COMMON$PLAN),rightIcon:(0,_.jsx)(m.default,{width:10,height:10})})}),!Q&&(0,_.jsx)(`div`,{className:i.cn(`absolute left-full top-[-4px] z-60 opacity-0 invisible pointer-events-none transition-all duration-200 ml-[1px]`,`group-hover/overflow-agent:opacity-100 group-hover/overflow-agent:visible group-hover/overflow-agent:pointer-events-auto`,`hover:opacity-100 hover:visible hover:pointer-events-auto`,H===`agent`&&`opacity-100 visible pointer-events-auto`),children:(0,_.jsxs)(u.ContextMenu,{testId:`overflow-agent-submenu`,className:`overflow-visible min-w-[195px] gap-0`,children:[(0,_.jsx)(d.ContextMenuListItem,{testId:`overflow-agent-code`,onClick:e=>{e.preventDefault(),e.stopPropagation(),Oe(`code`),$()},children:(0,_.jsx)(h.ToolsContextMenuIconText,{icon:(0,_.jsx)(l.CodePillIcon,{className:`h-[11px] w-[11px]`}),text:b(n.I18nKey.COMMON$CODE)})}),(0,_.jsx)(d.ContextMenuListItem,{testId:`overflow-agent-plan`,onClick:e=>{ke(e),$()},children:(0,_.jsx)(h.ToolsContextMenuIconText,{icon:(0,_.jsx)(ae.default,{width:16,height:16,color:`currentColor`}),text:b(n.I18nKey.COMMON$PLAN)})})]})})]}),!X&&(0,_.jsxs)(`div`,{className:`relative group/overflow-model`,children:[(0,_.jsx)(d.ContextMenuListItem,{testId:`overflow-model-button`,onClick:()=>U(e=>e===`model`?null:`model`),children:(0,_.jsx)(h.ToolsContextMenuIconText,{icon:(0,_.jsx)(c.Cpu,{width:16,height:16,strokeWidth:2,"aria-hidden":!0}),text:`Model`,rightIcon:(0,_.jsx)(m.default,{width:10,height:10})})}),(0,_.jsx)(`div`,{className:i.cn(`absolute left-full top-[-4px] z-60 opacity-0 invisible pointer-events-none transition-all duration-200 ml-[1px]`,`group-hover/overflow-model:opacity-100 group-hover/overflow-model:visible group-hover/overflow-model:pointer-events-auto`,`hover:opacity-100 hover:visible hover:pointer-events-auto`,H===`model`&&`opacity-100 visible pointer-events-auto`),children:(0,_.jsxs)(u.ContextMenu,{testId:`overflow-model-submenu`,className:`overflow-visible min-w-[220px] max-w-[320px] gap-0`,children:[(0,_.jsx)(`li`,{className:`text-sm`,children:(0,_.jsx)(`div`,{className:`p-2 leading-5 text-[var(--oh-foreground)] break-all`,children:O})}),(0,_.jsx)(fe.Divider,{inset:`menu`}),(0,_.jsx)(`li`,{className:`text-sm`,children:(0,_.jsxs)(de.NavigationLink,{to:E,onClick:$,className:i.cn(`group flex h-[30px] items-center gap-2 rounded p-2 leading-5 text-[var(--oh-foreground)] hover:bg-[var(--oh-interactive-hover)]`,`transition-[background-color,border-color,box-shadow,opacity] duration-150 motion-reduce:transition-none`),children:[(0,_.jsx)(ue.default,{width:16,height:16,className:i.cn(`shrink-0 text-[var(--oh-muted)] group-hover:text-[var(--oh-foreground)]`,`transition-[background-color,border-color,box-shadow,opacity] duration-150 motion-reduce:transition-none`),"aria-hidden":!0}),(0,_.jsx)(`span`,{children:D})]})})]})})]})]});return(0,_.jsxs)(`div`,{ref:j,className:`w-full min-w-0 flex items-center justify-between gap-2`,children:[(0,_.jsx)(`div`,{className:`flex min-w-0 items-center gap-1`,children:(0,_.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,_.jsx)(`div`,{ref:N,className:i.cn(!1),children:(0,_.jsx)(me.ChatAddFileButton,{disabled:e,handleFileIconClick:ye})}),k&&(0,_.jsx)(`div`,{ref:P,className:i.cn(!Y&&`hidden`),children:(0,_.jsx)(ce.ChangeAgentButton,{})}),(0,_.jsx)(`div`,{ref:F,className:i.cn(!X&&`hidden`),children:w||T?(0,_.jsx)(pe.ChatInputModel,{}):(0,_.jsx)(f.SwitchProfileButton,{})}),Z&&(0,_.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,_.jsx)(`button`,{ref:I,type:`button`,className:i.cn(`flex size-6 items-center justify-center rounded-full text-[var(--oh-muted)]`,`transition-[background-color,border-color,box-shadow,opacity] duration-150 motion-reduce:transition-none`,`hover:bg-white/10 hover:text-white cursor-pointer`),"aria-label":`More input actions`,"aria-expanded":B,"aria-haspopup":`menu`,onClick:e=>{e.preventDefault(),e.stopPropagation(),V(e=>!e)},children:(0,_.jsx)(ge.default,{width:16,height:16,color:`currentColor`})}),B&&typeof document<`u`&&W&&v.default.createPortal((0,_.jsx)(`div`,{style:W,children:We}),document.body)]})]})}),(0,_.jsxs)(`div`,{ref:M,className:`ml-auto flex shrink-0 items-center gap-2`,children:[He&&S&&(0,_.jsx)(ie.default,{handleStop:ze,handleResumeAgent:Be,disabled:e,isPausing:Ve}),be&&(0,_.jsx)(he.ChatSendButton,{buttonClassName:xe,handleSubmit:Se,disabled:e||!y})]})]})}exports.ChatInputActions=y;
2
2
  //# sourceMappingURL=chat-input-actions.cjs.map