Skip to content

Commit a6676f9

Browse files
feat(web,mobile): linked environments in Connections (#16698)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 6918c35 commit a6676f9

20 files changed

Lines changed: 684 additions & 6 deletions

‎apps/mobile/src/features/connection/ConnectionsRouteScreen.tsx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { AndroidScreenHeader } from "../../components/ui/AndroidScreenHeader";
1111
import { useRemoteConnections } from "../../state/use-remote-environment-registry";
1212
import { LocalEnvironmentList } from "./LocalEnvironmentList";
1313
import { PullRequestRoutingSettings } from "./PullRequestRoutingSettings";
14+
import { LinkedEnvironmentsSection } from "./LinkedEnvironmentsSection";
1415

1516
export function ConnectionsRouteScreen() {
1617
const {
@@ -69,6 +70,15 @@ export function ConnectionsRouteScreen() {
6970
onSetEnabled={onSetEnvironmentEnabled}
7071
onUpdate={onUpdateEnvironment}
7172
/>
73+
{connectedEnvironments
74+
.filter((environment) => environment.connectionState === "connected")
75+
.map((environment) => (
76+
<LinkedEnvironmentsSection
77+
key={environment.environmentId}
78+
environmentId={environment.environmentId}
79+
environmentLabel={environment.environmentLabel}
80+
/>
81+
))}
7282
<PullRequestRoutingSettings />
7383
</ScrollView>
7484
</View>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { peerLinkHealth } from "@t3tools/client-runtime/state/peerLinks";
2+
import { useFocusEffect } from "@react-navigation/native";
3+
import { AuthAccessReadScope, type EnvironmentId } from "@t3tools/contracts";
4+
import * as DateTime from "effect/DateTime";
5+
import { useCallback, useState } from "react";
6+
import { AppState, View } from "react-native";
7+
8+
import { AppText as Text } from "../../components/ui/AppText";
9+
import { useEnvironmentServerConfig } from "../../state/entities";
10+
import { peerLinkEnvironment } from "../../state/peerLinks";
11+
import { useEnvironmentQuery } from "../../state/query";
12+
import { useEnvironmentScope } from "../../state/session";
13+
import { SettingsSection } from "../settings/components/SettingsSection";
14+
15+
export function LinkedEnvironmentsSection(props: {
16+
readonly environmentId: EnvironmentId;
17+
readonly environmentLabel: string;
18+
}) {
19+
const config = useEnvironmentServerConfig(props.environmentId);
20+
const canRead = useEnvironmentScope(props.environmentId, AuthAccessReadScope);
21+
const supported = canRead && config?.environment.capabilities.peerLinks === true;
22+
const links = useEnvironmentQuery(
23+
supported ? peerLinkEnvironment.list({ environmentId: props.environmentId, input: {} }) : null,
24+
);
25+
const [nowMs, setNowMs] = useState(Date.now);
26+
const hasLinks = supported && (links.data?.links.length ?? 0) > 0;
27+
useFocusEffect(
28+
useCallback(() => {
29+
if (!hasLinks) return;
30+
const updateNow = () => setNowMs(Date.now());
31+
updateNow();
32+
const timer = setInterval(updateNow, 60_000);
33+
const subscription = AppState.addEventListener("change", (state) => {
34+
if (state === "active") updateNow();
35+
});
36+
return () => {
37+
clearInterval(timer);
38+
subscription.remove();
39+
};
40+
}, [hasLinks]),
41+
);
42+
if (!supported || links.error || !links.data || links.data.links.length === 0) return null;
43+
const now = DateTime.makeUnsafe(nowMs);
44+
return (
45+
<View className="mt-5 gap-3">
46+
<SettingsSection title={`Linked from ${props.environmentLabel}`}>
47+
{links.data.links.map((link) => {
48+
const health = peerLinkHealth(link, now);
49+
const status =
50+
health.kind === "expired"
51+
? "Expired. Link it again with a new pairing code."
52+
: health.kind === "unreachable"
53+
? (health.detail ?? "Not answering right now.")
54+
: health.kind === "failing"
55+
? health.detail
56+
: health.expiresInDays !== null
57+
? `Expires in ${health.expiresInDays} ${health.expiresInDays === 1 ? "day" : "days"}`
58+
: "Reachable";
59+
return (
60+
<View key={link.environmentId} className="gap-0.5 p-4">
61+
<Text className="text-base font-t3-bold text-foreground">{link.label}</Text>
62+
<Text
63+
className={
64+
health.kind === "reachable" && health.expiresInDays === null
65+
? "text-xs text-foreground-muted"
66+
: "text-xs text-danger-foreground"
67+
}
68+
numberOfLines={2}
69+
>
70+
{status}
71+
</Text>
72+
</View>
73+
);
74+
})}
75+
</SettingsSection>
76+
</View>
77+
);
78+
}

‎apps/mobile/src/features/threads/ThreadRouteScreen.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ function ThreadRouteContent(
489489
const headerSubtitle = [
490490
selectedThreadProject?.title ?? null,
491491
selectedEnvironmentConnection?.environmentLabel ?? null,
492+
selectedThread?.linkOrigin ? `From ${selectedThread.linkOrigin.label}` : null,
492493
]
493494
.filter(Boolean)
494495
.join(" · ");

‎apps/mobile/src/state/peerLinks.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { createPeerLinkEnvironmentAtoms } from "@t3tools/client-runtime/state/peerLinks";
2+
3+
import { connectionAtomRuntime } from "../connection/runtime";
4+
5+
export const peerLinkEnvironment = createPeerLinkEnvironmentAtoms(connectionAtomRuntime);

‎apps/server/src/auth/RpcAuthorization.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
authScopeRequiredResponse,
66
AssetCreateUrlInput,
77
AuthAccessReadScope,
8-
AuthAccessWriteScope,
98
ServerSettingsPatch,
109
ProviderInstanceMutation,
1110
requiredScopesForServerSettingsPatch,
@@ -88,8 +87,6 @@ export const RPC_REQUIRED_SCOPES = {
8887
[WS_METHODS.serverGetDatabaseStorage]: AuthOrchestrationReadScope,
8988
[WS_METHODS.serverGetSettings]: AuthOrchestrationReadScope,
9089
[WS_METHODS.peerLinksList]: AuthAccessReadScope,
91-
[WS_METHODS.peerLinksLink]: AuthAccessWriteScope,
92-
[WS_METHODS.peerLinksUnlink]: AuthAccessWriteScope,
9390
[WS_METHODS.serverUpdateSettings]: AuthSettingsWriteScope,
9491
[WS_METHODS.serverSearchAcpRegistry]: AuthOrchestrationReadScope,
9592
[WS_METHODS.serverPrepareAcpRegistryAgent]: AuthProvidersManageScope,

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3159,6 +3159,7 @@ export default function ChatView(props: ChatViewProps) {
31593159
activeThreadId={activeThread.id}
31603160
isServerThread={isServerThread}
31613161
activeThreadTitle={activeThread.title}
3162+
activeThreadLinkOrigin={activeThreadShell?.linkOrigin?.label ?? null}
31623163
activeProject={activeProject ?? null}
31633164
parentThreadLink={parentThreadLink}
31643165
onOpenThread={onOpenRelatedThreadStable}

‎apps/web/src/components/auth/ConnectAgentSurface.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { RadioGroup } from "../ui/radio-group";
2424
import { Spinner } from "../ui/spinner";
2525
import { AuthSurfaceShell } from "./AuthSurfaceShell";
2626

27-
const accessConfig: Record<
27+
export const accessConfig: Record<
2828
AuthMcpClientAccess,
2929
{ readonly label: string; readonly description: string; readonly icon: LucideIcon }
3030
> = {
@@ -279,7 +279,7 @@ function ConnectAgentHeading({
279279
);
280280
}
281281

282-
function AccessOption({
282+
export function AccessOption({
283283
access,
284284
selected,
285285
}: {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
type MouseEvent as ReactMouseEvent,
2020
} from "react";
2121
import { isTrailingDoubleClick } from "../Sidebar.logic";
22+
import { Badge } from "../ui/badge";
2223
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
2324
import { toastManager } from "../ui/toast";
2425
import { useThreadActionMenu } from "~/hooks/useThreadActionMenu";
@@ -45,6 +46,7 @@ interface ChatHeaderProps {
4546
activeThreadEnvironmentId: EnvironmentId;
4647
activeThreadId: ThreadId;
4748
activeThreadTitle: string;
49+
activeThreadLinkOrigin?: string | null | undefined;
4850
isServerThread: boolean;
4951
activeProject: EnvironmentProject | null;
5052
parentThreadLink: { threadId: ThreadId; title: string } | null;
@@ -70,6 +72,7 @@ export const ChatHeader = memo(function ChatHeader({
7072
activeThreadEnvironmentId,
7173
activeThreadId,
7274
activeThreadTitle,
75+
activeThreadLinkOrigin,
7376
isServerThread,
7477
activeProject,
7578
parentThreadLink,
@@ -406,6 +409,16 @@ export const ChatHeader = memo(function ChatHeader({
406409
<TooltipPopup side="top">{activeThreadTitle}</TooltipPopup>
407410
</Tooltip>
408411
)}
412+
{renamingTitle === null && activeThreadLinkOrigin ? (
413+
<Tooltip>
414+
<TooltipTrigger render={<Badge variant="info" size="sm" />}>
415+
From {activeThreadLinkOrigin}
416+
</TooltipTrigger>
417+
<TooltipPopup side="top">
418+
Started by an agent on {activeThreadLinkOrigin} through a linked environment.
419+
</TooltipPopup>
420+
</Tooltip>
421+
) : null}
409422
</WorkspaceBreadcrumbItem>
410423
</WorkspaceBreadcrumb>
411424
{isServerThread ? <GuestShareIndicator threadRef={activeThreadRef} /> : null}

‎apps/web/src/components/settings/ConnectionsSettings.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import { LocalEnvironmentSetting } from "./LocalEnvironmentSetting";
3636
import { searchableSetting } from "./settingsSearch";
3737
import { EnvironmentIconMenu } from "./EnvironmentIconPicker";
3838
import { FoldedSettingsSection } from "./FoldedSettingsSection";
39+
import { LinkedEnvironmentsSettings } from "./LinkedEnvironmentsSettings";
40+
import { usePeerLinkHosts } from "~/state/peerLinks";
3941
import { LoadBalancingSettings } from "./LoadBalancingSettings";
4042
import { PullRequestRoutingSettings } from "./PullRequestRoutingSettings";
4143
import { Input } from "../ui/input";
@@ -156,6 +158,7 @@ export function ConnectionsSettings({ view }: { readonly view: "environments" |
156158
const desktopBridge = window.desktopBridge;
157159
const { environments } = useEnvironments();
158160
const primaryEnvironment = usePrimaryEnvironment();
161+
const peerLinkHosts = usePeerLinkHosts();
159162
const removeEnvironment = useAtomCommand(environmentCatalog.remove, { reportFailure: false });
160163
const setEnvironmentEnabled = useAtomCommand(environmentCatalog.setEnabled, {
161164
reportFailure: false,
@@ -1533,6 +1536,14 @@ export function ConnectionsSettings({ view }: { readonly view: "environments" |
15331536
}}
15341537
/>
15351538
) : null}
1539+
{peerLinkHosts.map((environment, index) => (
1540+
<LinkedEnvironmentsSettings
1541+
key={environment.environmentId}
1542+
environmentId={environment.environmentId}
1543+
environmentLabel={peerLinkHosts.length > 1 ? environment.label : null}
1544+
isSearchTarget={index === 0}
1545+
/>
1546+
))}
15361547
<LoadBalancingSettings environments={loadBalancingEnvironments} />
15371548
<PullRequestRoutingSettings environments={loadBalancingEnvironments} />
15381549
</SettingsPageContainer>

0 commit comments

Comments
 (0)