From a3ad6015bc3c6fd8a840da4789b6ca6a706a1afc Mon Sep 17 00:00:00 2001 From: Roland Tannous Date: Sun, 24 May 2026 13:47:34 +0400 Subject: [PATCH] Studio: fix tsc errors in Phase 4 frontend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two errors surfaced by the frontend build (`tsc -b`) after the Phase 4 commit c74fc13eb landed: src/features/chat/chat-settings-sheet.tsx(449,9): TS2451 — cannot redeclare block-scoped 'activeThreadId'. src/features/rag/stores/rag-store.ts(326,9): TS2774 — condition will always return true since this function is always defined. Fixes - chat-settings-sheet.tsx: an `activeThreadId` declaration already existed near the code-exec section (line 636). Phase 2B's RAG retrieval-section block introduced a second declaration at line 449. The earlier one is needed for the Retrieval block; drop the later redeclaration — downstream code still resolves it via lexical scope. - rag-store.ts subscribeJob: `get().jobUnsubscribers[jobId]` indexes a `Record void>`. Without `noUncheckedIndexedAccess` TS infers the result as the function type (never undefined), so `if (existing)` is always-truthy. Replace with `if (jobId in get().jobUnsubscribers) return;` — same semantics, satisfies TS. --- studio/frontend/src/features/chat/chat-settings-sheet.tsx | 3 ++- studio/frontend/src/features/rag/stores/rag-store.ts | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/studio/frontend/src/features/chat/chat-settings-sheet.tsx b/studio/frontend/src/features/chat/chat-settings-sheet.tsx index dc57de469f..f954670c42 100644 --- a/studio/frontend/src/features/chat/chat-settings-sheet.tsx +++ b/studio/frontend/src/features/chat/chat-settings-sheet.tsx @@ -633,7 +633,8 @@ export function ChatSettingsPanel({ activeExternalProvider.baseUrl, ) && activeExternalProvider.providerType === "openai"; - const activeThreadId = useChatRuntimeStore((s) => s.activeThreadId); + // (activeThreadId is declared earlier in this component — see the + // RAG retrieval-section block above.) const openAiApiKeyForSection = activeExternalProvider ? getExternalProviderApiKey(activeExternalProvider.id) || null : null; diff --git a/studio/frontend/src/features/rag/stores/rag-store.ts b/studio/frontend/src/features/rag/stores/rag-store.ts index 02d6422748..a0434c448f 100644 --- a/studio/frontend/src/features/rag/stores/rag-store.ts +++ b/studio/frontend/src/features/rag/stores/rag-store.ts @@ -322,8 +322,10 @@ export const useRagStore = create((set, get) => ({ }, subscribeJob(jobId, onComplete) { - const existing = get().jobUnsubscribers[jobId]; - if (existing) return; + // Object indexing in TS returns V (not V|undefined) without + // noUncheckedIndexedAccess, so we test membership explicitly to + // avoid the "always-truthy function reference" lint. + if (jobId in get().jobUnsubscribers) return; const unsubscribe = subscribeToJobEvents(jobId, { onEvent: (event) => { set((state) => ({ jobs: { ...state.jobs, [jobId]: event } }));