The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tour): built-in tour no longer opens over a chat the user switched to (review)
alt-glitchbf81f4b2c9d2
diff --git a/apps/desktop/src/app/chat/built-in-tour.ts b/apps/desktop/src/app/chat/built-in-tour.tsindex 36c972f3d9a..2f3c21fd550 100644--- a/apps/desktop/src/app/chat/built-in-tour.ts+++ b/apps/desktop/src/app/chat/built-in-tour.ts@@ -86,8 +86,14 @@ async function canRunLocalModel(): Promise<boolean> {}/** Run the built-in tour. Never throws; failures come back like any tour- * action's, so the agent can say so in words. */-export async function runBuiltInTour(preset: TourPreset): Promise<TourResult> {+ * action's, so the agent can say so in words. `stillActive` is asked again+ * after the local-model wait: a chat switch during it answers `notActiveError`+ * instead of opening the tour over the other chat. */+export async function runBuiltInTour(+ preset: TourPreset,+ stillActive: () => boolean,+ notActiveError: string+): Promise<TourResult> {const stops = PRESET_STOPS[preset]().filter(id => onScreen(SELECTORS[id]))if (stops.length === 0) {@@ -95,6 +101,11 @@ export async function runBuiltInTour(preset: TourPreset): Promise<TourResult> {}const localLine = stops.includes('model') && (await canRunLocalModel())++ if (!stillActive()) {+ return { error: notActiveError, success: false }+ }+const copy = runtimeTranslations().appTourreturn startTour(diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/server-requests.ts b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/server-requests.tsindex fd8484b13de..b9d42359fe0 100644--- a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/server-requests.ts+++ b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/server-requests.ts@@ -615,7 +615,9 @@ const windowRead: Handler = ({ request }) => {)}-const tour: Handler = ({ isActiveSession, request, sessionId }) => {+const NOT_ACTIVE_TOUR_ERROR = 'Tours only run in the session the user is looking at.'++const tour: Handler = ({ deps, isActiveSession, request, sessionId }) => {// tour tool: one guided-tour action via driver.js, app DOM or preview guest// page. Active session only, same window-ownership rule as preview.act// (WINDOW_OWNED_REQUESTS).@@ -630,19 +632,29 @@ const tour: Handler = ({ isActiveSession, request, sessionId }) => {}if (!isActiveSession) {- answerValue(request, { error: 'Tours only run in the session the user is looking at.', success: false })+ answerValue(request, { error: NOT_ACTIVE_TOUR_ERROR, success: false })return}const kind = (str(p.action) || 'stop') as TourAction['kind']+ // The built-in tour waits for local-model data before it opens, and the user+ // may switch chats meanwhile: ask again, against the live active id.+ const stillActive = () =>+ requestNamesActiveSession({+ activeSessionId: deps.activeSessionIdRef.current,+ sessionId,+ storedIdForRuntimeId: runtimeId =>+ deps.sessionStateByRuntimeIdRef.current.get(runtimeId)?.storedSessionId ?? undefined+ })+// start with no steps is the app's own tour: one call, the app owns the stops.// The backend validated `preset`; absent means full.const run =kind === 'start' && !Array.isArray(p.steps)? import('@/app/chat/built-in-tour').then(({ runBuiltInTour }) =>- runBuiltInTour(p.preset === 'quick' ? 'quick' : 'full')+ runBuiltInTour(p.preset === 'quick' ? 'quick' : 'full', stillActive, NOT_ACTIVE_TOUR_ERROR)): import('@/lib/tour').then(({ runTour }) =>runTour(diff --git a/apps/shared/src/gateway-contract.generated.ts b/apps/shared/src/gateway-contract.generated.tsindex 3ff1bce356e..f9a22a43fb0 100644--- a/apps/shared/src/gateway-contract.generated.ts+++ b/apps/shared/src/gateway-contract.generated.ts@@ -4509,7 +4509,7 @@ export interface TourStep {side?: string | null[key: string]: unknown}-/** Which built-in tour ``start`` without steps runs. The wire contract imports this enum. */+/** Which built-in tour ``start`` without steps runs. */export type TourPreset = 'quick' | 'full'export interface DisplayInstallSudoParams {session_id: stringdiff --git a/apps/shared/src/gateway-contract.openrpc.json b/apps/shared/src/gateway-contract.openrpc.jsonindex 8a00ed09f29..9e248eeebf4 100644--- a/apps/shared/src/gateway-contract.openrpc.json+++ b/apps/shared/src/gateway-contract.openrpc.json@@ -36904,7 +36904,7 @@"type": "object"},"TourPreset": {- "description": "Which built-in tour ``start`` without steps runs. The wire contract imports this enum.",+ "description": "Which built-in tour ``start`` without steps runs.","enum": ["quick","full"diff --git a/tools/tour_presets.py b/tools/tour_presets.pynew file mode 100644index 00000000000..bd64ad8f57c--- /dev/null+++ b/tools/tour_presets.py@@ -0,0 +1,15 @@+"""The built-in tour presets ``gui_tour`` start-without-steps accepts.++A leaf module with no ``registry.register``: the wire contract+(``tui_gateway/contracts/server_requests.py``) imports this enum, and importing+``tools/tour_tool.py`` there would register ``gui_tour`` as a side effect.+"""++from enum import StrEnum+++class TourPreset(StrEnum):+ """Which built-in tour ``start`` without steps runs."""++ quick = "quick"+ full = "full"diff --git a/tools/tour_tool.py b/tools/tour_tool.pyindex abe469b1841..64c05959647 100644--- a/tools/tour_tool.py+++ b/tools/tour_tool.py@@ -8,24 +8,17 @@ tour covers the whole screen, so "off" must mean the model is never told the toothan offered a call that fails."""import json-from enum import StrEnumfrom typing import Callable, Optionalfrom tools import desktop_uifrom tools.registry import registry, tool_error+from tools.tour_presets import TourPresetACTIONS = ("targets", "show", "start", "next", "prev", "stop")SURFACES = ("app", "preview")SIDES = ("top", "right", "bottom", "left")-class TourPreset(StrEnum):- """Which built-in tour ``start`` without steps runs. The wire contract imports this enum."""-- quick = "quick"- full = "full"--PRESETS = tuple(TourPreset)diff --git a/tui_gateway/contracts/server_requests.py b/tui_gateway/contracts/server_requests.pyindex 1bfaad225e7..32569dc9ba0 100644--- a/tui_gateway/contracts/server_requests.py+++ b/tui_gateway/contracts/server_requests.py@@ -9,7 +9,7 @@ from __future__ import annotationsfrom pydantic import Field-from tools.tour_tool import TourPreset+from tools.tour_presets import TourPresetfrom .base import JsonValue, Params, Payload, Result, WireEnumfrom .registry import event, server_request