Skip to content

Commit 6d47e41

Browse files
feat(web,mobile): linked environments in Connections
Settings → Connections gains a Linked environments section, shown when the server supports peer links and the session may manage access: each link with whether it answers, its access, and a warning in its last five days, plus a Link dialog (address, pairing code, access) and Forget. Mobile lists a connected environment's links under Connections. A thread a linked environment started shows "From <label>" next to its title on web, and in the thread subtitle on mobile. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 4ccc714 commit 6d47e41

16 files changed

Lines changed: 505 additions & 2 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { AndroidScreenHeader } from "../../components/AndroidScreenHeader";
1010
import { useRemoteConnections } from "../../state/use-remote-environment-registry";
1111
import { LocalEnvironmentList } from "./LocalEnvironmentList";
1212
import { GitHubRoutingSettings } from "./GitHubRoutingSettings";
13+
import { LinkedEnvironmentsSection } from "./LinkedEnvironmentsSection";
1314

1415
export function ConnectionsRouteScreen() {
1516
const {
@@ -68,6 +69,13 @@ export function ConnectionsRouteScreen() {
6869
onSetEnabled={onSetEnvironmentEnabled}
6970
onUpdate={onUpdateEnvironment}
7071
/>
72+
{connectedEnvironments.map((environment) => (
73+
<LinkedEnvironmentsSection
74+
key={environment.environmentId}
75+
environmentId={environment.environmentId}
76+
environmentLabel={environment.environmentLabel}
77+
/>
78+
))}
7179
<GitHubRoutingSettings />
7280
</ScrollView>
7381
</View>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { peerLinkHealth } from "@t3tools/client-runtime/state/peerLinks";
2+
import type { EnvironmentId } from "@t3tools/contracts";
3+
import * as DateTime from "effect/DateTime";
4+
import { View } from "react-native";
5+
6+
import { AppText as Text } from "../../components/AppText";
7+
import { useEnvironmentServerConfig } from "../../state/entities";
8+
import { peerLinkEnvironment } from "../../state/peerLinks";
9+
import { useEnvironmentQuery } from "../../state/query";
10+
import { SettingsSection } from "../settings/components/SettingsSection";
11+
12+
/**
13+
* The environments one connected environment links to. Listing them needs
14+
* the administrative access a phone usually lacks, so this shows only when
15+
* the environment answers; links are made from a desktop or `t3 environment
16+
* link`, and revoked from the linked environment's Connections.
17+
*/
18+
export function LinkedEnvironmentsSection(props: {
19+
readonly environmentId: EnvironmentId;
20+
readonly environmentLabel: string;
21+
}) {
22+
const config = useEnvironmentServerConfig(props.environmentId);
23+
const supported = config?.environment.capabilities.peerLinks === true;
24+
const links = useEnvironmentQuery(
25+
supported ? peerLinkEnvironment.list({ environmentId: props.environmentId, input: {} }) : null,
26+
);
27+
if (!supported || links.error || !links.data || links.data.links.length === 0) return null;
28+
const now = DateTime.nowUnsafe();
29+
return (
30+
<View className="mt-5 gap-3">
31+
<SettingsSection title={`Linked from ${props.environmentLabel}`}>
32+
{links.data.links.map((link) => {
33+
const health = peerLinkHealth(link, now);
34+
const status =
35+
health.kind === "expired"
36+
? "Expired. Link it again with a new pairing code."
37+
: health.kind === "unreachable"
38+
? (health.detail ?? "Not answering right now.")
39+
: health.expiresInDays !== null
40+
? `Expires in ${health.expiresInDays} ${health.expiresInDays === 1 ? "day" : "days"}`
41+
: "Reachable";
42+
return (
43+
<View key={link.environmentId} className="gap-0.5 p-4">
44+
<Text className="text-base font-t3-bold text-foreground">{link.label}</Text>
45+
<Text
46+
className={
47+
health.kind === "reachable" && health.expiresInDays === null
48+
? "text-xs text-foreground-muted"
49+
: "text-xs text-danger-foreground"
50+
}
51+
numberOfLines={2}
52+
>
53+
{status}
54+
</Text>
55+
</View>
56+
);
57+
})}
58+
</SettingsSection>
59+
</View>
60+
);
61+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ function ThreadRouteContent(
504504
const headerSubtitle = [
505505
selectedThreadProject?.title ?? null,
506506
selectedEnvironmentConnection?.environmentLabel ?? null,
507+
selectedThread?.linkOrigin ? `From ${selectedThread.linkOrigin.label}` : null,
507508
]
508509
.filter(Boolean)
509510
.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/web/src/components/ChatView.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11217,6 +11217,7 @@ export default function ChatView(props: ChatViewProps) {
1121711217
activeThreadId={activeThread.id}
1121811218
isServerThread={isServerThread}
1121911219
activeThreadTitle={activeThread.title}
11220+
activeThreadLinkOrigin={activeThreadShell?.linkOrigin?.label ?? null}
1122011221
activeProject={activeProject ?? null}
1122111222
rightPanelOpen={inlineRightPanelOwnsTitleBar}
1122211223
onNewThreadInProject={handleNewThreadInActiveProject}

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

Lines changed: 3 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
> = {
@@ -298,7 +298,8 @@ function ConnectAgentHeading({
298298
);
299299
}
300300

301-
function AccessOption({
301+
/** One choice in a picker of what an outside agent, or a linked environment, may do. */
302+
export function AccessOption({
302303
access,
303304
selected,
304305
}: {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
type MouseEvent as ReactMouseEvent,
2222
} from "react";
2323
import { isTrailingDoubleClick } from "../Sidebar.logic";
24+
import { Badge } from "../ui/badge";
2425
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
2526
import { toastManager } from "../ui/toast";
2627
import { useThreadActionMenu } from "~/hooks/useThreadActionMenu";
@@ -42,6 +43,8 @@ interface ChatHeaderProps {
4243
activeThreadEnvironmentId: EnvironmentId;
4344
activeThreadId: ThreadId;
4445
activeThreadTitle: string;
46+
/** The linked environment that started this thread, shown beside the title. */
47+
activeThreadLinkOrigin?: string | null | undefined;
4548
/** Drafts have no server thread yet, so the title carries no action menu. */
4649
isServerThread: boolean;
4750
activeProject: EnvironmentProject | null;
@@ -75,6 +78,7 @@ export const ChatHeader = memo(function ChatHeader({
7578
activeThreadEnvironmentId,
7679
activeThreadId,
7780
activeThreadTitle,
81+
activeThreadLinkOrigin,
7882
isServerThread,
7983
activeProject,
8084
rightPanelOpen,
@@ -353,6 +357,17 @@ export const ChatHeader = memo(function ChatHeader({
353357
<TooltipPopup side="top">{activeThreadTitle}</TooltipPopup>
354358
</Tooltip>
355359
)}
360+
{renamingTitle === null && activeThreadLinkOrigin ? (
361+
<Tooltip>
362+
<TooltipTrigger render={<Badge variant="info" size="sm" />}>
363+
From {activeThreadLinkOrigin}
364+
</TooltipTrigger>
365+
<TooltipPopup side="top">
366+
Started by an agent on {activeThreadLinkOrigin} through a linked environment. It can
367+
change only threads that link started here.
368+
</TooltipPopup>
369+
</Tooltip>
370+
) : null}
356371
</WorkspaceBreadcrumbItem>
357372
</WorkspaceBreadcrumb>
358373
</div>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ import {
9595
formatDesktopSshTarget,
9696
} from "./EnvironmentRow";
9797
import { FoldedSettingsSection } from "./FoldedSettingsSection";
98+
import { LinkedEnvironmentsSettings } from "./LinkedEnvironmentsSettings";
9899
import { LoadBalancingSettings } from "./LoadBalancingSettings";
99100
import { GitHubRoutingSettings } from "./GitHubRoutingSettings";
100101
import { Input } from "../ui/input";
@@ -4209,6 +4210,11 @@ export function ConnectionsSettings() {
42094210
}}
42104211
/>
42114212
) : null}
4213+
{canManageLocalBackend &&
4214+
primaryEnvironmentId !== null &&
4215+
primaryServerConfig?.environment.capabilities.peerLinks === true ? (
4216+
<LinkedEnvironmentsSettings environmentId={primaryEnvironmentId} />
4217+
) : null}
42124218
<LoadBalancingSettings environments={loadBalancingEnvironments} />
42134219
<GitHubRoutingSettings environments={loadBalancingEnvironments} />
42144220
</SettingsPageContainer>

0 commit comments

Comments
 (0)