Skip to content

🤯 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.

🐛 fix(agent): 允许私有助手在档案页选择私人设备 (#21864)

Mochad5e0c8af4700
diff --git a/locales/en-US/setting.json b/locales/en-US/setting.json
index c60a70cddcc..9044d6fadfb 100644
--- a/locales/en-US/setting.json
+++ b/locales/en-US/setting.json
@@ -1302,6 +1302,8 @@
"settingAgent.description.placeholder": "Enter agent description",
"settingAgent.description.title": "Agent Description",
"settingAgent.devicePolicy.noPublicDevice": "No public devices",
+ "settingAgent.devicePolicy.privateDeviceFixed": "A fixed environment can only use public workspace devices",
+ "settingAgent.devicePolicy.privateDevicePublicAgent": "Private devices are for private agents only — other members cannot reach them",
"settingAgent.devicePolicy.selectTarget": "Select environment",
"settingAgent.devicePolicy.title": "Execution environment",
"settingAgent.export.dialogTitle": "Export Agent Profile",
diff --git a/locales/zh-CN/setting.json b/locales/zh-CN/setting.json
index 8318510f268..f159f2a10e3 100644
--- a/locales/zh-CN/setting.json
+++ b/locales/zh-CN/setting.json
@@ -1302,6 +1302,8 @@
"settingAgent.description.placeholder": "请输入助理描述",
"settingAgent.description.title": "助理描述",
"settingAgent.devicePolicy.noPublicDevice": "暂无公开设备",
+ "settingAgent.devicePolicy.privateDeviceFixed": "固定的执行环境只能使用公开的工作区设备",
+ "settingAgent.devicePolicy.privateDevicePublicAgent": "私人设备仅可用于私有助手,其他成员无法连接",
"settingAgent.devicePolicy.selectTarget": "选择环境",
"settingAgent.devicePolicy.title": "执行环境",
"settingAgent.export.dialogTitle": "导出助理档案",
diff --git a/packages/locales/src/default/setting.ts b/packages/locales/src/default/setting.ts
index 3f536a819be..b136a0814bf 100644
--- a/packages/locales/src/default/setting.ts
+++ b/packages/locales/src/default/setting.ts
@@ -1191,6 +1191,10 @@ export default {
'settingAgent.agentTools.tabUser': 'User Tools',
'settingAgent.agentTools.tabWorkspace': 'Workspace Tools',
'settingAgent.devicePolicy.noPublicDevice': 'No public devices',
+ 'settingAgent.devicePolicy.privateDeviceFixed':
+ 'A fixed environment can only use public workspace devices',
+ 'settingAgent.devicePolicy.privateDevicePublicAgent':
+ 'Private devices are for private agents only — other members cannot reach them',
'settingAgent.devicePolicy.selectTarget': 'Select environment',
'settingAgent.devicePolicy.title': 'Execution environment',
'settingAgent.modelPolicy.fixedTip':
diff --git a/src/routes/(main)/agent/profile/features/ProfileEditor/WorkspaceAgentDevicePolicy.test.tsx b/src/routes/(main)/agent/profile/features/ProfileEditor/WorkspaceAgentDevicePolicy.test.tsx
index 5aa492f332b..286f7eb875f 100644
--- a/src/routes/(main)/agent/profile/features/ProfileEditor/WorkspaceAgentDevicePolicy.test.tsx
+++ b/src/routes/(main)/agent/profile/features/ProfileEditor/WorkspaceAgentDevicePolicy.test.tsx
@@ -10,8 +10,12 @@ const testState = vi.hoisted(() => ({
agentMap: {
'agent-1': {
agencyConfig: {
- executionTarget: 'auto' as const,
- executionTargetSelectionPolicy: 'member' as const,
+ executionTarget: 'auto',
+ executionTargetSelectionPolicy: 'member',
+ } as {
+ boundDeviceId?: string;
+ executionTarget: string;
+ executionTargetSelectionPolicy: string;
},
visibility: 'public' as 'private' | 'public',
workspaceId: 'workspace-1',
@@ -152,3 +156,94 @@ describe('WorkspaceAgentDevicePolicy over an unconfirmed device list', () => {
expect(workspaceGroup()[0].disabled).toBeFalsy();
});
});
+
+describe('WorkspaceAgentDevicePolicy with a private workspace device', () => {
+ const privateDevice = {
+ channels: [],
+ deviceId: 'private-device',
+ friendlyName: 'My Laptop',
+ online: true,
+ scope: 'workspace',
+ visibility: 'private',
+ };
+
+ const privateGroupOptions = () => {
+ const options = (selectPropsSpy.mock.lastCall?.[0] as { options: unknown[] }).options as {
+ options?: { disabled?: boolean; value: string }[];
+ }[];
+ return (
+ options.find((group) =>
+ group.options?.some((option) => option.value.includes('private-device')),
+ )?.options ?? []
+ );
+ };
+
+ const deviceOption = () =>
+ privateGroupOptions().find((option) => option.value.includes('private-device'));
+
+ beforeEach(() => {
+ selectPropsSpy.mockClear();
+ testState.agent.updateAgentConfigById.mockReset();
+ testState.agent.agentMap['agent-1'].agencyConfig = {
+ executionTarget: 'auto',
+ executionTargetSelectionPolicy: 'member',
+ };
+ testState.deviceList = { data: [privateDevice], isConfirmed: true, isLoading: false };
+ });
+
+ it("lets a private agent's owner bind their own private device", () => {
+ testState.agent.agentMap['agent-1'].visibility = 'private';
+
+ render(<WorkspaceAgentDevicePolicy agentId="agent-1" />);
+
+ const option = deviceOption();
+ expect(option?.disabled).toBeFalsy();
+
+ const { onChange } = selectPropsSpy.mock.lastCall?.[0] as { onChange: (v: string) => void };
+ onChange(option!.value);
+ expect(testState.agent.updateAgentConfigById).toHaveBeenCalledWith('agent-1', {
+ agencyConfig: { boundDeviceId: 'private-device', executionTarget: 'device' },
+ });
+ });
+
+ it('keeps private devices unselectable on a public agent and says why', () => {
+ testState.agent.agentMap['agent-1'].visibility = 'public';
+
+ render(<WorkspaceAgentDevicePolicy agentId="agent-1" />);
+
+ expect(deviceOption()?.disabled).toBe(true);
+ expect(privateGroupOptions().map((option) => option.value)).toContain(
+ 'status:privateUnavailable',
+ );
+ });
+
+ it('keeps private devices unselectable once the environment is fixed', () => {
+ testState.agent.agentMap['agent-1'].visibility = 'private';
+ testState.agent.agentMap['agent-1'].agencyConfig = {
+ executionTarget: 'auto',
+ executionTargetSelectionPolicy: 'fixed',
+ };
+
+ render(<WorkspaceAgentDevicePolicy agentId="agent-1" />);
+
+ expect(deviceOption()?.disabled).toBe(true);
+ expect(privateGroupOptions().map((option) => option.value)).toContain(
+ 'status:privateUnavailable',
+ );
+ });
+
+ it('shows an already-bound private device as the current selection', () => {
+ testState.agent.agentMap['agent-1'].visibility = 'private';
+ testState.agent.agentMap['agent-1'].agencyConfig = {
+ boundDeviceId: 'private-device',
+ executionTarget: 'device',
+ executionTargetSelectionPolicy: 'member',
+ };
+
+ render(<WorkspaceAgentDevicePolicy agentId="agent-1" />);
+
+ const { value } = selectPropsSpy.mock.lastCall?.[0] as { value?: string };
+ expect(value).toContain('private-device');
+ expect(value).toBe(deviceOption()?.value);
+ });
+});
diff --git a/src/routes/(main)/agent/profile/features/ProfileEditor/WorkspaceAgentDevicePolicy.tsx b/src/routes/(main)/agent/profile/features/ProfileEditor/WorkspaceAgentDevicePolicy.tsx
index 863f48042c9..7550eea2c15 100644
--- a/src/routes/(main)/agent/profile/features/ProfileEditor/WorkspaceAgentDevicePolicy.tsx
+++ b/src/routes/(main)/agent/profile/features/ProfileEditor/WorkspaceAgentDevicePolicy.tsx
@@ -2,7 +2,7 @@
import { HETEROGENEOUS_TYPE_LABELS } from '@lobechat/heterogeneous-agents';
import type { DeviceExecutionTarget, DeviceListItem, LobeAgentAgencyConfig } from '@lobechat/types';
-import type { SelectOptions } from '@lobehub/ui';
+import type { SelectOption, SelectOptions } from '@lobehub/ui';
import { createStaticStyles, cssVar, Flexbox, Select } from '@lobehub/ui';
import { MonitorSmartphone } from 'lucide-react';
import { memo, useCallback, useMemo } from 'react';
@@ -170,11 +170,23 @@ const WorkspaceAgentDevicePolicy = memo<WorkspaceAgentDevicePolicyProps>(
const updateAgentConfigById = useAgentStore((s) => s.updateAgentConfigById);
const { data: devices, error, isConfirmed, isLoading, mutate } = useDeviceList();
- const { publicWorkspace: publicWorkspaceDevices } = useMemo(
- () => groupExecutionTargetDevices(devices),
- [devices],
+ const { privateWorkspace: privateWorkspaceDevices, publicWorkspace: publicWorkspaceDevices } =
+ useMemo(() => groupExecutionTargetDevices(devices), [devices]);
+ const selectableDevices = useMemo(
+ () => [...privateWorkspaceDevices, ...publicWorkspaceDevices],
+ [privateWorkspaceDevices, publicWorkspaceDevices],
);
const agencyConfig = config?.agencyConfig;
+ // This card writes the shared config, so a private device (resolvable only
+ // by the member who enrolled it) may be bound only when that member is the
+ // sole runner: a private Agent. A fixed target must stay public — the
+ // server rejects anything else (`assertFixedExecutionTarget`).
+ const privateDeviceBlockedReason =
+ config?.visibility !== 'private'
+ ? t('settingAgent.devicePolicy.privateDevicePublicAgent')
+ : agencyConfig?.executionTargetSelectionPolicy === 'fixed'
+ ? t('settingAgent.devicePolicy.privateDeviceFixed')
+ : undefined;
const heterogeneousType = agencyConfig?.heterogeneousProvider?.type;
const isHeterogeneous = !!heterogeneousType;
const supportsSandbox = isHeterogeneousSandboxExecutionAvailable(heterogeneousType);
@@ -287,8 +299,36 @@ const WorkspaceAgentDevicePolicy = memo<WorkspaceAgentDevicePolicyProps>(
},
];
+ // Only the caller's own private devices reach this list, so the group is
+ // simply absent for anyone without one.
+ const privateOptions: SelectOption<string>[] = [
+ ...privateWorkspaceDevices.map((device) => ({
+ disabled: !isConfirmed || !!privateDeviceBlockedReason,
+ label: renderDeviceLabel(device),
+ title: device.friendlyName || device.hostname || device.deviceId,
+ value: executionTargetValue('device', device.deviceId),
+ })),
+ ...(privateDeviceBlockedReason
+ ? [
+ {
+ disabled: true,
+ label: privateDeviceBlockedReason,
+ value: 'status:privateUnavailable',
+ },
+ ]
+ : []),
+ ];
+
return [
...sharedTargets,
+ ...(!error && !isLoading && privateWorkspaceDevices.length > 0
+ ? [
+ {
+ label: t('chat:heteroAgent.executionTarget.personalGroup'),
+ options: privateOptions,
+ },
+ ]
+ : []),
...(!error
? [
{
@@ -303,6 +343,8 @@ const WorkspaceAgentDevicePolicy = memo<WorkspaceAgentDevicePolicyProps>(
isConfirmed,
isLoading,
isHeterogeneous,
+ privateDeviceBlockedReason,
+ privateWorkspaceDevices,
publicWorkspaceDevices,
renderDeviceLabel,
renderTargetLabel,
@@ -314,7 +356,7 @@ const WorkspaceAgentDevicePolicy = memo<WorkspaceAgentDevicePolicyProps>(
const selectedTarget = resolveExecutionTargetSelection({
boundDeviceId: agencyConfig?.boundDeviceId,
configuredTarget: agencyConfig?.executionTarget,
- devices: publicWorkspaceDevices,
+ devices: selectableDevices,
isHeterogeneous,
});
const selectedValue = selectedTarget
@@ -353,7 +395,7 @@ const WorkspaceAgentDevicePolicy = memo<WorkspaceAgentDevicePolicyProps>(
const selection = parseExecutionTargetValue(option.value);
if (!selection) return option.label;
if (selection.target === 'device') {
- const device = publicWorkspaceDevices.find(
+ const device = selectableDevices.find(
(item) => item.deviceId === selection.deviceId,
);
return device ? renderDeviceLabel(device, true) : option.label;