Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 38 additions & 0 deletions apps/mobile/src/features/settings/SettingsFollowUpRouteScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
import { useAtomSet, useAtomValue } from "@effect/atom-react";
import {
DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD,
type PastedTextAttachmentThreshold,
} from "@t3tools/contracts";
import { pastedTextThresholdLabel } from "@t3tools/client-runtime/text-paste";
import { AsyncResult } from "effect/reactivity";
import { Platform } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
Expand Down Expand Up @@ -28,6 +33,17 @@ const FOLLOW_UP_OPTIONS: ReadonlyArray<{
},
];

const THRESHOLD_OPTIONS: ReadonlyArray<{
readonly threshold: PastedTextAttachmentThreshold;
readonly description: string;
}> = [
{ threshold: 1_000, description: "Most logs, stack traces, and code snippets become files." },
{ threshold: 5_000, description: "Long logs and documents become files; snippets stay as text." },
{ threshold: 32_768, description: "Default. Only very large pastes become files." },
];

const PASTE_AS_TEXT_SHORTCUT = Platform.OS === "ios" ? "Command + Shift + V" : "Ctrl + Shift + V";

export function SettingsFollowUpRouteScreen() {
const insets = useSafeAreaInsets();
const preferencesResult = useAtomValue(mobilePreferencesAtom);
Expand All @@ -36,6 +52,10 @@ export function SettingsFollowUpRouteScreen() {
const selectedBehavior = AsyncResult.isSuccess(preferencesResult)
? (preferencesResult.value.followUpBehavior ?? DEFAULT_FOLLOW_UP_BEHAVIOR)
: null;
const selectedThreshold = AsyncResult.isSuccess(preferencesResult)
? (preferencesResult.value.pastedTextAttachmentThreshold ??
DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD)
: null;

const content = (
<ScrollView
Expand All @@ -62,6 +82,24 @@ export function SettingsFollowUpRouteScreen() {
Long-press the send button to use the other option for a single message. With a hardware
keyboard, hold {Platform.OS === "android" ? "Ctrl" : "Command"} while sending.
</Text>
<SettingsSection title="Attach pastes as files from">
{THRESHOLD_OPTIONS.map(({ threshold, description }, index) => (
<SettingsChoiceRow
key={threshold}
label={pastedTextThresholdLabel(threshold)}
description={description}
selected={selectedThreshold === threshold}
separated={index > 0}
disabled={!preferencesReady}
onPress={() => savePreferences({ pastedTextAttachmentThreshold: threshold })}
/>
))}
</SettingsSection>
<Text className="px-2 text-sm text-foreground-muted">
Shorter pastes go into the message as text. Non-Latin text and emoji use more bytes per
character, so they reach the limit sooner. With a hardware keyboard, press{" "}
{PASTE_AS_TEXT_SHORTCUT} to paste a long block as text instead.
</Text>
</ScrollView>
);

Expand Down
10 changes: 9 additions & 1 deletion apps/mobile/src/features/settings/settings-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,15 @@ const SETTINGS_SEARCH_TERMS = {
"auto-resume",
"thread behavior",
],
SettingsFollowUp: ["follow-ups", "queue", "steer", "while the agent is running"],
SettingsFollowUp: [
"follow-ups",
"queue",
"steer",
"while the agent is running",
"large pastes",
"attachment",
"text file",
],
SettingsArchive: ["archive", "archived", "restore", "unarchive"],
SettingsProviderAccounts: [
"provider accounts",
Expand Down
3 changes: 3 additions & 0 deletions apps/mobile/src/features/threads/ThreadComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import Animated, {
withTiming,
} from "react-native-reanimated";
import { useUniwindTheme } from "../../lib/useUniwindTheme";
import { usePastedTextAttachmentThreshold } from "../../lib/usePastedTextAttachmentThreshold";
import { themeColorWithAlpha } from "../../lib/mobileTheme";
import { armAgentAwarenessLiveActivityForLocalWork } from "../agent-awareness/remoteRegistration";
import { scopedThreadKey } from "../../lib/scopedEntities";
Expand Down Expand Up @@ -436,6 +437,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
const navigation = useNavigation();
const foregroundColor = useUniwindTheme()["--color-foreground"];
const bodyText = useComposerTextRole();
const pastedTextAttachmentThreshold = usePastedTextAttachmentThreshold();
const fallbackInputRef = useRef<ComposerEditorHandle>(null);
const inputRef = props.editorRef ?? fallbackInputRef;
const [isFocused, setIsFocused] = useState(false);
Expand Down Expand Up @@ -1059,6 +1061,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
text: paste.text,
wouldExceedInputLimit,
canAttach: true,
thresholdBytes: pastedTextAttachmentThreshold,
}) === "attachment"
) {
if (canAttach) {
Expand Down
19 changes: 19 additions & 0 deletions apps/mobile/src/lib/usePastedTextAttachmentThreshold.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useAtomValue } from "@effect/atom-react";
import { DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD } from "@t3tools/contracts";
import { AsyncResult } from "effect/reactivity";

import { mobilePreferencesAtom } from "../state/preferences";

/**
* Paste size at which the composer folds clipboard text into a text-file
* attachment. Selects only the threshold so unrelated preference writes do not
* re-render the composer editors.
*/
export function usePastedTextAttachmentThreshold() {
return useAtomValue(mobilePreferencesAtom, (preferences) =>
AsyncResult.isSuccess(preferences)
? (preferences.value.pastedTextAttachmentThreshold ??
DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD)
: DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD,
);
}
5 changes: 3 additions & 2 deletions apps/mobile/src/native/T3ComposerEditor.ios.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PASTED_TEXT_ATTACHMENT_THRESHOLD_BYTES } from "@t3tools/client-runtime/text-paste";
import { PROVIDER_SEND_TURN_MAX_INPUT_CHARS } from "@t3tools/contracts";
import { collectComposerInlineTokens } from "@t3tools/shared/composerInlineTokens";
import { composerContextEditorTokens, composerSkillLabels } from "../lib/composerContext";
Expand Down Expand Up @@ -27,6 +26,7 @@ import { contextChipIconUri, modelChipIcon, modelChipIconUri } from "../lib/cont
import { useUniwindTheme } from "../lib/useUniwindTheme";
import { createNativeComposerTheme } from "../lib/nativeComposerTheme";
import { FONT_FAMILIES } from "../lib/fontFamilies";
import { usePastedTextAttachmentThreshold } from "../lib/usePastedTextAttachmentThreshold";
import { useComposerTextRole } from "../features/settings/appearance/useScaledTextRole";
import {
acknowledgeComposerNativeEvent,
Expand Down Expand Up @@ -179,6 +179,7 @@ export function ComposerEditor({
const bodyText = useComposerTextRole();
const theme = useUniwindTheme();
const fontFamily = FONT_FAMILIES.regular;
const pastedTextAttachmentThreshold = usePastedTextAttachmentThreshold();

const skillLabels = useMemo(() => composerSkillLabels(skills), [skills]);
const { modelsBySource, modelTokens } = useComposerModelTokens(props.value, models);
Expand Down Expand Up @@ -372,7 +373,7 @@ export function ComposerEditor({
autoFocus={props.autoFocus ?? false}
autoCorrect={props.autoCorrect ?? true}
spellCheck={props.spellCheck ?? true}
textPasteThresholdBytes={onPasteText ? PASTED_TEXT_ATTACHMENT_THRESHOLD_BYTES : 0}
textPasteThresholdBytes={onPasteText ? pastedTextAttachmentThreshold : 0}
maxInputChars={PROVIDER_SEND_TURN_MAX_INPUT_CHARS}
style={style as StyleProp<ViewStyle>}
onComposerChange={(event) => applyNativeChange(event.nativeEvent)}
Expand Down
5 changes: 3 additions & 2 deletions apps/mobile/src/native/T3ComposerEditor.native.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PASTED_TEXT_ATTACHMENT_THRESHOLD_BYTES } from "@t3tools/client-runtime/text-paste";
import { PROVIDER_SEND_TURN_MAX_INPUT_CHARS } from "@t3tools/contracts";
import { collectComposerInlineTokens } from "@t3tools/shared/composerInlineTokens";
import { composerContextEditorTokens, composerSkillLabels } from "../lib/composerContext";
Expand Down Expand Up @@ -29,6 +28,7 @@ import { contextChipIconUri, modelChipIcon, modelChipIconUri } from "../lib/cont
import { MOBILE_TYPOGRAPHY } from "../lib/typography";
import { useNativePaste } from "../lib/useNativePaste";
import { FONT_FAMILIES } from "../lib/fontFamilies";
import { usePastedTextAttachmentThreshold } from "../lib/usePastedTextAttachmentThreshold";
import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";
import { useUniwindTheme } from "../lib/useUniwindTheme";
import { createNativeComposerTheme } from "../lib/nativeComposerTheme";
Expand Down Expand Up @@ -313,6 +313,7 @@ export function ComposerEditor({
});
const resolvedTextStyle = StyleSheet.flatten(textStyle) ?? {};
const regularFontFamily = FONT_FAMILIES.regular;
const pastedTextAttachmentThreshold = usePastedTextAttachmentThreshold();
return (
<TextInputWrapper onPaste={handlePaste} style={[{ minHeight: 0 }, style]}>
<NativeView
Expand Down Expand Up @@ -346,7 +347,7 @@ export function ComposerEditor({
spellCheck={props.spellCheck ?? true}
enterBehavior={props.enterBehavior ?? DEFAULT_COMPOSER_ENTER_BEHAVIOR}
submitEnabled={onSubmit !== undefined}
textPasteThresholdBytes={onPasteText ? PASTED_TEXT_ATTACHMENT_THRESHOLD_BYTES : 0}
textPasteThresholdBytes={onPasteText ? pastedTextAttachmentThreshold : 0}
maxInputChars={PROVIDER_SEND_TURN_MAX_INPUT_CHARS}
style={{ flex: 1, minHeight: 0 }}
onComposerChange={(event) => {
Expand Down
7 changes: 7 additions & 0 deletions apps/mobile/src/persistence/mobile-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
PullRequestInvolvement,
PullRequestListFilters,
PullRequestListState,
PastedTextAttachmentThreshold,
type ProviderInstanceId,
PullRequestMergeMethod,
type SidebarProjectGroupingMode,
Expand All @@ -27,6 +28,7 @@ import { MobileStorageDecodeError, MobileStorageEncodeError } from "./mobile-sto
const PREFERENCES_KEY = "t3code.preferences";
const PREFERENCES_FALLBACK_KEY = "t3code.preferences.fallback";
const encodeJson = Schema.encodeUnknownEffect(Schema.fromJsonString(Schema.Unknown));
const isPastedTextAttachmentThreshold = Schema.is(PastedTextAttachmentThreshold);

export const PullRequestListControls = Schema.Struct({
state: PullRequestListState,
Expand Down Expand Up @@ -113,6 +115,7 @@ export interface Preferences {
/** Hardware-keyboard Return behavior in the composer. */
readonly composerEnterBehavior?: ComposerEnterBehavior;
readonly followUpBehavior?: FollowUpBehavior;
readonly pastedTextAttachmentThreshold?: PastedTextAttachmentThreshold;
/** The client `language` setting: a locale code or "system". Unset means English. */
readonly language?: string;
readonly microphones?: ReadonlyArray<MicrophoneEntry>;
Expand Down Expand Up @@ -200,6 +203,7 @@ function sanitizePreferences(parsed: Preferences): Preferences {
dismissedDatabaseStorageNotices?: readonly string[];
composerEnterBehavior?: ComposerEnterBehavior;
followUpBehavior?: FollowUpBehavior;
pastedTextAttachmentThreshold?: PastedTextAttachmentThreshold;
language?: string;
microphones?: ReadonlyArray<MicrophoneEntry>;
projectGroupingEnabled?: boolean;
Expand Down Expand Up @@ -305,6 +309,9 @@ function sanitizePreferences(parsed: Preferences): Preferences {
if (parsed.followUpBehavior === "queue" || parsed.followUpBehavior === "steer") {
preferences.followUpBehavior = parsed.followUpBehavior;
}
if (isPastedTextAttachmentThreshold(parsed.pastedTextAttachmentThreshold)) {
preferences.pastedTextAttachmentThreshold = parsed.pastedTextAttachmentThreshold;
}
if (typeof parsed.language === "string") preferences.language = parsed.language;
if (Array.isArray(parsed.microphones)) {
preferences.microphones = parsed.microphones.flatMap((entry): MicrophoneEntry[] => {
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/chat/ChatComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2637,6 +2637,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
questionAttachmentTarget,
attachmentTargetKey,
fileStagingLimit,
pastedTextAttachmentThreshold: settings.pastedTextAttachmentThreshold,
promptRef,
composerImagesRef,
composerFilesRef,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect } from "react";
import { EnvironmentId, ProjectId, ThreadId } from "@t3tools/contracts";
import { DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD } from "@t3tools/contracts/settings";
import { scopeProjectRef, scopeThreadRef } from "@t3tools/client-runtime/environment";
import { expect, it, vi } from "vite-plus/test";
import { AsyncResult } from "effect/reactivity";
Expand Down Expand Up @@ -86,6 +87,7 @@ it("prepares a repeated paste without a tile, and still keeps a different image"
questionAttachmentTarget: null,
attachmentTargetKey: target,
fileStagingLimit: null,
pastedTextAttachmentThreshold: DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD,
promptRef: { current: "" },
composerImagesRef,
composerFilesRef: { current: [] },
Expand Down Expand Up @@ -171,6 +173,7 @@ it.each(["thread", "session"] as const)(
questionAttachmentTarget: null,
attachmentTargetKey: targetKey,
fileStagingLimit: null,
pastedTextAttachmentThreshold: DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD,
promptRef: { current: "half-written prompt" },
composerImagesRef: { current: [] },
composerFilesRef: { current: [] },
Expand Down Expand Up @@ -217,3 +220,53 @@ it.each(["thread", "session"] as const)(
expect(restored?.images).toEqual([]);
},
);

it.each([
{ thresholdBytes: 1_000, folds: true },
{ thresholdBytes: DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD, folds: false },
])(
"a 4,600-byte paste at a $thresholdBytes-byte threshold folds: $folds",
async ({ thresholdBytes, folds }) => {
const attachedNames: string[] = [];
const input = {
activeThreadId: ThreadId.make("thread"),
activePendingProgress: null,
activePendingIsResponding: false,
pendingUserInputs: [],
supportsQuestionAttachments: false,
isLiteralPendingAnswer: false,
projectSelectionRequired: false,
questionAttachmentTarget: null,
attachmentTargetKey: DraftId.make("intake-paste-threshold"),
fileStagingLimit: 1_000_000,
pastedTextAttachmentThreshold: thresholdBytes,
promptRef: { current: "" },
composerImagesRef: { current: [] },
composerFilesRef: { current: [] },
composerEditorRef: { current: null },
isRevertingCheckpointRef: { current: false },
setThreadError: () => {},
countReservedAttachments: () => 0,
addComposerImage: () => [],
addComposerImagesToDraft: () => [],
addComposerFilesToDraft: (files) => {
attachedNames.push(...files.map((file) => file.name));
return [];
},
removeComposerImageFromDraft: () => {},
insertAttachmentReferences: () => false,
} satisfies IntakeInput;
let intake!: Intake;
await using _screen = await render(
<Harness
input={input}
ready={(value) => {
intake = value;
}}
/>,
);

expect(intake.foldPastedText("x".repeat(4_600), false)).toBe(folds);
expect(attachedNames).toEqual(folds ? ["pasted-text.txt"] : []);
},
);
3 changes: 3 additions & 0 deletions apps/web/src/components/chat/useComposerAttachmentIntake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export function useComposerAttachmentIntake(input: {
readonly questionAttachmentTarget: DraftId | null;
readonly attachmentTargetKey: string;
readonly fileStagingLimit: number | null;
readonly pastedTextAttachmentThreshold: number;
readonly promptRef: ChatComposerProps["promptRef"];
readonly composerImagesRef: ChatComposerProps["composerImagesRef"];
readonly composerFilesRef: ChatComposerProps["composerFilesRef"];
Expand Down Expand Up @@ -99,6 +100,7 @@ export function useComposerAttachmentIntake(input: {
questionAttachmentTarget,
attachmentTargetKey,
fileStagingLimit,
pastedTextAttachmentThreshold,
promptRef,
composerImagesRef,
composerFilesRef,
Expand Down Expand Up @@ -403,6 +405,7 @@ export function useComposerAttachmentIntake(input: {
bypassAutoAttachment,
wouldExceedInputLimit,
canAttach: true,
thresholdBytes: pastedTextAttachmentThreshold,
}) === "attachment";
if (!shouldFold) {
return false;
Expand Down
Loading
Loading