Skip to content

Commit 3d458d3

Browse files
Merge commit '585ce2c2ab396e4c3c5ffcfc422449c07896ddf9' into audit/text-only-preview-snapshot-10187
2 parents 67e1db2 + 585ce2c commit 3d458d3

29 files changed

Lines changed: 1377 additions & 234 deletions

‎apps/mobile/src/connection/runtime.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ type ConnectionLayerSource =
3131
| typeof mobileBackgroundActivityReporterLayer;
3232

3333
const providedClientConnectionLayer = snapshotLoaderLayer.pipe(
34-
Layer.provideMerge(Connection.layerWithOptions({ usageLimitSources: true })),
34+
Layer.provideMerge(
35+
Connection.layerWithOptions({ usageLimitSources: true, usageLimitsCommand: true }),
36+
),
3537
Layer.provideMerge(
3638
Layer.mergeAll(
3739
runtimeContextLayer,
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import type { EnvironmentId, UsageLimitsReport } from "@t3tools/contracts";
2+
import { Pressable, ScrollView, useWindowDimensions, View } from "react-native";
3+
4+
import { SymbolView } from "../../components/AppSymbol";
5+
import { AppText as Text } from "../../components/AppText";
6+
import { AccountLimits, ResetCredits } from "../usage/UsageLimitsSection";
7+
8+
const DRIVER_LABEL: Partial<Record<string, string>> = { codex: "Codex", claudeAgent: "Claude" };
9+
10+
/**
11+
* The /usage-limits result, docked above the composer. It is the Usage → Limits
12+
* card one size down, so the two read as the same thing. The surface is opaque
13+
* because nothing blurs the feed behind it.
14+
*/
15+
export function ComposerUsageLimits({
16+
report,
17+
environmentId,
18+
onClose,
19+
}: {
20+
readonly report: UsageLimitsReport;
21+
readonly environmentId: EnvironmentId;
22+
readonly onClose: () => void;
23+
}) {
24+
const now = Date.parse(report.createdAt);
25+
const { height } = useWindowDimensions();
26+
const close = (
27+
<Pressable
28+
accessibilityLabel="Dismiss usage limits"
29+
accessibilityRole="button"
30+
hitSlop={12}
31+
onPress={onClose}
32+
className="-me-1 p-1 active:opacity-60"
33+
>
34+
<SymbolView name="xmark" size={14} tintColorClassName="accent-icon-muted" type="monochrome" />
35+
</Pressable>
36+
);
37+
return (
38+
<View className="overflow-hidden rounded-[20px] border-continuous bg-card">
39+
<ScrollView
40+
bounces={false}
41+
showsVerticalScrollIndicator={false}
42+
style={{ maxHeight: Math.round(height * 0.4) }}
43+
>
44+
{report.accounts.map((account, index) => {
45+
const driverLabel = DRIVER_LABEL[account.driver] ?? String(account.driver);
46+
return (
47+
<AccountLimits
48+
key={account.id}
49+
dense
50+
first={index === 0}
51+
driver={account.driver}
52+
label={driverLabel}
53+
// Siblings need telling apart: a custom instance without a name shows its
54+
// id, and a pooled account shows its hub and account id.
55+
instanceLabel={
56+
account.instanceId
57+
? account.displayName?.trim() ||
58+
(String(account.instanceId) !== String(account.driver)
59+
? account.instanceId
60+
: driverLabel)
61+
: account.label
62+
}
63+
detail={account.plan}
64+
limits={account.limits}
65+
now={now}
66+
trailing={index === 0 ? close : undefined}
67+
footer={
68+
account.instanceId && account.limits.resetCredits ? (
69+
<ResetCredits
70+
dense
71+
environmentId={environmentId}
72+
instanceId={account.instanceId}
73+
credits={account.limits.resetCredits}
74+
now={now}
75+
/>
76+
) : undefined
77+
}
78+
/>
79+
);
80+
})}
81+
{report.accounts.length === 0 ? (
82+
// Nothing but notices, so the close control needs a row of its own.
83+
<View className="flex-row items-center gap-3 px-4 pt-3">
84+
<Text className="min-w-0 flex-1 text-base text-foreground">Usage limits</Text>
85+
{close}
86+
</View>
87+
) : null}
88+
{report.notices.map((notice) => (
89+
<Text
90+
key={notice}
91+
className={
92+
report.accounts.length === 0
93+
? "px-4 py-3 text-xs text-foreground-muted"
94+
: "border-t border-border-subtle px-4 py-3 text-xs text-foreground-muted"
95+
}
96+
>
97+
{notice}
98+
</Text>
99+
))}
100+
</ScrollView>
101+
</View>
102+
);
103+
}

‎apps/mobile/src/features/threads/NewTaskDraftScreen.tsx‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import { VideoPreviewModal, type VideoPreviewSource } from "../../components/Vid
4949
import { ProviderIcon } from "../../components/ProviderIcon";
5050
import { SymbolView } from "../../components/AppSymbol";
5151
import { AppText as Text } from "../../components/AppText";
52+
import { hasProviderUsageLimits, isUsageLimitsCommand } from "@t3tools/shared/usageLimits";
5253
import { COMPOSER_LAYOUT_TRANSITION, ComposerSurface } from "./ThreadComposer";
5354
import { ShimmeringWorkContent } from "./thread-work-log";
5455
import { ComposerCommandPopover } from "./ComposerCommandPopover";
@@ -309,6 +310,14 @@ export function NewTaskDraftScreen(props: {
309310
const isComposerInteractionLocked = isIncomingShareTransferPending || flow.submitting;
310311
// Also guard while a submit is in flight: an Android back press or iOS
311312
// Cancel would otherwise abandon the screen while the task still starts.
313+
// T3 owns /usage-limits only where Limits has data for the selected provider.
314+
const offersUsageLimits =
315+
flow.selectedProviderStatus !== null &&
316+
hasProviderUsageLimits(
317+
flow.selectedProviderStatus.driver,
318+
selectedEnvironmentServerConfig?.providers ?? [],
319+
selectedEnvironmentServerConfig?.usageLimitSources ?? [],
320+
);
312321
const composerMenu = useComposerCommandMenu({
313322
draftMessage: flow.prompt,
314323
ownerKey: flow.draftKey,
@@ -320,6 +329,7 @@ export function NewTaskDraftScreen(props: {
320329
selectedProviderStatus: flow.selectedProviderStatus,
321330
hasThread: false,
322331
hasCompactableConversation: false,
332+
offersUsageLimits: offersUsageLimits,
323333
enabled: isComposerFocused && !isComposerInteractionLocked,
324334
onChangeDraftMessage: flow.setPrompt,
325335
onUpdateInteractionMode: flow.planModeEnabled ? flow.setInteractionMode : undefined,
@@ -908,6 +918,20 @@ export function NewTaskDraftScreen(props: {
908918
);
909919
return;
910920
}
921+
// T3's own limits command is answered by the thread composer; a new task would
922+
// send it to the agent. A provider's same-named command, or a prompt carrying
923+
// attachments, goes through as usual.
924+
if (
925+
offersUsageLimits &&
926+
isUsageLimitsCommand(initialMessageText) &&
927+
draft.attachments.length === 0
928+
) {
929+
Alert.alert(
930+
"Usage limits",
931+
"Send /usage-limits inside a thread, or open Settings → Usage → Limits.",
932+
);
933+
return;
934+
}
911935
// A failed-send restore can leave the draft over the cap on purpose (it
912936
// never drops the user's files); starting anyway would upload everything
913937
// and have the server reject the turn.

‎apps/mobile/src/features/threads/ThreadComposer.tsx‎

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ import type {
77
ProviderInteractionMode,
88
RuntimeMode,
99
ServerConfig as T3ServerConfig,
10+
UsageLimitsReport,
1011
} from "@t3tools/contracts";
12+
import {
13+
collectProviderUsageLimits,
14+
hasProviderUsageLimits,
15+
isUsageLimitsCommand,
16+
} from "@t3tools/shared/usageLimits";
1117
import { StackActions, useFocusEffect, useNavigation } from "@react-navigation/native";
1218
import type { ReactNode } from "react";
1319
import {
@@ -20,7 +26,7 @@ import {
2026
useState,
2127
type RefObject,
2228
} from "react";
23-
import { ActivityIndicator, Platform, Pressable, View, type ViewStyle } from "react-native";
29+
import { ActivityIndicator, Alert, Platform, Pressable, View, type ViewStyle } from "react-native";
2430
import { FilePreviewModal, type FilePreviewSource } from "../../components/FilePreviewModal";
2531
import {
2632
composerAttachmentUploadBlockReason,
@@ -124,6 +130,8 @@ export interface ThreadComposerProps {
124130
readonly onRemoveDraftImage: (imageId: string) => void;
125131
readonly onStopThread: () => void;
126132
readonly onSendMessage: () => Promise<MessageId | null>;
133+
/** `/usage-limits` resolves locally; the host decides where the report shows. Null clears it. */
134+
readonly onShowUsageLimits: (report: UsageLimitsReport | null) => void;
127135
readonly onUpdateModelSelection: (modelSelection: ModelSelection) => void;
128136
readonly onUpdateRuntimeMode: (runtimeMode: RuntimeMode) => void;
129137
readonly onUpdateInteractionMode: (interactionMode: ProviderInteractionMode) => void;
@@ -336,6 +344,30 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
336344
);
337345
}, [props.serverConfig, props.selectedThread.modelSelection.instanceId]);
338346
const composerOwnerKey = scopedThreadKey(props.environmentId, props.selectedThread.id);
347+
const { onSendMessage, onChangeDraftMessage, onShowUsageLimits } = props;
348+
// T3 owns /usage-limits only where Limits has data for the selected provider;
349+
// elsewhere the name stays the provider's own and is sent through untouched.
350+
const usageLimitsOffered =
351+
selectedProviderStatus !== null &&
352+
hasProviderUsageLimits(
353+
selectedProviderStatus.driver,
354+
props.serverConfig?.providers ?? [],
355+
props.serverConfig?.usageLimitSources ?? [],
356+
);
357+
// Answered locally from the last Limits snapshot; the agent never sees it.
358+
const openUsageLimits = useCallback(() => {
359+
const report = collectProviderUsageLimits(
360+
currentModelSelection.instanceId,
361+
props.serverConfig?.providers ?? [],
362+
props.serverConfig?.usageLimitSources ?? [],
363+
Date.now(),
364+
);
365+
onShowUsageLimits(report);
366+
if (!report) {
367+
Alert.alert("Usage limits unavailable", "This provider does not currently report limits.");
368+
}
369+
return report !== null;
370+
}, [currentModelSelection.instanceId, onShowUsageLimits, props.serverConfig]);
339371

340372
const composerMenu = useComposerCommandMenu({
341373
draftMessage: props.draftMessage,
@@ -350,6 +382,10 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
350382
selectedProviderStatus?.showInteractionModeToggle === false
351383
? undefined
352384
: props.onUpdateInteractionMode,
385+
offersUsageLimits: usageLimitsOffered,
386+
// With attachments aboard the pick just inserts the text, so it sends as a prompt.
387+
onUsageLimits:
388+
usageLimitsOffered && props.draftAttachments.length === 0 ? openUsageLimits : undefined,
353389
});
354390
const voiceInput = useVoiceInputController({
355391
ownerKey: composerOwnerKey,
@@ -428,9 +464,17 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
428464
}
429465
onEditorFocusChange?.(false);
430466
}, [onEditorFocusChange, onExpandedChange, settingsSheetPresentation.isActive]);
431-
const { onSendMessage } = props;
432-
433467
const handleSend = useCallback(async () => {
468+
// Typed out in full rather than picked from the menu. Attachments mean the
469+
// user is sending a prompt, so those go through as usual.
470+
if (
471+
usageLimitsOffered &&
472+
isUsageLimitsCommand(props.draftMessage) &&
473+
props.draftAttachments.length === 0
474+
) {
475+
if (openUsageLimits()) onChangeDraftMessage("");
476+
return;
477+
}
434478
if (voiceInput.blocksSubmission) return;
435479
const threadKey = scopedThreadKey(props.environmentId, props.selectedThread.id);
436480
if (inFlightThreadIdsRef.current.has(threadKey)) return;
@@ -453,6 +497,11 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
453497
inFlightThreadIdsRef.current.delete(threadKey);
454498
}
455499
}, [
500+
props.draftMessage,
501+
props.draftAttachments.length,
502+
onChangeDraftMessage,
503+
openUsageLimits,
504+
usageLimitsOffered,
456505
onSendMessage,
457506
props.environmentId,
458507
props.environmentLabel,

0 commit comments

Comments
 (0)