Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
dab5c09
feat(mobile): select, cite, and comment on assistant text
jakeleventhal Oct 28, 2026
8cb1643
docs(mobile): name Go to message for opening a quote's source
jakeleventhal Oct 28, 2026
ab7ac87
fix(mobile): keep voice drafts locked when citing text
jakeleventhal Nov 2, 2026
45896dc
fix(mobile): hide cite while voice input blocks drafts
maria-rcks Nov 2, 2026
be3d5f3
fix(mobile): keep citation drafts within input limits
jakeleventhal Nov 12, 2026
e34f76a
fix(citations): preserve mobile quote sources and bound expansion
jakeleventhal Nov 12, 2026
75e6ac4
test(mobile): isolate citation picker presentation in previews
jakeleventhal Nov 12, 2026
e372cac
fix(mobile): keep quote choices aligned with live text
jakeleventhal Nov 12, 2026
209ae25
fix(server): reject oversized steering input before delivery
jakeleventhal Nov 12, 2026
4b6e9e7
fix(mobile): ignore empty blocks in citation context
jakeleventhal Nov 12, 2026
305f7fd
fix(mobile): exclude diagram source from citation occurrences
jakeleventhal Nov 12, 2026
651a9e6
merge: bring current main into mobile citations
maria-rcks Nov 15, 2026
81f59c3
fix(citations): preserve legacy links for unique quotes
maria-rcks Nov 15, 2026
c4de196
fix(citations): preserve merged validation and reference handling
maria-rcks Nov 15, 2026
210ce8a
Merge origin/main into t3/mobile-text-selection-citing
juliusmarminge Nov 17, 2026
f43e86c
fix(citations): keep citation links readable by released servers
juliusmarminge Nov 17, 2026
ea73fb3
Merge the author's latest t3/mobile-text-selection-citing
juliusmarminge Nov 17, 2026
40b876a
fix(server): limit only quote expansion to the provider input cap
juliusmarminge Nov 17, 2026
49e963a
Merge branch 'main' into t3/mobile-text-selection-citing
juliusmarminge Nov 18, 2026
2cdf11c
fix(mobile): translate quote citation copy after main added i18n
juliusmarminge Nov 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 131 additions & 0 deletions apps/mobile/src/components/AssistantCitationSheet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { ASSISTANT_CITATION_MAX_COMMENT_LENGTH, type AssistantCitation } from "@t3tools/contracts";
import { scopedThreadKey } from "@t3tools/client-runtime/environment";
import { useState } from "react";
import { T, useGT } from "gt-react-native";
import { Platform, ScrollView, TextInput, View } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { useOpenLinkedThread } from "../features/threads/useOpenLinkedThread";
import { requestThreadMessageJump } from "../features/threads/threadMessageJump";
import { copyTextWithHaptic } from "../lib/copyTextWithHaptic";
import { AppText as Text } from "./ui/AppText";
import { ListActionRow } from "./ui/ListActionRow";
import { ListSection } from "./ui/ListSection";
import { Sheet } from "./ui/Sheet";

const CONTEXT_CHARS = 80;

function contextBefore(prefix: string) {
const flat = prefix.replace(/\s+/g, " ");
if (flat.length <= CONTEXT_CHARS) return flat.trimStart();
const cut = flat.slice(-CONTEXT_CHARS);
return `…${cut.slice(cut.indexOf(" ") + 1)}`;
}

function contextAfter(suffix: string) {
const flat = suffix.replace(/\s+/g, " ");
if (flat.length <= CONTEXT_CHARS) return flat.trimEnd();
const cut = flat.slice(0, CONTEXT_CHARS);
return `${cut.slice(0, cut.lastIndexOf(" "))}…`;
}

export function AssistantCitationSheet(props: {
readonly citation: AssistantCitation;
readonly onClose: () => void;
readonly onRemove?: () => void;
readonly onCommentChange?: (comment: string) => void;
readonly canChangeComment?: (comment: string) => boolean;
}) {
const gt = useGT();
const openLinkedThread = useOpenLinkedThread();
const insets = useSafeAreaInsets();
const citation = props.citation;
const [comment, setComment] = useState(citation.comment ?? "");
const commentChanged = comment.trim() !== (citation.comment ?? "");
const commentTooLong = commentChanged && props.canChangeComment?.(comment) === false;
const close = () => {
if (commentTooLong) return;
if (props.onCommentChange && commentChanged) {
props.onCommentChange(comment);
}
props.onClose();
};
return (
<Sheet
title={gt("Quote", { $context: "noun, a quoted passage" })}
onClose={close}
dismissDisabled={commentTooLong}
>
<ScrollView
contentInsetAdjustmentBehavior={Platform.OS === "ios" ? "automatic" : "never"}
contentContainerStyle={{
paddingHorizontal: 20,
paddingTop: 12,
gap: 24,
paddingBottom: Math.max(20, insets.bottom),
}}
>
<View className="flex-row gap-3 rounded-2xl bg-grouped-card p-4">
<View className="w-1 rounded-full bg-primary" />
<Text selectable textRole="body" className="min-w-0 flex-1 text-foreground-muted">
{contextBefore(citation.prefix)}
<Text className="font-t3-medium text-foreground">{citation.text}</Text>
{contextAfter(citation.suffix)}
</Text>
</View>
{props.onCommentChange ? (
<ListSection title={gt("Comment", { $context: "noun" })}>
<TextInput
accessibilityLabel={gt("Comment on quote")}
placeholder={gt("Add an optional comment…")}
placeholderTextColorClassName="accent-foreground-muted"
multiline
maxLength={ASSISTANT_CITATION_MAX_COMMENT_LENGTH}
value={comment}
onChangeText={setComment}
className="min-h-24 px-4 py-3 text-base text-foreground"
style={{ textAlignVertical: "top" }}
/>
{commentTooLong ? (
<Text textRole="body" className="px-4 pb-3 text-foreground-muted">
<T>
This comment makes the message too long to send. Shorten it to save and close.
</T>
</Text>
) : null}
</ListSection>
) : citation.comment ? (
<ListSection title={gt("Comment", { $context: "noun" })}>
<Text selectable textRole="body" className="px-4 py-3 text-foreground">
{citation.comment}
</Text>
</ListSection>
) : null}
<ListSection>
<ListActionRow
icon="arrow.up.right"
label={gt("Go to message")}
onPress={() => {
if (commentTooLong) return;
close();
requestThreadMessageJump(scopedThreadKey(citation), citation.messageId);
openLinkedThread(citation);
}}
/>
<ListActionRow
icon="doc.on.doc"
label={gt("Copy quote")}
onPress={() => copyTextWithHaptic(citation.text)}
/>
{props.onRemove ? (
<ListActionRow
icon="trash"
label={gt("Remove from draft")}
tone="danger"
onPress={props.onRemove}
/>
) : null}
</ListSection>
</ScrollView>
</Sheet>
);
}
1 change: 1 addition & 0 deletions apps/mobile/src/components/ComposerEditor.ios.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ vi.mock("expo-file-system", () => ({
vi.mock("./ui/Dialog", () => ({ alert: vi.fn() }));
vi.mock("./ui/AppText", () => ({ AppText: ({ children }: { children?: ReactNode }) => children }));
vi.mock("./ComposerContextSheet", () => ({ ComposerContextSheet: () => null }));
vi.mock("./AssistantCitationSheet", () => ({ AssistantCitationSheet: () => null }));
vi.mock("../features/threads/useOpenLinkedThread", () => ({ useOpenLinkedThread: () => vi.fn() }));
vi.mock("../state/peerLinks", () => ({ useLinkedEnvironments: () => [] }));
vi.mock("../state/model-mentions", () => ({ useModelMentions: () => [] }));
Expand Down
79 changes: 66 additions & 13 deletions apps/mobile/src/components/ComposerEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import { useEffect, useState } from "react";
import type { EnvironmentId } from "@t3tools/contracts";
import { encodeComposerContextFragment } from "@t3tools/shared/composerContextClipboard";
import { collectComposerContextReferences } from "@t3tools/shared/composerContextReferences";
import {
collectAssistantCitations,
serializeAssistantCitation,
withAssistantCitationComment,
} from "@t3tools/shared/assistantCitations";
import { AssistantCitationSheet } from "./AssistantCitationSheet";
import { ComposerEditor as NativeComposerEditor } from "../native/T3ComposerEditor";
import type { ComposerEditorProps as NativeComposerEditorProps } from "../native/T3ComposerEditor";
import {
Expand Down Expand Up @@ -36,6 +42,7 @@ import { useLinkedEnvironments } from "../state/peerLinks";
import { ComposerContextSheet } from "./ComposerContextSheet";
import { AppText as Text } from "./ui/AppText";
import {
assistantCitationDraftWithinLimit,
composerDocumentAttachment,
composerMentionPath,
type ComposerDocumentAttachment,
Expand Down Expand Up @@ -183,13 +190,51 @@ export function ComposerEditor({
const selectedReference = selected
? collectComposerContextReferences(selected.source)[0]
: undefined;
const selectedCitation = selected
? collectAssistantCitations(selected.source)[0]?.citation
: undefined;
const selectedSkillName = selected?.source.match(/^\p{Sc}(.+)$/u)?.[1];
const selectedSkill = selectedSkillName
? props.skills?.find((skill) => skill.name === selectedSkillName)
: undefined;
const record = draft.context?.records.find(
(entry) => entry.contextId === selectedReference?.contextId,
);
const removeSelected =
props.readOnly || props.editable === false
? undefined
: () => {
if (!selected) return;
if (props.value.slice(selected.start, selected.end) === selected.source) {
changeText(props.value.slice(0, selected.start) + props.value.slice(selected.end));
props.onSelectionChange?.({ start: selected.start, end: selected.start });
}
setSelected(null);
};
const commentSelectedCitation =
props.readOnly || props.editable === false || !selected || !selectedCitation
? undefined
: (comment: string) => {
if (props.value.slice(selected.start, selected.end) !== selected.source) return;
const next = serializeAssistantCitation(
withAssistantCitationComment(selectedCitation, comment),
);
const text =
props.value.slice(0, selected.start) + next + props.value.slice(selected.end);
if (!assistantCitationDraftWithinLimit(text)) {
Dialog.alert(
gt("Could not update quote"),
gt(
"This comment would make the message too long to send. Shorten the comment or draft.",
),
);
return;
}
const cursor = selected.start + next.length;
if (draftKey)
rememberComposerDraftSelection(draftKey, text, { start: cursor, end: cursor });
changeText(text);
};
return (
<>
{/* Reset revision history with the recreated iOS view without aborting context imports. */}
Expand Down Expand Up @@ -242,6 +287,26 @@ export function ComposerEditor({
<T>Copying context…</T>
</Text>
) : null}
{selectedCitation ? (
<AssistantCitationSheet
citation={selectedCitation}
onClose={() => setSelected(null)}
onRemove={removeSelected}
onCommentChange={commentSelectedCitation}
canChangeComment={
selected && commentSelectedCitation
? (comment) =>
assistantCitationDraftWithinLimit(
props.value.slice(0, selected.start) +
serializeAssistantCitation(
withAssistantCitationComment(selectedCitation, comment),
) +
props.value.slice(selected.end),
)
: undefined
}
/>
) : null}
{selected && (selectedReference || selectedSkill) ? (
<ComposerContextSheet
label={
Expand Down Expand Up @@ -283,19 +348,7 @@ export function ComposerEditor({
records={draft.context?.records}
attachments={draft.attachments}
onClose={() => setSelected(null)}
onRemove={
props.readOnly || props.editable === false
? undefined
: () => {
if (props.value.slice(selected.start, selected.end) === selected.source) {
changeText(
props.value.slice(0, selected.start) + props.value.slice(selected.end),
);
props.onSelectionChange?.({ start: selected.start, end: selected.start });
}
setSelected(null);
}
}
onRemove={removeSelected}
/>
) : null}
</>
Expand Down
41 changes: 40 additions & 1 deletion apps/mobile/src/features/threads/ThreadDetailScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,15 @@ import { useAppearancePreferences } from "../settings/appearance/AppearancePrefe
import { collectProviderUsageLimits } from "@t3tools/shared/usageLimits";
import type { ComposerEditorHandle } from "../../components/ComposerEditor";
import type { StatusTone } from "../../components/StatusPill";
import { getComposerDraftSnapshot, setFreshSessionPending } from "../../state/use-composer-drafts";
import {
captureComposerDraftInsertion,
getComposerDraftSnapshot,
setFreshSessionPending,
insertComposerDraftText,
} from "../../state/use-composer-drafts";
import { assistantCitationDraftWithinLimit } from "../../lib/composerContext";
import { serializeAssistantCitation } from "@t3tools/shared/assistantCitations";
import type { AssistantCitation } from "@t3tools/contracts";
import { RenderErrorBoundary, RenderFailureView } from "../../components/RenderErrorBoundary";
import {
ANDROID_READING_MAX_WIDTH,
Expand Down Expand Up @@ -211,6 +219,7 @@ import { resolveThreadFeedSubmissionAnchor } from "./thread-feed-scroll-position
import { useOpenLinkedThread } from "./useOpenLinkedThread";
import { useGlobalVoiceInput } from "../voice-input/VoiceInputProvider";
import type { OrchestrationV2ProviderSession } from "@t3tools/contracts";
import { voiceInputBlocksSubmission } from "@t3tools/client-runtime/voice-input";

export interface ThreadDetailScreenProps {
readonly header?: React.ReactNode;
Expand Down Expand Up @@ -1351,6 +1360,35 @@ function ThreadDetailBody(
composerEditorRef.current?.blur();
};

const canCiteAssistantText =
props.composerDraftKey !== null &&
!isProviderSubagent &&
!composerSlotHidden &&
!props.isSavingQueuedEdit &&
!props.draftMode?.interactionLocked &&
!(
voiceInputSession.ownerKey === props.composerDraftKey &&
voiceInputBlocksSubmission(voiceInputSession.controller.currentState)
);
const handleCiteAssistantText = (citation: AssistantCitation) => {
if (!canCiteAssistantText || props.composerDraftKey === null) return;
const target = captureComposerDraftInsertion(props.composerDraftKey);
const prefix = target.start > 0 && !/\s/.test(target.text[target.start - 1]!) ? " " : "";
const value = `${prefix}${serializeAssistantCitation(citation)} `;
const text = target.text.slice(0, target.start) + value + target.text.slice(target.end);
if (!assistantCitationDraftWithinLimit(text)) {
Dialog.alert(
gt("Could not add quote"),
gt(
"This quote would make the message too long to send. Shorten the draft or select less text.",
),
);
return;
}
insertComposerDraftText(props.composerDraftKey, value, target);
composerEditorRef.current?.focus();
};

const handleUseArtifactTemplate = (template: CodexArtifactTemplate) => {
const draftMessage =
props.composerDraftKey === null ? "" : getComposerDraftSnapshot(props.composerDraftKey).text;
Expand Down Expand Up @@ -1493,6 +1531,7 @@ function ThreadDetailBody(
onHeaderMaterialVisibilityChange={props.onHeaderMaterialVisibilityChange}
onIsAtEndChange={setIsAtEnd}
skills={selectedProviderSkills}
onCiteAssistantText={canCiteAssistantText ? handleCiteAssistantText : undefined}
onUseArtifactTemplate={handleUseArtifactTemplate}
/>
</ColumnWidth>
Expand Down
Loading
Loading