From a09a57b7beea7010a667fbfb6670cae82128445d Mon Sep 17 00:00:00 2001 From: Byron Wall Date: Sat, 28 Nov 2026 00:45:28 -0500 Subject: [PATCH] Fix the data-flow hits: declared embedding result, unused store and response fields, Prisma enums - processEmbeddingRun declares its return type. The inferred union dropped umapProjection, and the route cast its result to a local copy to get it back. - Drop canvas.store fitToSpread (the canvas route has its own), the unread requestedTokens, and the considered/readFailures response fields. - ChatThreadStatus, ChatMessageRole and RunStatus come from the Prisma enums instead of hand-copied unions, so the six casts that hid the copies go. Co-Authored-By: Claude Opus 5.5 --- .../data/docs.actions.path-round.ts | 3 +-- .../data/docs.actions.scan-relative-images.ts | 6 ----- .../features/docs-index/data/docs.types.ts | 2 -- app/src/routes/embeddings/[id].tsx | 23 +++++-------------- app/src/services/ai/ai-chat.queries.ts | 14 +++++------ app/src/services/ai/ai-runs.queries.ts | 8 ++++--- .../services/embeddings/embeddings.server.ts | 21 +++++++++++++---- .../services/embeddings/embeddings.utils.ts | 6 +---- app/src/stores/canvas.store.ts | 16 ------------- 9 files changed, 37 insertions(+), 62 deletions(-) diff --git a/app/src/features/docs-index/data/docs.actions.path-round.ts b/app/src/features/docs-index/data/docs.actions.path-round.ts index 6ab645fc..351640c4 100644 --- a/app/src/features/docs-index/data/docs.actions.path-round.ts +++ b/app/src/features/docs-index/data/docs.actions.path-round.ts @@ -95,7 +95,7 @@ export const processPathRound = action(async () => { try { console.log("[docs.path-round] no updates; considered=%d", considered); } catch {} - return { ok: true, updated: 0, failed: 0, considered }; + return { ok: true, updated: 0, failed: 0 }; } const chunkSize = 100; @@ -146,7 +146,6 @@ export const processPathRound = action(async () => { ok: true, updated, failed, - considered, init: initCandidates, extend: extendCandidates, }; diff --git a/app/src/features/docs-index/data/docs.actions.scan-relative-images.ts b/app/src/features/docs-index/data/docs.actions.scan-relative-images.ts index 1b945ce5..30d8a598 100644 --- a/app/src/features/docs-index/data/docs.actions.scan-relative-images.ts +++ b/app/src/features/docs-index/data/docs.actions.scan-relative-images.ts @@ -70,10 +70,8 @@ export const scanRelativeImages = action( return { ok: true, total, - considered, matches, dryRun: true, - readFailures, }; } @@ -81,11 +79,9 @@ export const scanRelativeImages = action( return { ok: true, total, - considered, matches, updated: 0, failed: 0, - readFailures, }; } @@ -153,11 +149,9 @@ export const scanRelativeImages = action( return { ok: true, total, - considered, matches, updated, failed, - readFailures, }; }, "docs-scan-relative-images" diff --git a/app/src/features/docs-index/data/docs.types.ts b/app/src/features/docs-index/data/docs.types.ts index 4875f75c..271b6cf1 100644 --- a/app/src/features/docs-index/data/docs.types.ts +++ b/app/src/features/docs-index/data/docs.types.ts @@ -83,12 +83,10 @@ export type SourcesResponse = { export type ScanRelativeImagesResult = { ok: boolean; total: number; - considered: number; matches: number; updated?: number; failed?: number; dryRun?: boolean; - readFailures?: number; }; export type BulkMetaAction = diff --git a/app/src/routes/embeddings/[id].tsx b/app/src/routes/embeddings/[id].tsx index ad94d806..36644ece 100644 --- a/app/src/routes/embeddings/[id].tsx +++ b/app/src/routes/embeddings/[id].tsx @@ -32,6 +32,7 @@ import { deleteEmbeddingRun, processEmbeddingRun, } from "~/services/embeddings/embeddings.actions"; +import type { UmapProjectionSummary } from "~/services/embeddings/embeddings.server"; import { createUmapRun } from "~/services/umap/umap.actions"; import { fetchUmapRuns } from "~/services/umap/umap.queries"; import { fetchJobStatus, type JobStatus } from "~/services/jobs/jobs.queries"; @@ -39,14 +40,6 @@ import { createKeptAsync } from "~/utils/kept-async"; const DOCS_LIMIT = 10; -type ProcessEmbeddingResult = { - umapProjection?: { - runsUpdated: number; - pointsProjected: number; - failedRuns: number; - }; -}; - function formatParamValue(value: unknown): string { if (value == null) return "null"; if (typeof value === "string") return value; @@ -88,11 +81,7 @@ const EmbeddingDetail: VoidComponent = () => { sections: [] as DocSectionItem[], sectionsLoading: false, activeJobId: "", - lastProjectionSummary: null as null | { - runsUpdated: number; - pointsProjected: number; - failedRuns: number; - }, + lastProjectionSummary: null as null | UmapProjectionSummary, }); const umapRunsForEmbedding = createAsync(() => { if (!params.id) return Promise.resolve([]); @@ -207,10 +196,10 @@ const EmbeddingDetail: VoidComponent = () => { id: params.id, limit: state.batchSize, }); - const result = (await runProcessEmbedding({ + const result = await runProcessEmbedding({ id: params.id, limit: state.batchSize, - })) as ProcessEmbeddingResult; + }); setState("lastProjectionSummary", result.umapProjection ?? null); await revalidate( fetchEmbeddingRun.keyFor({ @@ -236,11 +225,11 @@ const EmbeddingDetail: VoidComponent = () => { id: params.id, limit: state.batchSize, }); - const result = (await runProcessEmbedding({ + const result = await runProcessEmbedding({ id: params.id, limit: state.batchSize, mode: "changed", - })) as ProcessEmbeddingResult; + }); setState("lastProjectionSummary", result.umapProjection ?? null); await revalidate( fetchEmbeddingRun.keyFor({ diff --git a/app/src/services/ai/ai-chat.queries.ts b/app/src/services/ai/ai-chat.queries.ts index bbe6b3c7..be0b047e 100644 --- a/app/src/services/ai/ai-chat.queries.ts +++ b/app/src/services/ai/ai-chat.queries.ts @@ -1,10 +1,10 @@ import { query } from "@solidjs/router"; +import type { ChatMessageRole, ChatThreadStatus } from "@prisma/client"; import { prisma } from "~/server/db"; import { getMagicUserIdFromEvent } from "~/services/ai/ai-auth"; -export type ChatThreadStatus = "ACTIVE" | "LOADING" | "DONE"; - -export type ChatMessageRole = "user" | "assistant"; +// The status and role enums come from the Prisma schema, the one source for them. +export type { ChatMessageRole, ChatThreadStatus }; export type ChatThreadPreview = { id: string; @@ -63,7 +63,7 @@ export const fetchChatThreads = query( return threads.map((t) => ({ id: t.id, title: t.title, - status: t.status as ChatThreadStatus, + status: t.status, hasUnread: t.hasUnread, noteId: t.noteId, lastMessageAt: t.lastMessageAt.toISOString(), @@ -71,7 +71,7 @@ export const fetchChatThreads = query( preview: t.messages?.[0] ? { id: t.messages[0].id, - role: t.messages[0].role as ChatMessageRole, + role: t.messages[0].role, contentHtml: t.messages[0].contentHtml, createdAt: t.messages[0].createdAt.toISOString(), } @@ -106,7 +106,7 @@ export const fetchChatThread = query( return { id: thread.id, title: thread.title, - status: thread.status as ChatThreadStatus, + status: thread.status, hasUnread: thread.hasUnread, noteId: thread.noteId, lastMessageAt: thread.lastMessageAt.toISOString(), @@ -114,7 +114,7 @@ export const fetchChatThread = query( updatedAt: thread.updatedAt.toISOString(), messages: thread.messages.map((m) => ({ id: m.id, - role: m.role as ChatMessageRole, + role: m.role, contentHtml: m.contentHtml, isEdited: m.isEdited, createdAt: m.createdAt.toISOString(), diff --git a/app/src/services/ai/ai-runs.queries.ts b/app/src/services/ai/ai-runs.queries.ts index f951a9fc..816e1845 100644 --- a/app/src/services/ai/ai-runs.queries.ts +++ b/app/src/services/ai/ai-runs.queries.ts @@ -1,7 +1,9 @@ import { query } from "@solidjs/router"; +import type { RunStatus } from "@prisma/client"; import { prisma } from "~/server/db"; -export type RunStatus = "SUCCESS" | "ERROR" | "PARTIAL"; +// The status enum comes from the Prisma schema, the one source for it. +export type { RunStatus }; export type PromptRunItem = { id: string; @@ -83,7 +85,7 @@ export const fetchPromptRuns = query( ); return runs.map((r) => ({ id: r.id, - status: r.status as RunStatus, + status: r.status, model: r.model, createdAt: r.createdAt.toISOString(), error: r.error, @@ -120,7 +122,7 @@ export const fetchPromptRun = query( console.log(`[services] fetchPromptRun id=${id}`); return { id: run.id, - status: run.status as RunStatus, + status: run.status, model: run.model, createdAt: run.createdAt.toISOString(), error: run.error, diff --git a/app/src/services/embeddings/embeddings.server.ts b/app/src/services/embeddings/embeddings.server.ts index 22987d7b..f7a0916d 100644 --- a/app/src/services/embeddings/embeddings.server.ts +++ b/app/src/services/embeddings/embeddings.server.ts @@ -303,9 +303,24 @@ export async function deleteEmbeddingRun( return { ok: true, id: deleted.id }; } +export type UmapProjectionSummary = { + runsUpdated: number; + pointsProjected: number; + failedRuns: number; +}; + +// Declared, not inferred: the early returns carry no projection, and the +// inferred union dropped `umapProjection` from every branch. +export type ProcessEmbeddingResult = { + addedDocs: number; + addedSections: number; + remaining: number; + umapProjection?: UmapProjectionSummary; +}; + export async function processEmbeddingRun( payload: z.infer, -) { +): Promise { if (!serverEnv.OPENAI_API_KEY) { throw new Error("OPENAI_API_KEY not configured"); } @@ -649,9 +664,7 @@ export async function processEmbeddingRun( ); } - let umapProjectionSummary: - | { runsUpdated: number; pointsProjected: number; failedRuns: number } - | undefined; + let umapProjectionSummary: UmapProjectionSummary | undefined; if (docRows.length) { const trainedRuns = await prisma.umapRun.findMany({ where: { diff --git a/app/src/services/embeddings/embeddings.utils.ts b/app/src/services/embeddings/embeddings.utils.ts index 78c4181f..585c7ded 100644 --- a/app/src/services/embeddings/embeddings.utils.ts +++ b/app/src/services/embeddings/embeddings.utils.ts @@ -89,10 +89,7 @@ function tryParseOpenAIError(err: unknown): OpenAIEmbeddingError | null { } } -function getContextLimitExceeded(err: unknown): { - requestedTokens: number; - maxTokens: number; -} | null { +function getContextLimitExceeded(err: unknown): { maxTokens: number } | null { const parsed = tryParseOpenAIError(err); const message = parsed?.error?.message || (err instanceof Error ? err.message : ""); const match = message.match( @@ -101,7 +98,6 @@ function getContextLimitExceeded(err: unknown): { if (!match) return null; return { maxTokens: Number(match[1]), - requestedTokens: Number(match[2]), }; } diff --git a/app/src/stores/canvas.store.ts b/app/src/stores/canvas.store.ts index c22c9465..64d07b74 100644 --- a/app/src/stores/canvas.store.ts +++ b/app/src/stores/canvas.store.ts @@ -101,21 +101,6 @@ export function createCanvasStore() { motionFrame = requestAnimationFrame(tick); } - function fitToSpread(spread = 1000) { - if (!isBrowser) return; - const vw = window.innerWidth; - const vh = window.innerHeight; - const availH = Math.max(100, vh - navHeight()); - const s = (0.9 * Math.min(vw, availH)) / (2 * spread); - const screenCx = vw / 2; - const screenCy = availH / 2; - setView({ - scale: Math.max(0.2, Math.min(2, s)), - offset: { x: screenCx, y: screenCy }, - }); - scheduleTransform(); - } - function animateToView(target: { scale: number; offset: Point; @@ -219,7 +204,6 @@ export function createCanvasStore() { panBy, startInertia, cancelMotion, - fitToSpread, animateToView, animateZoomAt, } as const;