Skip to content

Commit 78c084a

Browse files
fix(connections): reset pairing forms and refresh mobile link status
1 parent 1aac2ec commit 78c084a

9 files changed

Lines changed: 51 additions & 50 deletions

File tree

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,15 @@ export function ConnectionsRouteScreen() {
7070
onSetEnabled={onSetEnvironmentEnabled}
7171
onUpdate={onUpdateEnvironment}
7272
/>
73-
{connectedEnvironments.map((environment) => (
74-
<LinkedEnvironmentsSection
75-
key={environment.environmentId}
76-
environmentId={environment.environmentId}
77-
environmentLabel={environment.environmentLabel}
78-
/>
79-
))}
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+
))}
8082
<PullRequestRoutingSettings />
8183
</ScrollView>
8284
</View>

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

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { peerLinkHealth } from "@t3tools/client-runtime/state/peerLinks";
2+
import { useFocusEffect } from "@react-navigation/native";
23
import { AuthAccessReadScope, type EnvironmentId } from "@t3tools/contracts";
34
import * as DateTime from "effect/DateTime";
4-
import { View } from "react-native";
5+
import { useCallback, useState } from "react";
6+
import { AppState, View } from "react-native";
57

68
import { AppText as Text } from "../../components/ui/AppText";
79
import { useEnvironmentServerConfig } from "../../state/entities";
@@ -10,12 +12,6 @@ import { useEnvironmentQuery } from "../../state/query";
1012
import { useEnvironmentScope } from "../../state/session";
1113
import { SettingsSection } from "../settings/components/SettingsSection";
1214

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-
*/
1915
export function LinkedEnvironmentsSection(props: {
2016
readonly environmentId: EnvironmentId;
2117
readonly environmentLabel: string;
@@ -26,8 +22,25 @@ export function LinkedEnvironmentsSection(props: {
2622
const links = useEnvironmentQuery(
2723
supported ? peerLinkEnvironment.list({ environmentId: props.environmentId, input: {} }) : null,
2824
);
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+
);
2942
if (!supported || links.error || !links.data || links.data.links.length === 0) return null;
30-
const now = DateTime.nowUnsafe();
43+
const now = DateTime.makeUnsafe(nowMs);
3144
return (
3245
<View className="mt-5 gap-3">
3346
<SettingsSection title={`Linked from ${props.environmentLabel}`}>

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ function ConnectAgentHeading({
279279
);
280280
}
281281

282-
/** One choice in a picker of what an outside agent, or a linked environment, may do. */
283282
export function AccessOption({
284283
access,
285284
selected,

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ interface ChatHeaderProps {
4646
activeThreadEnvironmentId: EnvironmentId;
4747
activeThreadId: ThreadId;
4848
activeThreadTitle: string;
49-
/** The linked environment that started this thread, shown beside the title. */
5049
activeThreadLinkOrigin?: string | null | undefined;
5150
isServerThread: boolean;
5251
activeProject: EnvironmentProject | null;
@@ -416,8 +415,7 @@ export const ChatHeader = memo(function ChatHeader({
416415
From {activeThreadLinkOrigin}
417416
</TooltipTrigger>
418417
<TooltipPopup side="top">
419-
Started by an agent on {activeThreadLinkOrigin} through a linked environment. It can
420-
change only threads that link started here.
418+
Started by an agent on {activeThreadLinkOrigin} through a linked environment.
421419
</TooltipPopup>
422420
</Tooltip>
423421
) : null}

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

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { ConnectionStatusDot } from "../ConnectionStatusDot";
1818
import { Button } from "../ui/button";
1919
import {
2020
Dialog,
21+
DialogClose,
2122
DialogDescription,
2223
DialogFooter,
2324
DialogHeader,
@@ -30,19 +31,13 @@ import { Input } from "../ui/input";
3031
import { RadioGroup } from "../ui/radio-group";
3132
import { stackedThreadToast, toastManager } from "../ui/toast";
3233
import { ITEM_ROW_CLASSNAME, ITEM_ROW_INNER_CLASSNAME } from "./itemRows";
33-
import { SettingsRow, SettingsSection, useRelativeTimeTick } from "./settingsLayout";
34+
import { SettingsRow, SettingsSection } from "./settingsLayout";
35+
import { useNowMinute } from "../../hooks/useNowMinute";
3436
import { searchableSetting } from "./settingsSearch";
3537

3638
const failureToast = (title: string, description: string) =>
3739
toastManager.add(stackedThreadToast({ type: "error", title, description }));
3840

39-
/**
40-
* Other environments this one links to, so its agents can work there. Each
41-
* link is an outside agent session on the other environment, revoked from
42-
* that environment's own Connections. `environmentLabel` names the linking
43-
* environment when several are listed; only the first section is the search
44-
* target.
45-
*/
4641
export function LinkedEnvironmentsSettings({
4742
environmentId,
4843
environmentLabel,
@@ -90,8 +85,8 @@ function LinkedEnvironmentRow({
9085
readonly environmentId: EnvironmentId;
9186
readonly link: PeerLinkSummary;
9287
}) {
93-
const nowMs = useRelativeTimeTick(60_000);
94-
const health = peerLinkHealth(link, DateTime.makeUnsafe(nowMs));
88+
const nowMinute = useNowMinute();
89+
const health = peerLinkHealth(link, DateTime.makeUnsafe(nowMinute));
9590
const unlink = useAtomCommand(peerLinkEnvironment.unlink, { label: "unlink environment" });
9691
const canUnlink = useAtomValue(peerLinkEnvironment.unlink.permissionAtom(environmentId));
9792
const [busy, setBusy] = useState(false);
@@ -169,10 +164,13 @@ function LinkEnvironmentAction({ environmentId }: { readonly environmentId: Envi
169164
const formId = useId();
170165
const accessLabelId = `${formId}-access`;
171166
const link = useAtomCommand(peerLinkEnvironment.link, { label: "link environment" });
172-
const reset = () => {
173-
setUrl("");
174-
setPairingCode("");
175-
setAccess("approval-required");
167+
const handleOpenChange = (next: boolean) => {
168+
setOpen(next);
169+
if (!next) {
170+
setUrl("");
171+
setPairingCode("");
172+
setAccess("approval-required");
173+
}
176174
};
177175
const submit = async () => {
178176
setBusy(true);
@@ -183,8 +181,7 @@ function LinkEnvironmentAction({ environmentId }: { readonly environmentId: Envi
183181
setBusy(false);
184182
if (result._tag === "Success") {
185183
toastManager.add({ type: "success", title: `Linked ${result.value.label}` });
186-
reset();
187-
setOpen(false);
184+
handleOpenChange(false);
188185
} else if (!isAtomCommandInterrupted(result)) {
189186
failureToast("Could not link the environment", String(squashAtomCommandFailure(result)));
190187
}
@@ -193,10 +190,8 @@ function LinkEnvironmentAction({ environmentId }: { readonly environmentId: Envi
193190
<Dialog
194191
open={open}
195192
onOpenChange={(next) => {
196-
// A link that finishes after a close would still be made, and would close a reopened form.
197193
if (!next && busy) return;
198-
setOpen(next);
199-
if (!next) reset();
194+
handleOpenChange(next);
200195
}}
201196
>
202197
<DialogTrigger
@@ -254,6 +249,7 @@ function LinkEnvironmentAction({ environmentId }: { readonly environmentId: Envi
254249
</span>
255250
<RadioGroup
256251
aria-labelledby={accessLabelId}
252+
disabled={busy}
257253
value={access}
258254
onValueChange={(value) => setAccess(value as AuthMcpClientAccess)}
259255
>
@@ -262,16 +258,17 @@ function LinkEnvironmentAction({ environmentId }: { readonly environmentId: Envi
262258
))}
263259
</RadioGroup>
264260
<p className="text-xs text-muted-foreground">
265-
An agent here never gets more there than its own mode here either. Threads it starts
266-
there cannot change that environment's own threads, projects or settings.
261+
An agent never gets more access there than its own mode here. Below full access, it
262+
can change only threads this link started, not that environment's own threads,
263+
projects or settings.
267264
</p>
268265
</div>
269266
</form>
270267
</DialogPanel>
271268
<DialogFooter variant="bare">
272-
<Button variant="outline" type="button" disabled={busy} onClick={() => setOpen(false)}>
269+
<DialogClose disabled={busy} render={<Button variant="outline" type="button" />}>
273270
Cancel
274-
</Button>
271+
</DialogClose>
275272
<Button
276273
form={formId}
277274
type="submit"

‎apps/web/src/components/settings/settingsSearch.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ export interface SettingsSearchItem {
6565
readonly localEnvironmentOnly?: boolean;
6666
readonly wslAvailableOnly?: boolean;
6767
readonly managedTunnelOnly?: boolean;
68-
// Its section only renders for a connected environment with peer links that
69-
// lets this session read its links.
7068
readonly peerLinksOnly?: boolean;
7169
readonly secondary?: boolean;
7270
readonly requiresThreadAutoSettlement?: boolean;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { useEnvironmentsWithScope } from "./session";
77

88
export const peerLinkEnvironment = createPeerLinkEnvironmentAtoms(connectionAtomRuntime);
99

10-
/** Connected environments whose links this session may see, in catalog order. */
1110
export function usePeerLinkHosts() {
1211
const { environments } = useEnvironments();
1312
const supported = environments.filter(

‎packages/client-runtime/src/state/models.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ export interface EnvironmentThreadShell {
147147
readonly worktreePath: string | null;
148148
readonly lineage: OrchestrationV2ThreadShell["lineage"];
149149
readonly forkedFrom: OrchestrationV2ThreadShell["forkedFrom"];
150-
/** The linked environment that started this thread here, when one did. */
151150
readonly linkOrigin: OrchestrationV2ThreadShell["linkOrigin"] | null;
152151
readonly activeProviderThreadId: OrchestrationV2ThreadShell["activeProviderThreadId"];
153152
readonly latestRun: ThreadRunSummary | null;

‎packages/client-runtime/src/state/peerLinks.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { Atom } from "effect/reactivity";
77
import type { EnvironmentRegistry } from "../connection/registry.ts";
88
import { createEnvironmentRpcCommand, createEnvironmentRpcQueryAtomFamily } from "./runtime.ts";
99

10-
/** Links to other environments, kept by one environment's server. */
1110
export function createPeerLinkEnvironmentAtoms<R, E>(
1211
runtime: Atom.AtomRuntime<EnvironmentRegistry | R, E>,
1312
) {
@@ -34,7 +33,6 @@ export function createPeerLinkEnvironmentAtoms<R, E>(
3433
};
3534
}
3635

37-
/** Links expire after 30 days and cannot be renewed yet, so warn this long before. */
3836
const EXPIRY_WARNING_DAYS = 5;
3937

4038
export type PeerLinkHealth =
@@ -44,8 +42,6 @@ export type PeerLinkHealth =
4442
| { readonly kind: "expired" };
4543

4644
/**
47-
* What a link's row says about it. `expiresInDays` is set only inside the
48-
* warning window, while the link still works but has to be renewed soon.
4945
* Listing only checks that the peer answers, so a link whose last call failed
5046
* (the peer revoked it, say) is `failing` with the recorded reason; the next
5147
* successful call clears it.

0 commit comments

Comments
 (0)