mirror of
https://github.com/eliasstepanik/core.git
synced 2026-01-11 09:08:28 +00:00
* Feat: change space assignment from statement to episode * feat: add default spaces and improve integration, space tools discovery in MCP * feat: change spaces to episode based * Feat: take multiple spaceIds while ingesting * Feat: modify mcp tool descriptions, add spaceId in mcp url * feat: add copy * bump: new version 0.1.24 --------- Co-authored-by: Manoj <saimanoj58@gmail.com>
76 lines
1.8 KiB
TypeScript
76 lines
1.8 KiB
TypeScript
// lib/ingest.queue.ts
|
|
import { IngestionStatus } from "@core/database";
|
|
import { EpisodeType } from "@core/types";
|
|
import { type z } from "zod";
|
|
import { prisma } from "~/db.server";
|
|
import { type IngestBodyRequest, ingestTask } from "~/trigger/ingest/ingest";
|
|
import { ingestDocumentTask } from "~/trigger/ingest/ingest-document";
|
|
|
|
export const addToQueue = async (
|
|
rawBody: z.infer<typeof IngestBodyRequest>,
|
|
userId: string,
|
|
activityId?: string,
|
|
) => {
|
|
const body = { ...rawBody, source: rawBody.source.toLowerCase() };
|
|
const user = await prisma.user.findFirst({
|
|
where: {
|
|
id: userId,
|
|
},
|
|
include: {
|
|
Workspace: true,
|
|
},
|
|
});
|
|
|
|
if (!user?.Workspace?.id) {
|
|
throw new Error(
|
|
"Workspace ID is required to create an ingestion queue entry.",
|
|
);
|
|
}
|
|
|
|
const queuePersist = await prisma.ingestionQueue.create({
|
|
data: {
|
|
data: body,
|
|
type: body.type,
|
|
status: IngestionStatus.PENDING,
|
|
priority: 1,
|
|
workspaceId: user.Workspace.id,
|
|
activityId,
|
|
},
|
|
});
|
|
|
|
let handler;
|
|
if (body.type === EpisodeType.DOCUMENT) {
|
|
handler = await ingestDocumentTask.trigger(
|
|
{
|
|
body,
|
|
userId,
|
|
workspaceId: user.Workspace.id,
|
|
queueId: queuePersist.id,
|
|
},
|
|
{
|
|
queue: "document-ingestion-queue",
|
|
concurrencyKey: userId,
|
|
tags: [user.id, queuePersist.id],
|
|
},
|
|
);
|
|
} else if (body.type === EpisodeType.CONVERSATION) {
|
|
handler = await ingestTask.trigger(
|
|
{
|
|
body,
|
|
userId,
|
|
workspaceId: user.Workspace.id,
|
|
queueId: queuePersist.id,
|
|
},
|
|
{
|
|
queue: "ingestion-queue",
|
|
concurrencyKey: userId,
|
|
tags: [user.id, queuePersist.id],
|
|
},
|
|
);
|
|
}
|
|
|
|
return { id: handler?.id, token: handler?.publicAccessToken };
|
|
};
|
|
|
|
export { IngestBodyRequest };
|