Skip to content

Commit 8250c90

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-26136
2 parents d437f84 + 1cf14a4 commit 8250c90

253 files changed

Lines changed: 19536 additions & 1119 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
506 Bytes
Loading

‎apps/mobile/scripts/sync-context-chip-icons.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const lucideIcons = [
4343
"message-circle",
4444
"messages-square",
4545
"mouse-pointer-click",
46+
"server",
4647
"terminal",
4748
];
4849

‎apps/mobile/src/components/ComposerContextSheet.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ export function ComposerContextSheet(props: {
324324
) : null}
325325
</View>
326326
) : null}
327+
{record.kind === "environment" ? (
328+
<ContextField label="Machine" value={record.label} />
329+
) : null}
327330
{record.kind === "skill" ? (
328331
<View className="gap-3">
329332
<ContextField label="Skill" value={record.name} />

‎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: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { offersLinkedEnvironments } from "@t3tools/client-runtime/link-request";
2+
import { peerLinkHealth } from "@t3tools/client-runtime/state/peerLinks";
3+
import { useFocusEffect } from "@react-navigation/native";
4+
import { AuthAccessReadScope, type EnvironmentId } from "@t3tools/contracts";
5+
import * as DateTime from "effect/DateTime";
6+
import { useCallback, useState } from "react";
7+
import { AppState, View } from "react-native";
8+
9+
import { AppText as Text } from "../../components/ui/AppText";
10+
import { useEnvironmentServerConfig } from "../../state/entities";
11+
import { peerLinkEnvironment } from "../../state/peerLinks";
12+
import { useEnvironmentQuery } from "../../state/query";
13+
import { useEnvironmentScope } from "../../state/session";
14+
import { SettingsSection } from "../settings/components/SettingsSection";
15+
16+
export function LinkedEnvironmentsSection(props: {
17+
readonly environmentId: EnvironmentId;
18+
readonly environmentLabel: string;
19+
}) {
20+
const config = useEnvironmentServerConfig(props.environmentId);
21+
const canRead = useEnvironmentScope(props.environmentId, AuthAccessReadScope);
22+
const supported = canRead && offersLinkedEnvironments(config);
23+
const links = useEnvironmentQuery(
24+
supported ? peerLinkEnvironment.list({ environmentId: props.environmentId, input: {} }) : null,
25+
);
26+
const [nowMs, setNowMs] = useState(Date.now);
27+
const hasLinks = supported && (links.data?.links.length ?? 0) > 0;
28+
useFocusEffect(
29+
useCallback(() => {
30+
if (!hasLinks) return;
31+
const updateNow = () => setNowMs(Date.now());
32+
updateNow();
33+
const timer = setInterval(updateNow, 60_000);
34+
const subscription = AppState.addEventListener("change", (state) => {
35+
if (state === "active") updateNow();
36+
});
37+
return () => {
38+
clearInterval(timer);
39+
subscription.remove();
40+
};
41+
}, [hasLinks]),
42+
);
43+
if (!supported || links.error || !links.data || links.data.links.length === 0) return null;
44+
const now = DateTime.makeUnsafe(nowMs);
45+
return (
46+
<View className="mt-5 gap-3">
47+
<SettingsSection title={`Linked from ${props.environmentLabel}`}>
48+
{links.data.links.map((link) => {
49+
const health = peerLinkHealth(link, now);
50+
const status =
51+
health.kind === "expired"
52+
? "Expired. Link it again with a new pairing code."
53+
: health.kind === "unreachable"
54+
? (health.detail ?? "Not answering right now.")
55+
: health.kind === "failing"
56+
? health.detail
57+
: health.expiresInDays !== null
58+
? `Expires in ${health.expiresInDays} ${health.expiresInDays === 1 ? "day" : "days"}`
59+
: "Reachable";
60+
return (
61+
<View key={link.environmentId} className="gap-0.5 p-4">
62+
<Text className="text-base font-t3-bold text-foreground">{link.label}</Text>
63+
<Text
64+
className={
65+
health.kind === "reachable" && health.expiresInDays === null
66+
? "text-xs text-foreground-muted"
67+
: "text-xs text-danger-foreground"
68+
}
69+
numberOfLines={2}
70+
>
71+
{status}
72+
</Text>
73+
</View>
74+
);
75+
})}
76+
</SettingsSection>
77+
</View>
78+
);
79+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import type { EnvironmentId } from "@t3tools/contracts";
2+
import { View } from "react-native";
3+
4+
import { EmptyState } from "../../components/ui/EmptyState";
5+
import type { useAttachmentDocument } from "../../lib/attachmentDocument";
6+
import { HtmlRenderWebView } from "../threads/HtmlRenderWebView";
7+
import { AudioFilePreview } from "./AudioFilePreview";
8+
import { DelimitedFilePreview } from "./DelimitedFilePreview";
9+
import { FileMarkdownPreview } from "./FileMarkdownPreview";
10+
import { FilePreviewLoading, FilePreviewNotice } from "./FilePreviewFeedback";
11+
import { SourceFileSurface } from "./SourceFileSurface";
12+
import { WorkspaceFileWebPreview } from "./WorkspaceFileWebPreview";
13+
14+
export function nativeViewerKind(kind: ReturnType<typeof useAttachmentDocument>["kind"]) {
15+
if (kind === "image") return "image" as const;
16+
if (kind === "pdf") return "pdf" as const;
17+
if (kind === "video" || kind === "unsupported") return "document" as const;
18+
return null;
19+
}
20+
21+
export function AttachmentDocumentBody(props: {
22+
readonly document: Pick<
23+
ReturnType<typeof useAttachmentDocument>,
24+
| "kind"
25+
| "activeMode"
26+
| "uri"
27+
| "content"
28+
| "table"
29+
| "error"
30+
| "needsText"
31+
| "retry"
32+
| "revision"
33+
>;
34+
readonly name: string;
35+
readonly environmentId: EnvironmentId | null;
36+
readonly htmlRender: boolean;
37+
readonly nativeViewer: "pending" | "open" | "unavailable" | null;
38+
readonly nativeError: string | null;
39+
readonly onOpenNative: () => void;
40+
}) {
41+
const { document } = props;
42+
if (document.error) {
43+
return (
44+
<View className="flex-1 items-center justify-center bg-sheet px-6">
45+
<EmptyState
46+
title="File unavailable"
47+
detail={document.error}
48+
actionLabel="Try again"
49+
onAction={document.retry}
50+
/>
51+
</View>
52+
);
53+
}
54+
if (props.nativeViewer !== null && props.nativeViewer !== "unavailable") {
55+
return <FilePreviewLoading message="Opening in file viewer..." />;
56+
}
57+
// ZIP text entries are read into memory and have no file URI.
58+
if (document.needsText ? !document.content : !document.uri) {
59+
return <FilePreviewLoading message="Loading file..." />;
60+
}
61+
if (document.needsText && document.content) {
62+
const { content, table } = document;
63+
return (
64+
<View className="flex-1 bg-sheet">
65+
{content.truncated ? (
66+
<FilePreviewNotice title="Partial file">
67+
Preview limited to the first 1 MB. Save or share the file to read it in full.
68+
</FilePreviewNotice>
69+
) : null}
70+
{table && document.activeMode === "table" ? (
71+
<DelimitedFilePreview table={table} />
72+
) : document.activeMode === "markdown" && props.environmentId ? (
73+
<FileMarkdownPreview
74+
cwd=""
75+
relativePath=""
76+
environmentId={props.environmentId}
77+
threadId={null}
78+
markdown={content.text}
79+
captured
80+
/>
81+
) : (
82+
<SourceFileSurface contents={content.text} path={props.name} selectable />
83+
)}
84+
</View>
85+
);
86+
}
87+
if (!document.uri) return null;
88+
if (document.kind === "audio") {
89+
return <AudioFilePreview key={document.revision} uri={document.uri} onRetry={document.retry} />;
90+
}
91+
if (document.kind === "html") {
92+
return props.htmlRender ? (
93+
<HtmlRenderWebView key={document.uri} uri={document.uri} title={props.name} nested={false} />
94+
) : (
95+
<WorkspaceFileWebPreview uri={document.uri} />
96+
);
97+
}
98+
return (
99+
<View className="flex-1 items-center justify-center bg-sheet px-6">
100+
<EmptyState
101+
title="No preview for this file"
102+
detail={
103+
props.nativeError ??
104+
"No app on this device can show this format. Save or share it to open it elsewhere."
105+
}
106+
actionLabel="Try again"
107+
onAction={props.onOpenNative}
108+
/>
109+
</View>
110+
);
111+
}

0 commit comments

Comments
 (0)