Files
dataroom/features/ai/lib/trigger/process-pdf-for-ai.ts
zeekay caad90bc04 rip: enterprise dirs + paywalls — full AGPL, no commercial-license code
Drop the dual-licensed `ee/` tree entirely. All features previously
locked behind the Hanzo Dataroom Commercial License are now part of the
AGPL-3.0 core and freely available — custom domains, branded viewing,
advanced analytics, watermarks, access controls, Q&A, AI vector stores,
workflows, SAML SSO, dataroom invitations, conversations, templates.

Layout changes:
* `ee/features/{ai,conversations,workflows,permissions,storage,templates,
  dataroom-invitations,access-notifications,security,conversions}/` →
  `features/<name>/` (AGPL).
* `ee/limits/` → `lib/billing/limits/` with every plan resolving to an
  unlimited profile (no users/links/documents/domains/datarooms cap,
  conversations and watermarks always on).
* `ee/stripe/` → `lib/billing/legacy/` (already a compat shim over
  `@hanzoai/commerce`; renewal-reminder webhook is now a no-op).
* `ee/features/billing/cancellation/` deleted. Pause/unpause/cancel/
  retention routes now compile against `lib/billing/cancellation.ts`
  stubs that return 410 Gone; `isTeamPaused`/`isTeamPausedById` in
  `lib/billing/paused.ts` always report active. `CancellationModal` is
  a no-op shim in `components/billing/`.
* `app/(ee)/api/*` route group folded into `app/api/*` (SAML auth,
  SCIM, AI chat, workflows, FAQ, link-upload).

Build: `npm run build` green.
2026-06-07 11:46:48 -07:00

89 lines
2.3 KiB
TypeScript

import { logger, metadata, task } from "@trigger.dev/sdk/v3";
import path from "path";
import { openai } from "@/features/ai/lib/models/openai";
import { getFile } from "@/lib/files/get-file";
import prisma from "@/lib/prisma";
import type { ProcessFilePayload } from "./types";
/**
* Process a PDF file for AI indexing
* PDFs can be uploaded directly to OpenAI without conversion
*/
export const processPdfForAITask = task({
id: "process-pdf-for-ai",
retry: { maxAttempts: 3 },
queue: {
concurrencyLimit: 5,
},
run: async (payload: ProcessFilePayload): Promise<{ fileId: string }> => {
const { documentId, documentVersionId, teamId, documentName, filePath, storageType } =
payload;
logger.info("Processing PDF for AI", {
documentId,
documentVersionId,
teamId,
});
// Check if fileId already exists
const version = await prisma.documentVersion.findUnique({
where: { id: documentVersionId },
select: { fileId: true },
});
if (version?.fileId) {
logger.info("PDF already processed, reusing fileId", {
documentId,
fileId: version.fileId,
});
return { fileId: version.fileId };
}
metadata.set("status", "retrieving");
metadata.set("step", "Retrieving PDF...");
metadata.set("progress", 20);
// Get file URL
const fileUrl = await getFile({
type: storageType,
data: filePath,
isDownload: true,
});
// Fetch file
const response = await fetch(fileUrl);
if (!response.ok) {
throw new Error(`Failed to fetch PDF: ${response.statusText}`);
}
const buffer = Buffer.from(await response.arrayBuffer());
const fileName = path.basename(filePath);
metadata.set("status", "uploading");
metadata.set("step", "Uploading to OpenAI...");
metadata.set("progress", 60);
// Upload to OpenAI Files
const file = new File([buffer], fileName, { type: "application/pdf" });
const fileResponse = await openai.files.create({
file,
purpose: "assistants",
});
// Update document version with fileId
await prisma.documentVersion.update({
where: { id: documentVersionId },
data: { fileId: fileResponse.id },
});
logger.info("PDF processed successfully", {
documentId,
fileId: fileResponse.id,
});
return { fileId: fileResponse.id };
},
});