fix: resolve a new item's chosen name in session preview tools

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
AlexRV12
2026-10-12 11:28:55 +02:00
co-authored by Claude Opus 5.5
parent b347e792f8
commit a3420ca037
@@ -103,6 +103,7 @@ import {
type RawAppRunsProvider,
type RawAppScreenshotRequester
} from '$lib/components/raw_apps/utils'
import { resolveGlobalDraftStoragePathByKind } from '$lib/components/copilot/chat/global/userDraftAdapter'
import type {
RawAppDomQuery,
RawAppDomRequester,
@@ -1120,7 +1121,7 @@ function createRuntime(session: Session): SessionRuntime {
},
async requestRuntimeLogs(limit, appPath) {
const path =
appPath ??
(appPath && draftStoragePath(session, 'raw_app', appPath)) ??
activeDomAppPath ??
(runtimeLogRequesters.size === 1 ? [...runtimeLogRequesters.keys()][0] : undefined)
if (path === undefined) {
@@ -1156,7 +1157,7 @@ function createRuntime(session: Session): SessionRuntime {
// its element's app even when another tab is now visible), else the
// active preview, else the only one open.
const path =
query.appPath ??
(query.appPath && draftStoragePath(session, 'raw_app', query.appPath)) ??
activeDomAppPath ??
(domRequesters.size === 1 ? [...domRequesters.keys()][0] : undefined)
if (path === undefined) return undefined
@@ -1372,6 +1373,18 @@ export function removeSession(sessionId: string): void {
deleteSessionState(sessionId)
}
// The chat calls a new item by its chosen name while its draft is stored at
// `draft_<uuid>`; resolve the name the way the chat's write tools do.
function draftStoragePath(
session: Session,
kind: 'script' | 'flow' | 'raw_app',
path: string
): string {
return session.workspace_id
? resolveGlobalDraftStoragePathByKind(session.workspace_id, kind, path)
: path
}
// Register the global open_preview tool handler once at module load. It
// dispatches to the *calling* session (sessionId threaded from the tool ctx),
// falling back to the UI-active session only when none was passed — so a
@@ -1387,7 +1400,10 @@ setOpenPreviewHandler(async ({ sessionId: callerSessionId, kind, path, mode }) =
if (!session) {
return 'Error: no active session to open the preview in.'
}
const target = previewTargetForSessionTarget(kind, path)
const target = previewTargetForSessionTarget(
kind,
mode === 'view' || kind === 'pipeline' ? path : draftStoragePath(session, kind, path)
)
if (!target) {
return `Error: ${kind} targets cannot be shown in the preview panel.`
}