Skip to content

Commit 3edb3c8

Browse files
fix(devices): prime the iOS helper before opening the input socket and allow the Device tab on draft threads
serve-sim only accepts HID after screen capture is running, which the AVCC stream alone does not start; taps from the panel were silently dropped. Draft threads pre-allocate the ref the server thread inherits, so there is no reason to withhold the surface until the first message is sent. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent f3ead48 commit 3edb3c8

3 files changed

Lines changed: 32 additions & 9 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4003,9 +4003,9 @@ export default function ChatView(props: ChatViewProps) {
40034003
useRightPanelStore.getState().open(activeThreadRef, "agents");
40044004
}, [activeThreadRef]);
40054005
const addDeviceSurface = useCallback(() => {
4006-
if (!activeThreadRef || !isServerThread) return;
4006+
if (!activeThreadRef) return;
40074007
useRightPanelStore.getState().open(activeThreadRef, "device");
4008-
}, [activeThreadRef, isServerThread]);
4008+
}, [activeThreadRef]);
40094009
// An agent's `device_open` surfaces in every client the same way a
40104010
// `preview_open` does: the thread gains a device session and the panel
40114011
// opens on it. Closing the last session leaves the tab in place so the
@@ -8433,7 +8433,7 @@ export default function ChatView(props: ChatViewProps) {
84338433
filesAvailable={activeProject !== null}
84348434
pullRequestAvailable={pullRequestSurfaceAvailable}
84358435
agentsAvailable
8436-
deviceAvailable={isServerThread}
8436+
deviceAvailable={activeThreadRef !== null}
84378437
liveAgentCount={agentPanelModel.liveCount}
84388438
>
84398439
{rightPanelContent}
@@ -8485,7 +8485,7 @@ export default function ChatView(props: ChatViewProps) {
84858485
filesAvailable={activeProject !== null}
84868486
pullRequestAvailable={pullRequestSurfaceAvailable}
84878487
agentsAvailable
8488-
deviceAvailable={isServerThread}
8488+
deviceAvailable={activeThreadRef !== null}
84898489
liveAgentCount={agentPanelModel.liveCount}
84908490
>
84918491
{rightPanelContent}

‎apps/web/src/components/RightPanelTabs.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ const SURFACE_DISABLED_REASONS = {
143143
diff: "Diff is only available for server threads in Git repositories.",
144144
pullRequest: "This thread's branch has no pull request yet.",
145145
agents: "Agents are only available from a thread.",
146-
device: "Devices are only available from a server thread.",
146+
device: "Devices are only available from a thread.",
147147
} as const;
148148

149149
/** Overlays that must win over the launcher's letter shortcuts. */
@@ -166,7 +166,7 @@ const SURFACE_UNAVAILABLE_HINTS = {
166166
diff: "Available for Git repositories.",
167167
pullRequest: "No pull request on this branch yet.",
168168
agents: "Available from a thread.",
169-
device: "Available from a server thread.",
169+
device: "Available from a thread.",
170170
} as const;
171171

172172
type TabContextMenuAction =

‎apps/web/src/components/device/deviceStream.ts‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,31 @@ export function createDeviceStreamClient(
461461
if (!stopped) scheduleRetry(() => void readIosVideo());
462462
};
463463

464+
/**
465+
* serve-sim's helper only accepts HID and pushes its screen config once
466+
* screen capture is running, and the AVCC stream does not reliably start
467+
* it. Touching the MJPEG endpoint does; one aborted request is enough.
468+
*/
469+
const primeIosHelper = async () => {
470+
const controller = new AbortController();
471+
try {
472+
const response = await fetch(httpUrl(`/helper/${device}/stream.mjpeg`), {
473+
signal: controller.signal,
474+
credentials: access.credentials ? "include" : "same-origin",
475+
});
476+
if (response.status === 401 || response.status === 403) return handleUnauthorized();
477+
await response.body?.getReader().read();
478+
} catch {
479+
// A failed prime just means the socket may take a retry to come up.
480+
} finally {
481+
controller.abort();
482+
}
483+
};
484+
464485
// iOS input socket; also carries the screen config the helper pushes.
465-
const connectIosInput = () => {
486+
const connectIosInput = async () => {
487+
if (stopped) return;
488+
await primeIosHelper();
466489
if (stopped) return;
467490
const ws = new WebSocket(wsUrl(`/helper/ws?device=${device}`));
468491
ws.binaryType = "arraybuffer";
@@ -494,7 +517,7 @@ export function createDeviceStreamClient(
494517
);
495518
}
496519
if (event.code === 1008 || event.code === 4401) return handleUnauthorized();
497-
scheduleRetry(connectIosInput);
520+
scheduleRetry(() => void connectIosInput());
498521
};
499522
ws.onerror = () => ws.close();
500523
};
@@ -552,7 +575,7 @@ export function createDeviceStreamClient(
552575
firstFrame = false;
553576
events.onStatus("connecting");
554577
if (platform === "ios") {
555-
connectIosInput();
578+
void connectIosInput();
556579
if (useWebCodecs) void readIosVideo();
557580
else fallBackToMjpeg();
558581
} else if (useWebCodecs) {

0 commit comments

Comments
 (0)