The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(desktop): one script runner into the preview guest page, not a tour-only one
Brooklyn Nicholson90e30bdd2777
diff --git a/apps/desktop/src/app/chat/right-rail/preview-pane.tsx b/apps/desktop/src/app/chat/right-rail/preview-pane.tsxindex 7d6150b2f33..e2f236cf2fa 100644--- a/apps/desktop/src/app/chat/right-rail/preview-pane.tsx+++ b/apps/desktop/src/app/chat/right-rail/preview-pane.tsx@@ -30,7 +30,7 @@ import { previewConsoleState } from './preview-console-store'import { LocalFilePreview, PreviewEmptyState } from './preview-file'import { PREVIEW_BROWSER_ATTR, registerPreviewNav } from './preview-nav'import { registerPreviewPageReader } from './preview-reader'-import { registerPreviewTourRunner } from './preview-tour-runner'+import { registerPreviewScriptRunner } from './preview-script-runner'type PreviewWebview = HTMLElement & {canGoBack?: () => boolean@@ -455,15 +455,15 @@ export function PreviewPane({ embedded = false, onRestartServer, reloadRequest =})}, [isWebPreview, tabId])- // Publish the TOUR runner for this tab (the tour tool, surface='preview'):- // runs injected driver.js actions inside the guest page so the agent can- // give guided walkthroughs of whatever web app is open here.+ // Publish the SCRIPT runner for this tab: the one channel into the guest+ // page, shared by the tour tool (injected driver.js walkthroughs) and the+ // act_preview tool (clicking, typing, scrolling the page the user sees).useEffect(() => {if (!isWebPreview || !tabId) {return}- return registerPreviewTourRunner(tabId, async code => {+ return registerPreviewScriptRunner(tabId, async code => {const webview = webviewRef.currentif (!webview?.executeJavaScript) {diff --git a/apps/desktop/src/app/chat/right-rail/preview-script-runner.ts b/apps/desktop/src/app/chat/right-rail/preview-script-runner.tsnew file mode 100644index 00000000000..69a0efa2a4e--- /dev/null+++ b/apps/desktop/src/app/chat/right-rail/preview-script-runner.ts@@ -0,0 +1,38 @@+/**+ * PREVIEW SCRIPT RUNNER REGISTRY — the one way anything in the app reaches into+ * the preview pane's guest page, the script analog of preview-nav's handle+ * registry.+ *+ * A live browser pane registers its webview's `executeJavaScript` here, keyed+ * by tab id; `activePreviewScriptRunner` resolves the ACTIVE tab from the+ * store. Both guest-page features ride it — the tour tool (preview-tour.ts)+ * and the interaction tool (preview-act.ts) — so their heavy payloads stay out+ * of the pane component's static import graph and only load when used.+ */++import { $rightRailActiveTabId } from '@/store/layout'+import { $previewTabs } from '@/store/preview'++/** Runs JS source in the pane's guest page, resolving its completion value. */+export type PreviewScriptRunner = (code: string) => Promise<unknown>++const runners = new Map<string, PreviewScriptRunner>()++/** Register a live preview's script runner; returns an idempotent unregister. */+export function registerPreviewScriptRunner(tabId: string, runner: PreviewScriptRunner): () => void {+ runners.set(tabId, runner)++ return () => {+ if (runners.get(tabId) === runner) {+ runners.delete(tabId)+ }+ }+}++/** The ACTIVE preview tab's script runner. Null = no live page behind it. */+export function activePreviewScriptRunner(): PreviewScriptRunner | null {+ const tabs = $previewTabs.get()+ const tab = tabs.find(t => t.id === $rightRailActiveTabId.get()) ?? tabs[0]++ return (tab && runners.get(tab.id)) || null+}diff --git a/apps/desktop/src/app/chat/right-rail/preview-tour-runner.ts b/apps/desktop/src/app/chat/right-rail/preview-tour-runner.tsdeleted file mode 100644index 84a15c88699..00000000000--- a/apps/desktop/src/app/chat/right-rail/preview-tour-runner.ts+++ /dev/null@@ -1,38 +0,0 @@-/**- * PREVIEW TOUR RUNNER REGISTRY — the tour tool's script bridge into the- * preview pane, the tour analog of preview-nav's handle registry.- *- * A live browser pane registers a script runner (its webview's- * `executeJavaScript`) here, keyed by tab id; `activeTourRunner` resolves the- * ACTIVE tab from the store. Kept separate from preview-tour.ts so the pane- * component's static import stays tiny — the engine source + driver.js- * payload only load when a tour actually runs (gateway-event dynamic-imports- * preview-tour.ts).- */--import { $rightRailActiveTabId } from '@/store/layout'-import { $previewTabs } from '@/store/preview'--/** Runs JS source in the pane's guest page, resolving its completion value. */-export type TourScriptRunner = (code: string) => Promise<unknown>--const runners = new Map<string, TourScriptRunner>()--/** Register a live preview's script runner; returns an idempotent unregister. */-export function registerPreviewTourRunner(tabId: string, runner: TourScriptRunner): () => void {- runners.set(tabId, runner)-- return () => {- if (runners.get(tabId) === runner) {- runners.delete(tabId)- }- }-}--/** The ACTIVE preview tab's script runner. Null = no live page to tour. */-export function activeTourRunner(): TourScriptRunner | null {- const tabs = $previewTabs.get()- const tab = tabs.find(t => t.id === $rightRailActiveTabId.get()) ?? tabs[0]-- return (tab && runners.get(tab.id)) || null-}diff --git a/apps/desktop/src/app/chat/right-rail/preview-tour.ts b/apps/desktop/src/app/chat/right-rail/preview-tour.tsindex 12ad67dc71c..a033a7c1f85 100644--- a/apps/desktop/src/app/chat/right-rail/preview-tour.ts+++ b/apps/desktop/src/app/chat/right-rail/preview-tour.ts@@ -21,7 +21,7 @@ import driverIife from 'driver.js/dist/driver.js.iife.js?raw'import { collectTourTargets } from '@/lib/tour/collect-targets'import { runTourEngine, type TourAction, type TourResult } from '@/lib/tour/engine'-import { activeTourRunner } from './preview-tour-runner'+import { activePreviewScriptRunner } from './preview-script-runner'/** Build the idempotent inject-and-run script for one tour action. */function buildTourScript(action: TourAction): string {@@ -51,7 +51,7 @@ function buildTourScript(action: TourAction): string {/** Run one tour action in the ACTIVE preview tab's page. */export async function runPreviewTour(action: TourAction): Promise<TourResult> {- const run = activeTourRunner()+ const run = activePreviewScriptRunner()if (!run) {return { error: 'No live page is open in the preview pane — open one first.', success: false }