From cba77e78cb1b3b8be968e72c7b805acea70832d1 Mon Sep 17 00:00:00 2001 From: mustafab0 Date: Wed, 18 Nov 2026 09:27:38 -0800 Subject: [PATCH 1/3] URL options for embedding: ?robot= and ?onboarding=off robot= makes this page use that robot type without saving it (lv.view.robot is left to the other pages); unknown values are ignored. onboarding=off hides the first-run message cards and the 3D view's "Waiting for lidar data." overlay; the onboarding result still holds driving when nothing can be driven. For the Manipulation app, which embeds the Controller as ../dim-controller/?robot=arm&onboarding=off. --- docs/reference.md | 8 ++++++++ frontend/src/App.tsx | 3 ++- frontend/src/core/driveCore.ts | 13 +++++++++---- frontend/src/core/urlOptions.ts | 19 +++++++++++++++++++ frontend/src/ui/ScenePanel.tsx | 3 ++- frontend/test/urlOptions.test.ts | 9 +++++++++ 6 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 frontend/src/core/urlOptions.ts create mode 100644 frontend/test/urlOptions.test.ts diff --git a/docs/reference.md b/docs/reference.md index 67f06e7..18bc4ef 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -19,6 +19,14 @@ app's data dir), so a change from the agent or another window shows up in every continuous driving from the keys and sticks, which publishes through the gateway at 20 Hz with the gateway's deadman; `POST api/drive` is the endpoint way to drive (a Twist for up to 10 s, then zeros; `dryRun` sends nothing). +## URL options + +For an app that shows the Controller in an iframe, e.g. `../dim-controller/?robot=arm&onboarding=off` +([core/urlOptions.ts](../frontend/src/core/urlOptions.ts)): + +- `robot=` (`dog`, `humanoid`, `wheeled`, `arm`, `drone`): this page uses that [controller format](#controller-format), saved nowhere (other pages keep theirs). +- `onboarding=off`: no first-run message cards and no "Waiting for lidar data." in the 3D view; driving is still held when nothing can be driven. + ## What it shows Every dimos topic is `dimos//` on zenoh, so the key says how to draw it. Each message type has a diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 7f5b17e..761096a 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -36,6 +36,7 @@ import { cameraId, FIXED_PANELS, plotId } from "./ui/workspace.ts" import type { RunState } from "./core/runs.ts" import { openOverlay } from "./ui/overlay.ts" import { ContainCrash } from "./ui/Unavailable.tsx" +import { urlOptions } from "./core/urlOptions.ts" declare global { interface Window { @@ -146,7 +147,7 @@ function Driving({ app, api }: { app: ViewerApp; api: WorkspaceApi }) { {api.mobile ? !onboarding.blocksDriving && (isArm ? : ) : <>} - {onboarding.message && ( + {onboarding.message && !urlOptions.onboardingOff && (
diff --git a/frontend/src/core/driveCore.ts b/frontend/src/core/driveCore.ts index 5cae4fc..abf90c2 100644 --- a/frontend/src/core/driveCore.ts +++ b/frontend/src/core/driveCore.ts @@ -16,6 +16,7 @@ import type { RobotProfile, RobotType } from "../profile/types.ts" import { checkLink, DEFAULT_MAX_LATENCY_MS, LINK_CHECK_MS, maxLatencyOf } from "./linkWatch.ts" import type { ResolvedType, RobotsAnswer } from "./robotType.ts" import { robotsAnswer } from "./robotType.ts" +import { urlOptions } from "./urlOptions.ts" export interface ViewSettings { /** the robot type picked in Settings (a RobotType), "" = auto (core/robotType.ts) */ @@ -140,15 +141,18 @@ export class DriveCore { } } - /** Always the wheeled base's controls (Jeff 10-26: no format picker; drones come later). The auto-detection - * (core/robotType.ts resolveType) stays for when more formats return. */ + /** The type this page's URL asks for (?robot=arm), else the wheeled base's controls (Jeff 10-26: no format + * picker; drones come later). The auto-detection (core/robotType.ts resolveType) stays for when more formats return. */ #resolve(): ResolvedType { + if (urlOptions.robot) { + return { type: urlOptions.robot, reason: `this page's URL (?robot=${urlOptions.robot})` } + } return { type: "wheeled", reason: "the wheeled base controls" } } #updateRobot() { const resolved = this.#resolve() - const auto = true + const auto = !urlOptions.robot const current = this.robot.get() if (current.type !== resolved.type || current.reason !== resolved.reason || current.auto !== auto) { this.robot.set({ type: resolved.type, auto, reason: resolved.reason }) @@ -158,7 +162,8 @@ export class DriveCore { this.drive.setProfile(this.#profile) this.profileChanged.forEach((changed) => changed(this.#profile)) } - if (this.settings.get().robot !== resolved.type && typeof location !== "undefined") { + // a type from the URL is this page's alone: the shared lv.view.robot keeps the other pages' type + if (!urlOptions.robot && this.settings.get().robot !== resolved.type && typeof location !== "undefined") { this.settings.update({ robot: resolved.type }) } } diff --git a/frontend/src/core/urlOptions.ts b/frontend/src/core/urlOptions.ts new file mode 100644 index 0000000..8906ca3 --- /dev/null +++ b/frontend/src/core/urlOptions.ts @@ -0,0 +1,19 @@ +// Options in this page's own URL, for an app that shows the Controller in an iframe (docs/reference.md, "URL options"). +import type { RobotType } from "../profile/types.ts" +import { chosenType } from "./robotType.ts" + +export interface UrlOptions { + /** ?robot=: this page uses that robot type, saved nowhere; null when not given or not a robot type */ + robot: RobotType | null + /** ?onboarding=off: no first-run message cards, and no "Waiting for lidar data." in the 3D view */ + onboardingOff: boolean +} + +/** A query string (`location.search`) → its options. */ +export function readUrlOptions(search: string): UrlOptions { + const params = new URLSearchParams(search) + return { robot: chosenType(params.get("robot")), onboardingOff: params.get("onboarding") === "off" } +} + +/** This page's options (none in unit tests, which have no page). */ +export const urlOptions = readUrlOptions(typeof location === "undefined" ? "" : location.search) diff --git a/frontend/src/ui/ScenePanel.tsx b/frontend/src/ui/ScenePanel.tsx index eecfcfd..dea571a 100644 --- a/frontend/src/ui/ScenePanel.tsx +++ b/frontend/src/ui/ScenePanel.tsx @@ -38,6 +38,7 @@ import { jointControlState } from "../core/jointControl.ts" import { SceneSettings } from "./SettingsPanel.tsx" import { SnapshotTools } from "./SnapshotGallery.tsx" import { saveSnapshot, snapshot3d } from "../core/snapshots.ts" +import { urlOptions } from "../core/urlOptions.ts" const isCloud = (entry: LayerEntry) => entry.topic.type === "sensor_msgs.PointCloud2" @@ -98,7 +99,7 @@ export function ScenePanel({ host, app, onTf }: { host: RefObject} {app && !off && } {app && !off && } - {app && !off && } + {app && !off && !urlOptions.onboardingOff && } {app && menuOpen && !off && setMenuOpen(false)} />} diff --git a/frontend/test/urlOptions.test.ts b/frontend/test/urlOptions.test.ts new file mode 100644 index 0000000..7cd362b --- /dev/null +++ b/frontend/test/urlOptions.test.ts @@ -0,0 +1,9 @@ +// The page's URL options (core/urlOptions.ts): ?robot= and ?onboarding=off; anything else changes nothing. +import { assertEquals } from "jsr:@std/assert@1" +import { readUrlOptions } from "../src/core/urlOptions.ts" + +Deno.test("url options: a known robot type and onboarding=off; unknown values are ignored", () => { + assertEquals(readUrlOptions("?robot=arm&onboarding=off"), { robot: "arm", onboardingOff: true }) + assertEquals(readUrlOptions("?robot=car&onboarding=no"), { robot: null, onboardingOff: false }) + assertEquals(readUrlOptions(""), { robot: null, onboardingOff: false }) +}) From f71d6a2a1872ba9f7861618a93c91d49996f94f6 Mon Sep 17 00:00:00 2001 From: mustafab0 Date: Wed, 18 Nov 2026 09:31:00 -0800 Subject: [PATCH 2/3] Record is disabled while nothing is running With no Launcher run and no robot data on the bus, the Record button (bar and phone) and the palette's Start recording no longer start an empty recording; the button's title says "Nothing to record: launch a blueprint first". A blueprint run from a terminal still counts, and a recording under way can always be stopped. The "nothing running" test Onboarding used is now core/runs.ts nothingRunning, shared by both. --- frontend/src/core/recordFormat.ts | 8 ++++++-- frontend/src/core/runs.ts | 6 ++++++ frontend/src/ui/Onboarding.tsx | 8 ++++---- frontend/src/ui/RecordControl.tsx | 9 ++++++--- frontend/src/ui/useCommands.ts | 5 ++++- frontend/test/record.test.ts | 8 +++++--- 6 files changed, 31 insertions(+), 13 deletions(-) diff --git a/frontend/src/core/recordFormat.ts b/frontend/src/core/recordFormat.ts index 88bbd29..7787c1d 100644 --- a/frontend/src/core/recordFormat.ts +++ b/frontend/src/core/recordFormat.ts @@ -33,10 +33,13 @@ export function inRecordingsFolder(directory: string, root: string | null): bool return directory === trimmed || directory.startsWith(`${trimmed}/`) } +/** Why Record can't start with nothing running (the button's title, the palette's note). */ +export const NOTHING_TO_RECORD = "Nothing to record: launch a blueprint first" /** * The Record toggle's state, the bar's and the phone HUD's alike: recording (and for how long), the short text, and * whether it can be pressed (not while starting / stopping, not with the recorder down, not with nothing to record). + * `idle`: nothing is running (core/runs.ts nothingRunning), so a new recording would be empty. */ export function recordToggleState(input: { active: boolean @@ -45,8 +48,9 @@ export function recordToggleState(input: { recordNew: boolean selected: number seconds: number + idle: boolean }): { recording: boolean; text: string; disabled: boolean } { - const { active, pending, unavailable, recordNew, selected, seconds } = input + const { active, pending, unavailable, recordNew, selected, seconds, idle } = input const text = pending === "start" ? "Starting…" : pending === "stop" ? "Stopping…" : active ? formatClock(seconds) : "REC" - return { recording: active, text, disabled: pending !== null || !!unavailable || (!active && !recordNew && selected === 0) } + return { recording: active, text, disabled: pending !== null || !!unavailable || (!active && (idle || (!recordNew && selected === 0))) } } diff --git a/frontend/src/core/runs.ts b/frontend/src/core/runs.ts index e640386..7a05642 100644 --- a/frontend/src/core/runs.ts +++ b/frontend/src/core/runs.ts @@ -111,6 +111,12 @@ export class RunWatch { } } +/** Nothing running: no blueprint the Launcher started and no robot data on the bus (a blueprint run from a terminal, + * `dimos run` / `dtk run`, sends some; /rpc and /dimos/ topics are dimos's own). */ +export function nothingRunning(state: RunState, topics: { name: string }[]): boolean { + return state.running.length === 0 && !topics.some((topic) => !/^\/rpc\b|^\/dimos\//.test(topic.name)) +} + /** A running blueprint has dimos's ManipulationModule (the arm planner viser sits on): the controller's Plan and move * shows whatever the controller format, since a robot that drives can have arms too (an R1 Pro's nav). */ export function plannerRunning(state: RunState): boolean { diff --git a/frontend/src/ui/Onboarding.tsx b/frontend/src/ui/Onboarding.tsx index a227654..55909ee 100644 --- a/frontend/src/ui/Onboarding.tsx +++ b/frontend/src/ui/Onboarding.tsx @@ -7,6 +7,7 @@ import type { ViewerApp } from "../core/app.ts" import { useStore } from "../core/store.ts" import { appInstalled, type EmptyStateOptions, openApp, underDesktop } from "dimos-react/dim-app/desktop.js" import { takesVelocity } from "../core/cmdvel.ts" +import { nothingRunning } from "../core/runs.ts" const LAUNCH_DRIVABLE = { stream: "cmd_vel" } const LAUNCH_ARM = { stream: "joint_command" } @@ -160,13 +161,12 @@ export function useOnboarding(app: ViewerApp): Onboarding { }, } } - // nothing the Launcher started, but robot data is flowing: a blueprint run from a terminal (dimos run / dtk run) - const outside = runs.running.length === 0 && connection.topics.some((topic) => !/^\/rpc\b|^\/dimos\//.test(topic.name)) - if (runs.running.length === 0 && !outside && noBlueprintDismissed) { + const nothing = nothingRunning(runs, connection.topics) + if (nothing && noBlueprintDismissed) { // dismissed: the 3D view shows whatever topics exist; there's nothing to drive, so no key guide return { message: null, blocksDriving: true, reason: isArm ? "no arm blueprint is running" : "no blueprint with a cmd_vel input is running", launch } } - if (runs.running.length === 0 && !outside) { + if (nothing) { return { blocksDriving: true, reason: isArm ? "no arm blueprint is running" : "no blueprint with a cmd_vel input is running", diff --git a/frontend/src/ui/RecordControl.tsx b/frontend/src/ui/RecordControl.tsx index 53590f5..cc7d955 100644 --- a/frontend/src/ui/RecordControl.tsx +++ b/frontend/src/ui/RecordControl.tsx @@ -6,7 +6,8 @@ import { useEffect, useRef, useState } from "react" import type { ViewerApp } from "../core/app.ts" import { persistentStore, useStore } from "../core/store.ts" import { recorder, type Compression, type ImageFormat, type StreamRate } from "../core/recorder.ts" -import { biggestStreams, formatBytes, formatClock, formatRate, inRecordingsFolder, isRecorded, isRpcTopic, recordToggleState, TOP_STREAMS } from "../core/recordFormat.ts" +import { biggestStreams, formatBytes, formatClock, formatRate, inRecordingsFolder, isRecorded, isRpcTopic, NOTHING_TO_RECORD, recordToggleState, TOP_STREAMS } from "../core/recordFormat.ts" +import { nothingRunning } from "../core/runs.ts" import type { Topic } from "../core/transport.ts" import { Alert, Badge, Button, Card, Checkbox, Field, Heading, Label, NumberInput, Select, Text, TextInput, Toggle } from "dimos-react" import { Icon } from "./icons.tsx" @@ -35,6 +36,8 @@ export function RecordControl({ app }: { app: ViewerApp }) { const active = status.recording.active const selected = topics.filter((topic) => isRecorded(topic.key, chosen)) const busy = pending.action !== null + const runs = useStore(app.runs.state) + const idle = nothingRunning(runs, topics) // a hash link (#record, as other apps open it with) opens the options useEffect(() => { @@ -66,10 +69,10 @@ export function RecordControl({ app }: { app: ViewerApp }) { variant={active ? "danger" : "default"} className={`record-toggle ${active ? "recording" : ""} ${busy ? "pending" : ""}`} pressed={active} - title={status.unavailable ?? (error ? `${label}: ${error}` : label)} + title={status.unavailable ?? (!active && idle ? NOTHING_TO_RECORD : error ? `${label}: ${error}` : label)} aria-label={label} // with new streams joining, a recording can start before anything is on the bus: they join as they appear - disabled={recordToggleState({ active, pending: pending.action, unavailable: status.unavailable, recordNew: status.options.recordNew, selected: selected.length, seconds: status.recording.seconds }).disabled} + disabled={recordToggleState({ active, pending: pending.action, unavailable: status.unavailable, recordNew: status.options.recordNew, selected: selected.length, seconds: status.recording.seconds, idle }).disabled} onClick={toggle} > diff --git a/frontend/src/ui/useCommands.ts b/frontend/src/ui/useCommands.ts index da68126..4b7b55f 100644 --- a/frontend/src/ui/useCommands.ts +++ b/frontend/src/ui/useCommands.ts @@ -4,6 +4,8 @@ import type { ViewerApp } from "../core/app.ts" import { useStore } from "../core/store.ts" import { recorder } from "../core/recorder.ts" +import { NOTHING_TO_RECORD } from "../core/recordFormat.ts" +import { nothingRunning } from "../core/runs.ts" import { cameraTabs } from "../core/cameraChoice.ts" import { profiles } from "../profile/index.ts" import { type Command, panelCommands, panelTitle } from "./commands.ts" @@ -27,6 +29,7 @@ export function useCommands(app: ViewerApp, api: WorkspaceApi, cameras: CameraAc const recording = useStore(recorder.status) const view = useStore(app.settings) const connection = useStore(app.connection.status) + const runs = useStore(app.runs.state) const arm = app.profile.type === "arm" const focused = api.view.hide.length === 2 const offered = useStore(dockActions) @@ -103,7 +106,7 @@ export function useCommands(app: ViewerApp, api: WorkspaceApi, cameras: CameraAc id: "record.toggle", label: recording.recording.active ? "Stop recording" : "Start recording", group: "Record", - blocked: recording.unavailable ?? undefined, + blocked: recording.unavailable ?? (!recording.recording.active && nothingRunning(runs, connection.topics) ? NOTHING_TO_RECORD : undefined), words: "mcap capture", run: () => void toggleRecording(app).catch(() => {}), }, diff --git a/frontend/test/record.test.ts b/frontend/test/record.test.ts index c85a81c..e6a1080 100644 --- a/frontend/test/record.test.ts +++ b/frontend/test/record.test.ts @@ -47,15 +47,17 @@ Deno.test("numbers read at a glance", () => { }) Deno.test("the Record toggle (bar and phone HUD): REC at rest, the time while recording, and held while it starts or stops", () => { - const rest = { active: false, pending: null, unavailable: null, recordNew: true, selected: 0, seconds: 0 } as const + const rest = { active: false, pending: null, unavailable: null, recordNew: true, selected: 0, seconds: 0, idle: false } as const assertEquals(recordToggleState(rest), { recording: false, text: "REC", disabled: false }) assertEquals(recordToggleState({ ...rest, active: true, seconds: 75 }), { recording: true, text: formatClock(75), disabled: false }) assertEquals(recordToggleState({ ...rest, pending: "start" }), { recording: false, text: "Starting…", disabled: true }) assertEquals(recordToggleState({ ...rest, active: true, pending: "stop" }), { recording: true, text: "Stopping…", disabled: true }) - // the recorder down, or nothing chosen without new streams joining: can't start + // the recorder down, nothing running, or nothing chosen without new streams joining: can't start assert(recordToggleState({ ...rest, unavailable: "recorder down" }).disabled) + assert(recordToggleState({ ...rest, idle: true }).disabled) assert(recordToggleState({ ...rest, recordNew: false }).disabled) assert(!recordToggleState({ ...rest, recordNew: false, selected: 3 }).disabled) - // a recording can always be stopped, even if every stream was turned off since + // a recording can always be stopped, even if every stream was turned off or the blueprint stopped since assert(!recordToggleState({ ...rest, active: true, recordNew: false }).disabled) + assert(!recordToggleState({ ...rest, active: true, idle: true }).disabled) }) From 6a5e5cb9b0cfd2d5ae394fbe2cd6b850386539ea Mon Sep 17 00:00:00 2001 From: mustafab0 Date: Wed, 18 Nov 2026 12:16:17 -0800 Subject: [PATCH 3/3] Nothing running ignores the page's own request topics The Controller asks for the robot's model and named locations on /render_file_request, /file_request and /named_locations_request even when nothing runs. Those topics made nothingRunning false, so Record stayed enabled and the no-blueprint card never showed while idle. Topics ending in _request are now not counted as robot data. --- frontend/src/core/runs.ts | 5 +++-- frontend/test/record.test.ts | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/frontend/src/core/runs.ts b/frontend/src/core/runs.ts index 7a05642..da6d810 100644 --- a/frontend/src/core/runs.ts +++ b/frontend/src/core/runs.ts @@ -112,9 +112,10 @@ export class RunWatch { } /** Nothing running: no blueprint the Launcher started and no robot data on the bus (a blueprint run from a terminal, - * `dimos run` / `dtk run`, sends some; /rpc and /dimos/ topics are dimos's own). */ + * `dimos run` / `dtk run`, sends some). Not robot data: /rpc and /dimos/ topics (dimos's own) and topics ending in + * _request (questions apps ask the robot, such as this page's /render_file_request for the robot's model). */ export function nothingRunning(state: RunState, topics: { name: string }[]): boolean { - return state.running.length === 0 && !topics.some((topic) => !/^\/rpc\b|^\/dimos\//.test(topic.name)) + return state.running.length === 0 && !topics.some((topic) => !/^\/rpc\b|^\/dimos\/|_request$/.test(topic.name)) } /** A running blueprint has dimos's ManipulationModule (the arm planner viser sits on): the controller's Plan and move diff --git a/frontend/test/record.test.ts b/frontend/test/record.test.ts index e6a1080..f766e27 100644 --- a/frontend/test/record.test.ts +++ b/frontend/test/record.test.ts @@ -3,6 +3,7 @@ import { assert, assertEquals } from "jsr:@std/assert@1" import { biggestStreams, formatClock, formatRate, inRecordingsFolder, isRecorded, isRpcTopic, recordToggleState, TOP_STREAMS } from "../src/core/recordFormat.ts" import type { StreamRate } from "../src/core/recorder.ts" +import { nothingRunning, type RunState } from "../src/core/runs.ts" const stream = (topic: string, bytesPerSecond: number): StreamRate => ({ key: `dimos${topic}/x.Y`, @@ -61,3 +62,10 @@ Deno.test("the Record toggle (bar and phone HUD): REC at rest, the time while re assert(!recordToggleState({ ...rest, active: true, recordNew: false }).disabled) assert(!recordToggleState({ ...rest, active: true, idle: true }).disabled) }) + +Deno.test("nothing running: the page's own requests and dimos's topics on the bus aren't a robot", () => { + const none: RunState = { known: true, desktop: true, dimosInstalled: true, running: [], starting: null, blueprints: {} } + const asks = ["/render_file_request", "/file_request", "/named_locations_request", "/rpc/x", "/dimos/logs"].map((name) => ({ name })) + assert(nothingRunning(none, asks)) + assert(!nothingRunning(none, [...asks, { name: "/color_image" }])) +})