Files
dataroom/features/ai/lib/file-processing/process-document-for-vector-store.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

52 lines
1.6 KiB
TypeScript

import { openai } from "@/features/ai/lib/models/openai";
import { DocumentStorageType } from "@prisma/client";
import { toFile } from "openai";
import path from "path";
import { getFile } from "@/lib/files/get-file";
/**
* Process a document and prepare it for vector store upload
* Downloads the file from storage and returns it as a buffer
* @param filePath - The file path/key in storage
* @param storageType - The storage type (S3_PATH or VERCEL_BLOB)
* @returns File ID
*/
export async function processDocumentForVectorStore(
filePath: string,
storageType: DocumentStorageType,
): Promise<{ fileId: string }> {
try {
// Get the file URL
const fileUrl = await getFile({
type: storageType,
data: filePath,
isDownload: true,
});
// Fetch the file
const response = await fetch(fileUrl);
if (!response.ok) {
throw new Error(`Failed to fetch file: ${response.statusText}`);
}
// Extract filename from the original file path (not the presigned URL)
const fileName = path.basename(filePath);
// Convert response to buffer and create a properly named file
// This prevents OpenAI from inferring extension from URL query params
// const buffer = await response.arrayBuffer();
const file = await toFile(response, fileName, { type: "application/pdf" });
const fileResponse = await openai.files.create({
file,
purpose: "assistants",
});
return { fileId: fileResponse.id };
} catch (error) {
console.error("Error processing document for vector store:", error);
throw new Error("Failed to process document for vector store");
}
}