mirror of
https://github.com/eliasstepanik/core.git
synced 2026-01-11 18:28:29 +00:00
Fix: remove db.server dependency for prisma from trigger
This commit is contained in:
parent
6b243b3797
commit
6094893330
@ -1,9 +1,11 @@
|
|||||||
import { type ActionFunctionArgs, type LoaderFunctionArgs, json } from "@remix-run/node";
|
import {
|
||||||
import { PrismaClient } from "@prisma/client";
|
type ActionFunctionArgs,
|
||||||
|
type LoaderFunctionArgs,
|
||||||
|
json,
|
||||||
|
} from "@remix-run/node";
|
||||||
import { requireAuth } from "~/utils/auth-helper";
|
import { requireAuth } from "~/utils/auth-helper";
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
|
import { prisma } from "~/db.server";
|
||||||
const prisma = new PrismaClient();
|
|
||||||
|
|
||||||
// GET /api/oauth/clients/:clientId - Get specific OAuth client
|
// GET /api/oauth/clients/:clientId - Get specific OAuth client
|
||||||
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||||
@ -27,7 +29,7 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const client = await prisma.oAuthClient.findFirst({
|
const client = await prisma.oAuthClient.findFirst({
|
||||||
where: {
|
where: {
|
||||||
id: clientId,
|
id: clientId,
|
||||||
workspaceId: userRecord.Workspace.id,
|
workspaceId: userRecord.Workspace.id,
|
||||||
},
|
},
|
||||||
@ -88,7 +90,7 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
|
|||||||
|
|
||||||
// Verify client exists and belongs to user's workspace
|
// Verify client exists and belongs to user's workspace
|
||||||
const existingClient = await prisma.oAuthClient.findFirst({
|
const existingClient = await prisma.oAuthClient.findFirst({
|
||||||
where: {
|
where: {
|
||||||
id: clientId,
|
id: clientId,
|
||||||
workspaceId: userRecord.Workspace.id,
|
workspaceId: userRecord.Workspace.id,
|
||||||
},
|
},
|
||||||
@ -101,16 +103,29 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
|
|||||||
// PATCH - Update OAuth client
|
// PATCH - Update OAuth client
|
||||||
if (method === "PATCH") {
|
if (method === "PATCH") {
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
const { name, description, redirectUris, allowedScopes, requirePkce, logoUrl, homepageUrl, isActive } = body;
|
const {
|
||||||
|
name,
|
||||||
|
description,
|
||||||
|
redirectUris,
|
||||||
|
allowedScopes,
|
||||||
|
requirePkce,
|
||||||
|
logoUrl,
|
||||||
|
homepageUrl,
|
||||||
|
isActive,
|
||||||
|
} = body;
|
||||||
|
|
||||||
const updateData: any = {};
|
const updateData: any = {};
|
||||||
if (name !== undefined) updateData.name = name;
|
if (name !== undefined) updateData.name = name;
|
||||||
if (description !== undefined) updateData.description = description;
|
if (description !== undefined) updateData.description = description;
|
||||||
if (redirectUris !== undefined) {
|
if (redirectUris !== undefined) {
|
||||||
updateData.redirectUris = Array.isArray(redirectUris) ? redirectUris.join(',') : redirectUris;
|
updateData.redirectUris = Array.isArray(redirectUris)
|
||||||
|
? redirectUris.join(",")
|
||||||
|
: redirectUris;
|
||||||
}
|
}
|
||||||
if (allowedScopes !== undefined) {
|
if (allowedScopes !== undefined) {
|
||||||
updateData.allowedScopes = Array.isArray(allowedScopes) ? allowedScopes.join(',') : allowedScopes;
|
updateData.allowedScopes = Array.isArray(allowedScopes)
|
||||||
|
? allowedScopes.join(",")
|
||||||
|
: allowedScopes;
|
||||||
}
|
}
|
||||||
if (requirePkce !== undefined) updateData.requirePkce = requirePkce;
|
if (requirePkce !== undefined) updateData.requirePkce = requirePkce;
|
||||||
if (logoUrl !== undefined) updateData.logoUrl = logoUrl;
|
if (logoUrl !== undefined) updateData.logoUrl = logoUrl;
|
||||||
@ -145,7 +160,7 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
|
|||||||
const { action } = body;
|
const { action } = body;
|
||||||
|
|
||||||
if (action === "regenerate_secret") {
|
if (action === "regenerate_secret") {
|
||||||
const newClientSecret = crypto.randomBytes(32).toString('hex');
|
const newClientSecret = crypto.randomBytes(32).toString("hex");
|
||||||
|
|
||||||
const updatedClient = await prisma.oAuthClient.update({
|
const updatedClient = await prisma.oAuthClient.update({
|
||||||
where: { id: clientId },
|
where: { id: clientId },
|
||||||
@ -158,10 +173,11 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return json({
|
return json({
|
||||||
success: true,
|
success: true,
|
||||||
client: updatedClient,
|
client: updatedClient,
|
||||||
message: "Client secret regenerated successfully. Save it securely - it won't be shown again."
|
message:
|
||||||
|
"Client secret regenerated successfully. Save it securely - it won't be shown again.",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,13 +190,15 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
|
|||||||
where: { id: clientId },
|
where: { id: clientId },
|
||||||
});
|
});
|
||||||
|
|
||||||
return json({ success: true, message: "OAuth client deleted successfully" });
|
return json({
|
||||||
|
success: true,
|
||||||
|
message: "OAuth client deleted successfully",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return json({ error: "Method not allowed" }, { status: 405 });
|
return json({ error: "Method not allowed" }, { status: 405 });
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error managing OAuth client:", error);
|
console.error("Error managing OAuth client:", error);
|
||||||
return json({ error: "Internal server error" }, { status: 500 });
|
return json({ error: "Internal server error" }, { status: 500 });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -3,11 +3,9 @@ import {
|
|||||||
type LoaderFunctionArgs,
|
type LoaderFunctionArgs,
|
||||||
json,
|
json,
|
||||||
} from "@remix-run/node";
|
} from "@remix-run/node";
|
||||||
import { PrismaClient } from "@prisma/client";
|
|
||||||
import { requireAuth } from "~/utils/auth-helper";
|
import { requireAuth } from "~/utils/auth-helper";
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
|
import { prisma } from "~/db.server";
|
||||||
const prisma = new PrismaClient();
|
|
||||||
|
|
||||||
// GET /api/oauth/clients - List OAuth clients for user's workspace
|
// GET /api/oauth/clients - List OAuth clients for user's workspace
|
||||||
export const loader = async ({ request }: LoaderFunctionArgs) => {
|
export const loader = async ({ request }: LoaderFunctionArgs) => {
|
||||||
@ -95,7 +93,7 @@ export const action = async ({ request }: ActionFunctionArgs) => {
|
|||||||
// Integration scope
|
// Integration scope
|
||||||
"integration",
|
"integration",
|
||||||
"integration:read",
|
"integration:read",
|
||||||
"integration:credentials",
|
"integration:credentials",
|
||||||
"integration:manage",
|
"integration:manage",
|
||||||
"integration:webhook",
|
"integration:webhook",
|
||||||
// MCP scope
|
// MCP scope
|
||||||
|
|||||||
@ -4,9 +4,8 @@ import {
|
|||||||
type SpaceDeletionResult,
|
type SpaceDeletionResult,
|
||||||
type SpaceAssignmentResult,
|
type SpaceAssignmentResult,
|
||||||
} from "@core/types";
|
} from "@core/types";
|
||||||
import { prisma } from "~/db.server";
|
|
||||||
import { type Space } from "@prisma/client";
|
|
||||||
import { logger } from "~/services/logger.service";
|
import { logger } from "~/services/logger.service";
|
||||||
|
import { prisma } from "~/trigger/utils/prisma";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new space for a user
|
* Create a new space for a user
|
||||||
|
|||||||
@ -1,9 +1,7 @@
|
|||||||
import { PrismaClient } from "@prisma/client";
|
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import { env } from "~/env.server";
|
import { env } from "~/env.server";
|
||||||
import { type JWTPayload, jwtVerify, SignJWT } from "jose";
|
import { type JWTPayload, jwtVerify, SignJWT } from "jose";
|
||||||
|
import { prisma } from "~/db.server";
|
||||||
const prisma = new PrismaClient();
|
|
||||||
|
|
||||||
export interface OAuth2AuthorizeRequest {
|
export interface OAuth2AuthorizeRequest {
|
||||||
client_id: string;
|
client_id: string;
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import {
|
|||||||
type UpdateSpaceParams,
|
type UpdateSpaceParams,
|
||||||
type SpaceAssignmentResult,
|
type SpaceAssignmentResult,
|
||||||
} from "@core/types";
|
} from "@core/types";
|
||||||
import { prisma } from "~/db.server";
|
import { type Space } from "@prisma/client";
|
||||||
|
|
||||||
import { triggerSpaceAssignment } from "~/trigger/spaces/space-assignment";
|
import { triggerSpaceAssignment } from "~/trigger/spaces/space-assignment";
|
||||||
import {
|
import {
|
||||||
@ -18,7 +18,7 @@ import {
|
|||||||
removeStatementsFromSpace,
|
removeStatementsFromSpace,
|
||||||
updateSpace,
|
updateSpace,
|
||||||
} from "./graphModels/space";
|
} from "./graphModels/space";
|
||||||
import { type Space } from "@prisma/client";
|
import { prisma } from "~/trigger/utils/prisma";
|
||||||
|
|
||||||
export class SpaceService {
|
export class SpaceService {
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
import { PrismaClient } from "@prisma/client";
|
|
||||||
import { LLMMappings } from "@core/types";
|
import { LLMMappings } from "@core/types";
|
||||||
import { logger, task } from "@trigger.dev/sdk/v3";
|
import { logger, task } from "@trigger.dev/sdk/v3";
|
||||||
import { generate } from "../chat/stream-utils";
|
import { generate } from "../chat/stream-utils";
|
||||||
import { conversationTitlePrompt } from "./prompt";
|
import { conversationTitlePrompt } from "./prompt";
|
||||||
|
import { prisma } from "../utils/prisma";
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
|
||||||
export const createConversationTitle = task({
|
export const createConversationTitle = task({
|
||||||
id: "create-conversation-title",
|
id: "create-conversation-title",
|
||||||
run: async (payload: { conversationId: string; message: string }) => {
|
run: async (payload: { conversationId: string; message: string }) => {
|
||||||
|
|||||||
@ -1,13 +1,11 @@
|
|||||||
import { queue, task } from "@trigger.dev/sdk";
|
import { queue, task } from "@trigger.dev/sdk";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { KnowledgeGraphService } from "~/services/knowledgeGraph.server";
|
import { KnowledgeGraphService } from "~/services/knowledgeGraph.server";
|
||||||
import { PrismaClient } from "@prisma/client";
|
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
|
||||||
|
|
||||||
import { IngestionStatus } from "@core/database";
|
import { IngestionStatus } from "@core/database";
|
||||||
import { logger } from "~/services/logger.service";
|
import { logger } from "~/services/logger.service";
|
||||||
import { triggerSpaceAssignment } from "../spaces/space-assignment";
|
import { triggerSpaceAssignment } from "../spaces/space-assignment";
|
||||||
|
import { prisma } from "../utils/prisma";
|
||||||
|
|
||||||
export const IngestBodyRequest = z.object({
|
export const IngestBodyRequest = z.object({
|
||||||
episodeBody: z.string(),
|
episodeBody: z.string(),
|
||||||
|
|||||||
@ -1,10 +1,8 @@
|
|||||||
import { PrismaClient } from "@prisma/client";
|
|
||||||
import { IntegrationEventType } from "@core/types";
|
import { IntegrationEventType } from "@core/types";
|
||||||
import { logger, schedules, tasks } from "@trigger.dev/sdk/v3";
|
import { logger, schedules, tasks } from "@trigger.dev/sdk/v3";
|
||||||
|
|
||||||
import { type integrationRun } from "./integration-run";
|
import { type integrationRun } from "./integration-run";
|
||||||
|
import { prisma } from "../utils/prisma";
|
||||||
const prisma = new PrismaClient();
|
|
||||||
|
|
||||||
export const integrationRunSchedule = schedules.task({
|
export const integrationRunSchedule = schedules.task({
|
||||||
id: "integration-run-schedule",
|
id: "integration-run-schedule",
|
||||||
|
|||||||
@ -1,9 +1,7 @@
|
|||||||
import { PrismaClient } from "@prisma/client";
|
|
||||||
import { logger, schedules, task } from "@trigger.dev/sdk/v3";
|
import { logger, schedules, task } from "@trigger.dev/sdk/v3";
|
||||||
|
|
||||||
import { integrationRunSchedule } from "./integration-run-schedule";
|
import { integrationRunSchedule } from "./integration-run-schedule";
|
||||||
|
import { prisma } from "../utils/prisma";
|
||||||
const prisma = new PrismaClient();
|
|
||||||
|
|
||||||
export const scheduler = task({
|
export const scheduler = task({
|
||||||
id: "scheduler",
|
id: "scheduler",
|
||||||
|
|||||||
@ -12,7 +12,10 @@ import {
|
|||||||
} from "~/services/graphModels/space";
|
} from "~/services/graphModels/space";
|
||||||
import { triggerSpaceSummary } from "./space-summary";
|
import { triggerSpaceSummary } from "./space-summary";
|
||||||
import { triggerSpacePattern } from "./space-pattern";
|
import { triggerSpacePattern } from "./space-pattern";
|
||||||
import { updateMultipleSpaceStatuses, SPACE_STATUS } from "../utils/space-status";
|
import {
|
||||||
|
updateMultipleSpaceStatuses,
|
||||||
|
SPACE_STATUS,
|
||||||
|
} from "../utils/space-status";
|
||||||
import type { CoreMessage } from "ai";
|
import type { CoreMessage } from "ai";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { type Space } from "@prisma/client";
|
import { type Space } from "@prisma/client";
|
||||||
@ -321,7 +324,7 @@ export const spaceAssignmentTask = task({
|
|||||||
userId,
|
userId,
|
||||||
operation: "space-assignment",
|
operation: "space-assignment",
|
||||||
metadata: { mode, phase: "start_processing" },
|
metadata: { mode, phase: "start_processing" },
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
} catch (statusError) {
|
} catch (statusError) {
|
||||||
logger.warn(`Failed to update space statuses to processing:`, {
|
logger.warn(`Failed to update space statuses to processing:`, {
|
||||||
@ -332,7 +335,7 @@ export const spaceAssignmentTask = task({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Trigger space summaries for affected spaces (fan-out pattern)
|
// 5. Trigger space summaries for affected spaces (fan-out pattern)
|
||||||
if (affectedSpaces.size > 0) {
|
if (affectedSpaces.size > 0) {
|
||||||
try {
|
try {
|
||||||
logger.info(
|
logger.info(
|
||||||
@ -415,7 +418,7 @@ export const spaceAssignmentTask = task({
|
|||||||
userId,
|
userId,
|
||||||
operation: "space-assignment",
|
operation: "space-assignment",
|
||||||
metadata: { mode, phase: "completed_processing" },
|
metadata: { mode, phase: "completed_processing" },
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
} catch (finalStatusError) {
|
} catch (finalStatusError) {
|
||||||
logger.warn(`Failed to update space statuses to ready:`, {
|
logger.warn(`Failed to update space statuses to ready:`, {
|
||||||
|
|||||||
@ -4,20 +4,25 @@ import { makeModelCall } from "~/lib/model.server";
|
|||||||
import { runQuery } from "~/lib/neo4j.server";
|
import { runQuery } from "~/lib/neo4j.server";
|
||||||
import type { CoreMessage } from "ai";
|
import type { CoreMessage } from "ai";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { prisma } from "~/db.server";
|
|
||||||
import {
|
import {
|
||||||
EXPLICIT_PATTERN_TYPES,
|
EXPLICIT_PATTERN_TYPES,
|
||||||
IMPLICIT_PATTERN_TYPES,
|
IMPLICIT_PATTERN_TYPES,
|
||||||
type SpacePattern,
|
type SpacePattern,
|
||||||
type PatternDetectionResult,
|
type PatternDetectionResult,
|
||||||
type UserConfirmationStatus,
|
|
||||||
} from "@core/types";
|
} from "@core/types";
|
||||||
|
import { createSpacePattern, getSpace } from "../utils/space-utils";
|
||||||
|
|
||||||
interface SpacePatternPayload {
|
interface SpacePatternPayload {
|
||||||
userId: string;
|
userId: string;
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
spaceId: string;
|
spaceId: string;
|
||||||
triggerSource?: "summary_complete" | "manual" | "scheduled" | "new_space" | "growth_threshold" | "ingestion_complete";
|
triggerSource?:
|
||||||
|
| "summary_complete"
|
||||||
|
| "manual"
|
||||||
|
| "scheduled"
|
||||||
|
| "new_space"
|
||||||
|
| "growth_threshold"
|
||||||
|
| "ingestion_complete";
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SpaceStatementData {
|
interface SpaceStatementData {
|
||||||
@ -78,7 +83,7 @@ export const spacePatternTask = task({
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Get space data and check if it has enough content
|
// Get space data and check if it has enough content
|
||||||
const space = await getSpaceForPatternAnalysis(spaceId, userId);
|
const space = await getSpaceForPatternAnalysis(spaceId);
|
||||||
if (!space) {
|
if (!space) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@ -155,17 +160,9 @@ export const spacePatternTask = task({
|
|||||||
|
|
||||||
async function getSpaceForPatternAnalysis(
|
async function getSpaceForPatternAnalysis(
|
||||||
spaceId: string,
|
spaceId: string,
|
||||||
userId: string,
|
|
||||||
): Promise<SpaceThemeData | null> {
|
): Promise<SpaceThemeData | null> {
|
||||||
try {
|
try {
|
||||||
const space = await prisma.space.findFirst({
|
const space = await getSpace(spaceId);
|
||||||
where: {
|
|
||||||
id: spaceId,
|
|
||||||
workspace: {
|
|
||||||
userId: userId,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!space || !space.themes || space.themes.length === 0) {
|
if (!space || !space.themes || space.themes.length === 0) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
@ -536,13 +533,7 @@ async function storePatterns(
|
|||||||
if (allPatterns.length === 0) return;
|
if (allPatterns.length === 0) return;
|
||||||
|
|
||||||
// Store in PostgreSQL
|
// Store in PostgreSQL
|
||||||
await prisma.spacePattern.createMany({
|
await createSpacePattern(spaceId, allPatterns);
|
||||||
data: allPatterns.map((pattern) => ({
|
|
||||||
...pattern,
|
|
||||||
spaceId,
|
|
||||||
userConfirmed: pattern.userConfirmed as any, // Temporary cast until Prisma client is regenerated
|
|
||||||
})),
|
|
||||||
});
|
|
||||||
|
|
||||||
logger.info(`Stored ${allPatterns.length} patterns`, {
|
logger.info(`Stored ${allPatterns.length} patterns`, {
|
||||||
explicit: explicitPatterns.length,
|
explicit: explicitPatterns.length,
|
||||||
|
|||||||
@ -6,8 +6,8 @@ import { runQuery } from "~/lib/neo4j.server";
|
|||||||
import { updateSpaceStatus, SPACE_STATUS } from "../utils/space-status";
|
import { updateSpaceStatus, SPACE_STATUS } from "../utils/space-status";
|
||||||
import type { CoreMessage } from "ai";
|
import type { CoreMessage } from "ai";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { prisma } from "~/db.server";
|
import { triggerSpacePattern } from "./space-pattern";
|
||||||
import { spacePatternTask, triggerSpacePattern } from "./space-pattern";
|
import { getSpace, updateSpace } from "../utils/space-utils";
|
||||||
|
|
||||||
interface SpaceSummaryPayload {
|
interface SpaceSummaryPayload {
|
||||||
userId: string;
|
userId: string;
|
||||||
@ -90,8 +90,8 @@ export const spaceSummaryTask = task({
|
|||||||
await updateSpaceStatus(spaceId, SPACE_STATUS.READY, {
|
await updateSpaceStatus(spaceId, SPACE_STATUS.READY, {
|
||||||
userId,
|
userId,
|
||||||
operation: "space-summary",
|
operation: "space-summary",
|
||||||
metadata: {
|
metadata: {
|
||||||
triggerSource,
|
triggerSource,
|
||||||
phase: "completed_summary",
|
phase: "completed_summary",
|
||||||
statementCount: summaryResult.statementCount,
|
statementCount: summaryResult.statementCount,
|
||||||
confidence: summaryResult.confidence,
|
confidence: summaryResult.confidence,
|
||||||
@ -129,7 +129,11 @@ export const spaceSummaryTask = task({
|
|||||||
await updateSpaceStatus(spaceId, SPACE_STATUS.ERROR, {
|
await updateSpaceStatus(spaceId, SPACE_STATUS.ERROR, {
|
||||||
userId,
|
userId,
|
||||||
operation: "space-summary",
|
operation: "space-summary",
|
||||||
metadata: { triggerSource, phase: "failed_summary", error: "Failed to generate summary" },
|
metadata: {
|
||||||
|
triggerSource,
|
||||||
|
phase: "failed_summary",
|
||||||
|
error: "Failed to generate summary",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.warn(`Failed to generate summary for space ${spaceId}`);
|
logger.warn(`Failed to generate summary for space ${spaceId}`);
|
||||||
@ -146,10 +150,10 @@ export const spaceSummaryTask = task({
|
|||||||
await updateSpaceStatus(spaceId, SPACE_STATUS.ERROR, {
|
await updateSpaceStatus(spaceId, SPACE_STATUS.ERROR, {
|
||||||
userId,
|
userId,
|
||||||
operation: "space-summary",
|
operation: "space-summary",
|
||||||
metadata: {
|
metadata: {
|
||||||
triggerSource,
|
triggerSource,
|
||||||
phase: "exception",
|
phase: "exception",
|
||||||
error: error instanceof Error ? error.message : "Unknown error"
|
error: error instanceof Error ? error.message : "Unknown error",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (statusError) {
|
} catch (statusError) {
|
||||||
@ -483,9 +487,7 @@ async function getExistingSummary(spaceId: string): Promise<{
|
|||||||
lastUpdated: Date;
|
lastUpdated: Date;
|
||||||
} | null> {
|
} | null> {
|
||||||
try {
|
try {
|
||||||
const existingSummary = await prisma.space.findUnique({
|
const existingSummary = await getSpace(spaceId);
|
||||||
where: { id: spaceId },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (existingSummary?.summary) {
|
if (existingSummary?.summary) {
|
||||||
return {
|
return {
|
||||||
@ -616,16 +618,7 @@ function parseSummaryResponse(response: string): {
|
|||||||
async function storeSummary(summaryData: SpaceSummaryData): Promise<void> {
|
async function storeSummary(summaryData: SpaceSummaryData): Promise<void> {
|
||||||
try {
|
try {
|
||||||
// Store in PostgreSQL for API access and persistence
|
// Store in PostgreSQL for API access and persistence
|
||||||
await prisma.space.update({
|
await updateSpace(summaryData);
|
||||||
where: {
|
|
||||||
id: summaryData.spaceId,
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
summary: summaryData.summary,
|
|
||||||
themes: summaryData.themes,
|
|
||||||
statementCount: summaryData.statementCount,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// Also store in Neo4j for graph-based queries
|
// Also store in Neo4j for graph-based queries
|
||||||
const query = `
|
const query = `
|
||||||
|
|||||||
@ -6,8 +6,7 @@ import * as path from "path";
|
|||||||
|
|
||||||
import { type MCPTool } from "./types";
|
import { type MCPTool } from "./types";
|
||||||
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
||||||
import { PrismaClient } from "@prisma/client";
|
import { prisma } from "./prisma";
|
||||||
const prisma = new PrismaClient();
|
|
||||||
|
|
||||||
export const configureStdioMCPEnvironment = (
|
export const configureStdioMCPEnvironment = (
|
||||||
spec: any,
|
spec: any,
|
||||||
|
|||||||
@ -1,10 +1,8 @@
|
|||||||
import { PrismaClient } from "@prisma/client";
|
|
||||||
import { type Message } from "@core/types";
|
import { type Message } from "@core/types";
|
||||||
import { addToQueue } from "./queue";
|
import { addToQueue } from "./queue";
|
||||||
import { triggerWebhookDelivery } from "../webhooks/webhook-delivery";
|
import { triggerWebhookDelivery } from "../webhooks/webhook-delivery";
|
||||||
import { logger } from "@trigger.dev/sdk";
|
import { logger } from "@trigger.dev/sdk";
|
||||||
|
import { prisma } from "./prisma";
|
||||||
const prisma = new PrismaClient();
|
|
||||||
|
|
||||||
export const createIntegrationAccount = async ({
|
export const createIntegrationAccount = async ({
|
||||||
integrationDefinitionId,
|
integrationDefinitionId,
|
||||||
|
|||||||
10
apps/webapp/app/trigger/utils/prisma.ts
Normal file
10
apps/webapp/app/trigger/utils/prisma.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { PrismaClient } from "@prisma/client";
|
||||||
|
import { singleton } from "~/utils/singleton";
|
||||||
|
|
||||||
|
export const prisma = singleton("prisma", getClient);
|
||||||
|
|
||||||
|
function getClient() {
|
||||||
|
const client = new PrismaClient();
|
||||||
|
|
||||||
|
return client;
|
||||||
|
}
|
||||||
@ -1,8 +1,7 @@
|
|||||||
import { IngestionStatus, PrismaClient } from "@prisma/client";
|
import { IngestionStatus, PrismaClient } from "@prisma/client";
|
||||||
import { type z } from "zod";
|
import { type z } from "zod";
|
||||||
import { type IngestBodyRequest, ingestTask } from "../ingest/ingest";
|
import { type IngestBodyRequest, ingestTask } from "../ingest/ingest";
|
||||||
|
import { prisma } from "./prisma";
|
||||||
const prisma = new PrismaClient();
|
|
||||||
|
|
||||||
export const addToQueue = async (
|
export const addToQueue = async (
|
||||||
body: z.infer<typeof IngestBodyRequest>,
|
body: z.infer<typeof IngestBodyRequest>,
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { prisma } from "~/db.server";
|
|
||||||
import { logger } from "~/services/logger.service";
|
import { logger } from "~/services/logger.service";
|
||||||
|
import { prisma } from "./prisma";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update space status with proper error handling and logging
|
* Update space status with proper error handling and logging
|
||||||
@ -11,14 +11,14 @@ export async function updateSpaceStatus(
|
|||||||
userId?: string;
|
userId?: string;
|
||||||
operation?: string;
|
operation?: string;
|
||||||
metadata?: Record<string, unknown>;
|
metadata?: Record<string, unknown>;
|
||||||
}
|
},
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await prisma.space.update({
|
await prisma.space.update({
|
||||||
where: { id: spaceId },
|
where: { id: spaceId },
|
||||||
data: { status },
|
data: { status },
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.info(`Updated space status`, {
|
logger.info(`Updated space status`, {
|
||||||
spaceId,
|
spaceId,
|
||||||
status,
|
status,
|
||||||
@ -48,7 +48,7 @@ export async function updateMultipleSpaceStatuses(
|
|||||||
userId?: string;
|
userId?: string;
|
||||||
operation?: string;
|
operation?: string;
|
||||||
metadata?: Record<string, unknown>;
|
metadata?: Record<string, unknown>;
|
||||||
}
|
},
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (spaceIds.length === 0) return;
|
if (spaceIds.length === 0) return;
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ export async function updateMultipleSpaceStatuses(
|
|||||||
});
|
});
|
||||||
|
|
||||||
await Promise.allSettled(updatePromises);
|
await Promise.allSettled(updatePromises);
|
||||||
|
|
||||||
logger.info(`Completed batch status update`, {
|
logger.info(`Completed batch status update`, {
|
||||||
status,
|
status,
|
||||||
totalSpaces: spaceIds.length,
|
totalSpaces: spaceIds.length,
|
||||||
@ -109,4 +109,4 @@ export const SPACE_STATUS = {
|
|||||||
PENDING: "pending",
|
PENDING: "pending",
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export type SpaceStatus = typeof SPACE_STATUS[keyof typeof SPACE_STATUS];
|
export type SpaceStatus = (typeof SPACE_STATUS)[keyof typeof SPACE_STATUS];
|
||||||
|
|||||||
46
apps/webapp/app/trigger/utils/space-utils.ts
Normal file
46
apps/webapp/app/trigger/utils/space-utils.ts
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import { type SpacePattern } from "@core/types";
|
||||||
|
import { prisma } from "./prisma";
|
||||||
|
|
||||||
|
export const getSpace = async (spaceId: string) => {
|
||||||
|
const space = await prisma.space.findFirst({
|
||||||
|
where: {
|
||||||
|
id: spaceId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return space;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const createSpacePattern = async (
|
||||||
|
spaceId: string,
|
||||||
|
allPatterns: Omit<
|
||||||
|
SpacePattern,
|
||||||
|
"id" | "createdAt" | "updatedAt" | "spaceId"
|
||||||
|
>[],
|
||||||
|
) => {
|
||||||
|
return await prisma.spacePattern.createMany({
|
||||||
|
data: allPatterns.map((pattern) => ({
|
||||||
|
...pattern,
|
||||||
|
spaceId,
|
||||||
|
userConfirmed: pattern.userConfirmed as any, // Temporary cast until Prisma client is regenerated
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const updateSpace = async (summaryData: {
|
||||||
|
spaceId: string;
|
||||||
|
summary: string;
|
||||||
|
themes: string[];
|
||||||
|
statementCount: number;
|
||||||
|
}) => {
|
||||||
|
return await prisma.space.update({
|
||||||
|
where: {
|
||||||
|
id: summaryData.spaceId,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
summary: summaryData.summary,
|
||||||
|
themes: summaryData.themes,
|
||||||
|
statementCount: summaryData.statementCount,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
@ -4,7 +4,6 @@ import {
|
|||||||
type ConversationHistory,
|
type ConversationHistory,
|
||||||
type IntegrationDefinitionV2,
|
type IntegrationDefinitionV2,
|
||||||
type Prisma,
|
type Prisma,
|
||||||
PrismaClient,
|
|
||||||
UserType,
|
UserType,
|
||||||
type UserUsage,
|
type UserUsage,
|
||||||
type Workspace,
|
type Workspace,
|
||||||
@ -22,8 +21,7 @@ import axios from "axios";
|
|||||||
import nodeCrypto from "node:crypto";
|
import nodeCrypto from "node:crypto";
|
||||||
import { customAlphabet, nanoid } from "nanoid";
|
import { customAlphabet, nanoid } from "nanoid";
|
||||||
import { Exa } from "exa-js";
|
import { Exa } from "exa-js";
|
||||||
|
import { prisma } from "./prisma";
|
||||||
const prisma = new PrismaClient();
|
|
||||||
|
|
||||||
// Token generation utilities
|
// Token generation utilities
|
||||||
const tokenValueLength = 40;
|
const tokenValueLength = 40;
|
||||||
|
|||||||
@ -1,13 +1,11 @@
|
|||||||
import { queue, task } from "@trigger.dev/sdk";
|
import { queue, task } from "@trigger.dev/sdk";
|
||||||
import { PrismaClient } from "@prisma/client";
|
|
||||||
import { logger } from "~/services/logger.service";
|
import { logger } from "~/services/logger.service";
|
||||||
import {
|
import {
|
||||||
deliverWebhook,
|
deliverWebhook,
|
||||||
type WebhookEventType,
|
type WebhookEventType,
|
||||||
type WebhookTarget,
|
type WebhookTarget,
|
||||||
} from "./webhook-delivery-utils";
|
} from "./webhook-delivery-utils";
|
||||||
|
import { prisma } from "../utils/prisma";
|
||||||
const prisma = new PrismaClient();
|
|
||||||
|
|
||||||
const integrationWebhookQueue = queue({
|
const integrationWebhookQueue = queue({
|
||||||
name: "integration-webhook-queue",
|
name: "integration-webhook-queue",
|
||||||
|
|||||||
@ -1,13 +1,11 @@
|
|||||||
import { queue, task } from "@trigger.dev/sdk";
|
import { queue, task } from "@trigger.dev/sdk";
|
||||||
import { PrismaClient } from "@prisma/client";
|
|
||||||
import { logger } from "~/services/logger.service";
|
import { logger } from "~/services/logger.service";
|
||||||
import { WebhookDeliveryStatus } from "@core/database";
|
import { WebhookDeliveryStatus } from "@core/database";
|
||||||
import {
|
import {
|
||||||
deliverWebhook,
|
deliverWebhook,
|
||||||
prepareWebhookTargets,
|
prepareWebhookTargets,
|
||||||
} from "./webhook-delivery-utils";
|
} from "./webhook-delivery-utils";
|
||||||
|
import { prisma } from "../utils/prisma";
|
||||||
const prisma = new PrismaClient();
|
|
||||||
|
|
||||||
const webhookQueue = queue({
|
const webhookQueue = queue({
|
||||||
name: "webhook-delivery-queue",
|
name: "webhook-delivery-queue",
|
||||||
|
|||||||
@ -27,16 +27,16 @@ export default defineConfig({
|
|||||||
build: {
|
build: {
|
||||||
extensions: [
|
extensions: [
|
||||||
syncEnvVars(() => ({
|
syncEnvVars(() => ({
|
||||||
ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY as string,
|
// ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY as string,
|
||||||
API_BASE_URL: process.env.API_BASE_URL as string,
|
// API_BASE_URL: process.env.API_BASE_URL as string,
|
||||||
DATABASE_URL: process.env.DATABASE_URL as string,
|
// DATABASE_URL: process.env.DATABASE_URL as string,
|
||||||
EMBEDDING_MODEL: process.env.EMBEDDING_MODEL as string,
|
// EMBEDDING_MODEL: process.env.EMBEDDING_MODEL as string,
|
||||||
ENCRYPTION_KEY: process.env.ENCRYPTION_KEY as string,
|
// ENCRYPTION_KEY: process.env.ENCRYPTION_KEY as string,
|
||||||
MODEL: process.env.MODEL ?? "gpt-4.1-2025-04-14",
|
// MODEL: process.env.MODEL ?? "gpt-4.1-2025-04-14",
|
||||||
NEO4J_PASSWORD: process.env.NEO4J_PASSWORD as string,
|
// NEO4J_PASSWORD: process.env.NEO4J_PASSWORD as string,
|
||||||
NEO4J_URI: process.env.NEO4J_URI as string,
|
// NEO4J_URI: process.env.NEO4J_URI as string,
|
||||||
NEO4J_USERNAME: process.env.NEO4J_USERNAME as string,
|
// NEO4J_USERNAME: process.env.NEO4J_USERNAME as string,
|
||||||
OPENAI_API_KEY: process.env.OPENAI_API_KEY as string,
|
// OPENAI_API_KEY: process.env.OPENAI_API_KEY as string,
|
||||||
})),
|
})),
|
||||||
prismaExtension({
|
prismaExtension({
|
||||||
schema: "prisma/schema.prisma",
|
schema: "prisma/schema.prisma",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user