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
40 changes: 31 additions & 9 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
"name": "revect",
"dependencies": {
"@modelcontextprotocol/sdk": "^1.12.0",
"@types/cors": "^2.8.18",
"@types/express": "^5.0.2",
"bun-plugin-tailwind": "^0.0.15",
"cors": "^2.8.5",
"express": "^5.1.0",
"openai": "^4.97.0",
"react": "^19.1.0",
"react-dom": "^19.1.0",
Expand All @@ -26,16 +30,38 @@
"packages": {
"@modelcontextprotocol/sdk": ["@modelcontextprotocol/[email protected]", "", { "dependencies": { "ajv": "^6.12.6", "content-type": "^1.0.5", "cors": "^2.8.5", "cross-spawn": "^7.0.5", "eventsource": "^3.0.2", "express": "^5.0.1", "express-rate-limit": "^7.5.0", "pkce-challenge": "^5.0.0", "raw-body": "^3.0.0", "zod": "^3.23.8", "zod-to-json-schema": "^3.24.1" } }, "sha512-m//7RlINx1F3sz3KqwY1WWzVgTcYX52HYk4bJ1hkBXV3zccAEth+jRvG8DBRrdaQuRsPAJOx2MH3zaHNCKL7Zg=="],

"@types/body-parser": ["@types/[email protected]", "", { "dependencies": { "@types/connect": "*", "@types/node": "*" } }, "sha512-fB3Zu92ucau0iQ0JMCFQE7b/dv8Ot07NI3KaZIkIUNXq82k4eBAqUaneXfleGY9JWskeS9y+u0nXMyspcuQrCg=="],

"@types/bun": ["@types/[email protected]", "", { "dependencies": { "bun-types": "1.2.12" } }, "sha512-lY/GQTXDGsolT/TiH72p1tuyUORuRrdV7VwOTOjDOt8uTBJQOJc5zz3ufwwDl0VBaoxotSk4LdP0hhjLJ6ypIQ=="],

"@types/node": ["@types/[email protected]", "", { "dependencies": { "undici-types": "~5.26.4" } }, "sha512-4r3Y9EuCJjWduiam85Fo4GBQtneaEuoaBSdiKo+o6qwQUh0JFVBe7cRUK6I6yVzA0S1gBJJfoQx4VtBH4e5ikg=="],
"@types/connect": ["@types/[email protected]", "", { "dependencies": { "@types/node": "*" } }, "sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug=="],

"@types/cors": ["@types/[email protected]", "", { "dependencies": { "@types/node": "*" } }, "sha512-nX3d0sxJW41CqQvfOzVG1NCTXfFDrDWIghCZncpHeWlVFd81zxB/DLhg7avFg6eHLCRX7ckBmoIIcqa++upvJA=="],

"@types/express": ["@types/[email protected]", "", { "dependencies": { "@types/body-parser": "*", "@types/express-serve-static-core": "^5.0.0", "@types/serve-static": "*" } }, "sha512-BtjL3ZwbCQriyb0DGw+Rt12qAXPiBTPs815lsUvtt1Grk0vLRMZNMUZ741d5rjk+UQOxfDiBZ3dxpX00vSkK3g=="],

"@types/express-serve-static-core": ["@types/[email protected]", "", { "dependencies": { "@types/node": "*", "@types/qs": "*", "@types/range-parser": "*", "@types/send": "*" } }, "sha512-3xhRnjJPkULekpSzgtoNYYcTWgEZkp4myc+Saevii5JPnHNvHMRlBSHDbs7Bh1iPPoVTERHEZXyhyLbMEsExsA=="],

"@types/http-errors": ["@types/[email protected]", "", {}, "sha512-D0CFMMtydbJAegzOyHjtiKPLlvnm3iTZyZRSZoLq2mRhDdmLfIWOCYPfQJ4cu2erKghU++QvjcUjp/5h7hESpA=="],

"@types/mime": ["@types/[email protected]", "", {}, "sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w=="],

"@types/node": ["@types/[email protected]", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-BL1eyu/XWsFGTtDWOYULQEs4KR0qdtYfCxYAUYRoB7JP7h9ETYLgQTww6kH8Sj2C0pFGgrpM0XKv6/kbIzYJ1g=="],

"@types/node-fetch": ["@types/[email protected]", "", { "dependencies": { "@types/node": "*", "form-data": "^4.0.0" } }, "sha512-8nneRWKCg3rMtF69nLQJnOYUcbafYeFSjqkw3jCRLsqkWFlHaoQrr5mXmofFGOx3DKn7UfmBMyov8ySvLRVldA=="],

"@types/qs": ["@types/[email protected]", "", {}, "sha512-eOunJqu0K1923aExK6y8p6fsihYEn/BYuQ4g0CxAAgFc4b/ZLN4CrsRZ55srTdqoiLzU2B2evC+apEIxprEzkQ=="],

"@types/range-parser": ["@types/[email protected]", "", {}, "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ=="],

"@types/react": ["@types/[email protected]", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-dLWQ+Z0CkIvK1J8+wrDPwGxEYFA4RAyHoZPxHVGspYmFVnwGSNT24cGIhFJrtfRnWVuW8X7NO52gCXmhkVUWGQ=="],

"@types/react-dom": ["@types/[email protected]", "", { "peerDependencies": { "@types/react": "^19.0.0" } }, "sha512-rJXC08OG0h3W6wDMFxQrZF00Kq6qQvw0djHRdzl3U5DnIERz0MRce3WVc7IS6JYBwtaP/DwYtRRjVlvivNveKg=="],

"@types/send": ["@types/[email protected]", "", { "dependencies": { "@types/mime": "^1", "@types/node": "*" } }, "sha512-x2EM6TJOybec7c52BX0ZspPodMsQUd5L6PRwOunVyVUhXiBSKf3AezDL8Dgvgt5o0UfKNfuA0eMLr2wLT4AiBA=="],

"@types/serve-static": ["@types/[email protected]", "", { "dependencies": { "@types/http-errors": "*", "@types/node": "*", "@types/send": "*" } }, "sha512-W8Ym+h8nhuRwaKPaDw34QUkwsGi6Rc4yYqvKFo5rm2FUEhCFbzVWrxXUxuKK8TASjWsysJY0nsmNCGhCOIsrOw=="],

"abort-controller": ["[email protected]", "", { "dependencies": { "event-target-shim": "^5.0.0" } }, "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg=="],

"accepts": ["[email protected]", "", { "dependencies": { "mime-types": "^3.0.0", "negotiator": "^1.0.0" } }, "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng=="],
Expand Down Expand Up @@ -254,7 +280,7 @@

"typescript": ["[email protected]", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ=="],

"undici-types": ["undici-types@5.26.5", "", {}, "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA=="],
"undici-types": ["undici-types@6.21.0", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="],

"unpipe": ["[email protected]", "", {}, "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ=="],

Expand All @@ -276,16 +302,12 @@

"zod-to-json-schema": ["[email protected]", "", { "peerDependencies": { "zod": "^3.24.1" } }, "sha512-/AuWwMP+YqiPbsJx5D6TfgRTc4kTLjsh5SOcd4bLsfUg2RcEXrFMJl1DGgdHy2aCfsIA/cr/1JM0xcB2GZji8g=="],

"@types/node-fetch/@types/node": ["@types/[email protected]", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-BL1eyu/XWsFGTtDWOYULQEs4KR0qdtYfCxYAUYRoB7JP7h9ETYLgQTww6kH8Sj2C0pFGgrpM0XKv6/kbIzYJ1g=="],

"bun-types/@types/node": ["@types/[email protected]", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-BL1eyu/XWsFGTtDWOYULQEs4KR0qdtYfCxYAUYRoB7JP7h9ETYLgQTww6kH8Sj2C0pFGgrpM0XKv6/kbIzYJ1g=="],

"form-data/mime-types": ["[email protected]", "", { "dependencies": { "mime-db": "1.52.0" } }, "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw=="],

"@types/node-fetch/@types/node/undici-types": ["[email protected]", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="],

"bun-types/@types/node/undici-types": ["[email protected]", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="],
"openai/@types/node": ["@types/[email protected]", "", { "dependencies": { "undici-types": "~5.26.4" } }, "sha512-4r3Y9EuCJjWduiam85Fo4GBQtneaEuoaBSdiKo+o6qwQUh0JFVBe7cRUK6I6yVzA0S1gBJJfoQx4VtBH4e5ikg=="],

"form-data/mime-types/mime-db": ["[email protected]", "", {}, "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg=="],

"openai/@types/node/undici-types": ["[email protected]", "", {}, "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA=="],
}
}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
},
"dependencies": {
"@modelcontextprotocol/sdk": "^1.12.0",
"@types/cors": "^2.8.18",
"@types/express": "^5.0.2",
"bun-plugin-tailwind": "^0.0.15",
"cors": "^2.8.5",
"express": "^5.1.0",
"openai": "^4.97.0",
"react": "^19.1.0",
"react-dom": "^19.1.0",
Expand Down
1 change: 1 addition & 0 deletions src/database/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ async function migrate(direction: "up" | "down", targetMigration?: string) {
}
}
// Run migrations when script is executed directly
// @ts-ignore - Bun-specific feature
if (import.meta.main) {
const args = process.argv.slice(2);
const direction = args[0]?.toLowerCase();
Expand Down
14 changes: 6 additions & 8 deletions src/routes/context/getContext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Request, Response, NextFunction } from "express";
import { z } from "zod";
import { corsHeaders as headers } from "../../shared/corsHeaders";
import { db } from "../../database/database";

const schema = z.object({
Expand Down Expand Up @@ -42,16 +42,14 @@ export const getContext = async (body: GetContextProps): Promise<GetContextResul
}
};

export const getContextRoute = async (request: Request) => {
const body = await request.json();
export const getContextRoute = async (req: Request, res: Response, next: NextFunction) => {
const body = req.body;
const result = await getContext(body);

if ("error" in result) {
return Response.json(result, {
status: 400,
headers,
});
res.status(400).json(result);
return;
}

return Response.json(result, { headers });
res.json(result);
};
14 changes: 6 additions & 8 deletions src/routes/context/setContext.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Request, Response, NextFunction } from "express";
import { z } from "zod";
import { generateEmbeddings } from "../../shared/generateEmbeddings";
import { corsHeaders as headers } from "../../shared/corsHeaders";
import { db } from "../../database/database";

const schema = z.object({
Expand Down Expand Up @@ -63,16 +63,14 @@ export const setContext = async (body: SetContextProps): Promise<SetContextResul
}
};

export const setContextRoute = async (request: Request) => {
const body = await request.json();
export const setContextRoute = async (req: Request, res: Response, next: NextFunction) => {
const body = req.body;
const result = await setContext(body);

if ("error" in result) {
return Response.json(result, {
status: 400,
headers,
});
res.status(400).json(result);
return;
}

return Response.json(result, { headers });
res.json(result);
};
23 changes: 9 additions & 14 deletions src/routes/document/document.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Request, Response, NextFunction } from "express";
import { z } from "zod";
import { corsHeaders as headers } from "../../shared/corsHeaders";
import { db } from "../../database/database";

type Document = {
Expand Down Expand Up @@ -39,24 +39,19 @@ const getDocumentSchema = z.object({
id: z.number({ required_error: "document id is required" }),
});

export const documentRoute = async (request: Request) => {
const body = await request.json();
export const documentRoute = async (req: Request, res: Response, next: NextFunction) => {
const body = req.body;
const { error, data, success } = getDocumentSchema.safeParse(body);

if (!success) {
return Response.json(
{
error: "Validation failed",
issues: error.issues,
},
{
status: 400,
headers,
}
);
res.status(400).json({
error: "Validation failed",
issues: error.issues,
});
return;
}

const result = await document({ id: data.id });

return Response.json(result, { headers });
res.json(result);
};
22 changes: 13 additions & 9 deletions src/routes/index/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Request, Response, NextFunction } from "express";
import { z } from "zod";
import { generateEmbeddings } from "../../shared/generateEmbeddings";
import { indexDocument } from "./indexDocument";
import { indexDocumentChunk } from "./indexDocumentChunk";
import { corsHeaders as headers } from "../../shared/corsHeaders";
import { splitTextIntoChunks } from "../../utils/splitTextIntoChunks";
import { db } from "../../database/database";

Expand Down Expand Up @@ -35,7 +35,13 @@ export const index = async (body: IndexProps): Promise<IndexResult> => {
}

// Insert the main document and get its ID
const documentId = await indexDocument({ ...data, embeddings });
const documentId = await indexDocument({
text: data.text,
source: data.source,
external_id: data.external_id,
metadata: data.metadata,
embeddings
});

if (!documentId) {
return { error: "Failed to index document" };
Expand Down Expand Up @@ -74,16 +80,14 @@ export const index = async (body: IndexProps): Promise<IndexResult> => {
return { message: "Data successfully indexed" };
};

export const indexRoute = async (request: Request) => {
const body = await request.json();
export const indexRoute = async (req: Request, res: Response, next: NextFunction) => {
const body = req.body;
const result = await index(body);

if ("error" in result) {
return Response.json(result, {
status: 400,
headers,
});
res.status(400).json(result);
return;
}

return Response.json(result, { headers });
res.json(result);
};
Loading