🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat(sandbox): merge working directory and environment into one work location picker (#22612)
Arvin Xub8a1bab680c1
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.jsonindex 9b4e54086b4..fed87b9944e 100644--- a/locales/en-US/chat.json+++ b/locales/en-US/chat.json@@ -2108,12 +2108,9 @@"runtimeEnv.mode.noneDesc": "Disable runtime environment","runtimeEnv.selectMode": "Select Runtime Environment","runtimeEnv.title": "Runtime Environment",- "sandboxDrive.browse": "Choose a folder on your drive…",- "sandboxDrive.browseDesc": "Files in it are kept across conversations","sandboxDrive.browseOther": "Choose another folder…","sandboxDrive.building": "{{name}} · building","sandboxDrive.environmentBuildingDesc": "Environment directory · building, usable once it finishes",- "sandboxDrive.environmentDesc": "Environment directory · installed packages are kept too","sandboxDrive.fallback.directoryMissing": "This folder no longer exists on the drive. Runs use a temporary sandbox until you pick another folder.","sandboxDrive.fallback.instanceRebuildRequired": "This private environment directory is still on the public drive and needs to be rebuilt on your personal drive. This run will use a temporary sandbox.","sandboxDrive.fallback.instanceUnavailable": "This environment directory can’t be used here any more. Runs use a temporary sandbox until you pick another one.",@@ -2122,23 +2119,20 @@"sandboxDrive.fallbackChip.instanceRebuildRequired": "Rebuild on personal drive","sandboxDrive.fallbackChip.instanceUnavailable": "Environment unavailable","sandboxDrive.fallbackChip.rootNotAllowed": "Pick a folder",- "sandboxDrive.folderDesc": "Folder on your drive · {{path}}",- "sandboxDrive.folderOnDriveDesc": "{{drive}} · {{path}}",- "sandboxDrive.manageEnvironments": "Environments",- "sandboxDrive.pickerInfoTooltip": "Pick a folder on your drive and its files are kept across conversations. Without one, the sandbox is temporary.",- "sandboxDrive.pickerTitle": "Working directory",- "sandboxDrive.root": "Drive root",- "sandboxDrive.upsell": "Keep files on a drive",- "sandboxEnvironment.empty": "No environments yet. Create one in Environments.",- "sandboxEnvironment.hint": "Cloned and set up once in the working directory before the first command. A folder that already has files is left as it is.",+ "sandboxDrive.manageEnvironments": "Settings",+ "sandboxDrive.pickerInfoTooltip": "A temporary directory is cleaned up with the sandbox. A folder on your cloud drive is kept across conversations. A repository is cloned before the first command.",+ "sandboxDrive.pickerTitle": "Work location",+ "sandboxDrive.root": "Root",+ "sandboxDrive.title": "Cloud drive",+ "sandboxEnvironment.add": "Add repository",+ "sandboxEnvironment.empty": "No repositories yet. Add one to get started.",+ "sandboxEnvironment.hint": "Cloned and set up once before the first command.","sandboxEnvironment.loadFailed": "Couldn't load environments","sandboxEnvironment.loading": "Loading environment…","sandboxEnvironment.missing": "Environment unavailable",- "sandboxEnvironment.none": "No environment",- "sandboxEnvironment.noneDesc": "Start from an empty working directory","sandboxEnvironment.retry": "Retry","sandboxEnvironment.saveFailed": "Could not change the environment. Try again.",- "sandboxEnvironment.title": "Environment",+ "sandboxEnvironment.title": "Repository","sandboxStorage.allCopiesBusy": "Every copy is in use","sandboxStorage.buildFailed": "Not built","sandboxStorage.building": "Building",@@ -2149,7 +2143,6 @@"sandboxStorage.defaultCopy": "Default","sandboxStorage.environmentsUnavailable": "Environments could not be loaded","sandboxStorage.ephemeral": "Temporary working directory",- "sandboxStorage.ephemeralDesc": "Cleaned up when the sandbox is recycled","sandboxStorage.instanceBusy": "{{name}} is running in another conversation. This one keeps it, and picks it up when that run ends.","sandboxStorage.kind.code": "Code","sandboxStorage.kind.files": "Files",@@ -2157,7 +2150,6 @@"sandboxStorage.noCopyColleagueDesc": "Its creator has not set it up yet","sandboxStorage.noCopyYetDesc": "A copy is created the first time you pick it","sandboxStorage.persistentUpsell": "Persistent working directory",- "sandboxStorage.persistentUpsellDesc": "Keep files across runs and topics","sandboxStorage.pickerInfoTooltip": "An environment describes what a run needs around it — files, or repositories, setup and variables. Conversations run inside one of its copies and keep what they leave there; a second copy only appears when two conversations need the same environment at once.","sandboxStorage.pickerTitle": "Environment","sandboxStorage.privateGroup": "Private Environments",diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.jsonindex c486c3775b4..cbf0285bfdb 100644--- a/locales/zh-CN/chat.json+++ b/locales/zh-CN/chat.json@@ -2108,12 +2108,9 @@"runtimeEnv.mode.noneDesc": "禁用运行时环境","runtimeEnv.selectMode": "选择运行环境","runtimeEnv.title": "运行环境",- "sandboxDrive.browse": "选择网盘文件夹…",- "sandboxDrive.browseDesc": "其中的文件会跨会话保留","sandboxDrive.browseOther": "选择其他文件夹…","sandboxDrive.building": "{{name}} · 构建中","sandboxDrive.environmentBuildingDesc": "环境目录 · 正在构建,完成后即可使用",- "sandboxDrive.environmentDesc": "环境目录 · 已安装的依赖也会保留","sandboxDrive.fallback.directoryMissing": "该文件夹已不存在,运行将使用临时沙箱,请重新选择文件夹。","sandboxDrive.fallback.instanceRebuildRequired": "这个私有环境目录还在公共网盘中,需要在个人网盘重建后才能使用,本次运行将使用临时沙箱。","sandboxDrive.fallback.instanceUnavailable": "该环境目录已不可用,运行将使用临时沙箱,请重新选择。",@@ -2122,23 +2119,20 @@"sandboxDrive.fallbackChip.instanceRebuildRequired": "需在个人网盘重建","sandboxDrive.fallbackChip.instanceUnavailable": "环境目录不可用","sandboxDrive.fallbackChip.rootNotAllowed": "请选择文件夹",- "sandboxDrive.folderDesc": "网盘文件夹 · {{path}}",- "sandboxDrive.folderOnDriveDesc": "{{drive}} · {{path}}",- "sandboxDrive.manageEnvironments": "代码环境",- "sandboxDrive.pickerInfoTooltip": "选择网盘中的文件夹,其中的文件会跨会话保留;不选则使用临时沙箱。",- "sandboxDrive.pickerTitle": "工作目录",- "sandboxDrive.root": "网盘根目录",- "sandboxDrive.upsell": "保存到网盘",- "sandboxEnvironment.empty": "还没有代码环境,可在「代码环境」中创建。",- "sandboxEnvironment.hint": "在第一条命令前,于工作目录中克隆仓库并执行一次初始化。已有文件的文件夹不会被改动。",+ "sandboxDrive.manageEnvironments": "设置",+ "sandboxDrive.pickerInfoTooltip": "临时工作目录随沙箱清理;云盘文件夹跨会话保留;代码仓库在第一条命令前克隆好。",+ "sandboxDrive.pickerTitle": "工作位置",+ "sandboxDrive.root": "根目录",+ "sandboxDrive.title": "云盘",+ "sandboxEnvironment.add": "添加代码仓库",+ "sandboxEnvironment.empty": "还没有代码仓库,先添加一个。",+ "sandboxEnvironment.hint": "在第一条命令前克隆仓库,并执行一次初始化。","sandboxEnvironment.loadFailed": "无法加载环境列表","sandboxEnvironment.loading": "正在加载环境…","sandboxEnvironment.missing": "环境不可用",- "sandboxEnvironment.none": "不使用环境",- "sandboxEnvironment.noneDesc": "从空的工作目录开始","sandboxEnvironment.retry": "重试","sandboxEnvironment.saveFailed": "无法更改环境,请重试。",- "sandboxEnvironment.title": "代码环境",+ "sandboxEnvironment.title": "代码仓库","sandboxStorage.allCopiesBusy": "所有副本都在使用中","sandboxStorage.buildFailed": "未构建","sandboxStorage.building": "构建中",@@ -2149,7 +2143,6 @@"sandboxStorage.defaultCopy": "默认","sandboxStorage.environmentsUnavailable": "环境列表没能读取","sandboxStorage.ephemeral": "临时工作目录",- "sandboxStorage.ephemeralDesc": "沙箱回收时会被清理","sandboxStorage.instanceBusy": "{{name}} 正在另一个对话里运行。这个对话仍然绑着它,等那边结束后接着用。","sandboxStorage.kind.code": "代码","sandboxStorage.kind.files": "文件",@@ -2157,7 +2150,6 @@"sandboxStorage.noCopyColleagueDesc": "创建者还没有为它准备副本,暂不可用","sandboxStorage.noCopyYetDesc": "第一次选中时会自动创建副本","sandboxStorage.persistentUpsell": "持久化工作目录",- "sandboxStorage.persistentUpsellDesc": "跨运行、跨话题保留文件","sandboxStorage.pickerInfoTooltip": "环境描述一次运行需要的周边——文件,或者仓库、初始化和变量。对话跑在它的某一份副本里,留下的东西也留在那里;只有两个对话要同时用同一个环境时,才会出现第二份副本。","sandboxStorage.pickerTitle": "环境","sandboxStorage.privateGroup": "私人环境",diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.tsindex d781a80e5d7..d4282254891 100644--- a/packages/locales/src/default/chat.ts+++ b/packages/locales/src/default/chat.ts@@ -1667,9 +1667,7 @@ export default {'gatewayMode.desc':"Run agents in the cloud through LobeHub's Agent Gateway. Tasks keep running even after you close the page.",'sandboxStorage.ephemeral': 'Temporary working directory',- 'sandboxStorage.ephemeralDesc': 'Cleaned up when the sandbox is recycled','sandboxStorage.persistentUpsell': 'Persistent working directory',- 'sandboxStorage.persistentUpsellDesc': 'Keep files across runs and topics','sandboxStorage.setUpEnvironmentDesc': 'A persistent directory lives in an environment','sandboxStorage.setUpEnvironment': 'Set up an environment','sandboxStorage.manage': 'Manage',@@ -4355,31 +4353,25 @@ export default {'userFeedbackCard.count_other': '{{count}} comments','userFeedbackCard.title': 'User feedback','you': 'You',- 'sandboxDrive.pickerTitle': 'Working directory',- 'sandboxDrive.pickerInfoTooltip':- 'Pick a folder on your drive and its files are kept across conversations. Without one, the sandbox is temporary.',- 'sandboxDrive.manageEnvironments': 'Environments',- 'sandboxEnvironment.title': 'Environment',- 'sandboxEnvironment.hint':- 'Cloned and set up once in the working directory before the first command. A folder that already has files is left as it is.',- 'sandboxEnvironment.none': 'No environment',- 'sandboxEnvironment.noneDesc': 'Start from an empty working directory',- 'sandboxEnvironment.empty': 'No environments yet. Create one in Environments.',+ 'sandboxDrive.manageEnvironments': 'Settings','sandboxEnvironment.missing': 'Environment unavailable','sandboxEnvironment.loading': 'Loading environment…',+ 'sandboxDrive.pickerTitle': 'Work location',+ 'sandboxDrive.pickerInfoTooltip':+ 'A temporary directory is cleaned up with the sandbox. A folder on your cloud drive is kept across conversations. A repository is cloned before the first command.',+ 'sandboxEnvironment.title': 'Repository',+ 'sandboxEnvironment.hint': 'Cloned and set up once before the first command.',+ 'sandboxEnvironment.empty': 'No repositories yet. Add one to get started.',+ 'sandboxEnvironment.add': 'Add repository','sandboxEnvironment.loadFailed': "Couldn't load environments",'sandboxEnvironment.retry': 'Retry','sandboxEnvironment.saveFailed': 'Could not change the environment. Try again.',- 'sandboxDrive.root': 'Drive root',+ 'sandboxDrive.root': 'Root','sandboxDrive.building': '{{name}} · building',- 'sandboxDrive.browse': 'Choose a folder on your drive…',+ 'sandboxDrive.title': 'Cloud drive','sandboxDrive.browseOther': 'Choose another folder…',- 'sandboxDrive.browseDesc': 'Files in it are kept across conversations',- 'sandboxDrive.folderDesc': 'Folder on your drive · {{path}}',- 'sandboxDrive.environmentDesc': 'Environment directory · installed packages are kept too','sandboxDrive.environmentBuildingDesc':'Environment directory · building, usable once it finishes',- 'sandboxDrive.upsell': 'Keep files on a drive','sandboxDrive.fallback.directoryMissing':'This folder no longer exists on the drive. Runs use a temporary sandbox until you pick another folder.','sandboxDrive.fallback.instanceUnavailable':@@ -4392,7 +4384,6 @@ export default {'sandboxDrive.fallback.instanceRebuildRequired':'This private environment directory is still on the public drive and needs to be rebuilt on your personal drive. This run will use a temporary sandbox.','sandboxDrive.fallbackChip.instanceRebuildRequired': 'Rebuild on personal drive',- 'sandboxDrive.folderOnDriveDesc': '{{drive}} · {{path}}','input.costEstimate.hintUsd': 'Estimated cost: about {{amount}}','input.costEstimate.usdPerMillionTokens': '{{amount}} / 1M tokens','taskLabel.add': 'Add labels',diff --git a/src/features/ChatInput/ControlBar/OptionRow.tsx b/src/features/ChatInput/ControlBar/OptionRow.tsxindex d5b7c56c07d..6de7111582a 100644--- a/src/features/ChatInput/ControlBar/OptionRow.tsx+++ b/src/features/ChatInput/ControlBar/OptionRow.tsx@@ -3,7 +3,7 @@import { Flexbox, Icon } from '@lobehub/ui';import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';import * as stylex from '@stylexjs/stylex';-import { CheckIcon } from 'lucide-react';+import { CheckIcon, ChevronRightIcon } from 'lucide-react';import { memo, type ReactNode } from 'react';/**@@ -55,6 +55,7 @@ const styles = stylex.create({backgroundColor: { 'default': null, ':hover': 'transparent' },backgroundImage: { 'default': null, ':hover': 'none' },},+ optionCompact: { gap: '8px', paddingBlock: '6px' },/* Dims the row's own content rather than the row. Its trailing action is theway OUT of that state — dimming it would read as "also unavailable" — andopacity on the row cannot be undone by a child, so the action is left out@@ -75,6 +76,12 @@ const styles = stylex.create({backgroundColor: cssVar.colorBgElevated,backgroundImage: 'none',},+ optionIconCompact: {+ width: '16px',+ height: '16px',+ borderStyle: 'none',+ backgroundColor: 'transparent',+ },optionMeta: {display: 'flex',flex: '1',@@ -90,6 +97,14 @@ const styles = stylex.create({textOverflow: 'ellipsis',whiteSpace: 'nowrap',},+ hint: {+ overflow: 'hidden',+ minWidth: '0',+ fontSize: '11px',+ color: cssVar.colorTextDescription,+ textOverflow: 'ellipsis',+ whiteSpace: 'nowrap',+ },tag: {flex: 'none',paddingBlock: '0',@@ -105,10 +120,18 @@ const styles = stylex.create({export interface OptionRowProps {active?: boolean;+ /** The row opens a second level, so it ends in an arrow instead of a check. */+ arrow?: boolean;+ /** A ready-made mark beside the title, shown as it is rather than in a neutral pill. */+ badge?: ReactNode;+ /** A dense row for long lists: no icon frame, so its icon lines up with the menu's text. */+ compact?: boolean;desc?: ReactNode;disabled?: boolean;/** Trailing action, kept live while the row itself is disabled. */extra?: ReactNode;+ /** A short muted note beside the title, such as the owner/name of a repository. */+ hint?: ReactNode;icon: ReactNode;label: ReactNode;onClick: () => void;@@ -121,23 +144,49 @@ export interface OptionRowProps {}const OptionRow = memo<OptionRowProps>(- ({ active, desc, disabled, extra, icon, label, onClick, tag, tags, xstyle }) => (+ ({+ active,+ arrow,+ badge,+ compact,+ desc,+ disabled,+ extra,+ hint,+ icon,+ label,+ onClick,+ tag,+ tags,+ xstyle,+ }) => (<divonClick={() => {if (!disabled) onClick();}}{...stylex.props(styles.option,+ compact && styles.optionCompact,active && styles.optionActive,disabled && styles.optionDisabled,active && disabled && styles.optionActiveDisabled,xstyle,)}>- <div {...stylex.props(styles.optionIcon, disabled && styles.dimmed)}>{icon}</div>+ <div+ {...stylex.props(+ styles.optionIcon,+ compact && styles.optionIconCompact,+ disabled && styles.dimmed,+ )}+ >+ {icon}+ </div><div {...stylex.props(styles.optionMeta, disabled && styles.dimmed)}><Flexbox horizontal align={'center'} gap={6}><span {...stylex.props(styles.optionTitle)}>{label}</span>+ {hint ? <span {...stylex.props(styles.hint)}>{hint}</span> : null}+ {badge}{tag ? <span {...stylex.props(styles.tag)}>{tag}</span> : null}{tags?.map((item, index) => (<span key={index} {...stylex.props(styles.tag)}>@@ -158,7 +207,8 @@ const OptionRow = memo<OptionRowProps>({extra}</div>) : null}- {active ? (+ {arrow ? <Icon icon={ChevronRightIcon} size={14} /> : null}+ {active && !arrow ? (<IconclassName={stylex.props(styles.check, disabled && styles.dimmed).className}icon={CheckIcon}diff --git a/src/features/ChatInput/ControlBar/SandboxDriveMenu.tsx b/src/features/ChatInput/ControlBar/SandboxDriveMenu.tsxnew file mode 100644index 00000000000..499616dc850--- /dev/null+++ b/src/features/ChatInput/ControlBar/SandboxDriveMenu.tsx@@ -0,0 +1,134 @@+'use client';++import type { SandboxDrive } from '@lobechat/builtin-tool-cloud-sandbox';+import { SANDBOX_DRIVE_ROOT } from '@lobechat/builtin-tool-cloud-sandbox';+import { Button, Flexbox, Icon, Text } from '@lobehub/ui';+import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';+import * as stylex from '@stylexjs/stylex';+import { FolderIcon, FolderOpenIcon, HomeIcon } from 'lucide-react';+import { memo } from 'react';+import { useTranslation } from 'react-i18next';+import useSWR from 'swr';++import { useActiveWorkspaceId } from '@/business/client/hooks/useActiveWorkspaceId';+import { sandboxStorageService } from '@/services/sandboxStorage';++import OptionRow from './OptionRow';++const styles = stylex.create({+ header: {+ paddingBlock: '4px',+ paddingInline: '8px',+ fontSize: '12px',+ fontWeight: 500,+ color: cssVar.colorTextSecondary,+ },+ hint: {+ paddingInline: '8px',+ fontSize: '12px',+ color: cssVar.colorTextDescription,+ },+ list: {+ maxHeight: '280px',+ overflowY: 'auto',+ },+});++export interface SandboxDriveFolderPick {+ drive?: SandboxDrive;+ workingDirectory: string;+}++interface SandboxDriveMenuProps {+ /** Opens the full directory browser, for folders this short list does not reach. */+ onBrowse: () => void;+ onPick: (pick: SandboxDriveFolderPick) => void;+ /** The label of a pick the list cannot show: a nested folder, or another drive. */+ selectedLabel?: string;+ /** The folder the conversation is on, when it is on one. */+ selectedPath?: string;+}++/**+ * The second level of the work-location menu: the top of the conversation's own+ * drive, and the way into the full browser. The list lives here so it is only+ * fetched once the row is opened.+ */+const SandboxDriveMenu = memo<SandboxDriveMenuProps>(+ ({ onBrowse, onPick, selectedLabel, selectedPath }) => {+ const { t } = useTranslation(['chat', 'device']);+ const workspaceId = useActiveWorkspaceId();+ // The public drive's root is not a place to work, so a workspace starts on+ // the member's own drive, as a new conversation does.+ const drive: SandboxDrive | undefined = workspaceId ? 'personal' : undefined;++ const { data, error, mutate } = useSWR(+ ['sandbox-drive-menu-folders', workspaceId ?? '', drive ?? ''],+ () => sandboxStorageService.listFiles({ drive }),+ { revalidateOnFocus: false, shouldRetryOnError: false },+ );+ const folders = (data?.entries ?? [])+ .filter((entry) => entry.isDirectory)+ .sort((a, b) => a.name.localeCompare(b.name));++ const listed =+ selectedPath === SANDBOX_DRIVE_ROOT || folders.some((item) => item.path === selectedPath);++ return (+ <Flexbox gap={2} style={{ maxWidth: 360, minWidth: 280 }}>+ <div {...stylex.props(styles.header)}>{t('sandboxDrive.title')}</div>++ <div {...stylex.props(styles.list)}>+ {selectedLabel && !listed && (+ <OptionRow+ active+ compact+ icon={<Icon icon={FolderIcon} size={16} />}+ label={selectedLabel}+ onClick={() => {+ if (selectedPath) onPick({ drive, workingDirectory: selectedPath });+ }}+ />+ )}+ <OptionRow+ compact+ active={selectedPath === SANDBOX_DRIVE_ROOT}+ icon={<Icon icon={HomeIcon} size={16} />}+ label={t('sandboxDrive.root')}+ onClick={() => onPick({ drive, workingDirectory: SANDBOX_DRIVE_ROOT })}+ />+ {folders.map((folder) => (+ <OptionRow+ compact+ active={folder.path === selectedPath}+ icon={<Icon icon={FolderIcon} size={16} />}+ key={folder.path}+ label={folder.name}+ onClick={() => onPick({ drive, workingDirectory: folder.path })}+ />+ ))}+ </div>++ {error && (+ <Flexbox horizontal align={'center'} gap={8} justify={'space-between'} paddingInline={8}>+ <Text className={stylex.props(styles.hint).className} type={'danger'}>+ {t('workingDirectory.drive.foldersLoadFailed', { ns: 'device' })}+ </Text>+ <Button onClick={() => void mutate()}>{t('sandboxEnvironment.retry')}</Button>+ </Flexbox>+ )}++ <OptionRow+ compact+ icon={<Icon icon={FolderOpenIcon} size={16} />}+ label={t('sandboxDrive.browseOther')}+ onClick={onBrowse}+ />+ </Flexbox>+ );+ },+);++SandboxDriveMenu.displayName = 'SandboxDriveMenu';++export default SandboxDriveMenu;diff --git a/src/features/ChatInput/ControlBar/SandboxDrivePicker.tsx b/src/features/ChatInput/ControlBar/SandboxDrivePicker.tsxindex 714b4fc0af2..11e6aab7fc1 100644--- a/src/features/ChatInput/ControlBar/SandboxDrivePicker.tsx+++ b/src/features/ChatInput/ControlBar/SandboxDrivePicker.tsx@@ -1,13 +1,13 @@'use client';-import { Flexbox, Icon, Popover, Skeleton, Text, toast, Tooltip } from '@lobehub/ui';+import { ENABLE_BUSINESS_FEATURES } from '@lobechat/business-const';+import { Github } from '@lobehub/icons';+import { Flexbox, Icon, Popover, Skeleton, Tag, Text, toast, Tooltip } from '@lobehub/ui';import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';import * as stylex from '@stylexjs/stylex';import {ChevronDownIcon,- FolderClockIcon,FolderIcon,- FolderOpenIcon,HardDriveIcon,InfoIcon,PackageIcon,@@ -20,11 +20,19 @@ import useSWR from 'swr';import { openSandboxStorageUpsell } from '@/business/client/features/SandboxStorageUpsell';import { useActiveWorkspaceId } from '@/business/client/hooks/useActiveWorkspaceId';+import { openCreateEnvironmentModal } from '@/features/EnvironmentManager/CreateEnvironmentModal';import { openSandboxDirectoryModal } from '@/features/WorkingDirectory';+import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';+import { environmentService } from '@/services/environment';import { refreshProjectFiles } from '@/services/projectFile';import { sandboxStorageService } from '@/services/sandboxStorage';+import { useAgentStore } from '@/store/agent';+import { agentSelectors } from '@/store/agent/selectors';import OptionRow from './OptionRow';+import SandboxDriveMenu from './SandboxDriveMenu';+import { environmentChipState, pickableEnvironments } from './sandboxEnvironmentOptions';+import SandboxRepositoryMenu, { type SandboxRepositoryOption } from './SandboxRepositoryMenu';import { isPersistentSelection, type SandboxSelection } from './useSandboxPlacement';import { workingDirectoryChipStyles } from './workingDirectoryChipStyles';@@ -59,6 +67,16 @@ const styles = stylex.create({},});+/**+ * A submenu's list can arrive after it opens. Left to size itself, its positioner+ * keeps the size it was first measured at, so the popup would grow off the screen+ * instead of being placed again.+ */+const SUBMENU_STYLES = {+ content: { padding: 4 },+ root: { height: 'auto', width: 'auto' },+};+interface SandboxDrivePickerProps {/** Whether this plan includes a drive. Without one the menu offers the way to a plan. */entitled: boolean;@@ -78,9 +96,12 @@ const folderName = (path: string) => path.split('/').pop() || path;* Nothing picked is the temporary sandbox; picking a folder on the drive is* the choice to keep files. A pick that can no longer be honoured — the* folder was deleted — is said on the chip itself, before the next message- * runs somewhere the person did not choose. The environment the directory is- * initialized from is a separate choice, beside this one, and every pick here- * carries it along unchanged.+ * runs somewhere the person did not choose.+ *+ * A repository is the third kind of place, one level down: temporary, a folder+ * or a repository, one at a time. A checkout only lands in an empty folder, so+ * offering it beside a folder that holds files would let a pick silently do+ * nothing.** A conversation from before environments became initializers may still be* bound to an environment directory; it is shown by name until another pick@@ -91,7 +112,30 @@ const SandboxDrivePicker = memo<SandboxDrivePickerProps>(const { t } = useTranslation(['chat', 'device']);const [open, setOpen] = useState(false);const workspaceId = useActiveWorkspaceId();+ const navigate = useWorkspaceAwareNavigate();const persistent = isPersistentSelection(value);+ const onRepository = !!value.environmentId;++ const {+ data: environmentList,+ error: environmentsError,+ mutate: refreshEnvironments,+ } = useSWR(['sandbox-environment-chip', workspaceId ?? ''], () =>+ environmentService.listEnvironments(),+ );+ const sharedAgent = useAgentStore(+ (s) => !!workspaceId && agentSelectors.currentAgentVisibility(s) === 'public',+ );+ const environments = pickableEnvironments(environmentList?.environments ?? [], sharedAgent);+ const repository = environments.find((item) => item.id === value.environmentId);+ // Picked once but no longer readable — deleted, or unpublished by its owner+ // — is said rather than hidden; a list that has not loaded says nothing.+ const repositoryState = environmentChipState({+ current: repository,+ environmentId: value.environmentId,+ failed: !!environmentsError,+ loaded: !!environmentList,+ });// A legacy environment directory's own row, for its name — from the// database, so the chip never waits on a sandbox.@@ -122,9 +166,7 @@ const SandboxDrivePicker = memo<SandboxDrivePickerProps>(// go on showing the old answers — "no longer exists" on the chip and an// unreadable tree in the working panel, for a folder just re-created and// picked again. Ask once more after every pick.- const pick = async (placement: Omit<SandboxSelection, 'environmentId'>) => {- // The environment is chosen beside the folder, not with it.- const selection = { ...placement, environmentId: value.environmentId };+ const pick = async (selection: SandboxSelection) => {await onChange(selection);void revalidatePlacement();if (topicId && !selection.instanceId && selection.workingDirectory !== undefined) {@@ -133,7 +175,7 @@ const SandboxDrivePicker = memo<SandboxDrivePickerProps>(}};- const select = async (selection: Omit<SandboxSelection, 'environmentId'>) => {+ const select = async (selection: SandboxSelection) => {setOpen(false);try {await pick(selection);@@ -143,6 +185,31 @@ const SandboxDrivePicker = memo<SandboxDrivePickerProps>(}};+ // A repository is only cloned into an empty folder, so it never inherits the+ // folder the conversation was on: it starts in a temporary sandbox.+ const pickRepository = async (environment: SandboxRepositoryOption) => {+ try {+ await onChange({ environmentId: environment.id });+ void revalidatePlacement();+ } catch {+ // The topic kept its place; said rather than left looking changed.+ toast.error(t('sandboxEnvironment.saveFailed'));+ }+ };++ const addRepository = () => {+ setOpen(false);+ openCreateEnvironmentModal(+ // A workspace-public agent applies published environments only.+ sharedAgent ? 'public' : undefined,+ async (created) => {+ await refreshEnvironments();+ if (created?.id) await pickRepository(created);+ },+ t('sandboxEnvironment.add'),+ );+ };+const openBrowser = () => {setOpen(false);openSandboxDirectoryModal({@@ -167,25 +234,33 @@ const SandboxDrivePicker = memo<SandboxDrivePickerProps>(? folderName(value.workingDirectory): undefined;const currentIcon = value.instanceId ? PackageIcon : FolderIcon;+ const showFolder = persistent && !onRepository;const fallbackMessage = fallback ? t(`sandboxDrive.fallback.${fallback}`) : undefined;- // In a workspace a folder path means nothing without its drive.- const driveName = workspaceId- ? t(`workingDirectory.drive.drives.${value.drive ?? 'public'}`, { ns: 'device' })- : undefined;-const chipIcon = fallback ? (<Icon icon={TriangleAlertIcon} size={14} />+ ) : onRepository ? (+ <Github size={14} />) : persistent ? (<Icon icon={currentIcon} size={14} />) : (<Icon icon={TimerIcon} size={14} />);- const chipLabel = persistent- ? fallback- ? t(`sandboxDrive.fallbackChip.${fallback}`)- : currentLabel- : t('sandboxStorage.ephemeral');+ const repositoryLabel =+ repositoryState.kind === 'picked'+ ? repositoryState.name+ : repositoryState.kind === 'missing'+ ? t('sandboxEnvironment.missing')+ : repositoryState.kind === 'loadFailed'+ ? t('sandboxEnvironment.loadFailed')+ : t('sandboxEnvironment.loading');+ const chipLabel = fallback+ ? t(`sandboxDrive.fallbackChip.${fallback}`)+ : onRepository+ ? repositoryLabel+ : persistent+ ? currentLabel+ : t('sandboxStorage.ephemeral');const content = (<Flexbox gap={2} style={{ maxWidth: 360, minWidth: 280 }}>@@ -205,58 +280,95 @@ const SandboxDrivePicker = memo<SandboxDrivePickerProps>()}<OptionRow- active={!persistent}- desc={t('sandboxStorage.ephemeralDesc')}+ compact+ active={!persistent && !onRepository}icon={<Icon icon={TimerIcon} size={16} />}label={t('sandboxStorage.ephemeral')}onClick={() => void select({})}/>- {entitled && persistent && currentLabel && (- <OptionRow- active- icon={<Icon icon={currentIcon} size={16} />}- label={currentLabel}- desc={- value.instanceId- ? t('sandboxDrive.environmentDesc')- : driveName- ? t('sandboxDrive.folderOnDriveDesc', {- drive: driveName,- path: value.workingDirectory === '.' ? '/' : `/${value.workingDirectory}`,- })- : t('sandboxDrive.folderDesc', {- path: value.workingDirectory === '.' ? '/' : `/${value.workingDirectory}`,- })- }- onClick={() => setOpen(false)}- />- )}-- {entitled && (- <OptionRow- desc={t('sandboxDrive.browseDesc')}- icon={<Icon icon={persistent ? FolderOpenIcon : HardDriveIcon} size={16} />}- label={t(persistent ? 'sandboxDrive.browseOther' : 'sandboxDrive.browse')}- onClick={openBrowser}- />- )}+ {ENABLE_BUSINESS_FEATURES &&+ (entitled ? (+ <Popover+ arrow={false}+ closeDelay={150}+ placement={'rightBottom'}+ styles={SUBMENU_STYLES}+ trigger={['hover', 'click']}+ content={+ <SandboxDriveMenu+ selectedLabel={showFolder ? currentLabel : undefined}+ selectedPath={showFolder ? value.workingDirectory : undefined}+ onBrowse={openBrowser}+ onPick={(folder) => void select(folder)}+ />+ }+ >+ <div data-testid={'sandbox-drive-row'}>+ <OptionRow+ arrow+ compact+ active={showFolder}+ icon={<Icon icon={HardDriveIcon} size={16} />}+ label={t('sandboxDrive.title')}+ onClick={() => {}}+ />+ </div>+ </Popover>+ ) : (+ // The drive is part of a plan this account is not on. Offered in the+ // same list, in the same shape, so the row reads as one more place+ // files could go — and the tag says why it is not simply selectable.+ <OptionRow+ compact+ icon={<Icon icon={HardDriveIcon} size={16} />}+ label={t('sandboxDrive.title')}+ badge={+ <Tag color={'gold'} size={'small'} style={{ borderRadius: 999, paddingInline: 8 }}>+ {t('pro', { ns: 'common' })}+ </Tag>+ }+ onClick={() => {+ setOpen(false);+ openSandboxStorageUpsell();+ }}+ />+ ))}- {!entitled && (- // The drive is part of a plan this account is not on. Offered in the- // same list, in the same shape, so the row reads as one more place- // files could go — and the tag says why it is not simply selectable.- <OptionRow- desc={t('sandboxStorage.persistentUpsellDesc')}- icon={<Icon icon={FolderClockIcon} size={16} />}- label={t('sandboxDrive.upsell')}- tag={t('pro', { ns: 'common' })}- onClick={() => {- setOpen(false);- openSandboxStorageUpsell();- }}- />- )}+ <Popover+ arrow={false}+ closeDelay={150}+ placement={'rightBottom'}+ styles={SUBMENU_STYLES}+ trigger={['hover', 'click']}+ content={+ <SandboxRepositoryMenu+ environments={environments}+ failed={!!environmentsError}+ loaded={!!environmentList}+ selectedId={value.environmentId}+ onAdd={addRepository}+ onClose={() => setOpen(false)}+ onPick={pickRepository}+ onRetry={() => void refreshEnvironments()}+ onManage={() => {+ setOpen(false);+ navigate('/settings/environments');+ }}+ />+ }+ >+ <div data-testid={'sandbox-repository-row'}>+ <OptionRow+ arrow+ compact+ active={onRepository}+ icon={<Github size={16} />}+ label={t('sandboxEnvironment.title')}+ onClick={() => {}}+ />+ </div>+ </Popover></Flexbox>);@@ -270,6 +382,7 @@ const SandboxDrivePicker = memo<SandboxDrivePickerProps>(content={content}open={open}placement={'topLeft'}+ styles={{ content: { padding: 4 } }}trigger={'click'}onOpenChange={setOpen}>diff --git a/src/features/ChatInput/ControlBar/SandboxEnvironmentPicker.tsx b/src/features/ChatInput/ControlBar/SandboxEnvironmentPicker.tsxdeleted file mode 100644index 6a7265afe8e..00000000000--- a/src/features/ChatInput/ControlBar/SandboxEnvironmentPicker.tsx+++ /dev/null@@ -1,199 +0,0 @@-'use client';--import { Button, Flexbox, Icon, Popover, Text, toast } from '@lobehub/ui';-import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';-import * as stylex from '@stylexjs/stylex';-import { ChevronDownIcon, CircleSlashIcon, PackageIcon, SettingsIcon } from 'lucide-react';-import { memo, useState } from 'react';-import { useTranslation } from 'react-i18next';-import useSWR from 'swr';--import { useActiveWorkspaceId } from '@/business/client/hooks/useActiveWorkspaceId';-import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';-import { environmentService } from '@/services/environment';-import { useAgentStore } from '@/store/agent';-import { agentSelectors } from '@/store/agent/selectors';--import OptionRow from './OptionRow';-import { environmentChipState, pickableEnvironments } from './sandboxEnvironmentOptions';-import type { SandboxSelection } from './useSandboxPlacement';-import { workingDirectoryChipStyles } from './workingDirectoryChipStyles';--const styles = stylex.create({- header: {- alignItems: 'center',- display: 'flex',- gap: 6,- justifyContent: 'space-between',- paddingBlock: 4,- paddingInline: 8,- },- headerTitle: {- color: cssVar.colorTextTertiary,- fontSize: 12,- fontWeight: 500,- },- hint: {- color: cssVar.colorTextDescription,- fontSize: 11,- paddingBlockEnd: 4,- paddingInline: 8,- },- list: {- maxHeight: 280,- overflowY: 'auto',- },- manageButton: {- alignItems: 'center',- backgroundColor: 'transparent',- borderStyle: 'none',- color: { 'default': cssVar.colorTextQuaternary, ':hover': cssVar.colorPrimary },- cursor: 'pointer',- display: 'flex',- fontSize: 11,- gap: 3,- padding: 0,- transition: 'color 0.2s',- },-});--interface SandboxEnvironmentPickerProps {- onChange: (selection: SandboxSelection) => Promise<void>;- /** Where this conversation works today, and what it is initialized from. */- value: SandboxSelection;-}--/**- * Which code environment a cloud-sandbox conversation starts from — beside the- * working-directory chip, and independent of it. An environment is a one-time- * initializer: its repository is cloned and its setup run in the working- * directory before the first command, once per temporary sandbox and once for- * a folder on the drive. A folder that already holds files is left as it is.- *- * Picking here changes only the environment; the folder stays where it is.- */-const SandboxEnvironmentPicker = memo<SandboxEnvironmentPickerProps>(({ onChange, value }) => {- const { t } = useTranslation('chat');- const [open, setOpen] = useState(false);- const navigate = useWorkspaceAwareNavigate();- const workspaceId = useActiveWorkspaceId();-- const { data, error, mutate } = useSWR(['sandbox-environment-chip', workspaceId ?? ''], () =>- environmentService.listEnvironments(),- );- const sharedAgent = useAgentStore(- (s) => !!workspaceId && agentSelectors.currentAgentVisibility(s) === 'public',- );- const environments = pickableEnvironments(data?.environments ?? [], sharedAgent);- const current = environments.find((environment) => environment.id === value.environmentId);- // Picked once but no longer readable — deleted, or unpublished by its owner- // — is said rather than hidden; a list that has not loaded says nothing.- const state = environmentChipState({- current,- environmentId: value.environmentId,- failed: !!error,- loaded: !!data,- });-- const select = async (environmentId: string | undefined) => {- setOpen(false);- try {- // A legacy copy runs what its build made and is never initialized, so- // picking an environment leaves it for the folder it lives in.- await onChange({ ...value, environmentId, instanceId: undefined });- } catch {- // The topic kept its environment; said rather than left looking changed.- toast.error(t('sandboxEnvironment.saveFailed'));- }- };-- const content = (- <Flexbox gap={2} style={{ maxWidth: 360, minWidth: 280 }}>- <div {...stylex.props(styles.header)}>- <span {...stylex.props(styles.headerTitle)}>{t('sandboxEnvironment.title')}</span>- <button- {...stylex.props(styles.manageButton)}- type={'button'}- onClick={() => {- setOpen(false);- navigate('/settings/environments');- }}- >- <Icon icon={SettingsIcon} size={11} />- <span>{t('sandboxDrive.manageEnvironments')}</span>- </button>- </div>- <Text className={stylex.props(styles.hint).className}>{t('sandboxEnvironment.hint')}</Text>-- <OptionRow- active={!value.environmentId}- desc={t('sandboxEnvironment.noneDesc')}- icon={<Icon icon={CircleSlashIcon} size={16} />}- label={t('sandboxEnvironment.none')}- onClick={() => void select(undefined)}- />- <div {...stylex.props(styles.list)}>- {environments.map((environment) => (- <OptionRow- active={environment.id === value.environmentId}- desc={environment.description || undefined}- icon={<Icon icon={PackageIcon} size={16} />}- key={environment.id}- label={environment.name}- onClick={() => void select(environment.id)}- />- ))}- </div>- {data && environments.length === 0 && (- <Text className={stylex.props(styles.hint).className}>{t('sandboxEnvironment.empty')}</Text>- )}- {!data && error && (- <Flexbox horizontal align={'center'} gap={8} justify={'space-between'}>- <Text className={stylex.props(styles.hint).className} type={'danger'}>- {t('sandboxEnvironment.loadFailed')}- </Text>- <Button onClick={() => void mutate()}>{t('sandboxEnvironment.retry')}</Button>- </Flexbox>- )}- </Flexbox>- );-- const label =- state.kind === 'picked'- ? state.name- : state.kind === 'missing'- ? t('sandboxEnvironment.missing')- : state.kind === 'loading'- ? t('sandboxEnvironment.loading')- : state.kind === 'loadFailed'- ? t('sandboxEnvironment.loadFailed')- : t('sandboxEnvironment.none');-- // A plain div between the popover and the chip, as the device picker has:- // the popover merges trigger props into its direct child.- return (- <Popover- arrow={false}- content={content}- open={open}- placement={'topLeft'}- trigger={'click'}- onOpenChange={setOpen}- >- <div>- <div- {...stylex.props(workingDirectoryChipStyles.chip)}- data-testid={'sandbox-environment-chip'}- >- <Icon icon={value.environmentId ? PackageIcon : CircleSlashIcon} size={14} />- <span {...stylex.props(workingDirectoryChipStyles.label)}>{label}</span>- <Icon icon={ChevronDownIcon} size={12} />- </div>- </div>- </Popover>- );-});--SandboxEnvironmentPicker.displayName = 'SandboxEnvironmentPicker';--export default SandboxEnvironmentPicker;diff --git a/src/features/ChatInput/ControlBar/SandboxRepositoryMenu.tsx b/src/features/ChatInput/ControlBar/SandboxRepositoryMenu.tsxnew file mode 100644index 00000000000..b438de3f649--- /dev/null+++ b/src/features/ChatInput/ControlBar/SandboxRepositoryMenu.tsx@@ -0,0 +1,135 @@+'use client';++import type { EnvironmentConfiguration } from '@lobechat/types';+import { Github } from '@lobehub/icons';+import { Button, Flexbox, Icon, Text } from '@lobehub/ui';+import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';+import * as stylex from '@stylexjs/stylex';+import { PlusIcon, SettingsIcon } from 'lucide-react';+import { memo } from 'react';+import { useTranslation } from 'react-i18next';++import OptionRow from './OptionRow';+import { repositorySlug } from './sandboxEnvironmentOptions';++const styles = stylex.create({+ header: {+ display: 'flex',+ alignItems: 'center',+ justifyContent: 'space-between',+ paddingBlock: '4px',+ paddingInline: '8px',+ },+ headerTitle: {+ fontSize: '12px',+ fontWeight: 500,+ color: cssVar.colorTextSecondary,+ },+ hint: {+ paddingInline: '8px',+ fontSize: '12px',+ color: cssVar.colorTextDescription,+ },+ list: {+ maxHeight: '280px',+ overflowY: 'auto',+ },+ manageButton: {+ cursor: 'pointer',+ display: 'flex',+ gap: '4px',+ alignItems: 'center',+ padding: '0',+ borderStyle: 'none',+ fontSize: '11px',+ color: { 'default': cssVar.colorTextQuaternary, ':hover': cssVar.colorPrimary },+ backgroundColor: 'transparent',+ backgroundImage: 'none',+ transition: 'color 0.2s',+ },+});++export interface SandboxRepositoryOption {+ configuration?: Pick<EnvironmentConfiguration, 'sources'> | null;+ description?: string | null;+ id: string;+ name: string;+}++interface SandboxRepositoryMenuProps {+ environments: SandboxRepositoryOption[];+ failed: boolean;+ loaded: boolean;+ onAdd: () => void;+ /** Closes the whole work-location menu; a final pick leaves it. */+ onClose: () => void;+ onManage: () => void;+ onPick: (environment: SandboxRepositoryOption) => Promise<void>;+ onRetry: () => void;+ selectedId?: string;+}++/**+ * The second level of the work-location menu: the repositories a conversation+ * can work on, and the way to add one without leaving the composer.+ */+const SandboxRepositoryMenu = memo<SandboxRepositoryMenuProps>(+ ({ environments, failed, loaded, onAdd, onClose, onManage, onPick, onRetry, selectedId }) => {+ const { t } = useTranslation('chat');+ return (+ <Flexbox gap={2} style={{ maxWidth: 360, minWidth: 280 }}>+ <div {...stylex.props(styles.header)}>+ <span {...stylex.props(styles.headerTitle)}>{t('sandboxEnvironment.title')}</span>+ <button {...stylex.props(styles.manageButton)} type={'button'} onClick={onManage}>+ <Icon icon={SettingsIcon} size={11} />+ <span>{t('sandboxDrive.manageEnvironments')}</span>+ </button>+ </div>+ <Text className={stylex.props(styles.hint).className}>{t('sandboxEnvironment.hint')}</Text>++ <div {...stylex.props(styles.list)}>+ {environments.map((environment) => (+ <OptionRow+ compact+ active={environment.id === selectedId}+ desc={environment.description || undefined}+ hint={repositorySlug(environment)}+ icon={<Github size={16} />}+ key={environment.id}+ label={environment.name}+ onClick={() => {+ onClose();+ void onPick(environment);+ }}+ />+ ))}+ </div>++ {loaded && environments.length === 0 && (+ <Text className={stylex.props(styles.hint).className}>+ {t('sandboxEnvironment.empty')}+ </Text>+ )}+ {!loaded && failed && (+ <Flexbox horizontal align={'center'} gap={8} justify={'space-between'} paddingInline={8}>+ <Text className={stylex.props(styles.hint).className} type={'danger'}>+ {t('sandboxEnvironment.loadFailed')}+ </Text>+ <Button onClick={onRetry}>{t('sandboxEnvironment.retry')}</Button>+ </Flexbox>+ )}++ <OptionRow+ compact+ icon={<Icon icon={PlusIcon} size={16} />}+ label={t('sandboxEnvironment.add')}+ onClick={onAdd}+ />+ </Flexbox>+ );+ },+);++SandboxRepositoryMenu.displayName = 'SandboxRepositoryMenu';++export default SandboxRepositoryMenu;diff --git a/src/features/ChatInput/ControlBar/SandboxStorageSection.tsx b/src/features/ChatInput/ControlBar/SandboxStorageSection.tsxindex f60a5b1f4b0..5201153d00b 100644--- a/src/features/ChatInput/ControlBar/SandboxStorageSection.tsx+++ b/src/features/ChatInput/ControlBar/SandboxStorageSection.tsx@@ -6,7 +6,6 @@ import SafeBoundary from '@/components/ErrorBoundary';import { useTopicId } from '../hooks/useTopicId';import SandboxDrivePicker from './SandboxDrivePicker';-import SandboxEnvironmentPicker from './SandboxEnvironmentPicker';import { useSandboxPlacement } from './useSandboxPlacement';import { useSandboxStorageAccess } from './useSandboxStorageAccess';import { useSeedDefaultSelection } from './useSeedDefaultSelection';@@ -22,10 +21,9 @@ interface SandboxStorageSectionProps {* the run could work.** Nothing chosen means a temporary sandbox, cleaned up with the session; a- * folder on the drive keeps its files. A plan with a drive starts each new- * conversation on its default folder rather than nothing. Beside it, the- * environment the working directory is initialized from — a separate choice,- * so a temporary sandbox can start from a checkout too.+ * folder on the drive keeps its files, and a repository starts from a checkout.+ * A plan with a drive starts each new conversation on its default folder rather+ * than nothing.** A plan without a drive still gets the chip: the temporary sandbox is* everyone's, and the way to a plan is a row in the same menu rather than a@@ -43,15 +41,12 @@ const SandboxStorageSectionInner = memo<SandboxStorageSectionProps>(({ agentId }if (status === 'hidden') return null;return (- <>- <SandboxDrivePicker- entitled={status === 'ready'}- topicId={topicId}- value={selection}- onChange={setSelection}- />- <SandboxEnvironmentPicker value={selection} onChange={setSelection} />- </>+ <SandboxDrivePicker+ entitled={status === 'ready'}+ topicId={topicId}+ value={selection}+ onChange={setSelection}+ />);});diff --git a/src/features/ChatInput/ControlBar/sandboxEnvironmentOptions.test.ts b/src/features/ChatInput/ControlBar/sandboxEnvironmentOptions.test.tsindex 4a5fe096de8..fb7e9f24446 100644--- a/src/features/ChatInput/ControlBar/sandboxEnvironmentOptions.test.ts+++ b/src/features/ChatInput/ControlBar/sandboxEnvironmentOptions.test.ts@@ -1,6 +1,10 @@import { describe, expect, it } from 'vitest';-import { environmentChipState, pickableEnvironments } from './sandboxEnvironmentOptions';+import {+ environmentChipState,+ pickableEnvironments,+ repositorySlug,+} from './sandboxEnvironmentOptions';const environments = [{ id: 'mine', visibility: 'private' },@@ -45,3 +49,24 @@ describe('environmentChipState', () => {expect(environmentChipState({ failed: true, loaded: false })).toEqual({ kind: 'none' });});});++describe('repositorySlug', () => {+ const withUrl = (url: string) => ({+ configuration: { sources: [{ kind: 'git' as const, url }] },+ });++ it('reads owner/name from a repository URL', () => {+ expect(repositorySlug(withUrl('https://github.com/lobehub/lobehub'))).toBe('lobehub/lobehub');+ });++ it('drops a .git suffix', () => {+ expect(repositorySlug(withUrl('https://github.com/lobehub/lobe.id.git'))).toBe(+ 'lobehub/lobe.id',+ );+ });++ it('says nothing without a parsable source', () => {+ expect(repositorySlug({ configuration: null })).toBeUndefined();+ expect(repositorySlug(withUrl('not a url'))).toBeUndefined();+ });+});diff --git a/src/features/ChatInput/ControlBar/sandboxEnvironmentOptions.ts b/src/features/ChatInput/ControlBar/sandboxEnvironmentOptions.tsindex 81c1a849ced..f423b855333 100644--- a/src/features/ChatInput/ControlBar/sandboxEnvironmentOptions.ts+++ b/src/features/ChatInput/ControlBar/sandboxEnvironmentOptions.ts@@ -1,3 +1,5 @@+import type { EnvironmentConfiguration } from '@lobechat/types';+/*** The environments a conversation may start from. A workspace-public agent runs* on its caller's session, so it applies published environments only — the@@ -12,6 +14,20 @@ export const pickableEnvironments = <T extends { visibility?: string | null }>(? environments.filter((environment) => environment.visibility === 'public'): [...environments];+/** The `owner/name` of the repository an environment checks out, when it has one. */+export const repositorySlug = (environment: {+ configuration?: Pick<EnvironmentConfiguration, 'sources'> | null;+}): string | undefined => {+ const source = environment.configuration?.sources?.[0];+ if (source?.kind !== 'git') return undefined;+ const { url } = source;+ try {+ return new URL(url).pathname.replaceAll(/^\/+|\/+$/g, '').replace(/\.git$/, '') || undefined;+ } catch {+ return undefined;+ }+};+/*** What the environment chip says. A list still loading, or one that failed to* load, says nothing about the topic's environment — so it is not reported asdiff --git a/src/features/EnvironmentManager/CreateEnvironmentModal.tsx b/src/features/EnvironmentManager/CreateEnvironmentModal.tsxindex 5018118baaa..47b5529bf0b 100644--- a/src/features/EnvironmentManager/CreateEnvironmentModal.tsx+++ b/src/features/EnvironmentManager/CreateEnvironmentModal.tsx@@ -183,12 +183,13 @@ CreateEnvironmentContent.displayName = 'CreateEnvironmentContent';export const openCreateEnvironmentModal = (visibility?: EnvironmentVisibility,onCreated?: (environment: CreatedEnvironment) => void,+ title: string = translate('environments.create', { ns: 'setting' }),) =>createModal({content: <CreateEnvironmentContent visibility={visibility} onCreated={onCreated} />,footer: null,maskClosable: true,styles: { content: { padding: 0 } },- title: translate('environments.create', { ns: 'setting' }),+ title,width: 'min(90vw, 480px)',});