Skip to content

Commit 0d266fb

Browse files
StiensWoutmaria-rcksYash-Singh1
authored
feat(pi): show extension status in existing controls (#23901)
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Yash Singh <[email protected]>
1 parent cae7e5c commit 0d266fb

22 files changed

Lines changed: 1341 additions & 48 deletions

‎apps/mobile/src/components/ui/Dialog.android.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
Text,
1111
useNativeState,
1212
} from "@expo/ui/jetpack-compose";
13+
import { verticalScroll } from "@expo/ui/jetpack-compose/modifiers";
1314

1415
import { useAppearancePreferences } from "../../features/settings/appearance/AppearancePreferencesProvider";
1516
import { useScaledTextRole } from "../../features/settings/appearance/useScaledTextRole";
@@ -252,7 +253,9 @@ function DialogPresentation(props: DialogPresentationProps) {
252253
</AlertDialog.Text>
253254
) : props.request.message ? (
254255
<AlertDialog.Text>
255-
<Text style={bodyTypography}>{props.request.message}</Text>
256+
<Text modifiers={[verticalScroll()]} style={bodyTypography}>
257+
{props.request.message}
258+
</Text>
256259
</AlertDialog.Text>
257260
) : null}
258261
{actions.length > 1 ? (

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ import type { ThreadContentPresentation } from "./threadContentPresentation";
208208
import { resolveThreadFeedSubmissionAnchor } from "./thread-feed-live-follow";
209209
import { useOpenLinkedThread } from "./useOpenLinkedThread";
210210
import { useGlobalVoiceInput } from "../voice-input/VoiceInputProvider";
211+
import type { OrchestrationV2ProviderSession } from "@t3tools/contracts";
211212

212213
export interface ThreadDetailScreenProps {
213214
readonly header?: React.ReactNode;
@@ -240,6 +241,7 @@ export interface ThreadDetailScreenProps {
240241
readonly activeWorkStartedAt: string | null;
241242
readonly runlessWorkActive?: boolean;
242243
readonly providerSubagentStatus?: ProviderSubagentStatus | null;
244+
readonly extensionStatuses?: NonNullable<OrchestrationV2ProviderSession["extensionStatuses"]>;
243245
readonly isCompacting: boolean;
244246
readonly creationState:
245247
| {
@@ -735,6 +737,13 @@ function ThreadDetailBody(
735737
const pendingBackgroundWork = presentPendingBackgroundWork(
736738
props.selectedThread.pendingBackgroundTasks,
737739
);
740+
const extensionStatus = props.extensionStatuses?.length
741+
? {
742+
label: `Pi · ${props.extensionStatuses.map((status) => status.text).join(" · ")}`,
743+
onPress: () =>
744+
Dialog.alert("Pi", props.extensionStatuses?.map((status) => status.text).join("\n\n")),
745+
}
746+
: null;
738747
const floatingStatus = ((): FloatingWorkingStatus | null => {
739748
const connectionStatus = connectionFloatingStatus({
740749
connectionError: connectionRetrying ? retryConnectionError : props.connectionError,
@@ -864,6 +873,9 @@ function ThreadDetailBody(
864873
accessibilityLabel: `${goal.title}: ${goal.objective}`,
865874
};
866875
}
876+
if (extensionStatus !== null && contentPresentationKind === "ready") {
877+
return { kind: "extension", ...extensionStatus };
878+
}
867879
return null;
868880
})();
869881
const showWorkingControl = floatingStatus !== null;
@@ -1602,6 +1614,16 @@ function ThreadDetailBody(
16021614
<FloatingWorkingControl
16031615
colorScheme={isDarkMode ? "dark" : "light"}
16041616
status={floatingStatus}
1617+
extensionStatus={
1618+
floatingStatus !== null &&
1619+
(floatingStatus.kind === "working" ||
1620+
floatingStatus.kind === "compacting" ||
1621+
floatingStatus.kind === "background" ||
1622+
floatingStatus.kind === "goal" ||
1623+
floatingStatus.kind === "lifecycle")
1624+
? extensionStatus
1625+
: null
1626+
}
16051627
lift={floatingControlLift}
16061628
devicePreview={
16071629
devicePreviews.length > 0

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,7 @@ function ThreadRouteContent(
991991
}
992992
isCompacting={composer.isCompacting}
993993
runlessWorkActive={composer.runlessWorkActive}
994+
extensionStatuses={composer.extensionStatuses}
994995
providerSubagentStatus={composer.providerSubagentStatus}
995996
creationState={creationState}
996997
setupWorkingStartedAt={

‎apps/mobile/src/features/threads/floating-working-control.tsx‎

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export const FLOATING_WORKING_CONTROL_COVERAGE = CONTROL_OVERLAY_OFFSET + CONTRO
6969
export function FloatingWorkingControl(props: {
7070
readonly colorScheme: "light" | "dark";
7171
readonly status: FloatingWorkingStatus | null;
72+
readonly extensionStatus?: { readonly label: string; readonly onPress: () => void } | null;
7273
readonly devicePreview: { readonly count: number; readonly onPress: () => void } | null;
7374
readonly browserPreview: { readonly count: number; readonly onPress: () => void } | null;
7475
readonly showScrollToEnd: boolean;
@@ -84,6 +85,10 @@ export function FloatingWorkingControl(props: {
8485
const [overlayWidth, setOverlayWidth] = useState(windowWidth);
8586
const [queueWidth, setQueueWidth] = useState(0);
8687
const [actionWidth, setActionWidth] = useState(0);
88+
const [extensionWidth, setExtensionWidth] = useState(0);
89+
const extensionStatus = props.extensionStatus ?? null;
90+
const extensionOnly = props.status?.kind === "extension";
91+
const useGlass = NATIVE_LIQUID_GLASS_SUPPORTED && !extensionOnly;
8792
const action =
8893
props.status?.kind === "background" ||
8994
props.status?.kind === "lifecycle" ||
@@ -96,7 +101,7 @@ export function FloatingWorkingControl(props: {
96101
const [previewWidth, setPreviewWidth] = useState(0);
97102
const agents = props.agents;
98103
const hasAgents = agents !== null;
99-
const labelWidth = Math.max(
104+
const availableLabelWidth = Math.max(
100105
0,
101106
Math.min(overlayWidth, windowWidth) -
102107
CONTROL_HEIGHT -
@@ -106,6 +111,10 @@ export function FloatingWorkingControl(props: {
106111
(hasAgents ? agentsWidth : 0) -
107112
(hasPreview ? previewWidth : 0),
108113
);
114+
const labelWidth = Math.max(
115+
0,
116+
availableLabelWidth - (extensionStatus === null ? 0 : extensionWidth),
117+
);
109118
const separationProgress = useSharedValue(props.showScrollToEnd ? 1 : 0);
110119

111120
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- animates the Reanimated separation value when scroll-to-end visibility changes
@@ -163,10 +172,16 @@ export function FloatingWorkingControl(props: {
163172
(props.devicePreview !== null && props.browserPreview !== null);
164173
const statusInteractive =
165174
props.status?.kind === "connection" ||
175+
props.status?.kind === "extension" ||
166176
props.status?.kind === "child-input" ||
167177
props.status?.kind === "background";
168178
const capsuleInteractive =
169-
statusInteractive || action !== null || hasQueue || hasAgents || hasPreview;
179+
statusInteractive ||
180+
extensionStatus !== null ||
181+
action !== null ||
182+
hasQueue ||
183+
hasAgents ||
184+
hasPreview;
170185
const statusContent =
171186
props.status !== null ? (
172187
<View
@@ -181,7 +196,9 @@ export function FloatingWorkingControl(props: {
181196
>
182197
<FloatingStatusLabel
183198
key={
184-
props.status.kind === "working" || props.status.kind === "compacting"
199+
props.status.kind === "working" ||
200+
props.status.kind === "compacting" ||
201+
props.status.kind === "extension"
185202
? props.status.kind
186203
: `${props.status.kind}:${props.status.label}`
187204
}
@@ -195,6 +212,22 @@ export function FloatingWorkingControl(props: {
195212
const capsuleContent = (
196213
<View className="flex-row items-center">
197214
{statusContent}
215+
{extensionStatus !== null ? (
216+
<Pressable
217+
accessibilityRole="button"
218+
accessibilityLabel={extensionStatus.label}
219+
accessibilityHint="Shows the full Pi status"
220+
onPress={extensionStatus.onPress}
221+
onLayout={(event) => setExtensionWidth(settleWidth(event.nativeEvent.layout.width))}
222+
style={{ maxWidth: availableLabelWidth * 0.5 }}
223+
className="h-11 flex-row items-center px-3 active:opacity-70"
224+
>
225+
{hasStatus ? <View className="absolute left-0 h-4 w-px bg-border" /> : null}
226+
<Text className="shrink font-t3-medium text-xs text-foreground" numberOfLines={1}>
227+
{extensionStatus.label}
228+
</Text>
229+
</Pressable>
230+
) : null}
198231
{action !== null ? (
199232
<View
200233
onLayout={(event) => setActionWidth(settleWidth(event.nativeEvent.layout.width))}
@@ -273,10 +306,10 @@ export function FloatingWorkingControl(props: {
273306
className="absolute left-0 right-0 z-20 items-center"
274307
style={[{ top: -CONTROL_OVERLAY_OFFSET }, liftStyle]}
275308
onLayout={(event) => setOverlayWidth(event.nativeEvent.layout.width)}
276-
entering={NATIVE_LIQUID_GLASS_SUPPORTED || reducedMotion ? undefined : CONTROL_ENTERING}
277-
exiting={NATIVE_LIQUID_GLASS_SUPPORTED || reducedMotion ? undefined : CONTROL_EXITING}
309+
entering={useGlass || extensionOnly || reducedMotion ? undefined : CONTROL_ENTERING}
310+
exiting={useGlass || extensionOnly || reducedMotion ? undefined : CONTROL_EXITING}
278311
>
279-
{hasCapsule && NATIVE_LIQUID_GLASS_SUPPORTED ? (
312+
{hasCapsule && useGlass ? (
280313
<UniwindGlassContainer
281314
spacing={GLASS_MERGE_SPACING}
282315
pointerEvents="box-none"
@@ -374,6 +407,23 @@ function FloatingStatusLabel(props: {
374407
readonly status: FloatingWorkingStatus;
375408
readonly onLayout: (event: LayoutChangeEvent) => void;
376409
}) {
410+
if (props.status.kind === "extension") {
411+
return (
412+
<StatusLabelRow
413+
accessibilityLabel={props.status.label}
414+
accessibilityRole="button"
415+
onPress={props.status.onPress}
416+
onLayout={props.onLayout}
417+
className="gap-1.5"
418+
animated={false}
419+
>
420+
<Text className="shrink font-t3-medium text-xs text-foreground" numberOfLines={1}>
421+
{props.status.label}
422+
</Text>
423+
<SymbolView name="chevron.down" size={10} tintColorClassName="accent-foreground" />
424+
</StatusLabelRow>
425+
);
426+
}
377427
if (props.status.kind === "syncing") {
378428
return (
379429
<StatusLabelRow
@@ -546,6 +596,7 @@ function FloatingStatusLabel(props: {
546596
}
547597

548598
function StatusLabelRow(props: {
599+
readonly animated?: boolean;
549600
readonly accessibilityLabel?: string;
550601
readonly accessibilityRole?: "button";
551602
readonly className?: string;
@@ -558,8 +609,8 @@ function StatusLabelRow(props: {
558609
return (
559610
<Animated.View
560611
className="absolute max-w-full"
561-
entering={reducedMotion ? undefined : LABEL_ENTERING}
562-
exiting={reducedMotion ? undefined : LABEL_EXITING}
612+
entering={props.animated === false || reducedMotion ? undefined : LABEL_ENTERING}
613+
exiting={props.animated === false || reducedMotion ? undefined : LABEL_EXITING}
563614
onLayout={props.onLayout}
564615
>
565616
{props.onPress ? (

‎apps/mobile/src/features/threads/floating-working-status.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export type FloatingWorkingStatus =
3838
readonly action: FloatingStatusAction | null;
3939
}
4040
| { readonly kind: "goal"; readonly label: string; readonly accessibilityLabel: string }
41+
| { readonly kind: "extension"; readonly label: string; readonly onPress: () => void }
4142
| { readonly kind: "preparing"; readonly label: string }
4243
| {
4344
readonly kind: "connection";

‎apps/mobile/src/state/use-thread-composer-state.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { ThreadCheckpointSummary } from "@t3tools/client-runtime/state/thre
99
import { resolvePendingHandoff } from "@t3tools/client-runtime/handoff";
1010
import {
1111
deriveProviderSubagentStatus,
12+
deriveProviderExtensionStatuses,
1213
deriveResumableRunId,
1314
deriveRunlessWorkStartedAt,
1415
deriveThreadActivityRun,
@@ -874,6 +875,9 @@ export function useThreadComposerState(input: {
874875
dispatchingQueuedMessageId,
875876
activeWorkStartedAt,
876877
runlessWorkActive,
878+
extensionStatuses: deriveProviderExtensionStatuses(
879+
selectedThreadProjection?.projection ?? null,
880+
),
877881
providerSubagentStatus,
878882
isCompacting,
879883
composerDraftKey,

‎apps/server/src/orchestration-v2/ProjectionRecovery.test.ts‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
import * as DateTime from "effect/DateTime";
2222
import * as Effect from "effect/Effect";
2323
import * as Layer from "effect/Layer";
24+
import * as Stream from "effect/Stream";
2425
import * as SqlClient from "effect/sql/SqlClient";
2526
import * as Statement from "effect/sql/Statement";
2627

@@ -263,6 +264,103 @@ it.effect("stops a session its thread detached, which kept its live status", ()
263264
}).pipe(Effect.provide(layerRecoveryTest)),
264265
);
265266

267+
it.effect.each(["attached", "detached", "replaced"] as const)(
268+
"recovers attached sessions without restoring detached errors, session=%s",
269+
(state) =>
270+
Effect.gen(function* () {
271+
const projections = yield* ProjectionStore.ProjectionStoreV2;
272+
const recovery = yield* ProviderRuntimeRecovery.ProviderRuntimeRecoveryService;
273+
const now = yield* DateTime.now;
274+
const threadId = yield* createThread("failed-status-session");
275+
const providerSessionId = ProviderSessionId.make("session:recovery:failed-status");
276+
const session = {
277+
id: providerSessionId,
278+
driver,
279+
providerInstanceId,
280+
status: "error" as const,
281+
cwd: "/workspace",
282+
model: modelSelection.model,
283+
capabilities: CodexProviderCapabilitiesV2,
284+
extensionStatuses: [{ key: "watch", text: "Watching" }],
285+
createdAt: now,
286+
updatedAt: now,
287+
lastError: "Rate limited",
288+
};
289+
yield* projections.apply({
290+
id: EventId.make("event:recovery:failed-status:attached"),
291+
type: "provider-session.attached",
292+
threadId,
293+
driver,
294+
providerInstanceId,
295+
occurredAt: now,
296+
payload: session,
297+
});
298+
if (state !== "attached") {
299+
yield* projections.apply({
300+
id: EventId.make("event:recovery:failed-status:detached"),
301+
type: "provider-session.detached",
302+
threadId,
303+
driver,
304+
providerInstanceId,
305+
occurredAt: now,
306+
payload: { providerSessionId, detachedAt: now, reason: "Thread settled." },
307+
});
308+
}
309+
const replacementSessionId = ProviderSessionId.make("session:recovery:replacement");
310+
if (state === "replaced") {
311+
yield* projections.apply({
312+
id: EventId.make("event:recovery:replacement:attached"),
313+
type: "provider-session.attached",
314+
threadId,
315+
driver,
316+
providerInstanceId,
317+
occurredAt: now,
318+
payload: {
319+
...session,
320+
id: replacementSessionId,
321+
status: "ready",
322+
extensionStatuses: [],
323+
lastError: null,
324+
},
325+
});
326+
yield* createRun(threadId, "completed");
327+
}
328+
assert.deepEqual(
329+
yield* projections.getRecoveryThreadIds("runtime"),
330+
state === "detached" ? [] : [threadId],
331+
);
332+
yield* recovery.reconcile("startup");
333+
const eventStore = yield* EventStore.EventStoreV2;
334+
const stored = yield* eventStore.read({ threadId }).pipe(Stream.runCollect);
335+
const sessionUpdates = stored.flatMap(({ event }) =>
336+
event.type === "provider-session.updated"
337+
? [
338+
{
339+
id: event.payload.id,
340+
status: event.payload.status,
341+
lastError: event.payload.lastError,
342+
extensionStatuses: event.payload.extensionStatuses,
343+
},
344+
]
345+
: [],
346+
);
347+
assert.deepEqual(
348+
sessionUpdates,
349+
state === "detached"
350+
? []
351+
: [
352+
{
353+
id: state === "attached" ? providerSessionId : replacementSessionId,
354+
status: state === "attached" ? "error" : "stopped",
355+
lastError: state === "attached" ? "Rate limited" : null,
356+
extensionStatuses: [],
357+
},
358+
],
359+
);
360+
assert.deepEqual(yield* projections.getRecoveryThreadIds("runtime"), []);
361+
}).pipe(Effect.provide(layerRecoveryTest)),
362+
);
363+
266364
it.effect("selects unfinished recovery work without reading settled thread histories", () =>
267365
Effect.gen(function* () {
268366
const projections = yield* ProjectionStore.ProjectionStoreV2;

‎apps/server/src/orchestration-v2/ProjectionStore.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4200,6 +4200,9 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
42004200
CROSS JOIN orchestration_v2_projection_provider_session_bindings AS bindings
42014201
ON bindings.provider_session_id = sessions.provider_session_id
42024202
WHERE sessions.status NOT IN ('stopped', 'error')
4203+
OR (sessions.status = 'error' AND CASE WHEN json_valid(sessions.payload_json)
4204+
THEN json_array_length(sessions.payload_json, '$.extensionStatuses') > 0
4205+
ELSE 0 END)
42034206
UNION
42044207
-- A detach drops the binding but keeps the session's status.
42054208
SELECT sessions.thread_id
@@ -4702,6 +4705,9 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
47024705
)
47034706
AND (
47044707
session.status NOT IN ('stopped', 'error')
4708+
OR (session.status = 'error' AND CASE WHEN json_valid(session.payload_json)
4709+
THEN json_array_length(session.payload_json, '$.extensionStatuses') > 0
4710+
ELSE 0 END)
47054711
OR session.provider_session_id IN (
47064712
SELECT provider_thread.provider_session_id
47074713
FROM orchestration_v2_projection_provider_threads AS provider_thread

0 commit comments

Comments
 (0)