Skip to content
Merged
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
8 changes: 4 additions & 4 deletions app/docs/mcp-parity.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ Keep this file current when adding an action or a tool. A new action is either c

## Embeddings and UMAP

| Action / query | MCP | Notes |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | ---------------------------------------------------------------- |
| `createEmbeddingRun`, `processEmbeddingRun`, `updateEmbeddingRun`, `deleteEmbeddingRun`, `fetchEmbeddingRun`, `fetchEmbeddingRuns`, `fetchDocSections` | human-only | Admin; `search` uses the newest run, and agent writes refresh it |
| `createUmapRun`, `projectUmapRun`, `updateUmapRun`, `deleteUmapRun`, `regenerateUmapRegionsAction`, `fetchUmapRun`, `fetchUmapRuns`, `fetchUmapPointsForRun`, `fetchUmapRegionDetail`, `fetchLatestUmapRun`, `fetchUmapPoints`, `fetchNearbyUmapDocs` | human-only | The map view; `search` covers "notes like this" |
| Action / query | MCP | Notes |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | ---------------------------------------------------------------- |
| `createEmbeddingRun`, `processEmbeddingRun`, `updateEmbeddingRun`, `deleteEmbeddingRun`, `fetchEmbeddingRun`, `fetchEmbeddingRuns`, `fetchDocSections` | human-only | Admin; `search` uses the newest run, and agent writes refresh it |
| `createUmapRun`, `projectUmapRun`, `updateUmapRun`, `deleteUmapRun`, `regenerateUmapRegionsAction`, `fetchUmapRun`, `fetchUmapRuns`, `fetchUmapRegionDetail`, `fetchLatestUmapRun`, `fetchUmapPoints`, `fetchNearbyUmapDocs` | human-only | The map view; `search` covers "notes like this" |

## Admin and auth

Expand Down
1 change: 0 additions & 1 deletion app/src/features/umap/detail-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ import type {

export type UmapDetailData = {
meta: UmapRunDetail;
dims: number;
points: UmapPoint[];
};
2 changes: 1 addition & 1 deletion app/src/features/umap/useUmapCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function useUmapCanvas(props: UseUmapCanvasProps) {
createEffect(() => {
const detail = props.detail();
const points = detail?.points ?? [];
const dims = detail?.dims ?? 2;
const dims = detail?.meta.dims ?? 2;
const regions = detail?.meta.regions ?? null;
const width = canvasWidth();
const height = canvasHeight();
Expand Down
20 changes: 7 additions & 13 deletions app/src/routes/umap/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import {
import { Link } from "~/components/ui/link";
import { Text } from "~/components/ui/text";
import { Box, Container, Grid, Stack } from "styled-system/jsx";
import {
fetchUmapPointsForRun,
fetchUmapRun,
} from "~/services/umap/umap.queries";
import { fetchUmapPoints } from "~/services/umap.service";
import { fetchUmapRun } from "~/services/umap/umap.queries";
import {
deleteUmapRun,
regenerateUmapRegionsAction,
Expand All @@ -39,20 +37,16 @@ const UmapDetail: VoidComponent = () => {
const run = await fetchUmapRun(params.id);
if (!run) return null;

const pointsData = await fetchUmapPointsForRun(params.id).catch(() => null);
const points = await fetchUmapPoints(params.id).catch(() => []);

return {
meta: run,
dims: pointsData?.dims ?? run.dims,
points: pointsData?.points ?? [],
};
return { meta: run, points };
});

const { setCanvasContainerEl, setCanvasEl } = useUmapCanvas({ detail });

const refreshPoints = () => {
if (!params.id) return;
void revalidate(fetchUmapPointsForRun.keyFor(params.id));
void revalidate(fetchUmapPoints.keyFor(params.id));
};

const handleDelete = async () => {
Expand All @@ -78,7 +72,7 @@ const UmapDetail: VoidComponent = () => {
await runRegenerateRegions({ id: params.id });
await Promise.all([
revalidate(fetchUmapRun.keyFor(params.id)),
revalidate(fetchUmapPointsForRun.keyFor(params.id)),
revalidate(fetchUmapPoints.keyFor(params.id)),
]);
} catch (error) {
console.error(error);
Expand Down Expand Up @@ -131,7 +125,7 @@ const UmapDetail: VoidComponent = () => {
alignItems="start"
>
<UmapRunCanvasCard
dims={result().dims}
dims={result().meta.dims}
pointsCount={result().points.length}
busy={busy()}
onRefresh={refreshPoints}
Expand Down
30 changes: 0 additions & 30 deletions app/src/services/umap/umap.queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,36 +112,6 @@ export const fetchUmapRun = query(
"umap-run",
);

export const fetchUmapPointsForRun = query(
async (
runId: string,
): Promise<{ runId: string; dims: number; points: UmapPoint[] }> => {
"use server";
if (!runId) throw new Error("Missing runId");
const run = await prisma.umapRun.findUnique({
where: { id: runId },
select: { id: true, dims: true },
});
if (!run) throw new Error("Run not found");

const pts = await prisma.umapPoint.findMany({
where: { runId, doc: { archivedAt: null } },
select: { docId: true, x: true, y: true, z: true },
});
return {
runId,
dims: run.dims,
points: pts.map((p) => ({
docId: p.docId,
x: p.x,
y: p.y,
z: p.z,
})),
};
},
"umap-points",
);

export const fetchUmapRegionDetail = query(
async (input: {
runId: string;
Expand Down
72 changes: 72 additions & 0 deletions app/tests/unit/query-keys.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { readdirSync, readFileSync } from "node:fs";
import { join, relative } from "node:path";
import ts from "typescript";
import { describe, expect, it } from "vitest";

const SRC = join(__dirname, "../../src");
const UNREADABLE = "(name the scan cannot read)";

/** A router import that registers queries under a name the scan can't follow. */
const hidesQueries = (binding: ts.NamedImportBindings) =>
ts.isNamespaceImport(binding) ||
binding.elements.some((element) => {
const imported = (element.propertyName ?? element.name).text;
if (imported === "cache") return true;
return imported === "query" && element.name.text !== "query";
});

/** Every `query(fn, name)` call in a file that imports the router's `query`. */
const queryNames = (file: string) => {
const text = readFileSync(file, "utf8");
if (!text.includes("@solidjs/router")) return [];
const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest);
const found: { name: string; file: string }[] = [];
const add = (name: string) => found.push({ name, file: relative(SRC, file) });
const imports = source.statements.flatMap((node) =>
ts.isImportDeclaration(node) &&
ts.isStringLiteral(node.moduleSpecifier) &&
node.moduleSpecifier.text === "@solidjs/router" &&
node.importClause?.namedBindings
? [node.importClause.namedBindings]
: [],
);
if (imports.some(hidesQueries)) add(UNREADABLE);
// Elsewhere `query()` is usually a search-text signal.
const importsQuery = imports.some(
(binding) =>
ts.isNamedImports(binding) &&
binding.elements.some((element) => element.name.text === "query"),
);
const walk = (node: ts.Node) => {
if (
importsQuery &&
ts.isCallExpression(node) &&
ts.isIdentifier(node.expression) &&
node.expression.text === "query"
) {
const [, name, ...rest] = node.arguments;
const literal = name && ts.isStringLiteralLike(name) && !rest.length;
add(literal ? name.text : UNREADABLE);
}
ts.forEachChild(node, walk);
};
walk(source);
return found;
};

describe("router query names", () => {
// The router caches by name plus arguments. Two queries with one name read
// each other's entries, whatever their return types say.
it("are readable and used once each", () => {
const all = readdirSync(SRC, { recursive: true, encoding: "utf8" })
.filter((path) => /\.tsx?$/.test(path))
.flatMap((path) => queryNames(join(SRC, path)));
const byName = Map.groupBy(all, (query) => query.name);
const clashes = [...byName]
.filter(([name, uses]) => uses.length > 1 || name === UNREADABLE)
.map(([name, uses]) => `${name}: ${uses.map((u) => u.file).join(", ")}`);

expect(all.length).toBeGreaterThan(50);
expect(clashes).toEqual([]);
});
});
Loading