From 59620151f2a5da477a15f223c38e23d7b26cff49 Mon Sep 17 00:00:00 2001 From: Harshith Mullapudi Date: Sat, 20 Sep 2025 10:28:39 +0530 Subject: [PATCH] fix: delete log needs no body --- apps/webapp/app/routes/api.v1.logs.$logId.tsx | 12 +-- .../app/trigger/spaces/space-summary.ts | 76 +++++++++---------- 2 files changed, 41 insertions(+), 47 deletions(-) diff --git a/apps/webapp/app/routes/api.v1.logs.$logId.tsx b/apps/webapp/app/routes/api.v1.logs.$logId.tsx index 8abb24b..21bda8b 100644 --- a/apps/webapp/app/routes/api.v1.logs.$logId.tsx +++ b/apps/webapp/app/routes/api.v1.logs.$logId.tsx @@ -24,20 +24,16 @@ const loader = createHybridLoaderApiRoute( corsStrategy: "all", allowJWT: true, }, - async ({ params, authentication }) => { + async ({ params }) => { const formattedLog = await getIngestionQueueForFrontend(params.logId); return json({ log: formattedLog }); }, ); -export const DeleteEpisodeBodyRequest = z.object({ - id: z.string(), -}); - const { action } = createHybridActionApiRoute( { - body: DeleteEpisodeBodyRequest, + params: LogParamsSchema, allowJWT: true, method: "DELETE", authorization: { @@ -45,9 +41,9 @@ const { action } = createHybridActionApiRoute( }, corsStrategy: "all", }, - async ({ body, authentication }) => { + async ({ params, authentication }) => { try { - const ingestionQueue = await getIngestionQueue(body.id); + const ingestionQueue = await getIngestionQueue(params.logId); if (!ingestionQueue) { return json( diff --git a/apps/webapp/app/trigger/spaces/space-summary.ts b/apps/webapp/app/trigger/spaces/space-summary.ts index 0b190c6..b481b5a 100644 --- a/apps/webapp/app/trigger/spaces/space-summary.ts +++ b/apps/webapp/app/trigger/spaces/space-summary.ts @@ -8,9 +8,10 @@ import type { CoreMessage } from "ai"; import { z } from "zod"; import { triggerSpacePattern } from "./space-pattern"; import { getSpace, updateSpace } from "../utils/space-utils"; -import { addToQueue } from "~/lib/ingest.server"; + import { EpisodeType } from "@core/types"; import { getSpaceStatementCount } from "~/services/graphModels/space"; +import { addToQueue } from "../utils/queue"; interface SpaceSummaryPayload { userId: string; @@ -144,7 +145,9 @@ export const spaceSummaryTask = task({ }, }); - logger.info(`No summary generated for space ${spaceId} - insufficient or no new episodes`); + logger.info( + `No summary generated for space ${spaceId} - insufficient or no new episodes`, + ); return { success: true, spaceId, @@ -231,11 +234,7 @@ async function generateSpaceSummary( // Process in batches, each building on previous result const batches: SpaceEpisodeData[][] = []; - for ( - let i = 0; - i < episodes.length; - i += CONFIG.maxEpisodesForSummary - ) { + for (let i = 0; i < episodes.length; i += CONFIG.maxEpisodesForSummary) { batches.push(episodes.slice(i, i + CONFIG.maxEpisodesForSummary)); } @@ -374,16 +373,16 @@ function createUnifiedSummaryPrompt( const episodesText = episodes .map( (episode) => - `- ${episode.content} (Source: ${episode.source}, Session: ${episode.sessionId || 'N/A'})`, + `- ${episode.content} (Source: ${episode.source}, Session: ${episode.sessionId || "N/A"})`, ) .join("\n"); // Extract key entities and themes from episode content const contentWords = episodes - .map(ep => ep.content.toLowerCase()) - .join(' ') + .map((ep) => ep.content.toLowerCase()) + .join(" ") .split(/\s+/) - .filter(word => word.length > 3); + .filter((word) => word.length > 3); const wordFrequency = new Map(); contentWords.forEach((word) => { @@ -423,7 +422,7 @@ ${ 3. Create a coherent summary that captures the essence of this knowledge domain 4. Generate a well-structured markdown summary organized by the identified themes` } -${isUpdate ? '7' : '6'}. Assess your confidence in the ${isUpdate ? "updated" : ""} summary quality (0.0-1.0) +${isUpdate ? "7" : "6"}. Assess your confidence in the ${isUpdate ? "updated" : ""} summary quality (0.0-1.0) THEME IDENTIFICATION RULES: - A theme must be supported by AT LEAST 3 related episodes to be considered valid @@ -564,7 +563,7 @@ async function getSpaceEpisodes( WHERE ${whereClause} OPTIONAL MATCH (e:Episode{userId: $userId})-[:HAS_PROVENANCE]->(s) WITH e - WHERE e IS NOT NULL ${dateCondition ? `AND ${dateCondition}` : ''} + WHERE e IS NOT NULL ${dateCondition ? `AND ${dateCondition}` : ""} RETURN DISTINCT e ORDER BY e.createdAt DESC `; @@ -700,33 +699,32 @@ async function processSpaceSummarySequentially({ spaceName: string; summaryContent: string; triggerSource: - | "summary_complete" - | "manual" - | "assignment" - | "scheduled" - | "new_space" - | "growth_threshold" - | "ingestion_complete"; + | "summary_complete" + | "manual" + | "assignment" + | "scheduled" + | "new_space" + | "growth_threshold" + | "ingestion_complete"; }): Promise { - // Step 1: Ingest summary as document synchronously - await ingestSpaceSummaryDocument( - spaceId, - userId, - spaceName, - summaryContent - ); + // Step 1: Ingest summary as document synchronously + await ingestSpaceSummaryDocument(spaceId, userId, spaceName, summaryContent); - logger.info(`Successfully ingested space summary document for space ${spaceId}`); + logger.info( + `Successfully ingested space summary document for space ${spaceId}`, + ); - // Step 2: Now trigger space patterns (patterns will have access to the ingested summary) - await triggerSpacePattern({ - userId, - workspaceId, - spaceId, - triggerSource, - }); + // Step 2: Now trigger space patterns (patterns will have access to the ingested summary) + await triggerSpacePattern({ + userId, + workspaceId, + spaceId, + triggerSource, + }); - logger.info(`Sequential processing completed for space ${spaceId}: summary ingested → patterns triggered`); + logger.info( + `Sequential processing completed for space ${spaceId}: summary ingested → patterns triggered`, + ); } /** @@ -736,7 +734,7 @@ async function ingestSpaceSummaryDocument( spaceId: string, userId: string, spaceName: string, - summaryContent: string + summaryContent: string, ): Promise { // Create the ingest body const ingestBody = { @@ -756,9 +754,9 @@ async function ingestSpaceSummaryDocument( // Add to queue await addToQueue(ingestBody, userId); - + logger.info(`Queued space summary for synchronous ingestion`); - + return; }