Skip to content

Commit e925dd6

Browse files
shivamhwpPR Batch Testerclaude
authored
fix(web): allow folder references on saved local desktop servers (#27785)
Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent e6e2ab0 commit e925dd6

3 files changed

Lines changed: 116 additions & 7 deletions

File tree

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ import { useMediaQuery } from "../../hooks/useMediaQuery";
261261
import { useSoftwareKeyboardOpen } from "../../hooks/useSoftwareKeyboardOpen";
262262
import { useStableCallback } from "../../hooks/useStableCallback";
263263
import { usePanelAnimationSettings } from "../../panelAnimations";
264-
import { readEnvironmentScope } from "../../state/session";
264+
import { readEnvironmentScope, readPreparedConnection } from "../../state/session";
265265
import type { ReviewCommentContext } from "../../reviewCommentContext";
266266
import { useComposerRestingTransition } from "./useComposerRestingTransition";
267267
import { ComposerCommandMenuLayer } from "./ComposerCommandMenuLayer";
@@ -2522,11 +2522,13 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
25222522
localEnvironmentDisabled: isLocalEnvironmentDisabled(),
25232523
environmentId,
25242524
primaryEnvironmentId,
2525+
connection: readPreparedConnection(environmentId),
2526+
isDesktopRenderer: window.desktopBridge !== undefined,
25252527
});
25262528
if (target === "remote") {
25272529
toastManager.add({
25282530
type: "error",
2529-
title: "Folders can only be referenced in the local desktop environment",
2531+
title: "Folders can only be referenced on a server running on this computer",
25302532
});
25312533
return;
25322534
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import {
2+
BearerConnectionTarget,
3+
RelayConnectionTarget,
4+
SshConnectionTarget,
5+
} from "@t3tools/client-runtime/connection";
6+
import { EnvironmentId } from "@t3tools/contracts";
7+
import { describe, expect, it } from "vite-plus/test";
8+
9+
import { folderDropTarget } from "./folderDrop";
10+
11+
const environmentId = EnvironmentId.make("saved-local");
12+
const base = { environmentId, label: "server" };
13+
const savedServer = (httpBaseUrl: string, connectionId = "saved-1") => ({
14+
target: new BearerConnectionTarget({ ...base, connectionId }),
15+
httpBaseUrl,
16+
});
17+
const thinClient = {
18+
localEnvironmentDisabled: true,
19+
environmentId,
20+
primaryEnvironmentId: null,
21+
isDesktopRenderer: true,
22+
};
23+
24+
describe("folderDropTarget", () => {
25+
it.each([
26+
[
27+
"the bundled primary",
28+
{
29+
...thinClient,
30+
localEnvironmentDisabled: false,
31+
primaryEnvironmentId: environmentId,
32+
connection: null,
33+
},
34+
"local",
35+
],
36+
[
37+
"a saved loopback server on desktop",
38+
{ ...thinClient, connection: savedServer("http://127.0.0.1:3773") },
39+
"local",
40+
],
41+
[
42+
"a saved LAN server",
43+
{ ...thinClient, connection: savedServer("http://192.168.1.20:3773") },
44+
"remote",
45+
],
46+
[
47+
"a saved loopback server in a browser",
48+
{ ...thinClient, isDesktopRenderer: false, connection: savedServer("http://localhost:3773") },
49+
"remote",
50+
],
51+
[
52+
"a desktop WSL backend",
53+
{ ...thinClient, connection: savedServer("http://127.0.0.1:3774", "local:wsl-ubuntu") },
54+
"remote",
55+
],
56+
[
57+
"an SSH forward on loopback",
58+
{
59+
...thinClient,
60+
connection: {
61+
target: new SshConnectionTarget({ ...base, connectionId: "ssh-1" }),
62+
httpBaseUrl: "http://127.0.0.1:41000",
63+
},
64+
},
65+
"remote",
66+
],
67+
[
68+
"a relay connection",
69+
{
70+
...thinClient,
71+
connection: {
72+
target: new RelayConnectionTarget(base),
73+
httpBaseUrl: "https://relay.t3.codes",
74+
},
75+
},
76+
"remote",
77+
],
78+
["an unprepared connection", { ...thinClient, connection: null }, "remote"],
79+
] as const)("targets %s", (_name, input, expected) => {
80+
expect(folderDropTarget(input)).toBe(expected);
81+
});
82+
});

‎apps/web/src/components/chat/folderDrop.ts‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,43 @@
1+
import type { PreparedConnection } from "@t3tools/client-runtime/connection";
12
import type { EnvironmentId } from "@t3tools/contracts";
23

4+
import { isDesktopLocalConnectionTarget } from "~/connection/desktopLocal";
5+
import { isLoopbackHostname } from "~/environments/primary/target";
6+
37
export function folderDropTarget(input: {
48
localEnvironmentDisabled: boolean;
59
environmentId: EnvironmentId;
610
primaryEnvironmentId: EnvironmentId | null;
11+
connection: Pick<PreparedConnection, "target" | "httpBaseUrl"> | null;
12+
isDesktopRenderer: boolean;
713
}): "local" | "remote" {
814
if (
9-
input.localEnvironmentDisabled ||
10-
input.primaryEnvironmentId === null ||
11-
input.environmentId !== input.primaryEnvironmentId
15+
!input.localEnvironmentDisabled &&
16+
input.primaryEnvironmentId !== null &&
17+
input.environmentId === input.primaryEnvironmentId
1218
) {
13-
return "remote";
19+
return "local";
20+
}
21+
return input.isDesktopRenderer &&
22+
input.connection !== null &&
23+
isSavedLoopbackConnection(input.connection)
24+
? "local"
25+
: "remote";
26+
}
27+
28+
// A direct saved connection to loopback shares the desktop's filesystem; WSL backends and SSH forwards do not.
29+
function isSavedLoopbackConnection({
30+
target,
31+
httpBaseUrl,
32+
}: Pick<PreparedConnection, "target" | "httpBaseUrl">): boolean {
33+
if (target._tag !== "BearerConnectionTarget" || isDesktopLocalConnectionTarget(target)) {
34+
return false;
35+
}
36+
try {
37+
return isLoopbackHostname(new URL(httpBaseUrl).hostname);
38+
} catch {
39+
return false;
1440
}
15-
return "local";
1641
}
1742

1843
export function resolveDroppedFolderPath(

0 commit comments

Comments
 (0)