diff --git a/apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx b/apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx index de96c4c8913d6..0db1e31fdc63e 100644 --- a/apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx +++ b/apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx @@ -1,15 +1,24 @@ import { SheetCloseButton } from "../../components/ui/SheetHeader"; import { Button } from "../../components/ui/Button"; import * as Dialog from "../../components/ui/Dialog"; +import { scopeThreadRef } from "@t3tools/client-runtime/environment"; import { deviceToolVersionLabels, deviceToolUpdateOwnership, deviceToolUpdatePolicy, + otherThreadDeviceSessions, } from "@t3tools/client-runtime/state/device"; -import { useIsFocused, useNavigation, type StaticScreenProps } from "@react-navigation/native"; -import { EnvironmentId, ThreadId } from "@t3tools/contracts"; +import { threadRuntimeIsActive } from "@t3tools/client-runtime/state/shell"; +import { backgroundWorkHoldsCompletion } from "@t3tools/shared/orchestrationV2PendingBackgroundWork"; +import { + StackActions, + useIsFocused, + useNavigation, + type StaticScreenProps, +} from "@react-navigation/native"; +import { EnvironmentId, ThreadId, type DeviceSession } from "@t3tools/contracts"; import * as Cause from "effect/Cause"; -import { msg, T, useGT } from "gt-react-native"; +import { msg, T, useGT, Var } from "gt-react-native"; import { useEffect, useRef, useState, type RefObject } from "react"; import * as Haptics from "expo-haptics"; import { Accelerometer } from "expo-sensors"; @@ -36,6 +45,7 @@ import { deriveBottomControlInsets } from "../../lib/reserved-regions"; import { useNativeColumnLayoutMetrics } from "../../native/native-layout-metrics"; import { uuidv4 } from "../../lib/uuid"; import { deviceEnvironment, useDeviceHubAccess } from "../../state/device"; +import { useThreadShell } from "../../state/entities"; import { useEnvironmentQuery } from "../../state/query"; import { useAtomCommand } from "../../state/use-atom-command"; import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider"; @@ -90,6 +100,7 @@ export function DevicePreviewScreen({ readonly initialDeviceKey?: string; }) { const embedded = onMaximize !== undefined; + const navigation = useNavigation(); const insets = useSafeAreaInsets(); // In a pane the stream sits below the pane's bar, which content otherwise slides under. const barOverlap = useBarOverlap(); @@ -106,10 +117,14 @@ export function DevicePreviewScreen({ const [controlsVisible, setControlsVisible] = useState(true); const retryHost = useAtomCommand(deviceEnvironment.list); const shutdown = useAtomCommand(deviceEnvironment.shutdown, { reportFailure: false }); + const close = useAtomCommand(deviceEnvironment.close, { reportFailure: false }); const streamRef = useRef(null); const state = useEnvironmentQuery(deviceEnvironment.state({ environmentId, input: {} })); const previews = threadDevicePreviews(state.data, threadId); const preview = selectedThreadDevicePreview(previews, selectedKey); + const holders = preview + ? otherThreadDeviceSessions(state.data?.sessions ?? [], preview.session) + : []; const onInputConnected = async (connected: boolean) => { setInputConnected(connected); if (!connected) setControlsVisible(true); @@ -151,6 +166,32 @@ export function DevicePreviewScreen({ } }; + const takeOver = async (holder: DeviceSession) => { + const result = await close({ + environmentId, + input: { threadId: holder.threadId, hostId: holder.hostId, deviceId: holder.deviceId }, + }); + if (result._tag === "Failure") { + Dialog.alert(gt("Could not take over device"), String(Cause.squash(result.cause))); + } + }; + const holderBanners = holders.map((holder) => ( + + navigation.dispatch( + (embedded ? StackActions.push : StackActions.replace)("Thread", { + environmentId, + threadId: holder.threadId, + }), + ) + } + onTakeOver={() => takeOver(holder)} + /> + )); + const controls: AppBarMenuItem[] = [ ...(state.data?.hosts .filter( @@ -284,6 +325,9 @@ export function DevicePreviewScreen({ ]} /> + {holderBanners.length > 0 ? ( + {holderBanners} + ) : null} ) : null} {preview && focused && foreground ? ( @@ -351,6 +395,7 @@ export function DevicePreviewScreen({ /> + {holderBanners.length > 0 ? {holderBanners} : null} ) : ( @@ -376,6 +421,70 @@ export function DevicePreviewScreen({ ); } +function DeviceHolderBanner(props: { + readonly environmentId: EnvironmentId; + readonly holder: DeviceSession; + readonly onOpenThread: () => void; + readonly onTakeOver: () => Promise; +}) { + const gt = useGT(); + const shell = useThreadShell(scopeThreadRef(props.environmentId, props.holder.threadId)); + const running = + threadRuntimeIsActive(shell?.runtime) || + backgroundWorkHoldsCompletion(shell?.pendingBackgroundTasks ?? []); + const [takingOver, setTakingOver] = useState(false); + const title = shell?.title.trim() || gt("another thread"); + return ( + + + + {running ? ( + + Busy in{" "} + + {title} + + , which is running. + + ) : shell ? ( + + Busy in{" "} + + {title} + + , which isn't running. + + ) : ( + + Busy in{" "} + + {title} + + . + + )} + + + + + ); +} + function DeviceNotice(props: { readonly onDismiss: () => void; readonly children: ReactNode }) { const gt = useGT(); return ( diff --git a/apps/web/src/i18n/translations/de.json b/apps/web/src/i18n/translations/de.json index e8685533481d0..a7281ee86175b 100644 --- a/apps/web/src/i18n/translations/de.json +++ b/apps/web/src/i18n/translations/de.json @@ -5158,6 +5158,10 @@ "4b4ef3f2e2ed2c56": "{name} starten", "08098a6fb84e8a34": "Öffnen", "c71a5080b2026870": "Starten", + "cfae7ef07c37220e": "einem anderen Thread", + "23d5d026ee80963b": "Von {title} übernehmen", + "01e8d054b2d2f232": "Wird übernommen…", + "746c576ea195806b": "Übernehmen", "a34247bae083cebf": "Gerätefehler schließen", "191353bd8f033118": "Die Listen {first} und {second} auf {host} sind möglicherweise unvollständig.", "b17bcd4cbf80442e": "Die {platform}-Liste auf {host} ist möglicherweise unvollständig.", @@ -5175,6 +5179,33 @@ ], "e902f208c4e6146f": "Keine virtuellen Android-Geräte gefunden. Erstelle eines im Geräte-Manager von Android Studio und aktualisiere dann.", "d9a71f3db685cb0e": "Geräte aktualisieren", + "ce2da8d9521a3ef4": [ + "Belegt durch ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + ", läuft gerade." + ], + "5fae5a165e609f5a": [ + "Belegt durch ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + ", läuft gerade nicht." + ], + "9c4958e3e914e8e8": [ + "Belegt durch ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + "." + ], "4ad8ced64defdf73": "Interaktives 3D-Gerät. Ziehe auf dem Bildschirm, um es zu bedienen. Ziehe außerhalb oder wische mit zwei Fingern, um es zu drehen.", "84e4baf07ad8883d": "Erlaube dieser Umgebung, Simulatoren und Emulatoren zu öffnen, egal ob sie hier oder auf einem entfernten Geräte-Host laufen.", "771365c337509a82": "Neuen Agentensitzungen in dieser Umgebung erlauben, lokale und entfernte Geräte zu starten und zu steuern; die nötigen Tools werden automatisch eingerichtet.", diff --git a/apps/web/src/i18n/translations/en.json b/apps/web/src/i18n/translations/en.json index 05b83efc41fc5..f15f9428f8678 100644 --- a/apps/web/src/i18n/translations/en.json +++ b/apps/web/src/i18n/translations/en.json @@ -5158,6 +5158,10 @@ "4b4ef3f2e2ed2c56": "Start {name}", "08098a6fb84e8a34": "Open", "c71a5080b2026870": "Start", + "cfae7ef07c37220e": "another thread", + "23d5d026ee80963b": "Take over from {title}", + "01e8d054b2d2f232": "Taking over…", + "746c576ea195806b": "Take over", "a34247bae083cebf": "Dismiss device error", "191353bd8f033118": "{first} and {second} lists on {host} may be incomplete.", "b17bcd4cbf80442e": "{platform} list on {host} may be incomplete.", @@ -5176,6 +5180,33 @@ ], "e902f208c4e6146f": "No Android virtual devices found. Create one in Android Studio's Device Manager, then refresh.", "d9a71f3db685cb0e": "Refresh devices", + "ce2da8d9521a3ef4": [ + "Busy in ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + ", which is running." + ], + "5fae5a165e609f5a": [ + "Busy in ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + ", which isn't running." + ], + "9c4958e3e914e8e8": [ + "Busy in ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + "." + ], "4ad8ced64defdf73": "Interactive 3D device. Drag the screen to interact. Drag outside it or swipe with two fingers to turn.", "84e4baf07ad8883d": "Enable this environment to open simulators and emulators, whether they run here or on a remote device host.", "771365c337509a82": "Allow new agent sessions in this environment to start and control local and remote devices, with required tools set up automatically.", diff --git a/apps/web/src/i18n/translations/es.json b/apps/web/src/i18n/translations/es.json index 05ee7b77c7d7f..0471a4757a8e1 100644 --- a/apps/web/src/i18n/translations/es.json +++ b/apps/web/src/i18n/translations/es.json @@ -5156,6 +5156,10 @@ "4b4ef3f2e2ed2c56": "Iniciar {name}", "08098a6fb84e8a34": "Abrir", "c71a5080b2026870": "Iniciar", + "cfae7ef07c37220e": "otro hilo", + "23d5d026ee80963b": "Tomar control de {title}", + "01e8d054b2d2f232": "Tomando control…", + "746c576ea195806b": "Tomar control", "a34247bae083cebf": "Descartar el error del dispositivo", "191353bd8f033118": "Puede que las listas de {first} y {second} en {host} estén incompletas.", "b17bcd4cbf80442e": "Puede que la lista de {platform} en {host} esté incompleta.", @@ -5174,6 +5178,33 @@ ], "e902f208c4e6146f": "No se encontraron dispositivos virtuales de Android. Crea uno en el Device Manager de Android Studio y actualiza.", "d9a71f3db685cb0e": "Actualizar dispositivos", + "ce2da8d9521a3ef4": [ + "En uso en ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + ", que está en ejecución." + ], + "5fae5a165e609f5a": [ + "En uso en ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + ", que no está en ejecución." + ], + "9c4958e3e914e8e8": [ + "En uso en ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + "." + ], "4ad8ced64defdf73": "Dispositivo 3D interactivo. Arrastra la pantalla para interactuar. Arrastra fuera de ella o desliza con dos dedos para girarlo.", "84e4baf07ad8883d": "Activa este entorno para abrir simuladores y emuladores, tanto si se ejecutan aquí como en un host de dispositivos remoto.", "771365c337509a82": "Permite que las sesiones de agente nuevas de este entorno inicien y controlen dispositivos locales y remotos, con las herramientas necesarias configuradas automáticamente.", diff --git a/apps/web/src/i18n/translations/fr.json b/apps/web/src/i18n/translations/fr.json index ada03eb7f10a6..a9546ba7e7162 100644 --- a/apps/web/src/i18n/translations/fr.json +++ b/apps/web/src/i18n/translations/fr.json @@ -5157,6 +5157,10 @@ "4b4ef3f2e2ed2c56": "Démarrer {name}", "08098a6fb84e8a34": "Ouvrir", "c71a5080b2026870": "Démarrer", + "cfae7ef07c37220e": "un autre fil", + "23d5d026ee80963b": "Prendre le contrôle depuis {title}", + "01e8d054b2d2f232": "Prise de contrôle…", + "746c576ea195806b": "Prendre le contrôle", "a34247bae083cebf": "Ignorer l’erreur de l’appareil", "191353bd8f033118": "Les listes {first} et {second} sur {host} sont peut-être incomplètes.", "b17bcd4cbf80442e": "La liste {platform} sur {host} est peut-être incomplète.", @@ -5175,6 +5179,33 @@ ], "e902f208c4e6146f": "Aucun appareil virtuel Android trouvé. Créez-en un dans le Device Manager d’Android Studio, puis actualisez.", "d9a71f3db685cb0e": "Actualiser les appareils", + "ce2da8d9521a3ef4": [ + "Occupé dans ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + ", qui est en cours." + ], + "5fae5a165e609f5a": [ + "Occupé dans ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + ", qui n'est pas en cours." + ], + "9c4958e3e914e8e8": [ + "Occupé dans ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + "." + ], "4ad8ced64defdf73": "Appareil 3D interactif. Faites glisser l’écran pour interagir. Faites glisser en dehors ou balayez avec deux doigts pour le faire tourner.", "84e4baf07ad8883d": "Autorisez cet environnement à ouvrir des simulateurs et des émulateurs, qu’ils tournent ici ou sur un hôte d’appareils distant.", "771365c337509a82": "Autorisez les nouvelles sessions d’agent de cet environnement à démarrer et contrôler des appareils locaux et distants, avec les outils nécessaires configurés automatiquement.", diff --git a/apps/web/src/i18n/translations/ja.json b/apps/web/src/i18n/translations/ja.json index 9d743e7e0a7f0..d46d1a325b94a 100644 --- a/apps/web/src/i18n/translations/ja.json +++ b/apps/web/src/i18n/translations/ja.json @@ -5141,6 +5141,10 @@ "4b4ef3f2e2ed2c56": "{name} を起動", "08098a6fb84e8a34": "開く", "c71a5080b2026870": "起動", + "cfae7ef07c37220e": "別のスレッド", + "23d5d026ee80963b": "{title} から引き継ぐ", + "01e8d054b2d2f232": "引き継ぎ中…", + "746c576ea195806b": "引き継ぐ", "a34247bae083cebf": "デバイスのエラーを閉じる", "191353bd8f033118": "{host} の {first} と {second} の一覧は不完全な可能性があります。", "b17bcd4cbf80442e": "{host} の {platform} の一覧は不完全な可能性があります。", @@ -5158,6 +5162,33 @@ ], "e902f208c4e6146f": "Android の仮想デバイスが見つかりません。Android Studio の Device Manager で作成してから、更新してください。", "d9a71f3db685cb0e": "デバイスを更新", + "ce2da8d9521a3ef4": [ + "", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + " で使用中です。このスレッドは実行中です。" + ], + "5fae5a165e609f5a": [ + "", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + " で使用中です。このスレッドは実行中ではありません。" + ], + "9c4958e3e914e8e8": [ + "", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + " で使用中です。" + ], "4ad8ced64defdf73": "インタラクティブな 3D デバイス。画面をドラッグして操作します。画面の外をドラッグするか 2 本指でスワイプすると回転します。", "84e4baf07ad8883d": "この環境を有効にすると、ここまたはリモートのデバイスホストで実行されるシミュレーターやエミュレーターを開けます。", "771365c337509a82": "この環境の新しいエージェントセッションが、ローカルとリモートのデバイスを起動して操作できるようにします。必要なツールは自動的にセットアップされます。", diff --git a/apps/web/src/i18n/translations/ko.json b/apps/web/src/i18n/translations/ko.json index 943c383b7cef3..69e00c3fb30f7 100644 --- a/apps/web/src/i18n/translations/ko.json +++ b/apps/web/src/i18n/translations/ko.json @@ -5138,6 +5138,10 @@ "4b4ef3f2e2ed2c56": "{name} 시작", "08098a6fb84e8a34": "열기", "c71a5080b2026870": "시작", + "cfae7ef07c37220e": "다른 스레드", + "23d5d026ee80963b": "{title}에서 가져오기", + "01e8d054b2d2f232": "가져오는 중…", + "746c576ea195806b": "가져오기", "a34247bae083cebf": "기기 오류 닫기", "191353bd8f033118": "{host}의 {first} 및 {second} 목록이 불완전할 수 있습니다.", "b17bcd4cbf80442e": "{host}의 {platform} 목록이 불완전할 수 있습니다.", @@ -5155,6 +5159,33 @@ ], "e902f208c4e6146f": "Android 가상 기기가 없습니다. Android Studio의 Device Manager에서 만든 다음 새로 고치세요.", "d9a71f3db685cb0e": "기기 새로 고침", + "ce2da8d9521a3ef4": [ + "", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + "에서 사용 중이며, 해당 스레드가 실행 중입니다." + ], + "5fae5a165e609f5a": [ + "", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + "에서 사용 중이며, 해당 스레드는 실행 중이 아닙니다." + ], + "9c4958e3e914e8e8": [ + "", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + "에서 사용 중입니다." + ], "4ad8ced64defdf73": "대화형 3D 기기. 화면을 드래그하여 조작하세요. 화면 밖을 드래그하거나 두 손가락으로 스와이프하면 회전합니다.", "84e4baf07ad8883d": "이 환경에서 시뮬레이터와 에뮬레이터를 열 수 있게 합니다. 이곳에서 실행되든 원격 기기 호스트에서 실행되든 상관없습니다.", "771365c337509a82": "이 환경의 새 에이전트 세션이 로컬 및 원격 기기를 시작하고 제어하도록 허용하며, 필요한 도구는 자동으로 설정됩니다.", diff --git a/apps/web/src/i18n/translations/pt-BR.json b/apps/web/src/i18n/translations/pt-BR.json index 9f2f697d054c0..31a688c1c3314 100644 --- a/apps/web/src/i18n/translations/pt-BR.json +++ b/apps/web/src/i18n/translations/pt-BR.json @@ -5156,6 +5156,10 @@ "4b4ef3f2e2ed2c56": "Iniciar {name}", "08098a6fb84e8a34": "Abrir", "c71a5080b2026870": "Iniciar", + "cfae7ef07c37220e": "outra conversa", + "23d5d026ee80963b": "Assumir controle de {title}", + "01e8d054b2d2f232": "Assumindo controle…", + "746c576ea195806b": "Assumir controle", "a34247bae083cebf": "Dispensar erro do dispositivo", "191353bd8f033118": "As listas de {first} e {second} em {host} podem estar incompletas.", "b17bcd4cbf80442e": "A lista de {platform} em {host} pode estar incompleta.", @@ -5174,6 +5178,33 @@ ], "e902f208c4e6146f": "Nenhum dispositivo virtual Android encontrado. Crie um no Device Manager do Android Studio e atualize.", "d9a71f3db685cb0e": "Atualizar dispositivos", + "ce2da8d9521a3ef4": [ + "Em uso em ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + ", que está em execução." + ], + "5fae5a165e609f5a": [ + "Em uso em ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + ", que não está em execução." + ], + "9c4958e3e914e8e8": [ + "Em uso em ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + "." + ], "4ad8ced64defdf73": "Dispositivo 3D interativo. Arraste a tela para interagir. Arraste fora dela ou deslize com dois dedos para girar.", "84e4baf07ad8883d": "Ative este ambiente para abrir simuladores e emuladores, rodando aqui ou em um host de dispositivos remoto.", "771365c337509a82": "Permite que novas sessões de agente neste ambiente iniciem e controlem dispositivos locais e remotos, com as ferramentas necessárias configuradas automaticamente.", diff --git a/apps/web/src/i18n/translations/ru.json b/apps/web/src/i18n/translations/ru.json index 758380a495682..e2fd54ac99b8c 100644 --- a/apps/web/src/i18n/translations/ru.json +++ b/apps/web/src/i18n/translations/ru.json @@ -5156,6 +5156,10 @@ "4b4ef3f2e2ed2c56": "Запустить {name}", "08098a6fb84e8a34": "Открыть", "c71a5080b2026870": "Запустить", + "cfae7ef07c37220e": "другом потоке", + "23d5d026ee80963b": "Перехватить у {title}", + "01e8d054b2d2f232": "Перехват…", + "746c576ea195806b": "Перехватить", "a34247bae083cebf": "Закрыть ошибку устройства", "191353bd8f033118": "Списки {first} и {second} на {host} могут быть неполными.", "b17bcd4cbf80442e": "Список {platform} на {host} может быть неполным.", @@ -5174,6 +5178,33 @@ ], "e902f208c4e6146f": "Виртуальные устройства Android не найдены. Создайте одно в Device Manager в Android Studio, затем обновите.", "d9a71f3db685cb0e": "Обновить список устройств", + "ce2da8d9521a3ef4": [ + "Занято в ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + ", поток выполняется." + ], + "5fae5a165e609f5a": [ + "Занято в ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + ", поток не выполняется." + ], + "9c4958e3e914e8e8": [ + "Занято в ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + "." + ], "4ad8ced64defdf73": "Интерактивное 3D-устройство. Перетаскивайте экран для взаимодействия. Перетаскивайте вне экрана или проведите двумя пальцами, чтобы повернуть.", "84e4baf07ad8883d": "Включите это окружение, чтобы открывать симуляторы и эмуляторы — локально или на удалённом хосте устройств.", "771365c337509a82": "Разрешить новым сеансам агентов в этом окружении запускать локальные и удалённые устройства и управлять ими; нужные инструменты настраиваются автоматически.", diff --git a/apps/web/src/i18n/translations/sv.json b/apps/web/src/i18n/translations/sv.json index 5aa630e1a6853..689d8aad47c69 100644 --- a/apps/web/src/i18n/translations/sv.json +++ b/apps/web/src/i18n/translations/sv.json @@ -5157,6 +5157,10 @@ "4b4ef3f2e2ed2c56": "Starta {name}", "08098a6fb84e8a34": "Öppna", "c71a5080b2026870": "Starta", + "cfae7ef07c37220e": "en annan tråd", + "23d5d026ee80963b": "Ta över från {title}", + "01e8d054b2d2f232": "Tar över…", + "746c576ea195806b": "Ta över", "a34247bae083cebf": "Stäng enhetsfel", "191353bd8f033118": "Listorna för {first} och {second} på {host} kan vara ofullständiga.", "b17bcd4cbf80442e": "Listan för {platform} på {host} kan vara ofullständig.", @@ -5175,6 +5179,33 @@ ], "e902f208c4e6146f": "Inga virtuella Android-enheter hittades. Skapa en i Android Studios Device Manager och uppdatera sedan.", "d9a71f3db685cb0e": "Uppdatera enheter", + "ce2da8d9521a3ef4": [ + "Upptagen i ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + ", som körs." + ], + "5fae5a165e609f5a": [ + "Upptagen i ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + ", som inte körs." + ], + "9c4958e3e914e8e8": [ + "Upptagen i ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + "." + ], "4ad8ced64defdf73": "Interaktiv enhet i 3D. Dra på skärmen för att interagera. Dra utanför den eller svep med två fingrar för att vrida.", "84e4baf07ad8883d": "Aktivera den här miljön för att öppna simulatorer och emulatorer, oavsett om de körs här eller på en fjärrvärd för enheter.", "771365c337509a82": "Låt nya agentsessioner i den här miljön starta och styra lokala och fjärranslutna enheter, med nödvändiga verktyg konfigurerade automatiskt.", diff --git a/apps/web/src/i18n/translations/zh.json b/apps/web/src/i18n/translations/zh.json index 366a21392f806..5d3102c4c8884 100644 --- a/apps/web/src/i18n/translations/zh.json +++ b/apps/web/src/i18n/translations/zh.json @@ -5163,6 +5163,10 @@ "4b4ef3f2e2ed2c56": "启动 {name}", "08098a6fb84e8a34": "打开", "c71a5080b2026870": "启动", + "cfae7ef07c37220e": "另一个会话", + "23d5d026ee80963b": "从 {title} 接管", + "01e8d054b2d2f232": "正在接管…", + "746c576ea195806b": "接管", "a34247bae083cebf": "关闭设备错误提示", "191353bd8f033118": "{host} 上的 {first} 和 {second} 列表可能不完整。", "b17bcd4cbf80442e": "{host} 上的 {platform} 列表可能不完整。", @@ -5181,6 +5185,33 @@ ], "e902f208c4e6146f": "未找到 Android 虚拟设备。请在 Android Studio 的 Device Manager 中创建一个,然后刷新。", "d9a71f3db685cb0e": "刷新设备", + "ce2da8d9521a3ef4": [ + "正由 ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + " 使用,该会话正在运行。" + ], + "5fae5a165e609f5a": [ + "正由 ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + " 使用,该会话未在运行。" + ], + "9c4958e3e914e8e8": [ + "正由 ", + { + "i": 1, + "k": "_gt_value_1", + "v": "v" + }, + " 使用。" + ], "4ad8ced64defdf73": "可交互的 3D 设备。拖动屏幕进行操作,拖动屏幕外区域或用两指滑动可旋转。", "84e4baf07ad8883d": "启用后,此环境即可打开模拟器,无论它们运行在本机还是远程设备主机上。", "771365c337509a82": "允许此环境中的新智能体会话启动和控制本地及远程设备,并自动准备好所需的工具。", diff --git a/docs/user/devices.md b/docs/user/devices.md index 3130e4aa45c6c..19fc8d35cfb25 100644 --- a/docs/user/devices.md +++ b/docs/user/devices.md @@ -79,6 +79,12 @@ If the thread has several devices open, choose one in the viewer. Closing the viewer stops streaming and leaves the device available to the agent. Device activity also appears in the thread timeline. +Only one thread's agent can drive a device at a time. When another thread also +has the device open, the Device panel and the mobile viewer name that thread +and say whether it is still running; select the name to go there. Choose +**Take over** to close the device there so this thread's agent can use it. An +agent still working in that thread loses the device. + Agents drive the device through the `agent-device` command line. T3 Code installs and starts it only after **Agents can use devices** is on. iOS taps build a small test runner on first use, which takes a couple of minutes diff --git a/packages/client-runtime/src/state/device.ts b/packages/client-runtime/src/state/device.ts index 6a4920caa251c..6b30f76875501 100644 --- a/packages/client-runtime/src/state/device.ts +++ b/packages/client-runtime/src/state/device.ts @@ -1,4 +1,4 @@ -import { type DeviceToolVersions, WS_METHODS } from "@t3tools/contracts"; +import { type DeviceSession, type DeviceToolVersions, WS_METHODS } from "@t3tools/contracts"; import { Atom } from "effect/reactivity"; import type { EnvironmentRegistry } from "../connection/registry.ts"; @@ -150,6 +150,24 @@ export function deviceToolUpdatePolicy( ), ); } + +/** + * Other threads with the same device open. Any of them may hold the agent-device + * claim that refuses this thread's agent with DEVICE_IN_USE; closing their session + * releases it. Android serials repeat across hosts, so the host is part of the match. + */ +export function otherThreadDeviceSessions( + sessions: ReadonlyArray, + session: Pick, +) { + return sessions.filter( + (other) => + other.threadId !== session.threadId && + other.hostId === session.hostId && + other.deviceId === session.deviceId, + ); +} + export const deviceToolUpdateOwnership = msg( "This environment's T3 server chooses device tool versions for itself and its SSH hosts. Update that server to receive newer tool versions; updating only your browser or mobile app does not update a remote server.", );