diff --git a/apps/webapp/app/lib/ingest.server.ts b/apps/webapp/app/lib/ingest.server.ts index a0dd0f0..efc72e0 100644 --- a/apps/webapp/app/lib/ingest.server.ts +++ b/apps/webapp/app/lib/ingest.server.ts @@ -29,7 +29,6 @@ export const addToQueue = async ( const queuePersist = await prisma.ingestionQueue.create({ data: { - spaceId: body.spaceId ? body.spaceId : null, data: body, type: body.type, status: IngestionStatus.PENDING, diff --git a/apps/webapp/app/trigger/ingest/ingest.ts b/apps/webapp/app/trigger/ingest/ingest.ts index 63a831b..66e382f 100644 --- a/apps/webapp/app/trigger/ingest/ingest.ts +++ b/apps/webapp/app/trigger/ingest/ingest.ts @@ -16,7 +16,7 @@ export const IngestBodyRequest = z.object({ referenceTime: z.string(), metadata: z.record(z.union([z.string(), z.number(), z.boolean()])).optional(), source: z.string(), - spaceId: z.string().optional(), + spaceIds: z.array(z.string()).optional(), sessionId: z.string().optional(), type: z .enum([EpisodeType.CONVERSATION, EpisodeType.DOCUMENT]) @@ -151,25 +151,28 @@ export const ingestTask = task({ // Handle space assignment after successful ingestion try { - // If spaceId was explicitly provided, immediately assign the episode to that space - if (episodeBody.spaceId && episodeDetails.episodeUuid) { - logger.info(`Assigning episode to explicitly provided space`, { + // If spaceIds were explicitly provided, immediately assign the episode to those spaces + if (episodeBody.spaceIds && episodeBody.spaceIds.length > 0 && episodeDetails.episodeUuid) { + logger.info(`Assigning episode to explicitly provided spaces`, { userId: payload.userId, episodeId: episodeDetails.episodeUuid, - spaceId: episodeBody.spaceId, + spaceIds: episodeBody.spaceIds, }); - await assignEpisodesToSpace( - [episodeDetails.episodeUuid], - episodeBody.spaceId, - payload.userId, - ); + // Assign episode to each space + for (const spaceId of episodeBody.spaceIds) { + await assignEpisodesToSpace( + [episodeDetails.episodeUuid], + spaceId, + payload.userId, + ); + } logger.info( - `Skipping LLM space assignment - episode explicitly assigned to space ${episodeBody.spaceId}`, + `Skipping LLM space assignment - episode explicitly assigned to ${episodeBody.spaceIds.length} space(s)`, ); } else { - // Only trigger automatic LLM space assignment if no explicit spaceId was provided + // Only trigger automatic LLM space assignment if no explicit spaceIds were provided logger.info( `Triggering LLM space assignment after successful ingestion`, { diff --git a/apps/webapp/app/utils/mcp/memory.ts b/apps/webapp/app/utils/mcp/memory.ts index 9b9caff..453ab37 100644 --- a/apps/webapp/app/utils/mcp/memory.ts +++ b/apps/webapp/app/utils/mcp/memory.ts @@ -49,9 +49,12 @@ const IngestSchema = { type: "string", description: "The data to ingest in text format", }, - spaceId: { - type: "string", - description: "Optional: UUID of the space to associate this memory with. If working on a specific project, provide the space ID to organize the memory in that project's context.", + spaceIds: { + type: "array", + items: { + type: "string", + }, + description: "Optional: Array of space UUIDs to associate this memory with. If working on specific projects, provide space IDs to organize the memory in those project contexts. The episode will be assigned to all specified spaces.", }, }, required: ["message"], @@ -244,7 +247,7 @@ async function handleMemoryIngest(args: any) { referenceTime: new Date().toISOString(), source: args.source, type: EpisodeTypeEnum.CONVERSATION, - spaceId: args.spaceId, + spaceIds: args.spaceIds, }, args.userId, ); diff --git a/packages/database/prisma/migrations/20251009054406_remove_space_relation_ingestion_queue/migration.sql b/packages/database/prisma/migrations/20251009054406_remove_space_relation_ingestion_queue/migration.sql new file mode 100644 index 0000000..ee8ec0d --- /dev/null +++ b/packages/database/prisma/migrations/20251009054406_remove_space_relation_ingestion_queue/migration.sql @@ -0,0 +1,11 @@ +/* + Warnings: + + - You are about to drop the column `spaceId` on the `IngestionQueue` table. All the data in the column will be lost. + +*/ +-- DropForeignKey +ALTER TABLE "IngestionQueue" DROP CONSTRAINT "IngestionQueue_spaceId_fkey"; + +-- AlterTable +ALTER TABLE "IngestionQueue" DROP COLUMN "spaceId"; diff --git a/packages/database/prisma/schema.prisma b/packages/database/prisma/schema.prisma index 9e90491..8685b5f 100644 --- a/packages/database/prisma/schema.prisma +++ b/packages/database/prisma/schema.prisma @@ -113,10 +113,6 @@ model ConversationHistory { model IngestionQueue { id String @id @default(cuid()) - // Relations - space Space? @relation(fields: [spaceId], references: [id]) - spaceId String? - // Queue metadata data Json // The actual data to be processed output Json? // The processed output data @@ -494,7 +490,6 @@ model Space { createdAt DateTime @default(now()) updatedAt DateTime @updatedAt - IngestionQueue IngestionQueue[] SpacePattern SpacePattern[] }