Skip to content

armgit / crm

Public Imported from GitHub
0

Comp AI CRM is an open source, CRM designed for AI agents. Agentic-first CRM.

TypeScript

chore(env): update .env.example and build-func.mjs for Vercel compatibility

Lewis Carhart3baaa848161f
diff --git a/.env.example b/.env.example
index 1317408d..9dd784cd 100644
--- a/.env.example
+++ b/.env.example
@@ -1,6 +1,12 @@
# Postgres
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/crm?schema=public"
+# A direct, unpooled connection to that same database, used by
+# `prisma migrate deploy` when the API is built on Vercel. Set it only if
+# DATABASE_URL points at a pooler; POSTGRES_URL_NON_POOLING is read as a
+# fallback. Locally there is nothing to set.
+# DIRECT_DATABASE_URL=""
+
# Generate your own: openssl rand -base64 32
BETTER_AUTH_SECRET=""
diff --git a/apps/api/scripts/build-func.mjs b/apps/api/scripts/build-func.mjs
index e3391930..122215a0 100644
--- a/apps/api/scripts/build-func.mjs
+++ b/apps/api/scripts/build-func.mjs
@@ -163,3 +163,24 @@ writeFileSync(
);
console.log(`✓ built ${outDir}`);
+
+const directDatabaseUrl = !process.env.VERCEL
+ ? undefined
+ : process.env.DIRECT_DATABASE_URL ||
+ process.env.POSTGRES_URL_NON_POOLING ||
+ process.env.DATABASE_URL_UNPOOLED ||
+ process.env.DATABASE_URL;
+
+if (!process.env.VERCEL) {
+ console.log("• not a Vercel build — skipping migrations");
+} else if (!directDatabaseUrl) {
+ console.log("• no database URL at build time — skipping migrations");
+} else {
+ console.log("• applying migrations (prisma migrate deploy)...");
+ execSync(`${bun} x prisma migrate deploy`, {
+ cwd: join(repoRoot, "packages/db"),
+ stdio: "inherit",
+ env: { ...process.env, DATABASE_URL: directDatabaseUrl },
+ });
+ console.log("✓ migrations applied");
+}
diff --git a/apps/app/app/(app)/settings/agent-model.tsx b/apps/app/app/(app)/settings/agent-model.tsx
index 403d731e..6584a94c 100644
--- a/apps/app/app/(app)/settings/agent-model.tsx
+++ b/apps/app/app/(app)/settings/agent-model.tsx
@@ -94,9 +94,11 @@ export function AgentModel() {
const defaultModel = models.find((model) => model.id === defaultId);
const current = selectedId ?? FOLLOW_DEFAULT;
+ const effectiveName = effective?.name ?? effectiveId;
+
const currentLabel = selectedId
- ? (effective?.name ?? selectedId)
- : `Default — ${defaultModel?.name ?? defaultId}`;
+ ? effectiveName
+ : `Default — ${effectiveName}`;
const choose = (id: string) => {
setOpen(false);
diff --git a/apps/app/app/(app)/settings/page.tsx b/apps/app/app/(app)/settings/page.tsx
index 2494b0dd..02e99264 100644
--- a/apps/app/app/(app)/settings/page.tsx
+++ b/apps/app/app/(app)/settings/page.tsx
@@ -26,10 +26,9 @@ export default async function SettingsPage() {
await Promise.all([
queryClient.prefetchQuery(trpc.google.status.queryOptions()),
queryClient.prefetchQuery(trpc.settings.agentModel.queryOptions()),
+ queryClient.prefetchQuery(trpc.settings.modelCatalog.queryOptions()),
]);
- void queryClient.prefetchQuery(trpc.settings.modelCatalog.queryOptions());
-
return (
<PageShell>
<PageShellHeader>
diff --git a/packages/auth/src/client.ts b/packages/auth/src/client.ts
index 252f2f07..e54eb7cf 100644
--- a/packages/auth/src/client.ts
+++ b/packages/auth/src/client.ts
@@ -1,7 +1,7 @@
import { createAuthClient } from "better-auth/react";
export const authClient = createAuthClient({
- baseURL: process.env.NEXT_PUBLIC_API_URL,
+ baseURL: typeof window === "undefined" ? undefined : window.location.origin,
});
export const { getSession, signIn, signOut, useSession } = authClient;