Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/src/features/docs-index/data/docs.actions.path-round.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -146,7 +146,6 @@ export const processPathRound = action(async () => {
ok: true,
updated,
failed,
considered,
init: initCandidates,
extend: extendCandidates,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,18 @@ export const scanRelativeImages = action(
return {
ok: true,
total,
considered,
matches,
dryRun: true,
readFailures,
};
}

if (candidates.length === 0) {
return {
ok: true,
total,
considered,
matches,
updated: 0,
failed: 0,
readFailures,
};
}

Expand Down Expand Up @@ -153,11 +149,9 @@ export const scanRelativeImages = action(
return {
ok: true,
total,
considered,
matches,
updated,
failed,
readFailures,
};
},
"docs-scan-relative-images"
Expand Down
2 changes: 0 additions & 2 deletions app/src/features/docs-index/data/docs.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
23 changes: 6 additions & 17 deletions app/src/routes/embeddings/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,14 @@ 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";
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;
Expand Down Expand Up @@ -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([]);
Expand Down Expand Up @@ -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({
Expand All @@ -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({
Expand Down
14 changes: 7 additions & 7 deletions app/src/services/ai/ai-chat.queries.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -63,15 +63,15 @@ 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(),
updatedAt: t.updatedAt.toISOString(),
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(),
}
Expand Down Expand Up @@ -106,15 +106,15 @@ 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(),
createdAt: thread.createdAt.toISOString(),
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(),
Expand Down
8 changes: 5 additions & 3 deletions app/src/services/ai/ai-runs.queries.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
21 changes: 17 additions & 4 deletions app/src/services/embeddings/embeddings.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof processSchema>,
) {
): Promise<ProcessEmbeddingResult> {
if (!serverEnv.OPENAI_API_KEY) {
throw new Error("OPENAI_API_KEY not configured");
}
Expand Down Expand Up @@ -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: {
Expand Down
6 changes: 1 addition & 5 deletions app/src/services/embeddings/embeddings.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -101,7 +98,6 @@ function getContextLimitExceeded(err: unknown): {
if (!match) return null;
return {
maxTokens: Number(match[1]),
requestedTokens: Number(match[2]),
};
}

Expand Down
16 changes: 0 additions & 16 deletions app/src/stores/canvas.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -219,7 +204,6 @@ export function createCanvasStore() {
panBy,
startInertia,
cancelMotion,
fitToSpread,
animateToView,
animateZoomAt,
} as const;
Expand Down
Loading