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(desktop): upload a dropped file while the device gateway is off (#23101)

LiJian22139702242d
diff --git a/src/features/Conversation/useLocalPathReference.test.ts b/src/features/Conversation/useLocalPathReference.test.ts
index 23428a61955..7c6f357b52b 100644
--- a/src/features/Conversation/useLocalPathReference.test.ts
+++ b/src/features/Conversation/useLocalPathReference.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
-import { canReadLocalFileReferences } from './useLocalPathReference';
+import { canReadLocalFileReferences, canRuntimeReachLocalMachine } from './useLocalPathReference';
const base = {
isHeterogeneous: false,
@@ -41,3 +41,21 @@ describe('canReadLocalFileReferences', () => {
).toBe(true);
});
});
+
+describe('canRuntimeReachLocalMachine', () => {
+ it('uploads instead of referencing a path when a server-run agent has no device gateway', () => {
+ expect(canRuntimeReachLocalMachine({ gatewayConnected: false, runtime: 'gateway' })).toBe(
+ false,
+ );
+ expect(canRuntimeReachLocalMachine({ gatewayConnected: true, runtime: 'gateway' })).toBe(true);
+ });
+
+ it('lets in-process runs read the path whether or not the gateway is connected', () => {
+ expect(canRuntimeReachLocalMachine({ gatewayConnected: false, runtime: 'hetero' })).toBe(true);
+ expect(canRuntimeReachLocalMachine({ gatewayConnected: false, runtime: 'client' })).toBe(true);
+ });
+
+ it('uploads when the runtime cannot be resolved', () => {
+ expect(canRuntimeReachLocalMachine({ gatewayConnected: true, runtime: undefined })).toBe(false);
+ });
+});
diff --git a/src/features/Conversation/useLocalPathReference.ts b/src/features/Conversation/useLocalPathReference.ts
index 4324f10f595..5c69a5dbb12 100644
--- a/src/features/Conversation/useLocalPathReference.ts
+++ b/src/features/Conversation/useLocalPathReference.ts
@@ -8,11 +8,16 @@ import {
canExecutionTargetReadLocalPaths,
resolveExecutionTarget,
} from '@/helpers/executionTarget';
+import { useIsGatewayModeEnabled } from '@/helpers/gatewayMode';
import { useEffectiveAgencyConfig } from '@/hooks/useEffectiveAgencyConfig';
import { useEffectiveWorkingDirectory } from '@/hooks/useEffectiveWorkingDirectory';
import { useAgentStore } from '@/store/agent';
import { agentByIdSelectors, chatConfigByIdSelectors } from '@/store/agent/selectors';
import { useChatStore } from '@/store/chat';
+import {
+ type AgentRuntimeType,
+ selectRuntimeType,
+} from '@/store/chat/slices/agentRun/actions/dispatch/agentDispatcher';
import { useElectronStore } from '@/store/electron';
/**
@@ -38,6 +43,33 @@ export const canReadLocalFileReferences = ({
return toolMode === 'custom' && pinnedPluginIds.includes(LocalSystemIdentifier);
};
+/**
+ * Whether the run can reach this machine's filesystem right now. An in-process
+ * run (`hetero` CLI spawn, `client` runtime) reads the desktop's disk directly.
+ * A `gateway` run executes on the server, which reaches this machine only through
+ * the device gateway: while the user has switched it off (or it dropped), the
+ * agent gets a path it cannot open, so the drop must upload the file instead.
+ * `undefined` = the runtime config is invalid and the run cannot start.
+ */
+export const canRuntimeReachLocalMachine = ({
+ gatewayConnected,
+ runtime,
+}: {
+ gatewayConnected: boolean;
+ runtime: AgentRuntimeType | undefined;
+}) => {
+ if (!runtime) return false;
+ return runtime !== 'gateway' || gatewayConnected;
+};
+
+const resolveRuntime = (ctx: Parameters<typeof selectRuntimeType>[0]) => {
+ try {
+ return selectRuntimeType(ctx);
+ } catch {
+ return undefined;
+ }
+};
+
/**
* Whether a drag-dropped local path should become a `<localFile>` reference for
* this agent's next run, plus the insert handler for the drop zone.
@@ -59,6 +91,9 @@ export const useLocalPathReference = (agentId: string, topicId?: string | null)
const workingDirectory = useEffectiveWorkingDirectory(agentId, { topicId });
const { agencyConfig, workspaceScoped } = useEffectiveAgencyConfig(agentId, { topicId });
const currentDeviceId = useElectronStore((s) => s.gatewayDeviceInfo?.deviceId);
+ const gatewayConnected = useElectronStore((s) => s.gatewayConnectionStatus === 'connected');
+ const isGatewayMode = useIsGatewayModeEnabled(agentId);
+ const isWorkspaceAgent = useAgentStore((s) => !!s.agentMap[agentId]?.workspaceId);
const executionTarget = resolveExecutionTarget(agencyConfig, {
clientExecutionAvailable: isDesktop,
isHetero: isHeterogeneous,
@@ -73,7 +108,18 @@ export const useLocalPathReference = (agentId: string, topicId?: string | null)
pinnedPluginIds,
toolMode,
}) &&
- canExecutionTargetReadLocalPaths(executionTarget, agencyConfig, currentDeviceId);
+ canExecutionTargetReadLocalPaths(executionTarget, agencyConfig, currentDeviceId) &&
+ canRuntimeReachLocalMachine({
+ gatewayConnected,
+ runtime: resolveRuntime({
+ boundDeviceId: agencyConfig?.boundDeviceId,
+ executionTarget: agencyConfig?.executionTarget,
+ heterogeneousProvider: agencyConfig?.heterogeneousProvider,
+ isGatewayMode,
+ isWorkspaceAgent,
+ workspaceScoped,
+ }),
+ });
const handleLocalPaths = useCallback((paths: DroppedLocalPath[]) => {
const editor = useChatStore.getState().mainInputEditor?.instance;