Skip to content

Commit e83fa3a

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 1a5ef79 commit e83fa3a

21 files changed

Lines changed: 623 additions & 6 deletions

‎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: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { peerLinkHealth } from "@t3tools/client-runtime/state/peerLinks";
2+
import { AuthAccessReadScope, 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 { useEnvironmentScope } from "../../state/session";
11+
import { SettingsSection } from "../settings/components/SettingsSection";
12+
13+
/**
14+
* The environments one connected environment links to. Listing them needs
15+
* access:read, which a phone usually lacks, so this shows only for a session
16+
* granted it; links are made from a desktop or `t3 environment link`, and
17+
* revoked from the linked environment's Connections.
18+
*/
19+
export function LinkedEnvironmentsSection(props: {
20+
readonly environmentId: EnvironmentId;
21+
readonly environmentLabel: string;
22+
}) {
23+
const config = useEnvironmentServerConfig(props.environmentId);
24+
const canRead = useEnvironmentScope(props.environmentId, AuthAccessReadScope);
25+
const supported = canRead && config?.environment.capabilities.peerLinks === true;
26+
const links = useEnvironmentQuery(
27+
supported ? peerLinkEnvironment.list({ environmentId: props.environmentId, input: {} }) : null,
28+
);
29+
if (!supported || links.error || !links.data || links.data.links.length === 0) return null;
30+
const now = DateTime.nowUnsafe();
31+
return (
32+
<View className="mt-5 gap-3">
33+
<SettingsSection title={`Linked from ${props.environmentLabel}`}>
34+
{links.data.links.map((link) => {
35+
const health = peerLinkHealth(link, now);
36+
const status =
37+
health.kind === "expired"
38+
? "Expired. Link it again with a new pairing code."
39+
: health.kind === "unreachable"
40+
? (health.detail ?? "Not answering right now.")
41+
: health.kind === "failing"
42+
? health.detail
43+
: health.expiresInDays !== null
44+
? `Expires in ${health.expiresInDays} ${health.expiresInDays === 1 ? "day" : "days"}`
45+
: "Reachable";
46+
return (
47+
<View key={link.environmentId} className="gap-0.5 p-4">
48+
<Text className="text-base font-t3-bold text-foreground">{link.label}</Text>
49+
<Text
50+
className={
51+
health.kind === "reachable" && health.expiresInDays === null
52+
? "text-xs text-foreground-muted"
53+
: "text-xs text-danger-foreground"
54+
}
55+
numberOfLines={2}
56+
>
57+
{status}
58+
</Text>
59+
</View>
60+
);
61+
})}
62+
</SettingsSection>
63+
</View>
64+
);
65+
}

‎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/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,
@@ -82,8 +81,6 @@ export const RPC_REQUIRED_SCOPES = {
8281
[WS_METHODS.serverRemoveKeybinding]: AuthSettingsWriteScope,
8382
[WS_METHODS.serverGetSettings]: AuthOrchestrationReadScope,
8483
[WS_METHODS.peerLinksList]: AuthAccessReadScope,
85-
[WS_METHODS.peerLinksLink]: AuthAccessWriteScope,
86-
[WS_METHODS.peerLinksUnlink]: AuthAccessWriteScope,
8784
[WS_METHODS.serverUpdateSettings]: AuthSettingsWriteScope,
8885
[WS_METHODS.serverSearchAcpRegistry]: AuthOrchestrationReadScope,
8986
[WS_METHODS.serverPrepareAcpRegistryAgent]: AuthProvidersManageScope,

‎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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ import {
9595
formatDesktopSshTarget,
9696
} from "./EnvironmentRow";
9797
import { FoldedSettingsSection } from "./FoldedSettingsSection";
98+
import { LinkedEnvironmentsSettings } from "./LinkedEnvironmentsSettings";
99+
import { usePeerLinkHosts } from "~/state/peerLinks";
98100
import { LoadBalancingSettings } from "./LoadBalancingSettings";
99101
import { GitHubRoutingSettings } from "./GitHubRoutingSettings";
100102
import { Input } from "../ui/input";
@@ -2094,6 +2096,7 @@ export function ConnectionsSettings() {
20942096
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
20952097
const { environments } = useEnvironments();
20962098
const primaryEnvironment = usePrimaryEnvironment();
2099+
const peerLinkHosts = usePeerLinkHosts();
20972100
const connectPairing = useAtomCommand(connectPairingAtom, { reportFailure: false });
20982101
const connectSshEnvironment = useAtomCommand(connectSshEnvironmentAtom, {
20992102
reportFailure: false,
@@ -4209,6 +4212,14 @@ export function ConnectionsSettings() {
42094212
}}
42104213
/>
42114214
) : null}
4215+
{peerLinkHosts.map((environment, index) => (
4216+
<LinkedEnvironmentsSettings
4217+
key={environment.environmentId}
4218+
environmentId={environment.environmentId}
4219+
environmentLabel={peerLinkHosts.length > 1 ? environment.label : null}
4220+
isSearchTarget={index === 0}
4221+
/>
4222+
))}
42124223
<LoadBalancingSettings environments={loadBalancingEnvironments} />
42134224
<GitHubRoutingSettings environments={loadBalancingEnvironments} />
42144225
</SettingsPageContainer>

0 commit comments

Comments
 (0)